@cobol-ts/cobolts 0.0.14 → 0.0.17
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 +450 -21
- 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 +12 -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/ai.d.ts +12 -0
- package/dist/src/commands/ai.demo.spec.d.ts +1 -0
- package/dist/src/commands/ai.demo.spec.js +242 -0
- package/dist/src/commands/ai.demo.spec.js.map +1 -0
- package/dist/src/commands/ai.js +125 -0
- package/dist/src/commands/ai.js.map +1 -0
- package/dist/src/commands/ai.spec.d.ts +1 -0
- package/dist/src/commands/ai.spec.js +170 -0
- package/dist/src/commands/ai.spec.js.map +1 -0
- 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 +107 -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 +242 -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/graph.d.ts +9 -0
- package/dist/src/commands/graph.js +98 -0
- package/dist/src/commands/graph.js.map +1 -0
- package/dist/src/commands/graph.report.d.ts +26 -0
- package/dist/src/commands/graph.report.js +75 -0
- package/dist/src/commands/graph.report.js.map +1 -0
- package/dist/src/commands/graph.spec.d.ts +1 -0
- package/dist/src/commands/graph.spec.js +215 -0
- package/dist/src/commands/graph.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 +40 -6
- package/dist/src/context.js +582 -21
- package/dist/src/context.js.map +1 -1
- package/dist/src/indexed.accumulator.d.ts +18 -0
- package/dist/src/indexed.accumulator.js +107 -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 +81 -0
- package/dist/src/indexed.accumulator.spec.js.map +1 -0
- package/package.json +27 -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,184 @@ 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, schema);
|
|
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,
|
|
247
|
+
async serveCharacteristics(catalogues, port) {
|
|
248
|
+
const { createCharacteristicsApp } = await import('@cobol-ts/characteristics-express');
|
|
249
|
+
const server = createCharacteristicsApp(catalogues).listen(port, '127.0.0.1');
|
|
250
|
+
await new Promise((resolve, reject) => {
|
|
251
|
+
server.once('listening', resolve);
|
|
252
|
+
server.once('error', reject);
|
|
253
|
+
});
|
|
254
|
+
},
|
|
80
255
|
async list(paths) {
|
|
81
256
|
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
|
|
257
|
+
const result = [paths.catalogue];
|
|
258
|
+
if (await files_1.nodeTextFiles.exists(paths.policy))
|
|
259
|
+
result.push(paths.policy);
|
|
83
260
|
if (await files_1.nodeTextFiles.exists(paths.data))
|
|
84
261
|
result.push(paths.data);
|
|
85
262
|
if (await files_1.nodeTextFiles.exists(paths.accumulator))
|
|
@@ -124,18 +301,67 @@ exports.nodeCliServices = {
|
|
|
124
301
|
const loaded = await loadCelAuthoringGraph(paths, options.graph);
|
|
125
302
|
if ('errors' in loaded)
|
|
126
303
|
return loaded;
|
|
127
|
-
if (options.stage === 'graph')
|
|
304
|
+
if (options.stage === 'graph' && !options.short)
|
|
128
305
|
return { value: JSON.stringify(loaded.value, null, 2) };
|
|
129
306
|
const canonical = (0, cel_graph_runtime_1.canonicaliseCelGraph)(loaded.value);
|
|
130
307
|
if ('errors' in canonical)
|
|
131
308
|
return canonical;
|
|
309
|
+
const shortNodes = () => canonical.value.map(node => `${node.metadata.name} <- ${node.dependsOn.map(path => path.join('.')).join(', ') || '-'}`).join('\n');
|
|
310
|
+
if (options.stage === 'graph' && options.short)
|
|
311
|
+
return { value: shortNodes() };
|
|
312
|
+
if (options.stage === 'stats') {
|
|
313
|
+
const metrics = { binaryResolutions: 0, dynamicBinaryResolutions: 0, dynamicConditionalResolutions: 0 };
|
|
314
|
+
const compile = (projection, access) => (0, cel_graph_runtime_1.prepareCelGraph)(loaded.value, projection, access, {}, {}, metrics);
|
|
315
|
+
if (options.logicalName !== undefined) {
|
|
316
|
+
const source = await (0, file_display_1.openConfiguredCobolFile)({
|
|
317
|
+
configDirectory: paths.directory, logicalName: options.logicalName,
|
|
318
|
+
catalogue: paths.catalogue, data: paths.data
|
|
319
|
+
}, files_1.nodeTextFiles, yaml_jsyaml_1.jsYamlParser);
|
|
320
|
+
if ('errors' in source)
|
|
321
|
+
return source;
|
|
322
|
+
const details = await (0, cursor_loader_cobol_1.prepareCobolFileDetails)({
|
|
323
|
+
copybook: source.value.copybook,
|
|
324
|
+
...(source.value.framing ? { framing: source.value.framing } : {})
|
|
325
|
+
});
|
|
326
|
+
const compiled = compile(source.value.projection, (0, cel_access_1.cobolAccessCompiler)(details, source.value.projection));
|
|
327
|
+
if ('errors' in compiled)
|
|
328
|
+
return compiled;
|
|
329
|
+
}
|
|
330
|
+
else if (await (0, composition_definition_1.hasCompositionDefinition)(paths.directory)) {
|
|
331
|
+
const definition = (0, errors_1.valueOrThrow)(await (0, composition_definition_1.readCompositionDefinition)(paths.directory));
|
|
332
|
+
const composed = await (0, composition_definition_1.prepareCompositionDefinition)(definition, logicalName => (0, cursor_loader_source_1.prepareConfiguredFileSource)({ configDirectory: paths.directory, logicalName }));
|
|
333
|
+
const compiled = compile(composed.composed.projection, composed.access);
|
|
334
|
+
if ('errors' in compiled)
|
|
335
|
+
return compiled;
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
const empty = {};
|
|
339
|
+
const compiled = compile(empty, (0, cel_access_1.jsonAccessCompiler)(empty));
|
|
340
|
+
if ('errors' in compiled)
|
|
341
|
+
return compiled;
|
|
342
|
+
}
|
|
343
|
+
return (0, cel_stats_1.celGraphStats)(canonical.value, metrics);
|
|
344
|
+
}
|
|
132
345
|
if (options.stage === 'canonical')
|
|
133
|
-
return { value:
|
|
346
|
+
return { value: options.short
|
|
347
|
+
? shortNodes()
|
|
348
|
+
: JSON.stringify(canonical.value, (_name, value) => typeof value === 'bigint' ? value.toString() : value, 2) };
|
|
134
349
|
const sorted = (0, cel_graph_runtime_1.planCanonicalCelGraph)(canonical.value);
|
|
135
350
|
if ('errors' in sorted)
|
|
136
351
|
return sorted;
|
|
137
352
|
if (options.stage === 'sorted') {
|
|
138
|
-
return { value:
|
|
353
|
+
return { value: options.short
|
|
354
|
+
? sorted.value.generations.map((nodes, index) => `G${index}: ${nodes.map(node => `${node.metadata.name}(${node.dependsOn.map(path => path.join('.')).join(', ') || '-'})`).join(' ')}`).join('\n')
|
|
355
|
+
: JSON.stringify({ generations: sorted.value.generations }, (_name, value) => typeof value === 'bigint' ? value.toString() : value, 2) };
|
|
356
|
+
}
|
|
357
|
+
if (options.stage === 'planned') {
|
|
358
|
+
let index = 0;
|
|
359
|
+
const planned = (0, planned_graph_1.makePlannedGraph)(sorted.value.generations, sorted.value.graph, (node, downstream) => ({ index: index++, node, downstream }));
|
|
360
|
+
if ('errors' in planned)
|
|
361
|
+
return planned;
|
|
362
|
+
return { value: options.short
|
|
363
|
+
? planned.value.map((generation, i) => `G${i}: ${generation.map(n => `${n.index}:${n.node.metadata.name}->[${n.downstream.join(',')}]`).join(' ')}`).join('\n')
|
|
364
|
+
: JSON.stringify({ generations: planned.value }, (_name, value) => typeof value === 'bigint' ? value.toString() : value, 2) };
|
|
139
365
|
}
|
|
140
366
|
if (options.stage !== 'validate')
|
|
141
367
|
return { errors: [`Unexpected CEL operation: ${options.stage}`] };
|
|
@@ -145,10 +371,25 @@ exports.nodeCliServices = {
|
|
|
145
371
|
const checked = (0, cel_graph_runtime_1.validateInitialAccumulator)(initial.value, loaded.value, canonical.value);
|
|
146
372
|
if ('errors' in checked)
|
|
147
373
|
return checked;
|
|
374
|
+
if (await (0, composition_definition_1.hasCompositionDefinition)(paths.directory)) {
|
|
375
|
+
try {
|
|
376
|
+
const definition = (0, errors_1.valueOrThrow)(await (0, composition_definition_1.readCompositionDefinition)(paths.directory));
|
|
377
|
+
const composed = await (0, composition_definition_1.prepareCompositionDefinition)(definition, logicalName => (0, cursor_loader_source_1.prepareConfiguredFileSource)({ configDirectory: paths.directory, logicalName }));
|
|
378
|
+
const graph = (0, cel_graph_runtime_1.prepareIndexedCelGraph)(loaded.value, composed.composed.projection, composed.access);
|
|
379
|
+
if ('errors' in graph)
|
|
380
|
+
return graph;
|
|
381
|
+
return { value: 'Valid composed graph: ' + graph.value.schema.nodes.length +
|
|
382
|
+
' nodes, ' + composed.sources.length + ' sources' };
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
return { errors: ['Composed CEL validation: ' +
|
|
386
|
+
(error instanceof Error ? error.message : String(error))] };
|
|
387
|
+
}
|
|
388
|
+
}
|
|
148
389
|
if (options.logicalName === undefined) {
|
|
149
390
|
return { value: `Valid graph: ${canonical.value.length} nodes, ${sorted.value.generations.length} generations (structural)` };
|
|
150
391
|
}
|
|
151
|
-
const source = await (0,
|
|
392
|
+
const source = await (0, file_display_1.openConfiguredCobolFile)({
|
|
152
393
|
configDirectory: paths.directory, logicalName: options.logicalName,
|
|
153
394
|
catalogue: paths.catalogue, data: paths.data
|
|
154
395
|
}, files_1.nodeTextFiles, yaml_jsyaml_1.jsYamlParser);
|
|
@@ -168,7 +409,27 @@ exports.nodeCliServices = {
|
|
|
168
409
|
return { errors: [`CEL validation ${options.logicalName}: ${error instanceof Error ? error.message : String(error)}`] };
|
|
169
410
|
}
|
|
170
411
|
},
|
|
171
|
-
async celExecute(paths, options, emit) {
|
|
412
|
+
async celExecute(paths, options, emit, diagnostic = message => console.error(message)) {
|
|
413
|
+
const variables = options.periodicity === undefined ? {} : { periodicity: options.periodicity };
|
|
414
|
+
let requestedEntity;
|
|
415
|
+
if (options.entityId !== undefined) {
|
|
416
|
+
requestedEntity = options.entityId;
|
|
417
|
+
if (options.skip !== undefined || options.count !== undefined || options.all || options.onError !== undefined)
|
|
418
|
+
return { errors: ['CEL evaluate cannot combine an entity ID with count, skip, all or on-error'] };
|
|
419
|
+
}
|
|
420
|
+
const measurement = options.measurement;
|
|
421
|
+
const target = requestedEntity;
|
|
422
|
+
const debugging = options.debug || options.debugNode !== undefined;
|
|
423
|
+
const trace = (label, value) => {
|
|
424
|
+
if (!debugging)
|
|
425
|
+
return;
|
|
426
|
+
if (options.debugNode !== undefined && (label === 'PREVIOUS' || label === 'RESULT')) {
|
|
427
|
+
const state = value;
|
|
428
|
+
diagnostic(label + ' ' + (0, cel_json_1.stringifyCelJson)({ [options.debugNode]: state[options.debugNode] }));
|
|
429
|
+
}
|
|
430
|
+
else
|
|
431
|
+
diagnostic(label + ' ' + (0, cel_json_1.stringifyCelJson)(value));
|
|
432
|
+
};
|
|
172
433
|
const count = options.all ? undefined : (options.count ?? 10);
|
|
173
434
|
const skip = options.skip ?? 0;
|
|
174
435
|
if (options.all && options.count !== undefined)
|
|
@@ -182,6 +443,8 @@ exports.nodeCliServices = {
|
|
|
182
443
|
const authored = await loadCelAuthoringGraph(paths, options.graph);
|
|
183
444
|
if ('errors' in authored)
|
|
184
445
|
return authored;
|
|
446
|
+
if (options.debugNode !== undefined && !Object.prototype.hasOwnProperty.call(authored.value, options.debugNode))
|
|
447
|
+
return { errors: [`Unknown debug node ${options.debugNode}`] };
|
|
185
448
|
const canonical = (0, cel_graph_runtime_1.canonicaliseCelGraph)(authored.value);
|
|
186
449
|
if ('errors' in canonical)
|
|
187
450
|
return canonical;
|
|
@@ -194,7 +457,293 @@ exports.nodeCliServices = {
|
|
|
194
457
|
const checked = (0, cel_graph_runtime_1.validateInitialAccumulator)(initial.value, authored.value, canonical.value);
|
|
195
458
|
if ('errors' in checked)
|
|
196
459
|
return checked;
|
|
197
|
-
|
|
460
|
+
let stateConfiguration;
|
|
461
|
+
try {
|
|
462
|
+
stateConfiguration = (await (0, indexed_accumulator_1.readAccumulatorDocument)(paths.accumulator)).state;
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
return { errors: [`Accumulator configuration: ${error instanceof Error ? error.message : String(error)}`] };
|
|
466
|
+
}
|
|
467
|
+
if (options.strategyOverride)
|
|
468
|
+
stateConfiguration = { ...stateConfiguration, strategy: options.strategyOverride };
|
|
469
|
+
if (await (0, composition_definition_1.hasCompositionDefinition)(paths.directory)) {
|
|
470
|
+
if (options.input !== undefined)
|
|
471
|
+
return { errors: ['--input is not supported by composed CEL execution; configure physical files in data.yaml'] };
|
|
472
|
+
if (options.onError === 'continue')
|
|
473
|
+
return { errors: ['Composed execution does not support --on-error continue without rollback'] };
|
|
474
|
+
try {
|
|
475
|
+
const definition = (0, errors_1.valueOrThrow)(await (0, composition_definition_1.readCompositionDefinition)(paths.directory));
|
|
476
|
+
// The physical-source adapter supplies its configured COBOL projection.
|
|
477
|
+
// Other formats require an explicit projection from their authoring layer.
|
|
478
|
+
const open = async (logicalName) => (0, cursor_loader_source_1.prepareConfiguredFileSource)({
|
|
479
|
+
configDirectory: paths.directory, logicalName
|
|
480
|
+
});
|
|
481
|
+
const prepared = await (0, composition_definition_1.prepareCompositionDefinition)(definition, open);
|
|
482
|
+
if (stateConfiguration.strategy === 'object') {
|
|
483
|
+
const graph = (0, cel_graph_runtime_1.prepareCelGraph)(authored.value, prepared.composed.projection, prepared.access);
|
|
484
|
+
if ('errors' in graph)
|
|
485
|
+
return graph;
|
|
486
|
+
const observe = debugging ? (generation, state) => {
|
|
487
|
+
const values = {};
|
|
488
|
+
for (const node of graph.value.generations[generation]) {
|
|
489
|
+
if (options.debugNode !== undefined && node.metadata.name !== options.debugNode)
|
|
490
|
+
continue;
|
|
491
|
+
values[node.metadata.name] = state[node.metadata.name];
|
|
492
|
+
}
|
|
493
|
+
if (Object.keys(values).length !== 0) {
|
|
494
|
+
const selected = options.debugNode === undefined ? undefined : graph.value.generations[generation].find(node => node.metadata.name === options.debugNode);
|
|
495
|
+
diagnostic(`GENERATION ${generation} ${selected ? selected.type === 'cel' ?
|
|
496
|
+
`${selected.metadata.name} CEL ${JSON.stringify(selected.cel)} ` :
|
|
497
|
+
`${selected.metadata.name} AGGREGATE ${selected.operation}(${selected.window}) ` : ''}${(0, cel_json_1.stringifyCelJson)(values)}`);
|
|
498
|
+
}
|
|
499
|
+
} : undefined;
|
|
500
|
+
let visited = 0, emitted = 0;
|
|
501
|
+
if (!options.raw && target === undefined)
|
|
502
|
+
emit('# ' + paths.catalogue);
|
|
503
|
+
if (stateConfiguration.file) {
|
|
504
|
+
// Object and indexed execution must read the same historical state.
|
|
505
|
+
const historicalGraph = (0, cel_graph_runtime_1.prepareIndexedCelGraph)(authored.value, prepared.composed.projection, prepared.access);
|
|
506
|
+
if ('errors' in historicalGraph)
|
|
507
|
+
return historicalGraph;
|
|
508
|
+
const normalizeKey = (0, indexed_accumulator_1.indexedKeyNormalizer)(stateConfiguration.customerIdType, stateConfiguration.customerId);
|
|
509
|
+
await (0, cursor_loader_indexed_graph_state_1.scanIndexedAccumulator)(prepared.composed, {
|
|
510
|
+
schema: historicalGraph.value.schema, optional: stateConfiguration.optional,
|
|
511
|
+
removed: stateConfiguration.removed, customerIdType: stateConfiguration.customerIdType, initial: (0, indexed_accumulator_1.indexedSeedValues)(checked.value, historicalGraph.value.schema),
|
|
512
|
+
filename: (0, node_path_1.resolve)(paths.directory, stateConfiguration.file)
|
|
513
|
+
}, row => normalizeKey(row.key), (row, state) => {
|
|
514
|
+
visited++;
|
|
515
|
+
if (target !== undefined && (0, cel_entity_1.selectEntity)(row.key, target) === 'skip')
|
|
516
|
+
return true;
|
|
517
|
+
if (target === undefined && visited <= skip)
|
|
518
|
+
return true;
|
|
519
|
+
const previous = (0, cel_entity_1.indexedStateObject)(historicalGraph.value.schema, state);
|
|
520
|
+
if (debugging) {
|
|
521
|
+
const input = (0, cel_entity_1.debugProjectedInput)(prepared.composed.projection, prepared.access, row);
|
|
522
|
+
trace('INPUT', input);
|
|
523
|
+
trace('PREVIOUS', previous);
|
|
524
|
+
}
|
|
525
|
+
const startedCel = measurement ? node_perf_hooks_1.performance.now() : 0;
|
|
526
|
+
const result = graph.value.run(row, previous, variables, [], observe);
|
|
527
|
+
if (measurement) {
|
|
528
|
+
measurement.celMs += node_perf_hooks_1.performance.now() - startedCel;
|
|
529
|
+
measurement.records++;
|
|
530
|
+
}
|
|
531
|
+
options.observeObject?.(row.key, result);
|
|
532
|
+
if (!options.suppressOutput)
|
|
533
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
534
|
+
trace('RESULT', result);
|
|
535
|
+
emitted++;
|
|
536
|
+
return target === undefined && (count === undefined || emitted < count);
|
|
537
|
+
});
|
|
538
|
+
return target !== undefined && emitted === 0
|
|
539
|
+
? { errors: [`Entity ${target} not found`] } : { value: undefined };
|
|
540
|
+
}
|
|
541
|
+
await prepared.composed.scan(row => {
|
|
542
|
+
visited++;
|
|
543
|
+
if (target !== undefined && (0, cel_entity_1.selectEntity)(row.key, target) === 'skip')
|
|
544
|
+
return true;
|
|
545
|
+
if (target === undefined && visited <= skip)
|
|
546
|
+
return true;
|
|
547
|
+
if (debugging) {
|
|
548
|
+
const input = (0, cel_entity_1.debugProjectedInput)(prepared.composed.projection, prepared.access, row);
|
|
549
|
+
trace('INPUT', input);
|
|
550
|
+
trace('PREVIOUS', checked.value);
|
|
551
|
+
}
|
|
552
|
+
const startedCel = measurement ? node_perf_hooks_1.performance.now() : 0;
|
|
553
|
+
const result = graph.value.run(row, checked.value, variables, [], observe);
|
|
554
|
+
if (measurement) {
|
|
555
|
+
measurement.celMs += node_perf_hooks_1.performance.now() - startedCel;
|
|
556
|
+
measurement.records++;
|
|
557
|
+
}
|
|
558
|
+
options.observeObject?.(row.key, result);
|
|
559
|
+
if (!options.suppressOutput)
|
|
560
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
561
|
+
trace('RESULT', result);
|
|
562
|
+
emitted++;
|
|
563
|
+
return target === undefined && (count === undefined || emitted < count);
|
|
564
|
+
});
|
|
565
|
+
return target !== undefined && emitted === 0
|
|
566
|
+
? { errors: [`Entity ${target} not found`] } : { value: undefined };
|
|
567
|
+
}
|
|
568
|
+
const executor = compileIndexedComposedExecutor(paths, authored.value, checked.value, stateConfiguration, prepared);
|
|
569
|
+
if ('errors' in executor)
|
|
570
|
+
return executor;
|
|
571
|
+
return await executor.value(options, emit, diagnostic);
|
|
572
|
+
}
|
|
573
|
+
catch (error) {
|
|
574
|
+
return { errors: ['Composed CEL: ' + (error instanceof Error ? error.message : String(error))] };
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
if (options.logicalName === undefined)
|
|
578
|
+
return { errors: ['A logical file is required when no composition is declared in files.yaml'] };
|
|
579
|
+
if (stateConfiguration.strategy === 'indexed') {
|
|
580
|
+
// An in-place update may leave the current customer's state partial on failure.
|
|
581
|
+
// Fail fast until rollback is implemented.
|
|
582
|
+
if (options.onError === 'continue')
|
|
583
|
+
return { errors: [
|
|
584
|
+
'Indexed accumulator execution does not support --on-error continue without rollback'
|
|
585
|
+
] };
|
|
586
|
+
try {
|
|
587
|
+
const input = await (0, cursor_loader_source_1.prepareConfiguredFileSource)({
|
|
588
|
+
configDirectory: paths.directory, logicalName: options.logicalName,
|
|
589
|
+
...(options.input !== undefined ? { input: options.input } : {})
|
|
590
|
+
});
|
|
591
|
+
return await (0, cursor_loader_source_1.withPreparedFileSource)(input, async (source) => {
|
|
592
|
+
const prepared = (0, cel_graph_runtime_1.prepareIndexedCelGraph)(authored.value, source.projection, source.access);
|
|
593
|
+
if ('errors' in prepared)
|
|
594
|
+
return prepared;
|
|
595
|
+
const session = prepared.value.createIndexedSession(undefined, debugging ? (0, cel_entity_1.debugGenerations)(prepared.value.generations, prepared.value.schema, diagnostic, options.debugNode) : undefined);
|
|
596
|
+
const variables = options.periodicity === undefined ? {} : { periodicity: options.periodicity };
|
|
597
|
+
const indices = [];
|
|
598
|
+
let visited = 0, emitted = 0;
|
|
599
|
+
if (!options.raw && target === undefined)
|
|
600
|
+
emit(`# ${source.filename}`);
|
|
601
|
+
if (target !== undefined && !stateConfiguration.file) {
|
|
602
|
+
const keyAccess = source.access.compileScalar([stateConfiguration.customerId]);
|
|
603
|
+
if ('errors' in keyAccess)
|
|
604
|
+
return keyAccess;
|
|
605
|
+
await source.scan((record, lease) => {
|
|
606
|
+
try {
|
|
607
|
+
if ((0, cel_entity_1.selectEntity)(keyAccess.value.read(record, indices), target) === 'skip')
|
|
608
|
+
return true;
|
|
609
|
+
const state = (0, cel_entity_1.indexedStateFromInitial)(prepared.value.schema, checked.value);
|
|
610
|
+
state.entityKey = target;
|
|
611
|
+
if (debugging) {
|
|
612
|
+
trace('INPUT', (0, cel_entity_1.debugProjectedInput)(source.projection, source.access, record));
|
|
613
|
+
trace('PREVIOUS', (0, cel_entity_1.indexedStateObject)(prepared.value.schema, state));
|
|
614
|
+
}
|
|
615
|
+
session.run(record, state, variables, indices);
|
|
616
|
+
const result = (0, cel_entity_1.indexedStateObject)(prepared.value.schema, state);
|
|
617
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
618
|
+
trace('RESULT', result);
|
|
619
|
+
emitted++;
|
|
620
|
+
return false;
|
|
621
|
+
}
|
|
622
|
+
finally {
|
|
623
|
+
lease.close();
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
return emitted === 0 ? { errors: [`Entity ${target} not found`] } : { value: undefined };
|
|
627
|
+
}
|
|
628
|
+
const key = (0, indexed_accumulator_1.indexedCustomerKey)(source, stateConfiguration.customerId, stateConfiguration.customerIdType);
|
|
629
|
+
await (0, cursor_loader_indexed_graph_state_1.scanIndexedAccumulator)(source, {
|
|
630
|
+
schema: prepared.value.schema, optional: stateConfiguration.optional,
|
|
631
|
+
removed: stateConfiguration.removed, customerIdType: stateConfiguration.customerIdType, initial: (0, indexed_accumulator_1.indexedSeedValues)(checked.value, prepared.value.schema),
|
|
632
|
+
...(stateConfiguration.file ? { filename: (0, node_path_1.resolve)(paths.directory, stateConfiguration.file) } : {})
|
|
633
|
+
}, key, (record, state) => {
|
|
634
|
+
visited++;
|
|
635
|
+
if (target !== undefined) {
|
|
636
|
+
const entity = key(record);
|
|
637
|
+
const selection = (0, cel_entity_1.selectEntity)(entity, target);
|
|
638
|
+
if (selection === 'skip')
|
|
639
|
+
return true;
|
|
640
|
+
}
|
|
641
|
+
else if (visited <= skip)
|
|
642
|
+
return true;
|
|
643
|
+
if (debugging)
|
|
644
|
+
trace('INPUT', (0, cel_entity_1.debugProjectedInput)(source.projection, source.access, record));
|
|
645
|
+
if (debugging)
|
|
646
|
+
trace('PREVIOUS', (0, cel_entity_1.indexedStateObject)(prepared.value.schema, state));
|
|
647
|
+
try {
|
|
648
|
+
session.run(record, state, variables, indices);
|
|
649
|
+
}
|
|
650
|
+
catch (error) {
|
|
651
|
+
throw new Error(`Record ${visited}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
652
|
+
}
|
|
653
|
+
const result = (0, cel_entity_1.indexedStateObject)(prepared.value.schema, state);
|
|
654
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
655
|
+
trace('RESULT', result);
|
|
656
|
+
emitted++;
|
|
657
|
+
return target === undefined && (count === undefined || emitted < count);
|
|
658
|
+
});
|
|
659
|
+
return target !== undefined && emitted === 0
|
|
660
|
+
? { errors: [`Entity ${target} not found`] } : { value: undefined };
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
catch (error) {
|
|
664
|
+
return { errors: [`CEL ${options.logicalName}: ${error instanceof Error ? error.message : String(error)}`] };
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
if (target !== undefined) {
|
|
668
|
+
try {
|
|
669
|
+
const input = await (0, cursor_loader_source_1.prepareConfiguredFileSource)({
|
|
670
|
+
configDirectory: paths.directory, logicalName: options.logicalName,
|
|
671
|
+
...(options.input !== undefined ? { input: options.input } : {})
|
|
672
|
+
});
|
|
673
|
+
return await (0, cursor_loader_source_1.withPreparedFileSource)(input, async (source) => {
|
|
674
|
+
const graph = (0, cel_graph_runtime_1.prepareCelGraph)(authored.value, source.projection, source.access);
|
|
675
|
+
if ('errors' in graph)
|
|
676
|
+
return graph;
|
|
677
|
+
const observe = debugging ? (generation, state) => {
|
|
678
|
+
const values = {};
|
|
679
|
+
for (const node of graph.value.generations[generation]) {
|
|
680
|
+
if (options.debugNode !== undefined && node.metadata.name !== options.debugNode)
|
|
681
|
+
continue;
|
|
682
|
+
values[node.metadata.name] = state[node.metadata.name];
|
|
683
|
+
}
|
|
684
|
+
if (Object.keys(values).length !== 0) {
|
|
685
|
+
const selected = options.debugNode === undefined ? undefined : graph.value.generations[generation].find(node => node.metadata.name === options.debugNode);
|
|
686
|
+
diagnostic(`GENERATION ${generation} ${selected ? selected.type === 'cel' ?
|
|
687
|
+
`${selected.metadata.name} CEL ${JSON.stringify(selected.cel)} ` :
|
|
688
|
+
`${selected.metadata.name} AGGREGATE ${selected.operation}(${selected.window}) ` : ''}${(0, cel_json_1.stringifyCelJson)(values)}`);
|
|
689
|
+
}
|
|
690
|
+
} : undefined;
|
|
691
|
+
if (stateConfiguration.file) {
|
|
692
|
+
const historicalGraph = (0, cel_graph_runtime_1.prepareIndexedCelGraph)(authored.value, source.projection, source.access);
|
|
693
|
+
if ('errors' in historicalGraph)
|
|
694
|
+
return historicalGraph;
|
|
695
|
+
const key = (0, indexed_accumulator_1.indexedCustomerKey)(source, stateConfiguration.customerId, stateConfiguration.customerIdType);
|
|
696
|
+
let matched = false;
|
|
697
|
+
await (0, cursor_loader_indexed_graph_state_1.scanIndexedAccumulator)(source, {
|
|
698
|
+
schema: historicalGraph.value.schema, optional: stateConfiguration.optional,
|
|
699
|
+
removed: stateConfiguration.removed, customerIdType: stateConfiguration.customerIdType, initial: (0, indexed_accumulator_1.indexedSeedValues)(checked.value, historicalGraph.value.schema),
|
|
700
|
+
filename: (0, node_path_1.resolve)(paths.directory, stateConfiguration.file)
|
|
701
|
+
}, key, (record, state) => {
|
|
702
|
+
if ((0, cel_entity_1.selectEntity)(key(record), target) === 'skip')
|
|
703
|
+
return true;
|
|
704
|
+
matched = true;
|
|
705
|
+
const previous = (0, cel_entity_1.indexedStateObject)(historicalGraph.value.schema, state);
|
|
706
|
+
if (debugging) {
|
|
707
|
+
trace('INPUT', (0, cel_entity_1.debugProjectedInput)(source.projection, source.access, record));
|
|
708
|
+
trace('PREVIOUS', previous);
|
|
709
|
+
}
|
|
710
|
+
const result = graph.value.run(record, previous, variables, [], observe);
|
|
711
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
712
|
+
trace('RESULT', result);
|
|
713
|
+
return false;
|
|
714
|
+
});
|
|
715
|
+
return matched ? { value: undefined } : { errors: [`Entity ${target} not found`] };
|
|
716
|
+
}
|
|
717
|
+
const keyAccess = source.access.compileScalar([stateConfiguration.customerId]);
|
|
718
|
+
if ('errors' in keyAccess)
|
|
719
|
+
return keyAccess;
|
|
720
|
+
let matched = false;
|
|
721
|
+
await source.scan((record, lease) => {
|
|
722
|
+
try {
|
|
723
|
+
if ((0, cel_entity_1.selectEntity)(keyAccess.value.read(record, []), target) === 'skip')
|
|
724
|
+
return true;
|
|
725
|
+
matched = true;
|
|
726
|
+
if (debugging) {
|
|
727
|
+
trace('INPUT', (0, cel_entity_1.debugProjectedInput)(source.projection, source.access, record));
|
|
728
|
+
trace('PREVIOUS', checked.value);
|
|
729
|
+
}
|
|
730
|
+
const result = graph.value.run(record, checked.value, variables, [], observe);
|
|
731
|
+
emit((0, cel_json_1.stringifyCelJson)(result));
|
|
732
|
+
trace('RESULT', result);
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
finally {
|
|
736
|
+
lease.close();
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
return matched ? { value: undefined } : { errors: [`Entity ${target} not found`] };
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
catch (error) {
|
|
743
|
+
return { errors: [`CEL ${options.logicalName}: ${error instanceof Error ? error.message : String(error)}`] };
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
const source = await (0, file_display_1.openConfiguredCobolFile)({
|
|
198
747
|
configDirectory: paths.directory, logicalName: options.logicalName,
|
|
199
748
|
catalogue: paths.catalogue, data: paths.data,
|
|
200
749
|
...(options.input !== undefined ? { input: options.input } : {})
|
|
@@ -204,10 +753,12 @@ exports.nodeCliServices = {
|
|
|
204
753
|
let prepared;
|
|
205
754
|
let visit = 0;
|
|
206
755
|
let emitted = 0;
|
|
207
|
-
|
|
756
|
+
const previous = checked.value;
|
|
757
|
+
const indices = [];
|
|
758
|
+
let session;
|
|
208
759
|
let fatalErrors;
|
|
209
760
|
try {
|
|
210
|
-
await (0, cursor_loader_cobol_1.
|
|
761
|
+
await (0, cursor_loader_cobol_1.scanCobolFileLeased)({
|
|
211
762
|
filename: source.value.filename,
|
|
212
763
|
copybook: source.value.copybook,
|
|
213
764
|
projection: source.value.runtimeProjection,
|
|
@@ -216,19 +767,24 @@ exports.nodeCliServices = {
|
|
|
216
767
|
prepared = (0, cel_graph_runtime_1.prepareCelGraph)(authored.value, source.value.projection, (0, cel_access_1.cobolAccessCompiler)(details, source.value.projection));
|
|
217
768
|
if ('errors' in prepared)
|
|
218
769
|
throw new Error(prepared.errors.join('; '));
|
|
770
|
+
session = prepared.value.createSession(previous);
|
|
219
771
|
// Only emit output after all CEL nodes have compiled successfully.
|
|
220
772
|
if (!options.raw)
|
|
221
773
|
emit(`# ${source.value.filename}`);
|
|
222
774
|
}
|
|
223
|
-
}, (
|
|
775
|
+
}, (upstream, parsed) => {
|
|
224
776
|
visit++;
|
|
225
|
-
if (visit <= skip)
|
|
777
|
+
if (visit <= skip) {
|
|
778
|
+
// No graph result is created for skipped rows, so the
|
|
779
|
+
// cursor lease has no downstream owner to transfer to.
|
|
780
|
+
upstream.close();
|
|
226
781
|
return;
|
|
227
|
-
|
|
782
|
+
}
|
|
783
|
+
if (!session)
|
|
228
784
|
throw new Error('CEL graph not prepared');
|
|
229
785
|
let evaluated;
|
|
230
786
|
try {
|
|
231
|
-
evaluated =
|
|
787
|
+
evaluated = session.runLeased(parsed, upstream, variables, indices);
|
|
232
788
|
}
|
|
233
789
|
catch (error) {
|
|
234
790
|
emitted++;
|
|
@@ -242,9 +798,14 @@ exports.nodeCliServices = {
|
|
|
242
798
|
return false;
|
|
243
799
|
return;
|
|
244
800
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
801
|
+
try {
|
|
802
|
+
emitted++;
|
|
803
|
+
emit((0, cel_json_1.stringifyCelJson)(evaluated.value));
|
|
804
|
+
}
|
|
805
|
+
finally {
|
|
806
|
+
// Sole normal owner of the upstream record's lifetime.
|
|
807
|
+
evaluated.close();
|
|
808
|
+
}
|
|
248
809
|
if (count !== undefined && emitted >= count)
|
|
249
810
|
return false;
|
|
250
811
|
});
|