statelyai 0.12.5 → 0.12.7

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/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { C as run } from "./cli-uQku_cqo.mjs";
2
+ import { C as run } from "./cli-BRxosLYY.mjs";
3
3
 
4
4
  //#region src/bin.ts
5
5
  run();
@@ -6918,7 +6918,7 @@ var RawCode = class {
6918
6918
  function raw(code, sourceValue, sourceSlice, preserveWhitespace = false) {
6919
6919
  return new RawCode(code, sourceValue, sourceSlice, preserveWhitespace);
6920
6920
  }
6921
- const SERIALIZED_SOURCE_ID = "__stately_source_id__";
6921
+ const SERIALIZED_SOURCE_ID = Symbol("stately.sourceId");
6922
6922
  function serializeJS(value, indent = 0, step = 2) {
6923
6923
  if (value instanceof RawCode) return markSourceValue(value.sourceValue, value.code, value.sourceSlice);
6924
6924
  if (isCodeExpression(value)) return markSourceValue(value, value.expr);
@@ -6943,24 +6943,24 @@ function escapeString(s) {
6943
6943
  }
6944
6944
  function serializeArray(arr, indent, step) {
6945
6945
  const filtered = arr.filter((v) => v !== void 0);
6946
- if (filtered.length === 0) return "[]";
6946
+ if (filtered.length === 0) return markSourceValue(arr, "[]");
6947
6947
  const inner = indent + step;
6948
6948
  const pad = " ".repeat(inner);
6949
6949
  const closePad = " ".repeat(indent);
6950
- return `[\n${filtered.map((v) => `${pad}${serializeJS(v, inner, step)}`).join(",\n")},\n${closePad}]`;
6950
+ return markSourceValue(arr, `[\n${filtered.map((v) => `${pad}${serializeJS(v, inner, step)}`).join(",\n")},\n${closePad}]`);
6951
6951
  }
6952
6952
  function serializeObject(obj, indent, step) {
6953
6953
  const entries = Object.entries(obj).filter(([, v]) => v !== void 0);
6954
- if (entries.length === 0) return "{}";
6954
+ if (entries.length === 0) return markSourceValue(obj, "{}");
6955
6955
  const inner = indent + step;
6956
6956
  const pad = " ".repeat(inner);
6957
6957
  const closePad = " ".repeat(indent);
6958
- return `{\n${entries.map(([key, val]) => {
6958
+ return markSourceValue(obj, `{\n${entries.map(([key, val]) => {
6959
6959
  const k = VALID_IDENT.test(key) ? key : `'${escapeString(key)}'`;
6960
6960
  const serialized = serializeJS(val, inner, step);
6961
6961
  if (isRawExpression(val) && serialized.includes("\n")) return `${pad}${k}: ${preservesAuthoredWhitespace(val) ? serialized : indentRawCode(serialized, inner)}`;
6962
6962
  return `${pad}${k}: ${serialized}`;
6963
- }).join(",\n")},\n${closePad}}`;
6963
+ }).join(",\n")},\n${closePad}}`);
6964
6964
  }
6965
6965
  function preservesAuthoredWhitespace(value) {
6966
6966
  if (isCodeExpression(value)) return true;
@@ -7000,6 +7000,93 @@ function stripExportDefault(code) {
7000
7000
  if (trimmed.startsWith("export default ")) return trimmed.slice(15).replace(/;$/, "");
7001
7001
  return trimmed;
7002
7002
  }
7003
+ const FN_PROJECTION_META = "@statelyai.xstate.v6.fnProjection";
7004
+ /** Only literal returned objects are projected; nested functions are unrelated. */
7005
+ function returnedTransitionObjects(source) {
7006
+ const file = ts.createSourceFile("transition.ts", `const fn = ${source};`, ts.ScriptTarget.Latest, true);
7007
+ const objects = [];
7008
+ const value = (node) => {
7009
+ if (ts.isParenthesizedExpression(node)) value(node.expression);
7010
+ else if (ts.isConditionalExpression(node)) {
7011
+ value(node.whenTrue);
7012
+ value(node.whenFalse);
7013
+ } else if (ts.isObjectLiteralExpression(node)) objects.push(node);
7014
+ };
7015
+ const fn = (file.statements[0]?.declarationList?.declarations[0])?.initializer;
7016
+ if (!fn || !ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn)) return [];
7017
+ if (!ts.isBlock(fn.body)) value(fn.body);
7018
+ else {
7019
+ const visit = (node) => {
7020
+ if (node !== fn.body && ts.isFunctionLike(node)) return;
7021
+ if (ts.isReturnStatement(node) && node.expression) value(node.expression);
7022
+ else ts.forEachChild(node, visit);
7023
+ };
7024
+ visit(fn.body);
7025
+ }
7026
+ return objects;
7027
+ }
7028
+ function fieldText(key, value) {
7029
+ if (key === "guard" && value && typeof value === "object" && "code" in value) return String(value.code);
7030
+ if (isCodeExpression(value)) return value.expr;
7031
+ return serializeJS(value);
7032
+ }
7033
+ /** Keep the authored control flow and prelude; patch only returned value fields. */
7034
+ function projectedFunctionSource(value, options = {}) {
7035
+ const transitions = Array.isArray(value) ? value : [value];
7036
+ const projections = transitions.map((transition) => transition && typeof transition === "object" ? transition.meta : void 0).map((meta) => meta?.[FN_PROJECTION_META]);
7037
+ if (!projections.some(Boolean)) return void 0;
7038
+ const first = projections[0];
7039
+ const fail = () => {
7040
+ throw new Error("This transition preserves local declarations. Edit its control flow in source.");
7041
+ };
7042
+ if (!first || first.count !== transitions.length) return fail();
7043
+ if (projections.some((projection, index) => !projection || projection.source !== first.source || projection.index !== index || projection.count !== first.count)) return fail();
7044
+ const objects = returnedTransitionObjects(first.source);
7045
+ if (objects.length !== transitions.length) return fail();
7046
+ const replacements = [];
7047
+ const prefixLength = 11;
7048
+ transitions.forEach((transition, index) => {
7049
+ const baseline = projections[index].baseline;
7050
+ const object = objects[index];
7051
+ const replacementStart = replacements.length;
7052
+ const filtered = (key) => key === "meta" && options.showMeta === false || key === "description" && options.showDescriptions === false;
7053
+ const keys = new Set([...Object.keys(baseline), ...Object.keys(transition)]);
7054
+ for (const key of keys) {
7055
+ if (key === "meta" || filtered(key)) continue;
7056
+ if (fieldText(key, transition[key]) === fieldText(key, baseline[key])) continue;
7057
+ if (![
7058
+ "target",
7059
+ "context",
7060
+ "input"
7061
+ ].includes(key) || transition[key] === void 0) return fail();
7062
+ const property = object.properties.find((property) => ts.isPropertyAssignment(property) && (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)) && (property.name.text === key || key === "target" && property.name.text === "to"));
7063
+ if (!property) return fail();
7064
+ replacements.push({
7065
+ start: property.initializer.getStart() - prefixLength,
7066
+ end: property.initializer.getEnd() - prefixLength,
7067
+ text: serializeJS(transition[key])
7068
+ });
7069
+ }
7070
+ const publicMeta = (meta) => Object.fromEntries(Object.entries(meta ?? {}).filter(([key]) => !key.startsWith("@statelyai.")));
7071
+ if (options.showMeta !== false && serializeJS(publicMeta(transition.meta)) !== serializeJS(publicMeta(baseline.meta))) return fail();
7072
+ if (object.properties.some((property) => property.name && (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)) && filtered(property.name.text))) {
7073
+ const start = object.getStart() - prefixLength;
7074
+ const end = object.getEnd() - prefixLength;
7075
+ let objectSource = first.source.slice(start, end);
7076
+ for (const replacement of replacements.splice(replacementStart).sort((a, b) => b.start - a.start)) objectSource = objectSource.slice(0, replacement.start - start) + replacement.text + objectSource.slice(replacement.end - start);
7077
+ const patched = returnedTransitionObjects(`() => (${objectSource})`)[0];
7078
+ const updated = ts.factory.updateObjectLiteralExpression(patched, patched.properties.filter((property) => !property.name || !(ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)) || !filtered(property.name.text)));
7079
+ replacements.push({
7080
+ start,
7081
+ end,
7082
+ text: ts.createPrinter().printNode(ts.EmitHint.Expression, updated, patched.getSourceFile())
7083
+ });
7084
+ }
7085
+ });
7086
+ let source = first.source;
7087
+ for (const replacement of replacements.sort((a, b) => b.start - a.start)) source = source.slice(0, replacement.start) + replacement.text + source.slice(replacement.end);
7088
+ return source;
7089
+ }
7003
7090
  /**
7004
7091
  * Graph-native transition references. Transitions point at invoke/action/state
7005
7092
  * blocks by graph id (`@statelyai.*`); the literal `xstate.*` event is produced
@@ -7148,7 +7235,7 @@ function buildMeta(meta, color, showStatelyMeta = true) {
7148
7235
  if (isCodeExpression(meta)) return meta;
7149
7236
  const result = {};
7150
7237
  if (meta) {
7151
- for (const [k, v] of Object.entries(meta)) if (v !== void 0 && v !== null && (showStatelyMeta || !k.startsWith("@statelyai"))) result[k] = v;
7238
+ for (const [k, v] of Object.entries(meta)) if (v !== void 0 && v !== null && (showStatelyMeta || k === FN_PROJECTION_META || !k.startsWith("@statelyai"))) result[k] = v;
7152
7239
  }
7153
7240
  if (color && showStatelyMeta) result["@statelyai.color"] = color;
7154
7241
  return Object.keys(result).length > 0 ? result : void 0;
@@ -7165,7 +7252,7 @@ function formatStringParam(value) {
7165
7252
  return isCodeExpression(value) ? serializeJS(value) : "undefined";
7166
7253
  }
7167
7254
  function formatInlineObject(value) {
7168
- return `{ ${Object.entries(value).filter(([, item]) => item !== void 0).map(([key, item]) => `${formatObjectKey(key)}: ${serializeJS(item)}`).join(", ")} }`;
7255
+ return serializeJS(raw(`{ ${Object.entries(value).filter(([, item]) => item !== void 0).map(([key, item]) => `${formatObjectKey(key)}: ${serializeJS(item)}`).join(", ")} }`, value));
7169
7256
  }
7170
7257
  function formatObjectKey(key) {
7171
7258
  return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
@@ -7391,8 +7478,8 @@ function inlineCodeExpression$1(expr, sourceValue) {
7391
7478
  lang: "ts",
7392
7479
  expr: stripExportDefault(expr)
7393
7480
  };
7394
- const sourceId = sourceValue?.__stately_source_id__;
7395
- if (sourceId !== void 0) Object.defineProperty(result, "__stately_source_id__", {
7481
+ const sourceId = sourceValue?.[SERIALIZED_SOURCE_ID];
7482
+ if (sourceId !== void 0) Object.defineProperty(result, SERIALIZED_SOURCE_ID, {
7396
7483
  value: sourceId,
7397
7484
  enumerable: true
7398
7485
  });
@@ -7528,7 +7615,7 @@ function graphToMachineConfig(graph, options = {}) {
7528
7615
  ...size ? { size } : {}
7529
7616
  })) } : {},
7530
7617
  ...edge.data.appearance ? { "@statelyai.appearance": edge.data.appearance } : {}
7531
- }, edge.data.color, showStatelyMeta) : void 0;
7618
+ }, edge.data.color, showStatelyMeta) : edge.data.meta?.[FN_PROJECTION_META] ? { [FN_PROJECTION_META]: edge.data.meta[FN_PROJECTION_META] } : void 0;
7532
7619
  const transitionObject = {
7533
7620
  ...edge.data.matches ? { matches: edge.data.matches } : void 0,
7534
7621
  target: edge.data.transitionType === "targetless" ? void 0 : resolvedTargets.length > 1 ? resolvedTargets : `${resolvedTarget}`,
@@ -8300,7 +8387,45 @@ function typesCallSchema(node, bindings) {
8300
8387
  if (!ts.isCallExpression(value) || value.expression.getText() !== "types" || value.typeArguments?.length !== 1) return null;
8301
8388
  return typeNodeToJsonSchema(value.typeArguments[0], bindings);
8302
8389
  }
8303
- function schemasObjectToValue(node, bindings) {
8390
+ /** Recover only structural Zod calls whose types can be represented exactly. */
8391
+ function schemaExpressionToValue(node, bindings, imports, requireObject = false) {
8392
+ const typed = typesCallSchema(node, bindings);
8393
+ if (typed) return typed;
8394
+ const value = unwrapExpression$3(node);
8395
+ if (!ts.isCallExpression(value) || !ts.isPropertyAccessExpression(value.expression)) return null;
8396
+ const { expression: receiver, name } = value.expression;
8397
+ if (!ts.isIdentifier(receiver)) return null;
8398
+ const imported = imports?.get(receiver.text);
8399
+ if (imported?.package !== "zod" || imported.import !== "z") return null;
8400
+ for (let scope = receiver.parent; scope; scope = scope.parent) if (scopeBindsName(scope, receiver.text)) return null;
8401
+ const primitive = {
8402
+ string: "string",
8403
+ number: "number",
8404
+ boolean: "boolean"
8405
+ };
8406
+ if (Object.hasOwn(primitive, name.text) && value.arguments.length === 0) {
8407
+ if (requireObject) return null;
8408
+ return { type: primitive[name.text] };
8409
+ }
8410
+ if (name.text !== "object" || value.arguments.length !== 1) return null;
8411
+ const shape = unwrapExpression$3(value.arguments[0]);
8412
+ if (!ts.isObjectLiteralExpression(shape)) return null;
8413
+ const properties = {};
8414
+ for (const property of shape.properties) {
8415
+ if (!ts.isPropertyAssignment(property)) return null;
8416
+ const key = propName(property.name);
8417
+ const schema = schemaExpressionToValue(property.initializer, bindings, imports);
8418
+ if (key === null || !schema) return null;
8419
+ properties[key] = schema;
8420
+ }
8421
+ return {
8422
+ type: "object",
8423
+ properties,
8424
+ required: Object.keys(properties),
8425
+ "x-zod-unknownKeys": "strip"
8426
+ };
8427
+ }
8428
+ function schemasObjectToValue(node, bindings, imports) {
8304
8429
  const value = unwrapExpression$3(node);
8305
8430
  if (!ts.isObjectLiteralExpression(value)) return null;
8306
8431
  const result = {};
@@ -8318,7 +8443,7 @@ function schemasObjectToValue(node, bindings) {
8318
8443
  for (const eventProperty of property.initializer.properties) {
8319
8444
  if (!ts.isPropertyAssignment(eventProperty)) continue;
8320
8445
  const eventType = propName(eventProperty.name);
8321
- const schema = typesCallSchema(eventProperty.initializer, bindings);
8446
+ const schema = schemaExpressionToValue(eventProperty.initializer, bindings, imports, key !== "children");
8322
8447
  if (eventType && schema) events[eventType] = schema;
8323
8448
  }
8324
8449
  result[key] = events;
@@ -8331,13 +8456,13 @@ function schemasObjectToValue(node, bindings) {
8331
8456
  const name = propName(implementation.name);
8332
8457
  if (!name || !ts.isObjectLiteralExpression(implementation.initializer)) continue;
8333
8458
  const params = implementation.initializer.properties.find((candidate) => ts.isPropertyAssignment(candidate) && propName(candidate.name) === "params");
8334
- const schema = params ? typesCallSchema(params.initializer, bindings) : null;
8459
+ const schema = params ? schemaExpressionToValue(params.initializer, bindings, imports) : null;
8335
8460
  implementations[name] = schema ? { params: schema } : {};
8336
8461
  }
8337
8462
  result[key] = implementations;
8338
8463
  continue;
8339
8464
  }
8340
- const schema = typesCallSchema(property.initializer, bindings);
8465
+ const schema = schemaExpressionToValue(property.initializer, bindings, imports);
8341
8466
  if (!schema) continue;
8342
8467
  result[key] = key === "context" ? schema.properties ?? {} : schema;
8343
8468
  }
