@typeonce/effect-machine 0.8.0 → 0.10.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 (108) hide show
  1. package/README.md +180 -40
  2. package/dist/Machine.d.ts +659 -481
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +86 -222
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/activities.d.ts +5 -12
  7. package/dist/internal/machine/activities.d.ts.map +1 -1
  8. package/dist/internal/machine/activities.js +47 -17
  9. package/dist/internal/machine/activities.js.map +1 -1
  10. package/dist/internal/machine/atom.d.ts +6 -2
  11. package/dist/internal/machine/atom.d.ts.map +1 -1
  12. package/dist/internal/machine/atom.js +5 -0
  13. package/dist/internal/machine/atom.js.map +1 -1
  14. package/dist/internal/machine/cluster.d.ts.map +1 -1
  15. package/dist/internal/machine/cluster.js +2 -1
  16. package/dist/internal/machine/cluster.js.map +1 -1
  17. package/dist/internal/machine/command.js +2 -2
  18. package/dist/internal/machine/command.js.map +1 -1
  19. package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
  20. package/dist/internal/machine/commandRuntime.js +6 -3
  21. package/dist/internal/machine/commandRuntime.js.map +1 -1
  22. package/dist/internal/machine/configuration.d.ts +8 -1
  23. package/dist/internal/machine/configuration.d.ts.map +1 -1
  24. package/dist/internal/machine/configuration.js +9 -4
  25. package/dist/internal/machine/configuration.js.map +1 -1
  26. package/dist/internal/machine/errors.d.ts +1 -1
  27. package/dist/internal/machine/errors.d.ts.map +1 -1
  28. package/dist/internal/machine/executionPlan.d.ts +3 -3
  29. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  30. package/dist/internal/machine/executionPlan.js +74 -24
  31. package/dist/internal/machine/executionPlan.js.map +1 -1
  32. package/dist/internal/machine/invocation.d.ts +10 -2
  33. package/dist/internal/machine/invocation.d.ts.map +1 -1
  34. package/dist/internal/machine/invocation.js +94 -34
  35. package/dist/internal/machine/invocation.js.map +1 -1
  36. package/dist/internal/machine/invocationEvent.d.ts +39 -0
  37. package/dist/internal/machine/invocationEvent.d.ts.map +1 -0
  38. package/dist/internal/machine/invocationEvent.js +43 -0
  39. package/dist/internal/machine/invocationEvent.js.map +1 -0
  40. package/dist/internal/machine/machine.d.ts +16 -65
  41. package/dist/internal/machine/machine.d.ts.map +1 -1
  42. package/dist/internal/machine/machine.js +18 -73
  43. package/dist/internal/machine/machine.js.map +1 -1
  44. package/dist/internal/machine/planner.d.ts +4 -2
  45. package/dist/internal/machine/planner.d.ts.map +1 -1
  46. package/dist/internal/machine/planner.js +104 -24
  47. package/dist/internal/machine/planner.js.map +1 -1
  48. package/dist/internal/machine/process.d.ts.map +1 -1
  49. package/dist/internal/machine/process.js +8 -8
  50. package/dist/internal/machine/process.js.map +1 -1
  51. package/dist/internal/machine/protocol.d.ts +8 -5
  52. package/dist/internal/machine/protocol.d.ts.map +1 -1
  53. package/dist/internal/machine/protocol.js +207 -15
  54. package/dist/internal/machine/protocol.js.map +1 -1
  55. package/dist/internal/machine/runtime.d.ts +8 -2
  56. package/dist/internal/machine/runtime.d.ts.map +1 -1
  57. package/dist/internal/machine/runtime.js +86 -8
  58. package/dist/internal/machine/runtime.js.map +1 -1
  59. package/dist/internal/machine/symbols.d.ts +2 -0
  60. package/dist/internal/machine/symbols.d.ts.map +1 -1
  61. package/dist/internal/machine/symbols.js +2 -0
  62. package/dist/internal/machine/symbols.js.map +1 -1
  63. package/dist/internal/machine/topology.d.ts +7 -0
  64. package/dist/internal/machine/topology.d.ts.map +1 -1
  65. package/dist/internal/machine/topology.js +29 -0
  66. package/dist/internal/machine/topology.js.map +1 -1
  67. package/dist/internal/testing/machine/finiteModel.js +1 -1
  68. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  69. package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
  70. package/dist/internal/testing/machine/runtime.js +2 -1
  71. package/dist/internal/testing/machine/runtime.js.map +1 -1
  72. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  73. package/dist/internal/testing/machine/verification.js +5 -3
  74. package/dist/internal/testing/machine/verification.js.map +1 -1
  75. package/dist/testing/MachineTest.d.ts +7 -7
  76. package/dist/testing/MachineTest.js +7 -7
  77. package/dist/unstable/cluster/ClusterMachine.d.ts +1 -1
  78. package/dist/unstable/cluster/ClusterMachine.js +1 -1
  79. package/dist/unstable/reactivity/AtomMachine.d.ts +25 -8
  80. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  81. package/dist/unstable/reactivity/AtomMachine.js +18 -3
  82. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  83. package/docs/agent-guide.md +242 -122
  84. package/package.json +2 -2
  85. package/src/Machine.ts +1453 -812
  86. package/src/internal/machine/activities.ts +48 -33
  87. package/src/internal/machine/atom.ts +38 -13
  88. package/src/internal/machine/cluster.ts +2 -1
  89. package/src/internal/machine/command.ts +2 -2
  90. package/src/internal/machine/commandRuntime.ts +9 -4
  91. package/src/internal/machine/configuration.ts +23 -5
  92. package/src/internal/machine/errors.ts +1 -1
  93. package/src/internal/machine/executionPlan.ts +102 -28
  94. package/src/internal/machine/invocation.ts +182 -50
  95. package/src/internal/machine/invocationEvent.ts +72 -0
  96. package/src/internal/machine/machine.ts +80 -387
  97. package/src/internal/machine/planner.ts +127 -32
  98. package/src/internal/machine/process.ts +18 -8
  99. package/src/internal/machine/protocol.ts +313 -25
  100. package/src/internal/machine/runtime.ts +135 -9
  101. package/src/internal/machine/symbols.ts +3 -0
  102. package/src/internal/machine/topology.ts +38 -0
  103. package/src/internal/testing/machine/finiteModel.ts +1 -1
  104. package/src/internal/testing/machine/runtime.ts +2 -1
  105. package/src/internal/testing/machine/verification.ts +5 -3
  106. package/src/testing/MachineTest.ts +7 -7
  107. package/src/unstable/cluster/ClusterMachine.ts +1 -1
  108. package/src/unstable/reactivity/AtomMachine.ts +45 -13
