@demlik/tea 0.20.0 → 0.22.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 (130) hide show
  1. package/README.md +11 -2
  2. package/dist/agent/index.d.ts +36 -23
  3. package/dist/agent/index.js +12 -10
  4. package/dist/{chunk-UHAQ4PI6.js → chunk-2A5XTKQQ.js} +205 -59
  5. package/dist/chunk-2A5XTKQQ.js.map +1 -0
  6. package/dist/{chunk-JAKM53JF.js → chunk-7K7SEYCH.js} +16 -15
  7. package/dist/chunk-7K7SEYCH.js.map +1 -0
  8. package/dist/{chunk-RKVUVALV.js → chunk-A3QPMX5M.js} +31 -9
  9. package/dist/chunk-A3QPMX5M.js.map +1 -0
  10. package/dist/{chunk-DVNXEB7V.js → chunk-BVFS3ICC.js} +3 -3
  11. package/dist/chunk-BVFS3ICC.js.map +1 -0
  12. package/dist/{chunk-FTCYY2DO.js → chunk-CPE5ZQXQ.js} +3 -3
  13. package/dist/{chunk-FTCYY2DO.js.map → chunk-CPE5ZQXQ.js.map} +1 -1
  14. package/dist/chunk-DEAPNMKO.js +11 -0
  15. package/dist/chunk-DEAPNMKO.js.map +1 -0
  16. package/dist/{chunk-XWIE5V7R.js → chunk-ETRNSJCR.js} +4 -4
  17. package/dist/{chunk-XWIE5V7R.js.map → chunk-ETRNSJCR.js.map} +1 -1
  18. package/dist/chunk-FXWDDNGD.js +98 -0
  19. package/dist/chunk-FXWDDNGD.js.map +1 -0
  20. package/dist/chunk-GFGOQIEC.js +10 -0
  21. package/dist/chunk-GFGOQIEC.js.map +1 -0
  22. package/dist/{chunk-2R62Q5UK.js → chunk-IAHEYPYJ.js} +3 -3
  23. package/dist/{chunk-2R62Q5UK.js.map → chunk-IAHEYPYJ.js.map} +1 -1
  24. package/dist/{chunk-NGYFBD5G.js → chunk-J5JNLXO7.js} +3 -3
  25. package/dist/{chunk-NGYFBD5G.js.map → chunk-J5JNLXO7.js.map} +1 -1
  26. package/dist/{chunk-72CN3VPY.js → chunk-NFOGYDRS.js} +5 -5
  27. package/dist/{chunk-72CN3VPY.js.map → chunk-NFOGYDRS.js.map} +1 -1
  28. package/dist/{chunk-A73IJ27X.js → chunk-R2YNDRGL.js} +3 -3
  29. package/dist/{chunk-A73IJ27X.js.map → chunk-R2YNDRGL.js.map} +1 -1
  30. package/dist/{chunk-5HVKDHY6.js → chunk-R5NXOPL2.js} +3 -3
  31. package/dist/{chunk-5HVKDHY6.js.map → chunk-R5NXOPL2.js.map} +1 -1
  32. package/dist/chunk-RMBZ7YH7.js +52 -0
  33. package/dist/chunk-RMBZ7YH7.js.map +1 -0
  34. package/dist/{chunk-AIXC33SE.js → chunk-SHXUSTHM.js} +62 -15
  35. package/dist/chunk-SHXUSTHM.js.map +1 -0
  36. package/dist/{chunk-TAKPC6SD.js → chunk-UGTC33VH.js} +4 -4
  37. package/dist/{chunk-TAKPC6SD.js.map → chunk-UGTC33VH.js.map} +1 -1
  38. package/dist/{chunk-EA47MI5Q.js → chunk-VH5MYJ2K.js} +4 -4
  39. package/dist/{chunk-EA47MI5Q.js.map → chunk-VH5MYJ2K.js.map} +1 -1
  40. package/dist/{chunk-2774I242.js → chunk-WZEDIUWR.js} +21 -20
  41. package/dist/chunk-WZEDIUWR.js.map +1 -0
  42. package/dist/{chunk-TGJLXZAU.js → chunk-ZRRET3RP.js} +11 -11
  43. package/dist/chunk-ZRRET3RP.js.map +1 -0
  44. package/dist/{core-CtvAyPpH.d.ts → core-DNDAEhO2.d.ts} +9 -12
  45. package/dist/devtools/index.d.ts +4 -4
  46. package/dist/do/index.d.ts +103 -38
  47. package/dist/do/index.js +40 -21
  48. package/dist/do/index.js.map +1 -1
  49. package/dist/{drive-loop-Dw1sGSsW.d.ts → drive-loop-DlOEv49c.d.ts} +2 -2
  50. package/dist/{durable-effects-Ump5lSdO.d.ts → durable-effects-wLWEdy9H.d.ts} +1 -1
  51. package/dist/effect/index.d.ts +121 -28
  52. package/dist/effect/index.js +45 -31
  53. package/dist/effect/index.js.map +1 -1
  54. package/dist/extension/index.d.ts +3 -3
  55. package/dist/extension/index.js +2 -2
  56. package/dist/extension/index.js.map +1 -1
  57. package/dist/flow/index.d.ts +17 -13
  58. package/dist/flow/index.js +15 -12
  59. package/dist/flow/index.js.map +1 -1
  60. package/dist/idempotency/index.d.ts +3 -3
  61. package/dist/idempotency/index.js +3 -3
  62. package/dist/{index-CrcoVfd_.d.ts → index-9P1PaXIV.d.ts} +2 -2
  63. package/dist/{index-D3NY3VCN.d.ts → index-BBLI2WWN.d.ts} +1 -1
  64. package/dist/{index-Dl71V7kt.d.ts → index-C1WhBZ6a.d.ts} +4 -5
  65. package/dist/{index-CKtEKGyp.d.ts → index-C92SgNWz.d.ts} +3 -3
  66. package/dist/{index-CZZ3HI-Z.d.ts → index-CAsUE_d1.d.ts} +4 -4
  67. package/dist/{index-EIgfl83J.d.ts → index-CO34esWT.d.ts} +2 -2
  68. package/dist/{index-Bk2hBUdK.d.ts → index-COeX9Bmz.d.ts} +11 -9
  69. package/dist/{index-CVU7SK3a.d.ts → index-Cg0QXnzf.d.ts} +2 -2
  70. package/dist/index.d.ts +9 -9
  71. package/dist/index.js +2 -2
  72. package/dist/jev/index.d.ts +15 -15
  73. package/dist/jev/index.js +5 -5
  74. package/dist/jev/index.js.map +1 -1
  75. package/dist/laws-DTtCDDlU.d.ts +135 -0
  76. package/dist/loop-DReKGV1X.d.ts +70 -0
  77. package/dist/{machine-Dtre2TmN.d.ts → machine-C0WhOAyB.d.ts} +7 -7
  78. package/dist/machine-viz/index.d.ts +1 -1
  79. package/dist/machine-viz/index.js +2 -2
  80. package/dist/mem/index.d.ts +4 -3
  81. package/dist/mem/index.js +2 -2
  82. package/dist/mem/index.js.map +1 -1
  83. package/dist/node/index.d.ts +57 -9
  84. package/dist/node/index.js +175 -68
  85. package/dist/node/index.js.map +1 -1
  86. package/dist/otel/index.d.ts +28 -12
  87. package/dist/otel/index.js +25 -21
  88. package/dist/otel/index.js.map +1 -1
  89. package/dist/paginate/index.d.ts +4 -4
  90. package/dist/paginate/index.js +5 -5
  91. package/dist/parity/index.d.ts +11 -15
  92. package/dist/parity/index.js +4 -9
  93. package/dist/parity/index.js.map +1 -1
  94. package/dist/pbt/index.d.ts +279 -67
  95. package/dist/pbt/index.js +299 -58
  96. package/dist/pbt/index.js.map +1 -1
  97. package/dist/persistence/index.d.ts +10 -12
  98. package/dist/persistence/index.js +4 -4
  99. package/dist/promise/index.d.ts +118 -21
  100. package/dist/promise/index.js +6 -4
  101. package/dist/react/index.d.ts +34 -21
  102. package/dist/react/index.js +271 -42
  103. package/dist/react/index.js.map +1 -1
  104. package/dist/resilience/index.d.ts +6 -6
  105. package/dist/resilience/index.js +5 -5
  106. package/dist/{run-fiBe7pOG.d.ts → run-Cnw4qXj2.d.ts} +105 -23
  107. package/dist/{runtime-types-DEluQgGO.d.ts → runtime-types-CP-ykwgf.d.ts} +157 -29
  108. package/dist/testing/effect/index.d.ts +162 -9
  109. package/dist/testing/effect/index.js +110 -10
  110. package/dist/testing/effect/index.js.map +1 -1
  111. package/dist/testing/index.d.ts +6 -8
  112. package/dist/testing/index.js +4 -24
  113. package/dist/testing/index.js.map +1 -1
  114. package/dist/testing/promise/index.d.ts +4 -4
  115. package/dist/testing/promise/index.js +5 -5
  116. package/dist/timing/index.d.ts +4 -4
  117. package/dist/timing/index.js +4 -4
  118. package/dist/{types-CXNzlbAg.d.ts → types-S53WDy_h.d.ts} +1 -1
  119. package/dist/work-queue/index.d.ts +4 -4
  120. package/dist/work-queue/index.js +2 -2
  121. package/package.json +19 -17
  122. package/dist/chunk-2774I242.js.map +0 -1
  123. package/dist/chunk-AIXC33SE.js.map +0 -1
  124. package/dist/chunk-DVNXEB7V.js.map +0 -1
  125. package/dist/chunk-HX3C6LDK.js +0 -34
  126. package/dist/chunk-HX3C6LDK.js.map +0 -1
  127. package/dist/chunk-JAKM53JF.js.map +0 -1
  128. package/dist/chunk-RKVUVALV.js.map +0 -1
  129. package/dist/chunk-TGJLXZAU.js.map +0 -1
  130. package/dist/chunk-UHAQ4PI6.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { C as CtxArg } from './runtime-types-DEluQgGO.js';
