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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/money.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { u as DomainError } from "./chunks/kit-errors.js";
1
+ import { f as DomainError } from "./chunks/kit-errors.js";
2
2
  import { Result } from "@shirudo/result";
3
3
  //#region src/domain/value-object/money/money.d.ts
4
4
  /**
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Lt as PublishedCommand, P as EventBus, Pt as AggregateAddress, R as Aggregate, W as Id, Y as CommandOutboxCommitCandidate, Z as CommandOutboxWriter, _ as IdempotencyStore, a as StreamReadResult, c as ProjectionCheckpointStore, ct as EventCommitCandidate, f as IdempotencyClaimHandle, i as ReadStreamOptions, n as EventStore, nt as Outbox, st as CommittedDomainEvent, t as SnapshotStore, tt as DispatchTrackingOutbox, ut as AnyDomainEvent, w as DeadlineStore } from "./chunks/snapshot-store.js";
1
+ import { A as IdempotencyClaimHandle, E as ProjectionCheckpointStore, Et as EventCommitCandidate, F as IdempotencyStore, H as DeadlineStore, Ot as AnyDomainEvent, Q as EventBus, Qt as AggregateIdentity, Tt as CommittedDomainEvent, bt as Outbox, c as StreamReadResult, ct as Id, ht as CommandOutboxWriter, i as EventStore, n as ReplayableStreamPages, nt as Aggregate, pt as CommandOutboxCommitCandidate, s as ReadStreamOptions, t as SnapshotStore, tn as PublishedCommand, yt as DispatchTrackingOutbox } from "./chunks/snapshot-store.js";
2
2
  //#region src/testing/contract-assertions.d.ts
3
3
  /**
4
4
  * One entry of a contract test suite. Every suite (repository,
@@ -20,6 +20,10 @@ interface CommandOutboxContractEnvironment<C extends PublishedCommand> {
20
20
  readonly outbox: CommandOutboxWriter<C>;
21
21
  readonly addCommitted: (commits: ReadonlyArray<CommandOutboxCommitCandidate<C>>) => Promise<void>;
22
22
  readonly addRolledBack?: (commits: ReadonlyArray<CommandOutboxCommitCandidate<C>>) => Promise<void>;
23
+ /** Runs `outbox.endEventSources(sources)` in a transaction that commits. */
24
+ readonly endEventSourcesCommitted: (sources: ReadonlyArray<AggregateIdentity>) => Promise<void>;
25
+ /** Runs `outbox.endEventSources(sources)` in a transaction that rolls back. */
26
+ readonly endEventSourcesRolledBack?: (sources: ReadonlyArray<AggregateIdentity>) => Promise<void>;
23
27
  readonly readAll: () => Promise<ReadonlyArray<CommandOutboxCommitCandidate<C>>>;
24
28
  readonly teardown?: () => Promise<void>;
25
29
  }
@@ -35,6 +39,8 @@ interface CommandOutboxContractHarness<C extends PublishedCommand> {
35
39
  */
36
40
  readonly createCommand: (seed: number) => C;
37
41
  readonly providesRolledBackAdds?: boolean;
42
+ /** Declare `true` when environments provide `endEventSourcesRolledBack`. */
43
+ readonly providesRolledBackEnds?: boolean;
38
44
  }
39
45
  type CommandOutboxContractTest = ContractTest;
40
46
  declare function createCommandOutboxContractTests<C extends PublishedCommand>(harness: CommandOutboxContractHarness<C>): ReadonlyArray<CommandOutboxContractTest>;
