@ddd-ts-kit/kernel 0.113.2 → 0.115.0
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.fr.md +70 -62
- package/README.md +65 -57
- package/dist/application/audit/restamped.d.ts +9 -0
- package/dist/application/audit/restamped.d.ts.map +1 -0
- package/dist/application/audit/restamped.js +9 -0
- package/dist/application/audit/restamped.js.map +1 -0
- package/dist/application/audit/stamp-update.d.ts +1 -6
- package/dist/application/audit/stamp-update.d.ts.map +1 -1
- package/dist/application/audit/stamp-update.js +2 -8
- package/dist/application/audit/stamp-update.js.map +1 -1
- package/dist/application/background/enqueued-job.d.ts +1 -1
- package/dist/application/background/enqueued-job.d.ts.map +1 -1
- package/dist/application/error-reporting/report-once.d.ts.map +1 -1
- package/dist/application/error-reporting/report-once.js +2 -6
- package/dist/application/error-reporting/report-once.js.map +1 -1
- package/dist/application/event-sourcing/event-envelope.d.ts +2 -1
- package/dist/application/event-sourcing/event-envelope.d.ts.map +1 -1
- package/dist/application/event-sourcing/event-to-append.d.ts +1 -1
- package/dist/application/event-sourcing/event-to-append.d.ts.map +1 -1
- package/dist/application/execution/with-actor.d.ts +2 -2
- package/dist/application/execution/with-actor.js +3 -3
- package/dist/application/execution/with-actor.js.map +1 -1
- package/dist/application/files/stored-file.d.ts +3 -3
- package/dist/application/files/stored-file.d.ts.map +1 -1
- package/dist/application/hydration/hydration.d.ts.map +1 -1
- package/dist/application/hydration/hydration.js +3 -2
- package/dist/application/hydration/hydration.js.map +1 -1
- package/dist/application/logging/hidden-keys.d.ts +8 -0
- package/dist/application/logging/hidden-keys.d.ts.map +1 -0
- package/dist/application/logging/hidden-keys.js +10 -0
- package/dist/application/logging/hidden-keys.js.map +1 -0
- package/dist/application/logging/index.d.ts +1 -0
- package/dist/application/logging/index.d.ts.map +1 -1
- package/dist/application/logging/index.js +1 -0
- package/dist/application/logging/index.js.map +1 -1
- package/dist/application/observation/safely.d.ts +6 -0
- package/dist/application/observation/safely.d.ts.map +1 -0
- package/dist/application/observation/safely.js +13 -0
- package/dist/application/observation/safely.js.map +1 -0
- package/dist/application/persistence/append-changes.d.ts +1 -0
- package/dist/application/persistence/append-changes.d.ts.map +1 -1
- package/dist/application/persistence/append-changes.js +7 -6
- package/dist/application/persistence/append-changes.js.map +1 -1
- package/dist/application/persistence/optimistic-update.d.ts +6 -2
- package/dist/application/persistence/optimistic-update.d.ts.map +1 -1
- package/dist/application/persistence/optimistic-update.js +11 -3
- package/dist/application/persistence/optimistic-update.js.map +1 -1
- package/dist/application/ports/domain-event-dispatcher.d.ts +1 -1
- package/dist/application/ports/domain-event-dispatcher.js +1 -1
- package/dist/application/ports/logger.d.ts +3 -3
- package/dist/application/ports/unit-of-work.d.ts +1 -1
- package/dist/application/ports/unit-of-work.js +1 -1
- package/dist/application/read-model/stamp-of.d.ts +11 -4
- package/dist/application/read-model/stamp-of.d.ts.map +1 -1
- package/dist/application/read-model/stamp-of.js +10 -8
- package/dist/application/read-model/stamp-of.js.map +1 -1
- package/dist/application/session/anonymous-session.d.ts.map +1 -1
- package/dist/application/session/anonymous-session.js +4 -2
- package/dist/application/session/anonymous-session.js.map +1 -1
- package/dist/application/session/never-issued.d.ts +2 -1
- package/dist/application/session/never-issued.d.ts.map +1 -1
- package/dist/application/session/never-issued.js +4 -1
- package/dist/application/session/never-issued.js.map +1 -1
- package/dist/application/session/system-session.d.ts.map +1 -1
- package/dist/application/session/system-session.js +2 -2
- package/dist/application/session/system-session.js.map +1 -1
- package/dist/application/undecided/index.d.ts +3 -0
- package/dist/application/undecided/index.d.ts.map +1 -0
- package/dist/application/undecided/index.js +3 -0
- package/dist/application/undecided/index.js.map +1 -0
- package/dist/application/undecided/undecided-error.d.ts +12 -0
- package/dist/application/undecided/undecided-error.d.ts.map +1 -0
- package/dist/application/undecided/undecided-error.js +15 -0
- package/dist/application/undecided/undecided-error.js.map +1 -0
- package/dist/application/undecided/undecided.d.ts +7 -0
- package/dist/application/undecided/undecided.d.ts.map +1 -0
- package/dist/application/undecided/undecided.js +9 -0
- package/dist/application/undecided/undecided.js.map +1 -0
- package/dist/domain/aggregate-root.d.ts +6 -13
- package/dist/domain/aggregate-root.d.ts.map +1 -1
- package/dist/domain/aggregate-root.js +10 -16
- package/dist/domain/aggregate-root.js.map +1 -1
- package/dist/domain/aggregate-tracking.d.ts +30 -0
- package/dist/domain/aggregate-tracking.d.ts.map +1 -0
- package/dist/domain/aggregate-tracking.js +48 -0
- package/dist/domain/aggregate-tracking.js.map +1 -0
- package/dist/domain/domain-event.d.ts +4 -0
- package/dist/domain/domain-event.d.ts.map +1 -1
- package/dist/domain/domain-event.js.map +1 -1
- package/dist/domain/errors/domain-error.d.ts.map +1 -1
- package/dist/domain/errors/domain-error.js +2 -1
- package/dist/domain/errors/domain-error.js.map +1 -1
- package/dist/domain/errors/factual-refusal.d.ts.map +1 -1
- package/dist/domain/errors/factual-refusal.js +3 -0
- package/dist/domain/errors/factual-refusal.js.map +1 -1
- package/dist/domain/errors/kit-codes.d.ts +2 -0
- package/dist/domain/errors/kit-codes.d.ts.map +1 -1
- package/dist/domain/errors/kit-codes.js +2 -0
- package/dist/domain/errors/kit-codes.js.map +1 -1
- package/dist/domain/event-id-of.d.ts +8 -0
- package/dist/domain/event-id-of.d.ts.map +1 -0
- package/dist/domain/event-id-of.js +10 -0
- package/dist/domain/event-id-of.js.map +1 -0
- package/dist/domain/event-rank.d.ts +8 -0
- package/dist/domain/event-rank.d.ts.map +1 -0
- package/dist/domain/event-rank.js +8 -0
- package/dist/domain/event-rank.js.map +1 -0
- package/dist/domain/event-sourcing/event-sourced-aggregate.d.ts +0 -1
- package/dist/domain/event-sourcing/event-sourced-aggregate.d.ts.map +1 -1
- package/dist/domain/event-sourcing/event-sourced-aggregate.js +4 -8
- package/dist/domain/event-sourcing/event-sourced-aggregate.js.map +1 -1
- package/dist/domain/named-domain-event.d.ts +11 -4
- package/dist/domain/named-domain-event.d.ts.map +1 -1
- package/dist/domain/named-domain-event.js +14 -3
- package/dist/domain/named-domain-event.js.map +1 -1
- package/dist/domain/rank-of.d.ts +8 -0
- package/dist/domain/rank-of.d.ts.map +1 -0
- package/dist/domain/rank-of.js +14 -0
- package/dist/domain/rank-of.js.map +1 -0
- package/dist/domain/ranked.d.ts +10 -0
- package/dist/domain/ranked.d.ts.map +1 -0
- package/dist/domain/ranked.js +19 -0
- package/dist/domain/ranked.js.map +1 -0
- package/dist/domain/result/unwrap.d.ts +1 -0
- package/dist/domain/result/unwrap.d.ts.map +1 -1
- package/dist/domain/result/unwrap.js +4 -1
- package/dist/domain/result/unwrap.js.map +1 -1
- package/dist/domain/state-machine/state-machine.d.ts +4 -0
- package/dist/domain/state-machine/state-machine.d.ts.map +1 -1
- package/dist/domain/state-machine/state-machine.js +14 -4
- package/dist/domain/state-machine/state-machine.js.map +1 -1
- package/dist/domain/value-object/frozen-copy.d.ts +8 -0
- package/dist/domain/value-object/frozen-copy.d.ts.map +1 -0
- package/dist/domain/value-object/frozen-copy.js +34 -0
- package/dist/domain/value-object/frozen-copy.js.map +1 -0
- package/dist/domain/value-object/index.d.ts +2 -0
- package/dist/domain/value-object/index.d.ts.map +1 -0
- package/dist/domain/value-object/index.js +2 -0
- package/dist/domain/value-object/index.js.map +1 -0
- package/dist/domain/value-object/is-plain-record.d.ts +3 -0
- package/dist/domain/value-object/is-plain-record.d.ts.map +1 -0
- package/dist/domain/value-object/is-plain-record.js +9 -0
- package/dist/domain/value-object/is-plain-record.js.map +1 -0
- package/dist/domain/value-object/same-value.d.ts +8 -0
- package/dist/domain/value-object/same-value.d.ts.map +1 -0
- package/dist/domain/value-object/same-value.js +43 -0
- package/dist/domain/value-object/same-value.js.map +1 -0
- package/dist/domain/value-object/value-object.d.ts +28 -0
- package/dist/domain/value-object/value-object.d.ts.map +1 -0
- package/dist/domain/value-object/value-object.js +24 -0
- package/dist/domain/value-object/value-object.js.map +1 -0
- package/dist/index.d.ts +9 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -12
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/aggregates/aggregate-mapper.d.ts +21 -0
- package/dist/infrastructure/aggregates/aggregate-mapper.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/aggregate-mapper.js +18 -0
- package/dist/infrastructure/aggregates/aggregate-mapper.js.map +1 -0
- package/dist/infrastructure/aggregates/aggregate-save.d.ts +22 -0
- package/dist/infrastructure/aggregates/aggregate-save.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/aggregate-save.js +2 -0
- package/dist/infrastructure/aggregates/aggregate-save.js.map +1 -0
- package/dist/infrastructure/aggregates/as-found.d.ts +8 -0
- package/dist/infrastructure/aggregates/as-found.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/as-found.js +2 -0
- package/dist/infrastructure/aggregates/as-found.js.map +1 -0
- package/dist/infrastructure/aggregates/give-back.d.ts +9 -0
- package/dist/infrastructure/aggregates/give-back.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/give-back.js +13 -0
- package/dist/infrastructure/aggregates/give-back.js.map +1 -0
- package/dist/infrastructure/aggregates/index.d.ts +7 -0
- package/dist/infrastructure/aggregates/index.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/index.js +7 -0
- package/dist/infrastructure/aggregates/index.js.map +1 -0
- package/dist/infrastructure/aggregates/loaded-at.d.ts +8 -0
- package/dist/infrastructure/aggregates/loaded-at.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/loaded-at.js +12 -0
- package/dist/infrastructure/aggregates/loaded-at.js.map +1 -0
- package/dist/infrastructure/aggregates/noted-as-found.d.ts +8 -0
- package/dist/infrastructure/aggregates/noted-as-found.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/noted-as-found.js +15 -0
- package/dist/infrastructure/aggregates/noted-as-found.js.map +1 -0
- package/dist/infrastructure/aggregates/recorded-events-of.d.ts +4 -0
- package/dist/infrastructure/aggregates/recorded-events-of.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/recorded-events-of.js +6 -0
- package/dist/infrastructure/aggregates/recorded-events-of.js.map +1 -0
- package/dist/infrastructure/aggregates/save-aggregate-row.d.ts +23 -0
- package/dist/infrastructure/aggregates/save-aggregate-row.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/save-aggregate-row.js +17 -0
- package/dist/infrastructure/aggregates/save-aggregate-row.js.map +1 -0
- package/dist/infrastructure/aggregates/stored-at.d.ts +7 -0
- package/dist/infrastructure/aggregates/stored-at.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/stored-at.js +14 -0
- package/dist/infrastructure/aggregates/stored-at.js.map +1 -0
- package/dist/infrastructure/aggregates/take-recorded-events.d.ts +9 -0
- package/dist/infrastructure/aggregates/take-recorded-events.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/take-recorded-events.js +17 -0
- package/dist/infrastructure/aggregates/take-recorded-events.js.map +1 -0
- package/dist/infrastructure/aggregates/unstored-events-of.d.ts +4 -0
- package/dist/infrastructure/aggregates/unstored-events-of.d.ts.map +1 -0
- package/dist/infrastructure/aggregates/unstored-events-of.js +7 -0
- package/dist/infrastructure/aggregates/unstored-events-of.js.map +1 -0
- package/dist/infrastructure/clock/fixed-clock.d.ts +2 -1
- package/dist/infrastructure/clock/fixed-clock.d.ts.map +1 -1
- package/dist/infrastructure/clock/fixed-clock.js +5 -4
- package/dist/infrastructure/clock/fixed-clock.js.map +1 -1
- package/dist/infrastructure/context/scoped-actor-context.d.ts.map +1 -1
- package/dist/infrastructure/context/scoped-actor-context.js +2 -6
- package/dist/infrastructure/context/scoped-actor-context.js.map +1 -1
- package/dist/infrastructure/domain-events/announce-domain-events.d.ts +1 -1
- package/dist/infrastructure/domain-events/announce-domain-events.js +1 -1
- package/dist/infrastructure/domain-events/dispatching-on-save.d.ts +1 -1
- package/dist/infrastructure/domain-events/dispatching-on-save.d.ts.map +1 -1
- package/dist/infrastructure/domain-events/dispatching-on-save.js +3 -2
- package/dist/infrastructure/domain-events/dispatching-on-save.js.map +1 -1
- package/dist/infrastructure/domain-events/index.d.ts +13 -0
- package/dist/infrastructure/domain-events/index.d.ts.map +1 -0
- package/dist/infrastructure/domain-events/index.js +13 -0
- package/dist/infrastructure/domain-events/index.js.map +1 -0
- package/dist/infrastructure/domain-events/recorded-aggregates.d.ts +2 -5
- package/dist/infrastructure/domain-events/recorded-aggregates.d.ts.map +1 -1
- package/dist/infrastructure/domain-events/recorded-aggregates.js +3 -5
- package/dist/infrastructure/domain-events/recorded-aggregates.js.map +1 -1
- package/dist/infrastructure/domain-events/unit-of-work-aborted-error.d.ts +10 -0
- package/dist/infrastructure/domain-events/unit-of-work-aborted-error.d.ts.map +1 -0
- package/dist/infrastructure/domain-events/unit-of-work-aborted-error.js +13 -0
- package/dist/infrastructure/domain-events/unit-of-work-aborted-error.js.map +1 -0
- package/dist/infrastructure/domain-events/unit-of-work-over.d.ts +43 -0
- package/dist/infrastructure/domain-events/unit-of-work-over.d.ts.map +1 -0
- package/dist/infrastructure/domain-events/unit-of-work-over.js +132 -0
- package/dist/infrastructure/domain-events/unit-of-work-over.js.map +1 -0
- package/dist/infrastructure/domain-events/unit-of-work-scope.d.ts +9 -1
- package/dist/infrastructure/domain-events/unit-of-work-scope.d.ts.map +1 -1
- package/dist/infrastructure/domain-events/unit-of-work-scope.js.map +1 -1
- package/dist/infrastructure/domain-events/unscoped-unit-of-work-error.d.ts +8 -0
- package/dist/infrastructure/domain-events/unscoped-unit-of-work-error.d.ts.map +1 -0
- package/dist/infrastructure/domain-events/unscoped-unit-of-work-error.js +11 -0
- package/dist/infrastructure/domain-events/unscoped-unit-of-work-error.js.map +1 -0
- package/dist/infrastructure/domain-events/when-committed.d.ts.map +1 -1
- package/dist/infrastructure/domain-events/when-committed.js +2 -9
- package/dist/infrastructure/domain-events/when-committed.js.map +1 -1
- package/dist/infrastructure/event-sourcing/aggregate-id-of.d.ts +4 -0
- package/dist/infrastructure/event-sourcing/aggregate-id-of.d.ts.map +1 -0
- package/dist/infrastructure/event-sourcing/aggregate-id-of.js +6 -0
- package/dist/infrastructure/event-sourcing/aggregate-id-of.js.map +1 -0
- package/dist/infrastructure/event-sourcing/event-serializer.d.ts +3 -4
- package/dist/infrastructure/event-sourcing/event-serializer.d.ts.map +1 -1
- package/dist/infrastructure/event-sourcing/event-serializer.js +10 -12
- package/dist/infrastructure/event-sourcing/event-serializer.js.map +1 -1
- package/dist/infrastructure/event-sourcing/event-store-personal-data-export.d.ts.map +1 -1
- package/dist/infrastructure/event-sourcing/event-store-personal-data-export.js +1 -5
- package/dist/infrastructure/event-sourcing/event-store-personal-data-export.js.map +1 -1
- package/dist/infrastructure/events/idempotent.d.ts.map +1 -1
- package/dist/infrastructure/events/idempotent.js +9 -3
- package/dist/infrastructure/events/idempotent.js.map +1 -1
- package/dist/infrastructure/in-memory/as-json-carries.d.ts +9 -0
- package/dist/infrastructure/in-memory/as-json-carries.d.ts.map +1 -0
- package/dist/infrastructure/in-memory/as-json-carries.js +12 -0
- package/dist/infrastructure/in-memory/as-json-carries.js.map +1 -0
- package/dist/infrastructure/in-memory/composite-key.d.ts +6 -0
- package/dist/infrastructure/in-memory/composite-key.d.ts.map +1 -0
- package/dist/infrastructure/in-memory/composite-key.js +8 -0
- package/dist/infrastructure/in-memory/composite-key.js.map +1 -0
- package/dist/infrastructure/in-memory/in-memory-cache.d.ts +3 -1
- package/dist/infrastructure/in-memory/in-memory-cache.d.ts.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-cache.js +7 -3
- package/dist/infrastructure/in-memory/in-memory-cache.js.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-domain-event-dispatcher.d.ts +0 -1
- package/dist/infrastructure/in-memory/in-memory-domain-event-dispatcher.d.ts.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-domain-event-dispatcher.js +2 -9
- package/dist/infrastructure/in-memory/in-memory-domain-event-dispatcher.js.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-event-bus.d.ts +7 -14
- package/dist/infrastructure/in-memory/in-memory-event-bus.d.ts.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-event-bus.js +17 -9
- package/dist/infrastructure/in-memory/in-memory-event-bus.js.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-event-store.d.ts +1 -0
- package/dist/infrastructure/in-memory/in-memory-event-store.d.ts.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-event-store.js +11 -10
- package/dist/infrastructure/in-memory/in-memory-event-store.js.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-process-store.d.ts.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-process-store.js +4 -6
- package/dist/infrastructure/in-memory/in-memory-process-store.js.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-processed-event-store.d.ts.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-processed-event-store.js +3 -6
- package/dist/infrastructure/in-memory/in-memory-processed-event-store.js.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-unit-of-work.d.ts +4 -2
- package/dist/infrastructure/in-memory/in-memory-unit-of-work.d.ts.map +1 -1
- package/dist/infrastructure/in-memory/in-memory-unit-of-work.js +6 -4
- package/dist/infrastructure/in-memory/in-memory-unit-of-work.js.map +1 -1
- package/dist/infrastructure/in-memory/in-process-bus.d.ts +1 -0
- package/dist/infrastructure/in-memory/in-process-bus.d.ts.map +1 -1
- package/dist/infrastructure/in-memory/in-process-bus.js +4 -3
- package/dist/infrastructure/in-memory/in-process-bus.js.map +1 -1
- package/dist/infrastructure/in-memory/unit-of-work-middleware.d.ts +5 -5
- package/dist/infrastructure/in-memory/unit-of-work-middleware.d.ts.map +1 -1
- package/dist/infrastructure/in-memory/unit-of-work-middleware.js +13 -4
- package/dist/infrastructure/in-memory/unit-of-work-middleware.js.map +1 -1
- package/package.json +4 -4
- package/dist/domain/event-sourcing/unstored-events.d.ts +0 -8
- package/dist/domain/event-sourcing/unstored-events.d.ts.map +0 -1
- package/dist/domain/event-sourcing/unstored-events.js +0 -7
- package/dist/domain/event-sourcing/unstored-events.js.map +0 -1
- package/dist/domain/value-object.d.ts +0 -12
- package/dist/domain/value-object.d.ts.map +0 -1
- package/dist/domain/value-object.js +0 -40
- package/dist/domain/value-object.js.map +0 -1
- package/dist/infrastructure/domain-events/within-unit-of-work.d.ts +0 -25
- package/dist/infrastructure/domain-events/within-unit-of-work.d.ts.map +0 -1
- package/dist/infrastructure/domain-events/within-unit-of-work.js +0 -85
- package/dist/infrastructure/domain-events/within-unit-of-work.js.map +0 -1
- package/dist/infrastructure/event-sourcing/stored-origins.d.ts +0 -5
- package/dist/infrastructure/event-sourcing/stored-origins.d.ts.map +0 -1
- package/dist/infrastructure/event-sourcing/stored-origins.js +0 -3
- package/dist/infrastructure/event-sourcing/stored-origins.js.map +0 -1
- package/dist/infrastructure/event-sourcing/stored-stamp-of.d.ts +0 -11
- package/dist/infrastructure/event-sourcing/stored-stamp-of.d.ts.map +0 -1
- package/dist/infrastructure/event-sourcing/stored-stamp-of.js +0 -15
- package/dist/infrastructure/event-sourcing/stored-stamp-of.js.map +0 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { TransactionConflictError } from '../../domain/errors/transaction-conflict-error.js';
|
|
3
|
+
import { isTransactionConflict } from '../persistence/is-transaction-conflict.js';
|
|
4
|
+
import { isTransactionTimeout } from '../persistence/is-transaction-timeout.js';
|
|
5
|
+
import { TransactionTimeoutError } from '../persistence/transaction-timeout-error.js';
|
|
6
|
+
import { giveBack } from '../aggregates/give-back.js';
|
|
7
|
+
import { dispatchAfterCommit } from './dispatch-after-commit.js';
|
|
8
|
+
import { dispatchBeforeCommit } from './dispatch-before-commit.js';
|
|
9
|
+
import { UnitOfWorkAbortedError } from './unit-of-work-aborted-error.js';
|
|
10
|
+
import { unitOfWorkScope } from './unit-of-work-scope.js';
|
|
11
|
+
/**
|
|
12
|
+
* What every `UnitOfWork` is made of: the unit of work over the transactions of one database.
|
|
13
|
+
*
|
|
14
|
+
* The domain events of the aggregates saved by the work of a `run` wait in the scope of this
|
|
15
|
+
* unit of work, in recording order across the saves. Once the work has returned they are
|
|
16
|
+
* dispatched, still inside `transaction`: the handlers see every save, and what they save or
|
|
17
|
+
* append to the outbox commits with the rest. A handler that fails, like the work that fails,
|
|
18
|
+
* rejects the whole: the transaction rolls back, the waiting events reach no handler, and the
|
|
19
|
+
* aggregates the work saved are put back as it found them, at the version they were loaded at and
|
|
20
|
+
* with the events they had recorded, so the same instances can be saved again. The steps handed to
|
|
21
|
+
* `atCommit` are applied last, still inside
|
|
22
|
+
* `transaction`; when it rejects, those applied are undone. Once `transaction` has resolved, and
|
|
23
|
+
* only then, the `after-commit` handlers run, then the work handed to `afterCommit`.
|
|
24
|
+
*
|
|
25
|
+
* A deadlock or a serialization failure the database raised anywhere in the transaction, on the
|
|
26
|
+
* statement it chose, rejects the outermost `run` as a `TransactionConflictError`, a
|
|
27
|
+
* `ConcurrencyError` whose `cause` is the error of the driver: the caller runs it again. A
|
|
28
|
+
* transaction its ORM could not start in time, the pool being busy, or ended for running too
|
|
29
|
+
* long rejects it as a `TransactionTimeoutError` (`SERVICE_UNAVAILABLE`), the same way.
|
|
30
|
+
*
|
|
31
|
+
* `transaction` is called to open one, never to join: a `run` called while a transaction of
|
|
32
|
+
* this unit of work is open on the asynchronous call chain joins it, its work and nothing else,
|
|
33
|
+
* so one dispatch, at the end of the outermost. A unit of work over another database is another
|
|
34
|
+
* one, wherever it is called from: its own transaction, and its own events dispatched before its
|
|
35
|
+
* own commit. Two concurrent calls never share a scope.
|
|
36
|
+
*
|
|
37
|
+
* It commits or rolls back as a whole: once a `run` that joined has failed, the outermost one
|
|
38
|
+
* rejects, with that failure when it travelled up, with a `UnitOfWorkAbortedError` whose
|
|
39
|
+
* `cause` it is when the work caught it, a retry that then succeeded included.
|
|
40
|
+
*/
|
|
41
|
+
export function unitOfWorkOver(transaction, { rollsBack = true } = {}) {
|
|
42
|
+
// The scope of the transaction of this unit of work open on the asynchronous call chain.
|
|
43
|
+
const open = new AsyncLocalStorage();
|
|
44
|
+
return {
|
|
45
|
+
run(work) {
|
|
46
|
+
const joined = open.getStore();
|
|
47
|
+
if (isRunning(joined)) {
|
|
48
|
+
return joining(joined, work);
|
|
49
|
+
}
|
|
50
|
+
const scope = openScope(rollsBack);
|
|
51
|
+
return opened(work, scope, (scoped) => open.run(scope, () => unitOfWorkScope.run(scope, () => transaction(scoped))));
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** The work of a run that joined: its failure aborts the unit of work, whatever the caller does with it. */
|
|
56
|
+
async function joining(scope, work) {
|
|
57
|
+
try {
|
|
58
|
+
return await unitOfWorkScope.run(scope, work);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
scope.abortedBy ??= { failure: error };
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** The outermost run: the work, the dispatch and the commit steps inside `transaction`, the rest once it resolved. */
|
|
66
|
+
async function opened(work, scope, transaction) {
|
|
67
|
+
const applied = [];
|
|
68
|
+
const result = await transaction(() => thenDispatched(work, scope, applied))
|
|
69
|
+
.catch(async (error) => {
|
|
70
|
+
giveBack(scope.found);
|
|
71
|
+
await undone(applied);
|
|
72
|
+
throw translated(error);
|
|
73
|
+
})
|
|
74
|
+
.finally(() => {
|
|
75
|
+
scope.stage = 'closed';
|
|
76
|
+
scope.queue.length = 0;
|
|
77
|
+
});
|
|
78
|
+
await afterTheCommit(scope);
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
/** What the database said of the transaction, in the words of the kernel; any other failure as it is. */
|
|
82
|
+
function translated(error) {
|
|
83
|
+
if (isTransactionConflict(error)) {
|
|
84
|
+
return new TransactionConflictError(error);
|
|
85
|
+
}
|
|
86
|
+
return isTransactionTimeout(error) ? new TransactionTimeoutError(error) : error;
|
|
87
|
+
}
|
|
88
|
+
function isRunning(scope) {
|
|
89
|
+
return scope?.kind === 'unit-of-work' && (scope.stage === 'open' || scope.stage === 'before-commit');
|
|
90
|
+
}
|
|
91
|
+
function openScope(rollsBack) {
|
|
92
|
+
const scope = {
|
|
93
|
+
kind: 'unit-of-work',
|
|
94
|
+
stage: 'open',
|
|
95
|
+
queue: [],
|
|
96
|
+
dispatched: [],
|
|
97
|
+
committed: [],
|
|
98
|
+
atCommit: [],
|
|
99
|
+
};
|
|
100
|
+
return rollsBack ? { ...scope, found: new Map() } : scope;
|
|
101
|
+
}
|
|
102
|
+
async function thenDispatched(work, scope, applied) {
|
|
103
|
+
const result = await work();
|
|
104
|
+
refuseAborted(scope);
|
|
105
|
+
await dispatchBeforeCommit(scope);
|
|
106
|
+
refuseAborted(scope);
|
|
107
|
+
for (const step of scope.atCommit ?? []) {
|
|
108
|
+
await step.apply();
|
|
109
|
+
applied.push(step);
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
/** Asked before the events leave and again before the commit: a handler may have caught such a failure too. */
|
|
114
|
+
function refuseAborted({ abortedBy }) {
|
|
115
|
+
if (abortedBy !== undefined) {
|
|
116
|
+
throw new UnitOfWorkAbortedError(abortedBy.failure);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** Newest first; an undo that fails reported itself, and the others still run. */
|
|
120
|
+
async function undone(applied) {
|
|
121
|
+
for (const step of [...applied].reverse()) {
|
|
122
|
+
await step.undo().catch(() => undefined);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** The `after-commit` handlers, then the work handed to `afterCommit`; a rejection is dropped, the work reported its own. */
|
|
126
|
+
async function afterTheCommit(scope) {
|
|
127
|
+
await dispatchAfterCommit(scope);
|
|
128
|
+
for (const work of scope.committed ?? []) {
|
|
129
|
+
await work().catch(() => undefined);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=unit-of-work-over.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit-of-work-over.js","sourceRoot":"","sources":["../../../src/infrastructure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AAC;AACH,CAAC;AAED,kFAAkF;AAClF,KAAK,UAAU,MAAM,CAAC,OAA8B;IAClD,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC1C,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAED,6HAA6H;AAC7H,KAAK,UAAU,cAAc,CAAC,KAAsB;IAClD,MAAM,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAEjC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC;QACzC,MAAM,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
import type { DomainEventDispatcher } from '../../application/ports/domain-event-dispatcher.js';
|
|
3
|
+
import type { AggregateTracking } from '../../domain/aggregate-tracking.js';
|
|
3
4
|
import type { DomainEvent } from '../../domain/domain-event.js';
|
|
5
|
+
import type { AsFound } from '../aggregates/as-found.js';
|
|
4
6
|
import type { CommitStep } from './commit-step.js';
|
|
5
7
|
/** Runs the work somewhere: in an asynchronous context, in an execution context. */
|
|
6
8
|
export type Within = <T>(work: () => T) => T;
|
|
@@ -15,7 +17,7 @@ export interface QueuedDomainEvent {
|
|
|
15
17
|
readonly inContext: Within;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
|
-
* What one unit of work has to dispatch. `unit-of-work` is opened by `
|
|
20
|
+
* What one unit of work has to dispatch. `unit-of-work` is opened by a unit of work (`unitOfWorkOver`); `save`
|
|
19
21
|
* is the scope of a save made outside of any, which dispatches as soon as it resolved.
|
|
20
22
|
*/
|
|
21
23
|
export interface UnitOfWorkScope {
|
|
@@ -25,10 +27,16 @@ export interface UnitOfWorkScope {
|
|
|
25
27
|
readonly queue: QueuedDomainEvent[];
|
|
26
28
|
/** Dispatched before the commit, in that order: what the `after-commit` phase is given. */
|
|
27
29
|
readonly dispatched: QueuedDomainEvent[];
|
|
30
|
+
/** The first failure of a run that joined this unit of work: it no longer commits. */
|
|
31
|
+
abortedBy?: {
|
|
32
|
+
readonly failure: unknown;
|
|
33
|
+
};
|
|
28
34
|
/** What `afterCommit` was handed in a unit of work: run after the `after-commit` handlers, never on a rollback. */
|
|
29
35
|
readonly committed?: (() => Promise<void>)[];
|
|
30
36
|
/** What `atCommit` was handed in a unit of work: applied last, inside the transaction. */
|
|
31
37
|
readonly atCommit?: CommitStep[];
|
|
38
|
+
/** The aggregates saved in a unit of work whose transaction rolls back, as it found them: what a rollback gives back. */
|
|
39
|
+
readonly found?: Map<AggregateTracking, AsFound>;
|
|
32
40
|
}
|
|
33
41
|
export declare const unitOfWorkScope: AsyncLocalStorage<UnitOfWorkScope>;
|
|
34
42
|
//# sourceMappingURL=unit-of-work-scope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unit-of-work-scope.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/domain-events/unit-of-work-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AAC7F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,oFAAoF;AACpF,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,UAAU,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C,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,qBAAqB,EAAE,UAAU,CAAC,CAAC;IAC7D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAAC;IACvC,KAAK,EAAE,MAAM,GAAG,eAAe,GAAG,cAAc,GAAG,QAAQ,CAAC;IAC5D,qDAAqD;IACrD,QAAQ,CAAC,KAAK,EAAE,iBAAiB,EAAE,CAAC;IACpC,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,EAAE,iBAAiB,EAAE,CAAC;IACzC,sFAAsF;IACtF,SAAS,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAC1C,mHAAmH;IACnH,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;IAC7C,0FAA0F;IAC1F,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;IACjC,yHAAyH;IACzH,QAAQ,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;CAClD;AAGD,eAAO,MAAM,eAAe,oCAA2C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unit-of-work-scope.js","sourceRoot":"","sources":["../../../src/infrastructure/domain-events/unit-of-work-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"unit-of-work-scope.js","sourceRoot":"","sources":["../../../src/infrastructure/domain-events/unit-of-work-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AA0CrD,kGAAkG;AAClG,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,iBAAiB,EAAmB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A command ran in a unit of work that opened no scope for the domain events: nothing would hold
|
|
3
|
+
* them until the end of the work, and their `after-commit` handlers would run before the commit.
|
|
4
|
+
*/
|
|
5
|
+
export declare class UnscopedUnitOfWorkError extends Error {
|
|
6
|
+
constructor();
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=unscoped-unit-of-work-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unscoped-unit-of-work-error.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/domain-events/unscoped-unit-of-work-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,cAMC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A command ran in a unit of work that opened no scope for the domain events: nothing would hold
|
|
3
|
+
* them until the end of the work, and their `after-commit` handlers would run before the commit.
|
|
4
|
+
*/
|
|
5
|
+
export class UnscopedUnitOfWorkError extends Error {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('The unit of work given to unitOfWorkMiddleware opened no scope for the domain events. Build it on unitOfWorkOver of @ddd-ts-kit/kernel, around what begins and commits its transaction, or give InMemoryUnitOfWork where there is none.');
|
|
8
|
+
this.name = 'UnscopedUnitOfWorkError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=unscoped-unit-of-work-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unscoped-unit-of-work-error.js","sourceRoot":"","sources":["../../../src/infrastructure/domain-events/unscoped-unit-of-work-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD;QACE,KAAK,CACH,yOAAyO,CAC1O,CAAC;QAEF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when-committed.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/domain-events/when-committed.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"when-committed.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/domain-events/when-committed.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAC1B,MAAM,GAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAc,GACzC,OAAO,CAAC,IAAI,CAAC,CAUf"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { safely } from '../../application/observation/safely.js';
|
|
1
2
|
import { afterCommit } from './after-commit.js';
|
|
2
3
|
import { unitOfWorkScope } from './unit-of-work-scope.js';
|
|
3
4
|
/**
|
|
@@ -14,15 +15,7 @@ export async function whenCommitted(write, failed = ignored) {
|
|
|
14
15
|
await write();
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
|
-
await afterCommit(() => write().catch((error) =>
|
|
18
|
-
}
|
|
19
|
-
function tell(failed, error) {
|
|
20
|
-
try {
|
|
21
|
-
failed(error);
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
18
|
+
await afterCommit(() => write().catch((error) => safely(() => failed(error))));
|
|
26
19
|
}
|
|
27
20
|
function ignored() {
|
|
28
21
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when-committed.js","sourceRoot":"","sources":["../../../src/infrastructure/domain-events/when-committed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;A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SAAS,OAAO;IACd,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { StoredEvent } from '../../application/event-sourcing/stored-event.js';
|
|
2
|
+
/** The aggregate a stored event belongs to: the one its metadata names, else its stream. */
|
|
3
|
+
export declare function aggregateIdOf(stored: StoredEvent): string;
|
|
4
|
+
//# sourceMappingURL=aggregate-id-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate-id-of.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/aggregate-id-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAEjF,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAIzD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The aggregate a stored event belongs to: the one its metadata names, else its stream. */
|
|
2
|
+
export function aggregateIdOf(stored) {
|
|
3
|
+
const declared = stored.metadata['aggregateId'];
|
|
4
|
+
return typeof declared === 'string' ? declared : stored.stream;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=aggregate-id-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate-id-of.js","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/aggregate-id-of.ts"],"names":[],"mappings":"AAEA,4FAA4F;AAC5F,MAAM,UAAU,aAAa,CAAC,MAAmB;IAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAEhD,OAAO,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;AACjE,CAAC"}
|
|
@@ -2,25 +2,24 @@ import type { EventToAppend } from '../../application/event-sourcing/event-to-ap
|
|
|
2
2
|
import type { StoredData } from '../../application/event-sourcing/stored-data.js';
|
|
3
3
|
import type { StoredEventTypes } from '../../application/event-sourcing/stored-event-types.js';
|
|
4
4
|
import type { StoredEvent } from '../../application/event-sourcing/stored-event.js';
|
|
5
|
-
import type { IdGenerator } from '../../application/ports/id-generator.js';
|
|
6
5
|
import type { DomainEvent } from '../../domain/domain-event.js';
|
|
7
6
|
import { PersonalDataCipher } from './personal-data-cipher.js';
|
|
8
7
|
export interface EventSerializerOptions {
|
|
9
8
|
/** Seals and opens the personal values; without one, data holding a personal value is refused. */
|
|
10
9
|
readonly cipher?: PersonalDataCipher;
|
|
11
|
-
/** Gives each stored event its id. Default: a UUID. */
|
|
12
|
-
readonly ids?: IdGenerator;
|
|
13
10
|
}
|
|
14
11
|
/**
|
|
15
12
|
* Turns the domain events of one aggregate into stored events and back, as `defineStoredEvent`
|
|
16
13
|
* declared them: the current version of their shape on the way in, and on the way out the
|
|
17
14
|
* upcasters from the version they were stored with, then `decode`. Stored events are never
|
|
18
15
|
* rewritten. Personal values are sealed on the way in and opened on the way out.
|
|
16
|
+
*
|
|
17
|
+
* An event is stored under its own identity (`eventIdOf`) and read back at the rank its stream
|
|
18
|
+
* holds it at: the event a save dispatched and the one a replay reads are stamped alike.
|
|
19
19
|
*/
|
|
20
20
|
export declare class EventSerializer<E extends DomainEvent> {
|
|
21
21
|
private readonly options;
|
|
22
22
|
private readonly types;
|
|
23
|
-
private readonly ids;
|
|
24
23
|
constructor(types: StoredEventTypes<E>, options?: EventSerializerOptions);
|
|
25
24
|
/** Whether events of this name are declared here: what a subscription skips otherwise. */
|
|
26
25
|
declares(type: string): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-serializer.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-serializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;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UhD;IAED,uFAAuF;IACjF,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAUhD;IAED,OAAO,CAAC,MAAM;CAWf"}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { StoredEventData } from '../../application/event-sourcing/stored-event-data.js';
|
|
2
2
|
import { UnreadableEventError } from '../../application/event-sourcing/unreadable-event-error.js';
|
|
3
|
-
import {
|
|
3
|
+
import { eventIdOf } from '../../domain/event-id-of.js';
|
|
4
|
+
import { ranked } from '../../domain/ranked.js';
|
|
4
5
|
import { PersonalDataCipher } from './personal-data-cipher.js';
|
|
5
|
-
import {
|
|
6
|
+
import { aggregateIdOf } from './aggregate-id-of.js';
|
|
6
7
|
/**
|
|
7
8
|
* Turns the domain events of one aggregate into stored events and back, as `defineStoredEvent`
|
|
8
9
|
* declared them: the current version of their shape on the way in, and on the way out the
|
|
9
10
|
* upcasters from the version they were stored with, then `decode`. Stored events are never
|
|
10
11
|
* rewritten. Personal values are sealed on the way in and opened on the way out.
|
|
12
|
+
*
|
|
13
|
+
* An event is stored under its own identity (`eventIdOf`) and read back at the rank its stream
|
|
14
|
+
* holds it at: the event a save dispatched and the one a replay reads are stamped alike.
|
|
11
15
|
*/
|
|
12
16
|
export class EventSerializer {
|
|
13
17
|
options;
|
|
14
18
|
types = new Map();
|
|
15
|
-
ids;
|
|
16
19
|
constructor(types, options = {}) {
|
|
17
20
|
this.options = options;
|
|
18
21
|
for (const name of Object.keys(types)) {
|
|
@@ -21,7 +24,6 @@ export class EventSerializer {
|
|
|
21
24
|
this.types.set(name, declared);
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
|
-
this.ids = options.ids ?? new UuidGenerator();
|
|
25
27
|
}
|
|
26
28
|
/** Whether events of this name are declared here: what a subscription skips otherwise. */
|
|
27
29
|
declares(type) {
|
|
@@ -29,11 +31,12 @@ export class EventSerializer {
|
|
|
29
31
|
}
|
|
30
32
|
async serialize(event) {
|
|
31
33
|
const declared = this.typeOf(event.name);
|
|
34
|
+
const data = await this.seal(declared.encode(event));
|
|
32
35
|
return {
|
|
33
|
-
id:
|
|
36
|
+
id: eventIdOf(event),
|
|
34
37
|
type: event.name,
|
|
35
38
|
schemaVersion: declared.version,
|
|
36
|
-
data
|
|
39
|
+
data,
|
|
37
40
|
metadata: { aggregateId: event.aggregateId },
|
|
38
41
|
occurredAt: event.occurredAt,
|
|
39
42
|
};
|
|
@@ -48,8 +51,7 @@ export class EventSerializer {
|
|
|
48
51
|
occurredAt: stored.occurredAt,
|
|
49
52
|
version: stored.version,
|
|
50
53
|
});
|
|
51
|
-
|
|
52
|
-
return event;
|
|
54
|
+
return ranked(event, stored.version);
|
|
53
55
|
}
|
|
54
56
|
/** Seals the personal values of the data, for an event or a snapshot. */
|
|
55
57
|
async seal(data) {
|
|
@@ -97,8 +99,4 @@ function upcast(declared, data, stored) {
|
|
|
97
99
|
}
|
|
98
100
|
return current;
|
|
99
101
|
}
|
|
100
|
-
function aggregateIdOf(stored) {
|
|
101
|
-
const declared = stored.metadata['aggregateId'];
|
|
102
|
-
return typeof declared === 'string' ? declared : stored.stream;
|
|
103
|
-
}
|
|
104
102
|
//# sourceMappingURL=event-serializer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-serializer.js","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-serializer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AAIrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yDAAyD,CAAC;
|
|
1
|
+
{"version":3,"file":"event-serializer.js","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-serializer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AAIrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yDAAyD,CAAC;AAE/F,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAA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;YAC3B,MAAM,IAAI,oBAAoB,CAAC,GAAG,MAAM,CAAC,IAAI,iCAAiC,OAAO,EAAE,CAAC,CAAC;QAC3F,CAAC;QAED,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-store-personal-data-export.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-store-personal-data-export.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sDAAsD,CAAC;AAC/F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"event-store-personal-data-export.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-store-personal-data-export.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sDAAsD,CAAC;AAC/F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAIjF,MAAM,WAAW,mCAAmC;IAClD,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,sFAAsF;IACtF,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,4FAA4F;IAC5F,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC;IAChC,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,4BAA6B,YAAW,kBAAkB;IAGzD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAA6B,OAAO,EAAE,mCAAmC,EAExE;IAEK,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,kBAAkB,EAAE,CAAC,CAwBtE;IAED,uHAAuH;YACxG,iBAAiB;CAmBjC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PersonalDataCipher } from './personal-data-cipher.js';
|
|
2
|
+
import { aggregateIdOf } from './aggregate-id-of.js';
|
|
2
3
|
/**
|
|
3
4
|
* What the event store keeps of a person, for the right of access and to portability: one record
|
|
4
5
|
* per event that holds a value sealed with `personalData(subject, value)` for the subject, under
|
|
@@ -55,11 +56,6 @@ export class EventStorePersonalDataExport {
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
|
-
/** The aggregate the event belongs to, as the serializer reads it: its metadata, else its stream. */
|
|
59
|
-
function aggregateIdOf(event) {
|
|
60
|
-
const declared = event.metadata['aggregateId'];
|
|
61
|
-
return typeof declared === 'string' ? declared : event.stream;
|
|
62
|
-
}
|
|
63
59
|
/** The lookup of a key that reads each one once, however many values it sealed. */
|
|
64
60
|
function rememberedKeys(keys) {
|
|
65
61
|
const found = new Map();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-store-personal-data-export.js","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-store-personal-data-export.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"event-store-personal-data-export.js","sourceRoot":"","sources":["../../../src/infrastructure/event-sourcing/event-store-personal-data-export.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAkBlD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,4BAA4B;IAGV,OAAO;IAF3B,IAAI,CAAS;IAEtB,YAA6B,OAA4C;uBAA5C,OAAO;QAClC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,aAAa,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAe;QAC5B,MAAM,MAAM,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACzD,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,OAAO,GAAyB,EAAE,CAAC;QAEzC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,iBAAiB,EAAE,EAAE,CAAC;YACnD,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAEhF,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC5D,OAAO,CAAC,IAAI,CAAC;oBACX,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE;oBACpC,MAAM;oBACN,KAAK,EAAE;wBACL,MAAM,EAAE,KAAK,CAAC,MAAM;wBACpB,WAAW,EAAE,aAAa,CAAC,KAAK,CAAC;wBACjC,OAAO,EAAE,KAAK,CAAC,OAAO;wBACtB,UAAU,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AEtB,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idempotent.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/events/idempotent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qDAAqD,CAAC;AACpG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AAEzF;;;GAGG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,mBAAmB,EAC1B,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,
|
|
1
|
+
{"version":3,"file":"idempotent.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/events/idempotent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qDAAqD,CAAC;AACpG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AAEzF;;;GAGG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,mBAAmB,EAC1B,OAAO,EAAE,wBAAwB,GAChC,wBAAwB,CAiB1B"}
|
|
@@ -10,10 +10,16 @@ export function idempotent(consumer, store, handler) {
|
|
|
10
10
|
try {
|
|
11
11
|
await handler(event, delivery);
|
|
12
12
|
}
|
|
13
|
-
catch (
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
catch (failure) {
|
|
14
|
+
// A store that cannot give the mark back keeps it: both failures are told, the one of the handler first.
|
|
15
|
+
await store.release?.(consumer, event.id).catch((notReleased) => {
|
|
16
|
+
throw new AggregateError([failure, notReleased], markKept(consumer, event.id), { cause: failure });
|
|
17
|
+
});
|
|
18
|
+
throw failure;
|
|
16
19
|
}
|
|
17
20
|
};
|
|
18
21
|
}
|
|
22
|
+
function markKept(consumer, eventId) {
|
|
23
|
+
return `The handler of ${consumer} failed on event ${eventId} and its mark could not be released: a redelivery will be skipped.`;
|
|
24
|
+
}
|
|
19
25
|
//# sourceMappingURL=idempotent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idempotent.js","sourceRoot":"","sources":["../../../src/infrastructure/events/idempotent.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,UAAU,UAAU,CACxB,QAAgB,EAChB,KAA0B,EAC1B,OAAiC;IAEjC,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;QAC/B,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YACrD,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"idempotent.js","sourceRoot":"","sources":["../../../src/infrastructure/events/idempotent.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,UAAU,UAAU,CACxB,QAAgB,EAChB,KAA0B,EAC1B,OAAiC;IAEjC,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;QAC/B,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YACrD,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,OAAO,EAAE,CAAC;YACjB,yGAAyG;YACzG,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,WAAoB,EAAE,EAAE;gBACvE,MAAM,IAAI,cAAc,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;YACrG,CAAC,CAAC,CAAC;YAEH,MAAM,OAAO,CAAC;QAChB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,QAAgB,EAAE,OAAe;IACjD,OAAO,kBAAkB,QAAQ,oBAAoB,OAAO,oEAAoE,CAAC;AACnI,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value as JSON carries it to another process and back: a copy, where a `Date` is its text, a
|
|
3
|
+
* class instance a plain object and an `undefined` property is gone. What JSON cannot carry (a
|
|
4
|
+
* bigint, a cycle) is refused with the `TypeError` of `JSON.stringify`, as a broker or a shared
|
|
5
|
+
* cache refuses it. The in-memory cache and event bus hand values this way, so that a spec green
|
|
6
|
+
* on them holds behind the real ones.
|
|
7
|
+
*/
|
|
8
|
+
export declare function asJsonCarries(value: unknown): unknown;
|
|
9
|
+
//# sourceMappingURL=as-json-carries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"as-json-carries.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/in-memory/as-json-carries.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAIrD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value as JSON carries it to another process and back: a copy, where a `Date` is its text, a
|
|
3
|
+
* class instance a plain object and an `undefined` property is gone. What JSON cannot carry (a
|
|
4
|
+
* bigint, a cycle) is refused with the `TypeError` of `JSON.stringify`, as a broker or a shared
|
|
5
|
+
* cache refuses it. The in-memory cache and event bus hand values this way, so that a spec green
|
|
6
|
+
* on them holds behind the real ones.
|
|
7
|
+
*/
|
|
8
|
+
export function asJsonCarries(value) {
|
|
9
|
+
const carried = value === undefined ? undefined : JSON.parse(JSON.stringify(value));
|
|
10
|
+
return carried;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=as-json-carries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"as-json-carries.js","sourceRoot":"","sources":["../../../src/infrastructure/in-memory/as-json-carries.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,MAAM,OAAO,GAAY,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAE7F,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The key of a map for what several values identify together. JSON keeps the parts apart:
|
|
3
|
+
* `'a:b'` with `'c'` must not be the key of `'a'` with `'b:c'`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function compositeKey(...parts: readonly string[]): string;
|
|
6
|
+
//# sourceMappingURL=composite-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composite-key.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/in-memory/composite-key.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEhE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The key of a map for what several values identify together. JSON keeps the parts apart:
|
|
3
|
+
* `'a:b'` with `'c'` must not be the key of `'a'` with `'b:c'`.
|
|
4
|
+
*/
|
|
5
|
+
export function compositeKey(...parts) {
|
|
6
|
+
return JSON.stringify(parts);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=composite-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composite-key.js","sourceRoot":"","sources":["../../../src/infrastructure/in-memory/composite-key.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,GAAG,KAAwB;IACtD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -7,7 +7,9 @@ export interface InMemoryCacheOptions {
|
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* A bounded map in the memory of the process, with expiry read from the `Clock`. Fine for one
|
|
10
|
-
* instance and for tests; several instances share nothing.
|
|
10
|
+
* instance and for tests; several instances share nothing. It keeps and hands values as a shared
|
|
11
|
+
* cache does, as JSON carries them: a copy at each write and each read, a `Date` as its text,
|
|
12
|
+
* and a value JSON cannot carry (a bigint, a cycle) refused at the write.
|
|
11
13
|
*/
|
|
12
14
|
export declare class InMemoryCache implements Cache {
|
|
13
15
|
private readonly clock;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-cache.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/in-memory/in-memory-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"in-memory-cache.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/in-memory/in-memory-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAG3D,MAAM,WAAW,oBAAoB;IACnC,qDAAqD;IACrD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAUD;;;;;GAKG;AACH,qBAAa,aAAc,YAAW,KAAK;IAMvC,OAAO,CAAC,QAAQ,CAAC,KAAK;IALxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IAEpD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC,YACmB,KAAK,EAAE,KAAK,EAC7B,OAAO,GAAE,oBAAyB,EAGnC;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAEK,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAerD;IAEK,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAWvF;IAEK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAElD;IAED,OAAO,CAAC,mBAAmB;CAS5B"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { asJsonCarries } from './as-json-carries.js';
|
|
1
2
|
const DEFAULT_MAX_ENTRIES = 1000;
|
|
2
3
|
/**
|
|
3
4
|
* A bounded map in the memory of the process, with expiry read from the `Clock`. Fine for one
|
|
4
|
-
* instance and for tests; several instances share nothing.
|
|
5
|
+
* instance and for tests; several instances share nothing. It keeps and hands values as a shared
|
|
6
|
+
* cache does, as JSON carries them: a copy at each write and each read, a `Date` as its text,
|
|
7
|
+
* and a value JSON cannot carry (a bigint, a cycle) refused at the write.
|
|
5
8
|
*/
|
|
6
9
|
export class InMemoryCache {
|
|
7
10
|
clock;
|
|
@@ -24,12 +27,13 @@ export class InMemoryCache {
|
|
|
24
27
|
return undefined;
|
|
25
28
|
}
|
|
26
29
|
// eslint-disable-next-line ddd-ts-kit/clean-no-escape-hatch -- entries of every type share one map: the link between a key and the type of its value is only known to the CacheKey that wrote it
|
|
27
|
-
return entry.value;
|
|
30
|
+
return asJsonCarries(entry.value);
|
|
28
31
|
}
|
|
29
32
|
async set(key, value, options = {}) {
|
|
33
|
+
const carried = asJsonCarries(value);
|
|
30
34
|
this.entries.delete(key.name);
|
|
31
35
|
this.entries.set(key.name, {
|
|
32
|
-
value,
|
|
36
|
+
value: carried,
|
|
33
37
|
...(options.ttlMs === undefined ? {} : { expiresAt: this.clock.now().getTime() + options.ttlMs }),
|
|
34
38
|
});
|
|
35
39
|
this.evictBeyondCapacity();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-cache.js","sourceRoot":"","sources":["../../../src/infrastructure/in-memory/in-memory-cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"in-memory-cache.js","sourceRoot":"","sources":["../../../src/infrastructure/in-memory/in-memory-cache.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAalD,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IAML,KAAK;IALP,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;IAEnC,UAAU,CAAS;IAEpC,YACmB,KAAY,EAC7B,OAAO,GAAyB,EAAE;qBADjB,KAAK;QAGtB,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,mBAAmB,CAAC;IAC9D,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,GAAG,CAAI,GAAgB;QAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAA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MAAM,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -21,6 +21,5 @@ export declare class InMemoryDomainEventDispatcher implements DomainEventDispatc
|
|
|
21
21
|
on(name: string, handler: DomainEventCallback, subscription?: DomainEventSubscription): void;
|
|
22
22
|
dispatch(events: readonly DomainEvent[], phase?: DomainEventPhase): Promise<void>;
|
|
23
23
|
private attempted;
|
|
24
|
-
private tell;
|
|
25
24
|
}
|
|
26
25
|
//# sourceMappingURL=in-memory-domain-event-dispatcher.d.ts.map
|