wsp-ms-core 1.0.93 → 1.0.95

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.mts CHANGED
@@ -636,7 +636,7 @@ declare class DefaultMysqlOutboxRunner {
636
636
  private logErrors;
637
637
  private sleep;
638
638
  private processOutboxRecord;
639
- private process;
639
+ private processRecords;
640
640
  start(): Promise<void>;
641
641
  }
642
642
 
@@ -647,7 +647,33 @@ declare class DefaultMysqlInboxRunner {
647
647
  constructor(databaseConnector: DatabaseConnector, eventManager: EventManager);
648
648
  private saveEvent;
649
649
  subscribeTo(topic: string): void;
650
- private process;
650
+ private processEvents;
651
+ start(): Promise<void>;
652
+ }
653
+
654
+ interface InboxRepository {
655
+ create(event: InboxRecord): Promise<void>;
656
+ update(event: InboxRecord): Promise<void>;
657
+ listPending(limit: number): Promise<InboxRecord[]>;
658
+ }
659
+
660
+ declare class InboxMysqlRepository implements InboxRepository {
661
+ private readonly connection;
662
+ constructor(connection: DatabaseConnection);
663
+ private recordToRowValues;
664
+ create(record: InboxRecord): Promise<void>;
665
+ update(record: InboxRecord): Promise<void>;
666
+ listPending(limit: number): Promise<InboxRecord[]>;
667
+ }
668
+
669
+ type InboxHandlerProcessor = (record: InboxRecord) => void;
670
+ declare class DefaultMysqlInboxProcessor {
671
+ private repository;
672
+ private handlers;
673
+ constructor(repository: InboxMysqlRepository);
674
+ private sleep;
675
+ addHandlerForTopic(topic: string, handler: InboxHandlerProcessor): void;
676
+ processRecords(): Promise<void>;
651
677
  start(): Promise<void>;
652
678
  }
653
679
 
@@ -675,4 +701,4 @@ declare class StringVars {
675
701
  }): string;
676
702
  }
677
703
 
678
- 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 };
704
+ export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultMysqlInboxProcessor, 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
@@ -636,7 +636,7 @@ declare class DefaultMysqlOutboxRunner {
636
636
  private logErrors;
637
637
  private sleep;
638
638
  private processOutboxRecord;
639
- private process;
639
+ private processRecords;
640
640
  start(): Promise<void>;
641
641
  }
642
642
 
@@ -647,7 +647,33 @@ declare class DefaultMysqlInboxRunner {
647
647
  constructor(databaseConnector: DatabaseConnector, eventManager: EventManager);
648
648
  private saveEvent;
649
649
  subscribeTo(topic: string): void;
650
- private process;
650
+ private processEvents;
651
+ start(): Promise<void>;
652
+ }
653
+
654
+ interface InboxRepository {
655
+ create(event: InboxRecord): Promise<void>;
656
+ update(event: InboxRecord): Promise<void>;
657
+ listPending(limit: number): Promise<InboxRecord[]>;
658
+ }
659
+
660
+ declare class InboxMysqlRepository implements InboxRepository {
661
+ private readonly connection;
662
+ constructor(connection: DatabaseConnection);
663
+ private recordToRowValues;
664
+ create(record: InboxRecord): Promise<void>;
665
+ update(record: InboxRecord): Promise<void>;
666
+ listPending(limit: number): Promise<InboxRecord[]>;
667
+ }
668
+
669
+ type InboxHandlerProcessor = (record: InboxRecord) => void;
670
+ declare class DefaultMysqlInboxProcessor {
671
+ private repository;
672
+ private handlers;
673
+ constructor(repository: InboxMysqlRepository);
674
+ private sleep;
675
+ addHandlerForTopic(topic: string, handler: InboxHandlerProcessor): void;
676
+ processRecords(): Promise<void>;
651
677
  start(): Promise<void>;
652
678
  }
653
679
 
@@ -675,4 +701,4 @@ declare class StringVars {
675
701
  }): string;
676
702
  }
677
703
 
