@dereekb/util 12.4.5 → 12.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/util",
3
- "version": "12.4.5",
3
+ "version": "12.5.1",
4
4
  "exports": {
5
5
  ".": {
6
6
  "types": "./src/index.d.ts",
@@ -95,6 +95,31 @@ export declare function pushArrayItemsIntoArray<T>(target: T[], array: T[]): T[]
95
95
  * @returns
96
96
  */
97
97
  export declare function takeFront<T>(values: T[], maxToTake: number): T[];
98
+ /**
99
+ * splitFront() result
100
+ */
101
+ export interface SplitFrontResult<T> {
102
+ /**
103
+ * The input max to take value.
104
+ */
105
+ readonly maxToTake: number;
106
+ /**
107
+ * The front of the array up to the maxToTake.
108
+ */
109
+ readonly front: T[];
110
+ /**
111
+ * The remaining values after the front.
112
+ */
113
+ readonly remaining: T[];
114
+ }
115
+ /**
116
+ * Splits the array into two arrays, the first being the front of the array up to the maxToTake, and the second being the remaining values.
117
+ *
118
+ * @param values The array to split.
119
+ * @param maxToTake The maximum number of values to take from the front of the array.
120
+ * @returns The front and remaining values.
121
+ */
122
+ export declare function splitFront<T>(values: T[], maxToTake: number): SplitFrontResult<T>;
98
123
  /**
99
124
  * Copies/takes as many elements as possible from the end.
100
125
  *
@@ -1,5 +1,6 @@
1
1
  import { type AuthRole, type AuthRoleSet } from './auth.role';
2
2
  import { type ArrayOrValue } from '../array/array';
3
+ import { SetIncludesMode } from '../set';
3
4
  import { type Maybe } from '../value/maybe.type';
4
5
  /**
5
6
  * Key in the claims.
@@ -50,6 +51,20 @@ export interface AuthRoleClaimsFactoryConfigEntrySimpleOptions<V extends SimpleA
50
51
  * The roles to add when this claims is encountered.
51
52
  */
52
53
  roles: ArrayOrValue<AuthRole>;
54
+ /**
55
+ * Describes when to add the value when encoding the roles.
56
+ *
57
+ * During encoding back to roles, the value will be set in the claims if ["any"/"all"] roles are not present.
58
+ *
59
+ * For "all", set the inverse if "all of the roles are present"/"any of the roles are NOT present"
60
+ * For "any", set the inverse if "any of the roles are present"/"all of the roles are NOT present"
61
+ *
62
+ * True defaults to "any".
63
+ *
64
+ * For example, if there is a role that disables/disallowed the "uploads" role, and "uploads" is present during encoding,
65
+ * then the value will not be set on the inverse claim.
66
+ */
67
+ inverse?: true | SetIncludesMode;
53
68
  /**
54
69
  * (Optional) claim value. Overrides the default claim value.
55
70
  */
@@ -25,8 +25,10 @@ export declare function unixTimeNumberFromDate(date: MaybeNot): MaybeNot;
25
25
  * Converts a Date object or unix timestamp number to a Date object.
26
26
  *
27
27
  * @param input - Date object or unix timestamp number to convert
28
- * @returns Date object if input is valid, null/undefined if input is null/undefined
28
+ * @returns Date object if input is valid. Returns null/undefined if input is null/undefined
29
29
  */
30
+ export declare function dateFromDateOrTimeNumber(input: DateOrUnixDateTimeNumber): Date;
31
+ export declare function dateFromDateOrTimeNumber(input: MaybeNot): MaybeNot;
30
32
  export declare function dateFromDateOrTimeNumber(input: Maybe<DateOrUnixDateTimeNumber>): Maybe<Date>;
31
33
  /**
32
34
  * Converts a unix timestamp number to a Date object.
@@ -11,6 +11,10 @@ export type Getter<T> = () => T;
11
11
  * Getter with the design of returning a new value each time.
12
12
  */
13
13
  export type Factory<T> = Getter<T>;
14
+ /**
15
+ * Getter that returns a promise.
16
+ */
17
+ export type AsyncFactory<T> = Factory<Promise<T>>;
14
18
  /**
15
19
  * Function that returns a value with an optional single argument.
16
20
  */
@@ -8,9 +8,15 @@ export type NumberString = string;
8
8
  /**
9
9
  * Number that represents a percent.
10
10
  *
11
- * e.g. 5 = 0.05 = 5%
11
+ * e.g. PercentNumber of 5 = 0.05 = 5%
12
12
  */
13
13
  export type PercentNumber = number;
14
+ /**
15
+ * A percent decimal value.
16
+ *
17
+ * e.g. PercentDecimal of 0.05 = 5%
18
+ */
19
+ export type PercentDecimal = number;
14
20
  /**
15
21
  * Converts the percent number to a decimal value.
16
22
  *
@@ -1,7 +1,10 @@
1
1
  import { type MapSameFunction } from '../value/map';
2
+ import { DecisionFunction } from '../value/decision';
2
3
  import { type ArrayOrValue } from '../array/array';
3
- import { type IndexRangeInput, type Maybe } from '../value';
4
4
  import { type FactoryWithRequiredInput } from '../getter/getter';
5
+ import { type PrimativeValue } from '../type';
6
+ import { Maybe } from '../value/maybe.type';
7
+ import { IndexRangeInput } from '../value/indexed';
5
8
  export declare const SLASH_PATH_SEPARATOR = "/";
6
9
  export declare const SLASH_PATH_FILE_TYPE_SEPARATOR = ".";
7
10
  export type SlashPathSeparatorString = typeof SLASH_PATH_SEPARATOR;
@@ -11,22 +14,60 @@ export declare const DEFAULT_SLASH_PATH_ILLEGAL_CHARACTERS: string[];
11
14
  * Default replacement character for illegal characters.
12
15
  */
13
16
  export declare const DEFAULT_SLASH_PATH_ILLEGAL_CHARACTER_REPLACEMENT = "_";
17
+ /**
18
+ * A relative folder path that does not start with a slash.
19
+ */
20
+ export type RelativeSlashPathFolder = `${string}${SlashPathSeparatorString}`;
21
+ /**
22
+ * An absolute folder path that starts with a slash.
23
+ */
24
+ export type AbsoluteSlashPathFolder = `${SlashPathSeparatorString}${string}${SlashPathSeparatorString}`;
14
25
  /**
15
26
  * A forward-slash path string.
16
27
  */
17
- export type SlashPathFolder = `${SlashPathSeparatorString}${string}${SlashPathSeparatorString}` | `${string}${SlashPathSeparatorString}`;
28
+ export type SlashPathFolder = AbsoluteSlashPathFolder | RelativeSlashPathFolder | `${SlashPathSeparatorString}`;
29
+ /**
30
+ * A relative folder path that is just an empty string.
31
+ */
32
+ export type EmptyRelativeSlashPathFolder = '';
33
+ /**
34
+ * This type includes the empty relative folder path possibility.
35
+ */
36
+ export type InferredSlashPathFolder = SlashPathFolder | EmptyRelativeSlashPathFolder;
37
+ /**
38
+ * The file extension of a SlashPathTypedFile.
39
+ *
40
+ * e.g. 'png' in 'image.png'
41
+ */
42
+ export type SlashPathTypedFileExtension = string;
18
43
  /**
19
- * A file name without a type.
44
+ * The suffix of a typed file.
45
+ *
46
+ * e.g. '.png' in 'image.png'
20
47
  */
21
- export type SlashPathFile = string;
48
+ export type SlashPathTypedFileSuffix = `${SlashFileTypeSeparatorString}${SlashPathTypedFileExtension}`;
22
49
  /**
23
- * A file name
50
+ * A SlashPath file name without a file type identifier (e.g. 'image', and not 'image.png')
51
+ */
52
+ export type SlashPathUntypedFile = string;
53
+ /**
54
+ * A file name that contains a file type identifier (e.g. 'image.png')
24
55
  */
25
56
  export type SlashPathTypedFile = `${string}${SlashFileTypeSeparatorString}${string}`;
57
+ /**
58
+ * A SlashPath file name
59
+ */
60
+ export type SlashPathFile = SlashPathUntypedFile | SlashPathTypedFile;
26
61
  /**
27
62
  * A simple path made up of UTF-8 characters and slashes
28
63
  */
29
64
  export type SlashPath = SlashPathFolder | SlashPathFile | SlashPathTypedFile;
65
+ /**
66
+ * A part of a slash path.
67
+ *
68
+ * Does not contain any slashes.
69
+ */
70
+ export type SlashPathPart = string | SlashPathTypedFile;
30
71
  /**
31
72
  * Function that modifies the input SlashPath
32
73
  */
@@ -55,14 +96,14 @@ export declare function isValidSlashPath(input: string): input is SlashPath;
55
96
  *
56
97
  * @param slashPath
57
98
  */
58
- export declare function slashPathName(slashPath: SlashPath): string;
99
+ export declare function slashPathName(slashPath: SlashPath): SlashPathPart;
59
100
  /**
60
101
  * Returns each section of a SlashPath
61
102
  *
62
103
  * @param slashPath
63
104
  * @returns
64
105
  */
65
- export declare function slashPathParts(slashPath: SlashPath): string[];
106
+ export declare function slashPathParts(slashPath: SlashPath): SlashPathPart[];
66
107
  /**
67
108
  * Slash path type to enforce.
68
109
  * - relative: path that does not start with a slash
@@ -82,6 +123,49 @@ export declare const ALL_SLASHES_REGEX: RegExp;
82
123
  export declare const ALL_DOUBLE_SLASHES_REGEX: RegExp;
83
124
  export declare const ALL_SLASH_PATH_FILE_TYPE_SEPARATORS_REGEX: RegExp;
84
125
  export declare function toRelativeSlashPathStartType(input: SlashPath): SlashPath;
126
+ /**
127
+ * Factory function that creates a SlashPathFolder from a string.
128
+ */
129
+ export type SlashPathFolderFactory = (input: string) => InferredSlashPathFolder;
130
+ export interface SlashPathFolderFactoryConfig {
131
+ /**
132
+ * Optional start type for the slash path. Defaults to 'any'.
133
+ */
134
+ readonly startType?: SlashPathStartType;
135
+ /**
136
+ * Whether to treat untyped files as folders.
137
+ *
138
+ * Defaults to false.
139
+ */
140
+ readonly treatUntypedFilesAsFolders?: boolean;
141
+ /**
142
+ * Optional validation configuration.
143
+ */
144
+ readonly validationConfig?: SlashPathValidationFactoryConfig;
145
+ /**
146
+ * The path value to return if the input is considered invalid after the validation step.
147
+ *
148
+ * You can also configure the `throwError` option in `validationConfig` to throw an error, in which case this option will be ignored.
149
+ *
150
+ * Defaults to ''.
151
+ */
152
+ readonly invalidPathValue?: Maybe<InferredSlashPathFolder>;
153
+ }
154
+ /**
155
+ * Creates a SlashPathFolderFactory.
156
+ *
157
+ * @param config Configuration options for the factory.
158
+ * @returns A SlashPathFolderFactory.
159
+ */
160
+ export declare function slashPathFolderFactory(config?: SlashPathFolderFactoryConfig): SlashPathFolderFactory;
161
+ /**
162
+ * Converts the input string to a valid slash path folder based on the configuration.
163
+ *
164
+ * If the input is a file, the folder of the file is returned instead.
165
+ *
166
+ * @param input
167
+ */
168
+ export declare function slashPathFolder(input: string, config?: SlashPathFolderFactoryConfig): InferredSlashPathFolder;
85
169
  /**
86
170
  *
87
171
  * @param input
@@ -92,6 +176,13 @@ export declare function fixMultiSlashesInSlashPath(input: SlashPath): SlashPath;
92
176
  export declare function replaceMultipleFilePathsInSlashPath(input: SlashPath): SlashPath;
93
177
  export declare function removeTrailingSlashes(input: SlashPath): SlashPath;
94
178
  export declare function removeTrailingFileTypeSeparators(input: SlashPath): SlashPath;
179
+ /**
180
+ * Adds a trailing slash to the input if it does not already have one.
181
+ *
182
+ * @param input A slash path.
183
+ * @returns A slash path folder.
184
+ */
185
+ export declare function addTrailingSlash(input: SlashPath): SlashPathFolder;
95
186
  /**
96
187
  * Replaces all extra and invalidate FilePathTypeSeparator values from the SlashPath, returning a valid SlashPath.
97
188
  *
@@ -116,25 +207,25 @@ export interface SlashPathValidationFactoryConfig {
116
207
  /**
117
208
  * Set of illegal characters to find/replace. If not provided, used the DEFAULT_SLASH_PATH_ILLEGAL_CHARACTERS
118
209
  */
119
- illegalStrings?: ArrayOrValue<string>;
210
+ readonly illegalStrings?: ArrayOrValue<string>;
120
211
  /**
121
212
  * String used to replace all encountered illegal characters.
122
213
  *
123
214
  * Is true by default.
124
215
  */
125
- replaceIllegalCharacters?: string | boolean;
216
+ readonly replaceIllegalCharacters?: string | boolean;
126
217
  /**
127
218
  * Whether or not to replace extra dots by treating them as illegal characters.
128
219
  *
129
220
  * Will replace extra dots with the input value, or if true, will replace them with the value for replaceIllegalCharacters.
130
221
  */
131
- replaceIllegalDots?: string | boolean;
222
+ readonly replaceIllegalDots?: string | boolean;
132
223
  /**
133
224
  * Whether or not to validate a final time after replacing elements and throw an error if it is still not valid.
134
225
  *
135
226
  * Disabled by default unless replaceIllegalCharacters and replaceIllegalDots are false.
136
227
  */
137
- throwError?: boolean;
228
+ readonly throwError?: boolean;
138
229
  }
139
230
  export declare function slashPathValidationFactory(config?: SlashPathValidationFactoryConfig): SlashPathValidationFactory;
140
231
  /**
@@ -145,15 +236,15 @@ export interface SlashPathFactoryConfig {
145
236
  /**
146
237
  * SlashPath start type to enforce
147
238
  */
148
- startType?: SlashPathStartType;
239
+ readonly startType?: SlashPathStartType;
149
240
  /**
150
241
  * Prefix paths to append
151
242
  */
152
- basePath?: ArrayOrValue<SlashPathFolder>;
243
+ readonly basePath?: ArrayOrValue<SlashPathFolder>;
153
244
  /**
154
245
  * SlashPathValidationFactoryConfig to use for validation.
155
246
  */
156
- validate?: boolean | SlashPathValidationFactoryConfig;
247
+ readonly validate?: boolean | SlashPathValidationFactoryConfig;
157
248
  }
