drapcode-utility 1.2.1 → 1.2.2-beta

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
  var __importDefault = (this && this.__importDefault) || function (mod) {
48
44
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -89,7 +85,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
89
85
  searchQueryObj = null;
90
86
  if (searchObj) {
91
87
  _a = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _a.searchAggregateQuery, likeQuery = _a.likeQuery;
92
- aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery, true), searchAggregateQuery, true);
88
+ aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
93
89
  console.log("likeQuery after getSearchObjQuery", JSON.stringify(likeQuery));
94
90
  if (likeQuery && likeQuery.length > 0) {
95
91
  searchQueryObj = likeQuery;
@@ -107,7 +103,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
107
103
  else if (searchObj) {
108
104
  console.log("I donot have filter query");
109
105
  _b = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _b.searchAggregateQuery, likeQuery = _b.likeQuery;
110
- aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery, true), searchAggregateQuery, true);
106
+ aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
111
107
  if (likeQuery.length) {
112
108
  // aggregateQuery.push({ $match: { $or: likeQuery } });
113
109
  aggregateQuery.push({ $match: { $and: likeQuery } });
@@ -119,21 +115,21 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
119
115
  finder = query.finder, sortBy = query.sortBy, orderBy = query.orderBy;
120
116
  if (!(finder != "COUNT" && refCollectionFieldsInItems)) return [3 /*break*/, 2];
121
117
  return [4 /*yield*/, Promise.all(refCollectionFieldsInItems.map(function (field) {
122
- var _a, _b, _c;
118
+ var _a;
123
119
  if (["reference", "multi_reference", "belongsTo"].includes(field.type)) {
124
120
  var collectionName_1 = field.refCollection
125
121
  ? field.refCollection["collectionName"]
126
122
  : null;
127
123
  if (collectionName_1) {
128
124
  if (field.type === "belongsTo") {
129
- aggregateQuery.push({
130
- $lookup: {
131
- from: "".concat(collectionName_1),
132
- localField: field.fieldName,
133
- foreignField: "uuid",
134
- as: field.fieldName,
135
- },
136
- });
125
+ // aggregateQuery.push({
126
+ // $lookup: {
127
+ // from: `${collectionName}`,
128
+ // localField: field.fieldName,
129
+ // foreignField: "uuid",
130
+ // as: field.fieldName,
131
+ // },
132
+ // });
137
133
  aggregateQuery.push({
138
134
  $addFields: (_a = {},
139
135
  _a["_$belongsToMetaData"] = field,
@@ -141,71 +137,72 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
141
137
  });
142
138
  }
143
139
  else {
144
- aggregateQuery.push({
145
- $lookup: {
146
- from: "".concat(collectionName_1),
147
- let: (_b = {}, _b["".concat(field.fieldName)] = "$".concat(field.fieldName), _b),
148
- pipeline: [
149
- {
150
- $match: {
151
- $expr: {
152
- $in: [
153
- "$uuid",
154
- {
155
- $cond: {
156
- if: {
157
- $in: ["$$".concat(field.fieldName), ["", null]],
158
- },
159
- then: [],
160
- else: { $ifNull: ["$$".concat(field.fieldName), []] },
161
- },
162
- },
163
- ],
164
- },
165
- },
166
- },
167
- {
168
- $lookup: {
169
- from: "user",
170
- let: { createdBy: "$createdBy" },
171
- pipeline: [
172
- {
173
- $match: {
174
- $expr: { $eq: ["$uuid", "$$createdBy"] },
175
- },
176
- },
177
- { $project: { _id: 0, password: 0 } },
178
- ],
179
- as: "createdBy",
180
- },
181
- },
182
- ],
183
- as: field.fieldName,
184
- },
185
- });
140
+ // aggregateQuery.push({
141
+ // $lookup: {
142
+ // from: `${collectionName}`,
143
+ // let: { [`${field.fieldName}`]: `$${field.fieldName}` },
144
+ // pipeline: [
145
+ // {
146
+ // $match: {
147
+ // $expr: {
148
+ // $in: [
149
+ // "$uuid",
150
+ // {
151
+ // $cond: {
152
+ // if: {
153
+ // $in: [`$$${field.fieldName}`, ["", null]],
154
+ // },
155
+ // then: [],
156
+ // else: { $ifNull: [`$$${field.fieldName}`, []] },
157
+ // },
158
+ // },
159
+ // ],
160
+ // },
161
+ // },
162
+ // },
163
+ // {
164
+ // $lookup: {
165
+ // from: "user",
166
+ // let: { createdBy: "$createdBy" },
167
+ // pipeline: [
168
+ // {
169
+ // $match: {
170
+ // $expr: { $eq: ["$uuid", "$$createdBy"] },
171
+ // },
172
+ // },
173
+ // { $project: { _id: 0, password: 0 } },
174
+ // ],
175
+ // as: "createdBy",
176
+ // },
177
+ // },
178
+ // ],
179
+ // as: field.fieldName,
180
+ // },
181
+ // });
186
182
  }
187
183
  }
188
184
  }
189
- if (field.type === "createdBy")
190
- aggregateQuery.push({
191
- $lookup: {
192
- from: "user",
193
- let: (_c = {}, _c["".concat(field.fieldName)] = "$".concat(field.fieldName), _c),
194
- pipeline: [
195
- {
196
- $match: { $expr: { $eq: ["$uuid", "$$".concat(field.fieldName)] } },
197
- },
198
- { $project: { _id: 0, password: 0 } },
199
- ],
200
- as: field.fieldName,
201
- },
202
- });
185
+ if (field.type === "createdBy") {
186
+ }
187
+ // aggregateQuery.push({
188
+ // $lookup: {
189
+ // from: `user`,
190
+ // let: { [`${field.fieldName}`]: `$${field.fieldName}` },
191
+ // pipeline: [
192
+ // {
193
+ // $match: { $expr: { $eq: ["$uuid", `$$${field.fieldName}`] } },
194
+ // },
195
+ // { $project: { _id: 0, password: 0 } },
196
+ // ],
197
+ // as: field.fieldName,
198
+ // },
199
+ // });
203
200
  }))];
204
201
  case 1:
205
202
  _e.sent();
206
203
  _e.label = 2;
207
204
  case 2:
208
- if (finder != "COUNT" && !(0, util_1.isEmpty)(projection)) {
205
+ if (finder != "COUNT" && !util_1.isEmpty(projection)) {
209
206
  aggregateQuery.push({ $project: projection });
210
207
  }
211
208
  if (finder === "COUNT") {
@@ -226,8 +223,8 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
226
223
  }
227
224
  console.log("==> aggregateQuery", aggregateQuery);
228
225
  console.log("==> aggregateQuery", JSON.stringify(aggregateQuery));
229
- queryStr = ".aggregate(".concat(JSON.stringify(aggregateQuery), ", { collation: { locale: \"en\" } })");
230
- str = "req.db.collection('".concat(collectionName, "')").concat(queryStr);
226
+ queryStr = ".aggregate(" + JSON.stringify(aggregateQuery) + ", { collation: { locale: \"en\" } })";
227
+ str = "req.db.collection('" + collectionName + "')" + queryStr;
231
228
  str += ".toArray()";
232
229
  return [2 /*return*/, str];
233
230
  }
@@ -267,7 +264,7 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser,
267
264
  filterQuery[lastKey].push(mongoQuery);
268
265
  }
269
266
  else {
270
- filterQuery["$or".concat(index)] = [mongoQuery];
267
+ filterQuery["$or" + index] = [mongoQuery];
271
268
  }
272
269
  }
