@cobol-ts/cursor-loader-protobuf 0.0.0-stage → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -2
- package/dist/index.d.ts +18 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/src/protobuf.accumulator.d.ts +24 -0
- package/dist/src/protobuf.accumulator.file.d.ts +24 -0
- package/dist/src/protobuf.accumulator.file.js +164 -0
- package/dist/src/protobuf.accumulator.file.js.map +1 -0
- package/dist/src/protobuf.accumulator.js +110 -0
- package/dist/src/protobuf.accumulator.js.map +1 -0
- package/dist/src/protobuf.buffered.spec.d.ts +1 -0
- package/dist/src/protobuf.buffered.spec.js +97 -0
- package/dist/src/protobuf.buffered.spec.js.map +1 -0
- package/dist/src/protobuf.cursor.integration.spec.d.ts +1 -0
- package/dist/src/protobuf.cursor.integration.spec.js +116 -0
- package/dist/src/protobuf.cursor.integration.spec.js.map +1 -0
- package/dist/src/protobuf.envelope.d.ts +6 -0
- package/dist/src/protobuf.envelope.js +48 -0
- package/dist/src/protobuf.envelope.js.map +1 -0
- package/dist/src/protobuf.file.node.d.ts +16 -0
- package/dist/src/protobuf.file.node.js +43 -0
- package/dist/src/protobuf.file.node.js.map +1 -0
- package/dist/src/protobuf.file.spec.d.ts +1 -0
- package/dist/src/protobuf.file.spec.js +162 -0
- package/dist/src/protobuf.file.spec.js.map +1 -0
- package/dist/src/protobuf.mixed.codec.d.ts +7 -0
- package/dist/src/protobuf.mixed.codec.js +105 -0
- package/dist/src/protobuf.mixed.codec.js.map +1 -0
- package/dist/src/protobuf.number.file.d.ts +17 -0
- package/dist/src/protobuf.number.file.js +107 -0
- package/dist/src/protobuf.number.file.js.map +1 -0
- package/dist/src/protobuf.number.projection.d.ts +25 -0
- package/dist/src/protobuf.number.projection.js +310 -0
- package/dist/src/protobuf.number.projection.js.map +1 -0
- package/dist/src/protobuf.number.projection.spec.d.ts +1 -0
- package/dist/src/protobuf.number.projection.spec.js +111 -0
- package/dist/src/protobuf.number.projection.spec.js.map +1 -0
- package/dist/src/protobuf.number.rolling.d.ts +21 -0
- package/dist/src/protobuf.number.rolling.js +162 -0
- package/dist/src/protobuf.number.rolling.js.map +1 -0
- package/dist/src/protobuf.parser.d.ts +35 -0
- package/dist/src/protobuf.parser.js +142 -0
- package/dist/src/protobuf.parser.js.map +1 -0
- package/dist/src/protobuf.projection.support.d.ts +14 -0
- package/dist/src/protobuf.projection.support.js +75 -0
- package/dist/src/protobuf.projection.support.js.map +1 -0
- package/dist/src/protobuf.rdw.d.ts +15 -0
- package/dist/src/protobuf.rdw.js +107 -0
- package/dist/src/protobuf.rdw.js.map +1 -0
- package/dist/src/protobuf.registration.d.ts +3 -0
- package/dist/src/protobuf.registration.js +8 -0
- package/dist/src/protobuf.registration.js.map +1 -0
- package/dist/src/protobuf.reuse.spec.d.ts +1 -0
- package/dist/src/protobuf.reuse.spec.js +117 -0
- package/dist/src/protobuf.reuse.spec.js.map +1 -0
- package/dist/src/protobuf.rolling.layout.d.ts +13 -0
- package/dist/src/protobuf.rolling.layout.js +69 -0
- package/dist/src/protobuf.rolling.layout.js.map +1 -0
- package/dist/src/protobuf.rolling.spec.d.ts +1 -0
- package/dist/src/protobuf.rolling.spec.js +174 -0
- package/dist/src/protobuf.rolling.spec.js.map +1 -0
- package/dist/src/protobuf.roundtrip.spec.d.ts +1 -0
- package/dist/src/protobuf.roundtrip.spec.js +195 -0
- package/dist/src/protobuf.roundtrip.spec.js.map +1 -0
- package/dist/src/protobuf.safe-integer.d.ts +10 -0
- package/dist/src/protobuf.safe-integer.js +88 -0
- package/dist/src/protobuf.safe-integer.js.map +1 -0
- package/dist/src/protobuf.scalar.codec.d.ts +17 -0
- package/dist/src/protobuf.scalar.codec.js +276 -0
- package/dist/src/protobuf.scalar.codec.js.map +1 -0
- package/dist/src/protobuf.schema.d.ts +17 -0
- package/dist/src/protobuf.schema.first.parser.d.ts +10 -0
- package/dist/src/protobuf.schema.first.parser.js +23 -0
- package/dist/src/protobuf.schema.first.parser.js.map +1 -0
- package/dist/src/protobuf.schema.js +91 -0
- package/dist/src/protobuf.schema.js.map +1 -0
- package/package.json +68 -3
|
@@ -0,0 +1,117 @@
|
|
|
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_accumulator_1 = require("./protobuf.accumulator");
|
|
8
|
+
const protobuf_scalar_codec_1 = require("./protobuf.scalar.codec");
|
|
9
|
+
const promises_1 = require("node:fs/promises");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
const node_os_1 = require("node:os");
|
|
12
|
+
const protobuf_accumulator_file_1 = require("./protobuf.accumulator.file");
|
|
13
|
+
const graph = {
|
|
14
|
+
count: { type: 'cel', cel: 'prev.count + 1', metadata: { type: 'number', celResultType: 'int' } },
|
|
15
|
+
score: { type: 'cel', cel: '1.5', metadata: { type: 'number', celResultType: 'double' } },
|
|
16
|
+
enabled: { type: 'cel', cel: 'true', metadata: { type: 'boolean', celResultType: 'bool' } },
|
|
17
|
+
note: { type: 'cel', cel: '"yes"', metadata: { type: 'string', celResultType: 'string' } }
|
|
18
|
+
};
|
|
19
|
+
function fixture() {
|
|
20
|
+
const schema = (0, protobuf_schema_1.accumulatorSchemaFromGraph)((0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)(graph)));
|
|
21
|
+
return { schema, codec: (0, protobuf_scalar_codec_1.createScalarAccumulatorCodec)(schema) };
|
|
22
|
+
}
|
|
23
|
+
describe('pooled accumulator message reuse', () => {
|
|
24
|
+
test('reuses both wrapper and protobuf message, overwriting default scalar values', () => {
|
|
25
|
+
const { schema, codec } = fixture();
|
|
26
|
+
const pool = (0, protobuf_accumulator_1.createMessageAccumulatorPool)(schema.message, codec);
|
|
27
|
+
const first = pool.acquire(codec.encode((0, protobuf_1.create)(schema.message, {
|
|
28
|
+
customerId: 101n, count: 100n, score: 12.5, enabled: true, note: 'previous'
|
|
29
|
+
})));
|
|
30
|
+
const message = first.data;
|
|
31
|
+
expect(message.count).toEqual(100n);
|
|
32
|
+
first.close();
|
|
33
|
+
const second = pool.acquire(codec.encode((0, protobuf_1.create)(schema.message, {
|
|
34
|
+
customerId: 102n, count: 0n, score: 0, enabled: false, note: ''
|
|
35
|
+
})));
|
|
36
|
+
expect(second === first).toEqual(true);
|
|
37
|
+
expect(second.data === message).toEqual(true);
|
|
38
|
+
const data = second.data;
|
|
39
|
+
expect({ customerId: data.customerId, count: data.count, score: data.score, enabled: data.enabled, note: data.note })
|
|
40
|
+
.toEqual({ customerId: 102n, count: 0n, score: 0, enabled: false, note: '' });
|
|
41
|
+
second.close();
|
|
42
|
+
});
|
|
43
|
+
test('rejects missing fields instead of letting a previous customer value leak', () => {
|
|
44
|
+
const { schema, codec } = fixture();
|
|
45
|
+
const pool = (0, protobuf_accumulator_1.createMessageAccumulatorPool)(schema.message, codec);
|
|
46
|
+
const first = pool.acquire(codec.encode((0, protobuf_1.create)(schema.message, {
|
|
47
|
+
customerId: 101n, count: 100n, score: 12.5, enabled: true, note: 'previous'
|
|
48
|
+
})));
|
|
49
|
+
first.close();
|
|
50
|
+
let error = '';
|
|
51
|
+
try {
|
|
52
|
+
pool.acquire((0, protobuf_1.toBinary)(schema.message, (0, protobuf_1.create)(schema.message, { customerId: 102n })));
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
error = e instanceof Error ? e.message : String(e);
|
|
56
|
+
}
|
|
57
|
+
expect(error).toEqual('Missing accumulator field count');
|
|
58
|
+
const second = pool.acquire(codec.encode((0, protobuf_1.create)(schema.message, {
|
|
59
|
+
customerId: 103n, count: 0n, score: 0, enabled: false, note: ''
|
|
60
|
+
})));
|
|
61
|
+
expect(second.data.customerId).toEqual(103n);
|
|
62
|
+
second.close();
|
|
63
|
+
});
|
|
64
|
+
test('the actual schema-first cursor reuses both objects across records and preserves values', async () => {
|
|
65
|
+
const directory = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-proto-reuse-'));
|
|
66
|
+
const filename = (0, node_path_1.join)(directory, 'data.pb');
|
|
67
|
+
const { schema } = fixture();
|
|
68
|
+
try {
|
|
69
|
+
await (0, protobuf_accumulator_file_1.writeAccumulatorFile)(filename, schema, [
|
|
70
|
+
(0, protobuf_1.create)(schema.message, { customerId: 101n, count: 17n, score: 3.5, enabled: true, note: 'first' }),
|
|
71
|
+
(0, protobuf_1.create)(schema.message, { customerId: 102n, count: 0n, score: 0, enabled: false, note: '' }),
|
|
72
|
+
(0, protobuf_1.create)(schema.message, { customerId: 103n, count: 9007199254740993n, score: -2.5, enabled: true, note: 'last' })
|
|
73
|
+
]);
|
|
74
|
+
let wrapper;
|
|
75
|
+
let message;
|
|
76
|
+
const actual = [];
|
|
77
|
+
for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(filename, { bufferSize: 3 })) {
|
|
78
|
+
if (wrapper !== undefined) {
|
|
79
|
+
expect(lease === wrapper).toEqual(true);
|
|
80
|
+
expect(lease.data === message).toEqual(true);
|
|
81
|
+
}
|
|
82
|
+
wrapper = lease;
|
|
83
|
+
message = lease.data;
|
|
84
|
+
const d = lease.data;
|
|
85
|
+
actual.push({ customerId: d.customerId, count: d.count, score: d.score, enabled: d.enabled, note: d.note });
|
|
86
|
+
lease.close();
|
|
87
|
+
}
|
|
88
|
+
expect(actual).toEqual([
|
|
89
|
+
{ customerId: 101n, count: 17n, score: 3.5, enabled: true, note: 'first' },
|
|
90
|
+
{ customerId: 102n, count: 0n, score: 0, enabled: false, note: '' },
|
|
91
|
+
{ customerId: 103n, count: 9007199254740993n, score: -2.5, enabled: true, note: 'last' }
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
await (0, promises_1.rm)(directory, { recursive: true, force: true });
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('missing persisted accumulator state uses the same pool', () => {
|
|
100
|
+
test('a missing entity reuses the decoded message, replacing all prior fields with graph defaults', () => {
|
|
101
|
+
const { schema, codec } = fixture();
|
|
102
|
+
const pool = (0, protobuf_accumulator_1.createMessageAccumulatorPool)(schema.message, codec);
|
|
103
|
+
const persisted = pool.acquire(codec.encode((0, protobuf_1.create)(schema.message, {
|
|
104
|
+
customerId: 1001n, count: 123n, score: 8.5, enabled: true, note: 'persisted'
|
|
105
|
+
})));
|
|
106
|
+
const message = persisted.data;
|
|
107
|
+
persisted.close();
|
|
108
|
+
const missing = pool.acquireEmpty(1002n);
|
|
109
|
+
expect(missing === persisted).toEqual(true);
|
|
110
|
+
expect(missing.data === message).toEqual(true);
|
|
111
|
+
const data = missing.data;
|
|
112
|
+
expect({ customerId: data.customerId, count: data.count, score: data.score, enabled: data.enabled, note: data.note })
|
|
113
|
+
.toEqual({ customerId: 1002n, count: 0n, score: 0, enabled: false, note: '' });
|
|
114
|
+
missing.close();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=protobuf.reuse.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protobuf.reuse.spec.js","sourceRoot":"","sources":["../../src/protobuf.reuse.spec.ts"],"names":[],"mappings":";;AAAA,iDAAmD;AACnD,6CAA8C;AAC9C,+DAAoD;AACpD,uDAA6D;AAC7D,iEAAoE;AACpE,mEAAqE;AACrE,+CAA4C;AAC5C,yCAA+B;AAC/B,qCAA+B;AAC/B,2EAAqF;AAErF,MAAM,KAAK,GAAC;IACR,KAAK,EAAC,EAAC,IAAI,EAAC,KAAc,EAAC,GAAG,EAAC,gBAAgB,EAAC,QAAQ,EAAC,EAAC,IAAI,EAAC,QAAiB,EA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AAC;QACxE,OAAO,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ScalarValueType, RollingWindowValueType } from '@cobol-ts/value-types';
|
|
2
|
+
import type { AccumulatorSchema } from './protobuf.schema';
|
|
3
|
+
/** The descriptor is the authority for a persisted window's length, periodicity and element kind.
|
|
4
|
+
* Encode the arbitrary periodicity as UTF-16 hex so no runtime registry of units is needed. */
|
|
5
|
+
export declare function rollingMessageName(name: string, window: RollingWindowValueType): string;
|
|
6
|
+
export interface ProtobufRollingLayout {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly size: number;
|
|
9
|
+
readonly periodicity: string;
|
|
10
|
+
readonly element: ScalarValueType;
|
|
11
|
+
}
|
|
12
|
+
export declare function protobufRollingLayouts(schema: AccumulatorSchema): ReadonlyMap<string, ProtobufRollingLayout>;
|
|
13
|
+
export declare function emptyProtobufScalar(type: ScalarValueType): number | bigint | boolean | string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rollingMessageName = rollingMessageName;
|
|
4
|
+
exports.protobufRollingLayouts = protobufRollingLayouts;
|
|
5
|
+
exports.emptyProtobufScalar = emptyProtobufScalar;
|
|
6
|
+
/** The descriptor is the authority for a persisted window's length, periodicity and element kind.
|
|
7
|
+
* Encode the arbitrary periodicity as UTF-16 hex so no runtime registry of units is needed. */
|
|
8
|
+
function rollingMessageName(name, window) {
|
|
9
|
+
let encoded = '';
|
|
10
|
+
for (let i = 0; i < window.periodicity.length; i++)
|
|
11
|
+
encoded += window.periodicity.charCodeAt(i).toString(16).padStart(4, '0');
|
|
12
|
+
return `Window_${name}_S${window.size}_P${encoded}`;
|
|
13
|
+
}
|
|
14
|
+
function elementType(kind) {
|
|
15
|
+
switch (kind) {
|
|
16
|
+
case 1: return { kind: 'scalar', semanticType: 'float', javascriptType: 'number' };
|
|
17
|
+
case 3: return { kind: 'scalar', semanticType: 'integer', javascriptType: 'bigint' };
|
|
18
|
+
case 4: return { kind: 'scalar', semanticType: 'unsignedInteger', javascriptType: 'bigint' };
|
|
19
|
+
case 8: return { kind: 'scalar', semanticType: 'boolean', javascriptType: 'boolean' };
|
|
20
|
+
case 9: return { kind: 'scalar', semanticType: 'string', javascriptType: 'string' };
|
|
21
|
+
default: throw new Error(`Unsupported Protobuf rolling-window element type ${kind}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function protobufRollingLayouts(schema) {
|
|
25
|
+
const descriptor = schema.descriptorSet.file.flatMap(f => f.messageType).find(m => m.name === 'Accumulator');
|
|
26
|
+
if (!descriptor)
|
|
27
|
+
throw new Error('Accumulator descriptor not found');
|
|
28
|
+
const messages = new Map(schema.descriptorSet.file.flatMap(f => f.messageType).map(m => [m.name, m]));
|
|
29
|
+
const result = new Map();
|
|
30
|
+
for (const field of descriptor.field) {
|
|
31
|
+
if (field.type !== 11)
|
|
32
|
+
continue;
|
|
33
|
+
const name = field.typeName?.split('.').pop() ?? '';
|
|
34
|
+
const prefix = `Window_${field.name}_S`;
|
|
35
|
+
if (!name.startsWith(prefix))
|
|
36
|
+
throw new Error(`Invalid rolling-window descriptor for ${field.name}`);
|
|
37
|
+
const suffix = name.slice(prefix.length), match = /^([1-9][0-9]*)_P((?:[0-9a-f]{4})+)$/.exec(suffix);
|
|
38
|
+
if (!match)
|
|
39
|
+
throw new Error(`Invalid rolling-window layout metadata for ${field.name}`);
|
|
40
|
+
const size = Number(match[1]);
|
|
41
|
+
if (!Number.isSafeInteger(size) || size > 65535)
|
|
42
|
+
throw new Error(`Invalid rolling-window capacity for ${field.name}`);
|
|
43
|
+
const hex = match[2];
|
|
44
|
+
let periodicity = '';
|
|
45
|
+
for (let i = 0; i < hex.length; i += 4)
|
|
46
|
+
periodicity += String.fromCharCode(parseInt(hex.slice(i, i + 4), 16));
|
|
47
|
+
const message = messages.get(name);
|
|
48
|
+
if (!message)
|
|
49
|
+
throw new Error(`Missing rolling-window message ${name}`);
|
|
50
|
+
const fields = message.field;
|
|
51
|
+
if (fields.length !== 4 || fields[0].name !== 'count' || fields[0].type !== 13 ||
|
|
52
|
+
fields[1].name !== 'excluded' || fields[1].type !== 13 ||
|
|
53
|
+
fields[2].name !== 'hasExpired' || fields[2].type !== 8 ||
|
|
54
|
+
fields[3].name !== 'values' || fields[3].label !== 3)
|
|
55
|
+
throw new Error(`Invalid rolling-window message fields for ${field.name}`);
|
|
56
|
+
result.set(field.name, { name: field.name, size, periodicity, element: elementType(fields[3].type) });
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
function emptyProtobufScalar(type) {
|
|
61
|
+
switch (type.javascriptType) {
|
|
62
|
+
case 'bigint': return 0n;
|
|
63
|
+
case 'number': return 0;
|
|
64
|
+
case 'string': return '';
|
|
65
|
+
case 'boolean': return false;
|
|
66
|
+
default: throw new Error('Unsupported Protobuf scalar representation');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=protobuf.rolling.layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protobuf.rolling.layout.js","sourceRoot":"","sources":["../../src/protobuf.rolling.layout.ts"],"names":[],"mappings":";;AAKA,gDAIC;AAkBD,wDA2BC;AAED,kDAGC;AAxDD;+FAC+F;AAC/F,SAAgB,kBAAkB,CAAC,IAAW,EAAC,MAA6B;IACxE,IAAI,OAAO,GAAC,EAAE,CAAC;IACf,KAAI,IAAI,CAAC,GAAC,CAAC,EAAC,CAAC,GAAC,MAAM,CAAC,WAAW,CAAC,MAAM,EAAC,CAAC,EAAE;QAAE,OAAO,IAAE,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAC,GAAG,CAAC,CAA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AED,SAAgB,mBAAmB,CAAC,IAAoB;IACpD,QAAO,IAAI,CAAC,cAAc,EAAC,CAAC;QAAA,KAAK,QAAQ,CAAC,CAAA,OAAO,EAAE,CAAC;QAAA,KAAK,QAAQ,CAAC,CAAA,OAAO,CAAC,CAAC;QAAA,KAAK,QAAQ,CAAC,CAAA,OAAO,EAAE,CAAC;QAAA,KAAK,SAAS,CAAC,CAAA,OAAO,KAAK,CAAC;QAC3H,OAAO,CAAC,CAAA,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAAA,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
4
|
+
const promises_1 = require("node:fs/promises");
|
|
5
|
+
const node_os_1 = require("node:os");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const errors_1 = require("@cobol-ts/errors");
|
|
8
|
+
const dependency_node_1 = require("@cobol-ts/dependency_node");
|
|
9
|
+
const ring_buffer_1 = require("@cobol-ts/ring-buffer");
|
|
10
|
+
const protobuf_schema_1 = require("./protobuf.schema");
|
|
11
|
+
const protobuf_scalar_codec_1 = require("./protobuf.scalar.codec");
|
|
12
|
+
const protobuf_accumulator_1 = require("./protobuf.accumulator");
|
|
13
|
+
const protobuf_number_projection_1 = require("./protobuf.number.projection");
|
|
14
|
+
const protobuf_number_file_1 = require("./protobuf.number.file");
|
|
15
|
+
const protobuf_accumulator_file_1 = require("./protobuf.accumulator.file");
|
|
16
|
+
const nodes = (0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)({
|
|
17
|
+
amount: { type: 'cel', cel: '1', metadata: { type: 'number', celResultType: 'int' } },
|
|
18
|
+
history: { type: 'cel', cel: '1', metadata: { type: 'number', celResultType: 'int',
|
|
19
|
+
rollingWindow: { periodicity: 'monthly', size: 3 } } },
|
|
20
|
+
names: { type: 'cel', cel: '"a"', metadata: { type: 'string', celResultType: 'string',
|
|
21
|
+
rollingWindow: { periodicity: 'daily', size: 2 } } },
|
|
22
|
+
numbers: { type: 'cel', cel: '1.5', metadata: { type: 'number', celResultType: 'double',
|
|
23
|
+
rollingWindow: { periodicity: 'daily', size: 1 } } },
|
|
24
|
+
flags: { type: 'cel', cel: 'true', metadata: { type: 'boolean', celResultType: 'bool',
|
|
25
|
+
rollingWindow: { periodicity: 'daily', size: 2 } } }
|
|
26
|
+
}));
|
|
27
|
+
const schema = (0, protobuf_schema_1.accumulatorSchemaFromGraph)(nodes);
|
|
28
|
+
const graph = (0, protobuf_number_projection_1.workingAccumulatorFieldsFromGraph)(nodes);
|
|
29
|
+
function record(customerId) {
|
|
30
|
+
const history = (0, ring_buffer_1.createRingBuffer)(3);
|
|
31
|
+
for (const n of [1, 2, 3, 4, 5])
|
|
32
|
+
(0, ring_buffer_1.push)(history, n);
|
|
33
|
+
const names = (0, ring_buffer_1.createRingBuffer)(2);
|
|
34
|
+
for (const s of ['one', 'two', 'three'])
|
|
35
|
+
(0, ring_buffer_1.push)(names, s);
|
|
36
|
+
const numbers = (0, ring_buffer_1.createRingBuffer)(1);
|
|
37
|
+
(0, ring_buffer_1.push)(numbers, 0);
|
|
38
|
+
(0, ring_buffer_1.push)(numbers, 2.5);
|
|
39
|
+
const flags = (0, ring_buffer_1.createRingBuffer)(2);
|
|
40
|
+
(0, ring_buffer_1.push)(flags, false);
|
|
41
|
+
return { customerId, values: [19, history, names, numbers, flags] };
|
|
42
|
+
}
|
|
43
|
+
function nativeRecord(customerId) {
|
|
44
|
+
const codec = (0, protobuf_scalar_codec_1.createScalarAccumulatorCodec)(schema);
|
|
45
|
+
const msg = (0, protobuf_1.create)(schema.message);
|
|
46
|
+
codec.initialize(msg, customerId);
|
|
47
|
+
const data = msg;
|
|
48
|
+
data.amount = 19n;
|
|
49
|
+
const source = record(customerId);
|
|
50
|
+
for (let i = 1; i < graph.length; i++) {
|
|
51
|
+
const ring = source.values[i];
|
|
52
|
+
const target = data[graph[i].name];
|
|
53
|
+
const zero = typeof ring.values.find(v => v !== undefined) === 'bigint' ? 0n :
|
|
54
|
+
graph[i].name === 'history' ? 0n : graph[i].name === 'names' ? '' :
|
|
55
|
+
graph[i].name === 'flags' ? false : 0;
|
|
56
|
+
target.count = ring.count;
|
|
57
|
+
target.excluded = ring.excluded;
|
|
58
|
+
target.hasExpired = ring.hasExpired;
|
|
59
|
+
target.values = ring.values.map(v => v === undefined ? zero :
|
|
60
|
+
graph[i].name === 'history' ? BigInt(v) : v);
|
|
61
|
+
}
|
|
62
|
+
return msg;
|
|
63
|
+
}
|
|
64
|
+
describe('protobuf rolling-window accumulator', () => {
|
|
65
|
+
it('encodes ordinary Protobuf submessages and round-trips the ring including expelled values', () => {
|
|
66
|
+
const codec = (0, protobuf_number_projection_1.prepareNumberBackedProtobufProjection)(schema, graph);
|
|
67
|
+
const input = record(120n), bytes = new Uint8Array(codec.encodedLength(input));
|
|
68
|
+
expect(codec.encodeInto(input, bytes, 0)).toEqual(bytes.length);
|
|
69
|
+
const native = (0, protobuf_1.fromBinary)(schema.message, bytes);
|
|
70
|
+
expect(native.customerId).toEqual(120n);
|
|
71
|
+
expect(native.amount).toEqual(19n);
|
|
72
|
+
expect(native.history.values).toEqual([4n, 5n, 2n, 3n]);
|
|
73
|
+
const output = { customerId: 0n, values: Array(graph.length).fill(undefined) };
|
|
74
|
+
codec.decodeInto(bytes, output);
|
|
75
|
+
expect(output).toEqual(input);
|
|
76
|
+
const history = output.values[1];
|
|
77
|
+
expect([(0, ring_buffer_1.get)(history, 0), (0, ring_buffer_1.get)(history, 1), (0, ring_buffer_1.get)(history, 2), (0, ring_buffer_1.expired)(history)])
|
|
78
|
+
.toEqual([3, 4, 5, 2]);
|
|
79
|
+
const reused = output.values[1];
|
|
80
|
+
codec.decodeInto(bytes, output);
|
|
81
|
+
expect(output.values[1]).toBe(reused);
|
|
82
|
+
expect(output).toEqual(input);
|
|
83
|
+
});
|
|
84
|
+
it('round-trips empty and partially filled windows without treating scalar defaults as missing', () => {
|
|
85
|
+
const codec = (0, protobuf_number_projection_1.prepareNumberBackedProtobufProjection)(schema, graph);
|
|
86
|
+
const target = record(1n);
|
|
87
|
+
const empty = { customerId: 42n, values: [0,
|
|
88
|
+
(0, ring_buffer_1.createRingBuffer)(3), (0, ring_buffer_1.createRingBuffer)(2),
|
|
89
|
+
(0, ring_buffer_1.createRingBuffer)(1), (0, ring_buffer_1.createRingBuffer)(2)] };
|
|
90
|
+
const bytes = new Uint8Array(codec.encodedLength(empty));
|
|
91
|
+
expect(codec.encodeInto(empty, bytes, 0)).toEqual(bytes.length);
|
|
92
|
+
const original = target.values[1];
|
|
93
|
+
codec.decodeInto(bytes, target);
|
|
94
|
+
expect(target.values[1]).toBe(original);
|
|
95
|
+
expect(target).toEqual(empty);
|
|
96
|
+
expect((0, ring_buffer_1.expired)(target.values[1])).toEqual(undefined);
|
|
97
|
+
const partial = empty.values[1];
|
|
98
|
+
(0, ring_buffer_1.push)(partial, 0);
|
|
99
|
+
const partialBytes = new Uint8Array(codec.encodedLength(empty));
|
|
100
|
+
codec.encodeInto(empty, partialBytes, 0);
|
|
101
|
+
codec.decodeInto(partialBytes, target);
|
|
102
|
+
expect(target).toEqual(empty);
|
|
103
|
+
expect((0, ring_buffer_1.get)(target.values[1], 0)).toEqual(0);
|
|
104
|
+
expect((0, ring_buffer_1.expired)(target.values[1])).toEqual(undefined);
|
|
105
|
+
});
|
|
106
|
+
it('initialises empty native windows and retains pooled message and nested identities', () => {
|
|
107
|
+
const codec = (0, protobuf_scalar_codec_1.createScalarAccumulatorCodec)(schema);
|
|
108
|
+
const pool = (0, protobuf_accumulator_1.createMessageAccumulatorPool)(schema.message, codec);
|
|
109
|
+
const empty = pool.acquireEmpty(1n);
|
|
110
|
+
const message = empty.data;
|
|
111
|
+
const history = message.history;
|
|
112
|
+
expect({ count: history.count, excluded: history.excluded, hasExpired: history.hasExpired, values: history.values })
|
|
113
|
+
.toEqual({ count: 0, excluded: 0, hasExpired: false, values: [0n, 0n, 0n, 0n] });
|
|
114
|
+
empty.close();
|
|
115
|
+
const native = nativeRecord(2n);
|
|
116
|
+
const read = pool.acquire(codec.encode(native));
|
|
117
|
+
expect(read.data).toBe(message);
|
|
118
|
+
const current = read.data.history;
|
|
119
|
+
expect(current).toBe(history);
|
|
120
|
+
expect({ count: current.count, excluded: current.excluded, hasExpired: current.hasExpired, values: current.values })
|
|
121
|
+
.toEqual({ count: 3, excluded: 2, hasExpired: true, values: [4n, 5n, 2n, 3n] });
|
|
122
|
+
read.close();
|
|
123
|
+
const next = pool.acquireEmpty(3n);
|
|
124
|
+
expect(next.data.history).toBe(history);
|
|
125
|
+
expect(next.data.history.values).toEqual([0n, 0n, 0n, 0n]);
|
|
126
|
+
next.close();
|
|
127
|
+
});
|
|
128
|
+
it('rejects a schema with different window periodicity or size', () => {
|
|
129
|
+
const changed = graph.map(field => field.name === 'history' ?
|
|
130
|
+
{ name: field.name, valueType: { kind: 'rolling-window', size: 4, periodicity: 'monthly',
|
|
131
|
+
element: { kind: 'scalar', semanticType: 'integer', javascriptType: 'number' } } } : field);
|
|
132
|
+
let actual = '';
|
|
133
|
+
try {
|
|
134
|
+
(0, protobuf_number_projection_1.prepareNumberBackedProtobufProjection)(schema, changed);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
actual = error.message;
|
|
138
|
+
}
|
|
139
|
+
expect(actual).toEqual('Protobuf rolling-window layout mismatch for history');
|
|
140
|
+
});
|
|
141
|
+
it('round-trips a schema-first file through both native and number-backed cursors', async () => {
|
|
142
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'protobuf-rolling-'));
|
|
143
|
+
try {
|
|
144
|
+
const filename = (0, node_path_1.join)(dir, 'rolling.pb');
|
|
145
|
+
const rows = [record(10n), record(11n)];
|
|
146
|
+
await (0, protobuf_number_file_1.writeNumberBackedAccumulatorFile)(filename, schema, graph, rows);
|
|
147
|
+
const native = [];
|
|
148
|
+
for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(filename, { bufferSize: 3 })) {
|
|
149
|
+
const data = lease.data;
|
|
150
|
+
native.push([data.customerId, data.history.count, data.history.values]);
|
|
151
|
+
lease.close();
|
|
152
|
+
}
|
|
153
|
+
expect(native).toEqual([[10n, 3, [4n, 5n, 2n, 3n]], [11n, 3, [4n, 5n, 2n, 3n]]]);
|
|
154
|
+
const working = [];
|
|
155
|
+
for await (const lease of (0, protobuf_number_file_1.readNumberBackedAccumulatorFile)(filename, graph, { bufferSize: 3 })) {
|
|
156
|
+
working.push({ customerId: lease.customerId, values: lease.values.map(v => v && typeof v === 'object' ? { ...v, values: [...v.values] } : v) });
|
|
157
|
+
lease.close();
|
|
158
|
+
}
|
|
159
|
+
expect(working).toEqual(rows);
|
|
160
|
+
const second = (0, node_path_1.join)(dir, 'native.pb');
|
|
161
|
+
await (0, protobuf_accumulator_file_1.writeAccumulatorFile)(second, schema, [nativeRecord(21n), nativeRecord(22n)]);
|
|
162
|
+
const round = [];
|
|
163
|
+
for await (const lease of (0, protobuf_number_file_1.readNumberBackedAccumulatorFile)(second, graph, { bufferSize: 3 })) {
|
|
164
|
+
round.push({ customerId: lease.customerId, values: lease.values.map(v => v && typeof v === 'object' ? { ...v, values: [...v.values] } : v) });
|
|
165
|
+
lease.close();
|
|
166
|
+
}
|
|
167
|
+
expect(round).toEqual([record(21n), record(22n)]);
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
await (0, promises_1.rm)(dir, { recursive: true, force: true });
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
//# sourceMappingURL=protobuf.rolling.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protobuf.rolling.spec.js","sourceRoot":"","sources":["../../src/protobuf.rolling.spec.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A,CAAC,CAAA,EAAC,GAAG,CAAC,EAAC,MAAM,EAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAC,CAAA,CAAC,CAAA,CAAC,CAAC,EAAC,CAAC,CAAC;gBAC5D,KAAK,CAAC,KAAK,EAAE,CAAC;YAClB,CAAC;YACD,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC;gBAAO,CAAC;YAAA,MAAM,IAAA,aAAE,EAAC,GAAG,EAAC,EAAC,SAAS,EAAC,IAAI,EAAC,KAAK,EAAC,IAAI,EAAC,CAAC,CAAC;QAAA,CAAC;IACxD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,195 @@
|
|
|
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 errors_1 = require("@cobol-ts/errors");
|
|
8
|
+
const dependency_node_1 = require("@cobol-ts/dependency_node");
|
|
9
|
+
const protobuf_schema_1 = require("./protobuf.schema");
|
|
10
|
+
const protobuf_accumulator_file_1 = require("./protobuf.accumulator.file");
|
|
11
|
+
const protobuf_accumulator_1 = require("./protobuf.accumulator");
|
|
12
|
+
const protobuf_rdw_1 = require("./protobuf.rdw");
|
|
13
|
+
const authoring = {
|
|
14
|
+
totalCustomers: { type: 'cel', cel: 'prev.totalCustomers + 1', metadata: { type: 'number', celResultType: 'int' } },
|
|
15
|
+
totalOrderQuantity: { type: 'cel', cel: 'input.quantity', metadata: { type: 'number', celResultType: 'int' } },
|
|
16
|
+
hasOrders: { type: 'cel', cel: 'input.quantity > 0', metadata: { type: 'boolean', celResultType: 'bool' } },
|
|
17
|
+
averageOrder: { type: 'cel', cel: '1.5', metadata: { type: 'number', celResultType: 'double' } },
|
|
18
|
+
errors: { type: 'cel', cel: '"none"', metadata: { type: 'string', celResultType: 'string' } }
|
|
19
|
+
};
|
|
20
|
+
function schema() {
|
|
21
|
+
const canonical = (0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)(authoring));
|
|
22
|
+
return (0, protobuf_schema_1.accumulatorSchemaFromGraph)(canonical);
|
|
23
|
+
}
|
|
24
|
+
describe('self-describing Protobuf accumulator file', () => {
|
|
25
|
+
test('saves three graph-shaped customers, loads, changes, saves, reloads exactly', async () => {
|
|
26
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-acc-roundtrip-'));
|
|
27
|
+
const first = (0, node_path_1.join)(dir, 'before.pb');
|
|
28
|
+
const second = (0, node_path_1.join)(dir, 'after.pb');
|
|
29
|
+
try {
|
|
30
|
+
const defined = schema();
|
|
31
|
+
const rows = [
|
|
32
|
+
{ customerId: 1001n, totalCustomers: 1n, totalOrderQuantity: 2n, hasOrders: true, averageOrder: 1.5, errors: 'none' },
|
|
33
|
+
{ customerId: 1002n, totalCustomers: 2n, totalOrderQuantity: 9n, hasOrders: true, averageOrder: 4.5, errors: 'none' },
|
|
34
|
+
{ customerId: 1003n, totalCustomers: 3n, totalOrderQuantity: 0n, hasOrders: false, averageOrder: 0, errors: 'none' }
|
|
35
|
+
];
|
|
36
|
+
await (0, protobuf_accumulator_file_1.writeAccumulatorFile)(first, defined, rows.map(row => (0, protobuf_1.create)(defined.message, row)));
|
|
37
|
+
const readSchema = await (0, protobuf_accumulator_file_1.readAccumulatorFileSchema)(first);
|
|
38
|
+
expect(readSchema.messageFullName).toEqual('cobolts.accumulator.Accumulator');
|
|
39
|
+
expect((0, protobuf_1.toBinary)(readSchema.message, (0, protobuf_1.create)(readSchema.message, rows[0])))
|
|
40
|
+
.toEqual((0, protobuf_1.toBinary)(defined.message, (0, protobuf_1.create)(defined.message, rows[0])));
|
|
41
|
+
const changed = [];
|
|
42
|
+
for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(first)) {
|
|
43
|
+
expect(lease.closed).toEqual(false);
|
|
44
|
+
const data = lease.data;
|
|
45
|
+
const working = lease;
|
|
46
|
+
expect(working.set('totalCustomers', data.totalCustomers + 1n)).toEqual(true);
|
|
47
|
+
expect(working.set('errors', 'updated')).toEqual(true);
|
|
48
|
+
changed.push((0, protobuf_1.create)(readSchema.message, { ...data }));
|
|
49
|
+
lease.close();
|
|
50
|
+
expect(lease.closed).toEqual(true);
|
|
51
|
+
}
|
|
52
|
+
await (0, protobuf_accumulator_file_1.writeAccumulatorFile)(second, readSchema, changed);
|
|
53
|
+
const actual = [];
|
|
54
|
+
for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(second)) {
|
|
55
|
+
const d = lease.data;
|
|
56
|
+
actual.push({ customerId: d.customerId, totalCustomers: d.totalCustomers, totalOrderQuantity: d.totalOrderQuantity,
|
|
57
|
+
hasOrders: d.hasOrders, averageOrder: d.averageOrder, errors: d.errors });
|
|
58
|
+
lease.close();
|
|
59
|
+
}
|
|
60
|
+
expect(actual).toEqual(rows.map(row => ({ ...row, totalCustomers: row.totalCustomers + 1n, errors: 'updated' })));
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
await (0, promises_1.rm)(dir, { recursive: true, force: true });
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
test('schema-only file is valid, an empty file has no schema', async () => {
|
|
67
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-acc-roundtrip-'));
|
|
68
|
+
const file = (0, node_path_1.join)(dir, 'schema-only.pb');
|
|
69
|
+
try {
|
|
70
|
+
await (0, protobuf_accumulator_file_1.writeAccumulatorFile)(file, schema(), []);
|
|
71
|
+
let count = 0;
|
|
72
|
+
for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(file)) {
|
|
73
|
+
count++;
|
|
74
|
+
lease.close();
|
|
75
|
+
}
|
|
76
|
+
expect(count).toEqual(0);
|
|
77
|
+
await (0, promises_1.writeFile)(file, new Uint8Array());
|
|
78
|
+
let error = '';
|
|
79
|
+
try {
|
|
80
|
+
for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(file))
|
|
81
|
+
lease.close();
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
error = e instanceof Error ? e.message : String(e);
|
|
85
|
+
}
|
|
86
|
+
expect(error).toEqual('Accumulator file is missing its schema record');
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
await (0, promises_1.rm)(dir, { recursive: true, force: true });
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
test('defaults legacy numeric metadata to int64 and rejects duplicate field numbers', () => {
|
|
93
|
+
const nodes = (0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)(authoring));
|
|
94
|
+
const withoutPrecise = nodes.map(n => ({ ...n, metadata: { ...n.metadata } }));
|
|
95
|
+
delete withoutPrecise[0].metadata.celResultType;
|
|
96
|
+
expect((0, protobuf_schema_1.accumulatorSchemaFromGraph)(withoutPrecise).descriptorSet)
|
|
97
|
+
.toEqual((0, protobuf_schema_1.accumulatorSchemaFromGraph)(nodes).descriptorSet);
|
|
98
|
+
let secondError = '';
|
|
99
|
+
try {
|
|
100
|
+
(0, protobuf_schema_1.accumulatorSchemaFromGraph)(nodes, { totalCustomers: 2, totalOrderQuantity: 2 });
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
secondError = e instanceof Error ? e.message : String(e);
|
|
104
|
+
}
|
|
105
|
+
expect(secondError).toEqual('Invalid or duplicate Protobuf field number 2 for totalOrderQuantity');
|
|
106
|
+
});
|
|
107
|
+
test('pooled accumulators are independent while leased and reject double close', () => {
|
|
108
|
+
const desc = schema();
|
|
109
|
+
const pool = (0, protobuf_accumulator_1.createAccumulatorPool)();
|
|
110
|
+
const a = pool.acquire((0, protobuf_1.create)(desc.message, { customerId: 1n }));
|
|
111
|
+
const b = pool.acquire((0, protobuf_1.create)(desc.message, { customerId: 2n }));
|
|
112
|
+
expect(a === b).toEqual(false);
|
|
113
|
+
a.close();
|
|
114
|
+
let closeError = '';
|
|
115
|
+
try {
|
|
116
|
+
a.close();
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
closeError = e instanceof Error ? e.message : String(e);
|
|
120
|
+
}
|
|
121
|
+
expect(closeError).toEqual('Accumulator already closed');
|
|
122
|
+
const c = pool.acquire((0, protobuf_1.create)(desc.message, { customerId: 3n }));
|
|
123
|
+
expect(c === a).toEqual(true);
|
|
124
|
+
expect(c.data.customerId).toEqual(3n);
|
|
125
|
+
b.close();
|
|
126
|
+
c.close();
|
|
127
|
+
});
|
|
128
|
+
test('rejects truncated schema framing', async () => {
|
|
129
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-acc-roundtrip-'));
|
|
130
|
+
const file = (0, node_path_1.join)(dir, 'bad.pb');
|
|
131
|
+
try {
|
|
132
|
+
await (0, promises_1.writeFile)(file, (0, protobuf_rdw_1.rdwFrame)(Uint8Array.from([1, 2, 3])).subarray(0, 5));
|
|
133
|
+
let error = '';
|
|
134
|
+
try {
|
|
135
|
+
for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(file))
|
|
136
|
+
lease.close();
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
error = e instanceof Error ? e.message : String(e);
|
|
140
|
+
}
|
|
141
|
+
expect(error).toEqual('Truncated Protobuf record: expected 7 bytes, got 5');
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
await (0, promises_1.rm)(dir, { recursive: true, force: true });
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
describe('experiment schema variations', () => {
|
|
149
|
+
test('opens two different experiment schemas without changing the reader', async () => {
|
|
150
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-acc-schema-'));
|
|
151
|
+
try {
|
|
152
|
+
const first = schema();
|
|
153
|
+
const second = (0, protobuf_schema_1.accumulatorSchemaFromGraph)((0, errors_1.valueOrThrow)((0, dependency_node_1.normalise)({
|
|
154
|
+
riskScore: { type: 'cel', cel: '2.5', metadata: { type: 'number', celResultType: 'double' } }
|
|
155
|
+
})));
|
|
156
|
+
const a = (0, node_path_1.join)(dir, 'a.pb'), b = (0, node_path_1.join)(dir, 'b.pb');
|
|
157
|
+
await (0, protobuf_accumulator_file_1.writeAccumulatorFile)(a, first, [(0, protobuf_1.create)(first.message, { customerId: 1001n, totalCustomers: 9007199254740993n })]);
|
|
158
|
+
await (0, protobuf_accumulator_file_1.writeAccumulatorFile)(b, second, [(0, protobuf_1.create)(second.message, { customerId: 1001n, riskScore: 0.75 })]);
|
|
159
|
+
const rows = [];
|
|
160
|
+
for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(a)) {
|
|
161
|
+
rows.push(lease.data.totalCustomers);
|
|
162
|
+
lease.close();
|
|
163
|
+
}
|
|
164
|
+
for await (const lease of (0, protobuf_accumulator_file_1.readAccumulatorFile)(b)) {
|
|
165
|
+
rows.push(lease.data.riskScore);
|
|
166
|
+
lease.close();
|
|
167
|
+
}
|
|
168
|
+
expect(rows).toEqual([9007199254740993n, 0.75]);
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
await (0, promises_1.rm)(dir, { recursive: true, force: true });
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
test('rejects unsorted customer records before writing the second one', async () => {
|
|
175
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-acc-sort-'));
|
|
176
|
+
try {
|
|
177
|
+
const definition = schema();
|
|
178
|
+
let diagnostic = '';
|
|
179
|
+
try {
|
|
180
|
+
await (0, protobuf_accumulator_file_1.writeAccumulatorFile)((0, node_path_1.join)(dir, 'unordered.pb'), definition, [
|
|
181
|
+
(0, protobuf_1.create)(definition.message, { customerId: 1002n }),
|
|
182
|
+
(0, protobuf_1.create)(definition.message, { customerId: 1001n })
|
|
183
|
+
]);
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
diagnostic = e instanceof Error ? e.message : String(e);
|
|
187
|
+
}
|
|
188
|
+
expect(diagnostic).toEqual('Accumulator records must be strictly sorted by customerId');
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
await (0, promises_1.rm)(dir, { recursive: true, force: true });
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
//# sourceMappingURL=protobuf.roundtrip.spec.js.map
|