@dereekb/util 13.0.7 → 13.2.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/fetch/package.json +2 -2
- package/index.cjs.js +4107 -1516
- package/index.esm.js +4107 -1516
- package/package.json +1 -2
- package/src/lib/array/array.d.ts +92 -47
- package/src/lib/array/array.find.d.ts +14 -18
- package/src/lib/array/array.index.d.ts +43 -14
- package/src/lib/array/array.indexed.d.ts +66 -17
- package/src/lib/array/array.limit.d.ts +11 -0
- package/src/lib/array/array.make.d.ts +9 -3
- package/src/lib/array/array.map.d.ts +20 -8
- package/src/lib/array/array.number.d.ts +63 -5
- package/src/lib/array/array.random.d.ts +12 -9
- package/src/lib/array/array.set.d.ts +24 -1
- package/src/lib/array/array.string.d.ts +104 -0
- package/src/lib/array/array.unique.d.ts +60 -8
- package/src/lib/array/array.value.d.ts +20 -11
- package/src/lib/assertion/assertion.d.ts +30 -2
- package/src/lib/assertion/assertion.generic.d.ts +8 -0
- package/src/lib/assertion/assertion.number.d.ts +16 -0
- package/src/lib/auth/auth.role.claims.d.ts +14 -8
- package/src/lib/boolean.d.ts +54 -1
- package/src/lib/contact/domain.d.ts +22 -4
- package/src/lib/contact/random.d.ts +24 -0
- package/src/lib/date/date.d.ts +8 -13
- package/src/lib/date/hour.d.ts +51 -32
- package/src/lib/date/minute.d.ts +4 -4
- package/src/lib/date/time.d.ts +12 -3
- package/src/lib/date/week.d.ts +77 -10
- package/src/lib/error/error.d.ts +54 -3
- package/src/lib/error/error.server.d.ts +25 -2
- package/src/lib/filter/filter.d.ts +12 -7
- package/src/lib/function/function.boolean.d.ts +4 -4
- package/src/lib/function/function.d.ts +2 -5
- package/src/lib/function/function.forward.d.ts +19 -3
- package/src/lib/getter/getter.cache.d.ts +9 -5
- package/src/lib/getter/getter.d.ts +39 -22
- package/src/lib/getter/getter.map.d.ts +10 -4
- package/src/lib/getter/getter.util.d.ts +3 -3
- package/src/lib/grouping.d.ts +98 -31
- package/src/lib/hash.d.ts +15 -8
- package/src/lib/iterable/iterable.d.ts +62 -50
- package/src/lib/iterable/iterable.map.d.ts +4 -4
- package/src/lib/iterate.d.ts +17 -1
- package/src/lib/key.d.ts +32 -10
- package/src/lib/lifecycle.d.ts +10 -1
- package/src/lib/map/map.d.ts +17 -16
- package/src/lib/map/map.intersection.d.ts +5 -4
- package/src/lib/map/map.key.d.ts +16 -15
- package/src/lib/misc/host.d.ts +6 -3
- package/src/lib/model/id.batch.d.ts +7 -3
- package/src/lib/model/id.factory.d.ts +16 -1
- package/src/lib/model/model.conversion.d.ts +49 -6
- package/src/lib/model/model.conversion.field.d.ts +13 -3
- package/src/lib/model/model.copy.d.ts +11 -0
- package/src/lib/model/model.d.ts +174 -1
- package/src/lib/model/model.modify.d.ts +24 -5
- package/src/lib/nodejs/stream.d.ts +8 -6
- package/src/lib/number/bitwise.dencoder.d.ts +43 -3
- package/src/lib/number/bound.d.ts +34 -5
- package/src/lib/number/dollar.d.ts +13 -6
- package/src/lib/number/factory.d.ts +11 -3
- package/src/lib/number/number.d.ts +55 -32
- package/src/lib/number/random.d.ts +13 -3
- package/src/lib/number/round.d.ts +47 -26
- package/src/lib/number/sort.d.ts +7 -1
- package/src/lib/number/transform.d.ts +16 -0
- package/src/lib/object/object.array.d.ts +16 -2
- package/src/lib/object/object.array.delta.d.ts +6 -2
- package/src/lib/object/object.d.ts +33 -5
- package/src/lib/object/object.empty.d.ts +4 -2
- package/src/lib/object/object.equal.d.ts +21 -4
- package/src/lib/object/object.filter.tuple.d.ts +105 -3
- package/src/lib/object/object.key.d.ts +13 -6
- package/src/lib/object/object.map.d.ts +30 -19
- package/src/lib/page/page.d.ts +21 -0
- package/src/lib/page/page.filter.d.ts +16 -9
- package/src/lib/path/path.d.ts +101 -14
- package/src/lib/path/path.tree.d.ts +16 -0
- package/src/lib/promise/callback.d.ts +18 -0
- package/src/lib/promise/is.d.ts +10 -3
- package/src/lib/promise/map.d.ts +5 -3
- package/src/lib/promise/poll.d.ts +14 -4
- package/src/lib/promise/promise.d.ts +84 -18
- package/src/lib/promise/promise.factory.d.ts +18 -2
- package/src/lib/promise/promise.limit.d.ts +22 -2
- package/src/lib/promise/promise.loop.d.ts +69 -1
- package/src/lib/promise/promise.ref.d.ts +14 -2
- package/src/lib/promise/promise.task.d.ts +8 -4
- package/src/lib/promise/promise.type.d.ts +4 -4
- package/src/lib/promise/use.d.ts +6 -4
- package/src/lib/promise/wait.d.ts +5 -2
- package/src/lib/relation/relation.d.ts +98 -0
- package/src/lib/service/handler.config.d.ts +47 -9
- package/src/lib/service/handler.d.ts +43 -1
- package/src/lib/service/typed.service.d.ts +21 -2
- package/src/lib/set/set.allowed.d.ts +6 -4
- package/src/lib/set/set.d.ts +174 -46
- package/src/lib/set/set.decision.d.ts +4 -2
- package/src/lib/set/set.delta.d.ts +16 -3
- package/src/lib/set/set.hashset.d.ts +43 -0
- package/src/lib/set/set.selection.d.ts +7 -3
- package/src/lib/sort.d.ts +36 -16
- package/src/lib/string/char.d.ts +48 -34
- package/src/lib/string/dencoder.d.ts +84 -13
- package/src/lib/string/factory.d.ts +13 -4
- package/src/lib/string/html.d.ts +7 -6
- package/src/lib/string/mimetype.d.ts +65 -1
- package/src/lib/string/prefix.d.ts +21 -7
- package/src/lib/string/record.d.ts +7 -4
- package/src/lib/string/replace.d.ts +77 -33
- package/src/lib/string/search.d.ts +19 -9
- package/src/lib/string/sort.d.ts +10 -1
- package/src/lib/string/string.d.ts +74 -21
- package/src/lib/string/transform.d.ts +7 -0
- package/src/lib/string/tree.d.ts +91 -29
- package/src/lib/string/url.d.ts +148 -63
- package/src/lib/tree/tree.explore.d.ts +84 -17
- package/src/lib/tree/tree.flatten.d.ts +44 -7
- package/src/lib/type.d.ts +15 -12
- package/src/lib/value/address.d.ts +66 -17
- package/src/lib/value/bound.d.ts +253 -17
- package/src/lib/value/build.d.ts +30 -5
- package/src/lib/value/comparator.d.ts +53 -25
- package/src/lib/value/cron.d.ts +14 -6
- package/src/lib/value/decision.d.ts +57 -13
- package/src/lib/value/equal.d.ts +44 -13
- package/src/lib/value/indexed.d.ts +253 -82
- package/src/lib/value/label.d.ts +16 -5
- package/src/lib/value/map.d.ts +77 -20
- package/src/lib/value/maybe.d.ts +47 -49
- package/src/lib/value/modifier.d.ts +82 -27
- package/src/lib/value/point.d.ts +248 -54
- package/src/lib/value/url.d.ts +10 -3
- package/src/lib/value/use.d.ts +99 -8
- package/src/lib/value/vector.d.ts +71 -9
- package/test/index.cjs.js +86 -23
- package/test/index.esm.js +86 -23
- package/test/package.json +2 -2
- package/test/src/lib/shared/shared.d.ts +31 -5
- package/test/src/lib/shared/shared.fail.d.ts +72 -9
- package/test/src/lib/shared/shared.function.d.ts +40 -2
- package/test/src/lib/shared/shared.wrap.d.ts +20 -1
package/src/lib/page/page.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export declare const FIRST_PAGE = 0;
|
|
|
11
11
|
* Page value used when there are no elements left to load.
|
|
12
12
|
*/
|
|
13
13
|
export declare const FINAL_PAGE = -2;
|
|
14
|
+
/**
|
|
15
|
+
* Numeric page identifier.
|
|
16
|
+
*/
|
|
14
17
|
export type PageNumber = number;
|
|
15
18
|
/**
|
|
16
19
|
* Represents a page number.
|
|
@@ -21,6 +24,24 @@ export interface Page {
|
|
|
21
24
|
*/
|
|
22
25
|
page: PageNumber;
|
|
23
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Extracts the page number from a {@link Page} object, returning {@link UNLOADED_PAGE} if the input is nullish.
|
|
29
|
+
*
|
|
30
|
+
* @param page - Page object to read from
|
|
31
|
+
* @returns The page number, or {@link UNLOADED_PAGE} (-1) if not provided
|
|
32
|
+
*/
|
|
24
33
|
export declare function getPageNumber(page: Maybe<Partial<Page>>): number;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the next sequential page number after the given page.
|
|
36
|
+
*
|
|
37
|
+
* @param page - Current page object
|
|
38
|
+
* @returns The current page number plus one
|
|
39
|
+
*/
|
|
25
40
|
export declare function getNextPageNumber(page: Maybe<Partial<Page>>): number;
|
|
41
|
+
/**
|
|
42
|
+
* Checks whether the given page represents the final page of results.
|
|
43
|
+
*
|
|
44
|
+
* @param page - Page object to check
|
|
45
|
+
* @returns `true` if the page number equals {@link FINAL_PAGE}
|
|
46
|
+
*/
|
|
26
47
|
export declare function isFinalPage(page: Maybe<Partial<Page>>): boolean;
|
|
@@ -12,6 +12,9 @@ export interface FilteredPage<F> extends Page, OptionalFilter<F> {
|
|
|
12
12
|
export interface PageAndFilter<F> extends OptionalFilter<F> {
|
|
13
13
|
page: Page;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Callbacks for iterating over paged results. Provide either `use` (per-item) or `usePage` (per-page).
|
|
17
|
+
*/
|
|
15
18
|
export interface FilteredPageIterateFn<T> {
|
|
16
19
|
/**
|
|
17
20
|
* Uses each value one-by-one.
|
|
@@ -23,19 +26,23 @@ export interface FilteredPageIterateFn<T> {
|
|
|
23
26
|
usePage?: IteratePageFn<T>;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
|
-
* Creates a FilteredPage.
|
|
29
|
+
* Creates a {@link FilteredPage} combining a page number with an optional filter copied from the request.
|
|
27
30
|
*
|
|
28
|
-
* @param page
|
|
29
|
-
* @param request
|
|
30
|
-
* @returns
|
|
31
|
+
* @param page - The page number
|
|
32
|
+
* @param request - Optional filter to copy into the result
|
|
33
|
+
* @returns A new filtered page object
|
|
31
34
|
*/
|
|
32
35
|
export declare function filteredPage<F = unknown>(page: PageNumber, request?: Filter<F>): FilteredPage<F>;
|
|
33
36
|
/**
|
|
34
|
-
*
|
|
37
|
+
* Sequentially loads and iterates through pages of results until an empty page is returned.
|
|
38
|
+
*
|
|
39
|
+
* Starts from the given page and increments the page number after each load. Stops when
|
|
40
|
+
* `loadFn` returns an empty array. Either `iterFn.use` or `iterFn.usePage` must be provided.
|
|
35
41
|
*
|
|
36
|
-
* @param inputPage
|
|
37
|
-
* @param loadFn
|
|
38
|
-
* @param iterFn
|
|
39
|
-
* @returns
|
|
42
|
+
* @param inputPage - Starting page with optional filter
|
|
43
|
+
* @param loadFn - Async function that loads a page of results
|
|
44
|
+
* @param iterFn - Callbacks for processing each item or page
|
|
45
|
+
* @returns The total number of items processed across all pages
|
|
46
|
+
* @throws Error if neither `use` nor `usePage` is specified in `iterFn`
|
|
40
47
|
*/
|
|
41
48
|
export declare function iterateFilteredPages<T, F>(inputPage: FilteredPage<F>, loadFn: (page: FilteredPage<F>) => Promise<T[]>, iterFn: FilteredPageIterateFn<T>): Promise<number>;
|
package/src/lib/path/path.d.ts
CHANGED
|
@@ -81,27 +81,52 @@ export type SlashPathFunction = MapSameFunction<SlashPath>;
|
|
|
81
81
|
*/
|
|
82
82
|
export type SlashPathType = 'folder' | 'file' | 'typedfile' | 'invalid';
|
|
83
83
|
/**
|
|
84
|
-
*
|
|
84
|
+
* Determines the type of a slash path string.
|
|
85
85
|
*
|
|
86
|
-
* @param input
|
|
87
|
-
* @returns
|
|
86
|
+
* @param input - The slash path to classify.
|
|
87
|
+
* @returns The path type classification.
|
|
88
88
|
*/
|
|
89
89
|
export declare function slashPathType(input: SlashPath): SlashPathType;
|
|
90
|
+
/**
|
|
91
|
+
* Type guard that checks if the input is a file path (typed or untyped).
|
|
92
|
+
*
|
|
93
|
+
* @param input - The string to check.
|
|
94
|
+
* @returns Whether the input is a file path.
|
|
95
|
+
*/
|
|
90
96
|
export declare function isSlashPathFile(input: string): input is SlashPathFile;
|
|
97
|
+
/**
|
|
98
|
+
* Type guard that checks if the input is a typed file path (contains a file extension).
|
|
99
|
+
*
|
|
100
|
+
* @param input - The string to check.
|
|
101
|
+
* @returns Whether the input is a typed file path.
|
|
102
|
+
*/
|
|
91
103
|
export declare function isSlashPathTypedFile(input: string): input is SlashPathTypedFile;
|
|
104
|
+
/**
|
|
105
|
+
* Type guard that checks if the input is a folder path (ends with a slash).
|
|
106
|
+
*
|
|
107
|
+
* @param input - The string to check.
|
|
108
|
+
* @returns Whether the input is a folder path.
|
|
109
|
+
*/
|
|
92
110
|
export declare function isSlashPathFolder(input: string): input is SlashPathFolder;
|
|
111
|
+
/**
|
|
112
|
+
* Type guard that checks if the input is a valid slash path (not 'invalid' type).
|
|
113
|
+
*
|
|
114
|
+
* @param input - The string to check.
|
|
115
|
+
* @returns Whether the input is a valid slash path.
|
|
116
|
+
*/
|
|
93
117
|
export declare function isValidSlashPath(input: string): input is SlashPath;
|
|
94
118
|
/**
|
|
95
119
|
* Returns the last part of the slash path.
|
|
96
120
|
*
|
|
97
|
-
* @param slashPath
|
|
121
|
+
* @param slashPath - The path to extract the name from.
|
|
122
|
+
* @returns The last part of the path (file name or folder name).
|
|
98
123
|
*/
|
|
99
124
|
export declare function slashPathName(slashPath: SlashPath): SlashPathPart;
|
|
100
125
|
/**
|
|
101
|
-
* Returns each section of a SlashPath
|
|
126
|
+
* Returns each section of a SlashPath.
|
|
102
127
|
*
|
|
103
|
-
* @param slashPath
|
|
104
|
-
* @returns
|
|
128
|
+
* @param slashPath - The path to split.
|
|
129
|
+
* @returns Array of non-empty path segments.
|
|
105
130
|
*/
|
|
106
131
|
export declare function slashPathParts(slashPath: SlashPath): SlashPathPart[];
|
|
107
132
|
/**
|
|
@@ -115,6 +140,12 @@ export type SlashPathStartType = 'relative' | 'absolute' | 'any';
|
|
|
115
140
|
* Factory use to set the slash path type of the input.
|
|
116
141
|
*/
|
|
117
142
|
export type SlashPathStartTypeFactory = SlashPathFunction;
|
|
143
|
+
/**
|
|
144
|
+
* Creates a function that enforces the specified start type on a slash path.
|
|
145
|
+
*
|
|
146
|
+
* @param type - The start type to enforce.
|
|
147
|
+
* @returns A function that transforms paths to the specified start type.
|
|
148
|
+
*/
|
|
118
149
|
export declare function slashPathStartTypeFactory(type: SlashPathStartType): SlashPathStartTypeFactory;
|
|
119
150
|
export declare const LEADING_SLASHES_REGEX: RegExp;
|
|
120
151
|
export declare const TRAILING_SLASHES_REGEX: RegExp;
|
|
@@ -122,6 +153,12 @@ export declare const TRAILING_FILE_TYPE_SEPARATORS_REGEX: RegExp;
|
|
|
122
153
|
export declare const ALL_SLASHES_REGEX: RegExp;
|
|
123
154
|
export declare const ALL_DOUBLE_SLASHES_REGEX: RegExp;
|
|
124
155
|
export declare const ALL_SLASH_PATH_FILE_TYPE_SEPARATORS_REGEX: RegExp;
|
|
156
|
+
/**
|
|
157
|
+
* Converts a slash path to a relative path by removing all leading slashes.
|
|
158
|
+
*
|
|
159
|
+
* @param input - The slash path to convert.
|
|
160
|
+
* @returns A relative path without leading slashes.
|
|
161
|
+
*/
|
|
125
162
|
export declare function toRelativeSlashPathStartType(input: SlashPath): SlashPath;
|
|
126
163
|
/**
|
|
127
164
|
* Factory function that creates a SlashPathFolder from a string.
|
|
@@ -167,14 +204,39 @@ export declare function slashPathFolderFactory(config?: SlashPathFolderFactoryCo
|
|
|
167
204
|
*/
|
|
168
205
|
export declare function slashPathFolder(input: string, config?: SlashPathFolderFactoryConfig): InferredSlashPathFolder;
|
|
169
206
|
/**
|
|
207
|
+
* Converts a slash path to an absolute path by ensuring exactly one leading slash.
|
|
170
208
|
*
|
|
171
|
-
* @param input
|
|
172
|
-
* @returns
|
|
209
|
+
* @param input - The slash path to convert.
|
|
210
|
+
* @returns An absolute path starting with a single slash.
|
|
173
211
|
*/
|
|
174
212
|
export declare function toAbsoluteSlashPathStartType(input: SlashPath): SlashPath;
|
|
213
|
+
/**
|
|
214
|
+
* Replaces consecutive double slashes with single slashes.
|
|
215
|
+
*
|
|
216
|
+
* @param input - The slash path to fix.
|
|
217
|
+
* @returns The path with double slashes collapsed.
|
|
218
|
+
*/
|
|
175
219
|
export declare function fixMultiSlashesInSlashPath(input: SlashPath): SlashPath;
|
|
220
|
+
/**
|
|
221
|
+
* Replaces consecutive double slashes with single slashes. Alias for {@link fixMultiSlashesInSlashPath}.
|
|
222
|
+
*
|
|
223
|
+
* @param input - The slash path to fix.
|
|
224
|
+
* @returns The path with double slashes collapsed.
|
|
225
|
+
*/
|
|
176
226
|
export declare function replaceMultipleFilePathsInSlashPath(input: SlashPath): SlashPath;
|
|
227
|
+
/**
|
|
228
|
+
* Removes all trailing slashes from a slash path.
|
|
229
|
+
*
|
|
230
|
+
* @param input - The slash path to trim.
|
|
231
|
+
* @returns The path without trailing slashes.
|
|
232
|
+
*/
|
|
177
233
|
export declare function removeTrailingSlashes(input: SlashPath): SlashPath;
|
|
234
|
+
/**
|
|
235
|
+
* Removes all trailing dots from a slash path.
|
|
236
|
+
*
|
|
237
|
+
* @param input - The slash path to trim.
|
|
238
|
+
* @returns The path without trailing dots.
|
|
239
|
+
*/
|
|
178
240
|
export declare function removeTrailingFileTypeSeparators(input: SlashPath): SlashPath;
|
|
179
241
|
/**
|
|
180
242
|
* Adds a trailing slash to the input if it does not already have one.
|
|
@@ -227,6 +289,12 @@ export interface SlashPathValidationFactoryConfig {
|
|
|
227
289
|
*/
|
|
228
290
|
readonly throwError?: boolean;
|
|
229
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Creates a validation/fixup function for slash paths that replaces illegal characters and extra dots.
|
|
294
|
+
*
|
|
295
|
+
* @param config - Configuration for validation behavior.
|
|
296
|
+
* @returns A function that validates and fixes a slash path.
|
|
297
|
+
*/
|
|
230
298
|
export declare function slashPathValidationFactory(config?: SlashPathValidationFactoryConfig): SlashPathValidationFactory;
|
|
231
299
|
/**
|
|
232
300
|
* Factory use to generate/merge file paths together.
|
|
@@ -246,13 +314,32 @@ export interface SlashPathFactoryConfig {
|
|
|
246
314
|
*/
|
|
247
315
|
readonly validate?: boolean | SlashPathValidationFactoryConfig;
|
|
248
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Creates a factory function that merges path segments together with optional base path, start type enforcement, and validation.
|
|
319
|
+
*
|
|
320
|
+
* @param config - Configuration for path generation.
|
|
321
|
+
* @returns A factory function that merges input paths into a single validated slash path.
|
|
322
|
+
*/
|
|
249
323
|
export declare function slashPathFactory(config?: SlashPathFactoryConfig): SlashPathFactory;
|
|
324
|
+
/**
|
|
325
|
+
* Merges an array of path segments into a single slash path, filtering nullish values and collapsing double slashes.
|
|
326
|
+
*
|
|
327
|
+
* @param paths - Array of path segments to merge.
|
|
328
|
+
* @returns The merged slash path.
|
|
329
|
+
*/
|
|
250
330
|
export declare function mergeSlashPaths(paths: Maybe<SlashPath>[]): SlashPath;
|
|
331
|
+
/**
|
|
332
|
+
* Creates an Error indicating that a slash path is invalid.
|
|
333
|
+
*
|
|
334
|
+
* @returns A new Error with a descriptive message.
|
|
335
|
+
*/
|
|
251
336
|
export declare function slashPathInvalidError(): Error;
|
|
252
337
|
/**
|
|
253
338
|
* Splits the path and returns the items at the given ranges.
|
|
254
339
|
*
|
|
255
|
-
* @param path
|
|
340
|
+
* @param path - The path to isolate parts from.
|
|
341
|
+
* @param range - Index range defining which path segments to extract.
|
|
342
|
+
* @returns A new slash path containing only the segments within the range.
|
|
256
343
|
*/
|
|
257
344
|
export declare function isolateSlashPath(path: SlashPath, range: IndexRangeInput): SlashPath;
|
|
258
345
|
/**
|
|
@@ -281,8 +368,8 @@ export type IsolateSlashPathFunction = (path: SlashPath) => SlashPath;
|
|
|
281
368
|
/**
|
|
282
369
|
* Creates an IsolateSlashPathFunction.
|
|
283
370
|
*
|
|
284
|
-
* @param config
|
|
285
|
-
* @returns
|
|
371
|
+
* @param config - Configuration with range, optional start type, and file mode.
|
|
372
|
+
* @returns A function that isolates path segments within the configured range.
|
|
286
373
|
*/
|
|
287
374
|
export declare function isolateSlashPathFunction(config: IsolateSlashPathFunctionConfig): IsolateSlashPathFunction;
|
|
288
375
|
export interface SlashPathDetails {
|
|
@@ -382,8 +469,8 @@ export type SlashPathPathMatcherPath = ArrayOrValue<SlashPathPathMatcherPart>;
|
|
|
382
469
|
/**
|
|
383
470
|
* Expands the input matcher path into decision functions.
|
|
384
471
|
*
|
|
385
|
-
* @param path
|
|
386
|
-
* @returns
|
|
472
|
+
* @param path - Matcher path parts to expand into decision functions.
|
|
473
|
+
* @returns Array of decision functions for each path part.
|
|
387
474
|
*/
|
|
388
475
|
export declare function expandSlashPathPathMatcherPartToDecisionFunctions(path: SlashPathPathMatcherPath): SlashPathPathMatcherFunction[];
|
|
389
476
|
/**
|
|
@@ -8,7 +8,13 @@ export type SlashPathDirectoryTreeNodeValue<T> = {
|
|
|
8
8
|
readonly value: T;
|
|
9
9
|
readonly slashPathDetails: SlashPathDetails;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* A tree node containing a value with slash path details.
|
|
13
|
+
*/
|
|
11
14
|
export type SlashPathDirectoryTreeNode<T, V extends SlashPathDirectoryTreeNodeValue<T> = SlashPathDirectoryTreeNodeValue<T>> = TreeNode<V>;
|
|
15
|
+
/**
|
|
16
|
+
* Root of a slash path directory tree. Has children but no value of its own.
|
|
17
|
+
*/
|
|
12
18
|
export type SlashPathDirectoryTreeRoot<T, V extends SlashPathDirectoryTreeNodeValue<T> = SlashPathDirectoryTreeNodeValue<T>> = Omit<SlashPathDirectoryTreeNode<T, V>, 'value'>;
|
|
13
19
|
export interface SlashPathDirectoryTreeOptions {
|
|
14
20
|
/**
|
|
@@ -20,4 +26,14 @@ export interface SlashPathDirectoryTreeOptions {
|
|
|
20
26
|
*/
|
|
21
27
|
readonly includeChildrenWithMissingParentFolder?: Maybe<boolean>;
|
|
22
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Builds a directory tree structure from a flat list of node values based on their slash path hierarchy.
|
|
31
|
+
*
|
|
32
|
+
* Nodes are organized by their path parts, with each part becoming a level in the tree.
|
|
33
|
+
* Typed files (files with extensions) are added as children but cannot serve as parent folders.
|
|
34
|
+
*
|
|
35
|
+
* @param nodeValues - Flat list of values with associated slash path details.
|
|
36
|
+
* @param options - Optional configuration for tree building behavior.
|
|
37
|
+
* @returns The root node of the constructed directory tree.
|
|
38
|
+
*/
|
|
23
39
|
export declare function slashPathDirectoryTree<T, V extends SlashPathDirectoryTreeNodeValue<T> = SlashPathDirectoryTreeNodeValue<T>>(nodeValues: V[], options?: SlashPathDirectoryTreeOptions): SlashPathDirectoryTreeRoot<T, V>;
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { type Maybe } from '../value/maybe.type';
|
|
2
|
+
/**
|
|
3
|
+
* A Node.js-style error-first callback function.
|
|
4
|
+
*
|
|
5
|
+
* @param err - An optional error. If provided, indicates failure.
|
|
6
|
+
*/
|
|
2
7
|
export type PromiseCallback = (err?: Maybe<Error>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* A function that receives a {@link PromiseCallback} and invokes it to signal completion or failure.
|
|
10
|
+
*
|
|
11
|
+
* @param cb - The callback to invoke when the async operation completes.
|
|
12
|
+
*/
|
|
3
13
|
export type UsePromiseCallback = (cb: PromiseCallback) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Wraps a callback-based async operation as a Promise. The provided function receives a
|
|
16
|
+
* Node.js-style error-first callback; calling it with an error rejects the promise, and
|
|
17
|
+
* calling it without an error resolves it.
|
|
18
|
+
*
|
|
19
|
+
* @param use - A function that performs an async operation and signals completion via the provided callback.
|
|
20
|
+
* @returns A Promise that resolves when the callback is invoked without an error, or rejects with the provided error.
|
|
21
|
+
*/
|
|
4
22
|
export declare function useCallback(use: UsePromiseCallback): Promise<void>;
|
package/src/lib/promise/is.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Checks whether the input value is a native Promise by testing for a `.then` method.
|
|
3
3
|
*
|
|
4
|
-
* @param obj
|
|
5
|
-
* @returns
|
|
4
|
+
* @param obj - The value to test.
|
|
5
|
+
* @returns `true` if the value is a Promise, `false` otherwise.
|
|
6
6
|
*/
|
|
7
7
|
export declare function isPromise<T, S>(obj: Promise<T> | S): obj is Promise<T>;
|
|
8
|
+
/**
|
|
9
|
+
* Checks whether the input value is PromiseLike (i.e., has a `.then` method), which
|
|
10
|
+
* includes both native Promises and custom thenables.
|
|
11
|
+
*
|
|
12
|
+
* @param obj - The value to test.
|
|
13
|
+
* @returns `true` if the value is PromiseLike, `false` otherwise.
|
|
14
|
+
*/
|
|
8
15
|
export declare function isPromiseLike<T, S>(obj: PromiseLike<T> | S): obj is PromiseLike<T>;
|
package/src/lib/promise/map.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type PromiseOrValue } from './promise.type';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Applies a mapping function to a {@link PromiseOrValue}. If the input is a Promise, the
|
|
4
|
+
* mapping is applied via `.then()`; if it is a synchronous value, the mapping is applied directly.
|
|
4
5
|
*
|
|
5
|
-
* @param input
|
|
6
|
-
* @param mapFn
|
|
6
|
+
* @param input - A value or Promise to map over.
|
|
7
|
+
* @param mapFn - The transformation function to apply.
|
|
8
|
+
* @returns The mapped result, as a Promise if the input was a Promise, or synchronously otherwise.
|
|
7
9
|
*/
|
|
8
10
|
export declare function mapPromiseOrValue<I, O>(input: Promise<I>, mapFn: (input: I) => O): Promise<O>;
|
|
9
11
|
export declare function mapPromiseOrValue<I, O>(input: I, mapFn: (input: I) => O): O;
|
|
@@ -1,18 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the {@link poll} function.
|
|
3
|
+
*/
|
|
1
4
|
export interface PollConfig {
|
|
2
5
|
/**
|
|
3
|
-
* How long to wait between polling checks in
|
|
6
|
+
* How long to wait between polling checks in milliseconds.
|
|
7
|
+
*
|
|
8
|
+
* Defaults to 250.
|
|
4
9
|
*/
|
|
5
10
|
wait?: number;
|
|
6
11
|
/**
|
|
7
|
-
*
|
|
12
|
+
* Predicate function that returns `true` when the polling condition has been met.
|
|
8
13
|
*/
|
|
9
14
|
check: () => boolean;
|
|
10
15
|
/**
|
|
11
|
-
*
|
|
16
|
+
* Maximum number of polling iterations before giving up.
|
|
17
|
+
*
|
|
18
|
+
* Defaults to `Number.MAX_SAFE_INTEGER`.
|
|
12
19
|
*/
|
|
13
20
|
timesToGiveup?: number;
|
|
14
21
|
}
|
|
15
22
|
/**
|
|
16
|
-
* Polls
|
|
23
|
+
* Polls at a regular interval until a condition is met or the maximum number of attempts is reached.
|
|
24
|
+
*
|
|
25
|
+
* @param config - Polling configuration including check function, wait interval, and max attempts.
|
|
26
|
+
* @returns A Promise that resolves when the check condition returns `true` or the max attempts are exhausted.
|
|
17
27
|
*/
|
|
18
28
|
export declare function poll({ check, wait, timesToGiveup }: PollConfig): Promise<void>;
|
|
@@ -5,32 +5,66 @@ import { type StringFactory } from '../string/factory';
|
|
|
5
5
|
import { type IndexNumber } from '../value';
|
|
6
6
|
import { type Maybe } from '../value/maybe.type';
|
|
7
7
|
import { type PromiseOrValue } from './promise.type';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for {@link runAsyncTaskForValue}, which omits `throwError` since it always throws on failure.
|
|
10
|
+
*/
|
|
8
11
|
export type RunAsyncTaskForValueConfig<T = unknown> = Omit<PerformAsyncTaskConfig<T>, 'throwError'>;
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for {@link runAsyncTasksForValues}, which omits `throwError` since it always throws on failure.
|
|
14
|
+
*/
|
|
9
15
|
export type RunAsyncTasksForValuesConfig<T = unknown> = Omit<PerformAsyncTasksConfig<T>, 'throwError'>;
|
|
10
16
|
/**
|
|
11
|
-
* Runs
|
|
17
|
+
* Runs a single async task and returns the resulting value. Always configured to throw on failure.
|
|
18
|
+
*
|
|
19
|
+
* @param taskFn - The async task to execute.
|
|
20
|
+
* @param config - Optional configuration for retries and retry behavior.
|
|
21
|
+
* @returns The value produced by the task, or undefined if the task produced no value.
|
|
22
|
+
* @throws Rethrows any error thrown by the task function.
|
|
12
23
|
*/
|
|
13
24
|
export declare function runAsyncTaskForValue<O>(taskFn: () => Promise<O>, config?: RunAsyncTaskForValueConfig<0>): Promise<Maybe<O>>;
|
|
14
25
|
/**
|
|
15
|
-
*
|
|
26
|
+
* Runs an async task for each input value and returns an array of the resulting values.
|
|
27
|
+
* Always configured to throw on failure.
|
|
16
28
|
*
|
|
17
|
-
* @param input
|
|
18
|
-
* @param taskFn
|
|
19
|
-
* @param config
|
|
20
|
-
* @returns
|
|
29
|
+
* @param input - The array of input values to process.
|
|
30
|
+
* @param taskFn - The async task function to run for each input value.
|
|
31
|
+
* @param config - Optional configuration for parallelism and retries.
|
|
32
|
+
* @returns An array of results produced by the task function for each input.
|
|
33
|
+
* @throws Rethrows any error thrown by a task function.
|
|
21
34
|
*/
|
|
22
35
|
export declare function runAsyncTasksForValues<T, K = unknown>(input: T[], taskFn: PerformAsyncTaskFn<T, K>, config?: RunAsyncTasksForValuesConfig<T>): Promise<K[]>;
|
|
36
|
+
/**
|
|
37
|
+
* An async function that processes a value and returns a result. Receives the current retry/try number.
|
|
38
|
+
*
|
|
39
|
+
* @param value - The input value to process.
|
|
40
|
+
* @param tryNumber - The current attempt number (0-based).
|
|
41
|
+
*/
|
|
23
42
|
export type PerformAsyncTaskFn<T, K = unknown> = (value: T, tryNumber?: number) => Promise<K>;
|
|
43
|
+
/**
|
|
44
|
+
* The result of executing a single async task via {@link performAsyncTask}.
|
|
45
|
+
*/
|
|
24
46
|
export interface PerformAsyncTaskResult<O> {
|
|
47
|
+
/** The resulting value if the task succeeded, or undefined on failure. */
|
|
25
48
|
readonly value: Maybe<O>;
|
|
49
|
+
/** Whether the task completed successfully. */
|
|
26
50
|
readonly success: boolean;
|
|
27
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* The aggregated result of executing multiple async tasks via {@link performAsyncTasks}.
|
|
54
|
+
*/
|
|
28
55
|
export interface PerformAsyncTasksResult<I, O> {
|
|
56
|
+
/** Input values whose tasks succeeded. */
|
|
29
57
|
readonly succeded: I[];
|
|
58
|
+
/** Input values whose tasks failed. */
|
|
30
59
|
readonly failed: I[];
|
|
60
|
+
/** Tuples of [input, output] for each successful task. */
|
|
31
61
|
readonly results: [I, O][];
|
|
62
|
+
/** Tuples of [input, error] for each failed task. */
|
|
32
63
|
readonly errors: [I, unknown][];
|
|
33
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Configuration for retry behavior when performing async tasks.
|
|
67
|
+
*/
|
|
34
68
|
export interface PerformAsyncTaskConfig<I = unknown> {
|
|
35
69
|
/**
|
|
36
70
|
* Whether or not to throw an error if the task fails. Defaults to true.
|
|
@@ -51,19 +85,38 @@ export interface PerformAsyncTaskConfig<I = unknown> {
|
|
|
51
85
|
*/
|
|
52
86
|
readonly beforeRetry?: (value: I, tryNumber?: number) => void | Promise<void>;
|
|
53
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Configuration for {@link performAsyncTasks}, combining retry behavior with parallel execution options.
|
|
90
|
+
*/
|
|
54
91
|
export interface PerformAsyncTasksConfig<I = unknown, K extends PrimativeKey = PerformTasksInParallelTaskUniqueKey> extends PerformAsyncTaskConfig<I>, Omit<PerformTasksInParallelFunctionConfig<I, K>, 'taskFactory'> {
|
|
55
92
|
}
|
|
56
93
|
/**
|
|
57
|
-
* Performs
|
|
94
|
+
* Performs async tasks for each input value with configurable retry and parallelism behavior.
|
|
95
|
+
* Useful for operations that may experience optimistic concurrency collisions.
|
|
58
96
|
*
|
|
59
|
-
*
|
|
97
|
+
* @param input - The array of input values to process.
|
|
98
|
+
* @param taskFn - The async function to execute for each input.
|
|
99
|
+
* @param config - Configuration for retries, parallelism, and error handling.
|
|
100
|
+
* @returns An aggregated result with succeeded/failed items and their outputs/errors.
|
|
101
|
+
* @throws Rethrows the last error from retries if `throwError` is true (default).
|
|
60
102
|
*/
|
|
61
103
|
export declare function performAsyncTasks<I, O = unknown, K extends PrimativeKey = PerformTasksInParallelTaskUniqueKey>(input: I[], taskFn: PerformAsyncTaskFn<I, O>, config?: PerformAsyncTasksConfig<I, K>): Promise<PerformAsyncTasksResult<I, O>>;
|
|
104
|
+
/**
|
|
105
|
+
* Performs a single async task with configurable retry behavior and returns the result with success status.
|
|
106
|
+
*
|
|
107
|
+
* @param taskFn - The async task to execute.
|
|
108
|
+
* @param config - Optional configuration for retries and error handling.
|
|
109
|
+
* @returns A result object containing the value (if successful) and a success flag.
|
|
110
|
+
* @throws Rethrows the last error from retries if `throwError` is true (default).
|
|
111
|
+
*/
|
|
62
112
|
export declare function performAsyncTask<O>(taskFn: () => Promise<O>, config?: PerformAsyncTaskConfig<0>): Promise<PerformAsyncTaskResult<O>>;
|
|
63
113
|
/**
|
|
64
114
|
* Used as a key to identify the "group" that a task belongs to to prevent other concurrent tasks from that group from running in parallel when parallel execution is desired.
|
|
65
115
|
*/
|
|
66
116
|
export type PerformTasksInParallelTaskUniqueKey = string;
|
|
117
|
+
/**
|
|
118
|
+
* Configuration for {@link performTasksInParallelFunction}, excluding `waitBetweenTaskInputRequests`.
|
|
119
|
+
*/
|
|
67
120
|
export type PerformTasksInParallelFunctionConfig<I, K extends PrimativeKey = PerformTasksInParallelTaskUniqueKey> = Omit<PerformTasksFromFactoryInParallelFunctionConfig<I, K>, 'waitBetweenTaskInputRequests'>;
|
|
68
121
|
/**
|
|
69
122
|
* Function that awaits a promise generated from each of the input values.
|
|
@@ -72,19 +125,26 @@ export type PerformTasksInParallelFunctionConfig<I, K extends PrimativeKey = Per
|
|
|
72
125
|
*/
|
|
73
126
|
export type PerformTasksInParallelFunction<I> = (input: I[]) => Promise<void>;
|
|
74
127
|
/**
|
|
75
|
-
* Convenience function
|
|
128
|
+
* Convenience function that creates a parallel task executor and immediately runs it with the given input.
|
|
76
129
|
*
|
|
77
|
-
* @param input
|
|
78
|
-
* @param config
|
|
79
|
-
* @returns
|
|
130
|
+
* @param input - The array of items to process.
|
|
131
|
+
* @param config - Configuration for task execution, parallelism, and concurrency constraints.
|
|
132
|
+
* @returns A Promise that resolves when all tasks complete.
|
|
133
|
+
* @throws Rethrows the first error encountered during task execution.
|
|
80
134
|
*/
|
|
81
135
|
export declare function performTasksInParallel<I, K extends PrimativeKey = PerformTasksInParallelTaskUniqueKey>(input: I[], config: PerformTasksInParallelFunctionConfig<I, K>): Promise<void>;
|
|
82
136
|
/**
|
|
83
|
-
* Creates a function that performs tasks in parallel
|
|
137
|
+
* Creates a reusable function that performs tasks in parallel with optional concurrency limits
|
|
138
|
+
* and non-concurrent task key constraints.
|
|
84
139
|
*
|
|
85
|
-
* @param config
|
|
140
|
+
* @param config - Configuration for task factory, parallelism limits, and concurrency keys.
|
|
141
|
+
* @returns A function that accepts an array of inputs and returns a Promise resolving when all tasks complete.
|
|
86
142
|
*/
|
|
87
143
|
export declare function performTasksInParallelFunction<I, K extends PrimativeKey = PerformTasksInParallelTaskUniqueKey>(config: PerformTasksInParallelFunctionConfig<I, K>): PerformTasksInParallelFunction<I>;
|
|
144
|
+
/**
|
|
145
|
+
* Configuration for {@link performTasksFromFactoryInParallelFunction}, controlling task execution,
|
|
146
|
+
* parallelism limits, and non-concurrent key constraints.
|
|
147
|
+
*/
|
|
88
148
|
export interface PerformTasksFromFactoryInParallelFunctionConfig<I, K extends PrimativeKey = PerformTasksInParallelTaskUniqueKey> {
|
|
89
149
|
/**
|
|
90
150
|
* Creates a promise from the input.
|
|
@@ -115,6 +175,10 @@ export interface PerformTasksFromFactoryInParallelFunctionConfig<I, K extends Pr
|
|
|
115
175
|
*/
|
|
116
176
|
readonly waitBetweenTaskInputRequests?: Milliseconds;
|
|
117
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* A factory function that produces the next batch of task inputs. Returns `null` to signal
|
|
180
|
+
* that no more inputs are available.
|
|
181
|
+
*/
|
|
118
182
|
export type PerformTaskFactoryTasksInParallelFunctionTaskInputFactory<I> = () => PromiseOrValue<ArrayOrValue<I> | null>;
|
|
119
183
|
/**
|
|
120
184
|
* Function that awaits all promises generated from the task factory until the factory returns null.
|
|
@@ -125,14 +189,16 @@ export type PerformTaskFactoryTasksInParallelFunctionTaskInputFactory<I> = () =>
|
|
|
125
189
|
*/
|
|
126
190
|
export type PerformTaskFactoryTasksInParallelFunction<I> = (taskInputFactory: PerformTaskFactoryTasksInParallelFunctionTaskInputFactory<I>) => Promise<void>;
|
|
127
191
|
/**
|
|
128
|
-
* Creates a function that
|
|
192
|
+
* Creates a function that pulls task inputs from a factory and executes them in parallel
|
|
193
|
+
* with configurable concurrency limits and non-concurrent key constraints.
|
|
129
194
|
*
|
|
130
|
-
* @param config
|
|
195
|
+
* @param config - Configuration for the task factory, parallelism, and concurrency behavior.
|
|
196
|
+
* @returns A function that accepts a task input factory and returns a Promise resolving when all tasks complete.
|
|
131
197
|
*/
|
|
132
198
|
export declare function performTasksFromFactoryInParallelFunction<I, K extends PrimativeKey = PerformTasksInParallelTaskUniqueKey>(config: PerformTasksFromFactoryInParallelFunctionConfig<I, K>): PerformTaskFactoryTasksInParallelFunction<I>;
|
|
133
199
|
/**
|
|
134
|
-
* Creates a default non-concurrent task key factory that
|
|
200
|
+
* Creates a default non-concurrent task key factory that generates unique incrementing number strings.
|
|
135
201
|
*
|
|
136
|
-
* @returns A
|
|
202
|
+
* @returns A {@link StringFactory} that produces unique keys for identifying non-concurrent tasks.
|
|
137
203
|
*/
|
|
138
204
|
export declare function makeDefaultNonConcurrentTaskKeyFactory(): StringFactory<any>;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { type FactoryWithRequiredInput } from '../getter/getter';
|
|
2
2
|
import { type Maybe } from '../value/maybe.type';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* A function that tries an array of Promise factories one after another until one
|
|
5
|
+
* produces a successful result. Returns `undefined` if none succeed.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
+
* @param input - The input to pass to each factory.
|
|
8
|
+
* @param config - Optional per-call configuration overrides.
|
|
9
|
+
* @returns The first successful value, or `undefined` if no factory succeeds.
|
|
7
10
|
*/
|
|
8
11
|
export type TryWithPromiseFactoriesFunction<I, O> = (input: I, config?: TryWithPromiseFactoriesFunctionOptionalConfig<I, O>) => Promise<Maybe<O>>;
|
|
12
|
+
/**
|
|
13
|
+
* Optional per-call configuration for {@link TryWithPromiseFactoriesFunction}.
|
|
14
|
+
*/
|
|
9
15
|
export interface TryWithPromiseFactoriesFunctionOptionalConfig<I, O> {
|
|
10
16
|
/**
|
|
11
17
|
* Whether or not to return a Maybe value if it is returned by one of the created promises.
|
|
@@ -20,6 +26,9 @@ export interface TryWithPromiseFactoriesFunctionOptionalConfig<I, O> {
|
|
|
20
26
|
*/
|
|
21
27
|
readonly throwErrors?: boolean;
|
|
22
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for creating a {@link TryWithPromiseFactoriesFunction} via {@link tryWithPromiseFactoriesFunction}.
|
|
31
|
+
*/
|
|
23
32
|
export interface TryWithPromiseFactoriesFunctionConfig<I, O> extends TryWithPromiseFactoriesFunctionOptionalConfig<I, O> {
|
|
24
33
|
/**
|
|
25
34
|
* Factories used to create new Promise valeus to test.
|
|
@@ -30,4 +39,11 @@ export interface TryWithPromiseFactoriesFunctionConfig<I, O> extends TryWithProm
|
|
|
30
39
|
*/
|
|
31
40
|
readonly promiseFactories: FactoryWithRequiredInput<Promise<Maybe<O>>, I>[];
|
|
32
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a {@link TryWithPromiseFactoriesFunction} that sequentially tries each promise factory
|
|
44
|
+
* until one returns a non-null value (or a Maybe value if `successOnMaybe` is true).
|
|
45
|
+
*
|
|
46
|
+
* @param config - Configuration including the array of promise factories and default behavior options.
|
|
47
|
+
* @returns A function that tries each factory in order for a given input.
|
|
48
|
+
*/
|
|
33
49
|
export declare function tryWithPromiseFactoriesFunction<I, O>(config: TryWithPromiseFactoriesFunctionConfig<I, O>): TryWithPromiseFactoriesFunction<I, O>;
|
|
@@ -56,7 +56,14 @@ export interface ExponentialPromiseRateLimiterConfig {
|
|
|
56
56
|
*/
|
|
57
57
|
readonly exponentRate?: number;
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* A fully resolved {@link ExponentialPromiseRateLimiterConfig} with all fields required.
|
|
61
|
+
*/
|
|
59
62
|
export type FullExponentialPromiseRateLimiterConfig = Required<ExponentialPromiseRateLimiterConfig>;
|
|
63
|
+
/**
|
|
64
|
+
* An exponential backoff rate limiter that increases wait times exponentially based on usage,
|
|
65
|
+
* with a configurable cooldown that reduces the effective count over time.
|
|
66
|
+
*/
|
|
60
67
|
export interface ExponentialPromiseRateLimiter extends EnableTogglePromiseRateLimiter {
|
|
61
68
|
/**
|
|
62
69
|
* Returns the current config.
|
|
@@ -71,7 +78,18 @@ export interface ExponentialPromiseRateLimiter extends EnableTogglePromiseRateLi
|
|
|
71
78
|
*/
|
|
72
79
|
reset(): void;
|
|
73
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Creates an {@link ExponentialPromiseRateLimiter} that computes wait times using exponential
|
|
83
|
+
* growth with a configurable cooldown that reduces the effective count over time.
|
|
84
|
+
*
|
|
85
|
+
* @param initialConfig - Optional initial configuration. Defaults are applied for any omitted fields.
|
|
86
|
+
* @returns An ExponentialPromiseRateLimiter instance.
|
|
87
|
+
*/
|
|
74
88
|
export declare function exponentialPromiseRateLimiter(initialConfig?: Maybe<ExponentialPromiseRateLimiterConfig>): ExponentialPromiseRateLimiter;
|
|
89
|
+
/**
|
|
90
|
+
* Configuration for a {@link ResetPeriodPromiseRateLimiter} that resets its remaining count
|
|
91
|
+
* periodically and applies exponential backoff when the limit is exhausted.
|
|
92
|
+
*/
|
|
75
93
|
export interface ResetPeriodPromiseRateLimiterConfig extends Partial<ExponentialPromiseRateLimiterConfig> {
|
|
76
94
|
/**
|
|
77
95
|
* The number of times the rate limiter can be used before it needs to be reset.
|
|
@@ -124,8 +142,10 @@ export interface ResetPeriodPromiseRateLimiter extends EnableTogglePromiseRateLi
|
|
|
124
142
|
reset(): void;
|
|
125
143
|
}
|
|
126
144
|
/**
|
|
127
|
-
* Creates a ResetPeriodPromiseRateLimiter
|
|
145
|
+
* Creates a {@link ResetPeriodPromiseRateLimiter} that limits the number of operations per time period,
|
|
146
|
+
* resetting the count at regular intervals and applying exponential backoff when the limit is exceeded.
|
|
128
147
|
*
|
|
129
|
-
* @param limit
|
|
148
|
+
* @param initialConfig - Configuration specifying the limit count, reset period, and optional exponential backoff settings.
|
|
149
|
+
* @returns A ResetPeriodPromiseRateLimiter instance.
|
|
130
150
|
*/
|
|
131
151
|
export declare function resetPeriodPromiseRateLimiter(initialConfig: ResetPeriodPromiseRateLimiterConfig): ResetPeriodPromiseRateLimiter;
|