electrodb 1.4.0 → 1.4.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.
package/index.test-d.ts DELETED
@@ -1,3829 +0,0 @@
1
- import {Entity, Service, WhereAttributeSymbol, UpdateEntityItem, Schema} from ".";
2
- import {expectType, expectError, expectAssignable, expectNotAssignable, expectNotType} from 'tsd';
3
- let entityWithSK = new Entity({
4
- model: {
5
- entity: "abc",
6
- service: "myservice",
7
- version: "myversion"
8
- },
9
- attributes: {
10
- attr1: {
11
- type: "string",
12
- default: "abc",
13
- get: (val) => val + 123,
14
- set: (val) => (val ?? "") + 456,
15
- validate: (val) => !!val,
16
- },
17
- attr2: {
18
- type: "string",
19
- // default: () => "sfg",
20
- // required: false,
21
- validate: (val) => val.length > 0
22
- },
23
- attr3: {
24
- type: ["123", "def", "ghi"] as const,
25
- default: "def"
26
- },
27
- attr4: {
28
- type: ["abc", "ghi"] as const,
29
- required: true
30
- },
31
- attr5: {
32
- type: "string"
33
- },
34
- attr6: {
35
- type: "number",
36
- default: () => 100,
37
- get: (val) => val + 5,
38
- set: (val) => (val ?? 0) + 5,
39
- validate: (val) => true,
40
- },
41
- attr7: {
42
- type: "any",
43
- default: () => false,
44
- get: (val) => ({key: "value"}),
45
- set: (val) => (val ?? 0) + 5,
46
- validate: (val) => true,
47
- },
48
- attr8: {
49
- type: "boolean",
50
- required: true,
51
- get: (val) => !!val,
52
- set: (val) => !!val,
53
- validate: (val) => !!val,
54
- },
55
- attr9: {
56
- type: "number"
57
- },
58
- attr10: {
59
- type: "boolean"
60
- }
61
- },
62
- indexes: {
63
- myIndex: {
64
- collection: "mycollection2",
65
- pk: {
66
- field: "pk",
67
- composite: ["attr1"]
68
- },
69
- sk: {
70
- field: "sk",
71
- composite: ["attr2"]
72
- }
73
- },
74
- myIndex2: {
75
- collection: "mycollection1",
76
- index: "gsi1",
77
- pk: {
78
- field: "gsipk1",
79
- composite: ["attr6", "attr9"]
80
- },
81
- sk: {
82
- field: "gsisk1",
83
- composite: ["attr4", "attr5"]
84
- }
85
- },
86
- myIndex3: {
87
- collection: "mycollection",
88
- index: "gsi2",
89
- pk: {
90
- field: "gsipk2",
91
- composite: ["attr5"]
92
- },
93
- sk: {
94
- field: "gsisk2",
95
- composite: ["attr4", "attr3", "attr9"]
96
- }
97
- }
98
- }
99
- });
100
-
101
- let entityWithoutSK = new Entity({
102
- model: {
103
- entity: "abc",
104
- service: "myservice",
105
- version: "myversion"
106
- },
107
- attributes: {
108
- attr1: {
109
- type: "string",
110
- // default: "abc",
111
- get: (val) => val + 123,
112
- set: (val) => (val ?? "0") + 456,
113
- validate: (val) => !!val,
114
- },
115
- attr2: {
116
- type: "string",
117
- // default: () => "sfg",
118
- // required: false,
119
- validate: (val) => val.length > 0
120
- },
121
- attr3: {
122
- type: ["123", "def", "ghi"] as const,
123
- default: "def"
124
- },
125
- attr4: {
126
- type: ["abc", "def"] as const,
127
- required: true
128
- },
129
- attr5: {
130
- type: "string"
131
- },
132
- attr6: {
133
- type: "number",
134
- default: () => 100,
135
- get: (val) => val + 5,
136
- set: (val) => (val ?? 0) + 5,
137
- validate: (val) => true,
138
- },
139
- attr7: {
140
- type: "any",
141
- default: () => false,
142
- get: (val) => ({key: "value"}),
143
- set: (val) => (val ?? 0) + 5,
144
- validate: (val) => true,
145
- },
146
- attr8: {
147
- type: "boolean",
148
- required: true,
149
- default: () => false,
150
- get: (val) => !!val,
151
- set: (val) => !!val,
152
- validate: (val) => !!val,
153
- },
154
- attr9: {
155
- type: "number"
156
- }
157
- },
158
- indexes: {
159
- myIndex: {
160
- pk: {
161
- field: "pk",
162
- composite: ["attr1"]
163
- }
164
- },
165
- myIndex2: {
166
- index: "gsi1",
167
- collection: "mycollection1",
168
- pk: {
169
- field: "gsipk1",
170
- composite: ["attr6", "attr9"]
171
- },
172
- sk: {
173
- field: "gsisk1",
174
- composite: []
175
- }
176
- },
177
- myIndex3: {
178
- collection: "mycollection",
179
- index: "gsi2",
180
- pk: {
181
- field: "gsipk2",
182
- composite: ["attr5"]
183
- },
184
- sk: {
185
- field: "gsisk2",
186
- composite: []
187
- }
188
- }
189
- }
190
- });
191
-
192
- let standAloneEntity = new Entity({
193
- model: {
194
- entity: "standalone",
195
- service: "myservice",
196
- version: "1"
197
- },
198
- attributes: {
199
- prop1: {
200
- type: "string",
201
- default: "abc"
202
- },
203
- prop2: {
204
- type: "string"
205
- },
206
- prop3: {
207
- type: "string"
208
- }
209
- },
210
- indexes: {
211
- index1: {
212
- pk: {
213
- field: "pk",
214
- composite: ["prop1", "prop2"]
215
- },
216
- sk: {
217
- field: "sk",
218
- composite: ["prop3"]
219
- }
220
- }
221
- }
222
- });
223
-
224
- let normalEntity1 = new Entity({
225
- model: {
226
- entity: "normalEntity1",
227
- service: "myservice",
228
- version: "1"
229
- },
230
- attributes: {
231
- prop1: {
232
- type: "string",
233
- default: "abc"
234
- },
235
- prop2: {
236
- type: "string"
237
- },
238
- prop3: {
239
- type: "string",
240
- required: true
241
- },
242
- prop4: {
243
- type: "number"
244
- },
245
- prop10: {
246
- type: "boolean"
247
- }
248
- },
249
- indexes: {
250
- tableIndex: {
251
- collection: "normalcollection",
252
- pk: {
253
- field: "pk",
254
- composite: ["prop1", "prop2"]
255
- },
256
- sk: {
257
- field: "sk",
258
- composite: ["prop4"]
259
- }
260
- }
261
- }
262
- });
263
-
264
- let normalEntity2 = new Entity({
265
- model: {
266
- entity: "normalEntity2",
267
- service: "myservice",
268
- version: "1"
269
- },
270
- attributes: {
271
- prop1: {
272
- type: "string"
273
- },
274
- prop2: {
275
- type: "string"
276
- },
277
- prop3: {
278
- type: "string",
279
- required: true
280
- },
281
- prop5: {
282
- type: "number"
283
- },
284
- attr6: {
285
- type: "number",
286
- default: () => 100,
287
- get: (val) => val + 5,
288
- set: (val) => (val ?? 0) + 5,
289
- validate: (val) => true,
290
- },
291
- attr9: {
292
- type: "number"
293
- },
294
- },
295
- indexes: {
296
- indexTable: {
297
- collection: "normalcollection",
298
- pk: {
299
- field: "pk",
300
- composite: ["prop1", "prop2"]
301
- },
302
- sk: {
303
- field: "sk",
304
- composite: ["prop5"]
305
- }
306
- },
307
- anotherIndex: {
308
- index: "gsi1",
309
- collection: "mycollection1",
310
- pk: {
311
- field: "gsipk1",
312
- composite: ["attr6", "attr9"]
313
- },
314
- sk: {
315
- field: "gsisk1",
316
- composite: []
317
- }
318
- }
319
- }
320
- });
321
-
322
- type Item = {
323
- attr1?: string;
324
- attr2: string;
325
- attr3?: "123" | "def" | "ghi" | undefined;
326
- attr4: string;
327
- attr5?: string;
328
- attr6?: number;
329
- attr7?: any;
330
- attr8: boolean;
331
- attr9?: number;
332
- attr10?: boolean;
333
- }
334
-
335
- type ItemWithoutSK = {
336
- attr1?: string;
337
- attr2?: string;
338
- attr3?: "123" | "def" | "ghi" | undefined;
339
- attr4: string;
340
- attr5?: string;
341
- attr6?: number;
342
- attr7?: any;
343
- attr8: boolean;
344
- attr9?: number;
345
- }
346
-
347
- const item: Item = {
348
- attr1: "attr1",
349
- attr2: "attr2",
350
- attr3: "def",
351
- attr4: "attr4",
352
- attr5: "attr5",
353
- attr6: 123,
354
- attr7: "attr7",
355
- attr8: true,
356
- attr9: 456
357
- } as const
358
-
359
- type AttributeNames = "attr1" | "attr2" | "attr3" | "attr4" | "attr5" | "attr6" | "attr7" | "attr8" | "attr9";
360
- const AttributeName = "" as AttributeNames;
361
- type OperationNames = "eq" | "ne" | "gt" | "lt" | "gte" | "lte" | "between" | "begins" | "exists" | "notExists" | "contains" | "notContains" | "value" | "name";
362
-
363
-
364
- type WithSKMyIndexCompositeAttributes = {
365
- attr1: string;
366
- attr2: string;
367
- }
368
-
369
- type WithSKMyIndex2CompositeAttributes = {
370
- attr6: string;
371
- attr4?: string;
372
- attr5?: string;
373
- }
374
-
375
- type WithSKMyIndex3CompositeAttributes = {
376
- attr5: string;
377
- attr3?: "123" | "def" | "ghi";
378
- attr4?: string;
379
- attr9?: number;
380
- }
381
-
382
- type WithoutSKMyIndexCompositeAttributes = {
383
- attr1: string;
384
- }
385
-
386
- type WithoutSKMyIndex2CompositeAttributes = {
387
- attr6: number;
388
- attr9: number;
389
- }
390
-
391
- type WithoutSKMyIndex3CompositeAttributes = {
392
- attr5: string;
393
- }
394
-
395
- type Parameter<T extends (arg: any) => any> = T extends (arg: infer P) => any ? P : never;
396
-
397
- type GetKeys = <T extends {[key: string]: any}>(obj: T) => keyof T;
398
- let getKeys = ((val) => {}) as GetKeys;
399
-
400
- /** Schema With SK **/
401
- // Get
402
- // Single
403
- entityWithSK.get({attr1: "adg", attr2: "ada"});
404
- entityWithoutSK.get({attr1: "abc"});
405
-
406
- // Batch
407
- type GetBatchParametersWithSK = Parameter<typeof entityWithSK.get>;
408
- type GetBatchParametersWithoutSK = Parameter<typeof entityWithoutSK.get>;
409
- expectAssignable<GetBatchParametersWithSK>([{attr1: "abc", attr2: "abd"}]);
410
- expectAssignable<GetBatchParametersWithoutSK>([{attr1: "abc"}]);
411
-
412
- // Invalid Get
413
- expectError<GetBatchParametersWithSK>([{}]);
414
- expectError<GetBatchParametersWithSK>([{attr1: "sdggd"}]);
415
- expectError<GetBatchParametersWithSK>([{attr2: "sdggd"}]);
416
- expectError<GetBatchParametersWithSK>({attr1: 1324, attr2: "adsga"});
417
- expectError<GetBatchParametersWithoutSK>([{}]);
418
- expectError<GetBatchParametersWithoutSK>([{attr2: "adsga"}]);
419
- expectError<GetBatchParametersWithoutSK>({attr2: "adsga"});
420
- expectError<GetBatchParametersWithoutSK>({attr1: 1324, attr2: "adsga"});
421
-
422
- // Finishers
423
- type GetParametersFinishers = "go" | "params" | "where";
424
- let getSingleFinishersWithSK = getKeys(entityWithSK.get({attr1:"abc", attr2: "24"}));
425
- let getBatchFinishersWithSK = getKeys(entityWithSK.get([{attr1:"abc", attr2: "24"}]));
426
- let getSingleFinishersWithoutSK = getKeys(entityWithoutSK.get({attr1:"abc"}));
427
- let getBatchFinishersWithoutSK = getKeys(entityWithoutSK.get([{attr1:"abc"}]));
428
- expectAssignable<GetParametersFinishers>(getSingleFinishersWithSK);
429
- expectAssignable<GetParametersFinishers>(getBatchFinishersWithSK);
430
- expectAssignable<GetParametersFinishers>(getSingleFinishersWithoutSK);
431
- expectAssignable<GetParametersFinishers>(getBatchFinishersWithoutSK);
432
- entityWithSK.get([{attr1: "adg", attr2: "ada"}]).go({concurrency: 24});
433
- entityWithSK.get([{attr1: "adg", attr2: "ada"}]).params({concurrency: 24});
434
- entityWithoutSK.get([{attr1: "adg"}]).go({concurrency: 24});
435
- entityWithoutSK.get([{attr1: "adg"}]).params({concurrency: 24});
436
-
437
- let getSingleGoWithSK = entityWithSK.get({attr1: "adg", attr2: "ada"}).go;
438
- let getSingleGoWithoutSK = entityWithoutSK.get({attr1: "adg"}).go;
439
-
440
- let getSingleParamsWithSK = entityWithSK.get({attr1: "adg", attr2: "ada"}).params;
441
- let getSingleParamsWithoutSK = entityWithoutSK.get({attr1: "adg"}).params;
442
-
443
- let getBatchGoWithSK = entityWithSK.get([{attr1: "adg", attr2: "ada"}]).go;
444
- let getBatchGoWithoutSK = entityWithoutSK.get([{attr1: "adg"}]).go;
445
-
446
- let getBatchParamsWithSK = entityWithSK.get([{attr1: "adg", attr2: "ada"}]).params;
447
- let getBatchParamsWithoutSK = entityWithoutSK.get([{attr1: "adg"}]).params;
448
-
449
- type GetSingleGoParamsWithSK = Parameter<typeof getSingleGoWithSK>;
450
- type GetSingleGoParamsWithoutSK = Parameter<typeof getSingleGoWithoutSK>;
451
-
452
- type GetSingleParamsParamsWithSK = Parameter<typeof getSingleParamsWithSK>;
453
- type GetSingleParamsParamsWithoutSK = Parameter<typeof getSingleParamsWithoutSK>;
454
-
455
- type GetBatchGoParamsWithSK = Parameter<typeof getBatchGoWithSK>;
456
- type GetBatchGoParamsWithoutSK = Parameter<typeof getBatchGoWithoutSK>;
457
-
458
- type GetBatchParamsParamsWithSK = Parameter<typeof getBatchParamsWithSK>;
459
- type GetBatchParamsParamsWithoutSK = Parameter<typeof getBatchParamsWithoutSK>;
460
-
461
- expectAssignable<GetSingleGoParamsWithSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
462
- expectAssignable<GetSingleGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
463
-
464
- expectAssignable<GetSingleParamsParamsWithSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
465
- expectAssignable<GetSingleParamsParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
466
-
467
- expectError<GetSingleGoParamsWithSK>({concurrency: 10, unprocessed: "raw"});
468
- expectError<GetSingleGoParamsWithoutSK>({concurrency: 10, unprocessed: "raw"});
469
-
470
- expectError<GetSingleParamsParamsWithSK>({concurrency: 10, unprocessed: "raw"});
471
- expectError<GetSingleParamsParamsWithoutSK>({concurrency: 10, unprocessed: "raw"});
472
-
473
- expectAssignable<GetBatchGoParamsWithSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
474
- expectAssignable<GetBatchGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
475
-
476
- expectAssignable<GetBatchParamsParamsWithSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
477
- expectAssignable<GetBatchParamsParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
478
-
479
- // Results
480
- expectAssignable<Promise<Item>>(entityWithSK.get({attr1: "abc", attr2: "def"}).go());
481
- expectAssignable<Promise<ItemWithoutSK>>(entityWithoutSK.get({attr1: "abc"}).go());
482
- expectAssignable<"paramtest">(entityWithSK.get({attr1: "abc", attr2: "def"}).params<"paramtest">());
483
- expectAssignable<"paramtest">(entityWithoutSK.get({attr1: "abc"}).params<"paramtest">());
484
-
485
- expectAssignable<Promise<[WithSKMyIndexCompositeAttributes[], Item[]]>>(entityWithSK.get([{attr1: "abc", attr2: "def"}]).go());
486
- expectAssignable<Promise<[WithoutSKMyIndexCompositeAttributes[], ItemWithoutSK[]]>>(entityWithoutSK.get([{attr1: "abc"}]).go());
487
-
488
- // Delete
489
- // Single
490
- entityWithSK.delete({attr1: "adg", attr2: "ada"});
491
- entityWithoutSK.delete({attr1: "adg"});
492
-
493
- // Batch
494
- type DeleteBatchParametersWithSK = Parameter<typeof entityWithSK.delete>;
495
- type DeleteBatchParametersWithoutSK = Parameter<typeof entityWithoutSK.delete>;
496
-
497
- expectError(entityWithSK.delete({}));
498
- expectError(entityWithSK.delete({attr2: "abc"}));
499
- expectError(entityWithoutSK.delete({}));
500
- expectError(entityWithoutSK.delete({attr1: "13", attr2: "abc"}));
501
-
502
- expectAssignable<DeleteBatchParametersWithSK>([{attr1: "abc", attr2: "abd"}]);
503
- expectAssignable<DeleteBatchParametersWithoutSK>([{attr1: "abc"}]);
504
-
505
- // Invalid Query
506
- expectError<DeleteBatchParametersWithSK>({attr1: "sdggd"});
507
- expectError<DeleteBatchParametersWithoutSK>([{}]);
508
-
509
- expectError<DeleteBatchParametersWithSK>({attr1: 1324, attr2: "adsga"});
510
- expectError<DeleteBatchParametersWithoutSK>({attr1: 1324, attr2: "adsga"});
511
-
512
- // Finishers
513
- type DeleteParametersFinishers = "go" | "params" | "where";
514
-
515
- let deleteSingleFinishers = getKeys(entityWithSK.delete({attr1:"abc", attr2: "24"}));
516
- let deleteSingleFinishersWithoutSK = getKeys(entityWithoutSK.delete({attr1:"abc"}));
517
-
518
- let deleteBatchFinishers = getKeys(entityWithSK.delete([{attr1:"abc", attr2: "24"}]));
519
- let deleteBatchFinishersWithoutSK = getKeys(entityWithoutSK.delete([{attr1:"abc"}]));
520
-
521
- expectAssignable<DeleteParametersFinishers>(deleteSingleFinishers);
522
- expectAssignable<DeleteParametersFinishers>(deleteSingleFinishersWithoutSK);
523
-
524
- expectAssignable<DeleteParametersFinishers>(deleteBatchFinishers);
525
- expectAssignable<DeleteParametersFinishers>(deleteBatchFinishersWithoutSK);
526
-
527
- entityWithSK.delete([{attr1: "adg", attr2: "ada"}]).go({concurrency: 24});
528
- entityWithoutSK.delete([{attr1: "adg"}]).go({concurrency: 24});
529
-
530
- entityWithSK.delete([{attr1: "adg", attr2: "ada"}]).params({concurrency: 24});
531
- entityWithoutSK.delete([{attr1: "adg"}]).params({concurrency: 24});
532
-
533
- let deleteSingleGo = entityWithSK.delete({attr1: "adg", attr2: "ada"}).go;
534
- let deleteSingleGoWithoutSK = entityWithoutSK.delete({attr1: "adg"}).go;
535
-
536
- let deleteSingleParams = entityWithSK.delete({attr1: "adg", attr2: "ada"}).params;
537
- let deleteSingleParamsWithoutSK = entityWithoutSK.delete({attr1: "adg"}).params;
538
-
539
- let deleteBatchGo = entityWithSK.delete([{attr1: "adg", attr2: "ada"}]).go;
540
- let deleteBatchGoWithoutSK = entityWithoutSK.delete([{attr1: "adg"}]).go;
541
-
542
- let deleteBatchParams = entityWithSK.delete([{attr1: "adg", attr2: "ada"}]).params;
543
- let deleteBatchParamsWithoutSK = entityWithoutSK.delete([{attr1: "adg"}]).params;
544
-
545
- type DeleteSingleGoParams = Parameter<typeof deleteSingleGo>;
546
- type DeleteSingleGoParamsWithoutSK = Parameter<typeof deleteSingleGoWithoutSK>;
547
-
548
- type DeleteSingleParamsParams = Parameter<typeof deleteSingleParams>;
549
- type DeleteSingleParamsParamsWithoutSK = Parameter<typeof deleteSingleParamsWithoutSK>;
550
-
551
- type DeleteBatchGoParams = Parameter<typeof deleteBatchGo>;
552
- type DeleteBatchGoParamsWithoutSK = Parameter<typeof deleteBatchGoWithoutSK>;
553
-
554
- type DeleteBatchParamsParams = Parameter<typeof deleteBatchParams>;
555
- type DeleteBatchParamsParamsWithoutSK = Parameter<typeof deleteBatchParamsWithoutSK>;
556
-
557
- expectAssignable<DeleteSingleGoParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "all_old"});
558
- expectAssignable<DeleteSingleGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "all_old"});
559
-
560
- expectAssignable<DeleteSingleGoParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
561
- expectAssignable<DeleteSingleGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
562
-
563
- expectAssignable<DeleteSingleParamsParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "all_old"});
564
- expectAssignable<DeleteSingleParamsParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "all_old"});
565
-
566
- expectAssignable<DeleteSingleParamsParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
567
- expectAssignable<DeleteSingleParamsParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
568
-
569
- expectError<DeleteSingleGoParams>({concurrency: 10, unprocessed: "raw"});
570
- expectError<DeleteSingleGoParamsWithoutSK>({concurrency: 10, unprocessed: "raw"});
571
-
572
- expectNotAssignable<DeleteSingleGoParams>({response: "updated_new"});
573
- expectNotAssignable<DeleteSingleGoParamsWithoutSK>({response: "updated_new"});
574
-
575
- expectError<DeleteSingleParamsParams>({concurrency: 10, unprocessed: "raw"});
576
- expectError<DeleteSingleParamsParamsWithoutSK>({concurrency: 10, unprocessed: "raw"});
577
-
578
- expectNotAssignable<DeleteSingleParamsParams>({response: "updated_new"});
579
- expectNotAssignable<DeleteSingleParamsParamsWithoutSK>({response: "updated_new"});
580
-
581
- expectAssignable<DeleteBatchGoParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
582
- expectAssignable<DeleteBatchGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
583
-
584
- expectAssignable<DeleteBatchParamsParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
585
- expectAssignable<DeleteBatchParamsParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
586
-
587
- // Where
588
- entityWithSK.delete({attr1: "asbc", attr2: "gdd"}).where((attr, op) => {
589
- let opKeys = getKeys(op);
590
- expectAssignable<keyof typeof attr>(AttributeName);
591
- expectAssignable<OperationNames>(opKeys);
592
- return "";
593
- });
594
-
595
- entityWithoutSK.delete({attr1: "asbc"}).where((attr, op) => {
596
- let opKeys = getKeys(op);
597
- expectAssignable<keyof typeof attr>(AttributeName);
598
- expectAssignable<OperationNames>(opKeys);
599
- return "";
600
- });
601
-
602
- // Results
603
- expectAssignable<Promise<Item>>(entityWithSK.delete({attr1: "abc", attr2: "def"}).go({response: "all_old"}));
604
- expectAssignable<Promise<ItemWithoutSK>>(entityWithoutSK.delete({attr1: "abc"}).go({response: "all_old"}));
605
-
606
- expectAssignable<"paramtest">(entityWithSK.delete({attr1: "abc", attr2: "def"}).params<"paramtest">());
607
- expectAssignable<"paramtest">(entityWithoutSK.delete({attr1: "abc"}).params<"paramtest">());
608
-
609
- expectAssignable<Promise<WithoutSKMyIndexCompositeAttributes[]>>(entityWithoutSK.delete([{attr1: "abc"}]).go());
610
-
611
- // Put
612
- let putItemFull = {attr1: "abnc", attr2: "dsg", attr3: "def", attr4: "abc", attr5: "dbs", attr6: 13, attr7: {abc: "2345"}, attr8: true, attr9: 24, attr10: true} as const;
613
- let putItemPartial = {attr1: "abnc", attr2: "dsg", attr4: "abc", attr8: true} as const;
614
- let putItemWithoutSK = {attr1: "abnc", attr4: "abc", attr8: true, attr3: "def", attr5: "dbs", attr6: 13, attr9: 24, attr7: {abc: "2345"}} as const;
615
- let putItemWithoutPK = {attr4: "abc", attr2: "def", attr8: true, attr3: "def", attr5: "dbs", attr6: 13, attr9: 24, attr7: {abc: "2345"}} as const;
616
- // Single
617
- entityWithSK.put(putItemFull);
618
- entityWithoutSK.put({attr1: "abnc", attr2: "dsg", attr3: "def", attr4: "def", attr5: "dbs", attr6: 13, attr7: {abc: "2345"}, attr8: true, attr9: 24});
619
-
620
- entityWithSK.put({attr1: "abnc", attr2: "dsg", attr3: "def", attr4: "abc", attr5: "dbs", attr6: 13, attr7: {abc: "2345"}, attr8: true, attr9: undefined, attr10: undefined});
621
- entityWithoutSK.put(putItemPartial);
622
-
623
- // Batch
624
- type PutParametersWithSK = Parameter<typeof entityWithSK.put>;
625
- type PutParametersWithoutSK = Parameter<typeof entityWithoutSK.put>;
626
-
627
- expectAssignable<PutParametersWithSK>([putItemFull]);
628
- expectAssignable<PutParametersWithoutSK>([putItemFull]);
629
-
630
- expectAssignable<PutParametersWithSK>([putItemPartial]);
631
- expectAssignable<PutParametersWithoutSK>([putItemPartial]);
632
-
633
- // Invalid Query
634
- expectError<PutParametersWithSK>([{}]);
635
- expectError<PutParametersWithoutSK>([{}]);
636
-
637
- expectError<PutParametersWithSK>([putItemWithoutSK]);
638
-
639
- expectError<PutParametersWithSK>(putItemWithoutSK);
640
-
641
- expectError<PutParametersWithSK>(putItemWithoutPK);
642
- expectError<PutParametersWithoutSK>(putItemWithoutPK);
643
-
644
- // Assignable because attr1 has a default
645
- expectAssignable<PutParametersWithSK>([putItemWithoutPK]);
646
-
647
- expectError<PutParametersWithoutSK>([putItemWithoutPK]);
648
-
649
- expectError<PutParametersWithSK>([{attr1: "abnc", attr2: "dsg", attr4: "abc", attr8: "adef"}]);
650
- expectError<PutParametersWithoutSK>([{attr1: "abnc", attr2: "dsg", attr4: "abc", attr8: "adef"}]);
651
-
652
- // Finishers
653
- type PutSingleFinishers = "go" | "params" | "where";
654
- type PutBatchFinishers = "go" | "params" | "where" | "page";
655
-
656
- let putSingleFinishers = getKeys(entityWithSK.put(putItemFull));
657
- let putSingleFinishersWithoutSK = getKeys(entityWithoutSK.put(putItemFull));
658
-
659
- let putBatchFinishers = getKeys(entityWithSK.put(putItemFull));
660
- let putBatchFinishersWithoutSK = getKeys(entityWithoutSK.put(putItemFull));
661
-
662
- let putSingleItem = entityWithSK.put(putItemFull);
663
- let putSingleItemWithoutSK = entityWithoutSK.put(putItemFull);
664
-
665
- let putBulkItem = entityWithSK.put([putItemFull]);
666
- let putBulkItemWithoutSK = entityWithoutSK.put([putItemFull]);
667
-
668
- expectAssignable<PutSingleFinishers>(putSingleFinishers);
669
- expectAssignable<PutSingleFinishers>(putSingleFinishersWithoutSK);
670
-
671
- expectAssignable<PutBatchFinishers>(putBatchFinishers);
672
- expectAssignable<PutBatchFinishers>(putBatchFinishersWithoutSK);
673
-
674
- type PutSingleGoParams = Parameter<typeof putSingleItem.go>;
675
- type PutSingleGoParamsWithoutSK = Parameter<typeof putSingleItemWithoutSK.go>;
676
-
677
- type PutSingleParamsParams = Parameter<typeof putSingleItem.params>;
678
- type PutSingleParamsParamsWithoutSK = Parameter<typeof putSingleItemWithoutSK.params>;
679
-
680
- type PutBatchGoParams = Parameter<typeof putBulkItem.go>;
681
- type PutBatchGoParamsWithoutSK = Parameter<typeof putBulkItemWithoutSK.go>;
682
-
683
- type PutBatchParamsParams = Parameter<typeof putBulkItem.params>;
684
- type PutBatchParamsParamsWithoutSK = Parameter<typeof putBulkItemWithoutSK.params>;
685
-
686
- expectAssignable<PutSingleGoParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "all_old"});
687
- expectAssignable<PutSingleGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "all_old"});
688
-
689
- expectAssignable<PutSingleParamsParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "all_old"});
690
- expectAssignable<PutSingleParamsParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "all_old"});
691
-
692
- expectError<PutSingleGoParams>({concurrency: 10, unprocessed: "raw"});
693
- expectError<PutSingleGoParamsWithoutSK>({concurrency: 10, unprocessed: "raw"});
694
-
695
- expectError<PutSingleGoParams>({response: "updated_new"});
696
- expectError<PutSingleGoParamsWithoutSK>({response: "updated_new"});
697
-
698
- expectError<PutSingleParamsParams>({response: "updated_new"});
699
- expectError<PutSingleParamsParamsWithoutSK>({response: "updated_new"});
700
-
701
- expectError<PutSingleParamsParams>({concurrency: 10, unprocessed: "raw"});
702
- expectError<PutSingleParamsParamsWithoutSK>({concurrency: 10, unprocessed: "raw"});
703
-
704
- expectAssignable<PutBatchGoParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
705
- expectAssignable<PutBatchGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
706
-
707
- expectNotAssignable<PutBatchGoParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw", response: "all_old"});
708
- expectNotAssignable<PutBatchGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw", response: "all_old"});
709
-
710
- expectAssignable<PutBatchParamsParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
711
- expectAssignable<PutBatchParamsParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw"});
712
-
713
- expectNotAssignable<PutBatchParamsParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw", response: "all_old"});
714
- expectNotAssignable<PutBatchParamsParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", concurrency: 10, unprocessed: "raw", response: "all_old"});
715
-
716
- // Where
717
- entityWithSK.put(putItemFull).where((attr, op) => {
718
- let opKeys = getKeys(op);
719
- expectAssignable<keyof typeof attr>(AttributeName);
720
- expectAssignable<OperationNames>(opKeys);
721
- return "";
722
- });
723
-
724
- entityWithoutSK.put(putItemFull).where((attr, op) => {
725
- let opKeys = getKeys(op);
726
- expectAssignable<keyof typeof attr>(AttributeName);
727
- expectAssignable<OperationNames>(opKeys);
728
- return "";
729
- });
730
-
731
- // Results
732
- expectAssignable<Promise<Item>>(entityWithSK.put(putItemFull).go());
733
- expectAssignable<Promise<ItemWithoutSK>>(entityWithoutSK.put(putItemFull).go());
734
-
735
- expectAssignable<"paramtest">(entityWithSK.put(putItemFull).params<"paramtest">());
736
- expectAssignable<"paramtest">(entityWithoutSK.put(putItemFull).params<"paramtest">());
737
-
738
- expectAssignable<Promise<WithSKMyIndexCompositeAttributes[]>>(entityWithSK.put([putItemFull]).go());
739
- expectAssignable<Promise<WithoutSKMyIndexCompositeAttributes[]>>(entityWithoutSK.put([putItemFull]).go());
740
-
741
- // Create
742
- let createItemFull = {attr1: "abnc", attr2: "dsg", attr4: "abc", attr8: true, attr3: "def", attr5: "dbs", attr6: 13, attr9: 24, attr7: {abc: "2345"}} as const;
743
- let createItemPartial = {attr1: "abnc", attr2: "dsg", attr4: "abc", attr8: true} as const;
744
- let createItemFullWithoutSK = {attr4: "abc", attr8: true, attr3: "def", attr5: "dbs", attr6: 13, attr9: 24, attr7: {abc: "2345"}} as const;
745
- let createItemFullWithoutPK = {attr2: "dsg", attr4: "abc", attr8: true, attr3: "def", attr5: "dbs", attr6: 13, attr9: 24, attr7: {abc: "2345"}} as const;
746
-
747
- // Single
748
- entityWithSK.create(createItemFull);
749
- entityWithSK.create(createItemFullWithoutPK);
750
- entityWithoutSK.create(createItemFull);
751
-
752
- entityWithSK.create(createItemPartial);
753
- entityWithoutSK.create(createItemPartial);
754
-
755
- // Batch
756
- type CreateParametersWithSK = Parameter<typeof entityWithSK.create>;
757
- type CreateParametersWithoutSK = Parameter<typeof entityWithoutSK.create>;
758
-
759
- // batch not supported with create
760
- expectError<CreateParametersWithSK>([createItemFull]);
761
- expectError<CreateParametersWithoutSK>([createItemFull]);
762
-
763
- // batch not supported with create
764
- expectError<CreateParametersWithSK>([createItemPartial]);
765
- expectError<CreateParametersWithoutSK>([createItemPartial]);
766
-
767
- // Invalid Query
768
- expectError<CreateParametersWithSK>({});
769
- expectError<CreateParametersWithoutSK>({});
770
-
771
- expectError<CreateParametersWithSK>(createItemFullWithoutSK);
772
-
773
- // Assignable because attr1 has a default value
774
- expectAssignable<CreateParametersWithSK>(createItemFullWithoutPK);
775
-
776
- expectError<CreateParametersWithoutSK>(createItemFullWithoutPK);
777
-
778
- // Missing required properties
779
- expectError<CreateParametersWithSK>([{attr1: "abnc", attr2: "dsg", attr4: "abc", attr8: "adef"}]);
780
- expectError<CreateParametersWithoutSK>([{attr1: "abnc", attr2: "dsg", attr4: "abc", attr8: "adef"}]);
781
-
782
- // Finishers
783
- type CreateSingleFinishers = "go" | "params" | "where";
784
-
785
- let createSingleFinishers = getKeys(entityWithSK.create(putItemFull));
786
- let createSingleFinishersWithoutSK = getKeys(entityWithoutSK.create(putItemFull));
787
-
788
- let createItem = entityWithSK.put(createItemFull);
789
- let createItemWithoutSK = entityWithoutSK.put(createItemFull);
790
-
791
- expectAssignable<CreateSingleFinishers>(createSingleFinishers);
792
- expectAssignable<CreateSingleFinishers>(createSingleFinishersWithoutSK);
793
-
794
- type CreateGoParams = Parameter<typeof createItem.go>;
795
- type CreateGoParamsWithoutSK = Parameter<typeof createItemWithoutSK.go>;
796
-
797
- type CreateParamsParams = Parameter<typeof createItem.params>;
798
- type CreateParamsParamsWithoutSK = Parameter<typeof createItemWithoutSK.params>;
799
-
800
- expectAssignable<CreateGoParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
801
- expectAssignable<CreateGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
802
-
803
- expectAssignable<CreateParamsParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
804
- expectAssignable<CreateParamsParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
805
-
806
- expectError<CreateGoParams>({concurrency: 10, unprocessed: "raw"});
807
- expectError<CreateGoParamsWithoutSK>({concurrency: 10, unprocessed: "raw"});
808
-
809
- expectError<CreateParamsParams>({concurrency: 10, unprocessed: "raw"});
810
- expectError<CreateParamsParamsWithoutSK>({concurrency: 10, unprocessed: "raw"});
811
-
812
- // Where
813
- entityWithSK.create(putItemFull).where((attr, op) => {
814
- let opKeys = getKeys(op);
815
- expectAssignable<keyof typeof attr>(AttributeName);
816
- expectAssignable<OperationNames>(opKeys);
817
- return "";
818
- });
819
- entityWithoutSK.create(putItemFull).where((attr, op) => {
820
- let opKeys = getKeys(op);
821
- expectAssignable<keyof typeof attr>(AttributeName);
822
- expectAssignable<OperationNames>(opKeys);
823
- return "";
824
- });
825
-
826
- // Results
827
- expectAssignable<Promise<Item>>(entityWithSK.create(putItemFull).go());
828
- expectAssignable<Promise<ItemWithoutSK>>(entityWithoutSK.create(putItemFull).go());
829
-
830
- expectAssignable<"paramtest">(entityWithSK.create(putItemFull).params<"paramtest">());
831
- expectAssignable<"paramtest">(entityWithoutSK.create(putItemFull).params<"paramtest">());
832
-
833
- // Update
834
- let setItemFull = {attr4: "abc", attr8: true, attr3: "def", attr5: "dbs", attr6: 13, attr9: 24, attr7: {abc: "2345"}} as const;
835
-
836
- let setFn = entityWithSK.update({attr1: "abc", attr2: "def"}).set;
837
- let setFnWithoutSK = entityWithoutSK.update({attr1: "abc"}).set;
838
-
839
- type SetParameters = Parameter<typeof setFn>;
840
- type SetParametersWithoutSK = Parameter<typeof setFnWithoutSK>;
841
-
842
- expectAssignable<SetParameters>(setItemFull);
843
- expectAssignable<SetParametersWithoutSK>(setItemFull);
844
-
845
- expectAssignable<SetParameters>({});
846
- expectAssignable<SetParametersWithoutSK>({});
847
-
848
- // Invalid Set
849
- expectError<SetParameters>({attr1: "ff"});
850
- expectError<SetParametersWithoutSK>({attr1: "ff"});
851
-
852
- expectError<SetParameters>({attr6: "1234"});
853
- expectError<SetParametersWithoutSK>({attr6: "1234"});
854
-
855
- // Finishers
856
- type UpdateParametersFinishers = "set" | "delete" | "remove" | "go" | "params" | "where" | "add" | "subtract" | "append" | "data";
857
-
858
- let updateItem = entityWithSK.update({attr1: "abc", attr2: "def"}).set({});
859
- let updateItemWithoutSK = entityWithoutSK.update({attr1: "abc"}).set({});
860
-
861
- let updateFinishers = getKeys(updateItem);
862
- let updateFinishersWithoutSK = getKeys(updateItemWithoutSK);
863
-
864
- expectAssignable<UpdateParametersFinishers>(updateFinishers);
865
- expectAssignable<UpdateParametersFinishers>(updateFinishersWithoutSK);
866
-
867
- let updateGo = updateItem.go;
868
- let updateGoWithoutSK = updateItemWithoutSK.go;
869
-
870
- let updateParams = updateItem.params;
871
- let updateParamsWithoutSK = updateItemWithoutSK.params;
872
-
873
- type UpdateGoParams = Parameter<typeof updateGo>;
874
- type UpdateGoParamsWithoutSK = Parameter<typeof updateGoWithoutSK>;
875
-
876
- type UpdateParamsParams = Parameter<typeof updateParams>;
877
- type UpdateParamsParamsWithoutSK = Parameter<typeof updateParamsWithoutSK>;
878
-
879
-
880
- expectAssignable<UpdateGoParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "updated_new"});
881
- expectAssignable<UpdateGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "updated_new"});
882
-
883
- expectAssignable<UpdateParamsParams>({params: {}, table: "abc", response: "updated_new"});
884
- expectAssignable<UpdateParamsParamsWithoutSK>({params: {}, table: "abc", response: "updated_new"});
885
-
886
- // Where
887
- updateItem.where((attr, op) => {
888
- let opKeys = getKeys(op);
889
- expectAssignable<keyof typeof attr>(AttributeName);
890
- expectAssignable<OperationNames>(opKeys);
891
- return "";
892
- });
893
- updateItemWithoutSK.where((attr, op) => {
894
- let opKeys = getKeys(op);
895
- expectAssignable<keyof typeof attr>(AttributeName);
896
- expectAssignable<OperationNames>(opKeys);
897
- return "";
898
- });
899
-
900
- // Patch
901
- let patchItemFull = {attr4: "abc", attr8: true, attr3: "def", attr5: "dbs", attr6: 13, attr9: 24, attr7: {abc: "2345"}} as const;
902
-
903
- let patchFn = entityWithSK.patch({attr1: "abc", attr2: "def"}).set;
904
- let patchFnWithoutSK = entityWithoutSK.patch({attr1: "abc"}).set;
905
-
906
- type PatchParameters = Parameter<typeof patchFn>;
907
- type PatchParametersWithoutSK = Parameter<typeof patchFnWithoutSK>;
908
-
909
- expectAssignable<PatchParameters>(patchItemFull);
910
- expectAssignable<PatchParametersWithoutSK>(patchItemFull);
911
-
912
- expectAssignable<PatchParameters>({});
913
- expectAssignable<PatchParametersWithoutSK>({});
914
-
915
- // Invalid Set
916
- expectError<PatchParameters>({attr1: "ff"});
917
- expectError<PatchParametersWithoutSK>({attr1: "ff"});
918
-
919
- expectError<PatchParameters>({attr6: "1234"});
920
- expectError<PatchParametersWithoutSK>({attr6: "1234"});
921
-
922
- // Finishers
923
- type PatchParametersFinishers = "set" | "delete" | "remove" | "go" | "params" | "where" | "add" | "subtract" | "append" | "data";
924
-
925
- let patchItem = entityWithSK.patch({attr1: "abc", attr2: "def"}).set({});
926
- let patchItemWithoutSK = entityWithoutSK.patch({attr1: "abc"}).set({});
927
-
928
- let patchFinishers = getKeys(patchItem);
929
- let patchFinishersWithoutSK = getKeys(patchItemWithoutSK);
930
-
931
- expectAssignable<PatchParametersFinishers>(patchFinishers);
932
- expectAssignable<PatchParametersFinishers>(patchFinishersWithoutSK);
933
-
934
- let patchGo = patchItem.go;
935
- let patchGoWithoutSK = patchItemWithoutSK.go;
936
-
937
- let patchParams = patchItem.params;
938
- let patchParamsWithoutSK = patchItemWithoutSK.params;
939
-
940
- type PatchGoParams = Parameter<typeof patchGo>;
941
- type PatchGoParamsWithoutSK = Parameter<typeof patchGoWithoutSK>;
942
-
943
- type PatchParamsParams = Parameter<typeof patchParams>;
944
- type PatchParamsParamsWithoutSK = Parameter<typeof patchParamsWithoutSK>;
945
-
946
- expectAssignable<PatchGoParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "updated_new"});
947
- expectAssignable<PatchGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc", response: "updated_new"});
948
-
949
- expectAssignable<PatchParamsParams>({params: {}, table: "abc", response: "updated_new"});
950
- expectAssignable<PatchParamsParamsWithoutSK>({params: {}, table: "abc", response: "updated_new"});
951
-
952
- // Where
953
- patchItem.where((attr, op) => {
954
- let opKeys = getKeys(op);
955
- expectAssignable<keyof typeof attr>(AttributeName);
956
- expectAssignable<OperationNames>(opKeys);
957
- return "";
958
- });
959
- patchItemWithoutSK.where((attr, op) => {
960
- let opKeys = getKeys(op);
961
- expectAssignable<keyof typeof attr>(AttributeName);
962
- expectAssignable<OperationNames>(opKeys);
963
- return "";
964
- });
965
-
966
- // Find
967
- // Query
968
- let findFn = entityWithSK.find;
969
- let findFnWithoutSK = entityWithoutSK.find;
970
-
971
- type FindParameters = Parameter<typeof findFn>;
972
- type FindParametersWithoutSK = Parameter<typeof findFnWithoutSK>;
973
-
974
- expectAssignable<keyof FindParameters>(AttributeName);
975
- expectAssignable<keyof FindParametersWithoutSK>(AttributeName);
976
-
977
- expectAssignable<FindParameters>({attr6: 13});
978
- expectAssignable<FindParametersWithoutSK>({attr6: 13});
979
-
980
-
981
- // Invalid query
982
- expectError<FindParameters>({attr6: "ff"});
983
- expectError<FindParametersWithoutSK>({attr6: "ff"});
984
-
985
- expectError<FindParameters>({noexist: "ff"});
986
- expectError<FindParametersWithoutSK>({noexist: "ff"});
987
-
988
-
989
- // Where
990
- findFn({}).where((attr, op) => {
991
- let opKeys = getKeys(op);
992
- expectAssignable<keyof typeof attr>(AttributeName);
993
- expectAssignable<OperationNames>(opKeys);
994
- return "";
995
- });
996
- findFnWithoutSK({}).where((attr, op) => {
997
- let opKeys = getKeys(op);
998
- expectAssignable<keyof typeof attr>(AttributeName);
999
- expectAssignable<OperationNames>(opKeys);
1000
- return "";
1001
- });
1002
-
1003
- // Finishers
1004
- type FindParametersFinishers = "go" | "params" | "where" | "page";
1005
-
1006
- let findFinishers = entityWithSK.find({});
1007
- let findFinishersWithoutSK = entityWithoutSK.find({});
1008
- let matchFinishers = entityWithSK.find({});
1009
- let matchFinishersWithoutSK = entityWithoutSK.find({});
1010
-
1011
- let findFinisherKeys = getKeys(findFinishers);
1012
- let findFinisherKeysWithoutSK = getKeys(findFinishersWithoutSK);
1013
- let matchFinisherKeys = getKeys(matchFinishers);
1014
- let matchFinisherKeysWithoutSK = getKeys(matchFinishersWithoutSK);
1015
-
1016
- expectAssignable<FindParametersFinishers>(findFinisherKeys);
1017
- expectAssignable<FindParametersFinishers>(findFinisherKeysWithoutSK);
1018
- expectAssignable<FindParametersFinishers>(matchFinisherKeys);
1019
- expectAssignable<FindParametersFinishers>(matchFinisherKeysWithoutSK);
1020
-
1021
- let findGo = findFinishers.go;
1022
- let findGoWithoutSK = findFinishersWithoutSK.go;
1023
- let matchGo = matchFinishers.go;
1024
- let matchGoWithoutSK = matchFinishersWithoutSK.go;
1025
-
1026
- let findParams = findFinishers.params;
1027
- let findParamsWithoutSK = findFinishersWithoutSK.params;
1028
- let matchParams = matchFinishers.params;
1029
- let matchParamsWithoutSK = matchFinishersWithoutSK.params;
1030
-
1031
- type FindGoParams = Parameter<typeof findGo>;
1032
- type FindGoParamsWithoutSK = Parameter<typeof findGoWithoutSK>;
1033
- type MatchGoParams = Parameter<typeof matchGo>;
1034
- type MatchGoParamsWithoutSK = Parameter<typeof matchGoWithoutSK>;
1035
-
1036
- type FindParamsParams = Parameter<typeof findParams>;
1037
- type FindParamsParamsWithoutSK = Parameter<typeof findParamsWithoutSK>;
1038
- type MatchParamsParams = Parameter<typeof findParams>;
1039
- type MatchParamsParamsWithoutSK = Parameter<typeof findParamsWithoutSK>;
1040
-
1041
- expectAssignable<FindGoParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
1042
- expectAssignable<FindGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
1043
- expectAssignable<MatchGoParams>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
1044
- expectAssignable<MatchGoParamsWithoutSK>({includeKeys: true, originalErr: true, params: {}, raw: true, table: "abc"});
1045
-
1046
- expectAssignable<FindParamsParams>({params: {}, table: "abc"});
1047
- expectAssignable<FindParamsParamsWithoutSK>({params: {}, table: "abc"});
1048
- expectAssignable<MatchParamsParams>({params: {}, table: "abc"});
1049
- expectAssignable<MatchParamsParamsWithoutSK>({params: {}, table: "abc"});
1050
-
1051
-
1052
- // Page
1053
- let findPageFn = findFinishers.page;
1054
- let findPageFnWithoutSK = findFinishersWithoutSK.page;
1055
- let matchPageFn = matchFinishers.page;
1056
- let matchPageFnWithoutSK = matchFinishersWithoutSK.page;
1057
-
1058
- type FindPageParams = Parameters<typeof findPageFn>;
1059
- type FindPageParamsWithoutSK = Parameters<typeof findPageFnWithoutSK>;
1060
- type MatchPageParams = Parameters<typeof matchPageFn>;
1061
- type MatchPageParamsWithoutSK = Parameters<typeof matchPageFnWithoutSK>;
1062
-
1063
- type FindPageReturn = Promise<[WithSKMyIndexCompositeAttributes | null, Item[]]>;
1064
- type FindPageReturnWithoutSK = Promise<[WithoutSKMyIndexCompositeAttributes | null, ItemWithoutSK[]]>;
1065
- type MatchPageReturn = Promise<[WithSKMyIndexCompositeAttributes | null, Item[]]>;
1066
- type MatchPageReturnWithoutSK = Promise<[WithoutSKMyIndexCompositeAttributes | null, ItemWithoutSK[]]>;
1067
-
1068
- expectAssignable<FindPageParams>([{attr1: "abc", attr2: "def"}, {includeKeys: true, pager: "item", originalErr: true, params: {}, raw: true, table: "abc"}]);
1069
- expectAssignable<FindPageParamsWithoutSK>([{attr1: "abc"}, {includeKeys: true, pager: "raw", originalErr: true, params: {}, raw: true, table: "abc"}]);
1070
- expectAssignable<MatchPageParams>([{attr1: "abc", attr2: "def"}, {includeKeys: true, pager: "item", originalErr: true, params: {}, raw: true, table: "abc"}]);
1071
- expectAssignable<MatchPageParamsWithoutSK>([{attr1: "abc"}, {includeKeys: true, pager: "raw", originalErr: true, params: {}, raw: true, table: "abc"}]);
1072
-
1073
- expectAssignable<FindPageParams>([null]);
1074
- expectAssignable<FindPageParamsWithoutSK>([null]);
1075
- expectAssignable<MatchPageParams>([null]);
1076
- expectAssignable<MatchPageParamsWithoutSK>([null]);
1077
-
1078
- expectAssignable<FindPageParams>([]);
1079
- expectAssignable<FindPageParamsWithoutSK>([]);
1080
- expectAssignable<MatchPageParams>([]);
1081
- expectAssignable<MatchPageParamsWithoutSK>([]);
1082
-
1083
- expectAssignable<FindPageReturn>(findPageFn());
1084
- expectAssignable<FindPageReturnWithoutSK>(findPageFnWithoutSK());
1085
- expectAssignable<MatchPageReturn>(findPageFn());
1086
- expectAssignable<MatchPageReturnWithoutSK>(findPageFnWithoutSK());
1087
-
1088
- // Queries
1089
- type AccessPatternNames = "myIndex" | "myIndex2" | "myIndex3";
1090
-
1091
- let accessPatternNames = getKeys(entityWithSK.query);
1092
- let accessPatternNamesWithoutSK = getKeys(entityWithoutSK.query);
1093
-
1094
- expectType<AccessPatternNames>(accessPatternNames);
1095
- expectType<AccessPatternNames>(accessPatternNamesWithoutSK);
1096
-
1097
- type MyIndexCompositeAttributes = Parameter<typeof entityWithSK.query.myIndex>;
1098
- type MyIndexCompositeAttributesWithoutSK = Parameter<typeof entityWithoutSK.query.myIndex>;
1099
-
1100
- let myIndexBegins = entityWithSK.query.myIndex({attr1: "abc"}).begins;
1101
- // Begins does not exist on Find because the user has tossed out knowledge of order/indexes
1102
- expectError(entityWithoutSK.query.myIndex({attr1: "abc"}).begins);
1103
-
1104
- type MyIndexRemaining = Parameter<typeof myIndexBegins>;
1105
-
1106
- expectAssignable<MyIndexCompositeAttributes>({attr1: "abd"});
1107
- expectAssignable<MyIndexCompositeAttributesWithoutSK>({attr1: "abd"});
1108
-
1109
- expectAssignable<MyIndexCompositeAttributes>({attr1: "abd", attr2: "def"});
1110
- expectAssignable<MyIndexCompositeAttributesWithoutSK>({attr1: "abd"});
1111
-
1112
- expectAssignable<MyIndexRemaining>({});
1113
- expectAssignable<MyIndexRemaining>({attr2: "abc"});
1114
-
1115
- // attr1 not supplied
1116
- expectError<MyIndexCompositeAttributes>({attr2: "abc"});
1117
- expectError<MyIndexCompositeAttributesWithoutSK>({attr2: "abc"});
1118
-
1119
- // attr2 is a strin, not number
1120
- expectError<MyIndexCompositeAttributes>({attr1: "abd", attr2: 133});
1121
- expectError<MyIndexCompositeAttributesWithoutSK>({attr1: 243});
1122
-
1123
- // attr3 is not a pk or sk
1124
- expectError<MyIndexCompositeAttributes>({attr1: "abd", attr2: "def", attr3: "should_not_work"});
1125
- expectError<MyIndexCompositeAttributesWithoutSK>({attr1: "abd", attr2: "def", attr3: "should_not_work"});
1126
-
1127
- // attr1 was already used in the query method
1128
- expectError<MyIndexRemaining>({attr1: "abd"});
1129
-
1130
- // attr2 is a string not number (this tests the 'remaining' composite attributes which should also enforce type)
1131
- expectError<MyIndexRemaining>({attr2: 1243});
1132
-
1133
- // require at least PK
1134
- expectError(entityWithSK.query.myIndex({}));
1135
- expectError(entityWithoutSK.query.myIndex({}));
1136
-
1137
- // attr6 should be number
1138
- expectError(entityWithSK.query.myIndex2({attr6: "45"}));
1139
- expectError(entityWithoutSK.query.myIndex2({attr6: "45"}));
1140
-
1141
- entityWithSK.query
1142
- .myIndex({attr1: "abc", attr2: "def"})
1143
- .go({params: {}})
1144
- .then(a => a.map(val => val.attr4))
1145
-
1146
- entityWithSK.query
1147
- .myIndex({attr1: "abc"})
1148
- .go({params: {}})
1149
- .then(a => a.map(val => val.attr4))
1150
-
1151
- entityWithSK.query
1152
- .myIndex2({attr6: 45, attr9: 454, attr4: "abc", attr5: "def"})
1153
- .go({params: {}})
1154
- .then(a => a.map(val => val.attr4))
1155
-
1156
- entityWithSK.query
1157
- .myIndex2({attr6: 45, attr9: 24})
1158
- .go({params: {}})
1159
- .then(a => a.map(val => val.attr4))
1160
-
1161
- entityWithSK.query
1162
- .myIndex3({attr5: "dgdagad"})
1163
- .go({params: {}})
1164
- .then(a => a.map(val => val.attr4))
1165
-
1166
- entityWithoutSK.query
1167
- .myIndex({attr1: "abc"})
1168
- .go({params: {}})
1169
- .then(a => a.map(val => val.attr4))
1170
-
1171
- entityWithoutSK.query
1172
- .myIndex2({attr6: 53, attr9: 35})
1173
- .go({params: {}})
1174
- .then(a => a.map(val => val.attr4))
1175
-
1176
- entityWithoutSK.query
1177
- .myIndex3({attr5: "dgdagad"})
1178
- .go({params: {}})
1179
- .then(a => a.map(val => val.attr4))
1180
-
1181
- // Query Operations
1182
- entityWithSK.query
1183
- .myIndex({attr1: "abc"})
1184
- .begins({attr2: "asf"})
1185
- .go({params: {}})
1186
- .then(a => a.map(val => val.attr4))
1187
-
1188
- entityWithSK.query
1189
- .myIndex2({attr6: 45, attr9: 34, attr4: "abc"})
1190
- .begins({attr5: "db"})
1191
- .go({params: {}})
1192
- .then(a => a.map(val => val.attr4))
1193
-
1194
- entityWithSK.query
1195
- .myIndex3({attr5: "dgdagad"})
1196
- .between({attr4: "abc", attr9: 3, attr3: "def"}, {attr4: "abc", attr9: 4, attr3: "def"})
1197
- .go({params: {}})
1198
- .then(a => a.map(val => val.attr4))
1199
-
1200
- entityWithSK.query
1201
- .myIndex({attr1: "abc"})
1202
- .gte({attr2: "asf"})
1203
- .go({params: {}})
1204
- .then(a => a.map(val => val.attr4))
1205
-
1206
- entityWithSK.query
1207
- .myIndex2({attr6: 45, attr9: 33, attr4: "abc"})
1208
- .gt({attr5: "abd"})
1209
- .go({params: {}})
1210
- .then(a => a.map(val => val.attr4))
1211
-
1212
- entityWithSK.query
1213
- .myIndex3({attr5: "dgdagad"})
1214
- .lte({attr4: "abc", attr9: 3})
1215
- .go({params: {}})
1216
- .then(a => a.map(val => val.attr4))
1217
-
1218
- entityWithSK.query
1219
- .myIndex3({attr5: "dgdagad"})
1220
- .lt({attr4: "abc", attr9: 3})
1221
- .go({params: {}})
1222
- .then(a => a.map(val => val.attr4))
1223
-
1224
- entityWithSK.query
1225
- .myIndex({attr1: "abc", attr2: "db"})
1226
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1227
- ${name(attr6)} = ${value(attr6, 12)}
1228
- AND ${exists(attr6)}
1229
- AND ${notExists(attr6)}
1230
- AND ${begins(attr6, 35)}
1231
- AND ${between(attr6, 1, 10)}
1232
- AND ${contains(attr6, 14)}
1233
- AND ${eq(attr6, 14)}
1234
- AND ${gt(attr6, 14)}
1235
- AND ${gte(attr6, 14)}
1236
- AND ${lt(attr6, 14)}
1237
- AND ${lte(attr6, 14)}
1238
- AND ${notContains(attr6, 14)}
1239
- `)
1240
-
1241
- // Query Operations (Except with Type Errors)
1242
-
1243
- // This one ensures that an SK value in the index method still is type checked
1244
- expectError(entityWithSK.query
1245
- .myIndex({attr1: "452", attr2: 245})
1246
- .go({params: {}})
1247
- .then(a => a.map(val => val.attr4)))
1248
-
1249
- expectError(entityWithSK.query
1250
- .myIndex2({attr6: "45"})
1251
- .go({params: {}})
1252
- .then(a => a.map(val => val.attr4)))
1253
-
1254
- expectError(entityWithSK.query
1255
- .myIndex3({attr5: 426})
1256
- .go({params: {}})
1257
- .then(a => a.map(val => val.attr4)))
1258
-
1259
- expectError(entityWithoutSK.query
1260
- .myIndex({attr1: 246})
1261
- .go({params: {}})
1262
- .then(a => a.map(val => val.attr4)))
1263
-
1264
- expectError(entityWithoutSK.query
1265
- .myIndex2({attr6: 24, attr9: "1"})
1266
- .go({params: {}})
1267
- .then(a => a.map(val => val.attr4)))
1268
-
1269
- expectError(entityWithoutSK.query
1270
- .myIndex3({attr5: 346})
1271
- .go({params: {}})
1272
- .then(a => a.map(val => val.attr4)))
1273
-
1274
- // Query Operations
1275
- expectError(entityWithSK.query
1276
- .myIndex({attr1: "abc"})
1277
- .begins({attr2: 42})
1278
- .go({params: {}})
1279
- .then(a => a.map(val => val.attr4)))
1280
-
1281
- expectError(entityWithSK.query
1282
- .myIndex2({attr6: 45, attr4: "abc"})
1283
- .begins({attr5: 462})
1284
- .go({params: {}})
1285
- .then(a => a.map(val => val.attr4)))
1286
-
1287
- expectError(entityWithSK.query
1288
- .myIndex3({attr5: "dgdagad"})
1289
- .between({attr4: "abc", attr9: "3", attr3: "def"}, {attr4: "abc", attr9: "4", attr3: "def"})
1290
- .go({params: {}})
1291
- .then(a => a.map(val => val.attr4)))
1292
-
1293
- expectError(entityWithSK.query
1294
- .myIndex({attr1: "abc"})
1295
- .gte({attr2: 462})
1296
- .go({params: {}})
1297
- .then(a => a.map(val => val.attr4)))
1298
-
1299
- expectError(entityWithSK.query
1300
- .myIndex2({attr6: 45, attr4: "abc"})
1301
- .gt({attr5: 246})
1302
- .go({params: {}})
1303
- .then(a => a.map(val => val.attr4)))
1304
-
1305
- expectError(entityWithSK.query
1306
- .myIndex3({attr5: "dgdagad"})
1307
- .lte({attr4: "abc", attr9: "3"})
1308
- .go({params: {}})
1309
- .then(a => a.map(val => val.attr4)))
1310
-
1311
- expectError(entityWithSK.query
1312
- .myIndex3({attr5: "dgdagad"})
1313
- .lt({attr4: "abc", attr9: "3"})
1314
- .go({params: {}})
1315
- .then(a => a.map(val => val.attr4)))
1316
-
1317
- expectError(entityWithSK.query
1318
- .myIndex({attr1: "abc", attr2: "db"})
1319
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1320
- ${name(attr6)} = ${value()}
1321
- `));
1322
-
1323
- expectError(entityWithSK.query
1324
- .myIndex({attr1: "abc", attr2: "db"})
1325
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1326
- ${exists()}
1327
- `));
1328
-
1329
- expectError(entityWithSK.query
1330
- .myIndex({attr1: "abc", attr2: "db"})
1331
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1332
- ${notExists()}
1333
- `));
1334
-
1335
- expectError(entityWithSK.query
1336
- .myIndex({attr1: "abc", attr2: "db"})
1337
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1338
- ${begins(attr6, "35")}
1339
- `));
1340
-
1341
- expectError(entityWithSK.query
1342
- .myIndex({attr1: "abc", attr2: "db"})
1343
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1344
- ${between(attr6, "1", 10)}
1345
- `));
1346
-
1347
- expectError(entityWithSK.query
1348
- .myIndex({attr1: "abc", attr2: "db"})
1349
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1350
- ${between(attr6, 1, "10")}
1351
- `));
1352
-
1353
- expectError(entityWithSK.query
1354
- .myIndex({attr1: "abc", attr2: "db"})
1355
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1356
- ${contains(attr6, "14")}
1357
- `));
1358
-
1359
- expectError(entityWithSK.query
1360
- .myIndex({attr1: "abc", attr2: "db"})
1361
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1362
- ${eq(attr6, "14")}
1363
- `));
1364
-
1365
- expectError(entityWithSK.query
1366
- .myIndex({attr1: "abc", attr2: "db"})
1367
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1368
- ${gt(attr6, "14")}
1369
- `));
1370
-
1371
- expectError(entityWithSK.query
1372
- .myIndex({attr1: "abc", attr2: "db"})
1373
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1374
- ${gte(attr6, "14")}
1375
- `));
1376
-
1377
- expectError(entityWithSK.query
1378
- .myIndex({attr1: "abc", attr2: "db"})
1379
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1380
- ${lt(attr6, "14")}
1381
- `));
1382
-
1383
- expectError(entityWithSK.query
1384
- .myIndex({attr1: "abc", attr2: "db"})
1385
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1386
- ${lte(attr6, "14")}
1387
- `));
1388
-
1389
- expectError(entityWithSK.query
1390
- .myIndex({attr1: "abc", attr2: "db"})
1391
- .where(({attr6}, {value, name, exists, begins, between, contains, eq, gt, gte, lt, lte, notContains, notExists}) => `
1392
- ${notContains(attr6, "14")}
1393
- `));
1394
-
1395
-
1396
-
1397
- // Invalid cases
1398
- expectError(() => new Service({abc: "123"}));
1399
-
1400
-
1401
- // Service with no Entities
1402
- let nullCaseService = new Service({});
1403
- type nullCollections = typeof nullCaseService.collections;
1404
- type nullEntities = typeof nullCaseService.collections;
1405
- expectType<nullCollections>({});
1406
- expectType<nullEntities>({});
1407
-
1408
- // Service with no Collections
1409
- let serviceNoCollections = new Service({standAloneEntity});
1410
- type noEntityCollections = typeof serviceNoCollections.collections;
1411
- expectType<noEntityCollections>({});
1412
-
1413
- // Service no shared entity collections
1414
- let serviceNoShared = new Service({
1415
- entityWithoutSK,
1416
- standAloneEntity,
1417
- normalEntity1,
1418
- });
1419
-
1420
- let expectNoSharedCollections = "" as "normalcollection" | "mycollection" | "mycollection1"
1421
- type NoSharedCollectionsList = keyof typeof serviceNoShared.collections;
1422
- expectType<NoSharedCollectionsList>(expectNoSharedCollections);
1423
- type NoSharedCollectionParameter1 = Parameter<typeof serviceNoShared.collections.mycollection>;
1424
- expectType<NoSharedCollectionParameter1>({attr5: "string"});
1425
- expectError<NoSharedCollectionParameter1>({});
1426
- expectError<NoSharedCollectionParameter1>({attr5: 123});
1427
- expectError<NoSharedCollectionParameter1>({attr1: "123"});
1428
-
1429
- type NoSharedCollectionParameter2 = Parameter<typeof serviceNoShared.collections.normalcollection>;
1430
- expectType<NoSharedCollectionParameter2>({prop2: "abc", prop1: "def"});
1431
- expectError<NoSharedCollectionParameter2>({});
1432
- expectError<NoSharedCollectionParameter2>({prop2: "abc"});
1433
- expectError<NoSharedCollectionParameter2>({prop1: "abc"});
1434
- expectError<NoSharedCollectionParameter2>({prop1: 35});
1435
- expectError<NoSharedCollectionParameter2>({prop2: 35});
1436
- expectError<NoSharedCollectionParameter2>({prop3: "35"});
1437
-
1438
- // Service with complex collections
1439
- let complexService = new Service({
1440
- entityWithoutSK,
1441
- entityWithSK,
1442
- standAloneEntity,
1443
- normalEntity1,
1444
- normalEntity2
1445
- });
1446
-
1447
- let expectSharedCollections = "" as "normalcollection" | "mycollection" | "mycollection1" | "mycollection2"
1448
- type SharedCollectionsList = keyof typeof complexService.collections;
1449
- expectType<SharedCollectionsList>(expectSharedCollections);
1450
- type SharedCollectionParameter1 = Parameter<typeof complexService.collections.mycollection>;
1451
- // success
1452
- complexService.collections.mycollection({attr5: "abc"});
1453
- // failure - no collection composite attributes
1454
- expectError<SharedCollectionParameter1>({});
1455
- // failure - incorrect entity composite attribute types
1456
- expectError<SharedCollectionParameter1>({attr5: 123});
1457
- // failure - incorrect entity composite attribute properties
1458
- expectError<SharedCollectionParameter1>({attr1: "123"});
1459
-
1460
- type SharedCollectionParameter2 = Parameter<typeof complexService.collections.normalcollection>;
1461
- // success
1462
- complexService.collections.normalcollection({prop2: "abc", prop1: "def"});
1463
- // failure - no collection composite attributes
1464
- expectError<SharedCollectionParameter2>({});
1465
- // failure - incomplete composite attributes
1466
- expectError<SharedCollectionParameter2>({prop2: "abc"});
1467
- // failure - incomplete composite attributes
1468
- expectError<SharedCollectionParameter2>({prop1: "abc"});
1469
- // failure - incorrect entity composite attribute types
1470
- expectError<SharedCollectionParameter2>({prop1: 35});
1471
- // failure - incorrect entity composite attribute types
1472
- expectError<SharedCollectionParameter2>({prop2: 35});
1473
- // failure - incorrect entity composite attribute properties
1474
- expectError<SharedCollectionParameter2>({prop3: "35"});
1475
-
1476
- let chainMethods = complexService.collections.normalcollection({prop2: "abc", prop1: "def"});
1477
- type AfterQueryChainMethods = keyof typeof chainMethods;
1478
- let expectedAfterQueryChainMethods = "" as "where" | "go" | "params" | "page"
1479
- expectType<AfterQueryChainMethods>(expectedAfterQueryChainMethods);
1480
-
1481
- // .go params
1482
- type GoParams = Parameter<typeof chainMethods.go>;
1483
- expectAssignable<GoParams>({table: "df", raw: true, params: {}, originalErr: true, includeKeys: true});
1484
- complexService.collections
1485
- .normalcollection({prop2: "abc", prop1: "def"})
1486
- .go()
1487
- .then(values => {
1488
- // .go response includes only related entities
1489
- type NormalCollectionRelatedEntities = keyof typeof values;
1490
- let expectedEntities = "" as "normalEntity1" | "normalEntity2";
1491
- expectType<NormalCollectionRelatedEntities>(expectedEntities);
1492
- values.normalEntity1.map(item => {
1493
- expectError(item.attr1);
1494
- expectError(item.attr2);
1495
- expectError(item.attr3);
1496
- expectError(item.attr4);
1497
- expectError(item.attr5);
1498
- expectError(item.attr6);
1499
- expectError(item.attr7);
1500
- expectError(item.attr8);
1501
- expectError(item.attr9);
1502
- expectError(item.attr10);
1503
- expectType<string>(item.prop1);
1504
- expectType<string>(item.prop2);
1505
- expectType<string>(item.prop3);
1506
- expectType<number>(item.prop4);
1507
- expectType<boolean|undefined>(item.prop10);
1508
- let itemKeys = "" as "prop1" | "prop2" | "prop3" | "prop4" | "prop10";
1509
- expectType<keyof typeof item>(itemKeys);
1510
- });
1511
- values.normalEntity2.map(item => {
1512
- expectType<string>(item.prop1);
1513
- expectType<string>(item.prop2);
1514
- expectType<string>(item.prop3);
1515
- expectType<number>(item.prop5);
1516
- expectType<number|undefined>(item.attr9);
1517
- expectType<number|undefined>(item.attr6);
1518
- expectNotAssignable<{attr1: any}>(item);
1519
- expectNotAssignable<{attr2: any}>(item);
1520
- expectNotAssignable<{attr3: any}>(item);
1521
- expectNotAssignable<{attr4: any}>(item);
1522
- expectNotAssignable<{attr5: any}>(item);
1523
- expectNotAssignable<{attr6: any}>(item);
1524
- expectNotAssignable<{attr7: any}>(item);
1525
- expectNotAssignable<{attr8: any}>(item);
1526
- expectNotAssignable<{attr9: any}>(item);
1527
- expectNotAssignable<{attr10: any}>(item);
1528
- expectNotAssignable<{prop10: any}>(item);
1529
- let itemKeys = "" as "prop1" | "prop2" | "prop3" | "prop5" | "attr9" | "attr6";
1530
- expectType<keyof typeof item>(itemKeys);
1531
- });
1532
- });
1533
- complexService.collections
1534
- .mycollection({attr5: "sgad"})
1535
- .go()
1536
- .then(values => {
1537
- // .go response includes only related entities
1538
- type NormalCollectionRelatedEntities = keyof typeof values;
1539
- let expectedEntities = "" as "entityWithSK" | "entityWithoutSK";
1540
- expectType<NormalCollectionRelatedEntities>(expectedEntities);
1541
- values.entityWithSK.map(item => {
1542
- expectType<string>(item.attr1);
1543
- expectType<string>(item.attr2);
1544
- expectType<"123" | "def" | "ghi"|undefined>(item.attr3);
1545
- expectType<"abc" | "ghi">(item.attr4);
1546
- expectType<string|undefined>(item.attr5);
1547
- expectType<number|undefined>(item.attr6);
1548
- expectType<any>(item.attr7);
1549
- expectType<boolean>(item.attr8);
1550
- expectType<number|undefined>(item.attr9);
1551
- expectType<boolean|undefined>(item.attr10);
1552
- // .go response related entities correct items
1553
- let itemKeys = "" as "attr1" |"attr2" |"attr3" |"attr4" |"attr5" |"attr6" |"attr7" |"attr8" |"attr9" | "attr10";
1554
- expectType<keyof typeof item>(itemKeys);
1555
- });
1556
- values.entityWithoutSK.map(item => {
1557
- item.attr2
1558
- expectType<string>(item.attr1);
1559
- expectType<string | undefined>(item.attr2);
1560
- expectType<"123" | "def" | "ghi" | undefined>(item.attr3);
1561
- expectType<"abc" | "def">(item.attr4);
1562
- expectType<string|undefined>(item.attr5);
1563
- expectType<number|undefined>(item.attr6);
1564
- expectType<any>(item.attr7);
1565
- expectType<boolean>(item.attr8);
1566
- expectType<number|undefined>(item.attr9);
1567
- // .go response related entities correct items
1568
- let itemKeys = "" as "attr1" |"attr2" |"attr3" |"attr4" |"attr5" |"attr6" |"attr7" |"attr8" |"attr9";
1569
- expectType<keyof typeof item>(itemKeys);
1570
- });
1571
- });
1572
-
1573
- let serviceWhere = complexService.collections
1574
- .mycollection1({attr6: 13, attr9: 54})
1575
- .where((attr, op) => {
1576
- let opKeys = getKeys(op);
1577
- expectType<OperationNames>(opKeys);
1578
- op.eq(attr.attr9, 455);
1579
- op.eq(attr.prop5, 455);
1580
- expectAssignable<{attr1: WhereAttributeSymbol<string>}>(attr);
1581
- expectAssignable<{attr2: WhereAttributeSymbol<string>}>(attr);
1582
- expectAssignable<{attr3: WhereAttributeSymbol<"123" | "def" | "ghi">}>(attr);
1583
- expectAssignable<{attr4: WhereAttributeSymbol<"abc" | "def" | "ghi">}>(attr);
1584
- expectAssignable<{attr5: WhereAttributeSymbol<string>}>(attr);
1585
- expectAssignable<{attr6: WhereAttributeSymbol<number>}>(attr);
1586
- expectAssignable<{attr7: WhereAttributeSymbol<any>}>(attr);
1587
- expectAssignable<{attr8: WhereAttributeSymbol<boolean>}>(attr);
1588
- expectAssignable<{attr9: WhereAttributeSymbol<number>}>(attr);
1589
- expectAssignable<{attr10: WhereAttributeSymbol<boolean>}>(attr);
1590
- expectAssignable<{prop1: WhereAttributeSymbol<string>}>(attr);
1591
- expectAssignable<{prop2: WhereAttributeSymbol<string>}>(attr);
1592
- expectAssignable<{prop3: WhereAttributeSymbol<string>}>(attr);
1593
- expectNotAssignable<{prop4: WhereAttributeSymbol<number>}>(attr);
1594
- expectAssignable<{prop5: WhereAttributeSymbol<number>}>(attr);
1595
- expectNotAssignable<{prop10: WhereAttributeSymbol<boolean>}>(attr);
1596
- return "";
1597
- })
1598
- .go()
1599
- .then((items) => {
1600
- items.normalEntity2.map(item => {
1601
- let keys = "" as keyof typeof item;
1602
- expectType<"prop1" | "prop2" | "prop3" | "prop5" | "attr6" | "attr9">(keys);
1603
- expectType<string>(item.prop1);
1604
- expectType<string>(item.prop2);
1605
- expectType<string>(item.prop3);
1606
- expectType<number>(item.prop5);
1607
- expectType<number|undefined>(item.attr6);
1608
- expectType<number|undefined>(item.attr9);
1609
- });
1610
- items.entityWithSK.map((item) => {
1611
- let keys = "" as keyof typeof item;
1612
- expectType<"attr1" | "attr2" | "attr3" | "attr4" | "attr5" | "attr6" | "attr7" | "attr8" | "attr9" | "attr10">(keys);
1613
- expectType<string>(item.attr1);
1614
- expectType<string>(item.attr2);
1615
- expectType<"123" | "def" | "ghi" | undefined>(item.attr3);
1616
- expectType<"abc" | "ghi">(item.attr4);
1617
- expectType<string | undefined>(item.attr5);
1618
- expectType<number | undefined>(item.attr6);
1619
- expectType<any>(item.attr7);
1620
- expectType<boolean>(item.attr8);
1621
- expectType<number | undefined>(item.attr9);
1622
- expectType<boolean | undefined>(item.attr10);
1623
- });
1624
- items.entityWithoutSK.map((item) => {
1625
- let keys = "" as keyof typeof item;
1626
- expectType<"attr1" | "attr2" | "attr3" | "attr4" | "attr5" | "attr6" | "attr7" | "attr8" | "attr9">(keys);
1627
- expectType<string>(item.attr1);
1628
- expectType<string | undefined>(item.attr2);
1629
- expectType<"123" | "def" | "ghi" | undefined>(item.attr3);
1630
- expectType<"abc" | "def">(item.attr4);
1631
- expectType<string | undefined>(item.attr5);
1632
- expectType<number | undefined>(item.attr6);
1633
- expectType<any>(item.attr7);
1634
- expectType<boolean>(item.attr8);
1635
- expectType<number | undefined>(item.attr9);
1636
- });
1637
- });
1638
-
1639
- complexService.collections.normalcollection({prop1: "abc", prop2: "def"})
1640
- .where((attr, op) => {
1641
- let opKeys = getKeys(op);
1642
- expectType<OperationNames>(opKeys);
1643
- expectNotAssignable<{attr1: WhereAttributeSymbol<string>}>(attr);
1644
- expectNotAssignable<{attr2: WhereAttributeSymbol<string>}>(attr);
1645
- expectNotAssignable<{attr3: WhereAttributeSymbol<"123" | "def" | "ghi">}>(attr);
1646
- expectNotAssignable<{attr4: WhereAttributeSymbol<"abc" | "def" | "ghi">}>(attr);
1647
- expectNotAssignable<{attr5: WhereAttributeSymbol<string>}>(attr);
1648
- expectAssignable<{attr6: WhereAttributeSymbol<number>}>(attr);
1649
- expectNotAssignable<{attr7: WhereAttributeSymbol<any>}>(attr);
1650
- expectNotAssignable<{attr8: WhereAttributeSymbol<boolean>}>(attr);
1651
- expectAssignable<{attr9: WhereAttributeSymbol<number>}>(attr);
1652
- expectNotAssignable<{attr10: WhereAttributeSymbol<boolean>}>(attr);
1653
- expectAssignable<{prop1: WhereAttributeSymbol<string>}>(attr);
1654
- expectAssignable<{prop2: WhereAttributeSymbol<string>}>(attr);
1655
- expectAssignable<{prop3: WhereAttributeSymbol<string>}>(attr);
1656
- expectAssignable<{prop4: WhereAttributeSymbol<number>}>(attr);
1657
- expectAssignable<{prop5: WhereAttributeSymbol<number>}>(attr);
1658
- expectAssignable<{prop10: WhereAttributeSymbol<boolean>}>(attr);;
1659
- return op.eq(attr.prop1, "db");
1660
- })
1661
- .go()
1662
- .then((items) => {
1663
- items.normalEntity1.map(item => {
1664
- let keys = "" as keyof typeof item;
1665
- expectType<"prop1" | "prop2" | "prop3" | "prop4" | "prop10">(keys);
1666
- expectType<string>(item.prop1);
1667
- expectType<string>(item.prop2);
1668
- expectType<string>(item.prop3);
1669
- expectType<number>(item.prop4);
1670
- expectType<boolean | undefined>(item.prop10);
1671
- });
1672
- items.normalEntity2.map(item => {
1673
- let keys = "" as keyof typeof item;
1674
- expectType<"prop1" | "prop2" | "prop3" | "prop5" | "attr6" | "attr9">(keys);
1675
- expectType<string>(item.prop1);
1676
- expectType<string>(item.prop2);
1677
- expectType<string>(item.prop3);
1678
- expectType<number>(item.prop5);
1679
- expectType<number|undefined>(item.attr6);
1680
- expectType<number|undefined>(item.attr9);
1681
- });
1682
- });
1683
-
1684
- complexService.collections.mycollection2({attr1: "abc"})
1685
- .where((attr, op) => {
1686
- let opKeys = getKeys(op);
1687
- expectType<OperationNames>(opKeys);
1688
- expectAssignable<{attr1: WhereAttributeSymbol<string>}>(attr);
1689
- expectAssignable<{attr2: WhereAttributeSymbol<string>}>(attr);
1690
- expectAssignable<{attr3: WhereAttributeSymbol<"123" | "def" | "ghi">}>(attr);
1691
- expectAssignable<{attr4: WhereAttributeSymbol<"abc" | "def" | "ghi">}>(attr);
1692
- expectAssignable<{attr5: WhereAttributeSymbol<string>}>(attr);
1693
- expectAssignable<{attr6: WhereAttributeSymbol<number>}>(attr);
1694
- expectAssignable<{attr7: WhereAttributeSymbol<any>}>(attr);
1695
- expectAssignable<{attr8: WhereAttributeSymbol<boolean>}>(attr);
1696
- expectAssignable<{attr9: WhereAttributeSymbol<number>}>(attr);
1697
- expectAssignable<{attr10: WhereAttributeSymbol<boolean>}>(attr);
1698
- expectNotAssignable<{prop1: WhereAttributeSymbol<string>}>(attr);
1699
- expectNotAssignable<{prop2: WhereAttributeSymbol<string>}>(attr);
1700
- expectNotAssignable<{prop3: WhereAttributeSymbol<string>}>(attr);
1701
- expectNotAssignable<{prop4: WhereAttributeSymbol<number>}>(attr);
1702
- expectNotAssignable<{prop5: WhereAttributeSymbol<number>}>(attr);
1703
- expectNotAssignable<{prop10: WhereAttributeSymbol<boolean>}>(attr);
1704
- return op.eq(attr.attr9, 768);
1705
- })
1706
- .go()
1707
- .then(results => {
1708
- results.entityWithSK.map((item) => {
1709
- let keys = "" as keyof typeof item;
1710
- expectType<"attr1" | "attr2" | "attr3" | "attr4" | "attr5" | "attr6" | "attr7" | "attr8" | "attr9" | "attr10">(keys);
1711
- expectType<string>(item.attr1);
1712
- expectType<string>(item.attr2);
1713
- expectType<"123" | "def" | "ghi" | undefined>(item.attr3);
1714
- expectType<"abc" | "ghi">(item.attr4);
1715
- expectType<string | undefined>(item.attr5);
1716
- expectType<number | undefined>(item.attr6);
1717
- expectType<any>(item.attr7);
1718
- expectType<boolean>(item.attr8);
1719
- expectType<number | undefined>(item.attr9);
1720
- expectType<boolean | undefined>(item.attr10);
1721
- });
1722
- });
1723
-
1724
- let entityWithHiddenAttributes1 = new Entity({
1725
- model: {
1726
- entity: "e1",
1727
- service: "s1",
1728
- version: "1"
1729
- },
1730
- attributes: {
1731
- prop1: {
1732
- type: "string"
1733
- },
1734
- prop2: {
1735
- type: "string"
1736
- },
1737
- prop3: {
1738
- type: "string",
1739
- hidden: true
1740
- }
1741
- },
1742
- indexes: {
1743
- record: {
1744
- collection: "collection1",
1745
- pk: {
1746
- field: "pk",
1747
- composite: ["prop1"]
1748
- },
1749
- sk: {
1750
- field: "sk",
1751
- composite: ["prop2"]
1752
- }
1753
- }
1754
- }
1755
- });
1756
-
1757
- let entityWithHiddenAttributes2 = new Entity({
1758
- model: {
1759
- entity: "e2",
1760
- service: "s1",
1761
- version: "1"
1762
- },
1763
- attributes: {
1764
- prop1: {
1765
- type: "string"
1766
- },
1767
- prop2: {
1768
- type: "string"
1769
- },
1770
- prop4: {
1771
- type: "string",
1772
- hidden: true
1773
- },
1774
- prop5: {
1775
- type: "string",
1776
- }
1777
- },
1778
- indexes: {
1779
- record: {
1780
- collection: "collection1",
1781
- pk: {
1782
- field: "pk",
1783
- composite: ["prop1"]
1784
- },
1785
- sk: {
1786
- field: "sk",
1787
- composite: ["prop2"]
1788
- }
1789
- }
1790
- }
1791
- });
1792
-
1793
- const serviceWithHiddenAttributes = new Service({
1794
- e1: entityWithHiddenAttributes1,
1795
- e2: entityWithHiddenAttributes2
1796
- });
1797
-
1798
- type Entity1WithHiddenAttribute = {
1799
- prop1: string;
1800
- prop2: string;
1801
- };
1802
-
1803
- let entity1WithHiddenAttributeKey = "" as keyof Entity1WithHiddenAttribute;
1804
-
1805
- type Entity2WithHiddenAttribute = {
1806
- prop1: string;
1807
- prop2: string;
1808
- prop5: string | undefined;
1809
- };
1810
-
1811
- let entity2WithHiddenAttributeKey = "" as keyof Entity2WithHiddenAttribute;
1812
-
1813
- entityWithHiddenAttributes1
1814
- .get({prop1: "abc", prop2: "def"})
1815
- .where((attr, op) => {
1816
- expectAssignable<{prop3: WhereAttributeSymbol<string>}>(attr);
1817
- return op.eq(attr.prop3, "abc");
1818
- })
1819
- .go()
1820
- .then(value => {
1821
- if (value !== null) {
1822
- expectType<keyof typeof value>(entity1WithHiddenAttributeKey);
1823
- expectType<Entity1WithHiddenAttribute>(value);
1824
- }
1825
- });
1826
-
1827
- entityWithHiddenAttributes1
1828
- .query.record({prop1: "abc"})
1829
- .where((attr, op) => {
1830
- expectAssignable<{prop3: WhereAttributeSymbol<string>}>(attr);
1831
- return op.eq(attr.prop3, "abc");
1832
- })
1833
- .go()
1834
- .then(values => {
1835
- return values.map(value => {
1836
- expectType<keyof typeof value>(entity1WithHiddenAttributeKey);
1837
- expectType<Entity1WithHiddenAttribute>(value);
1838
- });
1839
- });
1840
-
1841
- serviceWithHiddenAttributes.collections
1842
- .collection1({prop1: "abc"})
1843
- .where((attr, op) => {
1844
- expectAssignable<{prop3: WhereAttributeSymbol<string>}>(attr);
1845
- expectAssignable<{prop4: WhereAttributeSymbol<string>}>(attr);
1846
- return `${op.eq(attr.prop3, "abc")} AND ${op.eq(attr.prop4, "def")}`
1847
- })
1848
- .go()
1849
- .then(results => {
1850
- results.e1.map(value => {
1851
- expectType<keyof typeof value>(entity1WithHiddenAttributeKey);
1852
- expectType<Entity1WithHiddenAttribute>(value);
1853
- });
1854
- results.e2.map(value => {
1855
- expectType<keyof typeof value>(entity2WithHiddenAttributeKey);
1856
- expectType<string>(value.prop1);
1857
- expectType<string>(value.prop2);
1858
- expectType<string | undefined>(value.prop5);
1859
- });
1860
- })
1861
-
1862
- let entityWithRequiredAttribute = new Entity({
1863
- model: {
1864
- entity: "e1",
1865
- service: "s1",
1866
- version: "1"
1867
- },
1868
- attributes: {
1869
- prop1: {
1870
- type: "string"
1871
- },
1872
- prop2: {
1873
- type: "string"
1874
- },
1875
- prop3: {
1876
- type: "string",
1877
- required: true
1878
- },
1879
- prop4: {
1880
- type: "number",
1881
- required: true,
1882
- },
1883
- prop5: {
1884
- type: "any",
1885
- required: true
1886
- },
1887
- prop6: {
1888
- type: "map",
1889
- properties: {
1890
- nested1: {
1891
- type: "string",
1892
- required: true
1893
- }
1894
- },
1895
- required: true,
1896
- },
1897
- prop7: {
1898
- type: "list",
1899
- items: {
1900
- type: "string",
1901
- required: true
1902
- },
1903
- required: true,
1904
- },
1905
- prop8: {
1906
- type: "string",
1907
- required: true,
1908
- default: "abc"
1909
- },
1910
- prop9: {
1911
- type: "map",
1912
- properties: {
1913
- nested1: {
1914
- type: "string",
1915
- required: true,
1916
- default: () => "abc"
1917
- },
1918
- nested2: {
1919
- type: "string",
1920
- required: true,
1921
- default: "abc"
1922
- }
1923
- },
1924
- default: {},
1925
- required: true,
1926
- },
1927
- prop10: {
1928
- type: "list",
1929
- items: {
1930
- type: "string",
1931
- },
1932
- required: true,
1933
- default: []
1934
- },
1935
- },
1936
- indexes: {
1937
- record: {
1938
- collection: "collection1",
1939
- pk: {
1940
- field: "pk",
1941
- composite: ["prop1"]
1942
- },
1943
- sk: {
1944
- field: "sk",
1945
- composite: ["prop2"]
1946
- }
1947
- }
1948
- }
1949
- });
1950
-
1951
- // required attributes, as object and array, without required (but defaulted attributes)
1952
- entityWithRequiredAttribute.put({
1953
- prop1: "abc",
1954
- prop2: "def",
1955
- prop3: "ghi",
1956
- prop4: 123,
1957
- prop5: {anyVal: ["anyItem"]},
1958
- prop6: {
1959
- nested1: "abc"
1960
- },
1961
- prop7: []
1962
- });
1963
- // required attributes, as object and array, without required (but defaulted attributes)
1964
- entityWithRequiredAttribute.put([{
1965
- prop1: "abc",
1966
- prop2: "def",
1967
- prop3: "ghi",
1968
- prop4: 123,
1969
- prop5: {anyVal: ["anyItem"]},
1970
- prop6: {
1971
- nested1: "abc"
1972
- },
1973
- prop7: []
1974
- }]);
1975
- // required attributes, as object and array, without required (but defaulted attributes)
1976
- entityWithRequiredAttribute.create({
1977
- prop1: "abc",
1978
- prop2: "def",
1979
- prop3: "ghi",
1980
- prop4: 123,
1981
- prop5: {anyVal: ["anyItem"]},
1982
- prop6: {
1983
- nested1: "abc"
1984
- },
1985
- prop7: []
1986
- });
1987
- // create doesnt allow for bulk
1988
- expectError(() => {
1989
- entityWithRequiredAttribute.create([{
1990
- prop1: "abc",
1991
- prop2: "def",
1992
- prop3: "ghi",
1993
- prop4: 123,
1994
- prop5: {anyVal: ["anyItem"]},
1995
- prop6: {
1996
- nested1: "abc"
1997
- },
1998
- prop7: []
1999
- }]);
2000
- });
2001
- // missing `nested1` on `prop6`
2002
- expectError(() => {
2003
- entityWithRequiredAttribute.put({
2004
- prop1: "abc",
2005
- prop2: "def",
2006
- prop3: "ghi",
2007
- prop4: 123,
2008
- prop5: {anyVal: ["anyItem"]},
2009
- prop6: {},
2010
- prop7: []
2011
- });
2012
- })
2013
- // missing `nested1` on `prop6`
2014
- expectError(() => {
2015
- entityWithRequiredAttribute.put([{
2016
- prop1: "abc",
2017
- prop2: "def",
2018
- prop3: "ghi",
2019
- prop4: 123,
2020
- prop5: {anyVal: ["anyItem"]},
2021
- prop6: {},
2022
- prop7: []
2023
- }]);
2024
- })
2025
- // missing `nested1` on `prop6`
2026
- expectError(() => {
2027
- entityWithRequiredAttribute.create({
2028
- prop1: "abc",
2029
- prop2: "def",
2030
- prop3: "ghi",
2031
- prop4: 123,
2032
- prop5: {anyVal: ["anyItem"]},
2033
- prop6: {},
2034
- prop7: []
2035
- });
2036
- });
2037
-
2038
- // no removing required attributes
2039
- expectError(() => {
2040
- entityWithRequiredAttribute
2041
- .update({prop1: "abc", prop2: "def"})
2042
- .remove(['prop3'])
2043
- });
2044
-
2045
- // no removing required attributes
2046
- expectError(() => {
2047
- entityWithRequiredAttribute
2048
- .update({prop1: "abc", prop2: "def"})
2049
- .remove(['prop5'])
2050
- });
2051
-
2052
- // no removing required attributes
2053
- expectError(() => {
2054
- entityWithRequiredAttribute
2055
- .update({prop1: "abc", prop2: "def"})
2056
- .remove(['prop6'])
2057
- });
2058
-
2059
- // no removing required attributes
2060
- expectError(() => {
2061
- entityWithRequiredAttribute
2062
- .update({prop1: "abc", prop2: "def"})
2063
- .remove(['prop7'])
2064
- });
2065
-
2066
- let entityWithReadOnlyAttribute = new Entity({
2067
- model: {
2068
- entity: "e1",
2069
- service: "s1",
2070
- version: "1"
2071
- },
2072
- attributes: {
2073
- prop1: {
2074
- type: "string"
2075
- },
2076
- prop2: {
2077
- type: "string"
2078
- },
2079
- prop3: {
2080
- type: "string",
2081
- readOnly: true
2082
- },
2083
- prop4: {
2084
- type: "string"
2085
- },
2086
- prop5: {
2087
- type: "number"
2088
- },
2089
- prop6: {
2090
- type: "any"
2091
- },
2092
- prop7: {
2093
- type: "string"
2094
- },
2095
- prop8: {
2096
- type: ["abc", "def"] as const
2097
- },
2098
- prop9: {
2099
- type: "number",
2100
- readOnly: true,
2101
- },
2102
- prop10: {
2103
- type: "any",
2104
- readOnly: true
2105
- }
2106
- },
2107
- indexes: {
2108
- record: {
2109
- collection: "collection1",
2110
- pk: {
2111
- field: "pk",
2112
- composite: ["prop1"]
2113
- },
2114
- sk: {
2115
- field: "sk",
2116
- composite: ["prop2"]
2117
- }
2118
- }
2119
- }
2120
- });
2121
-
2122
- entityWithReadOnlyAttribute.put({prop1: "abc", prop2: "def", prop3: "ghi"}).params();
2123
- entityWithReadOnlyAttribute.create({prop1: "abc", prop2: "def", prop3: "ghi"}).params();
2124
-
2125
- // readonly
2126
- expectError(() => {
2127
- entityWithReadOnlyAttribute
2128
- .update({prop1: "abc", prop2: "def"})
2129
- .set({prop3: "abc"})
2130
- .params();
2131
- });
2132
-
2133
- // readonly
2134
- expectError(() => {
2135
- entityWithReadOnlyAttribute
2136
- .update({prop1: "abc", prop2: "def"})
2137
- .add({prop9: 13})
2138
- .params();
2139
- });
2140
-
2141
- // readonly
2142
- expectError(() => {
2143
- entityWithReadOnlyAttribute
2144
- .update({prop1: "abc", prop2: "def"})
2145
- .subtract({prop9: 13})
2146
- .params();
2147
- });
2148
-
2149
- // readonly
2150
- expectError(() => {
2151
- entityWithReadOnlyAttribute
2152
- .update({prop1: "abc", prop2: "def"})
2153
- .delete({prop10: "13"})
2154
- .params();
2155
- });
2156
-
2157
- // readonly
2158
- expectError(() => {
2159
- entityWithReadOnlyAttribute
2160
- .update({prop1: "abc", prop2: "def"})
2161
- .append({prop10: ["abc"]})
2162
- .params();
2163
- });
2164
-
2165
- // bad type - not number
2166
- expectError(() => {
2167
- entityWithReadOnlyAttribute
2168
- .update({prop1: "abc", prop2: "def"})
2169
- .add({prop7: 13})
2170
- .params();
2171
- });
2172
-
2173
- // bad type - not number
2174
- expectError(() => {
2175
- entityWithReadOnlyAttribute
2176
- .update({prop1: "abc", prop2: "def"})
2177
- .subtract({prop7: 13})
2178
- .params();
2179
- });
2180
-
2181
- // bad type - not string
2182
- expectError(() => {
2183
- entityWithReadOnlyAttribute
2184
- .update({prop1: "abc", prop2: "def"})
2185
- // prop7 is string not number
2186
- .data(({prop7}, {set}) => set(prop7, 5))
2187
- .params();
2188
- });
2189
-
2190
- // bad type - incorrect enum
2191
- expectError(() => {
2192
- entityWithReadOnlyAttribute
2193
- .update({prop1: "abc", prop2: "def"})
2194
- // prop8 is enum with values ["abc", "def"]
2195
- .data(({prop8}, {set}) => set(prop8, "ghi"))
2196
- .params();
2197
- });
2198
-
2199
- // bad type - not number
2200
- expectError(() => {
2201
- entityWithReadOnlyAttribute
2202
- .update({prop1: "abc", prop2: "def"})
2203
- .data(({prop7}, {subtract}) => subtract(prop7, 5))
2204
- .params();
2205
- });
2206
-
2207
- // bad type - not number
2208
- expectError(() => {
2209
- entityWithReadOnlyAttribute
2210
- .update({prop1: "abc", prop2: "def"})
2211
- .data(({prop7}, {add}) => add(prop7, 5))
2212
- .params();
2213
- });
2214
-
2215
- // bad type - not any
2216
- expectError(() => {
2217
- entityWithReadOnlyAttribute
2218
- .update({prop1: "abc", prop2: "def"})
2219
- .data(({prop7}, {del}) => del(prop7, 5))
2220
- .params();
2221
- });
2222
-
2223
- // bad type - not any
2224
- expectError(() => {
2225
- entityWithReadOnlyAttribute
2226
- .update({prop1: "abc", prop2: "def"})
2227
- .data(({prop7}, op) => op.delete(prop7, 5))
2228
- .params();
2229
- });
2230
-
2231
- // bad type - not any
2232
- expectError(() => {
2233
- entityWithReadOnlyAttribute
2234
- .update({prop1: "abc", prop2: "def"})
2235
- .delete({prop7: "13", prop5: 24})
2236
- .params();
2237
- });
2238
-
2239
- // bad type - not any
2240
- expectError(() => {
2241
- entityWithReadOnlyAttribute
2242
- .update({prop1: "abc", prop2: "def"})
2243
- .delete({prop5: 24})
2244
- .params();
2245
- });
2246
-
2247
-
2248
- expectError(() => {
2249
- entityWithReadOnlyAttribute
2250
- .update({prop1: "abc", prop2: "def"})
2251
- .append({prop7: "13", prop5: 24})
2252
- .params();
2253
- });
2254
-
2255
- expectError(() => {
2256
- entityWithReadOnlyAttribute
2257
- .update({prop1: "abc", prop2: "def"})
2258
- .append({prop5: 24})
2259
- .params();
2260
- });
2261
-
2262
- // readonly
2263
- expectError(() => {
2264
- entityWithReadOnlyAttribute
2265
- .update({prop1: "abc", prop2: "def"})
2266
- .remove(["prop3"])
2267
- .params();
2268
- });
2269
-
2270
- // readonly
2271
- expectError(() => {
2272
- entityWithReadOnlyAttribute
2273
- .update({prop1: "abc", prop2: "def"})
2274
- .data(({prop3}, {remove}) => {
2275
- remove(prop3)
2276
- })
2277
- .params();
2278
- });
2279
-
2280
- expectError(() => {
2281
- entityWithReadOnlyAttribute
2282
- .update({prop1: "abc", prop2: "def"})
2283
- .data(({prop5}, {append}) => {
2284
- append(prop5, 25)
2285
- })
2286
- .params();
2287
- });
2288
-
2289
- // patch
2290
- expectError(() => {
2291
- entityWithReadOnlyAttribute
2292
- .patch({prop1: "abc", prop2: "def"})
2293
- .set({prop3: "abc"})
2294
- .params();
2295
- });
2296
-
2297
- expectError(() => {
2298
- entityWithReadOnlyAttribute
2299
- .patch({prop1: "abc", prop2: "def"})
2300
- .add({prop7: 13})
2301
- .params();
2302
- });
2303
-
2304
- expectError(() => {
2305
- entityWithReadOnlyAttribute
2306
- .patch({prop1: "abc", prop2: "def"})
2307
- .subtract({prop7: 13})
2308
- .params();
2309
- });
2310
-
2311
- expectError(() => {
2312
- entityWithReadOnlyAttribute
2313
- .patch({prop1: "abc", prop2: "def"})
2314
- .delete({prop7: "13", prop5: 24})
2315
- .params();
2316
- });
2317
-
2318
- expectError(() => {
2319
- entityWithReadOnlyAttribute
2320
- .patch({prop1: "abc", prop2: "def"})
2321
- .delete({prop5: 24})
2322
- .params();
2323
- });
2324
-
2325
- expectError(() => {
2326
- entityWithReadOnlyAttribute
2327
- .patch({prop1: "abc", prop2: "def"})
2328
- .append({prop7: "13", prop5: 24})
2329
- .params();
2330
- });
2331
-
2332
- expectError(() => {
2333
- entityWithReadOnlyAttribute
2334
- .patch({prop1: "abc", prop2: "def"})
2335
- .append({prop5: 24})
2336
- .params();
2337
- });
2338
-
2339
- expectError(() => {
2340
- entityWithReadOnlyAttribute
2341
- .patch({prop1: "abc", prop2: "def"})
2342
- .remove(["prop3"])
2343
- .params();
2344
- });
2345
-
2346
- expectError(() => {
2347
- entityWithReadOnlyAttribute
2348
- .patch({prop1: "abc", prop2: "def"})
2349
- .remove(["prop3"])
2350
- .params();
2351
- });
2352
-
2353
- let setItemValue = {} as UpdateEntityItem<typeof entityWithReadOnlyAttribute>
2354
- entityWithReadOnlyAttribute
2355
- .update({prop1: "abc", prop2: "def"})
2356
- .set(setItemValue)
2357
- .params();
2358
-
2359
- entityWithReadOnlyAttribute
2360
- .update({prop1: "abc", prop2: "def"})
2361
- .remove([
2362
- "prop4"
2363
- ])
2364
- .params();
2365
-
2366
- entityWithReadOnlyAttribute
2367
- .update({prop1: "abc", prop2: "def"})
2368
- .add({
2369
- prop5: 13,
2370
- })
2371
- .params();
2372
-
2373
- entityWithReadOnlyAttribute
2374
- .update({prop1: "abc", prop2: "def"})
2375
- .subtract({
2376
- prop5: 13,
2377
- })
2378
- .params();
2379
-
2380
- entityWithReadOnlyAttribute
2381
- .update({prop1: "abc", prop2: "def"})
2382
- .append({
2383
- prop6: ["value"]
2384
- })
2385
- .params();
2386
-
2387
- entityWithReadOnlyAttribute
2388
- .update({prop1: "abc", prop2: "def"})
2389
- .delete({
2390
- prop6: ["value"]
2391
- })
2392
- .params();
2393
-
2394
- // full chain with duplicates
2395
- entityWithReadOnlyAttribute
2396
- .update({prop1: "abc", prop2: "def"})
2397
- .set(setItemValue)
2398
- .remove([
2399
- "prop4"
2400
- ])
2401
- .add({
2402
- prop5: 13,
2403
- })
2404
- .subtract({
2405
- prop5: 13,
2406
- })
2407
- .append({
2408
- prop6: ["value"]
2409
- })
2410
- .delete({
2411
- prop6: ["value"]
2412
- })
2413
- .set(setItemValue)
2414
- .remove([
2415
- "prop4"
2416
- ])
2417
- .data((attr, op) => {
2418
- op.set(attr.prop4, "abc");
2419
- op.set(attr.prop5, 134);
2420
- op.set(attr.prop6, "def")
2421
- op.set(attr.prop6, 123)
2422
- op.set(attr.prop6, true)
2423
- op.set(attr.prop6[1], true)
2424
- op.set(attr.prop6.prop1, true)
2425
- op.set(attr.prop8, "def")
2426
-
2427
- op.remove(attr.prop4);
2428
- op.remove(attr.prop5);
2429
- op.remove(attr.prop6);
2430
- op.remove(attr.prop6);
2431
- op.remove(attr.prop6);
2432
- op.remove(attr.prop6[1]);
2433
- op.remove(attr.prop6.prop1);
2434
- op.remove(attr.prop8)
2435
-
2436
- op.append(attr.prop6, ["abc"]);
2437
- op.append(attr.prop6, ["abc"]);
2438
- op.append(attr.prop6, ["abc"]);
2439
- op.append(attr.prop6[1], ["abc"]);
2440
- op.append(attr.prop6.prop1, ["abc"]);
2441
-
2442
- op.delete(attr.prop6, ["abc"]);
2443
- op.delete(attr.prop6, ["abc"]);
2444
- op.delete(attr.prop6, ["abc"]);
2445
- op.delete(attr.prop6[1], ["abc"]);
2446
- op.delete(attr.prop6.prop1, ["abc"]);
2447
-
2448
- op.del(attr.prop6, ["abc"]);
2449
- op.del(attr.prop6, ["abc"]);
2450
- op.del(attr.prop6, ["abc"]);
2451
- op.del(attr.prop6[1], ["abc"]);
2452
- op.del(attr.prop6.prop1, ["abc"]);
2453
-
2454
- op.name(attr.prop4);
2455
- op.name(attr.prop5);
2456
- op.name(attr.prop6);
2457
- op.name(attr.prop6);
2458
- op.name(attr.prop6);
2459
- op.name(attr.prop6[1]);
2460
- op.name(attr.prop6.prop1);
2461
- op.name(attr.prop8);
2462
-
2463
- op.value(attr.prop4, "abc");
2464
- op.value(attr.prop5, 134);
2465
- op.value(attr.prop6, "abc");
2466
- op.value(attr.prop6, "abc");
2467
- op.value(attr.prop6, "abc");
2468
- op.value(attr.prop6[1], "abc");
2469
- op.value(attr.prop6.prop1, "abc");
2470
- op.value(attr.prop8, "abc");
2471
- })
2472
- .add({
2473
- prop5: 13,
2474
- })
2475
- .subtract({
2476
- prop5: 13,
2477
- })
2478
- .append({
2479
- prop6: ["value"]
2480
- })
2481
- .delete({
2482
- prop6: ["value"]
2483
- })
2484
- .params();
2485
-
2486
-
2487
- type MyCollection1Pager = {
2488
- attr5?: string | undefined;
2489
- attr9?: number | undefined;
2490
- attr6?: number | undefined;
2491
- attr1?: string | undefined;
2492
- attr2?: string | undefined;
2493
- prop1?: string | undefined;
2494
- prop2?: string | undefined;
2495
- prop5?: number | undefined;
2496
- __edb_e__?: string | undefined;
2497
- __edb_v__?: string | undefined;
2498
- attr4?: "abc" | "def" | "ghi" | undefined;
2499
- }
2500
-
2501
- type Collection1EntityNames = "entityWithSK" | "normalEntity2" | "entityWithoutSK";
2502
- const names = "" as Collection1EntityNames;
2503
- complexService.collections
2504
- .mycollection1({attr9: 123, attr6: 245})
2505
- .page()
2506
- .then(([next, results]) => {
2507
- expectType<string | undefined>(next?.attr1);
2508
- expectType<string | undefined>(next?.attr2);
2509
- expectType<number | undefined>(next?.attr6);
2510
- expectType<number | undefined>(next?.attr9);
2511
- expectType<"abc" | "def" | "ghi" | undefined>(next?.attr4);
2512
- expectType<string | undefined>(next?.attr5);
2513
- expectType<number | undefined>(next?.prop5);
2514
- expectType<string | undefined>(next?.prop1);
2515
- expectType<string | undefined>(next?.prop2);
2516
- expectType<string | undefined>(next?.__edb_e__);
2517
- expectType<string | undefined>(next?.__edb_v__);
2518
- expectAssignable<typeof next>({
2519
- attr1: "abc",
2520
- attr2: "abc",
2521
- attr6: 27,
2522
- attr9: 89,
2523
- attr4: "abc",
2524
- attr5: "abc",
2525
- __edb_e__: "entityWithSK",
2526
- __edb_v__: "1"
2527
- });
2528
- expectAssignable<typeof next>({
2529
- prop1: "abc",
2530
- prop2: "abc",
2531
- attr6: 27,
2532
- attr9: 89,
2533
- prop5: 12,
2534
- __edb_e__: "normalEntity2",
2535
- __edb_v__: "1"
2536
- });
2537
- expectAssignable<typeof next>({
2538
- attr1: "abc",
2539
- attr6: 27,
2540
- attr9: 89,
2541
- __edb_e__: "entityWithoutSK",
2542
- __edb_v__: "1"
2543
- });
2544
- expectType<keyof typeof results>(names);
2545
- expectNotType<any>(next);
2546
- })
2547
-
2548
- complexService.collections
2549
- .mycollection1({attr9: 123, attr6: 245})
2550
- .page(null)
2551
-
2552
- const nextPage = {} as MyCollection1Pager;
2553
- complexService.collections
2554
- .mycollection1({attr9: 123, attr6: 245})
2555
- .page(nextPage, {})
2556
-
2557
- complexService.entities
2558
- .entityWithSK.remove({attr1: "abc", attr2: "def"})
2559
- .where((attr, op) => op.eq(attr.attr9, 14))
2560
- .go();
2561
-
2562
-
2563
- const entityWithMultipleCollections1 = new Entity({
2564
- model: {
2565
- entity: "entity1",
2566
- service: "myservice",
2567
- version: "myversion"
2568
- },
2569
- attributes: {
2570
- attr1: {
2571
- type: "string",
2572
- },
2573
- attr2: {
2574
- type: "string",
2575
- }
2576
- },
2577
- indexes: {
2578
- myIndex: {
2579
- collection: ["outercollection", "innercollection"] as const,
2580
- pk: {
2581
- field: "pk",
2582
- composite: ["attr1"]
2583
- },
2584
- sk: {
2585
- field: "sk",
2586
- composite: ["attr2"]
2587
- }
2588
- },
2589
- }
2590
- })
2591
-
2592
- const entityWithMultipleCollections2 = new Entity({
2593
- model: {
2594
- entity: "entity2",
2595
- service: "myservice",
2596
- version: "myversion"
2597
- },
2598
- attributes: {
2599
- attr1: {
2600
- type: "string",
2601
- },
2602
- attr2: {
2603
- type: "string",
2604
- }
2605
- },
2606
- indexes: {
2607
- myIndex: {
2608
- collection: ["outercollection", "innercollection"] as const,
2609
- pk: {
2610
- field: "pk",
2611
- composite: ["attr1"]
2612
- },
2613
- sk: {
2614
- field: "sk",
2615
- composite: ["attr2"]
2616
- }
2617
- },
2618
- myIndex2: {
2619
- index: "index2",
2620
- collection: ["extracollection"] as const,
2621
- pk: {
2622
- field: "index2pk",
2623
- composite: ["attr1"]
2624
- },
2625
- sk: {
2626
- field: "index2sk",
2627
- composite: ["attr2"]
2628
- }
2629
- },
2630
- }
2631
- });
2632
-
2633
- const entityWithMultipleCollections3 = new Entity({
2634
- model: {
2635
- entity: "entity3",
2636
- service: "myservice",
2637
- version: "myversion"
2638
- },
2639
- attributes: {
2640
- attr1: {
2641
- type: "string",
2642
- },
2643
- attr2: {
2644
- type: "string",
2645
- }
2646
- },
2647
- indexes: {
2648
- myIndex: {
2649
- collection: "outercollection" as const,
2650
- pk: {
2651
- field: "pk",
2652
- composite: ["attr1"]
2653
- },
2654
- sk: {
2655
- field: "sk",
2656
- composite: ["attr2"]
2657
- }
2658
- },
2659
- myIndex2: {
2660
- index: "index2",
2661
- collection: "extracollection" as const,
2662
- pk: {
2663
- field: "index2pk",
2664
- composite: ["attr1"]
2665
- },
2666
- sk: {
2667
- field: "index2sk",
2668
- composite: ["attr2"]
2669
- }
2670
- },
2671
- }
2672
- });
2673
-
2674
- const serviceWithMultipleCollections = new Service({entityWithMultipleCollections3, entityWithMultipleCollections1, entityWithMultipleCollections2});
2675
-
2676
- type OuterCollectionEntities = "entityWithMultipleCollections2" | "entityWithMultipleCollections3" | "entityWithMultipleCollections1";
2677
- type InnerCollectionEntities = "entityWithMultipleCollections1" | "entityWithMultipleCollections2";
2678
- type ExtraCollectionEntities = "entityWithMultipleCollections2" | "entityWithMultipleCollections3";
2679
-
2680
- serviceWithMultipleCollections.collections
2681
- .outercollection({attr1: "abc"})
2682
- .go()
2683
- .then(values => {
2684
- const keys = "" as keyof typeof values;
2685
- expectType<OuterCollectionEntities>(keys);
2686
- })
2687
-
2688
- serviceWithMultipleCollections.collections
2689
- .innercollection({attr1: "abc"})
2690
- .go()
2691
- .then(values => {
2692
- const keys = "" as keyof typeof values;
2693
- expectType<InnerCollectionEntities>(keys);
2694
- })
2695
-
2696
- serviceWithMultipleCollections.collections
2697
- .extracollection({attr1: "abc"})
2698
- .go()
2699
- .then(values => {
2700
- const keys = "" as keyof typeof values;
2701
- expectType<ExtraCollectionEntities>(keys);
2702
- })
2703
-
2704
- const entityWithWatchAll = new Entity({
2705
- model: {
2706
- entity: "withwatchall",
2707
- service: "service",
2708
- version: "1"
2709
- },
2710
- attributes: {
2711
- prop1: {
2712
- type: "string"
2713
- },
2714
- prop2: {
2715
- type: "string"
2716
- },
2717
- prop3: {
2718
- type: "string",
2719
- watch: "*",
2720
- set: (value) => {
2721
- return value;
2722
- }
2723
- },
2724
- },
2725
- indexes: {
2726
- record: {
2727
- pk: {
2728
- field: "pk",
2729
- composite: ["prop1"]
2730
- },
2731
- sk: {
2732
- field: "sk",
2733
- composite: ["prop2"]
2734
- }
2735
- }
2736
- }
2737
- });
2738
-
2739
- const entityWithComplexShapes = new Entity({
2740
- model: {
2741
- entity: "entity",
2742
- service: "service",
2743
- version: "1"
2744
- },
2745
- attributes: {
2746
- prop1: {
2747
- type: "string",
2748
- label: "props"
2749
- },
2750
- prop2: {
2751
- type: "string",
2752
- },
2753
- prop3: {
2754
- type: "map",
2755
- properties: {
2756
- val1: {
2757
- type: "string"
2758
- }
2759
- }
2760
- },
2761
- prop4: {
2762
- type: "list",
2763
- items: {
2764
- type: "map",
2765
- properties: {
2766
- val2: {
2767
- type: "number",
2768
- },
2769
- val3: {
2770
- type: "list",
2771
- items: {
2772
- type: "string"
2773
- }
2774
- },
2775
- val4: {
2776
- type: "set",
2777
- items: "number"
2778
- }
2779
- }
2780
- }
2781
- },
2782
- prop5: {
2783
- type: "set",
2784
- items: "string"
2785
- },
2786
- prop6: {
2787
- type: "set",
2788
- items: "string"
2789
- }
2790
- },
2791
- indexes: {
2792
- record: {
2793
- collection: "mops",
2794
- pk: {
2795
- field: "pk",
2796
- composite: ["prop1"]
2797
- },
2798
- sk: {
2799
- field: "sk",
2800
- composite: ["prop2"]
2801
- }
2802
- }
2803
- }
2804
- });
2805
-
2806
- const entityWithComplexShapesRequired = new Entity({
2807
- model: {
2808
- entity: "entity",
2809
- service: "service",
2810
- version: "1"
2811
- },
2812
- attributes: {
2813
- prop1: {
2814
- type: "string",
2815
- label: "props"
2816
- },
2817
- prop2: {
2818
- type: "string",
2819
- },
2820
- attr3: {
2821
- type: "map",
2822
- properties: {
2823
- val1: {
2824
- type: "string",
2825
- required: true
2826
- }
2827
- },
2828
- required: true
2829
- },
2830
- attr4: {
2831
- type: "list",
2832
- items: {
2833
- type: "map",
2834
- properties: {
2835
- val2: {
2836
- type: "number",
2837
- required: true
2838
- },
2839
- val3: {
2840
- type: "list",
2841
- items: {
2842
- type: "string",
2843
- required: true
2844
- },
2845
- required: true
2846
- },
2847
- val4: {
2848
- type: "set",
2849
- items: "number",
2850
- required: true
2851
- }
2852
- }
2853
- },
2854
- required: true
2855
- },
2856
- attr5: {
2857
- type: "set",
2858
- items: "string",
2859
- required: true
2860
- },
2861
- attr6: {
2862
- type: "set",
2863
- items: "string",
2864
- required: true
2865
- }
2866
- },
2867
- indexes: {
2868
- record: {
2869
- collection: "mops",
2870
- pk: {
2871
- field: "pk",
2872
- composite: ["prop1"]
2873
- },
2874
- sk: {
2875
- field: "sk",
2876
- composite: ["prop2"]
2877
- }
2878
- }
2879
- }
2880
- });
2881
-
2882
- const entityWithComplexShapesRequiredOnEdge = new Entity({
2883
- model: {
2884
- entity: "entity",
2885
- service: "service",
2886
- version: "1"
2887
- },
2888
- attributes: {
2889
- prop1: {
2890
- type: "string",
2891
- label: "props"
2892
- },
2893
- prop2: {
2894
- type: "string",
2895
- },
2896
- attrz3: {
2897
- type: "map",
2898
- properties: {
2899
- val1: {
2900
- type: "string",
2901
- required: true
2902
- }
2903
- }
2904
- },
2905
- attrz4: {
2906
- type: "list",
2907
- items: {
2908
- type: "map",
2909
- properties: {
2910
- val2: {
2911
- type: "number",
2912
- required: true,
2913
- },
2914
- val3: {
2915
- type: "list",
2916
- items: {
2917
- type: "string",
2918
- required: true
2919
- },
2920
- },
2921
- val4: {
2922
- type: "set",
2923
- items: "number",
2924
- },
2925
- val5: {
2926
- type: "map",
2927
- properties: {
2928
- val6: {
2929
- type: "string",
2930
- required: true
2931
- }
2932
- }
2933
- }
2934
- }
2935
- },
2936
- },
2937
- attrz5: {
2938
- type: "set",
2939
- items: "string",
2940
- },
2941
- attrz6: {
2942
- type: "set",
2943
- items: "string",
2944
- }
2945
- },
2946
- indexes: {
2947
- record: {
2948
- collection: "mops",
2949
- pk: {
2950
- field: "pk",
2951
- composite: ["prop1"]
2952
- },
2953
- sk: {
2954
- field: "sk",
2955
- composite: ["prop2"]
2956
- }
2957
- }
2958
- }
2959
- });
2960
-
2961
- const complexShapeService = new Service({
2962
- ent1: entityWithComplexShapesRequiredOnEdge,
2963
- ent2: entityWithComplexShapes,
2964
- ent3: entityWithComplexShapesRequired
2965
- });
2966
-
2967
- const parsed = entityWithComplexShapes.parse({});
2968
- entityWithComplexShapes.query
2969
- .record({prop1: "abc"})
2970
- .go()
2971
- .then((data) => {
2972
- expectType<typeof data>(
2973
- entityWithComplexShapes.parse({
2974
- Items: []
2975
- })
2976
- )
2977
- })
2978
-
2979
- entityWithComplexShapes.get({prop1: "abc", prop2: "def"}).go().then(data => {
2980
- expectType<typeof parsed>(data);
2981
- if (data === null) {
2982
- return null;
2983
- }
2984
- data.prop3?.val1;
2985
- let int = 0;
2986
- if (Array.isArray(data.prop4)) {
2987
- for (let value of data.prop4) {
2988
- if (typeof value === "string") {
2989
- if (isNaN(parseInt(value))) {
2990
- int += 0;
2991
- } else {
2992
- int += parseInt(value);
2993
- }
2994
- } else if (typeof value === "number") {
2995
- int += value;
2996
- } else if (Array.isArray(value)) {
2997
- for (let val of value) {
2998
- int += val.val2
2999
- }
3000
- } else {
3001
- expectType<number|undefined>(value.val2);
3002
- int += value?.val2 ?? 0;
3003
- }
3004
- }
3005
- }
3006
- return data.prop3?.val1
3007
- });
3008
-
3009
- entityWithComplexShapes
3010
- .get({prop1: "abc", prop2: "def"})
3011
- .go()
3012
- .then(data => {
3013
- if (data !== null) {
3014
- data.prop5?.map(values => values);
3015
- data.prop6?.map(values => values);
3016
- }
3017
- })
3018
-
3019
- entityWithComplexShapes
3020
- .update({prop1: "abc", prop2: "def"})
3021
- .set({
3022
- prop4: [{
3023
- val2: 789,
3024
- val3: ["123"],
3025
- val4: [123, 456]
3026
- }],
3027
- prop5: ["abc"]
3028
- })
3029
- .go()
3030
-
3031
- entityWithComplexShapes
3032
- .put({
3033
- prop1: "abc",
3034
- prop2: "def",
3035
- prop4: [{
3036
- val2: 789,
3037
- val3: ["123"],
3038
- val4: [123, 456]
3039
- }],
3040
- prop5: ["abc"]
3041
- })
3042
- .go()
3043
-
3044
- entityWithComplexShapes
3045
- .update({prop1: "abc", prop2: "def"})
3046
- .set({
3047
- prop4: [{
3048
- val2: 789,
3049
- val3: ["123"],
3050
- // val4: [1, 2, 3]
3051
- }],
3052
- prop5: ["abc"]
3053
- })
3054
- .where(({prop5}, {eq}) => eq(prop5, ["abc"]))
3055
- .where(({prop1}, {eq}) => eq(prop1, "abc"))
3056
- .go();
3057
-
3058
-
3059
- entityWithComplexShapes
3060
- .update({prop1: "abc", prop2: "def"})
3061
- .append({
3062
- prop4: [{
3063
- val2: 789,
3064
- val3: ["123"],
3065
- val4: [1, 2, 3]
3066
- }],
3067
- })
3068
- .data(({prop5, prop4}, {add, append, remove}) => {
3069
- add(prop5, ["abc"]);
3070
- append(prop4[0].val3, ["123"]);
3071
- append(prop4, [{
3072
- val2: 789,
3073
- val3: ["123"],
3074
- val4: [1, 2, 3]
3075
- }]);
3076
- add(prop4[0].val2, 789);
3077
- add(prop4[0].val4, [1]);
3078
- remove(prop4[0].val4);
3079
- remove(prop4[0].val3);
3080
- remove(prop4[0].val2);
3081
-
3082
- })
3083
- .go()
3084
-
3085
-
3086
- expectError(() => {
3087
- entityWithComplexShapes
3088
- .update({prop1: "abc", prop2: "def"})
3089
- .append({
3090
- prop4: [{
3091
- val2: 789,
3092
- val3: ["123"],
3093
- val4: [1, 2, 3]
3094
- }],
3095
- prop5: ["abc"]
3096
- })
3097
- .go()
3098
- });
3099
-
3100
- expectError(() => {
3101
- entityWithComplexShapes
3102
- .update({prop1: "abc", prop2: "def"})
3103
- .data(({prop1}, {remove}) => {
3104
- remove(prop1);
3105
- })
3106
- .go()
3107
- });
3108
-
3109
- entityWithComplexShapes
3110
- .update({prop1: "abc", prop2: "def"})
3111
- .set({
3112
- prop4: [{
3113
- val2: 789,
3114
- val3: ["123"],
3115
- val4: [1, 2, 3]
3116
- }],
3117
- prop5: ["abc"]
3118
- })
3119
- .go()
3120
-
3121
- entityWithComplexShapesRequired.put({
3122
- prop1: "abc",
3123
- prop2: "def",
3124
- attr3: {
3125
- val1: "abc",
3126
- },
3127
- attr4: [{
3128
- val2: 789,
3129
- val3: ["123"],
3130
- val4: [1, 2, 3]
3131
- }],
3132
- attr5: ["abc"],
3133
- attr6: ["abdbdb"],
3134
- });
3135
-
3136
- expectError(() => {
3137
- entityWithComplexShapesRequired.put({});
3138
- })
3139
-
3140
- expectError(() => {
3141
- entityWithComplexShapesRequired.put({prop1: "abc", prop2: "def"});
3142
- });
3143
-
3144
- complexShapeService.collections
3145
- .mops({prop1: "abc"})
3146
- .where((a, op) => {
3147
- op.eq(a.attr3.val1, "abd");
3148
- expectError(() => op.eq(a.attr3, "abc"));
3149
- expectError(() => op.eq(a.attr3.val2, "abc"));
3150
- expectError(() => op.eq(a.attr3.val1, 123));
3151
- op.between(a.attr4[0].val2, 789, 888);
3152
- expectError(() => op.eq(a.attr4, "abc"));
3153
- expectError(() => op.eq(a.attr4.val2, "abc"));
3154
- expectError(() => op.eq(a.attr4[0].val2, "456"));
3155
- op.between(a.attr4[0].val3[1], "xyz", "123");
3156
- // expectNotAssignable<"abc">(a.attr4[1].val3[1]);
3157
- // expectNotAssignable<typeof (a.attr4[1].val3)>(["abc"]);
3158
- // expectError(() => op.eq(a.attr4[1].val3["def"], "xyz"));
3159
- op.gte(a.attr5, ["abc"]);
3160
-
3161
- op.eq(a.attrz3.val1, "abd");
3162
- expectError(() => op.eq(a.attrz3, "abc"))
3163
- expectError(() => op.eq(a.attrz3.val2, "abc"))
3164
- expectError(() => op.eq(a.attrz3.val1, 123));
3165
- op.between(a.attrz4[0].val2, 789, 888);
3166
- // expectNotAssignable<"abc">(a.attrz4[1].val3[1]);
3167
- // expectNotAssignable<["abc"]>(a.attrz4[1].val3);
3168
- expectError(() => op.eq(a.attrz4[0].val2, "456"));
3169
- op.between(a.attrz4[0].val3[1], "xyz", "123");
3170
- // expectError(() => op.eq(a.attr4[1].val3[1], "abc"));
3171
- // expectError(() => op.eq(a.attr4[1].val3["def"], "xyz"));
3172
- op.gte(a.attrz5, ["abc"]);
3173
-
3174
- op.eq(a.prop3.val1, "abd");
3175
- expectError(() => op.eq(a.attrz3, "abc"))
3176
- expectError(() => op.eq(a.attrz3.val2, "abc"))
3177
- expectError(() => op.eq(a.attrz3.val1, 123))
3178
- op.between(a.prop4[0].val2, 789, 888);
3179
- op.between(a.prop4[0].val3[1], "xyz", "123");
3180
- op.gte(a.prop5, ["abc"])
3181
- op.eq(a.prop2, "def");
3182
- op.contains(a.prop4[1].val3[2], "123");
3183
-
3184
- return "";
3185
- })
3186
-
3187
- const complex = new Entity({
3188
- model: {
3189
- entity: "user",
3190
- service: "versioncontrol",
3191
- version: "1"
3192
- },
3193
- attributes: {
3194
- stringVal: {
3195
- type: "string",
3196
- default: () => "abc",
3197
- validate: (value) => value !== undefined,
3198
- get: (value) => {
3199
- return value;
3200
- },
3201
- set: (value) => {
3202
- return value;
3203
- }
3204
- },
3205
- enumVal: {
3206
- type: ["abc", "def"] as const,
3207
- validate: (value: "abc" | "def") => value !== undefined,
3208
- default: () => "abc",
3209
- get: (value: "abc" | "def") => {
3210
- return value;
3211
- },
3212
- set: (value?: "abc" | "def") => {
3213
- return value;
3214
- }
3215
- },
3216
- numVal: {
3217
- type: "number",
3218
- validate: (value) => value !== undefined,
3219
- default: () => 123,
3220
- get: (value) => {
3221
- return value;
3222
- },
3223
- set: (value) => {
3224
- return value;
3225
- }
3226
- },
3227
- boolValue: {
3228
- type: "boolean",
3229
- validate: (value) => value !== undefined,
3230
- default: () => true,
3231
- get: (value) => {
3232
- return value;
3233
- },
3234
- set: (value) => {
3235
- return value;
3236
- }
3237
- },
3238
- stringSetValue: {
3239
- type: "set",
3240
- items: "string",
3241
- validate: (value) => value !== undefined,
3242
- default: () => ["abc"],
3243
- get: (value) => {
3244
- return value;
3245
- },
3246
- set: (value) => {
3247
- return value;
3248
- }
3249
- },
3250
- numberSetValue: {
3251
- type: "set",
3252
- items: "number",
3253
- validate: (value) => value !== undefined,
3254
- default: () => [1],
3255
- get: (value) => {
3256
- return value;
3257
- },
3258
- set: (value) => {
3259
- return value;
3260
- }
3261
- },
3262
- stringListValue: {
3263
- type: "list",
3264
- items: {
3265
- type: "string",
3266
- default: "abc",
3267
- validate: (value) => value !== undefined,
3268
- get: (value) => {
3269
- return value;
3270
- },
3271
- set: (value) => {
3272
- return value;
3273
- }
3274
- },
3275
- default: ["abc"],
3276
- validate: (value: string[]) => value !== undefined,
3277
- get: (value: string[]) => {
3278
- return value;
3279
- },
3280
- set: (value?: string[]) => {
3281
- return value;
3282
- }
3283
- },
3284
- numberListValue: {
3285
- type: "list",
3286
- items: {
3287
- type: "number",
3288
- validate: (value) => value !== undefined,
3289
- default: 0,
3290
- get: (value) => {
3291
- return value;
3292
- },
3293
- set: (value) => {
3294
- return value;
3295
- }
3296
- },
3297
- default: [],
3298
- validate: (value: number[]) => value !== undefined,
3299
- get: (value: number[]) => {
3300
- return value;
3301
- },
3302
- set: (value?: number[]) => {
3303
- return value;
3304
- }
3305
- },
3306
- mapListValue: {
3307
- type: "list",
3308
- items: {
3309
- type: "map",
3310
- properties: {
3311
- stringVal: {
3312
- type: "string",
3313
- default: "def",
3314
- validate: (value) => value !== undefined,
3315
- get: (value) => {
3316
- return value;
3317
- },
3318
- set: (value) => {
3319
- return value;
3320
- }
3321
- },
3322
- numVal: {
3323
- type: "number",
3324
- default: 5,
3325
- validate: (value) => value !== undefined,
3326
- get: (value) => {
3327
- return value;
3328
- },
3329
- set: (value) => {
3330
- return value;
3331
- }
3332
- },
3333
- boolValue: {
3334
- type: "boolean",
3335
- default: false,
3336
- validate: (value) => value !== undefined,
3337
- get: (value) => {
3338
- return value;
3339
- },
3340
- set: (value) => {
3341
- return value;
3342
- }
3343
- },
3344
- enumVal: {
3345
- type: ["abc", "def"] as const,
3346
- validate: (value: "abc" | "def") => value !== undefined,
3347
- default: () => "abc",
3348
- get: (value: "abc" | "def") => {
3349
- return value;
3350
- },
3351
- set: (value?: "abc" | "def") => {
3352
- return value;
3353
- }
3354
- },
3355
- },
3356
- validate: (value) => value !== undefined,
3357
- default: {
3358
- stringVal: "abc",
3359
- numVal: 123,
3360
- boolValue: false,
3361
- },
3362
- get: (value) => {
3363
- return value;
3364
- },
3365
- set: (value) => {
3366
- return value;
3367
- }
3368
- },
3369
- get: (value: any) => {
3370
- return value;
3371
- },
3372
- set: (value: any) => {
3373
- return value;
3374
- }
3375
- },
3376
- mapValue: {
3377
- type: "map",
3378
- properties: {
3379
- stringVal: {
3380
- type: "string",
3381
- default: () => "abc",
3382
- validate: (value) => value !== undefined,
3383
- get: (value) => {
3384
- return value;
3385
- },
3386
- set: (value) => {
3387
- return value;
3388
- }
3389
- },
3390
- numVal: {
3391
- type: "number",
3392
- default: () => 10,
3393
- validate: (value) => value !== undefined,
3394
- get: (value) => {
3395
- return value;
3396
- },
3397
- set: (value) => {
3398
- return value;
3399
- }
3400
- },
3401
- boolValue: {
3402
- type: "boolean",
3403
- default: () => false,
3404
- validate: (value) => value !== undefined,
3405
- get: (value) => {
3406
- return value;
3407
- },
3408
- set: (value) => {
3409
- return value;
3410
- }
3411
- },
3412
- enumVal: {
3413
- type: ["abc", "def"] as const,
3414
- validate: (value: "abc" | "def") => value !== undefined,
3415
- default: () => "abc",
3416
- get: (value: "abc" | "def") => {
3417
- return value;
3418
- },
3419
- set: (value?: "abc" | "def") => {
3420
- return value;
3421
- }
3422
- },
3423
- stringListValue: {
3424
- type: "list",
3425
- items: {
3426
- type: "string",
3427
- default: "abc",
3428
- validate: (value) => value !== undefined,
3429
- get: (value) => {
3430
- return value;
3431
- },
3432
- set: (value) => {
3433
- return value;
3434
- }
3435
- },
3436
- default: [],
3437
- validate: (value: string[]) => value !== undefined,
3438
- get: (value: string[]) => {
3439
- return value;
3440
- },
3441
- set: (value?: string[]) => {
3442
- return value;
3443
- }
3444
- },
3445
- numberListValue: {
3446
- type: "list",
3447
- items: {
3448
- type: "number",
3449
- default: () => 100,
3450
- validate: (value) => value !== undefined,
3451
- get: (value) => {
3452
- return value;
3453
- },
3454
- set: (value) => {
3455
- return value;
3456
- }
3457
- },
3458
- default: [123, 123],
3459
- validate: (value: number[]) => value !== undefined,
3460
- get: (value: number[]) => {
3461
- return value;
3462
- },
3463
- set: (value?: number[]) => {
3464
- return value;
3465
- }
3466
- },
3467
- mapListValue: {
3468
- type: "list",
3469
- items: {
3470
- type: "map",
3471
- properties: {
3472
- stringVal: {
3473
- type: "string",
3474
- default: "def",
3475
- validate: (value) => value !== undefined,
3476
- get: (value) => {
3477
- return value;
3478
- },
3479
- set: (value) => {
3480
- return value;
3481
- }
3482
- },
3483
- numVal: {
3484
- type: "number",
3485
- default: 100,
3486
- validate: (value) => value !== undefined,
3487
- get: (value) => {
3488
- return value;
3489
- },
3490
- set: (value) => {
3491
- return value;
3492
- }
3493
- },
3494
- boolValue: {
3495
- type: "boolean",
3496
- default: () => false,
3497
- validate: (value) => value !== undefined,
3498
- get: (value) => {
3499
- return value;
3500
- },
3501
- set: (value) => {
3502
- return value;
3503
- }
3504
- },
3505
- stringSetValue: {
3506
- type: "set",
3507
- items: "string",
3508
- default: ["abc"],
3509
- validate: (value) => value !== undefined,
3510
- get: (value) => {
3511
- return value;
3512
- },
3513
- set: (value) => {
3514
- return value;
3515
- }
3516
- },
3517
- numberSetValue: {
3518
- type: "set",
3519
- items: "number",
3520
- default: [5],
3521
- validate: (value) => value !== undefined,
3522
- get: (value) => {
3523
- return value;
3524
- },
3525
- set: (value) => {
3526
- return value;
3527
- }
3528
- },
3529
- enumVal: {
3530
- type: ["abc", "def"] as const,
3531
- validate: (value: "abc" | "def") => value !== undefined,
3532
- default: () => "abc",
3533
- get: (value: "abc" | "def") => {
3534
- return value;
3535
- },
3536
- set: (value?: "abc" | "def") => {
3537
- return value;
3538
- }
3539
- },
3540
- },
3541
- default: () => ({
3542
- stringVal: "anx",
3543
- numVal: 13,
3544
- boolValue: true,
3545
- emumValue: "abc",
3546
- stringSetValue: ["def"],
3547
- numberSetValue: [10],
3548
- }),
3549
- validate: (value) => value !== undefined,
3550
- get: (value) => {
3551
- return value;
3552
- },
3553
- set: (value) => {
3554
- return value;
3555
- }
3556
- },
3557
- default: [],
3558
- validate: (value: Record<string, any>[]) => value !== undefined,
3559
- get: (value: Record<string, any>[]) => {
3560
- return value;
3561
- },
3562
- set: (value?: Record<string, any>[]) => {
3563
- return value;
3564
- }
3565
- },
3566
- },
3567
- default: () => undefined,
3568
- validate: (value) => value !== undefined,
3569
- get: (value) => {
3570
- return value;
3571
- },
3572
- set: (value) => {
3573
- return value;
3574
- }
3575
- }
3576
- },
3577
- indexes: {
3578
- user: {
3579
- collection: "complexShapes",
3580
- pk: {
3581
- composite: ["username"],
3582
- field: "pk"
3583
- },
3584
- sk: {
3585
- composite: [],
3586
- field: "sk"
3587
- }
3588
- },
3589
- _: {
3590
- collection: "owned",
3591
- index: "gsi1pk-gsi1sk-index",
3592
- pk: {
3593
- composite: ["username"],
3594
- field: "gsi1pk"
3595
- },
3596
- sk: {
3597
- field: "gsi1sk",
3598
- composite: []
3599
- }
3600
- }
3601
- }
3602
- }, {table: "abc"});
3603
-
3604
- const mapTests = new Entity({
3605
- model: {
3606
- entity: "mapTests",
3607
- service: "tests",
3608
- version: "1"
3609
- },
3610
- attributes: {
3611
- username: {
3612
- type: "string"
3613
- },
3614
- mapObject: {
3615
- type: "map",
3616
- properties: {
3617
- minimal: {
3618
- type: "string"
3619
- },
3620
- required: {
3621
- type: "string",
3622
- required: true
3623
- },
3624
- hidden: {
3625
- type: "string",
3626
- hidden: true
3627
- },
3628
- readOnly: {
3629
- type: "string",
3630
- readOnly: true
3631
- },
3632
- anotherMap: {
3633
- type: "map",
3634
- properties: {
3635
- minimal: {
3636
- type: "string"
3637
- },
3638
- required: {
3639
- type: "string",
3640
- required: true
3641
- },
3642
- hidden: {
3643
- type: "string",
3644
- hidden: true
3645
- },
3646
- readOnly: {
3647
- type: "string",
3648
- readOnly: true
3649
- }
3650
- }
3651
- }
3652
- }
3653
- }
3654
- },
3655
- indexes: {
3656
- user: {
3657
- collection: "complexShapes",
3658
- pk: {
3659
- composite: ["username"],
3660
- field: "pk"
3661
- },
3662
- sk: {
3663
- composite: [],
3664
- field: "sk"
3665
- }
3666
- }
3667
- }
3668
- });
3669
-
3670
- const complexAttributeService = new Service({mapTests, complex});
3671
-
3672
- mapTests
3673
- .get({username: "test"})
3674
- .go()
3675
- .then(data => {
3676
- if (data && data.mapObject !== undefined) {
3677
- expectNotAssignable<string>(data.mapObject.hidden);
3678
- expectType<undefined|string>(data.mapObject.minimal);
3679
- expectType<undefined|string>(data.mapObject.readOnly);
3680
- expectType<string>(data.mapObject.required);
3681
- }
3682
- });
3683
-
3684
-
3685
- type MapTestPutParameters = Parameter<typeof mapTests.put>;
3686
- // just the key is fine because `mapObject` is not required
3687
- expectAssignable<MapTestPutParameters>([{username: "abc"}]);
3688
-
3689
- // with mapObject present, `required` is required
3690
- mapTests.put({username: "abc", mapObject: {required: "val"}});
3691
- mapTests.put([{username: "abc", mapObject: {required: "val"}}]);
3692
- expectError(() => {
3693
- mapTests.put({username: "abc", mapObject: {minimal: "abc"}});
3694
- });
3695
- expectError(() => {
3696
- mapTests.put([{username: "abc", mapObject: {minimal: "abc"}}]);
3697
- });
3698
-
3699
- // with anotherMap present, `required` is required
3700
- mapTests.put({username: "abc", mapObject: {required: "val", anotherMap: {required: "def"}}});
3701
- mapTests.put([{username: "abc", mapObject: {required: "val", anotherMap: {required: "def"}}}]);
3702
- expectError(() => {
3703
- mapTests.put({username: "abc", mapObject: {minimal: "abc", required: "def", anotherMap: {}}});
3704
- });
3705
- expectError(() => {
3706
- mapTests.put([{username: "abc", mapObject: {minimal: "abc", required: "def", anotherMap: {}}}]);
3707
- });
3708
-
3709
- //
3710
- mapTests.update({username: "abc"}).data((attr, op) => {
3711
- expectError(() => op.set(attr.mapObject.readOnly, "abc"));
3712
- expectError(() => op.set(attr.mapObject.anotherMap.readOnly, "abc"));
3713
-
3714
- op.set(attr.mapObject.minimal, "abc");
3715
- op.set(attr.mapObject.anotherMap.minimal, "abc");
3716
- op.set(attr.mapObject.hidden, "abc");
3717
- op.set(attr.mapObject.anotherMap.hidden, "abc");
3718
- op.set(attr.mapObject.required, "abc");
3719
- op.set(attr.mapObject.anotherMap.required, "abc");
3720
- // START SHOULD FAIL :(
3721
- // expectError(() => op.remove(attr.mapObject.readOnly));
3722
- // expectError(() => op.remove(attr.mapObject.required));
3723
- // expectError(() => op.set(attr.mapObject, {}));
3724
- // expectError(() => op.set(attr.mapObject, {minimal: "abc"}));
3725
- // END SHOULD FAIL :(
3726
- op.set(attr.mapObject, {required: "anc"});
3727
-
3728
- });
3729
-
3730
- expectError(() => mapTests.update({username: "abc"}).remove(["username"]));
3731
-
3732
- complexAttributeService.collections
3733
- .complexShapes({username: "abc"})
3734
- .where((attr, op) => {
3735
- op.eq(attr.mapObject.minimal, "abc");
3736
- op.eq(attr.numberListValue[0], 123)
3737
- op.eq(attr.mapListValue[1].enumVal, "def");
3738
- op.eq(attr.mapListValue[1].numVal, 345);
3739
- return "";
3740
- })
3741
- .go()
3742
-
3743
- // `value` operation should return the type of value for more constrained usage
3744
- complex.update({username: "abc"})
3745
- .data((attr, op) => {
3746
- const numberValue = op.value(attr.numVal, 10);
3747
- op.set(attr.numVal, numberValue);
3748
- op.set(attr.mapValue.numVal, numberValue);
3749
- expectError(() => op.set(attr.mapValue.stringVal, numberValue));
3750
- })
3751
- .where((attr, op) => {
3752
- const num = 10;
3753
- const numberValue = op.value(attr.numVal, num);
3754
- op.eq(attr.numVal, numberValue);
3755
- op.eq(attr.mapValue.numVal, numberValue);
3756
- expectError(() => op.eq(attr.mapValue.stringVal, numberValue));
3757
- return "";
3758
- })
3759
- .go()
3760
-
3761
- // casing property on schema
3762
- const casingEntity = new Entity({
3763
- model: {
3764
- service: "MallStoreDirectory",
3765
- entity: "MallStores",
3766
- version: "1",
3767
- },
3768
- attributes: {
3769
- id: {
3770
- type: "string",
3771
- field: "id",
3772
- },
3773
- mall: {
3774
- type: "string",
3775
- required: true,
3776
- field: "mall",
3777
- },
3778
- stores: {
3779
- type: "number",
3780
- },
3781
- value: {
3782
- type: "string"
3783
- }
3784
- },
3785
- indexes: {
3786
- store: {
3787
- collection: ["myCollection"],
3788
- pk: {
3789
- field: "parition_key",
3790
- composite: ["id"],
3791
- casing: "lower",
3792
- },
3793
- sk: {
3794
- field: "sort_key",
3795
- composite: ["mall", "stores"],
3796
- casing: "upper",
3797
- }
3798
- },
3799
- other: {
3800
- index: "idx1",
3801
- collection: "otherCollection",
3802
- pk: {
3803
- field: "parition_key_idx1",
3804
- composite: ["mall"],
3805
- casing: "upper",
3806
- },
3807
- sk: {
3808
- field: "sort_key_idx1",
3809
- composite: ["id", "stores"],
3810
- casing: "default",
3811
- }
3812
- }
3813
- }
3814
- }, {table: "StoreDirectory"});
3815
-
3816
- type RequiredIndexOptions = Required<Schema<any, any, any>["indexes"][string]>;
3817
- type PKCasingOptions = RequiredIndexOptions["pk"]["casing"];
3818
- type SKCasingOptions = RequiredIndexOptions["sk"]["casing"];
3819
- const allCasingOptions = "" as "default" | "upper" | "lower" | "none" | undefined;
3820
- expectAssignable<PKCasingOptions>(allCasingOptions);
3821
- expectAssignable<SKCasingOptions>(allCasingOptions);
3822
- expectError<PKCasingOptions>("not_available");
3823
- expectError<SKCasingOptions>("not_available");
3824
-
3825
- type AvailableParsingOptions = Parameters<typeof casingEntity.parse>[1]
3826
- expectAssignable<AvailableParsingOptions>(undefined);
3827
- expectAssignable<AvailableParsingOptions>({});
3828
- expectAssignable<AvailableParsingOptions>({ignoreOwnership: true});
3829
- expectAssignable<AvailableParsingOptions>({ignoreOwnership: false});