drapcode-utility 2.0.0 → 2.0.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.
Files changed (50) hide show
  1. package/build/encryption/KMS.js +54 -102
  2. package/build/encryption/crypt.d.ts +4 -2
  3. package/build/encryption/crypt.js +76 -91
  4. package/build/encryption/file.d.ts +0 -2
  5. package/build/encryption/file.js +14 -130
  6. package/build/encryption/index.js +162 -334
  7. package/build/encryption/utility.js +7 -10
  8. package/build/errors/app-error.js +9 -27
  9. package/build/errors/axios-error.js +3 -3
  10. package/build/errors/bad-request-error.js +10 -28
  11. package/build/errors/custom-error.js +5 -23
  12. package/build/errors/not-found.js +9 -27
  13. package/build/format-fields/index.d.ts +0 -1
  14. package/build/format-fields/index.js +32 -65
  15. package/build/index.d.ts +1 -4
  16. package/build/index.js +1 -4
  17. package/build/middlewares/error-logger.d.ts +1 -1
  18. package/build/middlewares/error-logger.js +29 -29
  19. package/build/middlewares/redis/request-log.js +24 -74
  20. package/build/query/queryBuilder.d.ts +9 -0
  21. package/build/query/queryBuilder.js +567 -0
  22. package/build/utils/check-error.d.ts +15 -8
  23. package/build/utils/check-error.js +71 -160
  24. package/build/utils/common-util.d.ts +40 -39
  25. package/build/utils/common-util.js +60 -59
  26. package/build/utils/date-util.d.ts +28 -7
  27. package/build/utils/date-util.js +180 -127
  28. package/build/utils/file-util.d.ts +51 -6
  29. package/build/utils/file-util.js +36 -40
  30. package/build/utils/prepare-query.js +70 -43
  31. package/build/utils/project-util.d.ts +43 -5
  32. package/build/utils/project-util.js +176 -121
  33. package/build/utils/query-parser.d.ts +1 -1
  34. package/build/utils/query-parser.js +289 -342
  35. package/build/utils/query-utils.d.ts +2 -2
  36. package/build/utils/query-utils.js +103 -116
  37. package/build/utils/rest-client.js +236 -328
  38. package/build/utils/s3-util.js +238 -469
  39. package/build/utils/token.js +34 -81
  40. package/build/utils/util.d.ts +58 -13
  41. package/build/utils/util.js +424 -494
  42. package/build/utils/uuid-generator.d.ts +20 -1
  43. package/build/utils/uuid-generator.js +111 -47
  44. package/package.json +7 -5
  45. package/build/middlewares/interceptor-logger-new.d.ts +0 -2
  46. package/build/middlewares/interceptor-logger-new.js +0 -53
  47. package/build/middlewares/interceptor-logger.d.ts +0 -2
  48. package/build/middlewares/interceptor-logger.js +0 -52
  49. package/build/utils/query-parser-new.d.ts +0 -1
  50. package/build/utils/query-parser-new.js +0 -541
