@typeonce/effect-machine 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 (46) hide show
  1. package/README.md +115 -5
  2. package/dist/Machine.d.ts +188 -52
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +6 -5
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  7. package/dist/internal/machine/executionPlan.js +50 -6
  8. package/dist/internal/machine/executionPlan.js.map +1 -1
  9. package/dist/internal/machine/initialization.d.ts.map +1 -1
  10. package/dist/internal/machine/initialization.js +7 -2
  11. package/dist/internal/machine/initialization.js.map +1 -1
  12. package/dist/internal/machine/machine.d.ts.map +1 -1
  13. package/dist/internal/machine/machine.js +132 -22
  14. package/dist/internal/machine/machine.js.map +1 -1
  15. package/dist/internal/machine/planner.d.ts +16 -2
  16. package/dist/internal/machine/planner.d.ts.map +1 -1
  17. package/dist/internal/machine/planner.js +67 -13
  18. package/dist/internal/machine/planner.js.map +1 -1
  19. package/dist/internal/machine/topology.d.ts +19 -2
  20. package/dist/internal/machine/topology.d.ts.map +1 -1
  21. package/dist/internal/machine/topology.js +17 -2
  22. package/dist/internal/machine/topology.js.map +1 -1
  23. package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
  24. package/dist/internal/testing/machine/finiteModel.js +3 -3
  25. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  26. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  27. package/dist/internal/testing/machine/verification.js +17 -3
  28. package/dist/internal/testing/machine/verification.js.map +1 -1
  29. package/dist/testing/MachineTest.d.ts +5 -3
  30. package/dist/testing/MachineTest.d.ts.map +1 -1
  31. package/dist/testing/MachineTest.js +3 -3
  32. package/dist/testing/MachineTest.js.map +1 -1
  33. package/dist/unstable/reactivity/AtomMachine.d.ts +1 -1
  34. package/dist/unstable/reactivity/AtomMachine.js +1 -1
  35. package/docs/agent-guide.md +51 -3
  36. package/package.json +1 -1
  37. package/src/Machine.ts +532 -107
  38. package/src/internal/machine/executionPlan.ts +62 -6
  39. package/src/internal/machine/initialization.ts +10 -2
  40. package/src/internal/machine/machine.ts +188 -24
  41. package/src/internal/machine/planner.ts +86 -15
  42. package/src/internal/machine/topology.ts +40 -3
  43. package/src/internal/testing/machine/finiteModel.ts +7 -3
  44. package/src/internal/testing/machine/verification.ts +24 -3
  45. package/src/testing/MachineTest.ts +5 -3
  46. package/src/unstable/reactivity/AtomMachine.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"MachineTest.js","sourceRoot":"","sources":["../../src/testing/MachineTest.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,KAAK,QAAQ,MAAM,6CAA6C,CAAA;AAIvE,OAAO,EACL,cAAc,EAGd,2BAA2B,EAU3B,iBAAiB,EAQjB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAKlB,qBAAqB,EAIrB,eAAe,EAMf,uBAAuB,EACvB,sBAAsB,EAEtB,WAAW,EACX,WAAW,EACX,oBAAoB,EACrB,MAAM,6CAA6C,CAAA;AAQpD,OAAO,EACL,YAAY,EAcZ,YAAY,EAKb,MAAM,6CAA6C,CAAA;AAEpD,OAAO,EACL,sBAAsB,EAavB,MAAM,6CAA6C,CAAA;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,QAAQ,CAAC,cAAc,CAAA;AAkGzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,CAAC,MAAM,SAAS,GACpB,QAAQ,CAAC,SAAS,CAAA;AAmNpB;;;;;;GAMG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAA;AAEnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,KAAK,G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AAC,MAAM,CAAA;AAE7D;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,WAAW,GACtB,QAAQ,CAAC,WAAW,CAAA"}
@@ -258,7 +258,7 @@ type ChildState<Child extends Machine.ChildMachine.Any> = RefState<Machine.Child
258
258
  * events: Machine.events(),
259
259
  * initial: {
260
260
  * target: (to) => to.Count(),
261
- * resolve: ({ target }) => target(new Count({ value: 0 }))
261
+ * resolve: ({ target }) => target.decoded(new Count({ value: 0 }))
262
262
  * }
