@demlik/tea 0.15.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 (115) hide show
  1. package/README.md +30 -7
  2. package/dist/agent/index.d.ts +49 -37
  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-AYS5N6WY.js → chunk-6NG4V5SB.js} +62 -172
  9. package/dist/chunk-6NG4V5SB.js.map +1 -0
  10. package/dist/{chunk-3B5X7SBB.js → chunk-7MGXQZPW.js} +11 -9
  11. package/dist/chunk-7MGXQZPW.js.map +1 -0
  12. package/dist/{chunk-V46HSVCK.js → chunk-BCTEOVOU.js} +3 -3
  13. package/dist/{chunk-V46HSVCK.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-TCLBCERH.js → chunk-EHUDXAKC.js} +238 -212
  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-22POWGFA.js → chunk-IVJP3GKJ.js} +46 -20
  23. package/dist/chunk-IVJP3GKJ.js.map +1 -0
  24. package/dist/{chunk-QPEVCJ5Q.js → chunk-MVZS5FDM.js} +13 -6
  25. package/dist/chunk-MVZS5FDM.js.map +1 -0
  26. package/dist/{chunk-VTQI2NHP.js → chunk-MYNLY3HP.js} +9 -8
  27. package/dist/chunk-MYNLY3HP.js.map +1 -0
  28. package/dist/{chunk-Q5CQTBFA.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-DnzqWy6u.d.ts → core-BbgtiXdg.d.ts} +231 -139
  35. package/dist/do/index.d.ts +37 -33
  36. package/dist/do/index.js +21 -14
  37. package/dist/do/index.js.map +1 -1
  38. package/dist/{durable-effects-CWzA-o2B.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 -59
  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-CSyMYDAB.d.ts → index-7vV8xmsD.d.ts} +1 -1
  51. package/dist/{index-KXqTRJyb.d.ts → index-Bz5Rh9Ga.d.ts} +19 -96
  52. package/dist/index-CjFDUBeq.d.ts +207 -0
  53. package/dist/{index-CuNO9m8i.d.ts → index-CkFYA9Y6.d.ts} +14 -16
  54. package/dist/{index-CA_7I5g9.d.ts → index-Cou86-GX.d.ts} +137 -246
  55. package/dist/{index-DrIRb_Ch.d.ts → index-DU6JpQ8G.d.ts} +1 -1
  56. package/dist/{index-HSYgG2Yt.d.ts → index-Xufl55W8.d.ts} +247 -211
  57. package/dist/{index-C2DwkjlP.d.ts → index-_dOR3xqA.d.ts} +57 -45
  58. package/dist/index.d.ts +121 -385
  59. package/dist/index.js +2 -1
  60. package/dist/jev/index.d.ts +133 -97
  61. package/dist/jev/index.js +205 -161
  62. package/dist/jev/index.js.map +1 -1
  63. package/dist/{machine-DGlPWCWI.d.ts → machine-BQzTV8On.d.ts} +171 -288
  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 -22
  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-D8VbH-VH.d.ts → protocol-ClRZBhHQ.d.ts} +7 -8
  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 -456
  91. package/dist/resilience/index.js +37 -483
  92. package/dist/resilience/index.js.map +1 -1
  93. package/dist/{runtime-types-CMF13BBh.d.ts → runtime-types-CiVpC0HN.d.ts} +131 -388
  94. package/dist/testing/index.d.ts +22 -16
  95. package/dist/testing/index.js +15 -7
  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-BseNPIhr.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-22POWGFA.js.map +0 -1
  104. package/dist/chunk-3B5X7SBB.js.map +0 -1
  105. package/dist/chunk-66PY5WYF.js +0 -1816
  106. package/dist/chunk-66PY5WYF.js.map +0 -1
  107. package/dist/chunk-AYS5N6WY.js.map +0 -1
  108. package/dist/chunk-L3TND7LA.js +0 -97
  109. package/dist/chunk-L3TND7LA.js.map +0 -1
  110. package/dist/chunk-MYXFNWAJ.js.map +0 -1
  111. package/dist/chunk-Q5CQTBFA.js.map +0 -1
  112. package/dist/chunk-QPEVCJ5Q.js.map +0 -1
  113. package/dist/chunk-TCLBCERH.js.map +0 -1
  114. package/dist/chunk-VTQI2NHP.js.map +0 -1
  115. package/dist/index-ZCMhnVKN.d.ts +0 -272
