cxn-engine
v0.0.3
Published
execute CXN expression
Downloads
2
Readme
CXN Execution Engine
general CXN execution engine
Get Started
const { execute } = require("cxn-engine")
const cds = require("@sap/cds-compiler");
const compileCXN = cds.parse.expr;
const ctx = {
a: ["1", "2", 3, 4],
b: [{ c: 1 }, { c: 2, name: "a name" }, { c: 3 }],
c: { d: [{ e: { f: { value: 1 } } }] }
};
expect(execute(compileCXN("a"), ctx)).toBe(ctx.a);
expect(execute(compileCXN("a[0]"), ctx)).toBe(ctx.a[0]);
expect(execute(compileCXN("a[2]"), ctx)).toBe(ctx.a[2]);
expect(execute(compileCXN("b[c=2]"), ctx)).toStrictEqual([ctx.b[1]]);
expect(execute(compileCXN("first(b[c=2])"), ctx)).toBe(ctx.b[1]);
expect(execute(compileCXN("b[c=2].name"), ctx)).toBe(ctx.b[1].name);
expect(execute(compileCXN("c.d[0].e.f.value"), ctx)).toBe(ctx.c.d[0].e.f.value);
Operators
- [x] Logic
- [ ] Deep Equal
- [x] Numeric
- [x] Numeric Common Order (
*
and/
should be calculated firstly)
- [x] Numeric Common Order (
- [x] Compare
- [x] Like/Between
- [x] NOT
- [x] IN
- [x] IS
- [x] EXISTS
Reference Evaluation
- [x] Chain
- [x] Deep
- [ ] Where
Built-in Functions
- [x] first
- [x] last
- [x] sum
- [x] avg
- [x] min
- [x] max
- [ ] assign
- [x] append (covered by
Array.prototype.concat
) - [ ] groupBy
- [x] uuid
- [x] nanoid
- [x] Array.prototype.*
- [x] Date.prototype.*
- [x] Number.prototype.*
- [x] String.prototype.*
Param Binding
- [ ] param binding
Security
- [ ] disable prototype access
- [ ] execution timeout