@cobol-ts/file-display 0.0.3 → 0.0.5
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.js.map +1 -0
- package/dist/src/file.display.d.ts +26 -0
- package/dist/src/file.display.int.spec.d.ts +1 -0
- package/dist/src/file.display.int.spec.js +93 -0
- package/dist/src/file.display.int.spec.js.map +1 -0
- package/dist/src/file.display.js +127 -0
- package/dist/src/file.display.js.map +1 -0
- package/dist/src/projection.json.d.ts +7 -0
- package/dist/src/projection.json.js +50 -0
- package/dist/src/projection.json.js.map +1 -0
- package/dist/src/projection.json.spec.d.ts +1 -0
- package/dist/src/projection.json.spec.js +40 -0
- package/dist/src/projection.json.spec.js.map +1 -0
- package/package.json +11 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAkC;AAClC,wDAAqC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TextFiles } from '@cobol-ts/files';
|
|
2
|
+
import { type ErrorsOr } from '@cobol-ts/errors';
|
|
3
|
+
export interface DisplayOptions {
|
|
4
|
+
readonly configDirectory: string;
|
|
5
|
+
readonly logicalName: string;
|
|
6
|
+
/** Defaults to 10 unless all is true. */
|
|
7
|
+
readonly count?: number;
|
|
8
|
+
readonly all?: boolean;
|
|
9
|
+
readonly skip?: number;
|
|
10
|
+
/** Physical path, relative to the caller's working directory if not absolute. */
|
|
11
|
+
readonly input?: string;
|
|
12
|
+
/** Optional configuration name within .cobolts. */
|
|
13
|
+
readonly catalogue?: string;
|
|
14
|
+
readonly data?: string;
|
|
15
|
+
readonly bufferSize?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface DisplayStream {
|
|
18
|
+
readonly filename: string;
|
|
19
|
+
/** Each item is one JSON value, without a newline. */
|
|
20
|
+
readonly lines: AsyncIterable<string>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolve the configured input and create a one-pass JSONL stream. Neither
|
|
24
|
+
* generation.yaml nor generated TypeScript participates in this operation.
|
|
25
|
+
*/
|
|
26
|
+
export declare function openFileDisplay(options: DisplayOptions, files?: TextFiles): Promise<ErrorsOr<DisplayStream>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_path_1 = require("node:path");
|
|
4
|
+
const promises_1 = require("node:fs/promises");
|
|
5
|
+
const node_os_1 = require("node:os");
|
|
6
|
+
const files_1 = require("@cobol-ts/files");
|
|
7
|
+
const file_display_1 = require("./file.display");
|
|
8
|
+
const definitions = (0, node_path_1.resolve)(__dirname, '../../../examples/example/definitions');
|
|
9
|
+
const configDirectory = (0, node_path_1.join)(definitions, '.cobolts');
|
|
10
|
+
const customers = [
|
|
11
|
+
{ customerId: 1001, customerName: 'ALICE ', contactValue: 'GB0042', contactParts: { region: 'GB', number: '0042' },
|
|
12
|
+
orderCount: 1, orders: [{ productCode: 'A001', productParts: { productCategory: 'A0', productNumber: '01' }, quantity: 2 }] },
|
|
13
|
+
{ customerId: 1002, customerName: 'BOB ', contactValue: 'US1234', contactParts: { region: 'US', number: '1234' },
|
|
14
|
+
orderCount: 3, orders: [
|
|
15
|
+
{ productCode: 'B001', productParts: { productCategory: 'B0', productNumber: '01' }, quantity: 1 },
|
|
16
|
+
{ productCode: 'C202', productParts: { productCategory: 'C2', productNumber: '02' }, quantity: 3 },
|
|
17
|
+
{ productCode: 'D303', productParts: { productCategory: 'D3', productNumber: '03' }, quantity: 5 }
|
|
18
|
+
] },
|
|
19
|
+
{ customerId: 1003, customerName: 'CARA ', contactValue: 'DE5678', contactParts: { region: 'DE', number: '5678' },
|
|
20
|
+
orderCount: 0, orders: [] }
|
|
21
|
+
];
|
|
22
|
+
const preferences = [
|
|
23
|
+
{ customerId: 1001, preferredChannel: 'E', creditLimit: 25000, reviewStatus: 'A' },
|
|
24
|
+
{ customerId: 1002, preferredChannel: 'P', creditLimit: 5000, reviewStatus: 'R' },
|
|
25
|
+
{ customerId: 1003, preferredChannel: 'E', creditLimit: 1000, reviewStatus: 'A' }
|
|
26
|
+
];
|
|
27
|
+
async function display(logicalName, options = {}) {
|
|
28
|
+
const opened = await (0, file_display_1.openFileDisplay)({ configDirectory, logicalName, bufferSize: 11, ...options }, files_1.nodeTextFiles);
|
|
29
|
+
if ('errors' in opened)
|
|
30
|
+
throw new Error(opened.errors.join('\n'));
|
|
31
|
+
const records = [];
|
|
32
|
+
for await (const line of opened.value.lines)
|
|
33
|
+
records.push(JSON.parse(line));
|
|
34
|
+
return { filename: opened.value.filename, records };
|
|
35
|
+
}
|
|
36
|
+
describe('configured COBOL display', () => {
|
|
37
|
+
describe('data bindings and default projection', () => {
|
|
38
|
+
it('reads customer ODO and both levels of REDEFINES directly from source definitions', async () => {
|
|
39
|
+
expect(await display('customers', { all: true })).toEqual({
|
|
40
|
+
filename: (0, node_path_1.join)(definitions, 'data/customers.fb'), records: customers
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it('reads customer preferences without any generated TypeScript', async () => {
|
|
44
|
+
expect(await display('customerPreferences', { all: true })).toEqual({
|
|
45
|
+
filename: (0, node_path_1.join)(definitions, 'data/customer-preferences.fb'), records: preferences
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe('selection and cursor lifecycle', () => {
|
|
50
|
+
it('defaults to the first ten records, stopping at EOF', async () => {
|
|
51
|
+
expect((await display('customers')).records).toEqual(customers);
|
|
52
|
+
});
|
|
53
|
+
it('limits the number of records emitted', async () => {
|
|
54
|
+
expect((await display('customers', { count: 1 })).records).toEqual([customers[0]]);
|
|
55
|
+
});
|
|
56
|
+
it('skips records before applying the count', async () => {
|
|
57
|
+
expect((await display('customers', { skip: 1, count: 1 })).records).toEqual([customers[1]]);
|
|
58
|
+
});
|
|
59
|
+
it('returns no records when the skip exceeds EOF', async () => {
|
|
60
|
+
expect((await display('customers', { skip: 99 })).records).toEqual([]);
|
|
61
|
+
});
|
|
62
|
+
it('reports invalid count and skip values', async () => {
|
|
63
|
+
expect(await (0, file_display_1.openFileDisplay)({ configDirectory, logicalName: 'customers', count: 0, skip: -1, all: true })).toEqual({ errors: [
|
|
64
|
+
'Display count must be a positive integer',
|
|
65
|
+
'Display skip must be a nonnegative integer',
|
|
66
|
+
'Display --all and --count cannot be combined'
|
|
67
|
+
] });
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('data file overrides and diagnostics', () => {
|
|
71
|
+
let root;
|
|
72
|
+
beforeEach(async () => {
|
|
73
|
+
root = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-display-'));
|
|
74
|
+
await (0, promises_1.mkdir)((0, node_path_1.join)(root, 'data'));
|
|
75
|
+
await (0, promises_1.copyFile)((0, node_path_1.join)(definitions, 'data/customers.fb'), (0, node_path_1.join)(root, 'data/customers.fb'));
|
|
76
|
+
});
|
|
77
|
+
afterEach(async () => { await (0, promises_1.rm)(root, { recursive: true, force: true }); });
|
|
78
|
+
it('uses an explicit input filename without reading data.yaml', async () => {
|
|
79
|
+
expect((await display('customers', { input: (0, node_path_1.join)(root, 'data/customers.fb'), data: 'no-data.yaml' })).records).toEqual(customers);
|
|
80
|
+
});
|
|
81
|
+
it('rejects an unknown logical name', async () => {
|
|
82
|
+
expect(await (0, file_display_1.openFileDisplay)({ configDirectory, logicalName: 'missing' })).toEqual({ errors: [
|
|
83
|
+
'Unknown logical file "missing"'
|
|
84
|
+
] });
|
|
85
|
+
});
|
|
86
|
+
it('rejects a binding without a physical filename', async () => {
|
|
87
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(root, 'missing.yaml'), 'root: ../data\nfiles:\n customerPreferences: customer-preferences.fb\n');
|
|
88
|
+
const result = await (0, file_display_1.openFileDisplay)({ configDirectory, logicalName: 'customers', data: (0, node_path_1.join)(root, 'missing.yaml') });
|
|
89
|
+
expect(result).toEqual({ errors: [`No data file configured for "customers" in ${(0, node_path_1.join)(root, 'missing.yaml')}`] });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
//# sourceMappingURL=file.display.int.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.display.int.spec.js","sourceRoot":"","sources":["../../src/file.display.int.spec.ts"],"names":[],"mappings":";;AAAA,yCAAuC;AACvC,+CAAwE;AACxE,qCAA8B;AAC9B,2CAA6C;AAC7C,iDAAmE;AAEnE,MAAM,WAAW,GAAG,IAAA,mBAAO,EAAC,SAAS,EAAE,uCAAuC,CAAC,CAAA;AAC/E,MAAM,eAAe,GAAG,IAAA,gBAAI,EAAC,WAAW,EAAE,UAAU,CAAC,CAAA;AAErD,MAAM,SAAS,GAAG;IACd,EAAC,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAC;QACjH,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,EAAC,eAAe,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAC,EAAE,QAAQ,EAAE,CAAC,EAAC,CAAC,EAAC;IAC5H,EAAC,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAC;QACjH,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE;YACnB,EAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,EAAC,eAAe,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAC,E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MAAM,MAAM,GAAG,MAAM,IAAA,8BAAe,EAAC,EAAC,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,IAAA,gBAAI,EAAC,IAAI,EAAE,cAAc,CAAC,EAAC,CAAC,CAAA;YACnH,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAC,MAAM,EAAE,CAAC,8CAA8C,IAAA,gBAAI,EAAC,IAAI,EAAE,cAAc,CAAC,EAAE,CAAC,EAAC,CAAC,CAAA;QAClH,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openFileDisplay = openFileDisplay;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const files_1 = require("@cobol-ts/files");
|
|
6
|
+
const copybook_1 = require("@cobol-ts/copybook");
|
|
7
|
+
const default_projection_typescript_1 = require("@cobol-ts/default-projection-typescript");
|
|
8
|
+
const cursor_projection_1 = require("@cobol-ts/cursor-projection");
|
|
9
|
+
const cobol_file_node_1 = require("@cobol-ts/cursor-loader-cobol/src/cobol.file.node");
|
|
10
|
+
const errors_1 = require("@cobol-ts/errors");
|
|
11
|
+
const file_catalogue_1 = require("@cobol-ts/file-catalogue");
|
|
12
|
+
const projection_json_1 = require("./projection.json");
|
|
13
|
+
function validateOptions(options) {
|
|
14
|
+
const diagnostics = [];
|
|
15
|
+
if (!options.logicalName.trim())
|
|
16
|
+
diagnostics.push('Display logical name must not be empty');
|
|
17
|
+
if (options.count !== undefined && (!Number.isSafeInteger(options.count) || options.count < 1)) {
|
|
18
|
+
diagnostics.push('Display count must be a positive integer');
|
|
19
|
+
}
|
|
20
|
+
if (options.skip !== undefined && (!Number.isSafeInteger(options.skip) || options.skip < 0)) {
|
|
21
|
+
diagnostics.push('Display skip must be a nonnegative integer');
|
|
22
|
+
}
|
|
23
|
+
if (options.all && options.count !== undefined)
|
|
24
|
+
diagnostics.push('Display --all and --count cannot be combined');
|
|
25
|
+
return diagnostics;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the configured input and create a one-pass JSONL stream. Neither
|
|
29
|
+
* generation.yaml nor generated TypeScript participates in this operation.
|
|
30
|
+
*/
|
|
31
|
+
async function openFileDisplay(options, files = files_1.nodeTextFiles) {
|
|
32
|
+
const invalid = validateOptions(options);
|
|
33
|
+
if (invalid.length)
|
|
34
|
+
return { errors: [...invalid] };
|
|
35
|
+
const directory = (0, node_path_1.resolve)(options.configDirectory);
|
|
36
|
+
const catalogueFilename = (0, node_path_1.resolve)(directory, options.catalogue ?? 'files.yaml');
|
|
37
|
+
const catalogue = await (0, file_catalogue_1.readFileCatalogue)(files, catalogueFilename);
|
|
38
|
+
if ('errors' in catalogue)
|
|
39
|
+
return catalogue;
|
|
40
|
+
const definition = catalogue.value.files[options.logicalName];
|
|
41
|
+
if (!definition)
|
|
42
|
+
return { errors: [`Unknown logical file ${JSON.stringify(options.logicalName)}`] };
|
|
43
|
+
if (definition.type !== 'cobol') {
|
|
44
|
+
return { errors: [`Display of ${JSON.stringify(options.logicalName)}: Format ${JSON.stringify(definition.type)} is not yet supported`] };
|
|
45
|
+
}
|
|
46
|
+
const sourceRoot = (0, node_path_1.resolve)(directory, catalogue.value.root);
|
|
47
|
+
if ((0, node_path_1.isAbsolute)(definition.copybook) || node_path_1.win32.isAbsolute(definition.copybook)) {
|
|
48
|
+
return { errors: [`Copybook for ${options.logicalName}: Expected a relative filename`] };
|
|
49
|
+
}
|
|
50
|
+
const sourcePath = (0, node_path_1.resolve)(sourceRoot, definition.copybook);
|
|
51
|
+
const suffix = (0, node_path_1.relative)(sourceRoot, sourcePath);
|
|
52
|
+
if (!suffix || suffix === '..' || suffix.startsWith('../') || suffix.startsWith('..\\')) {
|
|
53
|
+
return { errors: [`Copybook for ${options.logicalName}: Path escapes source root`] };
|
|
54
|
+
}
|
|
55
|
+
// The configuration's source-root escape rules are shared with the manifest resolver.
|
|
56
|
+
const resolvedFile = await readDataPath(files, options, catalogue.value, directory);
|
|
57
|
+
if ('errors' in resolvedFile)
|
|
58
|
+
return resolvedFile;
|
|
59
|
+
let copybook;
|
|
60
|
+
try {
|
|
61
|
+
copybook = await files.read(sourcePath);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return { errors: [`Reading copybook for ${options.logicalName} (${sourcePath}): ${error instanceof Error ? error.message : String(error)}`] };
|
|
65
|
+
}
|
|
66
|
+
const ast = (0, copybook_1.parseCopybook)(copybook);
|
|
67
|
+
if ('errors' in ast)
|
|
68
|
+
return ast;
|
|
69
|
+
const projected = (0, default_projection_typescript_1.createDefaultProjection)(ast.value);
|
|
70
|
+
if ('errors' in projected)
|
|
71
|
+
return projected;
|
|
72
|
+
const model = projected.value;
|
|
73
|
+
const framing = definition.options?.framing;
|
|
74
|
+
// Runtime's ProjectionDefinition<T> encodes the same tree. Here the
|
|
75
|
+
// generated-interface type is intentionally not part of the display pipeline.
|
|
76
|
+
const runtimeProjection = (0, cursor_projection_1.canonicalProjection)(model);
|
|
77
|
+
const filename = resolvedFile.value;
|
|
78
|
+
const count = options.all ? undefined : (options.count ?? 10);
|
|
79
|
+
const skip = options.skip ?? 0;
|
|
80
|
+
async function* lines() {
|
|
81
|
+
let visited = 0;
|
|
82
|
+
let emitted = 0;
|
|
83
|
+
for await (const record of (0, cobol_file_node_1.readCobolFile)({
|
|
84
|
+
filename, copybook: sourcePath, projection: runtimeProjection,
|
|
85
|
+
...(framing ? { framing } : {}),
|
|
86
|
+
...(options.bufferSize ? { bufferSize: options.bufferSize } : {})
|
|
87
|
+
})) {
|
|
88
|
+
try {
|
|
89
|
+
visited++;
|
|
90
|
+
if (visited <= skip)
|
|
91
|
+
continue;
|
|
92
|
+
let json;
|
|
93
|
+
try {
|
|
94
|
+
json = JSON.stringify((0, projection_json_1.projectionToJson)(model, record.result));
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw new Error(`Displaying ${options.logicalName}, record ${visited}: ${error instanceof Error ? error.message : String(error)}`);
|
|
98
|
+
}
|
|
99
|
+
emitted++;
|
|
100
|
+
yield json;
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
record.close();
|
|
104
|
+
}
|
|
105
|
+
if (count !== undefined && emitted >= count)
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return (0, errors_1.value)({ filename, lines: lines() });
|
|
110
|
+
}
|
|
111
|
+
async function readDataPath(files, options, catalogue, directory) {
|
|
112
|
+
if (options.input !== undefined) {
|
|
113
|
+
if (!options.input.trim())
|
|
114
|
+
return { errors: ['Display input filename must not be empty'] };
|
|
115
|
+
return (0, errors_1.value)((0, node_path_1.resolve)(options.input));
|
|
116
|
+
}
|
|
117
|
+
const dataFilename = (0, node_path_1.resolve)(directory, options.data ?? 'data.yaml');
|
|
118
|
+
const data = await (0, file_catalogue_1.readDataFileConfiguration)(files, dataFilename);
|
|
119
|
+
if ('errors' in data)
|
|
120
|
+
return data;
|
|
121
|
+
const resolved = (0, file_catalogue_1.resolveDataFiles)(catalogue, data.value, directory);
|
|
122
|
+
if ('errors' in resolved)
|
|
123
|
+
return resolved;
|
|
124
|
+
const found = resolved.value.find(entry => entry.logicalName === options.logicalName);
|
|
125
|
+
return found ? (0, errors_1.value)(found.filename) : { errors: [`No data file configured for ${JSON.stringify(options.logicalName)} in ${dataFilename}`] };
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=file.display.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.display.js","sourceRoot":"","sources":["../../src/file.display.ts"],"names":[],"mappings":";;AAsDA,0CAuEC;AA7HD,yCAA8D;AAE9D,2CAA6C;AAC7C,iDAAgD;AAChD,2FAA+E;AAC/E,mEAA+D;AAG/D,uFAA+E;AAC/E,6CAAqD;AACrD,6DAG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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProjectionAuthoring } from '@cobol-ts/cursor-loader-types';
|
|
2
|
+
/** A record is borrowed. Copy its selected values before closing the cursor lease. */
|
|
3
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
};
|
|
6
|
+
/** Traverse the definition, not the runtime object's private implementation. */
|
|
7
|
+
export declare function projectionToJson(projection: ProjectionAuthoring, source: unknown): Record<string, JsonValue>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.projectionToJson = projectionToJson;
|
|
4
|
+
function object(value, context) {
|
|
5
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
6
|
+
throw new Error(`${context}: Expected a projected object`);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
/** Traverse the definition, not the runtime object's private implementation. */
|
|
11
|
+
function projectionToJson(projection, source) {
|
|
12
|
+
function fields(definition, row, context) {
|
|
13
|
+
const instance = object(row, context);
|
|
14
|
+
const result = {};
|
|
15
|
+
for (const [key, node] of Object.entries(definition)) {
|
|
16
|
+
const name = `${context}.${key}`;
|
|
17
|
+
const member = instance[key];
|
|
18
|
+
if (node.type === 'object') {
|
|
19
|
+
result[key] = fields(node.fields, member, name);
|
|
20
|
+
}
|
|
21
|
+
else if (node.type === 'array') {
|
|
22
|
+
if (member === null || typeof member !== 'object') {
|
|
23
|
+
throw new Error(`${name}: Expected a projected array`);
|
|
24
|
+
}
|
|
25
|
+
const array = member;
|
|
26
|
+
if (typeof array.length !== 'number' || !Number.isSafeInteger(array.length) || array.length < 0) {
|
|
27
|
+
throw new Error(`${name}: Invalid projected array length`);
|
|
28
|
+
}
|
|
29
|
+
const entries = [];
|
|
30
|
+
for (let index = 0; index < array.length; index++) {
|
|
31
|
+
entries.push(fields(node.element, array[index], `${name}[${index}]`));
|
|
32
|
+
}
|
|
33
|
+
result[key] = entries;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (typeof member !== 'function')
|
|
37
|
+
throw new Error(`${name}: Expected a terminal accessor`);
|
|
38
|
+
const selected = Reflect.apply(member, instance, []);
|
|
39
|
+
const numeric = node.type === 'integer' || node.type === 'float';
|
|
40
|
+
if (numeric ? typeof selected !== 'number' || !Number.isFinite(selected) : typeof selected !== 'string') {
|
|
41
|
+
throw new Error(`${name}: Invalid ${numeric ? 'numeric' : 'string'} value`);
|
|
42
|
+
}
|
|
43
|
+
result[key] = selected;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
return fields(projection, source, 'record');
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=projection.json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.json.js","sourceRoot":"","sources":["../../src/projection.json.ts"],"names":[],"mappings":";;AAaA,4CAmCC;AA3CD,SAAS,MAAM,CAAC,KAAc,EAAE,OAAe;IAC3C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,+BAA+B,CAAC,CAAA;IAC9D,CAAC;IACD,OAAO,KAAgC,CAAA;AAC3C,CAAC;AAED,gFAAgF;AAChF,SAAgB,gBAAgB,CAAC,UAA+B,EAAE,MAAe;IAC7E,SAAS,MAAM,CAAC,UAA+B,EAAE,GAAY,EAAE,OAAe;QAC1E,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QACrC,MAAM,MAAM,GAA8B,EAAE,CAAA;QAC5C,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,C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GAAG,IAAI,gCAAgC,CAAC,CAAA;gBAC1F,MAAM,QAAQ,GAAY,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAA;gBAC7D,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,CAAA;gBAChE,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;oBACtG,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,aAAa,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,QAAQ,CAAC,CAAA;gBAC/E,CAAC;gBACD,MAAM,CAAC,GAAG,CAAC,GAAG,QAA2B,CAAA;YAC7C,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAA;IACjB,CAAC;IACD,OAAO,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;AAC/C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const projection_json_1 = require("./projection.json");
|
|
4
|
+
const definition = {
|
|
5
|
+
id: { type: 'integer', path: ['ID'] },
|
|
6
|
+
orders: { type: 'array', path: ['ORDERS'], element: {
|
|
7
|
+
product: { type: 'string', path: ['PRODUCT'] },
|
|
8
|
+
parts: { type: 'object', path: ['PRODUCT-PARTS'], fields: {
|
|
9
|
+
category: { type: 'string', path: ['CATEGORY'] }
|
|
10
|
+
} }
|
|
11
|
+
} }
|
|
12
|
+
};
|
|
13
|
+
describe('projection JSON materialisation', () => {
|
|
14
|
+
it('reads terminal accessors, nested REDEFINES views and each active occurrence', () => {
|
|
15
|
+
expect((0, projection_json_1.projectionToJson)(definition, {
|
|
16
|
+
id: () => 1002,
|
|
17
|
+
orders: [
|
|
18
|
+
{ product: () => 'B001', parts: { category: () => 'B0' } },
|
|
19
|
+
{ product: () => 'C202', parts: { category: () => 'C2' } }
|
|
20
|
+
]
|
|
21
|
+
})).toEqual({
|
|
22
|
+
id: 1002,
|
|
23
|
+
orders: [
|
|
24
|
+
{ product: 'B001', parts: { category: 'B0' } },
|
|
25
|
+
{ product: 'C202', parts: { category: 'C2' } }
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
it('does not access inactive array slots', () => {
|
|
30
|
+
let inactiveReads = 0;
|
|
31
|
+
const orders = { length: 0, get 0() { inactiveReads++; throw new Error('inactive slot'); } };
|
|
32
|
+
expect((0, projection_json_1.projectionToJson)(definition, { id: () => 1003, orders })).toEqual({ id: 1003, orders: [] });
|
|
33
|
+
expect(inactiveReads).toEqual(0);
|
|
34
|
+
});
|
|
35
|
+
it('rejects invalid values rather than converting them silently to JSON null', () => {
|
|
36
|
+
expect(() => (0, projection_json_1.projectionToJson)({ balance: { type: 'float' } }, { balance: () => Number.NaN }))
|
|
37
|
+
.toThrow('record.balance: Invalid numeric value');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=projection.json.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.json.spec.js","sourceRoot":"","sources":["../../src/projection.json.spec.ts"],"names":[],"mappings":";;AACA,uDAAkD;AAElD,MAAM,UAAU,GAAwB;IACpC,EAAE,EAAE,EAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAC;IACnC,MAAM,EAAE,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE;YAC/C,OAAO,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAE,IAA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AC,EAAE,CAAA;QACxF,MAAM,CAAC,IAAA,kCAAgB,EAAC,UAAU,EAAE,EAAC,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAC,CAAC,CAAA;QAC9F,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0EAA0E,EAAE,GAAG,EAAE;QAChF,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,kCAAgB,EAAC,EAAC,OAAO,EAAE,EAAC,IAAI,EAAE,OAAO,EAAC,EAAC,EAAE,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAC,CAAC,CAAC;aAClF,OAAO,CAAC,uCAAuC,CAAC,CAAA;IACzD,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobol-ts/file-display",
|
|
3
3
|
"description": "Stream JSONL from configured COBOL data files using an in-memory default projection",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"types": "dist/index",
|
|
7
7
|
"browserslist": {
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@cobol-ts/files": "0.0.
|
|
21
|
-
"@cobol-ts/errors": "0.0.
|
|
22
|
-
"@cobol-ts/file-catalogue": "0.0.
|
|
23
|
-
"@cobol-ts/copybook": "0.0.
|
|
24
|
-
"@cobol-ts/default-projection-typescript": "0.0.
|
|
25
|
-
"@cobol-ts/cursor-loader-types": "0.0.
|
|
26
|
-
"@cobol-ts/cursor-loader-cobol": "0.0.
|
|
27
|
-
"@cobol-ts/cursor-projection": "0.0.
|
|
20
|
+
"@cobol-ts/files": "0.0.5",
|
|
21
|
+
"@cobol-ts/errors": "0.0.5",
|
|
22
|
+
"@cobol-ts/file-catalogue": "0.0.5",
|
|
23
|
+
"@cobol-ts/copybook": "0.0.5",
|
|
24
|
+
"@cobol-ts/default-projection-typescript": "0.0.5",
|
|
25
|
+
"@cobol-ts/cursor-loader-types": "0.0.5",
|
|
26
|
+
"@cobol-ts/cursor-loader-cobol": "0.0.5",
|
|
27
|
+
"@cobol-ts/cursor-projection": "0.0.5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"typescript": "^5.2.2",
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"dist/index.js",
|
|
55
55
|
"dist/index.d.ts",
|
|
56
56
|
"dist/src/",
|
|
57
|
-
"build/"
|
|
57
|
+
"build/",
|
|
58
|
+
"dist/**/*"
|
|
58
59
|
],
|
|
59
60
|
"keywords": [
|
|
60
61
|
"indexing"
|