@cobol-ts/cursor-projection 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.
@@ -0,0 +1,339 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const projection_definition_1 = require("./projection.definition");
4
+ const create_projection_1 = require("./create.projection");
5
+ describe("canonicalProjection", () => {
6
+ test("uses the field name as the default path", () => {
7
+ const projection = {
8
+ age: {
9
+ type: "integer"
10
+ },
11
+ name: {
12
+ type: "string"
13
+ }
14
+ };
15
+ expect((0, projection_definition_1.canonicalProjection)(projection)).toEqual({
16
+ age: {
17
+ type: "integer",
18
+ path: [
19
+ "age"
20
+ ]
21
+ },
22
+ name: {
23
+ type: "string",
24
+ path: [
25
+ "name"
26
+ ]
27
+ }
28
+ });
29
+ });
30
+ test("preserves an explicitly supplied path", () => {
31
+ const projection = {
32
+ postcode: {
33
+ type: "string",
34
+ path: [
35
+ "address",
36
+ "postcode"
37
+ ]
38
+ }
39
+ };
40
+ expect((0, projection_definition_1.canonicalProjection)(projection)).toEqual({
41
+ postcode: {
42
+ type: "string",
43
+ path: [
44
+ "address",
45
+ "postcode"
46
+ ]
47
+ }
48
+ });
49
+ });
50
+ test("preserves each field type", () => {
51
+ const projection = {
52
+ id: {
53
+ type: "integer"
54
+ },
55
+ weight: {
56
+ type: "float"
57
+ },
58
+ initial: {
59
+ type: "character"
60
+ },
61
+ name: {
62
+ type: "string"
63
+ }
64
+ };
65
+ expect((0, projection_definition_1.canonicalProjection)(projection)).toEqual({
66
+ id: {
67
+ type: "integer",
68
+ path: [
69
+ "id"
70
+ ]
71
+ },
72
+ weight: {
73
+ type: "float",
74
+ path: [
75
+ "weight"
76
+ ]
77
+ },
78
+ initial: {
79
+ type: "character",
80
+ path: [
81
+ "initial"
82
+ ]
83
+ },
84
+ name: {
85
+ type: "string",
86
+ path: [
87
+ "name"
88
+ ]
89
+ }
90
+ });
91
+ });
92
+ test("does not replace an explicitly empty path", () => {
93
+ const projection = {
94
+ value: {
95
+ type: "integer",
96
+ path: []
97
+ }
98
+ };
99
+ expect((0, projection_definition_1.canonicalProjection)(projection)).toEqual({
100
+ value: {
101
+ type: "integer",
102
+ path: []
103
+ }
104
+ });
105
+ });
106
+ test("does not modify the authoring projection", () => {
107
+ const projection = {
108
+ age: {
109
+ type: "integer"
110
+ },
111
+ postcode: {
112
+ type: "string",
113
+ path: [
114
+ "address",
115
+ "postcode"
116
+ ]
117
+ }
118
+ };
119
+ (0, projection_definition_1.canonicalProjection)(projection);
120
+ expect(projection).toEqual({
121
+ age: {
122
+ type: "integer"
123
+ },
124
+ postcode: {
125
+ type: "string",
126
+ path: [
127
+ "address",
128
+ "postcode"
129
+ ]
130
+ }
131
+ });
132
+ });
133
+ test("creates a new canonical field object", () => {
134
+ const field = {
135
+ type: "string",
136
+ path: [
137
+ "customer",
138
+ "name"
139
+ ]
140
+ };
141
+ const projection = {
142
+ name: field
143
+ };
144
+ const canonical = (0, projection_definition_1.canonicalProjection)(projection);
145
+ expect(canonical.name).not.toBe(field);
146
+ expect(canonical.name.path).toBe(field.path);
147
+ });
148
+ });
149
+ /*
150
+ * Compile-time tests.
151
+ *
152
+ * These assignments deliberately rely on TypeScript checking the derived
153
+ * projection types. If the type arithmetic changes incorrectly, this file
154
+ * should stop compiling.
155
+ */
156
+ describe("projection types", () => {
157
+ test("derives number and string accessor types", () => {
158
+ const projection = {
159
+ age: {
160
+ type: "integer"
161
+ },
162
+ weight: {
163
+ type: "float"
164
+ },
165
+ initial: {
166
+ type: "character"
167
+ },
168
+ name: {
169
+ type: "string"
170
+ }
171
+ };
172
+ const customer = {
173
+ age: () => 62,
174
+ weight: () => 81.5,
175
+ initial: () => "P",
176
+ name: () => "Phil"
177
+ };
178
+ const age = customer.age();
179
+ const weight = customer.weight();
180
+ const initial = customer.initial();
181
+ const name = customer.name();
182
+ expect({
183
+ age,
184
+ weight,
185
+ initial,
186
+ name
187
+ }).toEqual({
188
+ age: 62,
189
+ weight: 81.5,
190
+ initial: "P",
191
+ name: "Phil"
192
+ });
193
+ });
194
+ test("derives the field value type", () => {
195
+ const integer = 1;
196
+ const float = 1.5;
197
+ const character = "A";
198
+ const string = "Fred";
199
+ expect([
200
+ integer,
201
+ float,
202
+ character,
203
+ string
204
+ ]).toEqual([
205
+ 1,
206
+ 1.5,
207
+ "A",
208
+ "Fred"
209
+ ]);
210
+ });
211
+ test("canonical type requires every path", () => {
212
+ const projection = {
213
+ age: {
214
+ type: "integer"
215
+ },
216
+ name: {
217
+ type: "string",
218
+ path: [
219
+ "customer",
220
+ "name"
221
+ ]
222
+ }
223
+ };
224
+ const canonical = {
225
+ age: {
226
+ type: "integer",
227
+ path: [
228
+ "age"
229
+ ]
230
+ },
231
+ name: {
232
+ type: "string",
233
+ path: [
234
+ "customer",
235
+ "name"
236
+ ]
237
+ }
238
+ };
239
+ expect(canonical.age.path).toEqual([
240
+ "age"
241
+ ]);
242
+ });
243
+ });
244
+ describe("defineProjection", () => {
245
+ test("makes omitted paths canonical using the projection field name", () => {
246
+ const projection = (0, create_projection_1.defineProjection)({
247
+ id: {
248
+ type: "integer"
249
+ },
250
+ age: {
251
+ type: "integer"
252
+ },
253
+ name: {
254
+ type: "string"
255
+ },
256
+ initial: {
257
+ type: "character"
258
+ },
259
+ balance: {
260
+ type: "float"
261
+ }
262
+ });
263
+ expect(projection).toEqual({
264
+ id: {
265
+ type: "integer",
266
+ path: [
267
+ "id"
268
+ ]
269
+ },
270
+ age: {
271
+ type: "integer",
272
+ path: [
273
+ "age"
274
+ ]
275
+ },
276
+ name: {
277
+ type: "string",
278
+ path: [
279
+ "name"
280
+ ]
281
+ },
282
+ initial: {
283
+ type: "character",
284
+ path: [
285
+ "initial"
286
+ ]
287
+ },
288
+ balance: {
289
+ type: "float",
290
+ path: [
291
+ "balance"
292
+ ]
293
+ }
294
+ });
295
+ });
296
+ test("preserves an explicitly supplied path", () => {
297
+ const path = [
298
+ "order",
299
+ "customer",
300
+ "name"
301
+ ];
302
+ const projection = (0, create_projection_1.defineProjection)({
303
+ name: {
304
+ type: "string",
305
+ path
306
+ }
307
+ });
308
+ expect(projection.name).toEqual({
309
+ type: "string",
310
+ path
311
+ });
312
+ expect(projection.name.path).toBe(path);
313
+ });
314
+ test("preserves an explicitly empty path", () => {
315
+ const path = [];
316
+ const projection = (0, create_projection_1.defineProjection)({
317
+ name: {
318
+ type: "string",
319
+ path
320
+ }
321
+ });
322
+ expect(projection.name.path).toBe(path);
323
+ });
324
+ test("does not modify the authoring definition", () => {
325
+ const definition = {
326
+ age: {
327
+ type: "integer"
328
+ }
329
+ };
330
+ const projection = (0, create_projection_1.defineProjection)(definition);
331
+ expect(definition).toEqual({
332
+ age: {
333
+ type: "integer"
334
+ }
335
+ });
336
+ expect(projection.age).not.toBe(definition.age);
337
+ });
338
+ });
339
+ //# sourceMappingURL=projection.definition.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.definition.spec.js","sourceRoot":"","sources":["../../src/projection.definition.spec.ts"],"names":[],"mappings":";;AAAA,mEAGiC;AAOjC,2DAAqD;AAGrD,QAAQ,CACJ,qBAAqB,EACrB,GAAG,EAAE;IAED,IAAI,CACA,yCAAyC,EACzC,GAAG,EAAE;QAED,MAAM,UAAU,GAAG;YACf,GAAG,EAAE;gBACD,IAAI,EACA,SAAS;aAChB;YAED,IAAI,EAAE;gBACF,IAAI,EACA,QAAQ;aACf;SACK,CAAC;QAGX,MAAM,CACF,IAAA,2CAAmB,EACf,UAAU,CACb,CACJ,CAAC,OAAO,CACL;YACI,GAAG,EAAE;gBACD,IAAI,EACA,SAAS;gBAEb,IAAI,EAAE;oBACF,KAAK;iBACR;aACJ;YAED,IAAI,EAAE;gBACF,IAAI,EACA,QAAQ;gBAEZ,IAAI,EAAE;oBACF,MAAM;iBACT;aACJ;SACJ,CACJ,CAAC;IACN,CAAC,CACJ,CAAC;IAGF,IAAI,CACA,uCAAuC,EACvC,GAAG,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,EAAE;gBACD,IAAI,EACA,SAAS;aAChB;SACJ,CACJ,CAAC;QAGF,MAAM,CACF,UAAU,CAAC,GAAG,CACjB,CAAC,GAAG,CAAC,IAAI,CACN,UAAU,CAAC,GAAG,CACjB,CAAC;IACN,CAAC,CACJ,CAAC;AACN,CAAC,CACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { utf8RangeToString } from "@cobol-ts/cursor-loader-types";
2
+ type Representation = Readonly<Record<string, unknown>>;
3
+ export interface Customer {
4
+ id(): number;
5
+ age(): number;
6
+ name(): string;
7
+ initial(): string;
8
+ balance(): number;
9
+ }
10
+ export interface OrderSummary {
11
+ orderId(): number;
12
+ customerName(): string;
13
+ total(): number;
14
+ }
15
+ export declare const customerProjection: import("@cobol-ts/cursor-loader-types").CanonicalProjection<import("@cobol-ts/cursor-loader-types").ProjectionDefinition<Customer>>;
16
+ export declare const orderSummaryProjection: import("@cobol-ts/cursor-loader-types").CanonicalProjection<import("@cobol-ts/cursor-loader-types").ProjectionDefinition<OrderSummary>>;
17
+ export declare const fakeParser: {
18
+ compileProjectionPath(_details: undefined, _context: import("@cobol-ts/cursor-loader-types").PhysicalRecordContext | undefined, path: readonly string[]): readonly string[];
19
+ integer(representation: Representation, _details: undefined, path: readonly string[]): number;
20
+ float(representation: Representation, _details: undefined, path: readonly string[]): number;
21
+ character(representation: Representation, _details: undefined, path: readonly string[]): string;
22
+ string(representation: Representation, _details: undefined, path: readonly string[]): string;
23
+ toDebugString: typeof utf8RangeToString;
24
+ };
25
+ export {};
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fakeParser = exports.orderSummaryProjection = exports.customerProjection = void 0;
4
+ const cursor_loader_types_1 = require("@cobol-ts/cursor-loader-types");
5
+ const create_projection_1 = require("./create.projection");
6
+ exports.customerProjection = (0, create_projection_1.defineProjection)({
7
+ id: {
8
+ type: "integer"
9
+ },
10
+ age: {
11
+ type: "integer"
12
+ },
13
+ name: {
14
+ type: "string"
15
+ },
16
+ initial: {
17
+ type: "character"
18
+ },
19
+ balance: {
20
+ type: "float"
21
+ }
22
+ });
23
+ exports.orderSummaryProjection = (0, create_projection_1.defineProjection)({
24
+ orderId: {
25
+ type: "integer",
26
+ path: [
27
+ "order",
28
+ "id"
29
+ ]
30
+ },
31
+ customerName: {
32
+ type: "string",
33
+ path: [
34
+ "order",
35
+ "customer",
36
+ "name"
37
+ ]
38
+ },
39
+ total: {
40
+ type: "float",
41
+ path: [
42
+ "order",
43
+ "total"
44
+ ]
45
+ }
46
+ });
47
+ exports.fakeParser = {
48
+ compileProjectionPath(_details, _context, path) {
49
+ return path;
50
+ },
51
+ integer(representation, _details, path) {
52
+ const value = valueAtPath(representation, path);
53
+ if (typeof value !== "number"
54
+ || !Number.isInteger(value)) {
55
+ throw new Error(`Expected integer at ${path.join(".")}`);
56
+ }
57
+ return value;
58
+ },
59
+ float(representation, _details, path) {
60
+ const value = valueAtPath(representation, path);
61
+ if (typeof value !== "number") {
62
+ throw new Error(`Expected float at ${path.join(".")}`);
63
+ }
64
+ return value;
65
+ },
66
+ character(representation, _details, path) {
67
+ const value = valueAtPath(representation, path);
68
+ if (typeof value !== "string"
69
+ || value.length !== 1) {
70
+ throw new Error(`Expected character at ${path.join(".")}`);
71
+ }
72
+ return value;
73
+ },
74
+ string(representation, _details, path) {
75
+ const value = valueAtPath(representation, path);
76
+ if (typeof value !== "string") {
77
+ throw new Error(`Expected string at ${path.join(".")}`);
78
+ }
79
+ return value;
80
+ },
81
+ toDebugString: cursor_loader_types_1.utf8RangeToString
82
+ };
83
+ function valueAtPath(representation, path) {
84
+ let value = representation;
85
+ for (const part of path) {
86
+ if (typeof value !== "object"
87
+ || value === null
88
+ || Array.isArray(value)) {
89
+ return undefined;
90
+ }
91
+ value =
92
+ value[part];
93
+ }
94
+ return value;
95
+ }
96
+ //# sourceMappingURL=projection.fixture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.fixture.js","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AED,KAAK;YAEG,KACH,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cobol-ts/cursor-projection",
3
3
  "description": "Defines declarative projections and projection support contracts for byte-backed cursor representations",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "main": "dist/index",
6
6
  "types": "dist/index",
7
7
  "browserslist": {
@@ -17,9 +17,9 @@
17
17
  ]
18
18
  },
19
19
  "dependencies": {
20
- "@cobol-ts/cursor-loader-types": "0.0.2",
21
- "@cobol-ts/arrays": "0.0.2",
22
- "@cobol-ts/metrics": "0.0.2"
20
+ "@cobol-ts/cursor-loader-types": "0.0.4",
21
+ "@cobol-ts/arrays": "0.0.4",
22
+ "@cobol-ts/metrics": "0.0.4"
23
23
  },
24
24
  "devDependencies": {
25
25
  "typescript": "^5.2.2",
@@ -49,7 +49,8 @@
49
49
  "dist/index.js",
50
50
  "dist/index.d.ts",
51
51
  "dist/src/",
52
- "build/"
52
+ "build/",
53
+ "dist/**/*"
53
54
  ],
54
55
  "keywords": [
55
56
  "indexing"