@statelyai/sdk 0.14.1 → 0.14.2
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 +2 -0
- package/dist/auth.d.mts +1 -1
- package/dist/{dist-C8jVuuHf.mjs → dist-CO36Ks-i.mjs} +239 -35
- package/dist/dist-Ci5I7Rjq.mjs +9401 -0
- package/dist/embed.d.mts +4 -3
- package/dist/{graph-R0sbxnZ7.d.mts → graph-3oSqiY4N.d.mts} +5 -1
- package/dist/graph.d.mts +1 -1
- package/dist/graph.mjs +4 -0
- package/dist/{index-DVjNSTuQ.d.mts → index-CcgKzQ-C.d.mts} +52 -4
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/{inspect-BcKTFJI1.mjs → inspect-DWDTNMEc.mjs} +15 -6
- package/dist/inspect.mjs +1 -1
- package/dist/patchTypes.d.mts +1 -1
- package/dist/protocol.d.mts +8 -6
- package/dist/studio.d.mts +1 -1
- package/dist/sync.d.mts +1 -1
- package/dist/sync.mjs +209 -7
- package/package.json +2 -2
- /package/dist/{auth-DmPZiERd.d.mts → auth-D9-iLi-S.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -132,6 +132,8 @@ completed request-scoped runs stay available for inspection.
|
|
|
132
132
|
|
|
133
133
|
XState v5 and v6 inspection events normalize to independent actor, event,
|
|
134
134
|
snapshot, and stop observations before crossing the WebSocket protocol.
|
|
135
|
+
Observations captured before the first transport registration replay in order
|
|
136
|
+
after the initial actor-tree baseline. Reconnects use the latest checkpoint.
|
|
135
137
|
In Node, the inspector opens in the default browser automatically. The SDK
|
|
136
138
|
generates a cryptographically random session capability; hosted inspectors open
|
|
137
139
|
without requiring login. The session capability controls access to the live
|
package/dist/auth.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as getCredentialToken, n as StatelyCredential, r as createAuthorizationHeader, t as StatelyAuthMode } from "./auth-
|
|
1
|
+
import { i as getCredentialToken, n as StatelyCredential, r as createAuthorizationHeader, t as StatelyAuthMode } from "./auth-D9-iLi-S.mjs";
|
|
2
2
|
export { StatelyAuthMode, StatelyCredential, createAuthorizationHeader, getCredentialToken };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
-
import "xstate";
|
|
3
2
|
import "xstate/graph";
|
|
4
3
|
|
|
5
4
|
//#region src/statelyPragma.ts
|
|
@@ -7064,6 +7063,10 @@ function stripExportDefault(code) {
|
|
|
7064
7063
|
if (trimmed.startsWith("export default ")) return trimmed.slice(15).replace(/;$/, "");
|
|
7065
7064
|
return trimmed;
|
|
7066
7065
|
}
|
|
7066
|
+
const MACHINE_PROFILES = ["xstate-v5", "xstate-v6-alpha"];
|
|
7067
|
+
function isXStateV6Profile(profile) {
|
|
7068
|
+
return profile === "xstate-v6-alpha";
|
|
7069
|
+
}
|
|
7067
7070
|
/**
|
|
7068
7071
|
* Graph-native transition references. Transitions point at invoke/action/state
|
|
7069
7072
|
* blocks by graph id (`@statelyai.*`); the literal `xstate.*` event is produced
|
|
@@ -7077,9 +7080,12 @@ const STATELY_REF_PREFIX = {
|
|
|
7077
7080
|
invokeDone: "@statelyai.invoke.done",
|
|
7078
7081
|
invokeError: "@statelyai.invoke.error",
|
|
7079
7082
|
invokeSnapshot: "@statelyai.invoke.snapshot",
|
|
7083
|
+
invokeTimeout: "@statelyai.invoke.timeout",
|
|
7080
7084
|
actionDone: "@statelyai.action.done",
|
|
7081
7085
|
actionError: "@statelyai.action.error",
|
|
7082
|
-
stateDone: "@statelyai.state.done"
|
|
7086
|
+
stateDone: "@statelyai.state.done",
|
|
7087
|
+
stateError: "@statelyai.state.error",
|
|
7088
|
+
stateTimeout: "@statelyai.state.timeout"
|
|
7083
7089
|
};
|
|
7084
7090
|
function parseStatelyRef(eventType) {
|
|
7085
7091
|
if (eventType.startsWith(`${LEGACY_STATELY_PREFIX}.`)) eventType = `${STATELY_PREFIX}${eventType.slice(8)}`;
|
|
@@ -7177,7 +7183,12 @@ function deepSimplify(config) {
|
|
|
7177
7183
|
}
|
|
7178
7184
|
}
|
|
7179
7185
|
}
|
|
7180
|
-
for (const key of [
|
|
7186
|
+
for (const key of [
|
|
7187
|
+
"always",
|
|
7188
|
+
"onDone",
|
|
7189
|
+
"onError",
|
|
7190
|
+
"onTimeout"
|
|
7191
|
+
]) {
|
|
7181
7192
|
const val = config[key];
|
|
7182
7193
|
if (val && typeof val === "object" && !Array.isArray(val)) simplifyAttributes(val);
|
|
7183
7194
|
else if (Array.isArray(val)) {
|
|
@@ -7194,7 +7205,7 @@ function deepSimplify(config) {
|
|
|
7194
7205
|
return config;
|
|
7195
7206
|
}
|
|
7196
7207
|
function buildMeta(meta, color) {
|
|
7197
|
-
if (isCodeExpression(meta)) return meta;
|
|
7208
|
+
if (isCodeExpression$1(meta)) return meta;
|
|
7198
7209
|
const result = {};
|
|
7199
7210
|
if (meta) {
|
|
7200
7211
|
for (const [k, v] of Object.entries(meta)) if (v !== void 0 && v !== null) result[k] = v;
|
|
@@ -7202,7 +7213,7 @@ function buildMeta(meta, color) {
|
|
|
7202
7213
|
if (color) result["@statelyai.color"] = color;
|
|
7203
7214
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
7204
7215
|
}
|
|
7205
|
-
function isCodeExpression(value) {
|
|
7216
|
+
function isCodeExpression$1(value) {
|
|
7206
7217
|
return Boolean(value && typeof value === "object" && !Array.isArray(value) && value["@type"] === "code" && typeof value.expr === "string");
|
|
7207
7218
|
}
|
|
7208
7219
|
/** Format event param — supports { type: string } (new) and plain string (legacy) */
|
|
@@ -7426,6 +7437,7 @@ function tagToString(tag) {
|
|
|
7426
7437
|
return typeof tag === "string" ? tag : tag.name;
|
|
7427
7438
|
}
|
|
7428
7439
|
function graphToMachineConfig(graph, options = {}) {
|
|
7440
|
+
const v6 = isXStateV6Profile(graph.data.profile);
|
|
7429
7441
|
const { showDescriptions = true, showMeta = true, inlineGuardsAsTypeRef = false } = options;
|
|
7430
7442
|
const config = {};
|
|
7431
7443
|
function getNodeConfig(node) {
|
|
@@ -7442,12 +7454,19 @@ function graphToMachineConfig(graph, options = {}) {
|
|
|
7442
7454
|
Object.assign(nodeConfig, {
|
|
7443
7455
|
id: resolvedNodeId,
|
|
7444
7456
|
type: nodeType === "normal" ? void 0 : nodeType ?? void 0,
|
|
7445
|
-
initial: initialNode
|
|
7457
|
+
initial: initialNode ? node.data.initialInput !== void 0 ? {
|
|
7458
|
+
target: initialNode.data.key,
|
|
7459
|
+
input: node.data.initialInput
|
|
7460
|
+
} : initialNode.data.key : void 0,
|
|
7461
|
+
...node.data.timeout !== void 0 ? { timeout: node.data.timeout } : void 0,
|
|
7462
|
+
...node.data.route !== void 0 ? { route: node.data.route } : void 0,
|
|
7446
7463
|
...node.data.entry?.length ? { entry: node.data.entry.map(serializeActionItem) } : void 0,
|
|
7447
7464
|
...node.data.exit?.length ? { exit: node.data.exit.map(serializeActionItem) } : void 0,
|
|
7448
7465
|
...node.data.invokes?.length ? { invoke: node.data.invokes.map((inv) => ({
|
|
7449
|
-
src: inv.src,
|
|
7466
|
+
src: inv.srcExpression ?? inv.src,
|
|
7450
7467
|
id: inv.invocationId ?? inv.id,
|
|
7468
|
+
...inv.registryKey ? { registryKey: inv.registryKey } : void 0,
|
|
7469
|
+
...inv.timeout !== void 0 ? { timeout: inv.timeout } : void 0,
|
|
7451
7470
|
...inv.input ? { input: inv.input } : void 0,
|
|
7452
7471
|
...inv.output ? { output: inv.output } : void 0
|
|
7453
7472
|
})) } : void 0,
|
|
@@ -7465,6 +7484,8 @@ function graphToMachineConfig(graph, options = {}) {
|
|
|
7465
7484
|
const alwaysArr = [];
|
|
7466
7485
|
const choiceArr = [];
|
|
7467
7486
|
const onDone = {};
|
|
7487
|
+
const onError = [];
|
|
7488
|
+
const onTimeout = [];
|
|
7468
7489
|
const invokeMap = {};
|
|
7469
7490
|
for (const edge of edges) {
|
|
7470
7491
|
const targetNode = graph.nodes.find((n) => n.id === edge.targetId);
|
|
@@ -7472,10 +7493,12 @@ function graphToMachineConfig(graph, options = {}) {
|
|
|
7472
7493
|
const type = edge.data.eventType ?? "";
|
|
7473
7494
|
const transitionMeta = showMeta ? buildMeta(edge.data.meta, edge.data.color) : void 0;
|
|
7474
7495
|
const transitionObject = {
|
|
7496
|
+
...edge.data.matches ? { matches: edge.data.matches } : void 0,
|
|
7475
7497
|
target: edge.data.transitionType === "targetless" ? void 0 : `${resolvedTarget}`,
|
|
7476
7498
|
...edge.data.transitionType === "reenter" ? { reenter: true } : void 0,
|
|
7477
7499
|
guard: edge.data.guard ? serializeGuard(edge.data.guard, inlineGuardsAsTypeRef) : void 0,
|
|
7478
7500
|
...edge.data.context !== void 0 ? { context: edge.data.context } : void 0,
|
|
7501
|
+
...edge.data.input !== void 0 ? { input: edge.data.input } : void 0,
|
|
7479
7502
|
actions: edge.data.actions?.length ? edge.data.actions.map(serializeActionItem) : void 0,
|
|
7480
7503
|
description: edge.data.description ?? void 0,
|
|
7481
7504
|
...transitionMeta ? { meta: transitionMeta } : void 0
|
|
@@ -7494,10 +7517,28 @@ function graphToMachineConfig(graph, options = {}) {
|
|
|
7494
7517
|
if (ref) if (ref.kind === "invokeDone") nestInvoke(ref.blockId, "onDone");
|
|
7495
7518
|
else if (ref.kind === "invokeError") nestInvoke(ref.blockId, "onError");
|
|
7496
7519
|
else if (ref.kind === "invokeSnapshot") nestInvoke(ref.blockId, "onSnapshot");
|
|
7520
|
+
else if (ref.kind === "invokeTimeout") nestInvoke(ref.blockId, "onTimeout");
|
|
7497
7521
|
else if (ref.kind === "stateDone") {
|
|
7498
7522
|
if (!onDone[type]) onDone[type] = [];
|
|
7499
7523
|
onDone[type].push(transitionObject);
|
|
7500
|
-
} else
|
|
7524
|
+
} else if (ref.kind === "stateError") onError.push(transitionObject);
|
|
7525
|
+
else if (ref.kind === "stateTimeout") onTimeout.push(transitionObject);
|
|
7526
|
+
else {
|
|
7527
|
+
const verb = ref.kind === "actionDone" ? "done" : "error";
|
|
7528
|
+
const actorId = resolveSpawnActorId$1(node, ref.blockId);
|
|
7529
|
+
if (v6) {
|
|
7530
|
+
const eventType = `xstate.${verb}.actor`;
|
|
7531
|
+
if (!on[eventType]) on[eventType] = [];
|
|
7532
|
+
on[eventType].push({
|
|
7533
|
+
...transitionObject,
|
|
7534
|
+
matches: {
|
|
7535
|
+
...transitionObject.matches,
|
|
7536
|
+
actorId
|
|
7537
|
+
}
|
|
7538
|
+
});
|
|
7539
|
+
} else pushOn(`xstate.${verb}.actor.${actorId}`);
|
|
7540
|
+
}
|
|
7541
|
+
else if (edge.data.route) continue;
|
|
7501
7542
|
else if (type === "" && node.data.type === "choice") choiceArr.push(transitionObject);
|
|
7502
7543
|
else if (type === "") alwaysArr.push(transitionObject);
|
|
7503
7544
|
else if (type.startsWith("xstate.after.")) {
|
|
@@ -7520,6 +7561,8 @@ function graphToMachineConfig(graph, options = {}) {
|
|
|
7520
7561
|
if (alwaysArr.length > 0) nodeConfig.always = singleOrArray(alwaysArr);
|
|
7521
7562
|
if (choiceArr.length > 0) nodeConfig.choice = singleOrArray(choiceArr);
|
|
7522
7563
|
if (Object.keys(onDone).length > 0) nodeConfig.onDone = singleOrArray(Object.values(onDone).flat());
|
|
7564
|
+
if (onError.length > 0) nodeConfig.onError = singleOrArray(onError);
|
|
7565
|
+
if (onTimeout.length > 0) nodeConfig.onTimeout = singleOrArray(onTimeout);
|
|
7523
7566
|
if (Object.keys(invokeMap).length > 0 && Array.isArray(nodeConfig.invoke)) nodeConfig.invoke = nodeConfig.invoke.map((inv, index) => {
|
|
7524
7567
|
const mapped = invokeMap[node.data.invokes?.[index]?.id ?? inv.id];
|
|
7525
7568
|
if (!mapped) return inv;
|
|
@@ -7527,7 +7570,8 @@ function graphToMachineConfig(graph, options = {}) {
|
|
|
7527
7570
|
...inv,
|
|
7528
7571
|
...mapped.onDone ? { onDone: singleOrArray(mapped.onDone) } : void 0,
|
|
7529
7572
|
...mapped.onError ? { onError: singleOrArray(mapped.onError) } : void 0,
|
|
7530
|
-
...mapped.onSnapshot ? { onSnapshot: singleOrArray(mapped.onSnapshot) } : void 0
|
|
7573
|
+
...mapped.onSnapshot ? { onSnapshot: singleOrArray(mapped.onSnapshot) } : void 0,
|
|
7574
|
+
...mapped.onTimeout ? { onTimeout: singleOrArray(mapped.onTimeout) } : void 0
|
|
7531
7575
|
};
|
|
7532
7576
|
});
|
|
7533
7577
|
}
|
|
@@ -7548,7 +7592,14 @@ function graphToMachineConfig(graph, options = {}) {
|
|
|
7548
7592
|
if (graph.data.context !== void 0 && graph.data.context !== null) config.context = graph.data.context;
|
|
7549
7593
|
return deepSimplify(config);
|
|
7550
7594
|
}
|
|
7551
|
-
const INLINE_EXPRESSION_DIRECTIVE_FIELDS = [
|
|
7595
|
+
const INLINE_EXPRESSION_DIRECTIVE_FIELDS = [
|
|
7596
|
+
"input",
|
|
7597
|
+
"output",
|
|
7598
|
+
"srcExpression",
|
|
7599
|
+
"timeout",
|
|
7600
|
+
"initialInput",
|
|
7601
|
+
"route"
|
|
7602
|
+
];
|
|
7552
7603
|
function jsonSchemaToTSType(schema) {
|
|
7553
7604
|
if (!schema) return "unknown";
|
|
7554
7605
|
if (schema.enum) return schema.enum.map((v) => typeof v === "string" ? `'${v}'` : String(v)).join(" | ");
|
|
@@ -7637,11 +7688,13 @@ function graphToXStateTS(graph, options = {}) {
|
|
|
7637
7688
|
const hasDelays = !!impls?.delays.length;
|
|
7638
7689
|
const hasSetup = hasSchemas || hasActions || hasGuards || hasActors || hasDelays;
|
|
7639
7690
|
const builtInActions = getUsedBuiltInActions(graph, xstateVersion);
|
|
7691
|
+
const actorSourceImports = getActorSourceImports(graph);
|
|
7640
7692
|
const imports = buildImports({
|
|
7641
7693
|
hasSetup,
|
|
7642
7694
|
hasActors,
|
|
7643
7695
|
actors: impls?.actors ?? [],
|
|
7644
7696
|
builtInActions,
|
|
7697
|
+
actorSourceImports,
|
|
7645
7698
|
usesTypes: xstateVersion === 6 && supportsTypeSyntax && hasSchemas
|
|
7646
7699
|
});
|
|
7647
7700
|
const machineConfig = xstateVersion === 6 ? toV6MachineConfig(graphToMachineConfig(graph, configOptions)) : toV5MachineConfig(graphToMachineConfig(graph, configOptions));
|
|
@@ -7735,7 +7788,7 @@ function mapV6MachineConfig(value, context = {}) {
|
|
|
7735
7788
|
result[key] = mapV6TransitionMap(item);
|
|
7736
7789
|
continue;
|
|
7737
7790
|
}
|
|
7738
|
-
if (key === "always" || key === "onDone" || key === "onError" || key === "onSnapshot") {
|
|
7791
|
+
if (key === "always" || key === "onDone" || key === "onError" || key === "onSnapshot" || key === "onTimeout") {
|
|
7739
7792
|
result[key] = mapV6MachineConfig(item, { transitionValue: true });
|
|
7740
7793
|
continue;
|
|
7741
7794
|
}
|
|
@@ -7753,16 +7806,18 @@ function toV6TransitionValue(value) {
|
|
|
7753
7806
|
if (Array.isArray(value)) return value.map((item) => toV6TransitionValue(item));
|
|
7754
7807
|
if (!value || typeof value !== "object") return value;
|
|
7755
7808
|
const transition = value;
|
|
7756
|
-
if (transition.guard || transition.description) return mapV6MachineConfig(transition);
|
|
7809
|
+
if (transition.guard || transition.description || transition.input !== void 0) return mapV6MachineConfig(transition);
|
|
7757
7810
|
const target = transition.target;
|
|
7811
|
+
const context = transition.context;
|
|
7758
7812
|
const actionsValue = transition.actions;
|
|
7759
7813
|
const actions = Array.isArray(actionsValue) ? actionsValue : actionsValue === void 0 ? [] : [actionsValue];
|
|
7760
|
-
if (actions.length === 0 && typeof target === "string" && !transition.reenter && !transition.meta) return target;
|
|
7761
|
-
if (actions.length === 0 && target === void 0) return mapV6MachineConfig(transition);
|
|
7814
|
+
if (actions.length === 0 && typeof target === "string" && context === void 0 && !transition.reenter && !transition.meta) return target;
|
|
7815
|
+
if (actions.length === 0 && target === void 0 && context === void 0) return mapV6MachineConfig(transition);
|
|
7762
7816
|
return buildV6ActionFunction(actions, {
|
|
7763
7817
|
target: typeof target === "string" ? target : void 0,
|
|
7764
7818
|
reenter: transition.reenter === true,
|
|
7765
|
-
meta: transition.meta
|
|
7819
|
+
meta: transition.meta,
|
|
7820
|
+
context
|
|
7766
7821
|
}) ?? mapV6MachineConfig(transition);
|
|
7767
7822
|
}
|
|
7768
7823
|
function toV6ActionField(actions) {
|
|
@@ -7782,10 +7837,19 @@ function buildV6ActionFunction(actions, transition) {
|
|
|
7782
7837
|
returnValue = effect?.returnValue ?? returnValue;
|
|
7783
7838
|
contextValue = effect?.contextValue ?? contextValue;
|
|
7784
7839
|
}
|
|
7785
|
-
if (transition) returnValue = buildV6TransitionReturnValue(transition, contextValue);
|
|
7840
|
+
if (transition) returnValue = buildV6TransitionReturnValue(transition, transition.context === void 0 ? contextValue : serializeJS(unwrapTemplateExpressions(transition.context)));
|
|
7786
7841
|
if (statements.length === 0 && !returnValue) return void 0;
|
|
7787
7842
|
return raw(`(_, enq) => {\n${[...statements.map((statement) => ` ${statement};`), ...returnValue ? [` return ${returnValue};`] : []].join("\n")}\n}`);
|
|
7788
7843
|
}
|
|
7844
|
+
function unwrapTemplateExpressions(value) {
|
|
7845
|
+
if (typeof value === "string") {
|
|
7846
|
+
const match = value.match(/^\{\{\s*([\s\S]*?)\s*\}\}$/);
|
|
7847
|
+
return match?.[1] ? raw(match[1]) : value;
|
|
7848
|
+
}
|
|
7849
|
+
if (Array.isArray(value)) return value.map(unwrapTemplateExpressions);
|
|
7850
|
+
if (!value || typeof value !== "object") return value;
|
|
7851
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, unwrapTemplateExpressions(item)]));
|
|
7852
|
+
}
|
|
7789
7853
|
function buildV6TransitionReturnValue(transition, contextValue) {
|
|
7790
7854
|
if (!transition.reenter && !transition.meta && !contextValue) return transition.target ? `{ target: ${serializeJS(transition.target)} }` : void 0;
|
|
7791
7855
|
return serializeJS({
|
|
@@ -7865,16 +7929,34 @@ function actionOptions(params, consumedKeys) {
|
|
|
7865
7929
|
const rest = Object.fromEntries(Object.entries(params).filter(([key, value]) => !consumedKeys.includes(key) && value !== void 0));
|
|
7866
7930
|
return Object.keys(rest).length ? `, ${serializeJS(rest)}` : "";
|
|
7867
7931
|
}
|
|
7868
|
-
function buildImports({ hasSetup, hasActors, actors, builtInActions, usesTypes }) {
|
|
7932
|
+
function buildImports({ hasSetup, hasActors, actors, builtInActions, actorSourceImports, usesTypes }) {
|
|
7869
7933
|
const xstateImports = [];
|
|
7870
7934
|
if (hasSetup) xstateImports.push("setup");
|
|
7871
7935
|
else xstateImports.push("createMachine");
|
|
7872
7936
|
for (const name of builtInActions) xstateImports.push(name);
|
|
7937
|
+
for (const name of actorSourceImports) xstateImports.push(name);
|
|
7873
7938
|
if (usesTypes) xstateImports.push("types");
|
|
7874
7939
|
if (hasActors) {
|
|
7875
7940
|
if (actors.length > 0) xstateImports.push("fromPromise");
|
|
7876
7941
|
}
|
|
7877
|
-
return `import { ${xstateImports.join(", ")} } from 'xstate';`;
|
|
7942
|
+
return `import { ${[...new Set(xstateImports)].join(", ")} } from 'xstate';`;
|
|
7943
|
+
}
|
|
7944
|
+
function getActorSourceImports(graph) {
|
|
7945
|
+
const imports = /* @__PURE__ */ new Set();
|
|
7946
|
+
const candidates = [
|
|
7947
|
+
"createAsyncLogic",
|
|
7948
|
+
"fromPromise",
|
|
7949
|
+
"fromCallback",
|
|
7950
|
+
"fromObservable",
|
|
7951
|
+
"fromEventObservable",
|
|
7952
|
+
"fromTransition"
|
|
7953
|
+
];
|
|
7954
|
+
for (const node of graph.nodes) for (const invoke of node.data.invokes ?? []) {
|
|
7955
|
+
const expression = invoke.srcExpression?.expr;
|
|
7956
|
+
if (!expression) continue;
|
|
7957
|
+
for (const candidate of candidates) if (new RegExp(`\\b${candidate}\\b`).test(expression)) imports.add(candidate);
|
|
7958
|
+
}
|
|
7959
|
+
return imports;
|
|
7878
7960
|
}
|
|
7879
7961
|
function buildSetupObject(schemas, impls, options) {
|
|
7880
7962
|
const setup = {};
|
|
@@ -8015,6 +8097,10 @@ function unwrapExpression(node) {
|
|
|
8015
8097
|
return node;
|
|
8016
8098
|
}
|
|
8017
8099
|
function propertyContext(parent, key) {
|
|
8100
|
+
if (parent.invokeValue && key === "src") return {
|
|
8101
|
+
v6: parent.v6,
|
|
8102
|
+
actorSourceValue: true
|
|
8103
|
+
};
|
|
8018
8104
|
if (parent.transitionMap) return {
|
|
8019
8105
|
v6: parent.v6,
|
|
8020
8106
|
transitionValue: true
|
|
@@ -8048,6 +8134,22 @@ function propertyContext(parent, key) {
|
|
|
8048
8134
|
v6: parent.v6,
|
|
8049
8135
|
ioValue: true
|
|
8050
8136
|
};
|
|
8137
|
+
if (parent.ioValue || parent.ioPropertyValue) return {
|
|
8138
|
+
v6: parent.v6,
|
|
8139
|
+
ioPropertyValue: true
|
|
8140
|
+
};
|
|
8141
|
+
if (key === "invoke") return {
|
|
8142
|
+
v6: parent.v6,
|
|
8143
|
+
invokeValue: true
|
|
8144
|
+
};
|
|
8145
|
+
if (key === "timeout") return {
|
|
8146
|
+
v6: parent.v6,
|
|
8147
|
+
timeoutValue: true
|
|
8148
|
+
};
|
|
8149
|
+
if (key === "route") return {
|
|
8150
|
+
v6: parent.v6,
|
|
8151
|
+
routeValue: true
|
|
8152
|
+
};
|
|
8051
8153
|
if (key === "on" || key === "after") return {
|
|
8052
8154
|
v6: parent.v6,
|
|
8053
8155
|
transitionMap: true
|
|
@@ -8447,13 +8549,41 @@ function objectLiteralToValue(node, bindings, context, depth, overrides = /* @__
|
|
|
8447
8549
|
function expressionToValue(expression, bindings, context = {}, depth = 0) {
|
|
8448
8550
|
if (depth > 30) return void 0;
|
|
8449
8551
|
const node = unwrapExpression(expression);
|
|
8552
|
+
if (context.actorSourceValue) {
|
|
8553
|
+
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) return node.text;
|
|
8554
|
+
if (ts.isIdentifier(node)) {
|
|
8555
|
+
const binding = bindings.get(node.text);
|
|
8556
|
+
if (binding && !ts.isFunctionDeclaration(binding)) return inlineCodeExpression(unwrapExpression(binding).getText());
|
|
8557
|
+
}
|
|
8558
|
+
return inlineCodeExpression(node.getText());
|
|
8559
|
+
}
|
|
8560
|
+
if (context.routeValue && !ts.isObjectLiteralExpression(node)) {
|
|
8561
|
+
if (ts.isIdentifier(node)) {
|
|
8562
|
+
const binding = bindings.get(node.text);
|
|
8563
|
+
if (binding && !ts.isFunctionDeclaration(binding)) return expressionToValue(binding, bindings, context, depth + 1);
|
|
8564
|
+
}
|
|
8565
|
+
return inlineCodeExpression(node.getText());
|
|
8566
|
+
}
|
|
8567
|
+
if (context.timeoutValue && (ts.isArrowFunction(node) || ts.isFunctionExpression(node) || ts.isCallExpression(node))) return inlineCodeExpression(node.getText());
|
|
8450
8568
|
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) return context.ioValue ? inlineCodeExpression(JSON.stringify(node.text)) : node.text;
|
|
8451
8569
|
if (ts.isNumericLiteral(node)) return context.ioValue ? inlineCodeExpression(node.text) : Number(node.text);
|
|
8452
8570
|
if (node.kind === ts.SyntaxKind.TrueKeyword) return context.ioValue ? inlineCodeExpression("true") : true;
|
|
8453
8571
|
if (node.kind === ts.SyntaxKind.FalseKeyword) return context.ioValue ? inlineCodeExpression("false") : false;
|
|
8454
8572
|
if (node.kind === ts.SyntaxKind.NullKeyword) return context.ioValue ? inlineCodeExpression("null") : null;
|
|
8573
|
+
if (context.ioPropertyValue) {
|
|
8574
|
+
if (ts.isIdentifier(node) && node.text === "undefined") return void 0;
|
|
8575
|
+
if (ts.isIdentifier(node)) {
|
|
8576
|
+
const binding = bindings.get(node.text);
|
|
8577
|
+
if (binding && !ts.isFunctionDeclaration(binding)) return expressionToValue(binding, bindings, context, depth + 1);
|
|
8578
|
+
}
|
|
8579
|
+
if (!ts.isObjectLiteralExpression(node) && !ts.isArrayLiteralExpression(node)) return inlineCodeExpression(node.getText());
|
|
8580
|
+
}
|
|
8455
8581
|
if (context.assignmentValue) {
|
|
8456
8582
|
if (ts.isIdentifier(node) && node.text === "undefined") return void 0;
|
|
8583
|
+
if (ts.isIdentifier(node)) {
|
|
8584
|
+
const binding = bindings.get(node.text);
|
|
8585
|
+
if (binding && !ts.isFunctionDeclaration(binding)) return expressionToValue(binding, bindings, context, depth + 1);
|
|
8586
|
+
}
|
|
8457
8587
|
return wrapAssignExpression(node.getText());
|
|
8458
8588
|
}
|
|
8459
8589
|
if (context.transitionContext && !ts.isObjectLiteralExpression(node)) return inlineCodeExpression(node.getText());
|
|
@@ -8462,7 +8592,16 @@ function expressionToValue(expression, bindings, context = {}, depth = 0) {
|
|
|
8462
8592
|
if (ts.isIdentifier(node)) {
|
|
8463
8593
|
if (node.text === "undefined") return void 0;
|
|
8464
8594
|
const binding = bindings.get(node.text);
|
|
8465
|
-
|
|
8595
|
+
if (binding) {
|
|
8596
|
+
if (ts.isFunctionDeclaration(binding)) {
|
|
8597
|
+
if (context.metaValue) return inlineCodeExpression(binding.name?.text ?? node.getText());
|
|
8598
|
+
if (context.v6 && context.transitionValue) return normalizeFunctionTransition(binding, bindings, depth + 1);
|
|
8599
|
+
if (context.v6 && context.actionValue) return normalizeFunctionAction(binding, bindings);
|
|
8600
|
+
return binding.name?.text ?? node.text;
|
|
8601
|
+
}
|
|
8602
|
+
return expressionToValue(binding, bindings, context, depth + 1);
|
|
8603
|
+
}
|
|
8604
|
+
return context.metaValue ? inlineCodeExpression(node.getText()) : node.text;
|
|
8466
8605
|
}
|
|
8467
8606
|
if (ts.isObjectLiteralExpression(node)) return objectLiteralToValue(node, bindings, context, depth);
|
|
8468
8607
|
if (ts.isArrayLiteralExpression(node)) {
|
|
@@ -8477,6 +8616,14 @@ function expressionToValue(expression, bindings, context = {}, depth = 0) {
|
|
|
8477
8616
|
}
|
|
8478
8617
|
if (ts.isCallExpression(node)) {
|
|
8479
8618
|
if (context.metaValue) return inlineCodeExpression(node.getText());
|
|
8619
|
+
if (ts.isIdentifier(node.expression)) {
|
|
8620
|
+
const binding = bindings.get(node.expression.text);
|
|
8621
|
+
if (binding && isFunctionBinding(binding)) return evaluateFunctionCall(binding, node.arguments, bindings, context, depth + 1);
|
|
8622
|
+
}
|
|
8623
|
+
if (ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "createStateConfig") {
|
|
8624
|
+
const configArg = node.arguments.length > 1 ? node.arguments[1] : node.arguments[0];
|
|
8625
|
+
return configArg ? expressionToValue(configArg, bindings, { v6: context.v6 }, depth + 1) : {};
|
|
8626
|
+
}
|
|
8480
8627
|
if (context.actionValue) return inlineAction(node);
|
|
8481
8628
|
const callee = node.expression.getText();
|
|
8482
8629
|
const type = callee.includes(".") ? callee.split(".").pop() : callee;
|
|
@@ -8484,11 +8631,30 @@ function expressionToValue(expression, bindings, context = {}, depth = 0) {
|
|
|
8484
8631
|
}
|
|
8485
8632
|
return context.metaValue ? inlineCodeExpression(node.getText()) : node.getText();
|
|
8486
8633
|
}
|
|
8634
|
+
function isFunctionBinding(binding) {
|
|
8635
|
+
return ts.isArrowFunction(binding) || ts.isFunctionExpression(binding) || ts.isFunctionDeclaration(binding);
|
|
8636
|
+
}
|
|
8637
|
+
function evaluateFunctionCall(fn, args, bindings, context, depth) {
|
|
8638
|
+
const scopedBindings = new Map(bindings);
|
|
8639
|
+
for (const [index, parameter] of fn.parameters.entries()) {
|
|
8640
|
+
if (!ts.isIdentifier(parameter.name)) continue;
|
|
8641
|
+
const argument = args[index];
|
|
8642
|
+
if (argument) scopedBindings.set(parameter.name.text, argument);
|
|
8643
|
+
else if (parameter.initializer) scopedBindings.set(parameter.name.text, parameter.initializer);
|
|
8644
|
+
}
|
|
8645
|
+
if (ts.isArrowFunction(fn) && !ts.isBlock(fn.body)) return expressionToValue(fn.body, scopedBindings, context, depth + 1);
|
|
8646
|
+
if (context.v6 && context.transitionValue) return normalizeFunctionTransition(fn, scopedBindings, depth + 1);
|
|
8647
|
+
if (context.v6 && context.actionValue) return normalizeFunctionAction(fn, scopedBindings);
|
|
8648
|
+
return context.metaValue ? inlineCodeExpression(fn.getText()) : fn.name?.getText() ?? fn.getText();
|
|
8649
|
+
}
|
|
8487
8650
|
function collectBindings(file) {
|
|
8488
8651
|
const bindings = /* @__PURE__ */ new Map();
|
|
8489
8652
|
for (const statement of file.statements) {
|
|
8490
|
-
if (
|
|
8491
|
-
|
|
8653
|
+
if (ts.isVariableStatement(statement)) {
|
|
8654
|
+
for (const declaration of statement.declarationList.declarations) if (ts.isIdentifier(declaration.name) && declaration.initializer) bindings.set(declaration.name.text, declaration.initializer);
|
|
8655
|
+
continue;
|
|
8656
|
+
}
|
|
8657
|
+
if (ts.isFunctionDeclaration(statement) && statement.name) bindings.set(statement.name.text, statement);
|
|
8492
8658
|
}
|
|
8493
8659
|
return bindings;
|
|
8494
8660
|
}
|
|
@@ -8500,16 +8666,37 @@ function isCreateMachineCall(node) {
|
|
|
8500
8666
|
}
|
|
8501
8667
|
function hasV6Syntax(source) {
|
|
8502
8668
|
const file = sourceFile(source);
|
|
8669
|
+
const bindings = collectBindings(file);
|
|
8503
8670
|
let found = false;
|
|
8671
|
+
function containsFunction(expression, seenBindings = /* @__PURE__ */ new Set()) {
|
|
8672
|
+
if (ts.isFunctionDeclaration(expression)) return true;
|
|
8673
|
+
const node = unwrapExpression(expression);
|
|
8674
|
+
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) return true;
|
|
8675
|
+
if (ts.isIdentifier(node)) {
|
|
8676
|
+
if (seenBindings.has(node.text)) return false;
|
|
8677
|
+
const binding = bindings.get(node.text);
|
|
8678
|
+
if (!binding) return false;
|
|
8679
|
+
return containsFunction(binding, new Set([...seenBindings, node.text]));
|
|
8680
|
+
}
|
|
8681
|
+
if (ts.isObjectLiteralExpression(node)) return node.properties.some((property) => {
|
|
8682
|
+
if (ts.isPropertyAssignment(property)) return containsFunction(property.initializer, seenBindings);
|
|
8683
|
+
if (ts.isShorthandPropertyAssignment(property)) return containsFunction(property.name, seenBindings);
|
|
8684
|
+
if (ts.isSpreadAssignment(property)) return containsFunction(property.expression, seenBindings);
|
|
8685
|
+
return false;
|
|
8686
|
+
});
|
|
8687
|
+
if (ts.isArrayLiteralExpression(node)) return node.elements.some((element) => ts.isExpression(element) && containsFunction(element, seenBindings));
|
|
8688
|
+
if (ts.isCallExpression(node)) return ts.isIdentifier(node.expression) && containsFunction(node.expression, seenBindings) || node.arguments.some((argument) => ts.isExpression(argument) && containsFunction(argument, seenBindings));
|
|
8689
|
+
return false;
|
|
8690
|
+
}
|
|
8504
8691
|
function visit(node) {
|
|
8505
8692
|
if (found) return;
|
|
8506
8693
|
if (ts.isPropertyAssignment(node) && (ts.isIdentifier(node.name) || ts.isStringLiteral(node.name))) {
|
|
8507
8694
|
const key = node.name.text;
|
|
8508
|
-
if (key === "triggers" || key === "internalEvents" || key === "timeout" || key === "onTimeout" || key === "choice" || key === "route") {
|
|
8695
|
+
if (key === "triggers" || key === "internalEvents" || key === "matches" || key === "actorSources" || key === "timeout" || key === "onTimeout" || key === "choice" || key === "route") {
|
|
8509
8696
|
found = true;
|
|
8510
8697
|
return;
|
|
8511
8698
|
}
|
|
8512
|
-
if ((key === "on" || key === "after" || key === "always" || key === "choice" || key === "onDone" || key === "onError" || key === "onSnapshot" || key === "onTimeout" || key === "entry" || key === "exit" || key === "actions" && !ts.isObjectLiteralExpression(node.initializer)) && node.initializer
|
|
8699
|
+
if ((key === "on" || key === "after" || key === "always" || key === "choice" || key === "onDone" || key === "onError" || key === "onSnapshot" || key === "onTimeout" || key === "entry" || key === "exit" || key === "actions" && !ts.isObjectLiteralExpression(node.initializer)) && containsFunction(node.initializer)) {
|
|
8513
8700
|
found = true;
|
|
8514
8701
|
return;
|
|
8515
8702
|
}
|
|
@@ -8605,6 +8792,7 @@ const createTransitionPatchSchema$1 = object({
|
|
|
8605
8792
|
sourceId: string(),
|
|
8606
8793
|
targetId: string(),
|
|
8607
8794
|
eventType: string(),
|
|
8795
|
+
matches: record(string(), unknown()).optional(),
|
|
8608
8796
|
transitionType: _enum([
|
|
8609
8797
|
"normal",
|
|
8610
8798
|
"targetless",
|
|
@@ -8621,6 +8809,7 @@ const updateTransitionPatchSchema$1 = object({
|
|
|
8621
8809
|
sourceId: string().optional(),
|
|
8622
8810
|
targetId: string().optional(),
|
|
8623
8811
|
eventType: string().optional(),
|
|
8812
|
+
matches: record(string(), unknown()).optional(),
|
|
8624
8813
|
transitionType: _enum([
|
|
8625
8814
|
"normal",
|
|
8626
8815
|
"targetless",
|
|
@@ -8781,11 +8970,7 @@ const machineFormatSchema = _enum([
|
|
|
8781
8970
|
"scxml",
|
|
8782
8971
|
"mermaid"
|
|
8783
8972
|
]);
|
|
8784
|
-
const xstateSourceProfileSchema = _enum([
|
|
8785
|
-
"auto",
|
|
8786
|
-
"xstate-v5",
|
|
8787
|
-
"xstate-v6-alpha"
|
|
8788
|
-
]);
|
|
8973
|
+
const xstateSourceProfileSchema = _enum(["auto", ...MACHINE_PROFILES]);
|
|
8789
8974
|
const machineInputSchema = object({
|
|
8790
8975
|
machine: union([record(string(), unknown()), string()]),
|
|
8791
8976
|
format: machineFormatSchema.optional(),
|
|
@@ -8871,7 +9056,10 @@ const updateNodePatchSchema = object({
|
|
|
8871
9056
|
key: string().optional(),
|
|
8872
9057
|
type: editorStateTypeSchema.optional(),
|
|
8873
9058
|
description: string().optional(),
|
|
8874
|
-
initialId: string().nullable().optional()
|
|
9059
|
+
initialId: string().nullable().optional(),
|
|
9060
|
+
initialInput: unknown().optional(),
|
|
9061
|
+
timeout: unknown().optional(),
|
|
9062
|
+
route: unknown().optional()
|
|
8875
9063
|
})
|
|
8876
9064
|
});
|
|
8877
9065
|
const deleteNodePatchSchema = object({
|
|
@@ -8886,6 +9074,7 @@ const createEdgePatchSchema = object({
|
|
|
8886
9074
|
sourceId: string(),
|
|
8887
9075
|
targetId: string(),
|
|
8888
9076
|
eventType: string(),
|
|
9077
|
+
matches: record(string(), unknown()).optional(),
|
|
8889
9078
|
transitionType: _enum([
|
|
8890
9079
|
"normal",
|
|
8891
9080
|
"targetless",
|
|
@@ -8900,12 +9089,14 @@ const updateEdgePatchSchema = object({
|
|
|
8900
9089
|
sourceId: string().optional(),
|
|
8901
9090
|
targetId: string().optional(),
|
|
8902
9091
|
eventType: string().optional(),
|
|
9092
|
+
matches: record(string(), unknown()).optional(),
|
|
8903
9093
|
transitionType: _enum([
|
|
8904
9094
|
"normal",
|
|
8905
9095
|
"targetless",
|
|
8906
9096
|
"reenter"
|
|
8907
9097
|
]).optional(),
|
|
8908
|
-
description: string().nullable().optional()
|
|
9098
|
+
description: string().nullable().optional(),
|
|
9099
|
+
input: unknown().optional()
|
|
8909
9100
|
})
|
|
8910
9101
|
});
|
|
8911
9102
|
const deleteEdgePatchSchema = object({
|
|
@@ -8933,6 +9124,9 @@ const updateStatePatchSchema = object({
|
|
|
8933
9124
|
type: editorStateTypeSchema.optional(),
|
|
8934
9125
|
stateDescription: string().optional(),
|
|
8935
9126
|
initialId: string().nullable().optional(),
|
|
9127
|
+
initialInput: unknown().optional(),
|
|
9128
|
+
timeout: unknown().optional(),
|
|
9129
|
+
route: unknown().optional(),
|
|
8936
9130
|
color: canvasColorSchema.nullable().optional(),
|
|
8937
9131
|
meta: record(string(), unknown()).nullable().optional(),
|
|
8938
9132
|
history: _enum(["shallow", "deep"]).nullable().optional()
|
|
@@ -8949,6 +9143,7 @@ const createTransitionPatchSchema = object({
|
|
|
8949
9143
|
sourceId: string(),
|
|
8950
9144
|
targetId: string(),
|
|
8951
9145
|
eventType: string(),
|
|
9146
|
+
matches: record(string(), unknown()).optional(),
|
|
8952
9147
|
transitionType: _enum([
|
|
8953
9148
|
"normal",
|
|
8954
9149
|
"targetless",
|
|
@@ -8960,7 +9155,8 @@ const createTransitionPatchSchema = object({
|
|
|
8960
9155
|
params: record(string(), unknown()).optional()
|
|
8961
9156
|
}).optional(),
|
|
8962
9157
|
color: canvasColorSchema.nullable().optional(),
|
|
8963
|
-
transitionDescription: string().nullable().optional()
|
|
9158
|
+
transitionDescription: string().nullable().optional(),
|
|
9159
|
+
input: unknown().optional()
|
|
8964
9160
|
});
|
|
8965
9161
|
const updateTransitionPatchSchema = object({
|
|
8966
9162
|
op: literal("updateTransition"),
|
|
@@ -8969,12 +9165,14 @@ const updateTransitionPatchSchema = object({
|
|
|
8969
9165
|
sourceId: string().optional(),
|
|
8970
9166
|
targetId: string().optional(),
|
|
8971
9167
|
eventType: string().optional(),
|
|
9168
|
+
matches: record(string(), unknown()).optional(),
|
|
8972
9169
|
transitionType: _enum([
|
|
8973
9170
|
"normal",
|
|
8974
9171
|
"targetless",
|
|
8975
9172
|
"reenter"
|
|
8976
9173
|
]).optional(),
|
|
8977
9174
|
transitionDescription: string().nullable().optional(),
|
|
9175
|
+
input: unknown().optional(),
|
|
8978
9176
|
color: canvasColorSchema.nullable().optional(),
|
|
8979
9177
|
meta: record(string(), unknown()).nullable().optional()
|
|
8980
9178
|
});
|
|
@@ -9018,9 +9216,12 @@ const createInvokePatchSchema = object({
|
|
|
9018
9216
|
id: string().optional(),
|
|
9019
9217
|
invocationId: string().optional(),
|
|
9020
9218
|
src: string(),
|
|
9219
|
+
srcExpression: unknown().optional(),
|
|
9021
9220
|
code: string().optional(),
|
|
9022
|
-
|
|
9023
|
-
|
|
9221
|
+
registryKey: string().optional(),
|
|
9222
|
+
timeout: unknown().optional(),
|
|
9223
|
+
input: unknown().optional(),
|
|
9224
|
+
output: unknown().optional()
|
|
9024
9225
|
})
|
|
9025
9226
|
});
|
|
9026
9227
|
const updateInvokePatchSchema = object({
|
|
@@ -9031,9 +9232,12 @@ const updateInvokePatchSchema = object({
|
|
|
9031
9232
|
data: object({
|
|
9032
9233
|
invocationId: string().optional(),
|
|
9033
9234
|
src: string().optional(),
|
|
9235
|
+
srcExpression: unknown().optional(),
|
|
9034
9236
|
code: string().optional(),
|
|
9035
|
-
|
|
9036
|
-
|
|
9237
|
+
registryKey: string().optional(),
|
|
9238
|
+
timeout: unknown().optional(),
|
|
9239
|
+
input: unknown().optional(),
|
|
9240
|
+
output: unknown().optional()
|
|
9037
9241
|
})
|
|
9038
9242
|
});
|
|
9039
9243
|
const deleteInvokePatchSchema = object({
|