@@ -8348,6 +8473,11 @@ function propertyContext(parent, key) {
8348
8473
  ...parent.imports ? { imports: parent.imports } : {},
8349
8474
  ...parent.typeBindings ? { typeBindings: parent.typeBindings } : {}
8350
8475
  };
8476
+ if (parent.assignmentValue) return {
8477
+ ...inherited,
8478
+ v6: parent.v6,
8479
+ assignmentValue: true
8480
+ };
8351
8481
  if (parent.statesMap) return {
8352
8482
  ...inherited,
8353
8483
  v6: parent.v6
@@ -8540,7 +8670,11 @@ function namedGuardFromCondition(text) {
8540
8670
  const call = unwrapExpression$3(statement.expression);
8541
8671
  if (!ts.isCallExpression(call)) return void 0;
8542
8672
  const name = namedReferenceName(call.expression, "guards");
8543
- if (!name) return void 0;
8673
+ if (!name || call.arguments.length < 1 || call.arguments.length > 2) return void 0;
8674
+ const args = unwrapExpression$3(call.arguments[0]);
8675
+ if (!ts.isObjectLiteralExpression(args) || args.properties.length !== 2) return void 0;
8676
+ const keys = args.properties.map((property) => ts.isShorthandPropertyAssignment(property) && !property.objectAssignmentInitializer ? property.name.text : void 0);
8677
+ if (!keys.includes("context") || !keys.includes("event")) return void 0;
8544
8678
  return {
8545
8679
  type: name,
8546
8680
  params: namedReferenceParams(call.arguments[1], /* @__PURE__ */ new Map())
@@ -8904,7 +9038,7 @@ function omitIdentityTransitionContext(transition, identity) {
8904
9038
  return rest;
8905
9039
  }
8906
9040
  function normalizeFunctionTransition(fn, bindings, depth) {
8907
- if (fn.body && ts.isBlock(fn.body) && hasUnsafeVariableInitializer(fn.body)) return fallbackFunctionTransition(fn);
9041
+ const preserveLocals = Boolean(fn.body && ts.isBlock(fn.body) && hasUnsafeVariableInitializer(fn.body));
8908
9042
  const branches = ts.isArrowFunction(fn) && !ts.isBlock(fn.body) ? expressionBranches(fn.body, bindings, depth + 1) : fn.body && ts.isBlock(fn.body) ? statementBranches(fn.body.statements, bindings, enqueueParamName(fn)) : [];
8909
9043
  if (branches.some((branch) => branch.unknown || isCodeExpression(branch.result))) return fallbackFunctionTransition(fn);
8910
9044
  const contextIdentity = transitionContextIdentity(fn);
@@ -8942,6 +9076,23 @@ function normalizeFunctionTransition(fn, bindings, depth) {
8942
9076
  guard
8943
9077
  } : transition, contextIdentity);
8944
9078
  }).filter((transition) => Boolean(transition));
9079
+ if (preserveLocals) {
9080
+ const objects = returnedTransitionObjects(fn.getText());
9081
+ if (objects.length !== transitions.length || transitions.length === 0 || objects.some((object) => object.properties.some(ts.isSpreadAssignment)) || transitions.some((transition) => typeof transition === "string" || !(typeof transition.target === "string" || Array.isArray(transition.target) && transition.target.every((target) => typeof target === "string")))) return fallbackFunctionTransition(fn);
9082
+ for (let index = 0; index < transitions.length; index++) {
9083
+ const transition = transitions[index];
9084
+ const baseline = { ...transition };
9085
+ transition.meta = {
9086
+ ...transition.meta,
9087
+ [FN_PROJECTION_META]: {
9088
+ source: fn.getText(),
9089
+ index,
9090
+ count: transitions.length,
9091
+ baseline
9092
+ }
9093
+ };
9094
+ }
9095
+ }
8945
9096
  if (transitions.length === 1) return transitions[0];
8946
9097
  if (transitions.length > 1) return transitions;
8947
9098
  return fallbackFunctionTransition(fn);
@@ -9183,8 +9334,8 @@ function objectLiteralToValue(node, bindings, context, depth, overrides = /* @__
9183
9334
  result[key] = overrides.get(key);
9184
9335
  continue;
9185
9336
  }
9186
- if (context.v6 && key === "schemas" && ts.isPropertyAssignment(property)) {
9187
- const schemas = schemasObjectToValue(property.initializer, context.typeBindings ?? /* @__PURE__ */ new Map());
9337
+ if (context.v6 && !context.assignmentValue && key === "schemas" && ts.isPropertyAssignment(property)) {
9338
+ const schemas = schemasObjectToValue(property.initializer, context.typeBindings ?? /* @__PURE__ */ new Map(), context.imports);
9188
9339
  if (schemas) {
9189
9340
  result[key] = schemas;
9190
9341
  continue;
@@ -9242,7 +9393,7 @@ function expressionToValue(expression, bindings, context = {}, depth = 0) {
9242
9393
  const binding = bindings.get(node.text);
9243
9394
  if (binding && !ts.isFunctionDeclaration(binding)) return expressionToValue(binding, bindings, context, depth + 1);
9244
9395
  }
9245
- const schemas = schemasObjectToValue(node, context.typeBindings ?? /* @__PURE__ */ new Map());
9396
+ const schemas = schemasObjectToValue(node, context.typeBindings ?? /* @__PURE__ */ new Map(), context.imports);
9246
9397
  if (schemas) return schemas;
9247
9398
  }
9248
9399
  if (context.machineContextValue && (ts.isArrowFunction(node) || ts.isFunctionExpression(node))) return inlineCodeExpression(node.getText());
@@ -9271,7 +9422,10 @@ function expressionToValue(expression, bindings, context = {}, depth = 0) {
9271
9422
  return inlineCodeExpression(node.getText());
9272
9423
  }
9273
9424
  if (context.timeoutValue && (ts.isArrowFunction(node) || ts.isFunctionExpression(node) || ts.isCallExpression(node))) return inlineCodeExpression(node.getText());
9274
- if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) return node.text;
9425
+ if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
9426
+ if (context.assignmentValue && /^\{\{[\s\S]*\}\}$/.test(node.text)) return inlineCodeExpression(node.getText());
9427
+ return node.text;
9428
+ }
9275
9429
  if (ts.isNumericLiteral(node)) return Number(node.text);
