@dereekb/util 13.0.7 → 13.1.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
|
@@ -7,109 +7,121 @@ import { type Maybe } from '../value/maybe.type';
|
|
|
7
7
|
* Note that strings are a valid Iterable, allowing iteration over characters.
|
|
8
8
|
*/
|
|
9
9
|
export type IterableOrValue<T> = T | Iterable<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Converts an IterableOrValue to an Iterable. Non-iterable values are wrapped in an array.
|
|
12
|
+
*
|
|
13
|
+
* @param values - The value or iterable to convert
|
|
14
|
+
* @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false)
|
|
15
|
+
* @returns An Iterable containing the value(s)
|
|
16
|
+
*/
|
|
10
17
|
export declare function asIterable<T = unknown>(values: IterableOrValue<T>, treatStringAsIterable?: boolean): Iterable<T>;
|
|
11
18
|
/**
|
|
12
|
-
* Converts
|
|
19
|
+
* Converts an IterableOrValue to an array.
|
|
13
20
|
*
|
|
14
|
-
* By default
|
|
21
|
+
* By default treats strings as a non-iterable value, using the string as a single value.
|
|
15
22
|
*
|
|
16
|
-
* @param values
|
|
17
|
-
* @param treatStringAsIterable
|
|
18
|
-
* @returns
|
|
23
|
+
* @param values - The value or iterable to convert
|
|
24
|
+
* @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false)
|
|
25
|
+
* @returns An array containing the value(s)
|
|
19
26
|
*/
|
|
20
27
|
export declare function iterableToArray<T = unknown>(values: IterableOrValue<T>, treatStringAsIterable?: boolean): T[];
|
|
21
28
|
/**
|
|
22
|
-
* Converts
|
|
29
|
+
* Converts an IterableOrValue to a Set.
|
|
23
30
|
*
|
|
24
|
-
* By default
|
|
31
|
+
* By default treats strings as a non-iterable value, using the string as a single value.
|
|
25
32
|
*
|
|
26
|
-
* @param values
|
|
27
|
-
* @param treatStringAsIterable
|
|
28
|
-
* @returns
|
|
33
|
+
* @param values - The value or iterable to convert
|
|
34
|
+
* @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false)
|
|
35
|
+
* @returns A Set containing the value(s)
|
|
29
36
|
*/
|
|
30
37
|
export declare function iterableToSet<T = unknown>(values: IterableOrValue<T>, treatStringAsIterable?: boolean): Set<T>;
|
|
31
38
|
/**
|
|
32
|
-
* Converts
|
|
39
|
+
* Converts an IterableOrValue to a Map using a key extraction function.
|
|
33
40
|
*
|
|
34
|
-
* @param values
|
|
35
|
-
* @param readKey
|
|
36
|
-
* @returns
|
|
41
|
+
* @param values - The value or iterable to convert
|
|
42
|
+
* @param readKey - Function to extract the key from each value
|
|
43
|
+
* @returns A Map with the extracted keys and their corresponding values
|
|
37
44
|
*/
|
|
38
45
|
export declare function iterableToMap<T, K extends PrimativeKey = PrimativeKey>(values: IterableOrValue<T>, readKey: ReadKeyFunction<T, K>): Map<Maybe<K>, T>;
|
|
39
46
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* Can specify whether or not to treat string values as iterable values. Is false by default.
|
|
47
|
+
* Type guard that returns true if the input is an Iterable.
|
|
48
|
+
* By default, strings are not treated as iterable.
|
|
43
49
|
*
|
|
44
|
-
* @param values
|
|
45
|
-
* @param treatStringAsIterable
|
|
46
|
-
* @returns
|
|
50
|
+
* @param values - The value to check
|
|
51
|
+
* @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false)
|
|
52
|
+
* @returns True if the value is iterable
|
|
47
53
|
*/
|
|
48
54
|
export declare function isIterable<T = unknown>(values: unknown, treatStringAsIterable?: boolean): values is Iterable<T>;
|
|
49
55
|
/**
|
|
50
|
-
* Returns true if
|
|
56
|
+
* Returns true if the iterable has no values.
|
|
51
57
|
*
|
|
52
|
-
* @param values
|
|
53
|
-
* @returns
|
|
58
|
+
* @param values - The iterable to check
|
|
59
|
+
* @returns True if the iterable is empty
|
|
54
60
|
*/
|
|
55
61
|
export declare function isEmptyIterable<T = unknown>(values: Iterable<T>): boolean;
|
|
56
62
|
/**
|
|
57
|
-
* Returns the first value from the Iterable
|
|
63
|
+
* Returns the first value from the Iterable, or undefined if empty. Order is not guaranteed.
|
|
58
64
|
*
|
|
59
|
-
* @param values
|
|
60
|
-
* @returns
|
|
65
|
+
* @param values - The iterable to read from
|
|
66
|
+
* @returns The first value, or undefined if empty
|
|
61
67
|
*/
|
|
62
68
|
export declare function firstValueFromIterable<T>(values: Iterable<T>): Maybe<T>;
|
|
63
69
|
/**
|
|
64
|
-
* Takes items from the iterable
|
|
70
|
+
* Takes up to `count` items from the iterable. Order is not guaranteed.
|
|
65
71
|
*
|
|
66
|
-
* @param values
|
|
67
|
-
* @param count
|
|
68
|
-
* @returns
|
|
72
|
+
* @param values - The iterable to take from
|
|
73
|
+
* @param count - Maximum number of items to take
|
|
74
|
+
* @returns An array of taken values
|
|
69
75
|
*/
|
|
70
76
|
export declare function takeValuesFromIterable<T>(values: Iterable<T>, count: number): T[];
|
|
71
77
|
/**
|
|
72
|
-
* Iterates over iterable values.
|
|
78
|
+
* Iterates over iterable values, calling the function for each one.
|
|
73
79
|
*
|
|
74
|
-
* @param values
|
|
75
|
-
* @param fn
|
|
80
|
+
* @param values - The iterable to iterate over
|
|
81
|
+
* @param fn - The function to call for each value
|
|
76
82
|
*/
|
|
77
83
|
export declare function forEachInIterable<T>(values: Iterable<T>, fn: (value: T) => void): void;
|
|
78
84
|
/**
|
|
79
|
-
*
|
|
85
|
+
* Calls the function for each value if the input is iterable, or once with the value if it's a single value.
|
|
86
|
+
* Does nothing if the input is null/undefined.
|
|
80
87
|
*
|
|
81
|
-
* @param values
|
|
82
|
-
* @param fn
|
|
88
|
+
* @param values - The value or iterable to process
|
|
89
|
+
* @param fn - The function to call for each value
|
|
90
|
+
* @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false)
|
|
83
91
|
*/
|
|
84
92
|
export declare function useIterableOrValue<T>(values: Maybe<IterableOrValue<T>>, fn: (value: T) => void, treatStringAsIterable?: boolean): void;
|
|
85
93
|
/**
|
|
86
|
-
*
|
|
94
|
+
* Finds and returns the first value in the iterable that matches the decision function.
|
|
87
95
|
*
|
|
88
|
-
* @param values
|
|
89
|
-
* @param fn
|
|
96
|
+
* @param values - The iterable to search
|
|
97
|
+
* @param fn - Decision function that returns true for the desired value
|
|
98
|
+
* @returns The first matching value, or undefined
|
|
90
99
|
*/
|
|
91
100
|
export declare function findInIterable<T>(values: Iterable<T>, fn: DecisionFunction<T>): Maybe<T>;
|
|
92
101
|
/**
|
|
93
|
-
*
|
|
102
|
+
* Returns true if any value in the iterable matches the decision function.
|
|
94
103
|
*
|
|
95
|
-
* @param values
|
|
96
|
-
* @param fn
|
|
97
|
-
* @returns
|
|
104
|
+
* @param values - The iterable to search
|
|
105
|
+
* @param fn - Decision function to test each value
|
|
106
|
+
* @returns True if at least one value matches
|
|
98
107
|
*/
|
|
99
108
|
export declare function existsInIterable<T>(values: Iterable<T>, fn: DecisionFunction<T>): boolean;
|
|
100
109
|
/**
|
|
101
|
-
* Filters values from the iterable
|
|
110
|
+
* Filters values from the iterable, keeping those that pass the decision function.
|
|
102
111
|
*
|
|
103
|
-
* @param values
|
|
104
|
-
* @param fn
|
|
105
|
-
* @returns
|
|
112
|
+
* @param values - The iterable to filter
|
|
113
|
+
* @param fn - Decision function that returns true for values to keep
|
|
114
|
+
* @returns An array of matching values
|
|
106
115
|
*/
|
|
107
116
|
export declare function filterFromIterable<T>(values: Iterable<T>, fn: DecisionFunction<T>): T[];
|
|
108
117
|
/**
|
|
109
|
-
* Wraps
|
|
118
|
+
* Wraps a single tuple value into an array. Distinguishes between a single tuple and an array of tuples
|
|
119
|
+
* by checking whether nested array elements have uniform length.
|
|
110
120
|
*
|
|
111
|
-
*
|
|
121
|
+
* Used to prevent functions from incorrectly treating a tuple as an array of values.
|
|
112
122
|
*
|
|
113
|
-
* @param input
|
|
123
|
+
* @param input - The tuple or array of tuples to wrap
|
|
124
|
+
* @returns An array containing the tuple(s)
|
|
125
|
+
* @throws Error if input is not an array
|
|
114
126
|
*/
|
|
115
127
|
export declare function wrapTuples<T>(input: IterableOrValue<T>): T[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Maps each value in an iterable through a function and returns the results as an array.
|
|
3
3
|
*
|
|
4
|
-
* @param values
|
|
5
|
-
* @param fn
|
|
6
|
-
* @returns
|
|
4
|
+
* @param values - The iterable to map over
|
|
5
|
+
* @param fn - The mapping function to apply to each value
|
|
6
|
+
* @returns An array of mapped results
|
|
7
7
|
*/
|
|
8
8
|
export declare function mapIterable<I, O>(values: Iterable<I>, fn: (value: I) => O): O[];
|
package/src/lib/iterate.d.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback invoked for each value during iteration. May be sync or async.
|
|
3
|
+
*/
|
|
1
4
|
export type IterateFn<T> = (value: T) => void | Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Callback invoked for each page of values during iteration. May be sync or async.
|
|
7
|
+
*/
|
|
2
8
|
export type IteratePageFn<T> = (values: T[]) => void | Promise<void>;
|
|
3
9
|
/**
|
|
4
|
-
*
|
|
10
|
+
* Iterates over each value in the array sequentially, awaiting each callback before proceeding to the next.
|
|
11
|
+
*
|
|
12
|
+
* @param values - Array of values to iterate over.
|
|
13
|
+
* @param useFn - Callback invoked for each value.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* await iterate([1, 2, 3], async (value) => {
|
|
18
|
+
* await processItem(value);
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
5
21
|
*/
|
|
6
22
|
export declare function iterate<T>(values: T[], useFn: IterateFn<T>): Promise<void>;
|
package/src/lib/key.d.ts
CHANGED
|
@@ -34,27 +34,49 @@ export type ReadMultipleKeysFunction<T, K extends PrimativeKey = PrimativeKey> =
|
|
|
34
34
|
*/
|
|
35
35
|
export type ReadKeysFunction<T, K extends PrimativeKey = PrimativeKey> = MapFunction<ArrayOrValue<T>, K[]>;
|
|
36
36
|
/**
|
|
37
|
-
* Creates a
|
|
37
|
+
* Creates a {@link ReadKeysFunction} from a key-reading function. Handles both single and array inputs,
|
|
38
|
+
* filtering out null/undefined keys.
|
|
38
39
|
*
|
|
39
|
-
* @param
|
|
40
|
+
* @param readKey - Function that extracts one or more keys from a value.
|
|
41
|
+
* @returns A function that reads keys from a single value or array of values.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const fn = readKeysFunction<string>((x) => x);
|
|
46
|
+
* fn(['a', 'b', 'c']); // ['a', 'b', 'c']
|
|
47
|
+
* ```
|
|
40
48
|
*/
|
|
41
49
|
export declare function readKeysFunction<T, K extends PrimativeKey = PrimativeKey>(readKey: ReadKeyFunction<T, K> | ReadMultipleKeysFunction<T, K>): ReadKeysFunction<T, K>;
|
|
42
50
|
/**
|
|
43
|
-
* Convenience function
|
|
44
|
-
*
|
|
45
|
-
* @param
|
|
46
|
-
* @
|
|
51
|
+
* Convenience function that reads all keys from an array of values using the provided key-reading function.
|
|
52
|
+
*
|
|
53
|
+
* @param readKey - Function that extracts one or more keys from a value.
|
|
54
|
+
* @param values - Values to read keys from.
|
|
55
|
+
* @returns An array of all extracted keys.
|
|
47
56
|
*/
|
|
48
57
|
export declare function readKeysFrom<T, K extends PrimativeKey = PrimativeKey>(readKey: ReadKeyFunction<T, K> | ReadMultipleKeysFunction<T, K>, values: T[]): K[];
|
|
49
58
|
/**
|
|
50
59
|
* Reads all defined keys from the input objects to a Set.
|
|
51
60
|
*/
|
|
52
61
|
export type ReadKeysSetFunction<T, K extends PrimativeKey = PrimativeKey> = MapFunction<T[], Set<K>>;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a {@link ReadKeysSetFunction} from a key-reading function. Like {@link readKeysFunction} but returns a Set, deduplicating keys.
|
|
64
|
+
*
|
|
65
|
+
* @param readKey - Function that extracts one or more keys from a value.
|
|
66
|
+
* @returns A function that reads keys from values into a Set.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const fn = readKeysSetFunction<string>((x) => x);
|
|
71
|
+
* fn(['a', 'b', 'a']); // Set { 'a', 'b' }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
53
74
|
export declare function readKeysSetFunction<T, K extends PrimativeKey = PrimativeKey>(readKey: ReadKeyFunction<T, K> | ReadMultipleKeysFunction<T, K>): ReadKeysSetFunction<T, K>;
|
|
54
75
|
/**
|
|
55
|
-
* Convenience function
|
|
56
|
-
*
|
|
57
|
-
* @param
|
|
58
|
-
* @
|
|
76
|
+
* Convenience function that reads all keys from an array of values into a Set using the provided key-reading function.
|
|
77
|
+
*
|
|
78
|
+
* @param readKey - Function that extracts one or more keys from a value.
|
|
79
|
+
* @param values - Values to read keys from.
|
|
80
|
+
* @returns A Set of all extracted keys.
|
|
59
81
|
*/
|
|
60
82
|
export declare function readKeysSetFrom<T, K extends PrimativeKey = PrimativeKey>(readKey: ReadKeyFunction<T, K> | ReadMultipleKeysFunction<T, K>, values: T[]): Set<K>;
|
package/src/lib/lifecycle.d.ts
CHANGED
|
@@ -16,7 +16,16 @@ export interface Destroyable {
|
|
|
16
16
|
*/
|
|
17
17
|
export type DestroyFunction = () => void;
|
|
18
18
|
/**
|
|
19
|
-
* Retains a reference to a single destroy function. When
|
|
19
|
+
* Retains a reference to a single destroy function. When a new function is set via {@link setDestroyFunction},
|
|
20
|
+
* the previous one is called first. Useful for managing cleanup of subscriptions or resources that change over time.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const obj = new DestroyFunctionObject();
|
|
25
|
+
* obj.setDestroyFunction(() => console.log('cleanup A'));
|
|
26
|
+
* obj.setDestroyFunction(() => console.log('cleanup B')); // logs 'cleanup A'
|
|
27
|
+
* obj.destroy(); // logs 'cleanup B'
|
|
28
|
+
* ```
|
|
20
29
|
*/
|
|
21
30
|
export declare class DestroyFunctionObject implements Destroyable {
|
|
22
31
|
private _destroy?;
|
package/src/lib/map/map.d.ts
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
import { type ArrayOrValue } from '../array/array';
|
|
2
2
|
import { type Maybe } from '../value/maybe.type';
|
|
3
3
|
/**
|
|
4
|
+
* Combines multiple Maps into a single Map. Later maps override earlier values for the same key.
|
|
4
5
|
*
|
|
5
|
-
* @param maps
|
|
6
|
-
* @returns
|
|
6
|
+
* @param maps - The maps to combine (null/undefined maps are skipped)
|
|
7
|
+
* @returns A new Map containing all entries
|
|
7
8
|
*/
|
|
8
9
|
export declare function combineMaps<K, T>(...maps: Maybe<Map<K, T>>[]): Map<K, T>;
|
|
9
10
|
/**
|
|
10
|
-
* Sets the value
|
|
11
|
+
* Sets the same value for one or more keys in a Map.
|
|
11
12
|
*
|
|
12
|
-
* @param map
|
|
13
|
-
* @param key
|
|
14
|
-
* @param value
|
|
15
|
-
* @returns
|
|
13
|
+
* @param map - The map to set values on
|
|
14
|
+
* @param key - A single key or array of keys to set
|
|
15
|
+
* @param value - The value to set for all keys
|
|
16
|
+
* @returns The modified map
|
|
16
17
|
*/
|
|
17
18
|
export declare function setKeysOnMap<K, T>(map: Map<K, T>, key: ArrayOrValue<K>, value: T): Map<K, T>;
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* Converts a Map to an array of key-value tuples.
|
|
20
21
|
*
|
|
21
|
-
* @param map
|
|
22
|
-
* @returns
|
|
22
|
+
* @param map - The map to convert
|
|
23
|
+
* @returns An array of [key, value] tuples
|
|
23
24
|
*/
|
|
24
25
|
export declare function mapToTuples<K, T>(map: Map<K, T>): [K, T][];
|
|
25
26
|
/**
|
|
26
|
-
* Expands a
|
|
27
|
+
* Expands a Map with array values into individual key/value tuples.
|
|
27
28
|
*
|
|
28
|
-
* @param map
|
|
29
|
-
* @returns
|
|
29
|
+
* @param map - A Map where values are arrays
|
|
30
|
+
* @returns An array of [key, value] tuples, one for each element in each array
|
|
30
31
|
*/
|
|
31
32
|
export declare function expandArrayMapTuples<K, T>(map: Map<K, T[]>): [K, T][];
|
|
32
33
|
/**
|
|
33
|
-
* Expands
|
|
34
|
+
* Expands tuples where values may be arrays into individual key/value tuples.
|
|
34
35
|
*
|
|
35
|
-
* @param values
|
|
36
|
-
* @returns
|
|
36
|
+
* @param values - Array of [key, ArrayOrValue] tuples to expand
|
|
37
|
+
* @returns An array of [key, value] tuples
|
|
37
38
|
*/
|
|
38
39
|
export declare function expandArrayValueTuples<K, T>(values: [K, ArrayOrValue<T>][]): [K, T][];
|
|
@@ -6,10 +6,11 @@ export interface MapKeysIntersectionObject<T> {
|
|
|
6
6
|
[key: string]: ArrayOrValue<T>;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* Builds an array from intersection of
|
|
9
|
+
* Builds an array from the intersection of an object's keys with the provided keys.
|
|
10
|
+
* For each matching key, the associated value (or values) are added to the result array.
|
|
10
11
|
*
|
|
11
|
-
* @param object
|
|
12
|
-
* @param keys
|
|
13
|
-
* @returns
|
|
12
|
+
* @param object - The object mapping keys to values
|
|
13
|
+
* @param keys - The keys to intersect with the object
|
|
14
|
+
* @returns An array of values from the matching keys
|
|
14
15
|
*/
|
|
15
16
|
export declare function mapKeysIntersectionObjectToArray<T>(object: MapKeysIntersectionObject<T>, keys: Iterable<string>): T[];
|
package/src/lib/map/map.key.d.ts
CHANGED
|
@@ -8,33 +8,34 @@ import { type Maybe } from '../value/maybe.type';
|
|
|
8
8
|
*/
|
|
9
9
|
export type KeyValueMapFactory<T, K extends PrimativeKey = PrimativeKey> = (values: T[]) => Map<K, T>;
|
|
10
10
|
/**
|
|
11
|
-
* Creates a KeyValueMapFactory
|
|
11
|
+
* Creates a KeyValueMapFactory that maps values by their key using a ReadKeyFunction.
|
|
12
12
|
*
|
|
13
|
-
* @param read
|
|
14
|
-
* @returns
|
|
13
|
+
* @param read - Function that extracts a key from each value
|
|
14
|
+
* @returns A factory that creates Maps from arrays of values
|
|
15
15
|
*/
|
|
16
16
|
export declare function keyValueMapFactory<T, K extends PrimativeKey = PrimativeKey>(read: ReadKeyFunction<T, K>): KeyValueMapFactory<T, K>;
|
|
17
17
|
/**
|
|
18
18
|
* Reads keys off the input values and places them in a Map using a ReadKeyFunction.
|
|
19
19
|
*
|
|
20
|
-
* @param values
|
|
21
|
-
* @param read
|
|
22
|
-
* @returns
|
|
20
|
+
* @param values - The array of values to map
|
|
21
|
+
* @param read - Function that extracts a key from each value
|
|
22
|
+
* @returns A Map keyed by the extracted keys
|
|
23
23
|
*/
|
|
24
24
|
export declare function readKeysToMap<T, K extends PrimativeKey = PrimativeKey>(values: T[], read: ReadKeyFunction<T, K>): Map<K, T>;
|
|
25
25
|
/**
|
|
26
|
-
* Creates a KeyValueMapFactory
|
|
26
|
+
* Creates a KeyValueMapFactory that maps values by multiple keys using a ReadMultipleKeysFunction.
|
|
27
|
+
* Each value can appear under multiple keys.
|
|
27
28
|
*
|
|
28
|
-
* @param read
|
|
29
|
-
* @returns
|
|
29
|
+
* @param read - Function that extracts multiple keys from each value
|
|
30
|
+
* @returns A factory that creates Maps from arrays of values
|
|
30
31
|
*/
|
|
31
32
|
export declare function multiKeyValueMapFactory<T, K extends PrimativeKey = PrimativeKey>(read: ReadMultipleKeysFunction<T, K>): KeyValueMapFactory<T, K>;
|
|
32
33
|
/**
|
|
33
|
-
* Reads keys off the input values and places them in a Map using a ReadMultipleKeysFunction.
|
|
34
|
+
* Reads multiple keys off the input values and places them in a Map using a ReadMultipleKeysFunction.
|
|
34
35
|
*
|
|
35
|
-
* @param values
|
|
36
|
-
* @param read
|
|
37
|
-
* @returns
|
|
36
|
+
* @param values - The array of values to map
|
|
37
|
+
* @param read - Function that extracts multiple keys from each value
|
|
38
|
+
* @returns A Map keyed by the extracted keys
|
|
38
39
|
*/
|
|
39
40
|
export declare function readMultipleKeysToMap<T, K extends PrimativeKey = PrimativeKey>(values: T[], read: ReadMultipleKeysFunction<T, K>): Map<K, T>;
|
|
40
41
|
/**
|
|
@@ -102,9 +103,9 @@ export interface MultiValueMapBuilder<T, K extends PrimativeKey = PrimativeKey>
|
|
|
102
103
|
get(key: Maybe<K>): T[];
|
|
103
104
|
}
|
|
104
105
|
/**
|
|
105
|
-
* Creates a new MultiValueMapBuilder
|
|
106
|
+
* Creates a new MultiValueMapBuilder for building Maps where each key maps to an array of values.
|
|
106
107
|
*
|
|
107
|
-
* @returns
|
|
108
|
+
* @returns A new MultiValueMapBuilder instance
|
|
108
109
|
*/
|
|
109
110
|
export declare function multiValueMapBuilder<T, K extends PrimativeKey = PrimativeKey>(): MultiValueMapBuilder<T, K>;
|
|
110
111
|
/**
|
package/src/lib/misc/host.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { type Maybe } from '../value/maybe.type';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for joining a host and port into a connection string.
|
|
4
|
+
*/
|
|
2
5
|
export interface JoinHostAndPortConfig {
|
|
3
6
|
readonly host: string;
|
|
4
7
|
readonly port: number | string;
|
|
5
8
|
}
|
|
6
9
|
/**
|
|
7
|
-
* Joins the host and port into a string.
|
|
10
|
+
* Joins the host and port into a "host:port" string.
|
|
8
11
|
*
|
|
9
|
-
* @param config
|
|
10
|
-
* @returns
|
|
12
|
+
* @param config - The host and port configuration, or null/undefined
|
|
13
|
+
* @returns The joined string, or null/undefined if config is null/undefined
|
|
11
14
|
*/
|
|
12
15
|
export declare function joinHostAndPort(config: Maybe<JoinHostAndPortConfig>): Maybe<string>;
|
|
@@ -29,9 +29,13 @@ export interface IdBatchFactoryConfig<T, K extends PrimativeKey = PrimativeKey>
|
|
|
29
29
|
*/
|
|
30
30
|
export type IdBatchFactory<T> = AsyncArrayFactory<T>;
|
|
31
31
|
/**
|
|
32
|
-
* Creates an IdBatchFactory
|
|
32
|
+
* Creates an {@link IdBatchFactory} that generates batches of unique, verified identifiers.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* The factory generates identifiers in batches, filters them for uniqueness, and verifies each batch
|
|
35
|
+
* using the configured verifier. Throws if uniqueness generation fails repeatedly (after 20 attempts).
|
|
36
|
+
*
|
|
37
|
+
* @param config - Configuration with the base factory for generating candidates and the verifier for validating them
|
|
38
|
+
* @returns An async factory function that produces the requested number of valid identifiers
|
|
39
|
+
* @throws Error if the factory cannot produce enough unique values after repeated attempts
|
|
36
40
|
*/
|
|
37
41
|
export declare function idBatchFactory<T, K extends PrimativeKey = PrimativeKey>(config: IdBatchFactoryConfig<T, K>): IdBatchFactory<T>;
|
|
@@ -35,6 +35,21 @@ export interface SequentialIncrementingNumberStringModelIdFactoryConfig {
|
|
|
35
35
|
readonly increaseBy?: number;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Creates a ModelIdFactory that generates sequential incrementing encoded
|
|
38
|
+
* Creates a {@link ModelIdFactory} that generates sequential incrementing encoded string identifiers.
|
|
39
|
+
*
|
|
40
|
+
* Each call to the returned factory produces the next identifier in the sequence, encoded using the configured
|
|
41
|
+
* {@link NumberStringDencoder} (defaults to base-64). Supports starting from a specific index or continuing
|
|
42
|
+
* from a current index, and an optional transform for post-processing (e.g., padding).
|
|
43
|
+
*
|
|
44
|
+
* @param config - Configuration for the starting index, increment step, dencoder, and transform
|
|
45
|
+
* @returns A factory function that returns the next encoded string identifier on each call
|
|
46
|
+
* @throws Error if `increaseBy` is 0
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const factory = sequentialIncrementingNumberStringModelIdFactory({ startAt: 0 });
|
|
51
|
+
* const first = factory(); // encoded representation of 0
|
|
52
|
+
* const second = factory(); // encoded representation of 1
|
|
53
|
+
* ```
|
|
39
54
|
*/
|
|
40
55
|
export declare function sequentialIncrementingNumberStringModelIdFactory(config?: SequentialIncrementingNumberStringModelIdFactoryConfig): ModelIdFactory;
|
|
@@ -15,6 +15,14 @@ export interface ModelMapFunctions<V extends object, D extends object> {
|
|
|
15
15
|
from: ModelMapFromFunction<V, D>;
|
|
16
16
|
to: ModelMapToFunction<V, D>;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates bidirectional map functions (`from` and `to`) from a set of {@link ModelFieldConversions}.
|
|
20
|
+
*
|
|
21
|
+
* The `to` function converts from the model (V) to data (D), while `from` converts back from data (D) to model (V).
|
|
22
|
+
*
|
|
23
|
+
* @param fields - Field conversion definitions for each key in the model
|
|
24
|
+
* @returns Object with `from` and `to` mapping functions
|
|
25
|
+
*/
|
|
18
26
|
export declare function makeModelMapFunctions<V extends object, D extends object>(fields: ModelFieldConversions<V, D>): ModelMapFunctions<V, D>;
|
|
19
27
|
export type ModelConversionFieldTuple<I extends object> = [keyof I, ModelFieldMapFunction<unknown, unknown>];
|
|
20
28
|
export type ModelConversionFieldValuesConfig<I extends object> = ModelConversionFieldTuple<I>[];
|
|
@@ -32,6 +40,14 @@ export interface ModelConversionOptions<I extends object> {
|
|
|
32
40
|
* A model conversion function. Performs a conversion on all non-null values.
|
|
33
41
|
*/
|
|
34
42
|
export type ModelConversionFieldValuesFunction<I extends object, O extends object> = ApplyMapFunctionWithOptions<Maybe<I>, O, ModelConversionOptions<I>>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a conversion function that maps fields from an input object to an output object using per-field conversion functions.
|
|
45
|
+
*
|
|
46
|
+
* Supports optional filtering by field names and skipping undefined values via {@link ModelConversionOptions}.
|
|
47
|
+
*
|
|
48
|
+
* @param fields - Array of `[key, convertFn]` tuples defining how each field is converted
|
|
49
|
+
* @returns A function that converts an input object to an output object
|
|
50
|
+
*/
|
|
35
51
|
export declare function makeModelConversionFieldValuesFunction<I extends object, O extends object>(fields: ModelConversionFieldValuesConfig<I>): ModelConversionFieldValuesFunction<I, O>;
|
|
36
52
|
/**
|
|
37
53
|
* An object map containing a ModelFieldMapFunctions entry for each key (required and optional) from the generic object.
|
|
@@ -45,6 +61,12 @@ export type ModelFieldConversions<V extends object, D extends object> = Required
|
|
|
45
61
|
export type ModelFieldConversionsConfig<V extends object, D extends object> = Required<{
|
|
46
62
|
[K in keyof V]: ModelFieldMapFunctionsConfig<V[K], TypedMappedModelData<V, D>[K]>;
|
|
47
63
|
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Converts a {@link ModelFieldConversionsConfig} (with raw config per field) into resolved {@link ModelFieldConversions} (with compiled map functions per field).
|
|
66
|
+
*
|
|
67
|
+
* @param config - Configuration object with a conversion config for each model field
|
|
68
|
+
* @returns Resolved field conversions with compiled `from` and `to` functions
|
|
69
|
+
*/
|
|
48
70
|
export declare function modelFieldConversions<V extends object, D extends object>(config: ModelFieldConversionsConfig<V, D>): ModelFieldConversions<V, D>;
|
|
49
71
|
export type ModelFieldMapFunctions<I = unknown, O = unknown> = {
|
|
50
72
|
readonly from: ModelFieldMapFromFunction<I, O>;
|
|
@@ -58,6 +80,12 @@ export type ModelFieldMapFunctionsWithDefaultsConfig<I = unknown, O = unknown> =
|
|
|
58
80
|
readonly from: ModelFieldMapFromWithDefaultConfig<I, O>;
|
|
59
81
|
readonly to: ModelFieldMapToWithDefaultConfig<I, O>;
|
|
60
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* Compiles a {@link ModelFieldMapFunctionsConfig} into resolved {@link ModelFieldMapFunctions} with `from` and `to` mapping functions.
|
|
85
|
+
*
|
|
86
|
+
* @param config - Configuration with `from` and `to` field map configs
|
|
87
|
+
* @returns Compiled field map functions
|
|
88
|
+
*/
|
|
61
89
|
export declare function modelFieldMapFunctions<I = unknown, O = unknown>(config: ModelFieldMapFunctionsConfig<I, O>): ModelFieldMapFunctions<I, O>;
|
|
62
90
|
/**
|
|
63
91
|
* ModelFieldMapFunction configuration that can convert a MaybeValue to the target value.
|
|
@@ -91,10 +119,15 @@ export type ModelFieldMapFunction<I = unknown, O = unknown> = MapFunction<Maybe<
|
|
|
91
119
|
export type ModelFieldMapFromFunction<I, O> = ModelFieldMapFunction<O, I>;
|
|
92
120
|
export type ModelFieldMapToFunction<I, O> = ModelFieldMapFunction<I, O>;
|
|
93
121
|
/**
|
|
94
|
-
* Creates a ModelFieldMapFunction.
|
|
122
|
+
* Creates a {@link ModelFieldMapFunction} from a config that handles Maybe input values.
|
|
123
|
+
*
|
|
124
|
+
* The function handles three cases:
|
|
125
|
+
* - Non-null input: uses `convert` to transform the value
|
|
126
|
+
* - Null/undefined input with `convertMaybe`: delegates to that function
|
|
127
|
+
* - Null/undefined input with `default` or `defaultInput`: uses the appropriate fallback
|
|
95
128
|
*
|
|
96
|
-
* @param config
|
|
97
|
-
* @returns
|
|
129
|
+
* @param config - Configuration specifying how to convert values and handle null/undefined
|
|
130
|
+
* @returns A function that maps Maybe input values to output values
|
|
98
131
|
*/
|
|
99
132
|
export declare function modelFieldMapFunction<I, O>(config: ModelFieldMapConfig<I, O>): ModelFieldMapFunction<I, O>;
|
|
100
133
|
export type ModelFieldConversionsConfigRef<T extends object, O extends object> = {
|
|
@@ -105,14 +138,24 @@ export type ModelFieldConversionsRef<T extends object, O extends object> = {
|
|
|
105
138
|
};
|
|
106
139
|
export type ToModelFieldConversionsInput<T extends object, O extends object> = ModelFieldConversionsConfigRef<T, O> | ModelFieldConversionsRef<T, O>;
|
|
107
140
|
/**
|
|
108
|
-
*
|
|
141
|
+
* Resolves a {@link ToModelFieldConversionsInput} to a {@link ModelFieldConversions} value.
|
|
109
142
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
143
|
+
* Accepts either a pre-built `fieldConversions` reference or a `fields` config that will be compiled.
|
|
144
|
+
*
|
|
145
|
+
* @param input - Either a config ref or a pre-built conversions ref
|
|
146
|
+
* @returns Resolved field conversions
|
|
112
147
|
*/
|
|
113
148
|
export declare function toModelFieldConversions<T extends object, O extends object>(input: ToModelFieldConversionsInput<T, O>): Required<{ [K in keyof T]: ModelFieldMapFunctions<T[K], ReplaceType<T, O, any>[K]>; }>;
|
|
114
149
|
export type ModelMapFunctionsRef<T extends object, O extends object> = {
|
|
115
150
|
readonly mapFunctions: ModelMapFunctions<T, O>;
|
|
116
151
|
};
|
|
117
152
|
export type ToModelMapFunctionsInput<T extends object, O extends object> = ToModelFieldConversionsInput<T, O> | ModelMapFunctionsRef<T, O>;
|
|
153
|
+
/**
|
|
154
|
+
* Resolves a {@link ToModelMapFunctionsInput} to {@link ModelMapFunctions}.
|
|
155
|
+
*
|
|
156
|
+
* Accepts a pre-built `mapFunctions` reference, a `fieldConversions` ref, or a `fields` config.
|
|
157
|
+
*
|
|
158
|
+
* @param input - Input that can be resolved to model map functions
|
|
159
|
+
* @returns Bidirectional model map functions
|
|
160
|
+
*/
|
|
118
161
|
export declare function toModelMapFunctions<T extends object, O extends object>(input: ToModelMapFunctionsInput<T, O>): ModelMapFunctions<T, O>;
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { type ModelFieldMapFunctionsConfig } from './model.conversion';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Creates a bidirectional field conversion config that copies values unchanged in both directions.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* When the input is null/undefined, the provided default value is used instead.
|
|
6
|
+
*
|
|
7
|
+
* @param defaultOutput - Default value to use when the source value is null/undefined
|
|
8
|
+
* @returns A {@link ModelFieldMapFunctionsConfig} with identity `from` and `to` conversions
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const nameField = copyField('');
|
|
13
|
+
* // nameField.from.convert('hello') === 'hello'
|
|
14
|
+
* // nameField.to.convert('hello') === 'hello'
|
|
15
|
+
* // When input is undefined, returns ''
|
|
16
|
+
* ```
|
|
7
17
|
*/
|
|
8
18
|
export declare function copyField<T>(defaultOutput: T): ModelFieldMapFunctionsConfig<T, T>;
|
|
@@ -13,4 +13,15 @@ export interface CopyModelFieldConfig<V = unknown> {
|
|
|
13
13
|
* Used for copying one field from one partial object to a target object.
|
|
14
14
|
*/
|
|
15
15
|
export type CopyModelFieldFunction<T> = (from: Partial<T>, target: Partial<T>) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a function that copies a single field from a partial source object to a partial target object.
|
|
18
|
+
*
|
|
19
|
+
* If the field exists on the source, its value (or the configured default if null) is assigned to the target.
|
|
20
|
+
* If the field does not exist on the source but a default is configured, the default is used.
|
|
21
|
+
* Otherwise, the target is left unchanged.
|
|
22
|
+
*
|
|
23
|
+
* @param key - The property key to copy
|
|
24
|
+
* @param inputConfig - Optional config with a default value for the field
|
|
25
|
+
* @returns A function that copies the field from source to target
|
|
26
|
+
*/
|
|
16
27
|
export declare function makeCopyModelFieldFunction<T extends object>(key: keyof T, inputConfig?: Maybe<CopyModelFieldConfig>): CopyModelFieldFunction<T>;
|