@cobol-ts/cursor-loader-indexed-graph-state 0.0.0-stage → 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.md +452 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/src/indexed.state.codec.d.ts +16 -0
- package/dist/src/indexed.state.codec.js +427 -0
- package/dist/src/indexed.state.codec.js.map +1 -0
- package/dist/src/indexed.state.configuration.d.ts +12 -0
- package/dist/src/indexed.state.configuration.js +45 -0
- package/dist/src/indexed.state.configuration.js.map +1 -0
- package/dist/src/indexed.state.exports.spec.d.ts +1 -0
- package/dist/src/indexed.state.exports.spec.js +23 -0
- package/dist/src/indexed.state.exports.spec.js.map +1 -0
- package/dist/src/indexed.state.file.d.ts +20 -0
- package/dist/src/indexed.state.file.js +147 -0
- package/dist/src/indexed.state.file.js.map +1 -0
- package/dist/src/indexed.state.file.spec.d.ts +1 -0
- package/dist/src/indexed.state.file.spec.js +345 -0
- package/dist/src/indexed.state.file.spec.js.map +1 -0
- package/dist/src/indexed.state.join.d.ts +36 -0
- package/dist/src/indexed.state.join.js +222 -0
- package/dist/src/indexed.state.join.js.map +1 -0
- package/dist/src/indexed.state.join.spec.d.ts +1 -0
- package/dist/src/indexed.state.join.spec.js +270 -0
- package/dist/src/indexed.state.join.spec.js.map +1 -0
- package/dist/src/indexed.state.number.spec.d.ts +1 -0
- package/dist/src/indexed.state.number.spec.js +102 -0
- package/dist/src/indexed.state.number.spec.js.map +1 -0
- package/dist/src/indexed.state.optional.spec.d.ts +1 -0
- package/dist/src/indexed.state.optional.spec.js +63 -0
- package/dist/src/indexed.state.optional.spec.js.map +1 -0
- package/dist/src/indexed.state.parser.d.ts +34 -0
- package/dist/src/indexed.state.parser.js +237 -0
- package/dist/src/indexed.state.parser.js.map +1 -0
- package/dist/src/indexed.state.rolling.spec.d.ts +1 -0
- package/dist/src/indexed.state.rolling.spec.js +176 -0
- package/dist/src/indexed.state.rolling.spec.js.map +1 -0
- package/dist/src/indexed.state.schema.d.ts +48 -0
- package/dist/src/indexed.state.schema.js +118 -0
- package/dist/src/indexed.state.schema.js.map +1 -0
- package/package.json +64 -3
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeIndexedGraphSchema = encodeIndexedGraphSchema;
|
|
4
|
+
exports.decodeIndexedGraphSchema = decodeIndexedGraphSchema;
|
|
5
|
+
exports.prepareIndexedGraphCodec = prepareIndexedGraphCodec;
|
|
6
|
+
const ring_buffer_1 = require("@cobol-ts/ring-buffer");
|
|
7
|
+
const indexed_state_schema_1 = require("./indexed.state.schema");
|
|
8
|
+
const encoder = new TextEncoder();
|
|
9
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
10
|
+
const MAGIC_V1 = new Uint8Array([73, 71, 83, 49]); // IGS1: fixed-width scalars
|
|
11
|
+
const MAGIC_V2 = new Uint8Array([73, 71, 83, 50]); // IGS2: explicit optional scalar presence
|
|
12
|
+
const MIN_INT = -(1n << 63n), MAX_INT = (1n << 63n) - 1n, MAX_UINT = (1n << 64n) - 1n;
|
|
13
|
+
function utf8Length(text) {
|
|
14
|
+
let length = 0;
|
|
15
|
+
for (let i = 0; i < text.length; i++) {
|
|
16
|
+
const c = text.charCodeAt(i);
|
|
17
|
+
if (c < 0x80)
|
|
18
|
+
length++;
|
|
19
|
+
else if (c < 0x800)
|
|
20
|
+
length += 2;
|
|
21
|
+
else if (c >= 0xd800 && c <= 0xdbff && i + 1 < text.length) {
|
|
22
|
+
const next = text.charCodeAt(i + 1);
|
|
23
|
+
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
24
|
+
length += 4;
|
|
25
|
+
i++;
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
length += 3;
|
|
29
|
+
}
|
|
30
|
+
else
|
|
31
|
+
length += 3;
|
|
32
|
+
}
|
|
33
|
+
return length;
|
|
34
|
+
}
|
|
35
|
+
/** Persist physical field type and temporal layout, but not working JS representation. */
|
|
36
|
+
function encodeIndexedGraphSchema(schema) {
|
|
37
|
+
const checked = (0, indexed_state_schema_1.validateIndexedGraphSchema)(schema);
|
|
38
|
+
const persisted = { ...checked, nodes: checked.nodes.map(field => field.type === 'rolling-window' ?
|
|
39
|
+
{ name: field.name, type: field.type, element: field.element, periodicity: field.periodicity, size: field.size } :
|
|
40
|
+
{ name: field.name, type: field.type, ...(field.optional ? { optional: true } : {}) }) };
|
|
41
|
+
const body = encoder.encode(JSON.stringify(persisted));
|
|
42
|
+
const magic = checked.version === 2 ? MAGIC_V2 : MAGIC_V1;
|
|
43
|
+
const result = new Uint8Array(magic.length + body.length);
|
|
44
|
+
result.set(magic);
|
|
45
|
+
result.set(body, magic.length);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function decodeIndexedGraphSchema(bytes) {
|
|
49
|
+
const v1 = bytes.length >= MAGIC_V1.length && MAGIC_V1.every((value, i) => bytes[i] === value);
|
|
50
|
+
const v2 = bytes.length >= MAGIC_V2.length && MAGIC_V2.every((value, i) => bytes[i] === value);
|
|
51
|
+
if (!v1 && !v2)
|
|
52
|
+
throw new Error('Invalid indexed graph schema magic');
|
|
53
|
+
let object;
|
|
54
|
+
try {
|
|
55
|
+
object = JSON.parse(decoder.decode(bytes.subarray(MAGIC_V1.length)));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw new Error(`Invalid indexed graph schema JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
59
|
+
}
|
|
60
|
+
const schema = (0, indexed_state_schema_1.validateIndexedGraphSchema)(object);
|
|
61
|
+
if (schema.version !== (v2 ? 2 : 1))
|
|
62
|
+
throw new Error('Indexed graph schema version and magic mismatch');
|
|
63
|
+
return schema;
|
|
64
|
+
}
|
|
65
|
+
function isRing(value) {
|
|
66
|
+
return value !== undefined && typeof value === 'object' && value !== null &&
|
|
67
|
+
'values' in value && Array.isArray(value.values) && 'excluded' in value;
|
|
68
|
+
}
|
|
69
|
+
function scalarLength(kind, representation, value, name) {
|
|
70
|
+
switch (kind) {
|
|
71
|
+
case 'int':
|
|
72
|
+
case 'uint': {
|
|
73
|
+
if (representation === 'number') {
|
|
74
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value))
|
|
75
|
+
throw new Error(`Indexed state ${name} must be a safe integer number`);
|
|
76
|
+
if (kind === 'uint' && value < 0)
|
|
77
|
+
throw new Error(`uint64 out of range: ${name}`);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
if (typeof value !== 'bigint')
|
|
81
|
+
throw new Error(`Indexed state ${name} must be bigint`);
|
|
82
|
+
if (kind === 'int' && (value < MIN_INT || value > MAX_INT))
|
|
83
|
+
throw new Error(`int64 out of range: ${name}`);
|
|
84
|
+
if (kind === 'uint' && (value < 0n || value > MAX_UINT))
|
|
85
|
+
throw new Error(`uint64 out of range: ${name}`);
|
|
86
|
+
}
|
|
87
|
+
return 8;
|
|
88
|
+
}
|
|
89
|
+
case 'double':
|
|
90
|
+
if (typeof value !== 'number')
|
|
91
|
+
throw new Error(`Indexed state ${name} must be number`);
|
|
92
|
+
return 8;
|
|
93
|
+
case 'bool':
|
|
94
|
+
if (typeof value !== 'boolean')
|
|
95
|
+
throw new Error(`Indexed state ${name} must be boolean`);
|
|
96
|
+
return 1;
|
|
97
|
+
case 'string':
|
|
98
|
+
if (typeof value !== 'string')
|
|
99
|
+
throw new Error(`Indexed state ${name} must be string`);
|
|
100
|
+
return 4 + utf8Length(value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** One reusable scratch cell per prepared codec: no per-field decoding objects. */
|
|
104
|
+
function readScalar(kind, representation, bytes, view, offset, limit, name, keep, read) {
|
|
105
|
+
read.value = undefined;
|
|
106
|
+
switch (kind) {
|
|
107
|
+
case 'int':
|
|
108
|
+
case 'uint': {
|
|
109
|
+
if (offset + 8 > limit)
|
|
110
|
+
throw new Error(`Truncated ${kind} field ${name}`);
|
|
111
|
+
let value;
|
|
112
|
+
if (keep) {
|
|
113
|
+
if (representation === 'number') {
|
|
114
|
+
const low = view.getUint32(offset, true);
|
|
115
|
+
const high = kind === 'int' ? view.getInt32(offset + 4, true) : view.getUint32(offset + 4, true);
|
|
116
|
+
const projected = high * 0x100000000 + low;
|
|
117
|
+
if (!Number.isSafeInteger(projected))
|
|
118
|
+
throw new RangeError(`Indexed state ${name} exceeds safe integer range`);
|
|
119
|
+
value = projected;
|
|
120
|
+
}
|
|
121
|
+
else
|
|
122
|
+
value = kind === 'int' ? view.getBigInt64(offset, true) : view.getBigUint64(offset, true);
|
|
123
|
+
}
|
|
124
|
+
read.value = value;
|
|
125
|
+
read.offset = offset + 8;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
case 'double': {
|
|
129
|
+
if (offset + 8 > limit)
|
|
130
|
+
throw new Error(`Truncated double field ${name}`);
|
|
131
|
+
read.value = keep ? view.getFloat64(offset, true) : undefined;
|
|
132
|
+
read.offset = offset + 8;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
case 'bool': {
|
|
136
|
+
if (offset >= limit)
|
|
137
|
+
throw new Error(`Truncated bool field ${name}`);
|
|
138
|
+
if (bytes[offset] !== 0 && bytes[offset] !== 1)
|
|
139
|
+
throw new Error(`Invalid bool field ${name}`);
|
|
140
|
+
read.value = keep ? bytes[offset] === 1 : undefined;
|
|
141
|
+
read.offset = offset + 1;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
case 'string': {
|
|
145
|
+
if (offset + 4 > limit)
|
|
146
|
+
throw new Error(`Truncated string length for ${name}`);
|
|
147
|
+
const length = view.getUint32(offset, true);
|
|
148
|
+
offset += 4;
|
|
149
|
+
if (length > limit - offset)
|
|
150
|
+
throw new Error(`Truncated string field ${name}`);
|
|
151
|
+
read.value = keep ? decoder.decode(bytes.subarray(offset, offset + length)) : undefined;
|
|
152
|
+
read.offset = offset + length;
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function writeScalar(kind, value, out, view, offset) {
|
|
158
|
+
switch (kind) {
|
|
159
|
+
case 'int': {
|
|
160
|
+
if (typeof value === 'number') {
|
|
161
|
+
const high = Math.floor(value / 0x100000000);
|
|
162
|
+
view.setUint32(offset, value - high * 0x100000000, true);
|
|
163
|
+
view.setInt32(offset + 4, high, true);
|
|
164
|
+
}
|
|
165
|
+
else
|
|
166
|
+
view.setBigInt64(offset, value, true);
|
|
167
|
+
return offset + 8;
|
|
168
|
+
}
|
|
169
|
+
case 'uint': {
|
|
170
|
+
if (typeof value === 'number') {
|
|
171
|
+
const high = Math.floor(value / 0x100000000);
|
|
172
|
+
view.setUint32(offset, value - high * 0x100000000, true);
|
|
173
|
+
view.setUint32(offset + 4, high, true);
|
|
174
|
+
}
|
|
175
|
+
else
|
|
176
|
+
view.setBigUint64(offset, value, true);
|
|
177
|
+
return offset + 8;
|
|
178
|
+
}
|
|
179
|
+
case 'double':
|
|
180
|
+
view.setFloat64(offset, value, true);
|
|
181
|
+
return offset + 8;
|
|
182
|
+
case 'bool':
|
|
183
|
+
out[offset] = value ? 1 : 0;
|
|
184
|
+
return offset + 1;
|
|
185
|
+
case 'string': {
|
|
186
|
+
const text = value, len = utf8Length(text);
|
|
187
|
+
view.setUint32(offset, len, true);
|
|
188
|
+
offset += 4;
|
|
189
|
+
const written = encoder.encodeInto(text, out.subarray(offset, offset + len));
|
|
190
|
+
if (written.written !== len)
|
|
191
|
+
throw new Error('Indexed state encoding failed for string');
|
|
192
|
+
return offset + len;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/** Bind field positions once, reuse ring data on decode, and keep scalar record bytes unchanged. */
|
|
197
|
+
function prepareIndexedGraphCodec(stored, active = stored, removed = 'reject', customerIdType = 'bigint') {
|
|
198
|
+
const storedSchema = (0, indexed_state_schema_1.validateIndexedGraphSchema)(stored);
|
|
199
|
+
const activeSchema = (0, indexed_state_schema_1.validateIndexedGraphSchema)(active);
|
|
200
|
+
for (const field of activeSchema.nodes)
|
|
201
|
+
(0, indexed_state_schema_1.indexedFieldValueType)(field);
|
|
202
|
+
const currentByName = new Map(activeSchema.nodes.map((node, index) => [node.name, index]));
|
|
203
|
+
const storedToCurrent = storedSchema.nodes.map(node => {
|
|
204
|
+
const index = currentByName.get(node.name);
|
|
205
|
+
if (index === undefined) {
|
|
206
|
+
if (removed === 'reject')
|
|
207
|
+
throw new Error(`Removed indexed state field ${node.name}`);
|
|
208
|
+
return -1;
|
|
209
|
+
}
|
|
210
|
+
const next = activeSchema.nodes[index];
|
|
211
|
+
if (next.type !== node.type)
|
|
212
|
+
throw new Error(`Indexed state type mismatch for ${node.name}: stored ${node.type}, current ${next.type}`);
|
|
213
|
+
if (node.type !== 'rolling-window' && next.type !== 'rolling-window' &&
|
|
214
|
+
node.optional && !next.optional)
|
|
215
|
+
throw new Error(`Indexed state optional field mismatch for ${node.name}`);
|
|
216
|
+
if (node.type === 'rolling-window' && next.type === 'rolling-window' &&
|
|
217
|
+
(node.element !== next.element || node.periodicity !== next.periodicity || node.size !== next.size))
|
|
218
|
+
throw new Error(`Indexed state rolling-window layout mismatch for ${node.name}`);
|
|
219
|
+
return index;
|
|
220
|
+
});
|
|
221
|
+
const read = { value: undefined, offset: 0 };
|
|
222
|
+
// The physical buffers and split-record scratch are pooled. Reuse the
|
|
223
|
+
// DataView for each backing byte array rather than creating one per row.
|
|
224
|
+
const readViews = new WeakMap();
|
|
225
|
+
const included = new Uint8Array(activeSchema.nodes.length);
|
|
226
|
+
for (const index of storedToCurrent)
|
|
227
|
+
if (index >= 0)
|
|
228
|
+
included[index] = 1;
|
|
229
|
+
const missing = [];
|
|
230
|
+
for (let i = 0; i < included.length; i++)
|
|
231
|
+
if (!included[i])
|
|
232
|
+
missing.push(i);
|
|
233
|
+
function emptyWindow(index, target) {
|
|
234
|
+
const field = activeSchema.nodes[index];
|
|
235
|
+
if (field.type !== 'rolling-window') {
|
|
236
|
+
target.values[index] = undefined;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const current = target.values[index];
|
|
240
|
+
if (isRing(current) && current.size === field.size)
|
|
241
|
+
(0, ring_buffer_1.clear)(current);
|
|
242
|
+
else
|
|
243
|
+
target.values[index] = (0, ring_buffer_1.createRingBuffer)(field.size);
|
|
244
|
+
}
|
|
245
|
+
function initializeMissing(target, customerId) {
|
|
246
|
+
if (target.values.length !== activeSchema.nodes.length)
|
|
247
|
+
throw new Error('Indexed state array has incorrect length');
|
|
248
|
+
target.customerId = customerId;
|
|
249
|
+
for (let i = 0; i < target.values.length; i++)
|
|
250
|
+
emptyWindow(i, target);
|
|
251
|
+
}
|
|
252
|
+
function decodeInto(bytes, target, start = 0, length = bytes.length - start) {
|
|
253
|
+
if (target.values.length !== activeSchema.nodes.length)
|
|
254
|
+
throw new Error('Indexed state array has incorrect length');
|
|
255
|
+
if (!Number.isSafeInteger(start) || start < 0 || start > bytes.length ||
|
|
256
|
+
!Number.isSafeInteger(length) || length < 0 || length > bytes.length - start)
|
|
257
|
+
throw new Error('Invalid indexed state payload span');
|
|
258
|
+
const limit = start + length;
|
|
259
|
+
if (length < 8)
|
|
260
|
+
throw new Error('Truncated indexed state entity key');
|
|
261
|
+
let view = readViews.get(bytes);
|
|
262
|
+
if (view === undefined) {
|
|
263
|
+
view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
264
|
+
readViews.set(bytes, view);
|
|
265
|
+
}
|
|
266
|
+
let offset = start;
|
|
267
|
+
if (customerIdType === 'number') {
|
|
268
|
+
// Decode the signed int64 as two words: no BigInt allocation in the merge hot path.
|
|
269
|
+
const low = view.getUint32(offset, true), high = view.getInt32(offset + 4, true);
|
|
270
|
+
const key = high * 0x100000000 + low;
|
|
271
|
+
if (!Number.isSafeInteger(key))
|
|
272
|
+
throw new Error('Indexed state customerId exceeds safe integer range');
|
|
273
|
+
target.customerId = key;
|
|
274
|
+
}
|
|
275
|
+
else
|
|
276
|
+
target.customerId = view.getBigInt64(offset, true);
|
|
277
|
+
offset += 8;
|
|
278
|
+
for (let i = 0; i < storedSchema.nodes.length; i++) {
|
|
279
|
+
const field = storedSchema.nodes[i], index = storedToCurrent[i];
|
|
280
|
+
if (field.type === 'rolling-window') {
|
|
281
|
+
if (offset + 9 > limit)
|
|
282
|
+
throw new Error(`Truncated rolling-window header ${field.name}`);
|
|
283
|
+
const count = view.getUint32(offset, true), excluded = view.getUint32(offset + 4, true);
|
|
284
|
+
const flag = bytes[offset + 8];
|
|
285
|
+
offset += 9;
|
|
286
|
+
if (flag !== 0 && flag !== 1)
|
|
287
|
+
throw new Error(`Invalid rolling-window expiration flag ${field.name}`);
|
|
288
|
+
let ring;
|
|
289
|
+
if (index >= 0) {
|
|
290
|
+
const current = target.values[index];
|
|
291
|
+
ring = isRing(current) && current.size === field.size ? current : (0, ring_buffer_1.createRingBuffer)(field.size);
|
|
292
|
+
// Every physical slot is overwritten below. Do not clear the
|
|
293
|
+
// backing array first: it is retained across decoded records.
|
|
294
|
+
}
|
|
295
|
+
for (let slot = 0; slot <= field.size; slot++) {
|
|
296
|
+
if (offset >= limit)
|
|
297
|
+
throw new Error(`Truncated rolling-window slot ${field.name}`);
|
|
298
|
+
const presence = bytes[offset++];
|
|
299
|
+
if (presence !== 0 && presence !== 1)
|
|
300
|
+
throw new Error(`Invalid rolling-window slot flag ${field.name}`);
|
|
301
|
+
if (presence === 1) {
|
|
302
|
+
readScalar(field.element, index >= 0 ? activeSchema.nodes[index].javascriptType : undefined, bytes, view, offset, limit, field.name, index >= 0, read);
|
|
303
|
+
offset = read.offset;
|
|
304
|
+
if (ring)
|
|
305
|
+
ring.values[slot] = read.value;
|
|
306
|
+
}
|
|
307
|
+
else if (ring) {
|
|
308
|
+
// An absent slot must overwrite a previously occupied one
|
|
309
|
+
// when the same ring is reused for a partial or empty history.
|
|
310
|
+
ring.values[slot] = undefined;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (ring) {
|
|
314
|
+
ring.count = count;
|
|
315
|
+
ring.excluded = excluded;
|
|
316
|
+
ring.hasExpired = flag === 1;
|
|
317
|
+
(0, ring_buffer_1.validateRingBuffer)(ring);
|
|
318
|
+
target.values[index] = ring;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
if (field.optional) {
|
|
323
|
+
if (offset >= limit)
|
|
324
|
+
throw new Error(`Truncated optional indexed state field ${field.name}`);
|
|
325
|
+
const presence = bytes[offset++];
|
|
326
|
+
if (presence !== 0 && presence !== 1)
|
|
327
|
+
throw new Error(`Invalid optional indexed state flag ${field.name}`);
|
|
328
|
+
if (presence === 0) {
|
|
329
|
+
if (index >= 0)
|
|
330
|
+
target.values[index] = undefined;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
readScalar(field.type, index >= 0 ? activeSchema.nodes[index].javascriptType : undefined, bytes, view, offset, limit, field.name, index >= 0, read);
|
|
335
|
+
offset = read.offset;
|
|
336
|
+
if (index >= 0)
|
|
337
|
+
target.values[index] = read.value;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (offset !== limit)
|
|
341
|
+
throw new Error(`Trailing indexed graph data: ${limit - offset} bytes`);
|
|
342
|
+
for (let i = 0; i < missing.length; i++)
|
|
343
|
+
emptyWindow(missing[i], target);
|
|
344
|
+
}
|
|
345
|
+
function encodedLength(record) {
|
|
346
|
+
if (record.values.length !== activeSchema.nodes.length)
|
|
347
|
+
throw new Error('Indexed state array has incorrect length');
|
|
348
|
+
if (typeof record.customerId === 'number') {
|
|
349
|
+
if (!Number.isSafeInteger(record.customerId))
|
|
350
|
+
throw new Error('Indexed state customerId is not a safe integer');
|
|
351
|
+
}
|
|
352
|
+
else if (record.customerId < MIN_INT || record.customerId > MAX_INT)
|
|
353
|
+
throw new Error('Indexed state customerId is outside int64 range');
|
|
354
|
+
let size = 8;
|
|
355
|
+
for (let i = 0; i < activeSchema.nodes.length; i++) {
|
|
356
|
+
const field = activeSchema.nodes[i], value = record.values[i];
|
|
357
|
+
if (field.type === 'rolling-window') {
|
|
358
|
+
if (!isRing(value) || value.size !== field.size)
|
|
359
|
+
throw new Error(`Invalid rolling-window value for ${field.name}`);
|
|
360
|
+
(0, ring_buffer_1.validateRingBuffer)(value);
|
|
361
|
+
size += 9 + field.size + 1;
|
|
362
|
+
for (const slot of value.values)
|
|
363
|
+
if (slot !== undefined)
|
|
364
|
+
size += scalarLength(field.element, field.javascriptType, slot, field.name);
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
if (field.optional)
|
|
368
|
+
size++;
|
|
369
|
+
if (value === undefined) {
|
|
370
|
+
if (!field.optional)
|
|
371
|
+
throw new Error(`Cannot persist missing indexed state field ${field.name}`);
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
if (isRing(value))
|
|
375
|
+
throw new Error(`Expected scalar indexed state field ${field.name}`);
|
|
376
|
+
size += scalarLength(field.type, field.javascriptType, value, field.name);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return size;
|
|
381
|
+
}
|
|
382
|
+
function encodeInto(record, out, offset) {
|
|
383
|
+
const length = encodedLength(record);
|
|
384
|
+
if (!Number.isSafeInteger(offset) || offset < 0 || length > out.length - offset)
|
|
385
|
+
throw new Error('Indexed state output buffer too small');
|
|
386
|
+
const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
387
|
+
const start = offset;
|
|
388
|
+
if (typeof record.customerId === 'number') {
|
|
389
|
+
const high = Math.floor(record.customerId / 0x100000000);
|
|
390
|
+
view.setUint32(offset, record.customerId - high * 0x100000000, true);
|
|
391
|
+
view.setInt32(offset + 4, high, true);
|
|
392
|
+
}
|
|
393
|
+
else
|
|
394
|
+
view.setBigInt64(offset, record.customerId, true);
|
|
395
|
+
offset += 8;
|
|
396
|
+
for (let i = 0; i < activeSchema.nodes.length; i++) {
|
|
397
|
+
const field = activeSchema.nodes[i], value = record.values[i];
|
|
398
|
+
if (field.type === 'rolling-window') {
|
|
399
|
+
if (!isRing(value))
|
|
400
|
+
throw new Error(`Invalid rolling-window value for ${field.name}`);
|
|
401
|
+
view.setUint32(offset, value.count, true);
|
|
402
|
+
view.setUint32(offset + 4, value.excluded, true);
|
|
403
|
+
out[offset + 8] = value.hasExpired ? 1 : 0;
|
|
404
|
+
offset += 9;
|
|
405
|
+
for (const slot of value.values) {
|
|
406
|
+
out[offset++] = slot === undefined ? 0 : 1;
|
|
407
|
+
if (slot !== undefined)
|
|
408
|
+
offset = writeScalar(field.element, slot, out, view, offset);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
if (field.optional)
|
|
413
|
+
out[offset++] = value === undefined ? 0 : 1;
|
|
414
|
+
if (value !== undefined) {
|
|
415
|
+
if (isRing(value))
|
|
416
|
+
throw new Error(`Expected scalar indexed state field ${field.name}`);
|
|
417
|
+
offset = writeScalar(field.type, value, out, view, offset);
|
|
418
|
+
}
|
|
419
|
+
else if (!field.optional)
|
|
420
|
+
throw new Error(`Expected scalar indexed state field ${field.name}`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return offset - start;
|
|
424
|
+
}
|
|
425
|
+
return { storedSchema, activeSchema, storedToCurrent, initializeMissing, decodeInto, encodedLength, encodeInto };
|
|
426
|
+
}
|
|
427
|
+
//# sourceMappingURL=indexed.state.codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexed.state.codec.js","sourceRoot":"","sources":["../../src/indexed.state.codec.ts"],"names":[],"mappings":";;AA4BA,4DAUC;AAED,4DAUC;AAkHD,4DAkLC;AAtVD,uDAA+F;AAC/F,iEAEiC;AAEjC,MAAM,OAAO,GAAC,IAAI,WAAW,EAAE,CAAA;AAC/B,MAAM,OAAO,GAAC,IAAI,WAAW,CAAC,OAA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wBAAC,MAAM,GAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAC,IAAI,EAAC,GAAG,EAAC,IAAI,EAAC,MAAM,CAAC,CAAA;gBAC9E,CAAC;YACL,CAAC;iBAAK,CAAC;gBACH,IAAG,KAAK,CAAC,QAAQ;oBAAC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAC,KAAK,KAAG,SAAS,CAAA,CAAC,CAAA,CAAC,CAAA,CAAC,CAAA,CAAC,CAAA;gBACrD,IAAG,KAAK,KAAG,SAAS,EAAC,CAAC;oBAClB,IAAG,MAAM,CAAC,KAAK,CAAC;wBAAC,MAAM,IAAI,KAAK,CAAC,uCAAuC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;oBACrF,MAAM,GAAC,WAAW,CAAC,KAAK,CAAC,IAAI,EAAC,KAAK,EAAC,GAAG,EAAC,IAAI,EAAC,MAAM,CAAC,CAAA;gBACxD,CAAC;qBAAK,IAAG,CAAC,KAAK,CAAC,QAAQ;oBAAC,MAAM,IAAI,KAAK,CAAC,uCAAuC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;YACjG,CAAC;QACL,CAAC;QACD,OAAO,MAAM,GAAC,KAAK,CAAA;IACvB,CAAC;IACD,OAAO,EAAC,YAAY,EAAC,YAAY,EAAC,eAAe,EAAC,iBAAiB,EAAC,UAAU,EAAC,aAAa,EAAC,UAAU,EAAC,CAAA;AAC5G,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Configuration section of .cobolts/accumulator.yaml. */
|
|
2
|
+
export interface IndexedAccumulatorConfiguration {
|
|
3
|
+
readonly strategy: 'object' | 'indexed';
|
|
4
|
+
readonly file?: string;
|
|
5
|
+
readonly optional: boolean;
|
|
6
|
+
readonly removed: 'reject' | 'ignore';
|
|
7
|
+
/** Logical projected scalar field containing the sorted entity key. */
|
|
8
|
+
readonly customerId: string;
|
|
9
|
+
/** JavaScript representation of the merge key; omitted for legacy bigint configuration. */
|
|
10
|
+
readonly customerIdType?: 'number' | 'bigint';
|
|
11
|
+
}
|
|
12
|
+
export declare function parseIndexedAccumulatorConfiguration(raw: unknown): IndexedAccumulatorConfiguration;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseIndexedAccumulatorConfiguration = parseIndexedAccumulatorConfiguration;
|
|
4
|
+
function parseIndexedAccumulatorConfiguration(raw) {
|
|
5
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
|
|
6
|
+
throw new Error('accumulator.yaml: Expected a mapping');
|
|
7
|
+
const fields = raw;
|
|
8
|
+
for (const key of Object.keys(fields))
|
|
9
|
+
if (!['strategy', 'file', 'optional', 'removed', 'customerId'].includes(key))
|
|
10
|
+
throw new Error(`accumulator.yaml: Unknown field ${key}`);
|
|
11
|
+
if (fields.strategy !== 'object' && fields.strategy !== 'indexed')
|
|
12
|
+
throw new Error('accumulator.yaml: strategy must be object or indexed');
|
|
13
|
+
if (fields.file !== undefined && (typeof fields.file !== 'string' || !fields.file.trim()))
|
|
14
|
+
throw new Error('accumulator.yaml: file must be a nonempty path');
|
|
15
|
+
if (fields.optional !== undefined && typeof fields.optional !== 'boolean')
|
|
16
|
+
throw new Error('accumulator.yaml: optional must be a Boolean');
|
|
17
|
+
if (fields.removed !== undefined && fields.removed !== 'reject' && fields.removed !== 'ignore')
|
|
18
|
+
throw new Error('accumulator.yaml: removed must be reject or ignore');
|
|
19
|
+
const configuredId = fields.customerId;
|
|
20
|
+
let customerId = 'customerId';
|
|
21
|
+
let customerIdType;
|
|
22
|
+
if (configuredId !== undefined) {
|
|
23
|
+
if (typeof configuredId === 'string')
|
|
24
|
+
customerId = configuredId;
|
|
25
|
+
else if (configuredId !== null && typeof configuredId === 'object' && !Array.isArray(configuredId)) {
|
|
26
|
+
const id = configuredId;
|
|
27
|
+
for (const name of Object.keys(id))
|
|
28
|
+
if (!['field', 'type'].includes(name))
|
|
29
|
+
throw new Error(`accumulator.yaml: Unknown customerId field ${name}`);
|
|
30
|
+
if (id.type !== 'number' && id.type !== 'bigint')
|
|
31
|
+
throw new Error('accumulator.yaml: customerId.type must be number or bigint');
|
|
32
|
+
customerId = id.field;
|
|
33
|
+
customerIdType = id.type;
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
throw new Error('accumulator.yaml: customerId must be one projected field name or a typed mapping');
|
|
37
|
+
if (typeof customerId !== 'string' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(customerId))
|
|
38
|
+
throw new Error('accumulator.yaml: customerId must be one projected field name');
|
|
39
|
+
}
|
|
40
|
+
return { strategy: fields.strategy, optional: fields.optional !== false,
|
|
41
|
+
removed: fields.removed === 'ignore' ? 'ignore' : 'reject', customerId,
|
|
42
|
+
...(customerIdType === undefined ? {} : { customerIdType }),
|
|
43
|
+
...(typeof fields.file === 'string' ? { file: fields.file } : {}) };
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=indexed.state.configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexed.state.configuration.js","sourceRoot":"","sources":["../../src/indexed.state.configuration.ts"],"names":[],"mappings":";;AAYA,oFAoCC;AApCD,SAAgB,oCAAoC,CAAC,GAAW;IAC5D,IAAG,GAAG,KAAG,IAAI,IAAE,OAAO,GAAG,KAAG,QAAQ,IAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAC,GAA6B,CAAC;IAC3C,KAAI,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;QAChC,IAAG,CAAC,CAAC,UAAU,EAAC,MAAM,EAAC,UAAU,EAAC,SAAS,EAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;YACnE,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,EAAE,CAAC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AAC;YAC1E,IAAG,EAAE,CAAC,IAAI,KAAG,QAAQ,IAAE,EAAE,CAAC,IAAI,KAAG,QAAQ;gBACrC,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;YAClF,UAAU,GAAC,EAAE,CAAC,KAAe,CAAC;YAC9B,cAAc,GAAC,EAAE,CAAC,IAAI,CAAC;QAC3B,CAAC;;YAAK,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;QAC1G,IAAG,OAAO,UAAU,KAAG,QAAQ,IAAE,CAAC,0BAA0B,CAAC,IAAI,CAAC,UAAU,CAAC;YACzE,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,EAAC,QAAQ,EAAC,MAAM,CAAC,QAAQ,EAAC,QAAQ,EAAC,MAAM,CAAC,QAAQ,KAAG,KAAK;QAC7D,OAAO,EAAC,MAAM,CAAC,OAAO,KAAG,QAAQ,CAAA,CAAC,CAAA,QAAQ,CAAA,CAAC,CAAA,QAAQ,EAAC,UAAU;QAC9D,GAAG,CAAC,cAAc,KAAG,SAAS,CAAA,CAAC,CAAA,EAAE,CAAA,CAAC,CAAA,EAAC,cAAc,EAAC,CAAC;QACnD,GAAG,CAAC,OAAO,MAAM,CAAC,IAAI,KAAG,QAAQ,CAAA,CAAC,CAAA,EAAC,IAAI,EAAC,MAAM,CAAC,IAAI,EAAC,CAAA,CAAC,CAAA,EAAE,CAAC,EAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("../index");
|
|
4
|
+
describe('Indexed Graph State package exports', () => {
|
|
5
|
+
it('exposes schema, pooled state, reader and writer through index.ts', () => {
|
|
6
|
+
expect({
|
|
7
|
+
createRecord: typeof index_1.createIndexedGraphRecord,
|
|
8
|
+
pool: typeof index_1.createIndexedGraphStatePool,
|
|
9
|
+
schema: typeof index_1.indexedGraphSchema,
|
|
10
|
+
read: typeof index_1.readIndexedGraphStateFile,
|
|
11
|
+
readSchema: typeof index_1.readIndexedGraphStateFileSchema,
|
|
12
|
+
write: typeof index_1.writeIndexedGraphStateFile
|
|
13
|
+
}).toEqual({
|
|
14
|
+
createRecord: 'function',
|
|
15
|
+
pool: 'function',
|
|
16
|
+
schema: 'function',
|
|
17
|
+
read: 'function',
|
|
18
|
+
readSchema: 'function',
|
|
19
|
+
write: 'function'
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=indexed.state.exports.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexed.state.exports.spec.js","sourceRoot":"","sources":["../../src/indexed.state.exports.spec.ts"],"names":[],"mappings":";;AAAA,oCAOiB;AAEjB,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;IACjD,EAAE,CAAC,kEAAkE,EAAE,GAAG,EAAE;QACxE,MAAM,CAAC;YACH,YAAY,EAAE,OAAO,gCAAwB;YAC7C,IAAI,EAAE,OAAO,mCAA2B;YACxC,MAAM,EAAE,OAAO,0BAAkB;YACjC,IAAI,EAAE,OAAO,iCAAyB;YACtC,UAAU,EAAE,OAAO,uCAA+B;YAClD,KAAK,EAAE,OAAO,kCAA0B;SAC3C,CAAC,CAAC,OAAO,CAAC;YACP,YAAY,EAAE,UAAU;YACxB,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,UAAU;YAClB,IAAI,EAAE,UAAU;YAChB,UAAU,EAAE,UAAU;YACtB,KAAK,EAAE,UAAU;SACpB,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type SynchronousCallbackLeaseCursor, type PreparedFileCursorResult } from '@cobol-ts/cursor-file';
|
|
2
|
+
import { type ParserRegistry } from '@cobol-ts/cursor-loader-types';
|
|
3
|
+
import { type IndexedGraphParserConfig } from './indexed.state.parser';
|
|
4
|
+
import { type IndexedGraphRecord, type IndexedGraphSchema, type IndexedCustomerId } from './indexed.state.schema';
|
|
5
|
+
export interface IndexedGraphFileOptions extends IndexedGraphParserConfig {
|
|
6
|
+
readonly bufferSize?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function createIndexedGraphParserRegistry(config?: IndexedGraphParserConfig): ParserRegistry<'indexed-graph-state'>;
|
|
9
|
+
/** Identical prepared cursor/lease infrastructure to COBOL, CSV, JSONL and Protobuf. */
|
|
10
|
+
export declare function readIndexedGraphStateFile(filename: string, options?: IndexedGraphFileOptions): AsyncGenerator<PreparedFileCursorResult<object, IndexedGraphRecord>, void, void>;
|
|
11
|
+
/** Callback/pull interface for joins; no async-generator record traffic. */
|
|
12
|
+
export declare function openIndexedGraphStateFileCursor(filename: string, options?: IndexedGraphFileOptions): Promise<SynchronousCallbackLeaseCursor<PreparedFileCursorResult<object, IndexedGraphRecord>>>;
|
|
13
|
+
export declare function readIndexedGraphStateFileSchema(filename: string, options?: IndexedGraphFileOptions): Promise<IndexedGraphSchema>;
|
|
14
|
+
/** A pooled in-memory record is also used for entities without historical state. */
|
|
15
|
+
export declare function createIndexedGraphStatePool(schema: IndexedGraphSchema): {
|
|
16
|
+
acquireEmpty: (customerId: IndexedCustomerId) => IndexedGraphRecord;
|
|
17
|
+
release: (record: IndexedGraphRecord) => void;
|
|
18
|
+
};
|
|
19
|
+
/** Writes the schema first, then strictly increasing entity keys; no per-row output buffer. */
|
|
20
|
+
export declare function writeIndexedGraphStateFile(filename: string, schema: IndexedGraphSchema, rows: Iterable<IndexedGraphRecord> | AsyncIterable<IndexedGraphRecord>, capacity?: number): Promise<void>;
|