@revisium/schema-toolkit 0.14.1 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -137,6 +137,18 @@ function validateFormulaInContext(expression, fieldPath, rootSchema) {
137
137
  error: `Formula cannot reference itself`
138
138
  };
139
139
  }
140
+ const isInsideArray = fieldPath.includes("[");
141
+ if (isInsideArray) {
142
+ const computedFields = getComputedFieldsInContext(contextSchema);
143
+ const arrayRefError = validateArrayReferences(
144
+ expression,
145
+ fieldPath,
146
+ computedFields
147
+ );
148
+ if (arrayRefError) {
149
+ return arrayRefError;
150
+ }
151
+ }
140
152
  const fieldSchema = contextSchema.properties?.[localFieldName];
141
153
  const expectedType = schemaTypeToInferred(fieldSchema?.type);
142
154
  const fieldTypes = getSchemaFieldTypes(contextSchema);
@@ -336,6 +348,39 @@ function validateRelativePath(relativePath, currentPath, rootSchema, fieldPath)
336
348
  }
337
349
  return null;
338
350
  }
351
+ function getComputedFieldsInContext(schema) {
352
+ const computedFields = /* @__PURE__ */ new Set();
353
+ const properties = schema.properties ?? {};
354
+ for (const [fieldName, fieldSchema] of Object.entries(properties)) {
355
+ if (fieldSchema["x-formula"]) {
356
+ computedFields.add(fieldName);
357
+ }
358
+ }
359
+ return computedFields;
360
+ }
361
+ function validateArrayReferences(expression, fieldPath, computedFields) {
362
+ const atNextMatches = expression.matchAll(/@next\.(\w+)/g);
363
+ for (const match of atNextMatches) {
364
+ const fieldName = match[1];
365
+ if (fieldName && computedFields.has(fieldName)) {
366
+ return {
367
+ field: fieldPath,
368
+ error: `Cannot reference computed field '${fieldName}' via @next. Use @prev instead for cross-element computed field references.`
369
+ };
370
+ }
371
+ }
372
+ const absoluteIndexMatches = expression.matchAll(/\/[\w[\]]+\[\d+\]\.(\w+)/g);
373
+ for (const match of absoluteIndexMatches) {
374
+ const fieldName = match[1];
375
+ if (fieldName && computedFields.has(fieldName)) {
376
+ return {
377
+ field: fieldPath,
378
+ error: `Absolute index reference to computed field '${fieldName}' may cause forward reference issues. Consider using @prev pattern instead.`
379
+ };
380
+ }
381
+ }
382
+ return null;
383
+ }
339
384
  var FORMULA_TYPES = /* @__PURE__ */ new Set(["number", "string", "boolean"]);
340
385
  function collectFormulaNodes(schema, data) {
341
386
  const nodes = [];
@@ -623,5 +668,5 @@ function setValueByPath(obj, path, value) {
623
668
  }
624
669
 
625
670
  export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, validateFormulaAgainstSchema, validateSchemaFormulas };