@@ -1,6 +1,5 @@
1
- import { C as Cmd } from './core-DnzqWy6u.js';
2
- import { S as SubscribeHandler } from './types-BseNPIhr.js';
3
- import { D as DeadlineExceeded, a as DeadlineSub } from './index-HSYgG2Yt.js';
1
+ import { C as Cmd, T as TimerDeps, d as Subscribe } from './core-BbgtiXdg.js';
2
+ import { D as DeadlineExceeded, a as DeadlineSub, b as DeadlinesSub } from './index-Xufl55W8.js';
4
3
 
5
4
  /**
6
5
  * internal/flow/batch-window — coalesce a stream of items into size- or
@@ -8,14 +7,13 @@ import { D as DeadlineExceeded, a as DeadlineSub } from './index-HSYgG2Yt.js';
8
7
  *
9
8
  * What this module actually DELEGATES to, vs. what it merely RE-EXPORTS:
10
9
  *
11
- * - `../deadline` — REAL delegation (the only one). The window timer IS a
12
- * `deadline` Sub: `subsFor` returns `deadlineSub` keyed on the window's
13
- * identity, the subscribe cell is `subscribeDeadline` verbatim, and the
14
- * expiry Msg is `deadlineExceeded`. Nothing about the timer is redrawn here.
15
- * "Fire at an absolute instant, even across a rehydrate" is exactly
16
- * `deadline`'s absolute-target lifecycle: a late subscribe (post-`Store`
17
- * rehydrate) recomputes the remaining delay from the current clock and still
18
- * fires at the correct moment.
10
+ * - `../deadline` — REAL delegation (the only one). The window timer's Msg
11
+ * is `deadlineExceeded`, keyed on the window's identity. `timerFor` arms it
12
+ * through the engine's built-in `timer` Sub: `maxMs` counted from the
13
+ * transition that opened the window, so a machine needs no runner. The
14
+ * absolute-instant form is still here too — `subsFor` lists the same
15
+ * deadline for `deadlinesSub` + `subscribeDeadline`, which re-arms for the
16
+ * REMAINING time after a `Store` rehydrate rather than a fresh `maxMs`.
19
17
  * - `../work-queue` — TYPE re-export only, NOT a sink this module calls. A
20
18
  * flush emits a Cmd; the CONSUMER's interpret handler is what enqueues onto a
21
19
  * `createQueue(store)`. This module never touches queue status — it has no
@@ -48,10 +46,10 @@ import { D as DeadlineExceeded, a as DeadlineSub } from './index-HSYgG2Yt.js';
48
46
  * // Model: { batch: BatchWindow<LogLine>, ... }
49
47
  * // init: (loaded) => [loaded ?? { batch: bw.init(), ... }, []]
50
48
  * // update cells:
51
- * // LogArrived: (s, m) => mapBatch(s, bw.add(s.batch, m.line, m.at))
52
- * // WindowFired: (s, m) => mapBatch(s, bw.onWindow(s.batch, m.atMs))
53
- * // subscriptions: (s) => bw.subs(s.batch)
54
- * // subscribe: { ...bw.handlers() }
49
+ * // LogArrived: (s, m) => mapBatch(s, bw.add(s.batch, m.line, m.at))
50
+ * // deadline_exceeded: (s, m) => mapBatch(s, bw.onWindow(s.batch, m.atMs))
51
+ * // subs: [{ type: "timer", deps: (s: Model) => bw.timer(s.batch) }]
52
+ * // at run: run(machine, { interpret }) // `timer` is built in
55
53
  *
56
54
  * where `mapBatch(s, [batch, cmds]) => [{ ...s, batch }, cmds]` lifts the slice
57
55
  * transition into the consumer's Model. The `FlushBatch` Cmd's interpret handler
@@ -118,26 +116,26 @@ interface BatchWindow<I> {
118
116
  /** The starting slice: closed window, empty buffer. */
119
117
  declare function initBatchWindow<I>(): BatchWindow<I>;
120
118
  /**
121
- * The Sub a batch window's open timer produces: it IS `../deadline`'s
119
+ * The deadline a batch window's open timer lists: it IS `../deadline`'s
122
120
  * `DeadlineSub`, not a re-tagged copy. `atMs` is the absolute flush-by instant
123
121
  * (`openedAt + maxMs`). Aliasing the deadline type (rather than redeclaring an
124
122
  * identical shape) is what lets `subsFor` return `deadlineSub(...)` with no
125
123
  * cast — the value's static type already satisfies this name. Consumers running
126
- * several windows route each one by the Sub's `id`, not by a distinct type.
124
+ * several windows route each one by the deadline's `id`, not by a distinct type.
127
125
  */
