@treatwell/moleculer-essentials 2.0.0-beta.3 → 2.0.0-beta.6

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,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'
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "type": "git",
7
7
  "url": "https://github.com/treatwell/moleculer-essentials"
8
8
  },
9
- "version": "2.0.0-beta.3",
9
+ "version": "2.0.0-beta.6",
10
10
  "main": "./dist/index.cjs",
11
11
  "module": "./dist/index.mjs",
12
12
  "types": "./dist/index.d.cts",
@@ -118,7 +118,7 @@
118
118
  "ioredis": "^5.2.3",
119
119
  "jsonwebtoken": "^9.0.2",
120
120
  "jwks-rsa": "^3.0.1",
121
- "moleculer": "^0.14.33",
121
+ "moleculer": "^0.15.0",
122
122
  "mongodb": "^6.15.0 || ^7.1.0",
123
123
  "redlock": "^4.2.0",
124
124
  "zod": "^3.25.0 || ^4.0.0"
@@ -164,7 +164,7 @@
164
164
  "jiti": "^2.6.1",
165
165
  "jsonwebtoken": "^9.0.3",
166
166
  "jwks-rsa": "^4.0.1",
167
- "moleculer": "^0.14.35",
167
+ "moleculer": "^0.15.0",
168
168
  "mongodb": "^7.1.1",
169
169
  "mongodb-memory-server": "^11.0.1",
170
170
  "pkgroll": "2.27.0",