263
263
  * }).handle({ Count: {} })
264
264
  * const machineAtom = AtomMachine.make(machine)
@@ -68,7 +68,7 @@ export const childEmissions = internal.childEmissions;
68
68
  * events: Machine.events(),
69
69
  * initial: {
70
70
  * target: (to) => to.Count(),
71
- * resolve: ({ target }) => target(new Count({ value: 0 }))
71
+ * resolve: ({ target }) => target.decoded(new Count({ value: 0 }))
72
72
  * }
73
73
  * }).handle({ Count: {} })
74
74
  * const machineAtom = AtomMachine.make(machine)
@@ -67,9 +67,12 @@ Each step has one job:
67
67
  Chain `.handle` from `Machine.make`. Do not store the intermediate definition
68
68
  when the module exports one machine implementation.
69
69
 
70
- State builders construct the next snapshot. Use `.from(...)` when a state owns
71
- data. The machine validates that input through the state schema while it plans
72
- the transition.
70
+ State builders construct the next snapshot. Use `.from(...)` for schema make
71
+ input; defaults, transformations, and refinements run while the machine plans
72
+ the transition. Use `.decoded(...)` only for an existing `Schema.Type`. It is
73
+ validated against the type side without rerunning encoded transformations.
74
+ Valued state builders are not callable, so the construction mode is always
75
+ visible. Schema-less state construction uses `.from()`.
73
76
 
74
77
  The examples below show one modeling decision at a time. They omit unchanged
75
78
  state and event declarations already shown above.
@@ -388,6 +391,51 @@ Do not read the clock, generate randomness, call a service, or await work while
388
391
  choosing a transition. Receive such values in an event or produce them through
389
392
  state-owned work first.
390
393
 
394
+ When only an active compound or parallel state's value changes, use its static
395
+ update selection instead of reconstructing its active descendants:
396
+
397
+ ```ts
398
+ Changed: (to) =>
399
+ to.local.update(({ current, owner }) =>
400
+ owner.from({ revision: current.revision + 1 })
401
+ )
402
+ ```
403
+
404
+ `to.local.update` addresses the nearest valued compound scope.
405
+ `to.branch.<path>.update` addresses a valued compound or parallel ancestor of
406
+ the handler source. Both preserve the complete active descendant
407
+ configuration. Neither runs lifecycle actions or restarts state-owned work by
408
+ default. Use an event handled inside a parallel sibling when that sibling owns
409
+ the value that must change.
410
+
411
+ When topology changes and one valued ancestor remains active but needs a new
412
+ value, declare the owner on the destination:
413
+
414
+ ```ts
415
+ CreatePlan: (to) =>
416
+ to.local.SavingPlan()
417
+ .updating(to.branch.Ready)
418
+ .resolve(({ current, event, owner, target }) =>
419
+ target.from({ request: event.input }).update(
420
+ owner.decoded(new Ready({ ...current, notice: null }))
421
+ )
422
+ )
423
+ ```
424
+
425
+ `.updating(...)` accepts the retained state selector itself. It makes the
426
+ owner replacement mandatory at compile time: the resolver must finish a
427
+ destination construction with `.update(...)`. `current` is the owner's
428
+ decoded pre-transition value. `target` constructs the destination and `owner`
429
+ constructs the complete replacement value.
430
+
431
+ Both instructions are validated and applied atomically. The retained owner is
432
+ not reentered, destination entry sees its new value, and eventless
433
+ stabilization runs afterward. Only local and branch targets that retain the
434
+ owner expose `.updating`; full targets do not. Combined targets support one
435
+ owner. Keep separate domain changes explicit by constructing the complete
436
+ owner value instead of relying on a partial merge helper. Combined updates use
437
+ a direct resolver; named branches support value-only updates.
438
+
391
439
  ## Test paths and invariants
392
440
 
393
441
  Test the statechart as a graph. Send domain events, inspect reached states, and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeonce/effect-machine",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "Schema-first state machines and statecharts for Effect",
5
5
  "author": "Sandro Maglione",
6
6
  "repository": {