package/dist/Machine.js CHANGED
@@ -13,6 +13,7 @@ import { InitialEventTypeId } from "./internal/machine/machine.js";
13
13
  * @since 0.4.0
14
14
  */
15
15
  export const TypeId = "~effect/Machine";
16
+ const ChildMachineLogicTypeId = internal.ChildMachineLogicTypeId;
16
17
  /**
17
18
  * Type identifier used for the synthetic event passed to startup lifecycle
18
19
  * actions.
@@ -142,7 +143,7 @@ export const isFinal = internal.isFinal;
142
143
  *
143
144
  * Machine.make({
144
145
  * states: States.states,
145
- * events: [],
146
+ * events: Machine.events(),
146
147
  * initial: () => States.initial.idle.from()
147
148
  * })
148
149
  * ```
@@ -162,10 +163,13 @@ export const defineStates = internal.defineStates;
162
163
  * `defineStates` or is passed inline. Call `handle` on the returned definition
163
164
  * to implement state behavior with ordinary TypeScript control flow.
164
165
  *
165
- * Schemas in `events` define the public input protocol. Schemas in
166
- * `internalEvents` are added to the complete handler protocol for invoke
167
- * results, child emissions, and other machine-local deliveries. Their tags
168
- * must be disjoint.
166
+ * `Machine.events` defines the public input protocol. `Machine.internalEvents`
167
+ * adds raised events and other machine-local deliveries.
168
+ * `Machine.emittedEvents` defines outward ephemeral notifications, while
169
+ * `parentEvents` declares the inputs a child may explicitly send to its owning
170
+ * actor. All descriptors expose deferred constructors while retaining their
171
+ * schemas opaquely for runtime validation. Public and internal tags must be
172
+ * disjoint.
169
173
  *
170
174
  * **Example** (Typed counter machine)
171
175
  *
@@ -182,10 +186,11 @@ export const defineStates = internal.defineStates;
182
186
  * }) {}
183
187
  *
184
188
  * const States = Machine.defineStates({ Count })
189
+ * const Events = Machine.events(Increment)
185
190
  *
186
191
  * const counter = Machine.make({
187
192
  * states: States.states,
188
- * events: [Increment],
193
+ * events: Events,
189
194
  * initial: () => States.initial.Count(new Count({ value: 0 }))
190
195
  * }).handle({
191
196
  * Count: {
@@ -203,45 +208,58 @@ export const defineStates = internal.defineStates;
203
208
  */
