@augment-vir/common 29.2.0 → 30.0.0
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/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/dist/augments/array/array-map.d.ts +6 -0
- package/dist/augments/array/array-map.js +4 -0
- package/dist/augments/array/array-to-object.d.ts +17 -0
- package/dist/augments/array/array-to-object.js +31 -0
- package/dist/augments/array/awaited/awaited-filter.d.ts +7 -0
- package/dist/augments/array/awaited/awaited-filter.js +7 -0
- package/dist/augments/array/awaited/awaited-for-each.d.ts +6 -0
- package/dist/augments/array/awaited/awaited-for-each.js +9 -0
- package/dist/augments/array/awaited/awaited-map.d.ts +1 -0
- package/dist/augments/array/awaited/awaited-map.js +8 -0
- package/dist/augments/array/filter.d.ts +3 -0
- package/dist/augments/array/filter.js +13 -0
- package/dist/augments/array/repeat-array.d.ts +1 -0
- package/dist/augments/array/repeat-array.js +3 -0
- package/dist/augments/array/shuffle-array.d.ts +2 -0
- package/dist/augments/array/shuffle-array.js +10 -0
- package/dist/augments/array/string-array.d.ts +1 -0
- package/dist/augments/array/string-array.js +3 -0
- package/dist/augments/boolean/if-truthy.d.ts +2 -0
- package/dist/{esm/augments/boolean.js → augments/boolean/if-truthy.js} +2 -7
- package/dist/augments/core-exports.d.ts +1 -0
- package/dist/augments/core-exports.js +1 -0
- package/dist/augments/enum/enum-value-check.d.ts +2 -0
- package/dist/augments/enum/enum-value-check.js +4 -0
- package/dist/augments/error/combine-errors.d.ts +3 -0
- package/dist/augments/error/combine-errors.js +12 -0
- package/dist/augments/function/call-asynchronously.d.ts +6 -0
- package/dist/augments/function/call-asynchronously.js +7 -0
- package/dist/augments/function/call-with-retries.d.ts +4 -0
- package/dist/augments/function/call-with-retries.js +27 -0
- package/dist/augments/function/debounce.d.ts +22 -0
- package/dist/augments/function/debounce.js +50 -0
- package/dist/augments/function/execution-duration.d.ts +8 -0
- package/dist/{esm/augments/time.js → augments/function/execution-duration.js} +7 -12
- package/dist/{types/augments → augments/function}/wrap-in-try.d.ts +2 -3
- package/dist/{esm/augments → augments/function}/wrap-in-try.js +4 -4
- package/dist/augments/json/append-json.d.ts +5 -0
- package/dist/augments/json/append-json.js +26 -0
- package/dist/augments/json/copy-through-json.d.ts +3 -0
- package/dist/augments/json/copy-through-json.js +11 -0
- package/dist/augments/json/jsonify.d.ts +2 -0
- package/dist/augments/json/jsonify.js +4 -0
- package/dist/augments/log/log-colors.d.ts +23 -0
- package/dist/augments/log/log-colors.js +116 -0
- package/dist/augments/log/log-string.d.ts +14 -0
- package/dist/augments/log/log-string.js +66 -0
- package/dist/augments/log/log-writer.d.ts +8 -0
- package/dist/augments/log/log.d.ts +13 -0
- package/dist/augments/log/log.js +42 -0
- package/dist/augments/log/logger.d.ts +11 -0
- package/dist/augments/log/logger.js +38 -0
- package/dist/augments/number/clamp.d.ts +7 -0
- package/dist/augments/number/clamp.js +8 -0
- package/dist/augments/number/coords.d.ts +19 -0
- package/dist/augments/number/digit.d.ts +1 -0
- package/dist/augments/number/dimensions.d.ts +19 -0
- package/dist/augments/number/min-max.d.ts +11 -0
- package/dist/augments/number/min-max.js +14 -0
- package/dist/augments/number/number-conversion.d.ts +23 -0
- package/dist/augments/number/number-conversion.js +50 -0
- package/dist/augments/number/round.d.ts +3 -0
- package/dist/augments/number/round.js +5 -0
- package/dist/augments/number/scientific.d.ts +1 -0
- package/dist/augments/number/scientific.js +3 -0
- package/dist/{esm/augments → augments/number}/truncate-number.js +14 -12
- package/dist/augments/number/wrap-number.d.ts +13 -0
- package/dist/augments/number/wrap-number.js +22 -0
- package/dist/augments/object/diff.d.ts +29 -0
- package/dist/augments/object/diff.js +133 -0
- package/dist/augments/object/empty.d.ts +3 -0
- package/dist/augments/object/get-or-set.d.ts +31 -0
- package/dist/{esm/augments → augments}/object/get-or-set.js +5 -3
- package/dist/{types/augments → augments}/object/key-count.d.ts +9 -5
- package/dist/augments/object/map-entries.d.ts +13 -0
- package/dist/augments/object/map-entries.js +57 -0
- package/dist/augments/object/map-enum.d.ts +4 -0
- package/dist/augments/object/map-enum.js +21 -0
- package/dist/{types/augments/object/map-object.d.ts → augments/object/map-values.d.ts} +6 -3
- package/dist/{esm/augments/object/map-object.js → augments/object/map-values.js} +9 -9
- package/dist/{esm/augments → augments}/object/merge-deep.js +5 -6
- package/dist/augments/object/merge-defined-properties.d.ts +6 -0
- package/dist/augments/object/merge-defined-properties.js +19 -0
- package/dist/{esm/augments → augments}/object/merge-property-arrays.js +1 -1
- package/dist/augments/object/object-entries.d.ts +4 -0
- package/dist/augments/object/object-entries.js +13 -0
- package/dist/augments/object/object-filter.d.ts +2 -0
- package/dist/augments/object/object-filter.js +7 -0
- package/dist/augments/object/object-keys.d.ts +2 -0
- package/dist/augments/object/object-keys.js +11 -0
- package/dist/augments/object/object-values.d.ts +2 -0
- package/dist/augments/object/object-values.js +4 -0
- package/dist/augments/prisma/prisma-models.d.ts +106 -0
- package/dist/augments/prisma/prisma-models.js +1 -0
- package/dist/augments/promise/timed-promise.d.ts +7 -0
- package/dist/augments/promise/timed-promise.js +36 -0
- package/dist/augments/random/random-boolean.d.ts +18 -0
- package/dist/augments/random/random-boolean.js +26 -0
- package/dist/augments/random/random-integer.d.ts +12 -0
- package/dist/augments/random/random-integer.js +32 -0
- package/dist/augments/random/random-string.d.ts +14 -0
- package/dist/augments/random/random-string.js +63 -0
- package/dist/{types/augments/regexp.d.ts → augments/regexp/regexp-flags.d.ts} +1 -1
- package/dist/augments/regexp/regexp-flags.js +18 -0
- package/dist/augments/regexp/regexp-string.d.ts +5 -0
- package/dist/augments/regexp/regexp-string.js +7 -0
- package/dist/augments/regexp/safe-match.d.ts +1 -0
- package/dist/augments/regexp/safe-match.js +4 -0
- package/dist/augments/selection-set/select-collapsed.d.ts +11 -0
- package/dist/augments/selection-set/select-collapsed.js +25 -0
- package/dist/augments/selection-set/select-from.d.ts +3 -0
- package/dist/augments/selection-set/select-from.js +25 -0
- package/dist/augments/selection-set/selection-set.d.ts +18 -0
- package/dist/augments/selection-set/selection-set.js +4 -0
- package/dist/augments/string/casing/capitalization.d.ts +3 -0
- package/dist/augments/string/casing/capitalization.js +11 -0
- package/dist/augments/string/casing/casing.d.ts +27 -0
- package/dist/augments/string/casing/casing.js +40 -0
- package/dist/augments/string/casing/kebab-and-camel.d.ts +3 -0
- package/dist/augments/string/casing/kebab-and-camel.js +42 -0
- package/dist/augments/string/commas.d.ts +7 -0
- package/dist/augments/string/commas.js +29 -0
- package/dist/augments/string/join.d.ts +10 -0
- package/dist/augments/string/join.js +23 -0
- package/dist/{types/augments/string/prefixes.d.ts → augments/string/prefix.d.ts} +16 -1
- package/dist/{esm/augments/string/prefixes.js → augments/string/prefix.js} +11 -1
- package/dist/augments/string/replace.d.ts +1 -0
- package/dist/augments/string/replace.js +5 -0
- package/dist/augments/string/split.d.ts +4 -0
- package/dist/augments/string/split.js +28 -0
- package/dist/augments/string/substring-index.d.ts +13 -0
- package/dist/augments/string/substring-index.js +38 -0
- package/dist/augments/string/suffix.d.ts +74 -0
- package/dist/augments/string/suffix.js +73 -0
- package/dist/augments/string/white-space.d.ts +5 -0
- package/dist/augments/string/white-space.js +12 -0
- package/dist/augments/string/wrap-string.d.ts +4 -0
- package/dist/augments/string/wrap-string.js +5 -0
- package/dist/augments/type/ensure-type.d.ts +8 -0
- package/dist/augments/type/ensure-type.js +10 -0
- package/dist/augments/type/readonly.d.ts +2 -0
- package/dist/augments/type/readonly.js +3 -0
- package/dist/augments/type/type-recursion.js +1 -0
- package/dist/augments/type/void-type.d.ts +5 -0
- package/dist/augments/type/void-type.js +1 -0
- package/dist/augments/type/writable.d.ts +3 -0
- package/dist/augments/type/writable.js +3 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.js +81 -0
- package/package.json +33 -15
- package/README.md +0 -7
- package/dist/cjs/augments/ansi.js +0 -27
- package/dist/cjs/augments/array/array.js +0 -68
- package/dist/cjs/augments/array/remove-duplicates.js +0 -16
- package/dist/cjs/augments/async.js +0 -28
- package/dist/cjs/augments/boolean.js +0 -19
- package/dist/cjs/augments/common-number.js +0 -112
- package/dist/cjs/augments/common-string.js +0 -245
- package/dist/cjs/augments/debounce.js +0 -38
- package/dist/cjs/augments/environment.js +0 -6
- package/dist/cjs/augments/error.js +0 -52
- package/dist/cjs/augments/esm-path.js +0 -11
- package/dist/cjs/augments/function.js +0 -2
- package/dist/cjs/augments/json-compatible.js +0 -2
- package/dist/cjs/augments/json.js +0 -28
- package/dist/cjs/augments/object/any-object.js +0 -2
- package/dist/cjs/augments/object/enum.js +0 -48
- package/dist/cjs/augments/object/filter-object.js +0 -26
- package/dist/cjs/augments/object/get-or-set.js +0 -40
- package/dist/cjs/augments/object/has-key.js +0 -6
- package/dist/cjs/augments/object/jsonify.js +0 -6
- package/dist/cjs/augments/object/key-count.js +0 -2
- package/dist/cjs/augments/object/map-object.js +0 -61
- package/dist/cjs/augments/object/merge-deep.js +0 -52
- package/dist/cjs/augments/object/merge-property-arrays.js +0 -14
- package/dist/cjs/augments/object/object-entries.js +0 -40
- package/dist/cjs/augments/object/object.js +0 -18
- package/dist/cjs/augments/object/pick-deep.js +0 -2
- package/dist/cjs/augments/object/selection-set.js +0 -56
- package/dist/cjs/augments/object/typed-has-property.js +0 -29
- package/dist/cjs/augments/promise/deferred-promise.js +0 -31
- package/dist/cjs/augments/promise/promise.js +0 -79
- package/dist/cjs/augments/promise/wait.js +0 -66
- package/dist/cjs/augments/random.js +0 -123
- package/dist/cjs/augments/regexp.js +0 -19
- package/dist/cjs/augments/string/prefixes.js +0 -20
- package/dist/cjs/augments/string/suffixes.js +0 -40
- package/dist/cjs/augments/string/uuid.js +0 -7
- package/dist/cjs/augments/time.js +0 -35
- package/dist/cjs/augments/truncate-number.js +0 -153
- package/dist/cjs/augments/tuple.js +0 -20
- package/dist/cjs/augments/type-recursion.js +0 -2
- package/dist/cjs/augments/type.js +0 -36
- package/dist/cjs/augments/union.js +0 -2
- package/dist/cjs/augments/wrap-in-try.js +0 -37
- package/dist/cjs/index.js +0 -60
- package/dist/esm/augments/ansi.js +0 -24
- package/dist/esm/augments/array/array.js +0 -57
- package/dist/esm/augments/async.js +0 -23
- package/dist/esm/augments/common-number.js +0 -100
- package/dist/esm/augments/common-string.js +0 -227
- package/dist/esm/augments/debounce.js +0 -34
- package/dist/esm/augments/environment.js +0 -3
- package/dist/esm/augments/error.js +0 -45
- package/dist/esm/augments/json.js +0 -24
- package/dist/esm/augments/object/enum.js +0 -41
- package/dist/esm/augments/object/filter-object.js +0 -21
- package/dist/esm/augments/object/has-key.js +0 -3
- package/dist/esm/augments/object/jsonify.js +0 -3
- package/dist/esm/augments/object/object-entries.js +0 -32
- package/dist/esm/augments/object/object.js +0 -14
- package/dist/esm/augments/object/selection-set.js +0 -52
- package/dist/esm/augments/object/typed-has-property.js +0 -25
- package/dist/esm/augments/promise/deferred-promise.js +0 -28
- package/dist/esm/augments/promise/promise.js +0 -71
- package/dist/esm/augments/promise/wait.js +0 -60
- package/dist/esm/augments/random.js +0 -117
- package/dist/esm/augments/regexp.js +0 -14
- package/dist/esm/augments/string/suffixes.js +0 -31
- package/dist/esm/augments/string/uuid.js +0 -4
- package/dist/esm/augments/tuple.js +0 -16
- package/dist/esm/augments/type.js +0 -30
- package/dist/esm/index.js +0 -44
- package/dist/types/augments/ansi.d.ts +0 -1
- package/dist/types/augments/array/array.d.ts +0 -26
- package/dist/types/augments/async.d.ts +0 -14
- package/dist/types/augments/boolean.d.ts +0 -6
- package/dist/types/augments/common-number.d.ts +0 -52
- package/dist/types/augments/common-string.d.ts +0 -74
- package/dist/types/augments/debounce.d.ts +0 -15
- package/dist/types/augments/environment.d.ts +0 -1
- package/dist/types/augments/error.d.ts +0 -9
- package/dist/types/augments/function.d.ts +0 -25
- package/dist/types/augments/json.d.ts +0 -9
- package/dist/types/augments/object/any-object.d.ts +0 -2
- package/dist/types/augments/object/enum.d.ts +0 -8
- package/dist/types/augments/object/filter-object.d.ts +0 -4
- package/dist/types/augments/object/get-or-set.d.ts +0 -26
- package/dist/types/augments/object/has-key.d.ts +0 -1
- package/dist/types/augments/object/jsonify.d.ts +0 -2
- package/dist/types/augments/object/object-entries.d.ts +0 -8
- package/dist/types/augments/object/object.d.ts +0 -21
- package/dist/types/augments/object/pick-deep.d.ts +0 -14
- package/dist/types/augments/object/selection-set.d.ts +0 -27
- package/dist/types/augments/object/typed-has-property.d.ts +0 -7
- package/dist/types/augments/promise/deferred-promise.d.ts +0 -8
- package/dist/types/augments/promise/promise.d.ts +0 -15
- package/dist/types/augments/promise/wait.d.ts +0 -18
- package/dist/types/augments/random.d.ts +0 -39
- package/dist/types/augments/string/suffixes.d.ts +0 -17
- package/dist/types/augments/string/uuid.d.ts +0 -1
- package/dist/types/augments/time.d.ts +0 -14
- package/dist/types/augments/tuple.d.ts +0 -17
- package/dist/types/augments/type.d.ts +0 -69
- package/dist/types/augments/union.d.ts +0 -5
- package/dist/types/index.d.ts +0 -44
- /package/dist/{types/augments → augments}/array/remove-duplicates.d.ts +0 -0
- /package/dist/{esm/augments → augments}/array/remove-duplicates.js +0 -0
- /package/dist/{types/augments → augments/file}/esm-path.d.ts +0 -0
- /package/dist/{esm/augments → augments/file}/esm-path.js +0 -0
- /package/dist/{types/augments → augments/json}/json-compatible.d.ts +0 -0
- /package/dist/{esm/augments → augments/json}/json-compatible.js +0 -0
- /package/dist/{esm/augments/function.js → augments/log/log-writer.js} +0 -0
- /package/dist/{esm/augments/object/any-object.js → augments/number/coords.js} +0 -0
- /package/dist/{esm/augments/object/key-count.js → augments/number/digit.js} +0 -0
- /package/dist/{esm/augments/object/pick-deep.js → augments/number/dimensions.js} +0 -0
- /package/dist/{types/augments → augments/number}/truncate-number.d.ts +0 -0
- /package/dist/{esm/augments/type-recursion.js → augments/object/empty.js} +0 -0
- /package/dist/{esm/augments/union.js → augments/object/key-count.js} +0 -0
- /package/dist/{types/augments → augments}/object/merge-deep.d.ts +0 -0
- /package/dist/{types/augments → augments}/object/merge-property-arrays.d.ts +0 -0
- /package/dist/{types/augments → augments/type}/type-recursion.d.ts +0 -0
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.combineErrors = combineErrors;
|
|
4
|
-
exports.combineErrorMessages = combineErrorMessages;
|
|
5
|
-
exports.extractErrorMessage = extractErrorMessage;
|
|
6
|
-
exports.ensureError = ensureError;
|
|
7
|
-
exports.ensureErrorAndPrependMessage = ensureErrorAndPrependMessage;
|
|
8
|
-
const boolean_1 = require("./boolean");
|
|
9
|
-
const typed_has_property_1 = require("./object/typed-has-property");
|
|
10
|
-
function combineErrors(errors) {
|
|
11
|
-
if (!errors || errors.length === 0) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
const firstError = errors[0];
|
|
15
|
-
if (errors.length === 1 && firstError) {
|
|
16
|
-
return firstError;
|
|
17
|
-
}
|
|
18
|
-
return new Error(errors.map((error) => extractErrorMessage(error).trim()).join('\n'));
|
|
19
|
-
}
|
|
20
|
-
function combineErrorMessages(errors) {
|
|
21
|
-
if (!errors) {
|
|
22
|
-
return '';
|
|
23
|
-
}
|
|
24
|
-
return errors.map(extractErrorMessage).filter(boolean_1.isTruthy).join('\n');
|
|
25
|
-
}
|
|
26
|
-
function extractErrorMessage(maybeError) {
|
|
27
|
-
if (!maybeError) {
|
|
28
|
-
return '';
|
|
29
|
-
}
|
|
30
|
-
if (maybeError instanceof Error) {
|
|
31
|
-
return maybeError.message;
|
|
32
|
-
}
|
|
33
|
-
else if ((0, typed_has_property_1.typedHasProperty)(maybeError, 'message')) {
|
|
34
|
-
return String(maybeError.message);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return String(maybeError);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function ensureError(maybeError) {
|
|
41
|
-
if (maybeError instanceof Error) {
|
|
42
|
-
return maybeError;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
return new Error(extractErrorMessage(maybeError));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function ensureErrorAndPrependMessage(maybeError, prependMessage) {
|
|
49
|
-
const error = ensureError(maybeError);
|
|
50
|
-
error.message = `${prependMessage}: ${error.message}`;
|
|
51
|
-
return error;
|
|
52
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEsmPath = getEsmPath;
|
|
4
|
-
function getEsmPath(importMeta) {
|
|
5
|
-
const filePath = new URL('', importMeta.url).pathname;
|
|
6
|
-
const dirPath = new URL('.', importMeta.url).pathname;
|
|
7
|
-
return {
|
|
8
|
-
filePath,
|
|
9
|
-
dirPath,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseJson = parseJson;
|
|
4
|
-
exports.stringifyJson = stringifyJson;
|
|
5
|
-
const wrap_in_try_1 = require("./wrap-in-try");
|
|
6
|
-
function parseJson({ jsonString, errorHandler, }) {
|
|
7
|
-
try {
|
|
8
|
-
const parsedJson = JSON.parse(jsonString);
|
|
9
|
-
return parsedJson;
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
if (errorHandler) {
|
|
13
|
-
return errorHandler(error);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
throw error;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function stringifyJson(jsonValue, { whitespace, ...tryOptions } = {}) {
|
|
21
|
-
const result = (0, wrap_in_try_1.wrapInTry)(() => JSON.stringify(jsonValue, undefined, whitespace), tryOptions);
|
|
22
|
-
if (result instanceof Error) {
|
|
23
|
-
throw result;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEnumTypedKeys = getEnumTypedKeys;
|
|
4
|
-
exports.getEnumTypedValues = getEnumTypedValues;
|
|
5
|
-
exports.isEnumValue = isEnumValue;
|
|
6
|
-
exports.ensureEnum = ensureEnum;
|
|
7
|
-
exports.filterToEnumValues = filterToEnumValues;
|
|
8
|
-
const object_entries_1 = require("./object-entries");
|
|
9
|
-
function getEnumTypedKeys(input) {
|
|
10
|
-
// enum keys are always strings
|
|
11
|
-
return (0, object_entries_1.getObjectTypedKeys)(input).filter((key) => isNaN(Number(key)));
|
|
12
|
-
}
|
|
13
|
-
function getEnumTypedValues(input) {
|
|
14
|
-
const keys = getEnumTypedKeys(input);
|
|
15
|
-
return keys.map((key) => input[key]);
|
|
16
|
-
}
|
|
17
|
-
/** Check if the given value is within the given enum. */
|
|
18
|
-
function isEnumValue(input, checkEnum) {
|
|
19
|
-
return getEnumTypedValues(checkEnum).includes(input);
|
|
20
|
-
}
|
|
21
|
-
/** Interpret a primitive as an enum value with type safety. */
|
|
22
|
-
function ensureEnum(value, checkEnum) {
|
|
23
|
-
if (isEnumValue(value, checkEnum)) {
|
|
24
|
-
return value;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
const enumValues = getEnumTypedValues(checkEnum);
|
|
28
|
-
throw new Error(`Given value '${value}' does not match given enum. Possible enum values: ${enumValues.join(',')}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function filterToEnumValues(inputs, checkEnum, caseInsensitive = false) {
|
|
32
|
-
if (caseInsensitive) {
|
|
33
|
-
return inputs.reduce((accum, currentInput) => {
|
|
34
|
-
const matchedEnumValue = getEnumTypedValues(checkEnum).find((actualEnumValue) => {
|
|
35
|
-
return String(actualEnumValue).toUpperCase() === String(currentInput).toUpperCase();
|
|
36
|
-
});
|
|
37
|
-
if (matchedEnumValue) {
|
|
38
|
-
return accum.concat(matchedEnumValue);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return accum;
|
|
42
|
-
}
|
|
43
|
-
}, []);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
return inputs.filter((input) => isEnumValue(input, checkEnum));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.filterObject = filterObject;
|
|
4
|
-
exports.omitObjectKeys = omitObjectKeys;
|
|
5
|
-
exports.pickObjectKeys = pickObjectKeys;
|
|
6
|
-
const object_entries_1 = require("./object-entries");
|
|
7
|
-
function filterObject(inputObject, callback) {
|
|
8
|
-
const filteredKeys = (0, object_entries_1.getObjectTypedKeys)(inputObject).filter((key) => {
|
|
9
|
-
const value = inputObject[key];
|
|
10
|
-
return callback(key, value, inputObject);
|
|
11
|
-
});
|
|
12
|
-
return filteredKeys.reduce((accum, key) => {
|
|
13
|
-
accum[key] = inputObject[key];
|
|
14
|
-
return accum;
|
|
15
|
-
}, {});
|
|
16
|
-
}
|
|
17
|
-
function omitObjectKeys(inputObject, omitTheseKeys) {
|
|
18
|
-
return filterObject(inputObject, (currentKey) => {
|
|
19
|
-
return !omitTheseKeys.includes(currentKey);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
function pickObjectKeys(inputObject, pickTheseKeys) {
|
|
23
|
-
return filterObject(inputObject, (currentKey) => {
|
|
24
|
-
return pickTheseKeys.includes(currentKey);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOrSetFromMap = getOrSetFromMap;
|
|
4
|
-
exports.getOrSet = getOrSet;
|
|
5
|
-
const run_time_assertions_1 = require("run-time-assertions");
|
|
6
|
-
function getOrSetFromMap(map, key, createNewValueCallback) {
|
|
7
|
-
const mapKey = key;
|
|
8
|
-
if (map.has(mapKey)) {
|
|
9
|
-
return map.get(mapKey);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
const newValue = createNewValueCallback();
|
|
13
|
-
map.set(mapKey, newValue);
|
|
14
|
-
return newValue;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function getOrSet(originalObject, key, createCallback) {
|
|
18
|
-
if (key in originalObject) {
|
|
19
|
-
return originalObject[key];
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
const createdValue = createCallback();
|
|
23
|
-
if ((0, run_time_assertions_1.isPromise)(createdValue)) {
|
|
24
|
-
return new Promise(async (resolve, reject) => {
|
|
25
|
-
try {
|
|
26
|
-
const awaitedValue = await createdValue;
|
|
27
|
-
originalObject[key] = awaitedValue;
|
|
28
|
-
resolve(awaitedValue);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
reject(error);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
originalObject[key] = createdValue;
|
|
37
|
-
return createdValue;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapObjectValuesSync = mapObjectValuesSync;
|
|
4
|
-
exports.mapObjectValues = mapObjectValues;
|
|
5
|
-
const object_entries_1 = require("./object-entries");
|
|
6
|
-
/**
|
|
7
|
-
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
8
|
-
* that this will not wrap the return value in a promise if any of the new object values are
|
|
9
|
-
* promises. This function also requires currying in order to get the types correct. This allows you
|
|
10
|
-
* to explicitly state the return type.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* mapObjectValuesSync({objectToIterateOver: 'initial value'})(callback);
|
|
14
|
-
*/
|
|
15
|
-
function mapObjectValuesSync(inputObject) {
|
|
16
|
-
function innerMap(mapCallback) {
|
|
17
|
-
const mappedObject = (0, object_entries_1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => {
|
|
18
|
-
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
|
|
19
|
-
return {
|
|
20
|
-
...accum,
|
|
21
|
-
[currentKey]: mappedValue,
|
|
22
|
-
};
|
|
23
|
-
}, {});
|
|
24
|
-
return mappedObject;
|
|
25
|
-
}
|
|
26
|
-
return innerMap;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Creates a new object with the same properties as the input object, but with values set to the
|
|
30
|
-
* result of mapCallback for each property.
|
|
31
|
-
*/
|
|
32
|
-
function mapObjectValues(inputObject, mapCallback) {
|
|
33
|
-
let gotAPromise = false;
|
|
34
|
-
const mappedObject = (0, object_entries_1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => {
|
|
35
|
-
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
|
|
36
|
-
if (mappedValue instanceof Promise) {
|
|
37
|
-
gotAPromise = true;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
...accum,
|
|
41
|
-
[currentKey]: mappedValue,
|
|
42
|
-
};
|
|
43
|
-
}, {});
|
|
44
|
-
if (gotAPromise) {
|
|
45
|
-
return new Promise(async (resolve, reject) => {
|
|
46
|
-
try {
|
|
47
|
-
await Promise.all((0, object_entries_1.getObjectTypedKeys)(mappedObject).map(async (key) => {
|
|
48
|
-
const value = await mappedObject[key];
|
|
49
|
-
mappedObject[key] = value;
|
|
50
|
-
}));
|
|
51
|
-
resolve(mappedObject);
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
reject(error);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
return mappedObject;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeDeep = mergeDeep;
|
|
4
|
-
const run_time_assertions_1 = require("run-time-assertions");
|
|
5
|
-
const tuple_1 = require("../tuple");
|
|
6
|
-
/**
|
|
7
|
-
* Accepts multiple objects and merges their key-value pairs recursively. Any values set to
|
|
8
|
-
* undefined will be removed.
|
|
9
|
-
*
|
|
10
|
-
* Note that order matters! Each input object will overwrite the properties of the previous objects.
|
|
11
|
-
*/
|
|
12
|
-
function mergeDeep(...inputs) {
|
|
13
|
-
if (!(0, tuple_1.isLengthAtLeast)(inputs, 1)) {
|
|
14
|
-
// nothing to merge if no inputs
|
|
15
|
-
return {};
|
|
16
|
-
}
|
|
17
|
-
if (inputs.length === 1) {
|
|
18
|
-
// nothing to merge if only one input
|
|
19
|
-
return inputs[0];
|
|
20
|
-
}
|
|
21
|
-
let result = undefined;
|
|
22
|
-
const mergeProps = {};
|
|
23
|
-
inputs.forEach((individualInput) => {
|
|
24
|
-
if (!(0, run_time_assertions_1.isRunTimeType)(individualInput, 'object')) {
|
|
25
|
-
/** If not an object, we can't merge. So overwrite instead. */
|
|
26
|
-
result = individualInput;
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
else if (!(0, run_time_assertions_1.isRunTimeType)(result, 'object')) {
|
|
30
|
-
/** If result isn't an object then we need to make it into one. */
|
|
31
|
-
result = { ...individualInput };
|
|
32
|
-
}
|
|
33
|
-
Object.entries(individualInput).forEach(([key, value,]) => {
|
|
34
|
-
if (!mergeProps[key]) {
|
|
35
|
-
mergeProps[key] = [];
|
|
36
|
-
}
|
|
37
|
-
mergeProps[key].push(value);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
if ((0, run_time_assertions_1.isRunTimeType)(result, 'object')) {
|
|
41
|
-
Object.entries(mergeProps).forEach(([key, mergeValues,]) => {
|
|
42
|
-
const newValue = mergeDeep(...mergeValues);
|
|
43
|
-
if (newValue === undefined && key in result) {
|
|
44
|
-
delete result[key];
|
|
45
|
-
}
|
|
46
|
-
else if (newValue !== undefined) {
|
|
47
|
-
result[key] = newValue;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergePropertyArrays = mergePropertyArrays;
|
|
4
|
-
const get_or_set_1 = require("./get-or-set");
|
|
5
|
-
function mergePropertyArrays(...inputs) {
|
|
6
|
-
const combined = {};
|
|
7
|
-
inputs.forEach((input) => {
|
|
8
|
-
Object.entries(input).forEach(([key, newArray,]) => {
|
|
9
|
-
const currentArray = (0, get_or_set_1.getOrSet)(combined, key, () => []);
|
|
10
|
-
currentArray.push(...newArray);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
return combined;
|
|
14
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isKeyof = isKeyof;
|
|
4
|
-
exports.getObjectTypedKeys = getObjectTypedKeys;
|
|
5
|
-
exports.getObjectTypedValues = getObjectTypedValues;
|
|
6
|
-
exports.getObjectTypedEntries = getObjectTypedEntries;
|
|
7
|
-
exports.getEntriesSortedByKey = getEntriesSortedByKey;
|
|
8
|
-
exports.typedObjectFromEntries = typedObjectFromEntries;
|
|
9
|
-
const typed_has_property_1 = require("./typed-has-property");
|
|
10
|
-
/** @deprecated This is the same as hasKey */
|
|
11
|
-
function isKeyof(key, object) {
|
|
12
|
-
return (0, typed_has_property_1.typedHasProperty)(object, key);
|
|
13
|
-
}
|
|
14
|
-
function getObjectTypedKeys(input) {
|
|
15
|
-
let reflectKeys;
|
|
16
|
-
try {
|
|
17
|
-
reflectKeys = Reflect.ownKeys(input);
|
|
18
|
-
}
|
|
19
|
-
catch (error) { }
|
|
20
|
-
return (reflectKeys ??
|
|
21
|
-
[
|
|
22
|
-
...Object.keys(input),
|
|
23
|
-
...Object.getOwnPropertySymbols(input),
|
|
24
|
-
]);
|
|
25
|
-
}
|
|
26
|
-
function getObjectTypedValues(input) {
|
|
27
|
-
return getObjectTypedKeys(input).map((key) => input[key]);
|
|
28
|
-
}
|
|
29
|
-
function getObjectTypedEntries(input) {
|
|
30
|
-
return getObjectTypedKeys(input).map((key) => [
|
|
31
|
-
key,
|
|
32
|
-
input[key],
|
|
33
|
-
]);
|
|
34
|
-
}
|
|
35
|
-
function getEntriesSortedByKey(input) {
|
|
36
|
-
return Object.entries(input).sort((tupleA, tupleB) => tupleA[0].localeCompare(tupleB[0]));
|
|
37
|
-
}
|
|
38
|
-
function typedObjectFromEntries(entries) {
|
|
39
|
-
return Object.fromEntries(entries);
|
|
40
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isObject = isObject;
|
|
4
|
-
exports.copyThroughJson = copyThroughJson;
|
|
5
|
-
/** Checks if the input is non-null and an object. Includes arrays. */
|
|
6
|
-
function isObject(input) {
|
|
7
|
-
return !!input && typeof input === 'object';
|
|
8
|
-
}
|
|
9
|
-
/** The input here must be serializable otherwise JSON parsing errors will be thrown */
|
|
10
|
-
function copyThroughJson(input) {
|
|
11
|
-
try {
|
|
12
|
-
return JSON.parse(JSON.stringify(input));
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
console.error(`Failed to JSON copy for`, input);
|
|
16
|
-
throw error;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.selectFrom = selectFrom;
|
|
4
|
-
exports.selectCollapsedFrom = selectCollapsedFrom;
|
|
5
|
-
const run_time_assertions_1 = require("run-time-assertions");
|
|
6
|
-
const tuple_1 = require("../tuple");
|
|
7
|
-
const filter_object_1 = require("./filter-object");
|
|
8
|
-
const map_object_1 = require("./map-object");
|
|
9
|
-
const object_1 = require("./object");
|
|
10
|
-
function shouldPreserve(input) {
|
|
11
|
-
return (0, run_time_assertions_1.isPrimitive)(input) || input instanceof RegExp || input instanceof Promise;
|
|
12
|
-
}
|
|
13
|
-
function selectFrom(originalObject, selectionSet) {
|
|
14
|
-
if (Array.isArray(originalObject)) {
|
|
15
|
-
return originalObject.map((originalEntry) => selectFrom(originalEntry, selectionSet));
|
|
16
|
-
}
|
|
17
|
-
const keysToRemove = [];
|
|
18
|
-
return (0, filter_object_1.omitObjectKeys)((0, map_object_1.mapObjectValues)(originalObject, (key, value) => {
|
|
19
|
-
const selection = selectionSet[key];
|
|
20
|
-
if (selection === true) {
|
|
21
|
-
return value;
|
|
22
|
-
}
|
|
23
|
-
else if (!selection) {
|
|
24
|
-
keysToRemove.push(key);
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
else if (shouldPreserve(value)) {
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
return selectFrom(value, selection);
|
|
32
|
-
}
|
|
33
|
-
}), keysToRemove);
|
|
34
|
-
}
|
|
35
|
-
function selectCollapsedFrom(originalObject, selectionSet) {
|
|
36
|
-
const selected = selectFrom(originalObject, selectionSet);
|
|
37
|
-
return collapseObject(selected, selectionSet);
|
|
38
|
-
}
|
|
39
|
-
function collapseObject(input, selectionSet) {
|
|
40
|
-
if (shouldPreserve(input)) {
|
|
41
|
-
return input;
|
|
42
|
-
}
|
|
43
|
-
const keys = Object.keys(input);
|
|
44
|
-
if (Array.isArray(input)) {
|
|
45
|
-
return input.map((innerInput) => collapseObject(innerInput, selectionSet));
|
|
46
|
-
}
|
|
47
|
-
else if ((0, tuple_1.isLengthAtLeast)(keys, 2)) {
|
|
48
|
-
return input;
|
|
49
|
-
}
|
|
50
|
-
else if ((0, tuple_1.isLengthAtLeast)(keys, 1) && (0, object_1.isObject)(selectionSet)) {
|
|
51
|
-
return collapseObject(input[keys[0]], selectionSet[keys[0]]);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
return input;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.typedHasProperty = typedHasProperty;
|
|
4
|
-
exports.typedHasProperties = typedHasProperties;
|
|
5
|
-
const hasPropertyAttempts = [
|
|
6
|
-
(object, key) => {
|
|
7
|
-
return key in object;
|
|
8
|
-
},
|
|
9
|
-
(object, key) => {
|
|
10
|
-
/** This handles cases where the input object can't use `in` directly, like string literals */
|
|
11
|
-
return key in object.constructor.prototype;
|
|
12
|
-
},
|
|
13
|
-
];
|
|
14
|
-
function typedHasProperty(inputObject, inputKey) {
|
|
15
|
-
if (!inputObject) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return hasPropertyAttempts.some((attemptCallback) => {
|
|
19
|
-
try {
|
|
20
|
-
return attemptCallback(inputObject, inputKey);
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function typedHasProperties(inputObject, inputKeys) {
|
|
28
|
-
return inputObject && inputKeys.every((key) => typedHasProperty(inputObject, key));
|
|
29
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDeferredPromiseWrapper = createDeferredPromiseWrapper;
|
|
4
|
-
function createDeferredPromiseWrapper() {
|
|
5
|
-
let resolve;
|
|
6
|
-
let reject;
|
|
7
|
-
let settled = false;
|
|
8
|
-
const promise = new Promise((resolveCallback, rejectCallback) => {
|
|
9
|
-
resolve = (value) => {
|
|
10
|
-
settled = true;
|
|
11
|
-
return resolveCallback(value);
|
|
12
|
-
};
|
|
13
|
-
reject = (reason) => {
|
|
14
|
-
settled = true;
|
|
15
|
-
rejectCallback(reason);
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
// no way to test this edge case
|
|
19
|
-
// istanbul ignore next
|
|
20
|
-
if (!resolve || !reject) {
|
|
21
|
-
throw new Error(`Reject and resolve callbacks were not set by the promise constructor for ${createDeferredPromiseWrapper.name}.`);
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
promise,
|
|
25
|
-
resolve,
|
|
26
|
-
reject,
|
|
27
|
-
isSettled() {
|
|
28
|
-
return settled;
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PromiseTimeoutError = void 0;
|
|
4
|
-
exports.isPromiseLike = isPromiseLike;
|
|
5
|
-
exports.wrapPromiseInTimeout = wrapPromiseInTimeout;
|
|
6
|
-
exports.callAsynchronously = callAsynchronously;
|
|
7
|
-
exports.executeWithRetries = executeWithRetries;
|
|
8
|
-
const typed_has_property_1 = require("../object/typed-has-property");
|
|
9
|
-
function isPromiseLike(input) {
|
|
10
|
-
if ((0, typed_has_property_1.typedHasProperty)(input, 'then') && typeof input.then === 'function') {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
class PromiseTimeoutError extends Error {
|
|
18
|
-
constructor(durationMs, message = `Promised timed out after ${durationMs} ms.`) {
|
|
19
|
-
super(message);
|
|
20
|
-
Object.defineProperty(this, "durationMs", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
configurable: true,
|
|
23
|
-
writable: true,
|
|
24
|
-
value: durationMs
|
|
25
|
-
});
|
|
26
|
-
Object.defineProperty(this, "message", {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
configurable: true,
|
|
29
|
-
writable: true,
|
|
30
|
-
value: message
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(this, "name", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
writable: true,
|
|
36
|
-
value: 'PromiseTimeoutError'
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.PromiseTimeoutError = PromiseTimeoutError;
|
|
41
|
-
function wrapPromiseInTimeout(durationMs, originalPromise) {
|
|
42
|
-
return new Promise(async (resolve, reject) => {
|
|
43
|
-
const timeoutId = durationMs === Infinity
|
|
44
|
-
? undefined
|
|
45
|
-
: setTimeout(() => {
|
|
46
|
-
reject(new PromiseTimeoutError(durationMs));
|
|
47
|
-
}, durationMs);
|
|
48
|
-
try {
|
|
49
|
-
const result = await originalPromise;
|
|
50
|
-
resolve(result);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
reject(error);
|
|
54
|
-
}
|
|
55
|
-
finally {
|
|
56
|
-
clearTimeout(timeoutId);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Call a function asynchronously without interrupting current synchronous execution, even if the
|
|
62
|
-
* function was originally synchronous.
|
|
63
|
-
*/
|
|
64
|
-
async function callAsynchronously(callback) {
|
|
65
|
-
return await Promise.resolve().then(() => callback());
|
|
66
|
-
}
|
|
67
|
-
async function executeWithRetries(retryCount, callback) {
|
|
68
|
-
let currentRetry = 0;
|
|
69
|
-
while (currentRetry < retryCount) {
|
|
70
|
-
try {
|
|
71
|
-
const result = await callback();
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
currentRetry++;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
throw new Error('Retry max reached.');
|
|
79
|
-
}
|