drapcode-utility 1.2.9 → 1.3.1

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,17 +21,52 @@ 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) {
25
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
26
- to[j] = from[i];
27
- return to;
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));
28
32
  };
29
33
  var __importDefault = (this && this.__importDefault) || function (mod) {
30
34
  return (mod && mod.__esModule) ? mod : { "default": mod };
31
35
  };
32
36
  Object.defineProperty(exports, "__esModule", { value: true });
33
- 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;
37
+ exports.replaceValueFromSource = 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;
34
38
  var lodash_1 = __importDefault(require("lodash"));
39
+ // TODO: Refactor
40
+ var derivedFieldExcludes = [
41
+ "formatType",
42
+ "restToLower",
43
+ "whitespace",
44
+ "type",
45
+ "noSplitopt",
46
+ "length",
47
+ "endopt",
48
+ "startLength",
49
+ "endLength",
50
+ "startString",
51
+ "endString",
52
+ "separator",
53
+ "expression",
54
+ "unixType",
55
+ "currency",
56
+ "maxFraction",
57
+ "position",
58
+ "refField",
59
+ "condition",
60
+ "match",
61
+ "refFieldType",
62
+ "index",
63
+ "positionOfRecords",
64
+ "numberOfRecords",
65
+ "elementToRender",
66
+ "indexNum",
67
+ ];
68
+ var environmentFixKey = "environment_variable.";
69
+ var tenantFixKey = "current_tenant.";
35
70
  var validateString = function (str) {
36
71
  var specialChar = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
37
72
  var isNumber = str.match(/\d+/g);
@@ -43,7 +78,7 @@ var validateString = function (str) {
43
78
  };
44
79
  exports.validateString = validateString;
45
80
  var camelize = function (str) {
46
- str = exports.clearSpaceAndReformat(str);
81
+ str = (0, exports.clearSpaceAndReformat)(str);
47
82
  return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
48
83
  return index === 0 ? word.toLowerCase() : word.toUpperCase();
49
84
  });
@@ -170,8 +205,8 @@ var cleanCollectionAndFieldName = function (str) {
170
205
  };
171
206
  exports.cleanCollectionAndFieldName = cleanCollectionAndFieldName;
172
207
  var formatCollectionAndFieldName = function (str) {
173
- var updateString = exports.cleanCollectionAndFieldName(str);
174
- return exports.clearSpaceAndReformat(updateString.trim(), "_");
208
+ var updateString = (0, exports.cleanCollectionAndFieldName)(str);
209
+ return (0, exports.clearSpaceAndReformat)(updateString.trim(), "_");
175
210
  };
176
211
  exports.formatCollectionAndFieldName = formatCollectionAndFieldName;
