@cobol-ts/cobolts 0.0.19 → 0.0.20

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.
Files changed (50) hide show
  1. package/README.md +72 -11
  2. package/build/gui/assets/index-AxtZbbsk.js +71 -0
  3. package/build/gui/assets/index-DUqGF627.css +1 -0
  4. package/build/gui/index.html +13 -0
  5. package/dist/src/cli.integration.spec.js +3 -3
  6. package/dist/src/cli.integration.spec.js.map +1 -1
  7. package/dist/src/cli.js +1 -0
  8. package/dist/src/cli.js.map +1 -1
  9. package/dist/src/commands/ai.demo.spec.js +8 -4
  10. package/dist/src/commands/ai.demo.spec.js.map +1 -1
  11. package/dist/src/commands/ai.spec.js +15 -4
  12. package/dist/src/commands/ai.spec.js.map +1 -1
  13. package/dist/src/commands/characteristics.d.ts +1 -0
  14. package/dist/src/commands/characteristics.js +77 -25
  15. package/dist/src/commands/characteristics.js.map +1 -1
  16. package/dist/src/commands/characteristics.spec.js +88 -15
  17. package/dist/src/commands/characteristics.spec.js.map +1 -1
  18. package/dist/src/commands/extract.d.ts +4 -1
  19. package/dist/src/commands/extract.js +23 -6
  20. package/dist/src/commands/extract.js.map +1 -1
  21. package/dist/src/commands/extract.spec.js +87 -0
  22. package/dist/src/commands/extract.spec.js.map +1 -1
  23. package/dist/src/commands/graph.spec.js +1 -1
  24. package/dist/src/commands/graph.spec.js.map +1 -1
  25. package/dist/src/composition.data.d.ts +10 -0
  26. package/dist/src/composition.data.js +133 -0
  27. package/dist/src/composition.data.js.map +1 -0
  28. package/dist/src/composition.data.spec.d.ts +1 -0
  29. package/dist/src/composition.data.spec.js +80 -0
  30. package/dist/src/composition.data.spec.js.map +1 -0
  31. package/dist/src/composition.run.d.ts +5 -0
  32. package/dist/src/composition.run.integration.spec.d.ts +1 -0
  33. package/dist/src/composition.run.integration.spec.js +32 -0
  34. package/dist/src/composition.run.integration.spec.js.map +1 -0
  35. package/dist/src/composition.run.js +32 -0
  36. package/dist/src/composition.run.js.map +1 -0
  37. package/dist/src/composition.run.spec.d.ts +1 -0
  38. package/dist/src/composition.run.spec.js +71 -0
  39. package/dist/src/composition.run.spec.js.map +1 -0
  40. package/dist/src/context.d.ts +13 -1
  41. package/dist/src/context.js +67 -3
  42. package/dist/src/context.js.map +1 -1
  43. package/dist/src/gui.assets.d.ts +11 -0
  44. package/dist/src/gui.assets.js +68 -0
  45. package/dist/src/gui.assets.js.map +1 -0
  46. package/dist/src/gui.assets.spec.d.ts +1 -0
  47. package/dist/src/gui.assets.spec.js +94 -0
  48. package/dist/src/gui.assets.spec.js.map +1 -0
  49. package/index.ts +2 -0
  50. package/package.json +34 -28
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.projectedEntity = projectedEntity;
4
+ exports.pageEntityIds = pageEntityIds;
5
+ exports.lookupEntityData = lookupEntityData;
6
+ exports.compositionDataQueries = compositionDataQueries;
7
+ const composition_definition_1 = require("@cobol-ts/composition-definition");
8
+ const cursor_loader_source_1 = require("@cobol-ts/cursor-loader-source");
9
+ const errors_1 = require("@cobol-ts/errors");
10
+ const message = (error) => error instanceof Error ? error.message : String(error);
11
+ const jsonScalar = (value) => typeof value === 'bigint' ||
12
+ (typeof value === 'number' && !Number.isFinite(value)) ? String(value) : value;
13
+ /** Use the source's actual compiled accessors, including for present optional members.
14
+ * This is a detached diagnostic snapshot; never return a leased view to HTTP. */
15
+ function projectedEntity(sources, row) {
16
+ const errors = new Map();
17
+ const capture = (path, read) => {
18
+ try {
19
+ return read();
20
+ }
21
+ catch (error) {
22
+ const reason = message(error);
23
+ errors.set(path, reason);
24
+ return `ERROR: ${reason}`;
25
+ }
26
+ };
27
+ function project(source, representation, fields, prefix, indices, display) {
28
+ return Object.fromEntries(Object.entries(fields).map(([name, node]) => {
29
+ const path = [...prefix, name];
30
+ const label = `${display}.${name}`;
31
+ return [name, capture(label, () => {
32
+ if (node.type === 'object')
33
+ return project(source, representation, node.fields, path, indices, label);
34
+ if (node.type === 'array') {
35
+ if (!source.access.compileArray)
36
+ throw new Error(`Cannot inspect array ${path.join('.')}`);
37
+ const compiled = (0, errors_1.valueOrThrow)(source.access.compileArray(path));
38
+ const length = compiled.length(representation, indices);
39
+ if (!Number.isSafeInteger(length) || length < 0)
40
+ throw new Error(`Invalid array length ${length}`);
41
+ return Array.from({ length }, (_, i) => project(source, representation, node.element, path, [...indices, i], `${label}[${i}]`));
42
+ }
43
+ return jsonScalar((0, errors_1.valueOrThrow)(source.access.compileScalar(path)).read(representation, indices));
44
+ })];
45
+ }));
46
+ }
47
+ const input = Object.fromEntries(sources.map((source, slot) => {
48
+ const path = `input.${source.name}`;
49
+ const value = capture(path, () => {
50
+ const count = row.count(slot);
51
+ const member = (i, label) => capture(label, () => project(source, row.entry(slot, i).representation, source.projection, [], [], label));
52
+ if (source.cardinality === 'many' || source.cardinality === 'manyOptional')
53
+ return Array.from({ length: count }, (_, i) => member(i, `${path}[${i}]`));
54
+ return count === 0 ? null : member(0, path);
55
+ });
56
+ return [source.name, value];
57
+ }));
58
+ return { id: String(row.key), input, errors: Object.fromEntries(errors) };
59
+ }
60
+ /** Scan only the master key for paging. A one-record lookahead determines whether another page exists. */
61
+ async function pageEntityIds(master, { offset, limit }) {
62
+ const cursor = await master.openCursor();
63
+ const ids = [];
64
+ let visited = 0;
65
+ let more = false;
66
+ try {
67
+ while (true) {
68
+ const next = cursor.take();
69
+ const lease = next instanceof Promise ? await next : next;
70
+ if (lease === undefined)
71
+ break;
72
+ try {
73
+ if (visited++ < offset)
74
+ continue;
75
+ if (ids.length === limit) {
76
+ more = true;
77
+ break;
78
+ }
79
+ ids.push(String(master.key(lease)));
80
+ }
81
+ finally {
82
+ lease.close();
83
+ }
84
+ }
85
+ }
86
+ finally {
87
+ await cursor.close();
88
+ }
89
+ return { ids, nextCursor: more ? String(offset + ids.length) : null };
90
+ }
91
+ /** One scan per batch, regardless of the number of requested IDs. Only requested records are projected. */
92
+ async function lookupEntityData(composed, ids) {
93
+ const results = new Map(ids.map(id => [id, { found: false }]));
94
+ const pending = new Set(ids);
95
+ if (pending.size)
96
+ await composed.scan(row => {
97
+ const id = String(row.key);
98
+ if (pending.delete(id))
99
+ results.set(id, { found: true, data: projectedEntity(composed.sources, row) });
100
+ return pending.size > 0;
101
+ });
102
+ return Object.fromEntries(results);
103
+ }
104
+ function compositionDataQueries(directory, run) {
105
+ const definition = async (name) => {
106
+ const result = (0, errors_1.valueOrThrow)(await (0, composition_definition_1.readCompositionDefinition)(directory, 'files.yaml', name));
107
+ if (result.type !== 'relational')
108
+ throw new Error(`Composition ${name} is not relational`);
109
+ return result;
110
+ };
111
+ const open = (logicalName) => (0, cursor_loader_source_1.prepareConfiguredFileSource)({ configDirectory: directory, logicalName });
112
+ return {
113
+ run,
114
+ compositions: async () => (0, errors_1.valueOrThrow)(await (0, composition_definition_1.readCompositionNames)(directory)).filter((summary) => summary.type === 'relational'),
115
+ ids: async (name, page) => {
116
+ const selected = await definition(name);
117
+ const master = selected.composition.master;
118
+ const file = selected.files[master];
119
+ const source = await open(master);
120
+ const prepared = (0, cursor_loader_source_1.withPreparedFileSource)(source, typed => (0, cursor_loader_source_1.asCompositionSource)(typed, {
121
+ name: master, cardinality: 'one', keyPath: (0, composition_definition_1.resolveEntityKeyPath)(typed.projection, file.key, file.keyPath)
122
+ }));
123
+ return pageEntityIds(prepared, page);
124
+ },
125
+ data: async (name, ids) => {
126
+ if (!ids.length)
127
+ return {};
128
+ const prepared = await (0, composition_definition_1.prepareCompositionDefinition)(await definition(name), open);
129
+ return lookupEntityData(prepared.composed, ids);
130
+ }
131
+ };
132
+ }
133
+ //# sourceMappingURL=composition.data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composition.data.js","sourceRoot":"","sources":["../../src/composition.data.ts"],"names":[],"mappings":";;AAaA,0CA0CC;AAGD,sCAkBC;AAGD,4CAUC;AAED,wDA2BC;AArHD,6EAAoJ;AACpJ,yEAAuH;AAG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ports, "__esModule", { value: true });
3
+ const composition_data_1 = require("./composition.data");
4
+ const projection = {
5
+ id: { type: 'integer' },
6
+ orders: { type: 'array', element: { quantity: { type: 'integer' } } },
7
+ broken: { type: 'integer' }
8
+ };
9
+ function source(name, cardinality, fields = projection) {
10
+ return { name, cardinality, projection: fields,
11
+ access: {
12
+ compileScalar: path => ({ value: { type: 'integer', plan: null, read: (record, indices) => {
13
+ if (path[0] === 'broken')
14
+ throw new Error('Invalid packed decimal');
15
+ if (path[0] === 'orders')
16
+ return record.orders[indices[0]].quantity;
17
+ return record.id;
18
+ } } }),
19
+ compileArray: () => ({ value: { plan: null, length: record => record.orders.length } })
20
+ },
21
+ key: lease => lease.representation.id,
22
+ openCursor: async () => { throw new Error('Unexpected open'); } };
23
+ }
24
+ function row(id) {
25
+ const representations = [[{ id, orders: [{ quantity: 2 }, { quantity: 5 }] }], [], [{ id: 9 }, { id: 10 }], [{ id: 11 }]];
26
+ return { key: id, active: true, slots: [], count: slot => representations[slot].length,
27
+ entry: (slot, index) => ({ representation: representations[slot][index], result: {}, closed: false, close() { } }) };
28
+ }
29
+ const sources = [source('customers', 'one'), source('optional', 'optional', { id: { type: 'integer' } }),
30
+ source('accounts', 'many', { id: { type: 'integer' } }), source('presentOptional', 'optional', { id: { type: 'integer' } })];
31
+ const expected = (id) => ({ id: String(id), input: { customers: { id, orders: [{ quantity: 2 }, { quantity: 5 }], broken: 'ERROR: Invalid packed decimal' },
32
+ optional: null, accounts: [{ id: 9 }, { id: 10 }], presentOptional: { id: 11 } },
33
+ errors: { 'input.customers.broken': 'Invalid packed decimal' } });
34
+ describe('composition diagnostic queries', () => {
35
+ it('materialises nested arrays and present/absent optional members while isolating field failures', () => {
36
+ expect((0, composition_data_1.projectedEntity)(sources, row(2))).toEqual(expected(2));
37
+ });
38
+ it('scans once for a batch, returning missing IDs and stopping after the last match', async () => {
39
+ const seen = [];
40
+ const composed = { sources, scan: async (visitor) => {
41
+ for (const id of [1, 2, 3, 4]) {
42
+ seen.push(id);
43
+ if (visitor(row(id)) === false)
44
+ break;
45
+ }
46
+ } };
47
+ expect(await (0, composition_data_1.lookupEntityData)(composed, ['3', '1', '3'])).toEqual({ '3': { found: true, data: expected(3) }, '1': { found: true, data: expected(1) } });
48
+ expect(seen).toEqual([1, 2, 3]);
49
+ seen.length = 0;
50
+ expect(await (0, composition_data_1.lookupEntityData)(composed, ['2', '99'])).toEqual({ '2': { found: true, data: expected(2) }, '99': { found: false } });
51
+ expect(seen).toEqual([1, 2, 3, 4]);
52
+ seen.length = 0;
53
+ expect(await (0, composition_data_1.lookupEntityData)(composed, [])).toEqual({});
54
+ expect(seen).toEqual([]);
55
+ });
56
+ it('pages master IDs with lookahead, closes every lease and does not read skipped keys', async () => {
57
+ const closed = [], keys = [];
58
+ let cursorClosed = 0;
59
+ const master = { ...source('customers', 'one'), key: lease => {
60
+ const id = lease.representation.id;
61
+ keys.push(id);
62
+ return id;
63
+ }, openCursor: async () => {
64
+ let index = 0;
65
+ return { take: () => {
66
+ if (index === 4)
67
+ return undefined;
68
+ const id = ++index;
69
+ return { representation: { id }, result: {}, closed: false, close: () => { closed.push(id); } };
70
+ }, close: async () => { cursorClosed++; } };
71
+ } };
72
+ expect(await (0, composition_data_1.pageEntityIds)(master, { offset: 1, limit: 2 })).toEqual({ ids: ['2', '3'], nextCursor: '3' });
73
+ expect(keys).toEqual([2, 3]);
74
+ expect(closed).toEqual([1, 2, 3, 4]);
75
+ expect(cursorClosed).toEqual(1);
76
+ expect(await (0, composition_data_1.pageEntityIds)(master, { offset: 3, limit: 2 })).toEqual({ ids: ['4'], nextCursor: null });
77
+ expect(cursorClosed).toEqual(2);
78
+ });
79
+ });
80
+ //# sourceMappingURL=composition.data.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composition.data.spec.js","sourceRoot":"","sources":["../../src/composition.data.spec.ts"],"names":[],"mappings":";;AAAA,yDAAmF;AAInF,MAAM,UAAU,GAAwB;IACpC,EAAE,EAAE,EAAC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a,EAAC,MAAM,EAAE,EAAC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,IAAI,EAAC,CAAC,CAAA;QAClG,MAAM,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IACnC,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { CompositionDataQueries } from '@cobol-ts/characteristics-express';
2
+ import type { CliPaths, CliServices } from './context';
3
+ /** Diagnostic execution uses the existing skip/count loop and read-only accumulator join.
4
+ * Snapshot inside the observer: indexed state and rolling-window buffers are pooled. */
5
+ export declare function compositionRunQuery(execute: CliServices['celExecute'], paths: CliPaths, graph?: string): CompositionDataQueries['run'];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const promises_1 = require("node:fs/promises");
4
+ const node_os_1 = require("node:os");
5
+ const node_path_1 = require("node:path");
6
+ const benchmark_periodic_fixture_1 = require("./benchmark.periodic.fixture");
7
+ const context_1 = require("./context");
8
+ const composition_run_1 = require("./composition.run");
9
+ const composition_data_1 = require("./composition.data");
10
+ test('diagnostic execution uses the selected composition periodicity with historical state', async () => {
11
+ const root = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-run-periodicity-'));
12
+ try {
13
+ const directory = await (0, benchmark_periodic_fixture_1.generatePeriodicBenchmarkProject)(root, 2);
14
+ const paths = await context_1.nodeCliServices.paths({ directory });
15
+ const queries = (0, composition_data_1.compositionDataQueries)(paths.directory, (0, composition_run_1.compositionRunQuery)(context_1.nodeCliServices.celExecute, paths));
16
+ const compositions = await queries.compositions();
17
+ const daily = compositions.find(c => c.name === 'benchmark');
18
+ const monthly = compositions.find(c => c.name === 'monthly');
19
+ expect([daily.periodicity, monthly.periodicity]).toEqual(['daily', 'monthly']);
20
+ const day = await queries.run(daily, 1);
21
+ const month = await queries.run(monthly, 1);
22
+ const values = (state) => [state.node0000, state.node0200, state.node0300];
23
+ expect({ id: day?.id, index: day?.index, before: values(day.accumulatorIn), after: values(day.accumulatorOut) })
24
+ .toEqual({ id: '2', index: 1, before: [32, 27, 0], after: [33, 27, 0] });
25
+ expect({ id: month?.id, index: month?.index, before: values(month.accumulatorIn), after: values(month.accumulatorOut) })
26
+ .toEqual({ id: '2', index: 1, before: [32, 27, 0], after: [0, 57, 58] });
27
+ }
28
+ finally {
29
+ await (0, promises_1.rm)(root, { recursive: true, force: true });
30
+ }
31
+ });
32
+ //# sourceMappingURL=composition.run.integration.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composition.run.integration.spec.js","sourceRoot":"","sources":["../../src/composition.run.integration.spec.ts"],"names":[],"mappings":";;AAAA,+CAA4C;AAC5C,qCAA8B;AAC9B,yCAA8B;AAC9B,6EAA6E;AAC7E,uCAAyC;AACzC,uDAAqD;AACrD,yDAAyD;AAEzD,IAAI,CAAC,sFAAsF,EAAE,KAAK,IAAI,EAAE;IACpG,MAAM,IAAI,GAAG,MAAM,IAAA,kBAAO,EAAC,IAAA,gBAAI,EAAC,IAAA,gBAAM,GAAE,EAAE,0BAA0B,CAAC,CAAC,CAAA;IACtE,IAAI,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,IAAA,6DAAgC,EAAC,IAAI,EAAE,CAAC,CAAC,CAAA;QACjE,MAAM,KAAK,GAAG,MAAM,yBAAe,CAAC,KAAK,CAAC,EAAC,SAAS,EAAC,CAAC,CAAA;QACtD,MAAM,OAAO,GAAG,IAAA,yCAAsB,EAAC,KAAK,CAAC,SAAS,EAAE,IAAA,qCAAmB,EAAC,yBAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAA;QAC/G,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,YAAY,EAAE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M,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAM,CAAC,cAAc,CAAC,EAAC,CAAC;aACnH,OAAO,CAAC,EAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAC,CAAC,CAAA;IAC9E,CAAC;YAAS,CAAC;QAAA,MAAM,IAAA,aAAE,EAAC,IAAI,EAAE,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC,CAAA;IAAA,CAAC;AAC9D,CAAC,CAAC,CAAA"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compositionRunQuery = compositionRunQuery;
4
+ const cel_json_1 = require("./cel.json");
5
+ const errors_1 = require("@cobol-ts/errors");
6
+ /** Diagnostic execution uses the existing skip/count loop and read-only accumulator join.
7
+ * Snapshot inside the observer: indexed state and rolling-window buffers are pooled. */
8
+ function compositionRunQuery(execute, paths, graph) {
9
+ return async (composition, index) => {
10
+ let result;
11
+ let previous;
12
+ const snapshot = (state) => JSON.parse((0, cel_json_1.stringifyCelJson)(Object.fromEntries(Object.entries(state).map(([name, value]) => [name, value ?? null]))));
13
+ const capturePrevious = (key, state) => {
14
+ previous = { id: String(key), snapshot: snapshot(state) };
15
+ };
16
+ const capture = (key, state) => {
17
+ if (!previous || previous.id !== String(key))
18
+ throw new Error('Missing input accumulator snapshot');
19
+ result = { id: String(key), index, accumulatorIn: previous.snapshot, accumulatorOut: snapshot(state) };
20
+ };
21
+ (0, errors_1.valueOrThrow)(await execute(paths, {
22
+ composition: composition.name, periodicity: composition.periodicity, ...(graph === undefined ? {} : { graph }), skip: index, count: 1,
23
+ raw: true, suppressOutput: true,
24
+ observePreviousObject: capturePrevious,
25
+ observePreviousIndexed: (key, values, schema) => capturePrevious(key, Object.fromEntries(schema.nodes.map((node, i) => [node.name, values[i]]))),
26
+ observeObject: capture,
27
+ observeIndexed: (key, values, schema) => capture(key, Object.fromEntries(schema.nodes.map((node, i) => [node.name, values[i]])))
28
+ }, () => { }));
29
+ return result;
30
+ };
31
+ }
32
+ //# sourceMappingURL=composition.run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composition.run.js","sourceRoot":"","sources":["../../src/composition.run.ts"],"names":[],"mappings":";;AAOA,kDA0BC;AA/BD,yCAA2C;AAC3C,6CAA6C;AAE7C;wFACwF;AACxF,SAAgB,mBAAmB,CAAC,OAAkC,EAAE,KAAe,EACnF,KAAc;IACd,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE;QAChC,IAAI,MAA6B,CAAA;QACjC,IAAI,QAAwE,CAAA;QAC5E,MAAM,QAAQ,GAAG,CAAC,KAAwC,EAA8B,EAAE,CACtF,IAAI,CAAC,KAAK,CAAC,IAAA,2BAAgB,EAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACzH,MAAM,eAAe,GAAG,CAAC,GAAY,EAAE,KAAwC,EAAE,EAAE;YAC/E,QAAQ,GAAG,EAAC,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAC,CAAA;QAC3D,CAAC,CAAA;QACD,MAAM,OAAO,GAAG,CAAC,GAAY,EAAE,KAAwC,EAAE,EAAE;YACvE,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAA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@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const composition_run_1 = require("./composition.run");
4
+ const paths = {};
5
+ const daily = { name: 'daily', type: 'relational', periodicity: 'daily' };
6
+ const monthly = { name: 'monthly', type: 'relational', periodicity: 'monthly' };
7
+ const schema = { format: 'indexed-graph-state', version: 1, nodes: [{ name: 'a', type: 'int' }, { name: 'b', type: 'string' }, { name: 'missing', type: 'int', optional: true }] };
8
+ test('executes only the requested index and detaches indexed accumulator values', async () => {
9
+ const execute = async (actualPaths, options) => {
10
+ expect(actualPaths).toEqual(paths);
11
+ const { observeIndexed, observeObject, observePreviousIndexed, observePreviousObject, ...rest } = options;
12
+ expect(rest).toEqual({ composition: 'daily', periodicity: 'daily', graph: 'custom.yaml', skip: 4, count: 1, raw: true, suppressOutput: true });
13
+ const values = [41n, 'N', undefined];
14
+ observePreviousIndexed('customer-9', values, schema);
15
+ values[0] = 42n;
16
+ values[1] = 'Y';
17
+ observeIndexed('customer-9', values, schema);
18
+ values[0] = 99n;
19
+ return { value: undefined };
20
+ };
21
+ expect(await (0, composition_run_1.compositionRunQuery)(execute, paths, 'custom.yaml')(daily, 4)).toEqual({
22
+ id: 'customer-9', index: 4, accumulatorIn: { a: '41', b: 'N', missing: null }, accumulatorOut: { a: '42', b: 'Y', missing: null }
23
+ });
24
+ });
25
+ test('supports object execution and out-of-range indices', async () => {
26
+ const execute = async (_paths, options) => {
27
+ if (options.skip === 0) {
28
+ const state = { a: 1n, b: false };
29
+ options.observePreviousObject?.(1001, state);
30
+ state.a = 0n;
31
+ options.observeObject?.(1001, state);
32
+ }
33
+ return { value: undefined };
34
+ };
35
+ const run = (0, composition_run_1.compositionRunQuery)(execute, paths);
36
+ expect(await run(daily, 0)).toEqual({ id: '1001', index: 0, accumulatorIn: { a: '1', b: false }, accumulatorOut: { a: '0', b: false } });
37
+ expect(await run(daily, 99)).toEqual(undefined);
38
+ });
39
+ test('propagates execution failures instead of treating them as missing records', async () => {
40
+ const execute = async () => ({ errors: ['Invalid packed decimal'] });
41
+ await expect((0, composition_run_1.compositionRunQuery)(execute, paths)(daily, 1)).rejects.toThrow('Invalid packed decimal');
42
+ });
43
+ test('detaches mutable window storage before and after evaluation', async () => {
44
+ const execute = async (_paths, options) => {
45
+ const window = { size: 2, count: 1, excluded: 0, hasExpired: false, values: [undefined, 5n, undefined] };
46
+ options.observePreviousObject?.('1', { window });
47
+ window.values[2] = 7n;
48
+ window.count = 2;
49
+ options.observeObject?.('1', { window });
50
+ window.values[1] = 99n;
51
+ return { value: undefined };
52
+ };
53
+ expect(await (0, composition_run_1.compositionRunQuery)(execute, paths)(daily, 0)).toEqual({ id: '1', index: 0,
54
+ accumulatorIn: { window: { size: 2, count: 1, excluded: 0, hasExpired: false, values: [null, '5', null] } },
55
+ accumulatorOut: { window: { size: 2, count: 2, excluded: 0, hasExpired: false, values: [null, '5', '7'] } } });
56
+ });
57
+ test('forwards the configured periodicity rather than inferring it from the composition name', async () => {
58
+ const calls = [];
59
+ const execute = async (_paths, options) => {
60
+ calls.push({ composition: options.composition, periodicity: options.periodicity, skip: options.skip, count: options.count });
61
+ return { value: undefined };
62
+ };
63
+ const run = (0, composition_run_1.compositionRunQuery)(execute, paths);
64
+ await run({ ...daily, name: 'snapshotA' }, 2);
65
+ await run({ ...monthly, name: 'snapshotB' }, 2);
66
+ expect(calls).toEqual([
67
+ { composition: 'snapshotA', periodicity: 'daily', skip: 2, count: 1 },
68
+ { composition: 'snapshotB', periodicity: 'monthly', skip: 2, count: 1 }
69
+ ]);
70
+ });
71
+ //# sourceMappingURL=composition.run.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composition.run.spec.js","sourceRoot":"","sources":["../../src/composition.run.spec.ts"],"names":[],"mappings":";;AAAA,uDAAqD;AAIrD,MAAM,KAAK,GAAG,EAAc,CAAA;AAC5B,MAAM,KAAK,GAAG,EAAC,IAAI,EAAE,OAAO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AA;IACD,MAAM,GAAG,GAAG,IAAA,qCAAmB,EAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC/C,MAAM,GAAG,CAAC,EAAC,GAAG,KAAK,EAAE,IAAI,EAAE,WAAW,EAAC,EAAE,CAAC,CAAC,CAAA;IAC3C,MAAM,GAAG,CAAC,EAAC,GAAG,OAAO,EAAE,IAAI,EAAE,WAAW,EAAC,EAAE,CAAC,CAAC,CAAA;IAC7C,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;QAClB,EAAC,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAC;QACnE,EAAC,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAC;KACxE,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
@@ -1,4 +1,6 @@
1
+ import type { ProjectionAuthoring } from '@cobol-ts/cursor-loader-types';
1
2
  import type { CharacteristicCatalogues } from '@cobol-ts/characteristics';