626
- //# sourceMappingURL=chunk-5KGKN42D.js.map
627
- //# sourceMappingURL=chunk-5KGKN42D.js.map
671
+ //# sourceMappingURL=chunk-R3MS2N4A.js.map
672
+ //# sourceMappingURL=chunk-R3MS2N4A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/extract-schema-formulas.ts","../src/lib/validate-schema-formulas.ts","../src/lib/formula.ts"],"names":["getParentPath"],"mappings":";;;;AA0BO,SAAS,sBACd,MAAA,EACoB;AACpB,EAAA,MAAM,WAA+B,EAAC;AACtC,EAAA,wBAAA,CAAyB,MAAA,EAAQ,IAAI,QAAQ,CAAA;AAC7C,EAAA,OAAO,QAAA;AACT;AAEA,SAAS,wBAAA,CACP,MAAA,EACA,UAAA,EACA,QAAA,EACM;AACN,EAAA,IAAI,MAAA,CAAO,IAAA,KAAS,OAAA,IAAW,MAAA,CAAO,KAAA,EAAO;AAC3C,IAAA,wBAAA,CAAyB,MAAA,CAAO,KAAA,EAAO,CAAA,EAAG,UAAU,MAAM,QAAQ,CAAA;AAClE,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,UAAA,IAAc,EAAC;AAEzC,EAAA,KAAA,MAAW,CAAC,SAAA,EAAW,WAAW,KAAK,MAAA,CAAO,OAAA,CAAQ,UAAU,CAAA,EAAG;AACjE,IAAA,MAAM,WAAW,UAAA,GAAa,CAAA,EAAG,UAAU,CAAA,CAAA,EAAI,SAAS,CAAA,C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AI,QAAQ,KAAK,CAAA;AAAA,IAC7B;AAAA,EACF;AAEA,EAAA,MAAM,WAAA,GAAc,QAAA,CAAS,EAAA,CAAG,EAAE,CAAA;AAClC,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA;AAAA,EACF;AAEA,EAAA,IAAI,WAAA,CAAY,SAAS,OAAA,EAAS;AAChC,IAAA,IAAI,CAAC,SAAA,CAAU,WAAA,CAAY,IAAI,CAAA,EAAG;AAChC,MAAA;AAAA,IACF;AACA,IAAC,OAAA,CAAoC,WAAA,CAAY,IAAI,CAAA,GAAI,KAAA;AAAA,EAC3D,CAAA,MAAO;AACL,IAAC,OAAA,CAAsB,WAAA,CAAY,KAAK,CAAA,GAAI,KAAA;AAAA,EAC9C;AACF","file":"chunk-R3MS2N4A.js","sourcesContent":["interface XFormulaInput {\n version: number;\n expression: string;\n}\n\ninterface SchemaProperty {\n type?: string;\n 'x-formula'?: XFormulaInput;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\n\ninterface JsonSchemaInput {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\n\nexport interface ExtractedFormula {\n fieldName: string;\n expression: string;\n fieldType: string;\n}\n\nexport function extractSchemaFormulas(\n schema: JsonSchemaInput,\n): ExtractedFormula[] {\n const formulas: ExtractedFormula[] = [];\n extractFormulasRecursive(schema, '', formulas);\n return formulas;\n}\n\nfunction extractFormulasRecursive(\n schema: SchemaProperty | JsonSchemaInput,\n pathPrefix: string,\n formulas: ExtractedFormula[],\n): void {\n if (schema.type === 'array' && schema.items) {\n extractFormulasRecursive(schema.items, `${pathPrefix}[]`, formulas);\n return;\n }\n\n const properties = schema.properties ?? {};\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n const fullPath = pathPrefix ? `${pathPrefix}.${fieldName}` : fieldName;\n\n const xFormula = fieldSchema['x-formula'];\n if (xFormula) {\n formulas.push({\n fieldName: fullPath,\n expression: xFormula.expression,\n fieldType: fieldSchema.type ?? 'string',\n });\n }\n\n if (fieldSchema.type === 'object' && fieldSchema.properties) {\n extractFormulasRecursive(fieldSchema, fullPath, formulas);\n }\n\n if (fieldSchema.type === 'array' && fieldSchema.items) {\n extractFormulasRecursive(fieldSchema.items, `${fullPath}[]`, formulas);\n }\n }\n}\n","import {\n parseExpression,\n validateFormulaSyntax,\n buildDependencyGraph,\n detectCircularDependencies,\n inferFormulaType,\n type FieldTypes,\n type InferredType,\n} from '@revisium/formula';\nimport { extractSchemaFormulas } from './extract-schema-formulas.js';\n\ninterface XFormula {\n version: number;\n expression: string;\n}\n\ninterface SchemaProperty {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n 'x-formula'?: XFormula;\n [key: string]: unknown;\n}\n\ninterface JsonSchemaInput {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\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\nexport function validateSchemaFormulas(\n schema: JsonSchemaInput,\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 const parentPath = getParentPath(formula.fieldName);\n const prefix = parentPath ? `${parentPath}.` : '';\n\n dependencies[formula.fieldName] = parseResult.dependencies.map((dep) => {\n if (dep.startsWith('/')) {\n return extractFieldRoot(dep.slice(1));\n }\n if (dep.startsWith('../')) {\n return resolveRelativePathForDependency(dep, parentPath);\n }\n const rootField = extractFieldRoot(dep);\n return `${prefix}${rootField}`;\n });\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\nexport function validateFormulaAgainstSchema(\n expression: string,\n fieldName: string,\n schema: JsonSchemaInput,\n): FormulaValidationError | null {\n return validateFormulaInContext(expression, fieldName, schema);\n}\n\nfunction validateFormulaInContext(\n expression: string,\n fieldPath: string,\n rootSchema: JsonSchemaInput,\n): FormulaValidationError | null {\n const syntaxResult = validateFormulaSyntax(expression);\n if (!syntaxResult.isValid) {\n return {\n field: fieldPath,\n error: syntaxResult.error,\n position: syntaxResult.position,\n };\n }\n\n const parentPath = getParentPath(fieldPath);\n const localFieldName = getFieldName(fieldPath);\n const contextSchema = resolveSubSchema(rootSchema, parentPath);\n\n if (!contextSchema) {\n return {\n field: fieldPath,\n error: `Cannot resolve schema context for path '${parentPath}'`,\n };\n }\n\n const parseResult = parseExpression(expression);\n const localSchemaFields = getSchemaFields(contextSchema);\n const rootSchemaFields = getSchemaFields(rootSchema);\n\n for (const dep of parseResult.dependencies) {\n if (dep.startsWith('/')) {\n const rootField = extractFieldRoot(dep.slice(1));\n if (!rootSchemaFields.has(rootField)) {\n return {\n field: fieldPath,\n error: `Unknown root field '${rootField}' in formula`,\n };\n }\n } else if (dep.startsWith('../')) {\n const validationResult = validateRelativePath(\n dep,\n parentPath,\n rootSchema,\n fieldPath,\n );\n if (validationResult) {\n return validationResult;\n }\n } else {\n const rootField = extractFieldRoot(dep);\n if (!localSchemaFields.has(rootField)) {\n return {\n field: fieldPath,\n error: `Unknown field '${rootField}' in formula`,\n };\n }\n }\n }\n\n if (\n parseResult.dependencies.some((d) => extractFieldRoot(d) === localFieldName)\n ) {\n return {\n field: fieldPath,\n error: `Formula cannot reference itself`,\n };\n }\n\n const isInsideArray = fieldPath.includes('[');\n if (isInsideArray) {\n const computedFields = getComputedFieldsInContext(contextSchema);\n const arrayRefError = validateArrayReferences(\n expression,\n fieldPath,\n computedFields,\n );\n if (arrayRefError) {\n return arrayRefError;\n }\n }\n\n const fieldSchema = contextSchema.properties?.[localFieldName];\n const expectedType = schemaTypeToInferred(fieldSchema?.type);\n const fieldTypes = getSchemaFieldTypes(contextSchema);\n const inferredType = inferFormulaType(expression, fieldTypes);\n\n if (!isTypeCompatible(inferredType, expectedType)) {\n return {\n field: fieldPath,\n error: `Type mismatch: formula returns '${inferredType}' but field expects '${expectedType}'`,\n };\n }\n\n return null;\n}\n\nfunction resolveSubSchema(\n schema: JsonSchemaInput,\n fieldPath: string,\n): SchemaProperty | null {\n if (!fieldPath) {\n return schema;\n }\n\n const segments = parsePathSegmentsForSchema(fieldPath);\n let current: SchemaProperty | JsonSchemaInput = schema;\n\n for (const segment of segments) {\n if (segment === '[]') {\n if (current.type === 'array' && current.items) {\n current = current.items;\n } else {\n return null;\n }\n } else if (current.properties?.[segment]) {\n current = current.properties[segment];\n } else {\n return null;\n }\n }\n\n return current;\n}\n\nfunction parsePathSegmentsForSchema(path: string): string[] {\n const segments: string[] = [];\n let current = '';\n let inBracket = false;\n\n for (const char of path) {\n if (char === '[') {\n if (current) {\n segments.push(current);\n current = '';\n }\n inBracket = true;\n } else if (char === ']') {\n inBracket = false;\n segments.push('[]');\n } else if (char === '.' && !inBracket) {\n if (current) {\n segments.push(current);\n current = '';\n }\n } else if (!inBracket) {\n current += char;\n }\n }\n\n if (current) {\n segments.push(current);\n }\n\n return segments;\n}\n\nfunction parsePathSegments(path: string): string[] {\n const segments: string[] = [];\n let current = '';\n let inBracket = false;\n\n for (const char of path) {\n if (char === '[') {\n if (current) {\n segments.push(current);\n current = '';\n }\n inBracket = true;\n } else if (char === ']') {\n inBracket = false;\n } else if (char === '.' && !inBracket) {\n if (current) {\n segments.push(current);\n current = '';\n }\n } else if (!inBracket) {\n current += char;\n }\n }\n\n if (current) {\n segments.push(current);\n }\n\n return segments;\n}\n\nfunction getParentPath(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n const lastBracketIndex = fieldPath.lastIndexOf('[');\n const splitIndex = Math.max(lastDotIndex, lastBracketIndex);\n\n if (splitIndex <= 0) {\n return '';\n }\n\n return fieldPath.substring(0, splitIndex);\n}\n\nfunction getFieldName(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n const lastBracketIndex = fieldPath.lastIndexOf(']');\n const splitIndex = Math.max(lastDotIndex, lastBracketIndex);\n\n if (splitIndex === -1) {\n return fieldPath;\n }\n\n return fieldPath.substring(splitIndex + 1);\n}\n\nfunction getSchemaFields(schema: SchemaProperty | JsonSchemaInput): 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: SchemaProperty | JsonSchemaInput): 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 (schemaType === 'integer') {\n fieldTypes[fieldName] = 'number';\n } else 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' || schemaType === 'integer') 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\nfunction countParentLevels(path: string): number {\n let count = 0;\n let remaining = path;\n while (remaining.startsWith('../')) {\n count++;\n remaining = remaining.slice(3);\n }\n return count;\n}\n\nfunction resolveRelativePathForDependency(\n relativePath: string,\n currentPath: string,\n): string {\n const parentLevels = countParentLevels(relativePath);\n const fieldAfterParents = relativePath.replace(/^(\\.\\.\\/)+/, '');\n const targetField = extractFieldRoot(fieldAfterParents);\n\n if (!currentPath) {\n return targetField;\n }\n\n const pathSegments = parsePathSegments(currentPath);\n const targetLevel = pathSegments.length - parentLevels;\n\n if (targetLevel <= 0) {\n return targetField;\n }\n\n const basePath = pathSegments.slice(0, targetLevel).join('.');\n return basePath ? `${basePath}.${targetField}` : targetField;\n}\n\nfunction validateRelativePath(\n relativePath: string,\n currentPath: string,\n rootSchema: JsonSchemaInput,\n fieldPath: string,\n): FormulaValidationError | null {\n const parentLevels = countParentLevels(relativePath);\n const fieldAfterParents = relativePath.replace(/^(\\.\\.\\/)+/, '');\n const targetField = extractFieldRoot(fieldAfterParents);\n\n const pathSegments = parsePathSegments(currentPath);\n const targetLevel = pathSegments.length - parentLevels;\n\n if (targetLevel <= 0) {\n const rootFields = getSchemaFields(rootSchema);\n if (!rootFields.has(targetField)) {\n return {\n field: fieldPath,\n error: `Unknown root field '${targetField}' in formula`,\n };\n }\n return null;\n }\n\n const targetPath = pathSegments.slice(0, targetLevel).join('.');\n const targetSchema = resolveSubSchema(rootSchema, targetPath);\n\n if (!targetSchema) {\n return {\n field: fieldPath,\n error: `Cannot resolve schema for relative path '${relativePath}'`,\n };\n }\n\n const targetFields = getSchemaFields(targetSchema);\n if (!targetFields.has(targetField)) {\n return {\n field: fieldPath,\n error: `Unknown field '${targetField}' in formula`,\n };\n }\n\n return null;\n}\n\nfunction getComputedFieldsInContext(\n schema: SchemaProperty | JsonSchemaInput,\n): Set<string> {\n const computedFields = new Set<string>();\n const properties = schema.properties ?? {};\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n if (fieldSchema['x-formula']) {\n computedFields.add(fieldName);\n }\n }\n\n return computedFields;\n}\n\nfunction validateArrayReferences(\n expression: string,\n fieldPath: string,\n computedFields: Set<string>,\n): FormulaValidationError | null {\n const atNextMatches = expression.matchAll(/@next\\.(\\w+)/g);\n for (const match of atNextMatches) {\n const fieldName = match[1];\n if (fieldName && computedFields.has(fieldName)) {\n return {\n field: fieldPath,\n error: `Cannot reference computed field '${fieldName}' via @next. Use @prev instead for cross-element computed field references.`,\n };\n }\n }\n\n const absoluteIndexMatches = expression.matchAll(/\\/[\\w[\\]]+\\[\\d+\\]\\.(\\w+)/g);\n for (const match of absoluteIndexMatches) {\n const fieldName = match[1];\n if (fieldName && computedFields.has(fieldName)) {\n return {\n field: fieldPath,\n error: `Absolute index reference to computed field '${fieldName}' may cause forward reference issues. Consider using @prev pattern instead.`,\n };\n }\n }\n\n return null;\n}\n","import {\n parseFormula,\n evaluateWithContext,\n type ArrayContext,\n type ArrayLevelContext,\n} from '@revisium/formula';\nimport { type JsonSchema } from '../types/index.js';\n\nexport { formulaSpec } from '@revisium/formula/spec';\nexport {\n extractSchemaFormulas,\n type ExtractedFormula,\n} from './extract-schema-formulas.js';\nexport {\n validateSchemaFormulas,\n validateFormulaAgainstSchema,\n type SchemaValidationResult,\n type FormulaValidationError,\n} from './validate-schema-formulas.js';\n\ninterface ArrayLevelInfo {\n index: number;\n length: number;\n arrayPath: string;\n}\n\nexport interface FormulaNode {\n path: string;\n expression: string;\n fieldType: 'number' | 'string' | 'boolean';\n currentPath: string;\n dependencies: string[];\n arrayLevels: ArrayLevelInfo[];\n}\n\nexport interface FormulaError {\n field: string;\n expression: string;\n error: string;\n defaultUsed: boolean;\n}\n\nexport interface EvaluateFormulasResult {\n values: Record<string, unknown>;\n errors: FormulaError[];\n}\n\nexport interface EvaluateFormulasOptions {\n useDefaults?: boolean;\n defaults?: Record<string, unknown>;\n}\n\ninterface SchemaNode {\n type?: string;\n properties?: Record<string, SchemaNode>;\n items?: SchemaNode;\n 'x-formula'?: { version: number; expression: string };\n}\n\nconst FORMULA_TYPES = new Set(['number', 'string', 'boolean']);\n\ninterface TraversalContext {\n arrayLevels: ArrayLevelInfo[];\n}\n\nexport function collectFormulaNodes(\n schema: JsonSchema,\n data: Record<string, unknown>,\n): FormulaNode[] {\n const nodes: FormulaNode[] = [];\n traverseAndCollect(schema as SchemaNode, data, '', nodes, { arrayLevels: [] });\n return nodes;\n}\n\nfunction traverseAndCollect(\n schema: SchemaNode,\n data: unknown,\n currentPath: string,\n nodes: FormulaNode[],\n ctx: TraversalContext,\n): void {\n if (schema.type === 'object' && schema.properties && typeof data === 'object' && data !== null) {\n const record = data as Record<string, unknown>;\n\n for (const [fieldName, fieldSchema] of Object.entries(schema.properties)) {\n const fieldPath = currentPath ? `${currentPath}.${fieldName}` : fieldName;\n const fieldValue = record[fieldName];\n\n if (fieldSchema['x-formula'] && FORMULA_TYPES.has(fieldSchema.type ?? '')) {\n const expression = fieldSchema['x-formula'].expression;\n const parentPath = getParentPath(fieldPath);\n\n nodes.push({\n path: fieldPath,\n expression,\n fieldType: fieldSchema.type as 'number' | 'string' | 'boolean',\n currentPath: parentPath,\n dependencies: parseDependencies(expression),\n arrayLevels: [...ctx.arrayLevels],\n });\n }\n\n traverseAndCollect(fieldSchema, fieldValue, fieldPath, nodes, ctx);\n }\n }\n\n if (schema.type === 'array' && schema.items && Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const itemPath = `${currentPath}[${i}]`;\n const arrayLevel: ArrayLevelInfo = {\n index: i,\n length: data.length,\n arrayPath: currentPath,\n };\n const newCtx: TraversalContext = {\n arrayLevels: [arrayLevel, ...ctx.arrayLevels],\n };\n traverseAndCollect(schema.items, data[i], itemPath, nodes, newCtx);\n }\n }\n}\n\nfunction parseDependencies(expression: string): string[] {\n try {\n return parseFormula(expression).dependencies;\n } catch {\n return [];\n }\n}\n\nfunction getParentPath(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n if (lastDotIndex === -1) {\n return '';\n }\n return fieldPath.substring(0, lastDotIndex);\n}\n\nexport function evaluateFormulas(\n schema: JsonSchema,\n data: Record<string, unknown>,\n options: EvaluateFormulasOptions = {},\n): EvaluateFormulasResult {\n const nodes = collectFormulaNodes(schema, data);\n\n if (nodes.length === 0) {\n return { values: {}, errors: [] };\n }\n\n const sortedNodes = orderByDependencies(nodes);\n const values: Record<string, unknown> = {};\n const errors: FormulaError[] = [];\n const failedPaths = new Set<string>();\n\n for (const node of sortedNodes) {\n const hasDependencyFailure = hasFailedDependency(node, failedPaths);\n\n if (hasDependencyFailure) {\n failedPaths.add(node.path);\n handleError(node, 'Dependency formula failed', data, values, errors, options);\n continue;\n }\n\n const result = evaluateNode(node, data);\n\n if (!result.success) {\n failedPaths.add(node.path);\n handleError(node, result.error, data, values, errors, options);\n continue;\n }\n\n setValueByPath(data, node.path, result.value);\n values[node.path] = result.value;\n }\n\n return { values, errors };\n}\n\nfunction orderByDependencies(nodes: FormulaNode[]): FormulaNode[] {\n if (nodes.length <= 1) {\n return nodes;\n }\n\n const formulaNodes = new Set(nodes.map((n) => n.path));\n const visited = new Set<string>();\n const order: FormulaNode[] = [];\n\n const nodeByPath = new Map(nodes.map((n) => [n.path, n]));\n\n const visit = (node: FormulaNode, stack: Set<string>): void => {\n if (visited.has(node.path)) {\n return;\n }\n\n if (stack.has(node.path)) {\n throw new Error(`Cyclic dependency detected in formulas: ${node.path}`);\n }\n\n stack.add(node.path);\n\n for (const dep of node.dependencies) {\n if (formulaNodes.has(dep)) {\n const depNode = nodeByPath.get(dep);\n if (depNode) {\n visit(depNode, stack);\n }\n }\n }\n\n stack.delete(node.path);\n visited.add(node.path);\n order.push(node);\n };\n\n for (const node of nodes) {\n visit(node, new Set());\n }\n\n return order;\n}\n\nfunction hasFailedDependency(node: FormulaNode, failedPaths: Set<string>): boolean {\n return node.dependencies.some((dep) => {\n for (const failedPath of failedPaths) {\n if (failedPath === dep || failedPath.endsWith(`.${dep}`)) {\n return true;\n }\n }\n return false;\n });\n}\n\nfunction buildArrayContext(\n node: FormulaNode,\n data: Record<string, unknown>,\n): ArrayContext | undefined {\n if (node.arrayLevels.length === 0) {\n return undefined;\n }\n\n const levels: ArrayLevelContext[] = node.arrayLevels.map((level) => {\n const array = getValueByPath(data, level.arrayPath) as unknown[] | undefined;\n const { index, length } = level;\n\n let prev: unknown = null;\n let next: unknown = null;\n\n if (array) {\n if (index > 0) {\n prev = array[index - 1] ?? null;\n }\n if (index < length - 1) {\n next = array[index + 1] ?? null;\n }\n }\n\n return { index, length, prev, next };\n });\n\n return { levels };\n}\n\nfunction evaluateNode(\n node: FormulaNode,\n data: Record<string, unknown>,\n): { success: true; value: unknown } | { success: false; error: string } {\n try {\n const itemData = node.currentPath\n ? getValueByPath(data, node.currentPath) as Record<string, unknown> | undefined\n : undefined;\n\n const arrayContext = buildArrayContext(node, data);\n\n const result = evaluateWithContext(node.expression, {\n rootData: data,\n ...(itemData && { itemData, currentPath: node.currentPath }),\n arrayContext,\n });\n\n if (result === undefined) {\n return { success: false, error: 'Formula returned undefined' };\n }\n\n return { success: true, value: result };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\nfunction handleError(\n node: FormulaNode,\n errorMessage: string,\n data: Record<string, unknown>,\n values: Record<string, unknown>,\n errors: FormulaError[],\n options: EvaluateFormulasOptions,\n): void {\n const defaultUsed = options.useDefaults ?? false;\n\n if (defaultUsed) {\n const defaultValue = getDefaultValue(node, options.defaults);\n setValueByPath(data, node.path, defaultValue);\n values[node.path] = defaultValue;\n }\n\n errors.push({\n field: node.path,\n expression: node.expression,\n error: errorMessage,\n defaultUsed,\n });\n}\n\nfunction getDefaultValue(\n node: FormulaNode,\n defaults?: Record<string, unknown>,\n): unknown {\n if (defaults && node.path in defaults) {\n return defaults[node.path];\n }\n\n switch (node.fieldType) {\n case 'number':\n return 0;\n case 'string':\n return '';\n case 'boolean':\n return false;\n }\n}\n\nfunction getValueByPath(\n obj: Record<string, unknown>,\n path: string,\n): unknown {\n const segments = parsePath(path);\n let current: unknown = obj;\n\n for (const segment of segments) {\n if (current === null || current === undefined) {\n return undefined;\n }\n\n if (segment.type === 'field') {\n current = (current as Record<string, unknown>)[segment.name];\n } else {\n if (!Array.isArray(current)) {\n return undefined;\n }\n current = current[segment.index];\n }\n }\n\n return current;\n}\n\ntype PathSegment = { type: 'field'; name: string } | { type: 'index'; index: number };\n\nfunction parsePath(path: string): PathSegment[] {\n const segments: PathSegment[] = [];\n let current = '';\n let position = 0;\n\n while (position < path.length) {\n const char = path[position];\n\n if (char === '.') {\n if (current) {\n segments.push({ type: 'field', name: current });\n current = '';\n }\n position++;\n } else if (char === '[') {\n if (current) {\n segments.push({ type: 'field', name: current });\n current = '';\n }\n const endBracket = path.indexOf(']', position);\n if (endBracket === -1) {\n position++;\n } else {\n const indexStr = path.slice(position + 1, endBracket);\n segments.push({ type: 'index', index: Number.parseInt(indexStr, 10) });\n position = endBracket + 1;\n }\n } else {\n current += char;\n position++;\n }\n }\n\n if (current) {\n segments.push({ type: 'field', name: current });\n }\n\n return segments;\n}\n\nfunction isSafeKey(key: string): boolean {\n return key !== '__proto__';\n}\n\nfunction setValueByPath(\n obj: Record<string, unknown>,\n path: string,\n value: unknown,\n): void {\n const segments = parsePath(path);\n let current: unknown = obj;\n\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n\n if (segment.type === 'field') {\n if (!isSafeKey(segment.name)) {\n return;\n }\n const record = current as Record<string, unknown>;\n if (!(segment.name in record)) {\n record[segment.name] = {};\n }\n current = record[segment.name];\n } else {\n const arr = current as unknown[];\n if (!arr[segment.index]) {\n arr[segment.index] = {};\n }\n current = arr[segment.index];\n }\n }\n\n const lastSegment = segments.at(-1);\n if (!lastSegment) {\n return;\n }\n\n if (lastSegment.type === 'field') {\n if (!isSafeKey(lastSegment.name)) {\n return;\n }\n (current as Record<string, unknown>)[lastSegment.name] = value;\n } else {\n (current as unknown[])[lastSegment.index] = value;\n }\n}\n"]}
@@ -139,6 +139,18 @@ function validateFormulaInContext(expression, fieldPath, rootSchema) {
139
139
  error: `Formula cannot reference itself`
140
140
  };
141
141
  }
142
+ const isInsideArray = fieldPath.includes("[");
143
+ if (isInsideArray) {
144
+ const computedFields = getComputedFieldsInContext(contextSchema);
145
+ const arrayRefError = validateArrayReferences(
146
+ expression,
147
+ fieldPath,
148
+ computedFields
149
+ );
150
+ if (arrayRefError) {
151
+ return arrayRefError;
152
+ }
153
+ }
142
154
  const fieldSchema = contextSchema.properties?.[localFieldName];
143
155
  const expectedType = schemaTypeToInferred(fieldSchema?.type);
144
156
  const fieldTypes = getSchemaFieldTypes(contextSchema);
