@message-queue-toolkit/core 12.0.0 → 12.1.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 +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/queues/AbstractQueueService.d.ts +3 -1
- package/dist/lib/queues/AbstractQueueService.js +17 -2
- package/dist/lib/queues/AbstractQueueService.js.map +1 -1
- package/dist/lib/types/queueOptionsTypes.d.ts +2 -0
- package/dist/lib/utils/dateUtils.d.ts +7 -0
- package/dist/lib/utils/dateUtils.js +15 -0
- package/dist/lib/utils/dateUtils.js.map +1 -0
- package/dist/lib/utils/parseUtils.d.ts +21 -1
- package/dist/lib/utils/parseUtils.js +18 -3
- package/dist/lib/utils/parseUtils.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export { MessageSchemaContainer } from './lib/queues/MessageSchemaContainer';
|
|
|
13
13
|
export type { MessageSchemaContainerOptions } from './lib/queues/MessageSchemaContainer';
|
|
14
14
|
export { objectToBuffer } from './lib/utils/queueUtils';
|
|
15
15
|
export { waitAndRetry } from './lib/utils/waitUtils';
|
|
16
|
-
export { parseMessage } from './lib/utils/parseUtils';
|
|
16
|
+
export { type ParseMessageResult, parseMessage } from './lib/utils/parseUtils';
|
|
17
|
+
export { isRetryDateExceeded } from './lib/utils/dateUtils';
|
|
17
18
|
export { toDatePreprocessor } from './lib/utils/toDateProcessor';
|
|
18
19
|
export { reloadConfig, isProduction } from './lib/utils/envUtils';
|
|
19
20
|
export { DomainEventEmitter } from './lib/events/DomainEventEmitter';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
3
|
+
exports.FakeListener = exports.EventRegistry = exports.DomainEventEmitter = exports.isProduction = exports.reloadConfig = exports.toDatePreprocessor = exports.isRetryDateExceeded = 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,6 +30,8 @@ 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 dateUtils_1 = require("./lib/utils/dateUtils");
|
|
34
|
+
Object.defineProperty(exports, "isRetryDateExceeded", { enumerable: true, get: function () { return dateUtils_1.isRetryDateExceeded; } });
|
|
33
35
|
var toDateProcessor_1 = require("./lib/utils/toDateProcessor");
|
|
34
36
|
Object.defineProperty(exports, "toDatePreprocessor", { enumerable: true, get: function () { return toDateProcessor_1.toDatePreprocessor; } });
|
|
35
37
|
var envUtils_1 = require("./lib/utils/envUtils");
|
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,
|
|
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,qDAA8E;AAA5C,0GAAA,YAAY,OAAA;AAC9C,mDAA2D;AAAlD,gHAAA,mBAAmB,OAAA;AAC5B,+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"}
|
|
@@ -12,8 +12,9 @@ type CommonQueueLocator = {
|
|
|
12
12
|
export declare abstract class AbstractQueueService<MessagePayloadSchemas extends object, MessageEnvelopeType extends object, DependenciesType extends QueueDependencies, QueueConfiguration extends object, QueueLocatorType extends object = CommonQueueLocator, OptionsType extends QueueOptions<QueueConfiguration, QueueLocatorType> = QueueOptions<QueueConfiguration, QueueLocatorType>, ExecutionContext = undefined, PrehandlerOutput = undefined> {
|
|
13
13
|
protected readonly errorReporter: ErrorReporter;
|
|
14
14
|
readonly logger: Logger;
|
|
15
|
-
protected readonly messageTypeField: string;
|
|
16
15
|
protected readonly messageIdField: string;
|
|
16
|
+
protected readonly messageTypeField: string;
|
|
17
|
+
protected readonly messageTimestampField: string;
|
|
17
18
|
protected readonly logMessages: boolean;
|
|
18
19
|
protected readonly creationConfig?: QueueConfiguration;
|
|
19
20
|
protected readonly locatorConfig?: QueueLocatorType;
|
|
@@ -36,6 +37,7 @@ export declare abstract class AbstractQueueService<MessagePayloadSchemas extends
|
|
|
36
37
|
protected handleMessageProcessed(message: MessagePayloadSchemas | null, processingResult: MessageProcessingResult, messageId?: string): void;
|
|
37
38
|
protected processPrehandlersInternal(preHandlers: Prehandler<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>[], message: MessagePayloadSchemas): Promise<PrehandlerOutput>;
|
|
38
39
|
protected preHandlerBarrierInternal<BarrierOutput>(barrier: BarrierCallback<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput, BarrierOutput> | undefined, message: MessagePayloadSchemas, executionContext: ExecutionContext, preHandlerOutput: PrehandlerOutput): Promise<BarrierResult<BarrierOutput>>;
|
|
40
|
+
protected tryToExtractTimestamp(message: MessagePayloadSchemas): Date | undefined;
|
|
39
41
|
protected abstract resolveNextFunction(preHandlers: Prehandler<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>[], message: MessagePayloadSchemas, index: number, preHandlerOutput: PrehandlerOutput, resolve: (value: PrehandlerOutput | PromiseLike<PrehandlerOutput>) => void, reject: (err: Error) => void): (preHandlerResult: PrehandlerResult) => void;
|
|
40
42
|
protected resolveNextPreHandlerFunctionInternal(preHandlers: Prehandler<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>[], executionContext: ExecutionContext, message: MessagePayloadSchemas, index: number, preHandlerOutput: PrehandlerOutput, resolve: (value: PrehandlerOutput | PromiseLike<PrehandlerOutput>) => void, reject: (err: Error) => void): (preHandlerResult: PrehandlerResult) => void;
|
|
41
43
|
protected abstract processPrehandlers(message: MessagePayloadSchemas, messageType: string): Promise<PrehandlerOutput>;
|
|
@@ -3,12 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AbstractQueueService = void 0;
|
|
4
4
|
const node_util_1 = require("node:util");
|
|
5
5
|
const node_core_1 = require("@lokalise/node-core");
|
|
6
|
+
const toDateProcessor_1 = require("../utils/toDateProcessor");
|
|
6
7
|
const HandlerSpy_1 = require("./HandlerSpy");
|
|
7
8
|
class AbstractQueueService {
|
|
8
9
|
errorReporter;
|
|
9
10
|
logger;
|
|
10
|
-
messageTypeField;
|
|
11
11
|
messageIdField;
|
|
12
|
+
messageTypeField;
|
|
13
|
+
messageTimestampField;
|
|
12
14
|
logMessages;
|
|
13
15
|
creationConfig;
|
|
14
16
|
locatorConfig;
|
|
@@ -23,8 +25,9 @@ class AbstractQueueService {
|
|
|
23
25
|
constructor({ errorReporter, logger }, options) {
|
|
24
26
|
this.errorReporter = errorReporter;
|
|
25
27
|
this.logger = logger;
|
|
26
|
-
this.messageTypeField = options.messageTypeField;
|
|
27
28
|
this.messageIdField = options.messageIdField ?? 'id';
|
|
29
|
+
this.messageTypeField = options.messageTypeField;
|
|
30
|
+
this.messageTimestampField = options.messageTimestampField ?? 'timestamp';
|
|
28
31
|
this.creationConfig = options.creationConfig;
|
|
29
32
|
this.locatorConfig = options.locatorConfig;
|
|
30
33
|
this.deletionConfig = options.deletionConfig;
|
|
@@ -103,6 +106,18 @@ class AbstractQueueService {
|
|
|
103
106
|
// @ts-ignore
|
|
104
107
|
return await barrier(message, executionContext, preHandlerOutput);
|
|
105
108
|
}
|
|
109
|
+
tryToExtractTimestamp(message) {
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
if (this.messageTimestampField in message) {
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
const res = (0, toDateProcessor_1.toDatePreprocessor)(message[this.messageTimestampField]);
|
|
114
|
+
if (!(res instanceof Date)) {
|
|
115
|
+
throw new Error(`${this.messageTimestampField} invalid type`);
|
|
116
|
+
}
|
|
117
|
+
return res;
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
106
121
|
// eslint-disable-next-line max-params
|
|
107
122
|
resolveNextPreHandlerFunctionInternal(preHandlers, executionContext, message, index, preHandlerOutput, resolve, reject) {
|
|
108
123
|
return (preHandlerResult) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractQueueService.js","sourceRoot":"","sources":["../../../lib/queues/AbstractQueueService.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAGjC,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AAC,qBAAqB,CAAC,CAAC,CAAA;YACnE,IAAI,CAAC,CAAC,GAAG,YAAY,IAAI,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,qBAAqB,eAAe,CAAC,CAAA;YAC/D,CAAC;YAED,OAAO,GAAG,CAAA;QACZ,CAAC;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;IAWD,sCAAsC;IAC5B,qCAAqC,CAC7C,WAAoF,EACpF,gBAAkC,EAClC,OAA8B,EAC9B,KAAa,EACb,gBAAkC,EAClC,OAA0E,EAC1E,MAA4B;QAE5B,OAAO,CAAC,gBAAkC,EAAE,EAAE;YAC5C,IAAI,gBAAgB,CAAC,KAAK,EAAE,CAAC;gBAC3B,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;YAChC,CAAC;YAED,IAAI,WAAW,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC;gBACnC,OAAO,CAAC,gBAAgB,CAAC,CAAA;YAC3B,CAAC;iBAAM,CAAC;gBACN,6DAA6D;gBAC7D,WAAW,CAAC,KAAK,CAAC,CAChB,OAAO,EACP,gBAAgB;gBAChB,aAAa;gBACb,gBAAgB,EAChB,IAAI,CAAC,qCAAqC,CACxC,WAAW,EACX,gBAAgB,EAChB,OAAO,EACP,KAAK,GAAG,CAAC,EACT,gBAAgB,EAChB,OAAO,EACP,MAAM,CACP,CACF,CAAA;YACH,CAAC;QACH,CAAC,CAAA;IACH,CAAC;CAqBF;AAxPD,oDAwPC"}
|
|
@@ -14,6 +14,7 @@ export type QueueConsumerDependencies = {
|
|
|
14
14
|
export type CommonQueueOptions = {
|
|
15
15
|
messageTypeField: string;
|
|
16
16
|
messageIdField?: string;
|
|
17
|
+
messageTimestampField?: string;
|
|
17
18
|
handlerSpy?: HandlerSpy<object> | HandlerSpyParams | boolean;
|
|
18
19
|
logMessages?: boolean;
|
|
19
20
|
deletionConfig?: DeletionConfig;
|
|
@@ -44,5 +45,6 @@ export type DeadLetterQueueOptions<CreationConfigType extends object, QueueLocat
|
|
|
44
45
|
export type QueueConsumerOptions<CreationConfigType extends object, QueueLocatorType extends object, DeadLetterQueueIntegrationOptions extends object, MessagePayloadSchemas extends object, ExecutionContext, PrehandlerOutput = undefined, DeadLetterQueueCreationConfigType extends object = CreationConfigType, DeadLetterQueueQueueLocatorType extends object = QueueLocatorType> = QueueOptions<CreationConfigType, QueueLocatorType> & {
|
|
45
46
|
handlers: MessageHandlerConfig<MessagePayloadSchemas, ExecutionContext, PrehandlerOutput>[];
|
|
46
47
|
deadLetterQueue?: DeadLetterQueueOptions<DeadLetterQueueCreationConfigType, DeadLetterQueueQueueLocatorType, DeadLetterQueueIntegrationOptions>;
|
|
48
|
+
maxRetryDuration?: number;
|
|
47
49
|
};
|
|
48
50
|
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRetryDateExceeded = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check if the retry date is exceeded
|
|
6
|
+
*
|
|
7
|
+
* @param timestamp
|
|
8
|
+
* @param maxRetryDuration max retry duration in seconds
|
|
9
|
+
*/
|
|
10
|
+
const isRetryDateExceeded = (timestamp, maxRetryDuration) => {
|
|
11
|
+
const lastRetryDate = new Date(timestamp.getTime() + maxRetryDuration * 1000);
|
|
12
|
+
return new Date() > lastRetryDate;
|
|
13
|
+
};
|
|
14
|
+
exports.isRetryDateExceeded = isRetryDateExceeded;
|
|
15
|
+
//# sourceMappingURL=dateUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateUtils.js","sourceRoot":"","sources":["../../../lib/utils/dateUtils.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,MAAM,mBAAmB,GAAG,CAAC,SAAe,EAAE,gBAAwB,EAAW,EAAE;IACxF,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,gBAAgB,GAAG,IAAI,CAAC,CAAA;IAC7E,OAAO,IAAI,IAAI,EAAE,GAAG,aAAa,CAAA;AACnC,CAAC,CAAA;AAHY,QAAA,mBAAmB,uBAG/B"}
|
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import type { Either, ErrorResolver } from '@lokalise/node-core';
|
|
2
2
|
import type { ZodSchema } from 'zod';
|
|
3
3
|
import type { MessageInvalidFormatError, MessageValidationError } from '../errors/Errors';
|
|
4
|
-
export
|
|
4
|
+
export type ParseMessageResult<T> = {
|
|
5
|
+
originalMessage: T;
|
|
6
|
+
parsedMessage: T;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Parses a message payload using the provided schema and error processor to handle validation.
|
|
10
|
+
* The function attempts to parse the message payload based on the provided schema.
|
|
11
|
+
* If successful, it returns a success object containing the parsed message along with the original message.
|
|
12
|
+
* If an error occurs during parsing, it returns an error object processed by the error processor.
|
|
13
|
+
*
|
|
14
|
+
* In success case, it returns original and parsed messages because zod is cutting off additional fields that are not
|
|
15
|
+
* defined in the schema, and we might add extra fields on publish to be used on the consumer side.
|
|
16
|
+
* eg: timestamp to avoid infinite retries on the same message.
|
|
17
|
+
*
|
|
18
|
+
* @param messagePayload The message payload to be parsed.
|
|
19
|
+
* @param schema The Zod schema used for parsing the message payload.
|
|
20
|
+
* @param errorProcessor An error resolver function used to process any validation errors encountered during parsing.
|
|
21
|
+
*
|
|
22
|
+
* @returns Either an object indicating a successful parsing result or an error encountered during parsing.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseMessage<T extends object>(messagePayload: unknown, schema: ZodSchema<T>, errorProcessor: ErrorResolver): Either<MessageInvalidFormatError | MessageValidationError, ParseMessageResult<T>>;
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Parses a message payload using the provided schema and error processor to handle validation.
|
|
6
|
+
* The function attempts to parse the message payload based on the provided schema.
|
|
7
|
+
* If successful, it returns a success object containing the parsed message along with the original message.
|
|
8
|
+
* If an error occurs during parsing, it returns an error object processed by the error processor.
|
|
9
|
+
*
|
|
10
|
+
* In success case, it returns original and parsed messages because zod is cutting off additional fields that are not
|
|
11
|
+
* defined in the schema, and we might add extra fields on publish to be used on the consumer side.
|
|
12
|
+
* eg: timestamp to avoid infinite retries on the same message.
|
|
13
|
+
*
|
|
14
|
+
* @param messagePayload The message payload to be parsed.
|
|
15
|
+
* @param schema The Zod schema used for parsing the message payload.
|
|
16
|
+
* @param errorProcessor An error resolver function used to process any validation errors encountered during parsing.
|
|
17
|
+
*
|
|
18
|
+
* @returns Either an object indicating a successful parsing result or an error encountered during parsing.
|
|
19
|
+
*/
|
|
4
20
|
function parseMessage(messagePayload, schema, errorProcessor) {
|
|
5
21
|
try {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
22
|
+
const parsedMessage = schema.parse(messagePayload);
|
|
23
|
+
return { result: { parsedMessage, originalMessage: messagePayload } };
|
|
9
24
|
}
|
|
10
25
|
catch (exception) {
|
|
11
26
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseUtils.js","sourceRoot":"","sources":["../../../lib/utils/parseUtils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"parseUtils.js","sourceRoot":"","sources":["../../../lib/utils/parseUtils.ts"],"names":[],"mappings":";;;AAUA;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,YAAY,CAC1B,cAAuB,EACvB,MAAoB,EACpB,cAA6B;IAE7B,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;QAElD,OAAO,EAAE,MAAM,EAAE,EAAE,aAAa,EAAE,eAAe,EAAE,cAAmB,EAAE,EAAE,CAAA;IAC5E,CAAC;IAAC,OAAO,SAAS,EAAE,CAAC;QACnB,OAAO;YACL,KAAK,EAAE,cAAc,CAAC,YAAY,CAAC,SAAS,CAAC;SAC9C,CAAA;IACH,CAAC;AACH,CAAC;AAdD,oCAcC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@message-queue-toolkit/core",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.1.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",
|