@treatwell/moleculer-essentials 2.0.0-beta.2 → 2.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- import { Document, WithoutId, InferIdType, ObjectId, Filter, WithId, OptionalId, FindOptions, CountDocumentsOptions, FindOneAndUpdateOptions, BulkWriteOptions, UpdateOptions, FindOneAndReplaceOptions, FindOneAndDeleteOptions, DeleteOptions, CollationOptions, CreateCollectionOptions, MongoClient, CollectionOptions, Collection, UpdateFilter, FindCursor, UpdateResult } from 'mongodb';
2
- import { ActionVisibility, BaseValidator, Errors, Context } from 'moleculer';
1
+ import { Document, ObjectId, WithoutId, InferIdType, Filter, OptionalId, WithId, CountDocumentsOptions, DeleteOptions, FindOneAndDeleteOptions, FindOptions, BulkWriteOptions, FindOneAndUpdateOptions, UpdateOptions, FindOneAndReplaceOptions, CollationOptions, CreateCollectionOptions, MongoClient, CollectionOptions, Collection, UpdateFilter, FindCursor, UpdateResult } from 'mongodb';
2
+ import { ActionVisibility, Validators, Errors, Context } from 'moleculer';
3
3
  import { ZodType, ZodObject } from 'zod/v4';
4
- import { V as ValidationSchema, J as JSONSchemaType, C as CustomActionSchema, a as CustomServiceSchema } from '../types-BEknQmfU.cjs';
4
+ import { X as ValidationSchema, J as JSONSchemaType, C as CustomActionSchema, a as CustomServiceSchema } from '../types-DLBNHgt4.cjs';
5
5
  import { Readable } from 'stream';
6
6
  import 'bson';
7
7
  import 'ajv/dist/2019.js';
@@ -224,7 +224,7 @@ declare class AjvActionSchemaFactory<TSchema extends Document> implements Action
224
224
  declare function addQueryOps<T>(schema: JSONSchemaType<T>, queryOps: QueryOp[]): JSONSchemaType<unknown>;
225
225
 
226
226
  declare function parseStringifiedQuery<TSchema extends Document>(sQuery?: string): Filter<TSchema>;
227
- declare function parseAndValidateQuery<TSchema extends Document>(validator: BaseValidator, schema: ValidationSchema | ZodType | undefined, sQuery: string | undefined): Filter<TSchema>;
227
+ declare function parseAndValidateQuery<TSchema extends Document>(validator: Validators.Base, schema: ValidationSchema | ZodType | undefined, sQuery: string | undefined): Filter<TSchema>;
228
228
 
229
229
  type DatabaseSoftDeleteScope = 'include-deleted' | 'only-deleted' | 'no-deleted';