204
209
  export const make = internal.make;
205
210
  /**
206
- * Constructs an event from a schema owned by a machine's protocol.
211
+ * Defines a public event protocol and returns deferred constructors for every
212
+ * statically finite configured event tag.
207
213
  *
208
- * **Details**
209
- *
210
- * The schema constructor runs exactly once. The resulting decoded event is
211
- * trusted by this machine and definitions derived from it with `handle`, so
212
- * repeated delivery does not decode the same already-constructed value again.
213
- * Events supplied through ordinary `send` and `plan` calls remain untrusted
214
- * and continue through full runtime schema validation.
215
- * Treat the returned event as immutable after construction.
216
- *
217
- * The schema must be one of the machine's configured public or internal event
218
- * schemas, or a case schema belonging to a configured `Schema.TaggedUnion`.
214
+ * Constructor inputs retain their schema-derived required fields, defaults,
215
+ * and transformations. Construction is deferred until delivery so failures
216
+ * enter the machine's `MachineSchemaDecodeError` channel rather than throwing
217
+ * at the call site.
219
218
  *
220
219
  * **Example**
221
220
  *
222
221
  * ```ts
223
- * import { Schema } from "effect"
224
- * import { Machine } from "@typeonce/effect-machine"
222
+ * const Events = Machine.events(Increment, Reset)
223
+ * const machine = Machine.make({ events: Events, ... })
224
+ * yield* ref.send(Events.Increment({ by: 1 }))
225
+ * ```
225
226
  *
226
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
227
- * class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {
228
- * by: Schema.Number
229
- * }) {}
227
+ * @category constructors
228
+ * @since 0.10.0
229
+ */
230
+ export const events = internal.events;
231
+ /**
232
+ * Defines an internal event protocol and returns deferred constructors for
233
+ * every statically finite configured event tag.
230
234
  *
231
- * const States = Machine.defineStates({ Idle })
232
- * const counter = Machine.make({
233
- * states: States.states,
234
- * events: [Increment],
235
- * initial: () => States.initial.Idle.from()
236
- * }).handle({ Idle: { on: { Increment: () => States.initial.Idle.from() } } })
235
+ * Use these constructors for raised events and other machine-local deliveries.
236
+ * Construction failures are reported through the
237
+ * owning machine's `MachineSchemaDecodeError` channel.
238
+ *
239
+ * **Example**
237
240
  *
238
- * const increment = Machine.event(counter, Increment, { by: 1 })
241
+ * ```ts
242
+ * const InternalEvents = Machine.internalEvents(Loaded, Failed)
243
+ * const machine = Machine.make({ internalEvents: InternalEvents, ... })
244
+ *
245
+ * // Inside a transition callback:
246
+ * enqueue.raise(InternalEvents.Loaded({ value }))
239
247
  * ```
240
248
  *
241
249
  * @category constructors
242
- * @since 0.4.0
250
+ * @since 0.10.0
243
251
  */
