@augment-vir/common 29.3.0 → 30.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/README.md +7 -3
- package/dist/augments/array/array-map.d.ts +34 -0
- package/dist/augments/array/array-map.js +32 -0
- package/dist/augments/array/array-to-object.d.ts +53 -0
- package/dist/augments/array/array-to-object.js +67 -0
- package/dist/augments/array/awaited/awaited-filter.d.ts +36 -0
- package/dist/augments/array/awaited/awaited-filter.js +36 -0
- package/dist/augments/array/awaited/awaited-for-each.d.ts +31 -0
- package/dist/augments/array/awaited/awaited-for-each.js +34 -0
- package/dist/augments/array/awaited/awaited-map.d.ts +33 -0
- package/dist/augments/array/awaited/awaited-map.js +40 -0
- package/dist/augments/array/filter.d.ts +32 -0
- package/dist/augments/array/filter.js +74 -0
- package/dist/augments/array/remove-duplicates.d.ts +60 -0
- package/dist/augments/array/remove-duplicates.js +72 -0
- package/dist/augments/array/repeat-array.d.ts +23 -0
- package/dist/augments/array/repeat-array.js +25 -0
- package/dist/augments/array/shuffle-array.d.ts +9 -0
- package/dist/augments/array/shuffle-array.js +17 -0
- package/dist/augments/array/string-array.d.ts +9 -0
- package/dist/augments/array/string-array.js +11 -0
- 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 +32 -0
- package/dist/augments/enum/enum-value-check.js +34 -0
- package/dist/augments/error/combine-errors.d.ts +24 -0
- package/dist/augments/error/combine-errors.js +34 -0
- package/dist/augments/function/call-asynchronously.d.ts +25 -0
- package/dist/augments/function/call-asynchronously.js +26 -0
- package/dist/augments/function/call-with-retries.d.ts +24 -0
- package/dist/augments/function/call-with-retries.js +50 -0
- package/dist/augments/function/debounce.d.ts +89 -0
- package/dist/augments/function/debounce.js +112 -0
- package/dist/augments/function/execution-duration.d.ts +20 -0
- package/dist/augments/function/execution-duration.js +39 -0
- package/dist/augments/function/if-truthy.d.ts +28 -0
- package/dist/augments/function/if-truthy.js +35 -0
- package/dist/{types/augments → augments/function}/wrap-in-try.d.ts +14 -7
- package/dist/augments/function/wrap-in-try.js +98 -0
- package/dist/augments/json/append-json.d.ts +5 -0
- package/dist/augments/json/append-json.js +59 -0
- package/dist/augments/json/copy-through-json.d.ts +34 -0
- package/dist/augments/json/copy-through-json.js +42 -0
- package/dist/augments/json/json-compatible.d.ts +50 -0
- package/dist/augments/json/jsonify.d.ts +31 -0
- package/dist/augments/json/jsonify.js +33 -0
- package/dist/augments/log/log-colors.d.ts +64 -0
- package/dist/augments/log/log-colors.js +157 -0
- package/dist/augments/log/log-string.d.ts +35 -0
- package/dist/augments/log/log-string.js +73 -0
- package/dist/augments/log/log-writer.d.ts +30 -0
- package/dist/augments/log/log.d.ts +56 -0
- package/dist/augments/log/log.js +85 -0
- package/dist/augments/log/logger.d.ts +60 -0
- package/dist/augments/log/logger.js +59 -0
- package/dist/augments/number/clamp.d.ts +18 -0
- package/dist/augments/number/clamp.js +19 -0
- package/dist/augments/number/coords.d.ts +23 -0
- package/dist/augments/number/digit.d.ts +8 -0
- package/dist/augments/number/dimensions.d.ts +23 -0
- package/dist/augments/number/min-max.d.ts +18 -0
- package/dist/augments/number/min-max.js +16 -0
- package/dist/augments/number/number-conversion.d.ts +29 -0
- package/dist/augments/number/number-conversion.js +56 -0
- package/dist/augments/number/round.d.ts +22 -0
- package/dist/augments/number/round.js +24 -0
- package/dist/augments/number/scientific.d.ts +18 -0
- package/dist/augments/number/scientific.js +20 -0
- package/dist/augments/number/truncate-number.d.ts +40 -0
- package/dist/{esm/augments → augments/number}/truncate-number.js +39 -17
- package/dist/augments/number/wrap-number.d.ts +19 -0
- package/dist/augments/number/wrap-number.js +28 -0
- package/dist/augments/object/diff.d.ts +51 -0
- package/dist/augments/object/diff.js +149 -0
- package/dist/augments/object/empty.d.ts +9 -0
- package/dist/augments/object/get-or-set.d.ts +10 -0
- package/dist/augments/object/get-or-set.js +100 -0
- package/dist/augments/object/key-count.d.ts +21 -0
- package/dist/augments/object/map-entries.d.ts +13 -0
- package/dist/augments/object/map-entries.js +80 -0
- package/dist/augments/object/map-enum.d.ts +11 -0
- package/dist/augments/object/map-enum.js +45 -0
- package/dist/augments/object/map-values.d.ts +35 -0
- package/dist/augments/object/map-values.js +65 -0
- package/dist/{types/augments → augments}/object/merge-deep.d.ts +4 -0
- package/dist/{esm/augments → augments}/object/merge-deep.js +9 -6
- package/dist/augments/object/merge-defined-properties.d.ts +19 -0
- package/dist/augments/object/merge-defined-properties.js +32 -0
- package/dist/augments/object/merge-property-arrays.d.ts +29 -0
- package/dist/augments/object/merge-property-arrays.js +39 -0
- package/dist/augments/object/object-entries.d.ts +31 -0
- package/dist/augments/object/object-entries.js +40 -0
- package/dist/augments/object/object-filter.d.ts +22 -0
- package/dist/augments/object/object-filter.js +27 -0
- package/dist/augments/object/object-keys.d.ts +34 -0
- package/dist/augments/object/object-keys.js +43 -0
- package/dist/augments/object/object-values.d.ts +11 -0
- package/dist/augments/object/object-values.js +13 -0
- package/dist/augments/path/esm-path.d.ts +26 -0
- package/dist/augments/path/esm-path.js +31 -0
- package/dist/augments/prisma/prisma-models.d.ts +143 -0
- package/dist/augments/prisma/prisma-models.js +1 -0
- package/dist/augments/promise/timed-promise.d.ts +22 -0
- package/dist/augments/promise/timed-promise.js +51 -0
- package/dist/augments/random/random-boolean.d.ts +24 -0
- package/dist/augments/random/random-boolean.js +32 -0
- package/dist/augments/random/random-integer.d.ts +14 -0
- package/dist/augments/random/random-integer.js +34 -0
- package/dist/augments/random/random-string.d.ts +18 -0
- package/dist/augments/random/random-string.js +67 -0
- package/dist/augments/regexp/match.d.ts +10 -0
- package/dist/augments/regexp/match.js +13 -0
- package/dist/augments/regexp/regexp-flags.d.ts +56 -0
- package/dist/augments/regexp/regexp-flags.js +75 -0
- package/dist/augments/regexp/regexp-string.d.ts +9 -0
- package/dist/augments/regexp/regexp-string.js +11 -0
- package/dist/augments/selection-set/select-collapsed.d.ts +54 -0
- package/dist/augments/selection-set/select-collapsed.js +63 -0
- package/dist/augments/selection-set/select-from.d.ts +48 -0
- package/dist/augments/selection-set/select-from.js +72 -0
- package/dist/augments/selection-set/selection-set.d.ts +37 -0
- package/dist/augments/selection-set/selection-set.js +1 -0
- package/dist/augments/string/casing/capitalization.d.ts +17 -0
- package/dist/augments/string/casing/capitalization.js +25 -0
- package/dist/augments/string/casing/casing.d.ts +73 -0
- package/dist/augments/string/casing/casing.js +65 -0
- package/dist/augments/string/casing/kebab-and-camel.d.ts +17 -0
- package/dist/augments/string/casing/kebab-and-camel.js +57 -0
- package/dist/augments/string/comma.d.ts +26 -0
- package/dist/augments/string/comma.js +48 -0
- package/dist/augments/string/join.d.ts +21 -0
- package/dist/augments/string/join.js +34 -0
- package/dist/augments/string/prefix.d.ts +30 -0
- package/dist/augments/string/prefix.js +30 -0
- package/dist/augments/string/remove-duplicate-characters.d.ts +17 -0
- package/dist/augments/string/remove-duplicate-characters.js +22 -0
- package/dist/augments/string/replace.d.ts +18 -0
- package/dist/augments/string/replace.js +22 -0
- package/dist/augments/string/split.d.ts +31 -0
- package/dist/augments/string/split.js +53 -0
- package/dist/augments/string/substring-index.d.ts +19 -0
- package/dist/augments/string/substring-index.js +47 -0
- package/dist/augments/string/suffix.d.ts +96 -0
- package/dist/augments/string/suffix.js +89 -0
- package/dist/augments/string/white-space.d.ts +12 -0
- package/dist/augments/string/white-space.js +19 -0
- package/dist/augments/string/wrap-string.d.ts +19 -0
- package/dist/augments/string/wrap-string.js +20 -0
- package/dist/augments/type/ensure-type.d.ts +12 -0
- package/dist/augments/type/ensure-type.js +14 -0
- package/dist/augments/type/readonly.d.ts +9 -0
- package/dist/augments/type/readonly.js +10 -0
- package/dist/augments/type/type-recursion.d.ts +253 -0
- package/dist/augments/type/type-recursion.js +1 -0
- package/dist/augments/type/union.d.ts +1 -0
- package/dist/augments/type/union.js +1 -0
- package/dist/augments/type/void-type.d.ts +9 -0
- package/dist/augments/type/void-type.js +1 -0
- package/dist/augments/type/writable.d.ts +10 -0
- package/dist/augments/type/writable.js +10 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +83 -0
- package/package.json +43 -15
- 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 -118
- 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 -13
- 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/array/remove-duplicates.js +0 -13
- package/dist/esm/augments/async.js +0 -23
- package/dist/esm/augments/boolean.js +0 -14
- 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/esm-path.js +0 -8
- 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/get-or-set.js +0 -36
- package/dist/esm/augments/object/has-key.js +0 -3
- package/dist/esm/augments/object/jsonify.js +0 -3
- package/dist/esm/augments/object/map-object.js +0 -57
- package/dist/esm/augments/object/merge-property-arrays.js +0 -11
- 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 -113
- package/dist/esm/augments/regexp.js +0 -14
- package/dist/esm/augments/string/prefixes.js +0 -16
- package/dist/esm/augments/string/suffixes.js +0 -31
- package/dist/esm/augments/string/uuid.js +0 -9
- package/dist/esm/augments/time.js +0 -31
- package/dist/esm/augments/tuple.js +0 -16
- package/dist/esm/augments/type.js +0 -30
- package/dist/esm/augments/wrap-in-try.js +0 -34
- 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/array/remove-duplicates.d.ts +0 -1
- 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/esm-path.d.ts +0 -4
- package/dist/types/augments/function.d.ts +0 -25
- package/dist/types/augments/json-compatible.d.ts +0 -22
- 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/key-count.d.ts +0 -13
- package/dist/types/augments/object/map-object.d.ts +0 -20
- package/dist/types/augments/object/merge-property-arrays.d.ts +0 -1
- 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 -37
- package/dist/types/augments/regexp.d.ts +0 -3
- package/dist/types/augments/string/prefixes.d.ts +0 -9
- package/dist/types/augments/string/suffixes.d.ts +0 -17
- package/dist/types/augments/string/uuid.d.ts +0 -5
- package/dist/types/augments/time.d.ts +0 -14
- package/dist/types/augments/truncate-number.d.ts +0 -19
- package/dist/types/augments/tuple.d.ts +0 -17
- package/dist/types/augments/type-recursion.d.ts +0 -161
- 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/{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/{esm/augments/type-recursion.js → augments/object/empty.js} +0 -0
- /package/dist/{esm/augments/union.js → augments/object/key-count.js} +0 -0
|
@@ -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
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultWaitUntilDefinedOptions = void 0;
|
|
4
|
-
exports.wait = wait;
|
|
5
|
-
exports.waitValue = waitValue;
|
|
6
|
-
exports.waitUntilTruthy = waitUntilTruthy;
|
|
7
|
-
const error_1 = require("../error");
|
|
8
|
-
const deferred_promise_1 = require("./deferred-promise");
|
|
9
|
-
function wait(delayMs) {
|
|
10
|
-
const deferredPromiseWrapper = (0, deferred_promise_1.createDeferredPromiseWrapper)();
|
|
11
|
-
if (delayMs !== Infinity) {
|
|
12
|
-
setTimeout(() => {
|
|
13
|
-
deferredPromiseWrapper.resolve();
|
|
14
|
-
}, delayMs <= 0 ? 0 : delayMs);
|
|
15
|
-
}
|
|
16
|
-
return deferredPromiseWrapper.promise;
|
|
17
|
-
}
|
|
18
|
-
async function waitValue(delayMs, returnValue) {
|
|
19
|
-
return wait(delayMs).then(() => returnValue);
|
|
20
|
-
}
|
|
21
|
-
exports.defaultWaitUntilDefinedOptions = {
|
|
22
|
-
interval: {
|
|
23
|
-
milliseconds: 100,
|
|
24
|
-
},
|
|
25
|
-
timeout: {
|
|
26
|
-
milliseconds: 10_000,
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Runs the predicate until it returns a truthy value, then returns that value. Use the options
|
|
31
|
-
* input to modify the timeout and interval durations. Automatically catches errors and handles
|
|
32
|
-
* async predicates.
|
|
33
|
-
*/
|
|
34
|
-
async function waitUntilTruthy(predicate, failureMessage, optionsInput = {}) {
|
|
35
|
-
const options = {
|
|
36
|
-
...exports.defaultWaitUntilDefinedOptions,
|
|
37
|
-
...optionsInput,
|
|
38
|
-
};
|
|
39
|
-
let lastValue = undefined;
|
|
40
|
-
let lastError;
|
|
41
|
-
async function checkCondition() {
|
|
42
|
-
try {
|
|
43
|
-
lastValue = await predicate();
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
lastValue = undefined;
|
|
47
|
-
lastError = error;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const startTime = Date.now();
|
|
51
|
-
while (!lastValue) {
|
|
52
|
-
await checkCondition();
|
|
53
|
-
await wait(options.interval.milliseconds);
|
|
54
|
-
if (Date.now() - startTime >= options.timeout.milliseconds) {
|
|
55
|
-
const message = failureMessage ? `${failureMessage}: ` : '';
|
|
56
|
-
const preMessage = `${message}Timeout of "${options.timeout.milliseconds}" exceeded waiting for value to be defined`;
|
|
57
|
-
if (lastError) {
|
|
58
|
-
throw (0, error_1.ensureErrorAndPrependMessage)(lastError, preMessage);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
throw new Error(preMessage);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return lastValue;
|
|
66
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randomInteger = randomInteger;
|
|
4
|
-
exports.randomBoolean = randomBoolean;
|
|
5
|
-
exports.randomString = randomString;
|
|
6
|
-
const common_number_1 = require("./common-number");
|
|
7
|
-
function accessCrypto() {
|
|
8
|
-
if (globalThis.crypto) {
|
|
9
|
-
return globalThis.crypto;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
return require('crypto').webcrypto;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const crypto = accessCrypto();
|
|
16
|
-
/**
|
|
17
|
-
* Creates a random integer (decimal points are all cut off) between the given min and max
|
|
18
|
-
* (inclusive).
|
|
19
|
-
*
|
|
20
|
-
* This function uses cryptographically secure randomness.
|
|
21
|
-
*/
|
|
22
|
-
function randomInteger({ min: rawMin, max: rawMax }) {
|
|
23
|
-
const { min, max } = (0, common_number_1.ensureMinAndMax)({ min: Math.floor(rawMin), max: Math.floor(rawMax) });
|
|
24
|
-
const range = max - min + 1;
|
|
25
|
-
const neededByteCount = Math.ceil(Math.log2(range) / 8);
|
|
26
|
-
const cutoff = Math.floor(256 ** neededByteCount / range) * range;
|
|
27
|
-
const currentBytes = new Uint8Array(neededByteCount);
|
|
28
|
-
let value;
|
|
29
|
-
do {
|
|
30
|
-
crypto.getRandomValues(currentBytes);
|
|
31
|
-
value = currentBytes.reduce((accum, byte, index) => {
|
|
32
|
-
return accum + byte * 256 ** index;
|
|
33
|
-
}, 0);
|
|
34
|
-
} while (value >= cutoff);
|
|
35
|
-
return min + (value % range);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Returns true at rate of the percentLikelyToBeTrue input. Inputs should be whole numbers which
|
|
39
|
-
* will be treated like percents. Anything outside of 0-100 inclusively will be clamped. An input 0
|
|
40
|
-
* will always return true. An input of 100 will always return true. Decimals on the input will be
|
|
41
|
-
* chopped off, use whole numbers.
|
|
42
|
-
*
|
|
43
|
-
* This function uses cryptographically secure randomness.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* randomBoolean(50); // 50% chance to return true
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* randomBoolean(0); // always false, 0% chance of being true
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* randomBoolean(100); // always true, 100% chance of being true
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* randomBoolean(59.67; // 59% chance of being true
|
|
56
|
-
*/
|
|
57
|
-
function randomBoolean(percentLikelyToBeTrue = 50) {
|
|
58
|
-
return (randomInteger({ min: 0, max: 99 }) <
|
|
59
|
-
(0, common_number_1.clamp)({
|
|
60
|
-
value: Math.floor(percentLikelyToBeTrue),
|
|
61
|
-
min: 0,
|
|
62
|
-
max: 100,
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
const validStringCharacters = [
|
|
66
|
-
'a',
|
|
67
|
-
'b',
|
|
68
|
-
'c',
|
|
69
|
-
'd',
|
|
70
|
-
'e',
|
|
71
|
-
'f',
|
|
72
|
-
'g',
|
|
73
|
-
'h',
|
|
74
|
-
'i',
|
|
75
|
-
'j',
|
|
76
|
-
'k',
|
|
77
|
-
'l',
|
|
78
|
-
'm',
|
|
79
|
-
'n',
|
|
80
|
-
'o',
|
|
81
|
-
'p',
|
|
82
|
-
'q',
|
|
83
|
-
'r',
|
|
84
|
-
's',
|
|
85
|
-
't',
|
|
86
|
-
'u',
|
|
87
|
-
'v',
|
|
88
|
-
'w',
|
|
89
|
-
'x',
|
|
90
|
-
'y',
|
|
91
|
-
'z',
|
|
92
|
-
0,
|
|
93
|
-
1,
|
|
94
|
-
2,
|
|
95
|
-
3,
|
|
96
|
-
4,
|
|
97
|
-
5,
|
|
98
|
-
6,
|
|
99
|
-
7,
|
|
100
|
-
8,
|
|
101
|
-
9,
|
|
102
|
-
];
|
|
103
|
-
/**
|
|
104
|
-
* Creates a random string (including letters and numbers) of a given length.
|
|
105
|
-
*
|
|
106
|
-
* This function uses cryptographically secure randomness.
|
|
107
|
-
*/
|
|
108
|
-
function randomString(inputLength = 16) {
|
|
109
|
-
let stringBuilder = '';
|
|
110
|
-
for (let i = 0; i < inputLength; i++) {
|
|
111
|
-
const index = randomInteger({
|
|
112
|
-
min: 0,
|
|
113
|
-
max: validStringCharacters.length - 1,
|
|
114
|
-
});
|
|
115
|
-
stringBuilder += validStringCharacters[index];
|
|
116
|
-
}
|
|
117
|
-
return stringBuilder;
|
|
118
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deDupeRegExFlags = deDupeRegExFlags;
|
|
4
|
-
exports.addRegExpFlags = addRegExpFlags;
|
|
5
|
-
exports.safeMatch = safeMatch;
|
|
6
|
-
function deDupeRegExFlags(flags) {
|
|
7
|
-
const deDuped = new Set(Array.from(flags.toLowerCase()));
|
|
8
|
-
return Array.from(deDuped).join('');
|
|
9
|
-
}
|
|
10
|
-
function addRegExpFlags(originalRegExp, flags) {
|
|
11
|
-
return new RegExp(originalRegExp.source, deDupeRegExFlags([
|
|
12
|
-
originalRegExp.flags,
|
|
13
|
-
flags,
|
|
14
|
-
].join('')));
|
|
15
|
-
}
|
|
16
|
-
function safeMatch(input, regExp) {
|
|
17
|
-
const match = input.match(regExp);
|
|
18
|
-
return match ?? [];
|
|
19
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addPrefix = addPrefix;
|
|
4
|
-
exports.removePrefix = removePrefix;
|
|
5
|
-
function addPrefix({ value, prefix, }) {
|
|
6
|
-
if (String(value).startsWith(prefix)) {
|
|
7
|
-
return String(value);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
return `${prefix}${String(value)}`;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function removePrefix({ value, prefix, }) {
|
|
14
|
-
if (value.startsWith(prefix)) {
|
|
15
|
-
return value.substring(prefix.length);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pxSuffix = exports.percentSuffix = void 0;
|
|
4
|
-
exports.addPx = addPx;
|
|
5
|
-
exports.removePx = removePx;
|
|
6
|
-
exports.addPercent = addPercent;
|
|
7
|
-
exports.removePercent = removePercent;
|
|
8
|
-
exports.addSuffix = addSuffix;
|
|
9
|
-
exports.removeSuffix = removeSuffix;
|
|
10
|
-
const common_number_1 = require("../common-number");
|
|
11
|
-
exports.percentSuffix = '%';
|
|
12
|
-
exports.pxSuffix = 'px';
|
|
13
|
-
function addPx(input) {
|
|
14
|
-
return addSuffix({ value: input, suffix: exports.pxSuffix });
|
|
15
|
-
}
|
|
16
|
-
function removePx(input) {
|
|
17
|
-
return (0, common_number_1.toEnsuredNumber)(removeSuffix({ value: input, suffix: exports.pxSuffix }));
|
|
18
|
-
}
|
|
19
|
-
function addPercent(input) {
|
|
20
|
-
return addSuffix({ value: input, suffix: exports.percentSuffix });
|
|
21
|
-
}
|
|
22
|
-
function removePercent(input) {
|
|
23
|
-
return (0, common_number_1.toEnsuredNumber)(removeSuffix({ value: input, suffix: exports.percentSuffix }));
|
|
24
|
-
}
|
|
25
|
-
function addSuffix({ value, suffix, }) {
|
|
26
|
-
if (String(value).endsWith(suffix)) {
|
|
27
|
-
return String(value);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return `${String(value)}${suffix}`;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function removeSuffix({ value, suffix, }) {
|
|
34
|
-
if (value.endsWith(suffix)) {
|
|
35
|
-
return value.substring(0, value.length - suffix.length);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return value;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUuid = isUuid;
|
|
4
|
-
exports.createUuid = createUuid;
|
|
5
|
-
const uuidRegExp = /[\d\w]{8}-[\d\w]{4}-[\d\w]{4}-[\d\w]{4}-[\d\w]{12}/;
|
|
6
|
-
/** Checks if the input string is a valid v4 UUID. */
|
|
7
|
-
function isUuid(maybeUuid) {
|
|
8
|
-
return !!maybeUuid.match(uuidRegExp);
|
|
9
|
-
}
|
|
10
|
-
/** Creates a cryptographically secure v4 UUID using `crypto.randomUUID`. */
|
|
11
|
-
function createUuid() {
|
|
12
|
-
return crypto.randomUUID();
|
|
13
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.measureCallbackDuration = void 0;
|
|
4
|
-
exports.timeCallback = timeCallback;
|
|
5
|
-
/**
|
|
6
|
-
* Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
|
|
7
|
-
* switches to async mode and awaits callbacks if they return a promise (otherwise this function is
|
|
8
|
-
* purely synchronous).
|
|
9
|
-
*/
|
|
10
|
-
function timeCallback(callback) {
|
|
11
|
-
const startTime = Date.now();
|
|
12
|
-
const result = callback();
|
|
13
|
-
if (result instanceof Promise) {
|
|
14
|
-
return new Promise(async (resolve, reject) => {
|
|
15
|
-
try {
|
|
16
|
-
await result;
|
|
17
|
-
const endTime = Date.now();
|
|
18
|
-
resolve(endTime - startTime);
|
|
19
|
-
}
|
|
20
|
-
catch (caught) {
|
|
21
|
-
reject(caught);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
const endTime = Date.now();
|
|
26
|
-
return (endTime - startTime);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
|
|
30
|
-
* switches to async mode and awaits callbacks if they return a promise (otherwise this function is
|
|
31
|
-
* purely synchronous).
|
|
32
|
-
*
|
|
33
|
-
* Alias of timeCallback.
|
|
34
|
-
*/
|
|
35
|
-
exports.measureCallbackDuration = timeCallback;
|