@revisium/schema-toolkit 0.13.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-I2ECBDBM.js → chunk-5KGKN42D.js} +68 -19
- package/dist/chunk-5KGKN42D.js.map +1 -0
- package/dist/{chunk-HZW3UZAB.cjs → chunk-FKKO5Y4M.cjs} +67 -18
- package/dist/chunk-FKKO5Y4M.cjs.map +1 -0
- package/dist/formula/index.cjs +7 -7
- package/dist/formula/index.d.cts +6 -0
- package/dist/formula/index.d.ts +6 -0
- package/dist/formula/index.js +1 -1
- package/dist/index.cjs +7 -7
- package/dist/index.js +1 -1
- package/dist/lib/index.cjs +7 -7
- package/dist/lib/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-HZW3UZAB.cjs.map +0 -1
- package/dist/chunk-I2ECBDBM.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseExpression, buildDependencyGraph, detectCircularDependencies, validateFormulaSyntax, inferFormulaType, parseFormula,
|
|
1
|
+
import { parseExpression, buildDependencyGraph, detectCircularDependencies, validateFormulaSyntax, inferFormulaType, parseFormula, evaluateWithContext } from '@revisium/formula';
|
|
2
2
|
export { formulaSpec } from '@revisium/formula/spec';
|
|
3
3
|
|
|
4
4
|
// src/lib/extract-schema-formulas.ts
|
|
@@ -339,10 +339,10 @@ function validateRelativePath(relativePath, currentPath, rootSchema, fieldPath)
|
|
|
339
339
|
var FORMULA_TYPES = /* @__PURE__ */ new Set(["number", "string", "boolean"]);
|
|
340
340
|
function collectFormulaNodes(schema, data) {
|
|
341
341
|
const nodes = [];
|
|
342
|
-
traverseAndCollect(schema, data, "", nodes);
|
|
342
|
+
traverseAndCollect(schema, data, "", nodes, { arrayLevels: [] });
|
|
343
343
|
return nodes;
|
|
344
344
|
}
|
|
345
|
-
function traverseAndCollect(schema, data, currentPath, nodes) {
|
|
345
|
+
function traverseAndCollect(schema, data, currentPath, nodes, ctx) {
|
|
346
346
|
if (schema.type === "object" && schema.properties && typeof data === "object" && data !== null) {
|
|
347
347
|
const record = data;
|
|
348
348
|
for (const [fieldName, fieldSchema] of Object.entries(schema.properties)) {
|
|
@@ -356,16 +356,25 @@ function traverseAndCollect(schema, data, currentPath, nodes) {
|
|
|
356
356
|
expression,
|
|
357
357
|
fieldType: fieldSchema.type,
|
|
358
358
|
currentPath: parentPath,
|
|
359
|
-
dependencies: parseDependencies(expression)
|
|
359
|
+
dependencies: parseDependencies(expression),
|
|
360
|
+
arrayLevels: [...ctx.arrayLevels]
|
|
360
361
|
});
|
|
361
362
|
}
|
|
362
|
-
traverseAndCollect(fieldSchema, fieldValue, fieldPath, nodes);
|
|
363
|
+
traverseAndCollect(fieldSchema, fieldValue, fieldPath, nodes, ctx);
|
|
363
364
|
}
|
|
364
365
|
}
|
|
365
366
|
if (schema.type === "array" && schema.items && Array.isArray(data)) {
|
|
366
367
|
for (let i = 0; i < data.length; i++) {
|
|
367
368
|
const itemPath = `${currentPath}[${i}]`;
|
|
368
|
-
|
|
369
|
+
const arrayLevel = {
|
|
370
|
+
index: i,
|
|
371
|
+
length: data.length,
|
|
372
|
+
arrayPath: currentPath
|
|
373
|
+
};
|
|
374
|
+
const newCtx = {
|
|
375
|
+
arrayLevels: [arrayLevel, ...ctx.arrayLevels]
|
|
376
|
+
};
|
|
377
|
+
traverseAndCollect(schema.items, data[i], itemPath, nodes, newCtx);
|
|
369
378
|
}
|
|
370
379
|
}
|
|
371
380
|
}
|
|
@@ -414,17 +423,34 @@ function orderByDependencies(nodes) {
|
|
|
414
423
|
if (nodes.length <= 1) {
|
|
415
424
|
return nodes;
|
|
416
425
|
}
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
426
|
+
const formulaNodes = new Set(nodes.map((n) => n.path));
|
|
427
|
+
const visited = /* @__PURE__ */ new Set();
|
|
428
|
+
const order = [];
|
|
429
|
+
const nodeByPath = new Map(nodes.map((n) => [n.path, n]));
|
|
430
|
+
const visit = (node, stack) => {
|
|
431
|
+
if (visited.has(node.path)) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (stack.has(node.path)) {
|
|
435
|
+
throw new Error(`Cyclic dependency detected in formulas: ${node.path}`);
|
|
436
|
+
}
|
|
437
|
+
stack.add(node.path);
|
|
438
|
+
for (const dep of node.dependencies) {
|
|
439
|
+
if (formulaNodes.has(dep)) {
|
|
440
|
+
const depNode = nodeByPath.get(dep);
|
|
441
|
+
if (depNode) {
|
|
442
|
+
visit(depNode, stack);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
stack.delete(node.path);
|
|
447
|
+
visited.add(node.path);
|
|
448
|
+
order.push(node);
|
|
449
|
+
};
|
|
450
|
+
for (const node of nodes) {
|
|
451
|
+
visit(node, /* @__PURE__ */ new Set());
|
|
425
452
|
}
|
|
426
|
-
|
|
427
|
-
return result.order.map((path) => nodeMap.get(path)).filter((n) => n !== void 0);
|
|
453
|
+
return order;
|
|
428
454
|
}
|
|
429
455
|
function hasFailedDependency(node, failedPaths) {
|
|
430
456
|
return node.dependencies.some((dep) => {
|
|
@@ -436,12 +462,35 @@ function hasFailedDependency(node, failedPaths) {
|
|
|
436
462
|
return false;
|
|
437
463
|
});
|
|
438
464
|
}
|
|
465
|
+
function buildArrayContext(node, data) {
|
|
466
|
+
if (node.arrayLevels.length === 0) {
|
|
467
|
+
return void 0;
|
|
468
|
+
}
|
|
469
|
+
const levels = node.arrayLevels.map((level) => {
|
|
470
|
+
const array = getValueByPath(data, level.arrayPath);
|
|
471
|
+
const { index, length } = level;
|
|
472
|
+
let prev = null;
|
|
473
|
+
let next = null;
|
|
474
|
+
if (array) {
|
|
475
|
+
if (index > 0) {
|
|
476
|
+
prev = array[index - 1] ?? null;
|
|
477
|
+
}
|
|
478
|
+
if (index < length - 1) {
|
|
479
|
+
next = array[index + 1] ?? null;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return { index, length, prev, next };
|
|
483
|
+
});
|
|
484
|
+
return { levels };
|
|
485
|
+
}
|
|
439
486
|
function evaluateNode(node, data) {
|
|
440
487
|
try {
|
|
441
488
|
const itemData = node.currentPath ? getValueByPath(data, node.currentPath) : void 0;
|
|
489
|
+
const arrayContext = buildArrayContext(node, data);
|
|
442
490
|
const result = evaluateWithContext(node.expression, {
|
|
443
491
|
rootData: data,
|
|
444
|
-
...itemData && { itemData, currentPath: node.currentPath }
|
|
492
|
+
...itemData && { itemData, currentPath: node.currentPath },
|
|
493
|
+
arrayContext
|
|
445
494
|
});
|
|
446
495
|
if (result === void 0) {
|
|
447
496
|
return { success: false, error: "Formula returned undefined" };
|
|
@@ -574,5 +623,5 @@ function setValueByPath(obj, path, value) {
|
|
|
574
623
|
}
|
|
575
624
|
|
|
576
625
|
export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, validateFormulaAgainstSchema, validateSchemaFormulas };
|
|
577
|
-
//# sourceMappingURL=chunk-
|
|
578
|
-
//# sourceMappingURL=chunk-
|
|
626
|
+
//# sourceMappingURL=chunk-5KGKN42D.js.map
|
|
627
|
+
//# sourceMappingURL=chunk-5KGKN42D.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,C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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"]}
|
|
@@ -341,10 +341,10 @@ function validateRelativePath(relativePath, currentPath, rootSchema, fieldPath)
|
|
|
341
341
|
var FORMULA_TYPES = /* @__PURE__ */ new Set(["number", "string", "boolean"]);
|
|
342
342
|
function collectFormulaNodes(schema, data) {
|
|
343
343
|
const nodes = [];
|
|
344
|
-
traverseAndCollect(schema, data, "", nodes);
|
|
344
|
+
traverseAndCollect(schema, data, "", nodes, { arrayLevels: [] });
|
|
345
345
|
return nodes;
|
|
346
346
|
}
|
|
347
|
-
function traverseAndCollect(schema, data, currentPath, nodes) {
|
|
347
|
+
function traverseAndCollect(schema, data, currentPath, nodes, ctx) {
|
|
348
348
|
if (schema.type === "object" && schema.properties && typeof data === "object" && data !== null) {
|
|
349
349
|
const record = data;
|
|
350
350
|
for (const [fieldName, fieldSchema] of Object.entries(schema.properties)) {
|
|
@@ -358,16 +358,25 @@ function traverseAndCollect(schema, data, currentPath, nodes) {
|
|
|
358
358
|
expression,
|
|
359
359
|
fieldType: fieldSchema.type,
|
|
360
360
|
currentPath: parentPath,
|
|
361
|
-
dependencies: parseDependencies(expression)
|
|
361
|
+
dependencies: parseDependencies(expression),
|
|
362
|
+
arrayLevels: [...ctx.arrayLevels]
|
|
362
363
|
});
|
|
363
364
|
}
|
|
364
|
-
traverseAndCollect(fieldSchema, fieldValue, fieldPath, nodes);
|
|
365
|
+
traverseAndCollect(fieldSchema, fieldValue, fieldPath, nodes, ctx);
|
|
365
366
|
}
|
|
366
367
|
}
|
|
367
368
|
if (schema.type === "array" && schema.items && Array.isArray(data)) {
|
|
368
369
|
for (let i = 0; i < data.length; i++) {
|
|
369
370
|
const itemPath = `${currentPath}[${i}]`;
|
|
370
|
-
|
|
371
|
+
const arrayLevel = {
|
|
372
|
+
index: i,
|
|
373
|
+
length: data.length,
|
|
374
|
+
arrayPath: currentPath
|
|
375
|
+
};
|
|
376
|
+
const newCtx = {
|
|
377
|
+
arrayLevels: [arrayLevel, ...ctx.arrayLevels]
|
|
378
|
+
};
|
|
379
|
+
traverseAndCollect(schema.items, data[i], itemPath, nodes, newCtx);
|
|
371
380
|
}
|
|
372
381
|
}
|
|
373
382
|
}
|
|
@@ -416,17 +425,34 @@ function orderByDependencies(nodes) {
|
|
|
416
425
|
if (nodes.length <= 1) {
|
|
417
426
|
return nodes;
|
|
418
427
|
}
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
428
|
+
const formulaNodes = new Set(nodes.map((n) => n.path));
|
|
429
|
+
const visited = /* @__PURE__ */ new Set();
|
|
430
|
+
const order = [];
|
|
431
|
+
const nodeByPath = new Map(nodes.map((n) => [n.path, n]));
|
|
432
|
+
const visit = (node, stack) => {
|
|
433
|
+
if (visited.has(node.path)) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (stack.has(node.path)) {
|
|
437
|
+
throw new Error(`Cyclic dependency detected in formulas: ${node.path}`);
|
|
438
|
+
}
|
|
439
|
+
stack.add(node.path);
|
|
440
|
+
for (const dep of node.dependencies) {
|
|
441
|
+
if (formulaNodes.has(dep)) {
|
|
442
|
+
const depNode = nodeByPath.get(dep);
|
|
443
|
+
if (depNode) {
|
|
444
|
+
visit(depNode, stack);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
stack.delete(node.path);
|
|
449
|
+
visited.add(node.path);
|
|
450
|
+
order.push(node);
|
|
451
|
+
};
|
|
452
|
+
for (const node of nodes) {
|
|
453
|
+
visit(node, /* @__PURE__ */ new Set());
|
|
427
454
|
}
|
|
428
|
-
|
|
429
|
-
return result.order.map((path) => nodeMap.get(path)).filter((n) => n !== void 0);
|
|
455
|
+
return order;
|
|
430
456
|
}
|
|
431
457
|
function hasFailedDependency(node, failedPaths) {
|
|
432
458
|
return node.dependencies.some((dep) => {
|
|
@@ -438,12 +464,35 @@ function hasFailedDependency(node, failedPaths) {
|
|
|
438
464
|
return false;
|
|
439
465
|
});
|
|
440
466
|
}
|
|
467
|
+
function buildArrayContext(node, data) {
|
|
468
|
+
if (node.arrayLevels.length === 0) {
|
|
469
|
+
return void 0;
|
|
470
|
+
}
|
|
471
|
+
const levels = node.arrayLevels.map((level) => {
|
|
472
|
+
const array = getValueByPath(data, level.arrayPath);
|
|
473
|
+
const { index, length } = level;
|
|
474
|
+
let prev = null;
|
|
475
|
+
let next = null;
|
|
476
|
+
if (array) {
|
|
477
|
+
if (index > 0) {
|
|
478
|
+
prev = array[index - 1] ?? null;
|
|
479
|
+
}
|
|
480
|
+
if (index < length - 1) {
|
|
481
|
+
next = array[index + 1] ?? null;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return { index, length, prev, next };
|
|
485
|
+
});
|
|
486
|
+
return { levels };
|
|
487
|
+
}
|
|
441
488
|
function evaluateNode(node, data) {
|
|
442
489
|
try {
|
|
443
490
|
const itemData = node.currentPath ? getValueByPath(data, node.currentPath) : void 0;
|
|
491
|
+
const arrayContext = buildArrayContext(node, data);
|
|
444
492
|
const result = formula.evaluateWithContext(node.expression, {
|
|
445
493
|
rootData: data,
|
|
446
|
-
...itemData && { itemData, currentPath: node.currentPath }
|
|
494
|
+
...itemData && { itemData, currentPath: node.currentPath },
|
|
495
|
+
arrayContext
|
|
447
496
|
});
|
|
448
497
|
if (result === void 0) {
|
|
449
498
|
return { success: false, error: "Formula returned undefined" };
|
|
@@ -584,5 +633,5 @@ exports.evaluateFormulas = evaluateFormulas;
|
|
|
584
633
|
exports.extractSchemaFormulas = extractSchemaFormulas;
|
|
585
634
|
exports.validateFormulaAgainstSchema = validateFormulaAgainstSchema;
|
|
586
635
|
exports.validateSchemaFormulas = validateSchemaFormulas;
|
|
587
|
-
//# sourceMappingURL=chunk-
|
|
588
|
-
//# sourceMappingURL=chunk-
|
|
636
|
+
//# sourceMappingURL=chunk-FKKO5Y4M.cjs.map
|
|
637
|
+
//# sourceMappingURL=chunk-FKKO5Y4M.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,IAAA,MAAM,WAAW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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"]}
|
package/dist/formula/index.cjs
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkFKKO5Y4M_cjs = require('../chunk-FKKO5Y4M.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "collectFormulaNodes", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkFKKO5Y4M_cjs.collectFormulaNodes; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "evaluateFormulas", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkFKKO5Y4M_cjs.evaluateFormulas; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "extractSchemaFormulas", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkFKKO5Y4M_cjs.extractSchemaFormulas; }
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, "formulaSpec", {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
21
|
+
get: function () { return chunkFKKO5Y4M_cjs.formulaSpec; }
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(exports, "validateFormulaAgainstSchema", {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
25
|
+
get: function () { return chunkFKKO5Y4M_cjs.validateFormulaAgainstSchema; }
|
|
26
26
|
});
|
|
27
27
|
Object.defineProperty(exports, "validateSchemaFormulas", {
|
|
28
28
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
29
|
+
get: function () { return chunkFKKO5Y4M_cjs.validateSchemaFormulas; }
|
|
30
30
|
});
|
|
31
31
|
//# sourceMappingURL=index.cjs.map
|
|
32
32
|
//# sourceMappingURL=index.cjs.map
|
package/dist/formula/index.d.cts
CHANGED
|
@@ -49,12 +49,18 @@ interface SchemaValidationResult {
|
|
|
49
49
|
declare function validateSchemaFormulas(schema: JsonSchemaInput): SchemaValidationResult;
|
|
50
50
|
declare function validateFormulaAgainstSchema(expression: string, fieldName: string, schema: JsonSchemaInput): FormulaValidationError | null;
|
|
51
51
|
|
|
52
|
+
interface ArrayLevelInfo {
|
|
53
|
+
index: number;
|
|
54
|
+
length: number;
|
|
55
|
+
arrayPath: string;
|
|
56
|
+
}
|
|
52
57
|
interface FormulaNode {
|
|
53
58
|
path: string;
|
|
54
59
|
expression: string;
|
|
55
60
|
fieldType: 'number' | 'string' | 'boolean';
|
|
56
61
|
currentPath: string;
|
|
57
62
|
dependencies: string[];
|
|
63
|
+
arrayLevels: ArrayLevelInfo[];
|
|
58
64
|
}
|
|
59
65
|
interface FormulaError {
|
|
60
66
|
field: string;
|
package/dist/formula/index.d.ts
CHANGED
|
@@ -49,12 +49,18 @@ interface SchemaValidationResult {
|
|
|
49
49
|
declare function validateSchemaFormulas(schema: JsonSchemaInput): SchemaValidationResult;
|
|
50
50
|
declare function validateFormulaAgainstSchema(expression: string, fieldName: string, schema: JsonSchemaInput): FormulaValidationError | null;
|
|
51
51
|
|
|
52
|
+
interface ArrayLevelInfo {
|
|
53
|
+
index: number;
|
|
54
|
+
length: number;
|
|
55
|
+
arrayPath: string;
|
|
56
|
+
}
|
|
52
57
|
interface FormulaNode {
|
|
53
58
|
path: string;
|
|
54
59
|
expression: string;
|
|
55
60
|
fieldType: 'number' | 'string' | 'boolean';
|
|
56
61
|
currentPath: string;
|
|
57
62
|
dependencies: string[];
|
|
63
|
+
arrayLevels: ArrayLevelInfo[];
|
|
58
64
|
}
|
|
59
65
|
interface FormulaError {
|
|
60
66
|
field: string;
|
package/dist/formula/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, formulaSpec, validateFormulaAgainstSchema, validateSchemaFormulas } from '../chunk-
|
|
1
|
+
export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, formulaSpec, validateFormulaAgainstSchema, validateSchemaFormulas } from '../chunk-5KGKN42D.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
|
|
8
|
+
var chunkFKKO5Y4M_cjs = require('./chunk-FKKO5Y4M.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
|
|
196
|
+
get: function () { return chunkFKKO5Y4M_cjs.collectFormulaNodes; }
|
|
197
197
|
});
|
|
198
198
|
Object.defineProperty(exports, "evaluateFormulas", {
|
|
199
199
|
enumerable: true,
|
|
200
|
-
get: function () { return
|
|
200
|
+
get: function () { return chunkFKKO5Y4M_cjs.evaluateFormulas; }
|
|
201
201
|
});
|
|
202
202
|
Object.defineProperty(exports, "extractSchemaFormulas", {
|
|
203
203
|
enumerable: true,
|
|
204
|
-
get: function () { return
|
|
204
|
+
get: function () { return chunkFKKO5Y4M_cjs.extractSchemaFormulas; }
|
|
205
205
|
});
|
|
206
206
|
Object.defineProperty(exports, "formulaSpec", {
|
|
207
207
|
enumerable: true,
|
|
208
|
-
get: function () { return
|
|
208
|
+
get: function () { return chunkFKKO5Y4M_cjs.formulaSpec; }
|
|
209
209
|
});
|
|
210
210
|
Object.defineProperty(exports, "validateFormulaAgainstSchema", {
|
|
211
211
|
enumerable: true,
|
|
212
|
-
get: function () { return
|
|
212
|
+
get: function () { return chunkFKKO5Y4M_cjs.validateFormulaAgainstSchema; }
|
|
213
213
|
});
|
|
214
214
|
Object.defineProperty(exports, "validateSchemaFormulas", {
|
|
215
215
|
enumerable: true,
|
|
216
|
-
get: function () { return
|
|
216
|
+
get: function () { return chunkFKKO5Y4M_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-
|
|
6
|
+
export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, formulaSpec, validateFormulaAgainstSchema, validateSchemaFormulas } from './chunk-5KGKN42D.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';
|
package/dist/lib/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkVX5C5YMF_cjs = require('../chunk-VX5C5YMF.cjs');
|
|
4
|
-
var
|
|
4
|
+
var chunkFKKO5Y4M_cjs = require('../chunk-FKKO5Y4M.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
|
|
147
|
+
get: function () { return chunkFKKO5Y4M_cjs.collectFormulaNodes; }
|
|
148
148
|
});
|
|
149
149
|
Object.defineProperty(exports, "evaluateFormulas", {
|
|
150
150
|
enumerable: true,
|
|
151
|
-
get: function () { return
|
|
151
|
+
get: function () { return chunkFKKO5Y4M_cjs.evaluateFormulas; }
|
|
152
152
|
});
|
|
153
153
|
Object.defineProperty(exports, "extractSchemaFormulas", {
|
|
154
154
|
enumerable: true,
|
|
155
|
-
get: function () { return
|
|
155
|
+
get: function () { return chunkFKKO5Y4M_cjs.extractSchemaFormulas; }
|
|
156
156
|
});
|
|
157
157
|
Object.defineProperty(exports, "formulaSpec", {
|
|
158
158
|
enumerable: true,
|
|
159
|
-
get: function () { return
|
|
159
|
+
get: function () { return chunkFKKO5Y4M_cjs.formulaSpec; }
|
|
160
160
|
});
|
|
161
161
|
Object.defineProperty(exports, "validateFormulaAgainstSchema", {
|
|
162
162
|
enumerable: true,
|
|
163
|
-
get: function () { return
|
|
163
|
+
get: function () { return chunkFKKO5Y4M_cjs.validateFormulaAgainstSchema; }
|
|
164
164
|
});
|
|
165
165
|
Object.defineProperty(exports, "validateSchemaFormulas", {
|
|
166
166
|
enumerable: true,
|
|
167
|
-
get: function () { return
|
|
167
|
+
get: function () { return chunkFKKO5Y4M_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-
|
|
2
|
+
export { collectFormulaNodes, evaluateFormulas, extractSchemaFormulas, formulaSpec, validateFormulaAgainstSchema, validateSchemaFormulas } from '../chunk-5KGKN42D.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.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Universal schema toolkit with TypeScript types and utilities for JSON Schema manipulation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"json-schema",
|
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
"typescript-eslint": "^8.15.0"
|
|
172
172
|
},
|
|
173
173
|
"dependencies": {
|
|
174
|
-
"@revisium/formula": "^0.
|
|
174
|
+
"@revisium/formula": "^0.9.0",
|
|
175
175
|
"nanoid": "^3.3.7"
|
|
176
176
|
},
|
|
177
177
|
"engines": {
|
|
@@ -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","getTopologicalOrder","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;A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file":"chunk-HZW3UZAB.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 buildDependencyGraph,\n getTopologicalOrder,\n evaluateWithContext,\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\nexport interface FormulaNode {\n path: string;\n expression: string;\n fieldType: 'number' | 'string' | 'boolean';\n currentPath: string;\n dependencies: string[];\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\nexport function collectFormulaNodes(\n schema: JsonSchema,\n data: Record<string, unknown>,\n): FormulaNode[] {\n const nodes: FormulaNode[] = [];\n traverseAndCollect(schema as SchemaNode, data, '', nodes);\n return nodes;\n}\n\nfunction traverseAndCollect(\n schema: SchemaNode,\n data: unknown,\n currentPath: string,\n nodes: FormulaNode[],\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 });\n }\n\n traverseAndCollect(fieldSchema, fieldValue, fieldPath, nodes);\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 traverseAndCollect(schema.items, data[i], itemPath, nodes);\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 dependencies = Object.fromEntries(\n nodes.map((n) => [n.path, n.dependencies]),\n );\n\n const result = getTopologicalOrder(buildDependencyGraph(dependencies));\n\n if (!result.success) {\n throw new Error(\n `Cyclic dependency detected in formulas: ${result.error ?? 'unknown error'}`,\n );\n }\n\n const nodeMap = new Map(nodes.map((n) => [n.path, n]));\n\n return result.order\n .map((path) => nodeMap.get(path))\n .filter((n): n is FormulaNode => n !== undefined);\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 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 result = evaluateWithContext(node.expression, {\n rootData: data,\n ...(itemData && { itemData, currentPath: node.currentPath }),\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":["getParentPath","buildDependencyGraph"],"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,CAAA,GAAK,SAAA;AAE7D,IAAA,MAAM,QAAA,GAAW,YAAY,WAAW,CAAA;AACxC,IAAA,IAAI,QAAA,EAAU;AACZ,MAAA,QAAA,CAAS,IAAA,CAAK;AAAA,QACZ,SAAA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vB,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-I2ECBDBM.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 buildDependencyGraph,\n getTopologicalOrder,\n evaluateWithContext,\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\nexport interface FormulaNode {\n path: string;\n expression: string;\n fieldType: 'number' | 'string' | 'boolean';\n currentPath: string;\n dependencies: string[];\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\nexport function collectFormulaNodes(\n schema: JsonSchema,\n data: Record<string, unknown>,\n): FormulaNode[] {\n const nodes: FormulaNode[] = [];\n traverseAndCollect(schema as SchemaNode, data, '', nodes);\n return nodes;\n}\n\nfunction traverseAndCollect(\n schema: SchemaNode,\n data: unknown,\n currentPath: string,\n nodes: FormulaNode[],\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 });\n }\n\n traverseAndCollect(fieldSchema, fieldValue, fieldPath, nodes);\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 traverseAndCollect(schema.items, data[i], itemPath, nodes);\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 dependencies = Object.fromEntries(\n nodes.map((n) => [n.path, n.dependencies]),\n );\n\n const result = getTopologicalOrder(buildDependencyGraph(dependencies));\n\n if (!result.success) {\n throw new Error(\n `Cyclic dependency detected in formulas: ${result.error ?? 'unknown error'}`,\n );\n }\n\n const nodeMap = new Map(nodes.map((n) => [n.path, n]));\n\n return result.order\n .map((path) => nodeMap.get(path))\n .filter((n): n is FormulaNode => n !== undefined);\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 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 result = evaluateWithContext(node.expression, {\n rootData: data,\n ...(itemData && { itemData, currentPath: node.currentPath }),\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"]}
|