@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,341 +1,12 @@
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>;
1
+ import { C as Cmd, S as Sub, M as Machine, R as RunHandlers, P as Port, N as NoCellError, i as Reducer, A as AnyCmdDef, j as Settled, c as CmdOf, k as Transitions, a as BuiltinSub, U as UpdateForm, l as Outcome, I as InterpretDetached, m as PortEmitter } from './core-BbgtiXdg.js';
333
2
 
334
3
  /**
335
4
  * @demlik/tea runtime interface surface + pure helpers — the public types,
336
5
  * interfaces, and construction/composition helpers the runtime (`./run`)
337
6
  * implements against: `Store`, the error-sink and supervision contracts, the
338
- * `RuntimeRef` / `BootingRuntime` / `Runtime` handle hierarchy, `definePort`, the
7
+ * engine-neutral `RunHandle` / `BootedRunHandle` every engine's `run` returns,
8
+ * the Promise engine's `RuntimeRef` / `BootingRuntime` / `Runtime` handle
9
+ * hierarchy that widens it, `definePort`, the
339
10
  * identity-typed constructors `defineMachine` / `asReducer`, and the pure tools
340
11
  * `replay` (compose without running) and `tryInterpret` (Railway).
341
12
  */
@@ -362,28 +33,14 @@ declare function absurd(x: never): never;
362
33
  declare const noop: <S, M, C extends Cmd>(state: S, _msg: M) => readonly [S, readonly C[]];
363
34
  /**
364
35
  * 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).
36
+ * process. It mechanizes invariant 7 (identity is explicit) at the runtime
37
+ * layer the type system cannot reach (string names compared at runtime).
368
38
  */
369
39
  declare class PortNameCollisionError extends Error {
370
40
  readonly name = "PortNameCollisionError";
371
41
  readonly _tag: "PortNameCollisionError";
372
42
  constructor(portName: string);
373
43
  }
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
44
  /**
388
45
  * Test-only escape hatch — clears the module-level port-name registry so the
389
46
  * collision assert in `definePort` doesn't false-positive across vitest's
@@ -401,13 +58,19 @@ declare function __resetPortRegistry(): void;
401
58
  * re-dispatched (the original dispatcher already resolved, so no caller).
402
59
  * A rejection caused by `stop()`'s own teardown is NOT this phase — see
403
60
  * `"discard"`.
61
+ * - `"interpret"` — a `Cmd.define`d handler failed outside its declared
62
+ * channel (ADR 0021): it threw, returned an `Err` whose tag it does not
63
+ * declare (`UndeclaredFailureError`), or returned something the engine cannot
64
+ * mint (`OutcomeContractError`, `AsyncSchemaError`). No `_err` Msg is
65
+ * dispatched, and the dispatch that emitted the Cmd still resolves.
404
66
  * - `"stop-save"` — the final `store.save(state)` inside `stop()` threw
405
67
  * (`stop()` resolves regardless, so without the sink this was silent loss).
406
68
  * - `"reduce"` — the pure `update` (reducer) threw synchronously; the configured
407
69
  * `Supervision` strategy decides what happens next, but the throw is surfaced
408
70
  * here as data first.
409
71
  * - `"listener"` — a `runtime.subscribe(...)` listener threw during fanout.
410
- * - `"observer"` — a `runtime.observe(...)` observer threw during fanout.
72
+ * - `"observer"` — a `runtime.observe(...)` observer threw during fanout, or
73
+ * the `telemetry` sink threw or rejected.
411
74
  * - `"event"` — the `events` projector or an `on(type, ...)` handler threw.
412
75
  * - `"boot"` — an `onBoot` handler threw (boot fanout, or a late registration).
413
76
  * - `"port-emit"` — a `subscribePort` listener threw during a port emission.
@@ -425,27 +88,34 @@ declare function __resetPortRegistry(): void;
425
88
  * `"discard"`: the loss is the FILTER WORKING, not a teardown, and a host
426
89
  * routing it (a metric, a 409 back to the caller) wants it apart from
427
90
  * 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
91
  *
434
92
  * The phase never decides fatality — the ERROR CLASS does (`RuntimeDiscardNotice`
435
93
  * warns, everything else rethrows). A phase is attached by the report site, so a
436
94
  * consumer sink that throws while handling a `"discard"` report inherits that
437
95
  * phase; keying the warn-only path on it would make the sink's own defect vanish.
438
96
  */