@@ -1,10 +1,10 @@
1
- export declare const getSearchObjQuery: (searchObj: any, searchQueryTypeObj: any, timezone: string) => {
1
+ export declare const getSearchObjQuery: (searchObj: any, searchQueryTypeObj: any) => {
2
2
  searchAggregateQuery: any;
3
3
  likeQuery: any;
4
4
  };
5
5
  export declare const mongoSelectQuery: (query?: any) => any;
6
6
  export declare const modifyQuery: (obj?: {}, hasAndQueryConjunction?: boolean) => any[];
7
- export declare const checkDate: (queryValue: string) => RegExpMatchArray | null;
7
+ export declare const isItDate: (queryValue: string) => RegExpMatchArray | null;
8
8
  export declare const getMinMaxValue: (value: any) => {
9
9
  startValue: any;
10
10
  endValue: any;
@@ -1,196 +1,183 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getValueOfProjectConstant = exports.isFixedValueQuery = exports.getMinMaxValue = exports.checkDate = exports.modifyQuery = exports.mongoSelectQuery = exports.getSearchObjQuery = void 0;
13
- var drapcode_constant_1 = require("drapcode-constant");
14
- var date_util_1 = require("./date-util");
15
- var util_1 = require("./util");
16
- var getSearchObjQuery = function (searchObj, searchQueryTypeObj, timezone) {
17
- var searchAggregateQuery = [];
18
- var likeQuery = [];
19
- Object.entries(searchObj).forEach(function (_a) {
20
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
21
- var key = _a[0], value = _a[1];
3
+ exports.getValueOfProjectConstant = exports.isFixedValueQuery = exports.getMinMaxValue = exports.isItDate = exports.modifyQuery = exports.mongoSelectQuery = exports.getSearchObjQuery = void 0;
4
+ const drapcode_constant_1 = require("drapcode-constant");
5
+ const date_util_1 = require("./date-util");
6
+ const util_1 = require("./util");
7
+ const getSearchObjQuery = (searchObj, searchQueryTypeObj) => {
8
+ let searchAggregateQuery = [];
9
+ let likeQuery = [];
10
+ Object.entries(searchObj).forEach(([key, value]) => {
22
11
  if (value) {
23
- var searchQueryTypeKey = searchQueryTypeObj[key];
12
+ const searchQueryTypeKey = searchQueryTypeObj[key];
24
13
  if (searchQueryTypeKey) {
25
14
  if (searchQueryTypeKey === "boolean") {
26
15
  // if input is string and db field type is boolean
27
16
  searchAggregateQuery.push({
28
- $addFields: (_b = {},
29
- _b["_".concat(key)] = "$".concat(key),
30
- _b),
17
+ $addFields: {
18
+ [`_${key}`]: `$${key}`,
19
+ },
20
+ });
21
+ likeQuery.push({
22
+ [`_${key}`]: toBoolean(value),
31
23
  });
32
- likeQuery.push((_c = {},
33
- _c["_".concat(key)] = toBoolean(value),
34
- _c));
35
24
  }
36
- else if (__spreadArray(__spreadArray([], drapcode_constant_1.OptionTypeFields, true), drapcode_constant_1.BelongsToReferenceField, true).includes(searchQueryTypeKey)) {
25
+ else if ([...drapcode_constant_1.OptionTypeFields, ...drapcode_constant_1.BelongsToReferenceField].includes(searchQueryTypeKey) //TODO: Changes
26
+ ) {
37
27
  // if input is string and db field type is array
38
28
  searchAggregateQuery.push({
39
- $addFields: (_d = {},
40
- _d["_".concat(key)] = "$".concat(key),
41
- _d),
29
+ $addFields: {
30
+ [`_${key}`]: `$${key}`,
31
+ },
32
+ });
33
+ likeQuery.push({
34
+ [`_${key}`]: { $all: [value] },
42
35
  });
43
- likeQuery.push((_e = {},
44
- _e["_".concat(key)] = { $all: [value] },
45
- _e));
46
36
  }
47
37
  else if (searchQueryTypeKey === "tel") {
48
38
  // handling value when db field type is tel
49
39
  searchAggregateQuery.push({
50
- $addFields: (_f = {},
51
- _f["_".concat(key)] = { $toString: "$".concat(key) },
52
- _f),
40
+ $addFields: {
41
+ [`_${key}`]: { $toString: `$${key}` },
42
+ },
53
43
  });
54
- likeQuery.push((_g = {},
55
- _g["_".concat(key)] = {
44
+ likeQuery.push({
45
+ [`_${key}`]: {
56
46
  $regex: value.startsWith("+") ? value.replace("+", "") : value,
57
47
  $options: "i",
58
48
  },
59
- _g));
49
+ });
60
50
  }
61
51
  else if (searchQueryTypeKey === "number") {
62
52
  if (key.startsWith("min_") || key.startsWith("max_")) {
63
- var fieldKey = key.replace("min_", "");
53
+ let fieldKey = key.replace("min_", "");
64
54
  fieldKey = fieldKey.replace("max_", "");
65
- var numericValue = Number(value);
55
+ const numericValue = Number(value);
66
56
  if (key.startsWith("min_")) {
67
- likeQuery.push((_h = {}, _h["".concat(fieldKey)] = { $gte: numericValue }, _h));
57
+ likeQuery.push({ [`${fieldKey}`]: { $gte: numericValue } });
68
58
  }
69
59
  else if (key.startsWith("max_")) {
70
- likeQuery.push((_j = {}, _j["".concat(fieldKey)] = { $lte: numericValue }, _j));
60
+ likeQuery.push({ [`${fieldKey}`]: { $lte: numericValue } });
71
61
  }
72
62
  }
73
63
  else {
74
64
  // handling value when db field type is Double/Int
75
65
  searchAggregateQuery.push({
76
- $addFields: (_k = {},
77
- _k["_".concat(key)] = { $toString: { $toLong: "$".concat(key) } },
78
- _k),
66
+ $addFields: {
67
+ [`_${key}`]: { $toString: { $toLong: `$${key}` } },
68
+ },
79
69
  });
80
- likeQuery.push((_l = {},
81
- _l["_".concat(key)] = {
70
+ likeQuery.push({
71
+ [`_${key}`]: {
82
72
  $regex: value,
83
73
  $options: "i",
84
74
  },
85
- _l));
75
+ });
86
76
  }
87
77
  }
88
- else if (__spreadArray(__spreadArray([
89
- drapcode_constant_1.FieldTypes.date.id
90
- ], drapcode_constant_1.systemDateField, true), [
78
+ else if ([
79
+ drapcode_constant_1.FieldTypes.date.id,
80
+ ...drapcode_constant_1.systemDateField,
91
81
  drapcode_constant_1.FieldTypes.time_slot.id,
92
- ], false).includes(searchQueryTypeKey)) {
82
+ ].includes(searchQueryTypeKey)) {
93
83
  if (key.startsWith("start_") || key.startsWith("end_")) {
94
- var fieldKey = key.replace("start_", "");
84
+ let fieldKey = key.replace("start_", "");
95
85
  fieldKey = fieldKey.replace("end_", "");
96
86
  searchAggregateQuery.push({
97
- $addFields: (_m = {},
98
- _m["_".concat(key)] = { $toString: "$".concat(fieldKey) },
99
- _m),
87
+ $addFields: {
88
+ [`_${key}`]: { $toString: `$${fieldKey}` },
89
+ },
100
90
  });
101
91
  if (key.startsWith("start_")) {
102
- likeQuery.push((_o = {},
103
- _o["_".concat(key)] = {
92
+ likeQuery.push({
93
+ [`_${key}`]: {
104
94
  $gte: (0, date_util_1.timezoneDateParse)(value, false, true),
105
95
  },
106
- _o));
96
+ });
107
97
  }
108
98
  else if (key.startsWith("end_")) {
109
- likeQuery.push((_p = {},
110
- _p["_".concat(key)] = {
99
+ likeQuery.push({
100
+ [`_${key}`]: {
111
101
  $lt: (0, date_util_1.timezoneDateParse)(value),
112
102
  },
113
- _p));
103
+ });
114
104
  }
115
105
  }
116
106
  else {
117
107
  searchAggregateQuery.push({
118
- $addFields: (_q = {},
119
- _q["_".concat(key)] = { $toString: "$".concat(key) },
120
- _q),
108
+ $addFields: {
109
+ [`_${key}`]: { $toString: `$${key}` },
110
+ },
121
111
  });
122
- likeQuery.push((_r = {},
123
- _r["_".concat(key)] = {
112
+ likeQuery.push({
113
+ [`_${key}`]: {
124
114
  $gte: (0, date_util_1.timezoneDateParse)(value, false, true),
125
115
  },
126
- _r));
127
- likeQuery.push((_s = {},
128
- _s["_".concat(key)] = {
116
+ });
117
+ likeQuery.push({
118
+ [`_${key}`]: {
129
119
  $lt: (0, date_util_1.timezoneDateParse)(value, false),
130
120
  },
131
- _s));
121
+ });
132
122
  }
133
123
  }
134
124
  else {
135
125
  // if input is string and db field type is number
136
126
  // converting db field to string first
137
127
  searchAggregateQuery.push({
138
- $addFields: (_t = {},
139
- _t["_".concat(key)] = { $toString: "$".concat(key) },
140
- _t),
128
+ $addFields: {
129
+ [`_${key}`]: { $toString: `$${key}` },
130
+ },
141
131
  });
142
- likeQuery.push((_u = {},
143
- _u["_".concat(key)] = {
132
+ likeQuery.push({
133
+ [`_${key}`]: {
144
134
  $regex: value,
145
135
  $options: "i",
146
136
  },
147
- _u));
137
+ });
148
138
  }
149
139
  }
150
140
  else {
151
- likeQuery.push((_v = {},
152
- _v[key] = {
141
+ likeQuery.push({
142
+ [key]: {
153
143
  $regex: value,
154
144
  $options: "i",
155
145
  },
156
- _v));
146
+ });
157
147
  }
158
148
  }
159
149
  });
160
- console.log("==> searchAggregateQuery", JSON.stringify(searchAggregateQuery));
161
- console.log("==> likeQuery", JSON.stringify(likeQuery));
162
- return { searchAggregateQuery: searchAggregateQuery, likeQuery: likeQuery };
150
+ console.log(`==> searchAggregateQuery`, JSON.stringify(searchAggregateQuery));
151
+ console.log(`==> likeQuery`, JSON.stringify(likeQuery));
152
+ return { searchAggregateQuery, likeQuery };
163
153
  };
164
154
  exports.getSearchObjQuery = getSearchObjQuery;
165
- var mongoSelectQuery = function (query) {
166
- if (query === void 0) { query = {}; }
167
- var projection = {};
168
- var fieldsInclude = query.fieldsInclude, fieldsExclude = query.fieldsExclude, finder = query.finder;
155
+ const mongoSelectQuery = (query = {}) => {
156
+ const projection = {};
157
+ let { fieldsInclude, fieldsExclude, finder } = query;
169
158
  if (!fieldsExclude)
170
159
  fieldsExclude = [];
171
160
  if (fieldsInclude[0] === "*") {
172
- fieldsExclude.map(function (field) {
161
+ fieldsExclude.map((field) => {
173
162
  if (field)
174
- return (projection["".concat(field)] = 0);
163
+ return (projection[`${field}`] = 0);
175
164
  });
176
165
  }
177
166
  else {
178
167
  if (["FIND_ALL", "FIND"].includes(finder))
179
168
  fieldsInclude = (0, util_1.processFieldsInclude)(fieldsInclude);
180
- fieldsInclude.map(function (field) {
169
+ fieldsInclude.map((field) => {
181
170
  if (field)
182
- return (projection["".concat(field)] = 1);
171
+ return (projection[`${field}`] = 1);
183
172
  });
184
173
  }
185
174
  return projection;
186
175
  };
187
176
  exports.mongoSelectQuery = mongoSelectQuery;
188
- var modifyQuery = function (obj, hasAndQueryConjunction) {
189
- if (obj === void 0) { obj = {}; }
190
- if (hasAndQueryConjunction === void 0) { hasAndQueryConjunction = false; }
191
- var arr = [];
192
- Object.entries(obj).forEach(function (_a) {
193
- var key = _a[0], value = _a[1];
177
+ const modifyQuery = (obj = {}, hasAndQueryConjunction = false) => {
178
+ let arr = [];
179
+ Object.entries(obj).forEach(([key, value]) => {
180
+ console.log("key:>> ", key);
194
181
  if (hasAndQueryConjunction) {
195
182
  arr.push({ $and: value });
196
183
  }
@@ -201,7 +188,7 @@ var modifyQuery = function (obj, hasAndQueryConjunction) {
201
188
  return arr;
202
189
  };
203
190
  exports.modifyQuery = modifyQuery;
204
- var toBoolean = function (value) {
191
+ const toBoolean = (value) => {
205
192
  if (!value) {
206
193
  return false;
207
194
  }
@@ -215,33 +202,33 @@ var toBoolean = function (value) {
215
202
  return false;
216
203
  }
217
204
  };
218
- var checkDate = function (queryValue) {
205
+ const isItDate = (queryValue) => {
219
206
  return ("" + queryValue).match(date_util_1.DATE_REGEX);
220
207
  };
221
- exports.checkDate = checkDate;
222
- var getMinMaxValue = function (value) {
223
- var isFixedValue = (0, exports.isFixedValueQuery)(value);
208
+ exports.isItDate = isItDate;
209
+ const getMinMaxValue = (value) => {
210
+ let isFixedValue = (0, exports.isFixedValueQuery)(value);
224
211
  if (isFixedValue)
225
212
  value = value.replace("FIXED_VALUE::", "");
226
- var isValid = value && value.includes("---");
213
+ let isValid = value && value.includes("---");
227
214
  if (isValid) {
228
- var isInteger = value.includes("^");
229
- var result = value.split("---");
230
- var endValue = result[1];
215
+ let isInteger = value.includes("^");
216
+ let result = value.split("---");
217
+ let endValue = result[1];
231
218
  if (isInteger && result.length)
232
219
  endValue = endValue.slice(0, -1);
233
- return { startValue: result[0], endValue: endValue, isInteger: isInteger, isFixedValue: isFixedValue };
220
+ return { startValue: result[0], endValue, isInteger, isFixedValue };
234
221
  }
235
222
  else {
236
- return { startValue: "", endValue: "", isFixedValue: isFixedValue };
223
+ return { startValue: "", endValue: "", isFixedValue };
237
224
  }
238
225
  };
239
226
  exports.getMinMaxValue = getMinMaxValue;
240
227
  // TODO: can be refactor with entity condition
241
- var isFixedValueQuery = function (value) {
242
- var isFixeValue = false;
228
+ const isFixedValueQuery = (value) => {
229
+ let isFixeValue = false;
243
230
  if (value && Array.isArray(value)) {
244
- value.forEach(function (val) {
231
+ value.forEach((val) => {
245
232
  if (typeof val === "string" || val instanceof String)
246
233
  isFixeValue = val.startsWith("FIXED_VALUE::");
247
234
  });
@@ -253,18 +240,18 @@ var isFixedValueQuery = function (value) {
253
240
  return isFixeValue;
254
241
  };
255
242
  exports.isFixedValueQuery = isFixedValueQuery;
256
- var getValueOfProjectConstant = function (value, currentUser, timezone) {
243
+ const getValueOfProjectConstant = (value, currentUser, timezone) => {
257
244
  if (!timezone)
258
245
  timezone = "(GMT+5:30)";
259
246
  timezone = timezone.substring(4, 10);
260
- var result;
247
+ let result;
261
248
  if (value === drapcode_constant_1.CURRENT_USER)
262
- return currentUser["uuid"];
249
+ return currentUser[`uuid`];
263
250
  if (value === drapcode_constant_1.CURRENT_DATE)
264
251
  result = (0, date_util_1.createLoggerDateFormat)(timezone);
265
252
  if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
266
253
  result = (0, date_util_1.createLogsDateFormat)(timezone);
267
- if (drapcode_constant_1.DateTimeUnit.some(function (cnst) { return value.includes(cnst); }))
254
+ if (drapcode_constant_1.DateTimeUnit.some((cnst) => value.includes(cnst)))
268
255
  result = (0, date_util_1.getDateValue)(value, timezone);
269
256
  return result;
270
257
  };