@@ -338,6 +350,39 @@ function validateRelativePath(relativePath, currentPath, rootSchema, fieldPath)
338
350
  }
339
351
  return null;
340
352
  }
353
+ function getComputedFieldsInContext(schema) {
354
+ const computedFields = /* @__PURE__ */ new Set();
355
+ const properties = schema.properties ?? {};
356
+ for (const [fieldName, fieldSchema] of Object.entries(properties)) {
357
+ if (fieldSchema["x-formula"]) {
358
+ computedFields.add(fieldName);
359
+ }
360
+ }
361
+ return computedFields;
362
+ }
363
+ function validateArrayReferences(expression, fieldPath, computedFields) {
364
+ const atNextMatches = expression.matchAll(/@next\.(\w+)/g);
365
+ for (const match of atNextMatches) {
366
+ const fieldName = match[1];
367
+ if (fieldName && computedFields.has(fieldName)) {
368
+ return {
369
+ field: fieldPath,
370
+ error: `Cannot reference computed field '${fieldName}' via @next. Use @prev instead for cross-element computed field references.`
371
+ };
372
+ }
373
+ }
374
+ const absoluteIndexMatches = expression.matchAll(/\/[\w[\]]+\[\d+\]\.(\w+)/g);
375
+ for (const match of absoluteIndexMatches) {
376
+ const fieldName = match[1];
377
+ if (fieldName && computedFields.has(fieldName)) {
378
+ return {
379
+ field: fieldPath,
380
+ error: `Absolute index reference to computed field '${fieldName}' may cause forward reference issues. Consider using @prev pattern instead.`
381
+ };
382
+ }
383
+ }
384
+ return null;
385
+ }
341
386
  var FORMULA_TYPES = /* @__PURE__ */ new Set(["number", "string", "boolean"]);
