@typeonce/effect-machine 0.41.1 → 0.43.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 +31 -4
  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 +3 -7
  7. package/dist/internal/machine/atom.d.ts.map +1 -1
  8. package/dist/internal/machine/atom.js +153 -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 +95 -19
  47. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  48. package/dist/unstable/reactivity/AtomMachine.js +13 -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 +262 -14
  52. package/docs/machine-review.md +18 -4
  53. package/package.json +1 -1
  54. package/src/Machine.ts +229 -32
  55. package/src/internal/machine/atom.ts +305 -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 +104 -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,53 @@ 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
+
183
+ /**
184
+ * Returns `true` if a value is a machine bridge created by `AtomMachine`.
185
+ *
186
+ * **Details**
187
+ *
188
+ * A child bridge returned by `child(...)` is not a machine bridge. Use this
189
+ * guard to accept both bridge kinds and select through `selectSnapshot` or
190
+ * `selectSnapshotChild` accordingly.
191
+ *
192
+ * @category guards
193
+ * @since 0.43.0
194
+ */
195
+ export const isMachineAtom: (u: unknown) => u is MachineAtom.Any = internal.isMachineAtom
196
+
147
197
  type RefState<Ref> = Ref extends Machine.MachineRef<infer State, any, any, any, any> ? State : never
148
198
 
149
199
  type RefError<Ref> = Ref extends Machine.MachineRef<any, any, infer Error, any, any> ? Error : never
@@ -251,23 +301,31 @@ export interface ChildMachineAtom<Child extends Machine.ChildMachine.Any, StartE
251
301
  /**
252
302
  * Writable atom that sends events to the active child.
253
303
  *
254
- * Writes fail with `ChildNotActiveError` while the child is inactive.
304
+ * **Details**
305
+ *
306
+ * Events written while the parent machine is still starting are held and
307
+ * delivered in write order once the parent is ready. Writes fail with
308
+ * `ChildNotActiveError` when the state that owns the child is not active.
255
309
  *
256
310
  * @since 0.4.0
257
311
  */
258
312
  readonly send: Atom.Writable<
259
- AsyncResult.AsyncResult<void, StartError | NotReadyError | ChildNotActiveError | Machine.StoppedError>,
313
+ AsyncResult.AsyncResult<void, StartError | ChildNotActiveError | Machine.StoppedError>,
260
314
  Machine.ChildMachine.Event<Child>
261
315
  >
262
316
  /**
263
317
  * Writable atom that stops the active child.
264
318
  *
265
- * Writes fail with `ChildNotActiveError` while the child is inactive.
319
+ * **Details**
320
+ *
321
+ * A stop written while the parent machine is still starting is held behind
322
+ * earlier writes. Writes fail with `ChildNotActiveError` when the state that
323
+ * owns the child is not active.
266
324
  *
267
325
  * @since 0.4.0
268
326
  */
269
327
  readonly stop: Atom.Writable<
270
- AsyncResult.AsyncResult<void, StartError | NotReadyError | ChildNotActiveError>,
328
+ AsyncResult.AsyncResult<void, StartError | ChildNotActiveError>,
271
329
  void
272
330
  >
273
331
  /**
@@ -282,6 +340,32 @@ export interface ChildMachineAtom<Child extends Machine.ChildMachine.Any, StartE
282
340
  ) => ChildMachineAtom<Nested, StartError>
283
341
  }
284
342
 
343
+ /**
344
+ * Namespace containing type-level members associated with `ChildMachineAtom`.
345
+ *
346
+ * @category models
347
+ * @since 0.42.0
348
+ */
349
+ export declare namespace ChildMachineAtom {
350
+ /**
351
+ * Any child machine bridge.
352
+ *
353
+ * @category utility types
354
+ * @since 0.42.0
355
+ */
356
+ export type Any = ChildMachineAtom<any, any>
357
+
358
+ /**
359
+ * Extracts the state type of the child selected by a child bridge.
360
+ *
361
+ * @category utility types
362
+ * @since 0.42.0
363
+ */
364
+ export type State<A extends Any> = A extends ChildMachineAtom<infer Child, any> ?
365
+ RefState<Machine.ChildMachine.Ref<Child>>
366
+ : never
367
+ }
368
+
285
369
  type BridgeStartError<Bridge> = Bridge extends MachineAtom<any, never, any, any, infer StartError, any> ? StartError
286
370
  : Bridge extends ChildMachineAtom<any, infer StartError> ? StartError
287
371
  : never
@@ -294,7 +378,7 @@ type BridgeStartError<Bridge> = Bridge extends MachineAtom<any, never, any, any,
294
378
  * @since 0.4.0
295
379
  */
296
380
  export type ChildOf<
297
- Parent extends MachineAtom<any, never, any, any, any, any> | ChildMachineAtom<any, any>,
381
+ Parent extends MachineAtom.Any | ChildMachineAtom.Any,
298
382
  Child extends Machine.ChildMachine.Any
299
383
  > = ChildMachineAtom<Child, BridgeStartError<Parent>>
300
384