1
+ import { C as CtxArg } from './runtime-types-CP-ykwgf.js';
2
2
 
3
3
  /**
4
4
  * The default round bound when `opts.maxRounds` is omitted: **100**.
@@ -124,4 +124,4 @@ declare class DriveNoHandlerError<M, C> extends Error {
124
124
  */
125
125
  declare function driveTraceOf<M, C>(err: unknown): readonly DriveTraceEntry<M, C>[] | undefined;
126
126
 
127
- export { DriveRoundsExceededError as D, DriveNoHandlerError as a, type DriveOptions as b, type DriveResult as c, DEFAULT_MAX_ROUNDS as d, type DriveCtxArg as e, type DriveTraceEntry as f, driveTraceOf as g };
127
+ export { type DriveOptions as D, type DriveResult as a, DEFAULT_MAX_ROUNDS as b, type DriveCtxArg as c, DriveNoHandlerError as d, DriveRoundsExceededError as e, type DriveTraceEntry as f, driveTraceOf as g };
@@ -1,4 +1,4 @@
1
- import { C as Cmd } from './core-CtvAyPpH.js';
1
+ import { C as Cmd } from './core-DNDAEhO2.js';
2
2
 
3
3
  /**
4
4
  * @demlik/tea/do — the durable pending-effects ledger (substrate primitive #1).
@@ -1,9 +1,10 @@
1
- import { Scope, Effect } from 'effect';
2
- import { C as Cmd, S as Sub, M as Machine } from '../core-CtvAyPpH.js';
3
- import { E as EffectRuntime, S as StoreFailed } from '../run-fiBe7pOG.js';
4
- export { C as CellErrors, a as EffectBootingRuntime, b as EffectInterpret, c as EffectInterpretCell, d as EffectRunOptions, e as EffectRunner, f as EffectSubscribe, I as InterpretServices, g as Stopped, h as SubscribeServices, r as run } from '../run-fiBe7pOG.js';
1
+ import { T as TellAnswer } from '../loop-DReKGV1X.js';
2
+ import { Scope, Effect, Schema } from 'effect';
3
+ import { C as Cmd$1, c as Sub, M as Machine, k as CmdInput, b as CmdDef, f as TaggedError } from '../core-DNDAEhO2.js';
4
+ import { E as EffectRun } from '../run-Cnw4qXj2.js';
5
+ export { C as CellErrors, a as EffectBootingRun, b as EffectBootingRuntime, c as EffectInterpret, d as EffectInterpretCell, e as EffectRunOptions, f as EffectRunner, g as EffectRuntime, h as EffectSubscribe, I as InterpretServices, S as Stopped, i as StoreFailed, j as SubFailed, k as SubscribeServices, r as run } from '../run-Cnw4qXj2.js';
5
6
  import '@standard-schema/spec';
6
- import '../runtime-types-DEluQgGO.js';
7
+ import '../runtime-types-CP-ykwgf.js';
7
8
  import 'effect/Cause';
8
9
  import 'effect/Types';
9
10
 
@@ -14,30 +15,49 @@ import 'effect/Types';
14
15
  * tea still runs one machine per `run` and keeps no table of runs (#312). A
15
16
  * host that builds a tree of runs keeps its own table, ids and Msg names, and
16
17
  * hands the steps that race to these functions: `spawn` starts a child and
17
- * enrols it as one step, `stop` stops one child, and `tell` sends the parent a
18
- * notice it may no longer take.
18
+ * enrols it as one step, `stop` stops one child, and `tell` puts a Msg on a
19
+ * run's line without waiting for it.
19
20
  */
