@cobol-ts/cel-implementation 0.0.27 → 0.0.29

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/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './src/cel.compile';
2
2
  export * from './src/cel.operations';
3
+ export * from './src/cel.input.usage';
package/dist/index.js CHANGED
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./src/cel.compile"), exports);
18
18
  __exportStar(require("./src/cel.operations"), exports);
19
+ __exportStar(require("./src/cel.input.usage"), exports);
19
20
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,uDAAoC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,uDAAoC;AACpC,wDAAqC"}
@@ -0,0 +1,15 @@
1
+ import { type ErrorsOr } from '@cobol-ts/errors';
2
+ import { compileCelExpression } from './cel.compile';
3
+ export interface CelInputUsage {
4
+ readonly scalars: readonly string[];
5
+ readonly collections: readonly string[];
6
+ }
7
+ /**
8
+ * Inspect the projected input accesses prepared by the scalar CEL compiler.
9
+ * Paths are logical paths (including the input root), not physical field names
10
+ * or occurrence indices. This is static usage, not a runtime read trace:
11
+ * conditional branches and optimised-away reads may also be reported.
12
+ * No records are read and no compiled expression is executed.
13
+ * The arguments and validation errors are those of compileCelExpression.
14
+ */
15
+ export declare function extractCelInputUsage<R, P, I extends readonly number[]>(...[expression, projection, access, ...context]: Parameters<typeof compileCelExpression<R, P, I>>): ErrorsOr<CelInputUsage>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractCelInputUsage = extractCelInputUsage;
4
+ const errors_1 = require("@cobol-ts/errors");
5
+ const cel_compile_1 = require("./cel.compile");
6
+ /**
7
+ * Inspect the projected input accesses prepared by the scalar CEL compiler.
8
+ * Paths are logical paths (including the input root), not physical field names
9
+ * or occurrence indices. This is static usage, not a runtime read trace:
10
+ * conditional branches and optimised-away reads may also be reported.
11
+ * No records are read and no compiled expression is executed.
12
+ * The arguments and validation errors are those of compileCelExpression.
13
+ */
14
+ function extractCelInputUsage(...[expression, projection, access, ...context]) {
15
+ const scalars = new Set();
16
+ const collections = new Set();
17
+ const inspected = {
18
+ preferNumberIntegers: access.preferNumberIntegers,
19
+ compileScalar(path) {
20
+ const result = access.compileScalar(path);
21
+ if (!(0, errors_1.isErrors)(result))
22
+ scalars.add(['input', ...path].join('.'));
23
+ return result;
24
+ }
25
+ };
26
+ if (access.compileArray !== undefined) {
27
+ inspected.compileArray = path => {
28
+ const result = access.compileArray(path);
29
+ if (!(0, errors_1.isErrors)(result))
30
+ collections.add(['input', ...path].join('.'));
31
+ return result;
32
+ };
33
+ }
34
+ const result = (0, cel_compile_1.compileCelExpression)(expression, projection, inspected, ...context);
35
+ if ((0, errors_1.isErrors)(result))
36
+ return result;
37
+ return (0, errors_1.value)({ scalars: [...scalars].sort(), collections: [...collections].sort() });
38
+ }
39
+ //# sourceMappingURL=cel.input.usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cel.input.usage.js","sourceRoot":"","sources":["../../src/cel.input.usage.ts"],"names":[],"mappings":";;AAiBA,oDAuBC;AAxCD,6CAA+D;AAE/D,+CAAkD;AAOlD;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAChC,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAiD;IAE/F,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IACjC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAA;IACrC,MAAM,SAAS,GAAsE;QACjF,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;QACjD,aAAa,CAAC,IAAI;YACd,MAAM,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;YACzC,IAAI,CAAC,IAAA,iBAAQ,EAAC,MAAM,CAAC;gBAAE,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;YAChE,OAAO,MAAM,CAAA;QACjB,CAAC;KACJ,CAAA;IACD,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACpC,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE;YAC5B,MAAM,MAAM,GAAG,MAAM,CAAC,YAAa,CAAC,IAAI,CAAC,CAAA;YACzC,IAAI,CAAC,IAAA,iBAAQ,EAAC,MAAM,CAAC;gBAAE,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;YACpE,OAAO,MAAM,CAAA;QACjB,CAAC,CAAA;IACL,CAAC;IACD,MAAM,MAAM,GAAG,IAAA,kCAAoB,EAAC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,CAAA;IAClF,IAAI,IAAA,iBAAQ,EAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IACnC,OAAO,IAAA,cAAK,EAAC,EAAC,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,IAAI,EAAE,EAAC,CAAC,CAAA;AACtF,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const errors_1 = require("@cobol-ts/errors");
4
+ const cel_access_1 = require("@cobol-ts/cel-access");
5
+ const cel_input_usage_1 = require("./cel.input.usage");
6
+ const projection = {
7
+ customers: { type: 'object', fields: { sicCode: { type: 'integer' } } },
8
+ accounts: { type: 'array', element: {
9
+ balance: { type: 'integer', path: ['RAW-BALANCE'] },
10
+ creditLimit: { type: 'integer' },
11
+ status: { type: 'string' },
12
+ transactions: { type: 'array', element: { amount: { type: 'integer' } } }
13
+ } }
14
+ };
15
+ const access = (0, cel_access_1.jsonAccessCompiler)(projection);
16
+ const usage = (expression) => (0, errors_1.valueOrThrow)((0, cel_input_usage_1.extractCelInputUsage)(expression, projection, access));
17
+ describe('CEL input usage', () => {
18
+ test.each([
19
+ ['input.customers.sicCode', ['input.customers.sicCode'], []],
20
+ ['input.accounts.size()', [], ['input.accounts']],
21
+ ['input.accounts.map(a, a.balance).sum()', ['input.accounts.balance'], ['input.accounts']],
22
+ ['input.accounts.map(a, a.creditLimit).sum()', ['input.accounts.creditLimit'], ['input.accounts']],
23
+ ['input.accounts.filter(a, a.balance < 0).size()', ['input.accounts.balance'], ['input.accounts']],
24
+ ['input.accounts.filter(a, a.balance < 0).map(a, a.balance).sum()', ['input.accounts.balance'], ['input.accounts']],
25
+ ['input.accounts.filter(a, a.status == "A").map(a, a.balance).sum()', ['input.accounts.balance', 'input.accounts.status'], ['input.accounts']],
26
+ ['input.accounts.reduce(total, a, 0, total + a.balance)', ['input.accounts.balance'], ['input.accounts']],
27
+ ['input.accounts[0].balance', ['input.accounts.balance'], ['input.accounts']],
28
+ ['input.accounts.map(a, a.transactions.map(a, a.amount).sum()).sum()', ['input.accounts.transactions.amount'], ['input.accounts', 'input.accounts.transactions']],
29
+ ['input.accounts.map(a, a.transactions.map(t, t.amount + a.balance).sum()).sum()', ['input.accounts.balance', 'input.accounts.transactions.amount'], ['input.accounts', 'input.accounts.transactions']],
30
+ ['input.accounts.map(a, a.balance).size()', ['input.accounts.balance'], ['input.accounts']],
31
+ ['1 + 2', [], []]
32
+ ])('%s', (expression, scalars, collections) => {
33
+ expect(usage(expression)).toEqual({ scalars, collections });
34
+ });
35
+ test('does not treat previous graph values as physical inputs', () => {
36
+ expect((0, errors_1.valueOrThrow)((0, cel_input_usage_1.extractCelInputUsage)('input.customers.sicCode != prev.C0330', projection, access, {}, { prev: { C0330: 'int' } }))).toEqual({ scalars: ['input.customers.sicCode'], collections: [] });
37
+ });
38
+ test('preserves compiler validation errors, not partial usage', () => {
39
+ expect((0, errors_1.errorsOrThrow)((0, cel_input_usage_1.extractCelInputUsage)('input.accounts.map(a, a.unknown).sum()', projection, access))).toEqual(['Unknown CEL projected field input.accounts.unknown']);
40
+ });
41
+ test('preserves the absence of an array access compiler', () => {
42
+ expect((0, errors_1.errorsOrThrow)((0, cel_input_usage_1.extractCelInputUsage)('input.accounts.size()', projection, { compileScalar: access.compileScalar }))).toEqual(['Array accessor required to compile a collection']);
43
+ });
44
+ test('inspection prepares accessors but never reads a record', () => {
45
+ const read = jest.fn(() => { throw new Error('Unexpected scalar read'); });
46
+ const length = jest.fn(() => { throw new Error('Unexpected array read'); });
47
+ const inspected = {
48
+ compileScalar: (path) => {
49
+ const result = (0, errors_1.valueOrThrow)(access.compileScalar(path));
50
+ return (0, errors_1.value)({ ...result, read });
51
+ },
52
+ compileArray: (path) => {
53
+ const result = (0, errors_1.valueOrThrow)(access.compileArray(path));
54
+ return (0, errors_1.value)({ ...result, length });
55
+ }
56
+ };
57
+ expect((0, errors_1.valueOrThrow)((0, cel_input_usage_1.extractCelInputUsage)('input.accounts.map(a, a.balance).sum()', projection, inspected)))
58
+ .toEqual({ scalars: ['input.accounts.balance'], collections: ['input.accounts'] });
59
+ expect(read).not.toHaveBeenCalled();
60
+ expect(length).not.toHaveBeenCalled();
61
+ });
62
+ });
63
+ //# sourceMappingURL=cel.input.usage.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cel.input.usage.spec.js","sourceRoot":"","sources":["../../src/cel.input.usage.spec.ts"],"names":[],"mappings":";;AAAA,6CAAmE;AA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,EAAC,CAAC,CAAA;YACrC,CAAC;SACJ,CAAA;QACD,MAAM,CAAC,IAAA,qBAAY,EAAC,IAAA,sCAAoB,EAAC,wCAAwC,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;aACtG,OAAO,CAAC,EAAC,OAAO,EAAE,CAAC,wBAAwB,CAAC,EAAE,WAAW,EAAE,CAAC,gBAAgB,CAAC,EAAC,CAAC,CAAA;QACpF,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAA;QACnC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAA;IACzC,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
package/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './src/cel.compile'
2
2
  export * from './src/cel.operations'
