@demlik/tea 0.14.0 → 0.16.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.
Files changed (116) hide show
  1. package/README.md +30 -7
  2. package/dist/agent/index.d.ts +49 -36
  3. package/dist/agent/index.js +12 -8
  4. package/dist/chunk-4LPY67E4.js +18 -0
  5. package/dist/chunk-4LPY67E4.js.map +1 -0
  6. package/dist/chunk-5XU6ZJO2.js +533 -0
  7. package/dist/chunk-5XU6ZJO2.js.map +1 -0
  8. package/dist/{chunk-AQ6ZIMEA.js → chunk-6NG4V5SB.js} +89 -115
  9. package/dist/chunk-6NG4V5SB.js.map +1 -0
  10. package/dist/{chunk-HYDWG35Q.js → chunk-7MGXQZPW.js} +11 -9
  11. package/dist/chunk-7MGXQZPW.js.map +1 -0
  12. package/dist/{chunk-BLJ2JQSH.js → chunk-BCTEOVOU.js} +3 -3
  13. package/dist/{chunk-BLJ2JQSH.js.map → chunk-BCTEOVOU.js.map} +1 -1
  14. package/dist/chunk-CH5KTOEZ.js +710 -0
  15. package/dist/chunk-CH5KTOEZ.js.map +1 -0
  16. package/dist/chunk-CIHSHLQX.js +64 -0
  17. package/dist/chunk-CIHSHLQX.js.map +1 -0
  18. package/dist/{chunk-Z2L3LSNV.js → chunk-EHUDXAKC.js} +246 -210
  19. package/dist/chunk-EHUDXAKC.js.map +1 -0
  20. package/dist/chunk-GOX2CYIM.js +380 -0
  21. package/dist/chunk-GOX2CYIM.js.map +1 -0
  22. package/dist/chunk-IVJP3GKJ.js +104 -0
  23. package/dist/chunk-IVJP3GKJ.js.map +1 -0
  24. package/dist/{chunk-F7FMAWLA.js → chunk-MVZS5FDM.js} +13 -6
  25. package/dist/chunk-MVZS5FDM.js.map +1 -0
  26. package/dist/{chunk-LYLTKJWM.js → chunk-MYNLY3HP.js} +9 -8
  27. package/dist/chunk-MYNLY3HP.js.map +1 -0
  28. package/dist/{chunk-I5MQMJDW.js → chunk-NSIAORRY.js} +20 -30
  29. package/dist/chunk-NSIAORRY.js.map +1 -0
  30. package/dist/{chunk-MYXFNWAJ.js → chunk-QNGYQMZB.js} +4 -4
  31. package/dist/chunk-QNGYQMZB.js.map +1 -0
  32. package/dist/chunk-WT5PBPLB.js +98 -0
  33. package/dist/chunk-WT5PBPLB.js.map +1 -0
  34. package/dist/{core-CTzMJ82M.d.ts → core-BbgtiXdg.d.ts} +231 -139
  35. package/dist/do/index.d.ts +37 -32
  36. package/dist/do/index.js +21 -14
  37. package/dist/do/index.js.map +1 -1
  38. package/dist/{durable-effects-B0-qGQDy.d.ts → durable-effects-7MTK_jnj.d.ts} +1 -1
  39. package/dist/effect/index.d.ts +151 -0
  40. package/dist/effect/index.js +98 -0
  41. package/dist/effect/index.js.map +1 -0
  42. package/dist/extension/index.d.ts +6 -7
  43. package/dist/extension/index.js +3 -2
  44. package/dist/extension/index.js.map +1 -1
  45. package/dist/flow/index.d.ts +68 -70
  46. package/dist/flow/index.js +32 -27
  47. package/dist/flow/index.js.map +1 -1
  48. package/dist/idempotency/index.d.ts +6 -7
  49. package/dist/idempotency/index.js +4 -2
  50. package/dist/{index-DJWIER_3.d.ts → index-7vV8xmsD.d.ts} +1 -1
  51. package/dist/{index-NjrT3fL2.d.ts → index-Bz5Rh9Ga.d.ts} +19 -96
  52. package/dist/index-CjFDUBeq.d.ts +207 -0
  53. package/dist/{index-6A7dB8f6.d.ts → index-CkFYA9Y6.d.ts} +14 -16
  54. package/dist/{index-B5BZ-_cT.d.ts → index-Cou86-GX.d.ts} +189 -108
  55. package/dist/{index-TvRb1KVf.d.ts → index-DU6JpQ8G.d.ts} +1 -1
  56. package/dist/{index-q0hXFeZ0.d.ts → index-Xufl55W8.d.ts} +286 -215
  57. package/dist/{index-4vZzljCD.d.ts → index-_dOR3xqA.d.ts} +57 -45
  58. package/dist/index.d.ts +181 -385
  59. package/dist/index.js +2 -1
  60. package/dist/jev/index.d.ts +147 -99
  61. package/dist/jev/index.js +329 -233
  62. package/dist/jev/index.js.map +1 -1
  63. package/dist/{machine-CdIcN2Xm.d.ts → machine-BQzTV8On.d.ts} +171 -280
  64. package/dist/machine-viz/index.d.ts +5 -5
  65. package/dist/machine-viz/index.js +8 -4
  66. package/dist/machine-viz/index.js.map +1 -1
  67. package/dist/mem/index.d.ts +3 -4
  68. package/dist/mem/index.js +2 -1
  69. package/dist/mem/index.js.map +1 -1
  70. package/dist/node/index.d.ts +119 -78
  71. package/dist/node/index.js +52 -38
  72. package/dist/node/index.js.map +1 -1
  73. package/dist/paginate/index.d.ts +27 -33
  74. package/dist/paginate/index.js +6 -4
  75. package/dist/parity/index.d.ts +4 -5
  76. package/dist/parity/index.js +3 -2
  77. package/dist/parity/index.js.map +1 -1
  78. package/dist/pbt/index.d.ts +2 -2
  79. package/dist/pbt/index.js +2 -1
  80. package/dist/pbt/index.js.map +1 -1
  81. package/dist/persistence/index.d.ts +6 -7
  82. package/dist/persistence/index.js +5 -3
  83. package/dist/promise/index.d.ts +186 -0
  84. package/dist/promise/index.js +5 -0
  85. package/dist/promise/index.js.map +1 -0
  86. package/dist/protocol-ClRZBhHQ.d.ts +53 -0
  87. package/dist/react/index.d.ts +36 -17
  88. package/dist/react/index.js +27 -4
  89. package/dist/react/index.js.map +1 -1
  90. package/dist/resilience/index.d.ts +63 -455
  91. package/dist/resilience/index.js +37 -483
  92. package/dist/resilience/index.js.map +1 -1
  93. package/dist/{runtime-types-LWDoi943.d.ts → runtime-types-CiVpC0HN.d.ts} +131 -388
  94. package/dist/testing/index.d.ts +165 -15
  95. package/dist/testing/index.js +104 -3
  96. package/dist/testing/index.js.map +1 -1
  97. package/dist/timing/index.d.ts +25 -22
  98. package/dist/timing/index.js +4 -3
  99. package/dist/timing/index.js.map +1 -1
  100. package/dist/{types-DP3f5NIl.d.ts → types-LxZxGYda.d.ts} +2 -2
  101. package/dist/work-queue/index.d.ts +5 -6
  102. package/package.json +18 -5
  103. package/dist/chunk-AQ6ZIMEA.js.map +0 -1
  104. package/dist/chunk-F2US5BW6.js +0 -72
  105. package/dist/chunk-F2US5BW6.js.map +0 -1
  106. package/dist/chunk-F7FMAWLA.js.map +0 -1
  107. package/dist/chunk-HUKZQX6U.js +0 -97
  108. package/dist/chunk-HUKZQX6U.js.map +0 -1
  109. package/dist/chunk-HYDWG35Q.js.map +0 -1
  110. package/dist/chunk-I5MQMJDW.js.map +0 -1
  111. package/dist/chunk-LYLTKJWM.js.map +0 -1
  112. package/dist/chunk-MYXFNWAJ.js.map +0 -1
  113. package/dist/chunk-RQULHGYH.js +0 -1804
  114. package/dist/chunk-RQULHGYH.js.map +0 -1
  115. package/dist/chunk-Z2L3LSNV.js.map +0 -1
  116. package/dist/index-DMCeMPMJ.d.ts +0 -272
