@revisium/formula 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-GOMUE724.cjs → chunk-QS3FBYM5.cjs} +91 -9
- package/dist/chunk-QS3FBYM5.cjs.map +1 -0
- package/dist/{chunk-LFEHEGBL.js → chunk-V6MB7X37.js} +91 -9
- package/dist/chunk-V6MB7X37.js.map +1 -0
- package/dist/editor/index.cjs +4 -4
- package/dist/editor/index.js +1 -1
- package/dist/formula-spec.cjs +181 -4
- package/dist/formula-spec.cjs.map +1 -1
- package/dist/formula-spec.js +181 -4
- package/dist/formula-spec.js.map +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-GOMUE724.cjs.map +0 -1
- package/dist/chunk-LFEHEGBL.js.map +0 -1
package/dist/formula-spec.js
CHANGED
|
@@ -379,15 +379,21 @@ var formulaSpec = {
|
|
|
379
379
|
},
|
|
380
380
|
{
|
|
381
381
|
name: "relative_path",
|
|
382
|
-
description: "Relative path reference starting with ../.
|
|
382
|
+
description: "Relative path reference starting with ../. Each ../ goes up one level in the path hierarchy. Works with nested objects, arrays, and combinations. Supports accessing nested properties after the relative prefix (e.g., ../config.value)",
|
|
383
383
|
minVersion: "1.1",
|
|
384
384
|
examples: [
|
|
385
385
|
"../discount",
|
|
386
|
-
"
|
|
386
|
+
"../../rootRate",
|
|
387
|
+
"../config.multiplier",
|
|
387
388
|
"price * (1 - ../discount)",
|
|
388
|
-
"price *
|
|
389
|
+
"price * ../../globalRate",
|
|
390
|
+
"price * ../settings.tax.rate"
|
|
389
391
|
],
|
|
390
|
-
dependenciesExtracted: [
|
|
392
|
+
dependenciesExtracted: [
|
|
393
|
+
'["../discount"]',
|
|
394
|
+
'["../../rootRate"]',
|
|
395
|
+
'["../config.multiplier"]'
|
|
396
|
+
]
|
|
391
397
|
},
|
|
392
398
|
{
|
|
393
399
|
name: "function_named_fields",
|
|
@@ -550,6 +556,177 @@ evaluateWithContext('value + 10', {
|
|
|
550
556
|
currentPath: 'items[0]'
|
|
551
557
|
})
|
|
552
558
|
// 60`
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
name: "Relative paths - path resolution",
|
|
562
|
+
description: "Understanding how ../ resolves based on currentPath. Each ../ goes up one segment (object property or array element counts as one segment)",
|
|
563
|
+
code: `// Path structure explanation:
|
|
564
|
+
// currentPath splits by "." (dots), keeping array indices attached to field names
|
|
565
|
+
// "items[0]" = 1 segment
|
|
566
|
+
// "items[0].inner" = 2 segments: ["items[0]", "inner"]
|
|
567
|
+
// "container.items[0]" = 2 segments: ["container", "items[0]"]
|
|
568
|
+
|
|
569
|
+
// Single ../ from array item -> goes to root
|
|
570
|
+
// currentPath: "items[0]" (1 segment)
|
|
571
|
+
// ../ goes up 1 level -> root
|
|
572
|
+
evaluateWithContext('price * ../discount', {
|
|
573
|
+
rootData: { discount: 0.2, items: [{ price: 100 }] },
|
|
574
|
+
itemData: { price: 100 },
|
|
575
|
+
currentPath: 'items[0]'
|
|
576
|
+
})
|
|
577
|
+
// Resolves ../discount to root.discount = 0.2
|
|
578
|
+
// Result: 100 * 0.2 = 20
|
|
579
|
+
|
|
580
|
+
// Single ../ from nested object in array -> goes to array item
|
|
581
|
+
// currentPath: "items[0].inner" (2 segments)
|
|
582
|
+
// ../ goes up 1 level -> "items[0]"
|
|
583
|
+
evaluateWithContext('price * ../itemMultiplier', {
|
|
584
|
+
rootData: { items: [{ itemMultiplier: 3, inner: { price: 10 } }] },
|
|
585
|
+
itemData: { price: 10 },
|
|
586
|
+
currentPath: 'items[0].inner'
|
|
587
|
+
})
|
|
588
|
+
// Resolves ../itemMultiplier to items[0].itemMultiplier = 3
|
|
589
|
+
// Result: 10 * 3 = 30
|
|
590
|
+
|
|
591
|
+
// Double ../../ from nested object in array -> goes to root
|
|
592
|
+
// currentPath: "items[0].inner" (2 segments)
|
|
593
|
+
// ../../ goes up 2 levels -> root
|
|
594
|
+
evaluateWithContext('price * ../../rootRate', {
|
|
595
|
+
rootData: { rootRate: 2, items: [{ inner: { price: 5 } }] },
|
|
596
|
+
itemData: { price: 5 },
|
|
597
|
+
currentPath: 'items[0].inner'
|
|
598
|
+
})
|
|
599
|
+
// Resolves ../../rootRate to root.rootRate = 2
|
|
600
|
+
// Result: 5 * 2 = 10`
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
name: "Relative paths - nested arrays",
|
|
604
|
+
description: "How relative paths work with arrays inside objects and nested arrays",
|
|
605
|
+
code: `// Array inside nested object
|
|
606
|
+
// currentPath: "container.items[0]" (2 segments: ["container", "items[0]"])
|
|
607
|
+
// ../ goes up 1 level -> "container"
|
|
608
|
+
evaluateWithContext('price * ../containerRate', {
|
|
609
|
+
rootData: {
|
|
610
|
+
container: {
|
|
611
|
+
containerRate: 4,
|
|
612
|
+
items: [{ price: 5 }]
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
itemData: { price: 5 },
|
|
616
|
+
currentPath: 'container.items[0]'
|
|
617
|
+
})
|
|
618
|
+
// Resolves ../containerRate to container.containerRate = 4
|
|
619
|
+
// Result: 5 * 4 = 20
|
|
620
|
+
|
|
621
|
+
// ../../ from array inside object -> goes to root
|
|
622
|
+
// currentPath: "container.items[0]" (2 segments)
|
|
623
|
+
// ../../ goes up 2 levels -> root
|
|
624
|
+
evaluateWithContext('price * ../../rootVal', {
|
|
625
|
+
rootData: {
|
|
626
|
+
rootVal: 6,
|
|
627
|
+
container: { items: [{ price: 5 }] }
|
|
628
|
+
},
|
|
629
|
+
itemData: { price: 5 },
|
|
630
|
+
currentPath: 'container.items[0]'
|
|
631
|
+
})
|
|
632
|
+
// Resolves ../../rootVal to root.rootVal = 6
|
|
633
|
+
// Result: 5 * 6 = 30
|
|
634
|
+
|
|
635
|
+
// Nested arrays: items[].subItems[]
|
|
636
|
+
// currentPath: "items[0].subItems[0]" (2 segments: ["items[0]", "subItems[0]"])
|
|
637
|
+
// ../ goes up 1 level -> "items[0]"
|
|
638
|
+
evaluateWithContext('qty * ../itemPrice', {
|
|
639
|
+
rootData: {
|
|
640
|
+
items: [{ itemPrice: 10, subItems: [{ qty: 3 }] }]
|
|
641
|
+
},
|
|
642
|
+
itemData: { qty: 3 },
|
|
643
|
+
currentPath: 'items[0].subItems[0]'
|
|
644
|
+
})
|
|
645
|
+
// Resolves ../itemPrice to items[0].itemPrice = 10
|
|
646
|
+
// Result: 3 * 10 = 30`
|
|
647
|
+
},
|
|
648
|
+
{
|
|
649
|
+
name: "Relative paths - accessing nested properties",
|
|
650
|
+
description: "Relative paths can include nested property access after the ../ prefix",
|
|
651
|
+
code: `// ../sibling.nested accesses a sibling with nested property
|
|
652
|
+
// currentPath: "items[0].products[0]" (2 segments)
|
|
653
|
+
// ../ goes to "items[0]", then accesses .config.discount
|
|
654
|
+
evaluateWithContext('price * ../config.discount', {
|
|
655
|
+
rootData: {
|
|
656
|
+
items: [{
|
|
657
|
+
config: { discount: 0.9 },
|
|
658
|
+
products: [{ price: 100 }]
|
|
659
|
+
}]
|
|
660
|
+
},
|
|
661
|
+
itemData: { price: 100 },
|
|
662
|
+
currentPath: 'items[0].products[0]'
|
|
663
|
+
})
|
|
664
|
+
// Resolves ../config.discount to items[0].config.discount = 0.9
|
|
665
|
+
// Result: 100 * 0.9 = 90
|
|
666
|
+
|
|
667
|
+
// Deep nested: ../../settings.tax.rate
|
|
668
|
+
evaluateWithContext('amount * ../../settings.tax.rate', {
|
|
669
|
+
rootData: {
|
|
670
|
+
settings: { tax: { rate: 0.1 } },
|
|
671
|
+
orders: [{ items: [{ amount: 200 }] }]
|
|
672
|
+
},
|
|
673
|
+
itemData: { amount: 200 },
|
|
674
|
+
currentPath: 'orders[0].items[0]'
|
|
675
|
+
})
|
|
676
|
+
// Resolves ../../settings.tax.rate to root.settings.tax.rate = 0.1
|
|
677
|
+
// Result: 200 * 0.1 = 20`
|
|
678
|
+
},
|
|
679
|
+
{
|
|
680
|
+
name: "Relative paths - complex nesting",
|
|
681
|
+
description: "Complex scenarios with arrays inside objects inside arrays",
|
|
682
|
+
code: `// Array inside object inside array
|
|
683
|
+
// Structure: items[].container.subItems[]
|
|
684
|
+
// currentPath: "items[0].container.subItems[0]" (3 segments)
|
|
685
|
+
evaluateWithContext('val * ../containerMultiplier', {
|
|
686
|
+
rootData: {
|
|
687
|
+
items: [{
|
|
688
|
+
container: {
|
|
689
|
+
containerMultiplier: 4,
|
|
690
|
+
subItems: [{ val: 3 }]
|
|
691
|
+
}
|
|
692
|
+
}]
|
|
693
|
+
},
|
|
694
|
+
itemData: { val: 3 },
|
|
695
|
+
currentPath: 'items[0].container.subItems[0]'
|
|
696
|
+
})
|
|
697
|
+
// ../ goes to "items[0].container"
|
|
698
|
+
// Resolves ../containerMultiplier to items[0].container.containerMultiplier = 4
|
|
699
|
+
// Result: 3 * 4 = 12
|
|
700
|
+
|
|
701
|
+
// ../../ from same structure -> goes to array item
|
|
702
|
+
evaluateWithContext('val * ../../itemRate', {
|
|
703
|
+
rootData: {
|
|
704
|
+
items: [{
|
|
705
|
+
itemRate: 5,
|
|
706
|
+
container: { subItems: [{ val: 2 }] }
|
|
707
|
+
}]
|
|
708
|
+
},
|
|
709
|
+
itemData: { val: 2 },
|
|
710
|
+
currentPath: 'items[0].container.subItems[0]'
|
|
711
|
+
})
|
|
712
|
+
// ../../ goes to "items[0]"
|
|
713
|
+
// Resolves ../../itemRate to items[0].itemRate = 5
|
|
714
|
+
// Result: 2 * 5 = 10
|
|
715
|
+
|
|
716
|
+
// ../../../ from same structure -> goes to root
|
|
717
|
+
evaluateWithContext('val * ../../../rootFactor', {
|
|
718
|
+
rootData: {
|
|
719
|
+
rootFactor: 3,
|
|
720
|
+
items: [{
|
|
721
|
+
container: { subItems: [{ val: 7 }] }
|
|
722
|
+
}]
|
|
723
|
+
},
|
|
724
|
+
itemData: { val: 7 },
|
|
725
|
+
currentPath: 'items[0].container.subItems[0]'
|
|
726
|
+
})
|
|
727
|
+
// ../../../ goes to root
|
|
728
|
+
// Resolves ../../../rootFactor to root.rootFactor = 3
|
|
729
|
+
// Result: 7 * 3 = 21`
|
|
553
730
|
}
|
|
554
731
|
],
|
|
555
732
|
schemaUsage: {
|
package/dist/formula-spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/formula-spec.ts"],"names":[],"mappings":";AAuDO,IAAM,WAAA,GAA2B;AAAA,EACtC,OAAA,EAAS,KAAA;AAAA,EACT,WAAA,EACE,8GAAA;AAAA,EAEF,MAAA,EAAQ;AAAA,IACN,eAAA,EAAiB;AAAA,MACf,iDAAA;AAAA,MACA,mDAAA;AAAA,MACA,qDAAA;AAAA,MACA;AAAA,KACF;AAAA,IACA,mBAAA,EAAqB;AAAA,MACnB,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,kCAAA,EAAmC;AAAA,MACjE,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,aAAA,EAAc;AAAA,MAC5C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,gBAAA,EAAiB;AAAA,MAC/C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,UAAA,EAAW;AAAA,MACzC,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,oBAAA;AAAqB,KACrD;AAAA,IACA,mBAAA,EAAqB;AAAA,MACnB,EAAE,QAAA,EAAU,IAAA,EAAM,WAAA,EAAa,OAAA,EAAQ;AAAA,MACvC,EAAE,QAAA,EAAU,IAAA,EAAM,WAAA,EAAa,WAAA,EAAY;AAAA,MAC3C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,cAAA,EAAe;AAAA,MAC7C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,WAAA,EAAY;AAAA,MAC1C,EAAE,QAAA,EAAU,IAAA,EAAM,WAAA,EAAa,kBAAA,EAAmB;AAAA,MAClD,EAAE,QAAA,EAAU,IAAA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EAAa,0CAAA;AAAA,MACb,IAAA,EAAM,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA;AAAA,KAMR;AAAA,IACA;AAAA,MACE,IAAA,EAAM,sBAAA;AAAA,MACN,WAAA,EAAa,oCAAA;AAAA,MACb,IAAA,EAAM,CAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA,IAAA;AAAA,KAcR;AAAA,IACA;AAAA,MACE,IAAA,EAAM,uBAAA;AAAA,MACN,WAAA,EAAa,qDAAA;AAAA,MACb,IAAA,EAAM,CAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA,KAAA;AAAA,KAaR;AAAA,IACA;AAAA,MACE,IAAA,EAAM,qCAAA;AAAA,MACN,WAAA,EACE,wEAAA;AAAA,MACF,IAAA,EAAM,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAAA;AAAA;AA+BR,GACF;AAAA,EAEA,WAAA,EAAa;AAAA,IACX,SAAA,EACE,0EAAA;AAAA,IACF,UAAA,EAAY,CAAC,QAAA,EAAU,QAAA,EAAU,SAAS,CAAA;AAAA,IAC1C,KAAA,EAAO;AAAA,MACL,0DAAA;AAAA,MACA,sDAAA;AAAA,MACA,6DAAA;AAAA,MACA;AAAA;AACF;AAEJ","file":"formula-spec.js","sourcesContent":["export interface FunctionSpec {\n name: string;\n description: string;\n signature: string;\n returnType: 'string' | 'number' | 'boolean' | 'any';\n examples: string[];\n}\n\nexport interface FormulaSpec {\n version: string;\n description: string;\n syntax: {\n fieldReferences: string[];\n arithmeticOperators: { operator: string; description: string }[];\n comparisonOperators: { operator: string; description: string }[];\n logicalOperators: { operator: string; description: string }[];\n other: string[];\n };\n functions: {\n string: FunctionSpec[];\n numeric: FunctionSpec[];\n boolean: FunctionSpec[];\n array: FunctionSpec[];\n conversion: FunctionSpec[];\n conditional: FunctionSpec[];\n };\n features: {\n name: string;\n description: string;\n minVersion: string;\n examples: string[];\n dependenciesExtracted?: string[];\n }[];\n versionDetection: { feature: string; minVersion: string }[];\n parseResult: {\n description: string;\n interface: string;\n };\n examples: {\n expression: string;\n description: string;\n result?: string;\n }[];\n apiExamples: {\n name: string;\n description: string;\n code: string;\n }[];\n schemaUsage: {\n structure: string;\n fieldTypes: string[];\n rules: string[];\n };\n}\n\nexport const formulaSpec: FormulaSpec = {\n version: '1.1',\n description:\n 'Formula expressions for computed fields. Formulas reference other fields and calculate values automatically.',\n\n syntax: {\n fieldReferences: [\n 'Simple field: fieldName (e.g., price, quantity)',\n 'Nested path: object.property (e.g., stats.damage)',\n 'Array index: array[0] or array[-1] for last element',\n 'Combined: items[0].price, user.addresses[-1].city',\n ],\n arithmeticOperators: [\n { operator: '+', description: 'Addition or string concatenation' },\n { operator: '-', description: 'Subtraction' },\n { operator: '*', description: 'Multiplication' },\n { operator: '/', description: 'Division' },\n { operator: '%', description: 'Modulo (remainder)' },\n ],\n comparisonOperators: [\n { operator: '==', description: 'Equal' },\n { operator: '!=', description: 'Not equal' },\n { operator: '>', description: 'Greater than' },\n { operator: '<', description: 'Less than' },\n { operator: '>=', description: 'Greater or equal' },\n { operator: '<=', description: 'Less or equal' },\n ],\n logicalOperators: [\n { operator: '&&', description: 'Logical AND' },\n { operator: '||', description: 'Logical OR' },\n { operator: '!', description: 'Logical NOT' },\n ],\n other: ['Parentheses: (a + b) * c', 'Unary minus: -value, a + -b'],\n },\n\n functions: {\n string: [\n {\n name: 'concat',\n description: 'Concatenate multiple values into a single string',\n signature: 'concat(value1, value2, ...)',\n returnType: 'string',\n examples: [\n 'concat(firstName, \" \", lastName) // \"John Doe\"',\n 'concat(\"Price: \", price, \" USD\") // \"Price: 100 USD\"',\n ],\n },\n {\n name: 'upper',\n description: 'Convert string to uppercase',\n signature: 'upper(text)',\n returnType: 'string',\n examples: ['upper(name) // \"HELLO\"'],\n },\n {\n name: 'lower',\n description: 'Convert string to lowercase',\n signature: 'lower(text)',\n returnType: 'string',\n examples: ['lower(name) // \"hello\"'],\n },\n {\n name: 'trim',\n description: 'Remove whitespace from both ends of a string',\n signature: 'trim(text)',\n returnType: 'string',\n examples: ['trim(name) // \"hello\" from \" hello \"'],\n },\n {\n name: 'left',\n description: 'Extract characters from the beginning of a string',\n signature: 'left(text, count)',\n returnType: 'string',\n examples: ['left(name, 3) // \"hel\" from \"hello\"'],\n },\n {\n name: 'right',\n description: 'Extract characters from the end of a string',\n signature: 'right(text, count)',\n returnType: 'string',\n examples: ['right(name, 3) // \"llo\" from \"hello\"'],\n },\n {\n name: 'replace',\n description: 'Replace first occurrence of a substring',\n signature: 'replace(text, search, replacement)',\n returnType: 'string',\n examples: ['replace(name, \"o\", \"0\") // \"hell0\" from \"hello\"'],\n },\n {\n name: 'join',\n description: 'Join array elements into a string',\n signature: 'join(array, separator?)',\n returnType: 'string',\n examples: ['join(tags) // \"a,b,c\"', 'join(tags, \" | \") // \"a | b | c\"'],\n },\n ],\n numeric: [\n {\n name: 'round',\n description: 'Round a number to specified decimal places',\n signature: 'round(number, decimals?)',\n returnType: 'number',\n examples: ['round(3.14159, 2) // 3.14', 'round(3.5) // 4'],\n },\n {\n name: 'floor',\n description: 'Round down to the nearest integer',\n signature: 'floor(number)',\n returnType: 'number',\n examples: ['floor(3.7) // 3'],\n },\n {\n name: 'ceil',\n description: 'Round up to the nearest integer',\n signature: 'ceil(number)',\n returnType: 'number',\n examples: ['ceil(3.2) // 4'],\n },\n {\n name: 'abs',\n description: 'Get the absolute value',\n signature: 'abs(number)',\n returnType: 'number',\n examples: ['abs(-5) // 5'],\n },\n {\n name: 'sqrt',\n description: 'Calculate the square root',\n signature: 'sqrt(number)',\n returnType: 'number',\n examples: ['sqrt(16) // 4'],\n },\n {\n name: 'pow',\n description: 'Raise a number to a power',\n signature: 'pow(base, exponent)',\n returnType: 'number',\n examples: ['pow(2, 3) // 8'],\n },\n {\n name: 'min',\n description: 'Get the minimum of multiple values',\n signature: 'min(value1, value2, ...)',\n returnType: 'number',\n examples: ['min(a, b, c) // smallest value'],\n },\n {\n name: 'max',\n description: 'Get the maximum of multiple values',\n signature: 'max(value1, value2, ...)',\n returnType: 'number',\n examples: ['max(a, b, c) // largest value'],\n },\n {\n name: 'log',\n description: 'Calculate the natural logarithm',\n signature: 'log(number)',\n returnType: 'number',\n examples: ['log(10) // 2.302...'],\n },\n {\n name: 'log10',\n description: 'Calculate the base-10 logarithm',\n signature: 'log10(number)',\n returnType: 'number',\n examples: ['log10(100) // 2'],\n },\n {\n name: 'exp',\n description: 'Calculate e raised to a power',\n signature: 'exp(number)',\n returnType: 'number',\n examples: ['exp(1) // 2.718...'],\n },\n {\n name: 'sign',\n description: 'Get the sign of a number (-1, 0, or 1)',\n signature: 'sign(number)',\n returnType: 'number',\n examples: ['sign(-5) // -1', 'sign(0) // 0', 'sign(5) // 1'],\n },\n {\n name: 'length',\n description: 'Get the length of a string or array',\n signature: 'length(value)',\n returnType: 'number',\n examples: ['length(name) // 5 from \"hello\"', 'length(items) // 3'],\n },\n ],\n boolean: [\n {\n name: 'and',\n description: 'Logical AND of two values',\n signature: 'and(a, b)',\n returnType: 'boolean',\n examples: ['and(isActive, hasPermission) // true if both true'],\n },\n {\n name: 'or',\n description: 'Logical OR of two values',\n signature: 'or(a, b)',\n returnType: 'boolean',\n examples: ['or(isAdmin, isOwner) // true if either true'],\n },\n {\n name: 'not',\n description: 'Logical NOT of a value',\n signature: 'not(value)',\n returnType: 'boolean',\n examples: ['not(isDeleted) // true if false'],\n },\n {\n name: 'contains',\n description: 'Check if a string contains a substring',\n signature: 'contains(text, search)',\n returnType: 'boolean',\n examples: ['contains(name, \"ell\") // true for \"hello\"'],\n },\n {\n name: 'startswith',\n description: 'Check if a string starts with a prefix',\n signature: 'startswith(text, prefix)',\n returnType: 'boolean',\n examples: ['startswith(name, \"hel\") // true for \"hello\"'],\n },\n {\n name: 'endswith',\n description: 'Check if a string ends with a suffix',\n signature: 'endswith(text, suffix)',\n returnType: 'boolean',\n examples: ['endswith(name, \"llo\") // true for \"hello\"'],\n },\n {\n name: 'isnull',\n description: 'Check if a value is null or undefined',\n signature: 'isnull(value)',\n returnType: 'boolean',\n examples: ['isnull(optionalField) // true if null/undefined'],\n },\n {\n name: 'includes',\n description: 'Check if an array contains a value',\n signature: 'includes(array, value)',\n returnType: 'boolean',\n examples: [\n 'includes(tags, \"featured\") // true if array contains value',\n ],\n },\n ],\n array: [\n {\n name: 'sum',\n description: 'Calculate the sum of array elements',\n signature: 'sum(array)',\n returnType: 'number',\n examples: ['sum(prices) // total of all prices'],\n },\n {\n name: 'avg',\n description: 'Calculate the average of array elements',\n signature: 'avg(array)',\n returnType: 'number',\n examples: ['avg(scores) // average score'],\n },\n {\n name: 'count',\n description: 'Get the number of elements in an array',\n signature: 'count(array)',\n returnType: 'number',\n examples: ['count(items) // number of items'],\n },\n {\n name: 'first',\n description: 'Get the first element of an array',\n signature: 'first(array)',\n returnType: 'any',\n examples: ['first(items) // first item'],\n },\n {\n name: 'last',\n description: 'Get the last element of an array',\n signature: 'last(array)',\n returnType: 'any',\n examples: ['last(items) // last item'],\n },\n ],\n conversion: [\n {\n name: 'tostring',\n description: 'Convert a value to string',\n signature: 'tostring(value)',\n returnType: 'string',\n examples: ['tostring(42) // \"42\"'],\n },\n {\n name: 'tonumber',\n description: 'Convert a value to number',\n signature: 'tonumber(value)',\n returnType: 'number',\n examples: ['tonumber(\"42\") // 42'],\n },\n {\n name: 'toboolean',\n description: 'Convert a value to boolean',\n signature: 'toboolean(value)',\n returnType: 'boolean',\n examples: ['toboolean(1) // true', 'toboolean(0) // false'],\n },\n ],\n conditional: [\n {\n name: 'if',\n description: 'Return one of two values based on a condition',\n signature: 'if(condition, valueIfTrue, valueIfFalse)',\n returnType: 'any',\n examples: [\n 'if(stock > 0, \"Available\", \"Out of Stock\")',\n 'if(price > 100, price * 0.9, price)',\n ],\n },\n {\n name: 'coalesce',\n description: 'Return the first non-null value',\n signature: 'coalesce(value1, value2, ...)',\n returnType: 'any',\n examples: ['coalesce(nickname, name, \"Anonymous\")'],\n },\n ],\n },\n\n features: [\n {\n name: 'simple_refs',\n description: 'Reference top-level fields by name',\n minVersion: '1.0',\n examples: ['price', 'quantity', 'baseDamage'],\n dependenciesExtracted: ['[\"price\"]', '[\"quantity\"]', '[\"baseDamage\"]'],\n },\n {\n name: 'arithmetic',\n description: 'Basic math operations (+, -, *, /)',\n minVersion: '1.0',\n examples: ['price * 1.1', 'a + b - c', 'quantity * price'],\n },\n {\n name: 'comparison',\n description: 'Compare values (>, <, >=, <=, ==, !=)',\n minVersion: '1.0',\n examples: ['price > 100', 'x == 10', 'quantity >= 5'],\n },\n {\n name: 'nested_path',\n description: 'Access nested object properties using dot notation',\n minVersion: '1.1',\n examples: ['stats.damage', 'user.profile.name', 'item.metadata.category'],\n dependenciesExtracted: ['[\"stats.damage\"]'],\n },\n {\n name: 'array_index',\n description:\n 'Access array elements by numeric index. Negative indices access from the end',\n minVersion: '1.1',\n examples: [\n 'items[0].price',\n 'inventory[1].quantity',\n 'items[-1].name // last element',\n 'items[-2].price // second to last',\n ],\n dependenciesExtracted: ['[\"items[0].price\"]', '[\"items[-1].name\"]'],\n },\n {\n name: 'root_path',\n description:\n 'Absolute path reference starting with /. Always resolves from root data, even inside array item formulas',\n minVersion: '1.1',\n examples: [\n '/taxRate',\n '/config.tax',\n 'price * (1 + /taxRate)',\n 'price * /config.multiplier',\n ],\n dependenciesExtracted: ['[\"/taxRate\"]', '[\"/config.tax\"]'],\n },\n {\n name: 'relative_path',\n description:\n 'Relative path reference starting with ../. Resolves from parent context (root data) when inside array item formulas',\n minVersion: '1.1',\n examples: [\n '../discount',\n '../settings.multiplier',\n 'price * (1 - ../discount)',\n 'price * ../settings.multiplier',\n ],\n dependenciesExtracted: ['[\"../discount\"]', '[\"../settings.multiplier\"]'],\n },\n {\n name: 'function_named_fields',\n description:\n 'Fields can have the same name as built-in functions (max, min, sum, etc.). Built-in functions are always checked first when a function call is made',\n minVersion: '1.0',\n examples: [\n 'max(max, 0)',\n 'min(min, 100)',\n 'max(max - field.min, 0)',\n 'round(round * 2)',\n ],\n },\n ],\n\n versionDetection: [\n { feature: 'Simple refs, arithmetic, comparisons', minVersion: '1.0' },\n { feature: 'Function-named fields (max(max, 0))', minVersion: '1.0' },\n { feature: 'Nested paths (a.b)', minVersion: '1.1' },\n { feature: 'Array index ([0], [-1])', minVersion: '1.1' },\n { feature: 'Absolute paths (/field)', minVersion: '1.1' },\n { feature: 'Relative paths (../field)', minVersion: '1.1' },\n ],\n\n parseResult: {\n description:\n 'The parser automatically detects the minimum required version',\n interface: `interface ParseResult {\n ast: ASTNode; // Abstract syntax tree\n dependencies: string[]; // List of field dependencies\n features: string[]; // List of detected features\n minVersion: string; // Minimum required version (\"1.0\" or \"1.1\")\n}`,\n },\n\n examples: [\n {\n expression: 'price * quantity',\n description: 'Calculate total from price and quantity',\n result: 'number',\n },\n {\n expression: 'firstName + \" \" + lastName',\n description: 'Concatenate strings with space',\n result: 'string',\n },\n {\n expression: 'quantity > 0',\n description: 'Check if in stock',\n result: 'boolean',\n },\n {\n expression: 'if(stock > 0, \"Available\", \"Out of Stock\")',\n description: 'Conditional text based on stock',\n result: 'string',\n },\n {\n expression: 'price * (1 + taxRate)',\n description: 'Price with tax',\n result: 'number',\n },\n {\n expression: 'items[0].price + items[1].price',\n description: 'Sum first two item prices (v1.1)',\n result: 'number',\n },\n ],\n\n apiExamples: [\n {\n name: 'Simple Expression (v1.0)',\n description: 'Parse a basic arithmetic expression',\n code: `parseExpression('price * 1.1')\n// {\n// minVersion: \"1.0\",\n// features: [],\n// dependencies: [\"price\"]\n// }`,\n },\n {\n name: 'Nested Path (v1.1)',\n description: 'Parse expression with nested object access',\n code: `parseExpression('stats.damage * multiplier')\n// {\n// minVersion: \"1.1\",\n// features: [\"nested_path\"],\n// dependencies: [\"stats.damage\", \"multiplier\"]\n// }`,\n },\n {\n name: 'Array Access (v1.1)',\n description: 'Parse expression with array index access',\n code: `parseExpression('items[0].price + items[1].price')\n// {\n// minVersion: \"1.1\",\n// features: [\"array_index\", \"nested_path\"],\n// dependencies: [\"items[0].price\", \"items[1].price\"]\n// }`,\n },\n {\n name: 'Evaluate expressions',\n description: 'Execute formulas with context data',\n code: `evaluate('price * 1.1', { price: 100 })\n// 110\n\nevaluate('stats.damage', { stats: { damage: 50 } })\n// 50\n\nevaluate('items[0].price', { items: [{ price: 10 }] })\n// 10\n\nevaluate('price > 100', { price: 150 })\n// true\n\nevaluate('a + b * c', { a: 1, b: 2, c: 3 })\n// 7`,\n },\n {\n name: 'Function-named fields',\n description: 'Fields can have the same name as built-in functions',\n code: `// Built-in functions take precedence in function calls\nevaluate('max(max, 0)', { max: 10 })\n// 10 (max() function, then max field)\n\nevaluate('max(max - field.min, 0)', { max: 100, field: { min: 20 } })\n// 80\n\nevaluate('round(round * 2)', { round: 3.7 })\n// 7\n\n// Field named \"sum\" doesn't conflict with sum() function\nevaluate('sum(values) + sum', { values: [1, 2, 3], sum: 10 })\n// 16`,\n },\n {\n name: 'Evaluate with context (array items)',\n description:\n 'Use evaluateWithContext() for array item formulas with path resolution',\n code: `// Absolute path: /field always resolves from root\nevaluateWithContext('price * (1 + /taxRate)', {\n rootData: { taxRate: 0.1, items: [{ price: 100 }] },\n itemData: { price: 100 },\n currentPath: 'items[0]'\n})\n// 110\n\n// Nested absolute path\nevaluateWithContext('price * /config.multiplier', {\n rootData: { config: { multiplier: 1.5 }, items: [] },\n itemData: { price: 100 },\n currentPath: 'items[0]'\n})\n// 150\n\n// Relative path: ../field resolves from parent (root)\nevaluateWithContext('price * (1 - ../discount)', {\n rootData: { discount: 0.2, items: [] },\n itemData: { price: 100 },\n currentPath: 'items[0]'\n})\n// 80\n\n// itemData takes precedence over rootData for same field\nevaluateWithContext('value + 10', {\n rootData: { value: 100 },\n itemData: { value: 50 },\n currentPath: 'items[0]'\n})\n// 60`,\n },\n ],\n\n schemaUsage: {\n structure:\n '{ \"x-formula\": { \"version\": 1, \"expression\": \"...\" }, \"readOnly\": true }',\n fieldTypes: ['string', 'number', 'boolean'],\n rules: [\n 'Add x-formula to string, number, or boolean field schema',\n 'readOnly: true is REQUIRED for fields with x-formula',\n 'Expression must reference existing fields in the same table',\n 'Circular dependencies are not allowed (a references b, b references a)',\n ],\n },\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/formula-spec.ts"],"names":[],"mappings":";AAuDO,IAAM,WAAA,GAA2B;AAAA,EACtC,OAAA,EAAS,KAAA;AAAA,EACT,WAAA,EACE,8GAAA;AAAA,EAEF,MAAA,EAAQ;AAAA,IACN,eAAA,EAAiB;AAAA,MACf,iDAAA;AAAA,MACA,mDAAA;AAAA,MACA,qDAAA;AAAA,MACA;AAAA,KACF;AAAA,IACA,mBAAA,EAAqB;AAAA,MACnB,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,kCAAA,EAAmC;AAAA,MACjE,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,aAAA,EAAc;AAAA,MAC5C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,gBAAA,EAAiB;AAAA,MAC/C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,UAAA,EAAW;AAAA,MACzC,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,oBAAA;AAAqB,KACrD;AAAA,IACA,mBAAA,EAAqB;AAAA,MACnB,EAAE,QAAA,EAAU,IAAA,EAAM,WAAA,EAAa,OAAA,EAAQ;AAAA,MACvC,EAAE,QAAA,EAAU,IAAA,EAAM,WAAA,EAAa,WAAA,EAAY;AAAA,MAC3C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,cAAA,EAAe;AAAA,MAC7C,EAAE,QAAA,EAAU,GAAA,EAAK,WAAA,EAAa,WAAA,EAA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AAEJ","file":"formula-spec.js","sourcesContent":["export interface FunctionSpec {\n name: string;\n description: string;\n signature: string;\n returnType: 'string' | 'number' | 'boolean' | 'any';\n examples: string[];\n}\n\nexport interface FormulaSpec {\n version: string;\n description: string;\n syntax: {\n fieldReferences: string[];\n arithmeticOperators: { operator: string; description: string }[];\n comparisonOperators: { operator: string; description: string }[];\n logicalOperators: { operator: string; description: string }[];\n other: string[];\n };\n functions: {\n string: FunctionSpec[];\n numeric: FunctionSpec[];\n boolean: FunctionSpec[];\n array: FunctionSpec[];\n conversion: FunctionSpec[];\n conditional: FunctionSpec[];\n };\n features: {\n name: string;\n description: string;\n minVersion: string;\n examples: string[];\n dependenciesExtracted?: string[];\n }[];\n versionDetection: { feature: string; minVersion: string }[];\n parseResult: {\n description: string;\n interface: string;\n };\n examples: {\n expression: string;\n description: string;\n result?: string;\n }[];\n apiExamples: {\n name: string;\n description: string;\n code: string;\n }[];\n schemaUsage: {\n structure: string;\n fieldTypes: string[];\n rules: string[];\n };\n}\n\nexport const formulaSpec: FormulaSpec = {\n version: '1.1',\n description:\n 'Formula expressions for computed fields. Formulas reference other fields and calculate values automatically.',\n\n syntax: {\n fieldReferences: [\n 'Simple field: fieldName (e.g., price, quantity)',\n 'Nested path: object.property (e.g., stats.damage)',\n 'Array index: array[0] or array[-1] for last element',\n 'Combined: items[0].price, user.addresses[-1].city',\n ],\n arithmeticOperators: [\n { operator: '+', description: 'Addition or string concatenation' },\n { operator: '-', description: 'Subtraction' },\n { operator: '*', description: 'Multiplication' },\n { operator: '/', description: 'Division' },\n { operator: '%', description: 'Modulo (remainder)' },\n ],\n comparisonOperators: [\n { operator: '==', description: 'Equal' },\n { operator: '!=', description: 'Not equal' },\n { operator: '>', description: 'Greater than' },\n { operator: '<', description: 'Less than' },\n { operator: '>=', description: 'Greater or equal' },\n { operator: '<=', description: 'Less or equal' },\n ],\n logicalOperators: [\n { operator: '&&', description: 'Logical AND' },\n { operator: '||', description: 'Logical OR' },\n { operator: '!', description: 'Logical NOT' },\n ],\n other: ['Parentheses: (a + b) * c', 'Unary minus: -value, a + -b'],\n },\n\n functions: {\n string: [\n {\n name: 'concat',\n description: 'Concatenate multiple values into a single string',\n signature: 'concat(value1, value2, ...)',\n returnType: 'string',\n examples: [\n 'concat(firstName, \" \", lastName) // \"John Doe\"',\n 'concat(\"Price: \", price, \" USD\") // \"Price: 100 USD\"',\n ],\n },\n {\n name: 'upper',\n description: 'Convert string to uppercase',\n signature: 'upper(text)',\n returnType: 'string',\n examples: ['upper(name) // \"HELLO\"'],\n },\n {\n name: 'lower',\n description: 'Convert string to lowercase',\n signature: 'lower(text)',\n returnType: 'string',\n examples: ['lower(name) // \"hello\"'],\n },\n {\n name: 'trim',\n description: 'Remove whitespace from both ends of a string',\n signature: 'trim(text)',\n returnType: 'string',\n examples: ['trim(name) // \"hello\" from \" hello \"'],\n },\n {\n name: 'left',\n description: 'Extract characters from the beginning of a string',\n signature: 'left(text, count)',\n returnType: 'string',\n examples: ['left(name, 3) // \"hel\" from \"hello\"'],\n },\n {\n name: 'right',\n description: 'Extract characters from the end of a string',\n signature: 'right(text, count)',\n returnType: 'string',\n examples: ['right(name, 3) // \"llo\" from \"hello\"'],\n },\n {\n name: 'replace',\n description: 'Replace first occurrence of a substring',\n signature: 'replace(text, search, replacement)',\n returnType: 'string',\n examples: ['replace(name, \"o\", \"0\") // \"hell0\" from \"hello\"'],\n },\n {\n name: 'join',\n description: 'Join array elements into a string',\n signature: 'join(array, separator?)',\n returnType: 'string',\n examples: ['join(tags) // \"a,b,c\"', 'join(tags, \" | \") // \"a | b | c\"'],\n },\n ],\n numeric: [\n {\n name: 'round',\n description: 'Round a number to specified decimal places',\n signature: 'round(number, decimals?)',\n returnType: 'number',\n examples: ['round(3.14159, 2) // 3.14', 'round(3.5) // 4'],\n },\n {\n name: 'floor',\n description: 'Round down to the nearest integer',\n signature: 'floor(number)',\n returnType: 'number',\n examples: ['floor(3.7) // 3'],\n },\n {\n name: 'ceil',\n description: 'Round up to the nearest integer',\n signature: 'ceil(number)',\n returnType: 'number',\n examples: ['ceil(3.2) // 4'],\n },\n {\n name: 'abs',\n description: 'Get the absolute value',\n signature: 'abs(number)',\n returnType: 'number',\n examples: ['abs(-5) // 5'],\n },\n {\n name: 'sqrt',\n description: 'Calculate the square root',\n signature: 'sqrt(number)',\n returnType: 'number',\n examples: ['sqrt(16) // 4'],\n },\n {\n name: 'pow',\n description: 'Raise a number to a power',\n signature: 'pow(base, exponent)',\n returnType: 'number',\n examples: ['pow(2, 3) // 8'],\n },\n {\n name: 'min',\n description: 'Get the minimum of multiple values',\n signature: 'min(value1, value2, ...)',\n returnType: 'number',\n examples: ['min(a, b, c) // smallest value'],\n },\n {\n name: 'max',\n description: 'Get the maximum of multiple values',\n signature: 'max(value1, value2, ...)',\n returnType: 'number',\n examples: ['max(a, b, c) // largest value'],\n },\n {\n name: 'log',\n description: 'Calculate the natural logarithm',\n signature: 'log(number)',\n returnType: 'number',\n examples: ['log(10) // 2.302...'],\n },\n {\n name: 'log10',\n description: 'Calculate the base-10 logarithm',\n signature: 'log10(number)',\n returnType: 'number',\n examples: ['log10(100) // 2'],\n },\n {\n name: 'exp',\n description: 'Calculate e raised to a power',\n signature: 'exp(number)',\n returnType: 'number',\n examples: ['exp(1) // 2.718...'],\n },\n {\n name: 'sign',\n description: 'Get the sign of a number (-1, 0, or 1)',\n signature: 'sign(number)',\n returnType: 'number',\n examples: ['sign(-5) // -1', 'sign(0) // 0', 'sign(5) // 1'],\n },\n {\n name: 'length',\n description: 'Get the length of a string or array',\n signature: 'length(value)',\n returnType: 'number',\n examples: ['length(name) // 5 from \"hello\"', 'length(items) // 3'],\n },\n ],\n boolean: [\n {\n name: 'and',\n description: 'Logical AND of two values',\n signature: 'and(a, b)',\n returnType: 'boolean',\n examples: ['and(isActive, hasPermission) // true if both true'],\n },\n {\n name: 'or',\n description: 'Logical OR of two values',\n signature: 'or(a, b)',\n returnType: 'boolean',\n examples: ['or(isAdmin, isOwner) // true if either true'],\n },\n {\n name: 'not',\n description: 'Logical NOT of a value',\n signature: 'not(value)',\n returnType: 'boolean',\n examples: ['not(isDeleted) // true if false'],\n },\n {\n name: 'contains',\n description: 'Check if a string contains a substring',\n signature: 'contains(text, search)',\n returnType: 'boolean',\n examples: ['contains(name, \"ell\") // true for \"hello\"'],\n },\n {\n name: 'startswith',\n description: 'Check if a string starts with a prefix',\n signature: 'startswith(text, prefix)',\n returnType: 'boolean',\n examples: ['startswith(name, \"hel\") // true for \"hello\"'],\n },\n {\n name: 'endswith',\n description: 'Check if a string ends with a suffix',\n signature: 'endswith(text, suffix)',\n returnType: 'boolean',\n examples: ['endswith(name, \"llo\") // true for \"hello\"'],\n },\n {\n name: 'isnull',\n description: 'Check if a value is null or undefined',\n signature: 'isnull(value)',\n returnType: 'boolean',\n examples: ['isnull(optionalField) // true if null/undefined'],\n },\n {\n name: 'includes',\n description: 'Check if an array contains a value',\n signature: 'includes(array, value)',\n returnType: 'boolean',\n examples: [\n 'includes(tags, \"featured\") // true if array contains value',\n ],\n },\n ],\n array: [\n {\n name: 'sum',\n description: 'Calculate the sum of array elements',\n signature: 'sum(array)',\n returnType: 'number',\n examples: ['sum(prices) // total of all prices'],\n },\n {\n name: 'avg',\n description: 'Calculate the average of array elements',\n signature: 'avg(array)',\n returnType: 'number',\n examples: ['avg(scores) // average score'],\n },\n {\n name: 'count',\n description: 'Get the number of elements in an array',\n signature: 'count(array)',\n returnType: 'number',\n examples: ['count(items) // number of items'],\n },\n {\n name: 'first',\n description: 'Get the first element of an array',\n signature: 'first(array)',\n returnType: 'any',\n examples: ['first(items) // first item'],\n },\n {\n name: 'last',\n description: 'Get the last element of an array',\n signature: 'last(array)',\n returnType: 'any',\n examples: ['last(items) // last item'],\n },\n ],\n conversion: [\n {\n name: 'tostring',\n description: 'Convert a value to string',\n signature: 'tostring(value)',\n returnType: 'string',\n examples: ['tostring(42) // \"42\"'],\n },\n {\n name: 'tonumber',\n description: 'Convert a value to number',\n signature: 'tonumber(value)',\n returnType: 'number',\n examples: ['tonumber(\"42\") // 42'],\n },\n {\n name: 'toboolean',\n description: 'Convert a value to boolean',\n signature: 'toboolean(value)',\n returnType: 'boolean',\n examples: ['toboolean(1) // true', 'toboolean(0) // false'],\n },\n ],\n conditional: [\n {\n name: 'if',\n description: 'Return one of two values based on a condition',\n signature: 'if(condition, valueIfTrue, valueIfFalse)',\n returnType: 'any',\n examples: [\n 'if(stock > 0, \"Available\", \"Out of Stock\")',\n 'if(price > 100, price * 0.9, price)',\n ],\n },\n {\n name: 'coalesce',\n description: 'Return the first non-null value',\n signature: 'coalesce(value1, value2, ...)',\n returnType: 'any',\n examples: ['coalesce(nickname, name, \"Anonymous\")'],\n },\n ],\n },\n\n features: [\n {\n name: 'simple_refs',\n description: 'Reference top-level fields by name',\n minVersion: '1.0',\n examples: ['price', 'quantity', 'baseDamage'],\n dependenciesExtracted: ['[\"price\"]', '[\"quantity\"]', '[\"baseDamage\"]'],\n },\n {\n name: 'arithmetic',\n description: 'Basic math operations (+, -, *, /)',\n minVersion: '1.0',\n examples: ['price * 1.1', 'a + b - c', 'quantity * price'],\n },\n {\n name: 'comparison',\n description: 'Compare values (>, <, >=, <=, ==, !=)',\n minVersion: '1.0',\n examples: ['price > 100', 'x == 10', 'quantity >= 5'],\n },\n {\n name: 'nested_path',\n description: 'Access nested object properties using dot notation',\n minVersion: '1.1',\n examples: ['stats.damage', 'user.profile.name', 'item.metadata.category'],\n dependenciesExtracted: ['[\"stats.damage\"]'],\n },\n {\n name: 'array_index',\n description:\n 'Access array elements by numeric index. Negative indices access from the end',\n minVersion: '1.1',\n examples: [\n 'items[0].price',\n 'inventory[1].quantity',\n 'items[-1].name // last element',\n 'items[-2].price // second to last',\n ],\n dependenciesExtracted: ['[\"items[0].price\"]', '[\"items[-1].name\"]'],\n },\n {\n name: 'root_path',\n description:\n 'Absolute path reference starting with /. Always resolves from root data, even inside array item formulas',\n minVersion: '1.1',\n examples: [\n '/taxRate',\n '/config.tax',\n 'price * (1 + /taxRate)',\n 'price * /config.multiplier',\n ],\n dependenciesExtracted: ['[\"/taxRate\"]', '[\"/config.tax\"]'],\n },\n {\n name: 'relative_path',\n description:\n 'Relative path reference starting with ../. Each ../ goes up one level in the path hierarchy. Works with nested objects, arrays, and combinations. Supports accessing nested properties after the relative prefix (e.g., ../config.value)',\n minVersion: '1.1',\n examples: [\n '../discount',\n '../../rootRate',\n '../config.multiplier',\n 'price * (1 - ../discount)',\n 'price * ../../globalRate',\n 'price * ../settings.tax.rate',\n ],\n dependenciesExtracted: [\n '[\"../discount\"]',\n '[\"../../rootRate\"]',\n '[\"../config.multiplier\"]',\n ],\n },\n {\n name: 'function_named_fields',\n description:\n 'Fields can have the same name as built-in functions (max, min, sum, etc.). Built-in functions are always checked first when a function call is made',\n minVersion: '1.0',\n examples: [\n 'max(max, 0)',\n 'min(min, 100)',\n 'max(max - field.min, 0)',\n 'round(round * 2)',\n ],\n },\n ],\n\n versionDetection: [\n { feature: 'Simple refs, arithmetic, comparisons', minVersion: '1.0' },\n { feature: 'Function-named fields (max(max, 0))', minVersion: '1.0' },\n { feature: 'Nested paths (a.b)', minVersion: '1.1' },\n { feature: 'Array index ([0], [-1])', minVersion: '1.1' },\n { feature: 'Absolute paths (/field)', minVersion: '1.1' },\n { feature: 'Relative paths (../field)', minVersion: '1.1' },\n ],\n\n parseResult: {\n description:\n 'The parser automatically detects the minimum required version',\n interface: `interface ParseResult {\n ast: ASTNode; // Abstract syntax tree\n dependencies: string[]; // List of field dependencies\n features: string[]; // List of detected features\n minVersion: string; // Minimum required version (\"1.0\" or \"1.1\")\n}`,\n },\n\n examples: [\n {\n expression: 'price * quantity',\n description: 'Calculate total from price and quantity',\n result: 'number',\n },\n {\n expression: 'firstName + \" \" + lastName',\n description: 'Concatenate strings with space',\n result: 'string',\n },\n {\n expression: 'quantity > 0',\n description: 'Check if in stock',\n result: 'boolean',\n },\n {\n expression: 'if(stock > 0, \"Available\", \"Out of Stock\")',\n description: 'Conditional text based on stock',\n result: 'string',\n },\n {\n expression: 'price * (1 + taxRate)',\n description: 'Price with tax',\n result: 'number',\n },\n {\n expression: 'items[0].price + items[1].price',\n description: 'Sum first two item prices (v1.1)',\n result: 'number',\n },\n ],\n\n apiExamples: [\n {\n name: 'Simple Expression (v1.0)',\n description: 'Parse a basic arithmetic expression',\n code: `parseExpression('price * 1.1')\n// {\n// minVersion: \"1.0\",\n// features: [],\n// dependencies: [\"price\"]\n// }`,\n },\n {\n name: 'Nested Path (v1.1)',\n description: 'Parse expression with nested object access',\n code: `parseExpression('stats.damage * multiplier')\n// {\n// minVersion: \"1.1\",\n// features: [\"nested_path\"],\n// dependencies: [\"stats.damage\", \"multiplier\"]\n// }`,\n },\n {\n name: 'Array Access (v1.1)',\n description: 'Parse expression with array index access',\n code: `parseExpression('items[0].price + items[1].price')\n// {\n// minVersion: \"1.1\",\n// features: [\"array_index\", \"nested_path\"],\n// dependencies: [\"items[0].price\", \"items[1].price\"]\n// }`,\n },\n {\n name: 'Evaluate expressions',\n description: 'Execute formulas with context data',\n code: `evaluate('price * 1.1', { price: 100 })\n// 110\n\nevaluate('stats.damage', { stats: { damage: 50 } })\n// 50\n\nevaluate('items[0].price', { items: [{ price: 10 }] })\n// 10\n\nevaluate('price > 100', { price: 150 })\n// true\n\nevaluate('a + b * c', { a: 1, b: 2, c: 3 })\n// 7`,\n },\n {\n name: 'Function-named fields',\n description: 'Fields can have the same name as built-in functions',\n code: `// Built-in functions take precedence in function calls\nevaluate('max(max, 0)', { max: 10 })\n// 10 (max() function, then max field)\n\nevaluate('max(max - field.min, 0)', { max: 100, field: { min: 20 } })\n// 80\n\nevaluate('round(round * 2)', { round: 3.7 })\n// 7\n\n// Field named \"sum\" doesn't conflict with sum() function\nevaluate('sum(values) + sum', { values: [1, 2, 3], sum: 10 })\n// 16`,\n },\n {\n name: 'Evaluate with context (array items)',\n description:\n 'Use evaluateWithContext() for array item formulas with path resolution',\n code: `// Absolute path: /field always resolves from root\nevaluateWithContext('price * (1 + /taxRate)', {\n rootData: { taxRate: 0.1, items: [{ price: 100 }] },\n itemData: { price: 100 },\n currentPath: 'items[0]'\n})\n// 110\n\n// Nested absolute path\nevaluateWithContext('price * /config.multiplier', {\n rootData: { config: { multiplier: 1.5 }, items: [] },\n itemData: { price: 100 },\n currentPath: 'items[0]'\n})\n// 150\n\n// Relative path: ../field resolves from parent (root)\nevaluateWithContext('price * (1 - ../discount)', {\n rootData: { discount: 0.2, items: [] },\n itemData: { price: 100 },\n currentPath: 'items[0]'\n})\n// 80\n\n// itemData takes precedence over rootData for same field\nevaluateWithContext('value + 10', {\n rootData: { value: 100 },\n itemData: { value: 50 },\n currentPath: 'items[0]'\n})\n// 60`,\n },\n {\n name: 'Relative paths - path resolution',\n description:\n 'Understanding how ../ resolves based on currentPath. Each ../ goes up one segment (object property or array element counts as one segment)',\n code: `// Path structure explanation:\n// currentPath splits by \".\" (dots), keeping array indices attached to field names\n// \"items[0]\" = 1 segment\n// \"items[0].inner\" = 2 segments: [\"items[0]\", \"inner\"]\n// \"container.items[0]\" = 2 segments: [\"container\", \"items[0]\"]\n\n// Single ../ from array item -> goes to root\n// currentPath: \"items[0]\" (1 segment)\n// ../ goes up 1 level -> root\nevaluateWithContext('price * ../discount', {\n rootData: { discount: 0.2, items: [{ price: 100 }] },\n itemData: { price: 100 },\n currentPath: 'items[0]'\n})\n// Resolves ../discount to root.discount = 0.2\n// Result: 100 * 0.2 = 20\n\n// Single ../ from nested object in array -> goes to array item\n// currentPath: \"items[0].inner\" (2 segments)\n// ../ goes up 1 level -> \"items[0]\"\nevaluateWithContext('price * ../itemMultiplier', {\n rootData: { items: [{ itemMultiplier: 3, inner: { price: 10 } }] },\n itemData: { price: 10 },\n currentPath: 'items[0].inner'\n})\n// Resolves ../itemMultiplier to items[0].itemMultiplier = 3\n// Result: 10 * 3 = 30\n\n// Double ../../ from nested object in array -> goes to root\n// currentPath: \"items[0].inner\" (2 segments)\n// ../../ goes up 2 levels -> root\nevaluateWithContext('price * ../../rootRate', {\n rootData: { rootRate: 2, items: [{ inner: { price: 5 } }] },\n itemData: { price: 5 },\n currentPath: 'items[0].inner'\n})\n// Resolves ../../rootRate to root.rootRate = 2\n// Result: 5 * 2 = 10`,\n },\n {\n name: 'Relative paths - nested arrays',\n description:\n 'How relative paths work with arrays inside objects and nested arrays',\n code: `// Array inside nested object\n// currentPath: \"container.items[0]\" (2 segments: [\"container\", \"items[0]\"])\n// ../ goes up 1 level -> \"container\"\nevaluateWithContext('price * ../containerRate', {\n rootData: {\n container: {\n containerRate: 4,\n items: [{ price: 5 }]\n }\n },\n itemData: { price: 5 },\n currentPath: 'container.items[0]'\n})\n// Resolves ../containerRate to container.containerRate = 4\n// Result: 5 * 4 = 20\n\n// ../../ from array inside object -> goes to root\n// currentPath: \"container.items[0]\" (2 segments)\n// ../../ goes up 2 levels -> root\nevaluateWithContext('price * ../../rootVal', {\n rootData: {\n rootVal: 6,\n container: { items: [{ price: 5 }] }\n },\n itemData: { price: 5 },\n currentPath: 'container.items[0]'\n})\n// Resolves ../../rootVal to root.rootVal = 6\n// Result: 5 * 6 = 30\n\n// Nested arrays: items[].subItems[]\n// currentPath: \"items[0].subItems[0]\" (2 segments: [\"items[0]\", \"subItems[0]\"])\n// ../ goes up 1 level -> \"items[0]\"\nevaluateWithContext('qty * ../itemPrice', {\n rootData: {\n items: [{ itemPrice: 10, subItems: [{ qty: 3 }] }]\n },\n itemData: { qty: 3 },\n currentPath: 'items[0].subItems[0]'\n})\n// Resolves ../itemPrice to items[0].itemPrice = 10\n// Result: 3 * 10 = 30`,\n },\n {\n name: 'Relative paths - accessing nested properties',\n description:\n 'Relative paths can include nested property access after the ../ prefix',\n code: `// ../sibling.nested accesses a sibling with nested property\n// currentPath: \"items[0].products[0]\" (2 segments)\n// ../ goes to \"items[0]\", then accesses .config.discount\nevaluateWithContext('price * ../config.discount', {\n rootData: {\n items: [{\n config: { discount: 0.9 },\n products: [{ price: 100 }]\n }]\n },\n itemData: { price: 100 },\n currentPath: 'items[0].products[0]'\n})\n// Resolves ../config.discount to items[0].config.discount = 0.9\n// Result: 100 * 0.9 = 90\n\n// Deep nested: ../../settings.tax.rate\nevaluateWithContext('amount * ../../settings.tax.rate', {\n rootData: {\n settings: { tax: { rate: 0.1 } },\n orders: [{ items: [{ amount: 200 }] }]\n },\n itemData: { amount: 200 },\n currentPath: 'orders[0].items[0]'\n})\n// Resolves ../../settings.tax.rate to root.settings.tax.rate = 0.1\n// Result: 200 * 0.1 = 20`,\n },\n {\n name: 'Relative paths - complex nesting',\n description: 'Complex scenarios with arrays inside objects inside arrays',\n code: `// Array inside object inside array\n// Structure: items[].container.subItems[]\n// currentPath: \"items[0].container.subItems[0]\" (3 segments)\nevaluateWithContext('val * ../containerMultiplier', {\n rootData: {\n items: [{\n container: {\n containerMultiplier: 4,\n subItems: [{ val: 3 }]\n }\n }]\n },\n itemData: { val: 3 },\n currentPath: 'items[0].container.subItems[0]'\n})\n// ../ goes to \"items[0].container\"\n// Resolves ../containerMultiplier to items[0].container.containerMultiplier = 4\n// Result: 3 * 4 = 12\n\n// ../../ from same structure -> goes to array item\nevaluateWithContext('val * ../../itemRate', {\n rootData: {\n items: [{\n itemRate: 5,\n container: { subItems: [{ val: 2 }] }\n }]\n },\n itemData: { val: 2 },\n currentPath: 'items[0].container.subItems[0]'\n})\n// ../../ goes to \"items[0]\"\n// Resolves ../../itemRate to items[0].itemRate = 5\n// Result: 2 * 5 = 10\n\n// ../../../ from same structure -> goes to root\nevaluateWithContext('val * ../../../rootFactor', {\n rootData: {\n rootFactor: 3,\n items: [{\n container: { subItems: [{ val: 7 }] }\n }]\n },\n itemData: { val: 7 },\n currentPath: 'items[0].container.subItems[0]'\n})\n// ../../../ goes to root\n// Resolves ../../../rootFactor to root.rootFactor = 3\n// Result: 7 * 3 = 21`,\n },\n ],\n\n schemaUsage: {\n structure:\n '{ \"x-formula\": { \"version\": 1, \"expression\": \"...\" }, \"readOnly\": true }',\n fieldTypes: ['string', 'number', 'boolean'],\n rules: [\n 'Add x-formula to string, number, or boolean field schema',\n 'readOnly: true is REQUIRED for fields with x-formula',\n 'Expression must reference existing fields in the same table',\n 'Circular dependencies are not allowed (a references b, b references a)',\n ],\n },\n};\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkQS3FBYM5_cjs = require('./chunk-QS3FBYM5.cjs');
|
|
4
4
|
|
|
5
5
|
// src/dependency-graph.ts
|
|
6
6
|
function buildDependencyGraph(dependencies) {
|
|
@@ -110,31 +110,31 @@ function processQueue(queue, graph, inDegree) {
|
|
|
110
110
|
|
|
111
111
|
Object.defineProperty(exports, "evaluate", {
|
|
112
112
|
enumerable: true,
|
|
113
|
-
get: function () { return
|
|
113
|
+
get: function () { return chunkQS3FBYM5_cjs.evaluate; }
|
|
114
114
|
});
|
|
115
115
|
Object.defineProperty(exports, "evaluateWithContext", {
|
|
116
116
|
enumerable: true,
|
|
117
|
-
get: function () { return
|
|
117
|
+
get: function () { return chunkQS3FBYM5_cjs.evaluateWithContext; }
|
|
118
118
|
});
|
|
119
119
|
Object.defineProperty(exports, "inferFormulaType", {
|
|
120
120
|
enumerable: true,
|
|
121
|
-
get: function () { return
|
|
121
|
+
get: function () { return chunkQS3FBYM5_cjs.inferFormulaType; }
|
|
122
122
|
});
|
|
123
123
|
Object.defineProperty(exports, "parseExpression", {
|
|
124
124
|
enumerable: true,
|
|
125
|
-
get: function () { return
|
|
125
|
+
get: function () { return chunkQS3FBYM5_cjs.parseExpression; }
|
|
126
126
|
});
|
|
127
127
|
Object.defineProperty(exports, "parseFormula", {
|
|
128
128
|
enumerable: true,
|
|
129
|
-
get: function () { return
|
|
129
|
+
get: function () { return chunkQS3FBYM5_cjs.parseFormula; }
|
|
130
130
|
});
|
|
131
131
|
Object.defineProperty(exports, "validateFormulaSyntax", {
|
|
132
132
|
enumerable: true,
|
|
133
|
-
get: function () { return
|
|
133
|
+
get: function () { return chunkQS3FBYM5_cjs.validateFormulaSyntax; }
|
|
134
134
|
});
|
|
135
135
|
Object.defineProperty(exports, "validateSyntax", {
|
|
136
136
|
enumerable: true,
|
|
137
|
-
get: function () { return
|
|
137
|
+
get: function () { return chunkQS3FBYM5_cjs.validateSyntax; }
|
|
138
138
|
});
|
|
139
139
|
exports.buildDependencyGraph = buildDependencyGraph;
|
|
140
140
|
exports.detectCircularDependencies = detectCircularDependencies;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { evaluate, evaluateWithContext, inferFormulaType, parseExpression, parseFormula, validateFormulaSyntax, validateSyntax } from './chunk-
|
|
1
|
+
export { evaluate, evaluateWithContext, inferFormulaType, parseExpression, parseFormula, validateFormulaSyntax, validateSyntax } from './chunk-V6MB7X37.js';
|
|
2
2
|
|
|
3
3
|
// src/dependency-graph.ts
|
|
4
4
|
function buildDependencyGraph(dependencies) {
|