@message-queue-toolkit/core 1.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 +5 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/queues/AbstractQueueService.d.ts +28 -0
- package/dist/lib/queues/AbstractQueueService.js +30 -0
- package/dist/lib/queues/AbstractQueueService.js.map +1 -0
- package/dist/lib/types/MessageQueueTypes.d.ts +27 -0
- package/dist/lib/types/MessageQueueTypes.js +3 -0
- package/dist/lib/types/MessageQueueTypes.js.map +1 -0
- package/dist/lib/utils/queueUtils.d.ts +2 -0
- package/dist/lib/utils/queueUtils.js +8 -0
- package/dist/lib/utils/queueUtils.js.map +1 -0
- package/dist/lib/utils/waitUtils.d.ts +1 -0
- package/dist/lib/utils/waitUtils.js +32 -0
- package/dist/lib/utils/waitUtils.js.map +1 -0
- package/package.json +61 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { QueueConsumer, AsyncPublisher, SyncPublisher, TransactionObservabilityManager, Logger, } from './lib/types/MessageQueueTypes';
|
|
2
|
+
export { AbstractQueueService } from './lib/queues/AbstractQueueService';
|
|
3
|
+
export type { QueueOptions, QueueDependencies, QueueConsumerDependencies, } from './lib/queues/AbstractQueueService';
|
|
4
|
+
export { objectToBuffer } from './lib/utils/queueUtils';
|
|
5
|
+
export { waitAndRetry } from './lib/utils/waitUtils';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitAndRetry = exports.objectToBuffer = exports.AbstractQueueService = void 0;
|
|
4
|
+
var AbstractQueueService_1 = require("./lib/queues/AbstractQueueService");
|
|
5
|
+
Object.defineProperty(exports, "AbstractQueueService", { enumerable: true, get: function () { return AbstractQueueService_1.AbstractQueueService; } });
|
|
6
|
+
var queueUtils_1 = require("./lib/utils/queueUtils");
|
|
7
|
+
Object.defineProperty(exports, "objectToBuffer", { enumerable: true, get: function () { return queueUtils_1.objectToBuffer; } });
|
|
8
|
+
var waitUtils_1 = require("./lib/utils/waitUtils");
|
|
9
|
+
Object.defineProperty(exports, "waitAndRetry", { enumerable: true, get: function () { return waitUtils_1.waitAndRetry; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAQA,0EAAwE;AAA/D,4HAAA,oBAAoB,OAAA;AAO7B,qDAAuD;AAA9C,4GAAA,cAAc,OAAA;AACvB,mDAAoD;AAA3C,yGAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ErrorReporter, ErrorResolver } from '@lokalise/node-core';
|
|
2
|
+
import type { ZodSchema } from 'zod';
|
|
3
|
+
import type { Logger, TransactionObservabilityManager } from '../types/MessageQueueTypes';
|
|
4
|
+
export type QueueDependencies = {
|
|
5
|
+
errorReporter: ErrorReporter;
|
|
6
|
+
logger: Logger;
|
|
7
|
+
};
|
|
8
|
+
export type QueueConsumerDependencies = {
|
|
9
|
+
consumerErrorResolver: ErrorResolver;
|
|
10
|
+
transactionObservabilityManager: TransactionObservabilityManager;
|
|
11
|
+
};
|
|
12
|
+
export type QueueOptions<MessagePayloadType extends object, QueueConfiguration extends object> = {
|
|
13
|
+
messageSchema: ZodSchema<MessagePayloadType>;
|
|
14
|
+
messageTypeField: string;
|
|
15
|
+
queueName: string;
|
|
16
|
+
queueConfiguration: QueueConfiguration;
|
|
17
|
+
};
|
|
18
|
+
export declare abstract class AbstractQueueService<MessagePayloadType extends object, DependenciesType extends QueueDependencies, QueueConfiguration extends object, OptionsType extends QueueOptions<MessagePayloadType, QueueConfiguration> = QueueOptions<MessagePayloadType, QueueConfiguration>> {
|
|
19
|
+
protected readonly queueName: string;
|
|
20
|
+
protected readonly errorReporter: ErrorReporter;
|
|
21
|
+
protected readonly messageSchema: ZodSchema<MessagePayloadType>;
|
|
22
|
+
protected readonly logger: Logger;
|
|
23
|
+
protected readonly messageTypeField: string;
|
|
24
|
+
protected readonly queueConfiguration: QueueConfiguration;
|
|
25
|
+
constructor({ errorReporter, logger }: DependenciesType, { messageSchema, messageTypeField, queueName, queueConfiguration }: OptionsType);
|
|
26
|
+
protected handleError(err: unknown): void;
|
|
27
|
+
abstract close(): Promise<unknown>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractQueueService = void 0;
|
|
4
|
+
const node_util_1 = require("node:util");
|
|
5
|
+
const node_core_1 = require("@lokalise/node-core");
|
|
6
|
+
class AbstractQueueService {
|
|
7
|
+
queueName;
|
|
8
|
+
errorReporter;
|
|
9
|
+
messageSchema;
|
|
10
|
+
logger;
|
|
11
|
+
messageTypeField;
|
|
12
|
+
queueConfiguration;
|
|
13
|
+
constructor({ errorReporter, logger }, { messageSchema, messageTypeField, queueName, queueConfiguration }) {
|
|
14
|
+
this.errorReporter = errorReporter;
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.queueName = queueName;
|
|
17
|
+
this.messageSchema = messageSchema;
|
|
18
|
+
this.messageTypeField = messageTypeField;
|
|
19
|
+
this.queueConfiguration = queueConfiguration;
|
|
20
|
+
}
|
|
21
|
+
handleError(err) {
|
|
22
|
+
const logObject = (0, node_core_1.resolveGlobalErrorLogObject)(err);
|
|
23
|
+
this.logger.error(logObject);
|
|
24
|
+
if (node_util_1.types.isNativeError(err)) {
|
|
25
|
+
this.errorReporter.report({ error: err });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.AbstractQueueService = AbstractQueueService;
|
|
30
|
+
//# sourceMappingURL=AbstractQueueService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractQueueService.js","sourceRoot":"","sources":["../../../lib/queues/AbstractQueueService.ts"],"names":[],"mappings":";;;AAAA,yCAAiC;AAGjC,mDAAiE;AAsBjE,MAAsB,oBAAoB;IASrB,SAAS,CAAQ;IACjB,aAAa,CAAe;IAC5B,aAAa,CAA+B;IAC5C,MAAM,CAAQ;IACd,gBAAgB,CAAQ;IACxB,kBAAkB,CAAoB;IAEzD,YACE,EAAE,aAAa,EAAE,MAAM,EAAoB,EAC3C,EAAE,aAAa,EAAE,gBAAgB,EAAE,SAAS,EAAE,kBAAkB,EAAe;QAE/E,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAA;IAC9C,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;AAtCD,oDAsCC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface QueueConsumer {
|
|
2
|
+
start(): Promise<unknown>;
|
|
3
|
+
close(): Promise<unknown>;
|
|
4
|
+
}
|
|
5
|
+
export interface SyncPublisher<MessagePayloadType> {
|
|
6
|
+
publish(message: MessagePayloadType): void;
|
|
7
|
+
}
|
|
8
|
+
export interface AsyncPublisher<MessagePayloadType, MessageOptions> {
|
|
9
|
+
publish(message: MessagePayloadType, options: MessageOptions): Promise<unknown>;
|
|
10
|
+
}
|
|
11
|
+
export type TransactionObservabilityManager = {
|
|
12
|
+
start: (transactionSpanId: string) => unknown;
|
|
13
|
+
stop: (transactionSpanId: string) => unknown;
|
|
14
|
+
};
|
|
15
|
+
export type LogFn = {
|
|
16
|
+
<T extends object>(obj: T, msg?: string, ...args: any[]): void;
|
|
17
|
+
(obj: unknown, msg?: string, ...args: any[]): void;
|
|
18
|
+
(msg: string, ...args: any[]): void;
|
|
19
|
+
};
|
|
20
|
+
export type Logger = {
|
|
21
|
+
error: LogFn;
|
|
22
|
+
info: LogFn;
|
|
23
|
+
warn: LogFn;
|
|
24
|
+
debug: LogFn;
|
|
25
|
+
trace: LogFn;
|
|
26
|
+
fatal: LogFn;
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageQueueTypes.js","sourceRoot":"","sources":["../../../lib/types/MessageQueueTypes.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectToBuffer = void 0;
|
|
4
|
+
const objectToBuffer = (object) => {
|
|
5
|
+
return Buffer.from(JSON.stringify(object));
|
|
6
|
+
};
|
|
7
|
+
exports.objectToBuffer = objectToBuffer;
|
|
8
|
+
//# sourceMappingURL=queueUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queueUtils.js","sourceRoot":"","sources":["../../../lib/utils/queueUtils.ts"],"names":[],"mappings":";;;AAAO,MAAM,cAAc,GAAG,CAAmB,MAAS,EAAU,EAAE;IACpE,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;AAC5C,CAAC,CAAA;AAFY,QAAA,cAAc,kBAE1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const waitAndRetry: <T>(predicateFn: () => T, sleepTime?: number, maxRetryCount?: number) => Promise<T>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitAndRetry = void 0;
|
|
4
|
+
const waitAndRetry = async (predicateFn, sleepTime = 100, maxRetryCount = 0) => {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
let retryCount = 0;
|
|
7
|
+
function performCheck() {
|
|
8
|
+
if (maxRetryCount !== 0 && retryCount > maxRetryCount) {
|
|
9
|
+
resolve(predicateFn());
|
|
10
|
+
}
|
|
11
|
+
Promise.resolve()
|
|
12
|
+
.then(() => {
|
|
13
|
+
return predicateFn();
|
|
14
|
+
})
|
|
15
|
+
.then((result) => {
|
|
16
|
+
if (result) {
|
|
17
|
+
resolve(result);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
retryCount++;
|
|
21
|
+
setTimeout(performCheck, sleepTime);
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
.catch((err) => {
|
|
25
|
+
reject(err);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
performCheck();
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
exports.waitAndRetry = waitAndRetry;
|
|
32
|
+
//# sourceMappingURL=waitUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waitUtils.js","sourceRoot":"","sources":["../../../lib/utils/waitUtils.ts"],"names":[],"mappings":";;;AAAO,MAAM,YAAY,GAAG,KAAK,EAC/B,WAAoB,EACpB,SAAS,GAAG,GAAG,EACf,aAAa,GAAG,CAAC,EACL,EAAE;IACd,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,UAAU,GAAG,CAAC,CAAA;QAClB,SAAS,YAAY;YACnB,IAAI,aAAa,KAAK,CAAC,IAAI,UAAU,GAAG,aAAa,EAAE;gBACrD,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;aACvB;YACD,OAAO,CAAC,OAAO,EAAE;iBACd,IAAI,CAAC,GAAG,EAAE;gBACT,OAAO,WAAW,EAAE,CAAA;YACtB,CAAC,CAAC;iBACD,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBACf,IAAI,MAAM,EAAE;oBACV,OAAO,CAAC,MAAM,CAAC,CAAA;iBAChB;qBAAM;oBACL,UAAU,EAAE,CAAA;oBACZ,UAAU,CAAC,YAAY,EAAE,SAAS,CAAC,CAAA;iBACpC;YACH,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACb,MAAM,CAAC,GAAG,CAAC,CAAA;YACb,CAAC,CAAC,CAAA;QACN,CAAC;QAED,YAAY,EAAE,CAAA;IAChB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AA9BY,QAAA,YAAY,gBA8BxB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@message-queue-toolkit/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "Useful utilities, interfaces and base classes for message queue handling. Supports AMQP and SQS with a common abstraction on top currently",
|
|
7
|
+
"maintainers": [
|
|
8
|
+
{
|
|
9
|
+
"name": "Igor Savin",
|
|
10
|
+
"email": "kibertoad@gmail.com"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"build:release": "del-cli dist && del-cli coverage && npm run lint && tsc --project tsconfig.release.json",
|
|
18
|
+
"lint": "eslint . --ext .ts",
|
|
19
|
+
"lint:fix": "eslint . --ext .ts --fix",
|
|
20
|
+
"test:coverage": "",
|
|
21
|
+
"docker:start:dev": "",
|
|
22
|
+
"docker:stop:dev": "",
|
|
23
|
+
"format": "prettier --write .",
|
|
24
|
+
"prepublishOnly": "npm run build:release"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^20.3.1",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^5.60.0",
|
|
30
|
+
"@typescript-eslint/parser": "^5.60.0",
|
|
31
|
+
"del-cli": "^5.0.0",
|
|
32
|
+
"eslint": "^8.43.0",
|
|
33
|
+
"eslint-config-prettier": "^8.8.0",
|
|
34
|
+
"eslint-plugin-import": "^2.27.5",
|
|
35
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
36
|
+
"prettier": "^2.8.8",
|
|
37
|
+
"typescript": "^5.1.3"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/kibertoad/message-queue-toolkit",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git://github.com/kibertoad/message-queue-toolkit.git"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"message",
|
|
46
|
+
"queue",
|
|
47
|
+
"queues",
|
|
48
|
+
"abstract",
|
|
49
|
+
"common",
|
|
50
|
+
"utils",
|
|
51
|
+
"sqs",
|
|
52
|
+
"amqp",
|
|
53
|
+
"rabbitmq",
|
|
54
|
+
"rabbit"
|
|
55
|
+
],
|
|
56
|
+
"files": [
|
|
57
|
+
"README.md",
|
|
58
|
+
"LICENSE",
|
|
59
|
+
"dist/*"
|
|
60
|
+
]
|
|
61
|
+
}
|