342
387
  function collectFormulaNodes(schema, data) {
343
388
  const nodes = [];
@@ -633,5 +678,5 @@ exports.evaluateFormulas = evaluateFormulas;
633
678
  exports.extractSchemaFormulas = extractSchemaFormulas;
634
679
  exports.validateFormulaAgainstSchema = validateFormulaAgainstSchema;
635
680
  exports.validateSchemaFormulas = validateSchemaFormulas;
636
- //# sourceMappingURL=chunk-FKKO5Y4M.cjs.map
637
- //# sourceMappingURL=chunk-FKKO5Y4M.cjs.map
681
+ //# sourceMappingURL=chunk-X2VRR7V7.cjs.map
682
+ //# sourceMappingURL=chunk-X2VRR7V7.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/extract-schema-formulas.ts","../src/lib/validate-schema-formulas.ts","../src/lib/formula.ts"],"names":["formula","parseExpression","buildDependencyGraph","detectCircularDependencies","validateFormulaSyntax","inferFormulaType","getParentPath","parseFormula","evaluateWithContext"],"mappings":";;;;;;AA0BO,SAAS,sBACd,MAAA,EACoB;AACpB,EAAA,MAAM,WAA+B,EAAC;AACtC,EAAA,wBAAA,CAAyB,MAAA,EAAQ,IAAI,QAAQ,CAAA;AAC7C,EAAA,OAAO,QAAA;AACT;AAEA,SAAS,wBAAA,CACP,MAAA,EACA,UAAA,EACA,QAAA,EACM;AACN,EAAA,IAAI,MAAA,CAAO,IAAA,KAAS,OAAA,IAAW,MAAA,CAAO,KAAA,EAAO;AAC3C,IAAA,wBAAA,CAAyB,MAAA,CAAO,KAAA,EAAO,CAAA,EAAG,UAAU,MAAM,QAAQ,CAAA;AAClE,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,UAAA,IAAc,EAAC;AAEzC,EAAA,KAAA,MAAW,CAAC,SAAA,EAAW,WAAW,KAAK,MAAA,CAAO,OAAA,CAAQ,UAAU,CAAA,EAAG;AACjE,IA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AAA,CAAI,OAAA,CAAQ,KAAK,CAAA,GAAI,EAAC;AAAA,MACxB;AACA,MAAA,OAAA,GAAU,GAAA,CAAI,QAAQ,KAAK,CAAA;AAAA,IAC7B;AAAA,EACF;AAEA,EAAA,MAAM,WAAA,GAAc,QAAA,CAAS,EAAA,CAAG,EAAE,CAAA;AAClC,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA;AAAA,EACF;AAEA,EAAA,IAAI,WAAA,CAAY,SAAS,OAAA,EAAS;AAChC,IAAA,IAAI,CAAC,SAAA,CAAU,WAAA,CAAY,IAAI,CAAA,EAAG;AAChC,MAAA;AAAA,IACF;AACA,IAAC,OAAA,CAAoC,WAAA,CAAY,IAAI,CAAA,GAAI,KAAA;AAAA,EAC3D,CAAA,MAAO;AACL,IAAC,OAAA,CAAsB,WAAA,CAAY,KAAK,CAAA,GAAI,KAAA;AAAA,EAC9C;AACF","file":"chunk-X2VRR7V7.cjs","sourcesContent":["interface XFormulaInput {\n version: number;\n expression: string;\n}\n\ninterface SchemaProperty {\n type?: string;\n 'x-formula'?: XFormulaInput;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\n\ninterface JsonSchemaInput {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\n\nexport interface ExtractedFormula {\n fieldName: string;\n expression: string;\n fieldType: string;\n}\n\nexport function extractSchemaFormulas(\n schema: JsonSchemaInput,\n): ExtractedFormula[] {\n const formulas: ExtractedFormula[] = [];\n extractFormulasRecursive(schema, '', formulas);\n return formulas;\n}\n\nfunction extractFormulasRecursive(\n schema: SchemaProperty | JsonSchemaInput,\n pathPrefix: string,\n formulas: ExtractedFormula[],\n): void {\n if (schema.type === 'array' && schema.items) {\n extractFormulasRecursive(schema.items, `${pathPrefix}[]`, formulas);\n return;\n }\n\n const properties = schema.properties ?? {};\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n const fullPath = pathPrefix ? `${pathPrefix}.${fieldName}` : fieldName;\n\n const xFormula = fieldSchema['x-formula'];\n if (xFormula) {\n formulas.push({\n fieldName: fullPath,\n expression: xFormula.expression,\n fieldType: fieldSchema.type ?? 'string',\n });\n }\n\n if (fieldSchema.type === 'object' && fieldSchema.properties) {\n extractFormulasRecursive(fieldSchema, fullPath, formulas);\n }\n\n if (fieldSchema.type === 'array' && fieldSchema.items) {\n extractFormulasRecursive(fieldSchema.items, `${fullPath}[]`, formulas);\n }\n }\n}\n","import {\n parseExpression,\n validateFormulaSyntax,\n buildDependencyGraph,\n detectCircularDependencies,\n inferFormulaType,\n type FieldTypes,\n type InferredType,\n} from '@revisium/formula';\nimport { extractSchemaFormulas } from './extract-schema-formulas.js';\n\ninterface XFormula {\n version: number;\n expression: string;\n}\n\ninterface SchemaProperty {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n 'x-formula'?: XFormula;\n [key: string]: unknown;\n}\n\ninterface JsonSchemaInput {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\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\nexport function validateSchemaFormulas(\n schema: JsonSchemaInput,\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 const parentPath = getParentPath(formula.fieldName);\n const prefix = parentPath ? `${parentPath}.` : '';\n\n dependencies[formula.fieldName] = parseResult.dependencies.map((dep) => {\n if (dep.startsWith('/')) {\n return extractFieldRoot(dep.slice(1));\n }\n if (dep.startsWith('../')) {\n return resolveRelativePathForDependency(dep, parentPath);\n }\n const rootField = extractFieldRoot(dep);\n return `${prefix}${rootField}`;\n });\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\nexport function validateFormulaAgainstSchema(\n expression: string,\n fieldName: string,\n schema: JsonSchemaInput,\n): FormulaValidationError | null {\n return validateFormulaInContext(expression, fieldName, schema);\n}\n\nfunction validateFormulaInContext(\n expression: string,\n fieldPath: string,\n rootSchema: JsonSchemaInput,\n): FormulaValidationError | null {\n const syntaxResult = validateFormulaSyntax(expression);\n if (!syntaxResult.isValid) {\n return {\n field: fieldPath,\n error: syntaxResult.error,\n position: syntaxResult.position,\n };\n }\n\n const parentPath = getParentPath(fieldPath);\n const localFieldName = getFieldName(fieldPath);\n const contextSchema = resolveSubSchema(rootSchema, parentPath);\n\n if (!contextSchema) {\n return {\n field: fieldPath,\n error: `Cannot resolve schema context for path '${parentPath}'`,\n };\n }\n\n const parseResult = parseExpression(expression);\n const localSchemaFields = getSchemaFields(contextSchema);\n const rootSchemaFields = getSchemaFields(rootSchema);\n\n for (const dep of parseResult.dependencies) {\n if (dep.startsWith('/')) {\n const rootField = extractFieldRoot(dep.slice(1));\n if (!rootSchemaFields.has(rootField)) {\n return {\n field: fieldPath,\n error: `Unknown root field '${rootField}' in formula`,\n };\n }\n } else if (dep.startsWith('../')) {\n const validationResult = validateRelativePath(\n dep,\n parentPath,\n rootSchema,\n fieldPath,\n );\n if (validationResult) {\n return validationResult;\n }\n } else {\n const rootField = extractFieldRoot(dep);\n if (!localSchemaFields.has(rootField)) {\n return {\n field: fieldPath,\n error: `Unknown field '${rootField}' in formula`,\n };\n }\n }\n }\n\n if (\n parseResult.dependencies.some((d) => extractFieldRoot(d) === localFieldName)\n ) {\n return {\n field: fieldPath,\n error: `Formula cannot reference itself`,\n };\n }\n\n const isInsideArray = fieldPath.includes('[');\n if (isInsideArray) {\n const computedFields = getComputedFieldsInContext(contextSchema);\n const arrayRefError = validateArrayReferences(\n expression,\n fieldPath,\n computedFields,\n );\n if (arrayRefError) {\n return arrayRefError;\n }\n }\n\n const fieldSchema = contextSchema.properties?.[localFieldName];\n const expectedType = schemaTypeToInferred(fieldSchema?.type);\n const fieldTypes = getSchemaFieldTypes(contextSchema);\n const inferredType = inferFormulaType(expression, fieldTypes);\n\n if (!isTypeCompatible(inferredType, expectedType)) {\n return {\n field: fieldPath,\n error: `Type mismatch: formula returns '${inferredType}' but field expects '${expectedType}'`,\n };\n }\n\n return null;\n}\n\nfunction resolveSubSchema(\n schema: JsonSchemaInput,\n fieldPath: string,\n): SchemaProperty | null {\n if (!fieldPath) {\n return schema;\n }\n\n const segments = parsePathSegmentsForSchema(fieldPath);\n let current: SchemaProperty | JsonSchemaInput = schema;\n\n for (const segment of segments) {\n if (segment === '[]') {\n if (current.type === 'array' && current.items) {\n current = current.items;\n } else {\n return null;\n }\n } else if (current.properties?.[segment]) {\n current = current.properties[segment];\n } else {\n return null;\n }\n }\n\n return current;\n}\n\nfunction parsePathSegmentsForSchema(path: string): string[] {\n const segments: string[] = [];\n let current = '';\n let inBracket = false;\n\n for (const char of path) {\n if (char === '[') {\n if (current) {\n segments.push(current);\n current = '';\n }\n inBracket = true;\n } else if (char === ']') {\n inBracket = false;\n segments.push('[]');\n } else if (char === '.' && !inBracket) {\n if (current) {\n segments.push(current);\n current = '';\n }\n } else if (!inBracket) {\n current += char;\n }\n }\n\n if (current) {\n segments.push(current);\n }\n\n return segments;\n}\n\nfunction parsePathSegments(path: string): string[] {\n const segments: string[] = [];\n let current = '';\n let inBracket = false;\n\n for (const char of path) {\n if (char === '[') {\n if (current) {\n segments.push(current);\n current = '';\n }\n inBracket = true;\n } else if (char === ']') {\n inBracket = false;\n } else if (char === '.' && !inBracket) {\n if (current) {\n segments.push(current);\n current = '';\n }\n } else if (!inBracket) {\n current += char;\n }\n }\n\n if (current) {\n segments.push(current);\n }\n\n return segments;\n}\n\nfunction getParentPath(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n const lastBracketIndex = fieldPath.lastIndexOf('[');\n const splitIndex = Math.max(lastDotIndex, lastBracketIndex);\n\n if (splitIndex <= 0) {\n return '';\n }\n\n return fieldPath.substring(0, splitIndex);\n}\n\nfunction getFieldName(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n const lastBracketIndex = fieldPath.lastIndexOf(']');\n const splitIndex = Math.max(lastDotIndex, lastBracketIndex);\n\n if (splitIndex === -1) {\n return fieldPath;\n }\n\n return fieldPath.substring(splitIndex + 1);\n}\n\nfunction getSchemaFields(schema: SchemaProperty | JsonSchemaInput): 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: SchemaProperty | JsonSchemaInput): 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 (schemaType === 'integer') {\n fieldTypes[fieldName] = 'number';\n } else 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' || schemaType === 'integer') 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\nfunction countParentLevels(path: string): number {\n let count = 0;\n let remaining = path;\n while (remaining.startsWith('../')) {\n count++;\n remaining = remaining.slice(3);\n }\n return count;\n}\n\nfunction resolveRelativePathForDependency(\n relativePath: string,\n currentPath: string,\n): string {\n const parentLevels = countParentLevels(relativePath);\n const fieldAfterParents = relativePath.replace(/^(\\.\\.\\/)+/, '');\n const targetField = extractFieldRoot(fieldAfterParents);\n\n if (!currentPath) {\n return targetField;\n }\n\n const pathSegments = parsePathSegments(currentPath);\n const targetLevel = pathSegments.length - parentLevels;\n\n if (targetLevel <= 0) {\n return targetField;\n }\n\n const basePath = pathSegments.slice(0, targetLevel).join('.');\n return basePath ? `${basePath}.${targetField}` : targetField;\n}\n\nfunction validateRelativePath(\n relativePath: string,\n currentPath: string,\n rootSchema: JsonSchemaInput,\n fieldPath: string,\n): FormulaValidationError | null {\n const parentLevels = countParentLevels(relativePath);\n const fieldAfterParents = relativePath.replace(/^(\\.\\.\\/)+/, '');\n const targetField = extractFieldRoot(fieldAfterParents);\n\n const pathSegments = parsePathSegments(currentPath);\n const targetLevel = pathSegments.length - parentLevels;\n\n if (targetLevel <= 0) {\n const rootFields = getSchemaFields(rootSchema);\n if (!rootFields.has(targetField)) {\n return {\n field: fieldPath,\n error: `Unknown root field '${targetField}' in formula`,\n };\n }\n return null;\n }\n\n const targetPath = pathSegments.slice(0, targetLevel).join('.');\n const targetSchema = resolveSubSchema(rootSchema, targetPath);\n\n if (!targetSchema) {\n return {\n field: fieldPath,\n error: `Cannot resolve schema for relative path '${relativePath}'`,\n };\n }\n\n const targetFields = getSchemaFields(targetSchema);\n if (!targetFields.has(targetField)) {\n return {\n field: fieldPath,\n error: `Unknown field '${targetField}' in formula`,\n };\n }\n\n return null;\n}\n\nfunction getComputedFieldsInContext(\n schema: SchemaProperty | JsonSchemaInput,\n): Set<string> {\n const computedFields = new Set<string>();\n const properties = schema.properties ?? {};\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n if (fieldSchema['x-formula']) {\n computedFields.add(fieldName);\n }\n }\n\n return computedFields;\n}\n\nfunction validateArrayReferences(\n expression: string,\n fieldPath: string,\n computedFields: Set<string>,\n): FormulaValidationError | null {\n const atNextMatches = expression.matchAll(/@next\\.(\\w+)/g);\n for (const match of atNextMatches) {\n const fieldName = match[1];\n if (fieldName && computedFields.has(fieldName)) {\n return {\n field: fieldPath,\n error: `Cannot reference computed field '${fieldName}' via @next. Use @prev instead for cross-element computed field references.`,\n };\n }\n }\n\n const absoluteIndexMatches = expression.matchAll(/\\/[\\w[\\]]+\\[\\d+\\]\\.(\\w+)/g);\n for (const match of absoluteIndexMatches) {\n const fieldName = match[1];\n if (fieldName && computedFields.has(fieldName)) {\n return {\n field: fieldPath,\n error: `Absolute index reference to computed field '${fieldName}' may cause forward reference issues. Consider using @prev pattern instead.`,\n };\n }\n }\n\n return null;\n}\n","import {\n parseFormula,\n evaluateWithContext,\n type ArrayContext,\n type ArrayLevelContext,\n} from '@revisium/formula';\nimport { type JsonSchema } from '../types/index.js';\n\nexport { formulaSpec } from '@revisium/formula/spec';\nexport {\n extractSchemaFormulas,\n type ExtractedFormula,\n} from './extract-schema-formulas.js';\nexport {\n validateSchemaFormulas,\n validateFormulaAgainstSchema,\n type SchemaValidationResult,\n type FormulaValidationError,\n} from './validate-schema-formulas.js';\n\ninterface ArrayLevelInfo {\n index: number;\n length: number;\n arrayPath: string;\n}\n\nexport interface FormulaNode {\n path: string;\n expression: string;\n fieldType: 'number' | 'string' | 'boolean';\n currentPath: string;\n dependencies: string[];\n arrayLevels: ArrayLevelInfo[];\n}\n\nexport interface FormulaError {\n field: string;\n expression: string;\n error: string;\n defaultUsed: boolean;\n}\n\nexport interface EvaluateFormulasResult {\n values: Record<string, unknown>;\n errors: FormulaError[];\n}\n\nexport interface EvaluateFormulasOptions {\n useDefaults?: boolean;\n defaults?: Record<string, unknown>;\n}\n\ninterface SchemaNode {\n type?: string;\n properties?: Record<string, SchemaNode>;\n items?: SchemaNode;\n 'x-formula'?: { version: number; expression: string };\n}\n\nconst FORMULA_TYPES = new Set(['number', 'string', 'boolean']);\n\ninterface TraversalContext {\n arrayLevels: ArrayLevelInfo[];\n}\n\nexport function collectFormulaNodes(\n schema: JsonSchema,\n data: Record<string, unknown>,\n): FormulaNode[] {\n const nodes: FormulaNode[] = [];\n traverseAndCollect(schema as SchemaNode, data, '', nodes, { arrayLevels: [] });\n return nodes;\n}\n\nfunction traverseAndCollect(\n schema: SchemaNode,\n data: unknown,\n currentPath: string,\n nodes: FormulaNode[],\n ctx: TraversalContext,\n): void {\n if (schema.type === 'object' && schema.properties && typeof data === 'object' && data !== null) {\n const record = data as Record<string, unknown>;\n\n for (const [fieldName, fieldSchema] of Object.entries(schema.properties)) {\n const fieldPath = currentPath ? `${currentPath}.${fieldName}` : fieldName;\n const fieldValue = record[fieldName];\n\n if (fieldSchema['x-formula'] && FORMULA_TYPES.has(fieldSchema.type ?? '')) {\n const expression = fieldSchema['x-formula'].expression;\n const parentPath = getParentPath(fieldPath);\n\n nodes.push({\n path: fieldPath,\n expression,\n fieldType: fieldSchema.type as 'number' | 'string' | 'boolean',\n currentPath: parentPath,\n dependencies: parseDependencies(expression),\n arrayLevels: [...ctx.arrayLevels],\n });\n }\n\n traverseAndCollect(fieldSchema, fieldValue, fieldPath, nodes, ctx);\n }\n }\n\n if (schema.type === 'array' && schema.items && Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const itemPath = `${currentPath}[${i}]`;\n const arrayLevel: ArrayLevelInfo = {\n index: i,\n length: data.length,\n arrayPath: currentPath,\n };\n const newCtx: TraversalContext = {\n arrayLevels: [arrayLevel, ...ctx.arrayLevels],\n };\n traverseAndCollect(schema.items, data[i], itemPath, nodes, newCtx);\n }\n }\n}\n\nfunction parseDependencies(expression: string): string[] {\n try {\n return parseFormula(expression).dependencies;\n } catch {\n return [];\n }\n}\n\nfunction getParentPath(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n if (lastDotIndex === -1) {\n return '';\n }\n return fieldPath.substring(0, lastDotIndex);\n}\n\nexport function evaluateFormulas(\n schema: JsonSchema,\n data: Record<string, unknown>,\n options: EvaluateFormulasOptions = {},\n): EvaluateFormulasResult {\n const nodes = collectFormulaNodes(schema, data);\n\n if (nodes.length === 0) {\n return { values: {}, errors: [] };\n }\n\n const sortedNodes = orderByDependencies(nodes);\n const values: Record<string, unknown> = {};\n const errors: FormulaError[] = [];\n const failedPaths = new Set<string>();\n\n for (const node of sortedNodes) {\n const hasDependencyFailure = hasFailedDependency(node, failedPaths);\n\n if (hasDependencyFailure) {\n failedPaths.add(node.path);\n handleError(node, 'Dependency formula failed', data, values, errors, options);\n continue;\n }\n\n const result = evaluateNode(node, data);\n\n if (!result.success) {\n failedPaths.add(node.path);\n handleError(node, result.error, data, values, errors, options);\n continue;\n }\n\n setValueByPath(data, node.path, result.value);\n values[node.path] = result.value;\n }\n\n return { values, errors };\n}\n\nfunction orderByDependencies(nodes: FormulaNode[]): FormulaNode[] {\n if (nodes.length <= 1) {\n return nodes;\n }\n\n const formulaNodes = new Set(nodes.map((n) => n.path));\n const visited = new Set<string>();\n const order: FormulaNode[] = [];\n\n const nodeByPath = new Map(nodes.map((n) => [n.path, n]));\n\n const visit = (node: FormulaNode, stack: Set<string>): void => {\n if (visited.has(node.path)) {\n return;\n }\n\n if (stack.has(node.path)) {\n throw new Error(`Cyclic dependency detected in formulas: ${node.path}`);\n }\n\n stack.add(node.path);\n\n for (const dep of node.dependencies) {\n if (formulaNodes.has(dep)) {\n const depNode = nodeByPath.get(dep);\n if (depNode) {\n visit(depNode, stack);\n }\n }\n }\n\n stack.delete(node.path);\n visited.add(node.path);\n order.push(node);\n };\n\n for (const node of nodes) {\n visit(node, new Set());\n }\n\n return order;\n}\n\nfunction hasFailedDependency(node: FormulaNode, failedPaths: Set<string>): boolean {\n return node.dependencies.some((dep) => {\n for (const failedPath of failedPaths) {\n if (failedPath === dep || failedPath.endsWith(`.${dep}`)) {\n return true;\n }\n }\n return false;\n });\n}\n\nfunction buildArrayContext(\n node: FormulaNode,\n data: Record<string, unknown>,\n): ArrayContext | undefined {\n if (node.arrayLevels.length === 0) {\n return undefined;\n }\n\n const levels: ArrayLevelContext[] = node.arrayLevels.map((level) => {\n const array = getValueByPath(data, level.arrayPath) as unknown[] | undefined;\n const { index, length } = level;\n\n let prev: unknown = null;\n let next: unknown = null;\n\n if (array) {\n if (index > 0) {\n prev = array[index - 1] ?? null;\n }\n if (index < length - 1) {\n next = array[index + 1] ?? null;\n }\n }\n\n return { index, length, prev, next };\n });\n\n return { levels };\n}\n\nfunction evaluateNode(\n node: FormulaNode,\n data: Record<string, unknown>,\n): { success: true; value: unknown } | { success: false; error: string } {\n try {\n const itemData = node.currentPath\n ? getValueByPath(data, node.currentPath) as Record<string, unknown> | undefined\n : undefined;\n\n const arrayContext = buildArrayContext(node, data);\n\n const result = evaluateWithContext(node.expression, {\n rootData: data,\n ...(itemData && { itemData, currentPath: node.currentPath }),\n arrayContext,\n });\n\n if (result === undefined) {\n return { success: false, error: 'Formula returned undefined' };\n }\n\n return { success: true, value: result };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\nfunction handleError(\n node: FormulaNode,\n errorMessage: string,\n data: Record<string, unknown>,\n values: Record<string, unknown>,\n errors: FormulaError[],\n options: EvaluateFormulasOptions,\n): void {\n const defaultUsed = options.useDefaults ?? false;\n\n if (defaultUsed) {\n const defaultValue = getDefaultValue(node, options.defaults);\n setValueByPath(data, node.path, defaultValue);\n values[node.path] = defaultValue;\n }\n\n errors.push({\n field: node.path,\n expression: node.expression,\n error: errorMessage,\n defaultUsed,\n });\n}\n\nfunction getDefaultValue(\n node: FormulaNode,\n defaults?: Record<string, unknown>,\n): unknown {\n if (defaults && node.path in defaults) {\n return defaults[node.path];\n }\n\n switch (node.fieldType) {\n case 'number':\n return 0;\n case 'string':\n return '';\n case 'boolean':\n return false;\n }\n}\n\nfunction getValueByPath(\n obj: Record<string, unknown>,\n path: string,\n): unknown {\n const segments = parsePath(path);\n let current: unknown = obj;\n\n for (const segment of segments) {\n if (current === null || current === undefined) {\n return undefined;\n }\n\n if (segment.type === 'field') {\n current = (current as Record<string, unknown>)[segment.name];\n } else {\n if (!Array.isArray(current)) {\n return undefined;\n }\n current = current[segment.index];\n }\n }\n\n return current;\n}\n\ntype PathSegment = { type: 'field'; name: string } | { type: 'index'; index: number };\n\nfunction parsePath(path: string): PathSegment[] {\n const segments: PathSegment[] = [];\n let current = '';\n let position = 0;\n\n while (position < path.length) {\n const char = path[position];\n\n if (char === '.') {\n if (current) {\n segments.push({ type: 'field', name: current });\n current = '';\n }\n position++;\n } else if (char === '[') {\n if (current) {\n segments.push({ type: 'field', name: current });\n current = '';\n }\n const endBracket = path.indexOf(']', position);\n if (endBracket === -1) {\n position++;\n } else {\n const indexStr = path.slice(position + 1, endBracket);\n segments.push({ type: 'index', index: Number.parseInt(indexStr, 10) });\n position = endBracket + 1;\n }\n } else {\n current += char;\n position++;\n }\n }\n\n if (current) {\n segments.push({ type: 'field', name: current });\n }\n\n return segments;\n}\n\nfunction isSafeKey(key: string): boolean {\n return key !== '__proto__';\n}\n\nfunction setValueByPath(\n obj: Record<string, unknown>,\n path: string,\n value: unknown,\n): void {\n const segments = parsePath(path);\n let current: unknown = obj;\n\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n\n if (segment.type === 'field') {\n if (!isSafeKey(segment.name)) {\n return;\n }\n const record = current as Record<string, unknown>;\n if (!(segment.name in record)) {\n record[segment.name] = {};\n }\n current = record[segment.name];\n } else {\n const arr = current as unknown[];\n if (!arr[segment.index]) {\n arr[segment.index] = {};\n }\n current = arr[segment.index];\n }\n }\n\n const lastSegment = segments.at(-1);\n if (!lastSegment) {\n return;\n }\n\n if (lastSegment.type === 'field') {\n if (!isSafeKey(lastSegment.name)) {\n return;\n }\n (current as Record<string, unknown>)[lastSegment.name] = value;\n } else {\n (current as unknown[])[lastSegment.index] = value;\n }\n}\n"]}
@@ -1,32 +1,32 @@
1
1
  'use strict';
2
2
 
3
- var chunkFKKO5Y4M_cjs = require('../chunk-FKKO5Y4M.cjs');
3
+ var chunkX2VRR7V7_cjs = require('../chunk-X2VRR7V7.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "collectFormulaNodes", {
8
8
  enumerable: true,
9
- get: function () { return chunkFKKO5Y4M_cjs.collectFormulaNodes; }
9
+ get: function () { return chunkX2VRR7V7_cjs.collectFormulaNodes; }
10
10
  });
11
11
  Object.defineProperty(exports, "evaluateFormulas", {
12
12
  enumerable: true,
13
- get: function () { return chunkFKKO5Y4M_cjs.evaluateFormulas; }
13
+ get: function () { return chunkX2VRR7V7_cjs.evaluateFormulas; }
14
14
  });
15
15
  Object.defineProperty(exports, "extractSchemaFormulas", {
16
16
  enumerable: true,
17
- get: function () { return chunkFKKO5Y4M_cjs.extractSchemaFormulas; }
17
+ get: function () { return chunkX2VRR7V7_cjs.extractSchemaFormulas; }
18
18
  });
