@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,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const promises_1 = require("node:fs/promises");
4
+ const node_os_1 = require("node:os");
5
+ const node_path_1 = require("node:path");
6
+ const protobuf_1 = require("@bufbuild/protobuf");
7
+ const dependency_node_1 = require("@cobol-ts/dependency_node");
8
+ const errors_1 = require("@cobol-ts/errors");
9
+ const protobuf_schema_1 = require("./protobuf.schema");
10
+ const protobuf_accumulator_file_1 = require("./protobuf.accumulator.file");
11
+ const authoring = {
12
+ total: { type: 'cel', cel: 'prev.total + input.quantity', metadata: { type: 'number', celResultType: 'int' } },
13
+ score: { type: 'cel', cel: '1.25', metadata: { type: 'number', celResultType: 'double' } },
14
+ errors: { type: 'cel', cel: '"none"', metadata: { type: 'string', celResultType: 'string' } }
15
+ };
16
+ describe('schema-first accumulator through the shared physical record cursor', () => {
17
+ test('three graph-derived records: write, fragmented cursor read, change, write, fragmented cursor reload', async () => {
18
+ const directory = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-protobuf-cursor-'));
19
+ const before = (0, node_path_1.join)(directory, 'before.pb');
20
+ const after = (0, node_path_1.join)(directory, 'after.pb');
21
+ try {
22
+ const schema = (0, protobuf_schema_1.accumulatorSchemaFromGraph)((0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)(authoring)));
23
+ const original = [
24
+ { customerId: 1001n, total: 2n, score: 1.25, errors: 'none' },
25
+ { customerId: 1002n, total: 9n, score: 2.5, errors: 'none' },
26
+ { customerId: 1003n, total: 9007199254740993n, score: 3.75, errors: 'none' }
27
+ ];
28
+ await (0, protobuf_accumulator_file_1.writeAccumulatorFile)(before, schema, original.map(row => (0, protobuf_1.create)(schema.message, row)));
29
+ const schemaRead = await (0, protobuf_accumulator_file_1.readAccumulatorFileSchema)(before);
30
+ expect(schemaRead.messageFullName).toEqual('cobolts.accumulator.Accumulator');
31
+ const saved = [];
32
+ const encountered = [];
33
+ // A tiny buffer forces fragmentation of the bootstrap descriptor and all data records.
34
+ for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(before, { bufferSize: 3 })) {
35
+ const data = lease.data;
36
+ encountered.push({ customerId: data.customerId, total: data.total, score: data.score, errors: data.errors });
37
+ const working = lease;
38
+ expect(working.set('total', data.total + 10n)).toEqual(true);
39
+ expect(working.set('errors', 'updated')).toEqual(true);
40
+ saved.push((0, protobuf_1.create)(schemaRead.message, { ...lease.data }));
41
+ lease.close();
42
+ expect(lease.closed).toEqual(true);
43
+ let diagnostic = '';
44
+ try {
45
+ void lease.data;
46
+ }
47
+ catch (e) {
48
+ diagnostic = e instanceof Error ? e.message : String(e);
49
+ }
50
+ expect(diagnostic).toEqual('Accumulator is closed');
51
+ }
52
+ expect(encountered).toEqual(original);
53
+ await (0, protobuf_accumulator_file_1.writeAccumulatorFile)(after, schemaRead, saved);
54
+ const actual = [];
55
+ for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(after, { bufferSize: 5 })) {
56
+ const data = lease.data;
57
+ actual.push({ customerId: data.customerId, total: data.total, score: data.score, errors: data.errors });
58
+ lease.close();
59
+ }
60
+ expect(actual).toEqual(original.map(row => ({ ...row, total: row.total + 10n, errors: 'updated' })));
61
+ // Both files carry the same embedded runtime schema; no external definition needed for reopening.
62
+ const afterSchema = await (0, protobuf_accumulator_file_1.readAccumulatorFileSchema)(after);
63
+ expect((0, protobuf_1.toBinary)(afterSchema.message, (0, protobuf_1.create)(afterSchema.message, original[0])))
64
+ .toEqual((0, protobuf_1.toBinary)(schema.message, (0, protobuf_1.create)(schema.message, original[0])));
65
+ }
66
+ finally {
67
+ await (0, promises_1.rm)(directory, { recursive: true, force: true });
68
+ }
69
+ });
70
+ test('an accumulator is not returned to the pool merely because the cursor advances', async () => {
71
+ const directory = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-protobuf-cursor-'));
72
+ const filename = (0, node_path_1.join)(directory, 'leases.pb');
73
+ try {
74
+ const schema = (0, protobuf_schema_1.accumulatorSchemaFromGraph)((0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)(authoring)));
75
+ await (0, protobuf_accumulator_file_1.writeAccumulatorFile)(filename, schema, [
76
+ (0, protobuf_1.create)(schema.message, { customerId: 1n, total: 10n }),
77
+ (0, protobuf_1.create)(schema.message, { customerId: 2n, total: 20n })
78
+ ]);
79
+ const reader = (0, protobuf_accumulator_file_1.readAccumulatorFile)(filename, { bufferSize: 3 });
80
+ try {
81
+ const first = (await reader.next()).value;
82
+ const second = (await reader.next()).value;
83
+ expect(first === second).toEqual(false);
84
+ expect(first.closed).toEqual(false);
85
+ expect(first.data.total).toEqual(10n);
86
+ expect(second.data.total).toEqual(20n);
87
+ first.close();
88
+ second.close();
89
+ }
90
+ finally {
91
+ await reader.return();
92
+ }
93
+ }
94
+ finally {
95
+ await (0, promises_1.rm)(directory, { recursive: true, force: true });
96
+ }
97
+ });
98
+ test('schema-only file succeeds and an empty file fails during cursor preparation', async () => {
99
+ const directory = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-protobuf-cursor-'));
100
+ const filename = (0, node_path_1.join)(directory, 'empty.pb');
101
+ try {
102
+ const schema = (0, protobuf_schema_1.accumulatorSchemaFromGraph)((0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)(authoring)));
103
+ await (0, protobuf_accumulator_file_1.writeAccumulatorFile)(filename, schema, []);
104
+ const rows = [];
105
+ for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(filename, { bufferSize: 2 })) {
106
+ rows.push(lease.data);
107
+ lease.close();
108
+ }
109
+ expect(rows).toEqual([]);
110
+ }
111
+ finally {
112
+ await (0, promises_1.rm)(directory, { recursive: true, force: true });
113
+ }
114
+ });
115
+ });
116
+ //# sourceMappingURL=protobuf.cursor.integration.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protobuf.cursor.integration.spec.js","sourceRoot":"","sources":["../../src/protobuf.cursor.integration.spec.ts"],"names":[],"mappings":";;AAAA,+CAA4C;AAC5C,qCAA+B;AAC/B,yCAA+B;AAC/B,iDAAgE;AAEhE,+DAAoD;AACpD,6CAA8C;AAC9C,uDAA6D;AAC7D,2EAA+G;AAE/G,MAAM,SAAS,GAAC;IACZ,KAAK,EAAC,EAAC,IAAI,EAAC,KAAc,EAAC,GAAG,EAAC,6BAA6B,EAAC,QAAQ,EAAC,EAAC,IAAI,EAAC,QAAiB,EAAC,aAAa,EAAC,KAAc,EAAC,EAAC;IAC5H,KAAK,EAAC,EAAC,IAAI,EAAC,KAAc,EAAC,GAAG,EAAC,MAAM,EAAC,QAAQ,EAAC,EAAC,IAAI,EAAC,QAAiB,EAAC,aAAa,EAAC,QAAiB,EAAC,EAAC;IACxG,MAAM,EAAC,EAAC,IAAI,EAAC,KAAc,EAAC,GAAG,EAAC,QAAQ,EAAC,QAAQ,EAAC,EAAC,IAAI,EAAC,QAAiB,EAAC,aAAa,EAAC,QAAiB,EAAC,EAAC;CAC9G,CAAC;AAEF,QAAQ,CAAC,oEAAoE,EAAC,GAAE,EAAE;IAC9E,IAAI,CAAC,qGAAqG,EAAC,KAAK,IAAE,EAAE;QAChH,MAAM,SAAS,GAAC,MAAM,IAAA,kBAAO,EAAC,IAAA,gBAAI,EAAC,IAAA,gBAAM,GAAE,EAAC,0BAA0B,CAAC,CAAC,CAAC;QACzE,MAAM,MAAM,GA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AC,SAAS,EAAC,IAAI,EAAC,KAAK,EAAC,IAAI,EAAC,CAAC,CAAC;QAAA,CAAC;IAChE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { type DescMessage, type Message } from '@bufbuild/protobuf';
2
+ import { type AccumulatorSchema } from './protobuf.schema';
3
+ export declare const envelopeSchema: DescMessage;
4
+ export declare function encodeSchemaEnvelope(schema: AccumulatorSchema): Uint8Array;
5
+ export declare function decodeSchemaEnvelope(bytes: Uint8Array): AccumulatorSchema;
6
+ export declare function decodeSchemaEnvelopeMessage(message: Message): AccumulatorSchema;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.envelopeSchema = void 0;
4
+ exports.encodeSchemaEnvelope = encodeSchemaEnvelope;
5
+ exports.decodeSchemaEnvelope = decodeSchemaEnvelope;
6
+ exports.decodeSchemaEnvelopeMessage = decodeSchemaEnvelopeMessage;
7
+ const protobuf_1 = require("@bufbuild/protobuf");
8
+ const wkt_1 = require("@bufbuild/protobuf/wkt");
9
+ const protobuf_schema_1 = require("./protobuf.schema");
10
+ /** Fixed envelope schema known before reading the experiment-specific schema. */
11
+ const envelopeFile = (0, protobuf_1.create)(wkt_1.FileDescriptorProtoSchema, {
12
+ name: 'cobolts/accumulator/envelope.proto', package: 'cobolts.accumulator', syntax: 'proto3',
13
+ messageType: [(0, protobuf_1.create)(wkt_1.DescriptorProtoSchema, {
14
+ name: 'SchemaEnvelope',
15
+ field: [
16
+ (0, protobuf_1.create)(wkt_1.FieldDescriptorProtoSchema, { name: 'format_version', number: 1, label: 1, type: 13 }),
17
+ (0, protobuf_1.create)(wkt_1.FieldDescriptorProtoSchema, { name: 'descriptor_set', number: 2, label: 1, type: 12 }),
18
+ (0, protobuf_1.create)(wkt_1.FieldDescriptorProtoSchema, { name: 'message_full_name', number: 3, label: 1, type: 9 })
19
+ ]
20
+ })]
21
+ });
22
+ const envelopeDescriptor = (0, protobuf_1.createFileRegistry)((0, protobuf_1.create)(wkt_1.FileDescriptorSetSchema, { file: [envelopeFile] }))
23
+ .getMessage('cobolts.accumulator.SchemaEnvelope');
24
+ if (envelopeDescriptor === undefined)
25
+ throw new Error('Internal Protobuf envelope descriptor is missing');
26
+ exports.envelopeSchema = envelopeDescriptor;
27
+ function encodeSchemaEnvelope(schema) {
28
+ return (0, protobuf_1.toBinary)(exports.envelopeSchema, (0, protobuf_1.create)(exports.envelopeSchema, {
29
+ formatVersion: 1,
30
+ descriptorSet: (0, protobuf_1.toBinary)(wkt_1.FileDescriptorSetSchema, schema.descriptorSet),
31
+ messageFullName: schema.messageFullName
32
+ }));
33
+ }
34
+ function decodeSchemaEnvelope(bytes) {
35
+ return decodeSchemaEnvelopeMessage((0, protobuf_1.fromBinary)(exports.envelopeSchema, bytes));
36
+ }
37
+ function decodeSchemaEnvelopeMessage(message) {
38
+ const raw = message;
39
+ if (raw.formatVersion !== 1)
40
+ throw new Error(`Unsupported accumulator file format version ${String(raw.formatVersion)}`);
41
+ if (typeof raw.messageFullName !== 'string' || raw.messageFullName.length === 0)
42
+ throw new Error('Missing accumulator message name in schema record');
43
+ if (!(raw.descriptorSet instanceof Uint8Array) || raw.descriptorSet.length === 0)
44
+ throw new Error('Missing FileDescriptorSet in schema record');
45
+ const descriptors = (0, protobuf_1.fromBinary)(wkt_1.FileDescriptorSetSchema, raw.descriptorSet);
46
+ return (0, protobuf_schema_1.resolveAccumulatorSchema)(descriptors, raw.messageFullName);
47
+ }
48
+ //# sourceMappingURL=protobuf.envelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protobuf.envelope.js","sourceRoot":"","sources":["../../src/protobuf.envelope.ts"],"names":[],"mappings":";;;AAwBA,oDAMC;AAED,oDAEC;AAED,kEASC;AA7CD,iDAA+G;AAC/G,gDAGgC;AAChC,uDAAkF;AAElF,iFAAiF;AACjF,MAAM,YAAY,GAAC,IAAA,iBAAM,EAAC,+BAAyB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C,CAAC,CAAC,CAAC;AACR,CAAC;AAED,SAAgB,oBAAoB,CAAC,KAAgB;IACjD,OAAO,2BAA2B,CAAC,IAAA,qBAAU,EAAC,sBAAc,EAAC,KAAK,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,SAAgB,2BAA2B,CAAC,OAAe;IACvD,MAAM,GAAG,GAAC,OAA4C,CAAC;IACvD,IAAG,GAAG,CAAC,aAAa,KAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACtH,IAAG,OAAO,GAAG,CAAC,eAAe,KAAG,QAAQ,IAAE,GAAG,CAAC,eAAe,CAAC,MAAM,KAAG,CAAC;QACpE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACzE,IAAG,CAAC,CAAC,GAAG,CAAC,aAAa,YAAY,UAAU,CAAC,IAAE,GAAG,CAAC,aAAa,CAAC,MAAM,KAAG,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAClE,MAAM,WAAW,GAAC,IAAA,qBAAU,EAAC,6BAAuB,EAAC,GAAG,CAAC,aAAa,CAAsB,CAAC;IAC7F,OAAO,IAAA,0CAAwB,EAAC,WAAW,EAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AACrE,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { DescMessage } from '@bufbuild/protobuf';
2
+ import { type CursorFileDefinition, type FileCursorResult } from '@cobol-ts/cursor-file';
3
+ import type { RecordObjectPool } from '@cobol-ts/cursor-record';
4
+ import type { FileBufferPool } from '@cobol-ts/cursor-loader-types';
5
+ export type ProtobufFileOptions<TProjection> = Readonly<{
6
+ filename: string;
7
+ schema: DescMessage;
8
+ projection: CursorFileDefinition<TProjection, 'protobuf'>['projection'];
9
+ bufferSize?: number;
10
+ maxRecordBytes?: number;
11
+ recordPool?: RecordObjectPool<any>;
12
+ byteBufferPool?: FileBufferPool;
13
+ }>;
14
+ export declare function readProtobufFile<TProjection>(options: ProtobufFileOptions<TProjection>): AsyncGenerator<FileCursorResult<TProjection>, void, void>;
15
+ export declare function scanProtobufFile<TProjection>(options: ProtobufFileOptions<TProjection>, onRecord: (row: TProjection, parsed: unknown) => void | boolean): Promise<void>;
16
+ export declare function scanProtobufFileLeased<TProjection>(options: ProtobufFileOptions<TProjection>, onRecord: (lease: FileCursorResult<TProjection>, parsed: unknown) => void | boolean): Promise<void>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readProtobufFile = readProtobufFile;
4
+ exports.scanProtobufFile = scanProtobufFile;
5
+ exports.scanProtobufFileLeased = scanProtobufFileLeased;
6
+ const promises_1 = require("node:fs/promises");
7
+ const cursor_file_1 = require("@cobol-ts/cursor-file");
8
+ const protobuf_parser_1 = require("./protobuf.parser");
9
+ const protobuf_registration_1 = require("./protobuf.registration");
10
+ async function* readProtobufFile(options) {
11
+ const details = (0, protobuf_parser_1.protobufDetails)(options.schema, options.maxRecordBytes);
12
+ const file = await (0, promises_1.open)(options.filename, 'r');
13
+ try {
14
+ yield* (0, cursor_file_1.createThrowingFileCursor)({ filename: options.filename, fileType: 'protobuf', projection: options.projection }, file, { parsers: (0, protobuf_registration_1.createProtobufParserRegistry)(details), bufferSize: options.bufferSize ?? 65536, fillFileBuffer: cursor_file_1.fillNodeFileBuffer,
15
+ recordPool: options.recordPool, byteBufferPool: options.byteBufferPool });
16
+ }
17
+ finally {
18
+ await file.close();
19
+ }
20
+ }
21
+ async function scanProtobufFile(options, onRecord) {
22
+ const details = (0, protobuf_parser_1.protobufDetails)(options.schema, options.maxRecordBytes);
23
+ const file = await (0, promises_1.open)(options.filename, 'r');
24
+ try {
25
+ await (0, cursor_file_1.scanThrowingFileCursor)({ filename: options.filename, fileType: 'protobuf', projection: options.projection }, file, { parsers: (0, protobuf_registration_1.createProtobufParserRegistry)(details), bufferSize: options.bufferSize ?? 65536, fillFileBuffer: cursor_file_1.fillNodeFileBuffer,
26
+ recordPool: options.recordPool, byteBufferPool: options.byteBufferPool }, onRecord);
27
+ }
28
+ finally {
29
+ await file.close();
30
+ }
31
+ }
32
+ async function scanProtobufFileLeased(options, onRecord) {
33
+ const details = (0, protobuf_parser_1.protobufDetails)(options.schema, options.maxRecordBytes);
34
+ const file = await (0, promises_1.open)(options.filename, 'r');
35
+ try {
36
+ await (0, cursor_file_1.scanLeasedFileCursor)({ filename: options.filename, fileType: 'protobuf', projection: options.projection }, file, { parsers: (0, protobuf_registration_1.createProtobufParserRegistry)(details), bufferSize: options.bufferSize ?? 65536, fillFileBuffer: cursor_file_1.fillNodeFileBuffer,
37
+ recordPool: options.recordPool, byteBufferPool: options.byteBufferPool }, onRecord);
38
+ }
39
+ finally {
40
+ await file.close();
41
+ }
42
+ }
43
+ //# sourceMappingURL=protobuf.file.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protobuf.file.node.js","sourceRoot":"","sources":["../../src/protobuf.file.node.ts"],"names":[],"mappings":";;AAkBA,4CAUC;AAED,4CAUC;AAED,wDAUC;AApDD,+CAAsC;AAEtC,uDAA8K;AAG9K,uDAAkD;AAClD,mEAAqE;AAY9D,KAAK,SAAS,CAAC,CAAC,gBAAgB,CAAc,OAAwC;IACzF,MAAM,OAAO,GAAC,IAAA,iCAAe,EAAC,OAAO,CAAC,MAAM,EAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACrE,MAAM,IAAI,GAAC,MAAM,IAAA,eAAI,EAAC,OAAO,CAAC,QAAQ,EAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,CAAC;QACD,KAAK,CAAC,CAAC,IAAA,sCAAwB,EAC3B,EAAC,QAAQ,EAAC,OAAO,CAAC,QAAQ,EAAC,QAAQ,EAAC,UAAU,EAAC,UAAU,EAAC,OAAO,CAAC,UAAU,EAAC,EAAC,IAAI,EAClF,EAAC,OAAO,EAAC,IAAA,oDAA4B,EAAC,OAAO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C,CAAC;IAC5C,IAAI,CAAC;QACD,MAAM,IAAA,kCAAoB,EACtB,EAAC,QAAQ,EAAC,OAAO,CAAC,QAAQ,EAAC,QAAQ,EAAC,UAAU,EAAC,UAAU,EAAC,OAAO,CAAC,UAAU,EAAC,EAAC,IAAI,EAClF,EAAC,OAAO,EAAC,IAAA,oDAA4B,EAAC,OAAO,CAAC,EAAC,UAAU,EAAC,OAAO,CAAC,UAAU,IAAE,KAAK,EAAC,cAAc,EAAC,gCAAkB;YACjH,UAAU,EAAC,OAAO,CAAC,UAAU,EAAC,cAAc,EAAC,OAAO,CAAC,cAAc,EAAC,EAAC,QAAQ,CACpF,CAAC;IACN,CAAC;YAAS,CAAC;QAAA,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IAAA,CAAC;AACnC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const promises_1 = require("node:fs/promises");
4
+ const node_os_1 = require("node:os");
5
+ const node_path_1 = require("node:path");
6
+ const protobuf_1 = require("@bufbuild/protobuf");
7
+ const wkt_1 = require("@bufbuild/protobuf/wkt");
8
+ const cursor_projection_1 = require("@cobol-ts/cursor-projection");
9
+ const protobuf_file_node_1 = require("./protobuf.file.node");
10
+ function framed(bytes) {
11
+ const result = new Uint8Array(bytes.length + 4);
12
+ if (result.length > 65535)
13
+ throw new Error("RDW record exceeds 65535 bytes");
14
+ result[0] = result.length >>> 8;
15
+ result[1] = result.length & 255;
16
+ // RDW control bytes 2 and 3 remain zero.
17
+ result.set(bytes, 4);
18
+ return result;
19
+ }
20
+ function concat(...parts) {
21
+ const result = new Uint8Array(parts.reduce((sum, part) => sum + part.length, 0));
22
+ let offset = 0;
23
+ for (const part of parts) {
24
+ result.set(part, offset);
25
+ offset += part.length;
26
+ }
27
+ return result;
28
+ }
29
+ describe('Protobuf file cursor', () => {
30
+ test('iterates two messages through fragmented physical buffers and projects integer fields', async () => {
31
+ const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-protobuf-'));
32
+ const filename = (0, node_path_1.join)(dir, 'acc.pb');
33
+ try {
34
+ await (0, promises_1.writeFile)(filename, concat(framed((0, protobuf_1.toBinary)(wkt_1.TimestampSchema, (0, protobuf_1.create)(wkt_1.TimestampSchema, { seconds: 1001n, nanos: 4 }))), framed((0, protobuf_1.toBinary)(wkt_1.TimestampSchema, (0, protobuf_1.create)(wkt_1.TimestampSchema, { seconds: 1002n, nanos: 9 })))));
35
+ const projection = (0, cursor_projection_1.defineProjection)({
36
+ customerId: { type: 'integer', path: ['seconds'] },
37
+ count: { type: 'integer', path: ['nanos'] }
38
+ });
39
+ const options = { filename, schema: wkt_1.TimestampSchema, projection, bufferSize: 3 };
40
+ const rows = [];
41
+ for await (const lease of (0, protobuf_file_node_1.readProtobufFile)(options)) {
42
+ try {
43
+ rows.push({ customerId: lease.result.customerId(), count: lease.result.count() });
44
+ }
45
+ finally {
46
+ lease.close();
47
+ }
48
+ }
49
+ expect(rows).toEqual([{ customerId: 1001, count: 4 }, { customerId: 1002, count: 9 }]);
50
+ const scanned = [];
51
+ await (0, protobuf_file_node_1.scanProtobufFile)(options, row => { scanned.push(row.customerId()); });
52
+ expect(scanned).toEqual([1001, 1002]);
53
+ }
54
+ finally {
55
+ await (0, promises_1.rm)(dir, { recursive: true, force: true });
56
+ }
57
+ });
58
+ test('reads a different schema without changing the cursor implementation', async () => {
59
+ const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-protobuf-'));
60
+ const filename = (0, node_path_1.join)(dir, 'acc.pb');
61
+ try {
62
+ await (0, promises_1.writeFile)(filename, framed((0, protobuf_1.toBinary)(wkt_1.DurationSchema, (0, protobuf_1.create)(wkt_1.DurationSchema, { seconds: 42n, nanos: 17 }))));
63
+ const projection = (0, cursor_projection_1.defineProjection)({
64
+ seconds: { type: 'integer' }, nanos: { type: 'integer' }
65
+ });
66
+ const rows = [];
67
+ for await (const lease of (0, protobuf_file_node_1.readProtobufFile)({ filename, schema: wkt_1.DurationSchema, projection, bufferSize: 5 })) {
68
+ try {
69
+ rows.push([lease.result.seconds(), lease.result.nanos()]);
70
+ }
71
+ finally {
72
+ lease.close();
73
+ }
74
+ }
75
+ expect(rows).toEqual([[42, 17]]);
76
+ }
77
+ finally {
78
+ await (0, promises_1.rm)(dir, { recursive: true, force: true });
79
+ }
80
+ });
81
+ test('reads an empty file as zero records', async () => {
82
+ const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-protobuf-'));
83
+ const filename = (0, node_path_1.join)(dir, 'empty.pb');
84
+ try {
85
+ await (0, promises_1.writeFile)(filename, new Uint8Array());
86
+ const projection = (0, cursor_projection_1.defineProjection)({ seconds: { type: 'integer' } });
87
+ let count = 0;
88
+ for await (const row of (0, protobuf_file_node_1.readProtobufFile)({ filename, schema: wkt_1.TimestampSchema, projection, bufferSize: 4 })) {
89
+ count++;
90
+ row.close();
91
+ }
92
+ expect(count).toEqual(0);
93
+ }
94
+ finally {
95
+ await (0, promises_1.rm)(dir, { recursive: true, force: true });
96
+ }
97
+ });
98
+ test('reports a truncated record instead of treating it as an empty trailing record', async () => {
99
+ const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-protobuf-'));
100
+ const filename = (0, node_path_1.join)(dir, 'truncated.pb');
101
+ try {
102
+ await (0, promises_1.writeFile)(filename, Uint8Array.from([0, 12, 0, 0, 8, 1]));
103
+ const projection = (0, cursor_projection_1.defineProjection)({ seconds: { type: 'integer' } });
104
+ let message = '';
105
+ try {
106
+ for await (const row of (0, protobuf_file_node_1.readProtobufFile)({ filename, schema: wkt_1.TimestampSchema, projection, bufferSize: 3 }))
107
+ row.close();
108
+ }
109
+ catch (error) {
110
+ message = error instanceof Error ? error.message : String(error);
111
+ }
112
+ expect(message).toEqual('Truncated Protobuf record: expected 12 bytes, got 6');
113
+ }
114
+ finally {
115
+ await (0, promises_1.rm)(dir, { recursive: true, force: true });
116
+ }
117
+ });
118
+ });
119
+ describe('Protobuf RDW edge cases', () => {
120
+ test('accepts a valid empty message payload', async () => {
121
+ const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-protobuf-'));
122
+ const filename = (0, node_path_1.join)(dir, 'empty-message.pb');
123
+ try {
124
+ await (0, promises_1.writeFile)(filename, Uint8Array.from([0, 4, 0, 0]));
125
+ const projection = (0, cursor_projection_1.defineProjection)({ seconds: { type: 'integer' } });
126
+ const rows = [];
127
+ for await (const lease of (0, protobuf_file_node_1.readProtobufFile)({ filename, schema: wkt_1.TimestampSchema, projection, bufferSize: 2 })) {
128
+ try {
129
+ rows.push(lease.result.seconds());
130
+ }
131
+ finally {
132
+ lease.close();
133
+ }
134
+ }
135
+ expect(rows).toEqual([0]);
136
+ }
137
+ finally {
138
+ await (0, promises_1.rm)(dir, { recursive: true, force: true });
139
+ }
140
+ });
141
+ test('rejects unsupported RDW control bytes', async () => {
142
+ const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-protobuf-'));
143
+ const filename = (0, node_path_1.join)(dir, 'bad-control.pb');
144
+ try {
145
+ await (0, promises_1.writeFile)(filename, Uint8Array.from([0, 4, 1, 0]));
146
+ const projection = (0, cursor_projection_1.defineProjection)({ seconds: { type: 'integer' } });
147
+ let message = '';
148
+ try {
149
+ for await (const lease of (0, protobuf_file_node_1.readProtobufFile)({ filename, schema: wkt_1.TimestampSchema, projection, bufferSize: 2 }))
150
+ lease.close();
151
+ }
152
+ catch (error) {
153
+ message = error instanceof Error ? error.message : String(error);
154
+ }
155
+ expect(message).toEqual('Unsupported Protobuf RDW control bytes 1, 0');
156
+ }
157
+ finally {
158
+ await (0, promises_1.rm)(dir, { recursive: true, force: true });
159
+ }
160
+ });
161
+ });
162
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AAC,UAAU,EAAC,CAAC,EAAC,CAAC;oBAAE,KAAK,CAAC,KAAK,EAAE,CAAC;YACxH,CAAC;YAAC,OAAM,KAAK,EAAE,CAAC;gBAAA,OAAO,GAAC,KAAK,YAAY,KAAK,CAAA,CAAC,CAAA,KAAK,CAAC,OAAO,CAAA,CAAC,CAAA,MAAM,CAAC,KAAK,CAAC,CAAC;YAAA,CAAC;YAC5E,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,6CAA6C,CAAC,CAAC;QAC3E,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,7 @@
1
+ import { type Message } from '@bufbuild/protobuf';
2
+ import type { AccumulatorSchema } from './protobuf.schema';
3
+ import type { ScalarAccumulatorCodec } from './protobuf.scalar.codec';
4
+ /** Native Protobuf accumulator adapter for mixed scalar/window descriptors.
5
+ * Unlike the scalar-only optimised codec, this uses Protobuf's standard wire
6
+ * encoder. The pooled outer message and nested windows retain their identity. */
7
+ export declare function createMixedAccumulatorCodec<T extends Message>(schema: AccumulatorSchema): ScalarAccumulatorCodec<T>;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMixedAccumulatorCodec = createMixedAccumulatorCodec;
4
+ const protobuf_1 = require("@bufbuild/protobuf");
5
+ const protobuf_rolling_layout_1 = require("./protobuf.rolling.layout");
6
+ /** Native Protobuf accumulator adapter for mixed scalar/window descriptors.
7
+ * Unlike the scalar-only optimised codec, this uses Protobuf's standard wire
8
+ * encoder. The pooled outer message and nested windows retain their identity. */
9
+ function createMixedAccumulatorCodec(schema) {
10
+ const layouts = (0, protobuf_rolling_layout_1.protobufRollingLayouts)(schema);
11
+ const fieldNames = schema.descriptorSet.file.flatMap(f => f.messageType)
12
+ .find(m => m.name === 'Accumulator')?.field.map(f => f.name) ?? [];
13
+ const typeNames = new Map(schema.descriptorSet.file.flatMap(f => f.messageType)
14
+ .find(m => m.name === 'Accumulator')?.field.filter(f => f.type === 11)
15
+ .map(f => [f.name, (f.typeName ?? '').replace(/^\./, '')]) ?? []);
16
+ function emptyWindow(name) {
17
+ const layout = layouts.get(name);
18
+ return { $typeName: typeNames.get(name), count: 0, excluded: 0, hasExpired: false,
19
+ values: Array(layout.size + 1).fill((0, protobuf_rolling_layout_1.emptyProtobufScalar)(layout.element)) };
20
+ }
21
+ function validateWindow(name, raw) {
22
+ const layout = layouts.get(name);
23
+ if (typeof raw !== 'object' || raw === null)
24
+ throw new Error(`Missing Protobuf rolling-window ${name}`);
25
+ const w = raw;
26
+ if (!Number.isInteger(w.count) || Number(w.count) < 0 || Number(w.count) > layout.size ||
27
+ !Number.isInteger(w.excluded) || Number(w.excluded) < 0 || Number(w.excluded) > layout.size ||
28
+ typeof w.hasExpired !== 'boolean' || (w.hasExpired && w.count !== layout.size) ||
29
+ (!w.hasExpired && w.excluded !== 0) || !Array.isArray(w.values) || w.values.length !== layout.size + 1)
30
+ throw new Error(`Invalid Protobuf rolling-window state ${name}`);
31
+ for (const value of w.values) {
32
+ if (typeof value !== layout.element.javascriptType)
33
+ throw new Error(`Invalid Protobuf rolling-window element ${name}`);
34
+ }
35
+ }
36
+ function validate(source) {
37
+ for (const name of fieldNames) {
38
+ if (source[name] === undefined)
39
+ throw new Error(`Missing accumulator field ${name}`);
40
+ if (layouts.has(name))
41
+ validateWindow(name, source[name]);
42
+ }
43
+ }
44
+ function encode(message) {
45
+ validate(message);
46
+ return (0, protobuf_1.toBinary)(schema.message, message);
47
+ }
48
+ return {
49
+ initialize(message, customerId) {
50
+ const target = message;
51
+ for (const f of schema.descriptorSet.file.flatMap(f => f.messageType)
52
+ .find(m => m.name === 'Accumulator').field) {
53
+ if (f.name === 'customerId')
54
+ target[f.name] = customerId;
55
+ else if (layouts.has(f.name)) {
56
+ const current = target[f.name];
57
+ const next = emptyWindow(f.name);
58
+ if (current && Array.isArray(current.values) && current.values.length === next.values.length) {
59
+ current.values.fill((0, protobuf_rolling_layout_1.emptyProtobufScalar)(layouts.get(f.name).element));
60
+ current.count = 0;
61
+ current.excluded = 0;
62
+ current.hasExpired = false;
63
+ }
64
+ else
65
+ target[f.name] = next;
66
+ }
67
+ else
68
+ target[f.name] = f.type === 3 || f.type === 4 ? 0n : f.type === 1 ? 0 : f.type === 8 ? false : '';
69
+ }
70
+ },
71
+ decodeInto(bytes, message) {
72
+ const incoming = (0, protobuf_1.fromBinary)(schema.message, bytes);
73
+ validate(incoming);
74
+ const target = message;
75
+ for (const name of fieldNames) {
76
+ if (!layouts.has(name)) {
77
+ target[name] = incoming[name];
78
+ continue;
79
+ }
80
+ const next = incoming[name];
81
+ const current = target[name];
82
+ if (current && Array.isArray(current.values) && current.values.length === next.values.length) {
83
+ current.count = next.count;
84
+ current.excluded = next.excluded;
85
+ current.hasExpired = next.hasExpired;
86
+ const values = current.values;
87
+ for (let i = 0; i < values.length; i++)
88
+ values[i] = next.values[i];
89
+ }
90
+ else
91
+ target[name] = next;
92
+ }
93
+ },
94
+ encodedLength(message) { return encode(message).length; },
95
+ encodeInto(message, out, offset) {
96
+ const bytes = encode(message);
97
+ if (!Number.isSafeInteger(offset) || offset < 0 || bytes.length > out.length - offset)
98
+ throw new Error('Accumulator output buffer too small');
99
+ out.set(bytes, offset);
100
+ return bytes.length;
101
+ },
102
+ encode
103
+ };
104
+ }
105
+ //# sourceMappingURL=protobuf.mixed.codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protobuf.mixed.codec.js","sourceRoot":"","sources":["../../src/protobuf.mixed.codec.ts"],"names":[],"mappings":";;AAQA,kEA4EC;AApFD,iDAAoE;AAGpE,uEAAqF;AAErF;;iFAEiF;AACjF,SAAgB,2BAA2B,CAAoB,MAAwB;IACnF,MAAM,OAA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T,CAAC;AACN,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { AccumulatorSchema } from './protobuf.schema';
2
+ import { type WorkingAccumulatorField, type NumberBackedRecord } from './protobuf.number.projection';
3
+ export interface NumberBackedAccumulatorLease extends NumberBackedRecord {
4
+ readonly closed: boolean;
5
+ close(): void;
6
+ }
7
+ /**
8
+ * Opens the same schema-first RDW file as readAccumulatorFile, but projects int64
9
+ * fields directly into graph-native numbers. The iterator leases arrays and
10
+ * physical records; consumers must call close() on each yielded record.
11
+ */
12
+ export declare function readNumberBackedAccumulatorFile(filename: string, graph: readonly WorkingAccumulatorField[], options?: {
13
+ bufferSize?: number;
14
+ maxRecordBytes?: number;
15
+ }): AsyncGenerator<NumberBackedAccumulatorLease, void, void>;
16
+ /** Writes graph-native number slots to legal Protobuf scalar fields, using the existing buffered RDW writer. */
17
+ export declare function writeNumberBackedAccumulatorFile(filename: string, schema: AccumulatorSchema, graph: readonly WorkingAccumulatorField[], rows: Iterable<NumberBackedRecord> | AsyncIterable<NumberBackedRecord>): Promise<void>;