@fgv/ts-utils 5.1.0-15 → 5.1.0-17
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/dist/packlets/collections/collector.js +23 -9
- package/dist/packlets/collections/collectorValidator.js +6 -1
- package/dist/packlets/conversion/baseConverter.js +102 -16
- package/dist/packlets/logging/logger.js +33 -8
- package/dist/ts-utils.d.ts +257 -55
- package/lib/packlets/collections/collector.d.ts +23 -9
- package/lib/packlets/collections/collector.js +23 -9
- package/lib/packlets/collections/collectorValidator.d.ts +29 -5
- package/lib/packlets/collections/collectorValidator.js +6 -1
- package/lib/packlets/collections/convertingCollector.d.ts +21 -3
- package/lib/packlets/collections/convertingCollectorValidator.d.ts +22 -3
- package/lib/packlets/collections/readonlyResultMap.d.ts +18 -7
- package/lib/packlets/collections/validatingCollector.d.ts +7 -3
- package/lib/packlets/collections/validatingResultMap.d.ts +2 -1
- package/lib/packlets/conversion/baseConverter.d.ts +102 -16
- package/lib/packlets/conversion/baseConverter.js +102 -16
- package/lib/packlets/logging/logger.d.ts +33 -8
- package/lib/packlets/logging/logger.js +33 -8
- package/lib/packlets/validation/validatorBase.d.ts +2 -1
- package/package.json +3 -3
package/dist/ts-utils.d.ts
CHANGED
|
@@ -579,63 +579,146 @@ declare class BaseConverter<T, TC = unknown> implements Converter<T, TC> {
|
|
|
579
579
|
*/
|
|
580
580
|
constructor(converter: ConverterFunc<T, TC>, defaultContext?: TC, traits?: ConverterTraits);
|
|
581
581
|
/**
|
|
582
|
-
*
|
|
582
|
+
* Indicates whether this element is explicitly optional.
|
|
583
583
|
*/
|
|
584
584
|
get isOptional(): boolean;
|
|
585
585
|
/**
|
|
586
|
-
*
|
|
586
|
+
* Returns the brand for a branded type.
|
|
587
587
|
*/
|
|
588
588
|
get brand(): string | undefined;
|
|
589
589
|
/**
|
|
590
|
-
*
|
|
590
|
+
* Converts from `unknown` to `<T>`. For objects and arrays, is guaranteed
|
|
591
|
+
* to return a new entity, with any unrecognized properties removed.
|
|
592
|
+
* @param from - The `unknown` to be converted
|
|
593
|
+
* @param context - An optional conversion context of type `<TC>` to be used in
|
|
594
|
+
* the conversion.
|
|
595
|
+
* @returns A {@link Result} with a {@link Success} and a value on success or an
|
|
596
|
+
* {@link Failure} with a a message on failure.
|
|
591
597
|
*/
|
|
592
598
|
convert(from: unknown, context?: TC): Result<T>;
|
|
593
599
|
/**
|
|
594
|
-
*
|
|
600
|
+
* Converts from `unknown` to `<T>` or `undefined`, as appropriate.
|
|
601
|
+
*
|
|
602
|
+
* @remarks
|
|
603
|
+
* If `onError` is `failOnError`, the converter succeeds for
|
|
604
|
+
* `undefined` or any convertible value, but reports an error
|
|
605
|
+
* if it encounters a value that cannot be converted.
|
|
606
|
+
*
|
|
607
|
+
* If `onError` is `ignoreErrors` (default) then values that
|
|
608
|
+
* cannot be converted result in a successful return of `undefined`.
|
|
609
|
+
* @param from - The `unknown` to be converted
|
|
610
|
+
* @param context - An optional conversion context of type `<TC>` to be used in
|
|
611
|
+
* the conversion.
|
|
612
|
+
* @param onError - Specifies handling of values that cannot be converted (default `ignoreErrors`).
|
|
613
|
+
* @returns A {@link Result} with a {@link Success} and a value on success or an
|
|
614
|
+
* {@link Failure} with a a message on failure.
|
|
595
615
|
*/
|
|
596
616
|
convertOptional(from: unknown, context?: TC, onError?: OnError): Result<T | undefined>;
|
|
597
617
|
/**
|
|
598
|
-
* {@
|
|
618
|
+
* Creates a {@link Converter} for an optional value.
|
|
619
|
+
*
|
|
620
|
+
* @remarks
|
|
621
|
+
* If `onError` is `failOnError`, the resulting converter will accept `undefined`
|
|
622
|
+
* or a convertible value, but report an error if it encounters a value that cannot be
|
|
623
|
+
* converted.
|
|
624
|
+
*
|
|
625
|
+
* If `onError` is `ignoreErrors` (default) then values that cannot be converted will
|
|
626
|
+
* result in a successful return of `undefined`.
|
|
627
|
+
*
|
|
628
|
+
* @param onError - Specifies handling of values that cannot be converted (default `ignoreErrors`).
|
|
629
|
+
* @returns A new {@link Converter} returning `<T|undefined>`.
|
|
599
630
|
*/
|
|
600
631
|
optional(onError?: OnError): Converter<T | undefined, TC>;
|
|
601
632
|
/**
|
|
602
|
-
* {@
|
|
633
|
+
* Creates a {@link Converter} which applies a (possibly) mapping conversion to
|
|
634
|
+
* the converted value of this {@link Converter}.
|
|
635
|
+
* @param mapper - A function which maps from the the result type `<T>` of this
|
|
636
|
+
* converter to a new result type `<T2>`.
|
|
637
|
+
* @returns A new {@link Converter} returning `<T2>`.
|
|
603
638
|
*/
|
|
604
639
|
map<T2>(mapper: (from: T, context?: TC) => Result<T2>): Converter<T2, TC>;
|
|
605
640
|
/**
|
|
606
|
-
* {@
|
|
641
|
+
* Creates a {@link Converter} which applies an additional supplied
|
|
642
|
+
* converter to the result of this converter.
|
|
643
|
+
*
|
|
644
|
+
* @param mapConverter - The {@link Converter} to be applied to the
|
|
645
|
+
* converted result from this {@link Converter}.
|
|
646
|
+
* @returns A new {@link Converter} returning `<T2>`.
|
|
607
647
|
*/
|
|
608
648
|
mapConvert<T2>(mapConverter: Converter<T2>): Converter<T2, TC>;
|
|
609
649
|
/**
|
|
610
|
-
* {@
|
|
650
|
+
* Creates a {@link Converter} which maps the individual items of a collection
|
|
651
|
+
* resulting from this {@link Converter} using the supplied map function.
|
|
652
|
+
*
|
|
653
|
+
* @remarks
|
|
654
|
+
* Fails if `from` is not an array.
|
|
655
|
+
*
|
|
656
|
+
* @param mapper - The map function to be applied to each element of the
|
|
657
|
+
* result of this {@link Converter}.
|
|
658
|
+
* @returns A new {@link Converter} returning `<TI[]>`.
|
|
611
659
|
*/
|
|
612
660
|
mapItems<TI>(mapper: (from: unknown, context?: TC) => Result<TI>): Converter<TI[], TC>;
|
|
613
661
|
/**
|
|
614
|
-
* {@
|
|
662
|
+
* Creates a {@link Converter} which maps the individual items of a collection
|
|
663
|
+
* resulting from this {@link Converter} using the supplied {@link Converter}.
|
|
664
|
+
*
|
|
665
|
+
* @remarks
|
|
666
|
+
* Fails if `from` is not an array.
|
|
667
|
+
*
|
|
668
|
+
* @param mapConverter - The {@link Converter} to be applied to each element of the
|
|
669
|
+
* result of this {@link Converter}.
|
|
670
|
+
* @returns A new {@link Converter} returning `<TI[]>`.
|
|
615
671
|
*/
|
|
616
672
|
mapConvertItems<TI>(mapConverter: Converter<TI, unknown>): Converter<TI[], TC>;
|
|
617
673
|
/**
|
|
618
|
-
* {@
|
|
674
|
+
* Creates a {@link Converter | Converter} which applies a supplied action after
|
|
675
|
+
* conversion. The supplied action is always called regardless of success or failure
|
|
676
|
+
* of the base conversion and is allowed to mutate the return type.
|
|
677
|
+
* @param action - The action to be applied.
|
|
619
678
|
*/
|
|
620
679
|
withAction<TI>(action: (result: Result<T>, context?: TC) => Result<TI>): Converter<TI, TC>;
|
|
621
680
|
/**
|
|
622
|
-
* {@
|
|
681
|
+
* Creates a {@link Converter} which applies a supplied type guard to the conversion
|
|
682
|
+
* result.
|
|
683
|
+
* @param guard - The type guard function to apply.
|
|
684
|
+
* @param message - Optional message to be reported if the type guard fails.
|
|
685
|
+
* @returns A new {@link Converter} returning `<TI>`.
|
|
623
686
|
*/
|
|
624
687
|
withTypeGuard<TI>(guard: (from: unknown, context?: TC) => from is TI, message?: string): Converter<TI, TC>;
|
|
625
688
|
/**
|
|
626
|
-
* {@
|
|
689
|
+
* Creates a {@link Converter} which applies a supplied type guard to each member of
|
|
690
|
+
* the conversion result from this converter.
|
|
691
|
+
*
|
|
692
|
+
* @remarks
|
|
693
|
+
* Fails if the conversion result is not an array or if any member fails the
|
|
694
|
+
* type guard.
|
|
695
|
+
* @param guard - The type guard function to apply to each element.
|
|
696
|
+
* @param message - Optional message to be reported if the type guard fails.
|
|
697
|
+
* @returns A new {@link Converter} returning `<TI>`.
|
|
627
698
|
*/
|
|
628
699
|
withItemTypeGuard<TI>(guard: (from: unknown, context?: TC) => from is TI, message?: string): Converter<TI[], TC>;
|
|
629
700
|
/**
|
|
630
|
-
* {@
|
|
701
|
+
* Creates a {@link Converter} which applies an optional constraint to the result
|
|
702
|
+
* of this conversion. If this {@link Converter} (the base converter) succeeds, the new
|
|
703
|
+
* converter calls a supplied constraint evaluation function with the conversion, which
|
|
704
|
+
* fails the entire conversion if the constraint function returns either `false` or
|
|
705
|
+
* {@link Failure | Failure<T>}.
|
|
706
|
+
*
|
|
707
|
+
* @param constraint - Constraint evaluation function.
|
|
708
|
+
* @param options - {@link Conversion.ConstraintOptions | Options} for constraint evaluation.
|
|
709
|
+
* @returns A new {@link Converter} returning `<T>`.
|
|
631
710
|
*/
|
|
632
711
|
withConstraint(constraint: (val: T, context?: TC) => boolean | Result<T>, options?: ConstraintOptions): Converter<T, TC>;
|
|
633
712
|
/**
|
|
634
|
-
*
|
|
713
|
+
* Returns a converter which adds a brand to the type to prevent mismatched usage
|
|
714
|
+
* of simple types.
|
|
715
|
+
* @param brand - The brand to be applied to the result value.
|
|
716
|
+
* @returns A {@link Converter} returning `Brand<T, B>`.
|
|
635
717
|
*/
|
|
636
718
|
withBrand<B extends string>(brand: B): Converter<Brand<T, B>, TC>;
|
|
637
719
|
/**
|
|
638
|
-
*
|
|
720
|
+
* Returns a Converter which always succeeds with a default value rather than failing.
|
|
721
|
+
* @param defaultValue - The default value to use if conversion fails.
|
|
639
722
|
*/
|
|
640
723
|
withDefault<TD = T>(defaultValue: TD): DefaultingConverter<T, TD, TC>;
|
|
641
724
|
or(other: Converter<T, TC>): Converter<T, TC>;
|
|
@@ -644,7 +727,10 @@ declare class BaseConverter<T, TC = unknown> implements Converter<T, TC> {
|
|
|
644
727
|
*/
|
|
645
728
|
protected _context(supplied?: TC): TC | undefined;
|
|
646
729
|
/**
|
|
647
|
-
* {@
|
|
730
|
+
* Creates a new {@link Converter} which is derived from this one but which returns an
|
|
731
|
+
* error message formatted by the supplied formatter if the conversion fails.
|
|
732
|
+
* @param formatter - The formatter to be applied.
|
|
733
|
+
* @returns A new {@link Converter} returning `<T>`.
|
|
648
734
|
*/
|
|
649
735
|
withFormattedError(formatter: ConversionErrorFormatter<TC>): Converter<T, TC>;
|
|
650
736
|
/**
|
|
@@ -1122,7 +1208,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1122
1208
|
private readonly _byKey;
|
|
1123
1209
|
private readonly _byIndex;
|
|
1124
1210
|
/**
|
|
1125
|
-
*
|
|
1211
|
+
* Returns the number of entries in the map.
|
|
1126
1212
|
*/
|
|
1127
1213
|
get size(): number;
|
|
1128
1214
|
/**
|
|
@@ -1149,19 +1235,28 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1149
1235
|
*/
|
|
1150
1236
|
add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1151
1237
|
/**
|
|
1152
|
-
*
|
|
1238
|
+
* Returns an iterator over the map entries.
|
|
1239
|
+
* @returns An iterator over the map entries.
|
|
1153
1240
|
*/
|
|
1154
1241
|
entries(): IterableIterator<KeyValueEntry<CollectibleKey<TITEM>, TITEM>>;
|
|
1155
1242
|
/**
|
|
1156
|
-
*
|
|
1243
|
+
* Calls a function for each entry in the map.
|
|
1244
|
+
* @param callback - The function to call for each entry.
|
|
1245
|
+
* @param arg - An optional argument to pass to the callback.
|
|
1157
1246
|
*/
|
|
1158
1247
|
forEach(callback: ResultMapForEachCb<CollectibleKey<TITEM>, TITEM>, arg?: unknown): void;
|
|
1159
1248
|
/**
|
|
1160
|
-
*
|
|
1249
|
+
* Gets a value by key.
|
|
1250
|
+
* @param key - The key to look up.
|
|
1251
|
+
* @returns Returns {@link DetailedSuccess | Success} with the value and detail `exists` if found,
|
|
1252
|
+
* or {@link DetailedFailure | Failure} with detail `not-found` if the key does not exist.
|
|
1161
1253
|
*/
|
|
1162
1254
|
get(key: CollectibleKey<TITEM>): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
1163
1255
|
/**
|
|
1164
|
-
*
|
|
1256
|
+
* Gets the item at a specified index.
|
|
1257
|
+
* @param index - The index of the item to retrieve.
|
|
1258
|
+
* @returns Returns {@link Success | Success} with the item if it exists, or {@link Failure | Failure}
|
|
1259
|
+
* with an error if the index is out of range.
|
|
1165
1260
|
*/
|
|
1166
1261
|
getAt(index: number): Result<TITEM>;
|
|
1167
1262
|
/**
|
|
@@ -1186,19 +1281,24 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1186
1281
|
*/
|
|
1187
1282
|
getOrAdd(key: CollectibleKey<TITEM>, factory: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1188
1283
|
/**
|
|
1189
|
-
*
|
|
1284
|
+
* Returns true if the map contains an entry with the given key.
|
|
1285
|
+
* @param key - The key to check for.
|
|
1286
|
+
* @returns `true` if the key exists, `false` otherwise.
|
|
1190
1287
|
*/
|
|
1191
1288
|
has(key: CollectibleKey<TITEM>): boolean;
|
|
1192
1289
|
/**
|
|
1193
|
-
*
|
|
1290
|
+
* Returns an iterator over the map keys.
|
|
1291
|
+
* @returns An iterator over the map keys.
|
|
1194
1292
|
*/
|
|
1195
1293
|
keys(): IterableIterator<CollectibleKey<TITEM>>;
|
|
1196
1294
|
/**
|
|
1197
|
-
*
|
|
1295
|
+
* Returns an iterator over the map values.
|
|
1296
|
+
* @returns An iterator over the map values.
|
|
1198
1297
|
*/
|
|
1199
1298
|
values(): IterableIterator<TITEM>;
|
|
1200
1299
|
/**
|
|
1201
|
-
*
|
|
1300
|
+
* Gets all items in the collection, ordered by index.
|
|
1301
|
+
* @returns An array of items in the collection, ordered by index.
|
|
1202
1302
|
*/
|
|
1203
1303
|
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
1204
1304
|
/**
|
|
@@ -1234,7 +1334,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1234
1334
|
*/
|
|
1235
1335
|
constructor(params: ICollectorValidatorCreateParams<TITEM>);
|
|
1236
1336
|
/**
|
|
1237
|
-
*
|
|
1337
|
+
* Adds an item to the collection, failing if a different item with the same key already exists. Note
|
|
1338
|
+
* that adding an object that is already in the collection again will succeed without updating the collection.
|
|
1339
|
+
* @param item - The item to add.
|
|
1340
|
+
* @returns Returns {@link DetailedSuccess | Success} with the item and detail `added` if it was added
|
|
1341
|
+
* or detail `exists` if the item was already in the map. Returns {@link DetailedFailure | Failure} with
|
|
1342
|
+
* an error message and appropriate detail if the item could not be added.
|
|
1238
1343
|
*/
|
|
1239
1344
|
add(item: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1240
1345
|
/**
|
|
@@ -1242,12 +1347,24 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1242
1347
|
*/
|
|
1243
1348
|
get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
1244
1349
|
/**
|
|
1245
|
-
*
|
|
1350
|
+
* Gets an existing item with a key matching the supplied key, or adds a new item to the collector
|
|
1351
|
+
* using a factory callback if no item with that key exists.
|
|
1352
|
+
* @param key - The weakly-typed key of the item to get or add.
|
|
1353
|
+
* @param factory - The factory callback to create the item.
|
|
1354
|
+
* @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -
|
|
1355
|
+
* detail `exists` indicates that an existing item was returned and detail `added` indicates
|
|
1356
|
+
* that the item was added. Returns {@link DetailedFailure | Failure} with an error and
|
|
1357
|
+
* appropriate detail if the item could not be added.
|
|
1246
1358
|
*/
|
|
1247
1359
|
getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1248
1360
|
/**
|
|
1249
|
-
*
|
|
1250
|
-
*
|
|
1361
|
+
* Gets an existing item with a key matching that of the supplied item, or adds the supplied
|
|
1362
|
+
* item to the collector if no item with that key exists.
|
|
1363
|
+
* @param item - The weakly-typed item to get or add.
|
|
1364
|
+
* @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -
|
|
1365
|
+
* detail `exists` indicates that an existing item was returned and detail `added` indicates
|
|
1366
|
+
* that the item was added. Returns {@link DetailedFailure | Failure} with an error and
|
|
1367
|
+
* appropriate detail if the item could not be added.
|
|
1251
1368
|
*/
|
|
1252
1369
|
getOrAdd(item: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1253
1370
|
/**
|
|
@@ -1712,7 +1829,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1712
1829
|
*/
|
|
1713
1830
|
static createConvertingCollector<TITEM extends ICollectible<any, any>, TSRC = TITEM>(params: IConvertingCollectorConstructorParams<TITEM, TSRC>): Result<ConvertingCollector<TITEM, TSRC>>;
|
|
1714
1831
|
/**
|
|
1715
|
-
*
|
|
1832
|
+
* Adds an item to the collection, failing if a different item with the same key already exists. Note
|
|
1833
|
+
* that adding an object that is already in the collection again will succeed without updating the collection.
|
|
1834
|
+
* @param item - The item to add.
|
|
1835
|
+
* @returns Returns {@link DetailedSuccess | Success} with the item and detail `added` if it was added
|
|
1836
|
+
* or detail `exists` if the item was already in the map. Returns {@link DetailedFailure | Failure} with
|
|
1837
|
+
* an error message and appropriate detail if the item could not be added.
|
|
1716
1838
|
*/
|
|
1717
1839
|
add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1718
1840
|
/**
|
|
@@ -1735,11 +1857,24 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1735
1857
|
*/
|
|
1736
1858
|
add(key: CollectibleKey<TITEM>, cb: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1737
1859
|
/**
|
|
1738
|
-
*
|
|
1860
|
+
* Gets an existing item with a key matching that of the supplied item, or adds the supplied
|
|
1861
|
+
* item to the collector if no item with that key exists.
|
|
1862
|
+
* @param item - The item to get or add.
|
|
1863
|
+
* @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -
|
|
1864
|
+
* detail `exists` indicates that an existing item was returned and detail `added` indicates
|
|
1865
|
+
* that the item was added. Returns {@link DetailedFailure | Failure} with an error and
|
|
1866
|
+
* appropriate detail if the item could not be added.
|
|
1739
1867
|
*/
|
|
1740
1868
|
getOrAdd(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1741
1869
|
/**
|
|
1742
|
-
*
|
|
1870
|
+
* Gets an existing item with a key matching the supplied key, or adds a new item to the collector
|
|
1871
|
+
* using a factory callback if no item with that key exists.
|
|
1872
|
+
* @param key - The key of the item to get or add.
|
|
1873
|
+
* @param callback - The factory callback to create the item.
|
|
1874
|
+
* @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -
|
|
1875
|
+
* detail `exists` indicates that an existing item was returned and detail `added` indicates
|
|
1876
|
+
* that the item was added. Returns {@link DetailedFailure | Failure} with an error and
|
|
1877
|
+
* appropriate detail if the item could not be added.
|
|
1743
1878
|
*/
|
|
1744
1879
|
getOrAdd(key: CollectibleKey<TITEM>, callback: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1745
1880
|
/**
|
|
@@ -1797,7 +1932,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1797
1932
|
*/
|
|
1798
1933
|
constructor(params: IConvertingCollectorValidatorCreateParams<TITEM, TSRC>);
|
|
1799
1934
|
/**
|
|
1800
|
-
*
|
|
1935
|
+
* Adds an item to the collector using the default factory at a specified key,
|
|
1936
|
+
* failing if an item with that key already exists.
|
|
1937
|
+
* @param key - The weakly-typed key of the item to add.
|
|
1938
|
+
* @param value - The source representation of the item to be added.
|
|
1939
|
+
* @returns Returns {@link Success | Success} with the item if it is added, or {@link Failure | Failure} with
|
|
1940
|
+
* an error if the item cannot be created and indexed.
|
|
1801
1941
|
*/
|
|
1802
1942
|
add(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1803
1943
|
/**
|
|
@@ -1810,11 +1950,25 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1810
1950
|
*/
|
|
1811
1951
|
get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
1812
1952
|
/**
|
|
1813
|
-
*
|
|
1953
|
+
* Gets an existing item with a key matching the supplied key, or adds a new item to the collector
|
|
1954
|
+
* by converting the supplied weakly-typed value if no item with that key exists.
|
|
1955
|
+
* @param key - The weakly-typed key of the item to get or add.
|
|
1956
|
+
* @param value - The weakly-typed source value to convert and add if the key does not exist.
|
|
1957
|
+
* @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -
|
|
1958
|
+
* detail `exists` indicates that an existing item was returned and detail `added` indicates
|
|
1959
|
+
* that the item was added. Returns {@link DetailedFailure | Failure} with an error and
|
|
1960
|
+
* appropriate detail if the item could not be added.
|
|
1814
1961
|
*/
|
|
1815
1962
|
getOrAdd(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1816
1963
|
/**
|
|
1817
|
-
*
|
|
1964
|
+
* Gets an existing item with a key matching the supplied key, or adds a new item to the collector
|
|
1965
|
+
* using a factory callback if no item with that key exists.
|
|
1966
|
+
* @param key - The weakly-typed key of the item to get or add.
|
|
1967
|
+
* @param factory - The factory callback to create the item.
|
|
1968
|
+
* @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -
|
|
1969
|
+
* detail `exists` indicates that an existing item was returned and detail `added` indicates
|
|
1970
|
+
* that the item was added. Returns {@link DetailedFailure | Failure} with an error and
|
|
1971
|
+
* appropriate detail if the item could not be added.
|
|
1818
1972
|
*/
|
|
1819
1973
|
getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1820
1974
|
/**
|
|
@@ -3167,7 +3321,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3167
3321
|
*/
|
|
3168
3322
|
has(key: string): boolean;
|
|
3169
3323
|
/**
|
|
3170
|
-
*
|
|
3324
|
+
* Gets an existing item with a key matching the supplied key, or adds a new item to the collector
|
|
3325
|
+
* using a factory callback if no item with that key exists.
|
|
3326
|
+
* @param key - The weakly-typed key of the item to get or add.
|
|
3327
|
+
* @param factory - The factory callback to create the item.
|
|
3328
|
+
* @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -
|
|
3329
|
+
* detail `exists` indicates that an existing item was returned and detail `added` indicates
|
|
3330
|
+
* that the item was added. Returns {@link DetailedFailure | Failure} with an error and
|
|
3331
|
+
* appropriate detail if the item could not be added.
|
|
3171
3332
|
*/
|
|
3172
3333
|
getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
3173
3334
|
}
|
|
@@ -3204,31 +3365,42 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3204
3365
|
*/
|
|
3205
3366
|
export declare interface IReadOnlyResultMap<TK extends string = string, TV = unknown> {
|
|
3206
3367
|
/**
|
|
3207
|
-
*
|
|
3368
|
+
* Returns the number of entries in the map.
|
|
3208
3369
|
*/
|
|
3209
3370
|
readonly size: number;
|
|
3210
3371
|
/**
|
|
3211
|
-
*
|
|
3372
|
+
* Returns an iterator over the map entries.
|
|
3373
|
+
* @returns An iterator over the map entries.
|
|
3212
3374
|
*/
|
|
3213
3375
|
entries(): IterableIterator<KeyValueEntry<TK, TV>>;
|
|
3214
3376
|
/**
|
|
3215
|
-
*
|
|
3377
|
+
* Calls a function for each entry in the map.
|
|
3378
|
+
* @param cb - The function to call for each entry.
|
|
3379
|
+
* @param arg - An optional argument to pass to the callback.
|
|
3216
3380
|
*/
|
|
3217
3381
|
forEach(cb: ResultMapForEachCb, arg?: unknown): void;
|
|
3218
3382
|
/**
|
|
3219
|
-
*
|
|
3383
|
+
* Gets a value from the map.
|
|
3384
|
+
* @param key - The key to retrieve.
|
|
3385
|
+
* @returns `Success` with the value and detail `exists` if the key was found,
|
|
3386
|
+
* `Failure` with detail `not-found` if the key was not found or with detail
|
|
3387
|
+
* `invalid-key` if the key is invalid.
|
|
3220
3388
|
*/
|
|
3221
3389
|
get(key: TK): DetailedResult<TV, ResultMapResultDetail>;
|
|
3222
3390
|
/**
|
|
3223
|
-
*
|
|
3391
|
+
* Returns `true` if the map contains a key.
|
|
3392
|
+
* @param key - The key to check.
|
|
3393
|
+
* @returns `true` if the key exists, `false` otherwise.
|
|
3224
3394
|
*/
|
|
3225
3395
|
has(key: TK): boolean;
|
|
3226
3396
|
/**
|
|
3227
|
-
*
|
|
3397
|
+
* Returns an iterator over the map keys.
|
|
3398
|
+
* @returns An iterator over the map keys.
|
|
3228
3399
|
*/
|
|
3229
3400
|
keys(): IterableIterator<TK>;
|
|
3230
3401
|
/**
|
|
3231
|
-
*
|
|
3402
|
+
* Returns an iterator over the map values.
|
|
3403
|
+
* @returns An iterator over the map values.
|
|
3232
3404
|
*/
|
|
3233
3405
|
values(): IterableIterator<TV>;
|
|
3234
3406
|
/**
|
|
@@ -3264,15 +3436,19 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3264
3436
|
*/
|
|
3265
3437
|
declare interface IReadOnlyValidatingCollector<TITEM extends ICollectible<any, any>> extends IReadOnlyValidatingResultMap<CollectibleKey<TITEM>, TITEM> {
|
|
3266
3438
|
/**
|
|
3267
|
-
* {@
|
|
3439
|
+
* A {@link Collections.CollectorValidator | CollectorValidator} which validates keys and values
|
|
3440
|
+
* before inserting them into this collector.
|
|
3268
3441
|
*/
|
|
3269
3442
|
readonly validating: IReadOnlyCollectorValidator<TITEM>;
|
|
3270
3443
|
/**
|
|
3271
|
-
*
|
|
3444
|
+
* Gets the item at a specified index.
|
|
3445
|
+
* @param index - The index of the item to retrieve.
|
|
3446
|
+
* @returns `Success` with the item if it exists, or `Failure` with an error if the index is out of range.
|
|
3272
3447
|
*/
|
|
3273
3448
|
getAt(index: number): Result<TITEM>;
|
|
3274
3449
|
/**
|
|
3275
|
-
*
|
|
3450
|
+
* Gets all items in the collection, ordered by index.
|
|
3451
|
+
* @returns An array of items in the collection, ordered by index.
|
|
3276
3452
|
*/
|
|
3277
3453
|
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
3278
3454
|
}
|
|
@@ -3283,7 +3459,8 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3283
3459
|
*/
|
|
3284
3460
|
declare interface IReadOnlyValidatingResultMap<TK extends string = string, TV = unknown> extends IReadOnlyResultMap<TK, TV> {
|
|
3285
3461
|
/**
|
|
3286
|
-
* {@
|
|
3462
|
+
* A {@link Collections.ResultMapValidator | ResultMapValidator} which validates keys and values
|
|
3463
|
+
* before inserting them into this collection.
|
|
3287
3464
|
*/
|
|
3288
3465
|
readonly validating: IReadOnlyResultMapValidator<TK, TV>;
|
|
3289
3466
|
}
|
|
@@ -3925,36 +4102,61 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3925
4102
|
*/
|
|
3926
4103
|
declare abstract class LoggerBase implements IDetailLogger {
|
|
3927
4104
|
/**
|
|
3928
|
-
*
|
|
4105
|
+
* The level of logging to be used.
|
|
3929
4106
|
*/
|
|
3930
4107
|
logLevel: ReporterLogLevel;
|
|
3931
4108
|
protected constructor(logLevel?: ReporterLogLevel);
|
|
3932
4109
|
/**
|
|
3933
|
-
*
|
|
4110
|
+
* Logs a detail message.
|
|
4111
|
+
* @param message - The message to log.
|
|
4112
|
+
* @param parameters - The parameters to log.
|
|
4113
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
4114
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
3934
4115
|
*/
|
|
3935
4116
|
detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3936
4117
|
/**
|
|
3937
|
-
*
|
|
4118
|
+
* Logs an info message.
|
|
4119
|
+
* @param message - The message to log.
|
|
4120
|
+
* @param parameters - The parameters to log.
|
|
4121
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
4122
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
3938
4123
|
*/
|
|
3939
4124
|
info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3940
4125
|
/**
|
|
3941
|
-
*
|
|
4126
|
+
* Logs a warning message.
|
|
4127
|
+
* @param message - The message to log.
|
|
4128
|
+
* @param parameters - The parameters to log.
|
|
4129
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
4130
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
3942
4131
|
*/
|
|
3943
4132
|
warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3944
4133
|
/**
|
|
3945
|
-
*
|
|
4134
|
+
* Logs an error message.
|
|
4135
|
+
* @param message - The message to log.
|
|
4136
|
+
* @param parameters - The parameters to log.
|
|
4137
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
4138
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
3946
4139
|
*/
|
|
3947
4140
|
error(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3948
4141
|
/**
|
|
3949
|
-
*
|
|
4142
|
+
* Logs a short error summary at `error` level, then emits `detail` at `detail` level.
|
|
4143
|
+
* @param message - Short human-readable summary.
|
|
4144
|
+
* @param detail - Full detail (e.g. raw converter error) logged at `detail` level.
|
|
3950
4145
|
*/
|
|
3951
4146
|
errorWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
3952
4147
|
/**
|
|
3953
|
-
*
|
|
4148
|
+
* Logs a short warning summary at `warning` level, then emits `detail` at `detail` level.
|
|
4149
|
+
* @param message - Short human-readable summary.
|
|
4150
|
+
* @param detail - Full detail logged at `detail` level.
|
|
3954
4151
|
*/
|
|
3955
4152
|
warnWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
3956
4153
|
/**
|
|
3957
|
-
*
|
|
4154
|
+
* Logs a message at the given level.
|
|
4155
|
+
* @param level - The level of the message.
|
|
4156
|
+
* @param message - The message to log.
|
|
4157
|
+
* @param parameters - The parameters to log.
|
|
4158
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
4159
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
3958
4160
|
*/
|
|
3959
4161
|
log(level: MessageLogLevel, message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3960
4162
|
/**
|
|
@@ -46,7 +46,7 @@ export declare class Collector<TITEM extends ICollectible<any, any>> implements
|
|
|
46
46
|
private readonly _byKey;
|
|
47
47
|
private readonly _byIndex;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* Returns the number of entries in the map.
|
|
50
50
|
*/
|
|
51
51
|
get size(): number;
|
|
52
52
|
/**
|
|
@@ -73,19 +73,28 @@ export declare class Collector<TITEM extends ICollectible<any, any>> implements
|
|
|
73
73
|
*/
|
|
74
74
|
add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
|
|
75
75
|
/**
|
|
76
|
-
*
|
|
76
|
+
* Returns an iterator over the map entries.
|
|
77
|
+
* @returns An iterator over the map entries.
|
|
77
78
|
*/
|
|
78
79
|
entries(): IterableIterator<KeyValueEntry<CollectibleKey<TITEM>, TITEM>>;
|
|
79
80
|
/**
|
|
80
|
-
*
|
|
81
|
+
* Calls a function for each entry in the map.
|
|
82
|
+
* @param callback - The function to call for each entry.
|
|
83
|
+
* @param arg - An optional argument to pass to the callback.
|
|
81
84
|
*/
|
|
82
85
|
forEach(callback: ResultMapForEachCb<CollectibleKey<TITEM>, TITEM>, arg?: unknown): void;
|
|
83
86
|
/**
|
|
84
|
-
*
|
|
87
|
+
* Gets a value by key.
|
|
88
|
+
* @param key - The key to look up.
|
|
89
|
+
* @returns Returns {@link DetailedSuccess | Success} with the value and detail `exists` if found,
|
|
90
|
+
* or {@link DetailedFailure | Failure} with detail `not-found` if the key does not exist.
|
|
85
91
|
*/
|
|
86
92
|
get(key: CollectibleKey<TITEM>): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
87
93
|
/**
|
|
88
|
-
*
|
|
94
|
+
* Gets the item at a specified index.
|
|
95
|
+
* @param index - The index of the item to retrieve.
|
|
96
|
+
* @returns Returns {@link Success | Success} with the item if it exists, or {@link Failure | Failure}
|
|
97
|
+
* with an error if the index is out of range.
|
|
89
98
|
*/
|
|
90
99
|
getAt(index: number): Result<TITEM>;
|
|
91
100
|
/**
|
|
@@ -110,19 +119,24 @@ export declare class Collector<TITEM extends ICollectible<any, any>> implements
|
|
|
110
119
|
*/
|
|
111
120
|
getOrAdd(key: CollectibleKey<TITEM>, factory: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
112
121
|
/**
|
|
113
|
-
*
|
|
122
|
+
* Returns true if the map contains an entry with the given key.
|
|
123
|
+
* @param key - The key to check for.
|
|
124
|
+
* @returns `true` if the key exists, `false` otherwise.
|
|
114
125
|
*/
|
|
115
126
|
has(key: CollectibleKey<TITEM>): boolean;
|
|
116
127
|
/**
|
|
117
|
-
*
|
|
128
|
+
* Returns an iterator over the map keys.
|
|
129
|
+
* @returns An iterator over the map keys.
|
|
118
130
|
*/
|
|
119
131
|
keys(): IterableIterator<CollectibleKey<TITEM>>;
|
|
120
132
|
/**
|
|
121
|
-
*
|
|
133
|
+
* Returns an iterator over the map values.
|
|
134
|
+
* @returns An iterator over the map values.
|
|
122
135
|
*/
|
|
123
136
|
values(): IterableIterator<TITEM>;
|
|
124
137
|
/**
|
|
125
|
-
*
|
|
138
|
+
* Gets all items in the collection, ordered by index.
|
|
139
|
+
* @returns An array of items in the collection, ordered by index.
|
|
126
140
|
*/
|
|
127
141
|
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
128
142
|
/**
|