diff --git a/packages/core/strapi/lib/core-api/service/index.d.ts b/packages/core/strapi/lib/core-api/service/index.d.ts index e0c8a39a0d..850660d4ff 100644 --- a/packages/core/strapi/lib/core-api/service/index.d.ts +++ b/packages/core/strapi/lib/core-api/service/index.d.ts @@ -12,11 +12,14 @@ export interface SingleTypeService extends BaseService { export interface CollectionTypeService extends BaseService { find?(params: object): Promise | Entity; - findOne?(entityId: string,params: object): Promise | Entity; + findOne?(entityId: string, params: object): Promise | Entity; create?(params: object): Promise | Entity; - update?(entityId: string,params: object): Promise | Entity; - delete?(entityId: string,params: object): Promise | Entity; + update?(entityId: string, params: object): Promise | Entity; + delete?(entityId: string, params: object): Promise | Entity; } export type Service = SingleTypeService | CollectionTypeService; +export type GenericService = Partial & { + [method: string | number | symbol]: (...args: any) => T; +}; diff --git a/packages/core/strapi/lib/types/core/strapi/index.d.ts b/packages/core/strapi/lib/types/core/strapi/index.d.ts index 5e07ae1705..3288a9ed7f 100644 --- a/packages/core/strapi/lib/types/core/strapi/index.d.ts +++ b/packages/core/strapi/lib/types/core/strapi/index.d.ts @@ -2,7 +2,8 @@ import type Koa from 'koa'; import { Database } from '@strapi/database'; import type { StringMap } from './utils'; -import type { GenericController } from '../core-api/controller' +import type { GenericController } from '../../../core-api/controller' +import type { GenericService } from '../../../core-api/service' /** * The Strapi interface implemented by the main Strapi class. @@ -33,12 +34,12 @@ export interface Strapi { * * It returns all the registered services */ - readonly services: StringMap; + readonly services: StringMap; /** * Find a service using its unique identifier */ - service(uid: string): T | undefined; + service(uid: string): T | undefined; /** * Getter for the Strapi controllers container diff --git a/packages/core/strapi/lib/types/factories.d.ts b/packages/core/strapi/lib/types/factories.d.ts index f71cd0145b..a7cc3669ba 100644 --- a/packages/core/strapi/lib/types/factories.d.ts +++ b/packages/core/strapi/lib/types/factories.d.ts @@ -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 = (params: { strapi: Strapi; }) => T; -type ServiceCallback = (params: { strapi: Strapi }) => T; +type ServiceCallback = (params: { strapi: Strapi }) => T; export function createCoreRouter(uid: string, cfg?: RouterConfig = {}): () => Router; export function createCoreController( uid: string, cfg?: ControllerCallback | T = {} ): () => T & Controller; -export function createCoreService( +export function createCoreService( uid: string, cfg?: ServiceCallback | T = {} ): () => T;