@fgv/ts-utils 5.1.0-3 → 5.1.0-31
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 +2 -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 +54 -1
- package/dist/packlets/base/normalize.js.map +1 -0
- package/dist/packlets/base/result.js +299 -2
- package/dist/packlets/base/result.js.map +1 -0
- package/dist/packlets/base/shouldNotFail.js +123 -0
- package/dist/packlets/base/shouldNotFail.js.map +1 -0
- package/dist/packlets/base/utils.js.map +1 -0
- package/dist/packlets/base/uuid.js +55 -0
- package/dist/packlets/base/uuid.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 +2 -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 +49 -8
- package/dist/packlets/logging/logger.js.map +1 -0
- package/dist/packlets/logging/multiLogger.js +104 -0
- package/dist/packlets/logging/multiLogger.js.map +1 -0
- package/dist/packlets/logging/retainingLogger.js +161 -0
- package/dist/packlets/logging/retainingLogger.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 +861 -57
- 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 +2 -0
- package/lib/packlets/base/index.d.ts.map +1 -0
- package/lib/packlets/base/index.js +2 -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 +24 -0
- package/lib/packlets/base/normalize.d.ts.map +1 -0
- package/lib/packlets/base/normalize.js +53 -0
- package/lib/packlets/base/normalize.js.map +1 -0
- package/lib/packlets/base/result.d.ts +263 -1
- package/lib/packlets/base/result.d.ts.map +1 -0
- package/lib/packlets/base/result.js +303 -3
- package/lib/packlets/base/result.js.map +1 -0
- package/lib/packlets/base/shouldNotFail.d.ts +53 -0
- package/lib/packlets/base/shouldNotFail.d.ts.map +1 -0
- package/lib/packlets/base/shouldNotFail.js +129 -0
- package/lib/packlets/base/shouldNotFail.js.map +1 -0
- package/lib/packlets/base/utils.d.ts +12 -0
- package/lib/packlets/base/utils.d.ts.map +1 -0
- package/lib/packlets/base/utils.js.map +1 -0
- package/lib/packlets/base/uuid.d.ts +27 -0
- package/lib/packlets/base/uuid.d.ts.map +1 -0
- package/lib/packlets/base/uuid.js +59 -0
- package/lib/packlets/base/uuid.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 +2 -0
- package/lib/packlets/logging/index.d.ts.map +1 -0
- package/lib/packlets/logging/index.js +2 -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 +46 -8
- package/lib/packlets/logging/logger.d.ts.map +1 -0
- package/lib/packlets/logging/logger.js +49 -8
- package/lib/packlets/logging/logger.js.map +1 -0
- package/lib/packlets/logging/multiLogger.d.ts +54 -0
- package/lib/packlets/logging/multiLogger.d.ts.map +1 -0
- package/lib/packlets/logging/multiLogger.js +108 -0
- package/lib/packlets/logging/multiLogger.js.map +1 -0
- package/lib/packlets/logging/retainingLogger.d.ts +143 -0
- package/lib/packlets/logging/retainingLogger.d.ts.map +1 -0
- package/lib/packlets/logging/retainingLogger.js +165 -0
- package/lib/packlets/logging/retainingLogger.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 +6 -4
- 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.
|
|
@@ -2135,6 +2432,10 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2135
2432
|
* {@inheritDoc IResult.orThrow}
|
|
2136
2433
|
*/
|
|
2137
2434
|
orThrow(cb: ErrorFormatter): never;
|
|
2435
|
+
/**
|
|
2436
|
+
* {@inheritDoc IResult.shouldNotFail}
|
|
2437
|
+
*/
|
|
2438
|
+
shouldNotFail(label?: string, frameDepth?: number): never;
|
|
2138
2439
|
/**
|
|
2139
2440
|
* {@inheritDoc IResult.orDefault}
|
|
2140
2441
|
*/
|
|
@@ -2161,6 +2462,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2161
2462
|
* {@inheritDoc IResult.onFailure}
|
|
2162
2463
|
*/
|
|
2163
2464
|
onFailure(cb: FailureContinuation<T>): Result<T>;
|
|
2465
|
+
/**
|
|
2466
|
+
* {@inheritDoc IResult.thenOnSuccess}
|
|
2467
|
+
*/
|
|
2468
|
+
thenOnSuccess<TN>(__: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;
|
|
2469
|
+
/**
|
|
2470
|
+
* {@inheritDoc IResult.thenOnFailure}
|
|
2471
|
+
*/
|
|
2472
|
+
thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T>;
|
|
2164
2473
|
/**
|
|
2165
2474
|
* {@inheritDoc IResult.withErrorFormat}
|
|
2166
2475
|
*/
|
|
@@ -2181,6 +2490,41 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2181
2490
|
* {@inheritDoc IResult.report}
|
|
2182
2491
|
*/
|
|
2183
2492
|
report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Failure<T>;
|
|
2493
|
+
/**
|
|
2494
|
+
* Re-types this {@link Failure | Failure<T>} as {@link Failure | Failure<U>} for
|
|
2495
|
+
* propagation under a different success type.
|
|
2496
|
+
* @remarks
|
|
2497
|
+
* Supports the canonical Result early-return-after-`isFailure()` pattern when the
|
|
2498
|
+
* outer function's success type differs from the inner Result's success type:
|
|
2499
|
+
*
|
|
2500
|
+
* ```ts
|
|
2501
|
+
* const storeResult = await PromptStoreFixture.build(seed);
|
|
2502
|
+
* if (storeResult.isFailure()) {
|
|
2503
|
+
* return storeResult.withType<PromptLibrary>();
|
|
2504
|
+
* }
|
|
2505
|
+
* return PromptLibrary.create({ store: storeResult.value, ... });
|
|
2506
|
+
* ```
|
|
2507
|
+
*
|
|
2508
|
+
* Without this helper, TypeScript rejects `return storeResult` because
|
|
2509
|
+
* `Failure<IPromptStore>` is invariant in `T` and not assignable to
|
|
2510
|
+
* `Result<PromptLibrary>`. The workaround `return fail<U>(r.message)` is
|
|
2511
|
+
* semantically equivalent but allocates a new {@link Failure} instance;
|
|
2512
|
+
* `withType` returns `this` and only retypes statically.
|
|
2513
|
+
*
|
|
2514
|
+
* This method is sound because a {@link Failure} variant carries no `T`-shaped
|
|
2515
|
+
* data — only an error message — so re-typing it as `Failure<U>` cannot
|
|
2516
|
+
* misrepresent any value. The same operation is NOT exposed on {@link Success}
|
|
2517
|
+
* because `Success<T>` carries `T`-shaped data and re-typing would be a lie.
|
|
2518
|
+
*
|
|
2519
|
+
* For `DetailedResult` propagation that preserves a typed `detail`, consider
|
|
2520
|
+
* propagating the {@link DetailedFailure} directly through `onSuccess` (which
|
|
2521
|
+
* already re-types the success arm) rather than reaching for `withType`.
|
|
2522
|
+
*
|
|
2523
|
+
* @returns This same {@link Failure} instance, statically retyped as
|
|
2524
|
+
* {@link Failure | Failure<U>}.
|
|
2525
|
+
* @public
|
|
2526
|
+
*/
|
|
2527
|
+
withType<U>(): Failure<U>;
|
|
2184
2528
|
/**
|
|
2185
2529
|
* Get a 'friendly' string representation of this object.
|
|
2186
2530
|
* @remarks
|
|
@@ -2280,6 +2624,20 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2280
2624
|
[key in keyof T]: Validator<T[key], TC>;
|
|
2281
2625
|
};
|
|
2282
2626
|
|
|
2627
|
+
/**
|
|
2628
|
+
* Finds the caller frame at the supplied depth in a stack string.
|
|
2629
|
+
*
|
|
2630
|
+
* Filters out frames whose **parsed function name** contains `shouldNotFail`
|
|
2631
|
+
* (the file path is deliberately NOT inspected — consumer test files may
|
|
2632
|
+
* themselves be named after `shouldNotFail` and their frames must not be
|
|
2633
|
+
* filtered out). Covers both the V8 path — where `Error.captureStackTrace`
|
|
2634
|
+
* should have done this already but the extra filter is harmless — and the
|
|
2635
|
+
* WebKit fallback path where `captureStackTrace` is unavailable. `frameDepth`
|
|
2636
|
+
* is 1-indexed: `1` selects the immediate caller.
|
|
2637
|
+
* @internal
|
|
2638
|
+
*/
|
|
2639
|
+
export declare function _findShouldNotFailFrame(stack: string | undefined, frameDepth: number): _IShouldNotFailFrame;
|
|
2640
|
+
|
|
2283
2641
|
/**
|
|
2284
2642
|
* Returns the first successful result from a collection of {@link Result | Result<T>} or {@link DeferredResult | DeferredResult<T>}.
|
|
2285
2643
|
* @param results - The collection of {@link Result | Result<T>} or {@link DeferredResult | DeferredResult<T>} to be tested.
|
|
@@ -2288,6 +2646,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2288
2646
|
*/
|
|
2289
2647
|
export declare function firstSuccess<T>(results: Iterable<Result<T> | DeferredResult<T>>): Result<T>;
|
|
2290
2648
|
|
|
2649
|
+
/**
|
|
2650
|
+
* Composes the error message thrown by `Result<T>.shouldNotFail` from the
|
|
2651
|
+
* captured frame and optional label.
|
|
2652
|
+
* @internal
|
|
2653
|
+
*/
|
|
2654
|
+
export declare function _formatShouldNotFailMessage(originalMessage: string, label: string | undefined, frame: _IShouldNotFailFrame): string;
|
|
2655
|
+
|
|
2291
2656
|
/**
|
|
2292
2657
|
* A {@link Validation.ConstraintTrait | ConstraintTrait} indicating that
|
|
2293
2658
|
* a {@link Validation.Constraint | Constraint<T>} function provides an
|
|
@@ -2298,6 +2663,18 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2298
2663
|
type: 'function';
|
|
2299
2664
|
}
|
|
2300
2665
|
|
|
2666
|
+
/**
|
|
2667
|
+
* Generates a cryptographically random UUIDv4 using the platform's Web Crypto
|
|
2668
|
+
* API (`globalThis.crypto.randomUUID`). Works in Node.js \>= 18 and modern
|
|
2669
|
+
* browsers without per-call runtime checks.
|
|
2670
|
+
* @returns A new {@link Uuid}.
|
|
2671
|
+
* @throws An `Error` if the runtime does not expose `globalThis.crypto.randomUUID`.
|
|
2672
|
+
* This indicates an unsupported platform, not a per-call failure mode, so it is
|
|
2673
|
+
* surfaced as a thrown error rather than a `Result`.
|
|
2674
|
+
* @public
|
|
2675
|
+
*/
|
|
2676
|
+
export declare function generateUuid(): Uuid;
|
|
2677
|
+
|
|
2301
2678
|
/**
|
|
2302
2679
|
* Helper function to create a {@link Converter | Converter} from a supplied {@link Conversion.ConverterFunc | ConverterFunc}.
|
|
2303
2680
|
* @param convert - the function to be wrapped
|
|
@@ -2760,6 +3137,28 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2760
3137
|
warnWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
2761
3138
|
}
|
|
2762
3139
|
|
|
3140
|
+
/**
|
|
3141
|
+
* Options for {@link Logging.RetainingLogger.getRecords | RetainingLogger.getRecords}.
|
|
3142
|
+
* @public
|
|
3143
|
+
*/
|
|
3144
|
+
declare interface IGetRecordsOptions {
|
|
3145
|
+
/**
|
|
3146
|
+
* If supplied, only records whose level would be emitted at this threshold
|
|
3147
|
+
* (per {@link Logging.shouldLog | shouldLog}) are returned.
|
|
3148
|
+
*/
|
|
3149
|
+
readonly minLevel?: ReporterLogLevel;
|
|
3150
|
+
/**
|
|
3151
|
+
* If supplied, only records with `seq > sinceSeq` are returned, enabling
|
|
3152
|
+
* incremental paging from a previously-held cursor.
|
|
3153
|
+
*/
|
|
3154
|
+
readonly sinceSeq?: number;
|
|
3155
|
+
/**
|
|
3156
|
+
* If supplied, returns at most this many records — the most recent N (tail),
|
|
3157
|
+
* still ordered oldest-first.
|
|
3158
|
+
*/
|
|
3159
|
+
readonly limit?: number;
|
|
3160
|
+
}
|
|
3161
|
+
|
|
2763
3162
|
/**
|
|
2764
3163
|
* Parameters for constructing a {@link Collections.KeyValueConverters | KeyValueConverters} instance.
|
|
2765
3164
|
* @public
|
|
@@ -2829,6 +3228,34 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2829
3228
|
error(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
2830
3229
|
}
|
|
2831
3230
|
|
|
3231
|
+
/**
|
|
3232
|
+
* A retained log record. Preserves the level and an ordering cursor so consumers
|
|
3233
|
+
* can filter by severity and page incrementally.
|
|
3234
|
+
* @public
|
|
3235
|
+
*/
|
|
3236
|
+
declare interface ILogRecord {
|
|
3237
|
+
/**
|
|
3238
|
+
* Monotonic 1-based sequence number, stable across ring eviction.
|
|
3239
|
+
*/
|
|
3240
|
+
readonly seq: number;
|
|
3241
|
+
/**
|
|
3242
|
+
* Milliseconds since epoch when the record was logged (from the injected clock).
|
|
3243
|
+
*/
|
|
3244
|
+
readonly timestamp: number;
|
|
3245
|
+
/**
|
|
3246
|
+
* The level the record was logged at.
|
|
3247
|
+
*/
|
|
3248
|
+
readonly level: MessageLogLevel;
|
|
3249
|
+
/**
|
|
3250
|
+
* The formatted message (same formatting {@link Logging.LoggerBase._format | LoggerBase._format} produces).
|
|
3251
|
+
*/
|
|
3252
|
+
readonly message: string;
|
|
3253
|
+
/**
|
|
3254
|
+
* The raw structured inputs `[message, ...parameters]` before formatting.
|
|
3255
|
+
*/
|
|
3256
|
+
readonly args?: readonly unknown[];
|
|
3257
|
+
}
|
|
3258
|
+
|
|
2832
3259
|
/**
|
|
2833
3260
|
* Parameters for creating a {@link Logging.LogReporter | LogReporter}.
|
|
2834
3261
|
* @public
|
|
@@ -3016,7 +3443,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3016
3443
|
*/
|
|
3017
3444
|
has(key: string): boolean;
|
|
3018
3445
|
/**
|
|
3019
|
-
*
|
|
3446
|
+
* Gets an existing item with a key matching the supplied key, or adds a new item to the collector
|
|
3447
|
+
* using a factory callback if no item with that key exists.
|
|
3448
|
+
* @param key - The weakly-typed key of the item to get or add.
|
|
3449
|
+
* @param factory - The factory callback to create the item.
|
|
3450
|
+
* @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -
|
|
3451
|
+
* detail `exists` indicates that an existing item was returned and detail `added` indicates
|
|
3452
|
+
* that the item was added. Returns {@link DetailedFailure | Failure} with an error and
|
|
3453
|
+
* appropriate detail if the item could not be added.
|
|
3020
3454
|
*/
|
|
3021
3455
|
getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
|
|
3022
3456
|
}
|
|
@@ -3053,31 +3487,42 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3053
3487
|
*/
|
|
3054
3488
|
export declare interface IReadOnlyResultMap<TK extends string = string, TV = unknown> {
|
|
3055
3489
|
/**
|
|
3056
|
-
*
|
|
3490
|
+
* Returns the number of entries in the map.
|
|
3057
3491
|
*/
|
|
3058
3492
|
readonly size: number;
|
|
3059
3493
|
/**
|
|
3060
|
-
*
|
|
3494
|
+
* Returns an iterator over the map entries.
|
|
3495
|
+
* @returns An iterator over the map entries.
|
|
3061
3496
|
*/
|
|
3062
3497
|
entries(): IterableIterator<KeyValueEntry<TK, TV>>;
|
|
3063
3498
|
/**
|
|
3064
|
-
*
|
|
3499
|
+
* Calls a function for each entry in the map.
|
|
3500
|
+
* @param cb - The function to call for each entry.
|
|
3501
|
+
* @param arg - An optional argument to pass to the callback.
|
|
3065
3502
|
*/
|
|
3066
3503
|
forEach(cb: ResultMapForEachCb, arg?: unknown): void;
|
|
3067
3504
|
/**
|
|
3068
|
-
*
|
|
3505
|
+
* Gets a value from the map.
|
|
3506
|
+
* @param key - The key to retrieve.
|
|
3507
|
+
* @returns `Success` with the value and detail `exists` if the key was found,
|
|
3508
|
+
* `Failure` with detail `not-found` if the key was not found or with detail
|
|
3509
|
+
* `invalid-key` if the key is invalid.
|
|
3069
3510
|
*/
|
|
3070
3511
|
get(key: TK): DetailedResult<TV, ResultMapResultDetail>;
|
|
3071
3512
|
/**
|
|
3072
|
-
*
|
|
3513
|
+
* Returns `true` if the map contains a key.
|
|
3514
|
+
* @param key - The key to check.
|
|
3515
|
+
* @returns `true` if the key exists, `false` otherwise.
|
|
3073
3516
|
*/
|
|
3074
3517
|
has(key: TK): boolean;
|
|
3075
3518
|
/**
|
|
3076
|
-
*
|
|
3519
|
+
* Returns an iterator over the map keys.
|
|
3520
|
+
* @returns An iterator over the map keys.
|
|
3077
3521
|
*/
|
|
3078
3522
|
keys(): IterableIterator<TK>;
|
|
3079
3523
|
/**
|
|
3080
|
-
*
|
|
3524
|
+
* Returns an iterator over the map values.
|
|
3525
|
+
* @returns An iterator over the map values.
|
|
3081
3526
|
*/
|
|
3082
3527
|
values(): IterableIterator<TV>;
|
|
3083
3528
|
/**
|
|
@@ -3113,15 +3558,19 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3113
3558
|
*/
|
|
3114
3559
|
declare interface IReadOnlyValidatingCollector<TITEM extends ICollectible<any, any>> extends IReadOnlyValidatingResultMap<CollectibleKey<TITEM>, TITEM> {
|
|
3115
3560
|
/**
|
|
3116
|
-
* {@
|
|
3561
|
+
* A {@link Collections.CollectorValidator | CollectorValidator} which validates keys and values
|
|
3562
|
+
* before inserting them into this collector.
|
|
3117
3563
|
*/
|
|
3118
3564
|
readonly validating: IReadOnlyCollectorValidator<TITEM>;
|
|
3119
3565
|
/**
|
|
3120
|
-
*
|
|
3566
|
+
* Gets the item at a specified index.
|
|
3567
|
+
* @param index - The index of the item to retrieve.
|
|
3568
|
+
* @returns `Success` with the item if it exists, or `Failure` with an error if the index is out of range.
|
|
3121
3569
|
*/
|
|
3122
3570
|
getAt(index: number): Result<TITEM>;
|
|
3123
3571
|
/**
|
|
3124
|
-
*
|
|
3572
|
+
* Gets all items in the collection, ordered by index.
|
|
3573
|
+
* @returns An array of items in the collection, ordered by index.
|
|
3125
3574
|
*/
|
|
3126
3575
|
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
3127
3576
|
}
|
|
@@ -3132,7 +3581,8 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3132
3581
|
*/
|
|
3133
3582
|
declare interface IReadOnlyValidatingResultMap<TK extends string = string, TV = unknown> extends IReadOnlyResultMap<TK, TV> {
|
|
3134
3583
|
/**
|
|
3135
|
-
* {@
|
|
3584
|
+
* A {@link Collections.ResultMapValidator | ResultMapValidator} which validates keys and values
|
|
3585
|
+
* before inserting them into this collection.
|
|
3136
3586
|
*/
|
|
3137
3587
|
readonly validating: IReadOnlyResultMapValidator<TK, TV>;
|
|
3138
3588
|
}
|
|
@@ -3234,6 +3684,47 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3234
3684
|
* {@label formatter}
|
|
3235
3685
|
*/
|
|
3236
3686
|
orThrow(cb: ErrorFormatter): T;
|
|
3687
|
+
/**
|
|
3688
|
+
* Asserts at the call site that this {@link IResult | result} MUST be a success.
|
|
3689
|
+
* Returns the value on success; on failure, throws an `Error` whose message
|
|
3690
|
+
* is composed from the original failure message and the captured call-site
|
|
3691
|
+
* location (file, line, and where useful function name).
|
|
3692
|
+
*
|
|
3693
|
+
* @remarks
|
|
3694
|
+
* Use for declaration-time / setup-time invariants — module-level `const`
|
|
3695
|
+
* initializers, static class properties, static initialization blocks, and
|
|
3696
|
+
* test fixtures — where a failure indicates a coding bug that should
|
|
3697
|
+
* surface at the call site rather than propagate as a `Result`. For chains
|
|
3698
|
+
* where the throw is intentional control flow, prefer `orThrow`.
|
|
3699
|
+
*
|
|
3700
|
+
* On V8 (Node + Chromium) `Error.captureStackTrace` is used to elide
|
|
3701
|
+
* `shouldNotFail` itself from the captured stack so the parsed frame is
|
|
3702
|
+
* the user's call site directly. On WebKit (where `captureStackTrace` is
|
|
3703
|
+
* unavailable) the stack is parsed manually and frames whose **parsed
|
|
3704
|
+
* function name** contains `shouldNotFail` are filtered out — the raw
|
|
3705
|
+
* stack-line text (including the file path) is deliberately NOT inspected,
|
|
3706
|
+
* so consumer files named after `shouldNotFail` are not collateral damage.
|
|
3707
|
+
* Function names and exact line numbers depend on source-map availability
|
|
3708
|
+
* in the runtime. When no caller frame is recoverable (e.g. `frameDepth`
|
|
3709
|
+
* out of range, or `frameDepth: 0`) the message falls back to the
|
|
3710
|
+
* label-only form (or the bare original message when no label is given).
|
|
3711
|
+
*
|
|
3712
|
+
* Error message format (depending on whether a label and a usable function
|
|
3713
|
+
* name are available):
|
|
3714
|
+
* - both: `<label> (at <fn> in <file>:<line>): <original>`
|
|
3715
|
+
* - label only: `<label> (at <file>:<line>): <original>`
|
|
3716
|
+
* - fn only: `<fn> at <file>:<line>: <original>`
|
|
3717
|
+
* - neither: `<file>:<line>: <original>`
|
|
3718
|
+
*
|
|
3719
|
+
* @param label - Optional human-meaningful identifier (e.g. the constant
|
|
3720
|
+
* name) prefixed to the error message.
|
|
3721
|
+
* @param frameDepth - Optional 1-indexed depth into the caller stack.
|
|
3722
|
+
* Default `1` (immediate caller). Library authors wrapping `shouldNotFail`
|
|
3723
|
+
* inside their own helper pass `2` to attribute to their caller.
|
|
3724
|
+
* @returns The result value, if the operation was successful.
|
|
3725
|
+
* @throws `Error` if the result was a failure.
|
|
3726
|
+
*/
|
|
3727
|
+
shouldNotFail(label?: string, frameDepth?: number): T;
|
|
3237
3728
|
/**
|
|
3238
3729
|
* Gets the value associated with a successful {@link IResult | result},
|
|
3239
3730
|
* or a default value if the corresponding operation failed.
|
|
@@ -3276,6 +3767,30 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3276
3767
|
* was successful, propagates the result value from the successful event.
|
|
3277
3768
|
*/
|
|
3278
3769
|
onFailure(cb: FailureContinuation<T>): Result<T>;
|
|
3770
|
+
/**
|
|
3771
|
+
* Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if
|
|
3772
|
+
* the operation was a success, bridging into an {@link AsyncResult} chain.
|
|
3773
|
+
* @remarks
|
|
3774
|
+
* If the async callback rejects, the rejection is caught and converted
|
|
3775
|
+
* to a {@link Failure}.
|
|
3776
|
+
* @param cb - The {@link AsyncSuccessContinuation | async success continuation} to
|
|
3777
|
+
* be called in the event of success.
|
|
3778
|
+
* @returns An {@link AsyncResult} wrapping the async continuation result, or
|
|
3779
|
+
* propagating the error message from this failure.
|
|
3780
|
+
*/
|
|
3781
|
+
thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;
|
|
3782
|
+
/**
|
|
3783
|
+
* Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if
|
|
3784
|
+
* the operation failed, bridging into an {@link AsyncResult} chain.
|
|
3785
|
+
* @remarks
|
|
3786
|
+
* If the async callback rejects, the rejection is caught and converted
|
|
3787
|
+
* to a {@link Failure}.
|
|
3788
|
+
* @param cb - The {@link AsyncFailureContinuation | async failure continuation} to
|
|
3789
|
+
* be called in the event of failure.
|
|
3790
|
+
* @returns An {@link AsyncResult} wrapping the async continuation result, or
|
|
3791
|
+
* propagating the success value from this result.
|
|
3792
|
+
*/
|
|
3793
|
+
thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T>;
|
|
3279
3794
|
/**
|
|
3280
3795
|
* Calls a supplied {@link ErrorFormatter | error formatter} if
|
|
3281
3796
|
* the operation failed.
|
|
@@ -3527,6 +4042,25 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3527
4042
|
*/
|
|
3528
4043
|
declare function isDetailLogger(logger: ILogger): logger is IDetailLogger;
|
|
3529
4044
|
|
|
4045
|
+
/**
|
|
4046
|
+
* Internal helpers for `Result<T>.shouldNotFail()`. Parsing and message
|
|
4047
|
+
* composition live here so the `Result` class file stays focused on the
|
|
4048
|
+
* Result hierarchy itself; the helpers are exported with the `_` prefix
|
|
4049
|
+
* convention and `@internal` tag so unit tests can cover them directly
|
|
4050
|
+
* without adding test-only public exports.
|
|
4051
|
+
*/
|
|
4052
|
+
/**
|
|
4053
|
+
* Parsed stack-frame information used by `Result<T>.shouldNotFail`.
|
|
4054
|
+
* All fields are optional — runtimes that don't expose stack traces produce
|
|
4055
|
+
* an empty frame and the call site is omitted from the message.
|
|
4056
|
+
* @internal
|
|
4057
|
+
*/
|
|
4058
|
+
export declare interface _IShouldNotFailFrame {
|
|
4059
|
+
fn?: string;
|
|
4060
|
+
file?: string;
|
|
4061
|
+
line?: number;
|
|
4062
|
+
}
|
|
4063
|
+
|
|
3530
4064
|
/**
|
|
3531
4065
|
* Determines if a supplied value is an iterable object or some other type.
|
|
3532
4066
|
* @param value - The value to be tested.
|
|
@@ -3554,6 +4088,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3554
4088
|
*/
|
|
3555
4089
|
declare function isValidator<T, TC>(converterOrValidator: Converter<T, TC> | Validator<T, TC>): converterOrValidator is Validator<T, TC>;
|
|
3556
4090
|
|
|
4091
|
+
/**
|
|
4092
|
+
* Type guard that returns `true` when the input is a canonical UUIDv4 string.
|
|
4093
|
+
* @param value - The string to test.
|
|
4094
|
+
* @returns `true` if `value` is a canonical UUIDv4, narrowing it to {@link Uuid}.
|
|
4095
|
+
* @public
|
|
4096
|
+
*/
|
|
4097
|
+
export declare function isValidUuid(value: string): value is Uuid;
|
|
4098
|
+
|
|
3557
4099
|
/**
|
|
3558
4100
|
* Parameters for constructing a {@link Collections.ValidatingCollector | ValidatingCollector}.
|
|
3559
4101
|
* @public
|
|
@@ -3750,36 +4292,61 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3750
4292
|
*/
|
|
3751
4293
|
declare abstract class LoggerBase implements IDetailLogger {
|
|
3752
4294
|
/**
|
|
3753
|
-
*
|
|
4295
|
+
* The level of logging to be used.
|
|
3754
4296
|
*/
|
|
3755
4297
|
logLevel: ReporterLogLevel;
|
|
3756
4298
|
protected constructor(logLevel?: ReporterLogLevel);
|
|
3757
4299
|
/**
|
|
3758
|
-
*
|
|
4300
|
+
* Logs a detail message.
|
|
4301
|
+
* @param message - The message to log.
|
|
4302
|
+
* @param parameters - The parameters to log.
|
|
4303
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
4304
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
3759
4305
|
*/
|
|
3760
4306
|
detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3761
4307
|
/**
|
|
3762
|
-
*
|
|
4308
|
+
* Logs an info message.
|
|
4309
|
+
* @param message - The message to log.
|
|
4310
|
+
* @param parameters - The parameters to log.
|
|
4311
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
4312
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
3763
4313
|
*/
|
|
3764
4314
|
info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3765
4315
|
/**
|
|
3766
|
-
*
|
|
4316
|
+
* Logs a warning message.
|
|
4317
|
+
* @param message - The message to log.
|
|
4318
|
+
* @param parameters - The parameters to log.
|
|
4319
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
4320
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
3767
4321
|
*/
|
|
3768
4322
|
warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3769
4323
|
/**
|
|
3770
|
-
*
|
|
4324
|
+
* Logs an error message.
|
|
4325
|
+
* @param message - The message to log.
|
|
4326
|
+
* @param parameters - The parameters to log.
|
|
4327
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
4328
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
3771
4329
|
*/
|
|
3772
4330
|
error(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3773
4331
|
/**
|
|
3774
|
-
*
|
|
4332
|
+
* Logs a short error summary at `error` level, then emits `detail` at `detail` level.
|
|
4333
|
+
* @param message - Short human-readable summary.
|
|
4334
|
+
* @param detail - Full detail (e.g. raw converter error) logged at `detail` level.
|
|
3775
4335
|
*/
|
|
3776
4336
|
errorWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
3777
4337
|
/**
|
|
3778
|
-
*
|
|
4338
|
+
* Logs a short warning summary at `warning` level, then emits `detail` at `detail` level.
|
|
4339
|
+
* @param message - Short human-readable summary.
|
|
4340
|
+
* @param detail - Full detail logged at `detail` level.
|
|
3779
4341
|
*/
|
|
3780
4342
|
warnWithDetail(message: string, detail: unknown): Success<string | undefined>;
|
|
3781
4343
|
/**
|
|
3782
|
-
*
|
|
4344
|
+
* Logs a message at the given level.
|
|
4345
|
+
* @param level - The level of the message.
|
|
4346
|
+
* @param message - The message to log.
|
|
4347
|
+
* @param parameters - The parameters to log.
|
|
4348
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
4349
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
3783
4350
|
*/
|
|
3784
4351
|
log(level: MessageLogLevel, message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
3785
4352
|
/**
|
|
@@ -3790,6 +4357,19 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3790
4357
|
* @public
|
|
3791
4358
|
*/
|
|
3792
4359
|
protected _format(message?: unknown, ...parameters: unknown[]): string;
|
|
4360
|
+
/**
|
|
4361
|
+
* Inner hook called for logged messages alongside {@link Logging.LoggerBase._log | _log},
|
|
4362
|
+
* exposing the structured `(level, formatted, message, parameters)` form before it is
|
|
4363
|
+
* collapsed to the formatted string. The default implementation is a no-op; subclasses
|
|
4364
|
+
* that need to retain structured records (e.g. {@link Logging.RetainingLogger | RetainingLogger})
|
|
4365
|
+
* override this. Fired only in the `shouldLog` branch, so suppressed messages never reach it.
|
|
4366
|
+
* @param __level - The {@link MessageLogLevel | level} of the message.
|
|
4367
|
+
* @param __formatted - The formatted message (same string passed to `_log`).
|
|
4368
|
+
* @param __message - The raw message argument before formatting.
|
|
4369
|
+
* @param __parameters - The raw parameter arguments before formatting.
|
|
4370
|
+
* @public
|
|
4371
|
+
*/
|
|
4372
|
+
protected _logStructured(__level: MessageLogLevel, __formatted: string, __message?: unknown, __parameters?: readonly unknown[]): void;
|
|
3793
4373
|
/**
|
|
3794
4374
|
* Inner method called for suppressed log messages.
|
|
3795
4375
|
* @public
|
|
@@ -3821,7 +4401,11 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3821
4401
|
LogValueFormatter,
|
|
3822
4402
|
LogMessageFormatter,
|
|
3823
4403
|
ILogReporterCreateParams,
|
|
3824
|
-
LogReporter
|
|
4404
|
+
LogReporter,
|
|
4405
|
+
MultiLogger,
|
|
4406
|
+
ILogRecord,
|
|
4407
|
+
IGetRecordsOptions,
|
|
4408
|
+
RetainingLogger
|
|
3825
4409
|
}
|
|
3826
4410
|
}
|
|
3827
4411
|
export { Logging }
|
|
@@ -4115,6 +4699,58 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4115
4699
|
*/
|
|
4116
4700
|
export declare type MessageLogLevel = 'quiet' | 'detail' | 'info' | 'warning' | 'error';
|
|
4117
4701
|
|
|
4702
|
+
/**
|
|
4703
|
+
* An {@link Logging.ILogger | ILogger} that fans every log call out to N child loggers,
|
|
4704
|
+
* each applying its own threshold.
|
|
4705
|
+
*
|
|
4706
|
+
* @remarks
|
|
4707
|
+
* The composite does not pre-filter — it forwards the raw `(level, message, ...params)`
|
|
4708
|
+
* to each child's public method so each child formats and filters per its own rules.
|
|
4709
|
+
* This lets a single pinned logger feed, for example, a {@link Logging.ConsoleLogger | ConsoleLogger}
|
|
4710
|
+
* (stdout) and a {@link Logging.RetainingLogger | RetainingLogger} (observability buffer)
|
|
4711
|
+
* with independent log levels.
|
|
4712
|
+
*
|
|
4713
|
+
* @public
|
|
4714
|
+
*/
|
|
4715
|
+
declare class MultiLogger implements ILogger {
|
|
4716
|
+
/**
|
|
4717
|
+
* The child loggers calls are fanned out to.
|
|
4718
|
+
* @internal
|
|
4719
|
+
*/
|
|
4720
|
+
private readonly _loggers;
|
|
4721
|
+
/**
|
|
4722
|
+
* Creates a new multi logger.
|
|
4723
|
+
* @param loggers - The child loggers to fan calls out to.
|
|
4724
|
+
*/
|
|
4725
|
+
constructor(loggers: ReadonlyArray<ILogger>);
|
|
4726
|
+
/**
|
|
4727
|
+
* The most-verbose (most-permissive) level among the children, so an upstream
|
|
4728
|
+
* `shouldLog` gate does not suppress a call before it can fan out to a more
|
|
4729
|
+
* permissive child. Computed on access, since a child's level may change.
|
|
4730
|
+
*/
|
|
4731
|
+
get logLevel(): ReporterLogLevel;
|
|
4732
|
+
/**
|
|
4733
|
+
* {@inheritDoc Logging.ILogger.log}
|
|
4734
|
+
*/
|
|
4735
|
+
log(level: MessageLogLevel, message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
4736
|
+
/**
|
|
4737
|
+
* {@inheritDoc Logging.ILogger.detail}
|
|
4738
|
+
*/
|
|
4739
|
+
detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
4740
|
+
/**
|
|
4741
|
+
* {@inheritDoc Logging.ILogger.info}
|
|
4742
|
+
*/
|
|
4743
|
+
info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
4744
|
+
/**
|
|
4745
|
+
* {@inheritDoc Logging.ILogger.warn}
|
|
4746
|
+
*/
|
|
4747
|
+
warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
4748
|
+
/**
|
|
4749
|
+
* {@inheritDoc Logging.ILogger.error}
|
|
4750
|
+
*/
|
|
4751
|
+
error(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
4752
|
+
}
|
|
4753
|
+
|
|
4118
4754
|
/**
|
|
4119
4755
|
* A no-op {@link Logging.LoggerBase | LoggerBase} that does not log anything.
|
|
4120
4756
|
* @public
|
|
@@ -4144,6 +4780,30 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4144
4780
|
* @returns A normalized version of the value
|
|
4145
4781
|
*/
|
|
4146
4782
|
normalize<T>(from: T): Result<T>;
|
|
4783
|
+
/**
|
|
4784
|
+
* Produces a stable, byte-identical JSON string following RFC 8785
|
|
4785
|
+
* (JSON Canonicalization Scheme) key-ordering rules.
|
|
4786
|
+
*
|
|
4787
|
+
* Builds the output string directly rather than constructing an intermediate
|
|
4788
|
+
* JS object, so integer-string keys (`"10"`, `"2"`) retain lexicographic
|
|
4789
|
+
* order instead of being reordered numerically by the JS engine during
|
|
4790
|
+
* `JSON.stringify`.
|
|
4791
|
+
*
|
|
4792
|
+
* @param from - Any JSON-compatible value (string, number, boolean, null,
|
|
4793
|
+
* plain object, or array). Fails for non-JSON types (Map, Set, Date,
|
|
4794
|
+
* RegExp, function, symbol, bigint, undefined).
|
|
4795
|
+
* @returns `Result<string>` — the canonical JSON string, or a failure if
|
|
4796
|
+
* `from` contains non-serializable types.
|
|
4797
|
+
* @public
|
|
4798
|
+
*/
|
|
4799
|
+
canonicalize(from: unknown): Result<string>;
|
|
4800
|
+
/**
|
|
4801
|
+
* Recursively builds a byte-identical RFC 8785 JSON string.
|
|
4802
|
+
* @throws For non-JSON-serializable types (non-finite numbers, Date, RegExp,
|
|
4803
|
+
* Map, Set, class instances, function, symbol, bigint, undefined).
|
|
4804
|
+
* Callers must wrap in captureResult.
|
|
4805
|
+
*/
|
|
4806
|
+
protected _canonicalizeRfc8785(value: unknown): string;
|
|
4147
4807
|
/**
|
|
4148
4808
|
* Compares two property names from some object being normalized.
|
|
4149
4809
|
* @param k1 - First key to be compared.
|
|
@@ -4170,6 +4830,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4170
4830
|
normalizeLiteral<T>(from: T): Result<T>;
|
|
4171
4831
|
}
|
|
4172
4832
|
|
|
4833
|
+
/**
|
|
4834
|
+
* Normalizes a function name from a stack frame, returning `undefined` when
|
|
4835
|
+
* the name is empty or one of the well-known anonymous-IIFE noise patterns
|
|
4836
|
+
* (typically emitted by V8 for module-top-level code).
|
|
4837
|
+
* @internal
|
|
4838
|
+
*/
|
|
4839
|
+
export declare function _normalizeShouldNotFailFnName(fn: string | undefined): string | undefined;
|
|
4840
|
+
|
|
4173
4841
|
/**
|
|
4174
4842
|
* A {@link Converter | Converter} which converts `unknown` to a `number`.
|
|
4175
4843
|
* @remarks
|
|
@@ -4513,6 +5181,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4513
5181
|
*/
|
|
4514
5182
|
export declare function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K>;
|
|
4515
5183
|
|
|
5184
|
+
/**
|
|
5185
|
+
* Union of all values in an array/tuple type, preserving literal types if possible.
|
|
5186
|
+
* If T is not an array/tuple, results in `never`.
|
|
5187
|
+
* @public
|
|
5188
|
+
*/
|
|
5189
|
+
export declare type OneOf<T> = T extends readonly unknown[] ? T[number] : never;
|
|
5190
|
+
|
|
4516
5191
|
/**
|
|
4517
5192
|
* A helper function to create a {@link Converter | Converter} for polymorphic values.
|
|
4518
5193
|
* Returns a converter which invokes the wrapped converters in sequence, returning the
|
|
@@ -4682,6 +5357,15 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4682
5357
|
*/
|
|
4683
5358
|
declare const optionalString: Converter<string | undefined, unknown>;
|
|
4684
5359
|
|
|
5360
|
+
/**
|
|
5361
|
+
* Parses a single stack-trace line in either V8 or WebKit format.
|
|
5362
|
+
*
|
|
5363
|
+
* V8: ` at <fn> (<file>:<line>:<col>)` or ` at <file>:<line>:<col>`
|
|
5364
|
+
* WebKit: `<fn>@<file>:<line>:<col>` or `@<file>:<line>:<col>`
|
|
5365
|
+
* @internal
|
|
5366
|
+
*/
|
|
5367
|
+
export declare function _parseStackFrame(line: string): _IShouldNotFailFrame;
|
|
5368
|
+
|
|
4685
5369
|
/**
|
|
4686
5370
|
* Simple implicit pick function, which picks a set of properties from a supplied
|
|
4687
5371
|
* object. Ignores picked properties that do not exist regardless of type signature.
|
|
@@ -5260,6 +5944,99 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
5260
5944
|
*/
|
|
5261
5945
|
export declare type ResultValueType<T> = T extends Result<infer TV> ? TV : never;
|
|
5262
5946
|
|
|
5947
|
+
/**
|
|
5948
|
+
* An {@link Logging.ILogger | ILogger} that retains structured log records in a bounded
|
|
5949
|
+
* most-recent-N ring, with a query API supporting min-severity filtering and
|
|
5950
|
+
* since-cursor incremental paging.
|
|
5951
|
+
*
|
|
5952
|
+
* @remarks
|
|
5953
|
+
* Records are captured via the {@link Logging.LoggerBase._logStructured | _logStructured} hook,
|
|
5954
|
+
* so the full structured form (`level` + formatted `message` + raw `args`) is retained.
|
|
5955
|
+
* The logger emits nowhere itself — pair it with a {@link Logging.MultiLogger | MultiLogger}
|
|
5956
|
+
* to also feed a {@link Logging.ConsoleLogger | ConsoleLogger} or other durable sink.
|
|
5957
|
+
*
|
|
5958
|
+
* @public
|
|
5959
|
+
*/
|
|
5960
|
+
declare class RetainingLogger extends LoggerBase {
|
|
5961
|
+
/**
|
|
5962
|
+
* The fixed ring capacity — the maximum number of records retained before the
|
|
5963
|
+
* oldest is overwritten. A positive integer (see the constructor normalization).
|
|
5964
|
+
* @internal
|
|
5965
|
+
*/
|
|
5966
|
+
private readonly _capacity;
|
|
5967
|
+
/**
|
|
5968
|
+
* Injected clock used to timestamp records.
|
|
5969
|
+
* @internal
|
|
5970
|
+
*/
|
|
5971
|
+
private readonly _now;
|
|
5972
|
+
/**
|
|
5973
|
+
* The backing store, used as a circular buffer. Grows lazily up to `_capacity`,
|
|
5974
|
+
* after which records overwrite the oldest slot in place — eviction is O(1), with
|
|
5975
|
+
* no `shift()` re-indexing regardless of capacity.
|
|
5976
|
+
* @internal
|
|
5977
|
+
*/
|
|
5978
|
+
private _buffer;
|
|
5979
|
+
/**
|
|
5980
|
+
* Index of the oldest retained record within `_buffer` once the ring is full.
|
|
5981
|
+
* @internal
|
|
5982
|
+
*/
|
|
5983
|
+
private _head;
|
|
5984
|
+
/**
|
|
5985
|
+
* The number of valid records currently retained (`<= _capacity`).
|
|
5986
|
+
* @internal
|
|
5987
|
+
*/
|
|
5988
|
+
private _count;
|
|
5989
|
+
/**
|
|
5990
|
+
* The most recently assigned sequence number; monotonic, stable across eviction
|
|
5991
|
+
* and {@link Logging.RetainingLogger.clear | clear()}.
|
|
5992
|
+
* @internal
|
|
5993
|
+
*/
|
|
5994
|
+
private _lastSeq;
|
|
5995
|
+
/**
|
|
5996
|
+
* Creates a new retaining logger.
|
|
5997
|
+
* @param logLevel - The level of logging to retain. Defaults to `'detail'` to capture
|
|
5998
|
+
* broadly and filter at query time.
|
|
5999
|
+
* @param maxRecords - The maximum number of records to retain. Defaults to `1000`.
|
|
6000
|
+
* @param now - Injected clock returning milliseconds since epoch. Defaults to `Date.now`.
|
|
6001
|
+
*/
|
|
6002
|
+
constructor(logLevel?: ReporterLogLevel, maxRecords?: number, now?: () => number);
|
|
6003
|
+
/**
|
|
6004
|
+
* The retained records, oldest-first.
|
|
6005
|
+
*/
|
|
6006
|
+
get records(): ReadonlyArray<ILogRecord>;
|
|
6007
|
+
/**
|
|
6008
|
+
* The most recently assigned sequence number. A client can hold this value and
|
|
6009
|
+
* pass it as `sinceSeq` to page only records logged afterward.
|
|
6010
|
+
*/
|
|
6011
|
+
get lastSeq(): number;
|
|
6012
|
+
/**
|
|
6013
|
+
* Returns retained records, oldest-first, optionally filtered.
|
|
6014
|
+
* @param options - {@link Logging.IGetRecordsOptions | Filtering and paging options}.
|
|
6015
|
+
* @returns The matching records, oldest-first.
|
|
6016
|
+
*/
|
|
6017
|
+
getRecords(options?: IGetRecordsOptions): ReadonlyArray<ILogRecord>;
|
|
6018
|
+
/**
|
|
6019
|
+
* Clears all retained records. Does NOT reset the sequence counter, so a client
|
|
6020
|
+
* holding a `sinceSeq` cursor never re-sees a sequence number.
|
|
6021
|
+
*/
|
|
6022
|
+
clear(): void;
|
|
6023
|
+
/**
|
|
6024
|
+
* Materializes the ring into a plain oldest-first array.
|
|
6025
|
+
* @internal
|
|
6026
|
+
*/
|
|
6027
|
+
private _toOrderedArray;
|
|
6028
|
+
/**
|
|
6029
|
+
* {@inheritDoc Logging.LoggerBase._logStructured}
|
|
6030
|
+
* @internal
|
|
6031
|
+
*/
|
|
6032
|
+
protected _logStructured(level: MessageLogLevel, formatted: string, message: unknown, parameters: readonly unknown[]): void;
|
|
6033
|
+
/**
|
|
6034
|
+
* {@inheritDoc Logging.LoggerBase._log}
|
|
6035
|
+
* @internal
|
|
6036
|
+
*/
|
|
6037
|
+
protected _log(message: string, __level: MessageLogLevel): Success<string | undefined>;
|
|
6038
|
+
}
|
|
6039
|
+
|
|
5263
6040
|
/**
|
|
5264
6041
|
* Compares two log levels.
|
|
5265
6042
|
* @param message - The first log level.
|
|
@@ -5424,6 +6201,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
5424
6201
|
message?: string;
|
|
5425
6202
|
}
|
|
5426
6203
|
|
|
6204
|
+
/**
|
|
6205
|
+
* Union of all string values in an array/tuple type, preserving literal types if possible.
|
|
6206
|
+
* If T is not an array/tuple, results in `never`.
|
|
6207
|
+
* @public
|
|
6208
|
+
*/
|
|
6209
|
+
export declare type StringOneOf<T> = Extract<OneOf<T>, string>;
|
|
6210
|
+
|
|
5427
6211
|
/**
|
|
5428
6212
|
* An in-place {@link Validation.Validator | Validator} for `string` values.
|
|
5429
6213
|
* @public
|
|
@@ -5531,6 +6315,10 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
5531
6315
|
* {@inheritDoc IResult.orThrow}
|
|
5532
6316
|
*/
|
|
5533
6317
|
orThrow(cb: ErrorFormatter): T;
|
|
6318
|
+
/**
|
|
6319
|
+
* {@inheritDoc IResult.shouldNotFail}
|
|
6320
|
+
*/
|
|
6321
|
+
shouldNotFail(__label?: string, __frameDepth?: number): T;
|
|
5534
6322
|
/**
|
|
5535
6323
|
* {@inheritDoc IResult.orDefault}
|
|
5536
6324
|
*/
|
|
@@ -5557,6 +6345,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
5557
6345
|
* {@inheritDoc IResult.onFailure}
|
|
5558
6346
|
*/
|
|
5559
6347
|
onFailure(__: FailureContinuation<T>): Result<T>;
|
|
6348
|
+
/**
|
|
6349
|
+
* {@inheritDoc IResult.thenOnSuccess}
|
|
6350
|
+
*/
|
|
6351
|
+
thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;
|
|
6352
|
+
/**
|
|
6353
|
+
* {@inheritDoc IResult.thenOnFailure}
|
|
6354
|
+
*/
|
|
6355
|
+
thenOnFailure(__: AsyncFailureContinuation<T>): AsyncResult<T>;
|
|
5560
6356
|
/**
|
|
5561
6357
|
* {@inheritDoc IResult.withErrorFormat}
|
|
5562
6358
|
*/
|
|
@@ -5746,6 +6542,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
5746
6542
|
}
|
|
5747
6543
|
}
|
|
5748
6544
|
|
|
6545
|
+
/**
|
|
6546
|
+
* A canonical UUIDv4 string: 8-4-4-4-12 lowercase hex digits with version
|
|
6547
|
+
* nibble `4` and variant nibble in `[89ab]`. Produced by {@link generateUuid}
|
|
6548
|
+
* and validated by {@link isValidUuid}.
|
|
6549
|
+
* @public
|
|
6550
|
+
*/
|
|
6551
|
+
export declare type Uuid = Brand<string, 'Uuid'>;
|
|
6552
|
+
|
|
5749
6553
|
/**
|
|
5750
6554
|
* Helper function to create a {@link Converter | Converter} from any {@link Validation.Validator}
|
|
5751
6555
|
* @param converterOrValidator - the {@link Validation.Validator} to be wrapped or {@link Converter | Converter}
|