drapcode-utility 2.7.3 → 2.7.4-sandbox.1

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.
Files changed (148) hide show
  1. package/build/aws/aws-util.d.ts +6 -0
  2. package/build/aws/aws-util.d.ts.map +1 -0
  3. package/build/aws/aws-util.js +34 -0
  4. package/build/aws/aws-util.js.map +1 -0
  5. package/build/aws/encryption/KMS.d.ts +9 -0
  6. package/build/aws/encryption/KMS.d.ts.map +1 -0
  7. package/build/aws/encryption/KMS.js +65 -0
  8. package/build/aws/encryption/KMS.js.map +1 -0
  9. package/build/{encryption → aws/encryption}/crypt.d.ts +1 -0
  10. package/build/aws/encryption/crypt.d.ts.map +1 -0
  11. package/build/{encryption → aws/encryption}/crypt.js +25 -36
  12. package/build/aws/encryption/crypt.js.map +1 -0
  13. package/build/{encryption → aws/encryption}/file.d.ts +2 -1
  14. package/build/aws/encryption/file.d.ts.map +1 -0
  15. package/build/{encryption → aws/encryption}/file.js +2 -3
  16. package/build/aws/encryption/file.js.map +1 -0
  17. package/build/{encryption → aws/encryption}/index.d.ts +4 -3
  18. package/build/aws/encryption/index.d.ts.map +1 -0
  19. package/build/{encryption → aws/encryption}/index.js +41 -41
  20. package/build/aws/encryption/index.js.map +1 -0
  21. package/build/{encryption → aws/encryption}/utility.d.ts +1 -0
  22. package/build/aws/encryption/utility.d.ts.map +1 -0
  23. package/build/{encryption → aws/encryption}/utility.js +3 -2
  24. package/build/aws/encryption/utility.js.map +1 -0
  25. package/build/aws/model.d.ts +30 -0
  26. package/build/aws/model.d.ts.map +1 -0
  27. package/build/{encryption → aws}/model.js +1 -0
  28. package/build/aws/model.js.map +1 -0
  29. package/build/aws/s3-util.d.ts +36 -0
  30. package/build/aws/s3-util.d.ts.map +1 -0
  31. package/build/aws/s3-util.js +198 -0
  32. package/build/aws/s3-util.js.map +1 -0
  33. package/build/errors/app-error.d.ts +17 -4
  34. package/build/errors/app-error.d.ts.map +1 -0
  35. package/build/errors/app-error.js +184 -6
  36. package/build/errors/app-error.js.map +1 -0
  37. package/build/errors/async-handler.d.ts +3 -0
  38. package/build/errors/async-handler.d.ts.map +1 -0
  39. package/build/errors/async-handler.js +9 -0
  40. package/build/errors/async-handler.js.map +1 -0
  41. package/build/errors/axios-error.d.ts +2 -1
  42. package/build/errors/axios-error.d.ts.map +1 -0
  43. package/build/errors/axios-error.js +12 -8
  44. package/build/errors/axios-error.js.map +1 -0
  45. package/build/errors/bad-request-error.d.ts +2 -1
  46. package/build/errors/bad-request-error.d.ts.map +1 -0
  47. package/build/errors/bad-request-error.js +1 -0
  48. package/build/errors/bad-request-error.js.map +1 -0
  49. package/build/errors/custom-error.d.ts +1 -0
  50. package/build/errors/custom-error.d.ts.map +1 -0
  51. package/build/errors/custom-error.js +1 -0
  52. package/build/errors/custom-error.js.map +1 -0
  53. package/build/errors/error-classes.d.ts +23 -0
  54. package/build/errors/error-classes.d.ts.map +1 -0
  55. package/build/errors/error-classes.js +87 -0
  56. package/build/errors/error-classes.js.map +1 -0
  57. package/build/errors/error-codes.d.ts +47 -0
  58. package/build/errors/error-codes.d.ts.map +1 -0
  59. package/build/errors/error-codes.js +78 -0
  60. package/build/errors/error-codes.js.map +1 -0
  61. package/build/errors/error-obj.d.ts +10 -0
  62. package/build/errors/error-obj.d.ts.map +1 -0
  63. package/build/errors/error-obj.js +55 -0
  64. package/build/errors/error-obj.js.map +1 -0
  65. package/build/errors/get-error-details.d.ts +11 -0
  66. package/build/errors/get-error-details.d.ts.map +1 -0
  67. package/build/errors/get-error-details.js +28 -0
  68. package/build/errors/get-error-details.js.map +1 -0
  69. package/build/errors/not-found.d.ts +2 -1
  70. package/build/errors/not-found.d.ts.map +1 -0
  71. package/build/errors/not-found.js +3 -2
  72. package/build/errors/not-found.js.map +1 -0
  73. package/build/errors/wrap-error.d.ts +9 -0
  74. package/build/errors/wrap-error.d.ts.map +1 -0
  75. package/build/errors/wrap-error.js +17 -0
  76. package/build/errors/wrap-error.js.map +1 -0
  77. package/build/format-fields/index.d.ts +1 -0
  78. package/build/format-fields/index.d.ts.map +1 -0
  79. package/build/format-fields/index.js +13 -13
  80. package/build/format-fields/index.js.map +1 -0
  81. package/build/index.d.ts +25 -21
  82. package/build/index.d.ts.map +1 -0
  83. package/build/index.js +13 -7
  84. package/build/index.js.map +1 -0
  85. package/build/middlewares/redis/request-log.d.ts +1 -0
  86. package/build/middlewares/redis/request-log.d.ts.map +1 -0
  87. package/build/middlewares/redis/request-log.js +3 -2
  88. package/build/middlewares/redis/request-log.js.map +1 -0
  89. package/build/query/queryBuilder.d.ts +1 -0
  90. package/build/query/queryBuilder.d.ts.map +1 -0
  91. package/build/query/queryBuilder.js +66 -129
  92. package/build/query/queryBuilder.js.map +1 -0
  93. package/build/utils/check-error.d.ts +1 -0
  94. package/build/utils/check-error.d.ts.map +1 -0
  95. package/build/utils/check-error.js +14 -15
  96. package/build/utils/check-error.js.map +1 -0
  97. package/build/utils/common-util.d.ts +2 -1
  98. package/build/utils/common-util.d.ts.map +1 -0
  99. package/build/utils/common-util.js +46 -47
  100. package/build/utils/common-util.js.map +1 -0
  101. package/build/utils/date-util.d.ts +1 -0
  102. package/build/utils/date-util.d.ts.map +1 -0
  103. package/build/utils/date-util.js +59 -60
  104. package/build/utils/date-util.js.map +1 -0
  105. package/build/utils/file-util.d.ts +9 -0
  106. package/build/utils/file-util.d.ts.map +1 -0
  107. package/build/utils/file-util.js +120 -9
  108. package/build/utils/file-util.js.map +1 -0
  109. package/build/utils/prepare-query.d.ts +1 -0
  110. package/build/utils/prepare-query.d.ts.map +1 -0
  111. package/build/utils/prepare-query.js +15 -17
  112. package/build/utils/prepare-query.js.map +1 -0
  113. package/build/utils/project-util.d.ts +2 -1
  114. package/build/utils/project-util.d.ts.map +1 -0
  115. package/build/utils/project-util.js +45 -50
  116. package/build/utils/project-util.js.map +1 -0
  117. package/build/utils/query-parser.d.ts +1 -1
  118. package/build/utils/query-parser.d.ts.map +1 -0
  119. package/build/utils/query-parser.js +6 -568
  120. package/build/utils/query-parser.js.map +1 -0
  121. package/build/utils/query-utils.d.ts +1 -0
  122. package/build/utils/query-utils.d.ts.map +1 -0
  123. package/build/utils/query-utils.js +46 -50
  124. package/build/utils/query-utils.js.map +1 -0
  125. package/build/utils/rest-client.d.ts +1 -0
  126. package/build/utils/rest-client.d.ts.map +1 -0
  127. package/build/utils/rest-client.js +88 -122
  128. package/build/utils/rest-client.js.map +1 -0
  129. package/build/utils/token.d.ts +1 -0
  130. package/build/utils/token.d.ts.map +1 -0
  131. package/build/utils/token.js +4 -3
  132. package/build/utils/token.js.map +1 -0
  133. package/build/utils/util.d.ts +2 -1
  134. package/build/utils/util.d.ts.map +1 -0
  135. package/build/utils/util.js +340 -392
  136. package/build/utils/util.js.map +1 -0
  137. package/build/utils/uuid-generator.d.ts +1 -0
  138. package/build/utils/uuid-generator.d.ts.map +1 -0
  139. package/build/utils/uuid-generator.js +9 -8
  140. package/build/utils/uuid-generator.js.map +1 -0
  141. package/package.json +7 -6
  142. package/build/encryption/KMS.d.ts +0 -8
  143. package/build/encryption/KMS.js +0 -67
  144. package/build/encryption/model.d.ts +0 -17
  145. package/build/middlewares/error-logger.d.ts +0 -3
  146. package/build/middlewares/error-logger.js +0 -74
  147. package/build/utils/s3-util.d.ts +0 -36
  148. package/build/utils/s3-util.js +0 -275