@@ -1,272 +0,0 @@
1
- import { a as CmdOf, b as CmdDef, C as Cmd, I as Interpret } from './core-CTzMJ82M.js';
2
-
3
- /**
4
- * The snapshot knob.
5
- *
6
- * `every` is the cadence: a checkpoint is written once `every` units of
7
- * progress have accumulated since the last one (see `record`). It is the
8
- * `snapshotEvery` field `monitored-run` threads through to this module.
9
- *
10
- * `key` is the store key the checkpoint is written under. A single machine
11
- * keeps a single rolling checkpoint, so the key is fixed at config time rather
12
- * than passed per write — the latest checkpoint overwrites the previous one
13
- * (R2/KV are last-write-wins on a key). Defaults to `"@@snapshot"`, mirroring
14
- * `doStore`'s `@@state` default-key convention.
15
- */
16
- interface SnapshotConfig {
17
- /**
18
- * Write a checkpoint once this many progress units have accumulated since the
19
- * last write. `every: 1` checkpoints on every `record`; a value `<= 0` is
20
- * treated as `1` (every progress unit triggers a write) — a non-positive
21
- * cadence has no other sensible meaning, and clamping keeps `record` from
22
- * never checkpointing on a misconfigured `0`.
23
- */
24
- readonly every: number;
25
- /** Store key the rolling checkpoint is written under. Defaults to `"@@snapshot"`. */
26
- readonly key?: string;
27
- }
28
- /**
29
- * The snapshot bookkeeping slice. Plain data — JSON-serializable so it rides
30
- * inside the consumer's `Store<S>` blob and survives DO eviction / reload (the
31
- * "durable" non-negotiable). It carries NO payload: the thing being
32
- * checkpointed lives elsewhere in the machine's state; this slice only tracks
33
- * *when* to checkpoint and *what has been acknowledged durable*.
34
- *
35
- * - `sinceLast` — progress units accumulated since the last checkpoint
36
- * DECISION (reset to 0 the moment `record` decides to write, not when the
37
- * write lands). The cadence counter.
38
- * - `seq` — monotonic checkpoint sequence. Bumped each time a write is
39
- * emitted, so the write Cmd and its later acknowledgement can be matched
40
- * even if several are in flight. The "version" of the latest emitted
41
- * checkpoint.
42
- * - `lastSavedSeq` — the highest `seq` whose write the host has confirmed
43
- * durable (via `confirm`). `null` until the first confirmed write. The gap
44
- * `seq - lastSavedSeq` is the "writes emitted but not yet acknowledged"
45
- * depth — observable for backpressure / health.
46
- * - `lastSavedAt` — the `at` of the most recent confirmed write (epoch ms),
47
- * `null` until the first. Carried for observability, never compared inside
48
- * a verb (time is injected, never read here).
49
- */
50
- interface SnapshotState {
51
- readonly sinceLast: number;
52
- readonly seq: number;
53
- readonly lastSavedSeq: number | null;
54
- readonly lastSavedAt: number | null;
55
- }
56
- /**
57
- * The abstract checkpoint sink — the intersection of R2's and KV's surface,
58
- * narrowed to exactly the two methods a rolling checkpoint needs. Deliberately
59
- * NOT the substrate's `Store<S>` (`{ load, save, migrate }`): that is the
60
- * runtime's whole-state persistence boundary keyed at a fixed cell, whereas a
61
- * checkpoint store is keyed, value-typed, and host-supplied.
62
- *
63
- * - `put(key, value)` — write the checkpoint. Last-write-wins on `key`.
64
- * - `get(key)` — read the latest checkpoint back, or `null` if none. Used by
65
- * a recovery path to seed `init`'s `loaded` from the durable checkpoint
66
- * when the runtime's own `Store<S>` blob is gone.
67
- *
68
- * No `@cloudflare/workers-types` import — an R2 bucket, a KV namespace, a DO
69
- * sub-key, or an in-memory `Map` all satisfy this shape with a 3-line adapter
70
- * at the host.
71
- */
72
- interface SnapshotStore<V> {
73
- get(key: string): Promise<V | null>;
74
- put(key: string, value: V): Promise<void>;
75
- }
76
- /**
77
- * The ports `handlers` binds. Just the store today — named so a future port
78
- * (a metrics sink, a clock) can grow without breaking the `handlers(ports)`
79
- * call shape.
80
- */
81
- interface SnapshotPorts<V> {
82
- readonly store: SnapshotStore<V>;
83
- }
84
- /**
85
- * The checkpoint-write Cmd a `record` / `force` decision emits. Plain data
86
- * (invariant 1 — Cmds are data, not closures): it carries the `payload` to
87
- * write, the `key` to write it under, the `seq` it represents, and the `at` it
88
- * was decided. The handler performs the `put` and routes the result back to a
89
- * `confirm` / fail Msg.
90
- *
91
- * `payload` is `V` — the consumer's serializable checkpoint value (the run
92
- * state, the cursor, whatever the machine wants restartable). The verb takes it
93
- * as an argument so the snapshot slice never has to hold a copy of the
94
- * machine's domain state.
95
- *
96
- * `Cmd.define`d (ADR 0014), minted per `V` by a factory the way
97
- * `workflowActivityDef<A>()` is, since the payload type is the knob's own
98
- * parameter. The handler answers through this module's OWN Msgs
99
- * (`snapshot_saved` / `snapshot_failed`), never the minted `_ok` / `_err`,
100
- * hence `ok: z.void()` and an empty `err` list.
101
- */
102
- declare function snapshotWriteDef<V>(): CmdDef<"snapshot_write", {
103
- readonly key: string;
104
- readonly seq: number;
105
- readonly at: number;
106
- readonly payload: V;
107
- }, void, never, unknown>;
108
- type SnapshotWriteCmd<V> = CmdOf<ReturnType<typeof snapshotWriteDef<V>>>;
109
- /**
110
- * The Msg the write handler dispatches on a SUCCESSFUL `put`. Fold it back
111
- * through `confirm(state, msg)` to advance `lastSavedSeq` / `lastSavedAt`. The
112
- * `seq` matches the emitting Cmd so a late acknowledgement of an older write
113
- * can never regress a newer confirmed one.
114
- */
115
- type SnapshotSavedMsg = {
116
- readonly type: "snapshot_saved";
117
- readonly seq: number;
118
- readonly at: number;
119
- };
120
- /**
121
- * The Msg the write handler dispatches on a FAILED `put`. Errors are data
122
- * (never swallowed): the consumer's reducer decides whether a failed checkpoint
123
- * is fatal, retryable (compose `@demlik/tea/retry-backoff`), or merely logged.
124
- * `seq` identifies which checkpoint failed; `error` is carried, never
125
- * interpreted here.
126
- */
127
- type SnapshotFailedMsg = {
128
- readonly type: "snapshot_failed";
129
- readonly seq: number;
130
- readonly error: unknown;
131
- };
132
- /**
133
- * The checkpoint-READ Cmd a `requestLoad` decision emits — the recovery half of
134
- * the module. Plain data (invariant 1): it carries only the `key` to read. The
135
- * handler performs `store.get(key)` and routes the result back to a
136
- * `snapshot_loaded` (Ok, payload-or-null) / `snapshot_load_failed` (Err) Msg.
137
- *
138
- * Distinct from `snapshot_write`: a write carries a payload OUT to the store; a
139
- * load asks the store to hand a payload BACK. The consumer dispatches the
140
- * triggering Msg once on resume (a `boot` Msg, never `init`'s rehydrate branch —
141
- * invariant 2), folds the recovered payload into its run slice, then continues.
142
- */
143
- declare const snapshotLoad: CmdDef<"snapshot_load", {
144
- key: string;
145
- }, void, never, unknown>;
146
- type SnapshotLoadCmd = CmdOf<typeof snapshotLoad>;
147
- /**
148
- * The Msg the load handler dispatches when `store.get` RESOLVES. `payload` is
149
- * the recovered checkpoint value, or `null` when the store has no checkpoint
150
- * under `key` (fresh boot — never checkpointed, or a wiped store). The consumer
151
- * folds this into `init`'s loaded branch: `payload === null` → keep the fresh
152
- * `init` state; non-null → seed the run slice from the durable checkpoint and
153
- * `boot` the snapshot slice's cadence counter.
154
- *
155
- * A `null` payload is NOT an error — "no checkpoint yet" is a normal first-run
156
- * state, distinct from "the read failed" (`snapshot_load_failed`).
157
- */
158
- type SnapshotLoadedMsg<V> = {
159
- readonly type: "snapshot_loaded";
160
- readonly payload: V | null;
161
- };
162
- /**
163
- * The Msg the load handler dispatches when `store.get` REJECTS. Errors are data
164
- * (never swallowed — the field-guide rule): a failed recovery read is a visible
165
- * signal the consumer's reducer decides on (fatal-abort, retry via
166
- * `@demlik/tea/retry-backoff`, or boot-fresh-and-log). `error` is carried, never
167
- * interpreted here. Kept separate from `snapshot_loaded`'s `null` so "the store
168
- * has no checkpoint" can never masquerade as "the read failed".
169
- */
170
- type SnapshotLoadFailedMsg = {
171
- readonly type: "snapshot_load_failed";
172
- readonly error: unknown;
173
- };
174
- /** Construct a `snapshot_saved` Msg. Shared by the handler and tests so the wire shape can't drift. */
175
- declare function snapshotSaved(seq: number, at: number): SnapshotSavedMsg;
176
- /** Construct a `snapshot_failed` Msg. Shared by the handler and tests so the wire shape can't drift. */
177
- declare function snapshotFailed(seq: number, error: unknown): SnapshotFailedMsg;
178
- /** Construct a `snapshot_loaded` Msg. Shared by the handler and tests so the wire shape can't drift. */
179
- declare function snapshotLoaded<V>(payload: V | null): SnapshotLoadedMsg<V>;
180
- /** Construct a `snapshot_load_failed` Msg. Shared by the handler and tests so the wire shape can't drift. */
181
- declare function snapshotLoadFailed(error: unknown): SnapshotLoadFailedMsg;
182
- /**
183
- * The bundle `createSnapshot` returns — the uniform knob contract. `subs` is
184
- * omitted: a checkpoint is driven by progress (a `record` call from the
185
- * consumer's reducer), not by a timer, so this module has no subscriptions.
186
- */
187
- interface SnapshotKnob<V> {
188
- /** The initial slice — zero progress, no checkpoint emitted or confirmed yet. */
189
- init(): SnapshotState;
190
- /**
191
- * Account one unit of progress. PURE. Increments `sinceLast`; once the
192
- * accumulated count reaches the configured cadence, DECIDES to checkpoint:
193
- * resets `sinceLast` to 0, bumps `seq`, and emits a single `snapshot_write`
194
- * Cmd carrying `payload` + `key` + the new `seq` + `at`. Below the cadence it
195
- * returns the bumped slice and NO Cmd.
196
- *
197
- * `payload` is the checkpoint value to persist (the consumer's domain state);
198
- * `at` is the caller-stamped time the progress occurred (epoch ms) — injected,
199
- * never read from the clock here.
200
- */
201
- record(state: SnapshotState, payload: V, at: number): readonly [SnapshotState, readonly Cmd[]];
202
- /**
203
- * Force a checkpoint regardless of the cadence counter. PURE. Always bumps
204
- * `seq`, resets `sinceLast`, and emits the write Cmd. Use on a phase boundary
205
- * the cadence would otherwise miss — e.g. "the run just finished, checkpoint
206
- * the terminal state now" — so the last durable checkpoint is the final state,
207
- * not whatever the modulo happened to land on.
208
- */
209
- force(state: SnapshotState, payload: V, at: number): readonly [SnapshotState, readonly Cmd[]];
210
- /**
211
- * Record a confirmed durable write. PURE. Advances `lastSavedSeq` /
212
- * `lastSavedAt` to the acknowledged `seq` / `at`, but only forward: an
213
- * out-of-order acknowledgement of an OLDER `seq` (a slow write landing after a
214
- * newer one) is ignored, so the confirmed watermark is monotonic. Fold the
215
- * `snapshot_saved` Msg here.
216
- *
217
- * Returns the reducer-cell shape `readonly [SnapshotState, readonly Cmd[]]`
218
- * (with `Cmd.none` — an ack emits nothing) for uniformity with every sibling
219
- * knob, so it drops straight into a `snapshot_saved` cell without the caller
220
- * re-wrapping a bare State.
221
- */
222
- confirm(state: SnapshotState, msg: SnapshotSavedMsg): readonly [SnapshotState, readonly Cmd[]];
223
- /**
224
- * Resume after a reload. PURE. Resets `sinceLast` to 0 because any
225
- * un-checkpointed progress accumulated before the crash is moot — recovery
226
- * resumes from the last DURABLE checkpoint (`get` from the store), so the
227
- * cadence counter starts fresh from there. `seq` / `lastSavedSeq` /
228
- * `lastSavedAt` are preserved (they describe what is durable, which a reload
229
- * does not change). Call from a `boot` Msg the host dispatches once after
230
- * `run(...)`, never from `init`'s rehydrate branch (invariant 2).
231
- *
232
- * Returns the reducer-cell shape `readonly [SnapshotState, readonly Cmd[]]`
233
- * (with `Cmd.none` — a resume emits nothing) for uniformity with every sibling
234
- * knob, so it drops straight into a `snapshot_loaded` cell without the caller
235
- * re-wrapping a bare State.
236
- */
237
- boot(state: SnapshotState): readonly [SnapshotState, readonly Cmd[]];
238
- /**
239
- * Ask the store for the durable checkpoint. PURE. Emits a single
240
- * `snapshot_load` Cmd carrying the configured `key`; returns the slice
241
- * UNCHANGED (a read decides nothing about the cadence bookkeeping — only the
242
- * later `snapshot_loaded` fold, via `boot`, touches the slice). This is the
243
- * entry point of the recovery loop: the consumer dispatches a `boot` Msg once
244
- * after `run(...)`, folds `requestLoad` here, and the emitted Cmd's handler
245
- * reads `store.get(key)` and dispatches `snapshot_loaded` / `snapshot_load_failed`.
246
- *
247
- * Returns `readonly [SnapshotState, readonly Cmd[]]` (the reducer-cell shape)
248
- * so it drops straight into a `boot: (s) => snap.requestLoad(s)` cell.
249
- */
250
- requestLoad(state: SnapshotState): readonly [SnapshotState, readonly Cmd[]];
251
- /**
252
- * The `interpret` map for this knob's two effect Cmds:
253
- *
254
- * - `snapshot_write` — binds the store and performs the `put`, routing
255
- * Ok → `snapshot_saved` / Err → `snapshot_failed`.
256
- * - `snapshot_load` — binds the store and performs the `get`, routing
257
- * Ok → `snapshot_loaded` (payload-or-null) / Err → `snapshot_load_failed`.
258
- *
259
- * Railway throughout — neither effect throws into the runtime; the outcome is
260
- * always a Msg. Spread into your machine's `interpret`.
261
- */
262
- handlers(ports: SnapshotPorts<V>): Interpret<SnapshotSavedMsg | SnapshotFailedMsg | SnapshotLoadedMsg<V> | SnapshotLoadFailedMsg, SnapshotWriteCmd<V> | SnapshotLoadCmd, unknown>;
263
- }
264
- /**
265
- * Create a snapshot knob from a `SnapshotConfig`. The returned bundle is spliced
266
- * into a consumer machine: `init()` seeds the slice, `record` / `force` are
267
- * folded in reducer cells, `confirm` / `boot` handle the acknowledgement +
268
- * resume Msgs, and `handlers({ store })` supplies the write `interpret` cell.
269
- */
270
- declare function createSnapshot<V>(config: SnapshotConfig): SnapshotKnob<V>;
271
-
272
- export { type SnapshotWriteCmd as S, type SnapshotState as a, type SnapshotStore as b, type SnapshotSavedMsg as c, type SnapshotFailedMsg as d, type SnapshotLoadedMsg as e, type SnapshotLoadFailedMsg as f, type SnapshotLoadCmd as g, type SnapshotConfig as h, type SnapshotKnob as i, type SnapshotPorts as j, createSnapshot as k, snapshotLoad as l, snapshotLoadFailed as m, snapshotLoaded as n, snapshotSaved as o, snapshotWriteDef as p, snapshotFailed as s };