@cobol-ts/cursor-loader-cobol 0.0.4 → 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.
Files changed (111) hide show
  1. package/dist/index.d.ts +6 -0
  2. package/dist/index.js +23 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/src/cobol.array.selection.d.ts +56 -0
  5. package/dist/src/cobol.array.selection.js +172 -0
  6. package/dist/src/cobol.array.selection.js.map +1 -0
  7. package/dist/src/cobol.array.selection.spec.d.ts +1 -0
  8. package/dist/src/cobol.array.selection.spec.js +64 -0
  9. package/dist/src/cobol.array.selection.spec.js.map +1 -0
  10. package/dist/src/cobol.callback.spec.d.ts +1 -0
  11. package/dist/src/cobol.callback.spec.js +69 -0
  12. package/dist/src/cobol.callback.spec.js.map +1 -0
  13. package/dist/src/cobol.debug.range.d.ts +21 -0
  14. package/dist/src/cobol.debug.range.js +53 -0
  15. package/dist/src/cobol.debug.range.js.map +1 -0
  16. package/dist/src/cobol.debug.range.spec.d.ts +1 -0
  17. package/dist/src/cobol.debug.range.spec.js +29 -0
  18. package/dist/src/cobol.debug.range.spec.js.map +1 -0
  19. package/dist/src/cobol.decoded.file.spec.d.ts +1 -0
  20. package/dist/src/cobol.decoded.file.spec.js +41 -0
  21. package/dist/src/cobol.decoded.file.spec.js.map +1 -0
  22. package/dist/src/cobol.decoded.integration.spec.d.ts +1 -0
  23. package/dist/src/cobol.decoded.integration.spec.js +124 -0
  24. package/dist/src/cobol.decoded.integration.spec.js.map +1 -0
  25. package/dist/src/cobol.file.node.d.ts +37 -0
  26. package/dist/src/cobol.file.node.js +65 -0
  27. package/dist/src/cobol.file.node.js.map +1 -0
  28. package/dist/src/cobol.fixed.array.projection.spec.d.ts +1 -0
  29. package/dist/src/cobol.fixed.array.projection.spec.js +128 -0
  30. package/dist/src/cobol.fixed.array.projection.spec.js.map +1 -0
  31. package/dist/src/cobol.layout.index.d.ts +18 -0
  32. package/dist/src/cobol.layout.index.js +33 -0
  33. package/dist/src/cobol.layout.index.js.map +1 -0
  34. package/dist/src/cobol.layout.index.spec.d.ts +1 -0
  35. package/dist/src/cobol.layout.index.spec.js +195 -0
  36. package/dist/src/cobol.layout.index.spec.js.map +1 -0
  37. package/dist/src/cobol.metrics.odo.spec.d.ts +1 -0
  38. package/dist/src/cobol.metrics.odo.spec.js +52 -0
  39. package/dist/src/cobol.metrics.odo.spec.js.map +1 -0
  40. package/dist/src/cobol.metrics.scalar.spec.d.ts +1 -0
  41. package/dist/src/cobol.metrics.scalar.spec.js +28 -0
  42. package/dist/src/cobol.metrics.scalar.spec.js.map +1 -0
  43. package/dist/src/cobol.multiple.nested.arrays.spec.d.ts +1 -0
  44. package/dist/src/cobol.multiple.nested.arrays.spec.js +253 -0
  45. package/dist/src/cobol.multiple.nested.arrays.spec.js.map +1 -0
  46. package/dist/src/cobol.multiple.nested.odo.spec.d.ts +1 -0
  47. package/dist/src/cobol.multiple.nested.odo.spec.js +129 -0
  48. package/dist/src/cobol.multiple.nested.odo.spec.js.map +1 -0
  49. package/dist/src/cobol.nested.redefines.projection.spec.d.ts +1 -0
  50. package/dist/src/cobol.nested.redefines.projection.spec.js +195 -0
  51. package/dist/src/cobol.nested.redefines.projection.spec.js.map +1 -0
  52. package/dist/src/cobol.occurrence.context.spec.d.ts +1 -0
  53. package/dist/src/cobol.occurrence.context.spec.js +187 -0
  54. package/dist/src/cobol.occurrence.context.spec.js.map +1 -0
  55. package/dist/src/cobol.occurs.clause.d.ts +10 -0
  56. package/dist/src/cobol.occurs.clause.js +14 -0
  57. package/dist/src/cobol.occurs.clause.js.map +1 -0
  58. package/dist/src/cobol.occurs.clause.spec.d.ts +1 -0
  59. package/dist/src/cobol.occurs.clause.spec.js +21 -0
  60. package/dist/src/cobol.occurs.clause.spec.js.map +1 -0
  61. package/dist/src/cobol.odo.positions.d.ts +17 -0
  62. package/dist/src/cobol.odo.positions.js +70 -0
  63. package/dist/src/cobol.odo.positions.js.map +1 -0
  64. package/dist/src/cobol.odo.positions.spec.d.ts +1 -0
  65. package/dist/src/cobol.odo.positions.spec.js +108 -0
  66. package/dist/src/cobol.odo.positions.spec.js.map +1 -0
  67. package/dist/src/cobol.odo.projection.spec.d.ts +1 -0
  68. package/dist/src/cobol.odo.projection.spec.js +246 -0
  69. package/dist/src/cobol.odo.projection.spec.js.map +1 -0
  70. package/dist/src/cobol.odo.three.level.spec.d.ts +1 -0
  71. package/dist/src/cobol.odo.three.level.spec.js +202 -0
  72. package/dist/src/cobol.odo.three.level.spec.js.map +1 -0
  73. package/dist/src/cobol.parser.d.ts +112 -0
  74. package/dist/src/cobol.parser.js +322 -0
  75. package/dist/src/cobol.parser.js.map +1 -0
  76. package/dist/src/cobol.projection.path.d.ts +50 -0
  77. package/dist/src/cobol.projection.path.js +146 -0
  78. package/dist/src/cobol.projection.path.js.map +1 -0
  79. package/dist/src/cobol.projection.symbolic.d.ts +68 -0
  80. package/dist/src/cobol.projection.symbolic.js +257 -0
  81. package/dist/src/cobol.projection.symbolic.js.map +1 -0
  82. package/dist/src/cobol.registration.d.ts +4 -0
  83. package/dist/src/cobol.registration.js +17 -0
  84. package/dist/src/cobol.registration.js.map +1 -0
  85. package/dist/src/cobol.representation.d.ts +16 -0
  86. package/dist/src/cobol.representation.js +29 -0
  87. package/dist/src/cobol.representation.js.map +1 -0
  88. package/dist/src/cobol.shared.fixed.lifecycle.spec.d.ts +1 -0
  89. package/dist/src/cobol.shared.fixed.lifecycle.spec.js +50 -0
  90. package/dist/src/cobol.shared.fixed.lifecycle.spec.js.map +1 -0
  91. package/dist/src/cobol.shared.odo.lifecycle.spec.d.ts +1 -0
  92. package/dist/src/cobol.shared.odo.lifecycle.spec.js +152 -0
  93. package/dist/src/cobol.shared.odo.lifecycle.spec.js.map +1 -0
  94. package/dist/src/cobol.symbolic.allocation.spec.d.ts +1 -0
  95. package/dist/src/cobol.symbolic.allocation.spec.js +84 -0
  96. package/dist/src/cobol.symbolic.allocation.spec.js.map +1 -0
  97. package/dist/src/customer.fixtures.d.ts +90 -0
  98. package/dist/src/customer.fixtures.js +167 -0
  99. package/dist/src/customer.fixtures.js.map +1 -0
  100. package/dist/src/customer.fixtures.spec.d.ts +1 -0
  101. package/dist/src/customer.fixtures.spec.js +132 -0
  102. package/dist/src/customer.fixtures.spec.js.map +1 -0
  103. package/dist/src/customer.projections.d.ts +44 -0
  104. package/dist/src/customer.projections.js +31 -0
  105. package/dist/src/customer.projections.js.map +1 -0
  106. package/dist/src/customer.projections.spec.d.ts +1 -0
  107. package/dist/src/customer.projections.spec.js +209 -0
  108. package/dist/src/customer.projections.spec.js.map +1 -0
  109. package/package.json +11 -11
  110. package/node.d.ts +0 -1
  111. package/node.js +0 -2
