drapcode-utility 1.2.2-beta → 1.2.3

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