node-cqrs 1.0.0 → 1.1.0-alpha.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/CHANGELOG.md +30 -1
- package/README.md +115 -101
- package/dist/cjs/AbstractProjection.js +43 -18
- package/dist/cjs/AbstractProjection.js.map +1 -1
- package/dist/cjs/AggregateCommandHandler.js +27 -13
- package/dist/cjs/AggregateCommandHandler.js.map +1 -1
- package/dist/cjs/CqrsContainerBuilder.js +6 -1
- package/dist/cjs/CqrsContainerBuilder.js.map +1 -1
- package/dist/cjs/EventDispatchPipeline.js +12 -2
- package/dist/cjs/EventDispatchPipeline.js.map +1 -1
- package/dist/cjs/EventDispatcher.js +39 -10
- package/dist/cjs/EventDispatcher.js.map +1 -1
- package/dist/cjs/EventStore.js +7 -2
- package/dist/cjs/EventStore.js.map +1 -1
- package/dist/cjs/SagaEventHandler.js +54 -40
- package/dist/cjs/SagaEventHandler.js.map +1 -1
- package/dist/cjs/in-memory/InMemoryEventStorage.js +39 -24
- package/dist/cjs/in-memory/InMemoryEventStorage.js.map +1 -1
- package/dist/cjs/in-memory/InMemoryMessageBus.js +11 -5
- package/dist/cjs/in-memory/InMemoryMessageBus.js.map +1 -1
- package/dist/cjs/interfaces/IDispatchPipelineProcessor.js.map +1 -1
- package/dist/cjs/interfaces/IMessageMeta.js +3 -0
- package/dist/cjs/interfaces/IMessageMeta.js.map +1 -0
- package/dist/cjs/interfaces/IObservable.js.map +1 -1
- package/dist/cjs/interfaces/index.js +1 -0
- package/dist/cjs/interfaces/index.js.map +1 -1
- package/dist/cjs/mongodb/AbstractMongoAccessor.js +51 -0
- package/dist/cjs/mongodb/AbstractMongoAccessor.js.map +1 -0
- package/dist/cjs/mongodb/AbstractMongoObjectProjection.js +26 -0
- package/dist/cjs/mongodb/AbstractMongoObjectProjection.js.map +1 -0
- package/dist/cjs/mongodb/AbstractMongoView.js +57 -0
- package/dist/cjs/mongodb/AbstractMongoView.js.map +1 -0
- package/dist/cjs/mongodb/IContainer.js +3 -0
- package/dist/cjs/mongodb/IContainer.js.map +1 -0
- package/dist/cjs/mongodb/MongoEventLocker.js +104 -0
- package/dist/cjs/mongodb/MongoEventLocker.js.map +1 -0
- package/dist/cjs/mongodb/MongoEventStorage.js +200 -0
- package/dist/cjs/mongodb/MongoEventStorage.js.map +1 -0
- package/dist/cjs/mongodb/MongoObjectStorage.js +101 -0
- package/dist/cjs/mongodb/MongoObjectStorage.js.map +1 -0
- package/dist/cjs/mongodb/MongoObjectView.js +41 -0
- package/dist/cjs/mongodb/MongoObjectView.js.map +1 -0
- package/dist/cjs/mongodb/MongoProjectionDataParams.js +3 -0
- package/dist/cjs/mongodb/MongoProjectionDataParams.js.map +1 -0
- package/dist/cjs/mongodb/MongoViewLocker.js +136 -0
- package/dist/cjs/mongodb/MongoViewLocker.js.map +1 -0
- package/dist/cjs/mongodb/index.js +28 -0
- package/dist/cjs/mongodb/index.js.map +1 -0
- package/dist/cjs/mongodb/registerExitCleanup.js +28 -0
- package/dist/cjs/mongodb/registerExitCleanup.js.map +1 -0
- package/dist/cjs/mongodb/utils/getEventId.js +14 -0
- package/dist/cjs/mongodb/utils/getEventId.js.map +1 -0
- package/dist/cjs/mongodb/utils/index.js +18 -0
- package/dist/cjs/mongodb/utils/index.js.map +1 -0
- package/dist/cjs/rabbitmq/RabbitMqCommandBus.js +21 -8
- package/dist/cjs/rabbitmq/RabbitMqCommandBus.js.map +1 -1
- package/dist/cjs/rabbitmq/RabbitMqEventBus.js +2 -2
- package/dist/cjs/rabbitmq/RabbitMqEventBus.js.map +1 -1
- package/dist/cjs/rabbitmq/RabbitMqGateway.js +89 -64
- package/dist/cjs/rabbitmq/RabbitMqGateway.js.map +1 -1
- package/dist/cjs/redis/AbstractRedisAccessor.js +51 -0
- package/dist/cjs/redis/AbstractRedisAccessor.js.map +1 -0
- package/dist/cjs/redis/AbstractRedisProjection.js +26 -0
- package/dist/cjs/redis/AbstractRedisProjection.js.map +1 -0
- package/dist/cjs/redis/IContainer.js +3 -0
- package/dist/cjs/redis/IContainer.js.map +1 -0
- package/dist/cjs/redis/RedisEventLocker.js +96 -0
- package/dist/cjs/redis/RedisEventLocker.js.map +1 -0
- package/dist/cjs/redis/RedisObjectStorage.js +125 -0
- package/dist/cjs/redis/RedisObjectStorage.js.map +1 -0
- package/dist/cjs/redis/RedisProjectionDataParams.js +3 -0
- package/dist/cjs/redis/RedisProjectionDataParams.js.map +1 -0
- package/dist/cjs/redis/RedisView.js +81 -0
- package/dist/cjs/redis/RedisView.js.map +1 -0
- package/dist/cjs/redis/RedisViewLocker.js +111 -0
- package/dist/cjs/redis/RedisViewLocker.js.map +1 -0
- package/dist/cjs/redis/index.js +30 -0
- package/dist/cjs/redis/index.js.map +1 -0
- package/dist/cjs/redis/utils/getEventId.js +14 -0
- package/dist/cjs/redis/utils/getEventId.js.map +1 -0
- package/dist/cjs/redis/utils/index.js +18 -0
- package/dist/cjs/redis/utils/index.js.map +1 -0
- package/dist/cjs/sqlite/AbstractSqliteView.js.map +1 -1
- package/dist/cjs/sqlite/SqliteEventStorage.js +215 -0
- package/dist/cjs/sqlite/SqliteEventStorage.js.map +1 -0
- package/dist/cjs/sqlite/SqliteObjectStorage.js +6 -6
- package/dist/cjs/sqlite/SqliteObjectStorage.js.map +1 -1
- package/dist/cjs/sqlite/SqliteObjectView.js.map +1 -1
- package/dist/cjs/sqlite/index.js +1 -0
- package/dist/cjs/sqlite/index.js.map +1 -1
- package/dist/cjs/sqlite/utils/bufferToGuid.js +9 -0
- package/dist/cjs/sqlite/utils/bufferToGuid.js.map +1 -0
- package/dist/cjs/sqlite/utils/getEventId.js +2 -5
- package/dist/cjs/sqlite/utils/getEventId.js.map +1 -1
- package/dist/cjs/sqlite/utils/guid.js +1 -1
- package/dist/cjs/sqlite/utils/guid.js.map +1 -1
- package/dist/cjs/sqlite/utils/index.js +1 -0
- package/dist/cjs/sqlite/utils/index.js.map +1 -1
- package/dist/cjs/telemetry/index.js +20 -0
- package/dist/cjs/telemetry/index.js.map +1 -0
- package/dist/cjs/telemetry/recordSpanError.js +19 -0
- package/dist/cjs/telemetry/recordSpanError.js.map +1 -0
- package/dist/cjs/telemetry/spanAttributes.js +26 -0
- package/dist/cjs/telemetry/spanAttributes.js.map +1 -0
- package/dist/cjs/telemetry/spanContext.js +25 -0
- package/dist/cjs/telemetry/spanContext.js.map +1 -0
- package/dist/cjs/utils/MapAssertable.js +25 -1
- package/dist/cjs/utils/MapAssertable.js.map +1 -1
- package/dist/esm/AbstractProjection.js +32 -7
- package/dist/esm/AbstractProjection.js.map +1 -1
- package/dist/esm/AggregateCommandHandler.js +22 -8
- package/dist/esm/AggregateCommandHandler.js.map +1 -1
- package/dist/esm/CqrsContainerBuilder.js +6 -1
- package/dist/esm/CqrsContainerBuilder.js.map +1 -1
- package/dist/esm/EventDispatchPipeline.js +12 -2
- package/dist/esm/EventDispatchPipeline.js.map +1 -1
- package/dist/esm/EventDispatcher.js +33 -4
- package/dist/esm/EventDispatcher.js.map +1 -1
- package/dist/esm/EventStore.js +7 -2
- package/dist/esm/EventStore.js.map +1 -1
- package/dist/esm/SagaEventHandler.js +42 -28
- package/dist/esm/SagaEventHandler.js.map +1 -1
- package/dist/esm/in-memory/InMemoryEventStorage.js +25 -10
- package/dist/esm/in-memory/InMemoryEventStorage.js.map +1 -1
- package/dist/esm/in-memory/InMemoryMessageBus.js +11 -5
- package/dist/esm/in-memory/InMemoryMessageBus.js.map +1 -1
- package/dist/esm/interfaces/IDispatchPipelineProcessor.js.map +1 -1
- package/dist/esm/interfaces/IMessageMeta.js +2 -0
- package/dist/esm/interfaces/IMessageMeta.js.map +1 -0
- package/dist/esm/interfaces/IObservable.js.map +1 -1
- package/dist/esm/interfaces/index.js +1 -0
- package/dist/esm/interfaces/index.js.map +1 -1
- package/dist/esm/mongodb/AbstractMongoAccessor.js +47 -0
- package/dist/esm/mongodb/AbstractMongoAccessor.js.map +1 -0
- package/dist/esm/mongodb/AbstractMongoObjectProjection.js +22 -0
- package/dist/esm/mongodb/AbstractMongoObjectProjection.js.map +1 -0
- package/dist/esm/mongodb/AbstractMongoView.js +53 -0
- package/dist/esm/mongodb/AbstractMongoView.js.map +1 -0
- package/dist/esm/mongodb/IContainer.js +2 -0
- package/dist/esm/mongodb/IContainer.js.map +1 -0
- package/dist/esm/mongodb/MongoEventLocker.js +100 -0
- package/dist/esm/mongodb/MongoEventLocker.js.map +1 -0
- package/dist/esm/mongodb/MongoEventStorage.js +196 -0
- package/dist/esm/mongodb/MongoEventStorage.js.map +1 -0
- package/dist/esm/mongodb/MongoObjectStorage.js +97 -0
- package/dist/esm/mongodb/MongoObjectStorage.js.map +1 -0
- package/dist/esm/mongodb/MongoObjectView.js +37 -0
- package/dist/esm/mongodb/MongoObjectView.js.map +1 -0
- package/dist/esm/mongodb/MongoProjectionDataParams.js +2 -0
- package/dist/esm/mongodb/MongoProjectionDataParams.js.map +1 -0
- package/dist/esm/mongodb/MongoViewLocker.js +132 -0
- package/dist/esm/mongodb/MongoViewLocker.js.map +1 -0
- package/dist/esm/mongodb/index.js +12 -0
- package/dist/esm/mongodb/index.js.map +1 -0
- package/dist/esm/mongodb/registerExitCleanup.js +24 -0
- package/dist/esm/mongodb/registerExitCleanup.js.map +1 -0
- package/dist/esm/mongodb/utils/getEventId.js +10 -0
- package/dist/esm/mongodb/utils/getEventId.js.map +1 -0
- package/dist/esm/mongodb/utils/index.js +2 -0
- package/dist/esm/mongodb/utils/index.js.map +1 -0
- package/dist/esm/rabbitmq/RabbitMqCommandBus.js +21 -8
- package/dist/esm/rabbitmq/RabbitMqCommandBus.js.map +1 -1
- package/dist/esm/rabbitmq/RabbitMqEventBus.js +2 -2
- package/dist/esm/rabbitmq/RabbitMqEventBus.js.map +1 -1
- package/dist/esm/rabbitmq/RabbitMqGateway.js +69 -44
- package/dist/esm/rabbitmq/RabbitMqGateway.js.map +1 -1
- package/dist/esm/redis/AbstractRedisAccessor.js +47 -0
- package/dist/esm/redis/AbstractRedisAccessor.js.map +1 -0
- package/dist/esm/redis/AbstractRedisProjection.js +22 -0
- package/dist/esm/redis/AbstractRedisProjection.js.map +1 -0
- package/dist/esm/redis/IContainer.js +2 -0
- package/dist/esm/redis/IContainer.js.map +1 -0
- package/dist/esm/redis/RedisEventLocker.js +92 -0
- package/dist/esm/redis/RedisEventLocker.js.map +1 -0
- package/dist/esm/redis/RedisObjectStorage.js +121 -0
- package/dist/esm/redis/RedisObjectStorage.js.map +1 -0
- package/dist/esm/redis/RedisProjectionDataParams.js +2 -0
- package/dist/esm/redis/RedisProjectionDataParams.js.map +1 -0
- package/dist/esm/redis/RedisView.js +77 -0
- package/dist/esm/redis/RedisView.js.map +1 -0
- package/dist/esm/redis/RedisViewLocker.js +107 -0
- package/dist/esm/redis/RedisViewLocker.js.map +1 -0
- package/dist/esm/redis/index.js +14 -0
- package/dist/esm/redis/index.js.map +1 -0
- package/dist/esm/redis/utils/getEventId.js +10 -0
- package/dist/esm/redis/utils/getEventId.js.map +1 -0
- package/dist/esm/redis/utils/index.js +2 -0
- package/dist/esm/redis/utils/index.js.map +1 -0
- package/dist/esm/sqlite/AbstractSqliteView.js.map +1 -1
- package/dist/esm/sqlite/SqliteEventStorage.js +211 -0
- package/dist/esm/sqlite/SqliteEventStorage.js.map +1 -0
- package/dist/esm/sqlite/SqliteObjectStorage.js +7 -7
- package/dist/esm/sqlite/SqliteObjectStorage.js.map +1 -1
- package/dist/esm/sqlite/SqliteObjectView.js.map +1 -1
- package/dist/esm/sqlite/index.js +1 -0
- package/dist/esm/sqlite/index.js.map +1 -1
- package/dist/esm/sqlite/utils/bufferToGuid.js +5 -0
- package/dist/esm/sqlite/utils/bufferToGuid.js.map +1 -0
- package/dist/esm/sqlite/utils/getEventId.js +2 -2
- package/dist/esm/sqlite/utils/getEventId.js.map +1 -1
- package/dist/esm/sqlite/utils/guid.js +1 -1
- package/dist/esm/sqlite/utils/guid.js.map +1 -1
- package/dist/esm/sqlite/utils/index.js +1 -0
- package/dist/esm/sqlite/utils/index.js.map +1 -1
- package/dist/esm/telemetry/index.js +4 -0
- package/dist/esm/telemetry/index.js.map +1 -0
- package/dist/esm/telemetry/recordSpanError.js +16 -0
- package/dist/esm/telemetry/recordSpanError.js.map +1 -0
- package/dist/esm/telemetry/spanAttributes.js +23 -0
- package/dist/esm/telemetry/spanAttributes.js.map +1 -0
- package/dist/esm/telemetry/spanContext.js +22 -0
- package/dist/esm/telemetry/spanContext.js.map +1 -0
- package/dist/esm/utils/MapAssertable.js +25 -1
- package/dist/esm/utils/MapAssertable.js.map +1 -1
- package/dist/types/AbstractProjection.d.ts +3 -1
- package/dist/types/AggregateCommandHandler.d.ts +3 -3
- package/dist/types/EventDispatchPipeline.d.ts +3 -1
- package/dist/types/EventDispatcher.d.ts +9 -1
- package/dist/types/EventStore.d.ts +4 -2
- package/dist/types/SagaEventHandler.d.ts +3 -3
- package/dist/types/in-memory/InMemoryEventStorage.d.ts +2 -1
- package/dist/types/in-memory/InMemoryMessageBus.d.ts +3 -3
- package/dist/types/interfaces/ICommandBus.d.ts +3 -2
- package/dist/types/interfaces/IContainer.d.ts +7 -0
- package/dist/types/interfaces/IDispatchPipelineProcessor.d.ts +2 -0
- package/dist/types/interfaces/IEventDispatcher.d.ts +3 -0
- package/dist/types/interfaces/IMessageMeta.d.ts +4 -0
- package/dist/types/interfaces/IObservable.d.ts +2 -1
- package/dist/types/interfaces/index.d.ts +1 -0
- package/dist/types/mongodb/AbstractMongoAccessor.d.ts +26 -0
- package/dist/types/mongodb/AbstractMongoObjectProjection.d.ts +8 -0
- package/dist/types/mongodb/AbstractMongoView.d.ts +25 -0
- package/dist/types/mongodb/IContainer.d.ts +11 -0
- package/dist/types/mongodb/MongoEventLocker.d.ts +47 -0
- package/dist/types/mongodb/MongoEventStorage.d.ts +27 -0
- package/dist/types/mongodb/MongoObjectStorage.d.ts +26 -0
- package/dist/types/mongodb/MongoObjectView.d.ts +16 -0
- package/dist/types/mongodb/MongoProjectionDataParams.d.ts +14 -0
- package/dist/types/mongodb/MongoViewLocker.d.ts +43 -0
- package/dist/types/mongodb/index.d.ts +11 -0
- package/dist/types/mongodb/registerExitCleanup.d.ts +10 -0
- package/dist/types/mongodb/utils/getEventId.d.ts +5 -0
- package/dist/types/mongodb/utils/index.d.ts +1 -0
- package/dist/types/rabbitmq/IContainer.d.ts +2 -2
- package/dist/types/rabbitmq/RabbitMqCommandBus.d.ts +5 -4
- package/dist/types/rabbitmq/RabbitMqEventBus.d.ts +2 -2
- package/dist/types/rabbitmq/RabbitMqGateway.d.ts +4 -4
- package/dist/types/redis/AbstractRedisAccessor.d.ts +26 -0
- package/dist/types/redis/AbstractRedisProjection.d.ts +8 -0
- package/dist/types/redis/IContainer.d.ts +7 -0
- package/dist/types/redis/RedisEventLocker.d.ts +36 -0
- package/dist/types/redis/RedisObjectStorage.d.ts +26 -0
- package/dist/types/redis/RedisProjectionDataParams.d.ts +21 -0
- package/dist/types/redis/RedisView.d.ts +33 -0
- package/dist/types/redis/RedisViewLocker.d.ts +35 -0
- package/dist/types/redis/index.d.ts +13 -0
- package/dist/types/redis/utils/getEventId.d.ts +5 -0
- package/dist/types/redis/utils/index.d.ts +1 -0
- package/dist/types/sqlite/AbstractSqliteView.d.ts +2 -2
- package/dist/types/sqlite/SqliteEventStorage.d.ts +18 -0
- package/dist/types/sqlite/SqliteObjectStorage.d.ts +7 -7
- package/dist/types/sqlite/SqliteObjectView.d.ts +7 -7
- package/dist/types/sqlite/index.d.ts +1 -0
- package/dist/types/sqlite/utils/bufferToGuid.d.ts +4 -0
- package/dist/types/sqlite/utils/getEventId.d.ts +1 -1
- package/dist/types/sqlite/utils/guid.d.ts +2 -1
- package/dist/types/sqlite/utils/index.d.ts +1 -0
- package/dist/types/telemetry/index.d.ts +3 -0
- package/dist/types/telemetry/recordSpanError.d.ts +6 -0
- package/dist/types/telemetry/spanAttributes.d.ts +14 -0
- package/dist/types/telemetry/spanContext.d.ts +12 -0
- package/dist/types/utils/MapAssertable.d.ts +8 -0
- package/package.json +43 -13
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type IEvent, type IEventSet, type IMessageHandler, type IObservable, type IEventStream, type IEventStore, type EventQueryAfter, type EventQueryBefore, type Identifier, type IEventBus, type IContainer, type AggregateEventsQueryParams } from './interfaces/index.ts';
|
|
2
2
|
export declare class EventStore implements IEventStore {
|
|
3
3
|
#private;
|
|
4
|
-
eventBus: IEventBus;
|
|
5
|
-
constructor({ eventStorage, eventStorageReader, identifierProvider, snapshotStorage, eventBus, eventDispatcher, eventDispatchPipeline, eventDispatchPipelines, logger }: Pick<IContainer, 'eventStorage' | 'eventStorageReader' | 'identifierProvider' | 'snapshotStorage' | 'eventBus' | 'eventDispatcher' | 'logger' | 'eventDispatchPipeline' | 'eventDispatchPipelines'>);
|
|
4
|
+
readonly eventBus: IEventBus;
|
|
5
|
+
constructor({ eventStorage, eventStorageReader, identifierProvider, snapshotStorage, eventBus, eventDispatcher, eventDispatchPipeline, eventDispatchPipelines, tracerFactory, logger }: Pick<IContainer, 'eventStorage' | 'eventStorageReader' | 'identifierProvider' | 'snapshotStorage' | 'eventBus' | 'eventDispatcher' | 'logger' | 'eventDispatchPipeline' | 'eventDispatchPipelines' | 'tracerFactory'>);
|
|
6
6
|
/**
|
|
7
7
|
* Generates and returns a new unique identifier using the configured identifier provider.
|
|
8
8
|
*
|
|
@@ -21,6 +21,8 @@ export declare class EventStore implements IEventStore {
|
|
|
21
21
|
* @returns Signed and committed events
|
|
22
22
|
*/
|
|
23
23
|
dispatch(events: IEventSet, meta?: Record<string, any>): Promise<IEventSet>;
|
|
24
|
+
/** Get a promise that resolves when all in-flight fire-and-forget event bus publishes have settled */
|
|
25
|
+
drain(): Promise<unknown>;
|
|
24
26
|
on(messageType: string, handler: IMessageHandler): void;
|
|
25
27
|
off(messageType: string, handler: IMessageHandler): void;
|
|
26
28
|
queue(name: string): IObservable;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IContainer, IEvent, IEventReceptor, IObservable, ISagaConstructor, ISagaFactory } from './interfaces/index.ts';
|
|
1
|
+
import type { IContainer, IEvent, IEventReceptor, IMessageMeta, IObservable, ISagaConstructor, ISagaFactory } from './interfaces/index.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Listens to Saga events,
|
|
4
4
|
* creates new saga or restores it from event store,
|
|
@@ -7,7 +7,7 @@ import type { IContainer, IEvent, IEventReceptor, IObservable, ISagaConstructor,
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class SagaEventHandler implements IEventReceptor {
|
|
9
9
|
#private;
|
|
10
|
-
constructor(options: Pick<IContainer, 'eventStore' | 'commandBus' | 'executionLocker' | 'logger'> & {
|
|
10
|
+
constructor(options: Pick<IContainer, 'eventStore' | 'commandBus' | 'executionLocker' | 'logger' | 'tracerFactory'> & {
|
|
11
11
|
sagaType?: ISagaConstructor;
|
|
12
12
|
sagaFactory?: ISagaFactory;
|
|
13
13
|
sagaDescriptor?: string;
|
|
@@ -18,5 +18,5 @@ export declare class SagaEventHandler implements IEventReceptor {
|
|
|
18
18
|
/** Overrides observer subscribe method */
|
|
19
19
|
subscribe(eventStore: IObservable): void;
|
|
20
20
|
/** Handle saga event */
|
|
21
|
-
handle(event: IEvent): Promise<void>;
|
|
21
|
+
handle(event: IEvent, meta?: IMessageMeta): Promise<void>;
|
|
22
22
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { IIdentifierProvider, IEvent, IEventSet, EventQueryAfter, IEventStorageReader, IEventStream, Identifier, IDispatchPipelineProcessor, DispatchPipelineBatch, AggregateEventsQueryParams } from '../interfaces/index.ts';
|
|
1
|
+
import type { IContainer, IIdentifierProvider, IEvent, IEventSet, EventQueryAfter, IEventStorageReader, IEventStream, Identifier, IDispatchPipelineProcessor, DispatchPipelineBatch, AggregateEventsQueryParams } from '../interfaces/index.ts';
|
|
2
2
|
/**
|
|
3
3
|
* A simple event storage implementation intended to use for tests only.
|
|
4
4
|
* Storage content resets on each app restart.
|
|
5
5
|
*/
|
|
6
6
|
export declare class InMemoryEventStorage implements IEventStorageReader, IIdentifierProvider, IDispatchPipelineProcessor {
|
|
7
7
|
#private;
|
|
8
|
+
constructor({ tracerFactory }?: Pick<IContainer, 'tracerFactory'>);
|
|
8
9
|
getNewId(): string;
|
|
9
10
|
commitEvents(events: IEventSet, options?: {
|
|
10
11
|
ignoreConcurrencyError?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ICommand, ICommandBus, IEvent, IEventBus, IMessageHandler, IObservable, IObservableQueueProvider } from '../interfaces/index.ts';
|
|
1
|
+
import type { ICommand, ICommandBus, IEvent, IEventBus, IMessageHandler, IMessageMeta, IObservable, IObservableQueueProvider } from '../interfaces/index.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Default implementation of the message bus.
|
|
4
4
|
* Keeps all subscriptions and messages in memory.
|
|
@@ -31,11 +31,11 @@ export declare class InMemoryMessageBus implements IEventBus, ICommandBus, IObse
|
|
|
31
31
|
send(commandType: string, aggregateId?: string, options?: {
|
|
32
32
|
payload?: object;
|
|
33
33
|
context?: object;
|
|
34
|
-
}): Promise<any>;
|
|
34
|
+
} & IMessageMeta): Promise<any>;
|
|
35
35
|
/**
|
|
36
36
|
* Send pre-built command to exactly 1 command handler
|
|
37
37
|
*/
|
|
38
|
-
send(command: ICommand): Promise<any>;
|
|
38
|
+
send(command: ICommand, meta?: IMessageMeta): Promise<any>;
|
|
39
39
|
/** @deprecated Use {@link send} */
|
|
40
40
|
sendRaw(command: ICommand): Promise<any>;
|
|
41
41
|
/**
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { ICommand } from './ICommand.ts';
|
|
2
|
+
import type { IMessageMeta } from './IMessageMeta.ts';
|
|
2
3
|
import type { IObservable } from './IObservable.ts';
|
|
3
4
|
import type { IObserver } from './IObserver.ts';
|
|
4
5
|
export interface ICommandBus extends IObservable {
|
|
5
|
-
send(command: ICommand): Promise<any>;
|
|
6
|
+
send(command: ICommand, meta?: IMessageMeta): Promise<any>;
|
|
6
7
|
send(commandType: string, aggregateId?: string, options?: {
|
|
7
8
|
payload?: object;
|
|
8
9
|
context?: object;
|
|
9
|
-
}): Promise<any>;
|
|
10
|
+
} & IMessageMeta): Promise<any>;
|
|
10
11
|
/** @deprecated Use {@link send} */
|
|
11
12
|
sendRaw(command: ICommand): Promise<any>;
|
|
12
13
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Tracer } from '@opentelemetry/api';
|
|
1
2
|
import type { Container } from 'di0';
|
|
2
3
|
import type { ICommandBus } from './ICommandBus.ts';
|
|
3
4
|
import type { IEventDispatcher } from './IEventDispatcher.ts';
|
|
@@ -33,5 +34,11 @@ export interface IContainer extends Container {
|
|
|
33
34
|
eventDispatchPipelines?: Record<string, IDispatchPipelineProcessor[]>;
|
|
34
35
|
executionLocker?: ILocker;
|
|
35
36
|
logger?: ILogger | IExtendableLogger;
|
|
37
|
+
tracerFactory?: (name: string) => Tracer;
|
|
36
38
|
process?: NodeJS.Process;
|
|
39
|
+
/**
|
|
40
|
+
* Promises from projection restore operations started during container creation.
|
|
41
|
+
* Await `Promise.all(restorePromises)` before closing shared resources.
|
|
42
|
+
*/
|
|
43
|
+
restorePromises?: Promise<void>[];
|
|
37
44
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Span } from '@opentelemetry/api';
|
|
1
2
|
import type { IEvent } from './IEvent.ts';
|
|
2
3
|
/**
|
|
3
4
|
* Represents a wrapper for an event that can optionally contain additional metadata.
|
|
@@ -13,6 +14,7 @@ export type DispatchPipelineEnvelope = {
|
|
|
13
14
|
*/
|
|
14
15
|
ignoreConcurrencyError?: boolean;
|
|
15
16
|
event?: IEvent;
|
|
17
|
+
span?: Span;
|
|
16
18
|
};
|
|
17
19
|
/**
|
|
18
20
|
* A batch of event envelopes. Can contain custom envelope types extending EventEnvelope.
|
|
@@ -2,5 +2,8 @@ import type { IEventSet } from './IEventSet.ts';
|
|
|
2
2
|
import type { IEventBus } from './IEventBus.ts';
|
|
3
3
|
export interface IEventDispatcher {
|
|
4
4
|
readonly eventBus: IEventBus;
|
|
5
|
+
/** Dispatch events through a routed pipeline and publish to the shared eventBus */
|
|
5
6
|
dispatch(events: IEventSet, meta?: Record<string, any>): Promise<IEventSet>;
|
|
7
|
+
/** Get a promise that resolves when all in-flight fire-and-forget event bus publishes have settled */
|
|
8
|
+
drain(): Promise<unknown>;
|
|
6
9
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IMessage } from './IMessage.ts';
|
|
2
|
+
import type { IMessageMeta } from './IMessageMeta.ts';
|
|
2
3
|
export interface IMessageHandler {
|
|
3
|
-
(message: IMessage, meta?:
|
|
4
|
+
(message: IMessage, meta?: IMessageMeta): unknown | Promise<unknown>;
|
|
4
5
|
}
|
|
5
6
|
export interface IObservable {
|
|
6
7
|
/**
|
|
@@ -18,6 +18,7 @@ export * from './IIdentifierProvider.ts';
|
|
|
18
18
|
export * from './ILocker.ts';
|
|
19
19
|
export * from './ILogger.ts';
|
|
20
20
|
export * from './IMessage.ts';
|
|
21
|
+
export * from './IMessageMeta.ts';
|
|
21
22
|
export * from './IMutableState.ts';
|
|
22
23
|
export * from './IObjectStorage.ts';
|
|
23
24
|
export * from './IObservable.ts';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Db } from 'mongodb';
|
|
2
|
+
import type { IContainer } from 'node-cqrs';
|
|
3
|
+
/**
|
|
4
|
+
* Abstract base class for accessing a MongoDB database.
|
|
5
|
+
*
|
|
6
|
+
* Manages the database connection lifecycle, ensuring initialization via `assertConnection`.
|
|
7
|
+
* Supports providing a Db instance directly or a factory function for lazy initialization.
|
|
8
|
+
*
|
|
9
|
+
* Subclasses must implement the `initialize` method for specific setup tasks
|
|
10
|
+
* (e.g. creating collections or indexes).
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class AbstractMongoAccessor {
|
|
13
|
+
#private;
|
|
14
|
+
protected db: Db | undefined;
|
|
15
|
+
constructor(c: Partial<Pick<IContainer, 'viewModelMongoDb' | 'viewModelMongoDbFactory'>>);
|
|
16
|
+
protected abstract initialize(db: Db): Promise<void> | void;
|
|
17
|
+
/**
|
|
18
|
+
* Ensures that the MongoDB connection is initialized.
|
|
19
|
+
* Uses a lock to prevent race conditions during concurrent initialization attempts.
|
|
20
|
+
* If the database is not already set, it creates one using the provided factory
|
|
21
|
+
* and then calls the `initialize` method.
|
|
22
|
+
*
|
|
23
|
+
* This method is idempotent and safe to call multiple times.
|
|
24
|
+
*/
|
|
25
|
+
assertConnection(): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IContainer } from 'node-cqrs';
|
|
2
|
+
import { AbstractProjection } from '../AbstractProjection.ts';
|
|
3
|
+
import { MongoObjectView } from './MongoObjectView.ts';
|
|
4
|
+
export declare abstract class AbstractMongoObjectProjection<T> extends AbstractProjection<MongoObjectView<T>> {
|
|
5
|
+
static get tableName(): string;
|
|
6
|
+
static get schemaVersion(): string;
|
|
7
|
+
constructor({ viewModelMongoDb, viewModelMongoDbFactory, logger }: Partial<Pick<IContainer, 'viewModelMongoDb' | 'viewModelMongoDbFactory' | 'logger'>>);
|
|
8
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Db } from 'mongodb';
|
|
2
|
+
import type { IContainer } from 'node-cqrs';
|
|
3
|
+
import type { IEvent, IEventLocker, ILogger, IViewLocker } from '../interfaces/index.ts';
|
|
4
|
+
import { MongoViewLocker, type MongoViewLockerParams } from './MongoViewLocker.ts';
|
|
5
|
+
import { MongoEventLocker, type MongoEventLockerParams } from './MongoEventLocker.ts';
|
|
6
|
+
import { AbstractMongoAccessor } from './AbstractMongoAccessor.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Base class for MongoDB-backed projection views with restore locking and last-processed-event tracking
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class AbstractMongoView extends AbstractMongoAccessor implements IViewLocker, IEventLocker {
|
|
11
|
+
protected readonly schemaVersion: string;
|
|
12
|
+
protected readonly viewLocker: MongoViewLocker;
|
|
13
|
+
protected readonly eventLocker: MongoEventLocker;
|
|
14
|
+
protected logger: ILogger | undefined;
|
|
15
|
+
get ready(): boolean;
|
|
16
|
+
constructor(options: Partial<Pick<IContainer, 'viewModelMongoDb' | 'viewModelMongoDbFactory' | 'logger'>> & MongoEventLockerParams & MongoViewLockerParams);
|
|
17
|
+
protected initialize(_db: Db): Promise<void> | void;
|
|
18
|
+
lock(): Promise<boolean>;
|
|
19
|
+
unlock(): Promise<void>;
|
|
20
|
+
once(event: 'ready'): Promise<void>;
|
|
21
|
+
getLastEvent(): Promise<IEvent | undefined>;
|
|
22
|
+
tryMarkAsProjecting(event: IEvent): Promise<boolean>;
|
|
23
|
+
markAsProjected(event: IEvent): Promise<void>;
|
|
24
|
+
markAsLastEvent(event: IEvent): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Db } from 'mongodb';
|
|
2
|
+
declare module 'node-cqrs' {
|
|
3
|
+
interface IContainer {
|
|
4
|
+
mongoDbFactory?: () => Promise<Db> | Db;
|
|
5
|
+
mongoEventStorageConfig?: {
|
|
6
|
+
collection?: string;
|
|
7
|
+
};
|
|
8
|
+
viewModelMongoDb?: Db;
|
|
9
|
+
viewModelMongoDbFactory?: () => Promise<Db> | Db;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Db } from 'mongodb';
|
|
2
|
+
import type { IContainer } from 'node-cqrs';
|
|
3
|
+
import type { IEvent, IEventLocker } from '../interfaces/index.ts';
|
|
4
|
+
import { AbstractMongoAccessor } from './AbstractMongoAccessor.ts';
|
|
5
|
+
import type { MongoProjectionDataParams } from './MongoProjectionDataParams.ts';
|
|
6
|
+
export type MongoEventLockerParams = MongoProjectionDataParams & {
|
|
7
|
+
/**
|
|
8
|
+
* (Optional) Time-to-live (TTL) duration in milliseconds
|
|
9
|
+
* for which an event remains in the "processing" state until released.
|
|
10
|
+
*
|
|
11
|
+
* @default MongoEventLocker.DEFAULT_EVENT_LOCK_TTL
|
|
12
|
+
*/
|
|
13
|
+
eventLockTtl?: number;
|
|
14
|
+
/**
|
|
15
|
+
* (Optional) MongoDB collection name used to store per-event processing locks.
|
|
16
|
+
*
|
|
17
|
+
* @default MongoEventLocker.DEFAULT_EVENT_LOCKS_COLLECTION
|
|
18
|
+
*/
|
|
19
|
+
eventLocksCollection?: string;
|
|
20
|
+
/**
|
|
21
|
+
* (Optional) MongoDB collection name used to store the last processed event per projection.
|
|
22
|
+
*
|
|
23
|
+
* @default MongoEventLocker.DEFAULT_VIEW_LOCKS_COLLECTION
|
|
24
|
+
*/
|
|
25
|
+
viewLocksCollection?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* MongoDB-backed implementation of IEventLocker.
|
|
29
|
+
*
|
|
30
|
+
* Uses two collections:
|
|
31
|
+
* - `ncqrs_event_locks`: tracks per-event processing state
|
|
32
|
+
* - `ncqrs_view_locks`: stores the last processed event per projection
|
|
33
|
+
*
|
|
34
|
+
* Event lock state machine: nil → processing → processed
|
|
35
|
+
*/
|
|
36
|
+
export declare class MongoEventLocker extends AbstractMongoAccessor implements IEventLocker {
|
|
37
|
+
#private;
|
|
38
|
+
static DEFAULT_EVENT_LOCK_TTL: number;
|
|
39
|
+
static DEFAULT_EVENT_LOCKS_COLLECTION: string;
|
|
40
|
+
static DEFAULT_VIEW_LOCKS_COLLECTION: string;
|
|
41
|
+
constructor(o: Partial<Pick<IContainer, 'viewModelMongoDb' | 'viewModelMongoDbFactory'>> & MongoEventLockerParams);
|
|
42
|
+
protected initialize(db: Db): Promise<void>;
|
|
43
|
+
tryMarkAsProjecting(event: IEvent): Promise<boolean>;
|
|
44
|
+
markAsProjected(event: IEvent): Promise<void>;
|
|
45
|
+
markAsLastEvent(event: IEvent): Promise<void>;
|
|
46
|
+
getLastEvent(): Promise<IEvent | undefined>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IContainer } from 'node-cqrs';
|
|
2
|
+
import type { EventQueryAfter, AggregateEventsQueryParams, DispatchPipelineBatch, IDispatchPipelineProcessor, IEvent, IEventSet, IEventStorageReader, IEventStream, IIdentifierProvider, Identifier } from '../interfaces/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* MongoDB-backed event storage for node-cqrs.
|
|
5
|
+
* Implements IEventStorageReader, IIdentifierProvider, and IDispatchPipelineProcessor.
|
|
6
|
+
*/
|
|
7
|
+
export declare class MongoEventStorage implements IEventStorageReader, IIdentifierProvider, IDispatchPipelineProcessor {
|
|
8
|
+
#private;
|
|
9
|
+
static readonly EVENTS_COLLECTION = "events";
|
|
10
|
+
constructor({ mongoDbFactory, mongoEventStorageConfig, process }: Pick<IContainer, 'mongoDbFactory' | 'mongoEventStorageConfig' | 'process'>);
|
|
11
|
+
getNewId(): string;
|
|
12
|
+
commitEvents(events: IEventSet, options?: {
|
|
13
|
+
ignoreConcurrencyError?: boolean;
|
|
14
|
+
}): Promise<IEventSet>;
|
|
15
|
+
getAggregateEvents(aggregateId: Identifier, options?: AggregateEventsQueryParams): IEventStream;
|
|
16
|
+
getSagaEvents(sagaId: Identifier, { beforeEvent }: {
|
|
17
|
+
beforeEvent: IEvent;
|
|
18
|
+
}): IEventStream;
|
|
19
|
+
getEventsByTypes(eventTypes: Readonly<string[]>, options?: EventQueryAfter): IEventStream;
|
|
20
|
+
/**
|
|
21
|
+
* Processes a batch of dispatch pipeline items, commits the events to MongoDB,
|
|
22
|
+
* and returns the original batch.
|
|
23
|
+
*
|
|
24
|
+
* This method is part of the `IDispatchPipelineProcessor` interface.
|
|
25
|
+
*/
|
|
26
|
+
process(batch: DispatchPipelineBatch): Promise<DispatchPipelineBatch>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Db } from 'mongodb';
|
|
2
|
+
import type { IContainer } from 'node-cqrs';
|
|
3
|
+
import type { IObjectStorage, Identifier } from '../interfaces/index.ts';
|
|
4
|
+
import { AbstractMongoAccessor } from './AbstractMongoAccessor.ts';
|
|
5
|
+
/**
|
|
6
|
+
* MongoDB-backed implementation of IObjectStorage.
|
|
7
|
+
*
|
|
8
|
+
* Each record is stored as a document `{ _id, data, version }`.
|
|
9
|
+
* The version field enables optimistic concurrency control: `update` and
|
|
10
|
+
* `updateEnforcingNew` re-read the record after the user callback runs and
|
|
11
|
+
* atomically commit only when the version still matches.
|
|
12
|
+
* On mismatch the operation retries up to `maxRetries` times.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MongoObjectStorage<TRecord> extends AbstractMongoAccessor implements IObjectStorage<TRecord> {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(o: Partial<Pick<IContainer, 'viewModelMongoDb' | 'viewModelMongoDbFactory'>> & {
|
|
17
|
+
tableName: string;
|
|
18
|
+
maxRetries?: number;
|
|
19
|
+
});
|
|
20
|
+
protected initialize(db: Db): Promise<void>;
|
|
21
|
+
get(id: Identifier): Promise<TRecord | undefined>;
|
|
22
|
+
create(id: Identifier, data: TRecord): Promise<void>;
|
|
23
|
+
update(id: Identifier, update: (r: TRecord) => TRecord): Promise<void>;
|
|
24
|
+
updateEnforcingNew(id: Identifier, update: (r?: TRecord) => TRecord): Promise<void>;
|
|
25
|
+
delete(id: Identifier): Promise<boolean>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AbstractMongoView } from './AbstractMongoView.ts';
|
|
2
|
+
import type { IObjectStorage, IEventLocker, Identifier } from '../interfaces/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* MongoDB-backed object view with restore locking and last-processed-event tracking
|
|
5
|
+
*/
|
|
6
|
+
export declare class MongoObjectView<TRecord> extends AbstractMongoView implements IObjectStorage<TRecord>, IEventLocker {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(options: ConstructorParameters<typeof AbstractMongoView>[0] & {
|
|
9
|
+
tableNamePrefix: string;
|
|
10
|
+
});
|
|
11
|
+
get(id: Identifier): Promise<TRecord | undefined>;
|
|
12
|
+
create(id: Identifier, data: TRecord): Promise<void>;
|
|
13
|
+
update(id: Identifier, update: (r: TRecord) => TRecord): Promise<void>;
|
|
14
|
+
updateEnforcingNew(id: Identifier, update: (r?: TRecord) => TRecord): Promise<void>;
|
|
15
|
+
delete(id: Identifier): Promise<boolean>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type MongoProjectionDataParams = {
|
|
2
|
+
/**
|
|
3
|
+
* Unique identifier for the projection, used with the schema version to distinguish data ownership.
|
|
4
|
+
*/
|
|
5
|
+
projectionName: string;
|
|
6
|
+
/**
|
|
7
|
+
* The version of the schema used for data produced by the projection.
|
|
8
|
+
* When the projection's output format changes, this version should be incremented.
|
|
9
|
+
* A version change indicates that previously stored data is obsolete and must be rebuilt.
|
|
10
|
+
*
|
|
11
|
+
* @example "20250519", "1.0.0"
|
|
12
|
+
*/
|
|
13
|
+
schemaVersion: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Db } from 'mongodb';
|
|
2
|
+
import type { IContainer } from 'node-cqrs';
|
|
3
|
+
import type { IViewLocker } from '../interfaces/index.ts';
|
|
4
|
+
import { AbstractMongoAccessor } from './AbstractMongoAccessor.ts';
|
|
5
|
+
import type { MongoProjectionDataParams } from './MongoProjectionDataParams.ts';
|
|
6
|
+
export type MongoViewLockerParams = MongoProjectionDataParams & {
|
|
7
|
+
/**
|
|
8
|
+
* (Optional) Time-to-live (TTL) duration (in milliseconds) for which a view remains locked.
|
|
9
|
+
* The lock is automatically prolonged while still held by this instance.
|
|
10
|
+
*
|
|
11
|
+
* @default MongoViewLocker.DEFAULT_VIEW_LOCK_TTL
|
|
12
|
+
*/
|
|
13
|
+
viewLockTtl?: number;
|
|
14
|
+
/**
|
|
15
|
+
* (Optional) MongoDB collection name used to store view locks.
|
|
16
|
+
*
|
|
17
|
+
* @default MongoViewLocker.DEFAULT_COLLECTION
|
|
18
|
+
*/
|
|
19
|
+
viewLocksCollection?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* MongoDB-backed implementation of IViewLocker.
|
|
23
|
+
*
|
|
24
|
+
* Uses a MongoDB document with token + lockedTill semantics to acquire a distributed view lock.
|
|
25
|
+
* The lock is automatically prolonged at half the TTL interval to prevent expiration
|
|
26
|
+
* while processing is in progress.
|
|
27
|
+
*
|
|
28
|
+
* Collection name: `ncqrs_view_locks`
|
|
29
|
+
*/
|
|
30
|
+
export declare class MongoViewLocker extends AbstractMongoAccessor implements IViewLocker {
|
|
31
|
+
#private;
|
|
32
|
+
static DEFAULT_VIEW_LOCK_TTL: number;
|
|
33
|
+
static DEFAULT_COLLECTION: string;
|
|
34
|
+
constructor(o: Partial<Pick<IContainer, 'viewModelMongoDb' | 'viewModelMongoDbFactory' | 'logger'>> & MongoViewLockerParams);
|
|
35
|
+
protected initialize(db: Db): Promise<void>;
|
|
36
|
+
get ready(): boolean;
|
|
37
|
+
lock(): Promise<boolean>;
|
|
38
|
+
private scheduleLockProlongation;
|
|
39
|
+
private cancelLockProlongation;
|
|
40
|
+
private prolongLock;
|
|
41
|
+
unlock(): Promise<void>;
|
|
42
|
+
once(event: 'ready'): Promise<void>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import './IContainer.ts';
|
|
2
|
+
export * from './AbstractMongoAccessor.ts';
|
|
3
|
+
export * from './AbstractMongoObjectProjection.ts';
|
|
4
|
+
export * from './AbstractMongoView.ts';
|
|
5
|
+
export * from './MongoEventLocker.ts';
|
|
6
|
+
export * from './MongoEventStorage.ts';
|
|
7
|
+
export * from './MongoObjectStorage.ts';
|
|
8
|
+
export * from './MongoObjectView.ts';
|
|
9
|
+
export * from './MongoProjectionDataParams.ts';
|
|
10
|
+
export * from './MongoViewLocker.ts';
|
|
11
|
+
export * from './utils/index.ts';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers cleanup handlers for SIGINT and SIGTERM signals on a Node.js process.
|
|
3
|
+
* Executes the provided cleanup procedure when one of these signals is received,
|
|
4
|
+
* then removes the listeners to allow the process to exit gracefully.
|
|
5
|
+
*
|
|
6
|
+
* @returns An object with a `dispose` method to manually remove the registered signal handlers.
|
|
7
|
+
*/
|
|
8
|
+
export declare const registerExitCleanup: (process: NodeJS.Process | undefined, cleanupProcedure: () => Promise<unknown> | unknown) => {
|
|
9
|
+
dispose: () => void;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getEventId.ts';
|
|
@@ -5,8 +5,8 @@ import type { RabbitMqGateway } from './RabbitMqGateway.ts';
|
|
|
5
5
|
import type { ConfigProvider } from './utils/index.ts';
|
|
6
6
|
declare module 'node-cqrs' {
|
|
7
7
|
interface IContainer {
|
|
8
|
-
rabbitMqGateway
|
|
9
|
-
rabbitMqConnectionFactory
|
|
8
|
+
rabbitMqGateway: RabbitMqGateway;
|
|
9
|
+
rabbitMqConnectionFactory: () => Promise<ChannelModel>;
|
|
10
10
|
/**
|
|
11
11
|
* Provides app id for publish metadata and `ignoreOwn` filtering.
|
|
12
12
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IContainer } from 'node-cqrs';
|
|
2
|
-
import type { ICommand, ICommandBus, IMessageHandler } from '../interfaces/index.ts';
|
|
2
|
+
import type { ICommand, ICommandBus, IMessageHandler, IMessageMeta } from '../interfaces/index.ts';
|
|
3
3
|
import { type Subscription } from './RabbitMqGateway.ts';
|
|
4
4
|
export type RabbitMqCommandBusConfig = Partial<Pick<Subscription, 'exchange' | 'queueName' | 'ignoreOwn' | 'concurrentLimit' | 'handlerProcessTimeout' | 'queueExpires'>>;
|
|
5
5
|
/**
|
|
@@ -11,6 +11,7 @@ export type RabbitMqCommandBusConfig = Partial<Pick<Subscription, 'exchange' | '
|
|
|
11
11
|
export declare class RabbitMqCommandBus implements ICommandBus {
|
|
12
12
|
#private;
|
|
13
13
|
static DEFAULT_EXCHANGE: string;
|
|
14
|
+
static DEFAULT_QUEUE_NAME: string;
|
|
14
15
|
constructor({ rabbitMqGateway, rabbitMqCommandBusConfig }: Pick<IContainer, 'rabbitMqGateway' | 'rabbitMqCommandBusConfig'>);
|
|
15
16
|
/**
|
|
16
17
|
* Format and send a command for execution
|
|
@@ -18,14 +19,14 @@ export declare class RabbitMqCommandBus implements ICommandBus {
|
|
|
18
19
|
send(commandType: string, aggregateId?: string, options?: {
|
|
19
20
|
payload?: object;
|
|
20
21
|
context?: object;
|
|
21
|
-
}): Promise<any>;
|
|
22
|
+
} & IMessageMeta): Promise<any>;
|
|
22
23
|
/**
|
|
23
24
|
* Sends a pre-built command to the exchange, routed to the durable queue.
|
|
24
25
|
* Exactly one consumer will process it.
|
|
25
26
|
*/
|
|
26
|
-
send(command: ICommand): Promise<any>;
|
|
27
|
+
send(command: ICommand, meta?: IMessageMeta): Promise<any>;
|
|
27
28
|
/** @deprecated Use {@link send} */
|
|
28
|
-
sendRaw(command: ICommand): Promise<any>;
|
|
29
|
+
sendRaw(command: ICommand, meta?: IMessageMeta): Promise<any>;
|
|
29
30
|
/**
|
|
30
31
|
* Registers a message handler for a specific message type on the durable queue.
|
|
31
32
|
* Only one consumer receives each message.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IContainer } from 'node-cqrs';
|
|
2
|
-
import type { IEventBus, IMessage, IMessageHandler, IObservable, IObservableQueueProvider } from '../interfaces/index.ts';
|
|
2
|
+
import type { IEventBus, IMessage, IMessageHandler, IMessageMeta, IObservable, IObservableQueueProvider } from '../interfaces/index.ts';
|
|
3
3
|
import { type Subscription, type SubscribeResult } from './RabbitMqGateway.ts';
|
|
4
4
|
export type RabbitMqEventBusConfig = Partial<Pick<Subscription, 'exchange' | 'queueName' | 'ignoreOwn' | 'concurrentLimit' | 'handlerProcessTimeout' | 'queueExpires'>>;
|
|
5
5
|
/**
|
|
@@ -22,7 +22,7 @@ export declare class RabbitMqEventBus implements IEventBus, IObservableQueueProv
|
|
|
22
22
|
* Publishes a message to the event exchange.
|
|
23
23
|
* The message will be delivered to all subscribers.
|
|
24
24
|
*/
|
|
25
|
-
publish(message: IMessage): Promise<void>;
|
|
25
|
+
publish(message: IMessage, meta?: IMessageMeta): Promise<void>;
|
|
26
26
|
/**
|
|
27
27
|
* Registers a message handler for a specific message type.
|
|
28
28
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ChannelModel } from 'amqplib';
|
|
2
2
|
import type { IContainer } from 'node-cqrs';
|
|
3
|
-
import type { IMessage } from '../interfaces/index.ts';
|
|
3
|
+
import type { IMessage, IMessageMeta } from '../interfaces/index.ts';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
|
-
type MessageHandler = (m: IMessage) => Promise<unknown> | unknown;
|
|
5
|
+
type MessageHandler = (m: IMessage, meta?: IMessageMeta) => Promise<unknown> | unknown;
|
|
6
6
|
/**
|
|
7
7
|
* Represents a subscription to events from a RabbitMQ exchange.
|
|
8
8
|
*/
|
|
@@ -79,7 +79,7 @@ export declare class RabbitMqGateway {
|
|
|
79
79
|
static RECONNECT_DELAY: number;
|
|
80
80
|
get connection(): ChannelModel | undefined;
|
|
81
81
|
isConnected(): this is this & RabbitMqGatewayConnected;
|
|
82
|
-
constructor({ rabbitMqConnectionFactory, rabbitMqAppId, eventEmitterFactory, logger, process }: Partial<Pick<IContainer, 'logger' | 'process' | 'rabbitMqConnectionFactory' | 'rabbitMqAppId'>> & {
|
|
82
|
+
constructor({ rabbitMqConnectionFactory, rabbitMqAppId, eventEmitterFactory, logger, process, tracerFactory }: Partial<Pick<IContainer, 'logger' | 'process' | 'rabbitMqConnectionFactory' | 'rabbitMqAppId' | 'tracerFactory'>> & {
|
|
83
83
|
eventEmitterFactory?: () => EventEmitter<GatewayEvents>;
|
|
84
84
|
});
|
|
85
85
|
/** Returns this gateway's app id from `rabbitMqAppIdProvider` */
|
|
@@ -125,7 +125,7 @@ export declare class RabbitMqGateway {
|
|
|
125
125
|
* Publishes an event to the fanout exchange.
|
|
126
126
|
* The event will be delivered to all subscribers, except this instance's own consumer.
|
|
127
127
|
*/
|
|
128
|
-
publish(exchange: string, message: IMessage): Promise<void>;
|
|
128
|
+
publish(exchange: string, message: IMessage, meta?: IMessageMeta): Promise<void>;
|
|
129
129
|
on<K extends keyof GatewayEvents>(event: K, fn: (...args: GatewayEvents[K]) => void): this;
|
|
130
130
|
once<K extends keyof GatewayEvents>(event: K, fn: (...args: GatewayEvents[K]) => void): this;
|
|
131
131
|
off<K extends keyof GatewayEvents>(event: K, fn: (...args: GatewayEvents[K]) => void): this;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IContainer } from 'node-cqrs';
|
|
2
|
+
import type { Redis } from 'ioredis';
|
|
3
|
+
/**
|
|
4
|
+
* Abstract base class for accessing a Redis instance.
|
|
5
|
+
*
|
|
6
|
+
* Manages the Redis client lifecycle, ensuring initialization via `assertConnection`.
|
|
7
|
+
* Supports providing a Redis instance directly or a factory function for lazy initialization.
|
|
8
|
+
*
|
|
9
|
+
* Subclasses must implement the `initialize` method for specific setup tasks
|
|
10
|
+
* (e.g. registering Lua commands with `defineCommand`).
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class AbstractRedisAccessor {
|
|
13
|
+
#private;
|
|
14
|
+
protected redis: Redis | undefined;
|
|
15
|
+
constructor(c: Partial<Pick<IContainer, 'viewModelRedis' | 'viewModelRedisFactory'>>);
|
|
16
|
+
protected abstract initialize(redis: Redis): Promise<void> | void;
|
|
17
|
+
/**
|
|
18
|
+
* Ensures that the Redis connection is initialized.
|
|
19
|
+
* Uses a lock to prevent race conditions during concurrent initialization attempts.
|
|
20
|
+
* If the client is not already set, it creates one using the provided factory
|
|
21
|
+
* and then calls the `initialize` method.
|
|
22
|
+
*
|
|
23
|
+
* This method is idempotent and safe to call multiple times.
|
|
24
|
+
*/
|
|
25
|
+
assertConnection(): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IContainer } from 'node-cqrs';
|
|
2
|
+
import { AbstractProjection } from '../AbstractProjection.ts';
|
|
3
|
+
import { RedisView } from './RedisView.ts';
|
|
4
|
+
export declare abstract class AbstractRedisProjection<T> extends AbstractProjection<RedisView<T>> {
|
|
5
|
+
static get tableName(): string;
|
|
6
|
+
static get schemaVersion(): string;
|
|
7
|
+
constructor({ viewModelRedis, viewModelRedisFactory, logger }: Partial<Pick<IContainer, 'viewModelRedis' | 'viewModelRedisFactory' | 'logger'>>);
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Redis } from 'ioredis';
|
|
2
|
+
import type { IContainer } from 'node-cqrs';
|
|
3
|
+
import type { IEvent, IEventLocker } from '../interfaces/index.ts';
|
|
4
|
+
import { AbstractRedisAccessor } from './AbstractRedisAccessor.ts';
|
|
5
|
+
import type { RedisProjectionDataParams } from './RedisProjectionDataParams.ts';
|
|
6
|
+
export type RedisEventLockerParams = RedisProjectionDataParams & {
|
|
7
|
+
/**
|
|
8
|
+
* (Optional) Time-to-live (TTL) duration in milliseconds for which an event
|
|
9
|
+
* remains in the "processing" state. After expiry Redis removes the key
|
|
10
|
+
* automatically, allowing another instance to re-acquire the lock.
|
|
11
|
+
*
|
|
12
|
+
* @default 15_000
|
|
13
|
+
*/
|
|
14
|
+
eventLockTtl?: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Redis-backed implementation of IEventLocker.
|
|
18
|
+
*
|
|
19
|
+
* Uses Lua scripts for atomic state transitions:
|
|
20
|
+
* - `tryMarkAsProjecting`: SET key "processing" NX PX {ttl}
|
|
21
|
+
* - `markAsProjected`: transitions "processing" → "processed" (permanent)
|
|
22
|
+
* - `markAsLastEvent` / `getLastEvent`: a single JSON key per projection
|
|
23
|
+
*
|
|
24
|
+
* Key formats:
|
|
25
|
+
* - Event lock: `{keyPrefix}:evtlock:{projectionName}:{schemaVersion}:{eventId}`
|
|
26
|
+
* - Last event: `{keyPrefix}:lastevent:{projectionName}:{schemaVersion}`
|
|
27
|
+
*/
|
|
28
|
+
export declare class RedisEventLocker extends AbstractRedisAccessor implements IEventLocker {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(o: Partial<Pick<IContainer, 'viewModelRedis' | 'viewModelRedisFactory'>> & RedisEventLockerParams);
|
|
31
|
+
protected initialize(_redis: Redis): void;
|
|
32
|
+
tryMarkAsProjecting(event: IEvent): Promise<boolean>;
|
|
33
|
+
markAsProjected(event: IEvent): Promise<void>;
|
|
34
|
+
markAsLastEvent(event: IEvent): Promise<void>;
|
|
35
|
+
getLastEvent(): Promise<IEvent | undefined>;
|
|
36
|
+
}
|