@cobol-ts/layout 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/index.js.map +1 -0
  2. package/dist/src/cobol.alignment.d.ts +30 -0
  3. package/dist/src/cobol.alignment.js +91 -0
  4. package/dist/src/cobol.alignment.js.map +1 -0
  5. package/dist/src/cobol.alignment.spec.d.ts +1 -0
  6. package/dist/src/cobol.alignment.spec.js +248 -0
  7. package/dist/src/cobol.alignment.spec.js.map +1 -0
  8. package/dist/src/cobol.layout.aws.emprec.spec.d.ts +1 -0
  9. package/dist/src/cobol.layout.aws.emprec.spec.js +102 -0
  10. package/dist/src/cobol.layout.aws.emprec.spec.js.map +1 -0
  11. package/dist/src/cobol.layout.carddemo.coordinates.spec.d.ts +1 -0
  12. package/dist/src/cobol.layout.carddemo.coordinates.spec.js +200 -0
  13. package/dist/src/cobol.layout.carddemo.coordinates.spec.js.map +1 -0
  14. package/dist/src/cobol.layout.carddemo.spec.d.ts +1 -0
  15. package/dist/src/cobol.layout.carddemo.spec.js +43 -0
  16. package/dist/src/cobol.layout.carddemo.spec.js.map +1 -0
  17. package/dist/src/cobol.layout.composable.spec.d.ts +1 -0
  18. package/dist/src/cobol.layout.composable.spec.js +174 -0
  19. package/dist/src/cobol.layout.composable.spec.js.map +1 -0
  20. package/dist/src/cobol.layout.d.ts +119 -0
  21. package/dist/src/cobol.layout.ibm-options.spec.d.ts +1 -0
  22. package/dist/src/cobol.layout.ibm-options.spec.js +40 -0
  23. package/dist/src/cobol.layout.ibm-options.spec.js.map +1 -0
  24. package/dist/src/cobol.layout.ibm.redefines.spec.d.ts +1 -0
  25. package/dist/src/cobol.layout.ibm.redefines.spec.js +41 -0
  26. package/dist/src/cobol.layout.ibm.redefines.spec.js.map +1 -0
  27. package/dist/src/cobol.layout.integration.campaign.spec.d.ts +1 -0
  28. package/dist/src/cobol.layout.integration.campaign.spec.js +366 -0
  29. package/dist/src/cobol.layout.integration.campaign.spec.js.map +1 -0
  30. package/dist/src/cobol.layout.js +522 -0
  31. package/dist/src/cobol.layout.js.map +1 -0
  32. package/dist/src/cobol.layout.location.d.ts +21 -0
  33. package/dist/src/cobol.layout.location.js +108 -0
  34. package/dist/src/cobol.layout.location.js.map +1 -0
  35. package/dist/src/cobol.layout.location.spec.d.ts +1 -0
  36. package/dist/src/cobol.layout.location.spec.js +69 -0
  37. package/dist/src/cobol.layout.location.spec.js.map +1 -0
  38. package/dist/src/cobol.layout.odo.nested.spec.d.ts +1 -0
  39. package/dist/src/cobol.layout.odo.nested.spec.js +175 -0
  40. package/dist/src/cobol.layout.odo.nested.spec.js.map +1 -0
  41. package/dist/src/cobol.layout.odo.spec.d.ts +1 -0
  42. package/dist/src/cobol.layout.odo.spec.js +137 -0
  43. package/dist/src/cobol.layout.odo.spec.js.map +1 -0
  44. package/dist/src/cobol.layout.published.spec.d.ts +1 -0
  45. package/dist/src/cobol.layout.published.spec.js +156 -0
  46. package/dist/src/cobol.layout.published.spec.js.map +1 -0
  47. package/dist/src/cobol.layout.reference-geometry.spec.d.ts +1 -0
  48. package/dist/src/cobol.layout.reference-geometry.spec.js +160 -0
  49. package/dist/src/cobol.layout.reference-geometry.spec.js.map +1 -0
  50. package/dist/src/cobol.layout.right.symbolic.spec.d.ts +1 -0
  51. package/dist/src/cobol.layout.right.symbolic.spec.js +85 -0
  52. package/dist/src/cobol.layout.right.symbolic.spec.js.map +1 -0
  53. package/dist/src/cobol.layout.spec.d.ts +1 -0
  54. package/dist/src/cobol.layout.spec.js +1541 -0
  55. package/dist/src/cobol.layout.spec.js.map +1 -0
  56. package/dist/src/cobol.overlay.alignment.d.ts +38 -0
  57. package/dist/src/cobol.overlay.alignment.js +24 -0
  58. package/dist/src/cobol.overlay.alignment.js.map +1 -0
  59. package/dist/src/cobol.padding.d.ts +79 -0
  60. package/dist/src/cobol.padding.js +136 -0
  61. package/dist/src/cobol.padding.js.map +1 -0
  62. package/dist/src/cobol.padding.spec.d.ts +1 -0
  63. package/dist/src/cobol.padding.spec.js +415 -0
  64. package/dist/src/cobol.padding.spec.js.map +1 -0
  65. package/dist/src/cobol.picture.d.ts +36 -0
  66. package/dist/src/cobol.picture.js +174 -0
  67. package/dist/src/cobol.picture.js.map +1 -0
  68. package/dist/src/cobol.picture.spec.d.ts +1 -0
  69. package/dist/src/cobol.picture.spec.js +67 -0
  70. package/dist/src/cobol.picture.spec.js.map +1 -0
  71. package/dist/src/cobol.primitive.size.d.ts +26 -0
  72. package/dist/src/cobol.primitive.size.js +169 -0
  73. package/dist/src/cobol.primitive.size.js.map +1 -0
  74. package/dist/src/cobol.primitive.size.spec.d.ts +1 -0
  75. package/dist/src/cobol.primitive.size.spec.js +292 -0
  76. package/dist/src/cobol.primitive.size.spec.js.map +1 -0
  77. package/dist/src/symbolic.layout.composition.spec.d.ts +1 -0
  78. package/dist/src/symbolic.layout.composition.spec.js +151 -0
  79. package/dist/src/symbolic.layout.composition.spec.js.map +1 -0
  80. package/package.json +8 -7
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Public AWS CardDemo copybooks: externally sourced byte-coordinate oracles
5
+ * and internal geometry-consistency properties.
6
+ *
7
+ * The GOLDEN coordinates below were transcribed from the FIELD DECLARATIONS
8
+ * in the named upstream files, independently of compileCobolLayout and
9
+ * locateCobolEntry. They are zero-based byte offsets and exclusive lengths.
10
+ *
11
+ * The additional geometry-consistency tests apply to all eight pinned source
12
+ * files, including those for which we do not yet have independently reviewed
13
+ * coordinates. They are deliberately NOT described as external oracles.
14
+ *
15
+ * Run alongside, not instead of, cobol.layout.carddemo.spec.ts.
16
+ */
17
+ const node_fs_1 = require("node:fs");
18
+ const node_path_1 = require("node:path");
19
+ const copybook_1 = require("@cobol-ts/copybook");
20
+ const errors_1 = require("@cobol-ts/errors");
21
+ const size_1 = require("@cobol-ts/size");
22
+ const cobol_layout_1 = require("./cobol.layout");
23
+ const cobol_layout_location_1 = require("./cobol.layout.location");
24
+ const noOdo = (path) => {
25
+ throw new Error(`A fixed CardDemo fixture unexpectedly requires an ODO count at ${path.join('.')}`);
26
+ };
27
+ const bits = (expression) => (0, size_1.evaluateStorageSize)(expression, noOdo);
28
+ const load = (filename) => {
29
+ const source = (0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', 'fixtures', 'carddemo', filename), 'utf8');
30
+ return (0, errors_1.valueOrThrow)((0, cobol_layout_1.compileCobolLayout)((0, errors_1.valueOrThrow)((0, copybook_1.parseCopybook)(source)), filename));
31
+ };
32
+ const oracle = (record, rows) => rows.map(([field, at, bytes]) => ({ path: [record, field], at, bytes }));
33
+ /**
34
+ * Verified against original field declarations at:
35
+ * https://github.com/aws-samples/aws-mainframe-modernization-carddemo/tree/main/app/cpy
36
+ *
37
+ * Explicit literals matter: expected positions MUST NOT be computed by the
38
+ * layout compiler or locator, nor read out of its generated geometry.
39
+ */
40
+ const golden = [
41
+ {
42
+ filename: 'CSUSR01Y.cpy', record: 'SEC-USER-DATA', bytes: 80,
43
+ fields: oracle('SEC-USER-DATA', [
44
+ ['SEC-USR-ID', 0, 8],
45
+ ['SEC-USR-FNAME', 8, 20],
46
+ ['SEC-USR-LNAME', 28, 20],
47
+ ['SEC-USR-PWD', 48, 8],
48
+ ['SEC-USR-TYPE', 56, 1],
49
+ ['SEC-USR-FILLER', 57, 23],
50
+ ])
51
+ },
52
+ {
53
+ filename: 'CVACT03Y.cpy', record: 'CARD-XREF-RECORD', bytes: 50,
54
+ fields: oracle('CARD-XREF-RECORD', [
55
+ ['XREF-CARD-NUM', 0, 16],
56
+ ['XREF-CUST-ID', 16, 9],
57
+ ['XREF-ACCT-ID', 25, 11],
58
+ ])
59
+ // The last 14 bytes are an unnamed FILLER: checked via the
60
+ // structural tail assertion below, not a name-based locator.
61
+ },
62
+ {
63
+ filename: 'CVTRA05Y.cpy', record: 'TRAN-RECORD', bytes: 350,
64
+ fields: oracle('TRAN-RECORD', [
65
+ ['TRAN-ID', 0, 16],
66
+ ['TRAN-TYPE-CD', 16, 2],
67
+ ['TRAN-CAT-CD', 18, 4],
68
+ ['TRAN-SOURCE', 22, 10],
69
+ ['TRAN-DESC', 32, 100],
70
+ ['TRAN-AMT', 132, 11],
71
+ ['TRAN-MERCHANT-ID', 143, 9],
72
+ ['TRAN-MERCHANT-NAME', 152, 50],
73
+ ['TRAN-MERCHANT-CITY', 202, 50],
74
+ ['TRAN-MERCHANT-ZIP', 252, 10],
75
+ ['TRAN-CARD-NUM', 262, 16],
76
+ ['TRAN-ORIG-TS', 278, 26],
77
+ ['TRAN-PROC-TS', 304, 26],
78
+ ])
79
+ // Trailing FILLER occupies [330,350), verified separately.
80
+ }
81
+ ];
82
+ const all = [
83
+ ['CSUSR01Y.cpy', 80],
84
+ ['CVACT01Y.cpy', 300],
85
+ ['CVACT02Y.cpy', 150],
86
+ ['CVCUS01Y.cpy', 500],
87
+ ['CVACT03Y.cpy', 50],
88
+ ['CVTRA06Y.cpy', 350],
89
+ ['CVTRA05Y.cpy', 350],
90
+ ['CVTRA02Y.cpy', 50],
91
+ ];
92
+ const group = (node) => {
93
+ if (node.kind !== 'group')
94
+ throw new Error('Expected compiled COBOL group');
95
+ return node;
96
+ };
97
+ const fixedCount = (node) => {
98
+ const clause = node.source.clauses.find(c => c.kind === 'occurs');
99
+ if (clause?.kind !== 'occurs')
100
+ return 1;
101
+ if ('count' in clause)
102
+ return clause.count;
103
+ throw new Error('This fixed-record geometry invariant needs a separate ODO count oracle');
104
+ };
105
+ /** One group occurrence owns its children; a repeated group owns many bodies. */
106
+ const oneBodySize = (node) => {
107
+ const count = fixedCount(node);
108
+ if (count <= 0)
109
+ throw new Error('Unexpected non-positive fixed OCCURS count');
110
+ const total = bits(node.size);
111
+ if (total % count !== 0)
112
+ throw new Error('Fixed table extent is not divisible by occurrence count');
113
+ return total / count;
114
+ };
115
+ /**
116
+ * These checks compare the independently implemented left and right folds,
117
+ * and check that every allocated byte belongs to at least one child,
118
+ * including generated padding. They are useful consistency properties,
119
+ * NOT external proof that the compiler selected the correct field sizes.
120
+ */
121
+ const verifyTree = (node, path) => {
122
+ const body = oneBodySize(node);
123
+ const occupied = [];
124
+ for (const [index, child] of node.children.entries()) {
125
+ const left = bits(child.leftOffset);
126
+ const width = bits(child.size);
127
+ const right = bits(child.rightOffset);
128
+ expect({ path, index, left, width, right }).toEqual({
129
+ path, index, left, width, right: body - left - width
130
+ });
131
+ expect(left).toBeGreaterThanOrEqual(0);
132
+ expect(width).toBeGreaterThanOrEqual(0);
133
+ expect(right).toBeGreaterThanOrEqual(0);
134
+ expect(left + width).toBeLessThanOrEqual(body);
135
+ if (width)
136
+ occupied.push([left, left + width]);
137
+ if (child.kind === 'group') {
138
+ const name = child.source.name.kind === 'named' ? child.source.name.name : `#${index}`;
139
+ verifyTree(child, `${path}.${name}`);
140
+ }
141
+ }
142
+ // All storage must be accounted for. Overlays may overlap; padding
143
+ // must occupy any alignment gaps. Sort independent of source order.
144
+ occupied.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
145
+ let end = 0;
146
+ for (const [start, after] of occupied) {
147
+ expect(start).toBeLessThanOrEqual(end);
148
+ end = Math.max(end, after);
149
+ }
150
+ expect(end).toBe(body);
151
+ return body;
152
+ };
153
+ describe('CardDemo: independent published-field byte coordinates', () => {
154
+ for (const { filename, record, bytes, fields } of golden) {
155
+ describe(filename, () => {
156
+ test(`the root is ${bytes} bytes`, () => {
157
+ const roots = load(filename);
158
+ expect(roots).toHaveLength(1);
159
+ expect(bits(roots[0].size)).toBe(bytes * 8);
160
+ });
161
+ test.each(fields)('$path starts at byte $at and occupies $bytes bytes', ({ path, at, bytes: width }) => {
162
+ const found = (0, errors_1.valueOrThrow)((0, cobol_layout_location_1.locateCobolEntry)(load(filename), path, noOdo));
163
+ expect(found.offsetBits).toBe(at * 8);
164
+ expect(found.sizeBits).toBe(width * 8);
165
+ // Independently folded suffix must agree with record end
166
+ // for each *direct* child of the record.
167
+ expect(bits(found.node.rightOffset)).toBe((bytes - at - width) * 8);
168
+ });
169
+ test('the root children cover the full expected extent', () => {
170
+ const top = group(load(filename)[0]);
171
+ expect(top.source.name.kind === 'named' && top.source.name.name).toBe(record);
172
+ expect(verifyTree(top, filename)).toBe(bytes * 8);
173
+ });
174
+ });
175
+ }
176
+ test('the unnamed trailing FILLER of CVACT03Y occupies bytes 36..49', () => {
177
+ const root = group(load('CVACT03Y.cpy')[0]);
178
+ const tail = root.children[root.children.length - 1];
179
+ expect(tail.kind).toBe('elementary');
180
+ expect(bits(tail.leftOffset)).toBe(36 * 8);
181
+ expect(bits(tail.size)).toBe(14 * 8);
182
+ expect(bits(tail.rightOffset)).toBe(0);
183
+ });
184
+ test('the unnamed trailing FILLER of CVTRA05Y occupies bytes 330..349', () => {
185
+ const root = group(load('CVTRA05Y.cpy')[0]);
186
+ const tail = root.children[root.children.length - 1];
187
+ expect(tail.kind).toBe('elementary');
188
+ expect(bits(tail.leftOffset)).toBe(330 * 8);
189
+ expect(bits(tail.size)).toBe(20 * 8);
190
+ expect(bits(tail.rightOffset)).toBe(0);
191
+ });
192
+ });
193
+ describe('CardDemo: geometry consistency across every original record', () => {
194
+ test.each(all)('%s has coherent left/right and full child coverage in %i bytes', (filename, expected) => {
195
+ const roots = load(filename);
196
+ expect(roots).toHaveLength(1);
197
+ expect(verifyTree(group(roots[0]), filename)).toBe(expected * 8);
198
+ });
199
+ });
200
+ //# sourceMappingURL=cobol.layout.carddemo.coordinates.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cobol.layout.carddemo.coordinates.spec.js","sourceRoot":"","sources":["../../src/cobol.layout.carddemo.coordinates.spec.ts"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;GAaG;AACH,qCAAqC;AACrC,yCAA+B;AAC/B,iDAAiD;AACjD,6CAA8C;AAC9C,yCAA+E;AAC/E,iDAAoG;AACpG,mEAAyD;AAWzD,MAAM,KAAK,GAAG,CA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,CAAC,CAAC,CAAC;QACrC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,6DAA6D,EAAE,GAAG,EAAE;IACzE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,gEAAgE,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE;QACpG,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Real, unmodified AWS CardDemo copybooks, fetched by
5
+ * scripts/fetch-carddemo-copybooks.mjs. Expected lengths are stated in
6
+ * the application's README under "Upload Sample Data".
7
+ *
8
+ * These are real-world acceptance tests: a legal copybook our compiler
9
+ * cannot lay out should FAIL, not be skipped, massaged, or adapted.
10
+ *
11
+ * They intentionally do not run a COBOL byte decoder.
12
+ */
13
+ const node_fs_1 = require("node:fs");
14
+ const node_path_1 = require("node:path");
15
+ const copybook_1 = require("@cobol-ts/copybook");
16
+ const errors_1 = require("@cobol-ts/errors");
17
+ const size_1 = require("@cobol-ts/size");
18
+ const cobol_layout_1 = require("./cobol.layout");
19
+ const documented = [
20
+ ['CSUSR01Y.cpy', 80],
21
+ ['CVACT01Y.cpy', 300],
22
+ ['CVACT02Y.cpy', 150],
23
+ ['CVCUS01Y.cpy', 500],
24
+ ['CVACT03Y.cpy', 50],
25
+ ['CVTRA06Y.cpy', 350],
26
+ ['CVTRA05Y.cpy', 350],
27
+ ['CVTRA02Y.cpy', 50],
28
+ ];
29
+ const noController = (path) => {
30
+ throw new Error(`Runtime controller required by ${path.join('.')}; add count-specific oracles`);
31
+ };
32
+ describe('Unmodified AWS CardDemo copybooks versus documented FB LRECL', () => {
33
+ test.each(documented)('%s has a physical extent of %i bytes', (filename, expectedBytes) => {
34
+ // Missing fixture is a setup failure, not a skip or a pretend pass.
35
+ const source = (0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', 'fixtures', 'carddemo', filename), 'utf8');
36
+ const ast = (0, errors_1.valueOrThrow)((0, copybook_1.parseCopybook)(source));
37
+ const roots = (0, errors_1.valueOrThrow)((0, cobol_layout_1.compileCobolLayout)(ast, filename));
38
+ expect(roots).toHaveLength(1);
39
+ const bits = (0, size_1.evaluateStorageSize)(roots[0].size, noController);
40
+ expect(bits).toBe(expectedBytes * 8);
41
+ });
42
+ });
43
+ //# sourceMappingURL=cobol.layout.carddemo.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cobol.layout.carddemo.spec.js","sourceRoot":"","sources":["../../src/cobol.layout.carddemo.spec.ts"],"names":[],"mappings":";;AAAA;;;;;;;;;GASG;AACH,qCAAqC;AACrC,yCAA+B;AAC/B,iDAAiD;AACjD,6CAA8C;AAC9C,yCAAmD;AACnD,iDAAkD;AAElD,MAAM,UAAU,GAAG;IACf,CAAC,cAAc,EAAE,EAAE,CAAC;IACpB,CAAC,cAAc,EAAE,GAAG,CAAC;IACrB,CAAC,cAAc,EAAE,GAAG,CAAC;IACrB,CAAC,cAAc,EAAE,GAAG,CAAC;IACrB,CAAC,cAAc,EAAE,EAAE,CAAC;IACpB,CAAC,cAAc,EAAE,GAAG,CAAC;IACrB,CAAC,cAAc,EAAE,GAAG,CAAC;IACrB,CAAC,cAAc,EAAE,EAAE,CAAC;CACd,CAAC;AAEX,MAAM,YAAY,GAAG,CAAC,IAAkC,EAAS,EAAE;IAC/D,MAAM,IAAI,KAAK,CAAC,kCAAkC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AACpG,CAAC,CAAC;AAEF,QAAQ,CAAC,8DAA8D,EAAE,GAAG,EAAE;IAC1E,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,sCAAsC,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE;QACtF,oEAAoE;QACpE,MAAM,MAAM,GAAG,IAAA,sBAAY,EAAC,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;QAC7F,MAAM,GAAG,GAAG,IAAA,qBAAY,EAAC,IAAA,wBAAa,EAAC,MAAM,CAAC,CAAC,CAAC;QAChD,MAAM,KAAK,GAAG,IAAA,qBAAY,EAAC,IAAA,iCAAkB,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC9D,MAAM,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,IAAI,GAAG,IAAA,0BAAmB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC9D,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const size_1 = require("@cobol-ts/size");
4
+ const errors_1 = require("@cobol-ts/errors");
5
+ const partial_functions_1 = require("@cobol-ts/partial_functions");
6
+ const cobol_layout_1 = require("./cobol.layout");
7
+ const named = (name) => ({ kind: "named", name });
8
+ const field = (name, clauses = []) => ({
9
+ kind: "elementary", level: 5, name: named(name), picture: "X", clauses, conditions: [], line: 3
10
+ });
11
+ const group = (name, children = []) => ({
12
+ kind: "group", level: 1, name: named(name), children, clauses: [], line: 2
13
+ });
14
+ const pendingField = (source, count = 1) => ({
15
+ kind: "elementary", source, count, size: 8
16
+ });
17
+ const pendingGroup = (source, count = 1) => ({
18
+ kind: "group", source, count, children: []
19
+ });
20
+ const frameFor = (source = group("REC"), position = 24) => ({
21
+ group: pendingGroup(source), absoluteOrigin: 0, position,
22
+ children: [], alignedAtStart: false
23
+ });
24
+ const add = (...terms) => (0, size_1.canonicaliseStorageSize)({ kind: "sum", terms });
25
+ const identitySize = (_source, size) => (0, errors_1.value)((0, size_1.canonicaliseStorageSize)(size));
26
+ describe("composable layout strategies", () => {
27
+ test("elementary declaration strategy uses its independently injected sizer and counter", () => {
28
+ const source = field("ITEM");
29
+ const first = (0, cobol_layout_1.elementaryStrategy)(() => (0, errors_1.value)(8), () => (0, errors_1.value)(1));
30
+ const second = (0, cobol_layout_1.elementaryStrategy)(() => (0, errors_1.value)(16), () => (0, errors_1.value)(3));
31
+ const input = { source, children: [] };
32
+ expect(first.isDefinedAt(input)).toBe(true);
33
+ expect((0, errors_1.valueOrThrow)(first.apply(input))).toEqual([pendingField(source, 1)]);
34
+ expect((0, errors_1.valueOrThrow)(second.apply(input))).toEqual([
35
+ { kind: "elementary", source, count: 3, size: 16 }
36
+ ]);
37
+ });
38
+ test("group strategy builds padding requirements as DATA, without sizes or offsets", () => {
39
+ const base = field("BASE");
40
+ const alternate = field("ALT", [{ kind: "redefines", target: "BASE" }]);
41
+ const tail = field("TAIL");
42
+ const source = group("REC", [base, alternate, tail]);
43
+ const built = (0, errors_1.valueOrThrow)((0, cobol_layout_1.groupStrategy)(() => (0, errors_1.value)(2)).apply({
44
+ source,
45
+ children: [pendingField(base), pendingField(alternate), pendingField(tail)]
46
+ }));
47
+ expect(built.length).toBe(1);
48
+ const node = built[0];
49
+ if (node.kind !== "group")
50
+ throw new Error("Expected group");
51
+ expect(node.size).toBe(undefined);
52
+ expect(node.leftOffset).toBe(undefined);
53
+ expect(node.children.map(child => child.kind === "padding"
54
+ ? `${child.role}:${child.source.name.kind === "named" ? child.source.name.name : "FILLER"}`
55
+ : child.source.name.kind === "named" ? child.source.name.name : "FILLER")).toEqual(["before:BASE", "BASE", "ALT", "before:TAIL", "TAIL", "after-occurrence:REC"]);
56
+ expect(node.children.filter(child => child.kind === "padding").every(child => child.size === undefined)).toBe(true);
57
+ });
58
+ test("declaration chain composes strategies without internal compiler closures", () => {
59
+ const build = (0, partial_functions_1.chainOfResponsibility)(() => { throw new Error("No declaration strategy"); }, (0, cobol_layout_1.elementaryStrategy)(() => (0, errors_1.value)(8), () => (0, errors_1.value)(1)), (0, cobol_layout_1.groupStrategy)(() => (0, errors_1.value)(1)), cobol_layout_1.ignoredStrategy);
60
+ const source = field("A");
61
+ expect((0, errors_1.valueOrThrow)(build({ source, children: [] }))).toEqual([pendingField(source)]);
62
+ });
63
+ test("single-occurrence strategy does not add padding", () => {
64
+ const source = field("A");
65
+ const strategy = (0, cobol_layout_1.singleOccurrenceStrategy)(identitySize);
66
+ const input = { node: pendingField(source), body: 8 };
67
+ expect(strategy.isDefinedAt(input)).toBe(true);
68
+ expect((0, errors_1.valueOrThrow)(strategy.apply(input))).toBe(8);
69
+ });
70
+ test("fixed-occurs strategy uses injected trailing padding for elementary fields", () => {
71
+ const source = field("A");
72
+ const calls = [];
73
+ const strategy = (0, cobol_layout_1.fixedOccursStrategy)((entry, body) => {
74
+ calls.push(entry.name.kind === "named" ? entry.name.name : "FILLER");
75
+ return (0, errors_1.value)(8);
76
+ }, add, identitySize);
77
+ const input = { node: pendingField(source, 3), body: 8 };
78
+ expect(strategy.isDefinedAt(input)).toBe(true);
79
+ expect((0, errors_1.valueOrThrow)(strategy.apply(input))).toBe(48);
80
+ expect(calls).toEqual(["A"]);
81
+ });
82
+ test("fixed-occurs group already owns its trailing padding requirement", () => {
83
+ const source = group("REC");
84
+ const strategy = (0, cobol_layout_1.fixedOccursStrategy)(() => {
85
+ throw new Error("Group must not invoke elementary trailing padding");
86
+ }, add, identitySize);
87
+ expect((0, errors_1.valueOrThrow)(strategy.apply({ node: pendingGroup(source, 3), body: 24 }))).toBe(72);
88
+ });
89
+ test("dependent occurrence strategy composes with injected sizing operations", () => {
90
+ const source = field("ITEMS");
91
+ const count = { kind: "dependent", min: 0, max: 3,
92
+ path: ["RECORD", "ITEM-COUNT"] };
93
+ const pending = { kind: "elementary", source, count, size: 16 };
94
+ const strategy = (0, cobol_layout_1.dependentOccursStrategy)(() => (0, errors_1.value)(0), add, identitySize);
95
+ const input = { node: pending, body: 16 };
96
+ expect(strategy.isDefinedAt(input)).toBe(true);
97
+ expect((0, errors_1.valueOrThrow)(strategy.apply(input))).toEqual({
98
+ kind: "depending-on", path: ["RECORD", "ITEM-COUNT"], expression: 16, min: 0, max: 3
99
+ });
100
+ });
101
+ test("fixed and dependent repetition strategies are disjoint", () => {
102
+ const source = field("ITEMS");
103
+ const dependent = { kind: "elementary", source, size: 8,
104
+ count: { kind: "dependent", min: 0, max: 3, path: ["REC", "COUNT"] } };
105
+ const fixed = pendingField(source, 3);
106
+ const dependency = () => (0, errors_1.value)(0);
107
+ expect((0, cobol_layout_1.dependentOccursStrategy)(dependency, add, identitySize)
108
+ .isDefinedAt({ node: fixed, body: 8 })).toBe(false);
109
+ expect((0, cobol_layout_1.fixedOccursStrategy)(dependency, add, identitySize)
110
+ .isDefinedAt({ node: dependent, body: 8 })).toBe(false);
111
+ });
112
+ test("sequential placement uses supplied run finalizer, not hidden state", () => {
113
+ const source = field("BASE");
114
+ const frame = frameFor();
115
+ let closed = 0;
116
+ const strategy = (0, cobol_layout_1.sequentialStrategy)(current => {
117
+ closed++;
118
+ current.position = 40;
119
+ });
120
+ expect(strategy.isDefinedAt({ node: pendingField(source), frame })).toBe(true);
121
+ expect((0, errors_1.valueOrThrow)(strategy.apply({ node: pendingField(source), frame }))).toBe(40);
122
+ expect(closed).toBe(1);
123
+ expect(frame.children.length).toBe(1);
124
+ expect(frame.run?.sources.has("BASE")).toBe(true);
125
+ });
126
+ test("overlay placement composes with sequential placement and shares its start", () => {
127
+ const base = field("BASE");
128
+ const alt = field("ALT", [{ kind: "redefines", target: "BASE" }]);
129
+ const frame = frameFor();
130
+ const sequential = (0, cobol_layout_1.sequentialStrategy)(() => { });
131
+ (0, errors_1.valueOrThrow)(sequential.apply({ node: pendingField(base), frame }));
132
+ const overlay = (0, cobol_layout_1.overlayStrategy)({
133
+ before: () => (0, errors_1.value)(0), add,
134
+ alignment: () => { throw new Error("Zero padding must not consult the overlay policy"); },
135
+ diagnostic: (_, __, message) => (0, errors_1.errors)(message),
136
+ contextOf: () => ({ path: [], inheritedSynchronized: false })
137
+ });
138
+ const input = { node: pendingField(alt), frame };
139
+ expect(overlay.isDefinedAt(input)).toBe(true);
140
+ expect((0, errors_1.valueOrThrow)(overlay.apply(input))).toBe(24);
141
+ expect(frame.children.length).toBe(2);
142
+ expect(frame.run?.members.length).toBe(2);
143
+ expect(frame.run?.sources.has("ALT")).toBe(true);
144
+ });
145
+ test("overlay alignment policy is injected, including rejection", () => {
146
+ const base = field("BASE");
147
+ const alt = field("ALT", [{ kind: "redefines", target: "BASE" }]);
148
+ const frame = frameFor();
149
+ (0, errors_1.valueOrThrow)((0, cobol_layout_1.sequentialStrategy)(() => { }).apply({ node: pendingField(base), frame }));
150
+ let calls = 0;
151
+ const strategy = (0, cobol_layout_1.overlayStrategy)({
152
+ before: () => (0, errors_1.value)(8), add,
153
+ alignment: () => { calls++; return (0, errors_1.value)("reject"); },
154
+ diagnostic: (_, __, message) => (0, errors_1.errors)(message),
155
+ contextOf: () => ({ path: [], inheritedSynchronized: false })
156
+ });
157
+ const result = strategy.apply({ node: pendingField(alt), frame });
158
+ expect((0, errors_1.errorsOrThrow)(result)).toEqual(["SYNCHRONIZED overlay requires alignment not provided by its target"]);
159
+ expect(calls).toBe(1);
160
+ expect(frame.run?.members.length).toBe(1);
161
+ });
162
+ test("unmatched strategy uses the chain's throwing default", () => {
163
+ const chain = (0, partial_functions_1.chainOfResponsibility)(() => { throw new Error("Missing repetition strategy"); }, (0, cobol_layout_1.singleOccurrenceStrategy)(identitySize), (0, cobol_layout_1.fixedOccursStrategy)(() => (0, errors_1.value)(0), add, identitySize));
164
+ let message = "";
165
+ try {
166
+ chain({ node: pendingField(field("A"), 0), body: 8 });
167
+ }
168
+ catch (failure) {
169
+ message = failure.message;
170
+ }
171
+ expect(message).toBe("Missing repetition strategy");
172
+ });
173
+ });
174
+ //# sourceMappingURL=cobol.layout.composable.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cobol.layout.composable.spec.js","sourceRoot":"","sources":["../../src/cobol.layout.composable.spec.ts"],"names":[],"mappings":";;AACA,yCAAmF;AACnF,6CAA2F;AAC3F,mEAAkE;AAClE,iDAcwB;AAExB,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,EAAC,IAAI,EAAE,OAAgB,EAAE,IAAI,EAAC,CAAC,CAAC;AACjE,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,UAA4B,EAAE,EAAmB,EAAE,CAAC,CAAC;IAC9E,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;CAClG,CAAC,CAAC;AACH,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,WAA6C,EAAE,EAAc,EAAE,CAAC,CAAC;IAC1F,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;CAC7E,CAAC,CAAC;AACH,MAAM,YAAY,GAAG,C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AA,uCAAwB,EAAC,YAAY,CAAC,EACtC,IAAA,kCAAmB,EAAC,GAAG,EAAE,CAAC,IAAA,cAAK,EAAC,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,CACzD,CAAC;QACF,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC;YACD,KAAK,CAAC,EAAC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAC,CAAC,CAAC;QACxD,CAAC;QAAC,OAAO,OAAO,EAAE,CAAC;YACf,OAAO,GAAI,OAAiB,CAAC,OAAO,CAAC;QACzC,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,119 @@
1
+ import type { CopybookAst, CopybookEntry, GroupEntry, ElementaryEntry } from "@cobol-ts/copybook";
2
+ import { type StorageSizeExpression, type DependsOnPath } from "@cobol-ts/size";
3
+ import { type ErrorsOr } from "@cobol-ts/errors";
4
+ import { type PartialFunction } from "@cobol-ts/partial_functions";
5
+ import { type CobolPrimitiveSizer, type IbmCobolPrimitiveSizingOptions } from "./cobol.primitive.size";
6
+ import { type CobolPaddingPolicy } from "./cobol.padding";
7
+ import { type CobolOverlayAlignmentPolicy } from "./cobol.overlay.alignment";
8
+ type Geometry = Readonly<{
9
+ size: StorageSizeExpression;
10
+ leftOffset: StorageSizeExpression;
11
+ rightOffset: StorageSizeExpression;
12
+ }>;
13
+ export type CompiledCobolElementary = Geometry & Readonly<{
14
+ kind: "elementary";
15
+ source: ElementaryEntry;
16
+ }>;
17
+ export type CompiledCobolGroup = Geometry & Readonly<{
18
+ kind: "group";
19
+ source: GroupEntry;
20
+ children: readonly CompiledCobolEntry[];
21
+ }>;
22
+ export type CompiledCobolPadding = Geometry & Readonly<{
23
+ kind: "padding";
24
+ }>;
25
+ export type CompiledCobolEntry = CompiledCobolElementary | CompiledCobolGroup | CompiledCobolPadding;
26
+ export type CobolLayoutOptions = Readonly<{
27
+ primitiveSizer?: CobolPrimitiveSizer;
28
+ primitiveSizing?: IbmCobolPrimitiveSizingOptions;
29
+ padding?: CobolPaddingPolicy;
30
+ overlayAlignment?: CobolOverlayAlignmentPolicy;
31
+ canonicalise?: (size: StorageSizeExpression) => StorageSizeExpression;
32
+ }>;
33
+ type Source = GroupEntry | ElementaryEntry;
34
+ type Context = Readonly<{
35
+ path: readonly string[];
36
+ inheritedUsage?: string;
37
+ inheritedSynchronized: boolean;
38
+ }>;
39
+ export type OccurrenceCount = number | Readonly<{
40
+ kind: "fixed";
41
+ count: number;
42
+ }> | Readonly<{
43
+ kind: "dependent";
44
+ min: number;
45
+ max: number;
46
+ path: DependsOnPath;
47
+ }>;
48
+ type PendingGeometry = {
49
+ size?: StorageSizeExpression;
50
+ leftOffset?: StorageSizeExpression;
51
+ rightOffset?: StorageSizeExpression;
52
+ };
53
+ export type PendingElementary = PendingGeometry & {
54
+ kind: "elementary";
55
+ source: ElementaryEntry;
56
+ count: OccurrenceCount;
57
+ };
58
+ export type PendingGroup = PendingGeometry & {
59
+ kind: "group";
60
+ source: GroupEntry;
61
+ count: OccurrenceCount;
62
+ children: PendingEntry[];
63
+ };
64
+ export type PendingPadding = PendingGeometry & {
65
+ kind: "padding";
66
+ role: "before" | "after-occurrence";
67
+ source: Source;
68
+ };
69
+ export type PendingEntry = PendingElementary | PendingGroup | PendingPadding;
70
+ export type Build = Readonly<{
71
+ source: CopybookEntry;
72
+ children: readonly PendingEntry[];
73
+ }>;
74
+ export type Repetition = Readonly<{
75
+ node: PendingElementary | PendingGroup;
76
+ body: StorageSizeExpression;
77
+ }>;
78
+ type Combine = (...terms: StorageSizeExpression[]) => StorageSizeExpression;
79
+ type Diagnostic = (source: Source, context: Context, message: string) => ErrorsOr<never>;
80
+ type ContextOf = (source: Source) => Context;
81
+ type CheckedSize = (source: Source, size: StorageSizeExpression, message?: string) => ErrorsOr<StorageSizeExpression>;
82
+ type CountOf = (source: Source) => ErrorsOr<OccurrenceCount>;
83
+ type PrimitiveSize = (source: ElementaryEntry) => ErrorsOr<StorageSizeExpression>;
84
+ type Before = (source: Source, offset: StorageSizeExpression) => ErrorsOr<StorageSizeExpression>;
85
+ type AfterOccurrence = (source: Source, size: StorageSizeExpression) => ErrorsOr<StorageSizeExpression>;
86
+ export declare const singleOccurrenceStrategy: (checkedSize: CheckedSize) => PartialFunction<Repetition, ErrorsOr<StorageSizeExpression>>;
87
+ export declare const fixedOccursStrategy: (afterOccurrence: AfterOccurrence, add: Combine, checkedSize: CheckedSize) => PartialFunction<Repetition, ErrorsOr<StorageSizeExpression>>;
88
+ /** ODO is an additional repetition strategy, not a special tree traversal. */
89
+ export declare const dependentOccursStrategy: (afterOccurrence: AfterOccurrence, add: Combine, checkedSize: CheckedSize) => PartialFunction<Repetition, ErrorsOr<StorageSizeExpression>>;
90
+ export declare const elementaryStrategy: (primitiveSize: PrimitiveSize, countOf: CountOf) => PartialFunction<Build, ErrorsOr<readonly PendingEntry[]>>;
91
+ export declare const groupStrategy: (countOf: CountOf) => PartialFunction<Build, ErrorsOr<readonly PendingEntry[]>>;
92
+ export declare const ignoredStrategy: PartialFunction<Build, ErrorsOr<readonly PendingEntry[]>>;
93
+ type Run = {
94
+ members: PendingEntry[];
95
+ sources: Map<string, Source>;
96
+ };
97
+ export type Frame = {
98
+ group: PendingGroup;
99
+ absoluteOrigin: StorageSizeExpression;
100
+ position: StorageSizeExpression;
101
+ children: PendingEntry[];
102
+ alignedAtStart: boolean;
103
+ run?: Run;
104
+ };
105
+ export type Place = Readonly<{
106
+ node: PendingEntry;
107
+ frame: Frame;
108
+ }>;
109
+ type CloseRun = (frame: Frame) => void;
110
+ export declare const sequentialStrategy: (closeRun: CloseRun) => PartialFunction<Place, ErrorsOr<StorageSizeExpression>>;
111
+ export declare const overlayStrategy: (services: {
112
+ before: Before;
113
+ add: Combine;
114
+ alignment: CobolOverlayAlignmentPolicy;
115
+ diagnostic: Diagnostic;
116
+ contextOf: ContextOf;
117
+ }) => PartialFunction<Place, ErrorsOr<StorageSizeExpression>>;
118
+ export declare function compileCobolLayout(ast: CopybookAst, copybook: string, options?: CobolLayoutOptions): ErrorsOr<readonly CompiledCobolEntry[]>;
119
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /** Full parser -> layout -> byte-offset integration for IBM compiler options. */
4
+ const copybook_1 = require("@cobol-ts/copybook");
5
+ const errors_1 = require("@cobol-ts/errors");
6
+ const cobol_layout_1 = require("./cobol.layout");
7
+ const cobol_layout_location_1 = require("./cobol.layout.location");
8
+ const compile = (source, primitiveSizing = {}) => (0, errors_1.valueOrThrow)((0, cobol_layout_1.compileCobolLayout)((0, errors_1.valueOrThrow)((0, copybook_1.parseCopybook)(source)), "IBM-OPTIONS.cpy", { primitiveSizing }));
9
+ const noCount = () => { throw new Error("No ODO in IBM options fixture"); };
10
+ describe("IBM file-layout compiler options: end-to-end", () => {
11
+ test("CURRENCY SIGN and UTF-8 BYTE-LENGTH shift following physical fields", () => {
12
+ const roots = compile(`
13
+ 01 RECORD.
14
+ 05 AMOUNT PIC f9(3).99.
15
+ 05 TEXT PIC U BYTE-LENGTH 11.
16
+ 05 TRAILER PIC X(2).
17
+ `, { currencySigns: [{ symbol: "f", value: "CHF" }] });
18
+ const amount = (0, errors_1.valueOrThrow)((0, cobol_layout_location_1.locateCobolEntry)(roots, ["RECORD", "AMOUNT"], noCount));
19
+ const utf8 = (0, errors_1.valueOrThrow)((0, cobol_layout_location_1.locateCobolEntry)(roots, ["RECORD", "TEXT"], noCount));
20
+ const trailer = (0, errors_1.valueOrThrow)((0, cobol_layout_location_1.locateCobolEntry)(roots, ["RECORD", "TRAILER"], noCount));
21
+ expect({ start: amount.offsetBits, size: amount.sizeBits }).toEqual({ start: 0, size: 72 });
22
+ expect({ start: utf8.offsetBits, size: utf8.sizeBits }).toEqual({ start: 72, size: 88 });
23
+ expect({ start: trailer.offsetBits, size: trailer.sizeBits }).toEqual({ start: 160, size: 16 });
24
+ });
25
+ test("DYNAMIC LENGTH parsed but not misrepresented as fixed file storage", () => {
26
+ const source = `01 RECORD.\n 05 TEXT PIC U DYNAMIC LENGTH LIMIT 20.\n`;
27
+ const ast = (0, errors_1.valueOrThrow)((0, copybook_1.parseCopybook)(source));
28
+ const field = ast.entries[0];
29
+ expect(field.kind).toBe("group");
30
+ if (field.kind !== "group")
31
+ return;
32
+ const child = field.children[0];
33
+ if (child.kind !== "elementary")
34
+ throw new Error("Expected elementary child");
35
+ expect(child.clauses).toContainEqual({ kind: "dynamic-length", limit: 20 });
36
+ const result = (0, cobol_layout_1.compileCobolLayout)(ast, "IBM-OPTIONS.cpy");
37
+ expect((0, errors_1.errorsOrThrow)(result).join(" ")).toContain("no inline file-record size");
38
+ });
39
+ });
40
+ //# sourceMappingURL=cobol.layout.ibm-options.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cobol.layout.ibm-options.spec.js","sourceRoot":"","sources":["../../src/cobol.layout.ibm-options.spec.ts"],"names":[],"mappings":";;AAAA,iFAAiF;AACjF,iDAAiD;AACjD,6CAA6D;AAC7D,iDAAkD;AAClD,mEAAyD;AAEzD,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,eAAe,GAAG,EAAE,EAAE,EAAE,CAAC,IAAA,qBAAY,EAClE,IAAA,iCAAkB,EAAC,IAAA,qBAAY,EAAC,IAAA,wBAAa,EAAC,MAAM,CAAC,CAAC,EAAE,iBAAiB,EAAE,EAAC,eAAe,EAAC,CAAC,CAChG,CAAC;AACF,MAAM,OAAO,GAAG,GAAU,EAAE,GAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA,CAAA,CAAC,CAAC;AAEhF,QAAQ,CAAC,8CAA8C,EAAE,GAAG,EAAE;IAC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