mocody 0.4.38 → 0.5.0-alpha
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/dist/core/base-schema.d.ts +13 -13
- package/dist/core/base-schema.js +11 -11
- package/dist/couch/couch-data-operation.d.ts +92 -92
- package/dist/couch/couch-data-operation.js +580 -580
- package/dist/couch/couch-data-operation.js.map +1 -1
- package/dist/couch/couch-filter-query-operation.d.ts +45 -47
- package/dist/couch/couch-filter-query-operation.js +371 -438
- package/dist/couch/couch-filter-query-operation.js.map +1 -1
- package/dist/couch/couch-initializer.d.ts +126 -126
- package/dist/couch/couch-initializer.js +189 -189
- 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 +103 -103
- package/dist/couch/couch-manage-table.js.map +1 -1
- package/dist/dynamo/dynamo-data-operation.d.ts +102 -99
- package/dist/dynamo/dynamo-data-operation.js +932 -797
- package/dist/dynamo/dynamo-data-operation.js.map +1 -1
- package/dist/dynamo/dynamo-filter-query-operation.d.ts +29 -29
- package/dist/dynamo/dynamo-filter-query-operation.js +603 -690
- package/dist/dynamo/dynamo-filter-query-operation.js.map +1 -1
- package/dist/dynamo/dynamo-filter-query-partiql-operation.d.ts +22 -0
- package/dist/dynamo/dynamo-filter-query-partiql-operation.js +457 -0
- package/dist/dynamo/dynamo-filter-query-partiql-operation.js.map +1 -0
- package/dist/dynamo/dynamo-helper.d.ts +1 -1
- package/dist/dynamo/dynamo-helper.js +8 -8
- package/dist/dynamo/dynamo-initializer.d.ts +15 -14
- package/dist/dynamo/dynamo-initializer.js +66 -58
- package/dist/dynamo/dynamo-initializer.js.map +1 -1
- package/dist/dynamo/dynamo-manage-table.d.ts +33 -33
- package/dist/dynamo/dynamo-manage-table.js +419 -419
- package/dist/dynamo/dynamo-manage-table.js.map +1 -1
- package/dist/dynamo/dynamo-query-partiql-processor.d.ts +31 -0
- package/dist/dynamo/dynamo-query-partiql-processor.js +277 -0
- package/dist/dynamo/dynamo-query-partiql-processor.js.map +1 -0
- package/dist/dynamo/dynamo-query-scan-processor.d.ts +25 -25
- package/dist/dynamo/dynamo-query-scan-processor.js +268 -268
- 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 +9 -9
- package/dist/helpers/logging-service.js +53 -53
- package/dist/helpers/logging-service.js.map +1 -1
- package/dist/helpers/mocody-utils.d.ts +16 -16
- package/dist/helpers/mocody-utils.js +58 -58
- package/dist/helpers/query-validator.d.ts +20 -20
- package/dist/helpers/query-validator.js +96 -96
- package/dist/helpers/util-service.d.ts +29 -29
- package/dist/helpers/util-service.js +155 -155
- package/dist/index.d.ts +12 -12
- package/dist/index.js +23 -23
- package/dist/model/index.d.ts +42 -42
- package/dist/model/index.js +6 -6
- package/dist/mongo/mongo-data-operation.d.ts +90 -90
- package/dist/mongo/mongo-data-operation.js +607 -607
- package/dist/mongo/mongo-data-operation.js.map +1 -1
- package/dist/mongo/mongo-filter-query-operation.d.ts +45 -47
- package/dist/mongo/mongo-filter-query-operation.js +368 -433
- package/dist/mongo/mongo-filter-query-operation.js.map +1 -1
- 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/mongo/mongo-table-manager.js.map +1 -1
- package/dist/pouch/pouch-data-operation.d.ts +90 -90
- package/dist/pouch/pouch-data-operation.js +583 -583
- package/dist/pouch/pouch-data-operation.js.map +1 -1
- package/dist/pouch/pouch-filter-query-operation.d.ts +45 -47
- package/dist/pouch/pouch-filter-query-operation.js +371 -438
- package/dist/pouch/pouch-filter-query-operation.js.map +1 -1
- package/dist/pouch/pouch-initializer.d.ts +111 -109
- package/dist/pouch/pouch-initializer.js +357 -357
- package/dist/pouch/pouch-initializer.js.map +1 -1
- package/dist/pouch/pouch-manage-table.d.ts +35 -35
- package/dist/pouch/pouch-manage-table.js +99 -99
- package/dist/pouch/pouch-manage-table.js.map +1 -1
- package/dist/type/index.d.ts +118 -119
- package/dist/type/index.js +2 -2
- package/package.json +17 -16
|
@@ -1,439 +1,372 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CouchFilterQueryOperation = void 0;
|
|
4
|
-
const errors_1 = require("../helpers/errors");
|
|
5
|
-
const query_validator_1 = require("../helpers/query-validator");
|
|
6
|
-
const KEY_CONDITION_MAP = {
|
|
7
|
-
$eq: "$eq",
|
|
8
|
-
$lt: "$lt",
|
|
9
|
-
$lte: "$lte",
|
|
10
|
-
$gt: "$gt",
|
|
11
|
-
$gte: "$gte",
|
|
12
|
-
$between: "",
|
|
13
|
-
$beginsWith: "",
|
|
14
|
-
};
|
|
15
|
-
const QUERY_CONDITION_MAP_PART = {
|
|
16
|
-
$ne: "$ne",
|
|
17
|
-
$exists: "",
|
|
18
|
-
$in: "",
|
|
19
|
-
$nin: "",
|
|
20
|
-
$
|
|
21
|
-
$
|
|
22
|
-
$
|
|
23
|
-
$
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
else {
|
|
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
|
-
|
|
263
|
-
|
|
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
|
-
|
|
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
|
-
const andArray = queryDefs[andKey];
|
|
373
|
-
query_validator_1.QueryValidatorCheck.and_query(andArray);
|
|
374
|
-
if (andArray && Array.isArray(andArray)) {
|
|
375
|
-
andArray.forEach((andQuery) => {
|
|
376
|
-
Object.keys(andQuery).forEach((fieldName) => {
|
|
377
|
-
const andQueryObjectOrValue = andQuery[fieldName];
|
|
378
|
-
if (andQueryObjectOrValue !== undefined) {
|
|
379
|
-
if (andQueryObjectOrValue && typeof andQueryObjectOrValue === "object") {
|
|
380
|
-
const _andQueryCond = this.operation__translateAdvancedQueryOperation({
|
|
381
|
-
fieldName,
|
|
382
|
-
queryObject: andQueryObjectOrValue,
|
|
383
|
-
});
|
|
384
|
-
queryAndConditions = [...queryAndConditions, ..._andQueryCond];
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
const _andQueryConditions = this.operation_translateBasicQueryOperation({
|
|
388
|
-
fieldName,
|
|
389
|
-
queryObject: andQueryObjectOrValue,
|
|
390
|
-
});
|
|
391
|
-
queryAndConditions = [...queryAndConditions, _andQueryConditions];
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
if (fieldName_Or_And) {
|
|
400
|
-
const fieldName2 = fieldName_Or_And;
|
|
401
|
-
const queryObjectOrValue = queryDefs[fieldName2];
|
|
402
|
-
if (queryObjectOrValue !== undefined) {
|
|
403
|
-
if (queryObjectOrValue && typeof queryObjectOrValue === "object") {
|
|
404
|
-
const _queryCond = this.operation__translateAdvancedQueryOperation({
|
|
405
|
-
fieldName: fieldName2,
|
|
406
|
-
queryObject: queryObjectOrValue,
|
|
407
|
-
});
|
|
408
|
-
queryMainConditions = [...queryMainConditions, ..._queryCond];
|
|
409
|
-
}
|
|
410
|
-
else {
|
|
411
|
-
const _queryConditions = this.operation_translateBasicQueryOperation({
|
|
412
|
-
fieldName: fieldName2,
|
|
413
|
-
queryObject: queryObjectOrValue,
|
|
414
|
-
});
|
|
415
|
-
queryMainConditions = [...queryMainConditions, _queryConditions];
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
let queryAllConditions = {};
|
|
422
|
-
if (queryMainConditions?.length) {
|
|
423
|
-
queryMainConditions.forEach((item1) => {
|
|
424
|
-
if (item1) {
|
|
425
|
-
queryAllConditions = { ...queryAllConditions, ...item1 };
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
if (queryAndConditions?.length) {
|
|
430
|
-
queryAllConditions.$and = queryAndConditions;
|
|
431
|
-
}
|
|
432
|
-
if (queryOrConditions?.length) {
|
|
433
|
-
queryAllConditions.$or = queryOrConditions;
|
|
434
|
-
}
|
|
435
|
-
return queryAllConditions;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
exports.CouchFilterQueryOperation = CouchFilterQueryOperation;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CouchFilterQueryOperation = void 0;
|
|
4
|
+
const errors_1 = require("../helpers/errors");
|
|
5
|
+
const query_validator_1 = require("../helpers/query-validator");
|
|
6
|
+
const KEY_CONDITION_MAP = {
|
|
7
|
+
$eq: "$eq",
|
|
8
|
+
$lt: "$lt",
|
|
9
|
+
$lte: "$lte",
|
|
10
|
+
$gt: "$gt",
|
|
11
|
+
$gte: "$gte",
|
|
12
|
+
$between: "",
|
|
13
|
+
$beginsWith: "",
|
|
14
|
+
};
|
|
15
|
+
const QUERY_CONDITION_MAP_PART = {
|
|
16
|
+
$ne: "$ne",
|
|
17
|
+
$exists: "",
|
|
18
|
+
$in: "",
|
|
19
|
+
$nin: "",
|
|
20
|
+
$contains: "",
|
|
21
|
+
$notContains: "",
|
|
22
|
+
$elemMatch: "",
|
|
23
|
+
$nestedMatch: "",
|
|
24
|
+
};
|
|
25
|
+
const QUERY_CONDITION_MAP_FULL = { ...KEY_CONDITION_MAP, ...QUERY_CONDITION_MAP_PART };
|
|
26
|
+
function getQueryConditionExpression(key) {
|
|
27
|
+
if (key && Object.keys(QUERY_CONDITION_MAP_FULL).includes(key)) {
|
|
28
|
+
const conditionExpr = QUERY_CONDITION_MAP_FULL[key];
|
|
29
|
+
if (conditionExpr) {
|
|
30
|
+
return conditionExpr;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
function regex_pcre_beginWith(text) {
|
|
36
|
+
return `(?i)\\A${text}`;
|
|
37
|
+
}
|
|
38
|
+
function regex_pcre_contain(text) {
|
|
39
|
+
return `(?i)${text}`;
|
|
40
|
+
}
|
|
41
|
+
class CouchFilterQueryOperation {
|
|
42
|
+
operation__filterFieldExist({ fieldName }) {
|
|
43
|
+
const result = {
|
|
44
|
+
[fieldName]: { $exists: true },
|
|
45
|
+
};
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
operation__filterFieldNotExist({ fieldName }) {
|
|
49
|
+
const result = {
|
|
50
|
+
[fieldName]: { $exists: false },
|
|
51
|
+
};
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
operation__helperFilterBasic({ fieldName, val, conditionExpr, }) {
|
|
55
|
+
if (conditionExpr) {
|
|
56
|
+
return {
|
|
57
|
+
[fieldName]: { [conditionExpr]: val },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const result = {
|
|
61
|
+
[fieldName]: { $eq: val },
|
|
62
|
+
};
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
operation__filterIn({ fieldName, attrValues }) {
|
|
66
|
+
const result = {
|
|
67
|
+
[fieldName]: { $in: attrValues },
|
|
68
|
+
};
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
operation__filterNotIn({ fieldName, attrValues, }) {
|
|
72
|
+
const result = {
|
|
73
|
+
[fieldName]: { $nin: attrValues },
|
|
74
|
+
};
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
operation__filterElementMatch({ fieldName, attrValues, }) {
|
|
78
|
+
const result = {
|
|
79
|
+
[fieldName]: {
|
|
80
|
+
$elemMatch: attrValues,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
operation__filterContains({ fieldName, term }) {
|
|
86
|
+
const result = {
|
|
87
|
+
[fieldName]: { $regex: regex_pcre_contain(term) },
|
|
88
|
+
};
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
operation__filterNotContains({ fieldName, term }) {
|
|
92
|
+
const result = {
|
|
93
|
+
[fieldName]: { $not: { $regex: regex_pcre_contain(term) } },
|
|
94
|
+
};
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
operation__filterBetween({ fieldName, from, to, }) {
|
|
98
|
+
const result = {
|
|
99
|
+
[fieldName]: { $gte: from, $lte: to },
|
|
100
|
+
};
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
operation__filterBeginsWith({ fieldName, term }) {
|
|
104
|
+
const result = {
|
|
105
|
+
[fieldName]: { $regex: regex_pcre_beginWith(term) },
|
|
106
|
+
};
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
operation__filterNestedMatchObject({ fieldName, attrValues, }) {
|
|
110
|
+
const results = [];
|
|
111
|
+
Object.entries(attrValues).forEach(([subFieldName, queryval]) => {
|
|
112
|
+
let _queryValue;
|
|
113
|
+
if (queryval && typeof queryval === "object") {
|
|
114
|
+
_queryValue = { ...queryval };
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
_queryValue = { $eq: queryval };
|
|
118
|
+
}
|
|
119
|
+
Object.entries(_queryValue).forEach(([condKey, val]) => {
|
|
120
|
+
const conditionKey = condKey;
|
|
121
|
+
if (!Object.keys(KEY_CONDITION_MAP).includes(conditionKey)) {
|
|
122
|
+
throw errors_1.MocodyErrorUtilsService.mocody_helper_createFriendlyError(`Invalid query key: ${conditionKey} @ NestedMatchObject`);
|
|
123
|
+
}
|
|
124
|
+
const conditionExpr = KEY_CONDITION_MAP[conditionKey];
|
|
125
|
+
if (conditionExpr) {
|
|
126
|
+
const result = {
|
|
127
|
+
[`${fieldName}.${subFieldName}`]: { [conditionExpr]: val },
|
|
128
|
+
};
|
|
129
|
+
results.push(result);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
if (conditionKey === "$between") {
|
|
133
|
+
if (!(Array.isArray(val) && val.length === 2)) {
|
|
134
|
+
throw errors_1.MocodyErrorUtilsService.mocody_helper_createFriendlyError("$between query must be an array of length 2");
|
|
135
|
+
}
|
|
136
|
+
const [fromVal, toVal] = val;
|
|
137
|
+
const result = {
|
|
138
|
+
[`${fieldName}.${subFieldName}`]: { $gte: fromVal, $lte: toVal },
|
|
139
|
+
};
|
|
140
|
+
results.push(result);
|
|
141
|
+
}
|
|
142
|
+
else if (conditionKey === "$beginsWith") {
|
|
143
|
+
const result = {
|
|
144
|
+
[`${fieldName}.${subFieldName}`]: { $regex: regex_pcre_beginWith(val) },
|
|
145
|
+
};
|
|
146
|
+
results.push(result);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw errors_1.MocodyErrorUtilsService.mocody_helper_createFriendlyError(`Query key: ${conditionKey} not currently supported`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
return results;
|
|
155
|
+
}
|
|
156
|
+
operation__translateAdvancedQueryOperation({ fieldName, queryObject, }) {
|
|
157
|
+
const queryConditions = [];
|
|
158
|
+
Object.entries(queryObject).forEach(([condKey, conditionValue]) => {
|
|
159
|
+
const conditionKey = condKey;
|
|
160
|
+
if (conditionValue !== undefined) {
|
|
161
|
+
if (conditionKey === "$between") {
|
|
162
|
+
query_validator_1.QueryValidatorCheck.between(conditionValue);
|
|
163
|
+
const _queryConditions = this.operation__filterBetween({
|
|
164
|
+
fieldName: fieldName,
|
|
165
|
+
from: conditionValue[0],
|
|
166
|
+
to: conditionValue[1],
|
|
167
|
+
});
|
|
168
|
+
queryConditions.push(_queryConditions);
|
|
169
|
+
}
|
|
170
|
+
else if (conditionKey === "$beginsWith") {
|
|
171
|
+
query_validator_1.QueryValidatorCheck.beginWith(conditionValue);
|
|
172
|
+
const _queryConditions = this.operation__filterBeginsWith({
|
|
173
|
+
fieldName: fieldName,
|
|
174
|
+
term: conditionValue,
|
|
175
|
+
});
|
|
176
|
+
queryConditions.push(_queryConditions);
|
|
177
|
+
}
|
|
178
|
+
else if (conditionKey === "$contains") {
|
|
179
|
+
query_validator_1.QueryValidatorCheck.contains(conditionValue);
|
|
180
|
+
const _queryConditions = this.operation__filterContains({
|
|
181
|
+
fieldName: fieldName,
|
|
182
|
+
term: conditionValue,
|
|
183
|
+
});
|
|
184
|
+
queryConditions.push(_queryConditions);
|
|
185
|
+
}
|
|
186
|
+
else if (conditionKey === "$notContains") {
|
|
187
|
+
query_validator_1.QueryValidatorCheck.notContains(conditionValue);
|
|
188
|
+
const _queryConditions = this.operation__filterNotContains({
|
|
189
|
+
fieldName: fieldName,
|
|
190
|
+
term: conditionValue,
|
|
191
|
+
});
|
|
192
|
+
queryConditions.push(_queryConditions);
|
|
193
|
+
}
|
|
194
|
+
else if (conditionKey === "$in") {
|
|
195
|
+
query_validator_1.QueryValidatorCheck.in_query(conditionValue);
|
|
196
|
+
const _queryConditions = this.operation__filterIn({
|
|
197
|
+
fieldName: fieldName,
|
|
198
|
+
attrValues: conditionValue,
|
|
199
|
+
});
|
|
200
|
+
queryConditions.push(_queryConditions);
|
|
201
|
+
}
|
|
202
|
+
else if (conditionKey === "$nin") {
|
|
203
|
+
query_validator_1.QueryValidatorCheck.notIn(conditionValue);
|
|
204
|
+
const _queryConditions = this.operation__filterNotIn({
|
|
205
|
+
fieldName: fieldName,
|
|
206
|
+
attrValues: conditionValue,
|
|
207
|
+
});
|
|
208
|
+
queryConditions.push(_queryConditions);
|
|
209
|
+
}
|
|
210
|
+
else if (conditionKey === "$elemMatch") {
|
|
211
|
+
query_validator_1.QueryValidatorCheck.elemMatch(conditionValue);
|
|
212
|
+
const _queryConditions = this.operation__filterElementMatch({
|
|
213
|
+
fieldName: fieldName,
|
|
214
|
+
attrValues: conditionValue,
|
|
215
|
+
});
|
|
216
|
+
queryConditions.push(_queryConditions);
|
|
217
|
+
}
|
|
218
|
+
else if (conditionKey === "$nestedMatch") {
|
|
219
|
+
query_validator_1.QueryValidatorCheck.nestedMatch(conditionValue);
|
|
220
|
+
const nestedMatchConditions = this.operation__filterNestedMatchObject({
|
|
221
|
+
fieldName: fieldName,
|
|
222
|
+
attrValues: conditionValue,
|
|
223
|
+
});
|
|
224
|
+
if (nestedMatchConditions?.length) {
|
|
225
|
+
nestedMatchConditions.forEach((_queryCondition) => {
|
|
226
|
+
queryConditions.push(_queryCondition);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else if (conditionKey === "$exists") {
|
|
231
|
+
query_validator_1.QueryValidatorCheck.exists(conditionValue);
|
|
232
|
+
if (String(conditionValue) === "true") {
|
|
233
|
+
const _queryConditions = this.operation__filterFieldExist({
|
|
234
|
+
fieldName: fieldName,
|
|
235
|
+
});
|
|
236
|
+
queryConditions.push(_queryConditions);
|
|
237
|
+
}
|
|
238
|
+
else if (String(conditionValue) === "false") {
|
|
239
|
+
const _queryConditions = this.operation__filterFieldNotExist({
|
|
240
|
+
fieldName: fieldName,
|
|
241
|
+
});
|
|
242
|
+
queryConditions.push(_queryConditions);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
const conditionExpr = getQueryConditionExpression(conditionKey);
|
|
247
|
+
if (conditionExpr) {
|
|
248
|
+
const _queryConditions = this.operation__helperFilterBasic({
|
|
249
|
+
fieldName: fieldName,
|
|
250
|
+
val: conditionValue,
|
|
251
|
+
conditionExpr: conditionExpr,
|
|
252
|
+
});
|
|
253
|
+
queryConditions.push(_queryConditions);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
query_validator_1.QueryValidatorCheck.throwQueryNotFound(conditionKey);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
return queryConditions;
|
|
262
|
+
}
|
|
263
|
+
operation_translateBasicQueryOperation({ fieldName, queryObject }) {
|
|
264
|
+
const _queryConditions = this.operation__helperFilterBasic({
|
|
265
|
+
fieldName: fieldName,
|
|
266
|
+
val: queryObject,
|
|
267
|
+
});
|
|
268
|
+
return _queryConditions;
|
|
269
|
+
}
|
|
270
|
+
processQueryFilter({ queryDefs }) {
|
|
271
|
+
let queryMainConditions = [];
|
|
272
|
+
let queryAndConditions = [];
|
|
273
|
+
let queryOrConditions = [];
|
|
274
|
+
Object.keys(queryDefs).forEach((fieldName_Or_And) => {
|
|
275
|
+
if (fieldName_Or_And === "$or") {
|
|
276
|
+
const orKey = fieldName_Or_And;
|
|
277
|
+
const orArray = queryDefs[orKey];
|
|
278
|
+
query_validator_1.QueryValidatorCheck.or_query(orArray);
|
|
279
|
+
if (orArray && Array.isArray(orArray)) {
|
|
280
|
+
orArray.forEach((orQuery) => {
|
|
281
|
+
Object.keys(orQuery).forEach((fieldName) => {
|
|
282
|
+
const orQueryObjectOrValue = orQuery[fieldName];
|
|
283
|
+
if (orQueryObjectOrValue !== undefined) {
|
|
284
|
+
if (orQueryObjectOrValue && typeof orQueryObjectOrValue === "object") {
|
|
285
|
+
const _orQueryCond = this.operation__translateAdvancedQueryOperation({
|
|
286
|
+
fieldName,
|
|
287
|
+
queryObject: orQueryObjectOrValue,
|
|
288
|
+
});
|
|
289
|
+
queryOrConditions = [...queryOrConditions, ..._orQueryCond];
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
const _orQueryConditions = this.operation_translateBasicQueryOperation({
|
|
293
|
+
fieldName,
|
|
294
|
+
queryObject: orQueryObjectOrValue,
|
|
295
|
+
});
|
|
296
|
+
queryOrConditions = [...queryOrConditions, _orQueryConditions];
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else if (fieldName_Or_And === "$and") {
|
|
304
|
+
const andKey = fieldName_Or_And;
|
|
305
|
+
const andArray = queryDefs[andKey];
|
|
306
|
+
query_validator_1.QueryValidatorCheck.and_query(andArray);
|
|
307
|
+
if (andArray && Array.isArray(andArray)) {
|
|
308
|
+
andArray.forEach((andQuery) => {
|
|
309
|
+
Object.keys(andQuery).forEach((fieldName) => {
|
|
310
|
+
const andQueryObjectOrValue = andQuery[fieldName];
|
|
311
|
+
if (andQueryObjectOrValue !== undefined) {
|
|
312
|
+
if (andQueryObjectOrValue && typeof andQueryObjectOrValue === "object") {
|
|
313
|
+
const _andQueryCond = this.operation__translateAdvancedQueryOperation({
|
|
314
|
+
fieldName,
|
|
315
|
+
queryObject: andQueryObjectOrValue,
|
|
316
|
+
});
|
|
317
|
+
queryAndConditions = [...queryAndConditions, ..._andQueryCond];
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
const _andQueryConditions = this.operation_translateBasicQueryOperation({
|
|
321
|
+
fieldName,
|
|
322
|
+
queryObject: andQueryObjectOrValue,
|
|
323
|
+
});
|
|
324
|
+
queryAndConditions = [...queryAndConditions, _andQueryConditions];
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
if (fieldName_Or_And) {
|
|
333
|
+
const fieldName2 = fieldName_Or_And;
|
|
334
|
+
const queryObjectOrValue = queryDefs[fieldName2];
|
|
335
|
+
if (queryObjectOrValue !== undefined) {
|
|
336
|
+
if (queryObjectOrValue && typeof queryObjectOrValue === "object") {
|
|
337
|
+
const _queryCond = this.operation__translateAdvancedQueryOperation({
|
|
338
|
+
fieldName: fieldName2,
|
|
339
|
+
queryObject: queryObjectOrValue,
|
|
340
|
+
});
|
|
341
|
+
queryMainConditions = [...queryMainConditions, ..._queryCond];
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
const _queryConditions = this.operation_translateBasicQueryOperation({
|
|
345
|
+
fieldName: fieldName2,
|
|
346
|
+
queryObject: queryObjectOrValue,
|
|
347
|
+
});
|
|
348
|
+
queryMainConditions = [...queryMainConditions, _queryConditions];
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
let queryAllConditions = {};
|
|
355
|
+
if (queryMainConditions?.length) {
|
|
356
|
+
queryMainConditions.forEach((item1) => {
|
|
357
|
+
if (item1) {
|
|
358
|
+
queryAllConditions = { ...queryAllConditions, ...item1 };
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
if (queryAndConditions?.length) {
|
|
363
|
+
queryAllConditions.$and = queryAndConditions;
|
|
364
|
+
}
|
|
365
|
+
if (queryOrConditions?.length) {
|
|
366
|
+
queryAllConditions.$or = queryOrConditions;
|
|
367
|
+
}
|
|
368
|
+
return queryAllConditions;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
exports.CouchFilterQueryOperation = CouchFilterQueryOperation;
|
|
439
372
|
//# sourceMappingURL=couch-filter-query-operation.js.map
|