@event-driven-io/emmett 0.43.0-beta.12 → 0.43.0-beta.13
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/README.md +591 -0
- package/dist/index.cjs +145 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -14
- package/dist/index.d.ts +30 -14
- package/dist/index.js +83 -37
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -292,14 +292,14 @@ declare const MessageProcessor: {
|
|
|
292
292
|
result: {
|
|
293
293
|
skip: (options?: {
|
|
294
294
|
reason?: string;
|
|
295
|
-
}) =>
|
|
295
|
+
}) => SingleMessageHandlerResult;
|
|
296
296
|
stop: (options?: {
|
|
297
297
|
reason?: string;
|
|
298
298
|
error?: EmmettError;
|
|
299
|
-
}) =>
|
|
299
|
+
}) => SingleMessageHandlerResult;
|
|
300
300
|
};
|
|
301
301
|
};
|
|
302
|
-
type MessageProcessingScope<HandlerContext extends DefaultRecord | undefined = undefined> = <Result =
|
|
302
|
+
type MessageProcessingScope<HandlerContext extends DefaultRecord | undefined = undefined> = <Result = SingleMessageHandlerResult>(handler: (context: HandlerContext) => Result | Promise<Result>, partialContext: Partial<HandlerContext>) => Result | Promise<Result>;
|
|
303
303
|
type Checkpointer<MessageType extends AnyMessage = AnyMessage, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends DefaultRecord = DefaultRecord> = {
|
|
304
304
|
read: ReadProcessorCheckpoint<HandlerContext>;
|
|
305
305
|
store: StoreProcessorCheckpoint<MessageType, MessageMetadataType, HandlerContext>;
|
|
@@ -347,7 +347,7 @@ type ProjectorOptions<EventType extends AnyEvent = AnyEvent, MessageMetadataType
|
|
|
347
347
|
truncateOnStart?: boolean;
|
|
348
348
|
projection: ProjectionDefinition<EventType, MessageMetadataType, HandlerContext, EventPayloadType>;
|
|
349
349
|
};
|
|
350
|
-
declare const defaultProcessingMessageProcessingScope: <HandlerContext = never, Result =
|
|
350
|
+
declare const defaultProcessingMessageProcessingScope: <HandlerContext = never, Result = SingleMessageHandlerResult>(handler: (context: HandlerContext) => Result | Promise<Result>, partialContext: Partial<HandlerContext>) => Result | Promise<Result>;
|
|
351
351
|
type ProcessorCheckpoint = Brand<string, 'ProcessorCheckpoint'>;
|
|
352
352
|
declare const bigIntProcessorCheckpoint: (value: bigint) => ProcessorCheckpoint;
|
|
353
353
|
declare const parseBigIntProcessorCheckpoint: (value: ProcessorCheckpoint) => bigint;
|
|
@@ -473,28 +473,42 @@ type AnyReadEventMetadata = AnyRecordedMessageMetadata;
|
|
|
473
473
|
type ReadEventMetadataWithGlobalPosition = RecordedMessageMetadataWithGlobalPosition;
|
|
474
474
|
type ReadEventMetadataWithoutGlobalPosition = RecordedMessageMetadataWithoutGlobalPosition;
|
|
475
475
|
|
|
476
|
-
type SingleRawMessageHandlerWithoutContext<MessageType extends Message = AnyMessage> = (message: MessageType) => Promise<
|
|
477
|
-
type SingleRecordedMessageHandlerWithoutContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = (message: RecordedMessage<MessageType, MessageMetaDataType>) => Promise<
|
|
476
|
+
type SingleRawMessageHandlerWithoutContext<MessageType extends Message = AnyMessage> = (message: MessageType) => Promise<SingleMessageHandlerResult> | SingleMessageHandlerResult;
|
|
477
|
+
type SingleRecordedMessageHandlerWithoutContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = (message: RecordedMessage<MessageType, MessageMetaDataType>) => Promise<SingleMessageHandlerResult> | SingleMessageHandlerResult;
|
|
478
478
|
type SingleMessageHandlerWithoutContext<MessageType extends AnyMessage = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = never> = SingleRawMessageHandlerWithoutContext<MessageType> | SingleRecordedMessageHandlerWithoutContext<MessageType, MessageMetaDataType>;
|
|
479
|
-
type SingleRawMessageHandlerWithContext<MessageType extends Message = AnyMessage, HandlerContext extends DefaultRecord | undefined = undefined> = (message: MessageType, context: HandlerContext) => Promise<
|
|
480
|
-
type SingleRecordedMessageHandlerWithContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = (message: RecordedMessage<MessageType, MessageMetaDataType>, context: HandlerContext) => Promise<
|
|
479
|
+
type SingleRawMessageHandlerWithContext<MessageType extends Message = AnyMessage, HandlerContext extends DefaultRecord | undefined = undefined> = (message: MessageType, context: HandlerContext) => Promise<SingleMessageHandlerResult> | SingleMessageHandlerResult;
|
|
480
|
+
type SingleRecordedMessageHandlerWithContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = (message: RecordedMessage<MessageType, MessageMetaDataType>, context: HandlerContext) => Promise<SingleMessageHandlerResult> | SingleMessageHandlerResult;
|
|
481
481
|
type SingleMessageHandlerWithContext<MessageType extends AnyMessage = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = never, HandlerContext extends DefaultRecord = DefaultRecord> = SingleRawMessageHandlerWithContext<MessageType, HandlerContext> | SingleRecordedMessageHandlerWithContext<MessageType, MessageMetaDataType, HandlerContext>;
|
|
482
482
|
type SingleMessageHandler<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = HandlerContext extends DefaultRecord ? SingleMessageHandlerWithContext<MessageType, MessageMetaDataType, HandlerContext> : SingleMessageHandlerWithoutContext<MessageType, MessageMetaDataType>;
|
|
483
|
-
type BatchRawMessageHandlerWithoutContext<MessageType extends Message = AnyMessage> = (messages: MessageType[]) => Promise<
|
|
484
|
-
type BatchRecordedMessageHandlerWithoutContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = (messages: RecordedMessage<MessageType, MessageMetaDataType>[]) => Promise<
|
|
483
|
+
type BatchRawMessageHandlerWithoutContext<MessageType extends Message = AnyMessage> = (messages: MessageType[]) => Promise<BatchMessageHandlerResult> | BatchMessageHandlerResult;
|
|
484
|
+
type BatchRecordedMessageHandlerWithoutContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = (messages: RecordedMessage<MessageType, MessageMetaDataType>[]) => Promise<BatchMessageHandlerResult> | BatchMessageHandlerResult;
|
|
485
485
|
type BatchMessageHandlerWithoutContext<MessageType extends AnyMessage = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = BatchRawMessageHandlerWithoutContext<MessageType> | BatchRecordedMessageHandlerWithoutContext<MessageType, MessageMetaDataType>;
|
|
486
|
-
type BatchRawMessageHandlerWithContext<MessageType extends Message = AnyMessage, HandlerContext extends DefaultRecord | undefined = undefined> = (messages: MessageType[], context: HandlerContext) => Promise<
|
|
487
|
-
type BatchRecordedMessageHandlerWithContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord = DefaultRecord> = (messages: RecordedMessage<MessageType, MessageMetaDataType>[], context: HandlerContext) => Promise<
|
|
486
|
+
type BatchRawMessageHandlerWithContext<MessageType extends Message = AnyMessage, HandlerContext extends DefaultRecord | undefined = undefined> = (messages: MessageType[], context: HandlerContext) => Promise<BatchMessageHandlerResult> | BatchMessageHandlerResult;
|
|
487
|
+
type BatchRecordedMessageHandlerWithContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord = DefaultRecord> = (messages: RecordedMessage<MessageType, MessageMetaDataType>[], context: HandlerContext) => Promise<BatchMessageHandlerResult> | BatchMessageHandlerResult;
|
|
488
488
|
type BatchMessageHandlerWithContext<MessageType extends AnyMessage = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord = DefaultRecord> = BatchRawMessageHandlerWithContext<MessageType, HandlerContext> | BatchRecordedMessageHandlerWithContext<MessageType, MessageMetaDataType, HandlerContext>;
|
|
489
489
|
type BatchMessageHandler<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = HandlerContext extends DefaultRecord ? BatchMessageHandlerWithContext<MessageType, MessageMetaDataType, HandlerContext> : BatchMessageHandlerWithoutContext<MessageType, MessageMetaDataType>;
|
|
490
490
|
type MessageHandler<MessageType extends Message = Message, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = (HandlerContext extends DefaultRecord ? SingleMessageHandler<MessageType, MessageMetaDataType, HandlerContext> : SingleMessageHandler<MessageType, MessageMetaDataType>) | (HandlerContext extends DefaultRecord ? BatchMessageHandler<MessageType, MessageMetaDataType, HandlerContext> : BatchMessageHandler<MessageType, MessageMetaDataType>);
|
|
491
|
-
type
|
|
491
|
+
type SingleMessageHandlerResult = void | {
|
|
492
|
+
type: 'ACK';
|
|
493
|
+
} | {
|
|
494
|
+
type: 'SKIP';
|
|
495
|
+
reason?: string;
|
|
496
|
+
} | {
|
|
497
|
+
type: 'STOP';
|
|
498
|
+
reason?: string;
|
|
499
|
+
error?: EmmettError;
|
|
500
|
+
};
|
|
501
|
+
type BatchMessageHandlerResult = void | {
|
|
502
|
+
type: 'ACK';
|
|
503
|
+
} | {
|
|
492
504
|
type: 'SKIP';
|
|
493
505
|
reason?: string;
|
|
506
|
+
lastSuccessfulMessage: AnyRecordedMessage;
|
|
494
507
|
} | {
|
|
495
508
|
type: 'STOP';
|
|
496
509
|
reason?: string;
|
|
497
510
|
error?: EmmettError;
|
|
511
|
+
lastSuccessfulMessage?: AnyRecordedMessage;
|
|
498
512
|
};
|
|
499
513
|
|
|
500
514
|
type Decider<State, CommandType extends Command, StreamEvent extends Event> = {
|
|
@@ -960,6 +974,8 @@ declare const upcastRecordedMessages: <MessageType extends AnyMessage, MessagePa
|
|
|
960
974
|
upcast?: MessageUpcast<MessageType, MessagePayloadType, RecordedMessageMetadataType>;
|
|
961
975
|
}) => RecordedMessage<MessageType, RecordedMessageMetadataType>[];
|
|
962
976
|
|
|
977
|
+
declare function reduceAsync<T, R>(items: T[], fn: (accumulator: R, item: T, index: number) => Promise<R>, initial: R): Promise<R>;
|
|
978
|
+
|
|
963
979
|
type Closeable = {
|
|
964
980
|
/**
|
|
965
981
|
* Gracefully cleans up managed resources
|
|
@@ -1240,4 +1256,4 @@ declare const WorkflowHandler: <Input extends AnyEvent | AnyCommand, State, Outp
|
|
|
1240
1256
|
retry?: WorkflowHandlerRetryOptions;
|
|
1241
1257
|
}) => <Store extends EventStore>(store: Store, message: Input | RecordedMessage<Input, MessageMetadataType>, handleOptions?: WorkflowHandleOptions<Store>) => Promise<WorkflowHandlerResult<Output, Store>>;
|
|
1242
1258
|
|
|
1243
|
-
export { type AcquireLockOptions, type AfterEventStoreCommitHandler, type AggregateStreamOptions, type AggregateStreamResult, type AggregateStreamResultOfEventStore, type AggregateStreamResultWithGlobalPosition, type AnyCommand, type AnyEvent, type AnyMessage, type AnyReadEvent, type AnyReadEventMetadata, type AnyRecord, type AnyRecordedMessage, type AnyRecordedMessageMetadata, type AppendStreamResultOfEventStore, type AppendToStreamOptions, type AppendToStreamResult, type AppendToStreamResultWithGlobalPosition, type ArgumentMatcher, AssertionError, type AsyncAwaiter, type AsyncDeciderSpecification, type AsyncRetryOptions, type BaseMessageProcessorOptions, type BatchMessageHandler, type BatchMessageHandlerWithContext, type BatchMessageHandlerWithoutContext, type BatchRawMessageHandlerWithContext, type BatchRawMessageHandlerWithoutContext, type BatchRecordedMessageHandlerWithContext, type BatchRecordedMessageHandlerWithoutContext, type BatchWorkflowOutputHandler, type BeforeEventStoreCommitHandler, type BoundedAccessGuard, type Brand, type CanHandle, type Checkpointer, type Closeable, type CombineMetadata, type CombinedMessageMetadata, type CombinedReadEventMetadata, type Command, type CommandBus, type CommandDataOf, CommandHandler, type CommandHandlerOptions, type CommandHandlerResult, type CommandHandlerRetryOptions, CommandHandlerStreamVersionConflictRetryOptions, type CommandMetaDataOf, type CommandProcessor, type CommandSender, type CommandTypeOf, type CommonReadEventMetadata, type CommonRecordedMessageMetadata, ConcurrencyError, type CreateCommandType, type CreateEventType, type CurrentMessageProcessorPosition, DATABASE_REQUIRED_ERROR_MESSAGE, type DatabaseHandleOptionErrors, type DatabaseHandleOptions, type DatabaseHandleResult, type Decider, DeciderCommandHandler, type DeciderCommandHandlerOptions, DeciderSpecification, type DeepReadonly, type DefaultCommandMetadata, type DefaultEventStoreOptions, type DefaultRecord, type DeleteManyOptions, type DeleteManyResult, type DeleteOneOptions, type DeleteResult, type Document, type DocumentHandler, EmmettError, type EnhancedOmit, type EnqueueTaskOptions, type Equatable, ErrorConstructor, type Event, type EventBus, type EventDataOf, type EventMetaDataOf, type EventStore, type EventStoreAppendSchemaOptions, type EventStoreReadEventMetadata, type EventStoreReadSchemaOptions, type EventStoreSchemaOptions, type EventStoreSession, type EventStoreSessionFactory, type EventStoreWrapper, type EventSubscription, type EventTypeOf, type EventsPublisher, type ExclusiveAccessGuard, type ExpectedDocumentVersion, type ExpectedDocumentVersionGeneral, type ExpectedDocumentVersionValue, type ExpectedStreamVersion, type ExpectedStreamVersionGeneral, type ExpectedStreamVersionWithValue, ExpectedVersionConflictError, type Flavour, type FullId, type GetCheckpoint, type GlobalPosition, type GlobalStreamCaughtUp, GlobalStreamCaughtUpType, type GlobalSubscriptionEvent, type HandleOptions, type HandlerOptions, type InMemoryCheckpointer, type InMemoryDatabase, type InMemoryDocumentEvolve, type InMemoryDocumentsCollection, type InMemoryEventStore, InMemoryEventStoreDefaultStreamVersion, type InMemoryEventStoreOptions, type InMemoryMultiStreamProjectionOptions, type InMemoryProcessor, type InMemoryProcessorConnectionOptions, type InMemoryProcessorEachBatchHandler, type InMemoryProcessorEachMessageHandler, type InMemoryProcessorHandlerContext, type InMemoryProcessorOptions, type InMemoryProjectionAssert, type InMemoryProjectionDefinition, type InMemoryProjectionHandlerContext, type InMemoryProjectionHandlerOptions, type InMemoryProjectionOptions, InMemoryProjectionSpec, type InMemoryProjectionSpecEvent, type InMemoryProjectionSpecOptions, type InMemoryProjectionSpecWhenOptions, type InMemoryProjectorOptions, type InMemoryReactorOptions, type InMemoryReadEvent, type InMemoryReadEventMetadata, type InMemorySingleStreamProjectionOptions, type InMemoryWithNotNullDocumentEvolve, type InMemoryWithNullableDocumentEvolve, InProcessLock, type InitializedOnceGuard, type InsertManyOptions, type InsertManyResult, type InsertOneOptions, type InsertOneResult, JSONCodec, type JSONCodecOptions, type JSONDeserializeOptions, JSONReplacer, JSONReplacers, JSONReviver, type JSONReviverContext, JSONRevivers, type JSONSerializationOptions, type JSONSerializeOptions, JSONSerializer, type JSONSerializerOptions, type Lock, type LockOptions, type Message, type MessageBus, type MessageConsumer, type MessageConsumerOptions, type MessageDataOf, type MessageDowncast, type MessageHandler, type
|
|
1259
|
+
export { type AcquireLockOptions, type AfterEventStoreCommitHandler, type AggregateStreamOptions, type AggregateStreamResult, type AggregateStreamResultOfEventStore, type AggregateStreamResultWithGlobalPosition, type AnyCommand, type AnyEvent, type AnyMessage, type AnyReadEvent, type AnyReadEventMetadata, type AnyRecord, type AnyRecordedMessage, type AnyRecordedMessageMetadata, type AppendStreamResultOfEventStore, type AppendToStreamOptions, type AppendToStreamResult, type AppendToStreamResultWithGlobalPosition, type ArgumentMatcher, AssertionError, type AsyncAwaiter, type AsyncDeciderSpecification, type AsyncRetryOptions, type BaseMessageProcessorOptions, type BatchMessageHandler, type BatchMessageHandlerResult, type BatchMessageHandlerWithContext, type BatchMessageHandlerWithoutContext, type BatchRawMessageHandlerWithContext, type BatchRawMessageHandlerWithoutContext, type BatchRecordedMessageHandlerWithContext, type BatchRecordedMessageHandlerWithoutContext, type BatchWorkflowOutputHandler, type BeforeEventStoreCommitHandler, type BoundedAccessGuard, type Brand, type CanHandle, type Checkpointer, type Closeable, type CombineMetadata, type CombinedMessageMetadata, type CombinedReadEventMetadata, type Command, type CommandBus, type CommandDataOf, CommandHandler, type CommandHandlerOptions, type CommandHandlerResult, type CommandHandlerRetryOptions, CommandHandlerStreamVersionConflictRetryOptions, type CommandMetaDataOf, type CommandProcessor, type CommandSender, type CommandTypeOf, type CommonReadEventMetadata, type CommonRecordedMessageMetadata, ConcurrencyError, type CreateCommandType, type CreateEventType, type CurrentMessageProcessorPosition, DATABASE_REQUIRED_ERROR_MESSAGE, type DatabaseHandleOptionErrors, type DatabaseHandleOptions, type DatabaseHandleResult, type Decider, DeciderCommandHandler, type DeciderCommandHandlerOptions, DeciderSpecification, type DeepReadonly, type DefaultCommandMetadata, type DefaultEventStoreOptions, type DefaultRecord, type DeleteManyOptions, type DeleteManyResult, type DeleteOneOptions, type DeleteResult, type Document, type DocumentHandler, EmmettError, type EnhancedOmit, type EnqueueTaskOptions, type Equatable, ErrorConstructor, type Event, type EventBus, type EventDataOf, type EventMetaDataOf, type EventStore, type EventStoreAppendSchemaOptions, type EventStoreReadEventMetadata, type EventStoreReadSchemaOptions, type EventStoreSchemaOptions, type EventStoreSession, type EventStoreSessionFactory, type EventStoreWrapper, type EventSubscription, type EventTypeOf, type EventsPublisher, type ExclusiveAccessGuard, type ExpectedDocumentVersion, type ExpectedDocumentVersionGeneral, type ExpectedDocumentVersionValue, type ExpectedStreamVersion, type ExpectedStreamVersionGeneral, type ExpectedStreamVersionWithValue, ExpectedVersionConflictError, type Flavour, type FullId, type GetCheckpoint, type GlobalPosition, type GlobalStreamCaughtUp, GlobalStreamCaughtUpType, type GlobalSubscriptionEvent, type HandleOptions, type HandlerOptions, type InMemoryCheckpointer, type InMemoryDatabase, type InMemoryDocumentEvolve, type InMemoryDocumentsCollection, type InMemoryEventStore, InMemoryEventStoreDefaultStreamVersion, type InMemoryEventStoreOptions, type InMemoryMultiStreamProjectionOptions, type InMemoryProcessor, type InMemoryProcessorConnectionOptions, type InMemoryProcessorEachBatchHandler, type InMemoryProcessorEachMessageHandler, type InMemoryProcessorHandlerContext, type InMemoryProcessorOptions, type InMemoryProjectionAssert, type InMemoryProjectionDefinition, type InMemoryProjectionHandlerContext, type InMemoryProjectionHandlerOptions, type InMemoryProjectionOptions, InMemoryProjectionSpec, type InMemoryProjectionSpecEvent, type InMemoryProjectionSpecOptions, type InMemoryProjectionSpecWhenOptions, type InMemoryProjectorOptions, type InMemoryReactorOptions, type InMemoryReadEvent, type InMemoryReadEventMetadata, type InMemorySingleStreamProjectionOptions, type InMemoryWithNotNullDocumentEvolve, type InMemoryWithNullableDocumentEvolve, InProcessLock, type InitializedOnceGuard, type InsertManyOptions, type InsertManyResult, type InsertOneOptions, type InsertOneResult, JSONCodec, type JSONCodecOptions, type JSONDeserializeOptions, JSONReplacer, JSONReplacers, JSONReviver, type JSONReviverContext, JSONRevivers, type JSONSerializationOptions, type JSONSerializeOptions, JSONSerializer, type JSONSerializerOptions, type Lock, type LockOptions, type Message, type MessageBus, type MessageConsumer, type MessageConsumerOptions, type MessageDataOf, type MessageDowncast, type MessageHandler, type MessageKindOf, type MessageMetaDataOf, type MessageProcessingScope, MessageProcessor, type MessageProcessorStartFrom, MessageProcessorType, type MessageScheduler, type MessageSubscription, type MessageTypeOf, type MessageUpcast, type MockedFunction, type Mutable, NO_CONCURRENCY_CHECK, NoRetries, type NonNullable$1 as NonNullable, type OnReactorCloseHook, type OnReactorInitHook, type OnReactorStartHook, type OperationResult, type OptionalId, type OptionalUnlessRequiredId, type OptionalUnlessRequiredIdAndVersion, type OptionalUnlessRequiredVersion, type OptionalVersion, type ProcessorCheckpoint, type ProcessorHooks, type ProjectionDefinition, type ProjectionHandler, type ProjectionHandlingType, type ProjectionInitOptions, type ProjectionRegistration, type ProjectorOptions, type ReactorOptions, type ReadEvent, type ReadEventMetadata, type ReadEventMetadataWithGlobalPosition, type ReadEventMetadataWithoutGlobalPosition, type ReadProcessorCheckpoint, type ReadProcessorCheckpointResult, type ReadStreamOptions, type ReadStreamResult, type RecordedMessage, type RecordedMessageMetadata, type RecordedMessageMetadataWithGlobalPosition, type RecordedMessageMetadataWithoutGlobalPosition, type ReleaseLockOptions, type ReplaceOneOptions, STREAM_DOES_NOT_EXIST, STREAM_EXISTS, type ScheduleOptions, type ScheduledMessage, type ScheduledMessageProcessor, type SerializationCodec, type Serializer, type ShutdownHandler, type SingleMessageHandler, type SingleMessageHandlerResult, type SingleMessageHandlerWithContext, type SingleMessageHandlerWithoutContext, type SingleRawMessageHandlerWithContext, type SingleRawMessageHandlerWithoutContext, type SingleRecordedMessageHandlerWithContext, type SingleRecordedMessageHandlerWithoutContext, type SingleWorkflowOutputHandler, type StoreProcessorCheckpoint, type StoreProcessorCheckpointResult, type StreamExistsResult, type StreamPosition, type Task, type TaskContext, TaskProcessor, type TaskProcessorOptions, type TaskQueue, type TaskQueueItem, type TestEventStream, type ThenThrows, type TruncateProjection, type UpdateManyOptions, type UpdateManyResult, type UpdateOneOptions, type UpdateResult, ValidationErrors, type WithGlobalPosition, type WithId, type WithIdAndVersion, type WithVersion, type WithoutId, type WithoutVersion, Workflow, type WorkflowCommand, type WorkflowEvent, type WorkflowHandleOptions, WorkflowHandler, type WorkflowHandlerResult, type WorkflowHandlerRetryOptions, WorkflowHandlerStreamVersionConflictRetryOptions, type WorkflowInputMessageMetadata, type WorkflowMessageAction, type WorkflowOptions, type WorkflowOutput, type WorkflowOutputHandlerDefinition, type WorkflowOutputHandlerOptions, type WorkflowOutputHandlerResult, type WorkflowOutputMessageMetadata, type WorkflowProcessorContext, type WorkflowProcessorOptions, WorkflowSpecification, WrapEventStore, argMatches, argValue, arrayUtils, assertDeepEqual, assertDefined, assertDoesNotThrow, assertEqual, assertExpectedVersionMatchesCurrent, assertFails, assertFalse, assertIsNotNull, assertIsNull, assertMatches, assertNotDeepEqual, assertNotEmptyString, assertNotEqual, assertOk, assertPositiveNumber, assertRejects, assertThat, assertThatArray, assertThrows, assertThrowsAsync, assertTrue, assertUnsignedBigInt, asyncAwaiter, asyncProjections, asyncRetry, bigInt, bigIntProcessorCheckpoint, canCreateEventStoreSession, caughtUpEventFrom, command, composeJSONReplacers, composeJSONRevivers, deepEquals, defaultProcessingMessageProcessingScope, defaultProcessorPartition, defaultProcessorVersion, defaultTag, delay, documentExists, downcastRecordedMessage, downcastRecordedMessages, emmettPrefix, event, eventInStream, eventsInStream, expectInMemoryDocuments, filterProjections, formatDateToUtcYYYYMMDD, forwardToMessageBus, getCheckpoint, getInMemoryDatabase, getInMemoryEventStore, getInMemoryMessageBus, getProcessorInstanceId, getProjectorId, getWorkflowId, globalStreamCaughtUp, globalTag, guardBoundedAccess, guardExclusiveAccess, guardInitializedOnce, handleInMemoryProjections, hashText, inMemoryCheckpointer, inMemoryMultiStreamProjection, inMemoryProjection, inMemoryProjector, inMemoryReactor, inMemorySingleStreamProjection, inlineProjections, isBigint, isEquatable, isExpectedVersionConflictError, isGlobalStreamCaughtUp, isNotInternalEvent, isNumber, isString, isSubscriptionEvent, isSubset, isValidYYYYMMDD, jsonSerializer, matchesExpectedVersion, merge, message, newEventsInStream, nulloSessionFactory, onShutdown, parseBigIntProcessorCheckpoint, parseDateFromUtcYYYYMMDD, projection, projections, projector, reactor, reduceAsync, sum, toNormalizedString, tryPublishMessagesAfterCommit, unknownTag, upcastRecordedMessage, upcastRecordedMessages, verifyThat, wasMessageHandled, workflowOutputHandler, workflowProcessor, workflowStreamName };
|
package/dist/index.d.ts
CHANGED
|
@@ -292,14 +292,14 @@ declare const MessageProcessor: {
|
|
|
292
292
|
result: {
|
|
293
293
|
skip: (options?: {
|
|
294
294
|
reason?: string;
|
|
295
|
-
}) =>
|
|
295
|
+
}) => SingleMessageHandlerResult;
|
|
296
296
|
stop: (options?: {
|
|
297
297
|
reason?: string;
|
|
298
298
|
error?: EmmettError;
|
|
299
|
-
}) =>
|
|
299
|
+
}) => SingleMessageHandlerResult;
|
|
300
300
|
};
|
|
301
301
|
};
|
|
302
|
-
type MessageProcessingScope<HandlerContext extends DefaultRecord | undefined = undefined> = <Result =
|
|
302
|
+
type MessageProcessingScope<HandlerContext extends DefaultRecord | undefined = undefined> = <Result = SingleMessageHandlerResult>(handler: (context: HandlerContext) => Result | Promise<Result>, partialContext: Partial<HandlerContext>) => Result | Promise<Result>;
|
|
303
303
|
type Checkpointer<MessageType extends AnyMessage = AnyMessage, MessageMetadataType extends AnyReadEventMetadata = AnyReadEventMetadata, HandlerContext extends DefaultRecord = DefaultRecord> = {
|
|
304
304
|
read: ReadProcessorCheckpoint<HandlerContext>;
|
|
305
305
|
store: StoreProcessorCheckpoint<MessageType, MessageMetadataType, HandlerContext>;
|
|
@@ -347,7 +347,7 @@ type ProjectorOptions<EventType extends AnyEvent = AnyEvent, MessageMetadataType
|
|
|
347
347
|
truncateOnStart?: boolean;
|
|
348
348
|
projection: ProjectionDefinition<EventType, MessageMetadataType, HandlerContext, EventPayloadType>;
|
|
349
349
|
};
|
|
350
|
-
declare const defaultProcessingMessageProcessingScope: <HandlerContext = never, Result =
|
|
350
|
+
declare const defaultProcessingMessageProcessingScope: <HandlerContext = never, Result = SingleMessageHandlerResult>(handler: (context: HandlerContext) => Result | Promise<Result>, partialContext: Partial<HandlerContext>) => Result | Promise<Result>;
|
|
351
351
|
type ProcessorCheckpoint = Brand<string, 'ProcessorCheckpoint'>;
|
|
352
352
|
declare const bigIntProcessorCheckpoint: (value: bigint) => ProcessorCheckpoint;
|
|
353
353
|
declare const parseBigIntProcessorCheckpoint: (value: ProcessorCheckpoint) => bigint;
|
|
@@ -473,28 +473,42 @@ type AnyReadEventMetadata = AnyRecordedMessageMetadata;
|
|
|
473
473
|
type ReadEventMetadataWithGlobalPosition = RecordedMessageMetadataWithGlobalPosition;
|
|
474
474
|
type ReadEventMetadataWithoutGlobalPosition = RecordedMessageMetadataWithoutGlobalPosition;
|
|
475
475
|
|
|
476
|
-
type SingleRawMessageHandlerWithoutContext<MessageType extends Message = AnyMessage> = (message: MessageType) => Promise<
|
|
477
|
-
type SingleRecordedMessageHandlerWithoutContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = (message: RecordedMessage<MessageType, MessageMetaDataType>) => Promise<
|
|
476
|
+
type SingleRawMessageHandlerWithoutContext<MessageType extends Message = AnyMessage> = (message: MessageType) => Promise<SingleMessageHandlerResult> | SingleMessageHandlerResult;
|
|
477
|
+
type SingleRecordedMessageHandlerWithoutContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = (message: RecordedMessage<MessageType, MessageMetaDataType>) => Promise<SingleMessageHandlerResult> | SingleMessageHandlerResult;
|
|
478
478
|
type SingleMessageHandlerWithoutContext<MessageType extends AnyMessage = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = never> = SingleRawMessageHandlerWithoutContext<MessageType> | SingleRecordedMessageHandlerWithoutContext<MessageType, MessageMetaDataType>;
|
|
479
|
-
type SingleRawMessageHandlerWithContext<MessageType extends Message = AnyMessage, HandlerContext extends DefaultRecord | undefined = undefined> = (message: MessageType, context: HandlerContext) => Promise<
|
|
480
|
-
type SingleRecordedMessageHandlerWithContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = (message: RecordedMessage<MessageType, MessageMetaDataType>, context: HandlerContext) => Promise<
|
|
479
|
+
type SingleRawMessageHandlerWithContext<MessageType extends Message = AnyMessage, HandlerContext extends DefaultRecord | undefined = undefined> = (message: MessageType, context: HandlerContext) => Promise<SingleMessageHandlerResult> | SingleMessageHandlerResult;
|
|
480
|
+
type SingleRecordedMessageHandlerWithContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = (message: RecordedMessage<MessageType, MessageMetaDataType>, context: HandlerContext) => Promise<SingleMessageHandlerResult> | SingleMessageHandlerResult;
|
|
481
481
|
type SingleMessageHandlerWithContext<MessageType extends AnyMessage = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = never, HandlerContext extends DefaultRecord = DefaultRecord> = SingleRawMessageHandlerWithContext<MessageType, HandlerContext> | SingleRecordedMessageHandlerWithContext<MessageType, MessageMetaDataType, HandlerContext>;
|
|
482
482
|
type SingleMessageHandler<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = HandlerContext extends DefaultRecord ? SingleMessageHandlerWithContext<MessageType, MessageMetaDataType, HandlerContext> : SingleMessageHandlerWithoutContext<MessageType, MessageMetaDataType>;
|
|
483
|
-
type BatchRawMessageHandlerWithoutContext<MessageType extends Message = AnyMessage> = (messages: MessageType[]) => Promise<
|
|
484
|
-
type BatchRecordedMessageHandlerWithoutContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = (messages: RecordedMessage<MessageType, MessageMetaDataType>[]) => Promise<
|
|
483
|
+
type BatchRawMessageHandlerWithoutContext<MessageType extends Message = AnyMessage> = (messages: MessageType[]) => Promise<BatchMessageHandlerResult> | BatchMessageHandlerResult;
|
|
484
|
+
type BatchRecordedMessageHandlerWithoutContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = (messages: RecordedMessage<MessageType, MessageMetaDataType>[]) => Promise<BatchMessageHandlerResult> | BatchMessageHandlerResult;
|
|
485
485
|
type BatchMessageHandlerWithoutContext<MessageType extends AnyMessage = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata> = BatchRawMessageHandlerWithoutContext<MessageType> | BatchRecordedMessageHandlerWithoutContext<MessageType, MessageMetaDataType>;
|
|
486
|
-
type BatchRawMessageHandlerWithContext<MessageType extends Message = AnyMessage, HandlerContext extends DefaultRecord | undefined = undefined> = (messages: MessageType[], context: HandlerContext) => Promise<
|
|
487
|
-
type BatchRecordedMessageHandlerWithContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord = DefaultRecord> = (messages: RecordedMessage<MessageType, MessageMetaDataType>[], context: HandlerContext) => Promise<
|
|
486
|
+
type BatchRawMessageHandlerWithContext<MessageType extends Message = AnyMessage, HandlerContext extends DefaultRecord | undefined = undefined> = (messages: MessageType[], context: HandlerContext) => Promise<BatchMessageHandlerResult> | BatchMessageHandlerResult;
|
|
487
|
+
type BatchRecordedMessageHandlerWithContext<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord = DefaultRecord> = (messages: RecordedMessage<MessageType, MessageMetaDataType>[], context: HandlerContext) => Promise<BatchMessageHandlerResult> | BatchMessageHandlerResult;
|
|
488
488
|
type BatchMessageHandlerWithContext<MessageType extends AnyMessage = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord = DefaultRecord> = BatchRawMessageHandlerWithContext<MessageType, HandlerContext> | BatchRecordedMessageHandlerWithContext<MessageType, MessageMetaDataType, HandlerContext>;
|
|
489
489
|
type BatchMessageHandler<MessageType extends Message = AnyMessage, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = HandlerContext extends DefaultRecord ? BatchMessageHandlerWithContext<MessageType, MessageMetaDataType, HandlerContext> : BatchMessageHandlerWithoutContext<MessageType, MessageMetaDataType>;
|
|
490
490
|
type MessageHandler<MessageType extends Message = Message, MessageMetaDataType extends AnyRecordedMessageMetadata = AnyRecordedMessageMetadata, HandlerContext extends DefaultRecord | undefined = undefined> = (HandlerContext extends DefaultRecord ? SingleMessageHandler<MessageType, MessageMetaDataType, HandlerContext> : SingleMessageHandler<MessageType, MessageMetaDataType>) | (HandlerContext extends DefaultRecord ? BatchMessageHandler<MessageType, MessageMetaDataType, HandlerContext> : BatchMessageHandler<MessageType, MessageMetaDataType>);
|
|
491
|
-
type
|
|
491
|
+
type SingleMessageHandlerResult = void | {
|
|
492
|
+
type: 'ACK';
|
|
493
|
+
} | {
|
|
494
|
+
type: 'SKIP';
|
|
495
|
+
reason?: string;
|
|
496
|
+
} | {
|
|
497
|
+
type: 'STOP';
|
|
498
|
+
reason?: string;
|
|
499
|
+
error?: EmmettError;
|
|
500
|
+
};
|
|
501
|
+
type BatchMessageHandlerResult = void | {
|
|
502
|
+
type: 'ACK';
|
|
503
|
+
} | {
|
|
492
504
|
type: 'SKIP';
|
|
493
505
|
reason?: string;
|
|
506
|
+
lastSuccessfulMessage: AnyRecordedMessage;
|
|
494
507
|
} | {
|
|
495
508
|
type: 'STOP';
|
|
496
509
|
reason?: string;
|
|
497
510
|
error?: EmmettError;
|
|
511
|
+
lastSuccessfulMessage?: AnyRecordedMessage;
|
|
498
512
|
};
|
|
499
513
|
|
|
500
514
|
type Decider<State, CommandType extends Command, StreamEvent extends Event> = {
|
|
@@ -960,6 +974,8 @@ declare const upcastRecordedMessages: <MessageType extends AnyMessage, MessagePa
|
|
|
960
974
|
upcast?: MessageUpcast<MessageType, MessagePayloadType, RecordedMessageMetadataType>;
|
|
961
975
|
}) => RecordedMessage<MessageType, RecordedMessageMetadataType>[];
|
|
962
976
|
|
|
977
|
+
declare function reduceAsync<T, R>(items: T[], fn: (accumulator: R, item: T, index: number) => Promise<R>, initial: R): Promise<R>;
|
|
978
|
+
|
|
963
979
|
type Closeable = {
|
|
964
980
|
/**
|
|
965
981
|
* Gracefully cleans up managed resources
|
|
@@ -1240,4 +1256,4 @@ declare const WorkflowHandler: <Input extends AnyEvent | AnyCommand, State, Outp
|
|
|
1240
1256
|
retry?: WorkflowHandlerRetryOptions;
|
|
1241
1257
|
}) => <Store extends EventStore>(store: Store, message: Input | RecordedMessage<Input, MessageMetadataType>, handleOptions?: WorkflowHandleOptions<Store>) => Promise<WorkflowHandlerResult<Output, Store>>;
|
|
1242
1258
|
|
|
1243
|
-
export { type AcquireLockOptions, type AfterEventStoreCommitHandler, type AggregateStreamOptions, type AggregateStreamResult, type AggregateStreamResultOfEventStore, type AggregateStreamResultWithGlobalPosition, type AnyCommand, type AnyEvent, type AnyMessage, type AnyReadEvent, type AnyReadEventMetadata, type AnyRecord, type AnyRecordedMessage, type AnyRecordedMessageMetadata, type AppendStreamResultOfEventStore, type AppendToStreamOptions, type AppendToStreamResult, type AppendToStreamResultWithGlobalPosition, type ArgumentMatcher, AssertionError, type AsyncAwaiter, type AsyncDeciderSpecification, type AsyncRetryOptions, type BaseMessageProcessorOptions, type BatchMessageHandler, type BatchMessageHandlerWithContext, type BatchMessageHandlerWithoutContext, type BatchRawMessageHandlerWithContext, type BatchRawMessageHandlerWithoutContext, type BatchRecordedMessageHandlerWithContext, type BatchRecordedMessageHandlerWithoutContext, type BatchWorkflowOutputHandler, type BeforeEventStoreCommitHandler, type BoundedAccessGuard, type Brand, type CanHandle, type Checkpointer, type Closeable, type CombineMetadata, type CombinedMessageMetadata, type CombinedReadEventMetadata, type Command, type CommandBus, type CommandDataOf, CommandHandler, type CommandHandlerOptions, type CommandHandlerResult, type CommandHandlerRetryOptions, CommandHandlerStreamVersionConflictRetryOptions, type CommandMetaDataOf, type CommandProcessor, type CommandSender, type CommandTypeOf, type CommonReadEventMetadata, type CommonRecordedMessageMetadata, ConcurrencyError, type CreateCommandType, type CreateEventType, type CurrentMessageProcessorPosition, DATABASE_REQUIRED_ERROR_MESSAGE, type DatabaseHandleOptionErrors, type DatabaseHandleOptions, type DatabaseHandleResult, type Decider, DeciderCommandHandler, type DeciderCommandHandlerOptions, DeciderSpecification, type DeepReadonly, type DefaultCommandMetadata, type DefaultEventStoreOptions, type DefaultRecord, type DeleteManyOptions, type DeleteManyResult, type DeleteOneOptions, type DeleteResult, type Document, type DocumentHandler, EmmettError, type EnhancedOmit, type EnqueueTaskOptions, type Equatable, ErrorConstructor, type Event, type EventBus, type EventDataOf, type EventMetaDataOf, type EventStore, type EventStoreAppendSchemaOptions, type EventStoreReadEventMetadata, type EventStoreReadSchemaOptions, type EventStoreSchemaOptions, type EventStoreSession, type EventStoreSessionFactory, type EventStoreWrapper, type EventSubscription, type EventTypeOf, type EventsPublisher, type ExclusiveAccessGuard, type ExpectedDocumentVersion, type ExpectedDocumentVersionGeneral, type ExpectedDocumentVersionValue, type ExpectedStreamVersion, type ExpectedStreamVersionGeneral, type ExpectedStreamVersionWithValue, ExpectedVersionConflictError, type Flavour, type FullId, type GetCheckpoint, type GlobalPosition, type GlobalStreamCaughtUp, GlobalStreamCaughtUpType, type GlobalSubscriptionEvent, type HandleOptions, type HandlerOptions, type InMemoryCheckpointer, type InMemoryDatabase, type InMemoryDocumentEvolve, type InMemoryDocumentsCollection, type InMemoryEventStore, InMemoryEventStoreDefaultStreamVersion, type InMemoryEventStoreOptions, type InMemoryMultiStreamProjectionOptions, type InMemoryProcessor, type InMemoryProcessorConnectionOptions, type InMemoryProcessorEachBatchHandler, type InMemoryProcessorEachMessageHandler, type InMemoryProcessorHandlerContext, type InMemoryProcessorOptions, type InMemoryProjectionAssert, type InMemoryProjectionDefinition, type InMemoryProjectionHandlerContext, type InMemoryProjectionHandlerOptions, type InMemoryProjectionOptions, InMemoryProjectionSpec, type InMemoryProjectionSpecEvent, type InMemoryProjectionSpecOptions, type InMemoryProjectionSpecWhenOptions, type InMemoryProjectorOptions, type InMemoryReactorOptions, type InMemoryReadEvent, type InMemoryReadEventMetadata, type InMemorySingleStreamProjectionOptions, type InMemoryWithNotNullDocumentEvolve, type InMemoryWithNullableDocumentEvolve, InProcessLock, type InitializedOnceGuard, type InsertManyOptions, type InsertManyResult, type InsertOneOptions, type InsertOneResult, JSONCodec, type JSONCodecOptions, type JSONDeserializeOptions, JSONReplacer, JSONReplacers, JSONReviver, type JSONReviverContext, JSONRevivers, type JSONSerializationOptions, type JSONSerializeOptions, JSONSerializer, type JSONSerializerOptions, type Lock, type LockOptions, type Message, type MessageBus, type MessageConsumer, type MessageConsumerOptions, type MessageDataOf, type MessageDowncast, type MessageHandler, type
|
|
1259
|
+
export { type AcquireLockOptions, type AfterEventStoreCommitHandler, type AggregateStreamOptions, type AggregateStreamResult, type AggregateStreamResultOfEventStore, type AggregateStreamResultWithGlobalPosition, type AnyCommand, type AnyEvent, type AnyMessage, type AnyReadEvent, type AnyReadEventMetadata, type AnyRecord, type AnyRecordedMessage, type AnyRecordedMessageMetadata, type AppendStreamResultOfEventStore, type AppendToStreamOptions, type AppendToStreamResult, type AppendToStreamResultWithGlobalPosition, type ArgumentMatcher, AssertionError, type AsyncAwaiter, type AsyncDeciderSpecification, type AsyncRetryOptions, type BaseMessageProcessorOptions, type BatchMessageHandler, type BatchMessageHandlerResult, type BatchMessageHandlerWithContext, type BatchMessageHandlerWithoutContext, type BatchRawMessageHandlerWithContext, type BatchRawMessageHandlerWithoutContext, type BatchRecordedMessageHandlerWithContext, type BatchRecordedMessageHandlerWithoutContext, type BatchWorkflowOutputHandler, type BeforeEventStoreCommitHandler, type BoundedAccessGuard, type Brand, type CanHandle, type Checkpointer, type Closeable, type CombineMetadata, type CombinedMessageMetadata, type CombinedReadEventMetadata, type Command, type CommandBus, type CommandDataOf, CommandHandler, type CommandHandlerOptions, type CommandHandlerResult, type CommandHandlerRetryOptions, CommandHandlerStreamVersionConflictRetryOptions, type CommandMetaDataOf, type CommandProcessor, type CommandSender, type CommandTypeOf, type CommonReadEventMetadata, type CommonRecordedMessageMetadata, ConcurrencyError, type CreateCommandType, type CreateEventType, type CurrentMessageProcessorPosition, DATABASE_REQUIRED_ERROR_MESSAGE, type DatabaseHandleOptionErrors, type DatabaseHandleOptions, type DatabaseHandleResult, type Decider, DeciderCommandHandler, type DeciderCommandHandlerOptions, DeciderSpecification, type DeepReadonly, type DefaultCommandMetadata, type DefaultEventStoreOptions, type DefaultRecord, type DeleteManyOptions, type DeleteManyResult, type DeleteOneOptions, type DeleteResult, type Document, type DocumentHandler, EmmettError, type EnhancedOmit, type EnqueueTaskOptions, type Equatable, ErrorConstructor, type Event, type EventBus, type EventDataOf, type EventMetaDataOf, type EventStore, type EventStoreAppendSchemaOptions, type EventStoreReadEventMetadata, type EventStoreReadSchemaOptions, type EventStoreSchemaOptions, type EventStoreSession, type EventStoreSessionFactory, type EventStoreWrapper, type EventSubscription, type EventTypeOf, type EventsPublisher, type ExclusiveAccessGuard, type ExpectedDocumentVersion, type ExpectedDocumentVersionGeneral, type ExpectedDocumentVersionValue, type ExpectedStreamVersion, type ExpectedStreamVersionGeneral, type ExpectedStreamVersionWithValue, ExpectedVersionConflictError, type Flavour, type FullId, type GetCheckpoint, type GlobalPosition, type GlobalStreamCaughtUp, GlobalStreamCaughtUpType, type GlobalSubscriptionEvent, type HandleOptions, type HandlerOptions, type InMemoryCheckpointer, type InMemoryDatabase, type InMemoryDocumentEvolve, type InMemoryDocumentsCollection, type InMemoryEventStore, InMemoryEventStoreDefaultStreamVersion, type InMemoryEventStoreOptions, type InMemoryMultiStreamProjectionOptions, type InMemoryProcessor, type InMemoryProcessorConnectionOptions, type InMemoryProcessorEachBatchHandler, type InMemoryProcessorEachMessageHandler, type InMemoryProcessorHandlerContext, type InMemoryProcessorOptions, type InMemoryProjectionAssert, type InMemoryProjectionDefinition, type InMemoryProjectionHandlerContext, type InMemoryProjectionHandlerOptions, type InMemoryProjectionOptions, InMemoryProjectionSpec, type InMemoryProjectionSpecEvent, type InMemoryProjectionSpecOptions, type InMemoryProjectionSpecWhenOptions, type InMemoryProjectorOptions, type InMemoryReactorOptions, type InMemoryReadEvent, type InMemoryReadEventMetadata, type InMemorySingleStreamProjectionOptions, type InMemoryWithNotNullDocumentEvolve, type InMemoryWithNullableDocumentEvolve, InProcessLock, type InitializedOnceGuard, type InsertManyOptions, type InsertManyResult, type InsertOneOptions, type InsertOneResult, JSONCodec, type JSONCodecOptions, type JSONDeserializeOptions, JSONReplacer, JSONReplacers, JSONReviver, type JSONReviverContext, JSONRevivers, type JSONSerializationOptions, type JSONSerializeOptions, JSONSerializer, type JSONSerializerOptions, type Lock, type LockOptions, type Message, type MessageBus, type MessageConsumer, type MessageConsumerOptions, type MessageDataOf, type MessageDowncast, type MessageHandler, type MessageKindOf, type MessageMetaDataOf, type MessageProcessingScope, MessageProcessor, type MessageProcessorStartFrom, MessageProcessorType, type MessageScheduler, type MessageSubscription, type MessageTypeOf, type MessageUpcast, type MockedFunction, type Mutable, NO_CONCURRENCY_CHECK, NoRetries, type NonNullable$1 as NonNullable, type OnReactorCloseHook, type OnReactorInitHook, type OnReactorStartHook, type OperationResult, type OptionalId, type OptionalUnlessRequiredId, type OptionalUnlessRequiredIdAndVersion, type OptionalUnlessRequiredVersion, type OptionalVersion, type ProcessorCheckpoint, type ProcessorHooks, type ProjectionDefinition, type ProjectionHandler, type ProjectionHandlingType, type ProjectionInitOptions, type ProjectionRegistration, type ProjectorOptions, type ReactorOptions, type ReadEvent, type ReadEventMetadata, type ReadEventMetadataWithGlobalPosition, type ReadEventMetadataWithoutGlobalPosition, type ReadProcessorCheckpoint, type ReadProcessorCheckpointResult, type ReadStreamOptions, type ReadStreamResult, type RecordedMessage, type RecordedMessageMetadata, type RecordedMessageMetadataWithGlobalPosition, type RecordedMessageMetadataWithoutGlobalPosition, type ReleaseLockOptions, type ReplaceOneOptions, STREAM_DOES_NOT_EXIST, STREAM_EXISTS, type ScheduleOptions, type ScheduledMessage, type ScheduledMessageProcessor, type SerializationCodec, type Serializer, type ShutdownHandler, type SingleMessageHandler, type SingleMessageHandlerResult, type SingleMessageHandlerWithContext, type SingleMessageHandlerWithoutContext, type SingleRawMessageHandlerWithContext, type SingleRawMessageHandlerWithoutContext, type SingleRecordedMessageHandlerWithContext, type SingleRecordedMessageHandlerWithoutContext, type SingleWorkflowOutputHandler, type StoreProcessorCheckpoint, type StoreProcessorCheckpointResult, type StreamExistsResult, type StreamPosition, type Task, type TaskContext, TaskProcessor, type TaskProcessorOptions, type TaskQueue, type TaskQueueItem, type TestEventStream, type ThenThrows, type TruncateProjection, type UpdateManyOptions, type UpdateManyResult, type UpdateOneOptions, type UpdateResult, ValidationErrors, type WithGlobalPosition, type WithId, type WithIdAndVersion, type WithVersion, type WithoutId, type WithoutVersion, Workflow, type WorkflowCommand, type WorkflowEvent, type WorkflowHandleOptions, WorkflowHandler, type WorkflowHandlerResult, type WorkflowHandlerRetryOptions, WorkflowHandlerStreamVersionConflictRetryOptions, type WorkflowInputMessageMetadata, type WorkflowMessageAction, type WorkflowOptions, type WorkflowOutput, type WorkflowOutputHandlerDefinition, type WorkflowOutputHandlerOptions, type WorkflowOutputHandlerResult, type WorkflowOutputMessageMetadata, type WorkflowProcessorContext, type WorkflowProcessorOptions, WorkflowSpecification, WrapEventStore, argMatches, argValue, arrayUtils, assertDeepEqual, assertDefined, assertDoesNotThrow, assertEqual, assertExpectedVersionMatchesCurrent, assertFails, assertFalse, assertIsNotNull, assertIsNull, assertMatches, assertNotDeepEqual, assertNotEmptyString, assertNotEqual, assertOk, assertPositiveNumber, assertRejects, assertThat, assertThatArray, assertThrows, assertThrowsAsync, assertTrue, assertUnsignedBigInt, asyncAwaiter, asyncProjections, asyncRetry, bigInt, bigIntProcessorCheckpoint, canCreateEventStoreSession, caughtUpEventFrom, command, composeJSONReplacers, composeJSONRevivers, deepEquals, defaultProcessingMessageProcessingScope, defaultProcessorPartition, defaultProcessorVersion, defaultTag, delay, documentExists, downcastRecordedMessage, downcastRecordedMessages, emmettPrefix, event, eventInStream, eventsInStream, expectInMemoryDocuments, filterProjections, formatDateToUtcYYYYMMDD, forwardToMessageBus, getCheckpoint, getInMemoryDatabase, getInMemoryEventStore, getInMemoryMessageBus, getProcessorInstanceId, getProjectorId, getWorkflowId, globalStreamCaughtUp, globalTag, guardBoundedAccess, guardExclusiveAccess, guardInitializedOnce, handleInMemoryProjections, hashText, inMemoryCheckpointer, inMemoryMultiStreamProjection, inMemoryProjection, inMemoryProjector, inMemoryReactor, inMemorySingleStreamProjection, inlineProjections, isBigint, isEquatable, isExpectedVersionConflictError, isGlobalStreamCaughtUp, isNotInternalEvent, isNumber, isString, isSubscriptionEvent, isSubset, isValidYYYYMMDD, jsonSerializer, matchesExpectedVersion, merge, message, newEventsInStream, nulloSessionFactory, onShutdown, parseBigIntProcessorCheckpoint, parseDateFromUtcYYYYMMDD, projection, projections, projector, reactor, reduceAsync, sum, toNormalizedString, tryPublishMessagesAfterCommit, unknownTag, upcastRecordedMessage, upcastRecordedMessages, verifyThat, wasMessageHandled, workflowOutputHandler, workflowProcessor, workflowStreamName };
|
package/dist/index.js
CHANGED
|
@@ -116,6 +116,15 @@ import { v4 as uuid5 } from "uuid";
|
|
|
116
116
|
// src/database/inMemoryDatabase.ts
|
|
117
117
|
import { v7 as uuid2 } from "uuid";
|
|
118
118
|
|
|
119
|
+
// src/utils/async/mapAsync.ts
|
|
120
|
+
async function reduceAsync(items, fn, initial) {
|
|
121
|
+
let accumulator = initial;
|
|
122
|
+
for (let i = 0; i < items.length; i++) {
|
|
123
|
+
accumulator = await fn(accumulator, items[i], i);
|
|
124
|
+
}
|
|
125
|
+
return accumulator;
|
|
126
|
+
}
|
|
127
|
+
|
|
119
128
|
// src/utils/collections/duplicates.ts
|
|
120
129
|
var hasDuplicates = (array, predicate) => {
|
|
121
130
|
const mapped = array.map(predicate);
|
|
@@ -1207,7 +1216,40 @@ var reactor = (options) => {
|
|
|
1207
1216
|
canHandle,
|
|
1208
1217
|
stopAfter
|
|
1209
1218
|
} = options;
|
|
1210
|
-
const
|
|
1219
|
+
const isCustomBatch = "eachBatch" in options && !!options.eachBatch;
|
|
1220
|
+
const eachBatch = isCustomBatch ? options.eachBatch : async (messages, context) => {
|
|
1221
|
+
let result = void 0;
|
|
1222
|
+
for (let i = 0; i < messages.length; i++) {
|
|
1223
|
+
const message2 = messages[i];
|
|
1224
|
+
const messageProcessingResult = await options.eachMessage(
|
|
1225
|
+
message2,
|
|
1226
|
+
context
|
|
1227
|
+
);
|
|
1228
|
+
if (messageProcessingResult && messageProcessingResult.type === "STOP") {
|
|
1229
|
+
result = {
|
|
1230
|
+
...messageProcessingResult,
|
|
1231
|
+
lastSuccessfulMessage: messageProcessingResult.error ? messages[i - 1] : message2
|
|
1232
|
+
};
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
if (stopAfter && stopAfter(message2)) {
|
|
1236
|
+
result = {
|
|
1237
|
+
type: "STOP",
|
|
1238
|
+
reason: "Stop condition reached",
|
|
1239
|
+
lastSuccessfulMessage: message2
|
|
1240
|
+
};
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
if (messageProcessingResult && messageProcessingResult.type === "SKIP") {
|
|
1244
|
+
result = {
|
|
1245
|
+
...messageProcessingResult,
|
|
1246
|
+
lastSuccessfulMessage: message2
|
|
1247
|
+
};
|
|
1248
|
+
continue;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
return result;
|
|
1252
|
+
};
|
|
1211
1253
|
let isInitiated = false;
|
|
1212
1254
|
let isActive = false;
|
|
1213
1255
|
let lastCheckpoint = null;
|
|
@@ -1245,10 +1287,11 @@ var reactor = (options) => {
|
|
|
1245
1287
|
await init(startOptions);
|
|
1246
1288
|
isActive = true;
|
|
1247
1289
|
closeSignal = onShutdown(() => close(startOptions));
|
|
1248
|
-
if (lastCheckpoint !== null)
|
|
1290
|
+
if (lastCheckpoint !== null) {
|
|
1249
1291
|
return {
|
|
1250
1292
|
lastCheckpoint
|
|
1251
1293
|
};
|
|
1294
|
+
}
|
|
1252
1295
|
return await processingScope(async (context) => {
|
|
1253
1296
|
if (hooks.onStart) {
|
|
1254
1297
|
await hooks.onStart(context);
|
|
@@ -1277,46 +1320,48 @@ var reactor = (options) => {
|
|
|
1277
1320
|
handle: async (messages, partialContext) => {
|
|
1278
1321
|
if (!isActive) return Promise.resolve();
|
|
1279
1322
|
return await processingScope(async (context) => {
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1323
|
+
const messagesAboveCheckpoint = messages.filter(
|
|
1324
|
+
(message2) => !wasMessageHandled(message2, lastCheckpoint)
|
|
1325
|
+
);
|
|
1326
|
+
const upcastedMessages = messagesAboveCheckpoint.map(
|
|
1327
|
+
(message2) => upcastRecordedMessage(
|
|
1284
1328
|
// TODO: Make it smarter
|
|
1285
1329
|
message2,
|
|
1286
1330
|
options.messageOptions?.schema?.versioning
|
|
1331
|
+
)
|
|
1332
|
+
).filter(
|
|
1333
|
+
(upcasted) => !canHandle || canHandle.includes(upcasted.type)
|
|
1334
|
+
);
|
|
1335
|
+
const stopMessageIndex = isCustomBatch && stopAfter ? upcastedMessages.findIndex(stopAfter) : -1;
|
|
1336
|
+
const unhandledMessages = stopMessageIndex !== -1 ? upcastedMessages.slice(0, stopMessageIndex + 1) : upcastedMessages;
|
|
1337
|
+
const batchResult = await eachBatch(unhandledMessages, context);
|
|
1338
|
+
const messageProcessingResult = batchResult?.type === "STOP" ? batchResult : stopMessageIndex !== -1 ? {
|
|
1339
|
+
type: "STOP",
|
|
1340
|
+
reason: "Stop condition reached",
|
|
1341
|
+
lastSuccessfulMessage: unhandledMessages[stopMessageIndex]
|
|
1342
|
+
} : batchResult;
|
|
1343
|
+
const isStop = messageProcessingResult && messageProcessingResult.type === "STOP";
|
|
1344
|
+
const checkpointMessage = messageProcessingResult?.type === "STOP" ? messageProcessingResult.lastSuccessfulMessage : messagesAboveCheckpoint[messagesAboveCheckpoint.length - 1];
|
|
1345
|
+
if (checkpointMessage && checkpoints) {
|
|
1346
|
+
const storeCheckpointResult = await checkpoints.store(
|
|
1347
|
+
{
|
|
1348
|
+
processorId,
|
|
1349
|
+
version,
|
|
1350
|
+
message: checkpointMessage,
|
|
1351
|
+
lastCheckpoint,
|
|
1352
|
+
partition
|
|
1353
|
+
},
|
|
1354
|
+
context
|
|
1287
1355
|
);
|
|
1288
|
-
if (
|
|
1289
|
-
|
|
1290
|
-
const messageProcessingResult = await eachMessage(upcasted, context);
|
|
1291
|
-
if (checkpoints) {
|
|
1292
|
-
const storeCheckpointResult = await checkpoints.store(
|
|
1293
|
-
{
|
|
1294
|
-
processorId,
|
|
1295
|
-
version,
|
|
1296
|
-
message: upcasted,
|
|
1297
|
-
lastCheckpoint,
|
|
1298
|
-
partition
|
|
1299
|
-
},
|
|
1300
|
-
context
|
|
1301
|
-
);
|
|
1302
|
-
if (storeCheckpointResult.success) {
|
|
1303
|
-
lastCheckpoint = storeCheckpointResult.newCheckpoint;
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
if (messageProcessingResult && messageProcessingResult.type === "STOP") {
|
|
1307
|
-
isActive = false;
|
|
1308
|
-
result = messageProcessingResult;
|
|
1309
|
-
break;
|
|
1356
|
+
if (storeCheckpointResult.success) {
|
|
1357
|
+
lastCheckpoint = storeCheckpointResult.newCheckpoint;
|
|
1310
1358
|
}
|
|
1311
|
-
if (stopAfter && stopAfter(upcasted)) {
|
|
1312
|
-
isActive = false;
|
|
1313
|
-
result = { type: "STOP", reason: "Stop condition reached" };
|
|
1314
|
-
break;
|
|
1315
|
-
}
|
|
1316
|
-
if (messageProcessingResult && messageProcessingResult.type === "SKIP")
|
|
1317
|
-
continue;
|
|
1318
1359
|
}
|
|
1319
|
-
|
|
1360
|
+
if (isStop) {
|
|
1361
|
+
isActive = false;
|
|
1362
|
+
return messageProcessingResult;
|
|
1363
|
+
}
|
|
1364
|
+
return void 0;
|
|
1320
1365
|
}, partialContext);
|
|
1321
1366
|
}
|
|
1322
1367
|
};
|
|
@@ -1344,7 +1389,7 @@ var projector = (options) => {
|
|
|
1344
1389
|
} : void 0,
|
|
1345
1390
|
onClose: options.hooks?.onClose
|
|
1346
1391
|
},
|
|
1347
|
-
|
|
1392
|
+
eachBatch: async (events, context) => projection2.handle(events, context)
|
|
1348
1393
|
});
|
|
1349
1394
|
};
|
|
1350
1395
|
|
|
@@ -2900,6 +2945,7 @@ export {
|
|
|
2900
2945
|
projections,
|
|
2901
2946
|
projector,
|
|
2902
2947
|
reactor,
|
|
2948
|
+
reduceAsync,
|
|
2903
2949
|
sum,
|
|
2904
2950
|
toNormalizedString,
|
|
2905
2951
|
tryPublishMessagesAfterCommit,
|