128
126
  type BatchWindowSub = DeadlineSub;
129
127
  /** The Msg a closed-by-time window dispatches. Alias of `deadline`'s Msg. */
130
128
  type BatchWindowExpired = DeadlineExceeded;
131
129
  /**
132
130
  * Construct the window-expired Msg for the window identified by `id`, flushing
133
- * by `atMs`. Re-exported alias of `deadlineExceeded` so the subscribe cell and
131
+ * by `atMs`. Re-exported alias of `deadlineExceeded` so the runner and
134
132
  * the consumer's reducer share one constructor rather than two literals that
135
133
  * can drift. The consumer handles it in a reducer cell by calling `onWindow`.
136
134
  */
137
135
  declare function batchWindowExpired(id: string, atMs: number): BatchWindowExpired;
138
136
  /**
139
137
  * The bound knob returned by `createBatchWindow`. `init` + the two pure verbs +
140
- * `subs` + `handlers`, all closing over one `BatchWindowConfig`. The verbs
138
+ * `timer` + `subs`, all closing over one `BatchWindowConfig`. The verbs
141
139
  * return `readonly [BatchWindow<I>, readonly C[]]`: the next slice and the Cmds
142
140
  * to emit (one `flush` Cmd when a window closes, none otherwise).
143
141
  */
@@ -154,18 +152,16 @@ interface BatchWindowKnob<I, C extends Cmd> {
154
152
  */
155
153
  onWindow(state: BatchWindow<I>, at: number): readonly [BatchWindow<I>, readonly C[]];
156
154
  /**
157
- * The window timer Sub, armed only while a window is open. See `subsFor`.
158
- * `id` keys the deadline so several windows on one machine route distinctly.
155
+ * The built-in `timer` Sub's deps while a window is open, `null` while it is
156
+ * closed. See `timerFor`. `id` keys the Msg so several windows on one
157
+ * machine route distinctly.
159
158
  */
160
- subs(state: BatchWindow<I>, id?: string): readonly BatchWindowSub[];
159
+ timer(state: BatchWindow<I>, id?: string): TimerDeps<BatchWindowExpired> | null;
161
160
  /**
162
- * The `subscribe` cells this knob splices into `machine.subscribe`. One cell,
163
- * keyed `"deadline"`, delegating to `../deadline`'s subscribe handler. Spread
164
- * into the consumer's subscribe map: `subscribe: { ...bw.handlers() }`.
161
+ * The window timer as an absolute deadline, listed only while a window is
162
+ * open — for `deadlinesSub` + `subscribeBatchWindow`. See `subsFor`.
165
163
  */
166
- handlers(): {
167
- deadline: SubscribeHandler<BatchWindowSub, BatchWindowExpired, unknown>;
168
- };
164
+ subs(state: BatchWindow<I>, id?: string): readonly BatchWindowSub[];
169
165
  }
170
166
  /**
171
167
  * Buffer `item` and decide whether the size trigger fires. PURE.
@@ -215,18 +211,18 @@ declare function addItem<I, C extends Cmd>(config: BatchWindowConfig<I, C>, stat
215
211
  */
216
212
  declare function onWindow<I, C extends Cmd>(config: BatchWindowConfig<I, C>, state: BatchWindow<I>, _at: number): readonly [BatchWindow<I>, readonly C[]];
217
213
  /**
218
- * The window timer Sub, derived from the slice. PURE.
214
+ * The window timer deadline, derived from the slice. PURE.
219
215
  *
220
- * Returns the single `deadline` Sub targeting `openedAt + maxMs` while a window
221
- * is open (buffer non-empty), or `[]` while it is closed. The substrate's
222
- * reconcile pass arms the timer when the array gains the Sub and disarms it
223
- * (clearing the pending `setTimeout`) when the array loses it — so a size-flush
224
- * that empties the buffer auto-cancels the now-irrelevant time trigger on the
225
- * next transition.
216
+ * Returns the single deadline targeting `openedAt + maxMs` while a window is
217
+ * open (buffer non-empty), or `[]` while it is closed. Fed through
218
+ * `deadlinesSub`, the engine arms the timer when the list gains the deadline
219
+ * and disarms it (clearing the pending `setTimeout`) when the list loses it —
220
+ * so a size-flush that empties the buffer auto-cancels the now-irrelevant time
221
+ * trigger on the next transition.
226
222
  *
227
223
  * `id` defaults to `"batch-window"`; pass a distinct id per window when a
228
- * machine runs several so the dispatched `BatchWindowExpired` Msg (and its
229
- * reconcile identity) routes to the right one.
224
+ * machine runs several so the dispatched `BatchWindowExpired` Msg routes to the
225
+ * right one.
230
226
  *
231
227
  * @param config the knob (maxMs)
232
228
  * @param state the current slice
@@ -235,22 +231,38 @@ declare function onWindow<I, C extends Cmd>(config: BatchWindowConfig<I, C>, sta
235
231
  */
