@fgv/ts-utils 5.1.0-2 → 5.1.0-20
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 +21 -0
- package/dist/index.js.map +1 -0
- package/dist/packlets/base/brand.js.map +1 -0
- package/dist/packlets/base/index.js.map +1 -0
- package/dist/packlets/base/mapResults.js.map +1 -0
- package/dist/packlets/base/messageAggregator.js.map +1 -0
- package/dist/packlets/base/normalize.js.map +1 -0
- package/dist/packlets/base/result.js +227 -2
- package/dist/packlets/base/result.js.map +1 -0
- package/dist/packlets/base/utils.js.map +1 -0
- package/dist/packlets/collections/aggregatedResultMap.js.map +1 -0
- package/dist/packlets/collections/collectible.js.map +1 -0
- package/dist/packlets/collections/collector.js +23 -9
- package/dist/packlets/collections/collector.js.map +1 -0
- package/dist/packlets/collections/collectorValidator.js +6 -1
- package/dist/packlets/collections/collectorValidator.js.map +1 -0
- package/dist/packlets/collections/common.js.map +1 -0
- package/dist/packlets/collections/converters.js.map +1 -0
- package/dist/packlets/collections/convertingCollector.js.map +1 -0
- package/dist/packlets/collections/convertingCollectorValidator.js.map +1 -0
- package/dist/packlets/collections/convertingResultMap.js.map +1 -0
- package/dist/packlets/collections/index.js.map +1 -0
- package/dist/packlets/collections/keyValueConverters.js.map +1 -0
- package/dist/packlets/collections/readOnlyConvertingResultMap.js.map +1 -0
- package/dist/packlets/collections/readonlyResultMap.js.map +1 -0
- package/dist/packlets/collections/resultMap.js.map +1 -0
- package/dist/packlets/collections/resultMapValidator.js.map +1 -0
- package/dist/packlets/collections/utils.js.map +1 -0
- package/dist/packlets/collections/validatingCollector.js.map +1 -0
- package/dist/packlets/collections/validatingConvertingCollector.js.map +1 -0
- package/dist/packlets/collections/validatingConvertingResultMap.js.map +1 -0
- package/dist/packlets/collections/validatingResultMap.js.map +1 -0
- package/dist/packlets/conversion/advancedConverters.js.map +1 -0
- package/dist/packlets/conversion/baseConverter.js +102 -16
- package/dist/packlets/conversion/baseConverter.js.map +1 -0
- package/dist/packlets/conversion/basicConverters.js.map +1 -0
- package/dist/packlets/conversion/converter.js.map +1 -0
- package/dist/packlets/conversion/converters.js.map +1 -0
- package/dist/packlets/conversion/defaultingConverter.js.map +1 -0
- package/dist/packlets/conversion/index.js.map +1 -0
- package/dist/packlets/conversion/objectConverter.js.map +1 -0
- package/dist/packlets/conversion/stringConverter.js.map +1 -0
- package/dist/packlets/hash/crcNormalizer.js.map +1 -0
- package/dist/packlets/hash/hashingNormalizer.js.map +1 -0
- package/dist/packlets/hash/index.js.map +1 -0
- package/dist/packlets/logging/bootLogger.js.map +1 -0
- package/dist/packlets/logging/index.js.map +1 -0
- package/dist/packlets/logging/logReporter.js.map +1 -0
- package/dist/packlets/logging/logger.js +33 -8
- package/dist/packlets/logging/logger.js.map +1 -0
- package/dist/packlets/validation/array.js.map +1 -0
- package/dist/packlets/validation/boolean.js.map +1 -0
- package/dist/packlets/validation/classes.js.map +1 -0
- package/dist/packlets/validation/common.js.map +1 -0
- package/dist/packlets/validation/compositeId.js.map +1 -0
- package/dist/packlets/validation/field.js.map +1 -0
- package/dist/packlets/validation/genericValidator.js.map +1 -0
- package/dist/packlets/validation/index.js.map +1 -0
- package/dist/packlets/validation/number.js.map +1 -0
- package/dist/packlets/validation/object.js.map +1 -0
- package/dist/packlets/validation/oneOf.js.map +1 -0
- package/dist/packlets/validation/string.js.map +1 -0
- package/dist/packlets/validation/traits.js.map +1 -0
- package/dist/packlets/validation/typeGuard.js.map +1 -0
- package/dist/packlets/validation/validator.js.map +1 -0
- package/dist/packlets/validation/validatorBase.js.map +1 -0
- package/dist/packlets/validation/validators.js.map +1 -0
- package/dist/ts-utils.d.ts +441 -56
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/base/brand.d.ts.map +1 -0
- package/lib/packlets/base/brand.js.map +1 -0
- package/lib/packlets/base/index.d.ts.map +1 -0
- package/lib/packlets/base/index.js.map +1 -0
- package/lib/packlets/base/mapResults.d.ts.map +1 -0
- package/lib/packlets/base/mapResults.js.map +1 -0
- package/lib/packlets/base/messageAggregator.d.ts.map +1 -0
- package/lib/packlets/base/messageAggregator.js.map +1 -0
- package/lib/packlets/base/normalize.d.ts.map +1 -0
- package/lib/packlets/base/normalize.js.map +1 -0
- package/lib/packlets/base/result.d.ts +179 -1
- package/lib/packlets/base/result.d.ts.map +1 -0
- package/lib/packlets/base/result.js +231 -3
- package/lib/packlets/base/result.js.map +1 -0
- package/lib/packlets/base/utils.d.ts.map +1 -0
- package/lib/packlets/base/utils.js.map +1 -0
- package/lib/packlets/collections/aggregatedResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/aggregatedResultMap.js.map +1 -0
- package/lib/packlets/collections/collectible.d.ts.map +1 -0
- package/lib/packlets/collections/collectible.js.map +1 -0
- package/lib/packlets/collections/collector.d.ts +23 -9
- package/lib/packlets/collections/collector.d.ts.map +1 -0
- package/lib/packlets/collections/collector.js +23 -9
- package/lib/packlets/collections/collector.js.map +1 -0
- package/lib/packlets/collections/collectorValidator.d.ts +29 -5
- package/lib/packlets/collections/collectorValidator.d.ts.map +1 -0
- package/lib/packlets/collections/collectorValidator.js +6 -1
- package/lib/packlets/collections/collectorValidator.js.map +1 -0
- package/lib/packlets/collections/common.d.ts.map +1 -0
- package/lib/packlets/collections/common.js.map +1 -0
- package/lib/packlets/collections/converters.d.ts.map +1 -0
- package/lib/packlets/collections/converters.js.map +1 -0
- package/lib/packlets/collections/convertingCollector.d.ts +21 -3
- package/lib/packlets/collections/convertingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/convertingCollector.js.map +1 -0
- package/lib/packlets/collections/convertingCollectorValidator.d.ts +22 -3
- package/lib/packlets/collections/convertingCollectorValidator.d.ts.map +1 -0
- package/lib/packlets/collections/convertingCollectorValidator.js.map +1 -0
- package/lib/packlets/collections/convertingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/convertingResultMap.js.map +1 -0
- package/lib/packlets/collections/index.d.ts.map +1 -0
- package/lib/packlets/collections/index.js.map +1 -0
- package/lib/packlets/collections/keyValueConverters.d.ts.map +1 -0
- package/lib/packlets/collections/keyValueConverters.js.map +1 -0
- package/lib/packlets/collections/readOnlyConvertingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/readOnlyConvertingResultMap.js.map +1 -0
- package/lib/packlets/collections/readonlyResultMap.d.ts +18 -7
- package/lib/packlets/collections/readonlyResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/readonlyResultMap.js.map +1 -0
- package/lib/packlets/collections/resultMap.d.ts.map +1 -0
- package/lib/packlets/collections/resultMap.js.map +1 -0
- package/lib/packlets/collections/resultMapValidator.d.ts.map +1 -0
- package/lib/packlets/collections/resultMapValidator.js.map +1 -0
- package/lib/packlets/collections/utils.d.ts.map +1 -0
- package/lib/packlets/collections/utils.js.map +1 -0
- package/lib/packlets/collections/validatingCollector.d.ts +7 -3
- package/lib/packlets/collections/validatingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/validatingCollector.js.map +1 -0
- package/lib/packlets/collections/validatingConvertingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/validatingConvertingCollector.js.map +1 -0
- package/lib/packlets/collections/validatingConvertingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/validatingConvertingResultMap.js.map +1 -0
- package/lib/packlets/collections/validatingResultMap.d.ts +2 -1
- package/lib/packlets/collections/validatingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/validatingResultMap.js.map +1 -0
- package/lib/packlets/conversion/advancedConverters.d.ts.map +1 -0
- package/lib/packlets/conversion/advancedConverters.js.map +1 -0
- package/lib/packlets/conversion/baseConverter.d.ts +102 -16
- package/lib/packlets/conversion/baseConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/baseConverter.js +102 -16
- package/lib/packlets/conversion/baseConverter.js.map +1 -0
- package/lib/packlets/conversion/basicConverters.d.ts.map +1 -0
- package/lib/packlets/conversion/basicConverters.js.map +1 -0
- package/lib/packlets/conversion/converter.d.ts.map +1 -0
- package/lib/packlets/conversion/converter.js.map +1 -0
- package/lib/packlets/conversion/converters.d.ts.map +1 -0
- package/lib/packlets/conversion/converters.js.map +1 -0
- package/lib/packlets/conversion/defaultingConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/defaultingConverter.js.map +1 -0
- package/lib/packlets/conversion/index.d.ts.map +1 -0
- package/lib/packlets/conversion/index.js.map +1 -0
- package/lib/packlets/conversion/objectConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/objectConverter.js.map +1 -0
- package/lib/packlets/conversion/stringConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/stringConverter.js.map +1 -0
- package/lib/packlets/hash/crcNormalizer.d.ts.map +1 -0
- package/lib/packlets/hash/crcNormalizer.js.map +1 -0
- package/lib/packlets/hash/hashingNormalizer.d.ts.map +1 -0
- package/lib/packlets/hash/hashingNormalizer.js.map +1 -0
- package/lib/packlets/hash/index.d.ts.map +1 -0
- package/lib/packlets/hash/index.js.map +1 -0
- package/lib/packlets/logging/bootLogger.d.ts.map +1 -0
- package/lib/packlets/logging/bootLogger.js.map +1 -0
- package/lib/packlets/logging/index.d.ts.map +1 -0
- package/lib/packlets/logging/index.js.map +1 -0
- package/lib/packlets/logging/logReporter.d.ts.map +1 -0
- package/lib/packlets/logging/logReporter.js.map +1 -0
- package/lib/packlets/logging/logger.d.ts +33 -8
- package/lib/packlets/logging/logger.d.ts.map +1 -0
- package/lib/packlets/logging/logger.js +33 -8
- package/lib/packlets/logging/logger.js.map +1 -0
- package/lib/packlets/validation/array.d.ts.map +1 -0
- package/lib/packlets/validation/array.js.map +1 -0
- package/lib/packlets/validation/boolean.d.ts.map +1 -0
- package/lib/packlets/validation/boolean.js.map +1 -0
- package/lib/packlets/validation/classes.d.ts.map +1 -0
- package/lib/packlets/validation/classes.js.map +1 -0
- package/lib/packlets/validation/common.d.ts.map +1 -0
- package/lib/packlets/validation/common.js.map +1 -0
- package/lib/packlets/validation/compositeId.d.ts.map +1 -0
- package/lib/packlets/validation/compositeId.js.map +1 -0
- package/lib/packlets/validation/field.d.ts.map +1 -0
- package/lib/packlets/validation/field.js.map +1 -0
- package/lib/packlets/validation/genericValidator.d.ts.map +1 -0
- package/lib/packlets/validation/genericValidator.js.map +1 -0
- package/lib/packlets/validation/index.d.ts.map +1 -0
- package/lib/packlets/validation/index.js.map +1 -0
- package/lib/packlets/validation/number.d.ts.map +1 -0
- package/lib/packlets/validation/number.js.map +1 -0
- package/lib/packlets/validation/object.d.ts.map +1 -0
- package/lib/packlets/validation/object.js.map +1 -0
- package/lib/packlets/validation/oneOf.d.ts.map +1 -0
- package/lib/packlets/validation/oneOf.js.map +1 -0
- package/lib/packlets/validation/string.d.ts.map +1 -0
- package/lib/packlets/validation/string.js.map +1 -0
- package/lib/packlets/validation/traits.d.ts.map +1 -0
- package/lib/packlets/validation/traits.js.map +1 -0
- package/lib/packlets/validation/typeGuard.d.ts.map +1 -0
- package/lib/packlets/validation/typeGuard.js.map +1 -0
- package/lib/packlets/validation/validator.d.ts.map +1 -0
- package/lib/packlets/validation/validator.js.map +1 -0
- package/lib/packlets/validation/validatorBase.d.ts +2 -1
- package/lib/packlets/validation/validatorBase.d.ts.map +1 -0
- package/lib/packlets/validation/validatorBase.js.map +1 -0
- package/lib/packlets/validation/validators.d.ts.map +1 -0
- package/lib/packlets/validation/validators.js.map +1 -0
- package/package.json +20 -18
- package/dist/test/helpers/jest/helpers/fsHelpers.js +0 -139
- package/dist/test/helpers/jest/helpers/index.js +0 -2
- package/dist/test/helpers/jest/index.js +0 -17
- package/dist/test/helpers/jest/matchers/index.js +0 -14
- package/dist/test/helpers/jest/matchers/toFail/index.js +0 -23
- package/dist/test/helpers/jest/matchers/toFail/predicate.js +0 -5
- package/dist/test/helpers/jest/matchers/toFailTest/index.js +0 -28
- package/dist/test/helpers/jest/matchers/toFailTest/predicate.js +0 -8
- package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/index.js +0 -24
- package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/predicate.js +0 -11
- package/dist/test/helpers/jest/matchers/toFailTestWith/index.js +0 -29
- package/dist/test/helpers/jest/matchers/toFailTestWith/predicate.js +0 -26
- package/dist/test/helpers/jest/matchers/toFailWith/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toFailWith/predicate.js +0 -16
- package/dist/test/helpers/jest/matchers/toFailWithDetail/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toFailWithDetail/predicate.js +0 -22
- package/dist/test/helpers/jest/matchers/toSucceed/index.js +0 -23
- package/dist/test/helpers/jest/matchers/toSucceed/predicate.js +0 -5
- package/dist/test/helpers/jest/matchers/toSucceedAndMatchInlineSnapshot/index.js +0 -24
- package/dist/test/helpers/jest/matchers/toSucceedAndMatchSnapshot/index.js +0 -24
- package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/index.js +0 -53
- package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/predicate.js +0 -17
- package/dist/test/helpers/jest/matchers/toSucceedWith/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toSucceedWith/predicate.js +0 -12
- package/dist/test/helpers/jest/matchers/toSucceedWithDetail/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toSucceedWithDetail/predicate.js +0 -17
- package/dist/test/helpers/jest/resolvers/cli.js +0 -10
- package/dist/test/helpers/jest/resolvers/ide.js +0 -10
- package/dist/test/helpers/jest/ts-utils.js +0 -2
- package/dist/test/helpers/jest/types/index.js +0 -3
- package/dist/test/helpers/jest/utils/matcherHelpers.js +0 -47
- package/dist/test/helpers/jest/utils/snapshotResolver.js +0 -11
- package/dist/test/unit/collections/helpers.js +0 -106
- package/dist/test/unit/hashTextEncodeCompat.js +0 -23
package/dist/ts-utils.d.ts
CHANGED
|
@@ -420,6 +420,131 @@ declare interface ArrayValidatorConstructorParams<T, TC = unknown> extends Valid
|
|
|
420
420
|
*/
|
|
421
421
|
declare function asValidator<T, TC = unknown>(converterOrValidator: Converter<T, TC> | Validator<T, TC>): Validator<T, TC>;
|
|
422
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Async continuation callback to be called in the event that a
|
|
425
|
+
* {@link Result} fails, returning a `Promise` of a new {@link Result}.
|
|
426
|
+
* @public
|
|
427
|
+
*/
|
|
428
|
+
export declare type AsyncFailureContinuation<T> = (message: string) => Promise<Result<T>>;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Wraps a `Promise` of a {@link Result} to enable fluent chaining of both
|
|
432
|
+
* synchronous and asynchronous operations.
|
|
433
|
+
*
|
|
434
|
+
* @remarks
|
|
435
|
+
* `AsyncResult<T>` implements `PromiseLike` so it can be directly `await`ed.
|
|
436
|
+
* Use the `thenOnSuccess` and `thenOnFailure` methods on {@link Result} to bridge
|
|
437
|
+
* from synchronous to asynchronous result chains.
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* ```typescript
|
|
441
|
+
* const result: Result<Final> = await parseInput(input)
|
|
442
|
+
* .thenOnSuccess(async (parsed) => fetchData(parsed))
|
|
443
|
+
* .onSuccess((data) => transform(data))
|
|
444
|
+
* .thenOnSuccess(async (transformed) => saveData(transformed))
|
|
445
|
+
* .withErrorFormat((msg) => `pipeline failed: ${msg}`);
|
|
446
|
+
* ```
|
|
447
|
+
*
|
|
448
|
+
* @public
|
|
449
|
+
*/
|
|
450
|
+
export declare class AsyncResult<T> implements PromiseLike<Result<T>> {
|
|
451
|
+
private readonly _promise;
|
|
452
|
+
/**
|
|
453
|
+
* Constructs an {@link AsyncResult} wrapping the supplied promise.
|
|
454
|
+
* @remarks
|
|
455
|
+
* If the supplied promise rejects, the rejection is caught and converted
|
|
456
|
+
* to a {@link Failure}, ensuring that awaiting an {@link AsyncResult} always
|
|
457
|
+
* yields a {@link Result}.
|
|
458
|
+
* @param promise - A `Promise` that resolves to a {@link Result}.
|
|
459
|
+
*/
|
|
460
|
+
constructor(promise: Promise<Result<T>>);
|
|
461
|
+
/**
|
|
462
|
+
* Calls a supplied {@link SuccessContinuation | success continuation} if
|
|
463
|
+
* the wrapped result is successful.
|
|
464
|
+
* @param cb - The synchronous {@link SuccessContinuation | success continuation}
|
|
465
|
+
* to be called in the event of success.
|
|
466
|
+
* @returns A new {@link AsyncResult} wrapping the continuation result.
|
|
467
|
+
*/
|
|
468
|
+
onSuccess<TN>(cb: SuccessContinuation<T, TN>): AsyncResult<TN>;
|
|
469
|
+
/**
|
|
470
|
+
* Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if
|
|
471
|
+
* the wrapped result is successful.
|
|
472
|
+
* @remarks
|
|
473
|
+
* Both synchronous throws and async rejections from the callback are caught
|
|
474
|
+
* and converted to a {@link Failure}.
|
|
475
|
+
* @param cb - The {@link AsyncSuccessContinuation | async success continuation}
|
|
476
|
+
* to be called in the event of success.
|
|
477
|
+
* @returns A new {@link AsyncResult} wrapping the async continuation result.
|
|
478
|
+
*/
|
|
479
|
+
thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;
|
|
480
|
+
/**
|
|
481
|
+
* Calls a supplied {@link FailureContinuation | failure continuation} if
|
|
482
|
+
* the wrapped result is a failure.
|
|
483
|
+
* @param cb - The synchronous {@link FailureContinuation | failure continuation}
|
|
484
|
+
* to be called in the event of failure.
|
|
485
|
+
* @returns A new {@link AsyncResult} wrapping the continuation result.
|
|
486
|
+
*/
|
|
487
|
+
onFailure(cb: FailureContinuation<T>): AsyncResult<T>;
|
|
488
|
+
/**
|
|
489
|
+
* Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if
|
|
490
|
+
* the wrapped result is a failure.
|
|
491
|
+
* @remarks
|
|
492
|
+
* Both synchronous throws and async rejections from the callback are caught
|
|
493
|
+
* and converted to a {@link Failure}.
|
|
494
|
+
* @param cb - The {@link AsyncFailureContinuation | async failure continuation}
|
|
495
|
+
* to be called in the event of failure.
|
|
496
|
+
* @returns A new {@link AsyncResult} wrapping the async continuation result.
|
|
497
|
+
*/
|
|
498
|
+
thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T>;
|
|
499
|
+
/**
|
|
500
|
+
* Calls a supplied {@link ErrorFormatter | error formatter} if
|
|
501
|
+
* the wrapped result is a failure.
|
|
502
|
+
* @param cb - The {@link ErrorFormatter | error formatter} to
|
|
503
|
+
* be called in the event of failure.
|
|
504
|
+
* @returns A new {@link AsyncResult} with the formatted error message,
|
|
505
|
+
* or the original success result.
|
|
506
|
+
*/
|
|
507
|
+
withErrorFormat(cb: ErrorFormatter): AsyncResult<T>;
|
|
508
|
+
/**
|
|
509
|
+
* Propagates the wrapped result, appending any error message to the
|
|
510
|
+
* supplied errors aggregator.
|
|
511
|
+
* @param errors - {@link IMessageAggregator | Error aggregator} in which
|
|
512
|
+
* errors will be aggregated.
|
|
513
|
+
* @param formatter - An optional {@link ErrorFormatter | error formatter}
|
|
514
|
+
* to be used to format the error message.
|
|
515
|
+
* @returns A new {@link AsyncResult} wrapping the result after aggregation.
|
|
516
|
+
*/
|
|
517
|
+
aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): AsyncResult<T>;
|
|
518
|
+
/**
|
|
519
|
+
* Reports the wrapped result to the supplied reporter.
|
|
520
|
+
* @param reporter - The {@link IResultReporter | reporter} to which the result
|
|
521
|
+
* will be reported.
|
|
522
|
+
* @param options - The {@link IResultReportOptions | options} for reporting the result.
|
|
523
|
+
* @returns A new {@link AsyncResult} wrapping the result after reporting.
|
|
524
|
+
*/
|
|
525
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): AsyncResult<T>;
|
|
526
|
+
/**
|
|
527
|
+
* Implementation of `PromiseLike.then` enabling `await` on {@link AsyncResult}.
|
|
528
|
+
* @param onfulfilled - Callback invoked when the promise resolves.
|
|
529
|
+
* @param onrejected - Callback invoked when the promise rejects.
|
|
530
|
+
* @returns A `Promise` resolving to the callback result.
|
|
531
|
+
*/
|
|
532
|
+
then<TResult1 = Result<T>, TResult2 = never>(onfulfilled?: ((value: Result<T>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
533
|
+
/**
|
|
534
|
+
* Creates an {@link AsyncResult} from a {@link Result}.
|
|
535
|
+
* @param result - The {@link Result} to wrap.
|
|
536
|
+
* @returns A new {@link AsyncResult} wrapping the supplied result.
|
|
537
|
+
*/
|
|
538
|
+
static from<T>(result: Result<T>): AsyncResult<T>;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Async continuation callback to be called in the event that a
|
|
543
|
+
* {@link Result} is successful, returning a `Promise` of a new {@link Result}.
|
|
544
|
+
* @public
|
|
545
|
+
*/
|
|
546
|
+
export declare type AsyncSuccessContinuation<T, TN> = (value: T) => Promise<Result<TN>>;
|
|
547
|
+
|
|
423
548
|
declare namespace Base {
|
|
424
549
|
export {
|
|
425
550
|
GenericValidatorConstructorParams,
|
|
@@ -454,63 +579,146 @@ declare class BaseConverter<T, TC = unknown> implements Converter<T, TC> {
|
|
|
454
579
|
*/
|
|
455
580
|
constructor(converter: ConverterFunc<T, TC>, defaultContext?: TC, traits?: ConverterTraits);
|
|
456
581
|
/**
|
|
457
|
-
*
|
|
582
|
+
* Indicates whether this element is explicitly optional.
|
|
458
583
|
*/
|
|
459
584
|
get isOptional(): boolean;
|
|
460
585
|
/**
|
|
461
|
-
*
|
|
586
|
+
* Returns the brand for a branded type.
|
|
462
587
|
*/
|
|
463
588
|
get brand(): string | undefined;
|
|
464
589
|
/**
|
|
465
|
-
*
|
|
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.
|
|
466
597
|
*/
|
|
467
598
|
convert(from: unknown, context?: TC): Result<T>;
|
|
468
599
|
/**
|
|
469
|
-
*
|
|
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.
|
|
470
615
|
*/
|
|
471
616
|
convertOptional(from: unknown, context?: TC, onError?: OnError): Result<T | undefined>;
|
|
472
617
|
/**
|
|
473
|
-
* {@
|
|
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>`.
|
|
474
630
|
*/
|
|
475
631
|
optional(onError?: OnError): Converter<T | undefined, TC>;
|
|
476
632
|
/**
|
|
477
|
-
* {@
|
|
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>`.
|
|
478
638
|
*/
|
|
479
639
|
map<T2>(mapper: (from: T, context?: TC) => Result<T2>): Converter<T2, TC>;
|
|
480
640
|
/**
|
|
481
|
-
* {@
|
|
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>`.
|
|
482
647
|
*/
|
|
483
648
|
mapConvert<T2>(mapConverter: Converter<T2>): Converter<T2, TC>;
|
|
484
649
|
/**
|
|
485
|
-
* {@
|
|
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[]>`.
|
|
486
659
|
*/
|
|
487
660
|
mapItems<TI>(mapper: (from: unknown, context?: TC) => Result<TI>): Converter<TI[], TC>;
|
|
488
661
|
/**
|
|
489
|
-
* {@
|
|
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[]>`.
|
|
490
671
|
*/
|
|
491
672
|
mapConvertItems<TI>(mapConverter: Converter<TI, unknown>): Converter<TI[], TC>;
|
|
492
673
|
/**
|
|
493
|
-
* {@
|
|
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.
|
|
494
678
|
*/
|
|
495
679
|
withAction<TI>(action: (result: Result<T>, context?: TC) => Result<TI>): Converter<TI, TC>;
|
|
496
680
|
/**
|
|
497
|
-
* {@
|
|
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>`.
|
|
498
686
|
*/
|
|
499
687
|
withTypeGuard<TI>(guard: (from: unknown, context?: TC) => from is TI, message?: string): Converter<TI, TC>;
|
|
500
688
|
/**
|
|
501
|
-
* {@
|
|
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>`.
|
|
502
698
|
*/
|
|
503
699
|
withItemTypeGuard<TI>(guard: (from: unknown, context?: TC) => from is TI, message?: string): Converter<TI[], TC>;
|
|
504
700
|
/**
|
|
505
|
-
* {@
|
|
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>`.
|
|
506
710
|
*/
|
|
507
711
|
withConstraint(constraint: (val: T, context?: TC) => boolean | Result<T>, options?: ConstraintOptions): Converter<T, TC>;
|
|
508
712
|
/**
|
|
509
|
-
*
|
|
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>`.
|
|
510
717
|
*/
|
|
511
718
|
withBrand<B extends string>(brand: B): Converter<Brand<T, B>, TC>;
|
|
512
719
|
/**
|
|
513
|
-
*
|
|
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.
|
|
514
722
|
*/
|
|
515
723
|
withDefault<TD = T>(defaultValue: TD): DefaultingConverter<T, TD, TC>;
|
|
516
724
|
or(other: Converter<T, TC>): Converter<T, TC>;
|
|
@@ -519,7 +727,10 @@ declare class BaseConverter<T, TC = unknown> implements Converter<T, TC> {
|
|
|
519
727
|
*/
|
|
520
728
|
protected _context(supplied?: TC): TC | undefined;
|
|
521
729
|
/**
|
|
522
|
-
* {@
|
|
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>`.
|
|
523
734
|
*/
|
|
524
735
|
withFormattedError(formatter: ConversionErrorFormatter<TC>): Converter<T, TC>;
|
|
525
736
|
/**
|
|
@@ -778,13 +989,23 @@ declare class CacheInvalidatingResultMapWrapper<TK extends string, TSRC, TTARGET
|
|
|
778
989
|
toReadOnly(): IReadOnlyResultMap<TK, TSRC>;
|
|
779
990
|
}
|
|
780
991
|
|
|
992
|
+
/**
|
|
993
|
+
* Wraps an async function which might throw to convert exception results
|
|
994
|
+
* to {@link Failure}.
|
|
995
|
+
* @param func - The async function to be captured.
|
|
996
|
+
* @returns Returns a `Promise` of {@link Success} with a value of type `<T>` on
|
|
997
|
+
* success, or {@link Failure} with the thrown error message if `func` throws or rejects.
|
|
998
|
+
* @public
|
|
999
|
+
*/
|
|
1000
|
+
export declare function captureAsyncResult<T>(func: () => Promise<T>): Promise<Result<T>>;
|
|
1001
|
+
|
|
781
1002
|
/**
|
|
782
1003
|
* Wraps a function which might throw to convert exception results
|
|
783
1004
|
* to {@link Failure}.
|
|
784
1005
|
* @param func - The function to be captured.
|
|
785
1006
|
* @returns Returns {@link Success} with a value of type `<T>` on
|
|
786
1007
|
* success , or {@link Failure} with the thrown error message if
|
|
787
|
-
* `func` throws an `Error
|
|
1008
|
+
* `func` throws an `Error` or string.
|
|
788
1009
|
* @public
|
|
789
1010
|
*/
|
|
790
1011
|
export declare function captureResult<T>(func: () => T): Result<T>;
|
|
@@ -987,7 +1208,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
987
1208
|
private readonly _byKey;
|
|
988
1209
|
private readonly _byIndex;
|
|
989
1210
|
/**
|
|
990
|
-
*
|
|
1211
|
+
* Returns the number of entries in the map.
|
|
991
1212
|
*/
|
|
992
1213
|
get size(): number;
|
|
993
1214
|
/**
|
|
@@ -1014,19 +1235,28 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1014
1235
|
*/
|
|
1015
1236
|
add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1016
1237
|
/**
|
|
1017
|
-
*
|
|
1238
|
+
* Returns an iterator over the map entries.
|
|
1239
|
+
* @returns An iterator over the map entries.
|
|
1018
1240
|
*/
|
|
1019
1241
|
entries(): IterableIterator<KeyValueEntry<CollectibleKey<TITEM>, TITEM>>;
|
|
1020
1242
|
/**
|
|
1021
|
-
*
|
|
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.
|
|
1022
1246
|
*/
|
|
1023
1247
|
forEach(callback: ResultMapForEachCb<CollectibleKey<TITEM>, TITEM>, arg?: unknown): void;
|
|
1024
1248
|
/**
|
|
1025
|
-
*
|
|
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.
|
|
1026
1253
|
*/
|
|
1027
1254
|
get(key: CollectibleKey<TITEM>): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
1028
1255
|
/**
|
|
1029
|
-
*
|
|
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.
|
|
1030
1260
|
*/
|
|
1031
1261
|
getAt(index: number): Result<TITEM>;
|
|
1032
1262
|
/**
|
|
@@ -1051,19 +1281,24 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1051
1281
|
*/
|
|
1052
1282
|
getOrAdd(key: CollectibleKey<TITEM>, factory: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1053
1283
|
/**
|
|
1054
|
-
*
|
|
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.
|
|
1055
1287
|
*/
|
|
1056
1288
|
has(key: CollectibleKey<TITEM>): boolean;
|
|
1057
1289
|
/**
|
|
1058
|
-
*
|
|
1290
|
+
* Returns an iterator over the map keys.
|
|
1291
|
+
* @returns An iterator over the map keys.
|
|
1059
1292
|
*/
|
|
1060
1293
|
keys(): IterableIterator<CollectibleKey<TITEM>>;
|
|
1061
1294
|
/**
|
|
1062
|
-
*
|
|
1295
|
+
* Returns an iterator over the map values.
|
|
1296
|
+
* @returns An iterator over the map values.
|
|
1063
1297
|
*/
|
|
1064
1298
|
values(): IterableIterator<TITEM>;
|
|
1065
1299
|
/**
|
|
1066
|
-
*
|
|
1300
|
+
* Gets all items in the collection, ordered by index.
|
|
1301
|
+
* @returns An array of items in the collection, ordered by index.
|
|
1067
1302
|
*/
|
|
1068
1303
|
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
1069
1304
|
/**
|
|
@@ -1099,7 +1334,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1099
1334
|
*/
|
|
1100
1335
|
constructor(params: ICollectorValidatorCreateParams<TITEM>);
|
|
1101
1336
|
/**
|
|
1102
|
-
*
|
|
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.
|
|
1103
1343
|
*/
|
|
1104
1344
|
add(item: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1105
1345
|
/**
|
|
@@ -1107,12 +1347,24 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1107
1347
|
*/
|
|
1108
1348
|
get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
1109
1349
|
/**
|
|
1110
|
-
*
|
|
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.
|
|
1111
1358
|
*/
|
|
1112
1359
|
getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1113
1360
|
/**
|
|
1114
|
-
*
|
|
1115
|
-
*
|
|
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.
|
|
1116
1368
|
*/
|
|
1117
1369
|
getOrAdd(item: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1118
1370
|
/**
|
|
@@ -1577,7 +1829,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1577
1829
|
*/
|
|
1578
1830
|
static createConvertingCollector<TITEM extends ICollectible<any, any>, TSRC = TITEM>(params: IConvertingCollectorConstructorParams<TITEM, TSRC>): Result<ConvertingCollector<TITEM, TSRC>>;
|
|
1579
1831
|
/**
|
|
1580
|
-
*
|
|
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.
|
|
1581
1838
|
*/
|
|
1582
1839
|
add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1583
1840
|
/**
|
|
@@ -1600,11 +1857,24 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1600
1857
|
*/
|
|
1601
1858
|
add(key: CollectibleKey<TITEM>, cb: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1602
1859
|
/**
|
|
1603
|
-
*
|
|
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.
|
|
1604
1867
|
*/
|
|
1605
1868
|
getOrAdd(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1606
1869
|
/**
|
|
1607
|
-
*
|
|
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.
|
|
1608
1878
|
*/
|
|
1609
1879
|
getOrAdd(key: CollectibleKey<TITEM>, callback: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1610
1880
|
/**
|
|
@@ -1662,7 +1932,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1662
1932
|
*/
|
|
1663
1933
|
constructor(params: IConvertingCollectorValidatorCreateParams<TITEM, TSRC>);
|
|
1664
1934
|
/**
|
|
1665
|
-
*
|
|
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.
|
|
1666
1941
|
*/
|
|
1667
1942
|
add(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1668
1943
|
/**
|
|
@@ -1675,11 +1950,25 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1675
1950
|
*/
|
|
1676
1951
|
get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
|
|
1677
1952
|
/**
|
|
1678
|
-
*
|
|
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.
|
|
1679
1961
|
*/
|
|
1680
1962
|
getOrAdd(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1681
1963
|
/**
|
|
1682
|
-
*
|
|
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.
|
|
1683
1972
|
*/
|
|
1684
1973
|
getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
1685
1974
|
/**
|
|
@@ -2070,6 +2359,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2070
2359
|
*/
|
|
2071
2360
|
export declare type ErrorFormatter<TD = unknown> = (message: string, detail?: TD) => string;
|
|
2072
2361
|
|
|
2362
|
+
/**
|
|
2363
|
+
* Extracts a message string from an unknown thrown/rejected value.
|
|
2364
|
+
* @param err - The caught error value.
|
|
2365
|
+
* @returns The error message string.
|
|
2366
|
+
* @internal
|
|
2367
|
+
*/
|
|
2368
|
+
export declare function _errorMessage(err: unknown): string;
|
|
2369
|
+
|
|
2073
2370
|
/**
|
|
2074
2371
|
* Returns {@link Failure | Failure<T>} with the supplied error message.
|
|
2075
2372
|
* @param message - Error message to be returned.
|
|
@@ -2161,6 +2458,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2161
2458
|
* {@inheritDoc IResult.onFailure}
|
|
2162
2459
|
*/
|
|
2163
2460
|
onFailure(cb: FailureContinuation<T>): Result<T>;
|
|
2461
|
+
/**
|
|
2462
|
+
* {@inheritDoc IResult.thenOnSuccess}
|
|
2463
|
+
*/
|
|
2464
|
+
thenOnSuccess<TN>(__: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;
|
|
2465
|
+
/**
|
|
2466
|
+
* {@inheritDoc IResult.thenOnFailure}
|
|
2467
|
+
*/
|
|
2468
|
+
thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T>;
|
|
2164
2469
|
/**
|
|
2165
2470
|
* {@inheritDoc IResult.withErrorFormat}
|
|
2166
2471
|
*/
|
|
@@ -3016,7 +3321,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3016
3321
|
*/
|
|
3017
3322
|
has(key: string): boolean;
|
|
3018
3323
|
/**
|
|
3019
|
-
*
|
|
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.
|
|
3020
3332
|
*/
|
|
3021
3333
|
getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
3022
3334
|
}
|
|
@@ -3053,31 +3365,42 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3053
3365
|
*/
|
|
3054
3366
|
export declare interface IReadOnlyResultMap<TK extends string = string, TV = unknown> {
|
|
3055
3367
|
/**
|
|
3056
|
-
*
|
|
3368
|
+
* Returns the number of entries in the map.
|
|
3057
3369
|
*/
|
|
3058
3370
|
readonly size: number;
|
|
3059
3371
|
/**
|
|
3060
|
-
*
|
|
3372
|
+
* Returns an iterator over the map entries.
|
|
3373
|
+
* @returns An iterator over the map entries.
|
|
3061
3374
|
*/
|
|
3062
3375
|
entries(): IterableIterator<KeyValueEntry<TK, TV>>;
|
|
3063
3376
|
/**
|
|
3064
|
-
*
|
|
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.
|
|
3065
3380
|
*/
|
|
3066
3381
|
forEach(cb: ResultMapForEachCb, arg?: unknown): void;
|
|
3067
3382
|
/**
|
|
3068
|
-
*
|
|
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.
|
|
3069
3388
|
*/
|
|
3070
3389
|
get(key: TK): DetailedResult<TV, ResultMapResultDetail>;
|
|
3071
3390
|
/**
|
|
3072
|
-
*
|
|
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.
|
|
3073
3394
|
*/
|
|
3074
3395
|
has(key: TK): boolean;
|
|
3075
3396
|
/**
|
|
3076
|
-
*
|
|
3397
|
+
* Returns an iterator over the map keys.
|
|
3398
|
+
* @returns An iterator over the map keys.
|
|
3077
3399
|
*/
|
|
3078
3400
|
keys(): IterableIterator<TK>;
|
|
3079
3401
|
/**
|
|
3080
|
-
*
|
|
3402
|
+
* Returns an iterator over the map values.
|
|
3403
|
+
* @returns An iterator over the map values.
|
|
3081
3404
|
*/
|
|
3082
3405
|
values(): IterableIterator<TV>;
|
|
3083
3406
|
/**
|
|
@@ -3113,15 +3436,19 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3113
3436
|
*/
|
|
3114
3437
|
declare interface IReadOnlyValidatingCollector<TITEM extends ICollectible<any, any>> extends IReadOnlyValidatingResultMap<CollectibleKey<TITEM>, TITEM> {
|
|
3115
3438
|
/**
|
|
3116
|
-
* {@
|
|
3439
|
+
* A {@link Collections.CollectorValidator | CollectorValidator} which validates keys and values
|
|
3440
|
+
* before inserting them into this collector.
|
|
3117
3441
|
*/
|
|
3118
3442
|
readonly validating: IReadOnlyCollectorValidator<TITEM>;
|
|
3119
3443
|
/**
|
|
3120
|
-
*
|
|
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.
|
|
3121
3447
|
*/
|
|
3122
3448
|
getAt(index: number): Result<TITEM>;
|
|
3123
3449
|
/**
|
|
3124
|
-
*
|
|
3450
|
+
* Gets all items in the collection, ordered by index.
|
|
3451
|
+
* @returns An array of items in the collection, ordered by index.
|
|
3125
3452
|
*/
|
|
3126
3453
|
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
3127
3454
|
}
|
|
@@ -3132,7 +3459,8 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3132
3459
|
*/
|
|
3133
3460
|
declare interface IReadOnlyValidatingResultMap<TK extends string = string, TV = unknown> extends IReadOnlyResultMap<TK, TV> {
|
|
3134
3461
|
/**
|
|
3135
|
-
* {@
|
|
3462
|
+
* A {@link Collections.ResultMapValidator | ResultMapValidator} which validates keys and values
|
|
3463
|
+
* before inserting them into this collection.
|
|
3136
3464
|
*/
|
|
3137
3465
|
readonly validating: IReadOnlyResultMapValidator<TK, TV>;
|
|
3138
3466
|
}
|
|
@@ -3276,6 +3604,30 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3276
3604
|
* was successful, propagates the result value from the successful event.
|
|
3277
3605
|
*/
|
|
3278
3606
|
onFailure(cb: FailureContinuation<T>): Result<T>;
|
|
3607
|
+
/**
|
|
3608
|
+
* Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if
|
|
3609
|
+
* the operation was a success, bridging into an {@link AsyncResult} chain.
|
|
3610
|
+
* @remarks
|
|
3611
|
+
* If the async callback rejects, the rejection is caught and converted
|
|
3612
|
+
* to a {@link Failure}.
|
|
3613
|
+
* @param cb - The {@link AsyncSuccessContinuation | async success continuation} to
|
|
3614
|
+
* be called in the event of success.
|
|
3615
|
+
* @returns An {@link AsyncResult} wrapping the async continuation result, or
|
|
3616
|
+
* propagating the error message from this failure.
|
|
3617
|
+
*/
|
|
3618
|
+
thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;
|
|
3619
|
+
/**
|
|
3620
|
+
* Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if
|
|
3621
|
+
* the operation failed, bridging into an {@link AsyncResult} chain.
|
|
3622
|
+
* @remarks
|
|
3623
|
+
* If the async callback rejects, the rejection is caught and converted
|
|
3624
|
+
* to a {@link Failure}.
|
|
3625
|
+
* @param cb - The {@link AsyncFailureContinuation | async failure continuation} to
|
|
3626
|
+
* be called in the event of failure.
|
|
3627
|
+
* @returns An {@link AsyncResult} wrapping the async continuation result, or
|
|
3628
|
+
* propagating the success value from this result.
|
|
3629
|
+
*/
|
|
3630
|
+
thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T>;
|
|
3279
3631
|
/**
|
|
3280
3632
|
* Calls a supplied {@link ErrorFormatter | error formatter} if
|
|
3281
3633
|
* the operation failed.
|
|
@@ -3750,36 +4102,61 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3750
4102
|
*/
|
|
3751
4103
|
declare abstract class LoggerBase implements IDetailLogger {
|
|
3752
4104
|
/**
|
|
3753
|
-
*
|
|
4105
|
+
* The level of logging to be used.
|
|
3754
4106
|
*/
|
|
3755
4107
|
logLevel: ReporterLogLevel;
|
|
3756
4108
|
protected constructor(logLevel?: ReporterLogLevel);
|
|
3757
4109
|
/**
|
|
3758
|
-
*
|
|
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.
|
|
3759
4115
|
*/
|
|
3760
4116
|
detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3761
4117
|
/**
|
|
3762
|
-
*
|
|
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.
|
|
3763
4123
|
*/
|
|
3764
4124
|
info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3765
4125
|
/**
|
|
3766
|
-
*
|
|
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.
|
|
3767
4131
|
*/
|
|
3768
4132
|
warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3769
4133
|
/**
|
|
3770
|
-
*
|
|
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.
|
|
3771
4139
|
*/
|
|
3772
4140
|
error(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3773
4141
|
/**
|
|
3774
|
-
*
|
|
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.
|
|
3775
4145
|
*/
|
|
3776
4146
|
errorWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
3777
4147
|
/**
|
|
3778
|
-
*
|
|
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.
|
|
3779
4151
|
*/
|
|
3780
4152
|
warnWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
3781
4153
|
/**
|
|
3782
|
-
*
|
|
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.
|
|
3783
4160
|
*/
|
|
3784
4161
|
log(level: MessageLogLevel, message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3785
4162
|
/**
|
|
@@ -5557,6 +5934,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
5557
5934
|
* {@inheritDoc IResult.onFailure}
|
|
5558
5935
|
*/
|
|
5559
5936
|
onFailure(__: FailureContinuation<T>): Result<T>;
|
|
5937
|
+
/**
|
|
5938
|
+
* {@inheritDoc IResult.thenOnSuccess}
|
|
5939
|
+
*/
|
|
5940
|
+
thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;
|
|
5941
|
+
/**
|
|
5942
|
+
* {@inheritDoc IResult.thenOnFailure}
|
|
5943
|
+
*/
|
|
5944
|
+
thenOnFailure(__: AsyncFailureContinuation<T>): AsyncResult<T>;
|
|
5560
5945
|
/**
|
|
5561
5946
|
* {@inheritDoc IResult.withErrorFormat}
|
|
5562
5947
|
*/
|