@demlik/tea 0.12.0 → 0.14.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 +11 -9
- package/dist/agent/index.d.ts +638 -45
- package/dist/agent/index.js +9 -19
- package/dist/{chunk-25LBDCBC.js → chunk-6IQPODUF.js} +2 -2
- package/dist/{chunk-25LBDCBC.js.map → chunk-6IQPODUF.js.map} +1 -1
- package/dist/chunk-AQ6ZIMEA.js +421 -0
- package/dist/chunk-AQ6ZIMEA.js.map +1 -0
- package/dist/{chunk-MUUROGIH.js → chunk-BLJ2JQSH.js} +62 -12
- package/dist/chunk-BLJ2JQSH.js.map +1 -0
- package/dist/{chunk-7SVIRMC6.js → chunk-F2US5BW6.js} +25 -5
- package/dist/chunk-F2US5BW6.js.map +1 -0
- package/dist/{batch-window/index.js → chunk-F7FMAWLA.js} +4 -8
- package/dist/chunk-F7FMAWLA.js.map +1 -0
- package/dist/{chunk-7V4EVLZA.js → chunk-HUKZQX6U.js} +20 -16
- package/dist/chunk-HUKZQX6U.js.map +1 -0
- package/dist/{chunk-EWJP3YYP.js → chunk-HWVW4AXC.js} +3 -3
- package/dist/chunk-HWVW4AXC.js.map +1 -0
- package/dist/{chunk-WLGO64WC.js → chunk-HYDWG35Q.js} +23 -6
- package/dist/chunk-HYDWG35Q.js.map +1 -0
- package/dist/{chunk-I5OV65MS.js → chunk-I5MQMJDW.js} +57 -7
- package/dist/chunk-I5MQMJDW.js.map +1 -0
- package/dist/{chunk-J6527VRQ.js → chunk-LFZUK6J2.js} +3 -3
- package/dist/chunk-LFZUK6J2.js.map +1 -0
- package/dist/{chunk-ZVJZ72HY.js → chunk-LYLTKJWM.js} +25 -11
- package/dist/chunk-LYLTKJWM.js.map +1 -0
- package/dist/{chunk-D736QUGF.js → chunk-MYXFNWAJ.js} +4 -5
- package/dist/chunk-MYXFNWAJ.js.map +1 -0
- package/dist/{chunk-K575PT4S.js → chunk-PR6TB3BL.js} +15 -4
- package/dist/chunk-PR6TB3BL.js.map +1 -0
- package/dist/chunk-RQULHGYH.js +1804 -0
- package/dist/chunk-RQULHGYH.js.map +1 -0
- package/dist/{chunk-FV3Z5MBE.js → chunk-TXN2KFHF.js} +14 -4
- package/dist/chunk-TXN2KFHF.js.map +1 -0
- package/dist/{chunk-Q2UM7BXU.js → chunk-VBDU4JL6.js} +2 -2
- package/dist/chunk-VBDU4JL6.js.map +1 -0
- package/dist/chunk-Z2L3LSNV.js +1470 -0
- package/dist/chunk-Z2L3LSNV.js.map +1 -0
- package/dist/core-CTzMJ82M.d.ts +562 -0
- package/dist/devtools/index.d.ts +2 -2
- package/dist/devtools/index.js +207 -2
- package/dist/devtools/index.js.map +1 -1
- package/dist/do/index.d.ts +48 -31
- package/dist/do/index.js +36 -25
- package/dist/do/index.js.map +1 -1
- package/dist/{durable-effects-D8SqU_if.d.ts → durable-effects-B0-qGQDy.d.ts} +2 -2
- package/dist/extension/index.d.ts +301 -3
- package/dist/extension/index.js +596 -5
- package/dist/extension/index.js.map +1 -1
- package/dist/flow/index.d.ts +1295 -0
- package/dist/flow/index.js +732 -0
- package/dist/flow/index.js.map +1 -0
- package/dist/idempotency/index.d.ts +90 -116
- package/dist/idempotency/index.js +4 -1
- package/dist/{batch-window/index.d.ts → index-4vZzljCD.d.ts} +7 -11
- package/dist/{fan-out/index.d.ts → index-6A7dB8f6.d.ts} +7 -8
- package/dist/index-B5BZ-_cT.d.ts +616 -0
- package/dist/index-Bc40JWVl.d.ts +131 -0
- package/dist/{debounce/index.d.ts → index-DHSUmQTR.d.ts} +7 -7
- package/dist/index-DJWIER_3.d.ts +69 -0
- package/dist/{snapshot/index.d.ts → index-DMCeMPMJ.d.ts} +15 -77
- package/dist/{monitored-run/index.d.ts → index-NjrT3fL2.d.ts} +37 -12
- package/dist/{recorder/index.d.ts → index-TvRb1KVf.d.ts} +4 -6
- package/dist/{deadline/index.d.ts → index-q0hXFeZ0.d.ts} +155 -8
- package/dist/index.d.ts +719 -6
- package/dist/index.js +1 -2
- package/dist/jev/index.d.ts +634 -0
- package/dist/jev/index.js +433 -0
- package/dist/jev/index.js.map +1 -0
- package/dist/machine-CdIcN2Xm.d.ts +1773 -0
- package/dist/machine-viz/index.d.ts +2 -1
- package/dist/machine-viz/index.js +12 -5
- package/dist/machine-viz/index.js.map +1 -1
- package/dist/mem/index.d.ts +19 -3
- package/dist/mem/index.js +22 -2
- package/dist/mem/index.js.map +1 -1
- package/dist/node/index.d.ts +130 -4
- package/dist/node/index.js +222 -10
- package/dist/node/index.js.map +1 -1
- package/dist/{paginator → paginate}/index.d.ts +151 -6
- package/dist/paginate/index.js +7 -0
- package/dist/parity/index.d.ts +5 -10
- package/dist/parity/index.js +4 -7
- package/dist/parity/index.js.map +1 -1
- package/dist/pbt/index.d.ts +248 -5
- package/dist/pbt/index.js +124 -5
- package/dist/pbt/index.js.map +1 -1
- package/dist/{trace-replay → persistence}/index.d.ts +7 -4
- package/dist/persistence/index.js +6 -0
- package/dist/react/index.d.ts +4 -3
- package/dist/react/index.js +1 -2
- package/dist/react/index.js.map +1 -1
- package/dist/resilience/index.d.ts +743 -0
- package/dist/resilience/index.js +657 -0
- package/dist/resilience/index.js.map +1 -0
- package/dist/retry-backoff/index.d.ts +3 -2
- package/dist/retry-backoff/index.js +1 -1
- package/dist/runtime-types-LWDoi943.d.ts +998 -0
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing/index.js +1 -2
- package/dist/testing/index.js.map +1 -1
- package/dist/{throttled-input → timing}/index.d.ts +144 -12
- package/dist/{throttled-input → timing}/index.js +57 -12
- package/dist/timing/index.js.map +1 -0
- package/dist/{types-D7u9DkH7.d.ts → types-DP3f5NIl.d.ts} +1 -1
- package/dist/work-queue/index.d.ts +131 -54
- package/dist/work-queue/index.js +3 -2
- package/dist/work-queue/index.js.map +1 -1
- package/package.json +50 -216
- package/dist/authed-call/index.d.ts +0 -119
- package/dist/authed-call/index.js +0 -134
- package/dist/authed-call/index.js.map +0 -1
- package/dist/await-terminal/index.d.ts +0 -100
- package/dist/await-terminal/index.js +0 -76
- package/dist/await-terminal/index.js.map +0 -1
- package/dist/batch-window/index.js.map +0 -1
- package/dist/cache/index.d.ts +0 -151
- package/dist/cache/index.js +0 -8
- package/dist/chart/index.d.ts +0 -217
- package/dist/chart/index.js +0 -16
- package/dist/chart/index.js.map +0 -1
- package/dist/chart/inspect/index.d.ts +0 -85
- package/dist/chart/inspect/index.js +0 -5
- package/dist/chart/inspect/react.d.ts +0 -112
- package/dist/chart/inspect/react.js +0 -11
- package/dist/chart/inspect/react.js.map +0 -1
- package/dist/chart/inspect/styles.css +0 -286
- package/dist/chart/lane/index.d.ts +0 -361
- package/dist/chart/lane/index.js +0 -9
- package/dist/chart/lane/index.js.map +0 -1
- package/dist/chart/lane/react.d.ts +0 -83
- package/dist/chart/lane/react.js +0 -559
- package/dist/chart/lane/react.js.map +0 -1
- package/dist/chart/lane/server.d.ts +0 -148
- package/dist/chart/lane/server.js +0 -209
- package/dist/chart/lane/server.js.map +0 -1
- package/dist/chart/lane/styles.css +0 -498
- package/dist/chart/lane/viewer/assets/abnfDiagram-N423BO3Z-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/architectureDiagram-T3A2C74G-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/blockDiagram-VBNYF7ZC-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/c4Diagram-5PPSVZJV-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/chunk-2GRJ4B5K-HdDf8SI3.js +0 -1
- package/dist/chart/lane/viewer/assets/chunk-5RXB4S5H-CcNtpUd7.js +0 -231
- package/dist/chart/lane/viewer/assets/chunk-5VM5RSS4-BP4fRS_5.js +0 -15
- package/dist/chart/lane/viewer/assets/chunk-KBJHAD2P-DZOw7xU6.js +0 -1
- package/dist/chart/lane/viewer/assets/chunk-NSK5VX7P-CBCyTZMs.js +0 -128
- package/dist/chart/lane/viewer/assets/classDiagram-JCYQIIEL-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/classDiagram-v2-OCEON4UE-D4uAiFr8.js +0 -206
- package/dist/chart/lane/viewer/assets/cose-bilkent-JH36ORCC-DOwCrGXH.js +0 -1
- package/dist/chart/lane/viewer/assets/cynefinDiagram-MW4NZA55-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/dagre-K_PewWfS.js +0 -1
- package/dist/chart/lane/viewer/assets/dagre-VZM6K2ZE-831qZcA8.js +0 -4
- package/dist/chart/lane/viewer/assets/diagram-7IWD3JNH-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/diagram-B4RE2ZJO-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/diagram-LBJQPF4R-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/diagram-Q27KOJAE-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/diagram-UB23O5K3-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/ebnfDiagram-BXEA7PRR-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/erDiagram-JOGREHBK-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/flowDiagram-UKHOOZJN-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/ganttDiagram-PKOTCBZU-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/gitGraphDiagram-DS77QQ5N-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/index-9SkH5NA3.css +0 -1
- package/dist/chart/lane/viewer/assets/index-Bgt4sXpW.js +0 -195
- package/dist/chart/lane/viewer/assets/infoDiagram-6WML65LV-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/ishikawaDiagram-WSZJBQD7-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/journeyDiagram-NVQOT4AX-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/kanban-definition-27J2QSJJ-G7PaPzy-.js +0 -89
- package/dist/chart/lane/viewer/assets/katex-DOwCrGXH.js +0 -1
- package/dist/chart/lane/viewer/assets/mindmap-definition-FAOFIHXS-CGj9nrVk.js +0 -96
- package/dist/chart/lane/viewer/assets/path-fybaL0A-.js +0 -1
- package/dist/chart/lane/viewer/assets/pegDiagram-VL7TDLO6-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/pieDiagram-7S7Q4E2Y-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/quadrantDiagram-CIZ2JOQS-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/railroadDiagram-AXF67PYL-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/requirementDiagram-LRYGKXZP-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/sankeyDiagram-W5VNT64P-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/sequenceDiagram-SI44F4Z6-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/stateDiagram-OKZ733FA-B_88AzBS.js +0 -1
- package/dist/chart/lane/viewer/assets/stateDiagram-v2-UEYNNEHI-CR5gcgq6.js +0 -1
- package/dist/chart/lane/viewer/assets/swimlanes-SLNWSIFB-B4xK-rwg.js +0 -1
- package/dist/chart/lane/viewer/assets/swimlanesDiagram-ULZ7WXOC-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/timeline-definition-Z64GVDOM-CCv52MfY.js +0 -120
- package/dist/chart/lane/viewer/assets/vennDiagram-T6HMQDX7-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/wardleyDiagram-T6FBY63Y-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/assets/xychartDiagram-ELKLHX3M-C729LI31.js +0 -1
- package/dist/chart/lane/viewer/index.html +0 -15
- package/dist/chart/report/index.d.ts +0 -116
- package/dist/chart/report/index.js +0 -32
- package/dist/chart/report/index.js.map +0 -1
- package/dist/chunk-2YFLOCWX.js +0 -15
- package/dist/chunk-2YFLOCWX.js.map +0 -1
- package/dist/chunk-3JU6657S.js +0 -372
- package/dist/chunk-3JU6657S.js.map +0 -1
- package/dist/chunk-4KTWLPL5.js +0 -33
- package/dist/chunk-4KTWLPL5.js.map +0 -1
- package/dist/chunk-5EHLEUTL.js +0 -686
- package/dist/chunk-5EHLEUTL.js.map +0 -1
- package/dist/chunk-5KJKJOFC.js +0 -758
- package/dist/chunk-5KJKJOFC.js.map +0 -1
- package/dist/chunk-7SVIRMC6.js.map +0 -1
- package/dist/chunk-7V4EVLZA.js.map +0 -1
- package/dist/chunk-A56OR5RF.js +0 -184
- package/dist/chunk-A56OR5RF.js.map +0 -1
- package/dist/chunk-AZZLE7XR.js +0 -62
- package/dist/chunk-AZZLE7XR.js.map +0 -1
- package/dist/chunk-B5VXOFMZ.js +0 -266
- package/dist/chunk-B5VXOFMZ.js.map +0 -1
- package/dist/chunk-BYQUGDD3.js +0 -16
- package/dist/chunk-BYQUGDD3.js.map +0 -1
- package/dist/chunk-D736QUGF.js.map +0 -1
- package/dist/chunk-E6GEDSF4.js +0 -307
- package/dist/chunk-E6GEDSF4.js.map +0 -1
- package/dist/chunk-EUF7XOEE.js +0 -223
- package/dist/chunk-EUF7XOEE.js.map +0 -1
- package/dist/chunk-EWJP3YYP.js.map +0 -1
- package/dist/chunk-FV3Z5MBE.js.map +0 -1
- package/dist/chunk-HCEVHFJ7.js +0 -54
- package/dist/chunk-HCEVHFJ7.js.map +0 -1
- package/dist/chunk-I5OV65MS.js.map +0 -1
- package/dist/chunk-J6527VRQ.js.map +0 -1
- package/dist/chunk-JELSZN25.js +0 -47
- package/dist/chunk-JELSZN25.js.map +0 -1
- package/dist/chunk-JER5O7PQ.js +0 -416
- package/dist/chunk-JER5O7PQ.js.map +0 -1
- package/dist/chunk-JGVL3WPL.js +0 -26
- package/dist/chunk-JGVL3WPL.js.map +0 -1
- package/dist/chunk-JP5D6GSL.js +0 -71
- package/dist/chunk-JP5D6GSL.js.map +0 -1
- package/dist/chunk-K575PT4S.js.map +0 -1
- package/dist/chunk-MU6MCIAC.js +0 -15
- package/dist/chunk-MU6MCIAC.js.map +0 -1
- package/dist/chunk-MUUROGIH.js.map +0 -1
- package/dist/chunk-ND3DH6KM.js +0 -88
- package/dist/chunk-ND3DH6KM.js.map +0 -1
- package/dist/chunk-Q2UM7BXU.js.map +0 -1
- package/dist/chunk-S2EGRPCM.js +0 -47
- package/dist/chunk-S2EGRPCM.js.map +0 -1
- package/dist/chunk-SINXE47Y.js +0 -55
- package/dist/chunk-SINXE47Y.js.map +0 -1
- package/dist/chunk-SUST46KO.js +0 -53
- package/dist/chunk-SUST46KO.js.map +0 -1
- package/dist/chunk-TP5UPGLY.js +0 -61
- package/dist/chunk-TP5UPGLY.js.map +0 -1
- package/dist/chunk-UF4MZSLT.js +0 -53
- package/dist/chunk-UF4MZSLT.js.map +0 -1
- package/dist/chunk-UOC2PL46.js +0 -13
- package/dist/chunk-UOC2PL46.js.map +0 -1
- package/dist/chunk-WLGO64WC.js.map +0 -1
- package/dist/chunk-WRAA7GVZ.js +0 -209
- package/dist/chunk-WRAA7GVZ.js.map +0 -1
- package/dist/chunk-ZCL7SCBK.js +0 -685
- package/dist/chunk-ZCL7SCBK.js.map +0 -1
- package/dist/chunk-ZD6PNZBK.js +0 -457
- package/dist/chunk-ZD6PNZBK.js.map +0 -1
- package/dist/chunk-ZF6WDK2D.js +0 -519
- package/dist/chunk-ZF6WDK2D.js.map +0 -1
- package/dist/chunk-ZJ5AOYBH.js +0 -8
- package/dist/chunk-ZJ5AOYBH.js.map +0 -1
- package/dist/chunk-ZVJZ72HY.js.map +0 -1
- package/dist/circuit-breaker/index.d.ts +0 -197
- package/dist/circuit-breaker/index.js +0 -3
- package/dist/circuit-breaker/index.js.map +0 -1
- package/dist/core-Bjc0bS8j.d.ts +0 -326
- package/dist/deadline/index.js +0 -6
- package/dist/deadline/index.js.map +0 -1
- package/dist/debounce/index.js +0 -3
- package/dist/debounce/index.js.map +0 -1
- package/dist/extension/react.d.ts +0 -121
- package/dist/extension/react.js +0 -75
- package/dist/extension/react.js.map +0 -1
- package/dist/extension/subs/index.d.ts +0 -44
- package/dist/extension/subs/index.js +0 -80
- package/dist/extension/subs/index.js.map +0 -1
- package/dist/extension/test-utils.d.ts +0 -128
- package/dist/extension/test-utils.js +0 -277
- package/dist/extension/test-utils.js.map +0 -1
- package/dist/fan-out/index.js +0 -5
- package/dist/fan-out/index.js.map +0 -1
- package/dist/fold-Blbhru48.d.ts +0 -435
- package/dist/graph-CcjWZVrd.d.ts +0 -923
- package/dist/idempotency/adapter.d.ts +0 -62
- package/dist/idempotency/adapter.js +0 -4
- package/dist/idempotency/adapter.js.map +0 -1
- package/dist/idempotent-intake/index.d.ts +0 -187
- package/dist/idempotent-intake/index.js +0 -7
- package/dist/idempotent-intake/index.js.map +0 -1
- package/dist/llm-call/index.d.ts +0 -310
- package/dist/llm-call/index.js +0 -16
- package/dist/llm-call/index.js.map +0 -1
- package/dist/machine-0OmPvsy_.d.ts +0 -804
- package/dist/monitored-run/index.js +0 -10
- package/dist/monitored-run/index.js.map +0 -1
- package/dist/paginated-walk/index.d.ts +0 -234
- package/dist/paginated-walk/index.js +0 -16
- package/dist/paginated-walk/index.js.map +0 -1
- package/dist/paginator/index.js +0 -3
- package/dist/paginator/index.js.map +0 -1
- package/dist/pbt/arbitraries/index.d.ts +0 -135
- package/dist/pbt/arbitraries/index.js +0 -3
- package/dist/pbt/arbitraries/index.js.map +0 -1
- package/dist/pbt/runners/index.d.ts +0 -117
- package/dist/pbt/runners/index.js +0 -5
- package/dist/pbt/runners/index.js.map +0 -1
- package/dist/poller/index.d.ts +0 -351
- package/dist/poller/index.js +0 -115
- package/dist/poller/index.js.map +0 -1
- package/dist/prediction/index.d.ts +0 -130
- package/dist/prediction/index.js +0 -4
- package/dist/prediction/index.js.map +0 -1
- package/dist/protocol-B5YmJr0d.d.ts +0 -45
- package/dist/pure/index.d.ts +0 -2
- package/dist/pure/index.js +0 -4
- package/dist/pure/index.js.map +0 -1
- package/dist/rate-limit/index.d.ts +0 -115
- package/dist/rate-limit/index.js +0 -3
- package/dist/rate-limit/index.js.map +0 -1
- package/dist/reconciler/index.d.ts +0 -192
- package/dist/reconciler/index.js +0 -164
- package/dist/reconciler/index.js.map +0 -1
- package/dist/recorder/index.js +0 -3
- package/dist/recorder/index.js.map +0 -1
- package/dist/reducer-BqyoVyBG.d.ts +0 -447
- package/dist/resilient-call/index.d.ts +0 -319
- package/dist/resilient-call/index.js +0 -14
- package/dist/resilient-call/index.js.map +0 -1
- package/dist/retry-to-success/index.d.ts +0 -109
- package/dist/retry-to-success/index.js +0 -37
- package/dist/retry-to-success/index.js.map +0 -1
- package/dist/run-BVeqJDBF.d.ts +0 -713
- package/dist/runtime-types-Bxc637bp.d.ts +0 -502
- package/dist/saga/index.d.ts +0 -240
- package/dist/saga/index.js +0 -150
- package/dist/saga/index.js.map +0 -1
- package/dist/samples-DCt6nF8H.d.ts +0 -59
- package/dist/snapshot/index.js +0 -5
- package/dist/snapshot/index.js.map +0 -1
- package/dist/subs/index.d.ts +0 -471
- package/dist/subs/index.js +0 -7
- package/dist/subs/index.js.map +0 -1
- package/dist/throttle/index.d.ts +0 -134
- package/dist/throttle/index.js +0 -3
- package/dist/throttle/index.js.map +0 -1
- package/dist/throttled-input/index.js.map +0 -1
- package/dist/token-refresh/index.d.ts +0 -215
- package/dist/token-refresh/index.js +0 -6
- package/dist/token-refresh/index.js.map +0 -1
- package/dist/trace-replay/index.js +0 -6
- package/dist/trace-replay/index.js.map +0 -1
- package/dist/with-deadline/index.d.ts +0 -196
- package/dist/with-deadline/index.js +0 -111
- package/dist/with-deadline/index.js.map +0 -1
- package/dist/with-resilience/index.d.ts +0 -224
- package/dist/with-resilience/index.js +0 -240
- package/dist/with-resilience/index.js.map +0 -1
- package/dist/with-telemetry/index.d.ts +0 -149
- package/dist/with-telemetry/index.js +0 -70
- package/dist/with-telemetry/index.js.map +0 -1
- package/dist/work-queue/adapter.d.ts +0 -83
- package/dist/work-queue/adapter.js +0 -4
- package/dist/work-queue/adapter.js.map +0 -1
- package/dist/work-queue/ops.d.ts +0 -70
- package/dist/work-queue/ops.js +0 -3
- package/dist/work-queue/ops.js.map +0 -1
- package/dist/workflow/index.d.ts +0 -484
- package/dist/workflow/index.js +0 -244
- package/dist/workflow/index.js.map +0 -1
- /package/dist/{cache → paginate}/index.js.map +0 -0
- /package/dist/{chart/inspect → persistence}/index.js.map +0 -0
|
@@ -0,0 +1,998 @@
|
|
|
1
|
+
import { Result } from 'better-result';
|
|
2
|
+
import { P as Port, N as NoCellError, C as Cmd, S as Sub, d as Reducer, A as AnyCmdDef, M as Machine, e as Settled, a as CmdOf, T as Transitions, f as RequirementsOf, g as PortEmitter, O as OkOf, E as ErrOf, U as UpdateForm, h as InterpretDetached } from './core-CTzMJ82M.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
* The host-side provider graph — what satisfies a Cmd's `R` (Requirements)
|
|
7
|
+
* channel.
|
|
8
|
+
*
|
|
9
|
+
* A `Cmd` is journaled data, so it can never carry a provider: a provider is a
|
|
10
|
+
* closure, and a closure does not survive a `Store<S>` round-trip (ADR 0014).
|
|
11
|
+
* The requirement it declares — `R` — is a TYPE, and a type needs no closure.
|
|
12
|
+
* So the graph that SATISFIES it lives one layer out, in the host, where
|
|
13
|
+
* closures are ordinary: `provide({ … })` builds the `ctx` object `run` already
|
|
14
|
+
* takes, acquiring each provider once, in dependency order, and releasing them
|
|
15
|
+
* in reverse when the run ends.
|
|
16
|
+
*
|
|
17
|
+
* The journal never sees any of this. Replay is a fold over Msgs (ADR 0014) and
|
|
18
|
+
* a fold calls no handler, so it calls no `acquire`. The graph is host wiring —
|
|
19
|
+
* hidden, per ADR 0015 — while the State it produced effects over stays visible.
|
|
20
|
+
*
|
|
21
|
+
* The contract is Effect's `Layer` + `Scope`, point for point, because that
|
|
22
|
+
* shape has a decade of production behind it and inventing a fourth one here
|
|
23
|
+
* would only be a fourth one to learn:
|
|
24
|
+
*
|
|
25
|
+
* 1. A provider is `acquire` plus an optional `release`; an `acquire` may depend
|
|
26
|
+
* on other providers.
|
|
27
|
+
* 2. Built once per scope, in dependency order, MEMOIZED — a provider two others
|
|
28
|
+
* depend on is acquired exactly once.
|
|
29
|
+
* 3. Released in reverse acquisition order, exactly once, on every terminal. A
|
|
30
|
+
* `release` that throws does not stop its siblings from running.
|
|
31
|
+
* 4. An `acquire` failure releases whatever was already acquired, in reverse,
|
|
32
|
+
* then surfaces as a typed `ProvideFailedError` (ADR 0011) — never a throw
|
|
33
|
+
* that escapes `run`.
|
|
34
|
+
*
|
|
35
|
+
* A dependency is named with a TOKEN that carries its value type, so `acquire`
|
|
36
|
+
* needs no parameter annotation and a name the tokens do not list is a compile
|
|
37
|
+
* error where it is written. That is Effect's `Context.Tag` — a token carrying
|
|
38
|
+
* name and type together, with the requirement set derived from what the
|
|
39
|
+
* constructor reads (ZIO's `ZLayer` + `ZIO.service[T]` is the same move):
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* const Config = dep<{ url: string }>()("config");
|
|
43
|
+
*
|
|
44
|
+
* const scoped = provide({
|
|
45
|
+
* config: value({ url: "postgres://…" }),
|
|
46
|
+
* db: layer([Config], ({ config }) => connect(config.url), (db) => db.close()),
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Either hand it straight to `run` — which acquires at boot and releases at
|
|
50
|
+
* // `stop()` — or open it yourself when the host wires its own `ctx`.
|
|
51
|
+
* const state = await driveToDone(run(machine, { ctx: scoped }), start, isDone);
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* The string-array form — `layer(["config"], ({ config }: { config: C }) => …)`
|
|
55
|
+
* — is the UNTYPED escape hatch it remains beside. It spells each dependency
|
|
56
|
+
* twice, once in `deps` and once in the annotation, and nothing ties the two
|
|
57
|
+
* together until `provide` compares both against the map. Reach for it where
|
|
58
|
+
* there is no token to hand: a dep name computed rather than written, or a graph
|
|
59
|
+
* assembled against a `ctx` shape declared elsewhere.
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* Brand marking a {@link Provided} graph apart from a hand-built `ctx`. Symbol
|
|
63
|
+
* keyed and module-private, so it reaches no export and no `ctx` object can
|
|
64
|
+
* collide with it by accident.
|
|
65
|
+
*/
|
|
66
|
+
declare const providedBrand: unique symbol;
|
|
67
|
+
/**
|
|
68
|
+
* One node of the graph: an `acquire`, an optional `release`, and the names of
|
|
69
|
+
* the sibling providers `acquire` reads.
|
|
70
|
+
*
|
|
71
|
+
* `D` is the shape `acquire` receives — a record of the resolved values of
|
|
72
|
+
* {@link Provider.deps}. Build one with {@link layer} or {@link value} rather
|
|
73
|
+
* than by hand; the constructors are what keep `deps` and `D` in step.
|
|
74
|
+
*
|
|
75
|
+
* `K` is the dependency NAME set — the keys `deps` may spell. {@link layer}
|
|
76
|
+
* infers it from the literal you pass, and {@link provide} constrains it to the
|
|
77
|
+
* map's own keys, so a misspelled dependency is a compile error at the call site
|
|
78
|
+
* rather than an {@link UnknownProviderError} at `open()`. It defaults to
|
|
79
|
+
* `string` — the untyped reading, for a provider read back off an erased map.
|
|
80
|
+
*
|
|
81
|
+
* MIGRATION: that default is why an ANNOTATION of the two-argument form no
|
|
82
|
+
* longer fits inside {@link provide}. `readonly string[]` is not assignable to
|
|
83
|
+
* `readonly ("config" | "db")[]`, so `const db: Provider<string, D> = …` is
|
|
84
|
+
* rejected — a leaf `Provider<Config>` with `deps: []` included, since the
|
|
85
|
+
* default is what is compared, not the value. Either name the key set,
|
|
86
|
+
* `Provider<string, D, "config" | "db">`, or drop the annotation and let
|
|
87
|
+
* {@link layer} / {@link value} infer `K` from the literal, which is the shape
|
|
88
|
+
* this API is written for.
|
|
89
|
+
*/
|
|
90
|
+
interface Provider<T, D = Record<never, never>, K extends string = string> {
|
|
91
|
+
/** Names of the sibling providers `acquire` reads, resolved before it runs. */
|
|
92
|
+
readonly deps: readonly K[];
|
|
93
|
+
/**
|
|
94
|
+
* Build the value. May be async; may read its declared `deps`.
|
|
95
|
+
*
|
|
96
|
+
* A function-typed PROPERTY, not a method: a method's parameters are
|
|
97
|
+
* bivariant, and bivariance here would silently accept a provider whose deps
|
|
98
|
+
* disagree with the map's — the one check `provide` exists to make.
|
|
99
|
+
*/
|
|
100
|
+
readonly acquire: (deps: D) => T | Promise<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Tear the value down. Optional — a provider with no `release` is a value with
|
|
103
|
+
* no lifetime. May be async; the scope awaits it.
|
|
104
|
+
*
|
|
105
|
+
* A METHOD, unlike `acquire`: its parameter is this provider's OWN value, so
|
|
106
|
+
* there is no sibling to cross-check and the bivariance a method's parameters
|
|
107
|
+
* get is what lets a `Provider<Db, …>` be read through the erased
|
|
108
|
+
* `Provider<unknown, …>` the map's constraint spells.
|
|
109
|
+
*/
|
|
110
|
+
release?(value: T): unknown;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The `ctx` a provider map produces: each key mapped to its provider's value.
|
|
114
|
+
*/
|
|
115
|
+
type ProvidedCtx<M> = {
|
|
116
|
+
[K in keyof M]: M[K] extends Provider<infer T, never, string> ? T : never;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* A provider with no dependencies — {@link layer}'s one-argument form and
|
|
120
|
+
* {@link value}. Its `K` is `never`, so an empty `deps` fits EVERY map: a
|
|
121
|
+
* leaf provider built through those constructors is admissible wherever it is
|
|
122
|
+
* declared, whatever keys the map around it happens to have.
|
|
123
|
+
*
|
|
124
|
+
* It is the CONSTRUCTED form that this holds for. Annotating the same value
|
|
125
|
+
* `Provider<T>` puts `K` back at its `string` default and outside `provide`'s
|
|
126
|
+
* constraint — see the migration note on {@link Provider}.
|
|
127
|
+
*/
|
|
128
|
+
type LeafProvider<T> = Provider<T, Record<never, never>, never>;
|
|
129
|
+
/**
|
|
130
|
+
* A live scope — the `ctx` its graph produced, plus the one call that tears it
|
|
131
|
+
* down. `release` is idempotent: the second call is a no-op, so a host that
|
|
132
|
+
* releases in a `finally` beside a `run` that already released cannot double-free.
|
|
133
|
+
*/
|
|
134
|
+
interface Scope<Ctx> {
|
|
135
|
+
/** The built `ctx`, one field per provider. */
|
|
136
|
+
readonly ctx: Ctx;
|
|
137
|
+
/**
|
|
138
|
+
* Release every acquired provider in reverse acquisition order, exactly once.
|
|
139
|
+
* Each `release` is isolated: a throw is routed to `onReleaseError` and the
|
|
140
|
+
* remaining releases still run. Never rejects.
|
|
141
|
+
*/
|
|
142
|
+
release(): Promise<void>;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Sink for a `release` that threw. A release failure has no caller to reject at
|
|
146
|
+
* — the run is already over — so it is reported, never propagated.
|
|
147
|
+
*/
|
|
148
|
+
type OnReleaseError = (error: unknown, provider: string) => void;
|
|
149
|
+
/**
|
|
150
|
+
* An unopened provider graph. Pass it to `run` as `ctx` (it acquires at boot and
|
|
151
|
+
* releases at `stop()`), or {@link Provided.open} it yourself when the host
|
|
152
|
+
* wires its own `ctx`.
|
|
153
|
+
*/
|
|
154
|
+
interface Provided<Ctx> {
|
|
155
|
+
/** Brand — see the module note. Never assigned by a consumer. */
|
|
156
|
+
readonly [providedBrand]: true;
|
|
157
|
+
/**
|
|
158
|
+
* Acquire the whole graph and return the live {@link Scope}. Rejects with a
|
|
159
|
+
* {@link ProvideFailedError} when an `acquire` fails, having already released
|
|
160
|
+
* everything it had acquired, in reverse.
|
|
161
|
+
*/
|
|
162
|
+
open(onReleaseError?: OnReleaseError): Promise<Scope<Ctx>>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* An `acquire` failed. A typed failure (ADR 0011) rather than the raw throw:
|
|
166
|
+
* `provider` names the node that failed and `cause` carries what it threw, so a
|
|
167
|
+
* host reads which dependency the run could not stand up without matching on a
|
|
168
|
+
* message.
|
|
169
|
+
*
|
|
170
|
+
* By the time this is raised, every provider acquired before it has been
|
|
171
|
+
* released in reverse.
|
|
172
|
+
*/
|
|
173
|
+
declare class ProvideFailedError extends Error {
|
|
174
|
+
readonly _tag: "provide_failed";
|
|
175
|
+
/** The provider key whose `acquire` failed. */
|
|
176
|
+
readonly provider: string;
|
|
177
|
+
constructor(provider: string, cause: unknown);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A provider named a dependency the map has no key for. A contract breach
|
|
181
|
+
* (ADR 0011) — the wiring itself is wrong, so it throws rather than settling.
|
|
182
|
+
*
|
|
183
|
+
* `provide` binds `deps` to `keyof M`, so a map it typechecked can never raise
|
|
184
|
+
* this: the typo is a compile error at the call site instead. What is left is
|
|
185
|
+
* the UNTYPED path — a map cast (`as never`, `as any`), assembled at runtime, or
|
|
186
|
+
* read back through an erased `Provider<unknown, …>` — where there was no key
|
|
187
|
+
* set to check against. The error stays because that path is real, not because
|
|
188
|
+
* the typed one still needs it.
|
|
189
|
+
*/
|
|
190
|
+
declare class UnknownProviderError extends Error {
|
|
191
|
+
readonly _tag: "unknown_provider";
|
|
192
|
+
/** The missing key. */
|
|
193
|
+
readonly provider: string;
|
|
194
|
+
/** The provider that asked for it. */
|
|
195
|
+
readonly requiredBy: string;
|
|
196
|
+
constructor(provider: string, requiredBy: string);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The dependency graph has a cycle, so no acquisition order exists. A contract
|
|
200
|
+
* breach (ADR 0011): the wiring is wrong and no run can fix it.
|
|
201
|
+
*/
|
|
202
|
+
declare class ProviderCycleError extends Error {
|
|
203
|
+
readonly _tag: "provider_cycle";
|
|
204
|
+
/** The cycle, in the order it was walked, closing on its own first key. */
|
|
205
|
+
readonly cycle: readonly string[];
|
|
206
|
+
constructor(cycle: readonly string[]);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Phantom key carrying a {@link DepToken}'s VALUE type. Declared, never
|
|
210
|
+
* assigned: `dep` builds a token whose only runtime field is `name`, and this
|
|
211
|
+
* property exists so the type survives into {@link DepsOf}. Symbol keyed and
|
|
212
|
+
* module-private, so it reaches no export and no object literal can collide
|
|
213
|
+
* with it.
|
|
214
|
+
*
|
|
215
|
+
* Typed `(probe: never) => T`, which makes the token COVARIANT in `T`: a
|
|
216
|
+
* `DepToken<"config", Config>` is readable through the `DepToken<string,
|
|
217
|
+
* unknown>` bound {@link layer}'s tuple is constrained by, while the value type
|
|
218
|
+
* itself is still recovered exactly by {@link DepValue}'s `infer`.
|
|
219
|
+
*/
|
|
220
|
+
declare const depValue: unique symbol;
|
|
221
|
+
/**
|
|
222
|
+
* A typed dependency name — Effect's `Context.Tag`. It carries the dependency's
|
|
223
|
+
* literal NAME and its VALUE type in one value, so {@link layer} derives the
|
|
224
|
+
* whole `acquire` parameter from the tokens and the caller annotates nothing.
|
|
225
|
+
*
|
|
226
|
+
* Build one with {@link dep}; the phantom field is not yours to write.
|
|
227
|
+
*/
|
|
228
|
+
interface DepToken<N extends string = string, T = unknown> {
|
|
229
|
+
/** The provider key this token stands for — the `keyof M` `provide` checks. */
|
|
230
|
+
readonly name: N;
|
|
231
|
+
/** Phantom — see the note on `depValue`. Never present at runtime. */
|
|
232
|
+
readonly [depValue]?: (probe: never) => T;
|
|
233
|
+
}
|
|
234
|
+
/** The value type a {@link DepToken} carries. */
|
|
235
|
+
type DepValue<Token> = Token extends DepToken<string, infer T> ? T : never;
|
|
236
|
+
/**
|
|
237
|
+
* The `acquire` parameter a tuple of {@link DepToken}s describes: one property
|
|
238
|
+
* per token, named by the token and typed with what it carries. This is the
|
|
239
|
+
* derivation that removes the second spelling — `D` is no longer annotated, it
|
|
240
|
+
* falls out of `deps`.
|
|
241
|
+
*/
|
|
242
|
+
type DepsOf<Tokens extends readonly DepToken<string, unknown>[]> = {
|
|
243
|
+
[N in Tokens[number]["name"]]: DepValue<Extract<Tokens[number], {
|
|
244
|
+
name: N;
|
|
245
|
+
}>>;
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Mint a typed dependency token: `dep<Config>()("config")`.
|
|
249
|
+
*
|
|
250
|
+
* CURRIED because TypeScript infers type arguments all-or-nothing — naming `T`
|
|
251
|
+
* in a single call would force `N` to be spelled too, and a spelled `N` is the
|
|
252
|
+
* widening this token exists to prevent. Effect's `Context.Tag("name")<Self,
|
|
253
|
+
* Shape>()` curries for the same reason; this one takes the type first so the
|
|
254
|
+
* name stays inferred from the literal.
|
|
255
|
+
*
|
|
256
|
+
* ```ts
|
|
257
|
+
* const Config = dep<{ url: string }>()("config");
|
|
258
|
+
* const Db = dep<Connection>()("db");
|
|
259
|
+
* const cache = layer([Config, Db], ({ config, db }) => …);
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
declare function dep<T>(): <const N extends string>(name: N) => DepToken<N, T>;
|
|
263
|
+
/**
|
|
264
|
+
* Declare a provider with no dependencies: an `acquire` and an optional
|
|
265
|
+
* `release`.
|
|
266
|
+
*/
|
|
267
|
+
declare function layer<T>(acquire: () => T | Promise<T>, release?: (value: T) => unknown): LeafProvider<T>;
|
|
268
|
+
/**
|
|
269
|
+
* Declare a provider that depends on siblings, naming each one with a
|
|
270
|
+
* {@link DepToken} — the TYPED route, and the one to reach for.
|
|
271
|
+
*
|
|
272
|
+
* `D` is {@link DepsOf} the tuple, so `acquire` takes NO annotation: its
|
|
273
|
+
* parameter is already a record of exactly the tokens' names at exactly the
|
|
274
|
+
* tokens' types. Both halves of a dependency mistake then land at THIS call —
|
|
275
|
+
* destructuring a property the tuple does not name does not compile, and
|
|
276
|
+
* reading one at the wrong type does not either — instead of surfacing inside
|
|
277
|
+
* `provide`'s `M` constraint as a message about the map.
|
|
278
|
+
*
|
|
279
|
+
* ```ts
|
|
280
|
+
* const Config = dep<Config>()("config");
|
|
281
|
+
* const db = layer([Config], ({ config }) => connect(config.url), (c) => c.end());
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* This is Effect's `Context.Tag`, and ZIO's `ZIO.service[T]`: the requirement
|
|
285
|
+
* set is derived from what the constructor reads rather than restated beside it.
|
|
286
|
+
*/
|
|
287
|
+
declare function layer<T, const Tokens extends readonly DepToken<string, unknown>[]>(deps: Tokens, acquire: (deps: DepsOf<Tokens>) => T | Promise<T>, release?: (value: T) => unknown): Provider<T, DepsOf<Tokens>, Tokens[number]["name"]>;
|
|
288
|
+
/**
|
|
289
|
+
* Declare a provider that depends on siblings, naming each one with a STRING —
|
|
290
|
+
* the untyped escape hatch. `deps` names them; `acquire` receives their resolved
|
|
291
|
+
* values as a record, and the annotation you give that parameter is what types
|
|
292
|
+
* `D`.
|
|
293
|
+
*
|
|
294
|
+
* Nothing ties the two spellings together: `layer(["config"], ({ config }: {
|
|
295
|
+
* cfg: C }) => …)` type-checks here and fails later, inside `provide`'s `M`
|
|
296
|
+
* constraint, in the map's vocabulary rather than the typo's. Prefer the token
|
|
297
|
+
* overload above, which derives the annotation instead of restating it; reach
|
|
298
|
+
* for this one where there is no token to hand.
|
|
299
|
+
*
|
|
300
|
+
* The names are inferred as literals, not widened to `string`, so {@link provide}
|
|
301
|
+
* can check them against the map's keys. `const K` is what pins that: without
|
|
302
|
+
* the modifier TypeScript 7 widens `["config"]` to `string[]` here where 5.x
|
|
303
|
+
* kept the literal, and every provider in the map then fails `provide`'s
|
|
304
|
+
* key constraint with "`string` is not assignable to `"config" | …`".
|
|
305
|
+
*/
|
|
306
|
+
declare function layer<T, D, const K extends string>(deps: readonly K[], acquire: (deps: D) => T | Promise<T>, release?: (value: T) => unknown): Provider<T, D, K>;
|
|
307
|
+
/**
|
|
308
|
+
* Lift an already-built value into the graph — a provider with no `acquire` work
|
|
309
|
+
* and no lifetime. The escape hatch for the config object, the clock, the
|
|
310
|
+
* `fetch` you were handed: things a `ctx` carries that were never resources.
|
|
311
|
+
*/
|
|
312
|
+
declare function value<T>(v: T): LeafProvider<T>;
|
|
313
|
+
/**
|
|
314
|
+
* Build an unopened provider graph from a map of providers.
|
|
315
|
+
*
|
|
316
|
+
* The map's own key set is the resulting `ctx`'s shape, and each provider is
|
|
317
|
+
* checked against that shape on BOTH of its ends — so both halves of a wiring
|
|
318
|
+
* mistake are a compile error here, not a surprise at 3 a.m.:
|
|
319
|
+
*
|
|
320
|
+
* - the `acquire` parameter, so a provider that reads `{ config: Config }`
|
|
321
|
+
* beside a `config` provider of some other type does not compile;
|
|
322
|
+
* - the `deps` names, bound to `keyof M`, so `layer(["confg"], …)` does not
|
|
323
|
+
* compile either.
|
|
324
|
+
*
|
|
325
|
+
* Nothing is acquired until the graph is opened — by `run`, at boot, or by
|
|
326
|
+
* {@link Provided.open}.
|
|
327
|
+
*/
|
|
328
|
+
declare function provide<M extends {
|
|
329
|
+
[K in keyof M]: Provider<unknown, ProvidedCtx<M>, Extract<keyof M, string>>;
|
|
330
|
+
}>(map: M): Provided<ProvidedCtx<M>>;
|
|
331
|
+
/** Is this `ctx` argument an unopened provider graph rather than a plain `ctx`? */
|
|
332
|
+
declare function isProvided<Ctx>(candidate: Ctx | Provided<Ctx> | undefined): candidate is Provided<Ctx>;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @demlik/tea runtime interface surface + pure helpers — the public types,
|
|
336
|
+
* interfaces, and construction/composition helpers the runtime (`./run`)
|
|
337
|
+
* implements against: `Store`, the error-sink and supervision contracts, the
|
|
338
|
+
* `RuntimeRef` / `BootingRuntime` / `Runtime` handle hierarchy, `definePort`, the
|
|
339
|
+
* identity-typed constructors `defineMachine` / `asReducer`, and the pure tools
|
|
340
|
+
* `replay` (compose without running) and `tryInterpret` (Railway).
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
declare const ReducerBrand: unique symbol;
|
|
344
|
+
type Branded<T> = T & {
|
|
345
|
+
readonly [ReducerBrand]: true;
|
|
346
|
+
};
|
|
347
|
+
/**
|
|
348
|
+
* Compile-time exhaustiveness assertion for default branches of switches over
|
|
349
|
+
* discriminated unions narrowed by hand (Sub handlers, message-bridge
|
|
350
|
+
* dispatchers, port fanouts) — TS narrows the operand to `never` only if every
|
|
351
|
+
* variant is covered, so adding one produces a compile error at the `absurd(x)`
|
|
352
|
+
* site. Strengthens invariant 7 (identity is explicit).
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* switch (msg.type) {
|
|
356
|
+
* case "a": return ...;
|
|
357
|
+
* case "b": return ...;
|
|
358
|
+
* default: return absurd(msg); // compile error if a "c" is added
|
|
359
|
+
* }
|
|
360
|
+
*/
|
|
361
|
+
declare function absurd(x: never): never;
|
|
362
|
+
declare const noop: <S, M, C extends Cmd>(state: S, _msg: M) => readonly [S, readonly C[]];
|
|
363
|
+
/**
|
|
364
|
+
* Thrown by `definePort` when a name has already been registered in the current
|
|
365
|
+
* process. Symmetric with `SubIdCollisionError` (thrown by `reconcileSubs`) —
|
|
366
|
+
* both mechanize invariant 7 (identity is explicit) at the runtime layer the
|
|
367
|
+
* type system cannot reach (string names compared at runtime).
|
|
368
|
+
*/
|
|
369
|
+
declare class PortNameCollisionError extends Error {
|
|
370
|
+
readonly name = "PortNameCollisionError";
|
|
371
|
+
readonly _tag: "PortNameCollisionError";
|
|
372
|
+
constructor(portName: string);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Thrown by `reconcileSubs` when, within ONE desired subscription set, two subs
|
|
376
|
+
* share an `id` but declare different `type`s — a silent bug class the type
|
|
377
|
+
* system cannot reach (ids are strings compared at runtime). The symmetric twin
|
|
378
|
+
* of `PortNameCollisionError`: both mechanize invariant 7 (identity is explicit)
|
|
379
|
+
* at the runtime layer. Same id across transitions is the no-churn case and does
|
|
380
|
+
* NOT throw; only a within-set type conflict does.
|
|
381
|
+
*/
|
|
382
|
+
declare class SubIdCollisionError extends Error {
|
|
383
|
+
readonly name = "SubIdCollisionError";
|
|
384
|
+
readonly _tag: "SubIdCollisionError";
|
|
385
|
+
constructor(id: string, declaredType: string, conflictingType: string);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Test-only escape hatch — clears the module-level port-name registry so the
|
|
389
|
+
* collision assert in `definePort` doesn't false-positive across vitest's
|
|
390
|
+
* non-isolated runs. Production code MUST NOT call this.
|
|
391
|
+
*
|
|
392
|
+
* @internal test-only
|
|
393
|
+
*/
|
|
394
|
+
declare function __resetPortRegistry(): void;
|
|
395
|
+
/**
|
|
396
|
+
* Which otherwise-unattributable runtime path produced an error. Every fanout is
|
|
397
|
+
* throw-isolated so one bad consumer never strands its siblings, and the
|
|
398
|
+
* isolated throw routes to the `OnError` sink rather than a bare `console.error`.
|
|
399
|
+
*
|
|
400
|
+
* - `"follow-up"` — a follow-up Msg an interpret handler returned rejected when
|
|
401
|
+
* re-dispatched (the original dispatcher already resolved, so no caller).
|
|
402
|
+
* A rejection caused by `stop()`'s own teardown is NOT this phase — see
|
|
403
|
+
* `"discard"`.
|
|
404
|
+
* - `"stop-save"` — the final `store.save(state)` inside `stop()` threw
|
|
405
|
+
* (`stop()` resolves regardless, so without the sink this was silent loss).
|
|
406
|
+
* - `"reduce"` — the pure `update` (reducer) threw synchronously; the configured
|
|
407
|
+
* `Supervision` strategy decides what happens next, but the throw is surfaced
|
|
408
|
+
* here as data first.
|
|
409
|
+
* - `"listener"` — a `runtime.subscribe(...)` listener threw during fanout.
|
|
410
|
+
* - `"observer"` — a `runtime.observe(...)` observer threw during fanout.
|
|
411
|
+
* - `"event"` — the `events` projector or an `on(type, ...)` handler threw.
|
|
412
|
+
* - `"boot"` — an `onBoot` handler threw (boot fanout, or a late registration).
|
|
413
|
+
* - `"port-emit"` — a `subscribePort` listener threw during a port emission.
|
|
414
|
+
* - `"sub-cleanup"` — a subscription's cleanup threw (reconcile-removal or
|
|
415
|
+
* `stop()` teardown).
|
|
416
|
+
* - `"discard"` — work lost to a teardown the host asked for. Two witnesses,
|
|
417
|
+
* both carrying a `RuntimeDiscardNotice`: `stop()` was called while interpret
|
|
418
|
+
* handlers were still awaiting (`RuntimeDiscardedError`), and a Msg that
|
|
419
|
+
* arrived DURING `stop()`'s drain and so could not be delivered
|
|
420
|
+
* (`DispatchDiscardedError`), and teardown work that did not settle inside
|
|
421
|
+
* `disposeTimeoutMs` (`DisposeTimeoutNotice`). The one phase that is a
|
|
422
|
+
* LIFECYCLE report rather than a failure: legal, merely lossy.
|
|
423
|
+
* - `"identity-drop"` — the `Identity` filter dropped a message addressed to a
|
|
424
|
+
* different instance (`IdentityDropNotice`). Its own phase rather than
|
|
425
|
+
* `"discard"`: the loss is the FILTER WORKING, not a teardown, and a host
|
|
426
|
+
* routing it (a metric, a 409 back to the caller) wants it apart from
|
|
427
|
+
* unmount-time noise. Warn-only, like every `RuntimeDiscardNotice`.
|
|
428
|
+
* - `"provide"` — a `provide({ … })` graph handed to `run` as `ctx`. Two
|
|
429
|
+
* witnesses: an `acquire` failed at boot (a `ProvideFailedError`, ALSO the
|
|
430
|
+
* rejection of `ready`, so this report is the copy a sink gets rather than the
|
|
431
|
+
* only route out), and a `release` threw during `stop()`, which carries
|
|
432
|
+
* `context.provider` and has no other route out at all — the run is over.
|
|
433
|
+
*
|
|
434
|
+
* The phase never decides fatality — the ERROR CLASS does (`RuntimeDiscardNotice`
|
|
435
|
+
* warns, everything else rethrows). A phase is attached by the report site, so a
|
|
436
|
+
* consumer sink that throws while handling a `"discard"` report inherits that
|
|
437
|
+
* phase; keying the warn-only path on it would make the sink's own defect vanish.
|
|
438
|
+
*/
|
|
439
|
+
type RuntimeErrorPhase = "follow-up" | "stop-save" | "reduce" | "listener" | "observer" | "event" | "boot" | "port-emit" | "sub-cleanup" | "discard" | "identity-drop" | "provide";
|
|
440
|
+
/** Context handed to an `OnError` sink alongside the error itself. */
|
|
441
|
+
interface RuntimeErrorContext {
|
|
442
|
+
readonly phase: RuntimeErrorPhase;
|
|
443
|
+
/**
|
|
444
|
+
* The provider key a `"provide"` report is about — set when a `release` threw
|
|
445
|
+
* (the run is over; the throw has nowhere else to go). Absent on the acquire
|
|
446
|
+
* report, which also rejects `ready` with a `ProvideFailedError` that names it.
|
|
447
|
+
*/
|
|
448
|
+
readonly provider?: string;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Sink for runtime failures that have no caller to reject at. Configured via
|
|
452
|
+
* `run(machine, { onError })`. Should be total — a throw inside the sink is
|
|
453
|
+
* itself surfaced via the default sink, so it can never re-introduce a silent
|
|
454
|
+
* failure.
|
|
455
|
+
*/
|
|
456
|
+
type OnError = (error: unknown, context: RuntimeErrorContext) => void;
|
|
457
|
+
/** The three declared reducer-throw supervision strategies. */
|
|
458
|
+
type SupervisionStrategy = "stop" | "escalate" | "restart";
|
|
459
|
+
/**
|
|
460
|
+
* Declared supervision policy for a reducer (`update`) throw, at
|
|
461
|
+
* `run(machine, { supervision })`. The bare-string shorthands (`"stop"` /
|
|
462
|
+
* `"escalate"`) are accepted for the two strategies that need no host data;
|
|
463
|
+
* `restart` MUST be the object form because it carries the `rehydrate` callback,
|
|
464
|
+
* which MUST return a valid `S` synchronously (the reducer is synchronous, so
|
|
465
|
+
* recovery is too — no suspension across the single-writer slot).
|
|
466
|
+
*/
|
|
467
|
+
type Supervision<S, M extends {
|
|
468
|
+
type: string;
|
|
469
|
+
}> = "stop" | "escalate" | {
|
|
470
|
+
readonly strategy: "stop";
|
|
471
|
+
} | {
|
|
472
|
+
readonly strategy: "escalate";
|
|
473
|
+
} | {
|
|
474
|
+
readonly strategy: "restart";
|
|
475
|
+
/**
|
|
476
|
+
* Host-provided rehydration to last-known-good state. Invoked when the
|
|
477
|
+
* reducer throws; its return value becomes the new state and the transition
|
|
478
|
+
* continues from there. Receives the pre-throw `state`, the `msg` that
|
|
479
|
+
* triggered the throw, and the thrown `error` so the host can route by
|
|
480
|
+
* cause.
|
|
481
|
+
*/
|
|
482
|
+
readonly rehydrate: (state: S, msg: M, error: unknown) => S;
|
|
483
|
+
};
|
|
484
|
+
/**
|
|
485
|
+
* Raised by `idle()` when the quiescence wait hits its iteration cap without the
|
|
486
|
+
* dispatch tail stabilizing — `idle()` REJECTS rather than silently resolving,
|
|
487
|
+
* so a livelocking machine surfaces instead of masquerading as quiescent.
|
|
488
|
+
* Mechanizes invariant 6 at the runtime layer, the role `PortNameCollisionError`
|
|
489
|
+
* plays for invariant 7.
|
|
490
|
+
*/
|
|
491
|
+
declare class QuiescenceTimeoutError extends Error {
|
|
492
|
+
readonly iterations: number;
|
|
493
|
+
readonly name = "QuiescenceTimeoutError";
|
|
494
|
+
readonly _tag: "QuiescenceTimeoutError";
|
|
495
|
+
constructor(iterations: number);
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Raised by `driveToDone` when the drive ends on a State its `failed` predicate
|
|
499
|
+
* marks as a failure. Carries that final State so the caller reads the failure
|
|
500
|
+
* off the Model the machine owns — never off a message string. A rejection, not
|
|
501
|
+
* a resolve, so a failed run cannot be mistaken for a finished one at the
|
|
502
|
+
* caller boundary (invariant 6).
|
|
503
|
+
*/
|
|
504
|
+
declare class DriveFailedError<S> extends Error {
|
|
505
|
+
readonly state: S;
|
|
506
|
+
readonly name = "DriveFailedError";
|
|
507
|
+
readonly _tag: "DriveFailedError";
|
|
508
|
+
constructor(state: S);
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Raised by `driveToDone` when `start`'s follow-up chain quiesces on a State
|
|
512
|
+
* that is neither terminal nor `failed` AND nothing in the runtime can still
|
|
513
|
+
* transition it — no live Sub (manual or dep-keyed), no in-flight Cmd. Waiting
|
|
514
|
+
* past that point is not the Sub-driven contract, it is a leak: no transition is
|
|
515
|
+
* coming, so the drive would hang with the runtime alive and `stop()` never
|
|
516
|
+
* reached. The rejection carries the stalled State on `error.state`, sibling to
|
|
517
|
+
* `DriveFailedError`, so the caller reads where the machine parked off the
|
|
518
|
+
* Model rather than off a message string (invariant 6).
|
|
519
|
+
*
|
|
520
|
+
* A machine that CAN still move — a Sub that will deliver the terminal Msg after
|
|
521
|
+
* the dispatch quiesces — is not stalled and the drive keeps waiting; this names
|
|
522
|
+
* only the case where the runtime itself can prove nothing is coming.
|
|
523
|
+
*/
|
|
524
|
+
declare class DriveStalledError<S> extends Error {
|
|
525
|
+
readonly state: S;
|
|
526
|
+
readonly name = "DriveStalledError";
|
|
527
|
+
readonly _tag: "DriveStalledError";
|
|
528
|
+
constructor(state: S);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Base of the LOSSY-BUT-LEGAL teardown facts: work the host discarded by letting
|
|
532
|
+
* go of a runtime that still had something outstanding. Reported under
|
|
533
|
+
* `phase: "discard"`, never raised.
|
|
534
|
+
*
|
|
535
|
+
* It exists so "is this fatal?" has ONE definition — `error instanceof
|
|
536
|
+
* RuntimeDiscardNotice` — that the default sink can ask about any error from any
|
|
537
|
+
* site. The phase cannot answer it: a report site attaches the phase, so a
|
|
538
|
+
* consumer sink that throws while handling a `"discard"` report carries that
|
|
539
|
+
* phase into the sink-failure path, and a phase-keyed warn branch would swallow
|
|
540
|
+
* the sink's own defect. Sub-classing is how a new teardown fact opts into the
|
|
541
|
+
* warn-only treatment; nothing else can.
|
|
542
|
+
*/
|
|
543
|
+
declare abstract class RuntimeDiscardNotice extends Error {
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Reported to the `OnError` sink under `phase: "discard"` when `stop()` is
|
|
547
|
+
* called while `interpret` handlers are still awaiting. The host is dropping
|
|
548
|
+
* its only handle on that work: `stop()` drains the tail, but the listeners,
|
|
549
|
+
* observers and event handlers that would have consumed the resulting
|
|
550
|
+
* transitions are gone, so the Cmds' results reach nobody.
|
|
551
|
+
*
|
|
552
|
+
* The motivating shape is `@demlik/tea/react`'s `useMachine`, which memoizes on
|
|
553
|
+
* `[machine, ctx, store]` — a ctx re-derived mid-flight replaces the runtime,
|
|
554
|
+
* and the in-flight mutation's response arrives for a runtime the UI no longer
|
|
555
|
+
* renders, silently rewinding the visible state. Never a throw: tearing a
|
|
556
|
+
* runtime down mid-flight is legal (a navigation does it every time), so this
|
|
557
|
+
* is surfaced as data, not raised. Mechanizes invariant 6 (no silent failures)
|
|
558
|
+
* at the teardown seam, the role `QuiescenceTimeoutError` plays for `idle()`.
|
|
559
|
+
*/
|
|
560
|
+
declare class RuntimeDiscardedError extends RuntimeDiscardNotice {
|
|
561
|
+
readonly pendingCmds: number;
|
|
562
|
+
readonly name = "RuntimeDiscardedError";
|
|
563
|
+
readonly _tag: "RuntimeDiscardedError";
|
|
564
|
+
constructor(pendingCmds: number);
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Reported to the `OnError` sink under `phase: "identity-drop"` when the
|
|
568
|
+
* `Identity` filter drops a message addressed to a different instance.
|
|
569
|
+
*
|
|
570
|
+
* The drop itself is the feature — it is what lets a reducer stop repeating
|
|
571
|
+
* `if (msg.runId !== state.runId) return`. What was missing is that it was
|
|
572
|
+
* INVISIBLE: the dispatch resolved exactly like an applied one, so a reusable
|
|
573
|
+
* Durable Object serving run A and then run B lost every run-B message and
|
|
574
|
+
* reported success to each caller. The comment claiming "the one observable
|
|
575
|
+
* enforcement point" described this notice before it existed.
|
|
576
|
+
*
|
|
577
|
+
* Never fatal (`RuntimeDiscardNotice`): a mis-addressed message is a normal
|
|
578
|
+
* consequence of instance reuse, not a defect. A host that wants to act on it
|
|
579
|
+
* — a metric, a 409 to the caller, a re-route — reads `phase: "identity-drop"`
|
|
580
|
+
* in its own sink.
|
|
581
|
+
*/
|
|
582
|
+
declare class IdentityDropNotice extends RuntimeDiscardNotice {
|
|
583
|
+
readonly msgType: string;
|
|
584
|
+
readonly name = "IdentityDropNotice";
|
|
585
|
+
readonly _tag: "IdentityDropNotice";
|
|
586
|
+
constructor(msgType: string);
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Reported to the `OnError` sink under `phase: "discard"` when `stop()`'s wait
|
|
590
|
+
* for async teardown work hits `disposeTimeoutMs`.
|
|
591
|
+
*
|
|
592
|
+
* `stop()` awaits the disposals it started so `await runtime.stop()` can mean
|
|
593
|
+
* "safe to evict". A `release` that never settles must not turn that guarantee
|
|
594
|
+
* into a host that never shuts down, so the wait is bounded and expiry is
|
|
595
|
+
* REPORTED rather than silently tolerated — the resource is genuinely still
|
|
596
|
+
* open at that point, and only the host can decide what that costs.
|
|
597
|
+
*/
|
|
598
|
+
declare class DisposeTimeoutNotice extends RuntimeDiscardNotice {
|
|
599
|
+
readonly pendingDisposals: number;
|
|
600
|
+
readonly timeoutMs: number;
|
|
601
|
+
readonly name = "DisposeTimeoutNotice";
|
|
602
|
+
readonly _tag: "DisposeTimeoutNotice";
|
|
603
|
+
constructor(pendingDisposals: number, timeoutMs: number);
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* The rejection of a dispatch that arrived DURING `stop()`'s drain — an in-flight
|
|
607
|
+
* interpret handler's follow-up Msg, a detached handler's terminal Msg, or a Sub
|
|
608
|
+
* that is still live because subs are torn down only after the drain. The stop
|
|
609
|
+
* barrier is absolute (the Msg is refused, never folded), so this names the loss.
|
|
610
|
+
*
|
|
611
|
+
* It is the SECOND witness of `RuntimeDiscardedError`'s fact, and it is why the
|
|
612
|
+
* drain window is a distinct runtime state rather than a plain `stopped` flag:
|
|
613
|
+
* a Msg refused inside the window was discarded BY the teardown, while the same
|
|
614
|
+
* refusal after `stop()` has returned is a consumer dispatching into a runtime it
|
|
615
|
+
* already retired — a real error, and still loud (`phase: "follow-up"`, or the
|
|
616
|
+
* caller's own rejection). The distinction is the state at refusal time, never
|
|
617
|
+
* the message text.
|
|
618
|
+
*/
|
|
619
|
+
declare class DispatchDiscardedError extends RuntimeDiscardNotice {
|
|
620
|
+
readonly msgType: string;
|
|
621
|
+
readonly name = "DispatchDiscardedError";
|
|
622
|
+
readonly _tag: "DispatchDiscardedError";
|
|
623
|
+
constructor(msgType: string);
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Define a typed port. `name` is metadata (devtools / debug logs); port identity
|
|
627
|
+
* is by reference. Each definePort call must use a unique `name` — a second call
|
|
628
|
+
* with the same name throws `PortNameCollisionError`. Use ports for "data leaving
|
|
629
|
+
* the runtime selectively" (cursor announcements, DOM-mutation broadcasts,
|
|
630
|
+
* telemetry) that should NOT be folded into State. Strengthens invariant 7.
|
|
631
|
+
*/
|
|
632
|
+
declare function definePort<T>(name: string): Port<T>;
|
|
633
|
+
interface Store<S> {
|
|
634
|
+
load(): Promise<unknown>;
|
|
635
|
+
save(state: S): Promise<void>;
|
|
636
|
+
migrate(raw: unknown): S | null;
|
|
637
|
+
}
|
|
638
|
+
interface FencedRead {
|
|
639
|
+
/** Raw bytes at the key, the `Store.load` contract unchanged. */
|
|
640
|
+
readonly raw: unknown;
|
|
641
|
+
/** The version those bytes were written at. A never-written key reads `0`. */
|
|
642
|
+
readonly version: number;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* A `Store<S>` that can refuse a second live writer.
|
|
646
|
+
*
|
|
647
|
+
* `run` fences automatically when it is handed one of these: it reads the
|
|
648
|
+
* version at boot and compare-and-swaps on every save, so a second process that
|
|
649
|
+
* started from the same version is refused at its first write with a
|
|
650
|
+
* {@link StoreConflictError}. Hand `run` a plain `Store<S>` and it stays exactly
|
|
651
|
+
* as it was — the last writer wins, and single-writer is your precondition to
|
|
652
|
+
* keep (see `docs/explanation/durability-model.md`).
|
|
653
|
+
*
|
|
654
|
+
* Fencing is opt-in at 0.x: every shipped factory that can fence takes an
|
|
655
|
+
* explicit `{ fenced: true }` and returns this type; the unfenced call is
|
|
656
|
+
* byte-for-byte the old behaviour.
|
|
657
|
+
*/
|
|
658
|
+
interface FencedStore<S> extends Store<S> {
|
|
659
|
+
/** Discriminant — the one thing {@link isFencedStore} reads. */
|
|
660
|
+
readonly fenced: true;
|
|
661
|
+
/** `load`, plus the version those bytes carry. */
|
|
662
|
+
loadFenced(): Promise<FencedRead>;
|
|
663
|
+
/**
|
|
664
|
+
* Compare-and-swap save. Writes `state` only if the stored version is still
|
|
665
|
+
* `expectedVersion`, and resolves with the NEW version to swap on next time.
|
|
666
|
+
* Throws {@link StoreConflictError} when it is not.
|
|
667
|
+
*/
|
|
668
|
+
saveFenced(state: S, expectedVersion: number): Promise<number>;
|
|
669
|
+
}
|
|
670
|
+
/** Narrow a `Store<S>` to a {@link FencedStore} — what `run` uses to decide. */
|
|
671
|
+
declare function isFencedStore<S>(store: Store<S>): store is FencedStore<S>;
|
|
672
|
+
/**
|
|
673
|
+
* Thrown when a fenced save finds a version other than the one it expected —
|
|
674
|
+
* another live writer has this run.
|
|
675
|
+
*
|
|
676
|
+
* A throw, not a settled failure Msg (ADR 0017, following ADR 0011): a second
|
|
677
|
+
* claimant is a contract breach of the single-writer promise, not a state this
|
|
678
|
+
* run can fold and continue from. There is no correct way for the loser to
|
|
679
|
+
* carry on, so it stops where it stands.
|
|
680
|
+
*/
|
|
681
|
+
declare class StoreConflictError extends Error {
|
|
682
|
+
readonly expectedVersion: number;
|
|
683
|
+
readonly actualVersion: number;
|
|
684
|
+
readonly name = "StoreConflictError";
|
|
685
|
+
readonly _tag: "store_conflict";
|
|
686
|
+
constructor(expectedVersion: number, actualVersion: number);
|
|
687
|
+
}
|
|
688
|
+
interface Schema<S> {
|
|
689
|
+
safeParse(raw: unknown): {
|
|
690
|
+
success: true;
|
|
691
|
+
data: S;
|
|
692
|
+
} | {
|
|
693
|
+
success: false;
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Build a `Store.migrate` from a schema (job 1) and an optional thin `upcast`
|
|
698
|
+
* (job 2). `upcast` maps a recognized-but-OLD raw shape forward into the shape
|
|
699
|
+
* the schema validates; it defaults to identity (no version migration yet).
|
|
700
|
+
*
|
|
701
|
+
* Never throws — a shape the schema rejects returns `null`, the substrate's
|
|
702
|
+
* fresh-boot path, per the `Store.migrate` contract. An `upcast` that itself
|
|
703
|
+
* throws on a corrupt blob is caught and collapses to `null` (same posture).
|
|
704
|
+
*/
|
|
705
|
+
declare function schemaMigrate<S>(schema: Schema<S>, upcast?: (raw: unknown) => unknown): (raw: unknown) => S | null;
|
|
706
|
+
type DispatchSettle = "quiescent" | "once";
|
|
707
|
+
interface RuntimeRef<M extends {
|
|
708
|
+
type: string;
|
|
709
|
+
}> {
|
|
710
|
+
/**
|
|
711
|
+
* Put a Msg in the runtime's inbox and resolve once processed. Runs to
|
|
712
|
+
* QUIESCENCE by default: settles only after the dispatched Msg AND every
|
|
713
|
+
* transitive interpret follow-up has drained. Pass `{ settle: "once" }` (or
|
|
714
|
+
* call `dispatchOnce`) for the single-step case.
|
|
715
|
+
*
|
|
716
|
+
* Rejection ordering: the ONE dispatched transition's own failure surfaces
|
|
717
|
+
* first, here. If it succeeds but the follow-up chain never stabilizes, the
|
|
718
|
+
* quiescent drain rejects with `QuiescenceTimeoutError`. Follow-up Msg
|
|
719
|
+
* rejections themselves route to the `onError` sink, never here.
|
|
720
|
+
*/
|
|
721
|
+
dispatch(msg: M, opts?: {
|
|
722
|
+
readonly settle?: DispatchSettle;
|
|
723
|
+
}): Promise<void>;
|
|
724
|
+
/**
|
|
725
|
+
* Dispatch `msg` and resolve after exactly ONE transition's effects settle,
|
|
726
|
+
* WITHOUT draining the follow-up chain — equivalent to
|
|
727
|
+
* `dispatch(msg, { settle: "once" })`. Prefer plain `dispatch` unless you will
|
|
728
|
+
* `await runtime.idle()` yourself; the un-awaited follow-up chain is the
|
|
729
|
+
* footgun the quiescent default removed.
|
|
730
|
+
*/
|
|
731
|
+
dispatchOnce(msg: M): Promise<void>;
|
|
732
|
+
}
|
|
733
|
+
interface BootingRuntime<S, M extends {
|
|
734
|
+
type: string;
|
|
735
|
+
}, E extends {
|
|
736
|
+
type: string;
|
|
737
|
+
} = never> extends RuntimeRef<M> {
|
|
738
|
+
dispatch(msg: M, opts?: {
|
|
739
|
+
readonly settle?: DispatchSettle;
|
|
740
|
+
}): Promise<void>;
|
|
741
|
+
dispatchOnce(msg: M): Promise<void>;
|
|
742
|
+
/**
|
|
743
|
+
* Register a zero-arg change notifier, fired for every applied transition
|
|
744
|
+
* with the fold's State already committed — `getState()` inside the listener
|
|
745
|
+
* reads it, not the State before. A `dispatch` issued from the listener is
|
|
746
|
+
* SCHEDULED onto the serial tail behind the fold that fired it, never folded
|
|
747
|
+
* re-entrantly and never discarded, so it needs no `setTimeout(fn, 0)`
|
|
748
|
+
* deferral; two listeners issuing in order fold in that order.
|
|
749
|
+
*/
|
|
750
|
+
subscribe(listener: () => void): () => void;
|
|
751
|
+
/**
|
|
752
|
+
* Register a `(msg, state)` trace hook, fired for every applied transition
|
|
753
|
+
* with the fold's committed State. A `dispatch` issued from the observer is
|
|
754
|
+
* SCHEDULED onto the serial tail behind the fold that fired it, never folded
|
|
755
|
+
* re-entrantly and never discarded, so it needs no `setTimeout(fn, 0)`
|
|
756
|
+
* deferral; two listeners issuing in order fold in that order.
|
|
757
|
+
*/
|
|
758
|
+
observe(observer: (msg: M, state: S) => void): () => void;
|
|
759
|
+
/**
|
|
760
|
+
* Subscribe to the INITIAL State — the boot transition. Fires exactly once:
|
|
761
|
+
* immediately if boot already completed (so a late subscriber never misses
|
|
762
|
+
* it), otherwise on the boot fanout. Returns a cleanup (a no-op once fired).
|
|
763
|
+
*/
|
|
764
|
+
onBoot(handler: (state: S) => void): () => void;
|
|
765
|
+
/**
|
|
766
|
+
* Subscribe to a SEMANTIC event of `type`. The handler receives exactly the
|
|
767
|
+
* `E` member whose `type` matches `K`, so a consumer never touches another
|
|
768
|
+
* event's shape and never references the machine's PRIVATE Msg names. Multiple
|
|
769
|
+
* handlers per type; fanout is synchronous and throw-isolated. Fires only when
|
|
770
|
+
* the machine's `events` projector (wired on `run`) emits that type.
|
|
771
|
+
*/
|
|
772
|
+
on<K extends E["type"]>(type: K, handler: (event: Extract<E, {
|
|
773
|
+
type: K;
|
|
774
|
+
}>) => void): () => void;
|
|
775
|
+
/**
|
|
776
|
+
* Subscribe to a typed Port. Multiple listeners per port; fanout is synchronous
|
|
777
|
+
* and isolated. Ports are for "data leaving the runtime selectively" (see
|
|
778
|
+
* `definePort`) — distinct from `observe` (every transition) and State.
|
|
779
|
+
*/
|
|
780
|
+
subscribePort<T>(port: Port<T>, listener: (value: T) => void): () => void;
|
|
781
|
+
/**
|
|
782
|
+
* Emit a value on a Port from OUTSIDE an interpret handler — same synchronous
|
|
783
|
+
* fanout as `ctx.emit`. The canonical use is `observe`-driven emission (one
|
|
784
|
+
* runtime publishing a state-derived signal another subscribes to via
|
|
785
|
+
* `subscribePort`) without spawning a "tell the outside world" Cmd per
|
|
786
|
+
* transition.
|
|
787
|
+
*/
|
|
788
|
+
emitPort<T>(port: Port<T>, value: T): void;
|
|
789
|
+
/**
|
|
790
|
+
* Resolves to the booted `Runtime<S, M>` after boot completes (or rejects with
|
|
791
|
+
* the boot error). This is the ONLY way to obtain a `Runtime` — and a
|
|
792
|
+
* `Runtime` is the only handle whose `getState()` is total. Awaiting `ready` is
|
|
793
|
+
* the single gate between "boot in flight" and "State exists":
|
|
794
|
+
*
|
|
795
|
+
* ```ts
|
|
796
|
+
* const runtime = await run(machine, opts).ready;
|
|
797
|
+
* runtime.getState(); // total — never throws-before-boot
|
|
798
|
+
* ```
|
|
799
|
+
*
|
|
800
|
+
* Idempotent — the same settled promise, resolving to the same `Runtime`, comes
|
|
801
|
+
* back on every read. Expresses canon §2.3 (boot is a named, awaitable moment).
|
|
802
|
+
*/
|
|
803
|
+
ready: Promise<Runtime<S, M, E>>;
|
|
804
|
+
stop(): Promise<void>;
|
|
805
|
+
}
|
|
806
|
+
interface Runtime<S, M extends {
|
|
807
|
+
type: string;
|
|
808
|
+
}, E extends {
|
|
809
|
+
type: string;
|
|
810
|
+
} = never> extends BootingRuntime<S, M, E> {
|
|
811
|
+
/**
|
|
812
|
+
* The current State. TOTAL — never throws. Obtaining a `Runtime` requires
|
|
813
|
+
* awaiting `ready`, which only resolves AFTER boot has run `init` and set the
|
|
814
|
+
* initial State.
|
|
815
|
+
*/
|
|
816
|
+
getState(): S;
|
|
817
|
+
/** Resolves to this same `Runtime` once boot completes. Idempotent. */
|
|
818
|
+
ready: Promise<Runtime<S, M, E>>;
|
|
819
|
+
/**
|
|
820
|
+
* Resolves once the runtime has reached QUIESCENCE — every dispatched Msg AND
|
|
821
|
+
* every transitive interpret follow-up has been processed, with no further step
|
|
822
|
+
* pending on the tail. Since plain `dispatch` already runs to quiescence, this
|
|
823
|
+
* is mainly for follow-ups left by a `dispatchOnce` single step, or a chain
|
|
824
|
+
* kicked off by a Sub / boot `init` cmds with no `dispatch` to await.
|
|
825
|
+
*
|
|
826
|
+
* Idempotent and re-entrant-safe. Tail rejections are NOT surfaced here (a
|
|
827
|
+
* failing dispatch surfaces on its OWN promise; follow-up rejections route to
|
|
828
|
+
* `onError`). The one rejection `idle()` produces is `QuiescenceTimeoutError`
|
|
829
|
+
* on hitting the iteration cap — so a livelock stays distinguishable from a
|
|
830
|
+
* genuine quiesce (invariant 6). A poll is still correct when waiting on an
|
|
831
|
+
* EXTERNAL event the runtime cannot enqueue itself.
|
|
832
|
+
*/
|
|
833
|
+
idle(): Promise<void>;
|
|
834
|
+
/**
|
|
835
|
+
* The terminal State of the run, or `undefined` while in flight — "terminal"
|
|
836
|
+
* per the `terminal` predicate passed to `run()` (no predicate → never
|
|
837
|
+
* terminal → always `undefined`). The first-class result read: the run's
|
|
838
|
+
* product off the State the machine already owns, NOT scraped off the `observe`
|
|
839
|
+
* firehose by matching an internal Msg name. Total — never throws.
|
|
840
|
+
*/
|
|
841
|
+
result(): S | undefined;
|
|
842
|
+
/**
|
|
843
|
+
* Resolves with the terminal State the first time the run reaches one (per the
|
|
844
|
+
* `terminal` predicate). If ALREADY terminal, resolves immediately; otherwise
|
|
845
|
+
* on the transition that first makes `terminal` hold. The awaitable companion
|
|
846
|
+
* to `result()`. With no predicate this never resolves. Idempotent and
|
|
847
|
+
* multi-caller safe.
|
|
848
|
+
*/
|
|
849
|
+
done(): Promise<S>;
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* The `types` option: the slots of a machine's shape that no value in the
|
|
853
|
+
* object can imply, declared once as phantom values (`{} as Model`).
|
|
854
|
+
*
|
|
855
|
+
* `model` and `msg` are always named. `cmd` is named only by a machine whose
|
|
856
|
+
* Cmds are hand-written records rather than `Cmd.define` constructors listed
|
|
857
|
+
* under `cmds`; `sub` only by one whose Sub union `subscriptions` does not
|
|
858
|
+
* imply; `ctx` only by one whose handlers read a `Ctx` slice no Cmd's
|
|
859
|
+
* `requirements` declares.
|
|
860
|
+
*/
|
|
861
|
+
type MachineTypes<S, M extends {
|
|
862
|
+
type: string;
|
|
863
|
+
}, C extends Cmd, U extends Sub, Ctx> = {
|
|
864
|
+
readonly model: S;
|
|
865
|
+
readonly msg: M;
|
|
866
|
+
readonly cmd?: C;
|
|
867
|
+
readonly sub?: U;
|
|
868
|
+
readonly ctx?: Ctx;
|
|
869
|
+
};
|
|
870
|
+
declare function defineMachine<S, M extends {
|
|
871
|
+
type: string;
|
|
872
|
+
}, D extends AnyCmdDef, U extends Sub = Sub<never>, Ctx = unknown>(m: NoInfer<Omit<Machine<S, M | Settled<D>, CmdOf<D>, U, Ctx>, "cmds">> & {
|
|
873
|
+
readonly types: MachineTypes<S, M, Cmd<never>, U, Ctx>;
|
|
874
|
+
readonly cmds: readonly D[];
|
|
875
|
+
}): Machine<S, M | Settled<D>, CmdOf<D>, U, Ctx>;
|
|
876
|
+
declare function defineMachine<S, M extends {
|
|
877
|
+
type: string;
|
|
878
|
+
}, C extends Cmd = Cmd<never>, U extends Sub = Sub<never>, Ctx = unknown>(m: NoInfer<Machine<S, M, C, U, Ctx>> & {
|
|
879
|
+
readonly types: MachineTypes<S, M, C, U, Ctx>;
|
|
880
|
+
}): Machine<S, M, C, U, Ctx>;
|
|
881
|
+
declare function defineMachine<S, M extends {
|
|
882
|
+
type: string;
|
|
883
|
+
}, D extends AnyCmdDef, U extends Sub, Ctx>(m: Omit<Machine<S, M | Settled<D>, CmdOf<D>, U, Ctx>, "update" | "cmds"> & {
|
|
884
|
+
readonly cmds: readonly D[];
|
|
885
|
+
update: [S] extends [{
|
|
886
|
+
type: string;
|
|
887
|
+
}] ? Transitions<S, M | Settled<D>, CmdOf<D>> : never;
|
|
888
|
+
}): Machine<S, M | Settled<D>, CmdOf<D>, U, Ctx>;
|
|
889
|
+
declare function defineMachine<S, M extends {
|
|
890
|
+
type: string;
|
|
891
|
+
}, D extends AnyCmdDef, U extends Sub, Ctx>(m: Omit<Machine<S, M | Settled<D>, CmdOf<D>, U, Ctx>, "update" | "cmds"> & {
|
|
892
|
+
readonly cmds: readonly D[];
|
|
893
|
+
update: Reducer<S, M | Settled<D>, CmdOf<D>>;
|
|
894
|
+
}): Machine<S, M | Settled<D>, CmdOf<D>, U, Ctx>;
|
|
895
|
+
declare function defineMachine<S, M extends {
|
|
896
|
+
type: string;
|
|
897
|
+
}, C extends Cmd, U extends Sub, Ctx>(m: Omit<Machine<S, M, C, U, Ctx>, "update"> & {
|
|
898
|
+
update: [S] extends [{
|
|
899
|
+
type: string;
|
|
900
|
+
}] ? Transitions<S, M, C> : never;
|
|
901
|
+
}): Machine<S, M, C, U, Ctx>;
|
|
902
|
+
declare function defineMachine<S, M extends {
|
|
903
|
+
type: string;
|
|
904
|
+
}, C extends Cmd, U extends Sub, Ctx>(m: Omit<Machine<S, M, C, U, Ctx>, "update"> & {
|
|
905
|
+
update: Reducer<S, M, C>;
|
|
906
|
+
}): Machine<S, M, C, U, Ctx>;
|
|
907
|
+
declare function asReducer<S, M extends {
|
|
908
|
+
type: string;
|
|
909
|
+
}, C extends Cmd>(reducer: Reducer<S, M, C>): Branded<Reducer<S, M, C>>;
|
|
910
|
+
type CtxArg<Ctx> = [Record<never, never>] extends [Ctx] ? {
|
|
911
|
+
ctx?: Ctx;
|
|
912
|
+
} : {
|
|
913
|
+
ctx: Ctx;
|
|
914
|
+
};
|
|
915
|
+
/**
|
|
916
|
+
* `run`'s `ctx` field: the `Ctx` object, or a `provide` graph that builds one.
|
|
917
|
+
* Conditionally optional exactly like {@link CtxArg} — a machine that reads
|
|
918
|
+
* nothing from `ctx` may omit it.
|
|
919
|
+
*/
|
|
920
|
+
type ScopedCtxArg<Ctx> = [Record<never, never>] extends [Ctx] ? {
|
|
921
|
+
ctx?: Ctx | Provided<Ctx>;
|
|
922
|
+
} : {
|
|
923
|
+
ctx: Ctx | Provided<Ctx>;
|
|
924
|
+
};
|
|
925
|
+
declare function replay<S, M extends {
|
|
926
|
+
type: string;
|
|
927
|
+
}, C extends Cmd, U extends Sub, Ctx>(machine: Machine<S, M, C, U, Ctx>, opts: {
|
|
928
|
+
msgs: readonly M[];
|
|
929
|
+
ctx: Ctx;
|
|
930
|
+
loaded?: S | null;
|
|
931
|
+
}): {
|
|
932
|
+
state: S;
|
|
933
|
+
cmds: C[];
|
|
934
|
+
subs: U[];
|
|
935
|
+
depSubs: {
|
|
936
|
+
index: number;
|
|
937
|
+
id: string;
|
|
938
|
+
}[];
|
|
939
|
+
};
|
|
940
|
+
declare function wrapDetached<C extends Cmd, M extends {
|
|
941
|
+
type: string;
|
|
942
|
+
}, Allowed extends M, Ctx>(handler: InterpretDetached<C, Allowed, Ctx>): (cmd: C, ctx: Ctx & PortEmitter, dispatch?: (msg: M) => void) => Promise<void>;
|
|
943
|
+
/**
|
|
944
|
+
* `applyCell`, with "no handler for this Msg" moved into the return type
|
|
945
|
+
* instead of a throw.
|
|
946
|
+
*
|
|
947
|
+
* `Ok` carries the handler's `[nextState, cmds]` verbatim; `Err` carries the same
|
|
948
|
+
* `NoCellError` (msg.type + state name + accepted set) `applyCell` would have
|
|
949
|
+
* thrown — both read one `lookupCell`, so neither can under-report. Dispatch
|
|
950
|
+
* inside `run` keeps using the throwing `applyCell` — this is for callers that
|
|
951
|
+
* step a machine themselves.
|
|
952
|
+
*/
|
|
953
|
+
declare function tryApplyCell<S, M extends {
|
|
954
|
+
type: string;
|
|
955
|
+
}, C extends Cmd>(machine: {
|
|
956
|
+
update: object;
|
|
957
|
+
__form?: UpdateForm;
|
|
958
|
+
}, state: S, msg: M): Result<readonly [S, readonly C[]], NoCellError>;
|
|
959
|
+
/**
|
|
960
|
+
* The refusal `tryFoldMsgs` reports: WHICH msg in the log had no handler, where.
|
|
961
|
+
*
|
|
962
|
+
* A plain record, not a new `Error` subclass — it is a `Result` payload, never
|
|
963
|
+
* thrown, and the actual error is the existing `NoCellError` it carries. The
|
|
964
|
+
* package's thrown-error idiom (`class extends Error` + `_tag`, pinned by
|
|
965
|
+
* `error-idiom.test.ts`) applies to errors raised at the runtime edge; this one
|
|
966
|
+
* is never raised, so adding a class would state a promise it does not make.
|
|
967
|
+
*/
|
|
968
|
+
interface FoldRefusal<M> {
|
|
969
|
+
/** Index into the `msgs` array the fold was given. */
|
|
970
|
+
readonly index: number;
|
|
971
|
+
/** The offending Msg itself — so the caller can print it, not just point. */
|
|
972
|
+
readonly msg: M;
|
|
973
|
+
/** The underlying cell-lookup failure: msg.type + state name + accepted set. */
|
|
974
|
+
readonly error: NoCellError;
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* `foldMsgs`, with the "no handler for this Msg" case in the return type,
|
|
978
|
+
* INCLUDING which message failed.
|
|
979
|
+
*
|
|
980
|
+
* The motivating use is "this persisted log does not replay — tell the user
|
|
981
|
+
* where". A bare `Result<S, NoCellError>` cannot: the error names the msg.type
|
|
982
|
+
* and the state, but a log usually contains that type many times, so the
|
|
983
|
+
* INDEX is the load-bearing fact. The fold stops at the first refusal (state
|
|
984
|
+
* past that point is not defined) and returns it.
|
|
985
|
+
*
|
|
986
|
+
* Shares `foldMsgs`' dev-mode discipline: `deepFreeze` the input state,
|
|
987
|
+
* `assertPureResult` the handler's return. Both compile out of production.
|
|
988
|
+
*/
|
|
989
|
+
declare function tryFoldMsgs<S, M extends {
|
|
990
|
+
type: string;
|
|
991
|
+
}, C extends Cmd>(machine: {
|
|
992
|
+
update: object;
|
|
993
|
+
__form?: UpdateForm;
|
|
994
|
+
}, base: S, msgs: readonly M[]): Result<S, FoldRefusal<M>>;
|
|
995
|
+
declare function settle<D extends AnyCmdDef, Ctx>(def: D, work: (cmd: CmdOf<D>, ctx: Ctx & RequirementsOf<CmdOf<D>> & PortEmitter) => Promise<Result<OkOf<D>, ErrOf<D>>>): (cmd: CmdOf<D>, ctx: Ctx & RequirementsOf<CmdOf<D>> & PortEmitter) => Promise<Settled<D>>;
|
|
996
|
+
declare function tryInterpret<C extends Cmd, Ok, M, Ctx>(work: (cmd: C, ctx: Ctx) => Promise<Ok>, onOk: (value: Ok, cmd: C) => M, onErr: (error: unknown, cmd: C) => M): (cmd: C, ctx: Ctx) => Promise<M>;
|
|
997
|
+
|
|
998
|
+
export { tryApplyCell as $, type SupervisionStrategy as A, type BootingRuntime as B, type CtxArg as C, type DepToken as D, absurd as E, type FencedStore as F, asReducer as G, defineMachine as H, IdentityDropNotice as I, definePort as J, dep as K, isFencedStore as L, type MachineTypes as M, isProvided as N, type OnError as O, PortNameCollisionError as P, QuiescenceTimeoutError as Q, type Runtime as R, type Store as S, layer as T, UnknownProviderError as U, noop as V, provide as W, replay as X, schemaMigrate as Y, settle as Z, __resetPortRegistry as _, type ScopedCtxArg as a, tryFoldMsgs as a0, tryInterpret as a1, value as a2, wrapDetached as a3, type Supervision as b, type Branded as c, type DepsOf as d, DispatchDiscardedError as e, type DispatchSettle as f, DisposeTimeoutNotice as g, DriveFailedError as h, DriveStalledError as i, type FencedRead as j, type FoldRefusal as k, type OnReleaseError as l, ProvideFailedError as m, type Provided as n, type ProvidedCtx as o, type Provider as p, ProviderCycleError as q, RuntimeDiscardNotice as r, RuntimeDiscardedError as s, type RuntimeErrorContext as t, type RuntimeErrorPhase as u, type RuntimeRef as v, type Schema as w, type Scope as x, StoreConflictError as y, SubIdCollisionError as z };
|