@shirudo/ddd-kit 3.0.0-rc.11 → 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.
@@ -464,6 +464,11 @@ 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
+ */
467
472
  declare function createUncommittedDomainEvent<T extends string>(type: T, payload?: undefined, options?: CreateUncommittedDomainEventOptions): UncommittedDomainEvent<T, void>;
468
473
  declare function createUncommittedDomainEvent<T extends string, P>(type: T, payload: P, options?: CreateUncommittedDomainEventOptions): UncommittedDomainEvent<T, P>;
469
474
  /**
@@ -474,6 +479,56 @@ declare function createUncommittedDomainEvent<T extends string, P>(type: T, payl
474
479
  * identity, recording time, and trace metadata.
475
480
  */
476
481
  declare function recordDomainEvent<T extends string, P>(event: UncommittedDomainEvent<T, P>, stamp: DomainEventStamp): DomainEvent<T, P>;
482
+ /**
483
+ * Creates a domain event with default values.
484
+ * Sets occurredAt to current date and schemaVersion to 1 if not provided.
485
+ *
486
+ * **Input ownership.** The event is deeply frozen, and `payload` and
487
+ * `metadata` are deep-cloned first, so the caller's own objects are never
488
+ * 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
490
+ * copy and the copy after it. So the copy loses no data without an error,
491
+ * and no getter of the data runs. The in-memory event store applies the
492
+ * same rule on append. The checks catch accidents, not a hostile `Proxy`: a
493
+ * trap that changes the data during the check can hide a loss. An error
494
+ * that a `Proxy` trap throws passes unchanged, so a coded error of the
495
+ * caller keeps its code. These values throw a `TypeError`: a function, a
496
+ * Promise, a WeakMap or a WeakSet, an `Error`, a host object such as a
497
+ * `File`, a binary buffer, a `RegExp`, and shared memory. The same holds
498
+ * for what the copy would lose or change: a class instance, an accessor, an
499
+ * enumerable symbol-keyed property, a non-enumerable data property, and an
500
+ * expando on a built-in. A non-enumerable symbol key is metadata by
501
+ * convention, and the event does not get it. Map a value object to plain
502
+ * data before it goes into an event. `toJSON()` of a `ValueObject` is
503
+ * shallow, so map a nested value object too.
504
+ *
505
+ * **For aggregate-internal events, prefer `this.createEvent(...)` on
506
+ * `StateStoredAggregate` / `EventSourcedAggregate`.** That helper auto-injects
507
+ * `aggregateId` (from `this.id`) and `aggregateType` (from the
508
+ * aggregate's declared `aggregateType` property), which downstream
509
+ * consumers (outbox dispatchers, projection handlers, audit logs)
510
+ * route by. The commit boundary validates that both fields are present
511
+ * and throws if they are missing, so a direct `createDomainEvent(...)`
512
+ * 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.
515
+ *
516
+ * Use `createDomainEvent(...)` directly for events that don't belong to
517
+ * an aggregate: system events, integration events, configuration events,
518
+ * test fixtures. For those, set `aggregateId` / `aggregateType` in
519
+ * `options` if downstream consumers expect routing metadata.
520
+ *
521
+ * @param type - The event type
522
+ * @param payload - The event payload
523
+ * @param options - Optional event configuration (including `aggregateId`
524
+ * and `aggregateType` for routing)
525
+ * @returns A domain event
526
+ *
527
+ * @example
528
+ * ```typescript
529
+ * const event = createDomainEvent("OrderCreated", { orderId: "123" });
530
+ * ```
531
+ */
477
532
  declare function createDomainEvent<T extends string>(type: T, payload?: undefined, options?: CreateDomainEventOptions): DomainEvent<T, void>;
478
533
  declare function createDomainEvent<T extends string, P>(type: T, payload: P, options?: CreateDomainEventOptions): DomainEvent<T, P>;