244
- export const event = internal.event;
252
+ export const internalEvents = internal.internalEvents;
253
+ /**
254
+ * Defines the ephemeral notifications a machine may publish to external
255
+ * observers. Emitted events are separate from actor input and are never sent
256
+ * implicitly to a parent actor. Observe them through `MachineRef.emissions` or
257
+ * the AtomMachine emission stream adapters.
258
+ *
259
+ * @category constructors
260
+ * @since 0.10.0
261
+ */
262
+ export const emittedEvents = internal.emittedEvents;
245
263
  /**
246
264
  * Encodes a decoded machine snapshot into a normalized data representation.
247
265
  *
@@ -275,7 +293,7 @@ export const event = internal.event;
275
293
  * const States = Machine.defineStates({ Idle })
276
294
  * const machine = Machine.make({
277
295
  * states: States.states,
278
- * events: [],
296
+ * events: Machine.events(),
279
297
  * initial: () => States.initial.Idle.from()
280
298
  * }).handle({ Idle: {} })
281
299
  *
@@ -319,7 +337,7 @@ export const encodeSnapshot = internal.encodeSnapshot;
319
337
  * const States = Machine.defineStates({ Idle })
320
338
  * const machine = Machine.make({
321
339
  * states: States.states,
322
- * events: [],
340
+ * events: Machine.events(),
323
341
  * initial: () => States.initial.Idle.from()
324
342
  * }).handle({ Idle: {} })
325
343
  *
@@ -336,147 +354,37 @@ export const encodeSnapshot = internal.encodeSnapshot;
336
354
  */
337
355
  export const decodeSnapshot = internal.decodeSnapshot;
338
356
  /**
339
- * Creates an invoked child process configuration for an active state.
357
+ * Preserves inference for a state-owned invocation configuration.
340
358
  *
341
- * **When to use**
342
- *
343
- * Use to run a child process while a machine remains in a state. Successful
344
- * outputs are sent directly to the parent machine as events; `void` sends
345
- * nothing. Unrecovered child failures fail the owning machine. Active
346
- * snapshots can optionally be mapped to progress events.
347
- *
348
- * **Gotchas**
359
+ * Use `effect` for one-shot work, `after` for a cancellable timer, `logic` for
360
+ * reusable process logic, or `child` for a complete child machine. `onDone` is
361
+ * required whenever the source can complete with an output, while `onFailure`
362
+ * is required only when the source has a typed failure channel.
349
363
  *
350
- * Invoked child processes run while their owning state is active and are
351
- * stopped before the state exits. An unrecovered child failure fails the owning
352
- * machine; recover inside the child Effect when failure should become an event.
353
- * The `id` is a state-local lifecycle key, not a communication address. To
354
- * send events to the invocation, pass a typed `childAddress` as `address`.
355
- * The `src` callback is intentionally independent from its parent state. When
356
- * construction depends on the typed state, lifecycle event, or runtime, use
357
- * the state config factory form `invoke: (context) => Machine.invoke(...)` and
358
- * close over that context from `src`.
359
- *
360
- * **Example** (Effect output as a parent event)
364
+ * This constructor is an identity at runtime, but preserves lifecycle callback
365
+ * inference through published declarations. Effects and durations may be
366
+ * supplied directly or derived from the owning state's entry context. Dynamic
367
+ * Effect sources infer the owner context, output, error, and service channels
368
+ * together without a return annotation. Logic invocations require both a
369
+ * lifecycle `id` and a typed communication `address`. Child descriptors already
370
+ * own their identity, so `id` and `address` must not be repeated.
361
371
  *
362
372
  * ```ts
363
- * import { Effect, Schema } from "effect"
364
- * import { Machine } from "@typeonce/effect-machine"
365
- *
366
- * class Loaded extends Schema.TaggedClass<Loaded>("Loaded")("Loaded", {
367
- * value: Schema.String
368
- * }) {}
369
- *
370
- * const load = Machine.invoke({
373
+ * invoke: Machine.invoke({
371
374
  * id: "load",
372
- * src: () => Machine.effect(Effect.succeed(new Loaded({ value: "ready" })))
375
+ * effect: Effect.tryPromise({
376
+ * try: () => fetch("/api/data").then((response) => response.json()),
377
+ * catch: (cause) => new LoadError({ cause })
378
+ * }),
379
+ * onDone: ({ output, target }) => target.full.Ready({ data: output }),
380
+ * onFailure: ({ error, target }) => target.full.Failed({ error })
373
381
  * })
374
382
  * ```
375
383
  *
376
- * @see {@link effect} for one-shot child effects.
377
- * @see {@link spawn} for children whose lifetime is controlled by actions.
378
- * @category constructors
379
- * @since 0.4.0
380
- */
381
- export const invoke = internal.invoke;
382
- /**
383
- * Invokes one Effect and maps its typed outcome into machine-local events.
384
- *
385
- * **Details**
386
- *
387
- * This is the high-level one-shot counterpart to `invoke`. Success and typed
388
- * failure values are mapped independently, so callers do not need to recover
389
- * an Effect into a common event union by hand. Defects and interruption remain
390
- * failures of the owning machine.
391
- *
392
- * Declare mapped outcomes in `internalEvents` unless they are also legitimate
393
- * public commands.
394
- *
395
- * **Example**
396
- *
397
- * ```ts
398
- * import { Effect, Schema } from "effect"
399
- * import { Machine } from "@typeonce/effect-machine"
400
- *
401
- * class Loaded extends Schema.TaggedClass<Loaded>("Loaded")("Loaded", {
402
- * value: Schema.String
403
- * }) {}
404
- *
405
- * const load = Machine.invokeEffect({
406
- * id: "load",
407
- * effect: Effect.succeed("ready"),
408
- * onSuccess: (value) => new Loaded({ value })
409
- * })
410
- * ```
411
- *
412
- * @see {@link invoke} for arbitrary child process logic.
413
- * @see {@link after} for a state-scoped delayed event.
414
- * @category constructors
415
- * @since 0.4.0
416
- */
417
- export const invokeEffect = internal.invokeEffect;
418
- /**
419
- * Creates a cancellable state-scoped delayed event.
420
- *
421
- * The timer starts when its owning state is entered and is interrupted when
422
- * that state exits. The delayed value should normally be declared in
423
- * `internalEvents`.
424
- *
425
- * **Example**
426
- *
427
- * ```ts
428
- * import { Schema } from "effect"
429
- * import { Machine } from "@typeonce/effect-machine"
430
- *
431
- * class TimedOut extends Schema.TaggedClass<TimedOut>("TimedOut")("TimedOut", {}) {}
432
- *
433
- * const timeout = Machine.after("5 seconds", new TimedOut({}))
434
- * ```
435
- *
436
- * @category constructors
437
- * @since 0.4.0
438
- */
439
- export const after = internal.after;
440
- /**
441
- * Constructs another tagged case from compatible source fields.
442
- *
443
- * The target must be one tagged struct or tagged class whose discriminator is
444
- * supplied by its constructor. Union wrappers are rejected because their
445
- * `make` operation cannot select a member after the source discriminator has
446
- * been discarded. Missing or incompatible required target fields must be
447
- * supplied by the patch, and the target schema's normal `make` validation
448
- * remains authoritative at runtime.
449
- *
450
384
  * @category constructors
451
- * @since 0.4.0
385
+ * @since 0.9.0
452
386
  */
