import { ActionSchema, Context, Validators, Middleware, EventSchema, Service, ServiceHooks, Logger, ServiceBroker, ActionEndpoint, EventEndpoint, Span } from 'moleculer'; import { ObjectId } from 'bson'; import { ZodType, z } from 'zod/v4'; import { Options, ErrorObject } from 'ajv/dist/2019.js'; import { LoggerOptions, Logger as Logger$1 } from 'pino'; import { PrettyOptions } from 'pino-pretty'; type UnionToIntersection$1 = (U extends any ? (_: U) => void : never) extends (_: infer I) => void ? I : never; type SomeJSONSchema = JSONSchemaType; type PartialSchema = Partial>; type JSONType = IsPartial extends true ? T | undefined : T; interface NumberKeywords { minimum?: number; maximum?: number; exclusiveMinimum?: number; exclusiveMaximum?: number; multipleOf?: number; format?: string; } interface StringKeywords { minLength?: number; maxLength?: number; pattern?: string; format?: string; } type JSONSchemaType = (// these two unions allow arbitrary unions of types { anyOf: readonly JSONSchemaType[]; } | { oneOf: readonly JSONSchemaType[]; } | { allOf: readonly JSONSchemaType[]; } | ({ type: readonly (T extends number ? JSONType<'number' | 'integer', IsPartial> : T extends string ? JSONType<'string', IsPartial> : T extends boolean ? JSONType<'boolean', IsPartial> : never)[]; } & UnionToIntersection$1) | ((T extends number ? { type: JSONType<'number' | 'integer', IsPartial>; } & NumberKeywords : T extends string ? { type: JSONType<'string', IsPartial>; } & StringKeywords : T extends boolean ? { type: JSONType<'boolean', IsPartial>; } : T extends Date ? { type: JSONType<'string', IsPartial>; format: 'date-time' | 'date'; } : T extends Buffer ? { instanceof: 'Buffer'; } : T extends null ? { type: JSONType<'null', IsPartial>; } | { nullable?: true; } : T extends ObjectId ? { type: JSONType<'string', IsPartial>; format: 'object-id'; } : T extends [any, ...any[]] ? { type: JSONType<'array', IsPartial>; items: { readonly [K in keyof T]-?: JSONSchemaType & Nullable; } & { length: T['length']; }; minItems: T['length']; } & ({ maxItems: T['length']; } | { additionalItems: false; }) : T extends readonly any[] ? { type: JSONType<'array', IsPartial>; items: JSONSchemaType; contains?: PartialSchema; minItems?: number; maxItems?: number; minContains?: number; maxContains?: number; uniqueItems?: true; additionalItems?: never; } : T extends Record ? { type: JSONType<'object', IsPartial>; required: IsPartial extends true ? Readonly<(keyof T)[]> : Readonly[]>; additionalProperties?: boolean | JSONSchemaType; unevaluatedProperties?: boolean | JSONSchemaType; discriminator?: { propertyName: keyof T; }; properties?: IsPartial extends true ? Partial> : PropertiesSchema; patternProperties?: Record>; propertyNames?: Omit, 'type'> & { type?: 'string'; }; dependencies?: { [K in keyof T]?: Readonly<(keyof T)[]> | PartialSchema; }; dependentRequired?: { [K in keyof T]?: Readonly<(keyof T)[]>; }; dependentSchemas?: { [K in keyof T]?: PartialSchema; }; minProperties?: number; maxProperties?: number; } : T extends null ? { type: JSONType<'null', IsPartial>; nullable: true; } : never) & { allOf?: Readonly[]>; anyOf?: Readonly[]>; oneOf?: Readonly[]>; if?: PartialSchema; then?: PartialSchema; else?: PartialSchema; not?: PartialSchema; })) & { [keyword: string]: any; $id?: string; $ref?: string; $defs?: Record>; definitions?: Record>; }; type Known = { [key: string]: Known; } | [Known, ...Known[]] | Known[] | number | string | boolean | null; type PropertiesSchema = { [K in keyof T]-?: (JSONSchemaType & Nullable) | { $ref: string; }; }; type RequiredMembers = { [K in keyof T]-?: undefined extends T[K] ? never : K; }[keyof T]; type Nullable = undefined extends T ? { nullable?: true; const?: never; enum?: Readonly<(T | null)[]>; default?: T | null; } : { const?: T; enum?: Readonly; default?: T; }; interface ContactObject { name?: string; url?: string; email?: string; } interface LicenseObject { name: string; url?: string; } interface InfoObject { title: string; description?: string; termsOfService?: string; contact?: ContactObject; license?: LicenseObject; version: string; } interface ServerVariableObject { enum?: string[]; default: string; description?: string; } interface ServerObject { url: string; description?: string; variables?: Record; } type PathsObject = Record; interface ExternalDocumentationObject { description?: string; url: string; } interface ParameterObject extends ParameterBaseObject { name: string; in: string; } type HeaderObject = ParameterBaseObject; interface ParameterBaseObject { description?: string; required?: boolean; deprecated?: boolean; allowEmptyValue?: boolean; style?: string; explode?: boolean; allowReserved?: boolean; schema?: ReferenceObject | SchemaObject; example?: any; examples?: Record; content?: Record; } type SchemaObject = JSONSchemaType; interface ReferenceObject { $ref: string; } interface ExampleObject { summary?: string; description?: string; value?: any; externalValue?: string; } interface EncodingObject { contentType?: string; headers?: Record; style?: string; explode?: boolean; allowReserved?: boolean; } interface MediaTypeObject { schema?: ReferenceObject | SchemaObject; example?: any; examples?: Record; encoding?: Record; } interface RequestBodyObject { description?: string; content: Record; required?: boolean; } interface LinkObject { operationRef?: string; operationId?: string; parameters?: Record; requestBody?: any; description?: string; server?: ServerObject; } interface ResponseObject { description: string; headers?: Record; content?: Record; links?: Record; } type ResponsesObject = Record; type SecurityRequirementObject = Record; interface HttpSecurityScheme { type: 'http'; description?: string; scheme: string; bearerFormat?: string; } interface ApiKeySecurityScheme { type: 'apiKey'; description?: string; name: string; in: string; } interface OAuth2SecurityScheme { type: 'oauth2'; flows: { implicit?: { authorizationUrl: string; refreshUrl?: string; scopes: Record; }; password?: { tokenUrl: string; refreshUrl?: string; scopes: Record; }; clientCredentials?: { tokenUrl: string; refreshUrl?: string; scopes: Record; }; authorizationCode?: { authorizationUrl: string; tokenUrl: string; refreshUrl?: string; scopes: Record; }; }; } interface OpenIdSecurityScheme { type: 'openIdConnect'; description?: string; openIdConnectUrl: string; } type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme; type CallbackObject = Record; interface ComponentsObject { schemas?: Record; responses?: Record; parameters?: Record; examples?: Record; requestBodies?: Record; headers?: Record; securitySchemes?: Record; links?: Record; callbacks?: Record; } interface TagObject { name: string; description?: string; externalDocs?: ExternalDocumentationObject; } interface OperationObject { tags?: string[]; summary?: string; description?: string; externalDocs?: ExternalDocumentationObject; operationId?: string; parameters?: (ReferenceObject | ParameterObject)[]; requestBody?: ReferenceObject | RequestBodyObject; responses?: ResponsesObject; callbacks?: Record; deprecated?: boolean; security?: SecurityRequirementObject[]; servers?: ServerObject[]; } interface PathItemObject { $ref?: string; summary?: string; description?: string; get?: OperationObject; put?: OperationObject; post?: OperationObject; delete?: OperationObject; options?: OperationObject; head?: OperationObject; patch?: OperationObject; trace?: OperationObject; servers?: ServerObject[]; parameters?: (ReferenceObject | ParameterObject)[]; } interface Document { openapi: string; info: InfoObject; servers?: ServerObject[]; paths: PathsObject; components?: ComponentsObject; security?: SecurityRequirementObject[]; tags?: TagObject[]; externalDocs?: ExternalDocumentationObject; 'x-express-openapi-additional-middleware'?: (((request: any, response: any, next: any) => Promise) | ((request: any, response: any, next: any) => void))[]; 'x-express-openapi-validation-strict'?: boolean; } /** * Redefine RestSchema from API gateway to add type support */ interface CustomRestSchema { path?: string; method?: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH'; fullPath?: string; basePath?: string; type?: 'call' | 'stream' | 'multipart'; } interface CustomActionSchema extends Omit { params?: unknown; handler?: (ctx: Context) => Promise | T; disableTransforms?: boolean; openAPINames?: string[] | null; openapi?: OperationObject; bodySchemaRefName?: string; rest?: CustomRestSchema | CustomRestSchema[] | string | string[] | null; } type Alias = { actionName: string; path: string; fullPath: string; methods: string; routePath: string; action: CustomActionSchema; }; type ValidationSchema = JSONSchemaType; type Transform = (val: T) => U; type TransformLevel = { type: 'access'; key: string; } | { type: 'this'; } | { type: 'loop'; } | { type: 'select'; subTransforms: TransformField[]; }; type TransformField = TransformLevel[]; type TransformMap = WeakMap; interface Transformer { transformMap: TransformMap; beforeTransformer: Transform; afterTransformer: Transform; findTransforms: (schema: ValidationSchema) => TransformField[]; } type ZodActionOrEventSchema = { params?: ZodType; }; /** * Use zod for schema validation. * DO NOT support Async refinements/transforms yet. * * Transforms MUST BE handled by the consumer directly. */ declare class ZodValidator extends Validators.Base { constructor(); compile(): Validators.Base.CheckerFunction; validate(params: unknown, schema: S, ctx?: Context): z.output; /** * Override BaseValidator middleware to handle our custom compile function. */ middleware(): { name: string; localAction: (handler: any, action: ZodActionOrEventSchema) => any; localEvent: (handler: any, event: ZodActionOrEventSchema) => any; }; convertSchemaToMoleculer(): Record; } declare module 'moleculer' { namespace Validators { interface Base { validate(params: unknown, schema: S): z.output; } } } type AjvValidatorCheckFnOption = { meta: { ctx: Context; }; }; /** * Moleculer validator using Ajv/zod for schema validation. * * It also supports some additional features: * - Property transformations depending on the schema (Dates, ObjectIds, array coercion) * - Ref extractor, used to optimize schema compilation, and generate better OpenAPI specs * * Some config can be done at the action level: * - disableTransforms: Disable all transformations for this action * - validatorMode: Use a different validator mode for this action */ declare class AjvValidator extends Validators.Base { private readonly modes; private readonly defaultMode; readonly zodValidator?: ZodValidator; /** * Cache of compiled validation functions. * This is because compiling a schema is quite expensive for Ajv. */ private compiledFns; constructor(opts: Record, defaultMode: Mode, zodValidator?: ZodValidator); /** * Validate a set of parameters against a schema. * * May have a small performance hit on the first call for a specific schema, * as it will compile the schema. */ validate(params: unknown, schema: ValidationSchema): true; validate(params: unknown, schema: S): z.output; /** * This method compiles a schema into a validation function. * * Compiling a schema is quite expensive, so it will only be done once per schema. */ compile(schema: ValidationSchema, mode?: Mode): (params: unknown, opts?: AjvValidatorCheckFnOption) => boolean; /** * For debugging purposes, log the validation errors. * This is only enabled if the DETAILED_AJV_VALIDATION_ERRORS env var is set to 'yes'. */ logError(name: string, schema: ValidationSchema, errors?: null | ErrorObject[]): void; /** * We wrap the localAction and localEvent methods to add validation to the actions and events handlers. * Note that we lazy compile schemas in order to avoid a performance hit on startup. */ middleware(): Middleware; convertSchemaToMoleculer(): Record; } declare module 'moleculer' { namespace Validators { interface Base { validate(params: unknown, schema: ValidationSchema): true; } } } type UnionToIntersection = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I & U : never; type OptionallyArray = T | T[]; type ServiceEventSchema = EventSchema & { params?: unknown; }; /** * For ONE particular mixin, return methods and settings. * Will recursively check mixins. */ type InjectedByMixin = (Mixin extends { mixins?: infer NestedMixin; } ? InjectMixins> : object) & (Mixin extends { methods?: infer Methods; } ? Methods : object) & (Mixin extends { settings?: infer Settings; } ? { settings: Settings; } : object); /** * For a list of mixins, get the merged resulting object to be injected */ type InjectMixins = Mixins extends readonly unknown[] ? UnionToIntersection> : object; /** * Outside injected props, we have some basic props. * We also allow any "other" props as unknown to give back some freedom. * */ interface BaseService { actions: never; settings: Settings; [key: string | symbol]: unknown; } /** * This type represent what is accessible from the `this` in a service file. * It tries to infer from generics: * - Direct methods * - Recursive mixins methods * * @internal Exported only for testing */ type ServiceWithInference = Service & Methods & InjectMixins & BaseService; /** * Type used for injecting `this` in an object. */ type ObjectServiceThis = T & ThisType>; /** * Type used for injecting `this` in a simple function. */ type CallbackServiceThis = (this: ServiceWithInference, ...params: Parameters) => Return; interface PartialCustomServiceSchema { name?: string; version?: string | number; dependencies?: OptionallyArray; metadata?: Record; settings?: Settings; hooks?: ServiceHooks; mixins?: Mixins; methods?: ObjectServiceThis; actions?: Record>; events?: Record>; created?: OptionallyArray>; started?: OptionallyArray | void, Settings, Methods, Mixins>>; stopped?: OptionallyArray | void, Settings, Methods, Mixins>>; merged?: OptionallyArray | void, Settings, Methods, Mixins, [ PartialCustomServiceSchema ]>>; } interface CustomServiceSchema extends PartialCustomServiceSchema { name: string; } /** * This class replace the default Context class in Moleculer to: * - Add a ctx.logger instance with the trace.id and span.id in the bindings */ declare class ContextFactory

, H = Record> extends Context { constructor(broker: ServiceBroker, endpoint: ActionEndpoint | EventEndpoint); startSpan(name: string, opts?: Record): Span; /** * Get a logger for this specific span of the context. */ setLogger(): void; } declare module 'moleculer' { interface Context { logger: Logger; } } type CreateLoggerOptions = LoggerOptions & { /** * Allow filtering messages, should only be used during development. */ filter?: RegExp; /** * Options related to the included prettifier (pino-pretty). */ prettyOptions?: { /** * Enable/Disable the prettifier transport. * If transport is specified, the default prettifier will be disabled. * * @default process.stdout.isTTY */ enabled?: boolean; /** * Options to be forwarded to pino-pretty. */ options?: PrettyOptions; }; }; type MoleculerLoggerConfigOptions = { /** * Pino logger instance to use. * * @default createLogger() */ logger?: Logger$1; /** * Name of the field added for context logging. `false` disable the field * @default 'trace.id' */ traceIdField?: string | false; /** * Name of the field added for context logging. `false` disable the field * @default 'span.id' */ spanIdField?: string | false; }; /** * Augment pino to something closer to what Moleculer is using. */ declare module 'pino' { interface LogFn { (msg: string, ...args: (Error | object)[]): void; } } export { ZodValidator as Z, AjvValidator as d, ContextFactory as i }; export type { Alias as A, ResponsesObject as B, CustomActionSchema as C, Document as D, EncodingObject as E, SecurityRequirementObject as F, SecuritySchemeObject as G, HeaderObject as H, InfoObject as I, JSONSchemaType as J, ServerObject as K, LicenseObject as L, MoleculerLoggerConfigOptions as M, ServerVariableObject as N, OperationObject as O, PartialCustomServiceSchema as P, Transform as Q, ReferenceObject as R, SomeJSONSchema as S, TagObject as T, TransformField as U, TransformLevel as V, TransformMap as W, Transformer as X, ValidationSchema as Y, SchemaObject as a, CustomServiceSchema as b, CreateLoggerOptions as c, ApiKeySecurityScheme as e, CallbackObject as f, ComponentsObject as g, ContactObject as h, ExampleObject as j, ExternalDocumentationObject as k, HttpSecurityScheme as l, CallbackServiceThis as m, ObjectServiceThis as n, LinkObject as o, MediaTypeObject as p, OAuth2SecurityScheme as q, OpenIdSecurityScheme as r, ParameterBaseObject as s, ParameterObject as t, PathItemObject as u, PathsObject as v, PropertiesSchema as w, RequestBodyObject as x, RequiredMembers as y, ResponseObject as z };