import { Constructor, Context, FindConfig, IDmlEntity, InferEntityForModuleService, InferEntityType, Pluralize, Prettify, RestoreReturn, SoftDeleteReturn } from "@medusajs/types"; import { EventArgs } from "@mikro-orm/core"; import { DmlEntity } from "../../dml"; export type BaseMethods = "retrieve" | "list" | "listAndCount" | "delete" | "softDelete" | "restore" | "create" | "update"; export type ModelDTOConfig = { dto: object; model?: DmlEntity; create?: any; update?: any; }; export type ModelsConfigTemplate = { [key: string]: ModelDTOConfig; }; /** * We do not want the DML DTO to accept auto-managed timestamps * as part of the input for the "create" and the "update" * methods */ type DMLDTOExcludeProperties = "created_at" | "updated_at" | "deleted_at"; export type ModelConfigurationsToConfigTemplate = { [Key in keyof T]: { dto: T[Key] extends DmlEntity ? InferEntityType : T[Key] extends Constructor ? InstanceType : any; inputDto: T[Key] extends DmlEntity ? Omit, DMLDTOExcludeProperties> : T[Key] extends Constructor ? InstanceType : any; model: T[Key] extends { model: infer MODEL; } ? MODEL : T[Key] extends IDmlEntity ? T[Key] : never; }; }; /** * @deprecated should all notion of singular and plural be removed once all modules are aligned with the convention */ export type ExtractSingularName, K = keyof T> = Capitalize; /** * @deprecated should all notion of singular and plural be removed once all modules are aligned with the convention * The pluralize will move to where it should be used instead */ export type ExtractPluralName, K = keyof T> = Capitalize>; export type ModelEntries = Record /** * @deprecated */ | Constructor /** * @deprecated */ | { name?: string; singular?: string; plural?: string; }>; /** * Returns the input DTO for the servide */ type GetServiceInput = Partial<[ undefined ] extends ModelConfig["inputDto"] ? ModelConfig["dto"] : ModelConfig["inputDto"]>; export type ExtractKeysFromConfig = ModelsConfig extends { __empty: any; } ? string : keyof ModelsConfig; export type AbstractModuleService> = { [TModelName in keyof TModelsDtoConfig as `retrieve${ExtractSingularName}`]: (id: string, config?: FindConfig, sharedContext?: Context) => Promise; } & { [TModelName in keyof TModelsDtoConfig as `list${ExtractPluralName}`]: (filters?: any, config?: FindConfig, sharedContext?: Context) => Promise; } & { [TModelName in keyof TModelsDtoConfig as `listAndCount${ExtractPluralName}`]: { (filters?: any, config?: FindConfig, sharedContext?: Context): Promise<[TModelsDtoConfig[TModelName]["dto"][], number]>; }; } & { [TModelName in keyof TModelsDtoConfig as `delete${ExtractPluralName}`]: { (primaryKeyValues: string | object | string[] | object[], sharedContext?: Context): Promise; }; } & { [TModelName in keyof TModelsDtoConfig as `softDelete${ExtractPluralName}`]: { (primaryKeyValues: string | object | string[] | object[], config?: SoftDeleteReturn, sharedContext?: Context): Promise | void>; }; } & { [TModelName in keyof TModelsDtoConfig as `restore${ExtractPluralName}`]: { (primaryKeyValues: string | object | string[] | object[], config?: RestoreReturn, sharedContext?: Context): Promise | void>; }; } & { [TModelName in keyof TModelsDtoConfig as `create${ExtractPluralName}`]: { (data: Prettify>, ...rest: any[]): Promise; (data: Prettify>[], ...rest: any[]): Promise; }; } & { [TModelName in keyof TModelsDtoConfig as `update${ExtractPluralName}`]: { (data: Prettify>, ...rest: any[]): Promise; (dataOrOptions: Prettify>[] | { selector: Record; data: Prettify> | Prettify>[]; } | { selector: Record; data: Prettify> | Prettify>[]; }[], ...rest: any[]): Promise; }; }; type InferModelFromConfig = { [K in keyof T as T[K] extends { model: any; } ? K : K extends IDmlEntity ? K : never]: T[K] extends { model: infer MODEL; } ? MODEL extends IDmlEntity ? MODEL : never : T[K] extends IDmlEntity ? T[K] : never; }; export type MedusaServiceReturnType> = { new (...args: any[]): AbstractModuleService; $modelObjects: InferModelFromConfig; /** * helper function to aggregate events. Will format the message properly and store in * the message aggregator in the context * @param action * @param object * @param eventName optional, can be inferred from the module joiner config + action + object * @param source optional, can be inferred from the module joiner config * @param data * @param context */ aggregatedEvents({ action, object, eventName, source, data, context, }: { action: string; object: string; eventName: string; source?: string; data: { id: any; } | { id: any; }[]; context: Context; }): void; /** * this method is meant to react to any event the orm might emit * when an entity is being mutated (created, updated, deleted). * The default implementation will handle all event to be emitted as part * of the message aggregator from the context. * * If you want to handle the event differently, you can override this method. * * @param event - The event type * @param args - The event arguments * @param context - The context */ interceptEntityMutationEvents(event: "afterCreate" | "afterUpdate" | "afterUpsert" | "afterDelete", args: EventArgs, context: Context): void; }; export {}; //# sourceMappingURL=medusa-service.d.ts.map