@event-driven-io/emmett 0.23.0-alpha.4 → 0.23.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +216 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -2
- package/dist/index.d.ts +53 -2
- package/dist/index.js +175 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -251,6 +251,23 @@ declare const isEquatable: <T>(left: T) => left is Equatable<T>;
|
|
|
251
251
|
|
|
252
252
|
declare const sum: (iterator: Iterator<number, number, number> | Iterator<number>) => number;
|
|
253
253
|
|
|
254
|
+
type LockOptions = {
|
|
255
|
+
lockId: number;
|
|
256
|
+
};
|
|
257
|
+
type AcquireLockOptions = {
|
|
258
|
+
lockId: string;
|
|
259
|
+
};
|
|
260
|
+
type ReleaseLockOptions = {
|
|
261
|
+
lockId: string;
|
|
262
|
+
};
|
|
263
|
+
type Lock = {
|
|
264
|
+
acquire(options: AcquireLockOptions): Promise<void>;
|
|
265
|
+
tryAcquire(options: AcquireLockOptions): Promise<boolean>;
|
|
266
|
+
release(options: ReleaseLockOptions): Promise<boolean>;
|
|
267
|
+
withAcquire: <Result = unknown>(handle: () => Promise<Result>, options: AcquireLockOptions) => Promise<Result>;
|
|
268
|
+
};
|
|
269
|
+
declare const InProcessLock: () => Lock;
|
|
270
|
+
|
|
254
271
|
declare const merge: <T>(array: T[], item: T, where: (current: T) => boolean, onExisting: (current: T) => T, onNotFound?: () => T | undefined) => T[];
|
|
255
272
|
|
|
256
273
|
type AsyncRetryOptions = retry.Options & {
|
|
@@ -478,6 +495,40 @@ declare const streamTransformations: {
|
|
|
478
495
|
waitAtMost: <Item>(waitTimeInMs: number) => web_streams_polyfill.TransformStream<Item, Item>;
|
|
479
496
|
};
|
|
480
497
|
|
|
498
|
+
type TaskQueue = TaskQueueItem[];
|
|
499
|
+
type TaskQueueItem = {
|
|
500
|
+
task: () => Promise<void>;
|
|
501
|
+
options?: EnqueueTaskOptions;
|
|
502
|
+
};
|
|
503
|
+
type TaskProcessorOptions = {
|
|
504
|
+
maxActiveTasks: number;
|
|
505
|
+
maxQueueSize: number;
|
|
506
|
+
maxTaskIdleTime?: number;
|
|
507
|
+
};
|
|
508
|
+
type Task<T> = (context: TaskContext) => Promise<T>;
|
|
509
|
+
type TaskContext = {
|
|
510
|
+
ack: () => void;
|
|
511
|
+
};
|
|
512
|
+
type EnqueueTaskOptions = {
|
|
513
|
+
taskGroupId?: string;
|
|
514
|
+
};
|
|
515
|
+
declare class TaskProcessor {
|
|
516
|
+
private options;
|
|
517
|
+
private queue;
|
|
518
|
+
private isProcessing;
|
|
519
|
+
private activeTasks;
|
|
520
|
+
private activeGroups;
|
|
521
|
+
constructor(options: TaskProcessorOptions);
|
|
522
|
+
enqueue<T>(task: Task<T>, options?: EnqueueTaskOptions): Promise<T>;
|
|
523
|
+
waitForEndOfProcessing(): Promise<void>;
|
|
524
|
+
private schedule;
|
|
525
|
+
private ensureProcessing;
|
|
526
|
+
private processQueue;
|
|
527
|
+
private executeItem;
|
|
528
|
+
private takeFirstAvailableItem;
|
|
529
|
+
private hasItemsToProcess;
|
|
530
|
+
}
|
|
531
|
+
|
|
481
532
|
declare class AssertionError extends Error {
|
|
482
533
|
constructor(message: string);
|
|
483
534
|
}
|
|
@@ -547,7 +598,7 @@ type ThenThrows<ErrorType extends Error> = (() => void) | ((errorConstructor: Er
|
|
|
547
598
|
type DeciderSpecfication<Command, Event> = (givenEvents: Event | Event[]) => {
|
|
548
599
|
when: (command: Command) => {
|
|
549
600
|
then: (expectedEvents: Event | Event[]) => void;
|
|
550
|
-
|
|
601
|
+
thenNothingHappened: () => void;
|
|
551
602
|
thenThrows: <ErrorType extends Error = Error>(...args: Parameters<ThenThrows<ErrorType>>) => void;
|
|
552
603
|
};
|
|
553
604
|
};
|
|
@@ -584,4 +635,4 @@ declare const assertNotEmptyString: (value: unknown) => string;
|
|
|
584
635
|
declare const assertPositiveNumber: (value: unknown) => number;
|
|
585
636
|
declare const assertUnsignedBigInt: (value: string) => bigint;
|
|
586
637
|
|
|
587
|
-
export { type AggregateStreamOptions, type AggregateStreamResult, type AggregateStreamResultOfEventStore, type AggregateStreamResultWithGlobalPosition, type AppendStreamResultOfEventStore, type AppendToStreamOptions, type AppendToStreamResult, type AppendToStreamResultWithGlobalPosition, type ArgumentMatcher, AssertionError, type AsyncRetryOptions, type BigIntGlobalPosition, type BigIntStreamPosition, BinaryJsonDecoder, type Brand, type CanHandle, CaughtUpTransformStream, type Command, type CommandBus, type CommandDataOf, CommandHandler$1 as CommandHandler, type CommandHandlerOptions, type CommandHandlerResult, type CommandHandlerRetryOptions, CommandHandlerStreamVersionConflictRetryOptions, type CommandMetaDataOf, type CommandProcessor, type CommandSender, type CommandTypeOf, CompositeDecoder, ConcurrencyError, type CreateCommandType, type CreateEventType, type Decider, DeciderCommandHandler, type DeciderCommandHandlerOptions, type DeciderSpecfication, DeciderSpecification, type Decoder, type DeepReadonly, type DefaultCommandMetadata, DefaultDecoder, type DefaultRecord, type Equatable, ErrorConstructor, type Event, type EventBus, type EventDataOf, type EventHandler$1 as EventHandler, type EventMetaDataOf, type EventProcessor, type EventStore, type EventStoreReadEventMetadata, type EventStoreSession, type EventStoreSessionFactory, type EventStoreWrapper, type EventTypeOf, type EventsPublisher, type ExpectedStreamVersion, type ExpectedStreamVersionGeneral, type ExpectedStreamVersionWithValue, ExpectedVersionConflictError, type Flavour, type GlobalPositionTypeOfEventStore, type GlobalPositionTypeOfReadEventMetadata, type GlobalStreamCaughtUp, GlobalStreamCaughtUpType, type GlobalSubscriptionEvent, type HandleOptions, type InMemoryEventStore, InMemoryEventStoreDefaultStreamVersion, JSONParser, JsonDecoder, type Mapper, type MapperArgs, type MessageBus, type MessageHandler, type MessageProcessor, type MessageScheduler, type MockedFunction, type Mutable, NO_CONCURRENCY_CHECK, NoRetries, type NonNullable, ObjectDecoder, ParseError, type ParseOptions, type ProjectionDefinition, type ProjectionHandler, type ProjectionHandlingType, type ProjectionRegistration, type ReadEvent, type ReadEventMetadata, type ReadEventMetadataWithGlobalPosition, type ReadEventMetadataWithoutGlobalPosition, type ReadStreamOptions, type ReadStreamResult, STREAM_DOES_NOT_EXIST, STREAM_EXISTS, type ScheduleOptions, type ScheduledMessage, type ScheduledMessageProcessor, type StreamPositionTypeOfEventStore, type StreamPositionTypeOfReadEventMetadata, StreamingCoordinator, StringDecoder, type StringifyOptions, type TestEventStream, type ThenThrows, type TypedProjectionDefinition, ValidationErrors, type Workflow, type WorkflowCommand, type WorkflowEvent, type WorkflowOutput, WrapEventStore, accept, argMatches, argValue, assertDeepEqual, assertDoesNotThrow, assertEqual, assertExpectedVersionMatchesCurrent, assertFails, assertFalse, assertIsNotNull, assertIsNull, assertMatches, assertNotDeepEqual, assertNotEmptyString, assertNotEqual, assertOk, assertPositiveNumber, assertRejects, assertThat, assertThatArray, assertThrows, assertThrowsAsync, assertTrue, assertUnsignedBigInt, asyncProjections, asyncRetry, canCreateEventStoreSession, caughtUpEventFrom, collect, command, complete, concatUint8Arrays, deepEquals, error, event, formatDateToUtcYYYYMMDD, getInMemoryEventStore, getInMemoryMessageBus, globalStreamCaughtUp, ignore, inlineProjections, isEquatable, isExpectedVersionConflictError, isGlobalStreamCaughtUp, isNotInternalEvent, isNumber, isString, isSubscriptionEvent, isSubset, isValidYYYYMMDD, matchesExpectedVersion, merge, nulloSessionFactory, parseDateFromUtcYYYYMMDD, projection, projections, publish, reply, restream, schedule, send, streamGenerators, streamTrackingGlobalPosition, streamTransformations, sum, verifyThat };
|
|
638
|
+
export { type AcquireLockOptions, type AggregateStreamOptions, type AggregateStreamResult, type AggregateStreamResultOfEventStore, type AggregateStreamResultWithGlobalPosition, type AppendStreamResultOfEventStore, type AppendToStreamOptions, type AppendToStreamResult, type AppendToStreamResultWithGlobalPosition, type ArgumentMatcher, AssertionError, type AsyncRetryOptions, type BigIntGlobalPosition, type BigIntStreamPosition, BinaryJsonDecoder, type Brand, type CanHandle, CaughtUpTransformStream, type Command, type CommandBus, type CommandDataOf, CommandHandler$1 as CommandHandler, type CommandHandlerOptions, type CommandHandlerResult, type CommandHandlerRetryOptions, CommandHandlerStreamVersionConflictRetryOptions, type CommandMetaDataOf, type CommandProcessor, type CommandSender, type CommandTypeOf, CompositeDecoder, ConcurrencyError, type CreateCommandType, type CreateEventType, type Decider, DeciderCommandHandler, type DeciderCommandHandlerOptions, type DeciderSpecfication, DeciderSpecification, type Decoder, type DeepReadonly, type DefaultCommandMetadata, DefaultDecoder, type DefaultRecord, type EnqueueTaskOptions, type Equatable, ErrorConstructor, type Event, type EventBus, type EventDataOf, type EventHandler$1 as EventHandler, type EventMetaDataOf, type EventProcessor, type EventStore, type EventStoreReadEventMetadata, type EventStoreSession, type EventStoreSessionFactory, type EventStoreWrapper, type EventTypeOf, type EventsPublisher, type ExpectedStreamVersion, type ExpectedStreamVersionGeneral, type ExpectedStreamVersionWithValue, ExpectedVersionConflictError, type Flavour, type GlobalPositionTypeOfEventStore, type GlobalPositionTypeOfReadEventMetadata, type GlobalStreamCaughtUp, GlobalStreamCaughtUpType, type GlobalSubscriptionEvent, type HandleOptions, type InMemoryEventStore, InMemoryEventStoreDefaultStreamVersion, InProcessLock, JSONParser, JsonDecoder, type Lock, type LockOptions, type Mapper, type MapperArgs, type MessageBus, type MessageHandler, type MessageProcessor, type MessageScheduler, type MockedFunction, type Mutable, NO_CONCURRENCY_CHECK, NoRetries, type NonNullable, ObjectDecoder, ParseError, type ParseOptions, type ProjectionDefinition, type ProjectionHandler, type ProjectionHandlingType, type ProjectionRegistration, type ReadEvent, type ReadEventMetadata, type ReadEventMetadataWithGlobalPosition, type ReadEventMetadataWithoutGlobalPosition, type ReadStreamOptions, type ReadStreamResult, type ReleaseLockOptions, STREAM_DOES_NOT_EXIST, STREAM_EXISTS, type ScheduleOptions, type ScheduledMessage, type ScheduledMessageProcessor, type StreamPositionTypeOfEventStore, type StreamPositionTypeOfReadEventMetadata, StreamingCoordinator, StringDecoder, type StringifyOptions, type Task, type TaskContext, TaskProcessor, type TaskProcessorOptions, type TaskQueue, type TaskQueueItem, type TestEventStream, type ThenThrows, type TypedProjectionDefinition, ValidationErrors, type Workflow, type WorkflowCommand, type WorkflowEvent, type WorkflowOutput, WrapEventStore, accept, argMatches, argValue, assertDeepEqual, assertDoesNotThrow, assertEqual, assertExpectedVersionMatchesCurrent, assertFails, assertFalse, assertIsNotNull, assertIsNull, assertMatches, assertNotDeepEqual, assertNotEmptyString, assertNotEqual, assertOk, assertPositiveNumber, assertRejects, assertThat, assertThatArray, assertThrows, assertThrowsAsync, assertTrue, assertUnsignedBigInt, asyncProjections, asyncRetry, canCreateEventStoreSession, caughtUpEventFrom, collect, command, complete, concatUint8Arrays, deepEquals, error, event, formatDateToUtcYYYYMMDD, getInMemoryEventStore, getInMemoryMessageBus, globalStreamCaughtUp, ignore, inlineProjections, isEquatable, isExpectedVersionConflictError, isGlobalStreamCaughtUp, isNotInternalEvent, isNumber, isString, isSubscriptionEvent, isSubset, isValidYYYYMMDD, matchesExpectedVersion, merge, nulloSessionFactory, parseDateFromUtcYYYYMMDD, projection, projections, publish, reply, restream, schedule, send, streamGenerators, streamTrackingGlobalPosition, streamTransformations, sum, verifyThat };
|
package/dist/index.d.ts
CHANGED
|
@@ -251,6 +251,23 @@ declare const isEquatable: <T>(left: T) => left is Equatable<T>;
|
|
|
251
251
|
|
|
252
252
|
declare const sum: (iterator: Iterator<number, number, number> | Iterator<number>) => number;
|
|
253
253
|
|
|
254
|
+
type LockOptions = {
|
|
255
|
+
lockId: number;
|
|
256
|
+
};
|
|
257
|
+
type AcquireLockOptions = {
|
|
258
|
+
lockId: string;
|
|
259
|
+
};
|
|
260
|
+
type ReleaseLockOptions = {
|
|
261
|
+
lockId: string;
|
|
262
|
+
};
|
|
263
|
+
type Lock = {
|
|
264
|
+
acquire(options: AcquireLockOptions): Promise<void>;
|
|
265
|
+
tryAcquire(options: AcquireLockOptions): Promise<boolean>;
|
|
266
|
+
release(options: ReleaseLockOptions): Promise<boolean>;
|
|
267
|
+
withAcquire: <Result = unknown>(handle: () => Promise<Result>, options: AcquireLockOptions) => Promise<Result>;
|
|
268
|
+
};
|
|
269
|
+
declare const InProcessLock: () => Lock;
|
|
270
|
+
|
|
254
271
|
declare const merge: <T>(array: T[], item: T, where: (current: T) => boolean, onExisting: (current: T) => T, onNotFound?: () => T | undefined) => T[];
|
|
255
272
|
|
|
256
273
|
type AsyncRetryOptions = retry.Options & {
|
|
@@ -478,6 +495,40 @@ declare const streamTransformations: {
|
|
|
478
495
|
waitAtMost: <Item>(waitTimeInMs: number) => web_streams_polyfill.TransformStream<Item, Item>;
|
|
479
496
|
};
|
|
480
497
|
|
|
498
|
+
type TaskQueue = TaskQueueItem[];
|
|
499
|
+
type TaskQueueItem = {
|
|
500
|
+
task: () => Promise<void>;
|
|
501
|
+
options?: EnqueueTaskOptions;
|
|
502
|
+
};
|
|
503
|
+
type TaskProcessorOptions = {
|
|
504
|
+
maxActiveTasks: number;
|
|
505
|
+
maxQueueSize: number;
|
|
506
|
+
maxTaskIdleTime?: number;
|
|
507
|
+
};
|
|
508
|
+
type Task<T> = (context: TaskContext) => Promise<T>;
|
|
509
|
+
type TaskContext = {
|
|
510
|
+
ack: () => void;
|
|
511
|
+
};
|
|
512
|
+
type EnqueueTaskOptions = {
|
|
513
|
+
taskGroupId?: string;
|
|
514
|
+
};
|
|
515
|
+
declare class TaskProcessor {
|
|
516
|
+
private options;
|
|
517
|
+
private queue;
|
|
518
|
+
private isProcessing;
|
|
519
|
+
private activeTasks;
|
|
520
|
+
private activeGroups;
|
|
521
|
+
constructor(options: TaskProcessorOptions);
|
|
522
|
+
enqueue<T>(task: Task<T>, options?: EnqueueTaskOptions): Promise<T>;
|
|
523
|
+
waitForEndOfProcessing(): Promise<void>;
|
|
524
|
+
private schedule;
|
|
525
|
+
private ensureProcessing;
|
|
526
|
+
private processQueue;
|
|
527
|
+
private executeItem;
|
|
528
|
+
private takeFirstAvailableItem;
|
|
529
|
+
private hasItemsToProcess;
|
|
530
|
+
}
|
|
531
|
+
|
|
481
532
|
declare class AssertionError extends Error {
|
|
482
533
|
constructor(message: string);
|
|
483
534
|
}
|
|
@@ -547,7 +598,7 @@ type ThenThrows<ErrorType extends Error> = (() => void) | ((errorConstructor: Er
|
|
|
547
598
|
type DeciderSpecfication<Command, Event> = (givenEvents: Event | Event[]) => {
|
|
548
599
|
when: (command: Command) => {
|
|
549
600
|
then: (expectedEvents: Event | Event[]) => void;
|
|
550
|
-
|
|
601
|
+
thenNothingHappened: () => void;
|
|
551
602
|
thenThrows: <ErrorType extends Error = Error>(...args: Parameters<ThenThrows<ErrorType>>) => void;
|
|
552
603
|
};
|
|
553
604
|
};
|
|
@@ -584,4 +635,4 @@ declare const assertNotEmptyString: (value: unknown) => string;
|
|
|
584
635
|
declare const assertPositiveNumber: (value: unknown) => number;
|
|
585
636
|
declare const assertUnsignedBigInt: (value: string) => bigint;
|
|
586
637
|
|
|
587
|
-
export { type AggregateStreamOptions, type AggregateStreamResult, type AggregateStreamResultOfEventStore, type AggregateStreamResultWithGlobalPosition, type AppendStreamResultOfEventStore, type AppendToStreamOptions, type AppendToStreamResult, type AppendToStreamResultWithGlobalPosition, type ArgumentMatcher, AssertionError, type AsyncRetryOptions, type BigIntGlobalPosition, type BigIntStreamPosition, BinaryJsonDecoder, type Brand, type CanHandle, CaughtUpTransformStream, type Command, type CommandBus, type CommandDataOf, CommandHandler$1 as CommandHandler, type CommandHandlerOptions, type CommandHandlerResult, type CommandHandlerRetryOptions, CommandHandlerStreamVersionConflictRetryOptions, type CommandMetaDataOf, type CommandProcessor, type CommandSender, type CommandTypeOf, CompositeDecoder, ConcurrencyError, type CreateCommandType, type CreateEventType, type Decider, DeciderCommandHandler, type DeciderCommandHandlerOptions, type DeciderSpecfication, DeciderSpecification, type Decoder, type DeepReadonly, type DefaultCommandMetadata, DefaultDecoder, type DefaultRecord, type Equatable, ErrorConstructor, type Event, type EventBus, type EventDataOf, type EventHandler$1 as EventHandler, type EventMetaDataOf, type EventProcessor, type EventStore, type EventStoreReadEventMetadata, type EventStoreSession, type EventStoreSessionFactory, type EventStoreWrapper, type EventTypeOf, type EventsPublisher, type ExpectedStreamVersion, type ExpectedStreamVersionGeneral, type ExpectedStreamVersionWithValue, ExpectedVersionConflictError, type Flavour, type GlobalPositionTypeOfEventStore, type GlobalPositionTypeOfReadEventMetadata, type GlobalStreamCaughtUp, GlobalStreamCaughtUpType, type GlobalSubscriptionEvent, type HandleOptions, type InMemoryEventStore, InMemoryEventStoreDefaultStreamVersion, JSONParser, JsonDecoder, type Mapper, type MapperArgs, type MessageBus, type MessageHandler, type MessageProcessor, type MessageScheduler, type MockedFunction, type Mutable, NO_CONCURRENCY_CHECK, NoRetries, type NonNullable, ObjectDecoder, ParseError, type ParseOptions, type ProjectionDefinition, type ProjectionHandler, type ProjectionHandlingType, type ProjectionRegistration, type ReadEvent, type ReadEventMetadata, type ReadEventMetadataWithGlobalPosition, type ReadEventMetadataWithoutGlobalPosition, type ReadStreamOptions, type ReadStreamResult, STREAM_DOES_NOT_EXIST, STREAM_EXISTS, type ScheduleOptions, type ScheduledMessage, type ScheduledMessageProcessor, type StreamPositionTypeOfEventStore, type StreamPositionTypeOfReadEventMetadata, StreamingCoordinator, StringDecoder, type StringifyOptions, type TestEventStream, type ThenThrows, type TypedProjectionDefinition, ValidationErrors, type Workflow, type WorkflowCommand, type WorkflowEvent, type WorkflowOutput, WrapEventStore, accept, argMatches, argValue, assertDeepEqual, assertDoesNotThrow, assertEqual, assertExpectedVersionMatchesCurrent, assertFails, assertFalse, assertIsNotNull, assertIsNull, assertMatches, assertNotDeepEqual, assertNotEmptyString, assertNotEqual, assertOk, assertPositiveNumber, assertRejects, assertThat, assertThatArray, assertThrows, assertThrowsAsync, assertTrue, assertUnsignedBigInt, asyncProjections, asyncRetry, canCreateEventStoreSession, caughtUpEventFrom, collect, command, complete, concatUint8Arrays, deepEquals, error, event, formatDateToUtcYYYYMMDD, getInMemoryEventStore, getInMemoryMessageBus, globalStreamCaughtUp, ignore, inlineProjections, isEquatable, isExpectedVersionConflictError, isGlobalStreamCaughtUp, isNotInternalEvent, isNumber, isString, isSubscriptionEvent, isSubset, isValidYYYYMMDD, matchesExpectedVersion, merge, nulloSessionFactory, parseDateFromUtcYYYYMMDD, projection, projections, publish, reply, restream, schedule, send, streamGenerators, streamTrackingGlobalPosition, streamTransformations, sum, verifyThat };
|
|
638
|
+
export { type AcquireLockOptions, type AggregateStreamOptions, type AggregateStreamResult, type AggregateStreamResultOfEventStore, type AggregateStreamResultWithGlobalPosition, type AppendStreamResultOfEventStore, type AppendToStreamOptions, type AppendToStreamResult, type AppendToStreamResultWithGlobalPosition, type ArgumentMatcher, AssertionError, type AsyncRetryOptions, type BigIntGlobalPosition, type BigIntStreamPosition, BinaryJsonDecoder, type Brand, type CanHandle, CaughtUpTransformStream, type Command, type CommandBus, type CommandDataOf, CommandHandler$1 as CommandHandler, type CommandHandlerOptions, type CommandHandlerResult, type CommandHandlerRetryOptions, CommandHandlerStreamVersionConflictRetryOptions, type CommandMetaDataOf, type CommandProcessor, type CommandSender, type CommandTypeOf, CompositeDecoder, ConcurrencyError, type CreateCommandType, type CreateEventType, type Decider, DeciderCommandHandler, type DeciderCommandHandlerOptions, type DeciderSpecfication, DeciderSpecification, type Decoder, type DeepReadonly, type DefaultCommandMetadata, DefaultDecoder, type DefaultRecord, type EnqueueTaskOptions, type Equatable, ErrorConstructor, type Event, type EventBus, type EventDataOf, type EventHandler$1 as EventHandler, type EventMetaDataOf, type EventProcessor, type EventStore, type EventStoreReadEventMetadata, type EventStoreSession, type EventStoreSessionFactory, type EventStoreWrapper, type EventTypeOf, type EventsPublisher, type ExpectedStreamVersion, type ExpectedStreamVersionGeneral, type ExpectedStreamVersionWithValue, ExpectedVersionConflictError, type Flavour, type GlobalPositionTypeOfEventStore, type GlobalPositionTypeOfReadEventMetadata, type GlobalStreamCaughtUp, GlobalStreamCaughtUpType, type GlobalSubscriptionEvent, type HandleOptions, type InMemoryEventStore, InMemoryEventStoreDefaultStreamVersion, InProcessLock, JSONParser, JsonDecoder, type Lock, type LockOptions, type Mapper, type MapperArgs, type MessageBus, type MessageHandler, type MessageProcessor, type MessageScheduler, type MockedFunction, type Mutable, NO_CONCURRENCY_CHECK, NoRetries, type NonNullable, ObjectDecoder, ParseError, type ParseOptions, type ProjectionDefinition, type ProjectionHandler, type ProjectionHandlingType, type ProjectionRegistration, type ReadEvent, type ReadEventMetadata, type ReadEventMetadataWithGlobalPosition, type ReadEventMetadataWithoutGlobalPosition, type ReadStreamOptions, type ReadStreamResult, type ReleaseLockOptions, STREAM_DOES_NOT_EXIST, STREAM_EXISTS, type ScheduleOptions, type ScheduledMessage, type ScheduledMessageProcessor, type StreamPositionTypeOfEventStore, type StreamPositionTypeOfReadEventMetadata, StreamingCoordinator, StringDecoder, type StringifyOptions, type Task, type TaskContext, TaskProcessor, type TaskProcessorOptions, type TaskQueue, type TaskQueueItem, type TestEventStream, type ThenThrows, type TypedProjectionDefinition, ValidationErrors, type Workflow, type WorkflowCommand, type WorkflowEvent, type WorkflowOutput, WrapEventStore, accept, argMatches, argValue, assertDeepEqual, assertDoesNotThrow, assertEqual, assertExpectedVersionMatchesCurrent, assertFails, assertFalse, assertIsNotNull, assertIsNull, assertMatches, assertNotDeepEqual, assertNotEmptyString, assertNotEqual, assertOk, assertPositiveNumber, assertRejects, assertThat, assertThatArray, assertThrows, assertThrowsAsync, assertTrue, assertUnsignedBigInt, asyncProjections, asyncRetry, canCreateEventStoreSession, caughtUpEventFrom, collect, command, complete, concatUint8Arrays, deepEquals, error, event, formatDateToUtcYYYYMMDD, getInMemoryEventStore, getInMemoryMessageBus, globalStreamCaughtUp, ignore, inlineProjections, isEquatable, isExpectedVersionConflictError, isGlobalStreamCaughtUp, isNotInternalEvent, isNumber, isString, isSubscriptionEvent, isSubset, isValidYYYYMMDD, matchesExpectedVersion, merge, nulloSessionFactory, parseDateFromUtcYYYYMMDD, projection, projections, publish, reply, restream, schedule, send, streamGenerators, streamTrackingGlobalPosition, streamTransformations, sum, verifyThat };
|
package/dist/index.js
CHANGED
|
@@ -371,6 +371,178 @@ var sum = (iterator) => {
|
|
|
371
371
|
return sum2;
|
|
372
372
|
};
|
|
373
373
|
|
|
374
|
+
// src/taskProcessing/taskProcessor.ts
|
|
375
|
+
var TaskProcessor = class {
|
|
376
|
+
constructor(options) {
|
|
377
|
+
this.options = options;
|
|
378
|
+
}
|
|
379
|
+
queue = [];
|
|
380
|
+
isProcessing = false;
|
|
381
|
+
activeTasks = 0;
|
|
382
|
+
activeGroups = /* @__PURE__ */ new Set();
|
|
383
|
+
enqueue(task, options) {
|
|
384
|
+
if (this.queue.length >= this.options.maxQueueSize) {
|
|
385
|
+
return Promise.reject(
|
|
386
|
+
new EmmettError(
|
|
387
|
+
"Too many pending connections. Please try again later."
|
|
388
|
+
)
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
return this.schedule(task, options);
|
|
392
|
+
}
|
|
393
|
+
waitForEndOfProcessing() {
|
|
394
|
+
return this.schedule(({ ack }) => Promise.resolve(ack()));
|
|
395
|
+
}
|
|
396
|
+
schedule(task, options) {
|
|
397
|
+
return promiseWithDeadline(
|
|
398
|
+
(resolve, reject) => {
|
|
399
|
+
const taskWithContext = () => {
|
|
400
|
+
return new Promise((resolveTask, failTask) => {
|
|
401
|
+
const taskPromise = task({
|
|
402
|
+
ack: resolveTask
|
|
403
|
+
});
|
|
404
|
+
taskPromise.then(resolve).catch((err) => {
|
|
405
|
+
failTask(err);
|
|
406
|
+
reject(err);
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
this.queue.push({ task: taskWithContext, options });
|
|
411
|
+
if (!this.isProcessing) {
|
|
412
|
+
this.ensureProcessing();
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
{ deadline: this.options.maxTaskIdleTime }
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
ensureProcessing() {
|
|
419
|
+
if (this.isProcessing) return;
|
|
420
|
+
this.isProcessing = true;
|
|
421
|
+
this.processQueue();
|
|
422
|
+
}
|
|
423
|
+
processQueue() {
|
|
424
|
+
try {
|
|
425
|
+
while (this.activeTasks < this.options.maxActiveTasks && this.queue.length > 0) {
|
|
426
|
+
const item = this.takeFirstAvailableItem();
|
|
427
|
+
if (item === null) return;
|
|
428
|
+
const groupId = item.options?.taskGroupId;
|
|
429
|
+
if (groupId) {
|
|
430
|
+
this.activeGroups.add(groupId);
|
|
431
|
+
}
|
|
432
|
+
this.activeTasks++;
|
|
433
|
+
void this.executeItem(item);
|
|
434
|
+
}
|
|
435
|
+
} catch (error2) {
|
|
436
|
+
console.error(error2);
|
|
437
|
+
throw error2;
|
|
438
|
+
} finally {
|
|
439
|
+
this.isProcessing = false;
|
|
440
|
+
if (this.hasItemsToProcess() && this.activeTasks < this.options.maxActiveTasks) {
|
|
441
|
+
this.ensureProcessing();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
async executeItem({ task, options }) {
|
|
446
|
+
try {
|
|
447
|
+
await task();
|
|
448
|
+
} finally {
|
|
449
|
+
this.activeTasks--;
|
|
450
|
+
if (options && options.taskGroupId) {
|
|
451
|
+
this.activeGroups.delete(options.taskGroupId);
|
|
452
|
+
}
|
|
453
|
+
this.ensureProcessing();
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
takeFirstAvailableItem = () => {
|
|
457
|
+
const taskIndex = this.queue.findIndex(
|
|
458
|
+
(item2) => !item2.options?.taskGroupId || !this.activeGroups.has(item2.options.taskGroupId)
|
|
459
|
+
);
|
|
460
|
+
if (taskIndex === -1) {
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
const [item] = this.queue.splice(taskIndex, 1);
|
|
464
|
+
return item ?? null;
|
|
465
|
+
};
|
|
466
|
+
hasItemsToProcess = () => this.queue.findIndex(
|
|
467
|
+
(item) => !item.options?.taskGroupId || !this.activeGroups.has(item.options.taskGroupId)
|
|
468
|
+
) !== -1;
|
|
469
|
+
};
|
|
470
|
+
var DEFAULT_PROMISE_DEADLINE = 2147483647;
|
|
471
|
+
var promiseWithDeadline = (executor, options) => {
|
|
472
|
+
return new Promise((resolve, reject) => {
|
|
473
|
+
let taskStarted = false;
|
|
474
|
+
const maxWaitingTime = options.deadline || DEFAULT_PROMISE_DEADLINE;
|
|
475
|
+
let timeoutId = setTimeout(() => {
|
|
476
|
+
if (!taskStarted) {
|
|
477
|
+
reject(
|
|
478
|
+
new Error("Task was not started within the maximum waiting time")
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
}, maxWaitingTime);
|
|
482
|
+
executor((value) => {
|
|
483
|
+
taskStarted = true;
|
|
484
|
+
if (timeoutId) {
|
|
485
|
+
clearTimeout(timeoutId);
|
|
486
|
+
}
|
|
487
|
+
timeoutId = null;
|
|
488
|
+
resolve(value);
|
|
489
|
+
}, reject);
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
// src/utils/locking/index.ts
|
|
494
|
+
var InProcessLock = () => {
|
|
495
|
+
const taskProcessor = new TaskProcessor({
|
|
496
|
+
maxActiveTasks: Number.MAX_VALUE,
|
|
497
|
+
maxQueueSize: Number.MAX_VALUE
|
|
498
|
+
});
|
|
499
|
+
const locks = /* @__PURE__ */ new Map();
|
|
500
|
+
return {
|
|
501
|
+
async acquire({ lockId }) {
|
|
502
|
+
await new Promise((resolve, reject) => {
|
|
503
|
+
taskProcessor.enqueue(
|
|
504
|
+
({ ack }) => {
|
|
505
|
+
locks.set(lockId, ack);
|
|
506
|
+
resolve();
|
|
507
|
+
return Promise.resolve();
|
|
508
|
+
},
|
|
509
|
+
{ taskGroupId: lockId }
|
|
510
|
+
).catch(reject);
|
|
511
|
+
});
|
|
512
|
+
},
|
|
513
|
+
async tryAcquire({ lockId }) {
|
|
514
|
+
if (locks.has(lockId)) {
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
await this.acquire({ lockId });
|
|
518
|
+
return true;
|
|
519
|
+
},
|
|
520
|
+
release({ lockId }) {
|
|
521
|
+
const ack = locks.get(lockId);
|
|
522
|
+
if (ack === void 0) {
|
|
523
|
+
return Promise.resolve(true);
|
|
524
|
+
}
|
|
525
|
+
locks.delete(lockId);
|
|
526
|
+
ack();
|
|
527
|
+
return Promise.resolve(true);
|
|
528
|
+
},
|
|
529
|
+
async withAcquire(handle, { lockId }) {
|
|
530
|
+
return taskProcessor.enqueue(
|
|
531
|
+
async ({ ack }) => {
|
|
532
|
+
locks.set(lockId, ack);
|
|
533
|
+
try {
|
|
534
|
+
return await handle();
|
|
535
|
+
} finally {
|
|
536
|
+
locks.delete(lockId);
|
|
537
|
+
ack();
|
|
538
|
+
}
|
|
539
|
+
},
|
|
540
|
+
{ taskGroupId: lockId }
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
};
|
|
545
|
+
|
|
374
546
|
// src/utils/merge.ts
|
|
375
547
|
var merge = (array, item, where, onExisting, onNotFound = () => void 0) => {
|
|
376
548
|
let wasFound = false;
|
|
@@ -1223,7 +1395,7 @@ var DeciderSpecification = {
|
|
|
1223
1395
|
expectedEventsArray
|
|
1224
1396
|
);
|
|
1225
1397
|
},
|
|
1226
|
-
|
|
1398
|
+
thenNothingHappened: () => {
|
|
1227
1399
|
const resultEvents = handle();
|
|
1228
1400
|
const resultEventsArray = Array.isArray(resultEvents) ? resultEvents : [resultEvents];
|
|
1229
1401
|
assertThatArray(resultEventsArray).isEmpty();
|
|
@@ -1317,6 +1489,7 @@ export {
|
|
|
1317
1489
|
GlobalStreamCaughtUpType,
|
|
1318
1490
|
IllegalStateError,
|
|
1319
1491
|
InMemoryEventStoreDefaultStreamVersion,
|
|
1492
|
+
InProcessLock,
|
|
1320
1493
|
JSONParser,
|
|
1321
1494
|
JsonDecoder,
|
|
1322
1495
|
NO_CONCURRENCY_CHECK,
|
|
@@ -1328,6 +1501,7 @@ export {
|
|
|
1328
1501
|
STREAM_EXISTS,
|
|
1329
1502
|
StreamingCoordinator,
|
|
1330
1503
|
StringDecoder,
|
|
1504
|
+
TaskProcessor,
|
|
1331
1505
|
ValidationError,
|
|
1332
1506
|
ValidationErrors,
|
|
1333
1507
|
WrapEventStore,
|