19
19
  Object.defineProperty(exports, "formulaSpec", {
20
20
  enumerable: true,
21
- get: function () { return chunkFKKO5Y4M_cjs.formulaSpec; }
21
+ get: function () { return chunkX2VRR7V7_cjs.formulaSpec; }
22
22
  });
23
23
  Object.defineProperty(exports, "validateFormulaAgainstSchema", {
24
24
  enumerable: true,
25
- get: function () { return chunkFKKO5Y4M_cjs.validateFormulaAgainstSchema; }
25
+ get: function () { return chunkX2VRR7V7_cjs.validateFormulaAgainstSchema; }
26
26
  });
27
27
  Object.defineProperty(exports, "validateSchemaFormulas", {
28
28
  enumerable: true,
29
- get: function () { return chunkFKKO5Y4M_cjs.validateSchemaFormulas; }
29
+ get: function () { return chunkX2VRR7V7_cjs.validateSchemaFormulas; }
30
30
  });
31
31
  //# sourceMappingURL=index.cjs.map
32
32
  //# sourceMappingURL=index.cjs.map
@@ -25,10 +25,15 @@ interface ExtractedFormula {
25
25
  }
26
26
  declare function extractSchemaFormulas(schema: JsonSchemaInput$1): ExtractedFormula[];
27
27
 
28
+ interface XFormula {
29
+ version: number;
30
+ expression: string;
31
+ }
28
32
  interface SchemaProperty {
29
33
  type?: string;
30
34
  properties?: Record<string, SchemaProperty>;
31
35
  items?: SchemaProperty;
36
+ 'x-formula'?: XFormula;
32
37
  [key: string]: unknown;
33
38
  }
34
39
  interface JsonSchemaInput {
@@ -25,10 +25,15 @@ interface ExtractedFormula {
25
25
  }
26
26
  declare function extractSchemaFormulas(schema: JsonSchemaInput$1): ExtractedFormula[];
27
27
 
28
+ interface XFormula {
29
+ version: number;
30
+ expression: string;
31
+ }
28
32
  interface SchemaProperty {
29
33
  type?: string;
30
34
  properties?: Record<string, SchemaProperty>;
31
35
  items?: SchemaProperty;
36
+ 'x-formula'?: XFormula;
32
37
  [key: string]: unknown;
33
38
  }
34
39
  interface JsonSchemaInput {
@@ -1,3 +1,3 @@
1
- export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, formulaSpec, validateFormulaAgainstSchema, validateSchemaFormulas } from '../chunk-5KGKN42D.js';
1
+ export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, formulaSpec, validateFormulaAgainstSchema, validateSchemaFormulas } from '../chunk-R3MS2N4A.js';
2
2
  //# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.cjs CHANGED
@@ -5,7 +5,7 @@ var chunkEJYILFAK_cjs = require('./chunk-EJYILFAK.cjs');
5
5
  var chunkIPL2CGVA_cjs = require('./chunk-IPL2CGVA.cjs');
6
6
  require('./chunk-ODCH3PP2.cjs');
7
7
  var chunkVX5C5YMF_cjs = require('./chunk-VX5C5YMF.cjs');
8
- var chunkFKKO5Y4M_cjs = require('./chunk-FKKO5Y4M.cjs');
8
+ var chunkX2VRR7V7_cjs = require('./chunk-X2VRR7V7.cjs');
9
9
  var chunkGF3XXYOS_cjs = require('./chunk-GF3XXYOS.cjs');
10
10
  var chunkEGC32GPY_cjs = require('./chunk-EGC32GPY.cjs');
11
11
  var chunkXNFSFT7T_cjs = require('./chunk-XNFSFT7T.cjs');
@@ -193,27 +193,27 @@ Object.defineProperty(exports, "validateJsonFieldName", {
193
193
  });
194
194
  Object.defineProperty(exports, "collectFormulaNodes", {
195
195
  enumerable: true,
196
- get: function () { return chunkFKKO5Y4M_cjs.collectFormulaNodes; }
196
+ get: function () { return chunkX2VRR7V7_cjs.collectFormulaNodes; }
197
197
  });
198
198
  Object.defineProperty(exports, "evaluateFormulas", {
199
199
  enumerable: true,
200
- get: function () { return chunkFKKO5Y4M_cjs.evaluateFormulas; }
200
+ get: function () { return chunkX2VRR7V7_cjs.evaluateFormulas; }
201
201
  });
202
202
  Object.defineProperty(exports, "extractSchemaFormulas", {
203
203
  enumerable: true,
204
- get: function () { return chunkFKKO5Y4M_cjs.extractSchemaFormulas; }
204
+ get: function () { return chunkX2VRR7V7_cjs.extractSchemaFormulas; }
205
205
  });
206
206
  Object.defineProperty(exports, "formulaSpec", {
207
207
  enumerable: true,
208
- get: function () { return chunkFKKO5Y4M_cjs.formulaSpec; }
208
+ get: function () { return chunkX2VRR7V7_cjs.formulaSpec; }
209
209
  });
210
210
  Object.defineProperty(exports, "validateFormulaAgainstSchema", {
211
211
  enumerable: true,
212
- get: function () { return chunkFKKO5Y4M_cjs.validateFormulaAgainstSchema; }
212
+ get: function () { return chunkX2VRR7V7_cjs.validateFormulaAgainstSchema; }
213
213
  });
214
214
  Object.defineProperty(exports, "validateSchemaFormulas", {
215
215
  enumerable: true,
216
- get: function () { return chunkFKKO5Y4M_cjs.validateSchemaFormulas; }
216
+ get: function () { return chunkX2VRR7V7_cjs.validateSchemaFormulas; }
217
217
  });