678
- 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 };
704
+ export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultMysqlInboxProcessor, 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
@@ -1582,7 +1582,7 @@ var KafkaManager = class extends EventManager {
1582
1582
  await this.execCallback(this._onMessage, `[New message detected for ${topic}]: ${message.value?.toString()}`);
1583
1583
  const json = JSON.parse(String(message.value?.toString()));
1584
1584
  await this.execRoute(topic, {
1585
- topic: String(json.topic),
1585
+ topic: String(topic),
1586
1586
  producer: String(json.producer),
1587
1587
  tenant: UUID.create(String(json.tenant)),
1588
1588
  message: json.data
@@ -1737,7 +1737,7 @@ var DefaultMysqlOutboxRunner = class {
1737
1737
  }
1738
1738
  }
1739
1739
  async sleep() {
1740
- return new Promise((r) => setTimeout(r, this.maxEvents));
1740
+ return new Promise((r) => setTimeout(r, this.interval));
1741
1741
  }
1742
1742
  async processOutboxRecord(e, eventBusRepository) {
1743
1743
  try {
@@ -1758,7 +1758,7 @@ var DefaultMysqlOutboxRunner = class {
1758
1758
  await eventBusRepository.update(e);
1759
1759
  }
1760
1760
  }
1761
- async process() {
1761
+ async processRecords() {
1762
1762
  const uow = await this.uowFactory.create();
1763
1763
  const eventBusRepository = new EventBusMysqlRepository(uow.connection);
1764
1764
  await uow.execute(async () => {
@@ -1776,7 +1776,7 @@ var DefaultMysqlOutboxRunner = class {
1776
1776
  async start() {
1777
1777
  console.log("[outbox-runner]: start");
1778
1778
  for (; ; ) {
1779
- await this.process();
1779
+ await this.processRecords();
1780
1780
  await this.sleep();
1781
1781
  }
1782
1782
  }
@@ -1841,7 +1841,6 @@ var DefaultMysqlInboxRunner = class {
1841
1841
  this.eventManager = eventManager;
1842
1842
  }
1843
1843
  async saveEvent(e, repository) {
1844
- console.log(e);
1845
1844
  try {
1846
1845
  let record = new InboxRecord(
1847
1846
  UUID.create(),
@@ -1853,24 +1852,23 @@ var DefaultMysqlInboxRunner = class {
1853
1852
  );
1854
1853
  await repository.create(record);
1855
1854
  } catch (error) {
1856
- console.log(error);
1857
1855
  throw error;
1858
1856
  }
1859
1857
  }
1860
1858
  subscribeTo(topic) {
1861
1859
  this.topics.push(topic);
1862
1860
  }
1863
- async process() {
1861
+ async processEvents() {
1862
+ this.eventManager.onSubscribe((data) => {
1863
+ console.log(data);
1864
+ });
1865
+ this.eventManager.onMessage((data) => {
1866
+ });
1867
+ this.eventManager.onError((data) => {
1868
+ console.log(data);
1869
+ });
1864
1870
  for (let topic of this.topics) {
1865
1871
  try {
1866
- this.eventManager.onSubscribe((data) => {
1867
- console.log(data);
1868
- });
1869
- this.eventManager.onMessage((data) => {
1870
- });
1871
- this.eventManager.onError((data) => {
1872
- console.log(data);
1873
- });
1874
1872
  this.eventManager.route(topic, async (e) => {
1875
1873
  await this.saveEvent(e, new InboxMysqlRepository(await this.databaseConnector.getConnection()));
1876
1874
  });
@@ -1882,7 +1880,35 @@ var DefaultMysqlInboxRunner = class {
1882
1880
  }
1883
1881
  async start() {
1884
1882
  console.log("[inbox-runner]: start");
1885
- await this.process();
1883
+ await this.processEvents();
1884
+ }
1885
+ };
1886
+
1887
+ // src/infrastructure/runners/default-mysql-inbox-processor.ts
1888
+ var DefaultMysqlInboxProcessor = class {
1889
+ constructor(repository) {
1890
+ this.repository = repository;
1891
+ }
1892
+ async sleep() {
1893
+ return new Promise((r) => setTimeout(r, 5e3));
1894
+ }
1895
+ addHandlerForTopic(topic, handler) {
1896
+ this.handlers.set(topic, handler);
1897
+ }
1898
+ async processRecords() {
1899
+ const records = await this.repository.listPending(20);
1900
+ for (let record of records) {
1901
+ if (this.handlers.has(record.topic)) {
1902
+ await this.handlers.get(record.topic)(record);
1903
+ }
1904
+ }
1905
+ }
1906
+ async start() {
1907
+ console.log("[inbox-runner-processor]: start");
1908
+ for (; ; ) {
1909
+ await this.processRecords();
1910
+ await this.sleep();
1911
+ }
1886
1912
  }
1887
1913
  };
1888
1914
 
@@ -1945,6 +1971,7 @@ export {
1945
1971
  Country,
1946
1972
  Currency,
1947
1973
  DateTime,
1974
+ DefaultMysqlInboxProcessor,
1948
1975
  DefaultMysqlInboxRunner,
1949
1976
  DefaultMysqlOutboxRunner,
1950
1977
  DomainEntity,