@message-queue-toolkit/core 11.0.0 → 12.0.0

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.
package/dist/index.d.ts CHANGED
@@ -14,4 +14,12 @@ export type { MessageSchemaContainerOptions } from './lib/queues/MessageSchemaCo
14
14
  export { objectToBuffer } from './lib/utils/queueUtils';
15
15
  export { waitAndRetry } from './lib/utils/waitUtils';
16
16
  export { parseMessage } from './lib/utils/parseUtils';
17
+ export { toDatePreprocessor } from './lib/utils/toDateProcessor';
17
18
  export { reloadConfig, isProduction } from './lib/utils/envUtils';
19
+ export { DomainEventEmitter } from './lib/events/DomainEventEmitter';
20
+ export { EventRegistry } from './lib/events/EventRegistry';
21
+ export { FakeListener } from './lib/events/fakes/FakeListener';
22
+ export * from './lib/events/eventTypes';
23
+ export * from './lib/events/baseEventSchemas';
24
+ export * from './lib/messages/baseMessageSchemas';
25
+ export * from './lib/messages/MetadataFiller';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isProduction = exports.reloadConfig = exports.parseMessage = exports.waitAndRetry = exports.objectToBuffer = exports.MessageSchemaContainer = exports.HandlerSpy = exports.MessageHandlerConfigBuilder = exports.MessageHandlerConfig = exports.HandlerContainer = exports.DoNotProcessMessageError = exports.RetryMessageLaterError = exports.objectMatches = exports.isShallowSubset = exports.MessageInvalidFormatError = exports.MessageValidationError = exports.isMessageError = exports.AbstractQueueService = void 0;
3
+ exports.FakeListener = exports.EventRegistry = exports.DomainEventEmitter = exports.isProduction = exports.reloadConfig = exports.toDatePreprocessor = exports.parseMessage = exports.waitAndRetry = exports.objectToBuffer = exports.MessageSchemaContainer = exports.HandlerSpy = exports.MessageHandlerConfigBuilder = exports.MessageHandlerConfig = exports.HandlerContainer = exports.DoNotProcessMessageError = exports.RetryMessageLaterError = exports.objectMatches = exports.isShallowSubset = exports.MessageInvalidFormatError = exports.MessageValidationError = exports.isMessageError = exports.AbstractQueueService = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  var AbstractQueueService_1 = require("./lib/queues/AbstractQueueService");
6
6
  Object.defineProperty(exports, "AbstractQueueService", { enumerable: true, get: function () { return AbstractQueueService_1.AbstractQueueService; } });
@@ -30,7 +30,19 @@ var waitUtils_1 = require("./lib/utils/waitUtils");
30
30
  Object.defineProperty(exports, "waitAndRetry", { enumerable: true, get: function () { return waitUtils_1.waitAndRetry; } });
31
31
  var parseUtils_1 = require("./lib/utils/parseUtils");
32
32
  Object.defineProperty(exports, "parseMessage", { enumerable: true, get: function () { return parseUtils_1.parseMessage; } });
33
+ var toDateProcessor_1 = require("./lib/utils/toDateProcessor");
34
+ Object.defineProperty(exports, "toDatePreprocessor", { enumerable: true, get: function () { return toDateProcessor_1.toDatePreprocessor; } });
33
35
  var envUtils_1 = require("./lib/utils/envUtils");
34
36
  Object.defineProperty(exports, "reloadConfig", { enumerable: true, get: function () { return envUtils_1.reloadConfig; } });
35
37
  Object.defineProperty(exports, "isProduction", { enumerable: true, get: function () { return envUtils_1.isProduction; } });
