drapcode-utility 1.9.5 → 1.9.7
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/utils/query-parser.d.ts +1 -1
- package/build/utils/query-parser.js +43 -16
- package/build/utils/util.d.ts +1 -1
- package/build/utils/util.js +25 -4
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
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, lookupConfig: any, rowLevelSecurityFilter: any) => Promise<any>;
|
|
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
3
|
export declare const isFixedValueQuery: (value: any) => boolean;
|
|
4
4
|
export declare const getMinMaxValue: (value: any) => {
|
|
@@ -54,19 +54,20 @@ var drapcode_constant_1 = require("drapcode-constant");
|
|
|
54
54
|
var date_util_1 = require("./date-util");
|
|
55
55
|
var util_1 = require("./util");
|
|
56
56
|
var prepare_query_1 = require("./prepare-query");
|
|
57
|
-
var queryParser = function (collectionName, query, constants, externalParams, currentUser, timezone, searchObj, refCollectionFieldsInItems, searchQueryTypeObj, currentTenant, currentUserSetting, lookupConfig, rowLevelSecurityFilter) {
|
|
57
|
+
var queryParser = function (collectionName, query, constants, externalParams, currentUser, timezone, searchObj, refCollectionFieldsInItems, searchQueryTypeObj, currentTenant, currentUserSetting, currentSubTenant, lookupConfig, rowLevelSecurityFilter) {
|
|
58
58
|
if (currentUser === void 0) { currentUser = {}; }
|
|
59
59
|
if (searchObj === void 0) { searchObj = null; }
|
|
60
60
|
if (refCollectionFieldsInItems === void 0) { refCollectionFieldsInItems = null; }
|
|
61
61
|
if (searchQueryTypeObj === void 0) { searchQueryTypeObj = {}; }
|
|
62
62
|
if (currentTenant === void 0) { currentTenant = {}; }
|
|
63
63
|
if (currentUserSetting === void 0) { currentUserSetting = {}; }
|
|
64
|
+
if (currentSubTenant === void 0) { currentSubTenant = {}; }
|
|
64
65
|
if (lookupConfig === void 0) { lookupConfig = []; }
|
|
65
66
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
66
|
-
var filterQuery, rlsFilterQuery, aggregateQuery, queryStr, searchQueryObj, _a, searchAggregateQuery, likeQuery, finalQuery, _b, searchAggregateQuery, likeQuery, projection, finder, sortBy, orderBy, offset, limit, resetLimit, direction;
|
|
67
|
-
var _c, _d, _e;
|
|
68
|
-
return __generator(this, function (
|
|
69
|
-
switch (
|
|
67
|
+
var filterQuery, rlsFilterQuery, aggregateQuery, queryStr, searchQueryObj, _a, searchAggregateQuery, likeQuery, finalQuery, addTenantQuery, addSubTenantQuery, additionalFilters, subTenantUuids, _b, searchAggregateQuery, likeQuery, projection, finder, sortBy, orderBy, offset, limit, resetLimit, direction;
|
|
68
|
+
var _c, _d, _e, _f;
|
|
69
|
+
return __generator(this, function (_g) {
|
|
70
|
+
switch (_g.label) {
|
|
70
71
|
case 0:
|
|
71
72
|
if (!collectionName)
|
|
72
73
|
return [2 /*return*/, ""];
|
|
@@ -82,11 +83,11 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
82
83
|
console.log("currentUser", JSON.stringify(currentUser));
|
|
83
84
|
console.log("searchObj", JSON.stringify(searchObj));
|
|
84
85
|
console.log("searchQueryTypeObj", JSON.stringify(searchQueryTypeObj));
|
|
85
|
-
filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone);
|
|
86
|
+
filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
|
|
86
87
|
console.log("filterQuery", JSON.stringify(filterQuery));
|
|
87
88
|
rlsFilterQuery = [];
|
|
88
89
|
if (rowLevelSecurityFilter && rowLevelSecurityFilter.conditions.length) {
|
|
89
|
-
rlsFilterQuery = mongoFilterQuery(rowLevelSecurityFilter, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone);
|
|
90
|
+
rlsFilterQuery = mongoFilterQuery(rowLevelSecurityFilter, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
|
|
90
91
|
console.log("**************************");
|
|
91
92
|
console.log("rlsFilterQuery", JSON.stringify(rlsFilterQuery));
|
|
92
93
|
}
|
|
@@ -116,7 +117,24 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
116
117
|
if (searchQueryObj) {
|
|
117
118
|
(_d = finalQuery.$and).push.apply(_d, searchQueryObj);
|
|
118
119
|
}
|
|
119
|
-
|
|
120
|
+
addTenantQuery = query.addTenantQuery, addSubTenantQuery = query.addSubTenantQuery;
|
|
121
|
+
additionalFilters = [];
|
|
122
|
+
if (addTenantQuery && (currentTenant === null || currentTenant === void 0 ? void 0 : currentTenant.uuid)) {
|
|
123
|
+
additionalFilters.push({ tenantId: currentTenant.uuid });
|
|
124
|
+
}
|
|
125
|
+
if (addSubTenantQuery &&
|
|
126
|
+
Array.isArray(currentUser.subTenantId) &&
|
|
127
|
+
currentUser.subTenantId.length > 0) {
|
|
128
|
+
subTenantUuids = currentUser.subTenantId
|
|
129
|
+
.map(function (item) { return item === null || item === void 0 ? void 0 : item.uuid; })
|
|
130
|
+
.filter(function (uuid) { return uuid; });
|
|
131
|
+
if (subTenantUuids.length > 0) {
|
|
132
|
+
additionalFilters.push({ subTenantId: { $in: subTenantUuids } });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (additionalFilters.length > 0) {
|
|
136
|
+
(_e = finalQuery.$and).push.apply(_e, additionalFilters);
|
|
137
|
+
}
|
|
120
138
|
aggregateQuery.push({ $match: finalQuery });
|
|
121
139
|
}
|
|
122
140
|
else if (searchObj) {
|
|
@@ -137,8 +155,8 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
137
155
|
return (0, prepare_query_1.commonLookupSetting)(field, lookupConfig, aggregateQuery);
|
|
138
156
|
}))];
|
|
139
157
|
case 1:
|
|
140
|
-
|
|
141
|
-
|
|
158
|
+
_g.sent();
|
|
159
|
+
_g.label = 2;
|
|
142
160
|
case 2:
|
|
143
161
|
if (finder != "COUNT" && !(0, util_1.isEmpty)(projection)) {
|
|
144
162
|
aggregateQuery.push({ $project: projection });
|
|
@@ -160,7 +178,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
|
|
|
160
178
|
}
|
|
161
179
|
if (finder != "COUNT" && sortBy) {
|
|
162
180
|
direction = orderBy && orderBy == "asc" ? 1 : -1;
|
|
163
|
-
aggregateQuery.push({ $sort: (
|
|
181
|
+
aggregateQuery.push({ $sort: (_f = {}, _f[sortBy] = direction, _f._id = 1, _f) });
|
|
164
182
|
}
|
|
165
183
|
if (finder != "COUNT" && limit) {
|
|
166
184
|
aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
|
|
@@ -186,17 +204,18 @@ var toBoolean = function (value) {
|
|
|
186
204
|
return false;
|
|
187
205
|
}
|
|
188
206
|
};
|
|
189
|
-
var mongoFilterQuery = function (query, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone) {
|
|
207
|
+
var mongoFilterQuery = function (query, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone) {
|
|
190
208
|
if (currentUser === void 0) { currentUser = {}; }
|
|
191
209
|
if (currentTenant === void 0) { currentTenant = {}; }
|
|
192
210
|
if (currentUserSetting === void 0) { currentUserSetting = {}; }
|
|
211
|
+
if (currentSubTenant === void 0) { currentSubTenant = {}; }
|
|
193
212
|
var filterQuery = { $or0: [] };
|
|
194
213
|
var conditions = query.conditions;
|
|
195
214
|
var queryConjunctions = [];
|
|
196
215
|
conditions.forEach(function (queryObj, index) {
|
|
197
216
|
var query = queryObj.query, requiredExternal = queryObj.requiredExternal;
|
|
198
217
|
console.log("query :>> ", JSON.stringify(query));
|
|
199
|
-
var mongoQuery = queryToMongo(query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone);
|
|
218
|
+
var mongoQuery = queryToMongo(query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
|
|
200
219
|
console.log(":::::::::mongoQuery::::", JSON.stringify(mongoQuery));
|
|
201
220
|
queryConjunctions.push(queryObj.conjunctionType);
|
|
202
221
|
if (queryObj.conjunctionType == "OR") {
|
|
@@ -267,11 +286,12 @@ var modifyQuery = function (obj, hasAndQueryConjunction) {
|
|
|
267
286
|
console.log("🚀 ~ file: query-parser.ts:303 ~ Object.entries ~ arr:", arr);
|
|
268
287
|
return arr;
|
|
269
288
|
};
|
|
270
|
-
var queryToMongo = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone) {
|
|
289
|
+
var queryToMongo = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone) {
|
|
271
290
|
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;
|
|
272
291
|
if (currentUser === void 0) { currentUser = {}; }
|
|
273
292
|
if (currentTenant === void 0) { currentTenant = {}; }
|
|
274
293
|
if (currentUserSetting === void 0) { currentUserSetting = {}; }
|
|
294
|
+
if (currentSubTenant === void 0) { currentSubTenant = {}; }
|
|
275
295
|
var key = query.key, field = query.field, value = query.value, fieldType = query.fieldType;
|
|
276
296
|
if ([drapcode_constant_1.EQUALS, drapcode_constant_1.NOT_EQUAL, drapcode_constant_1.EQUALS_OR_IGNORE].includes(key) &&
|
|
277
297
|
typeof value === "string" &&
|
|
@@ -280,7 +300,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
280
300
|
console.log("\n ===final getDateRangeValue", final);
|
|
281
301
|
return final;
|
|
282
302
|
}
|
|
283
|
-
var fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone);
|
|
303
|
+
var fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
|
|
284
304
|
if (["undefined", "null", null, undefined, ""].includes(fieldValue)) {
|
|
285
305
|
//TODO: In case field is not present in old record then fieldValue is undefined
|
|
286
306
|
//TODO: In case of this, we assign some random string to avoid resulting all values
|
|
@@ -513,7 +533,7 @@ var isFixedValueQuery = function (value) {
|
|
|
513
533
|
return isFixeValue;
|
|
514
534
|
};
|
|
515
535
|
exports.isFixedValueQuery = isFixedValueQuery;
|
|
516
|
-
var replaceExternalParams = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone) {
|
|
536
|
+
var replaceExternalParams = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone) {
|
|
517
537
|
var key = query.key, value = query.value, fieldType = query.fieldType;
|
|
518
538
|
if (fieldType &&
|
|
519
539
|
!requiredExternal &&
|
|
@@ -533,6 +553,9 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
533
553
|
if (refCollection === drapcode_constant_1.CURRENT_SETTINGS) {
|
|
534
554
|
finalValue = currentUserSetting[refField];
|
|
535
555
|
}
|
|
556
|
+
if (refCollection === drapcode_constant_1.CURRENT_SUB_TENANT) {
|
|
557
|
+
finalValue = currentSubTenant[refField];
|
|
558
|
+
}
|
|
536
559
|
}
|
|
537
560
|
}
|
|
538
561
|
if (value === drapcode_constant_1.CURRENT_USER) {
|
|
@@ -563,6 +586,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
563
586
|
{ constantName: drapcode_constant_1.CURRENT_USER, data: currentUser },
|
|
564
587
|
{ constantName: drapcode_constant_1.CURRENT_TENANT, data: currentTenant },
|
|
565
588
|
{ constantName: drapcode_constant_1.CURRENT_SETTINGS, data: currentUserSetting },
|
|
589
|
+
{ constantName: drapcode_constant_1.CURRENT_SUB_TENANT, data: currentSubTenant },
|
|
566
590
|
];
|
|
567
591
|
constantDataObj.forEach(function (cnst) {
|
|
568
592
|
if (value.includes(cnst.constantName)) {
|
|
@@ -624,6 +648,9 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
|
|
|
624
648
|
console.log("\n currentUserSettingsValue :>> ", currentUserSettingsValue);
|
|
625
649
|
if (currentUserSettingsValue)
|
|
626
650
|
return currentUserSettingsValue;
|
|
651
|
+
var currentSubTenantValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_SUB_TENANT, currentSubTenant);
|
|
652
|
+
if (currentSubTenantValue)
|
|
653
|
+
return currentSubTenantValue;
|
|
627
654
|
if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
|
|
628
655
|
return getValueOfProjectConstant(value, {}, timezone);
|
|
629
656
|
}
|
package/build/utils/util.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const arraysEqual: (array1: any, array2: any) => boolean;
|
|
|
20
20
|
export declare const convertItemToArray: (itemValue: any) => any[];
|
|
21
21
|
export declare const validateAlphanumericString: (str: string) => false | "String should contain only numbers and letters";
|
|
22
22
|
export declare const formatCustomCSSClasses: (customClasses: any) => string;
|
|
23
|
-
export declare const replaceDataValueIntoExpression: (expression: string, data: any, user: any, tenant: any, userSetting: any, sessionValue: any, envConstants: any, sessionFormValue: any, localStorageValue: any, cookiesValue: any) => string;
|
|
23
|
+
export declare const replaceDataValueIntoExpression: (expression: string, data: any, user: any, tenant: any, userSetting: any, subTenant: any, sessionValue: any, envConstants: any, sessionFormValue: any, localStorageValue: any, cookiesValue: any) => string;
|
|
24
24
|
export declare const parseJsonString: (str: string) => any;
|
|
25
25
|
export declare const parseValueFromData: (data: any, fieldName: string) => any;
|
|
26
26
|
export declare const unflattenObject: (obj: any) => {};
|
package/build/utils/util.js
CHANGED
|
@@ -294,7 +294,7 @@ var formatCustomCSSClasses = function (customClasses) {
|
|
|
294
294
|
return projectCustomCSSClassesData;
|
|
295
295
|
};
|
|
296
296
|
exports.formatCustomCSSClasses = formatCustomCSSClasses;
|
|
297
|
-
var replaceDataValueIntoExpression = function (expression, data, user, tenant, userSetting, sessionValue, envConstants, sessionFormValue, localStorageValue, cookiesValue) {
|
|
297
|
+
var replaceDataValueIntoExpression = function (expression, data, user, tenant, userSetting, subTenant, sessionValue, envConstants, sessionFormValue, localStorageValue, cookiesValue) {
|
|
298
298
|
var _a;
|
|
299
299
|
var contentList = (_a = expression
|
|
300
300
|
.match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
|
|
@@ -324,6 +324,12 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, u
|
|
|
324
324
|
dataOfItem = (0, exports.parseValueFromData)(userSetting, prop);
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
+
else if (prop.includes("current_sub_tenant")) {
|
|
328
|
+
prop = prop.replace("current_sub_tenant.", "");
|
|
329
|
+
if (Object.keys(userSetting).length > 0) {
|
|
330
|
+
dataOfItem = (0, exports.parseValueFromData)(subTenant, prop);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
327
333
|
else if (prop.includes("current_session")) {
|
|
328
334
|
console.log("Current Session");
|
|
329
335
|
prop = prop.replace("current_session.", "");
|
|
@@ -675,9 +681,24 @@ var validateData = function (fields, data) {
|
|
|
675
681
|
break;
|
|
676
682
|
case "reference":
|
|
677
683
|
case "belongsTo":
|
|
678
|
-
if (
|
|
679
|
-
fieldValue.some(function (item) {
|
|
680
|
-
|
|
684
|
+
if (Array.isArray(fieldValue)) {
|
|
685
|
+
var invalid = fieldValue.some(function (item) {
|
|
686
|
+
if (typeof item === "string")
|
|
687
|
+
return false;
|
|
688
|
+
if (typeof item === "object" && typeof item.uuid === "string")
|
|
689
|
+
return false;
|
|
690
|
+
return true;
|
|
691
|
+
});
|
|
692
|
+
if (invalid) {
|
|
693
|
+
errors.push("".concat(fieldTitle, " must be an array of UUID strings or objects with a uuid"));
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
else {
|
|
697
|
+
if (!(typeof fieldValue === "string" ||
|
|
698
|
+
(typeof fieldValue === "object" &&
|
|
699
|
+
typeof (fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.uuid) === "string"))) {
|
|
700
|
+
errors.push("".concat(fieldTitle, " must be a UUID string or an object with a uuid"));
|
|
701
|
+
}
|
|
681
702
|
}
|
|
682
703
|
break;
|
|
683
704
|
case "createdAt":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drapcode-utility",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"@types/voca": "^1.4.2",
|
|
38
38
|
"axios": "^1.1.2",
|
|
39
39
|
"dompurify": "^3.1.7",
|
|
40
|
-
"drapcode-constant": "^1.6.
|
|
41
|
-
"drapcode-logger": "^1.3.
|
|
42
|
-
"drapcode-redis": "^1.2.
|
|
40
|
+
"drapcode-constant": "^1.6.9",
|
|
41
|
+
"drapcode-logger": "^1.3.4",
|
|
42
|
+
"drapcode-redis": "^1.2.4",
|
|
43
43
|
"exiftool-vendored": "^28.2.1",
|
|
44
44
|
"express": "^4.17.1",
|
|
45
45
|
"gm": "^1.25.0",
|