9276
9430
  if (node.kind === ts.SyntaxKind.TrueKeyword) return true;
9277
9431
  if (node.kind === ts.SyntaxKind.FalseKeyword) return false;
@@ -9294,7 +9448,10 @@ function expressionToValue(expression, bindings, context = {}, depth = 0) {
9294
9448
  const binding = bindings.get(node.text);
9295
9449
  if (binding && !ts.isFunctionDeclaration(binding)) return expressionToValue(binding, bindings, context, depth + 1);
9296
9450
  }
9297
- return wrapAssignExpression(resolvedExpressionText(node, bindings));
9451
+ if (ts.isObjectLiteralExpression(node)) {
9452
+ const keys = node.properties.map((property) => ts.isPropertyAssignment(property) && !ts.isComputedPropertyName(property.name) ? propName(property.name) : null);
9453
+ if (keys.some((key) => key === null || key === "__proto__") || new Set(keys).size !== keys.length) return inlineCodeExpression(node.getText());
9454
+ } else if (!ts.isArrayLiteralExpression(node) || node.elements.some((element) => ts.isSpreadElement(element) || ts.isOmittedExpression(element))) return wrapAssignExpression(resolvedExpressionText(node, bindings));
9298
9455
  }
9299
9456
  if (context.transitionContext && !ts.isObjectLiteralExpression(node)) return inlineCodeExpression(node.getText());
