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.
@@ -21,11 +21,20 @@ 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, pack) {
25
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
26
+ if (ar || !(i in from)) {
27
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
28
+ ar[i] = from[i];
29
+ }
30
+ }
31
+ return to.concat(ar || Array.prototype.slice.call(from));
32
+ };
24
33
  var __importDefault = (this && this.__importDefault) || function (mod) {
25
34
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
35
  };
27
36
  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;
37
+ 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
38
  var lodash_1 = __importDefault(require("lodash"));
30
39
  var validateString = function (str) {
31
40
  var specialChar = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
@@ -38,7 +47,7 @@ var validateString = function (str) {
38
47
  };
39
48
  exports.validateString = validateString;
40
49
  var camelize = function (str) {
41
- str = exports.clearSpaceAndReformat(str);
50
+ str = (0, exports.clearSpaceAndReformat)(str);
42
51
  return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
43
52
  return index === 0 ? word.toLowerCase() : word.toUpperCase();
44
53
  });
@@ -165,8 +174,8 @@ var cleanCollectionAndFieldName = function (str) {
165
174
  };
166
175
  exports.cleanCollectionAndFieldName = cleanCollectionAndFieldName;
167
176
  var formatCollectionAndFieldName = function (str) {
168
- var updateString = exports.cleanCollectionAndFieldName(str);
169
- return exports.clearSpaceAndReformat(updateString.trim(), "_");
177
+ var updateString = (0, exports.cleanCollectionAndFieldName)(str);
178
+ return (0, exports.clearSpaceAndReformat)(updateString.trim(), "_");
170
179
  };
171
180
  exports.formatCollectionAndFieldName = formatCollectionAndFieldName;
172
181
  var restructureData = function (data) {
@@ -197,7 +206,7 @@ var restructureData = function (data) {
197
206
  exports.restructureData = restructureData;
198
207
  var checkAndCompareValue = function (input1, input2) {
199
208
  return Array.isArray(input2)
200
- ? exports.arraysEqual(input1, input2.map(function (key) { return key.value; }))
209
+ ? (0, exports.arraysEqual)(input1, input2.map(function (key) { return key.value; }))
201
210
  : input1 === input2.value;
202
211
  };
203
212
  exports.checkAndCompareValue = checkAndCompareValue;
@@ -207,7 +216,7 @@ var arraysEqual = function (array1, array2) {
207
216
  return false;
208
217
  for (var i = 0; i < array1.length; i++ // assert each element equal
209
218
  )
210
- if (!exports.arraysEqual(array1[i], array2[i]))
219
+ if (!(0, exports.arraysEqual)(array1[i], array2[i]))
211
220
  return false;
212
221
  return true;
213
222
  }
@@ -242,7 +251,7 @@ var formatCustomCSSClasses = function (projectCustomCSSClasses) {
242
251
  .replace(/"([^"]+)"/g, "$1")
243
252
  .split(",")
244
253
  .join(";");
245
- projectCustomCSSClassesData += "" + (element.class.startsWith(".") ? element.class : "." + element.class) + (element.pseudoClass ? ":" + element.pseudoClass : "") + unquotedClassWithProp + " ";
254
+ projectCustomCSSClassesData += "".concat(element.class.startsWith(".") ? element.class : "." + element.class).concat(element.pseudoClass ? ":" + element.pseudoClass : "").concat(unquotedClassWithProp, " ");
246
255
  }
247
256
  });
248
257
  return projectCustomCSSClassesData;
