drapcode-utility 1.2.1 → 1.2.2

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.
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ while (_) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -35,14 +35,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
39
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
40
+ to[j] = from[i];
41
+ return to;
46
42
  };
47
43
  Object.defineProperty(exports, "__esModule", { value: true });
48
44
  exports.queryParserNew = void 0;
@@ -85,11 +81,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
85
81
  if (searchQueryTypeObj[key]) {
86
82
  aggregateQuery.push({
87
83
  $addFields: (_b = {},
88
- _b["_".concat(key)] = { $toString: "$".concat(key) },
84
+ _b["_" + key] = { $toString: "$" + key },
89
85
  _b),
90
86
  });
91
87
  searchQueryObj_1.push((_c = {},
92
- _c["_".concat(key)] = {
88
+ _c["_" + key] = {
93
89
  $regex: value,
94
90
  $options: "i",
95
91
  },
@@ -123,11 +119,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
123
119
  // if input is string and db field type is boolean
124
120
  aggregateQuery.push({
125
121
  $addFields: (_b = {},
126
- _b["_".concat(key)] = "$".concat(key),
122
+ _b["_" + key] = "$" + key,
127
123
  _b),
128
124
  });
129
125
  likeQuery_1.push((_c = {},
130
- _c["_".concat(key)] = toBoolean(value),
126
+ _c["_" + key] = toBoolean(value),
131
127
  _c));
132
128
  }
133
129
  else if ([
@@ -139,22 +135,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
139
135
  // if input is string and db field type is array
140
136
  aggregateQuery.push({
141
137
  $addFields: (_d = {},
142
- _d["_".concat(key)] = "$".concat(key),
138
+ _d["_" + key] = "$" + key,
143
139
  _d),
144
140
  });
145
141
  likeQuery_1.push((_e = {},
146
- _e["_".concat(key)] = { $all: [value] },
142
+ _e["_" + key] = { $all: [value] },
147
143
  _e));
148
144
  }
149
145
  else if (searchQueryTypeObj[key] === "tel") {
150
146
  // handling value when db field type is tel
151
147
  aggregateQuery.push({
152
148
  $addFields: (_f = {},
153
- _f["_".concat(key)] = { $toString: "$".concat(key) },
149
+ _f["_" + key] = { $toString: "$" + key },
154
150
  _f),
155
151
  });
156
152
  likeQuery_1.push((_g = {},
157
- _g["_".concat(key)] = {
153
+ _g["_" + key] = {
158
154
  $regex: value.startsWith("+") ? value.replace("+", "") : value,
159
155
  $options: "i",
160
156
  },
@@ -164,11 +160,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
164
160
  // handling value when db field type is Double/Int
165
161
  aggregateQuery.push({
166
162
  $addFields: (_h = {},
167
- _h["_".concat(key)] = { $toString: { $toLong: "$".concat(key) } },
163
+ _h["_" + key] = { $toString: { $toLong: "$" + key } },
168
164
  _h),
169
165
  });
170
166
  likeQuery_1.push((_j = {},
171
- _j["_".concat(key)] = {
167
+ _j["_" + key] = {
172
168
  $regex: value,
173
169
  $options: "i",
174
170
  },
@@ -179,11 +175,11 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
179
175
  // converting db field to string first
180
176
  aggregateQuery.push({
181
177
  $addFields: (_k = {},
182
- _k["_".concat(key)] = { $toString: "$".concat(key) },
178
+ _k["_" + key] = { $toString: "$" + key },
183
179
  _k),
184
180
  });
185
181
  likeQuery_1.push((_l = {},
186
- _l["_".concat(key)] = {
182
+ _l["_" + key] = {
187
183
  $regex: value,
188
184
  $options: "i",
189
185
  },
@@ -218,7 +214,7 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
218
214
  if (field.type === "belongsTo") {
219
215
  aggregateQuery.push({
220
216
  $lookup: {
221
- from: "".concat(collectionName_1),
217
+ from: "" + collectionName_1,
222
218
  localField: field.fieldName,
223
219
  foreignField: "uuid",
224
220
  as: field.fieldName,
@@ -233,8 +229,8 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
233
229
  else {
234
230
  aggregateQuery.push({
235
231
  $lookup: {
236
- from: "".concat(collectionName_1),
237
- let: (_b = {}, _b["".concat(field.fieldName)] = "$".concat(field.fieldName), _b),
232
+ from: "" + collectionName_1,
233
+ let: (_b = {}, _b["" + field.fieldName] = "$" + field.fieldName, _b),
238
234
  pipeline: [
239
235
  {
240
236
  $match: {
@@ -244,10 +240,10 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
244
240
  {
245
241
  $cond: {
246
242
  if: {
247
- $in: ["$$".concat(field.fieldName), ["", null]],
243
+ $in: ["$$" + field.fieldName, ["", null]],
248
244
  },
249
245
  then: [],
250
- else: { $ifNull: ["$$".concat(field.fieldName), []] },
246
+ else: { $ifNull: ["$$" + field.fieldName, []] },
251
247
  },
252
248
  },
253
249
  ],
@@ -280,10 +276,10 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
280
276
  aggregateQuery.push({
281
277
  $lookup: {
282
278
  from: "user",
283
- let: (_c = {}, _c["".concat(field.fieldName)] = "$".concat(field.fieldName), _c),
279
+ let: (_c = {}, _c["" + field.fieldName] = "$" + field.fieldName, _c),
284
280
  pipeline: [
285
281
  {
286
- $match: { $expr: { $eq: ["$uuid", "$$".concat(field.fieldName)] } },
282
+ $match: { $expr: { $eq: ["$uuid", "$$" + field.fieldName] } },
287
283
  },
288
284
  { $project: { _id: 0, password: 0 } },
289
285
  ],
@@ -296,7 +292,7 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
296
292
  _b.label = 2;
297
293
  case 2:
298
294
  if (!["COUNT", "SUM", "AVG", "MIN", "MAX"].includes(finder) &&
299
- !(0, util_1.isEmpty)(projection)) {
295
+ !util_1.isEmpty(projection)) {
300
296
  aggregateQuery.push({ $project: projection });
301
297
  }
302
298
  if (finder === "COUNT") {
@@ -304,22 +300,22 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
304
300
  }
305
301
  else if (finder === "SUM") {
306
302
  aggregateQuery.push({
307
- $group: { _id: null, total: { $sum: "$".concat(aggregateFunctionField) } },
303
+ $group: { _id: null, total: { $sum: "$" + aggregateFunctionField } },
308
304
  });
309
305
  }
310
306
  else if (finder === "AVG") {
311
307
  aggregateQuery.push({
312
- $group: { _id: null, average: { $avg: "$".concat(aggregateFunctionField) } },
308
+ $group: { _id: null, average: { $avg: "$" + aggregateFunctionField } },
313
309
  });
314
310
  }
315
311
  else if (finder === "MIN") {
316
312
  aggregateQuery.push({
317
- $group: { _id: null, minimum: { $min: "$".concat(aggregateFunctionField) } },
313
+ $group: { _id: null, minimum: { $min: "$" + aggregateFunctionField } },
318
314
  });
319
315
  }
320
316
  else if (finder === "MAX") {
321
317
  aggregateQuery.push({
322
- $group: { _id: null, maximum: { $max: "$".concat(aggregateFunctionField) } },
318
+ $group: { _id: null, maximum: { $max: "$" + aggregateFunctionField } },
323
319
  });
324
320
  }
325
321
  offset = externalParams.offset || 0;
@@ -335,8 +331,8 @@ var queryParserNew = function (collectionName, query, constants, externalParams,
335
331
  if (finder != "COUNT" && limit) {
336
332
  aggregateQuery.push({ $skip: +offset }, { $limit: +limit });
337
333
  }
338
- queryStr = ".aggregate(".concat(JSON.stringify(aggregateQuery), ", { collation: { locale: \"en\" } })");
339
- str = "req.db.collection('".concat(collectionName, "')").concat(queryStr);
334
+ queryStr = ".aggregate(" + JSON.stringify(aggregateQuery) + ", { collation: { locale: \"en\" } })";
335
+ str = "req.db.collection('" + collectionName + "')" + queryStr;
340
336
  str += ".toArray()";
341
337
  return [2 /*return*/, str];
342
338
  }
@@ -373,7 +369,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
373
369
  filterQuery[lastKey].push(mongoQuery);
374
370
  }
375
371
  else {
376
- filterQuery["$or".concat(index)] = [mongoQuery];
372
+ filterQuery["$or" + index] = [mongoQuery];
377
373
  }
378
374
  }
379
375
  else if (queryObj.conjunctionType == "AND") {
@@ -382,11 +378,11 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
382
378
  filterQuery[lastKey].push(mongoQuery);
383
379
  }
384
380
  else {
385
- filterQuery["$and".concat(index)] = [mongoQuery];
381
+ filterQuery["$and" + index] = [mongoQuery];
386
382
  }
387
383
  }
388
384
  else {
389
- filterQuery["$or".concat(index)] = [mongoQuery];
385
+ filterQuery["$or" + index] = [mongoQuery];
390
386
  }
391
387
  });
392
388
  console.log("==> *** filterQuery #2 :>> ", filterQuery);
@@ -396,19 +392,21 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser)
396
392
  var mongoSelectQuery = function (query) {
397
393
  if (query === void 0) { query = {}; }
398
394
  var projection = {};
399
- var fieldsInclude = query.fieldsInclude, fieldsExclude = query.fieldsExclude;
395
+ var fieldsInclude = query.fieldsInclude, fieldsExclude = query.fieldsExclude, finder = query.finder;
400
396
  if (!fieldsExclude)
401
397
  fieldsExclude = [];
402
398
  if (fieldsInclude[0] === "*") {
403
399
  fieldsExclude.map(function (field) {
404
400
  if (field)
405
- return (projection["".concat(field)] = 0);
401
+ return (projection["" + field] = 0);
406
402
  });
407
403
  }
408
404
  else {
405
+ if (["FIND_ALL", "FIND"].includes(finder))
406
+ fieldsInclude = util_1.processFieldsInlcude(fieldsInclude);
409
407
  fieldsInclude.map(function (field) {
410
408
  if (field)
411
- return (projection["".concat(field)] = 1);
409
+ return (projection["" + field] = 1);
412
410
  });
413
411
  }
414
412
  return projection;
@@ -499,7 +497,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
499
497
  return _r = {},
500
498
  _r[field] = {
501
499
  $gte: fieldValue,
502
- $lt: new Date((0, date_util_1.nextDayDate)(fieldValue)),
500
+ $lt: new Date(date_util_1.nextDayDate(fieldValue)),
503
501
  },
504
502
  _r;
505
503
  }
@@ -577,11 +575,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
577
575
  if (key === drapcode_constant_1.BETWEEN) {
578
576
  var _a = getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
579
577
  if (requiredExternal) {
580
- startValue_1 = "".concat(externalParams[startValue_1]);
581
- endValue_1 = "".concat(externalParams[endValue_1]);
578
+ startValue_1 = "" + externalParams[startValue_1];
579
+ endValue_1 = "" + externalParams[endValue_1];
582
580
  }
583
581
  else {
584
- if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) {
582
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
585
583
  return startValue_1.includes(cnst);
586
584
  })) {
587
585
  startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
@@ -589,7 +587,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
589
587
  else {
590
588
  startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
591
589
  }
592
- if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) { return endValue_1.includes(cnst); })) {
590
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
593
591
  endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
594
592
  }
595
593
  else {
@@ -606,10 +604,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
606
604
  //TODO: Need to figure out the params should be treated as number/string
607
605
  if (!isNaN(startValue_1)) {
608
606
  console.log("I am Number");
609
- return "".concat(startValue_1, "---").concat(endValue_1, "^");
607
+ return startValue_1 + "---" + endValue_1 + "^";
610
608
  }
611
609
  else
612
- return "".concat(startValue_1, "---").concat(endValue_1);
610
+ return startValue_1 + "---" + endValue_1;
613
611
  }
614
612
  if (value.includes(drapcode_constant_1.CURRENT_USER)) {
615
613
  if (value === drapcode_constant_1.CURRENT_USER) {
@@ -647,11 +645,11 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
647
645
  //TODO: This is just to confirm if external then it should be get from externalParams
648
646
  if (requiredExternal) {
649
647
  //TODO: Value returns from here undefined.
650
- var externalParamValue = externalParams["".concat(value)];
648
+ var externalParamValue = externalParams["" + value];
651
649
  if (!isNaN(externalParamValue)) {
652
650
  return +externalParamValue;
653
651
  }
654
- return externalParams["".concat(value)];
652
+ return externalParams["" + value];
655
653
  }
656
654
  var constantArr = constants.filter(function (constant) { return constant.name == value; });
657
655
  return constantArr.length ? "" + constantArr[0].value : "";
@@ -678,9 +676,9 @@ var getValueOfProjectConstant = function (value, currentUser) {
678
676
  if (value === drapcode_constant_1.CURRENT_USER)
679
677
  return currentUser["uuid"];
680
678
  if (value === drapcode_constant_1.CURRENT_DATE)
681
- return (0, date_util_1.createLoggerDateFormat)();
679
+ return date_util_1.createLoggerDateFormat();
682
680
  if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
683
- return (0, date_util_1.createLogsDateFormat)();
681
+ return date_util_1.createLogsDateFormat();
684
682
  if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
685
- return (0, date_util_1.getDateValue)(value);
683
+ return date_util_1.getDateValue(value);
686
684
  };
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
25
25
  function verb(n) { return function (v) { return step([n, v]); }; }
26
26
  function step(op) {
27
27
  if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ while (_) try {
29
29
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
30
  if (y = 0, t) op = [op[0] & 2, t.value];
31
31
  switch (op[0]) {
@@ -75,9 +75,9 @@ exports.createS3Client = createS3Client;
75
75
  var fileUploadToS3 = function (files, s3Client, s3Config, encryption, options) {
76
76
  if (options === void 0) { options = {}; }
77
77
  return __awaiter(void 0, void 0, void 0, function () {
78
- var awsConfig, encryptionType, dataKey, accessKeyId, secretAccessKey, region, config, plainTextData, fileOptions, s3Key, _a, _b, _c, _i, index, file, fileObj, fileObj;
79
- return __generator(this, function (_d) {
80
- switch (_d.label) {
78
+ var awsConfig, encryptionType, dataKey, accessKeyId, secretAccessKey, region, config, plainTextData, fileOptions, s3Key, _a, _b, _i, index, file, fileObj, fileObj;
79
+ return __generator(this, function (_c) {
80
+ switch (_c.label) {
81
81
  case 0:
82
82
  if (!encryption) return [3 /*break*/, 2];
83
83
  awsConfig = encryption.awsConfig, encryptionType = encryption.encryptionType, dataKey = encryption.dataKey;
@@ -88,41 +88,38 @@ var fileUploadToS3 = function (files, s3Client, s3Config, encryption, options) {
88
88
  accessKeyId: accessKeyId,
89
89
  secretAccessKey: secretAccessKey,
90
90
  };
91
- return [4 /*yield*/, (0, encryption_2.processKMSDecryption)(config, dataKey, {})];
91
+ return [4 /*yield*/, encryption_2.processKMSDecryption(config, dataKey, {})];
92
92
  case 1:
93
- plainTextData = _d.sent();
93
+ plainTextData = _c.sent();
94
94
  if (plainTextData.status === "FAILED") {
95
95
  return [2 /*return*/, plainTextData];
96
96
  }
97
97
  encryption.dataKey = plainTextData.data;
98
- _d.label = 2;
98
+ _c.label = 2;
99
99
  case 2:
100
100
  if (!Array.isArray(files)) return [3 /*break*/, 7];
101
101
  console.log("I have multiple file");
102
102
  fileOptions = [];
103
103
  s3Key = s3Config.key;
104
- _a = files;
105
- _b = [];
106
- for (_c in _a)
107
- _b.push(_c);
104
+ _a = [];
105
+ for (_b in files)
106
+ _a.push(_b);
108
107
  _i = 0;
109
- _d.label = 3;
108
+ _c.label = 3;
110
109
  case 3:
111
- if (!(_i < _b.length)) return [3 /*break*/, 6];
112
- _c = _b[_i];
113
- if (!(_c in _a)) return [3 /*break*/, 5];
114
- index = _c;
110
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
111
+ index = _a[_i];
115
112
  file = files[index];
116
113
  if (s3Config.append) {
117
- s3Config.key = "".concat(s3Key, "/").concat(file.originalname);
114
+ s3Config.key = s3Key + "/" + file.originalname;
118
115
  }
119
116
  return [4 /*yield*/, processFileUploadToS3(file, s3Client, s3Config, encryption, options, encryption ? true : false)];
120
117
  case 4:
121
- fileObj = _d.sent();
118
+ fileObj = _c.sent();
122
119
  if (fileObj) {
123
120
  fileOptions.push(fileObj);
124
121
  }
125
- _d.label = 5;
122
+ _c.label = 5;
126
123
  case 5:
127
124
  _i++;
128
125
  return [3 /*break*/, 3];
@@ -130,11 +127,11 @@ var fileUploadToS3 = function (files, s3Client, s3Config, encryption, options) {
130
127
  case 7:
131
128
  console.log("I have single file");
132
129
  if (s3Config.append) {
133
- s3Config.key = "".concat(s3Config.key, "/").concat(files.originalname);
130
+ s3Config.key = s3Config.key + "/" + files.originalname;
134
131
  }
135
132
  return [4 /*yield*/, processFileUploadToS3(files, s3Client, s3Config, encryption, options, encryption ? true : false)];
136
133
  case 8:
137
- fileObj = _d.sent();
134
+ fileObj = _c.sent();
138
135
  return [2 /*return*/, fileObj];
139
136
  }
140
137
  });
@@ -154,7 +151,7 @@ var processFileUploadToS3 = function (file, s3Client, s3Config, encryption, opti
154
151
  acl = s3Config.acl, key = s3Config.key, bucket = s3Config.bucket;
155
152
  params = null;
156
153
  if (!encrypt) return [3 /*break*/, 2];
157
- return [4 /*yield*/, (0, encryption_1.cryptFile)(file.path, encryption, false)];
154
+ return [4 /*yield*/, encryption_1.cryptFile(file.path, encryption, false)];
158
155
  case 1:
159
156
  encryptedBody = _a.sent();
160
157
  params = __assign({ Bucket: bucket, ACL: acl, Key: key,
@@ -1,6 +1,6 @@
1
1
  export declare const validateString: (str: string) => false | "String should not contain special characters" | "String should not contain any number";
2
2
  export declare const camelize: (str: string) => string;
3
- export declare const clearSpaceAndReformat: (text: string, separator?: string) => string;
3
+ export declare const clearSpaceAndReformat: (text: string, separator?: string | undefined) => string;
4
4
  export declare const isEmpty: (obj: any) => boolean;
5
5
  export declare const isEmptyObject: (object: any) => boolean;
6
6
  export declare const isObject: (item: any) => any;
@@ -26,3 +26,4 @@ export declare const parseValueFromData: (data: any, fieldName: string) => any;
26
26
  export declare const unflattenObject: (obj: any) => {};
27
27
  export declare const replaceTransferObjectValueIntoExpression: (expression: string, transferObject: any) => string;
28
28
  export declare const removeMongoDbId: (result: any[]) => any[];
29
+ export declare const processFieldsInlcude: (fieldsInclude: any) => any;
@@ -21,11 +21,16 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  }
22
22
  return t;
23
23
  };
24
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
25
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
26
+ to[j] = from[i];
27
+ return to;
28
+ };
24
29
  var __importDefault = (this && this.__importDefault) || function (mod) {
25
30
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
31
  };
27
32
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.removeMongoDbId = exports.replaceTransferObjectValueIntoExpression = exports.unflattenObject = exports.parseValueFromData = exports.parseJsonString = exports.replaceDataValueIntoExpression = exports.formatCustomCSSClasses = exports.validateAlphanumericString = exports.convertItemToArray = exports.arraysEqual = exports.checkAndCompareValue = exports.restructureData = exports.formatCollectionAndFieldName = exports.cleanCollectionAndFieldName = exports.stringToExpression = exports.expressionToString = exports.getSpecialCharectorReplacedExpression = exports.validateUuidString = exports.validateEmail = exports.snakeCaseToTitleCase = exports.dynamicSort = exports.checkValidArray = exports.isObject = exports.isEmptyObject = exports.isEmpty = exports.clearSpaceAndReformat = exports.camelize = exports.validateString = void 0;
33
+ exports.processFieldsInlcude = exports.removeMongoDbId = exports.replaceTransferObjectValueIntoExpression = exports.unflattenObject = exports.parseValueFromData = exports.parseJsonString = exports.replaceDataValueIntoExpression = exports.formatCustomCSSClasses = exports.validateAlphanumericString = exports.convertItemToArray = exports.arraysEqual = exports.checkAndCompareValue = exports.restructureData = exports.formatCollectionAndFieldName = exports.cleanCollectionAndFieldName = exports.stringToExpression = exports.expressionToString = exports.getSpecialCharectorReplacedExpression = exports.validateUuidString = exports.validateEmail = exports.snakeCaseToTitleCase = exports.dynamicSort = exports.checkValidArray = exports.isObject = exports.isEmptyObject = exports.isEmpty = exports.clearSpaceAndReformat = exports.camelize = exports.validateString = void 0;
29
34
  var lodash_1 = __importDefault(require("lodash"));
30
35
  var validateString = function (str) {
31
36
  var specialChar = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
@@ -38,7 +43,7 @@ var validateString = function (str) {
38
43
  };
39
44
  exports.validateString = validateString;
40
45
  var camelize = function (str) {
41
- str = (0, exports.clearSpaceAndReformat)(str);
46
+ str = exports.clearSpaceAndReformat(str);
42
47
  return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
43
48
  return index === 0 ? word.toLowerCase() : word.toUpperCase();
44
49
  });
@@ -165,8 +170,8 @@ var cleanCollectionAndFieldName = function (str) {
165
170
  };
166
171
  exports.cleanCollectionAndFieldName = cleanCollectionAndFieldName;
167
172
  var formatCollectionAndFieldName = function (str) {
168
- var updateString = (0, exports.cleanCollectionAndFieldName)(str);
169
- return (0, exports.clearSpaceAndReformat)(updateString.trim(), "_");
173
+ var updateString = exports.cleanCollectionAndFieldName(str);
174
+ return exports.clearSpaceAndReformat(updateString.trim(), "_");
170
175
  };
171
176
  exports.formatCollectionAndFieldName = formatCollectionAndFieldName;
172
177
  var restructureData = function (data) {
@@ -197,7 +202,7 @@ var restructureData = function (data) {
197
202
  exports.restructureData = restructureData;
198
203
  var checkAndCompareValue = function (input1, input2) {
199
204
  return Array.isArray(input2)
200
- ? (0, exports.arraysEqual)(input1, input2.map(function (key) { return key.value; }))
205
+ ? exports.arraysEqual(input1, input2.map(function (key) { return key.value; }))
201
206
  : input1 === input2.value;
202
207
  };
203
208
  exports.checkAndCompareValue = checkAndCompareValue;
@@ -207,7 +212,7 @@ var arraysEqual = function (array1, array2) {
207
212
  return false;
208
213
  for (var i = 0; i < array1.length; i++ // assert each element equal
209
214
  )
210
- if (!(0, exports.arraysEqual)(array1[i], array2[i]))
215
+ if (!exports.arraysEqual(array1[i], array2[i]))
211
216
  return false;
212
217
  return true;
213
218
  }
@@ -242,7 +247,7 @@ var formatCustomCSSClasses = function (projectCustomCSSClasses) {
242
247
  .replace(/"([^"]+)"/g, "$1")
243
248
  .split(",")
244
249
  .join(";");
245
- projectCustomCSSClassesData += "".concat(element.class.startsWith(".") ? element.class : "." + element.class).concat(element.pseudoClass ? ":" + element.pseudoClass : "").concat(unquotedClassWithProp, " ");
250
+ projectCustomCSSClassesData += "" + (element.class.startsWith(".") ? element.class : "." + element.class) + (element.pseudoClass ? ":" + element.pseudoClass : "") + unquotedClassWithProp + " ";
246
251
  }
247
252
  });
248
253
  return projectCustomCSSClassesData;
@@ -253,18 +258,18 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
253
258
  var contentList = (_a = expression
254
259
  .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
255
260
  contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
256
- var needle = "{{".concat(prop, "}}");
261
+ var needle = "{{" + prop + "}}";
257
262
  var dataOfItem = "";
258
263
  if (prop.includes("current_user")) {
259
264
  prop = prop.replace("current_user.", "");
260
265
  if (Object.keys(user).length > 0) {
261
- dataOfItem = (0, exports.parseValueFromData)(user, prop);
266
+ dataOfItem = exports.parseValueFromData(user, prop);
262
267
  }
263
268
  }
264
269
  else if (prop.includes("current_tenant")) {
265
270
  prop = prop.replace("current_tenant.", "");
266
271
  if (Object.keys(tenant).length > 0) {
267
- dataOfItem = (0, exports.parseValueFromData)(tenant, prop);
272
+ dataOfItem = exports.parseValueFromData(tenant, prop);
268
273
  }
269
274
  }
270
275
  else if (prop.includes("current_session")) {
@@ -290,7 +295,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
290
295
  }
291
296
  else {
292
297
  if (Object.keys(data).length > 0) {
293
- dataOfItem = (0, exports.parseValueFromData)(data, prop);
298
+ dataOfItem = exports.parseValueFromData(data, prop);
294
299
  //TODO: Need better way
295
300
  delete data[prop];
296
301
  }
@@ -390,7 +395,7 @@ var replaceTransferObjectValueIntoExpression = function (expression, transferObj
390
395
  var contentList = (_a = expression
391
396
  .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
392
397
  contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
393
- var needle = "{{".concat(prop, "}}");
398
+ var needle = "{{" + prop + "}}";
394
399
  var dataOfItem = "";
395
400
  dataOfItem = transferObject[prop] ? transferObject[prop] : "";
396
401
  expression = dataOfItem
@@ -425,3 +430,82 @@ var removeMongoDbId = function (result) {
425
430
  return result.map(moveUuidToTopLevel);
426
431
  };
427
432
  exports.removeMongoDbId = removeMongoDbId;
433
+ // TODO: Refactor
434
+ var derivedFieldExcludes = [
435
+ "formatType",
436
+ "restToLower",
437
+ "whitespace",
438
+ "type",
439
+ "noSplitopt",
440
+ "length",
441
+ "endopt",
442
+ "startLength",
443
+ "endLength",
444
+ "startString",
445
+ "endString",
446
+ "separator",
447
+ "expression",
448
+ "unixType",
449
+ "currency",
450
+ "maxFraction",
451
+ "position",
452
+ "refField",
453
+ "condition",
454
+ "match",
455
+ "refFieldType",
456
+ "index",
457
+ "positionOfRecords",
458
+ "numberOfRecords",
459
+ "elementToRender",
460
+ "indexNum",
461
+ ];
462
+ var processFieldsInlcude = function (fieldsInclude) {
463
+ var result = fieldsInclude;
464
+ var refFieldsInclude = fieldsInclude.filter(function (field) {
465
+ return field.startsWith("RF::");
466
+ });
467
+ var derivedFieldsInclude = fieldsInclude.filter(function (field) {
468
+ return field.startsWith("DF::");
469
+ });
470
+ fieldsInclude = fieldsInclude.filter(function (field) { return !(field.startsWith("RF::") || field.startsWith("DF::")); });
471
+ var refFields = processReferenceFieldInclude(refFieldsInclude);
472
+ var derivedFields = processDerivedFieldInclude(derivedFieldsInclude);
473
+ var extraField = __spreadArray(__spreadArray([], refFields), derivedFields).filter(function (value, index, array) { return array.indexOf(value) === index; });
474
+ result = __spreadArray(__spreadArray([], fieldsInclude), extraField);
475
+ return result;
476
+ };
477
+ exports.processFieldsInlcude = processFieldsInlcude;
478
+ var processReferenceFieldInclude = function (refFieldsInclude) {
479
+ var refFields = [];
480
+ refFieldsInclude.forEach(function (exField) {
481
+ var field = exField.replace("RF::", "");
482
+ field = field.split(".")[0];
483
+ refFields.push(field);
484
+ });
485
+ return refFields;
486
+ };
487
+ var processDerivedFieldInclude = function (derivedFieldsInclude) {
488
+ var derivedFields = [];
489
+ derivedFieldsInclude.forEach(function (exField) {
490
+ var derivedFieldStr = exField.replace("DF::", "");
491
+ derivedFieldStr = derivedFieldStr.replaceAll("*#*#", '"');
492
+ var derivedFieldObj = JSON.parse(derivedFieldStr);
493
+ var fields = [];
494
+ derivedFieldObj.args.forEach(function (arg) {
495
+ var _a;
496
+ if (arg.name === "expression") {
497
+ var needleList = (_a = arg.key
498
+ .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
499
+ var tempFields = exports.processFieldsInlcude(needleList);
500
+ fields = __spreadArray(__spreadArray([], fields), tempFields);
501
+ }
502
+ else if (!derivedFieldExcludes.includes(arg.name)) {
503
+ var tempFields = Array.isArray(arg.key) ? arg.key : [arg.key];
504
+ tempFields = exports.processFieldsInlcude(tempFields);
505
+ fields = __spreadArray(__spreadArray([], fields), tempFields);
506
+ }
507
+ });
508
+ derivedFields = __spreadArray(__spreadArray([], derivedFields), fields);
509
+ });
510
+ return derivedFields;
511
+ };
@@ -38,10 +38,10 @@ var nextGeneratedString = function (str, prepend, minLength, append, algorithm)
38
38
  finalValue = voca_1.default.padLeft(finalValue, minLength, "0");
39
39
  }
40
40
  if (prepend) {
41
- finalValue = "".concat(prepend).concat(finalValue);
41
+ finalValue = "" + prepend + finalValue;
42
42
  }
43
43
  if (append) {
44
- finalValue = "".concat(finalValue).concat(append);
44
+ finalValue = "" + finalValue + append;
45
45
  }
46
46
  return finalValue;
47
47
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",