479
534
  /**
package/dist/index.d.ts CHANGED
@@ -3589,7 +3589,9 @@ declare function deepEqual(a: unknown, b: unknown): boolean;
3589
3589
  * `DataCloneError`. An Error, a Promise, a WeakMap, or a WeakSet cannot be
3590
3590
  * detached at all. A SharedArrayBuffer and a view over one keep sharing
3591
3591
  * their memory. A Proxy fails in the walk or in the clone; a failure in
3592
- * the clone is rethrown as a `TypeError` with the cause.
3592
+ * the clone is rethrown as a `TypeError` with the cause. An error that a
3593
+ * Proxy trap throws in the walk passes unchanged, so a coded error of the
3594
+ * caller keeps its code.
3593
3595
  *
3594
3596
  * The walk reads the graph through property descriptors and walks a Map
3595
3597
  * or a Set with the built-in iteration, so no accessor and no own iterator
@@ -3597,17 +3599,22 @@ declare function deepEqual(a: unknown, b: unknown): boolean;
3597
3599
  * change the graph, and an accessor that a trap adds runs during the
3598
3600
  * clone. A second walk checks the clone, so a value that a trap swapped in
3599
3601
  * and the content of a built-in whose prototype was replaced are rejected
3600
- * too. The walks also count the data properties of records and arrays. A
3601
- * copy with another count throws, because a built-in whose prototype was
3602
- * replaced loses its own properties in the copy. `subject` names the state
3603
- * in the messages.
3602
+ * too. A trap that changes the graph after the first walk can still hide a
3603
+ * value that the copy drops: the walks catch accidents, not a hostile
3604
+ * Proxy. The second walk also follows the steps of the first walk: the kind
3605
+ * of each object and the key of each data property, in walk order. A copy
3606
+ * that differs throws, because a built-in whose prototype was replaced is
3607
+ * a built-in again in the copy and loses its own properties. `subject`
3608
+ * names the state in the messages.
3604
3609
  *
3605
3610
  * Plain objects (from any realm), arrays, Dates, Maps, Sets, bigints, and
3606
3611
  * typed arrays pass. A RegExp passes: pattern and flags survive the clone,
3607
3612
  * and `lastIndex` restores as 0. The scan state of a global or sticky
3608
- * pattern is not domain data. A non-enumerable property on a built-in
3609
- * passes: it is the built-in's own machinery (`lastIndex`), not data. A
3610
- * non-enumerable symbol key passes anywhere: it is metadata by convention.
3613
+ * pattern is not domain data. On a built-in, the mutator shadows of a deep
3614
+ * freeze, the `lastIndex` of a RegExp, and the `length` of a boxed String
3615
+ * pass: they are machinery, not data. Every other non-enumerable property
3616
+ * throws. A non-enumerable symbol key passes anywhere: it is metadata by
3617
+ * convention.
3611
3618
  *
3612
3619
  * The concrete entity uses it for a detached read DTO of a plain-data
3613
3620
  * state. The snapshot model uses it for the captured DTO and the restored
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { $ as isDomainErrorLike, A as MissingHandlerError, B as SnapshotCorruptedError, C as InvalidEventStreamPageError, D as MisattributedEventError, E as KitWiringError, F as ProjectionOrderViolationError, G as UnmintedEventError, H as SnapshotVersionNotRestoredError, I as ProjectionReceiptViolationError, J as UnreplayableAggregateError, K as UnprojectableEventError, L as ReentrantEventRecordingError, M as PendingEventLimitExceededError, N as ProjectionGapError, O as MissingEntityIdError, P as ProjectionIdentityViolationError, Q as detachAggregateIdentity, R as ReplayRejectedError, S as InvalidCommandMessageError, T as InvalidVersionError, U as UnenrolledChangesError, V as SnapshotSchemaMismatchError, W as UnmanagedInstanceError, X as attributeConflictIntent, Y as assertNoHostileOwnProtoKey, Z as describeAggregateIdentity, _ as IdempotencyInFlightError, a as DirectStateMutationError, b as InMemoryCapacityExceededError, c as DuplicateEventIdError, d as EventHarvestError, et as isInfrastructureErrorLike, f as FoldReturnedNoStateError, g as IdempotencyCompletionWithoutClaimError, h as IdempotencyClaimLostError, i as ConcurrencyConflictError, j as PendingEventBatchMismatchError, k as MissingFoldError, l as DuplicateHandlerRegistrationError, m as HostileStateKeyError, n as AggregateNotFoundError, nt as rewriteErrorMessage, o as DomainError, p as ForeignEventError, q as UnregisteredHandlerError, r as CapabilityRegistryConflictError, s as DuplicateAggregateError, t as AggregateDeletedError, tt as isWiringErrorLike, u as ErrorMapperFailedError, v as IdempotencyKeyReuseError, w as InvalidIntegrationMessageError, x as InfrastructureError, y as IdempotencyReconciliationRequiredError, z as ReplayTargetMismatchError } from "./chunks/kit-errors.js";
2
- import { A as SnapshotTimeValidationError, B as voWithValidation, C as defaultDomainEventFactory, D as mintUncommittedDomainEvent, E as mergeMetadata, F as ValueObject, G as isBuiltInObject, H as deepOmit, I as deepFreeze, K as isIntrinsicConstructorPrototype, L as vo, M as detachState, N as hasCooperativeBrand, O as recordDomainEvent, P as stampCooperativeBrand, R as voEquals, S as createUncommittedDomainEvent, T as isUncommittedDomainEvent, U as deepEqual, V as deepEqualExcept, W as findPropertyDescriptor, _ as adoptUncommittedDomainEvent, a as isDispatchTrackingOutbox, b as createDomainEventFactory, c as runBoundedExecution, d as assertPositiveInteger, f as assertPositiveSafeInteger, g as adoptRecordedDomainEvent, h as waitRejectingOnAbort, i as assertPageWithinWindow, j as detachFreezableState, k as DomainEventValidationError, l as MAX_TIMER_DELAY_MS, m as abortReason, n as readStreamPages, o as DEFAULT_EXECUTION_TIMEOUT_MS, p as assertTimerDelay, q as isWeakMap, r as assertPageNotEmpty, s as ownerSignalOf, t as pinTargetVersion, u as assertNonNegativeSafeInteger, v as copyMetadata, w as isRecordedDomainEvent, x as createDomainEventFromFacts, y as createDomainEvent, z as voEqualsExcept } from "./chunks/read-stream-pages.js";
2
+ import { A as SnapshotTimeValidationError, B as stampCooperativeBrand, C as defaultDomainEventFactory, D as mintUncommittedDomainEvent, E as mergeMetadata, F as vo, G as isBuiltInObject, H as deepOmit, I as voEquals, K as isIntrinsicConstructorPrototype, L as voEqualsExcept, M as detachState, N as ValueObject, O as recordDomainEvent, P as deepFreeze, R as voWithValidation, S as createUncommittedDomainEvent, T as isUncommittedDomainEvent, U as deepEqual, V as deepEqualExcept, W as findPropertyDescriptor, _ as adoptUncommittedDomainEvent, a as isDispatchTrackingOutbox, b as createDomainEventFactory, c as runBoundedExecution, d as assertPositiveInteger, f as assertPositiveSafeInteger, g as adoptRecordedDomainEvent, h as waitRejectingOnAbort, i as assertPageWithinWindow, j as detachFreezableState, k as DomainEventValidationError, l as MAX_TIMER_DELAY_MS, m as abortReason, n as readStreamPages, o as DEFAULT_EXECUTION_TIMEOUT_MS, p as assertTimerDelay, q as isWeakMap, r as assertPageNotEmpty, s as ownerSignalOf, t as pinTargetVersion, u as assertNonNegativeSafeInteger, v as copyMetadata, w as isRecordedDomainEvent, x as createDomainEventFromFacts, y as createDomainEvent, z as hasCooperativeBrand } from "./chunks/read-stream-pages.js";
3
3
  import { err, ok } from "@shirudo/result";
4
4
  import { ValidationError, someChainRetryable } from "@shirudo/base-error";
5
5
 
package/dist/testing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { I as deepFreeze, U as deepEqual, a as isDispatchTrackingOutbox, c as runBoundedExecution, f as assertPositiveSafeInteger, n as readStreamPages, w as isRecordedDomainEvent } from "./chunks/read-stream-pages.js";
1
+ import { P as deepFreeze, U as deepEqual, a as isDispatchTrackingOutbox, c as runBoundedExecution, f as assertPositiveSafeInteger, n as readStreamPages, w as isRecordedDomainEvent } from "./chunks/read-stream-pages.js";
2
2
 
3
3
  //#region src/testing/contract-assertions.ts
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shirudo/ddd-kit",
3
- "version": "3.0.0-rc.11",
3
+ "version": "3.0.0-rc.12",
4
4
  "packageManager": "pnpm@11.13.1",
5
5
  "description": "Composable TypeScript toolkit for tactical DDD",
6
6
  "type": "module",