@typeonce/effect-machine 0.6.0 → 0.7.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 (54) hide show
  1. package/README.md +4 -3
  2. package/dist/Machine.d.ts +24 -6
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js.map +1 -1
  5. package/dist/internal/machine/atom.d.ts +5 -0
  6. package/dist/internal/machine/atom.d.ts.map +1 -1
  7. package/dist/internal/machine/atom.js +6 -3
  8. package/dist/internal/machine/atom.js.map +1 -1
  9. package/dist/internal/machine/machine.d.ts.map +1 -1
  10. package/dist/internal/machine/machine.js +1 -1
  11. package/dist/internal/machine/machine.js.map +1 -1
  12. package/dist/unstable/reactivity/AtomMachine.d.ts +26 -0
  13. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  14. package/dist/unstable/reactivity/AtomMachine.js +23 -0
  15. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  16. package/docs/agent-guide.md +14 -0
  17. package/package.json +5 -5
  18. package/src/Machine.ts +6909 -0
  19. package/src/index.ts +1 -0
  20. package/src/internal/machine/activities.ts +108 -0
  21. package/src/internal/machine/atom.ts +684 -0
  22. package/src/internal/machine/cluster.ts +394 -0
  23. package/src/internal/machine/command.ts +58 -0
  24. package/src/internal/machine/commandRuntime.ts +43 -0
  25. package/src/internal/machine/configuration.ts +1331 -0
  26. package/src/internal/machine/errors.ts +87 -0
  27. package/src/internal/machine/executionPlan.ts +996 -0
  28. package/src/internal/machine/invocation.ts +119 -0
  29. package/src/internal/machine/machine.ts +1750 -0
  30. package/src/internal/machine/planner.ts +1933 -0
  31. package/src/internal/machine/process.ts +906 -0
  32. package/src/internal/machine/protocol.ts +322 -0
  33. package/src/internal/machine/readiness.ts +10 -0
  34. package/src/internal/machine/runtime.ts +2512 -0
  35. package/src/internal/machine/serialization.ts +498 -0
  36. package/src/internal/machine/stateDefinition.ts +270 -0
  37. package/src/internal/machine/symbols.ts +2 -0
  38. package/src/internal/machine/topology.ts +479 -0
  39. package/src/internal/testing/machine/arbitrary.ts +102 -0
  40. package/src/internal/testing/machine/exploration.ts +331 -0
  41. package/src/internal/testing/machine/finiteModel.ts +1498 -0
  42. package/src/internal/testing/machine/invariant.ts +372 -0
  43. package/src/internal/testing/machine/probe.ts +79 -0
  44. package/src/internal/testing/machine/referenceModel.ts +1505 -0
  45. package/src/internal/testing/machine/runtime.ts +1710 -0
  46. package/src/internal/testing/machine/runtimeInvariant.ts +486 -0
  47. package/src/internal/testing/machine/trace.ts +150 -0
  48. package/src/internal/testing/machine/verification.ts +1890 -0
  49. package/src/testing/MachineTest.ts +2067 -0
  50. package/src/testing/index.ts +7 -0
  51. package/src/unstable/cluster/ClusterMachine.ts +390 -0
  52. package/src/unstable/cluster/index.ts +1 -0
  53. package/src/unstable/reactivity/AtomMachine.ts +696 -0
  54. package/src/unstable/reactivity/index.ts +1 -0
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * as Machine from "./Machine.js"
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Serializable structural metadata for state-owned machine activities.
3
+ *
4
+ * @since 0.4.0
5
+ */
6
+
7
+ /** @internal */
8
+ export const ActivityMetadataTypeId: unique symbol = Symbol.for("effect/Machine/ActivityMetadata")
9
+
10
+ /** @internal */
11
+ export type StaticActivityMetadata =
12
+ | {
13
+ readonly type: "process"
14
+ }
15
+ | {
16
+ readonly type: "effect"
17
+ readonly outcomes: {
18
+ readonly success: "dynamic"
19
+ readonly failure: "dynamic" | "none"
20
+ }
21
+ }
22
+ | {
23
+ readonly type: "timer"
24
+ readonly duration: string
25
+ readonly event: string
26
+ }
27
+ | {
28
+ readonly type: "machine"
29
+ readonly child: {
30
+ readonly id: string
31
+ readonly machineId: string | null
32
+ }
33
+ }
34
+
35
+ /** @internal */
36
+ export type ActivityDefinition<Source extends string = string> =
37
+ | ({
38
+ readonly source: Source
39
+ readonly id: string
40
+ } & StaticActivityMetadata)
41
+ | {
42
+ readonly source: Source
43
+ readonly type: "dynamic"
44
+ }
45
+
46
+ interface ActivityDescriptor {
47
+ readonly id: string
48
+ readonly [ActivityMetadataTypeId]: StaticActivityMetadata
49
+ }
50
+
51
+ interface InspectableMachine {
52
+ readonly handlers: unknown
53
+ readonly stateNodes: {
54
+ readonly byPath: {
55
+ values(): Iterable<{ readonly path: string }>
56
+ }
57
+ }
58
+ }
59
+
60
+ const isObject = (value: unknown): value is object =>
61
+ (typeof value === "object" && value !== null) || typeof value === "function"
62
+
63
+ const getProperty = (value: unknown, key: PropertyKey): unknown => isObject(value) ? Reflect.get(value, key) : undefined
64
+
65
+ const hasActivityMetadata = (value: unknown): value is ActivityDescriptor =>
66
+ isObject(value) && typeof getProperty(value, "id") === "string" &&
67
+ isObject(getProperty(value, ActivityMetadataTypeId))
68
+
69
+ const appendStaticDefinition = (
70
+ definitions: Array<ActivityDefinition>,
71
+ source: string,
72
+ descriptor: unknown
73
+ ): void => {
74
+ if (!hasActivityMetadata(descriptor)) {
75
+ return
76
+ }
77
+ definitions.push({
78
+ source,
79
+ id: descriptor.id,
80
+ ...descriptor[ActivityMetadataTypeId]
81
+ })
82
+ }
83
+
84
+ /**
85
+ * Collects state-owned activity descriptions without executing user code.
86
+ *
87
+ * Function-valued invoke definitions depend on an entry context and are
88
+ * therefore represented as dynamic. Static descriptors are returned in state
89
+ * definition order and descriptor array order.
90
+ *
91
+ * @internal
92
+ */
93
+ export const activityDefinitions = (machine: InspectableMachine): ReadonlyArray<ActivityDefinition> => {
94
+ const definitions: Array<ActivityDefinition> = []
95
+ for (const node of machine.stateNodes.byPath.values()) {
96
+ const invoke = getProperty(getProperty(machine.handlers, node.path), "invoke")
97
+ if (typeof invoke === "function") {
98
+ definitions.push({ source: node.path, type: "dynamic" })
99
+ } else if (Array.isArray(invoke)) {
100
+ for (const descriptor of invoke) {
101
+ appendStaticDefinition(definitions, node.path, descriptor)
102
+ }
103
+ } else {
104
+ appendStaticDefinition(definitions, node.path, invoke)
105
+ }
106
+ }
107
+ return definitions
108
+ }