@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
|
@@ -1,39 +1,107 @@
|
|
|
1
1
|
import { type BatchCount } from '../grouping';
|
|
2
2
|
import { type Maybe } from '../value/maybe.type';
|
|
3
3
|
import { type PromiseOrValue } from './promise.type';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for {@link performTaskLoop} without an initial value.
|
|
6
|
+
*/
|
|
4
7
|
export interface PerformTaskLoopConfig<O> {
|
|
8
|
+
/** Produces the next value given the iteration index and the previous value. */
|
|
5
9
|
next: (i: number, prev: Maybe<O>) => Promise<O>;
|
|
10
|
+
/** Returns whether to continue looping. Called after each iteration with the current value and next index. */
|
|
6
11
|
checkContinue: (prev: Maybe<O>, i: number) => PromiseOrValue<boolean>;
|
|
7
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for {@link performTaskLoop} with a required initial value.
|
|
15
|
+
*/
|
|
8
16
|
export interface PerformTaskLoopWithInitConfig<O> {
|
|
17
|
+
/** The initial value to start the loop with. */
|
|
9
18
|
initValue: O;
|
|
19
|
+
/** Produces the next value given the iteration index and the previous value. */
|
|
10
20
|
next: (i: number, prev: O) => Promise<O>;
|
|
21
|
+
/** Returns whether to continue looping. Called after each iteration with the current value and next index. */
|
|
11
22
|
checkContinue: (prev: O, i: number) => PromiseOrValue<boolean>;
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Executes an async task in a loop, calling `next` repeatedly until `checkContinue` returns false.
|
|
26
|
+
* Optionally starts with an initial value. Returns the final value produced by the loop.
|
|
27
|
+
*
|
|
28
|
+
* @param config - Loop configuration with the next-value producer and continuation check.
|
|
29
|
+
* @returns The final value produced by the last iteration.
|
|
30
|
+
*/
|
|
13
31
|
export declare function performTaskLoop<O>(config: PerformTaskLoopWithInitConfig<O>): Promise<O>;
|
|
14
32
|
export declare function performTaskLoop<O>(config: PerformTaskLoopConfig<O>): Promise<O>;
|
|
15
33
|
export declare function performTaskLoop<O>(config: PerformTaskLoopConfig<O>): Promise<Maybe<O>>;
|
|
16
34
|
export declare function performTaskLoop(config: PerformTaskLoopConfig<void>): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Configuration for {@link performTaskCountLoop} without an initial value.
|
|
37
|
+
*/
|
|
17
38
|
export interface PerformTaskCountLoopConfig<O> extends Omit<PerformTaskLoopConfig<O>, 'checkContinue'> {
|
|
39
|
+
/** The number of iterations to perform. */
|
|
18
40
|
count: number;
|
|
19
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Configuration for {@link performTaskCountLoop} with a required initial value.
|
|
44
|
+
*/
|
|
20
45
|
export interface PerformTaskCountLoopWithInitConfig<O> extends Omit<PerformTaskLoopWithInitConfig<O>, 'checkContinue'> {
|
|
46
|
+
/** The number of iterations to perform. */
|
|
21
47
|
count: number;
|
|
22
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Performs an async task loop a fixed number of times. A convenience wrapper around
|
|
51
|
+
* {@link performTaskLoop} that automatically checks the iteration count.
|
|
52
|
+
*
|
|
53
|
+
* @param config - Loop configuration with the iteration count and next-value producer.
|
|
54
|
+
* @returns The final value produced by the last iteration.
|
|
55
|
+
*/
|
|
23
56
|
export declare function performTaskCountLoop<O>(config: PerformTaskCountLoopWithInitConfig<O>): Promise<O>;
|
|
24
57
|
export declare function performTaskCountLoop<O>(config: PerformTaskCountLoopConfig<O>): Promise<Maybe<O>>;
|
|
25
58
|
export declare function performTaskCountLoop(config: PerformTaskCountLoopConfig<void>): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* A function that creates a single item in a {@link performMakeLoop} iteration.
|
|
61
|
+
*
|
|
62
|
+
* @param i - The current iteration index.
|
|
63
|
+
* @param made - The array of items created so far.
|
|
64
|
+
*/
|
|
26
65
|
export type PerformMakeLoopFunction<O> = (i: number, made: O[]) => Promise<O>;
|
|
66
|
+
/**
|
|
67
|
+
* Configuration for {@link performMakeLoop}.
|
|
68
|
+
*/
|
|
27
69
|
export interface PerformMakeLoopConfig<O> {
|
|
70
|
+
/** The factory function to create each item. */
|
|
28
71
|
make: PerformMakeLoopFunction<O>;
|
|
72
|
+
/** The total number of items to create. */
|
|
29
73
|
count: number;
|
|
30
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates an array of items by invoking a make function in a loop a specified number of times.
|
|
77
|
+
* Each iteration receives the current index and the array of items created so far.
|
|
78
|
+
*
|
|
79
|
+
* @param config - Configuration with the make function and count.
|
|
80
|
+
* @returns An array of all created items.
|
|
81
|
+
*/
|
|
31
82
|
export declare function performMakeLoop<O>(config: PerformMakeLoopConfig<O>): Promise<O[]>;
|
|
83
|
+
/**
|
|
84
|
+
* A function that creates a batch of items in a {@link performBatchLoop} iteration.
|
|
85
|
+
*
|
|
86
|
+
* @param itemsToMake - The number of items to create in this batch.
|
|
87
|
+
* @param i - The current batch index.
|
|
88
|
+
* @param made - The array of batches created so far.
|
|
89
|
+
*/
|
|
32
90
|
export type PerformBatchLoopFunction<O> = (itemsToMake: number, i: number, made: O[][]) => Promise<O[]>;
|
|
91
|
+
/**
|
|
92
|
+
* Configuration for {@link performBatchLoop}.
|
|
93
|
+
*/
|
|
33
94
|
export interface PerformBatchLoopConfig<O> extends BatchCount {
|
|
34
95
|
/**
|
|
35
|
-
*
|
|
96
|
+
* Factory function that creates a batch of items given the requested count.
|
|
36
97
|
*/
|
|
37
98
|
make: PerformBatchLoopFunction<O>;
|
|
38
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates items in batches by dividing a total count into batch-sized chunks and
|
|
102
|
+
* invoking the make function for each batch.
|
|
103
|
+
*
|
|
104
|
+
* @param config - Configuration with the make function and batch count parameters.
|
|
105
|
+
* @returns A two-dimensional array where each inner array is a batch of created items.
|
|
106
|
+
*/
|
|
39
107
|
export declare function performBatchLoop<O>(config: PerformBatchLoopConfig<O>): Promise<O[][]>;
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A
|
|
2
|
+
* A deconstructed Promise exposing its `resolve` and `reject` functions alongside the Promise itself.
|
|
3
|
+
* Useful for controlling Promise resolution from outside the executor.
|
|
3
4
|
*/
|
|
4
5
|
export type PromiseReference<O = unknown> = {
|
|
5
6
|
readonly promise: Promise<O>;
|
|
6
7
|
readonly resolve: (value: O | PromiseLike<O>) => void;
|
|
7
8
|
readonly reject: (reason?: unknown) => void;
|
|
8
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* An executor function for a Promise, matching the signature of the native Promise constructor callback.
|
|
12
|
+
*
|
|
13
|
+
* @param resolve - Resolves the Promise with a value.
|
|
14
|
+
* @param reject - Rejects the Promise with a reason.
|
|
15
|
+
*/
|
|
9
16
|
export type PromiseExecutor<O> = (resolve: (value: O | PromiseLike<O>) => void, reject: (reason?: unknown) => void) => void;
|
|
10
17
|
/**
|
|
11
|
-
* Creates a new
|
|
18
|
+
* Creates a new {@link PromiseReference} containing a Promise and its externally accessible
|
|
19
|
+
* `resolve` and `reject` functions. An optional executor can be provided to run initialization
|
|
20
|
+
* logic inside the Promise constructor.
|
|
21
|
+
*
|
|
22
|
+
* @param executor - An optional executor function invoked inside the Promise constructor.
|
|
23
|
+
* @returns A PromiseReference with the created Promise and its control functions.
|
|
12
24
|
*/
|
|
13
25
|
export declare function promiseReference<O>(executor?: PromiseExecutor<O>): PromiseReference<O>;
|
|
@@ -12,6 +12,9 @@ export type NamedAsyncTask<T = void> = {
|
|
|
12
12
|
readonly name: string;
|
|
13
13
|
readonly run: AsyncTask<T>;
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* A record of named async tasks, keyed by name.
|
|
17
|
+
*/
|
|
15
18
|
export type NamedAsyncTaskRecord<T = void> = Record<string, AsyncTask<T>>;
|
|
16
19
|
/**
|
|
17
20
|
* A function that runs an array of named async tasks.
|
|
@@ -54,10 +57,11 @@ export interface RunNamedAsyncTasksResult<T = void> {
|
|
|
54
57
|
*/
|
|
55
58
|
export declare function runNamedAsyncTasksFunction<T = void>(config?: RunNamedAsyncTasksFunctionConfig<T>): RunNamedAsyncTasksFunction<T>;
|
|
56
59
|
/**
|
|
57
|
-
*
|
|
60
|
+
* Convenience function that creates a {@link RunNamedAsyncTasksFunction} and immediately
|
|
61
|
+
* executes it with the given tasks.
|
|
58
62
|
*
|
|
59
|
-
* @param inputTasks
|
|
60
|
-
* @param options
|
|
61
|
-
* @returns
|
|
63
|
+
* @param inputTasks - An array of named tasks or a record of task functions keyed by name.
|
|
64
|
+
* @param config - Optional configuration for callbacks and default execution options.
|
|
65
|
+
* @returns The result containing successful and failed tasks.
|
|
62
66
|
*/
|
|
63
67
|
export declare function runNamedAsyncTasks<T = void>(inputTasks: RunNamedAsyncTasksInput<T>, config?: RunNamedAsyncTasksFunctionConfig<T>): Promise<RunNamedAsyncTasksResult<T>>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A
|
|
2
|
+
* A value that may be either a Promise resolving to T, or a synchronous value of type T.
|
|
3
3
|
*/
|
|
4
4
|
export type PromiseOrValue<T> = Promise<T> | T;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Wraps the input in a resolved Promise if it is not already a Promise.
|
|
7
7
|
*
|
|
8
|
-
* @param input
|
|
9
|
-
* @returns
|
|
8
|
+
* @param input - A value or Promise to normalize into a Promise.
|
|
9
|
+
* @returns A Promise that resolves to the input value.
|
|
10
10
|
*/
|
|
11
11
|
export declare function asPromise<T>(input: PromiseOrValue<T>): Promise<T>;
|
package/src/lib/promise/use.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { type GetterOrValue } from '../getter';
|
|
2
2
|
import { type UseAsync } from '../value';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* A function that resolves a cached Promise value and passes it to the given async consumer,
|
|
5
|
+
* returning the consumer's result.
|
|
5
6
|
*/
|
|
6
7
|
export type UsePromiseFunction<I> = <O>(useFn: UseAsync<I, O>) => Promise<O>;
|
|
7
8
|
/**
|
|
8
|
-
* Creates a UsePromiseFunction
|
|
9
|
+
* Creates a {@link UsePromiseFunction} that resolves the input promise and passes the result
|
|
10
|
+
* to any consumer function provided at call time.
|
|
9
11
|
*
|
|
10
|
-
* @param input
|
|
11
|
-
* @returns
|
|
12
|
+
* @param input - A Promise or a getter that returns a Promise, whose resolved value will be passed to consumers.
|
|
13
|
+
* @returns A function that accepts an async consumer and returns the consumer's result.
|
|
12
14
|
*/
|
|
13
15
|
export declare function usePromise<I>(input: GetterOrValue<Promise<I>>): UsePromiseFunction<I>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Returns a Promise that resolves after the specified number of milliseconds.
|
|
3
|
+
* Optionally resolves with the provided value.
|
|
3
4
|
*
|
|
4
|
-
* @param ms
|
|
5
|
+
* @param ms - The number of milliseconds to wait before resolving.
|
|
6
|
+
* @param value - An optional value to resolve the Promise with.
|
|
7
|
+
* @returns A Promise that resolves after the specified delay.
|
|
5
8
|
*/
|
|
6
9
|
export declare function waitForMs(ms: number): Promise<void>;
|
|
@@ -34,12 +34,33 @@ export declare const RelationChange: {
|
|
|
34
34
|
*/
|
|
35
35
|
readonly INSERT: "insert";
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Union of all valid {@link RelationChange} values.
|
|
39
|
+
*/
|
|
37
40
|
export type RelationChangeType = (typeof RelationChange)[keyof typeof RelationChange];
|
|
41
|
+
/**
|
|
42
|
+
* A string-based relation identifier.
|
|
43
|
+
*/
|
|
38
44
|
export type RelationString = string;
|
|
45
|
+
/**
|
|
46
|
+
* A relation target that is either a string key or an object containing relation data.
|
|
47
|
+
*/
|
|
39
48
|
export type RelationObject = RelationString | object;
|
|
49
|
+
/**
|
|
50
|
+
* A string identifying the type/category of a relation model.
|
|
51
|
+
*/
|
|
40
52
|
export type RelationModelType = string;
|
|
53
|
+
/**
|
|
54
|
+
* A unique key identifying a relation model, either a string or number.
|
|
55
|
+
*/
|
|
41
56
|
export type RelationKey = string | number;
|
|
57
|
+
/**
|
|
58
|
+
* Extracts the unique key from a relation model.
|
|
59
|
+
*/
|
|
42
60
|
export type ReadRelationKeyFn<T> = (model: T) => RelationKey;
|
|
61
|
+
/**
|
|
62
|
+
* Extracts the model type string from a relation model.
|
|
63
|
+
*/
|
|
43
64
|
export type ReadRelationModelTypeFn<T> = (model: T) => RelationModelType;
|
|
44
65
|
/**
|
|
45
66
|
* Merges the two input values. The "a" value is usually the existing/incumbent value, while "b" is the new value.
|
|
@@ -49,6 +70,9 @@ export type MergeRelationObjectsFn<T> = (a: T, b: T) => T;
|
|
|
49
70
|
* Whether or not the object is changable as part of this request.
|
|
50
71
|
*/
|
|
51
72
|
export type ChangeRelationObjectsMaskFn<T> = (x: T) => boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Configuration for modifying a single-type relation collection via {@link ModelRelationUtility}.
|
|
75
|
+
*/
|
|
52
76
|
export interface UpdateRelationConfig<T> {
|
|
53
77
|
readKey: ReadRelationKeyFn<T>;
|
|
54
78
|
merge: MergeRelationObjectsFn<T>;
|
|
@@ -64,6 +88,9 @@ export interface UpdateRelationConfig<T> {
|
|
|
64
88
|
*/
|
|
65
89
|
mask?: ChangeRelationObjectsMaskFn<T>;
|
|
66
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Extends {@link UpdateRelationConfig} with a type reader for multi-type relation collections.
|
|
93
|
+
*/
|
|
67
94
|
export interface UpdateMiltiTypeRelationConfig<T> extends UpdateRelationConfig<T> {
|
|
68
95
|
readType: ReadRelationModelTypeFn<T>;
|
|
69
96
|
}
|
|
@@ -73,7 +100,25 @@ export interface UpdateMiltiTypeRelationConfig<T> extends UpdateRelationConfig<T
|
|
|
73
100
|
* For instance, a string collection of keys.
|
|
74
101
|
*/
|
|
75
102
|
export declare class ModelRelationUtility {
|
|
103
|
+
/**
|
|
104
|
+
* Convenience method that modifies a collection of plain string relations.
|
|
105
|
+
*
|
|
106
|
+
* @param current - The current string collection.
|
|
107
|
+
* @param change - The type of relation change to perform.
|
|
108
|
+
* @param mods - The string values to apply as modifications.
|
|
109
|
+
* @returns The modified string collection.
|
|
110
|
+
*/
|
|
76
111
|
static modifyStringCollection(current: Maybe<RelationString[]>, change: RelationChangeType, mods: RelationString[]): RelationString[];
|
|
112
|
+
/**
|
|
113
|
+
* Applies a {@link RelationChangeType} operation to a typed collection of relation objects.
|
|
114
|
+
* Supports single-type and multi-type collections depending on the config.
|
|
115
|
+
*
|
|
116
|
+
* @param current - The current collection of relation objects.
|
|
117
|
+
* @param change - The relation change operation to perform.
|
|
118
|
+
* @param mods - The modification objects to apply.
|
|
119
|
+
* @param config - Configuration providing key/type readers, merge function, and optional mask.
|
|
120
|
+
* @returns The modified collection.
|
|
121
|
+
*/
|
|
77
122
|
static modifyCollection<T extends RelationObject>(current: Maybe<T[]>, change: RelationChangeType, mods: T[], config: UpdateMiltiTypeRelationConfig<T>): T[];
|
|
78
123
|
static modifyCollection<T extends RelationObject>(current: Maybe<T[]>, change: RelationChangeType, mods: T[], config: UpdateRelationConfig<T>): T[];
|
|
79
124
|
/**
|
|
@@ -83,7 +128,24 @@ export declare class ModelRelationUtility {
|
|
|
83
128
|
*/
|
|
84
129
|
private static _mergeMaskResults;
|
|
85
130
|
private static _modifyCollectionWithoutMask;
|
|
131
|
+
/**
|
|
132
|
+
* Merges update objects into matching existing items in the collection. Items without a match are ignored.
|
|
133
|
+
*
|
|
134
|
+
* @param current - The current collection.
|
|
135
|
+
* @param update - The objects to merge into matching items.
|
|
136
|
+
* @param config - Configuration with key/type readers and merge function.
|
|
137
|
+
* @returns The updated collection.
|
|
138
|
+
*/
|
|
86
139
|
static updateCollection<T extends RelationObject>(current: T[], update: T[], config: UpdateRelationConfig<T> | UpdateMiltiTypeRelationConfig<T>): T[];
|
|
140
|
+
/**
|
|
141
|
+
* Inserts objects into the collection: merges with existing items that share a key,
|
|
142
|
+
* and adds new items that have no match.
|
|
143
|
+
*
|
|
144
|
+
* @param current - The current collection.
|
|
145
|
+
* @param update - The objects to insert or merge.
|
|
146
|
+
* @param config - Configuration with key/type readers and merge function.
|
|
147
|
+
* @returns The collection with insertions and merges applied.
|
|
148
|
+
*/
|
|
87
149
|
static insertCollection<T extends RelationObject>(current: T[], update: T[], config: UpdateRelationConfig<T> | UpdateMiltiTypeRelationConfig<T>): T[];
|
|
88
150
|
/**
|
|
89
151
|
* Used to modify a collection which may be multi-type. If readType is provided, the collection is handled as a multi-type map.
|
|
@@ -92,9 +154,45 @@ export declare class ModelRelationUtility {
|
|
|
92
154
|
private static _modifyMultiTypeCollection;
|
|
93
155
|
private static _insertSingleTypeCollection;
|
|
94
156
|
private static _updateSingleTypeCollection;
|
|
157
|
+
/**
|
|
158
|
+
* Adds items to the collection, replacing any existing items with the same key.
|
|
159
|
+
* New items take precedence over existing ones with duplicate keys.
|
|
160
|
+
*
|
|
161
|
+
* @param current - The current collection.
|
|
162
|
+
* @param add - The items to add.
|
|
163
|
+
* @param readKey - Function to extract the unique key from each item.
|
|
164
|
+
* @returns The collection with added items.
|
|
165
|
+
*/
|
|
95
166
|
static addToCollection<T extends RelationObject>(current: Maybe<T[]>, add: T[], readKey: ReadRelationKeyFn<T>): T[];
|
|
167
|
+
/**
|
|
168
|
+
* Removes items from the collection by matching keys. Optionally uses a `shouldRemove`
|
|
169
|
+
* predicate to conditionally skip removal of matched items.
|
|
170
|
+
*
|
|
171
|
+
* @param current - The current collection.
|
|
172
|
+
* @param remove - The items whose keys identify which items to remove.
|
|
173
|
+
* @param readKey - Function to extract the unique key from each item.
|
|
174
|
+
* @param shouldRemove - Optional predicate that must return true for a matched item to actually be removed.
|
|
175
|
+
* @returns The collection with matching items removed.
|
|
176
|
+
*/
|
|
96
177
|
static removeFromCollection<T extends RelationObject>(current: Maybe<T[]>, remove: T[], readKey: ReadRelationKeyFn<T>, shouldRemove?: (x: T) => boolean): T[];
|
|
178
|
+
/**
|
|
179
|
+
* Removes items from the collection whose keys match any of the given keys to remove.
|
|
180
|
+
*
|
|
181
|
+
* @param current - The current collection.
|
|
182
|
+
* @param keysToRemove - The keys identifying items to remove.
|
|
183
|
+
* @param readKey - Function to extract the unique key from each item.
|
|
184
|
+
* @returns The collection with matching items removed.
|
|
185
|
+
*/
|
|
97
186
|
static removeKeysFromCollection<T extends RelationObject>(current: Maybe<T[]>, keysToRemove: RelationKey[], readKey: ReadRelationKeyFn<T>): T[];
|
|
187
|
+
/**
|
|
188
|
+
* Removes duplicate items from the collection by key, keeping the first occurrence.
|
|
189
|
+
* Optionally excludes items whose keys appear in an additional keys list.
|
|
190
|
+
*
|
|
191
|
+
* @param relations - The collection to deduplicate.
|
|
192
|
+
* @param readKey - Function to extract the unique key from each item.
|
|
193
|
+
* @param additionalKeys - Extra keys to treat as already seen (items with these keys are excluded).
|
|
194
|
+
* @returns The deduplicated collection.
|
|
195
|
+
*/
|
|
98
196
|
static removeDuplicates<T>(relations: Maybe<T[]>, readKey: ReadRelationKeyFn<T>, additionalKeys?: RelationKey[]): T[];
|
|
99
197
|
private static _assertMergeProvided;
|
|
100
198
|
}
|
|
@@ -10,11 +10,12 @@ export interface HandlerBindAccessor<T, K extends PrimativeKey = string, R = Han
|
|
|
10
10
|
readonly boundTo: unknown;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* Creates a HandlerBindAccessor
|
|
13
|
+
* Creates a {@link HandlerBindAccessor} that automatically binds handler functions to the given object
|
|
14
|
+
* when registering them via `set`.
|
|
14
15
|
*
|
|
15
|
-
* @param
|
|
16
|
-
* @param accessor
|
|
17
|
-
* @returns
|
|
16
|
+
* @param boundTo - The object to bind handler functions to.
|
|
17
|
+
* @param accessor - The underlying handler accessor to delegate to.
|
|
18
|
+
* @returns A HandlerBindAccessor wrapping the accessor with automatic binding.
|
|
18
19
|
*/
|
|
19
20
|
export declare function handlerBindAccessor<T, K extends PrimativeKey = string, R = HandleResult>(boundTo: unknown, accessor: HandlerAccessor<T, K, R>): HandlerBindAccessor<T, K, R>;
|
|
20
21
|
/**
|
|
@@ -22,27 +23,64 @@ export declare function handlerBindAccessor<T, K extends PrimativeKey = string,
|
|
|
22
23
|
*/
|
|
23
24
|
export type HandlerSetFunction<T, R = HandleResult> = (handlerFunction: InternalHandlerFunction<T, R>) => void;
|
|
24
25
|
/**
|
|
25
|
-
* Creates a HandlerSetFunction.
|
|
26
|
+
* Creates a {@link HandlerSetFunction} that registers a handler function on a pre-defined key.
|
|
26
27
|
*
|
|
27
|
-
* @param accessor
|
|
28
|
-
* @param key
|
|
29
|
-
* @returns
|
|
28
|
+
* @param accessor - The handler set accessor to register on.
|
|
29
|
+
* @param key - The key (or keys) to associate the handler with.
|
|
30
|
+
* @returns A function that accepts a handler function and registers it for the given key.
|
|
30
31
|
*/
|
|
31
32
|
export declare function handlerSetFunction<T, K extends PrimativeKey = string, R = HandleResult>(accessor: HandlerSetAccessor<T, K, R>, key: ArrayOrValue<K>): HandlerSetFunction<T, R>;
|
|
33
|
+
/**
|
|
34
|
+
* A function that registers a handler function whose input type differs from the handler's native type,
|
|
35
|
+
* using a mapping function to convert between them.
|
|
36
|
+
*/
|
|
32
37
|
export type HandlerMappedSetFunction<I, R = HandleResult> = (handlerFunction: InternalHandlerFunction<I, R>) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a {@link HandlerMappedSetFunction} that maps the handler's native input type to a different
|
|
40
|
+
* type before invoking the registered handler function.
|
|
41
|
+
*
|
|
42
|
+
* @param accessor - The handler set accessor to register on.
|
|
43
|
+
* @param key - The key (or keys) to associate the handler with.
|
|
44
|
+
* @param mapFn - Function to map from the handler's native type to the handler function's expected type.
|
|
45
|
+
* @returns A function that accepts a mapped handler function and registers it.
|
|
46
|
+
*/
|
|
33
47
|
export declare function handlerMappedSetFunction<I, T, K extends PrimativeKey = string, R = HandleResult>(accessor: HandlerSetAccessor<T, K, R>, key: ArrayOrValue<K>, mapFn: MapFunction<T, I>): HandlerMappedSetFunction<I, R>;
|
|
34
48
|
/**
|
|
35
49
|
* Factory for a HandlerMappedSetFunction<I>.
|
|
36
50
|
*/
|
|
37
51
|
export type HandlerMappedSetFunctionFactory<I, K extends PrimativeKey = string, R = HandleResult> = (key: ArrayOrValue<K>) => HandlerMappedSetFunction<I, R>;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a {@link HandlerMappedSetFunctionFactory} that produces mapped set functions for any given key.
|
|
54
|
+
*
|
|
55
|
+
* @param accessor - The handler set accessor to register on.
|
|
56
|
+
* @param mapFn - Function to map from the handler's native type to the handler function's expected type.
|
|
57
|
+
* @returns A factory that creates HandlerMappedSetFunctions for specific keys.
|
|
58
|
+
*/
|
|
38
59
|
export declare function handlerMappedSetFunctionFactory<I, T, K extends PrimativeKey = string, R = HandleResult>(accessor: HandlerSetAccessor<T, K, R>, mapFn: MapFunction<T, I>): HandlerMappedSetFunctionFactory<I, K, R>;
|
|
60
|
+
/**
|
|
61
|
+
* A function that configures handler bindings via a configurer object.
|
|
62
|
+
*/
|
|
39
63
|
export type HandlerConfigurerFunction<C extends HandlerBindAccessor<T, K, R>, T, K extends PrimativeKey = string, R = HandleResult> = (configurer: C) => void;
|
|
64
|
+
/**
|
|
65
|
+
* A function that binds an object to a handler and invokes a configure callback.
|
|
66
|
+
*/
|
|
40
67
|
export type HandlerConfigurer<C extends HandlerBindAccessor<T, K, R>, T, K extends PrimativeKey = string, R = HandleResult> = (bindTo: unknown, configure: HandlerConfigurerFunction<C, T, K, R>) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Factory that creates a {@link HandlerConfigurer} for a given handler.
|
|
70
|
+
*/
|
|
41
71
|
export type HandlerConfigurerFactory<C extends HandlerBindAccessor<T, K, R>, T, K extends PrimativeKey = string, R = HandleResult> = (handler: Handler<T, K, R>) => HandlerConfigurer<C, T, K, R>;
|
|
42
72
|
/**
|
|
43
|
-
*
|
|
73
|
+
* Configuration for {@link handlerConfigurerFactory}.
|
|
44
74
|
*/
|
|
45
75
|
export interface HandlerConfigurerFactoryConfig<C extends HandlerBindAccessor<T, K, R>, T, K extends PrimativeKey = string, R = HandleResult> {
|
|
76
|
+
/** Creates a typed configurer from a bind accessor. */
|
|
46
77
|
configurerForAccessor: (accessor: HandlerBindAccessor<T, K, R>) => C;
|
|
47
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Creates a {@link HandlerConfigurerFactory} that produces configurers for binding handler functions
|
|
81
|
+
* to a handler instance with automatic `this` binding.
|
|
82
|
+
*
|
|
83
|
+
* @param config - Configuration providing the accessor-to-configurer mapping.
|
|
84
|
+
* @returns A factory that creates HandlerConfigurers for specific handlers.
|
|
85
|
+
*/
|
|
48
86
|
export declare function handlerConfigurerFactory<C extends HandlerBindAccessor<T, K, R>, T, K extends PrimativeKey = string, R = HandleResult>(config: HandlerConfigurerFactoryConfig<C, T, K, R>): HandlerConfigurerFactory<C, T, K, R>;
|
|
@@ -2,7 +2,7 @@ import { type PrimativeKey, type ReadKeyFunction } from '../key';
|
|
|
2
2
|
import { type ArrayOrValue } from '../array/array';
|
|
3
3
|
import { type PromiseOrValue } from '../promise/promise.type';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Special key used to register a catch-all handler that matches any unhandled key.
|
|
6
6
|
*/
|
|
7
7
|
export declare const CATCH_ALL_HANDLE_RESULT_KEY = "__CATCH_ALL_HANDLE_RESULT_KEY__";
|
|
8
8
|
/**
|
|
@@ -15,7 +15,13 @@ export type HandleResult = boolean;
|
|
|
15
15
|
* If void is returned, assumes true.
|
|
16
16
|
*/
|
|
17
17
|
export type InternalHandlerFunctionHandleResult = HandleResult | void;
|
|
18
|
+
/**
|
|
19
|
+
* The type of the catch-all handler key constant.
|
|
20
|
+
*/
|
|
18
21
|
export type HandlerCatchAllKey = typeof CATCH_ALL_HANDLE_RESULT_KEY;
|
|
22
|
+
/**
|
|
23
|
+
* A handler key that is either a specific key type or the catch-all key.
|
|
24
|
+
*/
|
|
19
25
|
export type HandlerKey<K extends PrimativeKey = string> = K | HandlerCatchAllKey;
|
|
20
26
|
/**
|
|
21
27
|
* Used to perform a task on the input value.
|
|
@@ -27,6 +33,9 @@ export type HandlerFunction<T, R = HandleResult> = (value: T) => Promise<R>;
|
|
|
27
33
|
* HandleFunction, but used only by Handler that can return undefined.
|
|
28
34
|
*/
|
|
29
35
|
export type InternalHandlerFunction<T, R = HandleResult> = (value: T) => PromiseOrValue<R | void>;
|
|
36
|
+
/**
|
|
37
|
+
* Provides methods to register handler functions for specific keys.
|
|
38
|
+
*/
|
|
30
39
|
export interface HandlerSetAccessor<T, K extends PrimativeKey = string, R = HandleResult> {
|
|
31
40
|
/**
|
|
32
41
|
* Adds a new handler function to the current handler.
|
|
@@ -42,6 +51,9 @@ export interface HandlerSetAccessor<T, K extends PrimativeKey = string, R = Hand
|
|
|
42
51
|
*/
|
|
43
52
|
setCatchAll(handle: InternalHandlerFunction<T, R>): void;
|
|
44
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Extends {@link HandlerSetAccessor} with a key reader and a bind-aware set method.
|
|
56
|
+
*/
|
|
45
57
|
export interface HandlerAccessor<T, K extends PrimativeKey = string, R = HandleResult> extends HandlerSetAccessor<T, K, R> {
|
|
46
58
|
/**
|
|
47
59
|
* Used to read a handler key from the input value.
|
|
@@ -56,13 +68,43 @@ export interface HandlerAccessor<T, K extends PrimativeKey = string, R = HandleR
|
|
|
56
68
|
*/
|
|
57
69
|
bindSet(bindTo: unknown, key: ArrayOrValue<HandlerKey<K>>, handle: InternalHandlerFunction<T, R>): void;
|
|
58
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* A callable handler function combined with its accessor interface for registering sub-handlers.
|
|
73
|
+
*/
|
|
59
74
|
export type Handler<T, K extends PrimativeKey = string, R = HandleResult> = HandlerFunction<T, R> & HandlerAccessor<T, K, R>;
|
|
75
|
+
/**
|
|
76
|
+
* Factory that creates new {@link Handler} instances.
|
|
77
|
+
*/
|
|
60
78
|
export type HandlerFactory<T, K extends PrimativeKey = string, R = HandleResult> = () => Handler<T, K, R>;
|
|
79
|
+
/**
|
|
80
|
+
* Options for configuring default and negative results in a {@link HandlerFactory}.
|
|
81
|
+
*/
|
|
61
82
|
export interface HandlerFactoryOptions<R = HandleResult> {
|
|
83
|
+
/** The result returned when a handler function returns void. */
|
|
62
84
|
readonly defaultResult: R;
|
|
85
|
+
/** The result returned when no handler matches the input key. */
|
|
63
86
|
readonly negativeResult: R;
|
|
64
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Creates a {@link HandlerFactory} that produces key-based dispatch handlers.
|
|
90
|
+
* Each handler routes incoming values to registered handler functions based on a key extracted from the value.
|
|
91
|
+
*
|
|
92
|
+
* @param readKey - Function to extract the dispatch key from an input value.
|
|
93
|
+
* @param options - Optional configuration for default and negative result values.
|
|
94
|
+
* @returns A factory that creates new Handler instances.
|
|
95
|
+
*/
|
|
65
96
|
export declare function handlerFactory<T, K extends PrimativeKey = string>(readKey: ReadKeyFunction<T, K>): HandlerFactory<T, K, HandleResult>;
|
|
66
97
|
export declare function handlerFactory<T, K extends PrimativeKey = string, R = HandleResult>(readKey: ReadKeyFunction<T, K>, options: HandlerFactoryOptions<R>): HandlerFactory<T, K, R>;
|
|
98
|
+
/**
|
|
99
|
+
* Convenience function that creates a new {@link Handler} from the given key reader using default options.
|
|
100
|
+
*
|
|
101
|
+
* @param readKey - Function to extract the dispatch key from an input value.
|
|
102
|
+
* @returns A new Handler instance.
|
|
103
|
+
*/
|
|
67
104
|
export declare function makeHandler<T, K extends PrimativeKey = string>(readKey: ReadKeyFunction<T, K>): Handler<T, K>;
|
|
105
|
+
/**
|
|
106
|
+
* Returns the {@link CATCH_ALL_HANDLE_RESULT_KEY} constant, useful for registering a catch-all handler.
|
|
107
|
+
*
|
|
108
|
+
* @returns The catch-all handler key.
|
|
109
|
+
*/
|
|
68
110
|
export declare function catchAllHandlerKey(): typeof CATCH_ALL_HANDLE_RESULT_KEY;
|
|
@@ -15,16 +15,35 @@ export interface TypedServiceRegistry<S, T extends string = string> {
|
|
|
15
15
|
*/
|
|
16
16
|
export declare class TypedServiceRegistryInstance<S, T extends string = string> implements TypedServiceRegistry<S, T> {
|
|
17
17
|
private _map;
|
|
18
|
+
/**
|
|
19
|
+
* Registers a service (or getter) for the given type key.
|
|
20
|
+
*
|
|
21
|
+
* @param type - The type key to register the service under.
|
|
22
|
+
* @param service - The service instance or a getter function that returns it.
|
|
23
|
+
*/
|
|
18
24
|
registerServiceForType(type: T, service: GetterOrValue<S>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the service registered for the given type. Throws if no service is registered.
|
|
27
|
+
*
|
|
28
|
+
* @param type - The type key to look up.
|
|
29
|
+
* @returns The registered service instance.
|
|
30
|
+
* @throws Error if no service is registered for the given type.
|
|
31
|
+
*/
|
|
19
32
|
serviceForType(type: T): S;
|
|
20
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Configuration for initializing a {@link TypedServiceRegistryInstance} with a set of services.
|
|
36
|
+
*/
|
|
21
37
|
export interface TypedServiceRegistrySetupConfig<S, T extends string = string> {
|
|
38
|
+
/** A record mapping type keys to their service instances. */
|
|
22
39
|
services: {
|
|
23
40
|
[K in T]: S;
|
|
24
41
|
};
|
|
25
42
|
}
|
|
26
43
|
/**
|
|
27
|
-
* Creates a new TypedServiceRegistryInstance and registers the
|
|
28
|
-
*
|
|
44
|
+
* Creates a new {@link TypedServiceRegistryInstance} and registers all services from the provided config.
|
|
45
|
+
*
|
|
46
|
+
* @param config - Configuration containing the services to register.
|
|
47
|
+
* @returns A new TypedServiceRegistryInstance with all services registered.
|
|
29
48
|
*/
|
|
30
49
|
export declare function typedServiceRegistry<S, T extends string = string>(config: TypedServiceRegistrySetupConfig<S, T>): TypedServiceRegistryInstance<S, T>;
|
|
@@ -14,10 +14,12 @@ export interface AllowedSet<T> {
|
|
|
14
14
|
readonly disallowed?: Maybe<Set<T>>;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* Determines whether the input values are "allowed" for the given AllowedSet.
|
|
17
|
+
* Determines whether the input values are "allowed" for the given {@link AllowedSet}.
|
|
18
|
+
* A value is allowed if it matches the `allowed` set (or `allowed` is not specified)
|
|
19
|
+
* and does not match the `disallowed` set.
|
|
18
20
|
*
|
|
19
|
-
* @param input
|
|
20
|
-
* @param allowedSet
|
|
21
|
-
* @returns
|
|
21
|
+
* @param input - The value or array of values to check.
|
|
22
|
+
* @param allowedSet - The allowed/disallowed configuration.
|
|
23
|
+
* @returns `true` if the values are allowed.
|
|
22
24
|
*/
|
|
23
25
|
export declare function isAllowed<T>(input: ArrayOrValue<T>, allowedSet: AllowedSet<T>): boolean;
|