@typeonce/effect-machine 0.6.0 → 0.6.1
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/package.json +5 -5
- package/src/Machine.ts +6873 -0
- package/src/index.ts +1 -0
- package/src/internal/machine/activities.ts +108 -0
- package/src/internal/machine/atom.ts +636 -0
- package/src/internal/machine/cluster.ts +394 -0
- package/src/internal/machine/command.ts +58 -0
- package/src/internal/machine/commandRuntime.ts +43 -0
- package/src/internal/machine/configuration.ts +1331 -0
- package/src/internal/machine/errors.ts +87 -0
- package/src/internal/machine/executionPlan.ts +996 -0
- package/src/internal/machine/invocation.ts +119 -0
- package/src/internal/machine/machine.ts +1747 -0
- package/src/internal/machine/planner.ts +1933 -0
- package/src/internal/machine/process.ts +906 -0
- package/src/internal/machine/protocol.ts +322 -0
- package/src/internal/machine/readiness.ts +10 -0
- package/src/internal/machine/runtime.ts +2512 -0
- package/src/internal/machine/serialization.ts +498 -0
- package/src/internal/machine/stateDefinition.ts +270 -0
- package/src/internal/machine/symbols.ts +2 -0
- package/src/internal/machine/topology.ts +479 -0
- package/src/internal/testing/machine/arbitrary.ts +102 -0
- package/src/internal/testing/machine/exploration.ts +331 -0
- package/src/internal/testing/machine/finiteModel.ts +1498 -0
- package/src/internal/testing/machine/invariant.ts +372 -0
- package/src/internal/testing/machine/probe.ts +79 -0
- package/src/internal/testing/machine/referenceModel.ts +1505 -0
- package/src/internal/testing/machine/runtime.ts +1710 -0
- package/src/internal/testing/machine/runtimeInvariant.ts +486 -0
- package/src/internal/testing/machine/trace.ts +150 -0
- package/src/internal/testing/machine/verification.ts +1890 -0
- package/src/testing/MachineTest.ts +2067 -0
- package/src/testing/index.ts +7 -0
- package/src/unstable/cluster/ClusterMachine.ts +390 -0
- package/src/unstable/cluster/index.ts +1 -0
- package/src/unstable/reactivity/AtomMachine.ts +649 -0
- 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
|
+
}
|