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