439
- type RuntimeErrorPhase = "follow-up" | "stop-save" | "reduce" | "listener" | "observer" | "event" | "boot" | "port-emit" | "sub-cleanup" | "discard" | "identity-drop" | "provide";
97
+ type RuntimeErrorPhase = "follow-up" | "interpret" | "stop-save" | "reduce" | "listener" | "observer" | "event" | "boot" | "port-emit" | "sub-cleanup" | "discard" | "identity-drop";
98
+ /**
99
+ * What the `telemetry` sink passed to `run` receives, once per APPLIED
100
+ * transition. Plain data, so a recorded stream stays durable.
101
+ */
102
+ interface TelemetryEvent {
103
+ /** This run's applied transitions so far, counted from 1. Boot is not one. */
104
+ readonly seq: number;
105
+ /** The `Msg.type` that drove the transition. */
106
+ readonly msgType: string;
107
+ /** When the transition committed, read off `run`'s `clock` (ms since epoch). */
108
+ readonly at: number;
109
+ }
110
+ /**
111
+ * The `telemetry` option of `run`: a fire-and-forget sink. The run never waits
112
+ * on it, and a throw or rejection reaches `onError` under `"observer"` without
113
+ * touching the run.
114
+ */
115
+ type TelemetrySink = (event: TelemetryEvent) => void | Promise<void>;
440
116
  /** Context handed to an `OnError` sink alongside the error itself. */
441
117
  interface RuntimeErrorContext {
442
118
  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
119
  }
450
120
  /**
451
121
  * Sink for runtime failures that have no caller to reject at. Configured via
@@ -510,7 +180,7 @@ declare class DriveFailedError<S> extends Error {
510
180
  /**
511
181
  * Raised by `driveToDone` when `start`'s follow-up chain quiesces on a State
512
182
  * 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
183
+ * transition it — no live Sub, no in-flight Cmd. Waiting
514
184
  * past that point is not the Sub-driven contract, it is a leak: no transition is
515
185
  * coming, so the drive would hang with the runtime alive and `stop()` never
516
186
  * reached. The rejection carries the stalled State on `error.state`, sibling to
@@ -730,11 +400,90 @@ interface RuntimeRef<M extends {
730
400
  */
731
401
  dispatchOnce(msg: M): Promise<void>;
732
402
  }