453
- export const retag = internal.retag;
454
- /**
455
- * Creates an invoked child process from a complete statechart machine.
456
- *
457
- * **When to use**
458
- *
459
- * Use when a state should own another statechart machine and communicate with
460
- * it through typed child events, emissions, snapshots, or terminal output.
461
- *
462
- * **Details**
463
- *
464
- * Child emissions are delivered directly to the parent as events. Active
465
- * snapshots and terminal output can be mapped to parent events. The owning
466
- * state controls the child lifetime.
467
- *
468
- * **Gotchas**
469
- *
470
- * Active invoked machines must have unique child addresses. A machine starts
471
- * after its owning state's entry actions, so those actions cannot send events
472
- * to a newly entered child. Unrecovered child failures fail the parent.
473
- *
474
- * @see {@link invoke} for invoking lower-level process logic.
475
- * @see {@link sendTo} for sending events to the invoked machine.
476
- * @category constructors
477
- * @since 0.4.0
478
- */
479
- export const invokeMachine = internal.invokeMachine;
387
+ export const invoke = ((config) => config);
480
388
  /**
481
389
  * Plans the initial state for a machine without executing actor commands.
482
390
  *
@@ -505,7 +413,7 @@ export const invokeMachine = internal.invokeMachine;
505
413
  * const States = Machine.defineStates({ Idle })
506
414
  * const machine = Machine.make({
507
415
  * states: States.states,
508
- * events: [],
416
+ * events: Machine.events(),
509
417
  * initial: () => States.initial.Idle.from()
510
418
  * }).handle({ Idle: {} })
511
419
  *
@@ -553,10 +461,9 @@ export const transitionDefinitions = internal.transitionDefinitions;
553
461
  *
554
462
  * **Details**
555
463
  *
556
- * Static `invoke`, `invokeEffect`, `after`, and `invokeMachine` descriptors
557
- * expose stable ownership and lifecycle metadata without serializing runtime
558
- * values. Function-valued invoke factories are represented as dynamic and are
559
- * never evaluated during inspection.
464
+ * Static inline invocation definitions expose stable ownership and lifecycle
465
+ * metadata without serializing runtime values. Function-valued sources are
466
+ * represented as dynamic and are never evaluated during inspection.
560
467
  *
561
468
  * @category getters
562
469
  * @since 0.4.0
@@ -611,7 +518,7 @@ export const enabled = internal.enabled;
611
518
  * const States = Machine.defineStates({ Off, On })
612
519
  * const machine = Machine.make({
613
520
  * states: States.states,
614
- * events: [Toggle],
521
+ * events: Machine.events(Toggle),
615
522
  * initial: () => States.initial.Off.from()
616
523
  * }).handle({ Off: { on: { Toggle: () => States.initial.On.from() } }, On: {} })
617
524
  *
@@ -627,49 +534,6 @@ export const enabled = internal.enabled;
627
534
  * @since 0.4.0
628
535
  */