230
230
  /**
@@ -1,7 +1,7 @@
1
- import { Document, WithoutId, InferIdType, ObjectId, Filter, WithId, OptionalId, FindOptions, CountDocumentsOptions, FindOneAndUpdateOptions, BulkWriteOptions, UpdateOptions, FindOneAndReplaceOptions, FindOneAndDeleteOptions, DeleteOptions, CollationOptions, CreateCollectionOptions, MongoClient, CollectionOptions, Collection, UpdateFilter, FindCursor, UpdateResult } from 'mongodb';
2
- import { ActionVisibility, BaseValidator, Errors, Context } from 'moleculer';
1
+ import { Document, ObjectId, WithoutId, InferIdType, Filter, OptionalId, WithId, CountDocumentsOptions, DeleteOptions, FindOneAndDeleteOptions, FindOptions, BulkWriteOptions, FindOneAndUpdateOptions, UpdateOptions, FindOneAndReplaceOptions, CollationOptions, CreateCollectionOptions, MongoClient, CollectionOptions, Collection, UpdateFilter, FindCursor, UpdateResult } from 'mongodb';
2
+ import { ActionVisibility, Validators, Errors, Context } from 'moleculer';
3
3
  import { ZodType, ZodObject } from 'zod/v4';
4
- import { V as ValidationSchema, J as JSONSchemaType, C as CustomActionSchema, a as CustomServiceSchema } from '../types-BEknQmfU.mjs';
4
+ import { X as ValidationSchema, J as JSONSchemaType, C as CustomActionSchema, a as CustomServiceSchema } from '../types-DLBNHgt4.mjs';
5
5
  import { Readable } from 'stream';
6
6
  import 'bson';
7
7
  import 'ajv/dist/2019.js';
@@ -224,7 +224,7 @@ declare class AjvActionSchemaFactory<TSchema extends Document> implements Action
224
224
  declare function addQueryOps<T>(schema: JSONSchemaType<T>, queryOps: QueryOp[]): JSONSchemaType<unknown>;
225
225
 
226
226
  declare function parseStringifiedQuery<TSchema extends Document>(sQuery?: string): Filter<TSchema>;
227
- declare function parseAndValidateQuery<TSchema extends Document>(validator: BaseValidator, schema: ValidationSchema | ZodType | undefined, sQuery: string | undefined): Filter<TSchema>;
227
+ declare function parseAndValidateQuery<TSchema extends Document>(validator: Validators.Base, schema: ValidationSchema | ZodType | undefined, sQuery: string | undefined): Filter<TSchema>;
228
228
 
229
229
  type DatabaseSoftDeleteScope = 'include-deleted' | 'only-deleted' | 'no-deleted';
230
230
  /**
@@ -1,4 +1,4 @@
1
- import { o as omitFields, d as optionalFields, S as SCHEMA_REF_NAME, O as OBJECTID_TYPE, C as COERCE_ARRAY_ATTRIBUTE, i as isZodSchema, h as zodObjectId, j as zodCoerceArray, k as createOpenAPIResponses } from '../index-B6AujuxZ.mjs';
1
+ import { g as optionalFields, o as omitFields, S as SCHEMA_REF_NAME, O as OBJECTID_TYPE, C as COERCE_ARRAY_ATTRIBUTE, i as isZodSchema, k as zodObjectId, h as zodCoerceArray, e as createOpenAPIResponses } from '../index-DNiA_V_T.mjs';
2
2
  import { Errors } from 'moleculer';
3
3
  import { isEqual as isEqual$1 } from 'es-toolkit';
4
4
  import { z } from 'zod/v4';
@@ -308,7 +308,7 @@ function parseStringifiedQuery(sQuery) {
308
308
  if (!sQuery) {
309
309
  return {};
310
310
  }
311
- let query = {};
311
+ let query;
312
312
  try {
313
313
  query = JSON.parse(sQuery || "{}");
314
314
  } catch {
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.cjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.cjs';
2
2
  import { buildClient, NodeCachingMaterialsManager } from '@aws-crypto/client-node';
3
3
  import 'moleculer';
4
4
  import 'bson';
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.mjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.mjs';
2
2
  import { buildClient, NodeCachingMaterialsManager } from '@aws-crypto/client-node';
3
3
  import 'moleculer';
4
4
  import 'bson';
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.cjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.cjs';
2
2
  import 'moleculer';
3
3
  import 'bson';
4
4
  import 'zod/v4';
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.mjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.mjs';
2
2
  import 'moleculer';
3
3
  import 'bson';
4
4
  import 'zod/v4';
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.cjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.cjs';
2
2
  import { SignOptions, PrivateKey, VerifyOptions, JwtHeader, SigningKeyCallback } from 'jsonwebtoken';
3
3
  import { Options, JwksClient } from 'jwks-rsa';
4
4
  import { Context } from 'moleculer';
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.mjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.mjs';
2
2
  import { SignOptions, PrivateKey, VerifyOptions, JwtHeader, SigningKeyCallback } from 'jsonwebtoken';
3
3
  import { Options, JwksClient } from 'jwks-rsa';
4
4
  import { Context } from 'moleculer';
@@ -139,6 +139,9 @@ function QueueEventsClient(queueName, opts) {
139
139
  * Same as addJob but will also wait for the job to finish before returning.
140
140
  */
141
141
  async addAndWait(qName, name, data, jOpts, ttl) {
142
+ if (!("addJob" in this)) {
143
+ throw new Error(`Missing QueueClient mixin on service ${this.name}`);
144
+ }
142
145
  const job = await this.addJob(qName, name, data, jOpts);
143
146
  return job.waitUntilFinished(this.getQueueEvents(qName), ttl);
144
147
  },
@@ -146,6 +149,9 @@ function QueueEventsClient(queueName, opts) {
146
149
  * Same as addBulkJob but will also wait for the jobs to finish before returning.
147
150
  */
148
151
  async addBulkAndWait(qName, name, data, jOpts, ttl) {
152
+ if (!("addBulkJob" in this)) {
153
+ throw new Error(`Missing QueueClient mixin on service ${this.name}`);
154
+ }
149
155
  const jobs = await this.addBulkJob(qName, name, data, jOpts);
150
156
  const q = this.getQueueEvents(qName);
151
157
  return Promise.all(jobs.map((j) => j.waitUntilFinished(q, ttl)));
@@ -219,7 +225,7 @@ function QueueFlowProducerMixin(opts) {
219
225
  this[kConnection$1] = connection;
220
226
  },
221
227
  async stopped() {
222
- await this.$flowProducer?.close();
228
+ await this.getFlowProducer()?.close();
223
229
  this[kConnection$1]?.disconnect();
224
230
  }
225
231
  });