403
+ /**
404
+ * What an engine's `run` returns: queue a Msg, listen, wait for boot, stop.
405
+ * `getState` is not here — there is no State until boot runs, so it lives on
406
+ * the {@link BootedRunHandle} that `ready` resolves to. `E` is the machine's
407
+ * semantic event union (see `on`); `never` when the run projects none.
408
+ */
409
+ interface RunHandle<S, M extends {
410
+ type: string;
411
+ }, E extends {
412
+ type: string;
413
+ } = never> {
414
+ /** Put a Msg in the inbox; resolves once the engine has processed it. */
415
+ dispatch(msg: M): Promise<void>;
416
+ /** A zero-arg change notifier, fired after each applied transition. */
417
+ subscribe(listener: () => void): () => void;
418
+ /** A `(msg, state)` hook, fired after each applied transition. */
419
+ observe(observer: (msg: M, state: S) => void): () => void;
420
+ /** Fires once with the initial State — at once if boot already ran. */
421
+ onBoot(handler: (state: S) => void): () => void;
422
+ /** Subscribe to the semantic event of `type` the run's `events` projects. */
423
+ on<K extends E["type"]>(type: K, handler: (event: Extract<E, {
424
+ type: K;
425
+ }>) => void): () => void;
426
+ /** Resolves to the booted handle once boot completes. */
427
+ readonly ready: Promise<BootedRunHandle<S, M, E>>;
428
+ /** Stop the run; resolves once the engine has torn it down. */
429
+ stop(): Promise<void>;
430
+ }
431
+ /** A {@link RunHandle} whose boot has completed, so its State exists. */
432
+ interface BootedRunHandle<S, M extends {
433
+ type: string;
434
+ }, E extends {
435
+ type: string;
436
+ } = never> extends RunHandle<S, M, E> {
437
+ /** The current State. Total. */
438
+ getState(): S;
439
+ readonly ready: Promise<BootedRunHandle<S, M, E>>;
440
+ }
441
+ /**
442
+ * The options every engine's `run` accepts: the `ctx`, the handlers the
443
+ * machine runs under, an optional `store`, and the `events` projector that
444
+ * feeds `on`. An engine may take more; a host adapter hands only these.
445
+ */
446
+ type RunOptions<S, M extends {
447
+ type: string;
448
+ }, C extends Cmd, U extends Sub, Ctx, E extends {
449
+ type: string;
450
+ } = never> = CtxArg<Ctx> & RunHandlers<M, C, U, Ctx> & {
451
+ readonly store?: Store<S>;
452
+ readonly events?: (msg: M, state: S) => readonly E[];
453
+ };
454
+ /**
455
+ * An engine's `run`, seen from a host adapter: a machine and its
456
+ * {@link RunOptions} in, a {@link RunHandle} out. `useMachine` and
457
+ * `createAgentHost` take one, so they run on whichever engine the caller
458
+ * imported — `run` from `@demlik/tea/promise` fits it as it is.
459
+ */
460
+ type EngineRun<S, M extends {
461
+ type: string;
462
+ }, C extends Cmd, U extends Sub, Ctx, E extends {
463
+ type: string;
464
+ } = never> = (machine: Machine<S, M, C, U, Ctx>, opts: RunOptions<S, M, C, U, Ctx, E>) => RunHandle<S, M, E>;
465
+ /**
466
+ * What the Promise engine's `run` returns, the instant it is called, while boot
467
+ * is still in flight: its {@link RunHandle}, widened with Ports and
468
+ * `dispatchOnce`. It exposes exactly the surface total before boot — queue a
469
+ * dispatch, subscribe, observe, wire a Port, stop. Reading State (`getState`)
470
+ * and waiting for quiescence (`idle`) need the initial State to exist, so they
471
+ * live on the {@link Runtime} that `ready` resolves to; "read State before boot"
472
+ * is a compile error, not a runtime throw.
473
+ *
474
+ * `subscribe` is the React-shaped change notifier (zero-arg, paired with
475
+ * `getState()`). `observe` is the devtools-shaped trace hook — `(msg, state)`
476
+ * for every applied transition; boot is delivered via `onBoot` instead, so
477
+ * `observe`'s `msg` is total (never `null`). `on(type, handler)` is the semantic
478
+ * event channel: only the public, `type`-narrowed events a machine projects,
479
+ * never its private Msg vocabulary. `E` defaults to `never` (no projector → `on`
480
+ * uncallable).
481
+ */
733
482
  interface BootingRuntime<S, M extends {
734
483
  type: string;
735
484
  }, E extends {
736
485
  type: string;
737
- } = never> extends RuntimeRef<M> {
486
+ } = never> extends RuntimeRef<M>, RunHandle<S, M, E> {
738
487
  dispatch(msg: M, opts?: {
739
488
  readonly settle?: DispatchSettle;
740
489
  }): Promise<void>;
@@ -803,6 +552,15 @@ interface BootingRuntime<S, M extends {
803
552
  ready: Promise<Runtime<S, M, E>>;
804
553
  stop(): Promise<void>;
805
554
  }
555
+ /**
556
+ * The Promise engine's booted handle — what {@link BootingRuntime}'s `ready`
557
+ * resolves to once boot completes. It adds the members only meaningful once the
558
+ * initial State exists — `getState()` (total), `idle()` (quiescence), and the
559
+ * `result()` / `done()` reads of the terminal State — and narrows `ready` to
560
+ * resolve to itself. You never construct one directly; you obtain it via
561
+ * `await bootingRuntime.ready`, which makes "read State before boot"
562
+ * unrepresentable rather than merely discouraged.
563
+ */
806
564
  interface Runtime<S, M extends {
807
565
  type: string;
808
566
  }, E extends {
@@ -854,9 +612,9 @@ interface Runtime<S, M extends {
854
612
  *
855
613
  * `model` and `msg` are always named. `cmd` is named only by a machine whose
856
614
  * 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.
615
+ * under `cmds`; `sub` only by one that declares Subs other than the built-in
616
+ * `timer` (its union of `Sub<type, deps>`); `ctx` only by one whose `init`
617
+ * reads a `Ctx` or whose handlers are typed against one.
860
618
  */
861
619
  type MachineTypes<S, M extends {
862
620
  type: string;
@@ -912,16 +670,6 @@ type CtxArg<Ctx> = [Record<never, never>] extends [Ctx] ? {
912
670
  } : {
913
671
  ctx: Ctx;
914
672
  };
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
673
  declare function replay<S, M extends {
926
674
  type: string;
927
675
  }, C extends Cmd, U extends Sub, Ctx>(machine: Machine<S, M, C, U, Ctx>, opts: {
@@ -931,11 +679,7 @@ declare function replay<S, M extends {
931
679
  }): {
932
680
  state: S;
933
681
  cmds: C[];
934
- subs: U[];
935
- depSubs: {
936
- index: number;
937
- id: string;
938
- }[];
682
+ subs: (U | BuiltinSub<M>)[];
939
683
  };
940
684
  declare function wrapDetached<C extends Cmd, M extends {
941
685
  type: string;
@@ -955,11 +699,11 @@ declare function tryApplyCell<S, M extends {
955
699
  }, C extends Cmd>(machine: {
956
700
  update: object;
957
701
  __form?: UpdateForm;
958
- }, state: S, msg: M): Result<readonly [S, readonly C[]], NoCellError>;
702
+ }, state: S, msg: M): Outcome<readonly [S, readonly C[]], NoCellError>;
959
703
  /**
960
704
  * The refusal `tryFoldMsgs` reports: WHICH msg in the log had no handler, where.
961
705
  *
962
- * A plain record, not a new `Error` subclass — it is a `Result` payload, never
706
+ * A plain record, not a new `Error` subclass — it is an `Outcome` payload, never
963
707
  * thrown, and the actual error is the existing `NoCellError` it carries. The
964
708
  * package's thrown-error idiom (`class extends Error` + `_tag`, pinned by
965
709
  * `error-idiom.test.ts`) applies to errors raised at the runtime edge; this one
@@ -978,7 +722,7 @@ interface FoldRefusal<M> {
978
722
  * INCLUDING which message failed.
979
723
  *
980
724
  * 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
725
+ * where". A bare `Outcome<S, NoCellError>` cannot: the error names the msg.type
982
726
  * and the state, but a log usually contains that type many times, so the
983
727
  * INDEX is the load-bearing fact. The fold stops at the first refusal (state
984
728
  * past that point is not defined) and returns it.
@@ -991,8 +735,7 @@ declare function tryFoldMsgs<S, M extends {
991
735
  }, C extends Cmd>(machine: {
992
736
  update: object;
993
737
  __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>>;
738
+ }, base: S, msgs: readonly M[]): Outcome<S, FoldRefusal<M>>;
996
739
  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
740
 
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 };
741
+ export { replay as A, type BootingRuntime as B, type CtxArg as C, DispatchDiscardedError as D, type EngineRun as E, type FencedStore as F, schemaMigrate as G, tryApplyCell as H, IdentityDropNotice as I, tryFoldMsgs as J, tryInterpret as K, wrapDetached as L, type MachineTypes as M, type OnError as O, PortNameCollisionError as P, QuiescenceTimeoutError as Q, type Runtime as R, type Store as S, type TelemetrySink as T, __resetPortRegistry as _, type Supervision as a, type BootedRunHandle as b, type RunHandle as c, type Branded as d, type DispatchSettle as e, DisposeTimeoutNotice as f, DriveFailedError as g, DriveStalledError as h, type FencedRead as i, type FoldRefusal as j, type RunOptions as k, RuntimeDiscardNotice as l, RuntimeDiscardedError as m, type RuntimeErrorContext as n, type RuntimeErrorPhase as o, type RuntimeRef as p, type Schema as q, StoreConflictError as r, type SupervisionStrategy as s, type TelemetryEvent as t, absurd as u, asReducer as v, defineMachine as w, definePort as x, isFencedStore as y, noop as z };