20
21
 
21
22
  /**
22
- * Hand `msg` to a run only when its State has a cell for it, and drop it when
23
- * the run no longer takes it.
23
+ * Put `msg` on a run's line and answer at once. The answer means queued, not
24
+ * handled: the receiver's step has not run yet, and any result comes back later
25
+ * as its own Msg. So two machines can tell each other from their Cmd handlers
26
+ * and neither stops. `machine` is the machine `runtime` runs.
24
27
  *
25
- * `machine` is the machine `runtime` runs. The dispatch lands a moment after
26
- * the check, so a State that changed in between refuses the Msg with a
27
- * `NoCellError`, and a run that stopped refuses it with `Stopped`. Both mean
28
- * the run no longer takes the notice, so both are dropped and `tell` succeeds.
29
- * A failed save stays a `StoreFailed`, and a hand-written cell's declared
30
- * failure stays that failure.
28
+ * The answer is `"queued"`, `"stopped"` for a run that is stopping or has
29
+ * stopped, or `"no_cell"` when its current State has no cell for the Msg. Msgs
30
+ * already in line have not folded yet, so a Msg that only a queued one makes
31
+ * acceptable answers `"no_cell"`.
32
+ *
33
+ * `runtime` is what `ready` succeeded with, or a spread of it. Those carry the
34
+ * run's line, and the type asks for it, so an `EffectRuntime` built by hand is a
35
+ * compile error. So is the handle `run` yielded, with a store or without one: wait
36
+ * for `ready`.
37
+ *
38
+ * `tell` carries no failure in its type. A hand-built object cast past the type
39
+ * has no line to put a Msg on, and `tell` dies with a defect there.
40
+ *
41
+ * What happens after `"queued"` is the receiver's. Two `tell`s from one sender
42
+ * fold in the order they were sent. A failed save or a cell's failure goes to
43
+ * the receiver's `onError`, never back to the sender. A Msg whose cell is gone
44
+ * by its turn is dropped without a word, and a `stop()` that gives up drops
45
+ * what is still in line and counts it, per Msg type, in its
46
+ * `DrainTimeoutNotice`.
47
+ *
48
+ * Two hand-written waiting `runtime.dispatch(...)` calls into each other, one
49
+ * from each machine's Cmd handler, still stop both machines: `dispatch` waits,
50
+ * and tea has no lock-up detector. Use `tell` there.
31
51
  *
32
52
  * ```ts
33
- * yield* tell(parent, parentRun, { type: "child_stopped", id });
53
+ * const answer = yield* tell(parent, parentRun, { type: "child_stopped", id });
34
54
  * ```
35
55
  */
