@fgv/ts-utils 5.0.2 → 5.1.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +27 -27
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { DetailedResult, Result } from '../base';
|
|
2
|
+
import { Converter } from '../conversion';
|
|
3
|
+
import { Validator } from '../validation';
|
|
4
|
+
import { KeyValueEntry } from './common';
|
|
5
|
+
import { KeyValueConverters } from './keyValueConverters';
|
|
6
|
+
import { IReadOnlyResultMapValidator } from './resultMapValidator';
|
|
7
|
+
import { IReadOnlyResultMap, ResultMapForEachCb, ResultMapResultDetail } from './readonlyResultMap';
|
|
8
|
+
import { IResultMap, ResultMapValueFactory } from './resultMap';
|
|
9
|
+
import { IReadOnlyValidatingResultMap, ValidatingResultMap } from './validatingResultMap';
|
|
10
|
+
/**
|
|
11
|
+
* A read-only collection entry in an {@link AggregatedResultMap | aggregated result map}.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export interface IReadonlyAggregatedResultMapEntry<TCOLLECTIONID extends string = string, TITEMID extends string = string, TITEM = unknown, TMETADATA = unknown> {
|
|
15
|
+
readonly isMutable: false;
|
|
16
|
+
readonly id: TCOLLECTIONID;
|
|
17
|
+
readonly items: IReadOnlyValidatingResultMap<TITEMID, TITEM>;
|
|
18
|
+
readonly metadata?: TMETADATA;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A mutable collection entry in an {@link AggregatedResultMap | aggregated result map}.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export interface IMutableAggregatedResultMapEntry<TCOLLECTIONID extends string = string, TITEMID extends string = string, TITEM = unknown, TMETADATA = unknown> {
|
|
25
|
+
readonly isMutable: true;
|
|
26
|
+
readonly id: TCOLLECTIONID;
|
|
27
|
+
readonly items: ValidatingResultMap<TITEMID, TITEM>;
|
|
28
|
+
metadata?: TMETADATA;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A collection entry in an {@link AggregatedResultMap | aggregated result map}, either mutable or read-only.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export type AggregatedResultMapEntry<TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> = IReadonlyAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA> | IMutableAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>;
|
|
35
|
+
/**
|
|
36
|
+
* JSON format for an {@link AggregatedResultMap | aggregated result map} collection entry using an entries array.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export interface IAggregatedResultMapJsonEntryWithEntries<TCOLLECTIONID extends string = string> {
|
|
40
|
+
readonly isMutable: boolean;
|
|
41
|
+
readonly id: TCOLLECTIONID;
|
|
42
|
+
readonly entries: ReadonlyArray<KeyValueEntry<string, unknown>>;
|
|
43
|
+
readonly metadata?: unknown;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* JSON format for an {@link AggregatedResultMap | aggregated result map} collection entry using a string-keyed items object.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export interface IAggregatedResultMapJsonEntryWithItems<TCOLLECTIONID extends string = string> {
|
|
50
|
+
readonly isMutable: boolean;
|
|
51
|
+
readonly id: TCOLLECTIONID;
|
|
52
|
+
readonly items: Record<string, unknown>;
|
|
53
|
+
readonly metadata?: unknown;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* JSON format for an {@link AggregatedResultMap | aggregated result map} collection entry - supports both entries array and items object.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export type AggregatedResultMapJsonEntry<TCOLLECTIONID extends string = string> = IAggregatedResultMapJsonEntryWithEntries<TCOLLECTIONID> | IAggregatedResultMapJsonEntryWithItems<TCOLLECTIONID>;
|
|
60
|
+
/**
|
|
61
|
+
* Any valid input format for an {@link AggregatedResultMap | aggregated result map} collection entry.
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export type AggregatedResultMapEntryInit<TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> = AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA> | AggregatedResultMapJsonEntry<TCOLLECTIONID>;
|
|
65
|
+
/**
|
|
66
|
+
* Options for {@link Collections.AggregatedResultMapBase.addCollectionWithItems | addCollectionWithItems}.
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export interface IAddCollectionWithItemsOptions<TMETADATA = unknown> {
|
|
70
|
+
/**
|
|
71
|
+
* If true, the collection will be immutable (read-only).
|
|
72
|
+
* Defaults to false (mutable).
|
|
73
|
+
*/
|
|
74
|
+
readonly isImmutable?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Optional metadata to attach to the collection.
|
|
77
|
+
*/
|
|
78
|
+
readonly metadata?: TMETADATA;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Parameters for constructing an {@link AggregatedResultMap | aggregated result map}.
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export interface IAggregatedResultMapConstructorParams<TCOMPOSITEID extends string, TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> {
|
|
85
|
+
/**
|
|
86
|
+
* Validator for composite IDs.
|
|
87
|
+
*/
|
|
88
|
+
readonly compositeIdValidator?: Validator<TCOMPOSITEID, unknown>;
|
|
89
|
+
/**
|
|
90
|
+
* Converter or validator for collection IDs.
|
|
91
|
+
*/
|
|
92
|
+
readonly collectionIdConverter: Converter<TCOLLECTIONID, unknown> | Validator<TCOLLECTIONID, unknown>;
|
|
93
|
+
/**
|
|
94
|
+
* Converter or validator for item IDs.
|
|
95
|
+
*/
|
|
96
|
+
readonly itemIdConverter: Converter<TITEMID, unknown> | Validator<TITEMID, unknown>;
|
|
97
|
+
/**
|
|
98
|
+
* Converter or validator for individual items in each collection.
|
|
99
|
+
*/
|
|
100
|
+
readonly itemConverter: Converter<TITEM, unknown> | Validator<TITEM, unknown>;
|
|
101
|
+
/**
|
|
102
|
+
* Optional converter or validator for collection metadata. If not provided, a metadata field
|
|
103
|
+
* in the input will cause a validation failure.
|
|
104
|
+
*/
|
|
105
|
+
readonly metadataConverter?: Converter<TMETADATA, unknown> | Validator<TMETADATA, unknown>;
|
|
106
|
+
/**
|
|
107
|
+
* Optional separator string for composite IDs. Defaults to `.`.
|
|
108
|
+
*/
|
|
109
|
+
readonly separator?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Initial collections to populate the map.
|
|
112
|
+
* @remarks Each entry may be mutable or read-only.
|
|
113
|
+
*/
|
|
114
|
+
readonly collections?: ReadonlyArray<AggregatedResultMapEntryInit<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A validator for weakly-typed access to an {@link AggregatedResultMap | aggregated result map}.
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
export declare class AggregatedResultMapValidator<TCOMPOSITEID extends string, TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> implements IReadOnlyResultMapValidator<TCOMPOSITEID, TITEM> {
|
|
121
|
+
private readonly _map;
|
|
122
|
+
/**
|
|
123
|
+
* The key-value converters used for validating weakly-typed access.
|
|
124
|
+
*/
|
|
125
|
+
readonly converters: KeyValueConverters<TCOMPOSITEID, TITEM>;
|
|
126
|
+
/**
|
|
127
|
+
* Constructs a new {@link AggregatedResultMapValidator | aggregated result map validator}.
|
|
128
|
+
* @param map - The {@link AggregatedResultMap | aggregated result map} being validated.
|
|
129
|
+
* @param converters - The key-value converters for weakly-typed access.
|
|
130
|
+
*/
|
|
131
|
+
constructor(map: AggregatedResultMap<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, converters: KeyValueConverters<TCOMPOSITEID, TITEM>);
|
|
132
|
+
/** {@inheritDoc Collections.ResultMapValidator.map} */
|
|
133
|
+
get map(): IReadOnlyValidatingResultMap<TCOMPOSITEID, TITEM>;
|
|
134
|
+
/** {@inheritDoc Collections.ResultMapValidator.get} */
|
|
135
|
+
get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
136
|
+
/** {@inheritDoc Collections.ResultMapValidator.has} */
|
|
137
|
+
has(key: string): boolean;
|
|
138
|
+
/** {@inheritDoc Collections.ResultMapValidator.add} */
|
|
139
|
+
add(key: string, value: unknown): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
140
|
+
/** {@inheritDoc Collections.ResultMapValidator.set} */
|
|
141
|
+
set(key: string, value: unknown): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
142
|
+
/** {@inheritDoc Collections.ResultMapValidator.update} */
|
|
143
|
+
update(key: string, value: unknown): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
144
|
+
/** {@inheritDoc Collections.ResultMapValidator.delete} */
|
|
145
|
+
delete(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Base class for an aggregated result map that wraps a collection of {@link ValidatingResultMap} instances,
|
|
149
|
+
* keyed by collection ID. Items are accessed via composite IDs that combine the collection ID
|
|
150
|
+
* and item ID with a delimiter.
|
|
151
|
+
* @remarks Consumers should inherit from this class or use {@link AggregatedResultMap | AggregatedResultMap}
|
|
152
|
+
* for fully generic.
|
|
153
|
+
* @public
|
|
154
|
+
*/
|
|
155
|
+
export declare class AggregatedResultMapBase<TCOMPOSITEID extends string, TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> implements IResultMap<TCOMPOSITEID, TITEM>, IReadOnlyValidatingResultMap<TCOMPOSITEID, TITEM> {
|
|
156
|
+
private readonly _childKvConverters;
|
|
157
|
+
private readonly _collections;
|
|
158
|
+
private readonly _collectionKvConverters;
|
|
159
|
+
private readonly _compositeIdValidator;
|
|
160
|
+
private readonly _collectionIdConverter;
|
|
161
|
+
private readonly _itemIdConverter;
|
|
162
|
+
private readonly _itemConverter;
|
|
163
|
+
private readonly _metadataConverter?;
|
|
164
|
+
private readonly _delimiter;
|
|
165
|
+
private readonly _compositeIdConverter;
|
|
166
|
+
private readonly _kvConverters;
|
|
167
|
+
private readonly _validating;
|
|
168
|
+
/**
|
|
169
|
+
* Protected constructor for derived classes.
|
|
170
|
+
* Use the {@link AggregatedResultMap.create | create static method} for safe construction with error handling.
|
|
171
|
+
* @param params - {@link IAggregatedResultMapConstructorParams | Parameters} for constructing the map.
|
|
172
|
+
* @throws If initialization fails (e.g., invalid collections).
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
protected constructor(params: IAggregatedResultMapConstructorParams<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>);
|
|
176
|
+
/**
|
|
177
|
+
* A validator for weakly-typed access to the map.
|
|
178
|
+
*/
|
|
179
|
+
get validating(): IReadOnlyResultMapValidator<TCOMPOSITEID, TITEM>;
|
|
180
|
+
/**
|
|
181
|
+
* The total number of items across all collections.
|
|
182
|
+
*/
|
|
183
|
+
get size(): number;
|
|
184
|
+
/**
|
|
185
|
+
* Gets an item by its composite ID.
|
|
186
|
+
* @param key - The composite ID of the item.
|
|
187
|
+
* @returns `Success` with the item if found, `Failure` otherwise.
|
|
188
|
+
*/
|
|
189
|
+
get(key: TCOMPOSITEID): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
190
|
+
/**
|
|
191
|
+
* Checks if an item exists by its composite ID.
|
|
192
|
+
* @param key - The composite ID of the item.
|
|
193
|
+
* @returns `true` if the item exists, `false` otherwise.
|
|
194
|
+
*/
|
|
195
|
+
has(key: TCOMPOSITEID): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Iterates over all entries in all collections.
|
|
198
|
+
*/
|
|
199
|
+
entries(): IterableIterator<KeyValueEntry<TCOMPOSITEID, TITEM>>;
|
|
200
|
+
/**
|
|
201
|
+
* Iterates over all composite keys.
|
|
202
|
+
*/
|
|
203
|
+
keys(): IterableIterator<TCOMPOSITEID>;
|
|
204
|
+
/**
|
|
205
|
+
* Iterates over all values.
|
|
206
|
+
*/
|
|
207
|
+
values(): IterableIterator<TITEM>;
|
|
208
|
+
/**
|
|
209
|
+
* Calls a callback for each entry.
|
|
210
|
+
* @param cb - The callback to call.
|
|
211
|
+
* @param thisArg - Optional `this` argument for the callback.
|
|
212
|
+
*/
|
|
213
|
+
forEach(cb: ResultMapForEachCb<TCOMPOSITEID, TITEM>, thisArg?: unknown): void;
|
|
214
|
+
/**
|
|
215
|
+
* Gets an iterator over the map entries.
|
|
216
|
+
*/
|
|
217
|
+
[Symbol.iterator](): IterableIterator<KeyValueEntry<TCOMPOSITEID, TITEM>>;
|
|
218
|
+
/**
|
|
219
|
+
* Sets an item by its composite ID. Creates the collection if it doesn't exist and is mutable.
|
|
220
|
+
* @param key - The composite ID of the item.
|
|
221
|
+
* @param value - The value to set.
|
|
222
|
+
* @returns `Success` with the value if set, `Failure` otherwise.
|
|
223
|
+
*/
|
|
224
|
+
set(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
225
|
+
/**
|
|
226
|
+
* Adds an item by its composite ID. Fails if the item already exists.
|
|
227
|
+
* @param key - The composite ID of the item.
|
|
228
|
+
* @param value - The value to add.
|
|
229
|
+
* @returns `Success` with the value if added, `Failure` otherwise.
|
|
230
|
+
*/
|
|
231
|
+
add(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
232
|
+
/**
|
|
233
|
+
* Updates an existing item by its composite ID. Fails if the item doesn't exist.
|
|
234
|
+
* @param key - The composite ID of the item.
|
|
235
|
+
* @param value - The new value.
|
|
236
|
+
* @returns `Success` with the value if updated, `Failure` otherwise.
|
|
237
|
+
*/
|
|
238
|
+
update(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
239
|
+
/**
|
|
240
|
+
* Deletes an item by its composite ID.
|
|
241
|
+
* @param key - The composite ID of the item.
|
|
242
|
+
* @returns `Success` with the deleted value, `Failure` otherwise.
|
|
243
|
+
*/
|
|
244
|
+
delete(key: TCOMPOSITEID): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
245
|
+
/**
|
|
246
|
+
* Gets an existing item or adds a new one.
|
|
247
|
+
* @param key - The composite ID of the item.
|
|
248
|
+
* @param value - The value to add if not found.
|
|
249
|
+
* @returns `Success` with the existing or new value.
|
|
250
|
+
*/
|
|
251
|
+
getOrAdd(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
252
|
+
/**
|
|
253
|
+
* Gets an existing item or adds a new one using a factory.
|
|
254
|
+
* @param key - The composite ID of the item.
|
|
255
|
+
* @param factory - A factory function to create the value if not found. Receives the composite ID.
|
|
256
|
+
* @returns `Success` with the existing or new value.
|
|
257
|
+
*/
|
|
258
|
+
getOrAdd(key: TCOMPOSITEID, factory: ResultMapValueFactory<TCOMPOSITEID, TITEM>): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
259
|
+
/**
|
|
260
|
+
* Clears all items from all mutable collections.
|
|
261
|
+
* Immutable collections are not affected.
|
|
262
|
+
*/
|
|
263
|
+
clear(): void;
|
|
264
|
+
/**
|
|
265
|
+
* Returns a read-only view of this map.
|
|
266
|
+
*/
|
|
267
|
+
toReadOnly(): IReadOnlyResultMap<TCOMPOSITEID, TITEM>;
|
|
268
|
+
/**
|
|
269
|
+
* Composes a collection ID and item ID into a composite ID.
|
|
270
|
+
* @param collectionId - The collection ID.
|
|
271
|
+
* @param itemId - The item ID.
|
|
272
|
+
* @returns `Success` with the composite ID if valid, `Failure` otherwise.
|
|
273
|
+
*/
|
|
274
|
+
composeId(collectionId: TCOLLECTIONID, itemId: TITEMID): Result<TCOMPOSITEID>;
|
|
275
|
+
/**
|
|
276
|
+
* Adds an item using separate collection and item IDs.
|
|
277
|
+
* @param collectionId - The collection ID.
|
|
278
|
+
* @param itemId - The item ID.
|
|
279
|
+
* @param value - The value to add.
|
|
280
|
+
* @returns `Success` with the composite ID if added, `Failure` otherwise.
|
|
281
|
+
*/
|
|
282
|
+
addToCollection(collectionId: TCOLLECTIONID, itemId: TITEMID, value: TITEM): DetailedResult<TCOMPOSITEID, ResultMapResultDetail>;
|
|
283
|
+
/**
|
|
284
|
+
* Sets an item using separate collection and item IDs.
|
|
285
|
+
* @param collectionId - The collection ID.
|
|
286
|
+
* @param itemId - The item ID.
|
|
287
|
+
* @param value - The value to set.
|
|
288
|
+
* @returns `Success` with the composite ID if set, `Failure` otherwise.
|
|
289
|
+
*/
|
|
290
|
+
setInCollection(collectionId: TCOLLECTIONID, itemId: TITEMID, value: TITEM): DetailedResult<TCOMPOSITEID, ResultMapResultDetail>;
|
|
291
|
+
/**
|
|
292
|
+
* Updates an item using separate collection and item IDs.
|
|
293
|
+
* @param collectionId - The collection ID.
|
|
294
|
+
* @param itemId - The item ID.
|
|
295
|
+
* @param value - The new value.
|
|
296
|
+
* @returns `Success` with the composite ID if updated, `Failure` otherwise.
|
|
297
|
+
*/
|
|
298
|
+
updateInCollection(collectionId: TCOLLECTIONID, itemId: TITEMID, value: TITEM): DetailedResult<TCOMPOSITEID, ResultMapResultDetail>;
|
|
299
|
+
/**
|
|
300
|
+
* Deletes an item using separate collection and item IDs.
|
|
301
|
+
* @param collectionId - The collection ID.
|
|
302
|
+
* @param itemId - The item ID.
|
|
303
|
+
* @returns `Success` with the composite ID if deleted, `Failure` otherwise.
|
|
304
|
+
*/
|
|
305
|
+
deleteFromCollection(collectionId: TCOLLECTIONID, itemId: TITEMID): DetailedResult<TCOMPOSITEID, ResultMapResultDetail>;
|
|
306
|
+
/**
|
|
307
|
+
* Provides read-only access to the underlying collections map.
|
|
308
|
+
* Use `collections.has(id)` and `collections.get(id)` to check existence and retrieve collections.
|
|
309
|
+
*/
|
|
310
|
+
get collections(): IReadOnlyValidatingResultMap<TCOLLECTIONID, AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>>;
|
|
311
|
+
/**
|
|
312
|
+
* The number of collections.
|
|
313
|
+
*/
|
|
314
|
+
get collectionCount(): number;
|
|
315
|
+
/**
|
|
316
|
+
* Gets the metadata for a specific collection.
|
|
317
|
+
* @param collectionId - The collection ID.
|
|
318
|
+
* @returns `Success` with the metadata if found, `Failure` otherwise.
|
|
319
|
+
*/
|
|
320
|
+
getCollectionMetadata(collectionId: TCOLLECTIONID): Result<TMETADATA | undefined>;
|
|
321
|
+
/**
|
|
322
|
+
* Sets the metadata for a mutable collection.
|
|
323
|
+
* @param collectionId - The collection ID.
|
|
324
|
+
* @param metadata - The metadata to set.
|
|
325
|
+
* @returns `Success` if set, `Failure` otherwise.
|
|
326
|
+
*/
|
|
327
|
+
setCollectionMetadata(collectionId: TCOLLECTIONID, metadata: TMETADATA): Result<TMETADATA>;
|
|
328
|
+
/**
|
|
329
|
+
* Adds a new collection from a pre-built entry object.
|
|
330
|
+
* @param entry - The collection entry to add (JSON with items/entries, or pre-instantiated).
|
|
331
|
+
* @returns `Success` with the entry if added, `Failure` otherwise.
|
|
332
|
+
*/
|
|
333
|
+
addCollectionEntry(entry: AggregatedResultMapEntryInit<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>): DetailedResult<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, ResultMapResultDetail>;
|
|
334
|
+
/**
|
|
335
|
+
* Adds a new collection with the specified ID and optional initial entries.
|
|
336
|
+
* @param collectionId - The collection ID as a string (will be validated).
|
|
337
|
+
* @param items - Optional initial entries for the collection.
|
|
338
|
+
* @param options - Optional settings (isImmutable defaults to false).
|
|
339
|
+
* @returns `Success` with the validated collection ID if added, `Failure` otherwise.
|
|
340
|
+
*/
|
|
341
|
+
addCollectionWithItems(collectionId: string, items?: Iterable<KeyValueEntry<string, unknown>>, options?: IAddCollectionWithItemsOptions<TMETADATA>): Result<TCOLLECTIONID>;
|
|
342
|
+
/**
|
|
343
|
+
* Deletes a collection from the internal collections map.
|
|
344
|
+
* This is a protected method for use by derived classes that need to implement
|
|
345
|
+
* collection deletion functionality.
|
|
346
|
+
*
|
|
347
|
+
* @param collectionId - The collection ID to delete.
|
|
348
|
+
* @returns `Success` with the deleted entry if found, `Failure` otherwise.
|
|
349
|
+
* @remarks
|
|
350
|
+
* - Does NOT check if the collection is mutable - callers should validate this first.
|
|
351
|
+
* - Use `collections.get(id)` to check if a collection exists and its mutability before calling.
|
|
352
|
+
*/
|
|
353
|
+
protected _deleteCollection(collectionId: TCOLLECTIONID): DetailedResult<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, ResultMapResultDetail>;
|
|
354
|
+
/**
|
|
355
|
+
* Type guard to check if a value is a factory function.
|
|
356
|
+
*/
|
|
357
|
+
private _isFactory;
|
|
358
|
+
private _splitCompositeId;
|
|
359
|
+
private _splitAndLookup;
|
|
360
|
+
private _splitAndLookupMutable;
|
|
361
|
+
/**
|
|
362
|
+
* Gets an existing mutable collection by ID.
|
|
363
|
+
* Returns failure if the collection doesn't exist or is immutable.
|
|
364
|
+
*/
|
|
365
|
+
private _getMutableCollection;
|
|
366
|
+
/**
|
|
367
|
+
* Gets an existing mutable collection or creates a new one.
|
|
368
|
+
*/
|
|
369
|
+
private _getOrCreateMutableCollection;
|
|
370
|
+
/**
|
|
371
|
+
* Constructs a composite id validator using other converters/validators and separator supplied in params.
|
|
372
|
+
* @param params - Constructor params.
|
|
373
|
+
* @returns The composite ID validator.
|
|
374
|
+
*/
|
|
375
|
+
private static _compositeIdValidator;
|
|
376
|
+
/**
|
|
377
|
+
* Converts metadata from source, failing fast if metadata is present but no converter is configured.
|
|
378
|
+
* @param sourceMetadata - The metadata from the source (may be undefined).
|
|
379
|
+
* @param metadataConverter - Optional converter for metadata.
|
|
380
|
+
* @returns Success with converted metadata (or undefined), or Failure if metadata is present but disallowed.
|
|
381
|
+
*/
|
|
382
|
+
private static _convertMetadata;
|
|
383
|
+
/**
|
|
384
|
+
* Extracts metadata from a source object if present.
|
|
385
|
+
*/
|
|
386
|
+
private static _extractSourceMetadata;
|
|
387
|
+
/**
|
|
388
|
+
* Creates a converter for pre-instantiated mutable entries.
|
|
389
|
+
* These are entries that already have a ValidatingResultMap as their items property.
|
|
390
|
+
*/
|
|
391
|
+
private static _instantiatedMutableConverter;
|
|
392
|
+
/**
|
|
393
|
+
* Creates a converter for pre-instantiated read-only entries.
|
|
394
|
+
* These are entries that already have an IReadOnlyValidatingResultMap as their items property.
|
|
395
|
+
*/
|
|
396
|
+
private static _instantiatedReadonlyConverter;
|
|
397
|
+
/**
|
|
398
|
+
* Creates a converter for JSON entries with an entries array.
|
|
399
|
+
* Converts the entries array to a ValidatingResultMap.
|
|
400
|
+
*/
|
|
401
|
+
private static _jsonWithEntriesConverter;
|
|
402
|
+
/**
|
|
403
|
+
* Creates a converter for JSON entries with an items object.
|
|
404
|
+
* Converts the items object to a ValidatingResultMap.
|
|
405
|
+
*/
|
|
406
|
+
private static _jsonWithItemsConverter;
|
|
407
|
+
/**
|
|
408
|
+
* Creates a unified entry converter that handles all entry formats.
|
|
409
|
+
* Tries each format in order: instantiated mutable, instantiated readonly,
|
|
410
|
+
* JSON with entries array, JSON with items object.
|
|
411
|
+
*/
|
|
412
|
+
private static _entryConverter;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* An aggregated result map that wraps a collection of {@link ValidatingResultMap | ValidatingResultMap} instances,
|
|
416
|
+
* keyed by collection ID. Items are accessed via composite IDs that combine the collection ID
|
|
417
|
+
* and item ID with a delimiter.
|
|
418
|
+
* @public
|
|
419
|
+
*/
|
|
420
|
+
export declare class AggregatedResultMap<TCOMPOSITEID extends string, TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA = unknown> extends AggregatedResultMapBase<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA> {
|
|
421
|
+
/**
|
|
422
|
+
* Constructs a new {@link AggregatedResultMap | AggregatedResultMap}.
|
|
423
|
+
* @param params -
|
|
424
|
+
*/
|
|
425
|
+
constructor(params: IAggregatedResultMapConstructorParams<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>);
|
|
426
|
+
/**
|
|
427
|
+
* Creates a new {@link AggregatedResultMap | AggregatedResultMap}.
|
|
428
|
+
* @param params - Parameters for constructing the map.
|
|
429
|
+
* @returns `Success` with the new map if successful, `Failure` otherwise.
|
|
430
|
+
*/
|
|
431
|
+
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>>;
|
|
432
|
+
}
|
|
433
|
+
//# sourceMappingURL=aggregatedResultMap.d.ts.map
|