@@ -1,581 +1,19 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isEntityInCondition = exports.queryParser = void 0;
7
- const moment_1 = __importDefault(require("moment"));
8
- const drapcode_constant_1 = require("drapcode-constant");
9
- const date_util_1 = require("./date-util");
10
- const util_1 = require("./util");
11
- const prepare_query_1 = require("./prepare-query");
12
- const query_utils_1 = require("./query-utils");
13
- const queryParser = async (collectionName, query, constants, externalParams, currentUser = {}, timezone, searchObj = null, refCollectionFieldsInItems = null, searchQueryTypeObj = {}, currentTenant = {}, currentUserSetting = {}, currentSubTenant = {}, lookupConfig = [], rowLevelSecurityFilter) => {
14
- if (!collectionName)
15
- return "";
16
- if (!query)
17
- return "";
18
- console.log("***1*** queryParser ***");
19
- console.log("%%%%% refCollectionFieldsInItems", JSON.stringify(refCollectionFieldsInItems));
20
- console.log("%%%% timezone", timezone);
21
- console.log("collectionName", collectionName);
22
- console.log("query", JSON.stringify(query));
23
- console.log("constants", JSON.stringify(constants));
24
- console.log("externalParams", JSON.stringify(externalParams));
25
- console.log("currentUser", JSON.stringify(currentUser));
26
- console.log("searchObj", JSON.stringify(searchObj));
27
- console.log("searchQueryTypeObj", JSON.stringify(searchQueryTypeObj));
28
- let filterQuery = mongoFilterQuery(query, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
29
- console.log(`filterQuery`, JSON.stringify(filterQuery));
30
- let rlsFilterQuery = [];
31
- if (rowLevelSecurityFilter && rowLevelSecurityFilter.conditions.length) {
32
- rlsFilterQuery = mongoFilterQuery(rowLevelSecurityFilter, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
33
- console.log("**************************");
34
- console.log(`rlsFilterQuery`, JSON.stringify(rlsFilterQuery));
35
- }
36
- console.log(`==> searchQueryTypeObj :>>`, searchQueryTypeObj);
37
- let aggregateQuery = [];
38
- if (filterQuery.length &&
39
- ((filterQuery[0].$or && filterQuery[0].$or.length) ||
40
- (filterQuery[0].$and && filterQuery[0].$and.length))) {
41
- let searchQueryObj = null;
42
- if (searchObj) {
43
- const { searchAggregateQuery, likeQuery } = (0, query_utils_1.getSearchObjQuery)(searchObj, searchQueryTypeObj);
44
- aggregateQuery = [...aggregateQuery, ...searchAggregateQuery];
45
- console.log("likeQuery after getSearchObjQuery", JSON.stringify(likeQuery));
46
- if (likeQuery && likeQuery.length > 0) {
47
- searchQueryObj = likeQuery;
48
- }
49
- }
50
- console.log("aggregateQuery After search object condition", JSON.stringify(aggregateQuery));
51
- console.log("searchQueryObj", JSON.stringify(searchQueryObj));
52
- let finalQuery = { $and: filterQuery };
53
- if (rlsFilterQuery.length &&
54
- ((rlsFilterQuery[0].$or && rlsFilterQuery[0].$or.length) ||
55
- (rlsFilterQuery[0].$and && rlsFilterQuery[0].$and.length))) {
56
- finalQuery.$and.push(...rlsFilterQuery);
57
- }
58
- if (searchQueryObj) {
59
- finalQuery.$and.push(...searchQueryObj);
60
- }
61
- const { addTenantQuery, addSubTenantQuery } = query;
62
- const additionalFilters = [];
63
- if (addTenantQuery && currentTenant?.uuid) {
64
- additionalFilters.push({ tenantId: currentTenant.uuid });
65
- }
66
- if (addSubTenantQuery &&
67
- Array.isArray(currentUser.subTenantId) &&
68
- currentUser.subTenantId.length > 0) {
69
- const subTenantUuids = currentUser.subTenantId
70
- .map((item) => item?.uuid)
71
- .filter((uuid) => uuid); // Filters out undefined/null
72
- if (subTenantUuids.length > 0) {
73
- additionalFilters.push({ subTenantId: { $in: subTenantUuids } });
74
- }
75
- }
76
- if (additionalFilters.length > 0) {
77
- finalQuery.$and.push(...additionalFilters);
78
- }
79
- aggregateQuery.push({ $match: finalQuery });
80
- }
81
- else if (searchObj) {
82
- console.log("I donot have filter query");
83
- const { searchAggregateQuery, likeQuery } = (0, query_utils_1.getSearchObjQuery)(searchObj, searchQueryTypeObj);
84
- aggregateQuery = [...aggregateQuery, ...searchAggregateQuery];
85
- if (likeQuery.length) {
86
- aggregateQuery.push({ $match: { $and: likeQuery } });
87
- }
88
- }
89
- console.log(`==> query`, query);
90
- console.log("lookupConfig", lookupConfig);
91
- let projection = (0, query_utils_1.mongoSelectQuery)(query);
92
- let { finder, sortBy, orderBy, aggregateFunctionField } = query;
93
- if (finder != "COUNT" && refCollectionFieldsInItems) {
94
- await Promise.all(refCollectionFieldsInItems.map((field) => (0, prepare_query_1.commonLookupSetting)(field, lookupConfig, aggregateQuery)));
95
- }
96
- if (!util_1.nonFindQuery.includes(finder) && !(0, util_1.isEmpty)(projection)) {
97
- aggregateQuery.push({ $project: projection });
98
- }
99
- if (finder === "COUNT") {
100
- aggregateQuery.push({ $group: { _id: null, count: { $sum: 1 } } });
101
- }
102
- else if (finder === "SUM") {
103
- aggregateQuery.push({
104
- $group: { _id: null, total: { $sum: `$${aggregateFunctionField}` } },
105
- });
106
- }
107
- else if (finder === "AVG") {
108
- aggregateQuery.push({
109
- $group: { _id: null, average: { $avg: `$${aggregateFunctionField}` } },
110
- });
111
- }
112
- else if (finder === "MIN") {
113
- aggregateQuery.push({
114
- $group: { _id: null, minimum: { $min: `$${aggregateFunctionField}` } },
115
- });
116
- }
117
- else if (finder === "MAX") {
118
- aggregateQuery.push({
119
- $group: { _id: null, maximum: { $max: `$${aggregateFunctionField}` } },
120
- });
121
- }
122
- let offset = externalParams.offset || 0;
123
- let limit = externalParams.limit || 20000;
124
- let resetLimit = externalParams.resetLimit || false;
125
- if (externalParams.pagination == "false") {
126
- limit = 0;
127
- sortBy = 0;
128
- }
129
- // Reset limit value to 1 in case filter is of type FIND or when it's a COUNT finder for FIND filter
130
- if (finder === "FIND" || (util_1.nonFindQuery.includes(finder) && resetLimit)) {
131
- offset = 0;
132
- limit = 1;
133
- }
134
- if (!util_1.nonFindQuery.includes(finder) && sortBy) {
135
- let direction = orderBy && orderBy == "asc" ? 1 : -1;
136
- aggregateQuery.push({ $sort: { [sortBy]: direction, _id: 1 } });
137
- }
138
- if (!util_1.nonFindQuery.includes(finder) && limit) {
139
- aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
140
- }
141
- console.log(`==> aggregateQuery`, aggregateQuery);
142
- return aggregateQuery;
143
- };
144
- exports.queryParser = queryParser;
145
- const mongoFilterQuery = (query, externalParams, constants, currentUser = {}, currentTenant = {}, currentUserSetting = {}, currentSubTenant = {}, timezone) => {
146
- let filterQuery = { $or0: [] };
147
- let { conditions } = query;
148
- let queryConjunctions = [];
149
- conditions.forEach((queryObj, index) => {
150
- const { query, requiredExternal, conjunctionType } = queryObj;
151
- console.log("query :>> ", JSON.stringify(query));
152
- let mongoQuery = queryToMongo(query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
153
- console.log(":::::::::mongoQuery::::", JSON.stringify(mongoQuery));
154
- queryConjunctions.push(conjunctionType);
155
- if (conjunctionType == "OR") {
156
- let lastKey = Object.keys(filterQuery)[Object.keys(filterQuery).length - 1];
157
- if (filterQuery[lastKey] && Array.isArray(filterQuery[lastKey])) {
158
- filterQuery[lastKey].push(mongoQuery);
159
- }
160
- else {
161
- filterQuery[`$or${index}`] = [mongoQuery];
162
- }
163
- }
164
- else if (conjunctionType == "AND") {
165
- let lastKey = Object.keys(filterQuery)[Object.keys(filterQuery).length - 1];
166
- if (filterQuery[lastKey] && Array.isArray(filterQuery[lastKey])) {
167
- filterQuery[lastKey].push(mongoQuery);
168
- }
169
- else {
170
- filterQuery[`$and${index}`] = [mongoQuery];
171
- }
172
- }
173
- else {
174
- filterQuery[`$or${index}`] = [mongoQuery];
175
- }
176
- });
177
- console.log("==> *** filterQuery mongoFilterQuery :>> ", filterQuery);
178
- const hasAndQueryConjunction = queryConjunctions.includes("AND");
179
- return (0, query_utils_1.modifyQuery)(filterQuery, hasAndQueryConjunction);
180
- };
181
- const queryToMongo = (query, requiredExternal, externalParams, constants, currentUser = {}, currentTenant = {}, currentUserSetting = {}, currentSubTenant = {}, timezone) => {
182
- const { key, field, value, fieldType } = query;
183
- if ([drapcode_constant_1.EQUALS, drapcode_constant_1.NOT_EQUAL, drapcode_constant_1.EQUALS_OR_IGNORE].includes(key) &&
184
- typeof value === "string" &&
185
- drapcode_constant_1.DateRangeConstant.some((cnst) => value.includes(cnst))) {
186
- let final = (0, date_util_1.getDateRangeValue)(key, field, value);
187
- console.log("\n ===final getDateRangeValue", final);
188
- return final;
189
- }
190
- let fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone);
191
- if (["undefined", "null", null, undefined, ""].includes(fieldValue)) {
192
- //TODO: In case field is not present in old record then fieldValue is undefined
193
- //TODO: In case of this, we assign some random string to avoid resulting all values
194
- //TODO: This is use case in Spot Factor Project, where a new user with blank value able to see all records
195
- //TODO: Discussed on meet
196
- fieldValue = `random_string_since_field_not_present_${(0, moment_1.default)(1318874398806).valueOf()}`;
197
- }
198
- console.log("fieldValue queryToMongo 1", fieldValue);
199
- let isDate = (0, query_utils_1.isItDate)(fieldValue);
200
- console.log("isDate queryToMongo 2", isDate);
201
- // Todo: Remove if it's working properly
202
- // if (isDate) fieldValue = new Date(fieldValue);
203
- console.log("fieldValue queryToMongo 1", fieldValue);
204
- let condition = [...drapcode_constant_1.OptionTypeFields, ...drapcode_constant_1.BelongsToReferenceField].includes(fieldType);
205
- if (condition && key === drapcode_constant_1.EQUALS && !isDate) {
206
- if (!Array.isArray(fieldValue)) {
207
- fieldValue = [fieldValue];
208
- }
209
- return { [field]: { $in: fieldValue || [] } };
210
- }
211
- if (condition && key === drapcode_constant_1.NOT_EQUAL && !isDate) {
212
- if (!Array.isArray(fieldValue)) {
213
- fieldValue = [fieldValue];
214
- }
215
- return { [field]: { $nin: fieldValue || [] } };
216
- }
217
- if (condition && key === drapcode_constant_1.EQUALS_OR_IGNORE && !isDate) {
218
- if (typeof fieldValue === "string" && fieldValue.startsWith("CURRENT_")) {
219
- fieldValue = "random_string_since_field_not_present_1318874398806";
220
- } //Doing this because when Current Logged In Tenant/Settings/User have no data in that specific field then they return the fieldValue as CURRENT_SETTINGS:field not blank
221
- if (!Array.isArray(fieldValue)) {
222
- fieldValue = [fieldValue];
223
- }
224
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
225
- ? { [field]: { $in: fieldValue || [] } }
226
- : {};
227
- }
228
- if (condition && key === drapcode_constant_1.IS_NULL) {
229
- return {
230
- $or: [
231
- { [field]: { $exists: false } },
232
- { [field]: { $type: "array", $eq: [] } },
233
- ],
234
- };
235
- }
236
- if (condition && key === drapcode_constant_1.IS_NOT_NULL) {
237
- return { [field]: { $exists: true, $type: "array", $ne: [] } };
238
- }
239
- if (key === drapcode_constant_1.IS_NOT_NULL)
240
- return { [field]: { $nin: [null, ""] } };
241
- if (key === drapcode_constant_1.IS_NULL)
242
- return { [field]: { $in: [null, ""] } };
243
- if (key === drapcode_constant_1.LIKE)
244
- return { [field]: { $regex: fieldValue, $options: "i" } };
245
- if (key === drapcode_constant_1.GREATER_THAN_EQUALS_TO)
246
- return { [field]: { $gte: isDate ? fieldValue : +fieldValue } };
247
- if (key === drapcode_constant_1.LESS_THAN_EQUALS_TO)
248
- return { [field]: { $lte: isDate ? fieldValue : +fieldValue } };
249
- if (key === drapcode_constant_1.LESS_THAN)
250
- return { [field]: { $lt: isDate ? fieldValue : +fieldValue } };
251
- if (key === drapcode_constant_1.GREATER_THAN)
252
- return { [field]: { $gt: isDate ? fieldValue : +fieldValue } };
253
- if (key === drapcode_constant_1.IN_LIST) {
254
- if (!Array.isArray(fieldValue)) {
255
- fieldValue = [fieldValue];
256
- }
257
- return { [field]: { $in: fieldValue || [] } };
258
- }
259
- if (key === drapcode_constant_1.NOT_IN_LIST) {
260
- if (!Array.isArray(fieldValue)) {
261
- fieldValue = [fieldValue];
262
- }
263
- return { [field]: { $nin: fieldValue || [] } };
264
- }
265
- if (key === drapcode_constant_1.EQUALS && isDate) {
266
- return {
267
- [field]: {
268
- $gte: fieldValue,
269
- $lt: (0, date_util_1.nextDayDate)(fieldValue),
270
- },
271
- };
272
- }
273
- if (key === drapcode_constant_1.EQUALS_OR_IGNORE && isDate) {
274
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
275
- ? {
276
- [field]: {
277
- $gte: fieldValue,
278
- $lt: (0, date_util_1.nextDayDate)(fieldValue),
279
- },
280
- }
281
- : {};
282
- }
283
- if (key == drapcode_constant_1.EQUALS && field === "createdBy")
284
- return {
285
- $and: [
286
- { [field]: { $ne: null } },
287
- { [field]: { $ne: "" } },
288
- { [field]: { $eq: fieldValue } },
289
- ],
290
- };
291
- if (key === drapcode_constant_1.EQUALS_OR_IGNORE && field === "createdBy") {
292
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
293
- ? {
294
- $and: [
295
- { [field]: { $ne: null } },
296
- { [field]: { $ne: "" } },
297
- { [field]: { $eq: fieldValue } },
298
- ],
299
- }
300
- : {};
301
- }
302
- if (key == drapcode_constant_1.EQUALS && fieldType === drapcode_constant_1.FieldTypes.boolean.id && fieldValue)
303
- return JSON.parse(fieldValue)
304
- ? {
305
- [field]: JSON.parse(fieldValue),
306
- }
307
- : {
308
- $or: [
309
- { [field]: JSON.parse(fieldValue) },
310
- { [field]: { $exists: false } },
311
- ],
312
- };
313
- if (key === drapcode_constant_1.EQUALS_OR_IGNORE && fieldType === drapcode_constant_1.FieldTypes.boolean.id) {
314
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
315
- ? JSON.parse(fieldValue)
316
- ? {
317
- [field]: JSON.parse(fieldValue),
318
- }
319
- : {
320
- $or: [
321
- { [field]: JSON.parse(fieldValue) },
322
- { [field]: { $exists: false } },
323
- ],
324
- }
325
- : {};
326
- }
327
- if (key == drapcode_constant_1.EQUALS) {
328
- console.log("I am query parser");
329
- console.log("fieldType", fieldType);
330
- if (fieldType === drapcode_constant_1.FieldTypes.boolean.id) {
331
- return { [field]: !!fieldValue };
332
- }
333
- if (fieldType === drapcode_constant_1.FieldTypes.number.id) {
334
- return { [field]: +fieldValue };
335
- }
336
- console.log("Nothing match");
337
- return { [field]: `${fieldValue}` };
338
- }
339
- if (key === drapcode_constant_1.EQUALS_OR_IGNORE) {
340
- if (fieldType === drapcode_constant_1.FieldTypes.boolean.id) {
341
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
342
- ? { [field]: !!fieldValue }
343
- : {};
344
- }
345
- if (fieldType === drapcode_constant_1.FieldTypes.number.id) {
346
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
347
- ? { [field]: +fieldValue }
348
- : {};
349
- }
350
- else {
351
- return !fieldValue.includes("random_string_since_field_not_present_1318874398806")
352
- ? { [field]: fieldValue }
353
- : {};
354
- }
355
- }
356
- if (key == drapcode_constant_1.NOT_EQUAL)
357
- if (fieldType === drapcode_constant_1.FieldTypes.number.id) {
358
- return { [field]: { $ne: +fieldValue } };
359
- }
360
- else
361
- return {
362
- [field]: {
363
- $ne: fieldType === drapcode_constant_1.FieldTypes.boolean.id && fieldValue
364
- ? JSON.parse(fieldValue)
365
- : fieldValue,
366
- },
367
- };
368
- if (key == drapcode_constant_1.BETWEEN) {
369
- const { startValue, endValue, isInteger } = (0, query_utils_1.getMinMaxValue)(fieldValue);
370
- return {
371
- [field]: {
372
- $gte: isInteger ? +startValue : startValue,
373
- $lte: isInteger ? +endValue : endValue,
374
- },
375
- };
376
- }
377
- };
3
+ exports.isEntityInCondition = void 0;
378
4
  const isEntityInCondition = (value) => {
379
5
  let isEntity = false;
380
6
  if (value && Array.isArray(value)) {
381
7
  value.forEach((val) => {
382
- if (typeof val === "string" || val instanceof String)
383
- isEntity = val.startsWith("ENTITY::");
8
+ if (typeof val === 'string' || val instanceof String)
9
+ isEntity = val.startsWith('ENTITY::');
384
10
  });
385
11
  }
386
12
  else {
387
- if (value && (typeof value === "string" || value instanceof String))
388
- isEntity = value.startsWith("ENTITY::");
13
+ if (value && (typeof value === 'string' || value instanceof String))
14
+ isEntity = value.startsWith('ENTITY::');
389
15
  }
390
16
  return isEntity;
391
17
  };
392
18
  exports.isEntityInCondition = isEntityInCondition;
393
- const replaceExternalParams = (query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, currentSubTenant, timezone) => {
394
- const { key, value, fieldType } = query;
395
- if (fieldType &&
396
- !requiredExternal &&
397
- [...drapcode_constant_1.OptionTypeFields, ...drapcode_constant_1.BelongsToReferenceField].includes(fieldType)) {
398
- const { refCollection, refField } = query;
399
- let finalValue = "";
400
- if (drapcode_constant_1.OptionTypeFields.includes(fieldType)) {
401
- if (!value) {
402
- if (refCollection === drapcode_constant_1.CURRENT_USER) {
403
- finalValue = currentUser[refField];
404
- }
405
- if (refCollection === drapcode_constant_1.CURRENT_TENANT) {
406
- finalValue = currentTenant[refField];
407
- }
408
- if (refCollection === drapcode_constant_1.CURRENT_SETTINGS) {
409
- finalValue = currentUserSetting[refField];
410
- }
411
- if (refCollection === drapcode_constant_1.CURRENT_SUB_TENANT) {
412
- finalValue = currentSubTenant[refField];
413
- }
414
- }
415
- }
416
- if (value === drapcode_constant_1.CURRENT_USER) {
417
- finalValue = currentUser["uuid"];
418
- }
419
- if (!finalValue)
420
- finalValue = value;
421
- return finalValue;
422
- }
423
- if (fieldType &&
424
- fieldType === drapcode_constant_1.FieldTypes.boolean.id &&
425
- ["true", "false", "", true, false].includes(value)) {
426
- return "" + value;
427
- }
428
- if ([drapcode_constant_1.IN_LIST, drapcode_constant_1.NOT_IN_LIST].includes(key)) {
429
- let valueList = [];
430
- if (value && Array.isArray(value)) {
431
- value.forEach((val) => valueList.push(val));
432
- constants.forEach((constant) => {
433
- value.forEach((val) => {
434
- if (val === constant.name)
435
- valueList.push(constant.value);
436
- });
437
- });
438
- }
439
- else {
440
- const constantDataObj = [
441
- { constantName: drapcode_constant_1.CURRENT_USER, data: currentUser },
442
- { constantName: drapcode_constant_1.CURRENT_TENANT, data: currentTenant },
443
- { constantName: drapcode_constant_1.CURRENT_SETTINGS, data: currentUserSetting },
444
- { constantName: drapcode_constant_1.CURRENT_SUB_TENANT, data: currentSubTenant },
445
- ];
446
- constantDataObj.forEach((cnst) => {
447
- if (value.includes(cnst.constantName)) {
448
- const currentDataValue = getCurrentDataValueFrom(value, cnst.constantName, cnst.data, true);
449
- if (currentDataValue) {
450
- valueList = Array.isArray(currentDataValue)
451
- ? [...valueList, ...currentDataValue]
452
- : [...valueList, currentDataValue];
453
- }
454
- }
455
- });
456
- }
457
- return valueList;
458
- }
459
- if (key === drapcode_constant_1.BETWEEN) {
460
- let { startValue, endValue, isFixedValue } = (0, query_utils_1.getMinMaxValue)(value);
461
- if (requiredExternal) {
462
- startValue = `${externalParams[startValue]}`;
463
- endValue = `${externalParams[endValue]}`;
464
- }
465
- else {
466
- if ([drapcode_constant_1.CURRENT_USER, ...drapcode_constant_1.DateConstant].some((cnst) => startValue.includes(cnst))) {
467
- startValue = (0, query_utils_1.getValueOfProjectConstant)(startValue, currentUser, timezone);
468
- }
469
- else if (!isFixedValue) {
470
- startValue = constants.filter((constant) => constant.name == startValue);
471
- }
472
- if ([drapcode_constant_1.CURRENT_USER, ...drapcode_constant_1.DateConstant].some((cnst) => endValue.includes(cnst))) {
473
- endValue = (0, query_utils_1.getValueOfProjectConstant)(endValue, currentUser, timezone);
474
- }
475
- else if (!isFixedValue) {
476
- endValue = constants.filter((constant) => constant.name == endValue);
477
- }
478
- }
479
- if (Array.isArray(startValue)) {
480
- startValue = startValue[0].value;
481
- }
482
- if (Array.isArray(endValue)) {
483
- endValue = endValue[0].value;
484
- }
485
- if (!isNaN(startValue)) {
486
- return `${startValue}---${endValue}^`;
487
- }
488
- else
489
- return `${startValue}---${endValue}`;
490
- }
491
- const currentUserValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_USER, currentUser);
492
- console.log("\n currentUserValue :>> ", currentUserValue);
493
- if (currentUserValue)
494
- return currentUserValue;
495
- const currentTenantValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_TENANT, currentTenant);
496
- console.log("\n currentTenantValue :>> ", currentTenantValue);
497
- if (currentTenantValue)
498
- return currentTenantValue;
499
- const currentUserSettingsValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_SETTINGS, currentUserSetting);
500
- console.log("\n currentUserSettingsValue :>> ", currentUserSettingsValue);
501
- if (currentUserSettingsValue)
502
- return currentUserSettingsValue;
503
- const currentSubTenantValue = getCurrentDataValueFrom(value, drapcode_constant_1.CURRENT_SUB_TENANT, currentSubTenant);
504
- if (currentSubTenantValue)
505
- return currentSubTenantValue;
506
- if (drapcode_constant_1.DateConstant.some((cnst) => value.includes(cnst))) {
507
- return (0, query_utils_1.getValueOfProjectConstant)(value, {}, timezone);
508
- }
509
- if ((0, exports.isEntityInCondition)(value)) {
510
- const key = value.replace("ENTITY::", "");
511
- return externalParams[key] ? externalParams[key] : "";
512
- }
513
- if ((0, query_utils_1.isFixedValueQuery)(value))
514
- return value.replace("FIXED_VALUE::", "");
515
- //TODO: This is just to confirm if external then it should be get from externalParams
516
- if (requiredExternal) {
517
- //TODO: Value returns from here undefined.
518
- let externalParamValue = externalParams[`${value}`];
519
- if (!isNaN(externalParamValue)) {
520
- return +externalParamValue;
521
- }
522
- return externalParams[`${value}`];
523
- }
524
- let constantArr = constants.filter((constant) => constant.name == value);
525
- return constantArr.length ? "" + constantArr[0].value : "";
526
- };
527
- const getCurrentDataValueFrom = (value, constantName, data, isMultiRef = false) => {
528
- if (value.includes(constantName)) {
529
- if (value === constantName)
530
- return data[`uuid`];
531
- const splitValues = value.split("::");
532
- console.log("splitValues", splitValues);
533
- let refCollection = "", refCollectionField = "";
534
- if (splitValues.length > 2) {
535
- refCollection = splitValues[1];
536
- refCollectionField = splitValues[2];
537
- }
538
- else if (splitValues.length === 2) {
539
- refCollection = splitValues[0];
540
- refCollectionField = splitValues[1];
541
- }
542
- else {
543
- refCollection = splitValues[0];
544
- refCollectionField = "";
545
- }
546
- console.log("refCollection", refCollection);
547
- console.log("refCollectionField", refCollectionField);
548
- console.log("first", refCollectionField && refCollection);
549
- if (refCollection && refCollectionField) {
550
- console.log("I have refCollection and Field");
551
- if (refCollection === constantName) {
552
- return data[refCollectionField];
553
- }
554
- else {
555
- let refCollectionData = data[refCollection];
556
- console.log("refCollectionData", refCollectionData);
557
- if (!refCollectionData)
558
- return "";
559
- if (refCollectionData.length > 1) {
560
- //TODO: Need to handle multi ref
561
- // Handled For IN_LIST and NOT_IN_LIST Condition
562
- if (!isMultiRef)
563
- return "";
564
- let finalValue = [];
565
- refCollectionData.forEach((refData) => {
566
- if (refData[refCollectionField])
567
- finalValue.push(refData[refCollectionField]);
568
- });
569
- return finalValue;
570
- }
571
- refCollectionData = refCollectionData[0];
572
- console.log(`refCollectionData[refCollectionField]`, refCollectionData[refCollectionField]);
573
- return refCollectionData[refCollectionField];
574
- }
575
- }
576
- //this means that data has to be match with currnet user field that is not ref type
577
- if (refCollection)
578
- return data[refCollection];
579
- return data[`uuid`];
580
- }
581
- };
19
+ //# sourceMappingURL=query-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-parser.js","sourceRoot":"","sources":["../../src/utils/query-parser.ts"],"names":[],"mappings":";;;AAAO,MAAM,mBAAmB,GAAG,CAAC,KAAU,EAAE,EAAE;IAChD,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACpB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,YAAY,MAAM;gBAAE,QAAQ,GAAG,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC9F,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,IAAI,KAAK,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,CAAC;YACjE,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAXW,QAAA,mBAAmB,uBAW9B"}
@@ -18,3 +18,4 @@ export declare const getMinMaxValue: (value: any) => {
18
18
  };
19
19
  export declare const isFixedValueQuery: (value: any) => boolean;
20
20
  export declare const getValueOfProjectConstant: (value: any, currentUser: any, timezone: string, fieldType?: string) => any;
21
+ //# sourceMappingURL=query-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-utils.d.ts","sourceRoot":"","sources":["../../src/utils/query-utils.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,iBAAiB,GAAI,WAAW,GAAG,EAAE,oBAAoB,GAAG;;;CA0IxE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,QAAO,GAAQ,QAgB/C,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,QAAQ,EAAE,yBAAwB,OAAe,KAAG,GAAG,EAWlF,CAAC;AAiBF,eAAO,MAAM,QAAQ,GAAI,YAAY,MAAM,4BAE1C,CAAC;AACF,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG;;;;;;;;;;CAaxC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,OAAO,GAAG,YAY3C,CAAC;AACF,eAAO,MAAM,yBAAyB,GACpC,OAAO,GAAG,EACV,aAAa,GAAG,EAChB,UAAU,MAAM,EAChB,YAAW,MAAyB,QAYrC,CAAC"}