@cobol-ts/dependency_node 0.0.13 → 0.0.16
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 +53 -0
- package/dist/src/dependency.node.accumulator.spec.d.ts +1 -0
- package/dist/src/dependency.node.accumulator.spec.js +38 -0
- package/dist/src/dependency.node.accumulator.spec.js.map +1 -0
- package/dist/src/dependency.node.aggregate.spec.d.ts +1 -0
- package/dist/src/dependency.node.aggregate.spec.js +110 -0
- package/dist/src/dependency.node.aggregate.spec.js.map +1 -0
- package/dist/src/dependency.node.aggregate.typetest.d.ts +1 -0
- package/dist/src/dependency.node.aggregate.typetest.js +45 -0
- package/dist/src/dependency.node.aggregate.typetest.js.map +1 -0
- package/dist/src/dependency.node.d.ts +72 -10
- package/dist/src/dependency.node.js +105 -12
- package/dist/src/dependency.node.js.map +1 -1
- package/dist/src/dependency.node.spec.js +61 -52
- package/dist/src/dependency.node.spec.js.map +1 -1
- package/dist/src/dependency.node.typescript.js +23 -1
- package/dist/src/dependency.node.typescript.js.map +1 -1
- package/dist/src/dependency.node.typescript.spec.js +45 -8
- package/dist/src/dependency.node.typescript.spec.js.map +1 -1
- package/dist/src/dependency.node.typetest.js +9 -7
- package/dist/src/dependency.node.typetest.js.map +1 -1
- package/dist/src/dependency.node.value.types.spec.d.ts +1 -0
- package/dist/src/dependency.node.value.types.spec.js +38 -0
- package/dist/src/dependency.node.value.types.spec.js.map +1 -0
- package/package.json +6 -5
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @cobol-ts/dependency_node
|
|
2
|
+
|
|
3
|
+
Represent authored dependency nodes, normalise explicit and inferred paths, and carry canonical dependency metadata.
|
|
4
|
+
|
|
5
|
+
This package creates node descriptions; it does not sort, plan or execute the resulting graph.
|
|
6
|
+
|
|
7
|
+
## Node lifecycle
|
|
8
|
+
|
|
9
|
+
`CelDependencyNode` is the CEL authoring form: expression, metadata and optional `dependsOn` paths. `normalise` (see [`src/dependency.node.ts`](src/dependency.node.ts)) adds identifiers inferred from CEL, converts supported string paths to canonical array paths and records the node name in metadata.
|
|
10
|
+
|
|
11
|
+
`TemporalDependencyData` has four names: `input`, `now`, `prev` and `variables`. The graph runtime controls `prev` ordering and `now` change propagation; normalising a node is not execution.
|
|
12
|
+
|
|
13
|
+
The metadata distinguishes semantic type, JavaScript working representation, default/error policy and optional commentary. Authoring paths are validated before they become graph edges.
|
|
14
|
+
|
|
15
|
+
## Native aggregate nodes (stages 1–2)
|
|
16
|
+
|
|
17
|
+
`DependencyNode<Input, Acc, Variables>` is a **named discriminated union** of
|
|
18
|
+
`CelDependencyNode<Input, Acc, Variables>` and `AggregateDependencyNode`.
|
|
19
|
+
Likewise, `CanonicalDependencyNode` is the union of the named canonical
|
|
20
|
+
alternatives. Existing CEL-only callers can continue to use
|
|
21
|
+
`CelDependencyGraph` and the original `CannonicalCelDependencyNode` type.
|
|
22
|
+
|
|
23
|
+
An aggregate is authored without CEL or declared dependencies:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
const graph = {
|
|
27
|
+
history: {type: 'cel', cel: 'input.amount', metadata: {
|
|
28
|
+
type: 'number', javascriptType: 'bigint',
|
|
29
|
+
rollingWindow: {periodicity: 'monthly', size: 6}
|
|
30
|
+
}},
|
|
31
|
+
total: {type: 'aggregate', window: 'history', operation: 'sum'}
|
|
32
|
+
} as const
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`normalise()` resolves the window by graph name even when authored later,
|
|
36
|
+
validates the operation and type, and produces exactly one `now.history`
|
|
37
|
+
dependency. The window determines the aggregate's scalar type, except that
|
|
38
|
+
`count` returns a JavaScript `number` representing occupancy. Count is valid
|
|
39
|
+
for any scalar window; sum/min/max require number- or bigint-backed values.
|
|
40
|
+
The initial native operations are `sum`, `min`, `max` and `count`; average
|
|
41
|
+
requires a separate persisted supporting-state contract.
|
|
42
|
+
|
|
43
|
+
The independent `@cobol-ts/rolling-aggregate` package provides the pure
|
|
44
|
+
arithmetic. Canonicalisation **does not** yet compile or execute aggregate
|
|
45
|
+
nodes; those integration steps are separate.
|
|
46
|
+
|
|
47
|
+
## Source and tests
|
|
48
|
+
|
|
49
|
+
**Public entry points:** [dependency.node.ts](./src/dependency.node.ts).
|
|
50
|
+
|
|
51
|
+
**Tests:** [dependency.node.accumulator.spec.ts](src/dependency.node.accumulator.spec.ts), [dependency.node.spec.ts](src/dependency.node.spec.ts), [dependency.node.typescript.spec.ts](src/dependency.node.typescript.spec.ts) (+1 more)
|
|
52
|
+
|
|
53
|
+
**Related:** [@cobol-ts/cel](../cel/README.md) · [@cobol-ts/cel-graph-runtime](../../cel/graph-runtime/README.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dependency_node_typescript_1 = require("./dependency.node.typescript");
|
|
4
|
+
it('emits explicit accumulator-write metadata in the generated TypeScript graph', () => {
|
|
5
|
+
const node = {
|
|
6
|
+
type: 'cel',
|
|
7
|
+
cel: 'now.total + 1',
|
|
8
|
+
metadata: { name: 'total', type: 'number', javascriptType: 'bigint', accumulator: true },
|
|
9
|
+
valueType: { kind: 'scalar', semanticType: 'integer', javascriptType: 'bigint' },
|
|
10
|
+
dependsOn: [['now', 'total']]
|
|
11
|
+
};
|
|
12
|
+
expect((0, dependency_node_typescript_1.generateTypescript)([node], 'graph', {
|
|
13
|
+
input: 'Input', acc: 'Accumulator', variables: 'Vars'
|
|
14
|
+
})).toEqual([
|
|
15
|
+
'import type { NameAnd } from "@cobol-ts/records"',
|
|
16
|
+
'import type { CannonicalCelDependencyNode } from "@cobol-ts/dependency-node"',
|
|
17
|
+
'',
|
|
18
|
+
'export const graph = {',
|
|
19
|
+
' "total": {',
|
|
20
|
+
' type: "cel",',
|
|
21
|
+
' cel: "now.total + 1",',
|
|
22
|
+
' metadata: {',
|
|
23
|
+
' name: "total",',
|
|
24
|
+
' type: "number",',
|
|
25
|
+
' javascriptType: "bigint",',
|
|
26
|
+
' accumulator: true,',
|
|
27
|
+
' },',
|
|
28
|
+
' valueType: {"kind":"scalar","semanticType":"integer","javascriptType":"bigint"},',
|
|
29
|
+
' dependsOn: [',
|
|
30
|
+
' ["now", "total"],',
|
|
31
|
+
' ],',
|
|
32
|
+
' },',
|
|
33
|
+
'} as const satisfies NameAnd<',
|
|
34
|
+
' CannonicalCelDependencyNode<Input, Accumulator, Vars>',
|
|
35
|
+
'>'
|
|
36
|
+
]);
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=dependency.node.accumulator.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependency.node.accumulator.spec.js","sourceRoot":"","sources":["../../src/dependency.node.accumulator.spec.ts"],"names":[],"mappings":";;AAAA,6EAA+D;AAG/D,EAAE,CAAC,6EAA6E,EAAE,GAAG,EAAE;IACnF,MAAM,IAAI,GAAwE;QAC9E,IAAI,EAAE,KAAK;QACX,GAAG,EAAE,eAAe;QACpB,QAAQ,EAAE,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAC;QACrF,SAAS,EAAC,EAAC,IAAI,EAAC,QAAQ,EAAC,YAAY,EAAC,SAAS,EAAC,cAAc,EAAC,QAAQ,EAAC;QACxE,SAAS,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;KAChC,CAAA;IACD,MAAM,CAAC,IAAA,+CAAkB,EAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE;QACvC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM;KACxD,CAAC,CAAC,CAAC,OAAO,CAAC;QACR,kDAAkD;QAClD,8EAA8E;QAC9E,EAAE;QACF,wBAAwB;QACxB,gBAAgB;QAChB,sBAAsB;QACtB,+BAA+B;QAC/B,qBAAqB;QACrB,4BAA4B;QAC5B,6BAA6B;QAC7B,uCAAuC;QACvC,gCAAgC;QAChC,YAAY;QACZ,0FAA0F;QAC1F,sBAAsB;QACtB,+BAA+B;QAC/B,YAAY;QACZ,QAAQ;QACR,+BAA+B;QAC/B,2DAA2D;QAC3D,GAAG;KACN,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const errors_1 = require("@cobol-ts/errors");
|
|
4
|
+
const dependency_node_1 = require("./dependency.node");
|
|
5
|
+
function windowNode(javascriptType = 'bigint') {
|
|
6
|
+
return {
|
|
7
|
+
type: 'cel',
|
|
8
|
+
cel: 'input.amount',
|
|
9
|
+
metadata: {
|
|
10
|
+
type: (javascriptType === 'string' ? 'string' : 'number'),
|
|
11
|
+
javascriptType,
|
|
12
|
+
rollingWindow: { periodicity: 'monthly', size: 6 }
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
describe('aggregate node normalisation', () => {
|
|
17
|
+
it('normalises an aggregate declared before its rolling window without CEL compilation', () => {
|
|
18
|
+
const graph = {
|
|
19
|
+
sixMonthTotal: { type: 'aggregate', window: 'monthlyHistory', operation: 'sum' },
|
|
20
|
+
monthlyHistory: windowNode(),
|
|
21
|
+
sixMonthMaximum: { type: 'aggregate', window: 'monthlyHistory', operation: 'max', metadata: { comment: 'Largest month' } }
|
|
22
|
+
};
|
|
23
|
+
const result = (0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)(graph));
|
|
24
|
+
expect(result).toEqual([
|
|
25
|
+
{
|
|
26
|
+
type: 'aggregate',
|
|
27
|
+
window: 'monthlyHistory',
|
|
28
|
+
operation: 'sum',
|
|
29
|
+
metadata: { name: 'sixMonthTotal', type: 'number', javascriptType: 'bigint' },
|
|
30
|
+
valueType: { kind: 'scalar', semanticType: 'integer', javascriptType: 'bigint' },
|
|
31
|
+
dependsOn: [['now', 'monthlyHistory']]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: 'cel',
|
|
35
|
+
cel: 'input.amount',
|
|
36
|
+
metadata: {
|
|
37
|
+
name: 'monthlyHistory', type: 'number', javascriptType: 'bigint',
|
|
38
|
+
rollingWindow: { periodicity: 'monthly', size: 6 }
|
|
39
|
+
},
|
|
40
|
+
valueType: {
|
|
41
|
+
kind: 'rolling-window', periodicity: 'monthly', size: 6,
|
|
42
|
+
element: { kind: 'scalar', semanticType: 'integer', javascriptType: 'bigint' }
|
|
43
|
+
},
|
|
44
|
+
dependsOn: [['input', 'amount']]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'aggregate',
|
|
48
|
+
window: 'monthlyHistory',
|
|
49
|
+
operation: 'max',
|
|
50
|
+
metadata: { name: 'sixMonthMaximum', type: 'number', javascriptType: 'bigint', comment: 'Largest month' },
|
|
51
|
+
valueType: { kind: 'scalar', semanticType: 'integer', javascriptType: 'bigint' },
|
|
52
|
+
dependsOn: [['now', 'monthlyHistory']]
|
|
53
|
+
}
|
|
54
|
+
]);
|
|
55
|
+
});
|
|
56
|
+
it('uses an integer number result for count even when the window stores bigint', () => {
|
|
57
|
+
const graph = {
|
|
58
|
+
history: windowNode(),
|
|
59
|
+
observations: { type: 'aggregate', window: 'history', operation: 'count' }
|
|
60
|
+
};
|
|
61
|
+
expect((0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)(graph))[1]).toEqual({
|
|
62
|
+
type: 'aggregate', window: 'history', operation: 'count',
|
|
63
|
+
metadata: { name: 'observations', type: 'number', javascriptType: 'number' },
|
|
64
|
+
valueType: { kind: 'scalar', semanticType: 'integer', javascriptType: 'number' },
|
|
65
|
+
dependsOn: [['now', 'history']]
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
it('allows count over a non-numeric rolling window', () => {
|
|
69
|
+
const graph = {
|
|
70
|
+
history: { type: 'cel', cel: 'input.label', metadata: {
|
|
71
|
+
type: 'string', rollingWindow: { periodicity: 'monthly', size: 3 }
|
|
72
|
+
} },
|
|
73
|
+
observations: { type: 'aggregate', window: 'history', operation: 'count' }
|
|
74
|
+
};
|
|
75
|
+
expect((0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)(graph))[1].valueType)
|
|
76
|
+
.toEqual({ kind: 'scalar', semanticType: 'integer', javascriptType: 'number' });
|
|
77
|
+
});
|
|
78
|
+
it('rejects unknown windows, non-windows, unsupported operators and invalid metadata exactly', () => {
|
|
79
|
+
expect((0, errors_1.errorsOrThrow)((0, dependency_node_1.normalise)({
|
|
80
|
+
result: { type: 'aggregate', window: 'missing', operation: 'sum' }
|
|
81
|
+
}))).toEqual(['Graph result.window: Unknown rolling-window node "missing"']);
|
|
82
|
+
expect((0, errors_1.errorsOrThrow)((0, dependency_node_1.normalise)({
|
|
83
|
+
inputValue: { type: 'cel', cel: '1', metadata: { type: 'number' } },
|
|
84
|
+
result: { type: 'aggregate', window: 'inputValue', operation: 'sum' }
|
|
85
|
+
}))).toEqual(['Graph result.window: "inputValue" is not a rolling-window node']);
|
|
86
|
+
expect((0, errors_1.errorsOrThrow)((0, dependency_node_1.normalise)({
|
|
87
|
+
history: windowNode(),
|
|
88
|
+
result: { type: 'aggregate', window: 'history', operation: 'average' }
|
|
89
|
+
}))).toEqual(['Graph result.operation: Unsupported aggregate operation "average"']);
|
|
90
|
+
expect((0, errors_1.errorsOrThrow)((0, dependency_node_1.normalise)({
|
|
91
|
+
history: windowNode(),
|
|
92
|
+
result: { type: 'aggregate', window: 'history', operation: 'sum', metadata: { comment: 3 } }
|
|
93
|
+
}))).toEqual(['Graph result.metadata: Only an optional string comment is allowed']);
|
|
94
|
+
});
|
|
95
|
+
it('rejects arithmetic aggregates for non-numeric windows', () => {
|
|
96
|
+
const graph = {
|
|
97
|
+
history: { type: 'cel', cel: 'input.label', metadata: {
|
|
98
|
+
type: 'string', rollingWindow: { periodicity: 'monthly', size: 3 }
|
|
99
|
+
} },
|
|
100
|
+
result: { type: 'aggregate', window: 'history', operation: 'max' }
|
|
101
|
+
};
|
|
102
|
+
expect((0, errors_1.errorsOrThrow)((0, dependency_node_1.normalise)(graph))).toEqual([
|
|
103
|
+
'Graph result.window: "history" must contain numeric values'
|
|
104
|
+
]);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
/** A separate check for the authored discriminant, with named alternatives. */
|
|
108
|
+
const _aggregateContract = { type: 'aggregate', window: 'monthlyHistory', operation: 'sum' };
|
|
109
|
+
void _aggregateContract;
|
|
110
|
+
//# sourceMappingURL=dependency.node.aggregate.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependency.node.aggregate.spec.js","sourceRoot":"","sources":["../../src/dependency.node.aggregate.spec.ts"],"names":[],"mappings":";;AAAA,6CAA4D;AAC5D,uDAK0B;AAO1B,SAAS,UAAU,CAAC,iBAAiD,QAAQ;IACzE,OAAO;QACH,IAAI,EAAE,KAAc;QACpB,GAAG,EAAE,cAAc;QACnB,QAAQ,EAAE;YACN,IAAI,EAAE,CAAC,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAwB;YAChF,cAAc;YACd,aAAa,EAAE,EAAC,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAC;SACnD;KACJ,CAAA;AACL,CAAC;AAED,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC1C,EAAE,CAAC,oFAAoF,EAAE,GAAG,EAAE;QAC1F,MAAM,KAAK,GAAG;YACV,aAAa,EAAE,EAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,KAAK,EAAC;YAC9E,cAAc,EAAE,UAAU,EAAE;YAC5B,eAAe,EAAE,EAAC,IAAI,E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3
|
+
const aggregate = { type: 'aggregate', window: 'history', operation: 'sum' };
|
|
4
|
+
const cel = {
|
|
5
|
+
type: 'cel', cel: 'input.amount', metadata: { type: 'number' }
|
|
6
|
+
};
|
|
7
|
+
// The authored union has separately named branches with a shared discriminant.
|
|
8
|
+
const nodes = [aggregate, cel];
|
|
9
|
+
for (const node of nodes) {
|
|
10
|
+
if (node.type === 'aggregate') {
|
|
11
|
+
const window = node.window;
|
|
12
|
+
void window;
|
|
13
|
+
// @ts-expect-error Aggregate nodes cannot have CEL expressions.
|
|
14
|
+
const expression = node.cel;
|
|
15
|
+
void expression;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const expression = node.cel;
|
|
19
|
+
void expression;
|
|
20
|
+
// @ts-expect-error CEL nodes do not have an aggregate window.
|
|
21
|
+
const window = node.window;
|
|
22
|
+
void window;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// @ts-expect-error An aggregate cannot declare a CEL expression.
|
|
26
|
+
const invalidCel = { type: 'aggregate', window: 'history', operation: 'max', cel: '1' };
|
|
27
|
+
// @ts-expect-error Aggregates derive dependencies from their owning window.
|
|
28
|
+
const invalidDepends = { type: 'aggregate', window: 'history', operation: 'sum', dependsOn: [] };
|
|
29
|
+
// @ts-expect-error Only supported native operations are authorised.
|
|
30
|
+
const invalidOperation = { type: 'aggregate', window: 'history', operation: 'avg' };
|
|
31
|
+
void invalidCel;
|
|
32
|
+
void invalidDepends;
|
|
33
|
+
void invalidOperation;
|
|
34
|
+
const canonical = {
|
|
35
|
+
type: 'aggregate', window: 'history', operation: 'sum',
|
|
36
|
+
metadata: { name: 'total', type: 'number', javascriptType: 'bigint' },
|
|
37
|
+
valueType: { kind: 'scalar', semanticType: 'integer', javascriptType: 'bigint' },
|
|
38
|
+
dependsOn: [['now', 'history']]
|
|
39
|
+
};
|
|
40
|
+
const canonicalNode = canonical;
|
|
41
|
+
if (canonicalNode.type === 'aggregate') {
|
|
42
|
+
const name = canonicalNode.window;
|
|
43
|
+
void name;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=dependency.node.aggregate.typetest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependency.node.aggregate.typetest.js","sourceRoot":"","sources":["../../src/dependency.node.aggregate.typetest.ts"],"names":[],"mappings":";;AAYA,MAAM,SAAS,GAA4B,EAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAC,CAAA;AACnG,MAAM,GAAG,GAA6C;IAClD,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC;CAC/D,CAAA;AAED,+EAA+E;AAC/E,MAAM,KAAK,GAA4C,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;AACvE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;IACvB,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAW,IAAI,CAAC,MAAM,CAAA;QAClC,KAAK,MAAM,CAAA;QACX,gEAAgE;QAChE,MAAM,UAAU,GAAW,IAAI,CAAC,GAAG,CAAA;QACnC,KAAK,UAAU,CAAA;IACnB,CAAC;SAAM,CAAC;QACJ,MAAM,UAAU,GAAW,IAAI,CAAC,GAAG,CAAA;QACnC,KAAK,UAAU,CAAA;QACf,8DAA8D;QAC9D,MAAM,MAAM,GAAW,IAAI,CAAC,MAAM,CAAA;QAClC,KAAK,MAAM,CAAA;IACf,CAAC;AACL,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,GAA4B,EAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAC,CAAA;AAC9G,4EAA4E;AAC5E,MAAM,cAAc,GAA4B,EAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,EAAC,CAAA;AACvH,oEAAoE;AACpE,MAAM,gBAAgB,GAA4B,EAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAC,CAAA;AAC1G,KAAK,UAAU,CAAA;AACf,KAAK,cAAc,CAAA;AACnB,KAAK,gBAAgB,CAAA;AAErB,MAAM,SAAS,GAA4D;IACvE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK;IACtD,QAAQ,EAAE,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAC;IACnE,SAAS,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAC;IAC9E,SAAS,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;CAClC,CAAA;AACD,MAAM,aAAa,GAAmD,SAAS,CAAA;AAC/E,IAAI,aAAa,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;IACrC,MAAM,IAAI,GAAW,aAAa,CAAC,MAAM,CAAA;IACzC,KAAK,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -1,35 +1,97 @@
|
|
|
1
|
+
import { type JavaScriptScalarType, type ScalarValueType, type RollingWindowValueType, type RollingAggregateOperation } from '@cobol-ts/value-types';
|
|
1
2
|
import { type ErrorsOr } from '@cobol-ts/errors';
|
|
2
|
-
import { type EvaluationData } from '@cobol-ts/graph';
|
|
3
3
|
import { type ArrayPath, type StringPath } from '@cobol-ts/path';
|
|
4
4
|
import { type NameAnd } from '@cobol-ts/records';
|
|
5
5
|
export type DependencyNodeMetadata = {
|
|
6
6
|
name: string;
|
|
7
7
|
type: 'string' | 'number' | 'boolean';
|
|
8
|
+
/** Working JS representation; number arithmetic is the default for numeric nodes. */
|
|
9
|
+
javascriptType?: JavaScriptScalarType;
|
|
10
|
+
/** Legacy CEL-specific result declaration, retained for compatibility. */
|
|
11
|
+
celResultType?: 'int' | 'uint' | 'double' | 'string' | 'bool' | 'null';
|
|
12
|
+
default?: string | number | bigint | boolean;
|
|
13
|
+
errorIfNotPresent?: boolean;
|
|
8
14
|
comment?: string;
|
|
15
|
+
/** Legacy authoring flag; every graph node now updates the working accumulator. */
|
|
16
|
+
accumulator?: boolean;
|
|
9
17
|
array?: boolean;
|
|
18
|
+
/** A rolling window is a value, not a distinct node kind. The CEL result is its scalar element. */
|
|
19
|
+
rollingWindow?: Readonly<{
|
|
20
|
+
periodicity: string;
|
|
21
|
+
size: number;
|
|
22
|
+
}>;
|
|
23
|
+
/** Optional schedule for updating a scalar node. Unset means ordinary evaluation. */
|
|
24
|
+
periodicity?: string;
|
|
25
|
+
/** Reset a scalar to its canonical default after all graph nodes have executed. */
|
|
26
|
+
resetOn?: string;
|
|
27
|
+
};
|
|
28
|
+
export type TemporalDependencyData<Input, Acc, Variables> = {
|
|
29
|
+
input: Input;
|
|
30
|
+
now: Acc;
|
|
31
|
+
prev: Acc;
|
|
32
|
+
variables: Variables;
|
|
10
33
|
};
|
|
11
34
|
export type CelDependencyNode<Input, Acc, Variables> = {
|
|
12
35
|
type: 'cel';
|
|
13
36
|
cel: string;
|
|
14
37
|
metadata: Omit<DependencyNodeMetadata, 'name'>;
|
|
15
|
-
dependsOn?: StringPath<
|
|
38
|
+
dependsOn?: StringPath<TemporalDependencyData<Input, Acc, Variables>>[];
|
|
39
|
+
};
|
|
40
|
+
/** Aggregate nodes have no CEL text and do not declare their own result type.
|
|
41
|
+
* The referenced window determines the scalar representation at normalisation.
|
|
42
|
+
*/
|
|
43
|
+
export type AggregateDependencyNodeMetadata = Readonly<{
|
|
44
|
+
comment?: string;
|
|
45
|
+
}>;
|
|
46
|
+
export type AggregateDependencyNode = {
|
|
47
|
+
type: 'aggregate';
|
|
48
|
+
window: string;
|
|
49
|
+
operation: RollingAggregateOperation;
|
|
50
|
+
metadata?: AggregateDependencyNodeMetadata;
|
|
51
|
+
cel?: never;
|
|
52
|
+
dependsOn?: never;
|
|
16
53
|
};
|
|
54
|
+
export type DependencyNode<Input, Acc, Variables> = CelDependencyNode<Input, Acc, Variables> | AggregateDependencyNode;
|
|
55
|
+
/** Retained for CEL-only callers until the graph runtime supports mixed execution. */
|
|
17
56
|
export type CelDependencyGraph<Input, Acc, Variables> = NameAnd<CelDependencyNode<Input, Acc, Variables>>;
|
|
57
|
+
export type DependencyGraph<Input, Acc, Variables> = NameAnd<DependencyNode<Input, Acc, Variables>>;
|
|
18
58
|
export type CannonicalCelDependencyNode<Input, Acc, Variables> = {
|
|
19
59
|
type: 'cel';
|
|
20
60
|
cel: string;
|
|
21
|
-
metadata: DependencyNodeMetadata
|
|
22
|
-
|
|
61
|
+
metadata: DependencyNodeMetadata & {
|
|
62
|
+
javascriptType: JavaScriptScalarType;
|
|
63
|
+
};
|
|
64
|
+
/** Authoritative output type, calculated exactly once when authoring becomes canonical. */
|
|
65
|
+
valueType: ScalarValueType | RollingWindowValueType;
|
|
66
|
+
dependsOn: ArrayPath<TemporalDependencyData<Input, Acc, Variables>>[];
|
|
67
|
+
/** Nodes that must execute after this node; ordering only, not change propagation. */
|
|
68
|
+
mustBeBefore?: ArrayPath<TemporalDependencyData<Input, Acc, Variables>>[];
|
|
69
|
+
};
|
|
70
|
+
export type CanonicalAggregateDependencyNode<Input, Acc, Variables> = {
|
|
71
|
+
type: 'aggregate';
|
|
72
|
+
window: string;
|
|
73
|
+
operation: RollingAggregateOperation;
|
|
74
|
+
metadata: DependencyNodeMetadata & {
|
|
75
|
+
javascriptType: JavaScriptScalarType;
|
|
76
|
+
};
|
|
77
|
+
valueType: ScalarValueType;
|
|
78
|
+
/** Exactly one current-value dependency on the owning rolling window. */
|
|
79
|
+
dependsOn: ArrayPath<TemporalDependencyData<Input, Acc, Variables>>[];
|
|
80
|
+
mustBeBefore?: ArrayPath<TemporalDependencyData<Input, Acc, Variables>>[];
|
|
23
81
|
};
|
|
82
|
+
export type CanonicalDependencyNode<Input, Acc, Variables> = CannonicalCelDependencyNode<Input, Acc, Variables> | CanonicalAggregateDependencyNode<Input, Acc, Variables>;
|
|
24
83
|
/** Roots that may be inferred as graph dependencies from CEL identifiers. */
|
|
25
|
-
export type DependencyPrefix = keyof
|
|
84
|
+
export type DependencyPrefix = keyof TemporalDependencyData<unknown, unknown, unknown> & string;
|
|
26
85
|
export type NormaliseOptions = {
|
|
27
86
|
/** Overrides the default EvaluationData roots for inferred dependencies only. */
|
|
28
87
|
dependencyPrefixes?: readonly DependencyPrefix[];
|
|
29
88
|
};
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
* Dependencies are ordered by first occurrence, with extracted paths first.
|
|
33
|
-
* CEL errors are returned through ErrorsOr with the node name for context.
|
|
34
|
-
*/
|
|
89
|
+
/** CEL-only overload retains the existing inferred canonical type. */
|
|
35
90
|
export declare function normalise<Input, Acc, Variables>(graph: CelDependencyGraph<Input, Acc, Variables>, options?: NormaliseOptions): ErrorsOr<CannonicalCelDependencyNode<Input, Acc, Variables>[]>;
|
|
91
|
+
/** Mixed authoring requires a discriminated canonical graph. */
|
|
92
|
+
export declare function normalise<Input, Acc, Variables>(graph: DependencyGraph<Input, Acc, Variables>, options?: NormaliseOptions): ErrorsOr<CanonicalDependencyNode<Input, Acc, Variables>[]>;
|
|
93
|
+
/** Inspect a validated CEL expression without storing redundant temporal-read metadata. */
|
|
94
|
+
export declare function readsPreviousValue(cel: string, name?: string): boolean;
|
|
95
|
+
/** Read a canonical graph node's type, without inventing a physical representation.
|
|
96
|
+
* CEL vocabulary and legacy number metadata are interpreted at this boundary. */
|
|
97
|
+
export declare function canonicalNodeValueType(metadata: DependencyNodeMetadata): ScalarValueType | RollingWindowValueType;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalise = normalise;
|
|
4
|
+
exports.readsPreviousValue = readsPreviousValue;
|
|
5
|
+
exports.canonicalNodeValueType = canonicalNodeValueType;
|
|
6
|
+
const value_types_1 = require("@cobol-ts/value-types");
|
|
4
7
|
const cel_1 = require("@cobol-ts/cel");
|
|
5
8
|
const path_1 = require("@cobol-ts/path");
|
|
6
9
|
const defaultDependencyPrefixes = [
|
|
7
10
|
'input',
|
|
8
|
-
'
|
|
9
|
-
'
|
|
11
|
+
'now',
|
|
12
|
+
'prev',
|
|
10
13
|
'variables'
|
|
11
14
|
];
|
|
12
15
|
/** Only identifiers rooted in an allowed EvaluationData field become dependencies. */
|
|
@@ -23,18 +26,25 @@ function isDataReference(identifier, prefixes) {
|
|
|
23
26
|
function extractedPath(identifier) {
|
|
24
27
|
return (0, path_1.fromStringToArray)(identifier);
|
|
25
28
|
}
|
|
26
|
-
/** Normalise CEL and
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* CEL errors are returned through ErrorsOr with the node name for context.
|
|
29
|
+
/** Normalise CEL expressions and resolve explicit aggregate-to-window references.
|
|
30
|
+
* Existing CEL-only graphs retain their original order, output and diagnostics.
|
|
31
|
+
* Aggregate nodes are resolved in a second pass so their window may be declared later.
|
|
30
32
|
*/
|
|
31
33
|
function normalise(graph, options = {}) {
|
|
32
34
|
const prefixes = options.dependencyPrefixes ?? defaultDependencyPrefixes;
|
|
33
|
-
const
|
|
35
|
+
const entries = Object.entries(graph);
|
|
36
|
+
const nodes = Array(entries.length);
|
|
34
37
|
const errors = [];
|
|
35
|
-
for (
|
|
38
|
+
for (let index = 0; index < entries.length; index++) {
|
|
39
|
+
const [name, node] = entries[index];
|
|
40
|
+
if (node.type === 'aggregate')
|
|
41
|
+
continue;
|
|
42
|
+
if (node.type !== 'cel') {
|
|
43
|
+
errors.push(`Graph ${name}: Invalid node type`);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
36
46
|
const formatted = (0, cel_1.normaliseCel)(node.cel);
|
|
37
|
-
const identifiers = (0, cel_1.
|
|
47
|
+
const identifiers = (0, cel_1.extractFreeIdentifiers)(node.cel);
|
|
38
48
|
if ('errors' in formatted || 'errors' in identifiers) {
|
|
39
49
|
// Both operations parse the same source. Report its syntax errors once.
|
|
40
50
|
const diagnostics = 'errors' in formatted
|
|
@@ -54,13 +64,96 @@ function normalise(graph, options = {}) {
|
|
|
54
64
|
if (!unique.has(key))
|
|
55
65
|
unique.set(key, [...path]);
|
|
56
66
|
}
|
|
57
|
-
|
|
67
|
+
const javascriptType = node.metadata.javascriptType ??
|
|
68
|
+
(node.metadata.type === 'number' ? 'number' : node.metadata.type === 'boolean' ? 'boolean' : 'string');
|
|
69
|
+
const canonicalMetadata = { ...node.metadata, name, javascriptType };
|
|
70
|
+
let valueType;
|
|
71
|
+
try {
|
|
72
|
+
valueType = canonicalNodeValueType(canonicalMetadata);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
errors.push(error instanceof Error ? error.message : String(error));
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
nodes[index] = {
|
|
58
79
|
type: node.type,
|
|
59
80
|
cel: formatted.value,
|
|
60
|
-
metadata:
|
|
81
|
+
metadata: canonicalMetadata,
|
|
82
|
+
valueType,
|
|
61
83
|
dependsOn: [...unique.values()]
|
|
62
|
-
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const byName = new Map(nodes.flatMap(node => node === undefined ? [] : [[node.metadata.name, node]]));
|
|
87
|
+
for (let index = 0; index < entries.length; index++) {
|
|
88
|
+
const [name, node] = entries[index];
|
|
89
|
+
if (node.type !== 'aggregate')
|
|
90
|
+
continue;
|
|
91
|
+
if (typeof node.window !== 'string' || node.window.length === 0 || node.window.trim() !== node.window || node.window.includes('.')) {
|
|
92
|
+
errors.push(`Graph ${name}.window: Expected a nonempty graph node name`);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (!['sum', 'min', 'max', 'count'].includes(node.operation)) {
|
|
96
|
+
errors.push(`Graph ${name}.operation: Unsupported aggregate operation ${JSON.stringify(node.operation)}`);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (node.metadata !== undefined && (typeof node.metadata !== 'object' || node.metadata === null ||
|
|
100
|
+
Object.keys(node.metadata).some(key => key !== 'comment') ||
|
|
101
|
+
(node.metadata.comment !== undefined && typeof node.metadata.comment !== 'string'))) {
|
|
102
|
+
errors.push(`Graph ${name}.metadata: Only an optional string comment is allowed`);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if ('cel' in node || 'dependsOn' in node) {
|
|
106
|
+
errors.push(`Graph ${name}: Aggregate nodes cannot declare CEL or explicit dependencies`);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const window = byName.get(node.window);
|
|
110
|
+
if (!window) {
|
|
111
|
+
errors.push(`Graph ${name}.window: Unknown rolling-window node ${JSON.stringify(node.window)}`);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (window.type !== 'cel' || window.valueType.kind !== 'rolling-window') {
|
|
115
|
+
errors.push(`Graph ${name}.window: ${JSON.stringify(node.window)} is not a rolling-window node`);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const element = window.valueType.element;
|
|
119
|
+
if (node.operation !== 'count' && element.javascriptType !== 'number' && element.javascriptType !== 'bigint') {
|
|
120
|
+
errors.push(`Graph ${name}.window: ${JSON.stringify(node.window)} must contain numeric values`);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const output = node.operation === 'count'
|
|
124
|
+
? { kind: 'scalar', semanticType: 'integer', javascriptType: 'number' }
|
|
125
|
+
: element;
|
|
126
|
+
nodes[index] = {
|
|
127
|
+
type: 'aggregate', window: node.window, operation: node.operation,
|
|
128
|
+
metadata: { name, type: 'number', javascriptType: output.javascriptType,
|
|
129
|
+
...(node.metadata?.comment === undefined ? {} : { comment: node.metadata.comment }) },
|
|
130
|
+
valueType: output,
|
|
131
|
+
dependsOn: [extractedPath(`now.${node.window}`)]
|
|
132
|
+
};
|
|
63
133
|
}
|
|
64
134
|
return errors.length > 0 ? { errors } : { value: nodes };
|
|
65
135
|
}
|
|
136
|
+
/** Inspect a validated CEL expression without storing redundant temporal-read metadata. */
|
|
137
|
+
function readsPreviousValue(cel, name) {
|
|
138
|
+
const identifiers = (0, cel_1.extractFreeIdentifiers)(cel);
|
|
139
|
+
return 'value' in identifiers && identifiers.value.some(identifier => name === undefined ? identifier.startsWith('prev.') : identifier === `prev.${name}`);
|
|
140
|
+
}
|
|
141
|
+
/** Read a canonical graph node's type, without inventing a physical representation.
|
|
142
|
+
* CEL vocabulary and legacy number metadata are interpreted at this boundary. */
|
|
143
|
+
function canonicalNodeValueType(metadata) {
|
|
144
|
+
const semanticType = metadata.type === 'boolean' ? 'boolean' :
|
|
145
|
+
metadata.type === 'string' ? 'string' :
|
|
146
|
+
metadata.celResultType === 'double' ? 'float' :
|
|
147
|
+
metadata.celResultType === 'uint' ? 'unsignedInteger' : 'integer';
|
|
148
|
+
const candidate = { kind: 'scalar', semanticType, javascriptType: metadata.javascriptType };
|
|
149
|
+
if (!(0, value_types_1.isScalarValueType)(candidate))
|
|
150
|
+
throw new Error(`Graph ${metadata.name}: Invalid canonical scalar type`);
|
|
151
|
+
if (metadata.rollingWindow === undefined)
|
|
152
|
+
return candidate;
|
|
153
|
+
const { periodicity, size } = metadata.rollingWindow;
|
|
154
|
+
if (typeof periodicity !== 'string' || periodicity.length === 0 ||
|
|
155
|
+
!Number.isSafeInteger(size) || size < 1)
|
|
156
|
+
throw new Error(`Graph ${metadata.name}: Invalid rolling-window periodicity or size`);
|
|
157
|
+
return { kind: 'rolling-window', periodicity, size, element: candidate };
|
|
158
|
+
}
|
|
66
159
|
//# sourceMappingURL=dependency.node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency.node.js","sourceRoot":"","sources":["../../src/dependency.node.ts"],"names":[],"mappings":";;
|
|
1
|
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