@graphrefly/graphrefly 0.44.0 → 0.46.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 +22 -19
- 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 +811 -0
- package/dist/base/composition/index.cjs.map +1 -0
- package/dist/base/composition/index.d.cts +469 -0
- package/dist/base/composition/index.d.ts +469 -0
- package/dist/base/composition/index.js +40 -0
- package/dist/base/composition/index.js.map +1 -0
- package/dist/base/index.cjs +6336 -0
- package/dist/base/index.cjs.map +1 -0
- package/dist/base/index.d.cts +22 -0
- package/dist/base/index.d.ts +22 -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/{extra/render/index.d.ts → base/render/index.d.cts} +75 -31
- package/dist/{extra/render/index.d.cts → base/render/index.d.ts} +75 -31
- 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/{extra/sources.d.ts → base/sources/index.d.cts} +74 -301
- package/dist/{extra/sources.d.cts → base/sources/index.d.ts} +74 -301
- 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/{extra/node.d.ts → base/sources/node/index.d.cts} +35 -37
- package/dist/{extra/node.d.cts → base/sources/node/index.d.ts} +35 -37
- 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-BglDkMdX.d.cts → cascading-CSSbKGrJ.d.ts} +3 -3
- package/dist/{cascading-MFgxu7Yo.d.ts → cascading-baGkiihI.d.cts} +3 -3
- 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-3QZY5BI7.js +92 -0
- package/dist/chunk-3QZY5BI7.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-5THCXDWY.js +725 -0
- package/dist/chunk-5THCXDWY.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-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-FR6RGA3B.js +1277 -0
- package/dist/chunk-FR6RGA3B.js.map +1 -0
- package/dist/chunk-FW23JYNQ.js +454 -0
- package/dist/chunk-FW23JYNQ.js.map +1 -0
- package/dist/chunk-GBCENOLN.js +1575 -0
- package/dist/chunk-GBCENOLN.js.map +1 -0
- package/dist/chunk-HL7HUJIX.js +1 -0
- package/dist/chunk-HL7HUJIX.js.map +1 -0
- package/dist/chunk-HULCUY35.js +2508 -0
- package/dist/chunk-HULCUY35.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-KIIXR252.js +211 -0
- package/dist/chunk-KIIXR252.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-LBAJK24K.js +1071 -0
- package/dist/chunk-LBAJK24K.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-OO5BM6CJ.js +1153 -0
- package/dist/chunk-OO5BM6CJ.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-RGL53X5G.js +574 -0
- package/dist/chunk-RGL53X5G.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-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-W2BOPXTI.js +1 -0
- package/dist/chunk-W2BOPXTI.js.map +1 -0
- package/dist/chunk-WKSWLSCX.js +207 -0
- package/dist/chunk-WKSWLSCX.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-Z6EGP5D7.js +92 -0
- package/dist/chunk-Z6EGP5D7.js.map +1 -0
- package/dist/compat/index.cjs +3100 -9
- package/dist/compat/index.cjs.map +1 -0
- package/dist/compat/index.d.cts +112 -18
- package/dist/compat/index.d.ts +112 -18
- package/dist/compat/index.js +176 -1
- package/dist/compat/index.js.map +1 -0
- package/dist/compat/jotai/index.cjs +149 -1
- package/dist/compat/jotai/index.cjs.map +1 -0
- package/dist/compat/jotai/index.d.cts +2 -2
- package/dist/compat/jotai/index.d.ts +2 -2
- package/dist/compat/jotai/index.js +8 -1
- package/dist/compat/jotai/index.js.map +1 -0
- package/dist/compat/nanostores/index.cjs +205 -1
- package/dist/compat/nanostores/index.cjs.map +1 -0
- package/dist/compat/nanostores/index.d.cts +2 -2
- package/dist/compat/nanostores/index.d.ts +2 -2
- package/dist/compat/nanostores/index.js +22 -1
- package/dist/compat/nanostores/index.js.map +1 -0
- package/dist/compat/nestjs/index.cjs +2241 -9
- package/dist/compat/nestjs/index.cjs.map +1 -0
- package/dist/compat/nestjs/index.d.cts +7 -10
- package/dist/compat/nestjs/index.d.ts +7 -10
- package/dist/compat/nestjs/index.js +78 -1
- package/dist/compat/nestjs/index.js.map +1 -0
- package/dist/compat/react/index.cjs +114 -1
- package/dist/compat/react/index.cjs.map +1 -0
- package/dist/compat/react/index.d.cts +2 -2
- package/dist/compat/react/index.d.ts +2 -2
- package/dist/compat/react/index.js +12 -1
- package/dist/compat/react/index.js.map +1 -0
- package/dist/compat/solid/index.cjs +101 -1
- package/dist/compat/solid/index.cjs.map +1 -0
- package/dist/compat/solid/index.d.cts +2 -2
- package/dist/compat/solid/index.d.ts +2 -2
- package/dist/compat/solid/index.js +12 -1
- package/dist/compat/solid/index.js.map +1 -0
- package/dist/compat/svelte/index.cjs +104 -1
- package/dist/compat/svelte/index.cjs.map +1 -0
- package/dist/compat/svelte/index.d.cts +2 -2
- package/dist/compat/svelte/index.d.ts +2 -2
- package/dist/compat/svelte/index.js +12 -1
- package/dist/compat/svelte/index.js.map +1 -0
- package/dist/compat/vue/index.cjs +119 -1
- package/dist/compat/vue/index.cjs.map +1 -0
- package/dist/compat/vue/index.d.cts +2 -2
- package/dist/compat/vue/index.d.ts +2 -2
- package/dist/compat/vue/index.js +12 -1
- package/dist/compat/vue/index.js.map +1 -0
- package/dist/compat/zustand/index.cjs +69 -3
- package/dist/compat/zustand/index.cjs.map +1 -0
- package/dist/compat/zustand/index.d.cts +2 -6
- package/dist/compat/zustand/index.d.ts +2 -6
- package/dist/compat/zustand/index.js +8 -1
- package/dist/compat/zustand/index.js.map +1 -0
- 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-74oxi34l.d.cts → fallback-Bx46zqky.d.cts} +3 -10
- package/dist/{fallback-DUyyBTBK.d.ts → fallback-pIWW8A2d.d.ts} +3 -10
- package/dist/guarded-execution-BcdtxeBk.d.ts +207 -0
- package/dist/guarded-execution-C-3hnP6A.d.cts +207 -0
- package/dist/{index-CBGUK09R.d.ts → index-5SU_O78r.d.cts} +5 -5
- package/dist/{index-BmZXHqkE.d.ts → index-B6pxYJzO.d.cts} +1 -1
- package/dist/{index-hcDJ8PSI.d.cts → index-B6pxYJzO.d.ts} +1 -1
- package/dist/{index-C5stwKcw.d.cts → index-BFsng6v1.d.cts} +1 -1
- package/dist/{index-CdAlHFEt.d.ts → index-BFsng6v1.d.ts} +1 -1
- package/dist/{index-_6ODbuOu.d.cts → index-Bg-LwEt-.d.cts} +1 -1
- package/dist/{index-CviRnE4K.d.ts → index-Bg-LwEt-.d.ts} +1 -1
- package/dist/{index-CBBLl_rc.d.ts → index-Brp888t0.d.cts} +1 -1
- package/dist/{index-BQSKmbuG.d.cts → index-Brp888t0.d.ts} +1 -1
- package/dist/{index-sqkqlb1p.d.ts → index-CDfk6jHN.d.cts} +1 -1
- package/dist/{index-ZVQhLa2i.d.cts → index-CDfk6jHN.d.ts} +1 -1
- package/dist/{index-Climxqsu.d.cts → index-CEXCtYYJ.d.ts} +5 -5
- package/dist/index-DLAxYaN5.d.cts +169 -0
- package/dist/index-DLAxYaN5.d.ts +169 -0
- package/dist/{index-CK29LV56.d.cts → index-DeWbQzMe.d.cts} +1 -1
- package/dist/{index-CPQlGA29.d.ts → index-DeWbQzMe.d.ts} +1 -1
- package/dist/{index-BrPrLl4e.d.cts → index-dX9IzPqj.d.cts} +1 -1
- package/dist/{index-Dgl1HpPn.d.ts → index-dX9IzPqj.d.ts} +1 -1
- package/dist/index.cjs +25934 -191
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +58 -94
- package/dist/index.d.ts +58 -94
- package/dist/index.js +852 -1
- package/dist/index.js.map +1 -0
- 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-DWjNfLvC.d.ts → observable-BXQoW1P-.d.cts} +1 -1
- package/dist/{observable-e3eiPPFy.d.cts → observable-BXQoW1P-.d.ts} +1 -1
- package/dist/{pipeline-graph-Sgj0gCwn.d.ts → pipeline-graph-Ce47CB6Y.d.cts} +13 -10
- package/dist/{pipeline-graph-CIKhynsF.d.cts → pipeline-graph-DXCwY9vG.d.ts} +13 -10
- 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-DOTs9P3X.d.ts → reactive-layout-fswlBUvX.d.cts} +19 -7
- package/dist/{reactive-layout-DgctbqZo.d.cts → reactive-layout-fswlBUvX.d.ts} +19 -7
- 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-CWFysE9E.d.ts → types-BB5Lw-pB.d.cts} +3 -3
- package/dist/{types-C0_yquda.d.cts → types-BB5Lw-pB.d.ts} +3 -3
- 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/{patterns → utils}/ai/browser.d.cts +7 -5
- package/dist/{patterns → utils}/ai/browser.d.ts +7 -5
- 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/{index-CR8QpwX8.d.ts → utils/ai/index.d.cts} +73 -976
- package/dist/{index-UPSiS-X7.d.cts → utils/ai/index.d.ts} +73 -976
- 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/{patterns → utils}/ai/node.d.cts +5 -7
- package/dist/{patterns → utils}/ai/node.d.ts +5 -7
- 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/{index-CeFiHtAg.d.ts → utils/cqrs/index.d.cts} +7 -37
- package/dist/{index-B-_tFaqV.d.cts → utils/cqrs/index.d.ts} +7 -37
- 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/{index-B8YnZpIR.d.ts → utils/demo-shell/index.d.cts} +4 -16
- package/dist/{index-Cwv0KWcU.d.cts → utils/demo-shell/index.d.ts} +4 -16
- 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/{index-CzLVrjxn.d.ts → utils/domain-templates/index.d.cts} +3 -20
- package/dist/{index-BaQaY_IQ.d.cts → utils/domain-templates/index.d.ts} +3 -20
- 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/{index-CMh5Rz1y.d.ts → utils/graphspec/index.d.cts} +106 -42
- package/dist/{index-CS0LTlB8.d.cts → utils/graphspec/index.d.ts} +106 -42
- 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 +17609 -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/{index-DisjX8a-.d.ts → utils/job-queue/index.d.cts} +5 -26
- package/dist/{index-DV_1YuVk.d.cts → utils/job-queue/index.d.ts} +5 -26
- 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 +1451 -0
- package/dist/utils/memory/index.cjs.map +1 -0
- package/dist/{index-CZ3r5Rxp.d.ts → utils/memory/index.d.cts} +242 -34
- package/dist/{index-B17QddL1.d.cts → utils/memory/index.d.ts} +242 -34
- 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/{index-p09KSrTN.d.ts → utils/process/index.d.cts} +97 -44
- package/dist/{index-CasX6Pfq.d.cts → utils/process/index.d.ts} +97 -44
- 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/{index-B5S8ULbU.d.ts → utils/reactive-layout/index.d.cts} +58 -81
- package/dist/{index-Dc4AYqrJ.d.cts → utils/reactive-layout/index.d.ts} +58 -81
- 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/{index-Byu-OpX_.d.ts → utils/reduction/index.d.cts} +6 -17
- package/dist/{index-tRCxuAXF.d.cts → utils/reduction/index.d.ts} +6 -17
- 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/{index-CYq8vAyV.d.ts → utils/surface/index.d.cts} +7 -58
- package/dist/{index-CSOmP7xT.d.cts → utils/surface/index.d.ts} +7 -58
- 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 +664 -584
- package/dist/backoff-HPZMEZNF.js +0 -1
- package/dist/chunk-2T7U5EU6.js +0 -1
- package/dist/chunk-3G5U5QNE.js +0 -5
- package/dist/chunk-4VVTGLXJ.js +0 -1
- package/dist/chunk-5M4CCMMD.js +0 -45
- package/dist/chunk-5QDBSZBV.js +0 -1
- package/dist/chunk-5XJ6B66J.js +0 -1
- package/dist/chunk-6QZNQS5B.js +0 -1
- package/dist/chunk-6X7AFUJV.js +0 -9
- package/dist/chunk-7K6PWTDQ.js +0 -1
- package/dist/chunk-7LIAPXJB.js +0 -1
- package/dist/chunk-7WPU3UHQ.js +0 -1
- package/dist/chunk-A5WCQ5NO.js +0 -1
- package/dist/chunk-APPIWSGD.js +0 -84
- package/dist/chunk-BEZWM2SY.js +0 -1
- package/dist/chunk-C72GO4IZ.js +0 -1
- package/dist/chunk-CB676TKJ.js +0 -1
- package/dist/chunk-CE6TI2TL.js +0 -1
- package/dist/chunk-CE72X3WO.js +0 -1
- package/dist/chunk-CK2E7BTU.js +0 -1
- package/dist/chunk-CLVB32RD.js +0 -1
- package/dist/chunk-CRVT7D2P.js +0 -1
- package/dist/chunk-D5RFJOZ2.js +0 -1
- package/dist/chunk-D7GPHKFH.js +0 -1
- package/dist/chunk-DHRX7JX4.js +0 -2
- package/dist/chunk-ESMPEKEV.js +0 -1
- package/dist/chunk-F672GV32.js +0 -1
- package/dist/chunk-FZMYDOWV.js +0 -1
- package/dist/chunk-GHBWHMRZ.js +0 -1
- package/dist/chunk-GLERH466.js +0 -1
- package/dist/chunk-GPW2V3RE.js +0 -1
- package/dist/chunk-HIDYF36O.js +0 -1
- package/dist/chunk-HITNVN6B.js +0 -3
- package/dist/chunk-HY4DJBA7.js +0 -5
- package/dist/chunk-KZIEYVXN.js +0 -1
- package/dist/chunk-L6NSJVJZ.js +0 -1
- package/dist/chunk-N4MQX6JU.js +0 -18
- package/dist/chunk-N7FHEL4D.js +0 -1
- package/dist/chunk-NTEURFZH.js +0 -1
- package/dist/chunk-OIVP6KFV.js +0 -1
- package/dist/chunk-OPHBU3LG.js +0 -1
- package/dist/chunk-OYQOZP2F.js +0 -5
- package/dist/chunk-PTZK576G.js +0 -1
- package/dist/chunk-QYADASLV.js +0 -1
- package/dist/chunk-ST7UXLWR.js +0 -1
- package/dist/chunk-SVY7VUYU.js +0 -1
- package/dist/chunk-TK3NWWD4.js +0 -1
- package/dist/chunk-TSOYJ743.js +0 -1
- package/dist/chunk-UNGSTR4X.js +0 -61
- package/dist/chunk-VIMF6LGM.js +0 -1
- package/dist/chunk-VJLMUKOI.js +0 -1
- package/dist/chunk-VN6RDSK2.js +0 -1
- package/dist/chunk-VV4N5P64.js +0 -1
- package/dist/chunk-W3I423PS.js +0 -1
- package/dist/chunk-WJR24TAG.js +0 -1
- package/dist/chunk-XTGKMHSW.js +0 -1
- package/dist/chunk-YBB7ZGTY.js +0 -1
- package/dist/chunk-Z4NPUARF.js +0 -1
- package/dist/chunk-ZGNQRPDT.js +0 -1
- package/dist/chunk-ZKPSFFKU.js +0 -1
- package/dist/chunk-ZLV5SQSX.js +0 -1
- package/dist/content-addressed-storage-4-ST1tYk.d.cts +0 -124
- package/dist/content-addressed-storage-DuYMjV7o.d.ts +0 -124
- package/dist/core/index.cjs +0 -1
- package/dist/core/index.d.cts +0 -3
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.js +0 -1
- package/dist/decay-BvOWTZ00.d.ts +0 -112
- package/dist/decay-CFlLvXUT.d.cts +0 -112
- package/dist/extra/browser.cjs +0 -1
- package/dist/extra/browser.d.cts +0 -4
- package/dist/extra/browser.d.ts +0 -4
- package/dist/extra/browser.js +0 -1
- package/dist/extra/index.cjs +0 -20
- package/dist/extra/index.d.cts +0 -17
- package/dist/extra/index.d.ts +0 -17
- package/dist/extra/index.js +0 -1
- package/dist/extra/node.cjs +0 -2
- package/dist/extra/node.js +0 -2
- package/dist/extra/operators.cjs +0 -1
- package/dist/extra/operators.d.cts +0 -958
- package/dist/extra/operators.d.ts +0 -958
- package/dist/extra/operators.js +0 -1
- package/dist/extra/reactive.cjs +0 -1
- package/dist/extra/reactive.d.cts +0 -353
- package/dist/extra/reactive.d.ts +0 -353
- package/dist/extra/reactive.js +0 -1
- package/dist/extra/render/index.cjs +0 -5
- package/dist/extra/render/index.js +0 -1
- package/dist/extra/sources.cjs +0 -3
- package/dist/extra/sources.js +0 -1
- package/dist/extra/storage-browser.cjs +0 -1
- package/dist/extra/storage-browser.d.cts +0 -37
- package/dist/extra/storage-browser.d.ts +0 -37
- package/dist/extra/storage-browser.js +0 -1
- package/dist/extra/storage-core.cjs +0 -1
- package/dist/extra/storage-core.d.cts +0 -28
- package/dist/extra/storage-core.d.ts +0 -28
- package/dist/extra/storage-core.js +0 -1
- package/dist/extra/storage-node.cjs +0 -1
- package/dist/extra/storage-node.d.cts +0 -2
- package/dist/extra/storage-node.d.ts +0 -2
- package/dist/extra/storage-node.js +0 -0
- package/dist/extra/storage-tiers-browser.cjs +0 -1
- package/dist/extra/storage-tiers-browser.d.cts +0 -120
- package/dist/extra/storage-tiers-browser.d.ts +0 -120
- package/dist/extra/storage-tiers-browser.js +0 -1
- package/dist/extra/storage-tiers-node.cjs +0 -1
- package/dist/extra/storage-tiers-node.d.cts +0 -210
- package/dist/extra/storage-tiers-node.d.ts +0 -210
- package/dist/extra/storage-tiers-node.js +0 -1
- package/dist/extra/storage-tiers.cjs +0 -1
- package/dist/extra/storage-tiers.d.cts +0 -412
- package/dist/extra/storage-tiers.d.ts +0 -412
- package/dist/extra/storage-tiers.js +0 -1
- package/dist/graph/index.cjs +0 -7
- package/dist/graph/index.d.cts +0 -7
- package/dist/graph/index.d.ts +0 -7
- package/dist/graph/index.js +0 -1
- package/dist/graph-CWvEUQAq.d.cts +0 -1861
- package/dist/graph-D9LFnda9.d.ts +0 -1861
- package/dist/index-5k1T6jl0.d.cts +0 -121
- package/dist/index-9770hRuQ.d.cts +0 -779
- package/dist/index-B1F8Enjf.d.ts +0 -704
- package/dist/index-BHskSB8v.d.ts +0 -3413
- package/dist/index-BIYAkbAi.d.cts +0 -26
- package/dist/index-BoJ5JHxI.d.ts +0 -557
- package/dist/index-BocU7pqs.d.ts +0 -779
- package/dist/index-BxNs2HB9.d.cts +0 -1858
- package/dist/index-C1T3d7V-.d.cts +0 -704
- package/dist/index-C5ri2Axc.d.cts +0 -301
- package/dist/index-C9l6OEBL.d.ts +0 -26
- package/dist/index-CC-AvFTy.d.cts +0 -557
- package/dist/index-CJF1URuX.d.ts +0 -121
- package/dist/index-CdTelp1M.d.ts +0 -202
- package/dist/index-Cj3WohTd.d.cts +0 -202
- package/dist/index-Co7uli2l.d.cts +0 -3413
- package/dist/index-D0aciIex.d.cts +0 -209
- package/dist/index-DHen9Klo.d.ts +0 -1858
- package/dist/index-Yq60JP3s.d.ts +0 -209
- package/dist/index-nozs3fFC.d.ts +0 -301
- package/dist/node-kK3CvTrR.d.cts +0 -1347
- package/dist/node-kK3CvTrR.d.ts +0 -1347
- package/dist/patterns/ai/browser.cjs +0 -8
- package/dist/patterns/ai/browser.js +0 -3
- package/dist/patterns/ai/index.cjs +0 -74
- package/dist/patterns/ai/index.d.cts +0 -20
- package/dist/patterns/ai/index.d.ts +0 -20
- package/dist/patterns/ai/index.js +0 -1
- package/dist/patterns/ai/node.cjs +0 -1
- package/dist/patterns/ai/node.js +0 -1
- package/dist/patterns/cqrs/index.cjs +0 -3
- package/dist/patterns/cqrs/index.d.cts +0 -8
- package/dist/patterns/cqrs/index.d.ts +0 -8
- package/dist/patterns/cqrs/index.js +0 -1
- package/dist/patterns/demo-shell/index.cjs +0 -5
- package/dist/patterns/demo-shell/index.d.cts +0 -7
- package/dist/patterns/demo-shell/index.d.ts +0 -7
- package/dist/patterns/demo-shell/index.js +0 -1
- package/dist/patterns/domain-templates/index.cjs +0 -3
- package/dist/patterns/domain-templates/index.d.cts +0 -6
- package/dist/patterns/domain-templates/index.d.ts +0 -6
- package/dist/patterns/domain-templates/index.js +0 -1
- package/dist/patterns/graphspec/index.cjs +0 -86
- package/dist/patterns/graphspec/index.d.cts +0 -8
- package/dist/patterns/graphspec/index.d.ts +0 -8
- package/dist/patterns/graphspec/index.js +0 -1
- package/dist/patterns/harness/index.cjs +0 -48
- package/dist/patterns/harness/index.d.cts +0 -13
- package/dist/patterns/harness/index.d.ts +0 -13
- package/dist/patterns/harness/index.js +0 -1
- package/dist/patterns/inspect/index.cjs +0 -3
- package/dist/patterns/inspect/index.d.cts +0 -9
- package/dist/patterns/inspect/index.d.ts +0 -9
- package/dist/patterns/inspect/index.js +0 -1
- package/dist/patterns/job-queue/index.cjs +0 -3
- package/dist/patterns/job-queue/index.d.cts +0 -9
- package/dist/patterns/job-queue/index.d.ts +0 -9
- package/dist/patterns/job-queue/index.js +0 -1
- package/dist/patterns/memory/index.cjs +0 -3
- package/dist/patterns/memory/index.d.cts +0 -8
- package/dist/patterns/memory/index.d.ts +0 -8
- package/dist/patterns/memory/index.js +0 -1
- package/dist/patterns/messaging/index.cjs +0 -3
- package/dist/patterns/messaging/index.d.cts +0 -7
- package/dist/patterns/messaging/index.d.ts +0 -7
- package/dist/patterns/messaging/index.js +0 -1
- package/dist/patterns/orchestration/index.cjs +0 -3
- package/dist/patterns/orchestration/index.d.cts +0 -8
- package/dist/patterns/orchestration/index.d.ts +0 -8
- package/dist/patterns/orchestration/index.js +0 -1
- package/dist/patterns/process/index.cjs +0 -3
- package/dist/patterns/process/index.d.cts +0 -10
- package/dist/patterns/process/index.d.ts +0 -10
- package/dist/patterns/process/index.js +0 -1
- package/dist/patterns/reactive-layout/index.cjs +0 -4
- package/dist/patterns/reactive-layout/index.d.cts +0 -7
- package/dist/patterns/reactive-layout/index.d.ts +0 -7
- package/dist/patterns/reactive-layout/index.js +0 -1
- package/dist/patterns/reduction/index.cjs +0 -3
- package/dist/patterns/reduction/index.d.cts +0 -6
- package/dist/patterns/reduction/index.d.ts +0 -6
- package/dist/patterns/reduction/index.js +0 -1
- package/dist/patterns/surface/index.cjs +0 -13
- package/dist/patterns/surface/index.d.cts +0 -9
- package/dist/patterns/surface/index.d.ts +0 -9
- package/dist/patterns/surface/index.js +0 -1
- package/dist/reactive-log-BKALbfal.d.ts +0 -223
- package/dist/reactive-log-DIGdYqQ6.d.cts +0 -223
- package/dist/reactive-map-CEFGp8TK.d.cts +0 -296
- package/dist/reactive-map-DS_SIAxv.d.ts +0 -296
- package/dist/resilience-6LYQJAC5.js +0 -1
- package/dist/sugar-DQjFmVqb.d.cts +0 -399
- package/dist/sugar-fhLIE7TT.d.ts +0 -399
- package/dist/topology-tree-Bcz27hpF.d.cts +0 -25
- package/dist/topology-tree-xvaD0fOX.d.ts +0 -25
|
@@ -0,0 +1,1593 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/presets/resilience/index.ts
|
|
21
|
+
var resilience_exports = {};
|
|
22
|
+
__export(resilience_exports, {
|
|
23
|
+
ResilientPipelineGraph: () => ResilientPipelineGraph,
|
|
24
|
+
resilientPipeline: () => resilientPipeline
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(resilience_exports);
|
|
27
|
+
|
|
28
|
+
// src/presets/resilience/resilient-pipeline.ts
|
|
29
|
+
var import_core9 = require("@graphrefly/pure-ts/core");
|
|
30
|
+
var import_extra2 = require("@graphrefly/pure-ts/extra");
|
|
31
|
+
var import_graph = require("@graphrefly/pure-ts/graph");
|
|
32
|
+
|
|
33
|
+
// src/base/meta/domain-meta.ts
|
|
34
|
+
function domainMeta(domain, kind, extra) {
|
|
35
|
+
return {
|
|
36
|
+
[domain]: true,
|
|
37
|
+
[`${domain}_type`]: kind,
|
|
38
|
+
...extra ?? {}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/base/resilience/backoff.ts
|
|
43
|
+
var NS_PER_MS = 1e6;
|
|
44
|
+
var NS_PER_SEC = 1e9;
|
|
45
|
+
function clampNonNegative(value) {
|
|
46
|
+
return value < 0 ? 0 : value;
|
|
47
|
+
}
|
|
48
|
+
function applyJitter(delay, jitter) {
|
|
49
|
+
if (jitter === "none") return delay;
|
|
50
|
+
if (jitter === "full") return Math.random() * delay;
|
|
51
|
+
return delay / 2 + Math.random() * (delay / 2);
|
|
52
|
+
}
|
|
53
|
+
function randomBetween(min, max) {
|
|
54
|
+
return min + Math.random() * (max - min);
|
|
55
|
+
}
|
|
56
|
+
function constant(delayNs) {
|
|
57
|
+
const safe = clampNonNegative(delayNs);
|
|
58
|
+
return () => safe;
|
|
59
|
+
}
|
|
60
|
+
function linear(baseNs, stepNs) {
|
|
61
|
+
const safeBase = clampNonNegative(baseNs);
|
|
62
|
+
const safeStep = stepNs === void 0 ? safeBase : clampNonNegative(stepNs);
|
|
63
|
+
return (attempt) => safeBase + safeStep * Math.max(0, attempt);
|
|
64
|
+
}
|
|
65
|
+
function exponential(options) {
|
|
66
|
+
const baseNs = clampNonNegative(options?.baseNs ?? 100 * NS_PER_MS);
|
|
67
|
+
const factor = options?.factor !== void 0 && options.factor < 1 ? 1 : options?.factor ?? 2;
|
|
68
|
+
const maxDelayNs = clampNonNegative(options?.maxDelayNs ?? 30 * NS_PER_SEC);
|
|
69
|
+
const jitter = options?.jitter ?? "none";
|
|
70
|
+
return (attempt) => {
|
|
71
|
+
let delay;
|
|
72
|
+
if (baseNs === 0) {
|
|
73
|
+
delay = 0;
|
|
74
|
+
} else if (factor === 1) {
|
|
75
|
+
delay = baseNs;
|
|
76
|
+
} else {
|
|
77
|
+
const capRatio = maxDelayNs / baseNs;
|
|
78
|
+
let growth = 1;
|
|
79
|
+
for (let i = 0; i < Math.max(0, attempt); i++) {
|
|
80
|
+
if (growth >= capRatio) {
|
|
81
|
+
growth = capRatio;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
growth *= factor;
|
|
85
|
+
}
|
|
86
|
+
delay = baseNs * growth;
|
|
87
|
+
if (delay > maxDelayNs) delay = maxDelayNs;
|
|
88
|
+
}
|
|
89
|
+
return applyJitter(delay, jitter);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function fibonacci(baseNs = 100 * NS_PER_MS, maxDelayNs = 30 * NS_PER_SEC) {
|
|
93
|
+
const safeBase = clampNonNegative(baseNs);
|
|
94
|
+
const safeMax = clampNonNegative(maxDelayNs);
|
|
95
|
+
function fibUnit(attempt) {
|
|
96
|
+
if (attempt <= 0) return 1;
|
|
97
|
+
let prev = 1;
|
|
98
|
+
let cur = 2;
|
|
99
|
+
for (let i = 1; i < attempt; i++) {
|
|
100
|
+
const next = prev + cur;
|
|
101
|
+
prev = cur;
|
|
102
|
+
cur = next;
|
|
103
|
+
}
|
|
104
|
+
return cur;
|
|
105
|
+
}
|
|
106
|
+
return (attempt) => {
|
|
107
|
+
const raw = fibUnit(attempt) * safeBase;
|
|
108
|
+
return raw <= safeMax ? raw : safeMax;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function decorrelatedJitter(baseNs = 100 * NS_PER_MS, maxNs = 30 * NS_PER_SEC) {
|
|
112
|
+
return (_attempt, _error, prevDelayNs) => {
|
|
113
|
+
const last = prevDelayNs ?? baseNs;
|
|
114
|
+
const ceiling = Math.min(maxNs, last * 3);
|
|
115
|
+
return randomBetween(baseNs, ceiling);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function resolveBackoffPreset(name) {
|
|
119
|
+
if (name === "constant") return constant(1 * NS_PER_SEC);
|
|
120
|
+
if (name === "linear") return linear(1 * NS_PER_SEC);
|
|
121
|
+
if (name === "exponential") return exponential();
|
|
122
|
+
if (name === "fibonacci") return fibonacci();
|
|
123
|
+
if (name === "decorrelatedJitter") return decorrelatedJitter();
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Unknown backoff preset: "${String(name)}". Use one of: constant, linear, exponential, fibonacci, decorrelatedJitter`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/base/resilience/retry.ts
|
|
130
|
+
var import_core2 = require("@graphrefly/pure-ts/core");
|
|
131
|
+
|
|
132
|
+
// src/base/resilience/_internal.ts
|
|
133
|
+
var import_core = require("@graphrefly/pure-ts/core");
|
|
134
|
+
function operatorOpts(opts) {
|
|
135
|
+
return { describeKind: "derived", ...opts };
|
|
136
|
+
}
|
|
137
|
+
function clampNonNegative2(value) {
|
|
138
|
+
return value < 0 ? 0 : value;
|
|
139
|
+
}
|
|
140
|
+
function msgVal(m) {
|
|
141
|
+
return m[1];
|
|
142
|
+
}
|
|
143
|
+
function coerceDelayNs(raw) {
|
|
144
|
+
if (typeof raw !== "number" || !Number.isFinite(raw)) {
|
|
145
|
+
throw new TypeError("backoff strategy must return a finite number");
|
|
146
|
+
}
|
|
147
|
+
return raw < 0 ? 0 : raw;
|
|
148
|
+
}
|
|
149
|
+
function isNode(x) {
|
|
150
|
+
return x != null && typeof x === "object" && "cache" in x && typeof x.subscribe === "function";
|
|
151
|
+
}
|
|
152
|
+
function resolveReactiveOption(arg, onChange) {
|
|
153
|
+
if (!isNode(arg)) {
|
|
154
|
+
return { current: () => arg, unsub: () => void 0 };
|
|
155
|
+
}
|
|
156
|
+
const node9 = arg;
|
|
157
|
+
let latest = node9.cache;
|
|
158
|
+
const unsub = node9.subscribe((msgs) => {
|
|
159
|
+
for (const m of msgs) {
|
|
160
|
+
if (m[0] === import_core.DATA) {
|
|
161
|
+
latest = m[1];
|
|
162
|
+
if (onChange) onChange(latest);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
current: () => latest,
|
|
168
|
+
unsub
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function isThenable(x) {
|
|
172
|
+
return x != null && typeof x.then === "function";
|
|
173
|
+
}
|
|
174
|
+
function isAsyncIterable(x) {
|
|
175
|
+
return x != null && typeof x === "object" && typeof x[Symbol.asyncIterator] === "function";
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/base/resilience/retry.ts
|
|
179
|
+
function resolveRetryConfig(opts) {
|
|
180
|
+
const count = opts?.count;
|
|
181
|
+
const backoffOpt = opts?.backoff;
|
|
182
|
+
if (backoffOpt !== void 0 && count === void 0) {
|
|
183
|
+
throw new RangeError(
|
|
184
|
+
"retry({ backoff }) requires explicit count to prevent unbounded retries; pass { count: <n>, backoff: ... }"
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
const maxRetries = count !== void 0 ? count : 0;
|
|
188
|
+
if (maxRetries < 0) throw new RangeError("retry count must be >= 0");
|
|
189
|
+
const strategy = backoffOpt === void 0 ? null : typeof backoffOpt === "string" ? resolveBackoffPreset(backoffOpt) : backoffOpt;
|
|
190
|
+
return { maxRetries, strategy };
|
|
191
|
+
}
|
|
192
|
+
function retryFactoryArgs(opts) {
|
|
193
|
+
const args = {};
|
|
194
|
+
if (opts?.count !== void 0) args.count = opts.count;
|
|
195
|
+
if (typeof opts?.backoff === "string") args.backoff = opts.backoff;
|
|
196
|
+
return Object.keys(args).length > 0 ? args : void 0;
|
|
197
|
+
}
|
|
198
|
+
function _runRetryStateMachine(getCfg, acquireSource, a, emitState) {
|
|
199
|
+
let attempt = 0;
|
|
200
|
+
let stopped = false;
|
|
201
|
+
let prevDelay = null;
|
|
202
|
+
let unsub;
|
|
203
|
+
const timer = new import_core2.ResettableTimer();
|
|
204
|
+
const publish = (status) => {
|
|
205
|
+
emitState?.({ status, attempt, lastDelay_ns: prevDelay });
|
|
206
|
+
};
|
|
207
|
+
publish("pending");
|
|
208
|
+
function disconnectUpstream() {
|
|
209
|
+
unsub?.();
|
|
210
|
+
unsub = void 0;
|
|
211
|
+
}
|
|
212
|
+
function scheduleRetryOrFinish(err) {
|
|
213
|
+
if (stopped) return;
|
|
214
|
+
const cfg = getCfg();
|
|
215
|
+
if (attempt >= cfg.maxRetries) {
|
|
216
|
+
disconnectUpstream();
|
|
217
|
+
publish("errored");
|
|
218
|
+
a.down([[import_core2.ERROR, err]]);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const raw = cfg.strategy === null ? 0 : cfg.strategy(attempt, err, prevDelay);
|
|
222
|
+
if (raw === null || raw === void 0) {
|
|
223
|
+
disconnectUpstream();
|
|
224
|
+
publish("errored");
|
|
225
|
+
a.down([[import_core2.ERROR, err]]);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
let delayNs;
|
|
229
|
+
try {
|
|
230
|
+
delayNs = coerceDelayNs(raw);
|
|
231
|
+
} catch {
|
|
232
|
+
disconnectUpstream();
|
|
233
|
+
publish("errored");
|
|
234
|
+
a.down([[import_core2.ERROR, err]]);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
prevDelay = delayNs;
|
|
238
|
+
attempt += 1;
|
|
239
|
+
disconnectUpstream();
|
|
240
|
+
publish("paused");
|
|
241
|
+
const delayMs = delayNs > 0 ? delayNs / NS_PER_MS : 1;
|
|
242
|
+
timer.start(delayMs, () => {
|
|
243
|
+
if (stopped) return;
|
|
244
|
+
connect();
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
function connect() {
|
|
248
|
+
timer.cancel();
|
|
249
|
+
disconnectUpstream();
|
|
250
|
+
let src;
|
|
251
|
+
try {
|
|
252
|
+
src = acquireSource();
|
|
253
|
+
} catch (err) {
|
|
254
|
+
scheduleRetryOrFinish(err);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
publish("running");
|
|
258
|
+
unsub = src.subscribe((msgs) => {
|
|
259
|
+
if (stopped) return;
|
|
260
|
+
for (const m of msgs) {
|
|
261
|
+
const t = m[0];
|
|
262
|
+
if (t === import_core2.DIRTY) a.down([[import_core2.DIRTY]]);
|
|
263
|
+
else if (t === import_core2.DATA) {
|
|
264
|
+
attempt = 0;
|
|
265
|
+
prevDelay = null;
|
|
266
|
+
a.emit(m[1]);
|
|
267
|
+
publish("running");
|
|
268
|
+
} else if (t === import_core2.RESOLVED) a.down([[import_core2.RESOLVED]]);
|
|
269
|
+
else if (t === import_core2.COMPLETE) {
|
|
270
|
+
stopped = true;
|
|
271
|
+
disconnectUpstream();
|
|
272
|
+
publish("completed");
|
|
273
|
+
a.down([[import_core2.COMPLETE]]);
|
|
274
|
+
} else if (t === import_core2.ERROR) {
|
|
275
|
+
scheduleRetryOrFinish(msgVal(m));
|
|
276
|
+
return;
|
|
277
|
+
} else a.down([m]);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
connect();
|
|
282
|
+
return () => {
|
|
283
|
+
const wasStopped = stopped;
|
|
284
|
+
stopped = true;
|
|
285
|
+
timer.cancel();
|
|
286
|
+
disconnectUpstream();
|
|
287
|
+
if (!wasStopped) publish("cancelled");
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function retry(input, opts) {
|
|
291
|
+
const retryState = (0, import_core2.node)([], {
|
|
292
|
+
name: "retryState",
|
|
293
|
+
describeKind: "state",
|
|
294
|
+
initial: { status: "pending", attempt: 0, lastDelay_ns: null },
|
|
295
|
+
equals: (a, b) => a === b || a != null && b != null && typeof a === "object" && typeof b === "object" && JSON.stringify(a) === JSON.stringify(b)
|
|
296
|
+
});
|
|
297
|
+
const emit = (s) => {
|
|
298
|
+
retryState.down([[import_core2.DIRTY], [import_core2.DATA, s]]);
|
|
299
|
+
};
|
|
300
|
+
if (typeof input === "function") {
|
|
301
|
+
return {
|
|
302
|
+
node: _retryFactory(input, opts, emit),
|
|
303
|
+
retryState
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
node: _retrySource(input, opts, emit),
|
|
308
|
+
retryState
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function makeMergedOptsMirror(arg) {
|
|
312
|
+
if (arg === void 0) {
|
|
313
|
+
return { current: () => void 0, unsub: () => void 0 };
|
|
314
|
+
}
|
|
315
|
+
if (!isNode(arg)) {
|
|
316
|
+
return { current: () => arg, unsub: () => void 0 };
|
|
317
|
+
}
|
|
318
|
+
const optsNode = arg;
|
|
319
|
+
let merged = optsNode.cache ?? void 0;
|
|
320
|
+
const unsub = optsNode.subscribe((msgs) => {
|
|
321
|
+
for (const m of msgs) {
|
|
322
|
+
if (m[0] !== import_core2.DATA) continue;
|
|
323
|
+
const next = m[1];
|
|
324
|
+
if (next == null || typeof next !== "object") continue;
|
|
325
|
+
if (Object.keys(next).length === 0) continue;
|
|
326
|
+
merged = { ...merged ?? {}, ...next };
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
return { current: () => merged, unsub };
|
|
330
|
+
}
|
|
331
|
+
var _retrySourceNonResubscribableWarned = /* @__PURE__ */ new WeakSet();
|
|
332
|
+
function _retrySource(source, opts, emitState) {
|
|
333
|
+
const sourceWithFlag = source;
|
|
334
|
+
if (sourceWithFlag._resubscribable === false && !_retrySourceNonResubscribableWarned.has(source)) {
|
|
335
|
+
_retrySourceNonResubscribableWarned.add(source);
|
|
336
|
+
console.warn(
|
|
337
|
+
"retry(source, opts): source-mode requires `resubscribable: true` on the upstream node. Retries will be silent no-ops after the first ERROR. Either pass `resubscribable: true` to the source factory, OR use factory-mode retry `retry(() => buildSource(), opts)` so each attempt builds a fresh node."
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
const staticOpts = isNode(opts) ? void 0 : opts;
|
|
341
|
+
if (!isNode(opts)) resolveRetryConfig(staticOpts);
|
|
342
|
+
return (0, import_core2.node)(
|
|
343
|
+
(_data, a) => {
|
|
344
|
+
const merged = makeMergedOptsMirror(opts);
|
|
345
|
+
const getCfg = () => resolveRetryConfig(merged.current());
|
|
346
|
+
const inner = _runRetryStateMachine(getCfg, () => source, a, emitState);
|
|
347
|
+
return () => {
|
|
348
|
+
inner();
|
|
349
|
+
merged.unsub();
|
|
350
|
+
};
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
...operatorOpts(),
|
|
354
|
+
initial: source.cache,
|
|
355
|
+
meta: {
|
|
356
|
+
...staticOpts?.meta ?? {},
|
|
357
|
+
...(0, import_core2.factoryTag)(
|
|
358
|
+
"retry",
|
|
359
|
+
isNode(opts) ? { reactiveOpts: true } : retryFactoryArgs(staticOpts)
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
function _retryFactory(factory, opts, emitState) {
|
|
366
|
+
const staticOpts = isNode(opts) ? void 0 : opts;
|
|
367
|
+
if (!isNode(opts)) resolveRetryConfig(staticOpts);
|
|
368
|
+
return (0, import_core2.node)(
|
|
369
|
+
(_data, a) => {
|
|
370
|
+
const merged = makeMergedOptsMirror(opts);
|
|
371
|
+
const getCfg = () => resolveRetryConfig(merged.current());
|
|
372
|
+
const inner = _runRetryStateMachine(getCfg, factory, a, emitState);
|
|
373
|
+
return () => {
|
|
374
|
+
inner();
|
|
375
|
+
merged.unsub();
|
|
376
|
+
};
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
...operatorOpts(),
|
|
380
|
+
initial: staticOpts?.initial,
|
|
381
|
+
meta: {
|
|
382
|
+
...staticOpts?.meta ?? {},
|
|
383
|
+
...(0, import_core2.factoryTag)(
|
|
384
|
+
"retry",
|
|
385
|
+
isNode(opts) ? { reactiveOpts: true } : retryFactoryArgs(staticOpts)
|
|
386
|
+
)
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// src/base/resilience/status.ts
|
|
393
|
+
var import_core3 = require("@graphrefly/pure-ts/core");
|
|
394
|
+
function withStatus(src, options) {
|
|
395
|
+
const initialStatus = options?.initialStatus ?? "pending";
|
|
396
|
+
const callerMeta = options?.meta;
|
|
397
|
+
const out = (0, import_core3.node)(
|
|
398
|
+
[],
|
|
399
|
+
(_deps, a) => {
|
|
400
|
+
let currentStatus = initialStatus;
|
|
401
|
+
out.meta.status.down([[import_core3.DATA, initialStatus]]);
|
|
402
|
+
out.meta.error.down([[import_core3.DATA, null]]);
|
|
403
|
+
const unsub = src.subscribe((msgs) => {
|
|
404
|
+
for (const m of msgs) {
|
|
405
|
+
const t = m[0];
|
|
406
|
+
if (t === import_core3.DIRTY) a.down([[import_core3.DIRTY]]);
|
|
407
|
+
else if (t === import_core3.DATA) {
|
|
408
|
+
if (currentStatus === "errored") {
|
|
409
|
+
(0, import_core3.batch)(() => {
|
|
410
|
+
out.meta.error.down([[import_core3.DATA, null]]);
|
|
411
|
+
out.meta.status.down([[import_core3.DATA, "running"]]);
|
|
412
|
+
a.emit(m[1]);
|
|
413
|
+
});
|
|
414
|
+
currentStatus = "running";
|
|
415
|
+
} else if (currentStatus !== "running") {
|
|
416
|
+
(0, import_core3.batch)(() => {
|
|
417
|
+
out.meta.status.down([[import_core3.DATA, "running"]]);
|
|
418
|
+
a.emit(m[1]);
|
|
419
|
+
});
|
|
420
|
+
currentStatus = "running";
|
|
421
|
+
} else {
|
|
422
|
+
a.emit(m[1]);
|
|
423
|
+
}
|
|
424
|
+
} else if (t === import_core3.RESOLVED) a.down([[import_core3.RESOLVED]]);
|
|
425
|
+
else if (t === import_core3.COMPLETE) {
|
|
426
|
+
out.meta.status.down([[import_core3.DATA, "completed"]]);
|
|
427
|
+
currentStatus = "completed";
|
|
428
|
+
a.down([[import_core3.COMPLETE]]);
|
|
429
|
+
} else if (t === import_core3.ERROR) {
|
|
430
|
+
const err = msgVal(m);
|
|
431
|
+
(0, import_core3.batch)(() => {
|
|
432
|
+
out.meta.error.down([[import_core3.DATA, err]]);
|
|
433
|
+
out.meta.status.down([[import_core3.DATA, "errored"]]);
|
|
434
|
+
});
|
|
435
|
+
currentStatus = "errored";
|
|
436
|
+
a.down([m]);
|
|
437
|
+
} else a.down([m]);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
return unsub;
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
...operatorOpts(),
|
|
444
|
+
meta: {
|
|
445
|
+
...callerMeta ?? {},
|
|
446
|
+
status: initialStatus,
|
|
447
|
+
error: null,
|
|
448
|
+
...(0, import_core3.factoryTag)("withStatus", { initialStatus })
|
|
449
|
+
},
|
|
450
|
+
completeWhenDepsComplete: false,
|
|
451
|
+
resubscribable: true,
|
|
452
|
+
initial: src.cache
|
|
453
|
+
}
|
|
454
|
+
);
|
|
455
|
+
return {
|
|
456
|
+
node: out,
|
|
457
|
+
status: out.meta.status,
|
|
458
|
+
error: out.meta.error
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// src/base/resilience/timeout.ts
|
|
463
|
+
var import_core4 = require("@graphrefly/pure-ts/core");
|
|
464
|
+
var TimeoutError = class extends Error {
|
|
465
|
+
name = "TimeoutError";
|
|
466
|
+
constructor(ns) {
|
|
467
|
+
super(`Timed out after ${ns / NS_PER_MS}ms`);
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
function withTimeout(source, opts, extraOpts) {
|
|
471
|
+
const isReactive = isNode(opts);
|
|
472
|
+
let latestOpts = null;
|
|
473
|
+
if (!isReactive) {
|
|
474
|
+
const staticOpts = opts;
|
|
475
|
+
if (staticOpts.ns === void 0 || typeof staticOpts.ns !== "number" || !Number.isFinite(staticOpts.ns) || staticOpts.ns <= 0) {
|
|
476
|
+
throw new RangeError("withTimeout: opts.ns must be a positive finite number");
|
|
477
|
+
}
|
|
478
|
+
latestOpts = {
|
|
479
|
+
ns: staticOpts.ns,
|
|
480
|
+
...staticOpts.meta != null ? { meta: staticOpts.meta } : {}
|
|
481
|
+
};
|
|
482
|
+
} else {
|
|
483
|
+
const cached = opts.cache;
|
|
484
|
+
if (cached !== void 0) {
|
|
485
|
+
if (cached.ns === void 0 || typeof cached.ns !== "number" || !Number.isFinite(cached.ns) || cached.ns <= 0) {
|
|
486
|
+
throw new RangeError(
|
|
487
|
+
"withTimeout: opts.ns must be a positive finite number on first settle"
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
latestOpts = {
|
|
491
|
+
ns: cached.ns,
|
|
492
|
+
...cached.meta != null ? { meta: cached.meta } : {}
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const callerMeta = extraOpts?.meta;
|
|
497
|
+
const factoryArgs = isReactive ? { ns: "Node<Partial<TimeoutOptions>>" } : { ns: latestOpts.ns };
|
|
498
|
+
const timeoutState = (0, import_core4.node)([], {
|
|
499
|
+
name: "timeoutState",
|
|
500
|
+
describeKind: "state",
|
|
501
|
+
initial: { status: "pending" },
|
|
502
|
+
equals: (a, b) => a === b || a != null && b != null && typeof a === "object" && typeof b === "object" && a.status === b.status && JSON.stringify(a) === JSON.stringify(b)
|
|
503
|
+
});
|
|
504
|
+
const out = (0, import_core4.node)(
|
|
505
|
+
(_data, a) => {
|
|
506
|
+
let stopped = false;
|
|
507
|
+
let lastDeadlineNs = 0;
|
|
508
|
+
const timer = new import_core4.ResettableTimer();
|
|
509
|
+
let optsUnsub = null;
|
|
510
|
+
let srcUnsub = null;
|
|
511
|
+
function emitState(next) {
|
|
512
|
+
timeoutState.down([[import_core4.DIRTY], [import_core4.DATA, next]]);
|
|
513
|
+
}
|
|
514
|
+
function startTimer() {
|
|
515
|
+
if (stopped) return;
|
|
516
|
+
if (latestOpts == null || typeof latestOpts.ns !== "number" || !Number.isFinite(latestOpts.ns) || latestOpts.ns <= 0) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
const ns = latestOpts.ns;
|
|
520
|
+
lastDeadlineNs = ns;
|
|
521
|
+
const startedAt = (0, import_core4.monotonicNs)();
|
|
522
|
+
const delayMs = ns / NS_PER_MS;
|
|
523
|
+
emitState({
|
|
524
|
+
status: "running",
|
|
525
|
+
startedAt_ns: startedAt,
|
|
526
|
+
deadline_ns: ns
|
|
527
|
+
});
|
|
528
|
+
timer.start(delayMs, () => {
|
|
529
|
+
if (stopped) return;
|
|
530
|
+
stopped = true;
|
|
531
|
+
srcUnsub?.();
|
|
532
|
+
emitState({
|
|
533
|
+
status: "errored",
|
|
534
|
+
firedAt_ns: (0, import_core4.monotonicNs)(),
|
|
535
|
+
deadline_ns: ns
|
|
536
|
+
});
|
|
537
|
+
a.down([[import_core4.ERROR, new TimeoutError(ns)]]);
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
function attachSource() {
|
|
541
|
+
if (srcUnsub != null || stopped) return;
|
|
542
|
+
srcUnsub = source.subscribe((msgs) => {
|
|
543
|
+
for (const m of msgs) {
|
|
544
|
+
if (stopped) return;
|
|
545
|
+
const t = m[0];
|
|
546
|
+
if (t === import_core4.DIRTY) a.down([[import_core4.DIRTY]]);
|
|
547
|
+
else if (t === import_core4.DATA) {
|
|
548
|
+
startTimer();
|
|
549
|
+
a.emit(m[1]);
|
|
550
|
+
} else if (t === import_core4.RESOLVED) a.down([[import_core4.RESOLVED]]);
|
|
551
|
+
else if (t === import_core4.COMPLETE) {
|
|
552
|
+
timer.cancel();
|
|
553
|
+
stopped = true;
|
|
554
|
+
emitState({
|
|
555
|
+
status: "completed",
|
|
556
|
+
settledAt_ns: (0, import_core4.monotonicNs)()
|
|
557
|
+
});
|
|
558
|
+
a.down([[import_core4.COMPLETE]]);
|
|
559
|
+
return;
|
|
560
|
+
} else if (t === import_core4.ERROR) {
|
|
561
|
+
timer.cancel();
|
|
562
|
+
stopped = true;
|
|
563
|
+
emitState({
|
|
564
|
+
status: "errored",
|
|
565
|
+
firedAt_ns: (0, import_core4.monotonicNs)(),
|
|
566
|
+
deadline_ns: lastDeadlineNs
|
|
567
|
+
});
|
|
568
|
+
a.down([m]);
|
|
569
|
+
return;
|
|
570
|
+
} else if (t === import_core4.TEARDOWN) {
|
|
571
|
+
timer.cancel();
|
|
572
|
+
stopped = true;
|
|
573
|
+
a.down([m]);
|
|
574
|
+
return;
|
|
575
|
+
} else a.down([m]);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
if (latestOpts != null && latestOpts.ns > 0) {
|
|
579
|
+
startTimer();
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (isReactive) {
|
|
583
|
+
const optsNode = opts;
|
|
584
|
+
optsUnsub = optsNode.subscribe((msgs) => {
|
|
585
|
+
for (const m of msgs) {
|
|
586
|
+
if (m[0] !== import_core4.DATA) continue;
|
|
587
|
+
const next = m[1];
|
|
588
|
+
if (next == null || typeof next !== "object") continue;
|
|
589
|
+
const keys = Object.keys(next);
|
|
590
|
+
if (keys.length === 0) continue;
|
|
591
|
+
if ("ns" in next) {
|
|
592
|
+
if (typeof next.ns !== "number" || !Number.isFinite(next.ns) || next.ns <= 0) {
|
|
593
|
+
if (latestOpts == null) {
|
|
594
|
+
stopped = true;
|
|
595
|
+
a.down([
|
|
596
|
+
[
|
|
597
|
+
import_core4.ERROR,
|
|
598
|
+
new RangeError(
|
|
599
|
+
"withTimeout: opts.ns must be a positive finite number on first settle"
|
|
600
|
+
)
|
|
601
|
+
]
|
|
602
|
+
]);
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const wasNull = latestOpts == null;
|
|
609
|
+
latestOpts = {
|
|
610
|
+
...latestOpts ?? { ns: 0 },
|
|
611
|
+
...next
|
|
612
|
+
};
|
|
613
|
+
if (wasNull && latestOpts.ns > 0) {
|
|
614
|
+
attachSource();
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
if (latestOpts != null) {
|
|
620
|
+
attachSource();
|
|
621
|
+
}
|
|
622
|
+
return () => {
|
|
623
|
+
stopped = true;
|
|
624
|
+
timer.cancel();
|
|
625
|
+
if (srcUnsub) srcUnsub();
|
|
626
|
+
if (optsUnsub) optsUnsub();
|
|
627
|
+
};
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
...operatorOpts(),
|
|
631
|
+
initial: source.cache,
|
|
632
|
+
meta: { ...callerMeta ?? {}, ...(0, import_core4.factoryTag)("withTimeout", factoryArgs) }
|
|
633
|
+
}
|
|
634
|
+
);
|
|
635
|
+
return { node: out, timeoutState };
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// src/utils/resilience/breaker.ts
|
|
639
|
+
var import_core5 = require("@graphrefly/pure-ts/core");
|
|
640
|
+
var CircuitOpenError = class extends Error {
|
|
641
|
+
name = "CircuitOpenError";
|
|
642
|
+
constructor() {
|
|
643
|
+
super("Circuit breaker is open");
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
function circuitBreaker(options) {
|
|
647
|
+
let threshold = 5;
|
|
648
|
+
let baseCooldownNs = 30 * NS_PER_SEC;
|
|
649
|
+
let cooldownStrategy = null;
|
|
650
|
+
let halfOpenMax = 1;
|
|
651
|
+
let now = import_core5.monotonicNs;
|
|
652
|
+
function applyOptions(o) {
|
|
653
|
+
threshold = Math.max(1, o?.failureThreshold ?? 5);
|
|
654
|
+
baseCooldownNs = clampNonNegative2(o?.cooldownNs ?? 30 * NS_PER_SEC);
|
|
655
|
+
cooldownStrategy = o?.cooldown ?? null;
|
|
656
|
+
halfOpenMax = Math.max(1, o?.halfOpenMax ?? 1);
|
|
657
|
+
now = o?.now ?? import_core5.monotonicNs;
|
|
658
|
+
}
|
|
659
|
+
let _state = "closed";
|
|
660
|
+
let _failureCount = 0;
|
|
661
|
+
let _openCycle = 0;
|
|
662
|
+
let _lastOpenedAt = 0;
|
|
663
|
+
let _lastCooldownNs = baseCooldownNs;
|
|
664
|
+
let _halfOpenAttempts = 0;
|
|
665
|
+
let initialOpts;
|
|
666
|
+
let optsUnsub;
|
|
667
|
+
if (isNode(options)) {
|
|
668
|
+
const optsNode = options;
|
|
669
|
+
initialOpts = optsNode.cache;
|
|
670
|
+
applyOptions(initialOpts);
|
|
671
|
+
const lockedNow = initialOpts?.now;
|
|
672
|
+
const hadInitialCache = initialOpts !== void 0;
|
|
673
|
+
let firstEmit = hadInitialCache;
|
|
674
|
+
optsUnsub = optsNode.subscribe((msgs) => {
|
|
675
|
+
for (const m of msgs) {
|
|
676
|
+
if (m[0] !== import_core5.DATA) continue;
|
|
677
|
+
if (firstEmit) {
|
|
678
|
+
firstEmit = false;
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
const next = m[1];
|
|
682
|
+
if (next == null || typeof next !== "object") continue;
|
|
683
|
+
if (Object.keys(next).length === 0) continue;
|
|
684
|
+
if ("now" in next && next.now !== lockedNow) {
|
|
685
|
+
console.error(
|
|
686
|
+
"circuitBreaker: ignoring mid-flight `now` change \u2014 clock override is mode-locked at construction. Prior `now` preserved."
|
|
687
|
+
);
|
|
688
|
+
continue;
|
|
689
|
+
}
|
|
690
|
+
const merged = {
|
|
691
|
+
...initialOpts ?? {},
|
|
692
|
+
...next,
|
|
693
|
+
...lockedNow !== void 0 ? { now: lockedNow } : {}
|
|
694
|
+
};
|
|
695
|
+
applyOptions(merged);
|
|
696
|
+
initialOpts = merged;
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
} else {
|
|
700
|
+
applyOptions(options);
|
|
701
|
+
}
|
|
702
|
+
_lastCooldownNs = baseCooldownNs;
|
|
703
|
+
function getCooldownNs() {
|
|
704
|
+
if (!cooldownStrategy) return baseCooldownNs;
|
|
705
|
+
const delayNs = cooldownStrategy(_openCycle);
|
|
706
|
+
return delayNs !== null ? delayNs : baseCooldownNs;
|
|
707
|
+
}
|
|
708
|
+
function transitionToOpen() {
|
|
709
|
+
_state = "open";
|
|
710
|
+
_lastCooldownNs = getCooldownNs();
|
|
711
|
+
_lastOpenedAt = now();
|
|
712
|
+
_halfOpenAttempts = 0;
|
|
713
|
+
}
|
|
714
|
+
const breaker = {
|
|
715
|
+
canExecute() {
|
|
716
|
+
if (_state === "closed") return true;
|
|
717
|
+
if (_state === "open") {
|
|
718
|
+
const elapsed = now() - _lastOpenedAt;
|
|
719
|
+
if (elapsed >= _lastCooldownNs) {
|
|
720
|
+
_state = "half-open";
|
|
721
|
+
_halfOpenAttempts = 1;
|
|
722
|
+
return true;
|
|
723
|
+
}
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
726
|
+
if (_halfOpenAttempts < halfOpenMax) {
|
|
727
|
+
_halfOpenAttempts++;
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
return false;
|
|
731
|
+
},
|
|
732
|
+
recordSuccess() {
|
|
733
|
+
if (_state === "half-open") {
|
|
734
|
+
_state = "closed";
|
|
735
|
+
_failureCount = 0;
|
|
736
|
+
_openCycle = 0;
|
|
737
|
+
} else if (_state === "closed") {
|
|
738
|
+
_failureCount = 0;
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
recordFailure(_error) {
|
|
742
|
+
if (_state === "half-open") {
|
|
743
|
+
_openCycle++;
|
|
744
|
+
transitionToOpen();
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
if (_state === "closed") {
|
|
748
|
+
_failureCount++;
|
|
749
|
+
if (_failureCount >= threshold) {
|
|
750
|
+
transitionToOpen();
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
},
|
|
754
|
+
get state() {
|
|
755
|
+
return _state;
|
|
756
|
+
},
|
|
757
|
+
get failureCount() {
|
|
758
|
+
return _failureCount;
|
|
759
|
+
},
|
|
760
|
+
reset() {
|
|
761
|
+
_state = "closed";
|
|
762
|
+
_failureCount = 0;
|
|
763
|
+
_openCycle = 0;
|
|
764
|
+
_halfOpenAttempts = 0;
|
|
765
|
+
},
|
|
766
|
+
dispose() {
|
|
767
|
+
optsUnsub?.();
|
|
768
|
+
}
|
|
769
|
+
// Internal accessors used by withBreaker for the BreakerState
|
|
770
|
+
// companion (DS-13.5.B). Not part of the public CircuitBreaker
|
|
771
|
+
// interface but exposed for the bundle wiring.
|
|
772
|
+
};
|
|
773
|
+
breaker._stateSnapshot = () => ({
|
|
774
|
+
status: _state,
|
|
775
|
+
failureCount: _failureCount,
|
|
776
|
+
openCycle: _openCycle,
|
|
777
|
+
lastOpenedAtNs: _lastOpenedAt,
|
|
778
|
+
halfOpenAttempts: _halfOpenAttempts,
|
|
779
|
+
lastCooldownNs: _lastCooldownNs
|
|
780
|
+
});
|
|
781
|
+
return breaker;
|
|
782
|
+
}
|
|
783
|
+
function withBreaker(breaker, options) {
|
|
784
|
+
const onOpen = options?.onOpen ?? "skip";
|
|
785
|
+
const callerMeta = options?.meta;
|
|
786
|
+
return (source) => {
|
|
787
|
+
const snapshot = breaker._stateSnapshot;
|
|
788
|
+
const initialSnapshot = snapshot ? snapshot() : {
|
|
789
|
+
status: breaker.state,
|
|
790
|
+
failureCount: breaker.failureCount,
|
|
791
|
+
openCycle: 0,
|
|
792
|
+
lastOpenedAtNs: 0,
|
|
793
|
+
halfOpenAttempts: 0,
|
|
794
|
+
lastCooldownNs: 0
|
|
795
|
+
};
|
|
796
|
+
const wrapped = (0, import_core5.node)(
|
|
797
|
+
[],
|
|
798
|
+
(_deps, a) => {
|
|
799
|
+
function syncState() {
|
|
800
|
+
const s = snapshot ? snapshot() : {
|
|
801
|
+
status: breaker.state,
|
|
802
|
+
failureCount: breaker.failureCount,
|
|
803
|
+
openCycle: 0,
|
|
804
|
+
lastOpenedAtNs: 0,
|
|
805
|
+
halfOpenAttempts: 0,
|
|
806
|
+
lastCooldownNs: 0
|
|
807
|
+
};
|
|
808
|
+
wrapped.meta.breakerState.down([[import_core5.DIRTY], [import_core5.DATA, s]]);
|
|
809
|
+
}
|
|
810
|
+
const unsub = source.subscribe((msgs) => {
|
|
811
|
+
for (const m of msgs) {
|
|
812
|
+
const t = m[0];
|
|
813
|
+
if (t === import_core5.DIRTY) a.down([[import_core5.DIRTY]]);
|
|
814
|
+
else if (t === import_core5.DATA) {
|
|
815
|
+
if (breaker.canExecute()) {
|
|
816
|
+
syncState();
|
|
817
|
+
a.emit(m[1]);
|
|
818
|
+
} else {
|
|
819
|
+
syncState();
|
|
820
|
+
if (onOpen === "error") a.down([[import_core5.ERROR, new CircuitOpenError()]]);
|
|
821
|
+
else a.down([[import_core5.RESOLVED]]);
|
|
822
|
+
}
|
|
823
|
+
} else if (t === import_core5.RESOLVED) a.down([[import_core5.RESOLVED]]);
|
|
824
|
+
else if (t === import_core5.COMPLETE) {
|
|
825
|
+
breaker.recordSuccess();
|
|
826
|
+
syncState();
|
|
827
|
+
a.down([[import_core5.COMPLETE]]);
|
|
828
|
+
} else if (t === import_core5.ERROR) {
|
|
829
|
+
breaker.recordFailure(msgVal(m));
|
|
830
|
+
syncState();
|
|
831
|
+
a.down([m]);
|
|
832
|
+
} else a.down([m]);
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
syncState();
|
|
836
|
+
return unsub;
|
|
837
|
+
},
|
|
838
|
+
{
|
|
839
|
+
...operatorOpts(),
|
|
840
|
+
meta: {
|
|
841
|
+
...callerMeta ?? {},
|
|
842
|
+
breakerState: initialSnapshot,
|
|
843
|
+
...(0, import_core5.factoryTag)("withBreaker", { onOpen })
|
|
844
|
+
},
|
|
845
|
+
completeWhenDepsComplete: false,
|
|
846
|
+
initial: source.cache
|
|
847
|
+
}
|
|
848
|
+
);
|
|
849
|
+
return { node: wrapped, breakerState: wrapped.meta.breakerState };
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
// src/utils/resilience/budget-gate.ts
|
|
854
|
+
var import_core6 = require("@graphrefly/pure-ts/core");
|
|
855
|
+
var HeadIndexQueue = class {
|
|
856
|
+
buf = [];
|
|
857
|
+
head = 0;
|
|
858
|
+
get size() {
|
|
859
|
+
return this.buf.length - this.head;
|
|
860
|
+
}
|
|
861
|
+
push(item) {
|
|
862
|
+
this.buf.push(item);
|
|
863
|
+
}
|
|
864
|
+
/** O(1) — removes and returns the oldest item, or `undefined` when empty. */
|
|
865
|
+
shift() {
|
|
866
|
+
if (this.head >= this.buf.length) return void 0;
|
|
867
|
+
const item = this.buf[this.head];
|
|
868
|
+
this.buf[this.head] = void 0;
|
|
869
|
+
this.head++;
|
|
870
|
+
if (this.head > 32 && this.head * 2 > this.buf.length) {
|
|
871
|
+
this.buf = this.buf.slice(this.head);
|
|
872
|
+
this.head = 0;
|
|
873
|
+
}
|
|
874
|
+
return item;
|
|
875
|
+
}
|
|
876
|
+
clear() {
|
|
877
|
+
this.buf = [];
|
|
878
|
+
this.head = 0;
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
function budgetGate(source, constraints, opts) {
|
|
882
|
+
if (constraints.length === 0) throw new RangeError("budgetGate requires at least one constraint");
|
|
883
|
+
const constraintNodes = constraints.map((c) => c.node);
|
|
884
|
+
const allDeps = [source, ...constraintNodes];
|
|
885
|
+
const buffer = new HeadIndexQueue();
|
|
886
|
+
let paused = false;
|
|
887
|
+
let pendingResolved = false;
|
|
888
|
+
const lockId = /* @__PURE__ */ Symbol("budget-gate");
|
|
889
|
+
const latestValues = new Array(constraints.length);
|
|
890
|
+
function checkBudget() {
|
|
891
|
+
return constraints.every((c, i) => c.check(latestValues[i]));
|
|
892
|
+
}
|
|
893
|
+
function budgetGateStateEqual(a, b) {
|
|
894
|
+
if (a === b) return true;
|
|
895
|
+
if (a.status !== b.status) return false;
|
|
896
|
+
const sa = a.constraintsSnapshot;
|
|
897
|
+
const sb = b.constraintsSnapshot;
|
|
898
|
+
if (sa.length !== sb.length) return false;
|
|
899
|
+
for (let i = 0; i < sa.length; i++) {
|
|
900
|
+
const ai = sa[i];
|
|
901
|
+
const bi = sb[i];
|
|
902
|
+
if (ai === void 0 || bi === void 0) return false;
|
|
903
|
+
if (ai.name !== bi.name) return false;
|
|
904
|
+
if (ai.satisfied !== bi.satisfied) return false;
|
|
905
|
+
if (!Object.is(ai.value, bi.value)) return false;
|
|
906
|
+
}
|
|
907
|
+
return true;
|
|
908
|
+
}
|
|
909
|
+
const budgetGateState = (0, import_core6.node)([], {
|
|
910
|
+
name: "budgetGateState",
|
|
911
|
+
describeKind: "state",
|
|
912
|
+
initial: {
|
|
913
|
+
status: "closed",
|
|
914
|
+
constraintsSnapshot: constraints.map((c) => ({
|
|
915
|
+
name: c.name ?? c.node.name ?? "",
|
|
916
|
+
satisfied: false,
|
|
917
|
+
value: void 0
|
|
918
|
+
}))
|
|
919
|
+
},
|
|
920
|
+
equals: budgetGateStateEqual
|
|
921
|
+
});
|
|
922
|
+
let lastEmittedState = null;
|
|
923
|
+
function publishState() {
|
|
924
|
+
const snapshot = constraints.map((c, i) => {
|
|
925
|
+
const v = latestValues[i];
|
|
926
|
+
let satisfied = false;
|
|
927
|
+
try {
|
|
928
|
+
satisfied = c.check(v);
|
|
929
|
+
} catch (err) {
|
|
930
|
+
console.error(
|
|
931
|
+
`budgetGate: constraint "${c.name ?? c.node.name ?? `[${i}]`}" check threw; treating as not satisfied.`,
|
|
932
|
+
err
|
|
933
|
+
);
|
|
934
|
+
satisfied = false;
|
|
935
|
+
}
|
|
936
|
+
return {
|
|
937
|
+
name: c.name ?? c.node.name ?? "",
|
|
938
|
+
satisfied,
|
|
939
|
+
value: v
|
|
940
|
+
};
|
|
941
|
+
});
|
|
942
|
+
const status = snapshot.every((s) => s.satisfied) ? "open" : "closed";
|
|
943
|
+
const next = { status, constraintsSnapshot: snapshot };
|
|
944
|
+
if (lastEmittedState != null && budgetGateStateEqual(lastEmittedState, next)) {
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
lastEmittedState = next;
|
|
948
|
+
budgetGateState.down([[import_core6.DIRTY], [import_core6.DATA, next]]);
|
|
949
|
+
}
|
|
950
|
+
function flushBuffer(actions) {
|
|
951
|
+
while (buffer.size > 0 && checkBudget()) {
|
|
952
|
+
const item = buffer.shift();
|
|
953
|
+
actions.emit(item);
|
|
954
|
+
}
|
|
955
|
+
if (buffer.size === 0 && pendingResolved) {
|
|
956
|
+
pendingResolved = false;
|
|
957
|
+
actions.down([[import_core6.RESOLVED]]);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
const out = (0, import_core6.node)(
|
|
961
|
+
[],
|
|
962
|
+
(_data, gateActions) => {
|
|
963
|
+
for (let i = 0; i < constraints.length; i++) {
|
|
964
|
+
latestValues[i] = constraints[i].node.cache;
|
|
965
|
+
}
|
|
966
|
+
publishState();
|
|
967
|
+
const unsubs = [];
|
|
968
|
+
for (let depIdx = 0; depIdx < allDeps.length; depIdx++) {
|
|
969
|
+
const dep = allDeps[depIdx];
|
|
970
|
+
unsubs.push(
|
|
971
|
+
dep.subscribe((msgs) => {
|
|
972
|
+
for (const msg of msgs) {
|
|
973
|
+
_handleBudgetMessage(msg, depIdx, gateActions);
|
|
974
|
+
}
|
|
975
|
+
})
|
|
976
|
+
);
|
|
977
|
+
}
|
|
978
|
+
return () => {
|
|
979
|
+
for (const u of unsubs) u();
|
|
980
|
+
};
|
|
981
|
+
},
|
|
982
|
+
{
|
|
983
|
+
...opts,
|
|
984
|
+
describeKind: "derived",
|
|
985
|
+
meta: domainMeta("resilience", "budget_gate", opts?.meta)
|
|
986
|
+
}
|
|
987
|
+
);
|
|
988
|
+
return { node: out, budgetGateState };
|
|
989
|
+
function _handleBudgetMessage(msg, depIndex, actions) {
|
|
990
|
+
const t = msg[0];
|
|
991
|
+
if (depIndex === 0) {
|
|
992
|
+
if (t === import_core6.DATA) {
|
|
993
|
+
if (checkBudget() && buffer.size === 0) {
|
|
994
|
+
actions.emit(msg[1]);
|
|
995
|
+
} else {
|
|
996
|
+
buffer.push(msg[1]);
|
|
997
|
+
if (!paused) {
|
|
998
|
+
paused = true;
|
|
999
|
+
actions.up([[import_core6.PAUSE, lockId]]);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
return true;
|
|
1003
|
+
}
|
|
1004
|
+
if (t === import_core6.DIRTY) {
|
|
1005
|
+
actions.down([[import_core6.DIRTY]]);
|
|
1006
|
+
return true;
|
|
1007
|
+
}
|
|
1008
|
+
if (t === import_core6.RESOLVED) {
|
|
1009
|
+
if (buffer.size === 0) {
|
|
1010
|
+
actions.down([[import_core6.RESOLVED]]);
|
|
1011
|
+
} else {
|
|
1012
|
+
pendingResolved = true;
|
|
1013
|
+
}
|
|
1014
|
+
return true;
|
|
1015
|
+
}
|
|
1016
|
+
if (t === import_core6.COMPLETE || t === import_core6.ERROR) {
|
|
1017
|
+
while (buffer.size > 0) {
|
|
1018
|
+
actions.emit(buffer.shift());
|
|
1019
|
+
}
|
|
1020
|
+
pendingResolved = false;
|
|
1021
|
+
if (paused) {
|
|
1022
|
+
paused = false;
|
|
1023
|
+
actions.up([[import_core6.RESUME, lockId]]);
|
|
1024
|
+
}
|
|
1025
|
+
actions.down([msg]);
|
|
1026
|
+
return true;
|
|
1027
|
+
}
|
|
1028
|
+
return false;
|
|
1029
|
+
}
|
|
1030
|
+
if (t === import_core6.DATA) {
|
|
1031
|
+
latestValues[depIndex - 1] = msg[1];
|
|
1032
|
+
}
|
|
1033
|
+
if (t === import_core6.DATA || t === import_core6.RESOLVED) {
|
|
1034
|
+
const ok = checkBudget();
|
|
1035
|
+
if (ok && buffer.size > 0) {
|
|
1036
|
+
flushBuffer(actions);
|
|
1037
|
+
if (buffer.size === 0 && paused) {
|
|
1038
|
+
paused = false;
|
|
1039
|
+
actions.up([[import_core6.RESUME, lockId]]);
|
|
1040
|
+
}
|
|
1041
|
+
} else if (!ok && !paused && buffer.size > 0) {
|
|
1042
|
+
paused = true;
|
|
1043
|
+
actions.up([[import_core6.PAUSE, lockId]]);
|
|
1044
|
+
}
|
|
1045
|
+
if (t === import_core6.DATA) publishState();
|
|
1046
|
+
return true;
|
|
1047
|
+
}
|
|
1048
|
+
if (t === import_core6.DIRTY) {
|
|
1049
|
+
return true;
|
|
1050
|
+
}
|
|
1051
|
+
if (t === import_core6.ERROR) {
|
|
1052
|
+
actions.down([msg]);
|
|
1053
|
+
return true;
|
|
1054
|
+
}
|
|
1055
|
+
if (t === import_core6.COMPLETE) {
|
|
1056
|
+
return true;
|
|
1057
|
+
}
|
|
1058
|
+
return false;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
// src/utils/resilience/fallback.ts
|
|
1063
|
+
var import_core7 = require("@graphrefly/pure-ts/core");
|
|
1064
|
+
var import_extra = require("@graphrefly/pure-ts/extra");
|
|
1065
|
+
function fallback(source, fb, options) {
|
|
1066
|
+
const callerMeta = options?.meta;
|
|
1067
|
+
return (0, import_core7.node)(
|
|
1068
|
+
(_data, a) => {
|
|
1069
|
+
let fallbackUnsub;
|
|
1070
|
+
let sourceUnsub;
|
|
1071
|
+
function switchToFallback() {
|
|
1072
|
+
sourceUnsub?.();
|
|
1073
|
+
sourceUnsub = void 0;
|
|
1074
|
+
if (isNode(fb) || isThenable(fb) || isAsyncIterable(fb)) {
|
|
1075
|
+
const fbNode = (0, import_extra.fromAny)(fb);
|
|
1076
|
+
fallbackUnsub = fbNode.subscribe((fMsgs) => {
|
|
1077
|
+
a.down(fMsgs);
|
|
1078
|
+
for (const fm of fMsgs) {
|
|
1079
|
+
const ft = fm[0];
|
|
1080
|
+
if (ft === import_core7.COMPLETE || ft === import_core7.ERROR || ft === import_core7.TEARDOWN) {
|
|
1081
|
+
fallbackUnsub = void 0;
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
} else {
|
|
1087
|
+
a.emit(fb);
|
|
1088
|
+
a.down([[import_core7.COMPLETE]]);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
sourceUnsub = source.subscribe((msgs) => {
|
|
1092
|
+
for (const m of msgs) {
|
|
1093
|
+
const t = m[0];
|
|
1094
|
+
if (t === import_core7.DIRTY) a.down([[import_core7.DIRTY]]);
|
|
1095
|
+
else if (t === import_core7.DATA) a.emit(m[1]);
|
|
1096
|
+
else if (t === import_core7.RESOLVED) a.down([[import_core7.RESOLVED]]);
|
|
1097
|
+
else if (t === import_core7.COMPLETE) a.down([[import_core7.COMPLETE]]);
|
|
1098
|
+
else if (t === import_core7.ERROR) {
|
|
1099
|
+
switchToFallback();
|
|
1100
|
+
return;
|
|
1101
|
+
} else if (t === import_core7.TEARDOWN) {
|
|
1102
|
+
fallbackUnsub?.();
|
|
1103
|
+
a.down([m]);
|
|
1104
|
+
return;
|
|
1105
|
+
} else a.down([m]);
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
return () => {
|
|
1109
|
+
sourceUnsub?.();
|
|
1110
|
+
fallbackUnsub?.();
|
|
1111
|
+
};
|
|
1112
|
+
},
|
|
1113
|
+
{
|
|
1114
|
+
...operatorOpts(),
|
|
1115
|
+
initial: source.cache,
|
|
1116
|
+
meta: { ...callerMeta ?? {}, ...(0, import_core7.factoryTag)("fallback") }
|
|
1117
|
+
}
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// src/utils/resilience/rate-limiter.ts
|
|
1122
|
+
var import_core8 = require("@graphrefly/pure-ts/core");
|
|
1123
|
+
function tokenBucket(capacity, refillPerSecond, opts) {
|
|
1124
|
+
if (capacity <= 0) throw new RangeError("capacity must be > 0");
|
|
1125
|
+
if (refillPerSecond < 0) throw new RangeError("refillPerSecond must be >= 0");
|
|
1126
|
+
const clock = opts?.clock ?? import_core8.monotonicNs;
|
|
1127
|
+
let tokens = capacity;
|
|
1128
|
+
let updatedAt = clock();
|
|
1129
|
+
function refill(now) {
|
|
1130
|
+
if (refillPerSecond > 0) {
|
|
1131
|
+
const elapsedNs = now - updatedAt;
|
|
1132
|
+
tokens = Math.min(capacity, tokens + elapsedNs / NS_PER_SEC * refillPerSecond);
|
|
1133
|
+
}
|
|
1134
|
+
updatedAt = now;
|
|
1135
|
+
}
|
|
1136
|
+
return {
|
|
1137
|
+
available() {
|
|
1138
|
+
refill(clock());
|
|
1139
|
+
return tokens;
|
|
1140
|
+
},
|
|
1141
|
+
tryConsume(cost = 1) {
|
|
1142
|
+
if (cost <= 0) return true;
|
|
1143
|
+
const now = clock();
|
|
1144
|
+
refill(now);
|
|
1145
|
+
if (tokens >= cost) {
|
|
1146
|
+
tokens -= cost;
|
|
1147
|
+
return true;
|
|
1148
|
+
}
|
|
1149
|
+
return false;
|
|
1150
|
+
},
|
|
1151
|
+
putBack(cost = 1) {
|
|
1152
|
+
if (cost <= 0) return;
|
|
1153
|
+
refill(clock());
|
|
1154
|
+
tokens = Math.min(capacity, tokens + cost);
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
var RateLimiterOverflowError = class extends Error {
|
|
1159
|
+
name = "RateLimiterOverflowError";
|
|
1160
|
+
constructor(maxBuffer) {
|
|
1161
|
+
super(`rateLimiter buffer overflow (maxBuffer=${maxBuffer})`);
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
function rateLimiterStateEqual(a, b) {
|
|
1165
|
+
return a.status === b.status && a.droppedCount === b.droppedCount && a.pendingCount === b.pendingCount && a.paused === b.paused;
|
|
1166
|
+
}
|
|
1167
|
+
var RATE_LIMITER_INITIAL_STATE = Object.freeze({
|
|
1168
|
+
status: "open",
|
|
1169
|
+
droppedCount: 0,
|
|
1170
|
+
pendingCount: 0,
|
|
1171
|
+
paused: false
|
|
1172
|
+
});
|
|
1173
|
+
function rateLimiter(source, opts) {
|
|
1174
|
+
const isReactive = isNode(opts);
|
|
1175
|
+
if (!isReactive) {
|
|
1176
|
+
const o = opts;
|
|
1177
|
+
if (o.maxEvents <= 0) throw new RangeError("maxEvents must be > 0");
|
|
1178
|
+
if (o.windowNs <= 0) throw new RangeError("windowNs must be > 0");
|
|
1179
|
+
if (o.maxBuffer === void 0) {
|
|
1180
|
+
throw new RangeError(
|
|
1181
|
+
"rateLimiter requires explicit maxBuffer (use Infinity to opt in to unbounded)"
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
const isUnbounded0 = o.maxBuffer === Infinity;
|
|
1185
|
+
if (!isUnbounded0 && (!Number.isInteger(o.maxBuffer) || o.maxBuffer < 1)) {
|
|
1186
|
+
throw new RangeError("maxBuffer must be a positive integer (or Infinity for unbounded)");
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
const initialOpts = isReactive ? opts.cache : opts;
|
|
1190
|
+
const initialMaxBuffer = initialOpts?.maxBuffer;
|
|
1191
|
+
const isUnbounded = initialMaxBuffer === Infinity;
|
|
1192
|
+
const out = (0, import_core8.node)(
|
|
1193
|
+
(_data, a) => {
|
|
1194
|
+
let maxEvents = initialOpts?.maxEvents ?? 1;
|
|
1195
|
+
let windowNs = initialOpts?.windowNs ?? NS_PER_SEC;
|
|
1196
|
+
let maxBuffer = initialMaxBuffer ?? 1;
|
|
1197
|
+
let onOverflow = initialOpts?.onOverflow ?? "drop-newest";
|
|
1198
|
+
let refillPerSec = maxEvents * NS_PER_SEC / windowNs;
|
|
1199
|
+
let tokenTimeNs = NS_PER_SEC / refillPerSec;
|
|
1200
|
+
let bucket = tokenBucket(maxEvents, refillPerSec);
|
|
1201
|
+
const pending = isUnbounded ? makeArrayQueue() : ringBufferQueue(Math.max(1, maxBuffer));
|
|
1202
|
+
const timer = new import_core8.ResettableTimer();
|
|
1203
|
+
let terminated = false;
|
|
1204
|
+
let dropped = 0;
|
|
1205
|
+
const droppedNode = out.meta.droppedCount;
|
|
1206
|
+
const stateNode = out.meta.rateLimitState;
|
|
1207
|
+
let lastState = RATE_LIMITER_INITIAL_STATE;
|
|
1208
|
+
function syncState() {
|
|
1209
|
+
droppedNode.emit(dropped);
|
|
1210
|
+
const isPaused = pending.size > 0;
|
|
1211
|
+
const next = {
|
|
1212
|
+
status: isPaused ? "throttled" : "open",
|
|
1213
|
+
droppedCount: dropped,
|
|
1214
|
+
pendingCount: pending.size,
|
|
1215
|
+
paused: isPaused
|
|
1216
|
+
};
|
|
1217
|
+
if (!rateLimiterStateEqual(lastState, next)) {
|
|
1218
|
+
lastState = next;
|
|
1219
|
+
stateNode.emit(next);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
lastState = RATE_LIMITER_INITIAL_STATE;
|
|
1223
|
+
droppedNode.emit(0);
|
|
1224
|
+
stateNode.emit(RATE_LIMITER_INITIAL_STATE);
|
|
1225
|
+
const optMirror = resolveReactiveOption(
|
|
1226
|
+
opts,
|
|
1227
|
+
(next) => {
|
|
1228
|
+
if (terminated) return;
|
|
1229
|
+
if (next == null) return;
|
|
1230
|
+
if (typeof next === "object" && Object.keys(next).length === 0) return;
|
|
1231
|
+
if (!(next.maxEvents > 0) || !(next.windowNs > 0)) return;
|
|
1232
|
+
const nextBuf = next.maxBuffer;
|
|
1233
|
+
if (nextBuf === void 0) return;
|
|
1234
|
+
const nextUnbounded = nextBuf === Infinity;
|
|
1235
|
+
if (nextUnbounded !== isUnbounded) {
|
|
1236
|
+
return;
|
|
1237
|
+
}
|
|
1238
|
+
if (!nextUnbounded && (!Number.isInteger(nextBuf) || nextBuf < 1)) return;
|
|
1239
|
+
if (!nextUnbounded && nextBuf > maxBuffer) {
|
|
1240
|
+
console.warn(
|
|
1241
|
+
`rateLimiter: reactive maxBuffer grow (${maxBuffer} \u2192 ${nextBuf}) rejected. The pending ring buffer is allocated at construction; reactive maxBuffer is monotonically non-increasing. Recreate the rateLimiter with the larger cap if growth is required.`
|
|
1242
|
+
);
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
maxEvents = next.maxEvents;
|
|
1246
|
+
windowNs = next.windowNs;
|
|
1247
|
+
maxBuffer = nextBuf;
|
|
1248
|
+
onOverflow = next.onOverflow ?? "drop-newest";
|
|
1249
|
+
refillPerSec = maxEvents * NS_PER_SEC / windowNs;
|
|
1250
|
+
tokenTimeNs = NS_PER_SEC / refillPerSec;
|
|
1251
|
+
bucket = tokenBucket(maxEvents, refillPerSec);
|
|
1252
|
+
if (!nextUnbounded) {
|
|
1253
|
+
while (pending.size > maxBuffer) {
|
|
1254
|
+
pending.shift();
|
|
1255
|
+
dropped += 1;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
syncState();
|
|
1259
|
+
}
|
|
1260
|
+
);
|
|
1261
|
+
function tryEmit() {
|
|
1262
|
+
while (pending.size > 0) {
|
|
1263
|
+
if (bucket.tryConsume(1)) {
|
|
1264
|
+
a.emit(pending.shift());
|
|
1265
|
+
syncState();
|
|
1266
|
+
} else {
|
|
1267
|
+
timer.start(Math.max(1, tokenTimeNs / NS_PER_MS), tryEmit);
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
function recordDrop() {
|
|
1273
|
+
dropped += 1;
|
|
1274
|
+
syncState();
|
|
1275
|
+
}
|
|
1276
|
+
function resetForTerminal() {
|
|
1277
|
+
terminated = true;
|
|
1278
|
+
timer.cancel();
|
|
1279
|
+
while (pending.size > 0) pending.shift();
|
|
1280
|
+
dropped = 0;
|
|
1281
|
+
}
|
|
1282
|
+
const unsub = source.subscribe((msgs) => {
|
|
1283
|
+
for (const m of msgs) {
|
|
1284
|
+
if (terminated) return;
|
|
1285
|
+
const t = m[0];
|
|
1286
|
+
if (t === import_core8.DIRTY) a.down([[import_core8.DIRTY]]);
|
|
1287
|
+
else if (t === import_core8.DATA) {
|
|
1288
|
+
if (!isUnbounded && pending.size >= maxBuffer) {
|
|
1289
|
+
if (onOverflow === "drop-newest") {
|
|
1290
|
+
recordDrop();
|
|
1291
|
+
} else if (onOverflow === "drop-oldest") {
|
|
1292
|
+
pending.shift();
|
|
1293
|
+
pending.push(m[1]);
|
|
1294
|
+
recordDrop();
|
|
1295
|
+
} else {
|
|
1296
|
+
recordDrop();
|
|
1297
|
+
resetForTerminal();
|
|
1298
|
+
a.down([[import_core8.ERROR, new RateLimiterOverflowError(maxBuffer)]]);
|
|
1299
|
+
return;
|
|
1300
|
+
}
|
|
1301
|
+
} else {
|
|
1302
|
+
pending.push(m[1]);
|
|
1303
|
+
syncState();
|
|
1304
|
+
}
|
|
1305
|
+
tryEmit();
|
|
1306
|
+
} else if (t === import_core8.RESOLVED) a.down([[import_core8.RESOLVED]]);
|
|
1307
|
+
else if (t === import_core8.COMPLETE) {
|
|
1308
|
+
resetForTerminal();
|
|
1309
|
+
a.down([[import_core8.COMPLETE]]);
|
|
1310
|
+
} else if (t === import_core8.ERROR) {
|
|
1311
|
+
resetForTerminal();
|
|
1312
|
+
a.down([m]);
|
|
1313
|
+
} else if (t === import_core8.TEARDOWN) {
|
|
1314
|
+
resetForTerminal();
|
|
1315
|
+
a.down([m]);
|
|
1316
|
+
return;
|
|
1317
|
+
} else a.down([m]);
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
1320
|
+
return () => {
|
|
1321
|
+
terminated = true;
|
|
1322
|
+
timer.cancel();
|
|
1323
|
+
unsub();
|
|
1324
|
+
optMirror.unsub();
|
|
1325
|
+
};
|
|
1326
|
+
},
|
|
1327
|
+
{
|
|
1328
|
+
...operatorOpts(),
|
|
1329
|
+
initial: source.cache,
|
|
1330
|
+
meta: {
|
|
1331
|
+
// Caller-supplied meta first; companion seeds + factoryTag
|
|
1332
|
+
// override below so they always win.
|
|
1333
|
+
...isReactive ? {} : opts.meta ?? {},
|
|
1334
|
+
droppedCount: 0,
|
|
1335
|
+
rateLimitState: RATE_LIMITER_INITIAL_STATE,
|
|
1336
|
+
...(0, import_core8.factoryTag)("rateLimiter", isReactive ? { reactiveOpts: true } : opts)
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
);
|
|
1340
|
+
return {
|
|
1341
|
+
node: out,
|
|
1342
|
+
droppedCount: out.meta.droppedCount,
|
|
1343
|
+
rateLimitState: out.meta.rateLimitState
|
|
1344
|
+
};
|
|
1345
|
+
}
|
|
1346
|
+
function ringBufferQueue(capacity) {
|
|
1347
|
+
const buf = new import_core8.RingBuffer(capacity);
|
|
1348
|
+
return {
|
|
1349
|
+
push: (v) => buf.push(v),
|
|
1350
|
+
shift: () => buf.shift(),
|
|
1351
|
+
get size() {
|
|
1352
|
+
return buf.size;
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
function makeArrayQueue() {
|
|
1357
|
+
const arr = [];
|
|
1358
|
+
return {
|
|
1359
|
+
push: (v) => {
|
|
1360
|
+
arr.push(v);
|
|
1361
|
+
},
|
|
1362
|
+
shift: () => arr.shift(),
|
|
1363
|
+
get size() {
|
|
1364
|
+
return arr.length;
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
// src/presets/resilience/resilient-pipeline.ts
|
|
1370
|
+
function isNode2(x) {
|
|
1371
|
+
return typeof x === "object" && x !== null && "subscribe" in x && "down" in x;
|
|
1372
|
+
}
|
|
1373
|
+
function assertTimeoutMsValid(ms) {
|
|
1374
|
+
if (ms <= 0) throw new RangeError("timeoutMs must be > 0");
|
|
1375
|
+
if (ms > 9e6) {
|
|
1376
|
+
throw new RangeError(
|
|
1377
|
+
"timeoutMs must be <= 9_000_000 (\u22482.5h) to stay within safe ns arithmetic"
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
var ResilientPipelineGraph = class extends import_graph.Graph {
|
|
1382
|
+
/**
|
|
1383
|
+
* Final resilient node — subscribe to this for `DATA` emissions.
|
|
1384
|
+
*
|
|
1385
|
+
* Named `output` (not `node`) because `Graph.node(name)` already names the
|
|
1386
|
+
* path-resolution method on the base class; a `readonly node` field would
|
|
1387
|
+
* shadow it.
|
|
1388
|
+
*/
|
|
1389
|
+
output;
|
|
1390
|
+
/** Live status: `"pending" | "running" | "completed" | "errored"`. */
|
|
1391
|
+
status;
|
|
1392
|
+
/**
|
|
1393
|
+
* Last error payload, or `null` when not errored.
|
|
1394
|
+
*
|
|
1395
|
+
* Named `lastError` (not `error`) because `Graph.error(name, err)` already
|
|
1396
|
+
* names a method on the base class.
|
|
1397
|
+
*/
|
|
1398
|
+
lastError;
|
|
1399
|
+
/** Breaker state when `opts.breaker` is provided; `undefined` otherwise. */
|
|
1400
|
+
breakerState;
|
|
1401
|
+
/**
|
|
1402
|
+
* Timeout state companion when `opts.timeoutMs` is supplied as a
|
|
1403
|
+
* `Node<Partial<TimeoutOptions>>`-like form; `undefined` otherwise
|
|
1404
|
+
* (DS-13.5.B forwarding contract — Node-form opts skip the switchMap
|
|
1405
|
+
* rebuild and lift the primitive's lifecycle companion onto the
|
|
1406
|
+
* pipeline bundle).
|
|
1407
|
+
*/
|
|
1408
|
+
timeoutState;
|
|
1409
|
+
/**
|
|
1410
|
+
* Retry state companion when `opts.retry` is supplied as a
|
|
1411
|
+
* `Node<RetryOptions>`-like form; `undefined` otherwise
|
|
1412
|
+
* (DS-13.5.B forwarding contract).
|
|
1413
|
+
*/
|
|
1414
|
+
retryState;
|
|
1415
|
+
/**
|
|
1416
|
+
* Drop-counter when `opts.rateLimit` is provided; `undefined` otherwise.
|
|
1417
|
+
*
|
|
1418
|
+
* **Lifetime note:** `droppedCount` retains its final value through
|
|
1419
|
+
* terminal (`COMPLETE` / `ERROR` / `TEARDOWN`); the underlying counter
|
|
1420
|
+
* resets to `0` only at the next subscription cycle.
|
|
1421
|
+
*/
|
|
1422
|
+
droppedCount;
|
|
1423
|
+
/**
|
|
1424
|
+
* Combined rate-limit state when `opts.rateLimit` is provided; `undefined`
|
|
1425
|
+
* otherwise. Same lifecycle as {@link droppedCount} but exposes
|
|
1426
|
+
* `pendingCount` and `paused` alongside the drop counter for richer
|
|
1427
|
+
* backpressure observability (Tier 5.2 D7).
|
|
1428
|
+
*/
|
|
1429
|
+
rateLimitState;
|
|
1430
|
+
constructor(source, opts = {}) {
|
|
1431
|
+
super(opts.name ?? "resilient_pipeline", opts.graph);
|
|
1432
|
+
let current = source;
|
|
1433
|
+
let droppedCount;
|
|
1434
|
+
let rateLimitState;
|
|
1435
|
+
let breakerState;
|
|
1436
|
+
let timeoutState;
|
|
1437
|
+
let retryState;
|
|
1438
|
+
if (opts.rateLimit != null) {
|
|
1439
|
+
if (isNode2(opts.rateLimit)) {
|
|
1440
|
+
const bundle = rateLimiter(current, opts.rateLimit);
|
|
1441
|
+
current = bundle.node;
|
|
1442
|
+
droppedCount = bundle.droppedCount;
|
|
1443
|
+
rateLimitState = bundle.rateLimitState;
|
|
1444
|
+
this.add(current, { name: "rateLimited" });
|
|
1445
|
+
this.add(droppedCount, { name: "droppedCount" });
|
|
1446
|
+
this.add(rateLimitState, { name: "rateLimitState" });
|
|
1447
|
+
} else {
|
|
1448
|
+
const rateOpts = {
|
|
1449
|
+
...opts.rateLimit,
|
|
1450
|
+
maxBuffer: opts.rateLimit.maxBuffer ?? Infinity,
|
|
1451
|
+
meta: domainMeta("resilient", "rate-limit")
|
|
1452
|
+
};
|
|
1453
|
+
const bundle = rateLimiter(current, rateOpts);
|
|
1454
|
+
current = bundle.node;
|
|
1455
|
+
droppedCount = bundle.droppedCount;
|
|
1456
|
+
rateLimitState = bundle.rateLimitState;
|
|
1457
|
+
this.add(current, { name: "rateLimited" });
|
|
1458
|
+
this.add(droppedCount, { name: "droppedCount" });
|
|
1459
|
+
this.add(rateLimitState, { name: "rateLimitState" });
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
if (opts.budget != null) {
|
|
1463
|
+
if (isNode2(opts.budget)) {
|
|
1464
|
+
const inputForLayer = current;
|
|
1465
|
+
const reactiveBudget = opts.budget;
|
|
1466
|
+
current = (0, import_extra2.switchMap)(
|
|
1467
|
+
reactiveBudget,
|
|
1468
|
+
(constraints) => constraints.length > 0 ? budgetGate(inputForLayer, constraints, {
|
|
1469
|
+
meta: domainMeta("resilient", "budget")
|
|
1470
|
+
}).node : inputForLayer
|
|
1471
|
+
);
|
|
1472
|
+
this.add(current, { name: "budgetGated" });
|
|
1473
|
+
} else if (opts.budget.length > 0) {
|
|
1474
|
+
current = budgetGate(current, opts.budget, {
|
|
1475
|
+
meta: domainMeta("resilient", "budget")
|
|
1476
|
+
}).node;
|
|
1477
|
+
this.add(current, { name: "budgetGated" });
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
if (opts.breaker != null) {
|
|
1481
|
+
const breaker = circuitBreaker(opts.breaker);
|
|
1482
|
+
const onOpen = opts.breakerOnOpen ?? "skip";
|
|
1483
|
+
const wrapped = withBreaker(breaker, {
|
|
1484
|
+
onOpen,
|
|
1485
|
+
meta: domainMeta("resilient", "breaker")
|
|
1486
|
+
})(current);
|
|
1487
|
+
current = wrapped.node;
|
|
1488
|
+
breakerState = wrapped.breakerState;
|
|
1489
|
+
this.add(current, { name: "breakerWrapped" });
|
|
1490
|
+
this.add(breakerState, { name: "breakerState" });
|
|
1491
|
+
}
|
|
1492
|
+
if (opts.timeoutMs != null) {
|
|
1493
|
+
if (isNode2(opts.timeoutMs)) {
|
|
1494
|
+
const reactiveTimeoutMs = opts.timeoutMs;
|
|
1495
|
+
const initialMs = reactiveTimeoutMs.cache;
|
|
1496
|
+
if (initialMs !== void 0) assertTimeoutMsValid(initialMs);
|
|
1497
|
+
const optsBridge = (0, import_core9.node)(
|
|
1498
|
+
[reactiveTimeoutMs],
|
|
1499
|
+
(batchData, actions, ctx) => {
|
|
1500
|
+
const data = batchData.map(
|
|
1501
|
+
(b, i) => b != null && b.length > 0 ? b.at(-1) : ctx.prevData[i]
|
|
1502
|
+
);
|
|
1503
|
+
const ms = data[0];
|
|
1504
|
+
if (ms === void 0) return;
|
|
1505
|
+
if (typeof ms !== "number" || !Number.isFinite(ms) || ms <= 0 || ms > 9e6) {
|
|
1506
|
+
actions.down([
|
|
1507
|
+
[
|
|
1508
|
+
import_core9.ERROR,
|
|
1509
|
+
new RangeError(
|
|
1510
|
+
`resilientPipeline: timeoutMs reactive emit invalid (${ms}); must be > 0 and <= 9_000_000.`
|
|
1511
|
+
)
|
|
1512
|
+
]
|
|
1513
|
+
]);
|
|
1514
|
+
return;
|
|
1515
|
+
}
|
|
1516
|
+
actions.emit({ ns: ms * NS_PER_MS });
|
|
1517
|
+
},
|
|
1518
|
+
{
|
|
1519
|
+
describeKind: "derived",
|
|
1520
|
+
name: "timeoutOptsBridge",
|
|
1521
|
+
...initialMs !== void 0 ? { initial: { ns: initialMs * NS_PER_MS } } : {}
|
|
1522
|
+
}
|
|
1523
|
+
);
|
|
1524
|
+
this.add(optsBridge, { name: "timeoutOptsBridge" });
|
|
1525
|
+
const bundle = withTimeout(current, optsBridge, {
|
|
1526
|
+
meta: domainMeta("resilient", "timeout")
|
|
1527
|
+
});
|
|
1528
|
+
current = bundle.node;
|
|
1529
|
+
timeoutState = bundle.timeoutState;
|
|
1530
|
+
this.add(current, { name: "timeoutWrapped" });
|
|
1531
|
+
this.add(timeoutState, { name: "timeoutState" });
|
|
1532
|
+
} else {
|
|
1533
|
+
assertTimeoutMsValid(opts.timeoutMs);
|
|
1534
|
+
const bundle = withTimeout(
|
|
1535
|
+
current,
|
|
1536
|
+
{ ns: opts.timeoutMs * NS_PER_MS },
|
|
1537
|
+
{
|
|
1538
|
+
meta: domainMeta("resilient", "timeout")
|
|
1539
|
+
}
|
|
1540
|
+
);
|
|
1541
|
+
current = bundle.node;
|
|
1542
|
+
timeoutState = bundle.timeoutState;
|
|
1543
|
+
this.add(current, { name: "timeoutWrapped" });
|
|
1544
|
+
this.add(timeoutState, { name: "timeoutState" });
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
if (opts.retry != null) {
|
|
1548
|
+
if (isNode2(opts.retry)) {
|
|
1549
|
+
const bundle = retry(current, opts.retry);
|
|
1550
|
+
current = bundle.node;
|
|
1551
|
+
retryState = bundle.retryState;
|
|
1552
|
+
this.add(current, { name: "retryWrapped" });
|
|
1553
|
+
this.add(retryState, { name: "retryState" });
|
|
1554
|
+
} else {
|
|
1555
|
+
const bundle = retry(current, {
|
|
1556
|
+
...opts.retry,
|
|
1557
|
+
meta: domainMeta("resilient", "retry")
|
|
1558
|
+
});
|
|
1559
|
+
current = bundle.node;
|
|
1560
|
+
retryState = bundle.retryState;
|
|
1561
|
+
this.add(current, { name: "retryWrapped" });
|
|
1562
|
+
this.add(retryState, { name: "retryState" });
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
if (opts.fallback !== void 0) {
|
|
1566
|
+
current = fallback(current, opts.fallback, {
|
|
1567
|
+
meta: domainMeta("resilient", "fallback")
|
|
1568
|
+
});
|
|
1569
|
+
this.add(current, { name: "fallbackWrapped" });
|
|
1570
|
+
}
|
|
1571
|
+
const statusBundle = withStatus(current, {
|
|
1572
|
+
initialStatus: opts.initialStatus ?? "pending",
|
|
1573
|
+
meta: domainMeta("resilient", "status")
|
|
1574
|
+
});
|
|
1575
|
+
this.output = statusBundle.node;
|
|
1576
|
+
this.status = statusBundle.status;
|
|
1577
|
+
this.lastError = statusBundle.error;
|
|
1578
|
+
this.breakerState = breakerState;
|
|
1579
|
+
this.droppedCount = droppedCount;
|
|
1580
|
+
this.rateLimitState = rateLimitState;
|
|
1581
|
+
this.timeoutState = timeoutState;
|
|
1582
|
+
this.retryState = retryState;
|
|
1583
|
+
this.add(this.output, { name: "output" });
|
|
1584
|
+
this.add(this.status, { name: "status" });
|
|
1585
|
+
this.add(this.lastError, { name: "lastError" });
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
function resilientPipeline(source, opts = {}) {
|
|
1589
|
+
const g = new ResilientPipelineGraph(source, opts);
|
|
1590
|
+
g.tagFactory("resilientPipeline", (0, import_core9.placeholderArgs)(opts));
|
|
1591
|
+
return g;
|
|
1592
|
+
}
|
|
1593
|
+
//# sourceMappingURL=index.cjs.map
|