158
249
  export declare function slashPathFactory(config?: SlashPathFactoryConfig): SlashPathFactory;
159
250
  export declare function mergeSlashPaths(paths: Maybe<SlashPath>[]): SlashPath;
@@ -171,15 +262,15 @@ export interface IsolateSlashPathFunctionConfig {
171
262
  /**
172
263
  * Range to isolate
173
264
  */
174
- range: IndexRangeInput;
265
+ readonly range: IndexRangeInput;
175
266
  /**
176
267
  * Start type to force the result to be.
177
268
  */
178
- startType?: SlashPathStartType;
269
+ readonly startType?: SlashPathStartType;
179
270
  /**
180
271
  * Whether or not to isolate the path to a file path. If true, the result string will not end with a slash.
181
272
  */
182
- asFile?: boolean;
273
+ readonly asFile?: boolean;
183
274
  }
184
275
  /**
185
276
  * Isolates a configured index range of path elements.
@@ -194,3 +285,236 @@ export type IsolateSlashPathFunction = (path: SlashPath) => SlashPath;
194
285
  * @returns
195
286
  */
196
287
  export declare function isolateSlashPathFunction(config: IsolateSlashPathFunctionConfig): IsolateSlashPathFunction;
288
+ export interface SlashPathDetails {
289
+ /**
290
+ * The full path
291
+ */
292
+ readonly path: SlashPath;
293
+ /**
294
+ * The path type
295
+ */
296
+ readonly type: SlashPathType;
297
+ /**
298
+ * The last part of the path.
299
+ *
300
+ * If the input path ended with a slash, indicating it is a file, then this will include the slash.
301
+ */
302
+ readonly end: SlashPathPart;
303
+ /**
304
+ * Returns true if the input is a typed or untyped file.
305
+ */
306
+ readonly isFile: boolean;
307
+ /**
308
+ * The last part of the path, if the path is not a folder.
309
+ *
310
+ * If it is a folder, this is undefined.
311
+ */
312
+ readonly file?: Maybe<SlashPathFile | SlashPathTypedFile>;
313
+ /**
314
+ * The file name, if file is defined.
315
+ */
316
+ readonly fileName?: Maybe<string>;
317
+ /**
318
+ * The typed file part, if the file is a typed file.
319
+ */
320
+ readonly typedFile: Maybe<SlashPathTypedFile>;
321
+ /**
322
+ * The file extension of the typed file, if the file is a typed file.
323
+ */
324
+ readonly typedFileExtension?: Maybe<SlashPathTypedFileExtension>;
325
+ /**
326
+ * Contains the name of the folder the file is in, if applicable.
327
+ *
328
+ * Unset if there is no file.
329
+ */
330
+ readonly fileFolder: Maybe<SlashPathPart>;
331
+ /**
332
+ * Contains all parts of the path, minus the file part.
333
+ *
334
+ * If a folder is input, this is the entire folder path.
335
+ *
336
+ * If there is only one path part and the path is a relative path, this will be an empty string.
337
+ */
338
+ readonly folderPath: InferredSlashPathFolder;
339
+ /**
340
+ * The start type of the path.
341
+ */
342
+ readonly startType: SlashPathStartType;
343
+ /**
344
+ * All parts of the path
345
+ */
346
+ readonly parts: SlashPathPart[];
347
+ }
348
+ /**
349
+ * Returns the details of a path.
350
+ *
351
+ * @param path The path to get details for.
352
+ * @returns The details of the path.
353
+ */
354
+ export declare function slashPathDetails(path: SlashPath): SlashPathDetails;
355
+ /**
356
+ * Numbers that are translated into pre-configured function codes.
357
+ */
358
+ export declare enum SlashPathPathMatcherPartCode {
359
+ /**
360
+ * Treat as a wildcard
361
+ */
362
+ WILDCARD = 0
363
+ }
364
+ export type SlashPathPathMatcherFunction = DecisionFunction<SlashPathPart>;
365
+ /**
366
+ * A part of a path to match against.
367
+ *
368
+ * SlashPathFolders are expanded into multiple SlashPathPart values automatically.
369
+ * SlashPathPathMatcherPartCode values are translated into pre-configured functions.
370
+ * A boolean value will be translated into a decision function. NOTE: Putting false will cause all matches to fail.
371
+ * Finally, any function that is provided will be used as-is when matching against a path part.
372
+ */
373
+ export type SlashPathPathMatcherPart = SlashPathPart | SlashPathFolder | SlashPathPathMatcherPartCode | SlashPathPathMatcherFunction | boolean;
374
+ /**
375
+ * Matcher path composed of parts to match against.
376
+ */
377
+ export type SlashPathPathMatcherPath = ArrayOrValue<SlashPathPathMatcherPart>;
378
+ /**
379
+ * Expands the input matcher path into decision functions.
380
+ *
381
+ * @param path The path to expand.
382
+ * @returns An array of decision functions.
383
+ */
384
+ export declare function expandSlashPathPathMatcherPartToDecisionFunctions(path: SlashPathPathMatcherPath): SlashPathPathMatcherFunction[];
385
+ /**
386
+ * The default value to use when filling non-matching parts.
387
+ */
388
+ export declare const DEFAULT_SLASH_PATH_PATH_MATCHER_NON_MATCHING_FILL_VALUE = false;
389
+ export interface SlashPathPathMatcherConfig<N extends PrimativeValue = typeof DEFAULT_SLASH_PATH_PATH_MATCHER_NON_MATCHING_FILL_VALUE> {
390
+ /**
391
+ * The base path or parts to match against.
392
+ */
393
+ readonly targetPath: SlashPathPathMatcherPath;
394
+ /**
395
+ * A decision function to use when matching against the remaining parts of the input path that go past the target path.
396
+ *
397
+ * Defaults to a decision function that returns false.
398
+ */
399
+ readonly matchRemaining?: boolean | DecisionFunction<SlashPathPart>;
400
+ /**
401
+ * The maximum number of parts to compare/match.
402
+ */
403
+ readonly maxPartsToCompare?: number;
404
+ /**
405
+ * A value to use when filling non-matching parts.
406
+ *
407
+ * Defaults to false.
408
+ */
409
+ readonly nonMatchingFillValue?: N;
410
+ }
411
+ export type SlashPathPathMatcher<N extends PrimativeValue = typeof DEFAULT_SLASH_PATH_PATH_MATCHER_NON_MATCHING_FILL_VALUE> = (inputPath: SlashPath) => SlashPathPathMatcherResult<N>;
412
+ export interface SlashPathPathMatcherResult<N extends PrimativeValue = typeof DEFAULT_SLASH_PATH_PATH_MATCHER_NON_MATCHING_FILL_VALUE> {
413
+ /**
414
+ * The input path that was matched.
415
+ */
416
+ readonly inputPath: SlashPath;
417
+ /**
418
+ * True if the input path has the same configured base path.
419
+ */
420
+ readonly matchesTargetPath: boolean;
421
+ /**
422
+ * All parts of the input path.
423
+ */
424
+ readonly inputPathParts: SlashPathPart[];
425
+ /**
426
+ * Result of the comparison between the parts of the input path against the base path.
427
+ *
428
+ * The array element is null on parts that do not match.
429
+ */
430
+ readonly matchingParts: (SlashPathPart | null)[];
431
+ /**
432
+ * The value to use when filling non-matching parts.
433
+ */
434
+ readonly nonMatchingFillValue: N;
435
+ /**
436
+ * Result of the comparison between the parts of the input path against the base path.
437
+ *
438
+ * The array element is null on parts that match.
439
+ *
440
+ * If the input path is shorter than the target path, the remaining parts will be filled with the nonMatchingFillValue.
441
+ */
442
+ readonly nonMatchingParts: (SlashPathPart | null | N)[];
443
+ /**
444
+ * The total number of parts that did not match.
445
+ */
446
+ readonly nonMatchingPartsCount: number;
447
+ }
448
+ export type SlashPathPathMatcherConfigInput<N extends PrimativeValue = PrimativeValue> = SlashPathPathMatcherConfig<N> | SlashPathPathMatcherConfig<N>['targetPath'];
449
+ /**
450
+ * Creates a SlashPathPathMatcherConfig from the input.
451
+ *
452
+ * @param input The configuration input.
453
+ * @returns The configuration.
454
+ */
455
+ export declare function slashPathPathMatcherConfig<N extends PrimativeValue = PrimativeValue>(input: SlashPathPathMatcherConfigInput<N>): SlashPathPathMatcherConfig<N>;
456
+ /**
457
+ * Creates a SlashPathPathMatcher.
458
+ *
459
+ * @param config The configuration for the matcher.
460
+ * @returns The matcher.
461
+ */
462
+ export declare function slashPathPathMatcher<N extends PrimativeValue = PrimativeValue>(input: SlashPathPathMatcherConfigInput<N>): SlashPathPathMatcher<N>;
463
+ export interface SlashPathSubPathMatcherConfig {
464
+ /**
465
+ * The base path or parts to match against.
466
+ */
467
+ readonly basePath: SlashPathPathMatcherPath;
468
+ }
469
+ export type SlashPathSubPathMatcherResult = SlashPathSubPathMatcherNonMatchResult | SlashPathSubPathMatcherMatchResult;
470
+ export interface SlashPathSubPathMatcherBaseResult {
471
+ /**
472
+ * The input path that was matched.
473
+ */
474
+ readonly inputPath: SlashPath;
475
+ /**
476
+ * True if the input path has the same configured base path.
477
+ */
478
+ readonly matchesBasePath: boolean;
479
+ /**
480
+ * All parts of the input path.
481
+ */
482
+ readonly inputPathParts: SlashPathPart[];
483
+ /**
484
+ * Result of the comparison between the parts of the input path against the base path.
485
+ *
486
+ * The array element is null on parts that match.
487
+ */
488
+ readonly nonMatchingParts: (SlashPathPart | null)[];
489
+ /**
490
+ * All remaining parts of the path, relative to the base path.
491
+ *
492
+ * Only non-null if matchesBasePath is true.
493
+ */
494
+ readonly subPathParts: SlashPathPart[] | null;
495
+ }
496
+ export interface SlashPathSubPathMatcherMatchResult extends SlashPathSubPathMatcherBaseResult {
497
+ readonly matchesBasePath: true;
498
+ /**
499
+ * All parts of the sub path, relative to the base path.
500
+ */
501
+ readonly subPathParts: SlashPathPart[];
502
+ }
503
+ export interface SlashPathSubPathMatcherNonMatchResult extends SlashPathSubPathMatcherBaseResult {
504
+ readonly matchesBasePath: false;
505
+ /**
506
+ * Unset when the input path does not match the base path.
507
+ */
508
+ readonly subPathParts: null;
509
+ }
510
+ /**
511
+ * Used to match sub paths of a specific configured path.
512
+ */
513
+ export type SlashPathSubPathMatcher = (path: SlashPath) => SlashPathSubPathMatcherResult;
514
+ /**
515
+ * Creates a SlashPathSubPathMatcher.
516
+ *
517
+ * @param config The configuration for the matcher.
518
+ * @returns The matcher.
519
+ */
520
+ export declare function slashPathSubPathMatcher(config: SlashPathSubPathMatcherConfig): SlashPathSubPathMatcher;
@@ -8,5 +8,6 @@ export * from './promise.loop';
8
8
  export * from './promise.ref';