218
218
  Object.defineProperty(exports, "FieldChangeType", {
219
219
  enumerable: true,
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export { getAddPatch, getArraySchema, getBooleanSchema, getMovePatch, getNumberS
3
3
  export { CustomSchemeKeywords } from './chunk-5VDDLW7U.js';
4
4
  import './chunk-H7W4QNMA.js';
5
5
  export { SchemaTable, VALIDATE_JSON_FIELD_NAME_ERROR_MESSAGE, applyAddPatch, applyMovePatch, applyRemovePatch, applyReplacePatch, computeValueDiff, convertJsonPathToSchemaPath, convertSchemaPathToJsonPath, createJsonObjectSchemaStore, createJsonSchemaStore, createPrimitiveStoreBySchema, deepEqual, getDBJsonPathByJsonSchemaStore, getForeignKeyPatchesFromSchema, getForeignKeysFromSchema, getForeignKeysFromValue, getInvalidFieldNamesInSchema, getJsonSchemaStoreByPath, getJsonValueStoreByPath, getParentForPath, getPathByStore, getValueByPath, hasPath, parsePath, pluginRefs, replaceForeignKeyValue, resolveRefs, saveSharedFields, setValueByPath, traverseStore, traverseValue, validateJsonFieldName } from './chunk-DJ4JPKI4.js';
6
- export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, formulaSpec, validateFormulaAgainstSchema, validateSchemaFormulas } from './chunk-5KGKN42D.js';
6
+ export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, formulaSpec, validateFormulaAgainstSchema, validateSchemaFormulas } from './chunk-R3MS2N4A.js';
7
7
  export { FieldChangeType } from './chunk-KJCURW4D.js';
8
8
  export { ajvFileSchema, ajvRowCreatedAtSchema, ajvRowCreatedIdSchema, ajvRowHashSchema, ajvRowIdSchema, ajvRowPublishedAtSchema, ajvRowSchemaHashSchema, ajvRowUpdatedAtSchema, ajvRowVersionIdSchema, fileSchema, rowCreatedAtSchema, rowCreatedIdSchema, rowHashSchema, rowIdSchema, rowPublishedAtSchema, rowSchemaHashSchema, rowUpdatedAtSchema, rowVersionIdSchema } from './chunk-LLHQWDAR.js';
9
9
  export { SystemSchemaIds } from './chunk-Q2UOTIMG.js';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkVX5C5YMF_cjs = require('../chunk-VX5C5YMF.cjs');
4
- var chunkFKKO5Y4M_cjs = require('../chunk-FKKO5Y4M.cjs');
4
+ var chunkX2VRR7V7_cjs = require('../chunk-X2VRR7V7.cjs');
5
5
  require('../chunk-GF3XXYOS.cjs');
6
6
  require('../chunk-EGC32GPY.cjs');
7
7
  require('../chunk-XNFSFT7T.cjs');
@@ -144,27 +144,27 @@ Object.defineProperty(exports, "validateJsonFieldName", {
144
144
  });
145
145
  Object.defineProperty(exports, "collectFormulaNodes", {
146
146
  enumerable: true,
147
- get: function () { return chunkFKKO5Y4M_cjs.collectFormulaNodes; }
147
+ get: function () { return chunkX2VRR7V7_cjs.collectFormulaNodes; }
148
148
  });
149
149
  Object.defineProperty(exports, "evaluateFormulas", {
150
150
  enumerable: true,
151
- get: function () { return chunkFKKO5Y4M_cjs.evaluateFormulas; }
151
+ get: function () { return chunkX2VRR7V7_cjs.evaluateFormulas; }
152
152
  });
153
153
  Object.defineProperty(exports, "extractSchemaFormulas", {
154
154
  enumerable: true,
155
- get: function () { return chunkFKKO5Y4M_cjs.extractSchemaFormulas; }
155
+ get: function () { return chunkX2VRR7V7_cjs.extractSchemaFormulas; }
156
156
  });
157
157
  Object.defineProperty(exports, "formulaSpec", {
158
158
  enumerable: true,
159
- get: function () { return chunkFKKO5Y4M_cjs.formulaSpec; }
159
+ get: function () { return chunkX2VRR7V7_cjs.formulaSpec; }
160
160
  });
161
161
  Object.defineProperty(exports, "validateFormulaAgainstSchema", {
162
162
  enumerable: true,
163
- get: function () { return chunkFKKO5Y4M_cjs.validateFormulaAgainstSchema; }
163
+ get: function () { return chunkX2VRR7V7_cjs.validateFormulaAgainstSchema; }
164
164
  });
165
165
  Object.defineProperty(exports, "validateSchemaFormulas", {
166
166
  enumerable: true,
167
- get: function () { return chunkFKKO5Y4M_cjs.validateSchemaFormulas; }
167
+ get: function () { return chunkX2VRR7V7_cjs.validateSchemaFormulas; }
168
168
  });
169
169
  Object.defineProperty(exports, "addSharedFieldsFromState", {
170
170
  enumerable: true,
package/dist/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { SchemaTable, VALIDATE_JSON_FIELD_NAME_ERROR_MESSAGE, applyAddPatch, applyMovePatch, applyRemovePatch, applyReplacePatch, computeValueDiff, convertJsonPathToSchemaPath, convertSchemaPathToJsonPath, createJsonObjectSchemaStore, createJsonSchemaStore, createPrimitiveStoreBySchema, deepEqual, getDBJsonPathByJsonSchemaStore, getForeignKeyPatchesFromSchema, getForeignKeysFromSchema, getForeignKeysFromValue, getInvalidFieldNamesInSchema, getJsonSchemaStoreByPath, getJsonValueStoreByPath, getParentForPath, getPathByStore, getValueByPath, hasPath, parsePath, pluginRefs, replaceForeignKeyValue, resolveRefs, saveSharedFields, setValueByPath, traverseStore, traverseValue, validateJsonFieldName } from '../chunk-DJ4JPKI4.js';
2
- export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, formulaSpec, validateFormulaAgainstSchema, validateSchemaFormulas } from '../chunk-5KGKN42D.js';
2
+ export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, formulaSpec, validateFormulaAgainstSchema, validateSchemaFormulas } from '../chunk-R3MS2N4A.js';
3
3
  import '../chunk-KJCURW4D.js';
4
4
  import '../chunk-LLHQWDAR.js';
5
5
  import '../chunk-Q2UOTIMG.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revisium/schema-toolkit",
3
- "version": "0.14.1",
3
+ "version": "0.14.2",
4
4
  "description": "Universal schema toolkit with TypeScript types and utilities for JSON Schema manipulation",
5
5
  "keywords": [
6
6
  "json-schema",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/extract-schema-formulas.ts","../src/lib/validate-schema-formulas.ts","../src/lib/formula.ts"],"names":["getParentPath"],"mappings":";;;;AA0BO,SAAS,sBACd,MAAA,EACoB;AACpB,EAAA,MAAM,WAA+B,EAAC;AACtC,EAAA,wBAAA,CAAyB,MAAA,EAAQ,IAAI,QAAQ,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I,CAAA;AAAA,IAC/B,CAAA,MAAO;AACL,MAAA,MAAM,GAAA,GAAM,OAAA;AACZ,MAAA,IAAI,CAAC,GAAA,CAAI,OAAA,CAAQ,KAAK,CAAA,EAAG;AACvB,QAAA,GAAA,CAAI,OAAA,CAAQ,KAAK,CAAA,GAAI,EAAC;AAAA,MACxB;AACA,MAAA,OAAA,GAAU,GAAA,CAAI,QAAQ,KAAK,CAAA;AAAA,IAC7B;AAAA,EACF;AAEA,EAAA,MAAM,WAAA,GAAc,QAAA,CAAS,EAAA,CAAG,EAAE,CAAA;AAClC,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA;AAAA,EACF;AAEA,EAAA,IAAI,WAAA,CAAY,SAAS,OAAA,EAAS;AAChC,IAAA,IAAI,CAAC,SAAA,CAAU,WAAA,CAAY,IAAI,CAAA,EAAG;AAChC,MAAA;AAAA,IACF;AACA,IAAC,OAAA,CAAoC,WAAA,CAAY,IAAI,CAAA,GAAI,KAAA;AAAA,EAC3D,CAAA,MAAO;AACL,IAAC,OAAA,CAAsB,WAAA,CAAY,KAAK,CAAA,GAAI,KAAA;AAAA,EAC9C;AACF","file":"chunk-5KGKN42D.js","sourcesContent":["interface XFormulaInput {\n version: number;\n expression: string;\n}\n\ninterface SchemaProperty {\n type?: string;\n 'x-formula'?: XFormulaInput;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\n\ninterface JsonSchemaInput {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\n\nexport interface ExtractedFormula {\n fieldName: string;\n expression: string;\n fieldType: string;\n}\n\nexport function extractSchemaFormulas(\n schema: JsonSchemaInput,\n): ExtractedFormula[] {\n const formulas: ExtractedFormula[] = [];\n extractFormulasRecursive(schema, '', formulas);\n return formulas;\n}\n\nfunction extractFormulasRecursive(\n schema: SchemaProperty | JsonSchemaInput,\n pathPrefix: string,\n formulas: ExtractedFormula[],\n): void {\n if (schema.type === 'array' && schema.items) {\n extractFormulasRecursive(schema.items, `${pathPrefix}[]`, formulas);\n return;\n }\n\n const properties = schema.properties ?? {};\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n const fullPath = pathPrefix ? `${pathPrefix}.${fieldName}` : fieldName;\n\n const xFormula = fieldSchema['x-formula'];\n if (xFormula) {\n formulas.push({\n fieldName: fullPath,\n expression: xFormula.expression,\n fieldType: fieldSchema.type ?? 'string',\n });\n }\n\n if (fieldSchema.type === 'object' && fieldSchema.properties) {\n extractFormulasRecursive(fieldSchema, fullPath, formulas);\n }\n\n if (fieldSchema.type === 'array' && fieldSchema.items) {\n extractFormulasRecursive(fieldSchema.items, `${fullPath}[]`, formulas);\n }\n }\n}\n","import {\n parseExpression,\n validateFormulaSyntax,\n buildDependencyGraph,\n detectCircularDependencies,\n inferFormulaType,\n type FieldTypes,\n type InferredType,\n} from '@revisium/formula';\nimport { extractSchemaFormulas } from './extract-schema-formulas.js';\n\ninterface SchemaProperty {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\n\ninterface JsonSchemaInput {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\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\nexport function validateSchemaFormulas(\n schema: JsonSchemaInput,\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 const parentPath = getParentPath(formula.fieldName);\n const prefix = parentPath ? `${parentPath}.` : '';\n\n dependencies[formula.fieldName] = parseResult.dependencies.map((dep) => {\n if (dep.startsWith('/')) {\n return extractFieldRoot(dep.slice(1));\n }\n if (dep.startsWith('../')) {\n return resolveRelativePathForDependency(dep, parentPath);\n }\n const rootField = extractFieldRoot(dep);\n return `${prefix}${rootField}`;\n });\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\nexport function validateFormulaAgainstSchema(\n expression: string,\n fieldName: string,\n schema: JsonSchemaInput,\n): FormulaValidationError | null {\n return validateFormulaInContext(expression, fieldName, schema);\n}\n\nfunction validateFormulaInContext(\n expression: string,\n fieldPath: string,\n rootSchema: JsonSchemaInput,\n): FormulaValidationError | null {\n const syntaxResult = validateFormulaSyntax(expression);\n if (!syntaxResult.isValid) {\n return {\n field: fieldPath,\n error: syntaxResult.error,\n position: syntaxResult.position,\n };\n }\n\n const parentPath = getParentPath(fieldPath);\n const localFieldName = getFieldName(fieldPath);\n const contextSchema = resolveSubSchema(rootSchema, parentPath);\n\n if (!contextSchema) {\n return {\n field: fieldPath,\n error: `Cannot resolve schema context for path '${parentPath}'`,\n };\n }\n\n const parseResult = parseExpression(expression);\n const localSchemaFields = getSchemaFields(contextSchema);\n const rootSchemaFields = getSchemaFields(rootSchema);\n\n for (const dep of parseResult.dependencies) {\n if (dep.startsWith('/')) {\n const rootField = extractFieldRoot(dep.slice(1));\n if (!rootSchemaFields.has(rootField)) {\n return {\n field: fieldPath,\n error: `Unknown root field '${rootField}' in formula`,\n };\n }\n } else if (dep.startsWith('../')) {\n const validationResult = validateRelativePath(\n dep,\n parentPath,\n rootSchema,\n fieldPath,\n );\n if (validationResult) {\n return validationResult;\n }\n } else {\n const rootField = extractFieldRoot(dep);\n if (!localSchemaFields.has(rootField)) {\n return {\n field: fieldPath,\n error: `Unknown field '${rootField}' in formula`,\n };\n }\n }\n }\n\n if (\n parseResult.dependencies.some((d) => extractFieldRoot(d) === localFieldName)\n ) {\n return {\n field: fieldPath,\n error: `Formula cannot reference itself`,\n };\n }\n\n const fieldSchema = contextSchema.properties?.[localFieldName];\n const expectedType = schemaTypeToInferred(fieldSchema?.type);\n const fieldTypes = getSchemaFieldTypes(contextSchema);\n const inferredType = inferFormulaType(expression, fieldTypes);\n\n if (!isTypeCompatible(inferredType, expectedType)) {\n return {\n field: fieldPath,\n error: `Type mismatch: formula returns '${inferredType}' but field expects '${expectedType}'`,\n };\n }\n\n return null;\n}\n\nfunction resolveSubSchema(\n schema: JsonSchemaInput,\n fieldPath: string,\n): SchemaProperty | null {\n if (!fieldPath) {\n return schema;\n }\n\n const segments = parsePathSegmentsForSchema(fieldPath);\n let current: SchemaProperty | JsonSchemaInput = schema;\n\n for (const segment of segments) {\n if (segment === '[]') {\n if (current.type === 'array' && current.items) {\n current = current.items;\n } else {\n return null;\n }\n } else if (current.properties?.[segment]) {\n current = current.properties[segment];\n } else {\n return null;\n }\n }\n\n return current;\n}\n\nfunction parsePathSegmentsForSchema(path: string): string[] {\n const segments: string[] = [];\n let current = '';\n let inBracket = false;\n\n for (const char of path) {\n if (char === '[') {\n if (current) {\n segments.push(current);\n current = '';\n }\n inBracket = true;\n } else if (char === ']') {\n inBracket = false;\n segments.push('[]');\n } else if (char === '.' && !inBracket) {\n if (current) {\n segments.push(current);\n current = '';\n }\n } else if (!inBracket) {\n current += char;\n }\n }\n\n if (current) {\n segments.push(current);\n }\n\n return segments;\n}\n\nfunction parsePathSegments(path: string): string[] {\n const segments: string[] = [];\n let current = '';\n let inBracket = false;\n\n for (const char of path) {\n if (char === '[') {\n if (current) {\n segments.push(current);\n current = '';\n }\n inBracket = true;\n } else if (char === ']') {\n inBracket = false;\n } else if (char === '.' && !inBracket) {\n if (current) {\n segments.push(current);\n current = '';\n }\n } else if (!inBracket) {\n current += char;\n }\n }\n\n if (current) {\n segments.push(current);\n }\n\n return segments;\n}\n\nfunction getParentPath(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n const lastBracketIndex = fieldPath.lastIndexOf('[');\n const splitIndex = Math.max(lastDotIndex, lastBracketIndex);\n\n if (splitIndex <= 0) {\n return '';\n }\n\n return fieldPath.substring(0, splitIndex);\n}\n\nfunction getFieldName(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n const lastBracketIndex = fieldPath.lastIndexOf(']');\n const splitIndex = Math.max(lastDotIndex, lastBracketIndex);\n\n if (splitIndex === -1) {\n return fieldPath;\n }\n\n return fieldPath.substring(splitIndex + 1);\n}\n\nfunction getSchemaFields(schema: SchemaProperty | JsonSchemaInput): 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: SchemaProperty | JsonSchemaInput): 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 (schemaType === 'integer') {\n fieldTypes[fieldName] = 'number';\n } else 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' || schemaType === 'integer') 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\nfunction countParentLevels(path: string): number {\n let count = 0;\n let remaining = path;\n while (remaining.startsWith('../')) {\n count++;\n remaining = remaining.slice(3);\n }\n return count;\n}\n\nfunction resolveRelativePathForDependency(\n relativePath: string,\n currentPath: string,\n): string {\n const parentLevels = countParentLevels(relativePath);\n const fieldAfterParents = relativePath.replace(/^(\\.\\.\\/)+/, '');\n const targetField = extractFieldRoot(fieldAfterParents);\n\n if (!currentPath) {\n return targetField;\n }\n\n const pathSegments = parsePathSegments(currentPath);\n const targetLevel = pathSegments.length - parentLevels;\n\n if (targetLevel <= 0) {\n return targetField;\n }\n\n const basePath = pathSegments.slice(0, targetLevel).join('.');\n return basePath ? `${basePath}.${targetField}` : targetField;\n}\n\nfunction validateRelativePath(\n relativePath: string,\n currentPath: string,\n rootSchema: JsonSchemaInput,\n fieldPath: string,\n): FormulaValidationError | null {\n const parentLevels = countParentLevels(relativePath);\n const fieldAfterParents = relativePath.replace(/^(\\.\\.\\/)+/, '');\n const targetField = extractFieldRoot(fieldAfterParents);\n\n const pathSegments = parsePathSegments(currentPath);\n const targetLevel = pathSegments.length - parentLevels;\n\n if (targetLevel <= 0) {\n const rootFields = getSchemaFields(rootSchema);\n if (!rootFields.has(targetField)) {\n return {\n field: fieldPath,\n error: `Unknown root field '${targetField}' in formula`,\n };\n }\n return null;\n }\n\n const targetPath = pathSegments.slice(0, targetLevel).join('.');\n const targetSchema = resolveSubSchema(rootSchema, targetPath);\n\n if (!targetSchema) {\n return {\n field: fieldPath,\n error: `Cannot resolve schema for relative path '${relativePath}'`,\n };\n }\n\n const targetFields = getSchemaFields(targetSchema);\n if (!targetFields.has(targetField)) {\n return {\n field: fieldPath,\n error: `Unknown field '${targetField}' in formula`,\n };\n }\n\n return null;\n}\n","import {\n parseFormula,\n evaluateWithContext,\n type ArrayContext,\n type ArrayLevelContext,\n} from '@revisium/formula';\nimport { type JsonSchema } from '../types/index.js';\n\nexport { formulaSpec } from '@revisium/formula/spec';\nexport {\n extractSchemaFormulas,\n type ExtractedFormula,\n} from './extract-schema-formulas.js';\nexport {\n validateSchemaFormulas,\n validateFormulaAgainstSchema,\n type SchemaValidationResult,\n type FormulaValidationError,\n} from './validate-schema-formulas.js';\n\ninterface ArrayLevelInfo {\n index: number;\n length: number;\n arrayPath: string;\n}\n\nexport interface FormulaNode {\n path: string;\n expression: string;\n fieldType: 'number' | 'string' | 'boolean';\n currentPath: string;\n dependencies: string[];\n arrayLevels: ArrayLevelInfo[];\n}\n\nexport interface FormulaError {\n field: string;\n expression: string;\n error: string;\n defaultUsed: boolean;\n}\n\nexport interface EvaluateFormulasResult {\n values: Record<string, unknown>;\n errors: FormulaError[];\n}\n\nexport interface EvaluateFormulasOptions {\n useDefaults?: boolean;\n defaults?: Record<string, unknown>;\n}\n\ninterface SchemaNode {\n type?: string;\n properties?: Record<string, SchemaNode>;\n items?: SchemaNode;\n 'x-formula'?: { version: number; expression: string };\n}\n\nconst FORMULA_TYPES = new Set(['number', 'string', 'boolean']);\n\ninterface TraversalContext {\n arrayLevels: ArrayLevelInfo[];\n}\n\nexport function collectFormulaNodes(\n schema: JsonSchema,\n data: Record<string, unknown>,\n): FormulaNode[] {\n const nodes: FormulaNode[] = [];\n traverseAndCollect(schema as SchemaNode, data, '', nodes, { arrayLevels: [] });\n return nodes;\n}\n\nfunction traverseAndCollect(\n schema: SchemaNode,\n data: unknown,\n currentPath: string,\n nodes: FormulaNode[],\n ctx: TraversalContext,\n): void {\n if (schema.type === 'object' && schema.properties && typeof data === 'object' && data !== null) {\n const record = data as Record<string, unknown>;\n\n for (const [fieldName, fieldSchema] of Object.entries(schema.properties)) {\n const fieldPath = currentPath ? `${currentPath}.${fieldName}` : fieldName;\n const fieldValue = record[fieldName];\n\n if (fieldSchema['x-formula'] && FORMULA_TYPES.has(fieldSchema.type ?? '')) {\n const expression = fieldSchema['x-formula'].expression;\n const parentPath = getParentPath(fieldPath);\n\n nodes.push({\n path: fieldPath,\n expression,\n fieldType: fieldSchema.type as 'number' | 'string' | 'boolean',\n currentPath: parentPath,\n dependencies: parseDependencies(expression),\n arrayLevels: [...ctx.arrayLevels],\n });\n }\n\n traverseAndCollect(fieldSchema, fieldValue, fieldPath, nodes, ctx);\n }\n }\n\n if (schema.type === 'array' && schema.items && Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const itemPath = `${currentPath}[${i}]`;\n const arrayLevel: ArrayLevelInfo = {\n index: i,\n length: data.length,\n arrayPath: currentPath,\n };\n const newCtx: TraversalContext = {\n arrayLevels: [arrayLevel, ...ctx.arrayLevels],\n };\n traverseAndCollect(schema.items, data[i], itemPath, nodes, newCtx);\n }\n }\n}\n\nfunction parseDependencies(expression: string): string[] {\n try {\n return parseFormula(expression).dependencies;\n } catch {\n return [];\n }\n}\n\nfunction getParentPath(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n if (lastDotIndex === -1) {\n return '';\n }\n return fieldPath.substring(0, lastDotIndex);\n}\n\nexport function evaluateFormulas(\n schema: JsonSchema,\n data: Record<string, unknown>,\n options: EvaluateFormulasOptions = {},\n): EvaluateFormulasResult {\n const nodes = collectFormulaNodes(schema, data);\n\n if (nodes.length === 0) {\n return { values: {}, errors: [] };\n }\n\n const sortedNodes = orderByDependencies(nodes);\n const values: Record<string, unknown> = {};\n const errors: FormulaError[] = [];\n const failedPaths = new Set<string>();\n\n for (const node of sortedNodes) {\n const hasDependencyFailure = hasFailedDependency(node, failedPaths);\n\n if (hasDependencyFailure) {\n failedPaths.add(node.path);\n handleError(node, 'Dependency formula failed', data, values, errors, options);\n continue;\n }\n\n const result = evaluateNode(node, data);\n\n if (!result.success) {\n failedPaths.add(node.path);\n handleError(node, result.error, data, values, errors, options);\n continue;\n }\n\n setValueByPath(data, node.path, result.value);\n values[node.path] = result.value;\n }\n\n return { values, errors };\n}\n\nfunction orderByDependencies(nodes: FormulaNode[]): FormulaNode[] {\n if (nodes.length <= 1) {\n return nodes;\n }\n\n const formulaNodes = new Set(nodes.map((n) => n.path));\n const visited = new Set<string>();\n const order: FormulaNode[] = [];\n\n const nodeByPath = new Map(nodes.map((n) => [n.path, n]));\n\n const visit = (node: FormulaNode, stack: Set<string>): void => {\n if (visited.has(node.path)) {\n return;\n }\n\n if (stack.has(node.path)) {\n throw new Error(`Cyclic dependency detected in formulas: ${node.path}`);\n }\n\n stack.add(node.path);\n\n for (const dep of node.dependencies) {\n if (formulaNodes.has(dep)) {\n const depNode = nodeByPath.get(dep);\n if (depNode) {\n visit(depNode, stack);\n }\n }\n }\n\n stack.delete(node.path);\n visited.add(node.path);\n order.push(node);\n };\n\n for (const node of nodes) {\n visit(node, new Set());\n }\n\n return order;\n}\n\nfunction hasFailedDependency(node: FormulaNode, failedPaths: Set<string>): boolean {\n return node.dependencies.some((dep) => {\n for (const failedPath of failedPaths) {\n if (failedPath === dep || failedPath.endsWith(`.${dep}`)) {\n return true;\n }\n }\n return false;\n });\n}\n\nfunction buildArrayContext(\n node: FormulaNode,\n data: Record<string, unknown>,\n): ArrayContext | undefined {\n if (node.arrayLevels.length === 0) {\n return undefined;\n }\n\n const levels: ArrayLevelContext[] = node.arrayLevels.map((level) => {\n const array = getValueByPath(data, level.arrayPath) as unknown[] | undefined;\n const { index, length } = level;\n\n let prev: unknown = null;\n let next: unknown = null;\n\n if (array) {\n if (index > 0) {\n prev = array[index - 1] ?? null;\n }\n if (index < length - 1) {\n next = array[index + 1] ?? null;\n }\n }\n\n return { index, length, prev, next };\n });\n\n return { levels };\n}\n\nfunction evaluateNode(\n node: FormulaNode,\n data: Record<string, unknown>,\n): { success: true; value: unknown } | { success: false; error: string } {\n try {\n const itemData = node.currentPath\n ? getValueByPath(data, node.currentPath) as Record<string, unknown> | undefined\n : undefined;\n\n const arrayContext = buildArrayContext(node, data);\n\n const result = evaluateWithContext(node.expression, {\n rootData: data,\n ...(itemData && { itemData, currentPath: node.currentPath }),\n arrayContext,\n });\n\n if (result === undefined) {\n return { success: false, error: 'Formula returned undefined' };\n }\n\n return { success: true, value: result };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\nfunction handleError(\n node: FormulaNode,\n errorMessage: string,\n data: Record<string, unknown>,\n values: Record<string, unknown>,\n errors: FormulaError[],\n options: EvaluateFormulasOptions,\n): void {\n const defaultUsed = options.useDefaults ?? false;\n\n if (defaultUsed) {\n const defaultValue = getDefaultValue(node, options.defaults);\n setValueByPath(data, node.path, defaultValue);\n values[node.path] = defaultValue;\n }\n\n errors.push({\n field: node.path,\n expression: node.expression,\n error: errorMessage,\n defaultUsed,\n });\n}\n\nfunction getDefaultValue(\n node: FormulaNode,\n defaults?: Record<string, unknown>,\n): unknown {\n if (defaults && node.path in defaults) {\n return defaults[node.path];\n }\n\n switch (node.fieldType) {\n case 'number':\n return 0;\n case 'string':\n return '';\n case 'boolean':\n return false;\n }\n}\n\nfunction getValueByPath(\n obj: Record<string, unknown>,\n path: string,\n): unknown {\n const segments = parsePath(path);\n let current: unknown = obj;\n\n for (const segment of segments) {\n if (current === null || current === undefined) {\n return undefined;\n }\n\n if (segment.type === 'field') {\n current = (current as Record<string, unknown>)[segment.name];\n } else {\n if (!Array.isArray(current)) {\n return undefined;\n }\n current = current[segment.index];\n }\n }\n\n return current;\n}\n\ntype PathSegment = { type: 'field'; name: string } | { type: 'index'; index: number };\n\nfunction parsePath(path: string): PathSegment[] {\n const segments: PathSegment[] = [];\n let current = '';\n let position = 0;\n\n while (position < path.length) {\n const char = path[position];\n\n if (char === '.') {\n if (current) {\n segments.push({ type: 'field', name: current });\n current = '';\n }\n position++;\n } else if (char === '[') {\n if (current) {\n segments.push({ type: 'field', name: current });\n current = '';\n }\n const endBracket = path.indexOf(']', position);\n if (endBracket === -1) {\n position++;\n } else {\n const indexStr = path.slice(position + 1, endBracket);\n segments.push({ type: 'index', index: Number.parseInt(indexStr, 10) });\n position = endBracket + 1;\n }\n } else {\n current += char;\n position++;\n }\n }\n\n if (current) {\n segments.push({ type: 'field', name: current });\n }\n\n return segments;\n}\n\nfunction isSafeKey(key: string): boolean {\n return key !== '__proto__';\n}\n\nfunction setValueByPath(\n obj: Record<string, unknown>,\n path: string,\n value: unknown,\n): void {\n const segments = parsePath(path);\n let current: unknown = obj;\n\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n\n if (segment.type === 'field') {\n if (!isSafeKey(segment.name)) {\n return;\n }\n const record = current as Record<string, unknown>;\n if (!(segment.name in record)) {\n record[segment.name] = {};\n }\n current = record[segment.name];\n } else {\n const arr = current as unknown[];\n if (!arr[segment.index]) {\n arr[segment.index] = {};\n }\n current = arr[segment.index];\n }\n }\n\n const lastSegment = segments.at(-1);\n if (!lastSegment) {\n return;\n }\n\n if (lastSegment.type === 'field') {\n if (!isSafeKey(lastSegment.name)) {\n return;\n }\n (current as Record<string, unknown>)[lastSegment.name] = value;\n } else {\n (current as unknown[])[lastSegment.index] = value;\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/extract-schema-formulas.ts","../src/lib/validate-schema-formulas.ts","../src/lib/formula.ts"],"names":["formula","parseExpression","buildDependencyGraph","detectCircularDependencies","validateFormulaSyntax","inferFormulaType","getParentPath","parseFormula","evaluateWithContext"],"mappings":";;;;;;AA0BO,SAAS,sBACd,MAAA,EACoB;AACpB,EAAA,MAAM,WAA+B,EAAC;AACtC,EAAA,wBAAA,CAAyB,MAAA,EAAQ,IAAI,QAAQ,CAAA;AAC7C,EAAA,OAAO,QAAA;AACT;AAEA,SAAS,wBAAA,CACP,MAAA,EACA,UAAA,EACA,QAAA,EACM;AACN,EAAA,IAAI,MAAA,CAAO,IAAA,KAAS,OAAA,IAAW,MAAA,CAAO,KAAA,EAAO;AAC3C,IAAA,wBAAA,CAAyB,MAAA,CAAO,KAAA,EAAO,CAAA,EAAG,UAAU,MAAM,QAAQ,CAAA;AAClE,IAAA;AAAA,EACF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AA,IAC7B;AAAA,EACF;AAEA,EAAA,MAAM,WAAA,GAAc,QAAA,CAAS,EAAA,CAAG,EAAE,CAAA;AAClC,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA;AAAA,EACF;AAEA,EAAA,IAAI,WAAA,CAAY,SAAS,OAAA,EAAS;AAChC,IAAA,IAAI,CAAC,SAAA,CAAU,WAAA,CAAY,IAAI,CAAA,EAAG;AAChC,MAAA;AAAA,IACF;AACA,IAAC,OAAA,CAAoC,WAAA,CAAY,IAAI,CAAA,GAAI,KAAA;AAAA,EAC3D,CAAA,MAAO;AACL,IAAC,OAAA,CAAsB,WAAA,CAAY,KAAK,CAAA,GAAI,KAAA;AAAA,EAC9C;AACF","file":"chunk-FKKO5Y4M.cjs","sourcesContent":["interface XFormulaInput {\n version: number;\n expression: string;\n}\n\ninterface SchemaProperty {\n type?: string;\n 'x-formula'?: XFormulaInput;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\n\ninterface JsonSchemaInput {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\n\nexport interface ExtractedFormula {\n fieldName: string;\n expression: string;\n fieldType: string;\n}\n\nexport function extractSchemaFormulas(\n schema: JsonSchemaInput,\n): ExtractedFormula[] {\n const formulas: ExtractedFormula[] = [];\n extractFormulasRecursive(schema, '', formulas);\n return formulas;\n}\n\nfunction extractFormulasRecursive(\n schema: SchemaProperty | JsonSchemaInput,\n pathPrefix: string,\n formulas: ExtractedFormula[],\n): void {\n if (schema.type === 'array' && schema.items) {\n extractFormulasRecursive(schema.items, `${pathPrefix}[]`, formulas);\n return;\n }\n\n const properties = schema.properties ?? {};\n\n for (const [fieldName, fieldSchema] of Object.entries(properties)) {\n const fullPath = pathPrefix ? `${pathPrefix}.${fieldName}` : fieldName;\n\n const xFormula = fieldSchema['x-formula'];\n if (xFormula) {\n formulas.push({\n fieldName: fullPath,\n expression: xFormula.expression,\n fieldType: fieldSchema.type ?? 'string',\n });\n }\n\n if (fieldSchema.type === 'object' && fieldSchema.properties) {\n extractFormulasRecursive(fieldSchema, fullPath, formulas);\n }\n\n if (fieldSchema.type === 'array' && fieldSchema.items) {\n extractFormulasRecursive(fieldSchema.items, `${fullPath}[]`, formulas);\n }\n }\n}\n","import {\n parseExpression,\n validateFormulaSyntax,\n buildDependencyGraph,\n detectCircularDependencies,\n inferFormulaType,\n type FieldTypes,\n type InferredType,\n} from '@revisium/formula';\nimport { extractSchemaFormulas } from './extract-schema-formulas.js';\n\ninterface SchemaProperty {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\n\ninterface JsonSchemaInput {\n type?: string;\n properties?: Record<string, SchemaProperty>;\n items?: SchemaProperty;\n [key: string]: unknown;\n}\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\nexport function validateSchemaFormulas(\n schema: JsonSchemaInput,\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 const parentPath = getParentPath(formula.fieldName);\n const prefix = parentPath ? `${parentPath}.` : '';\n\n dependencies[formula.fieldName] = parseResult.dependencies.map((dep) => {\n if (dep.startsWith('/')) {\n return extractFieldRoot(dep.slice(1));\n }\n if (dep.startsWith('../')) {\n return resolveRelativePathForDependency(dep, parentPath);\n }\n const rootField = extractFieldRoot(dep);\n return `${prefix}${rootField}`;\n });\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\nexport function validateFormulaAgainstSchema(\n expression: string,\n fieldName: string,\n schema: JsonSchemaInput,\n): FormulaValidationError | null {\n return validateFormulaInContext(expression, fieldName, schema);\n}\n\nfunction validateFormulaInContext(\n expression: string,\n fieldPath: string,\n rootSchema: JsonSchemaInput,\n): FormulaValidationError | null {\n const syntaxResult = validateFormulaSyntax(expression);\n if (!syntaxResult.isValid) {\n return {\n field: fieldPath,\n error: syntaxResult.error,\n position: syntaxResult.position,\n };\n }\n\n const parentPath = getParentPath(fieldPath);\n const localFieldName = getFieldName(fieldPath);\n const contextSchema = resolveSubSchema(rootSchema, parentPath);\n\n if (!contextSchema) {\n return {\n field: fieldPath,\n error: `Cannot resolve schema context for path '${parentPath}'`,\n };\n }\n\n const parseResult = parseExpression(expression);\n const localSchemaFields = getSchemaFields(contextSchema);\n const rootSchemaFields = getSchemaFields(rootSchema);\n\n for (const dep of parseResult.dependencies) {\n if (dep.startsWith('/')) {\n const rootField = extractFieldRoot(dep.slice(1));\n if (!rootSchemaFields.has(rootField)) {\n return {\n field: fieldPath,\n error: `Unknown root field '${rootField}' in formula`,\n };\n }\n } else if (dep.startsWith('../')) {\n const validationResult = validateRelativePath(\n dep,\n parentPath,\n rootSchema,\n fieldPath,\n );\n if (validationResult) {\n return validationResult;\n }\n } else {\n const rootField = extractFieldRoot(dep);\n if (!localSchemaFields.has(rootField)) {\n return {\n field: fieldPath,\n error: `Unknown field '${rootField}' in formula`,\n };\n }\n }\n }\n\n if (\n parseResult.dependencies.some((d) => extractFieldRoot(d) === localFieldName)\n ) {\n return {\n field: fieldPath,\n error: `Formula cannot reference itself`,\n };\n }\n\n const fieldSchema = contextSchema.properties?.[localFieldName];\n const expectedType = schemaTypeToInferred(fieldSchema?.type);\n const fieldTypes = getSchemaFieldTypes(contextSchema);\n const inferredType = inferFormulaType(expression, fieldTypes);\n\n if (!isTypeCompatible(inferredType, expectedType)) {\n return {\n field: fieldPath,\n error: `Type mismatch: formula returns '${inferredType}' but field expects '${expectedType}'`,\n };\n }\n\n return null;\n}\n\nfunction resolveSubSchema(\n schema: JsonSchemaInput,\n fieldPath: string,\n): SchemaProperty | null {\n if (!fieldPath) {\n return schema;\n }\n\n const segments = parsePathSegmentsForSchema(fieldPath);\n let current: SchemaProperty | JsonSchemaInput = schema;\n\n for (const segment of segments) {\n if (segment === '[]') {\n if (current.type === 'array' && current.items) {\n current = current.items;\n } else {\n return null;\n }\n } else if (current.properties?.[segment]) {\n current = current.properties[segment];\n } else {\n return null;\n }\n }\n\n return current;\n}\n\nfunction parsePathSegmentsForSchema(path: string): string[] {\n const segments: string[] = [];\n let current = '';\n let inBracket = false;\n\n for (const char of path) {\n if (char === '[') {\n if (current) {\n segments.push(current);\n current = '';\n }\n inBracket = true;\n } else if (char === ']') {\n inBracket = false;\n segments.push('[]');\n } else if (char === '.' && !inBracket) {\n if (current) {\n segments.push(current);\n current = '';\n }\n } else if (!inBracket) {\n current += char;\n }\n }\n\n if (current) {\n segments.push(current);\n }\n\n return segments;\n}\n\nfunction parsePathSegments(path: string): string[] {\n const segments: string[] = [];\n let current = '';\n let inBracket = false;\n\n for (const char of path) {\n if (char === '[') {\n if (current) {\n segments.push(current);\n current = '';\n }\n inBracket = true;\n } else if (char === ']') {\n inBracket = false;\n } else if (char === '.' && !inBracket) {\n if (current) {\n segments.push(current);\n current = '';\n }\n } else if (!inBracket) {\n current += char;\n }\n }\n\n if (current) {\n segments.push(current);\n }\n\n return segments;\n}\n\nfunction getParentPath(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n const lastBracketIndex = fieldPath.lastIndexOf('[');\n const splitIndex = Math.max(lastDotIndex, lastBracketIndex);\n\n if (splitIndex <= 0) {\n return '';\n }\n\n return fieldPath.substring(0, splitIndex);\n}\n\nfunction getFieldName(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n const lastBracketIndex = fieldPath.lastIndexOf(']');\n const splitIndex = Math.max(lastDotIndex, lastBracketIndex);\n\n if (splitIndex === -1) {\n return fieldPath;\n }\n\n return fieldPath.substring(splitIndex + 1);\n}\n\nfunction getSchemaFields(schema: SchemaProperty | JsonSchemaInput): 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: SchemaProperty | JsonSchemaInput): 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 (schemaType === 'integer') {\n fieldTypes[fieldName] = 'number';\n } else 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' || schemaType === 'integer') 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\nfunction countParentLevels(path: string): number {\n let count = 0;\n let remaining = path;\n while (remaining.startsWith('../')) {\n count++;\n remaining = remaining.slice(3);\n }\n return count;\n}\n\nfunction resolveRelativePathForDependency(\n relativePath: string,\n currentPath: string,\n): string {\n const parentLevels = countParentLevels(relativePath);\n const fieldAfterParents = relativePath.replace(/^(\\.\\.\\/)+/, '');\n const targetField = extractFieldRoot(fieldAfterParents);\n\n if (!currentPath) {\n return targetField;\n }\n\n const pathSegments = parsePathSegments(currentPath);\n const targetLevel = pathSegments.length - parentLevels;\n\n if (targetLevel <= 0) {\n return targetField;\n }\n\n const basePath = pathSegments.slice(0, targetLevel).join('.');\n return basePath ? `${basePath}.${targetField}` : targetField;\n}\n\nfunction validateRelativePath(\n relativePath: string,\n currentPath: string,\n rootSchema: JsonSchemaInput,\n fieldPath: string,\n): FormulaValidationError | null {\n const parentLevels = countParentLevels(relativePath);\n const fieldAfterParents = relativePath.replace(/^(\\.\\.\\/)+/, '');\n const targetField = extractFieldRoot(fieldAfterParents);\n\n const pathSegments = parsePathSegments(currentPath);\n const targetLevel = pathSegments.length - parentLevels;\n\n if (targetLevel <= 0) {\n const rootFields = getSchemaFields(rootSchema);\n if (!rootFields.has(targetField)) {\n return {\n field: fieldPath,\n error: `Unknown root field '${targetField}' in formula`,\n };\n }\n return null;\n }\n\n const targetPath = pathSegments.slice(0, targetLevel).join('.');\n const targetSchema = resolveSubSchema(rootSchema, targetPath);\n\n if (!targetSchema) {\n return {\n field: fieldPath,\n error: `Cannot resolve schema for relative path '${relativePath}'`,\n };\n }\n\n const targetFields = getSchemaFields(targetSchema);\n if (!targetFields.has(targetField)) {\n return {\n field: fieldPath,\n error: `Unknown field '${targetField}' in formula`,\n };\n }\n\n return null;\n}\n","import {\n parseFormula,\n evaluateWithContext,\n type ArrayContext,\n type ArrayLevelContext,\n} from '@revisium/formula';\nimport { type JsonSchema } from '../types/index.js';\n\nexport { formulaSpec } from '@revisium/formula/spec';\nexport {\n extractSchemaFormulas,\n type ExtractedFormula,\n} from './extract-schema-formulas.js';\nexport {\n validateSchemaFormulas,\n validateFormulaAgainstSchema,\n type SchemaValidationResult,\n type FormulaValidationError,\n} from './validate-schema-formulas.js';\n\ninterface ArrayLevelInfo {\n index: number;\n length: number;\n arrayPath: string;\n}\n\nexport interface FormulaNode {\n path: string;\n expression: string;\n fieldType: 'number' | 'string' | 'boolean';\n currentPath: string;\n dependencies: string[];\n arrayLevels: ArrayLevelInfo[];\n}\n\nexport interface FormulaError {\n field: string;\n expression: string;\n error: string;\n defaultUsed: boolean;\n}\n\nexport interface EvaluateFormulasResult {\n values: Record<string, unknown>;\n errors: FormulaError[];\n}\n\nexport interface EvaluateFormulasOptions {\n useDefaults?: boolean;\n defaults?: Record<string, unknown>;\n}\n\ninterface SchemaNode {\n type?: string;\n properties?: Record<string, SchemaNode>;\n items?: SchemaNode;\n 'x-formula'?: { version: number; expression: string };\n}\n\nconst FORMULA_TYPES = new Set(['number', 'string', 'boolean']);\n\ninterface TraversalContext {\n arrayLevels: ArrayLevelInfo[];\n}\n\nexport function collectFormulaNodes(\n schema: JsonSchema,\n data: Record<string, unknown>,\n): FormulaNode[] {\n const nodes: FormulaNode[] = [];\n traverseAndCollect(schema as SchemaNode, data, '', nodes, { arrayLevels: [] });\n return nodes;\n}\n\nfunction traverseAndCollect(\n schema: SchemaNode,\n data: unknown,\n currentPath: string,\n nodes: FormulaNode[],\n ctx: TraversalContext,\n): void {\n if (schema.type === 'object' && schema.properties && typeof data === 'object' && data !== null) {\n const record = data as Record<string, unknown>;\n\n for (const [fieldName, fieldSchema] of Object.entries(schema.properties)) {\n const fieldPath = currentPath ? `${currentPath}.${fieldName}` : fieldName;\n const fieldValue = record[fieldName];\n\n if (fieldSchema['x-formula'] && FORMULA_TYPES.has(fieldSchema.type ?? '')) {\n const expression = fieldSchema['x-formula'].expression;\n const parentPath = getParentPath(fieldPath);\n\n nodes.push({\n path: fieldPath,\n expression,\n fieldType: fieldSchema.type as 'number' | 'string' | 'boolean',\n currentPath: parentPath,\n dependencies: parseDependencies(expression),\n arrayLevels: [...ctx.arrayLevels],\n });\n }\n\n traverseAndCollect(fieldSchema, fieldValue, fieldPath, nodes, ctx);\n }\n }\n\n if (schema.type === 'array' && schema.items && Array.isArray(data)) {\n for (let i = 0; i < data.length; i++) {\n const itemPath = `${currentPath}[${i}]`;\n const arrayLevel: ArrayLevelInfo = {\n index: i,\n length: data.length,\n arrayPath: currentPath,\n };\n const newCtx: TraversalContext = {\n arrayLevels: [arrayLevel, ...ctx.arrayLevels],\n };\n traverseAndCollect(schema.items, data[i], itemPath, nodes, newCtx);\n }\n }\n}\n\nfunction parseDependencies(expression: string): string[] {\n try {\n return parseFormula(expression).dependencies;\n } catch {\n return [];\n }\n}\n\nfunction getParentPath(fieldPath: string): string {\n const lastDotIndex = fieldPath.lastIndexOf('.');\n if (lastDotIndex === -1) {\n return '';\n }\n return fieldPath.substring(0, lastDotIndex);\n}\n\nexport function evaluateFormulas(\n schema: JsonSchema,\n data: Record<string, unknown>,\n options: EvaluateFormulasOptions = {},\n): EvaluateFormulasResult {\n const nodes = collectFormulaNodes(schema, data);\n\n if (nodes.length === 0) {\n return { values: {}, errors: [] };\n }\n\n const sortedNodes = orderByDependencies(nodes);\n const values: Record<string, unknown> = {};\n const errors: FormulaError[] = [];\n const failedPaths = new Set<string>();\n\n for (const node of sortedNodes) {\n const hasDependencyFailure = hasFailedDependency(node, failedPaths);\n\n if (hasDependencyFailure) {\n failedPaths.add(node.path);\n handleError(node, 'Dependency formula failed', data, values, errors, options);\n continue;\n }\n\n const result = evaluateNode(node, data);\n\n if (!result.success) {\n failedPaths.add(node.path);\n handleError(node, result.error, data, values, errors, options);\n continue;\n }\n\n setValueByPath(data, node.path, result.value);\n values[node.path] = result.value;\n }\n\n return { values, errors };\n}\n\nfunction orderByDependencies(nodes: FormulaNode[]): FormulaNode[] {\n if (nodes.length <= 1) {\n return nodes;\n }\n\n const formulaNodes = new Set(nodes.map((n) => n.path));\n const visited = new Set<string>();\n const order: FormulaNode[] = [];\n\n const nodeByPath = new Map(nodes.map((n) => [n.path, n]));\n\n const visit = (node: FormulaNode, stack: Set<string>): void => {\n if (visited.has(node.path)) {\n return;\n }\n\n if (stack.has(node.path)) {\n throw new Error(`Cyclic dependency detected in formulas: ${node.path}`);\n }\n\n stack.add(node.path);\n\n for (const dep of node.dependencies) {\n if (formulaNodes.has(dep)) {\n const depNode = nodeByPath.get(dep);\n if (depNode) {\n visit(depNode, stack);\n }\n }\n }\n\n stack.delete(node.path);\n visited.add(node.path);\n order.push(node);\n };\n\n for (const node of nodes) {\n visit(node, new Set());\n }\n\n return order;\n}\n\nfunction hasFailedDependency(node: FormulaNode, failedPaths: Set<string>): boolean {\n return node.dependencies.some((dep) => {\n for (const failedPath of failedPaths) {\n if (failedPath === dep || failedPath.endsWith(`.${dep}`)) {\n return true;\n }\n }\n return false;\n });\n}\n\nfunction buildArrayContext(\n node: FormulaNode,\n data: Record<string, unknown>,\n): ArrayContext | undefined {\n if (node.arrayLevels.length === 0) {\n return undefined;\n }\n\n const levels: ArrayLevelContext[] = node.arrayLevels.map((level) => {\n const array = getValueByPath(data, level.arrayPath) as unknown[] | undefined;\n const { index, length } = level;\n\n let prev: unknown = null;\n let next: unknown = null;\n\n if (array) {\n if (index > 0) {\n prev = array[index - 1] ?? null;\n }\n if (index < length - 1) {\n next = array[index + 1] ?? null;\n }\n }\n\n return { index, length, prev, next };\n });\n\n return { levels };\n}\n\nfunction evaluateNode(\n node: FormulaNode,\n data: Record<string, unknown>,\n): { success: true; value: unknown } | { success: false; error: string } {\n try {\n const itemData = node.currentPath\n ? getValueByPath(data, node.currentPath) as Record<string, unknown> | undefined\n : undefined;\n\n const arrayContext = buildArrayContext(node, data);\n\n const result = evaluateWithContext(node.expression, {\n rootData: data,\n ...(itemData && { itemData, currentPath: node.currentPath }),\n arrayContext,\n });\n\n if (result === undefined) {\n return { success: false, error: 'Formula returned undefined' };\n }\n\n return { success: true, value: result };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\nfunction handleError(\n node: FormulaNode,\n errorMessage: string,\n data: Record<string, unknown>,\n values: Record<string, unknown>,\n errors: FormulaError[],\n options: EvaluateFormulasOptions,\n): void {\n const defaultUsed = options.useDefaults ?? false;\n\n if (defaultUsed) {\n const defaultValue = getDefaultValue(node, options.defaults);\n setValueByPath(data, node.path, defaultValue);\n values[node.path] = defaultValue;\n }\n\n errors.push({\n field: node.path,\n expression: node.expression,\n error: errorMessage,\n defaultUsed,\n });\n}\n\nfunction getDefaultValue(\n node: FormulaNode,\n defaults?: Record<string, unknown>,\n): unknown {\n if (defaults && node.path in defaults) {\n return defaults[node.path];\n }\n\n switch (node.fieldType) {\n case 'number':\n return 0;\n case 'string':\n return '';\n case 'boolean':\n return false;\n }\n}\n\nfunction getValueByPath(\n obj: Record<string, unknown>,\n path: string,\n): unknown {\n const segments = parsePath(path);\n let current: unknown = obj;\n\n for (const segment of segments) {\n if (current === null || current === undefined) {\n return undefined;\n }\n\n if (segment.type === 'field') {\n current = (current as Record<string, unknown>)[segment.name];\n } else {\n if (!Array.isArray(current)) {\n return undefined;\n }\n current = current[segment.index];\n }\n }\n\n return current;\n}\n\ntype PathSegment = { type: 'field'; name: string } | { type: 'index'; index: number };\n\nfunction parsePath(path: string): PathSegment[] {\n const segments: PathSegment[] = [];\n let current = '';\n let position = 0;\n\n while (position < path.length) {\n const char = path[position];\n\n if (char === '.') {\n if (current) {\n segments.push({ type: 'field', name: current });\n current = '';\n }\n position++;\n } else if (char === '[') {\n if (current) {\n segments.push({ type: 'field', name: current });\n current = '';\n }\n const endBracket = path.indexOf(']', position);\n if (endBracket === -1) {\n position++;\n } else {\n const indexStr = path.slice(position + 1, endBracket);\n segments.push({ type: 'index', index: Number.parseInt(indexStr, 10) });\n position = endBracket + 1;\n }\n } else {\n current += char;\n position++;\n }\n }\n\n if (current) {\n segments.push({ type: 'field', name: current });\n }\n\n return segments;\n}\n\nfunction isSafeKey(key: string): boolean {\n return key !== '__proto__';\n}\n\nfunction setValueByPath(\n obj: Record<string, unknown>,\n path: string,\n value: unknown,\n): void {\n const segments = parsePath(path);\n let current: unknown = obj;\n\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n\n if (segment.type === 'field') {\n if (!isSafeKey(segment.name)) {\n return;\n }\n const record = current as Record<string, unknown>;\n if (!(segment.name in record)) {\n record[segment.name] = {};\n }\n current = record[segment.name];\n } else {\n const arr = current as unknown[];\n if (!arr[segment.index]) {\n arr[segment.index] = {};\n }\n current = arr[segment.index];\n }\n }\n\n const lastSegment = segments.at(-1);\n if (!lastSegment) {\n return;\n }\n\n if (lastSegment.type === 'field') {\n if (!isSafeKey(lastSegment.name)) {\n return;\n }\n (current as Record<string, unknown>)[lastSegment.name] = value;\n } else {\n (current as unknown[])[lastSegment.index] = value;\n }\n}\n"]}