@@ -253,18 +262,18 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
253
262
  var contentList = (_a = expression
254
263
  .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
255
264
  contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
256
- var needle = "{{" + prop + "}}";
265
+ var needle = "{{".concat(prop, "}}");
257
266
  var dataOfItem = "";
258
267
  if (prop.includes("current_user")) {
259
268
  prop = prop.replace("current_user.", "");
260
269
  if (Object.keys(user).length > 0) {
261
- dataOfItem = exports.parseValueFromData(user, prop);
270
+ dataOfItem = (0, exports.parseValueFromData)(user, prop);
262
271
  }
263
272
  }
264
273
  else if (prop.includes("current_tenant")) {
265
274
  prop = prop.replace("current_tenant.", "");
266
275
  if (Object.keys(tenant).length > 0) {
267
- dataOfItem = exports.parseValueFromData(tenant, prop);
276
+ dataOfItem = (0, exports.parseValueFromData)(tenant, prop);
268
277
  }
269
278
  }
270
279
  else if (prop.includes("current_session")) {
@@ -290,7 +299,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
290
299
  }
291
300
  else {
292
301
  if (Object.keys(data).length > 0) {
293
- dataOfItem = exports.parseValueFromData(data, prop);
302
+ dataOfItem = (0, exports.parseValueFromData)(data, prop);
294
303
  //TODO: Need better way
295
304
  delete data[prop];
296
305
  }
@@ -390,7 +399,7 @@ var replaceTransferObjectValueIntoExpression = function (expression, transferObj
390
399
  var contentList = (_a = expression
391
400
  .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
392
401
  contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
393
- var needle = "{{" + prop + "}}";
402
+ var needle = "{{".concat(prop, "}}");
394
403
  var dataOfItem = "";
395
404
  dataOfItem = transferObject[prop] ? transferObject[prop] : "";
396
405
  expression = dataOfItem
@@ -425,3 +434,82 @@ var removeMongoDbId = function (result) {
425
434
  return result.map(moveUuidToTopLevel);
426
435
  };
427
436
  exports.removeMongoDbId = removeMongoDbId;
437
+ // TODO: Refactor
438
+ var derivedFieldExcludes = [
439
+ "formatType",
440
+ "restToLower",
441
+ "whitespace",
442
+ "type",
443
+ "noSplitopt",
444
+ "length",
445
+ "endopt",
446
+ "startLength",
447
+ "endLength",
448
+ "startString",
449
+ "endString",
450
+ "separator",
451
+ "expression",
452
+ "unixType",
453
+ "currency",
454
+ "maxFraction",
455
+ "position",
456
+ "refField",
457
+ "condition",
458
+ "match",
459
+ "refFieldType",
460
+ "index",
461
+ "positionOfRecords",
462
+ "numberOfRecords",
463
+ "elementToRender",
464
+ "indexNum",
465
+ ];
466
+ var processFieldsInlcude = function (fieldsInclude) {
467
+ var result = fieldsInclude;
468
+ var refFieldsInclude = fieldsInclude.filter(function (field) {
469
+ return field.startsWith("RF::");
470
+ });
471
+ var derivedFieldsInclude = fieldsInclude.filter(function (field) {
472
+ return field.startsWith("DF::");
473
+ });
474
+ fieldsInclude = fieldsInclude.filter(function (field) { return !(field.startsWith("RF::") || field.startsWith("DF::")); });
475
+ var refFields = processReferenceFieldInclude(refFieldsInclude);
476
+ var derivedFields = processDerivedFieldInclude(derivedFieldsInclude);
477
+ var extraField = __spreadArray(__spreadArray([], refFields, true), derivedFields, true).filter(function (value, index, array) { return array.indexOf(value) === index; });
478
+ result = __spreadArray(__spreadArray([], fieldsInclude, true), extraField, true);
479
+ return result;
480
+ };
481
+ exports.processFieldsInlcude = processFieldsInlcude;
482
+ var processReferenceFieldInclude = function (refFieldsInclude) {
483
+ var refFields = [];
484
+ refFieldsInclude.forEach(function (exField) {
485
+ var field = exField.replace("RF::", "");
486
+ field = field.split(".")[0];
487
+ refFields.push(field);
488
+ });
489
+ return refFields;
490
+ };
491
+ var processDerivedFieldInclude = function (derivedFieldsInclude) {
492
+ var derivedFields = [];
493
+ derivedFieldsInclude.forEach(function (exField) {
494
+ var derivedFieldStr = exField.replace("DF::", "");
495
+ derivedFieldStr = derivedFieldStr.replaceAll("*#*#", '"');
496
+ var derivedFieldObj = JSON.parse(derivedFieldStr);
497
+ var fields = [];
498
+ derivedFieldObj.args.forEach(function (arg) {
499
+ var _a;
500
+ if (arg.name === "expression") {
501
+ var needleList = (_a = arg.key
502
+ .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
503
+ var tempFields = (0, exports.processFieldsInlcude)(needleList);
504
+ fields = __spreadArray(__spreadArray([], fields, true), tempFields, true);
505
+ }
506
+ else if (!derivedFieldExcludes.includes(arg.name)) {
507
+ var tempFields = Array.isArray(arg.key) ? arg.key : [arg.key];
508
+ tempFields = (0, exports.processFieldsInlcude)(tempFields);
509
+ fields = __spreadArray(__spreadArray([], fields, true), tempFields, true);
510
+ }
511
+ });
512
+ derivedFields = __spreadArray(__spreadArray([], derivedFields, true), fields, true);
513
+ });
514
+ return derivedFields;
515
+ };
@@ -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 = "" + prepend + finalValue;
41
+ finalValue = "".concat(prepend).concat(finalValue);
42
42
  }
43
43
  if (append) {
44
- finalValue = "" + finalValue + append;
44
+ finalValue = "".concat(finalValue).concat(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.2-beta",
3
+ "version": "1.2.3",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -32,8 +32,8 @@
32
32
  "@types/express": "^4.17.7",
33
33
  "@types/voca": "^1.4.2",
34
34
  "axios": "^1.1.2",
35
- "drapcode-constant": "^1.2.4",
36
- "drapcode-logger": "^1.0.4",
35
+ "drapcode-constant": "^1.2.7",
36
+ "drapcode-logger": "^1.0.5",
37
37
  "drapcode-redis": "^1.0.4",
38
38
  "express": "^4.17.1",
39
39
  "lodash": "^4.17.21",