@nextage/nx-frame-be 1.0.35 → 1.0.36
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.
- package/build/common/base/__test__/base.model.test.js +31 -23
- package/build/common/base/base.controller.d.ts +0 -26
- package/build/common/base/base.interfaces.d.ts +0 -26
- package/build/common/base/base.model.d.ts +0 -27
- package/build/common/base/mongo-utils.d.ts +0 -26
- package/build/common/base/mongo-utils.js +35 -13
- package/build/common/base/sql-utils.js +2 -2
- package/build/common/constants.d.ts +1 -3
- package/build/common/crypto/crypto.classes.d.ts +0 -2
- package/build/common/crypto/crypto.interfaces.d.ts +0 -1
- package/build/common/crypto/crypto.utils.d.ts +0 -1
- package/build/common/crypto/encryption.plugin.d.ts +0 -28
- package/build/common/crypto/encryption.plugin.js +1 -2
- package/build/common/express/express.utils.js +3 -4
- package/build/common/graphql/__test__/generator.schema.test.js +39 -39
- package/build/common/graphql/directives.js +3 -3
- package/build/common/graphql/generator copy.js +5 -5
- package/build/common/graphql/generator.js +5 -5
- package/build/common/graphql/loader.js +4 -4
- package/build/common/graphql/utils.js +3 -3
- package/build/common/grid-fs/gridfs-base.model.d.ts +0 -27
- package/build/common/grid-fs/gridfs.interfaces.d.ts +0 -26
- package/build/common/manager/bulk-manager.d.ts +0 -26
- package/build/common/manager/crypto-manager.d.ts +0 -1
- package/build/common/manager/socket-io-cli-manager.d.ts +0 -1
- package/build/common/manager/tunnel-manager.d.ts +0 -1
- package/build/common/models/coded-entity.model.js +2 -14
- package/build/common/types.d.ts +0 -26
- package/build/common/utils.d.ts +0 -3
- package/build/common/utils.js +83 -85
- package/package.json +5 -5
package/build/common/utils.js
CHANGED
|
@@ -12,8 +12,89 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
exports.
|
|
15
|
+
exports.devMode = devMode;
|
|
16
|
+
exports.prodMode = prodMode;
|
|
17
|
+
exports.generateJwt = generateJwt;
|
|
18
|
+
exports.validateJwt = validateJwt;
|
|
19
|
+
exports.randomString = randomString;
|
|
20
|
+
exports.baseComparator = baseComparator;
|
|
21
|
+
exports.baseComparatorReverse = baseComparatorReverse;
|
|
22
|
+
exports.isObject = isObject;
|
|
23
|
+
exports.isFunction = isFunction;
|
|
24
|
+
exports.isDate = isDate;
|
|
25
|
+
exports.isBoolean = isBoolean;
|
|
26
|
+
exports.isString = isString;
|
|
27
|
+
exports.isNumber = isNumber;
|
|
28
|
+
exports.isNotNull = isNotNull;
|
|
29
|
+
exports.isNil = isNil;
|
|
30
|
+
exports.isUndefined = isUndefined;
|
|
31
|
+
exports.isDefined = isDefined;
|
|
32
|
+
exports.isBase64 = isBase64;
|
|
33
|
+
exports.isEmail = isEmail;
|
|
34
|
+
exports.contains = contains;
|
|
35
|
+
exports.containsArrayValue = containsArrayValue;
|
|
36
|
+
exports.isEmpty = isEmpty;
|
|
37
|
+
exports.hasKeys = hasKeys;
|
|
38
|
+
exports.mergeArraysByKey = mergeArraysByKey;
|
|
39
|
+
exports.findDeep = findDeep;
|
|
40
|
+
exports.percentDiff = percentDiff;
|
|
41
|
+
exports.dottedKeys = dottedKeys;
|
|
42
|
+
exports.dotObj = dotObj;
|
|
43
|
+
exports.strToJson = strToJson;
|
|
44
|
+
exports.jsonToStr = jsonToStr;
|
|
45
|
+
exports.capitalize = capitalize;
|
|
46
|
+
exports.parseTypedString = parseTypedString;
|
|
47
|
+
exports.toFilterDatePeriod = toFilterDatePeriod;
|
|
48
|
+
exports.isValidDateStr = isValidDateStr;
|
|
49
|
+
exports.toDate = toDate;
|
|
50
|
+
exports.toMoment = toMoment;
|
|
51
|
+
exports.dateFormat = dateFormat;
|
|
52
|
+
exports.getDateDiff = getDateDiff;
|
|
53
|
+
exports.getDateValues = getDateValues;
|
|
54
|
+
exports.getTimeValues = getTimeValues;
|
|
55
|
+
exports.getDatePeriod = getDatePeriod;
|
|
56
|
+
exports.uuid = uuid;
|
|
57
|
+
exports.logClassCtx = logClassCtx;
|
|
58
|
+
exports.logMemory = logMemory;
|
|
59
|
+
exports.forceGC = forceGC;
|
|
60
|
+
exports.getCtxUser = getCtxUser;
|
|
61
|
+
exports.flattenArray = flattenArray;
|
|
62
|
+
exports.deleteKey = deleteKey;
|
|
63
|
+
exports.sortBy = sortBy;
|
|
64
|
+
exports.readFileSync = readFileSync;
|
|
65
|
+
exports.union = union;
|
|
66
|
+
exports.uniqBy = uniqBy;
|
|
67
|
+
exports.merge = merge;
|
|
68
|
+
exports.clone = clone;
|
|
69
|
+
exports.getAttr = getAttr;
|
|
70
|
+
exports.setAttr = setAttr;
|
|
71
|
+
exports.hasAttr = hasAttr;
|
|
72
|
+
exports.hasDefinedAttr = hasDefinedAttr;
|
|
73
|
+
exports.isEqual = isEqual;
|
|
74
|
+
exports.encodeString = encodeString;
|
|
75
|
+
exports.chunkString = chunkString;
|
|
76
|
+
exports.initObjectFromDotNotation = initObjectFromDotNotation;
|
|
77
|
+
exports.initObjectWithProperty = initObjectWithProperty;
|
|
78
|
+
exports.resizeBuffer = resizeBuffer;
|
|
79
|
+
exports.generateRandomHex = generateRandomHex;
|
|
80
|
+
exports.generateRandomBuffer = generateRandomBuffer;
|
|
81
|
+
exports.filterObject = filterObject;
|
|
82
|
+
exports.parseUserAgent = parseUserAgent;
|
|
83
|
+
exports.scheduleJob = scheduleJob;
|
|
84
|
+
exports.scheduleJobs = scheduleJobs;
|
|
85
|
+
exports.checkPasswordComplexity = checkPasswordComplexity;
|
|
86
|
+
exports.checkCommonPassword = checkCommonPassword;
|
|
87
|
+
exports.zipFolder = zipFolder;
|
|
88
|
+
exports.zipFolderStream = zipFolderStream;
|
|
89
|
+
exports.addDirectoryToZip = addDirectoryToZip;
|
|
90
|
+
exports.arrayPushRef = arrayPushRef;
|
|
91
|
+
exports.arrayPushUniq = arrayPushUniq;
|
|
92
|
+
exports.arrayToggle = arrayToggle;
|
|
93
|
+
exports.intersectArrays = intersectArrays;
|
|
94
|
+
exports.intersectArraysBy = intersectArraysBy;
|
|
95
|
+
exports.getLastChild = getLastChild;
|
|
96
|
+
exports.getLastChildren = getLastChildren;
|
|
97
|
+
exports.validDataUrl = validDataUrl;
|
|
17
98
|
const lodash_1 = __importDefault(require("lodash"));
|
|
18
99
|
const moment_1 = __importDefault(require("moment"));
|
|
19
100
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -31,11 +112,9 @@ const mongo_utils_1 = require("./base/mongo-utils");
|
|
|
31
112
|
function devMode() {
|
|
32
113
|
return process.env.NODE_ENV === enums_1.AppMode.DEV;
|
|
33
114
|
}
|
|
34
|
-
exports.devMode = devMode;
|
|
35
115
|
function prodMode() {
|
|
36
116
|
return process.env.NODE_ENV === enums_1.AppMode.PROD;
|
|
37
117
|
}
|
|
38
|
-
exports.prodMode = prodMode;
|
|
39
118
|
/**
|
|
40
119
|
*
|
|
41
120
|
* @param {*} jti
|
|
@@ -57,7 +136,6 @@ function generateJwt(sub, jti, iss, data, signOpts = {}, secret) {
|
|
|
57
136
|
sub, jti, iss, data
|
|
58
137
|
}, secret, signOpts);
|
|
59
138
|
}
|
|
60
|
-
exports.generateJwt = generateJwt;
|
|
61
139
|
/**
|
|
62
140
|
*
|
|
63
141
|
* @param {*} token
|
|
@@ -67,7 +145,6 @@ function validateJwt(token, options = {}, secret) {
|
|
|
67
145
|
secret = process.env.JWT_SECRET;
|
|
68
146
|
return jsonwebtoken_1.default.verify(token, secret, options);
|
|
69
147
|
}
|
|
70
|
-
exports.validateJwt = validateJwt;
|
|
71
148
|
/**
|
|
72
149
|
*
|
|
73
150
|
* @param {*} size
|
|
@@ -77,7 +154,6 @@ function randomString(size = 21) {
|
|
|
77
154
|
.toString('base64')
|
|
78
155
|
.slice(0, size);
|
|
79
156
|
}
|
|
80
|
-
exports.randomString = randomString;
|
|
81
157
|
/**
|
|
82
158
|
*
|
|
83
159
|
* @param {*} a
|
|
@@ -93,7 +169,6 @@ function baseComparator(a, b, key) {
|
|
|
93
169
|
return 1;
|
|
94
170
|
return 0;
|
|
95
171
|
}
|
|
96
|
-
exports.baseComparator = baseComparator;
|
|
97
172
|
/**
|
|
98
173
|
*
|
|
99
174
|
* @param {*} a
|
|
@@ -109,7 +184,6 @@ function baseComparatorReverse(a, b, key) {
|
|
|
109
184
|
return -1;
|
|
110
185
|
return 0;
|
|
111
186
|
}
|
|
112
|
-
exports.baseComparatorReverse = baseComparatorReverse;
|
|
113
187
|
/**
|
|
114
188
|
* Returns if a value is an object
|
|
115
189
|
*
|
|
@@ -118,7 +192,6 @@ exports.baseComparatorReverse = baseComparatorReverse;
|
|
|
118
192
|
function isObject(value) {
|
|
119
193
|
return lodash_1.default.isObject(value);
|
|
120
194
|
}
|
|
121
|
-
exports.isObject = isObject;
|
|
122
195
|
/**
|
|
123
196
|
* Returns if a value is a function
|
|
124
197
|
*
|
|
@@ -127,7 +200,6 @@ exports.isObject = isObject;
|
|
|
127
200
|
function isFunction(value) {
|
|
128
201
|
return lodash_1.default.isFunction(value);
|
|
129
202
|
}
|
|
130
|
-
exports.isFunction = isFunction;
|
|
131
203
|
/**
|
|
132
204
|
* Returns if a value is a date
|
|
133
205
|
*
|
|
@@ -136,7 +208,6 @@ exports.isFunction = isFunction;
|
|
|
136
208
|
function isDate(value) {
|
|
137
209
|
return lodash_1.default.isDate(value);
|
|
138
210
|
}
|
|
139
|
-
exports.isDate = isDate;
|
|
140
211
|
/**
|
|
141
212
|
* Returns if a value is a boolean
|
|
142
213
|
*
|
|
@@ -145,7 +216,6 @@ exports.isDate = isDate;
|
|
|
145
216
|
function isBoolean(value) {
|
|
146
217
|
return lodash_1.default.isBoolean(value);
|
|
147
218
|
}
|
|
148
|
-
exports.isBoolean = isBoolean;
|
|
149
219
|
/**
|
|
150
220
|
* Returns if a value is a string
|
|
151
221
|
*
|
|
@@ -154,7 +224,6 @@ exports.isBoolean = isBoolean;
|
|
|
154
224
|
function isString(value) {
|
|
155
225
|
return lodash_1.default.isString(value);
|
|
156
226
|
}
|
|
157
|
-
exports.isString = isString;
|
|
158
227
|
/**
|
|
159
228
|
* Returns if a value is a number
|
|
160
229
|
*
|
|
@@ -163,7 +232,6 @@ exports.isString = isString;
|
|
|
163
232
|
function isNumber(value) {
|
|
164
233
|
return lodash_1.default.isNumber(value);
|
|
165
234
|
}
|
|
166
|
-
exports.isNumber = isNumber;
|
|
167
235
|
/**
|
|
168
236
|
* Returns if a value is not null and not undefined
|
|
169
237
|
*
|
|
@@ -172,7 +240,6 @@ exports.isNumber = isNumber;
|
|
|
172
240
|
function isNotNull(value) {
|
|
173
241
|
return !lodash_1.default.isNil(value);
|
|
174
242
|
}
|
|
175
|
-
exports.isNotNull = isNotNull;
|
|
176
243
|
/**
|
|
177
244
|
*
|
|
178
245
|
* @param value
|
|
@@ -181,7 +248,6 @@ exports.isNotNull = isNotNull;
|
|
|
181
248
|
function isNil(value) {
|
|
182
249
|
return lodash_1.default.isNil(value);
|
|
183
250
|
}
|
|
184
|
-
exports.isNil = isNil;
|
|
185
251
|
/**
|
|
186
252
|
* Returns if a value is null or undefined
|
|
187
253
|
*
|
|
@@ -190,7 +256,6 @@ exports.isNil = isNil;
|
|
|
190
256
|
function isUndefined(value) {
|
|
191
257
|
return lodash_1.default.isUndefined(value);
|
|
192
258
|
}
|
|
193
|
-
exports.isUndefined = isUndefined;
|
|
194
259
|
/**
|
|
195
260
|
* Returns if a value is defined
|
|
196
261
|
*
|
|
@@ -199,7 +264,6 @@ exports.isUndefined = isUndefined;
|
|
|
199
264
|
function isDefined(value) {
|
|
200
265
|
return !isUndefined(value);
|
|
201
266
|
}
|
|
202
|
-
exports.isDefined = isDefined;
|
|
203
267
|
/**
|
|
204
268
|
*
|
|
205
269
|
* @param {*} v
|
|
@@ -223,7 +287,6 @@ function isBase64(value, opts = {}) {
|
|
|
223
287
|
regex = '(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}(==)?|[A-Za-z0-9+\\/]{3}=?)?';
|
|
224
288
|
return new RegExp('^' + regex + '$', 'gi').test(value);
|
|
225
289
|
}
|
|
226
|
-
exports.isBase64 = isBase64;
|
|
227
290
|
/**
|
|
228
291
|
* Returns if value is a valid email
|
|
229
292
|
*
|
|
@@ -233,7 +296,6 @@ exports.isBase64 = isBase64;
|
|
|
233
296
|
function isEmail(value) {
|
|
234
297
|
return isString(value) && constants_1.REGEX.email.test(value);
|
|
235
298
|
}
|
|
236
|
-
exports.isEmail = isEmail;
|
|
237
299
|
/**
|
|
238
300
|
* Returns true if array contains value
|
|
239
301
|
*
|
|
@@ -242,7 +304,6 @@ exports.isEmail = isEmail;
|
|
|
242
304
|
function contains(arr, value) {
|
|
243
305
|
return Array.isArray(arr) && arr.indexOf(value) !== -1;
|
|
244
306
|
}
|
|
245
|
-
exports.contains = contains;
|
|
246
307
|
/**
|
|
247
308
|
* Returns true if array contains value
|
|
248
309
|
*
|
|
@@ -253,7 +314,6 @@ function containsArrayValue(arr, value) {
|
|
|
253
314
|
return contains(arr, value);
|
|
254
315
|
return value.some(v => contains(arr, v));
|
|
255
316
|
}
|
|
256
|
-
exports.containsArrayValue = containsArrayValue;
|
|
257
317
|
/**
|
|
258
318
|
* Returns true if empty object or array
|
|
259
319
|
*
|
|
@@ -264,7 +324,6 @@ function isEmpty(item) {
|
|
|
264
324
|
return !item.length;
|
|
265
325
|
return !hasKeys(item);
|
|
266
326
|
}
|
|
267
|
-
exports.isEmpty = isEmpty;
|
|
268
327
|
/**
|
|
269
328
|
* Returns true if obj is not empty
|
|
270
329
|
*
|
|
@@ -273,7 +332,6 @@ exports.isEmpty = isEmpty;
|
|
|
273
332
|
function hasKeys(obj) {
|
|
274
333
|
return !!(obj && Object.keys(obj).length);
|
|
275
334
|
}
|
|
276
|
-
exports.hasKeys = hasKeys;
|
|
277
335
|
/**
|
|
278
336
|
*
|
|
279
337
|
* @param {*} key
|
|
@@ -290,7 +348,6 @@ function mergeArraysByKey(key, arrays) {
|
|
|
290
348
|
return acc;
|
|
291
349
|
}, []);
|
|
292
350
|
}
|
|
293
|
-
exports.mergeArraysByKey = mergeArraysByKey;
|
|
294
351
|
/**
|
|
295
352
|
*
|
|
296
353
|
* @param data
|
|
@@ -305,7 +362,6 @@ function findDeep(data, attr, obj) {
|
|
|
305
362
|
return true;
|
|
306
363
|
});
|
|
307
364
|
}
|
|
308
|
-
exports.findDeep = findDeep;
|
|
309
365
|
/**
|
|
310
366
|
* Percentage Difference between two numbers
|
|
311
367
|
*
|
|
@@ -318,7 +374,6 @@ function percentDiff(base, peak, round = false) {
|
|
|
318
374
|
const diff = (peak - base) / base * 100;
|
|
319
375
|
return round ? Math.round(diff) : diff;
|
|
320
376
|
}
|
|
321
|
-
exports.percentDiff = percentDiff;
|
|
322
377
|
;
|
|
323
378
|
/**
|
|
324
379
|
*
|
|
@@ -338,7 +393,6 @@ function dottedKeys(obj) {
|
|
|
338
393
|
});
|
|
339
394
|
return keys;
|
|
340
395
|
}
|
|
341
|
-
exports.dottedKeys = dottedKeys;
|
|
342
396
|
/**
|
|
343
397
|
*
|
|
344
398
|
* @param {*} obj
|
|
@@ -353,7 +407,6 @@ function dotObj(obj) {
|
|
|
353
407
|
});
|
|
354
408
|
return dotted;
|
|
355
409
|
}
|
|
356
|
-
exports.dotObj = dotObj;
|
|
357
410
|
/**
|
|
358
411
|
* json string parsed to object with regex values management
|
|
359
412
|
*
|
|
@@ -362,7 +415,6 @@ exports.dotObj = dotObj;
|
|
|
362
415
|
function strToJson(str) {
|
|
363
416
|
return JSON.parse(str, (k, v) => parseTypedString(v));
|
|
364
417
|
}
|
|
365
|
-
exports.strToJson = strToJson;
|
|
366
418
|
/**
|
|
367
419
|
* json object parsed to string with regex values management
|
|
368
420
|
*
|
|
@@ -371,7 +423,6 @@ exports.strToJson = strToJson;
|
|
|
371
423
|
function jsonToStr(obj) {
|
|
372
424
|
return JSON.stringify(obj, (k, v) => v instanceof RegExp ? `__REXP__${v.toString()}` : v);
|
|
373
425
|
}
|
|
374
|
-
exports.jsonToStr = jsonToStr;
|
|
375
426
|
/**
|
|
376
427
|
* Capitalize first char of string
|
|
377
428
|
* @param text
|
|
@@ -381,7 +432,6 @@ function capitalize(text) {
|
|
|
381
432
|
return '';
|
|
382
433
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
383
434
|
}
|
|
384
|
-
exports.capitalize = capitalize;
|
|
385
435
|
/**
|
|
386
436
|
* Parse string value type coded
|
|
387
437
|
*/
|
|
@@ -405,7 +455,6 @@ function parseTypedString(value) {
|
|
|
405
455
|
match = value.match(new RegExp('^__DATE__/(.*?)/([gimy]*)$'));
|
|
406
456
|
return match ? toDate(match[1]) : value;
|
|
407
457
|
}
|
|
408
|
-
exports.parseTypedString = parseTypedString;
|
|
409
458
|
/**
|
|
410
459
|
*
|
|
411
460
|
* @param {*} period
|
|
@@ -415,7 +464,6 @@ function toFilterDatePeriod(period, year) {
|
|
|
415
464
|
let values = getDatePeriod(period, year);
|
|
416
465
|
return values ? { $gte: values[0], $lt: values[1] } : {};
|
|
417
466
|
}
|
|
418
|
-
exports.toFilterDatePeriod = toFilterDatePeriod;
|
|
419
467
|
/**
|
|
420
468
|
* Returns if string is valid date
|
|
421
469
|
*
|
|
@@ -425,7 +473,6 @@ function isValidDateStr(value, format = 'YYYY-MM-DD') {
|
|
|
425
473
|
const date = toMoment(value);
|
|
426
474
|
return date.isValid() && value === date.format('YYYY-MM-DD');
|
|
427
475
|
}
|
|
428
|
-
exports.isValidDateStr = isValidDateStr;
|
|
429
476
|
/**
|
|
430
477
|
*
|
|
431
478
|
* @param {*} value
|
|
@@ -437,7 +484,6 @@ function toDate(value, format = 'YYYY-MM-DD') {
|
|
|
437
484
|
return value.map(v => toDate(v, format));
|
|
438
485
|
return (value instanceof Date) ? value : toMoment(value, format, true).toDate();
|
|
439
486
|
}
|
|
440
|
-
exports.toDate = toDate;
|
|
441
487
|
/**
|
|
442
488
|
*
|
|
443
489
|
* @param {*} value
|
|
@@ -448,7 +494,6 @@ function toMoment(value, format, utc = false) {
|
|
|
448
494
|
return moment_1.default.utc(value, format);
|
|
449
495
|
return (0, moment_1.default)(value, format);
|
|
450
496
|
}
|
|
451
|
-
exports.toMoment = toMoment;
|
|
452
497
|
/**
|
|
453
498
|
*
|
|
454
499
|
* @param {*} value
|
|
@@ -457,7 +502,6 @@ exports.toMoment = toMoment;
|
|
|
457
502
|
function dateFormat(value, format) {
|
|
458
503
|
return toMoment(value).format(format);
|
|
459
504
|
}
|
|
460
|
-
exports.dateFormat = dateFormat;
|
|
461
505
|
/**
|
|
462
506
|
*
|
|
463
507
|
* @param {*} d1
|
|
@@ -467,7 +511,6 @@ exports.dateFormat = dateFormat;
|
|
|
467
511
|
function getDateDiff(d1, d2, period = 'days') {
|
|
468
512
|
return toMoment(d2).diff(d1, period);
|
|
469
513
|
}
|
|
470
|
-
exports.getDateDiff = getDateDiff;
|
|
471
514
|
/**
|
|
472
515
|
*
|
|
473
516
|
* @param {*} date
|
|
@@ -479,7 +522,6 @@ function getDateValues(date, utc = true) {
|
|
|
479
522
|
date = toMoment(date, undefined, utc);
|
|
480
523
|
return { day: date.date(), month: date.month(), year: date.year() };
|
|
481
524
|
}
|
|
482
|
-
exports.getDateValues = getDateValues;
|
|
483
525
|
/**
|
|
484
526
|
*
|
|
485
527
|
* @param {*} date
|
|
@@ -491,7 +533,6 @@ function getTimeValues(date, utc = true) {
|
|
|
491
533
|
date = toMoment(date, undefined, utc);
|
|
492
534
|
return { hour: date.hour(), minute: date.minute(), seconds: date.seconds() };
|
|
493
535
|
}
|
|
494
|
-
exports.getTimeValues = getTimeValues;
|
|
495
536
|
/**
|
|
496
537
|
*
|
|
497
538
|
* @param {*} period
|
|
@@ -563,7 +604,6 @@ function getDatePeriod(period, year, momentValue = false) {
|
|
|
563
604
|
return values;
|
|
564
605
|
return [values[0].toDate(), values[1].toDate()];
|
|
565
606
|
}
|
|
566
|
-
exports.getDatePeriod = getDatePeriod;
|
|
567
607
|
/**
|
|
568
608
|
*
|
|
569
609
|
* @param {*} value value to be checked
|
|
@@ -571,7 +611,6 @@ exports.getDatePeriod = getDatePeriod;
|
|
|
571
611
|
function uuid(value) {
|
|
572
612
|
return value && (0, uuid_2.validate)(value) ? value : (0, uuid_1.v4)();
|
|
573
613
|
}
|
|
574
|
-
exports.uuid = uuid;
|
|
575
614
|
/**
|
|
576
615
|
*
|
|
577
616
|
* @param {*} obj
|
|
@@ -582,7 +621,6 @@ function logClassCtx(obj, method) {
|
|
|
582
621
|
return {};
|
|
583
622
|
return { context: obj.constructor.name, method };
|
|
584
623
|
}
|
|
585
|
-
exports.logClassCtx = logClassCtx;
|
|
586
624
|
/**
|
|
587
625
|
*
|
|
588
626
|
* @param obj
|
|
@@ -595,7 +633,6 @@ function logMemory(obj, logger = constants_1.APP.logger) {
|
|
|
595
633
|
memStr.push(`${key}: ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`);
|
|
596
634
|
logger.debug(`Memory usage %s`, memStr.join(', '), logClassCtx(obj));
|
|
597
635
|
}
|
|
598
|
-
exports.logMemory = logMemory;
|
|
599
636
|
/**
|
|
600
637
|
*
|
|
601
638
|
* @param logger
|
|
@@ -606,7 +643,6 @@ function forceGC(logger = constants_1.APP.logger) {
|
|
|
606
643
|
else
|
|
607
644
|
logger.warn('No GC hook! Start your program as `node --expose-gc app.js`.');
|
|
608
645
|
}
|
|
609
|
-
exports.forceGC = forceGC;
|
|
610
646
|
/**
|
|
611
647
|
*
|
|
612
648
|
* @param {*} ctx
|
|
@@ -614,7 +650,6 @@ exports.forceGC = forceGC;
|
|
|
614
650
|
function getCtxUser(ctx) {
|
|
615
651
|
return (ctx && ctx.user) ? ctx.user : null;
|
|
616
652
|
}
|
|
617
|
-
exports.getCtxUser = getCtxUser;
|
|
618
653
|
/**
|
|
619
654
|
*
|
|
620
655
|
*/
|
|
@@ -625,7 +660,6 @@ function flattenArray(arr, parseMethod) {
|
|
|
625
660
|
return flat.concat(parseMethod ? parseMethod(toFlatten) : toFlatten);
|
|
626
661
|
}, []);
|
|
627
662
|
}
|
|
628
|
-
exports.flattenArray = flattenArray;
|
|
629
663
|
/**
|
|
630
664
|
*
|
|
631
665
|
* @param {*} obj
|
|
@@ -644,7 +678,6 @@ function deleteKey(obj, path, cloneKey) {
|
|
|
644
678
|
}, _obj);
|
|
645
679
|
return _obj;
|
|
646
680
|
}
|
|
647
|
-
exports.deleteKey = deleteKey;
|
|
648
681
|
/**
|
|
649
682
|
*
|
|
650
683
|
* @param array
|
|
@@ -671,7 +704,6 @@ function sortBy(array, properties) {
|
|
|
671
704
|
return 0;
|
|
672
705
|
});
|
|
673
706
|
}
|
|
674
|
-
exports.sortBy = sortBy;
|
|
675
707
|
/**
|
|
676
708
|
*
|
|
677
709
|
* @param {*} path
|
|
@@ -682,7 +714,6 @@ function readFileSync(path) {
|
|
|
682
714
|
return path;
|
|
683
715
|
return fs_1.default.existsSync(path) ? fs_1.default.readFileSync(path).toString().trim() : '';
|
|
684
716
|
}
|
|
685
|
-
exports.readFileSync = readFileSync;
|
|
686
717
|
/**
|
|
687
718
|
*
|
|
688
719
|
* @param {*} arr1
|
|
@@ -692,7 +723,6 @@ exports.readFileSync = readFileSync;
|
|
|
692
723
|
function union(arr1, arr2) {
|
|
693
724
|
return lodash_1.default.union(arr1, arr2);
|
|
694
725
|
}
|
|
695
|
-
exports.union = union;
|
|
696
726
|
/**
|
|
697
727
|
*
|
|
698
728
|
* @param {*} arr
|
|
@@ -702,7 +732,6 @@ exports.union = union;
|
|
|
702
732
|
function uniqBy(arr, iteratee) {
|
|
703
733
|
return lodash_1.default.uniqBy(arr, iteratee);
|
|
704
734
|
}
|
|
705
|
-
exports.uniqBy = uniqBy;
|
|
706
735
|
/**
|
|
707
736
|
*
|
|
708
737
|
* @param {*} obj1
|
|
@@ -714,7 +743,6 @@ function merge(obj1, obj2, mergeFnc) {
|
|
|
714
743
|
return;
|
|
715
744
|
return mergeFnc ? lodash_1.default.mergeWith(obj1, obj2, mergeFnc) : lodash_1.default.merge(obj1, obj2);
|
|
716
745
|
}
|
|
717
|
-
exports.merge = merge;
|
|
718
746
|
/**
|
|
719
747
|
*
|
|
720
748
|
* @param data
|
|
@@ -724,7 +752,6 @@ function clone(data) {
|
|
|
724
752
|
return;
|
|
725
753
|
return lodash_1.default.cloneDeep(data);
|
|
726
754
|
}
|
|
727
|
-
exports.clone = clone;
|
|
728
755
|
/**
|
|
729
756
|
*
|
|
730
757
|
* @param object
|
|
@@ -733,7 +760,6 @@ exports.clone = clone;
|
|
|
733
760
|
function getAttr(object, path) {
|
|
734
761
|
return lodash_1.default.get(object, path);
|
|
735
762
|
}
|
|
736
|
-
exports.getAttr = getAttr;
|
|
737
763
|
/**
|
|
738
764
|
*
|
|
739
765
|
* @param object
|
|
@@ -743,7 +769,6 @@ exports.getAttr = getAttr;
|
|
|
743
769
|
function setAttr(object, path, value) {
|
|
744
770
|
return lodash_1.default.set(object, path, value);
|
|
745
771
|
}
|
|
746
|
-
exports.setAttr = setAttr;
|
|
747
772
|
/**
|
|
748
773
|
*
|
|
749
774
|
* @param object
|
|
@@ -752,7 +777,6 @@ exports.setAttr = setAttr;
|
|
|
752
777
|
function hasAttr(object, path) {
|
|
753
778
|
return lodash_1.default.has(object, path);
|
|
754
779
|
}
|
|
755
|
-
exports.hasAttr = hasAttr;
|
|
756
780
|
/**
|
|
757
781
|
*
|
|
758
782
|
* @param obj
|
|
@@ -762,7 +786,6 @@ exports.hasAttr = hasAttr;
|
|
|
762
786
|
function hasDefinedAttr(obj, prop) {
|
|
763
787
|
return prop in obj && obj[prop] !== undefined;
|
|
764
788
|
}
|
|
765
|
-
exports.hasDefinedAttr = hasDefinedAttr;
|
|
766
789
|
/**
|
|
767
790
|
*
|
|
768
791
|
* @param value1
|
|
@@ -771,7 +794,6 @@ exports.hasDefinedAttr = hasDefinedAttr;
|
|
|
771
794
|
function isEqual(value1, value2) {
|
|
772
795
|
return lodash_1.default.isEqual(value1, value2);
|
|
773
796
|
}
|
|
774
|
-
exports.isEqual = isEqual;
|
|
775
797
|
/**
|
|
776
798
|
*
|
|
777
799
|
* @param {*} value
|
|
@@ -781,7 +803,6 @@ exports.isEqual = isEqual;
|
|
|
781
803
|
function encodeString(value, from = 'base64', to = 'utf8') {
|
|
782
804
|
return value ? Buffer.from(value, from).toString(to) : value;
|
|
783
805
|
}
|
|
784
|
-
exports.encodeString = encodeString;
|
|
785
806
|
/**
|
|
786
807
|
* Split a string into chunks by specified size
|
|
787
808
|
* @param {String} stringToChunk The string to split
|
|
@@ -794,7 +815,6 @@ function chunkString(stringToChunk, size) {
|
|
|
794
815
|
result = result.concat(chars.slice(i * size, (i + 1) * size).join(''));
|
|
795
816
|
return result;
|
|
796
817
|
}
|
|
797
|
-
exports.chunkString = chunkString;
|
|
798
818
|
/**
|
|
799
819
|
* Initialize an object by a given dot notation structure
|
|
800
820
|
* eg.
|
|
@@ -805,7 +825,6 @@ exports.chunkString = chunkString;
|
|
|
805
825
|
function initObjectFromDotNotation(path, value) {
|
|
806
826
|
return setAttr({}, path, value);
|
|
807
827
|
}
|
|
808
|
-
exports.initObjectFromDotNotation = initObjectFromDotNotation;
|
|
809
828
|
/**
|
|
810
829
|
* Initialize an object with a dot notation property name
|
|
811
830
|
* eg.
|
|
@@ -818,7 +837,6 @@ function initObjectWithProperty(path, value) {
|
|
|
818
837
|
obj[path] = value;
|
|
819
838
|
return obj;
|
|
820
839
|
}
|
|
821
|
-
exports.initObjectWithProperty = initObjectWithProperty;
|
|
822
840
|
/**
|
|
823
841
|
* Resize phrase Buffer by given size
|
|
824
842
|
* @param { Buffer } phrase
|
|
@@ -830,7 +848,6 @@ function resizeBuffer(buffer, size) {
|
|
|
830
848
|
buffer.copy(new Uint8Array(resizedBuffer));
|
|
831
849
|
return resizedBuffer;
|
|
832
850
|
}
|
|
833
|
-
exports.resizeBuffer = resizeBuffer;
|
|
834
851
|
/**
|
|
835
852
|
* Generate a random Hex string (using sha256 HASH Algorithm)
|
|
836
853
|
* @returns { Buffer } Buffer representation of hash
|
|
@@ -838,7 +855,6 @@ exports.resizeBuffer = resizeBuffer;
|
|
|
838
855
|
function generateRandomHex() {
|
|
839
856
|
return crypto_1.default.createHash("sha256").update((0, uuid_1.v4)()).digest();
|
|
840
857
|
}
|
|
841
|
-
exports.generateRandomHex = generateRandomHex;
|
|
842
858
|
/**
|
|
843
859
|
* Generate random buffer of specified size
|
|
844
860
|
* @param { number } bitSize bit size of the buffer
|
|
@@ -849,7 +865,6 @@ function generateRandomBuffer(bitSize) {
|
|
|
849
865
|
const phrase = generateRandomHex();
|
|
850
866
|
return resizeBuffer(phrase, size);
|
|
851
867
|
}
|
|
852
|
-
exports.generateRandomBuffer = generateRandomBuffer;
|
|
853
868
|
/**
|
|
854
869
|
* Use object to filter another object
|
|
855
870
|
* @param {*} obj
|
|
@@ -868,7 +883,6 @@ function filterObject(obj, filterObj) {
|
|
|
868
883
|
}
|
|
869
884
|
return obj;
|
|
870
885
|
}
|
|
871
|
-
exports.filterObject = filterObject;
|
|
872
886
|
/**
|
|
873
887
|
*
|
|
874
888
|
* @param {*} request
|
|
@@ -877,7 +891,6 @@ function parseUserAgent(req) {
|
|
|
877
891
|
const ua = new ua_parser_js_1.default(getAttr(req, 'headers.user-agent'));
|
|
878
892
|
return ua.getResult();
|
|
879
893
|
}
|
|
880
|
-
exports.parseUserAgent = parseUserAgent;
|
|
881
894
|
/**
|
|
882
895
|
*
|
|
883
896
|
* @param {*} rule
|
|
@@ -901,7 +914,6 @@ function scheduleJob(rule, { recurrence, startTime, endTime }, method = () => co
|
|
|
901
914
|
}
|
|
902
915
|
return node_schedule_1.default.scheduleJob(rule, method);
|
|
903
916
|
}
|
|
904
|
-
exports.scheduleJob = scheduleJob;
|
|
905
917
|
/**
|
|
906
918
|
* Schedule multiple jobs.
|
|
907
919
|
* Input rules have following format:
|
|
@@ -925,7 +937,6 @@ function scheduleJobs(rules = []) {
|
|
|
925
937
|
});
|
|
926
938
|
return jobs;
|
|
927
939
|
}
|
|
928
|
-
exports.scheduleJobs = scheduleJobs;
|
|
929
940
|
/**
|
|
930
941
|
* Test password security / complexity criteria
|
|
931
942
|
*
|
|
@@ -935,7 +946,6 @@ exports.scheduleJobs = scheduleJobs;
|
|
|
935
946
|
function checkPasswordComplexity(pwd) {
|
|
936
947
|
return constants_1.REGEX.pwd.test(pwd);
|
|
937
948
|
}
|
|
938
|
-
exports.checkPasswordComplexity = checkPasswordComplexity;
|
|
939
949
|
/**
|
|
940
950
|
* Test password security / complexity criteria
|
|
941
951
|
*
|
|
@@ -945,7 +955,6 @@ exports.checkPasswordComplexity = checkPasswordComplexity;
|
|
|
945
955
|
function checkCommonPassword(commonPwds, pwd) {
|
|
946
956
|
return !commonPwds.some(p => p === pwd);
|
|
947
957
|
}
|
|
948
|
-
exports.checkCommonPassword = checkCommonPassword;
|
|
949
958
|
/**
|
|
950
959
|
* Zip and save a folder
|
|
951
960
|
*
|
|
@@ -962,7 +971,6 @@ function zipFolder(path, name) {
|
|
|
962
971
|
});
|
|
963
972
|
});
|
|
964
973
|
}
|
|
965
|
-
exports.zipFolder = zipFolder;
|
|
966
974
|
/**
|
|
967
975
|
*
|
|
968
976
|
* @param {*} path
|
|
@@ -975,7 +983,6 @@ function zipFolderStream(path, name) {
|
|
|
975
983
|
const zip = addDirectoryToZip(path, name, new jszip_1.default());
|
|
976
984
|
return zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true });
|
|
977
985
|
}
|
|
978
|
-
exports.zipFolderStream = zipFolderStream;
|
|
979
986
|
/**
|
|
980
987
|
* Add files to zip object
|
|
981
988
|
*
|
|
@@ -999,7 +1006,6 @@ function addDirectoryToZip(path, dir, zip) {
|
|
|
999
1006
|
}
|
|
1000
1007
|
return zip;
|
|
1001
1008
|
}
|
|
1002
|
-
exports.addDirectoryToZip = addDirectoryToZip;
|
|
1003
1009
|
/**
|
|
1004
1010
|
* Push in array and return value
|
|
1005
1011
|
*
|
|
@@ -1013,7 +1019,6 @@ function arrayPushRef(arr = [], value) {
|
|
|
1013
1019
|
arr.push(value);
|
|
1014
1020
|
return value;
|
|
1015
1021
|
}
|
|
1016
|
-
exports.arrayPushRef = arrayPushRef;
|
|
1017
1022
|
/**
|
|
1018
1023
|
*
|
|
1019
1024
|
* @param {*} arr
|
|
@@ -1027,7 +1032,6 @@ function arrayPushUniq(arr = [], item, attr) {
|
|
|
1027
1032
|
if (!arr.some(ai => getAttr(ai, attr) === getAttr(item, attr)))
|
|
1028
1033
|
arr.push(item);
|
|
1029
1034
|
}
|
|
1030
|
-
exports.arrayPushUniq = arrayPushUniq;
|
|
1031
1035
|
/**
|
|
1032
1036
|
*
|
|
1033
1037
|
* @param {*} arr
|
|
@@ -1044,7 +1048,6 @@ function arrayToggle(arr = [], item, attr) {
|
|
|
1044
1048
|
else
|
|
1045
1049
|
arr.push(item);
|
|
1046
1050
|
}
|
|
1047
|
-
exports.arrayToggle = arrayToggle;
|
|
1048
1051
|
/**
|
|
1049
1052
|
*
|
|
1050
1053
|
* @param {*} arrays
|
|
@@ -1053,7 +1056,6 @@ exports.arrayToggle = arrayToggle;
|
|
|
1053
1056
|
function intersectArrays(arrays = []) {
|
|
1054
1057
|
return lodash_1.default.intersection(...arrays);
|
|
1055
1058
|
}
|
|
1056
|
-
exports.intersectArrays = intersectArrays;
|
|
1057
1059
|
/**
|
|
1058
1060
|
*
|
|
1059
1061
|
* @param {*} arrays
|
|
@@ -1062,7 +1064,6 @@ exports.intersectArrays = intersectArrays;
|
|
|
1062
1064
|
function intersectArraysBy(arr = [], iteratee) {
|
|
1063
1065
|
return lodash_1.default.intersectionWith(...arr, iteratee);
|
|
1064
1066
|
}
|
|
1065
|
-
exports.intersectArraysBy = intersectArraysBy;
|
|
1066
1067
|
/**
|
|
1067
1068
|
* Get last child in a tree like structure array
|
|
1068
1069
|
* { _id: '', children: [{ _id: '', parent: '', children: [...] }]}
|
|
@@ -1078,7 +1079,6 @@ function getLastChild(item, attr = 'id', arr = []) {
|
|
|
1078
1079
|
const child = arr.find(ai => ai.parent === item[attr]);
|
|
1079
1080
|
return child ? getLastChild(child, attr, arr) : item;
|
|
1080
1081
|
}
|
|
1081
|
-
exports.getLastChild = getLastChild;
|
|
1082
1082
|
/**
|
|
1083
1083
|
* * Get an array with last childern in a tree like structure array
|
|
1084
1084
|
* { _id: '', children: [{ _id: '', parent: '', children: [...] }]}
|
|
@@ -1098,7 +1098,6 @@ function getLastChildren(items, attr = 'id', arr = []) {
|
|
|
1098
1098
|
// const child = arr.filter(ai => ai.parent === item[attr]);
|
|
1099
1099
|
return children.length ? children : items;
|
|
1100
1100
|
}
|
|
1101
|
-
exports.getLastChildren = getLastChildren;
|
|
1102
1101
|
/**
|
|
1103
1102
|
*
|
|
1104
1103
|
* @param {*} str
|
|
@@ -1107,4 +1106,3 @@ exports.getLastChildren = getLastChildren;
|
|
|
1107
1106
|
function validDataUrl(str) {
|
|
1108
1107
|
return constants_1.REGEX.dataurl.test((str || '').trim());
|
|
1109
1108
|
}
|
|
1110
|
-
exports.validDataUrl = validDataUrl;
|