mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Merge pull request #14061 from strapi/fix/service-typings
Fix service typings
This commit is contained in:
commit
8231bb905a
@ -12,11 +12,14 @@ export interface SingleTypeService extends BaseService {
|
||||
|
||||
export interface CollectionTypeService extends BaseService {
|
||||
find?(params: object): Promise<Entity[]> | Entity;
|
||||
findOne?(entityId: string,params: object): Promise<Entity> | Entity;
|
||||
findOne?(entityId: string, params: object): Promise<Entity> | Entity;
|
||||
create?(params: object): Promise<Entity> | Entity;
|
||||
update?(entityId: string,params: object): Promise<Entity> | Entity;
|
||||
delete?(entityId: string,params: object): Promise<Entity> | Entity;
|
||||
update?(entityId: string, params: object): Promise<Entity> | Entity;
|
||||
delete?(entityId: string, params: object): Promise<Entity> | Entity;
|
||||
}
|
||||
|
||||
export type Service = SingleTypeService | CollectionTypeService;
|
||||
|
||||
export type GenericService = Partial<Service> & {
|
||||
[method: string | number | symbol]: <T = any>(...args: any) => T;
|
||||
};
|
||||
|
||||
@ -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<Service>;
|
||||
readonly services: StringMap<GenericService>;
|
||||
|
||||
/**
|
||||
* Find a service using its unique identifier
|
||||
*/
|
||||
service<T extends Service = unknown>(uid: string): T | undefined;
|
||||
service<T extends GenericService = GenericService>(uid: string): T | undefined;
|
||||
|
||||
/**
|
||||
* Getter for the Strapi controllers container
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user