@typeonce/effect-machine 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -3
- package/dist/Machine.d.ts +258 -88
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +33 -33
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/activities.d.ts +2 -0
- package/dist/internal/machine/activities.d.ts.map +1 -1
- package/dist/internal/machine/activities.js +4 -0
- package/dist/internal/machine/activities.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +6 -1
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts +1 -1
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +25 -3
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationEvent.d.ts +8 -0
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
- package/dist/internal/machine/invocationEvent.js +8 -0
- package/dist/internal/machine/invocationEvent.js.map +1 -1
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +119 -48
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +7 -0
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +20 -11
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts +1 -0
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +25 -16
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +11 -0
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +17 -6
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/transitionCoverage.d.ts.map +1 -1
- package/dist/internal/testing/machine/transitionCoverage.js +6 -2
- package/dist/internal/testing/machine/transitionCoverage.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +6 -0
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +2 -1
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js.map +1 -1
- package/docs/agent-guide.md +63 -37
- package/package.json +1 -1
- package/src/Machine.ts +592 -159
- package/src/internal/machine/activities.ts +7 -0
- package/src/internal/machine/executionPlan.ts +6 -1
- package/src/internal/machine/invocation.ts +39 -4
- package/src/internal/machine/invocationEvent.ts +16 -0
- package/src/internal/machine/machine.ts +160 -47
- package/src/internal/machine/planner.ts +17 -3
- package/src/internal/machine/runtime.ts +61 -25
- package/src/internal/machine/topology.ts +31 -2
- package/src/internal/testing/machine/transitionCoverage.ts +6 -2
- package/src/internal/testing/machine/verification.ts +11 -0
- package/src/testing/MachineTest.ts +2 -0
package/README.md
CHANGED
|
@@ -413,7 +413,7 @@ synchronous. Conditions use ordinary TypeScript control flow. Callbacks may
|
|
|
413
413
|
select state and enqueue explicit `raise`, `emit`, `sendTo`, or `stop` commands;
|
|
414
414
|
arbitrary asynchronous Effects do not run inside planning.
|
|
415
415
|
|
|
416
|
-
## Effects, timers, and child machines
|
|
416
|
+
## Effects, Streams, timers, and child machines
|
|
417
417
|
|
|
418
418
|
State-scoped work starts on entry and is interrupted on exit:
|
|
419
419
|
|
|
@@ -445,8 +445,9 @@ Waiting: {
|
|
|
445
445
|
}
|
|
446
446
|
```
|
|
447
447
|
|
|
448
|
-
Use `effect` for one Effect, `
|
|
449
|
-
|
|
448
|
+
Use `effect` for one Effect, `stream` for a sequence of externally produced
|
|
449
|
+
values, `after` for a cancellable delay, `logic` for a reusable process, and
|
|
450
|
+
`child` for a complete child statechart—all through
|
|
450
451
|
`Machine.invoke({...})`. The helper is an identity at runtime and preserves
|
|
451
452
|
owner-context and source-channel inference across lifecycle handlers, including
|
|
452
453
|
for state-dependent Effects:
|
|
@@ -466,6 +467,33 @@ invoke: Machine.invoke({
|
|
|
466
467
|
})
|
|
467
468
|
```
|
|
468
469
|
|
|
470
|
+
A Stream source remains independent of the parent event protocol. Each element
|
|
471
|
+
is mapped by `onElement`, and the next element is not pulled until that parent
|
|
472
|
+
macrostep commits:
|
|
473
|
+
|
|
474
|
+
```ts
|
|
475
|
+
invoke: Machine.invoke({
|
|
476
|
+
id: "channel",
|
|
477
|
+
stream: () => channelMessages,
|
|
478
|
+
onElement: {
|
|
479
|
+
target: Machine.targetless,
|
|
480
|
+
resolve: ({ element }, enqueue) => {
|
|
481
|
+
enqueue.raise(Events.MessageReceived({ message: element }))
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
onDone: { target: Machine.targetless },
|
|
485
|
+
onFailure: Machine.transition({
|
|
486
|
+
target: (to) => to.full.Failed(),
|
|
487
|
+
resolve: ({ error, target }) => target.from({ error })
|
|
488
|
+
})
|
|
489
|
+
})
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
`target: Machine.targetless` is the direct shorthand for a non-reentering
|
|
493
|
+
transition that keeps the current configuration. Its optional `resolve`
|
|
494
|
+
callback may enqueue commands and must return `undefined`. Use
|
|
495
|
+
`Machine.transition(...)` for transitions that select state or reenter.
|
|
496
|
+
|
|
469
497
|
Inside `.handle(...)`, `Machine.invoke(...)` receives the owning machine's
|
|
470
498
|
public input and `parentEvents` protocols contextually. Its source and lifecycle
|
|
471
499
|
callbacks can send through `self` and `parent` while retaining the invoked
|