@raphy-js/raph 1.0.0-dev.2 → 1.0.1-dev.25
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 +1096 -0
- package/dist/api/Raph.d.ts +59 -190
- package/dist/api/RaphFacadeSession.d.ts +90 -0
- package/dist/api/RaphReactivityInstance.d.ts +72 -0
- package/dist/api/errors.d.ts +9 -4
- package/dist/api/types.d.ts +162 -17
- package/dist/core-CClhT8WR.js +1044 -0
- package/dist/core-cPQWYD4K.cjs +1 -0
- package/dist/debug/api/Raph.cjs +1 -1
- package/dist/debug/api/Raph.js +368 -367
- package/dist/debug/api/RaphFacadeSession.cjs +1 -0
- package/dist/debug/api/RaphFacadeSession.js +302 -0
- package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
- package/dist/debug/api/RaphReactivityInstance.js +146 -0
- package/dist/debug/api/errors.cjs +1 -1
- package/dist/debug/api/errors.js +10 -7
- package/dist/debug/path/DataPath.cjs +1 -0
- package/dist/debug/path/DataPath.js +390 -0
- package/dist/debug/path/PathRouter.cjs +1 -0
- package/dist/debug/path/PathRouter.js +80 -0
- package/dist/debug/path/RaphKernel.cjs +1 -1
- package/dist/debug/path/RaphKernel.js +316 -236
- package/dist/debug/path/data-path.utils.cjs +1 -0
- package/dist/debug/path/data-path.utils.js +56 -0
- package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
- package/dist/debug/path/derived/DerivedRegistry.js +143 -0
- package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -0
- package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +19 -22
- package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
- package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +71 -71
- package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
- package/dist/debug/path/derived/derived-strategy.types.js +1 -0
- package/dist/debug/path/meta/MetaController.cjs +1 -0
- package/dist/debug/path/{MetaController.js → meta/MetaController.js} +58 -66
- package/dist/debug/path/meta/RaphMeta.cjs +1 -0
- package/dist/debug/path/meta/RaphMeta.js +62 -0
- package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
- package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +24 -30
- package/dist/debug/path/meta/meta.types.cjs +1 -0
- package/dist/debug/path/meta/meta.types.js +1 -0
- package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
- package/dist/debug/path/storage/AdapterPathStore.js +128 -0
- package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
- package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +47 -57
- package/dist/debug/path/storage/PathEventHub.cjs +1 -0
- package/dist/debug/path/storage/PathEventHub.js +161 -0
- package/dist/debug/path/storage/PathStore.cjs +1 -0
- package/dist/debug/path/{PathStore.js → storage/PathStore.js} +88 -98
- package/dist/debug/path/storage/createDataDraft.cjs +1 -0
- package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +24 -28
- package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
- package/dist/debug/path/storage/data-adapter.types.js +1 -0
- package/dist/debug/reactivity/disposal.cjs +1 -0
- package/dist/debug/reactivity/disposal.js +32 -0
- package/dist/debug/reactivity/engine.cjs +1 -1
- package/dist/debug/reactivity/engine.js +888 -321
- package/dist/debug/reactivity/reactive-object.cjs +1 -0
- package/dist/debug/reactivity/reactive-object.js +265 -0
- package/dist/debug/reactivity/scope.cjs +1 -1
- package/dist/debug/reactivity/scope.js +221 -117
- package/dist/debug/reactivity/watch.cjs +1 -1
- package/dist/debug/reactivity/watch.js +1 -1
- package/dist/debug/runtime/RaphRuntime.cjs +1 -1
- package/dist/debug/runtime/RaphRuntime.js +1134 -502
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.js +287 -0
- package/dist/debug/runtime/errors.cjs +1 -1
- package/dist/debug/runtime/errors.js +6 -3
- package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphEffectScope.js +304 -0
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphNode.js +665 -0
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphScope.js +236 -0
- package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
- package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
- package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -0
- package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +13 -17
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +848 -0
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.js +176 -0
- package/dist/debug/runtime/phases/RaphPhaseWatch.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhaseWatch.js +20 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
- package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
- package/dist/debug/runtime/reactivity/PathHandle.js +165 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.js +108 -0
- package/dist/debug/runtime/reactivity/RaphSelector.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphSelector.js +503 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.js +1157 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +550 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.js +77 -0
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.cjs +1 -0
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.js +42 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
- package/dist/entrypoints/machine-testing.d.ts +2 -0
- package/dist/entrypoints/machine.d.ts +5 -0
- package/dist/entrypoints/path.d.ts +14 -0
- package/dist/entrypoints/reactivity.d.ts +1 -0
- package/dist/entrypoints/runtime.d.ts +18 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +46 -38
- package/dist/machine/compiler.d.ts +71 -0
- package/dist/machine/core.d.ts +50 -0
- package/dist/machine/persistence.d.ts +5 -0
- package/dist/machine/runtime.d.ts +4 -0
- package/dist/machine/testing.d.ts +43 -0
- package/dist/machine/types.d.ts +155 -0
- package/dist/machine-testing.cjs +1 -0
- package/dist/machine-testing.js +188 -0
- package/dist/machine.cjs +1 -0
- package/dist/machine.js +822 -0
- package/dist/main.d.ts +20 -0
- package/dist/path/{data-path.d.ts → DataPath.d.ts} +16 -40
- package/dist/path/{path-router.d.ts → PathRouter.d.ts} +1 -1
- package/dist/path/RaphKernel.d.ts +37 -10
- package/dist/path/data-path.types.d.ts +34 -0
- package/dist/path/data-path.utils.d.ts +9 -0
- package/dist/path/{DerivedRegistry.d.ts → derived/DerivedRegistry.d.ts} +2 -2
- package/dist/path/{RaphDerivedHandle.d.ts → derived/RaphDerivedHandle.d.ts} +3 -3
- package/dist/path/derived/derived-collection.types.d.ts +12 -0
- package/dist/path/{derived-collection.d.ts → derived/derived-collection.utils.d.ts} +3 -13
- package/dist/path/{derived-strategies.d.ts → derived/derived-strategy.types.d.ts} +0 -3
- package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
- package/dist/path/{MetaController.d.ts → meta/MetaController.d.ts} +4 -4
- package/dist/path/{RaphMeta.d.ts → meta/RaphMeta.d.ts} +2 -2
- package/dist/path/{RaphMetaStore.d.ts → meta/RaphMetaStore.d.ts} +1 -1
- package/dist/path/{meta.types.d.ts → meta/meta.types.d.ts} +2 -4
- package/dist/path/path.types.d.ts +3 -2
- package/dist/path/{segment-key.d.ts → pathSegmentKey.d.ts} +1 -1
- package/dist/path/{AdapterPathStore.d.ts → storage/AdapterPathStore.d.ts} +4 -4
- package/dist/path/{data-adapter.d.ts → storage/DefaultDataAdapter.d.ts} +2 -17
- package/dist/path/storage/PathEventHub.d.ts +62 -0
- package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +7 -7
- package/dist/path/storage/data-adapter.types.d.ts +17 -0
- package/dist/path.cjs +1 -1
- package/dist/path.js +16 -16
- package/dist/raph.cjs +1 -1
- package/dist/raph.js +46 -38
- package/dist/reactivity/disposal.d.ts +14 -0
- package/dist/reactivity/engine.d.ts +193 -6
- package/dist/reactivity/reactive-object.d.ts +36 -0
- package/dist/reactivity/scope.d.ts +108 -30
- package/dist/reactivity/types.d.ts +25 -0
- package/dist/reactivity.cjs +1 -1
- package/dist/reactivity.js +12 -12
- package/dist/runtime/RaphRuntime.d.ts +319 -160
- package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
- package/dist/runtime/errors.d.ts +5 -0
- package/dist/runtime/ownership/RaphEffectScope.d.ts +98 -0
- package/dist/runtime/ownership/RaphNode.d.ts +310 -0
- package/dist/runtime/ownership/RaphScope.d.ts +168 -0
- package/dist/runtime/{parent-graph.d.ts → ownership/parent-graph.types.d.ts} +0 -1
- package/dist/runtime/ownership/parentGraph.d.ts +3 -0
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +253 -0
- package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +195 -0
- package/dist/runtime/phases/RaphPhaseWatch.d.ts +22 -0
- package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
- package/dist/runtime/phases/phase.types.d.ts +171 -0
- package/dist/runtime/{PathHandle.d.ts → reactivity/PathHandle.d.ts} +14 -6
- package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
- package/dist/runtime/reactivity/RaphSelector.d.ts +338 -0
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +309 -0
- package/dist/runtime/reactivity/RuntimeReactivity.d.ts +293 -0
- package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +12 -6
- package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +19 -0
- package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +56 -0
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +21 -16
- package/package.json +76 -35
- package/ReadMe.md +0 -153
- package/dist/api/public.d.ts +0 -22
- package/dist/debug/api/public.cjs +0 -1
- package/dist/debug/api/public.js +0 -40
- package/dist/debug/path/AdapterPathStore.cjs +0 -1
- package/dist/debug/path/AdapterPathStore.js +0 -133
- package/dist/debug/path/DerivedRegistry.cjs +0 -1
- package/dist/debug/path/DerivedRegistry.js +0 -157
- package/dist/debug/path/MetaController.cjs +0 -1
- package/dist/debug/path/PathEventHub.cjs +0 -1
- package/dist/debug/path/PathEventHub.js +0 -148
- package/dist/debug/path/PathStore.cjs +0 -1
- package/dist/debug/path/RaphDerivedHandle.cjs +0 -1
- package/dist/debug/path/RaphMeta.cjs +0 -1
- package/dist/debug/path/RaphMeta.js +0 -68
- package/dist/debug/path/RaphMetaStore.cjs +0 -1
- package/dist/debug/path/data-adapter.cjs +0 -1
- package/dist/debug/path/data-draft.cjs +0 -1
- package/dist/debug/path/data-path.cjs +0 -1
- package/dist/debug/path/data-path.js +0 -423
- package/dist/debug/path/derived-collection.cjs +0 -1
- package/dist/debug/path/path-router.cjs +0 -1
- package/dist/debug/path/path-router.js +0 -86
- package/dist/debug/path/public.cjs +0 -1
- package/dist/debug/path/public.js +0 -18
- package/dist/debug/runtime/PathHandle.cjs +0 -1
- package/dist/debug/runtime/PathHandle.js +0 -139
- package/dist/debug/runtime/RaphDebug.cjs +0 -1
- package/dist/debug/runtime/RaphDebug.js +0 -15
- package/dist/debug/runtime/RaphFrameLoop.cjs +0 -1
- package/dist/debug/runtime/RaphNode.cjs +0 -1
- package/dist/debug/runtime/RaphNode.js +0 -143
- package/dist/debug/runtime/RaphPhasePipeline.cjs +0 -1
- package/dist/debug/runtime/RaphPhasePipeline.js +0 -526
- package/dist/debug/runtime/RaphScope.cjs +0 -1
- package/dist/debug/runtime/RaphScope.js +0 -64
- package/dist/debug/runtime/RuntimeReactivity.cjs +0 -1
- package/dist/debug/runtime/RuntimeReactivity.js +0 -154
- package/dist/debug/runtime/RuntimeWatch.cjs +0 -1
- package/dist/debug/runtime/RuntimeWatch.js +0 -71
- package/dist/debug/runtime/public.cjs +0 -1
- package/dist/debug/runtime/public.js +0 -18
- package/dist/path/PathEventHub.d.ts +0 -48
- package/dist/path/public.d.ts +0 -14
- package/dist/runtime/RaphDebug.d.ts +0 -32
- package/dist/runtime/RaphNode.d.ts +0 -68
- package/dist/runtime/RaphPhasePipeline.d.ts +0 -133
- package/dist/runtime/RaphScope.d.ts +0 -50
- package/dist/runtime/RuntimeReactivity.d.ts +0 -40
- package/dist/runtime/phase.types.d.ts +0 -49
- package/dist/runtime/public.d.ts +0 -13
- package/dist/runtime/runtime-reactivity.types.d.ts +0 -9
- /package/dist/debug/path/{meta.types.cjs → data-path.types.cjs} +0 -0
- /package/dist/debug/path/{meta.types.js → data-path.types.js} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.cjs → path/derived/derived-collection.types.cjs} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.js → path/derived/derived-collection.types.js} +0 -0
- /package/dist/debug/path/{derived-strategies.cjs → derived/derived-strategy.utils.cjs} +0 -0
- /package/dist/debug/path/{derived-strategies.js → derived/derived-strategy.utils.js} +0 -0
- /package/dist/debug/path/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
- /package/dist/debug/path/{segment-key.js → pathSegmentKey.js} +0 -0
- /package/dist/debug/runtime/{parent-graph.cjs → ownership/parentGraph.cjs} +0 -0
- /package/dist/debug/runtime/{parent-graph.js → ownership/parentGraph.js} +0 -0
- /package/dist/debug/runtime/{disposal.cjs → ownership/throwDisposalErrors.cjs} +0 -0
- /package/dist/debug/runtime/{disposal.js → ownership/throwDisposalErrors.js} +0 -0
- /package/dist/debug/runtime/{phase.types.cjs → phases/phase.types.cjs} +0 -0
- /package/dist/debug/runtime/{phase.types.js → phases/phase.types.js} +0 -0
- /package/dist/path/{data-draft.d.ts → storage/createDataDraft.d.ts} +0 -0
- /package/dist/runtime/{disposal.d.ts → ownership/throwDisposalErrors.d.ts} +0 -0
- /package/dist/runtime/{RaphFrameLoop.d.ts → phases/RaphFrameLoop.d.ts} +0 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { t as j, g as y, a as k } from "./core-CClhT8WR.js";
|
|
2
|
+
function z(n) {
|
|
3
|
+
const i = y(n), c = w(i), a = i.states.filter((t) => t.kind !== "history" && !c.has(t.id)).map((t) => t.path), o = i.states.filter((t) => t.kind === "atomic" && t.on.size === 0 && t.always.length === 0 && t.after.size === 0 && t.invokes.length === 0).map((t) => t.path), r = [];
|
|
4
|
+
for (const t of i.states)
|
|
5
|
+
t.kind === "parallel" && t.children.length === 0 && r.push(`Parallel state "${t.path}" has no regions.`), t.kind === "compound" && t.initial === void 0 && r.push(`Compound state "${t.path}" has no initial child.`);
|
|
6
|
+
return Object.freeze({
|
|
7
|
+
deadEnds: Object.freeze(o),
|
|
8
|
+
inconsistencies: Object.freeze(r),
|
|
9
|
+
reachable: Object.freeze([...c].map((t) => i.states[t].path)),
|
|
10
|
+
unreachable: Object.freeze(a),
|
|
11
|
+
valid: r.length === 0
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function x(n, i = {}) {
|
|
15
|
+
const c = y(n), a = i.maxDepth ?? 12, o = i.maxPaths ?? 1e3;
|
|
16
|
+
b(a, "maxDepth"), b(o, "maxPaths");
|
|
17
|
+
const r = i.events ?? c.eventTypes.map((l) => ({ type: l })), t = k(n, i.input), s = [{
|
|
18
|
+
events: Object.freeze([]),
|
|
19
|
+
snapshot: t
|
|
20
|
+
}], e = [s[0]], f = /* @__PURE__ */ new Set([v(t)]);
|
|
21
|
+
let u = 0;
|
|
22
|
+
for (; u < e.length && s.length < o; ) {
|
|
23
|
+
const l = e[u++];
|
|
24
|
+
if (!(l.events.length >= a || l.snapshot.status !== "active"))
|
|
25
|
+
for (const p of r) {
|
|
26
|
+
const d = j(n, l.snapshot, p, i.bindings);
|
|
27
|
+
if (d === l.snapshot)
|
|
28
|
+
continue;
|
|
29
|
+
const m = v(d);
|
|
30
|
+
if (f.has(m))
|
|
31
|
+
continue;
|
|
32
|
+
f.add(m);
|
|
33
|
+
const g = Object.freeze({
|
|
34
|
+
events: Object.freeze([...l.events, p]),
|
|
35
|
+
snapshot: d
|
|
36
|
+
});
|
|
37
|
+
if (s.push(g), e.push(g), s.length >= o)
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return Object.freeze(s);
|
|
42
|
+
}
|
|
43
|
+
function $() {
|
|
44
|
+
const n = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
|
|
45
|
+
return {
|
|
46
|
+
guard: (a, o) => {
|
|
47
|
+
const r = c.get(a) ?? { failed: 0, passed: 0 };
|
|
48
|
+
o ? r.passed++ : r.failed++, c.set(a, r);
|
|
49
|
+
},
|
|
50
|
+
record: (a, o, r) => {
|
|
51
|
+
for (const t of r.active)
|
|
52
|
+
n.set(t, (n.get(t) ?? 0) + 1);
|
|
53
|
+
if (a !== r) {
|
|
54
|
+
const t = `${a.active.join("|")} --${o.type}--> ${r.active.join("|")}`;
|
|
55
|
+
i.set(t, (i.get(t) ?? 0) + 1);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
report: () => Object.freeze({
|
|
59
|
+
guards: Object.freeze(Object.fromEntries(
|
|
60
|
+
[...c].map(([a, o]) => [a, Object.freeze({ ...o })])
|
|
61
|
+
)),
|
|
62
|
+
states: Object.freeze(Object.fromEntries(n)),
|
|
63
|
+
transitions: Object.freeze(Object.fromEntries(i))
|
|
64
|
+
}),
|
|
65
|
+
reset: () => {
|
|
66
|
+
n.clear(), i.clear(), c.clear();
|
|
67
|
+
},
|
|
68
|
+
transition: (a, o, r, t) => {
|
|
69
|
+
const s = j(a, o, r, t, {
|
|
70
|
+
guard: (e, f) => {
|
|
71
|
+
const u = c.get(e) ?? { failed: 0, passed: 0 };
|
|
72
|
+
f ? u.passed++ : u.failed++, c.set(e, u);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
for (const e of s.active)
|
|
76
|
+
n.set(e, (n.get(e) ?? 0) + 1);
|
|
77
|
+
if (o !== s) {
|
|
78
|
+
const e = `${o.active.join("|")} --${r.type}--> ${s.active.join("|")}`;
|
|
79
|
+
i.set(e, (i.get(e) ?? 0) + 1);
|
|
80
|
+
}
|
|
81
|
+
return s;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function M(n = 0) {
|
|
86
|
+
if (!Number.isFinite(n))
|
|
87
|
+
throw new TypeError("[Raph machine] Manual clock initial time must be finite.");
|
|
88
|
+
let i = n, c = 1;
|
|
89
|
+
const a = /* @__PURE__ */ new Map();
|
|
90
|
+
return {
|
|
91
|
+
advance: (s) => {
|
|
92
|
+
if (!Number.isFinite(s) || s < 0)
|
|
93
|
+
throw new TypeError("[Raph machine] Clock advance duration must be non-negative and finite.");
|
|
94
|
+
const e = i + s;
|
|
95
|
+
r(e), i = e;
|
|
96
|
+
},
|
|
97
|
+
clearTimeout: (s) => {
|
|
98
|
+
const e = a.get(s);
|
|
99
|
+
e !== void 0 && (e.active = !1, a.delete(e.id));
|
|
100
|
+
},
|
|
101
|
+
now: () => i,
|
|
102
|
+
get pending() {
|
|
103
|
+
return a.size;
|
|
104
|
+
},
|
|
105
|
+
runAll: () => {
|
|
106
|
+
let s = 0;
|
|
107
|
+
for (; a.size !== 0; ) {
|
|
108
|
+
if (++s > 1e5)
|
|
109
|
+
throw new Error("[Raph machine] Manual clock exceeded 100000 timer turns.");
|
|
110
|
+
const e = t();
|
|
111
|
+
if (e === void 0)
|
|
112
|
+
break;
|
|
113
|
+
r(e.at), i = e.at;
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
setTimeout: (s, e) => {
|
|
117
|
+
if (!Number.isFinite(e) || e < 0)
|
|
118
|
+
throw new TypeError("[Raph machine] Timer delay must be non-negative and finite.");
|
|
119
|
+
const f = { active: !0, at: i + e, callback: s, id: c++ };
|
|
120
|
+
return a.set(f.id, f), f.id;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
function r(s) {
|
|
124
|
+
for (; ; ) {
|
|
125
|
+
const e = t();
|
|
126
|
+
if (e === void 0 || e.at > s)
|
|
127
|
+
return;
|
|
128
|
+
i = e.at, a.delete(e.id), e.active && (e.active = !1, e.callback());
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function t() {
|
|
132
|
+
let s;
|
|
133
|
+
for (const e of a.values())
|
|
134
|
+
e.active && (s === void 0 || e.at < s.at || e.at === s.at && e.id < s.id) && (s = e);
|
|
135
|
+
return s;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function w(n) {
|
|
139
|
+
const i = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), a = [n.initial];
|
|
140
|
+
let o = 0;
|
|
141
|
+
for (; o < a.length; ) {
|
|
142
|
+
const r = a[o++];
|
|
143
|
+
if (c.has(r))
|
|
144
|
+
continue;
|
|
145
|
+
c.add(r);
|
|
146
|
+
for (const e of n.ancestry[r])
|
|
147
|
+
c.has(e) || a.push(e), i.add(e);
|
|
148
|
+
const t = n.states[r];
|
|
149
|
+
if (t.kind === "history") {
|
|
150
|
+
if (t.historyFallback !== void 0)
|
|
151
|
+
a.push(t.historyFallback);
|
|
152
|
+
else if (t.parent !== void 0) {
|
|
153
|
+
const e = n.states[t.parent];
|
|
154
|
+
e.initial !== void 0 && a.push(e.initial);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
t.initial !== void 0 && a.push(t.initial), t.kind === "parallel" && a.push(...t.children.filter((e) => n.states[e].kind !== "history"));
|
|
158
|
+
const s = [t.always, t.onDone, ...t.on.values(), ...t.after.values()];
|
|
159
|
+
for (const e of t.invokes)
|
|
160
|
+
s.push(e.onDone, e.onError);
|
|
161
|
+
for (const e of s)
|
|
162
|
+
for (const f of e)
|
|
163
|
+
f.target !== void 0 && a.push(f.target);
|
|
164
|
+
}
|
|
165
|
+
return i;
|
|
166
|
+
}
|
|
167
|
+
function v(n) {
|
|
168
|
+
return [
|
|
169
|
+
n.status,
|
|
170
|
+
n.active.join("|"),
|
|
171
|
+
h(n.context),
|
|
172
|
+
h(n.history),
|
|
173
|
+
h(n.output)
|
|
174
|
+
].join(":");
|
|
175
|
+
}
|
|
176
|
+
function h(n) {
|
|
177
|
+
return n === null || typeof n != "object" ? JSON.stringify(n) : Array.isArray(n) ? `[${n.map(h).join(",")}]` : `{${Object.keys(n).sort().map((i) => `${JSON.stringify(i)}:${h(n[i])}`).join(",")}}`;
|
|
178
|
+
}
|
|
179
|
+
function b(n, i) {
|
|
180
|
+
if (!Number.isSafeInteger(n) || n <= 0)
|
|
181
|
+
throw new TypeError(`[Raph machine] ${i} must be a positive safe integer.`);
|
|
182
|
+
}
|
|
183
|
+
export {
|
|
184
|
+
$ as createMachineCoverage,
|
|
185
|
+
M as createManualMachineClock,
|
|
186
|
+
x as enumerateMachinePaths,
|
|
187
|
+
z as inspectMachine
|
|
188
|
+
};
|
package/dist/machine.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./core-cPQWYD4K.cjs"),j=require("./debug/runtime/ownership/RaphScope.cjs");class p extends Error{}function q(o,t){return f.assertMachineSnapshot(o,t),y(t.context,"context"),t.output!==void 0&&y(t.output,"output"),Object.freeze({active:Object.freeze([...t.active]),context:E(t.context),history:Object.freeze(Object.fromEntries(Object.entries(t.history).map(([e,r])=>[e,Object.freeze([...r])]))),modelId:o.id,...t.output===void 0?{}:{output:E(t.output)},revision:t.revision,status:t.status,version:o.version})}function I(o,t,e){const r=f.getCompiledMachine(o);try{if(typeof t!="object"||t===null||Array.isArray(t))throw new p("[Raph machine] Persisted snapshot must be an object.");if(t.modelId!==o.id)throw new p(`[Raph machine] Snapshot model "${t.modelId}" is incompatible with "${o.id}".`);if(!Number.isSafeInteger(t.version)||t.version<1)throw new p("[Raph machine] Persisted version must be a positive integer.");let i=t;for(;i.version<o.version;){const s=r.migrations.get(i.version);if(s===void 0)throw new p(`[Raph machine] Missing migration from version ${i.version} for "${o.id}".`);const n=s(i);if(n.version!==i.version+1||n.modelId!==o.id)throw new p(`[Raph machine] Migration from version ${i.version} must produce version ${i.version+1}.`);i=n}if(i.version!==o.version)throw new p(`[Raph machine] Snapshot version ${i.version} is newer than model version ${o.version}.`);return y(i.context,"context"),i.output!==void 0&&y(i.output,"output"),f.hydrateSnapshot(o,i,e)}catch(i){throw i instanceof p?i:new p(`[Raph machine] Persisted snapshot is invalid: ${i instanceof Error?i.message:String(i)}`)}}function y(o,t,e=new Set){if(o===null)return;const r=typeof o;if(r==="string"||r==="boolean")return;if(r==="number"){if(!Number.isFinite(o))throw new p(`[Raph machine] ${t} contains a non-finite number.`);return}if(r!=="object")throw new p(`[Raph machine] ${t} is not JSON-safe.`);const i=o;if(e.has(i))throw new p(`[Raph machine] ${t} contains a cycle.`);if(e.add(i),Array.isArray(o))o.forEach((s,n)=>y(s,`${t}[${n}]`,e));else{const s=Object.getPrototypeOf(o);if(s!==Object.prototype&&s!==null)throw new p(`[Raph machine] ${t} contains a non-plain object.`);for(const[n,h]of Object.entries(o))y(h,`${t}.${n}`,e)}e.delete(i)}function E(o){return JSON.parse(JSON.stringify(o))}const C=new WeakMap,w=Symbol("RaphMachineActivationCancelled"),M=Object.freeze({type:"@@init"}),k=Object.freeze({clearTimeout:o=>clearTimeout(o),now:()=>Date.now(),setTimeout:(o,t)=>setTimeout(o,t)});class ${constructor(t,e,r,i){if(this.id=void 0,this.model=void 0,this.snapshot=void 0,this._owner=void 0,this._runtime=void 0,this._compiled=void 0,this._bindings=void 0,this._clock=void 0,this._input=void 0,this._errorPolicy=void 0,this._releaseSnapshot=R,this._writeSnapshotInBoundary=void 0,this._currentSnapshot=void 0,this._queue=void 0,this._listeners=void 0,this._stateCleanups=void 0,this._invocations=void 0,this._actors=void 0,this._releaseOwnership=R,this._releaseDebug=R,this._restored=!1,this._initialPlan=void 0,this._onError=void 0,this._queueCursor=0,this._processing=!1,this._started=!1,this._stopped=!1,this._lastIgnoredSnapshot=void 0,this._lastIgnoredResult=void 0,!(t instanceof j.RaphScope))throw new TypeError("[Raph machine] Machine owner must be a Raph Runtime scope or node.");if(t._assertAlive(),this._owner=t,this._runtime=t.runtime,this._compiled=f.getCompiledMachine(e),this.model=e,this._bindings=r,this._clock=i.clock??k,this._input=i.input,this._errorPolicy=i.errorPolicy??"throw",this._errorPolicy!=="ignore"&&this._errorPolicy!=="stop"&&this._errorPolicy!=="throw")throw new TypeError(`[Raph machine] Unknown error policy "${String(this._errorPolicy)}".`);this._onError=i.onError;const s=(C.get(this._runtime)??0)+1;if(C.set(this._runtime,s),this.id=i.id??`${e.id}#${s}`,!this.id.trim())throw new TypeError("[Raph machine] Instance id must not be empty.");if(this._runtime._hasMachineDebug(this.id))throw new Error(`[Raph] Machine diagnostic id "${this.id}" is already registered.`);const n=i.persisted===void 0?this._runtime.untracked(()=>f.createInitialSnapshot(e,this._input,r,this._runtime._traces("machine")?this._traceHooks():void 0)):void 0,h=n?.snapshot??I(e,i.persisted,this._input);this._initialPlan=n?.plan,this._restored=i.persisted!==void 0;const c=z(this._runtime,t,h);this._releaseSnapshot=c.dispose,this._writeSnapshotInBoundary=c.writeInBoundary,this._currentSnapshot=h,this.snapshot=c.source;try{this._releaseDebug=this._runtime._registerMachineDebug({id:this.id,ownerId:t.id,...i.parentId===void 0?{}:{parentId:i.parentId},snapshot:()=>{const a=this._currentSnapshot,u=Object.fromEntries(this._activeClosure(a).flatMap(d=>{const v=this._compiled.states[d].meta;return v===void 0?[]:[[this._compiled.states[d].path,v]]}));return Object.freeze({active:a.active,actors:Object.freeze([...this._actors?.keys()??[]]),contextKeys:Object.freeze(T(a.context)?Object.keys(a.context):[]),id:this.id,meta:Object.freeze(u),modelId:e.id,ownerId:t.id,...i.parentId===void 0?{}:{parentId:i.parentId},revision:a.revision,status:a.status})}}),this._releaseOwnership=t.own(()=>this._dispose(!1))}catch(a){const u=[a];try{this._releaseDebug()}catch(d){u.push(d)}try{this._releaseSnapshot()}catch(d){u.push(d)}throw u.length>1?new AggregateError(u,`[Raph machine] Machine "${this.id}" construction rollback failed.`):a}}get started(){return this._started&&!this._stopped}start(){if(this._stopped)throw new Error(`[Raph machine] Machine "${this.id}" is stopped.`);if(this._started)return this;this._owner._assertAlive();const t=this._currentSnapshot;if(t.status==="stopped")throw new Error(`[Raph machine] Persisted machine "${this.id}" is stopped.`);if(this._started=!0,this._compiled.flat)return this;const e=this._activeClosure(t).sort((s,n)=>this._compiled.states[s].depth-this._compiled.states[n].depth);let r=!1,i;this._processing=!0;try{const s=[];if(!this._restored){try{this._runOutputs(this._initialPlan?.exitOutputs??[],t,this._runtime._currentTraceCauseId())}catch(n){s.push(n)}if(this.started)try{this._runOutputs(this._initialPlan?.transitionOutputs??[],t,this._runtime._currentTraceCauseId())}catch(n){s.push(n)}if(this.started){const n=e.flatMap(h=>this._compiled.states[h].entry.map(c=>({event:M,ref:c})));try{this._runOutputs(n,t,this._runtime._currentTraceCauseId())}catch(h){s.push(h)}}}if(this.started&&t.status==="active")for(const n of e){if(!this.started)break;try{this._activateState(n,M,t)}catch(h){s.push(h)}}m(s,`[Raph machine] Machine "${this.id}" start work failed.`)}catch(s){try{this._handlePostCommitError(s,"start",this._runtime._currentTraceCauseId())}catch(n){r=!0,i=n}}finally{this._processing=!1,r?(this._queue!==void 0&&(this._queue.length=0),this._queueCursor=0):this._drainQueued()}if(r)throw i;return this}send(t){return this._enqueue(t)}sendTo(t,e){const r=this._actors?.get(t);if(r===void 0)throw new Error(`[Raph machine] Actor "${t}" is not active in "${this.id}".`);return r.send(e)}matches(t){return this.snapshot.get().active.some(e=>e===t||e.startsWith(`${t}.`))}hasTag(t){for(const e of this._activeClosure(this.snapshot.get()))if(this._compiled.states[e].tags.includes(t))return!0;return!1}subscribe(t){if(typeof t!="function")throw new TypeError("[Raph machine] Subscriber must be a function.");if(this._stopped)return()=>{};const e={listener:t},r=this._listeners;return this._listeners=r===void 0?[e]:[...r,e],()=>this._removeListener(e)}persist(){return q(this.model,this.snapshot.get())}stop(){let t;try{this._dispose(!0)}catch(e){(t??=[]).push(e)}try{this._releaseOwnership()}catch(e){(t??=[]).push(e)}m(t,`[Raph machine] Machine "${this.id}" stop failed.`)}_enqueue(t,e){if(!this.started)throw new Error(`[Raph machine] Machine "${this.id}" must be started before send().`);if(D(t),this._processing)return(this._queue??=[]).push({event:t,...e===void 0?{}:{transitions:e}}),{snapshot:this._currentSnapshot,status:"queued"};this._processing=!0;let r;try{r=this._process(t,e),this._drainQueuedItems()}finally{this._queue!==void 0&&(this._queue.length=0),this._queueCursor=0,this._processing=!1}return r}_process(t,e){const r=this._currentSnapshot,i=this._runtime._nextTraceOperation("machine"),s=this._runtime._currentTraceCauseId()??i;let n;i!==void 0&&this._trace(t.type,"start",i,s,r);try{const h=e===void 0?this._compiled.eventIndexes.get(t.type):void 0;if(e===void 0&&h===void 0)return i!==void 0&&this._trace(t.type,"ignored",i,s,r),this._ignored(r);const c=i===void 0?void 0:this._traceHooks(i,s),a=this._runtime._hasActiveReactiveContext()?this._runtime.untracked(()=>this._evaluate(r,t,h,e,c)):this._evaluate(r,t,h,e,c);if(!a.changed)return i!==void 0&&this._trace(t.type,"ignored",i,s,r),this._ignored(r);this._runtime._batchReactive(()=>{this._writeSnapshotInBoundary(a.snapshot),this._currentSnapshot=a.snapshot,n=a.snapshot});let u;try{this._applyPlan(a.plan,a.snapshot,s)}catch(g){(u??=[]).push(g)}const d=this._listeners;if(this.started&&d!==void 0){const g=this._notifyListeners(d,a.snapshot);g!==void 0&&(u??=[]).push(...g)}if(this.started&&a.snapshot.status==="done")try{this._stopStateResources()}catch(g){(u??=[]).push(g)}u!==void 0&&m(u,`[Raph machine] Machine "${this.id}" post-commit work failed.`);const v=this.started?a.snapshot:this._currentSnapshot;return i!==void 0&&this._trace(t.type,"end",i,s,v),{snapshot:v,status:"transitioned"}}catch(h){if(n!==void 0)return this._handlePostCommitError(h,t.type,s),{snapshot:this._currentSnapshot,status:"transitioned"};if(this._traceError(t.type,h,i,s),this._onError!==void 0)return this._onError(h),this._ignored(this._currentSnapshot);if(this._errorPolicy==="stop"&&this._dispose(!0),this._errorPolicy==="ignore")return this._ignored(this._currentSnapshot);throw h}}_ignored(t){return this._lastIgnoredSnapshot!==t&&(this._lastIgnoredSnapshot=t,this._lastIgnoredResult={snapshot:t,status:"ignored"}),this._lastIgnoredResult}_evaluate(t,e,r,i,s){return i===void 0?f.runValidatedMacrostep(this.model,t,e,this._bindings,this._input,s,this._compiled,r):f.runExplicitTransitions(this.model,t,e,i,this._bindings,this._input,s)}_drainQueued(){if(this._queue===void 0||this._queue.length===0||!this.started){this._queue!==void 0&&(this._queue.length=0),this._queueCursor=0;return}this._processing=!0;try{this._drainQueuedItems()}finally{this._queue!==void 0&&(this._queue.length=0),this._queueCursor=0,this._processing=!1}}_drainQueuedItems(){const t=this._queue;if(t!==void 0)for(;this._queueCursor<t.length&&this.started;){const e=t[this._queueCursor++];this._process(e.event,e.transitions)}}_applyPlan(t,e,r){if(t.exited.length===0&&t.exitOutputs.length===0&&t.transitionOutputs.length===0&&t.transitionOutputRefs===void 0&&t.entryOutputs.length===0&&t.entered.length===0)return;const i=[];for(const s of t.exited){try{this._cleanupState(s)}catch(n){i.push(n)}if(!this.started)break}if(this.started&&t.exitOutputs.length!==0)try{this._runOutputs(t.exitOutputs,e,r)}catch(s){i.push(s)}if(this.started&&t.transitionOutputRefs!==void 0)try{this._runOutputRefs(t.transitionOutputRefs,t.event,e,r)}catch(s){i.push(s)}else if(this.started&&t.transitionOutputs.length!==0)try{this._runOutputs(t.transitionOutputs,e,r)}catch(s){i.push(s)}if(this.started&&t.entryOutputs.length!==0)try{this._runOutputs(t.entryOutputs,e,r)}catch(s){i.push(s)}if(this.started)for(const s of t.entered){if(!this.started)break;try{this._activateState(s,t.event,e)}catch(n){i.push(n)}}m(i,`[Raph machine] Machine "${this.id}" post-commit work failed.`)}_activateState(t,e,r){if(!this.started||this._stateCleanups?.has(t))return;const i=this._compiled.states[t];if(i.resources.length===0&&i.after.size===0&&i.invokes.length===0)return;const s=[],n=this._stateCleanups??=new Map;n.set(t,s);try{for(const h of i.resources){const c=this._bindings.resources?.[h];if(c===void 0)throw new Error(`[Raph machine] Resource binding "${h}" is not defined.`);const a=new AbortController;let u;try{const d=this._runtime.untracked(()=>c({context:r.context,event:e,input:this._input,owner:this._owner,signal:a.signal,snapshot:r}));typeof d=="function"&&(u=d)}catch(d){throw a.abort(),d}if(s.push(S(()=>{a.abort(),u?.()})),!this.started)throw w}for(const[h,c]of i.after){const a=this._resolveDelay(h,r,e);if(!this.started)throw w;const u=this._clock.setTimeout(()=>{!this.started||!this._stateCleanups?.has(t)||this._enqueue(Object.freeze({type:`@@after:${i.path}:${h}`}),c)},a);if(s.push(S(()=>this._clock.clearTimeout(u))),!this.started)throw w}for(const h of i.invokes)if(this._startInvoke(i,h,e,r,s),!this.started)throw w}catch(h){n.get(t)===s&&n.delete(t),n.size===0&&this._stateCleanups===n&&(this._stateCleanups=void 0);const c=x(s);m(h===w?c:[h,...c],`[Raph machine] State "${i.path}" activation failed.`)}}_startInvoke(t,e,r,i,s){const n=this._invocations??=new Map;if(n.has(e.id))throw new Error(`[Raph machine] Invoke id "${e.id}" is already active.`);const h=new AbortController,c={},a={controller:h,invoke:e,token:c};n.set(e.id,a);const u=()=>{h.abort(),n.get(e.id)?.token===c&&n.delete(e.id),n.size===0&&this._invocations===n&&(this._invocations=void 0);const _=this._actors;_?.delete(e.id),_?.size===0&&this._actors===_&&(this._actors=void 0),a.actor?.stop()};s.push(S(u));const d=typeof e.input=="function"?e.input({context:i.context,event:r,input:this._input}):e.input;if(!this.started)return;if(e.type==="machine"){const l=typeof e.src=="string"?this._bindings.actors?.[e.src]:e.src;if(l===void 0)throw new Error(`[Raph machine] Actor source "${String(e.src)}" is not defined.`);const _=new $(this._owner,l,{},{errorPolicy:e.onError.length===0?"throw":"ignore",id:`${this.id}/${e.id}`,input:d,onError:e.onError.length===0?void 0:b=>{!this.started||this._invocations?.get(e.id)?.token!==c||this._enqueue(Object.freeze({error:b,type:`@@error.actor:${e.id}`}),e.onError)},parentId:this.id});if(!this.started||this._invocations?.get(e.id)?.token!==c||h.signal.aborted){_.stop();return}a.actor=_,(this._actors??=new Map).set(e.id,_);const P=_.subscribe(b=>{b.status==="done"&&this._invocations?.get(e.id)?.token===c&&this._enqueue(Object.freeze({output:b.output,type:`@@done.actor:${e.id}`}),e.onDone)});if(s.push(S(P)),_.start(),!this.started)return;const O=_.snapshot.peek();O.status==="done"&&this._invocations?.get(e.id)?.token===c&&this._enqueue(Object.freeze({output:O.output,type:`@@done.actor:${e.id}`}),e.onDone);return}if(typeof e.src!="string")throw new TypeError(`[Raph machine] Task invoke "${e.id}" requires a string source.`);const v=this._bindings.tasks?.[e.src];if(v===void 0)throw new Error(`[Raph machine] Task binding "${e.src}" is not defined.`);let g;try{g=this._runtime.untracked(()=>v({context:i.context,event:r,input:this._input,send:l=>{const _=this._invocations?.get(e.id);!this.started||_?.token!==c||h.signal.aborted||this.send(l)},signal:h.signal}))}catch(l){this._completeInvoke(e,c,!1,l);return}this.started&&Promise.resolve(g).then(l=>this._completeInvoke(e,c,!0,l),l=>this._completeInvoke(e,c,!1,l))}_completeInvoke(t,e,r,i){const s=this._invocations?.get(t.id);!this.started||s?.token!==e||s.controller.signal.aborted||this._enqueue(Object.freeze(r?{data:i,type:`@@done.invoke:${t.id}`}:{error:i,type:`@@error.invoke:${t.id}`}),r?t.onDone:t.onError)}_resolveDelay(t,e,r){const i=Number(t),s=Number.isFinite(i)&&t.trim()!==""?i:this._bindings.delays?.[t];if(s===void 0)throw new Error(`[Raph machine] Delay binding "${t}" is not defined.`);const n=typeof s=="function"?s({context:e.context,event:r,input:this._input}):s;if(!Number.isFinite(n)||n<0)throw new TypeError(`[Raph machine] Delay "${t}" must resolve to a non-negative finite number.`);return n}_runOutputs(t,e,r){if(t.length===0)return;let i;for(const s of t){try{const n=this._resolveOutput(s.ref);this._runtime._runWithTraceCause(r,()=>this._runtime.untracked(()=>n({context:e.context,event:s.event,input:this._input,snapshot:e})))}catch(n){(i??=[]).push(n)}if(!this.started)break}i!==void 0&&m(i,`[Raph machine] Machine "${this.id}" output work failed.`)}_notifyListeners(t,e){let r;for(let i=0;i<t.length;i+=1)try{t[i].listener(e)}catch(s){(r??=[]).push(s)}return r}_removeListener(t){const e=this._listeners;if(e===void 0)return;const r=e.indexOf(t);r!==-1&&(this._listeners=e.length===1?void 0:[...e.slice(0,r),...e.slice(r+1)])}_runOutputRefs(t,e,r,i){let s;for(const n of t){try{const h=this._resolveOutput(n);this._runtime._runWithTraceCause(i,()=>this._runtime.untracked(()=>h({context:r.context,event:e,input:this._input,snapshot:r})))}catch(h){(s??=[]).push(h)}if(!this.started)break}s!==void 0&&m(s,`[Raph machine] Machine "${this.id}" output work failed.`)}_resolveOutput(t){if(typeof t=="function")return t;const e=this._bindings.outputs?.[t];if(e===void 0)throw new Error(`[Raph machine] Output binding "${t}" is not defined.`);return e}_cleanupState(t){const e=this._stateCleanups,r=e?.get(t);e===void 0||r===void 0||(e.delete(t),e.size===0&&this._stateCleanups===e&&(this._stateCleanups=void 0),m(x(r),`[Raph machine] State "${this._compiled.states[t].path}" cleanup failed.`))}_stopStateResources(){if(this._stateCleanups===void 0)return;const t=[...this._stateCleanups.keys()].sort((r,i)=>this._compiled.states[i].depth-this._compiled.states[r].depth),e=[];for(const r of t)try{this._cleanupState(r)}catch(i){e.push(i)}m(e,`[Raph machine] Machine "${this.id}" final cleanup failed.`)}_dispose(t){if(this._stopped)return;this._stopped=!0,this._started=!1;let e;try{this._stopStateResources()}catch(r){(e??=[]).push(r)}this._queue!==void 0&&(this._queue.length=0),this._queueCursor=0,this._listeners=void 0;try{this._releaseDebug()}catch(r){(e??=[]).push(r)}if(t&&!this._runtime.disposed){const r=this._currentSnapshot,i=f.stopMachineSnapshot(this.model,r);try{this._runtime._batchReactive(()=>{this._writeSnapshotInBoundary(i),this._currentSnapshot=i})}catch(s){(e??=[]).push(s)}}try{this._releaseSnapshot()}catch(r){(e??=[]).push(r)}m(e,`[Raph machine] Machine "${this.id}" stop failed.`)}_activeClosure(t){const e=new Set;for(const r of t.active){let i=this._compiled.pathToState.get(r);for(;i!==void 0;)e.add(i),i=this._compiled.states[i].parent}return[...e]}_traceHooks(t,e=this._runtime._currentTraceCauseId()??t){return{guard:(r,i,s)=>this._runtime._recordTrace({...e===void 0?{}:{causeId:e},...s===void 0?{}:{context:s},guard:i?"passed":"failed",kind:"machine",name:`${this.id}:guard:${r}`,...t===void 0?{}:{operationId:t}}),transition:r=>this._runtime._recordTrace({...e===void 0?{}:{causeId:e},details:r,kind:"machine",name:`${this.id}:transition`,...t===void 0?{}:{operationId:t}})}}_trace(t,e,r,i,s){this._runtime._recordTrace({...i===void 0?{}:{causeId:i},context:T(s.context)?s.context:void 0,details:{active:s.active,revision:s.revision},kind:"machine",name:`${this.id}:${t}`,...r===void 0?{}:{operationId:r},status:e})}_traceError(t,e,r,i){const s={message:e instanceof Error?e.message:String(e)};this._runtime._recordTrace({...i===void 0?{}:{causeId:i},details:s,kind:"machine",name:`${this.id}:${t}`,...r===void 0?{}:{operationId:r},status:"error"}),this._runtime._recordTrace({...i===void 0?{}:{causeId:i},details:s,kind:"error",name:`machine:${this.id}`,...r===void 0?{}:{operationId:r},status:"error"})}_handlePostCommitError(t,e,r){if(this._traceError(e,t,void 0,r),this._onError!==void 0){this._onError(t);return}if(this._errorPolicy==="stop"&&this._dispose(!0),this._errorPolicy==="throw")throw t}}function A(o,t,e={},r={}){return new $(o,t,e,r)}function z(o,t,e){const r=o._getWorkGraph(),i=r.createProducer(t),s=o._getReactivity()._ownedSignal(e,r.producerHooks(i));let n=s.source,h=e;const c=Object.freeze({get:()=>(o._assertSourceReadable(t),n===void 0?h:n.get()),peek:()=>(t._assertAlive(),n===void 0?h:n.peek())});return r.attachProducer(i,c),{dispose:()=>{const a=n;a!==void 0&&(h=a.peek(),n=void 0,s.dispose())},source:c,writeInBoundary:a=>{t._assertAlive(),n.set(a),h=a}}}function x(o){const t=[];for(let e=o.length-1;e>=0;e--)try{o[e]()}catch(r){t.push(r)}return t}function m(o,t){if(o?.length===1)throw o[0];if(o!==void 0&&o.length>1)throw new AggregateError(o,t)}function D(o){if(typeof o!="object"||o===null||typeof o.type!="string"||!o.type)throw new TypeError("[Raph machine] Event must contain a non-empty string type.")}function T(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}function R(){}function S(o){let t=!0;return()=>{t&&(t=!1,o())}}exports.defineMachine=f.defineMachine;exports.getInitialSnapshot=f.getInitialSnapshot;exports.transition=f.transition;exports.MachinePersistenceError=p;exports.createMachine=A;exports.persistMachineSnapshot=q;exports.restoreMachineSnapshot=I;
|