@graphrefly/graphrefly 0.45.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/_internal-B23BagFd.d.cts +33 -0
- package/dist/_internal-B23BagFd.d.ts +33 -0
- package/dist/adaptive-rate-limiter-Dch_xYIi.d.cts +111 -0
- package/dist/adaptive-rate-limiter-Dch_xYIi.d.ts +111 -0
- package/dist/agents-C0Ji9ldU.d.cts +629 -0
- package/dist/agents-C9zexT7I.d.ts +629 -0
- package/dist/audit-BAXb3VOg.d.ts +246 -0
- package/dist/audit-C_bPfkqS.d.cts +246 -0
- package/dist/backoff-7KIK3WQW.js +24 -0
- package/dist/backoff-7KIK3WQW.js.map +1 -0
- package/dist/backoff-Bnb9OoPh.d.cts +6 -0
- package/dist/backoff-Bnb9OoPh.d.ts +6 -0
- package/dist/base/composition/index.cjs +865 -0
- package/dist/base/composition/index.cjs.map +1 -0
- package/dist/base/composition/index.d.cts +468 -0
- package/dist/base/composition/index.d.ts +468 -0
- package/dist/base/composition/index.js +40 -0
- package/dist/base/composition/index.js.map +1 -0
- package/dist/base/index.cjs +6390 -0
- package/dist/base/index.cjs.map +1 -0
- package/dist/base/index.d.cts +21 -0
- package/dist/base/index.d.ts +21 -0
- package/dist/base/index.js +259 -0
- package/dist/base/index.js.map +1 -0
- package/dist/base/io/index.cjs +3270 -0
- package/dist/base/io/index.cjs.map +1 -0
- package/dist/base/io/index.d.cts +2245 -0
- package/dist/base/io/index.d.ts +2245 -0
- package/dist/base/io/index.js +117 -0
- package/dist/base/io/index.js.map +1 -0
- package/dist/base/meta/index.cjs +43 -0
- package/dist/base/meta/index.cjs.map +1 -0
- package/dist/base/meta/index.d.cts +45 -0
- package/dist/base/meta/index.d.ts +45 -0
- package/dist/base/meta/index.js +13 -0
- package/dist/base/meta/index.js.map +1 -0
- package/dist/base/mutation/index.cjs +200 -0
- package/dist/base/mutation/index.cjs.map +1 -0
- package/dist/base/mutation/index.d.cts +177 -0
- package/dist/base/mutation/index.d.ts +177 -0
- package/dist/base/mutation/index.js +22 -0
- package/dist/base/mutation/index.js.map +1 -0
- package/dist/base/render/index.cjs +1120 -0
- package/dist/base/render/index.cjs.map +1 -0
- package/dist/base/render/index.d.cts +227 -0
- package/dist/base/render/index.d.ts +227 -0
- package/dist/base/render/index.js +24 -0
- package/dist/base/render/index.js.map +1 -0
- package/dist/base/sources/browser/index.cjs +172 -0
- package/dist/base/sources/browser/index.cjs.map +1 -0
- package/dist/base/sources/browser/index.d.cts +84 -0
- package/dist/base/sources/browser/index.d.ts +84 -0
- package/dist/base/sources/browser/index.js +151 -0
- package/dist/base/sources/browser/index.js.map +1 -0
- package/dist/base/sources/event/index.cjs +98 -0
- package/dist/base/sources/event/index.cjs.map +1 -0
- package/dist/base/sources/event/index.d.cts +91 -0
- package/dist/base/sources/event/index.d.ts +91 -0
- package/dist/base/sources/event/index.js +13 -0
- package/dist/base/sources/event/index.js.map +1 -0
- package/dist/base/sources/index.cjs +755 -0
- package/dist/base/sources/index.cjs.map +1 -0
- package/dist/base/sources/index.d.cts +357 -0
- package/dist/base/sources/index.d.ts +357 -0
- package/dist/base/sources/index.js +42 -0
- package/dist/base/sources/index.js.map +1 -0
- package/dist/base/sources/node/index.cjs +320 -0
- package/dist/base/sources/node/index.cjs.map +1 -0
- package/dist/base/sources/node/index.d.cts +185 -0
- package/dist/base/sources/node/index.d.ts +185 -0
- package/dist/base/sources/node/index.js +306 -0
- package/dist/base/sources/node/index.js.map +1 -0
- package/dist/base/utils/index.cjs +37 -0
- package/dist/base/utils/index.cjs.map +1 -0
- package/dist/base/utils/index.d.cts +37 -0
- package/dist/base/utils/index.d.ts +37 -0
- package/dist/base/utils/index.js +11 -0
- package/dist/base/utils/index.js.map +1 -0
- package/dist/base/worker/index.cjs +548 -0
- package/dist/base/worker/index.cjs.map +1 -0
- package/dist/base/worker/index.d.cts +207 -0
- package/dist/base/worker/index.d.ts +207 -0
- package/dist/base/worker/index.js +20 -0
- package/dist/base/worker/index.js.map +1 -0
- package/dist/breaker-C9skL3d8.d.ts +175 -0
- package/dist/breaker-ugSdq54q.d.cts +175 -0
- package/dist/cascading-CSSbKGrJ.d.ts +199 -0
- package/dist/cascading-baGkiihI.d.cts +199 -0
- package/dist/chunk-22SG74BD.js +207 -0
- package/dist/chunk-22SG74BD.js.map +1 -0
- package/dist/chunk-255UCBG4.js +58 -0
- package/dist/chunk-255UCBG4.js.map +1 -0
- package/dist/chunk-2LO3EL4W.js +1 -0
- package/dist/chunk-2LO3EL4W.js.map +1 -0
- package/dist/chunk-2OB3CEJS.js +1065 -0
- package/dist/chunk-2OB3CEJS.js.map +1 -0
- package/dist/chunk-36NMM65U.js +144 -0
- package/dist/chunk-36NMM65U.js.map +1 -0
- package/dist/chunk-3CEXCBN6.js +1 -0
- package/dist/chunk-3CEXCBN6.js.map +1 -0
- package/dist/chunk-3MUSLI6E.js +105 -0
- package/dist/chunk-3MUSLI6E.js.map +1 -0
- package/dist/chunk-3PSLNJDU.js +884 -0
- package/dist/chunk-3PSLNJDU.js.map +1 -0
- package/dist/chunk-42FQ27MQ.js +594 -0
- package/dist/chunk-42FQ27MQ.js.map +1 -0
- package/dist/chunk-4GYMCUDZ.js +1085 -0
- package/dist/chunk-4GYMCUDZ.js.map +1 -0
- package/dist/chunk-4S53H2KR.js +382 -0
- package/dist/chunk-4S53H2KR.js.map +1 -0
- package/dist/chunk-4XCHZRUJ.js +128 -0
- package/dist/chunk-4XCHZRUJ.js.map +1 -0
- package/dist/chunk-5IMMNARC.js +1153 -0
- package/dist/chunk-5IMMNARC.js.map +1 -0
- package/dist/chunk-6XZYT4SW.js +256 -0
- package/dist/chunk-6XZYT4SW.js.map +1 -0
- package/dist/chunk-7EGRP2VX.js +76 -0
- package/dist/chunk-7EGRP2VX.js.map +1 -0
- package/dist/chunk-A7KV5UK4.js +150 -0
- package/dist/chunk-A7KV5UK4.js.map +1 -0
- package/dist/chunk-APY2SS5X.js +156 -0
- package/dist/chunk-APY2SS5X.js.map +1 -0
- package/dist/chunk-AZDQPQ3V.js +66 -0
- package/dist/chunk-AZDQPQ3V.js.map +1 -0
- package/dist/chunk-BU3SEFA5.js +90 -0
- package/dist/chunk-BU3SEFA5.js.map +1 -0
- package/dist/chunk-BXGZFGZ4.js +189 -0
- package/dist/chunk-BXGZFGZ4.js.map +1 -0
- package/dist/chunk-CGHORL6G.js +579 -0
- package/dist/chunk-CGHORL6G.js.map +1 -0
- package/dist/chunk-CXANAIZU.js +530 -0
- package/dist/chunk-CXANAIZU.js.map +1 -0
- package/dist/chunk-CZQHCKKG.js +1 -0
- package/dist/chunk-CZQHCKKG.js.map +1 -0
- package/dist/chunk-DKNHAICT.js +133 -0
- package/dist/chunk-DKNHAICT.js.map +1 -0
- package/dist/chunk-DM4OMPWK.js +584 -0
- package/dist/chunk-DM4OMPWK.js.map +1 -0
- package/dist/chunk-DMSNO6ZB.js +452 -0
- package/dist/chunk-DMSNO6ZB.js.map +1 -0
- package/dist/chunk-E5OZPDIW.js +229 -0
- package/dist/chunk-E5OZPDIW.js.map +1 -0
- package/dist/chunk-EHRRQ4IC.js +211 -0
- package/dist/chunk-EHRRQ4IC.js.map +1 -0
- package/dist/chunk-EVYY4X5A.js +509 -0
- package/dist/chunk-EVYY4X5A.js.map +1 -0
- package/dist/chunk-FDFD67UO.js +1 -0
- package/dist/chunk-FDFD67UO.js.map +1 -0
- package/dist/chunk-FMPF42Q4.js +13 -0
- package/dist/chunk-FMPF42Q4.js.map +1 -0
- package/dist/chunk-FW23JYNQ.js +454 -0
- package/dist/chunk-FW23JYNQ.js.map +1 -0
- package/dist/chunk-GWRNLJNW.js +2508 -0
- package/dist/chunk-GWRNLJNW.js.map +1 -0
- package/dist/chunk-HL7HUJIX.js +1 -0
- package/dist/chunk-HL7HUJIX.js.map +1 -0
- package/dist/chunk-IHTWQEDR.js +169 -0
- package/dist/chunk-IHTWQEDR.js.map +1 -0
- package/dist/chunk-IJRR6YAI.js +128 -0
- package/dist/chunk-IJRR6YAI.js.map +1 -0
- package/dist/chunk-JGFRAFDL.js +221 -0
- package/dist/chunk-JGFRAFDL.js.map +1 -0
- package/dist/chunk-JKTC747G.js +725 -0
- package/dist/chunk-JKTC747G.js.map +1 -0
- package/dist/chunk-KN3H5CNT.js +11 -0
- package/dist/chunk-KN3H5CNT.js.map +1 -0
- package/dist/chunk-KPG3DGLA.js +1 -0
- package/dist/chunk-KPG3DGLA.js.map +1 -0
- package/dist/chunk-KRNQ6RGQ.js +1 -0
- package/dist/chunk-KRNQ6RGQ.js.map +1 -0
- package/dist/chunk-MLTPJMH6.js +417 -0
- package/dist/chunk-MLTPJMH6.js.map +1 -0
- package/dist/chunk-N3SZ7BMH.js +95 -0
- package/dist/chunk-N3SZ7BMH.js.map +1 -0
- package/dist/chunk-NDUD3IMO.js +540 -0
- package/dist/chunk-NDUD3IMO.js.map +1 -0
- package/dist/chunk-NY2PYHNC.js +873 -0
- package/dist/chunk-NY2PYHNC.js.map +1 -0
- package/dist/chunk-O3MT7DYI.js +225 -0
- package/dist/chunk-O3MT7DYI.js.map +1 -0
- package/dist/chunk-OCUDSN63.js +2386 -0
- package/dist/chunk-OCUDSN63.js.map +1 -0
- package/dist/chunk-OIWU3NYV.js +199 -0
- package/dist/chunk-OIWU3NYV.js.map +1 -0
- package/dist/chunk-OQUIJT7A.js +1 -0
- package/dist/chunk-OQUIJT7A.js.map +1 -0
- package/dist/chunk-P5LBT622.js +105 -0
- package/dist/chunk-P5LBT622.js.map +1 -0
- package/dist/chunk-PKGQG5QQ.js +519 -0
- package/dist/chunk-PKGQG5QQ.js.map +1 -0
- package/dist/chunk-PKPO3JTZ.js +561 -0
- package/dist/chunk-PKPO3JTZ.js.map +1 -0
- package/dist/chunk-PL5UDIQ5.js +118 -0
- package/dist/chunk-PL5UDIQ5.js.map +1 -0
- package/dist/chunk-PZWISPIQ.js +432 -0
- package/dist/chunk-PZWISPIQ.js.map +1 -0
- package/dist/chunk-Q3EYOCZB.js +510 -0
- package/dist/chunk-Q3EYOCZB.js.map +1 -0
- package/dist/chunk-QMBYUVRL.js +15 -0
- package/dist/chunk-QMBYUVRL.js.map +1 -0
- package/dist/chunk-RAGGHLCV.js +200 -0
- package/dist/chunk-RAGGHLCV.js.map +1 -0
- package/dist/chunk-RJOG4IJU.js +1039 -0
- package/dist/chunk-RJOG4IJU.js.map +1 -0
- package/dist/chunk-SOOKUYVM.js +403 -0
- package/dist/chunk-SOOKUYVM.js.map +1 -0
- package/dist/chunk-T5BN5KG7.js +1 -0
- package/dist/chunk-T5BN5KG7.js.map +1 -0
- package/dist/chunk-TNX5ZGDJ.js +574 -0
- package/dist/chunk-TNX5ZGDJ.js.map +1 -0
- package/dist/chunk-TP7244Y6.js +207 -0
- package/dist/chunk-TP7244Y6.js.map +1 -0
- package/dist/chunk-TSBFTJKM.js +57 -0
- package/dist/chunk-TSBFTJKM.js.map +1 -0
- package/dist/chunk-URQ2CBBF.js +143 -0
- package/dist/chunk-URQ2CBBF.js.map +1 -0
- package/dist/chunk-VLAGJZSL.js +1079 -0
- package/dist/chunk-VLAGJZSL.js.map +1 -0
- package/dist/chunk-W2BOPXTI.js +1 -0
- package/dist/chunk-W2BOPXTI.js.map +1 -0
- package/dist/chunk-Y52CS6YA.js +88 -0
- package/dist/chunk-Y52CS6YA.js.map +1 -0
- package/dist/chunk-YCBUWK77.js +92 -0
- package/dist/chunk-YCBUWK77.js.map +1 -0
- package/dist/chunk-YJ4U2D2C.js +314 -0
- package/dist/chunk-YJ4U2D2C.js.map +1 -0
- package/dist/chunk-Z4YXAUDN.js +239 -0
- package/dist/chunk-Z4YXAUDN.js.map +1 -0
- package/dist/chunk-Z65DVDEQ.js +146 -0
- package/dist/chunk-Z65DVDEQ.js.map +1 -0
- package/dist/chunk-Z6EGP5D7.js +92 -0
- package/dist/chunk-Z6EGP5D7.js.map +1 -0
- package/dist/chunk-ZT4WMQW4.js +1575 -0
- package/dist/chunk-ZT4WMQW4.js.map +1 -0
- package/dist/chunk-ZVXXDWIB.js +1282 -0
- package/dist/chunk-ZVXXDWIB.js.map +1 -0
- package/dist/compat/index.cjs +3150 -6
- package/dist/compat/index.cjs.map +1 -1
- package/dist/compat/index.d.cts +116 -1
- package/dist/compat/index.d.ts +116 -1
- package/dist/compat/index.js +175 -2
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/jotai/index.cjs +130 -2
- package/dist/compat/jotai/index.cjs.map +1 -1
- package/dist/compat/jotai/index.d.cts +2 -1
- package/dist/compat/jotai/index.d.ts +2 -1
- package/dist/compat/jotai/index.js +7 -2
- package/dist/compat/jotai/index.js.map +1 -1
- package/dist/compat/nanostores/index.cjs +186 -2
- package/dist/compat/nanostores/index.cjs.map +1 -1
- package/dist/compat/nanostores/index.d.cts +2 -1
- package/dist/compat/nanostores/index.d.ts +2 -1
- package/dist/compat/nanostores/index.js +21 -2
- package/dist/compat/nanostores/index.js.map +1 -1
- package/dist/compat/nestjs/index.cjs +2291 -6
- package/dist/compat/nestjs/index.cjs.map +1 -1
- package/dist/compat/nestjs/index.d.cts +10 -1
- package/dist/compat/nestjs/index.d.ts +10 -1
- package/dist/compat/nestjs/index.js +76 -2
- package/dist/compat/nestjs/index.js.map +1 -1
- package/dist/compat/react/index.cjs +95 -2
- package/dist/compat/react/index.cjs.map +1 -1
- package/dist/compat/react/index.d.cts +2 -1
- package/dist/compat/react/index.d.ts +2 -1
- package/dist/compat/react/index.js +11 -2
- package/dist/compat/react/index.js.map +1 -1
- package/dist/compat/solid/index.cjs +82 -2
- package/dist/compat/solid/index.cjs.map +1 -1
- package/dist/compat/solid/index.d.cts +2 -1
- package/dist/compat/solid/index.d.ts +2 -1
- package/dist/compat/solid/index.js +11 -2
- package/dist/compat/solid/index.js.map +1 -1
- package/dist/compat/svelte/index.cjs +85 -2
- package/dist/compat/svelte/index.cjs.map +1 -1
- package/dist/compat/svelte/index.d.cts +2 -1
- package/dist/compat/svelte/index.d.ts +2 -1
- package/dist/compat/svelte/index.js +11 -2
- package/dist/compat/svelte/index.js.map +1 -1
- package/dist/compat/vue/index.cjs +100 -2
- package/dist/compat/vue/index.cjs.map +1 -1
- package/dist/compat/vue/index.d.cts +3 -1
- package/dist/compat/vue/index.d.ts +3 -1
- package/dist/compat/vue/index.js +11 -2
- package/dist/compat/vue/index.js.map +1 -1
- package/dist/compat/zustand/index.cjs +50 -2
- package/dist/compat/zustand/index.cjs.map +1 -1
- package/dist/compat/zustand/index.d.cts +2 -1
- package/dist/compat/zustand/index.d.ts +2 -1
- package/dist/compat/zustand/index.js +7 -2
- package/dist/compat/zustand/index.js.map +1 -1
- package/dist/distill-De6Rnn15.d.cts +48 -0
- package/dist/distill-De6Rnn15.d.ts +48 -0
- package/dist/external-register-CWyroXb_.d.cts +138 -0
- package/dist/external-register-CWyroXb_.d.ts +138 -0
- package/dist/fallback-Bx46zqky.d.cts +243 -0
- package/dist/fallback-pIWW8A2d.d.ts +243 -0
- package/dist/guarded-execution-BcdtxeBk.d.ts +207 -0
- package/dist/guarded-execution-C-3hnP6A.d.cts +207 -0
- package/dist/index-B6pxYJzO.d.cts +36 -0
- package/dist/index-B6pxYJzO.d.ts +36 -0
- package/dist/index-BFsng6v1.d.cts +44 -0
- package/dist/index-BFsng6v1.d.ts +44 -0
- package/dist/index-B_p8tnvf.d.cts +770 -0
- package/dist/index-Bg-LwEt-.d.cts +45 -0
- package/dist/index-Bg-LwEt-.d.ts +45 -0
- package/dist/index-Brp888t0.d.cts +127 -0
- package/dist/index-Brp888t0.d.ts +127 -0
- package/dist/index-CDfk6jHN.d.cts +37 -0
- package/dist/index-CDfk6jHN.d.ts +37 -0
- package/dist/index-DLAxYaN5.d.cts +169 -0
- package/dist/index-DLAxYaN5.d.ts +169 -0
- package/dist/index-DeWbQzMe.d.cts +34 -0
- package/dist/index-DeWbQzMe.d.ts +34 -0
- package/dist/index-_HDSmPyp.d.ts +770 -0
- package/dist/index-dX9IzPqj.d.cts +86 -0
- package/dist/index-dX9IzPqj.d.ts +86 -0
- package/dist/index.cjs +26009 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -42
- package/dist/index.d.ts +55 -42
- package/dist/index.js +849 -0
- package/dist/index.js.map +1 -1
- package/dist/layout-types-B5aiHYgk.d.cts +72 -0
- package/dist/layout-types-B5aiHYgk.d.ts +72 -0
- package/dist/memory-composers-BryDrRBX.d.cts +529 -0
- package/dist/memory-composers-CVQqPYEV.d.ts +529 -0
- package/dist/observable-B25XqCbZ.d.cts +59 -0
- package/dist/observable-B25XqCbZ.d.ts +59 -0
- package/dist/pipeline-graph-Ce47CB6Y.d.cts +145 -0
- package/dist/pipeline-graph-DXCwY9vG.d.ts +145 -0
- package/dist/presets/ai/index.cjs +4377 -0
- package/dist/presets/ai/index.cjs.map +1 -0
- package/dist/presets/ai/index.d.cts +98 -0
- package/dist/presets/ai/index.d.ts +98 -0
- package/dist/presets/ai/index.js +54 -0
- package/dist/presets/ai/index.js.map +1 -0
- package/dist/presets/harness/index.cjs +5929 -0
- package/dist/presets/harness/index.cjs.map +1 -0
- package/dist/presets/harness/index.d.cts +566 -0
- package/dist/presets/harness/index.d.ts +566 -0
- package/dist/presets/harness/index.js +71 -0
- package/dist/presets/harness/index.js.map +1 -0
- package/dist/presets/index.cjs +9782 -0
- package/dist/presets/index.cjs.map +1 -0
- package/dist/presets/index.d.cts +28 -0
- package/dist/presets/index.d.ts +28 -0
- package/dist/presets/index.js +129 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/inspect/index.cjs +1087 -0
- package/dist/presets/inspect/index.cjs.map +1 -0
- package/dist/presets/inspect/index.d.cts +172 -0
- package/dist/presets/inspect/index.d.ts +172 -0
- package/dist/presets/inspect/index.js +21 -0
- package/dist/presets/inspect/index.js.map +1 -0
- package/dist/presets/resilience/index.cjs +1593 -0
- package/dist/presets/resilience/index.cjs.map +1 -0
- package/dist/presets/resilience/index.d.cts +205 -0
- package/dist/presets/resilience/index.d.ts +205 -0
- package/dist/presets/resilience/index.js +18 -0
- package/dist/presets/resilience/index.js.map +1 -0
- package/dist/rate-limiter-CEALq4N1.d.ts +559 -0
- package/dist/rate-limiter-DpVbSYdH.d.cts +559 -0
- package/dist/reactive-layout-fswlBUvX.d.cts +195 -0
- package/dist/reactive-layout-fswlBUvX.d.ts +195 -0
- package/dist/retry-BDbRZ_gx.d.ts +125 -0
- package/dist/retry-DWuhjvsA.d.cts +125 -0
- package/dist/solutions/index.cjs +8200 -0
- package/dist/solutions/index.cjs.map +1 -0
- package/dist/solutions/index.d.cts +23 -0
- package/dist/solutions/index.d.ts +23 -0
- package/dist/solutions/index.js +55 -0
- package/dist/solutions/index.js.map +1 -0
- package/dist/spawnable-5mDY501F.d.cts +746 -0
- package/dist/spawnable-D3lR0oQu.d.ts +746 -0
- package/dist/status-U-rUI79b.d.cts +84 -0
- package/dist/status-U-rUI79b.d.ts +84 -0
- package/dist/timeout-U5O4ESK3.js +12 -0
- package/dist/timeout-U5O4ESK3.js.map +1 -0
- package/dist/types-BB5Lw-pB.d.cts +442 -0
- package/dist/types-BB5Lw-pB.d.ts +442 -0
- package/dist/types-CJWIMJiZ.d.ts +548 -0
- package/dist/types-vCq7ShIm.d.cts +548 -0
- package/dist/utils/ai/browser.cjs +2169 -0
- package/dist/utils/ai/browser.cjs.map +1 -0
- package/dist/utils/ai/browser.d.cts +129 -0
- package/dist/utils/ai/browser.d.ts +129 -0
- package/dist/utils/ai/browser.js +255 -0
- package/dist/utils/ai/browser.js.map +1 -0
- package/dist/utils/ai/index.cjs +8468 -0
- package/dist/utils/ai/index.cjs.map +1 -0
- package/dist/utils/ai/index.d.cts +1777 -0
- package/dist/utils/ai/index.d.ts +1777 -0
- package/dist/utils/ai/index.js +173 -0
- package/dist/utils/ai/index.js.map +1 -0
- package/dist/utils/ai/node.cjs +648 -0
- package/dist/utils/ai/node.cjs.map +1 -0
- package/dist/utils/ai/node.d.cts +57 -0
- package/dist/utils/ai/node.d.ts +57 -0
- package/dist/utils/ai/node.js +84 -0
- package/dist/utils/ai/node.js.map +1 -0
- package/dist/utils/cqrs/index.cjs +1036 -0
- package/dist/utils/cqrs/index.cjs.map +1 -0
- package/dist/utils/cqrs/index.d.cts +438 -0
- package/dist/utils/cqrs/index.d.ts +438 -0
- package/dist/utils/cqrs/index.js +18 -0
- package/dist/utils/cqrs/index.js.map +1 -0
- package/dist/utils/demo-shell/index.cjs +865 -0
- package/dist/utils/demo-shell/index.cjs.map +1 -0
- package/dist/utils/demo-shell/index.d.cts +90 -0
- package/dist/utils/demo-shell/index.d.ts +90 -0
- package/dist/utils/demo-shell/index.js +13 -0
- package/dist/utils/demo-shell/index.js.map +1 -0
- package/dist/utils/domain-templates/index.cjs +732 -0
- package/dist/utils/domain-templates/index.cjs.map +1 -0
- package/dist/utils/domain-templates/index.d.cts +214 -0
- package/dist/utils/domain-templates/index.d.ts +214 -0
- package/dist/utils/domain-templates/index.js +17 -0
- package/dist/utils/domain-templates/index.js.map +1 -0
- package/dist/utils/graphspec/index.cjs +1174 -0
- package/dist/utils/graphspec/index.cjs.map +1 -0
- package/dist/utils/graphspec/index.d.cts +449 -0
- package/dist/utils/graphspec/index.d.ts +449 -0
- package/dist/utils/graphspec/index.js +35 -0
- package/dist/utils/graphspec/index.js.map +1 -0
- package/dist/utils/harness/index.cjs +656 -0
- package/dist/utils/harness/index.cjs.map +1 -0
- package/dist/utils/harness/index.d.cts +542 -0
- package/dist/utils/harness/index.d.ts +542 -0
- package/dist/utils/harness/index.js +56 -0
- package/dist/utils/harness/index.js.map +1 -0
- package/dist/utils/index.cjs +17614 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +96 -0
- package/dist/utils/index.d.ts +96 -0
- package/dist/utils/index.js +514 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/inspect/index.cjs +807 -0
- package/dist/utils/inspect/index.cjs.map +1 -0
- package/dist/utils/inspect/index.d.cts +123 -0
- package/dist/utils/inspect/index.d.ts +123 -0
- package/dist/utils/inspect/index.js +30 -0
- package/dist/utils/inspect/index.js.map +1 -0
- package/dist/utils/job-queue/index.cjs +717 -0
- package/dist/utils/job-queue/index.cjs.map +1 -0
- package/dist/utils/job-queue/index.d.cts +200 -0
- package/dist/utils/job-queue/index.d.ts +200 -0
- package/dist/utils/job-queue/index.js +18 -0
- package/dist/utils/job-queue/index.js.map +1 -0
- package/dist/utils/memory/index.cjs +1456 -0
- package/dist/utils/memory/index.cjs.map +1 -0
- package/dist/utils/memory/index.d.cts +660 -0
- package/dist/utils/memory/index.d.ts +660 -0
- package/dist/utils/memory/index.js +19 -0
- package/dist/utils/memory/index.js.map +1 -0
- package/dist/utils/messaging/index.cjs +666 -0
- package/dist/utils/messaging/index.cjs.map +1 -0
- package/dist/utils/messaging/index.d.cts +562 -0
- package/dist/utils/messaging/index.d.ts +562 -0
- package/dist/utils/messaging/index.js +50 -0
- package/dist/utils/messaging/index.js.map +1 -0
- package/dist/utils/orchestration/index.cjs +876 -0
- package/dist/utils/orchestration/index.cjs.map +1 -0
- package/dist/utils/orchestration/index.d.cts +233 -0
- package/dist/utils/orchestration/index.d.ts +233 -0
- package/dist/utils/orchestration/index.js +19 -0
- package/dist/utils/orchestration/index.js.map +1 -0
- package/dist/utils/process/index.cjs +743 -0
- package/dist/utils/process/index.cjs.map +1 -0
- package/dist/utils/process/index.d.cts +411 -0
- package/dist/utils/process/index.d.ts +411 -0
- package/dist/utils/process/index.js +14 -0
- package/dist/utils/process/index.js.map +1 -0
- package/dist/utils/reactive-layout/index.cjs +1607 -0
- package/dist/utils/reactive-layout/index.cjs.map +1 -0
- package/dist/utils/reactive-layout/index.d.cts +492 -0
- package/dist/utils/reactive-layout/index.d.ts +492 -0
- package/dist/utils/reactive-layout/index.js +52 -0
- package/dist/utils/reactive-layout/index.js.map +1 -0
- package/dist/utils/reduction/index.cjs +203 -0
- package/dist/utils/reduction/index.cjs.map +1 -0
- package/dist/utils/reduction/index.d.cts +102 -0
- package/dist/utils/reduction/index.d.ts +102 -0
- package/dist/utils/reduction/index.js +14 -0
- package/dist/utils/reduction/index.js.map +1 -0
- package/dist/utils/resilience/index.cjs +1617 -0
- package/dist/utils/resilience/index.cjs.map +1 -0
- package/dist/utils/resilience/index.d.cts +9 -0
- package/dist/utils/resilience/index.d.ts +9 -0
- package/dist/utils/resilience/index.js +44 -0
- package/dist/utils/resilience/index.js.map +1 -0
- package/dist/utils/surface/index.cjs +1070 -0
- package/dist/utils/surface/index.cjs.map +1 -0
- package/dist/utils/surface/index.d.cts +240 -0
- package/dist/utils/surface/index.d.ts +240 -0
- package/dist/utils/surface/index.js +30 -0
- package/dist/utils/surface/index.js.map +1 -0
- package/dist/utils/topology-view/index.cjs +620 -0
- package/dist/utils/topology-view/index.cjs.map +1 -0
- package/dist/utils/topology-view/index.d.cts +68 -0
- package/dist/utils/topology-view/index.d.ts +68 -0
- package/dist/utils/topology-view/index.js +11 -0
- package/dist/utils/topology-view/index.js.map +1 -0
- package/package.json +293 -241
- package/dist/core/index.cjs +0 -21
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.cts +0 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -3
- package/dist/core/index.js.map +0 -1
- package/dist/extra/browser.cjs +0 -21
- package/dist/extra/browser.cjs.map +0 -1
- package/dist/extra/browser.d.cts +0 -1
- package/dist/extra/browser.d.ts +0 -1
- package/dist/extra/browser.js +0 -3
- package/dist/extra/browser.js.map +0 -1
- package/dist/extra/index.cjs +0 -21
- package/dist/extra/index.cjs.map +0 -1
- package/dist/extra/index.d.cts +0 -1
- package/dist/extra/index.d.ts +0 -1
- package/dist/extra/index.js +0 -3
- package/dist/extra/index.js.map +0 -1
- package/dist/extra/node.cjs +0 -21
- package/dist/extra/node.cjs.map +0 -1
- package/dist/extra/node.d.cts +0 -1
- package/dist/extra/node.d.ts +0 -1
- package/dist/extra/node.js +0 -3
- package/dist/extra/node.js.map +0 -1
- package/dist/extra/operators.cjs +0 -21
- package/dist/extra/operators.cjs.map +0 -1
- package/dist/extra/operators.d.cts +0 -1
- package/dist/extra/operators.d.ts +0 -1
- package/dist/extra/operators.js +0 -3
- package/dist/extra/operators.js.map +0 -1
- package/dist/extra/reactive.cjs +0 -21
- package/dist/extra/reactive.cjs.map +0 -1
- package/dist/extra/reactive.d.cts +0 -1
- package/dist/extra/reactive.d.ts +0 -1
- package/dist/extra/reactive.js +0 -3
- package/dist/extra/reactive.js.map +0 -1
- package/dist/extra/render/index.cjs +0 -21
- package/dist/extra/render/index.cjs.map +0 -1
- package/dist/extra/render/index.d.cts +0 -1
- package/dist/extra/render/index.d.ts +0 -1
- package/dist/extra/render/index.js +0 -3
- package/dist/extra/render/index.js.map +0 -1
- package/dist/extra/sources.cjs +0 -21
- package/dist/extra/sources.cjs.map +0 -1
- package/dist/extra/sources.d.cts +0 -1
- package/dist/extra/sources.d.ts +0 -1
- package/dist/extra/sources.js +0 -3
- package/dist/extra/sources.js.map +0 -1
- package/dist/extra/storage-browser.cjs +0 -21
- package/dist/extra/storage-browser.cjs.map +0 -1
- package/dist/extra/storage-browser.d.cts +0 -1
- package/dist/extra/storage-browser.d.ts +0 -1
- package/dist/extra/storage-browser.js +0 -3
- package/dist/extra/storage-browser.js.map +0 -1
- package/dist/extra/storage-core.cjs +0 -21
- package/dist/extra/storage-core.cjs.map +0 -1
- package/dist/extra/storage-core.d.cts +0 -1
- package/dist/extra/storage-core.d.ts +0 -1
- package/dist/extra/storage-core.js +0 -3
- package/dist/extra/storage-core.js.map +0 -1
- package/dist/extra/storage-node.cjs +0 -21
- package/dist/extra/storage-node.cjs.map +0 -1
- package/dist/extra/storage-node.d.cts +0 -1
- package/dist/extra/storage-node.d.ts +0 -1
- package/dist/extra/storage-node.js +0 -3
- package/dist/extra/storage-node.js.map +0 -1
- package/dist/extra/storage-tiers-browser.cjs +0 -21
- package/dist/extra/storage-tiers-browser.cjs.map +0 -1
- package/dist/extra/storage-tiers-browser.d.cts +0 -1
- package/dist/extra/storage-tiers-browser.d.ts +0 -1
- package/dist/extra/storage-tiers-browser.js +0 -3
- package/dist/extra/storage-tiers-browser.js.map +0 -1
- package/dist/extra/storage-tiers-node.cjs +0 -21
- package/dist/extra/storage-tiers-node.cjs.map +0 -1
- package/dist/extra/storage-tiers-node.d.cts +0 -1
- package/dist/extra/storage-tiers-node.d.ts +0 -1
- package/dist/extra/storage-tiers-node.js +0 -3
- package/dist/extra/storage-tiers-node.js.map +0 -1
- package/dist/extra/storage-tiers.cjs +0 -21
- package/dist/extra/storage-tiers.cjs.map +0 -1
- package/dist/extra/storage-tiers.d.cts +0 -1
- package/dist/extra/storage-tiers.d.ts +0 -1
- package/dist/extra/storage-tiers.js +0 -3
- package/dist/extra/storage-tiers.js.map +0 -1
- package/dist/extra/storage-wal.cjs +0 -21
- package/dist/extra/storage-wal.cjs.map +0 -1
- package/dist/extra/storage-wal.d.cts +0 -1
- package/dist/extra/storage-wal.d.ts +0 -1
- package/dist/extra/storage-wal.js +0 -3
- package/dist/extra/storage-wal.js.map +0 -1
- package/dist/graph/index.cjs +0 -21
- package/dist/graph/index.cjs.map +0 -1
- package/dist/graph/index.d.cts +0 -1
- package/dist/graph/index.d.ts +0 -1
- package/dist/graph/index.js +0 -3
- package/dist/graph/index.js.map +0 -1
- package/dist/patterns/ai/browser.cjs +0 -21
- package/dist/patterns/ai/browser.cjs.map +0 -1
- package/dist/patterns/ai/browser.d.cts +0 -1
- package/dist/patterns/ai/browser.d.ts +0 -1
- package/dist/patterns/ai/browser.js +0 -3
- package/dist/patterns/ai/browser.js.map +0 -1
- package/dist/patterns/ai/index.cjs +0 -21
- package/dist/patterns/ai/index.cjs.map +0 -1
- package/dist/patterns/ai/index.d.cts +0 -1
- package/dist/patterns/ai/index.d.ts +0 -1
- package/dist/patterns/ai/index.js +0 -3
- package/dist/patterns/ai/index.js.map +0 -1
- package/dist/patterns/ai/node.cjs +0 -21
- package/dist/patterns/ai/node.cjs.map +0 -1
- package/dist/patterns/ai/node.d.cts +0 -1
- package/dist/patterns/ai/node.d.ts +0 -1
- package/dist/patterns/ai/node.js +0 -3
- package/dist/patterns/ai/node.js.map +0 -1
- package/dist/patterns/cqrs/index.cjs +0 -21
- package/dist/patterns/cqrs/index.cjs.map +0 -1
- package/dist/patterns/cqrs/index.d.cts +0 -1
- package/dist/patterns/cqrs/index.d.ts +0 -1
- package/dist/patterns/cqrs/index.js +0 -3
- package/dist/patterns/cqrs/index.js.map +0 -1
- package/dist/patterns/demo-shell/index.cjs +0 -21
- package/dist/patterns/demo-shell/index.cjs.map +0 -1
- package/dist/patterns/demo-shell/index.d.cts +0 -1
- package/dist/patterns/demo-shell/index.d.ts +0 -1
- package/dist/patterns/demo-shell/index.js +0 -3
- package/dist/patterns/demo-shell/index.js.map +0 -1
- package/dist/patterns/domain-templates/index.cjs +0 -21
- package/dist/patterns/domain-templates/index.cjs.map +0 -1
- package/dist/patterns/domain-templates/index.d.cts +0 -1
- package/dist/patterns/domain-templates/index.d.ts +0 -1
- package/dist/patterns/domain-templates/index.js +0 -3
- package/dist/patterns/domain-templates/index.js.map +0 -1
- package/dist/patterns/graphspec/index.cjs +0 -21
- package/dist/patterns/graphspec/index.cjs.map +0 -1
- package/dist/patterns/graphspec/index.d.cts +0 -1
- package/dist/patterns/graphspec/index.d.ts +0 -1
- package/dist/patterns/graphspec/index.js +0 -3
- package/dist/patterns/graphspec/index.js.map +0 -1
- package/dist/patterns/harness/index.cjs +0 -21
- package/dist/patterns/harness/index.cjs.map +0 -1
- package/dist/patterns/harness/index.d.cts +0 -1
- package/dist/patterns/harness/index.d.ts +0 -1
- package/dist/patterns/harness/index.js +0 -3
- package/dist/patterns/harness/index.js.map +0 -1
- package/dist/patterns/inspect/index.cjs +0 -21
- package/dist/patterns/inspect/index.cjs.map +0 -1
- package/dist/patterns/inspect/index.d.cts +0 -1
- package/dist/patterns/inspect/index.d.ts +0 -1
- package/dist/patterns/inspect/index.js +0 -3
- package/dist/patterns/inspect/index.js.map +0 -1
- package/dist/patterns/job-queue/index.cjs +0 -21
- package/dist/patterns/job-queue/index.cjs.map +0 -1
- package/dist/patterns/job-queue/index.d.cts +0 -1
- package/dist/patterns/job-queue/index.d.ts +0 -1
- package/dist/patterns/job-queue/index.js +0 -3
- package/dist/patterns/job-queue/index.js.map +0 -1
- package/dist/patterns/memory/index.cjs +0 -21
- package/dist/patterns/memory/index.cjs.map +0 -1
- package/dist/patterns/memory/index.d.cts +0 -1
- package/dist/patterns/memory/index.d.ts +0 -1
- package/dist/patterns/memory/index.js +0 -3
- package/dist/patterns/memory/index.js.map +0 -1
- package/dist/patterns/messaging/index.cjs +0 -21
- package/dist/patterns/messaging/index.cjs.map +0 -1
- package/dist/patterns/messaging/index.d.cts +0 -1
- package/dist/patterns/messaging/index.d.ts +0 -1
- package/dist/patterns/messaging/index.js +0 -3
- package/dist/patterns/messaging/index.js.map +0 -1
- package/dist/patterns/orchestration/index.cjs +0 -21
- package/dist/patterns/orchestration/index.cjs.map +0 -1
- package/dist/patterns/orchestration/index.d.cts +0 -1
- package/dist/patterns/orchestration/index.d.ts +0 -1
- package/dist/patterns/orchestration/index.js +0 -3
- package/dist/patterns/orchestration/index.js.map +0 -1
- package/dist/patterns/process/index.cjs +0 -21
- package/dist/patterns/process/index.cjs.map +0 -1
- package/dist/patterns/process/index.d.cts +0 -1
- package/dist/patterns/process/index.d.ts +0 -1
- package/dist/patterns/process/index.js +0 -3
- package/dist/patterns/process/index.js.map +0 -1
- package/dist/patterns/reactive-layout/index.cjs +0 -21
- package/dist/patterns/reactive-layout/index.cjs.map +0 -1
- package/dist/patterns/reactive-layout/index.d.cts +0 -1
- package/dist/patterns/reactive-layout/index.d.ts +0 -1
- package/dist/patterns/reactive-layout/index.js +0 -3
- package/dist/patterns/reactive-layout/index.js.map +0 -1
- package/dist/patterns/reduction/index.cjs +0 -21
- package/dist/patterns/reduction/index.cjs.map +0 -1
- package/dist/patterns/reduction/index.d.cts +0 -1
- package/dist/patterns/reduction/index.d.ts +0 -1
- package/dist/patterns/reduction/index.js +0 -3
- package/dist/patterns/reduction/index.js.map +0 -1
- package/dist/patterns/surface/index.cjs +0 -21
- package/dist/patterns/surface/index.cjs.map +0 -1
- package/dist/patterns/surface/index.d.cts +0 -1
- package/dist/patterns/surface/index.d.ts +0 -1
- package/dist/patterns/surface/index.js +0 -3
- package/dist/patterns/surface/index.js.map +0 -1
- package/dist/patterns/topology-view/index.cjs +0 -21
- package/dist/patterns/topology-view/index.cjs.map +0 -1
- package/dist/patterns/topology-view/index.d.cts +0 -1
- package/dist/patterns/topology-view/index.d.ts +0 -1
- package/dist/patterns/topology-view/index.js +0 -3
- package/dist/patterns/topology-view/index.js.map +0 -1
- package/dist/testing/index.cjs +0 -21
- package/dist/testing/index.cjs.map +0 -1
- package/dist/testing/index.d.cts +0 -1
- package/dist/testing/index.d.ts +0 -1
- package/dist/testing/index.js +0 -3
- package/dist/testing/index.js.map +0 -1
|
@@ -1,21 +1,2306 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from2, except, desc) => {
|
|
18
|
+
if (from2 && typeof from2 === "object" || typeof from2 === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from2))
|
|
9
20
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () =>
|
|
21
|
+
__defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
|
|
11
22
|
}
|
|
12
23
|
return to;
|
|
13
24
|
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
|
|
27
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
28
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
29
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
30
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
31
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
32
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
33
|
+
return value;
|
|
34
|
+
};
|
|
35
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
36
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
37
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
38
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
39
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
40
|
+
return __privateGet(this, extra);
|
|
41
|
+
}, set [name](x) {
|
|
42
|
+
return __privateSet(this, extra, x);
|
|
43
|
+
} }, name));
|
|
44
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
45
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
46
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
47
|
+
if (k) {
|
|
48
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
49
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
50
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
51
|
+
}
|
|
52
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
53
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
54
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
55
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
56
|
+
}
|
|
57
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
58
|
+
};
|
|
59
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
60
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
61
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
62
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
63
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
16
64
|
|
|
17
65
|
// src/compat/nestjs/index.ts
|
|
18
66
|
var nestjs_exports = {};
|
|
67
|
+
__export(nestjs_exports, {
|
|
68
|
+
ACTOR_KEY: () => ACTOR_KEY,
|
|
69
|
+
COMMAND_HANDLERS: () => COMMAND_HANDLERS,
|
|
70
|
+
CQRS_EVENT_HANDLERS: () => CQRS_EVENT_HANDLERS,
|
|
71
|
+
CRON_HANDLERS: () => CRON_HANDLERS,
|
|
72
|
+
CommandHandler: () => CommandHandler,
|
|
73
|
+
EVENT_HANDLERS: () => EVENT_HANDLERS,
|
|
74
|
+
EventHandler: () => EventHandler,
|
|
75
|
+
GRAPHREFLY_REQUEST_GRAPH: () => GRAPHREFLY_REQUEST_GRAPH,
|
|
76
|
+
GRAPHREFLY_ROOT_GRAPH: () => GRAPHREFLY_ROOT_GRAPH,
|
|
77
|
+
GraphCron: () => GraphCron,
|
|
78
|
+
GraphInterval: () => GraphInterval,
|
|
79
|
+
GraphReflyEventExplorer: () => GraphReflyEventExplorer,
|
|
80
|
+
GraphReflyGuard: () => GraphReflyGuard,
|
|
81
|
+
GraphReflyGuardImpl: () => GraphReflyGuardImpl,
|
|
82
|
+
GraphReflyModule: () => GraphReflyModule,
|
|
83
|
+
INTERVAL_HANDLERS: () => INTERVAL_HANDLERS,
|
|
84
|
+
InjectCqrsGraph: () => InjectCqrsGraph,
|
|
85
|
+
InjectGraph: () => InjectGraph,
|
|
86
|
+
InjectNode: () => InjectNode,
|
|
87
|
+
ObserveGateway: () => ObserveGateway,
|
|
88
|
+
OnGraphEvent: () => OnGraphEvent,
|
|
89
|
+
QUERY_HANDLERS: () => QUERY_HANDLERS,
|
|
90
|
+
QueryHandler: () => QueryHandler,
|
|
91
|
+
SAGA_HANDLERS: () => SAGA_HANDLERS,
|
|
92
|
+
SagaHandler: () => SagaHandler,
|
|
93
|
+
fromHeader: () => fromHeader,
|
|
94
|
+
fromJwtPayload: () => fromJwtPayload,
|
|
95
|
+
getActor: () => getActor,
|
|
96
|
+
getGraphToken: () => getGraphToken,
|
|
97
|
+
getNodeToken: () => getNodeToken,
|
|
98
|
+
observeSSE: () => observeSSE,
|
|
99
|
+
observeSubscription: () => observeSubscription,
|
|
100
|
+
toObservable: () => toObservable2
|
|
101
|
+
});
|
|
19
102
|
module.exports = __toCommonJS(nestjs_exports);
|
|
20
|
-
|
|
103
|
+
|
|
104
|
+
// src/compat/nestjs/decorators.ts
|
|
105
|
+
var import_common = require("@nestjs/common");
|
|
106
|
+
|
|
107
|
+
// src/compat/nestjs/tokens.ts
|
|
108
|
+
var GRAPHREFLY_ROOT_GRAPH = /* @__PURE__ */ Symbol.for("graphrefly:root-graph");
|
|
109
|
+
var GRAPHREFLY_REQUEST_GRAPH = /* @__PURE__ */ Symbol.for("graphrefly:request-graph");
|
|
110
|
+
function getGraphToken(name) {
|
|
111
|
+
return /* @__PURE__ */ Symbol.for(`graphrefly:graph:${name}`);
|
|
112
|
+
}
|
|
113
|
+
function getNodeToken(path) {
|
|
114
|
+
return /* @__PURE__ */ Symbol.for(`graphrefly:node:${path}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/compat/nestjs/decorators.ts
|
|
118
|
+
var EVENT_HANDLERS = /* @__PURE__ */ new Map();
|
|
119
|
+
var INTERVAL_HANDLERS = /* @__PURE__ */ new Map();
|
|
120
|
+
var CRON_HANDLERS = /* @__PURE__ */ new Map();
|
|
121
|
+
var COMMAND_HANDLERS = /* @__PURE__ */ new Map();
|
|
122
|
+
var CQRS_EVENT_HANDLERS = /* @__PURE__ */ new Map();
|
|
123
|
+
var QUERY_HANDLERS = /* @__PURE__ */ new Map();
|
|
124
|
+
var SAGA_HANDLERS = /* @__PURE__ */ new Map();
|
|
125
|
+
function InjectGraph(name) {
|
|
126
|
+
if (name === "request") return (0, import_common.Inject)(GRAPHREFLY_REQUEST_GRAPH);
|
|
127
|
+
return (0, import_common.Inject)(name ? getGraphToken(name) : GRAPHREFLY_ROOT_GRAPH);
|
|
128
|
+
}
|
|
129
|
+
function InjectCqrsGraph(name) {
|
|
130
|
+
return (0, import_common.Inject)(getGraphToken(name));
|
|
131
|
+
}
|
|
132
|
+
function InjectNode(path) {
|
|
133
|
+
return (0, import_common.Inject)(getNodeToken(path));
|
|
134
|
+
}
|
|
135
|
+
function OnGraphEvent(nodeName) {
|
|
136
|
+
return (_value, context) => {
|
|
137
|
+
const methodKey = context.name;
|
|
138
|
+
context.addInitializer(function() {
|
|
139
|
+
const ctor = this.constructor;
|
|
140
|
+
const existing = EVENT_HANDLERS.get(ctor) ?? [];
|
|
141
|
+
existing.push({ nodeName, methodKey });
|
|
142
|
+
EVENT_HANDLERS.set(ctor, existing);
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function GraphInterval(ms) {
|
|
147
|
+
return (_value, context) => {
|
|
148
|
+
const methodKey = context.name;
|
|
149
|
+
context.addInitializer(function() {
|
|
150
|
+
const ctor = this.constructor;
|
|
151
|
+
const existing = INTERVAL_HANDLERS.get(ctor) ?? [];
|
|
152
|
+
existing.push({ ms, methodKey });
|
|
153
|
+
INTERVAL_HANDLERS.set(ctor, existing);
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function GraphCron(expr) {
|
|
158
|
+
return (_value, context) => {
|
|
159
|
+
const methodKey = context.name;
|
|
160
|
+
context.addInitializer(function() {
|
|
161
|
+
const ctor = this.constructor;
|
|
162
|
+
const existing = CRON_HANDLERS.get(ctor) ?? [];
|
|
163
|
+
existing.push({ expr, methodKey });
|
|
164
|
+
CRON_HANDLERS.set(ctor, existing);
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function CommandHandler(cqrsName, commandName) {
|
|
169
|
+
return (_value, context) => {
|
|
170
|
+
const methodKey = context.name;
|
|
171
|
+
context.addInitializer(function() {
|
|
172
|
+
const ctor = this.constructor;
|
|
173
|
+
const existing = COMMAND_HANDLERS.get(ctor) ?? [];
|
|
174
|
+
existing.push({ cqrsName, commandName, methodKey });
|
|
175
|
+
COMMAND_HANDLERS.set(ctor, existing);
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function EventHandler(cqrsName, eventName) {
|
|
180
|
+
return (_value, context) => {
|
|
181
|
+
const methodKey = context.name;
|
|
182
|
+
context.addInitializer(function() {
|
|
183
|
+
const ctor = this.constructor;
|
|
184
|
+
const existing = CQRS_EVENT_HANDLERS.get(ctor) ?? [];
|
|
185
|
+
existing.push({ cqrsName, eventName, methodKey });
|
|
186
|
+
CQRS_EVENT_HANDLERS.set(ctor, existing);
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function QueryHandler(cqrsName, projectionName) {
|
|
191
|
+
return (_value, context) => {
|
|
192
|
+
const methodKey = context.name;
|
|
193
|
+
context.addInitializer(function() {
|
|
194
|
+
const ctor = this.constructor;
|
|
195
|
+
const existing = QUERY_HANDLERS.get(ctor) ?? [];
|
|
196
|
+
existing.push({ cqrsName, projectionName, methodKey });
|
|
197
|
+
QUERY_HANDLERS.set(ctor, existing);
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function SagaHandler(cqrsName, sagaName, eventNames) {
|
|
202
|
+
return (_value, context) => {
|
|
203
|
+
const methodKey = context.name;
|
|
204
|
+
context.addInitializer(function() {
|
|
205
|
+
const ctor = this.constructor;
|
|
206
|
+
const existing = SAGA_HANDLERS.get(ctor) ?? [];
|
|
207
|
+
existing.push({ cqrsName, eventNames, sagaName, methodKey });
|
|
208
|
+
SAGA_HANDLERS.set(ctor, existing);
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/compat/nestjs/explorer.ts
|
|
214
|
+
var import_core2 = require("@graphrefly/pure-ts/core");
|
|
215
|
+
var import_extra = require("@graphrefly/pure-ts/extra");
|
|
216
|
+
|
|
217
|
+
// src/base/sources/event/cron.ts
|
|
218
|
+
var import_core = require("@graphrefly/pure-ts/core");
|
|
219
|
+
function sourceOpts(opts) {
|
|
220
|
+
return { describeKind: "producer", ...opts };
|
|
221
|
+
}
|
|
222
|
+
function parseField(field, min, max) {
|
|
223
|
+
const result = /* @__PURE__ */ new Set();
|
|
224
|
+
for (const part of field.split(",")) {
|
|
225
|
+
const [range, stepStr] = part.split("/");
|
|
226
|
+
const step = stepStr ? Number.parseInt(stepStr, 10) : 1;
|
|
227
|
+
if (Number.isNaN(step) || step < 1) throw new Error(`Invalid cron step: ${part}`);
|
|
228
|
+
let start;
|
|
229
|
+
let end;
|
|
230
|
+
if (range === "*") {
|
|
231
|
+
start = min;
|
|
232
|
+
end = max;
|
|
233
|
+
} else if (range.includes("-")) {
|
|
234
|
+
const [a, b] = range.split("-");
|
|
235
|
+
start = Number.parseInt(a, 10);
|
|
236
|
+
end = Number.parseInt(b, 10);
|
|
237
|
+
} else {
|
|
238
|
+
start = Number.parseInt(range, 10);
|
|
239
|
+
end = start;
|
|
240
|
+
}
|
|
241
|
+
if (Number.isNaN(start) || Number.isNaN(end)) throw new Error(`Invalid cron field: ${field}`);
|
|
242
|
+
if (start < min || end > max)
|
|
243
|
+
throw new Error(`Cron field out of range: ${field} (${min}-${max})`);
|
|
244
|
+
if (start > end) throw new Error(`Invalid cron range: ${start}-${end} in ${field}`);
|
|
245
|
+
for (let i = start; i <= end; i += step) result.add(i);
|
|
246
|
+
}
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
function parseCron(expr) {
|
|
250
|
+
const parts = expr.trim().split(/\s+/);
|
|
251
|
+
if (parts.length !== 5) throw new Error(`Invalid cron: expected 5 fields, got ${parts.length}`);
|
|
252
|
+
return {
|
|
253
|
+
minutes: parseField(parts[0], 0, 59),
|
|
254
|
+
hours: parseField(parts[1], 0, 23),
|
|
255
|
+
daysOfMonth: parseField(parts[2], 1, 31),
|
|
256
|
+
months: parseField(parts[3], 1, 12),
|
|
257
|
+
daysOfWeek: parseField(parts[4], 0, 6)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function matchesCron(schedule, date) {
|
|
261
|
+
return schedule.minutes.has(date.getMinutes()) && schedule.hours.has(date.getHours()) && schedule.daysOfMonth.has(date.getDate()) && schedule.months.has(date.getMonth() + 1) && schedule.daysOfWeek.has(date.getDay());
|
|
262
|
+
}
|
|
263
|
+
function fromCron(expr, opts) {
|
|
264
|
+
const schedule = parseCron(expr);
|
|
265
|
+
const { tickMs: tickOpt, output, ...rest } = opts ?? {};
|
|
266
|
+
const tickMs = tickOpt ?? 6e4;
|
|
267
|
+
const emitDate = output === "date";
|
|
268
|
+
return (0, import_core.node)(
|
|
269
|
+
(_data, a) => {
|
|
270
|
+
let lastFiredKey = -1;
|
|
271
|
+
const check = () => {
|
|
272
|
+
const now = /* @__PURE__ */ new Date();
|
|
273
|
+
const key = now.getFullYear() * 1e8 + (now.getMonth() + 1) * 1e6 + now.getDate() * 1e4 + now.getHours() * 100 + now.getMinutes();
|
|
274
|
+
if (key !== lastFiredKey && matchesCron(schedule, now)) {
|
|
275
|
+
lastFiredKey = key;
|
|
276
|
+
a.emit(emitDate ? now : (0, import_core.wallClockNs)());
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
check();
|
|
280
|
+
const id = setInterval(check, tickMs);
|
|
281
|
+
return () => clearInterval(id);
|
|
282
|
+
},
|
|
283
|
+
{ ...sourceOpts(rest), name: rest.name ?? `cron:${expr}` }
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/compat/nestjs/explorer.ts
|
|
288
|
+
var scheduleSeq = 0;
|
|
289
|
+
var GraphReflyEventExplorer = class {
|
|
290
|
+
constructor(graph, moduleRef) {
|
|
291
|
+
this.graph = graph;
|
|
292
|
+
this.moduleRef = moduleRef;
|
|
293
|
+
}
|
|
294
|
+
disposers = [];
|
|
295
|
+
scheduleNodeNames = [];
|
|
296
|
+
onModuleInit() {
|
|
297
|
+
this.wireEvents();
|
|
298
|
+
this.wireIntervals();
|
|
299
|
+
this.wireCrons();
|
|
300
|
+
this.wireCqrsCommands();
|
|
301
|
+
this.wireCqrsEvents();
|
|
302
|
+
this.wireCqrsQueries();
|
|
303
|
+
this.wireCqrsSagas();
|
|
304
|
+
}
|
|
305
|
+
onModuleDestroy() {
|
|
306
|
+
for (const dispose of this.disposers) dispose();
|
|
307
|
+
this.disposers.length = 0;
|
|
308
|
+
for (const name of this.scheduleNodeNames) {
|
|
309
|
+
try {
|
|
310
|
+
this.graph.remove(name);
|
|
311
|
+
} catch {
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
this.scheduleNodeNames.length = 0;
|
|
315
|
+
}
|
|
316
|
+
// -----------------------------------------------------------------------
|
|
317
|
+
// @OnGraphEvent — reactive subscription via graph.observe()
|
|
318
|
+
// -----------------------------------------------------------------------
|
|
319
|
+
wireEvents() {
|
|
320
|
+
for (const [ctor, metas] of EVENT_HANDLERS) {
|
|
321
|
+
const instance = this.resolveInstance(ctor);
|
|
322
|
+
if (!instance) continue;
|
|
323
|
+
for (const meta of metas) {
|
|
324
|
+
this.wireEventHandler(instance, meta);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
wireEventHandler(instance, meta) {
|
|
329
|
+
const method = instance[meta.methodKey];
|
|
330
|
+
if (typeof method !== "function") return;
|
|
331
|
+
const bound = method.bind(instance);
|
|
332
|
+
const handle = this.observeNode(meta.nodeName);
|
|
333
|
+
const unsub = handle.subscribe((msgs) => {
|
|
334
|
+
for (const m of msgs) {
|
|
335
|
+
if (m[0] === import_core2.DATA) {
|
|
336
|
+
bound(m[1]);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
this.disposers.push(unsub);
|
|
341
|
+
}
|
|
342
|
+
// -----------------------------------------------------------------------
|
|
343
|
+
// @GraphInterval — reactive via fromTimer central timer primitive
|
|
344
|
+
// -----------------------------------------------------------------------
|
|
345
|
+
wireIntervals() {
|
|
346
|
+
for (const [ctor, metas] of INTERVAL_HANDLERS) {
|
|
347
|
+
const instance = this.resolveInstance(ctor);
|
|
348
|
+
if (!instance) continue;
|
|
349
|
+
for (const meta of metas) {
|
|
350
|
+
this.wireIntervalHandler(instance, ctor, meta);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
wireIntervalHandler(instance, ctor, meta) {
|
|
355
|
+
const method = instance[meta.methodKey];
|
|
356
|
+
if (typeof method !== "function") return;
|
|
357
|
+
const bound = method.bind(instance);
|
|
358
|
+
const className = ctor.name ?? "anonymous";
|
|
359
|
+
const nodeName = `__schedule__.${className}.${String(meta.methodKey)}.${scheduleSeq++}`;
|
|
360
|
+
const timerNode = (0, import_extra.fromTimer)(meta.ms, { period: meta.ms, name: nodeName });
|
|
361
|
+
this.graph.add(timerNode);
|
|
362
|
+
this.scheduleNodeNames.push(nodeName);
|
|
363
|
+
const handle = this.observeNode(nodeName);
|
|
364
|
+
const unsub = handle.subscribe((msgs) => {
|
|
365
|
+
for (const m of msgs) {
|
|
366
|
+
if (m[0] === import_core2.DATA) bound(m[1]);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
this.disposers.push(unsub);
|
|
370
|
+
}
|
|
371
|
+
// -----------------------------------------------------------------------
|
|
372
|
+
// @GraphCron — reactive via fromCron central timer primitive
|
|
373
|
+
// -----------------------------------------------------------------------
|
|
374
|
+
wireCrons() {
|
|
375
|
+
for (const [ctor, metas] of CRON_HANDLERS) {
|
|
376
|
+
const instance = this.resolveInstance(ctor);
|
|
377
|
+
if (!instance) continue;
|
|
378
|
+
for (const meta of metas) {
|
|
379
|
+
this.wireCronHandler(instance, ctor, meta);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
wireCronHandler(instance, ctor, meta) {
|
|
384
|
+
const method = instance[meta.methodKey];
|
|
385
|
+
if (typeof method !== "function") return;
|
|
386
|
+
const bound = method.bind(instance);
|
|
387
|
+
const className = ctor.name ?? "anonymous";
|
|
388
|
+
const nodeName = `__schedule__.${className}.${String(meta.methodKey)}.${scheduleSeq++}`;
|
|
389
|
+
const cronNode = fromCron(meta.expr, { name: nodeName });
|
|
390
|
+
this.graph.add(cronNode);
|
|
391
|
+
this.scheduleNodeNames.push(nodeName);
|
|
392
|
+
const handle = this.observeNode(nodeName);
|
|
393
|
+
const unsub = handle.subscribe((msgs) => {
|
|
394
|
+
for (const m of msgs) {
|
|
395
|
+
if (m[0] === import_core2.DATA) bound(m[1]);
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
this.disposers.push(unsub);
|
|
399
|
+
}
|
|
400
|
+
// -----------------------------------------------------------------------
|
|
401
|
+
// @CommandHandler — register method as CqrsGraph command handler
|
|
402
|
+
// -----------------------------------------------------------------------
|
|
403
|
+
wireCqrsCommands() {
|
|
404
|
+
for (const [ctor, metas] of COMMAND_HANDLERS) {
|
|
405
|
+
const instance = this.resolveInstance(ctor);
|
|
406
|
+
if (!instance) continue;
|
|
407
|
+
for (const meta of metas) {
|
|
408
|
+
this.wireCqrsCommand(instance, meta);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
wireCqrsCommand(instance, meta) {
|
|
413
|
+
const method = instance[meta.methodKey];
|
|
414
|
+
if (typeof method !== "function") return;
|
|
415
|
+
const bound = method.bind(instance);
|
|
416
|
+
const cqrsGraph = this.resolveCqrsGraph(meta.cqrsName);
|
|
417
|
+
if (!cqrsGraph) return;
|
|
418
|
+
cqrsGraph.command(meta.commandName, bound);
|
|
419
|
+
}
|
|
420
|
+
// -----------------------------------------------------------------------
|
|
421
|
+
// @EventHandler — subscribe method to CQRS event stream
|
|
422
|
+
// -----------------------------------------------------------------------
|
|
423
|
+
wireCqrsEvents() {
|
|
424
|
+
for (const [ctor, metas] of CQRS_EVENT_HANDLERS) {
|
|
425
|
+
const instance = this.resolveInstance(ctor);
|
|
426
|
+
if (!instance) continue;
|
|
427
|
+
for (const meta of metas) {
|
|
428
|
+
this.wireCqrsEventHandler(instance, meta);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
wireCqrsEventHandler(instance, meta) {
|
|
433
|
+
const method = instance[meta.methodKey];
|
|
434
|
+
if (typeof method !== "function") return;
|
|
435
|
+
const bound = method.bind(instance);
|
|
436
|
+
const cqrsGraph = this.resolveCqrsGraph(meta.cqrsName);
|
|
437
|
+
if (!cqrsGraph) return;
|
|
438
|
+
cqrsGraph.event(meta.eventName);
|
|
439
|
+
const eventNode = cqrsGraph.resolve(meta.eventName);
|
|
440
|
+
const existingEntries = eventNode.cache;
|
|
441
|
+
let lastSeq = existingEntries && existingEntries.length > 0 ? existingEntries[existingEntries.length - 1].seq : 0;
|
|
442
|
+
const handle = this.observeNodeOn(cqrsGraph, meta.eventName);
|
|
443
|
+
const unsub = handle.subscribe((msgs) => {
|
|
444
|
+
for (const m of msgs) {
|
|
445
|
+
if (m[0] === import_core2.DATA) {
|
|
446
|
+
const entries = m[1];
|
|
447
|
+
for (const entry of entries) {
|
|
448
|
+
if (entry.seq > lastSeq) {
|
|
449
|
+
bound(entry);
|
|
450
|
+
lastSeq = entry.seq;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
this.disposers.push(unsub);
|
|
457
|
+
}
|
|
458
|
+
// -----------------------------------------------------------------------
|
|
459
|
+
// @QueryHandler — subscribe method to CQRS projection changes
|
|
460
|
+
// -----------------------------------------------------------------------
|
|
461
|
+
wireCqrsQueries() {
|
|
462
|
+
for (const [ctor, metas] of QUERY_HANDLERS) {
|
|
463
|
+
const instance = this.resolveInstance(ctor);
|
|
464
|
+
if (!instance) continue;
|
|
465
|
+
for (const meta of metas) {
|
|
466
|
+
this.wireCqrsQuery(instance, meta);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
wireCqrsQuery(instance, meta) {
|
|
471
|
+
const method = instance[meta.methodKey];
|
|
472
|
+
if (typeof method !== "function") return;
|
|
473
|
+
const bound = method.bind(instance);
|
|
474
|
+
const cqrsGraph = this.resolveCqrsGraph(meta.cqrsName);
|
|
475
|
+
if (!cqrsGraph) return;
|
|
476
|
+
const handle = this.observeNodeOn(cqrsGraph, meta.projectionName);
|
|
477
|
+
const unsub = handle.subscribe((msgs) => {
|
|
478
|
+
for (const m of msgs) {
|
|
479
|
+
if (m[0] === import_core2.DATA) {
|
|
480
|
+
bound(m[1]);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
this.disposers.push(unsub);
|
|
485
|
+
}
|
|
486
|
+
// -----------------------------------------------------------------------
|
|
487
|
+
// @SagaHandler — register method as CqrsGraph saga (subgraph side effect)
|
|
488
|
+
// -----------------------------------------------------------------------
|
|
489
|
+
wireCqrsSagas() {
|
|
490
|
+
for (const [ctor, metas] of SAGA_HANDLERS) {
|
|
491
|
+
const instance = this.resolveInstance(ctor);
|
|
492
|
+
if (!instance) continue;
|
|
493
|
+
for (const meta of metas) {
|
|
494
|
+
this.wireCqrsSaga(instance, meta);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
wireCqrsSaga(instance, meta) {
|
|
499
|
+
const method = instance[meta.methodKey];
|
|
500
|
+
if (typeof method !== "function") return;
|
|
501
|
+
const bound = method.bind(instance);
|
|
502
|
+
const cqrsGraph = this.resolveCqrsGraph(meta.cqrsName);
|
|
503
|
+
if (!cqrsGraph) return;
|
|
504
|
+
cqrsGraph.saga(meta.sagaName, meta.eventNames, bound);
|
|
505
|
+
}
|
|
506
|
+
// -----------------------------------------------------------------------
|
|
507
|
+
// Helpers
|
|
508
|
+
// -----------------------------------------------------------------------
|
|
509
|
+
observeNode(name) {
|
|
510
|
+
return this.graph.observe(name);
|
|
511
|
+
}
|
|
512
|
+
observeNodeOn(graph, name) {
|
|
513
|
+
return graph.observe(name);
|
|
514
|
+
}
|
|
515
|
+
resolveCqrsGraph(name) {
|
|
516
|
+
try {
|
|
517
|
+
return this.moduleRef.get(getGraphToken(name), { strict: false });
|
|
518
|
+
} catch {
|
|
519
|
+
console.warn(
|
|
520
|
+
`[GraphReFly] CqrsGraph "${name}" not found in DI \u2014 did you import GraphReflyModule.forCqrs({ name: "${name}" })?`
|
|
521
|
+
);
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
resolveInstance(ctor) {
|
|
526
|
+
try {
|
|
527
|
+
return this.moduleRef.get(ctor, { strict: false });
|
|
528
|
+
} catch {
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// src/compat/nestjs/gateway.ts
|
|
535
|
+
var import_core4 = require("@graphrefly/pure-ts/core");
|
|
536
|
+
|
|
537
|
+
// src/base/composition/backpressure.ts
|
|
538
|
+
var import_core3 = require("@graphrefly/pure-ts/core");
|
|
539
|
+
var nextLockId = 0;
|
|
540
|
+
function createWatermarkController(sendUp, opts) {
|
|
541
|
+
if (opts.highWaterMark < 1) throw new RangeError("highWaterMark must be >= 1");
|
|
542
|
+
if (opts.lowWaterMark < 0) throw new RangeError("lowWaterMark must be >= 0");
|
|
543
|
+
if (opts.lowWaterMark >= opts.highWaterMark)
|
|
544
|
+
throw new RangeError("lowWaterMark must be < highWaterMark");
|
|
545
|
+
const lockId = /* @__PURE__ */ Symbol(`bp-${++nextLockId}`);
|
|
546
|
+
let pending = 0;
|
|
547
|
+
let paused = false;
|
|
548
|
+
return {
|
|
549
|
+
onEnqueue() {
|
|
550
|
+
pending += 1;
|
|
551
|
+
if (!paused && pending >= opts.highWaterMark) {
|
|
552
|
+
paused = true;
|
|
553
|
+
sendUp([[import_core3.PAUSE, lockId]]);
|
|
554
|
+
return true;
|
|
555
|
+
}
|
|
556
|
+
return false;
|
|
557
|
+
},
|
|
558
|
+
onDequeue() {
|
|
559
|
+
if (pending > 0) pending -= 1;
|
|
560
|
+
if (paused && pending <= opts.lowWaterMark) {
|
|
561
|
+
paused = false;
|
|
562
|
+
sendUp([[import_core3.RESUME, lockId]]);
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
565
|
+
return false;
|
|
566
|
+
},
|
|
567
|
+
get pending() {
|
|
568
|
+
return pending;
|
|
569
|
+
},
|
|
570
|
+
get paused() {
|
|
571
|
+
return paused;
|
|
572
|
+
},
|
|
573
|
+
dispose() {
|
|
574
|
+
if (paused) {
|
|
575
|
+
paused = false;
|
|
576
|
+
sendUp([[import_core3.RESUME, lockId]]);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// src/compat/nestjs/gateway.ts
|
|
583
|
+
function observeSSE(graph, path, opts) {
|
|
584
|
+
const { actor, serialize = defaultSerialize, keepAliveMs, signal } = opts ?? {};
|
|
585
|
+
const encoder = new TextEncoder();
|
|
586
|
+
let stop;
|
|
587
|
+
const useBackpressure = opts?.highWaterMark != null;
|
|
588
|
+
let wm;
|
|
589
|
+
let pullResolve;
|
|
590
|
+
const taggedBuf = [];
|
|
591
|
+
let closed = false;
|
|
592
|
+
return new ReadableStream({
|
|
593
|
+
start(controller) {
|
|
594
|
+
let keepAlive;
|
|
595
|
+
let unsub = () => {
|
|
596
|
+
};
|
|
597
|
+
const close = () => {
|
|
598
|
+
if (closed) return;
|
|
599
|
+
closed = true;
|
|
600
|
+
if (keepAlive !== void 0) clearInterval(keepAlive);
|
|
601
|
+
signal?.removeEventListener("abort", onAbort);
|
|
602
|
+
unsub();
|
|
603
|
+
wm?.dispose();
|
|
604
|
+
pullResolve?.();
|
|
605
|
+
pullResolve = void 0;
|
|
606
|
+
for (const entry of taggedBuf) controller.enqueue(entry.frame);
|
|
607
|
+
taggedBuf.length = 0;
|
|
608
|
+
controller.close();
|
|
609
|
+
};
|
|
610
|
+
stop = close;
|
|
611
|
+
const onAbort = () => close();
|
|
612
|
+
const handle = graph.observe(path, { actor });
|
|
613
|
+
if (useBackpressure) {
|
|
614
|
+
wm = createWatermarkController((msgs) => handle.up(msgs), {
|
|
615
|
+
highWaterMark: opts.highWaterMark,
|
|
616
|
+
lowWaterMark: opts.lowWaterMark ?? Math.floor(opts.highWaterMark / 2)
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
unsub = handle.subscribe((msgs) => {
|
|
620
|
+
for (const msg of msgs) {
|
|
621
|
+
if (closed) return;
|
|
622
|
+
const t = msg[0];
|
|
623
|
+
if (t === import_core4.DATA) {
|
|
624
|
+
const frame = encoder.encode(sseFrame("data", serialize(msg[1])));
|
|
625
|
+
if (useBackpressure) {
|
|
626
|
+
taggedBuf.push({ frame, counted: true });
|
|
627
|
+
wm.onEnqueue();
|
|
628
|
+
pullResolve?.();
|
|
629
|
+
pullResolve = void 0;
|
|
630
|
+
} else {
|
|
631
|
+
controller.enqueue(frame);
|
|
632
|
+
}
|
|
633
|
+
} else if (t === import_core4.ERROR) {
|
|
634
|
+
const frame = encoder.encode(sseFrame("error", serialize(msg[1])));
|
|
635
|
+
if (useBackpressure) {
|
|
636
|
+
taggedBuf.push({ frame, counted: false });
|
|
637
|
+
pullResolve?.();
|
|
638
|
+
pullResolve = void 0;
|
|
639
|
+
} else {
|
|
640
|
+
controller.enqueue(frame);
|
|
641
|
+
}
|
|
642
|
+
close();
|
|
643
|
+
return;
|
|
644
|
+
} else if (t === import_core4.COMPLETE || t === import_core4.TEARDOWN) {
|
|
645
|
+
if (t === import_core4.COMPLETE) {
|
|
646
|
+
const frame = encoder.encode(sseFrame("complete"));
|
|
647
|
+
if (useBackpressure) {
|
|
648
|
+
taggedBuf.push({ frame, counted: false });
|
|
649
|
+
pullResolve?.();
|
|
650
|
+
pullResolve = void 0;
|
|
651
|
+
} else {
|
|
652
|
+
controller.enqueue(frame);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
close();
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
if (keepAliveMs !== void 0 && keepAliveMs > 0) {
|
|
661
|
+
keepAlive = setInterval(() => {
|
|
662
|
+
if (closed) return;
|
|
663
|
+
if (useBackpressure) {
|
|
664
|
+
taggedBuf.push({ frame: encoder.encode(": keepalive\n\n"), counted: false });
|
|
665
|
+
pullResolve?.();
|
|
666
|
+
pullResolve = void 0;
|
|
667
|
+
} else {
|
|
668
|
+
controller.enqueue(encoder.encode(": keepalive\n\n"));
|
|
669
|
+
}
|
|
670
|
+
}, keepAliveMs);
|
|
671
|
+
}
|
|
672
|
+
if (signal?.aborted) onAbort();
|
|
673
|
+
else signal?.addEventListener("abort", onAbort, { once: true });
|
|
674
|
+
},
|
|
675
|
+
pull(controller) {
|
|
676
|
+
if (!useBackpressure) return;
|
|
677
|
+
if (closed) return;
|
|
678
|
+
if (taggedBuf.length > 0) {
|
|
679
|
+
const entry = taggedBuf.shift();
|
|
680
|
+
controller.enqueue(entry.frame);
|
|
681
|
+
if (entry.counted) wm.onDequeue();
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
return new Promise((resolve) => {
|
|
685
|
+
pullResolve = resolve;
|
|
686
|
+
});
|
|
687
|
+
},
|
|
688
|
+
cancel() {
|
|
689
|
+
try {
|
|
690
|
+
stop?.();
|
|
691
|
+
} catch {
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
function observeSubscription(graph, path, opts) {
|
|
697
|
+
const { actor, filter } = opts ?? {};
|
|
698
|
+
const queue = [];
|
|
699
|
+
const waiters = [];
|
|
700
|
+
let disposed = false;
|
|
701
|
+
const handle = graph.observe(path, { actor });
|
|
702
|
+
const wm = opts?.highWaterMark != null ? createWatermarkController((msgs) => handle.up(msgs), {
|
|
703
|
+
highWaterMark: opts.highWaterMark,
|
|
704
|
+
lowWaterMark: opts.lowWaterMark ?? Math.floor(opts.highWaterMark / 2)
|
|
705
|
+
}) : void 0;
|
|
706
|
+
const dispose = () => {
|
|
707
|
+
if (disposed) return;
|
|
708
|
+
disposed = true;
|
|
709
|
+
wm?.dispose();
|
|
710
|
+
unsub();
|
|
711
|
+
};
|
|
712
|
+
const push = (item) => {
|
|
713
|
+
if (disposed) return;
|
|
714
|
+
if (waiters.length > 0) {
|
|
715
|
+
const w = waiters.shift();
|
|
716
|
+
if (item.done && item.error) w.reject(item.error);
|
|
717
|
+
else if (item.done) w.resolve({ done: true, value: void 0 });
|
|
718
|
+
else w.resolve({ done: false, value: item.value });
|
|
719
|
+
} else {
|
|
720
|
+
queue.push(item);
|
|
721
|
+
if (!item.done) wm?.onEnqueue();
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
const unsub = handle.subscribe((msgs) => {
|
|
725
|
+
for (const msg of msgs) {
|
|
726
|
+
const t = msg[0];
|
|
727
|
+
if (t === import_core4.DATA) {
|
|
728
|
+
const value = msg[1];
|
|
729
|
+
if (filter && !filter(value)) continue;
|
|
730
|
+
push({ done: false, value });
|
|
731
|
+
} else if (t === import_core4.ERROR) {
|
|
732
|
+
const err = msg[1] instanceof Error ? msg[1] : new Error(String(msg[1]));
|
|
733
|
+
push({ done: true, error: err });
|
|
734
|
+
dispose();
|
|
735
|
+
return;
|
|
736
|
+
} else if (t === import_core4.COMPLETE || t === import_core4.TEARDOWN) {
|
|
737
|
+
push({ done: true });
|
|
738
|
+
dispose();
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
const iterator = {
|
|
744
|
+
next() {
|
|
745
|
+
if (queue.length > 0) {
|
|
746
|
+
const item = queue.shift();
|
|
747
|
+
if (!item.done) wm?.onDequeue();
|
|
748
|
+
if (item.done && item.error) return Promise.reject(item.error);
|
|
749
|
+
return Promise.resolve(
|
|
750
|
+
item.done ? { done: true, value: void 0 } : { done: false, value: item.value }
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
if (disposed) return Promise.resolve({ done: true, value: void 0 });
|
|
754
|
+
return new Promise((resolve, reject) => {
|
|
755
|
+
waiters.push({ resolve, reject });
|
|
756
|
+
});
|
|
757
|
+
},
|
|
758
|
+
return() {
|
|
759
|
+
dispose();
|
|
760
|
+
for (const w of waiters) w.resolve({ done: true, value: void 0 });
|
|
761
|
+
waiters.length = 0;
|
|
762
|
+
return Promise.resolve({ done: true, value: void 0 });
|
|
763
|
+
},
|
|
764
|
+
throw(err) {
|
|
765
|
+
dispose();
|
|
766
|
+
return Promise.reject(err);
|
|
767
|
+
},
|
|
768
|
+
[Symbol.asyncIterator]() {
|
|
769
|
+
return this;
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
return iterator;
|
|
773
|
+
}
|
|
774
|
+
var ObserveGateway = class {
|
|
775
|
+
constructor(graph, opts) {
|
|
776
|
+
this.graph = graph;
|
|
777
|
+
this.extractActor = opts?.extractActor ?? (() => void 0);
|
|
778
|
+
this.parse = opts?.parse ?? defaultParseCommand;
|
|
779
|
+
this.highWaterMark = opts?.highWaterMark;
|
|
780
|
+
this.lowWaterMark = opts?.lowWaterMark;
|
|
781
|
+
}
|
|
782
|
+
clients = /* @__PURE__ */ new Map();
|
|
783
|
+
extractActor;
|
|
784
|
+
parse;
|
|
785
|
+
highWaterMark;
|
|
786
|
+
lowWaterMark;
|
|
787
|
+
/**
|
|
788
|
+
* Register a new client. Call from `handleConnection`.
|
|
789
|
+
*/
|
|
790
|
+
handleConnection(client) {
|
|
791
|
+
if (!this.clients.has(client)) {
|
|
792
|
+
this.clients.set(client, /* @__PURE__ */ new Map());
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Unregister a client and dispose all its subscriptions. Call from `handleDisconnect`.
|
|
797
|
+
*/
|
|
798
|
+
handleDisconnect(client) {
|
|
799
|
+
const subs = this.clients.get(client);
|
|
800
|
+
if (!subs) return;
|
|
801
|
+
for (const entry of subs.values()) {
|
|
802
|
+
entry.wm?.dispose();
|
|
803
|
+
entry.unsub();
|
|
804
|
+
}
|
|
805
|
+
this.clients.delete(client);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Handle an incoming client message (subscribe/unsubscribe/ack command).
|
|
809
|
+
*
|
|
810
|
+
* @param client - The WebSocket client reference.
|
|
811
|
+
* @param raw - Raw message data (string or parsed object).
|
|
812
|
+
* @param send - Function to send a message back to the client.
|
|
813
|
+
* Defaults to `client.send(JSON.stringify(msg))`.
|
|
814
|
+
*/
|
|
815
|
+
handleMessage(client, raw, send) {
|
|
816
|
+
const sender = send ?? defaultSend.bind(null, client);
|
|
817
|
+
let cmd;
|
|
818
|
+
try {
|
|
819
|
+
cmd = typeof raw === "string" ? this.parse(raw) : raw;
|
|
820
|
+
} catch {
|
|
821
|
+
sender({ type: "err", message: "invalid command" });
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
if (cmd.type === "subscribe") {
|
|
825
|
+
this.subscribe(client, cmd.path, sender);
|
|
826
|
+
} else if (cmd.type === "unsubscribe") {
|
|
827
|
+
this.unsubscribe(client, cmd.path, sender);
|
|
828
|
+
} else if (cmd.type === "ack") {
|
|
829
|
+
this.ack(client, cmd.path, cmd.count ?? 1);
|
|
830
|
+
} else {
|
|
831
|
+
sender({ type: "err", message: `unknown command type: ${cmd.type}` });
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Number of active subscriptions for a client. Useful for tests.
|
|
836
|
+
*/
|
|
837
|
+
subscriptionCount(client) {
|
|
838
|
+
return this.clients.get(client)?.size ?? 0;
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Dispose all clients and subscriptions.
|
|
842
|
+
*/
|
|
843
|
+
destroy() {
|
|
844
|
+
for (const [client] of this.clients) {
|
|
845
|
+
this.handleDisconnect(client);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
// -----------------------------------------------------------------------
|
|
849
|
+
// Internal
|
|
850
|
+
// -----------------------------------------------------------------------
|
|
851
|
+
subscribe(client, path, send) {
|
|
852
|
+
let subs = this.clients.get(client);
|
|
853
|
+
if (!subs) {
|
|
854
|
+
subs = /* @__PURE__ */ new Map();
|
|
855
|
+
this.clients.set(client, subs);
|
|
856
|
+
}
|
|
857
|
+
if (subs.has(path)) {
|
|
858
|
+
send({ type: "subscribed", path });
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
const actor = this.extractActor(client);
|
|
862
|
+
let handle;
|
|
863
|
+
try {
|
|
864
|
+
handle = this.graph.observe(path, { actor });
|
|
865
|
+
} catch (err) {
|
|
866
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
867
|
+
send({ type: "err", message });
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
const wm = this.highWaterMark != null ? createWatermarkController((msgs) => handle.up(msgs), {
|
|
871
|
+
highWaterMark: this.highWaterMark,
|
|
872
|
+
lowWaterMark: this.lowWaterMark ?? Math.floor(this.highWaterMark / 2)
|
|
873
|
+
}) : void 0;
|
|
874
|
+
const cleanup = () => {
|
|
875
|
+
wm?.dispose();
|
|
876
|
+
unsub();
|
|
877
|
+
subs.delete(path);
|
|
878
|
+
};
|
|
879
|
+
const unsub = handle.subscribe((msgs) => {
|
|
880
|
+
for (const msg of msgs) {
|
|
881
|
+
const t = msg[0];
|
|
882
|
+
if (t === import_core4.DATA) {
|
|
883
|
+
wm?.onEnqueue();
|
|
884
|
+
trySend(send, { type: "data", path, value: msg[1] });
|
|
885
|
+
} else if (t === import_core4.ERROR) {
|
|
886
|
+
const errMsg = msg[1] instanceof Error ? msg[1].message : String(msg[1]);
|
|
887
|
+
trySend(send, { type: "error", path, error: errMsg });
|
|
888
|
+
cleanup();
|
|
889
|
+
return;
|
|
890
|
+
} else if (t === import_core4.COMPLETE || t === import_core4.TEARDOWN) {
|
|
891
|
+
trySend(send, { type: "complete", path });
|
|
892
|
+
cleanup();
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
subs.set(path, { unsub, wm });
|
|
898
|
+
send({ type: "subscribed", path });
|
|
899
|
+
}
|
|
900
|
+
unsubscribe(client, path, send) {
|
|
901
|
+
const subs = this.clients.get(client);
|
|
902
|
+
const entry = subs?.get(path);
|
|
903
|
+
if (entry) {
|
|
904
|
+
entry.wm?.dispose();
|
|
905
|
+
entry.unsub();
|
|
906
|
+
subs.delete(path);
|
|
907
|
+
}
|
|
908
|
+
send({ type: "unsubscribed", path });
|
|
909
|
+
}
|
|
910
|
+
ack(client, path, count) {
|
|
911
|
+
const entry = this.clients.get(client)?.get(path);
|
|
912
|
+
if (!entry?.wm) return;
|
|
913
|
+
const n = Math.min(Math.max(0, Math.floor(count)), 1024);
|
|
914
|
+
for (let i = 0; i < n; i++) entry.wm.onDequeue();
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
function defaultSerialize(value) {
|
|
918
|
+
if (value instanceof Error) return value.message;
|
|
919
|
+
try {
|
|
920
|
+
return JSON.stringify(value);
|
|
921
|
+
} catch {
|
|
922
|
+
return String(value);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
function sseFrame(event, data) {
|
|
926
|
+
let frame = `event: ${event}
|
|
927
|
+
`;
|
|
928
|
+
if (data !== void 0) {
|
|
929
|
+
for (const line of data.split("\n")) {
|
|
930
|
+
frame += `data: ${line}
|
|
931
|
+
`;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
frame += "\n";
|
|
935
|
+
return frame;
|
|
936
|
+
}
|
|
937
|
+
function defaultParseCommand(data) {
|
|
938
|
+
return JSON.parse(data);
|
|
939
|
+
}
|
|
940
|
+
function defaultSend(client, msg) {
|
|
941
|
+
try {
|
|
942
|
+
client.send(JSON.stringify(msg));
|
|
943
|
+
} catch {
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
function trySend(send, msg) {
|
|
947
|
+
try {
|
|
948
|
+
send(msg);
|
|
949
|
+
} catch {
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// src/compat/nestjs/guard.ts
|
|
954
|
+
var import_core5 = require("@graphrefly/pure-ts/core");
|
|
955
|
+
var ACTOR_KEY = "graphReflyActor";
|
|
956
|
+
function fromJwtPayload(mapping) {
|
|
957
|
+
return (context) => {
|
|
958
|
+
const req = context.switchToHttp().getRequest();
|
|
959
|
+
const user = req?.user;
|
|
960
|
+
if (user == null) return void 0;
|
|
961
|
+
if (mapping) return mapping(user);
|
|
962
|
+
return user;
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
function fromHeader(headerName = "x-graphrefly-actor") {
|
|
966
|
+
return (context) => {
|
|
967
|
+
const req = context.switchToHttp().getRequest();
|
|
968
|
+
const raw = req?.headers?.[headerName.toLowerCase()];
|
|
969
|
+
if (typeof raw !== "string" || raw.length === 0) return void 0;
|
|
970
|
+
try {
|
|
971
|
+
return JSON.parse(raw);
|
|
972
|
+
} catch {
|
|
973
|
+
return void 0;
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
function getActor(req) {
|
|
978
|
+
const actor = req?.[ACTOR_KEY];
|
|
979
|
+
return actor != null ? (0, import_core5.normalizeActor)(actor) : import_core5.DEFAULT_ACTOR;
|
|
980
|
+
}
|
|
981
|
+
var GraphReflyGuardImpl = class {
|
|
982
|
+
constructor(extractor) {
|
|
983
|
+
this.extractor = extractor;
|
|
984
|
+
}
|
|
985
|
+
canActivate(context) {
|
|
986
|
+
const actor = (0, import_core5.normalizeActor)(this.extractor(context));
|
|
987
|
+
const req = context.switchToHttp().getRequest();
|
|
988
|
+
if (req != null) {
|
|
989
|
+
req[ACTOR_KEY] = actor;
|
|
990
|
+
}
|
|
991
|
+
return true;
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
function GraphReflyGuard(extractor) {
|
|
995
|
+
return new GraphReflyGuardImpl(extractor ?? fromJwtPayload());
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// src/compat/nestjs/module.ts
|
|
999
|
+
var import_graph3 = require("@graphrefly/pure-ts/graph");
|
|
1000
|
+
var import_common2 = require("@nestjs/common");
|
|
1001
|
+
var import_core8 = require("@nestjs/core");
|
|
1002
|
+
|
|
1003
|
+
// src/utils/cqrs/index.ts
|
|
1004
|
+
var import_core7 = require("@graphrefly/pure-ts/core");
|
|
1005
|
+
var import_extra3 = require("@graphrefly/pure-ts/extra");
|
|
1006
|
+
var import_graph2 = require("@graphrefly/pure-ts/graph");
|
|
1007
|
+
|
|
1008
|
+
// src/base/mutation/index.ts
|
|
1009
|
+
var import_core6 = require("@graphrefly/pure-ts/core");
|
|
1010
|
+
var import_extra2 = require("@graphrefly/pure-ts/extra");
|
|
1011
|
+
var import_graph = require("@graphrefly/pure-ts/graph");
|
|
1012
|
+
var DEFAULT_AUDIT_GUARD = (0, import_core6.policy)((allow, deny) => {
|
|
1013
|
+
allow("observe");
|
|
1014
|
+
allow("signal");
|
|
1015
|
+
deny("write");
|
|
1016
|
+
});
|
|
1017
|
+
function createAuditLog(opts) {
|
|
1018
|
+
const log = (0, import_extra2.reactiveLog)([], {
|
|
1019
|
+
name: opts.name,
|
|
1020
|
+
maxSize: opts.retainedLimit ?? 1024,
|
|
1021
|
+
guard: opts.guard ?? DEFAULT_AUDIT_GUARD,
|
|
1022
|
+
...opts.versioning != null ? { versioning: opts.versioning } : {}
|
|
1023
|
+
});
|
|
1024
|
+
log.withLatest();
|
|
1025
|
+
if (opts.graph) {
|
|
1026
|
+
opts.graph.add(log.entries, { name: opts.name });
|
|
1027
|
+
}
|
|
1028
|
+
return log;
|
|
1029
|
+
}
|
|
1030
|
+
function deepFreeze(value) {
|
|
1031
|
+
if (value === null || typeof value !== "object" || Object.isFrozen(value)) return value;
|
|
1032
|
+
for (const k of Object.keys(value)) {
|
|
1033
|
+
deepFreeze(value[k]);
|
|
1034
|
+
}
|
|
1035
|
+
return Object.freeze(value);
|
|
1036
|
+
}
|
|
1037
|
+
function mutate(act, opts) {
|
|
1038
|
+
const { up, down } = typeof act === "function" ? { up: act, down: void 0 } : act;
|
|
1039
|
+
const freeze = opts.freeze ?? true;
|
|
1040
|
+
if (opts.frame === "inline") {
|
|
1041
|
+
return function wrapped(...args) {
|
|
1042
|
+
const sealed = freeze ? args.map(deepFreeze) : args;
|
|
1043
|
+
const t_ns = (0, import_core6.wallClockNs)();
|
|
1044
|
+
const seq = opts.seq ? bumpCursor(opts.seq) : void 0;
|
|
1045
|
+
try {
|
|
1046
|
+
const result = up(...sealed);
|
|
1047
|
+
if (opts.log && opts.onSuccessRecord) {
|
|
1048
|
+
appendAudit(
|
|
1049
|
+
opts.log,
|
|
1050
|
+
opts.onSuccessRecord,
|
|
1051
|
+
sealed,
|
|
1052
|
+
result,
|
|
1053
|
+
{ t_ns, seq },
|
|
1054
|
+
opts.handlerVersion
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
return result;
|
|
1058
|
+
} catch (err) {
|
|
1059
|
+
if (opts.log && opts.onFailureRecord) {
|
|
1060
|
+
const errorType = err instanceof Error ? err.name : typeof err;
|
|
1061
|
+
appendAudit(
|
|
1062
|
+
opts.log,
|
|
1063
|
+
opts.onFailureRecord,
|
|
1064
|
+
sealed,
|
|
1065
|
+
err,
|
|
1066
|
+
{ t_ns, seq, errorType },
|
|
1067
|
+
opts.handlerVersion
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
throw err;
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
return function wrapped(...args) {
|
|
1075
|
+
const sealed = freeze ? args.map(deepFreeze) : args;
|
|
1076
|
+
const t_ns = (0, import_core6.wallClockNs)();
|
|
1077
|
+
let result;
|
|
1078
|
+
let captured;
|
|
1079
|
+
let captureSet = false;
|
|
1080
|
+
let seq;
|
|
1081
|
+
try {
|
|
1082
|
+
(0, import_core6.batch)(() => {
|
|
1083
|
+
if (opts.seq) seq = bumpCursor(opts.seq);
|
|
1084
|
+
try {
|
|
1085
|
+
result = up(...sealed);
|
|
1086
|
+
if (opts.log && opts.onSuccessRecord) {
|
|
1087
|
+
appendAudit(
|
|
1088
|
+
opts.log,
|
|
1089
|
+
opts.onSuccessRecord,
|
|
1090
|
+
sealed,
|
|
1091
|
+
result,
|
|
1092
|
+
{ t_ns, seq },
|
|
1093
|
+
opts.handlerVersion
|
|
1094
|
+
);
|
|
1095
|
+
}
|
|
1096
|
+
} catch (err) {
|
|
1097
|
+
captured = err;
|
|
1098
|
+
captureSet = true;
|
|
1099
|
+
throw err;
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
} catch (outerErr) {
|
|
1103
|
+
if (captureSet && down) {
|
|
1104
|
+
try {
|
|
1105
|
+
down(...sealed);
|
|
1106
|
+
} catch (downErr) {
|
|
1107
|
+
console.error(
|
|
1108
|
+
`mutate: down hook threw \u2014 original action error preserved (${captured instanceof Error ? captured.name : typeof captured}). Down error:`,
|
|
1109
|
+
downErr
|
|
1110
|
+
);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (captureSet && opts.log && opts.onFailureRecord) {
|
|
1114
|
+
const errorType = captured instanceof Error ? captured.name : typeof captured;
|
|
1115
|
+
appendAudit(
|
|
1116
|
+
opts.log,
|
|
1117
|
+
opts.onFailureRecord,
|
|
1118
|
+
sealed,
|
|
1119
|
+
captured,
|
|
1120
|
+
{ t_ns, seq, errorType },
|
|
1121
|
+
opts.handlerVersion
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
throw captureSet ? captured : outerErr;
|
|
1125
|
+
}
|
|
1126
|
+
return result;
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
var _bumpCursorWarned = /* @__PURE__ */ new WeakSet();
|
|
1130
|
+
function bumpCursor(seq) {
|
|
1131
|
+
const raw = seq.cache;
|
|
1132
|
+
const valid = typeof raw === "number" && Number.isFinite(raw);
|
|
1133
|
+
if (!valid && raw !== void 0 && !_bumpCursorWarned.has(seq)) {
|
|
1134
|
+
_bumpCursorWarned.add(seq);
|
|
1135
|
+
console.warn(
|
|
1136
|
+
`bumpCursor: cursor cache held a non-numeric value (${String(raw)}); resetting to 0. Causes include: a snapshot codec round-tripping the cursor as a string / null / NaN, OR a malformed initial seed (e.g. state<number>(NaN)). Audit consumers may see colliding seq values after this point.`
|
|
1137
|
+
);
|
|
1138
|
+
}
|
|
1139
|
+
const cur = valid ? raw : 0;
|
|
1140
|
+
const next = cur + 1;
|
|
1141
|
+
seq.down([[import_core6.DIRTY], [import_core6.DATA, next]]);
|
|
1142
|
+
return next;
|
|
1143
|
+
}
|
|
1144
|
+
function appendAudit(audit, builder, args, value, meta, handlerVersion) {
|
|
1145
|
+
const record = builder(args, value, meta);
|
|
1146
|
+
if (record === void 0) return;
|
|
1147
|
+
const stamped = handlerVersion != null ? { ...record, handlerVersion } : record;
|
|
1148
|
+
audit.append(stamped);
|
|
1149
|
+
}
|
|
1150
|
+
function registerCursor(graph, name, initial = 0) {
|
|
1151
|
+
const cursor = (0, import_core6.node)([], { initial, name, describeKind: "state" });
|
|
1152
|
+
graph.add(cursor, { name });
|
|
1153
|
+
return cursor;
|
|
1154
|
+
}
|
|
1155
|
+
function registerCursorMap(graph, name, keys, initial = 0) {
|
|
1156
|
+
const out = {};
|
|
1157
|
+
const sub = new import_graph.Graph(name);
|
|
1158
|
+
for (const k of keys) {
|
|
1159
|
+
const cursor = (0, import_core6.node)([], {
|
|
1160
|
+
initial,
|
|
1161
|
+
name: k,
|
|
1162
|
+
describeKind: "state"
|
|
1163
|
+
});
|
|
1164
|
+
sub.add(cursor, { name: k });
|
|
1165
|
+
out[k] = cursor;
|
|
1166
|
+
}
|
|
1167
|
+
graph.mount(name, sub);
|
|
1168
|
+
return out;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
// src/utils/_errors/index.ts
|
|
1172
|
+
var GraphReFlyError = class extends Error {
|
|
1173
|
+
constructor(message, options) {
|
|
1174
|
+
super(message, options);
|
|
1175
|
+
this.name = this.constructor.name;
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
var DuplicateRegistrationError = class extends GraphReFlyError {
|
|
1179
|
+
constructor(kind, registrationName) {
|
|
1180
|
+
super(`Duplicate ${kind} registration: "${registrationName}"`);
|
|
1181
|
+
this.kind = kind;
|
|
1182
|
+
this.registrationName = registrationName;
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
var UndeclaredEmitError = class extends GraphReFlyError {
|
|
1186
|
+
constructor(commandName, eventName, declaredEmits) {
|
|
1187
|
+
super(
|
|
1188
|
+
`Command "${commandName}" emitted undeclared event "${eventName}". Declared emits: [${declaredEmits.join(", ")}]`
|
|
1189
|
+
);
|
|
1190
|
+
this.commandName = commandName;
|
|
1191
|
+
this.eventName = eventName;
|
|
1192
|
+
this.declaredEmits = declaredEmits;
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
var OptimisticConcurrencyError = class extends GraphReFlyError {
|
|
1196
|
+
constructor(aggregateId, expected, actual) {
|
|
1197
|
+
super(
|
|
1198
|
+
`Optimistic concurrency conflict on aggregate "${aggregateId}": expected version ${expected}, got ${actual}`
|
|
1199
|
+
);
|
|
1200
|
+
this.aggregateId = aggregateId;
|
|
1201
|
+
this.expected = expected;
|
|
1202
|
+
this.actual = actual;
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
var UnknownCommandError = class extends GraphReFlyError {
|
|
1206
|
+
constructor(commandName) {
|
|
1207
|
+
super(`Unknown command: "${commandName}". Register with command() first.`);
|
|
1208
|
+
this.commandName = commandName;
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
var CommandHandlerError = class extends GraphReFlyError {
|
|
1212
|
+
constructor(commandName, cause) {
|
|
1213
|
+
super(
|
|
1214
|
+
`Command handler "${commandName}" threw: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
1215
|
+
{ cause }
|
|
1216
|
+
);
|
|
1217
|
+
this.commandName = commandName;
|
|
1218
|
+
}
|
|
1219
|
+
};
|
|
1220
|
+
var RebuildError = class extends GraphReFlyError {
|
|
1221
|
+
constructor(projectionName, cause) {
|
|
1222
|
+
super(
|
|
1223
|
+
`Projection "${projectionName}" rebuild failed: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
1224
|
+
{ cause }
|
|
1225
|
+
);
|
|
1226
|
+
this.projectionName = projectionName;
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
// src/utils/cqrs/index.ts
|
|
1231
|
+
var import_extra4 = require("@graphrefly/pure-ts/extra");
|
|
1232
|
+
|
|
1233
|
+
// src/base/meta/domain-meta.ts
|
|
1234
|
+
function domainMeta(domain, kind, extra) {
|
|
1235
|
+
return {
|
|
1236
|
+
[domain]: true,
|
|
1237
|
+
[`${domain}_type`]: kind,
|
|
1238
|
+
...extra ?? {}
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
// src/utils/cqrs/index.ts
|
|
1243
|
+
var COMMAND_GUARD = (0, import_core7.policy)((allow, deny) => {
|
|
1244
|
+
allow("write");
|
|
1245
|
+
allow("signal");
|
|
1246
|
+
deny("observe");
|
|
1247
|
+
});
|
|
1248
|
+
var PROJECTION_GUARD = (0, import_core7.policy)((allow, deny) => {
|
|
1249
|
+
allow("observe");
|
|
1250
|
+
allow("signal");
|
|
1251
|
+
deny("write");
|
|
1252
|
+
});
|
|
1253
|
+
var EVENT_GUARD = (0, import_core7.policy)((allow, deny) => {
|
|
1254
|
+
allow("observe");
|
|
1255
|
+
allow("signal");
|
|
1256
|
+
deny("write");
|
|
1257
|
+
});
|
|
1258
|
+
function cqrsMeta(kind, extra) {
|
|
1259
|
+
return domainMeta("cqrs", kind, extra);
|
|
1260
|
+
}
|
|
1261
|
+
function deepFreeze2(value) {
|
|
1262
|
+
if (value === null || typeof value !== "object" || Object.isFrozen(value)) return value;
|
|
1263
|
+
for (const k of Object.keys(value)) {
|
|
1264
|
+
deepFreeze2(value[k]);
|
|
1265
|
+
}
|
|
1266
|
+
return Object.freeze(value);
|
|
1267
|
+
}
|
|
1268
|
+
var CqrsGraph = class extends import_graph2.Graph {
|
|
1269
|
+
/** Fan-in event streams (one per type, all aggregates merged). */
|
|
1270
|
+
_eventLogs = /* @__PURE__ */ new Map();
|
|
1271
|
+
/**
|
|
1272
|
+
* Per-aggregate event streams: type → aggregateId → entry. Used for
|
|
1273
|
+
* `event(type, aggregateId)` dual-form access and per-aggregate version
|
|
1274
|
+
* tracking. Only populated when an event with `aggregateId` is emitted.
|
|
1275
|
+
*/
|
|
1276
|
+
_eventLogsByAggregate = /* @__PURE__ */ new Map();
|
|
1277
|
+
/** Per-aggregate version counters: `${type}::${aggregateId}` → current version. */
|
|
1278
|
+
_aggregateVersions = /* @__PURE__ */ new Map();
|
|
1279
|
+
/**
|
|
1280
|
+
* LRU access order for `${type}::${aggregateId}`. Map insertion order
|
|
1281
|
+
* tracks recency — `delete` + `set` on access moves to the end.
|
|
1282
|
+
*/
|
|
1283
|
+
_aggregateLru = /* @__PURE__ */ new Map();
|
|
1284
|
+
_commandRegs = /* @__PURE__ */ new Map();
|
|
1285
|
+
_projections = /* @__PURE__ */ new Set();
|
|
1286
|
+
_sagas = /* @__PURE__ */ new Set();
|
|
1287
|
+
_seq = 0;
|
|
1288
|
+
_retainedLimit;
|
|
1289
|
+
_freezeCommandPayload;
|
|
1290
|
+
_freezeEventPayload;
|
|
1291
|
+
_maxAggregates;
|
|
1292
|
+
_dispatchSeqCursor;
|
|
1293
|
+
/** Audit log of every command dispatch (Audit 2). */
|
|
1294
|
+
dispatches;
|
|
1295
|
+
/** Alias for {@link CqrsGraph.dispatches} (Audit 2 `.audit` duplication). */
|
|
1296
|
+
audit;
|
|
1297
|
+
/** Per-aggregate LRU eviction observability; secondary log to `dispatches`. */
|
|
1298
|
+
aggregateEvictions;
|
|
1299
|
+
constructor(name, opts = {}) {
|
|
1300
|
+
super(name, opts.graph);
|
|
1301
|
+
this._retainedLimit = opts.retainedLimit ?? 1024;
|
|
1302
|
+
this._freezeCommandPayload = opts.freezeCommandPayload ?? true;
|
|
1303
|
+
this._freezeEventPayload = opts.freezeEventPayload ?? true;
|
|
1304
|
+
this._maxAggregates = opts.maxAggregates ?? 1e4;
|
|
1305
|
+
this.dispatches = createAuditLog({
|
|
1306
|
+
name: "dispatches",
|
|
1307
|
+
retainedLimit: this._retainedLimit,
|
|
1308
|
+
graph: this
|
|
1309
|
+
});
|
|
1310
|
+
this.audit = this.dispatches;
|
|
1311
|
+
this.aggregateEvictions = createAuditLog({
|
|
1312
|
+
name: "aggregateEvictions",
|
|
1313
|
+
retainedLimit: this._retainedLimit,
|
|
1314
|
+
graph: this
|
|
1315
|
+
});
|
|
1316
|
+
this._dispatchSeqCursor = registerCursor(this, "dispatch_seq", 0);
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Read the current per-aggregate version (last emitted `aggregateVersion`
|
|
1320
|
+
* for that `(type, aggregateId)` pair). Returns `0` if no events have been
|
|
1321
|
+
* emitted yet for this aggregate. Useful for callers preparing
|
|
1322
|
+
* {@link DispatchOptions.expectedAggregateVersion}.
|
|
1323
|
+
*/
|
|
1324
|
+
aggregateVersion(type, aggregateId) {
|
|
1325
|
+
return this._aggregateVersions.get(`${type}::${aggregateId}`) ?? 0;
|
|
1326
|
+
}
|
|
1327
|
+
/** LRU touch — moves the key to the end of the access order. */
|
|
1328
|
+
_touchAggregate(key) {
|
|
1329
|
+
this._aggregateLru.delete(key);
|
|
1330
|
+
this._aggregateLru.set(key, true);
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Evict the oldest aggregate streams (least-recently-touched) until the
|
|
1334
|
+
* aggregate count is back within `_maxAggregates`. Emits one
|
|
1335
|
+
* `AggregateEvictionRecord` per eviction. The fan-in stream is NOT touched
|
|
1336
|
+
* — events stay in the type-level log; only the per-aggregate stream and
|
|
1337
|
+
* version counter are removed.
|
|
1338
|
+
*/
|
|
1339
|
+
_enforceAggregateLru() {
|
|
1340
|
+
while (this._aggregateLru.size > this._maxAggregates) {
|
|
1341
|
+
const oldest = this._aggregateLru.keys().next();
|
|
1342
|
+
if (oldest.done) break;
|
|
1343
|
+
const key = oldest.value;
|
|
1344
|
+
this._aggregateLru.delete(key);
|
|
1345
|
+
const sep = key.indexOf("::");
|
|
1346
|
+
if (sep < 0) continue;
|
|
1347
|
+
const type = key.slice(0, sep);
|
|
1348
|
+
const aggregateId = key.slice(sep + 2);
|
|
1349
|
+
const lastVersion = this._aggregateVersions.get(key) ?? 0;
|
|
1350
|
+
this._aggregateVersions.delete(key);
|
|
1351
|
+
const byType = this._eventLogsByAggregate.get(type);
|
|
1352
|
+
if (byType) {
|
|
1353
|
+
byType.delete(aggregateId);
|
|
1354
|
+
if (byType.size === 0) this._eventLogsByAggregate.delete(type);
|
|
1355
|
+
}
|
|
1356
|
+
this.aggregateEvictions.append({
|
|
1357
|
+
aggregateId,
|
|
1358
|
+
type,
|
|
1359
|
+
lastVersion,
|
|
1360
|
+
t_ns: (0, import_core7.wallClockNs)()
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
/** Tiers attached via {@link attachEventStorage}; auto-wired into future event streams. */
|
|
1365
|
+
_attachedEventTiers = [];
|
|
1366
|
+
_attachedTierDisposers = /* @__PURE__ */ new Map();
|
|
1367
|
+
/**
|
|
1368
|
+
* Wire append-log storage tiers for ALL CQRS event streams — both currently
|
|
1369
|
+
* registered AND any future streams created via `event(name)` /
|
|
1370
|
+
* `event(name, aggregateId)` / handler emit. (M4 fix.)
|
|
1371
|
+
*
|
|
1372
|
+
* Returns a disposer that releases all storage subscriptions wired by this
|
|
1373
|
+
* call (including those for streams that were created after the call).
|
|
1374
|
+
*/
|
|
1375
|
+
attachEventStorage(tiers) {
|
|
1376
|
+
this._attachedEventTiers.push(tiers);
|
|
1377
|
+
for (const [name, entry] of this._eventLogs) {
|
|
1378
|
+
const dispose = entry.log.attachStorage(tiers);
|
|
1379
|
+
let arr = this._attachedTierDisposers.get(name);
|
|
1380
|
+
if (!arr) {
|
|
1381
|
+
arr = [];
|
|
1382
|
+
this._attachedTierDisposers.set(name, arr);
|
|
1383
|
+
}
|
|
1384
|
+
arr.push(dispose);
|
|
1385
|
+
}
|
|
1386
|
+
for (const [type, byAgg] of this._eventLogsByAggregate) {
|
|
1387
|
+
for (const [aggId, entry] of byAgg) {
|
|
1388
|
+
const key = `${type}::${aggId}`;
|
|
1389
|
+
const dispose = entry.log.attachStorage(tiers);
|
|
1390
|
+
let arr = this._attachedTierDisposers.get(key);
|
|
1391
|
+
if (!arr) {
|
|
1392
|
+
arr = [];
|
|
1393
|
+
this._attachedTierDisposers.set(key, arr);
|
|
1394
|
+
}
|
|
1395
|
+
arr.push(dispose);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
return () => {
|
|
1399
|
+
const idx = this._attachedEventTiers.indexOf(tiers);
|
|
1400
|
+
if (idx >= 0) this._attachedEventTiers.splice(idx, 1);
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
/** Wire newly-created event stream into all currently-attached tier sets. */
|
|
1404
|
+
_autoWireStreamStorage(key, log) {
|
|
1405
|
+
if (this._attachedEventTiers.length === 0) return;
|
|
1406
|
+
let arr = this._attachedTierDisposers.get(key);
|
|
1407
|
+
if (!arr) {
|
|
1408
|
+
arr = [];
|
|
1409
|
+
this._attachedTierDisposers.set(key, arr);
|
|
1410
|
+
}
|
|
1411
|
+
for (const tiers of this._attachedEventTiers) {
|
|
1412
|
+
arr.push(log.attachStorage(tiers));
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
event(name, aggregateId) {
|
|
1416
|
+
if (aggregateId !== void 0) {
|
|
1417
|
+
return this._ensureAggregateStream(name, aggregateId).node;
|
|
1418
|
+
}
|
|
1419
|
+
const existing = this._eventLogs.get(name);
|
|
1420
|
+
if (existing) return existing.node;
|
|
1421
|
+
const log = (0, import_extra3.reactiveLog)([], {
|
|
1422
|
+
name,
|
|
1423
|
+
versioning: 0,
|
|
1424
|
+
maxSize: this._retainedLimit
|
|
1425
|
+
});
|
|
1426
|
+
log.withLatest();
|
|
1427
|
+
const entries = log.entries;
|
|
1428
|
+
const guarded = this.derived(
|
|
1429
|
+
name,
|
|
1430
|
+
[entries],
|
|
1431
|
+
(batchData, ctx) => {
|
|
1432
|
+
const latest = batchData[0] != null && batchData[0].length > 0 ? batchData[0].at(-1) : ctx.prevData[0];
|
|
1433
|
+
return [latest];
|
|
1434
|
+
},
|
|
1435
|
+
{
|
|
1436
|
+
meta: cqrsMeta("event", { event_name: name }),
|
|
1437
|
+
guard: EVENT_GUARD,
|
|
1438
|
+
initial: entries.cache
|
|
1439
|
+
}
|
|
1440
|
+
);
|
|
1441
|
+
this.addDisposer((0, import_extra4.keepalive)(guarded));
|
|
1442
|
+
this._eventLogs.set(name, { log, node: guarded });
|
|
1443
|
+
this._autoWireStreamStorage(name, log);
|
|
1444
|
+
return guarded;
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Get-or-create the per-aggregate event stream for `(type, aggregateId)`.
|
|
1448
|
+
* Mounts the stream as a sibling node named `<type>_<aggregateId>` so it
|
|
1449
|
+
* appears in `describe()`. LRU access is touched on every call.
|
|
1450
|
+
*/
|
|
1451
|
+
_ensureAggregateStream(type, aggregateId) {
|
|
1452
|
+
if (!this._eventLogs.has(type)) this.event(type);
|
|
1453
|
+
let byType = this._eventLogsByAggregate.get(type);
|
|
1454
|
+
if (!byType) {
|
|
1455
|
+
byType = /* @__PURE__ */ new Map();
|
|
1456
|
+
this._eventLogsByAggregate.set(type, byType);
|
|
1457
|
+
}
|
|
1458
|
+
const lruKey = `${type}::${aggregateId}`;
|
|
1459
|
+
this._touchAggregate(lruKey);
|
|
1460
|
+
const existing = byType.get(aggregateId);
|
|
1461
|
+
if (existing) return existing;
|
|
1462
|
+
const nodeName = `${type}_${aggregateId.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
|
|
1463
|
+
const log = (0, import_extra3.reactiveLog)([], {
|
|
1464
|
+
name: nodeName,
|
|
1465
|
+
versioning: 0,
|
|
1466
|
+
maxSize: this._retainedLimit
|
|
1467
|
+
});
|
|
1468
|
+
log.withLatest();
|
|
1469
|
+
const entries = log.entries;
|
|
1470
|
+
let mountName = nodeName;
|
|
1471
|
+
let collisionIdx = 0;
|
|
1472
|
+
while (this.resolveOptional(mountName) !== void 0) {
|
|
1473
|
+
collisionIdx += 1;
|
|
1474
|
+
mountName = `${nodeName}_${collisionIdx}`;
|
|
1475
|
+
}
|
|
1476
|
+
let guarded;
|
|
1477
|
+
try {
|
|
1478
|
+
guarded = this.derived(
|
|
1479
|
+
mountName,
|
|
1480
|
+
[entries],
|
|
1481
|
+
(batchData, ctx) => {
|
|
1482
|
+
const latest = batchData[0] != null && batchData[0].length > 0 ? batchData[0].at(-1) : ctx.prevData[0];
|
|
1483
|
+
return [latest];
|
|
1484
|
+
},
|
|
1485
|
+
{
|
|
1486
|
+
meta: cqrsMeta("event_aggregate", {
|
|
1487
|
+
event_name: type,
|
|
1488
|
+
aggregate_id: aggregateId
|
|
1489
|
+
}),
|
|
1490
|
+
guard: EVENT_GUARD,
|
|
1491
|
+
initial: entries.cache
|
|
1492
|
+
}
|
|
1493
|
+
);
|
|
1494
|
+
} catch {
|
|
1495
|
+
guarded = (0, import_core7.node)(
|
|
1496
|
+
[entries],
|
|
1497
|
+
(batchData, actions, ctx) => {
|
|
1498
|
+
const latest = batchData[0] != null && batchData[0].length > 0 ? batchData[0].at(-1) : ctx.prevData[0];
|
|
1499
|
+
actions.emit(latest);
|
|
1500
|
+
},
|
|
1501
|
+
{
|
|
1502
|
+
name: nodeName,
|
|
1503
|
+
describeKind: "derived",
|
|
1504
|
+
meta: cqrsMeta("event_aggregate", {
|
|
1505
|
+
event_name: type,
|
|
1506
|
+
aggregate_id: aggregateId
|
|
1507
|
+
}),
|
|
1508
|
+
guard: EVENT_GUARD,
|
|
1509
|
+
initial: entries.cache
|
|
1510
|
+
}
|
|
1511
|
+
);
|
|
1512
|
+
}
|
|
1513
|
+
this.addDisposer((0, import_extra4.keepalive)(guarded));
|
|
1514
|
+
const entry = { log, node: guarded };
|
|
1515
|
+
byType.set(aggregateId, entry);
|
|
1516
|
+
this._autoWireStreamStorage(`${type}::${aggregateId}`, log);
|
|
1517
|
+
this._enforceAggregateLru();
|
|
1518
|
+
return entry;
|
|
1519
|
+
}
|
|
1520
|
+
/** Try `resolve(path)`; return `undefined` instead of throwing on missing. */
|
|
1521
|
+
resolveOptional(path) {
|
|
1522
|
+
try {
|
|
1523
|
+
return this.resolve(path);
|
|
1524
|
+
} catch {
|
|
1525
|
+
return void 0;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
/** Internal: append to an event log, auto-registering if needed. */
|
|
1529
|
+
_appendEvent(eventName, payload, extra) {
|
|
1530
|
+
let entry = this._eventLogs.get(eventName);
|
|
1531
|
+
if (!entry) {
|
|
1532
|
+
this.event(eventName);
|
|
1533
|
+
entry = this._eventLogs.get(eventName);
|
|
1534
|
+
}
|
|
1535
|
+
if (entry.node.status === "completed" || entry.node.status === "errored") {
|
|
1536
|
+
throw new Error(
|
|
1537
|
+
`Cannot dispatch to terminated event stream "${eventName}" (status: ${entry.node.status}).`
|
|
1538
|
+
);
|
|
1539
|
+
}
|
|
1540
|
+
let aggregateVersion;
|
|
1541
|
+
let aggregateEntry;
|
|
1542
|
+
if (extra?.aggregateId !== void 0) {
|
|
1543
|
+
const lruKey = `${eventName}::${extra.aggregateId}`;
|
|
1544
|
+
aggregateVersion = (this._aggregateVersions.get(lruKey) ?? 0) + 1;
|
|
1545
|
+
this._aggregateVersions.set(lruKey, aggregateVersion);
|
|
1546
|
+
aggregateEntry = this._ensureAggregateStream(eventName, extra.aggregateId);
|
|
1547
|
+
}
|
|
1548
|
+
const nv = entry.log.entries.v;
|
|
1549
|
+
const frozenPayload = this._freezeEventPayload ? deepFreeze2(payload) : payload;
|
|
1550
|
+
const evt = {
|
|
1551
|
+
type: eventName,
|
|
1552
|
+
payload: frozenPayload,
|
|
1553
|
+
timestampNs: (0, import_core7.wallClockNs)(),
|
|
1554
|
+
seq: ++this._seq,
|
|
1555
|
+
...extra?.aggregateId !== void 0 ? { aggregateId: extra.aggregateId } : {},
|
|
1556
|
+
...aggregateVersion !== void 0 ? { aggregateVersion } : {},
|
|
1557
|
+
...extra?.correlationId !== void 0 ? { correlationId: extra.correlationId } : {},
|
|
1558
|
+
...extra?.causationId !== void 0 ? { causationId: extra.causationId } : {},
|
|
1559
|
+
...extra?.metadata !== void 0 ? { metadata: Object.freeze({ ...extra.metadata }) } : {},
|
|
1560
|
+
...extra?.handlerVersion !== void 0 ? { handlerVersion: extra.handlerVersion } : {},
|
|
1561
|
+
...nv != null ? { v0: { id: nv.id, version: nv.version } } : {}
|
|
1562
|
+
};
|
|
1563
|
+
entry.log.append(evt);
|
|
1564
|
+
if (aggregateEntry) {
|
|
1565
|
+
aggregateEntry.log.append(evt);
|
|
1566
|
+
}
|
|
1567
|
+
return evt;
|
|
1568
|
+
}
|
|
1569
|
+
// -- Commands -------------------------------------------------------------
|
|
1570
|
+
/**
|
|
1571
|
+
* Register a command with its handler. Guard denies `observe` (write-only).
|
|
1572
|
+
* Use `dispatch(name, payload)` to execute.
|
|
1573
|
+
*
|
|
1574
|
+
* The command node carries dynamic `meta.error` — a reactive companion
|
|
1575
|
+
* that holds the last handler error (or `null` on success).
|
|
1576
|
+
*/
|
|
1577
|
+
command(name, handlerOrReg) {
|
|
1578
|
+
if (this._commandRegs.has(name)) {
|
|
1579
|
+
throw new DuplicateRegistrationError("command", name);
|
|
1580
|
+
}
|
|
1581
|
+
const reg = typeof handlerOrReg === "function" ? { handler: handlerOrReg } : handlerOrReg;
|
|
1582
|
+
const cmdNode = this.state(name, void 0, {
|
|
1583
|
+
meta: {
|
|
1584
|
+
...cqrsMeta("command", { command_name: name }),
|
|
1585
|
+
error: null
|
|
1586
|
+
},
|
|
1587
|
+
guard: COMMAND_GUARD
|
|
1588
|
+
});
|
|
1589
|
+
this._commandRegs.set(name, {
|
|
1590
|
+
handler: reg.handler,
|
|
1591
|
+
...reg.emits !== void 0 ? { emits: reg.emits } : {},
|
|
1592
|
+
...reg.handlerVersion !== void 0 ? { handlerVersion: reg.handlerVersion } : {}
|
|
1593
|
+
});
|
|
1594
|
+
if (reg.emits) {
|
|
1595
|
+
for (const e of reg.emits) {
|
|
1596
|
+
if (!this._eventLogs.has(e)) this.event(e);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
return cmdNode;
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* Execute a registered command. Wraps the entire dispatch in `batch()` so
|
|
1603
|
+
* the command node DATA and all emitted events settle atomically.
|
|
1604
|
+
*
|
|
1605
|
+
* If the handler throws, `meta.error` on the command node is set to the
|
|
1606
|
+
* error and the exception is re-thrown.
|
|
1607
|
+
*
|
|
1608
|
+
* **Tier 8 / COMPOSITION-GUIDE §35:** dispatch routes through the shared
|
|
1609
|
+
* {@link mutate} framework so freeze / rollback-on-throw / seq-cursor
|
|
1610
|
+
* advance / audit-record stamping flow through one centralized helper.
|
|
1611
|
+
* Failure records emit OUTSIDE the rolled-back batch (M5 / C4 invariants
|
|
1612
|
+
* preserved by the framework).
|
|
1613
|
+
*/
|
|
1614
|
+
dispatch(commandName, payload, opts) {
|
|
1615
|
+
const reg = this._commandRegs.get(commandName);
|
|
1616
|
+
if (!reg) throw new UnknownCommandError(commandName);
|
|
1617
|
+
if (opts?.aggregateId !== void 0 && opts.expectedAggregateVersion !== void 0 && reg.emits !== void 0) {
|
|
1618
|
+
let observedVersion = 0;
|
|
1619
|
+
for (const t of reg.emits) {
|
|
1620
|
+
const v = this._aggregateVersions.get(`${t}::${opts.aggregateId}`);
|
|
1621
|
+
if (v !== void 0 && v > observedVersion) observedVersion = v;
|
|
1622
|
+
}
|
|
1623
|
+
if (observedVersion !== opts.expectedAggregateVersion) {
|
|
1624
|
+
throw new OptimisticConcurrencyError(
|
|
1625
|
+
opts.aggregateId,
|
|
1626
|
+
opts.expectedAggregateVersion,
|
|
1627
|
+
observedVersion
|
|
1628
|
+
);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
const cmdNode = this.resolve(commandName);
|
|
1632
|
+
const emittedEvents = [];
|
|
1633
|
+
let actionThrew = false;
|
|
1634
|
+
const action = (sealed) => {
|
|
1635
|
+
cmdNode.emit(sealed, { internal: true });
|
|
1636
|
+
try {
|
|
1637
|
+
reg.handler(sealed, {
|
|
1638
|
+
emit: (eName, data) => {
|
|
1639
|
+
if (reg.emits !== void 0 && !reg.emits.includes(eName)) {
|
|
1640
|
+
throw new UndeclaredEmitError(commandName, eName, reg.emits);
|
|
1641
|
+
}
|
|
1642
|
+
emittedEvents.push(eName);
|
|
1643
|
+
this._appendEvent(eName, data, {
|
|
1644
|
+
// D1: thread the dispatch's aggregateId through so events
|
|
1645
|
+
// participate in per-aggregate versioning. Handlers can
|
|
1646
|
+
// override per-emit by passing their own through a richer
|
|
1647
|
+
// emit signature (future extension).
|
|
1648
|
+
...opts?.aggregateId !== void 0 ? { aggregateId: opts.aggregateId } : {},
|
|
1649
|
+
...opts?.correlationId !== void 0 ? { correlationId: opts.correlationId } : {},
|
|
1650
|
+
...opts?.causationId !== void 0 ? { causationId: opts.causationId } : {},
|
|
1651
|
+
...opts?.metadata !== void 0 ? { metadata: Object.freeze({ ...opts.metadata }) } : {},
|
|
1652
|
+
...reg.handlerVersion !== void 0 ? { handlerVersion: reg.handlerVersion } : {}
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
});
|
|
1656
|
+
cmdNode.meta.error.emit(null, { internal: true });
|
|
1657
|
+
} catch (err) {
|
|
1658
|
+
actionThrew = true;
|
|
1659
|
+
throw err;
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
try {
|
|
1663
|
+
mutate(action, {
|
|
1664
|
+
frame: "transactional",
|
|
1665
|
+
log: this.dispatches,
|
|
1666
|
+
seq: this._dispatchSeqCursor,
|
|
1667
|
+
freeze: this._freezeCommandPayload,
|
|
1668
|
+
onSuccessRecord: ([sealed], _result, { t_ns, seq }) => ({
|
|
1669
|
+
commandName,
|
|
1670
|
+
payload: sealed,
|
|
1671
|
+
outcome: "success",
|
|
1672
|
+
emittedEvents: [...emittedEvents],
|
|
1673
|
+
t_ns,
|
|
1674
|
+
seq: seq ?? 0,
|
|
1675
|
+
...reg.handlerVersion !== void 0 ? { handlerVersion: reg.handlerVersion } : {}
|
|
1676
|
+
}),
|
|
1677
|
+
onFailureRecord: ([sealed], err, { t_ns, seq, errorType }) => {
|
|
1678
|
+
const wrapped = err instanceof CommandHandlerError ? err : new CommandHandlerError(commandName, err);
|
|
1679
|
+
return {
|
|
1680
|
+
commandName,
|
|
1681
|
+
payload: sealed,
|
|
1682
|
+
outcome: "failure",
|
|
1683
|
+
error: wrapped,
|
|
1684
|
+
errorType,
|
|
1685
|
+
emittedEvents: [...emittedEvents],
|
|
1686
|
+
t_ns,
|
|
1687
|
+
seq: seq ?? 0,
|
|
1688
|
+
...reg.handlerVersion !== void 0 ? { handlerVersion: reg.handlerVersion } : {}
|
|
1689
|
+
};
|
|
1690
|
+
}
|
|
1691
|
+
})(payload);
|
|
1692
|
+
} catch (outerErr) {
|
|
1693
|
+
if (actionThrew) {
|
|
1694
|
+
cmdNode.meta.error.emit(outerErr, { internal: true });
|
|
1695
|
+
}
|
|
1696
|
+
throw outerErr;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
// -- Projections ----------------------------------------------------------
|
|
1700
|
+
/**
|
|
1701
|
+
* Register a read-only projection derived from event streams.
|
|
1702
|
+
* Guard denies `write` — value is computed from events only.
|
|
1703
|
+
*
|
|
1704
|
+
* **Wave C.3 Unit 21 (locked 2026-04-24):**
|
|
1705
|
+
* - Object-bag signature replaces the positional `(name, events, reducer, initial)` form.
|
|
1706
|
+
* - `mode: "scan"` (default) — incremental fold; `"replay"` — full replay each wave.
|
|
1707
|
+
* - `snapshot` integration for cold-start load + auto-checkpoint save.
|
|
1708
|
+
* - `freezeInputs` (default `true`) — freeze the event array before passing to reducer.
|
|
1709
|
+
* - Returns `ProjectionController<TState>` with `.node`, `.rebuild()`, `.reset()`.
|
|
1710
|
+
*
|
|
1711
|
+
* Fan-in across `events` is implemented by depending on all event-type fan-in
|
|
1712
|
+
* nodes directly, which preserves `describe()` edges (e.g. `orderPlaced →
|
|
1713
|
+
* orderCount`). Events are sorted by `(timestampNs, seq, aggregateId)` before
|
|
1714
|
+
* passing to the reducer (Option-3 cross-aggregate ordering, C.3).
|
|
1715
|
+
*/
|
|
1716
|
+
projection(opts) {
|
|
1717
|
+
const { name, events: eventNames, reducer, initial } = opts;
|
|
1718
|
+
const mode = opts.mode ?? "scan";
|
|
1719
|
+
const freezeInputs = opts.freezeInputs ?? true;
|
|
1720
|
+
const snapshotOpts = opts.snapshot;
|
|
1721
|
+
const eventNodes = eventNames.map((eName) => {
|
|
1722
|
+
if (!this._eventLogs.has(eName)) this.event(eName);
|
|
1723
|
+
return this._eventLogs.get(eName).node;
|
|
1724
|
+
});
|
|
1725
|
+
function sortEvents(evts) {
|
|
1726
|
+
evts.sort(
|
|
1727
|
+
(a, b) => a.timestampNs - b.timestampNs || a.seq - b.seq || (a.aggregateId ?? "").localeCompare(b.aggregateId ?? "")
|
|
1728
|
+
);
|
|
1729
|
+
}
|
|
1730
|
+
function collectAllEvents(snapshots) {
|
|
1731
|
+
const evts = [];
|
|
1732
|
+
for (const snap of snapshots) evts.push(...snap);
|
|
1733
|
+
sortEvents(evts);
|
|
1734
|
+
return evts;
|
|
1735
|
+
}
|
|
1736
|
+
const seedSnapshots = eventNodes.map(
|
|
1737
|
+
(n) => n.cache ?? []
|
|
1738
|
+
);
|
|
1739
|
+
const sortedSeed = collectAllEvents(seedSnapshots);
|
|
1740
|
+
const frozenSeed = freezeInputs ? Object.freeze(sortedSeed) : sortedSeed;
|
|
1741
|
+
let lastProcessedCount = 0;
|
|
1742
|
+
let scanState = initial;
|
|
1743
|
+
if (mode === "scan" && sortedSeed.length > 0) {
|
|
1744
|
+
scanState = reducer(initial, frozenSeed);
|
|
1745
|
+
lastProcessedCount = sortedSeed.length;
|
|
1746
|
+
}
|
|
1747
|
+
const seedState = mode === "replay" ? reducer(initial, frozenSeed) : scanState;
|
|
1748
|
+
const saveDebounceMs = snapshotOpts?.saveDebounceMs ?? 1e3;
|
|
1749
|
+
const saveEvery = snapshotOpts?.saveEvery ?? 1e3;
|
|
1750
|
+
let saveTimer;
|
|
1751
|
+
let savesSinceLastFlush = 0;
|
|
1752
|
+
function scheduleSave(currentState) {
|
|
1753
|
+
if (!snapshotOpts?.save) return;
|
|
1754
|
+
savesSinceLastFlush += 1;
|
|
1755
|
+
if (savesSinceLastFlush >= saveEvery) {
|
|
1756
|
+
savesSinceLastFlush = 0;
|
|
1757
|
+
if (saveTimer !== void 0) {
|
|
1758
|
+
clearTimeout(saveTimer);
|
|
1759
|
+
saveTimer = void 0;
|
|
1760
|
+
}
|
|
1761
|
+
const result = snapshotOpts.save(currentState);
|
|
1762
|
+
if (result instanceof Promise) result.catch(() => void 0);
|
|
1763
|
+
return;
|
|
1764
|
+
}
|
|
1765
|
+
if (saveTimer !== void 0) clearTimeout(saveTimer);
|
|
1766
|
+
saveTimer = setTimeout(() => {
|
|
1767
|
+
saveTimer = void 0;
|
|
1768
|
+
savesSinceLastFlush = 0;
|
|
1769
|
+
const result = snapshotOpts.save(currentState);
|
|
1770
|
+
if (result instanceof Promise) result.catch(() => void 0);
|
|
1771
|
+
}, saveDebounceMs);
|
|
1772
|
+
}
|
|
1773
|
+
const projNode = this.derived(
|
|
1774
|
+
name,
|
|
1775
|
+
eventNames,
|
|
1776
|
+
(batchData, ctx) => {
|
|
1777
|
+
const snapshots = batchData.map(
|
|
1778
|
+
(batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
|
|
1779
|
+
);
|
|
1780
|
+
const allEvents = collectAllEvents(snapshots);
|
|
1781
|
+
let newState;
|
|
1782
|
+
if (mode === "replay") {
|
|
1783
|
+
const frozen = freezeInputs ? Object.freeze(allEvents) : allEvents;
|
|
1784
|
+
newState = reducer(initial, frozen);
|
|
1785
|
+
} else {
|
|
1786
|
+
const newOnly = allEvents.slice(lastProcessedCount);
|
|
1787
|
+
lastProcessedCount = allEvents.length;
|
|
1788
|
+
const frozenNew = freezeInputs ? Object.freeze(newOnly) : newOnly;
|
|
1789
|
+
newState = reducer(scanState, frozenNew);
|
|
1790
|
+
scanState = newState;
|
|
1791
|
+
}
|
|
1792
|
+
scheduleSave(newState);
|
|
1793
|
+
return [newState];
|
|
1794
|
+
},
|
|
1795
|
+
{
|
|
1796
|
+
meta: cqrsMeta("projection", { projection_name: name, source_events: eventNames }),
|
|
1797
|
+
guard: PROJECTION_GUARD,
|
|
1798
|
+
initial: seedState
|
|
1799
|
+
}
|
|
1800
|
+
);
|
|
1801
|
+
this.addDisposer((0, import_extra4.keepalive)(projNode));
|
|
1802
|
+
this.addDisposer(() => {
|
|
1803
|
+
if (saveTimer !== void 0) {
|
|
1804
|
+
clearTimeout(saveTimer);
|
|
1805
|
+
saveTimer = void 0;
|
|
1806
|
+
}
|
|
1807
|
+
});
|
|
1808
|
+
this._projections.add(name);
|
|
1809
|
+
const rebuild = async (rebuildOpts) => {
|
|
1810
|
+
try {
|
|
1811
|
+
const pageSize = rebuildOpts?.pageSize ?? 1e3;
|
|
1812
|
+
const tier = rebuildOpts?.fromTier ?? this._attachedEventTiers[0]?.[0];
|
|
1813
|
+
const preBuildCount = collectAllEvents(
|
|
1814
|
+
eventNodes.map((n) => n.cache ?? [])
|
|
1815
|
+
).length;
|
|
1816
|
+
let rebuildState = initial;
|
|
1817
|
+
if (snapshotOpts?.load) {
|
|
1818
|
+
const loaded = await snapshotOpts.load();
|
|
1819
|
+
if (loaded !== void 0) rebuildState = loaded;
|
|
1820
|
+
}
|
|
1821
|
+
if (!tier || !tier.loadEntries) {
|
|
1822
|
+
const inMemory = collectAllEvents(
|
|
1823
|
+
eventNodes.map((n) => n.cache ?? [])
|
|
1824
|
+
);
|
|
1825
|
+
const frozen = freezeInputs ? Object.freeze(inMemory) : inMemory;
|
|
1826
|
+
rebuildState = reducer(rebuildState, frozen);
|
|
1827
|
+
} else {
|
|
1828
|
+
const watchedEvents = new Set(eventNames);
|
|
1829
|
+
let cursor;
|
|
1830
|
+
let done = false;
|
|
1831
|
+
while (!done) {
|
|
1832
|
+
const result = await tier.loadEntries({ cursor, pageSize });
|
|
1833
|
+
const page = [...result.entries].filter((e) => watchedEvents.has(e.type));
|
|
1834
|
+
sortEvents(page);
|
|
1835
|
+
const frozenPage = freezeInputs ? Object.freeze(page) : page;
|
|
1836
|
+
rebuildState = reducer(rebuildState, frozenPage);
|
|
1837
|
+
cursor = result.cursor;
|
|
1838
|
+
done = !cursor || result.entries.length === 0;
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
if (mode === "scan") {
|
|
1842
|
+
const allInMemory = collectAllEvents(
|
|
1843
|
+
eventNodes.map((n) => n.cache ?? [])
|
|
1844
|
+
);
|
|
1845
|
+
const pendingEvents = allInMemory.slice(preBuildCount);
|
|
1846
|
+
if (pendingEvents.length > 0) {
|
|
1847
|
+
const frozenPending = freezeInputs ? Object.freeze(pendingEvents) : pendingEvents;
|
|
1848
|
+
rebuildState = reducer(rebuildState, frozenPending);
|
|
1849
|
+
}
|
|
1850
|
+
scanState = rebuildState;
|
|
1851
|
+
lastProcessedCount = allInMemory.length;
|
|
1852
|
+
}
|
|
1853
|
+
projNode.emit(rebuildState, { internal: true });
|
|
1854
|
+
return rebuildState;
|
|
1855
|
+
} catch (err) {
|
|
1856
|
+
throw new RebuildError(name, err);
|
|
1857
|
+
}
|
|
1858
|
+
};
|
|
1859
|
+
const reset = async () => {
|
|
1860
|
+
try {
|
|
1861
|
+
let baseState = initial;
|
|
1862
|
+
if (snapshotOpts?.load) {
|
|
1863
|
+
const loaded = await snapshotOpts.load();
|
|
1864
|
+
if (loaded !== void 0) baseState = loaded;
|
|
1865
|
+
}
|
|
1866
|
+
const inMemory = collectAllEvents(
|
|
1867
|
+
eventNodes.map((n) => n.cache ?? [])
|
|
1868
|
+
);
|
|
1869
|
+
const frozen = freezeInputs ? Object.freeze(inMemory) : inMemory;
|
|
1870
|
+
const newState = reducer(baseState, frozen);
|
|
1871
|
+
if (mode === "scan") {
|
|
1872
|
+
scanState = newState;
|
|
1873
|
+
lastProcessedCount = inMemory.length;
|
|
1874
|
+
}
|
|
1875
|
+
projNode.emit(newState, { internal: true });
|
|
1876
|
+
return newState;
|
|
1877
|
+
} catch (err) {
|
|
1878
|
+
throw new RebuildError(name, err);
|
|
1879
|
+
}
|
|
1880
|
+
};
|
|
1881
|
+
return { node: projNode, rebuild, reset };
|
|
1882
|
+
}
|
|
1883
|
+
// -- Sagas ----------------------------------------------------------------
|
|
1884
|
+
/**
|
|
1885
|
+
* Register an event-driven side effect. Runs handler for each **new** event
|
|
1886
|
+
* from the specified streams (tracks last-processed entry count per stream).
|
|
1887
|
+
*
|
|
1888
|
+
* The saga node carries dynamic `meta.error` — a reactive companion that
|
|
1889
|
+
* holds the last handler error (or `null` on success). Handler errors do
|
|
1890
|
+
* not propagate out of the saga run (the event cursor still advances so
|
|
1891
|
+
* the same entry is not delivered twice).
|
|
1892
|
+
*/
|
|
1893
|
+
saga(name, eventNames, handler, opts = {}) {
|
|
1894
|
+
const _eventNodes = eventNames.map((eName) => {
|
|
1895
|
+
if (!this._eventLogs.has(eName)) this.event(eName);
|
|
1896
|
+
return this._eventLogs.get(eName).node;
|
|
1897
|
+
});
|
|
1898
|
+
const cursors = registerCursorMap(this, `${name}_cursor`, eventNames, 0);
|
|
1899
|
+
const invocations = createAuditLog({
|
|
1900
|
+
name: `${name}_invocations`,
|
|
1901
|
+
retainedLimit: this._retainedLimit,
|
|
1902
|
+
graph: this
|
|
1903
|
+
});
|
|
1904
|
+
const aggregateFilter = opts.aggregateId;
|
|
1905
|
+
const errorPolicy = opts.errorPolicy ?? "advance";
|
|
1906
|
+
const latestCursors = /* @__PURE__ */ new Map();
|
|
1907
|
+
for (const eName of eventNames) {
|
|
1908
|
+
const cursor = cursors[eName];
|
|
1909
|
+
latestCursors.set(eName, cursor.cache ?? 0);
|
|
1910
|
+
const sub = cursor.subscribe((msgs) => {
|
|
1911
|
+
for (const m of msgs) if (m[0] === import_core7.DATA) latestCursors.set(eName, m[1]);
|
|
1912
|
+
});
|
|
1913
|
+
this.addDisposer(sub);
|
|
1914
|
+
}
|
|
1915
|
+
const auditedHandler = mutate(
|
|
1916
|
+
(ev, _eName) => {
|
|
1917
|
+
handler(ev);
|
|
1918
|
+
},
|
|
1919
|
+
{
|
|
1920
|
+
frame: "inline",
|
|
1921
|
+
log: invocations,
|
|
1922
|
+
freeze: false,
|
|
1923
|
+
...opts.handlerVersion !== void 0 ? { handlerVersion: opts.handlerVersion } : {},
|
|
1924
|
+
// D5 (qa lock): always include the `aggregateId` key (even when
|
|
1925
|
+
// undefined) for parity with the pre-Tier-8 saga record shape.
|
|
1926
|
+
// Consumers using `Object.hasOwn(record, "aggregateId")` or JSON
|
|
1927
|
+
// serialization shape would observe a pre-1.0 break otherwise.
|
|
1928
|
+
onSuccessRecord: ([ev, eName], _r, { t_ns }) => ({
|
|
1929
|
+
eventType: eName,
|
|
1930
|
+
outcome: "success",
|
|
1931
|
+
aggregateId: ev.aggregateId,
|
|
1932
|
+
event: ev,
|
|
1933
|
+
t_ns
|
|
1934
|
+
}),
|
|
1935
|
+
onFailureRecord: ([ev, eName], err, { t_ns, errorType }) => ({
|
|
1936
|
+
eventType: eName,
|
|
1937
|
+
outcome: "failure",
|
|
1938
|
+
error: err,
|
|
1939
|
+
errorType,
|
|
1940
|
+
aggregateId: ev.aggregateId,
|
|
1941
|
+
event: ev,
|
|
1942
|
+
t_ns
|
|
1943
|
+
})
|
|
1944
|
+
}
|
|
1945
|
+
);
|
|
1946
|
+
const sagaRef = {};
|
|
1947
|
+
const sagaNode = this.effect(
|
|
1948
|
+
name,
|
|
1949
|
+
eventNames,
|
|
1950
|
+
(snapshots, _up) => {
|
|
1951
|
+
const errNode = sagaRef.n.meta.error;
|
|
1952
|
+
for (let i = 0; i < snapshots.length; i++) {
|
|
1953
|
+
const batch2 = snapshots[i];
|
|
1954
|
+
if (batch2 == null || batch2.length === 0) continue;
|
|
1955
|
+
const entries = batch2.at(-1);
|
|
1956
|
+
if (!entries) continue;
|
|
1957
|
+
const eName = eventNames[i];
|
|
1958
|
+
const cursor = cursors[eName];
|
|
1959
|
+
const lastCount = latestCursors.get(eName) ?? 0;
|
|
1960
|
+
if (entries.length > lastCount) {
|
|
1961
|
+
const newEntries = entries.slice(lastCount);
|
|
1962
|
+
let advancedTo = lastCount;
|
|
1963
|
+
for (const entry of newEntries) {
|
|
1964
|
+
const ev = entry;
|
|
1965
|
+
if (aggregateFilter !== void 0 && ev.aggregateId !== aggregateFilter) {
|
|
1966
|
+
advancedTo += 1;
|
|
1967
|
+
continue;
|
|
1968
|
+
}
|
|
1969
|
+
try {
|
|
1970
|
+
auditedHandler(ev, eName);
|
|
1971
|
+
errNode.emit(null, { internal: true });
|
|
1972
|
+
advancedTo += 1;
|
|
1973
|
+
} catch (err) {
|
|
1974
|
+
errNode.emit(err, { internal: true });
|
|
1975
|
+
if (errorPolicy === "hold") break;
|
|
1976
|
+
advancedTo += 1;
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
cursor.emit(advancedTo);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
},
|
|
1983
|
+
{
|
|
1984
|
+
meta: {
|
|
1985
|
+
...cqrsMeta("saga", { saga_name: name, source_events: eventNames }),
|
|
1986
|
+
error: null
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
);
|
|
1990
|
+
sagaRef.n = sagaNode;
|
|
1991
|
+
this.addDisposer((0, import_extra4.keepalive)(sagaNode));
|
|
1992
|
+
this._sagas.add(name);
|
|
1993
|
+
return {
|
|
1994
|
+
node: sagaNode,
|
|
1995
|
+
invocations,
|
|
1996
|
+
audit: invocations,
|
|
1997
|
+
cursors
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
2001
|
+
function cqrs(name, opts) {
|
|
2002
|
+
const g = new CqrsGraph(name, opts);
|
|
2003
|
+
const { factory: _f, factoryArgs: _fa, ...tagArgs } = opts ?? {};
|
|
2004
|
+
g.tagFactory("cqrs", (0, import_core7.placeholderArgs)(tagArgs));
|
|
2005
|
+
return g;
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
// src/compat/nestjs/module.ts
|
|
2009
|
+
var GraphReflyRootLifecycle = class {
|
|
2010
|
+
constructor(graph) {
|
|
2011
|
+
this.graph = graph;
|
|
2012
|
+
}
|
|
2013
|
+
onModuleDestroy() {
|
|
2014
|
+
this.graph.destroy();
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
var GraphReflyRequestLifecycle = class {
|
|
2018
|
+
graph = new import_graph3.Graph("request");
|
|
2019
|
+
onModuleDestroy() {
|
|
2020
|
+
this.graph.destroy();
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
2023
|
+
var _GraphReflyModule_decorators, _init;
|
|
2024
|
+
_GraphReflyModule_decorators = [(0, import_common2.Module)({})];
|
|
2025
|
+
var _GraphReflyModule = class _GraphReflyModule {
|
|
2026
|
+
/**
|
|
2027
|
+
* Register the root `Graph` singleton in the NestJS DI container.
|
|
2028
|
+
*
|
|
2029
|
+
* The root graph is `@Global()` — injectable everywhere without importing
|
|
2030
|
+
* the module again. Use `@InjectGraph()` to inject it.
|
|
2031
|
+
*
|
|
2032
|
+
* Lifecycle:
|
|
2033
|
+
* - **init:** Graph created in factory. If `build` is provided, it runs
|
|
2034
|
+
* first (registers nodes/mounts). If `snapshot` is provided, values
|
|
2035
|
+
* are restored via `graph.restore()`.
|
|
2036
|
+
* - **destroy:** Calls `graph.destroy()` — sends `[[TEARDOWN]]` to all
|
|
2037
|
+
* nodes, including mounted feature subgraphs (cascading teardown).
|
|
2038
|
+
*/
|
|
2039
|
+
static forRoot(opts) {
|
|
2040
|
+
const options = opts ?? {};
|
|
2041
|
+
const graphName = options.name ?? "root";
|
|
2042
|
+
const providers = [
|
|
2043
|
+
{
|
|
2044
|
+
provide: GRAPHREFLY_ROOT_GRAPH,
|
|
2045
|
+
useFactory: () => {
|
|
2046
|
+
const g = new import_graph3.Graph(graphName);
|
|
2047
|
+
if (options.build) options.build(g);
|
|
2048
|
+
if (options.snapshot) g.restore(options.snapshot);
|
|
2049
|
+
return g;
|
|
2050
|
+
}
|
|
2051
|
+
},
|
|
2052
|
+
{
|
|
2053
|
+
provide: /* @__PURE__ */ Symbol.for("graphrefly:root-lifecycle"),
|
|
2054
|
+
useFactory: (graph) => new GraphReflyRootLifecycle(graph),
|
|
2055
|
+
inject: [GRAPHREFLY_ROOT_GRAPH]
|
|
2056
|
+
},
|
|
2057
|
+
{
|
|
2058
|
+
provide: GraphReflyEventExplorer,
|
|
2059
|
+
useFactory: (graph, moduleRef) => new GraphReflyEventExplorer(graph, moduleRef),
|
|
2060
|
+
inject: [GRAPHREFLY_ROOT_GRAPH, import_core8.ModuleRef]
|
|
2061
|
+
}
|
|
2062
|
+
];
|
|
2063
|
+
if (options.nodes) {
|
|
2064
|
+
for (const path of options.nodes) {
|
|
2065
|
+
providers.push({
|
|
2066
|
+
provide: getNodeToken(path),
|
|
2067
|
+
useFactory: (graph) => graph.resolve(path),
|
|
2068
|
+
inject: [GRAPHREFLY_ROOT_GRAPH]
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
if (options.requestScope) {
|
|
2073
|
+
providers.push(
|
|
2074
|
+
{
|
|
2075
|
+
provide: /* @__PURE__ */ Symbol.for("graphrefly:request-lifecycle"),
|
|
2076
|
+
useFactory: () => new GraphReflyRequestLifecycle(),
|
|
2077
|
+
scope: import_common2.Scope.REQUEST
|
|
2078
|
+
},
|
|
2079
|
+
{
|
|
2080
|
+
provide: GRAPHREFLY_REQUEST_GRAPH,
|
|
2081
|
+
useFactory: (lifecycle) => lifecycle.graph,
|
|
2082
|
+
inject: [/* @__PURE__ */ Symbol.for("graphrefly:request-lifecycle")],
|
|
2083
|
+
scope: import_common2.Scope.REQUEST
|
|
2084
|
+
}
|
|
2085
|
+
);
|
|
2086
|
+
}
|
|
2087
|
+
return {
|
|
2088
|
+
module: _GraphReflyModule,
|
|
2089
|
+
global: true,
|
|
2090
|
+
providers,
|
|
2091
|
+
exports: [
|
|
2092
|
+
GRAPHREFLY_ROOT_GRAPH,
|
|
2093
|
+
...(options.nodes ?? []).map(getNodeToken),
|
|
2094
|
+
...options.requestScope ? [GRAPHREFLY_REQUEST_GRAPH] : []
|
|
2095
|
+
]
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
/**
|
|
2099
|
+
* Register a feature subgraph that auto-mounts into the root graph.
|
|
2100
|
+
*
|
|
2101
|
+
* The feature graph is created in the factory, built/restored, then
|
|
2102
|
+
* mounted into root via `root.mount(name, featureGraph)`. On app
|
|
2103
|
+
* shutdown, root's `graph.destroy()` cascades TEARDOWN through all
|
|
2104
|
+
* mounted subgraphs (no explicit remove needed).
|
|
2105
|
+
*
|
|
2106
|
+
* Node tokens are auto-qualified as `featureName::path` to prevent
|
|
2107
|
+
* collisions between features declaring nodes with the same local name.
|
|
2108
|
+
*
|
|
2109
|
+
* Injectable via `@InjectGraph(name)`.
|
|
2110
|
+
*/
|
|
2111
|
+
static forFeature(opts) {
|
|
2112
|
+
const providers = [
|
|
2113
|
+
{
|
|
2114
|
+
provide: getGraphToken(opts.name),
|
|
2115
|
+
useFactory: (rootGraph) => {
|
|
2116
|
+
const g = new import_graph3.Graph(opts.name);
|
|
2117
|
+
if (opts.build) opts.build(g);
|
|
2118
|
+
if (opts.snapshot) g.restore(opts.snapshot);
|
|
2119
|
+
rootGraph.mount(opts.name, g);
|
|
2120
|
+
return g;
|
|
2121
|
+
},
|
|
2122
|
+
inject: [GRAPHREFLY_ROOT_GRAPH]
|
|
2123
|
+
}
|
|
2124
|
+
];
|
|
2125
|
+
if (opts.nodes) {
|
|
2126
|
+
for (const path of opts.nodes) {
|
|
2127
|
+
providers.push({
|
|
2128
|
+
provide: getNodeToken(`${opts.name}::${path}`),
|
|
2129
|
+
useFactory: (graph) => graph.resolve(path),
|
|
2130
|
+
inject: [getGraphToken(opts.name)]
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
return {
|
|
2135
|
+
module: _GraphReflyModule,
|
|
2136
|
+
providers,
|
|
2137
|
+
exports: [
|
|
2138
|
+
getGraphToken(opts.name),
|
|
2139
|
+
...(opts.nodes ?? []).map((p) => getNodeToken(`${opts.name}::${p}`))
|
|
2140
|
+
]
|
|
2141
|
+
};
|
|
2142
|
+
}
|
|
2143
|
+
/**
|
|
2144
|
+
* Register a CQRS subgraph that auto-mounts into the root graph.
|
|
2145
|
+
*
|
|
2146
|
+
* Creates a `CqrsGraph` via the `cqrs()` factory (roadmap §4.5), mounts it
|
|
2147
|
+
* into the root graph, and exposes it for DI via `@InjectGraph(name)`.
|
|
2148
|
+
*
|
|
2149
|
+
* CQRS decorators (`@CommandHandler`, `@EventHandler`, `@QueryHandler`,
|
|
2150
|
+
* `@SagaHandler`) are discovered by the explorer and wired to this graph
|
|
2151
|
+
* on module init.
|
|
2152
|
+
*
|
|
2153
|
+
* @example
|
|
2154
|
+
* ```ts
|
|
2155
|
+
* GraphReflyModule.forCqrs({
|
|
2156
|
+
* name: "orders",
|
|
2157
|
+
* build: (g) => {
|
|
2158
|
+
* g.event("orderPlaced");
|
|
2159
|
+
* g.projection({ name: "orderCount", events: ["orderPlaced"], reducer: (_s, evts) => evts.length, initial: 0 });
|
|
2160
|
+
* },
|
|
2161
|
+
* })
|
|
2162
|
+
* ```
|
|
2163
|
+
*/
|
|
2164
|
+
static forCqrs(opts) {
|
|
2165
|
+
const providers = [
|
|
2166
|
+
{
|
|
2167
|
+
provide: getGraphToken(opts.name),
|
|
2168
|
+
useFactory: (rootGraph) => {
|
|
2169
|
+
const g = cqrs(opts.name, opts.cqrs);
|
|
2170
|
+
if (opts.eventStorage) g.attachEventStorage(opts.eventStorage);
|
|
2171
|
+
if (opts.build) opts.build(g);
|
|
2172
|
+
rootGraph.mount(opts.name, g);
|
|
2173
|
+
return g;
|
|
2174
|
+
},
|
|
2175
|
+
inject: [GRAPHREFLY_ROOT_GRAPH]
|
|
2176
|
+
}
|
|
2177
|
+
];
|
|
2178
|
+
if (opts.nodes) {
|
|
2179
|
+
for (const path of opts.nodes) {
|
|
2180
|
+
providers.push({
|
|
2181
|
+
provide: getNodeToken(`${opts.name}::${path}`),
|
|
2182
|
+
useFactory: (graph) => graph.resolve(path),
|
|
2183
|
+
inject: [getGraphToken(opts.name)]
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
return {
|
|
2188
|
+
module: _GraphReflyModule,
|
|
2189
|
+
providers,
|
|
2190
|
+
exports: [
|
|
2191
|
+
getGraphToken(opts.name),
|
|
2192
|
+
...(opts.nodes ?? []).map((p) => getNodeToken(`${opts.name}::${p}`))
|
|
2193
|
+
]
|
|
2194
|
+
};
|
|
2195
|
+
}
|
|
2196
|
+
};
|
|
2197
|
+
_init = __decoratorStart(null);
|
|
2198
|
+
_GraphReflyModule = __decorateElement(_init, 0, "GraphReflyModule", _GraphReflyModule_decorators, _GraphReflyModule);
|
|
2199
|
+
__runInitializers(_init, 1, _GraphReflyModule);
|
|
2200
|
+
var GraphReflyModule = _GraphReflyModule;
|
|
2201
|
+
|
|
2202
|
+
// src/compat/nestjs/observable.ts
|
|
2203
|
+
var import_rxjs = require("rxjs");
|
|
2204
|
+
|
|
2205
|
+
// src/base/composition/observable.ts
|
|
2206
|
+
var import_core9 = require("@graphrefly/pure-ts/core");
|
|
2207
|
+
var OBSERVABLE_KEY = typeof Symbol === "function" && Symbol.observable || "@@observable";
|
|
2208
|
+
function normalizeObserver(observer) {
|
|
2209
|
+
return typeof observer === "function" ? { next: observer } : observer;
|
|
2210
|
+
}
|
|
2211
|
+
function makeInterop(onSubscribe) {
|
|
2212
|
+
const obs = {
|
|
2213
|
+
subscribe(rawObserver) {
|
|
2214
|
+
const observer = normalizeObserver(rawObserver);
|
|
2215
|
+
let closed = false;
|
|
2216
|
+
let teardown;
|
|
2217
|
+
let teardownPending = false;
|
|
2218
|
+
const runTeardown = () => {
|
|
2219
|
+
if (teardown) teardown();
|
|
2220
|
+
else teardownPending = true;
|
|
2221
|
+
};
|
|
2222
|
+
const guarded = {
|
|
2223
|
+
get closed() {
|
|
2224
|
+
return closed;
|
|
2225
|
+
},
|
|
2226
|
+
next(value) {
|
|
2227
|
+
if (!closed) observer.next?.(value);
|
|
2228
|
+
},
|
|
2229
|
+
error(err) {
|
|
2230
|
+
if (closed) return;
|
|
2231
|
+
closed = true;
|
|
2232
|
+
try {
|
|
2233
|
+
observer.error?.(err);
|
|
2234
|
+
} finally {
|
|
2235
|
+
runTeardown();
|
|
2236
|
+
}
|
|
2237
|
+
},
|
|
2238
|
+
complete() {
|
|
2239
|
+
if (closed) return;
|
|
2240
|
+
closed = true;
|
|
2241
|
+
try {
|
|
2242
|
+
observer.complete?.();
|
|
2243
|
+
} finally {
|
|
2244
|
+
runTeardown();
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
};
|
|
2248
|
+
teardown = onSubscribe(guarded);
|
|
2249
|
+
if (teardownPending) teardown();
|
|
2250
|
+
return {
|
|
2251
|
+
unsubscribe() {
|
|
2252
|
+
if (closed) return;
|
|
2253
|
+
closed = true;
|
|
2254
|
+
teardown?.();
|
|
2255
|
+
}
|
|
2256
|
+
};
|
|
2257
|
+
}
|
|
2258
|
+
};
|
|
2259
|
+
obs[OBSERVABLE_KEY] = function() {
|
|
2260
|
+
return this;
|
|
2261
|
+
};
|
|
2262
|
+
return obs;
|
|
2263
|
+
}
|
|
2264
|
+
function toObservable(node4, options) {
|
|
2265
|
+
if (options?.raw) {
|
|
2266
|
+
return makeInterop((observer) => {
|
|
2267
|
+
return node4.subscribe((msgs) => {
|
|
2268
|
+
if (observer.closed) return;
|
|
2269
|
+
observer.next?.(msgs);
|
|
2270
|
+
for (const m of msgs) {
|
|
2271
|
+
if (m[0] === import_core9.ERROR) {
|
|
2272
|
+
observer.error?.(m[1]);
|
|
2273
|
+
return;
|
|
2274
|
+
}
|
|
2275
|
+
if (m[0] === import_core9.COMPLETE) {
|
|
2276
|
+
observer.complete?.();
|
|
2277
|
+
return;
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
});
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
return makeInterop((observer) => {
|
|
2284
|
+
return node4.subscribe((msgs) => {
|
|
2285
|
+
for (const m of msgs) {
|
|
2286
|
+
if (observer.closed) return;
|
|
2287
|
+
if (m[0] === import_core9.DATA) {
|
|
2288
|
+
observer.next?.(m[1]);
|
|
2289
|
+
} else if (m[0] === import_core9.ERROR) {
|
|
2290
|
+
observer.error?.(m[1]);
|
|
2291
|
+
return;
|
|
2292
|
+
} else if (m[0] === import_core9.COMPLETE) {
|
|
2293
|
+
observer.complete?.();
|
|
2294
|
+
return;
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
});
|
|
2298
|
+
});
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
// src/compat/nestjs/observable.ts
|
|
2302
|
+
function toObservable2(node4, options) {
|
|
2303
|
+
const base = options?.raw ? toObservable(node4, { raw: true }) : toObservable(node4);
|
|
2304
|
+
return (0, import_rxjs.from)(base);
|
|
2305
|
+
}
|
|
21
2306
|
//# sourceMappingURL=index.cjs.map
|