273
270
  else if (queryObj.conjunctionType == "AND") {
@@ -276,11 +273,11 @@ var mongoFilterQuery = function (query, externalParams, constants, currentUser,
276
273
  filterQuery[lastKey].push(mongoQuery);
277
274
  }
278
275
  else {
279
- filterQuery["$and".concat(index)] = [mongoQuery];
276
+ filterQuery["$and" + index] = [mongoQuery];
280
277
  }
281
278
  }
282
279
  else {
283
- filterQuery["$or".concat(index)] = [mongoQuery];
280
+ filterQuery["$or" + index] = [mongoQuery];
284
281
  }
285
282
  });
286
283
  console.log("==> *** filterQuery mongoFilterQuery :>> ", filterQuery);
@@ -299,13 +296,13 @@ var mongoSelectQuery = function (query) {
299
296
  if (fieldsInclude[0] === "*") {
300
297
  fieldsExclude.map(function (field) {
301
298
  if (field)
302
- return (projection["".concat(field)] = 0);
299
+ return (projection["" + field] = 0);
303
300
  });
304
301
  }
305
302
  else {
306
303
  fieldsInclude.map(function (field) {
307
304
  if (field)
308
- return (projection["".concat(field)] = 1);
305
+ return (projection["" + field] = 1);
309
306
  });
310
307
  }
311
308
  return projection;
@@ -337,7 +334,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
337
334
  //TODO: In case of this, we assign some random string to avoid resulting all values
338
335
  //TODO: This is use case in Spot Factor Project, where a new user with blank value able to see all records
339
336
  //TODO: Discussed on meet
340
- fieldValue = "random_string_since_field_not_present_".concat((0, moment_1.default)(1318874398806).valueOf());
337
+ fieldValue = "random_string_since_field_not_present_" + moment_1.default(1318874398806).valueOf();
341
338
  }
