@shirudo/ddd-kit 3.0.0-rc.12 → 3.0.0-rc.14
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 +13 -8
- package/dist/chunks/kit-errors.d.ts +30 -31
- package/dist/chunks/kit-errors.js +56 -57
- package/dist/chunks/kit-errors.js.map +1 -1
- package/dist/chunks/read-stream-pages.js +142 -1368
- package/dist/chunks/read-stream-pages.js.map +1 -1
- package/dist/chunks/snapshot-store.d.ts +150 -146
- package/dist/chunks/value-object.js +1275 -0
- package/dist/chunks/value-object.js.map +1 -0
- package/dist/index.d.ts +133 -413
- package/dist/index.js +252 -897
- package/dist/index.js.map +1 -1
- package/dist/money.d.ts +3 -3
- package/dist/money.js +3 -3
- package/dist/money.js.map +1 -1
- package/dist/state-machine.d.ts +227 -0
- package/dist/state-machine.js +673 -0
- package/dist/state-machine.js.map +1 -0
- package/dist/testing.d.ts +4 -4
- package/dist/testing.js +47 -20
- package/dist/testing.js.map +1 -1
- package/package.json +5 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as PendingEventLimitExceededErrorOptions, A as IdempotencyInFlightErrorOptions, B as InvalidEventStreamPageErrorOptions, C as FoldReturnedNoStateError, Ct as UnreplayableAggregateError, D as IdempotencyClaimLostErrorOptions, Dt as isWiringErrorLike, E as IdempotencyClaimLostError, Et as isInfrastructureErrorLike, F as InMemoryCapacityExceededError, G as KitWiringError, H as InvalidVersionError, I as InMemoryCapacityExceededErrorOptions, J as MissingFoldError, K as MisattributedEventError, L as InfrastructureError, M as IdempotencyKeyReuseErrorOptions, N as IdempotencyReconciliationRequiredError, O as IdempotencyCompletionWithoutClaimError, P as IdempotencyReconciliationRequiredErrorOptions, Q as PendingEventLimitExceededError, R as InvalidCommandMessageError, S as EventStreamPageReason, St as UnregisteredHandlerErrorOptions, T as
|
|
2
|
-
import { $ as
|
|
1
|
+
import { $ as PendingEventLimitExceededErrorOptions, A as IdempotencyInFlightErrorOptions, B as InvalidEventStreamPageErrorOptions, C as FoldReturnedNoStateError, Ct as UnreplayableAggregateError, D as IdempotencyClaimLostErrorOptions, Dt as isWiringErrorLike, E as IdempotencyClaimLostError, Et as isInfrastructureErrorLike, F as InMemoryCapacityExceededError, G as KitWiringError, H as InvalidVersionError, I as InMemoryCapacityExceededErrorOptions, J as MissingFoldError, K as MisattributedEventError, L as InfrastructureError, M as IdempotencyKeyReuseErrorOptions, N as IdempotencyReconciliationRequiredError, O as IdempotencyCompletionWithoutClaimError, P as IdempotencyReconciliationRequiredErrorOptions, Q as PendingEventLimitExceededError, R as InvalidCommandMessageError, S as EventStreamPageReason, St as UnregisteredHandlerErrorOptions, T as HandBuiltEventError, Tt as isDomainErrorLike, U as KitErrorCode, V as InvalidIntegrationMessageError, W as KitErrorOptions, X as PendingEventBatchMismatchError, Y as MissingHandlerError, Z as PendingEventBatchMismatchErrorOptions, _ as DuplicateHandlerRegistrationError, _t as UnmanagedInstanceError, a as AggregateNotFoundErrorOptions, at as ReentrantEventRecordingError, b as ErrorMapperFailedErrorOptions, bt as UnregisteredChangesErrorOptions, c as ConcurrencyConflictErrorOptions, ct as ReplayRejectedErrorOptions, d as DirectStateMutationErrorOptions, dt as ReplayTargetMismatchReason, et as ProjectionGapError, f as DomainError, ft as SnapshotCorruptedError, g as DuplicateEventIdErrorOptions, gt as SnapshotVersionNotRestoredErrorOptions, h as DuplicateEventIdError, ht as SnapshotVersionNotRestoredError, i as AggregateNotFoundError, it as PrototypePollutionError, j as IdempotencyKeyReuseError, k as IdempotencyInFlightError, l as ConcurrencyConflictReason, lt as ReplayTargetMismatchError, m as DuplicateAggregateErrorOptions, mt as SnapshotSchemaMismatchErrorOptions, n as AggregateDeletedErrorOptions, nt as ProjectionOrderViolationError, o as CapabilityRegistryConflictError, ot as ReentrantEventRecordingErrorOptions, p as DuplicateAggregateError, pt as SnapshotSchemaMismatchError, q as MissingEntityIdError, r as AggregateIdentityMismatchOptions, rt as ProjectionReceiptViolationError, s as ConcurrencyConflictError, st as ReplayRejectedError, t as AggregateDeletedError, tt as ProjectionIdentityViolationError, u as DirectStateMutationError, ut as ReplayTargetMismatchErrorOptions, v as DuplicateHandlerRegistrationErrorOptions, vt as UnprojectableEventError, w as ForeignEventError, wt as UnreplayableAggregateErrorOptions, x as EventCollectionError, xt as UnregisteredHandlerError, y as ErrorMapperFailedError, yt as UnregisteredChangesError, z as InvalidEventStreamPageError } from "./chunks/kit-errors.js";
|
|
2
|
+
import { $ as PublishOptions, $t as JsonPrimitive, A as IdempotentCommitRequest, At as CreateStampedDomainEventOptions, B as CommitRegistrationOptions, Bt as UnstampedDomainEventOf, C as IdempotencyClaim, Ct as CommittedDomainEvent, D as IdempotencyReconciliation, Dt as AnyUnstampedDomainEvent, E as IdempotencyOperationErrorContext, Et as AnyDomainEvent, F as DeadLetterDeadline, Ft as DomainEventStamp, G as DomainEventStampProvider, Gt as defaultDomainEventFactory, H as WithCommitWorkResult, Ht as createDomainEvent, I as DeadlineStore, It as EventIdFactory, J as TransactionScope, Jt as AggregateIdentity, K as SharedDomainEventStampOptions, Kt as mergeMetadata, L as DueDeadline, Lt as EventMetadata, M as IdempotentExecution, Mt as DomainEvent, N as WithIdempotentCommitDeps, Nt as DomainEventFactory, O as IdempotencyReconciliationDecision, Ot as CreateDomainEventOptions, P as withIdempotentCommit, Pt as DomainEventFactoryOptions, Q as OnceOptions, Qt as JsonObject, R as AggregateCommitToken, Rt as PendingDomainEvent, S as isPositionAfter, St as CommitPosition, T as IdempotencyLease, Tt as EventCommitCandidatePosition, U as withCommit, Ut as createDomainEventFactory, V as WithCommitDeps, Vt as copyMetadata, W as DomainEventStampFactory, Wt as createStampedDomainEvent, X as EventBus, Xt as CommandHandler, Y as TransactionalOptions, Yt as Command, Z as EventHandler, Zt as PublishedCommand, _ as IdentityMap, _t as DispatchTrackingOutbox, a as EventStoreAppendOptions, at as toVersion, b as ProjectionCheckpointStore, bt as OutboxWriter, c as StreamReadResult, ct as CommandCommitOriginCandidate, d as RepositoryTracking, dt as CommandOutboxCommitCandidate, en as JsonValue, et as Aggregate, f as UnitOfWorkIdentityMap, ft as CommandOutboxMapper, g as AggregateClass, gt as DeadLetterRecord, h as PersistenceModel, ht as routeEventsToCommandOutbox, i as EventStore, it as sameVersion, j as IdempotentCommitResult, jt as CreateUnstampedDomainEventOptions, k as IdempotencyStore, kt as CreateDomainEventStampOptions, l as AggregatePersistenceWrite, lt as CommandMessageContent, m as PersistenceLifecycle, mt as DurableCommandMessage, n as ReplayableStreamPages, nt as ReplayableAggregate, o as EventStreamReader, ot as Id, p as PersistenceChanges, pt as CommandOutboxWriter, q as stampPendingEvents, qt as ClockFactory, r as reconstituteAggregateFromStreamPages, rt as Version, s as ReadStreamOptions, st as IdGenerator, t as SnapshotStore, tt as AggregateSnapshot, u as AggregateWriteIntent, ut as CommandMessageRelationships, v as Projection, vt as Outbox, w as IdempotencyClaimHandle, wt as EventCommitCandidate, x as ProjectionPosition, xt as ExecutionContext, y as ProjectionCheckpoint, yt as OutboxRecord, z as CommitRegistration, zt as UnstampedDomainEvent } from "./chunks/snapshot-store.js";
|
|
3
3
|
import { Result } from "@shirudo/result";
|
|
4
4
|
import { ValidationError } from "@shirudo/base-error";
|
|
5
5
|
//#region src/application/cqrs/internal/bus-internals.d.ts
|
|
@@ -788,7 +788,7 @@ interface InMemoryIdempotencyStoreOptions {
|
|
|
788
788
|
*
|
|
789
789
|
* On its own, the store is the reference for the leased family: it cannot
|
|
790
790
|
* see commits or rollbacks. Claims and staged outcomes carry bounded leases,
|
|
791
|
-
* while every mutation compares the store-
|
|
791
|
+
* while every mutation compares the store-issued token. An expired pending
|
|
792
792
|
* claim may be replaced; an expired staged outcome cannot be guessed away and
|
|
793
793
|
* instead returns `reconciliation-required`. Only an authoritative
|
|
794
794
|
* `committed` / `not-committed` decision can settle it.
|
|
@@ -1532,10 +1532,10 @@ interface AggregateTrackingErrorOptions {
|
|
|
1532
1532
|
* A `CommitError` is the **potentially transient** post-completion
|
|
1533
1533
|
* failure (a commit-time serialization failure is the classic case), so
|
|
1534
1534
|
* it is the one a retrying caller should consider re-running. The
|
|
1535
|
-
* deterministic post-completion failure, a
|
|
1535
|
+
* deterministic post-completion failure, a collection-guard violation (an
|
|
1536
1536
|
* event missing `aggregateId` / `aggregateType`, or an eventful persisted
|
|
1537
1537
|
* aggregate that did not advance its version), is a programming bug and surfaces as
|
|
1538
|
-
* {@link
|
|
1538
|
+
* {@link EventCollectionError} instead, which does NOT extend
|
|
1539
1539
|
* `InfrastructureError`, so it stays out of retry paths by construction.
|
|
1540
1540
|
*/
|
|
1541
1541
|
declare class CommitError extends InfrastructureError<"COMMIT_FAILED"> {
|
|
@@ -1563,37 +1563,6 @@ declare class RollbackError extends InfrastructureError<"ROLLBACK_FAILED"> {
|
|
|
1563
1563
|
constructor(cause: unknown, rollbackCause: unknown);
|
|
1564
1564
|
}
|
|
1565
1565
|
//#endregion
|
|
1566
|
-
//#region src/application/unit-of-work/record-pending-events.d.ts
|
|
1567
|
-
/** Minimal shell role accepted by {@link recordPendingEvents}. */
|
|
1568
|
-
type DomainEventStampFactory = Pick<DomainEventFactory, "createStamp">;
|
|
1569
|
-
/** Per-decision stamp provider for metadata that depends on the event. */
|
|
1570
|
-
type DomainEventStampProvider<TEvent extends AnyDomainEvent> = (event: UncommittedDomainEventOf<TEvent>, index: number) => DomainEventStamp;
|
|
1571
|
-
/**
|
|
1572
|
-
* Stamp options that every decision of one recording shares: a recording time
|
|
1573
|
-
* and metadata such as the correlation id of the request. An `eventId` is per
|
|
1574
|
-
* fact, so the factory mints it for each decision.
|
|
1575
|
-
*/
|
|
1576
|
-
type SharedDomainEventStampOptions = Omit<CreateDomainEventStampOptions, "eventId">;
|
|
1577
|
-
/**
|
|
1578
|
-
* Records every still-unstamped event accepted by an aggregate.
|
|
1579
|
-
*
|
|
1580
|
-
* The function is a command that also returns the recorded batch, a
|
|
1581
|
-
* deliberate exception to command-query separation: the caller hands the
|
|
1582
|
-
* batch on to persistence and needs no second read of `pendingEvents`.
|
|
1583
|
-
*
|
|
1584
|
-
* Recording is atomic with respect to the aggregate's pending list: if stamp
|
|
1585
|
-
* creation or validation fails, every decision remains unrecorded. A
|
|
1586
|
-
* successful second call returns the same event objects and does not read the
|
|
1587
|
-
* factory again, which keeps event identity stable across transaction retries.
|
|
1588
|
-
*
|
|
1589
|
-
* Pass a `DomainEventFactory` (only its `createStamp` role is required) for one
|
|
1590
|
-
* uniform recording policy. Add `stampOptions` for metadata that every
|
|
1591
|
-
* decision of the batch shares, such as the correlation id of the request.
|
|
1592
|
-
* Pass a callback instead when metadata depends on the concrete decision.
|
|
1593
|
-
*/
|
|
1594
|
-
declare function recordPendingEvents<TId extends Id<string>, TEvent extends AnyDomainEvent>(aggregate: Aggregate<TId, TEvent>, factory: DomainEventStampFactory, stampOptions?: SharedDomainEventStampOptions): ReadonlyArray<TEvent>;
|
|
1595
|
-
declare function recordPendingEvents<TId extends Id<string>, TEvent extends AnyDomainEvent>(aggregate: Aggregate<TId, TEvent>, createStamp: DomainEventStampProvider<TEvent>): ReadonlyArray<TEvent>;
|
|
1596
|
-
//#endregion
|
|
1597
1566
|
//#region src/application/unit-of-work/unit-of-work.d.ts
|
|
1598
1567
|
/**
|
|
1599
1568
|
* What the application work callback receives: repositories already bound to
|
|
@@ -1624,6 +1593,11 @@ interface RunOptions {
|
|
|
1624
1593
|
* `TransactionScope`. Use `AbortSignal.timeout(ms)` for a deadline.
|
|
1625
1594
|
*/
|
|
1626
1595
|
readonly signal?: AbortSignal;
|
|
1596
|
+
/**
|
|
1597
|
+
* Stamp options that every event stamped in this run shares, for example
|
|
1598
|
+
* the correlation id of the request.
|
|
1599
|
+
*/
|
|
1600
|
+
readonly stampOptions?: SharedDomainEventStampOptions;
|
|
1627
1601
|
}
|
|
1628
1602
|
declare const repositoryDefinitionBrand: unique symbol;
|
|
1629
1603
|
/** Adapter wiring accepted by {@link defineRepository}. */
|
|
@@ -1635,7 +1609,7 @@ interface RepositoryDefinitionOptions<TCtx, TRepositoryPort extends object, TAgg
|
|
|
1635
1609
|
* reach; the static factories stay the only door.
|
|
1636
1610
|
*/
|
|
1637
1611
|
readonly aggregate: AggregateClass<TAggregate>;
|
|
1638
|
-
/** Adapter-owned
|
|
1612
|
+
/** Adapter-owned capture, baseline, and change-set policy. */
|
|
1639
1613
|
readonly persistence: PersistenceModel<TAggregate, TBaseline, TChangeSet>;
|
|
1640
1614
|
/**
|
|
1641
1615
|
* Creates the transaction-bound adapter for the port's non-lifecycle
|
|
@@ -1832,6 +1806,12 @@ interface UnitOfWorkDeps<Evt extends AnyDomainEvent, TCtx, TDefinitions extends
|
|
|
1832
1806
|
* application phase. Default `30000`ms.
|
|
1833
1807
|
*/
|
|
1834
1808
|
postCommitTimeoutMs?: number;
|
|
1809
|
+
/**
|
|
1810
|
+
* See `withCommit`: stamps every pending event that is still unstamped
|
|
1811
|
+
* when `add`, `update`, or `remove` registers its aggregate. Defaults to
|
|
1812
|
+
* `createDomainEventFactory()`.
|
|
1813
|
+
*/
|
|
1814
|
+
eventStampFactory?: DomainEventStampFactory;
|
|
1835
1815
|
repositories: CompatibleRepositoryDefinitions<Evt, TCtx, TDefinitions>;
|
|
1836
1816
|
}
|
|
1837
1817
|
/**
|
|
@@ -1840,7 +1820,7 @@ interface UnitOfWorkDeps<Evt extends AnyDomainEvent, TCtx, TDefinitions extends
|
|
|
1840
1820
|
* transaction and either persist completely or not at all.
|
|
1841
1821
|
*
|
|
1842
1822
|
* Built ON TOP of `withCommit` - the commit orchestration (event
|
|
1843
|
-
*
|
|
1823
|
+
* collection into the outbox inside the transaction, internal acknowledgement
|
|
1844
1824
|
* after the commit, best-effort in-process publish last) is inherited,
|
|
1845
1825
|
* not reimplemented. What this layer adds:
|
|
1846
1826
|
*
|
|
@@ -1906,7 +1886,7 @@ declare class UnitOfWork<Evt extends AnyDomainEvent, TCtx, TDefinitions extends
|
|
|
1906
1886
|
* Execute one unit of work: open the transaction, hand the callback
|
|
1907
1887
|
* tx-bound repositories, commit on resolve, roll back on throw,
|
|
1908
1888
|
* run the post-commit lifecycle (acknowledge, observe, publish) for every
|
|
1909
|
-
*
|
|
1889
|
+
* registered aggregate. Returns the callback's result.
|
|
1910
1890
|
*/
|
|
1911
1891
|
run<R>(work: (context: UnitOfWorkContext<RepositoriesOf<TDefinitions>>) => Promise<R>, options?: RunOptions): Promise<R>;
|
|
1912
1892
|
private buildRepositories;
|
|
@@ -2156,7 +2136,7 @@ declare abstract class Entity<TState, TId extends Id<string>> implements IEntity
|
|
|
2156
2136
|
* `TState` publicly would expose the aggregate's live object graph and
|
|
2157
2137
|
* let nested mutation bypass behavior, validation, versioning, and
|
|
2158
2138
|
* dirty tracking. Concrete entities should expose business-meaningful queries or
|
|
2159
|
-
*
|
|
2139
|
+
* immutable DTOs (`deepFreeze(copyPlainState(this.state))` for a
|
|
2160
2140
|
* plain-data state). Snapshot projection belongs to the persistence
|
|
2161
2141
|
* adapter, which captures the aggregate from outside through those
|
|
2162
2142
|
* queries and DTOs rather than asking the entity to create its own
|
|
@@ -2189,7 +2169,7 @@ declare abstract class Entity<TState, TId extends Id<string>> implements IEntity
|
|
|
2189
2169
|
* widens to the whole graph: NESTED objects are frozen in place too.
|
|
2190
2170
|
*
|
|
2191
2171
|
* @throws MissingEntityIdError when `id` is not a non-blank string.
|
|
2192
|
-
* @throws
|
|
2172
|
+
* @throws PrototypePollutionError when a plain-object, null-prototype,
|
|
2193
2173
|
* or array state carries an own `"__proto__"` data key; validate and
|
|
2194
2174
|
* strip untrusted input at the boundary.
|
|
2195
2175
|
*/
|
|
@@ -2205,23 +2185,11 @@ declare abstract class Entity<TState, TId extends Id<string>> implements IEntity
|
|
|
2205
2185
|
* ownership transfer and is frozen in place; see the constructor.
|
|
2206
2186
|
*
|
|
2207
2187
|
* @param newState - The new state
|
|
2208
|
-
* @throws
|
|
2188
|
+
* @throws PrototypePollutionError when the state carries an own
|
|
2209
2189
|
* `"__proto__"` data key; the previous state is kept.
|
|
2210
2190
|
*/
|
|
2211
2191
|
protected setState(newState: TState): void;
|
|
2212
2192
|
}
|
|
2213
|
-
/**
|
|
2214
|
-
* Shallow-freezes `value` when it's a non-null object or array, so that
|
|
2215
|
-
* direct property writes throw in strict mode. Returns the value as-is for
|
|
2216
|
-
* primitives. `Entity` picks this or {@link deepFreeze} per the
|
|
2217
|
-
* `deepFreezeState` config, so state read through the `state` getter
|
|
2218
|
-
* cannot be mutated from outside, without a deep clone on every read.
|
|
2219
|
-
*
|
|
2220
|
-
* Subclass code stores state through `setState`, which freezes by the
|
|
2221
|
-
* configured mode. The export remains for consumers using it as a
|
|
2222
|
-
* standalone utility.
|
|
2223
|
-
*/
|
|
2224
|
-
declare function freezeShallow<T>(value: T): T;
|
|
2225
2193
|
/**
|
|
2226
2194
|
* Checks if two entities have the same ID.
|
|
2227
2195
|
* Works with any object that has an 'id' property.
|
|
@@ -2303,7 +2271,7 @@ declare function removeEntityById<TId extends Id<string>, T extends Identifiable
|
|
|
2303
2271
|
/**
|
|
2304
2272
|
* Updates an entity with the given ID in the collection.
|
|
2305
2273
|
* Returns a new array with the updated entity.
|
|
2306
|
-
* Structural sharing for adapter-owned persistence
|
|
2274
|
+
* Structural sharing for adapter-owned persistence captures: returns
|
|
2307
2275
|
* the ORIGINAL array when nothing changed (no match, or the element kept
|
|
2308
2276
|
* its reference), so a partial-write adapter can skip the untouched
|
|
2309
2277
|
* collection; a new array only when an
|
|
@@ -2333,7 +2301,7 @@ declare function updateEntityById<TId extends Id<string>, T extends Identifiable
|
|
|
2333
2301
|
/**
|
|
2334
2302
|
* Replaces an entity with the given ID in the collection.
|
|
2335
2303
|
* Returns a new array with the replaced entity.
|
|
2336
|
-
* Structural sharing for adapter-owned persistence
|
|
2304
|
+
* Structural sharing for adapter-owned persistence captures: returns
|
|
2337
2305
|
* the ORIGINAL array when nothing changed (no match, or the element kept
|
|
2338
2306
|
* its reference), so a partial-write adapter can skip the untouched
|
|
2339
2307
|
* collection; a new array only when an
|
|
@@ -2400,8 +2368,8 @@ interface AggregateConfig<TState = unknown> extends EntityConfig<TState> {
|
|
|
2400
2368
|
* tracking, the kit-internal post-commit acknowledgement capability,
|
|
2401
2369
|
* the `markReconstituted` post-load marker, and the `createEvent` helper
|
|
2402
2370
|
* that auto-injects `aggregateId` + `aggregateType` on every event the
|
|
2403
|
-
* aggregate emits. The
|
|
2404
|
-
*
|
|
2371
|
+
* aggregate emits. The commit stamps the pending decisions when it
|
|
2372
|
+
* registers the aggregate, before persistence.
|
|
2405
2373
|
*
|
|
2406
2374
|
* Consumers do NOT extend this class directly; extend
|
|
2407
2375
|
* `StateStoredAggregate` for state-stored aggregates or
|
|
@@ -2459,22 +2427,22 @@ declare abstract class BaseAggregate<TState, TId extends Id<string>, TEvent exte
|
|
|
2459
2427
|
private readonly _maxPendingEvents;
|
|
2460
2428
|
protected constructor(id: TId, initialState: TState, config?: AggregateConfig<TState>);
|
|
2461
2429
|
/**
|
|
2462
|
-
* Stamps every
|
|
2463
|
-
* and time from `createStamp`, passes an already
|
|
2430
|
+
* Stamps every unstamped decision in the pending list with identity
|
|
2431
|
+
* and time from `createStamp`, passes an already stamped event through,
|
|
2464
2432
|
* and replaces the list atomically. Three guards run before the
|
|
2465
|
-
* assignment: an event that no kit constructor
|
|
2466
|
-
* ({@link
|
|
2433
|
+
* assignment: an event that no kit constructor built is rejected
|
|
2434
|
+
* ({@link HandBuiltEventError}); a stamp provider that recorded a new
|
|
2467
2435
|
* decision on this aggregate mid-map is rejected
|
|
2468
2436
|
* ({@link ReentrantEventRecordingError}); and two decisions that
|
|
2469
2437
|
* received one eventId are rejected ({@link DuplicateEventIdError}).
|
|
2470
|
-
* When a guard fires, every decision stays
|
|
2438
|
+
* When a guard fires, every decision stays unstamped.
|
|
2471
2439
|
*/
|
|
2472
2440
|
private recordPendingDecisions;
|
|
2473
2441
|
private acknowledgePendingEvents;
|
|
2474
2442
|
/**
|
|
2475
2443
|
* Post-commit cleanup for the deleted disposition. The row is gone, so
|
|
2476
2444
|
* there is no persisted version to advance: stamping the marker from the
|
|
2477
|
-
* live instance would make a later legitimate re-
|
|
2445
|
+
* live instance would make a later legitimate re-registration of this
|
|
2478
2446
|
* instance trip the unique-cursor guard for a row that does not exist.
|
|
2479
2447
|
*/
|
|
2480
2448
|
private discardPendingEventsAfterDeletion;
|
|
@@ -2536,12 +2504,12 @@ declare abstract class BaseAggregate<TState, TId extends Id<string>, TEvent exte
|
|
|
2536
2504
|
*/
|
|
2537
2505
|
protected markReconstituted(version: Version): void;
|
|
2538
2506
|
/**
|
|
2539
|
-
* Appends a domain event to the pending list. The event must be
|
|
2507
|
+
* Appends a domain event to the pending list. The event must be kit-built
|
|
2540
2508
|
* by a kit constructor; a missing `aggregateId` or `aggregateType` is
|
|
2541
2509
|
* stamped from this aggregate, and an aggregate identity that names another
|
|
2542
2510
|
* aggregate throws {@link MisattributedEventError} before anything is
|
|
2543
2511
|
* recorded. Each append is one fact. A decision appended twice becomes
|
|
2544
|
-
* two facts with distinct ids. A
|
|
2512
|
+
* two facts with distinct ids. A stamped event that is already pending
|
|
2545
2513
|
* throws {@link DuplicateEventIdError}, and a list at `maxPendingEvents`
|
|
2546
2514
|
* throws {@link PendingEventLimitExceededError}, before anything is
|
|
2547
2515
|
* recorded. Prefer the higher-level `StateStoredAggregate.setState()`
|
|
@@ -2556,7 +2524,7 @@ declare abstract class BaseAggregate<TState, TId extends Id<string>, TEvent exte
|
|
|
2556
2524
|
protected addDomainEvent(event: PendingDomainEvent<TEvent>): void;
|
|
2557
2525
|
/**
|
|
2558
2526
|
* One identity per fact, checked before the change becomes observable:
|
|
2559
|
-
* a
|
|
2527
|
+
* a stamped event whose `eventId` is already pending, or appears twice
|
|
2560
2528
|
* in one batch, throws {@link DuplicateEventIdError}. A decision has no
|
|
2561
2529
|
* `eventId` yet, so a stamp provider that reuses one is caught at
|
|
2562
2530
|
* recording instead.
|
|
@@ -2571,7 +2539,7 @@ declare abstract class BaseAggregate<TState, TId extends Id<string>, TEvent exte
|
|
|
2571
2539
|
protected assertPendingEventLimit(added: number): void;
|
|
2572
2540
|
/**
|
|
2573
2541
|
* Appends an event that the caller already passed through
|
|
2574
|
-
* {@link
|
|
2542
|
+
* {@link attributeNewEvent}, {@link assertEventIdsNotPending} and
|
|
2575
2543
|
* {@link assertPendingEventLimit}. `setState()` and `apply()` run the
|
|
2576
2544
|
* three before the state moves and append afterwards, so each gate
|
|
2577
2545
|
* runs once per event.
|
|
@@ -2588,35 +2556,34 @@ declare abstract class BaseAggregate<TState, TId extends Id<string>, TEvent exte
|
|
|
2588
2556
|
* present-but-foreign `aggregateId` / `aggregateType` is a wiring bug and
|
|
2589
2557
|
* throws {@link MisattributedEventError}; missing fields are filled in
|
|
2590
2558
|
* from the aggregate, so a recorded event always carries its full
|
|
2591
|
-
* aggregate identity and can never fail the
|
|
2592
|
-
* later. The
|
|
2593
|
-
* runs first, so
|
|
2559
|
+
* aggregate identity and can never fail the collection or the replay guard
|
|
2560
|
+
* later. The kit-built check
|
|
2561
|
+
* runs first, so a hand-built event fails before anything else. The
|
|
2594
2562
|
* stamped copy is frozen like the original (payload and metadata are
|
|
2595
2563
|
* shared, already deep-frozen by the constructors); a fully stamped
|
|
2596
2564
|
* event is returned as is.
|
|
2597
2565
|
*/
|
|
2598
|
-
protected
|
|
2566
|
+
protected attributeNewEvent<E extends PendingDomainEvent<TEvent>>(event: E): E;
|
|
2599
2567
|
/**
|
|
2600
|
-
*
|
|
2601
|
-
* constructor produced passes. The kit marks two shapes: a
|
|
2602
|
-
* event carries the
|
|
2603
|
-
* `
|
|
2604
|
-
* brand (
|
|
2605
|
-
* helper). Either brand implies deeply frozen with defensively copied
|
|
2568
|
+
* Kit-built check for every recording path: only an event that a kit
|
|
2569
|
+
* constructor produced passes. The kit marks two shapes: a stamped
|
|
2570
|
+
* event carries the stamped brand (`createDomainEvent`,
|
|
2571
|
+
* `createStampedDomainEvent`) and a decision carries the unstamped
|
|
2572
|
+
* brand (the aggregate `createEvent` helper). Either brand implies deeply frozen with defensively copied
|
|
2606
2573
|
* payload and metadata, a guarantee no frozen-ness probe can establish
|
|
2607
2574
|
* (a shallow-frozen literal with mutable nested data would fool it).
|
|
2608
2575
|
* O(1): one brand check per shape.
|
|
2609
2576
|
*/
|
|
2610
|
-
protected
|
|
2577
|
+
protected assertKitBuiltEvent(event: PendingDomainEvent<TEvent>): void;
|
|
2611
2578
|
/**
|
|
2612
2579
|
* Creates the immutable business fact accepted by this aggregate without
|
|
2613
2580
|
* reading a clock, generating an id, or attaching tracing metadata.
|
|
2614
2581
|
*
|
|
2615
|
-
* The
|
|
2616
|
-
*
|
|
2617
|
-
* concrete event producer, rather than in shell-owned
|
|
2582
|
+
* The commit stamps pending events when it registers the aggregate,
|
|
2583
|
+
* before persistence. Payload schema version stays here, next to the
|
|
2584
|
+
* concrete event producer, rather than in shell-owned stamp data.
|
|
2618
2585
|
*/
|
|
2619
|
-
protected createEvent<E extends TEvent>(type: E["type"], payload: E["payload"], options?: Omit<
|
|
2586
|
+
protected createEvent<E extends TEvent>(type: E["type"], payload: E["payload"], options?: Omit<CreateUnstampedDomainEventOptions, "aggregateId" | "aggregateType">): UnstampedDomainEventOf<E>;
|
|
2620
2587
|
}
|
|
2621
2588
|
//#endregion
|
|
2622
2589
|
//#region src/domain/aggregate/event-sourced-aggregate.d.ts
|
|
@@ -2699,7 +2666,7 @@ declare abstract class EventSourcedAggregate<TState, TId extends Id<string>, TEv
|
|
|
2699
2666
|
* the read boundary (see the event-upcasting guide) so the folds
|
|
2700
2667
|
* always receive the current event shape.
|
|
2701
2668
|
*/
|
|
2702
|
-
protected validateEvent(_event:
|
|
2669
|
+
protected validateEvent(_event: UnstampedDomainEventOf<TEvent>): void;
|
|
2703
2670
|
/**
|
|
2704
2671
|
* Always throws {@link DirectStateMutationError}. An event-sourced
|
|
2705
2672
|
* aggregate changes state only through `apply()`, where the fact is
|
|
@@ -2760,7 +2727,7 @@ declare abstract class EventSourcedAggregate<TState, TId extends Id<string>, TEv
|
|
|
2760
2727
|
* stream corruption) after the all-or-nothing rollback. History
|
|
2761
2728
|
* events without the optional aggregate identity fields pass unchecked (the
|
|
2762
2729
|
* fields are optional on the event shape); NEW events are covered
|
|
2763
|
-
* by the stricter `
|
|
2730
|
+
* by the stricter `attributeNewEvent` on the apply path.
|
|
2764
2731
|
*/
|
|
2765
2732
|
private assertReplayedEventBelongsHere;
|
|
2766
2733
|
private fold;
|
|
@@ -2801,16 +2768,16 @@ declare abstract class EventSourcedAggregate<TState, TId extends Id<string>, TEv
|
|
|
2801
2768
|
* state as `null` or as a status field, never as `undefined`.
|
|
2802
2769
|
*
|
|
2803
2770
|
* A fold MUST derive state from `type` and `payload` only. The
|
|
2804
|
-
* parameter is typed as the
|
|
2805
|
-
* folds the event BEFORE the shell
|
|
2806
|
-
* `occurredAt` do not exist yet. Replay folds
|
|
2771
|
+
* parameter is typed as the unstamped shape because a live `apply()`
|
|
2772
|
+
* folds the event BEFORE the shell stamps it: `eventId` and
|
|
2773
|
+
* `occurredAt` do not exist yet. Replay folds stamped events
|
|
2807
2774
|
* through the same map, so those fields ARE present at runtime
|
|
2808
2775
|
* there. A fold that reads them through an escape hatch (`as any`,
|
|
2809
2776
|
* plain JavaScript) sees `undefined` live and a value on replay,
|
|
2810
2777
|
* producing silently divergent state. When a time or identity changes a
|
|
2811
2778
|
* business decision, pass it in the payload.
|
|
2812
2779
|
*/
|
|
2813
|
-
protected abstract readonly folds: { [K in TEvent["type"]]: Fold<TState,
|
|
2780
|
+
protected abstract readonly folds: { [K in TEvent["type"]]: Fold<TState, UnstampedDomainEventOf<Extract<TEvent, {
|
|
2814
2781
|
type: K;
|
|
2815
2782
|
}>>>; };
|
|
2816
2783
|
}
|
|
@@ -2833,13 +2800,13 @@ declare function reconstituteAggregateFromHistory<TAggregate extends ReplayableA
|
|
|
2833
2800
|
* The aggregate owns identity, valid domain state, behavior, its current
|
|
2834
2801
|
* domain version, and pending domain events. It deliberately does not own a
|
|
2835
2802
|
* database baseline or dirty-key bookkeeping. A repository adapter defines
|
|
2836
|
-
* its own persistence
|
|
2803
|
+
* its own persistence capture; the application shell retains that opaque
|
|
2837
2804
|
* baseline and derives the adapter's change set at flush.
|
|
2838
2805
|
*/
|
|
2839
2806
|
declare abstract class StateStoredAggregate<TState, TId extends Id<string>, TEvent extends AnyDomainEvent = never> extends BaseAggregate<TState, TId, TEvent> {
|
|
2840
2807
|
/**
|
|
2841
2808
|
* Replaces the state, advances the OCC version, and records the events
|
|
2842
|
-
* of the change, in that order. State validation, the
|
|
2809
|
+
* of the change, in that order. State validation, the kit-built check,
|
|
2843
2810
|
* the aggregate identity check of the event, the pending event-id check,
|
|
2844
2811
|
* and the pending event limit check run before the change becomes
|
|
2845
2812
|
* observable, so a rejected decision records nothing and moves nothing.
|
|
@@ -2982,230 +2949,6 @@ declare abstract class Specification<T> {
|
|
|
2982
2949
|
*/
|
|
2983
2950
|
declare function specification<T>(name: string, predicate: (candidate: T) => boolean): Specification<T>;
|
|
2984
2951
|
//#endregion
|
|
2985
|
-
//#region src/domain/state-machine/contracts.d.ts
|
|
2986
|
-
/** Base shape for every input accepted by a domain state machine. */
|
|
2987
|
-
type DomainMachineInput = {
|
|
2988
|
-
readonly type: string;
|
|
2989
|
-
};
|
|
2990
|
-
/** Recursively readonly view of data accepted by the domain state machine. */
|
|
2991
|
-
type DomainMachineReadonly<TValue> = TValue extends bigint | boolean | null | number | string | symbol | undefined ? TValue : TValue extends ((...args: never[]) => unknown) ? TValue : TValue extends readonly unknown[] ? { readonly [TKey in keyof TValue]: DomainMachineReadonly<TValue[TKey]>; } : TValue extends object ? { readonly [TKey in keyof TValue]: DomainMachineReadonly<TValue[TKey]>; } : TValue;
|
|
2992
|
-
/** Immutable state and context value suitable for persistence. */
|
|
2993
|
-
type DomainMachineSnapshot<TState extends string, TContext> = {
|
|
2994
|
-
readonly state: TState;
|
|
2995
|
-
readonly context: DomainMachineReadonly<TContext>;
|
|
2996
|
-
};
|
|
2997
|
-
/** Optional context replacement and requested external work from a reducer. */
|
|
2998
|
-
type DomainTransitionResult<TContext, TOutput> = {
|
|
2999
|
-
readonly context?: TContext;
|
|
3000
|
-
readonly outputs?: readonly TOutput[];
|
|
3001
|
-
};
|
|
3002
|
-
/** A guard either allows, generically rejects, or returns a domain-specific rejection. */
|
|
3003
|
-
type DomainTransitionGuardResult = boolean | DomainError;
|
|
3004
|
-
/** A guarded state change and its optional pure context reducer. */
|
|
3005
|
-
type DomainTransition<TState extends string, TContext, TInput extends DomainMachineInput, TOutput, TSource extends TState = TState> = {
|
|
3006
|
-
readonly target: TState;
|
|
3007
|
-
/**
|
|
3008
|
-
* Must be synchronous, deterministic, and side-effect-free. Return a
|
|
3009
|
-
* `DomainError` to provide a typed rejection that `can()` treats as false and
|
|
3010
|
-
* `dispatch()` throws unchanged.
|
|
3011
|
-
*/
|
|
3012
|
-
readonly guard?: (input: {
|
|
3013
|
-
readonly state: TSource;
|
|
3014
|
-
readonly context: DomainMachineReadonly<TContext>;
|
|
3015
|
-
readonly input: DomainMachineReadonly<TInput>;
|
|
3016
|
-
}) => DomainTransitionGuardResult;
|
|
3017
|
-
/** Must be synchronous, deterministic, and side-effect-free. */
|
|
3018
|
-
readonly reduce?: (input: {
|
|
3019
|
-
readonly state: TSource;
|
|
3020
|
-
readonly context: DomainMachineReadonly<TContext>;
|
|
3021
|
-
readonly input: DomainMachineReadonly<TInput>;
|
|
3022
|
-
}) => DomainTransitionResult<TContext, TOutput> | undefined;
|
|
3023
|
-
};
|
|
3024
|
-
/** Configuration for one named control state. */
|
|
3025
|
-
type DomainStateNode<TState extends string, TContext, TInput extends DomainMachineInput, TOutput, TName extends TState = TState> = {
|
|
3026
|
-
readonly terminal?: boolean;
|
|
3027
|
-
/** State-specific context invariant. Must be synchronous, deterministic, and side-effect-free. */
|
|
3028
|
-
readonly validateContext?: (input: {
|
|
3029
|
-
readonly state: TName;
|
|
3030
|
-
readonly context: DomainMachineReadonly<TContext>;
|
|
3031
|
-
}) => boolean;
|
|
3032
|
-
readonly on?: { readonly [TType in TInput["type"]]?: DomainTransition<TState, TContext, Extract<TInput, {
|
|
3033
|
-
readonly type: TType;
|
|
3034
|
-
}>, TOutput, TName>; };
|
|
3035
|
-
};
|
|
3036
|
-
/** Complete, finite domain lifecycle definition. */
|
|
3037
|
-
type DomainMachineDefinition<TState extends string, TContext, TInput extends DomainMachineInput, TOutput = never> = {
|
|
3038
|
-
readonly initial: TState;
|
|
3039
|
-
readonly initialContext: () => TContext;
|
|
3040
|
-
/** Must be synchronous, deterministic, and side-effect-free. */
|
|
3041
|
-
readonly validateSnapshot?: (snapshot: DomainMachineSnapshot<TState, TContext>) => boolean;
|
|
3042
|
-
readonly states: { readonly [TName in TState]: DomainStateNode<TState, TContext, TInput, TOutput, TName>; };
|
|
3043
|
-
};
|
|
3044
|
-
/** Result of a successful transition. */
|
|
3045
|
-
type DomainTransitionOutcome<TState extends string, TContext, TOutput> = {
|
|
3046
|
-
readonly from: TState;
|
|
3047
|
-
readonly to: TState;
|
|
3048
|
-
readonly snapshot: DomainMachineSnapshot<TState, TContext>;
|
|
3049
|
-
readonly outputs: readonly DomainMachineReadonly<TOutput>[];
|
|
3050
|
-
};
|
|
3051
|
-
//#endregion
|
|
3052
|
-
//#region src/domain/state-machine/analyzer.d.ts
|
|
3053
|
-
type DomainMachineDefinitionDiagnostic<TState extends string> = {
|
|
3054
|
-
readonly code: "unreachable-state";
|
|
3055
|
-
readonly state: TState;
|
|
3056
|
-
} | {
|
|
3057
|
-
readonly code: "structural-dead-end";
|
|
3058
|
-
readonly state: TState;
|
|
3059
|
-
} | {
|
|
3060
|
-
readonly code: "no-terminal-path";
|
|
3061
|
-
readonly state: TState;
|
|
3062
|
-
};
|
|
3063
|
-
type DomainMachineTransitionDescription<TState extends string, TInputType extends string> = {
|
|
3064
|
-
readonly state: TState;
|
|
3065
|
-
readonly inputType: TInputType;
|
|
3066
|
-
readonly target: TState;
|
|
3067
|
-
readonly guarded: boolean;
|
|
3068
|
-
};
|
|
3069
|
-
type DomainMachineDefinitionAnalysis<TState extends string, TInputType extends string> = {
|
|
3070
|
-
readonly diagnostics: readonly DomainMachineDefinitionDiagnostic<TState>[];
|
|
3071
|
-
readonly transitions: readonly DomainMachineTransitionDescription<TState, TInputType>[];
|
|
3072
|
-
/** States reachable when every guard is assumed to allow its transition. */
|
|
3073
|
-
readonly structurallyReachableStates: readonly TState[];
|
|
3074
|
-
/** States with a graph path to a terminal state when every guard is assumed to allow it. */
|
|
3075
|
-
readonly statesWithTerminalPath: readonly TState[];
|
|
3076
|
-
};
|
|
3077
|
-
/**
|
|
3078
|
-
* Inspects the declarative transition graph without executing definition callbacks.
|
|
3079
|
-
* Guarded edges are treated as possible edges, so diagnostics never claim more
|
|
3080
|
-
* runtime reachability than the static graph can prove.
|
|
3081
|
-
*/
|
|
3082
|
-
declare function analyzeDomainMachineDefinition<TState extends string, TContext, TInput extends DomainMachineInput, TOutput>(definition: DomainMachineDefinition<TState, TContext, TInput, TOutput>): DomainMachineDefinitionAnalysis<TState, TInput["type"]>;
|
|
3083
|
-
//#endregion
|
|
3084
|
-
//#region src/domain/state-machine/definition.d.ts
|
|
3085
|
-
declare const preparedDefinitionBrand: unique symbol;
|
|
3086
|
-
/**
|
|
3087
|
-
* A machine definition that `prepareDomainMachineDefinition` has
|
|
3088
|
-
* validated, defensively copied, and deeply frozen. Assignable wherever
|
|
3089
|
-
* a plain `DomainMachineDefinition` is accepted; the reverse does NOT
|
|
3090
|
-
* hold (the brand is required), so an API that demands a prepared
|
|
3091
|
-
* definition rejects raw ones at compile time. The pure functions and
|
|
3092
|
-
* the `DomainStateMachine` constructor recognize prepared definitions
|
|
3093
|
-
* at runtime and skip their per-call validate-and-copy.
|
|
3094
|
-
*/
|
|
3095
|
-
type PreparedDomainMachineDefinition<TState extends string, TContext, TInput extends DomainMachineInput, TOutput = never> = DomainMachineDefinition<TState, TContext, TInput, TOutput> & {
|
|
3096
|
-
readonly [preparedDefinitionBrand]: true;
|
|
3097
|
-
};
|
|
3098
|
-
/**
|
|
3099
|
-
* Validates and stabilizes a machine definition ONCE, for repeated use
|
|
3100
|
-
* with the pure functions. Without it, `transitionDomainState` and
|
|
3101
|
-
* `canTransitionDomainState` re-validate and defensively re-copy the
|
|
3102
|
-
* WHOLE definition on every call (the documented safety of the raw
|
|
3103
|
-
* path); on a hot dispatch path that is avoidable O(definition) work.
|
|
3104
|
-
* The `DomainStateMachine` class does the equivalent once in its
|
|
3105
|
-
* constructor; this export brings the same amortization to pure-API
|
|
3106
|
-
* users:
|
|
3107
|
-
*
|
|
3108
|
-
* ```ts
|
|
3109
|
-
* const prepared = prepareDomainMachineDefinition(orderLifecycle);
|
|
3110
|
-
* // per dispatch: no re-validation, no definition copy
|
|
3111
|
-
* const outcome = transitionDomainState(prepared, snapshot, input);
|
|
3112
|
-
* ```
|
|
3113
|
-
*
|
|
3114
|
-
* The returned definition is a deeply frozen copy, isolated from later
|
|
3115
|
-
* mutation of the input object. Preparing an already-prepared
|
|
3116
|
-
* definition returns it unchanged.
|
|
3117
|
-
*/
|
|
3118
|
-
declare function prepareDomainMachineDefinition<TState extends string, TContext, TInput extends DomainMachineInput, TOutput>(definition: DomainMachineDefinition<TState, TContext, TInput, TOutput>): PreparedDomainMachineDefinition<TState, TContext, TInput, TOutput>;
|
|
3119
|
-
//#endregion
|
|
3120
|
-
//#region src/domain/state-machine/errors.d.ts
|
|
3121
|
-
/** No transition is defined for the input in the current state. */
|
|
3122
|
-
declare class InvalidDomainTransitionError extends DomainError<"INVALID_DOMAIN_TRANSITION"> {
|
|
3123
|
-
readonly state: string;
|
|
3124
|
-
readonly inputType: string;
|
|
3125
|
-
constructor(state: string, inputType: string);
|
|
3126
|
-
}
|
|
3127
|
-
/** A defined transition was rejected by its domain guard. */
|
|
3128
|
-
declare class DomainTransitionGuardRejectedError extends DomainError<"DOMAIN_TRANSITION_GUARD_REJECTED"> {
|
|
3129
|
-
readonly state: string;
|
|
3130
|
-
readonly inputType: string;
|
|
3131
|
-
constructor(state: string, inputType: string);
|
|
3132
|
-
}
|
|
3133
|
-
/** The machine definition violates its runtime contract. */
|
|
3134
|
-
declare class InvalidDomainMachineDefinitionError extends KitWiringError<"INVALID_DOMAIN_MACHINE_DEFINITION"> {
|
|
3135
|
-
constructor(message: string, cause?: unknown);
|
|
3136
|
-
}
|
|
3137
|
-
/** Context contains unsupported or unsafe runtime data. */
|
|
3138
|
-
declare class InvalidDomainMachineContextError extends KitWiringError<"INVALID_DOMAIN_MACHINE_CONTEXT"> {
|
|
3139
|
-
constructor(message: string, cause?: unknown);
|
|
3140
|
-
}
|
|
3141
|
-
/** A supplied or produced snapshot is malformed or violates invariants. */
|
|
3142
|
-
declare class InvalidDomainMachineSnapshotError extends KitWiringError<"INVALID_DOMAIN_MACHINE_SNAPSHOT"> {
|
|
3143
|
-
constructor(message: string, cause?: unknown);
|
|
3144
|
-
}
|
|
3145
|
-
/** An input is malformed or contains unsupported runtime data. */
|
|
3146
|
-
declare class InvalidDomainMachineInputError extends KitWiringError<"INVALID_DOMAIN_MACHINE_INPUT"> {
|
|
3147
|
-
constructor(message: string, cause?: unknown);
|
|
3148
|
-
}
|
|
3149
|
-
/** A guard returned a value other than `boolean` or `DomainError`. */
|
|
3150
|
-
declare class InvalidDomainTransitionGuardResultError extends KitWiringError<"INVALID_DOMAIN_TRANSITION_GUARD_RESULT"> {
|
|
3151
|
-
constructor(message: string, cause?: unknown);
|
|
3152
|
-
}
|
|
3153
|
-
/** A reducer returned a malformed result or unsupported output data. */
|
|
3154
|
-
declare class InvalidDomainTransitionResultError extends KitWiringError<"INVALID_DOMAIN_TRANSITION_RESULT"> {
|
|
3155
|
-
constructor(message: string, cause?: unknown);
|
|
3156
|
-
}
|
|
3157
|
-
/** A callback attempted to evaluate the same stateful machine recursively. */
|
|
3158
|
-
declare class ReentrantDomainStateMachineEvaluationError extends KitWiringError<"REENTRANT_DOMAIN_STATE_MACHINE_EVALUATION"> {
|
|
3159
|
-
constructor();
|
|
3160
|
-
}
|
|
3161
|
-
//#endregion
|
|
3162
|
-
//#region src/domain/state-machine/transition.d.ts
|
|
3163
|
-
/** Creates and validates a fresh initial snapshot from a machine definition. */
|
|
3164
|
-
declare function createInitialDomainMachineSnapshot<TState extends string, TContext, TInput extends DomainMachineInput, TOutput>(definition: DomainMachineDefinition<TState, TContext, TInput, TOutput>): DomainMachineSnapshot<TState, TContext>;
|
|
3165
|
-
/**
|
|
3166
|
-
* Checks whether an input currently has an allowed transition.
|
|
3167
|
-
*
|
|
3168
|
-
* Returns `false` for missing transitions, terminal states, rejected guards,
|
|
3169
|
-
* and inputs without an own string `type` property. Invalid payload data for a
|
|
3170
|
-
* matching transition and broken guard code still throw structured errors.
|
|
3171
|
-
*/
|
|
3172
|
-
declare function canTransitionDomainState<TState extends string, TContext, TInput extends DomainMachineInput, TOutput>(definition: DomainMachineDefinition<TState, TContext, TInput, TOutput>, snapshot: DomainMachineSnapshot<TState, TContext>, input: TInput): boolean;
|
|
3173
|
-
/**
|
|
3174
|
-
* Applies one input without mutating the input definition or snapshot.
|
|
3175
|
-
*
|
|
3176
|
-
* @throws {@link InvalidDomainTransitionError} when no transition is defined.
|
|
3177
|
-
* @throws {@link DomainTransitionGuardRejectedError} when its guard rejects.
|
|
3178
|
-
* @throws A concrete `DomainError` returned by a rejecting guard.
|
|
3179
|
-
*/
|
|
3180
|
-
declare function transitionDomainState<TState extends string, TContext, TInput extends DomainMachineInput, TOutput>(definition: DomainMachineDefinition<TState, TContext, TInput, TOutput>, snapshot: DomainMachineSnapshot<TState, TContext>, input: TInput): DomainTransitionOutcome<TState, TContext, TOutput>;
|
|
3181
|
-
//#endregion
|
|
3182
|
-
//#region src/domain/state-machine/domain-state-machine.d.ts
|
|
3183
|
-
/**
|
|
3184
|
-
* Stateful convenience wrapper around the pure domain transition functions.
|
|
3185
|
-
*
|
|
3186
|
-
* Persist {@link snapshot}, not the machine instance. Pass a restored snapshot
|
|
3187
|
-
* to the second constructor overload to validate and reconstitute a machine.
|
|
3188
|
-
*/
|
|
3189
|
-
declare class DomainStateMachine<TState extends string, TContext, TInput extends DomainMachineInput, TOutput = never> {
|
|
3190
|
-
#private;
|
|
3191
|
-
private readonly definition;
|
|
3192
|
-
constructor(definition: DomainMachineDefinition<TState, TContext, TInput, TOutput>);
|
|
3193
|
-
constructor(definition: DomainMachineDefinition<TState, TContext, TInput, TOutput>, snapshot: DomainMachineSnapshot<TState, TContext> | undefined);
|
|
3194
|
-
/** Returns a defensive, deeply frozen copy of the current snapshot. */
|
|
3195
|
-
get snapshot(): DomainMachineSnapshot<TState, TContext>;
|
|
3196
|
-
/** Current named control state. */
|
|
3197
|
-
get state(): TState;
|
|
3198
|
-
/** Current deeply readonly context. */
|
|
3199
|
-
get context(): DomainMachineReadonly<TContext>;
|
|
3200
|
-
/** Whether the current state permanently forbids outgoing transitions. */
|
|
3201
|
-
isTerminal(): boolean;
|
|
3202
|
-
/** Checks a transition without changing the current snapshot. */
|
|
3203
|
-
can(input: TInput): boolean;
|
|
3204
|
-
/** Applies an input and advances the current snapshot on success. */
|
|
3205
|
-
dispatch(input: TInput): DomainTransitionOutcome<TState, TContext, TOutput>;
|
|
3206
|
-
private evaluate;
|
|
3207
|
-
}
|
|
3208
|
-
//#endregion
|
|
3209
2952
|
//#region src/internal/structural/deep-omit.d.ts
|
|
3210
2953
|
type DeepOmitKey = string | symbol;
|
|
3211
2954
|
type DeepOmitPathSegment = string | number | symbol;
|
|
@@ -3253,7 +2996,7 @@ interface DeepOmitOptions {
|
|
|
3253
2996
|
* built via `Object.create(proto)` so the prototype is preserved, but the
|
|
3254
2997
|
* constructor is NOT re-invoked, so class invariants enforced by the
|
|
3255
2998
|
* constructor are not re-checked. `deepOmit` is therefore best used for
|
|
3256
|
-
* comparison/serialisation (`
|
|
2999
|
+
* comparison/serialisation (`valueObjectEqualsExcept`, `deepEqualExcept`), not as
|
|
3257
3000
|
* a general-purpose clone for behaviour-carrying objects.
|
|
3258
3001
|
*
|
|
3259
3002
|
* @param value - The value to create a deep copy from
|
|
@@ -3262,58 +3005,35 @@ interface DeepOmitOptions {
|
|
|
3262
3005
|
*/
|
|
3263
3006
|
declare function deepOmit<T>(value: T, options: DeepOmitOptions): T;
|
|
3264
3007
|
//#endregion
|
|
3265
|
-
//#region src/internal/structural/deep-equal-except.d.ts
|
|
3266
|
-
type DeepEqualExceptOptions = DeepOmitOptions;
|
|
3267
|
-
/**
|
|
3268
|
-
* Performs a deep equality comparison between two values after omitting specified keys.
|
|
3269
|
-
*
|
|
3270
|
-
* This function first removes the specified keys from both values using `deepOmit`,
|
|
3271
|
-
* then performs a deep equality check using `deepEqual`.
|
|
3272
|
-
*
|
|
3273
|
-
* @param a - The first value to compare
|
|
3274
|
-
* @param b - The second value to compare
|
|
3275
|
-
* @param options - Options specifying which keys to omit before comparison
|
|
3276
|
-
* @returns `true` if the values are deeply equal after omitting specified keys, `false` otherwise
|
|
3277
|
-
*
|
|
3278
|
-
* @example
|
|
3279
|
-
* ```ts
|
|
3280
|
-
* const obj1 = { id: 1, name: "Alice", updatedAt: "2024-01-01" };
|
|
3281
|
-
* const obj2 = { id: 2, name: "Alice", updatedAt: "2024-01-02" };
|
|
3282
|
-
*
|
|
3283
|
-
* deepEqualExcept(obj1, obj2, { ignoreKeys: ["id", "updatedAt"] }); // true
|
|
3284
|
-
* ```
|
|
3285
|
-
*/
|
|
3286
|
-
declare function deepEqualExcept(a: unknown, b: unknown, options: DeepEqualExceptOptions): boolean;
|
|
3287
|
-
//#endregion
|
|
3288
3008
|
//#region src/domain/value-object/value-object.d.ts
|
|
3289
|
-
type
|
|
3009
|
+
type ValueObjectOf<T> = Readonly<T>;
|
|
3290
3010
|
declare function deepFreeze<T>(obj: T): Readonly<T>;
|
|
3291
3011
|
/**
|
|
3292
3012
|
* Creates a deeply immutable value object from the given data.
|
|
3293
3013
|
*
|
|
3294
3014
|
* The input is first deep-cloned, then the clone is frozen, so calling
|
|
3295
|
-
* `
|
|
3296
|
-
* side-effect. Mutating the input afterwards does not bleed into the
|
|
3297
|
-
* Symbol-keyed properties are preserved (matching `
|
|
3015
|
+
* `valueObject(input)` never freezes the caller's own object graph as a
|
|
3016
|
+
* side-effect. Mutating the input afterwards does not bleed into the value object.
|
|
3017
|
+
* Symbol-keyed properties are preserved (matching `valueObjectEquals`). A kit
|
|
3298
3018
|
* `ValueObject` instance nested in the input is kept by reference and
|
|
3299
3019
|
* frozen in place; it must keep all of its state in `props`. A value
|
|
3300
3020
|
* object as the input itself is rejected.
|
|
3301
3021
|
* Function values and every other custom class instance are rejected
|
|
3302
3022
|
* (Value Objects are plain data, not behaviour-bearing object graphs). Inputs must be trusted and
|
|
3303
3023
|
* Proxy-free: ECMAScript provides no portable way to identify a transparent
|
|
3304
|
-
* Proxy without potentially executing its traps, so `
|
|
3024
|
+
* Proxy without potentially executing its traps, so `valueObject()` is not a sandbox
|
|
3305
3025
|
* for hostile in-process objects. Built-ins that cannot provide immutable,
|
|
3306
|
-
* value-based semantics are rejected instead of weakening the
|
|
3026
|
+
* value-based semantics are rejected instead of weakening the value object contract.
|
|
3307
3027
|
*
|
|
3308
3028
|
* @example
|
|
3309
3029
|
* ```typescript
|
|
3310
3030
|
* const nested = { lat: 52.5, lng: 13.4 };
|
|
3311
|
-
* const address =
|
|
3031
|
+
* const address = valueObject({ street: "Main St", coordinates: nested });
|
|
3312
3032
|
* address.coordinates.lat = 99; // ❌ Cannot assign to read-only property
|
|
3313
3033
|
* nested.lat = 0; // ✅ caller's input still mutable
|
|
3314
3034
|
* ```
|
|
3315
3035
|
*/
|
|
3316
|
-
declare function
|
|
3036
|
+
declare function valueObject<T>(t: T): ValueObjectOf<T>;
|
|
3317
3037
|
/**
|
|
3318
3038
|
* Compares two value objects for equality based on their values.
|
|
3319
3039
|
* Uses deep equality comparison that handles:
|
|
@@ -3329,22 +3049,22 @@ declare function vo<T>(t: T): VO<T>;
|
|
|
3329
3049
|
*
|
|
3330
3050
|
* @example
|
|
3331
3051
|
* ```typescript
|
|
3332
|
-
* const money1 =
|
|
3333
|
-
* const money2 =
|
|
3334
|
-
*
|
|
3052
|
+
* const money1 = valueObject({ amount: 100, currency: "USD" });
|
|
3053
|
+
* const money2 = valueObject({ amount: 100, currency: "USD" });
|
|
3054
|
+
* valueObjectEquals(money1, money2); // true
|
|
3335
3055
|
*
|
|
3336
|
-
* const address1 =
|
|
3056
|
+
* const address1 = valueObject({
|
|
3337
3057
|
* street: "Main St",
|
|
3338
3058
|
* coordinates: { lat: 52.5, lng: 13.4 }
|
|
3339
3059
|
* });
|
|
3340
|
-
* const address2 =
|
|
3060
|
+
* const address2 = valueObject({
|
|
3341
3061
|
* street: "Main St",
|
|
3342
3062
|
* coordinates: { lat: 52.5, lng: 13.4 }
|
|
3343
3063
|
* });
|
|
3344
|
-
*
|
|
3064
|
+
* valueObjectEquals(address1, address2); // true
|
|
3345
3065
|
* ```
|
|
3346
3066
|
*/
|
|
3347
|
-
declare function
|
|
3067
|
+
declare function valueObjectEquals<T>(a: ValueObjectOf<T>, b: ValueObjectOf<T>): boolean;
|
|
3348
3068
|
/**
|
|
3349
3069
|
* Compares two value objects for equality while ignoring specified keys.
|
|
3350
3070
|
* Useful for comparing value objects that contain metadata or optional fields
|
|
@@ -3363,38 +3083,38 @@ declare function voEquals<T>(a: VO<T>, b: VO<T>): boolean;
|
|
|
3363
3083
|
* @example
|
|
3364
3084
|
* ```typescript
|
|
3365
3085
|
* // Value object with metadata
|
|
3366
|
-
* const address1 =
|
|
3086
|
+
* const address1 = valueObject({
|
|
3367
3087
|
* street: "Main St",
|
|
3368
3088
|
* city: "Berlin",
|
|
3369
3089
|
* metadata: { createdAt: "2024-01-01", updatedAt: "2024-01-02" }
|
|
3370
3090
|
* });
|
|
3371
3091
|
*
|
|
3372
|
-
* const address2 =
|
|
3092
|
+
* const address2 = valueObject({
|
|
3373
3093
|
* street: "Main St",
|
|
3374
3094
|
* city: "Berlin",
|
|
3375
3095
|
* metadata: { createdAt: "2024-01-01", updatedAt: "2024-01-03" }
|
|
3376
3096
|
* });
|
|
3377
3097
|
*
|
|
3378
3098
|
* // Compare ignoring metadata timestamps
|
|
3379
|
-
*
|
|
3099
|
+
* valueObjectEqualsExcept(address1, address2, {
|
|
3380
3100
|
* ignoreKeys: ["updatedAt"],
|
|
3381
3101
|
* ignoreKeyPredicate: (key, path) => path.includes("metadata")
|
|
3382
3102
|
* }); // true
|
|
3383
3103
|
*
|
|
3384
3104
|
* // Compare ignoring all metadata
|
|
3385
|
-
*
|
|
3105
|
+
* valueObjectEqualsExcept(address1, address2, {
|
|
3386
3106
|
* ignoreKeyPredicate: (key, path) => path.includes("metadata")
|
|
3387
3107
|
* }); // true
|
|
3388
3108
|
* ```
|
|
3389
3109
|
*/
|
|
3390
|
-
declare function
|
|
3110
|
+
declare function valueObjectEqualsExcept<T>(a: ValueObjectOf<T>, b: ValueObjectOf<T>, options: DeepOmitOptions): boolean;
|
|
3391
3111
|
/**
|
|
3392
3112
|
* Creates a value object with optional validation.
|
|
3393
3113
|
* Returns a Result type instead of throwing an error.
|
|
3394
3114
|
*
|
|
3395
3115
|
* Note: the Result covers VALIDATION failures only. Non-data values and
|
|
3396
3116
|
* built-ins without immutable value semantics still throw a
|
|
3397
|
-
* `TypeError` from `
|
|
3117
|
+
* `TypeError` from `valueObject()`; they cannot occur in parsed JSON and signal
|
|
3398
3118
|
* a programming error, not a validation failure.
|
|
3399
3119
|
*
|
|
3400
3120
|
* @param t - The data to convert into a value object
|
|
@@ -3404,7 +3124,7 @@ declare function voEqualsExcept<T>(a: VO<T>, b: VO<T>, options: DeepEqualExceptO
|
|
|
3404
3124
|
*
|
|
3405
3125
|
* @example
|
|
3406
3126
|
* ```typescript
|
|
3407
|
-
* const result =
|
|
3127
|
+
* const result = valueObjectOrError(
|
|
3408
3128
|
* { amount: 100, currency: "USD" },
|
|
3409
3129
|
* (m) => m.amount >= 0 && m.currency.length === 3,
|
|
3410
3130
|
* "Invalid money: amount must be non-negative and currency must be 3 characters"
|
|
@@ -3417,7 +3137,7 @@ declare function voEqualsExcept<T>(a: VO<T>, b: VO<T>, options: DeepEqualExceptO
|
|
|
3417
3137
|
* }
|
|
3418
3138
|
* ```
|
|
3419
3139
|
*/
|
|
3420
|
-
declare function
|
|
3140
|
+
declare function valueObjectOrError<T>(t: T, validate: (value: T) => boolean, errorMessage?: string): Result<ValueObjectOf<T>, string>;
|
|
3421
3141
|
/**
|
|
3422
3142
|
* Interface for Value Objects.
|
|
3423
3143
|
* Value Objects are immutable and defined by their properties.
|
|
@@ -3515,16 +3235,16 @@ declare abstract class ValueObject<T extends object> implements IValueObject<T>
|
|
|
3515
3235
|
toJSON(): Readonly<T>;
|
|
3516
3236
|
}
|
|
3517
3237
|
//#endregion
|
|
3518
|
-
//#region src/domain/value-object/
|
|
3238
|
+
//#region src/domain/value-object/value-object-or-issues.d.ts
|
|
3519
3239
|
/**
|
|
3520
3240
|
* Builds an immutable value object while collecting **all** validation
|
|
3521
3241
|
* violations into a single {@link ValidationError}, instead of failing on the
|
|
3522
3242
|
* first one. This is the Result-first, multi-error counterpart to
|
|
3523
|
-
* `
|
|
3243
|
+
* `valueObjectOrError` (which returns a single string message).
|
|
3524
3244
|
*
|
|
3525
3245
|
* The `validate` callback receives a fresh `ValidationError` to push field
|
|
3526
3246
|
* issues onto (via `addIssue` / `addIssues`) and the raw input. When no issue
|
|
3527
|
-
* was recorded the input is frozen into a `
|
|
3247
|
+
* was recorded the input is frozen into a `ValueObjectOf<T>` and returned as `Ok`;
|
|
3528
3248
|
* otherwise the populated `ValidationError` is returned as `Err`.
|
|
3529
3249
|
*
|
|
3530
3250
|
* `ValidationError` comes from `@shirudo/base-error`; import it from there to
|
|
@@ -3534,7 +3254,7 @@ declare abstract class ValueObject<T extends object> implements IValueObject<T>
|
|
|
3534
3254
|
*
|
|
3535
3255
|
* @example
|
|
3536
3256
|
* ```ts
|
|
3537
|
-
* const result =
|
|
3257
|
+
* const result = valueObjectOrIssues(
|
|
3538
3258
|
* { email, age },
|
|
3539
3259
|
* (issues, m) => {
|
|
3540
3260
|
* if (!isEmail(m.email))
|
|
@@ -3547,38 +3267,9 @@ declare abstract class ValueObject<T extends object> implements IValueObject<T>
|
|
|
3547
3267
|
* // result.isErr() → result.error.publicIssues() has both violations
|
|
3548
3268
|
* ```
|
|
3549
3269
|
*/
|
|
3550
|
-
declare function
|
|
3270
|
+
declare function valueObjectOrIssues<T>(t: T, validate: (issues: ValidationError, value: T) => void, message?: string): Result<ValueObjectOf<T>, ValidationError>;
|
|
3551
3271
|
//#endregion
|
|
3552
|
-
//#region src/internal/structural/
|
|
3553
|
-
/**
|
|
3554
|
-
* Performs a deep equality check between two values.
|
|
3555
|
-
*
|
|
3556
|
-
* This function compares values recursively, handling:
|
|
3557
|
-
* - Primitives (with special handling for NaN)
|
|
3558
|
-
* - Arrays (nested arrays supported)
|
|
3559
|
-
* - Objects (plain objects and class instances)
|
|
3560
|
-
* - TypedArrays (Uint8Array, Int32Array, etc.)
|
|
3561
|
-
* - DataView
|
|
3562
|
-
* - Maps and Sets
|
|
3563
|
-
* - Dates and RegExp
|
|
3564
|
-
* - Wrapper objects (Boolean, Number, String)
|
|
3565
|
-
* - Circular references (detected and handled)
|
|
3566
|
-
*
|
|
3567
|
-
* @param a - The first value to compare
|
|
3568
|
-
* @param b - The second value to compare
|
|
3569
|
-
* @returns `true` if the values are deeply equal, `false` otherwise
|
|
3570
|
-
*
|
|
3571
|
-
* @example
|
|
3572
|
-
* ```ts
|
|
3573
|
-
* deepEqual([1, 2, 3], [1, 2, 3]); // true
|
|
3574
|
-
* deepEqual({ a: 1, b: [2, 3] }, { a: 1, b: [2, 3] }); // true
|
|
3575
|
-
* deepEqual(NaN, NaN); // true
|
|
3576
|
-
* deepEqual([1, 2], [1, 2, 3]); // false
|
|
3577
|
-
* ```
|
|
3578
|
-
*/
|
|
3579
|
-
declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
3580
|
-
//#endregion
|
|
3581
|
-
//#region src/internal/structural/detach-state.d.ts
|
|
3272
|
+
//#region src/internal/structural/copy-plain-state.d.ts
|
|
3582
3273
|
/**
|
|
3583
3274
|
* Returns a copy of `state` that shares no object with the original.
|
|
3584
3275
|
* Throws a `TypeError` that names the path when the graph carries a value
|
|
@@ -3587,7 +3278,7 @@ declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
|
3587
3278
|
* symbol-keyed, non-enumerable, or accessor property and an expando on a
|
|
3588
3279
|
* built-in are dropped. A function or a symbol value throws a raw
|
|
3589
3280
|
* `DataCloneError`. An Error, a Promise, a WeakMap, or a WeakSet cannot be
|
|
3590
|
-
*
|
|
3281
|
+
* copied at all. A SharedArrayBuffer and a view over one keep sharing
|
|
3591
3282
|
* their memory. A Proxy fails in the walk or in the clone; a failure in
|
|
3592
3283
|
* the clone is rethrown as a `TypeError` with the cause. An error that a
|
|
3593
3284
|
* Proxy trap throws in the walk passes unchanged, so a coded error of the
|
|
@@ -3616,12 +3307,41 @@ declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
|
3616
3307
|
* throws. A non-enumerable symbol key passes anywhere: it is metadata by
|
|
3617
3308
|
* convention.
|
|
3618
3309
|
*
|
|
3619
|
-
* The concrete entity uses it for
|
|
3310
|
+
* The concrete entity uses it for the plain state of a plain-data
|
|
3620
3311
|
* state. The snapshot model uses it for the captured DTO and the restored
|
|
3621
3312
|
* state. A state that carries a class-based child is mapped to plain data
|
|
3622
3313
|
* first, in the entity or in the model.
|
|
3623
3314
|
*/
|
|
3624
|
-
declare function
|
|
3315
|
+
declare function copyPlainState<T>(state: T, subject?: string): T;
|
|
3316
|
+
//#endregion
|
|
3317
|
+
//#region src/internal/structural/deep-equal.d.ts
|
|
3318
|
+
/**
|
|
3319
|
+
* Performs a deep equality check between two values.
|
|
3320
|
+
*
|
|
3321
|
+
* This function compares values recursively, handling:
|
|
3322
|
+
* - Primitives (with special handling for NaN)
|
|
3323
|
+
* - Arrays (nested arrays supported)
|
|
3324
|
+
* - Objects (plain objects and class instances)
|
|
3325
|
+
* - TypedArrays (Uint8Array, Int32Array, etc.)
|
|
3326
|
+
* - DataView
|
|
3327
|
+
* - Maps and Sets
|
|
3328
|
+
* - Dates and RegExp
|
|
3329
|
+
* - Wrapper objects (Boolean, Number, String)
|
|
3330
|
+
* - Circular references (detected and handled)
|
|
3331
|
+
*
|
|
3332
|
+
* @param a - The first value to compare
|
|
3333
|
+
* @param b - The second value to compare
|
|
3334
|
+
* @returns `true` if the values are deeply equal, `false` otherwise
|
|
3335
|
+
*
|
|
3336
|
+
* @example
|
|
3337
|
+
* ```ts
|
|
3338
|
+
* deepEqual([1, 2, 3], [1, 2, 3]); // true
|
|
3339
|
+
* deepEqual({ a: 1, b: [2, 3] }, { a: 1, b: [2, 3] }); // true
|
|
3340
|
+
* deepEqual(NaN, NaN); // true
|
|
3341
|
+
* deepEqual([1, 2], [1, 2, 3]); // false
|
|
3342
|
+
* ```
|
|
3343
|
+
*/
|
|
3344
|
+
declare function deepEqual(a: unknown, b: unknown): boolean;
|
|
3625
3345
|
//#endregion
|
|
3626
3346
|
//#region src/messaging/event-bus/errors.d.ts
|
|
3627
3347
|
/**
|
|
@@ -3689,7 +3409,7 @@ interface PublishChainState {
|
|
|
3689
3409
|
* ```ts
|
|
3690
3410
|
* import { AsyncLocalStorage } from "node:async_hooks";
|
|
3691
3411
|
*
|
|
3692
|
-
* const bus = new
|
|
3412
|
+
* const bus = new InProcessEventBus<OrderEvent>({
|
|
3693
3413
|
* chainStore: new AsyncLocalStorage<PublishChainState>(),
|
|
3694
3414
|
* });
|
|
3695
3415
|
* ```
|
|
@@ -3767,7 +3487,7 @@ interface EventBusObservers {
|
|
|
3767
3487
|
*/
|
|
3768
3488
|
readonly onSubscriptionThresholdExceeded: (report: SubscriptionThresholdReport) => void;
|
|
3769
3489
|
}
|
|
3770
|
-
/** Construction options for {@link
|
|
3490
|
+
/** Construction options for {@link InProcessEventBus}. */
|
|
3771
3491
|
interface EventBusOptions {
|
|
3772
3492
|
/**
|
|
3773
3493
|
* Subscriptions for one event type above which the bus reports through
|
|
@@ -3812,7 +3532,7 @@ interface EventBusOptions {
|
|
|
3812
3532
|
*
|
|
3813
3533
|
* @example
|
|
3814
3534
|
* ```typescript
|
|
3815
|
-
* const bus = new
|
|
3535
|
+
* const bus = new InProcessEventBus<OrderEvent>();
|
|
3816
3536
|
*
|
|
3817
3537
|
* bus.subscribe("OrderCreated", async (event) => {
|
|
3818
3538
|
* await sendEmail(event.payload.customerId);
|
|
@@ -3872,7 +3592,7 @@ interface EventBusOptions {
|
|
|
3872
3592
|
* the signal.
|
|
3873
3593
|
*
|
|
3874
3594
|
*/
|
|
3875
|
-
declare class
|
|
3595
|
+
declare class InProcessEventBus<Evt extends AnyDomainEvent> implements EventBus<Evt> {
|
|
3876
3596
|
private readonly handlers;
|
|
3877
3597
|
private readonly catchAllHandlers;
|
|
3878
3598
|
private readonly maxPublishDepth;
|
|
@@ -3963,7 +3683,7 @@ declare function encodeIntegrationMessage(message: IntegrationMessage): string;
|
|
|
3963
3683
|
*/
|
|
3964
3684
|
declare function decodeIntegrationMessage(serialized: string): IntegrationMessage;
|
|
3965
3685
|
/**
|
|
3966
|
-
* Composes a validated public message into a
|
|
3686
|
+
* Composes a validated public message into a kit-built local projector input.
|
|
3967
3687
|
* Relationship headers become local event metadata. The public JSON schema is
|
|
3968
3688
|
* retained; producer-private domain types are not reconstructed.
|
|
3969
3689
|
*/
|
|
@@ -4035,9 +3755,9 @@ interface InMemoryOutboxOptions {
|
|
|
4035
3755
|
* another aggregate version. Without an `InMemoryTransactionScope`, it keeps
|
|
4036
3756
|
* the first add of a rolled-back attempt. Dead-lettered and acknowledged
|
|
4037
3757
|
* retries must match the complete original candidate receipt. Reusing an `eventId` for another source or commit position
|
|
4038
|
-
* throws {@link
|
|
3758
|
+
* throws {@link EventCollectionError} while the pending, dead-letter, or bounded
|
|
4039
3759
|
* dispatched receipt still proves the collision. `add` also throws
|
|
4040
|
-
* {@link
|
|
3760
|
+
* {@link EventCollectionError} for a malformed candidate: a part that is not an
|
|
4041
3761
|
* object, an `eventId` or `type` that is not an own string data property, a
|
|
4042
3762
|
* source field that is not a string, or a position that is not a valid
|
|
4043
3763
|
* commit position. Insertion order is preserved:
|
|
@@ -4052,7 +3772,7 @@ interface InMemoryOutboxOptions {
|
|
|
4052
3772
|
* To link future eventful commits, the implementation also retains one
|
|
4053
3773
|
* source cursor per qualified aggregate after dispatch. `endEventSources`
|
|
4054
3774
|
* marks the cursor of a removed aggregate as ended, and a new event of that
|
|
4055
|
-
* source then throws {@link
|
|
3775
|
+
* source then throws {@link EventCollectionError}. Consequently a
|
|
4056
3776
|
* long-lived instance is bounded only when `maxRecords` and `maxSources` are
|
|
4057
3777
|
* configured, plus `maxRetainedDispatchedEventIds`; use a durable adapter with
|
|
4058
3778
|
* an explicit source-head lifecycle and an event-id unique key for unbounded
|
|
@@ -4084,10 +3804,10 @@ interface InMemoryOutboxOptions {
|
|
|
4084
3804
|
*
|
|
4085
3805
|
* @example
|
|
4086
3806
|
* ```ts
|
|
4087
|
-
* import { InMemoryOutbox,
|
|
3807
|
+
* import { InMemoryOutbox, InProcessEventBus } from "@shirudo/ddd-kit";
|
|
4088
3808
|
*
|
|
4089
3809
|
* const outbox = new InMemoryOutbox<OrderEvent>();
|
|
4090
|
-
* const bus = new
|
|
3810
|
+
* const bus = new InProcessEventBus<OrderEvent>();
|
|
4091
3811
|
*
|
|
4092
3812
|
* const uow = makeOrderUnitOfWork({ outbox, bus });
|
|
4093
3813
|
* await uow.run(async ({ repositories }) => {
|
|
@@ -4518,7 +4238,7 @@ interface RetryPolicy {
|
|
|
4518
4238
|
*
|
|
4519
4239
|
* **Classification is by error, not by guesswork.** Only errors the
|
|
4520
4240
|
* `isRetryable` predicate accepts are retried; everything else (a
|
|
4521
|
-
* `DomainError`, `
|
|
4241
|
+
* `DomainError`, `EventCollectionError`, `UnregisteredChangesError`,
|
|
4522
4242
|
* `DuplicateAggregateError`, a non-Error throw) surfaces immediately.
|
|
4523
4243
|
* After `maxAttempts` the last error is rethrown unchanged, so a caller
|
|
4524
4244
|
* can still match `ConcurrencyConflictError` and map it to HTTP 409.
|
|
@@ -4633,7 +4353,7 @@ interface SnapshotModel<TAggregate extends SnapshotAggregate, TSnapshotState> {
|
|
|
4633
4353
|
/** Type-inference helper for declaring an adapter-owned snapshot model. */
|
|
4634
4354
|
declare function defineSnapshotModel<TAggregate extends SnapshotAggregate, TSnapshotState>(model: SnapshotModel<TAggregate, TSnapshotState>): SnapshotModel<TAggregate, TSnapshotState>;
|
|
4635
4355
|
/**
|
|
4636
|
-
* Captures
|
|
4356
|
+
* Captures an independent persistence envelope at an application-supplied time.
|
|
4637
4357
|
* The application decides when snapshotting is worthwhile; this function does
|
|
4638
4358
|
* not read a clock or perform I/O. The envelope is deep-frozen, its `state`
|
|
4639
4359
|
* and its `snapshotAt` included: a write into the captured state or a
|
|
@@ -4660,5 +4380,5 @@ declare function captureAggregateSnapshot<TAggregate extends SnapshotAggregate,
|
|
|
4660
4380
|
*/
|
|
4661
4381
|
declare function reconstituteAggregateFromSnapshot<TAggregate extends SnapshotAggregate, TSnapshotState>(model: SnapshotModel<TAggregate, TSnapshotState>, id: TAggregate["id"], snapshot: AggregateSnapshot<unknown>): TAggregate;
|
|
4662
4382
|
//#endregion
|
|
4663
|
-
export { type AbsentStreamPages, type Aggregate, type AggregateClass, type AggregateCommitToken, type AggregateConfig, AggregateDeletedError, type AggregateDeletedErrorOptions, type AggregateIdentity, type AggregateIdentityMismatchOptions, AggregateNotFoundError, type AggregateNotFoundErrorOptions, type AggregatePersistence, type AggregatePersistenceWrite, type AggregateSnapshot, AggregateTrackingError, type AggregateTrackingErrorOptions, type AggregateTrackingReason, type AggregateWriteIntent, type AggregateWriteRegistration, type AnyDomainEvent, type
|
|
4383
|
+
export { type AbsentStreamPages, type Aggregate, type AggregateClass, type AggregateCommitToken, type AggregateConfig, AggregateDeletedError, type AggregateDeletedErrorOptions, type AggregateIdentity, type AggregateIdentityMismatchOptions, AggregateNotFoundError, type AggregateNotFoundErrorOptions, type AggregatePersistence, type AggregatePersistenceWrite, type AggregateSnapshot, AggregateTrackingError, type AggregateTrackingErrorOptions, type AggregateTrackingReason, type AggregateWriteIntent, type AggregateWriteRegistration, type AnyDomainEvent, type AnyUnstampedDomainEvent, type AppendOnlyWriteRegistration, CapabilityRegistryConflictError, type ClassifyConcurrencyConflictOptions, type ClockFactory, type Command, CommandBus, type CommandBusOptions, type CommandCommitOriginCandidate, type CommandHandler, type CommandMessageContent, type CommandMessageRelationships, type CommandOutboxCommitCandidate, type CommandOutboxMapper, type CommandOutboxWriter, CommitError, type CommitPosition, type CommitRegistration, type CommitRegistrationOptions, type CommittedDomainEvent, type CompatibleRepositoryDefinitions, ConcurrencyConflictError, type ConcurrencyConflictErrorOptions, type ConcurrencyConflictReason, type CreateDomainEventOptions, type CreateDomainEventStampOptions, type CreateStampedDomainEventOptions, type DeadLetterDeadline, type DeadLetterRecord, DeadlineProcessor, type DeadlineProcessorObservers, type DeadlineProcessorOptions, type DeadlineStore, type DeepOmitKey, type DeepOmitOptions, type DeepOmitPathSegment, type DeliveryFailureAssessment, type DeliveryFailureClassifier, type DeliveryFailureKind, DirectStateMutationError, type DirectStateMutationErrorOptions, type DispatchTrackingOutbox, DomainError, type DomainErrorClass, type DomainEvent, type DomainEventFactory, type DomainEventFactoryOptions, type DomainEventStamp, type DomainEventStampFactory, type DomainEventStampProvider, type DomainEventValidationCode, DomainEventValidationError, type DomainEventValidationField, type DueDeadline, DuplicateAggregateError, type DuplicateAggregateErrorOptions, DuplicateEventIdError, type DuplicateEventIdErrorOptions, DuplicateHandlerRegistrationError, type DuplicateHandlerRegistrationErrorOptions, type DurableCommandMessage, Entity, type EntityConfig, ErrorMapperFailedError, type ErrorMapperFailedErrorOptions, type EventBus, EventBusClosedError, type EventBusObservers, type EventBusOptions, EventCollectionError, type EventCommitCandidate, type EventCommitCandidatePosition, type EventHandler, type EventIdFactory, type EventMetadata, EventSourcedAggregate, type EventStore, type EventStoreAppendOptions, type EventStreamPageReason, type EventStreamReader, type ExecutionContext, type FlushStatementReason, FoldReturnedNoStateError, ForeignEventError, HandBuiltEventError, type HandlerFailureReport, type ICommandBus, type IEntity, type IQueryBus, type Id, type IdGenerator, type IdempotencyClaim, type IdempotencyClaimHandle, IdempotencyClaimLostError, type IdempotencyClaimLostErrorOptions, IdempotencyCompletionWithoutClaimError, IdempotencyInFlightError, type IdempotencyInFlightErrorOptions, IdempotencyKeyReuseError, type IdempotencyKeyReuseErrorOptions, type IdempotencyLease, type IdempotencyOperationErrorContext, type IdempotencyReconciliation, type IdempotencyReconciliationDecision, IdempotencyReconciliationRequiredError, type IdempotencyReconciliationRequiredErrorOptions, type IdempotencyStore, type IdempotentCommitRequest, type IdempotentCommitResult, type IdempotentExecution, type Identifiable, IdentityMap, InMemoryCapacityExceededError, type InMemoryCapacityExceededErrorOptions, InMemoryDeadlineStore, type InMemoryDeadlineStoreOptions, InMemoryEventStore, type InMemoryEventStoreOptions, InMemoryIdempotencyStore, type InMemoryIdempotencyStoreOptions, InMemoryOutbox, type InMemoryOutboxOptions, InMemoryProjectionCheckpointStore, type InMemoryProjectionCheckpointStoreOptions, InMemorySnapshotStore, type InMemorySnapshotStoreOptions, type InMemoryTransaction, type InMemoryTransactionParticipant, InMemoryTransactionScope, InProcessEventBus, InfrastructureError, type IntegrationMessage, type IntegrationMessageContent, type IntegrationMessageMapper, type IntegrationMessageRelationships, InvalidCommandMessageError, InvalidEventStreamPageError, type InvalidEventStreamPageErrorOptions, InvalidFlushStatementError, type InvalidFlushStatementErrorOptions, InvalidIntegrationMessageError, InvalidRepositoryAdapterError, type InvalidRepositoryAdapterErrorOptions, type InvalidRepositoryAdapterReason, InvalidRepositoryDefinitionError, InvalidVersionError, type JsonObject, type JsonPrimitive, type JsonValue, type KitErrorCode, type KitErrorOptions, type MatchedRows, MisattributedEventError, MissingEntityIdError, MissingFoldError, MissingHandlerError, NestedUnitOfWorkError, type OnceOptions, type Outbox, OutboxDispatcher, type OutboxDispatcherObservers, type OutboxDispatcherOptions, type OutboxRecord, type OutboxSink, type OutboxWriter, type PendingDomainEvent, PendingEventBatchMismatchError, type PendingEventBatchMismatchErrorOptions, PendingEventLimitExceededError, type PendingEventLimitExceededErrorOptions, type PersistenceChanges, type PersistenceLifecycle, type PersistenceModel, type PhysicalRemovalRegistration, type PinTargetVersionOptions, type PinnedTargetVersion, type ProjectOptions, type Projection, type ProjectionBatchResult, type ProjectionCheckpoint, type ProjectionCheckpointStore, type ProjectionEventHandler, type ProjectionFromHandlersOptions, ProjectionGapError, type ProjectionHandlers, ProjectionIdentityViolationError, ProjectionOrderViolationError, type ProjectionPosition, ProjectionReceiptViolationError, Projector, type ProjectorOptions, PrototypePollutionError, type PublishAbortedReport, type PublishChainState, type PublishChainStore, PublishDepthExceededError, type PublishOptions, type PublishedCommand, type Query, QueryBus, type QueryBusOptions, type QueryHandler, type ReachableStreamPages, type ReadStreamOptions, type ReadStreamPagesOptions, ReentrantEventRecordingError, type ReentrantEventRecordingErrorOptions, ReplayRejectedError, type ReplayRejectedErrorOptions, ReplayTargetMismatchError, type ReplayTargetMismatchErrorOptions, type ReplayTargetMismatchReason, type ReplayableAggregate, type ReplayableStreamPages, type RepositoriesOf, type Repository, type RepositoryDefinition, type RepositoryDefinitionOptions, RepositoryErrorMappingFailedError, type RepositoryErrorMappingFailedErrorOptions, type RepositoryTracking, type RetryPolicy, RetryingTransactionScope, RollbackError, type RunOptions, type SharedDomainEventStampOptions, SnapshotCorruptedError, type SnapshotModel, SnapshotSchemaMismatchError, type SnapshotSchemaMismatchErrorOptions, type SnapshotStore, SnapshotTimeValidationError, SnapshotVersionNotRestoredError, type SnapshotVersionNotRestoredErrorOptions, Specification, type SpecificationComposite, StateStoredAggregate, type StateValidator, type StreamPages, type StreamReadResult, type SubscriptionThresholdReport, TransactionClosedError, type TransactionScope, type TransactionalOptions, UnitOfWork, type UnitOfWorkContext, type UnitOfWorkDeps, type UnitOfWorkIdentityMap, UnmanagedInstanceError, UnprojectableEventError, type UnreachableStreamPages, UnregisteredChangesError, type UnregisteredChangesErrorOptions, UnregisteredHandlerError, type UnregisteredHandlerErrorOptions, UnreplayableAggregateError, type UnreplayableAggregateErrorOptions, type UnstampedDomainEvent, type UnstampedDomainEventOf, ValueObject, type ValueObjectOf, type Version, type VersionedFlushStatements, type VersionedWrite, type WithCommitDeps, type WithCommitWorkResult, type WithIdempotentCommitDeps, captureAggregateSnapshot, classifyConcurrencyConflict, copyMetadata, copyPlainState, createDomainEvent, createDomainEventFactory, createIntegrationMessage, createStampedDomainEvent, decodeIntegrationMessage, deepEqual, deepFreeze, deepOmit, defaultDomainEventFactory, defineRepository, defineSnapshotModel, domainErrorToResult, encodeIntegrationMessage, entityIds, eventBusSink, findEntityById, hasEntityId, ignoreProjectionEvent, integrationMessageToCommittedEvent, isDomainErrorLike, isInfrastructureErrorLike, isPositionAfter, isWiringErrorLike, mergeMetadata, outboxWriterAcceptingEventLoss, pinTargetVersion, projectionFromHandlers, readStreamPages, reconstituteAggregateFromHistory, reconstituteAggregateFromSnapshot, reconstituteAggregateFromStreamPages, removeEntityById, replaceEntityById, routeEventsToCommandOutbox, sameEntity, sameVersion, specification, stampPendingEvents, toVersion, updateEntityById, valueObject, valueObjectEquals, valueObjectEqualsExcept, valueObjectOrError, valueObjectOrIssues, versionedFlush, withCommit, withIdempotentCommit };
|
|
4664
4384
|
//# sourceMappingURL=index.d.ts.map
|