236
232
  declare function subsFor<I, C extends Cmd>(config: BatchWindowConfig<I, C>, state: BatchWindow<I>, id?: string): readonly BatchWindowSub[];
237
233
  /**
238
- * The `subscribe["deadline"]` cell for a batch window's timer — the exact
239
- * `../deadline` handler. Arms a one-shot timer for `max(0, atMs - now)` and
240
- * dispatches `batchWindowExpired(...)`; returns a cleanup that clears it. The
241
- * consumer assigns it via the knob's `handlers()`.
234
+ * The built-in `timer` Sub's deps for a batch window. PURE.
235
+ *
236
+ * While a window is open it counts `maxMs` down from the transition that
237
+ * opened it — the deps are fixed for the window's life (`openedAt` never moves
238
+ * while items append), so the engine starts the countdown exactly once — and
239
+ * fires `batchWindowExpired(id, openedAt + maxMs)`. A closed window is `null`,
240
+ * so a size-flush that empties the buffer cancels the countdown on the next
241
+ * transition.
242
+ *
243
+ * Relative by construction: a process that rehydrates an open window counts a
244
+ * fresh `maxMs`. Reach for `subsFor` + `subscribeBatchWindow` when the flush
245
+ * must land at the original absolute instant.
246
+ */
247
+ declare function timerFor<I, C extends Cmd>(config: BatchWindowConfig<I, C>, state: BatchWindow<I>, id?: string): TimerDeps<BatchWindowExpired> | null;
248
+ /**
249
+ * The `deadline` runner for a batch window's absolute timer — the exact
250
+ * `../deadline` runner. Arms a one-shot timer per listed deadline for
251
+ * `max(0, atMs - now)` and dispatches `batchWindowExpired(...)`; returns a
252
+ * cleanup that clears them. Hand it to `run` as `subscribe.deadline` when the
253
+ * machine declares `deadlinesSub((s) => bw.subs(s.batch))`.
242
254
  */
243
- declare const subscribeBatchWindow: SubscribeHandler<BatchWindowSub, BatchWindowExpired, unknown>;
255
+ declare const subscribeBatchWindow: Subscribe<BatchWindowExpired, DeadlinesSub, unknown>["deadline"];
244
256
  /**
245
257
  * Build a batch window knob from a config. Combinator form (the default L2
246
258
  * ergonomic): hand it the config, splice the ~4 returned hooks into your
247
259
  * machine. The pure verbs (`add` / `onWindow`) close over the config so the
248
- * consumer's reducer cells stay a uniform `(state, ...args)` shape; `subs` /
249
- * `handlers` pre-wire the window timer.
260
+ * consumer's reducer cells stay a uniform `(state, ...args)` shape; `timer`
261
+ * arms the window timer.
250
262
  *
251
263
  * @typeParam I the item type buffered into each batch
252
264
  * @typeParam C the Cmd type `config.flush` returns
253
265
  */
254
266
  declare function createBatchWindow<I, C extends Cmd>(config: BatchWindowConfig<I, C>): BatchWindowKnob<I, C>;
255
267
 
256
- export { type BatchWindow as B, type BatchWindowSub as a, type BatchWindowExpired as b, type BatchWindowConfig as c, type BatchWindowKnob as d, addItem as e, batchWindowExpired as f, createBatchWindow as g, subscribeBatchWindow as h, initBatchWindow as i, onWindow as o, subsFor as s };
268
+ export { type BatchWindow as B, type BatchWindowSub as a, type BatchWindowExpired as b, type BatchWindowConfig as c, type BatchWindowKnob as d, addItem as e, batchWindowExpired as f, createBatchWindow as g, subscribeBatchWindow as h, initBatchWindow as i, onWindow as o, subsFor as s, timerFor as t };