drapcode-utility 1.9.6 → 1.9.78
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/build/encryption/utility.d.ts +1 -2
- package/build/encryption/utility.js +4 -39
- package/build/format-fields/index.js +1 -1
- package/build/index.d.ts +3 -1
- package/build/index.js +3 -1
- package/build/utils/check-error.js +7 -7
- package/build/utils/common-util.d.ts +78 -0
- package/build/utils/common-util.js +219 -0
- package/build/utils/date-util.js +0 -13
- package/build/utils/file-util.d.ts +7 -0
- package/build/utils/file-util.js +118 -0
- package/build/utils/prepare-query.d.ts +0 -148
- package/build/utils/prepare-query.js +1 -100
- package/build/utils/project-util.d.ts +1 -0
- package/build/utils/project-util.js +31 -49
- package/build/utils/{query-paser-new.js → query-parser-new.js} +24 -174
- package/build/utils/query-parser.d.ts +0 -12
- package/build/utils/query-parser.js +16 -280
- package/build/utils/query-utils.d.ts +20 -0
- package/build/utils/query-utils.js +254 -0
- package/build/utils/rest-client.d.ts +6 -0
- package/build/utils/rest-client.js +342 -0
- package/build/utils/util.d.ts +77 -3
- package/build/utils/util.js +511 -32
- package/package.json +10 -5
- /package/build/utils/{query-paser-new.d.ts → query-parser-new.d.ts} +0 -0
|
@@ -50,6 +50,7 @@ var drapcode_constant_1 = require("drapcode-constant");
|
|
|
50
50
|
var date_util_1 = require("./date-util");
|
|
51
51
|
var util_1 = require("./util");
|
|
52
52
|
var prepare_query_1 = require("./prepare-query");
|
|
53
|
+
var query_utils_1 = require("./query-utils");
|
|
53
54
|
var queryParserNew = function (collectionName, query, constants, externalParams, currentUser, timezone, searchObj, refCollectionFieldsInItems, searchQueryTypeObj, lookupConfig) {
|
|
54
55
|
if (currentUser === void 0) { currentUser = {}; }
|
|
55
56
|
if (searchObj === void 0) { searchObj = null; }
|
|
@@ -57,10 +58,10 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
57
58
|
if (searchQueryTypeObj === void 0) { searchQueryTypeObj = {}; }
|
|
58
59
|
if (lookupConfig === void 0) { lookupConfig = []; }
|
|
59
60
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
-
var filterQuery, aggregateQuery, queryStr, searchQueryObj_1, finalQuery,
|
|
61
|
-
var
|
|
62
|
-
return __generator(this, function (
|
|
63
|
-
switch (
|
|
61
|
+
var filterQuery, aggregateQuery, queryStr, searchQueryObj_1, finalQuery, _a, searchAggregateQuery, likeQuery, projection, finder, sortBy, orderBy, aggregateFunctionField, offset, limit, direction;
|
|
62
|
+
var _b;
|
|
63
|
+
return __generator(this, function (_c) {
|
|
64
|
+
switch (_c.label) {
|
|
64
65
|
case 0:
|
|
65
66
|
if (!collectionName)
|
|
66
67
|
return [2 /*return*/, ""];
|
|
@@ -115,106 +116,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
115
116
|
aggregateQuery.push({ $match: finalQuery });
|
|
116
117
|
}
|
|
117
118
|
else if (searchObj) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (value) {
|
|
123
|
-
if (searchQueryTypeObj[key]) {
|
|
124
|
-
if (searchQueryTypeObj[key] === "boolean") {
|
|
125
|
-
// if input is string and db field type is boolean
|
|
126
|
-
aggregateQuery.push({
|
|
127
|
-
$addFields: (_b = {},
|
|
128
|
-
_b["_".concat(key)] = "$".concat(key),
|
|
129
|
-
_b),
|
|
130
|
-
});
|
|
131
|
-
likeQuery_1.push((_c = {},
|
|
132
|
-
_c["_".concat(key)] = toBoolean(value),
|
|
133
|
-
_c));
|
|
134
|
-
}
|
|
135
|
-
else if ([
|
|
136
|
-
"static_option",
|
|
137
|
-
"dynamic_option",
|
|
138
|
-
"reference",
|
|
139
|
-
"belongsTo",
|
|
140
|
-
].includes(searchQueryTypeObj[key])) {
|
|
141
|
-
// if input is string and db field type is array
|
|
142
|
-
aggregateQuery.push({
|
|
143
|
-
$addFields: (_d = {},
|
|
144
|
-
_d["_".concat(key)] = "$".concat(key),
|
|
145
|
-
_d),
|
|
146
|
-
});
|
|
147
|
-
likeQuery_1.push((_e = {},
|
|
148
|
-
_e["_".concat(key)] = { $all: [value] },
|
|
149
|
-
_e));
|
|
150
|
-
}
|
|
151
|
-
else if (searchQueryTypeObj[key] === "tel") {
|
|
152
|
-
// handling value when db field type is tel
|
|
153
|
-
aggregateQuery.push({
|
|
154
|
-
$addFields: (_f = {},
|
|
155
|
-
_f["_".concat(key)] = { $toString: "$".concat(key) },
|
|
156
|
-
_f),
|
|
157
|
-
});
|
|
158
|
-
likeQuery_1.push((_g = {},
|
|
159
|
-
_g["_".concat(key)] = {
|
|
160
|
-
$regex: value.startsWith("+") ? value.replace("+", "") : value,
|
|
161
|
-
$options: "i",
|
|
162
|
-
},
|
|
163
|
-
_g));
|
|
164
|
-
}
|
|
165
|
-
else if (searchQueryTypeObj[key] === "number") {
|
|
166
|
-
// handling value when db field type is Double/Int
|
|
167
|
-
aggregateQuery.push({
|
|
168
|
-
$addFields: (_h = {},
|
|
169
|
-
_h["_".concat(key)] = { $toString: { $toLong: "$".concat(key) } },
|
|
170
|
-
_h),
|
|
171
|
-
});
|
|
172
|
-
likeQuery_1.push((_j = {},
|
|
173
|
-
_j["_".concat(key)] = {
|
|
174
|
-
$regex: value,
|
|
175
|
-
$options: "i",
|
|
176
|
-
},
|
|
177
|
-
_j));
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
// if input is string and db field type is number
|
|
181
|
-
// converting db field to string first
|
|
182
|
-
aggregateQuery.push({
|
|
183
|
-
$addFields: (_k = {},
|
|
184
|
-
_k["_".concat(key)] = { $toString: "$".concat(key) },
|
|
185
|
-
_k),
|
|
186
|
-
});
|
|
187
|
-
likeQuery_1.push((_l = {},
|
|
188
|
-
_l["_".concat(key)] = {
|
|
189
|
-
$regex: value,
|
|
190
|
-
$options: "i",
|
|
191
|
-
},
|
|
192
|
-
_l));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
likeQuery_1.push((_m = {},
|
|
197
|
-
_m[key] = {
|
|
198
|
-
$regex: value,
|
|
199
|
-
$options: "i",
|
|
200
|
-
},
|
|
201
|
-
_m));
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
if (likeQuery_1.length) {
|
|
206
|
-
aggregateQuery.push({ $match: { $and: likeQuery_1 } });
|
|
119
|
+
_a = (0, query_utils_1.getSearchObjQuery)(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _a.searchAggregateQuery, likeQuery = _a.likeQuery;
|
|
120
|
+
aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery, true), searchAggregateQuery, true);
|
|
121
|
+
if (likeQuery.length) {
|
|
122
|
+
aggregateQuery.push({ $match: { $and: likeQuery } });
|
|
207
123
|
}
|
|
208
124
|
}
|
|
209
|
-
|
|
125
|
+
console.log("==> query", query);
|
|
126
|
+
projection = (0, query_utils_1.mongoSelectQuery)(query);
|
|
210
127
|
finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy, aggregateFunctionField = query.aggregateFunctionField;
|
|
211
128
|
if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
|
|
212
129
|
return [4 /*yield*/, Promise.all(refCollectionFieldsInItems.map(function (field) {
|
|
213
130
|
return (0, prepare_query_1.commonLookupSetting)(field, lookupConfig, aggregateQuery);
|
|
214
131
|
}))];
|
|
215
132
|
case 1:
|
|
216
|
-
|
|
217
|
-
|
|
133
|
+
_c.sent();
|
|
134
|
+
_c.label = 2;
|
|
218
135
|
case 2:
|
|
219
136
|
if (!["COUNT", "SUM", "AVG", "MIN", "MAX"].includes(finder) &&
|
|
220
137
|
!(0, util_1.isEmpty)(projection)) {
|
|
@@ -251,7 +168,7 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
|
|
|
251
168
|
}
|
|
252
169
|
if (finder != "COUNT" && sortBy) {
|
|
253
170
|
direction = orderBy && orderBy == "asc" ? 1 : -1;
|
|
254
|
-
aggregateQuery.push({ $sort: (
|
|
171
|
+
aggregateQuery.push({ $sort: (_b = {}, _b[sortBy] = direction, _b) });
|
|
255
172
|
}
|
|
256
173
|
if (finder != "COUNT" && limit) {
|
|
257
174
|
aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
|
|
@@ -310,56 +227,17 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
|
|
|
310
227
|
});
|
|
311
228
|
console.log("==> *** filterQuery #2 :>> ", filterQuery);
|
|
312
229
|
var hasAndQueryConjunction = queryConjunctions.includes("AND");
|
|
313
|
-
return modifyQuery(filterQuery, hasAndQueryConjunction);
|
|
314
|
-
};
|
|
315
|
-
var mongoSelectQuery = function (query) {
|
|
316
|
-
if (query === void 0) { query = {}; }
|
|
317
|
-
var projection = {};
|
|
318
|
-
var fieldsInclude = query.fieldsInclude, fieldsExclude = query.fieldsExclude, finder = query.finder;
|
|
319
|
-
if (!fieldsExclude)
|
|
320
|
-
fieldsExclude = [];
|
|
321
|
-
if (fieldsInclude[0] === "*") {
|
|
322
|
-
fieldsExclude.map(function (field) {
|
|
323
|
-
if (field)
|
|
324
|
-
return (projection["".concat(field)] = 0);
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
if (["FIND_ALL", "FIND"].includes(finder))
|
|
329
|
-
fieldsInclude = (0, util_1.processFieldsInlcude)(fieldsInclude);
|
|
330
|
-
fieldsInclude.map(function (field) {
|
|
331
|
-
if (field)
|
|
332
|
-
return (projection["".concat(field)] = 1);
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
return projection;
|
|
336
|
-
};
|
|
337
|
-
var modifyQuery = function (obj, hasAndQueryConjunction) {
|
|
338
|
-
if (obj === void 0) { obj = {}; }
|
|
339
|
-
if (hasAndQueryConjunction === void 0) { hasAndQueryConjunction = false; }
|
|
340
|
-
var arr = [];
|
|
341
|
-
console.log("🚀 ~ file: query-parser-new.ts:294 ~ modifyQuery ~ hasAndQueryConjunction:", hasAndQueryConjunction);
|
|
342
|
-
Object.entries(obj).forEach(function (_a) {
|
|
343
|
-
var key = _a[0], value = _a[1];
|
|
344
|
-
if (hasAndQueryConjunction) {
|
|
345
|
-
arr.push({ $and: value });
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
arr.push({ $or: value });
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
console.log("🚀 ~ file: query-parser-new.ts:303 ~ Object.entries ~ arr:", arr);
|
|
352
|
-
return arr;
|
|
230
|
+
return (0, query_utils_1.modifyQuery)(filterQuery, hasAndQueryConjunction);
|
|
353
231
|
};
|
|
354
232
|
var queryToMongo = function (query, requiredExternal, externalParams, constants, currentUser) {
|
|
355
233
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
|
|
356
234
|
if (currentUser === void 0) { currentUser = {}; }
|
|
357
235
|
var fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser);
|
|
358
|
-
var isDate = checkDate(fieldValue);
|
|
236
|
+
var isDate = (0, query_utils_1.checkDate)(fieldValue);
|
|
359
237
|
var key = query.key, field = query.field, value = query.value, fieldType = query.fieldType;
|
|
360
238
|
if (isDate)
|
|
361
239
|
fieldValue = new Date(fieldValue);
|
|
362
|
-
var condition =
|
|
240
|
+
var condition = drapcode_constant_1.SelectOptionFields.includes(fieldType);
|
|
363
241
|
if (condition && key === drapcode_constant_1.EQUALS && !isDate) {
|
|
364
242
|
if (!Array.isArray(fieldValue)) {
|
|
365
243
|
fieldValue = [fieldValue];
|
|
@@ -527,7 +405,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
527
405
|
},
|
|
528
406
|
_13;
|
|
529
407
|
if (key == drapcode_constant_1.BETWEEN) {
|
|
530
|
-
var _15 = getMinMaxValue(fieldValue), startValue = _15.startValue, endValue = _15.endValue, isInteger = _15.isInteger;
|
|
408
|
+
var _15 = (0, query_utils_1.getMinMaxValue)(fieldValue), startValue = _15.startValue, endValue = _15.endValue, isInteger = _15.isInteger;
|
|
531
409
|
return _14 = {},
|
|
532
410
|
_14[field] = {
|
|
533
411
|
$gte: isInteger ? +startValue : startValue,
|
|
@@ -540,12 +418,12 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
540
418
|
var key = query.key, value = query.value, fieldType = query.fieldType;
|
|
541
419
|
if (fieldType &&
|
|
542
420
|
!requiredExternal &&
|
|
543
|
-
|
|
421
|
+
drapcode_constant_1.SelectOptionFields.includes(fieldType)) {
|
|
544
422
|
//Todo: Remove if filter is working properly
|
|
545
423
|
// return value === CURRENT_USER ? currentUser["uuid"] : value;
|
|
546
424
|
var refCollection = query.refCollection, refField = query.refField;
|
|
547
425
|
var finalValue = "";
|
|
548
|
-
if (
|
|
426
|
+
if (drapcode_constant_1.OptionTypeFields.includes(fieldType)) {
|
|
549
427
|
if (!value) {
|
|
550
428
|
if (refCollection === drapcode_constant_1.CURRENT_USER) {
|
|
551
429
|
finalValue = currentUser[refField];
|
|
@@ -580,7 +458,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
580
458
|
return valueList_1;
|
|
581
459
|
}
|
|
582
460
|
if (key === drapcode_constant_1.BETWEEN) {
|
|
583
|
-
var _a = getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
461
|
+
var _a = (0, query_utils_1.getMinMaxValue)(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
|
|
584
462
|
if (requiredExternal) {
|
|
585
463
|
startValue_1 = "".concat(externalParams[startValue_1]);
|
|
586
464
|
endValue_1 = "".concat(externalParams[endValue_1]);
|
|
@@ -589,13 +467,13 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
589
467
|
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) {
|
|
590
468
|
return startValue_1.includes(cnst);
|
|
591
469
|
})) {
|
|
592
|
-
startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
|
|
470
|
+
startValue_1 = (0, query_utils_1.getValueOfProjectConstant)(startValue_1, currentUser, "");
|
|
593
471
|
}
|
|
594
472
|
else {
|
|
595
473
|
startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
|
|
596
474
|
}
|
|
597
475
|
if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) { return endValue_1.includes(cnst); })) {
|
|
598
|
-
endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
|
|
476
|
+
endValue_1 = (0, query_utils_1.getValueOfProjectConstant)(endValue_1, currentUser, "");
|
|
599
477
|
}
|
|
600
478
|
else {
|
|
601
479
|
endValue_1 = constants.filter(function (constant) { return constant.name == endValue_1; });
|
|
@@ -647,7 +525,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
647
525
|
return currentUser["uuid"];
|
|
648
526
|
}
|
|
649
527
|
if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
|
|
650
|
-
return getValueOfProjectConstant(value, {});
|
|
528
|
+
return (0, query_utils_1.getValueOfProjectConstant)(value, {}, "");
|
|
651
529
|
}
|
|
652
530
|
//TODO: This is just to confirm if external then it should be get from externalParams
|
|
653
531
|
if (requiredExternal) {
|
|
@@ -661,31 +539,3 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
661
539
|
var constantArr = constants.filter(function (constant) { return constant.name == value; });
|
|
662
540
|
return constantArr.length ? "" + constantArr[0].value : "";
|
|
663
541
|
};
|
|
664
|
-
var checkDate = function (queryValue) {
|
|
665
|
-
return ("" + queryValue).match(date_util_1.DATE_REGEX);
|
|
666
|
-
};
|
|
667
|
-
var getMinMaxValue = function (value) {
|
|
668
|
-
var isValid = value && value.includes("---");
|
|
669
|
-
if (isValid) {
|
|
670
|
-
var isInteger = value.includes("^");
|
|
671
|
-
var result = value.split("---");
|
|
672
|
-
var endValue = result[1];
|
|
673
|
-
if (isInteger && result.length)
|
|
674
|
-
endValue = endValue.slice(0, -1);
|
|
675
|
-
return { startValue: result[0], endValue: endValue, isInteger: isInteger };
|
|
676
|
-
}
|
|
677
|
-
else {
|
|
678
|
-
return { startValue: "", endValue: "" };
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
//TODO: need to fix for all app constant with these
|
|
682
|
-
var getValueOfProjectConstant = function (value, currentUser) {
|
|
683
|
-
if (value === drapcode_constant_1.CURRENT_USER)
|
|
684
|
-
return currentUser["uuid"];
|
|
685
|
-
if (value === drapcode_constant_1.CURRENT_DATE)
|
|
686
|
-
return (0, date_util_1.createLoggerDateFormat)();
|
|
687
|
-
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
688
|
-
return (0, date_util_1.createLogsDateFormat)();
|
|
689
|
-
if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
|
|
690
|
-
return (0, date_util_1.getDateValue)(value);
|
|
691
|
-
};
|
|
@@ -1,14 +1,2 @@
|
|
|
1
1
|
export declare const queryParser: (collectionName: string, query: any, constants: any[], externalParams: any, currentUser: any, timezone: string, searchObj: any, refCollectionFieldsInItems: any, searchQueryTypeObj: any, currentTenant: any, currentUserSetting: any, currentSubTenant: any, lookupConfig: any, rowLevelSecurityFilter: any) => Promise<any>;
|
|
2
2
|
export declare const isEntityInCondition: (value: any) => boolean;
|
|
3
|
-
export declare const isFixedValueQuery: (value: any) => boolean;
|
|
4
|
-
export declare const getMinMaxValue: (value: any) => {
|
|
5
|
-
startValue: any;
|
|
6
|
-
endValue: any;
|
|
7
|
-
isInteger: any;
|
|
8
|
-
isFixedValue: boolean;
|
|
9
|
-
} | {
|
|
10
|
-
startValue: string;
|
|
11
|
-
endValue: string;
|
|
12
|
-
isFixedValue: boolean;
|
|
13
|
-
isInteger?: undefined;
|
|
14
|
-
};
|