@cobol-ts/cursor-loader-cobol 0.0.4 → 0.0.6
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/dist/index.d.ts +6 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/src/cobol.array.selection.d.ts +56 -0
- package/dist/src/cobol.array.selection.js +172 -0
- package/dist/src/cobol.array.selection.js.map +1 -0
- package/dist/src/cobol.array.selection.spec.d.ts +1 -0
- package/dist/src/cobol.array.selection.spec.js +64 -0
- package/dist/src/cobol.array.selection.spec.js.map +1 -0
- package/dist/src/cobol.callback.spec.d.ts +1 -0
- package/dist/src/cobol.callback.spec.js +69 -0
- package/dist/src/cobol.callback.spec.js.map +1 -0
- package/dist/src/cobol.debug.range.d.ts +21 -0
- package/dist/src/cobol.debug.range.js +53 -0
- package/dist/src/cobol.debug.range.js.map +1 -0
- package/dist/src/cobol.debug.range.spec.d.ts +1 -0
- package/dist/src/cobol.debug.range.spec.js +29 -0
- package/dist/src/cobol.debug.range.spec.js.map +1 -0
- package/dist/src/cobol.decoded.file.spec.d.ts +1 -0
- package/dist/src/cobol.decoded.file.spec.js +41 -0
- package/dist/src/cobol.decoded.file.spec.js.map +1 -0
- package/dist/src/cobol.decoded.integration.spec.d.ts +1 -0
- package/dist/src/cobol.decoded.integration.spec.js +124 -0
- package/dist/src/cobol.decoded.integration.spec.js.map +1 -0
- package/dist/src/cobol.file.node.d.ts +37 -0
- package/dist/src/cobol.file.node.js +65 -0
- package/dist/src/cobol.file.node.js.map +1 -0
- package/dist/src/cobol.fixed.array.projection.spec.d.ts +1 -0
- package/dist/src/cobol.fixed.array.projection.spec.js +128 -0
- package/dist/src/cobol.fixed.array.projection.spec.js.map +1 -0
- package/dist/src/cobol.layout.index.d.ts +18 -0
- package/dist/src/cobol.layout.index.js +33 -0
- package/dist/src/cobol.layout.index.js.map +1 -0
- package/dist/src/cobol.layout.index.spec.d.ts +1 -0
- package/dist/src/cobol.layout.index.spec.js +195 -0
- package/dist/src/cobol.layout.index.spec.js.map +1 -0
- package/dist/src/cobol.metrics.odo.spec.d.ts +1 -0
- package/dist/src/cobol.metrics.odo.spec.js +52 -0
- package/dist/src/cobol.metrics.odo.spec.js.map +1 -0
- package/dist/src/cobol.metrics.scalar.spec.d.ts +1 -0
- package/dist/src/cobol.metrics.scalar.spec.js +28 -0
- package/dist/src/cobol.metrics.scalar.spec.js.map +1 -0
- package/dist/src/cobol.multiple.nested.arrays.spec.d.ts +1 -0
- package/dist/src/cobol.multiple.nested.arrays.spec.js +253 -0
- package/dist/src/cobol.multiple.nested.arrays.spec.js.map +1 -0
- package/dist/src/cobol.multiple.nested.odo.spec.d.ts +1 -0
- package/dist/src/cobol.multiple.nested.odo.spec.js +129 -0
- package/dist/src/cobol.multiple.nested.odo.spec.js.map +1 -0
- package/dist/src/cobol.nested.redefines.projection.spec.d.ts +1 -0
- package/dist/src/cobol.nested.redefines.projection.spec.js +195 -0
- package/dist/src/cobol.nested.redefines.projection.spec.js.map +1 -0
- package/dist/src/cobol.occurrence.context.spec.d.ts +1 -0
- package/dist/src/cobol.occurrence.context.spec.js +187 -0
- package/dist/src/cobol.occurrence.context.spec.js.map +1 -0
- package/dist/src/cobol.occurs.clause.d.ts +10 -0
- package/dist/src/cobol.occurs.clause.js +14 -0
- package/dist/src/cobol.occurs.clause.js.map +1 -0
- package/dist/src/cobol.occurs.clause.spec.d.ts +1 -0
- package/dist/src/cobol.occurs.clause.spec.js +21 -0
- package/dist/src/cobol.occurs.clause.spec.js.map +1 -0
- package/dist/src/cobol.odo.positions.d.ts +17 -0
- package/dist/src/cobol.odo.positions.js +70 -0
- package/dist/src/cobol.odo.positions.js.map +1 -0
- package/dist/src/cobol.odo.positions.spec.d.ts +1 -0
- package/dist/src/cobol.odo.positions.spec.js +108 -0
- package/dist/src/cobol.odo.positions.spec.js.map +1 -0
- package/dist/src/cobol.odo.projection.spec.d.ts +1 -0
- package/dist/src/cobol.odo.projection.spec.js +246 -0
- package/dist/src/cobol.odo.projection.spec.js.map +1 -0
- package/dist/src/cobol.odo.three.level.spec.d.ts +1 -0
- package/dist/src/cobol.odo.three.level.spec.js +202 -0
- package/dist/src/cobol.odo.three.level.spec.js.map +1 -0
- package/dist/src/cobol.parser.d.ts +112 -0
- package/dist/src/cobol.parser.js +322 -0
- package/dist/src/cobol.parser.js.map +1 -0
- package/dist/src/cobol.projection.path.d.ts +50 -0
- package/dist/src/cobol.projection.path.js +146 -0
- package/dist/src/cobol.projection.path.js.map +1 -0
- package/dist/src/cobol.projection.symbolic.d.ts +68 -0
- package/dist/src/cobol.projection.symbolic.js +257 -0
- package/dist/src/cobol.projection.symbolic.js.map +1 -0
- package/dist/src/cobol.registration.d.ts +4 -0
- package/dist/src/cobol.registration.js +17 -0
- package/dist/src/cobol.registration.js.map +1 -0
- package/dist/src/cobol.representation.d.ts +16 -0
- package/dist/src/cobol.representation.js +29 -0
- package/dist/src/cobol.representation.js.map +1 -0
- package/dist/src/cobol.shared.fixed.lifecycle.spec.d.ts +1 -0
- package/dist/src/cobol.shared.fixed.lifecycle.spec.js +50 -0
- package/dist/src/cobol.shared.fixed.lifecycle.spec.js.map +1 -0
- package/dist/src/cobol.shared.odo.lifecycle.spec.d.ts +1 -0
- package/dist/src/cobol.shared.odo.lifecycle.spec.js +152 -0
- package/dist/src/cobol.shared.odo.lifecycle.spec.js.map +1 -0
- package/dist/src/cobol.symbolic.allocation.spec.d.ts +1 -0
- package/dist/src/cobol.symbolic.allocation.spec.js +84 -0
- package/dist/src/cobol.symbolic.allocation.spec.js.map +1 -0
- package/dist/src/customer.fixtures.d.ts +90 -0
- package/dist/src/customer.fixtures.js +167 -0
- package/dist/src/customer.fixtures.js.map +1 -0
- package/dist/src/customer.fixtures.spec.d.ts +1 -0
- package/dist/src/customer.fixtures.spec.js +132 -0
- package/dist/src/customer.fixtures.spec.js.map +1 -0
- package/dist/src/customer.projections.d.ts +44 -0
- package/dist/src/customer.projections.js +31 -0
- package/dist/src/customer.projections.js.map +1 -0
- package/dist/src/customer.projections.spec.d.ts +1 -0
- package/dist/src/customer.projections.spec.js +209 -0
- package/dist/src/customer.projections.spec.js.map +1 -0
- package/package.json +11 -11
- package/node.d.ts +0 -1
- package/node.js +0 -2
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cursor_file_1 = require("@cobol-ts/cursor-file");
|
|
4
|
+
const cursor_projection_1 = require("@cobol-ts/cursor-projection");
|
|
5
|
+
const errors_1 = require("@cobol-ts/errors");
|
|
6
|
+
const copybook_1 = require("@cobol-ts/copybook");
|
|
7
|
+
const layout_1 = require("@cobol-ts/layout");
|
|
8
|
+
const cobol_parser_1 = require("./cobol.parser");
|
|
9
|
+
const customer_fixtures_1 = require("./customer.fixtures");
|
|
10
|
+
const personProjection = (0, cursor_projection_1.defineProjection)({
|
|
11
|
+
id: { type: 'integer', path: ['CUSTOMER', 'CUSTOMER-ID'] },
|
|
12
|
+
name: { type: 'string', path: ['CUSTOMER', 'CUSTOMER-NAME'] },
|
|
13
|
+
status: { type: 'character', path: ['CUSTOMER', 'STATUS'] }
|
|
14
|
+
});
|
|
15
|
+
test('real FB file cursor decodes two EBCDIC records across 3-byte physical buffers', async () => {
|
|
16
|
+
const details = (0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolDecodedFixedDetails)(customer_fixtures_1.customerSimple.layout));
|
|
17
|
+
const content = Uint8Array.from([...customer_fixtures_1.customerSimple.records[0].bytes, ...customer_fixtures_1.customerSimple.records[1].bytes]);
|
|
18
|
+
const source = { bytes: content, offset: 0 };
|
|
19
|
+
const cursor = (0, cursor_file_1.createFileCursor)({ filename: 'customers.fb', fileType: 'cobol', projection: personProjection }, source, {
|
|
20
|
+
parsers: {
|
|
21
|
+
cobol: {
|
|
22
|
+
parser: cobol_parser_1.cobolParser, parserConfig: () => details,
|
|
23
|
+
createRecordState: cobol_parser_1.createCobolRecordState, cleanRecordState: cobol_parser_1.cleanCobolRecordState
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
bufferSize: 3,
|
|
27
|
+
fillFileBuffer: async (s, destination) => {
|
|
28
|
+
const size = Math.min(destination.length, s.bytes.length - s.offset);
|
|
29
|
+
destination.set(s.bytes.subarray(s.offset, s.offset + size));
|
|
30
|
+
s.offset += size;
|
|
31
|
+
return size;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const a = await cursor.next(), b = await cursor.next();
|
|
35
|
+
if (a.done || b.done || !a.value || !b.value || Array.isArray(a.value) || Array.isArray(b.value))
|
|
36
|
+
throw new Error('Expected projected records');
|
|
37
|
+
expect([a.value.result.id(), a.value.result.name(), a.value.result.status()]).toEqual([1, 'ALICE ', 'A']);
|
|
38
|
+
expect([b.value.result.id(), b.value.result.name(), b.value.result.status()]).toEqual([42, 'BOB ', 'I']);
|
|
39
|
+
a.value.close();
|
|
40
|
+
b.value.close();
|
|
41
|
+
expect((await cursor.next()).done).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
test('decodes signed COMP after SYNCHRONIZED padding using real compiled layout', () => {
|
|
44
|
+
const details = (0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolDecodedFixedDetails)(customer_fixtures_1.customerAligned.layout));
|
|
45
|
+
const projection = (0, cursor_projection_1.defineProjection)({
|
|
46
|
+
balance: {
|
|
47
|
+
type: 'integer',
|
|
48
|
+
path: ['CUSTOMER', 'BALANCE']
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, projection), data = factory.create();
|
|
52
|
+
const original = customer_fixtures_1.customerAligned.records[1].bytes;
|
|
53
|
+
const physical = {
|
|
54
|
+
buffers: [original.subarray(0, 5), original.subarray(5, 7), original.subarray(7)],
|
|
55
|
+
startByte: 0, endByte: original.length, lastValidByte: original.length,
|
|
56
|
+
source: 'aligned.fb', recordNumber: 1, recordState: (0, cobol_parser_1.createCobolRecordState)()
|
|
57
|
+
};
|
|
58
|
+
factory.bind(data, physical, physical);
|
|
59
|
+
expect(data.balance()).toBe(-1);
|
|
60
|
+
factory.clear(data);
|
|
61
|
+
});
|
|
62
|
+
test('decoded fixed OCCURS projections select the proper byte range for each element', () => {
|
|
63
|
+
const definition = (0, cursor_projection_1.defineProjection)({
|
|
64
|
+
id: { type: 'integer', path: ['CUSTOMER', 'CUSTOMER-ID'] },
|
|
65
|
+
phones: {
|
|
66
|
+
type: 'array', path: ['CUSTOMER', 'TELEPHONES'], element: {
|
|
67
|
+
raw: { type: 'string', path: ['PHONE-RAW'] },
|
|
68
|
+
kind: { type: 'character', path: ['PHONE-PARTS', 'PHONE-KIND'] }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const details = (0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolDecodedFixedDetails)(customer_fixtures_1.customerFixedOccurs.layout));
|
|
73
|
+
const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, definition), row = factory.create();
|
|
74
|
+
const bytes = customer_fixtures_1.customerFixedOccurs.records[0].bytes;
|
|
75
|
+
const physical = {
|
|
76
|
+
buffers: [bytes.subarray(0, 6), bytes.subarray(6, 12), bytes.subarray(12)],
|
|
77
|
+
startByte: 0, endByte: bytes.length, lastValidByte: bytes.length,
|
|
78
|
+
source: 'phones.fb', recordNumber: 1, recordState: (0, cobol_parser_1.createCobolRecordState)()
|
|
79
|
+
};
|
|
80
|
+
factory.bind(row, physical, physical);
|
|
81
|
+
expect(row.id()).toBe(1001);
|
|
82
|
+
expect(row.phones[0].raw()).toBe('H12345');
|
|
83
|
+
expect(row.phones[1].raw()).toBe('M67890');
|
|
84
|
+
expect(row.phones[0].kind()).toBe('H');
|
|
85
|
+
factory.clear(row);
|
|
86
|
+
});
|
|
87
|
+
test('three-level ODO uses the same decoded-value scalar accessors', () => {
|
|
88
|
+
const copybook = [
|
|
89
|
+
'01 ROW.', '05 O-COUNT PIC 9.', '05 M-COUNT PIC 9.', '05 I-COUNT PIC 9.',
|
|
90
|
+
'05 OUTERS OCCURS 0 TO 3 TIMES DEPENDING ON O-COUNT.',
|
|
91
|
+
'10 O-HEAD PIC X.',
|
|
92
|
+
'10 MIDDLES OCCURS 0 TO 3 TIMES DEPENDING ON M-COUNT.',
|
|
93
|
+
'15 M-HEAD PIC X.',
|
|
94
|
+
'15 INNERS OCCURS 0 TO 3 TIMES DEPENDING ON I-COUNT.',
|
|
95
|
+
'20 CODE PIC X(2).', '15 M-TAIL PIC X.',
|
|
96
|
+
'10 O-TAIL PIC X.', '05 FINAL PIC X.'
|
|
97
|
+
].join('\n');
|
|
98
|
+
const projection = (0, cursor_projection_1.defineProjection)({
|
|
99
|
+
outers: {
|
|
100
|
+
type: 'array', path: ['ROW', 'OUTERS'], element: {
|
|
101
|
+
middles: {
|
|
102
|
+
type: 'array', path: ['MIDDLES'], element: {
|
|
103
|
+
inners: { type: 'array', path: ['INNERS'], element: { code: { type: 'string', path: ['CODE'] } } }
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, final: { type: 'character', path: ['ROW', 'FINAL'] }
|
|
108
|
+
});
|
|
109
|
+
const details = (0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolDecodedProjectionDetails)((0, errors_1.valueOrThrow)((0, layout_1.compileCobolLayout)((0, errors_1.valueOrThrow)((0, copybook_1.parseCopybook)(copybook)), 'odo.cpy'))));
|
|
110
|
+
const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, projection), row = factory.create();
|
|
111
|
+
const bytes = Uint8Array.from([0xf2, 0xf2, 0xf2,
|
|
112
|
+
0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce,
|
|
113
|
+
0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xe9]);
|
|
114
|
+
const physical = {
|
|
115
|
+
buffers: [bytes.subarray(0, 28), bytes.subarray(28)], startByte: 0,
|
|
116
|
+
endByte: bytes.length, lastValidByte: bytes.length, source: 'nested-odo.fb', recordNumber: 1,
|
|
117
|
+
recordState: (0, cobol_parser_1.createCobolRecordState)()
|
|
118
|
+
};
|
|
119
|
+
factory.bind(row, physical, physical);
|
|
120
|
+
expect(row.outers[1].middles[1].inners[1].code()).toBe('ûü'); // CP037 DB/DC
|
|
121
|
+
expect(row.final()).toBe('Z'); // E9 is Z
|
|
122
|
+
factory.clear(row);
|
|
123
|
+
});
|
|
124
|
+
//# sourceMappingURL=cobol.decoded.integration.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cobol.decoded.integration.spec.js","sourceRoot":"","sources":["../../src/cobol.decoded.integration.spec.ts"],"names":[],"mappings":";;AACA,uDAAuD;AACvD,mEAA+E;AAC/E,6CAA8C;AAC9C,iDAAiD;AACjD,6CAAoD;AACpD,iDAGwB;AACxB,2DAAyF;AAGzF,MAAM,gBAAgB,GAAG,IAAA,oCAAgB,EAAS;IAC9C,EAAE,EAAE,EAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,EAAC;IACxD,IAAI,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,UAAU,EAAE,eAAe,CAAC,EAAC;IAC3D,MAAM,EAAE,EAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAC;CAC5D,CAAC,CAAC;AAEH,IAAI,CAAC,+EAA+E,EAAE,KAAK,IAAI,EAAE;IAC7F,MAAM,OAAO,GAAG,IAAA,qBAAY,EAAC,IAAA,6CAA8B,EAAC,kCAAc,CAAC,MAAM,CAAC,CAAC,C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AAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc;IAC5E,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU;IACzC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type IPutMetrics } from '@cobol-ts/metrics';
|
|
2
|
+
import { type CobolLayoutOptions } from '@cobol-ts/layout';
|
|
3
|
+
import { type CobolDecodeOptions } from '@cobol-ts/codec';
|
|
4
|
+
import { type CursorFileDefinition, type FileCursorResult } from '@cobol-ts/cursor-file';
|
|
5
|
+
import type { RecordObjectPool } from '@cobol-ts/cursor-record';
|
|
6
|
+
import { type CobolFraming } from './cobol.parser';
|
|
7
|
+
/** Input paths are filenames, not COBOL text or precompiled descriptors. */
|
|
8
|
+
export type CobolFileOptions<TProjection> = Readonly<{
|
|
9
|
+
filename: string;
|
|
10
|
+
copybook: string;
|
|
11
|
+
projection: CursorFileDefinition<TProjection, 'cobol'>['projection'];
|
|
12
|
+
bufferSize?: number;
|
|
13
|
+
layoutOptions?: CobolLayoutOptions;
|
|
14
|
+
decodeOptions?: CobolDecodeOptions;
|
|
15
|
+
framing?: CobolFraming;
|
|
16
|
+
/** Optional physical record pool. Callback scans default to a fresh simple pool. */
|
|
17
|
+
recordPool?: RecordObjectPool<any>;
|
|
18
|
+
byteBufferPool?: import("@cobol-ts/cursor-loader-types").FileBufferPool;
|
|
19
|
+
metrics?: IPutMetrics;
|
|
20
|
+
/** Opt-in shared-binding native arrays for eligible small ODO tables. */
|
|
21
|
+
experimentalSharedOdoArrays?: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Open an FB or RDW-framed COBOL file as borrowed, lazy projections.
|
|
25
|
+
*
|
|
26
|
+
* Source setup and decoder compilation happen once, before any row is read.
|
|
27
|
+
* Records use the existing FileCursorResult.close() ownership contract.
|
|
28
|
+
* Opening the handle is deferred until iteration starts; it is closed on
|
|
29
|
+
* completion, error, or iterator.return() (e.g. breaking from for-await).
|
|
30
|
+
*/
|
|
31
|
+
export declare function readCobolFile<TProjection>(options: CobolFileOptions<TProjection>): AsyncGenerator<FileCursorResult<TProjection>, void, void>;
|
|
32
|
+
/**
|
|
33
|
+
* High-throughput alternative to readCobolFile(). Each borrowed projection is
|
|
34
|
+
* usable only until the synchronous callback returns. Return false to stop.
|
|
35
|
+
* All COBOL setup and field decoding is identical to readCobolFile().
|
|
36
|
+
*/
|
|
37
|
+
export declare function scanCobolFile<TProjection>(options: CobolFileOptions<TProjection>, onRecord: (row: TProjection) => void | boolean): Promise<void>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readCobolFile = readCobolFile;
|
|
4
|
+
exports.scanCobolFile = scanCobolFile;
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const copybook_1 = require("@cobol-ts/copybook");
|
|
8
|
+
const layout_1 = require("@cobol-ts/layout");
|
|
9
|
+
const errors_1 = require("@cobol-ts/errors");
|
|
10
|
+
const cursor_file_1 = require("@cobol-ts/cursor-file");
|
|
11
|
+
const cursor_file_node_1 = require("@cobol-ts/cursor-file/src/cursor.file.node");
|
|
12
|
+
const cobol_parser_1 = require("./cobol.parser");
|
|
13
|
+
const cobol_registration_1 = require("./cobol.registration");
|
|
14
|
+
/**
|
|
15
|
+
* Open an FB or RDW-framed COBOL file as borrowed, lazy projections.
|
|
16
|
+
*
|
|
17
|
+
* Source setup and decoder compilation happen once, before any row is read.
|
|
18
|
+
* Records use the existing FileCursorResult.close() ownership contract.
|
|
19
|
+
* Opening the handle is deferred until iteration starts; it is closed on
|
|
20
|
+
* completion, error, or iterator.return() (e.g. breaking from for-await).
|
|
21
|
+
*/
|
|
22
|
+
async function* readCobolFile(options) {
|
|
23
|
+
const text = await (0, promises_1.readFile)(options.copybook, 'utf8');
|
|
24
|
+
const ast = (0, errors_1.valueOrThrow)((0, copybook_1.parseCopybook)(text));
|
|
25
|
+
const layout = (0, errors_1.valueOrThrow)((0, layout_1.compileCobolLayout)(ast, (0, node_path_1.basename)(options.copybook), options.layoutOptions));
|
|
26
|
+
const details = { ...(0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolDecodedFramedDetails)(layout, options.framing, options.decodeOptions)), metrics: options.metrics,
|
|
27
|
+
experimentalSharedOdoArrays: options.experimentalSharedOdoArrays };
|
|
28
|
+
const file = await (0, promises_1.open)(options.filename, 'r');
|
|
29
|
+
try {
|
|
30
|
+
yield* (0, cursor_file_1.createThrowingFileCursor)({ filename: options.filename, fileType: 'cobol', projection: options.projection }, file, {
|
|
31
|
+
parsers: (0, cobol_registration_1.createCobolParserRegistry)(details),
|
|
32
|
+
bufferSize: options.bufferSize ?? 64 * 1024,
|
|
33
|
+
fillFileBuffer: cursor_file_node_1.fillNodeFileBuffer,
|
|
34
|
+
metrics: options.metrics,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
await file.close();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* High-throughput alternative to readCobolFile(). Each borrowed projection is
|
|
43
|
+
* usable only until the synchronous callback returns. Return false to stop.
|
|
44
|
+
* All COBOL setup and field decoding is identical to readCobolFile().
|
|
45
|
+
*/
|
|
46
|
+
async function scanCobolFile(options, onRecord) {
|
|
47
|
+
const text = await (0, promises_1.readFile)(options.copybook, 'utf8');
|
|
48
|
+
const ast = (0, errors_1.valueOrThrow)((0, copybook_1.parseCopybook)(text));
|
|
49
|
+
const layout = (0, errors_1.valueOrThrow)((0, layout_1.compileCobolLayout)(ast, (0, node_path_1.basename)(options.copybook), options.layoutOptions));
|
|
50
|
+
const details = { ...(0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolDecodedFramedDetails)(layout, options.framing, options.decodeOptions)), metrics: options.metrics,
|
|
51
|
+
experimentalSharedOdoArrays: options.experimentalSharedOdoArrays };
|
|
52
|
+
const file = await (0, promises_1.open)(options.filename, 'r');
|
|
53
|
+
try {
|
|
54
|
+
await (0, cursor_file_1.scanThrowingFileCursor)({ filename: options.filename, fileType: 'cobol', projection: options.projection }, file, { parsers: (0, cobol_registration_1.createCobolParserRegistry)(details),
|
|
55
|
+
bufferSize: options.bufferSize ?? 64 * 1024,
|
|
56
|
+
fillFileBuffer: cursor_file_node_1.fillNodeFileBuffer,
|
|
57
|
+
recordPool: options.recordPool,
|
|
58
|
+
byteBufferPool: options.byteBufferPool,
|
|
59
|
+
metrics: options.metrics }, onRecord);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
await file.close();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=cobol.file.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cobol.file.node.js","sourceRoot":"","sources":["../../src/cobol.file.node.ts"],"names":[],"mappings":";;AA2CA,sCAwBC;AAOD,sCAyBC;AAlGD,+CAAgD;AAChD,yCAAmC;AACnC,iDAAiD;AACjD,6CAA6E;AAC7E,6CAA8C;AAE9C,uDAK+B;AAC/B,iFAA8E;AAE9E,iDAAkF;AAClF,6DAA+D;AAmB/D;;;;;;;GAOG;AACI,KAAK,SAAS,CAAC,CAAC,aAAa,CAChC,OAAsC;IAEtC,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACtD,MAAM,GAAG,GAAG,IAAA,qBAAY,EAAC,IAAA,wBAAa,EAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,IAAA,qBAAY,EAAC,IAAA,2BAAkB,EAAC,GAAG,EAAE,I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,QAAQ,CAAC,EAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;IACtG,MAAM,OAAO,GAAG,EAAC,GAAG,IAAA,qBAAY,EAAC,IAAA,8CAA+B,EAAC,MAAM,EAAC,OAAO,CAAC,OAAO,EAAC,OAAO,CAAC,aAAa,CAAC,CAAC,EAAC,OAAO,EAAC,OAAO,CAAC,OAAO;QACnI,2BAA2B,EAAC,OAAO,CAAC,2BAA2B,EAAC,CAAC;IACrE,MAAM,IAAI,GAAG,MAAM,IAAA,eAAI,EAAC,OAAO,CAAC,QAAQ,EAAC,GAAG,CAAC,CAAC;IAC9C,IAAI,CAAC;QACD,MAAM,IAAA,oCAAsB,EACxB,EAAC,QAAQ,EAAC,OAAO,CAAC,QAAQ,EAAC,QAAQ,EAAC,OAAO,EAAC,UAAU,EAAC,OAAO,CAAC,UAAU,EAAC,EAC1E,IAAI,EACJ,EAAC,OAAO,EAAC,IAAA,8CAAyB,EAAC,OAAO,CAAC;YACvC,UAAU,EAAC,OAAO,CAAC,UAAU,IAAE,EAAE,GAAC,IAAI;YACtC,cAAc,EAAC,qCAAkB;YACjC,UAAU,EAAC,OAAO,CAAC,UAAU;YAC7B,cAAc,EAAC,OAAO,CAAC,cAAc;YACrC,OAAO,EAAC,OAAO,CAAC,OAAO,EAAC,EAC5B,QAAQ,CACX,CAAC;IACN,CAAC;YAAS,CAAC;QACP,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cursor_file_1 = require("@cobol-ts/cursor-file");
|
|
4
|
+
const cursor_projection_1 = require("@cobol-ts/cursor-projection");
|
|
5
|
+
const errors_1 = require("@cobol-ts/errors");
|
|
6
|
+
const cobol_parser_1 = require("./cobol.parser");
|
|
7
|
+
const customer_fixtures_1 = require("./customer.fixtures");
|
|
8
|
+
const definition = (0, cursor_projection_1.defineProjection)({
|
|
9
|
+
id: { type: "integer", path: ["CUSTOMER", "CUSTOMER-ID"] },
|
|
10
|
+
telephones: { type: "array", path: ["CUSTOMER", "TELEPHONES"], element: {
|
|
11
|
+
raw: { type: "string", path: ["PHONE-RAW"] },
|
|
12
|
+
parts: { type: "object", path: ["PHONE-PARTS"], fields: {
|
|
13
|
+
kind: { type: "character", path: ["PHONE-KIND"] },
|
|
14
|
+
number: { type: "string", path: ["PHONE-NUMBER"] }
|
|
15
|
+
} }
|
|
16
|
+
} },
|
|
17
|
+
status: { type: "character", path: ["CUSTOMER", "STATUS"] }
|
|
18
|
+
});
|
|
19
|
+
const details = (0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolFixedDetails)(customer_fixtures_1.customerFixedOccurs.layout));
|
|
20
|
+
const record = (n, state = (0, cobol_parser_1.createCobolRecordState)()) => ({
|
|
21
|
+
buffers: [customer_fixtures_1.customerFixedOccurs.records[n].bytes],
|
|
22
|
+
startByte: 0, endByte: 17, lastValidByte: 17,
|
|
23
|
+
source: "phones.fb", recordNumber: n + 1, recordState: state
|
|
24
|
+
});
|
|
25
|
+
describe("COBOL fixed OCCURS projected array", () => {
|
|
26
|
+
test("constant-position scalar access skips occurrence-location scratch", () => {
|
|
27
|
+
const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, definition);
|
|
28
|
+
const customer = factory.create(), bytes = record(0);
|
|
29
|
+
factory.bind(customer, bytes, bytes);
|
|
30
|
+
const state = bytes.recordState;
|
|
31
|
+
expect(state.fixedScratch).toBeUndefined();
|
|
32
|
+
expect(customer.status()).toBe("16/17/c1");
|
|
33
|
+
expect(state.fixedScratch).toBeUndefined();
|
|
34
|
+
expect(state.rangeScratch).toEqual({ from: 16, to: 17 });
|
|
35
|
+
factory.clear(customer);
|
|
36
|
+
});
|
|
37
|
+
test("indexed fixed fields retain occurrence resolution and index validation", () => {
|
|
38
|
+
const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, definition);
|
|
39
|
+
const customer = factory.create(), bytes = record(0);
|
|
40
|
+
factory.bind(customer, bytes, bytes);
|
|
41
|
+
const state = bytes.recordState;
|
|
42
|
+
expect(customer.telephones[1].raw()).toBe("10/16/d4 f6 f7 f8 f9 f0");
|
|
43
|
+
expect(customer.telephones[2]).toBeUndefined();
|
|
44
|
+
factory.clear(customer);
|
|
45
|
+
});
|
|
46
|
+
test("uses compiled byte offsets for a single fixed array without copying bytes", () => {
|
|
47
|
+
const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, definition);
|
|
48
|
+
const customer = factory.create();
|
|
49
|
+
const bytes = record(0);
|
|
50
|
+
factory.bind(customer, bytes, bytes);
|
|
51
|
+
expect(customer.telephones.length).toBe(2);
|
|
52
|
+
const first = customer.telephones[0];
|
|
53
|
+
const second = customer.telephones[1];
|
|
54
|
+
expect(first.raw()).toBe("4/10/c8 f1 f2 f3 f4 f5");
|
|
55
|
+
expect(second.raw()).toBe("10/16/d4 f6 f7 f8 f9 f0");
|
|
56
|
+
expect(first.raw()).toBe("4/10/c8 f1 f2 f3 f4 f5");
|
|
57
|
+
expect(customer.telephones[0]).toBe(first);
|
|
58
|
+
expect(customer.telephones[2]).toBeUndefined();
|
|
59
|
+
expect(customer.telephones.map(p => p.raw())).toEqual([
|
|
60
|
+
"4/10/c8 f1 f2 f3 f4 f5", "10/16/d4 f6 f7 f8 f9 f0"
|
|
61
|
+
]);
|
|
62
|
+
expect(customer.status()).toBe("16/17/c1");
|
|
63
|
+
// The projection borrows the original byte buffer: no element payloads
|
|
64
|
+
// have been copied or decoded into an alternative representation.
|
|
65
|
+
const original = bytes.buffers[0][4];
|
|
66
|
+
bytes.buffers[0][4] = 0xC9;
|
|
67
|
+
expect(first.raw()).toBe("4/10/c9 f1 f2 f3 f4 f5");
|
|
68
|
+
bytes.buffers[0][4] = original;
|
|
69
|
+
factory.clear(customer);
|
|
70
|
+
});
|
|
71
|
+
test("selects a REDEFINES group inside a fixed occurrence without extra data", () => {
|
|
72
|
+
const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, definition);
|
|
73
|
+
const customer = factory.create(), bytes = record(0);
|
|
74
|
+
factory.bind(customer, bytes, bytes);
|
|
75
|
+
expect(customer.telephones[0].parts.kind()).toBe("4/5/c8");
|
|
76
|
+
expect(customer.telephones[1].parts.number()).toBe("11/16/f6 f7 f8 f9 f0");
|
|
77
|
+
expect(customer.telephones[0].parts.number()).toBe("5/10/f1 f2 f3 f4 f5");
|
|
78
|
+
factory.clear(customer);
|
|
79
|
+
});
|
|
80
|
+
test("retains projections on the pooled physical state and clears bindings on reuse", () => {
|
|
81
|
+
const factory = (0, cursor_projection_1.createProjection)(cobol_parser_1.cobolParser, details, undefined, definition);
|
|
82
|
+
const customer = factory.create();
|
|
83
|
+
const state = (0, cobol_parser_1.createCobolRecordState)();
|
|
84
|
+
const first = record(0, state);
|
|
85
|
+
factory.bind(customer, first, first);
|
|
86
|
+
const phones = customer.telephones;
|
|
87
|
+
const a = phones[0], b = phones[1];
|
|
88
|
+
expect(a.raw()).toBe("4/10/c8 f1 f2 f3 f4 f5");
|
|
89
|
+
factory.clear(customer);
|
|
90
|
+
expect(phones.length).toBe(0);
|
|
91
|
+
const next = record(1, state);
|
|
92
|
+
factory.bind(customer, next, next);
|
|
93
|
+
expect(customer.telephones).toBe(phones);
|
|
94
|
+
expect(customer.telephones[0]).toBe(a);
|
|
95
|
+
expect(customer.telephones[1]).toBe(b);
|
|
96
|
+
expect(a.raw()).toBe("4/10/e6 f5 f4 f3 f2 f1");
|
|
97
|
+
expect(b.raw()).toBe("10/16/c2 f1 f1 f2 f2 f3");
|
|
98
|
+
factory.clear(customer);
|
|
99
|
+
});
|
|
100
|
+
test("holds two independent record leases through the real byte cursor", async () => {
|
|
101
|
+
const bytes = Uint8Array.from([...customer_fixtures_1.customerFixedOccurs.records[0].bytes, ...customer_fixtures_1.customerFixedOccurs.records[1].bytes]);
|
|
102
|
+
const source = { bytes, offset: 0 };
|
|
103
|
+
let cleanCalls = 0;
|
|
104
|
+
const cursor = (0, cursor_file_1.createFileCursor)({ filename: "phones.fb", fileType: "cobol", projection: definition }, source, { parsers: { cobol: { parser: cobol_parser_1.cobolParser, parserConfig: () => details,
|
|
105
|
+
createRecordState: cobol_parser_1.createCobolRecordState,
|
|
106
|
+
cleanRecordState: state => { cleanCalls++; (0, cobol_parser_1.cleanCobolRecordState)(state); } } },
|
|
107
|
+
bufferSize: 7,
|
|
108
|
+
fillFileBuffer: async (s, dst) => {
|
|
109
|
+
const n = Math.min(dst.length, s.bytes.length - s.offset);
|
|
110
|
+
dst.set(s.bytes.subarray(s.offset, s.offset + n));
|
|
111
|
+
s.offset += n;
|
|
112
|
+
return n;
|
|
113
|
+
} });
|
|
114
|
+
const a = await cursor.next(), b = await cursor.next();
|
|
115
|
+
if (a.done === true || b.done === true || Array.isArray(a.value) || Array.isArray(b.value))
|
|
116
|
+
throw new Error("Expected two records");
|
|
117
|
+
const first = a.value, second = b.value;
|
|
118
|
+
expect(first.result.telephones[1].raw()).toBe("10/16/d4 f6 f7 f8 f9 f0");
|
|
119
|
+
expect(second.result.telephones[1].raw()).toBe("10/16/c2 f1 f1 f2 f2 f3");
|
|
120
|
+
first.close();
|
|
121
|
+
expect(cleanCalls).toBe(1);
|
|
122
|
+
expect(second.result.telephones[0].raw()).toBe("4/10/e6 f5 f4 f3 f2 f1");
|
|
123
|
+
second.close();
|
|
124
|
+
expect(cleanCalls).toBe(2);
|
|
125
|
+
expect((await cursor.next()).done).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
//# sourceMappingURL=cobol.fixed.array.projection.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cobol.fixed.array.projection.spec.js","sourceRoot":"","sources":["../../src/cobol.fixed.array.projection.spec.ts"],"names":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AC;QACd,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACzE,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,MAAM,CAAC,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type CompiledCobolEntry, type CompiledCobolElementary, type CompiledCobolGroup } from "@cobol-ts/layout";
|
|
2
|
+
import { type ErrorsOr } from "@cobol-ts/errors";
|
|
3
|
+
/** Index entries reference the original compiled nodes; geometry is not copied. */
|
|
4
|
+
export type NamedCobolEntry = Readonly<{
|
|
5
|
+
node: CompiledCobolElementary | CompiledCobolGroup;
|
|
6
|
+
children: CobolNameIndex;
|
|
7
|
+
}>;
|
|
8
|
+
/** The keys retain their original copybook spelling. */
|
|
9
|
+
export type CobolNameIndex = ReadonlyMap<string, NamedCobolEntry>;
|
|
10
|
+
/** Find a name regardless of the casing used by the caller. */
|
|
11
|
+
export declare function findCobolName(index: CobolNameIndex, name: string): NamedCobolEntry | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Build one map per declarative scope, preserving source-node references.
|
|
14
|
+
* Padding and unnamed FILLER (including a FILLER group's descendants) are
|
|
15
|
+
* inaccessible. Duplicate-name diagnostics and independent subtree failures
|
|
16
|
+
* are combined by the shared ErrorsOr aggregation utility.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createCobolNameIndex(entries: readonly CompiledCobolEntry[]): ErrorsOr<CobolNameIndex>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findCobolName = findCobolName;
|
|
4
|
+
exports.createCobolNameIndex = createCobolNameIndex;
|
|
5
|
+
const errors_1 = require("@cobol-ts/errors");
|
|
6
|
+
const sameCobolName = (left, right) => left.toUpperCase() === right.toUpperCase();
|
|
7
|
+
/** Find a name regardless of the casing used by the caller. */
|
|
8
|
+
function findCobolName(index, name) {
|
|
9
|
+
for (const [declared, entry] of index) {
|
|
10
|
+
if (sameCobolName(declared, name))
|
|
11
|
+
return entry;
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build one map per declarative scope, preserving source-node references.
|
|
17
|
+
* Padding and unnamed FILLER (including a FILLER group's descendants) are
|
|
18
|
+
* inaccessible. Duplicate-name diagnostics and independent subtree failures
|
|
19
|
+
* are combined by the shared ErrorsOr aggregation utility.
|
|
20
|
+
*/
|
|
21
|
+
function createCobolNameIndex(entries) {
|
|
22
|
+
const named = entries.flatMap(node => node.kind !== "padding" && node.source.name.kind === "named"
|
|
23
|
+
? [{ name: node.source.name.name, node }]
|
|
24
|
+
: []);
|
|
25
|
+
const indexed = named.map(({ name, node }) => (0, errors_1.mapErrorsOr)(node.kind === "group"
|
|
26
|
+
? createCobolNameIndex(node.children)
|
|
27
|
+
: (0, errors_1.value)(new Map()), children => [name, { node, children }]));
|
|
28
|
+
const duplicates = named.flatMap(({ name }, i) => named.slice(i + 1)
|
|
29
|
+
.filter(other => sameCobolName(name, other.name))
|
|
30
|
+
.map(other => (0, errors_1.errors)(`Ambiguous COBOL names '${name}' and '${other.name}' in compiled layout scope`)));
|
|
31
|
+
return (0, errors_1.mapErrorsOr)((0, errors_1.flattenArrayOfErrorsOr)([...indexed, ...duplicates]), pairs => new Map(pairs));
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=cobol.layout.index.js.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