342
339
  console.log("fieldValue queryToMongo 1", fieldValue);
343
340
  var isDate = checkDate(fieldValue);
@@ -405,7 +402,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
405
402
  return _q = {},
406
403
  _q[field] = {
407
404
  $gte: fieldValue,
408
- $lt: (0, date_util_1.nextDayDate)(fieldValue),
405
+ $lt: date_util_1.nextDayDate(fieldValue),
409
406
  },
410
407
  _q;
411
408
  // Todo: Remove this if works properly
@@ -445,11 +442,12 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
445
442
  };
446
443
  if (key == drapcode_constant_1.EQUALS) {
447
444
  return _x = {},
445
+ // TODO:Handle Based of Field Type
448
446
  _x[field] = fieldType === "boolean" && fieldValue
449
447
  ? JSON.parse(fieldValue)
450
- : !isNaN(fieldValue)
451
- ? +fieldValue
452
- : fieldValue,
448
+ : // : !isNaN(fieldValue)
449
+ // ? +fieldValue
450
+ fieldValue,
453
451
  _x;
454
452
  }
455
453
  if (key == drapcode_constant_1.NOT_EQUAL)
@@ -461,7 +459,7 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
461
459
  },
462
460
  _y;
463
461
  if (key == drapcode_constant_1.BETWEEN) {
464
- var _0 = (0, exports.getMinMaxValue)(fieldValue), startValue = _0.startValue, endValue = _0.endValue, isInteger = _0.isInteger;
462
+ var _0 = exports.getMinMaxValue(fieldValue), startValue = _0.startValue, endValue = _0.endValue, isInteger = _0.isInteger;
465
463
  return _z = {},
466
464
  _z[field] = {
467
465
  $gte: isInteger ? +startValue : startValue,
@@ -511,13 +509,13 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
511
509
  return valueList_1;
512
510
  }
513
511
  if (key === drapcode_constant_1.BETWEEN) {
514
- var _a = (0, exports.getMinMaxValue)(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
512
+ var _a = exports.getMinMaxValue(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
515
513
  if (requiredExternal) {
516
- startValue_1 = "".concat(externalParams[startValue_1]);
517
- endValue_1 = "".concat(externalParams[endValue_1]);
514
+ startValue_1 = "" + externalParams[startValue_1];
515
+ endValue_1 = "" + externalParams[endValue_1];
518
516
  }
519
517
  else {
520
- if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) {
518
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
521
519
  return startValue_1.includes(cnst);
522
520
  })) {
523
521
  startValue_1 = getValueOfProjectConstant(startValue_1, currentUser, timezone);
@@ -525,7 +523,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
525
523
  else {
526
524
  startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
527
525
  }
528
- if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) { return endValue_1.includes(cnst); })) {
526
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
529
527
  endValue_1 = getValueOfProjectConstant(endValue_1, currentUser, timezone);
530
528
  }
531
529
  else {
@@ -541,10 +539,10 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
541
539
  }
542
540
  //TODO: Need to figure out the params should be treated as number/string
543
541
  if (!isNaN(startValue_1)) {
544
- return "".concat(startValue_1, "---").concat(endValue_1, "^");
542
+ return startValue_1 + "---" + endValue_1 + "^";
545
543
  }
546
544
  else
547
- return "".concat(startValue_1, "---").concat(endValue_1);
545
+ return startValue_1 + "---" + endValue_1;
548
546
  }
549
547
  console.log("==> value", value);
550
548
  console.log("==> currentUser", currentUser);
@@ -640,18 +638,19 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
640
638
  if (drapcode_constant_1.DateConstant.some(function (cnst) { return value.includes(cnst); })) {
641
639
  return getValueOfProjectConstant(value, {}, timezone);
642
640
  }
643
- if ((0, exports.isEntityInCondition)(value)) {
641
+ if (exports.isEntityInCondition(value)) {
644
642
  var key_1 = value.replace("ENTITY::", "");
645
643
  return externalParams[key_1] ? externalParams[key_1] : "";
646
644
  }
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)];
651
- if (!isNaN(externalParamValue)) {
652
- return +externalParamValue;
653
- }
654
- return externalParams["".concat(value)];
648
+ var externalParamValue = externalParams["" + value];
649
+ // TODO:Handle Based of Field Type
650
+ // if (!isNaN(externalParamValue)) {
651
+ // return +externalParamValue;
652
+ // }
653
+ return externalParams["" + value];
655
654
  }
656
655
  var constantArr = constants.filter(function (constant) { return constant.name == value; });
657
656
  return constantArr.length ? "" + constantArr[0].value : "";