@@ -406,7 +412,7 @@ function QueueWorker(queueName, opts, processorOptions = {}) {
406
412
  }
407
413
  },
408
414
  async stopped() {
409
- await this.$worker?.close();
415
+ await this.getWorker()?.close();
410
416
  this[kConnection]?.disconnect();
411
417
  }
412
418
  });
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.cjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.cjs';
2
2
  import { Redis } from 'ioredis';
3
3
  import { QueueOptions, Queue, JobsOptions, Job, QueueEventsOptions, QueueEvents, QueueBaseOptions, FlowProducer, RepeatOptions, WorkerOptions, Worker } from 'bullmq';
4
4
  import { Service } from 'moleculer';
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.mjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.mjs';
2
2
  import { Redis } from 'ioredis';
3
3
  import { QueueOptions, Queue, JobsOptions, Job, QueueEventsOptions, QueueEvents, QueueBaseOptions, FlowProducer, RepeatOptions, WorkerOptions, Worker } from 'bullmq';
4
4
  import { Service } from 'moleculer';
@@ -137,6 +137,9 @@ function QueueEventsClient(queueName, opts) {
137
137
  * Same as addJob but will also wait for the job to finish before returning.
138
138
  */
139
139
  async addAndWait(qName, name, data, jOpts, ttl) {
140
+ if (!("addJob" in this)) {
141
+ throw new Error(`Missing QueueClient mixin on service ${this.name}`);
142
+ }
140
143
  const job = await this.addJob(qName, name, data, jOpts);
141
144
  return job.waitUntilFinished(this.getQueueEvents(qName), ttl);
142
145
  },
@@ -144,6 +147,9 @@ function QueueEventsClient(queueName, opts) {
144
147
  * Same as addBulkJob but will also wait for the jobs to finish before returning.
145
148
  */
146
149
  async addBulkAndWait(qName, name, data, jOpts, ttl) {
150
+ if (!("addBulkJob" in this)) {
151
+ throw new Error(`Missing QueueClient mixin on service ${this.name}`);
152
+ }
147
153
  const jobs = await this.addBulkJob(qName, name, data, jOpts);
148
154
  const q = this.getQueueEvents(qName);
149
155
  return Promise.all(jobs.map((j) => j.waitUntilFinished(q, ttl)));
@@ -217,7 +223,7 @@ function QueueFlowProducerMixin(opts) {
217
223
  this[kConnection$1] = connection;
218
224
  },
219
225
  async stopped() {
220
- await this.$flowProducer?.close();
226
+ await this.getFlowProducer()?.close();
221
227
  this[kConnection$1]?.disconnect();
222
228
  }
223
229
  });
@@ -404,7 +410,7 @@ function QueueWorker(queueName, opts, processorOptions = {}) {
404
410
  }
405
411
  },
406
412
  async stopped() {
407
- await this.$worker?.close();
413
+ await this.getWorker()?.close();
408
414
  this[kConnection]?.disconnect();
409
415
  }
410
416
  });
@@ -36,8 +36,8 @@ function RedisMixin(options, { reuseClient = true, getOptions } = {}) {
36
36
  this.setClientToStore(
37
37
  "redis",
38
38
  key,
39
- this.redis,
40
- () => this.redis?.disconnect()
39
+ this.getRedis(),
40
+ () => this.getRedis()?.disconnect()
41
41
  );
42
42
  }
43
43
  },
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.cjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.cjs';
2
2
  import { RedisOptions, Redis } from 'ioredis';
3
3
  import { Service } from 'moleculer';
4
4
  import 'bson';
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.mjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.mjs';
2
2
  import { RedisOptions, Redis } from 'ioredis';
3
3
  import { Service } from 'moleculer';
4
4
  import 'bson';
@@ -34,8 +34,8 @@ function RedisMixin(options, { reuseClient = true, getOptions } = {}) {
34
34
  this.setClientToStore(
35
35
  "redis",
36
36
  key,
37
- this.redis,
38
- () => this.redis?.disconnect()
37
+ this.getRedis(),
38
+ () => this.getRedis()?.disconnect()
39
39
  );
40
40
  }
41
41
  },
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.cjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.cjs';
2
2
  import { Service } from 'moleculer';
3
3
  import { RedisOptions, Redis } from 'ioredis';
4
4
  import Redlock from 'redlock';
@@ -1,4 +1,4 @@
1
- import { a as CustomServiceSchema } from '../types-BEknQmfU.mjs';
1
+ import { a as CustomServiceSchema } from '../types-DLBNHgt4.mjs';
2
2
  import { Service } from 'moleculer';