9300
9457
  if (context.ioValue && !ts.isObjectLiteralExpression(node)) return inlineCodeExpression(node.getText());
@@ -9881,7 +10038,7 @@ function objectToZod(schema) {
9881
10038
  }));
9882
10039
  let result = `z.object(${serializeJS(shape)})`;
9883
10040
  if (schema.additionalProperties === false) result += ".strict()";
9884
- else if (schema.additionalProperties === true || schema.additionalProperties === void 0) result = `z.looseObject(${serializeJS(shape)})`;
10041
+ else if (schema.additionalProperties === true || schema.additionalProperties === void 0 && schema["x-zod-unknownKeys"] !== "strip") result = `z.looseObject(${serializeJS(shape)})`;
9885
10042
  else if (schema.additionalProperties) result += `.catchall(${jsonSchemaToZod(schema.additionalProperties)})`;
9886
10043
  return result;
9887
10044
  }
@@ -10001,7 +10158,7 @@ function graphToXStateTSResult(inputGraph, options = {}) {
10001
10158
  const machineConfig = xstateVersion === 6 ? toXStateV6MachineConfig(graphToMachineConfig(graph, {
10002
10159
  ...configOptions,
10003
10160
  keepChooseStructured: true
10004
- })) : toV5MachineConfig(graphToMachineConfig(graph, configOptions));
10161
+ }), configOptions) : toV5MachineConfig(graphToMachineConfig(graph, configOptions));
10005
10162
  if (xstateVersion === 6) stripStateSchemas(machineConfig);