36
56
  declare const tell: <S, M extends {
37
57
  type: string;
38
- }, C extends Cmd, U extends Sub, Ctx, E extends {
58
+ }, C extends Cmd$1, U extends Sub, Ctx, E extends {
39
59
  type: string;
40
- } = never, Err = never>(machine: Machine<S, M, C, U, Ctx>, runtime: EffectRuntime<S, M, E, Err>, msg: NoInfer<M>) => Effect.Effect<void, Err | StoreFailed>;
60
+ } = never, Err = never>(machine: Machine<S, M, C, U, Ctx>, runtime: EffectRun<S, M, E, Err>, msg: NoInfer<M>) => Effect.Effect<TellAnswer>;
41
61
  /**
42
62
  * The host's own steps of a {@link spawn}. The host owns the table of
43
63
  * children, their ids and the parent's Msg names; `spawn` owns the order the
@@ -63,11 +83,14 @@ interface SpawnSteps<A, E = never, R = never> {
63
83
  /**
64
84
  * Say the child stopped, usually a {@link tell} to the parent. It runs
65
85
  * after `remove`, on a fiber of its own that the closing scope never waits
66
- * for, so it may wait on the parent.
86
+ * for, so even a step that does wait cannot hold the close.
67
87
  *
68
88
  * It cannot fail: nothing reads that fiber, so the step itself handles what
69
- * its notice can fail with, such as the `StoreFailed` of a `tell`. A defect
70
- * in it is not observed by `spawn` and ends the fiber unseen.
89
+ * its notice can fail with. A `tell` has nothing to handle. Its argument is the
90
+ * handle the parent's `ready` gave: a parent handle built by hand, or one straight
91
+ * from `run`, does not compile. A defect in this step, such as a `tell` on a
92
+ * hand-built object cast past that type, is not observed by `spawn` and ends the
93
+ * fiber unseen.
71
94
  */
72
95
  readonly notify: Effect.Effect<unknown>;
73
96
  }
@@ -87,9 +110,14 @@ interface SpawnSteps<A, E = never, R = never> {
87
110
  * - `remove` runs after the child's run has stopped.
88
111
  *
89
112
  * Nothing reads the fiber `notify` runs on, so `spawn` reports no failure of
90
- * it and `notify` is typed to have none. The host handles what its notice can
91
- * fail with inside the step, as the `Effect.catch` below does for a parent
92
- * whose save failed. A defect in `notify` ends that fiber unseen.
113
+ * it and `notify` is typed to have none. A `tell` carries no failure, and a
114
+ * failed save of the parent reaches the parent's own `onError`. A defect in
115
+ * `notify`, such as a `tell` on a handle cast past its type, ends that fiber
116
+ * unseen.
117
+ *
118
+ * A child whose run fails stops the same way, with no host call: a Sub failure
119
+ * the Sub did not map to a Msg, or a reducer throw under the default `stop`
120
+ * strategy, closes the child's scope, so `remove` and `notify` run.
93
121
  *
94
122
  * `child.run.stop()` is not one of the two ways to stop a child. It stops the
95
123
  * run and leaves the scope open, so the entry stays in the table and the
@@ -101,9 +129,7 @@ interface SpawnSteps<A, E = never, R = never> {
101
129
  * Effect.map(run(worker, {}), (run) => ({ run, scope })),
102
130
  * enrol: (child) => Effect.sync(() => children.set(id, child)),
103
131
  * remove: Effect.sync(() => children.delete(id)),
104
- * notify: tell(parent, parentRun, { type: "child_stopped", id }).pipe(
105
- * Effect.catch((failure) => Effect.logError("notice failed", failure)),
106
- * ),
132
+ * notify: tell(parent, parentRun, { type: "child_stopped", id }),
107
133
  * });