3
+ import type { GraphInspection } from '@cobol-ts/characteristics-express';
2
4
  import { type SpreadsheetExtractConfig, type SpreadsheetExtraction } from '@cobol-ts/spreadsheet';
3
5
  import type { ArtefactManifest, FileCatalogue, GenerationPolicy } from '@cobol-ts/file-catalogue';
4
6
  import type { CodegenNames, CodegenSelection, GenerationResult } from '@cobol-ts/codegen';
@@ -22,6 +24,8 @@ export interface CelInspectOptions {
22
24
  readonly graph?: string;
23
25
  readonly composition?: string;
24
26
  readonly short?: boolean;
27
+ /** Build input-field nodes for inspection only; execution remains unchanged. */
28
+ readonly display?: boolean;
25
29
  }
26
30
  /** Optional benchmark instrumentation, updated only on successful graph executions.
27
31
  * Nothing is allocated per record when this is omitted. */
@@ -37,6 +41,8 @@ export interface CelCommandOptions {
37
41
  readonly strategyOverride?: 'object' | 'indexed';
38
42
  /** Internal: expose calculated state without formatting or retaining it. */
39
43
  readonly suppressOutput?: boolean;
44
+ readonly observePreviousObject?: (entityKey: unknown, state: Acc) => void;
45
+ readonly observePreviousIndexed?: (entityKey: unknown, values: readonly IndexedValue[], schema: IndexedGraphSchema) => void;
40
46
  readonly observeObject?: (entityKey: unknown, state: Acc) => void;
41
47
  readonly observeIndexed?: (entityKey: unknown, values: readonly IndexedValue[], schema: IndexedGraphSchema) => void;
42
48
  readonly logicalName?: string;
@@ -63,14 +69,20 @@ export interface CliPaths {
63
69
  readonly accumulator: string;
64
70
  readonly accumulatorProvided?: boolean;
65
71
  }
72
+ export interface ServeSettings {
73
+ readonly mode: 'api' | 'gui' | 'all';
74
+ readonly host: string;
75
+ readonly apiUrl?: string;
76
+ }
66
77
  export interface CliServices {
67
78
  readonly output: (message: string) => void;
68
79
  readonly diagnostic: (message: string) => void;
69
80
  readonly write: (filename: string, content: string) => Promise<void>;
81
+ readonly inputProjection?: (paths: CliPaths, file: string) => Promise<ProjectionAuthoring>;
70
82
  readonly extractSpreadsheet: (config: SpreadsheetExtractConfig) => Promise<SpreadsheetExtraction>;
71
83
  readonly read: (filename: string) => Promise<string>;
72
84
  /** Optional read-only HTTP adapter, injected for tests or CLI use. */
73
- readonly serveCharacteristics?: (catalogues: CharacteristicCatalogues, port: number) => Promise<void>;
85
+ readonly serveCharacteristics?: (catalogues: CharacteristicCatalogues | undefined, port: number, inspectGraph?: GraphInspection, paths?: CliPaths, graph?: string, settings?: ServeSettings) => Promise<void>;
74
86
  readonly paths: (options: CliOptions) => Promise<CliPaths>;
75
87
  readonly list: (paths: CliPaths) => Promise<readonly string[]>;
76
88
  readonly logicalNames: (paths: CliPaths) => Promise<readonly string[]>;
@@ -5,6 +5,9 @@ exports.discoverPaths = discoverPaths;
5
5
  exports.namingFor = namingFor;
6
6
  exports.prepareIndexedComposedExecutor = prepareIndexedComposedExecutor;
7
7
  const promises_1 = require("node:fs/promises");
8
+ const composition_data_1 = require("./composition.data");
9
+ const composition_run_1 = require("./composition.run");
10
+ const gui_assets_1 = require("./gui.assets");
8
11
  const spreadsheet_1 = require("@cobol-ts/spreadsheet");
9
12
  const spreadsheet_excel_1 = require("@cobol-ts/spreadsheet-excel");
10
13
  const node_path_1 = require("node:path");
@@ -17,6 +20,7 @@ const cursor_loader_cobol_1 = require("@cobol-ts/cursor-loader-cobol");
17
20
  const cel_access_1 = require("@cobol-ts/cel-access");
18
21
  const cel_graph_runtime_1 = require("@cobol-ts/cel-graph-runtime");
19
22
  const planned_graph_1 = require("@cobol-ts/planned_graph");
23
+ const graph_utils_1 = require("@cobol-ts/graph_utils");
20
24
  const cel_json_1 = require("./cel.json");
21
25
  const cel_stats_1 = require("./cel.stats");
22
26
  const cel_entity_1 = require("./cel.entity");
@@ -170,6 +174,7 @@ function compileIndexedComposedExecutor(paths, authored, initial, stateConfigura
170
174
  trace('PREVIOUS', (0, cel_entity_1.indexedStateObject)(schema, state));
171
175
  }
172
176
  try {
177
+ options.observePreviousIndexed?.(row.key, state.values, schema);
173
178
  const startedCel = measurement ? node_perf_hooks_1.performance.now() : 0;
174
179
  session.run(row, state, variables, indices);
175
180
  if (measurement) {
@@ -244,12 +249,30 @@ exports.nodeCliServices = {
244
249
  await (0, promises_1.mkdir)((0, node_path_1.dirname)(filename), { recursive: true });
245
250
  await (0, promises_1.writeFile)(filename, content, 'utf8');
246
251
  },
252
+ async inputProjection(paths, file) {
253
+ const raw = (0, errors_1.valueOrThrow)(yaml_jsyaml_1.jsYamlParser.parse(await files_1.nodeTextFiles.read(paths.catalogue)));
254
+ const catalogue = (0, errors_1.valueOrThrow)((0, file_catalogue_1.parseFileCatalogue)(raw));
255
+ const definition = catalogue.files[file];
256
+ if (!definition)
257
+ throw new Error(`Unknown logical file ${file}`);
258
+ if (definition.type === 'cobol')
259
+ return (0, errors_1.valueOrThrow)(await (0, file_display_1.readConfiguredCobolProjection)(paths.directory, catalogue, file, files_1.nodeTextFiles));
260
+ const authoring = raw;
261
+ return (0, cursor_loader_source_1.parseConfiguredProjection)((authoring.files?.[file] ?? authoring.mappings?.[file])?.projection, file);
262
+ },
247
263
  extractSpreadsheet: config => (0, spreadsheet_1.extractSpreadsheet)(spreadsheet_excel_1.excelSpreadsheetReader, config),
248
264
  read: filename => files_1.nodeTextFiles.read(filename),
249
265
  paths: discoverPaths,
250
- async serveCharacteristics(catalogues, port) {
251
- const { createCharacteristicsApp } = await import('@cobol-ts/characteristics-express');
252
- const server = createCharacteristicsApp(catalogues).listen(port, '127.0.0.1');
266
+ async serveCharacteristics(catalogues, port, inspectGraph, paths, graph, settings = { mode: 'all', host: '127.0.0.1' }) {
267
+ const { createCharacteristicsApp, createGuiApp, installGui } = await import('@cobol-ts/characteristics-express');
268
+ const guiDirectory = settings.mode === 'api' ? undefined :
269
+ await (0, gui_assets_1.guiAssetsProvider)(__dirname, undefined, exports.nodeCliServices.diagnostic).ensureAssets();
270
+ const app = catalogues
271
+ ? createCharacteristicsApp(catalogues, inspectGraph, paths ? (0, composition_data_1.compositionDataQueries)(paths.directory, (0, composition_run_1.compositionRunQuery)(exports.nodeCliServices.celExecute, paths, graph)) : undefined)
272
+ : createGuiApp(guiDirectory, settings.apiUrl ?? 'http://127.0.0.1:3000');
273
+ if (catalogues && settings.mode === 'all')
274
+ installGui(app, guiDirectory);
275
+ const server = app.listen(port, settings.host);
253
276
  await new Promise((resolve, reject) => {
254
277
  server.once('listening', resolve);
255
278
  server.once('error', reject);
@@ -312,6 +335,45 @@ exports.nodeCliServices = {
312
335
  const canonical = (0, cel_graph_runtime_1.canonicaliseCelGraph)(loaded.value);
313
336
  if ('errors' in canonical)
314
337
  return canonical;
338
+ if (options.display) {
339
+ if (options.stage !== 'graph' && options.stage !== 'canonical' &&
340
+ options.stage !== 'sorted' && options.stage !== 'planned')
341
+ return { errors: [`No display graph for ${options.stage}`] };
342
+ // Reuse the validated computational dependency graph, including the
343
+ // previous-value ordering semantics, without touching production state.
344
+ const original = (0, cel_graph_runtime_1.planCanonicalCelGraph)(canonical.value);
345
+ if ('errors' in original)
346
+ return original;
347
+ const display = (0, graph_utils_1.createDisplayGraph)(canonical.value, {
348
+ name: node => node.metadata.name,
349
+ displayString: node => node.metadata.name,
350
+ children: original.value.graph.children,
351
+ dependencyPaths: node => node.dependsOn,
352
+ mustBeBefore: node => node.mustBeBefore ?? [],
353
+ source: path => path[0] === 'input' && path.length > 2 ? path[1] : path[0],
354
+ fieldName: path => (path[0] === 'input' && path.length > 2
355
+ ? path.slice(2) : path.slice(1)).join('.')
356
+ });
357
+ if ('errors' in display)
358
+ return display;
359
+ const stringify = (data) => JSON.stringify(data, (_key, field) => typeof field === 'bigint' ? field.toString() : field, 2);
360
+ if (options.stage === 'graph')
361
+ return { value: stringify(Object.fromEntries([
362
+ ...Object.entries(loaded.value),
363
+ ...display.value.inputs.map(node => [node.metadata.name, node])
364
+ ])) };
365
+ if (options.stage === 'canonical')
366
+ return { value: stringify(display.value.nodes) };
367
+ const sortedDisplay = (0, graph_utils_1.sortDisplayGraph)(display.value);
368
+ if ('errors' in sortedDisplay)
369
+ return sortedDisplay;
370
+ if (options.stage === 'sorted')
371
+ return { value: stringify({ generations: sortedDisplay.value }) };
372
+ const plannedDisplay = (0, graph_utils_1.planDisplayGraph)(display.value, sortedDisplay.value);
373
+ if ('errors' in plannedDisplay)
374
+ return plannedDisplay;
375
+ return { value: stringify({ generations: plannedDisplay.value }) };
376
+ }
315
377
  const shortNodes = () => canonical.value.map(node => `${node.metadata.name} <- ${node.dependsOn.map(path => path.join('.')).join(', ') || '-'}`).join('\n');
316
378
  if (options.stage === 'graph' && options.short)
317
379
  return { value: shortNodes() };
@@ -542,6 +604,7 @@ exports.nodeCliServices = {
542
604
  trace('INPUT', input);
543
605
  trace('PREVIOUS', previous);
544
606
  }
607
+ options.observePreviousObject?.(row.key, previous);
545
608
  const startedCel = measurement ? node_perf_hooks_1.performance.now() : 0;
546
609
  const result = graph.value.run(row, previous, variables, [], observe);
547
610
  if (measurement) {
@@ -569,6 +632,7 @@ exports.nodeCliServices = {
569
632
  trace('INPUT', input);
570
633
  trace('PREVIOUS', checked.value);
571
634
  }
635
+ options.observePreviousObject?.(row.key, checked.value);
572
636
  const startedCel = measurement ? node_perf_hooks_1.performance.now() : 0;
573
637
  const result = graph.value.run(row, checked.value, variables, [], observe);
574
638
  if (measurement) {