3
3
  import { RedisOptions, Redis } from 'ioredis';
4
4
  import Redlock from 'redlock';
@@ -1,8 +1,8 @@
1
- import Moleculer__default, { RestSchema, ActionVisibility, Service, ActionCacheOptions, Context, TracingActionOptions, BulkheadOptions, BrokerCircuitBreakerOptions, RetryPolicyOptions, FallbackHandler, ActionHooks, Validators, ActionHandler, ActionSchema, ServiceEvent, ServiceDependency, ServiceHooks, GenericObject, ServiceBroker, Endpoint } from 'moleculer';
1
+ import { ActionSchema, Context, Validators, Middleware, EventSchema, Service, ServiceHooks, Logger, ServiceBroker, ActionEndpoint, EventEndpoint, Span } from 'moleculer';
2
2
  import { ObjectId } from 'bson';
3
3
  import { ZodType, z } from 'zod/v4';
4
4
  import { Options, ErrorObject } from 'ajv/dist/2019.js';
5
- import { LoggerOptions, Logger } from 'pino';
5
+ import { LoggerOptions, Logger as Logger$1 } from 'pino';
6
6
  import { PrettyOptions } from 'pino-pretty';
7
7
 
8
8
  type UnionToIntersection$1<U> = (U extends any ? (_: U) => void : never) extends (_: infer I) => void ? I : never;
@@ -333,24 +333,14 @@ interface Document {
333
333
  'x-express-openapi-validation-strict'?: boolean;
334
334
  }
335
335
 
