@cobol-ts/composition-definition 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 +86 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/src/composition.definition.d.ts +36 -0
- package/dist/src/composition.definition.js +198 -0
- package/dist/src/composition.definition.js.map +1 -0
- package/dist/src/composition.definition.spec.d.ts +1 -0
- package/dist/src/composition.definition.spec.js +68 -0
- package/dist/src/composition.definition.spec.js.map +1 -0
- package/dist/src/composition.prepare.d.ts +17 -0
- package/dist/src/composition.prepare.integration.spec.d.ts +1 -0
- package/dist/src/composition.prepare.integration.spec.js +99 -0
- package/dist/src/composition.prepare.integration.spec.js.map +1 -0
- package/dist/src/composition.prepare.js +86 -0
- package/dist/src/composition.prepare.js.map +1 -0
- package/package.json +66 -3
package/README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cobol-ts/composition-definition
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This module reads `.cobolts/files.yaml`, validates entity and relationship declarations, and prepares a streaming composition using the existing physical source readers and `@cobol-ts/cursor-composition`. It does not implement a second merge algorithm or materialise whole customer records.
|
|
4
|
+
|
|
5
|
+
## Quick orientation
|
|
6
|
+
|
|
7
|
+
**Responsibility.** Parse and validate entity identities, files, mappings and composition declarations and prepare a streaming join from configured readers.
|
|
8
|
+
|
|
9
|
+
**Boundary.** The module resolves declarations and keys; `cursor-composition` performs the ordered merge.
|
|
10
|
+
|
|
11
|
+
**Public modules.** [composition.definition.ts](./src/composition.definition.ts), [composition.prepare.ts](./src/composition.prepare.ts).
|
|
12
|
+
|
|
13
|
+
**Tests.** [composition.definition.spec.ts](src/composition.definition.spec.ts), [composition.prepare.integration.spec.ts](src/composition.prepare.integration.spec.ts)
|
|
14
|
+
|
|
15
|
+
**Related packages.** [@cobol-ts/file-catalogue](../file-catalogue/README.md) · [@cobol-ts/cursor-composition](../../cursor-loader/cursor-composition/README.md).
|
|
16
|
+
|
|
17
|
+
## Declaration
|
|
18
|
+
|
|
19
|
+
The physical catalogue, entity identities, mappings, and composition are declared together in `files.yaml`. The separate `data.yaml` binds each logical file and mapping name to a physical filename.
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
root: ../copybooks
|
|
23
|
+
entities:
|
|
24
|
+
- customer
|
|
25
|
+
- account
|
|
26
|
+
files:
|
|
27
|
+
customers:
|
|
28
|
+
type: cobol
|
|
29
|
+
copybook: CUSTOMER.cpy
|
|
30
|
+
key: customer
|
|
31
|
+
keyPath: customerId
|
|
32
|
+
accounts:
|
|
33
|
+
type: jsonl
|
|
34
|
+
key: account
|
|
35
|
+
keyPath: id
|
|
36
|
+
projection:
|
|
37
|
+
id: {type: integer}
|
|
38
|
+
balance: {type: integer}
|
|
39
|
+
mappings:
|
|
40
|
+
accountCustomerMap:
|
|
41
|
+
type: csv
|
|
42
|
+
key: account
|
|
43
|
+
keyPath: id
|
|
44
|
+
projection:
|
|
45
|
+
id: {type: integer}
|
|
46
|
+
custid: {type: integer}
|
|
47
|
+
foreign:
|
|
48
|
+
custid: customer
|
|
49
|
+
composition:
|
|
50
|
+
master: customers
|
|
51
|
+
files:
|
|
52
|
+
customers: one
|
|
53
|
+
accounts:
|
|
54
|
+
cardinality: manyOptional
|
|
55
|
+
mapping: accountCustomerMap
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`keyPath` is mandatory for **every composed physical source and mapping**. It names a scalar in that source's projection, and compilation rejects nonexistent and nonscalar paths. There is no identity-name inference. A file whose entity is not the master's entity must explicitly name the mapping through `composition.files.<name>.mapping`; absent or ambiguous mappings are validation errors. Direct same-entity files use a scalar cardinality (`one`, `optional`, `many`, or `manyOptional`) without a mapping.
|
|
59
|
+
|
|
60
|
+
For non-COBOL sources (`csv`, `jsonl`, `protobuf`, `indexed-graph-state`), `projection` declares the physical field types. A field has `type: integer`, `float`, `string`, or `character`; nested objects use `type: object` plus `fields`, and collections use `type: array` plus `element`. Declarations are checked when a source is prepared, before scanning. COBOL derives its projection from the configured copybook. No field types are inferred from sample input rows, and no benchmark-only projection arguments are required.
|
|
61
|
+
|
|
62
|
+
## Preparation and execution
|
|
63
|
+
|
|
64
|
+
`readCompositionDefinition(configDirectory)` parses and validates the document, checking declared entities and mappings against the physical file catalogue. `prepareCompositionDefinition(definition, openFile)` obtains the configured readers, binds each key and foreign-key path once, and constructs the streaming merge. The same source resolver, `prepareConfiguredFileSource`, is used by the normal CLI and by composition benchmarks.
|
|
65
|
+
|
|
66
|
+
Every input is expected to be sorted in the relevant key order. Mapping files must have unique, strictly increasing source IDs, and their effective customer keys must be nondecreasing. The master defines the customer domain. Cardinality violations, unmatched children, conflicting entities, duplicate singular records, unsorted keys and malformed physical inputs fail rather than silently drop data.
|
|
67
|
+
|
|
68
|
+
Physical input leases and mapping leases remain owned by their cursors until transferred to a composite record. The caller closes every yielded composite lease, including when evaluation fails; closing it releases the borrowed physical records. An iterator's cleanup releases outstanding lookahead leases. The indexed accumulator joins its own optional, sorted historical file, and does **not write any accumulator file**.
|
|
69
|
+
|
|
70
|
+
CEL continues to use its existing *safe* access rules. Optional singular dereference is not made unsafe or silently defaulted.
|
|
71
|
+
|
|
72
|
+
## Benchmarks
|
|
73
|
+
|
|
74
|
+
The existing five individual-format benchmarks remain independent. The separate `format-composed` benchmark reads COBOL, CSV, JSONL, Protobuf, and Indexed Graph State physical sources together, with a CSV account-to-customer mapping. Its one-to-many accounts are exercised by a non-cancelling CEL reduction. The generated `files.yaml` contains all projection declarations; the benchmark does not inject private projection objects.
|
|
75
|
+
|
|
76
|
+
```powershell
|
|
77
|
+
yarn cobolts benchmark init formats -n 10000 --graph-nodes 1000 --force
|
|
78
|
+
yarn cobolts benchmark composition verify -n 10000
|
|
79
|
+
yarn cobolts benchmark composition run -n 10000 --runs 3 --accumulator-strategy object
|
|
80
|
+
yarn cobolts benchmark composition run -n 10000 --runs 3 --accumulator-strategy indexed
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Tests and ownership contract
|
|
84
|
+
|
|
85
|
+
The test suite includes exact YAML diagnostics, nested projection validation, real JSONL/CSV mapped joins, mixed-source compiled CEL, and CLI integration for COBOL, CSV, JSONL, Protobuf and Indexed Graph State. Lower-level lease tests assert exact acquisition/release counts for `one`, `optional`, `many`, and `manyOptional` joins, duplicates, missing and orphan records, bad order, early termination, source exceptions and mapped-source failures.
|
|
86
|
+
|
|
87
|
+
`yarn test` in the repository must pass before production use. The module does not claim to infer new input schemas, implement unsafe CEL access or persist accumulator state.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src/composition.definition"), exports);
|
|
18
|
+
__exportStar(require("./src/composition.prepare"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C;AAC7C,4DAA0C"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ErrorsOr } from '@cobol-ts/errors';
|
|
2
|
+
import type { Cardinality } from '@cobol-ts/cursor-composition';
|
|
3
|
+
import { type FileCatalogue } from '@cobol-ts/file-catalogue';
|
|
4
|
+
export interface ComposedFileDefinition {
|
|
5
|
+
readonly key: string;
|
|
6
|
+
/** Explicit physical scalar path for this entity ID. */
|
|
7
|
+
readonly keyPath: string;
|
|
8
|
+
readonly type?: 'cobol' | 'csv' | 'jsonl' | 'protobuf' | 'indexed-graph-state';
|
|
9
|
+
readonly copybook?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MappingDefinition {
|
|
12
|
+
readonly type: 'csv' | 'jsonl' | 'cobol' | 'protobuf' | 'indexed-graph-state';
|
|
13
|
+
readonly key: string;
|
|
14
|
+
/** Explicit physical scalar path for the source entity ID. */
|
|
15
|
+
readonly keyPath: string;
|
|
16
|
+
readonly foreign: Readonly<Record<string, string>>;
|
|
17
|
+
}
|
|
18
|
+
export interface CompositionMember {
|
|
19
|
+
readonly cardinality: Cardinality;
|
|
20
|
+
readonly mapping?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface CompositionDefinition {
|
|
23
|
+
readonly entities: readonly string[];
|
|
24
|
+
readonly files: Readonly<Record<string, ComposedFileDefinition>>;
|
|
25
|
+
readonly mappings: Readonly<Record<string, MappingDefinition>>;
|
|
26
|
+
readonly composition: {
|
|
27
|
+
readonly master: string;
|
|
28
|
+
readonly files: Readonly<Record<string, CompositionMember>>;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Decode the agreed entities/files/mappings/composition document. Never infer relationships from filenames. */
|
|
32
|
+
export declare function parseCompositionDefinition(input: unknown): ErrorsOr<CompositionDefinition>;
|
|
33
|
+
/** Cross-check duplicate physical metadata against the authoritative catalogue. */
|
|
34
|
+
export declare function validateCompositionCatalogue(definition: CompositionDefinition, catalogue: FileCatalogue): ErrorsOr<CompositionDefinition>;
|
|
35
|
+
export declare function hasCompositionDefinition(configDirectory: string): Promise<boolean>;
|
|
36
|
+
export declare function readCompositionDefinition(configDirectory: string, filename?: string): Promise<ErrorsOr<CompositionDefinition>>;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCompositionDefinition = parseCompositionDefinition;
|
|
4
|
+
exports.validateCompositionCatalogue = validateCompositionCatalogue;
|
|
5
|
+
exports.hasCompositionDefinition = hasCompositionDefinition;
|
|
6
|
+
exports.readCompositionDefinition = readCompositionDefinition;
|
|
7
|
+
const promises_1 = require("node:fs/promises");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const yaml_jsyaml_1 = require("@cobol-ts/yaml-jsyaml");
|
|
10
|
+
const errors_1 = require("@cobol-ts/errors");
|
|
11
|
+
const file_catalogue_1 = require("@cobol-ts/file-catalogue");
|
|
12
|
+
const record = (input) => typeof input === 'object' && input !== null && !Array.isArray(input) ? input : undefined;
|
|
13
|
+
const name = (input) => typeof input === 'string' && /^[A-Za-z][A-Za-z0-9_-]*$/.test(input);
|
|
14
|
+
const isPath = (input) => typeof input === 'string' && input.split('.').every(name);
|
|
15
|
+
const cardinality = (value) => value === 'one' || value === 'optional' || value === 'many' || value === 'manyOptional';
|
|
16
|
+
const types = ['cobol', 'csv', 'jsonl', 'protobuf', 'indexed-graph-state'];
|
|
17
|
+
const unexpected = (data, allowed, path, diagnostics) => {
|
|
18
|
+
for (const key of Object.keys(data))
|
|
19
|
+
if (!allowed.includes(key))
|
|
20
|
+
diagnostics.push(`${path}.${key}: Unknown field`);
|
|
21
|
+
};
|
|
22
|
+
/** Decode the agreed entities/files/mappings/composition document. Never infer relationships from filenames. */
|
|
23
|
+
function parseCompositionDefinition(input) {
|
|
24
|
+
const diagnostics = [];
|
|
25
|
+
const root = record(input);
|
|
26
|
+
if (!root)
|
|
27
|
+
return (0, errors_1.errors)('Composition: Expected a mapping');
|
|
28
|
+
unexpected(root, ['root', 'entities', 'files', 'mappings', 'composition'], 'Composition', diagnostics);
|
|
29
|
+
const entities = [];
|
|
30
|
+
if (!Array.isArray(root.entities) || root.entities.length === 0)
|
|
31
|
+
diagnostics.push('Composition.entities: Expected a nonempty list');
|
|
32
|
+
else
|
|
33
|
+
for (const [index, entry] of root.entities.entries()) {
|
|
34
|
+
if (!name(entry))
|
|
35
|
+
diagnostics.push(`Composition.entities[${index}]: Expected an entity name`);
|
|
36
|
+
else if (entities.includes(entry))
|
|
37
|
+
diagnostics.push(`Composition.entities[${index}]: Duplicate entity ${entry}`);
|
|
38
|
+
else
|
|
39
|
+
entities.push(entry);
|
|
40
|
+
}
|
|
41
|
+
const files = {};
|
|
42
|
+
const fileEntries = record(root.files);
|
|
43
|
+
if (!fileEntries || Object.keys(fileEntries).length === 0)
|
|
44
|
+
diagnostics.push('Composition.files: Expected a nonempty mapping');
|
|
45
|
+
else
|
|
46
|
+
for (const [logical, raw] of Object.entries(fileEntries)) {
|
|
47
|
+
const path = `Composition.files.${logical}`;
|
|
48
|
+
const definition = record(raw);
|
|
49
|
+
if (!name(logical) || !definition) {
|
|
50
|
+
diagnostics.push(`${path}: Expected a named file mapping`);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
unexpected(definition, ['key', 'keyPath', 'type', 'copybook', 'description', 'options', 'projection'], path, diagnostics);
|
|
54
|
+
if (!name(definition.key) || !entities.includes(definition.key))
|
|
55
|
+
diagnostics.push(`${path}.key: Unknown entity ${String(definition.key)}`);
|
|
56
|
+
if (!isPath(definition.keyPath))
|
|
57
|
+
diagnostics.push(`${path}.keyPath: Expected a scalar field path`);
|
|
58
|
+
if (definition.type !== undefined && !types.includes(String(definition.type)))
|
|
59
|
+
diagnostics.push(`${path}.type: Unsupported physical type`);
|
|
60
|
+
if (definition.copybook !== undefined && (definition.type !== 'cobol' || typeof definition.copybook !== 'string' || !definition.copybook.trim()))
|
|
61
|
+
diagnostics.push(`${path}.copybook: Requires a COBOL type and nonempty filename`);
|
|
62
|
+
if (name(definition.key) && entities.includes(definition.key) &&
|
|
63
|
+
(definition.type === undefined || types.includes(String(definition.type))))
|
|
64
|
+
files[logical] = { key: definition.key, keyPath: definition.keyPath, ...(definition.type ? { type: definition.type } : {}),
|
|
65
|
+
...(typeof definition.copybook === 'string' ? { copybook: definition.copybook } : {}) };
|
|
66
|
+
}
|
|
67
|
+
const mappings = {};
|
|
68
|
+
const mappingEntries = root.mappings === undefined ? {} : record(root.mappings);
|
|
69
|
+
if (!mappingEntries)
|
|
70
|
+
diagnostics.push('Composition.mappings: Expected a mapping');
|
|
71
|
+
else
|
|
72
|
+
for (const [logical, raw] of Object.entries(mappingEntries)) {
|
|
73
|
+
const path = `Composition.mappings.${logical}`;
|
|
74
|
+
const entry = record(raw);
|
|
75
|
+
if (!name(logical) || !entry) {
|
|
76
|
+
diagnostics.push(`${path}: Expected a named mapping`);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
unexpected(entry, ['type', 'key', 'keyPath', 'foreign', 'copybook', 'description', 'options', 'projection'], path, diagnostics);
|
|
80
|
+
if (!types.includes(String(entry.type)))
|
|
81
|
+
diagnostics.push(`${path}.type: Unsupported physical type`);
|
|
82
|
+
if (!isPath(entry.keyPath))
|
|
83
|
+
diagnostics.push(`${path}.keyPath: Expected a scalar field path`);
|
|
84
|
+
if (!name(entry.key) || !entities.includes(entry.key))
|
|
85
|
+
diagnostics.push(`${path}.key: Unknown entity ${String(entry.key)}`);
|
|
86
|
+
const foreign = record(entry.foreign);
|
|
87
|
+
if (!foreign || Object.keys(foreign).length === 0)
|
|
88
|
+
diagnostics.push(`${path}.foreign: Expected at least one foreign-key field`);
|
|
89
|
+
else
|
|
90
|
+
for (const [pathName, target] of Object.entries(foreign)) {
|
|
91
|
+
if (!pathName.split('.').every(name))
|
|
92
|
+
diagnostics.push(`${path}.foreign: Invalid path ${pathName}`);
|
|
93
|
+
if (!name(target) || !entities.includes(target))
|
|
94
|
+
diagnostics.push(`${path}.foreign.${pathName}: Unknown entity ${String(target)}`);
|
|
95
|
+
}
|
|
96
|
+
if (types.includes(String(entry.type)) && name(entry.key) && entities.includes(entry.key) && foreign)
|
|
97
|
+
mappings[logical] = { type: entry.type, key: entry.key,
|
|
98
|
+
keyPath: entry.keyPath,
|
|
99
|
+
foreign: foreign };
|
|
100
|
+
}
|
|
101
|
+
const composition = record(root.composition);
|
|
102
|
+
const roles = {};
|
|
103
|
+
let master = '';
|
|
104
|
+
if (!composition)
|
|
105
|
+
diagnostics.push('Composition.composition: Expected a mapping');
|
|
106
|
+
else {
|
|
107
|
+
unexpected(composition, ['master', 'files'], 'Composition.composition', diagnostics);
|
|
108
|
+
if (!name(composition.master) || !Object.hasOwn(files, composition.master))
|
|
109
|
+
diagnostics.push(`Composition.composition.master: Unknown composed file ${String(composition.master)}`);
|
|
110
|
+
else
|
|
111
|
+
master = composition.master;
|
|
112
|
+
const members = record(composition.files);
|
|
113
|
+
if (!members || Object.keys(members).length === 0)
|
|
114
|
+
diagnostics.push('Composition.composition.files: Expected a nonempty mapping');
|
|
115
|
+
else
|
|
116
|
+
for (const [logical, raw] of Object.entries(members)) {
|
|
117
|
+
if (!Object.hasOwn(files, logical))
|
|
118
|
+
diagnostics.push(`Composition.composition.files.${logical}: Undefined file`);
|
|
119
|
+
const relation = record(raw);
|
|
120
|
+
const configuredCardinality = relation?.cardinality ?? raw;
|
|
121
|
+
if (relation)
|
|
122
|
+
unexpected(relation, ['cardinality', 'mapping'], `Composition.composition.files.${logical}`, diagnostics);
|
|
123
|
+
if (!cardinality(configuredCardinality))
|
|
124
|
+
diagnostics.push(`Composition.composition.files.${logical}: Unknown cardinality`);
|
|
125
|
+
if (relation && relation.mapping !== undefined && (!name(relation.mapping) || !Object.hasOwn(mappings, relation.mapping)))
|
|
126
|
+
diagnostics.push(`Composition.composition.files.${logical}.mapping: Unknown mapping ${String(relation.mapping)}`);
|
|
127
|
+
if (Object.hasOwn(files, logical) && cardinality(configuredCardinality)) {
|
|
128
|
+
const mapping = relation?.mapping;
|
|
129
|
+
roles[logical] = { cardinality: configuredCardinality, ...(typeof mapping === 'string' ? { mapping } : {}) };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (master && (roles[master]?.cardinality !== 'one' || roles[master]?.mapping !== undefined))
|
|
133
|
+
diagnostics.push('Composition.composition.master: Master must have cardinality one');
|
|
134
|
+
for (const logical of Object.keys(files)) {
|
|
135
|
+
if (!Object.hasOwn(roles, logical)) {
|
|
136
|
+
diagnostics.push(`Composition.composition.files.${logical}: Missing cardinality`);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const entity = files[logical].key;
|
|
140
|
+
if (master && logical !== master) {
|
|
141
|
+
const mappingName = roles[logical].mapping;
|
|
142
|
+
if (entity === files[master].key && mappingName !== undefined)
|
|
143
|
+
diagnostics.push(`Composition.composition.files.${logical}: Direct customer relationship must not specify a mapping`);
|
|
144
|
+
if (entity !== files[master].key && mappingName === undefined)
|
|
145
|
+
diagnostics.push(`Composition.composition.files.${logical}: Mapping is required for entity ${entity}`);
|
|
146
|
+
if (mappingName !== undefined && Object.hasOwn(mappings, mappingName)) {
|
|
147
|
+
const mapping = mappings[mappingName];
|
|
148
|
+
if (mapping.key !== entity)
|
|
149
|
+
diagnostics.push(`Composition.composition.files.${logical}.mapping: Mapping entity must be ${entity}`);
|
|
150
|
+
if (master && Object.values(mapping.foreign).filter(target => target === files[master].key).length !== 1)
|
|
151
|
+
diagnostics.push(`Composition.composition.files.${logical}.mapping: Requires exactly one foreign key to ${files[master].key}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return diagnostics.length ? { errors: diagnostics } : (0, errors_1.value)({ entities, files, mappings, composition: { master, files: roles } });
|
|
157
|
+
}
|
|
158
|
+
/** Cross-check duplicate physical metadata against the authoritative catalogue. */
|
|
159
|
+
function validateCompositionCatalogue(definition, catalogue) {
|
|
160
|
+
const diagnostics = [];
|
|
161
|
+
for (const [logical, entry] of [...Object.entries(definition.files), ...Object.entries(definition.mappings)]) {
|
|
162
|
+
const configured = catalogue.files[logical];
|
|
163
|
+
if (!configured) {
|
|
164
|
+
diagnostics.push(`Composition file ${logical}: Missing from files.yaml`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (entry.type !== undefined && configured.type !== entry.type)
|
|
168
|
+
diagnostics.push(`Composition file ${logical}: Type ${entry.type} does not match catalogue ${configured.type}`);
|
|
169
|
+
if ('copybook' in entry && entry.copybook !== undefined &&
|
|
170
|
+
(configured.type !== 'cobol' || configured.copybook !== entry.copybook))
|
|
171
|
+
diagnostics.push(`Composition file ${logical}: Copybook does not match files.yaml`);
|
|
172
|
+
}
|
|
173
|
+
return diagnostics.length ? { errors: diagnostics } : (0, errors_1.value)(definition);
|
|
174
|
+
}
|
|
175
|
+
async function hasCompositionDefinition(configDirectory) {
|
|
176
|
+
const source = await (0, promises_1.readFile)((0, node_path_1.join)(configDirectory, 'files.yaml'), 'utf8');
|
|
177
|
+
const parsed = yaml_jsyaml_1.jsYamlParser.parse(source);
|
|
178
|
+
if ((0, errors_1.isErrors)(parsed))
|
|
179
|
+
throw new Error(parsed.errors.join('\n'));
|
|
180
|
+
return record(parsed.value)?.composition !== undefined;
|
|
181
|
+
}
|
|
182
|
+
async function readCompositionDefinition(configDirectory, filename = 'files.yaml') {
|
|
183
|
+
try {
|
|
184
|
+
const yaml = await (0, promises_1.readFile)((0, node_path_1.join)(configDirectory, filename), 'utf8');
|
|
185
|
+
const parsed = yaml_jsyaml_1.jsYamlParser.parse(yaml);
|
|
186
|
+
if ((0, errors_1.isErrors)(parsed))
|
|
187
|
+
return parsed;
|
|
188
|
+
const composition = parseCompositionDefinition(parsed.value);
|
|
189
|
+
if ((0, errors_1.isErrors)(composition))
|
|
190
|
+
return composition;
|
|
191
|
+
const catalogue = (0, file_catalogue_1.parseFileCatalogue)(parsed.value);
|
|
192
|
+
return (0, errors_1.isErrors)(catalogue) ? catalogue : validateCompositionCatalogue(composition.value, catalogue.value);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
return (0, errors_1.errors)(`Reading ${filename}: ${error instanceof Error ? error.message : String(error)}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=composition.definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composition.definition.js","sourceRoot":"","sources":["../../src/composition.definition.ts"],"names":[],"mappings":";;AA4CA,gEAgGC;AAGD,oEAYC;AAED,4DAKC;AAED,8DAWC;AA/KD,+CAA0C;AAC1C,yCAA+B;AAC/B,uDAAmD;AACnD,6CAAqE;AAErE,6DAA+E;AA2B/E,MAAM,MAAM,GAAC,CAAC,KAAa,EAAkC,EAAE,CAC3D,OAAO,KAAK,KAAG,QAAQ,IAAE,KAAK,KAAG,IAAI,IAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA,CAAC,CAAA,KAA+B,CAAA,CAAC,CAAA,SAAS,CAAC;AAC3G,MAAM,IAAI,GAAC,CAAC,KAAa,EAAiB,EAAE,CAAA,OAAO,KAAK,KAAG,QAAQ,IAAE,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5G,MAAM,MAAM,GAAC,CAAC,KAAa,EAAiB,EAAE,CAAA,OAAO,KAAK,KAAG,QAAQ,IAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACpG,MAAM,WAAW,GAAC,CAAC,KAAa,EAAsB,EAAE,CACpD,KAAK,KAAG,KAAK,IAAE,KAAK,KAAG,UAAU,IAAE,KAAK,KAAG,MAAM,IAAE,KAAK,KAAG,cAAc,CAAC;AAC9E,MAAM,KAAK,GAAC,CAAC,OAAO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|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const composition_definition_1 = require("./composition.definition");
|
|
4
|
+
const declaration = {
|
|
5
|
+
entities: ['customer', 'account'],
|
|
6
|
+
files: { customers: { type: 'cobol', copybook: 'CUSTOMER.cpy', key: 'customer', keyPath: 'customerId' },
|
|
7
|
+
accounts: { type: 'jsonl', key: 'account', keyPath: 'id' } },
|
|
8
|
+
mappings: { accountCustomerMap: { type: 'csv', key: 'account', keyPath: 'id', foreign: { custid: 'customer' } } },
|
|
9
|
+
composition: { master: 'customers', files: { customers: 'one', accounts: { cardinality: 'manyOptional', mapping: 'accountCustomerMap' } } }
|
|
10
|
+
};
|
|
11
|
+
const expected = { ...declaration, composition: { master: 'customers', files: {
|
|
12
|
+
customers: { cardinality: 'one' }, accounts: { cardinality: 'manyOptional', mapping: 'accountCustomerMap' }
|
|
13
|
+
} } };
|
|
14
|
+
describe('explicit composition YAML contract', () => {
|
|
15
|
+
test('parses a named relationship and complete identity paths', () => {
|
|
16
|
+
expect((0, composition_definition_1.parseCompositionDefinition)(declaration)).toEqual({ value: expected });
|
|
17
|
+
});
|
|
18
|
+
test('requires a declared one-to-one master', () => {
|
|
19
|
+
expect((0, composition_definition_1.parseCompositionDefinition)({ ...declaration, composition: { master: 'customers', files: {
|
|
20
|
+
customers: 'many', accounts: { cardinality: 'manyOptional', mapping: 'accountCustomerMap' }
|
|
21
|
+
} } })).toEqual({ errors: ['Composition.composition.master: Master must have cardinality one'] });
|
|
22
|
+
});
|
|
23
|
+
test('requires explicit identity paths on physical and mapping files', () => {
|
|
24
|
+
expect((0, composition_definition_1.parseCompositionDefinition)({ ...declaration, files: { ...declaration.files,
|
|
25
|
+
accounts: { type: 'jsonl', key: 'account' } },
|
|
26
|
+
mappings: { accountCustomerMap: { type: 'csv', key: 'account', foreign: { custid: 'customer' } } } }))
|
|
27
|
+
.toEqual({ errors: ['Composition.files.accounts.keyPath: Expected a scalar field path',
|
|
28
|
+
'Composition.mappings.accountCustomerMap.keyPath: Expected a scalar field path'] });
|
|
29
|
+
});
|
|
30
|
+
test('rejects missing or unknown explicit mapping', () => {
|
|
31
|
+
expect((0, composition_definition_1.parseCompositionDefinition)({ ...declaration, composition: { master: 'customers', files: {
|
|
32
|
+
customers: 'one', accounts: 'manyOptional'
|
|
33
|
+
} } })).toEqual({ errors: ['Composition.composition.files.accounts: Mapping is required for entity account'] });
|
|
34
|
+
expect((0, composition_definition_1.parseCompositionDefinition)({ ...declaration, composition: { master: 'customers', files: {
|
|
35
|
+
customers: 'one', accounts: { cardinality: 'manyOptional', mapping: 'doesNotExist' }
|
|
36
|
+
} } })).toEqual({ errors: ['Composition.composition.files.accounts.mapping: Unknown mapping doesNotExist'] });
|
|
37
|
+
});
|
|
38
|
+
test('rejects a relationship mapping for a different entity', () => {
|
|
39
|
+
expect((0, composition_definition_1.parseCompositionDefinition)({ ...declaration, mappings: { accountCustomerMap: {
|
|
40
|
+
type: 'csv', key: 'customer', keyPath: 'id', foreign: { custid: 'customer' }
|
|
41
|
+
} } })).toEqual({ errors: ['Composition.composition.files.accounts.mapping: Mapping entity must be account'] });
|
|
42
|
+
});
|
|
43
|
+
test('rejects unknown targets, invalid paths and missing cardinalities', () => {
|
|
44
|
+
expect((0, composition_definition_1.parseCompositionDefinition)({ ...declaration, mappings: { accountCustomerMap: {
|
|
45
|
+
type: 'csv', key: 'account', keyPath: 'id', foreign: { custid: 'unknown' }
|
|
46
|
+
} } })).toEqual({ errors: [
|
|
47
|
+
'Composition.mappings.accountCustomerMap.foreign.custid: Unknown entity unknown',
|
|
48
|
+
'Composition.composition.files.accounts.mapping: Requires exactly one foreign key to customer'
|
|
49
|
+
] });
|
|
50
|
+
expect((0, composition_definition_1.parseCompositionDefinition)({ ...declaration, files: { ...declaration.files,
|
|
51
|
+
accounts: { type: 'jsonl', key: 'account', keyPath: 'a..b' } } })).toEqual({ errors: [
|
|
52
|
+
'Composition.files.accounts.keyPath: Expected a scalar field path'
|
|
53
|
+
] });
|
|
54
|
+
expect((0, composition_definition_1.parseCompositionDefinition)({ ...declaration, composition: { master: 'customers', files: {
|
|
55
|
+
customers: 'one'
|
|
56
|
+
} } })).toEqual({ errors: ['Composition.composition.files.accounts: Missing cardinality'] });
|
|
57
|
+
});
|
|
58
|
+
test('rejects catalogue type and copybook disagreement', () => {
|
|
59
|
+
const parsed = (0, composition_definition_1.parseCompositionDefinition)(declaration);
|
|
60
|
+
if ('errors' in parsed)
|
|
61
|
+
throw new Error(parsed.errors.join('\n'));
|
|
62
|
+
expect((0, composition_definition_1.validateCompositionCatalogue)(parsed.value, { root: '../sources', files: {
|
|
63
|
+
customers: { type: 'cobol', copybook: 'OTHER.cpy' },
|
|
64
|
+
accounts: { type: 'jsonl' }, accountCustomerMap: { type: 'csv' }
|
|
65
|
+
} })).toEqual({ errors: ['Composition file customers: Copybook does not match files.yaml'] });
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=composition.definition.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composition.definition.spec.js","sourceRoot":"","sources":["../../src/composition.definition.spec.ts"],"names":[],"mappings":";;AAAA,qEAAiG;AAEjG,MAAM,WAAW,GAAC;IACd,QAAQ,EAAC,CAAC,UAAU,EAAC,SAAS,CAAC;IAC/B,KAAK,EAAC,EAAC,SAAS,EAAC,EAAC,IAAI,EAAC,OAAO,EAAC,QAAQ,EAAC,cAAc,EAAC,GAAG,EAAC,UAAU,EAAC,OAAO,EAAC,YAAY,EAAC;QACvF,QAAQ,EAAC,EAAC,IAAI,EAAC,OAAO,EAAC,GAAG,EAAC,SAAS,EAAC,OAAO,EAAC,IAAI,EAAC,EAAC;IACvD,QAAQ,EAAC,EAAC,kBAAkB,EAAC,EAAC,IAAI,EAAC,KAAK,EAAC,GAAG,EAAC,SAAS,EAAC,OAAO,EAAC,IAAI,EAAC,OAAO,EAAC,EAAC,MAAM,EAAC,UAA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0B,EAAC,WAAW,CAAC,CAAC;QACrD,IAAG,QAAQ,IAAI,MAAM;YAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAChE,MAAM,CAAC,IAAA,qDAA4B,EAAC,MAAM,CAAC,KAAK,EAAC,EAAC,IAAI,EAAC,YAAY,EAAC,KAAK,EAAC;gBACtE,SAAS,EAAC,EAAC,IAAI,EAAC,OAAO,EAAC,QAAQ,EAAC,WAAW,EAAC;gBAC7C,QAAQ,EAAC,EAAC,IAAI,EAAC,OAAO,EAAC,EAAC,kBAAkB,EAAC,EAAC,IAAI,EAAC,KAAK,EAAC;aAC1D,EAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,MAAM,EAAC,CAAC,gEAAgE,CAAC,EAAC,CAAC,CAAC;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { compositeAccessCompiler, type PreparedSource, type PreparedComposition } from '@cobol-ts/cursor-composition';
|
|
2
|
+
import { type ConfiguredFileSource } from '@cobol-ts/cursor-loader-source';
|
|
3
|
+
import type { ProjectionAuthoring } from '@cobol-ts/cursor-loader-types';
|
|
4
|
+
import type { CompositionDefinition } from './composition.definition';
|
|
5
|
+
export interface CompositionFileFactory {
|
|
6
|
+
/** Source opening is supplied by the catalogue resolver; no physical format-specific join code. */
|
|
7
|
+
(logicalName: string): Promise<ConfiguredFileSource>;
|
|
8
|
+
}
|
|
9
|
+
export interface PreparedConfiguredComposition<T> {
|
|
10
|
+
readonly sources: readonly PreparedSource[];
|
|
11
|
+
readonly composed: PreparedComposition<T>;
|
|
12
|
+
readonly access: ReturnType<typeof compositeAccessCompiler>;
|
|
13
|
+
}
|
|
14
|
+
/** An identity must identify exactly one scalar in its declared projection. */
|
|
15
|
+
export declare function resolveEntityKeyPath(projection: ProjectionAuthoring, entity: string, explicit?: string): readonly string[];
|
|
16
|
+
/** Preparation performs all scalar-name and relationship resolution before opening cursors. */
|
|
17
|
+
export declare function prepareCompositionDefinition<T>(definition: CompositionDefinition, openFile: CompositionFileFactory): Promise<PreparedConfiguredComposition<T>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
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 cursor_loader_source_1 = require("@cobol-ts/cursor-loader-source");
|
|
7
|
+
const cel_implementation_1 = require("@cobol-ts/cel-implementation");
|
|
8
|
+
const errors_1 = require("@cobol-ts/errors");
|
|
9
|
+
const composition_definition_1 = require("./composition.definition");
|
|
10
|
+
const composition_prepare_1 = require("./composition.prepare");
|
|
11
|
+
const declaration = {
|
|
12
|
+
entities: ['customer', 'account'],
|
|
13
|
+
files: { customers: { key: 'customer', keyPath: 'customerId', type: 'jsonl' }, accounts: { key: 'account', keyPath: 'id', type: 'jsonl' } },
|
|
14
|
+
mappings: { accountCustomerMap: { type: 'csv', key: 'account', keyPath: 'id', foreign: { custid: 'customer' } } },
|
|
15
|
+
composition: { master: 'customers', files: { customers: 'one', accounts: { cardinality: 'manyOptional', mapping: 'accountCustomerMap' } } }
|
|
16
|
+
};
|
|
17
|
+
async function fixture() {
|
|
18
|
+
const root = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobolts-yaml-composition-'));
|
|
19
|
+
const config = (0, node_path_1.join)(root, '.cobolts');
|
|
20
|
+
await (0, promises_1.mkdir)(config);
|
|
21
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(config, 'files.yaml'), `root: ../data\nentities:\n - customer\n - account\nfiles:\n customers:\n type: jsonl\n key: customer\n keyPath: customerId\n projection:\n customerId: {type: integer}\n name: {type: string}\n accounts:\n type: jsonl\n key: account\n keyPath: id\n projection:\n id: {type: integer}\n balance: {type: integer}\nmappings:\n accountCustomerMap:\n type: csv\n key: account\n keyPath: id\n projection:\n id: {type: integer}\n custid: {type: integer}\n foreign:\n custid: customer\ncomposition:\n master: customers\n files:\n customers: one\n accounts:\n cardinality: manyOptional\n mapping: accountCustomerMap\n`);
|
|
22
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(config, 'data.yaml'), `root: ../data\nfiles:\n customers: customers.jsonl\n accounts: accounts.jsonl\n accountCustomerMap: mapping.csv\n`);
|
|
23
|
+
await (0, promises_1.mkdir)((0, node_path_1.join)(root, 'data'));
|
|
24
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(root, 'data', 'customers.jsonl'), '{"customerId":1,"name":"Aria"}\n{"customerId":2,"name":"Bram"}\n{"customerId":3,"name":"Cora"}\n');
|
|
25
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(root, 'data', 'accounts.jsonl'), '{"id":10,"balance":12}\n{"id":11,"balance":25}\n{"id":12,"balance":8}\n');
|
|
26
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(root, 'data', 'mapping.csv'), 'id,custid\n10,1\n11,1\n12,3\n');
|
|
27
|
+
return { root, config };
|
|
28
|
+
}
|
|
29
|
+
async function prepared(config) {
|
|
30
|
+
const declarationResult = await (0, composition_definition_1.readCompositionDefinition)(config);
|
|
31
|
+
if ('errors' in declarationResult)
|
|
32
|
+
throw new Error(declarationResult.errors.join('\n'));
|
|
33
|
+
return (0, composition_prepare_1.prepareCompositionDefinition)(declarationResult.value, async (logicalName) => (0, cursor_loader_source_1.prepareConfiguredFileSource)({ configDirectory: config, logicalName }));
|
|
34
|
+
}
|
|
35
|
+
describe('YAML-driven physical merge and CEL integration', () => {
|
|
36
|
+
test('joins real JSONL and CSV mapping with one-to-many cardinality and compiled CEL', async () => {
|
|
37
|
+
const { root, config } = await fixture();
|
|
38
|
+
try {
|
|
39
|
+
const { composed, access } = await prepared(config);
|
|
40
|
+
const compiled = (0, errors_1.valueOrThrow)((0, cel_implementation_1.compileCelExpression)('input.accounts.map(a, a.balance).sum()', composed.projection, access));
|
|
41
|
+
const run = compiled.createRunner();
|
|
42
|
+
const results = [];
|
|
43
|
+
await composed.scan(row => {
|
|
44
|
+
results.push({ key: row.key, count: row.count(1), sum: run(row, []) });
|
|
45
|
+
});
|
|
46
|
+
expect(results).toEqual([{ key: 1n, count: 2, sum: 37n }, { key: 2n, count: 0, sum: 0n }, { key: 3n, count: 1, sum: 8n }]);
|
|
47
|
+
expect(await (0, promises_1.readFile)((0, node_path_1.join)(root, 'data', 'mapping.csv'), 'utf8'))
|
|
48
|
+
.toEqual('id,custid\n10,1\n11,1\n12,3\n');
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
await (0, promises_1.rm)(root, { recursive: true, force: true });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
test('rejects duplicate mapping keys rather than multiplying an entity', async () => {
|
|
55
|
+
const { root, config } = await fixture();
|
|
56
|
+
try {
|
|
57
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(root, 'data', 'mapping.csv'), 'id,custid\n10,1\n11,1\n11,3\n');
|
|
58
|
+
const { composed } = await prepared(config);
|
|
59
|
+
const run = () => composed.scan(() => { });
|
|
60
|
+
await expect(run()).rejects.toThrow('Mapping accountCustomerMap must be strictly sorted by source ID');
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
await (0, promises_1.rm)(root, { recursive: true, force: true });
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
test('rejects unsorted master records', async () => {
|
|
67
|
+
const { root, config } = await fixture();
|
|
68
|
+
try {
|
|
69
|
+
await (0, promises_1.writeFile)((0, node_path_1.join)(root, 'data', 'customers.jsonl'), '{"customerId":1,"name":"Aria"}\n{"customerId":3,"name":"Cora"}\n{"customerId":2,"name":"Bram"}\n');
|
|
70
|
+
const { composed } = await prepared(config);
|
|
71
|
+
const run = () => composed.scan(() => { });
|
|
72
|
+
await expect(run()).rejects.toThrow('Source customers is not sorted by its effective entity key');
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
await (0, promises_1.rm)(root, { recursive: true, force: true });
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
test('rejects implicit identity discovery', () => {
|
|
79
|
+
expect(() => (0, composition_prepare_1.resolveEntityKeyPath)({ id: { type: 'integer' } }, 'account', undefined))
|
|
80
|
+
.toThrow('Entity account: Explicit keyPath is required');
|
|
81
|
+
});
|
|
82
|
+
test('rejects an undefined relationship mapping during YAML validation', () => {
|
|
83
|
+
expect((0, composition_definition_1.parseCompositionDefinition)({ ...declaration, mappings: {} }))
|
|
84
|
+
.toEqual({ errors: ['Composition.composition.files.accounts.mapping: Unknown mapping accountCustomerMap'] });
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('explicit entity identity paths', () => {
|
|
88
|
+
test('uses a declared path even when several identity-like fields exist', () => {
|
|
89
|
+
const projection = { id: { type: 'integer' }, metadata: { type: 'object', fields: { id: { type: 'integer' } } } };
|
|
90
|
+
expect((0, composition_prepare_1.resolveEntityKeyPath)(projection, 'account', 'metadata.id')).toEqual(['metadata', 'id']);
|
|
91
|
+
});
|
|
92
|
+
test('rejects unknown or non-scalar paths during preparation', () => {
|
|
93
|
+
expect(() => (0, composition_prepare_1.resolveEntityKeyPath)({ customerId: { type: 'integer' } }, 'customer', 'other.id'))
|
|
94
|
+
.toThrow('Entity customer: Unknown identity path other.id');
|
|
95
|
+
expect(() => (0, composition_prepare_1.resolveEntityKeyPath)({ name: { type: 'string' } }, 'customer', 'name.bad'))
|
|
96
|
+
.toThrow('Entity customer: Identity path name.bad traverses a non-object');
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=composition.prepare.integration.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composition.prepare.integration.spec.js","sourceRoot":"","sources":["../../src/composition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EAAC,UAAU,CAAC,CAAC;aAChF,OAAO,CAAC,iDAAiD,CAAC,CAAC;QAChE,MAAM,CAAC,GAAE,EAAE,CAAA,IAAA,0CAAoB,EAAC,EAAC,IAAI,EAAC,EAAC,IAAI,EAAC,QAAQ,EAAC,EAAC,EAAC,UAAU,EAAC,UAAU,CAAC,CAAC;aACzE,OAAO,CAAC,gEAAgE,CAAC,CAAC;IACnF,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveEntityKeyPath = resolveEntityKeyPath;
|
|
4
|
+
exports.prepareCompositionDefinition = prepareCompositionDefinition;
|
|
5
|
+
const errors_1 = require("@cobol-ts/errors");
|
|
6
|
+
const cursor_composition_1 = require("@cobol-ts/cursor-composition");
|
|
7
|
+
const cursor_loader_source_1 = require("@cobol-ts/cursor-loader-source");
|
|
8
|
+
/** An identity must identify exactly one scalar in its declared projection. */
|
|
9
|
+
function resolveEntityKeyPath(projection, entity, explicit) {
|
|
10
|
+
if (explicit !== undefined) {
|
|
11
|
+
const path = explicit.split('.');
|
|
12
|
+
let current = projection;
|
|
13
|
+
for (let i = 0; i < path.length; i++) {
|
|
14
|
+
const node = current[path[i]];
|
|
15
|
+
if (node === undefined)
|
|
16
|
+
throw new Error(`Entity ${entity}: Unknown identity path ${explicit}`);
|
|
17
|
+
if (i === path.length - 1) {
|
|
18
|
+
if (node.type !== 'integer' && node.type !== 'string')
|
|
19
|
+
throw new Error(`Entity ${entity}: Identity path ${explicit} must be a scalar`);
|
|
20
|
+
return path;
|
|
21
|
+
}
|
|
22
|
+
if (node.type !== 'object' || !node.fields)
|
|
23
|
+
throw new Error(`Entity ${entity}: Identity path ${explicit} traverses a non-object`);
|
|
24
|
+
current = node.fields;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Entity ${entity}: Explicit keyPath is required`);
|
|
28
|
+
}
|
|
29
|
+
function key(value, label) {
|
|
30
|
+
if (typeof value === 'bigint' || typeof value === 'string')
|
|
31
|
+
return value;
|
|
32
|
+
if (typeof value === 'number' && Number.isSafeInteger(value))
|
|
33
|
+
return BigInt(value);
|
|
34
|
+
throw new Error(`${label}: Expected a string or integer entity key`);
|
|
35
|
+
}
|
|
36
|
+
function compileKey(source, path, label) {
|
|
37
|
+
const compiled = (0, errors_1.valueOrThrow)(source.access.compileScalar(path));
|
|
38
|
+
const indices = [];
|
|
39
|
+
return lease => key(compiled.read(lease.representation, indices), label);
|
|
40
|
+
}
|
|
41
|
+
/** Preparation performs all scalar-name and relationship resolution before opening cursors. */
|
|
42
|
+
async function prepareCompositionDefinition(definition, openFile) {
|
|
43
|
+
const master = definition.files[definition.composition.master];
|
|
44
|
+
if (master === undefined)
|
|
45
|
+
throw new Error('Composition master has no definition');
|
|
46
|
+
const sources = [];
|
|
47
|
+
for (const [logical, member] of Object.entries(definition.composition.files)) {
|
|
48
|
+
const cardinality = member.cardinality;
|
|
49
|
+
const file = definition.files[logical];
|
|
50
|
+
if (!file)
|
|
51
|
+
throw new Error(`Unknown composed file ${logical}`);
|
|
52
|
+
const prepared = await openFile(logical);
|
|
53
|
+
if (file.type !== undefined && prepared.type !== file.type)
|
|
54
|
+
throw new Error(`File ${logical}: YAML type ${file.type} disagrees with catalogue ${prepared.type}`);
|
|
55
|
+
let source = (0, cursor_loader_source_1.withPreparedFileSource)(prepared, typed => (0, cursor_loader_source_1.asCompositionSource)(typed, {
|
|
56
|
+
name: logical, cardinality, keyPath: resolveEntityKeyPath(typed.projection, file.key, file.keyPath)
|
|
57
|
+
}));
|
|
58
|
+
if (file.key !== master.key) {
|
|
59
|
+
const mappingName = member.mapping;
|
|
60
|
+
if (mappingName === undefined)
|
|
61
|
+
throw new Error(`File ${logical}: Explicit mapping is required`);
|
|
62
|
+
const mapDefinition = definition.mappings[mappingName];
|
|
63
|
+
const mappingFile = await openFile(mappingName);
|
|
64
|
+
if (mappingFile.type !== mapDefinition.type)
|
|
65
|
+
throw new Error(`Mapping ${mappingName}: YAML type disagrees with catalogue`);
|
|
66
|
+
const mapping = (0, cursor_loader_source_1.withPreparedFileSource)(mappingFile, typed => (0, cursor_loader_source_1.asCompositionSource)(typed, {
|
|
67
|
+
name: mappingName, cardinality: 'one', keyPath: resolveEntityKeyPath(typed.projection, mapDefinition.key, mapDefinition.keyPath)
|
|
68
|
+
}));
|
|
69
|
+
const foreignFields = Object.entries(mapDefinition.foreign).filter(([, entity]) => entity === master.key);
|
|
70
|
+
if (foreignFields.length !== 1)
|
|
71
|
+
throw new Error(`Mapping ${mappingName}: Expected one foreign field targeting ${master.key}`);
|
|
72
|
+
const foreign = compileKey(mapping, foreignFields[0][0].split('.'), `Mapping ${mappingName} foreign key`);
|
|
73
|
+
const identity = {
|
|
74
|
+
name: mappingName,
|
|
75
|
+
key: lease => mapping.key(lease),
|
|
76
|
+
foreign,
|
|
77
|
+
openCursor: () => mapping.openCursor()
|
|
78
|
+
};
|
|
79
|
+
source = (0, cursor_composition_1.viaMapping)(source, identity);
|
|
80
|
+
}
|
|
81
|
+
sources.push(source);
|
|
82
|
+
}
|
|
83
|
+
const composed = (0, cursor_composition_1.createComposition)(sources, definition.composition.master);
|
|
84
|
+
return { sources, composed, access: (0, cursor_composition_1.compositeAccessCompiler)(sources) };
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=composition.prepare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composition.prepare.js","sourceRoot":"","sources":["../../src/composition.prepare.ts"],"names":[],"mappings":";;AAmBA,oDAkBC;AAgBD,oEAwCC;AA7FD,6CAAuD;AACvD,qEAC0H;AAC1H,yEAAoH;AAepH,+EAA+E;AAC/E,SAAgB,oBAAoB,CAAC,UAA8B,EAAC,MAAa,EAAC,QAAgB;IAC9F,IAAG,QAAQ,KAAG,SAAS,EAAC,CAAC;QACrB,MAAM,IAAI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nG,IAAG,aAAa,CAAC,MAAM,KAAG,CAAC;gBAAC,MAAM,IAAI,KAAK,CAAC,WAAW,WAAW,0CAA0C,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;YAC1H,MAAM,OAAO,GAAC,UAAU,CAAC,OAAO,EAAC,aAAa,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAC,WAAW,WAAW,cAAc,CAAC,CAAC;YACvG,MAAM,QAAQ,GAAiB;gBAC3B,IAAI,EAAC,WAAW;gBAChB,GAAG,EAAC,KAAK,CAAA,EAAE,CAAA,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;gBAC7B,OAAO;gBACP,UAAU,EAAC,GAAE,EAAE,CAAA,OAAO,CAAC,UAAU,EAAE;aACtC,CAAC;YACF,MAAM,GAAC,IAAA,+BAAU,EAAC,MAAM,EAAC,QAAQ,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IACD,MAAM,QAAQ,GAAC,IAAA,sCAAiB,EAAI,OAAO,EAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3E,OAAO,EAAC,OAAO,EAAC,QAAQ,EAAC,MAAM,EAAC,IAAA,4CAAuB,EAAC,OAAO,CAAC,EAAC,CAAC;AACtE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobol-ts/composition-definition",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "Validated YAML definitions and preparation of multi-file entity compositions",
|
|
4
|
+
"version": "0.0.16",
|
|
5
|
+
"main": "dist/index",
|
|
6
|
+
"types": "dist/index",
|
|
7
|
+
"browserslist": {
|
|
8
|
+
"development": [
|
|
9
|
+
"last 1 chrome version",
|
|
10
|
+
"last 1 firefox version",
|
|
11
|
+
"last 1 safari version"
|
|
12
|
+
],
|
|
13
|
+
"production": [
|
|
14
|
+
">0.2%",
|
|
15
|
+
"not dead",
|
|
16
|
+
"not op_mini all"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@cobol-ts/errors": "0.0.16",
|
|
21
|
+
"@cobol-ts/yaml": "0.0.16",
|
|
22
|
+
"@cobol-ts/yaml-jsyaml": "0.0.16",
|
|
23
|
+
"@cobol-ts/cursor-composition": "0.0.16",
|
|
24
|
+
"@cobol-ts/cursor-loader-source": "0.0.16",
|
|
25
|
+
"@cobol-ts/cel-access": "0.0.16",
|
|
26
|
+
"@cobol-ts/cursor-loader-types": "0.0.16",
|
|
27
|
+
"@cobol-ts/cel-implementation": "0.0.16",
|
|
28
|
+
"@cobol-ts/file-catalogue": "0.0.16"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"typescript": "^5.2.2",
|
|
32
|
+
"@testing-library/jest-dom": "^6.1.4",
|
|
33
|
+
"@types/jest": "^29.0.0",
|
|
34
|
+
"@types/node": "^14.0.0",
|
|
35
|
+
"jest": "^29.0.0",
|
|
36
|
+
"ts-jest": "^29.0.0"
|
|
37
|
+
},
|
|
38
|
+
"eslintConfig": {
|
|
39
|
+
"extends": [
|
|
40
|
+
"react-app",
|
|
41
|
+
"react-app/jest"
|
|
42
|
+
],
|
|
43
|
+
"overrides": [
|
|
44
|
+
{
|
|
45
|
+
"files": [
|
|
46
|
+
"**/*.stories.*"
|
|
47
|
+
],
|
|
48
|
+
"rules": {
|
|
49
|
+
"import/no-anonymous-default-export": "off"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist/index.js",
|
|
56
|
+
"dist/index.d.ts",
|
|
57
|
+
"dist/src/",
|
|
58
|
+
"dist/**/*"
|
|
59
|
+
],
|
|
60
|
+
"keywords": [
|
|
61
|
+
"indexing"
|
|
62
|
+
],
|
|
63
|
+
"license": "MIT",
|
|
64
|
+
"repository": "git@github.com:intellimaintain/intellimaintain.git",
|
|
65
|
+
"scripts": {
|
|
66
|
+
"test": "jest --config jest.config.json --env node",
|
|
67
|
+
"test:watch": "npm run test -- --watch"
|
|
68
|
+
}
|
|
6
69
|
}
|