wsp-ms-core 1.0.82 → 1.0.84
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.cjs +171 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +57 -9
- package/dist/index.d.ts +57 -9
- package/dist/index.js +169 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -355,7 +355,7 @@ declare class OutboxRecord {
|
|
|
355
355
|
private _publishedAt;
|
|
356
356
|
private _lastAttempt;
|
|
357
357
|
private readonly _createdAt;
|
|
358
|
-
|
|
358
|
+
constructor(eventUuid: UUID, eventType: string, tenantUuid: UUID, aggregateUuid: UUID, aggregateType: string, topic: string, payload: string, status: ProcessStatus, attempts: number, errorMessage: string | undefined, publishedAt: DateTime | undefined, lastAttempt: DateTime | undefined, createdAt?: DateTime);
|
|
359
359
|
get eventUuid(): UUID;
|
|
360
360
|
get tenantUuid(): UUID;
|
|
361
361
|
get aggregateUuid(): UUID;
|
|
@@ -434,12 +434,18 @@ declare class BasicUnitOfWorkFactory {
|
|
|
434
434
|
create(): Promise<BasicUnitOfWork>;
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
+
interface EventMessage {
|
|
438
|
+
topic: string;
|
|
439
|
+
producer: string;
|
|
440
|
+
tenant: UUID;
|
|
441
|
+
message: Record<string, any>;
|
|
442
|
+
}
|
|
437
443
|
interface EventManagerConnection {
|
|
438
444
|
userName: string;
|
|
439
445
|
password: string;
|
|
440
446
|
brokers: string[];
|
|
441
447
|
}
|
|
442
|
-
type RouteCallback = (
|
|
448
|
+
type RouteCallback = (e: EventMessage) => void;
|
|
443
449
|
interface RoutesCallbackList {
|
|
444
450
|
[key: string]: RouteCallback;
|
|
445
451
|
}
|
|
@@ -455,9 +461,9 @@ declare abstract class EventManager {
|
|
|
455
461
|
protected _onCrash: CallableFunction | null;
|
|
456
462
|
protected _onReconnect: CallableFunction | null;
|
|
457
463
|
protected constructor(connection: EventManagerConnection);
|
|
458
|
-
protected execRoute(topic: string,
|
|
464
|
+
protected execRoute(topic: string, event: EventMessage): Promise<void>;
|
|
459
465
|
protected execCallback(callback: CallableFunction | null, data: any): Promise<void>;
|
|
460
|
-
abstract send(
|
|
466
|
+
abstract send(event: EventMessage): void;
|
|
461
467
|
abstract start(): void;
|
|
462
468
|
abstract restart(): void;
|
|
463
469
|
abstract stop(): void;
|
|
@@ -507,6 +513,38 @@ interface Logger {
|
|
|
507
513
|
fatal(type: string, message: string, meta?: Record<string, any>): void;
|
|
508
514
|
}
|
|
509
515
|
|
|
516
|
+
declare class InboxRecord {
|
|
517
|
+
private readonly _eventUuid;
|
|
518
|
+
private readonly _tenantUuid;
|
|
519
|
+
private readonly _topic;
|
|
520
|
+
private readonly _producer;
|
|
521
|
+
private readonly _payload;
|
|
522
|
+
private _status;
|
|
523
|
+
private _attempts;
|
|
524
|
+
private _errorMessage;
|
|
525
|
+
private _lastAttempt;
|
|
526
|
+
private _processedAt;
|
|
527
|
+
private readonly _createdAt;
|
|
528
|
+
constructor(eventUuid: UUID, tenantUuid: UUID, topic: string, producer: string, payload: string, status: ProcessStatus, attempts?: number, errorMessage?: string | undefined, lastAttempt?: DateTime | undefined, processedAt?: DateTime | undefined, createdAt?: DateTime);
|
|
529
|
+
get eventUuid(): UUID;
|
|
530
|
+
get tenantUuid(): UUID;
|
|
531
|
+
get topic(): string;
|
|
532
|
+
get producer(): string;
|
|
533
|
+
get payload(): string;
|
|
534
|
+
get status(): ProcessStatus;
|
|
535
|
+
get attempts(): number;
|
|
536
|
+
get errorMessage(): string | undefined;
|
|
537
|
+
get lastAttempt(): DateTime | undefined;
|
|
538
|
+
get processedAt(): DateTime | undefined;
|
|
539
|
+
get createdAt(): DateTime;
|
|
540
|
+
incrementAttempts(): void;
|
|
541
|
+
markProcessed(): void;
|
|
542
|
+
markProcessing(): void;
|
|
543
|
+
markWithError(error: string): void;
|
|
544
|
+
toPrimitives(): Record<string, unknown>;
|
|
545
|
+
static reconstitute(data: Record<string, any>): InboxRecord;
|
|
546
|
+
}
|
|
547
|
+
|
|
510
548
|
interface ErrorTemplate {
|
|
511
549
|
type: string;
|
|
512
550
|
languages: Record<string, string>;
|
|
@@ -537,9 +575,9 @@ declare class ErrorManager {
|
|
|
537
575
|
declare class EventBusMysqlRepository implements EventBusRepository {
|
|
538
576
|
private readonly connection;
|
|
539
577
|
constructor(connection: DatabaseConnection);
|
|
540
|
-
private
|
|
541
|
-
create(
|
|
542
|
-
update(
|
|
578
|
+
private recordToRowValues;
|
|
579
|
+
create(record: OutboxRecord): Promise<void>;
|
|
580
|
+
update(record: OutboxRecord): Promise<void>;
|
|
543
581
|
listPending(limit: number): Promise<OutboxRecord[]>;
|
|
544
582
|
}
|
|
545
583
|
|
|
@@ -559,7 +597,7 @@ declare class KafkaManager extends EventManager {
|
|
|
559
597
|
private readonly producer;
|
|
560
598
|
constructor(connection: EventManagerConnection);
|
|
561
599
|
private run;
|
|
562
|
-
send(
|
|
600
|
+
send(e: EventMessage): Promise<void>;
|
|
563
601
|
start(autocommit?: boolean): Promise<void>;
|
|
564
602
|
pause(): Promise<void>;
|
|
565
603
|
restart(): Promise<void>;
|
|
@@ -602,6 +640,16 @@ declare class DefaultMysqlOutboxRunner {
|
|
|
602
640
|
start(): Promise<void>;
|
|
603
641
|
}
|
|
604
642
|
|
|
643
|
+
declare class DefaultMysqlInboxRunner {
|
|
644
|
+
private readonly uowFactory;
|
|
645
|
+
private readonly eventManager;
|
|
646
|
+
private readonly interval;
|
|
647
|
+
private readonly maxEvents;
|
|
648
|
+
private errors;
|
|
649
|
+
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
650
|
+
private saveEvent;
|
|
651
|
+
}
|
|
652
|
+
|
|
605
653
|
interface ExchangeRatesProps {
|
|
606
654
|
base: Currency;
|
|
607
655
|
rates: Record<string, number>;
|
|
@@ -626,4 +674,4 @@ declare class StringVars {
|
|
|
626
674
|
}): string;
|
|
627
675
|
}
|
|
628
676
|
|
|
629
|
-
export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultMysqlOutboxRunner, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, IntegrationEvent, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, OutboxRecord, PaymentGateway, PaymentStatus, Price, ProcessStatus, RouteCallback, RoutesCallbackList, StringVars, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
|
677
|
+
export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultMysqlInboxRunner, DefaultMysqlOutboxRunner, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, EventMessage, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, InboxRecord, IntegrationEvent, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, OutboxRecord, PaymentGateway, PaymentStatus, Price, ProcessStatus, RouteCallback, RoutesCallbackList, StringVars, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
package/dist/index.d.ts
CHANGED
|
@@ -355,7 +355,7 @@ declare class OutboxRecord {
|
|
|
355
355
|
private _publishedAt;
|
|
356
356
|
private _lastAttempt;
|
|
357
357
|
private readonly _createdAt;
|
|
358
|
-
|
|
358
|
+
constructor(eventUuid: UUID, eventType: string, tenantUuid: UUID, aggregateUuid: UUID, aggregateType: string, topic: string, payload: string, status: ProcessStatus, attempts: number, errorMessage: string | undefined, publishedAt: DateTime | undefined, lastAttempt: DateTime | undefined, createdAt?: DateTime);
|
|
359
359
|
get eventUuid(): UUID;
|
|
360
360
|
get tenantUuid(): UUID;
|
|
361
361
|
get aggregateUuid(): UUID;
|
|
@@ -434,12 +434,18 @@ declare class BasicUnitOfWorkFactory {
|
|
|
434
434
|
create(): Promise<BasicUnitOfWork>;
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
+
interface EventMessage {
|
|
438
|
+
topic: string;
|
|
439
|
+
producer: string;
|
|
440
|
+
tenant: UUID;
|
|
441
|
+
message: Record<string, any>;
|
|
442
|
+
}
|
|
437
443
|
interface EventManagerConnection {
|
|
438
444
|
userName: string;
|
|
439
445
|
password: string;
|
|
440
446
|
brokers: string[];
|
|
441
447
|
}
|
|
442
|
-
type RouteCallback = (
|
|
448
|
+
type RouteCallback = (e: EventMessage) => void;
|
|
443
449
|
interface RoutesCallbackList {
|
|
444
450
|
[key: string]: RouteCallback;
|
|
445
451
|
}
|
|
@@ -455,9 +461,9 @@ declare abstract class EventManager {
|
|
|
455
461
|
protected _onCrash: CallableFunction | null;
|
|
456
462
|
protected _onReconnect: CallableFunction | null;
|
|
457
463
|
protected constructor(connection: EventManagerConnection);
|
|
458
|
-
protected execRoute(topic: string,
|
|
464
|
+
protected execRoute(topic: string, event: EventMessage): Promise<void>;
|
|
459
465
|
protected execCallback(callback: CallableFunction | null, data: any): Promise<void>;
|
|
460
|
-
abstract send(
|
|
466
|
+
abstract send(event: EventMessage): void;
|
|
461
467
|
abstract start(): void;
|
|
462
468
|
abstract restart(): void;
|
|
463
469
|
abstract stop(): void;
|
|
@@ -507,6 +513,38 @@ interface Logger {
|
|
|
507
513
|
fatal(type: string, message: string, meta?: Record<string, any>): void;
|
|
508
514
|
}
|
|
509
515
|
|
|
516
|
+
declare class InboxRecord {
|
|
517
|
+
private readonly _eventUuid;
|
|
518
|
+
private readonly _tenantUuid;
|
|
519
|
+
private readonly _topic;
|
|
520
|
+
private readonly _producer;
|
|
521
|
+
private readonly _payload;
|
|
522
|
+
private _status;
|
|
523
|
+
private _attempts;
|
|
524
|
+
private _errorMessage;
|
|
525
|
+
private _lastAttempt;
|
|
526
|
+
private _processedAt;
|
|
527
|
+
private readonly _createdAt;
|
|
528
|
+
constructor(eventUuid: UUID, tenantUuid: UUID, topic: string, producer: string, payload: string, status: ProcessStatus, attempts?: number, errorMessage?: string | undefined, lastAttempt?: DateTime | undefined, processedAt?: DateTime | undefined, createdAt?: DateTime);
|
|
529
|
+
get eventUuid(): UUID;
|
|
530
|
+
get tenantUuid(): UUID;
|
|
531
|
+
get topic(): string;
|
|
532
|
+
get producer(): string;
|
|
533
|
+
get payload(): string;
|
|
534
|
+
get status(): ProcessStatus;
|
|
535
|
+
get attempts(): number;
|
|
536
|
+
get errorMessage(): string | undefined;
|
|
537
|
+
get lastAttempt(): DateTime | undefined;
|
|
538
|
+
get processedAt(): DateTime | undefined;
|
|
539
|
+
get createdAt(): DateTime;
|
|
540
|
+
incrementAttempts(): void;
|
|
541
|
+
markProcessed(): void;
|
|
542
|
+
markProcessing(): void;
|
|
543
|
+
markWithError(error: string): void;
|
|
544
|
+
toPrimitives(): Record<string, unknown>;
|
|
545
|
+
static reconstitute(data: Record<string, any>): InboxRecord;
|
|
546
|
+
}
|
|
547
|
+
|
|
510
548
|
interface ErrorTemplate {
|
|
511
549
|
type: string;
|
|
512
550
|
languages: Record<string, string>;
|
|
@@ -537,9 +575,9 @@ declare class ErrorManager {
|
|
|
537
575
|
declare class EventBusMysqlRepository implements EventBusRepository {
|
|
538
576
|
private readonly connection;
|
|
539
577
|
constructor(connection: DatabaseConnection);
|
|
540
|
-
private
|
|
541
|
-
create(
|
|
542
|
-
update(
|
|
578
|
+
private recordToRowValues;
|
|
579
|
+
create(record: OutboxRecord): Promise<void>;
|
|
580
|
+
update(record: OutboxRecord): Promise<void>;
|
|
543
581
|
listPending(limit: number): Promise<OutboxRecord[]>;
|
|
544
582
|
}
|
|
545
583
|
|
|
@@ -559,7 +597,7 @@ declare class KafkaManager extends EventManager {
|
|
|
559
597
|
private readonly producer;
|
|
560
598
|
constructor(connection: EventManagerConnection);
|
|
561
599
|
private run;
|
|
562
|
-
send(
|
|
600
|
+
send(e: EventMessage): Promise<void>;
|
|
563
601
|
start(autocommit?: boolean): Promise<void>;
|
|
564
602
|
pause(): Promise<void>;
|
|
565
603
|
restart(): Promise<void>;
|
|
@@ -602,6 +640,16 @@ declare class DefaultMysqlOutboxRunner {
|
|
|
602
640
|
start(): Promise<void>;
|
|
603
641
|
}
|
|
604
642
|
|
|
643
|
+
declare class DefaultMysqlInboxRunner {
|
|
644
|
+
private readonly uowFactory;
|
|
645
|
+
private readonly eventManager;
|
|
646
|
+
private readonly interval;
|
|
647
|
+
private readonly maxEvents;
|
|
648
|
+
private errors;
|
|
649
|
+
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
650
|
+
private saveEvent;
|
|
651
|
+
}
|
|
652
|
+
|
|
605
653
|
interface ExchangeRatesProps {
|
|
606
654
|
base: Currency;
|
|
607
655
|
rates: Record<string, number>;
|
|
@@ -626,4 +674,4 @@ declare class StringVars {
|
|
|
626
674
|
}): string;
|
|
627
675
|
}
|
|
628
676
|
|
|
629
|
-
export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultMysqlOutboxRunner, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, IntegrationEvent, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, OutboxRecord, PaymentGateway, PaymentStatus, Price, ProcessStatus, RouteCallback, RoutesCallbackList, StringVars, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
|
677
|
+
export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultMysqlInboxRunner, DefaultMysqlOutboxRunner, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, EventMessage, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, InboxRecord, IntegrationEvent, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, OutboxRecord, PaymentGateway, PaymentStatus, Price, ProcessStatus, RouteCallback, RoutesCallbackList, StringVars, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
package/dist/index.js
CHANGED
|
@@ -1090,9 +1090,9 @@ var EventManager = class {
|
|
|
1090
1090
|
this._onCrash = null;
|
|
1091
1091
|
this._onReconnect = null;
|
|
1092
1092
|
}
|
|
1093
|
-
async execRoute(topic,
|
|
1093
|
+
async execRoute(topic, event) {
|
|
1094
1094
|
if (this._callbackList[topic]) {
|
|
1095
|
-
await this._callbackList[topic](
|
|
1095
|
+
await this._callbackList[topic](event);
|
|
1096
1096
|
}
|
|
1097
1097
|
}
|
|
1098
1098
|
async execCallback(callback, data) {
|
|
@@ -1148,7 +1148,7 @@ var OutboxRecord = class _OutboxRecord {
|
|
|
1148
1148
|
this._errorMessage = errorMessage;
|
|
1149
1149
|
this._publishedAt = publishedAt;
|
|
1150
1150
|
this._lastAttempt = lastAttempt;
|
|
1151
|
-
this._createdAt = createdAt;
|
|
1151
|
+
this._createdAt = createdAt ?? DateTime.now();
|
|
1152
1152
|
}
|
|
1153
1153
|
get eventUuid() {
|
|
1154
1154
|
return this._eventUuid;
|
|
@@ -1241,30 +1241,126 @@ var OutboxRecord = class _OutboxRecord {
|
|
|
1241
1241
|
}
|
|
1242
1242
|
};
|
|
1243
1243
|
|
|
1244
|
+
// src/infrastructure/contracts/InboxRecord.ts
|
|
1245
|
+
var InboxRecord = class _InboxRecord {
|
|
1246
|
+
constructor(eventUuid, tenantUuid, topic, producer, payload, status, attempts, errorMessage, lastAttempt, processedAt, createdAt) {
|
|
1247
|
+
this._eventUuid = eventUuid;
|
|
1248
|
+
this._tenantUuid = tenantUuid;
|
|
1249
|
+
this._topic = topic;
|
|
1250
|
+
this._producer = producer;
|
|
1251
|
+
this._payload = payload;
|
|
1252
|
+
this._status = status;
|
|
1253
|
+
this._attempts = attempts ?? 0;
|
|
1254
|
+
this._errorMessage = errorMessage ?? void 0;
|
|
1255
|
+
this._lastAttempt = lastAttempt ?? void 0;
|
|
1256
|
+
this._processedAt = processedAt ?? void 0;
|
|
1257
|
+
this._createdAt = createdAt ?? DateTime.now();
|
|
1258
|
+
}
|
|
1259
|
+
get eventUuid() {
|
|
1260
|
+
return this._eventUuid;
|
|
1261
|
+
}
|
|
1262
|
+
get tenantUuid() {
|
|
1263
|
+
return this._tenantUuid;
|
|
1264
|
+
}
|
|
1265
|
+
get topic() {
|
|
1266
|
+
return this._topic;
|
|
1267
|
+
}
|
|
1268
|
+
get producer() {
|
|
1269
|
+
return this._producer;
|
|
1270
|
+
}
|
|
1271
|
+
get payload() {
|
|
1272
|
+
return this._payload;
|
|
1273
|
+
}
|
|
1274
|
+
get status() {
|
|
1275
|
+
return this._status;
|
|
1276
|
+
}
|
|
1277
|
+
get attempts() {
|
|
1278
|
+
return this._attempts;
|
|
1279
|
+
}
|
|
1280
|
+
get errorMessage() {
|
|
1281
|
+
return this._errorMessage;
|
|
1282
|
+
}
|
|
1283
|
+
get lastAttempt() {
|
|
1284
|
+
return this._lastAttempt;
|
|
1285
|
+
}
|
|
1286
|
+
get processedAt() {
|
|
1287
|
+
return this._processedAt;
|
|
1288
|
+
}
|
|
1289
|
+
get createdAt() {
|
|
1290
|
+
return this._createdAt;
|
|
1291
|
+
}
|
|
1292
|
+
incrementAttempts() {
|
|
1293
|
+
this._attempts++;
|
|
1294
|
+
this._lastAttempt = DateTime.now();
|
|
1295
|
+
}
|
|
1296
|
+
markProcessed() {
|
|
1297
|
+
this._status = ProcessStatus.PROCESSED;
|
|
1298
|
+
this._processedAt = DateTime.now();
|
|
1299
|
+
}
|
|
1300
|
+
markProcessing() {
|
|
1301
|
+
this.incrementAttempts();
|
|
1302
|
+
this._status = ProcessStatus.PROCESSING;
|
|
1303
|
+
}
|
|
1304
|
+
markWithError(error) {
|
|
1305
|
+
this._status = this.attempts < 5 ? ProcessStatus.FAILED : ProcessStatus.DEAD;
|
|
1306
|
+
this._errorMessage = error;
|
|
1307
|
+
}
|
|
1308
|
+
toPrimitives() {
|
|
1309
|
+
return {
|
|
1310
|
+
eventUuid: this.eventUuid.value,
|
|
1311
|
+
tenantUuid: this.tenantUuid.value,
|
|
1312
|
+
topic: this.topic,
|
|
1313
|
+
producer: this.producer,
|
|
1314
|
+
payload: this.payload,
|
|
1315
|
+
status: this.status.value,
|
|
1316
|
+
attempts: this.attempts,
|
|
1317
|
+
errorMessage: this.errorMessage ?? void 0,
|
|
1318
|
+
lastAttempt: this.lastAttempt?.value ?? void 0,
|
|
1319
|
+
processedAt: this.processedAt?.value ?? void 0,
|
|
1320
|
+
createdAt: this.createdAt.value
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
static reconstitute(data) {
|
|
1324
|
+
return new _InboxRecord(
|
|
1325
|
+
UUID.create(data.event_uuid),
|
|
1326
|
+
UUID.create(data.tenant_uuid),
|
|
1327
|
+
String(data.topic),
|
|
1328
|
+
String(data.producer),
|
|
1329
|
+
String(data.payload),
|
|
1330
|
+
ProcessStatus.create(data.status),
|
|
1331
|
+
Number(data.attempts),
|
|
1332
|
+
data.error_message ?? void 0,
|
|
1333
|
+
data.last_attempt ? DateTime.create(data.last_attempt) : void 0,
|
|
1334
|
+
data.processed_at ? DateTime.create(data.processed_at) : void 0,
|
|
1335
|
+
data.created_at ? DateTime.create(data.created_at) : void 0
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1339
|
+
|
|
1244
1340
|
// src/infrastructure/event-bus/EventBusMysqlRepository.ts
|
|
1245
1341
|
var EventBusMysqlRepository = class {
|
|
1246
1342
|
constructor(connection) {
|
|
1247
1343
|
this.connection = connection;
|
|
1248
1344
|
}
|
|
1249
|
-
|
|
1345
|
+
recordToRowValues(record) {
|
|
1250
1346
|
return [
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1347
|
+
record.eventUuid.value,
|
|
1348
|
+
record.eventType,
|
|
1349
|
+
record.tenantUuid.value,
|
|
1350
|
+
record.aggregateUuid.value,
|
|
1351
|
+
record.aggregateType,
|
|
1352
|
+
record.topic,
|
|
1353
|
+
record.payload,
|
|
1354
|
+
record.status.value,
|
|
1355
|
+
record.attempts,
|
|
1356
|
+
record.errorMessage,
|
|
1357
|
+
record.publishedAt?.value,
|
|
1358
|
+
record.lastAttempt?.value,
|
|
1359
|
+
record.createdAt.value
|
|
1264
1360
|
];
|
|
1265
1361
|
}
|
|
1266
|
-
async create(
|
|
1267
|
-
const values = this.
|
|
1362
|
+
async create(record) {
|
|
1363
|
+
const values = this.recordToRowValues(record);
|
|
1268
1364
|
await this.connection.query(
|
|
1269
1365
|
`INSERT INTO events_outbox (event_uuid, event_type, tenant_uuid, aggregate_uuid, aggregate_type, topic,
|
|
1270
1366
|
payload, status, attempts, error_message, published_at, last_attempt, created_at)
|
|
@@ -1272,8 +1368,8 @@ var EventBusMysqlRepository = class {
|
|
|
1272
1368
|
values
|
|
1273
1369
|
);
|
|
1274
1370
|
}
|
|
1275
|
-
async update(
|
|
1276
|
-
const values = [
|
|
1371
|
+
async update(record) {
|
|
1372
|
+
const values = [record.status.value, record.attempts, record.errorMessage, record.publishedAt?.value, record.lastAttempt?.value, record.eventUuid.value];
|
|
1277
1373
|
await this.connection.query(
|
|
1278
1374
|
`UPDATE events_outbox
|
|
1279
1375
|
SET status = ?,
|
|
@@ -1287,7 +1383,7 @@ var EventBusMysqlRepository = class {
|
|
|
1287
1383
|
}
|
|
1288
1384
|
async listPending(limit) {
|
|
1289
1385
|
const result = await this.connection.query(
|
|
1290
|
-
`SELECT * FROM events_outbox WHERE status IN ('PENDING','FAILED') AND published_at IS NULL LIMIT
|
|
1386
|
+
`SELECT * FROM events_outbox WHERE status IN ('PENDING','FAILED') AND published_at IS NULL LIMIT ${limit}`,
|
|
1291
1387
|
[]
|
|
1292
1388
|
);
|
|
1293
1389
|
return result.length > 0 ? result.map((r) => OutboxRecord.reconstitute(r)) : [];
|
|
@@ -1484,7 +1580,13 @@ var KafkaManager = class extends EventManager {
|
|
|
1484
1580
|
eachMessage: async ({ topic, partition, message, heartbeat }) => {
|
|
1485
1581
|
try {
|
|
1486
1582
|
await this.execCallback(this._onMessage, `[New message detected for ${topic}]: ${message.value?.toString()}`);
|
|
1487
|
-
|
|
1583
|
+
const json = JSON.parse(String(message.value?.toString()));
|
|
1584
|
+
await this.execRoute(topic, {
|
|
1585
|
+
topic: String(json.topic),
|
|
1586
|
+
producer: String(json.producer),
|
|
1587
|
+
tenant: UUID.create(String(json.tenant)),
|
|
1588
|
+
message: json.message
|
|
1589
|
+
});
|
|
1488
1590
|
const next = (BigInt(message.offset) + 1n).toString();
|
|
1489
1591
|
await this.consumer.commitOffsets([{ topic, partition, offset: next }]);
|
|
1490
1592
|
await heartbeat();
|
|
@@ -1500,11 +1602,12 @@ var KafkaManager = class extends EventManager {
|
|
|
1500
1602
|
await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.toString()));
|
|
1501
1603
|
}
|
|
1502
1604
|
}
|
|
1503
|
-
async send(
|
|
1605
|
+
async send(e) {
|
|
1504
1606
|
const evt = {
|
|
1505
1607
|
date: DateTime.now().value,
|
|
1506
|
-
|
|
1507
|
-
|
|
1608
|
+
tenant: e.tenant.value,
|
|
1609
|
+
producer: e.producer,
|
|
1610
|
+
data: e.message
|
|
1508
1611
|
};
|
|
1509
1612
|
try {
|
|
1510
1613
|
if (!this.producer) {
|
|
@@ -1512,7 +1615,7 @@ var KafkaManager = class extends EventManager {
|
|
|
1512
1615
|
}
|
|
1513
1616
|
await this.producer.connect();
|
|
1514
1617
|
await this.producer.send({
|
|
1515
|
-
topic,
|
|
1618
|
+
topic: e.topic,
|
|
1516
1619
|
messages: [{ value: JSON.stringify(evt) }]
|
|
1517
1620
|
});
|
|
1518
1621
|
await this.producer.disconnect();
|
|
@@ -1636,11 +1739,17 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1636
1739
|
async sleep() {
|
|
1637
1740
|
return new Promise((r) => setTimeout(r, this.maxEvents));
|
|
1638
1741
|
}
|
|
1742
|
+
// HACER QUE PUEDA MANDAR UN OBJETO NO UN STRING POR KAFKA
|
|
1639
1743
|
async processOutboxRecord(e, eventBusRepository) {
|
|
1640
1744
|
try {
|
|
1641
1745
|
e.markProcessing();
|
|
1642
1746
|
await eventBusRepository.update(e);
|
|
1643
|
-
await this.eventManager.send(
|
|
1747
|
+
await this.eventManager.send({
|
|
1748
|
+
topic: e.topic,
|
|
1749
|
+
producer: process.env.NAME && process.env.ENVIRONMENT ? `${process.env.NAME}-${process.env.ENVIRONMENT}` : "unknown",
|
|
1750
|
+
tenant: e.tenantUuid,
|
|
1751
|
+
message: JSON.parse(e.payload)
|
|
1752
|
+
});
|
|
1644
1753
|
e.markProcessed();
|
|
1645
1754
|
} catch (error) {
|
|
1646
1755
|
const type = String(error.type);
|
|
@@ -1674,6 +1783,36 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1674
1783
|
}
|
|
1675
1784
|
};
|
|
1676
1785
|
|
|
1786
|
+
// src/infrastructure/runners/default-mysql-inbox-runner.ts
|
|
1787
|
+
var DefaultMysqlInboxRunner = class {
|
|
1788
|
+
constructor(uowFactory, eventManager) {
|
|
1789
|
+
this.errors = [];
|
|
1790
|
+
this.uowFactory = uowFactory;
|
|
1791
|
+
this.eventManager = eventManager;
|
|
1792
|
+
this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
|
|
1793
|
+
this.maxEvents = Number(process.env.OUTBOX_RUNNER_MAX_EVENTS || 20);
|
|
1794
|
+
}
|
|
1795
|
+
async saveEvent(e, repository) {
|
|
1796
|
+
let record = new InboxRecord(
|
|
1797
|
+
UUID.create(),
|
|
1798
|
+
e.tenant,
|
|
1799
|
+
e.topic,
|
|
1800
|
+
e.producer,
|
|
1801
|
+
JSON.stringify(e.message),
|
|
1802
|
+
ProcessStatus.PENDING
|
|
1803
|
+
);
|
|
1804
|
+
try {
|
|
1805
|
+
await repository.create(record);
|
|
1806
|
+
} catch (error) {
|
|
1807
|
+
const type = String(error.type);
|
|
1808
|
+
record.markWithError(type);
|
|
1809
|
+
throw new Error(type);
|
|
1810
|
+
} finally {
|
|
1811
|
+
await repository.update(record);
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
|
|
1677
1816
|
// src/utils/ExchangeRates.ts
|
|
1678
1817
|
var ExchangeRates = class _ExchangeRates extends BaseObject {
|
|
1679
1818
|
constructor(props) {
|
|
@@ -1733,6 +1872,7 @@ export {
|
|
|
1733
1872
|
Country,
|
|
1734
1873
|
Currency,
|
|
1735
1874
|
DateTime,
|
|
1875
|
+
DefaultMysqlInboxRunner,
|
|
1736
1876
|
DefaultMysqlOutboxRunner,
|
|
1737
1877
|
DomainEntity,
|
|
1738
1878
|
DomainError,
|
|
@@ -1746,6 +1886,7 @@ export {
|
|
|
1746
1886
|
FatalError,
|
|
1747
1887
|
HttpHealthCheckController,
|
|
1748
1888
|
HttpNotFoundController,
|
|
1889
|
+
InboxRecord,
|
|
1749
1890
|
IntegrationEvent,
|
|
1750
1891
|
InternalError,
|
|
1751
1892
|
KafkaManager,
|