3
+ export * from './src/cel.input.usage'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cobol-ts/cel-implementation",
3
3
  "description": "Compiled reusable CEL execution functions",
4
- "version": "0.0.27",
4
+ "version": "0.0.29",
5
5
  "main": "dist/index",
6
6
  "types": "dist/index",
7
7
  "browserslist": {
@@ -17,14 +17,14 @@
17
17
  ]
18
18
  },
19
19
  "dependencies": {
20
- "@cobol-ts/cel-types": "0.0.27",
21
- "@cobol-ts/cel-access": "0.0.27",
22
- "@cobol-ts/cursor-loader-csv": "0.0.27",
23
- "@cobol-ts/cel": "0.0.27",
24
- "@cobol-ts/cursor-loader-types": "0.0.27",
25
- "@cobol-ts/errors": "0.0.27",
26
- "@cobol-ts/value-types": "0.0.27",
27
- "@cobol-ts/ring-buffer": "0.0.27"
20
+ "@cobol-ts/cel-types": "0.0.29",
21
+ "@cobol-ts/cel-access": "0.0.29",
22
+ "@cobol-ts/cursor-loader-csv": "0.0.29",
23
+ "@cobol-ts/cel": "0.0.29",
24
+ "@cobol-ts/cursor-loader-types": "0.0.29",
25
+ "@cobol-ts/errors": "0.0.29",
26
+ "@cobol-ts/value-types": "0.0.29",
27
+ "@cobol-ts/ring-buffer": "0.0.29"
28
28
  },
29
29
  "devDependencies": {
30
30
  "typescript": "^5.2.2",