import { EventEmitter } from "events"; import React from "react"; import { MessageDescriptor } from "react-intl"; import { StrapiRequestContext } from "./api"; import { HTTPMethod, Primitive, StringMap, TypeResult } from "./common"; import { StrapiContentTypeFullSchema, StrapiContentTypeSchema } from "./contentType"; import { OnlyStrings } from "./utils"; export interface IStrapi { config: StrapiConfigContainer; EE(): Function; get services(): StringMap; service(uid: string): StrapiService; get controllers(): StringMap; controller(uid: string): StrapiController; get contentTypes(): StringMap; contentType(name: string): StrapiContentType; get policies(): StringMap; policy(name: string): StrapiPolicy; get middlewares(): StringMap; middleware(name: string): StrapiMiddleware; get plugins(): StringMap; plugin(name: string): StrapiPlugin; get hooks(): StringMap; hook(name: string): StrapiHook; api(): StringMap; api(name: string): StrapiApi; auth(): StrapiAuth; getModel(uid: string): StrapiContentTypeFullSchema; query(uid: string): StrapiDBQuery; store(props: StrapiStoreQuery): StrapiStore; get components(): StringMap; start: Function; destroy: Function; sendStartupTelemetry: Function; openAdmin: Function; postListen: Function; listen: Function; stopWithError: Function; stop: Function; loadAdmin: Function; loadPlugins: Function; loadPolicies: Function; loadAPIs: Function; loadComponents: Function; loadMiddlewares: Function; loadApp: Function; registerInternalHooks: Function; register: Function; bootstrap: Function; load: Function; startWebhooks: Function; webhookRunner: StrapiWebhookRunner; webhookStore: StrapiWebhookStore; reload: Function; runLifecyclesFunctions: Function; db: StrapiDB; admin: StrapiAdmin; log: StrapiLog; cron: StrapiCron; customFields: StrapiServerCustomFields; } export type StrapiEvents = `${'entry' | 'media'}.${StrapiEventsCrudFlow}` | `entry.${StrapiEventsPublishFlow}`; type StrapiEventsCrudFlow = 'create' | 'update' | 'delete'; type StrapiEventsPublishFlow = 'publish' | 'unpublish'; export type StrapiService = any; export type StrapiController< TResult = unknown, TBody extends {} = StringMap, TQuery extends {} = StringMap, TParams extends {} = StringMap, TContextExtra extends {} = {} > = (context: StrapiRequestContext & TContextExtra) => TResult export type StrapiMiddleware = Object; export type StrapiContentType = T; export type StrapiPolicy = Object; export type StrapiHook = Object; export type StrapiWebhook = { id?: Id, name: string, type: string, url: string, headers: StringMap, events: StrapiEvents[], enabled: boolean, } export type StrapiWebhookRunner = { config: StringMap, eventHub: EventEmitter, listeners: Map, logger: unknown, queue: unknown, webhooksMap: Map, }; export type StrapiWebhookStore = { createWebhook: (data: StrapiWebhook) => any deleteWebhook: (id) => any findWebhook: (id) => StrapiWebhook findWebhooks: () => StrapiWebhook[] updateWebhook: (data: StrapiWebhook) => any } export type StrapiApi = Object; export type StrapiAuth = Object; export type StrapiPlugin = { get services(): StringMap; service(uid: string): StrapiService; get controllers(): StringMap; controller(name: string): StrapiController; get contentTypes(): StringMap; contentType(name: string): StrapiContentType; config(name: string): any; }; export type StrapiPluginConfig = TypeResult; export type StrapiConfigContainer = StringMap & { get: Function; }; export type StrapiStore = { get: ({ key: T }) => U; set: ({ key: T, value: U }) => void; delete: ({ key: T }) => void; }; export type StrapiStoreQuery = { type: string; name?: string; }; export type StrapiDB = { query(uid: string): StrapiDBQuery; }; export type StrapiDBQuery = { findOne(args: number | string | StrapiDBQueryArgs): Promise; findMany(args?: StrapiDBQueryArgs): Promise>; findWithCount( args: StrapiDBQueryArgs ): Promise<[items: Array, count: number]>; create(args: StrapiDBQueryArgs): Promise; createMany(args: StrapiDBQueryArgs): Promise; update(args: StrapiDBQueryArgs): Promise; updateMany(args: StrapiDBQueryArgs): Promise; delete(args: StrapiDBQueryArgs): Promise; deleteMany(args: StrapiDBQueryArgs): Promise; count(args?: StrapiDBQueryArgs): number; }; // https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/query-engine/filtering.html#logical-operators type EqualWhereOperator = { $eq: T }; type NotEqualWhereOperator = { $ne: T }; type InWhereOperator = { $in: Array }; type NotInWhereOperator = { $notIn: Array }; type LessThanWhereOperator = { $lt: number }; type LessThanEqualWhereOperator = { $lte: number }; type GreaterThanWhereOperator = { $gt: number }; type GreaterThanEqualWhereOperator = { $gte: number }; type BetweenWhereOperator = { $between: Array }; type ContainsWhereOperator = { $contains: string }; type NotContainsWhereOperator = { $notContains: string }; type ContainsCaseInsensitiveWhereOperator = { $containsi: string }; type NotContainsCaseInsensitiveWhereOperator = { $notContainsi: string }; type StartsWithWhereOperator = { $startsWith: string }; type EndsWithWhereOperator = { $endsWith: string }; type IsNullWhereOperator = { $null: boolean }; type IsNotNullWhereOperator = { $notNull: boolean }; type NotWhereOperator = { $not: { [TKey]: [TValue]; }; }; type AndWhereOperator = { $and: Partial[] }; type OrWhereOperator = { $or: Partial[] }; type WhereOperator = | T | EqualWhereOperator | NotEqualWhereOperator | InWhereOperator | NotInWhereOperator | LessThanWhereOperator | LessThanEqualWhereOperator | GreaterThanWhereOperator | GreaterThanEqualWhereOperator | BetweenWhereOperator | ContainsWhereOperator | NotContainsWhereOperator | ContainsCaseInsensitiveWhereOperator | NotContainsCaseInsensitiveWhereOperator | StartsWithWhereOperator | EndsWithWhereOperator | EndsWithWhereOperator | IsNullWhereOperator | IsNotNullWhereOperator; type WhereClause = Partial< Record> & OrWhereOperator>>> & AndWhereOperator>>> >; type PopulateClause = Partial | StringMap>> | Array | boolean; type SelectClause = TKeys | Array | '*'; export type StrapiDBQueryArgs = { select?: SelectClause>; where?: WhereClause>; data?: TData; offset?: number; limit?: number; populate?: PopulateClause>; orderBy?: string | Array; }; export type StrapiDBBulkActionResponse = { count: number; }; export type StrapiAdmin = any; export type StrapiAdminInstance = { addMenuLink: (input: ToBeFixed) => ToBeFixed createSettingSection: (...input: Array) => ToBeFixed addReducers: (input: ToBeFixed) => ToBeFixed registerPlugin: (input: ToBeFixed) => ToBeFixed customFields: StrapiAdminCustomFields } export type StrapiLog = { log: Function; error: Function; warn: Function; }; export type StrapiCron = { add: Function; remove: Function; jobs: any[]; }; export type AllowedCustomFieldType = | "biginteger" | "boolean" | "date" | "datetime" | "decimal" | "email" | "enumeration" | "float" | "integer" | "json" | "password" | "richtext" | "string" | "text" | "time" | "timestamp" | "uid"; export type StrapiServerCustomFieldRegisterInput = { name: string; plugin?: string; type: AllowedCustomFieldType; }; export type StrapiServerCustomFields = { register: (input: StrapiServerCustomFieldRegisterInput) => void; }; export export type CustomFieldInputAttribute = { type: string; customField: string; } export export type CustomFieldInputOption = { key: string; value: string; } export export type CustomFieldInputProps = { attribute: CustomFieldInputAttribute; contentTypeUID: string; multiple: boolean; withDefaultValue: boolean; description?: string; disabled: boolean; intlLabel: MessageDescriptor; labelAction: string; error?: ToBeFixed; name: string; options: CustomFieldInputOption[]; required: boolean; placeholder?: string; type: string; value?: unknown; onChange?: React.EventHandler } export type StrapiAdminCustomFieldRegisterInput = { pluginId?: string; icon?: React.ComponentType; intlLabel: MessageDescriptor; intlDescription: MessageDescriptor; // TODO: update once implementation doesn't require async components read components: { Input: () => Promise }; options: { base: Array; advanced: Array; validator: (...args: Array) => Record }, } & StrapiServerCustomFieldRegisterInput; export type StrapiAdminCustomFields = { register: (input: StrapiAdminCustomFieldRegisterInput) => void; }; export type StrapiRoute = { method: HTTPMethod; path: string; handler: string; config: StrapiRouteConfig; }; export type StrapiRouteConfig = { policies: Array; description?: string; tag?: StrapiRouteConfigTag; }; export type StrapiRouteConfigTag = { plugin: string; name?: string; actionType?: string; }; export type StrapiAdminUser = any; export type StrapiUser = { id: Id; email: string; username: string; } & StringMap; export type StrapiContext = { strapi: IStrapi; };