@message-queue-toolkit/core 4.1.0 → 5.0.1
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 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/queues/AbstractQueueService.d.ts +9 -3
- package/dist/lib/queues/AbstractQueueService.js +19 -0
- package/dist/lib/queues/AbstractQueueService.js.map +1 -1
- package/dist/lib/queues/HandlerSpy.d.ts +25 -0
- package/dist/lib/queues/HandlerSpy.js +108 -0
- package/dist/lib/queues/HandlerSpy.js.map +1 -0
- package/dist/lib/types/MessageQueueTypes.d.ts +1 -0
- package/package.json +17 -9
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export type { NewQueueOptions, ExistingQueueOptions, NewQueueOptionsMultiSchema,
|
|
|
4
4
|
export { isMessageError, MessageValidationError, MessageInvalidFormatError, } from './lib/errors/Errors';
|
|
5
5
|
export { HandlerContainer, MessageHandlerConfig, MessageHandlerConfigBuilder, BarrierCallbackMultiConsumers, BarrierResult, BarrierResultPositive, BarrierResultNegative, } from './lib/queues/HandlerContainer';
|
|
6
6
|
export type { HandlerContainerOptions, Handler } from './lib/queues/HandlerContainer';
|
|
7
|
+
export { HandlerSpy } from './lib/queues/HandlerSpy';
|
|
8
|
+
export type { SpyResult, HandlerSpyParams, PublicHandlerSpy } from './lib/queues/HandlerSpy';
|
|
7
9
|
export { MessageSchemaContainer } from './lib/queues/MessageSchemaContainer';
|
|
8
10
|
export type { MessageSchemaContainerOptions } from './lib/queues/MessageSchemaContainer';
|
|
9
11
|
export { objectToBuffer } from './lib/utils/queueUtils';
|
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.MessageHandlerConfigBuilder = exports.MessageHandlerConfig = exports.HandlerContainer = exports.MessageInvalidFormatError = exports.MessageValidationError = exports.isMessageError = exports.AbstractQueueService = void 0;
|
|
3
|
+
exports.isProduction = exports.reloadConfig = exports.parseMessage = exports.waitAndRetry = exports.objectToBuffer = exports.MessageSchemaContainer = exports.HandlerSpy = exports.MessageHandlerConfigBuilder = exports.MessageHandlerConfig = exports.HandlerContainer = exports.MessageInvalidFormatError = exports.MessageValidationError = exports.isMessageError = exports.AbstractQueueService = void 0;
|
|
4
4
|
var AbstractQueueService_1 = require("./lib/queues/AbstractQueueService");
|
|
5
5
|
Object.defineProperty(exports, "AbstractQueueService", { enumerable: true, get: function () { return AbstractQueueService_1.AbstractQueueService; } });
|
|
6
6
|
var Errors_1 = require("./lib/errors/Errors");
|
|
@@ -11,6 +11,8 @@ var HandlerContainer_1 = require("./lib/queues/HandlerContainer");
|
|
|
11
11
|
Object.defineProperty(exports, "HandlerContainer", { enumerable: true, get: function () { return HandlerContainer_1.HandlerContainer; } });
|
|
12
12
|
Object.defineProperty(exports, "MessageHandlerConfig", { enumerable: true, get: function () { return HandlerContainer_1.MessageHandlerConfig; } });
|
|
13
13
|
Object.defineProperty(exports, "MessageHandlerConfigBuilder", { enumerable: true, get: function () { return HandlerContainer_1.MessageHandlerConfigBuilder; } });
|
|
14
|
+
var HandlerSpy_1 = require("./lib/queues/HandlerSpy");
|
|
15
|
+
Object.defineProperty(exports, "HandlerSpy", { enumerable: true, get: function () { return HandlerSpy_1.HandlerSpy; } });
|
|
14
16
|
var MessageSchemaContainer_1 = require("./lib/queues/MessageSchemaContainer");
|
|
15
17
|
Object.defineProperty(exports, "MessageSchemaContainer", { enumerable: true, get: function () { return MessageSchemaContainer_1.MessageSchemaContainer; } });
|
|
16
18
|
var queueUtils_1 = require("./lib/utils/queueUtils");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAWA,0EAAwE;AAA/D,4HAAA,oBAAoB,OAAA;AAgB7B,8CAI4B;AAH1B,wGAAA,cAAc,OAAA;AACd,gHAAA,sBAAsB,OAAA;AACtB,mHAAA,yBAAyB,OAAA;AAG3B,kEAQsC;AAPpC,oHAAA,gBAAgB,OAAA;AAChB,wHAAA,oBAAoB,OAAA;AACpB,+HAAA,2BAA2B,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAWA,0EAAwE;AAA/D,4HAAA,oBAAoB,OAAA;AAgB7B,8CAI4B;AAH1B,wGAAA,cAAc,OAAA;AACd,gHAAA,sBAAsB,OAAA;AACtB,mHAAA,yBAAyB,OAAA;AAG3B,kEAQsC;AAPpC,oHAAA,gBAAgB,OAAA;AAChB,wHAAA,oBAAoB,OAAA;AACpB,+HAAA,2BAA2B,OAAA;AAO7B,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,8 +1,9 @@
|
|
|
1
1
|
import type { ErrorReporter, ErrorResolver, Either } from '@lokalise/node-core';
|
|
2
2
|
import type { ZodSchema, ZodType } from 'zod';
|
|
3
3
|
import type { MessageInvalidFormatError, MessageValidationError } from '../errors/Errors';
|
|
4
|
-
import type { Logger, TransactionObservabilityManager } from '../types/MessageQueueTypes';
|
|
4
|
+
import type { Logger, TransactionObservabilityManager, MessageProcessingResult } from '../types/MessageQueueTypes';
|
|
5
5
|
import type { MessageHandlerConfig } from './HandlerContainer';
|
|
6
|
+
import type { HandlerSpy, PublicHandlerSpy, HandlerSpyParams } from './HandlerSpy';
|
|
6
7
|
export type QueueDependencies = {
|
|
7
8
|
errorReporter: ErrorReporter;
|
|
8
9
|
logger: Logger;
|
|
@@ -20,16 +21,17 @@ export type DeletionConfig = {
|
|
|
20
21
|
forceDeleteInProduction?: boolean;
|
|
21
22
|
};
|
|
22
23
|
export type CommonQueueOptions = {
|
|
24
|
+
messageTypeField: string;
|
|
25
|
+
messageIdField?: string;
|
|
26
|
+
handlerSpy?: HandlerSpy<object> | HandlerSpyParams | boolean;
|
|
23
27
|
logMessages?: boolean;
|
|
24
28
|
};
|
|
25
29
|
export type NewQueueOptions<CreationConfigType extends object> = {
|
|
26
|
-
messageTypeField: string;
|
|
27
30
|
locatorConfig?: never;
|
|
28
31
|
deletionConfig?: DeletionConfig;
|
|
29
32
|
creationConfig: CreationConfigType;
|
|
30
33
|
} & CommonQueueOptions;
|
|
31
34
|
export type ExistingQueueOptions<QueueLocatorType extends object> = {
|
|
32
|
-
messageTypeField: string;
|
|
33
35
|
locatorConfig: QueueLocatorType;
|
|
34
36
|
deletionConfig?: DeletionConfig;
|
|
35
37
|
creationConfig?: never;
|
|
@@ -50,10 +52,13 @@ export declare abstract class AbstractQueueService<MessagePayloadSchemas extends
|
|
|
50
52
|
protected readonly errorReporter: ErrorReporter;
|
|
51
53
|
readonly logger: Logger;
|
|
52
54
|
protected readonly messageTypeField: string;
|
|
55
|
+
protected readonly messageIdField: string;
|
|
53
56
|
protected readonly logMessages: boolean;
|
|
54
57
|
protected readonly creationConfig?: QueueConfiguration;
|
|
55
58
|
protected readonly locatorConfig?: QueueLocatorType;
|
|
56
59
|
protected readonly deletionConfig?: DeletionConfig;
|
|
60
|
+
protected readonly _handlerSpy?: HandlerSpy<MessagePayloadSchemas>;
|
|
61
|
+
get handlerSpy(): PublicHandlerSpy<MessagePayloadSchemas>;
|
|
57
62
|
constructor({ errorReporter, logger }: DependenciesType, options: OptionsType);
|
|
58
63
|
protected abstract resolveSchema(message: MessagePayloadSchemas): Either<Error, ZodSchema<MessagePayloadSchemas>>;
|
|
59
64
|
protected abstract resolveMessage(message: MessageEnvelopeType): Either<MessageInvalidFormatError | MessageValidationError, unknown>;
|
|
@@ -66,5 +71,6 @@ export declare abstract class AbstractQueueService<MessagePayloadSchemas extends
|
|
|
66
71
|
*/
|
|
67
72
|
protected logMessage(messageLogEntry: unknown): void;
|
|
68
73
|
protected handleError(err: unknown, context?: Record<string, unknown>): void;
|
|
74
|
+
protected handleMessageProcessed(message: MessagePayloadSchemas | null, processingResult: MessageProcessingResult, messageId?: string): void;
|
|
69
75
|
abstract close(): Promise<unknown>;
|
|
70
76
|
}
|
|
@@ -3,22 +3,33 @@ 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 HandlerSpy_1 = require("./HandlerSpy");
|
|
6
7
|
class AbstractQueueService {
|
|
7
8
|
errorReporter;
|
|
8
9
|
logger;
|
|
9
10
|
messageTypeField;
|
|
11
|
+
messageIdField;
|
|
10
12
|
logMessages;
|
|
11
13
|
creationConfig;
|
|
12
14
|
locatorConfig;
|
|
13
15
|
deletionConfig;
|
|
16
|
+
_handlerSpy;
|
|
17
|
+
get handlerSpy() {
|
|
18
|
+
if (!this._handlerSpy) {
|
|
19
|
+
throw new Error('HandlerSpy was not instantiated, please pass `handlerSpy` parameter during queue service creation.');
|
|
20
|
+
}
|
|
21
|
+
return this._handlerSpy;
|
|
22
|
+
}
|
|
14
23
|
constructor({ errorReporter, logger }, options) {
|
|
15
24
|
this.errorReporter = errorReporter;
|
|
16
25
|
this.logger = logger;
|
|
17
26
|
this.messageTypeField = options.messageTypeField;
|
|
27
|
+
this.messageIdField = options.messageIdField ?? 'id';
|
|
18
28
|
this.creationConfig = options.creationConfig;
|
|
19
29
|
this.locatorConfig = options.locatorConfig;
|
|
20
30
|
this.deletionConfig = options.deletionConfig;
|
|
21
31
|
this.logMessages = options.logMessages ?? false;
|
|
32
|
+
this._handlerSpy = (0, HandlerSpy_1.resolveHandlerSpy)(options);
|
|
22
33
|
}
|
|
23
34
|
/**
|
|
24
35
|
* Format message for logging
|
|
@@ -47,6 +58,14 @@ class AbstractQueueService {
|
|
|
47
58
|
this.errorReporter.report({ error: err, context });
|
|
48
59
|
}
|
|
49
60
|
}
|
|
61
|
+
handleMessageProcessed(message, processingResult, messageId) {
|
|
62
|
+
if (this._handlerSpy) {
|
|
63
|
+
this._handlerSpy.addProcessedMessage({
|
|
64
|
+
message,
|
|
65
|
+
processingResult,
|
|
66
|
+
}, messageId);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
50
69
|
}
|
|
51
70
|
exports.AbstractQueueService = AbstractQueueService;
|
|
52
71
|
//# sourceMappingURL=AbstractQueueService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractQueueService.js","sourceRoot":"","sources":["../../../lib/queues/AbstractQueueService.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAGjC,mDAAiE;
|
|
1
|
+
{"version":3,"file":"AbstractQueueService.js","sourceRoot":"","sources":["../../../lib/queues/AbstractQueueService.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAGjC,mDAAiE;AAYjE,6CAAgD;AAyEhD,MAAsB,oBAAoB;IAYrB,aAAa,CAAe;IAC/B,MAAM,CAAQ;IACX,gBAAgB,CAAQ;IACxB,cAAc,CAAQ;IACtB,WAAW,CAAS;IACpB,cAAc,CAAqB;IACnC,aAAa,CAAmB;IAChC,cAAc,CAAiB;IAC/B,WAAW,CAAoC;IAElE,IAAI,UAAU;QACZ,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CACb,oGAAoG,CACrG,CAAA;QACH,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;IAED,YAAY,EAAE,aAAa,EAAE,MAAM,EAAoB,EAA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KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAA;QACpD,CAAC;IACH,CAAC;IAES,sBAAsB,CAC9B,OAAqC,EACrC,gBAAyC,EACzC,SAAkB;QAElB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAClC;gBACE,OAAO;gBACP,gBAAgB;aACjB,EACD,SAAS,CACV,CAAA;QACH,CAAC;IACH,CAAC;CAGF;AAnGD,oDAmGC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MessageProcessingResult } from '../types/MessageQueueTypes';
|
|
2
|
+
import type { CommonQueueOptions } from './AbstractQueueService';
|
|
3
|
+
export type HandlerSpyParams = {
|
|
4
|
+
bufferSize?: number;
|
|
5
|
+
messageIdField?: string;
|
|
6
|
+
};
|
|
7
|
+
export type SpyResult<MessagePayloadSchemas extends object> = {
|
|
8
|
+
message: MessagePayloadSchemas | null;
|
|
9
|
+
processingResult: MessageProcessingResult;
|
|
10
|
+
};
|
|
11
|
+
export declare function isHandlerSpy<T extends object>(value: unknown): value is HandlerSpy<T>;
|
|
12
|
+
export type PublicHandlerSpy<MessagePayloadSchemas extends object> = Omit<HandlerSpy<MessagePayloadSchemas>, 'addProcessedMessage'>;
|
|
13
|
+
export declare class HandlerSpy<MessagePayloadSchemas extends object> {
|
|
14
|
+
name: string;
|
|
15
|
+
private readonly messageBuffer;
|
|
16
|
+
private readonly messageIdField;
|
|
17
|
+
private readonly spyPromises;
|
|
18
|
+
constructor(params?: HandlerSpyParams);
|
|
19
|
+
private messageMatchesFilter;
|
|
20
|
+
waitForMessageWithId(id: string, processingResult?: MessageProcessingResult): Promise<SpyResult<MessagePayloadSchemas>>;
|
|
21
|
+
waitForMessage(fields: Partial<MessagePayloadSchemas>, processingResult?: MessageProcessingResult): Promise<SpyResult<MessagePayloadSchemas>>;
|
|
22
|
+
clear(): void;
|
|
23
|
+
addProcessedMessage(processingResult: SpyResult<MessagePayloadSchemas>, messageId?: string): void;
|
|
24
|
+
}
|
|
25
|
+
export declare function resolveHandlerSpy<T extends object>(queueOptions: CommonQueueOptions): HandlerSpy<T> | undefined;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveHandlerSpy = exports.HandlerSpy = exports.isHandlerSpy = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const node_core_1 = require("@lokalise/node-core");
|
|
6
|
+
const fast_equals_1 = require("fast-equals");
|
|
7
|
+
const toad_cache_1 = require("toad-cache");
|
|
8
|
+
function isHandlerSpy(value) {
|
|
9
|
+
return ((0, node_core_1.isObject)(value) &&
|
|
10
|
+
(value instanceof HandlerSpy || value.name === 'HandlerSpy'));
|
|
11
|
+
}
|
|
12
|
+
exports.isHandlerSpy = isHandlerSpy;
|
|
13
|
+
class HandlerSpy {
|
|
14
|
+
name = 'HandlerSpy';
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
messageBuffer;
|
|
17
|
+
messageIdField;
|
|
18
|
+
spyPromises;
|
|
19
|
+
constructor(params = {}) {
|
|
20
|
+
this.messageBuffer = new toad_cache_1.Fifo(params.bufferSize ?? 100);
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
this.messageIdField = params.messageIdField ?? 'id';
|
|
23
|
+
this.spyPromises = [];
|
|
24
|
+
}
|
|
25
|
+
messageMatchesFilter(spyResult, fields, processingResult) {
|
|
26
|
+
return (Object.entries(fields).every(([key, value]) => {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
return (0, fast_equals_1.deepEqual)(spyResult.message[key], value);
|
|
29
|
+
}) &&
|
|
30
|
+
(!processingResult || spyResult.processingResult === processingResult));
|
|
31
|
+
}
|
|
32
|
+
waitForMessageWithId(id, processingResult) {
|
|
33
|
+
return this.waitForMessage(
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
{
|
|
36
|
+
[this.messageIdField]: id,
|
|
37
|
+
}, processingResult);
|
|
38
|
+
}
|
|
39
|
+
waitForMessage(fields, processingResult) {
|
|
40
|
+
const processedMessageEntry = Object.values(this.messageBuffer.items).find(
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
(spyResult) => {
|
|
43
|
+
return this.messageMatchesFilter(spyResult.value, fields, processingResult);
|
|
44
|
+
});
|
|
45
|
+
if (processedMessageEntry) {
|
|
46
|
+
return Promise.resolve(processedMessageEntry.value);
|
|
47
|
+
}
|
|
48
|
+
let resolve;
|
|
49
|
+
const spyPromise = new Promise((_resolve) => {
|
|
50
|
+
resolve = _resolve;
|
|
51
|
+
});
|
|
52
|
+
this.spyPromises.push({
|
|
53
|
+
promise: spyPromise,
|
|
54
|
+
processingResult,
|
|
55
|
+
fields,
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
resolve,
|
|
58
|
+
});
|
|
59
|
+
return spyPromise;
|
|
60
|
+
}
|
|
61
|
+
clear() {
|
|
62
|
+
this.messageBuffer.clear();
|
|
63
|
+
}
|
|
64
|
+
addProcessedMessage(processingResult, messageId) {
|
|
65
|
+
const resolvedMessageId = processingResult.message?.[this.messageIdField] ?? messageId ?? (0, node_crypto_1.randomUUID)();
|
|
66
|
+
// If we failed to parse message, let's store id at least
|
|
67
|
+
const resolvedProcessingResult = processingResult.message
|
|
68
|
+
? processingResult
|
|
69
|
+
: {
|
|
70
|
+
...processingResult,
|
|
71
|
+
message: {
|
|
72
|
+
[this.messageIdField]: messageId,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
const cacheId = `${resolvedMessageId}-${Date.now()}-${(Math.random() + 1)
|
|
77
|
+
.toString(36)
|
|
78
|
+
.substring(7)}`;
|
|
79
|
+
this.messageBuffer.set(cacheId, resolvedProcessingResult);
|
|
80
|
+
const foundPromise = this.spyPromises.find((spyPromise) => {
|
|
81
|
+
return this.messageMatchesFilter(resolvedProcessingResult, spyPromise.fields, spyPromise.processingResult);
|
|
82
|
+
});
|
|
83
|
+
if (foundPromise) {
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
85
|
+
foundPromise.resolve(processingResult);
|
|
86
|
+
const index = this.spyPromises.indexOf(foundPromise);
|
|
87
|
+
if (index > -1) {
|
|
88
|
+
// only splice array when item is found
|
|
89
|
+
this.spyPromises.splice(index, 1); // 2nd parameter means remove one item only
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.HandlerSpy = HandlerSpy;
|
|
95
|
+
function resolveHandlerSpy(queueOptions) {
|
|
96
|
+
if (isHandlerSpy(queueOptions.handlerSpy)) {
|
|
97
|
+
return queueOptions.handlerSpy;
|
|
98
|
+
}
|
|
99
|
+
if (!queueOptions.handlerSpy) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
if (queueOptions.handlerSpy === true) {
|
|
103
|
+
return new HandlerSpy();
|
|
104
|
+
}
|
|
105
|
+
return new HandlerSpy(queueOptions.handlerSpy);
|
|
106
|
+
}
|
|
107
|
+
exports.resolveHandlerSpy = resolveHandlerSpy;
|
|
108
|
+
//# sourceMappingURL=HandlerSpy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HandlerSpy.js","sourceRoot":"","sources":["../../../lib/queues/HandlerSpy.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AAExC,mDAA8C;AAC9C,6CAAuC;AACvC,2CAAiC;AA6BjC,SAAgB,YAAY,CAAmB,KAAc;IAC3D,OAAO,CACL,IAAA,oBAAQ,EAAC,KAAK,CAAC;QACf,CAAC,KAAK,YAAY,UAAU,IAAK,KAAuC,CAAC,IAAI,KAAK,YAAY,CAAC,CAChG,CAAA;AACH,CAAC;AALD,oCAKC;AAOD,MAAa,UAAU;IACd,IAAI,GAAG,YAAY,CAAA;IAC1B,8DAA8D;IAC7C,aAAa,CAAsB;IACn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AC,MAAM,EACjB,UAAU,CAAC,gBAAgB,CAC5B,CAAA;QACH,CAAC,CAAC,CAAA;QAEF,IAAI,YAAY,EAAE,CAAC;YACjB,6DAA6D;YAC7D,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;YAEtC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;YACpD,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;gBACf,uCAAuC;gBACvC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA,CAAC,2CAA2C;YAC/E,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAjHD,gCAiHC;AAED,SAAgB,iBAAiB,CAAmB,YAAgC;IAClF,IAAI,YAAY,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1C,OAAO,YAAY,CAAC,UAAsC,CAAA;IAC5D,CAAC;IACD,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,YAAY,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;QACrC,OAAO,IAAI,UAAU,EAA8B,CAAA;IACrD,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,YAAY,CAAC,UAAU,CAA6B,CAAA;AAC5E,CAAC;AAZD,8CAYC"}
|
|
@@ -3,6 +3,7 @@ export interface QueueConsumer {
|
|
|
3
3
|
start(): Promise<unknown>;
|
|
4
4
|
close(): Promise<unknown>;
|
|
5
5
|
}
|
|
6
|
+
export type MessageProcessingResult = 'retryLater' | 'consumed' | 'published' | 'error' | 'invalid_message';
|
|
6
7
|
export interface SyncPublisher<MessagePayloadType> {
|
|
7
8
|
publish(message: MessagePayloadType): void;
|
|
8
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@message-queue-toolkit/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
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",
|
|
@@ -17,25 +17,33 @@
|
|
|
17
17
|
"build:release": "del-cli dist && del-cli coverage && npm run lint && tsc --project tsconfig.release.json",
|
|
18
18
|
"lint": "eslint . --ext .ts",
|
|
19
19
|
"lint:fix": "eslint . --ext .ts --fix",
|
|
20
|
-
"test
|
|
20
|
+
"test": "vitest",
|
|
21
|
+
"test:coverage": "npm test -- --coverage",
|
|
21
22
|
"test:ci": "npm run docker:start:dev && npm run test:coverage && npm run docker:stop:dev",
|
|
22
23
|
"docker:start:dev": "",
|
|
23
24
|
"docker:stop:dev": "",
|
|
24
25
|
"format": "prettier --write .",
|
|
25
26
|
"prepublishOnly": "npm run build:release"
|
|
26
27
|
},
|
|
27
|
-
"dependencies": {
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@lokalise/node-core": "^8.3.0",
|
|
30
|
+
"fast-equals": "^5.0.1",
|
|
31
|
+
"toad-cache": "^3.4.1"
|
|
32
|
+
},
|
|
28
33
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^20.
|
|
30
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
31
|
-
"@typescript-eslint/parser": "^6.
|
|
34
|
+
"@types/node": "^20.10.3",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
|
36
|
+
"@typescript-eslint/parser": "^6.13.2",
|
|
37
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
32
38
|
"del-cli": "^5.1.0",
|
|
33
|
-
"eslint": "^8.
|
|
34
|
-
"eslint-config-prettier": "^9.
|
|
39
|
+
"eslint": "^8.55.0",
|
|
40
|
+
"eslint-config-prettier": "^9.1.0",
|
|
35
41
|
"eslint-plugin-import": "^2.29.0",
|
|
36
42
|
"eslint-plugin-prettier": "^5.0.1",
|
|
37
43
|
"prettier": "^3.1.0",
|
|
38
|
-
"typescript": "^5.
|
|
44
|
+
"typescript": "^5.3.2",
|
|
45
|
+
"vitest": "0.34.6",
|
|
46
|
+
"vite": "4.5.0"
|
|
39
47
|
},
|
|
40
48
|
"homepage": "https://github.com/kibertoad/message-queue-toolkit",
|
|
41
49
|
"repository": {
|