@contrail/util 1.1.11 → 1.1.13

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decompressFromString = exports.compressIntoString = void 0;
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 = void 0;
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.areItemPropertyValuesEqual = exports.determineChangesIfEqual = exports.applyChangesIfEqual = void 0;
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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cloneDeep = void 0;
3
+ exports.cloneDeep = cloneDeep;
4
4
  function cloneDeep(obj) {
5
5
  if (obj === null || obj === undefined)
6
6
  return null;
@@ -13,4 +13,3 @@ function cloneDeep(obj) {
13
13
  return value;
14
14
  });
15
15
  }
16
- exports.cloneDeep = cloneDeep;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getObjectDiff = exports.getObjectDiffs = void 0;
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 = void 0;
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 = void 0;
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,8 +1,6 @@
1
1
  export declare function retainOnlyProperties<T extends Record<string, any>, K extends readonly string[]>(obj: T[], keysToKeep: K, options?: {
2
- shouldDeleteInPlace?: boolean;
3
- shouldSkipKeys?: readonly string[];
2
+ shouldDeleteInPlace: boolean;
4
3
  }): Array<Pick<T, K[number]>>;
5
4
  export declare function retainOnlyProperties<T extends Record<string, any>, K extends readonly string[]>(obj: T, keysToKeep: K, options?: {
6
- shouldDeleteInPlace?: boolean;
7
- shouldSkipKeys?: readonly string[];
5
+ shouldDeleteInPlace: boolean;
8
6
  }): Pick<T, K[number]>;
@@ -1,13 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.retainOnlyProperties = void 0;
3
+ exports.retainOnlyProperties = retainOnlyProperties;
4
4
  const object_util_1 = require("../object-util");
5
- function retainOnlyProperties(obj, keysToKeep, options = {
6
- shouldDeleteInPlace: false,
7
- shouldSkipKeys: [],
8
- }) {
5
+ function retainOnlyProperties(obj, keysToKeep, options = { shouldDeleteInPlace: false }) {
9
6
  const keepSet = new Set(keysToKeep);
10
- const skipSet = new Set(options.shouldSkipKeys || []);
11
7
  const shouldReturnAsIs = (value) => value === null || value === undefined || typeof value !== 'object' || value instanceof Date;
12
8
  const retain = (target) => {
13
9
  if (shouldReturnAsIs(target))
@@ -16,9 +12,6 @@ function retainOnlyProperties(obj, keysToKeep, options = {
16
12
  return target.map(retain);
17
13
  }
18
14
  for (const key in target) {
19
- if (skipSet.has(key)) {
20
- continue;
21
- }
22
15
  if (!keepSet.has(key)) {
23
16
  delete target[key];
24
17
  }
@@ -29,7 +22,5 @@ function retainOnlyProperties(obj, keysToKeep, options = {
29
22
  return target;
30
23
  };
31
24
  const objToModify = options.shouldDeleteInPlace ? obj : object_util_1.ObjectUtil.cloneDeep(obj);
32
- const toRetain = retain(objToModify);
33
- return toRetain;
25
+ return retain(objToModify);
34
26
  }
35
- exports.retainOnlyProperties = retainOnlyProperties;
@@ -1,4 +1,4 @@
1
1
  export declare class PromiseUtil {
2
- static resolveInChunks(objects: Array<any>, chunksSize: number, asyncFunction: (chunk: any) => Promise<any>): Promise<any>;
3
- static resolveInChunksAndLimit(objects: Array<any>, chunksSize: number, limitSize: number, asyncFunction: (chunk: any) => Promise<any>): Promise<any>;
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
- const chunks = (0, lodash_1.chunk)(objects, chunksSize);
18
- const promises = [];
19
- for (const chunk of chunks) {
20
- promises.push(asyncFunction(chunk));
21
- }
22
- return Promise.all(promises).then((chunkedResults) => chunkedResults.flat());
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
- const limit = (0, p_limit_1.default)(limitSize);
26
- const chunks = (0, lodash_1.chunk)(objects, chunksSize);
27
- const promises = [];
28
- for (const chunk of chunks) {
29
- const promise = limit(() => __awaiter(this, void 0, void 0, function* () {
30
- return yield asyncFunction(chunk);
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 = void 0;
12
+ exports.retry = retry;
13
13
  const DEFAULT_CONFIG = {
14
14
  maxRetries: 3,
15
15
  initialDelay: 1000,
16
16
  };
17
- function retry(fn, config = DEFAULT_CONFIG) {
18
- return __awaiter(this, void 0, void 0, function* () {
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): boolean;
7
- static isArray(value: any): boolean;
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.delay = exports.TimerManager = exports.Timer = exports.TimeUnit = void 0;
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 = exports.TimeUnit || (exports.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.11",
3
+ "version": "1.1.13",
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": "^4.0.0"
25
+ "typescript": "^5.8.3"
25
26
  },
26
27
  "jest": {
27
28
  "moduleFileExtensions": [