@contrail/util 1.1.12 → 1.1.14-alpha
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/lib/compression-util/compression.js +2 -3
- package/lib/date-util/getIsoDatePart/getIsoDatePart.js +1 -2
- package/lib/object-util/applyChangesIfEqual/applyChangesIfEqual.js +3 -4
- package/lib/object-util/cloneDeep/cloneDeep.d.ts +3 -1
- package/lib/object-util/cloneDeep/cloneDeep.js +8 -13
- package/lib/object-util/compareDeep/compareDeep.js +2 -3
- package/lib/object-util/isObject/isObject.js +1 -2
- package/lib/object-util/mergeDeep/mergeDeep.js +1 -2
- package/lib/object-util/retainOnlyProperties/retainOnlyProperties.js +1 -2
- package/lib/promise-util/promise-util.d.ts +2 -2
- package/lib/promise-util/promise-util.js +13 -16
- package/lib/retry-util/retry-util.js +3 -4
- package/lib/string-util/string-util.d.ts +2 -2
- package/lib/timer-util/timer-util.js +3 -3
- package/package.json +5 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.compressIntoString = compressIntoString;
|
|
4
|
+
exports.decompressFromString = decompressFromString;
|
|
4
5
|
const fflate_1 = require("fflate");
|
|
5
6
|
function compressIntoString(obj) {
|
|
6
7
|
const jsonStr = JSON.stringify(obj === undefined ? null : obj);
|
|
@@ -12,7 +13,6 @@ function compressIntoString(obj) {
|
|
|
12
13
|
const compressed = (0, fflate_1.compressSync)(buffer);
|
|
13
14
|
return Buffer.from(compressed).toString('base64');
|
|
14
15
|
}
|
|
15
|
-
exports.compressIntoString = compressIntoString;
|
|
16
16
|
function decompressFromString(str) {
|
|
17
17
|
if (typeof Buffer === 'undefined') {
|
|
18
18
|
console.warn('Buffer is not available. Decompression will be skipped. Returning original string.');
|
|
@@ -23,4 +23,3 @@ function decompressFromString(str) {
|
|
|
23
23
|
const originalText = new TextDecoder().decode(decompressed);
|
|
24
24
|
return JSON.parse(originalText);
|
|
25
25
|
}
|
|
26
|
-
exports.decompressFromString = decompressFromString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getIsoDatePart =
|
|
3
|
+
exports.getIsoDatePart = getIsoDatePart;
|
|
4
4
|
function getIsoDatePart(date) {
|
|
5
5
|
console.log('date 1: ', date.toISOString(), '\n\n\n\n\n\n\n\n');
|
|
6
6
|
let d = new Date(date);
|
|
@@ -14,4 +14,3 @@ function getIsoDatePart(date) {
|
|
|
14
14
|
}
|
|
15
15
|
return [year, month, day].join('-');
|
|
16
16
|
}
|
|
17
|
-
exports.getIsoDatePart = getIsoDatePart;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.applyChangesIfEqual = applyChangesIfEqual;
|
|
4
|
+
exports.determineChangesIfEqual = determineChangesIfEqual;
|
|
5
|
+
exports.areItemPropertyValuesEqual = areItemPropertyValuesEqual;
|
|
4
6
|
const types_1 = require("@contrail/types");
|
|
5
7
|
const compareDeep_1 = require("../compareDeep/compareDeep");
|
|
6
8
|
function applyChangesIfEqual(target, priorSourceValues, newSourceValues, properties) {
|
|
@@ -9,7 +11,6 @@ function applyChangesIfEqual(target, priorSourceValues, newSourceValues, propert
|
|
|
9
11
|
Object.assign(target, changes);
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
|
-
exports.applyChangesIfEqual = applyChangesIfEqual;
|
|
13
14
|
function determineChangesIfEqual(target, priorSourceValues, newSourceValues, properties) {
|
|
14
15
|
const changes = {};
|
|
15
16
|
for (const property of properties) {
|
|
@@ -26,7 +27,6 @@ function determineChangesIfEqual(target, priorSourceValues, newSourceValues, pro
|
|
|
26
27
|
}
|
|
27
28
|
return changes;
|
|
28
29
|
}
|
|
29
|
-
exports.determineChangesIfEqual = determineChangesIfEqual;
|
|
30
30
|
function areItemPropertyValuesEqual(property, itemOne, itemTwo) {
|
|
31
31
|
var _a, _b, _c, _d;
|
|
32
32
|
const propertyKey = getPropertyKey(property);
|
|
@@ -45,7 +45,6 @@ function areItemPropertyValuesEqual(property, itemOne, itemTwo) {
|
|
|
45
45
|
}
|
|
46
46
|
return propertyValueOne === propertyValueTwo;
|
|
47
47
|
}
|
|
48
|
-
exports.areItemPropertyValuesEqual = areItemPropertyValuesEqual;
|
|
49
48
|
function areSizeRangesEqual(sizeRangeOne, sizeRangeTwo) {
|
|
50
49
|
var _a, _b;
|
|
51
50
|
if (!sizeRangeOne && !sizeRangeTwo) {
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cloneDeep = void 0;
|
|
4
|
-
function cloneDeep(obj) {
|
|
5
|
-
if (obj === null || obj === undefined)
|
|
6
|
-
return null;
|
|
7
|
-
return JSON.parse(JSON.stringify(obj), (_key, value) => {
|
|
8
|
-
if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(value)) {
|
|
9
|
-
const date = new Date(value);
|
|
10
|
-
if (!isNaN(date.getTime()))
|
|
11
|
-
return date;
|
|
12
|
-
}
|
|
13
|
-
return value;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
3
|
exports.cloneDeep = cloneDeep;
|
|
4
|
+
const cloneDefault = require('rfdc')();
|
|
5
|
+
const cloneWithCircles = require('rfdc')({ circles: true });
|
|
6
|
+
function cloneDeep(obj, options) {
|
|
7
|
+
var _a;
|
|
8
|
+
const shouldPreserveCircles = (_a = options === null || options === void 0 ? void 0 : options.shouldPreserveCircularReferences) !== null && _a !== void 0 ? _a : false;
|
|
9
|
+
const clone = shouldPreserveCircles ? cloneWithCircles : cloneDefault;
|
|
10
|
+
return clone(obj);
|
|
11
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getObjectDiffs = getObjectDiffs;
|
|
4
|
+
exports.getObjectDiff = getObjectDiff;
|
|
4
5
|
function getObjectDiffs(before, after, prefix) {
|
|
5
6
|
const diffs = [];
|
|
6
7
|
if (!before || !after) {
|
|
@@ -67,7 +68,6 @@ function getObjectDiffs(before, after, prefix) {
|
|
|
67
68
|
});
|
|
68
69
|
return diffs;
|
|
69
70
|
}
|
|
70
|
-
exports.getObjectDiffs = getObjectDiffs;
|
|
71
71
|
function getObjectDiff(before, after, name) {
|
|
72
72
|
const diff = {
|
|
73
73
|
propertyName: name,
|
|
@@ -76,7 +76,6 @@ function getObjectDiff(before, after, name) {
|
|
|
76
76
|
};
|
|
77
77
|
return diff;
|
|
78
78
|
}
|
|
79
|
-
exports.getObjectDiff = getObjectDiff;
|
|
80
79
|
function sortFunc(x, y) {
|
|
81
80
|
const pre = ['string', 'number', 'bool'];
|
|
82
81
|
if (typeof x !== typeof y)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isObject =
|
|
3
|
+
exports.isObject = isObject;
|
|
4
4
|
function isObject(item) {
|
|
5
5
|
return item && typeof item === 'object' && !Array.isArray(item);
|
|
6
6
|
}
|
|
7
|
-
exports.isObject = isObject;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeDeep =
|
|
3
|
+
exports.mergeDeep = mergeDeep;
|
|
4
4
|
const isObject_1 = require("../isObject/isObject");
|
|
5
5
|
function mergeDeep(target, ...sources) {
|
|
6
6
|
if (!sources.length)
|
|
@@ -20,7 +20,6 @@ function mergeDeep(target, ...sources) {
|
|
|
20
20
|
}
|
|
21
21
|
return mergeDeep(target, ...sources);
|
|
22
22
|
}
|
|
23
|
-
exports.mergeDeep = mergeDeep;
|
|
24
23
|
function isDate(object) {
|
|
25
24
|
return object != null && object instanceof Date;
|
|
26
25
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.retainOnlyProperties =
|
|
3
|
+
exports.retainOnlyProperties = retainOnlyProperties;
|
|
4
4
|
const object_util_1 = require("../object-util");
|
|
5
5
|
function retainOnlyProperties(obj, keysToKeep, options = {}) {
|
|
6
6
|
const keepSet = new Set(keysToKeep);
|
|
@@ -28,4 +28,3 @@ function retainOnlyProperties(obj, keysToKeep, options = {}) {
|
|
|
28
28
|
const objToModify = options.shouldDeleteInPlace ? obj : object_util_1.ObjectUtil.cloneDeep(obj);
|
|
29
29
|
return retain(objToModify);
|
|
30
30
|
}
|
|
31
|
-
exports.retainOnlyProperties = retainOnlyProperties;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare class PromiseUtil {
|
|
2
|
-
static resolveInChunks(objects: Array<
|
|
3
|
-
static resolveInChunksAndLimit(objects: Array<
|
|
2
|
+
static resolveInChunks<TInput, TOutput>(objects: Array<TInput>, chunksSize: number, asyncFunction: (chunk: TInput[]) => Promise<TOutput[]>): Promise<TOutput[]>;
|
|
3
|
+
static resolveInChunksAndLimit<TInput, TOutput>(objects: Array<TInput>, chunksSize: number, limitSize: number, asyncFunction: (chunk: TInput[]) => Promise<TOutput[]>): Promise<TOutput[]>;
|
|
4
4
|
}
|
|
@@ -14,24 +14,21 @@ const p_limit_1 = require("p-limit");
|
|
|
14
14
|
const lodash_1 = require("lodash");
|
|
15
15
|
class PromiseUtil {
|
|
16
16
|
static resolveInChunks(objects, chunksSize, asyncFunction) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const chunks = (0, lodash_1.chunk)(objects, chunksSize);
|
|
19
|
+
const promises = chunks.map((chunk) => asyncFunction(chunk));
|
|
20
|
+
const chunkedResults = yield Promise.all(promises);
|
|
21
|
+
return chunkedResults.flat();
|
|
22
|
+
});
|
|
23
23
|
}
|
|
24
24
|
static resolveInChunksAndLimit(objects, chunksSize, limitSize, asyncFunction) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
promises.push(promise);
|
|
33
|
-
}
|
|
34
|
-
return Promise.all(promises).then((chunkedResults) => chunkedResults.flat());
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const limit = (0, p_limit_1.default)(limitSize);
|
|
27
|
+
const chunks = (0, lodash_1.chunk)(objects, chunksSize);
|
|
28
|
+
const promises = chunks.map((chunk) => limit(() => __awaiter(this, void 0, void 0, function* () { return asyncFunction(chunk); })));
|
|
29
|
+
const chunkedResults = yield Promise.all(promises);
|
|
30
|
+
return chunkedResults.flat();
|
|
31
|
+
});
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
exports.PromiseUtil = PromiseUtil;
|
|
@@ -9,13 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.retry =
|
|
12
|
+
exports.retry = retry;
|
|
13
13
|
const DEFAULT_CONFIG = {
|
|
14
14
|
maxRetries: 3,
|
|
15
15
|
initialDelay: 1000,
|
|
16
16
|
};
|
|
17
|
-
function retry(
|
|
18
|
-
return __awaiter(this,
|
|
17
|
+
function retry(fn_1) {
|
|
18
|
+
return __awaiter(this, arguments, void 0, function* (fn, config = DEFAULT_CONFIG) {
|
|
19
19
|
const { maxRetries, initialDelay, onRetryCallback } = Object.assign(Object.assign({}, DEFAULT_CONFIG), config);
|
|
20
20
|
if (maxRetries < 1) {
|
|
21
21
|
throw new Error('maxRetries must be at least 1');
|
|
@@ -39,4 +39,3 @@ function retry(fn, config = DEFAULT_CONFIG) {
|
|
|
39
39
|
throw new Error('Max retries reached');
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
exports.retry = retry;
|
|
@@ -3,8 +3,8 @@ export declare class StringUtil {
|
|
|
3
3
|
static parseVariables(variableString: string, data: any, quoteStrings?: boolean): string;
|
|
4
4
|
static convertToCamelCase(str: any): any;
|
|
5
5
|
static convertToTitleCase(str: any): any;
|
|
6
|
-
static isString(value: any):
|
|
7
|
-
static isArray(value: any):
|
|
6
|
+
static isString(value: any): value is string | String;
|
|
7
|
+
static isArray(value: any): value is any[];
|
|
8
8
|
static decodeEncodedString(encodedString: string): string;
|
|
9
9
|
static getStringSizeInMB(str: string): number;
|
|
10
10
|
}
|
|
@@ -9,12 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.TimerManager = exports.Timer = exports.TimeUnit = void 0;
|
|
13
|
+
exports.delay = delay;
|
|
13
14
|
var TimeUnit;
|
|
14
15
|
(function (TimeUnit) {
|
|
15
16
|
TimeUnit["MILLISECOND"] = "ms";
|
|
16
17
|
TimeUnit["SECOND"] = "s";
|
|
17
|
-
})(TimeUnit
|
|
18
|
+
})(TimeUnit || (exports.TimeUnit = TimeUnit = {}));
|
|
18
19
|
const MILLISECONDS_PER_TIME_UNIT = {
|
|
19
20
|
[TimeUnit.MILLISECOND]: 1,
|
|
20
21
|
[TimeUnit.SECOND]: 1000,
|
|
@@ -116,4 +117,3 @@ function delay(ms) {
|
|
|
116
117
|
});
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
|
-
exports.delay = delay;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/util",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14-alpha",
|
|
4
4
|
"description": "General javascript utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -16,12 +16,13 @@
|
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/jest": "^23.3.14",
|
|
19
|
+
"@types/lodash": "^4.17.17",
|
|
19
20
|
"jest": "^29.3.1",
|
|
20
21
|
"prettier": "^3.2.5",
|
|
21
22
|
"ts-jest": "^29.0.3",
|
|
22
23
|
"tslint": "^5.11.0",
|
|
23
24
|
"tslint-config-prettier": "^1.18.0",
|
|
24
|
-
"typescript": "^
|
|
25
|
+
"typescript": "^5.8.3"
|
|
25
26
|
},
|
|
26
27
|
"jest": {
|
|
27
28
|
"moduleFileExtensions": [
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@contrail/types": "^3.0.95",
|
|
42
43
|
"fflate": "^0.8.2",
|
|
43
|
-
"lodash": "^4.17.21"
|
|
44
|
+
"lodash": "^4.17.21",
|
|
45
|
+
"rfdc": "^1.4.1"
|
|
44
46
|
}
|
|
45
47
|
}
|