create a generic service type

This commit is contained in:
Bassel Kanso 2022-08-10 16:04:36 +03:00
parent 36ecf8c06b
commit a94b5d21ec
2 changed files with 8 additions and 3 deletions

View File

@ -20,3 +20,8 @@ export interface CollectionTypeService extends BaseService {
export type Service = SingleTypeService | CollectionTypeService;
export type GenericService = Partial<Service> & {
[method: string | number | symbol]: (...args:unknown) => Promise<Entity> | Entity;
};

View File

@ -1,4 +1,4 @@
import { Service } from '../core-api/service';
import { Service,GenericService } from '../core-api/service';
import { Controller, GenericController } from '../core-api/controller';
import { Middleware } from '../middlewares';
import { Policy } from '../core/registries/policies';
@ -47,14 +47,14 @@ interface Router {
type ControllerCallback<T extends GenericController = GenericController> = (params: {
strapi: Strapi;
}) => T;
type ServiceCallback<T extends Service = Service> = (params: { strapi: Strapi }) => T;
type ServiceCallback<T extends GenericService = GenericService> = (params: { strapi: Strapi }) => T;
export function createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router;
export function createCoreController<T extends GenericController = GenericController>(
uid: string,
cfg?: ControllerCallback<T> | T = {}
): () => T & Controller;
export function createCoreService<T extends Service = Service>(
export function createCoreService<T extends GenericService = GenericService>(
uid: string,
cfg?: ServiceCallback<T> | T = {}
): () => T;