mocody 0.2.15 → 0.2.18
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/LICENSE +21 -21
- package/README.md +4 -4
- package/dist/core/base-schema.d.ts +13 -13
- package/dist/core/base-schema.js +11 -11
- package/dist/core/base-schema.js.map +1 -1
- package/dist/couch/couch-data-operation.d.ts +90 -90
- package/dist/couch/couch-data-operation.js +581 -581
- package/dist/couch/couch-data-operation.js.map +1 -1
- package/dist/couch/couch-filter-query-operation.d.ts +47 -47
- package/dist/couch/couch-filter-query-operation.js +438 -438
- package/dist/couch/couch-initializer.d.ts +45 -45
- package/dist/couch/couch-initializer.js +98 -98
- package/dist/couch/couch-initializer.js.map +1 -1
- package/dist/couch/couch-manage-table.d.ts +46 -46
- package/dist/couch/couch-manage-table.js +113 -113
- package/dist/dynamo/dynamo-data-operation.d.ts +97 -97
- package/dist/dynamo/dynamo-data-operation.js +788 -793
- package/dist/dynamo/dynamo-data-operation.js.map +1 -1
- package/dist/dynamo/dynamo-filter-query-operation.d.ts +29 -28
- package/dist/dynamo/dynamo-filter-query-operation.js +655 -627
- package/dist/dynamo/dynamo-filter-query-operation.js.map +1 -1
- package/dist/dynamo/dynamo-helper.d.ts +1 -1
- package/dist/dynamo/dynamo-helper.js +8 -8
- package/dist/dynamo/dynamo-initializer.d.ts +14 -8
- package/dist/dynamo/dynamo-initializer.js +58 -34
- package/dist/dynamo/dynamo-initializer.js.map +1 -1
- package/dist/dynamo/dynamo-manage-table.d.ts +33 -32
- package/dist/dynamo/dynamo-manage-table.js +419 -418
- package/dist/dynamo/dynamo-manage-table.js.map +1 -1
- package/dist/dynamo/dynamo-query-scan-processor.d.ts +25 -24
- package/dist/dynamo/dynamo-query-scan-processor.js +268 -266
- package/dist/dynamo/dynamo-query-scan-processor.js.map +1 -1
- package/dist/helpers/base-joi-helper.d.ts +2 -2
- package/dist/helpers/base-joi-helper.js +12 -12
- package/dist/helpers/constants.d.ts +3 -3
- package/dist/helpers/constants.js +6 -6
- package/dist/helpers/errors.d.ts +13 -13
- package/dist/helpers/errors.js +38 -38
- package/dist/helpers/logging-service.d.ts +8 -8
- package/dist/helpers/logging-service.js +44 -44
- package/dist/helpers/mocody-utils.d.ts +13 -15
- package/dist/helpers/mocody-utils.js +48 -48
- package/dist/helpers/query-validator.d.ts +20 -20
- package/dist/helpers/query-validator.js +96 -84
- package/dist/helpers/query-validator.js.map +1 -1
- package/dist/helpers/util-service.d.ts +29 -29
- package/dist/helpers/util-service.js +155 -155
- package/dist/index.d.ts +10 -10
- package/dist/index.js +19 -19
- package/dist/model/index.d.ts +40 -40
- package/dist/model/index.js +6 -6
- package/dist/mongo/mongo-data-operation.d.ts +88 -88
- package/dist/mongo/mongo-data-operation.js +597 -597
- package/dist/mongo/mongo-data-operation.js.map +1 -1
- package/dist/mongo/mongo-filter-query-operation.d.ts +47 -47
- package/dist/mongo/mongo-filter-query-operation.js +433 -433
- package/dist/mongo/mongo-initializer.d.ts +16 -16
- package/dist/mongo/mongo-initializer.js +47 -47
- package/dist/mongo/mongo-initializer.js.map +1 -1
- package/dist/mongo/mongo-table-manager.d.ts +31 -31
- package/dist/mongo/mongo-table-manager.js +104 -104
- package/dist/type/index.d.ts +109 -108
- package/dist/type/index.js +2 -2
- package/package.json +70 -72
|
@@ -1,628 +1,656 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DynamoFilterQueryOperation = void 0;
|
|
4
|
-
const query_validator_1 = require("./../helpers/query-validator");
|
|
5
|
-
const logging_service_1 = require("../helpers/logging-service");
|
|
6
|
-
const util_service_1 = require("../helpers/util-service");
|
|
7
|
-
const errors_1 = require("../helpers/errors");
|
|
8
|
-
const dynamo_helper_1 = require("./dynamo-helper");
|
|
9
|
-
const keyConditionMap = {
|
|
10
|
-
$eq: "=",
|
|
11
|
-
$lt: "<",
|
|
12
|
-
$lte: "<=",
|
|
13
|
-
$gt: ">",
|
|
14
|
-
$gte: ">=",
|
|
15
|
-
$beginsWith: "",
|
|
16
|
-
$between: "",
|
|
17
|
-
};
|
|
18
|
-
const conditionMapPre = {
|
|
19
|
-
$ne: "<>",
|
|
20
|
-
$exists: "",
|
|
21
|
-
$in: "",
|
|
22
|
-
$nin: "",
|
|
23
|
-
$not: "",
|
|
24
|
-
$contains: "",
|
|
25
|
-
$notContains: "",
|
|
26
|
-
$elemMatch: "",
|
|
27
|
-
$nestedMatch: "",
|
|
28
|
-
};
|
|
29
|
-
const conditionMap = { ...keyConditionMap, ...conditionMapPre };
|
|
30
|
-
function hasQueryConditionValue(key) {
|
|
31
|
-
if (key && Object.keys(conditionMap).includes(key) && conditionMap[key]) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
class DynamoFilterQueryOperation {
|
|
37
|
-
operation__filterFieldExist({ fieldName }) {
|
|
38
|
-
const attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
39
|
-
const result = {
|
|
40
|
-
xExpressionAttributeNames: {
|
|
41
|
-
[attrKeyHash]: fieldName,
|
|
42
|
-
},
|
|
43
|
-
xFilterExpression: `attribute_exists (${attrKeyHash})`,
|
|
44
|
-
};
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
operation__filterFieldNotExist({ fieldName }) {
|
|
48
|
-
const attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
49
|
-
const result = {
|
|
50
|
-
xExpressionAttributeNames: {
|
|
51
|
-
[attrKeyHash]: fieldName,
|
|
52
|
-
},
|
|
53
|
-
xFilterExpression: `attribute_not_exists (${attrKeyHash})`,
|
|
54
|
-
};
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
operation__helperFilterBasic({ fieldName, val, conditionExpr, }) {
|
|
58
|
-
const keyAttr = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
59
|
-
const attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
60
|
-
const result = {
|
|
61
|
-
xExpressionAttributeValues: {
|
|
62
|
-
[keyAttr]: val,
|
|
63
|
-
},
|
|
64
|
-
xExpressionAttributeNames: {
|
|
65
|
-
[attrKeyHash]: fieldName,
|
|
66
|
-
},
|
|
67
|
-
xFilterExpression: [attrKeyHash, conditionExpr, keyAttr].join(" "),
|
|
68
|
-
};
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
operation__filterIn({ fieldName, attrValues }) {
|
|
72
|
-
const expressAttrVal = {};
|
|
73
|
-
const expressAttrName = {};
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
expressAttrName[
|
|
77
|
-
attrValues.forEach((item) => {
|
|
78
|
-
const keyAttr = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
_queryConditions
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
if (
|
|
594
|
-
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
}
|
|
627
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamoFilterQueryOperation = void 0;
|
|
4
|
+
const query_validator_1 = require("./../helpers/query-validator");
|
|
5
|
+
const logging_service_1 = require("../helpers/logging-service");
|
|
6
|
+
const util_service_1 = require("../helpers/util-service");
|
|
7
|
+
const errors_1 = require("../helpers/errors");
|
|
8
|
+
const dynamo_helper_1 = require("./dynamo-helper");
|
|
9
|
+
const keyConditionMap = {
|
|
10
|
+
$eq: "=",
|
|
11
|
+
$lt: "<",
|
|
12
|
+
$lte: "<=",
|
|
13
|
+
$gt: ">",
|
|
14
|
+
$gte: ">=",
|
|
15
|
+
$beginsWith: "",
|
|
16
|
+
$between: "",
|
|
17
|
+
};
|
|
18
|
+
const conditionMapPre = {
|
|
19
|
+
$ne: "<>",
|
|
20
|
+
$exists: "",
|
|
21
|
+
$in: "",
|
|
22
|
+
$nin: "",
|
|
23
|
+
$not: "",
|
|
24
|
+
$contains: "",
|
|
25
|
+
$notContains: "",
|
|
26
|
+
$elemMatch: "",
|
|
27
|
+
$nestedMatch: "",
|
|
28
|
+
};
|
|
29
|
+
const conditionMap = { ...keyConditionMap, ...conditionMapPre };
|
|
30
|
+
function hasQueryConditionValue(key) {
|
|
31
|
+
if (key && Object.keys(conditionMap).includes(key) && conditionMap[key]) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
class DynamoFilterQueryOperation {
|
|
37
|
+
operation__filterFieldExist({ fieldName }) {
|
|
38
|
+
const attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
39
|
+
const result = {
|
|
40
|
+
xExpressionAttributeNames: {
|
|
41
|
+
[attrKeyHash]: fieldName,
|
|
42
|
+
},
|
|
43
|
+
xFilterExpression: `attribute_exists (${attrKeyHash})`,
|
|
44
|
+
};
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
operation__filterFieldNotExist({ fieldName }) {
|
|
48
|
+
const attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
49
|
+
const result = {
|
|
50
|
+
xExpressionAttributeNames: {
|
|
51
|
+
[attrKeyHash]: fieldName,
|
|
52
|
+
},
|
|
53
|
+
xFilterExpression: `attribute_not_exists (${attrKeyHash})`,
|
|
54
|
+
};
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
operation__helperFilterBasic({ fieldName, val, conditionExpr, }) {
|
|
58
|
+
const keyAttr = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
59
|
+
const attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
60
|
+
const result = {
|
|
61
|
+
xExpressionAttributeValues: {
|
|
62
|
+
[keyAttr]: val,
|
|
63
|
+
},
|
|
64
|
+
xExpressionAttributeNames: {
|
|
65
|
+
[attrKeyHash]: fieldName,
|
|
66
|
+
},
|
|
67
|
+
xFilterExpression: [attrKeyHash, conditionExpr, keyAttr].join(" "),
|
|
68
|
+
};
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
operation__filterIn({ fieldName, attrValues, }) {
|
|
72
|
+
const expressAttrVal = {};
|
|
73
|
+
const expressAttrName = {};
|
|
74
|
+
const valuesVariable = [];
|
|
75
|
+
const attrKeyVariale = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
76
|
+
expressAttrName[attrKeyVariale] = fieldName;
|
|
77
|
+
attrValues.forEach((item, i) => {
|
|
78
|
+
const keyAttr = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
79
|
+
if (typeof item === "number") {
|
|
80
|
+
expressAttrVal[keyAttr] = { N: item };
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
expressAttrVal[keyAttr] = { S: item };
|
|
84
|
+
}
|
|
85
|
+
valuesVariable.push(keyAttr);
|
|
86
|
+
});
|
|
87
|
+
const filterExpressionValue01 = `${attrKeyVariale} IN (${valuesVariable.join(", ")})`;
|
|
88
|
+
const result = {
|
|
89
|
+
xExpressionAttributeValues: {
|
|
90
|
+
...expressAttrVal,
|
|
91
|
+
},
|
|
92
|
+
xExpressionAttributeNames: {
|
|
93
|
+
...expressAttrName,
|
|
94
|
+
},
|
|
95
|
+
xFilterExpression: filterExpressionValue01,
|
|
96
|
+
};
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
operation__filterIn_00({ fieldName, attrValues, }) {
|
|
100
|
+
const expressAttrVal = {};
|
|
101
|
+
const expressAttrName = {};
|
|
102
|
+
const filterExpress = [];
|
|
103
|
+
const _attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
104
|
+
expressAttrName[_attrKeyHash] = fieldName;
|
|
105
|
+
attrValues.forEach((item) => {
|
|
106
|
+
const keyAttr = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
107
|
+
expressAttrVal[keyAttr] = item;
|
|
108
|
+
filterExpress.push(`${_attrKeyHash} = ${keyAttr}`);
|
|
109
|
+
});
|
|
110
|
+
const _filterExpression = filterExpress.join(" OR ").trim();
|
|
111
|
+
const _filterExpressionValue = filterExpress.length > 1 ? `(${_filterExpression})` : _filterExpression;
|
|
112
|
+
const result = {
|
|
113
|
+
xExpressionAttributeValues: {
|
|
114
|
+
...expressAttrVal,
|
|
115
|
+
},
|
|
116
|
+
xExpressionAttributeNames: {
|
|
117
|
+
...expressAttrName,
|
|
118
|
+
},
|
|
119
|
+
xFilterExpression: _filterExpressionValue,
|
|
120
|
+
};
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
operation__filterElemMatch({ fieldName, attrValues, }) {
|
|
124
|
+
const result = [];
|
|
125
|
+
attrValues.$in.forEach((term) => {
|
|
126
|
+
const query01 = this.operation__filterContains({ term, fieldName });
|
|
127
|
+
result.push(query01);
|
|
128
|
+
});
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
operation__filterNestedMatchObject({ fieldName, attrValues, }) {
|
|
132
|
+
const results = [];
|
|
133
|
+
Object.entries(attrValues).forEach(([subFieldName, queryval]) => {
|
|
134
|
+
let _queryValue;
|
|
135
|
+
if (queryval && typeof queryval === "object") {
|
|
136
|
+
_queryValue = { ...queryval };
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
_queryValue = { $eq: queryval };
|
|
140
|
+
}
|
|
141
|
+
Object.entries(_queryValue).forEach(([condKey, conditionValue]) => {
|
|
142
|
+
const conditionKey = condKey;
|
|
143
|
+
if (!Object.keys(keyConditionMap).includes(conditionKey)) {
|
|
144
|
+
throw errors_1.MocodyErrorUtilsService.mocody_helper_createFriendlyError(`Invalid query key: ${conditionKey} @ NestedMatchObject`);
|
|
145
|
+
}
|
|
146
|
+
const conditionExpr = keyConditionMap[conditionKey];
|
|
147
|
+
const attrValue = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
148
|
+
const attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
149
|
+
const parentFieldName = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
150
|
+
if (conditionExpr) {
|
|
151
|
+
const result = {
|
|
152
|
+
xExpressionAttributeValues: {
|
|
153
|
+
[attrValue]: conditionValue,
|
|
154
|
+
},
|
|
155
|
+
xExpressionAttributeNames: {
|
|
156
|
+
[attrKeyHash]: subFieldName,
|
|
157
|
+
[parentFieldName]: fieldName,
|
|
158
|
+
},
|
|
159
|
+
xFilterExpression: [`${parentFieldName}.${attrKeyHash}`, conditionExpr, attrValue].join(" "),
|
|
160
|
+
};
|
|
161
|
+
results.push(result);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
if (conditionKey === "$between") {
|
|
165
|
+
query_validator_1.QueryValidatorCheck.between(conditionValue);
|
|
166
|
+
const fromKey = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
167
|
+
const toKey = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
168
|
+
const [fromVal, toVal] = conditionValue;
|
|
169
|
+
const result = {
|
|
170
|
+
xExpressionAttributeValues: {
|
|
171
|
+
[fromKey]: fromVal,
|
|
172
|
+
[toKey]: toVal,
|
|
173
|
+
},
|
|
174
|
+
xExpressionAttributeNames: {
|
|
175
|
+
[attrKeyHash]: subFieldName,
|
|
176
|
+
[parentFieldName]: fieldName,
|
|
177
|
+
},
|
|
178
|
+
xFilterExpression: [`${parentFieldName}.${attrKeyHash}`, "between", fromKey, "and", toKey].join(" "),
|
|
179
|
+
};
|
|
180
|
+
results.push(result);
|
|
181
|
+
}
|
|
182
|
+
else if (conditionKey === "$beginsWith") {
|
|
183
|
+
const result = {
|
|
184
|
+
xExpressionAttributeValues: {
|
|
185
|
+
[attrValue]: conditionValue,
|
|
186
|
+
},
|
|
187
|
+
xExpressionAttributeNames: {
|
|
188
|
+
[attrKeyHash]: subFieldName,
|
|
189
|
+
[parentFieldName]: fieldName,
|
|
190
|
+
},
|
|
191
|
+
xFilterExpression: `begins_with (${parentFieldName}.${attrKeyHash}, ${attrValue})`,
|
|
192
|
+
};
|
|
193
|
+
results.push(result);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
throw errors_1.MocodyErrorUtilsService.mocody_helper_createFriendlyError(`Query key: ${conditionKey} not currently supported`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
return results;
|
|
202
|
+
}
|
|
203
|
+
operation__filterContains({ fieldName, term }) {
|
|
204
|
+
const attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
205
|
+
const keyAttr = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
206
|
+
const result = {
|
|
207
|
+
xExpressionAttributeValues: {
|
|
208
|
+
[keyAttr]: term,
|
|
209
|
+
},
|
|
210
|
+
xExpressionAttributeNames: {
|
|
211
|
+
[attrKeyHash]: fieldName,
|
|
212
|
+
},
|
|
213
|
+
xFilterExpression: `contains (${attrKeyHash}, ${keyAttr})`,
|
|
214
|
+
};
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
operation__filterNot({ fieldName, selectorValues, }) {
|
|
218
|
+
const selector = { ...selectorValues };
|
|
219
|
+
const mConditions = [];
|
|
220
|
+
Object.entries(selector).forEach(([conditionKey, conditionValue]) => {
|
|
221
|
+
if (hasQueryConditionValue(conditionKey)) {
|
|
222
|
+
const _conditionKey01 = conditionKey;
|
|
223
|
+
if (_conditionKey01 === "$beginsWith") {
|
|
224
|
+
query_validator_1.QueryValidatorCheck.beginWith(conditionValue);
|
|
225
|
+
const _queryConditions = this.operation__filterBeginsWith({
|
|
226
|
+
fieldName: fieldName,
|
|
227
|
+
term: conditionValue,
|
|
228
|
+
});
|
|
229
|
+
mConditions.push(_queryConditions);
|
|
230
|
+
}
|
|
231
|
+
else if (_conditionKey01 === "$between") {
|
|
232
|
+
query_validator_1.QueryValidatorCheck.between(conditionValue);
|
|
233
|
+
const [from, to] = conditionValue;
|
|
234
|
+
const _queryConditions = this.operation__filterBetween({
|
|
235
|
+
fieldName: fieldName,
|
|
236
|
+
from,
|
|
237
|
+
to,
|
|
238
|
+
});
|
|
239
|
+
mConditions.push(_queryConditions);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
const conditionExpr = conditionMap[conditionKey];
|
|
243
|
+
if (conditionExpr) {
|
|
244
|
+
const _queryConditions = this.operation__helperFilterBasic({
|
|
245
|
+
fieldName: fieldName,
|
|
246
|
+
val: conditionValue,
|
|
247
|
+
conditionExpr: conditionExpr,
|
|
248
|
+
});
|
|
249
|
+
mConditions.push(_queryConditions);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
query_validator_1.QueryValidatorCheck.throwQueryNotFound(conditionKey);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
return mConditions;
|
|
258
|
+
}
|
|
259
|
+
operation__filterBetween({ fieldName, from, to, }) {
|
|
260
|
+
const _attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
261
|
+
const _fromKey = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
262
|
+
const _toKey = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
263
|
+
const result = {
|
|
264
|
+
xExpressionAttributeValues: {
|
|
265
|
+
[_fromKey]: from,
|
|
266
|
+
[_toKey]: to,
|
|
267
|
+
},
|
|
268
|
+
xExpressionAttributeNames: {
|
|
269
|
+
[_attrKeyHash]: fieldName,
|
|
270
|
+
},
|
|
271
|
+
xFilterExpression: [_attrKeyHash, "between", _fromKey, "and", _toKey].join(" "),
|
|
272
|
+
};
|
|
273
|
+
return result;
|
|
274
|
+
}
|
|
275
|
+
operation__filterBeginsWith({ fieldName, term }) {
|
|
276
|
+
const _attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
277
|
+
const keyAttr = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)(":");
|
|
278
|
+
const result = {
|
|
279
|
+
xExpressionAttributeValues: {
|
|
280
|
+
[keyAttr]: term,
|
|
281
|
+
},
|
|
282
|
+
xExpressionAttributeNames: {
|
|
283
|
+
[_attrKeyHash]: fieldName,
|
|
284
|
+
},
|
|
285
|
+
xFilterExpression: `begins_with (${_attrKeyHash}, ${keyAttr})`,
|
|
286
|
+
};
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
operation__translateAdvancedQueryOperation({ fieldName, queryObject, }) {
|
|
290
|
+
const queryConditions = [];
|
|
291
|
+
const notConditions = [];
|
|
292
|
+
const orConditions = [];
|
|
293
|
+
Object.entries(queryObject).forEach(([condKey, conditionValue]) => {
|
|
294
|
+
const conditionKey = condKey;
|
|
295
|
+
if (conditionValue !== undefined) {
|
|
296
|
+
if (conditionKey === "$between") {
|
|
297
|
+
query_validator_1.QueryValidatorCheck.between(conditionValue);
|
|
298
|
+
const [from, to] = conditionValue;
|
|
299
|
+
const _queryConditions = this.operation__filterBetween({
|
|
300
|
+
fieldName: fieldName,
|
|
301
|
+
from,
|
|
302
|
+
to,
|
|
303
|
+
});
|
|
304
|
+
queryConditions.push(_queryConditions);
|
|
305
|
+
}
|
|
306
|
+
else if (conditionKey === "$beginsWith") {
|
|
307
|
+
query_validator_1.QueryValidatorCheck.beginWith(conditionValue);
|
|
308
|
+
const _queryConditions = this.operation__filterBeginsWith({
|
|
309
|
+
fieldName: fieldName,
|
|
310
|
+
term: conditionValue,
|
|
311
|
+
});
|
|
312
|
+
queryConditions.push(_queryConditions);
|
|
313
|
+
}
|
|
314
|
+
else if (conditionKey === "$contains") {
|
|
315
|
+
query_validator_1.QueryValidatorCheck.contains(conditionValue);
|
|
316
|
+
const _queryConditions = this.operation__filterContains({
|
|
317
|
+
fieldName: fieldName,
|
|
318
|
+
term: conditionValue,
|
|
319
|
+
});
|
|
320
|
+
queryConditions.push(_queryConditions);
|
|
321
|
+
}
|
|
322
|
+
else if (conditionKey === "$in") {
|
|
323
|
+
query_validator_1.QueryValidatorCheck.in_query(conditionValue);
|
|
324
|
+
const _queryConditions = this.operation__filterIn({
|
|
325
|
+
fieldName: fieldName,
|
|
326
|
+
attrValues: conditionValue,
|
|
327
|
+
});
|
|
328
|
+
queryConditions.push(_queryConditions);
|
|
329
|
+
}
|
|
330
|
+
else if (conditionKey === "$nin") {
|
|
331
|
+
query_validator_1.QueryValidatorCheck.notIn(conditionValue);
|
|
332
|
+
const _queryConditions = this.operation__filterIn({
|
|
333
|
+
fieldName: fieldName,
|
|
334
|
+
attrValues: conditionValue,
|
|
335
|
+
});
|
|
336
|
+
_queryConditions.xFilterExpression = `NOT ${_queryConditions.xFilterExpression}`;
|
|
337
|
+
queryConditions.push(_queryConditions);
|
|
338
|
+
}
|
|
339
|
+
else if (conditionKey === "$elemMatch") {
|
|
340
|
+
query_validator_1.QueryValidatorCheck.elemMatch(conditionValue);
|
|
341
|
+
const elemMatchConditions = this.operation__filterElemMatch({
|
|
342
|
+
fieldName: fieldName,
|
|
343
|
+
attrValues: conditionValue,
|
|
344
|
+
});
|
|
345
|
+
if (elemMatchConditions?.length) {
|
|
346
|
+
elemMatchConditions.forEach((cond) => {
|
|
347
|
+
orConditions.push(cond);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else if (conditionKey === "$nestedMatch") {
|
|
352
|
+
query_validator_1.QueryValidatorCheck.nestedMatch(conditionValue);
|
|
353
|
+
const nestedMatchConditions = this.operation__filterNestedMatchObject({
|
|
354
|
+
fieldName: fieldName,
|
|
355
|
+
attrValues: conditionValue,
|
|
356
|
+
});
|
|
357
|
+
if (nestedMatchConditions?.length) {
|
|
358
|
+
nestedMatchConditions.forEach((cond) => {
|
|
359
|
+
queryConditions.push(cond);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
else if (conditionKey === "$not") {
|
|
364
|
+
query_validator_1.QueryValidatorCheck.not_query(conditionValue);
|
|
365
|
+
const _queryConditions = this.operation__filterNot({
|
|
366
|
+
fieldName: fieldName,
|
|
367
|
+
selectorValues: conditionValue,
|
|
368
|
+
});
|
|
369
|
+
if (_queryConditions?.length) {
|
|
370
|
+
_queryConditions.forEach((cond) => {
|
|
371
|
+
notConditions.push(cond);
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else if (conditionKey === "$notContains") {
|
|
376
|
+
query_validator_1.QueryValidatorCheck.notContains(conditionValue);
|
|
377
|
+
const _queryConditions = this.operation__filterContains({
|
|
378
|
+
fieldName: fieldName,
|
|
379
|
+
term: conditionValue,
|
|
380
|
+
});
|
|
381
|
+
_queryConditions.xFilterExpression = `NOT (${_queryConditions.xFilterExpression})`;
|
|
382
|
+
queryConditions.push(_queryConditions);
|
|
383
|
+
}
|
|
384
|
+
else if (conditionKey === "$exists") {
|
|
385
|
+
query_validator_1.QueryValidatorCheck.exists(conditionValue);
|
|
386
|
+
if (String(conditionValue) === "true") {
|
|
387
|
+
const _queryConditions = this.operation__filterFieldExist({
|
|
388
|
+
fieldName: fieldName,
|
|
389
|
+
});
|
|
390
|
+
queryConditions.push(_queryConditions);
|
|
391
|
+
}
|
|
392
|
+
else if (String(conditionValue) === "false") {
|
|
393
|
+
const _queryConditions = this.operation__filterFieldNotExist({
|
|
394
|
+
fieldName: fieldName,
|
|
395
|
+
});
|
|
396
|
+
queryConditions.push(_queryConditions);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
const conditionExpr = conditionMap[conditionKey];
|
|
401
|
+
if (hasQueryConditionValue(conditionKey) && conditionExpr) {
|
|
402
|
+
const _queryConditions = this.operation__helperFilterBasic({
|
|
403
|
+
fieldName: fieldName,
|
|
404
|
+
val: conditionValue,
|
|
405
|
+
conditionExpr: conditionExpr,
|
|
406
|
+
});
|
|
407
|
+
queryConditions.push(_queryConditions);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
query_validator_1.QueryValidatorCheck.throwQueryNotFound(conditionKey);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
logging_service_1.LoggingService.log(queryConditions);
|
|
416
|
+
return { queryConditions, notConditions, orConditions };
|
|
417
|
+
}
|
|
418
|
+
operation_translateBasicQueryOperation({ fieldName, queryObject }) {
|
|
419
|
+
const _queryConditions = this.operation__helperFilterBasic({
|
|
420
|
+
fieldName: fieldName,
|
|
421
|
+
val: queryObject,
|
|
422
|
+
conditionExpr: "=",
|
|
423
|
+
});
|
|
424
|
+
return _queryConditions;
|
|
425
|
+
}
|
|
426
|
+
processQueryFilter({ queryDefs, projectionFields, }) {
|
|
427
|
+
let AND_queryConditions = [];
|
|
428
|
+
let OR_queryConditions = [];
|
|
429
|
+
const OR_queryConditions_multiFields = [];
|
|
430
|
+
let NOT_queryConditions = [];
|
|
431
|
+
let NOT_inside_OR_queryConditions = [];
|
|
432
|
+
const AND_FilterExpressionArray = [];
|
|
433
|
+
const OR_FilterExpressionArray = [];
|
|
434
|
+
const OR_FilterExpressionMultiFieldsArray = [];
|
|
435
|
+
const NOT_FilterExpressionArray = [];
|
|
436
|
+
const NOT_inside_OR_FilterExpressionArray = [];
|
|
437
|
+
Object.entries(queryDefs).forEach(([conditionKey, conditionValue]) => {
|
|
438
|
+
if (conditionKey === "$or") {
|
|
439
|
+
query_validator_1.QueryValidatorCheck.or_query(conditionValue);
|
|
440
|
+
const orArray = conditionValue;
|
|
441
|
+
orArray.forEach((orQuery) => {
|
|
442
|
+
const OR_queryMultiConditionsPrivate = [];
|
|
443
|
+
const hasMultiField = Object.keys(orQuery || {}).length > 1;
|
|
444
|
+
Object.entries(orQuery).forEach(([fieldName, orQueryObjectOrValue]) => {
|
|
445
|
+
if (orQueryObjectOrValue !== undefined) {
|
|
446
|
+
if (orQueryObjectOrValue && typeof orQueryObjectOrValue === "object") {
|
|
447
|
+
const orQueryCond01 = this.operation__translateAdvancedQueryOperation({
|
|
448
|
+
fieldName,
|
|
449
|
+
queryObject: orQueryObjectOrValue,
|
|
450
|
+
});
|
|
451
|
+
if (orQueryCond01?.queryConditions?.length) {
|
|
452
|
+
if (hasMultiField) {
|
|
453
|
+
OR_queryMultiConditionsPrivate.push(...orQueryCond01.queryConditions);
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
OR_queryConditions = [...OR_queryConditions, ...orQueryCond01.queryConditions];
|
|
457
|
+
NOT_inside_OR_queryConditions = [
|
|
458
|
+
...NOT_inside_OR_queryConditions,
|
|
459
|
+
...orQueryCond01.notConditions,
|
|
460
|
+
];
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
const orQueryCondition01 = this.operation_translateBasicQueryOperation({
|
|
466
|
+
fieldName,
|
|
467
|
+
queryObject: orQueryObjectOrValue,
|
|
468
|
+
});
|
|
469
|
+
OR_queryConditions.push(orQueryCondition01);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
if (OR_queryMultiConditionsPrivate.length) {
|
|
474
|
+
OR_queryConditions_multiFields.push(OR_queryMultiConditionsPrivate);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
else if (conditionKey === "$and") {
|
|
479
|
+
const andArray = conditionValue;
|
|
480
|
+
query_validator_1.QueryValidatorCheck.and_query(andArray);
|
|
481
|
+
andArray.forEach((andQuery) => {
|
|
482
|
+
Object.entries(andQuery).forEach(([fieldName, andQueryObjectOrValue]) => {
|
|
483
|
+
if (andQueryObjectOrValue !== undefined) {
|
|
484
|
+
if (andQueryObjectOrValue && typeof andQueryObjectOrValue === "object") {
|
|
485
|
+
const andQueryCond01 = this.operation__translateAdvancedQueryOperation({
|
|
486
|
+
fieldName,
|
|
487
|
+
queryObject: andQueryObjectOrValue,
|
|
488
|
+
});
|
|
489
|
+
AND_queryConditions = [...AND_queryConditions, ...andQueryCond01.queryConditions];
|
|
490
|
+
NOT_queryConditions = [...NOT_queryConditions, ...andQueryCond01.notConditions];
|
|
491
|
+
OR_queryConditions = [...OR_queryConditions, ...andQueryCond01.orConditions];
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
const andQueryCondition01 = this.operation_translateBasicQueryOperation({
|
|
495
|
+
fieldName,
|
|
496
|
+
queryObject: andQueryObjectOrValue,
|
|
497
|
+
});
|
|
498
|
+
AND_queryConditions = [...AND_queryConditions, andQueryCondition01];
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
if (conditionKey) {
|
|
506
|
+
if (conditionValue !== undefined) {
|
|
507
|
+
if (conditionValue && typeof conditionValue === "object") {
|
|
508
|
+
const queryCond01 = this.operation__translateAdvancedQueryOperation({
|
|
509
|
+
fieldName: conditionKey,
|
|
510
|
+
queryObject: conditionValue,
|
|
511
|
+
});
|
|
512
|
+
AND_queryConditions = [...AND_queryConditions, ...queryCond01.queryConditions];
|
|
513
|
+
NOT_queryConditions = [...NOT_queryConditions, ...queryCond01.notConditions];
|
|
514
|
+
OR_queryConditions = [...OR_queryConditions, ...queryCond01.orConditions];
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
const queryCondition01 = this.operation_translateBasicQueryOperation({
|
|
518
|
+
fieldName: conditionKey,
|
|
519
|
+
queryObject: conditionValue,
|
|
520
|
+
});
|
|
521
|
+
AND_queryConditions = [...AND_queryConditions, queryCondition01];
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
let _expressionAttributeValues = {};
|
|
528
|
+
let _expressionAttributeNames = {};
|
|
529
|
+
let _projectionExpression;
|
|
530
|
+
AND_queryConditions.forEach((item) => {
|
|
531
|
+
_expressionAttributeNames = {
|
|
532
|
+
..._expressionAttributeNames,
|
|
533
|
+
...item.xExpressionAttributeNames,
|
|
534
|
+
};
|
|
535
|
+
_expressionAttributeValues = {
|
|
536
|
+
..._expressionAttributeValues,
|
|
537
|
+
...item.xExpressionAttributeValues,
|
|
538
|
+
};
|
|
539
|
+
AND_FilterExpressionArray.push(item.xFilterExpression);
|
|
540
|
+
});
|
|
541
|
+
OR_queryConditions.forEach((item2) => {
|
|
542
|
+
_expressionAttributeNames = {
|
|
543
|
+
..._expressionAttributeNames,
|
|
544
|
+
...item2.xExpressionAttributeNames,
|
|
545
|
+
};
|
|
546
|
+
_expressionAttributeValues = {
|
|
547
|
+
..._expressionAttributeValues,
|
|
548
|
+
...item2.xExpressionAttributeValues,
|
|
549
|
+
};
|
|
550
|
+
OR_FilterExpressionArray.push(item2.xFilterExpression);
|
|
551
|
+
});
|
|
552
|
+
OR_queryConditions_multiFields.forEach((item2a) => {
|
|
553
|
+
const xFilterExpression = [];
|
|
554
|
+
item2a.forEach((item01) => {
|
|
555
|
+
_expressionAttributeNames = {
|
|
556
|
+
..._expressionAttributeNames,
|
|
557
|
+
...item01.xExpressionAttributeNames,
|
|
558
|
+
};
|
|
559
|
+
_expressionAttributeValues = {
|
|
560
|
+
..._expressionAttributeValues,
|
|
561
|
+
...item01.xExpressionAttributeValues,
|
|
562
|
+
};
|
|
563
|
+
xFilterExpression.push(item01.xFilterExpression);
|
|
564
|
+
});
|
|
565
|
+
OR_FilterExpressionMultiFieldsArray.push(xFilterExpression);
|
|
566
|
+
});
|
|
567
|
+
NOT_queryConditions.forEach((item03) => {
|
|
568
|
+
_expressionAttributeNames = {
|
|
569
|
+
..._expressionAttributeNames,
|
|
570
|
+
...item03.xExpressionAttributeNames,
|
|
571
|
+
};
|
|
572
|
+
_expressionAttributeValues = {
|
|
573
|
+
..._expressionAttributeValues,
|
|
574
|
+
...item03.xExpressionAttributeValues,
|
|
575
|
+
};
|
|
576
|
+
NOT_FilterExpressionArray.push(item03.xFilterExpression);
|
|
577
|
+
});
|
|
578
|
+
NOT_inside_OR_queryConditions.forEach((item4) => {
|
|
579
|
+
_expressionAttributeNames = {
|
|
580
|
+
..._expressionAttributeNames,
|
|
581
|
+
...item4.xExpressionAttributeNames,
|
|
582
|
+
};
|
|
583
|
+
_expressionAttributeValues = {
|
|
584
|
+
..._expressionAttributeValues,
|
|
585
|
+
...item4.xExpressionAttributeValues,
|
|
586
|
+
};
|
|
587
|
+
NOT_inside_OR_FilterExpressionArray.push(item4.xFilterExpression);
|
|
588
|
+
});
|
|
589
|
+
let _andfilterExpression = "";
|
|
590
|
+
let _orfilterExpression = "";
|
|
591
|
+
let _notfilterExpression = "";
|
|
592
|
+
let _notInsideOrFilterExpression = "";
|
|
593
|
+
if (AND_FilterExpressionArray?.length) {
|
|
594
|
+
_andfilterExpression = AND_FilterExpressionArray.join(" AND ").trim();
|
|
595
|
+
}
|
|
596
|
+
if (OR_FilterExpressionMultiFieldsArray?.length) {
|
|
597
|
+
const subQuery = [];
|
|
598
|
+
OR_FilterExpressionMultiFieldsArray.forEach((item01) => {
|
|
599
|
+
const val = item01.join(" AND ").trim();
|
|
600
|
+
subQuery.push(`(${val})`);
|
|
601
|
+
});
|
|
602
|
+
_orfilterExpression = [...OR_FilterExpressionArray, ...subQuery].join(" OR ").trim();
|
|
603
|
+
}
|
|
604
|
+
else if (OR_FilterExpressionArray?.length) {
|
|
605
|
+
_orfilterExpression = OR_FilterExpressionArray.join(" OR ").trim();
|
|
606
|
+
}
|
|
607
|
+
if (NOT_FilterExpressionArray?.length) {
|
|
608
|
+
_notfilterExpression = NOT_FilterExpressionArray.join(" AND ").trim();
|
|
609
|
+
_notfilterExpression = `NOT (${_notfilterExpression})`;
|
|
610
|
+
}
|
|
611
|
+
if (NOT_inside_OR_FilterExpressionArray?.length) {
|
|
612
|
+
_notInsideOrFilterExpression = NOT_inside_OR_FilterExpressionArray.join(" OR ").trim();
|
|
613
|
+
_notInsideOrFilterExpression = `NOT (${_notInsideOrFilterExpression})`;
|
|
614
|
+
}
|
|
615
|
+
let allFilters = [
|
|
616
|
+
_andfilterExpression,
|
|
617
|
+
_notfilterExpression,
|
|
618
|
+
_orfilterExpression,
|
|
619
|
+
_notInsideOrFilterExpression,
|
|
620
|
+
].filter((f) => f);
|
|
621
|
+
if (allFilters?.length && allFilters.length > 1) {
|
|
622
|
+
allFilters = allFilters.map((f) => `(${f})`);
|
|
623
|
+
}
|
|
624
|
+
const _filterExpression = allFilters.join(" AND ");
|
|
625
|
+
if (projectionFields?.length && Array.isArray(projectionFields)) {
|
|
626
|
+
const _projection_expressionAttributeNames = {};
|
|
627
|
+
projectionFields.forEach((field) => {
|
|
628
|
+
if (field && typeof field === "string") {
|
|
629
|
+
const attrKeyHash = (0, dynamo_helper_1.getDynamoRandomKeyOrHash)("#");
|
|
630
|
+
_projection_expressionAttributeNames[attrKeyHash] = field;
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
_projectionExpression = Object.keys(_projection_expressionAttributeNames).join(", ");
|
|
634
|
+
_expressionAttributeNames = {
|
|
635
|
+
..._projection_expressionAttributeNames,
|
|
636
|
+
..._expressionAttributeNames,
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
const _expressionAttributeValuesFinal = util_service_1.UtilService.objectHasAnyProperty(_expressionAttributeValues)
|
|
640
|
+
? _expressionAttributeValues
|
|
641
|
+
: undefined;
|
|
642
|
+
const _expressionAttributeNamesFinal = util_service_1.UtilService.objectHasAnyProperty(_expressionAttributeNames)
|
|
643
|
+
? _expressionAttributeNames
|
|
644
|
+
: undefined;
|
|
645
|
+
const queryExpressions = {
|
|
646
|
+
expressionAttributeValues: _expressionAttributeValuesFinal,
|
|
647
|
+
filterExpression: _filterExpression,
|
|
648
|
+
projectionExpressionAttr: _projectionExpression,
|
|
649
|
+
expressionAttributeNames: _expressionAttributeNamesFinal,
|
|
650
|
+
};
|
|
651
|
+
logging_service_1.LoggingService.log(JSON.stringify({ queryExpressions }, null, 2));
|
|
652
|
+
return queryExpressions;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
exports.DynamoFilterQueryOperation = DynamoFilterQueryOperation;
|
|
628
656
|
//# sourceMappingURL=dynamo-filter-query-operation.js.map
|