@anatix/runtime 1.0.0 → 1.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/contracts/index.d.ts +2 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/{configs → contracts}/index.js +1 -2
- package/dist/contracts/index.js.map +1 -0
- package/dist/{configs/service-runtime.d.ts → contracts/service-options.d.ts} +7 -6
- package/dist/contracts/service-options.d.ts.map +1 -0
- package/dist/{configs/service-runtime.js → contracts/service-options.js} +1 -1
- package/dist/contracts/service-options.js.map +1 -0
- package/dist/envelope/envelope.config.d.ts +17 -0
- package/dist/envelope/envelope.config.d.ts.map +1 -0
- package/dist/envelope/envelope.config.js +5 -0
- package/dist/envelope/envelope.config.js.map +1 -0
- package/dist/envelope/index.d.ts +2 -0
- package/dist/envelope/index.d.ts.map +1 -1
- package/dist/envelope/index.js +2 -0
- package/dist/envelope/index.js.map +1 -1
- package/dist/envelope/services/inbox-retry.service.d.ts +3 -1
- package/dist/envelope/services/inbox-retry.service.d.ts.map +1 -1
- package/dist/envelope/services/inbox-retry.service.js +16 -7
- package/dist/envelope/services/inbox-retry.service.js.map +1 -1
- package/dist/envelope/services/index.d.ts +1 -0
- package/dist/envelope/services/index.d.ts.map +1 -1
- package/dist/envelope/services/index.js +1 -0
- package/dist/envelope/services/index.js.map +1 -1
- package/dist/envelope/services/outbox-dispatcher.service.d.ts +3 -2
- package/dist/envelope/services/outbox-dispatcher.service.d.ts.map +1 -1
- package/dist/envelope/services/outbox-dispatcher.service.js +41 -18
- package/dist/envelope/services/outbox-dispatcher.service.js.map +1 -1
- package/dist/envelope/tx-manager.d.ts +14 -0
- package/dist/envelope/tx-manager.d.ts.map +1 -0
- package/dist/envelope/tx-manager.js +20 -0
- package/dist/envelope/tx-manager.js.map +1 -0
- package/dist/event-bus/event-bus.config.d.ts +17 -0
- package/dist/event-bus/event-bus.config.d.ts.map +1 -0
- package/dist/event-bus/event-bus.config.js +17 -0
- package/dist/event-bus/event-bus.config.js.map +1 -0
- package/dist/event-bus/index.d.ts +1 -0
- package/dist/event-bus/index.d.ts.map +1 -1
- package/dist/event-bus/index.js +1 -0
- package/dist/event-bus/index.js.map +1 -1
- package/dist/event-bus/modules/event-bus.module.d.ts.map +1 -1
- package/dist/event-bus/modules/event-bus.module.js +9 -2
- package/dist/event-bus/modules/event-bus.module.js.map +1 -1
- package/dist/event-bus/services/event-bus.service.d.ts +4 -0
- package/dist/event-bus/services/event-bus.service.d.ts.map +1 -1
- package/dist/event-bus/services/event-bus.service.js +55 -16
- package/dist/event-bus/services/event-bus.service.js.map +1 -1
- package/dist/guards/base/index.d.ts +0 -1
- package/dist/guards/base/index.d.ts.map +1 -1
- package/dist/guards/base/index.js +0 -1
- package/dist/guards/base/index.js.map +1 -1
- package/dist/guards/base/jwt-auth.guard.d.ts +6 -1
- package/dist/guards/base/jwt-auth.guard.d.ts.map +1 -1
- package/dist/guards/base/jwt-auth.guard.js +32 -20
- package/dist/guards/base/jwt-auth.guard.js.map +1 -1
- package/dist/guards/base/permissions.guard.d.ts +1 -0
- package/dist/guards/base/permissions.guard.d.ts.map +1 -1
- package/dist/guards/base/permissions.guard.js +6 -2
- package/dist/guards/base/permissions.guard.js.map +1 -1
- package/dist/guards/types/base-roles.enum.d.ts +6 -0
- package/dist/guards/types/base-roles.enum.d.ts.map +1 -0
- package/dist/guards/types/base-roles.enum.js +10 -0
- package/dist/guards/types/base-roles.enum.js.map +1 -0
- package/dist/guards/types/index.d.ts +2 -0
- package/dist/guards/types/index.d.ts.map +1 -1
- package/dist/guards/types/index.js +2 -0
- package/dist/guards/types/index.js.map +1 -1
- package/dist/guards/types/tokens.constant.d.ts +5 -0
- package/dist/guards/types/tokens.constant.d.ts.map +1 -0
- package/dist/guards/types/tokens.constant.js +7 -0
- package/dist/guards/types/tokens.constant.js.map +1 -0
- package/dist/guards/utils/token.util.d.ts.map +1 -1
- package/dist/guards/utils/token.util.js +14 -9
- package/dist/guards/utils/token.util.js.map +1 -1
- package/dist/health/index.d.ts +2 -0
- package/dist/health/index.d.ts.map +1 -0
- package/dist/health/index.js +18 -0
- package/dist/health/index.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/repository/cursor.d.ts +6 -0
- package/dist/repository/cursor.d.ts.map +1 -0
- package/dist/repository/cursor.js +45 -0
- package/dist/repository/cursor.js.map +1 -0
- package/dist/repository/index.d.ts +2 -0
- package/dist/repository/index.d.ts.map +1 -0
- package/dist/repository/index.js +18 -0
- package/dist/repository/index.js.map +1 -0
- package/dist/security/bcrypt.adapter.d.ts +6 -0
- package/dist/security/bcrypt.adapter.d.ts.map +1 -0
- package/dist/security/bcrypt.adapter.js +48 -0
- package/dist/security/bcrypt.adapter.js.map +1 -0
- package/dist/security/index.d.ts +1 -0
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +1 -0
- package/dist/security/index.js.map +1 -1
- package/package.json +33 -17
- package/dist/configs/env-validation.d.ts +0 -2
- package/dist/configs/env-validation.d.ts.map +0 -1
- package/dist/configs/env-validation.js +0 -49
- package/dist/configs/env-validation.js.map +0 -1
- package/dist/configs/index.d.ts +0 -3
- package/dist/configs/index.d.ts.map +0 -1
- package/dist/configs/index.js.map +0 -1
- package/dist/configs/service-repo-configs.d.ts +0 -13
- package/dist/configs/service-repo-configs.d.ts.map +0 -1
- package/dist/configs/service-repo-configs.js +0 -3
- package/dist/configs/service-repo-configs.js.map +0 -1
- package/dist/configs/service-runtime.d.ts.map +0 -1
- package/dist/configs/service-runtime.js.map +0 -1
- package/dist/guards/base/roles.guard.d.ts +0 -10
- package/dist/guards/base/roles.guard.d.ts.map +0 -1
- package/dist/guards/base/roles.guard.js +0 -58
- package/dist/guards/base/roles.guard.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./service-
|
|
18
|
-
__exportStar(require("./service-runtime"), exports);
|
|
17
|
+
__exportStar(require("./service-options"), exports);
|
|
19
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
export type OrderDir = "ASC" | "DESC";
|
|
2
2
|
export interface ServiceListOptions {
|
|
3
3
|
limit?: number;
|
|
4
|
-
cursor?: string;
|
|
5
4
|
offset?: number;
|
|
5
|
+
cursor?: string;
|
|
6
6
|
orderBy?: string;
|
|
7
7
|
orderDir?: OrderDir;
|
|
8
|
-
include?: string | string[];
|
|
9
8
|
projection?: string | string[];
|
|
10
9
|
}
|
|
11
10
|
export interface ServiceQueryOptions extends ServiceListOptions {
|
|
12
11
|
search?: string;
|
|
13
12
|
}
|
|
13
|
+
export type RepoListOptions = ServiceListOptions;
|
|
14
|
+
export type RepoQueryOptions = ServiceQueryOptions;
|
|
14
15
|
export interface TxManager<R> {
|
|
15
|
-
transaction?<T>(fn: (
|
|
16
|
-
isolation?:
|
|
16
|
+
transaction?<T>(fn: (trxRepo: R) => Promise<T>, opts?: {
|
|
17
|
+
isolation?: string;
|
|
17
18
|
}): Promise<T>;
|
|
18
19
|
}
|
|
19
|
-
//# sourceMappingURL=service-
|
|
20
|
+
//# sourceMappingURL=service-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-options.d.ts","sourceRoot":"","sources":["../../src/contracts/service-options.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;AAEtC,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAGD,MAAM,MAAM,eAAe,GAAG,kBAAkB,CAAC;AACjD,MAAM,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;AAMnD,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,WAAW,CAAC,CAAC,CAAC,EACZ,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9B,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAC5B,OAAO,CAAC,CAAC,CAAC,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-options.js","sourceRoot":"","sources":["../../src/contracts/service-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface OutboxDispatchConfig {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
intervalMs?: number;
|
|
4
|
+
maxAttempts?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface InboxRetryConfig {
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
intervalMs?: number;
|
|
9
|
+
maxAttempts?: number;
|
|
10
|
+
stuckMinutes?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface EnvelopeConfig {
|
|
13
|
+
outbox?: OutboxDispatchConfig;
|
|
14
|
+
inboxRetry?: InboxRetryConfig;
|
|
15
|
+
}
|
|
16
|
+
export declare const ENVELOPE_CONFIG = "ENVELOPE_CONFIG";
|
|
17
|
+
//# sourceMappingURL=envelope.config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.config.d.ts","sourceRoot":"","sources":["../../src/envelope/envelope.config.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,oBAAoB;IAEnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAE/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAWD,eAAO,MAAM,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.config.js","sourceRoot":"","sources":["../../src/envelope/envelope.config.ts"],"names":[],"mappings":";;;AAoCa,QAAA,eAAe,GAAG,iBAAiB,CAAC"}
|
package/dist/envelope/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/envelope/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,cAAc,gBAAgB,CAAC;AAG/B,cAAc,YAAY,CAAC;AAG3B,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/envelope/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,cAAc,gBAAgB,CAAC;AAG/B,cAAc,YAAY,CAAC;AAG3B,cAAc,WAAW,CAAC;AAG1B,cAAc,mBAAmB,CAAC;AAGlC,cAAc,cAAc,CAAC"}
|
package/dist/envelope/index.js
CHANGED
|
@@ -18,4 +18,6 @@ __exportStar(require("./types"), exports);
|
|
|
18
18
|
__exportStar(require("./repositories"), exports);
|
|
19
19
|
__exportStar(require("./services"), exports);
|
|
20
20
|
__exportStar(require("./helpers"), exports);
|
|
21
|
+
__exportStar(require("./envelope.config"), exports);
|
|
22
|
+
__exportStar(require("./tx-manager"), exports);
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/envelope/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,0CAAwB;AAGxB,iDAA+B;AAG/B,6CAA2B;AAG3B,4CAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/envelope/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,0CAAwB;AAGxB,iDAA+B;AAG/B,6CAA2B;AAG3B,4CAA0B;AAG1B,oDAAkC;AAGlC,+CAA6B"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { OnModuleInit } from '@nestjs/common';
|
|
2
2
|
import { DataSource } from 'typeorm';
|
|
3
|
+
import { type EnvelopeConfig } from '../envelope.config';
|
|
3
4
|
export declare class InboxRetryService implements OnModuleInit {
|
|
4
5
|
private readonly dataSource;
|
|
5
6
|
private readonly retryHandler;
|
|
7
|
+
private readonly cfg;
|
|
6
8
|
private readonly logger;
|
|
7
9
|
private intervalId?;
|
|
8
|
-
constructor(dataSource: DataSource, retryHandler: (topic: string, payload: any, meta: any) => Promise<void
|
|
10
|
+
constructor(dataSource: DataSource, retryHandler: (topic: string, payload: any, meta: any) => Promise<void>, cfg: EnvelopeConfig);
|
|
9
11
|
onModuleInit(): Promise<void>;
|
|
10
12
|
stop(): void;
|
|
11
13
|
private retryMessages;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inbox-retry.service.d.ts","sourceRoot":"","sources":["../../../src/envelope/services/inbox-retry.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inbox-retry.service.d.ts","sourceRoot":"","sources":["../../../src/envelope/services/inbox-retry.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,YAAY,EAAU,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE1E,qBACa,iBAAkB,YAAW,YAAY;IAKlD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAK3B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAE7B,OAAO,CAAC,QAAQ,CAAC,GAAG;IAXtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAC7D,OAAO,CAAC,UAAU,CAAC,CAAiB;gBAGjB,UAAU,EAAE,UAAU,EAKtB,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,EAEvE,GAAG,EAAE,cAAc;IAGhC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBnC,IAAI,IAAI,IAAI;YAQE,aAAa;CA6C5B"}
|
|
@@ -8,28 +8,35 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
var InboxRetryService_1;
|
|
12
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
16
|
exports.InboxRetryService = void 0;
|
|
14
17
|
const common_1 = require("@nestjs/common");
|
|
15
18
|
const typeorm_1 = require("typeorm");
|
|
16
19
|
const repositories_1 = require("../repositories");
|
|
20
|
+
const envelope_config_1 = require("../envelope.config");
|
|
17
21
|
let InboxRetryService = InboxRetryService_1 = class InboxRetryService {
|
|
18
22
|
dataSource;
|
|
19
23
|
retryHandler;
|
|
24
|
+
cfg;
|
|
20
25
|
logger = new common_1.Logger(InboxRetryService_1.name);
|
|
21
26
|
intervalId;
|
|
22
|
-
constructor(dataSource, retryHandler) {
|
|
27
|
+
constructor(dataSource, retryHandler, cfg) {
|
|
23
28
|
this.dataSource = dataSource;
|
|
24
29
|
this.retryHandler = retryHandler;
|
|
30
|
+
this.cfg = cfg;
|
|
25
31
|
}
|
|
26
32
|
async onModuleInit() {
|
|
27
|
-
const
|
|
28
|
-
const enabled =
|
|
33
|
+
const inboxCfg = this.cfg?.inboxRetry ?? {};
|
|
34
|
+
const enabled = inboxCfg.enabled ?? true;
|
|
29
35
|
if (!enabled) {
|
|
30
|
-
this.logger.log('Inbox retry service disabled');
|
|
36
|
+
this.logger.log('Inbox retry service disabled by config');
|
|
31
37
|
return;
|
|
32
38
|
}
|
|
39
|
+
const intervalMs = inboxCfg.intervalMs ?? 60000;
|
|
33
40
|
this.intervalId = setInterval(() => {
|
|
34
41
|
this.retryMessages().catch((err) => {
|
|
35
42
|
this.logger.error(`Inbox retry error: ${err?.message || err}`);
|
|
@@ -45,8 +52,9 @@ let InboxRetryService = InboxRetryService_1 = class InboxRetryService {
|
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
async retryMessages() {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
55
|
+
const inboxCfg = this.cfg?.inboxRetry ?? {};
|
|
56
|
+
const maxAttempts = inboxCfg.maxAttempts ?? 3;
|
|
57
|
+
const stuckMinutes = inboxCfg.stuckMinutes ?? 5;
|
|
50
58
|
const failedMessages = await repositories_1.InboxRepo.getFailedMessages(this.dataSource, maxAttempts, 10);
|
|
51
59
|
for (const msg of failedMessages) {
|
|
52
60
|
this.logger.warn(`Retrying failed message: ${msg.messageId} (attempt ${msg.attempts + 1}/${maxAttempts})`);
|
|
@@ -76,6 +84,7 @@ let InboxRetryService = InboxRetryService_1 = class InboxRetryService {
|
|
|
76
84
|
exports.InboxRetryService = InboxRetryService;
|
|
77
85
|
exports.InboxRetryService = InboxRetryService = InboxRetryService_1 = __decorate([
|
|
78
86
|
(0, common_1.Injectable)(),
|
|
79
|
-
|
|
87
|
+
__param(2, (0, common_1.Inject)(envelope_config_1.ENVELOPE_CONFIG)),
|
|
88
|
+
__metadata("design:paramtypes", [typeorm_1.DataSource, Function, Object])
|
|
80
89
|
], InboxRetryService);
|
|
81
90
|
//# sourceMappingURL=inbox-retry.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inbox-retry.service.js","sourceRoot":"","sources":["../../../src/envelope/services/inbox-retry.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inbox-retry.service.js","sourceRoot":"","sources":["../../../src/envelope/services/inbox-retry.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,2CAA0E;AAC1E,qCAAqC;AACrC,kDAA4C;AAC5C,wDAA0E;AAGnE,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAKT;IAKA;IAEA;IAXF,MAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;IACrD,UAAU,CAAkB;IAEpC,YACmB,UAAsB,EAKtB,YAAuE,EAEvE,GAAmB;QAPnB,eAAU,GAAV,UAAU,CAAY;QAKtB,iBAAY,GAAZ,YAAY,CAA2D;QAEvE,QAAG,GAAH,GAAG,CAAgB;IACnC,CAAC;IAEJ,KAAK,CAAC,YAAY;QAChB,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BACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,kCAAkC,GAAG,CAAC,SAAS,KAAK,KAAK,EAAE,OAAO,IAAI,KAAK,EAAE,CAC9E,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAA;AAxFY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAYR,WAAA,IAAA,eAAM,EAAC,iCAAe,CAAC,CAAA;qCANK,oBAAU;GAL9B,iBAAiB,CAwF7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/envelope/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/envelope/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC"}
|
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./outbox-dispatcher.service"), exports);
|
|
18
|
+
__exportStar(require("./inbox-retry.service"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/envelope/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/envelope/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C;AAC5C,wDAAsC"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { OnModuleInit } from '@nestjs/common';
|
|
2
2
|
import { DataSource } from 'typeorm';
|
|
3
|
+
import { type EnvelopeConfig } from '../envelope.config';
|
|
3
4
|
export declare class OutboxDispatcherService implements OnModuleInit {
|
|
4
5
|
private readonly dataSource;
|
|
5
6
|
private readonly publishFn;
|
|
7
|
+
private readonly cfg;
|
|
6
8
|
private readonly logger;
|
|
7
9
|
private intervalId?;
|
|
8
|
-
constructor(dataSource: DataSource, publishFn: (topic: string, payload: any, meta: any) => Promise<void
|
|
10
|
+
constructor(dataSource: DataSource, publishFn: (topic: string, payload: any, meta: any) => Promise<void>, cfg: EnvelopeConfig);
|
|
9
11
|
onModuleInit(): Promise<void>;
|
|
10
12
|
stop(): void;
|
|
11
|
-
private updateLastAttemptAt;
|
|
12
13
|
private publishMessage;
|
|
13
14
|
private dispatch;
|
|
14
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbox-dispatcher.service.d.ts","sourceRoot":"","sources":["../../../src/envelope/services/outbox-dispatcher.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,YAAY,
|
|
1
|
+
{"version":3,"file":"outbox-dispatcher.service.d.ts","sourceRoot":"","sources":["../../../src/envelope/services/outbox-dispatcher.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,YAAY,EAAU,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAO1E,qBACa,uBAAwB,YAAW,YAAY;IAKxD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAK3B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAE1B,OAAO,CAAC,QAAQ,CAAC,GAAG;IAXtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4C;IACnE,OAAO,CAAC,UAAU,CAAC,CAAiB;gBAGjB,UAAU,EAAE,UAAU,EAKtB,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,EAEpE,GAAG,EAAE,cAAc;IAOhC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IA0BnC,IAAI,IAAI,IAAI;YAQE,cAAc;YAcd,QAAQ;CA6CvB"}
|
|
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
var OutboxDispatcherService_1;
|
|
12
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
16
|
exports.OutboxDispatcherService = void 0;
|
|
@@ -15,18 +18,27 @@ const common_1 = require("@nestjs/common");
|
|
|
15
18
|
const typeorm_1 = require("typeorm");
|
|
16
19
|
const repositories_1 = require("../repositories");
|
|
17
20
|
const schemas_1 = require("../schemas");
|
|
21
|
+
const envelope_config_1 = require("../envelope.config");
|
|
18
22
|
let OutboxDispatcherService = OutboxDispatcherService_1 = class OutboxDispatcherService {
|
|
19
23
|
dataSource;
|
|
20
24
|
publishFn;
|
|
25
|
+
cfg;
|
|
21
26
|
logger = new common_1.Logger(OutboxDispatcherService_1.name);
|
|
22
27
|
intervalId;
|
|
23
|
-
constructor(dataSource, publishFn) {
|
|
28
|
+
constructor(dataSource, publishFn, cfg) {
|
|
24
29
|
this.dataSource = dataSource;
|
|
25
30
|
this.publishFn = publishFn;
|
|
31
|
+
this.cfg = cfg;
|
|
26
32
|
}
|
|
27
33
|
async onModuleInit() {
|
|
28
|
-
const
|
|
29
|
-
const
|
|
34
|
+
const outboxCfg = this.cfg?.outbox ?? {};
|
|
35
|
+
const enabled = outboxCfg.enabled ?? true;
|
|
36
|
+
if (!enabled) {
|
|
37
|
+
this.logger.log('Outbox dispatcher disabled by config');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const intervalMs = outboxCfg.intervalMs ?? 5000;
|
|
41
|
+
const maxAttempts = outboxCfg.maxAttempts ?? 5;
|
|
30
42
|
this.intervalId = setInterval(() => {
|
|
31
43
|
this.dispatch(maxAttempts).catch((err) => {
|
|
32
44
|
this.logger.error(`Outbox dispatch error: ${err?.message || err}`);
|
|
@@ -41,12 +53,6 @@ let OutboxDispatcherService = OutboxDispatcherService_1 = class OutboxDispatcher
|
|
|
41
53
|
this.logger.log('Outbox dispatcher stopped');
|
|
42
54
|
}
|
|
43
55
|
}
|
|
44
|
-
async updateLastAttemptAt(messageId) {
|
|
45
|
-
const repo = this.dataSource.getRepository(schemas_1.OutboxSchema);
|
|
46
|
-
await repo.update(messageId, {
|
|
47
|
-
lastAttemptAt: new Date()
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
56
|
async publishMessage(message) {
|
|
51
57
|
try {
|
|
52
58
|
const payload = JSON.parse(message.payload);
|
|
@@ -60,20 +66,36 @@ let OutboxDispatcherService = OutboxDispatcherService_1 = class OutboxDispatcher
|
|
|
60
66
|
}
|
|
61
67
|
async dispatch(maxAttempts) {
|
|
62
68
|
const messages = await repositories_1.OutboxRepo.getPending(this.dataSource, maxAttempts);
|
|
63
|
-
if (messages.length === 0) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
this.logger.debug(`Dispatching ${messages.length} outbox messages`);
|
|
67
69
|
for (const message of messages) {
|
|
70
|
+
const queryRunner = this.dataSource.createQueryRunner();
|
|
71
|
+
await queryRunner.connect();
|
|
72
|
+
await queryRunner.startTransaction();
|
|
68
73
|
try {
|
|
69
|
-
await
|
|
74
|
+
await queryRunner.manager
|
|
75
|
+
.createQueryBuilder()
|
|
76
|
+
.select()
|
|
77
|
+
.from(schemas_1.OutboxSchema, 'outbox')
|
|
78
|
+
.where('id = :id', { id: message.id })
|
|
79
|
+
.setLock('pessimistic_write')
|
|
80
|
+
.getRawOne();
|
|
81
|
+
await queryRunner.manager
|
|
82
|
+
.getRepository(schemas_1.OutboxSchema)
|
|
83
|
+
.update(message.id, { lastAttemptAt: new Date() });
|
|
70
84
|
await this.publishMessage(message);
|
|
71
|
-
await
|
|
72
|
-
|
|
85
|
+
await queryRunner.manager.getRepository(schemas_1.OutboxSchema).update(message.id, {
|
|
86
|
+
status: 'published',
|
|
87
|
+
publishedAt: new Date(),
|
|
88
|
+
});
|
|
89
|
+
await queryRunner.commitTransaction();
|
|
90
|
+
this.logger.debug(`Published message ${message.id}`);
|
|
73
91
|
}
|
|
74
92
|
catch (error) {
|
|
75
|
-
|
|
93
|
+
await queryRunner.rollbackTransaction();
|
|
76
94
|
await repositories_1.OutboxRepo.markFailed(this.dataSource, message.id, error?.message || String(error));
|
|
95
|
+
this.logger.error(`Failed to publish ${message.id}: ${error?.message || error}`);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
await queryRunner.release();
|
|
77
99
|
}
|
|
78
100
|
}
|
|
79
101
|
}
|
|
@@ -81,6 +103,7 @@ let OutboxDispatcherService = OutboxDispatcherService_1 = class OutboxDispatcher
|
|
|
81
103
|
exports.OutboxDispatcherService = OutboxDispatcherService;
|
|
82
104
|
exports.OutboxDispatcherService = OutboxDispatcherService = OutboxDispatcherService_1 = __decorate([
|
|
83
105
|
(0, common_1.Injectable)(),
|
|
84
|
-
|
|
106
|
+
__param(2, (0, common_1.Inject)(envelope_config_1.ENVELOPE_CONFIG)),
|
|
107
|
+
__metadata("design:paramtypes", [typeorm_1.DataSource, Function, Object])
|
|
85
108
|
], OutboxDispatcherService);
|
|
86
109
|
//# sourceMappingURL=outbox-dispatcher.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbox-dispatcher.service.js","sourceRoot":"","sources":["../../../src/envelope/services/outbox-dispatcher.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"outbox-dispatcher.service.js","sourceRoot":"","sources":["../../../src/envelope/services/outbox-dispatcher.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AC,CAAA;qCANK,oBAAU;GAL9B,uBAAuB,CAgHnC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DataSource, EntityManager } from "typeorm";
|
|
2
|
+
import type { TxManager } from "../contracts";
|
|
3
|
+
export interface WithManager<R> {
|
|
4
|
+
withManager(manager: EntityManager): R;
|
|
5
|
+
}
|
|
6
|
+
export declare class TypeormTxManager<R extends WithManager<R>> implements TxManager<R> {
|
|
7
|
+
private readonly dataSource;
|
|
8
|
+
private readonly repo;
|
|
9
|
+
constructor(dataSource: DataSource, repo: R);
|
|
10
|
+
transaction<T>(fn: (trxRepo: R) => Promise<T>, opts?: {
|
|
11
|
+
isolation?: string;
|
|
12
|
+
}): Promise<T>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=tx-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx-manager.d.ts","sourceRoot":"","sources":["../../src/envelope/tx-manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAS9C,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,CAAC,CAAC;CACxC;AAaD,qBAAa,gBAAgB,CAAC,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,CACpD,YAAW,SAAS,CAAC,CAAC,CAAC;IAGrB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI;gBADJ,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,CAAC;IAGpB,WAAW,CAAC,CAAC,EACjB,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9B,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAC5B,OAAO,CAAC,CAAC,CAAC;CAYd"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeormTxManager = void 0;
|
|
4
|
+
class TypeormTxManager {
|
|
5
|
+
dataSource;
|
|
6
|
+
repo;
|
|
7
|
+
constructor(dataSource, repo) {
|
|
8
|
+
this.dataSource = dataSource;
|
|
9
|
+
this.repo = repo;
|
|
10
|
+
}
|
|
11
|
+
async transaction(fn, opts) {
|
|
12
|
+
const iso = opts?.isolation;
|
|
13
|
+
return this.dataSource.transaction(iso ? { isolation: iso } : undefined, async (manager) => {
|
|
14
|
+
const trxRepo = this.repo.withManager(manager);
|
|
15
|
+
return fn(trxRepo);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.TypeormTxManager = TypeormTxManager;
|
|
20
|
+
//# sourceMappingURL=tx-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx-manager.js","sourceRoot":"","sources":["../../src/envelope/tx-manager.ts"],"names":[],"mappings":";;;AA2BA,MAAa,gBAAgB;IAIR;IACA;IAFnB,YACmB,UAAsB,EACtB,IAAO;QADP,eAAU,GAAV,UAAU,CAAY;QACtB,SAAI,GAAJ,IAAI,CAAG;IACvB,CAAC;IAEJ,KAAK,CAAC,WAAW,CACf,EAA8B,EAC9B,IAA6B;QAE7B,MAAM,GAAG,GAAG,IAAI,EAAE,SAAS,CAAC;QAE5B,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAEhC,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAU,EAAE,CAAC,CAAC,CAAC,SAAS,EAC3C,KAAK,EAAE,OAAO,EAAE,EAAE;YAChB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAC/C,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC;QACrB,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAvBD,4CAuBC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface EventBusConnectionConfig {
|
|
2
|
+
url?: string;
|
|
3
|
+
exchange?: string;
|
|
4
|
+
queue?: string;
|
|
5
|
+
prefetch?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface EventBusCircuitBreakerConfig {
|
|
8
|
+
maxFailures?: number;
|
|
9
|
+
resetTimeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface EventBusConfig {
|
|
12
|
+
connection?: EventBusConnectionConfig;
|
|
13
|
+
circuitBreaker?: EventBusCircuitBreakerConfig;
|
|
14
|
+
}
|
|
15
|
+
export declare const EVENT_BUS_CONFIG = "EVENT_BUS_CONFIG";
|
|
16
|
+
export declare const defaultEventBusConfig: EventBusConfig;
|
|
17
|
+
//# sourceMappingURL=event-bus.config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus.config.d.ts","sourceRoot":"","sources":["../../src/event-bus/event-bus.config.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,wBAAwB;IAEvC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,4BAA4B;IAE3C,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAE7B,UAAU,CAAC,EAAE,wBAAwB,CAAC;IAGtC,cAAc,CAAC,EAAE,4BAA4B,CAAC;CAC/C;AAWD,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAKnD,eAAO,MAAM,qBAAqB,EAAE,cAWnC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultEventBusConfig = exports.EVENT_BUS_CONFIG = void 0;
|
|
4
|
+
exports.EVENT_BUS_CONFIG = 'EVENT_BUS_CONFIG';
|
|
5
|
+
exports.defaultEventBusConfig = {
|
|
6
|
+
connection: {
|
|
7
|
+
url: 'amqp://localhost',
|
|
8
|
+
exchange: 'anatix-event-bus',
|
|
9
|
+
queue: 'default-queue',
|
|
10
|
+
prefetch: 1,
|
|
11
|
+
},
|
|
12
|
+
circuitBreaker: {
|
|
13
|
+
maxFailures: 5,
|
|
14
|
+
resetTimeoutMs: 60_000,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=event-bus.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-bus.config.js","sourceRoot":"","sources":["../../src/event-bus/event-bus.config.ts"],"names":[],"mappings":";;;AAqCa,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAKtC,QAAA,qBAAqB,GAAmB;IACnD,UAAU,EAAE;QACV,GAAG,EAAE,kBAAkB;QACvB,QAAQ,EAAE,kBAAkB;QAC5B,KAAK,EAAE,eAAe;QACtB,QAAQ,EAAE,CAAC;KACZ;IACD,cAAc,EAAE;QACd,WAAW,EAAE,CAAC;QACd,cAAc,EAAE,MAAM;KACvB;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/event-bus/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/event-bus/index.ts"],"names":[],"mappings":"AAGA,cAAc,SAAS,CAAC;AAGxB,cAAc,YAAY,CAAC;AAG3B,cAAc,WAAW,CAAC;AAG1B,cAAc,oBAAoB,CAAC"}
|
package/dist/event-bus/index.js
CHANGED
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
18
|
__exportStar(require("./services"), exports);
|
|
19
19
|
__exportStar(require("./modules"), exports);
|
|
20
|
+
__exportStar(require("./event-bus.config"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/event-bus/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/event-bus/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGA,0CAAwB;AAGxB,6CAA2B;AAG3B,4CAA0B;AAG1B,qDAAmC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.module.d.ts","sourceRoot":"","sources":["../../../src/event-bus/modules/event-bus.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-bus.module.d.ts","sourceRoot":"","sources":["../../../src/event-bus/modules/event-bus.module.ts"],"names":[],"mappings":"AAwBA,qBAUa,cAAc;CAAG"}
|
|
@@ -9,13 +9,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.EventBusModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const services_1 = require("../services");
|
|
12
|
+
const event_bus_config_1 = require("../event-bus.config");
|
|
12
13
|
let EventBusModule = class EventBusModule {
|
|
13
14
|
};
|
|
14
15
|
exports.EventBusModule = EventBusModule;
|
|
15
16
|
exports.EventBusModule = EventBusModule = __decorate([
|
|
16
17
|
(0, common_1.Module)({
|
|
17
|
-
providers: [
|
|
18
|
-
|
|
18
|
+
providers: [
|
|
19
|
+
services_1.EventBusService,
|
|
20
|
+
{
|
|
21
|
+
provide: event_bus_config_1.EVENT_BUS_CONFIG,
|
|
22
|
+
useValue: event_bus_config_1.defaultEventBusConfig,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
exports: [services_1.EventBusService, event_bus_config_1.EVENT_BUS_CONFIG],
|
|
19
26
|
})
|
|
20
27
|
], EventBusModule);
|
|
21
28
|
//# sourceMappingURL=event-bus.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.module.js","sourceRoot":"","sources":["../../../src/event-bus/modules/event-bus.module.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"event-bus.module.js","sourceRoot":"","sources":["../../../src/event-bus/modules/event-bus.module.ts"],"names":[],"mappings":";;;;;;;;;AACA,2CAAwC;AACxC,0CAA8C;AAC9C,0DAG6B;AA4BtB,IAAM,cAAc,GAApB,MAAM,cAAc;CAAG,CAAA;AAAjB,wCAAc;yBAAd,cAAc;IAV1B,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,0BAAe;YACf;gBACE,OAAO,EAAE,mCAAgB;gBACzB,QAAQ,EAAE,wCAAqB;aAChC;SACF;QACD,OAAO,EAAE,CAAC,0BAAe,EAAE,mCAAgB,CAAC;KAC7C,CAAC;GACW,cAAc,CAAG"}
|
|
@@ -3,12 +3,16 @@ import { DataSource } from 'typeorm';
|
|
|
3
3
|
import { type Envelope, type EventMeta } from '../../envelope';
|
|
4
4
|
import { LogLevel } from '../../logger';
|
|
5
5
|
import type { EnvelopeHandler, TxHandler, TxAfterHook, ReplyTransformer } from '../types';
|
|
6
|
+
import { type EventBusConfig } from '../event-bus.config';
|
|
6
7
|
export declare class EventBusService implements OnModuleInit, OnModuleDestroy {
|
|
7
8
|
private readonly logger;
|
|
8
9
|
private connection?;
|
|
9
10
|
private channel?;
|
|
10
11
|
private subscriptions;
|
|
12
|
+
private readonly cfg;
|
|
13
|
+
private connectionParams;
|
|
11
14
|
private circuitBreaker;
|
|
15
|
+
constructor(cfg: EventBusConfig);
|
|
12
16
|
onModuleInit(): Promise<void>;
|
|
13
17
|
onModuleDestroy(): Promise<void>;
|
|
14
18
|
private assertReady;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.service.d.ts","sourceRoot":"","sources":["../../../src/event-bus/services/event-bus.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-bus.service.d.ts","sourceRoot":"","sources":["../../../src/event-bus/services/event-bus.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,eAAe,EACf,YAAY,EAEb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,SAAS,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAqB,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAEV,eAAe,EACf,SAAS,EACT,WAAW,EACX,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,qBAAqB,CAAC;AAe7B,qBACa,eAAgB,YAAW,YAAY,EAAE,eAAe;IACnE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAE3D,OAAO,CAAC,UAAU,CAAC,CAAe;IAClC,OAAO,CAAC,OAAO,CAAC,CAAU;IAG1B,OAAO,CAAC,aAAa,CAAwC;IAG7D,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAiB;IAGrC,OAAO,CAAC,gBAAgB,CAKtB;IAEF,OAAO,CAAC,cAAc,CAKpB;gBAIA,GAAG,EAAE,cAAc;IAkBf,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAO7B,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBtC,OAAO,CAAC,WAAW;IAiBb,OAAO,CAAC,CAAC,EACb,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,CAAC,EACP,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GACxB,OAAO,CAAC,IAAI,CAAC;IA4BV,OAAO,CAAC,CAAC,EAAE,CAAC,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,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