@raphy-js/raph 1.0.1-dev.20 → 1.0.1-dev.26
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/dist/{core-CyilRD7s.js → core-CClhT8WR.js} +389 -400
- package/dist/core-cPQWYD4K.cjs +1 -0
- package/dist/debug/api/Raph.cjs +1 -1
- package/dist/debug/api/Raph.js +46 -47
- package/dist/debug/api/RaphFacadeSession.cjs +1 -1
- package/dist/debug/api/RaphFacadeSession.js +85 -89
- package/dist/debug/api/RaphReactivityInstance.cjs +1 -1
- package/dist/debug/api/RaphReactivityInstance.js +27 -30
- package/dist/debug/path/DataPath.cjs +1 -1
- package/dist/debug/path/DataPath.js +198 -202
- package/dist/debug/path/PathRouter.cjs +1 -1
- package/dist/debug/path/PathRouter.js +44 -50
- package/dist/debug/path/RaphKernel.cjs +1 -1
- package/dist/debug/path/RaphKernel.js +257 -228
- package/dist/debug/path/data-path.utils.cjs +1 -1
- package/dist/debug/path/data-path.utils.js +41 -41
- package/dist/debug/path/derived/DerivedRegistry.cjs +1 -1
- package/dist/debug/path/derived/DerivedRegistry.js +52 -66
- package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -1
- package/dist/debug/path/derived/RaphDerivedHandle.js +19 -22
- package/dist/debug/path/derived/derived-collection.utils.cjs +1 -1
- package/dist/debug/path/derived/derived-collection.utils.js +70 -70
- package/dist/debug/path/meta/MetaController.cjs +1 -1
- package/dist/debug/path/meta/MetaController.js +57 -65
- package/dist/debug/path/meta/RaphMeta.cjs +1 -1
- package/dist/debug/path/meta/RaphMeta.js +26 -32
- package/dist/debug/path/meta/RaphMetaStore.cjs +1 -1
- package/dist/debug/path/meta/RaphMetaStore.js +24 -30
- package/dist/debug/path/storage/AdapterPathStore.cjs +1 -1
- package/dist/debug/path/storage/AdapterPathStore.js +49 -54
- package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -1
- package/dist/debug/path/storage/DefaultDataAdapter.js +46 -56
- package/dist/debug/path/storage/PathEventHub.cjs +1 -1
- package/dist/debug/path/storage/PathEventHub.js +74 -61
- package/dist/debug/path/storage/PathStore.cjs +1 -1
- package/dist/debug/path/storage/PathStore.js +89 -99
- package/dist/debug/path/storage/createDataDraft.cjs +1 -1
- package/dist/debug/path/storage/createDataDraft.js +24 -28
- 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 +787 -392
- package/dist/debug/reactivity/reactive-object.cjs +1 -1
- package/dist/debug/reactivity/reactive-object.js +81 -96
- 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 +764 -411
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -1
- package/dist/debug/runtime/diagnostics/RaphDebug.js +90 -100
- package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphEffectScope.js +215 -82
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphNode.js +595 -136
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphScope.js +203 -68
- package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -1
- package/dist/debug/runtime/phases/RaphFrameLoop.js +13 -17
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -1
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +618 -357
- 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/reactivity/PathHandle.cjs +1 -1
- package/dist/debug/runtime/reactivity/PathHandle.js +50 -60
- package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -1
- package/dist/debug/runtime/reactivity/RaphMetaSource.js +28 -32
- 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 -1
- package/dist/debug/runtime/reactivity/RaphWorkGraph.js +541 -379
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -1
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +484 -90
- package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -1
- package/dist/debug/runtime/reactivity/RuntimeWatch.js +33 -44
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.cjs +1 -0
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.js +42 -0
- package/dist/entrypoints/runtime.d.ts +2 -1
- package/dist/machine-testing.cjs +1 -1
- package/dist/machine-testing.js +1 -1
- package/dist/machine.cjs +1 -1
- package/dist/machine.js +216 -231
- package/dist/path/RaphKernel.d.ts +24 -0
- package/dist/path/storage/PathEventHub.d.ts +14 -0
- package/dist/path/storage/PathStore.d.ts +4 -4
- package/dist/reactivity/disposal.d.ts +14 -0
- package/dist/reactivity/engine.d.ts +177 -4
- package/dist/reactivity/scope.d.ts +108 -30
- package/dist/runtime/RaphRuntime.d.ts +236 -17
- package/dist/runtime/ownership/RaphEffectScope.d.ts +70 -1
- package/dist/runtime/ownership/RaphNode.d.ts +276 -6
- package/dist/runtime/ownership/RaphScope.d.ts +144 -14
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +202 -28
- package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +195 -0
- package/dist/runtime/phases/RaphPhaseWatch.d.ts +22 -0
- package/dist/runtime/phases/phase.types.d.ts +83 -4
- package/dist/runtime/reactivity/RaphSelector.d.ts +338 -0
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +163 -25
- package/dist/runtime/reactivity/RuntimeReactivity.d.ts +258 -10
- package/dist/runtime/reactivity/RuntimeWatch.d.ts +8 -8
- package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +19 -0
- package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +48 -3
- package/package.json +10 -2
- package/dist/core-ugchZNqC.cjs +0 -1
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
var a = (i, e, t) => e in i ? h(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
-
var r = (i, e, t) => a(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
class l {
|
|
1
|
+
class h {
|
|
5
2
|
/**
|
|
6
3
|
* Создаёт runtime-owned watch с явным lifecycle остановки.
|
|
7
4
|
*/
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
10
|
-
r(this, "_cleanup");
|
|
11
|
-
r(this, "_stopped", !1);
|
|
12
|
-
/**
|
|
13
|
-
* Освобождает предыдущий результат callback и выполняет новую доставку.
|
|
14
|
-
* Ошибка cleanup не лишает живой watcher текущего события.
|
|
15
|
-
*/
|
|
16
|
-
r(this, "deliver", () => {
|
|
5
|
+
constructor(s, t) {
|
|
6
|
+
this._cleanup = void 0, this._stopped = !1, this._runUntracked = s, this._callback = t, this.deliver = () => {
|
|
17
7
|
if (this._stopped)
|
|
18
8
|
return;
|
|
19
9
|
const e = this._cleanup;
|
|
20
10
|
if (e === void 0) {
|
|
21
|
-
const
|
|
22
|
-
if (typeof
|
|
11
|
+
const i = this._callback();
|
|
12
|
+
if (typeof i != "function")
|
|
23
13
|
return;
|
|
24
|
-
this._stopped ? this._runUntracked(
|
|
14
|
+
this._stopped ? this._runUntracked(i) : this._cleanup = i;
|
|
25
15
|
return;
|
|
26
16
|
}
|
|
27
17
|
this._deliverWithCleanup(e);
|
|
28
|
-
}
|
|
29
|
-
this._runUntracked = e, this._callback = t;
|
|
18
|
+
};
|
|
30
19
|
}
|
|
31
20
|
/**
|
|
32
21
|
* Показывает, остановлен ли watch.
|
|
@@ -38,51 +27,51 @@ class l {
|
|
|
38
27
|
* Preserves cleanup/callback error aggregation and reentrant stop semantics
|
|
39
28
|
* for the less common resource-returning callback path.
|
|
40
29
|
*/
|
|
41
|
-
_deliverWithCleanup(
|
|
30
|
+
_deliverWithCleanup(s) {
|
|
42
31
|
const t = [];
|
|
43
|
-
if (this._cleanup = void 0, this._attempt(
|
|
44
|
-
let
|
|
32
|
+
if (this._cleanup = void 0, this._attempt(s, t), !this._stopped) {
|
|
33
|
+
let e = null;
|
|
45
34
|
try {
|
|
46
|
-
const
|
|
47
|
-
typeof
|
|
48
|
-
} catch (
|
|
49
|
-
t.push(
|
|
35
|
+
const i = this._runUntracked(this._callback);
|
|
36
|
+
typeof i == "function" && (e = i);
|
|
37
|
+
} catch (i) {
|
|
38
|
+
t.push(i);
|
|
50
39
|
}
|
|
51
|
-
|
|
40
|
+
e !== null && (this._stopped ? this._attempt(e, t) : this._cleanup = e);
|
|
52
41
|
}
|
|
53
|
-
|
|
42
|
+
r(t);
|
|
54
43
|
}
|
|
55
44
|
/**
|
|
56
45
|
* Останавливает внешнюю регистрацию и cleanup callback, сохраняя обе ошибки.
|
|
57
46
|
*/
|
|
58
|
-
stop(
|
|
47
|
+
stop(s) {
|
|
59
48
|
if (this._stopped)
|
|
60
49
|
return;
|
|
61
50
|
this._stopped = !0;
|
|
62
51
|
const t = [];
|
|
63
|
-
if (
|
|
52
|
+
if (s !== void 0)
|
|
64
53
|
try {
|
|
65
|
-
|
|
66
|
-
} catch (
|
|
67
|
-
t.push(
|
|
54
|
+
s();
|
|
55
|
+
} catch (i) {
|
|
56
|
+
t.push(i);
|
|
68
57
|
}
|
|
69
|
-
const
|
|
70
|
-
this._cleanup = void 0,
|
|
58
|
+
const e = this._cleanup;
|
|
59
|
+
this._cleanup = void 0, e !== void 0 && this._attempt(e, t), r(t);
|
|
71
60
|
}
|
|
72
|
-
_attempt(
|
|
61
|
+
_attempt(s, t) {
|
|
73
62
|
try {
|
|
74
|
-
this._runUntracked(
|
|
75
|
-
} catch (
|
|
76
|
-
t.push(
|
|
63
|
+
this._runUntracked(s);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
t.push(e);
|
|
77
66
|
}
|
|
78
67
|
}
|
|
79
68
|
}
|
|
80
|
-
function
|
|
81
|
-
if (
|
|
82
|
-
throw
|
|
83
|
-
if (
|
|
84
|
-
throw new AggregateError(
|
|
69
|
+
function r(n) {
|
|
70
|
+
if (n.length === 1)
|
|
71
|
+
throw n[0];
|
|
72
|
+
if (n.length > 1)
|
|
73
|
+
throw new AggregateError(n, "[Raph] Runtime watch delivery failed.");
|
|
85
74
|
}
|
|
86
75
|
export {
|
|
87
|
-
|
|
76
|
+
h as RuntimeWatch
|
|
88
77
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function w(t,n,e){n._sweepDue=e,t.push(n),S(t,n,t.length-1)}function _(t,n){const e=n._sweepSlot;if(e<0||t[e]!==n)return!1;n._sweepSlot=-1;const o=t.pop();return o===n||(e!==0&&o._sweepDue<t[e-1>>1]._sweepDue?S(t,o,e):s(t,o,e)),!0}function f(t,n){const e=t[0];e._sweepDue=n,s(t,e,0)}function S(t,n,e){const o=n._sweepDue;for(;e!==0;){const i=e-1>>1,p=t[i];if(p._sweepDue<=o)break;t[e]=p,p._sweepSlot=e,e=i}t[e]=n,n._sweepSlot=e}function s(t,n,e){const o=t.length,i=n._sweepDue;for(let p=e*2+1;p<o;p=e*2+1){const r=p+1;r<o&&t[r]._sweepDue<t[p]._sweepDue&&(p=r);const c=t[p];if(c._sweepDue>=i)break;t[e]=c,c._sweepSlot=e,e=p}t[e]=n,n._sweepSlot=e}exports.dequeueSweeper=_;exports.enqueueSweeper=w;exports.postponeFirstSweeper=f;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function s(n, t, e) {
|
|
2
|
+
t._sweepDue = e, n.push(t), r(n, t, n.length - 1);
|
|
3
|
+
}
|
|
4
|
+
function w(n, t) {
|
|
5
|
+
const e = t._sweepSlot;
|
|
6
|
+
if (e < 0 || n[e] !== t)
|
|
7
|
+
return !1;
|
|
8
|
+
t._sweepSlot = -1;
|
|
9
|
+
const o = n.pop();
|
|
10
|
+
return o === t || (e !== 0 && o._sweepDue < n[e - 1 >> 1]._sweepDue ? r(n, o, e) : f(n, o, e)), !0;
|
|
11
|
+
}
|
|
12
|
+
function S(n, t) {
|
|
13
|
+
const e = n[0];
|
|
14
|
+
e._sweepDue = t, f(n, e, 0);
|
|
15
|
+
}
|
|
16
|
+
function r(n, t, e) {
|
|
17
|
+
const o = t._sweepDue;
|
|
18
|
+
for (; e !== 0; ) {
|
|
19
|
+
const i = e - 1 >> 1, p = n[i];
|
|
20
|
+
if (p._sweepDue <= o)
|
|
21
|
+
break;
|
|
22
|
+
n[e] = p, p._sweepSlot = e, e = i;
|
|
23
|
+
}
|
|
24
|
+
n[e] = t, t._sweepSlot = e;
|
|
25
|
+
}
|
|
26
|
+
function f(n, t, e) {
|
|
27
|
+
const o = n.length, i = t._sweepDue;
|
|
28
|
+
for (let p = e * 2 + 1; p < o; p = e * 2 + 1) {
|
|
29
|
+
const c = p + 1;
|
|
30
|
+
c < o && n[c]._sweepDue < n[p]._sweepDue && (p = c);
|
|
31
|
+
const _ = n[p];
|
|
32
|
+
if (_._sweepDue >= i)
|
|
33
|
+
break;
|
|
34
|
+
n[e] = _, _._sweepSlot = e, e = p;
|
|
35
|
+
}
|
|
36
|
+
n[e] = t, t._sweepSlot = e;
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
w as dequeueSweeper,
|
|
40
|
+
s as enqueueSweeper,
|
|
41
|
+
S as postponeFirstSweeper
|
|
42
|
+
};
|
|
@@ -8,10 +8,11 @@ export type { NodeOptions } from '../runtime/ownership/RaphNode';
|
|
|
8
8
|
export { RaphScope } from '../runtime/ownership/RaphScope';
|
|
9
9
|
export { orderPhaseTasks } from '../runtime/phases/orderPhaseTasks';
|
|
10
10
|
export { RaphSchedulerType } from '../runtime/phases/phase.types';
|
|
11
|
-
export type { FrameLoopLease, RaphAggregateSource, RaphEffectInitialMode, RaphEffectOptions, RaphFrameContext, RaphPhase, RaphPhaseBatch, RaphPhaseEffect, RaphPhaseTask, RaphSchedulerMode, RaphStructureCause, RaphTaskOrderOptions, RaphWatchInclude, RaphWatchInitialMode, RaphWatchOptions, RaphWatchSource, RaphWorkCause, RaphWorkCauseKind, } from '../runtime/phases/phase.types';
|
|
11
|
+
export type { FrameLoopLease, RaphAggregateSource, RaphEffectGroup, RaphEffectGroupOptions, RaphEffectGroupRun, RaphEffectGroupSlot, RaphEffectInitialMode, RaphEffectOptions, RaphFrameContext, RaphPhase, RaphPhaseBatch, RaphPhaseBody, RaphPhaseEffect, RaphPhaseTask, RaphSchedulerMode, RaphStructureCause, RaphTaskOrderOptions, RaphWatchInclude, RaphWatchInitialMode, RaphWatchOptions, RaphWatchSource, RaphWorkCause, RaphWorkCauseKind, } from '../runtime/phases/phase.types';
|
|
12
12
|
export { RaphRuntime } from '../runtime/RaphRuntime';
|
|
13
13
|
export type { RaphRuntimeConfiguration, RaphRuntimeMeta, RaphRuntimeOptions, } from '../runtime/RaphRuntime';
|
|
14
14
|
export { PathHandle } from '../runtime/reactivity/PathHandle';
|
|
15
15
|
export type { RaphMetaSource } from '../runtime/reactivity/RaphMetaSource';
|
|
16
16
|
export type { RaphMetaSourceOptions } from '../runtime/reactivity/RaphMetaSource';
|
|
17
|
+
export type { RaphSelector, RaphSelectorOptions } from '../runtime/reactivity/RaphSelector';
|
|
17
18
|
export type { RaphAggregate } from '../runtime/reactivity/RaphWorkGraph';
|
package/dist/machine-testing.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./core-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./core-cPQWYD4K.cjs");function y(n){const i=h.getCompiledMachine(n),c=M(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=[];for(const t of i.states)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.`);return Object.freeze({deadEnds:Object.freeze(o),inconsistencies:Object.freeze(r),reachable:Object.freeze([...c].map(t=>i.states[t].path)),unreachable:Object.freeze(a),valid:r.length===0})}function k(n,i={}){const c=h.getCompiledMachine(n),a=i.maxDepth??12,o=i.maxPaths??1e3;j(a,"maxDepth"),j(o,"maxPaths");const r=i.events??c.eventTypes.map(l=>({type:l})),t=h.getInitialSnapshot(n,i.input),s=[{events:Object.freeze([]),snapshot:t}],e=[s[0]],f=new Set([b(t)]);let u=0;for(;u<e.length&&s.length<o;){const l=e[u++];if(!(l.events.length>=a||l.snapshot.status!=="active"))for(const m of r){const p=h.transition(n,l.snapshot,m,i.bindings);if(p===l.snapshot)continue;const g=b(p);if(f.has(g))continue;f.add(g);const v=Object.freeze({events:Object.freeze([...l.events,m]),snapshot:p});if(s.push(v),e.push(v),s.length>=o)break}}return Object.freeze(s)}function w(){const n=new Map,i=new Map,c=new Map;return{guard:(a,o)=>{const r=c.get(a)??{failed:0,passed:0};o?r.passed++:r.failed++,c.set(a,r)},record:(a,o,r)=>{for(const t of r.active)n.set(t,(n.get(t)??0)+1);if(a!==r){const t=`${a.active.join("|")} --${o.type}--> ${r.active.join("|")}`;i.set(t,(i.get(t)??0)+1)}},report:()=>Object.freeze({guards:Object.freeze(Object.fromEntries([...c].map(([a,o])=>[a,Object.freeze({...o})]))),states:Object.freeze(Object.fromEntries(n)),transitions:Object.freeze(Object.fromEntries(i))}),reset:()=>{n.clear(),i.clear(),c.clear()},transition:(a,o,r,t)=>{const s=h.transition(a,o,r,t,{guard:(e,f)=>{const u=c.get(e)??{failed:0,passed:0};f?u.passed++:u.failed++,c.set(e,u)}});for(const e of s.active)n.set(e,(n.get(e)??0)+1);if(o!==s){const e=`${o.active.join("|")} --${r.type}--> ${s.active.join("|")}`;i.set(e,(i.get(e)??0)+1)}return s}}}function O(n=0){if(!Number.isFinite(n))throw new TypeError("[Raph machine] Manual clock initial time must be finite.");let i=n,c=1;const a=new Map;return{advance:s=>{if(!Number.isFinite(s)||s<0)throw new TypeError("[Raph machine] Clock advance duration must be non-negative and finite.");const e=i+s;r(e),i=e},clearTimeout:s=>{const e=a.get(s);e!==void 0&&(e.active=!1,a.delete(e.id))},now:()=>i,get pending(){return a.size},runAll:()=>{let s=0;for(;a.size!==0;){if(++s>1e5)throw new Error("[Raph machine] Manual clock exceeded 100000 timer turns.");const e=t();if(e===void 0)break;r(e.at),i=e.at}},setTimeout:(s,e)=>{if(!Number.isFinite(e)||e<0)throw new TypeError("[Raph machine] Timer delay must be non-negative and finite.");const f={active:!0,at:i+e,callback:s,id:c++};return a.set(f.id,f),f.id}};function r(s){for(;;){const e=t();if(e===void 0||e.at>s)return;i=e.at,a.delete(e.id),e.active&&(e.active=!1,e.callback())}}function t(){let s;for(const e of a.values())e.active&&(s===void 0||e.at<s.at||e.at===s.at&&e.id<s.id)&&(s=e);return s}}function M(n){const i=new Set,c=new Set,a=[n.initial];let o=0;for(;o<a.length;){const r=a[o++];if(c.has(r))continue;c.add(r);for(const e of n.ancestry[r])c.has(e)||a.push(e),i.add(e);const t=n.states[r];if(t.kind==="history"){if(t.historyFallback!==void 0)a.push(t.historyFallback);else if(t.parent!==void 0){const e=n.states[t.parent];e.initial!==void 0&&a.push(e.initial)}}t.initial!==void 0&&a.push(t.initial),t.kind==="parallel"&&a.push(...t.children.filter(e=>n.states[e].kind!=="history"));const s=[t.always,t.onDone,...t.on.values(),...t.after.values()];for(const e of t.invokes)s.push(e.onDone,e.onError);for(const e of s)for(const f of e)f.target!==void 0&&a.push(f.target)}return i}function b(n){return[n.status,n.active.join("|"),d(n.context),d(n.history),d(n.output)].join(":")}function d(n){return n===null||typeof n!="object"?JSON.stringify(n):Array.isArray(n)?`[${n.map(d).join(",")}]`:`{${Object.keys(n).sort().map(i=>`${JSON.stringify(i)}:${d(n[i])}`).join(",")}}`}function j(n,i){if(!Number.isSafeInteger(n)||n<=0)throw new TypeError(`[Raph machine] ${i} must be a positive safe integer.`)}exports.createMachineCoverage=w;exports.createManualMachineClock=O;exports.enumerateMachinePaths=k;exports.inspectMachine=y;
|
package/dist/machine-testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as j, g as y, a as k } from "./core-
|
|
1
|
+
import { t as j, g as y, a as k } from "./core-CClhT8WR.js";
|
|
2
2
|
function z(n) {
|
|
3
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
4
|
for (const t of i.states)
|
package/dist/machine.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./core-ugchZNqC.cjs"),J=require("./debug/runtime/ownership/RaphScope.cjs");class m extends Error{}function B(o,t){return g.assertMachineSnapshot(o,t),w(t.context,"context"),t.output!==void 0&&w(t.output,"output"),Object.freeze({active:Object.freeze([...t.active]),context:k(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:k(t.output)},revision:t.revision,status:t.status,version:o.version})}function L(o,t,e){const r=g.getCompiledMachine(o);try{if(typeof t!="object"||t===null||Array.isArray(t))throw new m("[Raph machine] Persisted snapshot must be an object.");if(t.modelId!==o.id)throw new m(`[Raph machine] Snapshot model "${t.modelId}" is incompatible with "${o.id}".`);if(!Number.isSafeInteger(t.version)||t.version<1)throw new m("[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 m(`[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 m(`[Raph machine] Migration from version ${i.version} must produce version ${i.version+1}.`);i=n}if(i.version!==o.version)throw new m(`[Raph machine] Snapshot version ${i.version} is newer than model version ${o.version}.`);return w(i.context,"context"),i.output!==void 0&&w(i.output,"output"),g.hydrateSnapshot(o,i,e)}catch(i){throw i instanceof m?i:new m(`[Raph machine] Persisted snapshot is invalid: ${i instanceof Error?i.message:String(i)}`)}}function w(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 m(`[Raph machine] ${t} contains a non-finite number.`);return}if(r!=="object")throw new m(`[Raph machine] ${t} is not JSON-safe.`);const i=o;if(e.has(i))throw new m(`[Raph machine] ${t} contains a cycle.`);if(e.add(i),Array.isArray(o))o.forEach((s,n)=>w(s,`${t}[${n}]`,e));else{const s=Object.getPrototypeOf(o);if(s!==Object.prototype&&s!==null)throw new m(`[Raph machine] ${t} contains a non-plain object.`);for(const[n,a]of Object.entries(o))w(a,`${t}.${n}`,e)}e.delete(i)}function k(o){return JSON.parse(JSON.stringify(o))}const A=new WeakMap,R=Symbol("RaphMachineActivationCancelled"),z=Object.freeze({type:"@@init"}),Q=Object.freeze({clearTimeout:o=>clearTimeout(o),now:()=>Date.now(),setTimeout:(o,t)=>setTimeout(o,t)});class C{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=E,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=E,this._releaseDebug=E,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=g.getCompiledMachine(e),this.model=e,this._bindings=r,this._clock=i.clock??Q,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=(A.get(this._runtime)??0)+1;if(A.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(()=>g.createInitialSnapshot(e,this._input,r,this._runtime._traces("machine")?this._traceHooks():void 0)):void 0,a=(n==null?void 0:n.snapshot)??L(e,i.persisted,this._input);this._initialPlan=n==null?void 0:n.plan,this._restored=i.persisted!==void 0;const c=H(this._runtime,t,a);this._releaseSnapshot=c.dispose,this._writeSnapshotInBoundary=c.writeInBoundary,this._currentSnapshot=a,this.snapshot=c.source;try{this._releaseDebug=this._runtime._registerMachineDebug({id:this.id,ownerId:t.id,...i.parentId===void 0?{}:{parentId:i.parentId},snapshot:()=>{var _;const h=this._currentSnapshot,u=Object.fromEntries(this._activeClosure(h).flatMap(f=>{const d=this._compiled.states[f].meta;return d===void 0?[]:[[this._compiled.states[f].path,d]]}));return Object.freeze({active:h.active,actors:Object.freeze([...((_=this._actors)==null?void 0:_.keys())??[]]),contextKeys:Object.freeze(N(h.context)?Object.keys(h.context):[]),id:this.id,meta:Object.freeze(u),modelId:e.id,ownerId:t.id,...i.parentId===void 0?{}:{parentId:i.parentId},revision:h.revision,status:h.status})}}),this._releaseOwnership=t.own(()=>this._dispose(!1))}catch(h){const u=[h];try{this._releaseDebug()}catch(_){u.push(_)}try{this._releaseSnapshot()}catch(_){u.push(_)}throw u.length>1?new AggregateError(u,`[Raph machine] Machine "${this.id}" construction rollback failed.`):h}}get started(){return this._started&&!this._stopped}start(){var s,n;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((a,c)=>this._compiled.states[a].depth-this._compiled.states[c].depth);let r=!1,i;this._processing=!0;try{const a=[];if(!this._restored){try{this._runOutputs(((s=this._initialPlan)==null?void 0:s.exitOutputs)??[],t,this._runtime._currentTraceCauseId())}catch(c){a.push(c)}if(this.started)try{this._runOutputs(((n=this._initialPlan)==null?void 0:n.transitionOutputs)??[],t,this._runtime._currentTraceCauseId())}catch(c){a.push(c)}if(this.started){const c=e.flatMap(h=>this._compiled.states[h].entry.map(u=>({event:z,ref:u})));try{this._runOutputs(c,t,this._runtime._currentTraceCauseId())}catch(h){a.push(h)}}}if(this.started&&t.status==="active")for(const c of e){if(!this.started)break;try{this._activateState(c,z,t)}catch(h){a.push(h)}}v(a,`[Raph machine] Machine "${this.id}" start work failed.`)}catch(a){try{this._handlePostCommitError(a,"start",this._runtime._currentTraceCauseId())}catch(c){r=!0,i=c}}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){var i;const r=(i=this._actors)==null?void 0:i.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 B(this.model,this.snapshot.get())}stop(){let t;try{this._dispose(!0)}catch(e){(t??(t=[])).push(e)}try{this._releaseOwnership()}catch(e){(t??(t=[])).push(e)}v(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(F(t),this._processing)return(this._queue??(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 a=e===void 0?this._compiled.eventIndexes.get(t.type):void 0;if(e===void 0&&a===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),h=this._runtime._hasActiveReactiveContext()?this._runtime.untracked(()=>this._evaluate(r,t,a,e,c)):this._evaluate(r,t,a,e,c);if(!h.changed)return i!==void 0&&this._trace(t.type,"ignored",i,s,r),this._ignored(r);this._runtime._batchReactive(()=>{this._writeSnapshotInBoundary(h.snapshot),this._currentSnapshot=h.snapshot,n=h.snapshot});let u;try{this._applyPlan(h.plan,h.snapshot,s)}catch(d){(u??(u=[])).push(d)}const _=this._listeners;if(this.started&&_!==void 0){const d=this._notifyListeners(_,h.snapshot);d!==void 0&&(u??(u=[])).push(...d)}if(this.started&&h.snapshot.status==="done")try{this._stopStateResources()}catch(d){(u??(u=[])).push(d)}u!==void 0&&v(u,`[Raph machine] Machine "${this.id}" post-commit work failed.`);const f=this.started?h.snapshot:this._currentSnapshot;return i!==void 0&&this._trace(t.type,"end",i,s,f),{snapshot:f,status:"transitioned"}}catch(a){if(n!==void 0)return this._handlePostCommitError(a,t.type,s),{snapshot:this._currentSnapshot,status:"transitioned"};if(this._traceError(t.type,a,i,s),this._onError!==void 0)return this._onError(a),this._ignored(this._currentSnapshot);if(this._errorPolicy==="stop"&&this._dispose(!0),this._errorPolicy==="ignore")return this._ignored(this._currentSnapshot);throw a}}_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?g.runValidatedMacrostep(this.model,t,e,this._bindings,this._input,s,this._compiled,r):g.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)}}v(i,`[Raph machine] Machine "${this.id}" post-commit work failed.`)}_activateState(t,e,r){var a,c;if(!this.started||(a=this._stateCleanups)!=null&&a.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??(this._stateCleanups=new Map);n.set(t,s);try{for(const h of i.resources){const u=(c=this._bindings.resources)==null?void 0:c[h];if(u===void 0)throw new Error(`[Raph machine] Resource binding "${h}" is not defined.`);const _=new AbortController;let f;try{const d=this._runtime.untracked(()=>u({context:r.context,event:e,input:this._input,owner:this._owner,signal:_.signal,snapshot:r}));typeof d=="function"&&(f=d)}catch(d){throw _.abort(),d}if(s.push(O(()=>{_.abort(),f==null||f()})),!this.started)throw R}for(const[h,u]of i.after){const _=this._resolveDelay(h,r,e);if(!this.started)throw R;const f=this._clock.setTimeout(()=>{var d;!this.started||!((d=this._stateCleanups)!=null&&d.has(t))||this._enqueue(Object.freeze({type:`@@after:${i.path}:${h}`}),u)},_);if(s.push(O(()=>this._clock.clearTimeout(f))),!this.started)throw R}for(const h of i.invokes)if(this._startInvoke(i,h,e,r,s),!this.started)throw R}catch(h){n.get(t)===s&&n.delete(t),n.size===0&&this._stateCleanups===n&&(this._stateCleanups=void 0);const u=D(s);v(h===R?u:[h,...u],`[Raph machine] State "${i.path}" activation failed.`)}}_startInvoke(t,e,r,i,s){var M,x,T,q,I,P;const n=this._invocations??(this._invocations=new Map);if(n.has(e.id))throw new Error(`[Raph machine] Invoke id "${e.id}" is already active.`);const a=new AbortController,c={},h={controller:a,invoke:e,token:c};n.set(e.id,h);const u=()=>{var y;a.abort();const l=n.get(e.id);(l==null?void 0:l.token)===c&&n.delete(e.id),n.size===0&&this._invocations===n&&(this._invocations=void 0);const p=this._actors;p==null||p.delete(e.id),(p==null?void 0:p.size)===0&&this._actors===p&&(this._actors=void 0),(y=h.actor)==null||y.stop()};s.push(O(u));const _=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"?(M=this._bindings.actors)==null?void 0:M[e.src]:e.src;if(l===void 0)throw new Error(`[Raph machine] Actor source "${String(e.src)}" is not defined.`);const p=new C(this._owner,l,{},{errorPolicy:e.onError.length===0?"throw":"ignore",id:`${this.id}/${e.id}`,input:_,onError:e.onError.length===0?void 0:$=>{var b,S;!this.started||((S=(b=this._invocations)==null?void 0:b.get(e.id))==null?void 0:S.token)!==c||this._enqueue(Object.freeze({error:$,type:`@@error.actor:${e.id}`}),e.onError)},parentId:this.id});if(!this.started||((T=(x=this._invocations)==null?void 0:x.get(e.id))==null?void 0:T.token)!==c||a.signal.aborted){p.stop();return}h.actor=p,(this._actors??(this._actors=new Map)).set(e.id,p);const y=p.subscribe($=>{var b,S;$.status==="done"&&((S=(b=this._invocations)==null?void 0:b.get(e.id))==null?void 0:S.token)===c&&this._enqueue(Object.freeze({output:$.output,type:`@@done.actor:${e.id}`}),e.onDone)});if(s.push(O(y)),p.start(),!this.started)return;const j=p.snapshot.peek();j.status==="done"&&((I=(q=this._invocations)==null?void 0:q.get(e.id))==null?void 0:I.token)===c&&this._enqueue(Object.freeze({output:j.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 f=(P=this._bindings.tasks)==null?void 0:P[e.src];if(f===void 0)throw new Error(`[Raph machine] Task binding "${e.src}" is not defined.`);let d;try{d=this._runtime.untracked(()=>f({context:i.context,event:r,input:this._input,send:l=>{var y;const p=(y=this._invocations)==null?void 0:y.get(e.id);!this.started||(p==null?void 0:p.token)!==c||a.signal.aborted||this.send(l)},signal:a.signal}))}catch(l){this._completeInvoke(e,c,!1,l);return}this.started&&Promise.resolve(d).then(l=>this._completeInvoke(e,c,!0,l),l=>this._completeInvoke(e,c,!1,l))}_completeInvoke(t,e,r,i){var n;const s=(n=this._invocations)==null?void 0:n.get(t.id);!this.started||(s==null?void 0: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){var a;const i=Number(t),s=Number.isFinite(i)&&t.trim()!==""?i:(a=this._bindings.delays)==null?void 0:a[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??(i=[])).push(n)}if(!this.started)break}i!==void 0&&v(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??(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 a=this._resolveOutput(n);this._runtime._runWithTraceCause(i,()=>this._runtime.untracked(()=>a({context:r.context,event:e,input:this._input,snapshot:r})))}catch(a){(s??(s=[])).push(a)}if(!this.started)break}s!==void 0&&v(s,`[Raph machine] Machine "${this.id}" output work failed.`)}_resolveOutput(t){var r;if(typeof t=="function")return t;const e=(r=this._bindings.outputs)==null?void 0:r[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==null?void 0:e.get(t);e===void 0||r===void 0||(e.delete(t),e.size===0&&this._stateCleanups===e&&(this._stateCleanups=void 0),v(D(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)}v(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??(e=[])).push(r)}this._queue!==void 0&&(this._queue.length=0),this._queueCursor=0,this._listeners=void 0;try{this._releaseDebug()}catch(r){(e??(e=[])).push(r)}if(t&&!this._runtime.disposed){const r=this._currentSnapshot,i=g.stopMachineSnapshot(this.model,r);try{this._runtime._batchReactive(()=>{this._writeSnapshotInBoundary(i),this._currentSnapshot=i})}catch(s){(e??(e=[])).push(s)}}try{this._releaseSnapshot()}catch(r){(e??(e=[])).push(r)}v(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:N(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 W(o,t,e={},r={}){return new C(o,t,e,r)}function H(o,t,e){const r=o._getWorkGraph(),i=r.createProducer(t),s=o._getReactivity()._ownedSignal(e,r.producerHooks(i));let n=s.source,a=e;const c=Object.freeze({get:()=>(o._assertSourceReadable(t),n===void 0?a:n.get()),peek:()=>(t._assertAlive(),n===void 0?a:n.peek())});return r.attachProducer(i,c),{dispose:()=>{const h=n;h!==void 0&&(a=h.peek(),n=void 0,s.dispose())},source:c,writeInBoundary:h=>{t._assertAlive(),n.set(h),a=h}}}function D(o){const t=[];for(let e=o.length-1;e>=0;e--)try{o[e]()}catch(r){t.push(r)}return t}function v(o,t){if((o==null?void 0:o.length)===1)throw o[0];if(o!==void 0&&o.length>1)throw new AggregateError(o,t)}function F(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 N(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)}function E(){}function O(o){let t=!0;return()=>{t&&(t=!1,o())}}exports.defineMachine=g.defineMachine;exports.getInitialSnapshot=g.getInitialSnapshot;exports.transition=g.transition;exports.MachinePersistenceError=m;exports.createMachine=W;exports.persistMachineSnapshot=B;exports.restoreMachineSnapshot=L;
|
|
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;
|