629
536
  export const plan = internal.plan;
630
- /**
631
- * Creates a one-shot child process from an Effect.
632
- *
633
- * **When to use**
634
- *
635
- * Use when you need side effects that produce one typed output or error.
636
- *
637
- * **Details**
638
- *
639
- * The Effect may run arbitrary side effects. Its success value is the process
640
- * output, its typed error is preserved, and its services are inferred. When
641
- * invoked, the output is sent to the owning machine as an event unless it is
642
- * `void`.
643
- *
644
- * **Gotchas**
645
- *
646
- * This process has no incoming event protocol. Its Effect runs once. Use
647
- * `transition` for a process that receives events over time and `logic` for
648
- * direct machine-local communication or intermediate snapshots.
649
- *
650
- * **Example** (Recover a child failure as output)
651
- *
652
- * ```ts
653
- * import { Effect, Schema } from "effect"
654
- * import { Machine } from "@typeonce/effect-machine"
655
- *
656
- * class LoadFailed extends Schema.TaggedClass<LoadFailed>("LoadFailed")("LoadFailed", {
657
- * reason: Schema.String
658
- * }) {}
659
- *
660
- * const load = Machine.effect(
661
- * Effect.fail("unavailable").pipe(
662
- * Effect.catch((reason) => Effect.succeed(new LoadFailed({ reason })))
663
- * )
664
- * )
665
- * ```
666
- *
667
- * @see {@link transition} for event-driven state.
668
- * @see {@link logic} for direct control over intermediate snapshots.
669
- * @category constructors
670
- * @since 0.4.0
671
- */
672
- export const effect = internal.effect;
673
537
  /**
674
538
  * Creates advanced stateful process logic from explicit initialization and
675
539
  * execution methods.
@@ -691,9 +555,9 @@ export const effect = internal.effect;
691
555
  * This is the low-level process constructor. Parent messages sent directly
692
556
  * through its scope are intentionally `unknown` because the logic does not know
693
557
  * which machine will eventually own it. Prefer typed output, typed child
694
- * addresses, or invoke snapshot mapping when possible.
558
+ * addresses, or invocation lifecycle transitions when possible.
695
559
  *
696
- * @see {@link effect} for one-shot work.
560
+ * Use an inline `invoke` with an `effect` source for one-shot work.
697
561
  * @see {@link transition} for event-driven state.
698
562
  * @category constructors
699
563
  * @since 0.4.0
@@ -724,7 +588,7 @@ export const logic = internal.logic;
724
588
  * )
725
589
  * ```
726
590
  *
727
- * @see {@link effect} for one-shot work.
591
+ * Use an inline `invoke` with an `effect` source for one-shot work.
728
592
  * @see {@link logic} for direct process lifecycle control.
729
593
  * @category constructors
730
594
  * @since 0.4.0
@@ -823,7 +687,7 @@ export const watch = internal.watch;
823
687
  * const States = Machine.defineStates({ Idle })
824
688
  * const machine = Machine.make({
825
689
  * states: States.states,
826
- * events: [],
690
+ * events: Machine.events(),
827
691
  * initial: () => States.initial.Idle.from()
828
692
  * }).handle({ Idle: {} })
829
693
  *
@@ -849,8 +713,8 @@ export const start = internal.start;
849
713
  * entry or transition actions, re-deliver raised or emitted events, or
850
714
  * re-evaluate historical completion and eventless transitions. Active-state
851
715
  * invokes start once in ancestor and document order with {@link InitialEvent};
852
- * delayed invokes restart their complete duration and invoked machines start
853
- * from their own initial state.
716
+ * timer invocations restart their complete duration and child-machine
717
+ * invocations start from their own initial state.
854
718
  *
855
719
  * Only logical state, completion, and history metadata are resumed. Queues,
856
720
  * scopes, subscriptions, fibers, spawned children, invoke progress, and prior
@@ -873,7 +737,7 @@ export const start = internal.start;
873
737
  * const States = Machine.defineStates({ Idle })
874
738
  * const machine = Machine.make({
875
739
  * states: States.states,
876
- * events: [],
740
+ * events: Machine.events(),
877
741
  * initial: () => States.initial.Idle.from()
878
742
  * }).handle({ Idle: {} })
879
743
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Machine.js","sourceRoot":"","sources":["../src/Machine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAc9C,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAA;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAelE;;;;;GAKG;AACH,MAAM,CAAC,M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,CAAA;AAE1E;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,KAAK,GAChB,QAAQ,CAAC,KAAK,CAAA;AAEhB;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAuD,QAAQ,CAAC,YAAY,CAAA;AAErG;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,KAAK,GAsCd,QAAQ,CAAC,KAAK,CAAA;AAElB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GASf,QAAQ,CAAC,MAAM,CAAA;AAEnB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAGlB,QAAQ,CAAC,SAAS,CAAA;AAEtB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAEyC,QAAQ,CAAC,KAAK,CAAA;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,CAAC,MAAM,KAAK,GA2Dd,QAAQ,CAAC,KAAY,CAAA;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,CAAC,MAAM,MAAM,GAqDf,QAAQ,CAAC,MAAa,CAAA"}
@@ -4,8 +4,6 @@
4
4
  * @since 0.4.0
5
5
  */
