@doeixd/machine 0.0.17 → 0.0.18

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.
@@ -593,6 +593,43 @@ function createParallelMachine(m1, m2) {
593
593
 
594
594
  // src/extract.ts
595
595
  import { Project, Node } from "ts-morph";
596
+ function _typeToJson(type, verbose = false) {
597
+ const symbol = type.getSymbol();
598
+ if (symbol && symbol.getDeclarations().some(Node.isClassDeclaration)) {
599
+ return symbol.getName();
600
+ }
601
+ if (type.isStringLiteral()) return type.getLiteralValue();
602
+ if (type.isNumberLiteral()) return type.getLiteralValue();
603
+ if (type.isBooleanLiteral()) return type.getLiteralValue();
604
+ if (type.isString()) return "string";
605
+ if (type.isNumber()) return "number";
606
+ if (type.isBoolean()) return "boolean";
607
+ if (type.isArray()) {
608
+ const elementType = type.getArrayElementTypeOrThrow();
609
+ return [_typeToJson(elementType, verbose)];
610
+ }
611
+ if (type.isObject() || type.isIntersection()) {
612
+ const obj = {};
613
+ const properties = type.getProperties();
614
+ for (const prop of properties) {
615
+ const propName = prop.getName();
616
+ if (propName.startsWith("__@")) continue;
617
+ const declaration = prop.getValueDeclaration();
618
+ if (!declaration) continue;
619
+ try {
620
+ obj[propName] = _typeToJson(declaration.getType(), verbose);
621
+ } catch (e) {
622
+ if (verbose) console.error(` Warning: Failed to serialize property ${propName}:`, e);
623
+ obj[propName] = "unknown";
624
+ }
625
+ }
626
+ return Object.keys(obj).length > 0 ? obj : null;
627
+ }
628
+ if (verbose) {
629
+ console.error(` Unhandled type: ${type.getText()}`);
630
+ }
631
+ return "unknown";
632
+ }
596
633
  function resolveClassName(node) {
597
634
  if (Node.isIdentifier(node)) {
598
635
  return node.getText();
@@ -2181,6 +2218,7 @@ export {
2181
2218
  MachineBase,
2182
2219
  MiddlewareBuilder,
2183
2220
  MultiMachineBase,
2221
+ _typeToJson,
2184
2222
  action,
2185
2223
  bindTransitions,
2186
2224
  branch,