@cobol-ts/cursor-composition 0.0.0-stage → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/src/access.d.ts +5 -0
- package/dist/src/access.js +83 -0
- package/dist/src/access.js.map +1 -0
- package/dist/src/accumulator.d.ts +25 -0
- package/dist/src/accumulator.js +217 -0
- package/dist/src/accumulator.js.map +1 -0
- package/dist/src/composition.d.ts +45 -0
- package/dist/src/composition.integration.spec.d.ts +1 -0
- package/dist/src/composition.integration.spec.js +295 -0
- package/dist/src/composition.integration.spec.js.map +1 -0
- package/dist/src/composition.js +303 -0
- package/dist/src/composition.js.map +1 -0
- package/dist/src/composition.ownership.spec.d.ts +1 -0
- package/dist/src/composition.ownership.spec.js +194 -0
- package/dist/src/composition.ownership.spec.js.map +1 -0
- package/dist/src/mapping.d.ts +20 -0
- package/dist/src/mapping.js +142 -0
- package/dist/src/mapping.js.map +1 -0
- package/package.json +69 -3
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const promises_1 = require("node:fs/promises");
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const node_os_1 = require("node:os");
|
|
6
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
7
|
+
const errors_1 = require("@cobol-ts/errors");
|
|
8
|
+
const dependency_node_1 = require("@cobol-ts/dependency_node");
|
|
9
|
+
const cursor_projection_1 = require("@cobol-ts/cursor-projection");
|
|
10
|
+
const cursor_loader_json_1 = require("@cobol-ts/cursor-loader-json");
|
|
11
|
+
const cursor_loader_csv_1 = require("@cobol-ts/cursor-loader-csv");
|
|
12
|
+
const cel_access_1 = require("@cobol-ts/cel-access");
|
|
13
|
+
const cursor_file_1 = require("@cobol-ts/cursor-file");
|
|
14
|
+
const cursor_file_2 = require("@cobol-ts/cursor-file");
|
|
15
|
+
const cursor_loader_protobuf_1 = require("@cobol-ts/cursor-loader-protobuf");
|
|
16
|
+
const cel_implementation_1 = require("@cobol-ts/cel-implementation");
|
|
17
|
+
const composition_1 = require("./composition");
|
|
18
|
+
const access_1 = require("./access");
|
|
19
|
+
const accumulator_1 = require("./accumulator");
|
|
20
|
+
const mapping_1 = require("./mapping");
|
|
21
|
+
const characterProjection = (0, cursor_projection_1.defineProjection)({ id: { type: 'integer' }, name: { type: 'string' } });
|
|
22
|
+
const accountProjection = (0, cursor_projection_1.defineProjection)({ id: { type: 'integer' }, balance: { type: 'integer' },
|
|
23
|
+
transactions: { type: 'array', element: { amount: { type: 'integer' } } } });
|
|
24
|
+
const personProjection = (0, cursor_projection_1.defineProjection)({ id: { type: 'integer' }, alias: { type: 'string' } });
|
|
25
|
+
async function next(cursor) {
|
|
26
|
+
const result = cursor.take();
|
|
27
|
+
return result instanceof Promise ? await result : result;
|
|
28
|
+
}
|
|
29
|
+
async function required(cursor) {
|
|
30
|
+
const result = await next(cursor);
|
|
31
|
+
if (result === undefined)
|
|
32
|
+
throw new Error('Expected cursor row');
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
async function openJsonCursor(filename, projection) {
|
|
36
|
+
const file = await (0, promises_1.open)(filename, 'r');
|
|
37
|
+
try {
|
|
38
|
+
const cursor = await (0, cursor_file_1.openPreparedFileCursor)({ filename, fileType: 'json', projection }, file, { parsers: { json: { parser: cursor_loader_json_1.jsonParser, parserConfig: () => undefined,
|
|
39
|
+
createRecordState: cursor_loader_json_1.createJsonRecordState } }, bufferSize: 7, fillFileBuffer: cursor_file_2.fillNodeFileBuffer });
|
|
40
|
+
return { take: () => cursor.take(), async close() { try {
|
|
41
|
+
await cursor.close();
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
await file.close();
|
|
45
|
+
} } };
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
await file.close();
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function openCsvCursor(filename) {
|
|
53
|
+
const file = await (0, promises_1.open)(filename, 'r');
|
|
54
|
+
try {
|
|
55
|
+
const cursor = await (0, cursor_file_1.openPreparedFileCursor)({ filename, fileType: 'csv', projection: mappingProjection }, file, { parsers: { csv: { parser: cursor_loader_csv_1.csvParser, parserConfig: () => ({}),
|
|
56
|
+
createRecordState: cursor_loader_csv_1.createCsvRecordState } }, bufferSize: 7, fillFileBuffer: cursor_file_2.fillNodeFileBuffer });
|
|
57
|
+
return { take: () => cursor.take(), async close() { try {
|
|
58
|
+
await cursor.close();
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
await file.close();
|
|
62
|
+
} } };
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
await file.close();
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Real JSONL through the existing physical cursor, not fabricated projection leases. */
|
|
70
|
+
function fileSource(filename, name, cardinality, projection, effectiveKey) {
|
|
71
|
+
const authoring = projection;
|
|
72
|
+
return {
|
|
73
|
+
name, cardinality, projection: authoring,
|
|
74
|
+
access: (0, cel_access_1.jsonAccessCompiler)(authoring),
|
|
75
|
+
key: (lease) => effectiveKey(lease.representation),
|
|
76
|
+
openCursor: () => openJsonCursor(filename, projection),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async function writeJsonl(filename, rows) {
|
|
80
|
+
await (0, promises_1.writeFile)(filename, rows.map(row => JSON.stringify(row)).join('\n') + '\n');
|
|
81
|
+
}
|
|
82
|
+
const mappingProjection = (0, cursor_projection_1.defineProjection)({ id: { type: 'integer' }, customerId: { type: 'integer' } });
|
|
83
|
+
function csvMapping(filename, name) {
|
|
84
|
+
return {
|
|
85
|
+
name,
|
|
86
|
+
key: row => BigInt(row.result.id()),
|
|
87
|
+
foreign: row => BigInt(row.result.customerId()),
|
|
88
|
+
openCursor: () => openCsvCursor(filename),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const authoring = {
|
|
92
|
+
total: { type: 'cel', cel: 'prev.total', metadata: { type: 'number', celResultType: 'int' } },
|
|
93
|
+
note: { type: 'cel', cel: '"state"', metadata: { type: 'string', celResultType: 'string' } }
|
|
94
|
+
};
|
|
95
|
+
describe('real JSONL mapped composition + self-describing Protobuf accumulator + compiled CEL', () => {
|
|
96
|
+
test('three characters: scalar, indexed, map/filter/reduce, nested arrays and missing pooled state', async () => {
|
|
97
|
+
const folder = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-composed-'));
|
|
98
|
+
try {
|
|
99
|
+
const customers = (0, node_path_1.join)(folder, 'characters.jsonl');
|
|
100
|
+
const accounts = (0, node_path_1.join)(folder, 'accounts.jsonl');
|
|
101
|
+
const people = (0, node_path_1.join)(folder, 'people.jsonl');
|
|
102
|
+
const accountMapPath = (0, node_path_1.join)(folder, 'accountCustomerMap.csv');
|
|
103
|
+
const personMapPath = (0, node_path_1.join)(folder, 'personCustomerMap.csv');
|
|
104
|
+
const accumulatorFile = (0, node_path_1.join)(folder, 'previous.pb');
|
|
105
|
+
await writeJsonl(customers, [
|
|
106
|
+
{ id: 1, name: 'Aria' }, { id: 2, name: 'Bram' }, { id: 3, name: 'Cora' }
|
|
107
|
+
]);
|
|
108
|
+
await writeJsonl(accounts, [
|
|
109
|
+
{ id: 10, balance: 12, transactions: [{ amount: 3 }, { amount: 5 }] },
|
|
110
|
+
{ id: 11, balance: 25, transactions: [{ amount: 7 }] },
|
|
111
|
+
{ id: 12, balance: 8, transactions: [] }
|
|
112
|
+
]);
|
|
113
|
+
await writeJsonl(people, [
|
|
114
|
+
{ id: 101, alias: 'A' }, { id: 102, alias: 'B' }, { id: 103, alias: 'C' }
|
|
115
|
+
]);
|
|
116
|
+
await (0, promises_1.writeFile)(accountMapPath, 'id,customerId\n10,1\n11,1\n12,3\n');
|
|
117
|
+
await (0, promises_1.writeFile)(personMapPath, 'id,customerId\n101,1\n102,2\n103,3\n');
|
|
118
|
+
const schema = (0, cursor_loader_protobuf_1.accumulatorSchemaFromGraph)((0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)(authoring)));
|
|
119
|
+
await (0, cursor_loader_protobuf_1.writeAccumulatorFile)(accumulatorFile, schema, [
|
|
120
|
+
(0, protobuf_1.create)(schema.message, { customerId: 1n, total: 5n, note: 'old one' }),
|
|
121
|
+
(0, protobuf_1.create)(schema.message, { customerId: 3n, total: 9n, note: 'old three' })
|
|
122
|
+
]);
|
|
123
|
+
const sources = [
|
|
124
|
+
fileSource(customers, 'characters', 'one', characterProjection, r => BigInt(r.id)),
|
|
125
|
+
(0, mapping_1.viaMapping)(fileSource(accounts, 'accounts', 'manyOptional', accountProjection, r => BigInt(r.id)), csvMapping(accountMapPath, 'accountCustomerMap')),
|
|
126
|
+
(0, mapping_1.viaMapping)(fileSource(people, 'people', 'manyOptional', personProjection, r => BigInt(r.id)), csvMapping(personMapPath, 'personCustomerMap'))
|
|
127
|
+
];
|
|
128
|
+
const composition = (0, composition_1.createComposition)(sources, 'characters');
|
|
129
|
+
const access = (0, access_1.compositeAccessCompiler)(sources);
|
|
130
|
+
const expr = (source) => (0, errors_1.valueOrThrow)((0, cel_implementation_1.compileCelExpression)(source, composition.projection, access, {}, { now: { total: 'int' } }));
|
|
131
|
+
const sum = expr('input.accounts.map(a, a.balance).sum()').createRunner?.();
|
|
132
|
+
const filtered = expr('input.accounts.filter(a, a.balance > 15).map(a, a.balance).sum()').createRunner?.();
|
|
133
|
+
const reduced = expr('input.accounts.reduce(n, a, 0, n + a.balance)').createRunner?.();
|
|
134
|
+
const nested = expr('input.accounts.map(a, a.transactions.map(t, t.amount).sum()).sum()').createRunner?.();
|
|
135
|
+
const indexed = expr('input.accounts[1].balance').createRunner?.();
|
|
136
|
+
const indexedNested = expr('input.accounts[1].transactions.map(t, t.amount).sum()').createRunner?.();
|
|
137
|
+
const running = expr('now.total + input.accounts.map(a, a.balance).sum()').createRunner?.();
|
|
138
|
+
const count = expr('input.people.map(p, p.id).sum()').createRunner?.();
|
|
139
|
+
if (!sum || !filtered || !reduced || !nested || !indexed || !indexedNested || !running || !count)
|
|
140
|
+
throw new Error('Missing compiled CEL runner');
|
|
141
|
+
const entity = (0, accumulator_1.bindAccumulator)(composition, schema, accumulatorFile, { experiment: 'demo' }, (data) => data.customerId);
|
|
142
|
+
const scan = await entity.openCursor();
|
|
143
|
+
const first = await required(scan), second = await required(scan);
|
|
144
|
+
const evaluate = (row, run) => run(row.representation, []);
|
|
145
|
+
// Advancing does not invalidate either borrowed row or accumulator.
|
|
146
|
+
expect(first.result.input.characters.name()).toEqual('Aria');
|
|
147
|
+
expect(first.result.input.accounts[1].balance()).toEqual(25);
|
|
148
|
+
expect(first.result.input.accounts.length).toEqual(2);
|
|
149
|
+
expect(evaluate(first, sum)).toEqual(37n);
|
|
150
|
+
expect(evaluate(first, filtered)).toEqual(25n);
|
|
151
|
+
expect(evaluate(first, reduced)).toEqual(37n);
|
|
152
|
+
expect(evaluate(first, nested)).toEqual(15n);
|
|
153
|
+
expect(evaluate(first, indexed)).toEqual(25n);
|
|
154
|
+
expect(evaluate(first, indexedNested)).toEqual(7n);
|
|
155
|
+
expect(evaluate(first, running)).toEqual(42n);
|
|
156
|
+
expect(evaluate(first, count)).toEqual(101n);
|
|
157
|
+
expect(second.result.input.characters.name()).toEqual('Bram');
|
|
158
|
+
expect(second.result.input.accounts.length).toEqual(0);
|
|
159
|
+
expect(second.result.acc.total).toEqual(0n);
|
|
160
|
+
expect(second.result.acc.note).toEqual('');
|
|
161
|
+
expect(evaluate(second, sum)).toEqual(0n);
|
|
162
|
+
const third = await required(scan);
|
|
163
|
+
expect(third.result.input.characters.name()).toEqual('Cora');
|
|
164
|
+
expect(evaluate(third, running)).toEqual(17n);
|
|
165
|
+
expect(first.result.input.accounts[0].balance()).toEqual(12);
|
|
166
|
+
expect(first.result.acc === second.result.acc).toEqual(false);
|
|
167
|
+
first.close();
|
|
168
|
+
second.close();
|
|
169
|
+
third.close();
|
|
170
|
+
expect(await next(scan)).toEqual(undefined);
|
|
171
|
+
await scan.close();
|
|
172
|
+
expect([first.closed, second.closed, third.closed]).toEqual([true, true, true]);
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
await (0, promises_1.rm)(folder, { recursive: true, force: true });
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
test('rejects unresolved CEL slots and cannot silently process an unordered effective-key stream', async () => {
|
|
179
|
+
const folder = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-composed-order-'));
|
|
180
|
+
try {
|
|
181
|
+
const filename = (0, node_path_1.join)(folder, 'accounts.jsonl');
|
|
182
|
+
await writeJsonl(filename, [{ id: 10, balance: 1, transactions: [] }, { id: 11, balance: 2, transactions: [] }]);
|
|
183
|
+
const mappedSource = fileSource(filename, 'accounts', 'one', accountProjection, r => BigInt(r.id));
|
|
184
|
+
const source = (0, mapping_1.viaMapping)(mappedSource, {
|
|
185
|
+
name: 'accountCustomerMap',
|
|
186
|
+
key: row => row.result.id,
|
|
187
|
+
foreign: row => row.result.customerId,
|
|
188
|
+
async openCursor() {
|
|
189
|
+
const rows = [{ id: 10n, customerId: 2n }, { id: 11n, customerId: 1n }];
|
|
190
|
+
let i = 0;
|
|
191
|
+
return { take() {
|
|
192
|
+
if (i >= rows.length)
|
|
193
|
+
return undefined;
|
|
194
|
+
const row = rows[i++];
|
|
195
|
+
return { result: row, representation: row, close() { } };
|
|
196
|
+
}, async close() { } };
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
const compiler = (0, access_1.compositeAccessCompiler)([source]);
|
|
200
|
+
expect((0, errors_1.errorsOrThrow)(compiler.compileScalar(['unknown', 'balance']))).toEqual(['Unknown composite slot unknown']);
|
|
201
|
+
const composition = (0, composition_1.createComposition)([source], 'accounts');
|
|
202
|
+
let error = '';
|
|
203
|
+
try {
|
|
204
|
+
await composition.scan(() => { });
|
|
205
|
+
}
|
|
206
|
+
catch (e) {
|
|
207
|
+
error = e instanceof Error ? e.message : String(e);
|
|
208
|
+
}
|
|
209
|
+
expect(error).toEqual('Source accounts is not sorted by its effective entity key');
|
|
210
|
+
}
|
|
211
|
+
finally {
|
|
212
|
+
await (0, promises_1.rm)(folder, { recursive: true, force: true });
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
test('reuses the composite projection and wrapper after close, without rebuilding accessors', async () => {
|
|
216
|
+
const folder = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-composed-pool-'));
|
|
217
|
+
try {
|
|
218
|
+
const filename = (0, node_path_1.join)(folder, 'characters.jsonl');
|
|
219
|
+
await writeJsonl(filename, [{ id: 1, name: 'Aria' }, { id: 2, name: 'Bram' }]);
|
|
220
|
+
const source = fileSource(filename, 'characters', 'one', characterProjection, r => BigInt(r.id));
|
|
221
|
+
const composition = (0, composition_1.createComposition)([source], 'characters');
|
|
222
|
+
const scan = await composition.openCursor();
|
|
223
|
+
const first = await required(scan);
|
|
224
|
+
const projection = first.result;
|
|
225
|
+
expect(projection.characters.name()).toEqual('Aria');
|
|
226
|
+
first.close();
|
|
227
|
+
const second = await required(scan);
|
|
228
|
+
expect(second === first).toEqual(true);
|
|
229
|
+
expect(second.result === projection).toEqual(true);
|
|
230
|
+
expect(second.result.characters.name()).toEqual('Bram');
|
|
231
|
+
second.close();
|
|
232
|
+
expect(await next(scan)).toEqual(undefined);
|
|
233
|
+
await scan.close();
|
|
234
|
+
}
|
|
235
|
+
finally {
|
|
236
|
+
await (0, promises_1.rm)(folder, { recursive: true, force: true });
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
test('an absent optional accumulator file supplies pooled default state', async () => {
|
|
240
|
+
const folder = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-composed-absent-'));
|
|
241
|
+
try {
|
|
242
|
+
const filename = (0, node_path_1.join)(folder, 'characters.jsonl');
|
|
243
|
+
await writeJsonl(filename, [{ id: 1, name: 'Aria' }, { id: 2, name: 'Bram' }]);
|
|
244
|
+
const source = fileSource(filename, 'characters', 'one', characterProjection, r => BigInt(r.id));
|
|
245
|
+
const schema = (0, cursor_loader_protobuf_1.accumulatorSchemaFromGraph)((0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)(authoring)));
|
|
246
|
+
const composition = (0, composition_1.createComposition)([source], 'characters');
|
|
247
|
+
const accumulator = (0, accumulator_1.bindAccumulator)(composition, schema, (0, node_path_1.join)(folder, 'not-present.pb'), {}, data => data.customerId);
|
|
248
|
+
const scan = await accumulator.openCursor();
|
|
249
|
+
const first = await required(scan);
|
|
250
|
+
const message = first.result.acc;
|
|
251
|
+
const data = message;
|
|
252
|
+
expect([data.customerId, data.total, data.note]).toEqual([1n, 0n, '']);
|
|
253
|
+
first.close();
|
|
254
|
+
const second = await required(scan);
|
|
255
|
+
expect(second.result.acc === message).toEqual(true);
|
|
256
|
+
const nextData = second.result.acc;
|
|
257
|
+
expect([nextData.customerId, nextData.total, nextData.note]).toEqual([2n, 0n, '']);
|
|
258
|
+
second.close();
|
|
259
|
+
expect(await next(scan)).toEqual(undefined);
|
|
260
|
+
await scan.close();
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
await (0, promises_1.rm)(folder, { recursive: true, force: true });
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
test('an optional singular child is undefined when unmatched; unsafe CEL dereference is rejected', async () => {
|
|
267
|
+
const folder = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-composed-optional-'));
|
|
268
|
+
try {
|
|
269
|
+
const names = (0, node_path_1.join)(folder, 'names.jsonl');
|
|
270
|
+
const people = (0, node_path_1.join)(folder, 'people.jsonl');
|
|
271
|
+
await writeJsonl(names, [{ id: 1, name: 'Aria' }, { id: 2, name: 'Bram' }]);
|
|
272
|
+
await writeJsonl(people, [{ id: 1, alias: 'A' }]);
|
|
273
|
+
const sources = [
|
|
274
|
+
fileSource(names, 'characters', 'one', characterProjection, r => BigInt(r.id)),
|
|
275
|
+
fileSource(people, 'person', 'optional', personProjection, r => BigInt(r.id))
|
|
276
|
+
];
|
|
277
|
+
const composition = (0, composition_1.createComposition)(sources, 'characters');
|
|
278
|
+
const compilation = (0, access_1.compositeAccessCompiler)(sources);
|
|
279
|
+
expect((0, errors_1.errorsOrThrow)(compilation.compileScalar(['person', 'alias'])))
|
|
280
|
+
.toEqual(['Optional source person requires presence semantics']);
|
|
281
|
+
const scan = await composition.openCursor();
|
|
282
|
+
const first = await required(scan), second = await required(scan);
|
|
283
|
+
expect(first.result.person?.alias()).toEqual('A');
|
|
284
|
+
expect(second.result.person).toEqual(undefined);
|
|
285
|
+
first.close();
|
|
286
|
+
second.close();
|
|
287
|
+
expect(await next(scan)).toEqual(undefined);
|
|
288
|
+
await scan.close();
|
|
289
|
+
}
|
|
290
|
+
finally {
|
|
291
|
+
await (0, promises_1.rm)(folder, { recursive: true, force: true });
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
//# sourceMappingURL=composition.integration.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composition.integration.spec.js","sourceRoot":"","sources":["../../src/composition.integration.spec.ts"],"names":[],"mappings":";;AAAA,+CAA2D;AAC3D,yCAA+B;AAC/B,qCAA+B;AAC/B,iDAA0C;AAC1C,6CAA4D;AAC5D,+DAAoD;AACpD,mEAA6D;AAG7D,qEAA6F;AAC7F,mEAAkG;AAClG,qDAAwD;AACxD,uDAAoH;AACpH,uDAAyD;AACzD,6EAAiG;AACjG,qEAAkE;AAClE,+CAAqF;AACrF,qCAAiD;AACjD,+CAA8C;AAC9C,uCAA0D;AAQ1D,MAAM,mBAAmB,GAAC,IAAA,oCAAgB,EAAY,EAAC,EA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,CAAC;AAEP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createComposition = createComposition;
|
|
4
|
+
const arrays_1 = require("@cobol-ts/arrays");
|
|
5
|
+
/** No field name resolution, getter creation, array creation or path parsing during a scan. */
|
|
6
|
+
function createComposition(sources, masterName) {
|
|
7
|
+
if (sources.length === 0)
|
|
8
|
+
throw new Error('Composition has no sources');
|
|
9
|
+
const names = new Set();
|
|
10
|
+
let master = -1;
|
|
11
|
+
const authoring = {};
|
|
12
|
+
for (let index = 0; index < sources.length; index++) {
|
|
13
|
+
const source = sources[index];
|
|
14
|
+
if (names.has(source.name))
|
|
15
|
+
throw new Error(`Duplicate source ${source.name}`);
|
|
16
|
+
names.add(source.name);
|
|
17
|
+
if (source.name === masterName)
|
|
18
|
+
master = index;
|
|
19
|
+
authoring[source.name] = source.cardinality === 'many' || source.cardinality === 'manyOptional'
|
|
20
|
+
? { type: 'array', element: source.projection }
|
|
21
|
+
: { type: 'object', fields: source.projection };
|
|
22
|
+
}
|
|
23
|
+
if (master < 0)
|
|
24
|
+
throw new Error(`Unknown master source ${masterName}`);
|
|
25
|
+
if (sources[master].cardinality !== 'one')
|
|
26
|
+
throw new Error('Master cardinality must be one');
|
|
27
|
+
const available = [];
|
|
28
|
+
const compare = (a, b) => {
|
|
29
|
+
if (typeof a !== typeof b)
|
|
30
|
+
throw new Error(`Incompatible entity-key types: ${typeof a} and ${typeof b}`);
|
|
31
|
+
if (typeof a === 'number' && (!Number.isFinite(a) || !Number.isFinite(b)))
|
|
32
|
+
throw new Error('Entity key must be finite');
|
|
33
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
34
|
+
};
|
|
35
|
+
function make() {
|
|
36
|
+
const slots = sources.map(() => ({ values: [], size: 0 }));
|
|
37
|
+
const item = { slots, key: 0, active: false, acc: undefined, variables: undefined };
|
|
38
|
+
const view = {};
|
|
39
|
+
for (let i = 0; i < sources.length; i++) {
|
|
40
|
+
const slot = i, name = sources[i].name;
|
|
41
|
+
if (sources[i].cardinality === 'many' || sources[i].cardinality === 'manyOptional') {
|
|
42
|
+
const array = (0, arrays_1.createProjectedArray)({
|
|
43
|
+
length: () => item.active ? slots[slot].size : 0,
|
|
44
|
+
element: (index) => item.entry(slot, index).result
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(view, name, { enumerable: true, get() {
|
|
47
|
+
if (!item.active)
|
|
48
|
+
throw new Error('Composite is closed');
|
|
49
|
+
return array;
|
|
50
|
+
} });
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
Object.defineProperty(view, name, { enumerable: true, get() {
|
|
54
|
+
if (!item.active)
|
|
55
|
+
throw new Error('Composite is closed');
|
|
56
|
+
return slots[slot].size === 0 ? undefined : item.entry(slot, 0).result;
|
|
57
|
+
} });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
Object.defineProperties(item, {
|
|
61
|
+
view: { value: view },
|
|
62
|
+
result: { get() { if (!item.active)
|
|
63
|
+
throw new Error('Composite is closed'); return view; } },
|
|
64
|
+
representation: { get() { if (!item.active)
|
|
65
|
+
throw new Error('Composite is closed'); return item; } },
|
|
66
|
+
closed: { get() { return !item.active; } }
|
|
67
|
+
});
|
|
68
|
+
item.entry = (slot, index) => {
|
|
69
|
+
if (!item.active)
|
|
70
|
+
throw new Error('Composite is closed');
|
|
71
|
+
const group = slots[slot];
|
|
72
|
+
if (group === undefined || index < 0 || index >= group.size || !Number.isSafeInteger(index))
|
|
73
|
+
throw new RangeError(`Invalid composite occurrence ${slot}[${index}]`);
|
|
74
|
+
return group.values[index];
|
|
75
|
+
};
|
|
76
|
+
item.count = (slot) => {
|
|
77
|
+
if (!item.active)
|
|
78
|
+
throw new Error('Composite is closed');
|
|
79
|
+
return slots[slot].size;
|
|
80
|
+
};
|
|
81
|
+
item.close = () => {
|
|
82
|
+
if (!item.active)
|
|
83
|
+
throw new Error('Composite already closed');
|
|
84
|
+
item.active = false;
|
|
85
|
+
item.acc = undefined;
|
|
86
|
+
item.variables = undefined;
|
|
87
|
+
let failure;
|
|
88
|
+
for (let slot = 0; slot < slots.length; slot++) {
|
|
89
|
+
const group = slots[slot];
|
|
90
|
+
for (let i = 0; i < group.size; i++) {
|
|
91
|
+
const child = group.values[i];
|
|
92
|
+
group.values[i] = undefined;
|
|
93
|
+
try {
|
|
94
|
+
child.close();
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
failure ??= e;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
group.size = 0;
|
|
101
|
+
}
|
|
102
|
+
available.push(item);
|
|
103
|
+
if (failure !== undefined)
|
|
104
|
+
throw failure;
|
|
105
|
+
};
|
|
106
|
+
return item;
|
|
107
|
+
}
|
|
108
|
+
function acquire(key) {
|
|
109
|
+
const item = available.pop() ?? make();
|
|
110
|
+
item.key = key;
|
|
111
|
+
item.active = true;
|
|
112
|
+
return item;
|
|
113
|
+
}
|
|
114
|
+
function push(item, index, lease) {
|
|
115
|
+
const group = item.slots[index];
|
|
116
|
+
group.values[group.size++] = lease;
|
|
117
|
+
}
|
|
118
|
+
/** Resumable sorted merge. There are no async generators or per-record
|
|
119
|
+
* iterator result promises. Every source owns one leased lookahead. */
|
|
120
|
+
async function openCursor() {
|
|
121
|
+
const cursors = [];
|
|
122
|
+
try {
|
|
123
|
+
for (let i = 0; i < sources.length; i++)
|
|
124
|
+
cursors.push(await sources[i].openCursor());
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
for (let i = 0; i < cursors.length; i++)
|
|
128
|
+
await cursors[i].close();
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
const lookahead = new Array(sources.length);
|
|
132
|
+
const previous = new Array(sources.length);
|
|
133
|
+
const keys = new Array(sources.length);
|
|
134
|
+
let primed = false, closed = false, ended = false;
|
|
135
|
+
function accept(index, lease) {
|
|
136
|
+
if (lease === undefined) {
|
|
137
|
+
lookahead[index] = undefined;
|
|
138
|
+
keys[index] = undefined;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
const key = sources[index].key(lease);
|
|
143
|
+
const last = previous[index];
|
|
144
|
+
if (last !== undefined && compare(key, last) < 0)
|
|
145
|
+
throw new Error(`Source ${sources[index].name} is not sorted by its effective entity key`);
|
|
146
|
+
previous[index] = key;
|
|
147
|
+
lookahead[index] = lease;
|
|
148
|
+
keys[index] = key;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
lease.close();
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function advance(index) {
|
|
156
|
+
const row = cursors[index].take();
|
|
157
|
+
if (row instanceof Promise)
|
|
158
|
+
return row.then(lease => { accept(index, lease); });
|
|
159
|
+
accept(index, row);
|
|
160
|
+
}
|
|
161
|
+
function prime(index) {
|
|
162
|
+
for (let i = index; i < sources.length; i++) {
|
|
163
|
+
const refill = advance(i);
|
|
164
|
+
if (refill instanceof Promise)
|
|
165
|
+
return refill.then(() => prime(i + 1));
|
|
166
|
+
}
|
|
167
|
+
primed = true;
|
|
168
|
+
}
|
|
169
|
+
// A composition is assembled one entity at a time. Reuse the same
|
|
170
|
+
// continuation across rows rather than allocating a closure per entity.
|
|
171
|
+
let assembling;
|
|
172
|
+
let assemblyKey = 0;
|
|
173
|
+
let assemblyIndex = 0;
|
|
174
|
+
function collect() {
|
|
175
|
+
const item = assembling;
|
|
176
|
+
const key = assemblyKey;
|
|
177
|
+
while (assemblyIndex < sources.length) {
|
|
178
|
+
const i = assemblyIndex;
|
|
179
|
+
if (lookahead[i] !== undefined && compare(keys[i], key) < 0)
|
|
180
|
+
throw new Error(`Unmatched record in source ${sources[i].name} before entity ${String(key)}`);
|
|
181
|
+
if ((sources[i].cardinality === 'one' || sources[i].cardinality === 'optional') && item.count(i) > 0) {
|
|
182
|
+
if (lookahead[i] !== undefined && compare(keys[i], key) === 0)
|
|
183
|
+
throw new Error(`Duplicate ${sources[i].name} record for entity ${String(key)}`);
|
|
184
|
+
assemblyIndex++;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
while (lookahead[i] !== undefined && compare(keys[i], key) === 0) {
|
|
188
|
+
const lease = lookahead[i];
|
|
189
|
+
lookahead[i] = undefined;
|
|
190
|
+
keys[i] = undefined;
|
|
191
|
+
push(item, i, lease);
|
|
192
|
+
const refill = advance(i);
|
|
193
|
+
if (refill instanceof Promise)
|
|
194
|
+
return refill.then(collect);
|
|
195
|
+
if (sources[i].cardinality === 'one' || sources[i].cardinality === 'optional') {
|
|
196
|
+
if (lookahead[i] !== undefined && compare(keys[i], key) === 0)
|
|
197
|
+
throw new Error(`Duplicate ${sources[i].name} record for entity ${String(key)}`);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if ((sources[i].cardinality === 'one' || sources[i].cardinality === 'optional')
|
|
202
|
+
&& item.count(i) !== 0 && lookahead[i] !== undefined && compare(keys[i], key) === 0)
|
|
203
|
+
throw new Error(`Duplicate ${sources[i].name} record for entity ${String(key)}`);
|
|
204
|
+
const required = sources[i].cardinality === 'one' || sources[i].cardinality === 'many';
|
|
205
|
+
if (required && item.count(i) === 0)
|
|
206
|
+
throw new Error(`Missing required ${sources[i].name} for entity ${String(key)}`);
|
|
207
|
+
assemblyIndex++;
|
|
208
|
+
}
|
|
209
|
+
assembling = undefined;
|
|
210
|
+
return item;
|
|
211
|
+
}
|
|
212
|
+
function fail(error) {
|
|
213
|
+
const item = assembling;
|
|
214
|
+
assembling = undefined;
|
|
215
|
+
if (item?.active)
|
|
216
|
+
item.close();
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
function compose() {
|
|
220
|
+
if (lookahead[master] === undefined) {
|
|
221
|
+
for (let i = 0; i < sources.length; i++)
|
|
222
|
+
if (lookahead[i] !== undefined)
|
|
223
|
+
throw new Error(`Unmatched trailing record in ${sources[i].name}`);
|
|
224
|
+
ended = true;
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
assemblyKey = keys[master];
|
|
228
|
+
assembling = acquire(assemblyKey);
|
|
229
|
+
assemblyIndex = 0;
|
|
230
|
+
try {
|
|
231
|
+
const result = collect();
|
|
232
|
+
return result instanceof Promise ? result.catch(fail) : result;
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
return fail(error);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function take() {
|
|
239
|
+
if (closed)
|
|
240
|
+
throw new Error('Composite cursor already closed');
|
|
241
|
+
if (ended)
|
|
242
|
+
return undefined;
|
|
243
|
+
if (!primed) {
|
|
244
|
+
const initialization = prime(0);
|
|
245
|
+
if (initialization instanceof Promise)
|
|
246
|
+
return initialization.then(compose);
|
|
247
|
+
}
|
|
248
|
+
return compose();
|
|
249
|
+
}
|
|
250
|
+
async function close() {
|
|
251
|
+
if (closed)
|
|
252
|
+
return;
|
|
253
|
+
closed = true;
|
|
254
|
+
let failure;
|
|
255
|
+
for (let i = 0; i < cursors.length; i++) {
|
|
256
|
+
const lease = lookahead[i];
|
|
257
|
+
lookahead[i] = undefined;
|
|
258
|
+
try {
|
|
259
|
+
lease?.close();
|
|
260
|
+
}
|
|
261
|
+
catch (e) {
|
|
262
|
+
failure ??= e;
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
await cursors[i].close();
|
|
266
|
+
}
|
|
267
|
+
catch (e) {
|
|
268
|
+
failure ??= e;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (failure !== undefined)
|
|
272
|
+
throw failure;
|
|
273
|
+
}
|
|
274
|
+
return { take, close };
|
|
275
|
+
}
|
|
276
|
+
async function scan(visitor) {
|
|
277
|
+
const cursor = await openCursor();
|
|
278
|
+
try {
|
|
279
|
+
while (true) {
|
|
280
|
+
const next = cursor.take();
|
|
281
|
+
const lease = next instanceof Promise ? await next : next;
|
|
282
|
+
if (lease === undefined)
|
|
283
|
+
break;
|
|
284
|
+
let decision;
|
|
285
|
+
try {
|
|
286
|
+
decision = visitor(lease.representation);
|
|
287
|
+
if (decision !== null && typeof decision === 'object' && typeof decision.then === 'function')
|
|
288
|
+
throw new TypeError('Composite visitor must be synchronous');
|
|
289
|
+
}
|
|
290
|
+
finally {
|
|
291
|
+
lease.close();
|
|
292
|
+
}
|
|
293
|
+
if (decision === false)
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
await cursor.close();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return { sources, projection: authoring, scan, openCursor };
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=composition.js.map
|