@cobol-ts/cobolts 0.0.14 → 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.benchmark-formats.md +52 -0
- package/README.benchmark-reporting.md +16 -0
- package/README.benchmark.md +199 -0
- package/README.cel.md +112 -57
- package/README.md +166 -19
- package/README.periodic-verification.md +83 -0
- package/dist/src/benchmark.access.spec.d.ts +1 -0
- package/dist/src/benchmark.access.spec.js +30 -0
- package/dist/src/benchmark.access.spec.js.map +1 -0
- package/dist/src/benchmark.aggregate.fixture.d.ts +10 -0
- package/dist/src/benchmark.aggregate.fixture.js +108 -0
- package/dist/src/benchmark.aggregate.fixture.js.map +1 -0
- package/dist/src/benchmark.aggregate.fixture.spec.d.ts +1 -0
- package/dist/src/benchmark.aggregate.fixture.spec.js +116 -0
- package/dist/src/benchmark.aggregate.fixture.spec.js.map +1 -0
- package/dist/src/benchmark.allocations.cli.spec.d.ts +1 -0
- package/dist/src/benchmark.allocations.cli.spec.js +60 -0
- package/dist/src/benchmark.allocations.cli.spec.js.map +1 -0
- package/dist/src/benchmark.allocations.d.ts +19 -0
- package/dist/src/benchmark.allocations.js +82 -0
- package/dist/src/benchmark.allocations.js.map +1 -0
- package/dist/src/benchmark.allocations.spec.d.ts +1 -0
- package/dist/src/benchmark.allocations.spec.js +64 -0
- package/dist/src/benchmark.allocations.spec.js.map +1 -0
- package/dist/src/benchmark.cli.functional.spec.d.ts +1 -0
- package/dist/src/benchmark.cli.functional.spec.js +370 -0
- package/dist/src/benchmark.cli.functional.spec.js.map +1 -0
- package/dist/src/benchmark.cli.golden.spec.d.ts +1 -0
- package/dist/src/benchmark.cli.golden.spec.js +194 -0
- package/dist/src/benchmark.cli.golden.spec.js.map +1 -0
- package/dist/src/benchmark.composed.execution.spec.d.ts +1 -0
- package/dist/src/benchmark.composed.execution.spec.js +120 -0
- package/dist/src/benchmark.composed.execution.spec.js.map +1 -0
- package/dist/src/benchmark.composed.fixture.d.ts +4 -0
- package/dist/src/benchmark.composed.fixture.js +77 -0
- package/dist/src/benchmark.composed.fixture.js.map +1 -0
- package/dist/src/benchmark.composed.fixture.spec.d.ts +1 -0
- package/dist/src/benchmark.composed.fixture.spec.js +50 -0
- package/dist/src/benchmark.composed.fixture.spec.js.map +1 -0
- package/dist/src/benchmark.composed.runner.d.ts +13 -0
- package/dist/src/benchmark.composed.runner.js +221 -0
- package/dist/src/benchmark.composed.runner.js.map +1 -0
- package/dist/src/benchmark.composed.two.fixture.d.ts +5 -0
- package/dist/src/benchmark.composed.two.fixture.js +111 -0
- package/dist/src/benchmark.composed.two.fixture.js.map +1 -0
- package/dist/src/benchmark.composed.two.spec.d.ts +1 -0
- package/dist/src/benchmark.composed.two.spec.js +86 -0
- package/dist/src/benchmark.composed.two.spec.js.map +1 -0
- package/dist/src/benchmark.format.cli.functional.spec.d.ts +1 -0
- package/dist/src/benchmark.format.cli.functional.spec.js +44 -0
- package/dist/src/benchmark.format.cli.functional.spec.js.map +1 -0
- package/dist/src/benchmark.format.composition.spec.d.ts +1 -0
- package/dist/src/benchmark.format.composition.spec.js +196 -0
- package/dist/src/benchmark.format.composition.spec.js.map +1 -0
- package/dist/src/benchmark.format.family.cli.functional.spec.d.ts +1 -0
- package/dist/src/benchmark.format.family.cli.functional.spec.js +102 -0
- package/dist/src/benchmark.format.family.cli.functional.spec.js.map +1 -0
- package/dist/src/benchmark.format.fixture.d.ts +26 -0
- package/dist/src/benchmark.format.fixture.js +181 -0
- package/dist/src/benchmark.format.fixture.js.map +1 -0
- package/dist/src/benchmark.format.oracle.d.ts +8 -0
- package/dist/src/benchmark.format.oracle.js +30 -0
- package/dist/src/benchmark.format.oracle.js.map +1 -0
- package/dist/src/benchmark.format.runner.d.ts +6 -0
- package/dist/src/benchmark.format.runner.js +271 -0
- package/dist/src/benchmark.format.runner.js.map +1 -0
- package/dist/src/benchmark.format.source.d.ts +6 -0
- package/dist/src/benchmark.format.source.js +15 -0
- package/dist/src/benchmark.format.source.js.map +1 -0
- package/dist/src/benchmark.format.spec.d.ts +1 -0
- package/dist/src/benchmark.format.spec.js +85 -0
- package/dist/src/benchmark.format.spec.js.map +1 -0
- package/dist/src/benchmark.format.stateful.spec.d.ts +1 -0
- package/dist/src/benchmark.format.stateful.spec.js +120 -0
- package/dist/src/benchmark.format.stateful.spec.js.map +1 -0
- package/dist/src/benchmark.gc.d.ts +26 -0
- package/dist/src/benchmark.gc.js +62 -0
- package/dist/src/benchmark.gc.js.map +1 -0
- package/dist/src/benchmark.gc.spec.d.ts +1 -0
- package/dist/src/benchmark.gc.spec.js +26 -0
- package/dist/src/benchmark.gc.spec.js.map +1 -0
- package/dist/src/benchmark.periodic.execution.spec.d.ts +1 -0
- package/dist/src/benchmark.periodic.execution.spec.js +166 -0
- package/dist/src/benchmark.periodic.execution.spec.js.map +1 -0
- package/dist/src/benchmark.periodic.fixture.d.ts +5 -0
- package/dist/src/benchmark.periodic.fixture.js +69 -0
- package/dist/src/benchmark.periodic.fixture.js.map +1 -0
- package/dist/src/benchmark.periodic.fixture.spec.d.ts +1 -0
- package/dist/src/benchmark.periodic.fixture.spec.js +96 -0
- package/dist/src/benchmark.periodic.fixture.spec.js.map +1 -0
- package/dist/src/benchmark.profile.d.ts +8 -0
- package/dist/src/benchmark.profile.js +62 -0
- package/dist/src/benchmark.profile.js.map +1 -0
- package/dist/src/benchmark.profile.spec.d.ts +1 -0
- package/dist/src/benchmark.profile.spec.js +65 -0
- package/dist/src/benchmark.profile.spec.js.map +1 -0
- package/dist/src/benchmark.report.d.ts +113 -0
- package/dist/src/benchmark.report.js +279 -0
- package/dist/src/benchmark.report.js.map +1 -0
- package/dist/src/benchmark.report.spec.d.ts +1 -0
- package/dist/src/benchmark.report.spec.js +271 -0
- package/dist/src/benchmark.report.spec.js.map +1 -0
- package/dist/src/benchmark.runner.d.ts +74 -0
- package/dist/src/benchmark.runner.js +371 -0
- package/dist/src/benchmark.runner.js.map +1 -0
- package/dist/src/benchmark.runner.spec.d.ts +1 -0
- package/dist/src/benchmark.runner.spec.js +241 -0
- package/dist/src/benchmark.runner.spec.js.map +1 -0
- package/dist/src/benchmark.strategy.spec.d.ts +1 -0
- package/dist/src/benchmark.strategy.spec.js +66 -0
- package/dist/src/benchmark.strategy.spec.js.map +1 -0
- package/dist/src/cel.composition.integration.spec.d.ts +1 -0
- package/dist/src/cel.composition.integration.spec.js +110 -0
- package/dist/src/cel.composition.integration.spec.js.map +1 -0
- package/dist/src/cel.entity.d.ts +12 -0
- package/dist/src/cel.entity.js +98 -0
- package/dist/src/cel.entity.js.map +1 -0
- package/dist/src/cel.entity.spec.d.ts +1 -0
- package/dist/src/cel.entity.spec.js +82 -0
- package/dist/src/cel.entity.spec.js.map +1 -0
- package/dist/src/cel.evaluate.cli.spec.d.ts +1 -0
- package/dist/src/cel.evaluate.cli.spec.js +63 -0
- package/dist/src/cel.evaluate.cli.spec.js.map +1 -0
- package/dist/src/cel.evaluate.integration.spec.d.ts +1 -0
- package/dist/src/cel.evaluate.integration.spec.js +128 -0
- package/dist/src/cel.evaluate.integration.spec.js.map +1 -0
- package/dist/src/cel.integration.spec.js +227 -38
- package/dist/src/cel.integration.spec.js.map +1 -1
- package/dist/src/cel.result.ownership.spec.d.ts +1 -0
- package/dist/src/cel.result.ownership.spec.js +52 -0
- package/dist/src/cel.result.ownership.spec.js.map +1 -0
- package/dist/src/cel.shared.execution.d.ts +20 -0
- package/dist/src/cel.shared.execution.js +49 -0
- package/dist/src/cel.shared.execution.js.map +1 -0
- package/dist/src/cel.stats.d.ts +5 -0
- package/dist/src/cel.stats.js +73 -0
- package/dist/src/cel.stats.js.map +1 -0
- package/dist/src/cel.stats.spec.d.ts +1 -0
- package/dist/src/cel.stats.spec.js +85 -0
- package/dist/src/cel.stats.spec.js.map +1 -0
- package/dist/src/cli.integration.spec.js +14 -2
- package/dist/src/cli.integration.spec.js.map +1 -1
- package/dist/src/cli.js +8 -0
- package/dist/src/cli.js.map +1 -1
- package/dist/src/cli.spec.js +46 -6
- package/dist/src/cli.spec.js.map +1 -1
- package/dist/src/commands/benchmark.d.ts +3 -0
- package/dist/src/commands/benchmark.js +300 -0
- package/dist/src/commands/benchmark.js.map +1 -0
- package/dist/src/commands/cel.d.ts +1 -1
- package/dist/src/commands/cel.js +38 -5
- package/dist/src/commands/cel.js.map +1 -1
- package/dist/src/commands/characteristics.d.ts +3 -0
- package/dist/src/commands/characteristics.js +57 -0
- package/dist/src/commands/characteristics.js.map +1 -0
- package/dist/src/commands/characteristics.spec.d.ts +1 -0
- package/dist/src/commands/characteristics.spec.js +109 -0
- package/dist/src/commands/characteristics.spec.js.map +1 -0
- package/dist/src/commands/config.validate.js +8 -4
- package/dist/src/commands/config.validate.js.map +1 -1
- package/dist/src/commands/extract.d.ts +14 -0
- package/dist/src/commands/extract.js +85 -0
- package/dist/src/commands/extract.js.map +1 -0
- package/dist/src/commands/extract.spec.d.ts +1 -0
- package/dist/src/commands/extract.spec.js +179 -0
- package/dist/src/commands/extract.spec.js.map +1 -0
- package/dist/src/commands/periodicity.d.ts +3 -0
- package/dist/src/commands/periodicity.js +11 -0
- package/dist/src/commands/periodicity.js.map +1 -0
- package/dist/src/commands/validate.all.d.ts +7 -0
- package/dist/src/commands/validate.all.integration.spec.d.ts +1 -0
- package/dist/src/commands/validate.all.integration.spec.js +43 -0
- package/dist/src/commands/validate.all.integration.spec.js.map +1 -0
- package/dist/src/commands/validate.all.js +75 -0
- package/dist/src/commands/validate.all.js.map +1 -0
- package/dist/src/commands/validate.all.spec.d.ts +1 -0
- package/dist/src/commands/validate.all.spec.js +70 -0
- package/dist/src/commands/validate.all.spec.js.map +1 -0
- package/dist/src/context.d.ts +37 -6
- package/dist/src/context.js +574 -21
- package/dist/src/context.js.map +1 -1
- package/dist/src/indexed.accumulator.d.ts +18 -0
- package/dist/src/indexed.accumulator.js +102 -0
- package/dist/src/indexed.accumulator.js.map +1 -0
- package/dist/src/indexed.accumulator.spec.d.ts +1 -0
- package/dist/src/indexed.accumulator.spec.js +74 -0
- package/dist/src/indexed.accumulator.spec.js.map +1 -0
- package/package.json +24 -11
package/dist/src/context.js
CHANGED
|
@@ -3,18 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.nodeCliServices = void 0;
|
|
4
4
|
exports.discoverPaths = discoverPaths;
|
|
5
5
|
exports.namingFor = namingFor;
|
|
6
|
+
exports.prepareIndexedComposedExecutor = prepareIndexedComposedExecutor;
|
|
7
|
+
const promises_1 = require("node:fs/promises");
|
|
8
|
+
const spreadsheet_1 = require("@cobol-ts/spreadsheet");
|
|
9
|
+
const spreadsheet_excel_1 = require("@cobol-ts/spreadsheet-excel");
|
|
6
10
|
const node_path_1 = require("node:path");
|
|
11
|
+
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
7
12
|
const files_1 = require("@cobol-ts/files");
|
|
8
13
|
const file_catalogue_1 = require("@cobol-ts/file-catalogue");
|
|
9
14
|
const codegen_1 = require("@cobol-ts/codegen");
|
|
10
15
|
const file_display_1 = require("@cobol-ts/file-display");
|
|
11
|
-
const file_display_2 = require("@cobol-ts/file-display");
|
|
12
16
|
const cursor_loader_cobol_1 = require("@cobol-ts/cursor-loader-cobol");
|
|
13
17
|
const cel_access_1 = require("@cobol-ts/cel-access");
|
|
14
18
|
const cel_graph_runtime_1 = require("@cobol-ts/cel-graph-runtime");
|
|
19
|
+
const planned_graph_1 = require("@cobol-ts/planned_graph");
|
|
15
20
|
const cel_json_1 = require("./cel.json");
|
|
21
|
+
const cel_stats_1 = require("./cel.stats");
|
|
22
|
+
const cel_entity_1 = require("./cel.entity");
|
|
16
23
|
const errors_1 = require("@cobol-ts/errors");
|
|
17
24
|
const yaml_jsyaml_1 = require("@cobol-ts/yaml-jsyaml");
|
|
25
|
+
const cursor_loader_source_1 = require("@cobol-ts/cursor-loader-source");
|
|
26
|
+
const cursor_loader_indexed_graph_state_1 = require("@cobol-ts/cursor-loader-indexed-graph-state");
|
|
27
|
+
const composition_definition_1 = require("@cobol-ts/composition-definition");
|
|
28
|
+
const indexed_accumulator_1 = require("./indexed.accumulator");
|
|
18
29
|
async function discoverPaths(options) {
|
|
19
30
|
const startDirectory = options.directory ?? options.root ?? process.cwd();
|
|
20
31
|
const directory = await (0, files_1.findDirectoryUp)('.cobolts', (0, node_path_1.resolve)(startDirectory));
|
|
@@ -68,18 +79,176 @@ async function loadInitialAccumulator(paths) {
|
|
|
68
79
|
catch (error) {
|
|
69
80
|
return { errors: [`Reading accumulator ${paths.accumulator}: ${error instanceof Error ? error.message : String(error)}`] };
|
|
70
81
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
try {
|
|
83
|
+
return { value: (0, indexed_accumulator_1.parseAccumulatorDocument)(source).initial };
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return { errors: [paths.accumulator + ': ' + (error instanceof Error ? error.message : String(error))] };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function compileIndexedComposedExecutor(paths, authored, initial, stateConfiguration, prepared) {
|
|
90
|
+
const graph = (0, cel_graph_runtime_1.prepareIndexedCelGraph)(authored, prepared.composed.projection, prepared.access);
|
|
91
|
+
if ('errors' in graph)
|
|
92
|
+
return graph;
|
|
93
|
+
const schema = graph.value.schema;
|
|
94
|
+
const initialValues = (0, indexed_accumulator_1.indexedSeedValues)(initial);
|
|
95
|
+
const stateFile = stateConfiguration.file ? (0, node_path_1.resolve)(paths.directory, stateConfiguration.file) : undefined;
|
|
96
|
+
// Accumulator preparation has the same lifetime as the compiled executor.
|
|
97
|
+
// Each run still opens fresh composition and historical-state cursors.
|
|
98
|
+
const scanAccumulator = (0, cursor_loader_indexed_graph_state_1.prepareIndexedAccumulator)({
|
|
99
|
+
schema, optional: stateConfiguration.optional,
|
|
100
|
+
removed: stateConfiguration.removed, customerIdType: stateConfiguration.customerIdType,
|
|
101
|
+
initial: initialValues,
|
|
102
|
+
...(stateFile ? { filename: stateFile } : {})
|
|
103
|
+
});
|
|
104
|
+
// The session is stateful and execution must be sequential, not concurrent.
|
|
105
|
+
const normalSession = graph.value.createIndexedSession();
|
|
106
|
+
const indices = [];
|
|
107
|
+
return { value: async (options, emit, diagnostic = message => console.error(message)) => {
|
|
108
|
+
const measurement = options.measurement;
|
|
109
|
+
const target = options.entityId;
|
|
110
|
+
const debugging = !!options.debug || options.debugNode !== undefined;
|
|
111
|
+
const count = options.all ? undefined : (options.count ?? 10);
|
|
112
|
+
const skip = options.skip ?? 0;
|
|
113
|
+
const graphTiming = measurement?.timingSampleEvery === undefined ? undefined :
|
|
114
|
+
(0, cel_graph_runtime_1.createCelGraphTimings)(graph.value.generations, measurement.timingSampleEvery);
|
|
115
|
+
if (measurement)
|
|
116
|
+
measurement.graphTiming = graphTiming;
|
|
117
|
+
const session = graphTiming || debugging
|
|
118
|
+
? graph.value.createIndexedSession(graphTiming, debugging ? (0, cel_entity_1.debugGenerations)(graph.value.generations, schema, diagnostic, options.debugNode) : undefined)
|
|
119
|
+
: normalSession;
|
|
120
|
+
const trace = (label, value) => {
|
|
121
|
+
if (!debugging)
|
|
122
|
+
return;
|
|
123
|
+
if (options.debugNode !== undefined && (label === 'PREVIOUS' || label === 'RESULT')) {
|
|
124
|
+
const state = value;
|
|
125
|
+
diagnostic(label + ' ' + (0, cel_json_1.stringifyCelJson)({ [options.debugNode]: state[options.debugNode] }));
|
|
126
|
+
}
|
|
127
|
+
else
|
|
128
|
+
diagnostic(label + ' ' + (0, cel_json_1.stringifyCelJson)(value));
|
|
129
|
+
};
|
|
130
|
+
const variables = options.periodicity === undefined ? {} : { periodicity: options.periodicity };
|
|
131
|
+
let visited = 0, emitted = 0;
|
|
132
|
+
if (!options.raw && target === undefined)
|
|
133
|
+
emit('# ' + paths.catalogue);
|
|
134
|
+
try {
|
|
135
|
+
if (target !== undefined && !stateFile) {
|
|
136
|
+
await prepared.composed.scan(row => {
|
|
137
|
+
if ((0, cel_entity_1.selectEntity)(row.key, target) === 'skip')
|
|
138
|
+
return true;
|
|
139
|
+
const state = (0, cel_entity_1.indexedStateFromInitial)(schema, initial);
|
|
140
|
+
state.entityKey = String(row.key);
|
|
141
|
+
if (debugging) {
|
|
142
|
+
trace('INPUT', (0, cel_entity_1.debugProjectedInput)(prepared.composed.projection, prepared.access, row));
|
|
143
|
+
trace('PREVIOUS', (0, cel_entity_1.indexedStateObject)(schema, state));
|
|
144
|
+
}
|
|
145
|
+
const startedCel = measurement ? node_perf_hooks_1.performance.now() : 0;
|
|
146
|
+
session.run(row, state, variables, indices);
|
|
147
|
+
if (measurement) {
|
|
148
|
+
measurement.celMs += node_perf_hooks_1.performance.now() - startedCel;
|
|
149
|
+
measurement.records++;
|
|
150
|
+
}
|
|
151
|
+
const result = (0, cel_entity_1.indexedStateObject)(schema, state);
|
|
152
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
153
|
+
trace('RESULT', result);
|
|
154
|
+
emitted++;
|
|
155
|
+
return false;
|
|
156
|
+
});
|
|
157
|
+
return emitted === 0 ? { errors: [`Entity ${target} not found`] } : { value: undefined };
|
|
158
|
+
}
|
|
159
|
+
const normalizeKey = (0, indexed_accumulator_1.indexedKeyNormalizer)(stateConfiguration.customerIdType, stateConfiguration.customerId);
|
|
160
|
+
await scanAccumulator(prepared.composed, row => normalizeKey(row.key), (row, state) => {
|
|
161
|
+
visited++;
|
|
162
|
+
if (target !== undefined) {
|
|
163
|
+
if ((0, cel_entity_1.selectEntity)(row.key, target) === 'skip')
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
else if (visited <= skip)
|
|
167
|
+
return true;
|
|
168
|
+
if (debugging) {
|
|
169
|
+
trace('INPUT', (0, cel_entity_1.debugProjectedInput)(prepared.composed.projection, prepared.access, row));
|
|
170
|
+
trace('PREVIOUS', (0, cel_entity_1.indexedStateObject)(schema, state));
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const startedCel = measurement ? node_perf_hooks_1.performance.now() : 0;
|
|
174
|
+
session.run(row, state, variables, indices);
|
|
175
|
+
if (measurement) {
|
|
176
|
+
measurement.celMs += node_perf_hooks_1.performance.now() - startedCel;
|
|
177
|
+
measurement.records++;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
throw new Error('Record ' + visited + ': ' + (error instanceof Error ? error.message : String(error)), { cause: error });
|
|
182
|
+
}
|
|
183
|
+
options.observeIndexed?.(row.key, state.values, schema);
|
|
184
|
+
if (!options.suppressOutput || debugging) {
|
|
185
|
+
const result = (0, cel_entity_1.indexedStateObject)(schema, state);
|
|
186
|
+
if (!options.suppressOutput)
|
|
187
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
188
|
+
trace('RESULT', result);
|
|
189
|
+
}
|
|
190
|
+
emitted++;
|
|
191
|
+
return target === undefined && (count === undefined || emitted < count);
|
|
192
|
+
});
|
|
193
|
+
if (target !== undefined && emitted === 0)
|
|
194
|
+
return { errors: [`Entity ${target} not found`] };
|
|
195
|
+
return { value: undefined };
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
return { errors: ['Composed CEL: ' + (error instanceof Error ? error.message : String(error))] };
|
|
199
|
+
}
|
|
200
|
+
} };
|
|
201
|
+
}
|
|
202
|
+
/** Compile once; execute repeatedly. This is a factory, not a cache. */
|
|
203
|
+
async function prepareIndexedComposedExecutor(paths, graphName) {
|
|
204
|
+
const authored = await loadCelAuthoringGraph(paths, graphName);
|
|
205
|
+
if ('errors' in authored)
|
|
206
|
+
return authored;
|
|
207
|
+
const canonical = (0, cel_graph_runtime_1.canonicaliseCelGraph)(authored.value);
|
|
208
|
+
if ('errors' in canonical)
|
|
209
|
+
return canonical;
|
|
210
|
+
const sorted = (0, cel_graph_runtime_1.planCanonicalCelGraph)(canonical.value);
|
|
211
|
+
if ('errors' in sorted)
|
|
212
|
+
return sorted;
|
|
213
|
+
const initial = await loadInitialAccumulator(paths);
|
|
214
|
+
if ('errors' in initial)
|
|
215
|
+
return initial;
|
|
216
|
+
const checked = (0, cel_graph_runtime_1.validateInitialAccumulator)(initial.value, authored.value, canonical.value);
|
|
217
|
+
if ('errors' in checked)
|
|
218
|
+
return checked;
|
|
219
|
+
let stateConfiguration;
|
|
220
|
+
try {
|
|
221
|
+
stateConfiguration = (await (0, indexed_accumulator_1.readAccumulatorDocument)(paths.accumulator)).state;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
return { errors: [`Accumulator configuration: ${error instanceof Error ? error.message : String(error)}`] };
|
|
225
|
+
}
|
|
226
|
+
if (!await (0, composition_definition_1.hasCompositionDefinition)(paths.directory))
|
|
227
|
+
return { errors: ['Prepared indexed CEL execution requires a composition definition'] };
|
|
228
|
+
try {
|
|
229
|
+
const definition = (0, errors_1.valueOrThrow)(await (0, composition_definition_1.readCompositionDefinition)(paths.directory));
|
|
230
|
+
const prepared = await (0, composition_definition_1.prepareCompositionDefinition)(definition, logicalName => (0, cursor_loader_source_1.prepareConfiguredFileSource)({ configDirectory: paths.directory, logicalName }));
|
|
231
|
+
return compileIndexedComposedExecutor(paths, authored.value, checked.value, { ...stateConfiguration, strategy: 'indexed' }, prepared);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
return { errors: ['Composed CEL: ' + (error instanceof Error ? error.message : String(error))] };
|
|
235
|
+
}
|
|
75
236
|
}
|
|
76
237
|
exports.nodeCliServices = {
|
|
77
238
|
output: message => console.log(message),
|
|
239
|
+
diagnostic: message => console.error(message),
|
|
240
|
+
async write(filename, content) {
|
|
241
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(filename), { recursive: true });
|
|
242
|
+
await (0, promises_1.writeFile)(filename, content, 'utf8');
|
|
243
|
+
},
|
|
244
|
+
extractSpreadsheet: config => (0, spreadsheet_1.extractSpreadsheet)(spreadsheet_excel_1.excelSpreadsheetReader, config),
|
|
78
245
|
read: filename => files_1.nodeTextFiles.read(filename),
|
|
79
246
|
paths: discoverPaths,
|
|
80
247
|
async list(paths) {
|
|
81
248
|
const catalogue = (0, errors_1.valueOrThrow)(await (0, file_catalogue_1.readFileCatalogue)(files_1.nodeTextFiles, paths.catalogue, yaml_jsyaml_1.jsYamlParser));
|
|
82
|
-
const result = [paths.catalogue
|
|
249
|
+
const result = [paths.catalogue];
|
|
250
|
+
if (await files_1.nodeTextFiles.exists(paths.policy))
|
|
251
|
+
result.push(paths.policy);
|
|
83
252
|
if (await files_1.nodeTextFiles.exists(paths.data))
|
|
84
253
|
result.push(paths.data);
|
|
85
254
|
if (await files_1.nodeTextFiles.exists(paths.accumulator))
|
|
@@ -124,18 +293,67 @@ exports.nodeCliServices = {
|
|
|
124
293
|
const loaded = await loadCelAuthoringGraph(paths, options.graph);
|
|
125
294
|
if ('errors' in loaded)
|
|
126
295
|
return loaded;
|
|
127
|
-
if (options.stage === 'graph')
|
|
296
|
+
if (options.stage === 'graph' && !options.short)
|
|
128
297
|
return { value: JSON.stringify(loaded.value, null, 2) };
|
|
129
298
|
const canonical = (0, cel_graph_runtime_1.canonicaliseCelGraph)(loaded.value);
|
|
130
299
|
if ('errors' in canonical)
|
|
131
300
|
return canonical;
|
|
301
|
+
const shortNodes = () => canonical.value.map(node => `${node.metadata.name} <- ${node.dependsOn.map(path => path.join('.')).join(', ') || '-'}`).join('\n');
|
|
302
|
+
if (options.stage === 'graph' && options.short)
|
|
303
|
+
return { value: shortNodes() };
|
|
304
|
+
if (options.stage === 'stats') {
|
|
305
|
+
const metrics = { binaryResolutions: 0, dynamicBinaryResolutions: 0, dynamicConditionalResolutions: 0 };
|
|
306
|
+
const compile = (projection, access) => (0, cel_graph_runtime_1.prepareCelGraph)(loaded.value, projection, access, {}, {}, metrics);
|
|
307
|
+
if (options.logicalName !== undefined) {
|
|
308
|
+
const source = await (0, file_display_1.openConfiguredCobolFile)({
|
|
309
|
+
configDirectory: paths.directory, logicalName: options.logicalName,
|
|
310
|
+
catalogue: paths.catalogue, data: paths.data
|
|
311
|
+
}, files_1.nodeTextFiles, yaml_jsyaml_1.jsYamlParser);
|
|
312
|
+
if ('errors' in source)
|
|
313
|
+
return source;
|
|
314
|
+
const details = await (0, cursor_loader_cobol_1.prepareCobolFileDetails)({
|
|
315
|
+
copybook: source.value.copybook,
|
|
316
|
+
...(source.value.framing ? { framing: source.value.framing } : {})
|
|
317
|
+
});
|
|
318
|
+
const compiled = compile(source.value.projection, (0, cel_access_1.cobolAccessCompiler)(details, source.value.projection));
|
|
319
|
+
if ('errors' in compiled)
|
|
320
|
+
return compiled;
|
|
321
|
+
}
|
|
322
|
+
else if (await (0, composition_definition_1.hasCompositionDefinition)(paths.directory)) {
|
|
323
|
+
const definition = (0, errors_1.valueOrThrow)(await (0, composition_definition_1.readCompositionDefinition)(paths.directory));
|
|
324
|
+
const composed = await (0, composition_definition_1.prepareCompositionDefinition)(definition, logicalName => (0, cursor_loader_source_1.prepareConfiguredFileSource)({ configDirectory: paths.directory, logicalName }));
|
|
325
|
+
const compiled = compile(composed.composed.projection, composed.access);
|
|
326
|
+
if ('errors' in compiled)
|
|
327
|
+
return compiled;
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
const empty = {};
|
|
331
|
+
const compiled = compile(empty, (0, cel_access_1.jsonAccessCompiler)(empty));
|
|
332
|
+
if ('errors' in compiled)
|
|
333
|
+
return compiled;
|
|
334
|
+
}
|
|
335
|
+
return (0, cel_stats_1.celGraphStats)(canonical.value, metrics);
|
|
336
|
+
}
|
|
132
337
|
if (options.stage === 'canonical')
|
|
133
|
-
return { value:
|
|
338
|
+
return { value: options.short
|
|
339
|
+
? shortNodes()
|
|
340
|
+
: JSON.stringify(canonical.value, (_name, value) => typeof value === 'bigint' ? value.toString() : value, 2) };
|
|
134
341
|
const sorted = (0, cel_graph_runtime_1.planCanonicalCelGraph)(canonical.value);
|
|
135
342
|
if ('errors' in sorted)
|
|
136
343
|
return sorted;
|
|
137
344
|
if (options.stage === 'sorted') {
|
|
138
|
-
return { value:
|
|
345
|
+
return { value: options.short
|
|
346
|
+
? sorted.value.generations.map((nodes, index) => `G${index}: ${nodes.map(node => `${node.metadata.name}(${node.dependsOn.map(path => path.join('.')).join(', ') || '-'})`).join(' ')}`).join('\n')
|
|
347
|
+
: JSON.stringify({ generations: sorted.value.generations }, (_name, value) => typeof value === 'bigint' ? value.toString() : value, 2) };
|
|
348
|
+
}
|
|
349
|
+
if (options.stage === 'planned') {
|
|
350
|
+
let index = 0;
|
|
351
|
+
const planned = (0, planned_graph_1.makePlannedGraph)(sorted.value.generations, sorted.value.graph, (node, downstream) => ({ index: index++, node, downstream }));
|
|
352
|
+
if ('errors' in planned)
|
|
353
|
+
return planned;
|
|
354
|
+
return { value: options.short
|
|
355
|
+
? planned.value.map((generation, i) => `G${i}: ${generation.map(n => `${n.index}:${n.node.metadata.name}->[${n.downstream.join(',')}]`).join(' ')}`).join('\n')
|
|
356
|
+
: JSON.stringify({ generations: planned.value }, (_name, value) => typeof value === 'bigint' ? value.toString() : value, 2) };
|
|
139
357
|
}
|
|
140
358
|
if (options.stage !== 'validate')
|
|
141
359
|
return { errors: [`Unexpected CEL operation: ${options.stage}`] };
|
|
@@ -145,10 +363,25 @@ exports.nodeCliServices = {
|
|
|
145
363
|
const checked = (0, cel_graph_runtime_1.validateInitialAccumulator)(initial.value, loaded.value, canonical.value);
|
|
146
364
|
if ('errors' in checked)
|
|
147
365
|
return checked;
|
|
366
|
+
if (await (0, composition_definition_1.hasCompositionDefinition)(paths.directory)) {
|
|
367
|
+
try {
|
|
368
|
+
const definition = (0, errors_1.valueOrThrow)(await (0, composition_definition_1.readCompositionDefinition)(paths.directory));
|
|
369
|
+
const composed = await (0, composition_definition_1.prepareCompositionDefinition)(definition, logicalName => (0, cursor_loader_source_1.prepareConfiguredFileSource)({ configDirectory: paths.directory, logicalName }));
|
|
370
|
+
const graph = (0, cel_graph_runtime_1.prepareIndexedCelGraph)(loaded.value, composed.composed.projection, composed.access);
|
|
371
|
+
if ('errors' in graph)
|
|
372
|
+
return graph;
|
|
373
|
+
return { value: 'Valid composed graph: ' + graph.value.schema.nodes.length +
|
|
374
|
+
' nodes, ' + composed.sources.length + ' sources' };
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
return { errors: ['Composed CEL validation: ' +
|
|
378
|
+
(error instanceof Error ? error.message : String(error))] };
|
|
379
|
+
}
|
|
380
|
+
}
|
|
148
381
|
if (options.logicalName === undefined) {
|
|
149
382
|
return { value: `Valid graph: ${canonical.value.length} nodes, ${sorted.value.generations.length} generations (structural)` };
|
|
150
383
|
}
|
|
151
|
-
const source = await (0,
|
|
384
|
+
const source = await (0, file_display_1.openConfiguredCobolFile)({
|
|
152
385
|
configDirectory: paths.directory, logicalName: options.logicalName,
|
|
153
386
|
catalogue: paths.catalogue, data: paths.data
|
|
154
387
|
}, files_1.nodeTextFiles, yaml_jsyaml_1.jsYamlParser);
|
|
@@ -168,7 +401,27 @@ exports.nodeCliServices = {
|
|
|
168
401
|
return { errors: [`CEL validation ${options.logicalName}: ${error instanceof Error ? error.message : String(error)}`] };
|
|
169
402
|
}
|
|
170
403
|
},
|
|
171
|
-
async celExecute(paths, options, emit) {
|
|
404
|
+
async celExecute(paths, options, emit, diagnostic = message => console.error(message)) {
|
|
405
|
+
const variables = options.periodicity === undefined ? {} : { periodicity: options.periodicity };
|
|
406
|
+
let requestedEntity;
|
|
407
|
+
if (options.entityId !== undefined) {
|
|
408
|
+
requestedEntity = options.entityId;
|
|
409
|
+
if (options.skip !== undefined || options.count !== undefined || options.all || options.onError !== undefined)
|
|
410
|
+
return { errors: ['CEL evaluate cannot combine an entity ID with count, skip, all or on-error'] };
|
|
411
|
+
}
|
|
412
|
+
const measurement = options.measurement;
|
|
413
|
+
const target = requestedEntity;
|
|
414
|
+
const debugging = options.debug || options.debugNode !== undefined;
|
|
415
|
+
const trace = (label, value) => {
|
|
416
|
+
if (!debugging)
|
|
417
|
+
return;
|
|
418
|
+
if (options.debugNode !== undefined && (label === 'PREVIOUS' || label === 'RESULT')) {
|
|
419
|
+
const state = value;
|
|
420
|
+
diagnostic(label + ' ' + (0, cel_json_1.stringifyCelJson)({ [options.debugNode]: state[options.debugNode] }));
|
|
421
|
+
}
|
|
422
|
+
else
|
|
423
|
+
diagnostic(label + ' ' + (0, cel_json_1.stringifyCelJson)(value));
|
|
424
|
+
};
|
|
172
425
|
const count = options.all ? undefined : (options.count ?? 10);
|
|
173
426
|
const skip = options.skip ?? 0;
|
|
174
427
|
if (options.all && options.count !== undefined)
|
|
@@ -182,6 +435,8 @@ exports.nodeCliServices = {
|
|
|
182
435
|
const authored = await loadCelAuthoringGraph(paths, options.graph);
|
|
183
436
|
if ('errors' in authored)
|
|
184
437
|
return authored;
|
|
438
|
+
if (options.debugNode !== undefined && !Object.prototype.hasOwnProperty.call(authored.value, options.debugNode))
|
|
439
|
+
return { errors: [`Unknown debug node ${options.debugNode}`] };
|
|
185
440
|
const canonical = (0, cel_graph_runtime_1.canonicaliseCelGraph)(authored.value);
|
|
186
441
|
if ('errors' in canonical)
|
|
187
442
|
return canonical;
|
|
@@ -194,7 +449,293 @@ exports.nodeCliServices = {
|
|
|
194
449
|
const checked = (0, cel_graph_runtime_1.validateInitialAccumulator)(initial.value, authored.value, canonical.value);
|
|
195
450
|
if ('errors' in checked)
|
|
196
451
|
return checked;
|
|
197
|
-
|
|
452
|
+
let stateConfiguration;
|
|
453
|
+
try {
|
|
454
|
+
stateConfiguration = (await (0, indexed_accumulator_1.readAccumulatorDocument)(paths.accumulator)).state;
|
|
455
|
+
}
|
|
456
|
+
catch (error) {
|
|
457
|
+
return { errors: [`Accumulator configuration: ${error instanceof Error ? error.message : String(error)}`] };
|
|
458
|
+
}
|
|
459
|
+
if (options.strategyOverride)
|
|
460
|
+
stateConfiguration = { ...stateConfiguration, strategy: options.strategyOverride };
|
|
461
|
+
if (await (0, composition_definition_1.hasCompositionDefinition)(paths.directory)) {
|
|
462
|
+
if (options.input !== undefined)
|
|
463
|
+
return { errors: ['--input is not supported by composed CEL execution; configure physical files in data.yaml'] };
|
|
464
|
+
if (options.onError === 'continue')
|
|
465
|
+
return { errors: ['Composed execution does not support --on-error continue without rollback'] };
|
|
466
|
+
try {
|
|
467
|
+
const definition = (0, errors_1.valueOrThrow)(await (0, composition_definition_1.readCompositionDefinition)(paths.directory));
|
|
468
|
+
// The physical-source adapter supplies its configured COBOL projection.
|
|
469
|
+
// Other formats require an explicit projection from their authoring layer.
|
|
470
|
+
const open = async (logicalName) => (0, cursor_loader_source_1.prepareConfiguredFileSource)({
|
|
471
|
+
configDirectory: paths.directory, logicalName
|
|
472
|
+
});
|
|
473
|
+
const prepared = await (0, composition_definition_1.prepareCompositionDefinition)(definition, open);
|
|
474
|
+
if (stateConfiguration.strategy === 'object') {
|
|
475
|
+
const graph = (0, cel_graph_runtime_1.prepareCelGraph)(authored.value, prepared.composed.projection, prepared.access);
|
|
476
|
+
if ('errors' in graph)
|
|
477
|
+
return graph;
|
|
478
|
+
const observe = debugging ? (generation, state) => {
|
|
479
|
+
const values = {};
|
|
480
|
+
for (const node of graph.value.generations[generation]) {
|
|
481
|
+
if (options.debugNode !== undefined && node.metadata.name !== options.debugNode)
|
|
482
|
+
continue;
|
|
483
|
+
values[node.metadata.name] = state[node.metadata.name];
|
|
484
|
+
}
|
|
485
|
+
if (Object.keys(values).length !== 0) {
|
|
486
|
+
const selected = options.debugNode === undefined ? undefined : graph.value.generations[generation].find(node => node.metadata.name === options.debugNode);
|
|
487
|
+
diagnostic(`GENERATION ${generation} ${selected ? selected.type === 'cel' ?
|
|
488
|
+
`${selected.metadata.name} CEL ${JSON.stringify(selected.cel)} ` :
|
|
489
|
+
`${selected.metadata.name} AGGREGATE ${selected.operation}(${selected.window}) ` : ''}${(0, cel_json_1.stringifyCelJson)(values)}`);
|
|
490
|
+
}
|
|
491
|
+
} : undefined;
|
|
492
|
+
let visited = 0, emitted = 0;
|
|
493
|
+
if (!options.raw && target === undefined)
|
|
494
|
+
emit('# ' + paths.catalogue);
|
|
495
|
+
if (stateConfiguration.file) {
|
|
496
|
+
// Object and indexed execution must read the same historical state.
|
|
497
|
+
const historicalGraph = (0, cel_graph_runtime_1.prepareIndexedCelGraph)(authored.value, prepared.composed.projection, prepared.access);
|
|
498
|
+
if ('errors' in historicalGraph)
|
|
499
|
+
return historicalGraph;
|
|
500
|
+
const normalizeKey = (0, indexed_accumulator_1.indexedKeyNormalizer)(stateConfiguration.customerIdType, stateConfiguration.customerId);
|
|
501
|
+
await (0, cursor_loader_indexed_graph_state_1.scanIndexedAccumulator)(prepared.composed, {
|
|
502
|
+
schema: historicalGraph.value.schema, optional: stateConfiguration.optional,
|
|
503
|
+
removed: stateConfiguration.removed, customerIdType: stateConfiguration.customerIdType, initial: (0, indexed_accumulator_1.indexedSeedValues)(checked.value),
|
|
504
|
+
filename: (0, node_path_1.resolve)(paths.directory, stateConfiguration.file)
|
|
505
|
+
}, row => normalizeKey(row.key), (row, state) => {
|
|
506
|
+
visited++;
|
|
507
|
+
if (target !== undefined && (0, cel_entity_1.selectEntity)(row.key, target) === 'skip')
|
|
508
|
+
return true;
|
|
509
|
+
if (target === undefined && visited <= skip)
|
|
510
|
+
return true;
|
|
511
|
+
const previous = (0, cel_entity_1.indexedStateObject)(historicalGraph.value.schema, state);
|
|
512
|
+
if (debugging) {
|
|
513
|
+
const input = (0, cel_entity_1.debugProjectedInput)(prepared.composed.projection, prepared.access, row);
|
|
514
|
+
trace('INPUT', input);
|
|
515
|
+
trace('PREVIOUS', previous);
|
|
516
|
+
}
|
|
517
|
+
const startedCel = measurement ? node_perf_hooks_1.performance.now() : 0;
|
|
518
|
+
const result = graph.value.run(row, previous, variables, [], observe);
|
|
519
|
+
if (measurement) {
|
|
520
|
+
measurement.celMs += node_perf_hooks_1.performance.now() - startedCel;
|
|
521
|
+
measurement.records++;
|
|
522
|
+
}
|
|
523
|
+
options.observeObject?.(row.key, result);
|
|
524
|
+
if (!options.suppressOutput)
|
|
525
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
526
|
+
trace('RESULT', result);
|
|
527
|
+
emitted++;
|
|
528
|
+
return target === undefined && (count === undefined || emitted < count);
|
|
529
|
+
});
|
|
530
|
+
return target !== undefined && emitted === 0
|
|
531
|
+
? { errors: [`Entity ${target} not found`] } : { value: undefined };
|
|
532
|
+
}
|
|
533
|
+
await prepared.composed.scan(row => {
|
|
534
|
+
visited++;
|
|
535
|
+
if (target !== undefined && (0, cel_entity_1.selectEntity)(row.key, target) === 'skip')
|
|
536
|
+
return true;
|
|
537
|
+
if (target === undefined && visited <= skip)
|
|
538
|
+
return true;
|
|
539
|
+
if (debugging) {
|
|
540
|
+
const input = (0, cel_entity_1.debugProjectedInput)(prepared.composed.projection, prepared.access, row);
|
|
541
|
+
trace('INPUT', input);
|
|
542
|
+
trace('PREVIOUS', checked.value);
|
|
543
|
+
}
|
|
544
|
+
const startedCel = measurement ? node_perf_hooks_1.performance.now() : 0;
|
|
545
|
+
const result = graph.value.run(row, checked.value, variables, [], observe);
|
|
546
|
+
if (measurement) {
|
|
547
|
+
measurement.celMs += node_perf_hooks_1.performance.now() - startedCel;
|
|
548
|
+
measurement.records++;
|
|
549
|
+
}
|
|
550
|
+
options.observeObject?.(row.key, result);
|
|
551
|
+
if (!options.suppressOutput)
|
|
552
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
553
|
+
trace('RESULT', result);
|
|
554
|
+
emitted++;
|
|
555
|
+
return target === undefined && (count === undefined || emitted < count);
|
|
556
|
+
});
|
|
557
|
+
return target !== undefined && emitted === 0
|
|
558
|
+
? { errors: [`Entity ${target} not found`] } : { value: undefined };
|
|
559
|
+
}
|
|
560
|
+
const executor = compileIndexedComposedExecutor(paths, authored.value, checked.value, stateConfiguration, prepared);
|
|
561
|
+
if ('errors' in executor)
|
|
562
|
+
return executor;
|
|
563
|
+
return await executor.value(options, emit, diagnostic);
|
|
564
|
+
}
|
|
565
|
+
catch (error) {
|
|
566
|
+
return { errors: ['Composed CEL: ' + (error instanceof Error ? error.message : String(error))] };
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (options.logicalName === undefined)
|
|
570
|
+
return { errors: ['A logical file is required when no composition is declared in files.yaml'] };
|
|
571
|
+
if (stateConfiguration.strategy === 'indexed') {
|
|
572
|
+
// An in-place update may leave the current customer's state partial on failure.
|
|
573
|
+
// Fail fast until rollback is implemented.
|
|
574
|
+
if (options.onError === 'continue')
|
|
575
|
+
return { errors: [
|
|
576
|
+
'Indexed accumulator execution does not support --on-error continue without rollback'
|
|
577
|
+
] };
|
|
578
|
+
try {
|
|
579
|
+
const input = await (0, cursor_loader_source_1.prepareConfiguredFileSource)({
|
|
580
|
+
configDirectory: paths.directory, logicalName: options.logicalName,
|
|
581
|
+
...(options.input !== undefined ? { input: options.input } : {})
|
|
582
|
+
});
|
|
583
|
+
return await (0, cursor_loader_source_1.withPreparedFileSource)(input, async (source) => {
|
|
584
|
+
const prepared = (0, cel_graph_runtime_1.prepareIndexedCelGraph)(authored.value, source.projection, source.access);
|
|
585
|
+
if ('errors' in prepared)
|
|
586
|
+
return prepared;
|
|
587
|
+
const session = prepared.value.createIndexedSession(undefined, debugging ? (0, cel_entity_1.debugGenerations)(prepared.value.generations, prepared.value.schema, diagnostic, options.debugNode) : undefined);
|
|
588
|
+
const variables = options.periodicity === undefined ? {} : { periodicity: options.periodicity };
|
|
589
|
+
const indices = [];
|
|
590
|
+
let visited = 0, emitted = 0;
|
|
591
|
+
if (!options.raw && target === undefined)
|
|
592
|
+
emit(`# ${source.filename}`);
|
|
593
|
+
if (target !== undefined && !stateConfiguration.file) {
|
|
594
|
+
const keyAccess = source.access.compileScalar([stateConfiguration.customerId]);
|
|
595
|
+
if ('errors' in keyAccess)
|
|
596
|
+
return keyAccess;
|
|
597
|
+
await source.scan((record, lease) => {
|
|
598
|
+
try {
|
|
599
|
+
if ((0, cel_entity_1.selectEntity)(keyAccess.value.read(record, indices), target) === 'skip')
|
|
600
|
+
return true;
|
|
601
|
+
const state = (0, cel_entity_1.indexedStateFromInitial)(prepared.value.schema, checked.value);
|
|
602
|
+
state.entityKey = target;
|
|
603
|
+
if (debugging) {
|
|
604
|
+
trace('INPUT', (0, cel_entity_1.debugProjectedInput)(source.projection, source.access, record));
|
|
605
|
+
trace('PREVIOUS', (0, cel_entity_1.indexedStateObject)(prepared.value.schema, state));
|
|
606
|
+
}
|
|
607
|
+
session.run(record, state, variables, indices);
|
|
608
|
+
const result = (0, cel_entity_1.indexedStateObject)(prepared.value.schema, state);
|
|
609
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
610
|
+
trace('RESULT', result);
|
|
611
|
+
emitted++;
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
finally {
|
|
615
|
+
lease.close();
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
return emitted === 0 ? { errors: [`Entity ${target} not found`] } : { value: undefined };
|
|
619
|
+
}
|
|
620
|
+
const key = (0, indexed_accumulator_1.indexedCustomerKey)(source, stateConfiguration.customerId, stateConfiguration.customerIdType);
|
|
621
|
+
await (0, cursor_loader_indexed_graph_state_1.scanIndexedAccumulator)(source, {
|
|
622
|
+
schema: prepared.value.schema, optional: stateConfiguration.optional,
|
|
623
|
+
removed: stateConfiguration.removed, customerIdType: stateConfiguration.customerIdType, initial: (0, indexed_accumulator_1.indexedSeedValues)(checked.value),
|
|
624
|
+
...(stateConfiguration.file ? { filename: (0, node_path_1.resolve)(paths.directory, stateConfiguration.file) } : {})
|
|
625
|
+
}, key, (record, state) => {
|
|
626
|
+
visited++;
|
|
627
|
+
if (target !== undefined) {
|
|
628
|
+
const entity = key(record);
|
|
629
|
+
const selection = (0, cel_entity_1.selectEntity)(entity, target);
|
|
630
|
+
if (selection === 'skip')
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
else if (visited <= skip)
|
|
634
|
+
return true;
|
|
635
|
+
if (debugging)
|
|
636
|
+
trace('INPUT', (0, cel_entity_1.debugProjectedInput)(source.projection, source.access, record));
|
|
637
|
+
if (debugging)
|
|
638
|
+
trace('PREVIOUS', (0, cel_entity_1.indexedStateObject)(prepared.value.schema, state));
|
|
639
|
+
try {
|
|
640
|
+
session.run(record, state, variables, indices);
|
|
641
|
+
}
|
|
642
|
+
catch (error) {
|
|
643
|
+
throw new Error(`Record ${visited}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
644
|
+
}
|
|
645
|
+
const result = (0, cel_entity_1.indexedStateObject)(prepared.value.schema, state);
|
|
646
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
647
|
+
trace('RESULT', result);
|
|
648
|
+
emitted++;
|
|
649
|
+
return target === undefined && (count === undefined || emitted < count);
|
|
650
|
+
});
|
|
651
|
+
return target !== undefined && emitted === 0
|
|
652
|
+
? { errors: [`Entity ${target} not found`] } : { value: undefined };
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
catch (error) {
|
|
656
|
+
return { errors: [`CEL ${options.logicalName}: ${error instanceof Error ? error.message : String(error)}`] };
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if (target !== undefined) {
|
|
660
|
+
try {
|
|
661
|
+
const input = await (0, cursor_loader_source_1.prepareConfiguredFileSource)({
|
|
662
|
+
configDirectory: paths.directory, logicalName: options.logicalName,
|
|
663
|
+
...(options.input !== undefined ? { input: options.input } : {})
|
|
664
|
+
});
|
|
665
|
+
return await (0, cursor_loader_source_1.withPreparedFileSource)(input, async (source) => {
|
|
666
|
+
const graph = (0, cel_graph_runtime_1.prepareCelGraph)(authored.value, source.projection, source.access);
|
|
667
|
+
if ('errors' in graph)
|
|
668
|
+
return graph;
|
|
669
|
+
const observe = debugging ? (generation, state) => {
|
|
670
|
+
const values = {};
|
|
671
|
+
for (const node of graph.value.generations[generation]) {
|
|
672
|
+
if (options.debugNode !== undefined && node.metadata.name !== options.debugNode)
|
|
673
|
+
continue;
|
|
674
|
+
values[node.metadata.name] = state[node.metadata.name];
|
|
675
|
+
}
|
|
676
|
+
if (Object.keys(values).length !== 0) {
|
|
677
|
+
const selected = options.debugNode === undefined ? undefined : graph.value.generations[generation].find(node => node.metadata.name === options.debugNode);
|
|
678
|
+
diagnostic(`GENERATION ${generation} ${selected ? selected.type === 'cel' ?
|
|
679
|
+
`${selected.metadata.name} CEL ${JSON.stringify(selected.cel)} ` :
|
|
680
|
+
`${selected.metadata.name} AGGREGATE ${selected.operation}(${selected.window}) ` : ''}${(0, cel_json_1.stringifyCelJson)(values)}`);
|
|
681
|
+
}
|
|
682
|
+
} : undefined;
|
|
683
|
+
if (stateConfiguration.file) {
|
|
684
|
+
const historicalGraph = (0, cel_graph_runtime_1.prepareIndexedCelGraph)(authored.value, source.projection, source.access);
|
|
685
|
+
if ('errors' in historicalGraph)
|
|
686
|
+
return historicalGraph;
|
|
687
|
+
const key = (0, indexed_accumulator_1.indexedCustomerKey)(source, stateConfiguration.customerId, stateConfiguration.customerIdType);
|
|
688
|
+
let matched = false;
|
|
689
|
+
await (0, cursor_loader_indexed_graph_state_1.scanIndexedAccumulator)(source, {
|
|
690
|
+
schema: historicalGraph.value.schema, optional: stateConfiguration.optional,
|
|
691
|
+
removed: stateConfiguration.removed, customerIdType: stateConfiguration.customerIdType, initial: (0, indexed_accumulator_1.indexedSeedValues)(checked.value),
|
|
692
|
+
filename: (0, node_path_1.resolve)(paths.directory, stateConfiguration.file)
|
|
693
|
+
}, key, (record, state) => {
|
|
694
|
+
if ((0, cel_entity_1.selectEntity)(key(record), target) === 'skip')
|
|
695
|
+
return true;
|
|
696
|
+
matched = true;
|
|
697
|
+
const previous = (0, cel_entity_1.indexedStateObject)(historicalGraph.value.schema, state);
|
|
698
|
+
if (debugging) {
|
|
699
|
+
trace('INPUT', (0, cel_entity_1.debugProjectedInput)(source.projection, source.access, record));
|
|
700
|
+
trace('PREVIOUS', previous);
|
|
701
|
+
}
|
|
702
|
+
const result = graph.value.run(record, previous, variables, [], observe);
|
|
703
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
704
|
+
trace('RESULT', result);
|
|
705
|
+
return false;
|
|
706
|
+
});
|
|
707
|
+
return matched ? { value: undefined } : { errors: [`Entity ${target} not found`] };
|
|
708
|
+
}
|
|
709
|
+
const keyAccess = source.access.compileScalar([stateConfiguration.customerId]);
|
|
710
|
+
if ('errors' in keyAccess)
|
|
711
|
+
return keyAccess;
|
|
712
|
+
let matched = false;
|
|
713
|
+
await source.scan((record, lease) => {
|
|
714
|
+
try {
|
|
715
|
+
if ((0, cel_entity_1.selectEntity)(keyAccess.value.read(record, []), target) === 'skip')
|
|
716
|
+
return true;
|
|
717
|
+
matched = true;
|
|
718
|
+
if (debugging) {
|
|
719
|
+
trace('INPUT', (0, cel_entity_1.debugProjectedInput)(source.projection, source.access, record));
|
|
720
|
+
trace('PREVIOUS', checked.value);
|
|
721
|
+
}
|
|
722
|
+
const result = graph.value.run(record, checked.value, variables, [], observe);
|
|
723
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
724
|
+
trace('RESULT', result);
|
|
725
|
+
return false;
|
|
726
|
+
}
|
|
727
|
+
finally {
|
|
728
|
+
lease.close();
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
return matched ? { value: undefined } : { errors: [`Entity ${target} not found`] };
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
catch (error) {
|
|
735
|
+
return { errors: [`CEL ${options.logicalName}: ${error instanceof Error ? error.message : String(error)}`] };
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
const source = await (0, file_display_1.openConfiguredCobolFile)({
|
|
198
739
|
configDirectory: paths.directory, logicalName: options.logicalName,
|
|
199
740
|
catalogue: paths.catalogue, data: paths.data,
|
|
200
741
|
...(options.input !== undefined ? { input: options.input } : {})
|
|
@@ -204,10 +745,12 @@ exports.nodeCliServices = {
|
|
|
204
745
|
let prepared;
|
|
205
746
|
let visit = 0;
|
|
206
747
|
let emitted = 0;
|
|
207
|
-
|
|
748
|
+
const previous = checked.value;
|
|
749
|
+
const indices = [];
|
|
750
|
+
let session;
|
|
208
751
|
let fatalErrors;
|
|
209
752
|
try {
|
|
210
|
-
await (0, cursor_loader_cobol_1.
|
|
753
|
+
await (0, cursor_loader_cobol_1.scanCobolFileLeased)({
|
|
211
754
|
filename: source.value.filename,
|
|
212
755
|
copybook: source.value.copybook,
|
|
213
756
|
projection: source.value.runtimeProjection,
|
|
@@ -216,19 +759,24 @@ exports.nodeCliServices = {
|
|
|
216
759
|
prepared = (0, cel_graph_runtime_1.prepareCelGraph)(authored.value, source.value.projection, (0, cel_access_1.cobolAccessCompiler)(details, source.value.projection));
|
|
217
760
|
if ('errors' in prepared)
|
|
218
761
|
throw new Error(prepared.errors.join('; '));
|
|
762
|
+
session = prepared.value.createSession(previous);
|
|
219
763
|
// Only emit output after all CEL nodes have compiled successfully.
|
|
220
764
|
if (!options.raw)
|
|
221
765
|
emit(`# ${source.value.filename}`);
|
|
222
766
|
}
|
|
223
|
-
}, (
|
|
767
|
+
}, (upstream, parsed) => {
|
|
224
768
|
visit++;
|
|
225
|
-
if (visit <= skip)
|
|
769
|
+
if (visit <= skip) {
|
|
770
|
+
// No graph result is created for skipped rows, so the
|
|
771
|
+
// cursor lease has no downstream owner to transfer to.
|
|
772
|
+
upstream.close();
|
|
226
773
|
return;
|
|
227
|
-
|
|
774
|
+
}
|
|
775
|
+
if (!session)
|
|
228
776
|
throw new Error('CEL graph not prepared');
|
|
229
777
|
let evaluated;
|
|
230
778
|
try {
|
|
231
|
-
evaluated =
|
|
779
|
+
evaluated = session.runLeased(parsed, upstream, variables, indices);
|
|
232
780
|
}
|
|
233
781
|
catch (error) {
|
|
234
782
|
emitted++;
|
|
@@ -242,9 +790,14 @@ exports.nodeCliServices = {
|
|
|
242
790
|
return false;
|
|
243
791
|
return;
|
|
244
792
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
793
|
+
try {
|
|
794
|
+
emitted++;
|
|
795
|
+
emit((0, cel_json_1.stringifyCelJson)(evaluated.value));
|
|
796
|
+
}
|
|
797
|
+
finally {
|
|
798
|
+
// Sole normal owner of the upstream record's lifetime.
|
|
799
|
+
evaluated.close();
|
|
800
|
+
}
|
|
248
801
|
if (count !== undefined && emitted >= count)
|
|
249
802
|
return false;
|
|
250
803
|
});
|