@graphrefly/ts 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -0
- package/dist/adapters/index.cjs +105 -66
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +11 -136
- package/dist/adapters/index.d.ts +11 -136
- package/dist/adapters/index.js +27 -225
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/observe-storage.d.cts +4 -4
- package/dist/adapters/observe-storage.d.ts +4 -4
- package/dist/adapters/observe-storage.js +1 -0
- package/dist/adapters/observe-storage.js.map +1 -1
- package/dist/adapters/react.cjs +166 -0
- package/dist/adapters/react.cjs.map +1 -0
- package/dist/adapters/react.d.cts +31 -0
- package/dist/adapters/react.d.ts +31 -0
- package/dist/adapters/react.js +51 -0
- package/dist/adapters/react.js.map +1 -0
- package/dist/adapters/solid.cjs +157 -0
- package/dist/adapters/solid.cjs.map +1 -0
- package/dist/adapters/solid.d.cts +26 -0
- package/dist/adapters/solid.d.ts +26 -0
- package/dist/adapters/solid.js +48 -0
- package/dist/adapters/solid.js.map +1 -0
- package/dist/adapters/svelte.cjs +148 -0
- package/dist/adapters/svelte.cjs.map +1 -0
- package/dist/adapters/svelte.d.cts +31 -0
- package/dist/adapters/svelte.d.ts +31 -0
- package/dist/adapters/svelte.js +46 -0
- package/dist/adapters/svelte.js.map +1 -0
- package/dist/adapters/vue.cjs +155 -0
- package/dist/adapters/vue.cjs.map +1 -0
- package/dist/adapters/vue.d.cts +26 -0
- package/dist/adapters/vue.d.ts +26 -0
- package/dist/adapters/vue.js +46 -0
- package/dist/adapters/vue.js.map +1 -0
- package/dist/agent-runtime-BesGDZcB.d.ts +555 -0
- package/dist/agent-runtime-DZTJ3C-p.d.cts +555 -0
- package/dist/agentic-memory-BmRCvh0d.d.ts +517 -0
- package/dist/agentic-memory-DfuVZ-lY.d.cts +517 -0
- package/dist/capability-admission-B0BzqAm5.d.cts +102 -0
- package/dist/capability-admission-g0mn9hpq.d.ts +102 -0
- package/dist/{chunk-JR4IKCR2.js → chunk-2747WN4Y.js} +5 -5
- package/dist/{chunk-2ILL7HQI.js → chunk-3JR3EDB2.js} +17 -17
- package/dist/{chunk-2ILL7HQI.js.map → chunk-3JR3EDB2.js.map} +1 -1
- package/dist/{chunk-GDL26N2T.js → chunk-3KN7NJDR.js} +2 -2
- package/dist/{chunk-DJC4CHLQ.js → chunk-43BKLFZU.js} +9 -9
- package/dist/chunk-6XAIOL3X.js +2407 -0
- package/dist/chunk-6XAIOL3X.js.map +1 -0
- package/dist/{chunk-SCRFRCGR.js → chunk-BSQGE5PS.js} +1 -1
- package/dist/{chunk-Y3ZLRGHC.js → chunk-CZNV3VXM.js} +16 -16
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/{chunk-JIMUDQN3.js → chunk-FBUU43PM.js} +2 -2
- package/dist/chunk-H75VXTGT.js +219 -0
- package/dist/chunk-H75VXTGT.js.map +1 -0
- package/dist/{chunk-RIIOUTGM.js → chunk-HKK2JD7Z.js} +12 -9
- package/dist/chunk-HKK2JD7Z.js.map +1 -0
- package/dist/{chunk-D6BG7U6A.js → chunk-IXZBUWSP.js} +3 -3
- package/dist/chunk-PC3BTTBE.js +3217 -0
- package/dist/chunk-PC3BTTBE.js.map +1 -0
- package/dist/chunk-QFY4AFY4.js +879 -0
- package/dist/chunk-QFY4AFY4.js.map +1 -0
- package/dist/{chunk-DK554R7P.js → chunk-S6HXABGL.js} +2 -1
- package/dist/chunk-S6HXABGL.js.map +1 -0
- package/dist/{chunk-PKVBHGBM.js → chunk-SS2A464I.js} +7 -7
- package/dist/chunk-UT3MHJCW.js +49 -0
- package/dist/chunk-UT3MHJCW.js.map +1 -0
- package/dist/{chunk-G4M3NHRJ.js → chunk-V7CIJE4B.js} +3 -3
- package/dist/{chunk-TEW47IVR.js → chunk-VPEFSDME.js} +2 -2
- package/dist/chunk-VTHLCFN4.js +368 -0
- package/dist/chunk-VTHLCFN4.js.map +1 -0
- package/dist/{chunk-SWTLEQL6.js → chunk-WQIA3GFB.js} +2 -2
- package/dist/chunk-WQIA3GFB.js.map +1 -0
- package/dist/{chunk-I3IHOHCJ.js → chunk-XKXWK2KP.js} +108 -64
- package/dist/chunk-XKXWK2KP.js.map +1 -0
- package/dist/{chunk-COHO25CZ.js → chunk-YDSIVHRR.js} +553 -7
- package/dist/chunk-YDSIVHRR.js.map +1 -0
- package/dist/chunk-YXMZ2N6J.js +1884 -0
- package/dist/chunk-YXMZ2N6J.js.map +1 -0
- package/dist/composition/index.cjs +102 -57
- package/dist/composition/index.cjs.map +1 -1
- package/dist/composition/index.d.cts +4 -4
- package/dist/composition/index.d.ts +4 -4
- package/dist/composition/index.js +6 -5
- package/dist/core/index.cjs +102 -57
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +5 -4
- package/dist/cqrs/index.cjs.map +1 -1
- package/dist/cqrs/index.d.cts +4 -4
- package/dist/cqrs/index.d.ts +4 -4
- package/dist/cqrs/index.js +3 -2
- package/dist/cqrs/index.js.map +1 -1
- package/dist/cqrs/messaging.cjs +312 -0
- package/dist/cqrs/messaging.cjs.map +1 -0
- package/dist/cqrs/messaging.d.cts +57 -0
- package/dist/cqrs/messaging.d.ts +57 -0
- package/dist/cqrs/messaging.js +274 -0
- package/dist/cqrs/messaging.js.map +1 -0
- package/dist/cqrs/work-queue.cjs +329 -0
- package/dist/cqrs/work-queue.cjs.map +1 -0
- package/dist/cqrs/work-queue.d.cts +90 -0
- package/dist/cqrs/work-queue.d.ts +90 -0
- package/dist/cqrs/work-queue.js +292 -0
- package/dist/cqrs/work-queue.js.map +1 -0
- package/dist/data/index.cjs +19 -0
- package/dist/data/index.cjs.map +1 -0
- package/dist/data/index.d.cts +36 -0
- package/dist/data/index.d.ts +36 -0
- package/dist/data/index.js +1 -0
- package/dist/data/index.js.map +1 -0
- package/dist/data-structures/index.cjs +105 -57
- package/dist/data-structures/index.cjs.map +1 -1
- package/dist/data-structures/index.d.cts +8 -8
- package/dist/data-structures/index.d.ts +8 -8
- package/dist/data-structures/index.js +7 -6
- package/dist/{describe-BZb7AS2y.d.ts → describe-BpyJuWkw.d.ts} +1 -1
- package/dist/{describe-Ciu8SUnN.d.cts → describe-DYMw_l1C.d.cts} +1 -1
- package/dist/executors/work-queue.cjs +342 -0
- package/dist/executors/work-queue.cjs.map +1 -0
- package/dist/executors/work-queue.d.cts +90 -0
- package/dist/executors/work-queue.d.ts +90 -0
- package/dist/executors/work-queue.js +306 -0
- package/dist/executors/work-queue.js.map +1 -0
- package/dist/graph/index.cjs +112 -58
- package/dist/graph/index.cjs.map +1 -1
- package/dist/graph/index.d.cts +9 -9
- package/dist/graph/index.d.ts +9 -9
- package/dist/graph/index.js +18 -17
- package/dist/{graph-DfdF9zy4.d.ts → graph-D-1-SQeC.d.ts} +3 -3
- package/dist/{graph-s23RbbFO.d.cts → graph-DCEWh4T2.d.cts} +3 -3
- package/dist/{index-CAEmLCYF.d.cts → index-72VZC0-E.d.cts} +2 -2
- package/dist/{index-SnzZu3x7.d.ts → index-Bmxeu0nK.d.ts} +2 -2
- package/dist/index.cjs +112 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -10
- package/dist/index.d.ts +11 -10
- package/dist/index.js +118 -113
- package/dist/inspection/boundary.cjs +98 -0
- package/dist/inspection/boundary.cjs.map +1 -0
- package/dist/inspection/boundary.d.cts +61 -0
- package/dist/inspection/boundary.d.ts +61 -0
- package/dist/inspection/boundary.js +75 -0
- package/dist/inspection/boundary.js.map +1 -0
- package/dist/{messages-BZqrGGm1.d.ts → messages-CAzUPPJM.d.cts} +10 -5
- package/dist/{messages-BZqrGGm1.d.cts → messages-CAzUPPJM.d.ts} +10 -5
- package/dist/messaging/index.cjs +744 -613
- package/dist/messaging/index.cjs.map +1 -1
- package/dist/messaging/index.d.cts +216 -160
- package/dist/messaging/index.d.ts +216 -160
- package/dist/messaging/index.js +19 -749
- package/dist/messaging/index.js.map +1 -1
- package/dist/operators/index.cjs +102 -57
- package/dist/operators/index.cjs.map +1 -1
- package/dist/operators/index.d.cts +6 -6
- package/dist/operators/index.d.ts +6 -6
- package/dist/operators/index.js +8 -7
- package/dist/orchestration/index.cjs +3333 -59
- package/dist/orchestration/index.cjs.map +1 -1
- package/dist/orchestration/index.d.cts +7 -4
- package/dist/orchestration/index.d.ts +7 -4
- package/dist/orchestration/index.js +49 -8
- package/dist/orchestration/index.js.map +1 -1
- package/dist/orchestration/messaging.cjs +314 -0
- package/dist/orchestration/messaging.cjs.map +1 -0
- package/dist/orchestration/messaging.d.cts +59 -0
- package/dist/orchestration/messaging.d.ts +59 -0
- package/dist/orchestration/messaging.js +276 -0
- package/dist/orchestration/messaging.js.map +1 -0
- package/dist/orchestration/work-queue.cjs +262 -0
- package/dist/orchestration/work-queue.cjs.map +1 -0
- package/dist/orchestration/work-queue.d.cts +85 -0
- package/dist/orchestration/work-queue.d.ts +85 -0
- package/dist/orchestration/work-queue.js +226 -0
- package/dist/orchestration/work-queue.js.map +1 -0
- package/dist/patterns/event-flow.cjs +447 -0
- package/dist/patterns/event-flow.cjs.map +1 -0
- package/dist/patterns/event-flow.d.cts +115 -0
- package/dist/patterns/event-flow.d.ts +115 -0
- package/dist/patterns/event-flow.js +14 -0
- package/dist/patterns/event-flow.js.map +1 -0
- package/dist/patterns/index.cjs +423 -18
- package/dist/patterns/index.cjs.map +1 -1
- package/dist/patterns/index.d.cts +8 -5
- package/dist/patterns/index.d.ts +8 -5
- package/dist/patterns/index.js +13 -4
- package/dist/{reactive-collection-Cb1II1Fi.d.ts → reactive-collection-BAmfrGjd.d.ts} +9 -9
- package/dist/{reactive-collection-BxBqtIOE.d.cts → reactive-collection-DNV0-gFi.d.cts} +9 -9
- package/dist/{reactive-collection-storage-D-KmjE0J.d.cts → reactive-collection-storage-BNEldDyi.d.cts} +5 -5
- package/dist/{reactive-collection-storage-BNiEc-Gd.d.ts → reactive-collection-storage-YZsAQsWK.d.ts} +5 -5
- package/dist/{reactive-map-D-g3dv8I.d.cts → reactive-map-DRD1LJ2H.d.cts} +6 -6
- package/dist/{reactive-map-BcB4KsQR.d.ts → reactive-map-EsDiCmJk.d.ts} +6 -6
- package/dist/render/index.d.cts +3 -3
- package/dist/render/index.d.ts +3 -3
- package/dist/render/index.js +1 -0
- package/dist/{semantic-memory-graph-BYoIlP35.d.cts → semantic-memory-graph-DKuNzuWw.d.cts} +2 -2
- package/dist/{semantic-memory-graph-CxyXLms3.d.ts → semantic-memory-graph-uwbwJdhe.d.ts} +2 -2
- package/dist/solutions/index.cjs +4478 -2
- package/dist/solutions/index.cjs.map +1 -1
- package/dist/solutions/index.d.cts +13 -519
- package/dist/solutions/index.d.ts +13 -519
- package/dist/solutions/index.js +90 -6
- package/dist/solutions/reactive-layout/browser/index.cjs +449 -0
- package/dist/solutions/reactive-layout/browser/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/browser/index.d.cts +44 -0
- package/dist/solutions/reactive-layout/browser/index.d.ts +44 -0
- package/dist/solutions/reactive-layout/browser/index.js +69 -0
- package/dist/solutions/reactive-layout/browser/index.js.map +1 -0
- package/dist/solutions/reactive-layout/index.cjs +4266 -0
- package/dist/solutions/reactive-layout/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/index.d.cts +581 -0
- package/dist/solutions/reactive-layout/index.d.ts +581 -0
- package/dist/solutions/reactive-layout/index.js +86 -0
- package/dist/solutions/reactive-layout/index.js.map +1 -0
- package/dist/solutions/reactive-layout/node-canvas/index.cjs +545 -0
- package/dist/solutions/reactive-layout/node-canvas/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/node-canvas/index.d.cts +54 -0
- package/dist/solutions/reactive-layout/node-canvas/index.d.ts +54 -0
- package/dist/solutions/reactive-layout/node-canvas/index.js +131 -0
- package/dist/solutions/reactive-layout/node-canvas/index.js.map +1 -0
- package/dist/solutions/reactive-layout/react-native/index.cjs +494 -0
- package/dist/solutions/reactive-layout/react-native/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/react-native/index.d.cts +51 -0
- package/dist/solutions/reactive-layout/react-native/index.d.ts +51 -0
- package/dist/solutions/reactive-layout/react-native/index.js +77 -0
- package/dist/solutions/reactive-layout/react-native/index.js.map +1 -0
- package/dist/solutions/reactive-layout/skia/index.cjs +547 -0
- package/dist/solutions/reactive-layout/skia/index.cjs.map +1 -0
- package/dist/solutions/reactive-layout/skia/index.d.cts +64 -0
- package/dist/solutions/reactive-layout/skia/index.d.ts +64 -0
- package/dist/solutions/reactive-layout/skia/index.js +70 -0
- package/dist/solutions/reactive-layout/skia/index.js.map +1 -0
- package/dist/solutions/work-item/actions.cjs +2164 -0
- package/dist/solutions/work-item/actions.cjs.map +1 -0
- package/dist/solutions/work-item/actions.d.cts +201 -0
- package/dist/solutions/work-item/actions.d.ts +201 -0
- package/dist/solutions/work-item/actions.js +1454 -0
- package/dist/solutions/work-item/actions.js.map +1 -0
- package/dist/solutions/work-item/scheduling.cjs +2454 -0
- package/dist/solutions/work-item/scheduling.cjs.map +1 -0
- package/dist/solutions/work-item/scheduling.d.cts +433 -0
- package/dist/solutions/work-item/scheduling.d.ts +433 -0
- package/dist/solutions/work-item/scheduling.js +32 -0
- package/dist/solutions/work-item/scheduling.js.map +1 -0
- package/dist/solutions/work-item/work-queue.cjs +306 -0
- package/dist/solutions/work-item/work-queue.cjs.map +1 -0
- package/dist/solutions/work-item/work-queue.d.cts +71 -0
- package/dist/solutions/work-item/work-queue.d.ts +71 -0
- package/dist/solutions/work-item/work-queue.js +270 -0
- package/dist/solutions/work-item/work-queue.js.map +1 -0
- package/dist/sources/browser.cjs +169 -57
- package/dist/sources/browser.cjs.map +1 -1
- package/dist/sources/browser.d.cts +33 -6
- package/dist/sources/browser.d.ts +33 -6
- package/dist/sources/browser.js +73 -6
- package/dist/sources/browser.js.map +1 -1
- package/dist/sources/index.cjs +102 -57
- package/dist/sources/index.cjs.map +1 -1
- package/dist/sources/index.d.cts +5 -5
- package/dist/sources/index.d.ts +5 -5
- package/dist/sources/index.js +6 -5
- package/dist/sources/node.cjs.map +1 -1
- package/dist/sources/node.d.cts +4 -4
- package/dist/sources/node.d.ts +4 -4
- package/dist/sources/node.js +2 -1
- package/dist/sources/node.js.map +1 -1
- package/dist/storage/browser.js +1 -0
- package/dist/storage/browser.js.map +1 -1
- package/dist/storage/index.d.cts +5 -5
- package/dist/storage/index.d.ts +5 -5
- package/dist/storage/index.js +5 -4
- package/dist/storage/node.js +1 -0
- package/dist/storage/node.js.map +1 -1
- package/dist/store-C-joM4gh.d.ts +123 -0
- package/dist/store-CNJwmT-h.d.cts +123 -0
- package/dist/testing/index.cjs +1 -0
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +3 -2
- package/dist/{types-h12mNYbq.d.ts → types-BsJvElYZ.d.ts} +31 -31
- package/dist/{types-bNMSWKqF.d.cts → types-CcPIn7sy.d.cts} +31 -31
- package/dist/work-item-runtime-C3M79vE9.d.ts +228 -0
- package/dist/work-item-runtime-qaVgsL0T.d.cts +228 -0
- package/dist/work-queue/index.cjs +1132 -0
- package/dist/work-queue/index.cjs.map +1 -0
- package/dist/work-queue/index.d.cts +369 -0
- package/dist/work-queue/index.d.ts +369 -0
- package/dist/work-queue/index.js +1078 -0
- package/dist/work-queue/index.js.map +1 -0
- package/package.json +266 -2
- package/dist/chunk-COHO25CZ.js.map +0 -1
- package/dist/chunk-DK554R7P.js.map +0 -1
- package/dist/chunk-I3IHOHCJ.js.map +0 -1
- package/dist/chunk-RIIOUTGM.js.map +0 -1
- package/dist/chunk-SWTLEQL6.js.map +0 -1
- /package/dist/{chunk-JR4IKCR2.js.map → chunk-2747WN4Y.js.map} +0 -0
- /package/dist/{chunk-GDL26N2T.js.map → chunk-3KN7NJDR.js.map} +0 -0
- /package/dist/{chunk-DJC4CHLQ.js.map → chunk-43BKLFZU.js.map} +0 -0
- /package/dist/{chunk-SCRFRCGR.js.map → chunk-BSQGE5PS.js.map} +0 -0
- /package/dist/{chunk-Y3ZLRGHC.js.map → chunk-CZNV3VXM.js.map} +0 -0
- /package/dist/{chunk-JIMUDQN3.js.map → chunk-FBUU43PM.js.map} +0 -0
- /package/dist/{chunk-D6BG7U6A.js.map → chunk-IXZBUWSP.js.map} +0 -0
- /package/dist/{chunk-PKVBHGBM.js.map → chunk-SS2A464I.js.map} +0 -0
- /package/dist/{chunk-G4M3NHRJ.js.map → chunk-V7CIJE4B.js.map} +0 -0
- /package/dist/{chunk-TEW47IVR.js.map → chunk-VPEFSDME.js.map} +0 -0
package/dist/core/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { C as Ctx, a as CtxState, D as Dispatcher, H as Handle, f as HandleStat, N as Node, m as NodeFn, n as NodeOptions, o as NodeVersion, p as NodeVersionHashFn, q as NodeVersionJson, r as NodeVersionV0, s as NodeVersionV1, t as NodeVersioningLevel, u as NodeVersioningPolicy, P as Pool, v as PoolKind, R as RewireNext, S as Sink, B as Status, T as TerminalData, W as WaveData, Z as defaultDispatcher, _ as defaultNodeVersionHash, $ as depBatch, a0 as depCount, a1 as depLatest, a2 as depTerminal, a3 as depWaves, a5 as dynamicNode, a7 as isTerminalComplete, a8 as isTerminalError, a9 as isTerminalNone, aa as node, ab as terminalErrorValue } from '../types-
|
|
2
|
-
export { L as LockId, M as Message, a as MessageType, S as SENTINEL, T as TIER_CONTROL, b as TIER_NOTIFICATION, c as TIER_SETTLE, d as TIER_START, e as TIER_TEARDOWN, f as TIER_TERMINAL, g as TIER_VALUE, W as Wave, h as errorPayload, i as isDeferredTier, j as isInvalidErrorPayload, k as isPauseBufferedTier, l as isTerminal, m as isUpAllowed, n as isValueTier, o as messageTier } from '../messages-
|
|
1
|
+
export { C as Ctx, a as CtxState, D as Dispatcher, H as Handle, f as HandleStat, N as Node, m as NodeFn, n as NodeOptions, o as NodeVersion, p as NodeVersionHashFn, q as NodeVersionJson, r as NodeVersionV0, s as NodeVersionV1, t as NodeVersioningLevel, u as NodeVersioningPolicy, P as Pool, v as PoolKind, R as RewireNext, S as Sink, B as Status, T as TerminalData, W as WaveData, Z as defaultDispatcher, _ as defaultNodeVersionHash, $ as depBatch, a0 as depCount, a1 as depLatest, a2 as depTerminal, a3 as depWaves, a5 as dynamicNode, a7 as isTerminalComplete, a8 as isTerminalError, a9 as isTerminalNone, aa as node, ab as terminalErrorValue } from '../types-CcPIn7sy.cjs';
|
|
2
|
+
export { L as LockId, M as Message, a as MessageType, P as PullDemand, S as SENTINEL, T as TIER_CONTROL, b as TIER_NOTIFICATION, c as TIER_SETTLE, d as TIER_START, e as TIER_TEARDOWN, f as TIER_TERMINAL, g as TIER_VALUE, W as Wave, h as errorPayload, i as isDeferredTier, j as isInvalidErrorPayload, k as isPauseBufferedTier, l as isTerminal, m as isUpAllowed, n as isValueTier, o as messageTier } from '../messages-CAzUPPJM.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Declarative batch (R-batch-coalesce / D12).
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { C as Ctx, a as CtxState, D as Dispatcher, H as Handle, f as HandleStat, N as Node, m as NodeFn, n as NodeOptions, o as NodeVersion, p as NodeVersionHashFn, q as NodeVersionJson, r as NodeVersionV0, s as NodeVersionV1, t as NodeVersioningLevel, u as NodeVersioningPolicy, P as Pool, v as PoolKind, R as RewireNext, S as Sink, B as Status, T as TerminalData, W as WaveData, Z as defaultDispatcher, _ as defaultNodeVersionHash, $ as depBatch, a0 as depCount, a1 as depLatest, a2 as depTerminal, a3 as depWaves, a5 as dynamicNode, a7 as isTerminalComplete, a8 as isTerminalError, a9 as isTerminalNone, aa as node, ab as terminalErrorValue } from '../types-
|
|
2
|
-
export { L as LockId, M as Message, a as MessageType, S as SENTINEL, T as TIER_CONTROL, b as TIER_NOTIFICATION, c as TIER_SETTLE, d as TIER_START, e as TIER_TEARDOWN, f as TIER_TERMINAL, g as TIER_VALUE, W as Wave, h as errorPayload, i as isDeferredTier, j as isInvalidErrorPayload, k as isPauseBufferedTier, l as isTerminal, m as isUpAllowed, n as isValueTier, o as messageTier } from '../messages-
|
|
1
|
+
export { C as Ctx, a as CtxState, D as Dispatcher, H as Handle, f as HandleStat, N as Node, m as NodeFn, n as NodeOptions, o as NodeVersion, p as NodeVersionHashFn, q as NodeVersionJson, r as NodeVersionV0, s as NodeVersionV1, t as NodeVersioningLevel, u as NodeVersioningPolicy, P as Pool, v as PoolKind, R as RewireNext, S as Sink, B as Status, T as TerminalData, W as WaveData, Z as defaultDispatcher, _ as defaultNodeVersionHash, $ as depBatch, a0 as depCount, a1 as depLatest, a2 as depTerminal, a3 as depWaves, a5 as dynamicNode, a7 as isTerminalComplete, a8 as isTerminalError, a9 as isTerminalNone, aa as node, ab as terminalErrorValue } from '../types-BsJvElYZ.js';
|
|
2
|
+
export { L as LockId, M as Message, a as MessageType, P as PullDemand, S as SENTINEL, T as TIER_CONTROL, b as TIER_NOTIFICATION, c as TIER_SETTLE, d as TIER_START, e as TIER_TEARDOWN, f as TIER_TERMINAL, g as TIER_VALUE, W as Wave, h as errorPayload, i as isDeferredTier, j as isInvalidErrorPayload, k as isPauseBufferedTier, l as isTerminal, m as isUpAllowed, n as isValueTier, o as messageTier } from '../messages-CAzUPPJM.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Declarative batch (R-batch-coalesce / D12).
|
package/dist/core/index.js
CHANGED
|
@@ -6,8 +6,7 @@ import {
|
|
|
6
6
|
defaultNodeVersionHash,
|
|
7
7
|
dynamicNode,
|
|
8
8
|
node
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-4VLAQHZI.js";
|
|
9
|
+
} from "../chunk-XKXWK2KP.js";
|
|
11
10
|
import {
|
|
12
11
|
depBatch,
|
|
13
12
|
depCount,
|
|
@@ -18,7 +17,7 @@ import {
|
|
|
18
17
|
isTerminalError,
|
|
19
18
|
isTerminalNone,
|
|
20
19
|
terminalErrorValue
|
|
21
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-WQIA3GFB.js";
|
|
22
21
|
import {
|
|
23
22
|
SENTINEL,
|
|
24
23
|
TIER_CONTROL,
|
|
@@ -36,7 +35,9 @@ import {
|
|
|
36
35
|
isUpAllowed,
|
|
37
36
|
isValueTier,
|
|
38
37
|
messageTier
|
|
39
|
-
} from "../chunk-
|
|
38
|
+
} from "../chunk-S6HXABGL.js";
|
|
39
|
+
import "../chunk-4VLAQHZI.js";
|
|
40
|
+
import "../chunk-DGUM43GV.js";
|
|
40
41
|
export {
|
|
41
42
|
Dispatcher,
|
|
42
43
|
Node,
|
package/dist/cqrs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cqrs/index.ts","../../src/protocol/messages.ts","../../src/ctx/types.ts"],"sourcesContent":["/**\n * Reusable application-infrastructure CQRS helpers (B63 / D125 / D129).\n *\n * The bundle is graph-visible facts over ordinary nodes: command DATA facts\n * enter through a graph-owned command node, command handlers run inside the\n * dispatched runtime node, and events/status/errors/audit/cursor are derived\n * facts. It is not a Graph subclass, hidden EventEmitter, saga runtime, or\n * storage-owned restore surface.\n */\n\nimport { depBatch } from \"../ctx/types.js\";\nimport type { Graph } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\n\n/** Command fact accepted by a CQRS bundle. */\nexport interface CqrsCommand<T = unknown> {\n\treadonly id: string;\n\treadonly type: string;\n\treadonly payload: T;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\n/** Event draft returned by a command handler before the runtime orders it. */\nexport interface CqrsEventDraft<T = unknown> {\n\treadonly id?: string;\n\treadonly type: string;\n\treadonly payload: T;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\n/** Ordered event fact emitted by the CQRS runtime node. */\nexport interface CqrsEvent<T = unknown> {\n\treadonly id: string;\n\treadonly type: string;\n\treadonly seq: number;\n\treadonly cursor: number;\n\treadonly runtimeCursor: CqrsCursor;\n\treadonly commandId: string;\n\treadonly commandType: string;\n\treadonly payload: T;\n\treadonly timestampMs: number;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\nexport type CqrsErrorCode =\n\t| \"malformed-command\"\n\t| \"duplicate-command\"\n\t| \"unknown-command\"\n\t| \"handler-threw\"\n\t| \"clock-threw\"\n\t| \"malformed-event\"\n\t| \"unknown-event\"\n\t| \"duplicate-event\";\n\n/** Graph-visible CQRS error fact. These are DATA facts, not protocol ERROR. */\nexport interface CqrsError {\n\treadonly code: CqrsErrorCode;\n\treadonly message: string;\n\treadonly command?: unknown;\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly event?: unknown;\n\treadonly eventType?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsStatus {\n\treadonly state: \"accepted\" | \"rejected\";\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly eventCount: number;\n\treadonly errorCode?: CqrsErrorCode;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsAuditRecord {\n\treadonly seq: number;\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly outcome: \"success\" | \"failure\";\n\treadonly eventIds: readonly string[];\n\treadonly eventTypes: readonly string[];\n\treadonly errorCode?: CqrsErrorCode;\n\treadonly errorMessage?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsDedupeSnapshot {\n\treadonly commandIdsRetained: number;\n\treadonly eventIdsRetained: number;\n\treadonly commandIdsEvicted: number;\n\treadonly eventIdsEvicted: number;\n}\n\nexport interface CqrsCursor {\n\treadonly eventSeq: number;\n\treadonly commandCount: number;\n\treadonly errorCount: number;\n\treadonly auditSeq: number;\n\treadonly dedupe?: CqrsDedupeSnapshot;\n}\n\nexport type CqrsRuntimeFact<T = unknown> =\n\t| { readonly kind: \"event\"; readonly event: CqrsEvent<T> }\n\t| { readonly kind: \"status\"; readonly status: CqrsStatus }\n\t| { readonly kind: \"error\"; readonly error: CqrsError }\n\t| { readonly kind: \"audit\"; readonly audit: CqrsAuditRecord }\n\t| { readonly kind: \"cursor\"; readonly cursor: CqrsCursor };\n\nexport type CqrsCommandHandler<TCommand = unknown, TEvent = unknown> = (\n\tcommand: CqrsCommand<TCommand>,\n) => readonly CqrsEventDraft<TEvent>[];\n\nexport interface CqrsCommandHandlerDefinition<TCommand = unknown, TEvent = unknown> {\n\treadonly type: string;\n\treadonly handle: CqrsCommandHandler<TCommand, TEvent>;\n}\n\nexport interface CqrsOptions<TCommand = unknown, TEvent = unknown> {\n\treadonly name?: string;\n\treadonly handlers?: readonly CqrsCommandHandlerDefinition<TCommand, TEvent>[];\n\treadonly events?: readonly string[];\n\treadonly now?: () => number;\n\t/**\n\t * D142: static command/event duplicate-recognition windows. Omitted means\n\t * exact unbounded dedupe; bounded windows evict oldest ids by insertion order.\n\t */\n\treadonly dedupe?: CqrsDedupePolicy;\n}\n\n/**\n * D151 membership-based duplicate-recognition window for CQRS ids.\n *\n * This is passive CQRS vocabulary, not a shared idempotency reducer engine:\n * commands and events each own their own id membership window.\n */\nexport type CqrsDedupeWindow = \"unbounded\" | { readonly maxEntries: number };\n\nexport interface CqrsDedupePolicy {\n\treadonly commands?: CqrsDedupeWindow;\n\treadonly events?: CqrsDedupeWindow;\n}\n\nexport interface CqrsBundle<TCommand = unknown, TEvent = unknown> {\n\treadonly command: Node<CqrsCommand<TCommand>>;\n\treadonly runtime: Node<CqrsRuntimeFact<TEvent>>;\n\treadonly events: Node<CqrsEvent<TEvent>>;\n\treadonly status: Node<CqrsStatus>;\n\treadonly errors: Node<CqrsError>;\n\treadonly audit: Node<CqrsAuditRecord>;\n\treadonly cursor: Node<CqrsCursor>;\n\tdispatch(command: CqrsCommand<TCommand>): CqrsCommand<TCommand>;\n}\n\ninterface CqrsRuntimeState {\n\teventSeq: number;\n\tcommandCount: number;\n\terrorCount: number;\n\tauditSeq: number;\n\tseenCommandIds: string[];\n\tseenEventIds: string[];\n\tcommandDedupeEvicted?: number;\n\teventDedupeEvicted?: number;\n}\n\ninterface HandlerRecord {\n\treadonly type: string;\n\treadonly handle: CqrsCommandHandler<unknown, unknown>;\n}\n\ninterface NormalizedCqrsDedupePolicy {\n\treadonly commandMaxEntries?: number;\n\treadonly eventMaxEntries?: number;\n\treadonly bounded: boolean;\n}\n\n/** Convenience helper for declaring typed command handlers in a CQRS bundle. */\nexport function cqrsCommandHandler<TCommand = unknown, TEvent = unknown>(\n\ttype: string,\n\thandle: CqrsCommandHandler<TCommand, TEvent>,\n): CqrsCommandHandlerDefinition<TCommand, TEvent> {\n\tif (type.length === 0) throw new Error(\"cqrsCommandHandler: type must be non-empty\");\n\treturn { type, handle };\n}\n\n/**\n * Create a graph-visible CQRS bundle. Command dispatch is only DATA on the\n * returned `command` node; all derived facts flow through declared graph deps.\n */\nexport function cqrs<TCommand = unknown, TEvent = unknown>(\n\tgraph: Graph,\n\topts: CqrsOptions<TCommand, TEvent> = {},\n): CqrsBundle<TCommand, TEvent> {\n\tconst name = opts.name ?? \"cqrs\";\n\tconst handlers = normalizeHandlers(opts.handlers ?? []);\n\tconst knownEvents =\n\t\topts.events === undefined ? undefined : new Set(uniqueNames(opts.events, \"cqrs.events\"));\n\tconst now = opts.now ?? Date.now;\n\tconst dedupe = normalizeDedupePolicy(opts.dedupe);\n\tconst command = graph.node<CqrsCommand<TCommand>>([], null, {\n\t\tname: `${name}/command`,\n\t\tfactory: \"cqrsCommand\",\n\t\tcompleteWhenDepsComplete: false,\n\t\terrorWhenDepsError: false,\n\t});\n\tconst runtime = graph.node<CqrsRuntimeFact<TEvent>>(\n\t\t[command],\n\t\t(ctx) => {\n\t\t\tconst state =\n\t\t\t\tctx.state.get<CqrsRuntimeState>() ??\n\t\t\t\t({\n\t\t\t\t\teventSeq: 0,\n\t\t\t\t\tcommandCount: 0,\n\t\t\t\t\terrorCount: 0,\n\t\t\t\t\tauditSeq: 0,\n\t\t\t\t\tseenCommandIds: [],\n\t\t\t\t\tseenEventIds: [],\n\t\t\t\t} satisfies CqrsRuntimeState);\n\t\t\tctx.state.persist(true);\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\treduceCommandFact(raw, state, handlers, knownEvents, now, dedupe, (fact) =>\n\t\t\t\t\tctx.down([[\"DATA\", fact as CqrsRuntimeFact<TEvent>]]),\n\t\t\t\t);\n\t\t\t}\n\t\t\tctx.state.set(state);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/runtime`,\n\t\t\tfactory: \"cqrsRuntime\",\n\t\t\tmeta: {\n\t\t\t\tcommandTypes: [...handlers.keys()],\n\t\t\t\teventTypes: knownEvents ? [...knownEvents] : \"open\",\n\t\t\t\tdedupe: dedupeMeta(dedupe),\n\t\t\t},\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst events = runtimeProjection<CqrsEvent<TEvent>, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"event\",\n\t\t`${name}/events`,\n\t\t\"cqrsEvents\",\n\t\t(fact) => (fact.kind === \"event\" ? fact.event : undefined),\n\t);\n\tconst status = runtimeProjection<CqrsStatus, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"status\",\n\t\t`${name}/status`,\n\t\t\"cqrsStatus\",\n\t\t(fact) => (fact.kind === \"status\" ? fact.status : undefined),\n\t);\n\tconst errors = runtimeProjection<CqrsError, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"error\",\n\t\t`${name}/errors`,\n\t\t\"cqrsErrors\",\n\t\t(fact) => (fact.kind === \"error\" ? fact.error : undefined),\n\t);\n\tconst audit = runtimeProjection<CqrsAuditRecord, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"audit\",\n\t\t`${name}/audit`,\n\t\t\"cqrsAudit\",\n\t\t(fact) => (fact.kind === \"audit\" ? fact.audit : undefined),\n\t);\n\tconst cursor = runtimeProjection<CqrsCursor, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"cursor\",\n\t\t`${name}/cursor`,\n\t\t\"cqrsCursor\",\n\t\t(fact) => (fact.kind === \"cursor\" ? fact.cursor : undefined),\n\t);\n\tgraph.retain(runtime, { reason: `${name}.cqrs.runtime` });\n\tgraph.retain(events, { reason: `${name}.cqrs.events` });\n\tgraph.retain(status, { reason: `${name}.cqrs.status` });\n\tgraph.retain(errors, { reason: `${name}.cqrs.errors` });\n\tgraph.retain(audit, { reason: `${name}.cqrs.audit` });\n\tgraph.retain(cursor, { reason: `${name}.cqrs.cursor` });\n\treturn {\n\t\tcommand,\n\t\truntime,\n\t\tevents,\n\t\tstatus,\n\t\terrors,\n\t\taudit,\n\t\tcursor,\n\t\tdispatch(commandFact) {\n\t\t\tcommand.down([[\"DATA\", commandFact]]);\n\t\t\treturn commandFact;\n\t\t},\n\t};\n}\n\nexport interface CqrsProjectionOptions<TState, TEvent = unknown> {\n\treadonly name?: string;\n\treadonly events?: readonly string[];\n\treadonly initial: TState;\n\treadonly reducer: (state: TState, event: CqrsEvent<TEvent>) => TState;\n}\n\nexport type CqrsProjectionFrame<TState> =\n\t| {\n\t\t\treadonly kind: \"value\";\n\t\t\treadonly state: TState;\n\t\t\treadonly eventId: string;\n\t\t\treadonly cursor: CqrsCursor;\n\t }\n\t| { readonly kind: \"error\"; readonly error: CqrsProjectionError };\n\nexport interface CqrsProjectionError {\n\treadonly code: \"projection-threw\";\n\treadonly message: string;\n\treadonly eventId: string;\n\treadonly eventType: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsProjectionStatus {\n\treadonly state: \"updated\" | \"errored\";\n\treadonly eventId: string;\n\treadonly eventType?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsProjection<TState> {\n\treadonly frames: Node<CqrsProjectionFrame<TState>>;\n\treadonly value: Node<TState>;\n\treadonly status: Node<CqrsProjectionStatus>;\n\treadonly errors: Node<CqrsProjectionError>;\n}\n\n/**\n * Derive a projection from declared CQRS event deps. Reducer failures become\n * graph-visible error DATA facts on the returned `errors` node.\n */\nexport function cqrsProjection<TState, TEvent = unknown>(\n\tgraph: Graph,\n\tsource: Pick<CqrsBundle<unknown, TEvent>, \"events\">,\n\topts: CqrsProjectionOptions<TState, TEvent>,\n): CqrsProjection<TState> {\n\tconst name = opts.name ?? \"cqrsProjection\";\n\tconst eventFilter =\n\t\topts.events === undefined\n\t\t\t? undefined\n\t\t\t: new Set(uniqueNames(opts.events, \"cqrsProjection.events\"));\n\tconst frames = graph.node<CqrsProjectionFrame<TState>>(\n\t\t[source.events],\n\t\t(ctx) => {\n\t\t\tconst state = ctx.state.get<{ value: TState }>() ?? { value: opts.initial };\n\t\t\tctx.state.persist(true);\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst event = raw as CqrsEvent<TEvent>;\n\t\t\t\tif (eventFilter !== undefined && !eventFilter.has(event.type)) continue;\n\t\t\t\ttry {\n\t\t\t\t\tstate.value = opts.reducer(state.value, event);\n\t\t\t\t\tctx.state.set(state);\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"value\",\n\t\t\t\t\t\t\t\tstate: state.value,\n\t\t\t\t\t\t\t\teventId: event.id,\n\t\t\t\t\t\t\t\tcursor: event.runtimeCursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionFrame<TState>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t} catch (error) {\n\t\t\t\t\trethrowGraphRuntimeInvariant(error);\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"error\",\n\t\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\t\tcode: \"projection-threw\",\n\t\t\t\t\t\t\t\t\tmessage: errorMessage(error),\n\t\t\t\t\t\t\t\t\teventId: event.id,\n\t\t\t\t\t\t\t\t\teventType: event.type,\n\t\t\t\t\t\t\t\t\tcursor: event.runtimeCursor,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t} satisfies CqrsProjectionFrame<TState>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory: \"cqrsProjection\",\n\t\t\tmeta: { eventTypes: eventFilter ? [...eventFilter] : \"open\" },\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst value = graph.node<TState>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"value\") ctx.down([[\"DATA\", typed.state]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/value`,\n\t\t\tfactory: \"cqrsProjectionValue\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst errors = graph.node<CqrsProjectionError>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"error\") ctx.down([[\"DATA\", typed.error]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/errors`,\n\t\t\tfactory: \"cqrsProjectionErrors\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst status = graph.node<CqrsProjectionStatus>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"value\") {\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tstate: \"updated\",\n\t\t\t\t\t\t\t\teventId: typed.eventId,\n\t\t\t\t\t\t\t\tcursor: typed.cursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionStatus,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t} else {\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tstate: \"errored\",\n\t\t\t\t\t\t\t\teventId: typed.error.eventId,\n\t\t\t\t\t\t\t\teventType: typed.error.eventType,\n\t\t\t\t\t\t\t\tcursor: typed.error.cursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionStatus,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/status`,\n\t\t\tfactory: \"cqrsProjectionStatus\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tgraph.retain(frames, { reason: `${name}.cqrsProjection.frames` });\n\tgraph.retain(value, { reason: `${name}.cqrsProjection.value` });\n\tgraph.retain(status, { reason: `${name}.cqrsProjection.status` });\n\tgraph.retain(errors, { reason: `${name}.cqrsProjection.errors` });\n\treturn { frames, value, status, errors };\n}\n\nfunction normalizeHandlers<TCommand, TEvent>(\n\tdefinitions: readonly CqrsCommandHandlerDefinition<TCommand, TEvent>[],\n): ReadonlyMap<string, HandlerRecord> {\n\tconst handlers = new Map<string, HandlerRecord>();\n\tfor (const definition of definitions) {\n\t\tif (definition.type.length === 0) throw new Error(\"cqrs: handler type must be non-empty\");\n\t\tif (handlers.has(definition.type))\n\t\t\tthrow new Error(`cqrs: duplicate handler '${definition.type}'`);\n\t\thandlers.set(definition.type, {\n\t\t\ttype: definition.type,\n\t\t\thandle: definition.handle as CqrsCommandHandler<unknown, unknown>,\n\t\t});\n\t}\n\treturn handlers;\n}\n\nfunction reduceCommandFact<TEvent>(\n\traw: unknown,\n\tstate: CqrsRuntimeState,\n\thandlers: ReadonlyMap<string, HandlerRecord>,\n\tknownEvents: ReadonlySet<string> | undefined,\n\tnow: () => number,\n\tdedupe: NormalizedCqrsDedupePolicy,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n): void {\n\tstate.commandCount += 1;\n\tconst parsed = parseCommand(raw);\n\tif (typeof parsed === \"string\") {\n\t\temitFailure(state, emit, raw, undefined, \"malformed-command\", parsed, dedupe);\n\t\treturn;\n\t}\n\tconst command = parsed as CqrsCommand<unknown>;\n\tif (state.seenCommandIds.includes(command.id)) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"duplicate-command\",\n\t\t\t`cqrs: duplicate command '${command.id}'`,\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tstate.seenCommandIds.push(command.id);\n\ttrimDedupeWindow(state.seenCommandIds, dedupe.commandMaxEntries, (evicted) => {\n\t\tstate.commandDedupeEvicted = (state.commandDedupeEvicted ?? 0) + evicted;\n\t});\n\tconst handler = handlers.get(command.type);\n\tif (handler === undefined) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"unknown-command\",\n\t\t\t`cqrs: unknown command '${command.type}'`,\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tlet drafts: readonly CqrsEventDraft<unknown>[];\n\ttry {\n\t\tdrafts = handler.handle(command);\n\t} catch (error) {\n\t\trethrowGraphRuntimeInvariant(error);\n\t\temitFailure(state, emit, command, command, \"handler-threw\", errorMessage(error), dedupe);\n\t\treturn;\n\t}\n\tif (!Array.isArray(drafts)) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"malformed-event\",\n\t\t\t\"cqrs: command handler must return an event draft array\",\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tconst prepared = prepareEvents(command, drafts, state, knownEvents);\n\tif (typeof prepared === \"string\") {\n\t\temitFailure(state, emit, command, command, preparedCode(prepared), prepared, dedupe);\n\t\treturn;\n\t}\n\tconst timestampMs = readTimestampMs(now);\n\tif (typeof timestampMs === \"string\") {\n\t\temitFailure(state, emit, command, command, \"clock-threw\", timestampMs, dedupe);\n\t\treturn;\n\t}\n\tconst events: CqrsEvent<unknown>[] = [];\n\tfor (const draft of prepared) {\n\t\tstate.eventSeq += 1;\n\t\tstate.seenEventIds.push(draft.id);\n\t\ttrimDedupeWindow(state.seenEventIds, dedupe.eventMaxEntries, (evicted) => {\n\t\t\tstate.eventDedupeEvicted = (state.eventDedupeEvicted ?? 0) + evicted;\n\t\t});\n\t\tconst runtimeCursor = cursorOf(state, dedupe);\n\t\tevents.push({\n\t\t\tid: draft.id,\n\t\t\ttype: draft.type,\n\t\t\tseq: state.eventSeq,\n\t\t\tcursor: state.eventSeq,\n\t\t\truntimeCursor,\n\t\t\tcommandId: command.id,\n\t\t\tcommandType: command.type,\n\t\t\tpayload: draft.payload,\n\t\t\ttimestampMs,\n\t\t\t...(draft.aggregateId === undefined ? {} : { aggregateId: draft.aggregateId }),\n\t\t\t...(draft.correlationId === undefined ? {} : { correlationId: draft.correlationId }),\n\t\t\t...(draft.causationId === undefined ? {} : { causationId: draft.causationId }),\n\t\t\t...(draft.metadata === undefined ? {} : { metadata: draft.metadata }),\n\t\t});\n\t}\n\tfor (const event of events) emit({ kind: \"event\", event: event as CqrsEvent<TEvent> });\n\temitStatus(state, emit, command, \"accepted\", events.length, dedupe);\n\temitAudit(state, emit, command, \"success\", events, undefined, undefined, dedupe);\n\temit({ kind: \"cursor\", cursor: cursorOf(state, dedupe) });\n}\n\nfunction parseCommand(value: unknown): CqrsCommand<unknown> | string {\n\tif (!isObjectRecord(value)) return \"cqrs: command fact must be an object\";\n\tif (typeof value.id !== \"string\" || value.id.length === 0) {\n\t\treturn \"cqrs: command id must be a non-empty string\";\n\t}\n\tif (typeof value.type !== \"string\" || value.type.length === 0) {\n\t\treturn \"cqrs: command type must be a non-empty string\";\n\t}\n\treturn {\n\t\tid: value.id,\n\t\ttype: value.type,\n\t\tpayload: value.payload,\n\t\t...(typeof value.aggregateId === \"string\" ? { aggregateId: value.aggregateId } : {}),\n\t\t...(typeof value.correlationId === \"string\" ? { correlationId: value.correlationId } : {}),\n\t\t...(typeof value.causationId === \"string\" ? { causationId: value.causationId } : {}),\n\t\t...(isObjectRecord(value.metadata) ? { metadata: value.metadata } : {}),\n\t};\n}\n\nfunction prepareEvents(\n\tcommand: CqrsCommand<unknown>,\n\tdrafts: readonly CqrsEventDraft<unknown>[],\n\tstate: CqrsRuntimeState,\n\tknownEvents: ReadonlySet<string> | undefined,\n): Array<CqrsEventDraft<unknown> & { readonly id: string }> | string {\n\tconst seenInCommand = new Set<string>();\n\tconst prepared: Array<CqrsEventDraft<unknown> & { readonly id: string }> = [];\n\tfor (let i = 0; i < drafts.length; i += 1) {\n\t\tconst draft = drafts[i];\n\t\tif (!isObjectRecord(draft) || typeof draft.type !== \"string\" || draft.type.length === 0) {\n\t\t\treturn \"cqrs: event draft must have a non-empty type\";\n\t\t}\n\t\tif (knownEvents !== undefined && !knownEvents.has(draft.type)) {\n\t\t\treturn `cqrs: unknown event '${draft.type}'`;\n\t\t}\n\t\tconst id =\n\t\t\ttypeof draft.id === \"string\" && draft.id.length > 0 ? draft.id : `${command.id}:${i + 1}`;\n\t\tif (state.seenEventIds.includes(id) || seenInCommand.has(id)) {\n\t\t\treturn `cqrs: duplicate event '${id}'`;\n\t\t}\n\t\tseenInCommand.add(id);\n\t\tprepared.push({\n\t\t\tid,\n\t\t\ttype: draft.type,\n\t\t\tpayload: draft.payload,\n\t\t\t...(typeof draft.aggregateId === \"string\" ? { aggregateId: draft.aggregateId } : {}),\n\t\t\t...(typeof draft.correlationId === \"string\" ? { correlationId: draft.correlationId } : {}),\n\t\t\t...(typeof draft.causationId === \"string\" ? { causationId: draft.causationId } : {}),\n\t\t\t...(isObjectRecord(draft.metadata) ? { metadata: draft.metadata } : {}),\n\t\t});\n\t}\n\treturn prepared;\n}\n\nfunction preparedCode(message: string): CqrsErrorCode {\n\tif (message.includes(\"unknown event\")) return \"unknown-event\";\n\tif (message.includes(\"duplicate event\")) return \"duplicate-event\";\n\treturn \"malformed-event\";\n}\n\nfunction rethrowGraphRuntimeInvariant(error: unknown): void {\n\tconst message = errorMessage(error);\n\tif (\n\t\tmessage.includes(\"R-reentrancy\") ||\n\t\tmessage.includes(\"R-rewire\") ||\n\t\tmessage.includes(\"R-graph-domain\") ||\n\t\tmessage.includes(\"D37\") ||\n\t\tmessage.includes(\"D22\") ||\n\t\tmessage.includes(\"different graph\") ||\n\t\tmessage.includes(\"cross-graph\") ||\n\t\tmessage.includes(\"wire bridge\") ||\n\t\tmessage.includes(\"mid-fn topology mutation\") ||\n\t\tmessage.includes(\"reentrant dep mutation\") ||\n\t\tmessage.includes(\"feedback cycle\")\n\t) {\n\t\tthrow error;\n\t}\n}\n\nfunction emitFailure<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\traw: unknown,\n\tcommand: CqrsCommand<unknown> | undefined,\n\tcode: CqrsErrorCode,\n\tmessage: string,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\tstate.errorCount += 1;\n\tconst cursor = cursorOf(state, dedupe);\n\tconst error: CqrsError = {\n\t\tcode,\n\t\tmessage,\n\t\tcommand: raw,\n\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\tcursor,\n\t};\n\temit({ kind: \"error\", error });\n\temit({\n\t\tkind: \"status\",\n\t\tstatus: {\n\t\t\tstate: \"rejected\",\n\t\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\t\teventCount: 0,\n\t\t\terrorCode: code,\n\t\t\tcursor,\n\t\t},\n\t});\n\temitAudit(state, emit, command, \"failure\", [], code, message, dedupe);\n\temit({ kind: \"cursor\", cursor: cursorOf(state, dedupe) });\n}\n\nfunction emitStatus<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\tcommand: CqrsCommand<unknown>,\n\tstatusState: \"accepted\" | \"rejected\",\n\teventCount: number,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\temit({\n\t\tkind: \"status\",\n\t\tstatus: {\n\t\t\tstate: statusState,\n\t\t\tcommandId: command.id,\n\t\t\tcommandType: command.type,\n\t\t\teventCount,\n\t\t\tcursor: cursorOf(state, dedupe),\n\t\t},\n\t});\n}\n\nfunction emitAudit<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\tcommand: CqrsCommand<unknown> | undefined,\n\toutcome: \"success\" | \"failure\",\n\tevents: readonly CqrsEvent<unknown>[],\n\terrorCode: CqrsErrorCode | undefined,\n\terrorMessageValue: string | undefined,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\tstate.auditSeq += 1;\n\temit({\n\t\tkind: \"audit\",\n\t\taudit: {\n\t\t\tseq: state.auditSeq,\n\t\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\t\toutcome,\n\t\t\teventIds: Object.freeze(events.map((event) => event.id)),\n\t\t\teventTypes: Object.freeze(events.map((event) => event.type)),\n\t\t\t...(errorCode === undefined ? {} : { errorCode }),\n\t\t\t...(errorMessageValue === undefined ? {} : { errorMessage: errorMessageValue }),\n\t\t\tcursor: cursorOf(state, dedupe),\n\t\t},\n\t});\n}\n\nfunction runtimeProjection<TOut, TEvent>(\n\tgraph: Graph,\n\truntime: Node<CqrsRuntimeFact<TEvent>>,\n\tkind: CqrsRuntimeFact<TEvent>[\"kind\"],\n\tname: string,\n\tfactory: string,\n\tselect: (fact: CqrsRuntimeFact<TEvent>) => TOut | undefined,\n): Node<TOut> {\n\treturn graph.node<TOut>(\n\t\t[runtime],\n\t\t(ctx) => {\n\t\t\tfor (const fact of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = fact as CqrsRuntimeFact<TEvent>;\n\t\t\t\tif (typed.kind !== kind) continue;\n\t\t\t\tconst selected = select(typed);\n\t\t\t\tif (selected !== undefined) ctx.down([[\"DATA\", selected]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n}\n\nfunction cursorOf(state: CqrsRuntimeState, dedupe: NormalizedCqrsDedupePolicy): CqrsCursor {\n\treturn {\n\t\teventSeq: state.eventSeq,\n\t\tcommandCount: state.commandCount,\n\t\terrorCount: state.errorCount,\n\t\tauditSeq: state.auditSeq,\n\t\t...(dedupe.bounded\n\t\t\t? {\n\t\t\t\t\tdedupe: {\n\t\t\t\t\t\tcommandIdsRetained: state.seenCommandIds.length,\n\t\t\t\t\t\teventIdsRetained: state.seenEventIds.length,\n\t\t\t\t\t\tcommandIdsEvicted: state.commandDedupeEvicted ?? 0,\n\t\t\t\t\t\teventIdsEvicted: state.eventDedupeEvicted ?? 0,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n\nfunction normalizeDedupePolicy(policy: CqrsDedupePolicy | undefined): NormalizedCqrsDedupePolicy {\n\tconst commandMaxEntries = normalizeDedupeWindow(policy?.commands, \"cqrs.dedupe.commands\");\n\tconst eventMaxEntries = normalizeDedupeWindow(policy?.events, \"cqrs.dedupe.events\");\n\treturn {\n\t\t...(commandMaxEntries === undefined ? {} : { commandMaxEntries }),\n\t\t...(eventMaxEntries === undefined ? {} : { eventMaxEntries }),\n\t\tbounded: commandMaxEntries !== undefined || eventMaxEntries !== undefined,\n\t};\n}\n\nfunction normalizeDedupeWindow(\n\twindow: CqrsDedupeWindow | undefined,\n\towner: string,\n): number | undefined {\n\tif (window === undefined || window === \"unbounded\") return undefined;\n\tif (!Number.isInteger(window.maxEntries) || window.maxEntries < 0) {\n\t\tthrow new RangeError(`${owner}: maxEntries must be a non-negative integer`);\n\t}\n\treturn window.maxEntries;\n}\n\nfunction dedupeMeta(dedupe: NormalizedCqrsDedupePolicy): unknown {\n\tif (!dedupe.bounded) return \"unbounded\";\n\treturn {\n\t\tcommands:\n\t\t\tdedupe.commandMaxEntries === undefined\n\t\t\t\t? \"unbounded\"\n\t\t\t\t: { maxEntries: dedupe.commandMaxEntries },\n\t\tevents:\n\t\t\tdedupe.eventMaxEntries === undefined ? \"unbounded\" : { maxEntries: dedupe.eventMaxEntries },\n\t};\n}\n\nfunction trimDedupeWindow(\n\tids: string[],\n\tmaxEntries: number | undefined,\n\tonEvicted: (evicted: number) => void,\n): void {\n\tif (maxEntries === undefined || ids.length <= maxEntries) return;\n\tconst evicted = ids.length - maxEntries;\n\tids.splice(0, evicted);\n\tonEvicted(evicted);\n}\n\nfunction readTimestampMs(now: () => number): number | string {\n\ttry {\n\t\tconst timestampMs = now();\n\t\treturn Number.isFinite(timestampMs) ? timestampMs : \"cqrs: now() must return a finite number\";\n\t} catch (error) {\n\t\treturn `cqrs: now() threw: ${errorMessage(error)}`;\n\t}\n}\n\nfunction uniqueNames(values: readonly string[], owner: string): readonly string[] {\n\tconst unique = [...new Set(values)];\n\tif (unique.length !== values.length) throw new Error(`${owner}: duplicate value`);\n\tfor (const value of unique) {\n\t\tif (value.length === 0) throw new Error(`${owner}: values must be non-empty`);\n\t}\n\treturn Object.freeze(unique);\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction isObjectRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n","/**\n * Wave-protocol message types and the tier const table.\n *\n * Canonical authority: ~/src/graphrefly/spec/rules.jsonl\n * R-msg-format, R-msg-closed-set, R-tier (D34), R-data-payload, R-sentinel.\n */\n\n/** Opaque pause-lock identifier (R-pause-lockset). */\nexport type LockId = string | symbol;\n\n/**\n * The CLOSED set of 10 message types (R-msg-closed-set / D9 + START handshake).\n * No open set, no user-defined custom types. Adding a type is a spec change.\n */\nexport type Message =\n\t| readonly [\"START\"]\n\t| readonly [\"DIRTY\"]\n\t| readonly [\"DATA\", unknown]\n\t| readonly [\"RESOLVED\"]\n\t| readonly [\"INVALIDATE\"]\n\t| readonly [\"COMPLETE\"]\n\t| readonly [\"ERROR\", unknown]\n\t| readonly [\"TEARDOWN\"]\n\t| readonly [\"PAUSE\", LockId]\n\t| readonly [\"RESUME\", LockId];\n\n/** One array of messages delivered in one call = one Wave (R-wave-boundary). */\nexport type Wave = readonly Message[];\n\n/** The message-type tag (the first tuple element). */\nexport type MessageType = Message[0];\n\n/**\n * SENTINEL = absence-of-DATA (R-sentinel / D16). TS representation is `undefined`.\n * Never a valid DATA payload; `null` IS a valid DATA value (domain-level absence).\n */\nexport const SENTINEL = undefined;\n\n/** R-data-payload: ERROR payloads must not collide with terminal metadata shorthand. */\nexport function isInvalidErrorPayload(v: unknown): boolean {\n\treturn v === SENTINEL || typeof v === \"boolean\";\n}\n\n/** R-data-payload / D78: host-language failures that collide with ctx.terminal shorthand become diagnostics. */\nexport function errorPayload(reason: unknown, fallback = \"error without a valid payload\"): unknown {\n\treturn isInvalidErrorPayload(reason) ? new Error(fallback) : reason;\n}\n\nexport const TIER_START = 0;\nexport const TIER_CONTROL = 1;\nexport const TIER_NOTIFICATION = 2;\nexport const TIER_VALUE = 3;\nexport const TIER_SETTLE = 4;\nexport const TIER_TERMINAL = 5;\nexport const TIER_TEARDOWN = 6;\n\n/**\n * Tier const table (R-tier / D34). Tiers below value dispatch immediately; value\n * and above are batch-deferred. This is a compile-time const table (D18), not runtime config.\n */\nconst TIER: Record<MessageType, number> = {\n\tSTART: TIER_START,\n\tPAUSE: TIER_CONTROL,\n\tRESUME: TIER_CONTROL,\n\tDIRTY: TIER_NOTIFICATION,\n\tDATA: TIER_VALUE,\n\tRESOLVED: TIER_VALUE,\n\tINVALIDATE: TIER_SETTLE,\n\tCOMPLETE: TIER_TERMINAL,\n\tERROR: TIER_TERMINAL,\n\tTEARDOWN: TIER_TEARDOWN,\n};\n\nexport function messageTier(t: MessageType): number {\n\treturn TIER[t];\n}\n\n/** Value and above are deferred inside a batch (DATA/RESOLVED/INVALIDATE/terminal/teardown). */\nexport function isDeferredTier(t: MessageType): boolean {\n\treturn TIER[t] >= TIER_VALUE;\n}\n\n/** Value-tier messages (DATA/RESOLVED) occupy the tier-3 slot. */\nexport function isValueTier(t: MessageType): boolean {\n\treturn TIER[t] === TIER_VALUE;\n}\n\n/** The pause buffer holds the settle slice only: value-tier DATA/RESOLVED plus INVALIDATE. */\nexport function isPauseBufferedTier(t: MessageType): boolean {\n\tconst tier = TIER[t];\n\treturn tier === TIER_VALUE || tier === TIER_SETTLE;\n}\n\n/**\n * A TERMINAL message = tier 5 (COMPLETE | ERROR), R-tier / D34. Detected via the CENTRAL tier\n * table, NOT a per-variant `=== \"COMPLETE\" || === \"ERROR\"` check — so terminal routing stays\n * driven by the one const table (feedback_use_tier_for_signal_routing); discriminate COMPLETE vs\n * ERROR within the tier by the message type only where the handling actually differs.\n */\nexport function isTerminal(t: MessageType): boolean {\n\treturn TIER[t] === TIER_TERMINAL;\n}\n\n/**\n * ctx.up carries control tiers only (R-ctx-up / DR-5): DIRTY, PAUSE, RESUME,\n * INVALIDATE, TEARDOWN. DATA/RESOLVED (tier 3) and COMPLETE/ERROR (tier 5) are\n * down-only.\n */\nexport function isUpAllowed(t: MessageType): boolean {\n\tconst tier = TIER[t];\n\treturn tier !== TIER_VALUE && tier !== TIER_TERMINAL;\n}\n","/**\n * The fn-invocation context and per-dep input shapes.\n *\n * Canonical authority: ~/src/graphrefly/spec/rules.jsonl\n * R-fn-contract (D8/D27), R-ctx-state (D23/D29), R-cleanup-hooks (D28), R-ctx-up.\n */\n\nimport type { Dispatcher } from \"../dispatcher/index.js\";\nimport type { EnvironmentDrivers } from \"../graph/environment.js\";\nimport type { Node } from \"../node/node.js\";\nimport { type Message, SENTINEL, type Wave } from \"../protocol/messages.js\";\n\n/** A downstream sink callback (the only way to connect to a node's output). */\nexport type Sink = (msg: Message, delivery?: DeliveryMeta) => void;\n\n/** Internal delivery metadata used to preserve the upstream `ctx.down(msgs)` wave boundary. */\nexport interface DeliveryMeta {\n\treadonly wave: object;\n\treadonly last: boolean;\n}\n\n/**\n * Internal current-value reader. It is deliberately a symbol-backed implementation detail:\n * raw ctx exposes `waveData` + `terminal`; helpers below derive from that plus this dep cache.\n */\nexport const CTX_DEP_CACHE: unique symbol = Symbol(\"graphrefly.ctx.depCache\");\n\nexport interface CtxDepCache {\n\treadonly latest: readonly unknown[];\n}\n\n/** Internal node-construction binding for graph-local helper-created deps. */\nexport const CTX_NODE_BINDING: unique symbol = Symbol(\"graphrefly.ctx.nodeBinding\");\n\nexport interface CtxNodeBinding {\n\treadonly dispatcher: Dispatcher;\n\tcreate<T>(factory: () => Node<T>): Node<T>;\n}\n\n/** Per-dep wave projections: dep -> waves -> values/SENTINEL markers. */\nexport type WaveData = readonly (readonly (readonly unknown[])[])[];\n\n/** Terminal metadata parallel to `waveData`: false = none, true = COMPLETE, otherwise ERROR payload. */\nexport type TerminalData = readonly unknown[];\n\nexport function isTerminalNone(t: unknown): boolean {\n\treturn t === false || t === undefined;\n}\n\nexport function isTerminalComplete(t: unknown): t is true {\n\treturn t === true;\n}\n\nexport function isTerminalError(t: unknown): boolean {\n\treturn !isTerminalNone(t) && !isTerminalComplete(t);\n}\n\nexport function terminalErrorValue(t: unknown): unknown {\n\treturn isTerminalError(t) ? t : undefined;\n}\n\n/**\n * Per-node private cross-wave state (R-ctx-state / D23,D29). Default fresh-lifecycle\n * wipe; `persist(true)` keeps it across lifecycle transitions.\n */\nexport interface CtxState {\n\tget<S = unknown>(): S | undefined;\n\tset<S = unknown>(v: S): void;\n\tpersist(on?: boolean): void;\n}\n\n/**\n * Deferred SELF-rewire (R-rewire-deferred / D47). A node fn may, DURING its run, request a\n * mutation of its OWN dep set; the request is QUEUED and applied at the committed wave boundary\n * (after the current wave settles / batch commit / final-lock RESUME) as a fresh wave, reusing\n * R-rewire surgical/Option-C semantics (D42). This is the ONLY legal self-triggered rewire — an\n * IMMEDIATE in-fn `node.subscribeDep/unsubscribeDep/replaceDeps` is the D37 mid-fn feedback-cycle ERROR. An\n * added cached dep pushes `[DIRTY,DATA]` on the boundary wave (R-push-subscribe); a removed dep\n * is drained and, if it loses its last subscriber, `_deactivate`s + fires `onDeactivation`\n * (input-side teardown — the basis for higher-order operator cancellation / abortInFlight).\n */\nexport interface RewireNext {\n\t/** Defer subscribing to a dep (paired with the re-supplied fn — positional fn-deps lock, SD-1). */\n\tsubscribeDep(dep: Node<unknown>, fn: NodeFn): void;\n\t/** Defer unsubscribing from a dep (its source is torn down if it loses its last subscriber). */\n\tunsubscribeDep(dep: Node<unknown>, fn: NodeFn): void;\n\t/** Defer replacing the whole dep set (surgical: kept deps untouched, removed drained, added fresh-subscribe). */\n\treplaceDeps(deps: Node<unknown>[], fn: NodeFn): void;\n}\n\n/**\n * The single argument to a node fn: `(ctx) => void` (R-fn-contract / D8). All emission\n * is explicit via `ctx.down`; there is no return-value framing.\n */\nexport interface Ctx {\n\t/**\n\t * Emit upstream toward deps — control tiers only (R-ctx-up). IMMEDIATE. `towardDep` (a dep index)\n\t * routes the wave up ONE declared edge (R-up-routing directed-up); omitted = broadcast up all deps.\n\t * A pull DEMAND is `up([[RESUME, pullId]])` — but for a SELF-demand (demanding a dep this fn also\n\t * reads) use {@link Ctx.upNext} instead, since an immediate demand whose delivery loops back\n\t * re-enters this fn mid-wave (D37 / R-reentrancy).\n\t */\n\tup(msgs: Wave, towardDep?: number): void;\n\t/** Emit downstream toward sinks. */\n\tdown(msgs: Wave): void;\n\t/**\n\t * The single raw dep-value input surface (R-ctx-wave-data / D77): dep -> upstream waves ->\n\t * per-wave DATA payloads and INVALIDATE/SENTINEL markers. `waveData[i] = []` means dep i\n\t * delivered no wave to this invocation; `waveData[i] = [[]]` means RESOLVED-only.\n\t */\n\twaveData: WaveData;\n\t/** Terminal metadata for the same invocation; terminal values never enter `waveData`. */\n\tterminal: TerminalData;\n\tstate: CtxState;\n\t/** Release external resources on deactivation (R-cleanup-hooks). */\n\tonDeactivation(fn: () => void): void;\n\t/** Flush on INVALIDATE (R-cleanup-hooks). */\n\tonInvalidate(fn: () => void): void;\n\t/** Graph-owned environment drivers for source/adapter boundaries (D130/D131). */\n\tenvironment(): EnvironmentDrivers;\n\t/**\n\t * Deferred SELF-rewire (R-rewire-deferred / D47) — the substrate affordance higher-order\n\t * operators (switchMap/mergeMap/concatMap/exhaustMap/flatMap) use to grow/shrink their own\n\t * inner-source dep set in response to their own data. Always present; see {@link RewireNext}.\n\t */\n\trewireNext: RewireNext;\n\t/**\n\t * Deferred up — the boundary-deferred form of {@link Ctx.up} (R-up-routing / R-pull / D59). Routes\n\t * `msgs` up from this node at the COMMITTED wave boundary (broadcast, or up the single `towardDep`\n\t * edge), riding the same R-rewire-deferred (D47) drain as {@link RewireNext}. This is the\n\t * SELF-DEMAND path: a consumer issues `ctx.upNext([[RESUME, pullId]])` to demand a pull dep it\n\t * ALSO reads — the cone-routed RESUME reaches the pullId-holder, whose delivery loops back as a\n\t * FRESH wave (not a mid-fn re-entry → no D37). The consumer accepts one-wave latency (the\n\t * HTTP-request model). No node reference needed: the author writes the pullId verbatim.\n\t */\n\tupNext(msgs: Wave, towardDep?: number): void;\n\t/**\n\t * Read a dep's latest value by index (dynamicNode only, R-dynamic-node / D35).\n\t * Present only on dynamicNode fns; all declared deps still participate in wave\n\t * tracking. Under D49/R-resolved-undirty an unread dep's change still fires the fn,\n\t * which re-emits its (unchanged) output as a DATA occurrence — there is NO equals-\n\t * absorption; pair with distinctUntilChanged to suppress unchanged re-emits (opt-in).\n\t */\n\ttrack?(depIndex: number): unknown;\n\t[CTX_DEP_CACHE]?: CtxDepCache;\n\t[CTX_NODE_BINDING]?: CtxNodeBinding;\n}\n\n/** A node fn (R-fn-contract). Registered in a dispatcher pool, indexed by Handle. */\nexport type NodeFn = (ctx: Ctx) => void;\n\n/** Number of declared dep slots visible in this invocation. */\nexport function depCount(ctx: Ctx): number {\n\treturn ctx.waveData.length;\n}\n\n/** DATA/SENTINEL projection batches delivered by one dep in this invocation. */\nexport function depWaves(ctx: Ctx, depIndex: number): readonly (readonly unknown[])[] {\n\treturn ctx.waveData[depIndex] ?? [];\n}\n\n/** Flattened DATA projection for old event-counting operator bodies; null = no wave. */\nexport function depBatch(ctx: Ctx, depIndex: number): readonly unknown[] | null {\n\tconst waves = depWaves(ctx, depIndex);\n\tif (waves.length === 0) return null;\n\tconst flattened = waves.flat().filter((v) => v !== SENTINEL);\n\treturn flattened.length === 0 ? [] : flattened;\n}\n\n/** Latest cached DATA for a dep, derived from implementation-owned dep cache. */\nexport function depLatest(ctx: Ctx, depIndex: number): unknown {\n\treturn ctx[CTX_DEP_CACHE]?.latest[depIndex];\n}\n\n/** Terminal metadata for one dep: false = none, true = COMPLETE, otherwise ERROR payload. */\nexport function depTerminal(ctx: Ctx, depIndex: number): unknown {\n\tconst t = ctx.terminal[depIndex];\n\treturn t === undefined ? false : t;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACoCO,IAAM,WAAW;;;ACyHjB,SAAS,SAAS,KAAU,UAAmD;AACrF,SAAO,IAAI,SAAS,Q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a,OAAwB;AAC7C,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC7D;AAEA,SAAS,eAAe,OAAkD;AACzE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC3E;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/cqrs/index.ts","../../src/protocol/messages.ts","../../src/ctx/types.ts"],"sourcesContent":["/**\n * Reusable application-infrastructure CQRS helpers (B63 / D125 / D129).\n *\n * The bundle is graph-visible facts over ordinary nodes: command DATA facts\n * enter through a graph-owned command node, command handlers run inside the\n * dispatched runtime node, and events/status/errors/audit/cursor are derived\n * facts. It is not a Graph subclass, hidden EventEmitter, saga runtime, or\n * storage-owned restore surface.\n */\n\nimport { depBatch } from \"../ctx/types.js\";\nimport type { Graph } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\n\n/** Command fact accepted by a CQRS bundle. */\nexport interface CqrsCommand<T = unknown> {\n\treadonly id: string;\n\treadonly type: string;\n\treadonly payload: T;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\n/** Event draft returned by a command handler before the runtime orders it. */\nexport interface CqrsEventDraft<T = unknown> {\n\treadonly id?: string;\n\treadonly type: string;\n\treadonly payload: T;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\n/** Ordered event fact emitted by the CQRS runtime node. */\nexport interface CqrsEvent<T = unknown> {\n\treadonly id: string;\n\treadonly type: string;\n\treadonly seq: number;\n\treadonly cursor: number;\n\treadonly runtimeCursor: CqrsCursor;\n\treadonly commandId: string;\n\treadonly commandType: string;\n\treadonly payload: T;\n\treadonly timestampMs: number;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\nexport type CqrsErrorCode =\n\t| \"malformed-command\"\n\t| \"duplicate-command\"\n\t| \"unknown-command\"\n\t| \"handler-threw\"\n\t| \"clock-threw\"\n\t| \"malformed-event\"\n\t| \"unknown-event\"\n\t| \"duplicate-event\";\n\n/** Graph-visible CQRS error fact. These are DATA facts, not protocol ERROR. */\nexport interface CqrsError {\n\treadonly code: CqrsErrorCode;\n\treadonly message: string;\n\treadonly command?: unknown;\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly event?: unknown;\n\treadonly eventType?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsStatus {\n\treadonly state: \"accepted\" | \"rejected\";\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly eventCount: number;\n\treadonly errorCode?: CqrsErrorCode;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsAuditRecord {\n\treadonly seq: number;\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly outcome: \"success\" | \"failure\";\n\treadonly eventIds: readonly string[];\n\treadonly eventTypes: readonly string[];\n\treadonly errorCode?: CqrsErrorCode;\n\treadonly errorMessage?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsDedupeSnapshot {\n\treadonly commandIdsRetained: number;\n\treadonly eventIdsRetained: number;\n\treadonly commandIdsEvicted: number;\n\treadonly eventIdsEvicted: number;\n}\n\nexport interface CqrsCursor {\n\treadonly eventSeq: number;\n\treadonly commandCount: number;\n\treadonly errorCount: number;\n\treadonly auditSeq: number;\n\treadonly dedupe?: CqrsDedupeSnapshot;\n}\n\nexport type CqrsRuntimeFact<T = unknown> =\n\t| { readonly kind: \"event\"; readonly event: CqrsEvent<T> }\n\t| { readonly kind: \"status\"; readonly status: CqrsStatus }\n\t| { readonly kind: \"error\"; readonly error: CqrsError }\n\t| { readonly kind: \"audit\"; readonly audit: CqrsAuditRecord }\n\t| { readonly kind: \"cursor\"; readonly cursor: CqrsCursor };\n\nexport type CqrsCommandHandler<TCommand = unknown, TEvent = unknown> = (\n\tcommand: CqrsCommand<TCommand>,\n) => readonly CqrsEventDraft<TEvent>[];\n\nexport interface CqrsCommandHandlerDefinition<TCommand = unknown, TEvent = unknown> {\n\treadonly type: string;\n\treadonly handle: CqrsCommandHandler<TCommand, TEvent>;\n}\n\nexport interface CqrsOptions<TCommand = unknown, TEvent = unknown> {\n\treadonly name?: string;\n\treadonly handlers?: readonly CqrsCommandHandlerDefinition<TCommand, TEvent>[];\n\treadonly events?: readonly string[];\n\treadonly now?: () => number;\n\t/**\n\t * D142: static command/event duplicate-recognition windows. Omitted means\n\t * exact unbounded dedupe; bounded windows evict oldest ids by insertion order.\n\t */\n\treadonly dedupe?: CqrsDedupePolicy;\n}\n\n/**\n * D151 membership-based duplicate-recognition window for CQRS ids.\n *\n * This is passive CQRS vocabulary, not a shared idempotency reducer engine:\n * commands and events each own their own id membership window.\n */\nexport type CqrsDedupeWindow = \"unbounded\" | { readonly maxEntries: number };\n\nexport interface CqrsDedupePolicy {\n\treadonly commands?: CqrsDedupeWindow;\n\treadonly events?: CqrsDedupeWindow;\n}\n\nexport interface CqrsBundle<TCommand = unknown, TEvent = unknown> {\n\treadonly command: Node<CqrsCommand<TCommand>>;\n\treadonly runtime: Node<CqrsRuntimeFact<TEvent>>;\n\treadonly events: Node<CqrsEvent<TEvent>>;\n\treadonly status: Node<CqrsStatus>;\n\treadonly errors: Node<CqrsError>;\n\treadonly audit: Node<CqrsAuditRecord>;\n\treadonly cursor: Node<CqrsCursor>;\n\tdispatch(command: CqrsCommand<TCommand>): CqrsCommand<TCommand>;\n}\n\ninterface CqrsRuntimeState {\n\teventSeq: number;\n\tcommandCount: number;\n\terrorCount: number;\n\tauditSeq: number;\n\tseenCommandIds: string[];\n\tseenEventIds: string[];\n\tcommandDedupeEvicted?: number;\n\teventDedupeEvicted?: number;\n}\n\ninterface HandlerRecord {\n\treadonly type: string;\n\treadonly handle: CqrsCommandHandler<unknown, unknown>;\n}\n\ninterface NormalizedCqrsDedupePolicy {\n\treadonly commandMaxEntries?: number;\n\treadonly eventMaxEntries?: number;\n\treadonly bounded: boolean;\n}\n\n/** Convenience helper for declaring typed command handlers in a CQRS bundle. */\nexport function cqrsCommandHandler<TCommand = unknown, TEvent = unknown>(\n\ttype: string,\n\thandle: CqrsCommandHandler<TCommand, TEvent>,\n): CqrsCommandHandlerDefinition<TCommand, TEvent> {\n\tif (type.length === 0) throw new Error(\"cqrsCommandHandler: type must be non-empty\");\n\treturn { type, handle };\n}\n\n/**\n * Create a graph-visible CQRS bundle. Command dispatch is only DATA on the\n * returned `command` node; all derived facts flow through declared graph deps.\n */\nexport function cqrs<TCommand = unknown, TEvent = unknown>(\n\tgraph: Graph,\n\topts: CqrsOptions<TCommand, TEvent> = {},\n): CqrsBundle<TCommand, TEvent> {\n\tconst name = opts.name ?? \"cqrs\";\n\tconst handlers = normalizeHandlers(opts.handlers ?? []);\n\tconst knownEvents =\n\t\topts.events === undefined ? undefined : new Set(uniqueNames(opts.events, \"cqrs.events\"));\n\tconst now = opts.now ?? Date.now;\n\tconst dedupe = normalizeDedupePolicy(opts.dedupe);\n\tconst command = graph.node<CqrsCommand<TCommand>>([], null, {\n\t\tname: `${name}/command`,\n\t\tfactory: \"cqrsCommand\",\n\t\tcompleteWhenDepsComplete: false,\n\t\terrorWhenDepsError: false,\n\t});\n\tconst runtime = graph.node<CqrsRuntimeFact<TEvent>>(\n\t\t[command],\n\t\t(ctx) => {\n\t\t\tconst state =\n\t\t\t\tctx.state.get<CqrsRuntimeState>() ??\n\t\t\t\t({\n\t\t\t\t\teventSeq: 0,\n\t\t\t\t\tcommandCount: 0,\n\t\t\t\t\terrorCount: 0,\n\t\t\t\t\tauditSeq: 0,\n\t\t\t\t\tseenCommandIds: [],\n\t\t\t\t\tseenEventIds: [],\n\t\t\t\t} satisfies CqrsRuntimeState);\n\t\t\tctx.state.persist(true);\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\treduceCommandFact(raw, state, handlers, knownEvents, now, dedupe, (fact) =>\n\t\t\t\t\tctx.down([[\"DATA\", fact as CqrsRuntimeFact<TEvent>]]),\n\t\t\t\t);\n\t\t\t}\n\t\t\tctx.state.set(state);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/runtime`,\n\t\t\tfactory: \"cqrsRuntime\",\n\t\t\tmeta: {\n\t\t\t\tcommandTypes: [...handlers.keys()],\n\t\t\t\teventTypes: knownEvents ? [...knownEvents] : \"open\",\n\t\t\t\tdedupe: dedupeMeta(dedupe),\n\t\t\t},\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst events = runtimeProjection<CqrsEvent<TEvent>, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"event\",\n\t\t`${name}/events`,\n\t\t\"cqrsEvents\",\n\t\t(fact) => (fact.kind === \"event\" ? fact.event : undefined),\n\t);\n\tconst status = runtimeProjection<CqrsStatus, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"status\",\n\t\t`${name}/status`,\n\t\t\"cqrsStatus\",\n\t\t(fact) => (fact.kind === \"status\" ? fact.status : undefined),\n\t);\n\tconst errors = runtimeProjection<CqrsError, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"error\",\n\t\t`${name}/errors`,\n\t\t\"cqrsErrors\",\n\t\t(fact) => (fact.kind === \"error\" ? fact.error : undefined),\n\t);\n\tconst audit = runtimeProjection<CqrsAuditRecord, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"audit\",\n\t\t`${name}/audit`,\n\t\t\"cqrsAudit\",\n\t\t(fact) => (fact.kind === \"audit\" ? fact.audit : undefined),\n\t);\n\tconst cursor = runtimeProjection<CqrsCursor, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"cursor\",\n\t\t`${name}/cursor`,\n\t\t\"cqrsCursor\",\n\t\t(fact) => (fact.kind === \"cursor\" ? fact.cursor : undefined),\n\t);\n\tgraph.retain(runtime, { reason: `${name}.cqrs.runtime` });\n\tgraph.retain(events, { reason: `${name}.cqrs.events` });\n\tgraph.retain(status, { reason: `${name}.cqrs.status` });\n\tgraph.retain(errors, { reason: `${name}.cqrs.errors` });\n\tgraph.retain(audit, { reason: `${name}.cqrs.audit` });\n\tgraph.retain(cursor, { reason: `${name}.cqrs.cursor` });\n\treturn {\n\t\tcommand,\n\t\truntime,\n\t\tevents,\n\t\tstatus,\n\t\terrors,\n\t\taudit,\n\t\tcursor,\n\t\tdispatch(commandFact) {\n\t\t\tcommand.down([[\"DATA\", commandFact]]);\n\t\t\treturn commandFact;\n\t\t},\n\t};\n}\n\nexport interface CqrsProjectionOptions<TState, TEvent = unknown> {\n\treadonly name?: string;\n\treadonly events?: readonly string[];\n\treadonly initial: TState;\n\treadonly reducer: (state: TState, event: CqrsEvent<TEvent>) => TState;\n}\n\nexport type CqrsProjectionFrame<TState> =\n\t| {\n\t\t\treadonly kind: \"value\";\n\t\t\treadonly state: TState;\n\t\t\treadonly eventId: string;\n\t\t\treadonly cursor: CqrsCursor;\n\t }\n\t| { readonly kind: \"error\"; readonly error: CqrsProjectionError };\n\nexport interface CqrsProjectionError {\n\treadonly code: \"projection-threw\";\n\treadonly message: string;\n\treadonly eventId: string;\n\treadonly eventType: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsProjectionStatus {\n\treadonly state: \"updated\" | \"errored\";\n\treadonly eventId: string;\n\treadonly eventType?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsProjection<TState> {\n\treadonly frames: Node<CqrsProjectionFrame<TState>>;\n\treadonly value: Node<TState>;\n\treadonly status: Node<CqrsProjectionStatus>;\n\treadonly errors: Node<CqrsProjectionError>;\n}\n\n/**\n * Derive a projection from declared CQRS event deps. Reducer failures become\n * graph-visible error DATA facts on the returned `errors` node.\n */\nexport function cqrsProjection<TState, TEvent = unknown>(\n\tgraph: Graph,\n\tsource: Pick<CqrsBundle<unknown, TEvent>, \"events\">,\n\topts: CqrsProjectionOptions<TState, TEvent>,\n): CqrsProjection<TState> {\n\tconst name = opts.name ?? \"cqrsProjection\";\n\tconst eventFilter =\n\t\topts.events === undefined\n\t\t\t? undefined\n\t\t\t: new Set(uniqueNames(opts.events, \"cqrsProjection.events\"));\n\tconst frames = graph.node<CqrsProjectionFrame<TState>>(\n\t\t[source.events],\n\t\t(ctx) => {\n\t\t\tconst state = ctx.state.get<{ value: TState }>() ?? { value: opts.initial };\n\t\t\tctx.state.persist(true);\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst event = raw as CqrsEvent<TEvent>;\n\t\t\t\tif (eventFilter !== undefined && !eventFilter.has(event.type)) continue;\n\t\t\t\ttry {\n\t\t\t\t\tstate.value = opts.reducer(state.value, event);\n\t\t\t\t\tctx.state.set(state);\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"value\",\n\t\t\t\t\t\t\t\tstate: state.value,\n\t\t\t\t\t\t\t\teventId: event.id,\n\t\t\t\t\t\t\t\tcursor: event.runtimeCursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionFrame<TState>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t} catch (error) {\n\t\t\t\t\trethrowGraphRuntimeInvariant(error);\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"error\",\n\t\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\t\tcode: \"projection-threw\",\n\t\t\t\t\t\t\t\t\tmessage: errorMessage(error),\n\t\t\t\t\t\t\t\t\teventId: event.id,\n\t\t\t\t\t\t\t\t\teventType: event.type,\n\t\t\t\t\t\t\t\t\tcursor: event.runtimeCursor,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t} satisfies CqrsProjectionFrame<TState>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory: \"cqrsProjection\",\n\t\t\tmeta: { eventTypes: eventFilter ? [...eventFilter] : \"open\" },\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst value = graph.node<TState>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"value\") ctx.down([[\"DATA\", typed.state]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/value`,\n\t\t\tfactory: \"cqrsProjectionValue\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst errors = graph.node<CqrsProjectionError>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"error\") ctx.down([[\"DATA\", typed.error]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/errors`,\n\t\t\tfactory: \"cqrsProjectionErrors\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst status = graph.node<CqrsProjectionStatus>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"value\") {\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tstate: \"updated\",\n\t\t\t\t\t\t\t\teventId: typed.eventId,\n\t\t\t\t\t\t\t\tcursor: typed.cursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionStatus,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t} else {\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tstate: \"errored\",\n\t\t\t\t\t\t\t\teventId: typed.error.eventId,\n\t\t\t\t\t\t\t\teventType: typed.error.eventType,\n\t\t\t\t\t\t\t\tcursor: typed.error.cursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionStatus,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/status`,\n\t\t\tfactory: \"cqrsProjectionStatus\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tgraph.retain(frames, { reason: `${name}.cqrsProjection.frames` });\n\tgraph.retain(value, { reason: `${name}.cqrsProjection.value` });\n\tgraph.retain(status, { reason: `${name}.cqrsProjection.status` });\n\tgraph.retain(errors, { reason: `${name}.cqrsProjection.errors` });\n\treturn { frames, value, status, errors };\n}\n\nfunction normalizeHandlers<TCommand, TEvent>(\n\tdefinitions: readonly CqrsCommandHandlerDefinition<TCommand, TEvent>[],\n): ReadonlyMap<string, HandlerRecord> {\n\tconst handlers = new Map<string, HandlerRecord>();\n\tfor (const definition of definitions) {\n\t\tif (definition.type.length === 0) throw new Error(\"cqrs: handler type must be non-empty\");\n\t\tif (handlers.has(definition.type))\n\t\t\tthrow new Error(`cqrs: duplicate handler '${definition.type}'`);\n\t\thandlers.set(definition.type, {\n\t\t\ttype: definition.type,\n\t\t\thandle: definition.handle as CqrsCommandHandler<unknown, unknown>,\n\t\t});\n\t}\n\treturn handlers;\n}\n\nfunction reduceCommandFact<TEvent>(\n\traw: unknown,\n\tstate: CqrsRuntimeState,\n\thandlers: ReadonlyMap<string, HandlerRecord>,\n\tknownEvents: ReadonlySet<string> | undefined,\n\tnow: () => number,\n\tdedupe: NormalizedCqrsDedupePolicy,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n): void {\n\tstate.commandCount += 1;\n\tconst parsed = parseCommand(raw);\n\tif (typeof parsed === \"string\") {\n\t\temitFailure(state, emit, raw, undefined, \"malformed-command\", parsed, dedupe);\n\t\treturn;\n\t}\n\tconst command = parsed as CqrsCommand<unknown>;\n\tif (state.seenCommandIds.includes(command.id)) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"duplicate-command\",\n\t\t\t`cqrs: duplicate command '${command.id}'`,\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tstate.seenCommandIds.push(command.id);\n\ttrimDedupeWindow(state.seenCommandIds, dedupe.commandMaxEntries, (evicted) => {\n\t\tstate.commandDedupeEvicted = (state.commandDedupeEvicted ?? 0) + evicted;\n\t});\n\tconst handler = handlers.get(command.type);\n\tif (handler === undefined) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"unknown-command\",\n\t\t\t`cqrs: unknown command '${command.type}'`,\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tlet drafts: readonly CqrsEventDraft<unknown>[];\n\ttry {\n\t\tdrafts = handler.handle(command);\n\t} catch (error) {\n\t\trethrowGraphRuntimeInvariant(error);\n\t\temitFailure(state, emit, command, command, \"handler-threw\", errorMessage(error), dedupe);\n\t\treturn;\n\t}\n\tif (!Array.isArray(drafts)) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"malformed-event\",\n\t\t\t\"cqrs: command handler must return an event draft array\",\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tconst prepared = prepareEvents(command, drafts, state, knownEvents);\n\tif (typeof prepared === \"string\") {\n\t\temitFailure(state, emit, command, command, preparedCode(prepared), prepared, dedupe);\n\t\treturn;\n\t}\n\tconst timestampMs = readTimestampMs(now);\n\tif (typeof timestampMs === \"string\") {\n\t\temitFailure(state, emit, command, command, \"clock-threw\", timestampMs, dedupe);\n\t\treturn;\n\t}\n\tconst events: CqrsEvent<unknown>[] = [];\n\tfor (const draft of prepared) {\n\t\tstate.eventSeq += 1;\n\t\tstate.seenEventIds.push(draft.id);\n\t\ttrimDedupeWindow(state.seenEventIds, dedupe.eventMaxEntries, (evicted) => {\n\t\t\tstate.eventDedupeEvicted = (state.eventDedupeEvicted ?? 0) + evicted;\n\t\t});\n\t\tconst runtimeCursor = cursorOf(state, dedupe);\n\t\tevents.push({\n\t\t\tid: draft.id,\n\t\t\ttype: draft.type,\n\t\t\tseq: state.eventSeq,\n\t\t\tcursor: state.eventSeq,\n\t\t\truntimeCursor,\n\t\t\tcommandId: command.id,\n\t\t\tcommandType: command.type,\n\t\t\tpayload: draft.payload,\n\t\t\ttimestampMs,\n\t\t\t...(draft.aggregateId === undefined ? {} : { aggregateId: draft.aggregateId }),\n\t\t\t...(draft.correlationId === undefined ? {} : { correlationId: draft.correlationId }),\n\t\t\t...(draft.causationId === undefined ? {} : { causationId: draft.causationId }),\n\t\t\t...(draft.metadata === undefined ? {} : { metadata: draft.metadata }),\n\t\t});\n\t}\n\tfor (const event of events) emit({ kind: \"event\", event: event as CqrsEvent<TEvent> });\n\temitStatus(state, emit, command, \"accepted\", events.length, dedupe);\n\temitAudit(state, emit, command, \"success\", events, undefined, undefined, dedupe);\n\temit({ kind: \"cursor\", cursor: cursorOf(state, dedupe) });\n}\n\nfunction parseCommand(value: unknown): CqrsCommand<unknown> | string {\n\tif (!isObjectRecord(value)) return \"cqrs: command fact must be an object\";\n\tif (typeof value.id !== \"string\" || value.id.length === 0) {\n\t\treturn \"cqrs: command id must be a non-empty string\";\n\t}\n\tif (typeof value.type !== \"string\" || value.type.length === 0) {\n\t\treturn \"cqrs: command type must be a non-empty string\";\n\t}\n\treturn {\n\t\tid: value.id,\n\t\ttype: value.type,\n\t\tpayload: value.payload,\n\t\t...(typeof value.aggregateId === \"string\" ? { aggregateId: value.aggregateId } : {}),\n\t\t...(typeof value.correlationId === \"string\" ? { correlationId: value.correlationId } : {}),\n\t\t...(typeof value.causationId === \"string\" ? { causationId: value.causationId } : {}),\n\t\t...(isObjectRecord(value.metadata) ? { metadata: value.metadata } : {}),\n\t};\n}\n\nfunction prepareEvents(\n\tcommand: CqrsCommand<unknown>,\n\tdrafts: readonly CqrsEventDraft<unknown>[],\n\tstate: CqrsRuntimeState,\n\tknownEvents: ReadonlySet<string> | undefined,\n): Array<CqrsEventDraft<unknown> & { readonly id: string }> | string {\n\tconst seenInCommand = new Set<string>();\n\tconst prepared: Array<CqrsEventDraft<unknown> & { readonly id: string }> = [];\n\tfor (let i = 0; i < drafts.length; i += 1) {\n\t\tconst draft = drafts[i];\n\t\tif (!isObjectRecord(draft) || typeof draft.type !== \"string\" || draft.type.length === 0) {\n\t\t\treturn \"cqrs: event draft must have a non-empty type\";\n\t\t}\n\t\tif (knownEvents !== undefined && !knownEvents.has(draft.type)) {\n\t\t\treturn `cqrs: unknown event '${draft.type}'`;\n\t\t}\n\t\tconst id =\n\t\t\ttypeof draft.id === \"string\" && draft.id.length > 0 ? draft.id : `${command.id}:${i + 1}`;\n\t\tif (state.seenEventIds.includes(id) || seenInCommand.has(id)) {\n\t\t\treturn `cqrs: duplicate event '${id}'`;\n\t\t}\n\t\tseenInCommand.add(id);\n\t\tprepared.push({\n\t\t\tid,\n\t\t\ttype: draft.type,\n\t\t\tpayload: draft.payload,\n\t\t\t...(typeof draft.aggregateId === \"string\" ? { aggregateId: draft.aggregateId } : {}),\n\t\t\t...(typeof draft.correlationId === \"string\" ? { correlationId: draft.correlationId } : {}),\n\t\t\t...(typeof draft.causationId === \"string\" ? { causationId: draft.causationId } : {}),\n\t\t\t...(isObjectRecord(draft.metadata) ? { metadata: draft.metadata } : {}),\n\t\t});\n\t}\n\treturn prepared;\n}\n\nfunction preparedCode(message: string): CqrsErrorCode {\n\tif (message.includes(\"unknown event\")) return \"unknown-event\";\n\tif (message.includes(\"duplicate event\")) return \"duplicate-event\";\n\treturn \"malformed-event\";\n}\n\nfunction rethrowGraphRuntimeInvariant(error: unknown): void {\n\tconst message = errorMessage(error);\n\tif (\n\t\tmessage.includes(\"R-reentrancy\") ||\n\t\tmessage.includes(\"R-rewire\") ||\n\t\tmessage.includes(\"R-graph-domain\") ||\n\t\tmessage.includes(\"D37\") ||\n\t\tmessage.includes(\"D22\") ||\n\t\tmessage.includes(\"different graph\") ||\n\t\tmessage.includes(\"cross-graph\") ||\n\t\tmessage.includes(\"wire bridge\") ||\n\t\tmessage.includes(\"mid-fn topology mutation\") ||\n\t\tmessage.includes(\"reentrant dep mutation\") ||\n\t\tmessage.includes(\"feedback cycle\")\n\t) {\n\t\tthrow error;\n\t}\n}\n\nfunction emitFailure<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\traw: unknown,\n\tcommand: CqrsCommand<unknown> | undefined,\n\tcode: CqrsErrorCode,\n\tmessage: string,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\tstate.errorCount += 1;\n\tconst cursor = cursorOf(state, dedupe);\n\tconst error: CqrsError = {\n\t\tcode,\n\t\tmessage,\n\t\tcommand: raw,\n\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\tcursor,\n\t};\n\temit({ kind: \"error\", error });\n\temit({\n\t\tkind: \"status\",\n\t\tstatus: {\n\t\t\tstate: \"rejected\",\n\t\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\t\teventCount: 0,\n\t\t\terrorCode: code,\n\t\t\tcursor,\n\t\t},\n\t});\n\temitAudit(state, emit, command, \"failure\", [], code, message, dedupe);\n\temit({ kind: \"cursor\", cursor: cursorOf(state, dedupe) });\n}\n\nfunction emitStatus<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\tcommand: CqrsCommand<unknown>,\n\tstatusState: \"accepted\" | \"rejected\",\n\teventCount: number,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\temit({\n\t\tkind: \"status\",\n\t\tstatus: {\n\t\t\tstate: statusState,\n\t\t\tcommandId: command.id,\n\t\t\tcommandType: command.type,\n\t\t\teventCount,\n\t\t\tcursor: cursorOf(state, dedupe),\n\t\t},\n\t});\n}\n\nfunction emitAudit<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\tcommand: CqrsCommand<unknown> | undefined,\n\toutcome: \"success\" | \"failure\",\n\tevents: readonly CqrsEvent<unknown>[],\n\terrorCode: CqrsErrorCode | undefined,\n\terrorMessageValue: string | undefined,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\tstate.auditSeq += 1;\n\temit({\n\t\tkind: \"audit\",\n\t\taudit: {\n\t\t\tseq: state.auditSeq,\n\t\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\t\toutcome,\n\t\t\teventIds: Object.freeze(events.map((event) => event.id)),\n\t\t\teventTypes: Object.freeze(events.map((event) => event.type)),\n\t\t\t...(errorCode === undefined ? {} : { errorCode }),\n\t\t\t...(errorMessageValue === undefined ? {} : { errorMessage: errorMessageValue }),\n\t\t\tcursor: cursorOf(state, dedupe),\n\t\t},\n\t});\n}\n\nfunction runtimeProjection<TOut, TEvent>(\n\tgraph: Graph,\n\truntime: Node<CqrsRuntimeFact<TEvent>>,\n\tkind: CqrsRuntimeFact<TEvent>[\"kind\"],\n\tname: string,\n\tfactory: string,\n\tselect: (fact: CqrsRuntimeFact<TEvent>) => TOut | undefined,\n): Node<TOut> {\n\treturn graph.node<TOut>(\n\t\t[runtime],\n\t\t(ctx) => {\n\t\t\tfor (const fact of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = fact as CqrsRuntimeFact<TEvent>;\n\t\t\t\tif (typed.kind !== kind) continue;\n\t\t\t\tconst selected = select(typed);\n\t\t\t\tif (selected !== undefined) ctx.down([[\"DATA\", selected]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n}\n\nfunction cursorOf(state: CqrsRuntimeState, dedupe: NormalizedCqrsDedupePolicy): CqrsCursor {\n\treturn {\n\t\teventSeq: state.eventSeq,\n\t\tcommandCount: state.commandCount,\n\t\terrorCount: state.errorCount,\n\t\tauditSeq: state.auditSeq,\n\t\t...(dedupe.bounded\n\t\t\t? {\n\t\t\t\t\tdedupe: {\n\t\t\t\t\t\tcommandIdsRetained: state.seenCommandIds.length,\n\t\t\t\t\t\teventIdsRetained: state.seenEventIds.length,\n\t\t\t\t\t\tcommandIdsEvicted: state.commandDedupeEvicted ?? 0,\n\t\t\t\t\t\teventIdsEvicted: state.eventDedupeEvicted ?? 0,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n\nfunction normalizeDedupePolicy(policy: CqrsDedupePolicy | undefined): NormalizedCqrsDedupePolicy {\n\tconst commandMaxEntries = normalizeDedupeWindow(policy?.commands, \"cqrs.dedupe.commands\");\n\tconst eventMaxEntries = normalizeDedupeWindow(policy?.events, \"cqrs.dedupe.events\");\n\treturn {\n\t\t...(commandMaxEntries === undefined ? {} : { commandMaxEntries }),\n\t\t...(eventMaxEntries === undefined ? {} : { eventMaxEntries }),\n\t\tbounded: commandMaxEntries !== undefined || eventMaxEntries !== undefined,\n\t};\n}\n\nfunction normalizeDedupeWindow(\n\twindow: CqrsDedupeWindow | undefined,\n\towner: string,\n): number | undefined {\n\tif (window === undefined || window === \"unbounded\") return undefined;\n\tif (!Number.isInteger(window.maxEntries) || window.maxEntries < 0) {\n\t\tthrow new RangeError(`${owner}: maxEntries must be a non-negative integer`);\n\t}\n\treturn window.maxEntries;\n}\n\nfunction dedupeMeta(dedupe: NormalizedCqrsDedupePolicy): unknown {\n\tif (!dedupe.bounded) return \"unbounded\";\n\treturn {\n\t\tcommands:\n\t\t\tdedupe.commandMaxEntries === undefined\n\t\t\t\t? \"unbounded\"\n\t\t\t\t: { maxEntries: dedupe.commandMaxEntries },\n\t\tevents:\n\t\t\tdedupe.eventMaxEntries === undefined ? \"unbounded\" : { maxEntries: dedupe.eventMaxEntries },\n\t};\n}\n\nfunction trimDedupeWindow(\n\tids: string[],\n\tmaxEntries: number | undefined,\n\tonEvicted: (evicted: number) => void,\n): void {\n\tif (maxEntries === undefined || ids.length <= maxEntries) return;\n\tconst evicted = ids.length - maxEntries;\n\tids.splice(0, evicted);\n\tonEvicted(evicted);\n}\n\nfunction readTimestampMs(now: () => number): number | string {\n\ttry {\n\t\tconst timestampMs = now();\n\t\treturn Number.isFinite(timestampMs) ? timestampMs : \"cqrs: now() must return a finite number\";\n\t} catch (error) {\n\t\treturn `cqrs: now() threw: ${errorMessage(error)}`;\n\t}\n}\n\nfunction uniqueNames(values: readonly string[], owner: string): readonly string[] {\n\tconst unique = [...new Set(values)];\n\tif (unique.length !== values.length) throw new Error(`${owner}: duplicate value`);\n\tfor (const value of unique) {\n\t\tif (value.length === 0) throw new Error(`${owner}: values must be non-empty`);\n\t}\n\treturn Object.freeze(unique);\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction isObjectRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n","/**\n * Wave-protocol message types and the tier const table.\n *\n * Canonical authority: ~/src/graphrefly/spec/rules.jsonl\n * R-msg-format, R-msg-closed-set, R-tier (D34), R-data-payload, R-sentinel.\n */\n\n/** Opaque pause-lock / pull identifier (R-pause-lockset, R-pull). */\nexport type LockId = string | symbol;\n\n/** Explicit pull demand payload (D269/D272). Params are holder-visible context, never DATA-up. */\nexport interface PullDemand {\n\treadonly pullId: LockId;\n\treadonly params?: unknown;\n}\n\n/**\n * The CLOSED set of 11 message types (R-msg-closed-set / D9 + D269 + START handshake).\n * No open set, no user-defined custom types. Adding a type is a spec change.\n */\nexport type Message =\n\t| readonly [\"START\"]\n\t| readonly [\"DIRTY\"]\n\t| readonly [\"DATA\", unknown]\n\t| readonly [\"RESOLVED\"]\n\t| readonly [\"INVALIDATE\"]\n\t| readonly [\"COMPLETE\"]\n\t| readonly [\"ERROR\", unknown]\n\t| readonly [\"TEARDOWN\"]\n\t| readonly [\"PAUSE\", LockId]\n\t| readonly [\"RESUME\", LockId]\n\t| readonly [\"PULL\", PullDemand];\n\n/** One array of messages delivered in one call = one Wave (R-wave-boundary). */\nexport type Wave = readonly Message[];\n\n/** The message-type tag (the first tuple element). */\nexport type MessageType = Message[0];\n\n/**\n * SENTINEL = absence-of-DATA (R-sentinel / D16). TS representation is `undefined`.\n * Never a valid DATA payload; `null` IS a valid DATA value (domain-level absence).\n */\nexport const SENTINEL = undefined;\n\n/** R-data-payload: ERROR payloads must not collide with terminal metadata shorthand. */\nexport function isInvalidErrorPayload(v: unknown): boolean {\n\treturn v === SENTINEL || typeof v === \"boolean\";\n}\n\n/** R-data-payload / D78: host-language failures that collide with ctx.terminal shorthand become diagnostics. */\nexport function errorPayload(reason: unknown, fallback = \"error without a valid payload\"): unknown {\n\treturn isInvalidErrorPayload(reason) ? new Error(fallback) : reason;\n}\n\nexport const TIER_START = 0;\nexport const TIER_CONTROL = 1;\nexport const TIER_NOTIFICATION = 2;\nexport const TIER_VALUE = 3;\nexport const TIER_SETTLE = 4;\nexport const TIER_TERMINAL = 5;\nexport const TIER_TEARDOWN = 6;\n\n/**\n * Tier const table (R-tier / D34). Tiers below value dispatch immediately; value\n * and above are batch-deferred. This is a compile-time const table (D18), not runtime config.\n */\nconst TIER: Record<MessageType, number> = {\n\tSTART: TIER_START,\n\tPAUSE: TIER_CONTROL,\n\tRESUME: TIER_CONTROL,\n\tPULL: TIER_CONTROL,\n\tDIRTY: TIER_NOTIFICATION,\n\tDATA: TIER_VALUE,\n\tRESOLVED: TIER_VALUE,\n\tINVALIDATE: TIER_SETTLE,\n\tCOMPLETE: TIER_TERMINAL,\n\tERROR: TIER_TERMINAL,\n\tTEARDOWN: TIER_TEARDOWN,\n};\n\nexport function messageTier(t: MessageType): number {\n\treturn TIER[t];\n}\n\n/** Value and above are deferred inside a batch (DATA/RESOLVED/INVALIDATE/terminal/teardown). */\nexport function isDeferredTier(t: MessageType): boolean {\n\treturn TIER[t] >= TIER_VALUE;\n}\n\n/** Value-tier messages (DATA/RESOLVED) occupy the tier-3 slot. */\nexport function isValueTier(t: MessageType): boolean {\n\treturn TIER[t] === TIER_VALUE;\n}\n\n/** The pause buffer holds the settle slice only: value-tier DATA/RESOLVED plus INVALIDATE. */\nexport function isPauseBufferedTier(t: MessageType): boolean {\n\tconst tier = TIER[t];\n\treturn tier === TIER_VALUE || tier === TIER_SETTLE;\n}\n\n/**\n * A TERMINAL message = tier 5 (COMPLETE | ERROR), R-tier / D34. Detected via the CENTRAL tier\n * table, NOT a per-variant `=== \"COMPLETE\" || === \"ERROR\"` check — so terminal routing stays\n * driven by the one const table (feedback_use_tier_for_signal_routing); discriminate COMPLETE vs\n * ERROR within the tier by the message type only where the handling actually differs.\n */\nexport function isTerminal(t: MessageType): boolean {\n\treturn TIER[t] === TIER_TERMINAL;\n}\n\n/**\n * ctx.up carries control/demand tiers only (R-ctx-up / D269): DIRTY, PAUSE, RESUME, PULL,\n * INVALIDATE, TEARDOWN. DATA/RESOLVED (tier 3) and COMPLETE/ERROR (tier 5) are\n * down-only.\n */\nexport function isUpAllowed(t: MessageType): boolean {\n\tconst tier = TIER[t];\n\treturn tier !== TIER_VALUE && tier !== TIER_TERMINAL;\n}\n","/**\n * The fn-invocation context and per-dep input shapes.\n *\n * Canonical authority: ~/src/graphrefly/spec/rules.jsonl\n * R-fn-contract (D8/D27), R-ctx-state (D23/D29), R-cleanup-hooks (D28), R-ctx-up.\n */\n\nimport type { Dispatcher } from \"../dispatcher/index.js\";\nimport type { EnvironmentDrivers } from \"../graph/environment.js\";\nimport type { Node } from \"../node/node.js\";\nimport { type Message, type PullDemand, SENTINEL, type Wave } from \"../protocol/messages.js\";\n\n/** A downstream sink callback (the only way to connect to a node's output). */\nexport type Sink = (msg: Message, delivery?: DeliveryMeta) => void;\n\n/** Internal delivery metadata used to preserve the upstream `ctx.down(msgs)` wave boundary. */\nexport interface DeliveryMeta {\n\treadonly wave: object;\n\treadonly last: boolean;\n}\n\n/**\n * Internal current-value reader. It is deliberately a symbol-backed implementation detail:\n * raw ctx exposes `waveData` + `terminal`; helpers below derive from that plus this dep cache.\n */\nexport const CTX_DEP_CACHE: unique symbol = Symbol(\"graphrefly.ctx.depCache\");\n\nexport interface CtxDepCache {\n\treadonly latest: readonly unknown[];\n}\n\n/** Internal node-construction binding for graph-local helper-created deps. */\nexport const CTX_NODE_BINDING: unique symbol = Symbol(\"graphrefly.ctx.nodeBinding\");\n\nexport interface CtxNodeBinding {\n\treadonly dispatcher: Dispatcher;\n\tcreate<T>(factory: () => Node<T>): Node<T>;\n}\n\n/** Per-dep wave projections: dep -> waves -> values/SENTINEL markers. */\nexport type WaveData = readonly (readonly (readonly unknown[])[])[];\n\n/** Terminal metadata parallel to `waveData`: false = none, true = COMPLETE, otherwise ERROR payload. */\nexport type TerminalData = readonly unknown[];\n\nexport function isTerminalNone(t: unknown): boolean {\n\treturn t === false || t === undefined;\n}\n\nexport function isTerminalComplete(t: unknown): t is true {\n\treturn t === true;\n}\n\nexport function isTerminalError(t: unknown): boolean {\n\treturn !isTerminalNone(t) && !isTerminalComplete(t);\n}\n\nexport function terminalErrorValue(t: unknown): unknown {\n\treturn isTerminalError(t) ? t : undefined;\n}\n\n/**\n * Per-node private cross-wave state (R-ctx-state / D23,D29). Default fresh-lifecycle\n * wipe; `persist(true)` keeps it across lifecycle transitions.\n */\nexport interface CtxState {\n\tget<S = unknown>(): S | undefined;\n\tset<S = unknown>(v: S): void;\n\tpersist(on?: boolean): void;\n}\n\n/**\n * Deferred SELF-rewire (R-rewire-deferred / D47). A node fn may, DURING its run, request a\n * mutation of its OWN dep set; the request is QUEUED and applied at the committed wave boundary\n * (after the current wave settles / batch commit / final-lock RESUME) as a fresh wave, reusing\n * R-rewire surgical/Option-C semantics (D42). This is the ONLY legal self-triggered rewire — an\n * IMMEDIATE in-fn `node.subscribeDep/unsubscribeDep/replaceDeps` is the D37 mid-fn feedback-cycle ERROR. An\n * added cached dep pushes `[DIRTY,DATA]` on the boundary wave (R-push-subscribe); a removed dep\n * is drained and, if it loses its last subscriber, `_deactivate`s + fires `onDeactivation`\n * (input-side teardown — the basis for higher-order operator cancellation / abortInFlight).\n */\nexport interface RewireNext {\n\t/** Defer subscribing to a dep (paired with the re-supplied fn — positional fn-deps lock, SD-1). */\n\tsubscribeDep(dep: Node<unknown>, fn: NodeFn): void;\n\t/** Defer unsubscribing from a dep (its source is torn down if it loses its last subscriber). */\n\tunsubscribeDep(dep: Node<unknown>, fn: NodeFn): void;\n\t/** Defer replacing the whole dep set (surgical: kept deps untouched, removed drained, added fresh-subscribe). */\n\treplaceDeps(deps: Node<unknown>[], fn: NodeFn): void;\n}\n\n/**\n * The single argument to a node fn: `(ctx) => void` (R-fn-contract / D8). All emission\n * is explicit via `ctx.down`; there is no return-value framing.\n */\nexport interface Ctx {\n\t/**\n\t * Emit upstream toward deps — control tiers only (R-ctx-up). IMMEDIATE. `towardDep` (a dep index)\n\t * routes the wave up ONE declared edge (R-up-routing directed-up); omitted = broadcast up all deps.\n\t * A pull DEMAND is `up([[PULL, { pullId, params }]])` — but for a SELF-demand (demanding a dep\n\t * this fn also reads) use {@link Ctx.upNext} instead, since an immediate demand whose delivery loops back\n\t * re-enters this fn mid-wave (D37 / R-reentrancy).\n\t */\n\tup(msgs: Wave, towardDep?: number): void;\n\t/** Emit downstream toward sinks. */\n\tdown(msgs: Wave): void;\n\t/**\n\t * The single raw dep-value input surface (R-ctx-wave-data / D77): dep -> upstream waves ->\n\t * per-wave DATA payloads and INVALIDATE/SENTINEL markers. `waveData[i] = []` means dep i\n\t * delivered no wave to this invocation; `waveData[i] = [[]]` means RESOLVED-only.\n\t */\n\twaveData: WaveData;\n\t/** Terminal metadata for the same invocation; terminal values never enter `waveData`. */\n\tterminal: TerminalData;\n\tstate: CtxState;\n\t/** Release external resources on deactivation (R-cleanup-hooks). */\n\tonDeactivation(fn: () => void): void;\n\t/** Flush on INVALIDATE (R-cleanup-hooks). */\n\tonInvalidate(fn: () => void): void;\n\t/** Graph-owned environment drivers for source/adapter boundaries (D130/D131). */\n\tenvironment(): EnvironmentDrivers;\n\t/** Holder-visible context for a PULL-caused invocation (D272); absent for ordinary waves. */\n\treadonly pull?: PullDemand;\n\t/**\n\t * Deferred SELF-rewire (R-rewire-deferred / D47) — the substrate affordance higher-order\n\t * operators (switchMap/mergeMap/concatMap/exhaustMap/flatMap) use to grow/shrink their own\n\t * inner-source dep set in response to their own data. Always present; see {@link RewireNext}.\n\t */\n\trewireNext: RewireNext;\n\t/**\n\t * Deferred up — the boundary-deferred form of {@link Ctx.up} (R-up-routing / R-pull / D59). Routes\n\t * `msgs` up from this node at the COMMITTED wave boundary (broadcast, or up the single `towardDep`\n\t * edge), riding the same R-rewire-deferred (D47) drain as {@link RewireNext}. This is the\n\t * SELF-DEMAND path: a consumer issues `ctx.upNext([[PULL, { pullId, params }]])` to demand a pull\n\t * dep it ALSO reads — the cone-routed PULL reaches the pullId-holder, whose delivery loops back as a\n\t * FRESH wave (not a mid-fn re-entry → no D37). The consumer accepts one-wave latency (the\n\t * HTTP-request model). No node reference needed: the author writes the pullId verbatim.\n\t */\n\tupNext(msgs: Wave, towardDep?: number): void;\n\t/**\n\t * Read a dep's latest value by index (dynamicNode only, R-dynamic-node / D35).\n\t * Present only on dynamicNode fns; all declared deps still participate in wave\n\t * tracking. Under D49/R-resolved-undirty an unread dep's change still fires the fn,\n\t * which re-emits its (unchanged) output as a DATA occurrence — there is NO equals-\n\t * absorption; pair with distinctUntilChanged to suppress unchanged re-emits (opt-in).\n\t */\n\ttrack?(depIndex: number): unknown;\n\t[CTX_DEP_CACHE]?: CtxDepCache;\n\t[CTX_NODE_BINDING]?: CtxNodeBinding;\n}\n\n/** A node fn (R-fn-contract). Registered in a dispatcher pool, indexed by Handle. */\nexport type NodeFn = (ctx: Ctx) => void;\n\n/** Number of declared dep slots visible in this invocation. */\nexport function depCount(ctx: Ctx): number {\n\treturn ctx.waveData.length;\n}\n\n/** DATA/SENTINEL projection batches delivered by one dep in this invocation. */\nexport function depWaves(ctx: Ctx, depIndex: number): readonly (readonly unknown[])[] {\n\treturn ctx.waveData[depIndex] ?? [];\n}\n\n/** Flattened DATA projection for old event-counting operator bodies; null = no wave. */\nexport function depBatch(ctx: Ctx, depIndex: number): readonly unknown[] | null {\n\tconst waves = depWaves(ctx, depIndex);\n\tif (waves.length === 0) return null;\n\tconst flattened = waves.flat().filter((v) => v !== SENTINEL);\n\treturn flattened.length === 0 ? [] : flattened;\n}\n\n/** Latest cached DATA for a dep, derived from implementation-owned dep cache. */\nexport function depLatest(ctx: Ctx, depIndex: number): unknown {\n\treturn ctx[CTX_DEP_CACHE]?.latest[depIndex];\n}\n\n/** Terminal metadata for one dep: false = none, true = COMPLETE, otherwise ERROR payload. */\nexport function depTerminal(ctx: Ctx, depIndex: number): unknown {\n\tconst t = ctx.terminal[depIndex];\n\treturn t === undefined ? false : t;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2CO,IAAM,WAAW;;;ACoHjB,SAAS,SAAS,KAAU,UAAmD;AACrF,SAAO,IAAI,SAAS,QAAQ,KAAK,CAAC;AACnC;AAGO,SAAS,SAAS,KAAU,UAA6C;AAC/E,QAAM,QAAQ,SAAS,KAAK,QAAQ;AACpC,MAAI,MAAM,WAAW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,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC3E;","names":[]}
|
package/dist/cqrs/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { d as Graph } from '../graph-
|
|
2
|
-
import { N as Node } from '../types-
|
|
1
|
+
import { d as Graph } from '../graph-DCEWh4T2.cjs';
|
|
2
|
+
import { N as Node } from '../types-CcPIn7sy.cjs';
|
|
3
3
|
import '../core/index.cjs';
|
|
4
|
-
import '../messages-
|
|
4
|
+
import '../messages-CAzUPPJM.cjs';
|
|
5
5
|
import '../codec-BB7p8fJc.cjs';
|
|
6
|
-
import '../describe-
|
|
6
|
+
import '../describe-DYMw_l1C.cjs';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Reusable application-infrastructure CQRS helpers (B63 / D125 / D129).
|
package/dist/cqrs/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { d as Graph } from '../graph-
|
|
2
|
-
import { N as Node } from '../types-
|
|
1
|
+
import { d as Graph } from '../graph-D-1-SQeC.js';
|
|
2
|
+
import { N as Node } from '../types-BsJvElYZ.js';
|
|
3
3
|
import '../core/index.js';
|
|
4
|
-
import '../messages-
|
|
4
|
+
import '../messages-CAzUPPJM.js';
|
|
5
5
|
import '../codec-BB7p8fJc.js';
|
|
6
|
-
import '../describe-
|
|
6
|
+
import '../describe-BpyJuWkw.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Reusable application-infrastructure CQRS helpers (B63 / D125 / D129).
|
package/dist/cqrs/index.js
CHANGED
package/dist/cqrs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cqrs/index.ts"],"sourcesContent":["/**\n * Reusable application-infrastructure CQRS helpers (B63 / D125 / D129).\n *\n * The bundle is graph-visible facts over ordinary nodes: command DATA facts\n * enter through a graph-owned command node, command handlers run inside the\n * dispatched runtime node, and events/status/errors/audit/cursor are derived\n * facts. It is not a Graph subclass, hidden EventEmitter, saga runtime, or\n * storage-owned restore surface.\n */\n\nimport { depBatch } from \"../ctx/types.js\";\nimport type { Graph } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\n\n/** Command fact accepted by a CQRS bundle. */\nexport interface CqrsCommand<T = unknown> {\n\treadonly id: string;\n\treadonly type: string;\n\treadonly payload: T;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\n/** Event draft returned by a command handler before the runtime orders it. */\nexport interface CqrsEventDraft<T = unknown> {\n\treadonly id?: string;\n\treadonly type: string;\n\treadonly payload: T;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\n/** Ordered event fact emitted by the CQRS runtime node. */\nexport interface CqrsEvent<T = unknown> {\n\treadonly id: string;\n\treadonly type: string;\n\treadonly seq: number;\n\treadonly cursor: number;\n\treadonly runtimeCursor: CqrsCursor;\n\treadonly commandId: string;\n\treadonly commandType: string;\n\treadonly payload: T;\n\treadonly timestampMs: number;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\nexport type CqrsErrorCode =\n\t| \"malformed-command\"\n\t| \"duplicate-command\"\n\t| \"unknown-command\"\n\t| \"handler-threw\"\n\t| \"clock-threw\"\n\t| \"malformed-event\"\n\t| \"unknown-event\"\n\t| \"duplicate-event\";\n\n/** Graph-visible CQRS error fact. These are DATA facts, not protocol ERROR. */\nexport interface CqrsError {\n\treadonly code: CqrsErrorCode;\n\treadonly message: string;\n\treadonly command?: unknown;\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly event?: unknown;\n\treadonly eventType?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsStatus {\n\treadonly state: \"accepted\" | \"rejected\";\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly eventCount: number;\n\treadonly errorCode?: CqrsErrorCode;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsAuditRecord {\n\treadonly seq: number;\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly outcome: \"success\" | \"failure\";\n\treadonly eventIds: readonly string[];\n\treadonly eventTypes: readonly string[];\n\treadonly errorCode?: CqrsErrorCode;\n\treadonly errorMessage?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsDedupeSnapshot {\n\treadonly commandIdsRetained: number;\n\treadonly eventIdsRetained: number;\n\treadonly commandIdsEvicted: number;\n\treadonly eventIdsEvicted: number;\n}\n\nexport interface CqrsCursor {\n\treadonly eventSeq: number;\n\treadonly commandCount: number;\n\treadonly errorCount: number;\n\treadonly auditSeq: number;\n\treadonly dedupe?: CqrsDedupeSnapshot;\n}\n\nexport type CqrsRuntimeFact<T = unknown> =\n\t| { readonly kind: \"event\"; readonly event: CqrsEvent<T> }\n\t| { readonly kind: \"status\"; readonly status: CqrsStatus }\n\t| { readonly kind: \"error\"; readonly error: CqrsError }\n\t| { readonly kind: \"audit\"; readonly audit: CqrsAuditRecord }\n\t| { readonly kind: \"cursor\"; readonly cursor: CqrsCursor };\n\nexport type CqrsCommandHandler<TCommand = unknown, TEvent = unknown> = (\n\tcommand: CqrsCommand<TCommand>,\n) => readonly CqrsEventDraft<TEvent>[];\n\nexport interface CqrsCommandHandlerDefinition<TCommand = unknown, TEvent = unknown> {\n\treadonly type: string;\n\treadonly handle: CqrsCommandHandler<TCommand, TEvent>;\n}\n\nexport interface CqrsOptions<TCommand = unknown, TEvent = unknown> {\n\treadonly name?: string;\n\treadonly handlers?: readonly CqrsCommandHandlerDefinition<TCommand, TEvent>[];\n\treadonly events?: readonly string[];\n\treadonly now?: () => number;\n\t/**\n\t * D142: static command/event duplicate-recognition windows. Omitted means\n\t * exact unbounded dedupe; bounded windows evict oldest ids by insertion order.\n\t */\n\treadonly dedupe?: CqrsDedupePolicy;\n}\n\n/**\n * D151 membership-based duplicate-recognition window for CQRS ids.\n *\n * This is passive CQRS vocabulary, not a shared idempotency reducer engine:\n * commands and events each own their own id membership window.\n */\nexport type CqrsDedupeWindow = \"unbounded\" | { readonly maxEntries: number };\n\nexport interface CqrsDedupePolicy {\n\treadonly commands?: CqrsDedupeWindow;\n\treadonly events?: CqrsDedupeWindow;\n}\n\nexport interface CqrsBundle<TCommand = unknown, TEvent = unknown> {\n\treadonly command: Node<CqrsCommand<TCommand>>;\n\treadonly runtime: Node<CqrsRuntimeFact<TEvent>>;\n\treadonly events: Node<CqrsEvent<TEvent>>;\n\treadonly status: Node<CqrsStatus>;\n\treadonly errors: Node<CqrsError>;\n\treadonly audit: Node<CqrsAuditRecord>;\n\treadonly cursor: Node<CqrsCursor>;\n\tdispatch(command: CqrsCommand<TCommand>): CqrsCommand<TCommand>;\n}\n\ninterface CqrsRuntimeState {\n\teventSeq: number;\n\tcommandCount: number;\n\terrorCount: number;\n\tauditSeq: number;\n\tseenCommandIds: string[];\n\tseenEventIds: string[];\n\tcommandDedupeEvicted?: number;\n\teventDedupeEvicted?: number;\n}\n\ninterface HandlerRecord {\n\treadonly type: string;\n\treadonly handle: CqrsCommandHandler<unknown, unknown>;\n}\n\ninterface NormalizedCqrsDedupePolicy {\n\treadonly commandMaxEntries?: number;\n\treadonly eventMaxEntries?: number;\n\treadonly bounded: boolean;\n}\n\n/** Convenience helper for declaring typed command handlers in a CQRS bundle. */\nexport function cqrsCommandHandler<TCommand = unknown, TEvent = unknown>(\n\ttype: string,\n\thandle: CqrsCommandHandler<TCommand, TEvent>,\n): CqrsCommandHandlerDefinition<TCommand, TEvent> {\n\tif (type.length === 0) throw new Error(\"cqrsCommandHandler: type must be non-empty\");\n\treturn { type, handle };\n}\n\n/**\n * Create a graph-visible CQRS bundle. Command dispatch is only DATA on the\n * returned `command` node; all derived facts flow through declared graph deps.\n */\nexport function cqrs<TCommand = unknown, TEvent = unknown>(\n\tgraph: Graph,\n\topts: CqrsOptions<TCommand, TEvent> = {},\n): CqrsBundle<TCommand, TEvent> {\n\tconst name = opts.name ?? \"cqrs\";\n\tconst handlers = normalizeHandlers(opts.handlers ?? []);\n\tconst knownEvents =\n\t\topts.events === undefined ? undefined : new Set(uniqueNames(opts.events, \"cqrs.events\"));\n\tconst now = opts.now ?? Date.now;\n\tconst dedupe = normalizeDedupePolicy(opts.dedupe);\n\tconst command = graph.node<CqrsCommand<TCommand>>([], null, {\n\t\tname: `${name}/command`,\n\t\tfactory: \"cqrsCommand\",\n\t\tcompleteWhenDepsComplete: false,\n\t\terrorWhenDepsError: false,\n\t});\n\tconst runtime = graph.node<CqrsRuntimeFact<TEvent>>(\n\t\t[command],\n\t\t(ctx) => {\n\t\t\tconst state =\n\t\t\t\tctx.state.get<CqrsRuntimeState>() ??\n\t\t\t\t({\n\t\t\t\t\teventSeq: 0,\n\t\t\t\t\tcommandCount: 0,\n\t\t\t\t\terrorCount: 0,\n\t\t\t\t\tauditSeq: 0,\n\t\t\t\t\tseenCommandIds: [],\n\t\t\t\t\tseenEventIds: [],\n\t\t\t\t} satisfies CqrsRuntimeState);\n\t\t\tctx.state.persist(true);\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\treduceCommandFact(raw, state, handlers, knownEvents, now, dedupe, (fact) =>\n\t\t\t\t\tctx.down([[\"DATA\", fact as CqrsRuntimeFact<TEvent>]]),\n\t\t\t\t);\n\t\t\t}\n\t\t\tctx.state.set(state);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/runtime`,\n\t\t\tfactory: \"cqrsRuntime\",\n\t\t\tmeta: {\n\t\t\t\tcommandTypes: [...handlers.keys()],\n\t\t\t\teventTypes: knownEvents ? [...knownEvents] : \"open\",\n\t\t\t\tdedupe: dedupeMeta(dedupe),\n\t\t\t},\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst events = runtimeProjection<CqrsEvent<TEvent>, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"event\",\n\t\t`${name}/events`,\n\t\t\"cqrsEvents\",\n\t\t(fact) => (fact.kind === \"event\" ? fact.event : undefined),\n\t);\n\tconst status = runtimeProjection<CqrsStatus, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"status\",\n\t\t`${name}/status`,\n\t\t\"cqrsStatus\",\n\t\t(fact) => (fact.kind === \"status\" ? fact.status : undefined),\n\t);\n\tconst errors = runtimeProjection<CqrsError, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"error\",\n\t\t`${name}/errors`,\n\t\t\"cqrsErrors\",\n\t\t(fact) => (fact.kind === \"error\" ? fact.error : undefined),\n\t);\n\tconst audit = runtimeProjection<CqrsAuditRecord, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"audit\",\n\t\t`${name}/audit`,\n\t\t\"cqrsAudit\",\n\t\t(fact) => (fact.kind === \"audit\" ? fact.audit : undefined),\n\t);\n\tconst cursor = runtimeProjection<CqrsCursor, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"cursor\",\n\t\t`${name}/cursor`,\n\t\t\"cqrsCursor\",\n\t\t(fact) => (fact.kind === \"cursor\" ? fact.cursor : undefined),\n\t);\n\tgraph.retain(runtime, { reason: `${name}.cqrs.runtime` });\n\tgraph.retain(events, { reason: `${name}.cqrs.events` });\n\tgraph.retain(status, { reason: `${name}.cqrs.status` });\n\tgraph.retain(errors, { reason: `${name}.cqrs.errors` });\n\tgraph.retain(audit, { reason: `${name}.cqrs.audit` });\n\tgraph.retain(cursor, { reason: `${name}.cqrs.cursor` });\n\treturn {\n\t\tcommand,\n\t\truntime,\n\t\tevents,\n\t\tstatus,\n\t\terrors,\n\t\taudit,\n\t\tcursor,\n\t\tdispatch(commandFact) {\n\t\t\tcommand.down([[\"DATA\", commandFact]]);\n\t\t\treturn commandFact;\n\t\t},\n\t};\n}\n\nexport interface CqrsProjectionOptions<TState, TEvent = unknown> {\n\treadonly name?: string;\n\treadonly events?: readonly string[];\n\treadonly initial: TState;\n\treadonly reducer: (state: TState, event: CqrsEvent<TEvent>) => TState;\n}\n\nexport type CqrsProjectionFrame<TState> =\n\t| {\n\t\t\treadonly kind: \"value\";\n\t\t\treadonly state: TState;\n\t\t\treadonly eventId: string;\n\t\t\treadonly cursor: CqrsCursor;\n\t }\n\t| { readonly kind: \"error\"; readonly error: CqrsProjectionError };\n\nexport interface CqrsProjectionError {\n\treadonly code: \"projection-threw\";\n\treadonly message: string;\n\treadonly eventId: string;\n\treadonly eventType: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsProjectionStatus {\n\treadonly state: \"updated\" | \"errored\";\n\treadonly eventId: string;\n\treadonly eventType?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsProjection<TState> {\n\treadonly frames: Node<CqrsProjectionFrame<TState>>;\n\treadonly value: Node<TState>;\n\treadonly status: Node<CqrsProjectionStatus>;\n\treadonly errors: Node<CqrsProjectionError>;\n}\n\n/**\n * Derive a projection from declared CQRS event deps. Reducer failures become\n * graph-visible error DATA facts on the returned `errors` node.\n */\nexport function cqrsProjection<TState, TEvent = unknown>(\n\tgraph: Graph,\n\tsource: Pick<CqrsBundle<unknown, TEvent>, \"events\">,\n\topts: CqrsProjectionOptions<TState, TEvent>,\n): CqrsProjection<TState> {\n\tconst name = opts.name ?? \"cqrsProjection\";\n\tconst eventFilter =\n\t\topts.events === undefined\n\t\t\t? undefined\n\t\t\t: new Set(uniqueNames(opts.events, \"cqrsProjection.events\"));\n\tconst frames = graph.node<CqrsProjectionFrame<TState>>(\n\t\t[source.events],\n\t\t(ctx) => {\n\t\t\tconst state = ctx.state.get<{ value: TState }>() ?? { value: opts.initial };\n\t\t\tctx.state.persist(true);\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst event = raw as CqrsEvent<TEvent>;\n\t\t\t\tif (eventFilter !== undefined && !eventFilter.has(event.type)) continue;\n\t\t\t\ttry {\n\t\t\t\t\tstate.value = opts.reducer(state.value, event);\n\t\t\t\t\tctx.state.set(state);\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"value\",\n\t\t\t\t\t\t\t\tstate: state.value,\n\t\t\t\t\t\t\t\teventId: event.id,\n\t\t\t\t\t\t\t\tcursor: event.runtimeCursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionFrame<TState>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t} catch (error) {\n\t\t\t\t\trethrowGraphRuntimeInvariant(error);\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"error\",\n\t\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\t\tcode: \"projection-threw\",\n\t\t\t\t\t\t\t\t\tmessage: errorMessage(error),\n\t\t\t\t\t\t\t\t\teventId: event.id,\n\t\t\t\t\t\t\t\t\teventType: event.type,\n\t\t\t\t\t\t\t\t\tcursor: event.runtimeCursor,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t} satisfies CqrsProjectionFrame<TState>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory: \"cqrsProjection\",\n\t\t\tmeta: { eventTypes: eventFilter ? [...eventFilter] : \"open\" },\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst value = graph.node<TState>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"value\") ctx.down([[\"DATA\", typed.state]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/value`,\n\t\t\tfactory: \"cqrsProjectionValue\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst errors = graph.node<CqrsProjectionError>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"error\") ctx.down([[\"DATA\", typed.error]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/errors`,\n\t\t\tfactory: \"cqrsProjectionErrors\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst status = graph.node<CqrsProjectionStatus>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"value\") {\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tstate: \"updated\",\n\t\t\t\t\t\t\t\teventId: typed.eventId,\n\t\t\t\t\t\t\t\tcursor: typed.cursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionStatus,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t} else {\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tstate: \"errored\",\n\t\t\t\t\t\t\t\teventId: typed.error.eventId,\n\t\t\t\t\t\t\t\teventType: typed.error.eventType,\n\t\t\t\t\t\t\t\tcursor: typed.error.cursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionStatus,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/status`,\n\t\t\tfactory: \"cqrsProjectionStatus\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tgraph.retain(frames, { reason: `${name}.cqrsProjection.frames` });\n\tgraph.retain(value, { reason: `${name}.cqrsProjection.value` });\n\tgraph.retain(status, { reason: `${name}.cqrsProjection.status` });\n\tgraph.retain(errors, { reason: `${name}.cqrsProjection.errors` });\n\treturn { frames, value, status, errors };\n}\n\nfunction normalizeHandlers<TCommand, TEvent>(\n\tdefinitions: readonly CqrsCommandHandlerDefinition<TCommand, TEvent>[],\n): ReadonlyMap<string, HandlerRecord> {\n\tconst handlers = new Map<string, HandlerRecord>();\n\tfor (const definition of definitions) {\n\t\tif (definition.type.length === 0) throw new Error(\"cqrs: handler type must be non-empty\");\n\t\tif (handlers.has(definition.type))\n\t\t\tthrow new Error(`cqrs: duplicate handler '${definition.type}'`);\n\t\thandlers.set(definition.type, {\n\t\t\ttype: definition.type,\n\t\t\thandle: definition.handle as CqrsCommandHandler<unknown, unknown>,\n\t\t});\n\t}\n\treturn handlers;\n}\n\nfunction reduceCommandFact<TEvent>(\n\traw: unknown,\n\tstate: CqrsRuntimeState,\n\thandlers: ReadonlyMap<string, HandlerRecord>,\n\tknownEvents: ReadonlySet<string> | undefined,\n\tnow: () => number,\n\tdedupe: NormalizedCqrsDedupePolicy,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n): void {\n\tstate.commandCount += 1;\n\tconst parsed = parseCommand(raw);\n\tif (typeof parsed === \"string\") {\n\t\temitFailure(state, emit, raw, undefined, \"malformed-command\", parsed, dedupe);\n\t\treturn;\n\t}\n\tconst command = parsed as CqrsCommand<unknown>;\n\tif (state.seenCommandIds.includes(command.id)) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"duplicate-command\",\n\t\t\t`cqrs: duplicate command '${command.id}'`,\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tstate.seenCommandIds.push(command.id);\n\ttrimDedupeWindow(state.seenCommandIds, dedupe.commandMaxEntries, (evicted) => {\n\t\tstate.commandDedupeEvicted = (state.commandDedupeEvicted ?? 0) + evicted;\n\t});\n\tconst handler = handlers.get(command.type);\n\tif (handler === undefined) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"unknown-command\",\n\t\t\t`cqrs: unknown command '${command.type}'`,\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tlet drafts: readonly CqrsEventDraft<unknown>[];\n\ttry {\n\t\tdrafts = handler.handle(command);\n\t} catch (error) {\n\t\trethrowGraphRuntimeInvariant(error);\n\t\temitFailure(state, emit, command, command, \"handler-threw\", errorMessage(error), dedupe);\n\t\treturn;\n\t}\n\tif (!Array.isArray(drafts)) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"malformed-event\",\n\t\t\t\"cqrs: command handler must return an event draft array\",\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tconst prepared = prepareEvents(command, drafts, state, knownEvents);\n\tif (typeof prepared === \"string\") {\n\t\temitFailure(state, emit, command, command, preparedCode(prepared), prepared, dedupe);\n\t\treturn;\n\t}\n\tconst timestampMs = readTimestampMs(now);\n\tif (typeof timestampMs === \"string\") {\n\t\temitFailure(state, emit, command, command, \"clock-threw\", timestampMs, dedupe);\n\t\treturn;\n\t}\n\tconst events: CqrsEvent<unknown>[] = [];\n\tfor (const draft of prepared) {\n\t\tstate.eventSeq += 1;\n\t\tstate.seenEventIds.push(draft.id);\n\t\ttrimDedupeWindow(state.seenEventIds, dedupe.eventMaxEntries, (evicted) => {\n\t\t\tstate.eventDedupeEvicted = (state.eventDedupeEvicted ?? 0) + evicted;\n\t\t});\n\t\tconst runtimeCursor = cursorOf(state, dedupe);\n\t\tevents.push({\n\t\t\tid: draft.id,\n\t\t\ttype: draft.type,\n\t\t\tseq: state.eventSeq,\n\t\t\tcursor: state.eventSeq,\n\t\t\truntimeCursor,\n\t\t\tcommandId: command.id,\n\t\t\tcommandType: command.type,\n\t\t\tpayload: draft.payload,\n\t\t\ttimestampMs,\n\t\t\t...(draft.aggregateId === undefined ? {} : { aggregateId: draft.aggregateId }),\n\t\t\t...(draft.correlationId === undefined ? {} : { correlationId: draft.correlationId }),\n\t\t\t...(draft.causationId === undefined ? {} : { causationId: draft.causationId }),\n\t\t\t...(draft.metadata === undefined ? {} : { metadata: draft.metadata }),\n\t\t});\n\t}\n\tfor (const event of events) emit({ kind: \"event\", event: event as CqrsEvent<TEvent> });\n\temitStatus(state, emit, command, \"accepted\", events.length, dedupe);\n\temitAudit(state, emit, command, \"success\", events, undefined, undefined, dedupe);\n\temit({ kind: \"cursor\", cursor: cursorOf(state, dedupe) });\n}\n\nfunction parseCommand(value: unknown): CqrsCommand<unknown> | string {\n\tif (!isObjectRecord(value)) return \"cqrs: command fact must be an object\";\n\tif (typeof value.id !== \"string\" || value.id.length === 0) {\n\t\treturn \"cqrs: command id must be a non-empty string\";\n\t}\n\tif (typeof value.type !== \"string\" || value.type.length === 0) {\n\t\treturn \"cqrs: command type must be a non-empty string\";\n\t}\n\treturn {\n\t\tid: value.id,\n\t\ttype: value.type,\n\t\tpayload: value.payload,\n\t\t...(typeof value.aggregateId === \"string\" ? { aggregateId: value.aggregateId } : {}),\n\t\t...(typeof value.correlationId === \"string\" ? { correlationId: value.correlationId } : {}),\n\t\t...(typeof value.causationId === \"string\" ? { causationId: value.causationId } : {}),\n\t\t...(isObjectRecord(value.metadata) ? { metadata: value.metadata } : {}),\n\t};\n}\n\nfunction prepareEvents(\n\tcommand: CqrsCommand<unknown>,\n\tdrafts: readonly CqrsEventDraft<unknown>[],\n\tstate: CqrsRuntimeState,\n\tknownEvents: ReadonlySet<string> | undefined,\n): Array<CqrsEventDraft<unknown> & { readonly id: string }> | string {\n\tconst seenInCommand = new Set<string>();\n\tconst prepared: Array<CqrsEventDraft<unknown> & { readonly id: string }> = [];\n\tfor (let i = 0; i < drafts.length; i += 1) {\n\t\tconst draft = drafts[i];\n\t\tif (!isObjectRecord(draft) || typeof draft.type !== \"string\" || draft.type.length === 0) {\n\t\t\treturn \"cqrs: event draft must have a non-empty type\";\n\t\t}\n\t\tif (knownEvents !== undefined && !knownEvents.has(draft.type)) {\n\t\t\treturn `cqrs: unknown event '${draft.type}'`;\n\t\t}\n\t\tconst id =\n\t\t\ttypeof draft.id === \"string\" && draft.id.length > 0 ? draft.id : `${command.id}:${i + 1}`;\n\t\tif (state.seenEventIds.includes(id) || seenInCommand.has(id)) {\n\t\t\treturn `cqrs: duplicate event '${id}'`;\n\t\t}\n\t\tseenInCommand.add(id);\n\t\tprepared.push({\n\t\t\tid,\n\t\t\ttype: draft.type,\n\t\t\tpayload: draft.payload,\n\t\t\t...(typeof draft.aggregateId === \"string\" ? { aggregateId: draft.aggregateId } : {}),\n\t\t\t...(typeof draft.correlationId === \"string\" ? { correlationId: draft.correlationId } : {}),\n\t\t\t...(typeof draft.causationId === \"string\" ? { causationId: draft.causationId } : {}),\n\t\t\t...(isObjectRecord(draft.metadata) ? { metadata: draft.metadata } : {}),\n\t\t});\n\t}\n\treturn prepared;\n}\n\nfunction preparedCode(message: string): CqrsErrorCode {\n\tif (message.includes(\"unknown event\")) return \"unknown-event\";\n\tif (message.includes(\"duplicate event\")) return \"duplicate-event\";\n\treturn \"malformed-event\";\n}\n\nfunction rethrowGraphRuntimeInvariant(error: unknown): void {\n\tconst message = errorMessage(error);\n\tif (\n\t\tmessage.includes(\"R-reentrancy\") ||\n\t\tmessage.includes(\"R-rewire\") ||\n\t\tmessage.includes(\"R-graph-domain\") ||\n\t\tmessage.includes(\"D37\") ||\n\t\tmessage.includes(\"D22\") ||\n\t\tmessage.includes(\"different graph\") ||\n\t\tmessage.includes(\"cross-graph\") ||\n\t\tmessage.includes(\"wire bridge\") ||\n\t\tmessage.includes(\"mid-fn topology mutation\") ||\n\t\tmessage.includes(\"reentrant dep mutation\") ||\n\t\tmessage.includes(\"feedback cycle\")\n\t) {\n\t\tthrow error;\n\t}\n}\n\nfunction emitFailure<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\traw: unknown,\n\tcommand: CqrsCommand<unknown> | undefined,\n\tcode: CqrsErrorCode,\n\tmessage: string,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\tstate.errorCount += 1;\n\tconst cursor = cursorOf(state, dedupe);\n\tconst error: CqrsError = {\n\t\tcode,\n\t\tmessage,\n\t\tcommand: raw,\n\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\tcursor,\n\t};\n\temit({ kind: \"error\", error });\n\temit({\n\t\tkind: \"status\",\n\t\tstatus: {\n\t\t\tstate: \"rejected\",\n\t\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\t\teventCount: 0,\n\t\t\terrorCode: code,\n\t\t\tcursor,\n\t\t},\n\t});\n\temitAudit(state, emit, command, \"failure\", [], code, message, dedupe);\n\temit({ kind: \"cursor\", cursor: cursorOf(state, dedupe) });\n}\n\nfunction emitStatus<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\tcommand: CqrsCommand<unknown>,\n\tstatusState: \"accepted\" | \"rejected\",\n\teventCount: number,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\temit({\n\t\tkind: \"status\",\n\t\tstatus: {\n\t\t\tstate: statusState,\n\t\t\tcommandId: command.id,\n\t\t\tcommandType: command.type,\n\t\t\teventCount,\n\t\t\tcursor: cursorOf(state, dedupe),\n\t\t},\n\t});\n}\n\nfunction emitAudit<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\tcommand: CqrsCommand<unknown> | undefined,\n\toutcome: \"success\" | \"failure\",\n\tevents: readonly CqrsEvent<unknown>[],\n\terrorCode: CqrsErrorCode | undefined,\n\terrorMessageValue: string | undefined,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\tstate.auditSeq += 1;\n\temit({\n\t\tkind: \"audit\",\n\t\taudit: {\n\t\t\tseq: state.auditSeq,\n\t\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\t\toutcome,\n\t\t\teventIds: Object.freeze(events.map((event) => event.id)),\n\t\t\teventTypes: Object.freeze(events.map((event) => event.type)),\n\t\t\t...(errorCode === undefined ? {} : { errorCode }),\n\t\t\t...(errorMessageValue === undefined ? {} : { errorMessage: errorMessageValue }),\n\t\t\tcursor: cursorOf(state, dedupe),\n\t\t},\n\t});\n}\n\nfunction runtimeProjection<TOut, TEvent>(\n\tgraph: Graph,\n\truntime: Node<CqrsRuntimeFact<TEvent>>,\n\tkind: CqrsRuntimeFact<TEvent>[\"kind\"],\n\tname: string,\n\tfactory: string,\n\tselect: (fact: CqrsRuntimeFact<TEvent>) => TOut | undefined,\n): Node<TOut> {\n\treturn graph.node<TOut>(\n\t\t[runtime],\n\t\t(ctx) => {\n\t\t\tfor (const fact of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = fact as CqrsRuntimeFact<TEvent>;\n\t\t\t\tif (typed.kind !== kind) continue;\n\t\t\t\tconst selected = select(typed);\n\t\t\t\tif (selected !== undefined) ctx.down([[\"DATA\", selected]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n}\n\nfunction cursorOf(state: CqrsRuntimeState, dedupe: NormalizedCqrsDedupePolicy): CqrsCursor {\n\treturn {\n\t\teventSeq: state.eventSeq,\n\t\tcommandCount: state.commandCount,\n\t\terrorCount: state.errorCount,\n\t\tauditSeq: state.auditSeq,\n\t\t...(dedupe.bounded\n\t\t\t? {\n\t\t\t\t\tdedupe: {\n\t\t\t\t\t\tcommandIdsRetained: state.seenCommandIds.length,\n\t\t\t\t\t\teventIdsRetained: state.seenEventIds.length,\n\t\t\t\t\t\tcommandIdsEvicted: state.commandDedupeEvicted ?? 0,\n\t\t\t\t\t\teventIdsEvicted: state.eventDedupeEvicted ?? 0,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n\nfunction normalizeDedupePolicy(policy: CqrsDedupePolicy | undefined): NormalizedCqrsDedupePolicy {\n\tconst commandMaxEntries = normalizeDedupeWindow(policy?.commands, \"cqrs.dedupe.commands\");\n\tconst eventMaxEntries = normalizeDedupeWindow(policy?.events, \"cqrs.dedupe.events\");\n\treturn {\n\t\t...(commandMaxEntries === undefined ? {} : { commandMaxEntries }),\n\t\t...(eventMaxEntries === undefined ? {} : { eventMaxEntries }),\n\t\tbounded: commandMaxEntries !== undefined || eventMaxEntries !== undefined,\n\t};\n}\n\nfunction normalizeDedupeWindow(\n\twindow: CqrsDedupeWindow | undefined,\n\towner: string,\n): number | undefined {\n\tif (window === undefined || window === \"unbounded\") return undefined;\n\tif (!Number.isInteger(window.maxEntries) || window.maxEntries < 0) {\n\t\tthrow new RangeError(`${owner}: maxEntries must be a non-negative integer`);\n\t}\n\treturn window.maxEntries;\n}\n\nfunction dedupeMeta(dedupe: NormalizedCqrsDedupePolicy): unknown {\n\tif (!dedupe.bounded) return \"unbounded\";\n\treturn {\n\t\tcommands:\n\t\t\tdedupe.commandMaxEntries === undefined\n\t\t\t\t? \"unbounded\"\n\t\t\t\t: { maxEntries: dedupe.commandMaxEntries },\n\t\tevents:\n\t\t\tdedupe.eventMaxEntries === undefined ? \"unbounded\" : { maxEntries: dedupe.eventMaxEntries },\n\t};\n}\n\nfunction trimDedupeWindow(\n\tids: string[],\n\tmaxEntries: number | undefined,\n\tonEvicted: (evicted: number) => void,\n): void {\n\tif (maxEntries === undefined || ids.length <= maxEntries) return;\n\tconst evicted = ids.length - maxEntries;\n\tids.splice(0, evicted);\n\tonEvicted(evicted);\n}\n\nfunction readTimestampMs(now: () => number): number | string {\n\ttry {\n\t\tconst timestampMs = now();\n\t\treturn Number.isFinite(timestampMs) ? timestampMs : \"cqrs: now() must return a finite number\";\n\t} catch (error) {\n\t\treturn `cqrs: now() threw: ${errorMessage(error)}`;\n\t}\n}\n\nfunction uniqueNames(values: readonly string[], owner: string): readonly string[] {\n\tconst unique = [...new Set(values)];\n\tif (unique.length !== values.length) throw new Error(`${owner}: duplicate value`);\n\tfor (const value of unique) {\n\t\tif (value.length === 0) throw new Error(`${owner}: values must be non-empty`);\n\t}\n\treturn Object.freeze(unique);\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction isObjectRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":";;;;;;AA0LO,SAAS,mBACf,MACA,QACiD;AACjD,MAAI,KAAK,WAAW,EAAG,OAAM,IAAI,MAAM,4CAA4C;AACnF,SAAO,EAAE,MAAM,OAAO;AACvB;AAMO,SAAS,KACf,OACA,OAAsC,CAAC,GACR;AAC/B,QAAM,OAAO,KAAK,QAAQ;AAC1B,QAAM,WAAW,kBAAkB,KAAK,YAAY,CAAC,CAAC;AACtD,QAAM,cACL,KAAK,WAAW,SAAY,SAAY,IAAI,IAAI,YAAY,KAAK,QAAQ,aAAa,CAAC;AACxF,QAAM,MAAM,KAAK,OAAO,KAAK;AAC7B,QAAM,SAAS,sBAAsB,KAAK,MAAM;AAChD,QAAM,UAAU,MAAM,KAA4B,CAAC,GAAG,MAAM;AAAA,IAC3D,MAAM,GAAG,IAAI;AAAA,IACb,SAAS;AAAA,IACT,0BAA0B;AAAA,IAC1B,oBAAoB;AAAA,EACrB,CAAC;AACD,QAAM,UAAU,MAAM;AAAA,I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AAS,OAAO;AACf,WAAO,sBAAsB,aAAa,KAAK,CAAC;AAAA,EACjD;AACD;AAEA,SAAS,YAAY,QAA2B,OAAkC;AACjF,QAAM,SAAS,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC;AAClC,MAAI,OAAO,WAAW,OAAO,OAAQ,OAAM,IAAI,MAAM,GAAG,KAAK,mBAAmB;AAChF,aAAW,SAAS,QAAQ;AAC3B,QAAI,MAAM,WAAW,EAAG,OAAM,IAAI,MAAM,GAAG,KAAK,4BAA4B;AAAA,EAC7E;AACA,SAAO,OAAO,OAAO,MAAM;AAC5B;AAEA,SAAS,aAAa,OAAwB;AAC7C,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC7D;AAEA,SAAS,eAAe,OAAkD;AACzE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC3E;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/cqrs/index.ts"],"sourcesContent":["/**\n * Reusable application-infrastructure CQRS helpers (B63 / D125 / D129).\n *\n * The bundle is graph-visible facts over ordinary nodes: command DATA facts\n * enter through a graph-owned command node, command handlers run inside the\n * dispatched runtime node, and events/status/errors/audit/cursor are derived\n * facts. It is not a Graph subclass, hidden EventEmitter, saga runtime, or\n * storage-owned restore surface.\n */\n\nimport { depBatch } from \"../ctx/types.js\";\nimport type { Graph } from \"../graph/graph.js\";\nimport type { Node } from \"../node/node.js\";\n\n/** Command fact accepted by a CQRS bundle. */\nexport interface CqrsCommand<T = unknown> {\n\treadonly id: string;\n\treadonly type: string;\n\treadonly payload: T;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\n/** Event draft returned by a command handler before the runtime orders it. */\nexport interface CqrsEventDraft<T = unknown> {\n\treadonly id?: string;\n\treadonly type: string;\n\treadonly payload: T;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\n/** Ordered event fact emitted by the CQRS runtime node. */\nexport interface CqrsEvent<T = unknown> {\n\treadonly id: string;\n\treadonly type: string;\n\treadonly seq: number;\n\treadonly cursor: number;\n\treadonly runtimeCursor: CqrsCursor;\n\treadonly commandId: string;\n\treadonly commandType: string;\n\treadonly payload: T;\n\treadonly timestampMs: number;\n\treadonly aggregateId?: string;\n\treadonly correlationId?: string;\n\treadonly causationId?: string;\n\treadonly metadata?: Record<string, unknown>;\n}\n\nexport type CqrsErrorCode =\n\t| \"malformed-command\"\n\t| \"duplicate-command\"\n\t| \"unknown-command\"\n\t| \"handler-threw\"\n\t| \"clock-threw\"\n\t| \"malformed-event\"\n\t| \"unknown-event\"\n\t| \"duplicate-event\";\n\n/** Graph-visible CQRS error fact. These are DATA facts, not protocol ERROR. */\nexport interface CqrsError {\n\treadonly code: CqrsErrorCode;\n\treadonly message: string;\n\treadonly command?: unknown;\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly event?: unknown;\n\treadonly eventType?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsStatus {\n\treadonly state: \"accepted\" | \"rejected\";\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly eventCount: number;\n\treadonly errorCode?: CqrsErrorCode;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsAuditRecord {\n\treadonly seq: number;\n\treadonly commandId?: string;\n\treadonly commandType?: string;\n\treadonly outcome: \"success\" | \"failure\";\n\treadonly eventIds: readonly string[];\n\treadonly eventTypes: readonly string[];\n\treadonly errorCode?: CqrsErrorCode;\n\treadonly errorMessage?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsDedupeSnapshot {\n\treadonly commandIdsRetained: number;\n\treadonly eventIdsRetained: number;\n\treadonly commandIdsEvicted: number;\n\treadonly eventIdsEvicted: number;\n}\n\nexport interface CqrsCursor {\n\treadonly eventSeq: number;\n\treadonly commandCount: number;\n\treadonly errorCount: number;\n\treadonly auditSeq: number;\n\treadonly dedupe?: CqrsDedupeSnapshot;\n}\n\nexport type CqrsRuntimeFact<T = unknown> =\n\t| { readonly kind: \"event\"; readonly event: CqrsEvent<T> }\n\t| { readonly kind: \"status\"; readonly status: CqrsStatus }\n\t| { readonly kind: \"error\"; readonly error: CqrsError }\n\t| { readonly kind: \"audit\"; readonly audit: CqrsAuditRecord }\n\t| { readonly kind: \"cursor\"; readonly cursor: CqrsCursor };\n\nexport type CqrsCommandHandler<TCommand = unknown, TEvent = unknown> = (\n\tcommand: CqrsCommand<TCommand>,\n) => readonly CqrsEventDraft<TEvent>[];\n\nexport interface CqrsCommandHandlerDefinition<TCommand = unknown, TEvent = unknown> {\n\treadonly type: string;\n\treadonly handle: CqrsCommandHandler<TCommand, TEvent>;\n}\n\nexport interface CqrsOptions<TCommand = unknown, TEvent = unknown> {\n\treadonly name?: string;\n\treadonly handlers?: readonly CqrsCommandHandlerDefinition<TCommand, TEvent>[];\n\treadonly events?: readonly string[];\n\treadonly now?: () => number;\n\t/**\n\t * D142: static command/event duplicate-recognition windows. Omitted means\n\t * exact unbounded dedupe; bounded windows evict oldest ids by insertion order.\n\t */\n\treadonly dedupe?: CqrsDedupePolicy;\n}\n\n/**\n * D151 membership-based duplicate-recognition window for CQRS ids.\n *\n * This is passive CQRS vocabulary, not a shared idempotency reducer engine:\n * commands and events each own their own id membership window.\n */\nexport type CqrsDedupeWindow = \"unbounded\" | { readonly maxEntries: number };\n\nexport interface CqrsDedupePolicy {\n\treadonly commands?: CqrsDedupeWindow;\n\treadonly events?: CqrsDedupeWindow;\n}\n\nexport interface CqrsBundle<TCommand = unknown, TEvent = unknown> {\n\treadonly command: Node<CqrsCommand<TCommand>>;\n\treadonly runtime: Node<CqrsRuntimeFact<TEvent>>;\n\treadonly events: Node<CqrsEvent<TEvent>>;\n\treadonly status: Node<CqrsStatus>;\n\treadonly errors: Node<CqrsError>;\n\treadonly audit: Node<CqrsAuditRecord>;\n\treadonly cursor: Node<CqrsCursor>;\n\tdispatch(command: CqrsCommand<TCommand>): CqrsCommand<TCommand>;\n}\n\ninterface CqrsRuntimeState {\n\teventSeq: number;\n\tcommandCount: number;\n\terrorCount: number;\n\tauditSeq: number;\n\tseenCommandIds: string[];\n\tseenEventIds: string[];\n\tcommandDedupeEvicted?: number;\n\teventDedupeEvicted?: number;\n}\n\ninterface HandlerRecord {\n\treadonly type: string;\n\treadonly handle: CqrsCommandHandler<unknown, unknown>;\n}\n\ninterface NormalizedCqrsDedupePolicy {\n\treadonly commandMaxEntries?: number;\n\treadonly eventMaxEntries?: number;\n\treadonly bounded: boolean;\n}\n\n/** Convenience helper for declaring typed command handlers in a CQRS bundle. */\nexport function cqrsCommandHandler<TCommand = unknown, TEvent = unknown>(\n\ttype: string,\n\thandle: CqrsCommandHandler<TCommand, TEvent>,\n): CqrsCommandHandlerDefinition<TCommand, TEvent> {\n\tif (type.length === 0) throw new Error(\"cqrsCommandHandler: type must be non-empty\");\n\treturn { type, handle };\n}\n\n/**\n * Create a graph-visible CQRS bundle. Command dispatch is only DATA on the\n * returned `command` node; all derived facts flow through declared graph deps.\n */\nexport function cqrs<TCommand = unknown, TEvent = unknown>(\n\tgraph: Graph,\n\topts: CqrsOptions<TCommand, TEvent> = {},\n): CqrsBundle<TCommand, TEvent> {\n\tconst name = opts.name ?? \"cqrs\";\n\tconst handlers = normalizeHandlers(opts.handlers ?? []);\n\tconst knownEvents =\n\t\topts.events === undefined ? undefined : new Set(uniqueNames(opts.events, \"cqrs.events\"));\n\tconst now = opts.now ?? Date.now;\n\tconst dedupe = normalizeDedupePolicy(opts.dedupe);\n\tconst command = graph.node<CqrsCommand<TCommand>>([], null, {\n\t\tname: `${name}/command`,\n\t\tfactory: \"cqrsCommand\",\n\t\tcompleteWhenDepsComplete: false,\n\t\terrorWhenDepsError: false,\n\t});\n\tconst runtime = graph.node<CqrsRuntimeFact<TEvent>>(\n\t\t[command],\n\t\t(ctx) => {\n\t\t\tconst state =\n\t\t\t\tctx.state.get<CqrsRuntimeState>() ??\n\t\t\t\t({\n\t\t\t\t\teventSeq: 0,\n\t\t\t\t\tcommandCount: 0,\n\t\t\t\t\terrorCount: 0,\n\t\t\t\t\tauditSeq: 0,\n\t\t\t\t\tseenCommandIds: [],\n\t\t\t\t\tseenEventIds: [],\n\t\t\t\t} satisfies CqrsRuntimeState);\n\t\t\tctx.state.persist(true);\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\treduceCommandFact(raw, state, handlers, knownEvents, now, dedupe, (fact) =>\n\t\t\t\t\tctx.down([[\"DATA\", fact as CqrsRuntimeFact<TEvent>]]),\n\t\t\t\t);\n\t\t\t}\n\t\t\tctx.state.set(state);\n\t\t},\n\t\t{\n\t\t\tname: `${name}/runtime`,\n\t\t\tfactory: \"cqrsRuntime\",\n\t\t\tmeta: {\n\t\t\t\tcommandTypes: [...handlers.keys()],\n\t\t\t\teventTypes: knownEvents ? [...knownEvents] : \"open\",\n\t\t\t\tdedupe: dedupeMeta(dedupe),\n\t\t\t},\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst events = runtimeProjection<CqrsEvent<TEvent>, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"event\",\n\t\t`${name}/events`,\n\t\t\"cqrsEvents\",\n\t\t(fact) => (fact.kind === \"event\" ? fact.event : undefined),\n\t);\n\tconst status = runtimeProjection<CqrsStatus, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"status\",\n\t\t`${name}/status`,\n\t\t\"cqrsStatus\",\n\t\t(fact) => (fact.kind === \"status\" ? fact.status : undefined),\n\t);\n\tconst errors = runtimeProjection<CqrsError, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"error\",\n\t\t`${name}/errors`,\n\t\t\"cqrsErrors\",\n\t\t(fact) => (fact.kind === \"error\" ? fact.error : undefined),\n\t);\n\tconst audit = runtimeProjection<CqrsAuditRecord, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"audit\",\n\t\t`${name}/audit`,\n\t\t\"cqrsAudit\",\n\t\t(fact) => (fact.kind === \"audit\" ? fact.audit : undefined),\n\t);\n\tconst cursor = runtimeProjection<CqrsCursor, TEvent>(\n\t\tgraph,\n\t\truntime,\n\t\t\"cursor\",\n\t\t`${name}/cursor`,\n\t\t\"cqrsCursor\",\n\t\t(fact) => (fact.kind === \"cursor\" ? fact.cursor : undefined),\n\t);\n\tgraph.retain(runtime, { reason: `${name}.cqrs.runtime` });\n\tgraph.retain(events, { reason: `${name}.cqrs.events` });\n\tgraph.retain(status, { reason: `${name}.cqrs.status` });\n\tgraph.retain(errors, { reason: `${name}.cqrs.errors` });\n\tgraph.retain(audit, { reason: `${name}.cqrs.audit` });\n\tgraph.retain(cursor, { reason: `${name}.cqrs.cursor` });\n\treturn {\n\t\tcommand,\n\t\truntime,\n\t\tevents,\n\t\tstatus,\n\t\terrors,\n\t\taudit,\n\t\tcursor,\n\t\tdispatch(commandFact) {\n\t\t\tcommand.down([[\"DATA\", commandFact]]);\n\t\t\treturn commandFact;\n\t\t},\n\t};\n}\n\nexport interface CqrsProjectionOptions<TState, TEvent = unknown> {\n\treadonly name?: string;\n\treadonly events?: readonly string[];\n\treadonly initial: TState;\n\treadonly reducer: (state: TState, event: CqrsEvent<TEvent>) => TState;\n}\n\nexport type CqrsProjectionFrame<TState> =\n\t| {\n\t\t\treadonly kind: \"value\";\n\t\t\treadonly state: TState;\n\t\t\treadonly eventId: string;\n\t\t\treadonly cursor: CqrsCursor;\n\t }\n\t| { readonly kind: \"error\"; readonly error: CqrsProjectionError };\n\nexport interface CqrsProjectionError {\n\treadonly code: \"projection-threw\";\n\treadonly message: string;\n\treadonly eventId: string;\n\treadonly eventType: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsProjectionStatus {\n\treadonly state: \"updated\" | \"errored\";\n\treadonly eventId: string;\n\treadonly eventType?: string;\n\treadonly cursor: CqrsCursor;\n}\n\nexport interface CqrsProjection<TState> {\n\treadonly frames: Node<CqrsProjectionFrame<TState>>;\n\treadonly value: Node<TState>;\n\treadonly status: Node<CqrsProjectionStatus>;\n\treadonly errors: Node<CqrsProjectionError>;\n}\n\n/**\n * Derive a projection from declared CQRS event deps. Reducer failures become\n * graph-visible error DATA facts on the returned `errors` node.\n */\nexport function cqrsProjection<TState, TEvent = unknown>(\n\tgraph: Graph,\n\tsource: Pick<CqrsBundle<unknown, TEvent>, \"events\">,\n\topts: CqrsProjectionOptions<TState, TEvent>,\n): CqrsProjection<TState> {\n\tconst name = opts.name ?? \"cqrsProjection\";\n\tconst eventFilter =\n\t\topts.events === undefined\n\t\t\t? undefined\n\t\t\t: new Set(uniqueNames(opts.events, \"cqrsProjection.events\"));\n\tconst frames = graph.node<CqrsProjectionFrame<TState>>(\n\t\t[source.events],\n\t\t(ctx) => {\n\t\t\tconst state = ctx.state.get<{ value: TState }>() ?? { value: opts.initial };\n\t\t\tctx.state.persist(true);\n\t\t\tfor (const raw of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst event = raw as CqrsEvent<TEvent>;\n\t\t\t\tif (eventFilter !== undefined && !eventFilter.has(event.type)) continue;\n\t\t\t\ttry {\n\t\t\t\t\tstate.value = opts.reducer(state.value, event);\n\t\t\t\t\tctx.state.set(state);\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"value\",\n\t\t\t\t\t\t\t\tstate: state.value,\n\t\t\t\t\t\t\t\teventId: event.id,\n\t\t\t\t\t\t\t\tcursor: event.runtimeCursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionFrame<TState>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t} catch (error) {\n\t\t\t\t\trethrowGraphRuntimeInvariant(error);\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tkind: \"error\",\n\t\t\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\t\t\tcode: \"projection-threw\",\n\t\t\t\t\t\t\t\t\tmessage: errorMessage(error),\n\t\t\t\t\t\t\t\t\teventId: event.id,\n\t\t\t\t\t\t\t\t\teventType: event.type,\n\t\t\t\t\t\t\t\t\tcursor: event.runtimeCursor,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t} satisfies CqrsProjectionFrame<TState>,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory: \"cqrsProjection\",\n\t\t\tmeta: { eventTypes: eventFilter ? [...eventFilter] : \"open\" },\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst value = graph.node<TState>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"value\") ctx.down([[\"DATA\", typed.state]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/value`,\n\t\t\tfactory: \"cqrsProjectionValue\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst errors = graph.node<CqrsProjectionError>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"error\") ctx.down([[\"DATA\", typed.error]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/errors`,\n\t\t\tfactory: \"cqrsProjectionErrors\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tconst status = graph.node<CqrsProjectionStatus>(\n\t\t[frames],\n\t\t(ctx) => {\n\t\t\tfor (const frame of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = frame as CqrsProjectionFrame<TState>;\n\t\t\t\tif (typed.kind === \"value\") {\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tstate: \"updated\",\n\t\t\t\t\t\t\t\teventId: typed.eventId,\n\t\t\t\t\t\t\t\tcursor: typed.cursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionStatus,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t} else {\n\t\t\t\t\tctx.down([\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"DATA\",\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tstate: \"errored\",\n\t\t\t\t\t\t\t\teventId: typed.error.eventId,\n\t\t\t\t\t\t\t\teventType: typed.error.eventType,\n\t\t\t\t\t\t\t\tcursor: typed.error.cursor,\n\t\t\t\t\t\t\t} satisfies CqrsProjectionStatus,\n\t\t\t\t\t\t],\n\t\t\t\t\t]);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: `${name}/status`,\n\t\t\tfactory: \"cqrsProjectionStatus\",\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n\tgraph.retain(frames, { reason: `${name}.cqrsProjection.frames` });\n\tgraph.retain(value, { reason: `${name}.cqrsProjection.value` });\n\tgraph.retain(status, { reason: `${name}.cqrsProjection.status` });\n\tgraph.retain(errors, { reason: `${name}.cqrsProjection.errors` });\n\treturn { frames, value, status, errors };\n}\n\nfunction normalizeHandlers<TCommand, TEvent>(\n\tdefinitions: readonly CqrsCommandHandlerDefinition<TCommand, TEvent>[],\n): ReadonlyMap<string, HandlerRecord> {\n\tconst handlers = new Map<string, HandlerRecord>();\n\tfor (const definition of definitions) {\n\t\tif (definition.type.length === 0) throw new Error(\"cqrs: handler type must be non-empty\");\n\t\tif (handlers.has(definition.type))\n\t\t\tthrow new Error(`cqrs: duplicate handler '${definition.type}'`);\n\t\thandlers.set(definition.type, {\n\t\t\ttype: definition.type,\n\t\t\thandle: definition.handle as CqrsCommandHandler<unknown, unknown>,\n\t\t});\n\t}\n\treturn handlers;\n}\n\nfunction reduceCommandFact<TEvent>(\n\traw: unknown,\n\tstate: CqrsRuntimeState,\n\thandlers: ReadonlyMap<string, HandlerRecord>,\n\tknownEvents: ReadonlySet<string> | undefined,\n\tnow: () => number,\n\tdedupe: NormalizedCqrsDedupePolicy,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n): void {\n\tstate.commandCount += 1;\n\tconst parsed = parseCommand(raw);\n\tif (typeof parsed === \"string\") {\n\t\temitFailure(state, emit, raw, undefined, \"malformed-command\", parsed, dedupe);\n\t\treturn;\n\t}\n\tconst command = parsed as CqrsCommand<unknown>;\n\tif (state.seenCommandIds.includes(command.id)) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"duplicate-command\",\n\t\t\t`cqrs: duplicate command '${command.id}'`,\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tstate.seenCommandIds.push(command.id);\n\ttrimDedupeWindow(state.seenCommandIds, dedupe.commandMaxEntries, (evicted) => {\n\t\tstate.commandDedupeEvicted = (state.commandDedupeEvicted ?? 0) + evicted;\n\t});\n\tconst handler = handlers.get(command.type);\n\tif (handler === undefined) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"unknown-command\",\n\t\t\t`cqrs: unknown command '${command.type}'`,\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tlet drafts: readonly CqrsEventDraft<unknown>[];\n\ttry {\n\t\tdrafts = handler.handle(command);\n\t} catch (error) {\n\t\trethrowGraphRuntimeInvariant(error);\n\t\temitFailure(state, emit, command, command, \"handler-threw\", errorMessage(error), dedupe);\n\t\treturn;\n\t}\n\tif (!Array.isArray(drafts)) {\n\t\temitFailure(\n\t\t\tstate,\n\t\t\temit,\n\t\t\tcommand,\n\t\t\tcommand,\n\t\t\t\"malformed-event\",\n\t\t\t\"cqrs: command handler must return an event draft array\",\n\t\t\tdedupe,\n\t\t);\n\t\treturn;\n\t}\n\tconst prepared = prepareEvents(command, drafts, state, knownEvents);\n\tif (typeof prepared === \"string\") {\n\t\temitFailure(state, emit, command, command, preparedCode(prepared), prepared, dedupe);\n\t\treturn;\n\t}\n\tconst timestampMs = readTimestampMs(now);\n\tif (typeof timestampMs === \"string\") {\n\t\temitFailure(state, emit, command, command, \"clock-threw\", timestampMs, dedupe);\n\t\treturn;\n\t}\n\tconst events: CqrsEvent<unknown>[] = [];\n\tfor (const draft of prepared) {\n\t\tstate.eventSeq += 1;\n\t\tstate.seenEventIds.push(draft.id);\n\t\ttrimDedupeWindow(state.seenEventIds, dedupe.eventMaxEntries, (evicted) => {\n\t\t\tstate.eventDedupeEvicted = (state.eventDedupeEvicted ?? 0) + evicted;\n\t\t});\n\t\tconst runtimeCursor = cursorOf(state, dedupe);\n\t\tevents.push({\n\t\t\tid: draft.id,\n\t\t\ttype: draft.type,\n\t\t\tseq: state.eventSeq,\n\t\t\tcursor: state.eventSeq,\n\t\t\truntimeCursor,\n\t\t\tcommandId: command.id,\n\t\t\tcommandType: command.type,\n\t\t\tpayload: draft.payload,\n\t\t\ttimestampMs,\n\t\t\t...(draft.aggregateId === undefined ? {} : { aggregateId: draft.aggregateId }),\n\t\t\t...(draft.correlationId === undefined ? {} : { correlationId: draft.correlationId }),\n\t\t\t...(draft.causationId === undefined ? {} : { causationId: draft.causationId }),\n\t\t\t...(draft.metadata === undefined ? {} : { metadata: draft.metadata }),\n\t\t});\n\t}\n\tfor (const event of events) emit({ kind: \"event\", event: event as CqrsEvent<TEvent> });\n\temitStatus(state, emit, command, \"accepted\", events.length, dedupe);\n\temitAudit(state, emit, command, \"success\", events, undefined, undefined, dedupe);\n\temit({ kind: \"cursor\", cursor: cursorOf(state, dedupe) });\n}\n\nfunction parseCommand(value: unknown): CqrsCommand<unknown> | string {\n\tif (!isObjectRecord(value)) return \"cqrs: command fact must be an object\";\n\tif (typeof value.id !== \"string\" || value.id.length === 0) {\n\t\treturn \"cqrs: command id must be a non-empty string\";\n\t}\n\tif (typeof value.type !== \"string\" || value.type.length === 0) {\n\t\treturn \"cqrs: command type must be a non-empty string\";\n\t}\n\treturn {\n\t\tid: value.id,\n\t\ttype: value.type,\n\t\tpayload: value.payload,\n\t\t...(typeof value.aggregateId === \"string\" ? { aggregateId: value.aggregateId } : {}),\n\t\t...(typeof value.correlationId === \"string\" ? { correlationId: value.correlationId } : {}),\n\t\t...(typeof value.causationId === \"string\" ? { causationId: value.causationId } : {}),\n\t\t...(isObjectRecord(value.metadata) ? { metadata: value.metadata } : {}),\n\t};\n}\n\nfunction prepareEvents(\n\tcommand: CqrsCommand<unknown>,\n\tdrafts: readonly CqrsEventDraft<unknown>[],\n\tstate: CqrsRuntimeState,\n\tknownEvents: ReadonlySet<string> | undefined,\n): Array<CqrsEventDraft<unknown> & { readonly id: string }> | string {\n\tconst seenInCommand = new Set<string>();\n\tconst prepared: Array<CqrsEventDraft<unknown> & { readonly id: string }> = [];\n\tfor (let i = 0; i < drafts.length; i += 1) {\n\t\tconst draft = drafts[i];\n\t\tif (!isObjectRecord(draft) || typeof draft.type !== \"string\" || draft.type.length === 0) {\n\t\t\treturn \"cqrs: event draft must have a non-empty type\";\n\t\t}\n\t\tif (knownEvents !== undefined && !knownEvents.has(draft.type)) {\n\t\t\treturn `cqrs: unknown event '${draft.type}'`;\n\t\t}\n\t\tconst id =\n\t\t\ttypeof draft.id === \"string\" && draft.id.length > 0 ? draft.id : `${command.id}:${i + 1}`;\n\t\tif (state.seenEventIds.includes(id) || seenInCommand.has(id)) {\n\t\t\treturn `cqrs: duplicate event '${id}'`;\n\t\t}\n\t\tseenInCommand.add(id);\n\t\tprepared.push({\n\t\t\tid,\n\t\t\ttype: draft.type,\n\t\t\tpayload: draft.payload,\n\t\t\t...(typeof draft.aggregateId === \"string\" ? { aggregateId: draft.aggregateId } : {}),\n\t\t\t...(typeof draft.correlationId === \"string\" ? { correlationId: draft.correlationId } : {}),\n\t\t\t...(typeof draft.causationId === \"string\" ? { causationId: draft.causationId } : {}),\n\t\t\t...(isObjectRecord(draft.metadata) ? { metadata: draft.metadata } : {}),\n\t\t});\n\t}\n\treturn prepared;\n}\n\nfunction preparedCode(message: string): CqrsErrorCode {\n\tif (message.includes(\"unknown event\")) return \"unknown-event\";\n\tif (message.includes(\"duplicate event\")) return \"duplicate-event\";\n\treturn \"malformed-event\";\n}\n\nfunction rethrowGraphRuntimeInvariant(error: unknown): void {\n\tconst message = errorMessage(error);\n\tif (\n\t\tmessage.includes(\"R-reentrancy\") ||\n\t\tmessage.includes(\"R-rewire\") ||\n\t\tmessage.includes(\"R-graph-domain\") ||\n\t\tmessage.includes(\"D37\") ||\n\t\tmessage.includes(\"D22\") ||\n\t\tmessage.includes(\"different graph\") ||\n\t\tmessage.includes(\"cross-graph\") ||\n\t\tmessage.includes(\"wire bridge\") ||\n\t\tmessage.includes(\"mid-fn topology mutation\") ||\n\t\tmessage.includes(\"reentrant dep mutation\") ||\n\t\tmessage.includes(\"feedback cycle\")\n\t) {\n\t\tthrow error;\n\t}\n}\n\nfunction emitFailure<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\traw: unknown,\n\tcommand: CqrsCommand<unknown> | undefined,\n\tcode: CqrsErrorCode,\n\tmessage: string,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\tstate.errorCount += 1;\n\tconst cursor = cursorOf(state, dedupe);\n\tconst error: CqrsError = {\n\t\tcode,\n\t\tmessage,\n\t\tcommand: raw,\n\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\tcursor,\n\t};\n\temit({ kind: \"error\", error });\n\temit({\n\t\tkind: \"status\",\n\t\tstatus: {\n\t\t\tstate: \"rejected\",\n\t\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\t\teventCount: 0,\n\t\t\terrorCode: code,\n\t\t\tcursor,\n\t\t},\n\t});\n\temitAudit(state, emit, command, \"failure\", [], code, message, dedupe);\n\temit({ kind: \"cursor\", cursor: cursorOf(state, dedupe) });\n}\n\nfunction emitStatus<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\tcommand: CqrsCommand<unknown>,\n\tstatusState: \"accepted\" | \"rejected\",\n\teventCount: number,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\temit({\n\t\tkind: \"status\",\n\t\tstatus: {\n\t\t\tstate: statusState,\n\t\t\tcommandId: command.id,\n\t\t\tcommandType: command.type,\n\t\t\teventCount,\n\t\t\tcursor: cursorOf(state, dedupe),\n\t\t},\n\t});\n}\n\nfunction emitAudit<TEvent>(\n\tstate: CqrsRuntimeState,\n\temit: (fact: CqrsRuntimeFact<TEvent>) => void,\n\tcommand: CqrsCommand<unknown> | undefined,\n\toutcome: \"success\" | \"failure\",\n\tevents: readonly CqrsEvent<unknown>[],\n\terrorCode: CqrsErrorCode | undefined,\n\terrorMessageValue: string | undefined,\n\tdedupe: NormalizedCqrsDedupePolicy,\n): void {\n\tstate.auditSeq += 1;\n\temit({\n\t\tkind: \"audit\",\n\t\taudit: {\n\t\t\tseq: state.auditSeq,\n\t\t\t...(command === undefined ? {} : { commandId: command.id, commandType: command.type }),\n\t\t\toutcome,\n\t\t\teventIds: Object.freeze(events.map((event) => event.id)),\n\t\t\teventTypes: Object.freeze(events.map((event) => event.type)),\n\t\t\t...(errorCode === undefined ? {} : { errorCode }),\n\t\t\t...(errorMessageValue === undefined ? {} : { errorMessage: errorMessageValue }),\n\t\t\tcursor: cursorOf(state, dedupe),\n\t\t},\n\t});\n}\n\nfunction runtimeProjection<TOut, TEvent>(\n\tgraph: Graph,\n\truntime: Node<CqrsRuntimeFact<TEvent>>,\n\tkind: CqrsRuntimeFact<TEvent>[\"kind\"],\n\tname: string,\n\tfactory: string,\n\tselect: (fact: CqrsRuntimeFact<TEvent>) => TOut | undefined,\n): Node<TOut> {\n\treturn graph.node<TOut>(\n\t\t[runtime],\n\t\t(ctx) => {\n\t\t\tfor (const fact of depBatch(ctx, 0) ?? []) {\n\t\t\t\tconst typed = fact as CqrsRuntimeFact<TEvent>;\n\t\t\t\tif (typed.kind !== kind) continue;\n\t\t\t\tconst selected = select(typed);\n\t\t\t\tif (selected !== undefined) ctx.down([[\"DATA\", selected]]);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname,\n\t\t\tfactory,\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t},\n\t);\n}\n\nfunction cursorOf(state: CqrsRuntimeState, dedupe: NormalizedCqrsDedupePolicy): CqrsCursor {\n\treturn {\n\t\teventSeq: state.eventSeq,\n\t\tcommandCount: state.commandCount,\n\t\terrorCount: state.errorCount,\n\t\tauditSeq: state.auditSeq,\n\t\t...(dedupe.bounded\n\t\t\t? {\n\t\t\t\t\tdedupe: {\n\t\t\t\t\t\tcommandIdsRetained: state.seenCommandIds.length,\n\t\t\t\t\t\teventIdsRetained: state.seenEventIds.length,\n\t\t\t\t\t\tcommandIdsEvicted: state.commandDedupeEvicted ?? 0,\n\t\t\t\t\t\teventIdsEvicted: state.eventDedupeEvicted ?? 0,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n\nfunction normalizeDedupePolicy(policy: CqrsDedupePolicy | undefined): NormalizedCqrsDedupePolicy {\n\tconst commandMaxEntries = normalizeDedupeWindow(policy?.commands, \"cqrs.dedupe.commands\");\n\tconst eventMaxEntries = normalizeDedupeWindow(policy?.events, \"cqrs.dedupe.events\");\n\treturn {\n\t\t...(commandMaxEntries === undefined ? {} : { commandMaxEntries }),\n\t\t...(eventMaxEntries === undefined ? {} : { eventMaxEntries }),\n\t\tbounded: commandMaxEntries !== undefined || eventMaxEntries !== undefined,\n\t};\n}\n\nfunction normalizeDedupeWindow(\n\twindow: CqrsDedupeWindow | undefined,\n\towner: string,\n): number | undefined {\n\tif (window === undefined || window === \"unbounded\") return undefined;\n\tif (!Number.isInteger(window.maxEntries) || window.maxEntries < 0) {\n\t\tthrow new RangeError(`${owner}: maxEntries must be a non-negative integer`);\n\t}\n\treturn window.maxEntries;\n}\n\nfunction dedupeMeta(dedupe: NormalizedCqrsDedupePolicy): unknown {\n\tif (!dedupe.bounded) return \"unbounded\";\n\treturn {\n\t\tcommands:\n\t\t\tdedupe.commandMaxEntries === undefined\n\t\t\t\t? \"unbounded\"\n\t\t\t\t: { maxEntries: dedupe.commandMaxEntries },\n\t\tevents:\n\t\t\tdedupe.eventMaxEntries === undefined ? \"unbounded\" : { maxEntries: dedupe.eventMaxEntries },\n\t};\n}\n\nfunction trimDedupeWindow(\n\tids: string[],\n\tmaxEntries: number | undefined,\n\tonEvicted: (evicted: number) => void,\n): void {\n\tif (maxEntries === undefined || ids.length <= maxEntries) return;\n\tconst evicted = ids.length - maxEntries;\n\tids.splice(0, evicted);\n\tonEvicted(evicted);\n}\n\nfunction readTimestampMs(now: () => number): number | string {\n\ttry {\n\t\tconst timestampMs = now();\n\t\treturn Number.isFinite(timestampMs) ? timestampMs : \"cqrs: now() must return a finite number\";\n\t} catch (error) {\n\t\treturn `cqrs: now() threw: ${errorMessage(error)}`;\n\t}\n}\n\nfunction uniqueNames(values: readonly string[], owner: string): readonly string[] {\n\tconst unique = [...new Set(values)];\n\tif (unique.length !== values.length) throw new Error(`${owner}: duplicate value`);\n\tfor (const value of unique) {\n\t\tif (value.length === 0) throw new Error(`${owner}: values must be non-empty`);\n\t}\n\treturn Object.freeze(unique);\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction isObjectRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"],"mappings":";;;;;;;AA0LO,SAAS,mBACf,MACA,QACiD;AACjD,MAAI,KAAK,WAAW,EAAG,OAAM,IAAI,MAAM,4CAA4C;AACnF,SAAO,EAAE,MAAM,OAAO;AACvB;AAMO,SAAS,KACf,OACA,OAAsC,CAAC,GACR;AAC/B,QAAM,OAAO,KAAK,QAAQ;AAC1B,QAAM,WAAW,kBAAkB,KAAK,YAAY,CAAC,CAAC;AACtD,QAAM,cACL,KAAK,WAAW,SAAY,SAAY,IAAI,IAAI,YAAY,KAAK,QAAQ,aAAa,CAAC;AACxF,QAAM,MAAM,KAAK,OAAO,KAAK;AAC7B,QAAM,SAAS,sBAAsB,KAAK,MAAM;AAChD,QAAM,UAAU,MAAM,KAA4B,CAAC,GAAG,MAAM;AAAA,IAC3D,MAAM,GAAG,IAAI;AAAA,IACb,SAAS;AAAA,IACT,0BAA0B;AAAA,IAC1B,oBAAoB;AAAA,EACrB,CAAC;AACD,QAAM,UAAU,MAAM;AAAA,IACrB,CAAC,OAAO;AAAA,IACR,CAAC,QAAQ;AACR,YAAM,QACL,IAAI,MAAM,IAAsB,KAC/B;AAAA,QACA,UAAU;AAAA,QACV,cAAc;AAAA,QACd,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,gBAAgB,CAAC;AAAA,QACjB,cAAc,CAAC;AAAA,MAChB;AACD,UAAI,MAAM,QAAQ,IAAI;AACtB,iBAAW,OAAO,SAAS,KAAK,CAAC,KAAK,CAAC,GAAG;AACzC;AAAA,UAAkB;AAAA,UAAK;AAAA,UAAO;AAAA,UAAU;AAAA,UAAa;AAAA,UAAK;AAAA,UAAQ,CAAC,SAClE,IAAI,KAAK,CAAC,CAAC,QAAQ,IAA+B,CAAC,CAAC;AAAA,Q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