177
212
  var restructureData = function (data) {
@@ -202,7 +237,7 @@ var restructureData = function (data) {
202
237
  exports.restructureData = restructureData;
203
238
  var checkAndCompareValue = function (input1, input2) {
204
239
  return Array.isArray(input2)
205
- ? exports.arraysEqual(input1, input2.map(function (key) { return key.value; }))
240
+ ? (0, exports.arraysEqual)(input1, input2.map(function (key) { return key.value; }))
206
241
  : input1 === input2.value;
207
242
  };
208
243
  exports.checkAndCompareValue = checkAndCompareValue;
@@ -212,7 +247,7 @@ var arraysEqual = function (array1, array2) {
212
247
  return false;
213
248
  for (var i = 0; i < array1.length; i++ // assert each element equal
214
249
  )
215
- if (!exports.arraysEqual(array1[i], array2[i]))
250
+ if (!(0, exports.arraysEqual)(array1[i], array2[i]))
216
251
  return false;
217
252
  return true;
218
253
  }
@@ -235,19 +270,19 @@ var validateAlphanumericString = function (str) {
235
270
  return false;
236
271
  };
237
272
  exports.validateAlphanumericString = validateAlphanumericString;
238
- var formatCustomCSSClasses = function (projectCustomCSSClasses) {
239
- if (!projectCustomCSSClasses || !Array.isArray(projectCustomCSSClasses)) {
273
+ var formatCustomCSSClasses = function (customClasses) {
274
+ if (!customClasses || !Array.isArray(customClasses)) {
240
275
  return "";
241
276
  }
242
277
  var projectCustomCSSClassesData = "";
243
- projectCustomCSSClasses.forEach(function (element) {
278
+ customClasses.forEach(function (element) {
244
279
  if (element.classProperty) {
245
280
  var classWithProp = JSON.stringify(element.classProperty);
246
281
  var unquotedClassWithProp = classWithProp
247
282
  .replace(/"([^"]+)"/g, "$1")
248
283
  .split(",")
249
284
  .join(";");
250
- projectCustomCSSClassesData += "" + (element.class.startsWith(".") ? element.class : "." + element.class) + (element.pseudoClass ? ":" + element.pseudoClass : "") + unquotedClassWithProp + " ";
285
+ projectCustomCSSClassesData += "".concat(element.class.startsWith(".") ? element.class : "." + element.class).concat(element.pseudoClass ? ":" + element.pseudoClass : "").concat(unquotedClassWithProp, " ");
251
286
  }
252
287
  });
253
288
  return projectCustomCSSClassesData;
@@ -258,18 +293,18 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
258
293
  var contentList = (_a = expression
259
294
  .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
260
295
  contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
261
- var needle = "{{" + prop + "}}";
296
+ var needle = "{{".concat(prop, "}}");
262
297
  var dataOfItem = "";
263
298
  if (prop.includes("current_user")) {
264
299
  prop = prop.replace("current_user.", "");
265
300
  if (Object.keys(user).length > 0) {
266
- dataOfItem = exports.parseValueFromData(user, prop);
301
+ dataOfItem = (0, exports.parseValueFromData)(user, prop);
267
302
  }
268
303
  }
269
304
  else if (prop.includes("current_tenant")) {
270
305
  prop = prop.replace("current_tenant.", "");
271
306
  if (Object.keys(tenant).length > 0) {
272
- dataOfItem = exports.parseValueFromData(tenant, prop);
307
+ dataOfItem = (0, exports.parseValueFromData)(tenant, prop);
273
308
  }
274
309
  }
275
310
  else if (prop.includes("current_session")) {
@@ -295,7 +330,7 @@ var replaceDataValueIntoExpression = function (expression, data, user, tenant, s
295
330
  }
296
331
  else {
297
332
  if (Object.keys(data).length > 0) {
298
- dataOfItem = exports.parseValueFromData(data, prop);
333
+ dataOfItem = (0, exports.parseValueFromData)(data, prop);
299
334
  //TODO: Need better way
300
335
  delete data[prop];
301
336
  }
@@ -395,7 +430,7 @@ var replaceTransferObjectValueIntoExpression = function (expression, transferObj
395
430
  var contentList = (_a = expression
396
431
  .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
397
432
  contentList === null || contentList === void 0 ? void 0 : contentList.forEach(function (prop) {
398
- var needle = "{{" + prop + "}}";
433
+ var needle = "{{".concat(prop, "}}");
399
434
  var dataOfItem = "";
400
435
  dataOfItem = transferObject[prop] ? transferObject[prop] : "";
401
436
  expression = dataOfItem
@@ -430,35 +465,6 @@ var removeMongoDbId = function (result) {
430
465
  return result.map(moveUuidToTopLevel);
431
466
  };
432
467
  exports.removeMongoDbId = removeMongoDbId;
433
- // TODO: Refactor
434
- var derivedFieldExcludes = [
435
- "formatType",
436
- "restToLower",
437
- "whitespace",
438
- "type",
439
- "noSplitopt",
440
- "length",
441
- "endopt",
442
- "startLength",
443
- "endLength",
444
- "startString",
445
- "endString",
446
- "separator",
447
- "expression",
448
- "unixType",
449
- "currency",
450
- "maxFraction",
451
- "position",
452
- "refField",
453
- "condition",
454
- "match",
455
- "refFieldType",
456
- "index",
457
- "positionOfRecords",
458
- "numberOfRecords",
459
- "elementToRender",
460
- "indexNum",
461
- ];
462
468
  var processFieldsInlcude = function (fieldsInclude) {
463
469
  var result = fieldsInclude;
464
470
  var refFieldsInclude = fieldsInclude.filter(function (field) {
@@ -470,8 +476,8 @@ var processFieldsInlcude = function (fieldsInclude) {
470
476
  fieldsInclude = fieldsInclude.filter(function (field) { return !(field.startsWith("RF::") || field.startsWith("DF::")); });
471
477
  var refFields = processReferenceFieldInclude(refFieldsInclude);
472
478
  var derivedFields = processDerivedFieldInclude(derivedFieldsInclude);
473
- var extraField = __spreadArray(__spreadArray([], refFields), derivedFields).filter(function (value, index, array) { return array.indexOf(value) === index; });
474
- result = __spreadArray(__spreadArray([], fieldsInclude), extraField);
479
+ var extraField = __spreadArray(__spreadArray([], refFields, true), derivedFields, true).filter(function (value, index, array) { return array.indexOf(value) === index; });
480
+ result = __spreadArray(__spreadArray([], fieldsInclude, true), extraField, true);
475
481
  return result;
476
482
  };
477
483
  exports.processFieldsInlcude = processFieldsInlcude;
@@ -496,16 +502,53 @@ var processDerivedFieldInclude = function (derivedFieldsInclude) {
496
502
  if (arg.name === "expression") {
497
503
  var needleList = (_a = arg.key
498
504
  .match(/{{(.*?)}}/g)) === null || _a === void 0 ? void 0 : _a.map(function (b) { return b.replace(/{{(.*?)}}/g, "$1"); });
499
- var tempFields = exports.processFieldsInlcude(needleList);
500
- fields = __spreadArray(__spreadArray([], fields), tempFields);
505
+ var tempFields = (0, exports.processFieldsInlcude)(needleList);
506
+ fields = __spreadArray(__spreadArray([], fields, true), tempFields, true);
501
507
  }
502
508
  else if (!derivedFieldExcludes.includes(arg.name)) {
503
509
  var tempFields = Array.isArray(arg.key) ? arg.key : [arg.key];
504
- tempFields = exports.processFieldsInlcude(tempFields);
505
- fields = __spreadArray(__spreadArray([], fields), tempFields);
510
+ tempFields = (0, exports.processFieldsInlcude)(tempFields);
511
+ fields = __spreadArray(__spreadArray([], fields, true), tempFields, true);
506
512
  }
507
513
  });
508
- derivedFields = __spreadArray(__spreadArray([], derivedFields), fields);
514
+ derivedFields = __spreadArray(__spreadArray([], derivedFields, true), fields, true);
509
515
  });
510
516
  return derivedFields;
511
517
  };
518
+ var replaceValueFromSource = function (variableName, environment, tenant) {
519
+ if (variableName && typeof variableName === "string") {
520
+ if (variableName.startsWith(environmentFixKey)) {
521
+ return replaceValueFromEnvironment(variableName, environment);
522
+ }
523
+ else if (variableName.startsWith(tenantFixKey)) {
524
+ return replaceValueFromTenant(variableName, tenant);
525
+ }
526
+ else {
527
+ return variableName;
528
+ }
529
+ }
530
+ else {
531
+ return variableName;
532
+ }
533
+ };
534
+ exports.replaceValueFromSource = replaceValueFromSource;
535
+ var replaceValueFromEnvironment = function (variableName, environment) {
536
+ if (variableName &&
537
+ typeof variableName === "string" &&
538
+ variableName.startsWith(environmentFixKey) &&
539
+ environment &&
540
+ environment.constants) {
541
+ var envConstant = environment.constants.find(function (env) { return env.name === variableName.replace(environmentFixKey, ""); });
542
+ return envConstant.value;
543
+ }
544
+ else {
545
+ return variableName;
546
+ }
547
+ };
548
+ var replaceValueFromTenant = function (variableName, tenant) {
549
+ if (!tenant) {
550
+ return variableName;
551
+ }
552
+ variableName = variableName.replace(tenantFixKey, "");
553
+ return lodash_1.default.get(tenant, variableName);
554
+ };
@@ -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.9",
3
+ "version": "1.3.1",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -21,6 +21,7 @@
21
21
  "devDependencies": {
22
22
  "@types/lodash": "^4.14.179",
23
23
  "@types/mime-types": "^2.1.4",
24
+ "@types/uuid": "^9.0.8",
24
25
  "del-cli": "^5.0.0",
25
26
  "typescript": "^4.0.2"
26
27
  },
@@ -32,7 +33,7 @@
32
33
  "@types/express": "^4.17.7",
33
34
  "@types/voca": "^1.4.2",
34
35
  "axios": "^1.1.2",
35
- "drapcode-constant": "^1.2.9",
36
+ "drapcode-constant": "^1.3.0",
36
37
  "drapcode-logger": "^1.0.7",
37
38
  "drapcode-redis": "^1.0.4",
38
39
  "express": "^4.17.1",
@@ -40,6 +41,7 @@
40
41
  "mime-types": "^2.1.35",
41
42
  "moment": "^2.29.0",
42
43
  "stringify-object": "^3.3.0",
44
+ "uuid": "^8.3.2",
43
45
  "voca": "^1.4.0"
44
46
  }
45
47
  }