@revisium/formula 0.1.0 → 0.1.1

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.
@@ -1,7 +1,6 @@
1
1
  interface XFormula {
2
2
  version: 1;
3
3
  expression: string;
4
- onError?: 'null' | 'default' | 'throw';
5
4
  }
6
5
  type FormulaMinorVersion = '1.0' | '1.1';
7
6
  type FormulaFeature = 'nested_path' | 'array_index' | 'array_wildcard' | 'relative_path' | 'root_path' | 'context_token' | 'array_function';
@@ -84,7 +83,6 @@ declare function validateFormulaSyntax(expression: string): SyntaxValidationResu
84
83
  interface XFormulaInput {
85
84
  version: number;
86
85
  expression: string;
87
- onError?: 'null' | 'default' | 'throw';
88
86
  }
89
87
  interface SchemaProperty {
90
88
  type?: string;
@@ -1,7 +1,6 @@
1
1
  interface XFormula {
2
2
  version: 1;
3
3
  expression: string;
4
- onError?: 'null' | 'default' | 'throw';
5
4
  }
6
5
  type FormulaMinorVersion = '1.0' | '1.1';
7
6
  type FormulaFeature = 'nested_path' | 'array_index' | 'array_wildcard' | 'relative_path' | 'root_path' | 'context_token' | 'array_function';
@@ -84,7 +83,6 @@ declare function validateFormulaSyntax(expression: string): SyntaxValidationResu
84
83
  interface XFormulaInput {
85
84
  version: number;
86
85
  expression: string;
87
- onError?: 'null' | 'default' | 'throw';
88
86
  }
89
87
  interface SchemaProperty {
90
88
  type?: string;
package/dist/index.cjs CHANGED
@@ -1,56 +1,56 @@
1
1
  'use strict';
2
2
 
3
- var chunkDJBJIFBU_cjs = require('./chunk-DJBJIFBU.cjs');
3
+ var chunkV4BMBATD_cjs = require('./chunk-V4BMBATD.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "buildDependencyGraph", {
8
8
  enumerable: true,
9
- get: function () { return chunkDJBJIFBU_cjs.buildDependencyGraph; }
9
+ get: function () { return chunkV4BMBATD_cjs.buildDependencyGraph; }
10
10
  });
11
11
  Object.defineProperty(exports, "detectCircularDependencies", {
12
12
  enumerable: true,
13
- get: function () { return chunkDJBJIFBU_cjs.detectCircularDependencies; }
13
+ get: function () { return chunkV4BMBATD_cjs.detectCircularDependencies; }
14
14
  });
15
15
  Object.defineProperty(exports, "evaluate", {
16
16
  enumerable: true,
17
- get: function () { return chunkDJBJIFBU_cjs.evaluate; }
17
+ get: function () { return chunkV4BMBATD_cjs.evaluate; }
18
18
  });
19
19
  Object.defineProperty(exports, "extractSchemaFormulas", {
20
20
  enumerable: true,
21
- get: function () { return chunkDJBJIFBU_cjs.extractSchemaFormulas; }
21
+ get: function () { return chunkV4BMBATD_cjs.extractSchemaFormulas; }
22
22
  });
23
23
  Object.defineProperty(exports, "getTopologicalOrder", {
24
24
  enumerable: true,
25
- get: function () { return chunkDJBJIFBU_cjs.getTopologicalOrder; }
25
+ get: function () { return chunkV4BMBATD_cjs.getTopologicalOrder; }
26
26
  });
27
27
  Object.defineProperty(exports, "inferFormulaType", {
28
28
  enumerable: true,
29
- get: function () { return chunkDJBJIFBU_cjs.inferFormulaType; }
29
+ get: function () { return chunkV4BMBATD_cjs.inferFormulaType; }
30
30
  });
31
31
  Object.defineProperty(exports, "parseExpression", {
32
32
  enumerable: true,
33
- get: function () { return chunkDJBJIFBU_cjs.parseExpression; }
33
+ get: function () { return chunkV4BMBATD_cjs.parseExpression; }
34
34
  });
35
35
  Object.defineProperty(exports, "parseFormula", {
36
36
  enumerable: true,
37
- get: function () { return chunkDJBJIFBU_cjs.parseFormula; }
37
+ get: function () { return chunkV4BMBATD_cjs.parseFormula; }
38
38
  });
39
39
  Object.defineProperty(exports, "validateFormulaAgainstSchema", {
40
40
  enumerable: true,
41
- get: function () { return chunkDJBJIFBU_cjs.validateFormulaAgainstSchema; }
41
+ get: function () { return chunkV4BMBATD_cjs.validateFormulaAgainstSchema; }
42
42
  });
43
43
  Object.defineProperty(exports, "validateFormulaSyntax", {
44
44
  enumerable: true,
45
- get: function () { return chunkDJBJIFBU_cjs.validateFormulaSyntax; }
45
+ get: function () { return chunkV4BMBATD_cjs.validateFormulaSyntax; }
46
46
  });
47
47
  Object.defineProperty(exports, "validateSchemaFormulas", {
48
48
  enumerable: true,
49
- get: function () { return chunkDJBJIFBU_cjs.validateSchemaFormulas; }
49
+ get: function () { return chunkV4BMBATD_cjs.validateSchemaFormulas; }
50
50
  });
51
51
  Object.defineProperty(exports, "validateSyntax", {
52
52
  enumerable: true,
53
- get: function () { return chunkDJBJIFBU_cjs.validateSyntax; }
53
+ get: function () { return chunkV4BMBATD_cjs.validateSyntax; }
54
54
  });
55
55
  //# sourceMappingURL=index.cjs.map
56
56
  //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as ASTNode, E as ExtractedFormula, F as FieldTypes, m as FormulaAnalysis, r as FormulaContext, l as FormulaFeature, k as FormulaMinorVersion, s as FormulaResult, h as FormulaValidationError, I as InferredType, J as JsonSchema, P as ParseResult, b as ParsedExpression, o as ParsedPath, n as PathSegment, q as PathValidationResult, j as SchemaValidationResult, S as SyntaxValidationResult, X as XFormula, e as evaluate, d as extractSchemaFormulas, i as inferFormulaType, a as parseExpression, p as parseFormula, f as validateFormulaAgainstSchema, c as validateFormulaSyntax, g as validateSchemaFormulas, v as validateSyntax } from './index-ChO-K1-Q.cjs';
1
+ export { A as ASTNode, E as ExtractedFormula, F as FieldTypes, m as FormulaAnalysis, r as FormulaContext, l as FormulaFeature, k as FormulaMinorVersion, s as FormulaResult, h as FormulaValidationError, I as InferredType, J as JsonSchema, P as ParseResult, b as ParsedExpression, o as ParsedPath, n as PathSegment, q as PathValidationResult, j as SchemaValidationResult, S as SyntaxValidationResult, X as XFormula, e as evaluate, d as extractSchemaFormulas, i as inferFormulaType, a as parseExpression, p as parseFormula, f as validateFormulaAgainstSchema, c as validateFormulaSyntax, g as validateSchemaFormulas, v as validateSyntax } from './index-DO2EZ7U6.cjs';
2
2
 
3
3
  interface DependencyGraph {
4
4
  nodes: Set<string>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as ASTNode, E as ExtractedFormula, F as FieldTypes, m as FormulaAnalysis, r as FormulaContext, l as FormulaFeature, k as FormulaMinorVersion, s as FormulaResult, h as FormulaValidationError, I as InferredType, J as JsonSchema, P as ParseResult, b as ParsedExpression, o as ParsedPath, n as PathSegment, q as PathValidationResult, j as SchemaValidationResult, S as SyntaxValidationResult, X as XFormula, e as evaluate, d as extractSchemaFormulas, i as inferFormulaType, a as parseExpression, p as parseFormula, f as validateFormulaAgainstSchema, c as validateFormulaSyntax, g as validateSchemaFormulas, v as validateSyntax } from './index-ChO-K1-Q.js';
1
+ export { A as ASTNode, E as ExtractedFormula, F as FieldTypes, m as FormulaAnalysis, r as FormulaContext, l as FormulaFeature, k as FormulaMinorVersion, s as FormulaResult, h as FormulaValidationError, I as InferredType, J as JsonSchema, P as ParseResult, b as ParsedExpression, o as ParsedPath, n as PathSegment, q as PathValidationResult, j as SchemaValidationResult, S as SyntaxValidationResult, X as XFormula, e as evaluate, d as extractSchemaFormulas, i as inferFormulaType, a as parseExpression, p as parseFormula, f as validateFormulaAgainstSchema, c as validateFormulaSyntax, g as validateSchemaFormulas, v as validateSyntax } from './index-DO2EZ7U6.js';
2
2
 
3
3
  interface DependencyGraph {
4
4
  nodes: Set<string>;
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { buildDependencyGraph, detectCircularDependencies, evaluate, extractSchemaFormulas, getTopologicalOrder, inferFormulaType, parseExpression, parseFormula, validateFormulaAgainstSchema, validateFormulaSyntax, validateSchemaFormulas, validateSyntax } from './chunk-N7DFRM77.js';
1
+ export { buildDependencyGraph, detectCircularDependencies, evaluate, extractSchemaFormulas, getTopologicalOrder, inferFormulaType, parseExpression, parseFormula, validateFormulaAgainstSchema, validateFormulaSyntax, validateSchemaFormulas, validateSyntax } from './chunk-5TRH7SCW.js';
2
2
  //# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revisium/formula",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Formula expression parser and evaluator for Revisium",
5
5
  "keywords": [
6
6
  "formula",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/parser.ts","../src/parse-formula.ts","../src/validate-syntax.ts","../src/dependency-graph.ts","../src/extract-schema.ts","../src/validate-schema.ts"],"names":["parseModule","token","parse","subscript"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAM,EAAE,MAAK,GAAIA,sBAAA;AAGjB,IAAM,QAAA,GAAW,CAAC,CAAA,KACf,CAAA,IAAK,MAAM,CAAA,IAAK,GAAA;AAChB,CAAA,IAAK,MAAM,CAAA,IAAK,EAAA;AAChB,CAAA,IAAK,MAAM,CAAA,IAAK,EAAA;AACjB,CAAA,KAAM,KACF,CAAA,GACA,CAAA;AAGNC,eAAA,CAAM,GAAA,EAAK,GAAA,EAAK,CAAC,CAAA,KAAe;AAC9B,EAAA,IAAI,CAAA,EAAG;AACP,EAAA,MAAM,IAAA,GAAO,KAAK,QAAQ,CAAA;AAC1B,EAAA,IAAI,CAAC,IAAA,EAAM;AACX,EAAA,OAAO,GAAA,GAAM,IAAA;AACf,CAAC,CAAA;AAGDA,eAAA,CAAM,GAAA,EAAK,GAAA,EAAK,CAAC,CAAA,KAAe;AAC9B,EAAA,IAAI,CAAA,EAAG;AACP,EAAA,MAAM,IAAA,GAAO,KAAK,QAAQ,CAAA;AAC1B,EAAA,IAAI,CAAC,IAAA,EAAM;AACX,EAAA,OAAO,GAAA,GAAM,IAAA;AACf,CAAC,CAAA;AAGD,IAAM,wBAAwB,MAAiB;AAC7C,EAAA,MAAM,MAAiB,EAAC;AACxB,EAAA,GAAA,CAAI,CAAC,CAAA,GAAI,GAAA;AACT,EAAA,OAAO,GAAA;AACT,CAAA;AAGAA,eAAA,CAAM,GAAA,EAAK,GAAA,EAAK,CAAC,CAAA,KAAe;AAC9B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C;AAEA,EAAA,MAAM,eAAyC,EAAC;AAChD,EAAA,KAAA,MAAW,WAAW,QAAA,EAAU;AAC9B,IAAA,MAAM,WAAA,GAAc,eAAA,CAAgB,OAAA,CAAQ,UAAU,CAAA;AACtD,IAAA,YAAA,CAAa,QAAQ,SAAS,CAAA,GAC5B,WAAA,CAAY,YAAA,CAAa,IAAI,gBAAgB,CAAA;AAAA,EACjD;AAEA,EAAA,MAAM,KAAA,GAAQ,qBAAqB,YAAY,CAAA;AAC/C,EAAA,MAAM,aAAA,GAAgB,2BAA2B,KAAK,CAAA;AAEtD,EAAA,MAAM,QAAQ,aAAA,CAAc,KAAA;AAC5B,EAAA,IAAI,aAAA,CAAc,WAAA,IAAe,KAAA,IAAS,KAAA,CAAM,SAAS,CAAA,EAAG;AAC1D,IAAA,MAAM,UAAA,GAAa,MAAM,CAAC,CAAA;AAC1B,IAAA,IAAI,UAAA,EAAY;AACd,MAAA,MAAA,CAAO,IAAA,CAAK;AAAA,QACV,KAAA,EAAO,UAAA;AAAA,QACP,KAAA,EAAO,CAAA,qBAAA,EAAwB,KAAA,CAAM,IAAA,CAAK,UAAK,CAAC,CAAA;AAAA,OACjD,CAAA;AACD,MAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,MAAA,EAAO;AAAA,IAClC;AAAA,EACF;AAEA,EAAA,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,MAAA,EAAQ,EAAC,EAAE;AACrC","file":"chunk-DJBJIFBU.cjs","sourcesContent":["import subscript, { parse, token } from 'subscript';\nimport { FormulaFeature, FormulaMinorVersion } from './types';\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore - subscript internal module\nimport * as parseModule from 'subscript/src/parse.js';\n\nconst { next } = parseModule as { next: (fn: (c: number) => number) => string };\n\n// Helper for identifier chars - returns 1 if valid, 0 otherwise\nconst isIdChar = (c: number): number =>\n (c >= 97 && c <= 122) || // a-z\n (c >= 65 && c <= 90) || // A-Z\n (c >= 48 && c <= 57) || // 0-9\n c === 95 // _\n ? 1\n : 0;\n\n// Register @ for context tokens (@prev, @next, @current)\ntoken('@', 200, (a: unknown) => {\n if (a) return; // must not follow another token\n const name = next(isIdChar);\n if (!name) return;\n return '@' + name;\n});\n\n// Register # for position tokens (#index, #first, #last, #length)\ntoken('#', 200, (a: unknown) => {\n if (a) return;\n const name = next(isIdChar);\n if (!name) return;\n return '#' + name;\n});\n\n// Create sparse array literal for wildcard: [, '*'] means literal value '*'\nconst createWildcardLiteral = (): unknown[] => {\n const arr: unknown[] = [];\n arr[1] = '*';\n return arr;\n};\n\n// Register * as wildcard when standalone (inside [])\ntoken('*', 200, (a: unknown) => {\n if (!a) return createWildcardLiteral();\n return undefined;\n});\n\nexport type ASTNode = string | number | boolean | null | [string, ...ASTNode[]];\n\nconst KEYWORDS = new Set([\n 'true',\n 'false',\n 'null',\n 'and',\n 'or',\n 'not',\n 'if',\n 'constructor',\n '__proto__',\n 'prototype',\n 'round',\n 'floor',\n 'ceil',\n 'abs',\n 'sqrt',\n 'pow',\n 'min',\n 'max',\n 'log',\n 'log10',\n 'exp',\n 'sign',\n 'concat',\n 'upper',\n 'lower',\n 'length',\n 'trim',\n 'left',\n 'right',\n 'replace',\n 'contains',\n 'startswith',\n 'endswith',\n 'tostring',\n 'tonumber',\n 'toboolean',\n 'isnull',\n 'coalesce',\n 'sum',\n 'avg',\n 'count',\n 'first',\n 'last',\n 'join',\n 'filter',\n 'map',\n 'includes',\n]);\n\nconst ARRAY_FUNCTIONS = new Set([\n 'sum',\n 'avg',\n 'count',\n 'first',\n 'last',\n 'join',\n 'filter',\n 'map',\n 'includes',\n]);\n\nexport interface ParseResult {\n ast: ASTNode;\n dependencies: string[];\n features: FormulaFeature[];\n minVersion: FormulaMinorVersion;\n}\n\nfunction isKeyword(name: string): boolean {\n return KEYWORDS.has(name.toLowerCase());\n}\n\nfunction isArrayFunction(name: string): boolean {\n return ARRAY_FUNCTIONS.has(name.toLowerCase());\n}\n\nfunction isContextToken(name: string): boolean {\n return name.startsWith('@') || name.startsWith('#');\n}\n\nfunction isValidIdentifierRoot(rootName: string): boolean {\n return !isKeyword(rootName) && !isContextToken(rootName);\n}\n\nfunction extractRootName(path: string): string {\n return path.split('.')[0]?.split('[')[0] ?? '';\n}\n\nfunction addPathIfValid(path: string | null, identifiers: Set<string>): void {\n if (path && isValidIdentifierRoot(extractRootName(path))) {\n identifiers.add(path);\n }\n}\n\nfunction collectStringIdentifier(node: string, identifiers: Set<string>): void {\n if (!isContextToken(node) && !isKeyword(node)) {\n identifiers.add(node);\n }\n}\n\nfunction collectFunctionCallIdentifiers(\n args: ASTNode[],\n identifiers: Set<string>,\n): void {\n for (let i = 1; i < args.length; i++) {\n collectIdentifiers(args[i] as ASTNode, identifiers);\n }\n const funcName = args[0];\n if (typeof funcName !== 'string') {\n collectIdentifiers(funcName as ASTNode, identifiers);\n }\n}\n\nfunction collectPathOrFallback(node: ASTNode, identifiers: Set<string>): void {\n const path = buildDotPath(node);\n if (path) {\n addPathIfValid(path, identifiers);\n } else {\n const [, ...args] = node as [string, ...ASTNode[]];\n for (const arg of args) {\n collectIdentifiers(arg, identifiers);\n }\n }\n}\n\nfunction collectIdentifiers(node: ASTNode, identifiers: Set<string>): void {\n if (typeof node === 'string') {\n collectStringIdentifier(node, identifiers);\n return;\n }\n\n if (!Array.isArray(node)) {\n return;\n }\n\n const [op, ...args] = node;\n\n if (op === '.' || op === '[]') {\n collectPathOrFallback(node, identifiers);\n return;\n }\n\n if (op === '()') {\n collectFunctionCallIdentifiers(args, identifiers);\n return;\n }\n\n for (const arg of args) {\n collectIdentifiers(arg, identifiers);\n }\n}\n\nfunction isLiteralArray(arr: unknown[]): boolean {\n return !(0 in arr);\n}\n\nfunction buildPropertyAccessPath(left: ASTNode, right: ASTNode): string | null {\n const leftPath = buildDotPath(left);\n const rightPath = typeof right === 'string' ? right : null;\n if (leftPath && rightPath) {\n return `${leftPath}.${rightPath}`;\n }\n return null;\n}\n\nfunction getNegativeIndexValue(index: unknown): number | null {\n if (!Array.isArray(index) || index[0] !== '-' || index.length !== 2) {\n return null;\n }\n const inner: unknown = index[1];\n if (\n Array.isArray(inner) &&\n isLiteralArray(inner) &&\n typeof inner[1] === 'number'\n ) {\n return -inner[1];\n }\n return null;\n}\n\nfunction buildArrayAccessPath(left: ASTNode, right: ASTNode): string | null {\n const leftPath = buildDotPath(left);\n if (!leftPath) {\n return null;\n }\n\n if (Array.isArray(right) && isLiteralArray(right)) {\n if (right[1] === '*') {\n return `${leftPath}[*]`;\n }\n if (typeof right[1] === 'number') {\n return `${leftPath}[${right[1]}]`;\n }\n }\n\n const negativeIndex = getNegativeIndexValue(right);\n if (negativeIndex !== null) {\n return `${leftPath}[${negativeIndex}]`;\n }\n\n const rightPath = buildDotPath(right);\n if (rightPath) {\n return `${leftPath}[${rightPath}]`;\n }\n return null;\n}\n\nfunction buildDotPath(node: ASTNode): string | null {\n if (typeof node === 'string') {\n return node;\n }\n\n if (!Array.isArray(node) || isLiteralArray(node)) {\n return null;\n }\n\n const [op, left, right] = node;\n\n if (op === '.') {\n return buildPropertyAccessPath(left as ASTNode, right as ASTNode);\n }\n\n if (op === '[]') {\n return buildArrayAccessPath(left as ASTNode, right as ASTNode);\n }\n\n return null;\n}\n\nfunction isNegativeIndexLiteral(index: unknown): boolean {\n if (!Array.isArray(index) || index[0] !== '-' || index.length !== 2) {\n return false;\n }\n const inner: unknown = index[1];\n return (\n Array.isArray(inner) &&\n isLiteralArray(inner) &&\n typeof inner[1] === 'number'\n );\n}\n\nfunction detectArrayAccessFeatures(\n index: ASTNode,\n features: Set<FormulaFeature>,\n): void {\n if (Array.isArray(index) && isLiteralArray(index)) {\n if (index[1] === '*') {\n features.add('array_wildcard');\n } else if (typeof index[1] === 'number') {\n features.add('array_index');\n }\n }\n if (isNegativeIndexLiteral(index)) {\n features.add('array_index');\n }\n}\n\nfunction detectFunctionCallFeatures(\n funcName: ASTNode,\n features: Set<FormulaFeature>,\n): void {\n if (typeof funcName === 'string' && isArrayFunction(funcName)) {\n features.add('array_function');\n }\n}\n\nfunction detectFeatures(node: ASTNode, features: Set<FormulaFeature>): void {\n if (typeof node === 'string') {\n if (isContextToken(node)) {\n features.add('context_token');\n }\n return;\n }\n\n if (!Array.isArray(node) || isLiteralArray(node)) {\n return;\n }\n\n const op = node[0];\n\n if (op === '.') {\n features.add('nested_path');\n }\n\n if (op === '[]') {\n detectArrayAccessFeatures(node[2] as ASTNode, features);\n }\n\n if (op === '()') {\n detectFunctionCallFeatures(node[1] as ASTNode, features);\n }\n\n for (let i = 1; i < node.length; i++) {\n detectFeatures(node[i] as ASTNode, features);\n }\n}\n\nexport function parseFormula(expression: string): ParseResult {\n const trimmed = expression.trim();\n if (!trimmed) {\n throw new Error('Empty expression');\n }\n\n const ast = parse(trimmed) as ASTNode;\n\n const identifiers = new Set<string>();\n collectIdentifiers(ast, identifiers);\n\n const featuresSet = new Set<FormulaFeature>();\n detectFeatures(ast, featuresSet);\n\n const features = Array.from(featuresSet);\n const minVersion: FormulaMinorVersion = features.length > 0 ? '1.1' : '1.0';\n\n return {\n ast,\n dependencies: Array.from(identifiers),\n features,\n minVersion,\n };\n}\n\nexport function validateSyntax(\n expression: string,\n): { isValid: true } | { isValid: false; error: string; position?: number } {\n const trimmed = expression.trim();\n\n if (!trimmed) {\n return { isValid: false, error: 'Empty expression' };\n }\n\n try {\n parse(trimmed);\n return { isValid: true };\n } catch (e) {\n const error = e as Error;\n const match = /at (\\d+):(\\d+)/.exec(error.message);\n const position = match\n ? Number.parseInt(match[2] ?? '0', 10) - 1\n : undefined;\n return {\n isValid: false,\n error: error.message,\n position,\n };\n }\n}\n\nexport function evaluate(\n expression: string,\n context: Record<string, unknown>,\n): unknown {\n const trimmed = expression.trim();\n if (!trimmed) {\n throw new Error('Empty expression');\n }\n const fn = subscript(trimmed);\n return fn(context);\n}\n\n/**\n * Inferred type of a formula expression\n */\nexport type InferredType = 'number' | 'boolean' | 'string' | 'unknown';\n\n/**\n * Schema field types for type inference\n */\nexport interface FieldTypes {\n [fieldName: string]: 'number' | 'string' | 'boolean' | 'object' | 'array';\n}\n\nconst ARITHMETIC_OPS = new Set(['+', '-', '*', '/', '%']);\nconst COMPARISON_OPS = new Set([\n '<',\n '>',\n '<=',\n '>=',\n '==',\n '!=',\n '===',\n '!==',\n]);\nconst LOGICAL_OPS = new Set(['&&', '||', '!', 'and', 'or', 'not']);\nconst NUMERIC_FUNCTIONS = new Set([\n 'round',\n 'floor',\n 'ceil',\n 'abs',\n 'sqrt',\n 'pow',\n 'min',\n 'max',\n 'log',\n 'log10',\n 'exp',\n 'sign',\n 'sum',\n 'avg',\n 'count',\n 'tonumber',\n]);\nconst STRING_FUNCTIONS = new Set([\n 'concat',\n 'upper',\n 'lower',\n 'trim',\n 'left',\n 'right',\n 'replace',\n 'tostring',\n 'join',\n]);\nconst BOOLEAN_FUNCTIONS = new Set([\n 'contains',\n 'startswith',\n 'endswith',\n 'isnull',\n 'toboolean',\n 'includes',\n]);\n\nfunction getFieldType(path: string, fieldTypes: FieldTypes): InferredType {\n const rootField = path.split('.')[0]?.split('[')[0] || path;\n const schemaType = fieldTypes[rootField];\n if (schemaType === 'number') return 'number';\n if (schemaType === 'string') return 'string';\n if (schemaType === 'boolean') return 'boolean';\n return 'unknown';\n}\n\nfunction inferPrimitiveType(\n node: ASTNode,\n fieldTypes: FieldTypes,\n): InferredType | null {\n if (typeof node === 'number') return 'number';\n if (typeof node === 'boolean') return 'boolean';\n if (typeof node === 'string') return getFieldType(node, fieldTypes);\n if (node === null) return 'unknown';\n return null;\n}\n\nfunction inferLiteralArrayType(node: unknown[]): InferredType {\n const val = node[1];\n if (typeof val === 'number') return 'number';\n if (typeof val === 'string') return 'string';\n if (typeof val === 'boolean') return 'boolean';\n return 'unknown';\n}\n\nfunction inferOperatorType(\n op: string,\n argsLength: number,\n): InferredType | null {\n if (ARITHMETIC_OPS.has(op)) return 'number';\n if (COMPARISON_OPS.has(op)) return 'boolean';\n if (LOGICAL_OPS.has(op)) return 'boolean';\n if (op === '-' && argsLength === 1) return 'number';\n return null;\n}\n\nfunction inferPropertyAccessType(\n node: ASTNode,\n fieldTypes: FieldTypes,\n): InferredType {\n const path = buildDotPath(node);\n return path ? getFieldType(path, fieldTypes) : 'unknown';\n}\n\nfunction inferFunctionCallType(funcName: ASTNode): InferredType {\n if (typeof funcName !== 'string') return 'unknown';\n const lowerName = funcName.toLowerCase();\n if (NUMERIC_FUNCTIONS.has(lowerName)) return 'number';\n if (STRING_FUNCTIONS.has(lowerName)) return 'string';\n if (BOOLEAN_FUNCTIONS.has(lowerName)) return 'boolean';\n return 'unknown';\n}\n\nfunction inferTypeFromNode(\n node: ASTNode,\n fieldTypes: FieldTypes,\n): InferredType {\n const primitiveType = inferPrimitiveType(node, fieldTypes);\n if (primitiveType !== null) return primitiveType;\n\n if (!Array.isArray(node)) return 'unknown';\n if (isLiteralArray(node)) return inferLiteralArrayType(node);\n\n const [op, ...args] = node;\n\n const operatorType = inferOperatorType(op, args.length);\n if (operatorType !== null) return operatorType;\n\n if (op === '.' || op === '[]') {\n return inferPropertyAccessType(node, fieldTypes);\n }\n\n if (op === '()') {\n return inferFunctionCallType(args[0] as ASTNode);\n }\n\n return 'unknown';\n}\n\n/**\n * Infer the return type of a formula expression\n *\n * @param expression - Formula expression string\n * @param fieldTypes - Map of field names to their types from schema\n * @returns Inferred type of the expression result\n *\n * @example\n * inferFormulaType('price * quantity', { price: 'number', quantity: 'number' })\n * // 'number'\n *\n * inferFormulaType('price > 100', { price: 'number' })\n * // 'boolean'\n *\n * inferFormulaType('name', { name: 'string' })\n * // 'string'\n */\nexport function inferFormulaType(\n expression: string,\n fieldTypes: FieldTypes = {},\n): InferredType {\n const trimmed = expression.trim();\n if (!trimmed) {\n return 'unknown';\n }\n\n try {\n const ast = parse(trimmed) as ASTNode;\n return inferTypeFromNode(ast, fieldTypes);\n } catch {\n return 'unknown';\n }\n}\n\nexport { parse, compile } from 'subscript';\n","import { FormulaFeature, FormulaMinorVersion } from './types';\nimport { parseFormula } from './parser';\n\nexport interface ParsedExpression {\n expression: string;\n dependencies: string[];\n minVersion: FormulaMinorVersion;\n features: FormulaFeature[];\n}\n\n/**\n * Parse a formula expression string\n *\n * @param expression - Formula expression string\n * @returns Parsed expression with dependencies and version info\n *\n * @example\n * parseExpression('price * 1.1')\n * // { expression: 'price * 1.1', dependencies: ['price'], minVersion: '1.0', features: [] }\n *\n * parseExpression('stats.damage * multiplier')\n * // { expression: '...', dependencies: ['stats.damage', 'multiplier'], minVersion: '1.1', features: ['nested_path'] }\n */\nexport function parseExpression(expression: string): ParsedExpression {\n const result = parseFormula(expression);\n return {\n expression,\n dependencies: result.dependencies,\n minVersion: result.minVersion,\n features: result.features,\n };\n}\n","import { validateSyntax } from './parser';\n\nexport type SyntaxValidationResult =\n | { isValid: true }\n | { isValid: false; error: string; position?: number };\n\n/**\n * Validate formula expression syntax\n *\n * @param expression - Formula expression string\n * @returns Validation result with error details if invalid\n *\n * @example\n * validateFormulaSyntax('price * 1.1')\n * // { isValid: true }\n *\n * validateFormulaSyntax('price * (1.1')\n * // { isValid: false, error: 'Unclosed (', position: 8 }\n */\nexport function validateFormulaSyntax(\n expression: string,\n): SyntaxValidationResult {\n const result = validateSyntax(expression);\n\n if (result.isValid) {\n return { isValid: true };\n }\n\n return {\n isValid: false,\n error: result.error,\n position: result.position,\n };\n}\n","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","interface XFormulaInput {\n version: number;\n expression: string;\n onError?: 'null' | 'default' | 'throw';\n}\n\ninterface SchemaProperty {\n type?: string;\n 'x-formula'?: XFormulaInput;\n [key: string]: unknown;\n}\n\nexport interface JsonSchema {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n [key: string]: unknown;\n}\n\nexport interface ExtractedFormula {\n fieldName: string;\n expression: string;\n fieldType: string;\n}\n\n/**\n * Extract formula definitions from a JSON Schema\n *\n * @param schema - JSON Schema object with properties\n * @returns Array of extracted formulas with field names and expressions\n *\n * @example\n * extractSchemaFormulas({\n * type: 'object',\n * properties: {\n * price: { type: 'number' },\n * tax: { type: 'number', 'x-formula': { version: 1, expression: 'price * 0.1' } }\n * }\n * });\n * // [{ fieldName: 'tax', expression: 'price * 0.1', fieldType: 'number' }]\n */\nexport function extractSchemaFormulas(schema: JsonSchema): ExtractedFormula[] {\n const formulas: ExtractedFormula[] = [];\n const properties = schema.properties ?? {};\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n const xFormula = fieldSchema['x-formula'];\n if (xFormula) {\n formulas.push({\n fieldName,\n expression: xFormula.expression,\n fieldType: fieldSchema.type ?? 'string',\n });\n }\n }\n\n return formulas;\n}\n","import { parseExpression } from './parse-formula';\nimport { validateFormulaSyntax } from './validate-syntax';\nimport { extractSchemaFormulas, JsonSchema } from './extract-schema';\nimport {\n buildDependencyGraph,\n detectCircularDependencies,\n} from './dependency-graph';\nimport { inferFormulaType, FieldTypes, InferredType } from './parser';\n\nexport interface FormulaValidationError {\n field: string;\n error: string;\n position?: number;\n}\n\nexport interface SchemaValidationResult {\n isValid: boolean;\n errors: FormulaValidationError[];\n}\n\nfunction getSchemaFields(schema: JsonSchema): Set<string> {\n const fields = new Set<string>();\n const properties = schema.properties ?? {};\n\n for (const fieldName of Object.keys(properties)) {\n fields.add(fieldName);\n }\n\n return fields;\n}\n\nfunction getSchemaFieldTypes(schema: JsonSchema): FieldTypes {\n const fieldTypes: FieldTypes = {};\n const properties = schema.properties ?? {};\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n const schemaType = fieldSchema.type;\n if (\n schemaType === 'number' ||\n schemaType === 'string' ||\n schemaType === 'boolean' ||\n schemaType === 'object' ||\n schemaType === 'array'\n ) {\n fieldTypes[fieldName] = schemaType;\n }\n }\n\n return fieldTypes;\n}\n\nfunction schemaTypeToInferred(\n schemaType: string | undefined,\n): InferredType | null {\n if (schemaType === 'number') return 'number';\n if (schemaType === 'string') return 'string';\n if (schemaType === 'boolean') return 'boolean';\n return null;\n}\n\nfunction isTypeCompatible(\n inferredType: InferredType,\n expectedType: InferredType | null,\n): boolean {\n if (expectedType === null) return true;\n if (inferredType === 'unknown') return true;\n return inferredType === expectedType;\n}\n\nfunction extractFieldRoot(dependency: string): string {\n const root = dependency.split('.')[0]?.split('[')[0];\n return root || dependency;\n}\n\nexport function validateFormulaAgainstSchema(\n expression: string,\n fieldName: string,\n schema: JsonSchema,\n): FormulaValidationError | null {\n const syntaxResult = validateFormulaSyntax(expression);\n if (!syntaxResult.isValid) {\n return {\n field: fieldName,\n error: syntaxResult.error,\n position: syntaxResult.position,\n };\n }\n\n const parseResult = parseExpression(expression);\n const schemaFields = getSchemaFields(schema);\n\n for (const dep of parseResult.dependencies) {\n const rootField = extractFieldRoot(dep);\n if (!schemaFields.has(rootField)) {\n return {\n field: fieldName,\n error: `Unknown field '${rootField}' in formula`,\n };\n }\n }\n\n if (parseResult.dependencies.some((d) => extractFieldRoot(d) === fieldName)) {\n return {\n field: fieldName,\n error: `Formula cannot reference itself`,\n };\n }\n\n const fieldSchema = schema.properties?.[fieldName];\n const expectedType = schemaTypeToInferred(fieldSchema?.type);\n const fieldTypes = getSchemaFieldTypes(schema);\n const inferredType = inferFormulaType(expression, fieldTypes);\n\n if (!isTypeCompatible(inferredType, expectedType)) {\n return {\n field: fieldName,\n error: `Type mismatch: formula returns '${inferredType}' but field expects '${expectedType}'`,\n };\n }\n\n return null;\n}\n\nexport function validateSchemaFormulas(\n schema: JsonSchema,\n): SchemaValidationResult {\n const errors: FormulaValidationError[] = [];\n const formulas = extractSchemaFormulas(schema);\n\n for (const formula of formulas) {\n const error = validateFormulaAgainstSchema(\n formula.expression,\n formula.fieldName,\n schema,\n );\n if (error) {\n errors.push(error);\n }\n }\n\n if (errors.length > 0) {\n return { isValid: false, errors };\n }\n\n const dependencies: Record<string, string[]> = {};\n for (const formula of formulas) {\n const parseResult = parseExpression(formula.expression);\n dependencies[formula.fieldName] =\n parseResult.dependencies.map(extractFieldRoot);\n }\n\n const graph = buildDependencyGraph(dependencies);\n const circularCheck = detectCircularDependencies(graph);\n\n const cycle = circularCheck.cycle;\n if (circularCheck.hasCircular && cycle && cycle.length > 0) {\n const firstField = cycle[0];\n if (firstField) {\n errors.push({\n field: firstField,\n error: `Circular dependency: ${cycle.join(' → ')}`,\n });\n return { isValid: false, errors };\n }\n }\n\n return { isValid: true, errors: [] };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/parser.ts","../src/parse-formula.ts","../src/validate-syntax.ts","../src/dependency-graph.ts","../src/extract-schema.ts","../src/validate-schema.ts"],"names":[],"mappings":";;;;AAOA,IAAM,EAAE,MAAK,GAAI,WAAA;AAGjB,IAAM,QAAA,GAAW,CAAC,CAAA,KACf,CAAA,IAAK,MAAM,CAAA,IAAK,GAAA;AAChB,CAAA,IAAK,MAAM,CAAA,IAAK,EAAA;AAChB,CAAA,IAAK,MAAM,CAAA,IAAK,EAAA;AACjB,CAAA,KAAM,KACF,CAAA,GACA,CAAA;AAGN,KAAA,CAAM,GAAA,EAAK,GAAA,EAAK,CAAC,CAAA,KAAe;AAC9B,EAAA,IAAI,CAAA,EAAG;AACP,EAAA,MAAM,IAAA,GAAO,KAAK,QAAQ,CAAA;AAC1B,EAAA,IAAI,CAAC,IAAA,EAAM;AACX,EAAA,OAAO,GAAA,GAAM,IAAA;AACf,CAAC,CAAA;AAGD,KAAA,CAAM,GAAA,EAAK,GAAA,EAAK,CAAC,CAAA,KAAe;AAC9B,EAAA,IAAI,CAAA,EAAG;AACP,EAAA,MAAM,IAAA,GAAO,KAAK,QAAQ,CAAA;AAC1B,EAAA,IAAI,CAAC,IAAA,EAAM;AACX,EAAA,OAAO,GAAA,GAAM,IAAA;AACf,CAAC,CAAA;AAGD,IAAM,wBAAwB,MAAiB;AAC7C,EAAA,MAAM,MAAiB,EAAC;AACxB,EAAA,GAAA,CAAI,CAAC,CAAA,GAAI,GAAA;AACT,EAAA,OAAO,GAAA;AACT,CAAA;AAGA,KAAA,CAAM,GAAA,EAAK,GAAA,EAAK,CAAC,CAAA,KAAe;AAC9B,EAAA,IAAI,CAAC,CAAA,EAAG,OAAO,qBAAA,EAAsB;AACrC,EAAA,OAAO,MA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B,IAAA,MAAM,WAAA,GAAc,eAAA,CAAgB,OAAA,CAAQ,UAAU,CAAA;AACtD,IAAA,YAAA,CAAa,QAAQ,SAAS,CAAA,GAC5B,WAAA,CAAY,YAAA,CAAa,IAAI,gBAAgB,CAAA;AAAA,EACjD;AAEA,EAAA,MAAM,KAAA,GAAQ,qBAAqB,YAAY,CAAA;AAC/C,EAAA,MAAM,aAAA,GAAgB,2BAA2B,KAAK,CAAA;AAEtD,EAAA,MAAM,QAAQ,aAAA,CAAc,KAAA;AAC5B,EAAA,IAAI,aAAA,CAAc,WAAA,IAAe,KAAA,IAAS,KAAA,CAAM,SAAS,CAAA,EAAG;AAC1D,IAAA,MAAM,UAAA,GAAa,MAAM,CAAC,CAAA;AAC1B,IAAA,IAAI,UAAA,EAAY;AACd,MAAA,MAAA,CAAO,IAAA,CAAK;AAAA,QACV,KAAA,EAAO,UAAA;AAAA,QACP,KAAA,EAAO,CAAA,qBAAA,EAAwB,KAAA,CAAM,IAAA,CAAK,UAAK,CAAC,CAAA;AAAA,OACjD,CAAA;AACD,MAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,MAAA,EAAO;AAAA,IAClC;AAAA,EACF;AAEA,EAAA,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,MAAA,EAAQ,EAAC,EAAE;AACrC","file":"chunk-N7DFRM77.js","sourcesContent":["import subscript, { parse, token } from 'subscript';\nimport { FormulaFeature, FormulaMinorVersion } from './types';\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore - subscript internal module\nimport * as parseModule from 'subscript/src/parse.js';\n\nconst { next } = parseModule as { next: (fn: (c: number) => number) => string };\n\n// Helper for identifier chars - returns 1 if valid, 0 otherwise\nconst isIdChar = (c: number): number =>\n (c >= 97 && c <= 122) || // a-z\n (c >= 65 && c <= 90) || // A-Z\n (c >= 48 && c <= 57) || // 0-9\n c === 95 // _\n ? 1\n : 0;\n\n// Register @ for context tokens (@prev, @next, @current)\ntoken('@', 200, (a: unknown) => {\n if (a) return; // must not follow another token\n const name = next(isIdChar);\n if (!name) return;\n return '@' + name;\n});\n\n// Register # for position tokens (#index, #first, #last, #length)\ntoken('#', 200, (a: unknown) => {\n if (a) return;\n const name = next(isIdChar);\n if (!name) return;\n return '#' + name;\n});\n\n// Create sparse array literal for wildcard: [, '*'] means literal value '*'\nconst createWildcardLiteral = (): unknown[] => {\n const arr: unknown[] = [];\n arr[1] = '*';\n return arr;\n};\n\n// Register * as wildcard when standalone (inside [])\ntoken('*', 200, (a: unknown) => {\n if (!a) return createWildcardLiteral();\n return undefined;\n});\n\nexport type ASTNode = string | number | boolean | null | [string, ...ASTNode[]];\n\nconst KEYWORDS = new Set([\n 'true',\n 'false',\n 'null',\n 'and',\n 'or',\n 'not',\n 'if',\n 'constructor',\n '__proto__',\n 'prototype',\n 'round',\n 'floor',\n 'ceil',\n 'abs',\n 'sqrt',\n 'pow',\n 'min',\n 'max',\n 'log',\n 'log10',\n 'exp',\n 'sign',\n 'concat',\n 'upper',\n 'lower',\n 'length',\n 'trim',\n 'left',\n 'right',\n 'replace',\n 'contains',\n 'startswith',\n 'endswith',\n 'tostring',\n 'tonumber',\n 'toboolean',\n 'isnull',\n 'coalesce',\n 'sum',\n 'avg',\n 'count',\n 'first',\n 'last',\n 'join',\n 'filter',\n 'map',\n 'includes',\n]);\n\nconst ARRAY_FUNCTIONS = new Set([\n 'sum',\n 'avg',\n 'count',\n 'first',\n 'last',\n 'join',\n 'filter',\n 'map',\n 'includes',\n]);\n\nexport interface ParseResult {\n ast: ASTNode;\n dependencies: string[];\n features: FormulaFeature[];\n minVersion: FormulaMinorVersion;\n}\n\nfunction isKeyword(name: string): boolean {\n return KEYWORDS.has(name.toLowerCase());\n}\n\nfunction isArrayFunction(name: string): boolean {\n return ARRAY_FUNCTIONS.has(name.toLowerCase());\n}\n\nfunction isContextToken(name: string): boolean {\n return name.startsWith('@') || name.startsWith('#');\n}\n\nfunction isValidIdentifierRoot(rootName: string): boolean {\n return !isKeyword(rootName) && !isContextToken(rootName);\n}\n\nfunction extractRootName(path: string): string {\n return path.split('.')[0]?.split('[')[0] ?? '';\n}\n\nfunction addPathIfValid(path: string | null, identifiers: Set<string>): void {\n if (path && isValidIdentifierRoot(extractRootName(path))) {\n identifiers.add(path);\n }\n}\n\nfunction collectStringIdentifier(node: string, identifiers: Set<string>): void {\n if (!isContextToken(node) && !isKeyword(node)) {\n identifiers.add(node);\n }\n}\n\nfunction collectFunctionCallIdentifiers(\n args: ASTNode[],\n identifiers: Set<string>,\n): void {\n for (let i = 1; i < args.length; i++) {\n collectIdentifiers(args[i] as ASTNode, identifiers);\n }\n const funcName = args[0];\n if (typeof funcName !== 'string') {\n collectIdentifiers(funcName as ASTNode, identifiers);\n }\n}\n\nfunction collectPathOrFallback(node: ASTNode, identifiers: Set<string>): void {\n const path = buildDotPath(node);\n if (path) {\n addPathIfValid(path, identifiers);\n } else {\n const [, ...args] = node as [string, ...ASTNode[]];\n for (const arg of args) {\n collectIdentifiers(arg, identifiers);\n }\n }\n}\n\nfunction collectIdentifiers(node: ASTNode, identifiers: Set<string>): void {\n if (typeof node === 'string') {\n collectStringIdentifier(node, identifiers);\n return;\n }\n\n if (!Array.isArray(node)) {\n return;\n }\n\n const [op, ...args] = node;\n\n if (op === '.' || op === '[]') {\n collectPathOrFallback(node, identifiers);\n return;\n }\n\n if (op === '()') {\n collectFunctionCallIdentifiers(args, identifiers);\n return;\n }\n\n for (const arg of args) {\n collectIdentifiers(arg, identifiers);\n }\n}\n\nfunction isLiteralArray(arr: unknown[]): boolean {\n return !(0 in arr);\n}\n\nfunction buildPropertyAccessPath(left: ASTNode, right: ASTNode): string | null {\n const leftPath = buildDotPath(left);\n const rightPath = typeof right === 'string' ? right : null;\n if (leftPath && rightPath) {\n return `${leftPath}.${rightPath}`;\n }\n return null;\n}\n\nfunction getNegativeIndexValue(index: unknown): number | null {\n if (!Array.isArray(index) || index[0] !== '-' || index.length !== 2) {\n return null;\n }\n const inner: unknown = index[1];\n if (\n Array.isArray(inner) &&\n isLiteralArray(inner) &&\n typeof inner[1] === 'number'\n ) {\n return -inner[1];\n }\n return null;\n}\n\nfunction buildArrayAccessPath(left: ASTNode, right: ASTNode): string | null {\n const leftPath = buildDotPath(left);\n if (!leftPath) {\n return null;\n }\n\n if (Array.isArray(right) && isLiteralArray(right)) {\n if (right[1] === '*') {\n return `${leftPath}[*]`;\n }\n if (typeof right[1] === 'number') {\n return `${leftPath}[${right[1]}]`;\n }\n }\n\n const negativeIndex = getNegativeIndexValue(right);\n if (negativeIndex !== null) {\n return `${leftPath}[${negativeIndex}]`;\n }\n\n const rightPath = buildDotPath(right);\n if (rightPath) {\n return `${leftPath}[${rightPath}]`;\n }\n return null;\n}\n\nfunction buildDotPath(node: ASTNode): string | null {\n if (typeof node === 'string') {\n return node;\n }\n\n if (!Array.isArray(node) || isLiteralArray(node)) {\n return null;\n }\n\n const [op, left, right] = node;\n\n if (op === '.') {\n return buildPropertyAccessPath(left as ASTNode, right as ASTNode);\n }\n\n if (op === '[]') {\n return buildArrayAccessPath(left as ASTNode, right as ASTNode);\n }\n\n return null;\n}\n\nfunction isNegativeIndexLiteral(index: unknown): boolean {\n if (!Array.isArray(index) || index[0] !== '-' || index.length !== 2) {\n return false;\n }\n const inner: unknown = index[1];\n return (\n Array.isArray(inner) &&\n isLiteralArray(inner) &&\n typeof inner[1] === 'number'\n );\n}\n\nfunction detectArrayAccessFeatures(\n index: ASTNode,\n features: Set<FormulaFeature>,\n): void {\n if (Array.isArray(index) && isLiteralArray(index)) {\n if (index[1] === '*') {\n features.add('array_wildcard');\n } else if (typeof index[1] === 'number') {\n features.add('array_index');\n }\n }\n if (isNegativeIndexLiteral(index)) {\n features.add('array_index');\n }\n}\n\nfunction detectFunctionCallFeatures(\n funcName: ASTNode,\n features: Set<FormulaFeature>,\n): void {\n if (typeof funcName === 'string' && isArrayFunction(funcName)) {\n features.add('array_function');\n }\n}\n\nfunction detectFeatures(node: ASTNode, features: Set<FormulaFeature>): void {\n if (typeof node === 'string') {\n if (isContextToken(node)) {\n features.add('context_token');\n }\n return;\n }\n\n if (!Array.isArray(node) || isLiteralArray(node)) {\n return;\n }\n\n const op = node[0];\n\n if (op === '.') {\n features.add('nested_path');\n }\n\n if (op === '[]') {\n detectArrayAccessFeatures(node[2] as ASTNode, features);\n }\n\n if (op === '()') {\n detectFunctionCallFeatures(node[1] as ASTNode, features);\n }\n\n for (let i = 1; i < node.length; i++) {\n detectFeatures(node[i] as ASTNode, features);\n }\n}\n\nexport function parseFormula(expression: string): ParseResult {\n const trimmed = expression.trim();\n if (!trimmed) {\n throw new Error('Empty expression');\n }\n\n const ast = parse(trimmed) as ASTNode;\n\n const identifiers = new Set<string>();\n collectIdentifiers(ast, identifiers);\n\n const featuresSet = new Set<FormulaFeature>();\n detectFeatures(ast, featuresSet);\n\n const features = Array.from(featuresSet);\n const minVersion: FormulaMinorVersion = features.length > 0 ? '1.1' : '1.0';\n\n return {\n ast,\n dependencies: Array.from(identifiers),\n features,\n minVersion,\n };\n}\n\nexport function validateSyntax(\n expression: string,\n): { isValid: true } | { isValid: false; error: string; position?: number } {\n const trimmed = expression.trim();\n\n if (!trimmed) {\n return { isValid: false, error: 'Empty expression' };\n }\n\n try {\n parse(trimmed);\n return { isValid: true };\n } catch (e) {\n const error = e as Error;\n const match = /at (\\d+):(\\d+)/.exec(error.message);\n const position = match\n ? Number.parseInt(match[2] ?? '0', 10) - 1\n : undefined;\n return {\n isValid: false,\n error: error.message,\n position,\n };\n }\n}\n\nexport function evaluate(\n expression: string,\n context: Record<string, unknown>,\n): unknown {\n const trimmed = expression.trim();\n if (!trimmed) {\n throw new Error('Empty expression');\n }\n const fn = subscript(trimmed);\n return fn(context);\n}\n\n/**\n * Inferred type of a formula expression\n */\nexport type InferredType = 'number' | 'boolean' | 'string' | 'unknown';\n\n/**\n * Schema field types for type inference\n */\nexport interface FieldTypes {\n [fieldName: string]: 'number' | 'string' | 'boolean' | 'object' | 'array';\n}\n\nconst ARITHMETIC_OPS = new Set(['+', '-', '*', '/', '%']);\nconst COMPARISON_OPS = new Set([\n '<',\n '>',\n '<=',\n '>=',\n '==',\n '!=',\n '===',\n '!==',\n]);\nconst LOGICAL_OPS = new Set(['&&', '||', '!', 'and', 'or', 'not']);\nconst NUMERIC_FUNCTIONS = new Set([\n 'round',\n 'floor',\n 'ceil',\n 'abs',\n 'sqrt',\n 'pow',\n 'min',\n 'max',\n 'log',\n 'log10',\n 'exp',\n 'sign',\n 'sum',\n 'avg',\n 'count',\n 'tonumber',\n]);\nconst STRING_FUNCTIONS = new Set([\n 'concat',\n 'upper',\n 'lower',\n 'trim',\n 'left',\n 'right',\n 'replace',\n 'tostring',\n 'join',\n]);\nconst BOOLEAN_FUNCTIONS = new Set([\n 'contains',\n 'startswith',\n 'endswith',\n 'isnull',\n 'toboolean',\n 'includes',\n]);\n\nfunction getFieldType(path: string, fieldTypes: FieldTypes): InferredType {\n const rootField = path.split('.')[0]?.split('[')[0] || path;\n const schemaType = fieldTypes[rootField];\n if (schemaType === 'number') return 'number';\n if (schemaType === 'string') return 'string';\n if (schemaType === 'boolean') return 'boolean';\n return 'unknown';\n}\n\nfunction inferPrimitiveType(\n node: ASTNode,\n fieldTypes: FieldTypes,\n): InferredType | null {\n if (typeof node === 'number') return 'number';\n if (typeof node === 'boolean') return 'boolean';\n if (typeof node === 'string') return getFieldType(node, fieldTypes);\n if (node === null) return 'unknown';\n return null;\n}\n\nfunction inferLiteralArrayType(node: unknown[]): InferredType {\n const val = node[1];\n if (typeof val === 'number') return 'number';\n if (typeof val === 'string') return 'string';\n if (typeof val === 'boolean') return 'boolean';\n return 'unknown';\n}\n\nfunction inferOperatorType(\n op: string,\n argsLength: number,\n): InferredType | null {\n if (ARITHMETIC_OPS.has(op)) return 'number';\n if (COMPARISON_OPS.has(op)) return 'boolean';\n if (LOGICAL_OPS.has(op)) return 'boolean';\n if (op === '-' && argsLength === 1) return 'number';\n return null;\n}\n\nfunction inferPropertyAccessType(\n node: ASTNode,\n fieldTypes: FieldTypes,\n): InferredType {\n const path = buildDotPath(node);\n return path ? getFieldType(path, fieldTypes) : 'unknown';\n}\n\nfunction inferFunctionCallType(funcName: ASTNode): InferredType {\n if (typeof funcName !== 'string') return 'unknown';\n const lowerName = funcName.toLowerCase();\n if (NUMERIC_FUNCTIONS.has(lowerName)) return 'number';\n if (STRING_FUNCTIONS.has(lowerName)) return 'string';\n if (BOOLEAN_FUNCTIONS.has(lowerName)) return 'boolean';\n return 'unknown';\n}\n\nfunction inferTypeFromNode(\n node: ASTNode,\n fieldTypes: FieldTypes,\n): InferredType {\n const primitiveType = inferPrimitiveType(node, fieldTypes);\n if (primitiveType !== null) return primitiveType;\n\n if (!Array.isArray(node)) return 'unknown';\n if (isLiteralArray(node)) return inferLiteralArrayType(node);\n\n const [op, ...args] = node;\n\n const operatorType = inferOperatorType(op, args.length);\n if (operatorType !== null) return operatorType;\n\n if (op === '.' || op === '[]') {\n return inferPropertyAccessType(node, fieldTypes);\n }\n\n if (op === '()') {\n return inferFunctionCallType(args[0] as ASTNode);\n }\n\n return 'unknown';\n}\n\n/**\n * Infer the return type of a formula expression\n *\n * @param expression - Formula expression string\n * @param fieldTypes - Map of field names to their types from schema\n * @returns Inferred type of the expression result\n *\n * @example\n * inferFormulaType('price * quantity', { price: 'number', quantity: 'number' })\n * // 'number'\n *\n * inferFormulaType('price > 100', { price: 'number' })\n * // 'boolean'\n *\n * inferFormulaType('name', { name: 'string' })\n * // 'string'\n */\nexport function inferFormulaType(\n expression: string,\n fieldTypes: FieldTypes = {},\n): InferredType {\n const trimmed = expression.trim();\n if (!trimmed) {\n return 'unknown';\n }\n\n try {\n const ast = parse(trimmed) as ASTNode;\n return inferTypeFromNode(ast, fieldTypes);\n } catch {\n return 'unknown';\n }\n}\n\nexport { parse, compile } from 'subscript';\n","import { FormulaFeature, FormulaMinorVersion } from './types';\nimport { parseFormula } from './parser';\n\nexport interface ParsedExpression {\n expression: string;\n dependencies: string[];\n minVersion: FormulaMinorVersion;\n features: FormulaFeature[];\n}\n\n/**\n * Parse a formula expression string\n *\n * @param expression - Formula expression string\n * @returns Parsed expression with dependencies and version info\n *\n * @example\n * parseExpression('price * 1.1')\n * // { expression: 'price * 1.1', dependencies: ['price'], minVersion: '1.0', features: [] }\n *\n * parseExpression('stats.damage * multiplier')\n * // { expression: '...', dependencies: ['stats.damage', 'multiplier'], minVersion: '1.1', features: ['nested_path'] }\n */\nexport function parseExpression(expression: string): ParsedExpression {\n const result = parseFormula(expression);\n return {\n expression,\n dependencies: result.dependencies,\n minVersion: result.minVersion,\n features: result.features,\n };\n}\n","import { validateSyntax } from './parser';\n\nexport type SyntaxValidationResult =\n | { isValid: true }\n | { isValid: false; error: string; position?: number };\n\n/**\n * Validate formula expression syntax\n *\n * @param expression - Formula expression string\n * @returns Validation result with error details if invalid\n *\n * @example\n * validateFormulaSyntax('price * 1.1')\n * // { isValid: true }\n *\n * validateFormulaSyntax('price * (1.1')\n * // { isValid: false, error: 'Unclosed (', position: 8 }\n */\nexport function validateFormulaSyntax(\n expression: string,\n): SyntaxValidationResult {\n const result = validateSyntax(expression);\n\n if (result.isValid) {\n return { isValid: true };\n }\n\n return {\n isValid: false,\n error: result.error,\n position: result.position,\n };\n}\n","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","interface XFormulaInput {\n version: number;\n expression: string;\n onError?: 'null' | 'default' | 'throw';\n}\n\ninterface SchemaProperty {\n type?: string;\n 'x-formula'?: XFormulaInput;\n [key: string]: unknown;\n}\n\nexport interface JsonSchema {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n [key: string]: unknown;\n}\n\nexport interface ExtractedFormula {\n fieldName: string;\n expression: string;\n fieldType: string;\n}\n\n/**\n * Extract formula definitions from a JSON Schema\n *\n * @param schema - JSON Schema object with properties\n * @returns Array of extracted formulas with field names and expressions\n *\n * @example\n * extractSchemaFormulas({\n * type: 'object',\n * properties: {\n * price: { type: 'number' },\n * tax: { type: 'number', 'x-formula': { version: 1, expression: 'price * 0.1' } }\n * }\n * });\n * // [{ fieldName: 'tax', expression: 'price * 0.1', fieldType: 'number' }]\n */\nexport function extractSchemaFormulas(schema: JsonSchema): ExtractedFormula[] {\n const formulas: ExtractedFormula[] = [];\n const properties = schema.properties ?? {};\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n const xFormula = fieldSchema['x-formula'];\n if (xFormula) {\n formulas.push({\n fieldName,\n expression: xFormula.expression,\n fieldType: fieldSchema.type ?? 'string',\n });\n }\n }\n\n return formulas;\n}\n","import { parseExpression } from './parse-formula';\nimport { validateFormulaSyntax } from './validate-syntax';\nimport { extractSchemaFormulas, JsonSchema } from './extract-schema';\nimport {\n buildDependencyGraph,\n detectCircularDependencies,\n} from './dependency-graph';\nimport { inferFormulaType, FieldTypes, InferredType } from './parser';\n\nexport interface FormulaValidationError {\n field: string;\n error: string;\n position?: number;\n}\n\nexport interface SchemaValidationResult {\n isValid: boolean;\n errors: FormulaValidationError[];\n}\n\nfunction getSchemaFields(schema: JsonSchema): Set<string> {\n const fields = new Set<string>();\n const properties = schema.properties ?? {};\n\n for (const fieldName of Object.keys(properties)) {\n fields.add(fieldName);\n }\n\n return fields;\n}\n\nfunction getSchemaFieldTypes(schema: JsonSchema): FieldTypes {\n const fieldTypes: FieldTypes = {};\n const properties = schema.properties ?? {};\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n const schemaType = fieldSchema.type;\n if (\n schemaType === 'number' ||\n schemaType === 'string' ||\n schemaType === 'boolean' ||\n schemaType === 'object' ||\n schemaType === 'array'\n ) {\n fieldTypes[fieldName] = schemaType;\n }\n }\n\n return fieldTypes;\n}\n\nfunction schemaTypeToInferred(\n schemaType: string | undefined,\n): InferredType | null {\n if (schemaType === 'number') return 'number';\n if (schemaType === 'string') return 'string';\n if (schemaType === 'boolean') return 'boolean';\n return null;\n}\n\nfunction isTypeCompatible(\n inferredType: InferredType,\n expectedType: InferredType | null,\n): boolean {\n if (expectedType === null) return true;\n if (inferredType === 'unknown') return true;\n return inferredType === expectedType;\n}\n\nfunction extractFieldRoot(dependency: string): string {\n const root = dependency.split('.')[0]?.split('[')[0];\n return root || dependency;\n}\n\nexport function validateFormulaAgainstSchema(\n expression: string,\n fieldName: string,\n schema: JsonSchema,\n): FormulaValidationError | null {\n const syntaxResult = validateFormulaSyntax(expression);\n if (!syntaxResult.isValid) {\n return {\n field: fieldName,\n error: syntaxResult.error,\n position: syntaxResult.position,\n };\n }\n\n const parseResult = parseExpression(expression);\n const schemaFields = getSchemaFields(schema);\n\n for (const dep of parseResult.dependencies) {\n const rootField = extractFieldRoot(dep);\n if (!schemaFields.has(rootField)) {\n return {\n field: fieldName,\n error: `Unknown field '${rootField}' in formula`,\n };\n }\n }\n\n if (parseResult.dependencies.some((d) => extractFieldRoot(d) === fieldName)) {\n return {\n field: fieldName,\n error: `Formula cannot reference itself`,\n };\n }\n\n const fieldSchema = schema.properties?.[fieldName];\n const expectedType = schemaTypeToInferred(fieldSchema?.type);\n const fieldTypes = getSchemaFieldTypes(schema);\n const inferredType = inferFormulaType(expression, fieldTypes);\n\n if (!isTypeCompatible(inferredType, expectedType)) {\n return {\n field: fieldName,\n error: `Type mismatch: formula returns '${inferredType}' but field expects '${expectedType}'`,\n };\n }\n\n return null;\n}\n\nexport function validateSchemaFormulas(\n schema: JsonSchema,\n): SchemaValidationResult {\n const errors: FormulaValidationError[] = [];\n const formulas = extractSchemaFormulas(schema);\n\n for (const formula of formulas) {\n const error = validateFormulaAgainstSchema(\n formula.expression,\n formula.fieldName,\n schema,\n );\n if (error) {\n errors.push(error);\n }\n }\n\n if (errors.length > 0) {\n return { isValid: false, errors };\n }\n\n const dependencies: Record<string, string[]> = {};\n for (const formula of formulas) {\n const parseResult = parseExpression(formula.expression);\n dependencies[formula.fieldName] =\n parseResult.dependencies.map(extractFieldRoot);\n }\n\n const graph = buildDependencyGraph(dependencies);\n const circularCheck = detectCircularDependencies(graph);\n\n const cycle = circularCheck.cycle;\n if (circularCheck.hasCircular && cycle && cycle.length > 0) {\n const firstField = cycle[0];\n if (firstField) {\n errors.push({\n field: firstField,\n error: `Circular dependency: ${cycle.join(' → ')}`,\n });\n return { isValid: false, errors };\n }\n }\n\n return { isValid: true, errors: [] };\n}\n"]}