@cobol-ts/cursor-loader-protobuf 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.
Files changed (77) hide show
  1. package/README.md +94 -2
  2. package/dist/index.d.ts +18 -0
  3. package/dist/index.js +35 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/src/protobuf.accumulator.d.ts +24 -0
  6. package/dist/src/protobuf.accumulator.file.d.ts +24 -0
  7. package/dist/src/protobuf.accumulator.file.js +164 -0
  8. package/dist/src/protobuf.accumulator.file.js.map +1 -0
  9. package/dist/src/protobuf.accumulator.js +110 -0
  10. package/dist/src/protobuf.accumulator.js.map +1 -0
  11. package/dist/src/protobuf.buffered.spec.d.ts +1 -0
  12. package/dist/src/protobuf.buffered.spec.js +97 -0
  13. package/dist/src/protobuf.buffered.spec.js.map +1 -0
  14. package/dist/src/protobuf.cursor.integration.spec.d.ts +1 -0
  15. package/dist/src/protobuf.cursor.integration.spec.js +116 -0
  16. package/dist/src/protobuf.cursor.integration.spec.js.map +1 -0
  17. package/dist/src/protobuf.envelope.d.ts +6 -0
  18. package/dist/src/protobuf.envelope.js +48 -0
  19. package/dist/src/protobuf.envelope.js.map +1 -0
  20. package/dist/src/protobuf.file.node.d.ts +16 -0
  21. package/dist/src/protobuf.file.node.js +43 -0
  22. package/dist/src/protobuf.file.node.js.map +1 -0
  23. package/dist/src/protobuf.file.spec.d.ts +1 -0
  24. package/dist/src/protobuf.file.spec.js +162 -0
  25. package/dist/src/protobuf.file.spec.js.map +1 -0
  26. package/dist/src/protobuf.mixed.codec.d.ts +7 -0
  27. package/dist/src/protobuf.mixed.codec.js +105 -0
  28. package/dist/src/protobuf.mixed.codec.js.map +1 -0
  29. package/dist/src/protobuf.number.file.d.ts +17 -0
  30. package/dist/src/protobuf.number.file.js +107 -0
  31. package/dist/src/protobuf.number.file.js.map +1 -0
  32. package/dist/src/protobuf.number.projection.d.ts +25 -0
  33. package/dist/src/protobuf.number.projection.js +310 -0
  34. package/dist/src/protobuf.number.projection.js.map +1 -0
  35. package/dist/src/protobuf.number.projection.spec.d.ts +1 -0
  36. package/dist/src/protobuf.number.projection.spec.js +111 -0
  37. package/dist/src/protobuf.number.projection.spec.js.map +1 -0
  38. package/dist/src/protobuf.number.rolling.d.ts +21 -0
  39. package/dist/src/protobuf.number.rolling.js +162 -0
  40. package/dist/src/protobuf.number.rolling.js.map +1 -0
  41. package/dist/src/protobuf.parser.d.ts +35 -0
  42. package/dist/src/protobuf.parser.js +142 -0
  43. package/dist/src/protobuf.parser.js.map +1 -0
  44. package/dist/src/protobuf.projection.support.d.ts +14 -0
  45. package/dist/src/protobuf.projection.support.js +75 -0
  46. package/dist/src/protobuf.projection.support.js.map +1 -0
  47. package/dist/src/protobuf.rdw.d.ts +15 -0
  48. package/dist/src/protobuf.rdw.js +107 -0
  49. package/dist/src/protobuf.rdw.js.map +1 -0
  50. package/dist/src/protobuf.registration.d.ts +3 -0
  51. package/dist/src/protobuf.registration.js +8 -0
  52. package/dist/src/protobuf.registration.js.map +1 -0
  53. package/dist/src/protobuf.reuse.spec.d.ts +1 -0
  54. package/dist/src/protobuf.reuse.spec.js +117 -0
  55. package/dist/src/protobuf.reuse.spec.js.map +1 -0
  56. package/dist/src/protobuf.rolling.layout.d.ts +13 -0
  57. package/dist/src/protobuf.rolling.layout.js +69 -0
  58. package/dist/src/protobuf.rolling.layout.js.map +1 -0
  59. package/dist/src/protobuf.rolling.spec.d.ts +1 -0
  60. package/dist/src/protobuf.rolling.spec.js +174 -0
  61. package/dist/src/protobuf.rolling.spec.js.map +1 -0
  62. package/dist/src/protobuf.roundtrip.spec.d.ts +1 -0
  63. package/dist/src/protobuf.roundtrip.spec.js +195 -0
  64. package/dist/src/protobuf.roundtrip.spec.js.map +1 -0
  65. package/dist/src/protobuf.safe-integer.d.ts +10 -0
  66. package/dist/src/protobuf.safe-integer.js +88 -0
  67. package/dist/src/protobuf.safe-integer.js.map +1 -0
  68. package/dist/src/protobuf.scalar.codec.d.ts +17 -0
  69. package/dist/src/protobuf.scalar.codec.js +276 -0
  70. package/dist/src/protobuf.scalar.codec.js.map +1 -0
  71. package/dist/src/protobuf.schema.d.ts +17 -0
  72. package/dist/src/protobuf.schema.first.parser.d.ts +10 -0
  73. package/dist/src/protobuf.schema.first.parser.js +23 -0
  74. package/dist/src/protobuf.schema.first.parser.js.map +1 -0
  75. package/dist/src/protobuf.schema.js +91 -0
  76. package/dist/src/protobuf.schema.js.map +1 -0
  77. package/package.json +68 -3
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readNumberBackedAccumulatorFile = readNumberBackedAccumulatorFile;
4
+ exports.writeNumberBackedAccumulatorFile = writeNumberBackedAccumulatorFile;
5
+ const promises_1 = require("node:fs/promises");
6
+ const errors_1 = require("@cobol-ts/errors");
7
+ const cursor_record_1 = require("@cobol-ts/cursor-record");
8
+ const cursor_file_1 = require("@cobol-ts/cursor-file");
9
+ const protobuf_schema_first_parser_1 = require("./protobuf.schema.first.parser");
10
+ const protobuf_parser_1 = require("./protobuf.parser");
11
+ const protobuf_envelope_1 = require("./protobuf.envelope");
12
+ const protobuf_rdw_1 = require("./protobuf.rdw");
13
+ const protobuf_number_projection_1 = require("./protobuf.number.projection");
14
+ function numberPool(count) {
15
+ const available = [];
16
+ function take(parent) {
17
+ const item = available.pop() ?? {
18
+ customerId: 0n,
19
+ values: Array(count).fill(undefined),
20
+ parent: undefined,
21
+ active: false,
22
+ get closed() { return !this.active; },
23
+ close() {
24
+ if (!this.active)
25
+ throw new Error('Accumulator already closed');
26
+ this.active = false;
27
+ const lease = this.parent;
28
+ this.parent = undefined;
29
+ try {
30
+ lease?.close();
31
+ }
32
+ finally {
33
+ available.push(this);
34
+ }
35
+ }
36
+ };
37
+ item.parent = parent;
38
+ item.active = true;
39
+ return item;
40
+ }
41
+ return { take };
42
+ }
43
+ function openNumberCursor(filename, file, options) {
44
+ return (0, cursor_record_1.openRecordCursor)(protobuf_schema_first_parser_1.schemaFirstProtobufParser, { maxRecordBytes: options.maxRecordBytes }, (0, cursor_record_1.createDefaultPhysicalRecordConfig)({
45
+ source: filename, file, bufferSize: options.bufferSize ?? 65536,
46
+ fillFileBuffer: cursor_file_1.fillNodeFileBuffer, createRecordState: protobuf_parser_1.createProtobufRecordState
47
+ }));
48
+ }
49
+ /**
50
+ * Opens the same schema-first RDW file as readAccumulatorFile, but projects int64
51
+ * fields directly into graph-native numbers. The iterator leases arrays and
52
+ * physical records; consumers must call close() on each yielded record.
53
+ */
54
+ async function* readNumberBackedAccumulatorFile(filename, graph, options = {}) {
55
+ const file = await (0, promises_1.open)(filename, 'r');
56
+ let opened;
57
+ try {
58
+ opened = await openNumberCursor(filename, file, options);
59
+ const codec = (0, protobuf_number_projection_1.prepareNumberBackedProtobufProjection)(opened.details.accumulatorSchema, graph);
60
+ const pool = numberPool(graph.length);
61
+ for await (const row of opened.recordCursor) {
62
+ if ((0, errors_1.isErrors)(row.result)) {
63
+ row.physicalRecord.close();
64
+ throw new errors_1.ErrorsException(row.result.errors, row.result.reference);
65
+ }
66
+ const lease = pool.take(row.physicalRecord);
67
+ try {
68
+ codec.decodeInto(row.result.data, lease);
69
+ }
70
+ catch (error) {
71
+ lease.close();
72
+ throw error;
73
+ }
74
+ yield lease;
75
+ }
76
+ }
77
+ finally {
78
+ opened?.close();
79
+ await file.close();
80
+ }
81
+ }
82
+ /** Writes graph-native number slots to legal Protobuf scalar fields, using the existing buffered RDW writer. */
83
+ async function writeNumberBackedAccumulatorFile(filename, schema, graph, rows) {
84
+ const codec = (0, protobuf_number_projection_1.prepareNumberBackedProtobufProjection)(schema, graph);
85
+ const file = await (0, promises_1.open)(filename, 'w');
86
+ const writer = (0, protobuf_rdw_1.createBufferedRdwWriter)(file);
87
+ try {
88
+ if (!writer.appendRecord((0, protobuf_envelope_1.encodeSchemaEnvelope)(schema)))
89
+ throw new Error('Accumulator schema does not fit output buffer');
90
+ let previous;
91
+ for await (const row of rows) {
92
+ if (previous !== undefined && row.customerId <= previous)
93
+ throw new Error('Accumulator records must be strictly sorted by customerId');
94
+ previous = row.customerId;
95
+ if (!writer.appendEncoded(row, codec)) {
96
+ await writer.flush();
97
+ if (!writer.appendEncoded(row, codec))
98
+ throw new Error('Accumulator record does not fit output buffer');
99
+ }
100
+ }
101
+ await writer.flush();
102
+ }
103
+ finally {
104
+ await file.close();
105
+ }
106
+ }
107
+ //# sourceMappingURL=protobuf.number.file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protobuf.number.file.js","sourceRoot":"","sources":["../../src/protobuf.number.file.ts"],"names":[],"mappings":";;AA2DA,0EAwBC;AAGD,4EAuBC;AA7GD,+CAAsD;AACtD,6CAA0D;AAC1D,2DAA2F;AAC3F,uDAAyD;AACzD,iFAAyE;AACzE,uDAA4D;AAC5D,2DAAyD;AACzD,iDAAuD;AAEvD,6EAAwI;AAQxI,SAAS,UAAU,CAAC,KAAY;IAK5B,MAAM,SAAS,GAAQ,EAAE,CAAC;IAC1B,SAAS,IAAI,CAAC,MAAkB;QAC5B,MAAM,IAAI,GAAC,SAAS,CAAC,GAAG,EAAE,IAAE;YACxB,UAAU,EAAC,EAAE;YACb,MAAM,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;YACnC,MAAM,EAAC,SAAS;YAChB,MAAM,EAAC,KAAK;YACZ,IAAI,MAAM,KAAY,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,CAAC;YAC3C,KAAK;gBACD,IAAG,CAAC,IAAI,CAAC,MAAM;oBAAC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;gBAC9D,IAAI,CAAC,MAAM,GAAC,KAAK,CAAC;gBAClB,MAAM,KAAK,GAAC,IAAI,CAAC,MAAM,CAAC;gBAAA,IAAI,CAAC,MAAM,GAAC,SAAS,CAAC;gBAC9C,IAAG,CAAC;oBAAA,KAAK,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AAS,IAAE,GAAG,CAAC,UAAU,IAAE,QAAQ;gBAC7C,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;YACjF,QAAQ,GAAC,GAAG,CAAC,UAAU,CAAC;YACxB,IAAG,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAC,KAAK,CAAC,EAAE,CAAC;gBAClC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;gBACrB,IAAG,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAC,KAAK,CAAC;oBAAC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;YACzG,CAAC;QACL,CAAC;QACD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;YAAS,CAAC;QAAA,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IAAA,CAAC;AACnC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { AccumulatorSchema } from './protobuf.schema';
2
+ import type { ScalarValueType, RollingWindowValueType } from '@cobol-ts/value-types';
3
+ import type { RingBuffer } from '@cobol-ts/ring-buffer';
4
+ /** A graph-facing value is deliberately NOT a Protobuf Message: its int64 slots may be numbers. */
5
+ export type WorkingScalar = number | bigint | string | boolean | RingBuffer<number | bigint | string | boolean> | undefined;
6
+ export interface NumberBackedRecord {
7
+ customerId: bigint;
8
+ readonly values: WorkingScalar[];
9
+ }
10
+ export interface WorkingAccumulatorField {
11
+ readonly name: string;
12
+ readonly valueType: ScalarValueType | RollingWindowValueType;
13
+ }
14
+ /**
15
+ * Prepared once from the persisted descriptor and canonical graph field order.
16
+ * The hot path uses numeric field indexes and decodes safe int64 directly into numbers.
17
+ * The customer key remains bigint. This path never assigns a number to a Protobuf Message.
18
+ */
19
+ export declare function prepareNumberBackedProtobufProjection(schema: AccumulatorSchema, graph: readonly WorkingAccumulatorField[]): {
20
+ decodeInto: (bytes: Uint8Array, target: NumberBackedRecord) => void;
21
+ encodedLength: (record: NumberBackedRecord) => number;
22
+ encodeInto: (record: NumberBackedRecord, out: Uint8Array, offset: number, knownLength?: number) => number;
23
+ };
24
+ /** Prepare the working type declarations from canonical graph metadata, once per graph. */
25
+ export declare function workingAccumulatorFieldsFromGraph<I, A, V>(nodes: readonly import('@cobol-ts/dependency_node').CannonicalCelDependencyNode<I, A, V>[]): WorkingAccumulatorField[];
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareNumberBackedProtobufProjection = prepareNumberBackedProtobufProjection;
4
+ exports.workingAccumulatorFieldsFromGraph = workingAccumulatorFieldsFromGraph;
5
+ const protobuf_rolling_layout_1 = require("./protobuf.rolling.layout");
6
+ const protobuf_number_rolling_1 = require("./protobuf.number.rolling");
7
+ const protobuf_safe_integer_1 = require("./protobuf.safe-integer");
8
+ const encoder = new TextEncoder();
9
+ const decoder = new TextDecoder('utf-8', { fatal: true });
10
+ function utf8Length(s) {
11
+ let length = 0;
12
+ for (let i = 0; i < s.length; i++) {
13
+ const c = s.charCodeAt(i);
14
+ if (c < 0x80)
15
+ length++;
16
+ else if (c < 0x800)
17
+ length += 2;
18
+ else if (c >= 0xd800 && c <= 0xdbff && i + 1 < s.length) {
19
+ const next = s.charCodeAt(i + 1);
20
+ if (next >= 0xdc00 && next <= 0xdfff) {
21
+ length += 4;
22
+ i++;
23
+ }
24
+ else
25
+ length += 3;
26
+ }
27
+ else
28
+ length += 3;
29
+ }
30
+ return length;
31
+ }
32
+ const MAX_UINT64 = (1n << 64n) - 1n, MAX_INT64 = (1n << 63n) - 1n, MIN_INT64 = -(1n << 63n);
33
+ function readBigVarint(bytes, cursor) {
34
+ let value = 0n;
35
+ for (let i = 0; i < 10; i++) {
36
+ if (cursor.offset >= bytes.length)
37
+ throw new Error('Truncated accumulator varint');
38
+ const b = bytes[cursor.offset++];
39
+ if (i === 9 && (b & 127) > 1)
40
+ throw new Error('Accumulator varint exceeds 64 bits');
41
+ value |= BigInt(b & 127) << BigInt(i * 7);
42
+ if ((b & 128) === 0)
43
+ return value;
44
+ }
45
+ throw new Error('Accumulator varint is too long');
46
+ }
47
+ function bigVarintLength(value) {
48
+ let n = 1;
49
+ while (value >= 128n) {
50
+ value >>= 7n;
51
+ n++;
52
+ }
53
+ return n;
54
+ }
55
+ function writeBigVarint(out, offset, value) {
56
+ while (value >= 128n) {
57
+ out[offset++] = Number(value & 127n) | 128;
58
+ value >>= 7n;
59
+ }
60
+ out[offset++] = Number(value);
61
+ return offset;
62
+ }
63
+ function toUnsigned(value, signed, name) {
64
+ if (signed ? value < MIN_INT64 || value > MAX_INT64 : value < 0n || value > MAX_UINT64)
65
+ throw new Error(`Protobuf ${signed ? 'int64' : 'uint64'} out of range for ${name}`);
66
+ return value < 0n ? value + (1n << 64n) : value;
67
+ }
68
+ function checkField(field, kind) {
69
+ if (field.valueType.kind !== 'scalar')
70
+ throw new Error(`Expected scalar field ${field.name}`);
71
+ const { semanticType, javascriptType } = field.valueType;
72
+ if (javascriptType === 'fixed')
73
+ throw new Error(`Custom fixed representation not yet supported: ${field.name}`);
74
+ switch (semanticType) {
75
+ case 'string':
76
+ if (kind === 9 && javascriptType === 'string')
77
+ return false;
78
+ break;
79
+ case 'boolean':
80
+ if (kind === 8 && javascriptType === 'boolean')
81
+ return false;
82
+ break;
83
+ case 'float':
84
+ if (kind === 1 && javascriptType === 'number')
85
+ return false;
86
+ break;
87
+ case 'integer':
88
+ case 'unsignedInteger':
89
+ case 'fixed2':
90
+ case 'fixed3':
91
+ if ((kind === 3 || kind === 4) && javascriptType === 'number')
92
+ return true;
93
+ if ((kind === 3 || kind === 4) && javascriptType === 'bigint')
94
+ return false;
95
+ break;
96
+ }
97
+ throw new Error(`Accumulator schema type incompatible with graph node ${field.name}: Protobuf field kind ${kind}, ${semanticType}/${javascriptType}`);
98
+ }
99
+ /**
100
+ * Prepared once from the persisted descriptor and canonical graph field order.
101
+ * The hot path uses numeric field indexes and decodes safe int64 directly into numbers.
102
+ * The customer key remains bigint. This path never assigns a number to a Protobuf Message.
103
+ */
104
+ function prepareNumberBackedProtobufProjection(schema, graph) {
105
+ if ((0, protobuf_rolling_layout_1.protobufRollingLayouts)(schema).size > 0)
106
+ return (0, protobuf_number_rolling_1.prepareRollingNumberBackedProtobufProjection)(schema, graph);
107
+ const descriptorName = schema.messageFullName.replace(/^\./, '').split('.').pop();
108
+ const message = schema.descriptorSet.file.flatMap(f => f.messageType).find(m => m.name === descriptorName);
109
+ if (!message)
110
+ throw new Error(`Cannot find accumulator message ${schema.messageFullName}`);
111
+ const indexes = new Map();
112
+ graph.forEach((n, i) => { if (indexes.has(n.name))
113
+ throw new Error(`Duplicate graph node ${n.name}`); indexes.set(n.name, i); });
114
+ const prepared = [];
115
+ const byNumber = new Map();
116
+ const seen = new Uint32Array(message.field.length);
117
+ let epoch = 0;
118
+ let customerField = false;
119
+ for (const f of message.field) {
120
+ if (f.number === undefined || f.number < 1 || byNumber.has(f.number))
121
+ throw new Error(`Invalid accumulator field number for ${f.name}`);
122
+ if (f.name === 'customerId') {
123
+ if (f.type !== 3)
124
+ throw new Error('Accumulator customerId must be protobuf int64');
125
+ customerField = true;
126
+ }
127
+ const index = f.name === 'customerId' ? -1 : indexes.get(f.name);
128
+ if (index === undefined)
129
+ throw new Error(`Stored accumulator node ${f.name} is not in the graph`);
130
+ const kind = f.type;
131
+ if (kind !== 1 && kind !== 3 && kind !== 4 && kind !== 8 && kind !== 9)
132
+ throw new Error(`Unsupported Protobuf kind for ${f.name}`);
133
+ const field = { name: f.name, number: f.number, kind, wire: kind === 1 ? 1 : kind === 9 ? 2 : 0, index,
134
+ numberBacked: index >= 0 ? checkField(graph[index], kind) : false };
135
+ byNumber.set(f.number, field);
136
+ prepared.push(field);
137
+ }
138
+ if (!customerField)
139
+ throw new Error('Accumulator schema has no customerId');
140
+ const indices = new Map(prepared.map((f, i) => [f.number, i]));
141
+ const cursor = { offset: 0, value: 0 };
142
+ const scratch = new DataView(new ArrayBuffer(8));
143
+ function read(bytes, target) {
144
+ if (target.values.length !== graph.length)
145
+ throw new Error('Incorrect graph value array length');
146
+ target.values.fill(undefined);
147
+ epoch++;
148
+ if (epoch === 0xffffffff) {
149
+ seen.fill(0);
150
+ epoch = 1;
151
+ }
152
+ cursor.offset = 0;
153
+ let count = 0;
154
+ while (cursor.offset < bytes.length) {
155
+ (0, protobuf_safe_integer_1.readSafeVarint64)(bytes, cursor, false);
156
+ const tag = cursor.value;
157
+ const f = byNumber.get(Math.floor(tag / 8));
158
+ if (!f)
159
+ throw new Error(`Unknown accumulator field ${Math.floor(tag / 8)}`);
160
+ const wire = tag % 8;
161
+ if (wire !== f.wire)
162
+ throw new Error(`Incorrect Protobuf wire type for ${f.name}`);
163
+ const index = indices.get(f.number);
164
+ if (seen[index] === epoch)
165
+ throw new Error(`Duplicate accumulator field ${f.name}`);
166
+ seen[index] = epoch;
167
+ count++;
168
+ let value;
169
+ switch (f.kind) {
170
+ case 3:
171
+ case 4:
172
+ if (f.numberBacked) {
173
+ (0, protobuf_safe_integer_1.readSafeVarint64)(bytes, cursor, f.kind === 3);
174
+ value = cursor.value;
175
+ }
176
+ else {
177
+ const raw = readBigVarint(bytes, cursor);
178
+ value = f.kind === 3 && raw > MAX_INT64 ? raw - (1n << 64n) : raw;
179
+ }
180
+ break;
181
+ case 8:
182
+ (0, protobuf_safe_integer_1.readSafeVarint64)(bytes, cursor, false);
183
+ if (cursor.value !== 0 && cursor.value !== 1)
184
+ throw new Error(`Invalid boolean ${f.name}`);
185
+ value = cursor.value === 1;
186
+ break;
187
+ case 1:
188
+ if (cursor.offset + 8 > bytes.length)
189
+ throw new Error(`Truncated double ${f.name}`);
190
+ for (let i = 0; i < 8; i++)
191
+ scratch.setUint8(i, bytes[cursor.offset++]);
192
+ value = scratch.getFloat64(0, true);
193
+ break;
194
+ case 9: {
195
+ (0, protobuf_safe_integer_1.readSafeVarint64)(bytes, cursor, false);
196
+ const length = cursor.value;
197
+ if (length > bytes.length - cursor.offset)
198
+ throw new Error(`Truncated string ${f.name}`);
199
+ value = decoder.decode(bytes.subarray(cursor.offset, cursor.offset + length));
200
+ cursor.offset += length;
201
+ break;
202
+ }
203
+ default: throw new Error(`Unsupported kind ${f.kind}`);
204
+ }
205
+ if (f.index === -1)
206
+ target.customerId = value;
207
+ else
208
+ target.values[f.index] = value;
209
+ }
210
+ if (count !== prepared.length)
211
+ for (let i = 0; i < prepared.length; i++)
212
+ if (seen[i] !== epoch)
213
+ throw new Error(`Missing accumulator field ${prepared[i].name}`);
214
+ }
215
+ function getValue(record, f) {
216
+ const value = f.index === -1 ? record.customerId : record.values[f.index];
217
+ if (value === undefined)
218
+ throw new Error(`Cannot persist missing accumulator value ${f.name}`);
219
+ return value;
220
+ }
221
+ function length(record) {
222
+ if (record.values.length !== graph.length)
223
+ throw new Error('Incorrect graph value array length');
224
+ let result = 0;
225
+ for (const f of prepared) {
226
+ result += (0, protobuf_safe_integer_1.safeVarint64Length)(f.number * 8 + f.wire, false);
227
+ const value = getValue(record, f);
228
+ switch (f.kind) {
229
+ case 3:
230
+ case 4:
231
+ if (f.numberBacked) {
232
+ if (typeof value !== 'number')
233
+ throw new Error(`Expected number for ${f.name}`);
234
+ result += (0, protobuf_safe_integer_1.safeVarint64Length)(value, f.kind === 3);
235
+ }
236
+ else {
237
+ if (typeof value !== 'bigint')
238
+ throw new Error(`Expected bigint for ${f.name}`);
239
+ result += bigVarintLength(toUnsigned(value, f.kind === 3, f.name));
240
+ }
241
+ break;
242
+ case 8:
243
+ if (typeof value !== 'boolean')
244
+ throw new Error(`Expected boolean for ${f.name}`);
245
+ result++;
246
+ break;
247
+ case 1:
248
+ if (typeof value !== 'number')
249
+ throw new Error(`Expected number for ${f.name}`);
250
+ result += 8;
251
+ break;
252
+ case 9:
253
+ if (typeof value !== 'string')
254
+ throw new Error(`Expected string for ${f.name}`);
255
+ {
256
+ const bytes = utf8Length(value);
257
+ result += (0, protobuf_safe_integer_1.safeVarint64Length)(bytes, false) + bytes;
258
+ }
259
+ break;
260
+ }
261
+ }
262
+ return result;
263
+ }
264
+ function encodeInto(record, out, offset, knownLength) {
265
+ const size = knownLength ?? length(record);
266
+ if (!Number.isSafeInteger(offset) || offset < 0 || size > out.length - offset)
267
+ throw new Error('Accumulator output buffer too small');
268
+ const start = offset;
269
+ for (const f of prepared) {
270
+ offset = (0, protobuf_safe_integer_1.writeSafeVarint64)(out, offset, f.number * 8 + f.wire, false);
271
+ const value = getValue(record, f);
272
+ switch (f.kind) {
273
+ case 3:
274
+ case 4:
275
+ if (f.numberBacked)
276
+ offset = (0, protobuf_safe_integer_1.writeSafeVarint64)(out, offset, value, f.kind === 3);
277
+ else
278
+ offset = writeBigVarint(out, offset, toUnsigned(value, f.kind === 3, f.name));
279
+ break;
280
+ case 8:
281
+ out[offset++] = value ? 1 : 0;
282
+ break;
283
+ case 1:
284
+ scratch.setFloat64(0, value, true);
285
+ for (let i = 0; i < 8; i++)
286
+ out[offset++] = scratch.getUint8(i);
287
+ break;
288
+ case 9: {
289
+ const stringValue = value;
290
+ const byteLength = utf8Length(stringValue);
291
+ offset = (0, protobuf_safe_integer_1.writeSafeVarint64)(out, offset, byteLength, false);
292
+ const written = encoder.encodeInto(stringValue, out.subarray(offset, offset + byteLength));
293
+ if (written.written !== byteLength)
294
+ throw new Error(`String encoding failed for ${f.name}`);
295
+ offset += byteLength;
296
+ break;
297
+ }
298
+ }
299
+ }
300
+ return offset - start;
301
+ }
302
+ return { decodeInto: read, encodedLength: length, encodeInto };
303
+ }
304
+ /** Prepare the working type declarations from canonical graph metadata, once per graph. */
305
+ function workingAccumulatorFieldsFromGraph(nodes) {
306
+ return nodes.map(node => {
307
+ return { name: node.metadata.name, valueType: node.valueType };
308
+ });
309
+ }
310
+ //# sourceMappingURL=protobuf.number.projection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protobuf.number.projection.js","sourceRoot":"","sources":["../../src/protobuf.number.projection.ts"],"names":[],"mappings":";;AAuFA,sFA8HC;AAGD,8EAMC;AA3ND,uEAAiE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AAU,CAAC,WAAW,EAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAC,MAAM,GAAC,UAAU,CAAC,CAAC,CAAC;oBACrF,IAAG,OAAO,CAAC,OAAO,KAAG,UAAU;wBAAC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;oBACxF,MAAM,IAAE,UAAU,CAAC;oBAAA,MAAM;gBAC7B,CAAC;YACL,CAAC;QACL,CAAC;QACD,OAAO,MAAM,GAAC,KAAK,CAAC;IACxB,CAAC;IACD,OAAO,EAAC,UAAU,EAAC,IAAI,EAAC,aAAa,EAAC,MAAM,EAAC,UAAU,EAAC,CAAC;AAC7D,CAAC;AAED,2FAA2F;AAC3F,SAAgB,iCAAiC,CAC7C,KAAuF;IAEvF,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAA,EAAE;QACnB,OAAO,EAAC,IAAI,EAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAC,SAAS,EAAC,IAAI,CAAC,SAAS,EAAC,CAAA;IAC7D,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const protobuf_1 = require("@bufbuild/protobuf");
4
+ const errors_1 = require("@cobol-ts/errors");
5
+ const dependency_node_1 = require("@cobol-ts/dependency_node");
6
+ const protobuf_schema_1 = require("./protobuf.schema");
7
+ const protobuf_number_projection_1 = require("./protobuf.number.projection");
8
+ const protobuf_safe_integer_1 = require("./protobuf.safe-integer");
9
+ const canonical = (0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)({
10
+ balance: { type: 'cel', cel: '1', metadata: { type: 'number', celResultType: 'int' } },
11
+ count: { type: 'cel', cel: '1', metadata: { type: 'number', celResultType: 'int' } },
12
+ rate: { type: 'cel', cel: '1.5', metadata: { type: 'number', celResultType: 'double' } },
13
+ label: { type: 'cel', cel: '"x"', metadata: { type: 'string', celResultType: 'string' } }
14
+ }));
15
+ const schema = (0, protobuf_schema_1.accumulatorSchemaFromGraph)(canonical);
16
+ const fields = [
17
+ { name: 'balance', valueType: { kind: 'scalar', semanticType: 'fixed2', javascriptType: 'number' } },
18
+ { name: 'count', valueType: { kind: 'scalar', semanticType: 'integer', javascriptType: 'number' } },
19
+ { name: 'rate', valueType: { kind: 'scalar', semanticType: 'float', javascriptType: 'number' } },
20
+ { name: 'label', valueType: { kind: 'scalar', semanticType: 'string', javascriptType: 'string' } }
21
+ ];
22
+ describe('number-backed Protobuf accumulator projection', () => {
23
+ test('writes standard int64 protobuf bytes and reads directly into reusable number slots', () => {
24
+ const codec = (0, protobuf_number_projection_1.prepareNumberBackedProtobufProjection)(schema, fields);
25
+ const cases = [0, 1, 127, 128, -1, -128, -129, 12345, -12345, 2 ** 32, -(2 ** 32), Number.MAX_SAFE_INTEGER, -Number.MAX_SAFE_INTEGER];
26
+ const target = { customerId: 0n, values: [undefined, undefined, undefined, undefined] };
27
+ for (const amount of cases) {
28
+ const row = { customerId: 1001n, values: [amount, amount, 2.5, 'hello'] };
29
+ const bytes = new Uint8Array(codec.encodedLength(row));
30
+ expect(codec.encodeInto(row, bytes, 0)).toEqual(bytes.length);
31
+ const protobuf = (0, protobuf_1.create)(schema.message, {
32
+ customerId: 1001n, balance: BigInt(amount), count: BigInt(amount), rate: 2.5, label: 'hello'
33
+ });
34
+ // Check legal wire compatibility, not only self-consistent private encoding.
35
+ expect(bytes).toEqual((0, protobuf_1.toBinary)(schema.message, protobuf));
36
+ codec.decodeInto(bytes, target);
37
+ expect(target.customerId).toEqual(1001n);
38
+ expect(target.values).toEqual([amount, amount, 2.5, 'hello']);
39
+ expect(typeof target.values[0]).toEqual('number');
40
+ }
41
+ });
42
+ test('rejects int64 precision loss and schema type mismatches', () => {
43
+ const codec = (0, protobuf_number_projection_1.prepareNumberBackedProtobufProjection)(schema, fields);
44
+ expect(() => codec.encodedLength({ customerId: 1n, values: [Number.MAX_SAFE_INTEGER + 1, 1, 1, 'x'] }))
45
+ .toThrow('Invalid int64 number');
46
+ expect(() => (0, protobuf_number_projection_1.prepareNumberBackedProtobufProjection)(schema, [
47
+ { ...fields[0], valueType: { kind: 'scalar', semanticType: 'string', javascriptType: 'string' } }, fields[1], fields[2], fields[3]
48
+ ])).toThrow('Accumulator schema type incompatible');
49
+ const message = (0, protobuf_1.create)(schema.message, {
50
+ customerId: 1n, balance: 9007199254740993n, count: 0n, rate: 0, label: ''
51
+ });
52
+ const bytes = (0, protobuf_1.toBinary)(schema.message, message);
53
+ const target = { customerId: 0n, values: [undefined, undefined, undefined, undefined] };
54
+ expect(() => codec.decodeInto(bytes, target)).toThrow('Accumulator integer exceeds JavaScript safe-integer range');
55
+ });
56
+ test('signed wire reader/writer have no BigInt intermediary and reject unsafe values', () => {
57
+ const cursor = { offset: 0, value: 0 };
58
+ for (const n of [0, 1, 127, 128, 2 ** 32, Number.MAX_SAFE_INTEGER, -1, -128, -(2 ** 32), -Number.MAX_SAFE_INTEGER]) {
59
+ const bytes = new Uint8Array(10);
60
+ const end = (0, protobuf_safe_integer_1.writeSafeVarint64)(bytes, 0, n, true);
61
+ expect(end).toEqual((0, protobuf_safe_integer_1.safeVarint64Length)(n, true));
62
+ cursor.offset = 0;
63
+ (0, protobuf_safe_integer_1.readSafeVarint64)(bytes.subarray(0, end), cursor, true);
64
+ expect(cursor.value).toEqual(n);
65
+ }
66
+ expect(() => (0, protobuf_safe_integer_1.writeSafeVarint64)(new Uint8Array(10), 0, Number.MAX_SAFE_INTEGER + 1, true)).toThrow();
67
+ expect(() => (0, protobuf_safe_integer_1.writeSafeVarint64)(new Uint8Array(10), 0, -1, false)).toThrow();
68
+ });
69
+ });
70
+ // The persisted descriptor remains a normal Protobuf descriptor. Legacy readers
71
+ // should see the corresponding bigint fields, even when the new graph reader sees numbers.
72
+ const promises_1 = require("node:fs/promises");
73
+ const node_os_1 = require("node:os");
74
+ const node_path_1 = require("node:path");
75
+ const protobuf_number_file_1 = require("./protobuf.number.file");
76
+ const protobuf_accumulator_file_1 = require("./protobuf.accumulator.file");
77
+ describe('number-backed Protobuf file interoperability', () => {
78
+ test('writes standard Protobuf records read by the original message reader', async () => {
79
+ const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'protobuf-number-backed-'));
80
+ const filename = (0, node_path_1.join)(dir, 'accumulator.pb');
81
+ try {
82
+ await (0, protobuf_number_file_1.writeNumberBackedAccumulatorFile)(filename, schema, fields, [
83
+ { customerId: 1n, values: [12345, 10, 1.25, 'first'] },
84
+ { customerId: 2n, values: [-98765, -20, 2.5, 'second'] }
85
+ ]);
86
+ const legacy = [];
87
+ for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(filename)) {
88
+ const data = lease.data;
89
+ legacy.push({ customerId: data.customerId, balance: data.balance, count: data.count, rate: data.rate, label: data.label });
90
+ lease.close();
91
+ }
92
+ expect(legacy).toEqual([
93
+ { customerId: 1n, balance: 12345n, count: 10n, rate: 1.25, label: 'first' },
94
+ { customerId: 2n, balance: -98765n, count: -20n, rate: 2.5, label: 'second' }
95
+ ]);
96
+ const working = [];
97
+ for await (const lease of (0, protobuf_number_file_1.readNumberBackedAccumulatorFile)(filename, fields)) {
98
+ working.push({ customerId: lease.customerId, values: [...lease.values] });
99
+ lease.close();
100
+ }
101
+ expect(working).toEqual([
102
+ { customerId: 1n, values: [12345, 10, 1.25, 'first'] },
103
+ { customerId: 2n, values: [-98765, -20, 2.5, 'second'] }
104
+ ]);
105
+ }
106
+ finally {
107
+ await (0, promises_1.rm)(dir, { recursive: true, force: true });
108
+ }
109
+ });
110
+ });
111
+ //# sourceMappingURL=protobuf.number.projection.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protobuf.number.projection.spec.js","sourceRoot":"","sources":["../../src/protobuf.number.projection.spec.ts"],"names":[],"mappings":";;AAAA,iDAAmD;AACnD,6CAA8C;AAC9C,+DAAoD;A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AAM,CAAC,EAAE,CAAC;gBACxE,OAAO,CAAC,IAAI,CAAC,EAAC,UAAU,EAAC,KAAK,CAAC,UAAU,EAAC,MAAM,EAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,EAAC,CAAC,CAAC;gBACrE,KAAK,CAAC,KAAK,EAAE,CAAC;YAClB,CAAC;YACD,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;gBACpB,EAAC,UAAU,EAAC,EAAE,EAAC,MAAM,EAAC,CAAC,KAAK,EAAC,EAAE,EAAC,IAAI,EAAC,OAAO,CAAC,EAAC;gBAC9C,EAAC,UAAU,EAAC,EAAE,EAAC,MAAM,EAAC,CAAC,CAAC,KAAK,EAAC,CAAC,EAAE,EAAC,GAAG,EAAC,QAAQ,CAAC,EAAC;aACnD,CAAC,CAAC;QACP,CAAC;gBAAS,CAAC;YAAA,MAAM,IAAA,aAAE,EAAC,GAAG,EAAC,EAAC,SAAS,EAAC,IAAI,EAAC,KAAK,EAAC,IAAI,EAAC,CAAC,CAAC;QAAA,CAAC;IAC1D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type RingBuffer } from '@cobol-ts/ring-buffer';
2
+ import type { ValueType, ScalarValueType } from '@cobol-ts/value-types';
3
+ import type { AccumulatorSchema } from './protobuf.schema';
4
+ export type WorkingProtobufElement = number | bigint | boolean | string;
5
+ export type WorkingProtobufValue = WorkingProtobufElement | RingBuffer<WorkingProtobufElement> | undefined;
6
+ export interface MixedNumberBackedRecord {
7
+ customerId: bigint;
8
+ readonly values: WorkingProtobufValue[];
9
+ }
10
+ export interface MixedWorkingAccumulatorField {
11
+ readonly name: string;
12
+ readonly valueType: ScalarValueType | Extract<ValueType, {
13
+ kind: 'rolling-window';
14
+ }>;
15
+ }
16
+ /** Descriptor-driven adapter: native on disk, reusable RingBuffer values in the graph. */
17
+ export declare function prepareRollingNumberBackedProtobufProjection(schema: AccumulatorSchema, graph: readonly MixedWorkingAccumulatorField[]): {
18
+ decodeInto: (bytes: Uint8Array, target: MixedNumberBackedRecord) => void;
19
+ encodedLength: (row: MixedNumberBackedRecord) => number;
20
+ encodeInto(row: MixedNumberBackedRecord, out: Uint8Array, offset: number): number;
21
+ };