@fgv/ts-utils 5.0.2 → 5.1.0-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/README.md +152 -84
- package/dist/index.js +2 -2
- package/dist/packlets/base/messageAggregator.js +6 -6
- package/dist/packlets/base/result.js +39 -39
- package/dist/packlets/base/utils.js +47 -0
- package/dist/packlets/collections/aggregatedResultMap.js +722 -0
- package/dist/packlets/collections/collector.js +9 -9
- package/dist/packlets/collections/collectorValidator.js +4 -4
- package/dist/packlets/collections/converters.js +39 -0
- package/dist/packlets/collections/convertingCollectorValidator.js +3 -3
- package/dist/packlets/collections/convertingResultMap.js +208 -0
- package/dist/packlets/collections/index.js +4 -0
- package/dist/packlets/collections/keyValueConverters.js +1 -4
- package/dist/packlets/collections/readOnlyConvertingResultMap.js +193 -0
- package/dist/packlets/collections/resultMapValidator.js +50 -6
- package/dist/packlets/collections/validatingConvertingResultMap.js +78 -0
- package/dist/packlets/conversion/advancedConverters.js +249 -0
- package/dist/packlets/conversion/baseConverter.js +23 -16
- package/dist/packlets/conversion/basicConverters.js +571 -0
- package/dist/packlets/conversion/converters.js +3 -617
- package/dist/packlets/conversion/defaultingConverter.js +21 -15
- package/dist/packlets/logging/bootLogger.js +122 -0
- package/dist/packlets/logging/index.js +1 -0
- package/dist/packlets/logging/logReporter.js +32 -1
- package/dist/packlets/logging/logger.js +25 -5
- package/dist/packlets/validation/classes.js +1 -0
- package/dist/packlets/validation/compositeId.js +60 -0
- package/dist/packlets/validation/field.js +1 -1
- package/dist/packlets/validation/genericValidator.js +24 -10
- package/dist/packlets/validation/object.js +3 -6
- package/dist/packlets/validation/validators.js +12 -0
- package/dist/ts-utils.d.ts +1633 -200
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -1
- package/lib/packlets/base/mapResults.d.ts +3 -3
- package/lib/packlets/base/messageAggregator.d.ts +6 -6
- package/lib/packlets/base/messageAggregator.js +6 -6
- package/lib/packlets/base/result.d.ts +74 -51
- package/lib/packlets/base/result.js +39 -39
- package/lib/packlets/base/utils.d.ts +42 -0
- package/lib/packlets/base/utils.js +52 -0
- package/lib/packlets/collections/aggregatedResultMap.d.ts +433 -0
- package/lib/packlets/collections/aggregatedResultMap.js +728 -0
- package/lib/packlets/collections/collector.d.ts +11 -10
- package/lib/packlets/collections/collector.js +9 -9
- package/lib/packlets/collections/collectorValidator.d.ts +12 -10
- package/lib/packlets/collections/collectorValidator.js +4 -4
- package/lib/packlets/collections/converters.d.ts +18 -0
- package/lib/packlets/collections/converters.js +42 -0
- package/lib/packlets/collections/convertingCollector.d.ts +4 -4
- package/lib/packlets/collections/convertingCollectorValidator.d.ts +10 -7
- package/lib/packlets/collections/convertingCollectorValidator.js +3 -3
- package/lib/packlets/collections/convertingResultMap.d.ts +176 -0
- package/lib/packlets/collections/convertingResultMap.js +213 -0
- package/lib/packlets/collections/index.d.ts +4 -0
- package/lib/packlets/collections/index.js +4 -0
- package/lib/packlets/collections/keyValueConverters.d.ts +1 -4
- package/lib/packlets/collections/keyValueConverters.js +1 -4
- package/lib/packlets/collections/readOnlyConvertingResultMap.d.ts +153 -0
- package/lib/packlets/collections/readOnlyConvertingResultMap.js +197 -0
- package/lib/packlets/collections/readonlyResultMap.d.ts +7 -7
- package/lib/packlets/collections/resultMap.d.ts +108 -2
- package/lib/packlets/collections/resultMapValidator.d.ts +45 -11
- package/lib/packlets/collections/resultMapValidator.js +52 -7
- package/lib/packlets/collections/validatingCollector.d.ts +5 -5
- package/lib/packlets/collections/validatingConvertingCollector.d.ts +3 -3
- package/lib/packlets/collections/validatingConvertingResultMap.d.ts +102 -0
- package/lib/packlets/collections/validatingConvertingResultMap.js +83 -0
- package/lib/packlets/collections/validatingResultMap.d.ts +1 -1
- package/lib/packlets/conversion/advancedConverters.d.ts +170 -0
- package/lib/packlets/conversion/advancedConverters.js +258 -0
- package/lib/packlets/conversion/baseConverter.d.ts +39 -23
- package/lib/packlets/conversion/baseConverter.js +23 -16
- package/lib/packlets/conversion/basicConverters.d.ts +470 -0
- package/lib/packlets/conversion/basicConverters.js +595 -0
- package/lib/packlets/conversion/converter.d.ts +7 -0
- package/lib/packlets/conversion/converters.d.ts +2 -535
- package/lib/packlets/conversion/converters.js +17 -639
- package/lib/packlets/conversion/defaultingConverter.d.ts +20 -16
- package/lib/packlets/conversion/defaultingConverter.js +21 -15
- package/lib/packlets/logging/bootLogger.d.ts +84 -0
- package/lib/packlets/logging/bootLogger.js +126 -0
- package/lib/packlets/logging/index.d.ts +1 -0
- package/lib/packlets/logging/index.js +1 -0
- package/lib/packlets/logging/logReporter.d.ts +18 -3
- package/lib/packlets/logging/logReporter.js +31 -0
- package/lib/packlets/logging/logger.d.ts +39 -6
- package/lib/packlets/logging/logger.js +26 -5
- package/lib/packlets/validation/classes.d.ts +1 -0
- package/lib/packlets/validation/classes.js +3 -1
- package/lib/packlets/validation/compositeId.d.ts +29 -0
- package/lib/packlets/validation/compositeId.js +64 -0
- package/lib/packlets/validation/field.d.ts +1 -1
- package/lib/packlets/validation/field.js +1 -1
- package/lib/packlets/validation/genericValidator.d.ts +15 -11
- package/lib/packlets/validation/genericValidator.js +24 -10
- package/lib/packlets/validation/object.d.ts +3 -6
- package/lib/packlets/validation/object.js +3 -6
- package/lib/packlets/validation/traits.d.ts +3 -3
- package/lib/packlets/validation/validator.d.ts +7 -0
- package/lib/packlets/validation/validators.d.ts +10 -0
- package/lib/packlets/validation/validators.js +13 -0
- package/package.json +14 -14
package/dist/ts-utils.d.ts
CHANGED
|
@@ -1,3 +1,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An aggregated result map that wraps a collection of {@link ValidatingResultMap | ValidatingResultMap} instances,
|
|
3
|
+
* keyed by collection ID. Items are accessed via composite IDs that combine the collection ID
|
|
4
|
+
* and item ID with a delimiter.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare class AggregatedResultMap<TCOMPOSITEID extends string, TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> extends AggregatedResultMapBase<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA> {
|
|
8
|
+
/**
|
|
9
|
+
* Constructs a new {@link AggregatedResultMap | AggregatedResultMap}.
|
|
10
|
+
* @param params -
|
|
11
|
+
*/
|
|
12
|
+
constructor(params: IAggregatedResultMapConstructorParams<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>);
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new {@link AggregatedResultMap | AggregatedResultMap}.
|
|
15
|
+
* @param params - Parameters for constructing the map.
|
|
16
|
+
* @returns `Success` with the new map if successful, `Failure` otherwise.
|
|
17
|
+
*/
|
|
18
|
+
static create<TCOMPOSITEID extends string, TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown>(params: IAggregatedResultMapConstructorParams<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>): Result<AggregatedResultMap<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Base class for an aggregated result map that wraps a collection of {@link ValidatingResultMap} instances,
|
|
23
|
+
* keyed by collection ID. Items are accessed via composite IDs that combine the collection ID
|
|
24
|
+
* and item ID with a delimiter.
|
|
25
|
+
* @remarks Consumers should inherit from this class or use {@link AggregatedResultMap | AggregatedResultMap}
|
|
26
|
+
* for fully generic.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
declare class AggregatedResultMapBase<TCOMPOSITEID extends string, TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> implements IResultMap<TCOMPOSITEID, TITEM>, IReadOnlyValidatingResultMap<TCOMPOSITEID, TITEM> {
|
|
30
|
+
private readonly _childKvConverters;
|
|
31
|
+
private readonly _collections;
|
|
32
|
+
private readonly _collectionKvConverters;
|
|
33
|
+
private readonly _compositeIdValidator;
|
|
34
|
+
private readonly _collectionIdConverter;
|
|
35
|
+
private readonly _itemIdConverter;
|
|
36
|
+
private readonly _itemConverter;
|
|
37
|
+
private readonly _metadataConverter?;
|
|
38
|
+
private readonly _delimiter;
|
|
39
|
+
private readonly _compositeIdConverter;
|
|
40
|
+
private readonly _kvConverters;
|
|
41
|
+
private readonly _validating;
|
|
42
|
+
/**
|
|
43
|
+
* Protected constructor for derived classes.
|
|
44
|
+
* Use the {@link AggregatedResultMap.create | create static method} for safe construction with error handling.
|
|
45
|
+
* @param params - {@link IAggregatedResultMapConstructorParams | Parameters} for constructing the map.
|
|
46
|
+
* @throws If initialization fails (e.g., invalid collections).
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
protected constructor(params: IAggregatedResultMapConstructorParams<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>);
|
|
50
|
+
/**
|
|
51
|
+
* A validator for weakly-typed access to the map.
|
|
52
|
+
*/
|
|
53
|
+
get validating(): IReadOnlyResultMapValidator<TCOMPOSITEID, TITEM>;
|
|
54
|
+
/**
|
|
55
|
+
* The total number of items across all collections.
|
|
56
|
+
*/
|
|
57
|
+
get size(): number;
|
|
58
|
+
/**
|
|
59
|
+
* Gets an item by its composite ID.
|
|
60
|
+
* @param key - The composite ID of the item.
|
|
61
|
+
* @returns `Success` with the item if found, `Failure` otherwise.
|
|
62
|
+
*/
|
|
63
|
+
get(key: TCOMPOSITEID): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
64
|
+
/**
|
|
65
|
+
* Checks if an item exists by its composite ID.
|
|
66
|
+
* @param key - The composite ID of the item.
|
|
67
|
+
* @returns `true` if the item exists, `false` otherwise.
|
|
68
|
+
*/
|
|
69
|
+
has(key: TCOMPOSITEID): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Iterates over all entries in all collections.
|
|
72
|
+
*/
|
|
73
|
+
entries(): IterableIterator<KeyValueEntry<TCOMPOSITEID, TITEM>>;
|
|
74
|
+
/**
|
|
75
|
+
* Iterates over all composite keys.
|
|
76
|
+
*/
|
|
77
|
+
keys(): IterableIterator<TCOMPOSITEID>;
|
|
78
|
+
/**
|
|
79
|
+
* Iterates over all values.
|
|
80
|
+
*/
|
|
81
|
+
values(): IterableIterator<TITEM>;
|
|
82
|
+
/**
|
|
83
|
+
* Calls a callback for each entry.
|
|
84
|
+
* @param cb - The callback to call.
|
|
85
|
+
* @param thisArg - Optional `this` argument for the callback.
|
|
86
|
+
*/
|
|
87
|
+
forEach(cb: ResultMapForEachCb<TCOMPOSITEID, TITEM>, thisArg?: unknown): void;
|
|
88
|
+
/**
|
|
89
|
+
* Gets an iterator over the map entries.
|
|
90
|
+
*/
|
|
91
|
+
[Symbol.iterator](): IterableIterator<KeyValueEntry<TCOMPOSITEID, TITEM>>;
|
|
92
|
+
/**
|
|
93
|
+
* Sets an item by its composite ID. Creates the collection if it doesn't exist and is mutable.
|
|
94
|
+
* @param key - The composite ID of the item.
|
|
95
|
+
* @param value - The value to set.
|
|
96
|
+
* @returns `Success` with the value if set, `Failure` otherwise.
|
|
97
|
+
*/
|
|
98
|
+
set(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
99
|
+
/**
|
|
100
|
+
* Adds an item by its composite ID. Fails if the item already exists.
|
|
101
|
+
* @param key - The composite ID of the item.
|
|
102
|
+
* @param value - The value to add.
|
|
103
|
+
* @returns `Success` with the value if added, `Failure` otherwise.
|
|
104
|
+
*/
|
|
105
|
+
add(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
106
|
+
/**
|
|
107
|
+
* Updates an existing item by its composite ID. Fails if the item doesn't exist.
|
|
108
|
+
* @param key - The composite ID of the item.
|
|
109
|
+
* @param value - The new value.
|
|
110
|
+
* @returns `Success` with the value if updated, `Failure` otherwise.
|
|
111
|
+
*/
|
|
112
|
+
update(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
113
|
+
/**
|
|
114
|
+
* Deletes an item by its composite ID.
|
|
115
|
+
* @param key - The composite ID of the item.
|
|
116
|
+
* @returns `Success` with the deleted value, `Failure` otherwise.
|
|
117
|
+
*/
|
|
118
|
+
delete(key: TCOMPOSITEID): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
119
|
+
/**
|
|
120
|
+
* Gets an existing item or adds a new one.
|
|
121
|
+
* @param key - The composite ID of the item.
|
|
122
|
+
* @param value - The value to add if not found.
|
|
123
|
+
* @returns `Success` with the existing or new value.
|
|
124
|
+
*/
|
|
125
|
+
getOrAdd(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
126
|
+
/**
|
|
127
|
+
* Gets an existing item or adds a new one using a factory.
|
|
128
|
+
* @param key - The composite ID of the item.
|
|
129
|
+
* @param factory - A factory function to create the value if not found. Receives the composite ID.
|
|
130
|
+
* @returns `Success` with the existing or new value.
|
|
131
|
+
*/
|
|
132
|
+
getOrAdd(key: TCOMPOSITEID, factory: ResultMapValueFactory<TCOMPOSITEID, TITEM>): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
133
|
+
/**
|
|
134
|
+
* Clears all items from all mutable collections.
|
|
135
|
+
* Immutable collections are not affected.
|
|
136
|
+
*/
|
|
137
|
+
clear(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Returns a read-only view of this map.
|
|
140
|
+
*/
|
|
141
|
+
toReadOnly(): IReadOnlyResultMap<TCOMPOSITEID, TITEM>;
|
|
142
|
+
/**
|
|
143
|
+
* Composes a collection ID and item ID into a composite ID.
|
|
144
|
+
* @param collectionId - The collection ID.
|
|
145
|
+
* @param itemId - The item ID.
|
|
146
|
+
* @returns `Success` with the composite ID if valid, `Failure` otherwise.
|
|
147
|
+
*/
|
|
148
|
+
composeId(collectionId: TCOLLECTIONID, itemId: TITEMID): Result<TCOMPOSITEID>;
|
|
149
|
+
/**
|
|
150
|
+
* Adds an item using separate collection and item IDs.
|
|
151
|
+
* @param collectionId - The collection ID.
|
|
152
|
+
* @param itemId - The item ID.
|
|
153
|
+
* @param value - The value to add.
|
|
154
|
+
* @returns `Success` with the composite ID if added, `Failure` otherwise.
|
|
155
|
+
*/
|
|
156
|
+
addToCollection(collectionId: TCOLLECTIONID, itemId: TITEMID, value: TITEM): DetailedResult<TCOMPOSITEID, ResultMapResultDetail>;
|
|
157
|
+
/**
|
|
158
|
+
* Sets an item using separate collection and item IDs.
|
|
159
|
+
* @param collectionId - The collection ID.
|
|
160
|
+
* @param itemId - The item ID.
|
|
161
|
+
* @param value - The value to set.
|
|
162
|
+
* @returns `Success` with the composite ID if set, `Failure` otherwise.
|
|
163
|
+
*/
|
|
164
|
+
setInCollection(collectionId: TCOLLECTIONID, itemId: TITEMID, value: TITEM): DetailedResult<TCOMPOSITEID, ResultMapResultDetail>;
|
|
165
|
+
/**
|
|
166
|
+
* Updates an item using separate collection and item IDs.
|
|
167
|
+
* @param collectionId - The collection ID.
|
|
168
|
+
* @param itemId - The item ID.
|
|
169
|
+
* @param value - The new value.
|
|
170
|
+
* @returns `Success` with the composite ID if updated, `Failure` otherwise.
|
|
171
|
+
*/
|
|
172
|
+
updateInCollection(collectionId: TCOLLECTIONID, itemId: TITEMID, value: TITEM): DetailedResult<TCOMPOSITEID, ResultMapResultDetail>;
|
|
173
|
+
/**
|
|
174
|
+
* Deletes an item using separate collection and item IDs.
|
|
175
|
+
* @param collectionId - The collection ID.
|
|
176
|
+
* @param itemId - The item ID.
|
|
177
|
+
* @returns `Success` with the composite ID if deleted, `Failure` otherwise.
|
|
178
|
+
*/
|
|
179
|
+
deleteFromCollection(collectionId: TCOLLECTIONID, itemId: TITEMID): DetailedResult<TCOMPOSITEID, ResultMapResultDetail>;
|
|
180
|
+
/**
|
|
181
|
+
* Provides read-only access to the underlying collections map.
|
|
182
|
+
* Use `collections.has(id)` and `collections.get(id)` to check existence and retrieve collections.
|
|
183
|
+
*/
|
|
184
|
+
get collections(): IReadOnlyValidatingResultMap<TCOLLECTIONID, AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>>;
|
|
185
|
+
/**
|
|
186
|
+
* The number of collections.
|
|
187
|
+
*/
|
|
188
|
+
get collectionCount(): number;
|
|
189
|
+
/**
|
|
190
|
+
* Gets the metadata for a specific collection.
|
|
191
|
+
* @param collectionId - The collection ID.
|
|
192
|
+
* @returns `Success` with the metadata if found, `Failure` otherwise.
|
|
193
|
+
*/
|
|
194
|
+
getCollectionMetadata(collectionId: TCOLLECTIONID): Result<TMETADATA | undefined>;
|
|
195
|
+
/**
|
|
196
|
+
* Sets the metadata for a mutable collection.
|
|
197
|
+
* @param collectionId - The collection ID.
|
|
198
|
+
* @param metadata - The metadata to set.
|
|
199
|
+
* @returns `Success` if set, `Failure` otherwise.
|
|
200
|
+
*/
|
|
201
|
+
setCollectionMetadata(collectionId: TCOLLECTIONID, metadata: TMETADATA): Result<TMETADATA>;
|
|
202
|
+
/**
|
|
203
|
+
* Adds a new collection from a pre-built entry object.
|
|
204
|
+
* @param entry - The collection entry to add (JSON with items/entries, or pre-instantiated).
|
|
205
|
+
* @returns `Success` with the entry if added, `Failure` otherwise.
|
|
206
|
+
*/
|
|
207
|
+
addCollectionEntry(entry: AggregatedResultMapEntryInit<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>): DetailedResult<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, ResultMapResultDetail>;
|
|
208
|
+
/**
|
|
209
|
+
* Adds a new collection with the specified ID and optional initial entries.
|
|
210
|
+
* @param collectionId - The collection ID as a string (will be validated).
|
|
211
|
+
* @param items - Optional initial entries for the collection.
|
|
212
|
+
* @param options - Optional settings (isImmutable defaults to false).
|
|
213
|
+
* @returns `Success` with the validated collection ID if added, `Failure` otherwise.
|
|
214
|
+
*/
|
|
215
|
+
addCollectionWithItems(collectionId: string, items?: Iterable<KeyValueEntry<string, unknown>>, options?: IAddCollectionWithItemsOptions<TMETADATA>): Result<TCOLLECTIONID>;
|
|
216
|
+
/**
|
|
217
|
+
* Deletes a collection from the internal collections map.
|
|
218
|
+
* This is a protected method for use by derived classes that need to implement
|
|
219
|
+
* collection deletion functionality.
|
|
220
|
+
*
|
|
221
|
+
* @param collectionId - The collection ID to delete.
|
|
222
|
+
* @returns `Success` with the deleted entry if found, `Failure` otherwise.
|
|
223
|
+
* @remarks
|
|
224
|
+
* - Does NOT check if the collection is mutable - callers should validate this first.
|
|
225
|
+
* - Use `collections.get(id)` to check if a collection exists and its mutability before calling.
|
|
226
|
+
*/
|
|
227
|
+
protected _deleteCollection(collectionId: TCOLLECTIONID): DetailedResult<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, ResultMapResultDetail>;
|
|
228
|
+
/**
|
|
229
|
+
* Type guard to check if a value is a factory function.
|
|
230
|
+
*/
|
|
231
|
+
private _isFactory;
|
|
232
|
+
private _splitCompositeId;
|
|
233
|
+
private _splitAndLookup;
|
|
234
|
+
private _splitAndLookupMutable;
|
|
235
|
+
/**
|
|
236
|
+
* Gets an existing mutable collection by ID.
|
|
237
|
+
* Returns failure if the collection doesn't exist or is immutable.
|
|
238
|
+
*/
|
|
239
|
+
private _getMutableCollection;
|
|
240
|
+
/**
|
|
241
|
+
* Gets an existing mutable collection or creates a new one.
|
|
242
|
+
*/
|
|
243
|
+
private _getOrCreateMutableCollection;
|
|
244
|
+
/**
|
|
245
|
+
* Constructs a composite id validator using other converters/validators and separator supplied in params.
|
|
246
|
+
* @param params - Constructor params.
|
|
247
|
+
* @returns The composite ID validator.
|
|
248
|
+
*/
|
|
249
|
+
private static _compositeIdValidator;
|
|
250
|
+
/**
|
|
251
|
+
* Converts metadata from source, failing fast if metadata is present but no converter is configured.
|
|
252
|
+
* @param sourceMetadata - The metadata from the source (may be undefined).
|
|
253
|
+
* @param metadataConverter - Optional converter for metadata.
|
|
254
|
+
* @returns Success with converted metadata (or undefined), or Failure if metadata is present but disallowed.
|
|
255
|
+
*/
|
|
256
|
+
private static _convertMetadata;
|
|
257
|
+
/**
|
|
258
|
+
* Extracts metadata from a source object if present.
|
|
259
|
+
*/
|
|
260
|
+
private static _extractSourceMetadata;
|
|
261
|
+
/**
|
|
262
|
+
* Creates a converter for pre-instantiated mutable entries.
|
|
263
|
+
* These are entries that already have a ValidatingResultMap as their items property.
|
|
264
|
+
*/
|
|
265
|
+
private static _instantiatedMutableConverter;
|
|
266
|
+
/**
|
|
267
|
+
* Creates a converter for pre-instantiated read-only entries.
|
|
268
|
+
* These are entries that already have an IReadOnlyValidatingResultMap as their items property.
|
|
269
|
+
*/
|
|
270
|
+
private static _instantiatedReadonlyConverter;
|
|
271
|
+
/**
|
|
272
|
+
* Creates a converter for JSON entries with an entries array.
|
|
273
|
+
* Converts the entries array to a ValidatingResultMap.
|
|
274
|
+
*/
|
|
275
|
+
private static _jsonWithEntriesConverter;
|
|
276
|
+
/**
|
|
277
|
+
* Creates a converter for JSON entries with an items object.
|
|
278
|
+
* Converts the items object to a ValidatingResultMap.
|
|
279
|
+
*/
|
|
280
|
+
private static _jsonWithItemsConverter;
|
|
281
|
+
/**
|
|
282
|
+
* Creates a unified entry converter that handles all entry formats.
|
|
283
|
+
* Tries each format in order: instantiated mutable, instantiated readonly,
|
|
284
|
+
* JSON with entries array, JSON with items object.
|
|
285
|
+
*/
|
|
286
|
+
private static _entryConverter;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* A collection entry in an {@link AggregatedResultMap | aggregated result map}, either mutable or read-only.
|
|
291
|
+
* @public
|
|
292
|
+
*/
|
|
293
|
+
declare type AggregatedResultMapEntry<TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> = IReadonlyAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA> | IMutableAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Any valid input format for an {@link AggregatedResultMap | aggregated result map} collection entry.
|
|
297
|
+
* @public
|
|
298
|
+
*/
|
|
299
|
+
declare type AggregatedResultMapEntryInit<TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> = AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA> | AggregatedResultMapJsonEntry<TCOLLECTIONID>;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* JSON format for an {@link AggregatedResultMap | aggregated result map} collection entry - supports both entries array and items object.
|
|
303
|
+
* @public
|
|
304
|
+
*/
|
|
305
|
+
declare type AggregatedResultMapJsonEntry<TCOLLECTIONID extends string = string> = IAggregatedResultMapJsonEntryWithEntries<TCOLLECTIONID> | IAggregatedResultMapJsonEntryWithItems<TCOLLECTIONID>;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* A validator for weakly-typed access to an {@link AggregatedResultMap | aggregated result map}.
|
|
309
|
+
* @public
|
|
310
|
+
*/
|
|
311
|
+
declare class AggregatedResultMapValidator<TCOMPOSITEID extends string, TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> implements IReadOnlyResultMapValidator<TCOMPOSITEID, TITEM> {
|
|
312
|
+
private readonly _map;
|
|
313
|
+
/**
|
|
314
|
+
* The key-value converters used for validating weakly-typed access.
|
|
315
|
+
*/
|
|
316
|
+
readonly converters: KeyValueConverters<TCOMPOSITEID, TITEM>;
|
|
317
|
+
/**
|
|
318
|
+
* Constructs a new {@link AggregatedResultMapValidator | aggregated result map validator}.
|
|
319
|
+
* @param map - The {@link AggregatedResultMap | aggregated result map} being validated.
|
|
320
|
+
* @param converters - The key-value converters for weakly-typed access.
|
|
321
|
+
*/
|
|
322
|
+
constructor(map: AggregatedResultMap<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, converters: KeyValueConverters<TCOMPOSITEID, TITEM>);
|
|
323
|
+
/** {@inheritDoc Collections.ResultMapValidator.map} */
|
|
324
|
+
get map(): IReadOnlyValidatingResultMap<TCOMPOSITEID, TITEM>;
|
|
325
|
+
/** {@inheritDoc Collections.ResultMapValidator.get} */
|
|
326
|
+
get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
327
|
+
/** {@inheritDoc Collections.ResultMapValidator.has} */
|
|
328
|
+
has(key: string): boolean;
|
|
329
|
+
/** {@inheritDoc Collections.ResultMapValidator.add} */
|
|
330
|
+
add(key: string, value: unknown): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
331
|
+
/** {@inheritDoc Collections.ResultMapValidator.set} */
|
|
332
|
+
set(key: string, value: unknown): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
333
|
+
/** {@inheritDoc Collections.ResultMapValidator.update} */
|
|
334
|
+
update(key: string, value: unknown): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
335
|
+
/** {@inheritDoc Collections.ResultMapValidator.delete} */
|
|
336
|
+
delete(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
337
|
+
}
|
|
338
|
+
|
|
1
339
|
/**
|
|
2
340
|
* Determines if an iterable collection of {@link Result | Result<T>} were all successful.
|
|
3
341
|
* @param results - The collection of {@link Result | Result<T>} to be tested.
|
|
@@ -18,7 +356,7 @@ export declare function allSucceed<T>(results: Iterable<Result<unknown>>, succes
|
|
|
18
356
|
* be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
|
|
19
357
|
* @param converter - {@link Converter | Converter} or {@link Validator | Validator} used to convert each
|
|
20
358
|
* item in the array.
|
|
21
|
-
* @param
|
|
359
|
+
* @param onError - Specifies treatment of unconvertible elements.
|
|
22
360
|
* @returns A {@link Converter | Converter} which returns an array of `<T>`.
|
|
23
361
|
* @public
|
|
24
362
|
*/
|
|
@@ -73,6 +411,15 @@ declare interface ArrayValidatorConstructorParams<T, TC = unknown> extends Valid
|
|
|
73
411
|
validateElement: Validator<T, TC>;
|
|
74
412
|
}
|
|
75
413
|
|
|
414
|
+
/**
|
|
415
|
+
* Helper function to create a {@link Validation.Validator | Validator} from any {@link Conversion.Converter | Converter}
|
|
416
|
+
* or {@link Validation.Validator | Validator}.
|
|
417
|
+
* @param converterOrValidator - the {@link Conversion.Converter | Converter} to be wrappped or {@link Validation.Validator | Validator} to be used directly.
|
|
418
|
+
* @returns A {@link Validation.Validator | Validator} which uses the supplied converter or validator.
|
|
419
|
+
* @public
|
|
420
|
+
*/
|
|
421
|
+
declare function asValidator<T, TC = unknown>(converterOrValidator: Converter<T, TC> | Validator<T, TC>): Validator<T, TC>;
|
|
422
|
+
|
|
76
423
|
declare namespace Base {
|
|
77
424
|
export {
|
|
78
425
|
GenericValidatorConstructorParams,
|
|
@@ -107,71 +454,72 @@ declare class BaseConverter<T, TC = unknown> implements Converter<T, TC> {
|
|
|
107
454
|
*/
|
|
108
455
|
constructor(converter: ConverterFunc<T, TC>, defaultContext?: TC, traits?: ConverterTraits);
|
|
109
456
|
/**
|
|
110
|
-
* {@
|
|
457
|
+
* {@inheritDoc Converter.isOptional}
|
|
111
458
|
*/
|
|
112
459
|
get isOptional(): boolean;
|
|
113
460
|
/**
|
|
114
|
-
* {@
|
|
461
|
+
* {@inheritDoc Converter.brand}
|
|
115
462
|
*/
|
|
116
463
|
get brand(): string | undefined;
|
|
117
464
|
/**
|
|
118
|
-
* {@
|
|
465
|
+
* {@inheritDoc Converter.convert}
|
|
119
466
|
*/
|
|
120
467
|
convert(from: unknown, context?: TC): Result<T>;
|
|
121
468
|
/**
|
|
122
|
-
* {@
|
|
469
|
+
* {@inheritDoc Converter.convertOptional}
|
|
123
470
|
*/
|
|
124
471
|
convertOptional(from: unknown, context?: TC, onError?: OnError): Result<T | undefined>;
|
|
125
472
|
/**
|
|
126
|
-
* {@
|
|
473
|
+
* {@inheritDoc Converter.optional}
|
|
127
474
|
*/
|
|
128
475
|
optional(onError?: OnError): Converter<T | undefined, TC>;
|
|
129
476
|
/**
|
|
130
|
-
* {@
|
|
477
|
+
* {@inheritDoc Converter.map}
|
|
131
478
|
*/
|
|
132
479
|
map<T2>(mapper: (from: T, context?: TC) => Result<T2>): Converter<T2, TC>;
|
|
133
480
|
/**
|
|
134
|
-
* {@
|
|
481
|
+
* {@inheritDoc Converter.mapConvert}
|
|
135
482
|
*/
|
|
136
483
|
mapConvert<T2>(mapConverter: Converter<T2>): Converter<T2, TC>;
|
|
137
484
|
/**
|
|
138
|
-
* {@
|
|
485
|
+
* {@inheritDoc Converter.mapItems}
|
|
139
486
|
*/
|
|
140
487
|
mapItems<TI>(mapper: (from: unknown, context?: TC) => Result<TI>): Converter<TI[], TC>;
|
|
141
488
|
/**
|
|
142
|
-
* {@
|
|
489
|
+
* {@inheritDoc Converter.mapConvertItems}
|
|
143
490
|
*/
|
|
144
491
|
mapConvertItems<TI>(mapConverter: Converter<TI, unknown>): Converter<TI[], TC>;
|
|
145
492
|
/**
|
|
146
|
-
* {@
|
|
493
|
+
* {@inheritDoc Converter.withAction}
|
|
147
494
|
*/
|
|
148
495
|
withAction<TI>(action: (result: Result<T>, context?: TC) => Result<TI>): Converter<TI, TC>;
|
|
149
496
|
/**
|
|
150
|
-
* {@
|
|
497
|
+
* {@inheritDoc Converter.withTypeGuard}
|
|
151
498
|
*/
|
|
152
499
|
withTypeGuard<TI>(guard: (from: unknown, context?: TC) => from is TI, message?: string): Converter<TI, TC>;
|
|
153
500
|
/**
|
|
154
|
-
* {@
|
|
501
|
+
* {@inheritDoc Converter.withItemTypeGuard}
|
|
155
502
|
*/
|
|
156
503
|
withItemTypeGuard<TI>(guard: (from: unknown, context?: TC) => from is TI, message?: string): Converter<TI[], TC>;
|
|
157
504
|
/**
|
|
158
|
-
* {@
|
|
505
|
+
* {@inheritDoc Converter.withConstraint}
|
|
159
506
|
*/
|
|
160
507
|
withConstraint(constraint: (val: T, context?: TC) => boolean | Result<T>, options?: ConstraintOptions): Converter<T, TC>;
|
|
161
508
|
/**
|
|
162
|
-
* {@
|
|
509
|
+
* {@inheritDoc Converter.withBrand}
|
|
163
510
|
*/
|
|
164
511
|
withBrand<B extends string>(brand: B): Converter<Brand<T, B>, TC>;
|
|
165
512
|
/**
|
|
166
|
-
* {@
|
|
513
|
+
* {@inheritDoc Converter.withDefault}
|
|
167
514
|
*/
|
|
168
515
|
withDefault<TD = T>(defaultValue: TD): DefaultingConverter<T, TD, TC>;
|
|
516
|
+
or(other: Converter<T, TC>): Converter<T, TC>;
|
|
169
517
|
/**
|
|
170
518
|
* @internal
|
|
171
519
|
*/
|
|
172
520
|
protected _context(supplied?: TC): TC | undefined;
|
|
173
521
|
/**
|
|
174
|
-
* {@
|
|
522
|
+
* {@inheritDoc Converter.withFormattedError}
|
|
175
523
|
*/
|
|
176
524
|
withFormattedError(formatter: ConversionErrorFormatter<TC>): Converter<T, TC>;
|
|
177
525
|
/**
|
|
@@ -225,6 +573,88 @@ declare class BooleanValidator<TC = unknown> extends GenericValidator<boolean, T
|
|
|
225
573
|
*/
|
|
226
574
|
declare type BooleanValidatorConstructorParams<TC = unknown> = GenericValidatorConstructorParams<boolean, TC>;
|
|
227
575
|
|
|
576
|
+
/**
|
|
577
|
+
* A logger that buffers log entries during startup, then replays them
|
|
578
|
+
* to a real logger once it becomes available.
|
|
579
|
+
*
|
|
580
|
+
* @remarks
|
|
581
|
+
* During application bootstrap, the real logger (e.g. one backed by
|
|
582
|
+
* toast notifications) may not be available yet. `BootLogger` solves
|
|
583
|
+
* this by:
|
|
584
|
+
* 1. Buffering all log calls in memory during the boot phase.
|
|
585
|
+
* 2. When {@link BootLogger.ready | ready()} is called with the real
|
|
586
|
+
* logger, replaying all buffered entries and then forwarding all
|
|
587
|
+
* subsequent calls directly.
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
* ```typescript
|
|
591
|
+
* // Create early, before the real logger exists
|
|
592
|
+
* const bootLogger = new BootLogger('detail');
|
|
593
|
+
* bootLogger.info('Starting up...');
|
|
594
|
+
*
|
|
595
|
+
* // Later, when the real logger is available
|
|
596
|
+
* bootLogger.ready(realLogger);
|
|
597
|
+
* // 'Starting up...' is replayed to realLogger
|
|
598
|
+
* // All future calls go directly to realLogger
|
|
599
|
+
* ```
|
|
600
|
+
*
|
|
601
|
+
* @public
|
|
602
|
+
*/
|
|
603
|
+
declare class BootLogger implements IDetailLogger {
|
|
604
|
+
private _buffer;
|
|
605
|
+
private _delegate;
|
|
606
|
+
private _isReady;
|
|
607
|
+
/**
|
|
608
|
+
* Creates a new boot logger.
|
|
609
|
+
* @param logLevel - The log level for the initial in-memory buffer phase.
|
|
610
|
+
* Defaults to 'detail' to capture everything during boot.
|
|
611
|
+
*/
|
|
612
|
+
constructor(logLevel?: ReporterLogLevel);
|
|
613
|
+
/**
|
|
614
|
+
* {@inheritDoc Logging.ILogger.logLevel}
|
|
615
|
+
*/
|
|
616
|
+
get logLevel(): ReporterLogLevel;
|
|
617
|
+
/**
|
|
618
|
+
* Whether the boot logger has been connected to a real logger.
|
|
619
|
+
*/
|
|
620
|
+
get isReady(): boolean;
|
|
621
|
+
/**
|
|
622
|
+
* Connects this boot logger to a real logger.
|
|
623
|
+
* All buffered entries are replayed to the new logger in order,
|
|
624
|
+
* and all subsequent calls are forwarded directly.
|
|
625
|
+
* @param logger - The real logger to forward to.
|
|
626
|
+
*/
|
|
627
|
+
ready(logger: ILogger): void;
|
|
628
|
+
/**
|
|
629
|
+
* {@inheritDoc Logging.ILogger.log}
|
|
630
|
+
*/
|
|
631
|
+
log(level: MessageLogLevel, message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
632
|
+
/**
|
|
633
|
+
* {@inheritDoc Logging.ILogger.detail}
|
|
634
|
+
*/
|
|
635
|
+
detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
636
|
+
/**
|
|
637
|
+
* {@inheritDoc Logging.ILogger.info}
|
|
638
|
+
*/
|
|
639
|
+
info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
640
|
+
/**
|
|
641
|
+
* {@inheritDoc Logging.ILogger.warn}
|
|
642
|
+
*/
|
|
643
|
+
warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
644
|
+
/**
|
|
645
|
+
* {@inheritDoc Logging.ILogger.error}
|
|
646
|
+
*/
|
|
647
|
+
error(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
648
|
+
/**
|
|
649
|
+
* {@inheritDoc Logging.IDetailLogger.errorWithDetail}
|
|
650
|
+
*/
|
|
651
|
+
errorWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
652
|
+
/**
|
|
653
|
+
* {@inheritDoc Logging.IDetailLogger.warnWithDetail}
|
|
654
|
+
*/
|
|
655
|
+
warnWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
656
|
+
}
|
|
657
|
+
|
|
228
658
|
/**
|
|
229
659
|
* Helper type to brand a simple type to prevent inappropriate use
|
|
230
660
|
* @public
|
|
@@ -233,6 +663,121 @@ export declare type Brand<T, B> = T & {
|
|
|
233
663
|
__brand: B;
|
|
234
664
|
};
|
|
235
665
|
|
|
666
|
+
/**
|
|
667
|
+
* A wrapper around a mutable result map that invalidates cache entries
|
|
668
|
+
* in the parent {@link Collections.ConvertingResultMap | ConvertingResultMap} when mutations occur.
|
|
669
|
+
* @public
|
|
670
|
+
*/
|
|
671
|
+
declare class CacheInvalidatingResultMapWrapper<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>> implements IResultMap<TK, TSRC> {
|
|
672
|
+
private readonly _inner;
|
|
673
|
+
private readonly _parent;
|
|
674
|
+
/**
|
|
675
|
+
* Constructs a new cache-invalidating wrapper.
|
|
676
|
+
* @param inner - The inner map to wrap.
|
|
677
|
+
* @param parent - The parent converting map whose cache should be invalidated.
|
|
678
|
+
*/
|
|
679
|
+
constructor(inner: TSRCMAP, parent: ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>);
|
|
680
|
+
/**
|
|
681
|
+
* The number of entries in the map.
|
|
682
|
+
*/
|
|
683
|
+
get size(): number;
|
|
684
|
+
/**
|
|
685
|
+
* Adds a key/value pair to the map if the key does not already exist.
|
|
686
|
+
* Invalidates the cache entry for the key.
|
|
687
|
+
* @param key - The key to add.
|
|
688
|
+
* @param value - The value to add.
|
|
689
|
+
* @returns The result of the add operation.
|
|
690
|
+
*/
|
|
691
|
+
add(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail>;
|
|
692
|
+
/**
|
|
693
|
+
* Sets a key/value pair in the map.
|
|
694
|
+
* Invalidates the cache entry for the key.
|
|
695
|
+
* @param key - The key to set.
|
|
696
|
+
* @param value - The value to set.
|
|
697
|
+
* @returns The result of the set operation.
|
|
698
|
+
*/
|
|
699
|
+
set(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail>;
|
|
700
|
+
/**
|
|
701
|
+
* Updates an existing key in the map.
|
|
702
|
+
* Invalidates the cache entry for the key.
|
|
703
|
+
* @param key - The key to update.
|
|
704
|
+
* @param value - The new value.
|
|
705
|
+
* @returns The result of the update operation.
|
|
706
|
+
*/
|
|
707
|
+
update(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail>;
|
|
708
|
+
/**
|
|
709
|
+
* Deletes a key from the map.
|
|
710
|
+
* Invalidates the cache entry for the key.
|
|
711
|
+
* @param key - The key to delete.
|
|
712
|
+
* @returns The result of the delete operation.
|
|
713
|
+
*/
|
|
714
|
+
delete(key: TK): DetailedResult<TSRC, ResultMapResultDetail>;
|
|
715
|
+
/**
|
|
716
|
+
* Gets a value from the map.
|
|
717
|
+
* @param key - The key to retrieve.
|
|
718
|
+
* @returns The result of the get operation.
|
|
719
|
+
*/
|
|
720
|
+
get(key: TK): DetailedResult<TSRC, ResultMapResultDetail>;
|
|
721
|
+
/**
|
|
722
|
+
* Gets a value from the map, or adds a supplied value if it does not exist.
|
|
723
|
+
* Invalidates the cache entry for the key if a new value is added.
|
|
724
|
+
* @param key - The key to retrieve or add.
|
|
725
|
+
* @param value - The value to add if the key does not exist.
|
|
726
|
+
* @returns The result of the operation.
|
|
727
|
+
*/
|
|
728
|
+
getOrAdd(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail>;
|
|
729
|
+
/**
|
|
730
|
+
* Gets a value from the map, or adds a value created by a factory if it does not exist.
|
|
731
|
+
* Invalidates the cache entry for the key if a new value is added.
|
|
732
|
+
* @param key - The key to retrieve or add.
|
|
733
|
+
* @param factory - A factory function to create the value if the key does not exist.
|
|
734
|
+
* @returns The result of the operation.
|
|
735
|
+
*/
|
|
736
|
+
getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TSRC>): DetailedResult<TSRC, ResultMapResultDetail>;
|
|
737
|
+
/**
|
|
738
|
+
* Checks if the map contains a key.
|
|
739
|
+
* @param key - The key to check.
|
|
740
|
+
* @returns `true` if the key exists, `false` otherwise.
|
|
741
|
+
*/
|
|
742
|
+
has(key: TK): boolean;
|
|
743
|
+
/**
|
|
744
|
+
* Clears all entries from the map.
|
|
745
|
+
* Clears the entire cache.
|
|
746
|
+
*/
|
|
747
|
+
clear(): void;
|
|
748
|
+
/**
|
|
749
|
+
* Returns an iterator over the map entries.
|
|
750
|
+
* @returns An iterator over the map entries.
|
|
751
|
+
*/
|
|
752
|
+
entries(): IterableIterator<KeyValueEntry<TK, TSRC>>;
|
|
753
|
+
/**
|
|
754
|
+
* Returns an iterator over the map keys.
|
|
755
|
+
* @returns An iterator over the map keys.
|
|
756
|
+
*/
|
|
757
|
+
keys(): IterableIterator<TK>;
|
|
758
|
+
/**
|
|
759
|
+
* Returns an iterator over the map values.
|
|
760
|
+
* @returns An iterator over the map values.
|
|
761
|
+
*/
|
|
762
|
+
values(): IterableIterator<TSRC>;
|
|
763
|
+
/**
|
|
764
|
+
* Calls a callback for each entry in the map.
|
|
765
|
+
* @param cb - The callback to call for each entry.
|
|
766
|
+
* @param thisArg - Optional `this` argument for the callback.
|
|
767
|
+
*/
|
|
768
|
+
forEach(cb: ResultMapForEachCb<TK, TSRC>, thisArg?: unknown): void;
|
|
769
|
+
/**
|
|
770
|
+
* Gets an iterator over the map entries.
|
|
771
|
+
* @returns An iterator over the map entries.
|
|
772
|
+
*/
|
|
773
|
+
[Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TSRC>>;
|
|
774
|
+
/**
|
|
775
|
+
* Gets a read-only version of this map.
|
|
776
|
+
* @returns A read-only version of this map.
|
|
777
|
+
*/
|
|
778
|
+
toReadOnly(): IReadOnlyResultMap<TK, TSRC>;
|
|
779
|
+
}
|
|
780
|
+
|
|
236
781
|
/**
|
|
237
782
|
* Wraps a function which might throw to convert exception results
|
|
238
783
|
* to {@link Failure}.
|
|
@@ -250,6 +795,8 @@ declare namespace Classes {
|
|
|
250
795
|
ArrayValidatorConstructorParams,
|
|
251
796
|
BooleanValidator,
|
|
252
797
|
BooleanValidatorConstructorParams,
|
|
798
|
+
CompositeIdValidator,
|
|
799
|
+
CompositeIdValidatorConstructorParams,
|
|
253
800
|
NumberValidator,
|
|
254
801
|
NumberValidatorConstructorParams,
|
|
255
802
|
FieldValidators,
|
|
@@ -369,6 +916,9 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
369
916
|
Collectible,
|
|
370
917
|
IConvertingCollectorConstructorParams,
|
|
371
918
|
ConvertingCollector,
|
|
919
|
+
IConvertingResultMapConstructorParams,
|
|
920
|
+
CacheInvalidatingResultMapWrapper,
|
|
921
|
+
ConvertingResultMap,
|
|
372
922
|
CollectorResultDetail,
|
|
373
923
|
IReadOnlyCollector,
|
|
374
924
|
ICollectorConstructorParams,
|
|
@@ -386,18 +936,40 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
386
936
|
ResultMapResultDetail,
|
|
387
937
|
ResultMapForEachCb,
|
|
388
938
|
IReadOnlyResultMap,
|
|
939
|
+
ConvertingResultMapValueConverter,
|
|
940
|
+
ConversionErrorHandling,
|
|
941
|
+
IReadOnlyConvertingResultMapConstructorParams,
|
|
942
|
+
ReadOnlyConvertingResultMap,
|
|
389
943
|
IResultMapConstructorParams,
|
|
390
944
|
ResultMapValueFactory,
|
|
945
|
+
IResultMap,
|
|
391
946
|
ResultMap,
|
|
392
947
|
IReadOnlyResultMapValidator,
|
|
393
948
|
IResultMapValidatorCreateParams,
|
|
949
|
+
ReadOnlyResultMapValidator,
|
|
394
950
|
ResultMapValidator,
|
|
395
951
|
IReadOnlyValidatingCollector,
|
|
396
952
|
IValidatingCollectorConstructorParams,
|
|
397
953
|
ValidatingCollector,
|
|
954
|
+
IValidatingReadOnlyConvertingResultMapConstructorParams,
|
|
955
|
+
ValidatingReadOnlyConvertingResultMap,
|
|
956
|
+
IValidatingConvertingResultMapConstructorParams,
|
|
957
|
+
ValidatingConvertingResultMap,
|
|
398
958
|
IReadOnlyValidatingResultMap,
|
|
399
959
|
IValidatingResultMapConstructorParams,
|
|
400
|
-
ValidatingResultMap
|
|
960
|
+
ValidatingResultMap,
|
|
961
|
+
IReadonlyAggregatedResultMapEntry,
|
|
962
|
+
IMutableAggregatedResultMapEntry,
|
|
963
|
+
AggregatedResultMapEntry,
|
|
964
|
+
IAggregatedResultMapJsonEntryWithEntries,
|
|
965
|
+
IAggregatedResultMapJsonEntryWithItems,
|
|
966
|
+
AggregatedResultMapJsonEntry,
|
|
967
|
+
AggregatedResultMapEntryInit,
|
|
968
|
+
IAddCollectionWithItemsOptions,
|
|
969
|
+
IAggregatedResultMapConstructorParams,
|
|
970
|
+
AggregatedResultMapValidator,
|
|
971
|
+
AggregatedResultMapBase,
|
|
972
|
+
AggregatedResultMap
|
|
401
973
|
}
|
|
402
974
|
}
|
|
403
975
|
export { Collections }
|
|
@@ -415,7 +987,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
415
987
|
private readonly _byKey;
|
|
416
988
|
private readonly _byIndex;
|
|
417
989
|
/**
|
|
418
|
-
* {@
|
|
990
|
+
* {@inheritDoc Collections.ResultMap.size}
|
|
419
991
|
*/
|
|
420
992
|
get size(): number;
|
|
421
993
|
/**
|
|
@@ -442,19 +1014,19 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
442
1014
|
*/
|
|
443
1015
|
add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
|
|
444
1016
|
/**
|
|
445
|
-
* {@
|
|
1017
|
+
* {@inheritDoc Collections.ResultMap.entries}
|
|
446
1018
|
*/
|
|
447
1019
|
entries(): IterableIterator<KeyValueEntry<CollectibleKey<TITEM>, TITEM>>;
|
|
448
1020
|
/**
|
|
449
|
-
* {@
|
|
1021
|
+
* {@inheritDoc Collections.ResultMap.forEach}
|
|
450
1022
|
*/
|
|
451
1023
|
forEach(callback: ResultMapForEachCb<CollectibleKey<TITEM>, TITEM>, arg?: unknown): void;
|
|
452
1024
|
/**
|
|
453
|
-
* {@
|
|
1025
|
+
* {@inheritDoc Collections.ResultMap.get}
|
|
454
1026
|
*/
|
|
455
1027
|
get(key: CollectibleKey<TITEM>): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
456
1028
|
/**
|
|
457
|
-
* {@
|
|
1029
|
+
* {@inheritDoc Collections.IReadOnlyCollector.getAt}
|
|
458
1030
|
*/
|
|
459
1031
|
getAt(index: number): Result<TITEM>;
|
|
460
1032
|
/**
|
|
@@ -471,7 +1043,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
471
1043
|
* Gets an existing item with a key matching the supplied key, or adds a new item to the collector
|
|
472
1044
|
* using a factory callback if no item with that key exists.
|
|
473
1045
|
* @param key - The key of the item to add.
|
|
474
|
-
* @param
|
|
1046
|
+
* @param factory - The factory callback to create the item.
|
|
475
1047
|
* @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -
|
|
476
1048
|
* detail `exists` indicates that an existing item return and detail `added` indicates that the
|
|
477
1049
|
* item was added. Returns {@link DetailedFailure | Failure} with an error and appropriate
|
|
@@ -479,19 +1051,19 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
479
1051
|
*/
|
|
480
1052
|
getOrAdd(key: CollectibleKey<TITEM>, factory: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
481
1053
|
/**
|
|
482
|
-
* {@
|
|
1054
|
+
* {@inheritDoc Collections.ResultMap.has}
|
|
483
1055
|
*/
|
|
484
1056
|
has(key: CollectibleKey<TITEM>): boolean;
|
|
485
1057
|
/**
|
|
486
|
-
* {@
|
|
1058
|
+
* {@inheritDoc Collections.ResultMap.keys}
|
|
487
1059
|
*/
|
|
488
1060
|
keys(): IterableIterator<CollectibleKey<TITEM>>;
|
|
489
1061
|
/**
|
|
490
|
-
* {@
|
|
1062
|
+
* {@inheritDoc Collections.ResultMap.values}
|
|
491
1063
|
*/
|
|
492
1064
|
values(): IterableIterator<TITEM>;
|
|
493
1065
|
/**
|
|
494
|
-
* {@
|
|
1066
|
+
* {@inheritDoc Collections.IReadOnlyCollector.valuesByIndex}
|
|
495
1067
|
*/
|
|
496
1068
|
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
497
1069
|
/**
|
|
@@ -527,28 +1099,28 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
527
1099
|
*/
|
|
528
1100
|
constructor(params: ICollectorValidatorCreateParams<TITEM>);
|
|
529
1101
|
/**
|
|
530
|
-
* {@
|
|
1102
|
+
* {@inheritDoc Collections.Collector.add}
|
|
531
1103
|
*/
|
|
532
1104
|
add(item: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
533
1105
|
/**
|
|
534
|
-
* {@
|
|
1106
|
+
* {@inheritDoc Collections.Collector.get}
|
|
535
1107
|
*/
|
|
536
1108
|
get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
537
1109
|
/**
|
|
538
|
-
* {@
|
|
1110
|
+
* {@inheritDoc Collections.Collector.getOrAdd}
|
|
539
1111
|
*/
|
|
540
1112
|
getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
541
1113
|
/**
|
|
542
|
-
* {@
|
|
1114
|
+
* {@inheritDoc Collections.Collector.getOrAdd}
|
|
543
1115
|
* @param item - The item to add to the collector.
|
|
544
1116
|
*/
|
|
545
1117
|
getOrAdd(item: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
546
1118
|
/**
|
|
547
|
-
* {@
|
|
1119
|
+
* {@inheritDoc Collections.ResultMap.has}
|
|
548
1120
|
*/
|
|
549
1121
|
has(key: string): boolean;
|
|
550
1122
|
/**
|
|
551
|
-
* {@
|
|
1123
|
+
* {@inheritDoc Collections.Collector.toReadOnly}
|
|
552
1124
|
*/
|
|
553
1125
|
toReadOnly(): IReadOnlyCollectorValidator<TITEM>;
|
|
554
1126
|
/**
|
|
@@ -563,6 +1135,85 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
563
1135
|
protected _convertValue(value: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
564
1136
|
}
|
|
565
1137
|
|
|
1138
|
+
/**
|
|
1139
|
+
* Creates a {@link Converter | Converter} for a strongly-typed {@link Converters.ICompositeId | CompositeId} from
|
|
1140
|
+
* either a string or an object representation.
|
|
1141
|
+
* @param collectionIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.
|
|
1142
|
+
* @param separator - The separator string.
|
|
1143
|
+
* @param itemIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.
|
|
1144
|
+
* @returns A {@link Converter | Converter} for the strongly-typed {@link Converters.ICompositeId | CompositeId}.
|
|
1145
|
+
* @public
|
|
1146
|
+
*/
|
|
1147
|
+
declare function compositeId<TCOLLECTIONID extends string, TITEMID extends string, TC = unknown>(collectionIdConverter: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>, separator: string, itemIdConverter: Converter<TITEMID, TC> | Validator<TITEMID, TC>): Converter<ICompositeId<TCOLLECTIONID, TITEMID>, TC>;
|
|
1148
|
+
|
|
1149
|
+
/** Helper function to create a {@link Validation.Validator | Validator} which validates a
|
|
1150
|
+
* strongly-typed composite ID.
|
|
1151
|
+
* @param params - {@link Validation.Classes.CompositeIdValidatorConstructorParams | params}
|
|
1152
|
+
* used to construct the validator.
|
|
1153
|
+
* @returns A new {@link Validation.Validator | Validator} which validates the desired
|
|
1154
|
+
* composite ID in place.
|
|
1155
|
+
* @public
|
|
1156
|
+
*/
|
|
1157
|
+
declare function compositeId_2<T extends string = string, TCOLLECTIONID extends string = string, TITEMID extends string = string, TC = unknown>(params: CompositeIdValidatorConstructorParams<T, TCOLLECTIONID, TITEMID, TC>): CompositeIdValidator<T, TCOLLECTIONID, TITEMID, TC>;
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* Creates an {@link ObjectConverter | ObjectConverter} for a strongly-typed {@link Converters.ICompositeId | CompositeId}.
|
|
1161
|
+
* @param collectionIdValidator - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.
|
|
1162
|
+
* @param separator - The separator string.
|
|
1163
|
+
* @param itemIdValidator - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.
|
|
1164
|
+
* @returns An {@link ObjectConverter | ObjectConverter} for the strongly-typed composite ICompositeId.
|
|
1165
|
+
* @public
|
|
1166
|
+
*/
|
|
1167
|
+
declare function compositeIdFromObject<TCOLLECTIONID extends string, TITEMID extends string, TC = unknown>(collectionIdValidator: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>, separator: string, itemIdValidator: Converter<TITEMID, TC> | Validator<TITEMID, TC>): Converter<ICompositeId<TCOLLECTIONID, TITEMID>, TC>;
|
|
1168
|
+
|
|
1169
|
+
/**
|
|
1170
|
+
* Converts a composite ID string into a strongly-typed {@link Converters.ICompositeId | CompositeId}.
|
|
1171
|
+
* @param collectionIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.
|
|
1172
|
+
* @param separator - The separator string.
|
|
1173
|
+
* @param itemIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.
|
|
1174
|
+
* @returns A {@link Converter | Converter} for the strongly-typed {@link Converters.ICompositeId | CompositeId}.
|
|
1175
|
+
* @public
|
|
1176
|
+
*/
|
|
1177
|
+
declare function compositeIdFromString<TCOLLECTIONID extends string, TITEMID extends string, TC = unknown>(collectionIdConverter: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>, separator: string, itemIdConverter: Converter<TITEMID, TC> | Validator<TITEMID, TC>): Converter<ICompositeId<TCOLLECTIONID, TITEMID>, TC>;
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* Converts a strongly-typed {@link Converters.ICompositeId | CompositeId} into a string.
|
|
1181
|
+
* @param compositeIdConverter - {@link Converter | Converter} or {@link Validator | Validator} that validates/converts the composite ID string.
|
|
1182
|
+
* @param collectionIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.
|
|
1183
|
+
* @param separator - The separator string.
|
|
1184
|
+
* @param itemIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.
|
|
1185
|
+
* @returns A {@link Converter | Converter} which produces a composite ID string.
|
|
1186
|
+
* @public
|
|
1187
|
+
*/
|
|
1188
|
+
declare function compositeIdString<T extends string, TCOLLECTIONID extends string, TITEMID extends string, TC = unknown>(compositeIdConverter: Validator<T, TC> | Converter<T, TC>, collectionIdConverter: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>, separator: string, itemIdConverter: Converter<TITEMID, TC> | Validator<TITEMID, TC>): Converter<T, TC>;
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* An in-place {@link Validation.Validator | Validator} for a strongly-typed composite ID.
|
|
1192
|
+
* @public
|
|
1193
|
+
*/
|
|
1194
|
+
declare class CompositeIdValidator<T extends string = string, TCOLLECTIONID extends string = string, TITEMID extends string = string, TC = unknown> extends ValidatorBase<T, TC> {
|
|
1195
|
+
protected readonly _collectionIdValidator: Validator<TCOLLECTIONID, TC>;
|
|
1196
|
+
protected readonly _itemIdValidator: Validator<TITEMID, TC>;
|
|
1197
|
+
protected readonly _separator: string;
|
|
1198
|
+
/**
|
|
1199
|
+
* Constructs a new {@link Validation.Classes.StringValidator | StringValidator}.
|
|
1200
|
+
* @param params - Optional {@link Validation.Classes.StringValidatorConstructorParams | init params}
|
|
1201
|
+
* for the new {@link Validation.Classes.StringValidator | StringValidator}.
|
|
1202
|
+
*/
|
|
1203
|
+
constructor(params: CompositeIdValidatorConstructorParams<T, TCOLLECTIONID, TITEMID, TC>);
|
|
1204
|
+
protected _validate(value: unknown, context?: TC): boolean | Failure<T>;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
* Parameters used to construct a {@link Validation.Classes.StringValidator | StringValidator}.
|
|
1209
|
+
* @public
|
|
1210
|
+
*/
|
|
1211
|
+
declare interface CompositeIdValidatorConstructorParams<T extends string = string, TCOLLECTIONID extends string = string, TITEMID extends string = string, TC = unknown> extends ValidatorBaseConstructorParams<T, TC> {
|
|
1212
|
+
readonly collectionId: Validator<TCOLLECTIONID, TC>;
|
|
1213
|
+
readonly separator: string;
|
|
1214
|
+
readonly itemId: Validator<TITEMID, TC>;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
566
1217
|
/**
|
|
567
1218
|
* A console logger that outputs messages to the console.
|
|
568
1219
|
* @public
|
|
@@ -612,6 +1263,8 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
612
1263
|
Converters,
|
|
613
1264
|
Infer,
|
|
614
1265
|
ConvertedToType,
|
|
1266
|
+
ConverterResultType,
|
|
1267
|
+
ConverterResultTypes,
|
|
615
1268
|
ConverterFunc,
|
|
616
1269
|
BaseConverter,
|
|
617
1270
|
OnError,
|
|
@@ -641,9 +1294,19 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
641
1294
|
declare type ConversionErrorFormatter<TC = unknown> = (val: unknown, message?: string, context?: TC) => string;
|
|
642
1295
|
|
|
643
1296
|
/**
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
1297
|
+
* Error handling behavior for conversion failures during iteration.
|
|
1298
|
+
* - `'ignore'`: Silently skip failed conversions (default behavior)
|
|
1299
|
+
* - `'warn'`: Log warning and skip failed conversions
|
|
1300
|
+
* - `'fail'`: Throw error on first conversion failure
|
|
1301
|
+
* @public
|
|
1302
|
+
*/
|
|
1303
|
+
declare type ConversionErrorHandling = 'ignore' | 'warn' | 'fail';
|
|
1304
|
+
|
|
1305
|
+
/**
|
|
1306
|
+
* Deprecated name for {@link Conversion.Infer | Infer
|
|
1307
|
+
* } retained for compatibility.
|
|
1308
|
+
* @deprecated Use {@link Conversion.Infer | Infer} instead.
|
|
1309
|
+
* @public
|
|
647
1310
|
*/
|
|
648
1311
|
declare type ConvertedToType<TCONV> = Infer<TCONV>;
|
|
649
1312
|
|
|
@@ -655,6 +1318,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
655
1318
|
*/
|
|
656
1319
|
export declare interface Converter<T, TC = unknown> extends ConverterTraits {
|
|
657
1320
|
/**
|
|
1321
|
+
*
|
|
658
1322
|
* Indicates whether this element is explicitly optional.
|
|
659
1323
|
*/
|
|
660
1324
|
readonly isOptional: boolean;
|
|
@@ -803,6 +1467,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
803
1467
|
* Returns a Converter which always succeeds with a default value rather than failing.
|
|
804
1468
|
*/
|
|
805
1469
|
withDefault<TD = T>(dflt: TD): DefaultingConverter<T, TD, TC>;
|
|
1470
|
+
/**
|
|
1471
|
+
* Chains this converter with another of the same type, to be attempted if this
|
|
1472
|
+
* converter fails.
|
|
1473
|
+
* @param other -
|
|
1474
|
+
*/
|
|
1475
|
+
or(other: Converter<T, TC>): Converter<T, TC>;
|
|
806
1476
|
}
|
|
807
1477
|
|
|
808
1478
|
/**
|
|
@@ -811,13 +1481,30 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
811
1481
|
*/
|
|
812
1482
|
declare type ConverterFunc<T, TC> = (from: unknown, self: Converter<T, TC>, context?: TC) => Result<T>;
|
|
813
1483
|
|
|
1484
|
+
/**
|
|
1485
|
+
* Helper type to extract the result type from a {@link Converter | Converter}.
|
|
1486
|
+
* For simple single-level extraction. For complex nested types, use {@link Conversion.Infer | Infer}.
|
|
1487
|
+
* @public
|
|
1488
|
+
*/
|
|
1489
|
+
declare type ConverterResultType<C> = C extends Converter<infer T, unknown> ? T : never;
|
|
1490
|
+
|
|
1491
|
+
/**
|
|
1492
|
+
* Helper type to map a tuple of {@link Converter | Converters} to a tuple of their result types.
|
|
1493
|
+
* @public
|
|
1494
|
+
*/
|
|
1495
|
+
declare type ConverterResultTypes<T extends readonly Converter<unknown, unknown>[]> = {
|
|
1496
|
+
[K in keyof T]: T[K] extends Converter<infer R, unknown> ? R : never;
|
|
1497
|
+
};
|
|
1498
|
+
|
|
814
1499
|
declare namespace Converters {
|
|
815
1500
|
export {
|
|
816
1501
|
enumeratedValue,
|
|
817
1502
|
mappedEnumeratedValue,
|
|
818
1503
|
literal,
|
|
819
1504
|
delimitedString,
|
|
1505
|
+
isValidator,
|
|
820
1506
|
validated,
|
|
1507
|
+
asValidator,
|
|
821
1508
|
generic,
|
|
822
1509
|
isA,
|
|
823
1510
|
oneOf,
|
|
@@ -832,8 +1519,6 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
832
1519
|
object,
|
|
833
1520
|
strictObject,
|
|
834
1521
|
discriminatedObject,
|
|
835
|
-
transform,
|
|
836
|
-
transformObject,
|
|
837
1522
|
OnError,
|
|
838
1523
|
string,
|
|
839
1524
|
value,
|
|
@@ -847,6 +1532,15 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
847
1532
|
KeyedConverterOptions,
|
|
848
1533
|
StrictObjectConverterOptions,
|
|
849
1534
|
DiscriminatedObjectConverters,
|
|
1535
|
+
compositeIdFromObject,
|
|
1536
|
+
compositeIdFromString,
|
|
1537
|
+
compositeId,
|
|
1538
|
+
compositeIdString,
|
|
1539
|
+
transform,
|
|
1540
|
+
transformObject,
|
|
1541
|
+
tuple,
|
|
1542
|
+
ICompositeId,
|
|
1543
|
+
IPartialCompositeId,
|
|
850
1544
|
FieldTransformers,
|
|
851
1545
|
TransformObjectOptions
|
|
852
1546
|
}
|
|
@@ -883,7 +1577,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
883
1577
|
*/
|
|
884
1578
|
static createConvertingCollector<TITEM extends ICollectible<any, any>, TSRC = TITEM>(params: IConvertingCollectorConstructorParams<TITEM, TSRC>): Result<ConvertingCollector<TITEM, TSRC>>;
|
|
885
1579
|
/**
|
|
886
|
-
* {@
|
|
1580
|
+
* {@inheritDoc Collections.Collector.add}
|
|
887
1581
|
*/
|
|
888
1582
|
add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
|
|
889
1583
|
/**
|
|
@@ -900,17 +1594,17 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
900
1594
|
* Adds an item to the collector using a supplied {@link Collections.CollectibleFactoryCallback | factory callback}
|
|
901
1595
|
* at a specified key, failing if an item with that key already exists or if the created item is invalid.
|
|
902
1596
|
* @param key - The key of the item to add.
|
|
903
|
-
* @param
|
|
1597
|
+
* @param cb - The factory callback to create the item.
|
|
904
1598
|
* @returns Returns {@link Success | Success} with the item if it is added, or {@link Failure | Failure} with
|
|
905
1599
|
* an error if the item cannot be created and indexed.
|
|
906
1600
|
*/
|
|
907
1601
|
add(key: CollectibleKey<TITEM>, cb: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
908
1602
|
/**
|
|
909
|
-
* {@
|
|
1603
|
+
* {@inheritDoc Collections.Collector.getOrAdd}
|
|
910
1604
|
*/
|
|
911
1605
|
getOrAdd(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
|
|
912
1606
|
/**
|
|
913
|
-
* {@
|
|
1607
|
+
* {@inheritDoc Collections.Collector.getOrAdd}
|
|
914
1608
|
*/
|
|
915
1609
|
getOrAdd(key: CollectibleKey<TITEM>, callback: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
916
1610
|
/**
|
|
@@ -968,31 +1662,32 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
968
1662
|
*/
|
|
969
1663
|
constructor(params: IConvertingCollectorValidatorCreateParams<TITEM, TSRC>);
|
|
970
1664
|
/**
|
|
971
|
-
* {@
|
|
1665
|
+
* {@inheritDoc Collections.ConvertingCollector.add}
|
|
972
1666
|
*/
|
|
973
1667
|
add(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
974
1668
|
/**
|
|
975
|
-
*
|
|
1669
|
+
* Adds an item to the collector using a supplied factory callback
|
|
1670
|
+
* at a specified key, validating the key first.
|
|
976
1671
|
*/
|
|
977
1672
|
add(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
978
1673
|
/**
|
|
979
|
-
* {@
|
|
1674
|
+
* {@inheritDoc Collections.Collector.get}
|
|
980
1675
|
*/
|
|
981
1676
|
get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
982
1677
|
/**
|
|
983
|
-
* {@
|
|
1678
|
+
* {@inheritDoc Collections.ConvertingCollector.getOrAdd}
|
|
984
1679
|
*/
|
|
985
1680
|
getOrAdd(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
986
1681
|
/**
|
|
987
|
-
* {@
|
|
1682
|
+
* {@inheritDoc Collections.Collector.getOrAdd}
|
|
988
1683
|
*/
|
|
989
1684
|
getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
990
1685
|
/**
|
|
991
|
-
* {@
|
|
1686
|
+
* {@inheritDoc Collections.ResultMap.has}
|
|
992
1687
|
*/
|
|
993
1688
|
has(key: string): boolean;
|
|
994
1689
|
/**
|
|
995
|
-
* {@
|
|
1690
|
+
* {@inheritDoc Collections.Collector.toReadOnly}
|
|
996
1691
|
*/
|
|
997
1692
|
toReadOnly(): IReadOnlyCollectorValidator<TITEM>;
|
|
998
1693
|
/**
|
|
@@ -1005,6 +1700,55 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1005
1700
|
protected _isCollectibleFactoryCallback(value: unknown | CollectibleFactoryCallback<TITEM>): value is CollectibleFactoryCallback<TITEM>;
|
|
1006
1701
|
}
|
|
1007
1702
|
|
|
1703
|
+
/**
|
|
1704
|
+
* A result map that wraps an inner {@link Collections.IResultMap | IResultMap} of source type
|
|
1705
|
+
* and returns lazily-converted, cached values of a target type. Exposes the inner map
|
|
1706
|
+
* via a {@link Collections.CacheInvalidatingResultMapWrapper | source} property that
|
|
1707
|
+
* invalidates cache entries when mutations occur.
|
|
1708
|
+
* @public
|
|
1709
|
+
*/
|
|
1710
|
+
declare class ConvertingResultMap<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>> extends ReadOnlyConvertingResultMap<TK, TSRC, TTARGET> {
|
|
1711
|
+
/**
|
|
1712
|
+
* A wrapper around the inner map that invalidates cache entries when mutations occur.
|
|
1713
|
+
* Use this property to add, update, or delete source values.
|
|
1714
|
+
*/
|
|
1715
|
+
readonly source: CacheInvalidatingResultMapWrapper<TK, TSRC, TTARGET, TSRCMAP>;
|
|
1716
|
+
/**
|
|
1717
|
+
* The inner map, typed as the specific source map type.
|
|
1718
|
+
*/
|
|
1719
|
+
protected readonly _typedInner: TSRCMAP;
|
|
1720
|
+
/**
|
|
1721
|
+
* Constructs a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.
|
|
1722
|
+
* @param params - Parameters for constructing the map.
|
|
1723
|
+
*/
|
|
1724
|
+
constructor(params: IConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>);
|
|
1725
|
+
/**
|
|
1726
|
+
* Creates a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.
|
|
1727
|
+
* @param params - Parameters for constructing the map.
|
|
1728
|
+
* @returns `Success` with the new map, or `Failure` with error details if an error occurred.
|
|
1729
|
+
*/
|
|
1730
|
+
static create<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>>(params: IConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>): Result<ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>>;
|
|
1731
|
+
/**
|
|
1732
|
+
* Clears a single entry from the cache.
|
|
1733
|
+
* This method is public to allow the cache-invalidating wrapper to call it.
|
|
1734
|
+
* @param key - The key to clear from the cache.
|
|
1735
|
+
* @internal
|
|
1736
|
+
*/
|
|
1737
|
+
_clearCacheEntry(key: TK): void;
|
|
1738
|
+
/**
|
|
1739
|
+
* Clears all entries from the cache.
|
|
1740
|
+
* This method is public to allow the cache-invalidating wrapper to call it.
|
|
1741
|
+
* @internal
|
|
1742
|
+
*/
|
|
1743
|
+
_clearCache(): void;
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
/**
|
|
1747
|
+
* A function that converts a source value to a target value.
|
|
1748
|
+
* @public
|
|
1749
|
+
*/
|
|
1750
|
+
declare type ConvertingResultMapValueConverter<TK extends string, TSRC, TTARGET> = (src: TSRC, key: TK) => Result<TTARGET>;
|
|
1751
|
+
|
|
1008
1752
|
/**
|
|
1009
1753
|
* A {@link Hash.HashingNormalizer | hashing normalizer} which computes object
|
|
1010
1754
|
* hash using the CRC32 algorithm.
|
|
@@ -1090,7 +1834,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1090
1834
|
* @remarks
|
|
1091
1835
|
* Mutates the success type as the success callback would have, but does not
|
|
1092
1836
|
* call the success callback.
|
|
1093
|
-
* @param
|
|
1837
|
+
* @param __cb - {@link DetailedSuccessContinuation | Success callback} to be called
|
|
1094
1838
|
* on a {@link DetailedResult} in case of success (ignored).
|
|
1095
1839
|
* @returns A new {@link DetailedFailure | DetailedFailure<TN, TD>} which contains
|
|
1096
1840
|
* the error message and detail from this one.
|
|
@@ -1104,15 +1848,15 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1104
1848
|
*/
|
|
1105
1849
|
onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD>;
|
|
1106
1850
|
/**
|
|
1107
|
-
* {@
|
|
1851
|
+
* {@inheritDoc IResult.withErrorFormat}
|
|
1108
1852
|
*/
|
|
1109
1853
|
withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD>;
|
|
1110
1854
|
/**
|
|
1111
|
-
* {@
|
|
1855
|
+
* {@inheritDoc IResult.aggregateError}
|
|
1112
1856
|
*/
|
|
1113
1857
|
aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter<TD>): this;
|
|
1114
1858
|
/**
|
|
1115
|
-
* {@
|
|
1859
|
+
* {@inheritDoc IResult.report}
|
|
1116
1860
|
*/
|
|
1117
1861
|
report(reporter?: IResultReporter<T, unknown>, options?: IResultReportOptions<unknown>): DetailedFailure<T, TD>;
|
|
1118
1862
|
orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never;
|
|
@@ -1144,11 +1888,17 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1144
1888
|
export declare type DetailedFailureContinuation<T, TD> = (message: string, detail?: TD) => DetailedResult<T, TD>;
|
|
1145
1889
|
|
|
1146
1890
|
/**
|
|
1147
|
-
*
|
|
1891
|
+
* Represents a result with additional detail.
|
|
1148
1892
|
* @beta
|
|
1149
1893
|
*/
|
|
1150
1894
|
export declare type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;
|
|
1151
1895
|
|
|
1896
|
+
/**
|
|
1897
|
+
* Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.
|
|
1898
|
+
* @beta
|
|
1899
|
+
*/
|
|
1900
|
+
export declare type DetailedResultValueType<T> = T extends DetailedResult<infer TV, unknown> ? TV : never;
|
|
1901
|
+
|
|
1152
1902
|
/**
|
|
1153
1903
|
* A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success
|
|
1154
1904
|
* details in addition to the error message.
|
|
@@ -1194,17 +1944,17 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1194
1944
|
* Propagates this {@link DetailedSuccess}.
|
|
1195
1945
|
* @remarks
|
|
1196
1946
|
* Failure does not mutate return type so we can return this event directly.
|
|
1197
|
-
* @param
|
|
1947
|
+
* @param __cb - {@link DetailedFailureContinuation | Failure callback} to be called
|
|
1198
1948
|
* on a {@link DetailedResult} in case of failure (ignored).
|
|
1199
1949
|
* @returns `this`
|
|
1200
1950
|
*/
|
|
1201
1951
|
onFailure(__cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD>;
|
|
1202
1952
|
/**
|
|
1203
|
-
* {@
|
|
1953
|
+
* {@inheritDoc Success.withErrorFormat}
|
|
1204
1954
|
*/
|
|
1205
1955
|
withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD>;
|
|
1206
1956
|
/**
|
|
1207
|
-
* {@
|
|
1957
|
+
* {@inheritDoc IResult.report}
|
|
1208
1958
|
*/
|
|
1209
1959
|
report(reporter?: IResultReporter<T, unknown>, options?: IResultReportOptions<unknown>): DetailedSuccess<T, TD>;
|
|
1210
1960
|
/**
|
|
@@ -1264,6 +2014,30 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1264
2014
|
*/
|
|
1265
2015
|
declare function element<T, TC = unknown>(index: number, converter: Converter<T, TC> | Validator<T, TC>): Converter<T, TC>;
|
|
1266
2016
|
|
|
2017
|
+
/**
|
|
2018
|
+
* Ensures the input is an array. If already an array, returns it as-is.
|
|
2019
|
+
* If a single item, wraps it in an array.
|
|
2020
|
+
* Preserves readonly status of input arrays.
|
|
2021
|
+
* @param items - A single item or an array of items.
|
|
2022
|
+
* @returns The input array unchanged, or a new array containing the single item.
|
|
2023
|
+
* @public
|
|
2024
|
+
*/
|
|
2025
|
+
export declare function ensureArray<T>(items: T): EnsureArrayResult<T>;
|
|
2026
|
+
|
|
2027
|
+
/**
|
|
2028
|
+
* Helper type to extract the element type and preserve readonly status.
|
|
2029
|
+
* @public
|
|
2030
|
+
*/
|
|
2031
|
+
export declare type EnsureArrayResult<T> = T extends readonly (infer _U)[] ? T : T[];
|
|
2032
|
+
|
|
2033
|
+
/**
|
|
2034
|
+
* Type-safe(ish) entries extractor for typed records.
|
|
2035
|
+
* @param obj - The record from which entries are to be extracted.
|
|
2036
|
+
* @returns The entries of the record as an array of `[key, value]` tuples.
|
|
2037
|
+
* @public
|
|
2038
|
+
*/
|
|
2039
|
+
export declare function entriesForRecord<TK extends string, TV>(obj: Record<TK, TV>): Array<[TK, TV]>;
|
|
2040
|
+
|
|
1267
2041
|
/**
|
|
1268
2042
|
* @internal
|
|
1269
2043
|
*/
|
|
@@ -1308,13 +2082,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1308
2082
|
export { fail_2 as fail }
|
|
1309
2083
|
|
|
1310
2084
|
/**
|
|
1311
|
-
* {@
|
|
2085
|
+
* {@inheritDoc fail}
|
|
1312
2086
|
* @public
|
|
1313
2087
|
*/
|
|
1314
2088
|
export declare function fails<T>(message: string): Failure<T>;
|
|
1315
2089
|
|
|
1316
2090
|
/**
|
|
1317
|
-
* {@
|
|
2091
|
+
* {@inheritDoc failWithDetail}
|
|
1318
2092
|
* @public
|
|
1319
2093
|
*/
|
|
1320
2094
|
export declare function failsWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD>;
|
|
@@ -1325,7 +2099,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1325
2099
|
*/
|
|
1326
2100
|
export declare class Failure<out T> implements IResult<T> {
|
|
1327
2101
|
/**
|
|
1328
|
-
* {@
|
|
2102
|
+
* {@inheritDoc IResult.success}
|
|
1329
2103
|
*/
|
|
1330
2104
|
readonly success: false;
|
|
1331
2105
|
/**
|
|
@@ -1346,65 +2120,65 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1346
2120
|
*/
|
|
1347
2121
|
get message(): string;
|
|
1348
2122
|
/**
|
|
1349
|
-
* {@
|
|
2123
|
+
* {@inheritDoc IResult.isSuccess}
|
|
1350
2124
|
*/
|
|
1351
2125
|
isSuccess(): this is Success<T>;
|
|
1352
2126
|
/**
|
|
1353
|
-
* {@
|
|
2127
|
+
* {@inheritDoc IResult.isFailure}
|
|
1354
2128
|
*/
|
|
1355
2129
|
isFailure(): this is Failure<T>;
|
|
1356
2130
|
/**
|
|
1357
|
-
* {@
|
|
2131
|
+
* {@inheritDoc IResult.orThrow}
|
|
1358
2132
|
*/
|
|
1359
2133
|
orThrow(logger?: IResultLogger): never;
|
|
1360
2134
|
/**
|
|
1361
|
-
* {@
|
|
2135
|
+
* {@inheritDoc IResult.orThrow}
|
|
1362
2136
|
*/
|
|
1363
2137
|
orThrow(cb: ErrorFormatter): never;
|
|
1364
2138
|
/**
|
|
1365
|
-
* {@
|
|
2139
|
+
* {@inheritDoc IResult.orDefault}
|
|
1366
2140
|
*/
|
|
1367
2141
|
orDefault(dflt: T): T;
|
|
1368
2142
|
/**
|
|
1369
|
-
* {@
|
|
2143
|
+
* {@inheritDoc IResult.orDefault}
|
|
1370
2144
|
*/
|
|
1371
2145
|
orDefault(): T | undefined;
|
|
1372
2146
|
/**
|
|
1373
|
-
* {@
|
|
1374
|
-
* @deprecated Use {@link Failure.
|
|
2147
|
+
* {@inheritDoc IResult.getValueOrThrow}
|
|
2148
|
+
* @deprecated Use {@link Failure.orThrow | orThrow(logger)} or {@link Failure.orThrow | orThrow(formatter)} instead.
|
|
1375
2149
|
*/
|
|
1376
2150
|
getValueOrThrow(logger?: IResultLogger): never;
|
|
1377
2151
|
/**
|
|
1378
|
-
* {@
|
|
1379
|
-
* @deprecated Use {@link Failure.
|
|
2152
|
+
* {@inheritDoc IResult.getValueOrDefault}
|
|
2153
|
+
* @deprecated Use {@link Failure.orDefault | orDefault(T)} or {@link Failure.orDefault | orDefault()} instead.
|
|
1380
2154
|
*/
|
|
1381
2155
|
getValueOrDefault(dflt?: T): T | undefined;
|
|
1382
2156
|
/**
|
|
1383
|
-
* {@
|
|
2157
|
+
* {@inheritDoc IResult.onSuccess}
|
|
1384
2158
|
*/
|
|
1385
2159
|
onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN>;
|
|
1386
2160
|
/**
|
|
1387
|
-
* {@
|
|
2161
|
+
* {@inheritDoc IResult.onFailure}
|
|
1388
2162
|
*/
|
|
1389
2163
|
onFailure(cb: FailureContinuation<T>): Result<T>;
|
|
1390
2164
|
/**
|
|
1391
|
-
* {@
|
|
2165
|
+
* {@inheritDoc IResult.withErrorFormat}
|
|
1392
2166
|
*/
|
|
1393
2167
|
withErrorFormat(cb: ErrorFormatter): Result<T>;
|
|
1394
2168
|
/**
|
|
1395
|
-
* {@
|
|
2169
|
+
* {@inheritDoc IResult.withFailureDetail}
|
|
1396
2170
|
*/
|
|
1397
2171
|
withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;
|
|
1398
2172
|
/**
|
|
1399
|
-
* {@
|
|
2173
|
+
* {@inheritDoc IResult.withDetail}
|
|
1400
2174
|
*/
|
|
1401
2175
|
withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD>;
|
|
1402
2176
|
/**
|
|
1403
|
-
* {@
|
|
2177
|
+
* {@inheritDoc IResult.aggregateError}
|
|
1404
2178
|
*/
|
|
1405
2179
|
aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this;
|
|
1406
2180
|
/**
|
|
1407
|
-
* {@
|
|
2181
|
+
* {@inheritDoc IResult.report}
|
|
1408
2182
|
*/
|
|
1409
2183
|
report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Failure<T>;
|
|
1410
2184
|
/**
|
|
@@ -1467,8 +2241,8 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1467
2241
|
};
|
|
1468
2242
|
|
|
1469
2243
|
/**
|
|
1470
|
-
* String-keyed record of initialization functions to be passed to {@link
|
|
1471
|
-
* or {@link
|
|
2244
|
+
* String-keyed record of initialization functions to be passed to {@link populateObject}
|
|
2245
|
+
* or {@link populateObject}.
|
|
1472
2246
|
* @public
|
|
1473
2247
|
*/
|
|
1474
2248
|
export declare type FieldInitializers<T> = {
|
|
@@ -1551,15 +2325,15 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1551
2325
|
declare class GenericDefaultingConverter<T, TD = T, TC = unknown> implements DefaultingConverter<T, TD, TC> {
|
|
1552
2326
|
private _converter;
|
|
1553
2327
|
/**
|
|
1554
|
-
* {@
|
|
2328
|
+
* {@inheritDoc Conversion.DefaultingConverter.defaultValue}
|
|
1555
2329
|
*/
|
|
1556
2330
|
defaultValue: TD;
|
|
1557
2331
|
/**
|
|
1558
|
-
* {@
|
|
2332
|
+
* {@inheritDoc Converter.isOptional}
|
|
1559
2333
|
*/
|
|
1560
2334
|
get isOptional(): boolean;
|
|
1561
2335
|
/**
|
|
1562
|
-
* {@
|
|
2336
|
+
* {@inheritDoc Converter.isOptional}
|
|
1563
2337
|
*/
|
|
1564
2338
|
get brand(): string | undefined;
|
|
1565
2339
|
/**
|
|
@@ -1569,55 +2343,55 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1569
2343
|
*/
|
|
1570
2344
|
constructor(converter: Converter<T, TC>, defaultValue: TD);
|
|
1571
2345
|
/**
|
|
1572
|
-
* {@
|
|
2346
|
+
* {@inheritDoc Converter.convert}
|
|
1573
2347
|
*/
|
|
1574
2348
|
convert(from: unknown, ctx?: TC | undefined): Success<T | TD>;
|
|
1575
2349
|
/**
|
|
1576
|
-
* {@
|
|
2350
|
+
* {@inheritDoc Converter.convertOptional}
|
|
1577
2351
|
*/
|
|
1578
2352
|
convertOptional(from: unknown, context?: TC | undefined, onError?: ('failOnError' | 'ignoreErrors') | undefined): Result<T | TD | undefined>;
|
|
1579
2353
|
/**
|
|
1580
|
-
* {@
|
|
2354
|
+
* {@inheritDoc Converter.optional}
|
|
1581
2355
|
*/
|
|
1582
2356
|
optional(onError?: ('failOnError' | 'ignoreErrors') | undefined): Converter<T | TD | undefined, TC>;
|
|
1583
2357
|
/**
|
|
1584
|
-
* {@
|
|
2358
|
+
* {@inheritDoc Converter.map}
|
|
1585
2359
|
*/
|
|
1586
2360
|
map<T2>(mapper: (from: T | TD) => Result<T2>): Converter<T2, TC>;
|
|
1587
2361
|
/**
|
|
1588
|
-
* {@
|
|
2362
|
+
* {@inheritDoc Converter.mapConvert}
|
|
1589
2363
|
*/
|
|
1590
2364
|
mapConvert<T2>(mapConverter: Converter<T2, unknown>): Converter<T2, TC>;
|
|
1591
2365
|
/**
|
|
1592
|
-
* {@
|
|
2366
|
+
* {@inheritDoc Converter.mapItems}
|
|
1593
2367
|
*/
|
|
1594
2368
|
mapItems<TI>(mapper: (from: unknown) => Result<TI>): Converter<TI[], TC>;
|
|
1595
2369
|
/**
|
|
1596
|
-
* {@
|
|
2370
|
+
* {@inheritDoc Converter.mapConvertItems}
|
|
1597
2371
|
*/
|
|
1598
2372
|
mapConvertItems<TI>(mapConverter: Converter<TI, unknown>): Converter<TI[], TC>;
|
|
1599
2373
|
/**
|
|
1600
|
-
* {@
|
|
2374
|
+
* {@inheritDoc Converter.withAction}
|
|
1601
2375
|
*/
|
|
1602
2376
|
withAction<T2>(action: (result: Result<T | TD>) => Result<T2>): Converter<T2, TC>;
|
|
1603
2377
|
/**
|
|
1604
|
-
* {@
|
|
2378
|
+
* {@inheritDoc Converter.withTypeGuard}
|
|
1605
2379
|
*/
|
|
1606
2380
|
withTypeGuard<TI>(guard: (from: unknown) => from is TI, message?: string | undefined): Converter<TI, TC>;
|
|
1607
2381
|
/**
|
|
1608
|
-
* {@
|
|
2382
|
+
* {@inheritDoc Converter.withItemTypeGuard}
|
|
1609
2383
|
*/
|
|
1610
2384
|
withItemTypeGuard<TI>(guard: (from: unknown) => from is TI, message?: string | undefined): Converter<TI[], TC>;
|
|
1611
2385
|
/**
|
|
1612
|
-
* {@
|
|
2386
|
+
* {@inheritDoc Converter.withConstraint}
|
|
1613
2387
|
*/
|
|
1614
2388
|
withConstraint(constraint: (val: T | TD) => boolean | Result<T | TD>, options?: ConstraintOptions | undefined): Converter<T | TD, TC>;
|
|
1615
2389
|
/**
|
|
1616
|
-
* {@
|
|
2390
|
+
* {@inheritDoc Converter.withBrand}
|
|
1617
2391
|
*/
|
|
1618
2392
|
withBrand<B extends string>(brand: B): Converter<Brand<T | TD, B>, TC>;
|
|
1619
2393
|
/**
|
|
1620
|
-
* {@
|
|
2394
|
+
* {@inheritDoc Converter.withFormattedError}
|
|
1621
2395
|
*/
|
|
1622
2396
|
withFormattedError(formatter: ConversionErrorFormatter<TC>): Converter<T | TD, TC>;
|
|
1623
2397
|
/**
|
|
@@ -1628,6 +2402,10 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1628
2402
|
* {@link Conversion.DefaultingConverter | DefaultingConverter}.
|
|
1629
2403
|
*/
|
|
1630
2404
|
withDefault<TD2 = T>(dflt: TD2): DefaultingConverter<T, TD2, TC>;
|
|
2405
|
+
/**
|
|
2406
|
+
* {@inheritDoc Converter.or}
|
|
2407
|
+
*/
|
|
2408
|
+
or(__converter: Converter<T, TC>): DefaultingConverter<T, TD, TC>;
|
|
1631
2409
|
private _applyDefault;
|
|
1632
2410
|
}
|
|
1633
2411
|
|
|
@@ -1637,7 +2415,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1637
2415
|
*/
|
|
1638
2416
|
declare class GenericValidator<T, TC = unknown> implements Validator<T, TC> {
|
|
1639
2417
|
/**
|
|
1640
|
-
* {@
|
|
2418
|
+
* {@inheritDoc Validation.Validator.traits}
|
|
1641
2419
|
*/
|
|
1642
2420
|
readonly traits: ValidatorTraits;
|
|
1643
2421
|
/**
|
|
@@ -1655,45 +2433,49 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1655
2433
|
*/
|
|
1656
2434
|
constructor(params: Partial<GenericValidatorConstructorParams<T, TC>>);
|
|
1657
2435
|
/**
|
|
1658
|
-
* {@
|
|
2436
|
+
* {@inheritDoc Validation.Validator.isOptional}
|
|
1659
2437
|
*/
|
|
1660
2438
|
get isOptional(): boolean;
|
|
1661
2439
|
/**
|
|
1662
|
-
* {@
|
|
2440
|
+
* {@inheritDoc Validation.Validator.brand}
|
|
1663
2441
|
*/
|
|
1664
2442
|
get brand(): string | undefined;
|
|
1665
2443
|
/**
|
|
1666
|
-
* {@
|
|
2444
|
+
* {@inheritDoc Validation.Validator.validate}
|
|
1667
2445
|
*/
|
|
1668
2446
|
validate(from: unknown, context?: TC): Result<T>;
|
|
1669
2447
|
/**
|
|
1670
|
-
* {@
|
|
2448
|
+
* {@inheritDoc Validation.Validator.convert}
|
|
1671
2449
|
*/
|
|
1672
2450
|
convert(from: unknown, context?: TC): Result<T>;
|
|
1673
2451
|
/**
|
|
1674
|
-
* {@
|
|
2452
|
+
* {@inheritDoc Validation.Validator.validateOptional}
|
|
1675
2453
|
*/
|
|
1676
2454
|
validateOptional(from: unknown, context?: TC): Result<T | undefined>;
|
|
1677
2455
|
/**
|
|
1678
|
-
* {@
|
|
2456
|
+
* {@inheritDoc Validation.Validator.guard}
|
|
1679
2457
|
*/
|
|
1680
2458
|
guard(from: unknown, context?: TC): from is T;
|
|
1681
2459
|
/**
|
|
1682
|
-
* {@
|
|
2460
|
+
* {@inheritDoc Validation.Validator.optional}
|
|
1683
2461
|
*/
|
|
1684
2462
|
optional(): Validator<T | undefined, TC>;
|
|
1685
2463
|
/**
|
|
1686
|
-
* {@
|
|
2464
|
+
* {@inheritDoc Validation.Validator.withConstraint}
|
|
1687
2465
|
*/
|
|
1688
2466
|
withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;
|
|
1689
2467
|
/**
|
|
1690
|
-
* {@
|
|
2468
|
+
* {@inheritDoc Validation.Validator.brand}
|
|
1691
2469
|
*/
|
|
1692
2470
|
withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;
|
|
1693
2471
|
/**
|
|
1694
|
-
* {@
|
|
2472
|
+
* {@inheritDoc Validation.Validator.withFormattedError}
|
|
1695
2473
|
*/
|
|
1696
2474
|
withFormattedError(formatter: ValidationErrorFormatter<TC>): Validator<T, TC>;
|
|
2475
|
+
/**
|
|
2476
|
+
* {@inheritDoc Validation.Validator.or}
|
|
2477
|
+
*/
|
|
2478
|
+
or(other: Validator<T, TC>): Validator<T, TC>;
|
|
1697
2479
|
/**
|
|
1698
2480
|
* Gets a default or explicit context.
|
|
1699
2481
|
* @param explicitContext - Optional explicit context.
|
|
@@ -1771,6 +2553,81 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1771
2553
|
protected _normalizeLiteralToString(from: string | number | bigint | boolean | symbol | undefined | Date | RegExp | null): Result<string>;
|
|
1772
2554
|
}
|
|
1773
2555
|
|
|
2556
|
+
/**
|
|
2557
|
+
* Options for {@link Collections.AggregatedResultMapBase.addCollectionWithItems | addCollectionWithItems}.
|
|
2558
|
+
* @public
|
|
2559
|
+
*/
|
|
2560
|
+
declare interface IAddCollectionWithItemsOptions<TMETADATA = unknown> {
|
|
2561
|
+
/**
|
|
2562
|
+
* If true, the collection will be immutable (read-only).
|
|
2563
|
+
* Defaults to false (mutable).
|
|
2564
|
+
*/
|
|
2565
|
+
readonly isImmutable?: boolean;
|
|
2566
|
+
/**
|
|
2567
|
+
* Optional metadata to attach to the collection.
|
|
2568
|
+
*/
|
|
2569
|
+
readonly metadata?: TMETADATA;
|
|
2570
|
+
}
|
|
2571
|
+
|
|
2572
|
+
/**
|
|
2573
|
+
* Parameters for constructing an {@link AggregatedResultMap | aggregated result map}.
|
|
2574
|
+
* @public
|
|
2575
|
+
*/
|
|
2576
|
+
declare interface IAggregatedResultMapConstructorParams<TCOMPOSITEID extends string, TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> {
|
|
2577
|
+
/**
|
|
2578
|
+
* Validator for composite IDs.
|
|
2579
|
+
*/
|
|
2580
|
+
readonly compositeIdValidator?: Validator<TCOMPOSITEID, unknown>;
|
|
2581
|
+
/**
|
|
2582
|
+
* Converter or validator for collection IDs.
|
|
2583
|
+
*/
|
|
2584
|
+
readonly collectionIdConverter: Converter<TCOLLECTIONID, unknown> | Validator<TCOLLECTIONID, unknown>;
|
|
2585
|
+
/**
|
|
2586
|
+
* Converter or validator for item IDs.
|
|
2587
|
+
*/
|
|
2588
|
+
readonly itemIdConverter: Converter<TITEMID, unknown> | Validator<TITEMID, unknown>;
|
|
2589
|
+
/**
|
|
2590
|
+
* Converter or validator for individual items in each collection.
|
|
2591
|
+
*/
|
|
2592
|
+
readonly itemConverter: Converter<TITEM, unknown> | Validator<TITEM, unknown>;
|
|
2593
|
+
/**
|
|
2594
|
+
* Optional converter or validator for collection metadata. If not provided, a metadata field
|
|
2595
|
+
* in the input will cause a validation failure.
|
|
2596
|
+
*/
|
|
2597
|
+
readonly metadataConverter?: Converter<TMETADATA, unknown> | Validator<TMETADATA, unknown>;
|
|
2598
|
+
/**
|
|
2599
|
+
* Optional separator string for composite IDs. Defaults to `.`.
|
|
2600
|
+
*/
|
|
2601
|
+
readonly separator?: string;
|
|
2602
|
+
/**
|
|
2603
|
+
* Initial collections to populate the map.
|
|
2604
|
+
* @remarks Each entry may be mutable or read-only.
|
|
2605
|
+
*/
|
|
2606
|
+
readonly collections?: ReadonlyArray<AggregatedResultMapEntryInit<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>>;
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
/**
|
|
2610
|
+
* JSON format for an {@link AggregatedResultMap | aggregated result map} collection entry using an entries array.
|
|
2611
|
+
* @public
|
|
2612
|
+
*/
|
|
2613
|
+
declare interface IAggregatedResultMapJsonEntryWithEntries<TCOLLECTIONID extends string = string> {
|
|
2614
|
+
readonly isMutable: boolean;
|
|
2615
|
+
readonly id: TCOLLECTIONID;
|
|
2616
|
+
readonly entries: ReadonlyArray<KeyValueEntry<string, unknown>>;
|
|
2617
|
+
readonly metadata?: unknown;
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
/**
|
|
2621
|
+
* JSON format for an {@link AggregatedResultMap | aggregated result map} collection entry using a string-keyed items object.
|
|
2622
|
+
* @public
|
|
2623
|
+
*/
|
|
2624
|
+
declare interface IAggregatedResultMapJsonEntryWithItems<TCOLLECTIONID extends string = string> {
|
|
2625
|
+
readonly isMutable: boolean;
|
|
2626
|
+
readonly id: TCOLLECTIONID;
|
|
2627
|
+
readonly items: Record<string, unknown>;
|
|
2628
|
+
readonly metadata?: unknown;
|
|
2629
|
+
}
|
|
2630
|
+
|
|
1774
2631
|
/**
|
|
1775
2632
|
* An item that can be collected by some {@link ConvertingCollector | Collector}.
|
|
1776
2633
|
* @public
|
|
@@ -1813,6 +2670,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1813
2670
|
* @public
|
|
1814
2671
|
*/
|
|
1815
2672
|
declare interface ICollectorConstructorParams<TITEM extends ICollectible<any, any>> {
|
|
2673
|
+
/** Optional initial items to populate the collector. */
|
|
1816
2674
|
items?: TITEM[];
|
|
1817
2675
|
}
|
|
1818
2676
|
|
|
@@ -1821,10 +2679,23 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1821
2679
|
* @public
|
|
1822
2680
|
*/
|
|
1823
2681
|
declare interface ICollectorValidatorCreateParams<TITEM extends ICollectible<any, any>> {
|
|
2682
|
+
/** The collector to validate access to. */
|
|
1824
2683
|
readonly collector: Collector<TITEM>;
|
|
2684
|
+
/** The key-value converters for validation. */
|
|
1825
2685
|
readonly converters: KeyValueConverters<CollectibleKey<TITEM>, TITEM>;
|
|
1826
2686
|
}
|
|
1827
2687
|
|
|
2688
|
+
/**
|
|
2689
|
+
* Represents a composite ID constructed of two strongly-typed string IDs
|
|
2690
|
+
* separated by a delimiter.
|
|
2691
|
+
* @public
|
|
2692
|
+
*/
|
|
2693
|
+
declare interface ICompositeId<TCOLLECTIONID extends string, TITEMID extends string> {
|
|
2694
|
+
readonly collectionId: TCOLLECTIONID;
|
|
2695
|
+
readonly separator: string;
|
|
2696
|
+
readonly itemId: TITEMID;
|
|
2697
|
+
}
|
|
2698
|
+
|
|
1828
2699
|
/**
|
|
1829
2700
|
* Parameters for constructing a {@link Collections.ConvertingCollector | ConvertingCollector}.
|
|
1830
2701
|
* @public
|
|
@@ -1845,10 +2716,50 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1845
2716
|
* @public
|
|
1846
2717
|
*/
|
|
1847
2718
|
declare interface IConvertingCollectorValidatorCreateParams<TITEM extends ICollectible<any, any>, TSRC = TITEM> {
|
|
2719
|
+
/** The converting collector to validate access to. */
|
|
1848
2720
|
collector: ConvertingCollector<TITEM, TSRC>;
|
|
2721
|
+
/** The key-value converters for validation. */
|
|
1849
2722
|
converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;
|
|
1850
2723
|
}
|
|
1851
2724
|
|
|
2725
|
+
/**
|
|
2726
|
+
* Parameters for constructing a {@link Collections.ConvertingResultMap | ConvertingResultMap}.
|
|
2727
|
+
* @public
|
|
2728
|
+
*/
|
|
2729
|
+
declare interface IConvertingResultMapConstructorParams<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>> {
|
|
2730
|
+
/**
|
|
2731
|
+
* The inner map containing source values.
|
|
2732
|
+
*/
|
|
2733
|
+
inner: TSRCMAP;
|
|
2734
|
+
/**
|
|
2735
|
+
* The converter function to transform source values to target values.
|
|
2736
|
+
*/
|
|
2737
|
+
converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;
|
|
2738
|
+
}
|
|
2739
|
+
|
|
2740
|
+
/**
|
|
2741
|
+
* Extended logger interface that supports logging a short summary message at a
|
|
2742
|
+
* primary level (error/warn) while emitting the full detail at `detail` level.
|
|
2743
|
+
*
|
|
2744
|
+
* The detail is suppressed by default (requires log level `'detail'` or `'all'`),
|
|
2745
|
+
* keeping the primary log clean while preserving the full context for debugging.
|
|
2746
|
+
* @public
|
|
2747
|
+
*/
|
|
2748
|
+
declare interface IDetailLogger extends ILogger {
|
|
2749
|
+
/**
|
|
2750
|
+
* Logs a short error summary at `error` level, then emits `detail` at `detail` level.
|
|
2751
|
+
* @param message - Short human-readable summary.
|
|
2752
|
+
* @param detail - Full detail (e.g. raw converter error) logged at `detail` level.
|
|
2753
|
+
*/
|
|
2754
|
+
errorWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
2755
|
+
/**
|
|
2756
|
+
* Logs a short warning summary at `warning` level, then emits `detail` at `detail` level.
|
|
2757
|
+
* @param message - Short human-readable summary.
|
|
2758
|
+
* @param detail - Full detail logged at `detail` level.
|
|
2759
|
+
*/
|
|
2760
|
+
warnWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
2761
|
+
}
|
|
2762
|
+
|
|
1852
2763
|
/**
|
|
1853
2764
|
* Parameters for constructing a {@link Collections.KeyValueConverters | KeyValueConverters} instance.
|
|
1854
2765
|
* @public
|
|
@@ -1978,10 +2889,21 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1978
2889
|
}
|
|
1979
2890
|
|
|
1980
2891
|
/**
|
|
1981
|
-
*
|
|
1982
|
-
*
|
|
2892
|
+
* A mutable collection entry in an {@link AggregatedResultMap | aggregated result map}.
|
|
2893
|
+
* @public
|
|
2894
|
+
*/
|
|
2895
|
+
declare interface IMutableAggregatedResultMapEntry<TCOLLECTIONID extends string = string, TITEMID extends string = string, TITEM = unknown, TMETADATA = unknown> {
|
|
2896
|
+
readonly isMutable: true;
|
|
2897
|
+
readonly id: TCOLLECTIONID;
|
|
2898
|
+
readonly items: ValidatingResultMap<TITEMID, TITEM>;
|
|
2899
|
+
metadata?: TMETADATA;
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
/**
|
|
2903
|
+
* Infers the type that will be returned by an instantiated converter. Works
|
|
2904
|
+
* for complex as well as simple types, including nested arrays.
|
|
1983
2905
|
* @example `Infer<typeof Converters.mapOf(Converters.stringArray)>` is `Map<string, string[]>`
|
|
1984
|
-
* @
|
|
2906
|
+
* @public
|
|
1985
2907
|
*/
|
|
1986
2908
|
declare type Infer<TCONV> = TCONV extends Converter<infer TTO, unknown> ? InnerInferredType<TTO> : never;
|
|
1987
2909
|
|
|
@@ -2024,20 +2946,38 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2024
2946
|
protected _log(message: string, __level: MessageLogLevel): Success<string | undefined>;
|
|
2025
2947
|
/**
|
|
2026
2948
|
* {@inheritDoc Logging.LoggerBase._suppressLog}
|
|
2027
|
-
* @param level - The level of the message.
|
|
2028
|
-
* @param message - The message to suppress.
|
|
2029
|
-
* @param parameters - The parameters to suppress.
|
|
2030
|
-
* @returns `Success` with `undefined` if the message is suppressed.
|
|
2031
2949
|
* @internal
|
|
2032
2950
|
*/
|
|
2033
2951
|
protected _suppressLog(level: MessageLogLevel, message?: unknown, ...parameters: unknown[]): Success<undefined>;
|
|
2034
2952
|
}
|
|
2035
2953
|
|
|
2036
2954
|
/**
|
|
2037
|
-
*
|
|
2955
|
+
* Internal helper that recursively unwraps converter and array types.
|
|
2956
|
+
* @internal
|
|
2038
2957
|
*/
|
|
2039
2958
|
declare type InnerInferredType<TCONV> = TCONV extends Converter<infer TTO> ? TTO extends Array<infer TTOELEM> ? InnerInferredType<TTOELEM>[] : TTO : TCONV extends Array<infer TELEM> ? InnerInferredType<TELEM>[] : TCONV;
|
|
2040
2959
|
|
|
2960
|
+
/**
|
|
2961
|
+
* Represents a partial composite ID, where separator is optional.
|
|
2962
|
+
* @public
|
|
2963
|
+
*/
|
|
2964
|
+
declare interface IPartialCompositeId<TCOLLECTIONID extends string, TITEMID extends string> {
|
|
2965
|
+
readonly collectionId: TCOLLECTIONID;
|
|
2966
|
+
readonly separator?: string;
|
|
2967
|
+
readonly itemId: TITEMID;
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
/**
|
|
2971
|
+
* A read-only collection entry in an {@link AggregatedResultMap | aggregated result map}.
|
|
2972
|
+
* @public
|
|
2973
|
+
*/
|
|
2974
|
+
declare interface IReadonlyAggregatedResultMapEntry<TCOLLECTIONID extends string = string, TITEMID extends string = string, TITEM = unknown, TMETADATA = unknown> {
|
|
2975
|
+
readonly isMutable: false;
|
|
2976
|
+
readonly id: TCOLLECTIONID;
|
|
2977
|
+
readonly items: IReadOnlyValidatingResultMap<TITEMID, TITEM>;
|
|
2978
|
+
readonly metadata?: TMETADATA;
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2041
2981
|
/**
|
|
2042
2982
|
* A read-only interface exposing only the non-mutating methods of a {@link Collections.Collector | ICollector}.
|
|
2043
2983
|
* @public
|
|
@@ -2064,23 +3004,47 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2064
3004
|
*/
|
|
2065
3005
|
declare interface IReadOnlyCollectorValidator<TITEM extends ICollectible<any, any>> extends IReadOnlyResultMapValidator<CollectibleKey<TITEM>, TITEM> {
|
|
2066
3006
|
/**
|
|
2067
|
-
* {@
|
|
3007
|
+
* {@inheritDoc Collections.ReadOnlyResultMapValidator.map}
|
|
2068
3008
|
*/
|
|
2069
3009
|
readonly map: IReadOnlyResultMap<CollectibleKey<TITEM>, TITEM>;
|
|
2070
3010
|
/**
|
|
2071
|
-
* {@
|
|
3011
|
+
* {@inheritDoc Collections.Collector.get}
|
|
2072
3012
|
*/
|
|
2073
3013
|
get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
2074
3014
|
/**
|
|
2075
|
-
* {@
|
|
3015
|
+
* {@inheritDoc Collections.ResultMap.has}
|
|
2076
3016
|
*/
|
|
2077
3017
|
has(key: string): boolean;
|
|
2078
3018
|
/**
|
|
2079
|
-
* {@
|
|
3019
|
+
* {@inheritDoc Collections.Collector.getOrAdd}
|
|
2080
3020
|
*/
|
|
2081
3021
|
getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
2082
3022
|
}
|
|
2083
3023
|
|
|
3024
|
+
/**
|
|
3025
|
+
* Parameters for constructing a {@link Collections.ReadOnlyConvertingResultMap | ReadOnlyConvertingResultMap}.
|
|
3026
|
+
* @public
|
|
3027
|
+
*/
|
|
3028
|
+
declare interface IReadOnlyConvertingResultMapConstructorParams<TK extends string, TSRC, TTARGET> {
|
|
3029
|
+
/**
|
|
3030
|
+
* The inner map containing source values.
|
|
3031
|
+
*/
|
|
3032
|
+
inner: IReadOnlyResultMap<TK, TSRC>;
|
|
3033
|
+
/**
|
|
3034
|
+
* The converter function to transform source values to target values.
|
|
3035
|
+
*/
|
|
3036
|
+
converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;
|
|
3037
|
+
/**
|
|
3038
|
+
* Error handling behavior for conversion failures during iteration.
|
|
3039
|
+
* Defaults to `'ignore'` (silently skip failed conversions).
|
|
3040
|
+
*/
|
|
3041
|
+
onConversionError?: ConversionErrorHandling;
|
|
3042
|
+
/**
|
|
3043
|
+
* Optional logger for warnings when `onConversionError` is `'warn'`.
|
|
3044
|
+
*/
|
|
3045
|
+
logger?: ILogger;
|
|
3046
|
+
}
|
|
3047
|
+
|
|
2084
3048
|
/**
|
|
2085
3049
|
* A readonly `ReadonlyMap<TK, TV>`-like object which reports success or failure
|
|
2086
3050
|
* with additional details using the
|
|
@@ -2089,31 +3053,31 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2089
3053
|
*/
|
|
2090
3054
|
export declare interface IReadOnlyResultMap<TK extends string = string, TV = unknown> {
|
|
2091
3055
|
/**
|
|
2092
|
-
* {@
|
|
3056
|
+
* {@inheritDoc Collections.ResultMap.size}
|
|
2093
3057
|
*/
|
|
2094
3058
|
readonly size: number;
|
|
2095
3059
|
/**
|
|
2096
|
-
* {@
|
|
3060
|
+
* {@inheritDoc Collections.ResultMap.entries}
|
|
2097
3061
|
*/
|
|
2098
3062
|
entries(): IterableIterator<KeyValueEntry<TK, TV>>;
|
|
2099
3063
|
/**
|
|
2100
|
-
* {@
|
|
3064
|
+
* {@inheritDoc Collections.ResultMap.forEach}
|
|
2101
3065
|
*/
|
|
2102
3066
|
forEach(cb: ResultMapForEachCb, arg?: unknown): void;
|
|
2103
3067
|
/**
|
|
2104
|
-
* {@
|
|
3068
|
+
* {@inheritDoc Collections.ResultMap.get}
|
|
2105
3069
|
*/
|
|
2106
3070
|
get(key: TK): DetailedResult<TV, ResultMapResultDetail>;
|
|
2107
3071
|
/**
|
|
2108
|
-
* {@
|
|
3072
|
+
* {@inheritDoc Collections.ResultMap.has}
|
|
2109
3073
|
*/
|
|
2110
3074
|
has(key: TK): boolean;
|
|
2111
3075
|
/**
|
|
2112
|
-
* {@
|
|
3076
|
+
* {@inheritDoc Collections.ResultMap.keys}
|
|
2113
3077
|
*/
|
|
2114
3078
|
keys(): IterableIterator<TK>;
|
|
2115
3079
|
/**
|
|
2116
|
-
* {@
|
|
3080
|
+
* {@inheritDoc Collections.ResultMap.values}
|
|
2117
3081
|
*/
|
|
2118
3082
|
values(): IterableIterator<TV>;
|
|
2119
3083
|
/**
|
|
@@ -2129,15 +3093,15 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2129
3093
|
*/
|
|
2130
3094
|
declare interface IReadOnlyResultMapValidator<TK extends string = string, TV = unknown> {
|
|
2131
3095
|
/**
|
|
2132
|
-
* {@
|
|
3096
|
+
* {@inheritDoc Collections.ReadOnlyResultMapValidator.map}
|
|
2133
3097
|
*/
|
|
2134
3098
|
readonly map: IReadOnlyResultMap<TK, TV>;
|
|
2135
3099
|
/**
|
|
2136
|
-
* {@
|
|
3100
|
+
* {@inheritDoc Collections.ResultMap.get}
|
|
2137
3101
|
*/
|
|
2138
3102
|
get(key: string): DetailedResult<TV, ResultMapResultDetail>;
|
|
2139
3103
|
/**
|
|
2140
|
-
* {@
|
|
3104
|
+
* {@inheritDoc Collections.ResultMap.has}
|
|
2141
3105
|
*/
|
|
2142
3106
|
has(key: string): boolean;
|
|
2143
3107
|
}
|
|
@@ -2149,15 +3113,15 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2149
3113
|
*/
|
|
2150
3114
|
declare interface IReadOnlyValidatingCollector<TITEM extends ICollectible<any, any>> extends IReadOnlyValidatingResultMap<CollectibleKey<TITEM>, TITEM> {
|
|
2151
3115
|
/**
|
|
2152
|
-
* {@
|
|
3116
|
+
* {@inheritDoc Collections.ValidatingCollector.validating}
|
|
2153
3117
|
*/
|
|
2154
3118
|
readonly validating: IReadOnlyCollectorValidator<TITEM>;
|
|
2155
3119
|
/**
|
|
2156
|
-
* {@
|
|
3120
|
+
* {@inheritDoc Collections.IReadOnlyCollector.getAt}
|
|
2157
3121
|
*/
|
|
2158
3122
|
getAt(index: number): Result<TITEM>;
|
|
2159
3123
|
/**
|
|
2160
|
-
* {@
|
|
3124
|
+
* {@inheritDoc Collections.IReadOnlyCollector.valuesByIndex}
|
|
2161
3125
|
*/
|
|
2162
3126
|
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
2163
3127
|
}
|
|
@@ -2168,7 +3132,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2168
3132
|
*/
|
|
2169
3133
|
declare interface IReadOnlyValidatingResultMap<TK extends string = string, TV = unknown> extends IReadOnlyResultMap<TK, TV> {
|
|
2170
3134
|
/**
|
|
2171
|
-
* {@
|
|
3135
|
+
* {@inheritDoc Collections.ValidatingResultMap.validating}
|
|
2172
3136
|
*/
|
|
2173
3137
|
readonly validating: IReadOnlyResultMapValidator<TK, TV>;
|
|
2174
3138
|
}
|
|
@@ -2234,7 +3198,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2234
3198
|
* error will also be reported.
|
|
2235
3199
|
* @returns The return value, if the operation was successful.
|
|
2236
3200
|
* @throws The error message if the operation failed.
|
|
2237
|
-
* @deprecated Use {@link IResult.
|
|
3201
|
+
* @deprecated Use {@link IResult.orThrow | orThrow(logger)} or {@link IResult.orThrow | orThrow(formatter)} instead.
|
|
2238
3202
|
*/
|
|
2239
3203
|
getValueOrThrow(logger?: IResultLogger): T;
|
|
2240
3204
|
/**
|
|
@@ -2248,7 +3212,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2248
3212
|
*
|
|
2249
3213
|
* @returns The return value, if the operation was successful. Returns
|
|
2250
3214
|
* the supplied default value or `undefined` if no default is supplied.
|
|
2251
|
-
* @deprecated Use {@link IResult.
|
|
3215
|
+
* @deprecated Use {@link IResult.orDefault | orDefault(T)} or {@link IResult.orDefault | orDefault()} instead.
|
|
2252
3216
|
*/
|
|
2253
3217
|
getValueOrDefault(dflt?: T): T | undefined;
|
|
2254
3218
|
/**
|
|
@@ -2359,7 +3323,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2359
3323
|
}
|
|
2360
3324
|
|
|
2361
3325
|
/**
|
|
2362
|
-
* Simple logger interface used by {@link IResult.
|
|
3326
|
+
* Simple logger interface used by {@link IResult.orThrow | orThrow(logger)} and {@link IResult.orThrow | orThrow(formatter)}.
|
|
2363
3327
|
* @public
|
|
2364
3328
|
*/
|
|
2365
3329
|
export declare interface IResultLogger<TD = unknown> {
|
|
@@ -2370,6 +3334,113 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2370
3334
|
error(message: string, detail?: TD): void;
|
|
2371
3335
|
}
|
|
2372
3336
|
|
|
3337
|
+
/**
|
|
3338
|
+
* Interface for a mutable {@link Collections.ResultMap | ResultMap}.
|
|
3339
|
+
* @public
|
|
3340
|
+
*/
|
|
3341
|
+
declare interface IResultMap<TK extends string = string, TV = unknown> extends IReadOnlyResultMap<TK, TV> {
|
|
3342
|
+
/**
|
|
3343
|
+
* Sets a key/value pair in the map if the key does not already exist.
|
|
3344
|
+
* @param key - The key to set.
|
|
3345
|
+
* @param value - The value to set.
|
|
3346
|
+
* @returns `Success` with the value and detail `added` if the key was added,
|
|
3347
|
+
* `Failure` with detail `exists` if the key already exists. Fails with detail
|
|
3348
|
+
* 'invalid-key' or 'invalid-value' and an error message if either is invalid.
|
|
3349
|
+
*/
|
|
3350
|
+
add(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
|
|
3351
|
+
/**
|
|
3352
|
+
* Sets a key/value pair in the map regardless of whether the key already exists.
|
|
3353
|
+
* @param key - The key to set.
|
|
3354
|
+
* @param value - The value to set.
|
|
3355
|
+
* @returns `Success` with the new value and the detail `updated` if the
|
|
3356
|
+
* key was found and updated, `Success` with the new value and detail
|
|
3357
|
+
* `added` if the key was not found and added. Fails with detail
|
|
3358
|
+
* 'invalid-key' or 'invalid-value' and an error message if either is invalid.
|
|
3359
|
+
*/
|
|
3360
|
+
set(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
|
|
3361
|
+
/**
|
|
3362
|
+
* Updates the value associated with a key in the map.
|
|
3363
|
+
* @param key - The key to update.
|
|
3364
|
+
* @param value - The value to set.
|
|
3365
|
+
* @returns `Success` with the value and detail 'updated' if the key was found
|
|
3366
|
+
* and the value updated, `Failure` an error message and with detail `not-found`
|
|
3367
|
+
* if the key was not found, or with detail 'invalid-key' or 'invalid-value'
|
|
3368
|
+
* if either is invalid.
|
|
3369
|
+
*/
|
|
3370
|
+
update(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
|
|
3371
|
+
/**
|
|
3372
|
+
* Deletes a key from the map.
|
|
3373
|
+
* @param key - The key to delete.
|
|
3374
|
+
* @returns `Success` with the previous value and the detail 'deleted'
|
|
3375
|
+
* if the key was found and deleted, `Failure` with detail 'not-found'
|
|
3376
|
+
* if the key was not found, or with detail 'invalid-key' if the key is invalid.
|
|
3377
|
+
*/
|
|
3378
|
+
delete(key: TK): DetailedResult<TV, ResultMapResultDetail>;
|
|
3379
|
+
/**
|
|
3380
|
+
* Gets a value from the map.
|
|
3381
|
+
* @param key - The key to retrieve.
|
|
3382
|
+
* @returns `Success` with the value and detail `exists` if the key was found,
|
|
3383
|
+
* `Failure` with detail `not-found` if the key was not found or with detail
|
|
3384
|
+
* `invalid-key` if the key is invalid.
|
|
3385
|
+
*/
|
|
3386
|
+
get(key: TK): DetailedResult<TV, ResultMapResultDetail>;
|
|
3387
|
+
/**
|
|
3388
|
+
* Gets a value from the map, or adds a supplied value if it does not exist.
|
|
3389
|
+
* @param key - The key to be retrieved or created.
|
|
3390
|
+
* @param value - The value to add if the key does not exist.
|
|
3391
|
+
* @returns `Success` with the value and detail `exists` if the key was found,
|
|
3392
|
+
* `Success` with the value and detail `added` if the key was not found and added.
|
|
3393
|
+
* Fails with detail 'invalid-key' or 'invalid-value' and an error message if either
|
|
3394
|
+
* is invalid.
|
|
3395
|
+
* {@label WITH_VALUE}
|
|
3396
|
+
*/
|
|
3397
|
+
getOrAdd(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
|
|
3398
|
+
/**
|
|
3399
|
+
* Gets a value from the map, or adds a value created by a factory function if it does not exist.
|
|
3400
|
+
* @param key - The key of the element to be retrieved or created.
|
|
3401
|
+
* @param factory - A {@link Collections.ResultMapValueFactory | factory function} to create the value if
|
|
3402
|
+
* the key does not exist.
|
|
3403
|
+
* @returns `Success` with the value and detail `exists` if the key was found, `Success` with
|
|
3404
|
+
* the value and detail `added` if the key was not found and added. Fails with detail 'invalid-key'
|
|
3405
|
+
* or 'invalid-value' and an error message if either is invalid.
|
|
3406
|
+
* {@label WITH_FACTORY}
|
|
3407
|
+
*/
|
|
3408
|
+
getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;
|
|
3409
|
+
/**
|
|
3410
|
+
* Returns an iterator over the map entries.
|
|
3411
|
+
* @returns An iterator over the map entries.
|
|
3412
|
+
*/
|
|
3413
|
+
entries(): IterableIterator<KeyValueEntry<TK, TV>>;
|
|
3414
|
+
/**
|
|
3415
|
+
* Returns the number of entries in the map.
|
|
3416
|
+
*/
|
|
3417
|
+
readonly size: number;
|
|
3418
|
+
/**
|
|
3419
|
+
* Returns an iterator over the map keys.
|
|
3420
|
+
* @returns An iterator over the map keys.
|
|
3421
|
+
*/
|
|
3422
|
+
keys(): IterableIterator<TK>;
|
|
3423
|
+
/**
|
|
3424
|
+
* Returns an iterator over the map values.
|
|
3425
|
+
* @returns An iterator over the map values.
|
|
3426
|
+
*/
|
|
3427
|
+
values(): IterableIterator<TV>;
|
|
3428
|
+
/**
|
|
3429
|
+
* Calls a function for each entry in the map.
|
|
3430
|
+
* @param cb - The function to call for each entry.
|
|
3431
|
+
* @param arg - An optional argument to pass to the callback.
|
|
3432
|
+
*/
|
|
3433
|
+
forEach(cb: ResultMapForEachCb<TK, TV>, arg?: unknown): void;
|
|
3434
|
+
/**
|
|
3435
|
+
* Clears all entries from the map.
|
|
3436
|
+
*/
|
|
3437
|
+
clear(): void;
|
|
3438
|
+
/**
|
|
3439
|
+
* Gets a readonly version of this map.
|
|
3440
|
+
*/
|
|
3441
|
+
toReadOnly(): IReadOnlyResultMap<TK, TV>;
|
|
3442
|
+
}
|
|
3443
|
+
|
|
2373
3444
|
/**
|
|
2374
3445
|
* Parameters for constructing a {@link Collections.ResultMap | ResultMap}.
|
|
2375
3446
|
* @public
|
|
@@ -2392,7 +3463,9 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2392
3463
|
* @public
|
|
2393
3464
|
*/
|
|
2394
3465
|
export declare interface IResultReporter<T, TD = unknown> {
|
|
3466
|
+
/** Reports a successful result at the specified log level. */
|
|
2395
3467
|
reportSuccess(level: MessageLogLevel, value: T, detail?: TD, message?: ErrorFormatter<TD>): void;
|
|
3468
|
+
/** Reports a failed result at the specified log level. */
|
|
2396
3469
|
reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;
|
|
2397
3470
|
}
|
|
2398
3471
|
|
|
@@ -2411,6 +3484,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2411
3484
|
success?: MessageLogLevel | IMessageReportDetail<TD>;
|
|
2412
3485
|
}
|
|
2413
3486
|
|
|
3487
|
+
/**
|
|
3488
|
+
* Type inference to determine the result type of an {@link IResult}.
|
|
3489
|
+
* @beta
|
|
3490
|
+
*/
|
|
3491
|
+
export declare type IResultValueType<T> = T extends IResult<infer TV> ? TV : never;
|
|
3492
|
+
|
|
2414
3493
|
/**
|
|
2415
3494
|
* Helper function to create a {@link Converter | Converter} from a supplied type guard function.
|
|
2416
3495
|
* @param description - a description of the thing to be validated for use in error messages
|
|
@@ -2440,6 +3519,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2440
3519
|
*/
|
|
2441
3520
|
export declare function isDeferredResult<T>(result: Result<T> | DeferredResult<T>): result is DeferredResult<T>;
|
|
2442
3521
|
|
|
3522
|
+
/**
|
|
3523
|
+
* Type guard that checks whether a logger implements {@link IDetailLogger}.
|
|
3524
|
+
* @param logger - The logger to check.
|
|
3525
|
+
* @returns `true` if the logger implements `IDetailLogger`.
|
|
3526
|
+
* @public
|
|
3527
|
+
*/
|
|
3528
|
+
declare function isDetailLogger(logger: ILogger): logger is IDetailLogger;
|
|
3529
|
+
|
|
2443
3530
|
/**
|
|
2444
3531
|
* Determines if a supplied value is an iterable object or some other type.
|
|
2445
3532
|
* @param value - The value to be tested.
|
|
@@ -2458,17 +3545,26 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2458
3545
|
*/
|
|
2459
3546
|
export declare function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T;
|
|
2460
3547
|
|
|
3548
|
+
/**
|
|
3549
|
+
* Determines if a supplied {@link Conversion.Converter | Converter} or {@link Validation.Validator | Validator} is
|
|
3550
|
+
* a {@link Validation.Validator | Validator}.
|
|
3551
|
+
* @param converterOrValidator - The {@link Conversion.Converter | Converter} or {@link Validation.Validator | Validator} to be tested.
|
|
3552
|
+
* @returns `true` if `converterOrValidator` is a {@link Validation.Validator | Validator}, `false` otherwise.
|
|
3553
|
+
* @public
|
|
3554
|
+
*/
|
|
3555
|
+
declare function isValidator<T, TC>(converterOrValidator: Converter<T, TC> | Validator<T, TC>): converterOrValidator is Validator<T, TC>;
|
|
3556
|
+
|
|
2461
3557
|
/**
|
|
2462
3558
|
* Parameters for constructing a {@link Collections.ValidatingCollector | ValidatingCollector}.
|
|
2463
3559
|
* @public
|
|
2464
3560
|
*/
|
|
2465
3561
|
declare interface IValidatingCollectorConstructorParams<TITEM extends ICollectible<any, any>> {
|
|
2466
3562
|
/**
|
|
2467
|
-
* {@
|
|
3563
|
+
* {@inheritDoc Collections.ICollectorValidatorCreateParams.converters}
|
|
2468
3564
|
*/
|
|
2469
3565
|
converters: KeyValueConverters<CollectibleKey<TITEM>, TITEM>;
|
|
2470
3566
|
/**
|
|
2471
|
-
* {@
|
|
3567
|
+
* {@inheritDoc Collections.ICollectorConstructorParams.items}
|
|
2472
3568
|
*/
|
|
2473
3569
|
items?: unknown[];
|
|
2474
3570
|
}
|
|
@@ -2479,19 +3575,59 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2479
3575
|
*/
|
|
2480
3576
|
declare interface IValidatingConvertingCollectorConstructorParams<TITEM extends ICollectible<any, any>, TSRC = TITEM> {
|
|
2481
3577
|
/**
|
|
2482
|
-
* {@
|
|
3578
|
+
* {@inheritDoc Collections.IConvertingCollectorConstructorParams.factory}
|
|
2483
3579
|
*/
|
|
2484
3580
|
factory: CollectibleFactory<TITEM, TSRC>;
|
|
2485
3581
|
/**
|
|
2486
|
-
* {@
|
|
3582
|
+
* {@inheritDoc Collections.IConvertingCollectorValidatorCreateParams.converters}
|
|
2487
3583
|
*/
|
|
2488
3584
|
converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;
|
|
2489
3585
|
/**
|
|
2490
|
-
* {@
|
|
3586
|
+
* {@inheritDoc Collections.IConvertingCollectorConstructorParams.entries}
|
|
2491
3587
|
*/
|
|
2492
3588
|
entries?: KeyValueEntry<CollectibleKey<TITEM>, TSRC>[];
|
|
2493
3589
|
}
|
|
2494
3590
|
|
|
3591
|
+
/**
|
|
3592
|
+
* Parameters for constructing a
|
|
3593
|
+
* {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.
|
|
3594
|
+
* @public
|
|
3595
|
+
*/
|
|
3596
|
+
declare interface IValidatingConvertingResultMapConstructorParams<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>> {
|
|
3597
|
+
/**
|
|
3598
|
+
* The inner map containing source values.
|
|
3599
|
+
*/
|
|
3600
|
+
inner: TSRCMAP;
|
|
3601
|
+
/**
|
|
3602
|
+
* The converter function to transform source values to target values.
|
|
3603
|
+
*/
|
|
3604
|
+
converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;
|
|
3605
|
+
/**
|
|
3606
|
+
* The key-value converters for validating weakly-typed access.
|
|
3607
|
+
*/
|
|
3608
|
+
converters: KeyValueConverters<TK, TTARGET>;
|
|
3609
|
+
}
|
|
3610
|
+
|
|
3611
|
+
/**
|
|
3612
|
+
* Parameters for constructing a
|
|
3613
|
+
* {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.
|
|
3614
|
+
* @public
|
|
3615
|
+
*/
|
|
3616
|
+
declare interface IValidatingReadOnlyConvertingResultMapConstructorParams<TK extends string, TSRC, TTARGET> {
|
|
3617
|
+
/**
|
|
3618
|
+
* The inner map containing source values.
|
|
3619
|
+
*/
|
|
3620
|
+
inner: IReadOnlyResultMap<TK, TSRC>;
|
|
3621
|
+
/**
|
|
3622
|
+
* The converter function to transform source values to target values.
|
|
3623
|
+
*/
|
|
3624
|
+
converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;
|
|
3625
|
+
/**
|
|
3626
|
+
* The key-value converters for validating weakly-typed access.
|
|
3627
|
+
*/
|
|
3628
|
+
converters: KeyValueConverters<TK, TTARGET>;
|
|
3629
|
+
}
|
|
3630
|
+
|
|
2495
3631
|
/**
|
|
2496
3632
|
* Parameters for constructing a {@link Collections.ResultMap | ResultMap}.
|
|
2497
3633
|
* @public
|
|
@@ -2502,8 +3638,8 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2502
3638
|
}
|
|
2503
3639
|
|
|
2504
3640
|
/**
|
|
2505
|
-
* Options for {@link
|
|
2506
|
-
* {@link
|
|
3641
|
+
* Options for {@link recordOf} and
|
|
3642
|
+
* {@link mapOf}
|
|
2507
3643
|
* helper functions.
|
|
2508
3644
|
* @public
|
|
2509
3645
|
*/
|
|
@@ -2528,6 +3664,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2528
3664
|
*/
|
|
2529
3665
|
declare type KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;
|
|
2530
3666
|
|
|
3667
|
+
/**
|
|
3668
|
+
* Type-safe(ish) key extractor for typed records.
|
|
3669
|
+
* @param obj - The record from which keys are to be extracted.
|
|
3670
|
+
* @returns The keys of the record as an array.
|
|
3671
|
+
* @public
|
|
3672
|
+
*/
|
|
3673
|
+
export declare function keysForRecord<TK extends string>(obj: Record<TK, unknown>): TK[];
|
|
3674
|
+
|
|
2531
3675
|
/**
|
|
2532
3676
|
* Helper class for converting strongly-typed keys, values, or entries
|
|
2533
3677
|
* from unknown values.
|
|
@@ -2544,10 +3688,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2544
3688
|
readonly value: Validator<TV, unknown> | Converter<TV, unknown>;
|
|
2545
3689
|
/**
|
|
2546
3690
|
* Constructs a new key-value validator.
|
|
2547
|
-
* @param
|
|
2548
|
-
* or {@link Conversion.ConverterFunc | converter function}.
|
|
2549
|
-
* @param value - Required value {@link Validator | validator}, {@link Converter | converter},
|
|
2550
|
-
* or {@link Conversion.ConverterFunc | converter function}.
|
|
3691
|
+
* @param params - Key and value converters or validators.
|
|
2551
3692
|
*/
|
|
2552
3693
|
constructor({ key, value }: IKeyValueConverterConstructorParams<TK, TV>);
|
|
2553
3694
|
/**
|
|
@@ -2604,10 +3745,10 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2604
3745
|
declare function literal_2<T extends string | number | boolean | symbol | null | undefined>(value: T): Validator<T>;
|
|
2605
3746
|
|
|
2606
3747
|
/**
|
|
2607
|
-
* Abstract base class which implements {@link Logging.
|
|
3748
|
+
* Abstract base class which implements {@link Logging.IDetailLogger | IDetailLogger}.
|
|
2608
3749
|
* @public
|
|
2609
3750
|
*/
|
|
2610
|
-
declare abstract class LoggerBase implements
|
|
3751
|
+
declare abstract class LoggerBase implements IDetailLogger {
|
|
2611
3752
|
/**
|
|
2612
3753
|
* {@inheritDoc Logging.ILogger.logLevel}
|
|
2613
3754
|
*/
|
|
@@ -2629,6 +3770,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2629
3770
|
* {@inheritDoc Logging.ILogger.error}
|
|
2630
3771
|
*/
|
|
2631
3772
|
error(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3773
|
+
/**
|
|
3774
|
+
* {@inheritDoc Logging.IDetailLogger.errorWithDetail}
|
|
3775
|
+
*/
|
|
3776
|
+
errorWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
3777
|
+
/**
|
|
3778
|
+
* {@inheritDoc Logging.IDetailLogger.warnWithDetail}
|
|
3779
|
+
*/
|
|
3780
|
+
warnWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
2632
3781
|
/**
|
|
2633
3782
|
* {@inheritDoc Logging.ILogger.log}
|
|
2634
3783
|
*/
|
|
@@ -2658,10 +3807,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2658
3807
|
|
|
2659
3808
|
declare namespace Logging {
|
|
2660
3809
|
export {
|
|
3810
|
+
BootLogger,
|
|
2661
3811
|
shouldLog,
|
|
2662
3812
|
stringifyLogValue,
|
|
3813
|
+
isDetailLogger,
|
|
2663
3814
|
ReporterLogLevel,
|
|
2664
3815
|
ILogger,
|
|
3816
|
+
IDetailLogger,
|
|
2665
3817
|
LoggerBase,
|
|
2666
3818
|
InMemoryLogger,
|
|
2667
3819
|
ConsoleLogger,
|
|
@@ -2685,7 +3837,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2685
3837
|
* both {@link Logging.ILogger | ILogger} and {@link IResultReporter | IResultReporter}.
|
|
2686
3838
|
* @public
|
|
2687
3839
|
*/
|
|
2688
|
-
declare class LogReporter<T, TD = unknown> implements
|
|
3840
|
+
declare class LogReporter<T, TD = unknown> implements IDetailLogger, IResultReporter<T, TD> {
|
|
2689
3841
|
/**
|
|
2690
3842
|
* Base logger used to by this reporter.
|
|
2691
3843
|
* @public
|
|
@@ -2706,6 +3858,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2706
3858
|
* @param params - The parameters for creating the {@link Logging.LogReporter | LogReporter}.
|
|
2707
3859
|
*/
|
|
2708
3860
|
constructor(params?: ILogReporterCreateParams<T, TD>);
|
|
3861
|
+
/**
|
|
3862
|
+
* Creates a default {@link Logging.LogReporter | LogReporter} with a {@link Logging.NoOpLogger | NoOpLogger} with the
|
|
3863
|
+
* supplied parameters, returning both the logger and reporter.
|
|
3864
|
+
* @param logger - Optional logger to use; defaults to a new {@link Logging.NoOpLogger | NoOpLogger} if not provided.
|
|
3865
|
+
* @returns
|
|
3866
|
+
*/
|
|
3867
|
+
static createDefault(logger?: ILogger): Result<LogReporter<unknown>>;
|
|
2709
3868
|
/**
|
|
2710
3869
|
* {@inheritDoc Logging.ILogger.logLevel}
|
|
2711
3870
|
*/
|
|
@@ -2726,6 +3885,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2726
3885
|
* {@inheritDoc Logging.ILogger.error}
|
|
2727
3886
|
*/
|
|
2728
3887
|
error(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3888
|
+
/**
|
|
3889
|
+
* {@inheritDoc Logging.IDetailLogger.errorWithDetail}
|
|
3890
|
+
*/
|
|
3891
|
+
errorWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
3892
|
+
/**
|
|
3893
|
+
* {@inheritDoc Logging.IDetailLogger.warnWithDetail}
|
|
3894
|
+
*/
|
|
3895
|
+
warnWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
2729
3896
|
/**
|
|
2730
3897
|
* {@inheritDoc Logging.ILogger.log}
|
|
2731
3898
|
*/
|
|
@@ -2898,27 +4065,27 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2898
4065
|
*/
|
|
2899
4066
|
constructor(errors?: string[]);
|
|
2900
4067
|
/**
|
|
2901
|
-
* {@
|
|
4068
|
+
* {@inheritDoc IMessageAggregator.hasMessages}
|
|
2902
4069
|
*/
|
|
2903
4070
|
get hasMessages(): boolean;
|
|
2904
4071
|
/**
|
|
2905
|
-
* {@
|
|
4072
|
+
* {@inheritDoc IMessageAggregator.numMessages}
|
|
2906
4073
|
*/
|
|
2907
4074
|
get numMessages(): number;
|
|
2908
4075
|
/**
|
|
2909
|
-
* {@
|
|
4076
|
+
* {@inheritDoc IMessageAggregator.messages}
|
|
2910
4077
|
*/
|
|
2911
4078
|
get messages(): string[];
|
|
2912
4079
|
/**
|
|
2913
|
-
* {@
|
|
4080
|
+
* {@inheritDoc IMessageAggregator.addMessage}
|
|
2914
4081
|
*/
|
|
2915
4082
|
addMessage(message: string | undefined): this;
|
|
2916
4083
|
/**
|
|
2917
|
-
* {@
|
|
4084
|
+
* {@inheritDoc IMessageAggregator.addMessages}
|
|
2918
4085
|
*/
|
|
2919
4086
|
addMessages(messages: string[] | undefined): this;
|
|
2920
4087
|
/**
|
|
2921
|
-
* {@
|
|
4088
|
+
* {@inheritDoc IMessageAggregator.toString}
|
|
2922
4089
|
*/
|
|
2923
4090
|
toString(separator?: string): string;
|
|
2924
4091
|
/**
|
|
@@ -3260,10 +4427,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3260
4427
|
protected readonly _allowedFields?: Set<keyof T>;
|
|
3261
4428
|
/**
|
|
3262
4429
|
* Constructs a new {@link Validation.Classes.ObjectValidator | ObjectValidator<T>}.
|
|
3263
|
-
* @param
|
|
3264
|
-
* a {@link Validation.Validator | Validator} for each field.
|
|
3265
|
-
* @param options - An optional {@link Validation.Classes.ObjectValidatorOptions} to configure
|
|
3266
|
-
* validation.
|
|
4430
|
+
* @param params - Construction parameters including field validators and options.
|
|
3267
4431
|
*/
|
|
3268
4432
|
constructor(params: ObjectValidatorConstructorParams<T, TC>);
|
|
3269
4433
|
/**
|
|
@@ -3292,13 +4456,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3292
4456
|
/**
|
|
3293
4457
|
* Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with
|
|
3294
4458
|
* new optional properties as specified by a supplied array of `keyof T`.
|
|
3295
|
-
* @param
|
|
4459
|
+
* @param addOptionalFields - The keys to be made optional.
|
|
3296
4460
|
* @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional
|
|
3297
4461
|
* source properties.
|
|
3298
4462
|
*/
|
|
3299
4463
|
addPartial(addOptionalFields: (keyof T)[]): ObjectValidator<Partial<T>, TC>;
|
|
3300
4464
|
/**
|
|
3301
|
-
* {@
|
|
4465
|
+
* {@inheritDoc Validation.ValidatorBase._validate}
|
|
3302
4466
|
* @internal
|
|
3303
4467
|
*/
|
|
3304
4468
|
protected _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T>;
|
|
@@ -3559,7 +4723,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3559
4723
|
export declare function populateObject<T>(initializers: FieldInitializers<T>, order: (keyof T)[] | undefined, aggregatedErrors?: IMessageAggregator): Result<T>;
|
|
3560
4724
|
|
|
3561
4725
|
/**
|
|
3562
|
-
* Options for the {@link
|
|
4726
|
+
* Options for the {@link populateObject} function.
|
|
3563
4727
|
* @public
|
|
3564
4728
|
*/
|
|
3565
4729
|
export declare interface PopulateObjectOptions<T> {
|
|
@@ -3593,6 +4757,162 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3593
4757
|
*/
|
|
3594
4758
|
export declare function propagateWithDetail<T, TD>(result: Result<T>, detail: TD, successDetail?: TD): DetailedResult<T, TD>;
|
|
3595
4759
|
|
|
4760
|
+
/**
|
|
4761
|
+
* A read-only result map that wraps an inner {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}
|
|
4762
|
+
* of source type and returns lazily-converted, cached values of a target type.
|
|
4763
|
+
* @public
|
|
4764
|
+
*/
|
|
4765
|
+
declare class ReadOnlyConvertingResultMap<TK extends string, TSRC, TTARGET> implements IReadOnlyResultMap<TK, TTARGET> {
|
|
4766
|
+
/**
|
|
4767
|
+
* The inner map containing source values.
|
|
4768
|
+
*/
|
|
4769
|
+
protected readonly _inner: IReadOnlyResultMap<TK, TSRC>;
|
|
4770
|
+
/**
|
|
4771
|
+
* The converter function to transform source values to target values.
|
|
4772
|
+
*/
|
|
4773
|
+
protected readonly _converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;
|
|
4774
|
+
/**
|
|
4775
|
+
* Cache of converted target values.
|
|
4776
|
+
*/
|
|
4777
|
+
protected readonly _cache: Map<TK, TTARGET>;
|
|
4778
|
+
/**
|
|
4779
|
+
* Error handling behavior for conversion failures during iteration.
|
|
4780
|
+
*/
|
|
4781
|
+
protected readonly _onConversionError: ConversionErrorHandling;
|
|
4782
|
+
/**
|
|
4783
|
+
* Optional logger for warnings.
|
|
4784
|
+
*/
|
|
4785
|
+
protected readonly _logger?: ILogger;
|
|
4786
|
+
/**
|
|
4787
|
+
* Constructs a new {@link Collections.ReadOnlyConvertingResultMap | ReadOnlyConvertingResultMap}.
|
|
4788
|
+
* @param params - Parameters for constructing the map.
|
|
4789
|
+
*/
|
|
4790
|
+
constructor(params: IReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>);
|
|
4791
|
+
/**
|
|
4792
|
+
* Creates a new {@link Collections.ReadOnlyConvertingResultMap | ReadOnlyConvertingResultMap}.
|
|
4793
|
+
* @param params - Parameters for constructing the map.
|
|
4794
|
+
* @returns `Success` with the new map, or `Failure` with error details if an error occurred.
|
|
4795
|
+
*/
|
|
4796
|
+
static create<TK extends string, TSRC, TTARGET>(params: IReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>): Result<ReadOnlyConvertingResultMap<TK, TSRC, TTARGET>>;
|
|
4797
|
+
/**
|
|
4798
|
+
* The number of entries in the map.
|
|
4799
|
+
*/
|
|
4800
|
+
get size(): number;
|
|
4801
|
+
/**
|
|
4802
|
+
* Gets a converted value from the map by key.
|
|
4803
|
+
* @param key - The key to retrieve.
|
|
4804
|
+
* @returns `Success` with the converted value and detail `exists` if the key was found,
|
|
4805
|
+
* `Failure` with detail `not-found` if the key was not found, or `Failure` with
|
|
4806
|
+
* detail `invalid-value` if conversion failed.
|
|
4807
|
+
*/
|
|
4808
|
+
get(key: TK): DetailedResult<TTARGET, ResultMapResultDetail>;
|
|
4809
|
+
/**
|
|
4810
|
+
* Checks if the map contains a key.
|
|
4811
|
+
* @param key - The key to check.
|
|
4812
|
+
* @returns `true` if the key exists, `false` otherwise.
|
|
4813
|
+
*/
|
|
4814
|
+
has(key: TK): boolean;
|
|
4815
|
+
/**
|
|
4816
|
+
* Returns an iterator over the map entries with converted values.
|
|
4817
|
+
* @returns An iterator over the map entries.
|
|
4818
|
+
*/
|
|
4819
|
+
entries(): IterableIterator<KeyValueEntry<TK, TTARGET>>;
|
|
4820
|
+
/**
|
|
4821
|
+
* Returns an iterator over the map keys.
|
|
4822
|
+
* @returns An iterator over the map keys.
|
|
4823
|
+
*/
|
|
4824
|
+
keys(): IterableIterator<TK>;
|
|
4825
|
+
/**
|
|
4826
|
+
* Returns an iterator over the converted map values.
|
|
4827
|
+
* @returns An iterator over the map values.
|
|
4828
|
+
*/
|
|
4829
|
+
values(): IterableIterator<TTARGET>;
|
|
4830
|
+
/**
|
|
4831
|
+
* Calls a callback for each entry in the map with converted values.
|
|
4832
|
+
* @param cb - The callback to call for each entry.
|
|
4833
|
+
* @param thisArg - Optional `this` argument for the callback.
|
|
4834
|
+
*/
|
|
4835
|
+
forEach(cb: ResultMapForEachCb<TK, TTARGET>, thisArg?: unknown): void;
|
|
4836
|
+
/**
|
|
4837
|
+
* Gets an iterator over the map entries.
|
|
4838
|
+
* @returns An iterator over the map entries.
|
|
4839
|
+
*/
|
|
4840
|
+
[Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TTARGET>>;
|
|
4841
|
+
/**
|
|
4842
|
+
* Gets a read-only version of this map.
|
|
4843
|
+
* @returns A read-only version of this map.
|
|
4844
|
+
*/
|
|
4845
|
+
toReadOnly(): IReadOnlyResultMap<TK, TTARGET>;
|
|
4846
|
+
/**
|
|
4847
|
+
* Converts a source value to a target value and caches the result.
|
|
4848
|
+
* @param key - The key of the value.
|
|
4849
|
+
* @param src - The source value to convert.
|
|
4850
|
+
* @returns `Success` with the converted value if successful, `Failure` otherwise.
|
|
4851
|
+
*/
|
|
4852
|
+
protected _convertAndCache(key: TK, src: TSRC): DetailedResult<TTARGET, ResultMapResultDetail>;
|
|
4853
|
+
/**
|
|
4854
|
+
* Gets a cached value or converts and caches a source value.
|
|
4855
|
+
* Used by iterators. Handles conversion failures according to `_onConversionError`.
|
|
4856
|
+
* @param key - The key of the value.
|
|
4857
|
+
* @param src - The source value to convert if not cached.
|
|
4858
|
+
* @returns The converted value, or `undefined` if conversion failed.
|
|
4859
|
+
* @throws Error if `_onConversionError` is `'fail'` and conversion fails.
|
|
4860
|
+
*/
|
|
4861
|
+
protected _getOrConvert(key: TK, src: TSRC): TTARGET | undefined;
|
|
4862
|
+
/**
|
|
4863
|
+
* Clears a single entry from the cache.
|
|
4864
|
+
* @param key - The key to clear from the cache.
|
|
4865
|
+
*/
|
|
4866
|
+
protected _clearCacheEntry(key: TK): void;
|
|
4867
|
+
/**
|
|
4868
|
+
* Clears all entries from the cache.
|
|
4869
|
+
*/
|
|
4870
|
+
protected _clearCache(): void;
|
|
4871
|
+
}
|
|
4872
|
+
|
|
4873
|
+
/**
|
|
4874
|
+
* A read-only validator for any {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}
|
|
4875
|
+
* that validates weakly-typed keys before accessing values.
|
|
4876
|
+
* @public
|
|
4877
|
+
*/
|
|
4878
|
+
declare class ReadOnlyResultMapValidator<TK extends string = string, TV = unknown> implements IReadOnlyResultMapValidator<TK, TV> {
|
|
4879
|
+
/**
|
|
4880
|
+
* The key-value converters used for validation.
|
|
4881
|
+
*/
|
|
4882
|
+
readonly converters: KeyValueConverters<TK, TV>;
|
|
4883
|
+
/**
|
|
4884
|
+
* The underlying map.
|
|
4885
|
+
*/
|
|
4886
|
+
get map(): IReadOnlyResultMap<TK, TV>;
|
|
4887
|
+
private readonly _map;
|
|
4888
|
+
/**
|
|
4889
|
+
* Constructs a new {@link Collections.ReadOnlyResultMapValidator | ReadOnlyResultMapValidator}.
|
|
4890
|
+
* @param map - The map to validate access to.
|
|
4891
|
+
* @param converters - The key-value converters for validation.
|
|
4892
|
+
*/
|
|
4893
|
+
constructor(map: IReadOnlyResultMap<TK, TV>, converters: KeyValueConverters<TK, TV>);
|
|
4894
|
+
/**
|
|
4895
|
+
* Gets a value from the map by key, validating the key first.
|
|
4896
|
+
* @param key - The key to retrieve (will be validated).
|
|
4897
|
+
* @returns `Success` with the value if found, `Failure` otherwise.
|
|
4898
|
+
*/
|
|
4899
|
+
get(key: string): DetailedResult<TV, ResultMapResultDetail>;
|
|
4900
|
+
/**
|
|
4901
|
+
* Checks if the map contains a key, validating the key first.
|
|
4902
|
+
* @param key - The key to check (will be validated).
|
|
4903
|
+
* @returns `true` if the key exists and is valid, `false` otherwise.
|
|
4904
|
+
*/
|
|
4905
|
+
has(key: string): boolean;
|
|
4906
|
+
}
|
|
4907
|
+
|
|
4908
|
+
/**
|
|
4909
|
+
* Type-safe(ish) record constructor from an iterable of `[key, value]` tuples.
|
|
4910
|
+
* @param entries - The iterable of `[key, value]` tuples from which to construct the record.
|
|
4911
|
+
* @returns A record constructed from the supplied entries.
|
|
4912
|
+
* @public
|
|
4913
|
+
*/
|
|
4914
|
+
export declare function recordFromEntries<TK extends string, TV>(entries: Iterable<[TK, TV]>): Record<TK, TV>;
|
|
4915
|
+
|
|
3596
4916
|
/**
|
|
3597
4917
|
* A helper function to create a {@link Converter | Converter} which converts the `string`-keyed
|
|
3598
4918
|
* properties using a supplied {@link Converter | Converter<T, TC>} or {@link Validator | Validator<T>} to
|
|
@@ -3689,7 +5009,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3689
5009
|
* {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#the-result-pattern | result pattern}.
|
|
3690
5010
|
* @public
|
|
3691
5011
|
*/
|
|
3692
|
-
export declare class ResultMap<TK extends string = string, TV = unknown> implements
|
|
5012
|
+
export declare class ResultMap<TK extends string = string, TV = unknown> implements IResultMap<TK, TV> {
|
|
3693
5013
|
/**
|
|
3694
5014
|
* Protected raw access to the inner `Map<TK, TV>` object.
|
|
3695
5015
|
* @public
|
|
@@ -3871,35 +5191,35 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3871
5191
|
*/
|
|
3872
5192
|
constructor(params: IResultMapValidatorCreateParams<TK, TV>);
|
|
3873
5193
|
/**
|
|
3874
|
-
* {@
|
|
5194
|
+
* {@inheritDoc Collections.ResultMap.add}
|
|
3875
5195
|
*/
|
|
3876
5196
|
add(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail>;
|
|
3877
5197
|
/**
|
|
3878
|
-
* {@
|
|
5198
|
+
* {@inheritDoc Collections.ResultMap.delete}
|
|
3879
5199
|
*/
|
|
3880
5200
|
delete(key: string): DetailedResult<TV, ResultMapResultDetail>;
|
|
3881
5201
|
/**
|
|
3882
|
-
* {@
|
|
5202
|
+
* {@inheritDoc Collections.ResultMap.get}
|
|
3883
5203
|
*/
|
|
3884
5204
|
get(key: string): DetailedResult<TV, ResultMapResultDetail>;
|
|
3885
5205
|
/**
|
|
3886
|
-
* {@
|
|
5206
|
+
* {@inheritDoc Collections.ResultMap.getOrAdd}
|
|
3887
5207
|
*/
|
|
3888
5208
|
getOrAdd(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail>;
|
|
3889
5209
|
/**
|
|
3890
|
-
* {@
|
|
5210
|
+
* {@inheritDoc Collections.ResultMap.getOrAdd}
|
|
3891
5211
|
*/
|
|
3892
5212
|
getOrAdd(key: string, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;
|
|
3893
5213
|
/**
|
|
3894
|
-
* {@
|
|
5214
|
+
* {@inheritDoc Collections.ResultMap.has}
|
|
3895
5215
|
*/
|
|
3896
5216
|
has(key: string): boolean;
|
|
3897
5217
|
/**
|
|
3898
|
-
* {@
|
|
5218
|
+
* {@inheritDoc Collections.ResultMap.set}
|
|
3899
5219
|
*/
|
|
3900
5220
|
set(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail>;
|
|
3901
5221
|
/**
|
|
3902
|
-
* {@
|
|
5222
|
+
* {@inheritDoc Collections.ResultMap.update}
|
|
3903
5223
|
*/
|
|
3904
5224
|
update(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail>;
|
|
3905
5225
|
/**
|
|
@@ -3917,11 +5237,23 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3917
5237
|
}
|
|
3918
5238
|
|
|
3919
5239
|
/**
|
|
3920
|
-
* Deferred constructor for the {@link Collections.ResultMap.
|
|
5240
|
+
* Deferred constructor for the {@link Collections.ResultMap.getOrAdd | getOrAdd} method.
|
|
3921
5241
|
* @public
|
|
3922
5242
|
*/
|
|
3923
5243
|
declare type ResultMapValueFactory<TK extends string = string, TV = unknown> = (key: TK) => Result<TV>;
|
|
3924
5244
|
|
|
5245
|
+
/**
|
|
5246
|
+
* Type inference to determine the value type returned from a result-map style
|
|
5247
|
+
* `get` method.
|
|
5248
|
+
* @remarks
|
|
5249
|
+
* Useful for extracting collection entry types from maps whose `get` method
|
|
5250
|
+
* returns an {@link IResult}.
|
|
5251
|
+
* @beta
|
|
5252
|
+
*/
|
|
5253
|
+
export declare type ResultMapValueType<TCollection extends {
|
|
5254
|
+
get: (...args: readonly unknown[]) => unknown;
|
|
5255
|
+
}> = Exclude<IResultValueType<ReturnType<TCollection['get']>>, undefined>;
|
|
5256
|
+
|
|
3925
5257
|
/**
|
|
3926
5258
|
* Type inference to determine the result type of an {@link Result}.
|
|
3927
5259
|
* @beta
|
|
@@ -3973,13 +5305,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3973
5305
|
* @param optional - An array of `keyof T` containing keys to be considered optional.
|
|
3974
5306
|
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
|
|
3975
5307
|
* {@label WITH_KEYS}
|
|
3976
|
-
* @deprecated Use {@link Converters.
|
|
5308
|
+
* @deprecated Use {@link Converters.strictObject | Converters.strictObject(options)} instead.
|
|
3977
5309
|
* @public
|
|
3978
5310
|
*/
|
|
3979
5311
|
declare function strictObject<T, TC = unknown>(properties: FieldConverters<T, TC>, optional: (keyof T)[]): ObjectConverter<T, TC>;
|
|
3980
5312
|
|
|
3981
5313
|
/**
|
|
3982
|
-
* Options for the {@link
|
|
5314
|
+
* Options for the {@link strictObject} helper function.
|
|
3983
5315
|
* @public
|
|
3984
5316
|
*/
|
|
3985
5317
|
declare type StrictObjectConverterOptions<T> = Omit<ObjectConverterOptions<T>, 'strict'>;
|
|
@@ -4130,13 +5462,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4130
5462
|
export declare function succeed<T>(value: T): Success<T>;
|
|
4131
5463
|
|
|
4132
5464
|
/**
|
|
4133
|
-
* {@
|
|
5465
|
+
* {@inheritDoc succeed}
|
|
4134
5466
|
* @public
|
|
4135
5467
|
*/
|
|
4136
5468
|
export declare function succeeds<T>(value: T): Success<T>;
|
|
4137
5469
|
|
|
4138
5470
|
/**
|
|
4139
|
-
* {@
|
|
5471
|
+
* {@inheritDoc succeedWithDetail}
|
|
4140
5472
|
* @public
|
|
4141
5473
|
*/
|
|
4142
5474
|
export declare function succeedsWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
|
|
@@ -4163,7 +5495,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4163
5495
|
*/
|
|
4164
5496
|
export declare class Success<out T> implements IResult<T> {
|
|
4165
5497
|
/**
|
|
4166
|
-
* {@
|
|
5498
|
+
* {@inheritDoc IResult.success}
|
|
4167
5499
|
*/
|
|
4168
5500
|
readonly success: true;
|
|
4169
5501
|
/**
|
|
@@ -4184,65 +5516,65 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4184
5516
|
*/
|
|
4185
5517
|
get value(): T;
|
|
4186
5518
|
/**
|
|
4187
|
-
* {@
|
|
5519
|
+
* {@inheritDoc IResult.isSuccess}
|
|
4188
5520
|
*/
|
|
4189
5521
|
isSuccess(): this is Success<T>;
|
|
4190
5522
|
/**
|
|
4191
|
-
* {@
|
|
5523
|
+
* {@inheritDoc IResult.isFailure}
|
|
4192
5524
|
*/
|
|
4193
5525
|
isFailure(): this is Failure<T>;
|
|
4194
5526
|
/**
|
|
4195
|
-
* {@
|
|
5527
|
+
* {@inheritDoc IResult.orThrow}
|
|
4196
5528
|
*/
|
|
4197
5529
|
orThrow(logger?: IResultLogger): T;
|
|
4198
5530
|
/**
|
|
4199
|
-
* {@
|
|
5531
|
+
* {@inheritDoc IResult.orThrow}
|
|
4200
5532
|
*/
|
|
4201
5533
|
orThrow(cb: ErrorFormatter): T;
|
|
4202
5534
|
/**
|
|
4203
|
-
* {@
|
|
5535
|
+
* {@inheritDoc IResult.orDefault}
|
|
4204
5536
|
*/
|
|
4205
5537
|
orDefault(dflt: T): T;
|
|
4206
5538
|
/**
|
|
4207
|
-
* {@
|
|
5539
|
+
* {@inheritDoc IResult.orDefault}
|
|
4208
5540
|
*/
|
|
4209
5541
|
orDefault(): T | undefined;
|
|
4210
5542
|
/**
|
|
4211
|
-
* {@
|
|
4212
|
-
* @deprecated Use {@link Success.
|
|
5543
|
+
* {@inheritDoc IResult.getValueOrThrow}
|
|
5544
|
+
* @deprecated Use {@link Success.orThrow | orThrow(logger)} or {@link Success.orThrow | orThrow(formatter)} instead.
|
|
4213
5545
|
*/
|
|
4214
5546
|
getValueOrThrow(__logger?: IResultLogger): T;
|
|
4215
5547
|
/**
|
|
4216
|
-
* {@
|
|
4217
|
-
* @deprecated Use {@link Success.
|
|
5548
|
+
* {@inheritDoc IResult.getValueOrDefault}
|
|
5549
|
+
* @deprecated Use {@link Success.orDefault | orDefault(T)} or {@link Success.orDefault | orDefault()} instead.
|
|
4218
5550
|
*/
|
|
4219
5551
|
getValueOrDefault(dflt?: T): T | undefined;
|
|
4220
5552
|
/**
|
|
4221
|
-
* {@
|
|
5553
|
+
* {@inheritDoc IResult.onSuccess}
|
|
4222
5554
|
*/
|
|
4223
5555
|
onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;
|
|
4224
5556
|
/**
|
|
4225
|
-
* {@
|
|
5557
|
+
* {@inheritDoc IResult.onFailure}
|
|
4226
5558
|
*/
|
|
4227
5559
|
onFailure(__: FailureContinuation<T>): Result<T>;
|
|
4228
5560
|
/**
|
|
4229
|
-
* {@
|
|
5561
|
+
* {@inheritDoc IResult.withErrorFormat}
|
|
4230
5562
|
*/
|
|
4231
5563
|
withErrorFormat(__cb: ErrorFormatter): Result<T>;
|
|
4232
5564
|
/**
|
|
4233
|
-
* {@
|
|
5565
|
+
* {@inheritDoc IResult.withFailureDetail}
|
|
4234
5566
|
*/
|
|
4235
5567
|
withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD>;
|
|
4236
5568
|
/**
|
|
4237
|
-
* {@
|
|
5569
|
+
* {@inheritDoc IResult.withDetail}
|
|
4238
5570
|
*/
|
|
4239
5571
|
withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;
|
|
4240
5572
|
/**
|
|
4241
|
-
* {@
|
|
5573
|
+
* {@inheritDoc IResult.aggregateError}
|
|
4242
5574
|
*/
|
|
4243
5575
|
aggregateError(__errors: IMessageAggregator, __formatter?: ErrorFormatter): this;
|
|
4244
5576
|
/**
|
|
4245
|
-
* {@
|
|
5577
|
+
* {@inheritDoc IResult.report}
|
|
4246
5578
|
*/
|
|
4247
5579
|
report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Success<T>;
|
|
4248
5580
|
/**
|
|
@@ -4325,6 +5657,32 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4325
5657
|
description?: string;
|
|
4326
5658
|
}
|
|
4327
5659
|
|
|
5660
|
+
/**
|
|
5661
|
+
* Creates a {@link Converter | Converter} that converts an array to a strongly-typed tuple,
|
|
5662
|
+
* using the supplied tuple of {@link Converter | Converters} to convert each element.
|
|
5663
|
+
*
|
|
5664
|
+
* @remarks
|
|
5665
|
+
* The resulting {@link Converter | Converter} returns {@link Success | Success} with a tuple
|
|
5666
|
+
* containing the converted values if all conversions succeed. Returns {@link Failure | Failure}
|
|
5667
|
+
* with an error message if the source is not an array, has the wrong number of elements, or
|
|
5668
|
+
* any element conversion fails.
|
|
5669
|
+
*
|
|
5670
|
+
* @example
|
|
5671
|
+
* ```typescript
|
|
5672
|
+
* const converter = tuple([Converters.string, Converters.number, Converters.boolean]);
|
|
5673
|
+
* // Type is Converter<[string, number, boolean]>
|
|
5674
|
+
*
|
|
5675
|
+
* converter.convert(['hello', 42, true]);
|
|
5676
|
+
* // Returns Success with ['hello', 42, true]
|
|
5677
|
+
* ```
|
|
5678
|
+
*
|
|
5679
|
+
* @param converters - A tuple of {@link Converter | Converters} defining the expected types
|
|
5680
|
+
* for each element of the tuple.
|
|
5681
|
+
* @returns A {@link Converter | Converter} that returns a strongly-typed tuple.
|
|
5682
|
+
* @public
|
|
5683
|
+
*/
|
|
5684
|
+
declare function tuple<T extends readonly Converter<unknown, TC>[], TC = unknown>(converters: [...T]): Converter<ConverterResultTypes<T>, TC>;
|
|
5685
|
+
|
|
4328
5686
|
/**
|
|
4329
5687
|
* An in-place {@link Validation.Validator | Validator} that can be instantiated using a type guard
|
|
4330
5688
|
* function.
|
|
@@ -4390,11 +5748,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4390
5748
|
|
|
4391
5749
|
/**
|
|
4392
5750
|
* Helper function to create a {@link Converter | Converter} from any {@link Validation.Validator}
|
|
4393
|
-
* @param
|
|
5751
|
+
* @param converterOrValidator - the {@link Validation.Validator} to be wrapped or {@link Converter | Converter}
|
|
5752
|
+
* to be used directly.
|
|
4394
5753
|
* @returns A {@link Converter | Converter} which uses the supplied validator.
|
|
4395
5754
|
* @public
|
|
4396
5755
|
*/
|
|
4397
|
-
declare function validated<T, TC = unknown>(
|
|
5756
|
+
declare function validated<T, TC = unknown>(converterOrValidator: Validator<T, TC> | Converter<T, TC>): Converter<T, TC>;
|
|
4398
5757
|
|
|
4399
5758
|
/**
|
|
4400
5759
|
* Helper function to create a {@link Converter | Converter} which validates that a supplied value is
|
|
@@ -4477,6 +5836,64 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4477
5836
|
toReadOnly(): IReadOnlyValidatingCollector<TITEM>;
|
|
4478
5837
|
}
|
|
4479
5838
|
|
|
5839
|
+
/**
|
|
5840
|
+
* A result map that wraps an inner {@link Collections.IResultMap | IResultMap} of source type
|
|
5841
|
+
* and returns lazily-converted, cached values of a target type, with a
|
|
5842
|
+
* {@link Collections.ReadOnlyResultMapValidator | validating} property for weakly-typed access
|
|
5843
|
+
* and a {@link Collections.CacheInvalidatingResultMapWrapper | source} property for mutable access
|
|
5844
|
+
* to the underlying source map.
|
|
5845
|
+
* @public
|
|
5846
|
+
*/
|
|
5847
|
+
declare class ValidatingConvertingResultMap<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>> extends ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP> {
|
|
5848
|
+
/**
|
|
5849
|
+
* A validator for weakly-typed access to the map.
|
|
5850
|
+
*/
|
|
5851
|
+
readonly validating: ReadOnlyResultMapValidator<TK, TTARGET>;
|
|
5852
|
+
/**
|
|
5853
|
+
* The key-value converters used for validation.
|
|
5854
|
+
*/
|
|
5855
|
+
protected readonly _converters: KeyValueConverters<TK, TTARGET>;
|
|
5856
|
+
/**
|
|
5857
|
+
* Constructs a new {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.
|
|
5858
|
+
* @param params - Parameters for constructing the map.
|
|
5859
|
+
*/
|
|
5860
|
+
constructor(params: IValidatingConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>);
|
|
5861
|
+
/**
|
|
5862
|
+
* Creates a new {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.
|
|
5863
|
+
* @param params - Parameters for constructing the map.
|
|
5864
|
+
* @returns `Success` with the new map, or `Failure` with error details if an error occurred.
|
|
5865
|
+
*/
|
|
5866
|
+
static create<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>>(params: IValidatingConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>): Result<ValidatingConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>>;
|
|
5867
|
+
}
|
|
5868
|
+
|
|
5869
|
+
/**
|
|
5870
|
+
* A read-only result map that wraps an inner {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}
|
|
5871
|
+
* of source type and returns lazily-converted, cached values of a target type, with a
|
|
5872
|
+
* {@link Collections.ReadOnlyResultMapValidator | validating} property for weakly-typed access.
|
|
5873
|
+
* @public
|
|
5874
|
+
*/
|
|
5875
|
+
declare class ValidatingReadOnlyConvertingResultMap<TK extends string, TSRC, TTARGET> extends ReadOnlyConvertingResultMap<TK, TSRC, TTARGET> {
|
|
5876
|
+
/**
|
|
5877
|
+
* A validator for weakly-typed access to the map.
|
|
5878
|
+
*/
|
|
5879
|
+
readonly validating: ReadOnlyResultMapValidator<TK, TTARGET>;
|
|
5880
|
+
/**
|
|
5881
|
+
* The key-value converters used for validation.
|
|
5882
|
+
*/
|
|
5883
|
+
protected readonly _converters: KeyValueConverters<TK, TTARGET>;
|
|
5884
|
+
/**
|
|
5885
|
+
* Constructs a new {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.
|
|
5886
|
+
* @param params - Parameters for constructing the map.
|
|
5887
|
+
*/
|
|
5888
|
+
constructor(params: IValidatingReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>);
|
|
5889
|
+
/**
|
|
5890
|
+
* Creates a new {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.
|
|
5891
|
+
* @param params - Parameters for constructing the map.
|
|
5892
|
+
* @returns `Success` with the new map, or `Failure` with error details if an error occurred.
|
|
5893
|
+
*/
|
|
5894
|
+
static create<TK extends string, TSRC, TTARGET>(params: IValidatingReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>): Result<ValidatingReadOnlyConvertingResultMap<TK, TSRC, TTARGET>>;
|
|
5895
|
+
}
|
|
5896
|
+
|
|
4480
5897
|
/**
|
|
4481
5898
|
* A {@link Collections.ResultMap | ResultMap} with a {@link Collections.ResultMapValidator | validator}
|
|
4482
5899
|
* property that enables validated use of the underlying map with weakly-typed keys and values.
|
|
@@ -4616,6 +6033,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4616
6033
|
* @returns A new {@link Validation.Validator | Validator}.
|
|
4617
6034
|
*/
|
|
4618
6035
|
withFormattedError(formatter: ValidationErrorFormatter<TC>): Validator<T, TC>;
|
|
6036
|
+
/**
|
|
6037
|
+
* Chains this validator with another of the same type, to be attempted if this
|
|
6038
|
+
* validator fails.
|
|
6039
|
+
* @param other - The other {@link Validation.Validator | Validator} to be attempted
|
|
6040
|
+
* if this one fails.
|
|
6041
|
+
*/
|
|
6042
|
+
or(other: Validator<T, TC>): Validator<T, TC>;
|
|
4619
6043
|
}
|
|
4620
6044
|
|
|
4621
6045
|
/**
|
|
@@ -4669,6 +6093,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4669
6093
|
recordOf_2 as recordOf,
|
|
4670
6094
|
enumeratedValue_2 as enumeratedValue,
|
|
4671
6095
|
literal_2 as literal,
|
|
6096
|
+
compositeId_2 as compositeId,
|
|
4672
6097
|
oneOf_2 as oneOf,
|
|
4673
6098
|
isA_2 as isA,
|
|
4674
6099
|
generic_2 as generic,
|
|
@@ -4686,15 +6111,15 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4686
6111
|
*/
|
|
4687
6112
|
declare class ValidatorTraits implements ValidatorTraitValues {
|
|
4688
6113
|
/**
|
|
4689
|
-
* {@
|
|
6114
|
+
* {@inheritDoc Validation.ValidatorTraitValues.isOptional}
|
|
4690
6115
|
*/
|
|
4691
6116
|
readonly isOptional: boolean;
|
|
4692
6117
|
/**
|
|
4693
|
-
* {@
|
|
6118
|
+
* {@inheritDoc Validation.ValidatorTraitValues.brand}
|
|
4694
6119
|
*/
|
|
4695
6120
|
readonly brand?: string;
|
|
4696
6121
|
/**
|
|
4697
|
-
* {@
|
|
6122
|
+
* {@inheritDoc Validation.ValidatorTraitValues.constraints}
|
|
4698
6123
|
*/
|
|
4699
6124
|
readonly constraints: ConstraintTrait[];
|
|
4700
6125
|
/**
|
|
@@ -4738,4 +6163,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4738
6163
|
*/
|
|
4739
6164
|
declare const value: typeof literal;
|
|
4740
6165
|
|
|
6166
|
+
/**
|
|
6167
|
+
* Type-safe(ish) value extractor for typed records.
|
|
6168
|
+
* @param obj - The record from which values are to be extracted.
|
|
6169
|
+
* @returns The values of the record as an array.
|
|
6170
|
+
* @public
|
|
6171
|
+
*/
|
|
6172
|
+
export declare function valuesForRecord<TK extends string, TV>(obj: Record<TK, TV>): TV[];
|
|
6173
|
+
|
|
4741
6174
|
export { }
|