@message-queue-toolkit/core 3.2.1 → 3.4.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/lib/queues/AbstractQueueService.d.ts +14 -2
- package/dist/lib/queues/AbstractQueueService.js +14 -0
- package/dist/lib/queues/AbstractQueueService.js.map +1 -1
- package/dist/lib/queues/HandlerContainer.d.ts +12 -6
- package/dist/lib/queues/HandlerContainer.js +9 -5
- package/dist/lib/queues/HandlerContainer.js.map +1 -1
- package/package.json +1 -1
|
@@ -18,18 +18,21 @@ export type DeletionConfig = {
|
|
|
18
18
|
deleteIfExists?: boolean;
|
|
19
19
|
forceDeleteInProduction?: boolean;
|
|
20
20
|
};
|
|
21
|
+
export type CommonQueueOptions = {
|
|
22
|
+
logMessages?: boolean;
|
|
23
|
+
};
|
|
21
24
|
export type NewQueueOptions<CreationConfigType extends object> = {
|
|
22
25
|
messageTypeField: string;
|
|
23
26
|
locatorConfig?: never;
|
|
24
27
|
deletionConfig?: DeletionConfig;
|
|
25
28
|
creationConfig: CreationConfigType;
|
|
26
|
-
};
|
|
29
|
+
} & CommonQueueOptions;
|
|
27
30
|
export type ExistingQueueOptions<QueueLocatorType extends object> = {
|
|
28
31
|
messageTypeField: string;
|
|
29
32
|
locatorConfig: QueueLocatorType;
|
|
30
33
|
deletionConfig?: DeletionConfig;
|
|
31
34
|
creationConfig?: never;
|
|
32
|
-
};
|
|
35
|
+
} & CommonQueueOptions;
|
|
33
36
|
export type MultiSchemaPublisherOptions<MessagePayloadSchemas extends object> = {
|
|
34
37
|
messageSchemas: readonly ZodSchema<MessagePayloadSchemas>[];
|
|
35
38
|
};
|
|
@@ -46,12 +49,21 @@ export declare abstract class AbstractQueueService<MessagePayloadSchemas extends
|
|
|
46
49
|
protected readonly errorReporter: ErrorReporter;
|
|
47
50
|
readonly logger: Logger;
|
|
48
51
|
protected readonly messageTypeField: string;
|
|
52
|
+
protected readonly logMessages: boolean;
|
|
49
53
|
protected readonly creationConfig?: QueueConfiguration;
|
|
50
54
|
protected readonly locatorConfig?: QueueLocatorType;
|
|
51
55
|
protected readonly deletionConfig?: DeletionConfig;
|
|
52
56
|
constructor({ errorReporter, logger }: DependenciesType, options: OptionsType);
|
|
53
57
|
protected abstract resolveSchema(message: MessagePayloadSchemas): Either<Error, ZodSchema<MessagePayloadSchemas>>;
|
|
54
58
|
protected abstract resolveMessage(message: MessageEnvelopeType): Either<MessageInvalidFormatError | MessageValidationError, unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Format message for logging
|
|
61
|
+
*/
|
|
62
|
+
protected resolveMessageLog(message: MessagePayloadSchemas, _messageType: string): unknown;
|
|
63
|
+
/**
|
|
64
|
+
* Log preformatted and potentially presanitized message payload
|
|
65
|
+
*/
|
|
66
|
+
protected logMessage(messageLogEntry: unknown): void;
|
|
55
67
|
protected handleError(err: unknown): void;
|
|
56
68
|
abstract close(): Promise<unknown>;
|
|
57
69
|
}
|
|
@@ -7,6 +7,7 @@ class AbstractQueueService {
|
|
|
7
7
|
errorReporter;
|
|
8
8
|
logger;
|
|
9
9
|
messageTypeField;
|
|
10
|
+
logMessages;
|
|
10
11
|
creationConfig;
|
|
11
12
|
locatorConfig;
|
|
12
13
|
deletionConfig;
|
|
@@ -17,6 +18,19 @@ class AbstractQueueService {
|
|
|
17
18
|
this.creationConfig = options.creationConfig;
|
|
18
19
|
this.locatorConfig = options.locatorConfig;
|
|
19
20
|
this.deletionConfig = options.deletionConfig;
|
|
21
|
+
this.logMessages = options.logMessages ?? false;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Format message for logging
|
|
25
|
+
*/
|
|
26
|
+
resolveMessageLog(message, _messageType) {
|
|
27
|
+
return message;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Log preformatted and potentially presanitized message payload
|
|
31
|
+
*/
|
|
32
|
+
logMessage(messageLogEntry) {
|
|
33
|
+
this.logger.debug(messageLogEntry);
|
|
20
34
|
}
|
|
21
35
|
handleError(err) {
|
|
22
36
|
const logObject = (0, node_core_1.resolveGlobalErrorLogObject)(err);
|
|
@@ -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;AA6EjE,MAAsB,oBAAoB;IAYrB,aAAa,CAAe;IAC/B,MAAM,CAAQ;IACX,gBAAgB,CAAQ;IACxB,WAAW,CAAS;IACpB,cAAc,CAAqB;IACnC,aAAa,CAAmB;IAChC,cAAc,CAAiB;IAElD,YAAY,EAAE,aAAa,EAAE,MAAM,EAAoB,EAAE,OAAoB;QAC3E,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAA;QAChD,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QAC5C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAA;QAC1C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QAE5C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,KAAK,CAAA;IACjD,CAAC;IASD;;OAEG;IACO,iBAAiB,CAAC,OAA8B,EAAE,YAAoB;QAC9E,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;OAEG;IACO,UAAU,CAAC,eAAwB;QAC3C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;IACpC,CAAC;IAES,WAAW,CAAC,GAAY;QAChC,MAAM,SAAS,GAAG,IAAA,uCAA2B,EAAC,GAAG,CAAC,CAAA;QAClD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QAC5B,IAAI,iBAAK,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE;YAC5B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;SAC1C;IACH,CAAC;CAGF;AA9DD,oDA8DC"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import type { Either } from '@lokalise/node-core';
|
|
2
2
|
import type { ZodSchema } from 'zod';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export type LogFormatter<MessagePayloadSchema> = (message: MessagePayloadSchema) => unknown;
|
|
4
|
+
export declare const defaultLogFormatter: <MessagePayloadSchema>(message: MessagePayloadSchema) => MessagePayloadSchema;
|
|
5
|
+
export type HandlerConfigOptions<MessagePayloadSchema> = {
|
|
6
|
+
messageLogFormatter?: LogFormatter<MessagePayloadSchema>;
|
|
7
|
+
};
|
|
8
|
+
export declare class MessageHandlerConfig<const MessagePayloadSchema, const ExecutionContext> {
|
|
9
|
+
readonly schema: ZodSchema<MessagePayloadSchema>;
|
|
10
|
+
readonly messageLogFormatter: LogFormatter<MessagePayloadSchema>;
|
|
11
|
+
readonly handler: Handler<MessagePayloadSchema, ExecutionContext>;
|
|
12
|
+
constructor(schema: ZodSchema<MessagePayloadSchema>, handler: Handler<MessagePayloadSchema, ExecutionContext>, options?: HandlerConfigOptions<MessagePayloadSchema>);
|
|
7
13
|
}
|
|
8
14
|
export declare class MessageHandlerConfigBuilder<MessagePayloadSchemas, ExecutionContext> {
|
|
9
15
|
private readonly configs;
|
|
10
16
|
constructor();
|
|
11
|
-
addConfig<MessagePayloadSchema extends MessagePayloadSchemas>(schema: ZodSchema<MessagePayloadSchema>, handler: Handler<MessagePayloadSchema, ExecutionContext>): this;
|
|
17
|
+
addConfig<MessagePayloadSchema extends MessagePayloadSchemas>(schema: ZodSchema<MessagePayloadSchema>, handler: Handler<MessagePayloadSchema, ExecutionContext>, options?: HandlerConfigOptions<MessagePayloadSchema>): this;
|
|
12
18
|
build(): MessageHandlerConfig<MessagePayloadSchemas, ExecutionContext>[];
|
|
13
19
|
}
|
|
14
20
|
export type Handler<MessagePayloadSchemas, ExecutionContext> = (message: MessagePayloadSchemas, context: ExecutionContext) => Promise<Either<'retryLater', 'success'>>;
|
|
@@ -20,6 +26,6 @@ export declare class HandlerContainer<MessagePayloadSchemas extends object, Exec
|
|
|
20
26
|
private readonly messageHandlers;
|
|
21
27
|
private readonly messageTypeField;
|
|
22
28
|
constructor(options: HandlerContainerOptions<MessagePayloadSchemas, ExecutionContext>);
|
|
23
|
-
resolveHandler(messageType: string):
|
|
29
|
+
resolveHandler(messageType: string): MessageHandlerConfig<MessagePayloadSchemas, ExecutionContext>;
|
|
24
30
|
private resolveHandlerMap;
|
|
25
31
|
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HandlerContainer = exports.MessageHandlerConfigBuilder = exports.MessageHandlerConfig = void 0;
|
|
3
|
+
exports.HandlerContainer = exports.MessageHandlerConfigBuilder = exports.MessageHandlerConfig = exports.defaultLogFormatter = void 0;
|
|
4
|
+
const defaultLogFormatter = (message) => message;
|
|
5
|
+
exports.defaultLogFormatter = defaultLogFormatter;
|
|
4
6
|
class MessageHandlerConfig {
|
|
5
7
|
schema;
|
|
8
|
+
messageLogFormatter;
|
|
6
9
|
handler;
|
|
7
|
-
constructor(schema, handler) {
|
|
10
|
+
constructor(schema, handler, options) {
|
|
8
11
|
this.schema = schema;
|
|
9
12
|
this.handler = handler;
|
|
13
|
+
this.messageLogFormatter = options?.messageLogFormatter ?? exports.defaultLogFormatter;
|
|
10
14
|
}
|
|
11
15
|
}
|
|
12
16
|
exports.MessageHandlerConfig = MessageHandlerConfig;
|
|
@@ -15,9 +19,9 @@ class MessageHandlerConfigBuilder {
|
|
|
15
19
|
constructor() {
|
|
16
20
|
this.configs = [];
|
|
17
21
|
}
|
|
18
|
-
addConfig(schema, handler) {
|
|
22
|
+
addConfig(schema, handler, options) {
|
|
19
23
|
// @ts-ignore
|
|
20
|
-
this.configs.push(new MessageHandlerConfig(schema, handler));
|
|
24
|
+
this.configs.push(new MessageHandlerConfig(schema, handler, options));
|
|
21
25
|
return this;
|
|
22
26
|
}
|
|
23
27
|
build() {
|
|
@@ -44,7 +48,7 @@ class HandlerContainer {
|
|
|
44
48
|
return supportedHandlers.reduce((acc, entry) => {
|
|
45
49
|
// @ts-ignore
|
|
46
50
|
const messageType = entry.schema.shape[this.messageTypeField].value;
|
|
47
|
-
acc[messageType] = entry
|
|
51
|
+
acc[messageType] = entry;
|
|
48
52
|
return acc;
|
|
49
53
|
}, {});
|
|
50
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HandlerContainer.js","sourceRoot":"","sources":["../../../lib/queues/HandlerContainer.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"HandlerContainer.js","sourceRoot":"","sources":["../../../lib/queues/HandlerContainer.ts"],"names":[],"mappings":";;;AAKO,MAAM,mBAAmB,GAAG,CAAuB,OAA6B,EAAE,EAAE,CAAC,OAAO,CAAA;AAAtF,QAAA,mBAAmB,uBAAmE;AAMnG,MAAa,oBAAoB;IACf,MAAM,CAAiC;IACvC,mBAAmB,CAAoC;IACvD,OAAO,CAAiD;IAExE,YACE,MAAuC,EACvC,OAAwD,EACxD,OAAoD;QAEpD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,mBAAmB,GAAG,OAAO,EAAE,mBAAmB,IAAI,2BAAmB,CAAA;IAChF,CAAC;CACF;AAdD,oDAcC;AAED,MAAa,2BAA2B;IACrB,OAAO,CAAiE;IAEzF;QACE,IAAI,CAAC,OAAO,G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olkit/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.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",
|