mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
create a generic service type
This commit is contained in:
parent
36ecf8c06b
commit
a94b5d21ec
@ -20,3 +20,8 @@ export interface CollectionTypeService extends BaseService {
|
|||||||
|
|
||||||
export type Service = SingleTypeService | CollectionTypeService;
|
export type Service = SingleTypeService | CollectionTypeService;
|
||||||
|
|
||||||
|
export type GenericService = Partial<Service> & {
|
||||||
|
[method: string | number | symbol]: (...args:unknown) => Promise<Entity> | Entity;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 { Controller, GenericController } from '../core-api/controller';
|
||||||
import { Middleware } from '../middlewares';
|
import { Middleware } from '../middlewares';
|
||||||
import { Policy } from '../core/registries/policies';
|
import { Policy } from '../core/registries/policies';
|
||||||
@ -47,14 +47,14 @@ interface Router {
|
|||||||
type ControllerCallback<T extends GenericController = GenericController> = (params: {
|
type ControllerCallback<T extends GenericController = GenericController> = (params: {
|
||||||
strapi: Strapi;
|
strapi: Strapi;
|
||||||
}) => T;
|
}) => 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 createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router;
|
||||||
export function createCoreController<T extends GenericController = GenericController>(
|
export function createCoreController<T extends GenericController = GenericController>(
|
||||||
uid: string,
|
uid: string,
|
||||||
cfg?: ControllerCallback<T> | T = {}
|
cfg?: ControllerCallback<T> | T = {}
|
||||||
): () => T & Controller;
|
): () => T & Controller;
|
||||||
export function createCoreService<T extends Service = Service>(
|
export function createCoreService<T extends GenericService = GenericService>(
|
||||||
uid: string,
|
uid: string,
|
||||||
cfg?: ServiceCallback<T> | T = {}
|
cfg?: ServiceCallback<T> | T = {}
|
||||||
): () => T;
|
): () => T;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user