@ls-stack/utils 3.65.0 → 3.66.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/dist/{arrayUtils.d.cts → arrayUtils.d.mts} +24 -23
- package/dist/arrayUtils.mjs +249 -0
- package/dist/assertions-qMxfVhSu.mjs +207 -0
- package/dist/{assertions.d.ts → assertions.d.mts} +4 -3
- package/dist/assertions.mjs +3 -0
- package/dist/asyncQueue.d.mts +497 -0
- package/dist/asyncQueue.mjs +757 -0
- package/dist/{awaitDebounce.d.cts → awaitDebounce.d.mts} +11 -6
- package/dist/awaitDebounce.mjs +54 -0
- package/dist/{cache.d.ts → cache.d.mts} +76 -68
- package/dist/cache.mjs +355 -0
- package/dist/castValues-DfICShCc.mjs +19 -0
- package/dist/{castValues.d.cts → castValues.d.mts} +3 -2
- package/dist/castValues.mjs +3 -0
- package/dist/{concurrentCalls.d.ts → concurrentCalls.d.mts} +74 -65
- package/dist/concurrentCalls.mjs +295 -0
- package/dist/consoleFmt.d.mts +55 -0
- package/dist/consoleFmt.mjs +63 -0
- package/dist/conversions-DTmwEMIu.mjs +12 -0
- package/dist/conversions.d.mts +4 -0
- package/dist/conversions.mjs +3 -0
- package/dist/createThrottleController.d.mts +18 -0
- package/dist/createThrottleController.mjs +40 -0
- package/dist/debounce.d.mts +47 -0
- package/dist/debounce.mjs +117 -0
- package/dist/dedent.d.mts +74 -0
- package/dist/dedent.mjs +80 -0
- package/dist/deepEqual-C7EZEixx.mjs +78 -0
- package/dist/{deepEqual.d.cts → deepEqual.d.mts} +3 -2
- package/dist/deepEqual.mjs +3 -0
- package/dist/{deepReplaceValues.d.cts → deepReplaceValues.d.mts} +4 -3
- package/dist/deepReplaceValues.mjs +61 -0
- package/dist/diffParser.d.mts +63 -0
- package/dist/diffParser.mjs +410 -0
- package/dist/enhancedMap.d.mts +21 -0
- package/dist/enhancedMap.mjs +69 -0
- package/dist/exhaustiveMatch.d.mts +10 -0
- package/dist/exhaustiveMatch.mjs +48 -0
- package/dist/{filterObjectOrArrayKeys.d.cts → filterObjectOrArrayKeys.d.mts} +15 -8
- package/dist/filterObjectOrArrayKeys.mjs +497 -0
- package/dist/{getAutoIncrementId.d.cts → getAutoIncrementId.d.mts} +9 -5
- package/dist/getAutoIncrementId.mjs +53 -0
- package/dist/{getCompositeKey.d.cts → getCompositeKey.d.mts} +3 -2
- package/dist/getCompositeKey.mjs +50 -0
- package/dist/{getValueStableKey.d.cts → getValueStableKey.d.mts} +5 -3
- package/dist/getValueStableKey.mjs +17 -0
- package/dist/{hash.d.cts → hash.d.mts} +3 -2
- package/dist/hash.mjs +28 -0
- package/dist/interpolate.d.mts +17 -0
- package/dist/interpolate.mjs +28 -0
- package/dist/{iteratorUtils.d.cts → iteratorUtils.d.mts} +5 -4
- package/dist/iteratorUtils.mjs +39 -0
- package/dist/keepPrevIfUnchanged.d.mts +12 -0
- package/dist/keepPrevIfUnchanged.mjs +9 -0
- package/dist/keyedMap.d.mts +76 -0
- package/dist/keyedMap.mjs +139 -0
- package/dist/keyedSet.d.mts +77 -0
- package/dist/keyedSet.mjs +129 -0
- package/dist/{levenshtein.d.cts → levenshtein.d.mts} +3 -2
- package/dist/levenshtein.mjs +121 -0
- package/dist/main.d.mts +4 -0
- package/dist/main.mjs +7 -0
- package/dist/matchPath.d.mts +50 -0
- package/dist/matchPath.mjs +81 -0
- package/dist/mathUtils-BDP1lM_z.mjs +81 -0
- package/dist/{mathUtils.d.cts → mathUtils.d.mts} +3 -2
- package/dist/mathUtils.mjs +3 -0
- package/dist/{mutationUtils.d.cts → mutationUtils.d.mts} +6 -5
- package/dist/mutationUtils.mjs +44 -0
- package/dist/{objUtils.d.ts → objUtils.d.mts} +8 -6
- package/dist/objUtils.mjs +115 -0
- package/dist/parallelAsyncCalls.d.mts +83 -0
- package/dist/parallelAsyncCalls.mjs +121 -0
- package/dist/partialEqual.d.mts +139 -0
- package/dist/partialEqual.mjs +1055 -0
- package/dist/promiseUtils.d.mts +9 -0
- package/dist/promiseUtils.mjs +17 -0
- package/dist/regexUtils.d.mts +18 -0
- package/dist/regexUtils.mjs +34 -0
- package/dist/{retryOnError.d.cts → retryOnError.d.mts} +38 -37
- package/dist/retryOnError.mjs +91 -0
- package/dist/{runShellCmd.d.ts → runShellCmd.d.mts} +24 -15
- package/dist/runShellCmd.mjs +151 -0
- package/dist/{safeJson.d.cts → safeJson.d.mts} +3 -2
- package/dist/safeJson.mjs +30 -0
- package/dist/{saferTyping.d.cts → saferTyping.d.mts} +4 -3
- package/dist/saferTyping.mjs +45 -0
- package/dist/serializeXML.d.mts +23 -0
- package/dist/serializeXML.mjs +74 -0
- package/dist/{shallowEqual.d.cts → shallowEqual.d.mts} +3 -2
- package/dist/shallowEqual.mjs +54 -0
- package/dist/sleep.d.mts +4 -0
- package/dist/sleep.mjs +7 -0
- package/dist/stringUtils-DjhWOiYn.mjs +113 -0
- package/dist/{stringUtils.d.cts → stringUtils.d.mts} +3 -2
- package/dist/stringUtils.mjs +3 -0
- package/dist/{testUtils.d.ts → testUtils.d.mts} +83 -52
- package/dist/testUtils.mjs +310 -0
- package/dist/{throttle.d.ts → throttle.d.mts} +18 -17
- package/dist/throttle.mjs +102 -0
- package/dist/time-sr2lhQRw.mjs +67 -0
- package/dist/{time.d.ts → time.d.mts} +8 -7
- package/dist/time.mjs +3 -0
- package/dist/{timers.d.cts → timers.d.mts} +22 -13
- package/dist/timers.mjs +220 -0
- package/dist/{tsResult.d.cts → tsResult.d.mts} +52 -48
- package/dist/tsResult.mjs +142 -0
- package/dist/typeGuards-B1mzA-Rz.mjs +128 -0
- package/dist/{typeGuards.d.cts → typeGuards.d.mts} +3 -2
- package/dist/typeGuards.mjs +3 -0
- package/dist/{typeUtils.d.ts → typeUtils.d.mts} +13 -34
- package/dist/typeUtils.mjs +1 -0
- package/dist/{typedStrings.d.cts → typedStrings.d.mts} +5 -4
- package/dist/typedStrings.mjs +131 -0
- package/dist/typingFnUtils-Bb8drgKF.mjs +101 -0
- package/dist/{typingFnUtils.d.cts → typingFnUtils.d.mts} +13 -22
- package/dist/typingFnUtils.mjs +3 -0
- package/dist/{typingTestUtils.d.cts → typingTestUtils.d.mts} +11 -15
- package/dist/typingTestUtils.mjs +80 -0
- package/dist/typingUtils.d.mts +20 -0
- package/dist/typingUtils.mjs +1 -0
- package/dist/yamlStringify.d.mts +17 -0
- package/dist/yamlStringify.mjs +189 -0
- package/package.json +65 -242
- package/dist/arrayUtils.cjs +0 -229
- package/dist/arrayUtils.d.ts +0 -171
- package/dist/arrayUtils.js +0 -42
- package/dist/assertions.cjs +0 -107
- package/dist/assertions.d.cts +0 -192
- package/dist/assertions.js +0 -25
- package/dist/asyncQueue.cjs +0 -672
- package/dist/asyncQueue.d.cts +0 -488
- package/dist/asyncQueue.d.ts +0 -488
- package/dist/asyncQueue.js +0 -631
- package/dist/awaitDebounce.cjs +0 -106
- package/dist/awaitDebounce.d.ts +0 -41
- package/dist/awaitDebounce.js +0 -28
- package/dist/cache.cjs +0 -367
- package/dist/cache.d.cts +0 -228
- package/dist/cache.js +0 -19
- package/dist/castValues.cjs +0 -50
- package/dist/castValues.d.ts +0 -4
- package/dist/castValues.js +0 -8
- package/dist/chunk-5DZT3Z5Z.js +0 -8
- package/dist/chunk-6FBIEPWU.js +0 -96
- package/dist/chunk-6FIBVC2P.js +0 -56
- package/dist/chunk-7CQPOM5I.js +0 -100
- package/dist/chunk-B6DNOZCP.js +0 -369
- package/dist/chunk-BM4PYVOX.js +0 -109
- package/dist/chunk-C2SVCIWE.js +0 -57
- package/dist/chunk-CCUPDGSZ.js +0 -132
- package/dist/chunk-DBOWTYR4.js +0 -49
- package/dist/chunk-DFXNVEH6.js +0 -14
- package/dist/chunk-DX2524CZ.js +0 -314
- package/dist/chunk-GMJTLFM6.js +0 -60
- package/dist/chunk-IATIXMCE.js +0 -20
- package/dist/chunk-II4R3VVX.js +0 -25
- package/dist/chunk-JF2MDHOJ.js +0 -40
- package/dist/chunk-JQFUKJU5.js +0 -71
- package/dist/chunk-MI4UE2PQ.js +0 -561
- package/dist/chunk-PUKVXYYL.js +0 -52
- package/dist/chunk-QQS7I7ZL.js +0 -16
- package/dist/chunk-VAAMRG4K.js +0 -20
- package/dist/chunk-WFQJUJTC.js +0 -182
- package/dist/chunk-ZXIKIA5B.js +0 -178
- package/dist/concurrentCalls.cjs +0 -406
- package/dist/concurrentCalls.d.cts +0 -116
- package/dist/concurrentCalls.js +0 -346
- package/dist/consoleFmt.cjs +0 -85
- package/dist/consoleFmt.d.cts +0 -54
- package/dist/consoleFmt.d.ts +0 -54
- package/dist/consoleFmt.js +0 -60
- package/dist/conversions.cjs +0 -44
- package/dist/conversions.d.cts +0 -3
- package/dist/conversions.d.ts +0 -3
- package/dist/conversions.js +0 -6
- package/dist/createThrottleController.cjs +0 -193
- package/dist/createThrottleController.d.cts +0 -13
- package/dist/createThrottleController.d.ts +0 -13
- package/dist/createThrottleController.js +0 -61
- package/dist/debounce.cjs +0 -157
- package/dist/debounce.d.cts +0 -46
- package/dist/debounce.d.ts +0 -46
- package/dist/debounce.js +0 -8
- package/dist/dedent.cjs +0 -104
- package/dist/dedent.d.cts +0 -73
- package/dist/dedent.d.ts +0 -73
- package/dist/dedent.js +0 -79
- package/dist/deepEqual.cjs +0 -96
- package/dist/deepEqual.d.ts +0 -21
- package/dist/deepEqual.js +0 -8
- package/dist/deepReplaceValues.cjs +0 -87
- package/dist/deepReplaceValues.d.ts +0 -27
- package/dist/deepReplaceValues.js +0 -7
- package/dist/enhancedMap.cjs +0 -131
- package/dist/enhancedMap.d.cts +0 -20
- package/dist/enhancedMap.d.ts +0 -20
- package/dist/enhancedMap.js +0 -10
- package/dist/exhaustiveMatch.cjs +0 -66
- package/dist/exhaustiveMatch.d.cts +0 -9
- package/dist/exhaustiveMatch.d.ts +0 -9
- package/dist/exhaustiveMatch.js +0 -40
- package/dist/filterObjectOrArrayKeys.cjs +0 -619
- package/dist/filterObjectOrArrayKeys.d.ts +0 -88
- package/dist/filterObjectOrArrayKeys.js +0 -9
- package/dist/getAutoIncrementId.cjs +0 -44
- package/dist/getAutoIncrementId.d.ts +0 -46
- package/dist/getAutoIncrementId.js +0 -18
- package/dist/getCompositeKey.cjs +0 -86
- package/dist/getCompositeKey.d.ts +0 -11
- package/dist/getCompositeKey.js +0 -8
- package/dist/getValueStableKey.cjs +0 -89
- package/dist/getValueStableKey.d.ts +0 -15
- package/dist/getValueStableKey.js +0 -11
- package/dist/hash.cjs +0 -57
- package/dist/hash.d.ts +0 -7
- package/dist/hash.js +0 -32
- package/dist/interpolate.cjs +0 -88
- package/dist/interpolate.d.cts +0 -11
- package/dist/interpolate.d.ts +0 -11
- package/dist/interpolate.js +0 -46
- package/dist/iteratorUtils.cjs +0 -73
- package/dist/iteratorUtils.d.ts +0 -10
- package/dist/iteratorUtils.js +0 -44
- package/dist/keepPrevIfUnchanged.cjs +0 -102
- package/dist/keepPrevIfUnchanged.d.cts +0 -7
- package/dist/keepPrevIfUnchanged.d.ts +0 -7
- package/dist/keepPrevIfUnchanged.js +0 -7
- package/dist/keyedMap.cjs +0 -224
- package/dist/keyedMap.d.cts +0 -75
- package/dist/keyedMap.d.ts +0 -75
- package/dist/keyedMap.js +0 -145
- package/dist/keyedSet.cjs +0 -205
- package/dist/keyedSet.d.cts +0 -76
- package/dist/keyedSet.d.ts +0 -76
- package/dist/keyedSet.js +0 -126
- package/dist/levenshtein.cjs +0 -180
- package/dist/levenshtein.d.ts +0 -5
- package/dist/levenshtein.js +0 -153
- package/dist/main.cjs +0 -32
- package/dist/main.d.cts +0 -3
- package/dist/main.d.ts +0 -3
- package/dist/main.js +0 -7
- package/dist/matchPath.cjs +0 -155
- package/dist/matchPath.d.cts +0 -53
- package/dist/matchPath.d.ts +0 -53
- package/dist/matchPath.js +0 -108
- package/dist/mathUtils.cjs +0 -81
- package/dist/mathUtils.d.ts +0 -54
- package/dist/mathUtils.js +0 -22
- package/dist/mutationUtils.cjs +0 -153
- package/dist/mutationUtils.d.ts +0 -15
- package/dist/mutationUtils.js +0 -55
- package/dist/objUtils.cjs +0 -242
- package/dist/objUtils.d.cts +0 -28
- package/dist/objUtils.js +0 -38
- package/dist/parallelAsyncCalls.cjs +0 -162
- package/dist/parallelAsyncCalls.d.cts +0 -82
- package/dist/parallelAsyncCalls.d.ts +0 -82
- package/dist/parallelAsyncCalls.js +0 -126
- package/dist/partialEqual.cjs +0 -1196
- package/dist/partialEqual.d.cts +0 -141
- package/dist/partialEqual.d.ts +0 -141
- package/dist/partialEqual.js +0 -1168
- package/dist/promiseUtils.cjs +0 -38
- package/dist/promiseUtils.d.cts +0 -8
- package/dist/promiseUtils.d.ts +0 -8
- package/dist/promiseUtils.js +0 -6
- package/dist/regexUtils.cjs +0 -60
- package/dist/regexUtils.d.cts +0 -17
- package/dist/regexUtils.d.ts +0 -17
- package/dist/regexUtils.js +0 -33
- package/dist/retryOnError.cjs +0 -130
- package/dist/retryOnError.d.ts +0 -83
- package/dist/retryOnError.js +0 -101
- package/dist/runShellCmd.cjs +0 -127
- package/dist/runShellCmd.d.cts +0 -90
- package/dist/runShellCmd.js +0 -98
- package/dist/safeJson.cjs +0 -45
- package/dist/safeJson.d.ts +0 -16
- package/dist/safeJson.js +0 -8
- package/dist/saferTyping.cjs +0 -52
- package/dist/saferTyping.d.ts +0 -47
- package/dist/saferTyping.js +0 -23
- package/dist/serializeXML.cjs +0 -154
- package/dist/serializeXML.d.cts +0 -22
- package/dist/serializeXML.d.ts +0 -22
- package/dist/serializeXML.js +0 -116
- package/dist/shallowEqual.cjs +0 -88
- package/dist/shallowEqual.d.ts +0 -4
- package/dist/shallowEqual.js +0 -63
- package/dist/sleep.cjs +0 -32
- package/dist/sleep.d.cts +0 -3
- package/dist/sleep.d.ts +0 -3
- package/dist/sleep.js +0 -6
- package/dist/stringUtils.cjs +0 -155
- package/dist/stringUtils.d.ts +0 -55
- package/dist/stringUtils.js +0 -50
- package/dist/testUtils.cjs +0 -1490
- package/dist/testUtils.d.cts +0 -133
- package/dist/testUtils.js +0 -359
- package/dist/throttle.cjs +0 -282
- package/dist/throttle.d.cts +0 -98
- package/dist/throttle.js +0 -38
- package/dist/time.cjs +0 -152
- package/dist/time.d.cts +0 -25
- package/dist/time.js +0 -38
- package/dist/timers.cjs +0 -194
- package/dist/timers.d.ts +0 -121
- package/dist/timers.js +0 -156
- package/dist/tsResult.cjs +0 -226
- package/dist/tsResult.d.ts +0 -114
- package/dist/tsResult.js +0 -180
- package/dist/typeGuards.cjs +0 -70
- package/dist/typeGuards.d.ts +0 -111
- package/dist/typeGuards.js +0 -18
- package/dist/typeUtils.cjs +0 -18
- package/dist/typeUtils.d.cts +0 -61
- package/dist/typeUtils.js +0 -0
- package/dist/typedStrings.cjs +0 -90
- package/dist/typedStrings.d.ts +0 -163
- package/dist/typedStrings.js +0 -57
- package/dist/typingFnUtils.cjs +0 -96
- package/dist/typingFnUtils.d.ts +0 -100
- package/dist/typingFnUtils.js +0 -30
- package/dist/typingTestUtils.cjs +0 -52
- package/dist/typingTestUtils.d.ts +0 -79
- package/dist/typingTestUtils.js +0 -27
- package/dist/typingUtils.cjs +0 -18
- package/dist/typingUtils.d.cts +0 -35
- package/dist/typingUtils.d.ts +0 -35
- package/dist/typingUtils.js +0 -0
- package/dist/yamlStringify.cjs +0 -423
- package/dist/yamlStringify.d.cts +0 -10
- package/dist/yamlStringify.d.ts +0 -10
- package/dist/yamlStringify.js +0 -9
|
@@ -1,61 +1,66 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Result, ResultValidErrors } from "t-result";
|
|
2
2
|
|
|
3
|
+
//#region src/concurrentCalls.d.ts
|
|
3
4
|
declare class ConcurrentCallsAggregateError extends AggregateError {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
errors: ResultValidErrors[];
|
|
6
|
+
total: number;
|
|
7
|
+
failed: number;
|
|
8
|
+
constructor(errors: ResultValidErrors[], total: number, failed: number);
|
|
8
9
|
}
|
|
9
10
|
declare class ConcurrentCallsWithMetadataAggregateError<M extends ValidMetadata> extends AggregateError {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
errors: ResultValidErrors[];
|
|
12
|
+
errorsWithMetadata: {
|
|
13
|
+
error: ResultValidErrors;
|
|
14
|
+
metadata: M;
|
|
15
|
+
}[];
|
|
16
|
+
total: number;
|
|
17
|
+
failed: number;
|
|
18
|
+
constructor(errors: {
|
|
19
|
+
error: ResultValidErrors;
|
|
20
|
+
metadata: M;
|
|
21
|
+
}[], total: number, failed: number);
|
|
21
22
|
}
|
|
22
23
|
type ValidMetadata = string | number | boolean | Record<string, unknown>;
|
|
23
24
|
type RunProps = {
|
|
24
|
-
|
|
25
|
+
delayStart?: (index: number) => number;
|
|
25
26
|
};
|
|
26
27
|
type SucceededCall<R, M> = {
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
value: R;
|
|
29
|
+
metadata: M;
|
|
29
30
|
};
|
|
30
31
|
type FailedCall<M, E extends ResultValidErrors = Error> = {
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
metadata: M;
|
|
33
|
+
error: E;
|
|
33
34
|
};
|
|
34
35
|
type Action<R, E extends ResultValidErrors> = () => Promise<Result<R, E>>;
|
|
35
36
|
type SettledResultWithMetadata<R, M, E extends ResultValidErrors = Error> = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
ok: true;
|
|
38
|
+
value: R;
|
|
39
|
+
metadata: M;
|
|
40
|
+
error: false;
|
|
40
41
|
} | {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
ok: false;
|
|
43
|
+
error: E;
|
|
44
|
+
metadata: M;
|
|
44
45
|
};
|
|
45
46
|
declare class ConcurrentCalls<R = unknown, E extends ResultValidErrors = Error> {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
#private;
|
|
48
|
+
allowResultify: boolean;
|
|
49
|
+
constructor(allowResultify: boolean);
|
|
50
|
+
add(...calls: Action<R, E>[]): this;
|
|
51
|
+
resultifyAdd(...calls: ((() => R) | (() => Promise<R>))[]): this;
|
|
52
|
+
runAll({
|
|
53
|
+
delayStart
|
|
54
|
+
}?: RunProps): Promise<Result<R[], E>>;
|
|
55
|
+
runAllSettled({
|
|
56
|
+
delayStart
|
|
57
|
+
}?: RunProps): Promise<{
|
|
58
|
+
allFailed: boolean;
|
|
59
|
+
failures: E[];
|
|
60
|
+
succeeded: R[];
|
|
61
|
+
total: number;
|
|
62
|
+
aggregatedError: ConcurrentCallsAggregateError | null;
|
|
63
|
+
}>;
|
|
59
64
|
}
|
|
60
65
|
/**
|
|
61
66
|
* Executes multiple asynchronous calls concurrently and collects the results in
|
|
@@ -65,28 +70,32 @@ declare class ConcurrentCalls<R = unknown, E extends ResultValidErrors = Error>
|
|
|
65
70
|
*/
|
|
66
71
|
declare function concurrentCalls<R = unknown>(): ConcurrentCalls<R, Error>;
|
|
67
72
|
declare class ConcurrentCallsWithMetadata<M extends ValidMetadata, R = unknown, E extends ResultValidErrors = Error> {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
73
|
+
#private;
|
|
74
|
+
allowResultify: boolean;
|
|
75
|
+
constructor(allowResultify: boolean);
|
|
76
|
+
add(...calls: {
|
|
77
|
+
fn: Action<R, E>;
|
|
78
|
+
metadata: M;
|
|
79
|
+
}[]): this;
|
|
80
|
+
resultifyAdd(...items: {
|
|
81
|
+
fn: (() => R) | (() => Promise<R>);
|
|
82
|
+
metadata: M;
|
|
83
|
+
}[]): this;
|
|
84
|
+
runAll({
|
|
85
|
+
delayStart
|
|
86
|
+
}?: RunProps): Promise<Result<SucceededCall<R, M>[], FailedCall<M, E>>>;
|
|
87
|
+
runAllSettled({
|
|
88
|
+
delayStart
|
|
89
|
+
}?: RunProps): Promise<{
|
|
90
|
+
allFailed: boolean;
|
|
91
|
+
/** @deprecated Use failures property instead */
|
|
92
|
+
failed: FailedCall<M, E>[];
|
|
93
|
+
failures: FailedCall<M, E>[];
|
|
94
|
+
succeeded: SucceededCall<R, M>[];
|
|
95
|
+
total: number;
|
|
96
|
+
results: SettledResultWithMetadata<R, M, E>[];
|
|
97
|
+
aggregatedError: ConcurrentCallsWithMetadataAggregateError<M> | null;
|
|
98
|
+
}>;
|
|
90
99
|
}
|
|
91
100
|
/**
|
|
92
101
|
* Executes multiple asynchronous calls concurrently with metadata for each call
|
|
@@ -112,5 +121,5 @@ declare function concurrentResultCalls<ResultFn extends (...args: any[]) => Prom
|
|
|
112
121
|
* @template ResultFn - The type of the result function that will be called.
|
|
113
122
|
*/
|
|
114
123
|
declare function concurrentResultsWithMetadata<M extends ValidMetadata, ResultFn extends (...args: any[]) => Promise<Result<unknown, ResultValidErrors>>>(): ConcurrentCallsWithMetadata<M, ValueFromResult<Awaited<ReturnType<ResultFn>>>, ErrorFromResult<Awaited<ReturnType<ResultFn>>>>;
|
|
115
|
-
|
|
116
|
-
export { ConcurrentCallsAggregateError, ConcurrentCallsWithMetadataAggregateError, concurrentCalls, concurrentCallsWithMetadata, concurrentResultCalls, concurrentResultsWithMetadata };
|
|
124
|
+
//#endregion
|
|
125
|
+
export { ConcurrentCallsAggregateError, ConcurrentCallsWithMetadataAggregateError, concurrentCalls, concurrentCallsWithMetadata, concurrentResultCalls, concurrentResultsWithMetadata };
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { i as isObject, o as isPromise } from "./typeGuards-B1mzA-Rz.mjs";
|
|
2
|
+
import { i as invariant } from "./assertions-qMxfVhSu.mjs";
|
|
3
|
+
import { truncateArray } from "./arrayUtils.mjs";
|
|
4
|
+
import { safeJsonStringify } from "./safeJson.mjs";
|
|
5
|
+
import { sleep } from "./sleep.mjs";
|
|
6
|
+
import { C as truncateString } from "./stringUtils-DjhWOiYn.mjs";
|
|
7
|
+
import { Result, resultify, unknownToError } from "t-result";
|
|
8
|
+
|
|
9
|
+
//#region src/concurrentCalls.ts
|
|
10
|
+
function formatErrorMessagesWithCounts(messages, failed, total) {
|
|
11
|
+
const errorMessageCounts = /* @__PURE__ */ new Map();
|
|
12
|
+
for (const message of messages) errorMessageCounts.set(message, (errorMessageCounts.get(message) || 0) + 1);
|
|
13
|
+
return `${failed}/${total} calls failed:\n${truncateArray(Array.from(errorMessageCounts.entries()).map(([message, count]) => count > 1 ? `${message} (${count}x)` : message), 5, "...").join("\n")}`;
|
|
14
|
+
}
|
|
15
|
+
var ConcurrentCallsAggregateError = class extends AggregateError {
|
|
16
|
+
errors = [];
|
|
17
|
+
total = 0;
|
|
18
|
+
failed = 0;
|
|
19
|
+
constructor(errors, total, failed) {
|
|
20
|
+
const message = formatErrorMessagesWithCounts(errors.map((error) => `- ${truncateString(error instanceof Error ? error.message : safeJsonStringify(error) ?? "???", 100)}`), failed, total);
|
|
21
|
+
super(errors, message);
|
|
22
|
+
this.errors = errors;
|
|
23
|
+
this.total = total;
|
|
24
|
+
this.failed = failed;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var ConcurrentCallsWithMetadataAggregateError = class extends AggregateError {
|
|
28
|
+
errors = [];
|
|
29
|
+
errorsWithMetadata = [];
|
|
30
|
+
total = 0;
|
|
31
|
+
failed = 0;
|
|
32
|
+
constructor(errors, total, failed) {
|
|
33
|
+
const message = formatErrorMessagesWithCounts(errors.map(({ error, metadata }) => {
|
|
34
|
+
let metadataPrefix = typeof metadata === "string" || typeof metadata === "number" || typeof metadata === "boolean" ? `${metadata}: ` : "";
|
|
35
|
+
try {
|
|
36
|
+
const isArray = Array.isArray(metadata);
|
|
37
|
+
if (isObject(metadata) || isArray) {
|
|
38
|
+
const stringifiedMetadata = JSON.stringify(metadata);
|
|
39
|
+
if (stringifiedMetadata.length < 30) metadataPrefix = `${stringifiedMetadata}: `;
|
|
40
|
+
else metadataPrefix = `[${isArray ? "Array" : "Object"} metadata]: `;
|
|
41
|
+
}
|
|
42
|
+
} catch (_) {}
|
|
43
|
+
return `- ${metadataPrefix}${truncateString(error instanceof Error ? error.message : safeJsonStringify(error) ?? "???", 100)}`;
|
|
44
|
+
}), failed, total);
|
|
45
|
+
const errorInstances = errors.map((e) => e.error);
|
|
46
|
+
super(errorInstances, message);
|
|
47
|
+
this.errors = errorInstances;
|
|
48
|
+
this.errorsWithMetadata = errors;
|
|
49
|
+
this.total = total;
|
|
50
|
+
this.failed = failed;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var ConcurrentCalls = class {
|
|
54
|
+
#pendingCalls = [];
|
|
55
|
+
#alreadyRun = false;
|
|
56
|
+
allowResultify = true;
|
|
57
|
+
constructor(allowResultify) {
|
|
58
|
+
this.allowResultify = allowResultify;
|
|
59
|
+
}
|
|
60
|
+
add(...calls) {
|
|
61
|
+
this.#pendingCalls.push(...calls);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
resultifyAdd(...calls) {
|
|
65
|
+
if (!this.allowResultify) throw new Error("resultifyAdd is not allowed when using concurrentResults");
|
|
66
|
+
const processedCalls = calls.map((call) => {
|
|
67
|
+
return async () => {
|
|
68
|
+
try {
|
|
69
|
+
const valueOrPromise = call();
|
|
70
|
+
const value = isPromise(valueOrPromise) ? await valueOrPromise : valueOrPromise;
|
|
71
|
+
return Result.ok(value);
|
|
72
|
+
} catch (err$1) {
|
|
73
|
+
return Result.err(unknownToError(err$1));
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
return this.add(...processedCalls);
|
|
78
|
+
}
|
|
79
|
+
async runAll({ delayStart } = {}) {
|
|
80
|
+
invariant(!this.#alreadyRun, "Already run");
|
|
81
|
+
this.#alreadyRun = true;
|
|
82
|
+
try {
|
|
83
|
+
const asyncResults = await Promise.all(this.#pendingCalls.map(async (fn, i) => {
|
|
84
|
+
try {
|
|
85
|
+
if (delayStart) await sleep(delayStart(i));
|
|
86
|
+
const result = await fn();
|
|
87
|
+
if (!result.ok) throw result.error;
|
|
88
|
+
return result.value;
|
|
89
|
+
} catch (exception) {
|
|
90
|
+
throw unknownToError(exception);
|
|
91
|
+
}
|
|
92
|
+
}));
|
|
93
|
+
return Result.ok(asyncResults);
|
|
94
|
+
} catch (exception) {
|
|
95
|
+
return Result.err(unknownToError(exception));
|
|
96
|
+
} finally {
|
|
97
|
+
this.#pendingCalls = [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async runAllSettled({ delayStart } = {}) {
|
|
101
|
+
invariant(!this.#alreadyRun, "Already run");
|
|
102
|
+
this.#alreadyRun = true;
|
|
103
|
+
const total = this.#pendingCalls.length;
|
|
104
|
+
const settledResults = await Promise.allSettled(this.#pendingCalls.map(async (callOrPromise, i) => {
|
|
105
|
+
try {
|
|
106
|
+
if (delayStart) await sleep(delayStart(i));
|
|
107
|
+
const result = await callOrPromise();
|
|
108
|
+
if (!result.ok) throw result.error;
|
|
109
|
+
return result.value;
|
|
110
|
+
} catch (exception) {
|
|
111
|
+
throw unknownToError(exception);
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
114
|
+
const succeeded = [];
|
|
115
|
+
const failed = [];
|
|
116
|
+
for (const settledResult of settledResults) if (settledResult.status === "fulfilled") succeeded.push(settledResult.value);
|
|
117
|
+
else failed.push(settledResult.reason);
|
|
118
|
+
const allFailed = failed.length === total;
|
|
119
|
+
const aggregatedError = failed.length > 0 ? new ConcurrentCallsAggregateError(failed, total, failed.length) : null;
|
|
120
|
+
this.#pendingCalls = [];
|
|
121
|
+
return {
|
|
122
|
+
succeeded,
|
|
123
|
+
failures: failed,
|
|
124
|
+
allFailed,
|
|
125
|
+
total,
|
|
126
|
+
aggregatedError
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Executes multiple asynchronous calls concurrently and collects the results in
|
|
132
|
+
* a easier to use format.
|
|
133
|
+
*
|
|
134
|
+
* @template R - The type of the result value.
|
|
135
|
+
*/
|
|
136
|
+
function concurrentCalls() {
|
|
137
|
+
return new ConcurrentCalls(true);
|
|
138
|
+
}
|
|
139
|
+
var ConcurrentCallsWithMetadata = class {
|
|
140
|
+
#pendingCalls = [];
|
|
141
|
+
#alreadyRun = false;
|
|
142
|
+
allowResultify = true;
|
|
143
|
+
constructor(allowResultify) {
|
|
144
|
+
this.allowResultify = allowResultify;
|
|
145
|
+
}
|
|
146
|
+
add(...calls) {
|
|
147
|
+
invariant(!this.#alreadyRun, "Cannot add calls after execution has started.");
|
|
148
|
+
this.#pendingCalls.push(...calls);
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
resultifyAdd(...items) {
|
|
152
|
+
if (!this.allowResultify) throw new Error("resultifyAdd is not allowed when using concurrentResultsWithMetadata");
|
|
153
|
+
const processedItems = items.map(({ fn, metadata }) => {
|
|
154
|
+
const cb = () => resultify(async () => {
|
|
155
|
+
const valueOrPromise = fn();
|
|
156
|
+
return isPromise(valueOrPromise) ? await valueOrPromise : valueOrPromise;
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
fn: cb,
|
|
160
|
+
metadata
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
return this.add(...processedItems);
|
|
164
|
+
}
|
|
165
|
+
async runAll({ delayStart } = {}) {
|
|
166
|
+
invariant(!this.#alreadyRun, "Already run");
|
|
167
|
+
this.#alreadyRun = true;
|
|
168
|
+
const currentCalls = [...this.#pendingCalls];
|
|
169
|
+
this.#pendingCalls = [];
|
|
170
|
+
try {
|
|
171
|
+
const successfulResults = [];
|
|
172
|
+
for (let i = 0; i < currentCalls.length; i++) {
|
|
173
|
+
const call = currentCalls[i];
|
|
174
|
+
try {
|
|
175
|
+
if (delayStart) await sleep(delayStart(i));
|
|
176
|
+
const result = await call.fn();
|
|
177
|
+
if (!result.ok) throw {
|
|
178
|
+
metadata: call.metadata,
|
|
179
|
+
error: result.error
|
|
180
|
+
};
|
|
181
|
+
successfulResults.push({
|
|
182
|
+
value: result.value,
|
|
183
|
+
metadata: call.metadata
|
|
184
|
+
});
|
|
185
|
+
} catch (exception) {
|
|
186
|
+
if (typeof exception === "object" && exception !== null && "metadata" in exception && "error" in exception && exception.metadata === call.metadata) throw exception;
|
|
187
|
+
else throw {
|
|
188
|
+
metadata: call.metadata,
|
|
189
|
+
error: unknownToError(exception)
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return Result.ok(successfulResults);
|
|
194
|
+
} catch (errorPayload) {
|
|
195
|
+
return Result.err(errorPayload);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async runAllSettled({ delayStart } = {}) {
|
|
199
|
+
invariant(!this.#alreadyRun, "Already run");
|
|
200
|
+
this.#alreadyRun = true;
|
|
201
|
+
const currentCalls = [...this.#pendingCalls];
|
|
202
|
+
this.#pendingCalls = [];
|
|
203
|
+
const total = currentCalls.length;
|
|
204
|
+
if (total === 0) return {
|
|
205
|
+
succeeded: [],
|
|
206
|
+
failed: [],
|
|
207
|
+
failures: [],
|
|
208
|
+
results: [],
|
|
209
|
+
allFailed: false,
|
|
210
|
+
total: 0,
|
|
211
|
+
aggregatedError: null
|
|
212
|
+
};
|
|
213
|
+
const settledOutcomes = await Promise.allSettled(currentCalls.map(async (call, i) => {
|
|
214
|
+
try {
|
|
215
|
+
if (delayStart) await sleep(delayStart(i));
|
|
216
|
+
const result = await call.fn();
|
|
217
|
+
if (!result.ok) throw result.error;
|
|
218
|
+
return result.value;
|
|
219
|
+
} catch (innerException) {
|
|
220
|
+
throw unknownToError(innerException);
|
|
221
|
+
}
|
|
222
|
+
}));
|
|
223
|
+
const succeededProcessing = [];
|
|
224
|
+
const failedProcessing = [];
|
|
225
|
+
const resultsProcessing = [];
|
|
226
|
+
for (let i = 0; i < settledOutcomes.length; i++) {
|
|
227
|
+
const outcome = settledOutcomes[i];
|
|
228
|
+
const { metadata } = currentCalls[i];
|
|
229
|
+
if (outcome.status === "fulfilled") {
|
|
230
|
+
const value = outcome.value;
|
|
231
|
+
succeededProcessing.push({
|
|
232
|
+
value,
|
|
233
|
+
metadata
|
|
234
|
+
});
|
|
235
|
+
resultsProcessing.push({
|
|
236
|
+
ok: true,
|
|
237
|
+
value,
|
|
238
|
+
metadata,
|
|
239
|
+
error: false
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
const error = outcome.reason;
|
|
243
|
+
failedProcessing.push({
|
|
244
|
+
error,
|
|
245
|
+
metadata
|
|
246
|
+
});
|
|
247
|
+
resultsProcessing.push({
|
|
248
|
+
ok: false,
|
|
249
|
+
error,
|
|
250
|
+
metadata
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
succeeded: succeededProcessing,
|
|
256
|
+
failed: failedProcessing,
|
|
257
|
+
failures: failedProcessing,
|
|
258
|
+
results: resultsProcessing,
|
|
259
|
+
allFailed: failedProcessing.length === total,
|
|
260
|
+
total,
|
|
261
|
+
aggregatedError: failedProcessing.length > 0 ? new ConcurrentCallsWithMetadataAggregateError(failedProcessing, total, failedProcessing.length) : null
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* Executes multiple asynchronous calls concurrently with metadata for each call
|
|
267
|
+
* and collects the results in a easier to use format.
|
|
268
|
+
*
|
|
269
|
+
* @template M - The type of the call metadata.
|
|
270
|
+
* @template R - The type of the result value.
|
|
271
|
+
*/
|
|
272
|
+
function concurrentCallsWithMetadata() {
|
|
273
|
+
return new ConcurrentCallsWithMetadata(true);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Executes multiple asynchronous result calls concurrently and collects the
|
|
277
|
+
* results in a easier to use format.
|
|
278
|
+
*
|
|
279
|
+
* @template R - The type of the result function that will be called.
|
|
280
|
+
*/
|
|
281
|
+
function concurrentResultCalls() {
|
|
282
|
+
return new ConcurrentCalls(false);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Executes multiple asynchronous result calls concurrently with metadata for
|
|
286
|
+
* each call and collects the results in a easier to use format.
|
|
287
|
+
*
|
|
288
|
+
* @template ResultFn - The type of the result function that will be called.
|
|
289
|
+
*/
|
|
290
|
+
function concurrentResultsWithMetadata() {
|
|
291
|
+
return new ConcurrentCallsWithMetadata(false);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
//#endregion
|
|
295
|
+
export { ConcurrentCallsAggregateError, ConcurrentCallsWithMetadataAggregateError, concurrentCalls, concurrentCallsWithMetadata, concurrentResultCalls, concurrentResultsWithMetadata };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//#region src/consoleFmt.d.ts
|
|
2
|
+
declare const colorToCodeASCII: {
|
|
3
|
+
red: string;
|
|
4
|
+
green: string;
|
|
5
|
+
yellow: string;
|
|
6
|
+
blue: string;
|
|
7
|
+
magenta: string;
|
|
8
|
+
cyan: string;
|
|
9
|
+
white: string;
|
|
10
|
+
black: string;
|
|
11
|
+
gray: string;
|
|
12
|
+
brightRed: string;
|
|
13
|
+
brightGreen: string;
|
|
14
|
+
brightYellow: string;
|
|
15
|
+
brightBlue: string;
|
|
16
|
+
brightMagenta: string;
|
|
17
|
+
brightCyan: string;
|
|
18
|
+
brightWhite: string;
|
|
19
|
+
};
|
|
20
|
+
/** @deprecated Use `styleText` from `node:util` instead. */
|
|
21
|
+
declare function consoleColors(color: keyof typeof colorToCodeASCII, text: string): string;
|
|
22
|
+
/** @deprecated Use `styleText` from `node:util` instead. */
|
|
23
|
+
declare function bold(text: string): string;
|
|
24
|
+
/** @deprecated Use `styleText` from `node:util` instead. */
|
|
25
|
+
declare function underline(text: string): string;
|
|
26
|
+
declare const bgColorToCodeASCII: {
|
|
27
|
+
red: string;
|
|
28
|
+
green: string;
|
|
29
|
+
yellow: string;
|
|
30
|
+
blue: string;
|
|
31
|
+
magenta: string;
|
|
32
|
+
cyan: string;
|
|
33
|
+
white: string;
|
|
34
|
+
black: string;
|
|
35
|
+
gray: string;
|
|
36
|
+
brightRed: string;
|
|
37
|
+
brightGreen: string;
|
|
38
|
+
brightYellow: string;
|
|
39
|
+
brightBlue: string;
|
|
40
|
+
brightMagenta: string;
|
|
41
|
+
brightCyan: string;
|
|
42
|
+
brightWhite: string;
|
|
43
|
+
};
|
|
44
|
+
/** @deprecated Use `styleText` from `node:util` instead. */
|
|
45
|
+
declare function bgColor(color: keyof typeof bgColorToCodeASCII, text: string): string;
|
|
46
|
+
/** @deprecated Use `styleText` from `node:util` instead. */
|
|
47
|
+
declare const consoleFmt: {
|
|
48
|
+
/** @deprecated Use `styleText` from `node:util` instead. */
|
|
49
|
+
color: typeof consoleColors;
|
|
50
|
+
bold: typeof bold;
|
|
51
|
+
underline: typeof underline;
|
|
52
|
+
bgColor: typeof bgColor;
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { consoleFmt };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//#region src/consoleFmt.ts
|
|
2
|
+
const colorToCodeASCII = {
|
|
3
|
+
red: "\x1B[31m",
|
|
4
|
+
green: "\x1B[32m",
|
|
5
|
+
yellow: "\x1B[33m",
|
|
6
|
+
blue: "\x1B[34m",
|
|
7
|
+
magenta: "\x1B[35m",
|
|
8
|
+
cyan: "\x1B[36m",
|
|
9
|
+
white: "\x1B[37m",
|
|
10
|
+
black: "\x1B[30m",
|
|
11
|
+
gray: "\x1B[90m",
|
|
12
|
+
brightRed: "\x1B[91m",
|
|
13
|
+
brightGreen: "\x1B[92m",
|
|
14
|
+
brightYellow: "\x1B[93m",
|
|
15
|
+
brightBlue: "\x1B[94m",
|
|
16
|
+
brightMagenta: "\x1B[95m",
|
|
17
|
+
brightCyan: "\x1B[96m",
|
|
18
|
+
brightWhite: "\x1B[97m"
|
|
19
|
+
};
|
|
20
|
+
/** @deprecated Use `styleText` from `node:util` instead. */
|
|
21
|
+
function consoleColors(color, text) {
|
|
22
|
+
return `${colorToCodeASCII[color]}${text}\x1b[0m`;
|
|
23
|
+
}
|
|
24
|
+
/** @deprecated Use `styleText` from `node:util` instead. */
|
|
25
|
+
function bold(text) {
|
|
26
|
+
return `\x1b[1m${text}\x1b[0m`;
|
|
27
|
+
}
|
|
28
|
+
/** @deprecated Use `styleText` from `node:util` instead. */
|
|
29
|
+
function underline(text) {
|
|
30
|
+
return `\x1b[4m${text}\x1b[0m`;
|
|
31
|
+
}
|
|
32
|
+
const bgColorToCodeASCII = {
|
|
33
|
+
red: "\x1B[41m",
|
|
34
|
+
green: "\x1B[42m",
|
|
35
|
+
yellow: "\x1B[43m",
|
|
36
|
+
blue: "\x1B[44m",
|
|
37
|
+
magenta: "\x1B[45m",
|
|
38
|
+
cyan: "\x1B[46m",
|
|
39
|
+
white: "\x1B[47m",
|
|
40
|
+
black: "\x1B[40m",
|
|
41
|
+
gray: "\x1B[100m",
|
|
42
|
+
brightRed: "\x1B[101m",
|
|
43
|
+
brightGreen: "\x1B[102m",
|
|
44
|
+
brightYellow: "\x1B[103m",
|
|
45
|
+
brightBlue: "\x1B[104m",
|
|
46
|
+
brightMagenta: "\x1B[105m",
|
|
47
|
+
brightCyan: "\x1B[106m",
|
|
48
|
+
brightWhite: "\x1B[107m"
|
|
49
|
+
};
|
|
50
|
+
/** @deprecated Use `styleText` from `node:util` instead. */
|
|
51
|
+
function bgColor(color, text) {
|
|
52
|
+
return `${bgColorToCodeASCII[color]}${text}[49m\x1b[0m`;
|
|
53
|
+
}
|
|
54
|
+
/** @deprecated Use `styleText` from `node:util` instead. */
|
|
55
|
+
const consoleFmt = {
|
|
56
|
+
color: consoleColors,
|
|
57
|
+
bold,
|
|
58
|
+
underline,
|
|
59
|
+
bgColor
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { consoleFmt };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/conversions.ts
|
|
2
|
+
function bytesToHumanReadable(bytes) {
|
|
3
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
4
|
+
const kb = bytes / 1024;
|
|
5
|
+
if (kb < 1024) return `${kb.toFixed(2)} KB`;
|
|
6
|
+
const mb = kb / 1024;
|
|
7
|
+
if (mb < 1024) return `${mb.toFixed(2)} MB`;
|
|
8
|
+
return `${(mb / 1024).toFixed(2)} GB`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { bytesToHumanReadable as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DurationObj } from "./time.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/createThrottleController.d.ts
|
|
4
|
+
type Options = {
|
|
5
|
+
maxCalls: number;
|
|
6
|
+
per: DurationObj;
|
|
7
|
+
cleanupCheckSecsInterval?: number;
|
|
8
|
+
};
|
|
9
|
+
type ThrottleController = {
|
|
10
|
+
shouldSkip: (callId?: string | number | (string | number)[]) => boolean;
|
|
11
|
+
};
|
|
12
|
+
declare function createThrottleController({
|
|
13
|
+
maxCalls,
|
|
14
|
+
per,
|
|
15
|
+
cleanupCheckSecsInterval
|
|
16
|
+
}: Options): ThrottleController;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { createThrottleController };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { p as durationObjToMs } from "./time-sr2lhQRw.mjs";
|
|
2
|
+
import { EnhancedMap } from "./enhancedMap.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/createThrottleController.ts
|
|
5
|
+
function createThrottleController({ maxCalls, per, cleanupCheckSecsInterval = 1800 }) {
|
|
6
|
+
const msInterval = durationObjToMs(per);
|
|
7
|
+
if (msInterval === 0) throw new Error("Invalid interval");
|
|
8
|
+
let lastCleanupCheck = Date.now();
|
|
9
|
+
const windows = new EnhancedMap();
|
|
10
|
+
function cleanup(checkTime) {
|
|
11
|
+
if (!(checkTime - lastCleanupCheck > cleanupCheckSecsInterval * 1e3)) return;
|
|
12
|
+
setTimeout(() => {
|
|
13
|
+
const now = Date.now();
|
|
14
|
+
lastCleanupCheck = now;
|
|
15
|
+
for (const [key, value] of windows) if (now - value.windowStartTime > msInterval) windows.delete(key);
|
|
16
|
+
}, 2);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
shouldSkip(callId = "") {
|
|
20
|
+
const now = Date.now();
|
|
21
|
+
const serializedCallId = String(callId);
|
|
22
|
+
const window = windows.getOrInsert(serializedCallId, () => ({
|
|
23
|
+
windowStartTime: now,
|
|
24
|
+
calls: 0
|
|
25
|
+
}));
|
|
26
|
+
if (now - window.windowStartTime > msInterval) {
|
|
27
|
+
window.windowStartTime = now;
|
|
28
|
+
window.calls = 0;
|
|
29
|
+
}
|
|
30
|
+
window.calls++;
|
|
31
|
+
cleanup(now);
|
|
32
|
+
if (window.calls > maxCalls) return true;
|
|
33
|
+
return false;
|
|
34
|
+
},
|
|
35
|
+
_currentWindows: windows
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { createThrottleController };
|