wsp-ms-core 1.0.82 → 1.0.83
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 +40 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +14 -8
- package/dist/index.d.ts +14 -8
- package/dist/index.js +40 -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
|
-
protected 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
|
|
358
|
+
protected 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: string;
|
|
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;
|
|
@@ -537,9 +543,9 @@ declare class ErrorManager {
|
|
|
537
543
|
declare class EventBusMysqlRepository implements EventBusRepository {
|
|
538
544
|
private readonly connection;
|
|
539
545
|
constructor(connection: DatabaseConnection);
|
|
540
|
-
private
|
|
541
|
-
create(
|
|
542
|
-
update(
|
|
546
|
+
private recordToRowValues;
|
|
547
|
+
create(record: OutboxRecord): Promise<void>;
|
|
548
|
+
update(record: OutboxRecord): Promise<void>;
|
|
543
549
|
listPending(limit: number): Promise<OutboxRecord[]>;
|
|
544
550
|
}
|
|
545
551
|
|
|
@@ -559,7 +565,7 @@ declare class KafkaManager extends EventManager {
|
|
|
559
565
|
private readonly producer;
|
|
560
566
|
constructor(connection: EventManagerConnection);
|
|
561
567
|
private run;
|
|
562
|
-
send(
|
|
568
|
+
send(e: EventMessage): Promise<void>;
|
|
563
569
|
start(autocommit?: boolean): Promise<void>;
|
|
564
570
|
pause(): Promise<void>;
|
|
565
571
|
restart(): Promise<void>;
|
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
|
-
protected 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
|
|
358
|
+
protected 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: string;
|
|
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;
|
|
@@ -537,9 +543,9 @@ declare class ErrorManager {
|
|
|
537
543
|
declare class EventBusMysqlRepository implements EventBusRepository {
|
|
538
544
|
private readonly connection;
|
|
539
545
|
constructor(connection: DatabaseConnection);
|
|
540
|
-
private
|
|
541
|
-
create(
|
|
542
|
-
update(
|
|
546
|
+
private recordToRowValues;
|
|
547
|
+
create(record: OutboxRecord): Promise<void>;
|
|
548
|
+
update(record: OutboxRecord): Promise<void>;
|
|
543
549
|
listPending(limit: number): Promise<OutboxRecord[]>;
|
|
544
550
|
}
|
|
545
551
|
|
|
@@ -559,7 +565,7 @@ declare class KafkaManager extends EventManager {
|
|
|
559
565
|
private readonly producer;
|
|
560
566
|
constructor(connection: EventManagerConnection);
|
|
561
567
|
private run;
|
|
562
|
-
send(
|
|
568
|
+
send(e: EventMessage): Promise<void>;
|
|
563
569
|
start(autocommit?: boolean): Promise<void>;
|
|
564
570
|
pause(): Promise<void>;
|
|
565
571
|
restart(): Promise<void>;
|
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;
|
|
@@ -1246,25 +1246,25 @@ var EventBusMysqlRepository = class {
|
|
|
1246
1246
|
constructor(connection) {
|
|
1247
1247
|
this.connection = connection;
|
|
1248
1248
|
}
|
|
1249
|
-
|
|
1249
|
+
recordToRowValues(record) {
|
|
1250
1250
|
return [
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1251
|
+
record.eventUuid.value,
|
|
1252
|
+
record.eventType,
|
|
1253
|
+
record.tenantUuid.value,
|
|
1254
|
+
record.aggregateUuid.value,
|
|
1255
|
+
record.aggregateType,
|
|
1256
|
+
record.topic,
|
|
1257
|
+
record.payload,
|
|
1258
|
+
record.status.value,
|
|
1259
|
+
record.attempts,
|
|
1260
|
+
record.errorMessage,
|
|
1261
|
+
record.publishedAt?.value,
|
|
1262
|
+
record.lastAttempt?.value,
|
|
1263
|
+
record.createdAt.value
|
|
1264
1264
|
];
|
|
1265
1265
|
}
|
|
1266
|
-
async create(
|
|
1267
|
-
const values = this.
|
|
1266
|
+
async create(record) {
|
|
1267
|
+
const values = this.recordToRowValues(record);
|
|
1268
1268
|
await this.connection.query(
|
|
1269
1269
|
`INSERT INTO events_outbox (event_uuid, event_type, tenant_uuid, aggregate_uuid, aggregate_type, topic,
|
|
1270
1270
|
payload, status, attempts, error_message, published_at, last_attempt, created_at)
|
|
@@ -1272,8 +1272,8 @@ var EventBusMysqlRepository = class {
|
|
|
1272
1272
|
values
|
|
1273
1273
|
);
|
|
1274
1274
|
}
|
|
1275
|
-
async update(
|
|
1276
|
-
const values = [
|
|
1275
|
+
async update(record) {
|
|
1276
|
+
const values = [record.status.value, record.attempts, record.errorMessage, record.publishedAt?.value, record.lastAttempt?.value, record.eventUuid.value];
|
|
1277
1277
|
await this.connection.query(
|
|
1278
1278
|
`UPDATE events_outbox
|
|
1279
1279
|
SET status = ?,
|
|
@@ -1287,7 +1287,7 @@ var EventBusMysqlRepository = class {
|
|
|
1287
1287
|
}
|
|
1288
1288
|
async listPending(limit) {
|
|
1289
1289
|
const result = await this.connection.query(
|
|
1290
|
-
`SELECT * FROM events_outbox WHERE status IN ('PENDING','FAILED') AND published_at IS NULL LIMIT
|
|
1290
|
+
`SELECT * FROM events_outbox WHERE status IN ('PENDING','FAILED') AND published_at IS NULL LIMIT ${limit}`,
|
|
1291
1291
|
[]
|
|
1292
1292
|
);
|
|
1293
1293
|
return result.length > 0 ? result.map((r) => OutboxRecord.reconstitute(r)) : [];
|
|
@@ -1484,7 +1484,13 @@ var KafkaManager = class extends EventManager {
|
|
|
1484
1484
|
eachMessage: async ({ topic, partition, message, heartbeat }) => {
|
|
1485
1485
|
try {
|
|
1486
1486
|
await this.execCallback(this._onMessage, `[New message detected for ${topic}]: ${message.value?.toString()}`);
|
|
1487
|
-
|
|
1487
|
+
const json = JSON.parse(String(message.value?.toString()));
|
|
1488
|
+
await this.execRoute(topic, {
|
|
1489
|
+
topic: String(json.topic),
|
|
1490
|
+
producer: String(json.producer),
|
|
1491
|
+
tenant: UUID.create(String(json.tenant)),
|
|
1492
|
+
message: String(json.message)
|
|
1493
|
+
});
|
|
1488
1494
|
const next = (BigInt(message.offset) + 1n).toString();
|
|
1489
1495
|
await this.consumer.commitOffsets([{ topic, partition, offset: next }]);
|
|
1490
1496
|
await heartbeat();
|
|
@@ -1500,11 +1506,12 @@ var KafkaManager = class extends EventManager {
|
|
|
1500
1506
|
await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.toString()));
|
|
1501
1507
|
}
|
|
1502
1508
|
}
|
|
1503
|
-
async send(
|
|
1509
|
+
async send(e) {
|
|
1504
1510
|
const evt = {
|
|
1505
1511
|
date: DateTime.now().value,
|
|
1506
|
-
|
|
1507
|
-
|
|
1512
|
+
tenant: e.tenant.value,
|
|
1513
|
+
producer: e.producer,
|
|
1514
|
+
data: e.message
|
|
1508
1515
|
};
|
|
1509
1516
|
try {
|
|
1510
1517
|
if (!this.producer) {
|
|
@@ -1512,7 +1519,7 @@ var KafkaManager = class extends EventManager {
|
|
|
1512
1519
|
}
|
|
1513
1520
|
await this.producer.connect();
|
|
1514
1521
|
await this.producer.send({
|
|
1515
|
-
topic,
|
|
1522
|
+
topic: e.topic,
|
|
1516
1523
|
messages: [{ value: JSON.stringify(evt) }]
|
|
1517
1524
|
});
|
|
1518
1525
|
await this.producer.disconnect();
|
|
@@ -1640,7 +1647,12 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1640
1647
|
try {
|
|
1641
1648
|
e.markProcessing();
|
|
1642
1649
|
await eventBusRepository.update(e);
|
|
1643
|
-
await this.eventManager.send(
|
|
1650
|
+
await this.eventManager.send({
|
|
1651
|
+
topic: e.topic,
|
|
1652
|
+
producer: process.env.NAME && process.env.ENVIRONMENT ? `${process.env.NAME}-${process.env.ENVIRONMENT}` : "unknown",
|
|
1653
|
+
tenant: e.tenantUuid,
|
|
1654
|
+
message: e.payload
|
|
1655
|
+
});
|
|
1644
1656
|
e.markProcessed();
|
|
1645
1657
|
} catch (error) {
|
|
1646
1658
|
const type = String(error.type);
|