@revisium/formula 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/__tests__/array-context.spec.d.ts +2 -0
- package/dist/__tests__/array-context.spec.d.ts.map +1 -0
- package/dist/__tests__/dependency-graph.spec.d.ts +2 -0
- package/dist/__tests__/dependency-graph.spec.d.ts.map +1 -0
- package/dist/__tests__/evaluate-complex.spec.d.ts +2 -0
- package/dist/__tests__/evaluate-complex.spec.d.ts.map +1 -0
- package/dist/__tests__/parse-formula.spec.d.ts +2 -0
- package/dist/__tests__/parse-formula.spec.d.ts.map +1 -0
- package/dist/__tests__/parser.spec.d.ts +2 -0
- package/dist/__tests__/parser.spec.d.ts.map +1 -0
- package/dist/__tests__/replace-dependencies.spec.d.ts +2 -0
- package/dist/__tests__/replace-dependencies.spec.d.ts.map +1 -0
- package/dist/__tests__/serialize-ast.spec.d.ts +2 -0
- package/dist/__tests__/serialize-ast.spec.d.ts.map +1 -0
- package/dist/__tests__/validate-syntax.spec.d.ts +2 -0
- package/dist/__tests__/validate-syntax.spec.d.ts.map +1 -0
- package/dist/dependency-graph.d.ts +17 -0
- package/dist/dependency-graph.d.ts.map +1 -0
- package/dist/editor/index.cjs +4 -19
- package/dist/editor/index.d.ts +8 -1
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.mjs +3 -0
- package/dist/formula-spec.cjs +808 -535
- package/dist/formula-spec.cjs.map +1 -1
- package/dist/formula-spec.d.ts +10 -5
- package/dist/formula-spec.d.ts.map +1 -0
- package/dist/formula-spec.mjs +1039 -0
- package/dist/formula-spec.mjs.map +1 -0
- package/dist/index.cjs +121 -123
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -20
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +130 -0
- package/dist/index.mjs.map +1 -0
- package/dist/ohm/core/parser.d.ts +30 -0
- package/dist/ohm/core/parser.d.ts.map +1 -0
- package/dist/ohm/core/replace-dependencies.d.ts +3 -0
- package/dist/ohm/core/replace-dependencies.d.ts.map +1 -0
- package/dist/ohm/core/serialize-ast.d.ts +3 -0
- package/dist/ohm/core/serialize-ast.d.ts.map +1 -0
- package/dist/ohm/core/types.d.ts +78 -0
- package/dist/ohm/core/types.d.ts.map +1 -0
- package/dist/ohm/grammar/index.d.ts +3 -0
- package/dist/ohm/grammar/index.d.ts.map +1 -0
- package/dist/ohm/index.d.ts +8 -0
- package/dist/ohm/index.d.ts.map +1 -0
- package/dist/ohm/semantics/index.d.ts +2 -0
- package/dist/ohm/semantics/index.d.ts.map +1 -0
- package/dist/parse-formula.d.ts +9 -0
- package/dist/parse-formula.d.ts.map +1 -0
- package/dist/types.d.ts +52 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validate-syntax-BGrLewnG.cjs +1502 -0
- package/dist/validate-syntax-BGrLewnG.cjs.map +1 -0
- package/dist/validate-syntax-CmqnFrsc.mjs +1421 -0
- package/dist/validate-syntax-CmqnFrsc.mjs.map +1 -0
- package/dist/validate-syntax.d.ts +9 -0
- package/dist/validate-syntax.d.ts.map +1 -0
- package/package.json +12 -11
- package/dist/chunk-5TM76LGI.js +0 -1216
- package/dist/chunk-5TM76LGI.js.map +0 -1
- package/dist/chunk-IM22W645.cjs +0 -1244
- package/dist/chunk-IM22W645.cjs.map +0 -1
- package/dist/editor/index.cjs.map +0 -1
- package/dist/editor/index.d.cts +0 -1
- package/dist/editor/index.js +0 -3
- package/dist/editor/index.js.map +0 -1
- package/dist/formula-spec.d.cts +0 -68
- package/dist/formula-spec.js +0 -765
- package/dist/formula-spec.js.map +0 -1
- package/dist/index-CPsOPCQ6.d.cts +0 -166
- package/dist/index-CPsOPCQ6.d.ts +0 -166
- package/dist/index.d.cts +0 -20
- package/dist/index.js +0 -111
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -53,6 +53,31 @@ evaluate('max(max, 0)', { max: 10 });
|
|
|
53
53
|
evaluate('max(max - field.min, 0)', { max: 100, field: { min: 20 } });
|
|
54
54
|
// 80
|
|
55
55
|
|
|
56
|
+
// AST serialization (inverse of parseFormula)
|
|
57
|
+
import { parseFormula, serializeAst, replaceDependencies } from '@revisium/formula';
|
|
58
|
+
|
|
59
|
+
serializeAst(parseFormula('(a + b) * 2').ast);
|
|
60
|
+
// "(a + b) * 2"
|
|
61
|
+
|
|
62
|
+
serializeAst(parseFormula('a + b * 2').ast);
|
|
63
|
+
// "a + b * 2" (no unnecessary parentheses)
|
|
64
|
+
|
|
65
|
+
serializeAst(parseFormula('items[*].price').ast);
|
|
66
|
+
// "items[*].price"
|
|
67
|
+
|
|
68
|
+
// Dependency replacement
|
|
69
|
+
|
|
70
|
+
const ast = parseFormula('price * quantity + 10').ast;
|
|
71
|
+
const newAst = replaceDependencies(ast, { price: 'cost', quantity: 'qty' });
|
|
72
|
+
serializeAst(newAst);
|
|
73
|
+
// "cost * qty + 10"
|
|
74
|
+
|
|
75
|
+
// Replace with different path types
|
|
76
|
+
const ast2 = parseFormula('items[*].price * 2').ast;
|
|
77
|
+
const newAst2 = replaceDependencies(ast2, { 'items[*].price': 'products[*].cost' });
|
|
78
|
+
serializeAst(newAst2);
|
|
79
|
+
// "products[*].cost * 2"
|
|
80
|
+
|
|
56
81
|
// Type inference
|
|
57
82
|
import { inferFormulaType } from '@revisium/formula';
|
|
58
83
|
|
|
@@ -93,6 +118,8 @@ evaluateWithContext('price * (1 - ../discount)', {
|
|
|
93
118
|
| `evaluate` | Evaluate expression with context |
|
|
94
119
|
| `evaluateWithContext` | Evaluate with automatic `/` and `../` path resolution |
|
|
95
120
|
| `inferFormulaType` | Infer return type of expression |
|
|
121
|
+
| `serializeAst` | Serialize AST back to expression string (inverse of `parseFormula`) |
|
|
122
|
+
| `replaceDependencies` | Replace dependency paths in AST (returns new AST) |
|
|
96
123
|
|
|
97
124
|
### Expression API
|
|
98
125
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-context.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/array-context.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependency-graph.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/dependency-graph.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate-complex.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/evaluate-complex.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-formula.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/parse-formula.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/parser.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-dependencies.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/replace-dependencies.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize-ast.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/serialize-ast.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-syntax.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/validate-syntax.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface DependencyGraph {
|
|
2
|
+
nodes: Set<string>;
|
|
3
|
+
edges: Map<string, Set<string>>;
|
|
4
|
+
}
|
|
5
|
+
export interface CircularDependencyResult {
|
|
6
|
+
hasCircular: boolean;
|
|
7
|
+
cycle: string[] | null;
|
|
8
|
+
}
|
|
9
|
+
export interface TopologicalOrderResult {
|
|
10
|
+
success: boolean;
|
|
11
|
+
order: string[];
|
|
12
|
+
error?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function buildDependencyGraph(dependencies: Record<string, string[]>): DependencyGraph;
|
|
15
|
+
export declare function detectCircularDependencies(graph: DependencyGraph): CircularDependencyResult;
|
|
16
|
+
export declare function getTopologicalOrder(graph: DependencyGraph): TopologicalOrderResult;
|
|
17
|
+
//# sourceMappingURL=dependency-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependency-graph.d.ts","sourceRoot":"","sources":["../src/dependency-graph.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACnB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAgBD,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GACrC,eAAe,CAcjB;AAYD,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,eAAe,GACrB,wBAAwB,CAe1B;AA2CD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,eAAe,GACrB,sBAAsB,CAgBxB"}
|
package/dist/editor/index.cjs
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
const require_validate_syntax = require('../validate-syntax-BGrLewnG.cjs');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "parseExpression", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () { return chunkIM22W645_cjs.parseExpression; }
|
|
10
|
-
});
|
|
11
|
-
Object.defineProperty(exports, "parseFormula", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () { return chunkIM22W645_cjs.parseFormula; }
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(exports, "validateFormulaSyntax", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () { return chunkIM22W645_cjs.validateFormulaSyntax; }
|
|
18
|
-
});
|
|
19
|
-
//# sourceMappingURL=index.cjs.map
|
|
20
|
-
//# sourceMappingURL=index.cjs.map
|
|
3
|
+
exports.parseExpression = require_validate_syntax.parseExpression;
|
|
4
|
+
exports.parseFormula = require_validate_syntax.parseFormula;
|
|
5
|
+
exports.validateFormulaSyntax = require_validate_syntax.validateFormulaSyntax;
|
package/dist/editor/index.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { parseFormula } from '../ohm';
|
|
2
|
+
export { parseExpression } from '../parse-formula';
|
|
3
|
+
export { validateFormulaSyntax } from '../validate-syntax';
|
|
4
|
+
export type { ParseResult, ASTNode } from '../ohm';
|
|
5
|
+
export type { ParsedExpression } from '../parse-formula';
|
|
6
|
+
export type { SyntaxValidationResult } from '../validate-syntax';
|
|
7
|
+
export type { XFormula, FormulaMinorVersion, FormulaFeature, FormulaAnalysis, PathSegment, ParsedPath, PathValidationResult, } from '../types';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/editor/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACnD,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,YAAY,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,YAAY,EACV,QAAQ,EACR,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,WAAW,EACX,UAAU,EACV,oBAAoB,GACrB,MAAM,UAAU,CAAC"}
|