@typeonce/effect-machine 0.41.0 → 0.42.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 (67) hide show
  1. package/README.md +33 -6
  2. package/dist/Machine.d.ts +159 -27
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +20 -6
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/atom.d.ts +2 -7
  7. package/dist/internal/machine/atom.d.ts.map +1 -1
  8. package/dist/internal/machine/atom.js +132 -87
  9. package/dist/internal/machine/atom.js.map +1 -1
  10. package/dist/internal/machine/childRegistry.d.ts +7 -0
  11. package/dist/internal/machine/childRegistry.d.ts.map +1 -1
  12. package/dist/internal/machine/childRegistry.js +7 -0
  13. package/dist/internal/machine/childRegistry.js.map +1 -1
  14. package/dist/internal/machine/invocation.d.ts.map +1 -1
  15. package/dist/internal/machine/invocation.js +13 -2
  16. package/dist/internal/machine/invocation.js.map +1 -1
  17. package/dist/internal/machine/invocationDefinition.d.ts +7 -0
  18. package/dist/internal/machine/invocationDefinition.d.ts.map +1 -1
  19. package/dist/internal/machine/invocationDefinition.js +16 -0
  20. package/dist/internal/machine/invocationDefinition.js.map +1 -1
  21. package/dist/internal/machine/machine.d.ts.map +1 -1
  22. package/dist/internal/machine/machine.js +69 -6
  23. package/dist/internal/machine/machine.js.map +1 -1
  24. package/dist/internal/machine/plannedSnapshot.d.ts +30 -0
  25. package/dist/internal/machine/plannedSnapshot.d.ts.map +1 -0
  26. package/dist/internal/machine/plannedSnapshot.js +103 -0
  27. package/dist/internal/machine/plannedSnapshot.js.map +1 -0
  28. package/dist/internal/machine/planner.d.ts +5 -0
  29. package/dist/internal/machine/planner.d.ts.map +1 -1
  30. package/dist/internal/machine/planner.js +1 -1
  31. package/dist/internal/machine/planner.js.map +1 -1
  32. package/dist/internal/machine/runtime.d.ts +5 -4
  33. package/dist/internal/machine/runtime.d.ts.map +1 -1
  34. package/dist/internal/machine/runtime.js +60 -15
  35. package/dist/internal/machine/runtime.js.map +1 -1
  36. package/dist/internal/machine/runtimeCompiled.js +2 -2
  37. package/dist/internal/machine/runtimeCompiled.js.map +1 -1
  38. package/dist/internal/machine/runtimeGeneric.js +1 -1
  39. package/dist/internal/machine/runtimeGeneric.js.map +1 -1
  40. package/dist/internal/machine/runtimeProtocol.d.ts +2 -1
  41. package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -1
  42. package/dist/internal/machine/runtimeProtocol.js +2 -2
  43. package/dist/internal/machine/runtimeProtocol.js.map +1 -1
  44. package/dist/testing/MachineTest.d.ts +2 -2
  45. package/dist/testing/MachineTest.js +2 -2
  46. package/dist/unstable/reactivity/AtomMachine.d.ts +82 -19
  47. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  48. package/dist/unstable/reactivity/AtomMachine.js +0 -7
  49. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  50. package/docs/agent-guide.md +28 -5
  51. package/docs/effect-atom-react.md +207 -11
  52. package/docs/machine-review.md +18 -4
  53. package/package.json +4 -4
  54. package/src/Machine.ts +229 -32
  55. package/src/internal/machine/atom.ts +263 -113
  56. package/src/internal/machine/childRegistry.ts +9 -0
  57. package/src/internal/machine/invocation.ts +17 -2
  58. package/src/internal/machine/invocationDefinition.ts +19 -0
  59. package/src/internal/machine/machine.ts +65 -2
  60. package/src/internal/machine/plannedSnapshot.ts +113 -0
  61. package/src/internal/machine/planner.ts +1 -1
  62. package/src/internal/machine/runtime.ts +101 -28
  63. package/src/internal/machine/runtimeCompiled.ts +2 -2
  64. package/src/internal/machine/runtimeGeneric.ts +1 -1
  65. package/src/internal/machine/runtimeProtocol.ts +4 -2
  66. package/src/testing/MachineTest.ts +2 -2
  67. package/src/unstable/reactivity/AtomMachine.ts +90 -20