9
9
  export * from './promise.factory';
10
10
  export * from './promise.type';
11
+ export * from './promise.task';
11
12
  export * from './wait';
12
13
  export * from './use';
@@ -19,8 +19,8 @@ export declare function runAsyncTaskForValue<O>(taskFn: () => Promise<O>, config
19
19
  * @param config
20
20
  * @returns
21
21
  */
22
- export declare function runAsyncTasksForValues<T, K = unknown>(input: T[], taskFn: PromiseAsyncTaskFn<T, K>, config?: RunAsyncTasksForValuesConfig<T>): Promise<K[]>;
23
- export type PromiseAsyncTaskFn<T, K = unknown> = (value: T, tryNumber?: number) => Promise<K>;
22
+ export declare function runAsyncTasksForValues<T, K = unknown>(input: T[], taskFn: PerformAsyncTaskFn<T, K>, config?: RunAsyncTasksForValuesConfig<T>): Promise<K[]>;
23
+ export type PerformAsyncTaskFn<T, K = unknown> = (value: T, tryNumber?: number) => Promise<K>;
24
24
  export interface PerformAsyncTaskResult<O> {
25
25
  readonly value: Maybe<O>;
26
26
  readonly success: boolean;
@@ -58,7 +58,7 @@ export interface PerformAsyncTasksConfig<I = unknown, K extends PrimativeKey = P
58
58
  *
59
59
  * This is useful for retrying sections that may experience optimistic concurrency collisions.
60
60
  */
61
- export declare function performAsyncTasks<I, O = unknown, K extends PrimativeKey = PerformTasksInParallelTaskUniqueKey>(input: I[], taskFn: PromiseAsyncTaskFn<I, O>, config?: PerformAsyncTasksConfig<I, K>): Promise<PerformAsyncTasksResult<I, O>>;
61
+ 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>>;
62
62
  export declare function performAsyncTask<O>(taskFn: () => Promise<O>, config?: PerformAsyncTaskConfig<0>): Promise<PerformAsyncTaskResult<O>>;
63
63
  /**
64
64
  * 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.
@@ -136,3 +136,4 @@ export declare function performTasksFromFactoryInParallelFunction<I, K extends P
136
136
  * @returns A string factory that generates unique keys for non-concurrent tasks.
137
137
  */
138
138
  export declare function makeDefaultNonConcurrentTaskKeyFactory(): StringFactory<any>;
139
+ export type PromiseAsyncTaskFn<T, K = unknown> = PerformAsyncTaskFn<T, K>;
@@ -0,0 +1,63 @@
1
+ import { AsyncFactory } from '../getter/getter';
2
+ import { Maybe } from '../value';
3
+ import { RunAsyncTasksForValuesConfig } from './promise';
4
+ /**
5
+ * A function that returns a Promise, typically returning void/no value.
6
+ */
7
+ export type AsyncTask<T = void> = AsyncFactory<T>;
8
+ /**
9
+ * An AsyncTask that has a name and a run function.
10
+ */
11
+ export type NamedAsyncTask<T = void> = {
12
+ readonly name: string;
13
+ readonly run: AsyncTask<T>;
14
+ };
15
+ export type NamedAsyncTaskRecord<T = void> = Record<string, AsyncTask<T>>;
16
+ /**
17
+ * A function that runs an array of named async tasks.
18
+ */
19
+ export type RunNamedAsyncTasksFunction<T = void> = (inputTasks: RunNamedAsyncTasksInput<T>, options?: Maybe<RunNamedAsyncTasksFunctionOptions<T>>) => Promise<RunNamedAsyncTasksResult<T>>;
20
+ /**
21
+ * Options for a RunNamedAsyncTasksFunction.
22
+ */
23
+ export type RunNamedAsyncTasksFunctionOptions<T = void> = Maybe<Omit<RunAsyncTasksForValuesConfig<T>, 'nonConcurrentTaskKeyFactory' | 'retriesAllowed' | 'retryWait' | 'beforeRetry'>>;
24
+ /**
25
+ * Config for runNamedAsyncTasksFunction().
26
+ */
27
+ export interface RunNamedAsyncTasksFunctionConfig<T = void> {
28
+ readonly onTaskSuccess?: (task: NamedAsyncTask<T>, value: T) => void;
29
+ readonly onTaskFailure?: (task: NamedAsyncTask<T>, error: unknown) => void;
30
+ readonly defaultOptions?: RunNamedAsyncTasksFunctionOptions<T>;
31
+ }
32
+ /**
33
+ * The input for runNamedAsyncTasks(). Either an array of NamedAsyncTasks or a NamedAsyncTaskRecord.
34
+ */
35
+ export type RunNamedAsyncTasksInput<T = void> = NamedAsyncTaskRecord<T> | NamedAsyncTask<T>[];
36
+ /**
37
+ * The result of runNamedAsyncTasks().
38
+ */
39
+ export interface RunNamedAsyncTasksResult<T = void> {
40
+ /**
41
+ * The tasks that were run successfully.
42
+ */
43
+ readonly successfulTasks: NamedAsyncTask<T>[];
44
+ /**
45
+ * The tasks that failed.
46
+ */
47
+ readonly failedTasks: NamedAsyncTask<T>[];
48
+ }
49
+ /**
50
+ * Creates a new RunNamedAsyncTasksFunction.
51
+ *
52
+ * @param config Optional configuration.
53
+ * @returns A new RunNamedAsyncTasksFunction.
54
+ */
55
+ export declare function runNamedAsyncTasksFunction<T = void>(config?: RunNamedAsyncTasksFunctionConfig<T>): RunNamedAsyncTasksFunction<T>;
56
+ /**
57
+ * Runs the input named tasks and returns the results.
58
+ *
59
+ * @param inputTasks
60
+ * @param options
61
+ * @returns
62
+ */
63
+ export declare function runNamedAsyncTasks<T = void>(inputTasks: RunNamedAsyncTasksInput<T>, config?: RunNamedAsyncTasksFunctionConfig<T>): Promise<RunNamedAsyncTasksResult<T>>;