336
- interface CustomActionSchema<T = unknown> {
337
- name?: string;
338
- rest?: RestSchema | RestSchema[] | string | string[];
339
- visibility?: ActionVisibility;
340
- service?: Service;
341
- cache?: boolean | ActionCacheOptions;
342
- handler?: (ctx: Context<never, never>) => Promise<T> | T;
343
- tracing?: boolean | TracingActionOptions;
344
- bulkhead?: BulkheadOptions;
345
- circuitBreaker?: BrokerCircuitBreakerOptions;
346
- retryPolicy?: RetryPolicyOptions;
347
- fallback?: string | FallbackHandler;
348
- hooks?: ActionHooks;
336
+ interface CustomActionSchema<T = unknown> extends Omit<ActionSchema, 'params' | 'handler'> {
349
337
  params?: unknown;
338
+ handler?: (ctx: Context<never, never>) => Promise<T> | T;
350
339
  disableTransforms?: boolean;
351
340
  openAPINames?: string[] | null;
352
341
  openapi?: OperationObject;
353
342
  bodySchemaRefName?: string;
343
+ rest?: string | string[];
354
344
  }
355
345
  type Alias = {
356
346
  actionName: string;
@@ -383,6 +373,9 @@ interface Transformer<T, U> {
383
373
  findTransforms: (schema: ValidationSchema) => TransformField[];
384
374
  }
385
375
 
376
+ type ZodActionOrEventSchema = {
377
+ params?: ZodType;
378
+ };
386
379
  /**
387
380
  * Use zod for schema validation.
388
381
  * DO NOT support Async refinements/transforms yet.
@@ -390,19 +383,32 @@ interface Transformer<T, U> {
390
383
  * Transforms MUST BE handled by the consumer directly.
391
384
  */
392
385
  declare class ZodValidator extends Validators.Base {
393
- compile(): () => void;
386
+ constructor();
387
+ compile(): Validators.Base.CheckerFunction;
394
388
  validate<S extends ZodType>(params: unknown, schema: S, ctx?: Context): z.output<S>;
395
389
  /**
396
390
  * Override BaseValidator middleware to handle our custom compile function.
397
391
  */
398
- middleware(): (handler: ActionHandler, action: ActionSchema) => unknown;
392
+ middleware(): {
393
+ name: string;
394
+ localAction: (handler: any, action: ZodActionOrEventSchema) => any;
395
+ localEvent: (handler: any, event: ZodActionOrEventSchema) => any;
396
+ };
397
+ convertSchemaToMoleculer(): Record<string, unknown>;
399
398
  }
400
399
  declare module 'moleculer' {
401
- interface BaseValidator {
402
- validate<S extends ZodType>(params: unknown, schema: S): z.output<S>;
400
+ namespace Validators {
401
+ interface Base {
402
+ validate<S extends ZodType>(params: unknown, schema: S): z.output<S>;
403
+ }
403
404
  }
404
405
  }
405
406
 
407
+ type AjvValidatorCheckFnOption = {
408
+ meta: {
409
+ ctx: Context;
410
+ };
411
+ };
406
412
  /**
407
413
  * Moleculer validator using Ajv/zod for schema validation.
408
414
  *
@@ -417,7 +423,6 @@ declare module 'moleculer' {
417
423
  declare class AjvValidator<Mode extends string> extends Validators.Base {
418
424
  private readonly modes;
419
425
  private readonly defaultMode;
420
- private readonly broker;
421
426
  readonly zodValidator?: ZodValidator;
422
427
  /**
423
428
  * Cache of compiled validation functions.
@@ -438,7 +443,7 @@ declare class AjvValidator<Mode extends string> extends Validators.Base {
438
443
  *
439
444
  * Compiling a schema is quite expensive, so it will only be done once per schema.
440
445
  */
441
- compile(schema: ValidationSchema, mode?: Mode): (params: unknown, ctx?: Context) => boolean;
446
+ compile(schema: ValidationSchema, mode?: Mode): (params: unknown, opts?: AjvValidatorCheckFnOption) => boolean;
442
447
  /**
443
448
  * For debugging purposes, log the validation errors.
444
449
  * This is only enabled if the DETAILED_AJV_VALIDATION_ERRORS env var is set to 'yes'.
@@ -448,11 +453,14 @@ declare class AjvValidator<Mode extends string> extends Validators.Base {
448
453
  * We wrap the localAction and localEvent methods to add validation to the actions and events handlers.
449
454
  * Note that we lazy compile schemas in order to avoid a performance hit on startup.
450
455
  */
451
- middleware(): (handler: ActionHandler, action: ActionSchema) => unknown;
456
+ middleware(): Middleware;
457
+ convertSchemaToMoleculer(): Record<string, unknown>;
452
458
  }
453
459
  declare module 'moleculer' {
454
- interface BaseValidator {
455
- validate(params: unknown, schema: ValidationSchema): true;
460
+ namespace Validators {
461
+ interface Base {
462
+ validate(params: unknown, schema: ValidationSchema): true;
463
+ }
456
464
  }
457
465
  }
458
466
 
@@ -460,7 +468,7 @@ type Unpacked<T> = T extends (infer U)[] ? U : never;
460
468
  type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
461
469
  type OptionallyArray<T> = T | T[];
462
470
 
463
- type ServiceEventSchema = ServiceEvent & {
471
+ type ServiceEventSchema = EventSchema & {
464
472
  params?: unknown;
465
473
  };
466
474
 
@@ -483,7 +491,7 @@ type CallbackServiceThis<Return, Settings, Methods, Mixins, Parameters extends u
483
491
  interface CustomServiceSchema<Settings, Methods, Mixins> {
484
492
  name: string;
485
493
  version?: string | number;
486
- dependencies?: OptionallyArray<string | ServiceDependency>;
494
+ dependencies?: OptionallyArray<string | Service.ServiceDependency>;
487
495
  metadata?: Record<string, unknown>;
488
496
  settings?: Settings;
489
497
  hooks?: ServiceHooks;
@@ -503,9 +511,9 @@ interface CustomServiceSchema<Settings, Methods, Mixins> {
503
511
  * This class replace the default Context class in Moleculer to:
504
512
  * - Add a ctx.logger instance with the trace.id and span.id in the bindings
505
513
  */
506
- declare class ContextFactory<P = unknown, M extends object = {}, L = GenericObject> extends Context<P, M, L> {
507
- constructor(broker: ServiceBroker, endpoint: Endpoint);
508
- startSpan(name: string, opts?: Moleculer__default.GenericObject): Moleculer__default.Span;
514
+ declare class ContextFactory<P = unknown, M extends object = {}, L = Record<string, unknown>, H = Record<string, unknown>> extends Context<P, M, L, H> {
515
+ constructor(broker: ServiceBroker, endpoint: ActionEndpoint | EventEndpoint);
516
+ startSpan(name: string, opts?: Record<string, unknown>): Span;
509
517
  /**
510
518
  * Get a logger for this specific span of the context.
511
519
  */
@@ -513,7 +521,7 @@ declare class ContextFactory<P = unknown, M extends object = {}, L = GenericObje
513
521
  }
514
522
  declare module 'moleculer' {
515
523
  interface Context {
516
- logger: Moleculer__default.LoggerInstance;
524
+ logger: Logger;
517
525
  }
518
526
  }
519
527
 
@@ -545,7 +553,7 @@ type MoleculerLoggerConfigOptions = {
545
553
  *
546
554
  * @default createLogger()
547
555
  */
548
- logger?: Logger;
556
+ logger?: Logger$1;
549
557
  /**
550
558
  * Name of the field added for context logging. `false` disable the field
551
559
  * @default 'trace.id'
@@ -566,5 +574,5 @@ declare module 'pino' {
566
574
  }
567
575
  }
568
576
 
569
- export { ZodValidator as Z, AjvValidator as e, ContextFactory as j };
570
- export type { Alias as A, OAuth2SecurityScheme as B, CustomActionSchema as C, Document as D, ExternalDocumentationObject as E, OpenIdSecurityScheme as F, SecuritySchemeObject as G, HeaderObject as H, InfoObject as I, JSONSchemaType as J, CallbackObject as K, LicenseObject as L, MoleculerLoggerConfigOptions as M, ComponentsObject as N, OperationObject as O, PropertiesSchema as P, TagObject as Q, ReferenceObject as R, SomeJSONSchema as S, Transformer as T, PathItemObject as U, ValidationSchema as V, ObjectServiceThis as W, CallbackServiceThis as X, CustomServiceSchema as a, SchemaObject as b, CreateLoggerOptions as c, RequiredMembers as d, Transform as f, TransformLevel as g, TransformMap as h, TransformField as i, ContactObject as k, ServerVariableObject as l, ServerObject as m, PathsObject as n, ParameterObject as o, ParameterBaseObject as p, ExampleObject as q, EncodingObject as r, MediaTypeObject as s, RequestBodyObject as t, LinkObject as u, ResponseObject as v, ResponsesObject as w, SecurityRequirementObject as x, HttpSecurityScheme as y, ApiKeySecurityScheme as z };
577
+ export { ZodValidator as Z, AjvValidator as d, ContextFactory as i };
578
+ export type { Alias as A, SecurityRequirementObject as B, CustomActionSchema as C, Document as D, EncodingObject as E, SecuritySchemeObject as F, ServerObject as G, HeaderObject as H, InfoObject as I, JSONSchemaType as J, ServerVariableObject as K, LicenseObject as L, MoleculerLoggerConfigOptions as M, Transform as N, OperationObject as O, ParameterBaseObject as P, TransformField as Q, ReferenceObject as R, SomeJSONSchema as S, TagObject as T, TransformLevel as U, TransformMap as V, Transformer as W, ValidationSchema as X, CustomServiceSchema as a, SchemaObject 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, ParameterObject as s, PathItemObject as t, PathsObject as u, PropertiesSchema as v, RequestBodyObject as w, RequiredMembers as x, ResponseObject as y, ResponsesObject as z };
@@ -1,8 +1,8 @@
1
- import Moleculer__default, { RestSchema, ActionVisibility, Service, ActionCacheOptions, Context, TracingActionOptions, BulkheadOptions, BrokerCircuitBreakerOptions, RetryPolicyOptions, FallbackHandler, ActionHooks, Validators, ActionHandler, ActionSchema, ServiceEvent, ServiceDependency, ServiceHooks, GenericObject, ServiceBroker, Endpoint } from 'moleculer';
1
+ import { ActionSchema, Context, Validators, Middleware, EventSchema, Service, ServiceHooks, Logger, ServiceBroker, ActionEndpoint, EventEndpoint, Span } from 'moleculer';
2
2
  import { ObjectId } from 'bson';
3
3
  import { ZodType, z } from 'zod/v4';
4
4
  import { Options, ErrorObject } from 'ajv/dist/2019.js';
5
- import { LoggerOptions, Logger } from 'pino';
5
+ import { LoggerOptions, Logger as Logger$1 } from 'pino';
6
6
  import { PrettyOptions } from 'pino-pretty';
7
7
 
8
8
  type UnionToIntersection$1<U> = (U extends any ? (_: U) => void : never) extends (_: infer I) => void ? I : never;
@@ -333,24 +333,14 @@ interface Document {
333
333
  'x-express-openapi-validation-strict'?: boolean;
334
334
  }
335
335
 
336
- interface CustomActionSchema<T = unknown> {
337
- name?: string;
338
- rest?: RestSchema | RestSchema[] | string | string[];
339
- visibility?: ActionVisibility;
340
- service?: Service;
341
- cache?: boolean | ActionCacheOptions;
342
- handler?: (ctx: Context<never, never>) => Promise<T> | T;
343
- tracing?: boolean | TracingActionOptions;
344
- bulkhead?: BulkheadOptions;
345
- circuitBreaker?: BrokerCircuitBreakerOptions;
346
- retryPolicy?: RetryPolicyOptions;
347
- fallback?: string | FallbackHandler;
348
- hooks?: ActionHooks;
336
+ interface CustomActionSchema<T = unknown> extends Omit<ActionSchema, 'params' | 'handler'> {
349
337
  params?: unknown;
338
+ handler?: (ctx: Context<never, never>) => Promise<T> | T;
350
339
  disableTransforms?: boolean;
351
340
  openAPINames?: string[] | null;
352
341
  openapi?: OperationObject;
353
342
  bodySchemaRefName?: string;
343
+ rest?: string | string[];
354
344
  }
355
345
  type Alias = {
356
346
  actionName: string;
@@ -383,6 +373,9 @@ interface Transformer<T, U> {
383
373
  findTransforms: (schema: ValidationSchema) => TransformField[];
384
374
  }
385
375
 
376
+ type ZodActionOrEventSchema = {
377
+ params?: ZodType;
378
+ };
386
379
  /**
387
380
  * Use zod for schema validation.
388
381
  * DO NOT support Async refinements/transforms yet.
@@ -390,19 +383,32 @@ interface Transformer<T, U> {
390
383
  * Transforms MUST BE handled by the consumer directly.
391
384
  */
392
385
  declare class ZodValidator extends Validators.Base {
393
- compile(): () => void;
386
+ constructor();
387
+ compile(): Validators.Base.CheckerFunction;
394
388
  validate<S extends ZodType>(params: unknown, schema: S, ctx?: Context): z.output<S>;
395
389
  /**
396
390
  * Override BaseValidator middleware to handle our custom compile function.
397
391
  */
398
- middleware(): (handler: ActionHandler, action: ActionSchema) => unknown;
392
+ middleware(): {
393
+ name: string;
394
+ localAction: (handler: any, action: ZodActionOrEventSchema) => any;
395
+ localEvent: (handler: any, event: ZodActionOrEventSchema) => any;
396
+ };
397
+ convertSchemaToMoleculer(): Record<string, unknown>;
399
398
  }
400
399
  declare module 'moleculer' {
401
- interface BaseValidator {
402
- validate<S extends ZodType>(params: unknown, schema: S): z.output<S>;
400
+ namespace Validators {
401
+ interface Base {
402
+ validate<S extends ZodType>(params: unknown, schema: S): z.output<S>;
403
+ }
403
404
  }
404
405
  }
405
406
 
407
+ type AjvValidatorCheckFnOption = {
408
+ meta: {
409
+ ctx: Context;
410
+ };
411
+ };
406
412
  /**
407
413
  * Moleculer validator using Ajv/zod for schema validation.
408
414
  *
@@ -417,7 +423,6 @@ declare module 'moleculer' {
417
423
  declare class AjvValidator<Mode extends string> extends Validators.Base {
418
424
  private readonly modes;
419
425
  private readonly defaultMode;
420
- private readonly broker;
421
426
  readonly zodValidator?: ZodValidator;
422
427
  /**
423
428
  * Cache of compiled validation functions.
@@ -438,7 +443,7 @@ declare class AjvValidator<Mode extends string> extends Validators.Base {
438
443
  *
439
444
  * Compiling a schema is quite expensive, so it will only be done once per schema.
440
445
  */
441
- compile(schema: ValidationSchema, mode?: Mode): (params: unknown, ctx?: Context) => boolean;
446
+ compile(schema: ValidationSchema, mode?: Mode): (params: unknown, opts?: AjvValidatorCheckFnOption) => boolean;
442
447
  /**
443
448
  * For debugging purposes, log the validation errors.
444
449
  * This is only enabled if the DETAILED_AJV_VALIDATION_ERRORS env var is set to 'yes'.
@@ -448,11 +453,14 @@ declare class AjvValidator<Mode extends string> extends Validators.Base {
448
453
  * We wrap the localAction and localEvent methods to add validation to the actions and events handlers.
449
454
  * Note that we lazy compile schemas in order to avoid a performance hit on startup.
450
455
  */
451
- middleware(): (handler: ActionHandler, action: ActionSchema) => unknown;
456
+ middleware(): Middleware;
457
+ convertSchemaToMoleculer(): Record<string, unknown>;
452
458
  }
453
459
  declare module 'moleculer' {
454
- interface BaseValidator {
455
- validate(params: unknown, schema: ValidationSchema): true;
460
+ namespace Validators {
461
+ interface Base {
462
+ validate(params: unknown, schema: ValidationSchema): true;
463
+ }
456
464
  }
457
465
  }
458
466
 
@@ -460,7 +468,7 @@ type Unpacked<T> = T extends (infer U)[] ? U : never;
460
468
  type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
461
469
  type OptionallyArray<T> = T | T[];
462
470
 
463
- type ServiceEventSchema = ServiceEvent & {
471
+ type ServiceEventSchema = EventSchema & {
464
472
  params?: unknown;
465
473
  };
466
474
 
@@ -483,7 +491,7 @@ type CallbackServiceThis<Return, Settings, Methods, Mixins, Parameters extends u
483
491
  interface CustomServiceSchema<Settings, Methods, Mixins> {
484
492
  name: string;
485
493
  version?: string | number;
486
- dependencies?: OptionallyArray<string | ServiceDependency>;
494
+ dependencies?: OptionallyArray<string | Service.ServiceDependency>;
487
495
  metadata?: Record<string, unknown>;
488
496
  settings?: Settings;
489
497
  hooks?: ServiceHooks;
@@ -503,9 +511,9 @@ interface CustomServiceSchema<Settings, Methods, Mixins> {
503
511
  * This class replace the default Context class in Moleculer to:
504
512
  * - Add a ctx.logger instance with the trace.id and span.id in the bindings
505
513
  */
506
- declare class ContextFactory<P = unknown, M extends object = {}, L = GenericObject> extends Context<P, M, L> {
507
- constructor(broker: ServiceBroker, endpoint: Endpoint);
508
- startSpan(name: string, opts?: Moleculer__default.GenericObject): Moleculer__default.Span;
514
+ declare class ContextFactory<P = unknown, M extends object = {}, L = Record<string, unknown>, H = Record<string, unknown>> extends Context<P, M, L, H> {
515
+ constructor(broker: ServiceBroker, endpoint: ActionEndpoint | EventEndpoint);
516
+ startSpan(name: string, opts?: Record<string, unknown>): Span;
509
517
  /**
510
518
  * Get a logger for this specific span of the context.
511
519
  */
@@ -513,7 +521,7 @@ declare class ContextFactory<P = unknown, M extends object = {}, L = GenericObje
513
521
  }
514
522
  declare module 'moleculer' {
515
523
  interface Context {
516
- logger: Moleculer__default.LoggerInstance;
524
+ logger: Logger;
517
525
  }
518
526
  }
519
527
 
@@ -545,7 +553,7 @@ type MoleculerLoggerConfigOptions = {
545
553
  *
546
554
  * @default createLogger()
547
555
  */
548
- logger?: Logger;
556
+ logger?: Logger$1;
549
557
  /**
550
558
  * Name of the field added for context logging. `false` disable the field
551
559
  * @default 'trace.id'
@@ -566,5 +574,5 @@ declare module 'pino' {
566
574
  }
567
575
  }
568
576
 
569
- export { ZodValidator as Z, AjvValidator as e, ContextFactory as j };
570
- export type { Alias as A, OAuth2SecurityScheme as B, CustomActionSchema as C, Document as D, ExternalDocumentationObject as E, OpenIdSecurityScheme as F, SecuritySchemeObject as G, HeaderObject as H, InfoObject as I, JSONSchemaType as J, CallbackObject as K, LicenseObject as L, MoleculerLoggerConfigOptions as M, ComponentsObject as N, OperationObject as O, PropertiesSchema as P, TagObject as Q, ReferenceObject as R, SomeJSONSchema as S, Transformer as T, PathItemObject as U, ValidationSchema as V, ObjectServiceThis as W, CallbackServiceThis as X, CustomServiceSchema as a, SchemaObject as b, CreateLoggerOptions as c, RequiredMembers as d, Transform as f, TransformLevel as g, TransformMap as h, TransformField as i, ContactObject as k, ServerVariableObject as l, ServerObject as m, PathsObject as n, ParameterObject as o, ParameterBaseObject as p, ExampleObject as q, EncodingObject as r, MediaTypeObject as s, RequestBodyObject as t, LinkObject as u, ResponseObject as v, ResponsesObject as w, SecurityRequirementObject as x, HttpSecurityScheme as y, ApiKeySecurityScheme as z };
577
+ export { ZodValidator as Z, AjvValidator as d, ContextFactory as i };
578
+ export type { Alias as A, SecurityRequirementObject as B, CustomActionSchema as C, Document as D, EncodingObject as E, SecuritySchemeObject as F, ServerObject as G, HeaderObject as H, InfoObject as I, JSONSchemaType as J, ServerVariableObject as K, LicenseObject as L, MoleculerLoggerConfigOptions as M, Transform as N, OperationObject as O, ParameterBaseObject as P, TransformField as Q, ReferenceObject as R, SomeJSONSchema as S, TagObject as T, TransformLevel as U, TransformMap as V, Transformer as W, ValidationSchema as X, CustomServiceSchema as a, SchemaObject 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, ParameterObject as s, PathItemObject as t, PathsObject as u, PropertiesSchema as v, RequestBodyObject as w, RequiredMembers as x, ResponseObject as y, ResponsesObject as z };