38
+ var DomainEventEmitter_1 = require("./lib/events/DomainEventEmitter");
39
+ Object.defineProperty(exports, "DomainEventEmitter", { enumerable: true, get: function () { return DomainEventEmitter_1.DomainEventEmitter; } });
40
+ var EventRegistry_1 = require("./lib/events/EventRegistry");
41
+ Object.defineProperty(exports, "EventRegistry", { enumerable: true, get: function () { return EventRegistry_1.EventRegistry; } });
42
+ var FakeListener_1 = require("./lib/events/fakes/FakeListener");
43
+ Object.defineProperty(exports, "FakeListener", { enumerable: true, get: function () { return FakeListener_1.FakeListener; } });
44
+ tslib_1.__exportStar(require("./lib/events/eventTypes"), exports);
45
+ tslib_1.__exportStar(require("./lib/events/baseEventSchemas"), exports);
46
+ tslib_1.__exportStar(require("./lib/messages/baseMessageSchemas"), exports);
47
+ tslib_1.__exportStar(require("./lib/messages/MetadataFiller"), exports);
36
48
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;AAWA,0EAAsF;AAA7E,4HAAA,oBAAoB,OAAA;AAC7B,wEAA6C;AAE7C,8CAI4B;AAH1B,wGAAA,cAAc,OAAA;AACd,gHAAA,sBAAsB,OAAA;AACtB,mHAAA,yBAAyB,OAAA;AAG3B,qDAAuE;AAA9D,6GAAA,eAAe,OAAA;AAAE,2GAAA,aAAa,OAAA;AAEvC,8EAA4E;AAAnE,gIAAA,sBAAsB,OAAA;AAE/B,oEAAyE;AAAhE,6HAAA,wBAAwB,OAAA;AAEjC,kEAIsC;AAHpC,oHAAA,gBAAgB,OAAA;AAChB,wHAAA,oBAAoB,OAAA;AACpB,+HAAA,2BAA2B,OAAA;AAY7B,sDAAoD;AAA3C,wGAAA,UAAU,OAAA;AAGnB,8EAA4E;AAAnE,gIAAA,sBAAsB,OAAA;AAG/B,qDAAuD;AAA9C,4GAAA,cAAc,OAAA;AACvB,mDAAoD;AAA3C,yGAAA,YAAY,OAAA;AACrB,qDAAqD;AAA5C,0GAAA,YAAY,OAAA;AAErB,iDAAiE;AAAxD,wGAAA,YAAY,OAAA;AAAE,wGAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;AAWA,0EAAsF;AAA7E,4HAAA,oBAAoB,OAAA;AAC7B,wEAA6C;AAE7C,8CAI4B;AAH1B,wGAAA,cAAc,OAAA;AACd,gHAAA,sBAAsB,OAAA;AACtB,mHAAA,yBAAyB,OAAA;AAG3B,qDAAuE;AAA9D,6GAAA,eAAe,OAAA;AAAE,2GAAA,aAAa,OAAA;AAEvC,8EAA4E;AAAnE,gIAAA,sBAAsB,OAAA;AAE/B,oEAAyE;AAAhE,6HAAA,wBAAwB,OAAA;AAEjC,kEAIsC;AAHpC,oHAAA,gBAAgB,OAAA;AAChB,wHAAA,oBAAoB,OAAA;AACpB,+HAAA,2BAA2B,OAAA;AAY7B,sDAAoD;AAA3C,wGAAA,UAAU,OAAA;AAGnB,8EAA4E;AAAnE,gIAAA,sBAAsB,OAAA;AAG/B,qDAAuD;AAA9C,4GAAA,cAAc,OAAA;AACvB,mDAAoD;AAA3C,yGAAA,YAAY,OAAA;AACrB,qDAAqD;AAA5C,0GAAA,YAAY,OAAA;AACrB,+DAAgE;AAAvD,qHAAA,kBAAkB,OAAA;AAE3B,iDAAiE;AAAxD,wGAAA,YAAY,OAAA;AAAE,wGAAA,YAAY,OAAA;AAEnC,sEAAoE;AAA3D,wHAAA,kBAAkB,OAAA;AAC3B,4DAA0D;AAAjD,8GAAA,aAAa,OAAA;AACtB,gEAA8D;AAArD,4GAAA,YAAY,OAAA;AAErB,kEAAuC;AACvC,wEAA6C;AAC7C,4EAAiD;AAEjD,wEAA6C"}
@@ -0,0 +1,24 @@
1
+ import type { EventRegistry } from './EventRegistry';
2
+ import type { AnyEventHandler, SingleEventHandler, CommonEventDefinition, CommonEventDefinitionSchemaType, EventTypeNames } from './eventTypes';
3
+ export declare class DomainEventEmitter<SupportedEvents extends CommonEventDefinition[]> {
4
+ private readonly eventRegistry;
5
+ private readonly eventHandlerMap;
6
+ private readonly anyHandlers;
7
+ constructor({ eventRegistry }: {
8
+ eventRegistry: EventRegistry<SupportedEvents>;
9
+ });
10
+ emit<SupportedEvent extends SupportedEvents[number]>(supportedEvent: SupportedEvent, data: Omit<CommonEventDefinitionSchemaType<SupportedEvent>, 'type'>): Promise<void>;
11
+ /**
12
+ * Register handler for a specific event
13
+ */
14
+ on<EventTypeName extends EventTypeNames<SupportedEvents[number]>>(eventTypeName: EventTypeName, handler: SingleEventHandler<SupportedEvents, EventTypeName>): void;
15
+ /**
16
+ * Register handler for multiple events
17
+ */
18
+ onMany<EventTypeName extends EventTypeNames<SupportedEvents[number]>>(eventTypeNames: EventTypeName[], handler: SingleEventHandler<SupportedEvents, EventTypeName>): void;
19
+ /**
20
+ * Register handler for all events supported by the emitter
21
+ */
22
+ onAny(handler: AnyEventHandler<SupportedEvents>): void;
23
+ private addOnHandler;
24
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DomainEventEmitter = void 0;
4
+ const node_core_1 = require("@lokalise/node-core");
5
+ class DomainEventEmitter {
6
+ eventRegistry;
7
+ eventHandlerMap = {};
8
+ anyHandlers = [];
9
+ constructor({ eventRegistry }) {
10
+ this.eventRegistry = eventRegistry;
11
+ }
12
+ async emit(supportedEvent, data) {
13
+ const eventTypeName = supportedEvent.schema.shape.type.value;
14
+ if (!this.eventRegistry.isSupportedEvent(eventTypeName)) {
15
+ throw new node_core_1.InternalError({
16
+ errorCode: 'UNKNOWN_EVENT',
17
+ message: `Unknown event ${eventTypeName}`,
18
+ });
19
+ }
20
+ const eventHandlers = this.eventHandlerMap[eventTypeName];
21
+ // No relevant handlers are registered, we can stop processing
22
+ if (!eventHandlers && this.anyHandlers.length === 0) {
23
+ return;
24
+ }
25
+ const validatedEvent = this.eventRegistry
26
+ .getEventDefinitionByTypeName(eventTypeName)
27
+ .schema.parse({
28
+ type: eventTypeName,
29
+ ...data,
30
+ });
31
+ if (eventHandlers) {
32
+ for (const handler of eventHandlers) {
33
+ await handler.handleEvent(validatedEvent);
34
+ }
35
+ }
36
+ for (const handler of this.anyHandlers) {
37
+ await handler.handleEvent(validatedEvent);
38
+ }
39
+ }
40
+ /**
41
+ * Register handler for a specific event
42
+ */
43
+ on(eventTypeName, handler) {
44
+ this.addOnHandler(eventTypeName, handler);
45
+ }
46
+ /**
47
+ * Register handler for multiple events
48
+ */
49
+ onMany(eventTypeNames, handler) {
50
+ for (const eventTypeName of eventTypeNames) {
51
+ this.on(eventTypeName, handler);
52
+ }
53
+ }
54
+ /**
55
+ * Register handler for all events supported by the emitter
56
+ */
57
+ onAny(handler) {
58
+ this.anyHandlers.push(handler);
59
+ }
60
+ addOnHandler(eventTypeName, handler) {
61
+ if (!this.eventHandlerMap[eventTypeName]) {
62
+ this.eventHandlerMap[eventTypeName] = [];
63
+ }
64
+ this.eventHandlerMap[eventTypeName].push(handler);
65
+ }
66
+ }
67
+ exports.DomainEventEmitter = DomainEventEmitter;
68
+ //# sourceMappingURL=DomainEventEmitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DomainEventEmitter.js","sourceRoot":"","sources":["../../../lib/events/DomainEventEmitter.ts"],"names":[],"mappings":";;;AAAA,mDAAmD;AAYnD,MAAa,kBAAkB;IACZ,aAAa,CAAgC;IAE7C,eAAe,GAG5B,EAAE,CAAA;IACW,WAAW,GAAuC,EAAE,CAAA;IAErE,YAAY,EAAE,aAAa,EAAqD;QAC9E,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;IACpC,CAAC;IAEM,KAAK,CAAC,IAAI,CACf,cAA8B,EAC9B,IAAmE;QAEnE,MAAM,aAAa,GAAG,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAA;QAE5D,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,CAAC;YACxD,MAAM,IAAI,yBAAa,CAAC;gBACtB,SAAS,EAAE,eAAe;gBAC1B,OAAO,EAAE,iBAAiB,aAAa,EAAE;aAC1C,CAAC,CAAA;QACJ,CAAC;QAED,MAAM,aAAa,GAAG,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAA;QAEzD,8DAA8D;QAC9D,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpD,OAAM;QACR,CAAC;QAED,MAAM,cAAc,GAAG,IAAI,CAAC,aAAa;aACtC,4BAA4B,CAAC,aAAa,CAAC;aAC3C,MAAM,CAAC,KAAK,CAAC;YACZ,IAAI,EAAE,aAAa;YACnB,GAAG,IAAI;SACR,CAAC,CAAA;QAEJ,IAAI,aAAa,EAAE,CAAC;YAClB,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;gBACpC,MAAM,OAAO,CAAC,WAAW,CAAC,cAAc,CAAC,CAAA;YAC3C,CAAC;QACH,CAAC;QAED,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACvC,MAAM,OAAO,CAAC,WAAW,CAAC,cAAc,CAAC,CAAA;QAC3C,CAAC;IACH,CAAC;IAED;;OAEG;IACI,EAAE,CACP,aAA4B,EAC5B,OAA2D;QAE3D,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED;;OAEG;IACI,MAAM,CACX,cAA+B,EAC/B,OAA2D;QAE3D,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE,CAAC;YAC3C,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;QACjC,CAAC;IACH,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAyC;QACpD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAChC,CAAC;IAEO,YAAY,CAClB,aAAsD,EACtD,OAAqB;QAErB,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE,CAAC;YACzC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,GAAG,EAAE,CAAA;QAC1C,CAAC;QAED,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACnD,CAAC;CACF;AA1FD,gDA0FC"}
@@ -0,0 +1,9 @@
1
+ import type { CommonEventDefinition, EventTypeNames } from './eventTypes';
2
+ export declare class EventRegistry<SupportedEvents extends CommonEventDefinition[]> {
3
+ readonly supportedEvents: SupportedEvents;
4
+ private readonly supportedEventsSet;
5
+ private readonly supportedEventMap;
6
+ constructor(supportedEvents: SupportedEvents);
7
+ getEventDefinitionByTypeName: <EventTypeName extends EventTypeNames<SupportedEvents[number]>>(eventTypeName: EventTypeName) => CommonEventDefinition;
8
+ isSupportedEvent(eventTypeName: string): boolean;
9
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventRegistry = void 0;
4
+ class EventRegistry {
5
+ supportedEvents;
6
+ supportedEventsSet;
7
+ supportedEventMap = {};
8
+ constructor(supportedEvents) {
9
+ this.supportedEvents = supportedEvents;
10
+ this.supportedEventsSet = new Set();
11
+ for (const supportedEvent of supportedEvents) {
12
+ this.supportedEventMap[supportedEvent.schema.shape.type.value] = supportedEvent;
13
+ this.supportedEventsSet.add(supportedEvent.schema.shape.type.value);
14
+ }
15
+ }
16
+ getEventDefinitionByTypeName = (eventTypeName) => {
17
+ return this.supportedEventMap[eventTypeName];
18
+ };
19
+ isSupportedEvent(eventTypeName) {
20
+ return this.supportedEventsSet.has(eventTypeName);
21
+ }
22
+ }
23
+ exports.EventRegistry = EventRegistry;
24
+ //# sourceMappingURL=EventRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventRegistry.js","sourceRoot":"","sources":["../../../lib/events/EventRegistry.ts"],"names":[],"mappings":";;;AAEA,MAAa,aAAa;IACR,eAAe,CAAiB;IAC/B,kBAAkB,CAAa;IAC/B,iBAAiB,GAA0C,EAAE,CAAA;IAE9E,YAAY,eAAgC;QAC1C,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,kBAAkB,GAAG,IAAI,GAAG,EAAU,CAAA;QAE3C,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;YAC7C,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,cAAc,CAAA;YAC/E,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACrE,CAAC;IACH,CAAC;IAEM,4BAA4B,GAAG,CAGpC,aAA4B,EACL,EAAE;QACzB,OAAO,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAA;IAC9C,CAAC,CAAA;IAEM,gBAAgB,CAAC,aAAqB;QAC3C,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IACnD,CAAC;CACF;AA1BD,sCA0BC"}
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+ export declare const BASE_EVENT_SCHEMA: z.ZodObject<{
3
+ id: z.ZodString;
4
+ timestamp: z.ZodString;
5
+ type: z.ZodLiteral<string>;
6
+ payload: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ id: string;
9
+ timestamp: string;
10
+ type: string;
11
+ payload?: {} | undefined;
12
+ }, {
13
+ id: string;
14
+ timestamp: string;
15
+ type: string;
16
+ payload?: {} | undefined;
17
+ }>;
18
+ export type BaseEventType = z.infer<typeof BASE_EVENT_SCHEMA>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BASE_EVENT_SCHEMA = void 0;
4
+ const zod_1 = require("zod");
5
+ // Core fields that describe either internal event or external message
6
+ exports.BASE_EVENT_SCHEMA = zod_1.z.object({
7
+ id: zod_1.z.string().describe('event unique identifier'),
8
+ timestamp: zod_1.z.string().datetime().describe('iso 8601 datetime'),
9
+ type: zod_1.z.literal('<replace.me>').describe('event type name'),
10
+ payload: zod_1.z.optional(zod_1.z.object({})).describe('event payload based on type'),
11
+ });
12
+ //# sourceMappingURL=baseEventSchemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseEventSchemas.js","sourceRoot":"","sources":["../../../lib/events/baseEventSchemas.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEvB,sEAAsE;AACzD,QAAA,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,yBAAyB,CAAC;IAClD,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IAC9D,IAAI,EAAE,OAAC,CAAC,OAAO,CAAS,cAAc,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC;IACnE,OAAO,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,6BAA6B,CAAC;CAC1E,CAAC,CAAA"}
@@ -0,0 +1,20 @@
1
+ import type { ZodObject, ZodTypeAny } from 'zod';
2
+ import type z from 'zod';
3
+ import type { BASE_EVENT_SCHEMA } from './baseEventSchemas';
4
+ export type EventTypeNames<EventDefinition extends CommonEventDefinition> = CommonEventDefinitionSchemaType<EventDefinition>['type'];
5
+ export type CommonEventDefinition = {
6
+ schema: ZodObject<Omit<(typeof BASE_EVENT_SCHEMA)['shape'], 'payload'> & {
7
+ payload: ZodTypeAny;
8
+ }>;
9
+ schemaVersion?: string;
10
+ };
11
+ export type CommonEventDefinitionSchemaType<T extends CommonEventDefinition> = z.infer<T['schema']>;
12
+ export type EventHandler<EventDefinitionSchema extends CommonEventDefinitionSchemaType<CommonEventDefinition> = CommonEventDefinitionSchemaType<CommonEventDefinition>> = {
13
+ handleEvent(event: EventDefinitionSchema): void | Promise<void>;
14
+ };
15
+ export type AnyEventHandler<EventDefinitions extends CommonEventDefinition[]> = EventHandler<CommonEventDefinitionSchemaType<EventDefinitions[number]>>;
16
+ export type SingleEventHandler<EventDefinition extends CommonEventDefinition[], EventTypeName extends EventTypeNames<EventDefinition[number]>> = EventHandler<EventFromArrayByTypeName<EventDefinition, EventTypeName>>;
17
+ type EventFromArrayByTypeName<EventDefinition extends CommonEventDefinition[], EventTypeName extends EventTypeNames<EventDefinition[number]>> = Extract<CommonEventDefinitionSchemaType<EventDefinition[number]>, {
18
+ type: EventTypeName;
19
+ }>;
20
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=eventTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventTypes.js","sourceRoot":"","sources":["../../../lib/events/eventTypes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { AnyEventHandler, CommonEventDefinition } from '../eventTypes';
2
+ export declare class FakeListener<SupportedEvents extends CommonEventDefinition[]> implements AnyEventHandler<SupportedEvents> {
3
+ receivedEvents: SupportedEvents[number]['schema']['_output'][];
4
+ constructor(_supportedEvents: SupportedEvents);
5
+ handleEvent(event: SupportedEvents[number]['schema']['_output']): void | Promise<void>;
6
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FakeListener = void 0;
4
+ class FakeListener {
5
+ receivedEvents = [];
6
+ constructor(_supportedEvents) {
7
+ this.receivedEvents = [];
8
+ }
9
+ handleEvent(event) {
10
+ this.receivedEvents.push(event);
11
+ }
12
+ }
13
+ exports.FakeListener = FakeListener;
14
+ //# sourceMappingURL=FakeListener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeListener.js","sourceRoot":"","sources":["../../../../lib/events/fakes/FakeListener.ts"],"names":[],"mappings":";;;AAEA,MAAa,YAAY;IAGhB,cAAc,GAAmD,EAAE,CAAA;IAE1E,YAAY,gBAAiC;QAC3C,IAAI,CAAC,cAAc,GAAG,EAAE,CAAA;IAC1B,CAAC;IAED,WAAW,CAAC,KAAmD;QAC7D,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;CACF;AAZD,oCAYC"}
@@ -0,0 +1,25 @@
1
+ import type { BaseEventType } from '../events/baseEventSchemas';
2
+ import type { CommonEventDefinition } from '../events/eventTypes';
3
+ import type { MessageMetadataType } from './baseMessageSchemas';
4
+ export type IdGenerator = () => string;
5
+ export type TimestampGenerator = () => string;
6
+ export type MetadataFillerOptions = {
7
+ serviceId: string;
8
+ schemaVersion: string;
9
+ idGenerator?: IdGenerator;
10
+ timestampGenerator?: TimestampGenerator;
11
+ defaultVersion?: string;
12
+ };
13
+ export type MetadataFiller<T extends BaseEventType = BaseEventType, D = CommonEventDefinition, M = MessageMetadataType> = {
14
+ produceMetadata(currentMessage: T, eventDefinition: D, precedingMessageMetadata?: M): M;
15
+ produceId(): string;
16
+ produceTimestamp(): string;
17
+ };
18
+ export declare class CommonMetadataFiller implements MetadataFiller {
19
+ private readonly serviceId;
20
+ readonly produceId: IdGenerator;
21
+ readonly produceTimestamp: TimestampGenerator;
22
+ private readonly defaultVersion;
23
+ constructor(options: MetadataFillerOptions);
24
+ produceMetadata(_currentMessage: BaseEventType, eventDefinition: CommonEventDefinition, precedingMessageMetadata?: MessageMetadataType): MessageMetadataType;
25
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommonMetadataFiller = void 0;
4
+ const node_crypto_1 = require("node:crypto");
5
+ class CommonMetadataFiller {
6
+ serviceId;
7
+ produceId;
8
+ produceTimestamp;
9
+ defaultVersion;
10
+ constructor(options) {
11
+ this.serviceId = options.serviceId;
12
+ this.defaultVersion = options.defaultVersion ?? '1.0.0';
13
+ this.produceId =
14
+ options.idGenerator ??
15
+ (() => {
16
+ return (0, node_crypto_1.randomUUID)();
17
+ });
18
+ this.produceTimestamp =
19
+ options.timestampGenerator ??
20
+ (() => {
21
+ return new Date().toISOString();
22
+ });
23
+ }
24
+ produceMetadata(_currentMessage, eventDefinition, precedingMessageMetadata) {
25
+ return {
26
+ producedBy: this.serviceId,
27
+ originatedFrom: precedingMessageMetadata?.originatedFrom ?? this.serviceId,
28
+ schemaVersion: eventDefinition.schemaVersion ?? this.defaultVersion,
29
+ correlationId: precedingMessageMetadata?.correlationId ?? this.produceId(),
30
+ };
31
+ }
32
+ }
33
+ exports.CommonMetadataFiller = CommonMetadataFiller;
34
+ //# sourceMappingURL=MetadataFiller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MetadataFiller.js","sourceRoot":"","sources":["../../../lib/messages/MetadataFiller.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AA4BxC,MAAa,oBAAoB;IACd,SAAS,CAAQ;IAClB,SAAS,CAAa;IACtB,gBAAgB,CAAoB;IACnC,cAAc,CAAQ;IAEvC,YAAY,OAA8B;QACxC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,OAAO,CAAA;QACvD,IAAI,CAAC,SAAS;YACZ,OAAO,CAAC,WAAW;gBACnB,CAAC,GAAG,EAAE;oBACJ,OAAO,IAAA,wBAAU,GAAE,CAAA;gBACrB,CAAC,CAAC,CAAA;QACJ,IAAI,CAAC,gBAAgB;YACnB,OAAO,CAAC,kBAAkB;gBAC1B,CAAC,GAAG,EAAE;oBACJ,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;gBACjC,CAAC,CAAC,CAAA;IACN,CAAC;IAED,eAAe,CACb,eAA8B,EAC9B,eAAsC,EACtC,wBAA8C;QAE9C,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,SAAS;YAC1B,cAAc,EAAE,wBAAwB,EAAE,cAAc,IAAI,IAAI,CAAC,SAAS;YAC1E,aAAa,EAAE,eAAe,CAAC,aAAa,IAAI,IAAI,CAAC,cAAc;YACnE,aAAa,EAAE,wBAAwB,EAAE,aAAa,IAAI,IAAI,CAAC,SAAS,EAAE;SAC3E,CAAA;IACH,CAAC;CACF;AAjCD,oDAiCC"}
@@ -0,0 +1,64 @@
1
+ import z from 'zod';
2
+ export declare const MESSAGE_METADATA_SCHEMA: z.ZodObject<{
3
+ schemaVersion: z.ZodString;
4
+ producedBy: z.ZodString;
5
+ originatedFrom: z.ZodString;
6
+ correlationId: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ schemaVersion: string;
9
+ producedBy: string;
10
+ originatedFrom: string;
11
+ correlationId: string;
12
+ }, {
13
+ schemaVersion: string;
14
+ producedBy: string;
15
+ originatedFrom: string;
16
+ correlationId: string;
17
+ }>;
18
+ export declare const BASE_MESSAGE_SCHEMA: z.ZodObject<z.objectUtil.extendShape<{
19
+ id: z.ZodString;
20
+ timestamp: z.ZodString;
21
+ type: z.ZodLiteral<string>;
22
+ payload: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
23
+ }, {
24
+ metadata: z.ZodOptional<z.ZodObject<{
25
+ schemaVersion: z.ZodString;
26
+ producedBy: z.ZodString;
27
+ originatedFrom: z.ZodString;
28
+ correlationId: z.ZodString;
29
+ }, "strip", z.ZodTypeAny, {
30
+ schemaVersion: string;
31
+ producedBy: string;
32
+ originatedFrom: string;
33
+ correlationId: string;
34
+ }, {
35
+ schemaVersion: string;
36
+ producedBy: string;
37
+ originatedFrom: string;
38
+ correlationId: string;
39
+ }>>;
40
+ }>, "strip", z.ZodTypeAny, {
41
+ id: string;
42
+ timestamp: string;
43
+ type: string;
44
+ payload?: {} | undefined;
45
+ metadata?: {
46
+ schemaVersion: string;
47
+ producedBy: string;
48
+ originatedFrom: string;
49
+ correlationId: string;
50
+ } | undefined;
51
+ }, {
52
+ id: string;
53
+ timestamp: string;
54
+ type: string;
55
+ payload?: {} | undefined;
56
+ metadata?: {
57
+ schemaVersion: string;
58
+ producedBy: string;
59
+ originatedFrom: string;
60
+ correlationId: string;
61
+ } | undefined;
62
+ }>;
63
+ export type BaseMessageType = z.infer<typeof BASE_MESSAGE_SCHEMA>;
64
+ export type MessageMetadataType = z.infer<typeof MESSAGE_METADATA_SCHEMA>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BASE_MESSAGE_SCHEMA = exports.MESSAGE_METADATA_SCHEMA = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const zod_1 = tslib_1.__importDefault(require("zod"));
6
+ const baseEventSchemas_1 = require("../events/baseEventSchemas");
7
+ // External message metadata that describe the context in which the message was created, primarily used for debugging purposes
8
+ exports.MESSAGE_METADATA_SCHEMA = zod_1.default
9
+ .object({
10
+ schemaVersion: zod_1.default.string().min(1).describe('message schema version'),
11
+ // this is always set to a service that created the message
12
+ producedBy: zod_1.default.string().min(1).describe('app/service that produced the message'),
13
+ // this is always propagated within the message chain. For the first message in the chain it is equal to "producedBy"
14
+ originatedFrom: zod_1.default
15
+ .string()
16
+ .min(1)
17
+ .describe('app/service that initiated entire workflow that led to creating this message'),
18
+ // this is always propagated within the message chain.
19
+ correlationId: zod_1.default.string().describe('unique identifier passed to all events in workflow chain'),
20
+ })
21
+ .describe('external message metadata');
22
+ exports.BASE_MESSAGE_SCHEMA = baseEventSchemas_1.BASE_EVENT_SCHEMA.extend({
23
+ // For internal domain events that did not originate within a message chain metadata field can be omitted, producer should then assume it is initiating a new chain
24
+ metadata: exports.MESSAGE_METADATA_SCHEMA.optional(),
25
+ });
26
+ //# sourceMappingURL=baseMessageSchemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseMessageSchemas.js","sourceRoot":"","sources":["../../../lib/messages/baseMessageSchemas.ts"],"names":[],"mappings":";;;;AAAA,sDAAmB;AAEnB,iEAA8D;AAE9D,8HAA8H;AACjH,QAAA,uBAAuB,GAAG,aAAC;KACrC,MAAM,CAAC;IACN,aAAa,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,wBAAwB,CAAC;IACnE,2DAA2D;IAC3D,UAAU,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,uCAAuC,CAAC;IAC/E,qHAAqH;IACrH,cAAc,EAAE,aAAC;SACd,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CAAC,8EAA8E,CAAC;IAC3F,sDAAsD;IACtD,aAAa,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,0DAA0D,CAAC;CAC/F,CAAC;KACD,QAAQ,CAAC,2BAA2B,CAAC,CAAA;AAE3B,QAAA,mBAAmB,GAAG,oCAAiB,CAAC,MAAM,CAAC;IAC1D,mKAAmK;IACnK,QAAQ,EAAE,+BAAuB,CAAC,QAAQ,EAAE;CAC7C,CAAC,CAAA"}
@@ -1,3 +1,4 @@
1
+ import type { TransactionObservabilityManager } from '@lokalise/node-core';
1
2
  import type { ZodSchema } from 'zod';
2
3
  export interface QueueConsumer {
3
4
  start(): Promise<unknown>;
@@ -10,10 +11,7 @@ export interface SyncPublisher<MessagePayloadType> {
10
11
  export interface AsyncPublisher<MessagePayloadType, MessageOptions> {
11
12
  publish(message: MessagePayloadType, options: MessageOptions): Promise<unknown>;
12
13
  }
13
- export type TransactionObservabilityManager = {
14
- start: (transactionSpanId: string) => unknown;
15
- stop: (transactionSpanId: string) => unknown;
16
- };
14
+ export { TransactionObservabilityManager };
17
15
  export type LogFn = {
18
16
  <T extends object>(obj: T, msg?: string, ...args: any[]): void;
19
17
  (obj: unknown, msg?: string, ...args: any[]): void;
@@ -0,0 +1 @@
1
+ export declare const toDatePreprocessor: (value: unknown) => unknown;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDatePreprocessor = void 0;
4
+ const toDatePreprocessor = (value) => {
5
+ switch (typeof value) {
6
+ case 'string':
7
+ case 'number':
8
+ return new Date(value);
9
+ default:
10
+ return value; // could not coerce, return the original and face the consequences during validation
11
+ }
12
+ };
13
+ exports.toDatePreprocessor = toDatePreprocessor;
14
+ //# sourceMappingURL=toDateProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toDateProcessor.js","sourceRoot":"","sources":["../../../lib/utils/toDateProcessor.ts"],"names":[],"mappings":";;;AAAO,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAAE,EAAE;IACnD,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ;YACX,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAA;QAExB;YACE,OAAO,KAAK,CAAA,CAAC,oFAAoF;IACrG,CAAC;AACH,CAAC,CAAA;AATY,QAAA,kBAAkB,sBAS9B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@message-queue-toolkit/core",
3
- "version": "11.0.0",
3
+ "version": "12.0.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Useful utilities, interfaces and base classes for message queue handling. Supports AMQP and SQS with a common abstraction on top currently",
@@ -25,22 +25,23 @@
25
25
  "prepublishOnly": "npm run build:release"
26
26
  },
27
27
  "dependencies": {
28
- "@lokalise/node-core": "^9.14.0",
28
+ "@lokalise/node-core": "^9.17.0",
29
29
  "fast-equals": "^5.0.1",
30
- "toad-cache": "^3.7.0"
30
+ "toad-cache": "^3.7.0",
31
+ "zod": "^3.23.6"
31
32
  },
32
33
  "devDependencies": {
33
- "@types/node": "^20.11.25",
34
+ "@types/node": "^20.12.8",
34
35
  "@typescript-eslint/eslint-plugin": "^7.7.1",
35
36
  "@typescript-eslint/parser": "^7.7.1",
36
- "@vitest/coverage-v8": "^1.5.0",
37
+ "@vitest/coverage-v8": "^1.6.0",
37
38
  "del-cli": "^5.1.0",
38
39
  "eslint": "^8.57.0",
39
40
  "eslint-plugin-import": "^2.29.1",
40
41
  "eslint-plugin-vitest": "0.4.1",
41
42
  "prettier": "^3.2.5",
42
43
  "typescript": "^5.4.5",
43
- "vitest": "^1.5.0"
44
+ "vitest": "^1.6.0"
44
45
  },
45
46
  "homepage": "https://github.com/kibertoad/message-queue-toolkit",
46
47
  "repository": {