drapcode-utility 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,23 +83,25 @@ var crypt = function (data, fields, encryption, decrypt) { return __awaiter(void
83
83
  exports.crypt = crypt;
84
84
  var cryptItem = function (item, fields, encryption, decrypt) { return __awaiter(void 0, void 0, void 0, function () {
85
85
  return __generator(this, function (_a) {
86
- Object.keys(item).forEach(function (fieldName) { return __awaiter(void 0, void 0, void 0, function () {
87
- var field, _a, _b;
88
- return __generator(this, function (_c) {
89
- switch (_c.label) {
90
- case 0:
91
- field = fields.find(function (field) { return field.fieldName === fieldName; });
92
- if (!(field && field.encrypted)) return [3 /*break*/, 2];
93
- _a = item;
94
- _b = fieldName;
95
- return [4 /*yield*/, cryptData(item[fieldName], encryption, decrypt)];
96
- case 1:
97
- _a[_b] = _c.sent();
98
- _c.label = 2;
99
- case 2: return [2 /*return*/];
100
- }
101
- });
102
- }); });
86
+ if (item && typeof item === "object") {
87
+ Object.keys(item).forEach(function (fieldName) { return __awaiter(void 0, void 0, void 0, function () {
88
+ var field, _a, _b;
89
+ return __generator(this, function (_c) {
90
+ switch (_c.label) {
91
+ case 0:
92
+ field = fields.find(function (field) { return field.fieldName === fieldName; });
93
+ if (!(field && field.encrypted)) return [3 /*break*/, 2];
94
+ _a = item;
95
+ _b = fieldName;
96
+ return [4 /*yield*/, cryptData(item[fieldName], encryption, decrypt)];
97
+ case 1:
98
+ _a[_b] = _c.sent();
99
+ _c.label = 2;
100
+ case 2: return [2 /*return*/];
101
+ }
102
+ });
103
+ }); });
104
+ }
103
105
  return [2 /*return*/, item];
104
106
  });
105
107
  }); };
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -7,6 +7,8 @@ var __extends = (this && this.__extends) || (function () {
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -35,12 +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 __spreadArrays = (this && this.__spreadArrays) || function () {
39
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
40
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
41
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
42
- r[k] = a[j];
43
- return r;
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;
44
42
  };
45
43
  var __importDefault = (this && this.__importDefault) || function (mod) {
46
44
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -183,7 +181,7 @@ var nestedValue = function (data, messages) {
183
181
  messages.push(value);
184
182
  }
185
183
  else if (Array.isArray(value)) {
186
- messages = __spreadArrays(messages, value);
184
+ messages = __spreadArray(__spreadArray([], messages), value);
187
185
  }
188
186
  else {
189
187
  if (Object.keys(value).length) {
@@ -87,22 +87,24 @@ var timezoneDateParse = function (value, nextDay, prevDay) {
87
87
  };
88
88
  exports.timezoneDateParse = timezoneDateParse;
89
89
  var formatItemDates = function (item, fields, dateFormat, reverse) {
90
- var dateFormat1 = reverse ? dateFormat : "YYYY-MM-DD";
91
- var dateFormat2 = reverse ? "YYYY-MM-DD" : dateFormat;
92
- Object.keys(item).forEach(function (fieldName) {
93
- var _a;
94
- var field = fields.find(function (field) { return field.fieldName === fieldName; });
95
- if (field && (field === null || field === void 0 ? void 0 : field.type) === "date") {
96
- if (moment(item[fieldName]).isValid()) {
97
- item[fieldName] =
98
- ((_a = field === null || field === void 0 ? void 0 : field.extraFieldSetting) === null || _a === void 0 ? void 0 : _a.dateDisplayType) === "datetime-local"
99
- ? item[fieldName]
100
- : moment(item[fieldName], dateFormat1).format(dateFormat2);
90
+ if (item && typeof item === "object") {
91
+ var dateFormat1_1 = reverse ? dateFormat : "YYYY-MM-DD";
92
+ var dateFormat2_1 = reverse ? "YYYY-MM-DD" : dateFormat;
93
+ Object.keys(item).forEach(function (fieldName) {
94
+ var _a;
95
+ var field = fields.find(function (field) { return field.fieldName === fieldName; });
96
+ if (field && (field === null || field === void 0 ? void 0 : field.type) === "date") {
97
+ if (moment(item[fieldName]).isValid()) {
98
+ item[fieldName] =
99
+ ((_a = field === null || field === void 0 ? void 0 : field.extraFieldSetting) === null || _a === void 0 ? void 0 : _a.dateDisplayType) === "datetime-local"
100
+ ? item[fieldName]
101
+ : moment(item[fieldName], dateFormat1_1).format(dateFormat2_1);
102
+ }
103
+ else
104
+ item[fieldName] = "";
101
105
  }
102
- else
103
- item[fieldName] = "";
104
- }
105
- });
106
+ });
107
+ }
106
108
  return item;
107
109
  };
108
110
  var formatProjectDates = function (item, dateFormat, fields, reverse) {
@@ -35,12 +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 __spreadArrays = (this && this.__spreadArrays) || function () {
39
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
40
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
41
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
42
- r[k] = a[j];
43
- return r;
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;
44
42
  };
45
43
  var __importDefault = (this && this.__importDefault) || function (mod) {
46
44
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -87,7 +85,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
87
85
  searchQueryObj = null;
88
86
  if (searchObj) {
89
87
  _a = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _a.searchAggregateQuery, likeQuery = _a.likeQuery;
90
- aggregateQuery = __spreadArrays(aggregateQuery, searchAggregateQuery);
88
+ aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
91
89
  console.log("likeQuery after getSearchObjQuery", JSON.stringify(likeQuery));
92
90
  if (likeQuery && likeQuery.length > 0) {
93
91
  searchQueryObj = likeQuery;
@@ -105,7 +103,7 @@ var queryParser = function (collectionName, query, constants, externalParams, cu
105
103
  else if (searchObj) {
106
104
  console.log("I donot have filter query");
107
105
  _b = getSearchObjQuery(searchObj, searchQueryTypeObj, timezone), searchAggregateQuery = _b.searchAggregateQuery, likeQuery = _b.likeQuery;
108
- aggregateQuery = __spreadArrays(aggregateQuery, searchAggregateQuery);
106
+ aggregateQuery = __spreadArray(__spreadArray([], aggregateQuery), searchAggregateQuery);
109
107
  if (likeQuery.length) {
110
108
  // aggregateQuery.push({ $match: { $or: likeQuery } });
111
109
  aggregateQuery.push({ $match: { $and: likeQuery } });
@@ -510,7 +508,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
510
508
  endValue_1 = "" + externalParams[endValue_1];
511
509
  }
512
510
  else {
513
- if (__spreadArrays([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
511
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
514
512
  return startValue_1.includes(cnst);
515
513
  })) {
516
514
  startValue_1 = getValueOfProjectConstant(startValue_1, currentUser, timezone);
@@ -518,7 +516,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
518
516
  else {
519
517
  startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
520
518
  }
521
- if (__spreadArrays([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
519
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
522
520
  endValue_1 = getValueOfProjectConstant(endValue_1, currentUser, timezone);
523
521
  }
524
522
  else {
@@ -35,12 +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 __spreadArrays = (this && this.__spreadArrays) || function () {
39
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
40
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
41
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
42
- r[k] = a[j];
43
- return r;
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;
44
42
  };
45
43
  Object.defineProperty(exports, "__esModule", { value: true });
46
44
  exports.queryParserNew = void 0;
@@ -569,7 +567,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
569
567
  endValue_1 = "" + externalParams[endValue_1];
570
568
  }
571
569
  else {
572
- if (__spreadArrays([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
570
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) {
573
571
  return startValue_1.includes(cnst);
574
572
  })) {
575
573
  startValue_1 = getValueOfProjectConstant(startValue_1, currentUser);
@@ -577,7 +575,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
577
575
  else {
578
576
  startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
579
577
  }
580
- if (__spreadArrays([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
578
+ if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant).some(function (cnst) { return endValue_1.includes(cnst); })) {
581
579
  endValue_1 = getValueOfProjectConstant(endValue_1, currentUser);
582
580
  }
583
581
  else {
@@ -25,3 +25,4 @@ export declare const parseJsonString: (str: string) => any;
25
25
  export declare const parseValueFromData: (data: any, fieldName: string) => any;
26
26
  export declare const unflattenObject: (obj: any) => {};
27
27
  export declare const replaceTransferObjectValueIntoExpression: (expression: string, transferObject: any) => string;
28
+ export declare const removeMongoDbId: (result: any[]) => any[];
@@ -1,9 +1,31 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
2
24
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
26
  };
5
27
  Object.defineProperty(exports, "__esModule", { value: true });
6
- 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;
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;
7
29
  var lodash_1 = __importDefault(require("lodash"));
8
30
  var validateString = function (str) {
9
31
  var specialChar = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
@@ -373,3 +395,27 @@ var replaceTransferObjectValueIntoExpression = function (expression, transferObj
373
395
  return expression;
374
396
  };
375
397
  exports.replaceTransferObjectValueIntoExpression = replaceTransferObjectValueIntoExpression;
398
+ var removeMongoDbId = function (result) {
399
+ var removeIdRecursively = function (obj) {
400
+ if (Array.isArray(obj)) {
401
+ return obj.map(removeIdRecursively);
402
+ }
403
+ if (typeof obj === "object" && obj !== null) {
404
+ for (var key in obj) {
405
+ if (key === "_id") {
406
+ delete obj[key];
407
+ }
408
+ else {
409
+ obj[key] = removeIdRecursively(obj[key]);
410
+ }
411
+ }
412
+ }
413
+ return obj;
414
+ };
415
+ var moveUuidToTopLevel = function (obj) {
416
+ var uuid = obj.uuid, rest = __rest(obj, ["uuid"]);
417
+ return __assign({ uuid: uuid }, removeIdRecursively(rest));
418
+ };
419
+ return result.map(moveUuidToTopLevel);
420
+ };
421
+ exports.removeMongoDbId = removeMongoDbId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  "@types/voca": "^1.4.2",
32
32
  "aws-sdk": "^2.1324.0",
33
33
  "axios": "^1.1.2",
34
- "drapcode-constant": "^1.1.2",
34
+ "drapcode-constant": "^1.1.3",
35
35
  "drapcode-logger": "^1.0.0",
36
36
  "drapcode-redis": "^1.0.0",
37
37
  "express": "^4.17.1",