0.0.3 • Published 2 years ago
cxn-engine v0.0.3
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
- Logic
- Deep Equal
- Numeric
- Numeric Common Order (
*
and/
should be calculated firstly)
- Numeric Common Order (
- Compare
- Like/Between
- NOT
- IN
- IS
- EXISTS
Reference Evaluation
- Chain
- Deep
- Where
Built-in Functions
- first
- last
- sum
- avg
- min
- max
- assign
- append (covered by
Array.prototype.concat
) - groupBy
- uuid
- nanoid
- Array.prototype.*
- Date.prototype.*
- Number.prototype.*
- String.prototype.*
Param Binding
- param binding
Security
- disable prototype access
- execution timeout