@@ -11,7 +11,7 @@ import type * as Schema from "effect/Schema"
11
11
  import type * as Scope from "effect/Scope"
12
12
  import type * as Stream from "effect/Stream"
13
13
  import * as internal from "../../internal/machine/atom.js"
14
- import type { ChildNotActiveError, NotReadyError } from "../../internal/machine/atom.js"
14
+ import type { ChildNotActiveError } from "../../internal/machine/atom.js"
15
15
  import type { EnsureExecutable } from "../../internal/machine/readiness.js"
16
16
  import type {
17
17
  ExcludeCompatibleRuntime as ExcludeCompatibleMachineRuntime,
@@ -19,14 +19,6 @@ import type {
19
19
  } from "../../internal/machine/requirements.js"
20
20
  import type * as Machine from "../../Machine.js"
21
21
 
22
- /**
23
- * Error returned when a machine command is issued before startup completes.
24
- *
25
- * @category errors
26
- * @since 0.4.0
27
- */
28
- export { NotReadyError } from "../../internal/machine/atom.js"
29
-
30
22
  /**
31
23
  * Error returned when a command targets a child machine that is not active.
32
24
  *
@@ -114,23 +106,34 @@ export interface MachineAtom<State, Event, Error = never, Output = never, StartE
114
106
  readonly result: Atom.Atom<AsyncResult.AsyncResult<State, StartError | Error>>
115
107
 
116
108
  /**
117
- * Writable atom that sends events to the machine. Writes before startup
118
- * completes fail with `NotReadyError`.
109
+ * Writable atom that sends events to the machine.
110
+ *
111
+ * **Details**
112
+ *
113
+ * Events written while the machine is still starting are held and delivered
114
+ * in write order once startup succeeds. The write result is waiting until
115
+ * the event is delivered, and fails with the startup failure when startup
116
+ * fails. Writes after the machine stopped or completed fail with
117
+ * `StoppedError`.
119
118
  *
120
119
  * @since 0.4.0
121
120
  */
122
121
  readonly send: Atom.Writable<
123
- AsyncResult.AsyncResult<void, StartError | NotReadyError | Machine.StoppedError>,
122
+ AsyncResult.AsyncResult<void, StartError | Machine.StoppedError>,
124
123
  Event
125
124
  >
126
125
 
127
126
  /**
128
- * Writable atom that stops the machine. Writes before startup completes fail
129
- * with `NotReadyError`.
127
+ * Writable atom that stops the machine.
128
+ *
129
+ * **Details**
130
+ *
131
+ * A stop written while the machine is still starting is held behind earlier
132
+ * writes and stops the machine as soon as startup succeeds.
130
133
  *
131
134
  * @since 0.4.0
132
135
  */
133
- readonly stop: Atom.Writable<AsyncResult.AsyncResult<void, StartError | NotReadyError>, void>
136
+ readonly stop: Atom.Writable<AsyncResult.AsyncResult<void, StartError>, void>
134
137
 
135
138
  /**
136
139
  * Creates a reactive bridge for a directly owned child machine.
@@ -144,6 +147,39 @@ export interface MachineAtom<State, Event, Error = never, Output = never, StartE
144
147
  ) => ChildMachineAtom<Child, StartError>
145
148
  }
146
149
 
150
+ /**
151
+ * Namespace containing type-level members associated with `MachineAtom`.
152
+ *
153
+ * @category models
154
+ * @since 0.42.0
155
+ */
156
+ export declare namespace MachineAtom {
157
+ /**
158
+ * Any machine bridge, including bridges for machines without events.
159
+ *
160
+ * @category utility types
161
+ * @since 0.42.0
162
+ */
163
+ export type Any = MachineAtom<any, never, any, any, any, any>
164
+
165
+ /**
166
+ * Extracts the state type of a machine bridge.
167
+ *
168
+ * @category utility types
169
+ * @since 0.42.0
170
+ */
171
+ export type State<A extends Any> = A extends MachineAtom<infer State, infer _Event, any, any, any, any> ? State
172
+ : never
173
+
174
+ /**
175
+ * Extracts the event type accepted by a machine bridge.
176
+ *
177
+ * @category utility types
178
+ * @since 0.42.0
179
+ */
180
+ export type Event<A extends Any> = A extends MachineAtom<any, infer Event, any, any, any, any> ? Event : never
181
+ }
182
+
147
183
  type RefState<Ref> = Ref extends Machine.MachineRef<infer State, any, any, any, any> ? State : never
148
184
 
149
185
  type RefError<Ref> = Ref extends Machine.MachineRef<any, any, infer Error, any, any> ? Error : never
@@ -251,23 +287,31 @@ export interface ChildMachineAtom<Child extends Machine.ChildMachine.Any, StartE
251
287
  /**
252
288
  * Writable atom that sends events to the active child.
253
289
  *
254
- * Writes fail with `ChildNotActiveError` while the child is inactive.
290
+ * **Details**
291
+ *
292
+ * Events written while the parent machine is still starting are held and
293
+ * delivered in write order once the parent is ready. Writes fail with
294
+ * `ChildNotActiveError` when the state that owns the child is not active.
255
295
  *
256
296
  * @since 0.4.0
257
297
  */
258
298
  readonly send: Atom.Writable<
259
- AsyncResult.AsyncResult<void, StartError | NotReadyError | ChildNotActiveError | Machine.StoppedError>,
299
+ AsyncResult.AsyncResult<void, StartError | ChildNotActiveError | Machine.StoppedError>,
260
300
  Machine.ChildMachine.Event<Child>
261
301
  >
262
302
  /**
263
303
  * Writable atom that stops the active child.
264
304
  *
265
- * Writes fail with `ChildNotActiveError` while the child is inactive.
305
+ * **Details**
306
+ *
307
+ * A stop written while the parent machine is still starting is held behind
308
+ * earlier writes. Writes fail with `ChildNotActiveError` when the state that
309
+ * owns the child is not active.
266
310
  *
267
311
  * @since 0.4.0
268
312
  */
269
313
  readonly stop: Atom.Writable<
270
- AsyncResult.AsyncResult<void, StartError | NotReadyError | ChildNotActiveError>,
314
+ AsyncResult.AsyncResult<void, StartError | ChildNotActiveError>,
271
315
  void
272
316
  >
273
317
  /**
@@ -282,6 +326,32 @@ export interface ChildMachineAtom<Child extends Machine.ChildMachine.Any, StartE
282
326
  ) => ChildMachineAtom<Nested, StartError>
283
327
  }
284
328
 
329
+ /**
330
+ * Namespace containing type-level members associated with `ChildMachineAtom`.
331
+ *
332
+ * @category models
333
+ * @since 0.42.0
334
+ */
335
+ export declare namespace ChildMachineAtom {
336
+ /**
337
+ * Any child machine bridge.
338
+ *
339
+ * @category utility types
340
+ * @since 0.42.0
341
+ */
342
+ export type Any = ChildMachineAtom<any, any>
343
+
344
+ /**
345
+ * Extracts the state type of the child selected by a child bridge.
346
+ *
347
+ * @category utility types
348
+ * @since 0.42.0
349
+ */
350
+ export type State<A extends Any> = A extends ChildMachineAtom<infer Child, any> ?
351
+ RefState<Machine.ChildMachine.Ref<Child>>
352
+ : never
353
+ }
354
+
285
355
  type BridgeStartError<Bridge> = Bridge extends MachineAtom<any, never, any, any, infer StartError, any> ? StartError
286
356
  : Bridge extends ChildMachineAtom<any, infer StartError> ? StartError
287
357
  : never
@@ -294,7 +364,7 @@ type BridgeStartError<Bridge> = Bridge extends MachineAtom<any, never, any, any,
294
364
  * @since 0.4.0
295
365
  */
296
366
  export type ChildOf<
297
- Parent extends MachineAtom<any, never, any, any, any, any> | ChildMachineAtom<any, any>,
367
+ Parent extends MachineAtom.Any | ChildMachineAtom.Any,
298
368
  Child extends Machine.ChildMachine.Any
299
369
  > = ChildMachineAtom<Child, BridgeStartError<Parent>>
300
370