108
134
  * ```
109
135
  */
@@ -123,4 +149,71 @@ declare const spawn: <A, E = never, R = never>(parentScope: Scope.Scope, steps:
123
149
  */
124
150
  declare const stop: (scope: Scope.Closeable) => Effect.Effect<void>;
125
151
 
126
- export { EffectRuntime, type SpawnSteps, StoreFailed, spawn, stop, tell };
152
+ /**
153
+ * The Effect entry's `Cmd`: the core `Cmd` with a `define` that takes plain
154
+ * Effect schemas (#631). It is a function over the core `Cmd.define`, so the
155
+ * def it returns is the same `CmdDef` a hand-wrapped call builds.
156
+ */
157
+
158
+ /**
159
+ * An Effect schema that checks a value and hands the same type on. Both sides
160
+ * are one type, and decoding needs no service.
161
+ *
162
+ * tea types a handler's answer by the type the `ok` schema hands on, and checks
163
+ * that answer by parsing it. A schema whose two sides differ — a
164
+ * transformation like `Schema.FiniteFromString`, a brand — would refuse the
165
+ * very value the handler's type asks for, so it does not compile here. Pass
166
+ * `Schema.toType(schema)` to keep the checks and drop the translation.
167
+ */
168
+ type CheckingSchema<T> = Schema.Codec<T, NoInfer<T>>;
169
+ declare function define<const Name extends string, Input extends CmdInput, Ok, const Tags extends readonly string[]>(name: Name, spec: {
170
+ readonly input: CheckingSchema<Input>;
171
+ readonly ok: CheckingSchema<Ok>;
172
+ readonly err: Tags;
173
+ }): CmdDef<Name, Input, Ok, TaggedError<Tags[number]>>;
174
+ /**
175
+ * A Cmd value, as the core types it. Exported beside the `Cmd` helpers so an
176
+ * Effect user reads both from this entry.
177
+ */
178
+ type Cmd<T extends string = string, Ok = unknown, E = unknown> = Cmd$1<T, Ok, E>;
179
+ /**
180
+ * The helpers for building Cmds on the Effect engine. `Cmd.none`, `Cmd.batch`,
181
+ * `Cmd.when` and `Cmd.whenDefined` are the core's; `Cmd.define` is this
182
+ * entry's own.
183
+ */
184
+ declare const Cmd: {
185
+ /**
186
+ * Declare a typed Cmd constructor from plain Effect schemas. It returns what
187
+ * the core `Cmd.define` returns, with each schema passed through
188
+ * `Schema.toStandardSchemaV1` for you:
189
+ *
190
+ * const fetchUser = Cmd.define("fetch_user", {
191
+ * input: Schema.Struct({ id: Schema.String }),
192
+ * ok: Schema.Struct({ name: Schema.String }),
193
+ * err: ["not_found"],
194
+ * });
195
+ *
196
+ * `input` and `ok` take a schema that checks and never translates: both of
197
+ * its sides are one type and decoding needs no service. A transformation, a
198
+ * brand or a schema that needs a service is a compile error.
199
+ *
200
+ * To keep the checks of a transformation or a brand, pass
201
+ * `Schema.toType(schema)`. That is no way through for a schema that needs a
202
+ * service: its check lives in the decode step, and `Schema.toType` drops that
203
+ * step, so the Cmd would compile and never run the check. Run such a check in
204
+ * the handler.
205
+ *
206
+ * A schema whose validation needs a Promise compiles, and is refused with
207
+ * `AsyncSchemaError` when the Cmd settles, as the core's is.
208
+ *
209
+ * It takes Effect schemas only. A zod schema, or any other Standard Schema,
210
+ * goes to `Cmd.define` from `@demlik/tea`.
211
+ */
212
+ readonly define: typeof define;
213
+ readonly none: readonly never[];
214
+ readonly batch: <const C extends Cmd$1>(...arrs: readonly (readonly C[])[]) => readonly C[];
215
+ readonly when: <const C extends Cmd$1>(cond: boolean, cmd: C) => readonly C[];
216
+ readonly whenDefined: <T, const C extends Cmd$1>(value: T | undefined, build: (value: T) => C) => readonly C[];
217
+ };
218
+
219
+ export { type CheckingSchema, Cmd, EffectRun, type SpawnSteps, TellAnswer, spawn, stop, tell };
@@ -1,35 +1,49 @@
1
- export { Stopped, StoreFailed, run } from '../chunk-AIXC33SE.js';
2
- import '../chunk-UHAQ4PI6.js';
3
- import '../chunk-A73IJ27X.js';
4
- import { acceptedTypes, NoCellError } from '../chunk-RKVUVALV.js';
5
- import { Effect, Scope, Exit } from 'effect';
1
+ export { Stopped, StoreFailed, SubFailed, run, spawn, stop, tell } from '../chunk-SHXUSTHM.js';
2
+ import '../chunk-2A5XTKQQ.js';
3
+ import '../chunk-R2YNDRGL.js';
4
+ import '../chunk-DEAPNMKO.js';
5
+ import { Cmd } from '../chunk-A3QPMX5M.js';
6
+ import { Schema } from 'effect';
6
7
 
7
- var tell = (machine, runtime, msg) => Effect.suspend(
8
- () => acceptedTypes(machine, runtime.getState()).includes(msg.type) ? runtime.dispatch(msg) : Effect.void
9
- ).pipe(
10
- Effect.catchTag("Stopped", () => Effect.void),
11
- Effect.catchDefect(
12
- (defect) => defect instanceof NoCellError ? Effect.void : Effect.die(defect)
13
- )
14
- );
15
- var spawn = (parentScope, steps) => Effect.uninterruptible(
16
- Effect.gen(function* () {
17
- const scope = yield* Scope.fork(parentScope);
18
- yield* Scope.addFinalizer(
19
- scope,
20
- Effect.andThen(steps.remove, Effect.forkDetach(steps.notify))
21
- );
22
- const child = yield* steps.start(scope).pipe(
23
- Scope.provide(scope),
24
- Effect.onError((cause) => Scope.close(scope, Exit.failCause(cause)))
25
- );
26
- yield* steps.enrol(child);
27
- if (scope.state._tag === "Closed") yield* steps.remove;
28
- return child;
29
- })
30
- );
31
- var stop = (scope) => Scope.close(scope, Exit.void);
8
+ function define(name, spec) {
9
+ return Cmd.define(name, {
10
+ input: Schema.toStandardSchemaV1(spec.input),
11
+ ok: Schema.toStandardSchemaV1(spec.ok),
12
+ err: spec.err
13
+ });
14
+ }
15
+ var Cmd2 = {
16
+ ...Cmd,
17
+ /**
18
+ * Declare a typed Cmd constructor from plain Effect schemas. It returns what
19
+ * the core `Cmd.define` returns, with each schema passed through
20
+ * `Schema.toStandardSchemaV1` for you:
21
+ *
22
+ * const fetchUser = Cmd.define("fetch_user", {
23
+ * input: Schema.Struct({ id: Schema.String }),
24
+ * ok: Schema.Struct({ name: Schema.String }),
25
+ * err: ["not_found"],
26
+ * });
27
+ *
28
+ * `input` and `ok` take a schema that checks and never translates: both of
29
+ * its sides are one type and decoding needs no service. A transformation, a
30
+ * brand or a schema that needs a service is a compile error.
31
+ *
32
+ * To keep the checks of a transformation or a brand, pass
33
+ * `Schema.toType(schema)`. That is no way through for a schema that needs a
34
+ * service: its check lives in the decode step, and `Schema.toType` drops that
35
+ * step, so the Cmd would compile and never run the check. Run such a check in
36
+ * the handler.
37
+ *
38
+ * A schema whose validation needs a Promise compiles, and is refused with
39
+ * `AsyncSchemaError` when the Cmd settles, as the core's is.
40
+ *
41
+ * It takes Effect schemas only. A zod schema, or any other Standard Schema,
42
+ * goes to `Cmd.define` from `@demlik/tea`.
43
+ */
44
+ define
45
+ };
32
46
 
33
- export { spawn, stop, tell };
47
+ export { Cmd2 as Cmd };
34
48
  //# sourceMappingURL=index.js.map
35
49
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/effect/children.ts"],"names":[],"mappings":";;;;;;AAgCO,IAAM,IAAA,GAAO,CASlB,OAAA,EACA,OAAA,EACA,QAEA,MAAA,CAAO,OAAA;AAAA,EAAQ,MACb,aAAA,CAAc,OAAA,EAAS,OAAA,CAAQ,UAAU,CAAA,CAAE,QAAA,CAAS,GAAA,CAAI,IAAI,CAAA,GACxD,OAAA,CAAQ,QAAA,CAAS,GAAG,IACpB,MAAA,CAAO;AACb,CAAA,CAAE,IAAA;AAAA,EACA,MAAA,CAAO,QAAA,CAAS,SAAA,EAAW,MAAM,OAAO,IAAI,CAAA;AAAA,EAC5C,MAAA,CAAO,WAAA;AAAA,IAAY,CAAC,WAClB,MAAA,YAAkB,WAAA,GAAc,OAAO,IAAA,GAAO,MAAA,CAAO,IAAI,MAAM;AAAA;AAEnE;AAwEK,IAAM,KAAA,GAAQ,CACnB,WAAA,EACA,KAAA,KAEA,MAAA,CAAO,eAAA;AAAA,EACL,MAAA,CAAO,IAAI,aAAa;AACtB,IAAA,MAAM,KAAA,GAAQ,OAAO,KAAA,CAAM,IAAA,CAAK,WAAW,CAAA;AAG3C,IAAA,OAAO,KAAA,CAAM,YAAA;AAAA,MACX,KAAA;AAAA,MACA,MAAA,CAAO,QAAQ,KAAA,CAAM,MAAA,EAAQ,OAAO,UAAA,CAAW,KAAA,CAAM,MAAM,CAAC;AAAA,KAC9D;AACA,IAAA,MAAM,KAAA,GAAQ,OAAO,KAAA,CAAM,KAAA,CAAM,KAAK,CAAA,CAAE,IAAA;AAAA,MACtC,KAAA,CAAM,QAAQ,KAAK,CAAA;AAAA,MACnB,MAAA,CAAO,OAAA,CAAQ,CAAC,KAAA,KAAU,KAAA,CAAM,KAAA,CAAM,KAAA,EAAO,IAAA,CAAK,SAAA,CAAU,KAAK,CAAC,CAAC;AAAA,KACrE;AACA,IAAA,OAAO,KAAA,CAAM,MAAM,KAAK,CAAA;AAExB,IAAA,IAAI,KAAA,CAAM,KAAA,CAAM,IAAA,KAAS,QAAA,SAAiB,KAAA,CAAM,MAAA;AAChD,IAAA,OAAO,KAAA;AAAA,EACT,CAAC;AACH;AAeK,IAAM,OAAO,CAAC,KAAA,KACnB,MAAM,KAAA,CAAM,KAAA,EAAO,KAAK,IAAI","file":"index.js","sourcesContent":["/**\n * Helpers for running child machines under a parent on the Effect engine\n * (#556, ruling R1.1 of #554).\n *\n * tea still runs one machine per `run` and keeps no table of runs (#312). A\n * host that builds a tree of runs keeps its own table, ids and Msg names, and\n * hands the steps that race to these functions: `spawn` starts a child and\n * enrols it as one step, `stop` stops one child, and `tell` sends the parent a\n * notice it may no longer take.\n */\n\nimport { Effect, Exit, Scope } from \"effect\";\nimport type { Cmd, Machine, Sub } from \"../pure/core\";\nimport { acceptedTypes, NoCellError } from \"../pure/core\";\nimport type { StoreFailed } from \"./failures\";\nimport type { EffectRuntime } from \"./handle\";\n\n/**\n * Hand `msg` to a run only when its State has a cell for it, and drop it when\n * the run no longer takes it.\n *\n * `machine` is the machine `runtime` runs. The dispatch lands a moment after\n * the check, so a State that changed in between refuses the Msg with a\n * `NoCellError`, and a run that stopped refuses it with `Stopped`. Both mean\n * the run no longer takes the notice, so both are dropped and `tell` succeeds.\n * A failed save stays a `StoreFailed`, and a hand-written cell's declared\n * failure stays that failure.\n *\n * ```ts\n * yield* tell(parent, parentRun, { type: \"child_stopped\", id });\n * ```\n */\nexport const tell = <\n S,\n M extends { type: string },\n C extends Cmd,\n U extends Sub,\n Ctx,\n E extends { type: string } = never,\n Err = never,\n>(\n machine: Machine<S, M, C, U, Ctx>,\n runtime: EffectRuntime<S, M, E, Err>,\n msg: NoInfer<M>,\n): Effect.Effect<void, Err | StoreFailed> =>\n Effect.suspend(() =>\n acceptedTypes(machine, runtime.getState()).includes(msg.type)\n ? runtime.dispatch(msg)\n : Effect.void,\n ).pipe(\n Effect.catchTag(\"Stopped\", () => Effect.void),\n Effect.catchDefect((defect) =>\n defect instanceof NoCellError ? Effect.void : Effect.die(defect),\n ),\n ) as Effect.Effect<void, Err | StoreFailed>;\n\n/**\n * The host's own steps of a {@link spawn}. The host owns the table of\n * children, their ids and the parent's Msg names; `spawn` owns the order the\n * steps run in and keeps an interrupt from landing between them.\n */\nexport interface SpawnSteps<A, E = never, R = never> {\n /**\n * Start the child and return what the host keeps for it. It runs with the\n * child's scope provided, so a `run(machine, opts)` in it belongs to that\n * scope, and so does anything else it acquires. `scope` is the same scope,\n * for a host that keeps it to stop the child with `stop`. A failure\n * closes the child's scope, which runs `remove` and `notify`.\n */\n readonly start: (scope: Scope.Closeable) => Effect.Effect<A, E, R>;\n /** Add the started child to the host's table. */\n readonly enrol: (child: A) => Effect.Effect<unknown>;\n /**\n * Take the child out of the host's table. It runs when the child's scope\n * closes, after its run has stopped, whether or not `enrol` ran, so it must\n * be safe on a child the table does not hold.\n */\n readonly remove: Effect.Effect<unknown>;\n /**\n * Say the child stopped, usually a {@link tell} to the parent. It runs\n * after `remove`, on a fiber of its own that the closing scope never waits\n * for, so it may wait on the parent.\n *\n * It cannot fail: nothing reads that fiber, so the step itself handles what\n * its notice can fail with, such as the `StoreFailed` of a `tell`. A defect\n * in it is not observed by `spawn` and ends the fiber unseen.\n */\n readonly notify: Effect.Effect<unknown>;\n}\n\n/**\n * Start a child in a scope forked from `parentScope` and enrol it in the\n * host's table, as one uninterruptible step. Stop a child with `stop`,\n * or by closing its scope; closing `parentScope` stops every child spawned\n * under it.\n *\n * What it guarantees, with no guard in host code:\n *\n * - the table never holds a child whose scope has closed. The fork, the\n * removal finalizer, `start` and `enrol` all happen or none do, and a\n * child whose scope closed before `enrol` is removed again;\n * - closing a child never waits for the parent. `notify` runs on a detached\n * fiber, so a parent Cmd handler can stop a child;\n * - `remove` runs after the child's run has stopped.\n *\n * Nothing reads the fiber `notify` runs on, so `spawn` reports no failure of\n * it and `notify` is typed to have none. The host handles what its notice can\n * fail with inside the step, as the `Effect.catch` below does for a parent\n * whose save failed. A defect in `notify` ends that fiber unseen.\n *\n * `child.run.stop()` is not one of the two ways to stop a child. It stops the\n * run and leaves the scope open, so the entry stays in the table and the\n * parent is not told.\n *\n * ```ts\n * const child = yield* spawn(parentScope, {\n * start: (scope) =>\n * Effect.map(run(worker, {}), (run) => ({ run, scope })),\n * enrol: (child) => Effect.sync(() => children.set(id, child)),\n * remove: Effect.sync(() => children.delete(id)),\n * notify: tell(parent, parentRun, { type: \"child_stopped\", id }).pipe(\n * Effect.catch((failure) => Effect.logError(\"notice failed\", failure)),\n * ),\n * });\n * ```\n */\nexport const spawn = <A, E = never, R = never>(\n parentScope: Scope.Scope,\n steps: SpawnSteps<A, E, R>,\n): Effect.Effect<A, E, Exclude<R, Scope.Scope>> =>\n Effect.uninterruptible(\n Effect.gen(function* () {\n const scope = yield* Scope.fork(parentScope);\n // Added before `start`, so it runs after everything `start` put in the\n // scope has been released, the child's run included.\n yield* Scope.addFinalizer(\n scope,\n Effect.andThen(steps.remove, Effect.forkDetach(steps.notify)),\n );\n const child = yield* steps.start(scope).pipe(\n Scope.provide(scope),\n Effect.onError((cause) => Scope.close(scope, Exit.failCause(cause))),\n );\n yield* steps.enrol(child);\n // A scope that closed under `start` ran `remove` before `enrol`.\n if (scope.state._tag === \"Closed\") yield* steps.remove;\n return child;\n }),\n );\n\n/**\n * Stop one child that `spawn` started. `scope` is the child's scope,\n * the one its `start` was handed.\n *\n * It closes that scope, so the child's run stops, `remove` takes the entry\n * out of the host's table and `notify` tells the parent. It does not wait for\n * `notify`, so a parent Cmd handler can call it. Stopping a child that has\n * already stopped succeeds and sends no second notice.\n *\n * ```ts\n * yield* stop(child.scope);\n * ```\n */\nexport const stop = (scope: Scope.Closeable): Effect.Effect<void> =>\n Scope.close(scope, Exit.void);\n"]}
1
+ {"version":3,"sources":["../../src/effect/cmd.ts"],"names":["Cmd"],"mappings":";;;;;;;AA0BA,SAAS,MAAA,CAMP,MACA,IAAA,EAKoD;AACpD,EAAA,OAAO,GAAA,CAAQ,OAAO,IAAA,EAAM;AAAA,IAC1B,KAAA,EAAO,MAAA,CAAO,kBAAA,CAAmB,IAAA,CAAK,KAAK,CAAA;AAAA,IAC3C,EAAA,EAAI,MAAA,CAAO,kBAAA,CAAmB,IAAA,CAAK,EAAE,CAAA;AAAA,IACrC,KAAK,IAAA,CAAK;AAAA,GACX,CAAA;AACH;AAiBO,IAAMA,IAAAA,GAAM;AAAA,EACjB,GAAG,GAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA4BH;AACF","file":"index.js","sourcesContent":["/**\n * The Effect entry's `Cmd`: the core `Cmd` with a `define` that takes plain\n * Effect schemas (#631). It is a function over the core `Cmd.define`, so the\n * def it returns is the same `CmdDef` a hand-wrapped call builds.\n */\n\nimport { Schema } from \"effect\";\nimport {\n type CmdDef,\n type CmdInput,\n Cmd as CoreCmd,\n type TaggedError,\n} from \"../pure/core\";\n\n/**\n * An Effect schema that checks a value and hands the same type on. Both sides\n * are one type, and decoding needs no service.\n *\n * tea types a handler's answer by the type the `ok` schema hands on, and checks\n * that answer by parsing it. A schema whose two sides differ — a\n * transformation like `Schema.FiniteFromString`, a brand — would refuse the\n * very value the handler's type asks for, so it does not compile here. Pass\n * `Schema.toType(schema)` to keep the checks and drop the translation.\n */\nexport type CheckingSchema<T> = Schema.Codec<T, NoInfer<T>>;\n\nfunction define<\n const Name extends string,\n Input extends CmdInput,\n Ok,\n const Tags extends readonly string[],\n>(\n name: Name,\n spec: {\n readonly input: CheckingSchema<Input>;\n readonly ok: CheckingSchema<Ok>;\n readonly err: Tags;\n },\n): CmdDef<Name, Input, Ok, TaggedError<Tags[number]>> {\n return CoreCmd.define(name, {\n input: Schema.toStandardSchemaV1(spec.input),\n ok: Schema.toStandardSchemaV1(spec.ok),\n err: spec.err,\n });\n}\n\n/**\n * A Cmd value, as the core types it. Exported beside the `Cmd` helpers so an\n * Effect user reads both from this entry.\n */\nexport type Cmd<T extends string = string, Ok = unknown, E = unknown> = CoreCmd<\n T,\n Ok,\n E\n>;\n\n/**\n * The helpers for building Cmds on the Effect engine. `Cmd.none`, `Cmd.batch`,\n * `Cmd.when` and `Cmd.whenDefined` are the core's; `Cmd.define` is this\n * entry's own.\n */\nexport const Cmd = {\n ...CoreCmd,\n /**\n * Declare a typed Cmd constructor from plain Effect schemas. It returns what\n * the core `Cmd.define` returns, with each schema passed through\n * `Schema.toStandardSchemaV1` for you:\n *\n * const fetchUser = Cmd.define(\"fetch_user\", {\n * input: Schema.Struct({ id: Schema.String }),\n * ok: Schema.Struct({ name: Schema.String }),\n * err: [\"not_found\"],\n * });\n *\n * `input` and `ok` take a schema that checks and never translates: both of\n * its sides are one type and decoding needs no service. A transformation, a\n * brand or a schema that needs a service is a compile error.\n *\n * To keep the checks of a transformation or a brand, pass\n * `Schema.toType(schema)`. That is no way through for a schema that needs a\n * service: its check lives in the decode step, and `Schema.toType` drops that\n * step, so the Cmd would compile and never run the check. Run such a check in\n * the handler.\n *\n * A schema whose validation needs a Promise compiles, and is refused with\n * `AsyncSchemaError` when the Cmd settles, as the core's is.\n *\n * It takes Effect schemas only. A zod schema, or any other Standard Schema,\n * goes to `Cmd.define` from `@demlik/tea`.\n */\n define,\n} as const;\n"]}
@@ -1,7 +1,7 @@
1
- import { R as Runtime, M as Migrated, S as Store } from '../runtime-types-DEluQgGO.js';
1
+ import { R as Runtime, M as Migrated, b as Store } from '../runtime-types-CP-ykwgf.js';
2
2
  import { ReactNode } from 'react';
3
- import { S as Sub } from '../core-CtvAyPpH.js';
4
- import { S as SubscribeHandler } from '../types-CXNzlbAg.js';
3
+ import { c as Sub } from '../core-DNDAEhO2.js';
4
+ import { S as SubscribeHandler } from '../types-S53WDy_h.js';
5
5
  import '@standard-schema/spec';
6
6
 
7
7
  /**
@@ -1,5 +1,5 @@
1
- import { historyTracker, dispatchIfPresent } from '../chunk-DVNXEB7V.js';
2
- import { describeError } from '../chunk-RKVUVALV.js';
1
+ import { historyTracker, dispatchIfPresent } from '../chunk-BVFS3ICC.js';
2
+ import { describeError } from '../chunk-A3QPMX5M.js';
3
3
  import { useRef, useSyncExternalStore, useEffect, useCallback, createContext, useMemo, useContext } from 'react';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5