node-cqrs 0.16.4 → 1.0.0-beta.0
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 +615 -79
- package/LICENSE +202 -21
- package/NOTICE +15 -0
- package/README.md +429 -112
- package/dist/cjs/AbstractAggregate.js +193 -0
- package/dist/cjs/AbstractAggregate.js.map +1 -0
- package/dist/cjs/AbstractProjection.js +165 -0
- package/dist/cjs/AbstractProjection.js.map +1 -0
- package/dist/cjs/AbstractSaga.js +109 -0
- package/dist/cjs/AbstractSaga.js.map +1 -0
- package/dist/cjs/AggregateCommandHandler.js +182 -0
- package/dist/cjs/AggregateCommandHandler.js.map +1 -0
- package/dist/cjs/CommandBus.js +9 -0
- package/dist/cjs/CommandBus.js.map +1 -0
- package/dist/cjs/CqrsContainerBuilder.js +97 -0
- package/dist/cjs/CqrsContainerBuilder.js.map +1 -0
- package/dist/cjs/Event.js +19 -0
- package/dist/cjs/Event.js.map +1 -0
- package/dist/cjs/EventDispatchPipeline.js +83 -0
- package/dist/cjs/EventDispatchPipeline.js.map +1 -0
- package/dist/cjs/EventDispatcher.js +93 -0
- package/dist/cjs/EventDispatcher.js.map +1 -0
- package/dist/cjs/EventIdAugmentor.js +30 -0
- package/dist/cjs/EventIdAugmentor.js.map +1 -0
- package/dist/cjs/EventStore.js +106 -0
- package/dist/cjs/EventStore.js.map +1 -0
- package/dist/cjs/SagaEventHandler.js +153 -0
- package/dist/cjs/SagaEventHandler.js.map +1 -0
- package/dist/cjs/errors/ConcurrencyError.js +21 -0
- package/dist/cjs/errors/ConcurrencyError.js.map +1 -0
- package/dist/cjs/errors/index.js +18 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/in-memory/InMemoryEventStorage.js +106 -0
- package/dist/cjs/in-memory/InMemoryEventStorage.js.map +1 -0
- package/dist/cjs/in-memory/InMemoryLock.js +44 -0
- package/dist/cjs/in-memory/InMemoryLock.js.map +1 -0
- package/dist/cjs/in-memory/InMemoryMessageBus.js +93 -0
- package/dist/cjs/in-memory/InMemoryMessageBus.js.map +1 -0
- package/dist/cjs/in-memory/InMemorySnapshotStorage.js +101 -0
- package/dist/cjs/in-memory/InMemorySnapshotStorage.js.map +1 -0
- package/dist/cjs/in-memory/InMemoryView.js +154 -0
- package/dist/cjs/in-memory/InMemoryView.js.map +1 -0
- package/dist/cjs/in-memory/index.js +22 -0
- package/dist/cjs/in-memory/index.js.map +1 -0
- package/dist/cjs/in-memory/utils/index.js +18 -0
- package/dist/cjs/in-memory/utils/index.js.map +1 -0
- package/dist/cjs/in-memory/utils/nextCycle.js +9 -0
- package/dist/cjs/in-memory/utils/nextCycle.js.map +1 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interfaces/IAggregate.js +3 -0
- package/dist/cjs/interfaces/IAggregate.js.map +1 -0
- package/dist/cjs/interfaces/IAggregateSnapshotStorage.js +13 -0
- package/dist/cjs/interfaces/IAggregateSnapshotStorage.js.map +1 -0
- package/dist/cjs/interfaces/ICommand.js +3 -0
- package/dist/cjs/interfaces/ICommand.js.map +1 -0
- package/dist/cjs/interfaces/ICommandBus.js +3 -0
- package/dist/cjs/interfaces/ICommandBus.js.map +1 -0
- package/dist/cjs/interfaces/IContainer.js +3 -0
- package/dist/cjs/interfaces/IContainer.js.map +1 -0
- package/dist/cjs/interfaces/IDispatchPipelineProcessor.js +9 -0
- package/dist/cjs/interfaces/IDispatchPipelineProcessor.js.map +1 -0
- package/dist/cjs/interfaces/IEvent.js +10 -0
- package/dist/cjs/interfaces/IEvent.js.map +1 -0
- package/dist/cjs/interfaces/IEventBus.js +9 -0
- package/dist/cjs/interfaces/IEventBus.js.map +1 -0
- package/dist/cjs/interfaces/IEventDispatcher.js +3 -0
- package/dist/cjs/interfaces/IEventDispatcher.js.map +1 -0
- package/dist/cjs/interfaces/IEventLocker.js +15 -0
- package/dist/cjs/interfaces/IEventLocker.js.map +1 -0
- package/dist/cjs/interfaces/IEventReceptor.js +3 -0
- package/dist/cjs/interfaces/IEventReceptor.js.map +1 -0
- package/dist/cjs/interfaces/IEventSet.js +8 -0
- package/dist/cjs/interfaces/IEventSet.js.map +1 -0
- package/dist/cjs/interfaces/IEventStorageReader.js +13 -0
- package/dist/cjs/interfaces/IEventStorageReader.js.map +1 -0
- package/dist/cjs/interfaces/IEventStore.js +3 -0
- package/dist/cjs/interfaces/IEventStore.js.map +1 -0
- package/dist/cjs/interfaces/IEventStream.js +3 -0
- package/dist/cjs/interfaces/IEventStream.js.map +1 -0
- package/dist/cjs/interfaces/IIdentifierProvider.js +9 -0
- package/dist/cjs/interfaces/IIdentifierProvider.js.map +1 -0
- package/dist/cjs/interfaces/ILocker.js +9 -0
- package/dist/cjs/interfaces/ILocker.js.map +1 -0
- package/dist/cjs/interfaces/ILogger.js +3 -0
- package/dist/cjs/interfaces/ILogger.js.map +1 -0
- package/dist/cjs/interfaces/IMessage.js +10 -0
- package/dist/cjs/interfaces/IMessage.js.map +1 -0
- package/dist/cjs/interfaces/IMutableState.js +3 -0
- package/dist/cjs/interfaces/IMutableState.js.map +1 -0
- package/dist/cjs/interfaces/IObjectStorage.js +3 -0
- package/dist/cjs/interfaces/IObjectStorage.js.map +1 -0
- package/dist/cjs/interfaces/IObservable.js +11 -0
- package/dist/cjs/interfaces/IObservable.js.map +1 -0
- package/dist/cjs/interfaces/IObservableQueueProvider.js +9 -0
- package/dist/cjs/interfaces/IObservableQueueProvider.js.map +1 -0
- package/dist/cjs/interfaces/IObserver.js +3 -0
- package/dist/cjs/interfaces/IObserver.js.map +1 -0
- package/dist/cjs/interfaces/IProjection.js +3 -0
- package/dist/cjs/interfaces/IProjection.js.map +1 -0
- package/dist/cjs/interfaces/ISaga.js +3 -0
- package/dist/cjs/interfaces/ISaga.js.map +1 -0
- package/dist/cjs/interfaces/ISnapshotEvent.js +10 -0
- package/dist/cjs/interfaces/ISnapshotEvent.js.map +1 -0
- package/dist/cjs/interfaces/IViewLocker.js +21 -0
- package/dist/cjs/interfaces/IViewLocker.js.map +1 -0
- package/dist/cjs/interfaces/Identifier.js +3 -0
- package/dist/cjs/interfaces/Identifier.js.map +1 -0
- package/dist/cjs/interfaces/index.js +46 -0
- package/dist/cjs/interfaces/index.js.map +1 -0
- package/dist/cjs/interfaces/isObject.js +9 -0
- package/dist/cjs/interfaces/isObject.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/rabbitmq/IContainer.js +3 -0
- package/dist/cjs/rabbitmq/IContainer.js.map +1 -0
- package/dist/cjs/rabbitmq/RabbitMqCommandBus.js +84 -0
- package/dist/cjs/rabbitmq/RabbitMqCommandBus.js.map +1 -0
- package/dist/cjs/rabbitmq/RabbitMqEventBus.js +121 -0
- package/dist/cjs/rabbitmq/RabbitMqEventBus.js.map +1 -0
- package/dist/cjs/rabbitmq/RabbitMqGateway.js +578 -0
- package/dist/cjs/rabbitmq/RabbitMqGateway.js.map +1 -0
- package/dist/cjs/rabbitmq/index.js +21 -0
- package/dist/cjs/rabbitmq/index.js.map +1 -0
- package/dist/cjs/rabbitmq/utils/index.js +19 -0
- package/dist/cjs/rabbitmq/utils/index.js.map +1 -0
- package/dist/cjs/rabbitmq/utils/registerExitCleanup.js +28 -0
- package/dist/cjs/rabbitmq/utils/registerExitCleanup.js.map +1 -0
- package/dist/cjs/rabbitmq/utils/resolveProvider.js +9 -0
- package/dist/cjs/rabbitmq/utils/resolveProvider.js.map +1 -0
- package/dist/cjs/sqlite/AbstractSqliteAccessor.js +50 -0
- package/dist/cjs/sqlite/AbstractSqliteAccessor.js.map +1 -0
- package/dist/cjs/sqlite/AbstractSqliteObjectProjection.js +26 -0
- package/dist/cjs/sqlite/AbstractSqliteObjectProjection.js.map +1 -0
- package/dist/cjs/sqlite/AbstractSqliteView.js +50 -0
- package/dist/cjs/sqlite/AbstractSqliteView.js.map +1 -0
- package/dist/cjs/sqlite/IContainer.js +3 -0
- package/dist/cjs/sqlite/IContainer.js.map +1 -0
- package/dist/cjs/sqlite/SqliteEventLocker.js +93 -0
- package/dist/cjs/sqlite/SqliteEventLocker.js.map +1 -0
- package/dist/cjs/sqlite/SqliteObjectStorage.js +114 -0
- package/dist/cjs/sqlite/SqliteObjectStorage.js.map +1 -0
- package/dist/cjs/sqlite/SqliteObjectView.js +48 -0
- package/dist/cjs/sqlite/SqliteObjectView.js.map +1 -0
- package/dist/cjs/sqlite/SqliteProjectionDataParams.js +3 -0
- package/dist/cjs/sqlite/SqliteProjectionDataParams.js.map +1 -0
- package/dist/cjs/sqlite/SqliteViewLocker.js +119 -0
- package/dist/cjs/sqlite/SqliteViewLocker.js.map +1 -0
- package/dist/cjs/sqlite/index.js +26 -0
- package/dist/cjs/sqlite/index.js.map +1 -0
- package/dist/cjs/sqlite/queries/eventLockTableInit.js +15 -0
- package/dist/cjs/sqlite/queries/eventLockTableInit.js.map +1 -0
- package/dist/cjs/sqlite/queries/index.js +19 -0
- package/dist/cjs/sqlite/queries/index.js.map +1 -0
- package/dist/cjs/sqlite/queries/viewLockTableInit.js +14 -0
- package/dist/cjs/sqlite/queries/viewLockTableInit.js.map +1 -0
- package/dist/cjs/sqlite/utils/getEventId.js +14 -0
- package/dist/cjs/sqlite/utils/getEventId.js.map +1 -0
- package/dist/cjs/sqlite/utils/guid.js +9 -0
- package/dist/cjs/sqlite/utils/guid.js.map +1 -0
- package/dist/cjs/sqlite/utils/index.js +19 -0
- package/dist/cjs/sqlite/utils/index.js.map +1 -0
- package/dist/cjs/utils/Deferred.js +38 -0
- package/dist/cjs/utils/Deferred.js.map +1 -0
- package/dist/cjs/utils/Lock.js +102 -0
- package/dist/cjs/utils/Lock.js.map +1 -0
- package/dist/cjs/utils/MapAssertable.js +30 -0
- package/dist/cjs/utils/MapAssertable.js.map +1 -0
- package/dist/cjs/utils/assert.js +88 -0
- package/dist/cjs/utils/assert.js.map +1 -0
- package/dist/cjs/utils/clone.js +13 -0
- package/dist/cjs/utils/clone.js.map +1 -0
- package/dist/cjs/utils/extractErrorDetails.js +37 -0
- package/dist/cjs/utils/extractErrorDetails.js.map +1 -0
- package/dist/cjs/utils/getClassName.js +10 -0
- package/dist/cjs/utils/getClassName.js.map +1 -0
- package/dist/cjs/utils/getHandler.js +18 -0
- package/dist/cjs/utils/getHandler.js.map +1 -0
- package/dist/cjs/utils/getMessageHandlerNames.js +30 -0
- package/dist/cjs/utils/getMessageHandlerNames.js.map +1 -0
- package/dist/cjs/utils/index.js +31 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/isClass.js +8 -0
- package/dist/cjs/utils/isClass.js.map +1 -0
- package/dist/cjs/utils/sagaId.js +23 -0
- package/dist/cjs/utils/sagaId.js.map +1 -0
- package/dist/cjs/utils/setupOneTimeEmitterSubscription.js +45 -0
- package/dist/cjs/utils/setupOneTimeEmitterSubscription.js.map +1 -0
- package/dist/cjs/utils/subscribe.js +43 -0
- package/dist/cjs/utils/subscribe.js.map +1 -0
- package/dist/cjs/utils/validateHandlers.js +21 -0
- package/dist/cjs/utils/validateHandlers.js.map +1 -0
- package/dist/cjs/workers/AbstractWorkerProjection.js +56 -0
- package/dist/cjs/workers/AbstractWorkerProjection.js.map +1 -0
- package/dist/cjs/workers/WorkerProxyProjection.js +142 -0
- package/dist/cjs/workers/WorkerProxyProjection.js.map +1 -0
- package/dist/cjs/workers/index.js +20 -0
- package/dist/cjs/workers/index.js.map +1 -0
- package/dist/cjs/workers/interfaces/IProxyProjection.js +3 -0
- package/dist/cjs/workers/interfaces/IProxyProjection.js.map +1 -0
- package/dist/cjs/workers/interfaces/IWorkerProjection.js +3 -0
- package/dist/cjs/workers/interfaces/IWorkerProjection.js.map +1 -0
- package/dist/cjs/workers/interfaces/index.js +3 -0
- package/dist/cjs/workers/interfaces/index.js.map +1 -0
- package/dist/cjs/workers/protocol.js +16 -0
- package/dist/cjs/workers/protocol.js.map +1 -0
- package/dist/cjs/workers/utils/ProjectionView.js +3 -0
- package/dist/cjs/workers/utils/ProjectionView.js.map +1 -0
- package/dist/cjs/workers/utils/createWorker.js +87 -0
- package/dist/cjs/workers/utils/createWorker.js.map +1 -0
- package/dist/cjs/workers/utils/createWorkerInstance.js +59 -0
- package/dist/cjs/workers/utils/createWorkerInstance.js.map +1 -0
- package/dist/cjs/workers/utils/index.js +21 -0
- package/dist/cjs/workers/utils/index.js.map +1 -0
- package/dist/cjs/workers/utils/nodeEndpoint.js +8 -0
- package/dist/cjs/workers/utils/nodeEndpoint.js.map +1 -0
- package/dist/cjs/workers/utils/workerProxyFactory.js +21 -0
- package/dist/cjs/workers/utils/workerProxyFactory.js.map +1 -0
- package/dist/esm/AbstractAggregate.js +189 -0
- package/dist/esm/AbstractAggregate.js.map +1 -0
- package/dist/esm/AbstractProjection.js +161 -0
- package/dist/esm/AbstractProjection.js.map +1 -0
- package/dist/esm/AbstractSaga.js +105 -0
- package/dist/esm/AbstractSaga.js.map +1 -0
- package/dist/esm/AggregateCommandHandler.js +178 -0
- package/dist/esm/AggregateCommandHandler.js.map +1 -0
- package/dist/esm/CommandBus.js +5 -0
- package/dist/esm/CommandBus.js.map +1 -0
- package/dist/esm/CqrsContainerBuilder.js +93 -0
- package/dist/esm/CqrsContainerBuilder.js.map +1 -0
- package/dist/esm/Event.js +15 -0
- package/dist/esm/Event.js.map +1 -0
- package/dist/esm/EventDispatchPipeline.js +79 -0
- package/dist/esm/EventDispatchPipeline.js.map +1 -0
- package/dist/esm/EventDispatcher.js +89 -0
- package/dist/esm/EventDispatcher.js.map +1 -0
- package/dist/esm/EventIdAugmentor.js +26 -0
- package/dist/esm/EventIdAugmentor.js.map +1 -0
- package/dist/esm/EventStore.js +102 -0
- package/dist/esm/EventStore.js.map +1 -0
- package/dist/esm/SagaEventHandler.js +116 -0
- package/dist/esm/SagaEventHandler.js.map +1 -0
- package/dist/esm/errors/ConcurrencyError.js +17 -0
- package/dist/esm/errors/ConcurrencyError.js.map +1 -0
- package/dist/esm/errors/index.js +2 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/in-memory/InMemoryEventStorage.js +102 -0
- package/dist/esm/in-memory/InMemoryEventStorage.js.map +1 -0
- package/dist/esm/in-memory/InMemoryLock.js +40 -0
- package/dist/esm/in-memory/InMemoryLock.js.map +1 -0
- package/dist/esm/in-memory/InMemoryMessageBus.js +89 -0
- package/dist/esm/in-memory/InMemoryMessageBus.js.map +1 -0
- package/dist/esm/in-memory/InMemorySnapshotStorage.js +64 -0
- package/dist/esm/in-memory/InMemorySnapshotStorage.js.map +1 -0
- package/dist/esm/in-memory/InMemoryView.js +150 -0
- package/dist/esm/in-memory/InMemoryView.js.map +1 -0
- package/dist/esm/in-memory/index.js +6 -0
- package/dist/esm/in-memory/index.js.map +1 -0
- package/dist/esm/in-memory/utils/index.js +2 -0
- package/dist/esm/in-memory/utils/index.js.map +1 -0
- package/dist/esm/in-memory/utils/nextCycle.js +5 -0
- package/dist/esm/in-memory/utils/nextCycle.js.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interfaces/IAggregate.js +2 -0
- package/dist/esm/interfaces/IAggregate.js.map +1 -0
- package/dist/esm/interfaces/IAggregateSnapshotStorage.js +9 -0
- package/dist/esm/interfaces/IAggregateSnapshotStorage.js.map +1 -0
- package/dist/esm/interfaces/ICommand.js +2 -0
- package/dist/esm/interfaces/ICommand.js.map +1 -0
- package/dist/esm/interfaces/ICommandBus.js +2 -0
- package/dist/esm/interfaces/ICommandBus.js.map +1 -0
- package/dist/esm/interfaces/IContainer.js +2 -0
- package/dist/esm/interfaces/IContainer.js.map +1 -0
- package/dist/esm/interfaces/IDispatchPipelineProcessor.js +5 -0
- package/dist/esm/interfaces/IDispatchPipelineProcessor.js.map +1 -0
- package/dist/esm/interfaces/IEvent.js +6 -0
- package/dist/esm/interfaces/IEvent.js.map +1 -0
- package/dist/esm/interfaces/IEventBus.js +5 -0
- package/dist/esm/interfaces/IEventBus.js.map +1 -0
- package/dist/esm/interfaces/IEventDispatcher.js +2 -0
- package/dist/esm/interfaces/IEventDispatcher.js.map +1 -0
- package/dist/esm/interfaces/IEventLocker.js +11 -0
- package/dist/esm/interfaces/IEventLocker.js.map +1 -0
- package/dist/esm/interfaces/IEventReceptor.js +2 -0
- package/dist/esm/interfaces/IEventReceptor.js.map +1 -0
- package/dist/esm/interfaces/IEventSet.js +4 -0
- package/dist/esm/interfaces/IEventSet.js.map +1 -0
- package/dist/esm/interfaces/IEventStorageReader.js +9 -0
- package/dist/esm/interfaces/IEventStorageReader.js.map +1 -0
- package/dist/esm/interfaces/IEventStore.js +2 -0
- package/dist/esm/interfaces/IEventStore.js.map +1 -0
- package/dist/esm/interfaces/IEventStream.js +2 -0
- package/dist/esm/interfaces/IEventStream.js.map +1 -0
- package/dist/esm/interfaces/IIdentifierProvider.js +5 -0
- package/dist/esm/interfaces/IIdentifierProvider.js.map +1 -0
- package/dist/esm/interfaces/ILocker.js +5 -0
- package/dist/esm/interfaces/ILocker.js.map +1 -0
- package/dist/esm/interfaces/ILogger.js +2 -0
- package/dist/esm/interfaces/ILogger.js.map +1 -0
- package/dist/esm/interfaces/IMessage.js +6 -0
- package/dist/esm/interfaces/IMessage.js.map +1 -0
- package/dist/esm/interfaces/IMutableState.js +2 -0
- package/dist/esm/interfaces/IMutableState.js.map +1 -0
- package/dist/esm/interfaces/IObjectStorage.js +2 -0
- package/dist/esm/interfaces/IObjectStorage.js.map +1 -0
- package/dist/esm/interfaces/IObservable.js +7 -0
- package/dist/esm/interfaces/IObservable.js.map +1 -0
- package/dist/esm/interfaces/IObservableQueueProvider.js +5 -0
- package/dist/esm/interfaces/IObservableQueueProvider.js.map +1 -0
- package/dist/esm/interfaces/IObserver.js +2 -0
- package/dist/esm/interfaces/IObserver.js.map +1 -0
- package/dist/esm/interfaces/IProjection.js +2 -0
- package/dist/esm/interfaces/IProjection.js.map +1 -0
- package/dist/esm/interfaces/ISaga.js +2 -0
- package/dist/esm/interfaces/ISaga.js.map +1 -0
- package/dist/esm/interfaces/ISnapshotEvent.js +6 -0
- package/dist/esm/interfaces/ISnapshotEvent.js.map +1 -0
- package/dist/esm/interfaces/IViewLocker.js +17 -0
- package/dist/esm/interfaces/IViewLocker.js.map +1 -0
- package/dist/esm/interfaces/Identifier.js +2 -0
- package/dist/esm/interfaces/Identifier.js.map +1 -0
- package/dist/esm/interfaces/index.js +30 -0
- package/dist/esm/interfaces/index.js.map +1 -0
- package/dist/esm/interfaces/isObject.js +5 -0
- package/dist/esm/interfaces/isObject.js.map +1 -0
- package/dist/esm/rabbitmq/IContainer.js +2 -0
- package/dist/esm/rabbitmq/IContainer.js.map +1 -0
- package/dist/esm/rabbitmq/RabbitMqCommandBus.js +80 -0
- package/dist/esm/rabbitmq/RabbitMqCommandBus.js.map +1 -0
- package/dist/esm/rabbitmq/RabbitMqEventBus.js +117 -0
- package/dist/esm/rabbitmq/RabbitMqEventBus.js.map +1 -0
- package/dist/esm/rabbitmq/RabbitMqGateway.js +541 -0
- package/dist/esm/rabbitmq/RabbitMqGateway.js.map +1 -0
- package/dist/esm/rabbitmq/index.js +5 -0
- package/dist/esm/rabbitmq/index.js.map +1 -0
- package/dist/esm/rabbitmq/utils/index.js +3 -0
- package/dist/esm/rabbitmq/utils/index.js.map +1 -0
- package/dist/esm/rabbitmq/utils/registerExitCleanup.js +24 -0
- package/dist/esm/rabbitmq/utils/registerExitCleanup.js.map +1 -0
- package/dist/esm/rabbitmq/utils/resolveProvider.js +6 -0
- package/dist/esm/rabbitmq/utils/resolveProvider.js.map +1 -0
- package/dist/esm/sqlite/AbstractSqliteAccessor.js +46 -0
- package/dist/esm/sqlite/AbstractSqliteAccessor.js.map +1 -0
- package/dist/esm/sqlite/AbstractSqliteObjectProjection.js +22 -0
- package/dist/esm/sqlite/AbstractSqliteObjectProjection.js.map +1 -0
- package/dist/esm/sqlite/AbstractSqliteView.js +46 -0
- package/dist/esm/sqlite/AbstractSqliteView.js.map +1 -0
- package/dist/esm/sqlite/IContainer.js +2 -0
- package/dist/esm/sqlite/IContainer.js.map +1 -0
- package/dist/esm/sqlite/SqliteEventLocker.js +89 -0
- package/dist/esm/sqlite/SqliteEventLocker.js.map +1 -0
- package/dist/esm/sqlite/SqliteObjectStorage.js +110 -0
- package/dist/esm/sqlite/SqliteObjectStorage.js.map +1 -0
- package/dist/esm/sqlite/SqliteObjectView.js +44 -0
- package/dist/esm/sqlite/SqliteObjectView.js.map +1 -0
- package/dist/esm/sqlite/SqliteProjectionDataParams.js +2 -0
- package/dist/esm/sqlite/SqliteProjectionDataParams.js.map +1 -0
- package/dist/esm/sqlite/SqliteViewLocker.js +115 -0
- package/dist/esm/sqlite/SqliteViewLocker.js.map +1 -0
- package/dist/esm/sqlite/index.js +10 -0
- package/dist/esm/sqlite/index.js.map +1 -0
- package/dist/esm/sqlite/queries/eventLockTableInit.js +11 -0
- package/dist/esm/sqlite/queries/eventLockTableInit.js.map +1 -0
- package/dist/esm/sqlite/queries/index.js +3 -0
- package/dist/esm/sqlite/queries/index.js.map +1 -0
- package/dist/esm/sqlite/queries/viewLockTableInit.js +10 -0
- package/dist/esm/sqlite/queries/viewLockTableInit.js.map +1 -0
- package/dist/esm/sqlite/utils/getEventId.js +7 -0
- package/dist/esm/sqlite/utils/getEventId.js.map +1 -0
- package/dist/esm/sqlite/utils/guid.js +5 -0
- package/dist/esm/sqlite/utils/guid.js.map +1 -0
- package/dist/esm/sqlite/utils/index.js +3 -0
- package/dist/esm/sqlite/utils/index.js.map +1 -0
- package/dist/esm/utils/Deferred.js +34 -0
- package/dist/esm/utils/Deferred.js.map +1 -0
- package/dist/esm/utils/Lock.js +97 -0
- package/dist/esm/utils/Lock.js.map +1 -0
- package/dist/esm/utils/MapAssertable.js +26 -0
- package/dist/esm/utils/MapAssertable.js.map +1 -0
- package/dist/esm/utils/assert.js +70 -0
- package/dist/esm/utils/assert.js.map +1 -0
- package/dist/esm/utils/clone.js +10 -0
- package/dist/esm/utils/clone.js.map +1 -0
- package/dist/esm/utils/extractErrorDetails.js +33 -0
- package/dist/esm/utils/extractErrorDetails.js.map +1 -0
- package/dist/esm/utils/getClassName.js +7 -0
- package/dist/esm/utils/getClassName.js.map +1 -0
- package/dist/esm/utils/getHandler.js +15 -0
- package/dist/esm/utils/getHandler.js.map +1 -0
- package/dist/esm/utils/getMessageHandlerNames.js +27 -0
- package/dist/esm/utils/getMessageHandlerNames.js.map +1 -0
- package/dist/esm/utils/index.js +15 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/isClass.js +5 -0
- package/dist/esm/utils/isClass.js.map +1 -0
- package/dist/esm/utils/sagaId.js +18 -0
- package/dist/esm/utils/sagaId.js.map +1 -0
- package/dist/esm/utils/setupOneTimeEmitterSubscription.js +42 -0
- package/dist/esm/utils/setupOneTimeEmitterSubscription.js.map +1 -0
- package/dist/esm/utils/subscribe.js +40 -0
- package/dist/esm/utils/subscribe.js.map +1 -0
- package/dist/esm/utils/validateHandlers.js +18 -0
- package/dist/esm/utils/validateHandlers.js.map +1 -0
- package/dist/esm/workers/AbstractWorkerProjection.js +52 -0
- package/dist/esm/workers/AbstractWorkerProjection.js.map +1 -0
- package/dist/esm/workers/WorkerProxyProjection.js +105 -0
- package/dist/esm/workers/WorkerProxyProjection.js.map +1 -0
- package/dist/esm/workers/index.js +4 -0
- package/dist/esm/workers/index.js.map +1 -0
- package/dist/esm/workers/interfaces/IProxyProjection.js +2 -0
- package/dist/esm/workers/interfaces/IProxyProjection.js.map +1 -0
- package/dist/esm/workers/interfaces/IWorkerProjection.js +2 -0
- package/dist/esm/workers/interfaces/IWorkerProjection.js.map +1 -0
- package/dist/esm/workers/interfaces/index.js +2 -0
- package/dist/esm/workers/interfaces/index.js.map +1 -0
- package/dist/esm/workers/protocol.js +11 -0
- package/dist/esm/workers/protocol.js.map +1 -0
- package/dist/esm/workers/utils/ProjectionView.js +2 -0
- package/dist/esm/workers/utils/ProjectionView.js.map +1 -0
- package/dist/esm/workers/utils/createWorker.js +51 -0
- package/dist/esm/workers/utils/createWorker.js.map +1 -0
- package/dist/esm/workers/utils/createWorkerInstance.js +23 -0
- package/dist/esm/workers/utils/createWorkerInstance.js.map +1 -0
- package/dist/esm/workers/utils/index.js +5 -0
- package/dist/esm/workers/utils/index.js.map +1 -0
- package/dist/esm/workers/utils/nodeEndpoint.js +5 -0
- package/dist/esm/workers/utils/nodeEndpoint.js.map +1 -0
- package/dist/esm/workers/utils/workerProxyFactory.js +18 -0
- package/dist/esm/workers/utils/workerProxyFactory.js.map +1 -0
- package/dist/types/AbstractAggregate.d.ts +80 -0
- package/dist/types/AbstractProjection.d.ts +77 -0
- package/dist/types/AbstractSaga.d.ts +42 -0
- package/dist/types/AggregateCommandHandler.d.ts +22 -0
- package/dist/types/CommandBus.d.ts +4 -0
- package/dist/types/CqrsContainerBuilder.d.ts +21 -0
- package/dist/types/Event.d.ts +9 -0
- package/dist/types/EventDispatchPipeline.d.ts +16 -0
- package/dist/types/EventDispatcher.d.ts +39 -0
- package/dist/types/EventIdAugmentor.d.ts +12 -0
- package/dist/types/EventStore.d.ts +29 -0
- package/dist/types/SagaEventHandler.d.ts +22 -0
- package/dist/types/errors/ConcurrencyError.d.ts +9 -0
- package/dist/types/errors/index.d.ts +1 -0
- package/dist/types/in-memory/InMemoryEventStorage.d.ts +24 -0
- package/dist/types/in-memory/InMemoryLock.d.ts +23 -0
- package/dist/types/in-memory/InMemoryMessageBus.d.ts +45 -0
- package/dist/types/in-memory/InMemorySnapshotStorage.d.ts +37 -0
- package/dist/types/in-memory/InMemoryView.d.ts +53 -0
- package/dist/types/in-memory/index.d.ts +5 -0
- package/dist/types/in-memory/utils/index.d.ts +1 -0
- package/dist/types/in-memory/utils/nextCycle.d.ts +4 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/interfaces/IAggregate.d.ts +78 -0
- package/dist/types/interfaces/IAggregateSnapshotStorage.d.ts +8 -0
- package/dist/types/interfaces/ICommand.d.ts +2 -0
- package/dist/types/interfaces/ICommandBus.d.ts +15 -0
- package/dist/types/interfaces/IContainer.d.ts +37 -0
- package/dist/types/interfaces/IDispatchPipelineProcessor.d.ts +29 -0
- package/dist/types/interfaces/IEvent.d.ts +7 -0
- package/dist/types/interfaces/IEventBus.d.ts +6 -0
- package/dist/types/interfaces/IEventDispatcher.d.ts +6 -0
- package/dist/types/interfaces/IEventLocker.d.ts +28 -0
- package/dist/types/interfaces/IEventReceptor.d.ts +5 -0
- package/dist/types/interfaces/IEventSet.d.ts +3 -0
- package/dist/types/interfaces/IEventStorageReader.d.ts +48 -0
- package/dist/types/interfaces/IEventStore.d.ts +9 -0
- package/dist/types/interfaces/IEventStream.d.ts +2 -0
- package/dist/types/interfaces/IIdentifierProvider.d.ts +10 -0
- package/dist/types/interfaces/ILocker.d.ts +8 -0
- package/dist/types/interfaces/ILogger.d.ts +22 -0
- package/dist/types/interfaces/IMessage.d.ts +23 -0
- package/dist/types/interfaces/IMutableState.d.ts +14 -0
- package/dist/types/interfaces/IObjectStorage.d.ts +8 -0
- package/dist/types/interfaces/IObservable.d.ts +15 -0
- package/dist/types/interfaces/IObservableQueueProvider.d.ts +8 -0
- package/dist/types/interfaces/IObserver.d.ts +4 -0
- package/dist/types/interfaces/IProjection.d.ts +17 -0
- package/dist/types/interfaces/ISaga.d.ts +38 -0
- package/dist/types/interfaces/ISnapshotEvent.d.ts +7 -0
- package/dist/types/interfaces/IViewLocker.d.ts +34 -0
- package/dist/types/interfaces/Identifier.d.ts +1 -0
- package/dist/types/interfaces/index.d.ts +29 -0
- package/dist/types/interfaces/isObject.d.ts +1 -0
- package/dist/types/rabbitmq/IContainer.d.ts +19 -0
- package/dist/types/rabbitmq/RabbitMqCommandBus.d.ts +38 -0
- package/dist/types/rabbitmq/RabbitMqEventBus.d.ts +44 -0
- package/dist/types/rabbitmq/RabbitMqGateway.d.ts +133 -0
- package/dist/types/rabbitmq/index.d.ts +4 -0
- package/dist/types/rabbitmq/utils/index.d.ts +2 -0
- package/dist/types/rabbitmq/utils/registerExitCleanup.d.ts +10 -0
- package/dist/types/rabbitmq/utils/resolveProvider.d.ts +3 -0
- package/dist/types/sqlite/AbstractSqliteAccessor.d.ts +25 -0
- package/dist/types/sqlite/AbstractSqliteObjectProjection.d.ts +8 -0
- package/dist/types/sqlite/AbstractSqliteView.d.ts +23 -0
- package/dist/types/sqlite/IContainer.d.ts +7 -0
- package/dist/types/sqlite/SqliteEventLocker.d.ts +30 -0
- package/dist/types/sqlite/SqliteObjectStorage.d.ts +17 -0
- package/dist/types/sqlite/SqliteObjectView.d.ts +19 -0
- package/dist/types/sqlite/SqliteProjectionDataParams.d.ts +14 -0
- package/dist/types/sqlite/SqliteViewLocker.d.ts +31 -0
- package/dist/types/sqlite/index.d.ts +9 -0
- package/dist/types/sqlite/queries/eventLockTableInit.d.ts +1 -0
- package/dist/types/sqlite/queries/index.d.ts +2 -0
- package/dist/types/sqlite/queries/viewLockTableInit.d.ts +1 -0
- package/dist/types/sqlite/utils/getEventId.d.ts +5 -0
- package/dist/types/sqlite/utils/guid.d.ts +4 -0
- package/dist/types/sqlite/utils/index.d.ts +2 -0
- package/dist/types/utils/Deferred.d.ts +13 -0
- package/dist/types/utils/Lock.d.ts +30 -0
- package/dist/types/utils/MapAssertable.d.ts +11 -0
- package/dist/types/utils/assert.d.ts +20 -0
- package/dist/types/utils/clone.d.ts +1 -0
- package/dist/types/utils/extractErrorDetails.d.ts +8 -0
- package/dist/types/utils/getClassName.d.ts +4 -0
- package/dist/types/utils/getHandler.d.ts +7 -0
- package/dist/types/utils/getMessageHandlerNames.d.ts +12 -0
- package/dist/types/utils/index.d.ts +14 -0
- package/dist/types/utils/isClass.d.ts +1 -0
- package/dist/types/utils/sagaId.d.ts +6 -0
- package/dist/types/utils/setupOneTimeEmitterSubscription.d.ts +12 -0
- package/dist/types/utils/subscribe.d.ts +9 -0
- package/dist/types/utils/validateHandlers.d.ts +4 -0
- package/dist/types/workers/AbstractWorkerProjection.d.ts +25 -0
- package/dist/types/workers/WorkerProxyProjection.d.ts +25 -0
- package/dist/types/workers/index.d.ts +3 -0
- package/dist/types/workers/interfaces/IProxyProjection.d.ts +15 -0
- package/dist/types/workers/interfaces/IWorkerProjection.d.ts +19 -0
- package/dist/types/workers/interfaces/index.d.ts +2 -0
- package/dist/types/workers/protocol.d.ts +10 -0
- package/dist/types/workers/utils/ProjectionView.d.ts +2 -0
- package/dist/types/workers/utils/createWorker.d.ts +10 -0
- package/dist/types/workers/utils/createWorkerInstance.d.ts +11 -0
- package/dist/types/workers/utils/index.d.ts +5 -0
- package/dist/types/workers/utils/nodeEndpoint.d.ts +2 -0
- package/dist/types/workers/utils/workerProxyFactory.d.ts +14 -0
- package/package.json +129 -29
- package/jsconfig.json +0 -15
- package/src/AbstractAggregate.js +0 -277
- package/src/AbstractProjection.js +0 -192
- package/src/AbstractSaga.js +0 -171
- package/src/AggregateCommandHandler.js +0 -126
- package/src/CommandBus.js +0 -91
- package/src/CqrsContainerBuilder.js +0 -131
- package/src/EventStore.js +0 -457
- package/src/EventStream.js +0 -63
- package/src/SagaEventHandler.js +0 -141
- package/src/index.js +0 -21
- package/src/infrastructure/InMemoryEventStorage.js +0 -76
- package/src/infrastructure/InMemoryMessageBus.js +0 -132
- package/src/infrastructure/InMemorySnapshotStorage.js +0 -40
- package/src/infrastructure/InMemoryView.js +0 -265
- package/src/subscribe.js +0 -48
- package/src/utils/getClassName.js +0 -11
- package/src/utils/getHandledMessageTypes.js +0 -24
- package/src/utils/getHandler.js +0 -21
- package/src/utils/getMessageHandlerNames.js +0 -51
- package/src/utils/index.js +0 -6
- package/src/utils/isClass.js +0 -6
- package/src/utils/nullLogger.js +0 -8
- package/src/utils/validateHandlers.js +0 -25
- package/types/index.d.ts +0 -16
- package/types/interfaces/IAggregate.d.ts +0 -30
- package/types/interfaces/IAggregateSnapshotStorage.d.ts +0 -4
- package/types/interfaces/ICommandBus.d.ts +0 -6
- package/types/interfaces/ICommandHandler.d.ts +0 -3
- package/types/interfaces/IConcurrentView.d.ts +0 -22
- package/types/interfaces/IEventReceptor.d.ts +0 -3
- package/types/interfaces/IEventStorage.d.ts +0 -20
- package/types/interfaces/IEventStore.d.ts +0 -18
- package/types/interfaces/IEventStream.d.ts +0 -13
- package/types/interfaces/ILogger.d.ts +0 -3
- package/types/interfaces/IMessageBus.d.ts +0 -5
- package/types/interfaces/IObserver.d.ts +0 -11
- package/types/interfaces/IProjection.d.ts +0 -10
- package/types/interfaces/ISaga.d.ts +0 -27
- package/types/interfaces/Identifier.d.ts +0 -1
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/* eslint no-return-assign: "off", eqeqeq: "off", require-jsdoc: "off" */
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A simple event storage implementation intended to use for tests only.
|
|
6
|
-
* Storage content resets on each app restart.
|
|
7
|
-
*
|
|
8
|
-
* @class InMemoryEventStorage
|
|
9
|
-
* @implements {IEventStorage}
|
|
10
|
-
*/
|
|
11
|
-
class InMemoryEventStorage {
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
this._nextId = 0;
|
|
15
|
-
this._events = Promise.resolve([]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @param {IEvent[]} events
|
|
20
|
-
* @returns {Promise<void>}
|
|
21
|
-
*/
|
|
22
|
-
commitEvents(events) {
|
|
23
|
-
return this._events = this._events.then(data =>
|
|
24
|
-
data.concat(events));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param {Identifier} aggregateId
|
|
29
|
-
* @param {object} [options]
|
|
30
|
-
* @param {IEvent} [options.snapshot]
|
|
31
|
-
* @returns {Promise<IEventStream>}
|
|
32
|
-
*/
|
|
33
|
-
async getAggregateEvents(aggregateId, { snapshot } = {}) {
|
|
34
|
-
const events = await this._events;
|
|
35
|
-
|
|
36
|
-
if (snapshot)
|
|
37
|
-
return events.filter(e => e.aggregateId == aggregateId && e.aggregateVersion > snapshot.aggregateVersion);
|
|
38
|
-
|
|
39
|
-
return events.filter(e => e.aggregateId == aggregateId);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @param {Identifier} sagaId
|
|
44
|
-
* @param {object} [options]
|
|
45
|
-
* @param {IEvent} [options.beforeEvent]
|
|
46
|
-
* @returns {Promise<IEventStream>}
|
|
47
|
-
*/
|
|
48
|
-
getSagaEvents(sagaId, { beforeEvent }) {
|
|
49
|
-
return this._events.then(events =>
|
|
50
|
-
events.filter(e =>
|
|
51
|
-
e.sagaId == sagaId
|
|
52
|
-
&& e.sagaVersion < beforeEvent.sagaVersion));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @param {string[]} eventTypes
|
|
57
|
-
* @returns {Promise<IEventStream>}
|
|
58
|
-
*/
|
|
59
|
-
getEvents(eventTypes) {
|
|
60
|
-
if (!eventTypes)
|
|
61
|
-
return this._events;
|
|
62
|
-
|
|
63
|
-
return this._events.then(events =>
|
|
64
|
-
events.filter(e => eventTypes.includes(e.type)));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @returns {number}
|
|
69
|
-
*/
|
|
70
|
-
getNewId() {
|
|
71
|
-
this._nextId += 1;
|
|
72
|
-
return this._nextId;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
module.exports = InMemoryEventStorage;
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Default implementation of the message bus. Keeps all subscriptions and messages in memory.
|
|
5
|
-
*
|
|
6
|
-
* @class InMemoryMessageBus
|
|
7
|
-
* @implements {IMessageBus}
|
|
8
|
-
*/
|
|
9
|
-
class InMemoryMessageBus {
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Indicates that message bus supports named queue subscriptions
|
|
13
|
-
*
|
|
14
|
-
* @type {boolean}
|
|
15
|
-
* @readonly
|
|
16
|
-
* @static
|
|
17
|
-
*/
|
|
18
|
-
static get supportsQueues() {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates an instance of InMemoryMessageBus
|
|
24
|
-
* @param {object} [options]
|
|
25
|
-
* @param {string} [options.name]
|
|
26
|
-
* @param {boolean} [options.uniqueEventHandlers]
|
|
27
|
-
*/
|
|
28
|
-
constructor({ name, uniqueEventHandlers = !!name } = {}) {
|
|
29
|
-
/** @type {Map<string, Set<IMessageHandler>>} */
|
|
30
|
-
this._handlers = new Map();
|
|
31
|
-
|
|
32
|
-
this._name = name;
|
|
33
|
-
this._uniqueEventHandlers = uniqueEventHandlers;
|
|
34
|
-
|
|
35
|
-
/** @type {Map<string, InMemoryMessageBus>} */
|
|
36
|
-
this._queues = new Map();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Subscribe to message type
|
|
41
|
-
*
|
|
42
|
-
* @param {string} messageType
|
|
43
|
-
* @param {IMessageHandler} handler
|
|
44
|
-
*/
|
|
45
|
-
on(messageType, handler) {
|
|
46
|
-
if (typeof messageType !== 'string' || !messageType.length) throw new TypeError('messageType argument must be a non-empty String');
|
|
47
|
-
if (typeof handler !== 'function') throw new TypeError('handler argument must be a Function');
|
|
48
|
-
if (arguments.length !== 2) throw new TypeError(`2 arguments are expected, but ${arguments.length} received`);
|
|
49
|
-
|
|
50
|
-
// Events published to a named queue must be consumed only once.
|
|
51
|
-
// For example, for sending a welcome email, NotificationReceptor will subscribe to "notifications:userCreated".
|
|
52
|
-
// Since we use an in-memory bus, there is no need to track message handling by multiple distributed subscribers,
|
|
53
|
-
// and we only need to make sure that no more than 1 such subscriber will be created
|
|
54
|
-
if (!this._handlers.has(messageType))
|
|
55
|
-
this._handlers.set(messageType, new Set());
|
|
56
|
-
else if (this._uniqueEventHandlers)
|
|
57
|
-
throw new Error(`"${messageType}" handler is already set up on the "${this._name}" queue`);
|
|
58
|
-
|
|
59
|
-
this._handlers.get(messageType).add(handler);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Get or create a named queue.
|
|
64
|
-
* Named queues support only one handler per event type.
|
|
65
|
-
*
|
|
66
|
-
* @param {string} name
|
|
67
|
-
* @returns {IObservable}
|
|
68
|
-
*/
|
|
69
|
-
queue(name) {
|
|
70
|
-
if (!this._queues.has(name))
|
|
71
|
-
this._queues.set(name, new InMemoryMessageBus({ name, uniqueEventHandlers: true }));
|
|
72
|
-
|
|
73
|
-
return this._queues.get(name);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Remove subscription
|
|
78
|
-
*
|
|
79
|
-
* @param {string} messageType
|
|
80
|
-
* @param {IMessageHandler} handler
|
|
81
|
-
*/
|
|
82
|
-
off(messageType, handler) {
|
|
83
|
-
if (typeof messageType !== 'string' || !messageType.length) throw new TypeError('messageType argument must be a non-empty String');
|
|
84
|
-
if (typeof handler !== 'function') throw new TypeError('handler argument must be a Function');
|
|
85
|
-
if (arguments.length !== 2) throw new TypeError(`2 arguments are expected, but ${arguments.length} received`);
|
|
86
|
-
if (!this._handlers.has(messageType)) throw new Error(`No ${messageType} subscribers found`);
|
|
87
|
-
|
|
88
|
-
this._handlers.get(messageType).delete(handler);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Send command to exactly 1 command handler
|
|
93
|
-
*
|
|
94
|
-
* @param {ICommand} command
|
|
95
|
-
* @returns {Promise<any>}
|
|
96
|
-
*/
|
|
97
|
-
async send(command) {
|
|
98
|
-
if (typeof command !== 'object' || !command) throw new TypeError('command argument must be an Object');
|
|
99
|
-
if (typeof command.type !== 'string' || !command.type.length) throw new TypeError('command.type argument must be a non-empty String');
|
|
100
|
-
|
|
101
|
-
const handlers = this._handlers.get(command.type);
|
|
102
|
-
if (!handlers || !handlers.size)
|
|
103
|
-
throw new Error(`No '${command.type}' subscribers found`);
|
|
104
|
-
if (handlers.size > 1)
|
|
105
|
-
throw new Error(`More than one '${command.type}' subscriber found`);
|
|
106
|
-
|
|
107
|
-
const commandHandler = handlers.values().next().value;
|
|
108
|
-
|
|
109
|
-
return commandHandler(command);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Publish event to all subscribers (if any)
|
|
114
|
-
*
|
|
115
|
-
* @param {IEvent} event
|
|
116
|
-
* @returns {Promise<any>}
|
|
117
|
-
*/
|
|
118
|
-
async publish(event) {
|
|
119
|
-
if (typeof event !== 'object' || !event) throw new TypeError('event argument must be an Object');
|
|
120
|
-
if (typeof event.type !== 'string' || !event.type.length) throw new TypeError('event.type argument must be a non-empty String');
|
|
121
|
-
|
|
122
|
-
const handlers = [
|
|
123
|
-
...this._handlers.get(event.type) || [],
|
|
124
|
-
...Array.from(this._queues.values()).map(namedQueue =>
|
|
125
|
-
e => namedQueue.publish(e))
|
|
126
|
-
];
|
|
127
|
-
|
|
128
|
-
return Promise.all(handlers.map(handler => handler(event)));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
module.exports = InMemoryMessageBus;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* In-memory storage for aggregate snapshots.
|
|
5
|
-
* Storage content resets on app restart
|
|
6
|
-
*
|
|
7
|
-
* @class InMemorySnapshotStorage
|
|
8
|
-
* @implements {IAggregateSnapshotStorage}
|
|
9
|
-
*/
|
|
10
|
-
class InMemorySnapshotStorage {
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates an instance of InMemorySnapshotStorage
|
|
14
|
-
*/
|
|
15
|
-
constructor() {
|
|
16
|
-
/** @type {Map<Identifier, IEvent>} */
|
|
17
|
-
this._snapshots = new Map();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get latest aggregate snapshot
|
|
22
|
-
*
|
|
23
|
-
* @param {Identifier} aggregateId
|
|
24
|
-
* @returns {Promise<IEvent>}
|
|
25
|
-
*/
|
|
26
|
-
async getAggregateSnapshot(aggregateId) {
|
|
27
|
-
return this._snapshots.get(aggregateId);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Save new aggregate snapshot
|
|
32
|
-
*
|
|
33
|
-
* @param {IEvent} snapshotEvent
|
|
34
|
-
*/
|
|
35
|
-
async saveAggregateSnapshot(snapshotEvent) {
|
|
36
|
-
this._snapshots.set(snapshotEvent.aggregateId, snapshotEvent);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = InMemorySnapshotStorage;
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const nextCycle = () => new Promise(setImmediate);
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Update given value with an update Cb and return updated value.
|
|
7
|
-
* Wrapper is needed for backward compatibility with update methods that were modifying the passed in objects directly
|
|
8
|
-
*
|
|
9
|
-
* @template TObjectValue
|
|
10
|
-
* @param {TObjectValue} view
|
|
11
|
-
* @param {function (TObjectValue): TObjectValue} update
|
|
12
|
-
* @returns {TObjectValue}
|
|
13
|
-
*/
|
|
14
|
-
const applyUpdate = (view, update) => {
|
|
15
|
-
const valueReturnedByUpdate = update(view);
|
|
16
|
-
return valueReturnedByUpdate === undefined ?
|
|
17
|
-
view :
|
|
18
|
-
valueReturnedByUpdate;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* In-memory Projection View, which suspends get()'s until it is ready
|
|
23
|
-
*
|
|
24
|
-
* @class InMemoryView
|
|
25
|
-
* @template TRecord
|
|
26
|
-
*/
|
|
27
|
-
class InMemoryView {
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Whether the view is restored
|
|
31
|
-
*
|
|
32
|
-
* @type {boolean}
|
|
33
|
-
*/
|
|
34
|
-
get ready() {
|
|
35
|
-
return this._ready;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Number of records in the View
|
|
40
|
-
*
|
|
41
|
-
* @type {number}
|
|
42
|
-
* @readonly
|
|
43
|
-
*/
|
|
44
|
-
get size() {
|
|
45
|
-
return this._map.size;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Creates an instance of InMemoryView
|
|
50
|
-
*/
|
|
51
|
-
constructor() {
|
|
52
|
-
/** @type {Map<Identifier, TRecord>} */
|
|
53
|
-
this._map = new Map();
|
|
54
|
-
|
|
55
|
-
// explicitly bind the `get` method to this object for easier using in Promises
|
|
56
|
-
Object.defineProperty(this, this.get.name, {
|
|
57
|
-
value: this.get.bind(this)
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Lock the view to prevent concurrent modifications
|
|
63
|
-
*
|
|
64
|
-
* @returns {Promise<void>}
|
|
65
|
-
*/
|
|
66
|
-
async lock() {
|
|
67
|
-
if (this.ready === false)
|
|
68
|
-
await this.once('ready');
|
|
69
|
-
|
|
70
|
-
this._lockPromise = new Promise(resolve => {
|
|
71
|
-
this._unlock = resolve;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
this._ready = false;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Release the lock
|
|
79
|
-
*/
|
|
80
|
-
unlock() {
|
|
81
|
-
this._ready = true;
|
|
82
|
-
if (typeof this._unlock === 'function')
|
|
83
|
-
this._unlock();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Check if view contains a record with a given key.
|
|
88
|
-
* This is the only synchronous method, so make sure to check the `ready` flag, if necessary
|
|
89
|
-
*
|
|
90
|
-
* @deprecated Use `async get()` instead
|
|
91
|
-
*
|
|
92
|
-
* @param {Identifier} key
|
|
93
|
-
* @returns {boolean}
|
|
94
|
-
*/
|
|
95
|
-
has(key) {
|
|
96
|
-
return this._map.has(key);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Get record with a given key; await until the view is restored
|
|
101
|
-
*
|
|
102
|
-
* @param {Identifier} key
|
|
103
|
-
* @param {object} [options]
|
|
104
|
-
* @param {boolean} [options.nowait] Skip waiting until the view is restored/ready
|
|
105
|
-
* @returns {Promise<TRecord>}
|
|
106
|
-
*/
|
|
107
|
-
async get(key, options) {
|
|
108
|
-
if (!key) throw new TypeError('key argument required');
|
|
109
|
-
|
|
110
|
-
if (!this._ready && !(options && options.nowait))
|
|
111
|
-
await this.once('ready');
|
|
112
|
-
|
|
113
|
-
await nextCycle();
|
|
114
|
-
|
|
115
|
-
return this._map.get(key);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Get all records matching an optional filter
|
|
120
|
-
*
|
|
121
|
-
* @param {function(TRecord, Identifier): boolean} [filter]
|
|
122
|
-
*/
|
|
123
|
-
async getAll(filter) {
|
|
124
|
-
if (filter && typeof filter !== 'function')
|
|
125
|
-
throw new TypeError('filter argument, when defined, must be a Function');
|
|
126
|
-
|
|
127
|
-
if (!this._ready)
|
|
128
|
-
await this.once('ready');
|
|
129
|
-
|
|
130
|
-
await nextCycle();
|
|
131
|
-
|
|
132
|
-
const r = [];
|
|
133
|
-
for (const entry of this._map.entries()) {
|
|
134
|
-
if (!filter || filter(entry[1], entry[0]))
|
|
135
|
-
r.push(entry);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return r;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Create record with a given key and value
|
|
143
|
-
*
|
|
144
|
-
* @param {Identifier} key
|
|
145
|
-
* @param {TRecord} [value]
|
|
146
|
-
*/
|
|
147
|
-
create(key, value = {}) {
|
|
148
|
-
if (!key) throw new TypeError('key argument required');
|
|
149
|
-
if (typeof value === 'function') throw new TypeError('value argument must be an instance of an Object');
|
|
150
|
-
|
|
151
|
-
if (this._map.has(key))
|
|
152
|
-
throw new Error(`Key '${key}' already exists`);
|
|
153
|
-
|
|
154
|
-
this._map.set(key, value);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Update existing view record
|
|
159
|
-
*
|
|
160
|
-
* @param {Identifier} key
|
|
161
|
-
* @param {function(TRecord): TRecord} update
|
|
162
|
-
*/
|
|
163
|
-
update(key, update) {
|
|
164
|
-
if (!key) throw new TypeError('key argument required');
|
|
165
|
-
if (typeof update !== 'function') throw new TypeError('update argument must be a Function');
|
|
166
|
-
|
|
167
|
-
if (!this._map.has(key))
|
|
168
|
-
throw new Error(`Key '${key}' does not exist`);
|
|
169
|
-
|
|
170
|
-
this._update(key, update);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Update existing view record or create new
|
|
175
|
-
*
|
|
176
|
-
* @param {Identifier} key
|
|
177
|
-
* @param {function(TRecord): TRecord} update
|
|
178
|
-
*/
|
|
179
|
-
updateEnforcingNew(key, update) {
|
|
180
|
-
if (!key) throw new TypeError('key argument required');
|
|
181
|
-
if (typeof update !== 'function') throw new TypeError('update argument must be a Function');
|
|
182
|
-
|
|
183
|
-
if (!this._map.has(key))
|
|
184
|
-
return this.create(key, applyUpdate(undefined, update));
|
|
185
|
-
|
|
186
|
-
return this._update(key, update);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Update all records that match filter criteria
|
|
191
|
-
*
|
|
192
|
-
* @param {function(TRecord): boolean} [filter]
|
|
193
|
-
* @param {function(TRecord): TRecord} update
|
|
194
|
-
*/
|
|
195
|
-
updateAll(filter, update) {
|
|
196
|
-
if (filter && typeof filter !== 'function') throw new TypeError('filter argument, when specified, must be a Function');
|
|
197
|
-
if (typeof update !== 'function') throw new TypeError('update argument must be a Function');
|
|
198
|
-
|
|
199
|
-
for (const [key, value] of this._map) {
|
|
200
|
-
if (!filter || filter(value))
|
|
201
|
-
this._update(key, update);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Update existing record
|
|
207
|
-
*
|
|
208
|
-
* @private
|
|
209
|
-
* @param {Identifier} key
|
|
210
|
-
* @param {function(TRecord): TRecord} update
|
|
211
|
-
*/
|
|
212
|
-
_update(key, update) {
|
|
213
|
-
const value = this._map.get(key);
|
|
214
|
-
this._map.set(key, applyUpdate(value, update));
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Delete record
|
|
219
|
-
*
|
|
220
|
-
* @param {Identifier} key
|
|
221
|
-
*/
|
|
222
|
-
delete(key) {
|
|
223
|
-
if (!key) throw new TypeError('key argument required');
|
|
224
|
-
|
|
225
|
-
this._map.delete(key);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Delete all records that match filter criteria
|
|
230
|
-
*
|
|
231
|
-
* @param {function(TRecord): boolean} [filter]
|
|
232
|
-
*/
|
|
233
|
-
deleteAll(filter) {
|
|
234
|
-
if (filter && typeof filter !== 'function') throw new TypeError('filter argument, when specified, must be a Function');
|
|
235
|
-
|
|
236
|
-
for (const [key, value] of this._map) {
|
|
237
|
-
if (!filter || filter(value))
|
|
238
|
-
this._map.delete(key);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Create a Promise which will resolve to a first emitted event of a given type
|
|
244
|
-
*
|
|
245
|
-
* @param {"ready"} eventType
|
|
246
|
-
* @returns {Promise<any>}
|
|
247
|
-
*/
|
|
248
|
-
once(eventType) {
|
|
249
|
-
if (eventType !== 'ready')
|
|
250
|
-
throw new TypeError(`Unexpected event type: ${eventType}`);
|
|
251
|
-
|
|
252
|
-
return this._lockPromise;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Get view summary as string
|
|
257
|
-
*
|
|
258
|
-
* @returns {string}
|
|
259
|
-
*/
|
|
260
|
-
toString() {
|
|
261
|
-
return `${this.size} record${this.size !== 1 ? 's' : ''}`;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
module.exports = InMemoryView;
|
package/src/subscribe.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { getHandler } = require('./utils');
|
|
4
|
-
const getHandledMessageTypes = require('./utils/getHandledMessageTypes');
|
|
5
|
-
|
|
6
|
-
const unique = arr => [...new Set(arr)];
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Subscribe observer to observable
|
|
10
|
-
*
|
|
11
|
-
* @param {IObservable} observable
|
|
12
|
-
* @param {object} observer
|
|
13
|
-
* @param {object} [options]
|
|
14
|
-
* @param {string[]} [options.messageTypes]
|
|
15
|
-
* @param {IMessageHandler} [options.masterHandler]
|
|
16
|
-
* @param {string} [options.queueName]
|
|
17
|
-
*/
|
|
18
|
-
function subscribe(observable, observer, options = {}) {
|
|
19
|
-
if (typeof observable !== 'object' || !observable)
|
|
20
|
-
throw new TypeError('observable argument must be an Object');
|
|
21
|
-
if (typeof observable.on !== 'function')
|
|
22
|
-
throw new TypeError('observable.on must be a Function');
|
|
23
|
-
if (typeof observer !== 'object' || !observer)
|
|
24
|
-
throw new TypeError('observer argument must be an Object');
|
|
25
|
-
|
|
26
|
-
const { masterHandler, messageTypes, queueName } = options;
|
|
27
|
-
if (masterHandler && typeof masterHandler !== 'function')
|
|
28
|
-
throw new TypeError('masterHandler parameter, when provided, must be a Function');
|
|
29
|
-
if (queueName && typeof observable.queue !== 'function')
|
|
30
|
-
throw new TypeError('observable.queue, when queueName is specified, must be a Function');
|
|
31
|
-
|
|
32
|
-
const subscribeTo = messageTypes || getHandledMessageTypes(observer);
|
|
33
|
-
if (!Array.isArray(subscribeTo))
|
|
34
|
-
throw new TypeError('either options.messageTypes, observer.handles or ObserverType.handles is required');
|
|
35
|
-
|
|
36
|
-
for (const messageType of unique(subscribeTo)) {
|
|
37
|
-
const handler = masterHandler || getHandler(observer, messageType);
|
|
38
|
-
if (!handler)
|
|
39
|
-
throw new Error(`'${messageType}' handler is not defined or not a function`);
|
|
40
|
-
|
|
41
|
-
if (queueName)
|
|
42
|
-
observable.queue(queueName).on(messageType, handler);
|
|
43
|
-
else
|
|
44
|
-
observable.on(messageType, handler);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
module.exports = subscribe;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const getMessageHandlerNames = require('./getMessageHandlerNames');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Get a list of message types handled by observer
|
|
7
|
-
* @param {object | function} observerInstanceOrClass
|
|
8
|
-
* @returns {string[]}
|
|
9
|
-
*/
|
|
10
|
-
function getHandledMessageTypes(observerInstanceOrClass) {
|
|
11
|
-
if (!observerInstanceOrClass)
|
|
12
|
-
throw new TypeError('observerInstanceOrClass argument required');
|
|
13
|
-
|
|
14
|
-
if (observerInstanceOrClass.handles)
|
|
15
|
-
return observerInstanceOrClass.handles;
|
|
16
|
-
|
|
17
|
-
const prototype = Object.getPrototypeOf(observerInstanceOrClass);
|
|
18
|
-
if (prototype && prototype.constructor && prototype.constructor.handles)
|
|
19
|
-
return prototype.constructor.handles;
|
|
20
|
-
|
|
21
|
-
return getMessageHandlerNames(observerInstanceOrClass);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = getHandledMessageTypes;
|
package/src/utils/getHandler.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Gets a handler for a specific message type, prefers a public (w\o _ prefix) method, if available
|
|
5
|
-
* @param {Object} context
|
|
6
|
-
* @param {String} messageType
|
|
7
|
-
* @return {IMessageHandler}
|
|
8
|
-
*/
|
|
9
|
-
module.exports = function getHandler(context, messageType) {
|
|
10
|
-
if (!context || typeof context !== 'object') throw new TypeError('context argument required');
|
|
11
|
-
if (typeof messageType !== 'string' || !messageType.length) throw new TypeError('messageType argument must be a non-empty string');
|
|
12
|
-
|
|
13
|
-
if (messageType in context && typeof context[messageType] === 'function')
|
|
14
|
-
return context[messageType].bind(context);
|
|
15
|
-
|
|
16
|
-
const privateHandlerName = `_${messageType}`;
|
|
17
|
-
if (privateHandlerName in context && typeof context[privateHandlerName] === 'function')
|
|
18
|
-
return context[privateHandlerName].bind(context);
|
|
19
|
-
|
|
20
|
-
return null;
|
|
21
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const KNOWN_METHOD_NAMES = new Set([
|
|
4
|
-
'subscribe'
|
|
5
|
-
]);
|
|
6
|
-
|
|
7
|
-
function getInheritedPropertyNames(prototype) {
|
|
8
|
-
const parentPrototype = prototype && Object.getPrototypeOf(prototype);
|
|
9
|
-
if (!parentPrototype)
|
|
10
|
-
return [];
|
|
11
|
-
|
|
12
|
-
const propDescriptors = Object.getOwnPropertyDescriptors(parentPrototype);
|
|
13
|
-
const propNames = Object.keys(propDescriptors);
|
|
14
|
-
|
|
15
|
-
return [
|
|
16
|
-
...propNames,
|
|
17
|
-
...getInheritedPropertyNames(parentPrototype)
|
|
18
|
-
];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Get message handler names from a command/event handler class.
|
|
23
|
-
* Assumes all private method names start from underscore ("_").
|
|
24
|
-
*
|
|
25
|
-
* @param {any} observerInstanceOrClass Command or event handler class
|
|
26
|
-
* @returns {string[]}
|
|
27
|
-
*/
|
|
28
|
-
function getMessageHandlerNames(observerInstanceOrClass) {
|
|
29
|
-
if (!observerInstanceOrClass)
|
|
30
|
-
throw new TypeError('observerInstanceOrClass argument required');
|
|
31
|
-
|
|
32
|
-
const prototype = typeof observerInstanceOrClass === 'function' ?
|
|
33
|
-
observerInstanceOrClass.prototype :
|
|
34
|
-
Object.getPrototypeOf(observerInstanceOrClass);
|
|
35
|
-
|
|
36
|
-
if (!prototype)
|
|
37
|
-
throw new TypeError('prototype cannot be resolved');
|
|
38
|
-
|
|
39
|
-
const inheritedProperties = new Set(getInheritedPropertyNames(prototype));
|
|
40
|
-
|
|
41
|
-
const propDescriptors = Object.getOwnPropertyDescriptors(prototype);
|
|
42
|
-
const propNames = Object.keys(propDescriptors);
|
|
43
|
-
|
|
44
|
-
return propNames.filter(key =>
|
|
45
|
-
!key.startsWith('_') &&
|
|
46
|
-
!inheritedProperties.has(key) &&
|
|
47
|
-
!KNOWN_METHOD_NAMES.has(key) &&
|
|
48
|
-
typeof propDescriptors[key].value === 'function');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = getMessageHandlerNames;
|
package/src/utils/index.js
DELETED
package/src/utils/isClass.js
DELETED