10006
10163
  let machineExpr;
10007
10164
  if (hasSetup) {
@@ -10137,22 +10294,23 @@ function toV5MachineConfig(machineConfig) {
10137
10294
  return wasArray ? mapped : mapped[0];
10138
10295
  });
10139
10296
  }
10140
- function toXStateV6MachineConfig(machineConfig) {
10141
- return mapV6MachineConfig(machineConfig);
10297
+ function toXStateV6MachineConfig(machineConfig, options = {}) {
10298
+ return mapV6MachineConfig(machineConfig, { projectionOptions: options });
10142
10299
  }
10143
10300
  function mapV6MachineConfig(value, context = {}) {
10144
- if (context.transitionValue) return toV6TransitionValue(value);
10301
+ if (context.transitionValue) return toV6TransitionValue(value, context.projectionOptions);
10145
10302
  if (Array.isArray(value)) return value.map((item) => mapV6MachineConfig(item, context));
10146
10303
  if (!value || typeof value !== "object") return value;
10147
10304
  const result = {};
10148
- for (const [key, item] of Object.entries(value)) {
10305
+ for (const key of Reflect.ownKeys(value)) {
10306
+ const item = Reflect.get(value, key);
10149
10307
  if (key === "states") {
10150
- result[key] = mapV6StatesMap(item);
10308
+ result[key] = mapV6StatesMap(item, context.projectionOptions);
10151
10309
  continue;
10152
10310
  }
10153
10311
  if (key === "choice" && value.type === "choice") {
10154
10312
  const choices = Array.isArray(item) ? item : [item];
10155
- result[key] = choices.length === 1 && opaqueTransitionSource(choices[0]) !== void 0 ? toV6TransitionValue(item) : buildV6TransitionFunction(choices.map(withoutOpaqueTransitionMeta), true) ?? toV6TransitionValue(item);
10313
+ result[key] = choices.length === 1 && opaqueTransitionSource(choices[0]) !== void 0 ? toV6TransitionValue(item, context.projectionOptions) : buildV6TransitionFunction(choices.map(withoutOpaqueTransitionMeta), true) ?? toV6TransitionValue(item, context.projectionOptions);
10156
10314
  continue;
10157
10315
  }
10158
10316
  if (key === "entry" || key === "exit" || key === "actions") {
@@ -10160,28 +10318,34 @@ function mapV6MachineConfig(value, context = {}) {
10160
10318
  continue;
10161
10319
  }
10162
10320
  if (key === "on" || key === "after") {
10163
- result[key] = mapV6TransitionMap(item);
10321
+ result[key] = mapV6TransitionMap(item, context.projectionOptions);
10164
10322
  continue;
10165
10323
  }
10166
10324
  if (key === "always" || key === "onDone" || key === "onError" || key === "onSnapshot" || key === "onTimeout") {
10167
- result[key] = mapV6MachineConfig(item, { transitionValue: true });
10325
+ result[key] = mapV6MachineConfig(item, {
10326
+ transitionValue: true,
10327
+ projectionOptions: context.projectionOptions
10328
+ });
10168
10329
  continue;
10169
10330
  }
10170
- result[key] = mapV6MachineConfig(item);
10331
+ result[key] = mapV6MachineConfig(item, context);
10171
10332
  }
10172
10333
  return result;
10173
10334
  }
10174
10335
  /** Walks a `states` map, treating every entry as a state node. */
10175
- function mapV6StatesMap(value) {
10336
+ function mapV6StatesMap(value, options) {
10176
10337
  if (!value || typeof value !== "object" || Array.isArray(value)) return value;
10177
10338
  const result = {};
10178
- for (const [key, item] of Object.entries(value)) result[key] = mapV6MachineConfig(item);
10339
+ for (const [key, item] of Object.entries(value)) result[key] = mapV6MachineConfig(item, { projectionOptions: options });
10179
10340
  return result;
10180
10341
  }
10181
- function mapV6TransitionMap(value) {
10342
+ function mapV6TransitionMap(value, options) {
10182
10343
  if (!value || typeof value !== "object" || Array.isArray(value)) return value;
10183
10344
  const result = {};
10184
- for (const [key, item] of Object.entries(value)) result[key] = mapV6MachineConfig(item, { transitionValue: true });
10345
+ for (const [key, item] of Object.entries(value)) result[key] = mapV6MachineConfig(item, {
10346
+ transitionValue: true,
10347
+ projectionOptions: options
10348
+ });
10185
10349
  return result;
10186
10350
  }
10187
10351
  /**
@@ -10209,7 +10373,9 @@ function withoutOpaqueTransitionMeta(value) {
10209
10373
  meta: Object.keys(publicMeta).length > 0 ? publicMeta : void 0
10210
10374
  };
10211
10375
  }
10212
- function toV6TransitionValue(value) {
10376
+ function toV6TransitionValue(value, options) {
10377
+ const projectedSource = projectedFunctionSource(value, options);
10378
+ if (projectedSource !== void 0) return raw(projectedSource, value, void 0, true);
10213
10379
  const opaqueSource = opaqueTransitionSource(value);
10214
10380
  if (opaqueSource !== void 0) return raw(opaqueSource, value, void 0, true);
10215
10381
  if (Array.isArray(value)) {
@@ -10218,27 +10384,27 @@ function toV6TransitionValue(value) {
10218
10384
  if (onlyOpaqueSource !== void 0) return raw(onlyOpaqueSource, value[0], void 0, true);
10219
10385
  }
10220
10386
  const transitions = value.map(withoutOpaqueTransitionMeta);
10221
- return buildV6TransitionFunction(transitions) ?? transitions.map((item) => toV6TransitionValue(item));
10387
+ return buildV6TransitionFunction(transitions) ?? transitions.map((item) => toV6TransitionValue(item, options));
10222
10388
  }
10223
10389
  if (!value || typeof value !== "object") return value;
10224
10390
  const transition = withoutOpaqueTransitionMeta(value);
10225
- if (transition.matches !== void 0) return buildV6TransitionFunction([transition]) ?? mapV6MachineConfig(transition);
10226
- if (transition.guard) return buildV6TransitionFunction([transition]) ?? mapV6MachineConfig(transition);
10227
- if (transition.description || transition.input !== void 0 && !containsCodeExpression(transition.input)) return mapV6MachineConfig(transition);
10391
+ if (transition.matches !== void 0) return buildV6TransitionFunction([transition]) ?? mapV6MachineConfig(transition, { projectionOptions: options });
10392
+ if (transition.guard) return buildV6TransitionFunction([transition]) ?? mapV6MachineConfig(transition, { projectionOptions: options });
10393
+ if (transition.description || transition.input !== void 0 && !containsCodeExpression(transition.input)) return mapV6MachineConfig(transition, { projectionOptions: options });
10228
10394
  const target = transition.target;
10229
10395
  const context = transition.context;
10230
10396
  const actionsValue = transition.actions;
10231
10397
  const actions = Array.isArray(actionsValue) ? actionsValue : actionsValue === void 0 ? [] : [actionsValue];
10232
- if (actions.length === 0 && !containsCodeExpression(transition) && !containsTemplateExpression(transition)) return mapV6MachineConfig(transition);
10398
+ if (actions.length === 0 && !containsCodeExpression(transition) && !containsTemplateExpression(transition)) return mapV6MachineConfig(transition, { projectionOptions: options });
10233
10399
  if (actions.length === 0 && typeof target === "string" && context === void 0 && transition.input === void 0 && !transition.reenter && !transition.meta) return { target };
10234
- if (actions.length === 0 && target === void 0 && context === void 0 && transition.input === void 0) return mapV6MachineConfig(transition);
10400
+ if (actions.length === 0 && target === void 0 && context === void 0 && transition.input === void 0) return mapV6MachineConfig(transition, { projectionOptions: options });
10235
10401
  return buildV6ActionFunction(actions, {
10236
10402
  target: typeof target === "string" || Array.isArray(target) && target.every((item) => typeof item === "string") ? target : void 0,
10237
10403
  reenter: transition.reenter === true,
10238
10404
  meta: transition.meta,
10239
10405
  context,
10240
10406
  input: transition.input
10241
- }) ?? mapV6MachineConfig(transition);
10407
+ }) ?? mapV6MachineConfig(transition, { projectionOptions: options });
10242
10408
  }
10243
10409
  function guardCondition(value) {
10244
10410
  const expression = inlineExpr(value);
@@ -10486,9 +10652,21 @@ function unwrapTemplateExpressions(value) {
10486
10652
  const match = value.match(/^\{\{\s*([\s\S]*?)\s*\}\}$/);
10487
10653
  return match?.[1] ? raw(match[1]) : value;
10488
10654
  }
10489
- if (Array.isArray(value)) return value.map(unwrapTemplateExpressions);
10655
+ if (Array.isArray(value)) {
10656
+ const result = value.map(unwrapTemplateExpressions);
10657
+ if (SERIALIZED_SOURCE_ID in value) Object.defineProperty(result, SERIALIZED_SOURCE_ID, {
10658
+ value: Reflect.get(value, SERIALIZED_SOURCE_ID),
10659
+ enumerable: true
10660
+ });
10661
+ return result;
10662
+ }
10490
10663
  if (!value || typeof value !== "object") return value;
10491
- return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, unwrapTemplateExpressions(item)]));
10664
+ const result = Object.fromEntries(Object.entries(value).map(([key, item]) => [key, unwrapTemplateExpressions(item)]));
10665
+ if (SERIALIZED_SOURCE_ID in value) Object.defineProperty(result, SERIALIZED_SOURCE_ID, {
10666
+ value: Reflect.get(value, SERIALIZED_SOURCE_ID),
10667
+ enumerable: true
10668
+ });
10669
+ return result;
10492
10670
  }
10493
10671
  function containsTemplateExpression(value) {
10494
10672
  if (typeof value === "string") return /^\{\{[\s\S]*\}\}$/.test(value.trim());
@@ -10512,7 +10690,8 @@ function mapMachineActionFields(value, mapActions) {
10512
10690
  if (Array.isArray(value)) return value.map((item) => mapMachineActionFields(item, mapActions));
10513
10691
  if (!value || typeof value !== "object") return value;
10514
10692
  const result = {};
10515
- for (const [key, item] of Object.entries(value)) {
10693
+ for (const key of Reflect.ownKeys(value)) {
10694
+ const item = Reflect.get(value, key);
10516
10695
  if (key === "states" && item && typeof item === "object" && !Array.isArray(item)) {
10517
10696
  result[key] = Object.fromEntries(Object.entries(item).map(([stateKey, state]) => [stateKey, mapMachineActionFields(state, mapActions)]));
10518
10697
  continue;
@@ -20457,7 +20636,7 @@ function sourceLocationUris(sourceLocations) {
20457
20636
 
20458
20637
  //#endregion
20459
20638
  //#region src/version.ts
20460
- const CLI_VERSION = "0.12.5";
20639
+ const CLI_VERSION = "0.12.7";
20461
20640
 
20462
20641
  //#endregion
20463
20642
  //#region src/cliHost.ts
@@ -21558,7 +21737,7 @@ function getScriptKind$1(fileName) {
21558
21737
  }
21559
21738
 
21560
21739
  //#endregion
21561
- //#region ../../node_modules/.pnpm/@statelyai+graph@2.1.0_@statelyai+layout@0.3.0_cytoscape@3.34.0_d3-force@3.0.0_d3-hiera_7624816e5d9226bed30c68417318a8b7/node_modules/@statelyai/graph/dist/index.mjs
21740
+ //#region ../../node_modules/.pnpm/@statelyai+graph@2.1.0_@statelyai+layout@0.4.2_cytoscape@3.34.0_d3-force@3.0.0_d3-hiera_48d6687797f6ba8a844c48e50eec3ae1/node_modules/@statelyai/graph/dist/index.mjs
21562
21741
  const LAYOUT_KEYS = {
21563
21742
  node: [
21564
21743
  "x",
package/dist/index.d.mts CHANGED
@@ -71,7 +71,7 @@ declare function createStatelyProjectConfig(options: {
71
71
  defaultXStateVersion?: number;
72
72
  }): StatelyProjectConfig;
73
73
  //#endregion
74
- //#region ../../node_modules/.pnpm/@statelyai+graph@2.1.0_@statelyai+layout@0.3.0_cytoscape@3.34.0_d3-force@3.0.0_d3-hiera_7624816e5d9226bed30c68417318a8b7/node_modules/@statelyai/graph/dist/types-BAEQTwK_.d.mts
74
+ //#region ../../node_modules/.pnpm/@statelyai+graph@2.1.0_@statelyai+layout@0.4.2_cytoscape@3.34.0_d3-force@3.0.0_d3-hiera_48d6687797f6ba8a844c48e50eec3ae1/node_modules/@statelyai/graph/dist/types-BAEQTwK_.d.mts
75
75
  //#region src/types.d.ts
76
76
  /**
77
77
  * Directedness of a graph or an individual edge.
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { C as run, D as verifyProject, E as resolveVerificationRequest, O as formatVerificationJUnit, S as resolveProjectStatus, T as scanProjectSources, _ as isFileGitDirty, a as discoverMachinesInSource, b as resolveCredentialStatus, c as formatDiscoveredMachines, d as formatProjectStatus, f as formatStoredCredentialSource, g as initProject, h as inferInitProjectName, i as discoverLinkedPullTargets, k as createStatelyProjectConfig, l as formatMissingNewMachineDirMessage, m as getEnvCredential, n as buildOAuthLoginStart, o as discoverOAuthLogin, p as getEnvApiKey, r as classifyPushCandidates, s as discoverRemoteProjectMachineTargets, t as COMMANDS, u as formatPlanSummary, v as resolveApiKey, w as scanProjectMachines, x as resolveOpenRootDir, y as resolveConfiguredPullTargets } from "./cli-uQku_cqo.mjs";
1
+ import { C as run, D as verifyProject, E as resolveVerificationRequest, O as formatVerificationJUnit, S as resolveProjectStatus, T as scanProjectSources, _ as isFileGitDirty, a as discoverMachinesInSource, b as resolveCredentialStatus, c as formatDiscoveredMachines, d as formatProjectStatus, f as formatStoredCredentialSource, g as initProject, h as inferInitProjectName, i as discoverLinkedPullTargets, k as createStatelyProjectConfig, l as formatMissingNewMachineDirMessage, m as getEnvCredential, n as buildOAuthLoginStart, o as discoverOAuthLogin, p as getEnvApiKey, r as classifyPushCandidates, s as discoverRemoteProjectMachineTargets, t as COMMANDS, u as formatPlanSummary, v as resolveApiKey, w as scanProjectMachines, x as resolveOpenRootDir, y as resolveConfiguredPullTargets } from "./cli-BRxosLYY.mjs";
2
2
 
3
3
  export { COMMANDS, buildOAuthLoginStart, classifyPushCandidates, createStatelyProjectConfig, discoverLinkedPullTargets, discoverMachinesInSource, discoverOAuthLogin, discoverRemoteProjectMachineTargets, formatDiscoveredMachines, formatMissingNewMachineDirMessage, formatPlanSummary, formatProjectStatus, formatStoredCredentialSource, formatVerificationJUnit, getEnvApiKey, getEnvCredential, inferInitProjectName, initProject, isFileGitDirty, resolveApiKey, resolveConfiguredPullTargets, resolveCredentialStatus, resolveOpenRootDir, resolveProjectStatus, resolveVerificationRequest, run, scanProjectMachines, scanProjectSources, verifyProject };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statelyai",
3
- "version": "0.12.5",
3
+ "version": "0.12.7",
4
4
  "description": "Command-line tools for Stately",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -24,14 +24,14 @@
24
24
  "typescript": "^5.9.3",
25
25
  "ws": "^8.21.0",
26
26
  "zod": "^4.4.1",
27
- "@statelyai/sdk": "0.37.4"
27
+ "@statelyai/sdk": "0.38.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/ws": "^8.18.1",
31
31
  "tsdown": "0.21.0-beta.2",
32
32
  "vitest": "^3.2.4",
33
- "@statelyai/api-contract": "0.6.0",
34
- "@statelyai/editor-sync": "0.1.47"
33
+ "@statelyai/api-contract": "0.6.2",
34
+ "@statelyai/editor-sync": "0.1.50"
35
35
  },
36
36
  "oclif": {
37
37
  "bin": "statelyai",