@@ -0,0 +1,6 @@
1
+ export * from './src/cobol.layout.index';
2
+ export * from './src/cobol.debug.range';
3
+ export * from './src/cobol.file.node';
4
+ export * from './src/cobol.occurs.clause';
5
+ export * from './src/cobol.parser';
6
+ export * from './src/cobol.registration';
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
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/cobol.layout.index"), exports);
18
+ __exportStar(require("./src/cobol.debug.range"), exports);
19
+ __exportStar(require("./src/cobol.file.node"), exports);
20
+ __exportStar(require("./src/cobol.occurs.clause"), exports);
21
+ __exportStar(require("./src/cobol.parser"), exports);
22
+ __exportStar(require("./src/cobol.registration"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAwC;AACxC,0DAAuC;AACvC,wDAAqC;AACrC,4DAAyC;AACzC,qDAAkC;AAClC,2DAAwC"}
@@ -0,0 +1,56 @@
1
+ import type { ProjectionPhysicalRecord } from "@cobol-ts/cursor-loader-types";
2
+ import type { ProjectedArraySource } from "@cobol-ts/arrays";
3
+ import { type CobolSymbolicPath } from "./cobol.projection.symbolic";
4
+ import type { CobolFixedProjectionPath, CobolProjectionPath } from "./cobol.projection.path";
5
+ import type { CobolProjectionDetails, CobolRepresentation } from "./cobol.parser";
6
+ /** One retained provider per projected-array runtime. The path is compiled
7
+ * once, and provider selection happens only when that runtime is created.
8
+ * A subsequent record lease rebinds just the record-dependent state. */
9
+ interface CobolArrayProvider extends ProjectedArraySource<CobolRepresentation> {
10
+ bind(parent: CobolRepresentation, details: CobolProjectionDetails): void;
11
+ }
12
+ export declare class FixedCobolArraySelection implements CobolArrayProvider {
13
+ readonly path: CobolFixedProjectionPath;
14
+ private record?;
15
+ private base;
16
+ private metrics;
17
+ private readonly count;
18
+ private readonly strideBits;
19
+ constructor(path: CobolFixedProjectionPath);
20
+ bind(parent: CobolRepresentation, details: CobolProjectionDetails): void;
21
+ length(): number;
22
+ /** Experimental: create a permanent occurrence descriptor, not a copied record. */
23
+ sharedElement(index: number, lease: {
24
+ record: ProjectionPhysicalRecord | undefined;
25
+ }): CobolRepresentation;
26
+ element(index: number, reusable?: CobolRepresentation): CobolRepresentation;
27
+ }
28
+ /** Symbolic arrays retain the original ODO resolution machinery and its
29
+ * record-scoped scratch and position cache. No geometry logic is changed. */
30
+ export declare class SymbolicCobolArraySelection implements CobolArrayProvider {
31
+ readonly path: CobolSymbolicPath;
32
+ private record?;
33
+ private resolver?;
34
+ private table?;
35
+ private metrics;
36
+ private sharedCapacity;
37
+ private sharedStrideBits;
38
+ private sharedActiveCount;
39
+ constructor(path: CobolSymbolicPath);
40
+ bind(parent: CobolRepresentation, details: CobolProjectionDetails): void;
41
+ length(): number;
42
+ /** Capability discovery is checked once at runtime construction. */
43
+ sharedOdoCapacity(): number;
44
+ /** Stable symbolic occurrence: its location and borrowed record are
45
+ * resolved through the current table/lease without per-child rebinding. */
46
+ sharedOdoElement(index: number, lease: {
47
+ record: ProjectionPhysicalRecord | undefined;
48
+ activeCount?: number;
49
+ }): CobolRepresentation;
50
+ element(index: number, reusable?: CobolRepresentation): CobolRepresentation;
51
+ }
52
+ /** A retained source is reusable only for exactly the same compiled path.
53
+ * This prevents mixing fixed and symbolic providers or reusing a provider
54
+ * for unrelated array members if a caller passes the wrong reusable source. */
55
+ export declare function bindCobolArraySelection(parent: CobolRepresentation, details: CobolProjectionDetails, path: CobolProjectionPath, reusable?: ProjectedArraySource<CobolRepresentation>): ProjectedArraySource<CobolRepresentation>;
56
+ export {};
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SymbolicCobolArraySelection = exports.FixedCobolArraySelection = void 0;
4
+ exports.bindCobolArraySelection = bindCobolArraySelection;
5
+ const metrics_1 = require("@cobol-ts/metrics");
6
+ const cobol_occurs_clause_1 = require("./cobol.occurs.clause");
7
+ const cobol_projection_symbolic_1 = require("./cobol.projection.symbolic");
8
+ const cobol_representation_1 = require("./cobol.representation");
9
+ class FixedCobolArraySelection {
10
+ path;
11
+ record;
12
+ base = 0;
13
+ metrics = metrics_1.NULL_METRICS;
14
+ count;
15
+ strideBits;
16
+ constructor(path) {
17
+ this.path = path;
18
+ if (path.node.kind !== "group" || path.runtimeDimensions.length !== 1)
19
+ throw new Error("COBOL projected array requires one fixed OCCURS group");
20
+ const dimension = path.runtimeDimensions[0];
21
+ this.count = dimension.count;
22
+ this.strideBits = dimension.strideBits;
23
+ }
24
+ bind(parent, details) {
25
+ this.metrics = details.metrics ?? metrics_1.NULL_METRICS;
26
+ this.metrics.put(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_BIND);
27
+ this.record = (0, cobol_representation_1.physical)(parent);
28
+ this.base = (0, cobol_representation_1.displacement)(parent);
29
+ }
30
+ length() {
31
+ this.metrics.put(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_LENGTH);
32
+ if (!this.record)
33
+ throw new Error("COBOL projected array is not bound");
34
+ return this.count;
35
+ }
36
+ /** Experimental: create a permanent occurrence descriptor, not a copied record. */
37
+ sharedElement(index, lease) {
38
+ if (!Number.isSafeInteger(index) || index < 0 || index >= this.count)
39
+ throw new RangeError(`OCCURS index ${index} outside 0..${this.count - 1}`);
40
+ const provider = this;
41
+ return {
42
+ get physical() {
43
+ if (!lease.record)
44
+ throw new Error("Projected array is not bound");
45
+ return lease.record;
46
+ },
47
+ get displacementBits() { return provider.base + index * provider.strideBits; }
48
+ };
49
+ }
50
+ element(index, reusable) {
51
+ this.metrics.put(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_ELEMENT);
52
+ const record = this.record;
53
+ if (!record)
54
+ throw new Error("COBOL projected array is not bound");
55
+ if (!Number.isSafeInteger(index) || index < 0 || index >= this.count)
56
+ throw new RangeError(`OCCURS index ${index} outside 0..${this.count - 1}`);
57
+ const selected = reusable && "physical" in reusable && "displacementBits" in reusable
58
+ ? reusable
59
+ : { physical: record, displacementBits: 0 };
60
+ selected.physical = record;
61
+ selected.displacementBits = this.base + index * this.strideBits;
62
+ return selected;
63
+ }
64
+ }
65
+ exports.FixedCobolArraySelection = FixedCobolArraySelection;
66
+ /** Symbolic arrays retain the original ODO resolution machinery and its
67
+ * record-scoped scratch and position cache. No geometry logic is changed. */
68
+ class SymbolicCobolArraySelection {
69
+ path;
70
+ record;
71
+ resolver;
72
+ table;
73
+ metrics = metrics_1.NULL_METRICS;
74
+ sharedCapacity = 0;
75
+ sharedStrideBits = 0;
76
+ sharedActiveCount = 0;
77
+ constructor(path) {
78
+ this.path = path;
79
+ if (path.node.kind !== "group" || !(0, cobol_occurs_clause_1.hasOccursClause)(path.node.source.clauses))
80
+ throw new Error("COBOL projected array requires an OCCURS group");
81
+ }
82
+ bind(parent, details) {
83
+ this.metrics = details.metrics ?? metrics_1.NULL_METRICS;
84
+ this.metrics.put(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_BIND);
85
+ const record = (0, cobol_representation_1.physical)(parent);
86
+ const table = this.table ?? (this.table = { physical: record, originBits: 0, enclosingIndices: [] });
87
+ const resolver = (0, cobol_representation_1.countResolver)(details, record);
88
+ (0, cobol_projection_symbolic_1.selectSymbolicInto)((0, cobol_representation_1.symbolicView)(parent), this.path, resolver, [], table);
89
+ this.resolver = resolver;
90
+ this.record = record;
91
+ // Opt-in only for a root-level ODO with fixed element size and a
92
+ // statically positioned table. Nested/symbolic layouts stay lazy.
93
+ this.sharedCapacity = 0;
94
+ if (details.experimentalSharedOdoArrays) {
95
+ const occurs = (0, cobol_occurs_clause_1.findOccursClause)(this.path.node.source.clauses);
96
+ const size = this.path.node.size;
97
+ if (occurs?.kind === "occurs" && !("count" in occurs) &&
98
+ occurs.max <= 8 && occurs.max > 0 &&
99
+ typeof size !== "number" && size.kind === "depending-on" &&
100
+ typeof size.expression === "number" &&
101
+ this.path.relativeSteps.length === this.path.steps.length &&
102
+ this.path.steps.every((step, index) => typeof step.node.leftOffset === "number" && step.index === undefined &&
103
+ (index === this.path.steps.length - 1 || !(0, cobol_occurs_clause_1.hasOccursClause)(step.node.source.clauses))) &&
104
+ table.enclosingIndices.length === 0) {
105
+ this.sharedCapacity = occurs.max;
106
+ this.sharedStrideBits = size.expression;
107
+ this.sharedActiveCount = (0, cobol_projection_symbolic_1.activeCount)(this.path.node, resolver, table.enclosingIndices);
108
+ }
109
+ }
110
+ }
111
+ length() {
112
+ this.metrics.put(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_LENGTH);
113
+ if (!this.record)
114
+ throw new Error("COBOL projected array is not bound");
115
+ if (this.sharedCapacity > 0)
116
+ return this.sharedActiveCount;
117
+ return (0, cobol_projection_symbolic_1.activeCount)(this.path.node, this.resolver, this.table.enclosingIndices);
118
+ }
119
+ /** Capability discovery is checked once at runtime construction. */
120
+ sharedOdoCapacity() { return this.sharedCapacity; }
121
+ /** Stable symbolic occurrence: its location and borrowed record are
122
+ * resolved through the current table/lease without per-child rebinding. */
123
+ sharedOdoElement(index, lease) {
124
+ if (!this.sharedCapacity || !Number.isSafeInteger(index) || index < 0 || index >= this.sharedCapacity)
125
+ throw new RangeError(`ODO occurrence index ${index} outside retained capacity`);
126
+ const provider = this;
127
+ const indices = [index];
128
+ const requireActive = () => {
129
+ if (!lease.record)
130
+ throw new Error("Projected array is not bound");
131
+ if (index >= (lease.activeCount ?? 0))
132
+ throw new RangeError(`ODO occurrence ${index} is not active (count ${lease.activeCount})`);
133
+ };
134
+ return {
135
+ get physical() { requireActive(); return lease.record; },
136
+ get originBits() { requireActive(); return provider.table.originBits + index * provider.sharedStrideBits; },
137
+ get endBits() { requireActive(); return provider.table.originBits + (index + 1) * provider.sharedStrideBits; },
138
+ enclosingIndices: indices
139
+ };
140
+ }
141
+ element(index, reusable) {
142
+ this.metrics.put(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_ELEMENT);
143
+ const record = this.record;
144
+ if (!record)
145
+ throw new Error("COBOL projected array is not bound");
146
+ const selected = reusable && "originBits" in reusable
147
+ ? reusable
148
+ : { physical: record, originBits: 0, enclosingIndices: [] };
149
+ (0, cobol_projection_symbolic_1.singleDepthOccurrenceInto)(this.table, this.path.node, index, this.resolver, selected);
150
+ return selected;
151
+ }
152
+ }
153
+ exports.SymbolicCobolArraySelection = SymbolicCobolArraySelection;
154
+ /** A retained source is reusable only for exactly the same compiled path.
155
+ * This prevents mixing fixed and symbolic providers or reusing a provider
156
+ * for unrelated array members if a caller passes the wrong reusable source. */
157
+ function bindCobolArraySelection(parent, details, path, reusable) {
158
+ let provider;
159
+ if ("symbolic" in path) {
160
+ provider = reusable instanceof SymbolicCobolArraySelection && reusable.path === path
161
+ ? reusable : new SymbolicCobolArraySelection(path);
162
+ }
163
+ else {
164
+ provider = reusable instanceof FixedCobolArraySelection && reusable.path === path
165
+ ? reusable : new FixedCobolArraySelection(path);
166
+ }
167
+ if (provider !== reusable)
168
+ details.metrics?.put(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_CREATE);
169
+ provider.bind(parent, details);
170
+ return provider;
171
+ }
172
+ //# sourceMappingURL=cobol.array.selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cobol.array.selection.js","sourceRoot":"","sources":["../../src/cobol.array.selection.ts"],"names":[],"mappings":";;;AAsKA,0DAeC;AArLD,+CAAuE;AAIvE,+DAAuE;AACvE,2EAAqJ;AAErJ,iEAAwF;AAUxF,MAAa,wBAAwB;IAOZ;IANb,MAAM,CAA2B;IACjC,IAAI,GAAC,CAAC,CAAC;IACP,OAAO,GAAa,sBAAY,CAAC;IACxB,KAAK,CAAQ;IACb,UAAU,CAAQ;IAEnC,YAAqB,IAA6B;QAA7B,SAAI,GAAJ,IAAI,CAAyB;QAC9C,IAAG,IAAI,CAAC,IAAI,CAAC,IAAI,KAAG,OAAO,IAAI,IAAI,CAAC,iBAAiB,CAAC,MAAM,KAAG,CAAC;YAC5D,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC7E,MAAM,SAAS,GAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,GAAC,SAAS,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAC,SAAS,CAAC,UAAU,CAAC;IACzC,CAAC;IAED,IAAI,CAAC,MAA0B,EAAC,OAA8B;QAC1D,IAAI,CAAC,OAAO,GAAC,OAAO,CAAC,OAAO,IAAE,sBAAY,CAAC;QAC3C,IAAI,CAAC,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
1
+ export {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const metrics_1 = require("@cobol-ts/metrics");
4
+ const errors_1 = require("@cobol-ts/errors");
5
+ const cobol_parser_1 = require("./cobol.parser");
6
+ const cobol_array_selection_1 = require("./cobol.array.selection");
7
+ const customer_fixtures_1 = require("./customer.fixtures");
8
+ function record(bytes, recordNumber) {
9
+ return { buffers: [bytes], startByte: 0, endByte: bytes.length, lastValidByte: bytes.length,
10
+ source: 'array-selection.fb', recordNumber, recordState: (0, cobol_parser_1.createCobolRecordState)() };
11
+ }
12
+ describe('specialised COBOL projected-array providers', () => {
13
+ test('fixed provider caches the compiled path and reuses the child representation across records', () => {
14
+ const metrics = new metrics_1.MemoryMetrics();
15
+ const details = { ...(0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolFixedDetails)(customer_fixtures_1.customerFixedOccurs.layout)), metrics };
16
+ const arrayPath = cobol_parser_1.cobolParser.compileProjectionPath(details, undefined, ['CUSTOMER', 'TELEPHONES']);
17
+ const scalarPath = cobol_parser_1.cobolParser.compileProjectionPath(details, undefined, ['PHONE-RAW'], arrayPath);
18
+ const first = record(customer_fixtures_1.customerFixedOccurs.records[0].bytes, 1);
19
+ const second = record(customer_fixtures_1.customerFixedOccurs.records[1].bytes, 2);
20
+ const provider = cobol_parser_1.cobolParser.array(first, details, arrayPath);
21
+ expect(provider).toBeInstanceOf(cobol_array_selection_1.FixedCobolArraySelection);
22
+ expect(provider.length()).toBe(2);
23
+ const child = provider.element(1);
24
+ expect(cobol_parser_1.cobolParser.string(child, details, scalarPath)).toBe('10/16/d4 f6 f7 f8 f9 f0');
25
+ expect(() => provider.element(2)).toThrow(/OCCURS index/);
26
+ const rebound = cobol_parser_1.cobolParser.array(second, details, arrayPath, provider);
27
+ expect(rebound).toBe(provider);
28
+ expect(rebound.element(1, child)).toBe(child);
29
+ expect(cobol_parser_1.cobolParser.string(child, details, scalarPath)).toBe('10/16/c2 f1 f1 f2 f2 f3');
30
+ expect(metrics.get(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_CREATE)).toBe(1);
31
+ expect(metrics.get(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_BIND)).toBe(2);
32
+ });
33
+ test('a different compiled path cannot accidentally inherit another fixed provider', () => {
34
+ const metrics = new metrics_1.MemoryMetrics();
35
+ const details = { ...(0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolFixedDetails)(customer_fixtures_1.customerFixedOccurs.layout)), metrics };
36
+ const firstPath = cobol_parser_1.cobolParser.compileProjectionPath(details, undefined, ['CUSTOMER', 'TELEPHONES']);
37
+ const otherPath = cobol_parser_1.cobolParser.compileProjectionPath(details, undefined, ['CUSTOMER', 'TELEPHONES']);
38
+ const bytes = record(customer_fixtures_1.customerFixedOccurs.records[0].bytes, 1);
39
+ const first = cobol_parser_1.cobolParser.array(bytes, details, firstPath);
40
+ const other = cobol_parser_1.cobolParser.array(bytes, details, otherPath, first);
41
+ expect(other).toBeInstanceOf(cobol_array_selection_1.FixedCobolArraySelection);
42
+ expect(other).not.toBe(first);
43
+ expect(metrics.get(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_CREATE)).toBe(2);
44
+ });
45
+ test('symbolic provider reuses its table and resolves changing ODO counts on rebinding', () => {
46
+ const metrics = new metrics_1.MemoryMetrics();
47
+ const details = { ...(0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolProjectionDetails)(customer_fixtures_1.customerOdoRedefines.layout)), metrics };
48
+ const path = cobol_parser_1.cobolParser.compileProjectionPath(details, undefined, ['CUSTOMER', 'PURCHASES']);
49
+ const empty = record(customer_fixtures_1.customerOdoRedefines.records[0].bytes, 1);
50
+ const populated = record(customer_fixtures_1.customerOdoRedefines.records[1].bytes, 2);
51
+ const provider = cobol_parser_1.cobolParser.array(empty, details, path);
52
+ expect(provider).toBeInstanceOf(cobol_array_selection_1.SymbolicCobolArraySelection);
53
+ expect(provider.length()).toBe(0);
54
+ expect(() => provider.element(0)).toThrow(/OCCURS index/);
55
+ const rebound = cobol_parser_1.cobolParser.array(populated, details, path, provider);
56
+ expect(rebound).toBe(provider);
57
+ expect(rebound.length()).toBe(3);
58
+ const item = rebound.element(2);
59
+ expect('originBits' in item ? item.originBits : -1).toBe(19 * 8);
60
+ expect(metrics.get(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_CREATE)).toBe(1);
61
+ expect(metrics.get(metrics_1.METRIC.COBOL_ARRAY_PROVIDER_BIND)).toBe(2);
62
+ });
63
+ });
64
+ //# sourceMappingURL=cobol.array.selection.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cobol.array.selection.spec.js","sourceRoot":"","sources":["../../src/cobol.array.selection.spec.ts"],"names":[],"mappings":";;AAAA,+CAAuD;AAEvD,6CAA8C;AAC9C,iDAAuH;AACvH,mEAA6F;AAC7F,2DAA6E;AAE7E,SAAS,MAAM,CAAC,KAAgB,EAAC,YAAmB;IAChD,OAAO,EAAC,OAAO,EAAC,CAAC,KAAK,CAAC,EAAC,SAAS,EAAC,CAAC,EAAC,OAAO,EAAC,KAAK,CAAC,MAAM,EAAC,aAAa,EAAC,KAAK,CAAC,MAAM;QAC/E,MAAM,EAAC,oBAAoB,EAAC,YAAY,EAAC,WAAW,EAAC,IAAA,qCAAsB,GAAE,EAAC,CAAC;AACvF,CAAC;AAED,QAAQ,CAAC,6CAA6C,EAAC,GAAE,EAAE;IACvD,IAAI,CAAC,4FAA4F,EAAC,GAAE,EAAE;QAClG,MAAM,OAAO,GAAC,IAAI,uBAAa,EAAE,CAAC;QAClC,MAAM,OAAO,GAAC,EAAC,GAAG,IAAA,qBAAY,EAAC,IAAA,sCAAuB,EAAC,uCAAmB,CAAC,MAAM,CAAC,CAAC,EAAC,OAAO,EAAC,CAAC;QAC7F,MAAM,SAAS,GAAC,0BAAW,CAAC,qBAAqB,CAAC,OAAO,EAAC,SAAS,EAAC,CAAC,UAAU,EAAC,YAAY,CAAC,CAAC,CAAC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C,QAAQ,CAAC,CAAC;QAC/B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjC,MAAM,IAAI,GAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,GAAC,CAAC,CAAC,CAAC;QAC/D,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAM,CAAC,2BAA2B,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAChE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cursor_file_1 = require("@cobol-ts/cursor-file");
4
+ const cursor_projection_1 = require("@cobol-ts/cursor-projection");
5
+ const errors_1 = require("@cobol-ts/errors");
6
+ const cobol_parser_1 = require("./cobol.parser");
7
+ const customer_fixtures_1 = require("./customer.fixtures");
8
+ const projection = (0, cursor_projection_1.defineProjection)({
9
+ id: { type: 'integer', path: ['CUSTOMER', 'CUSTOMER-ID'] },
10
+ name: { type: 'string', path: ['CUSTOMER', 'CUSTOMER-NAME'] },
11
+ status: { type: 'character', path: ['CUSTOMER', 'STATUS'] }
12
+ });
13
+ function memorySource(content, bufferSize) {
14
+ const file = { bytes: content, offset: 0, reads: 0 };
15
+ return {
16
+ file,
17
+ infrastructure: {
18
+ parsers: {
19
+ cobol: {
20
+ parser: cobol_parser_1.cobolParser,
21
+ parserConfig: () => (0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolDecodedFixedDetails)(customer_fixtures_1.customerSimple.layout)),
22
+ createRecordState: cobol_parser_1.createCobolRecordState,
23
+ cleanRecordState: cobol_parser_1.cleanCobolRecordState
24
+ }
25
+ },
26
+ bufferSize,
27
+ fillFileBuffer: async (source, destination) => {
28
+ source.reads++;
29
+ const count = Math.min(destination.length, source.bytes.length - source.offset);
30
+ destination.set(source.bytes.subarray(source.offset, source.offset + count));
31
+ source.offset += count;
32
+ return count;
33
+ }
34
+ }
35
+ };
36
+ }
37
+ test('synchronously calls back with decoded records across small physical buffers', async () => {
38
+ const bytes = Uint8Array.from([...customer_fixtures_1.customerSimple.records[0].bytes, ...customer_fixtures_1.customerSimple.records[1].bytes]);
39
+ const source = memorySource(bytes, 3);
40
+ const rows = [];
41
+ let saved;
42
+ await (0, cursor_file_1.scanThrowingFileCursor)({ filename: 'customer.fb', fileType: 'cobol', projection }, source.file, source.infrastructure, row => {
43
+ saved = row;
44
+ rows.push([row.id(), row.name(), row.status()]);
45
+ });
46
+ expect(rows).toEqual([[1, 'ALICE ', 'A'], [42, 'BOB ', 'I']]);
47
+ expect(source.file.reads).toBeGreaterThan(2);
48
+ expect(() => saved.id()).toThrow(/not bound/i);
49
+ });
50
+ test('false stops callback scan without processing later records', async () => {
51
+ const bytes = Uint8Array.from([...customer_fixtures_1.customerSimple.records[0].bytes, ...customer_fixtures_1.customerSimple.records[1].bytes]);
52
+ const source = memorySource(bytes, 3);
53
+ let calls = 0;
54
+ await (0, cursor_file_1.scanThrowingFileCursor)({ filename: 'customer.fb', fileType: 'cobol', projection }, source.file, source.infrastructure, row => { expect(row.id()).toBe(1); calls++; return false; });
55
+ expect(calls).toBe(1);
56
+ });
57
+ test('rejects asynchronous callbacks because projections are borrowed', async () => {
58
+ const source = memorySource(customer_fixtures_1.customerSimple.records[0].bytes, 3);
59
+ await expect((0, cursor_file_1.scanThrowingFileCursor)({
60
+ filename: 'customer.fb',
61
+ fileType: 'cobol',
62
+ projection
63
+ }, source.file, source.infrastructure,
64
+ // @ts-expect-error Async callbacks are deliberately forbidden by the API.
65
+ async (row) => {
66
+ row.id();
67
+ })).rejects.toThrow(/synchronous/);
68
+ });
69
+ //# sourceMappingURL=cobol.callback.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cobol.callback.spec.js","sourceRoot":"","sources":["../../src/cobol.callback.spec.ts"],"names":[],"mappings":";;AAAA,uDAA6D;AAC7D,mEAA6D;AAC7D,6CAA8C;AAC9C,iDAKwB;AACxB,2DAAmD;AAGnD,MAAM,UAAU,GAAG,IAAA,oCAAgB,EAAW;IAC1C,EAAE,EAAE,EAAC,IAAI,EAAC,SAAS,EAAC,IAAI,EAAC,CAAC,UAAU,EAAC,aAAa,CAAC,EAAC;IACpD,IAAI,EAAE,EAAC,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,CAAC,UAAU,EAAC,eAAe,CAAC,EAAC;IACvD,MAAM,EAAE,EAAC,IAAI,EAAC,WAAW,EAAC,IAAI,EAAC,CAAC,UAAU,EAAC,QAAQ,CAAC,EAAC;CACxD,CAAC,CAAC;AAEH,SAAS,YAAY,CAAC,OAAkB,EAAC,UAAiB;IACtD,MAAM,IAAI,GAAC,EAAC,KAAK,EAAC,OAAO,EAAC,MAAM,EAAC,CAAC,EAAC,KAAK,EAAC,CAAC,EAAC,CAAC;IAC5C,OAAO;QACH,IAAI;QACJ,cAAc,EAAE;YACZ,OAAO,EAAE;gBACL,KAAK,EAAE;oBACH,MAAM,EAAC,0BAAW;oBAClB,YAAY,EAAC,GAAE,EAAE,CAAA,IAAA,qBAAY,EAAC,IAAA,6CAA8B,EAAC,kCAAc,CAAC,MAAM,CAAC,CAAC;oBACpF,iBAAiB,EAAC,qCAAsB;oBACxC,gBAAgB,EAAC,oCAAqB;iBACzC;aACJ;YACD,UAAU;YACV,cAAc,EAAC,KAAK,EAAE,MAAkB,EAAC,WAAsB,EAAC,EAAE;gBAC9D,MAAM,CAAC,KAAK,EAAE,CAAC;g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,EAClB;QACI,QAAQ,EAAE,aAAa;QACvB,QAAQ,EAAE,OAAO;QACjB,UAAU;KACb,EACD,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,cAAc;IACrB,0EAA0E;IAC1E,KAAK,EAAC,GAAG,EAAC,EAAE;QACR,GAAG,CAAC,EAAE,EAAE,CAAA;IACZ,CAAC,CACJ,CACJ,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;AACpC,CAAC,CAAC,CAAA"}
@@ -0,0 +1,21 @@
1
+ import { type ProjectionPhysicalRecord } from "@cobol-ts/cursor-loader-types";
2
+ /** Exclusive-end, record-relative byte coordinates. */
3
+ export type CobolDebugRange = Readonly<{
4
+ from: number;
5
+ to: number;
6
+ }>;
7
+ /**
8
+ * Diagnostic numeric projection: upper 16 bits = from, lower 16 bits = to.
9
+ * Arithmetic (not signed bitwise operations) preserves unsigned offsets.
10
+ */
11
+ export declare function cobolDebugRangeNumber(range: CobolDebugRange): number;
12
+ /**
13
+ * Diagnostic string projection: 'from/to/hex-bytes'.
14
+ * The hex is the actual borrowed record content, not a decoded COBOL value.
15
+ */
16
+ export declare function cobolDebugRangeString(record: ProjectionPhysicalRecord, range: CobolDebugRange): string;
17
+ /** Convert already-evaluated COBOL bit geometry to byte coordinates. */
18
+ export declare function cobolDebugRangeFromBits(offsetBits: number, sizeBits: number, into?: {
19
+ from: number;
20
+ to: number;
21
+ }): CobolDebugRange;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cobolDebugRangeNumber = cobolDebugRangeNumber;
4
+ exports.cobolDebugRangeString = cobolDebugRangeString;
5
+ exports.cobolDebugRangeFromBits = cobolDebugRangeFromBits;
6
+ const cursor_loader_types_1 = require("@cobol-ts/cursor-loader-types");
7
+ const MAX_16_BIT = 0xffff;
8
+ /**
9
+ * Diagnostic numeric projection: upper 16 bits = from, lower 16 bits = to.
10
+ * Arithmetic (not signed bitwise operations) preserves unsigned offsets.
11
+ */
12
+ function cobolDebugRangeNumber(range) {
13
+ validateRange(range);
14
+ if (range.to > MAX_16_BIT) {
15
+ throw new RangeError("COBOL debug range exceeds unsigned 16-bit coordinate capacity");
16
+ }
17
+ return range.from * 0x10000 + range.to;
18
+ }
19
+ /**
20
+ * Diagnostic string projection: 'from/to/hex-bytes'.
21
+ * The hex is the actual borrowed record content, not a decoded COBOL value.
22
+ */
23
+ function cobolDebugRangeString(record, range) {
24
+ validateRange(range);
25
+ if (record.startByte + range.to > record.endByte) {
26
+ throw new RangeError("COBOL debug field extends beyond the completed record");
27
+ }
28
+ const start = record.startByte + range.from;
29
+ const end = record.startByte + range.to;
30
+ return `${range.from}/${range.to}/${(0, cursor_loader_types_1.bytesToDebugString)(record, start, end)}`;
31
+ }
32
+ /** Convert already-evaluated COBOL bit geometry to byte coordinates. */
33
+ function cobolDebugRangeFromBits(offsetBits, sizeBits, into) {
34
+ if (!Number.isSafeInteger(offsetBits) || offsetBits < 0 || offsetBits % 8 !== 0 ||
35
+ !Number.isSafeInteger(sizeBits) || sizeBits < 0 || sizeBits % 8 !== 0 ||
36
+ !Number.isSafeInteger(offsetBits + sizeBits)) {
37
+ throw new RangeError("COBOL debug geometry must be nonnegative, byte-aligned safe integers");
38
+ }
39
+ const from = offsetBits / 8, to = (offsetBits + sizeBits) / 8;
40
+ if (into) {
41
+ into.from = from;
42
+ into.to = to;
43
+ return into;
44
+ }
45
+ return { from, to };
46
+ }
47
+ function validateRange(range) {
48
+ if (!Number.isSafeInteger(range.from) || range.from < 0 ||
49
+ !Number.isSafeInteger(range.to) || range.to < range.from) {
50
+ throw new RangeError("Invalid COBOL debug byte range");
51
+ }
52
+ }
53
+ //# sourceMappingURL=cobol.debug.range.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cobol.debug.range.js","sourceRoot":"","sources":["../../src/cobol.debug.range.ts"],"names":[],"mappings":";;AAWA,sDAMC;AAMD,sDAWC;AAGD,0DAYC;AAjDD,uEAAg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EAC9C,CAAC;QACC,MAAM,IAAI,UAAU,CAAC,sEAAsE,CAAC,CAAC;IACjG,CAAC;IACD,MAAM,IAAI,GAAC,UAAU,GAAC,CAAC,EAAC,EAAE,GAAC,CAAC,UAAU,GAAC,QAAQ,CAAC,GAAC,CAAC,CAAC;IACnD,IAAG,IAAI,EAAC,CAAC;QAAA,IAAI,CAAC,IAAI,GAAC,IAAI,CAAC;QAAA,IAAI,CAAC,EAAE,GAAC,EAAE,CAAC;QAAA,OAAO,IAAI,CAAC;IAAA,CAAC;IAChD,OAAO,EAAC,IAAI,EAAC,EAAE,EAAC,CAAC;AACrB,CAAC;AAED,SAAS,aAAa,CAAC,KAAsB;IACzC,IACI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC;QACnD,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,EAC1D,CAAC;QACC,MAAM,IAAI,UAAU,CAAC,gCAAgC,CAAC,CAAC;IAC3D,CAAC;AACL,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cobol_debug_range_1 = require("./cobol.debug.range");
4
+ function record(startByte, endByte) {
5
+ return {
6
+ buffers: [Uint8Array.from([0xaa, 0xbb, 0xcc]), Uint8Array.from([0xdd, 0xee, 0xff])],
7
+ startByte, endByte, lastValidByte: 6,
8
+ source: "fixture.bin", recordNumber: 1
9
+ };
10
+ }
11
+ test("debug number encodes exclusive byte positions in two unsigned 16-bit halves", () => {
12
+ expect((0, cobol_debug_range_1.cobolDebugRangeNumber)({ from: 10, to: 14 })).toBe(10 * 65536 + 14);
13
+ expect((0, cobol_debug_range_1.cobolDebugRangeNumber)({ from: 0, to: 65535 })).toBe(65535);
14
+ expect(() => (0, cobol_debug_range_1.cobolDebugRangeNumber)({ from: 0, to: 65536 })).toThrow(/16-bit/);
15
+ });
16
+ test("string debug output respects record start and crosses buffer boundaries", () => {
17
+ // Record is logical bytes 1..5; selected field bytes 1..3 inside that record.
18
+ expect((0, cobol_debug_range_1.cobolDebugRangeString)(record(1, 5), { from: 1, to: 3 }))
19
+ .toBe("1/3/cc dd");
20
+ });
21
+ test("refuses to read beyond a record even when following bytes are in the buffer", () => {
22
+ expect(() => (0, cobol_debug_range_1.cobolDebugRangeString)(record(1, 4), { from: 0, to: 4 }))
23
+ .toThrow(/beyond/);
24
+ });
25
+ test("does not silently round bit offsets into bytes", () => {
26
+ expect((0, cobol_debug_range_1.cobolDebugRangeFromBits)(80, 32)).toEqual({ from: 10, to: 14 });
27
+ expect(() => (0, cobol_debug_range_1.cobolDebugRangeFromBits)(81, 32)).toThrow(/byte-aligned/);
28
+ });
29
+ //# sourceMappingURL=cobol.debug.range.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cobol.debug.range.spec.js","sourceRoot":"","sources":["../../src/cobol.debug.range.spec.ts"],"names":[],"mappings":";;AAAA,2DAA0G;AAG1G,SAAS,MAAM,CAAC,SAAiB,EAAE,OAAe;IAC9C,OAAO;QACH,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QACnF,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;QACpC,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC;KACzC,CAAC;AACN,CAAC;AAED,IAAI,CAAC,6EAA6E,EAAE,GAAG,EAAE;IACrF,MAAM,CAAC,IAAA,yCAAqB,EAAC,EAAC,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAA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CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
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_file_1 = require("@cobol-ts/cursor-file");
7
+ const cursor_projection_1 = require("@cobol-ts/cursor-projection");
8
+ const errors_1 = require("@cobol-ts/errors");
9
+ const cobol_parser_1 = require("./cobol.parser");
10
+ const customer_fixtures_1 = require("./customer.fixtures");
11
+ test('opens a genuine fixed-block binary file and reads all rows from the filesystem', async () => {
12
+ const directory = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'cobol-decoder-'));
13
+ const filename = (0, node_path_1.join)(directory, 'customers.fb');
14
+ const fixture = Uint8Array.from(customer_fixtures_1.customerSimple.records.flatMap(r => [...r.bytes]));
15
+ await (0, promises_1.writeFile)(filename, fixture);
16
+ const handle = await (0, promises_1.open)(filename, 'r');
17
+ try {
18
+ const projection = (0, cursor_projection_1.defineProjection)({
19
+ id: { type: 'integer', path: ['CUSTOMER', 'CUSTOMER-ID'] },
20
+ name: { type: 'string', path: ['CUSTOMER', 'CUSTOMER-NAME'] }
21
+ });
22
+ const details = (0, errors_1.valueOrThrow)((0, cobol_parser_1.createCobolDecodedFixedDetails)(customer_fixtures_1.customerSimple.layout));
23
+ const cursor = (0, cursor_file_1.createFileCursor)({ filename, fileType: 'cobol', projection }, { handle }, { parsers: { cobol: { parser: cobol_parser_1.cobolParser, parserConfig: () => details,
24
+ createRecordState: cobol_parser_1.createCobolRecordState, cleanRecordState: cobol_parser_1.cleanCobolRecordState } },
25
+ bufferSize: 4, fillFileBuffer: async (source, destination) => (await source.handle.read(destination, 0, destination.length, null)).bytesRead
26
+ });
27
+ const values = [];
28
+ for await (const record of cursor) {
29
+ if (Array.isArray(record))
30
+ throw new Error(`COBOL row failure: ${record.join(', ')}`);
31
+ values.push({ id: record.result.id(), name: record.result.name() });
32
+ record.close();
33
+ }
34
+ expect(values).toEqual([{ id: 1, name: 'ALICE ' }, { id: 42, name: 'BOB ' }]);
35
+ }
36
+ finally {
37
+ await handle.close();
38
+ await (0, promises_1.rm)(directory, { recursive: true, force: true });
39
+ }
40
+ });
41
+ //# sourceMappingURL=cobol.decoded.file.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cobol.decoded.file.spec.js","sourceRoot":"","sources":["../../src/cobol.decoded.file.spec.ts"],"names":[],"mappings":";;AAAA,+CAA8D;AAC9D,qCAA+B;AAC/B,yCAA+B;AAC/B,uDAAuD;AACvD,mEAA6D;AAC7D,6CAA8C;AAC9C,iDAAuH;AACvH,2DAAmD;AAEnD,IAAI,CAAC,gFAAgF,EAAC,KAAK,IAAE,EAAE;IAC3F,MAAM,SAAS,GAAC,MAAM,IAAA,kBAAO,EAAC,IAAA,gBAAI,EAAC,IAAA,gBAAM,GAAE,EAAC,gBAAgB,CAAC,CAAC,CAAC;IAC/D,MAAM,QAAQ,GAAC,IAAA,gBAAI,EAAC,SAAS,EAAC,cAAc,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAC,UAAU,CAAC,IAAI,CAAC,kCAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA,EAAE,CAAA,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC/E,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAC,OAAO,CAAC,CAAC;IAClC,MAAM,MAAM,GAAC,MAAM,IAAA,eAAI,EAAC,QAAQ,EAAC,GAAG,CAAC,CAAC;IACtC,IAAI,CAAC;QACD,MAAM,UAAU,GAAC,IAAA,oCAAgB,EAA8B;YAC3D,EAAE,EAAC,EAAC,IAAI,EAAC,SAAS,EAAC,IAAI,EAAC,CAAC,UAAU,EAAC,aAAa,CAAC,EAAC;YACnD,IAAI,EAAC,EAAC,IAAI,EAAC,QAAQ,EAAC,IA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