@revisium/formula 0.8.0 → 0.10.0

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.
Files changed (75) hide show
  1. package/dist/__tests__/array-context.spec.d.ts +2 -0
  2. package/dist/__tests__/array-context.spec.d.ts.map +1 -0
  3. package/dist/__tests__/dependency-graph.spec.d.ts +2 -0
  4. package/dist/__tests__/dependency-graph.spec.d.ts.map +1 -0
  5. package/dist/__tests__/evaluate-complex.spec.d.ts +2 -0
  6. package/dist/__tests__/evaluate-complex.spec.d.ts.map +1 -0
  7. package/dist/__tests__/parse-formula.spec.d.ts +2 -0
  8. package/dist/__tests__/parse-formula.spec.d.ts.map +1 -0
  9. package/dist/__tests__/parser.spec.d.ts +2 -0
  10. package/dist/__tests__/parser.spec.d.ts.map +1 -0
  11. package/dist/__tests__/replace-dependencies.spec.d.ts +2 -0
  12. package/dist/__tests__/replace-dependencies.spec.d.ts.map +1 -0
  13. package/dist/__tests__/serialize-ast.spec.d.ts +2 -0
  14. package/dist/__tests__/serialize-ast.spec.d.ts.map +1 -0
  15. package/dist/__tests__/validate-syntax.spec.d.ts +2 -0
  16. package/dist/__tests__/validate-syntax.spec.d.ts.map +1 -0
  17. package/dist/dependency-graph.d.ts +17 -0
  18. package/dist/dependency-graph.d.ts.map +1 -0
  19. package/dist/editor/index.cjs +4 -19
  20. package/dist/editor/index.d.ts +8 -1
  21. package/dist/editor/index.d.ts.map +1 -0
  22. package/dist/editor/index.mjs +3 -0
  23. package/dist/formula-spec.cjs +831 -535
  24. package/dist/formula-spec.cjs.map +1 -1
  25. package/dist/formula-spec.d.ts +10 -5
  26. package/dist/formula-spec.d.ts.map +1 -0
  27. package/dist/formula-spec.mjs +1062 -0
  28. package/dist/formula-spec.mjs.map +1 -0
  29. package/dist/index.cjs +121 -131
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.ts +10 -25
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.mjs +130 -0
  34. package/dist/index.mjs.map +1 -0
  35. package/dist/ohm/core/parser.d.ts +30 -0
  36. package/dist/ohm/core/parser.d.ts.map +1 -0
  37. package/dist/ohm/core/replace-dependencies.d.ts +3 -0
  38. package/dist/ohm/core/replace-dependencies.d.ts.map +1 -0
  39. package/dist/ohm/core/serialize-ast.d.ts +3 -0
  40. package/dist/ohm/core/serialize-ast.d.ts.map +1 -0
  41. package/dist/ohm/core/types.d.ts +78 -0
  42. package/dist/ohm/core/types.d.ts.map +1 -0
  43. package/dist/ohm/grammar/index.d.ts +3 -0
  44. package/dist/ohm/grammar/index.d.ts.map +1 -0
  45. package/dist/ohm/index.d.ts +8 -0
  46. package/dist/ohm/index.d.ts.map +1 -0
  47. package/dist/ohm/semantics/index.d.ts +2 -0
  48. package/dist/ohm/semantics/index.d.ts.map +1 -0
  49. package/dist/parse-formula.d.ts +9 -0
  50. package/dist/parse-formula.d.ts.map +1 -0
  51. package/dist/types.d.ts +52 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/validate-syntax-Dttxs0ku.mjs +1426 -0
  54. package/dist/validate-syntax-Dttxs0ku.mjs.map +1 -0
  55. package/dist/validate-syntax-q3bM-DaM.cjs +1507 -0
  56. package/dist/validate-syntax-q3bM-DaM.cjs.map +1 -0
  57. package/dist/validate-syntax.d.ts +9 -0
  58. package/dist/validate-syntax.d.ts.map +1 -0
  59. package/package.json +12 -11
  60. package/dist/chunk-4FIOGFOL.cjs +0 -1512
  61. package/dist/chunk-4FIOGFOL.cjs.map +0 -1
  62. package/dist/chunk-RMAHNB4D.js +0 -1482
  63. package/dist/chunk-RMAHNB4D.js.map +0 -1
  64. package/dist/editor/index.cjs.map +0 -1
  65. package/dist/editor/index.d.cts +0 -1
  66. package/dist/editor/index.js +0 -3
  67. package/dist/editor/index.js.map +0 -1
  68. package/dist/formula-spec.d.cts +0 -68
  69. package/dist/formula-spec.js +0 -765
  70. package/dist/formula-spec.js.map +0 -1
  71. package/dist/index-CPsOPCQ6.d.cts +0 -166
  72. package/dist/index-CPsOPCQ6.d.ts +0 -166
  73. package/dist/index.d.cts +0 -25
  74. package/dist/index.js +0 -111
  75. package/dist/index.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/formula-spec.ts"],"names":[],"mappings":";AAuDO,IAAM,WAAA,GAA2B;AAAA,EACtC,OAAA,EAAS,KAAA;AAAA,EACT,WAAA,EACE,8GAAA;AAAA,EAEF,MAAA,EAAQ;AAAA,IACN,eAAA,EAAiB;AAAA,MACf,iDAAA;AAAA,MACA,mDAAA;AAAA,MACA,qDAAA;AAAA,MACA,qEAAA;AAAA,MACA,kDAAA;AAAA,MACA,kEAAA;AAAA,MACA,kEAAA;AAAA,MACA;AAAA,KACF;AAAA,IACA,mBAAA,EAAqB;AAAA,MACnB,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,kCAAA,EAAmC;AAAA,MACjE,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,aAAA,EAAc;AAAA,MAC5C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,gBAAA,EAAiB;AAAA,MAC/C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,UAAA,EAAW;AAAA,MACzC,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,oBAAA;AAAqB,KACrD;AAAA,IACA,mBAAA,EAAqB;AAAA,MACnB,EAAE,QAAA,EAAU,IAAA,EAAM,WAAA,EAAa,OAAA,EAAQ;AAAA,MACvC,EAAE,QAAA,EAAU,IAAA,EAAM,WAAA,EAAa,WAAA,EAAY;AAAA,MAC3C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,cAAA,EAAe;AAAA,MAC7C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,WAAA,EAAY;AAAA,MAC1C,EAAE,QAAA,EAAU,IAAA,EAAM,WAAA,EAAa,kBAAA,EAAmB;AAAA,MAClD,EAAE,QAAA,EAAU,IAAA,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AAAA;AAAA;AAAA,qBAAA;AAAA;AAgDR,GACF;AAAA,EAEA,WAAA,EAAa;AAAA,IACX,SAAA,EACE,0EAAA;AAAA,IACF,UAAA,EAAY,CAAC,QAAA,EAAU,QAAA,EAAU,SAAS,CAAA;AAAA,IAC1C,KAAA,EAAO;AAAA,MACL,0DAAA;AAAA,MACA,sDAAA;AAAA,MACA,6DAAA;AAAA,MACA;AAAA;AACF;AAEJ","file":"formula-spec.js","sourcesContent":["export interface FunctionSpec {\n name: string;\n description: string;\n signature: string;\n returnType: 'string' | 'number' | 'boolean' | 'any';\n examples: string[];\n}\n\nexport interface FormulaSpec {\n version: string;\n description: string;\n syntax: {\n fieldReferences: string[];\n arithmeticOperators: { operator: string; description: string }[];\n comparisonOperators: { operator: string; description: string }[];\n logicalOperators: { operator: string; description: string }[];\n other: string[];\n };\n functions: {\n string: FunctionSpec[];\n numeric: FunctionSpec[];\n boolean: FunctionSpec[];\n array: FunctionSpec[];\n conversion: FunctionSpec[];\n conditional: FunctionSpec[];\n };\n features: {\n name: string;\n description: string;\n minVersion: string;\n examples: string[];\n dependenciesExtracted?: string[];\n }[];\n versionDetection: { feature: string; minVersion: string }[];\n parseResult: {\n description: string;\n interface: string;\n };\n examples: {\n expression: string;\n description: string;\n result?: string;\n }[];\n apiExamples: {\n name: string;\n description: string;\n code: string;\n }[];\n schemaUsage: {\n structure: string;\n fieldTypes: string[];\n rules: string[];\n };\n}\n\nexport const formulaSpec: FormulaSpec = {\n version: '1.1',\n description:\n 'Formula expressions for computed fields. Formulas reference other fields and calculate values automatically.',\n\n syntax: {\n fieldReferences: [\n 'Simple field: fieldName (e.g., price, quantity)',\n 'Nested path: object.property (e.g., stats.damage)',\n 'Array index: array[0] or array[-1] for last element',\n 'Bracket notation: [\"field-name\"] for field names containing hyphens',\n ' - Required when field name contains hyphen (-)',\n ' - Without brackets: field-name is parsed as \"field minus name\"',\n ' - With brackets: [\"field-name\"] references the field correctly',\n 'Combined: items[0].price, user.addresses[-1].city, obj[\"field-name\"].value',\n ],\n arithmeticOperators: [\n { operator: '+', description: 'Addition or string concatenation' },\n { operator: '-', description: 'Subtraction' },\n { operator: '*', description: 'Multiplication' },\n { operator: '/', description: 'Division' },\n { operator: '%', description: 'Modulo (remainder)' },\n ],\n comparisonOperators: [\n { operator: '==', description: 'Equal' },\n { operator: '!=', description: 'Not equal' },\n { operator: '>', description: 'Greater than' },\n { operator: '<', description: 'Less than' },\n { operator: '>=', description: 'Greater or equal' },\n { operator: '<=', description: 'Less or equal' },\n ],\n logicalOperators: [\n { operator: '&&', description: 'Logical AND' },\n { operator: '||', description: 'Logical OR' },\n { operator: '!', description: 'Logical NOT' },\n ],\n other: ['Parentheses: (a + b) * c', 'Unary minus: -value, a + -b'],\n },\n\n functions: {\n string: [\n {\n name: 'concat',\n description: 'Concatenate multiple values into a single string',\n signature: 'concat(value1, value2, ...)',\n returnType: 'string',\n examples: [\n 'concat(firstName, \" \", lastName) // \"John Doe\"',\n 'concat(\"Price: \", price, \" USD\") // \"Price: 100 USD\"',\n ],\n },\n {\n name: 'upper',\n description: 'Convert string to uppercase',\n signature: 'upper(text)',\n returnType: 'string',\n examples: ['upper(name) // \"HELLO\"'],\n },\n {\n name: 'lower',\n description: 'Convert string to lowercase',\n signature: 'lower(text)',\n returnType: 'string',\n examples: ['lower(name) // \"hello\"'],\n },\n {\n name: 'trim',\n description: 'Remove whitespace from both ends of a string',\n signature: 'trim(text)',\n returnType: 'string',\n examples: ['trim(name) // \"hello\" from \" hello \"'],\n },\n {\n name: 'left',\n description: 'Extract characters from the beginning of a string',\n signature: 'left(text, count)',\n returnType: 'string',\n examples: ['left(name, 3) // \"hel\" from \"hello\"'],\n },\n {\n name: 'right',\n description: 'Extract characters from the end of a string',\n signature: 'right(text, count)',\n returnType: 'string',\n examples: ['right(name, 3) // \"llo\" from \"hello\"'],\n },\n {\n name: 'replace',\n description: 'Replace first occurrence of a substring',\n signature: 'replace(text, search, replacement)',\n returnType: 'string',\n examples: ['replace(name, \"o\", \"0\") // \"hell0\" from \"hello\"'],\n },\n {\n name: 'join',\n description: 'Join array elements into a string',\n signature: 'join(array, separator?)',\n returnType: 'string',\n examples: ['join(tags) // \"a,b,c\"', 'join(tags, \" | \") // \"a | b | c\"'],\n },\n ],\n numeric: [\n {\n name: 'round',\n description: 'Round a number to specified decimal places',\n signature: 'round(number, decimals?)',\n returnType: 'number',\n examples: ['round(3.14159, 2) // 3.14', 'round(3.5) // 4'],\n },\n {\n name: 'floor',\n description: 'Round down to the nearest integer',\n signature: 'floor(number)',\n returnType: 'number',\n examples: ['floor(3.7) // 3'],\n },\n {\n name: 'ceil',\n description: 'Round up to the nearest integer',\n signature: 'ceil(number)',\n returnType: 'number',\n examples: ['ceil(3.2) // 4'],\n },\n {\n name: 'abs',\n description: 'Get the absolute value',\n signature: 'abs(number)',\n returnType: 'number',\n examples: ['abs(-5) // 5'],\n },\n {\n name: 'sqrt',\n description: 'Calculate the square root',\n signature: 'sqrt(number)',\n returnType: 'number',\n examples: ['sqrt(16) // 4'],\n },\n {\n name: 'pow',\n description: 'Raise a number to a power',\n signature: 'pow(base, exponent)',\n returnType: 'number',\n examples: ['pow(2, 3) // 8'],\n },\n {\n name: 'min',\n description: 'Get the minimum of multiple values',\n signature: 'min(value1, value2, ...)',\n returnType: 'number',\n examples: ['min(a, b, c) // smallest value'],\n },\n {\n name: 'max',\n description: 'Get the maximum of multiple values',\n signature: 'max(value1, value2, ...)',\n returnType: 'number',\n examples: ['max(a, b, c) // largest value'],\n },\n {\n name: 'log',\n description: 'Calculate the natural logarithm',\n signature: 'log(number)',\n returnType: 'number',\n examples: ['log(10) // 2.302...'],\n },\n {\n name: 'log10',\n description: 'Calculate the base-10 logarithm',\n signature: 'log10(number)',\n returnType: 'number',\n examples: ['log10(100) // 2'],\n },\n {\n name: 'exp',\n description: 'Calculate e raised to a power',\n signature: 'exp(number)',\n returnType: 'number',\n examples: ['exp(1) // 2.718...'],\n },\n {\n name: 'sign',\n description: 'Get the sign of a number (-1, 0, or 1)',\n signature: 'sign(number)',\n returnType: 'number',\n examples: ['sign(-5) // -1', 'sign(0) // 0', 'sign(5) // 1'],\n },\n {\n name: 'length',\n description: 'Get the length of a string or array',\n signature: 'length(value)',\n returnType: 'number',\n examples: ['length(name) // 5 from \"hello\"', 'length(items) // 3'],\n },\n ],\n boolean: [\n {\n name: 'and',\n description: 'Logical AND of two values',\n signature: 'and(a, b)',\n returnType: 'boolean',\n examples: ['and(isActive, hasPermission) // true if both true'],\n },\n {\n name: 'or',\n description: 'Logical OR of two values',\n signature: 'or(a, b)',\n returnType: 'boolean',\n examples: ['or(isAdmin, isOwner) // true if either true'],\n },\n {\n name: 'not',\n description: 'Logical NOT of a value',\n signature: 'not(value)',\n returnType: 'boolean',\n examples: ['not(isDeleted) // true if false'],\n },\n {\n name: 'contains',\n description: 'Check if a string contains a substring',\n signature: 'contains(text, search)',\n returnType: 'boolean',\n examples: ['contains(name, \"ell\") // true for \"hello\"'],\n },\n {\n name: 'startswith',\n description: 'Check if a string starts with a prefix',\n signature: 'startswith(text, prefix)',\n returnType: 'boolean',\n examples: ['startswith(name, \"hel\") // true for \"hello\"'],\n },\n {\n name: 'endswith',\n description: 'Check if a string ends with a suffix',\n signature: 'endswith(text, suffix)',\n returnType: 'boolean',\n examples: ['endswith(name, \"llo\") // true for \"hello\"'],\n },\n {\n name: 'isnull',\n description: 'Check if a value is null or undefined',\n signature: 'isnull(value)',\n returnType: 'boolean',\n examples: ['isnull(optionalField) // true if null/undefined'],\n },\n {\n name: 'includes',\n description: 'Check if an array contains a value',\n signature: 'includes(array, value)',\n returnType: 'boolean',\n examples: [\n 'includes(tags, \"featured\") // true if array contains value',\n ],\n },\n ],\n array: [\n {\n name: 'sum',\n description: 'Calculate the sum of array elements',\n signature: 'sum(array)',\n returnType: 'number',\n examples: ['sum(prices) // total of all prices'],\n },\n {\n name: 'avg',\n description: 'Calculate the average of array elements',\n signature: 'avg(array)',\n returnType: 'number',\n examples: ['avg(scores) // average score'],\n },\n {\n name: 'count',\n description: 'Get the number of elements in an array',\n signature: 'count(array)',\n returnType: 'number',\n examples: ['count(items) // number of items'],\n },\n {\n name: 'first',\n description: 'Get the first element of an array',\n signature: 'first(array)',\n returnType: 'any',\n examples: ['first(items) // first item'],\n },\n {\n name: 'last',\n description: 'Get the last element of an array',\n signature: 'last(array)',\n returnType: 'any',\n examples: ['last(items) // last item'],\n },\n ],\n conversion: [\n {\n name: 'tostring',\n description: 'Convert a value to string',\n signature: 'tostring(value)',\n returnType: 'string',\n examples: ['tostring(42) // \"42\"'],\n },\n {\n name: 'tonumber',\n description: 'Convert a value to number',\n signature: 'tonumber(value)',\n returnType: 'number',\n examples: ['tonumber(\"42\") // 42'],\n },\n {\n name: 'toboolean',\n description: 'Convert a value to boolean',\n signature: 'toboolean(value)',\n returnType: 'boolean',\n examples: ['toboolean(1) // true', 'toboolean(0) // false'],\n },\n ],\n conditional: [\n {\n name: 'if',\n description: 'Return one of two values based on a condition',\n signature: 'if(condition, valueIfTrue, valueIfFalse)',\n returnType: 'any',\n examples: [\n 'if(stock > 0, \"Available\", \"Out of Stock\")',\n 'if(price > 100, price * 0.9, price)',\n ],\n },\n {\n name: 'coalesce',\n description: 'Return the first non-null value',\n signature: 'coalesce(value1, value2, ...)',\n returnType: 'any',\n examples: ['coalesce(nickname, name, \"Anonymous\")'],\n },\n ],\n },\n\n features: [\n {\n name: 'simple_refs',\n description: 'Reference top-level fields by name',\n minVersion: '1.0',\n examples: ['price', 'quantity', 'baseDamage'],\n dependenciesExtracted: ['[\"price\"]', '[\"quantity\"]', '[\"baseDamage\"]'],\n },\n {\n name: 'arithmetic',\n description: 'Basic math operations (+, -, *, /)',\n minVersion: '1.0',\n examples: ['price * 1.1', 'a + b - c', 'quantity * price'],\n },\n {\n name: 'comparison',\n description: 'Compare values (>, <, >=, <=, ==, !=)',\n minVersion: '1.0',\n examples: ['price > 100', 'x == 10', 'quantity >= 5'],\n },\n {\n name: 'nested_path',\n description: 'Access nested object properties using dot notation',\n minVersion: '1.1',\n examples: ['stats.damage', 'user.profile.name', 'item.metadata.category'],\n dependenciesExtracted: ['[\"stats.damage\"]'],\n },\n {\n name: 'array_index',\n description:\n 'Access array elements by numeric index. Negative indices access from the end',\n minVersion: '1.1',\n examples: [\n 'items[0].price',\n 'inventory[1].quantity',\n 'items[-1].name // last element',\n 'items[-2].price // second to last',\n ],\n dependenciesExtracted: ['[\"items[0].price\"]', '[\"items[-1].name\"]'],\n },\n {\n name: 'root_path',\n description:\n 'Absolute path reference starting with /. Always resolves from root data, even inside array item formulas',\n minVersion: '1.1',\n examples: [\n '/taxRate',\n '/config.tax',\n 'price * (1 + /taxRate)',\n 'price * /config.multiplier',\n ],\n dependenciesExtracted: ['[\"/taxRate\"]', '[\"/config.tax\"]'],\n },\n {\n name: 'relative_path',\n description:\n 'Relative path reference starting with ../. Each ../ goes up one level in the path hierarchy. Works with nested objects, arrays, and combinations. Supports accessing nested properties after the relative prefix (e.g., ../config.value)',\n minVersion: '1.1',\n examples: [\n '../discount',\n '../../rootRate',\n '../config.multiplier',\n 'price * (1 - ../discount)',\n 'price * ../../globalRate',\n 'price * ../settings.tax.rate',\n ],\n dependenciesExtracted: [\n '[\"../discount\"]',\n '[\"../../rootRate\"]',\n '[\"../config.multiplier\"]',\n ],\n },\n {\n name: 'function_named_fields',\n description:\n 'Fields can have the same name as built-in functions (max, min, sum, etc.). Built-in functions are always checked first when a function call is made',\n minVersion: '1.0',\n examples: [\n 'max(max, 0)',\n 'min(min, 100)',\n 'max(max - field.min, 0)',\n 'round(round * 2)',\n ],\n },\n {\n name: 'bracket_notation',\n description:\n 'Access fields containing hyphens using bracket notation with quotes. Required because \"field-name\" would be parsed as \"field minus name\" (subtraction). Works like JavaScript object[\"key\"] syntax.',\n minVersion: '1.1',\n examples: [\n '[\"field-name\"] // Without brackets: field - name (subtraction!)',\n \"['field-name'] // Single quotes also work\",\n '[\"field-one\"][\"field-two\"]',\n 'obj[\"field-name\"].value',\n '[\"items-list\"][0][\"val\"]',\n '[\"price-new\"] * 2',\n ],\n dependenciesExtracted: ['[\"field-name\"]', \"['field-name']\"],\n },\n ],\n\n versionDetection: [\n { feature: 'Simple refs, arithmetic, comparisons', minVersion: '1.0' },\n { feature: 'Function-named fields (max(max, 0))', minVersion: '1.0' },\n { feature: 'Nested paths (a.b)', minVersion: '1.1' },\n { feature: 'Array index ([0], [-1])', minVersion: '1.1' },\n { feature: 'Absolute paths (/field)', minVersion: '1.1' },\n { feature: 'Relative paths (../field)', minVersion: '1.1' },\n { feature: 'Bracket notation ([\"field-name\"])', minVersion: '1.1' },\n ],\n\n parseResult: {\n description:\n 'The parser automatically detects the minimum required version',\n interface: `interface ParseResult {\n ast: ASTNode; // Abstract syntax tree\n dependencies: string[]; // List of field dependencies\n features: string[]; // List of detected features\n minVersion: string; // Minimum required version (\"1.0\" or \"1.1\")\n}`,\n },\n\n examples: [\n {\n expression: 'price * quantity',\n description: 'Calculate total from price and quantity',\n result: 'number',\n },\n {\n expression: 'firstName + \" \" + lastName',\n description: 'Concatenate strings with space',\n result: 'string',\n },\n {\n expression: 'quantity > 0',\n description: 'Check if in stock',\n result: 'boolean',\n },\n {\n expression: 'if(stock > 0, \"Available\", \"Out of Stock\")',\n description: 'Conditional text based on stock',\n result: 'string',\n },\n {\n expression: 'price * (1 + taxRate)',\n description: 'Price with tax',\n result: 'number',\n },\n {\n expression: 'items[0].price + items[1].price',\n description: 'Sum first two item prices (v1.1)',\n result: 'number',\n },\n ],\n\n apiExamples: [\n {\n name: 'Simple Expression (v1.0)',\n description: 'Parse a basic arithmetic expression',\n code: `parseExpression('price * 1.1')\n// {\n// minVersion: \"1.0\",\n// features: [],\n// dependencies: [\"price\"]\n// }`,\n },\n {\n name: 'Nested Path (v1.1)',\n description: 'Parse expression with nested object access',\n code: `parseExpression('stats.damage * multiplier')\n// {\n// minVersion: \"1.1\",\n// features: [\"nested_path\"],\n// dependencies: [\"stats.damage\", \"multiplier\"]\n// }`,\n },\n {\n name: 'Array Access (v1.1)',\n description: 'Parse expression with array index access',\n code: `parseExpression('items[0].price + items[1].price')\n// {\n// minVersion: \"1.1\",\n// features: [\"array_index\", \"nested_path\"],\n// dependencies: [\"items[0].price\", \"items[1].price\"]\n// }`,\n },\n {\n name: 'Evaluate expressions',\n description: 'Execute formulas with context data',\n code: `evaluate('price * 1.1', { price: 100 })\n// 110\n\nevaluate('stats.damage', { stats: { damage: 50 } })\n// 50\n\nevaluate('items[0].price', { items: [{ price: 10 }] })\n// 10\n\nevaluate('price > 100', { price: 150 })\n// true\n\nevaluate('a + b * c', { a: 1, b: 2, c: 3 })\n// 7`,\n },\n {\n name: 'Function-named fields',\n description: 'Fields can have the same name as built-in functions',\n code: `// Built-in functions take precedence in function calls\nevaluate('max(max, 0)', { max: 10 })\n// 10 (max() function, then max field)\n\nevaluate('max(max - field.min, 0)', { max: 100, field: { min: 20 } })\n// 80\n\nevaluate('round(round * 2)', { round: 3.7 })\n// 7\n\n// Field named \"sum\" doesn't conflict with sum() function\nevaluate('sum(values) + sum', { values: [1, 2, 3], sum: 10 })\n// 16`,\n },\n {\n name: 'Evaluate with context (array items)',\n description:\n 'Use evaluateWithContext() for array item formulas with path resolution',\n code: `// Absolute path: /field always resolves from root\nevaluateWithContext('price * (1 + /taxRate)', {\n rootData: { taxRate: 0.1, items: [{ price: 100 }] },\n itemData: { price: 100 },\n currentPath: 'items[0]'\n})\n// 110\n\n// Nested absolute path\nevaluateWithContext('price * /config.multiplier', {\n rootData: { config: { multiplier: 1.5 }, items: [] },\n itemData: { price: 100 },\n currentPath: 'items[0]'\n})\n// 150\n\n// Relative path: ../field resolves from parent (root)\nevaluateWithContext('price * (1 - ../discount)', {\n rootData: { discount: 0.2, items: [] },\n itemData: { price: 100 },\n currentPath: 'items[0]'\n})\n// 80\n\n// itemData takes precedence over rootData for same field\nevaluateWithContext('value + 10', {\n rootData: { value: 100 },\n itemData: { value: 50 },\n currentPath: 'items[0]'\n})\n// 60`,\n },\n {\n name: 'Relative paths - path resolution',\n description:\n 'Understanding how ../ resolves based on currentPath. Each ../ goes up one segment (object property or array element counts as one segment)',\n code: `// Path structure explanation:\n// currentPath splits by \".\" (dots), keeping array indices attached to field names\n// \"items[0]\" = 1 segment\n// \"items[0].inner\" = 2 segments: [\"items[0]\", \"inner\"]\n// \"container.items[0]\" = 2 segments: [\"container\", \"items[0]\"]\n\n// Single ../ from array item -> goes to root\n// currentPath: \"items[0]\" (1 segment)\n// ../ goes up 1 level -> root\nevaluateWithContext('price * ../discount', {\n rootData: { discount: 0.2, items: [{ price: 100 }] },\n itemData: { price: 100 },\n currentPath: 'items[0]'\n})\n// Resolves ../discount to root.discount = 0.2\n// Result: 100 * 0.2 = 20\n\n// Single ../ from nested object in array -> goes to array item\n// currentPath: \"items[0].inner\" (2 segments)\n// ../ goes up 1 level -> \"items[0]\"\nevaluateWithContext('price * ../itemMultiplier', {\n rootData: { items: [{ itemMultiplier: 3, inner: { price: 10 } }] },\n itemData: { price: 10 },\n currentPath: 'items[0].inner'\n})\n// Resolves ../itemMultiplier to items[0].itemMultiplier = 3\n// Result: 10 * 3 = 30\n\n// Double ../../ from nested object in array -> goes to root\n// currentPath: \"items[0].inner\" (2 segments)\n// ../../ goes up 2 levels -> root\nevaluateWithContext('price * ../../rootRate', {\n rootData: { rootRate: 2, items: [{ inner: { price: 5 } }] },\n itemData: { price: 5 },\n currentPath: 'items[0].inner'\n})\n// Resolves ../../rootRate to root.rootRate = 2\n// Result: 5 * 2 = 10`,\n },\n {\n name: 'Relative paths - nested arrays',\n description:\n 'How relative paths work with arrays inside objects and nested arrays',\n code: `// Array inside nested object\n// currentPath: \"container.items[0]\" (2 segments: [\"container\", \"items[0]\"])\n// ../ goes up 1 level -> \"container\"\nevaluateWithContext('price * ../containerRate', {\n rootData: {\n container: {\n containerRate: 4,\n items: [{ price: 5 }]\n }\n },\n itemData: { price: 5 },\n currentPath: 'container.items[0]'\n})\n// Resolves ../containerRate to container.containerRate = 4\n// Result: 5 * 4 = 20\n\n// ../../ from array inside object -> goes to root\n// currentPath: \"container.items[0]\" (2 segments)\n// ../../ goes up 2 levels -> root\nevaluateWithContext('price * ../../rootVal', {\n rootData: {\n rootVal: 6,\n container: { items: [{ price: 5 }] }\n },\n itemData: { price: 5 },\n currentPath: 'container.items[0]'\n})\n// Resolves ../../rootVal to root.rootVal = 6\n// Result: 5 * 6 = 30\n\n// Nested arrays: items[].subItems[]\n// currentPath: \"items[0].subItems[0]\" (2 segments: [\"items[0]\", \"subItems[0]\"])\n// ../ goes up 1 level -> \"items[0]\"\nevaluateWithContext('qty * ../itemPrice', {\n rootData: {\n items: [{ itemPrice: 10, subItems: [{ qty: 3 }] }]\n },\n itemData: { qty: 3 },\n currentPath: 'items[0].subItems[0]'\n})\n// Resolves ../itemPrice to items[0].itemPrice = 10\n// Result: 3 * 10 = 30`,\n },\n {\n name: 'Relative paths - accessing nested properties',\n description:\n 'Relative paths can include nested property access after the ../ prefix',\n code: `// ../sibling.nested accesses a sibling with nested property\n// currentPath: \"items[0].products[0]\" (2 segments)\n// ../ goes to \"items[0]\", then accesses .config.discount\nevaluateWithContext('price * ../config.discount', {\n rootData: {\n items: [{\n config: { discount: 0.9 },\n products: [{ price: 100 }]\n }]\n },\n itemData: { price: 100 },\n currentPath: 'items[0].products[0]'\n})\n// Resolves ../config.discount to items[0].config.discount = 0.9\n// Result: 100 * 0.9 = 90\n\n// Deep nested: ../../settings.tax.rate\nevaluateWithContext('amount * ../../settings.tax.rate', {\n rootData: {\n settings: { tax: { rate: 0.1 } },\n orders: [{ items: [{ amount: 200 }] }]\n },\n itemData: { amount: 200 },\n currentPath: 'orders[0].items[0]'\n})\n// Resolves ../../settings.tax.rate to root.settings.tax.rate = 0.1\n// Result: 200 * 0.1 = 20`,\n },\n {\n name: 'Relative paths - complex nesting',\n description: 'Complex scenarios with arrays inside objects inside arrays',\n code: `// Array inside object inside array\n// Structure: items[].container.subItems[]\n// currentPath: \"items[0].container.subItems[0]\" (3 segments)\nevaluateWithContext('val * ../containerMultiplier', {\n rootData: {\n items: [{\n container: {\n containerMultiplier: 4,\n subItems: [{ val: 3 }]\n }\n }]\n },\n itemData: { val: 3 },\n currentPath: 'items[0].container.subItems[0]'\n})\n// ../ goes to \"items[0].container\"\n// Resolves ../containerMultiplier to items[0].container.containerMultiplier = 4\n// Result: 3 * 4 = 12\n\n// ../../ from same structure -> goes to array item\nevaluateWithContext('val * ../../itemRate', {\n rootData: {\n items: [{\n itemRate: 5,\n container: { subItems: [{ val: 2 }] }\n }]\n },\n itemData: { val: 2 },\n currentPath: 'items[0].container.subItems[0]'\n})\n// ../../ goes to \"items[0]\"\n// Resolves ../../itemRate to items[0].itemRate = 5\n// Result: 2 * 5 = 10\n\n// ../../../ from same structure -> goes to root\nevaluateWithContext('val * ../../../rootFactor', {\n rootData: {\n rootFactor: 3,\n items: [{\n container: { subItems: [{ val: 7 }] }\n }]\n },\n itemData: { val: 7 },\n currentPath: 'items[0].container.subItems[0]'\n})\n// ../../../ goes to root\n// Resolves ../../../rootFactor to root.rootFactor = 3\n// Result: 7 * 3 = 21`,\n },\n ],\n\n schemaUsage: {\n structure:\n '{ \"x-formula\": { \"version\": 1, \"expression\": \"...\" }, \"readOnly\": true }',\n fieldTypes: ['string', 'number', 'boolean'],\n rules: [\n 'Add x-formula to string, number, or boolean field schema',\n 'readOnly: true is REQUIRED for fields with x-formula',\n 'Expression must reference existing fields in the same table',\n 'Circular dependencies are not allowed (a references b, b references a)',\n ],\n },\n};\n"]}
@@ -1,166 +0,0 @@
1
- interface XFormula {
2
- version: 1;
3
- expression: string;
4
- }
5
- type FormulaMinorVersion = '1.0' | '1.1';
6
- type FormulaFeature = 'nested_path' | 'array_index' | 'array_wildcard' | 'relative_path' | 'root_path' | 'context_token' | 'array_function' | 'bracket_notation';
7
- interface FormulaAnalysis {
8
- minVersion: FormulaMinorVersion;
9
- features: FormulaFeature[];
10
- dependencies: string[];
11
- }
12
- type PathSegment = {
13
- type: 'property';
14
- name: string;
15
- } | {
16
- type: 'index';
17
- value: number;
18
- } | {
19
- type: 'wildcard';
20
- } | {
21
- type: 'parent';
22
- } | {
23
- type: 'root';
24
- } | {
25
- type: 'token';
26
- name: string;
27
- };
28
- interface ParsedPath {
29
- original: string;
30
- segments: PathSegment[];
31
- isAbsolute: boolean;
32
- isRelative: boolean;
33
- }
34
- interface PathValidationResult {
35
- isValid: boolean;
36
- error?: string;
37
- segments?: PathSegment[];
38
- }
39
- interface FormulaContext {
40
- [fieldName: string]: unknown;
41
- }
42
- type FormulaResult = number | string | boolean | null;
43
-
44
- type ASTNode = NumberLiteral | StringLiteral | BooleanLiteral | NullLiteral | Identifier | BracketedIdentifier | RootPath | RelativePath | ContextToken | BinaryOp | UnaryOp | TernaryOp | CallExpression | MemberExpression | BracketedMemberExpression | IndexExpression | WildcardExpression;
45
- interface NumberLiteral {
46
- type: 'NumberLiteral';
47
- value: number;
48
- }
49
- interface StringLiteral {
50
- type: 'StringLiteral';
51
- value: string;
52
- }
53
- interface BooleanLiteral {
54
- type: 'BooleanLiteral';
55
- value: boolean;
56
- }
57
- interface NullLiteral {
58
- type: 'NullLiteral';
59
- }
60
- interface Identifier {
61
- type: 'Identifier';
62
- name: string;
63
- }
64
- interface BracketedIdentifier {
65
- type: 'BracketedIdentifier';
66
- name: string;
67
- }
68
- interface RootPath {
69
- type: 'RootPath';
70
- path: string;
71
- }
72
- interface RelativePath {
73
- type: 'RelativePath';
74
- path: string;
75
- }
76
- interface ContextToken {
77
- type: 'ContextToken';
78
- name: string;
79
- }
80
- interface BinaryOp {
81
- type: 'BinaryOp';
82
- op: string;
83
- left: ASTNode;
84
- right: ASTNode;
85
- }
86
- interface UnaryOp {
87
- type: 'UnaryOp';
88
- op: string;
89
- argument: ASTNode;
90
- }
91
- interface TernaryOp {
92
- type: 'TernaryOp';
93
- condition: ASTNode;
94
- consequent: ASTNode;
95
- alternate: ASTNode;
96
- }
97
- interface CallExpression {
98
- type: 'CallExpression';
99
- callee: ASTNode;
100
- arguments: ASTNode[];
101
- }
102
- interface MemberExpression {
103
- type: 'MemberExpression';
104
- object: ASTNode;
105
- property: string;
106
- }
107
- interface BracketedMemberExpression {
108
- type: 'BracketedMemberExpression';
109
- object: ASTNode;
110
- property: string;
111
- }
112
- interface IndexExpression {
113
- type: 'IndexExpression';
114
- object: ASTNode;
115
- index: ASTNode;
116
- }
117
- interface WildcardExpression {
118
- type: 'WildcardExpression';
119
- object: ASTNode;
120
- }
121
-
122
- interface ParseResult {
123
- ast: ASTNode;
124
- dependencies: string[];
125
- features: FormulaFeature[];
126
- minVersion: FormulaMinorVersion;
127
- }
128
- declare function parseFormula(expression: string): ParseResult;
129
- declare function validateSyntax(expression: string): {
130
- isValid: true;
131
- } | {
132
- isValid: false;
133
- error: string;
134
- position?: number;
135
- };
136
- declare function evaluate(expression: string, context: Record<string, unknown>): unknown;
137
- interface EvaluateContextOptions {
138
- rootData: Record<string, unknown>;
139
- itemData?: Record<string, unknown>;
140
- currentPath?: string;
141
- }
142
- declare function evaluateWithContext(expression: string, options: EvaluateContextOptions): unknown;
143
- type InferredType = 'number' | 'boolean' | 'string' | 'unknown';
144
- interface FieldTypes {
145
- [fieldName: string]: 'number' | 'string' | 'boolean' | 'object' | 'array';
146
- }
147
- declare function inferFormulaType(expression: string, fieldTypes?: FieldTypes): InferredType;
148
-
149
- interface ParsedExpression {
150
- expression: string;
151
- dependencies: string[];
152
- minVersion: FormulaMinorVersion;
153
- features: FormulaFeature[];
154
- }
155
- declare function parseExpression(expression: string): ParsedExpression;
156
-
157
- type SyntaxValidationResult = {
158
- isValid: true;
159
- } | {
160
- isValid: false;
161
- error: string;
162
- position?: number;
163
- };
164
- declare function validateFormulaSyntax(expression: string): SyntaxValidationResult;
165
-
166
- export { type ASTNode as A, type EvaluateContextOptions as E, type FieldTypes as F, type InferredType as I, type ParseResult as P, type SyntaxValidationResult as S, type XFormula as X, evaluateWithContext as a, parseExpression as b, type ParsedExpression as c, validateFormulaSyntax as d, evaluate as e, type FormulaMinorVersion as f, type FormulaFeature as g, type FormulaAnalysis as h, inferFormulaType as i, type PathSegment as j, type ParsedPath as k, type PathValidationResult as l, type FormulaContext as m, type FormulaResult as n, parseFormula as p, validateSyntax as v };
@@ -1,166 +0,0 @@
1
- interface XFormula {
2
- version: 1;
3
- expression: string;
4
- }
5
- type FormulaMinorVersion = '1.0' | '1.1';
6
- type FormulaFeature = 'nested_path' | 'array_index' | 'array_wildcard' | 'relative_path' | 'root_path' | 'context_token' | 'array_function' | 'bracket_notation';
7
- interface FormulaAnalysis {
8
- minVersion: FormulaMinorVersion;
9
- features: FormulaFeature[];
10
- dependencies: string[];
11
- }
12
- type PathSegment = {
13
- type: 'property';
14
- name: string;
15
- } | {
16
- type: 'index';
17
- value: number;
18
- } | {
19
- type: 'wildcard';
20
- } | {
21
- type: 'parent';
22
- } | {
23
- type: 'root';
24
- } | {
25
- type: 'token';
26
- name: string;
27
- };
28
- interface ParsedPath {
29
- original: string;
30
- segments: PathSegment[];
31
- isAbsolute: boolean;
32
- isRelative: boolean;
33
- }
34
- interface PathValidationResult {
35
- isValid: boolean;
36
- error?: string;
37
- segments?: PathSegment[];
38
- }
39
- interface FormulaContext {
40
- [fieldName: string]: unknown;
41
- }
42
- type FormulaResult = number | string | boolean | null;
43
-
44
- type ASTNode = NumberLiteral | StringLiteral | BooleanLiteral | NullLiteral | Identifier | BracketedIdentifier | RootPath | RelativePath | ContextToken | BinaryOp | UnaryOp | TernaryOp | CallExpression | MemberExpression | BracketedMemberExpression | IndexExpression | WildcardExpression;
45
- interface NumberLiteral {
46
- type: 'NumberLiteral';
47
- value: number;
48
- }
49
- interface StringLiteral {
50
- type: 'StringLiteral';
51
- value: string;
52
- }
53
- interface BooleanLiteral {
54
- type: 'BooleanLiteral';
55
- value: boolean;
56
- }
57
- interface NullLiteral {
58
- type: 'NullLiteral';
59
- }
60
- interface Identifier {
61
- type: 'Identifier';
62
- name: string;
63
- }
64
- interface BracketedIdentifier {
65
- type: 'BracketedIdentifier';
66
- name: string;
67
- }
68
- interface RootPath {
69
- type: 'RootPath';
70
- path: string;
71
- }
72
- interface RelativePath {
73
- type: 'RelativePath';
74
- path: string;
75
- }
76
- interface ContextToken {
77
- type: 'ContextToken';
78
- name: string;
79
- }
80
- interface BinaryOp {
81
- type: 'BinaryOp';
82
- op: string;
83
- left: ASTNode;
84
- right: ASTNode;
85
- }
86
- interface UnaryOp {
87
- type: 'UnaryOp';
88
- op: string;
89
- argument: ASTNode;
90
- }
91
- interface TernaryOp {
92
- type: 'TernaryOp';
93
- condition: ASTNode;
94
- consequent: ASTNode;
95
- alternate: ASTNode;
96
- }
97
- interface CallExpression {
98
- type: 'CallExpression';
99
- callee: ASTNode;
100
- arguments: ASTNode[];
101
- }
102
- interface MemberExpression {
103
- type: 'MemberExpression';
104
- object: ASTNode;
105
- property: string;
106
- }
107
- interface BracketedMemberExpression {
108
- type: 'BracketedMemberExpression';
109
- object: ASTNode;
110
- property: string;
111
- }
112
- interface IndexExpression {
113
- type: 'IndexExpression';
114
- object: ASTNode;
115
- index: ASTNode;
116
- }
117
- interface WildcardExpression {
118
- type: 'WildcardExpression';
119
- object: ASTNode;
120
- }
121
-
122
- interface ParseResult {
123
- ast: ASTNode;
124
- dependencies: string[];
125
- features: FormulaFeature[];
126
- minVersion: FormulaMinorVersion;
127
- }
128
- declare function parseFormula(expression: string): ParseResult;
129
- declare function validateSyntax(expression: string): {
130
- isValid: true;
131
- } | {
132
- isValid: false;
133
- error: string;
134
- position?: number;
135
- };
136
- declare function evaluate(expression: string, context: Record<string, unknown>): unknown;
137
- interface EvaluateContextOptions {
138
- rootData: Record<string, unknown>;
139
- itemData?: Record<string, unknown>;
140
- currentPath?: string;
141
- }
142
- declare function evaluateWithContext(expression: string, options: EvaluateContextOptions): unknown;
143
- type InferredType = 'number' | 'boolean' | 'string' | 'unknown';
144
- interface FieldTypes {
145
- [fieldName: string]: 'number' | 'string' | 'boolean' | 'object' | 'array';
146
- }
147
- declare function inferFormulaType(expression: string, fieldTypes?: FieldTypes): InferredType;
148
-
149
- interface ParsedExpression {
150
- expression: string;
151
- dependencies: string[];
152
- minVersion: FormulaMinorVersion;
153
- features: FormulaFeature[];
154
- }
155
- declare function parseExpression(expression: string): ParsedExpression;
156
-
157
- type SyntaxValidationResult = {
158
- isValid: true;
159
- } | {
160
- isValid: false;
161
- error: string;
162
- position?: number;
163
- };
164
- declare function validateFormulaSyntax(expression: string): SyntaxValidationResult;
165
-
166
- export { type ASTNode as A, type EvaluateContextOptions as E, type FieldTypes as F, type InferredType as I, type ParseResult as P, type SyntaxValidationResult as S, type XFormula as X, evaluateWithContext as a, parseExpression as b, type ParsedExpression as c, validateFormulaSyntax as d, evaluate as e, type FormulaMinorVersion as f, type FormulaFeature as g, type FormulaAnalysis as h, inferFormulaType as i, type PathSegment as j, type ParsedPath as k, type PathValidationResult as l, type FormulaContext as m, type FormulaResult as n, parseFormula as p, validateSyntax as v };
package/dist/index.d.cts DELETED
@@ -1,25 +0,0 @@
1
- import { A as ASTNode } from './index-CPsOPCQ6.cjs';
2
- export { E as EvaluateContextOptions, F as FieldTypes, h as FormulaAnalysis, m as FormulaContext, g as FormulaFeature, f as FormulaMinorVersion, n as FormulaResult, I as InferredType, P as ParseResult, c as ParsedExpression, k as ParsedPath, j as PathSegment, l as PathValidationResult, S as SyntaxValidationResult, X as XFormula, e as evaluate, a as evaluateWithContext, i as inferFormulaType, b as parseExpression, p as parseFormula, d as validateFormulaSyntax, v as validateSyntax } from './index-CPsOPCQ6.cjs';
3
-
4
- declare function serializeAst(ast: ASTNode): string;
5
-
6
- declare function replaceDependencies(ast: ASTNode, replacements: Record<string, string>): ASTNode;
7
-
8
- interface DependencyGraph {
9
- nodes: Set<string>;
10
- edges: Map<string, Set<string>>;
11
- }
12
- interface CircularDependencyResult {
13
- hasCircular: boolean;
14
- cycle: string[] | null;
15
- }
16
- interface TopologicalOrderResult {
17
- success: boolean;
18
- order: string[];
19
- error?: string;
20
- }
21
- declare function buildDependencyGraph(dependencies: Record<string, string[]>): DependencyGraph;
22
- declare function detectCircularDependencies(graph: DependencyGraph): CircularDependencyResult;
23
- declare function getTopologicalOrder(graph: DependencyGraph): TopologicalOrderResult;
24
-
25
- export { ASTNode, type CircularDependencyResult, type DependencyGraph, type TopologicalOrderResult, buildDependencyGraph, detectCircularDependencies, getTopologicalOrder, replaceDependencies, serializeAst };
package/dist/index.js DELETED
@@ -1,111 +0,0 @@
1
- export { evaluate, evaluateWithContext, inferFormulaType, parseExpression, parseFormula, replaceDependencies, serializeAst, validateFormulaSyntax, validateSyntax } from './chunk-RMAHNB4D.js';
2
-
3
- // src/dependency-graph.ts
4
- function buildDependencyGraph(dependencies) {
5
- const nodes = /* @__PURE__ */ new Set();
6
- const edges = /* @__PURE__ */ new Map();
7
- for (const [node, deps] of Object.entries(dependencies)) {
8
- nodes.add(node);
9
- edges.set(node, new Set(deps));
10
- for (const dep of deps) {
11
- nodes.add(dep);
12
- }
13
- }
14
- return { nodes, edges };
15
- }
16
- function detectCircularDependencies(graph) {
17
- const visited = /* @__PURE__ */ new Set();
18
- const recursionStack = /* @__PURE__ */ new Set();
19
- const path = [];
20
- for (const node of graph.nodes) {
21
- if (!visited.has(node)) {
22
- const cycle = dfsVisit(node, graph, visited, recursionStack, path);
23
- if (cycle) {
24
- return { hasCircular: true, cycle };
25
- }
26
- }
27
- }
28
- return { hasCircular: false, cycle: null };
29
- }
30
- function dfsVisit(node, graph, visited, recursionStack, path) {
31
- visited.add(node);
32
- recursionStack.add(node);
33
- path.push(node);
34
- const deps = graph.edges.get(node);
35
- if (deps) {
36
- for (const dep of deps) {
37
- if (!visited.has(dep)) {
38
- const cycle = dfsVisit(dep, graph, visited, recursionStack, path);
39
- if (cycle) {
40
- return cycle;
41
- }
42
- } else if (recursionStack.has(dep)) {
43
- const cycleStart = path.indexOf(dep);
44
- return [...path.slice(cycleStart), dep];
45
- }
46
- }
47
- }
48
- path.pop();
49
- recursionStack.delete(node);
50
- return null;
51
- }
52
- function getTopologicalOrder(graph) {
53
- const circularCheck = detectCircularDependencies(graph);
54
- if (circularCheck.hasCircular && circularCheck.cycle) {
55
- return {
56
- success: false,
57
- order: [],
58
- error: `Circular dependency detected: ${circularCheck.cycle.join(" -> ")}`
59
- };
60
- }
61
- const inDegree = initializeInDegree(graph);
62
- const queue = findZeroInDegreeNodes(inDegree);
63
- const order = processQueue(queue, graph, inDegree);
64
- order.reverse();
65
- return { success: true, order };
66
- }
67
- function initializeInDegree(graph) {
68
- const inDegree = /* @__PURE__ */ new Map();
69
- for (const node of graph.nodes) {
70
- inDegree.set(node, 0);
71
- }
72
- for (const deps of graph.edges.values()) {
73
- for (const dep of deps) {
74
- inDegree.set(dep, (inDegree.get(dep) ?? 0) + 1);
75
- }
76
- }
77
- return inDegree;
78
- }
79
- function findZeroInDegreeNodes(inDegree) {
80
- const result = [];
81
- for (const [node, degree] of inDegree) {
82
- if (degree === 0) {
83
- result.push(node);
84
- }
85
- }
86
- return result;
87
- }
88
- function processQueue(queue, graph, inDegree) {
89
- const order = [];
90
- let head = 0;
91
- while (head < queue.length) {
92
- const node = queue[head];
93
- head++;
94
- order.push(node);
95
- const deps = graph.edges.get(node);
96
- if (deps) {
97
- for (const dep of deps) {
98
- const newDegree = (inDegree.get(dep) ?? 0) - 1;
99
- inDegree.set(dep, newDegree);
100
- if (newDegree === 0) {
101
- queue.push(dep);
102
- }
103
- }
104
- }
105
- }
106
- return order;
107
- }
108
-
109
- export { buildDependencyGraph, detectCircularDependencies, getTopologicalOrder };
110
- //# sourceMappingURL=index.js.map
111
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/dependency-graph.ts"],"names":[],"mappings":";;;AA8BO,SAAS,qBACd,YAAA,EACiB;AACjB,EAAA,MAAM,KAAA,uBAAY,GAAA,EAAY;AAC9B,EAAA,MAAM,KAAA,uBAAY,GAAA,EAAyB;AAE3C,EAAA,KAAA,MAAW,CAAC,IA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S,GAAA,CAAI,GAAG,KAAK,CAAA,IAAK,CAAA;AAC7C,QAAA,QAAA,CAAS,GAAA,CAAI,KAAK,SAAS,CAAA;AAC3B,QAAA,IAAI,cAAc,CAAA,EAAG;AACnB,UAAA,KAAA,CAAM,KAAK,GAAG,CAAA;AAAA,QAChB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,KAAA;AACT","file":"index.js","sourcesContent":["export interface DependencyGraph {\n nodes: Set<string>;\n edges: Map<string, Set<string>>;\n}\n\nexport interface CircularDependencyResult {\n hasCircular: boolean;\n cycle: string[] | null;\n}\n\nexport interface TopologicalOrderResult {\n success: boolean;\n order: string[];\n error?: string;\n}\n\n/**\n * Build a dependency graph from a dependencies map\n *\n * @param dependencies - Map of node names to their dependencies\n * @returns Dependency graph with nodes and edges\n *\n * @example\n * const graph = buildDependencyGraph({\n * tax: ['price'],\n * total: ['price', 'tax']\n * });\n * // graph.edges.get('tax') = Set(['price'])\n * // graph.edges.get('total') = Set(['price', 'tax'])\n */\nexport function buildDependencyGraph(\n dependencies: Record<string, string[]>,\n): DependencyGraph {\n const nodes = new Set<string>();\n const edges = new Map<string, Set<string>>();\n\n for (const [node, deps] of Object.entries(dependencies)) {\n nodes.add(node);\n edges.set(node, new Set(deps));\n\n for (const dep of deps) {\n nodes.add(dep);\n }\n }\n\n return { nodes, edges };\n}\n\n/**\n * Detect first circular dependency in a dependency graph\n *\n * @param graph - Dependency graph\n * @returns Result with detected cycle (null if no cycle)\n *\n * @example\n * detectCircularDependencies(graph)\n * // { hasCircular: true, cycle: ['a', 'b', 'c', 'a'] }\n */\nexport function detectCircularDependencies(\n graph: DependencyGraph,\n): CircularDependencyResult {\n const visited = new Set<string>();\n const recursionStack = new Set<string>();\n const path: string[] = [];\n\n for (const node of graph.nodes) {\n if (!visited.has(node)) {\n const cycle = dfsVisit(node, graph, visited, recursionStack, path);\n if (cycle) {\n return { hasCircular: true, cycle };\n }\n }\n }\n\n return { hasCircular: false, cycle: null };\n}\n\nfunction dfsVisit(\n node: string,\n graph: DependencyGraph,\n visited: Set<string>,\n recursionStack: Set<string>,\n path: string[],\n): string[] | null {\n visited.add(node);\n recursionStack.add(node);\n path.push(node);\n\n const deps = graph.edges.get(node);\n if (deps) {\n for (const dep of deps) {\n if (!visited.has(dep)) {\n const cycle = dfsVisit(dep, graph, visited, recursionStack, path);\n if (cycle) {\n return cycle;\n }\n } else if (recursionStack.has(dep)) {\n const cycleStart = path.indexOf(dep);\n return [...path.slice(cycleStart), dep];\n }\n }\n }\n\n path.pop();\n recursionStack.delete(node);\n return null;\n}\n\n/**\n * Get topological order for formula evaluation\n *\n * @param graph - Dependency graph\n * @returns Ordered list of field names for evaluation\n *\n * @example\n * getTopologicalOrder(graph)\n * // { success: true, order: ['price', 'tax', 'total'] }\n */\nexport function getTopologicalOrder(\n graph: DependencyGraph,\n): TopologicalOrderResult {\n const circularCheck = detectCircularDependencies(graph);\n if (circularCheck.hasCircular && circularCheck.cycle) {\n return {\n success: false,\n order: [],\n error: `Circular dependency detected: ${circularCheck.cycle.join(' -> ')}`,\n };\n }\n\n const inDegree = initializeInDegree(graph);\n const queue = findZeroInDegreeNodes(inDegree);\n const order = processQueue(queue, graph, inDegree);\n\n order.reverse();\n return { success: true, order };\n}\n\nfunction initializeInDegree(graph: DependencyGraph): Map<string, number> {\n const inDegree = new Map<string, number>();\n\n for (const node of graph.nodes) {\n inDegree.set(node, 0);\n }\n\n for (const deps of graph.edges.values()) {\n for (const dep of deps) {\n inDegree.set(dep, (inDegree.get(dep) ?? 0) + 1);\n }\n }\n\n return inDegree;\n}\n\nfunction findZeroInDegreeNodes(inDegree: Map<string, number>): string[] {\n const result: string[] = [];\n for (const [node, degree] of inDegree) {\n if (degree === 0) {\n result.push(node);\n }\n }\n return result;\n}\n\nfunction processQueue(\n queue: string[],\n graph: DependencyGraph,\n inDegree: Map<string, number>,\n): string[] {\n const order: string[] = [];\n let head = 0;\n\n while (head < queue.length) {\n const node = queue[head]!;\n head++;\n order.push(node);\n\n const deps = graph.edges.get(node);\n if (deps) {\n for (const dep of deps) {\n const newDegree = (inDegree.get(dep) ?? 0) - 1;\n inDegree.set(dep, newDegree);\n if (newDegree === 0) {\n queue.push(dep);\n }\n }\n }\n }\n\n return order;\n}\n"]}