6
6
  /** @internal */
7
- export declare const ActivityMetadataTypeId: unique symbol;
8
- /** @internal */
9
7
  export type StaticActivityMetadata = {
10
8
  readonly type: "process";
11
9
  } | {
@@ -16,8 +14,7 @@ export type StaticActivityMetadata = {
16
14
  };
17
15
  } | {
18
16
  readonly type: "timer";
19
- readonly duration: string;
20
- readonly event: string;
17
+ readonly duration: string | "dynamic";
21
18
  } | {
22
19
  readonly type: "machine";
23
20
  readonly child: {
@@ -26,13 +23,10 @@ export type StaticActivityMetadata = {
26
23
  };
27
24
  };
28
25
  /** @internal */
29
- export type ActivityDefinition<Source extends string = string> = ({
26
+ export type ActivityDefinition<Source extends string = string> = {
30
27
  readonly source: Source;
31
28
  readonly id: string;
32
- } & StaticActivityMetadata) | {
33
- readonly source: Source;
34
- readonly type: "dynamic";
35
- };
29
+ } & StaticActivityMetadata;
36
30
  interface InspectableMachine {
37
31
  readonly handlers: unknown;
38
32
  readonly stateNodes: {
@@ -46,9 +40,8 @@ interface InspectableMachine {
46
40
  /**
47
41
  * Collects state-owned activity descriptions without executing user code.
48
42
  *
49
- * Function-valued invoke definitions depend on an entry context and are
50
- * therefore represented as dynamic. Static descriptors are returned in state
51
- * definition order and descriptor array order.
43
+ * Source factories are inspected without execution. Static descriptors are
44
+ * returned in state definition order and descriptor array order.
52
45
  *
53
46
  * @internal
54
47
  */
@@ -1 +1 @@
1
- {"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../../src/internal/machine/activities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gBAAgB;AAChB,eAAO,MAAM,sBAAsB,EAAE,OAAO,MAAsD,CAAA;AAElG,gBAAgB;AAChB,MAAM,MAAM,sBAAsB,GAC9B;IACA,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CACzB,GACC;IACA,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,QAAQ,EAAE;QACjB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAA;QAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,GAAG,MAAM,CAAA;KACrC,CAAA;CACF,GACC;IACA,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,GACC;IACA,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;QACnB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;KAClC,CAAA;CACF,CAAA;AAEH,gBAA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QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;QACnB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;KAClC,CAAA;CACF,CAAA;AAEH,gBAAgB;AAChB,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI;IAC/D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CACpB,GAAG,sBAAsB,CAAA;AAE1B,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE;QACnB,QAAQ,CAAC,MAAM,EAAE;YACf,MAAM,IAAI,QAAQ,CAAC;gBAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;aAAE,CAAC,CAAA;SAC9C,CAAA;KACF,CAAA;CACF;AAwDD;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,kBAAkB,KAAG,aAAa,CAAC,kBAAkB,CAajG,CAAA"}
@@ -3,28 +3,61 @@
3
3
  *
4
4
  * @since 0.4.0
5
5
  */
6
- /** @internal */
7
- export const ActivityMetadataTypeId = Symbol.for("effect/Machine/ActivityMetadata");
6
+ import * as Duration from "effect/Duration";
8
7
  const isObject = (value) => (typeof value === "object" && value !== null) || typeof value === "function";
9
8
  const getProperty = (value, key) => isObject(value) ? Reflect.get(value, key) : undefined;
10
- const hasActivityMetadata = (value) => isObject(value) && typeof getProperty(value, "id") === "string" &&
11
- isObject(getProperty(value, ActivityMetadataTypeId));
12
9
  const appendStaticDefinition = (definitions, source, descriptor) => {
13
- if (!hasActivityMetadata(descriptor)) {
10
+ if (!isObject(descriptor))
11
+ return;
12
+ const child = getProperty(descriptor, "child");
13
+ if (isObject(child)) {
14
+ const id = getProperty(child, "id");
15
+ if (typeof id !== "string")
16
+ return;
17
+ const machine = getProperty(child, "machine");
18
+ const machineId = getProperty(machine, "id");
19
+ definitions.push({
20
+ source,
21
+ id,
22
+ type: "machine",
23
+ child: { id, machineId: typeof machineId === "string" ? machineId : null }
24
+ });
25
+ return;
26
+ }
27
+ const id = getProperty(descriptor, "id");
28
+ if (typeof id !== "string")
29
+ return;
30
+ if (Reflect.has(descriptor, "effect")) {
31
+ definitions.push({
32
+ source,
33
+ id,
34
+ type: "effect",
35
+ outcomes: {
36
+ success: "dynamic",
37
+ failure: Reflect.has(descriptor, "onFailure") ? "dynamic" : "none"
38
+ }
39
+ });
14
40
  return;
15
41
  }
16
- definitions.push({
17
- source,
18
- id: descriptor.id,
19
- ...descriptor[ActivityMetadataTypeId]
20
- });
42
+ if (Reflect.has(descriptor, "after")) {
43
+ const after = getProperty(descriptor, "after");
44
+ definitions.push({
45
+ source,
46
+ id,
47
+ type: "timer",
48
+ duration: typeof after === "function" ? "dynamic" : Duration.format(Duration.fromInputUnsafe(after))
49
+ });
50
+ return;
51
+ }
52
+ if (Reflect.has(descriptor, "logic")) {
53
+ definitions.push({ source, id, type: "process" });
54
+ }
21
55
  };
22
56
  /**
23
57
  * Collects state-owned activity descriptions without executing user code.
24
58
  *
25
- * Function-valued invoke definitions depend on an entry context and are
26
- * therefore represented as dynamic. Static descriptors are returned in state
27
- * definition order and descriptor array order.
59
+ * Source factories are inspected without execution. Static descriptors are
60
+ * returned in state definition order and descriptor array order.
28
61
  *
29
62
  * @internal
30
63
  */
@@ -32,10 +65,7 @@ export const activityDefinitions = (machine) => {
32
65
  const definitions = [];
33
66
  for (const node of machine.stateNodes.byPath.values()) {
34
67
  const invoke = getProperty(getProperty(machine.handlers, node.path), "invoke");
35
- if (typeof invoke === "function") {
36
- definitions.push({ source: node.path, type: "dynamic" });
37
- }
38
- else if (Array.isArray(invoke)) {
68
+ if (Array.isArray(invoke)) {
39
69
  for (const descriptor of invoke) {
40
70
  appendStaticDefinition(definitions, node.path, descriptor);
41
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"activities.js","sourceRoot":"","sources":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