@@ -89,8 +95,8 @@ interface DeadlineStoreContractHarness {
89
95
  /**
90
96
  * Declare `true` when environments provide {@link
91
97
  * DeadlineStoreContractEnvironment.runRolledBack}. Without it, the
92
- * rollback tests are marked skipped: the honest state of an
93
- * in-memory fake, and a loud gap for a transactional adapter.
98
+ * rollback tests are marked skipped: the honest state of a store
99
+ * without a rollback, and a loud gap for a transactional adapter.
94
100
  */
95
101
  providesRolledBackRuns?: boolean;
96
102
  /**
@@ -129,7 +135,7 @@ interface EsRepositoryContractEnvironment<TAggregate extends Aggregate<Id<string
129
135
  }) => Promise<R>): Promise<R>;
130
136
  committedOutboxEvents(): Promise<ReadonlyArray<CommittedDomainEvent<TEvent>>>;
131
137
  failNextOutboxWrite(error: Error): void;
132
- committedStreamEvents(stream: AggregateAddress<TAggregate["id"]>, options: ReadStreamOptions): Promise<StreamReadResult<TEvent>>;
138
+ committedStreamEvents(stream: AggregateIdentity<TAggregate["id"]>, options: ReadStreamOptions): Promise<StreamReadResult<TEvent>>;
133
139
  teardown?(): Promise<void>;
134
140
  }
135
141
  interface EsRepositoryContractHarness<TAggregate extends Aggregate<Id<string>, TEvent>, TEvent extends AnyDomainEvent = AnyDomainEvent> {
@@ -137,7 +143,7 @@ interface EsRepositoryContractHarness<TAggregate extends Aggregate<Id<string>, T
137
143
  /** Fresh aggregate with exactly one recorded creation event. */
138
144
  createAggregate(): TAggregate;
139
145
  createAggregateWithId?(id: TAggregate["id"]): TAggregate;
140
- streamKeyFor(id: TAggregate["id"]): AggregateAddress<TAggregate["id"]>;
146
+ streamKeyFor(id: TAggregate["id"]): AggregateIdentity<TAggregate["id"]>;
141
147
  /** Applies exactly one event and advances the aggregate version by one. */
142
148
  mutate(aggregate: TAggregate): void;
143
149
  snapshotState?(aggregate: TAggregate): unknown;
@@ -225,13 +231,13 @@ interface EventStoreContractEnvironment<Evt extends AnyDomainEvent> {
225
231
  *
226
232
  * `createCollidingStreamKeys` must return two valid stream keys with the same
227
233
  * raw aggregate id and different aggregate types. `createEvent` must return an
228
- * event addressed to the supplied key; different sequence values must produce
234
+ * event that belongs to the supplied key; different sequence values must produce
229
235
  * different event ids.
230
236
  */
231
237
  interface EventStoreContractHarness<Evt extends AnyDomainEvent> {
232
238
  createEnvironment(): Promise<EventStoreContractEnvironment<Evt>>;
233
- createCollidingStreamKeys(): readonly [AggregateAddress, AggregateAddress];
234
- createEvent(stream: AggregateAddress, sequence: number): Evt;
239
+ createCollidingStreamKeys(): readonly [AggregateIdentity, AggregateIdentity];
240
+ createEvent(stream: AggregateIdentity, sequence: number): Evt;
235
241
  }
236
242
  /**
237
243
  * Reusable proof of an EventStore adapter's portable semantics: qualified
@@ -339,10 +345,21 @@ interface OutboxContractEnvironment<Evt extends AnyDomainEvent> {
339
345
  * Optional capability: runs `outbox.add(candidates)` inside a
340
346
  * transaction that ROLLS BACK. Enables the rollback-purity test: a
341
347
  * rolled-back add must leave nothing behind. Transactional adapters
342
- * should always provide this; it is the half of the outbox promise
343
- * that in-memory fakes cannot keep.
348
+ * should always provide this.
344
349
  */
345
350
  addRolledBack?(events: ReadonlyArray<EventCommitCandidate<Evt>>): Promise<void>;
351
+ /**
352
+ * Runs `outbox.endEventSources(sources)` inside a transaction that
353
+ * COMMITS, the way `withCommit` calls it for a removal. For a
354
+ * non-transactional store this is simply `outbox.endEventSources(sources)`.
355
+ */
356
+ endEventSourcesCommitted(sources: ReadonlyArray<AggregateIdentity>): Promise<void>;
357
+ /**
358
+ * Optional capability: runs `outbox.endEventSources(sources)` inside a
359
+ * transaction that ROLLS BACK. Enables the test that a rolled-back
360
+ * removal leaves its event source open.
361
+ */
362
+ endEventSourcesRolledBack?(sources: ReadonlyArray<AggregateIdentity>): Promise<void>;
346
363
  /** Release connections, drop schemas, etc. Called in a finally. */
347
364
  teardown?(): Promise<void>;
348
365
  }
@@ -380,10 +397,16 @@ interface OutboxContractHarness<Evt extends AnyDomainEvent> {
380
397
  /**
381
398
  * Declare `true` when environments provide {@link
382
399
  * OutboxContractEnvironment.addRolledBack}. Without it, the
383
- * rollback-purity test is marked skipped: the honest state of an
384
- * in-memory fake, and a loud gap for a transactional adapter.
400
+ * rollback-purity test is marked skipped: the honest state of a store
401
+ * without a rollback, and a loud gap for a transactional adapter.
385
402
  */
386
403
  providesRolledBackAdds?: boolean;
404
+ /**
405
+ * Declare `true` when environments provide {@link
406
+ * OutboxContractEnvironment.endEventSourcesRolledBack}. Without it, the
407
+ * test that a rolled-back end leaves the source open is marked skipped.
408
+ */
409
+ providesRolledBackEnds?: boolean;
387
410
  /**
388
411
  * Declare `true` when the adapter's `getPending` CLAIMS the returned
389
412
  * records for competing dispatchers (lease, visibility timeout,
@@ -447,7 +470,7 @@ interface ProjectionCheckpointStoreContractEnvironment<TCtx> {
447
470
  * BACK. Enables the rollback test: a rolled-back save must leave no
448
471
  * checkpoint behind, the half of the atomic update+checkpoint
449
472
  * promise the store contributes. Transactional adapters should
450
- * always provide this; in-memory fakes cannot.
473
+ * always provide this.
451
474
  */
452
475
  runRolledBack?<R>(work: (ctx: TCtx) => Promise<R>): Promise<R>;
453
476
  /** Release connections, drop schemas, etc. Called in a finally. */
@@ -466,7 +489,8 @@ interface ProjectionCheckpointStoreContractHarness<TCtx> {
466
489
  * Declare `true` when environments provide {@link
467
490
  * ProjectionCheckpointStoreContractEnvironment.runRolledBack}.
468
491
  * Without it, the rollback test is marked skipped: the honest state
469
- * of an in-memory fake, and a loud gap for a transactional adapter.
492
+ * of a store without a rollback, and a loud gap for a transactional
493
+ * adapter.
470
494
  */
471
495
  providesRolledBackRuns?: boolean;
472
496
  /**
@@ -497,6 +521,73 @@ interface ProjectionCheckpointStoreContractHarness<TCtx> {
497
521
  */
498
522
  declare function createProjectionCheckpointStoreContractTests<TCtx>(harness: ProjectionCheckpointStoreContractHarness<TCtx>): ProjectionCheckpointStoreContractTest[];
499
523
  //#endregion
524
+ //#region src/testing/replayable-stream-pages.d.ts
525
+ /** Options for {@link createReplayableStreamPages}. */
526
+ interface CreateReplayableStreamPagesOptions<Evt extends AnyDomainEvent> extends Pick<ReplayableStreamPages<Evt>, "fromVersion" | "targetVersion"> {
527
+ /** The events after the cursor through the target, in append order. */
528
+ readonly tail: ReadonlyArray<Evt>;
529
+ /**
530
+ * The maximum number of events per page. Without it, the tail comes back
531
+ * as one page. Set it to make a test cross a page boundary. Must be a
532
+ * positive safe integer when present.
533
+ */
534
+ readonly limit?: number;
535
+ }
536
+ /**
537
+ * Builds a replayable stream read from an in-memory tail, for a test of the
538
+ * code that consumes a read: a repository, or the replay over a fixed window.
539
+ * It stands in for `readStreamPages` or an adapter that pages on its own,
540
+ * and it tests neither. The tail is copied once and frozen deeply, and it
541
+ * comes back in the same pages on every iteration. So a consumer that
542
+ * changes an event in place fails at the write in its own test. An empty
543
+ * tail yields no page, as `readStreamPages` does.
544
+ */
545
+ declare function createReplayableStreamPages<Evt extends AnyDomainEvent>(stream: AggregateIdentity, options: CreateReplayableStreamPagesOptions<Evt>): ReplayableStreamPages<Evt>;
546
+ //#endregion
547
+ //#region src/testing/replayable-stream-pages-contract.d.ts
548
+ /** One named contract test for code that builds replayable stream reads. */
549
+ type ReplayableStreamPagesContractTest = ContractTest;
550
+ /** The window the suite asks the code under test for. */
551
+ interface ReplayableStreamPagesContractWindow {
552
+ /** The cursor: the pages hold the events after this version. */
553
+ readonly fromVersion: number;
554
+ /** The version a point-in-time read asks for. Absent for a read to the head. */
555
+ readonly toVersion?: number;
556
+ /** The maximum number of events per page. */
557
+ readonly limit: number;
558
+ }
559
+ /** The code under test and the store it reads. The suite creates one per test. */
560
+ interface ReplayableStreamPagesContractEnvironment<Evt extends AnyDomainEvent> {
561
+ /** Appends events to the end of the stream in the store that the code reads. */
562
+ append(stream: AggregateIdentity, events: ReadonlyArray<Evt>): Promise<void>;
563
+ /**
564
+ * Reads the stream through the code under test. Returns `undefined`
565
+ * for an absent stream and for a window that lies outside the stream.
566
+ */
567
+ read(stream: AggregateIdentity, window: ReplayableStreamPagesContractWindow): Promise<ReplayableStreamPages<Evt> | undefined>;
568
+ teardown?(): Promise<void>;
569
+ }
570
+ /**
571
+ * Inputs the suite needs. `createStream` returns an aggregate identity that no
572
+ * other test uses. `createEvent` returns an event that belongs to that
573
+ * stream; different sequence values give different event ids.
574
+ */
575
+ interface ReplayableStreamPagesContractHarness<Evt extends AnyDomainEvent> {
576
+ createEnvironment(): Promise<ReplayableStreamPagesContractEnvironment<Evt>>;
577
+ createStream(): AggregateIdentity;
578
+ createEvent(stream: AggregateIdentity, sequence: number): Evt;
579
+ }
580
+ /**
581
+ * Reusable proof of code that builds `ReplayableStreamPages` values:
582
+ * `readStreamPages`, or an adapter that pages on its own.
583
+ * The suite proves that the pages hold the events after the cursor
584
+ * through the target version in append order, that no page is empty or
585
+ * larger than the limit, that every iteration yields the same prefix, and
586
+ * that an append during the iteration stays out. It also proves that an
587
+ * absent stream and a window outside the stream give no replayable read.
588
+ */
589
+ declare function createReplayableStreamPagesContractTests<Evt extends AnyDomainEvent>(harness: ReplayableStreamPagesContractHarness<Evt>): ReplayableStreamPagesContractTest[];
590
+ //#endregion
500
591
  //#region src/testing/repository-contract.d.ts
501
592
  /** Application-facing state-stored repository exercised by the suite. */
502
593
  interface ContractRepository<TAggregate extends Aggregate<Id<string>, AnyDomainEvent>> {
@@ -627,5 +718,5 @@ interface SnapshotStoreContractHarness {
627
718
  */
628
719
  declare function createSnapshotStoreContractTests(harness: SnapshotStoreContractHarness): SnapshotStoreContractTest[];
629
720
  //#endregion
630
- export { type CommandOutboxContractEnvironment, type CommandOutboxContractHarness, type CommandOutboxContractTest, type ContractRepository, type DeadlineStoreContractEnvironment, type DeadlineStoreContractHarness, type DeadlineStoreContractTest, type EsContractRepository, type EsRepositoryContractEnvironment, type EsRepositoryContractHarness, type EsRepositoryContractTest, type EventBusContractEnvironment, type EventBusContractHarness, type EventBusContractTest, type EventStoreContractEnvironment, type EventStoreContractHarness, type EventStoreContractTest, type IdempotencyStoreContractEnvironment, type IdempotencyStoreContractHarness, type IdempotencyStoreContractTest, type OutboxContractEnvironment, type OutboxContractHarness, type OutboxContractTest, type ProjectionCheckpointStoreContractEnvironment, type ProjectionCheckpointStoreContractHarness, type ProjectionCheckpointStoreContractTest, type RepositoryContractEnvironment, type RepositoryContractHarness, type RepositoryContractTest, type SnapshotStoreContractEnvironment, type SnapshotStoreContractHarness, type SnapshotStoreContractTest, createCommandOutboxContractTests, createDeadlineStoreContractTests, createEsRepositoryContractTests, createEventBusContractTests, createEventStoreContractTests, createIdempotencyStoreContractTests, createOutboxContractTests, createProjectionCheckpointStoreContractTests, createRepositoryContractTests, createSnapshotStoreContractTests };
721
+ export { type CommandOutboxContractEnvironment, type CommandOutboxContractHarness, type CommandOutboxContractTest, type ContractRepository, type CreateReplayableStreamPagesOptions, type DeadlineStoreContractEnvironment, type DeadlineStoreContractHarness, type DeadlineStoreContractTest, type EsContractRepository, type EsRepositoryContractEnvironment, type EsRepositoryContractHarness, type EsRepositoryContractTest, type EventBusContractEnvironment, type EventBusContractHarness, type EventBusContractTest, type EventStoreContractEnvironment, type EventStoreContractHarness, type EventStoreContractTest, type IdempotencyStoreContractEnvironment, type IdempotencyStoreContractHarness, type IdempotencyStoreContractTest, type OutboxContractEnvironment, type OutboxContractHarness, type OutboxContractTest, type ProjectionCheckpointStoreContractEnvironment, type ProjectionCheckpointStoreContractHarness, type ProjectionCheckpointStoreContractTest, type ReplayableStreamPagesContractEnvironment, type ReplayableStreamPagesContractHarness, type ReplayableStreamPagesContractTest, type ReplayableStreamPagesContractWindow, type RepositoryContractEnvironment, type RepositoryContractHarness, type RepositoryContractTest, type SnapshotStoreContractEnvironment, type SnapshotStoreContractHarness, type SnapshotStoreContractTest, createCommandOutboxContractTests, createDeadlineStoreContractTests, createEsRepositoryContractTests, createEventBusContractTests, createEventStoreContractTests, createIdempotencyStoreContractTests, createOutboxContractTests, createProjectionCheckpointStoreContractTests, createReplayableStreamPages, createReplayableStreamPagesContractTests, createRepositoryContractTests, createSnapshotStoreContractTests };
631
722
  //# sourceMappingURL=testing.d.ts.map