@shirudo/ddd-kit 3.0.0-rc.12 → 3.0.0-rc.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { f as DomainError, ot as ReplayRejectedError } from "./kit-errors.js";
1
+ import { f as DomainError, st as ReplayRejectedError } from "./kit-errors.js";
2
2
  import { Result } from "@shirudo/result";
3
3
  //#region src/internal/json-value.d.ts
4
4
  /** A primitive value represented without loss by JSON. */
@@ -250,7 +250,7 @@ interface EventMetadata {
250
250
  * Events are immutable and carry information about what occurred.
251
251
  *
252
252
  * **Events are PLAIN DATA objects**, constructed via `createDomainEvent`
253
- * (or the aggregate's `createEvent` plus application-shell recording path)
253
+ * (or the aggregate's `createEvent` plus application-shell stamping)
254
254
  * and deeply frozen. Class-based
255
255
  * event objects that satisfy this shape structurally via prototype
256
256
  * members are unsupported.
@@ -321,29 +321,29 @@ interface DomainEvent<T extends string, P = void> {
321
321
  */
322
322
  type AnyDomainEvent = DomainEvent<string, unknown>;
323
323
  /**
324
- * A domain event accepted by an aggregate but not yet given its recording
325
- * identity, recording time, or delivery metadata.
324
+ * A domain event accepted by an aggregate but not yet given its event id,
325
+ * stamp time, or delivery metadata.
326
326
  *
327
327
  * The aggregate owns the event type, payload, source aggregate identity,
328
328
  * and payload schema version because those values describe the business
329
329
  * fact it produced.
330
330
  * The application shell later turns this value into a {@link DomainEvent}.
331
331
  */
332
- interface UncommittedDomainEvent<T extends string, P = void> {
332
+ interface UnstampedDomainEvent<T extends string, P = void> {
333
333
  readonly type: T;
334
334
  readonly aggregateId?: string;
335
335
  readonly aggregateType?: string;
336
336
  readonly payload: P;
337
337
  readonly schemaVersion: number;
338
338
  }
339
- /** Upper-bound alias for any uncommitted domain-event shape. */
340
- type AnyUncommittedDomainEvent = UncommittedDomainEvent<string, unknown>;
341
- /** Derives the uncommitted shape represented by a concrete event or event union. */
342
- type UncommittedDomainEventOf<TEvent extends AnyDomainEvent> = TEvent extends DomainEvent<infer TType, infer TPayload> ? UncommittedDomainEvent<TType, TPayload> : never;
343
- /** An aggregate may hold unstamped decisions and already recorded events together. */
344
- type PendingDomainEvent<TEvent extends AnyDomainEvent> = TEvent | UncommittedDomainEventOf<TEvent>;
345
- /** Producer-owned options for an uncommitted event. */
346
- interface CreateUncommittedDomainEventOptions {
339
+ /** Upper-bound alias for any unstamped domain-event shape. */
340
+ type AnyUnstampedDomainEvent = UnstampedDomainEvent<string, unknown>;
341
+ /** Derives the unstamped shape represented by a concrete event or event union. */
342
+ type UnstampedDomainEventOf<TEvent extends AnyDomainEvent> = TEvent extends DomainEvent<infer TType, infer TPayload> ? UnstampedDomainEvent<TType, TPayload> : never;
343
+ /** An aggregate may hold unstamped decisions and already stamped events together. */
344
+ type PendingDomainEvent<TEvent extends AnyDomainEvent> = TEvent | UnstampedDomainEventOf<TEvent>;
345
+ /** Producer-owned options for an unstamped event. */
346
+ interface CreateUnstampedDomainEventOptions {
347
347
  readonly aggregateId?: string;
348
348
  readonly aggregateType?: string;
349
349
  readonly schemaVersion?: number;
@@ -379,7 +379,7 @@ interface CreateDomainEventOptions {
379
379
  */
380
380
  metadata?: EventMetadata;
381
381
  }
382
- /** Technical recording data attached by the application shell. */
382
+ /** Technical stamp data attached by the application shell. */
383
383
  interface DomainEventStamp {
384
384
  /** Stable identity for this event instance. */
385
385
  readonly eventId: string;
@@ -389,7 +389,7 @@ interface DomainEventStamp {
389
389
  readonly metadata?: EventMetadata;
390
390
  }
391
391
  /** Full strict-construction options, including producer-owned event fields. */
392
- interface CreateDomainEventFromFactsOptions extends DomainEventStamp {
392
+ interface CreateStampedDomainEventOptions extends DomainEventStamp {
393
393
  readonly aggregateId?: string;
394
394
  readonly aggregateType?: string;
395
395
  readonly schemaVersion?: number;
@@ -407,11 +407,11 @@ interface DomainEventFactoryOptions {
407
407
  /** Event-recording clock. Defaults to `() => new Date()`. */
408
408
  readonly clock?: ClockFactory;
409
409
  /**
410
- * Origin stamped on every event this factory mints, unless the call site
410
+ * Origin stamped on every event this factory builds, unless the call site
411
411
  * names one itself.
412
412
  *
413
413
  * A plain value, not a factory like the two above. Those produce a new
414
- * value for each event. An origin identifies the system that mints them
414
+ * value for each event. An origin identifies the system that builds them
415
415
  * and does not change between two of them.
416
416
  */
417
417
  readonly source?: string;
@@ -423,7 +423,7 @@ interface DomainEventFactoryOptions {
423
423
  */
424
424
  interface DomainEventFactory {
425
425
  /**
426
- * Creates immutable technical recording data in the application shell.
426
+ * Creates immutable technical stamp data in the application shell.
427
427
  */
428
428
  readonly createStamp: (options?: CreateDomainEventStampOptions) => DomainEventStamp;
429
429
  readonly create: {
@@ -454,7 +454,7 @@ interface DomainEventFactory {
454
454
  * clock: () => new Date(),
455
455
  * });
456
456
  * order.confirm();
457
- * recordPendingEvents(order, domainEvents);
457
+ * stampPendingEvents(order, domainEvents);
458
458
  * ```
459
459
  */
460
460
  declare function createDomainEventFactory(options?: DomainEventFactoryOptions): DomainEventFactory;
@@ -464,21 +464,6 @@ declare function createDomainEventFactory(options?: DomainEventFactoryOptions):
464
464
  * with {@link createDomainEventFactory} for custom policy.
465
465
  */
466
466
  declare const defaultDomainEventFactory: DomainEventFactory;
467
- /**
468
- * Creates an uncommitted domain event: the event that an aggregate method
469
- * returns before the application shell records it. The payload and the
470
- * metadata follow the input ownership rule of {@link createDomainEvent}.
471
- */
472
- declare function createUncommittedDomainEvent<T extends string>(type: T, payload?: undefined, options?: CreateUncommittedDomainEventOptions): UncommittedDomainEvent<T, void>;
473
- declare function createUncommittedDomainEvent<T extends string, P>(type: T, payload: P, options?: CreateUncommittedDomainEventOptions): UncommittedDomainEvent<T, P>;
474
- /**
475
- * Attaches shell-owned recording data to an accepted aggregate decision.
476
- *
477
- * The decision supplies the domain type, payload, source aggregate
478
- * identity, and payload schema version. The stamp supplies only event
479
- * identity, recording time, and trace metadata.
480
- */
481
- declare function recordDomainEvent<T extends string, P>(event: UncommittedDomainEvent<T, P>, stamp: DomainEventStamp): DomainEvent<T, P>;
482
467
  /**
483
468
  * Creates a domain event with default values.
484
469
  * Sets occurredAt to current date and schemaVersion to 1 if not provided.
@@ -486,7 +471,7 @@ declare function recordDomainEvent<T extends string, P>(event: UncommittedDomain
486
471
  * **Input ownership.** The event is deeply frozen, and `payload` and
487
472
  * `metadata` are deep-cloned first, so the caller's own objects are never
488
473
  * frozen in place and later mutation of them does not bleed into the event
489
- * (same contract as `vo()`). The event data rule checks the data before the
474
+ * (same contract as `valueObject()`). The event data rule checks the data before the
490
475
  * copy and the copy after it. So the copy loses no data without an error,
491
476
  * and no getter of the data runs. The in-memory event store applies the
492
477
  * same rule on append. The checks catch accidents, not a hostile `Proxy`: a
@@ -510,8 +495,8 @@ declare function recordDomainEvent<T extends string, P>(event: UncommittedDomain
510
495
  * route by. The commit boundary validates that both fields are present
511
496
  * and throws if they are missing, so a direct `createDomainEvent(...)`
512
497
  * call inside an aggregate that forgets the options is caught at
513
- * runtime. Record pending decisions in the application
514
- * shell before repository persistence or outbox harvest.
498
+ * runtime. Stamp pending decisions in the application
499
+ * shell before repository persistence or outbox collection.
515
500
  *
516
501
  * Use `createDomainEvent(...)` directly for events that don't belong to
517
502
  * an aggregate: system events, integration events, configuration events,
@@ -532,17 +517,17 @@ declare function recordDomainEvent<T extends string, P>(event: UncommittedDomain
532
517
  declare function createDomainEvent<T extends string>(type: T, payload?: undefined, options?: CreateDomainEventOptions): DomainEvent<T, void>;
533
518
  declare function createDomainEvent<T extends string, P>(type: T, payload: P, options?: CreateDomainEventOptions): DomainEvent<T, P>;
534
519
  /**
535
- * Creates an already minted domain event exclusively from explicit envelope
520
+ * Creates a kit-built, stamped domain event exclusively from explicit envelope
536
521
  * facts. Unlike {@link createDomainEvent}, it has no clock or event-id fallback
537
522
  * and is useful when replay, migration, or a caller-owned boundary already has
538
523
  * the final identity and occurrence time.
539
524
  *
540
- * Aggregate behavior normally creates an {@link UncommittedDomainEvent} through
525
+ * Aggregate behavior normally creates an {@link UnstampedDomainEvent} through
541
526
  * its protected `createEvent` helper. The application shell later records that
542
527
  * pending fact with caller-owned time and identity.
543
528
  */
544
- declare function createDomainEventFromFacts<T extends string>(type: T, payload: undefined, options: CreateDomainEventFromFactsOptions): DomainEvent<T, void>;
545
- declare function createDomainEventFromFacts<T extends string, P>(type: T, payload: P, options: CreateDomainEventFromFactsOptions): DomainEvent<T, P>;
529
+ declare function createStampedDomainEvent<T extends string>(type: T, payload: undefined, options: CreateStampedDomainEventOptions): DomainEvent<T, void>;
530
+ declare function createStampedDomainEvent<T extends string, P>(type: T, payload: P, options: CreateStampedDomainEventOptions): DomainEvent<T, P>;
546
531
  /**
547
532
  * Copies metadata from a source event to a new event.
548
533
  * Useful for maintaining correlation chains in event-driven architectures.
@@ -1065,7 +1050,7 @@ interface ReplayableAggregate<TId extends Id<string>, TEvent extends AnyDomainEv
1065
1050
  * decisions, or a fold records one
1066
1051
  * @throws MissingFoldError when no fold is declared for an event type
1067
1052
  * @throws FoldReturnedNoStateError when a fold returns `undefined`
1068
- * @throws HostileStateKeyError when the folded state carries an own
1053
+ * @throws PrototypePollutionError when the folded state carries an own
1069
1054
  * `__proto__` key
1070
1055
  */
1071
1056
  replayHistory(history: ReadonlyArray<TEvent>): Result<void, DomainError>;
@@ -1477,9 +1462,9 @@ interface WithCommitDeps<Evt extends AnyDomainEvent, TCtx> {
1477
1462
  }
1478
1463
  declare const aggregateCommitTokenBrand: unique symbol;
1479
1464
  /**
1480
- * Opaque receipt that one aggregate was explicitly enrolled in the current
1481
- * {@link withCommit} invocation. Tokens are minted only by the invocation's
1482
- * {@link CommitEnrollment} capability and are bound to that invocation at
1465
+ * Opaque receipt that one aggregate was explicitly registered in the current
1466
+ * {@link withCommit} invocation. Tokens are issued only by the invocation's
1467
+ * {@link CommitRegistration} capability and are bound to that invocation at
1483
1468
  * runtime; a forged token or one retained from an earlier call is rejected
1484
1469
  * inside the transaction.
1485
1470
  */
@@ -1487,26 +1472,26 @@ interface AggregateCommitToken<Evt extends AnyDomainEvent = AnyDomainEvent> {
1487
1472
  readonly [aggregateCommitTokenBrand]: Evt;
1488
1473
  }
1489
1474
  /**
1490
- * Invocation-scoped enrollment capability handed to a {@link withCommit}
1491
- * callback. Call `enrollSaved` only for an aggregate participating in the
1475
+ * Invocation-scoped registration capability handed to a {@link withCommit}
1476
+ * callback. Call `registerSaved` only for an aggregate participating in the
1492
1477
  * repository write, and return every resulting token in `commits`. Omitting
1493
- * any token rejects the transaction: an enrolled write may not commit without
1494
- * its event harvest and post-commit acknowledgement. Enrollable instances
1478
+ * any token rejects the transaction: a registered write may not commit without
1479
+ * its event collection and post-commit acknowledgement. Registrable instances
1495
1480
  * must extend `StateStoredAggregate` or `EventSourcedAggregate`; structural
1496
1481
  * `Aggregate` lookalikes have no internal lifecycle capability and fail
1497
1482
  * before commit.
1498
1483
  */
1499
- interface CommitEnrollment<Evt extends AnyDomainEvent> {
1500
- enrollSaved(aggregate: Aggregate<Id<string>, Evt>, options?: CommitEnrollmentOptions): AggregateCommitToken<Evt>;
1484
+ interface CommitRegistration<Evt extends AnyDomainEvent> {
1485
+ registerSaved(aggregate: Aggregate<Id<string>, Evt>, options?: CommitRegistrationOptions): AggregateCommitToken<Evt>;
1501
1486
  /**
1502
- * Enroll an aggregate whose row is deleted by the current transaction.
1503
- * Its events are harvested and discarded after commit, but the saved-only
1487
+ * Register an aggregate whose row the current transaction removes.
1488
+ * Its events are collected and discarded after commit, but the saved-only
1504
1489
  * application `onPersisted` observer is not called.
1505
1490
  */
1506
- enrollDeleted(aggregate: Aggregate<Id<string>, Evt>, options?: CommitEnrollmentOptions): AggregateCommitToken<Evt>;
1491
+ registerRemoved(aggregate: Aggregate<Id<string>, Evt>, options?: CommitRegistrationOptions): AggregateCommitToken<Evt>;
1507
1492
  }
1508
- /** OCC baseline associated with one exact commit enrollment. */
1509
- interface CommitEnrollmentOptions {
1493
+ /** OCC baseline associated with one exact commit registration. */
1494
+ interface CommitRegistrationOptions {
1510
1495
  /** Absent for a new aggregate; captured at load for update or removal. */
1511
1496
  readonly expectedVersion?: Version;
1512
1497
  }
@@ -1514,8 +1499,8 @@ interface CommitEnrollmentOptions {
1514
1499
  interface WithCommitWorkResult<Evt extends AnyDomainEvent, R> {
1515
1500
  result: R;
1516
1501
  /**
1517
- * Commit tokens returned by the invocation's enrollment capability.
1518
- * Every token minted during the callback must appear at least once.
1502
+ * Commit tokens returned by the invocation's registration capability.
1503
+ * Every token issued during the callback must appear at least once.
1519
1504
  * Naked aggregates are intentionally not accepted: touching an aggregate
1520
1505
  * does not prove that its repository write participated in the transaction.
1521
1506
  */
@@ -1524,29 +1509,29 @@ interface WithCommitWorkResult<Evt extends AnyDomainEvent, R> {
1524
1509
  /**
1525
1510
  * Helper for executing a write Use Case inside a transaction scope.
1526
1511
  *
1527
- * The use-case callback receives an invocation-scoped enrollment capability
1512
+ * The use-case callback receives an invocation-scoped registration capability
1528
1513
  * and returns opaque commit tokens for the repository writes that completed
1529
- * in the transaction. `withCommit` owns the post-commit lifecycle (harvest,
1514
+ * in the transaction. `withCommit` owns the post-commit lifecycle (collection,
1530
1515
  * outbox, mark-persisted, publish). A naked aggregate is not commit evidence:
1531
1516
  * merely touching or constructing one must never make it look persisted.
1532
1517
  *
1533
- * **Trust boundary.** A token proves invocation-local enrollment, not that the
1518
+ * **Trust boundary.** A token proves invocation-local registration, not that the
1534
1519
  * kit inspected a database write; a generic transaction helper cannot observe
1535
- * adapter internals. Repository code must enroll only writes participating in
1520
+ * adapter internals. Repository code must register only writes participating in
1536
1521
  * this transaction. `UnitOfWork` centralizes that rule in repository methods.
1537
1522
  * The opaque, scoped token prevents accidental aggregate smuggling and stale
1538
1523
  * reuse; it is not a security boundary against code that deliberately lies to
1539
1524
  * its own persistence capability.
1540
1525
  *
1541
1526
  * Order of operations:
1542
- * 1. `fn(ctx, enrollment)` runs inside `scope.transactional(...)`; domain
1527
+ * 1. `fn(ctx, registration)` runs inside `scope.transactional(...)`; domain
1543
1528
  * mutations + repo writes happen here. After a repository write has
1544
- * enrolled an aggregate, the callback includes that opaque token in its
1529
+ * registered an aggregate, the callback includes that opaque token in its
1545
1530
  * `commits` result. Tokens are invocation-bound: forged or stale tokens
1546
- * fail before harvest. `ctx` is whatever transaction handle the `scope`
1531
+ * fail before collection. `ctx` is whatever transaction handle the `scope`
1547
1532
  * exposes (Drizzle `tx`, Prisma `tx`, Mongo session, or `undefined` for
1548
1533
  * context-free scopes).
1549
- * 2. **Still inside the transaction**, `withCommit` harvests every
1534
+ * 2. **Still inside the transaction**, `withCommit` collects every
1550
1535
  * aggregate's `pendingEvents` and writes them via `outbox.add` (so
1551
1536
  * events persist atomically with the state change). Skipped when no
1552
1537
  * events were recorded. Each bare domain event is composed into an
@@ -1556,7 +1541,7 @@ interface WithCommitWorkResult<Evt extends AnyDomainEvent, R> {
1556
1541
  * resulting `CommittedDomainEvent`. The domain event itself is never
1557
1542
  * stamped or copied.
1558
1543
  *
1559
- * **Harvest order.** Events are concatenated in the order
1544
+ * **Collection order.** Events are concatenated in the order
1560
1545
  * tokens appear in the returned `commits` array, then in
1561
1546
  * each aggregate's `pendingEvents` order (insertion order via
1562
1547
  * `apply` / `commit` / `addDomainEvent`). So tokens for `[a, b]`
@@ -1580,7 +1565,7 @@ interface WithCommitWorkResult<Evt extends AnyDomainEvent, R> {
1580
1565
  * across aggregates at delivery time.
1581
1566
  * 3. The transaction commits.
1582
1567
  * 4. **After** the commit, a non-exported capability acknowledges every
1583
- * saved enrollment and discards pending events for deleted enrollments.
1568
+ * saved registration and discards pending events for deleted registrations.
1584
1569
  * Only after the complete commit set is clean does the optional
1585
1570
  * application-shell `onPersisted(aggregate, version, context)` observer run for
1586
1571
  * saved aggregates. Deleted rows never trigger that observer.
@@ -1610,16 +1595,16 @@ interface WithCommitWorkResult<Evt extends AnyDomainEvent, R> {
1610
1595
  * If the transaction rolls back, no acknowledgement occurs: the aggregate
1611
1596
  * keeps its pending events, so the caller can retry or discard the instance.
1612
1597
  *
1613
- * Enrollment captures an exact version and event batch. Re-enrolling the same
1598
+ * Registration captures an exact version and event batch. Re-registering the same
1614
1599
  * aggregate after it changes rejects. `UnitOfWork` additionally seals the
1615
- * adapter persistence projection and rejects later mutation before flush. For
1616
- * direct `withCommit` use, make domain decisions first, write, and enroll last.
1600
+ * adapter persistence capture and rejects later mutation before flush. For
1601
+ * direct `withCommit` use, make domain decisions first, write, and register last.
1617
1602
  *
1618
- * **Duplicate enrollment is idempotent by reference.** Enrolling the same
1603
+ * **Duplicate registration is idempotent by reference.** Registering the same
1619
1604
  * instance repeatedly returns the same token, and a repeated token in
1620
- * `commits` is harvested once. A repeat call that omits `expectedVersion`
1605
+ * `commits` is collected once. A repeat call that omits `expectedVersion`
1621
1606
  * makes no OCC assertion; only a supplied value that contradicts the
1622
- * enrollment-time baseline rejects. Each event lands in the outbox exactly once
1607
+ * registration-time baseline rejects. Each event lands in the outbox exactly once
1623
1608
  * and post-commit acknowledgement runs exactly once. Two
1624
1609
  * *different* instances with the same logical id cannot be detected
1625
1610
  * at this layer; that is a Repository contract violation (failure to
@@ -1630,17 +1615,17 @@ interface WithCommitWorkResult<Evt extends AnyDomainEvent, R> {
1630
1615
  *
1631
1616
  * @example Tx-bound repos (Drizzle, Prisma, Mongo, …)
1632
1617
  * ```typescript
1633
- * const result = await withCommit({ outbox, bus, scope }, async (tx, enrollment) => {
1618
+ * const result = await withCommit({ outbox, bus, scope }, async (tx, registration) => {
1634
1619
  * const orderRepository = makeOrderRepository(tx); // your factory binds tx to the repo
1635
1620
  * const order = await orderRepository.getById(orderId);
1636
1621
  * order.confirm();
1637
1622
  * await persistOrder(tx, order); // low-level adapter write
1638
- * const commit = enrollment.enrollSaved(order); // attest the repository write
1623
+ * const commit = registration.registerSaved(order); // attest the repository write
1639
1624
  * return { result: order.id, commits: [commit] };
1640
1625
  * });
1641
1626
  * ```
1642
1627
  */
1643
- declare function withCommit<Evt extends AnyDomainEvent, R, TCtx>(deps: WithCommitDeps<Evt, TCtx>, fn: (ctx: TCtx, enrollment: CommitEnrollment<Evt>) => Promise<WithCommitWorkResult<Evt, R>>): Promise<R>;
1628
+ declare function withCommit<Evt extends AnyDomainEvent, R, TCtx>(deps: WithCommitDeps<Evt, TCtx>, fn: (ctx: TCtx, registration: CommitRegistration<Evt>) => Promise<WithCommitWorkResult<Evt, R>>): Promise<R>;
1644
1629
  //#endregion
1645
1630
  //#region src/application/deadlines/deadline-store.d.ts
1646
1631
  /**
@@ -1816,7 +1801,7 @@ interface IdempotencyLease {
1816
1801
  /** Delay after which the wrapper should renew this lease. */
1817
1802
  readonly renewAfterMs: number;
1818
1803
  }
1819
- /** Store-minted ownership receipt for one successful claim. */
1804
+ /** Store-issued ownership receipt for one successful claim. */
1820
1805
  interface IdempotencyClaimHandle {
1821
1806
  readonly key: string;
1822
1807
  /** Unique across ownership generations for this key; treat as opaque. */
@@ -1875,7 +1860,7 @@ type IdempotencyClaim = {
1875
1860
  *
1876
1861
  * A NON-transactional store (the in-memory reference on its own, a separate
1877
1862
  * durable store) cannot see commits or rollbacks. Every fresh claim
1878
- * therefore returns a store-minted token and bounded lease. The wrapper
1863
+ * therefore returns a store-issued token and bounded lease. The wrapper
1879
1864
  * renews it while the transaction runs; `complete`, `renew`, `confirm`,
1880
1865
  * `abandon`, and `reconcile` compare the token so a stale owner cannot
1881
1866
  * mutate a successor claim. An expired PENDING claim may be replaced. An
@@ -2035,12 +2020,12 @@ interface WithIdempotentCommitDeps<Evt extends AnyDomainEvent, TCtx> extends Wit
2035
2020
  * 2. A fresh claim carries an opaque ownership token. For a leased store the
2036
2021
  * wrapper renews it at `renewAfterMs` until the transaction callback is
2037
2022
  * ready to commit. A renewal failure rejects before commit and releases
2038
- * the claim. `fn(ctx, enrollment, execution)` receives the same token so a
2023
+ * the claim. `fn(ctx, registration, execution)` receives the same token so a
2039
2024
  * source-side marker can make later reconciliation conclusive.
2040
2025
  * 3. `store.complete(ctx, claim, fn's result)` stages or completes the outcome
2041
- * in the same transaction as aggregate writes and outbox. The enrollment
2026
+ * in the same transaction as aggregate writes and outbox. The registration
2042
2027
  * capability is sealed and its token array copied before `complete` can
2043
- * yield, so leaked callback state cannot change the harvest receipt.
2028
+ * yield, so leaked callback state cannot change the collection receipt.
2044
2029
  * 4. After commit, `store.confirm(claim)` finalizes a leased store's staged
2045
2030
  * outcome; it is a no-op for transactional stores. A failure cannot reject
2046
2031
  * an already committed write, so it is sent to `onIdempotencyError` and the
@@ -2063,7 +2048,7 @@ interface WithIdempotentCommitDeps<Evt extends AnyDomainEvent, TCtx> extends Wit
2063
2048
  * production default. Leases make the non-transactional family recoverable;
2064
2049
  * they do not manufacture an atomic exactly-once boundary across two stores.
2065
2050
  */
2066
- declare function withIdempotentCommit<Evt extends AnyDomainEvent, R, TCtx>(deps: WithIdempotentCommitDeps<Evt, TCtx>, request: IdempotentCommitRequest, fn: (ctx: TCtx, enrollment: CommitEnrollment<Evt>, execution: IdempotentExecution) => Promise<WithCommitWorkResult<Evt, R>>): Promise<IdempotentCommitResult<R>>;
2051
+ declare function withIdempotentCommit<Evt extends AnyDomainEvent, R, TCtx>(deps: WithIdempotentCommitDeps<Evt, TCtx>, request: IdempotentCommitRequest, fn: (ctx: TCtx, registration: CommitRegistration<Evt>, execution: IdempotentExecution) => Promise<WithCommitWorkResult<Evt, R>>): Promise<IdempotentCommitResult<R>>;
2067
2052
  //#endregion
2068
2053
  //#region src/application/projections/ports.d.ts
2069
2054
  /**
@@ -2248,7 +2233,7 @@ type AggregateClass<TAgg> = Function & {
2248
2233
  * `AggregatePersistence` implementations: two `findById(id)` calls in the same
2249
2234
  * unit of work MUST return the same instance, because commit-token
2250
2235
  * write registration dedupes by JavaScript object identity. Two instances for
2251
- * one logical aggregate can otherwise produce two tokens, two harvests,
2236
+ * one logical aggregate can otherwise produce two tokens, two collections,
2252
2237
  * and two post-commit lifecycle calls.
2253
2238
  *
2254
2239
  * Storage is two-level (per-type stores created lazily), so
@@ -2309,7 +2294,7 @@ declare class IdentityMap {
2309
2294
  * - Registering a DIFFERENT instance for an occupied type+id throws:
2310
2295
  * that is precisely the identity-map violation this class exists
2311
2296
  * to prevent (the repository hydrated twice instead of checking
2312
- * {@link get} first), and letting it pass would double-harvest
2297
+ * {@link get} first), and letting it pass would double-collect
2313
2298
  * events downstream.
2314
2299
  * - Registering a type+id that was {@link delete}d in this unit of
2315
2300
  * work throws `AggregateDeletedError`: deletion is final within
@@ -2322,7 +2307,7 @@ declare class IdentityMap {
2322
2307
  * Registered instances that have recorded MORE pending events than they
2323
2308
  * carried when first registered (loaded). Used by the unit of work's
2324
2309
  * end-of-run guard: an aggregate that gained events after load but was
2325
- * never enrolled would silently drop them. A read-only load, or a
2310
+ * never registered would silently drop them. A read-only load, or a
2326
2311
  * reconstitution that already carried events, shows no increase and is
2327
2312
  * not reported.
2328
2313
  */
@@ -2354,16 +2339,16 @@ declare class IdentityMap {
2354
2339
  /** Whether a baseline represents an existing row or a pending insert. */
2355
2340
  type PersistenceLifecycle = "loaded" | "new";
2356
2341
  /**
2357
- * Adapter-owned projection and change derivation for one aggregate type.
2342
+ * Adapter-owned capture and change derivation for one aggregate type.
2358
2343
  *
2359
2344
  * The domain model does not implement this contract. A repository adapter
2360
- * chooses what it persists, how that projection is captured at load, and
2345
+ * chooses what it persists, how it captures the aggregate at load, and
2361
2346
  * whether a change set is a partial diff or a full replacement.
2362
2347
  */
2363
2348
  interface PersistenceModel<TAggregate, TBaseline, TChangeSet> {
2364
2349
  /**
2365
- * Captures the adapter's persistence projection at the current moment.
2366
- * Return a detached value or an immutable value object: the Unit of Work
2350
+ * Captures the aggregate for the adapter at the current moment.
2351
+ * Return a copied value or an immutable value object: the Unit of Work
2367
2352
  * retains it as a baseline and cannot make an arbitrary adapter type safe.
2368
2353
  *
2369
2354
  * Capture must be deterministic for an unchanged aggregate: the Unit of
@@ -2382,7 +2367,7 @@ interface PersistenceModel<TAggregate, TBaseline, TChangeSet> {
2382
2367
  */
2383
2368
  capture(aggregate: TAggregate): TBaseline;
2384
2369
  /**
2385
- * Adapter-owned equality for two captures of the persistence projection.
2370
+ * Adapter-owned equality for two captures.
2386
2371
  * Optional: the default is the package's structural deep equality (Set
2387
2372
  * members and Map keys by reference). Supply it when the capture shape
2388
2373
  * needs domain-specific comparison, for example rebuilt value-object Set
@@ -2401,46 +2386,11 @@ interface PersistenceModel<TAggregate, TBaseline, TChangeSet> {
2401
2386
  /** Tells orchestration whether the derived state write is empty. */
2402
2387
  isEmpty(changes: TChangeSet): boolean;
2403
2388
  }
2404
- declare const persistenceBaselineBrand: unique symbol;
2405
- /**
2406
- * Opaque, typed receipt for an adapter-owned persistence baseline.
2407
- *
2408
- * It intentionally exposes no data. The Unit of Work may retain the token and
2409
- * ask the owning adapter capability to derive changes, but cannot branch on or
2410
- * couple itself to the baseline's shape.
2411
- */
2412
- interface PersistenceBaseline<TAggregate, TChangeSet> {
2413
- readonly [persistenceBaselineBrand]: (aggregate: TAggregate) => TChangeSet;
2414
- }
2415
2389
  /** A derived adapter change set plus its adapter-defined emptiness result. */
2416
2390
  interface PersistenceChanges<TChangeSet> {
2417
2391
  readonly value: TChangeSet;
2418
2392
  readonly empty: boolean;
2419
2393
  }
2420
- /** Captures a baseline for an aggregate restored by a repository adapter. */
2421
- declare function capturePersistenceBaseline<TAggregate, TBaseline, TChangeSet>(model: PersistenceModel<TAggregate, TBaseline, TChangeSet>, aggregate: TAggregate): PersistenceBaseline<TAggregate, TChangeSet>;
2422
- /** Creates the explicit no-row baseline for a newly added aggregate. */
2423
- declare function insertPersistenceBaseline<TAggregate, TBaseline, TChangeSet>(model: PersistenceModel<TAggregate, TBaseline, TChangeSet>): PersistenceBaseline<TAggregate, TChangeSet>;
2424
- /**
2425
- * Captures the aggregate's current adapter projection using the capability
2426
- * carried by an existing baseline. Used to seal persistence-last registration.
2427
- */
2428
- declare function recapturePersistenceBaseline<TAggregate, TChangeSet>(baseline: PersistenceBaseline<TAggregate, TChangeSet>, aggregate: TAggregate): PersistenceBaseline<TAggregate, TChangeSet>;
2429
- /**
2430
- * Recaptures the adapter projection and reports whether it drifted from the
2431
- * baseline's stored capture, using the model's `captureEquals` when supplied
2432
- * and structural deep equality otherwise.
2433
- *
2434
- * This, not `changes()`/`isEmpty()`, is the mutation detector: the
2435
- * `PersistenceModel` contract explicitly permits a full-replacement change
2436
- * set whose `isEmpty` is never true, so a non-empty change set proves
2437
- * nothing about mutation. Comparing capture to capture asks the honest
2438
- * question independent of the model's diffing strategy. A `"new"` lifecycle
2439
- * baseline has no stored capture and never reports drift.
2440
- */
2441
- declare function persistenceProjectionDrifted<TAggregate, TChangeSet>(baseline: PersistenceBaseline<TAggregate, TChangeSet>, aggregate: TAggregate): boolean;
2442
- /** Derives a typed adapter change set without exposing the stored baseline. */
2443
- declare function derivePersistenceChanges<TAggregate, TChangeSet>(baseline: PersistenceBaseline<TAggregate, TChangeSet>, aggregate: TAggregate): PersistenceChanges<TChangeSet>;
2444
2394
  //#endregion
2445
2395
  //#region src/application/unit-of-work/persistence-contract.d.ts
2446
2396
  /** The explicit persistence intent registered for one tracked aggregate. */
@@ -2454,7 +2404,7 @@ type UnitOfWorkIdentityMap = Pick<IdentityMap, "get" | "has" | "isDeleted">;
2454
2404
  * restored aggregate.
2455
2405
  * Write methods exposed to application code are replaced by Unit-of-Work-owned
2456
2406
  * `add`, `update`, and `remove` registrations, so an adapter implementation of
2457
- * those methods cannot perform durable I/O early or skip event harvesting.
2407
+ * those methods cannot perform durable I/O early or skip event collection.
2458
2408
  *
2459
2409
  * Contract for repository implementations:
2460
2410
  * - `findById(id)` checks `identityMap.get` BEFORE hydrating, treats
@@ -2840,7 +2790,7 @@ declare function reconstituteAggregateFromStreamPages<TAggregate extends Replaya
2840
2790
  * `createSnapshotStoreContractTests` from `@shirudo/ddd-kit/testing`):
2841
2791
  * the snapshot round-trips verbatim (`state` as plain data,
2842
2792
  * `version`, `snapshotAt` with millisecond fidelity, `schemaVersion`
2843
- * including its absence), loads return detached copies (never live
2793
+ * including its absence), loads return copies (never live
2844
2794
  * internal state), and keys are isolated per aggregate type AND id
2845
2795
  * (one table may serve every aggregate type).
2846
2796
  *
@@ -2875,5 +2825,5 @@ interface SnapshotStore<TState = unknown> {
2875
2825
  delete(identity: AggregateIdentity): Promise<void>;
2876
2826
  }
2877
2827
  //#endregion
2878
- export { EventHandler as $, Command as $t, IdempotencyClaimHandle as A, CreateDomainEventFromFactsOptions as At, withIdempotentCommit as B, PendingDomainEvent as Bt, IdentityMap as C, ExecutionContext as Ct, ProjectionPosition as D, EventCommitCandidatePosition as Dt, ProjectionCheckpointStore as E, EventCommitCandidate as Et, IdempotencyStore as F, DomainEventFactory as Ft, CommitEnrollment as G, createDomainEventFactory as Gt, DeadlineStore as H, UncommittedDomainEventOf as Ht, IdempotentCommitRequest as I, DomainEventFactoryOptions as It, WithCommitWorkResult as J, defaultDomainEventFactory as Jt, CommitEnrollmentOptions as K, createDomainEventFromFacts as Kt, IdempotentCommitResult as L, DomainEventStamp as Lt, IdempotencyOperationErrorContext as M, CreateDomainEventStampOptions as Mt, IdempotencyReconciliation as N, CreateUncommittedDomainEventOptions as Nt, isPositionAfter as O, AnyDomainEvent as Ot, IdempotencyReconciliationDecision as P, DomainEvent as Pt, EventBus as Q, AggregateIdentity as Qt, IdempotentExecution as R, EventIdFactory as Rt, AggregateClass as S, OutboxWriter as St, ProjectionCheckpoint as T, CommittedDomainEvent as Tt, DueDeadline as U, copyMetadata as Ut, DeadLetterDeadline as V, UncommittedDomainEvent as Vt, AggregateCommitToken as W, createDomainEvent as Wt, TransactionScope as X, recordDomainEvent as Xt, withCommit as Y, mergeMetadata as Yt, TransactionalOptions as Z, ClockFactory as Zt, capturePersistenceBaseline as _, routeEventsToCommandOutbox as _t, EventStoreAppendOptions as a, Version as at, persistenceProjectionDrifted as b, Outbox as bt, StreamReadResult as c, Id as ct, RepositoryTracking as d, CommandMessageContent as dt, CommandHandler as en, OnceOptions as et, UnitOfWorkIdentityMap as f, CommandMessageRelationships as ft, PersistenceModel as g, DurableCommandMessage as gt, PersistenceLifecycle as h, CommandOutboxWriter as ht, EventStore as i, JsonValue as in, ReplayableAggregate as it, IdempotencyLease as j, CreateDomainEventOptions as jt, IdempotencyClaim as k, AnyUncommittedDomainEvent as kt, AggregatePersistenceWrite as l, IdGenerator as lt, PersistenceChanges as m, CommandOutboxMapper as mt, ReplayableStreamPages as n, JsonObject as nn, Aggregate as nt, EventStreamReader as o, sameVersion as ot, PersistenceBaseline as p, CommandOutboxCommitCandidate as pt, WithCommitDeps as q, createUncommittedDomainEvent as qt, reconstituteAggregateFromStreamPages as r, JsonPrimitive as rn, AggregateSnapshot as rt, ReadStreamOptions as s, toVersion as st, SnapshotStore as t, PublishedCommand as tn, PublishOptions as tt, AggregateWriteIntent as u, CommandCommitOriginCandidate as ut, derivePersistenceChanges as v, DeadLetterRecord as vt, Projection as w, CommitPosition as wt, recapturePersistenceBaseline as x, OutboxRecord as xt, insertPersistenceBaseline as y, DispatchTrackingOutbox as yt, WithIdempotentCommitDeps as z, EventMetadata as zt };
2828
+ export { Version as $, IdempotentCommitRequest as A, DomainEventFactoryOptions as At, CommitRegistrationOptions as B, createStampedDomainEvent as Bt, IdempotencyClaim as C, AnyUnstampedDomainEvent as Ct, IdempotencyReconciliation as D, CreateUnstampedDomainEventOptions as Dt, IdempotencyOperationErrorContext as E, CreateStampedDomainEventOptions as Et, DeadLetterDeadline as F, UnstampedDomainEvent as Ft, TransactionalOptions as G, Command as Gt, WithCommitWorkResult as H, mergeMetadata as Ht, DeadlineStore as I, UnstampedDomainEventOf as It, OnceOptions as J, JsonObject as Jt, EventBus as K, CommandHandler as Kt, DueDeadline as L, copyMetadata as Lt, IdempotentExecution as M, EventIdFactory as Mt, WithIdempotentCommitDeps as N, EventMetadata as Nt, IdempotencyReconciliationDecision as O, DomainEvent as Ot, withIdempotentCommit as P, PendingDomainEvent as Pt, ReplayableAggregate as Q, AggregateCommitToken as R, createDomainEvent as Rt, isPositionAfter as S, AnyDomainEvent as St, IdempotencyLease as T, CreateDomainEventStampOptions as Tt, withCommit as U, ClockFactory as Ut, WithCommitDeps as V, defaultDomainEventFactory as Vt, TransactionScope as W, AggregateIdentity as Wt, Aggregate as X, JsonValue as Xt, PublishOptions as Y, JsonPrimitive as Yt, AggregateSnapshot as Z, IdentityMap as _, ExecutionContext as _t, EventStoreAppendOptions as a, CommandMessageContent as at, ProjectionCheckpointStore as b, EventCommitCandidate as bt, StreamReadResult as c, CommandOutboxMapper as ct, RepositoryTracking as d, routeEventsToCommandOutbox as dt, sameVersion as et, UnitOfWorkIdentityMap as f, DeadLetterRecord as ft, AggregateClass as g, OutboxWriter as gt, PersistenceModel as h, OutboxRecord as ht, EventStore as i, CommandCommitOriginCandidate as it, IdempotentCommitResult as j, DomainEventStamp as jt, IdempotencyStore as k, DomainEventFactory as kt, AggregatePersistenceWrite as l, CommandOutboxWriter as lt, PersistenceLifecycle as m, Outbox as mt, ReplayableStreamPages as n, Id as nt, EventStreamReader as o, CommandMessageRelationships as ot, PersistenceChanges as p, DispatchTrackingOutbox as pt, EventHandler as q, PublishedCommand as qt, reconstituteAggregateFromStreamPages as r, IdGenerator as rt, ReadStreamOptions as s, CommandOutboxCommitCandidate as st, SnapshotStore as t, toVersion as tt, AggregateWriteIntent as u, DurableCommandMessage as ut, Projection as v, CommitPosition as vt, IdempotencyClaimHandle as w, CreateDomainEventOptions as wt, ProjectionPosition as x, EventCommitCandidatePosition as xt, ProjectionCheckpoint as y, CommittedDomainEvent as yt, CommitRegistration as z, createDomainEventFactory as zt };
2879
2829
  //# sourceMappingURL=snapshot-store.d.ts.map