@@ -682,11 +681,11 @@ var getValueOfProjectConstant = function (value, currentUser, timezone) {
682
681
  if (value === drapcode_constant_1.CURRENT_USER)
683
682
  return currentUser["uuid"];
684
683
  if (value === drapcode_constant_1.CURRENT_DATE)
685
- result = (0, date_util_1.createLoggerDateFormat)(timezone);
684
+ result = date_util_1.createLoggerDateFormat(timezone);
686
685
  if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
687
- result = (0, date_util_1.createLogsDateFormat)(timezone);
686
+ result = date_util_1.createLogsDateFormat(timezone);
688
687
  if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
689
- result = (0, date_util_1.getDateValue)(value, timezone);
688
+ result = date_util_1.getDateValue(value, timezone);
690
689
  return result;
691
690
  };
692
691
  var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
@@ -702,11 +701,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
702
701
  // if input is string and db field type is boolean
703
702
  searchAggregateQuery.push({
704
703
  $addFields: (_b = {},
705
- _b["_".concat(key)] = "$".concat(key),
704
+ _b["_" + key] = "$" + key,
706
705
  _b),
707
706
  });
708
707
  likeQuery.push((_c = {},
709
- _c["_".concat(key)] = toBoolean(value),
708
+ _c["_" + key] = toBoolean(value),
710
709
  _c));
711
710
  }
712
711
  else if ([
@@ -718,22 +717,22 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
718
717
  // if input is string and db field type is array
719
718
  searchAggregateQuery.push({
720
719
  $addFields: (_d = {},
721
- _d["_".concat(key)] = "$".concat(key),
720
+ _d["_" + key] = "$" + key,
722
721
  _d),
723
722
  });
724
723
  likeQuery.push((_e = {},
725
- _e["_".concat(key)] = { $all: [value] },
724
+ _e["_" + key] = { $all: [value] },
726
725
  _e));
727
726
  }
728
727
  else if (searchQueryTypeKey === "tel") {
729
728
  // handling value when db field type is tel
730
729
  searchAggregateQuery.push({
731
730
  $addFields: (_f = {},
732
- _f["_".concat(key)] = { $toString: "$".concat(key) },
731
+ _f["_" + key] = { $toString: "$" + key },
733
732
  _f),
734
733
  });
735
734
  likeQuery.push((_g = {},
736
- _g["_".concat(key)] = {
735
+ _g["_" + key] = {
737
736
  $regex: value.startsWith("+") ? value.replace("+", "") : value,
738
737
  $options: "i",
739
738
  },
@@ -743,11 +742,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
743
742
  // handling value when db field type is Double/Int
744
743
  searchAggregateQuery.push({
745
744
  $addFields: (_h = {},
746
- _h["_".concat(key)] = { $toString: { $toLong: "$".concat(key) } },
745
+ _h["_" + key] = { $toString: { $toLong: "$" + key } },
747
746
  _h),
748
747
  });
749
748
  likeQuery.push((_j = {},
750
- _j["_".concat(key)] = {
749
+ _j["_" + key] = {
751
750
  $regex: value,
752
751
  $options: "i",
753
752
  },
@@ -759,20 +758,20 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
759
758
  fieldKey = fieldKey.replace("end_", "");
760
759
  searchAggregateQuery.push({
761
760
  $addFields: (_k = {},
762
- _k["_".concat(key)] = { $toString: "$".concat(fieldKey) },
761
+ _k["_" + key] = { $toString: "$" + fieldKey },
763
762
  _k),
764
763
  });
765
764
  if (key.startsWith("start_")) {
766
765
  likeQuery.push((_l = {},
767
- _l["_".concat(key)] = {
768
- $gte: (0, date_util_1.timezoneDateParse)(value, false, true),
766
+ _l["_" + key] = {
767
+ $gte: date_util_1.timezoneDateParse(value, false, true),
769
768
  },
770
769
  _l));
771
770
  }
772
771
  else if (key.startsWith("end_")) {
773
772
  likeQuery.push((_m = {},
774
- _m["_".concat(key)] = {
775
- $lt: (0, date_util_1.timezoneDateParse)(value, true),
773
+ _m["_" + key] = {
774
+ $lt: date_util_1.timezoneDateParse(value, true),
776
775
  },
777
776
  _m));
778
777
  }
@@ -783,11 +782,11 @@ var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
783
782
  // converting db field to string first
784
783
  searchAggregateQuery.push({
785
784
  $addFields: (_o = {},
786
- _o["_".concat(key)] = { $toString: "$".concat(key) },
785
+ _o["_" + key] = { $toString: "$" + key },
787
786
  _o),
788
787
  });
789
788
  likeQuery.push((_p = {},
790
- _p["_".concat(key)] = {
789
+ _p["_" + key] = {
791
790
  $regex: value,
792
791
  $options: "i",
793
792
  },