@fgv/ts-utils 2.1.0 → 2.1.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.json +0 -30
  2. package/CHANGELOG.md +1 -14
  3. package/dist/ts-utils.d.ts +1509 -1924
  4. package/dist/tsdoc-metadata.json +1 -1
  5. package/lib/index.d.ts +1 -6
  6. package/lib/index.d.ts.map +1 -1
  7. package/lib/index.js +1 -9
  8. package/lib/index.js.map +1 -1
  9. package/lib/packlets/base/logger.js.map +1 -1
  10. package/lib/packlets/base/normalize.js.map +1 -1
  11. package/lib/packlets/base/result.d.ts +20 -6
  12. package/lib/packlets/base/result.d.ts.map +1 -1
  13. package/lib/packlets/base/result.js +4 -6
  14. package/lib/packlets/base/result.js.map +1 -1
  15. package/lib/packlets/base/utils.js.map +1 -1
  16. package/lib/packlets/conversion/converter.js.map +1 -1
  17. package/lib/packlets/conversion/converters.d.ts +5 -29
  18. package/lib/packlets/conversion/converters.d.ts.map +1 -1
  19. package/lib/packlets/conversion/converters.js +1 -47
  20. package/lib/packlets/conversion/converters.js.map +1 -1
  21. package/lib/packlets/conversion/objectConverter.js.map +1 -1
  22. package/lib/packlets/conversion/stringConverter.js.map +1 -1
  23. package/lib/packlets/validation/array.js.map +1 -1
  24. package/lib/packlets/validation/boolean.js.map +1 -1
  25. package/lib/packlets/validation/field.js.map +1 -1
  26. package/lib/packlets/validation/genericValidator.js.map +1 -1
  27. package/lib/packlets/validation/number.js.map +1 -1
  28. package/lib/packlets/validation/object.js.map +1 -1
  29. package/lib/packlets/validation/string.js.map +1 -1
  30. package/lib/packlets/validation/typeGuard.js.map +1 -1
  31. package/lib/packlets/validation/validators.js.map +1 -1
  32. package/package.json +22 -23
  33. package/lib/packlets/csv/csvHelpers.d.ts +0 -17
  34. package/lib/packlets/csv/csvHelpers.d.ts.map +0 -1
  35. package/lib/packlets/csv/csvHelpers.js +0 -69
  36. package/lib/packlets/csv/csvHelpers.js.map +0 -1
  37. package/lib/packlets/csv/index.d.ts +0 -2
  38. package/lib/packlets/csv/index.d.ts.map +0 -1
  39. package/lib/packlets/csv/index.js +0 -39
  40. package/lib/packlets/csv/index.js.map +0 -1
  41. package/lib/packlets/experimental/extendedArray.d.ts +0 -56
  42. package/lib/packlets/experimental/extendedArray.d.ts.map +0 -1
  43. package/lib/packlets/experimental/extendedArray.js +0 -106
  44. package/lib/packlets/experimental/extendedArray.js.map +0 -1
  45. package/lib/packlets/experimental/formatter.d.ts +0 -66
  46. package/lib/packlets/experimental/formatter.d.ts.map +0 -1
  47. package/lib/packlets/experimental/formatter.js +0 -75
  48. package/lib/packlets/experimental/formatter.js.map +0 -1
  49. package/lib/packlets/experimental/index.d.ts +0 -4
  50. package/lib/packlets/experimental/index.d.ts.map +0 -1
  51. package/lib/packlets/experimental/index.js +0 -41
  52. package/lib/packlets/experimental/index.js.map +0 -1
  53. package/lib/packlets/experimental/rangeOf.d.ts +0 -122
  54. package/lib/packlets/experimental/rangeOf.d.ts.map +0 -1
  55. package/lib/packlets/experimental/rangeOf.js +0 -185
  56. package/lib/packlets/experimental/rangeOf.js.map +0 -1
  57. package/lib/packlets/hash/hash.d.ts +0 -51
  58. package/lib/packlets/hash/hash.d.ts.map +0 -1
  59. package/lib/packlets/hash/hash.js +0 -166
  60. package/lib/packlets/hash/hash.js.map +0 -1
  61. package/lib/packlets/hash/index.d.ts +0 -2
  62. package/lib/packlets/hash/index.d.ts.map +0 -1
  63. package/lib/packlets/hash/index.js +0 -39
  64. package/lib/packlets/hash/index.js.map +0 -1
  65. package/lib/packlets/record-jar/index.d.ts +0 -2
  66. package/lib/packlets/record-jar/index.d.ts.map +0 -1
  67. package/lib/packlets/record-jar/index.js +0 -39
  68. package/lib/packlets/record-jar/index.js.map +0 -1
  69. package/lib/packlets/record-jar/recordJarHelpers.d.ts +0 -37
  70. package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +0 -1
  71. package/lib/packlets/record-jar/recordJarHelpers.js +0 -263
  72. package/lib/packlets/record-jar/recordJarHelpers.js.map +0 -1
@@ -247,14 +247,6 @@ declare namespace Classes {
247
247
  }
248
248
  }
249
249
 
250
- /**
251
- * Computes an md5 hash from an array of strings. Not secure and not intended to be secure.
252
- * @param parts - The strings to be hashed
253
- * @returns An md5 hash of the parts
254
- * @public
255
- */
256
- declare function computeHash(parts: string[]): string;
257
-
258
250
  /**
259
251
  * A {@link Validation.Constraint | Constraint<T>} function returns
260
252
  * `true` if the supplied value meets the constraint. Can return
@@ -457,7 +449,6 @@ declare namespace Converters {
457
449
  isA,
458
450
  oneOf,
459
451
  arrayOf,
460
- extendedArrayOf,
461
452
  recordOf,
462
453
  mapOf,
463
454
  validateWith,
@@ -470,8 +461,7 @@ declare namespace Converters {
470
461
  discriminatedObject,
471
462
  transform,
472
463
  transformObject,
473
- rangeTypeOf,
474
- rangeOf,
464
+ OnError_2 as OnError,
475
465
  string,
476
466
  value,
477
467
  number,
@@ -500,29 +490,6 @@ declare interface ConverterTraits {
500
490
  readonly brand?: string;
501
491
  }
502
492
 
503
- declare namespace Csv {
504
- export {
505
- readCsvFileSync,
506
- CsvOptions
507
- }
508
- }
509
- export { Csv }
510
-
511
- /**
512
- * Options for {@link Csv.readCsvFileSync}
513
- * @beta
514
- */
515
- declare interface CsvOptions {
516
- delimiter?: string;
517
- }
518
-
519
- /**
520
- * Default {@link Experimental.RangeOfFormats | formats} to use for both
521
- * open-ended and complete {@link Experimental.RangeOf | RangeOf<T>}.
522
- * @public
523
- */
524
- declare const DEFAULT_RANGEOF_FORMATS: RangeOfFormats;
525
-
526
493
  /**
527
494
  * Default {@link Validation.ValidatorTraitValues | validation traits}.
528
495
  * @public
@@ -727,90 +694,6 @@ declare function enumeratedValue<T>(values: T[]): Converter<T, T[]>;
727
694
  */
728
695
  declare function enumeratedValue_2<T extends string>(values: T[]): Validator<T, T[]>;
729
696
 
730
- declare namespace Experimental {
731
- export {
732
- ExtendedArray,
733
- formatList,
734
- FormatTargets,
735
- Formattable,
736
- FormattableBase,
737
- Formatter,
738
- FormattersByExtendedTarget,
739
- FormattersByTarget,
740
- RangeOfProperties,
741
- RangeOfFormats,
742
- DEFAULT_RANGEOF_FORMATS,
743
- RangeOf
744
- }
745
- }
746
- export { Experimental }
747
-
748
- /**
749
- * An experimental array template which extend built-in `Array` to include a handful
750
- * of predicates which return {@link Result | Result<T>}.
751
- * @beta
752
- */
753
- declare class ExtendedArray<T> extends Array<T> {
754
- readonly itemDescription: string;
755
- /**
756
- * Constructs an {@link Experimental.ExtendedArray}.
757
- * @param itemDescription - Brief description of the type of each item in this array.
758
- * @param items - The initial contents of the array.
759
- */
760
- constructor(itemDescription: string, ...items: T[]);
761
- /**
762
- * Type guard to determine if some arbitrary array is an
763
- * {@link Experimental.ExtendedArray}
764
- * @param a - The `Array` to be tested.
765
- * @returns Returns `true` if `a` is an {@link Experimental.ExtendedArray},
766
- * `false` otherwise.
767
- */
768
- static isExtendedArray<T>(a?: T[]): a is ExtendedArray<T>;
769
- /**
770
- * Determines if this array contains exactly one element which matches
771
- * a supplied predicate.
772
- * @param predicate - The predicate function to be applied.
773
- * @returns Returns {@link Success | Success<T>} with the single matching
774
- * result if exactly one item matches `predicate`. Returns {@link Failure}
775
- * with an error message if there are no matches or more than one match.
776
- */
777
- single(predicate?: (item: T) => boolean): Result<T>;
778
- /**
779
- * Returns the first element of an {@link Experimental.ExtendedArray}. Fails with an
780
- * error message if the array is empty.
781
- * @param failMessage - Optional message to be displayed in the event of failure.
782
- * @returns Returns {@link Success | Success<T>} with the value of the first element
783
- * in the array, or {@link Failure} with an error message if the array is empty.
784
- */
785
- first(failMessage?: string): Result<T>;
786
- /**
787
- * Returns an array containing all elements of an {@link Experimental.ExtendedArray}. Fails with
788
- * an error message if the array is empty.
789
- * @param failMessage - Optional message to be displayed in the event of failure.
790
- * @returns Returns {@link Success | Success<T[]>} with a new (non-extended) `Array`
791
- * containing the elements of this array, or {@link Failure} with an error message
792
- * if the array is empty.
793
- */
794
- atLeastOne(failMessage?: string): Result<T[]>;
795
- /**
796
- * Gets a new (non-extended) `Array` containing all of the elements from this
797
- * {@link Experimental.ExtendedArray}.
798
- * @returns A new (non-extended) `Array<T>`.
799
- */
800
- all(): T[];
801
- }
802
-
803
- /**
804
- * A helper function to create a {@link Converter} which converts `unknown` to {@link Experimental.ExtendedArray | ExtendedArray<T>}.
805
- * @remarks
806
- * If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot
807
- * be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
808
- * @param converter - {@link Converter} used to convert each item in the array
809
- * @param ignoreErrors - Specifies treatment of unconvertible elements
810
- * @beta
811
- */
812
- declare function extendedArrayOf<T, TC = undefined>(label: string, converter: Converter<T, TC>, onError?: OnError_2): Converter<ExtendedArray<T>, TC>;
813
-
814
697
  /**
815
698
  * Returns {@link Failure | Failure<T>} with the supplied error message.
816
699
  * @param message - Error message to be returned.
@@ -856,13 +739,16 @@ export declare class Failure<T> implements IResult<T> {
856
739
  /**
857
740
  * {@inheritdoc IResult.orDefault}
858
741
  */
859
- orDefault(dflt?: T): T | undefined;
742
+ orDefault(dflt: T): T;
743
+ orDefault(): T | undefined;
860
744
  /**
861
745
  * {@inheritdoc IResult.getValueOrThrow}
746
+ * @deprecated Use {@link Failure.orThrow | orThrow} instead.
862
747
  */
863
748
  getValueOrThrow(logger?: IResultLogger): never;
864
749
  /**
865
750
  * {@inheritdoc IResult.getValueOrDefault}
751
+ * @deprecated Use {@link Failure.orDefault | orDefault} instead.
866
752
  */
867
753
  getValueOrDefault(dflt?: T): T | undefined;
868
754
  /**
@@ -971,2037 +857,1736 @@ declare type FieldValidators<T, TC = unknown> = {
971
857
  };
972
858
 
973
859
  /**
974
- * Formats a list of items using the supplied template and formatter, one result
975
- * per output line.
976
- * @param format - A mustache template used to format each item.
977
- * @param items - The items to be formatted.
978
- * @param itemFormatter - The {@link Experimental.Formatter | Formatter<T>} used to format each item.
979
- * @returns The resulting string.
980
- * @beta
860
+ * A {@link Validation.ConstraintTrait | ConstraintTrait} indicating that
861
+ * a {@link Validation.Constraint | Constraint<T>} function provides an
862
+ * additional constraint implementation.
863
+ * @public
981
864
  */
982
- declare function formatList<T>(format: string, items: T[], itemFormatter: Formatter<T>): Result<string>;
865
+ declare interface FunctionConstraintTrait {
866
+ type: 'function';
867
+ }
983
868
 
984
869
  /**
985
- * Interface for an object that can be formatted.
986
- * @beta
870
+ * Generic base implementation for an in-place {@link Validation.Validator | Validator}.
871
+ * @public
987
872
  */
988
- declare interface Formattable {
989
- /**
990
- * Formats an object using the supplied mustache template.
991
- * @param format - A mustache template used to format the object.
992
- * @returns {@link Success} with the resulting string, or {@link Failure}
993
- * with an error message if an error occurs.
994
- */
995
- format(format: string): Result<string>;
996
- }
997
-
873
+ declare class GenericValidator<T, TC = undefined> implements Validator<T, TC> {
998
874
  /**
999
- * Base class which adds common formatting.
1000
- * @beta
875
+ * {@inheritdoc Validation.Validator.traits}
1001
876
  */
1002
- declare class FormattableBase {
1003
- /**
1004
- * Helper enables derived classes to add named details to a formatted presentation.
1005
- * @param details - An array of detail description strings.
1006
- * @param label - Label to use for the new detail.
1007
- * @param value - Value to use for the new detail.
1008
- * @internal
1009
- */
1010
- protected static _tryAddDetail(details: string[], label: string, value: string | undefined): void;
1011
- /**
1012
- * {@inheritdoc Experimental.Formattable.format}
1013
- */
1014
- format(template: string): Result<string>;
1015
- }
1016
-
877
+ readonly traits: ValidatorTraits;
1017
878
  /**
1018
- * Destination format for some formatted string.
1019
- * @beta
879
+ * @internal
1020
880
  */
1021
- declare type FormatTargets = 'text' | 'markdown' | 'embed';
1022
-
881
+ protected readonly _validator: ValidatorFunc<T, TC>;
1023
882
  /**
1024
- * Type definition for a formatting function, which takes a `string` and an
1025
- * item and returns {@link Result | Result<string>}.
1026
- * @beta
883
+ * @internal
1027
884
  */
1028
- declare type Formatter<T> = (format: string, item: T) => Result<string>;
1029
-
885
+ protected readonly _options: ValidatorOptions<TC>;
1030
886
  /**
1031
- * A collection of {@link Experimental.Formatter | formatters} indexed by target name, to enable
1032
- * different format methods per output target.
1033
- * @beta
887
+ * Constructs a new {@link Validation.Base.GenericValidator | GenericValidator<T>}.
888
+ * @param params - The {@link Validation.Base.GenericValidatorConstructorParams | constructor params}
889
+ * used to configure validation.
1034
890
  */
1035
- declare type FormattersByExtendedTarget<TFT extends FormatTargets, T> = Record<TFT, Formatter<T>>;
1036
-
891
+ constructor(params: Partial<GenericValidatorConstructorParams<T, TC>>);
1037
892
  /**
1038
- * A collection of {@link Experimental.Formatter | formatters} indexed by the
1039
- * {@link Experimental.FormatTargets | default supported target formats}.
1040
- * @beta
893
+ * {@inheritdoc Validation.Validator.isOptional}
1041
894
  */
1042
- declare type FormattersByTarget<T> = FormattersByExtendedTarget<FormatTargets, T>;
1043
-
895
+ get isOptional(): boolean;
1044
896
  /**
1045
- * A {@link Validation.ConstraintTrait | ConstraintTrait} indicating that
1046
- * a {@link Validation.Constraint | Constraint<T>} function provides an
1047
- * additional constraint implementation.
1048
- * @public
897
+ * {@inheritdoc Validation.Validator.brand}
1049
898
  */
1050
- declare interface FunctionConstraintTrait {
1051
- type: 'function';
1052
- }
1053
-
899
+ get brand(): string | undefined;
1054
900
  /**
1055
- * Generic base implementation for an in-place {@link Validation.Validator | Validator}.
1056
- * @public
901
+ * {@inheritdoc Validation.Validator.validate}
1057
902
  */
1058
- declare class GenericValidator<T, TC = undefined> implements Validator<T, TC> {
1059
- /**
1060
- * {@inheritdoc Validation.Validator.traits}
1061
- */
1062
- readonly traits: ValidatorTraits;
1063
- /**
1064
- * @internal
1065
- */
1066
- protected readonly _validator: ValidatorFunc<T, TC>;
1067
- /**
1068
- * @internal
1069
- */
1070
- protected readonly _options: ValidatorOptions<TC>;
1071
- /**
1072
- * Constructs a new {@link Validation.Base.GenericValidator | GenericValidator<T>}.
1073
- * @param params - The {@link Validation.Base.GenericValidatorConstructorParams | constructor params}
1074
- * used to configure validation.
1075
- */
1076
- constructor(params: Partial<GenericValidatorConstructorParams<T, TC>>);
1077
- /**
1078
- * {@inheritdoc Validation.Validator.isOptional}
1079
- */
1080
- get isOptional(): boolean;
1081
- /**
1082
- * {@inheritdoc Validation.Validator.brand}
1083
- */
1084
- get brand(): string | undefined;
1085
- /**
1086
- * {@inheritdoc Validation.Validator.validate}
1087
- */
1088
- validate(from: unknown, context?: TC): Result<T>;
1089
- /**
1090
- * {@inheritdoc Validation.Validator.validateOptional}
1091
- */
1092
- validateOptional(from: unknown, context?: TC): Result<T | undefined>;
1093
- /**
1094
- * {@inheritdoc Validation.Validator.guard}
1095
- */
1096
- guard(from: unknown, context?: TC): from is T;
1097
- /**
1098
- * {@inheritdoc Validation.Validator.optional}
1099
- */
1100
- optional(): Validator<T | undefined, TC>;
1101
- /**
1102
- * {@inheritdoc Validation.Validator.withConstraint}
1103
- */
1104
- withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;
1105
- /**
1106
- * {@inheritdoc Validation.Validator.brand}
1107
- */
1108
- withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;
1109
- /**
1110
- * Gets a default or explicit context.
1111
- * @param explicitContext - Optional explicit context.
1112
- * @returns The appropriate context to use.
1113
- * @internal
1114
- */
1115
- protected _context(explicitContext?: TC): TC | undefined;
1116
- }
1117
-
903
+ validate(from: unknown, context?: TC): Result<T>;
1118
904
  /**
1119
- * Options used to initialize a {@link Validation.Base.GenericValidator | GenericValidator}.
1120
- * @public
905
+ * {@inheritdoc Validation.Validator.validateOptional}
1121
906
  */
1122
- declare interface GenericValidatorConstructorParams<T, TC> {
1123
- options?: ValidatorOptions<TC>;
1124
- traits?: Partial<ValidatorTraits>;
1125
- validator?: ValidatorFunc<T, TC>;
1126
- }
1127
-
907
+ validateOptional(from: unknown, context?: TC): Result<T | undefined>;
1128
908
  /**
1129
- * Gets the type of a property specified by key from an arbitrary object.
1130
- * @param key - The key specifying the property to be tested.
1131
- * @param item - The object from which the property is to be tested.
1132
- * @returns The type of the requested property, or `undefined` if the
1133
- * property does not exist.
1134
- * @example
1135
- * Returns `'undefined'` (a string) if the property exists but has the value
1136
- * undefined but `undefined` (the literal) if the property does not exist.
1137
- * @public
909
+ * {@inheritdoc Validation.Validator.guard}
1138
910
  */
1139
- export declare function getTypeOfProperty<T extends object>(key: string | number | symbol, item: T): 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'undefined' | 'object' | 'function' | undefined;
1140
-
911
+ guard(from: unknown, context?: TC): from is T;
1141
912
  /**
1142
- * Gets the value of a property specified by key from an arbitrary object,
1143
- * or a default value if the property does not exist.
1144
- * @param key - The key specifying the property to be retrieved.
1145
- * @param item - The object from which the property is to be retrieved.
1146
- * @param defaultValue - An optional default value to be returned if the property
1147
- * is not present (default `undefined`).
1148
- * @returns The value of the requested property, or the default value if the
1149
- * requested property does not exist.
1150
- * @public
913
+ * {@inheritdoc Validation.Validator.optional}
1151
914
  */
1152
- export declare function getValueOfPropertyOrDefault<T extends object>(key: string | number | symbol, item: T, defaultValue?: unknown): unknown | undefined;
1153
-
1154
- declare namespace Hash {
1155
- export {
1156
- computeHash,
1157
- Normalizer_2 as Normalizer
1158
- }
1159
- }
1160
- export { Hash }
1161
-
915
+ optional(): Validator<T | undefined, TC>;
1162
916
  /**
1163
- * Infers the type that will be returned by an instantiated converter. Works
1164
- * for complex as well as simple types.
1165
- * @example `Infer<typeof Converters.mapOf(Converters.stringArray)>` is `Map<string, string[]>`
1166
- * @beta
917
+ * {@inheritdoc Validation.Validator.withConstraint}
1167
918
  */
1168
- declare type Infer<TCONV> = TCONV extends Converter<infer TTO> ? InnerInferredType<TTO> : never;
1169
-
919
+ withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;
1170
920
  /**
1171
- * @public
921
+ * {@inheritdoc Validation.Validator.brand}
1172
922
  */
1173
- declare class InMemoryLogger extends LoggerBase {
1174
- protected _messages: string[];
1175
- protected _silent: string[];
1176
- constructor(logLevel?: LogLevel);
1177
- get messages(): string[];
1178
- get silent(): string[];
1179
- clear(): void;
1180
- protected _innerLog(message: string): Success<string | undefined>;
1181
- protected _innerSilent(message: string): Success<string | undefined>;
1182
- }
1183
-
923
+ withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;
1184
924
  /**
1185
- * internal
925
+ * Gets a default or explicit context.
926
+ * @param explicitContext - Optional explicit context.
927
+ * @returns The appropriate context to use.
928
+ * @internal
1186
929
  */
1187
- declare type InnerInferredType<TCONV> = TCONV extends Converter<infer TTO> ? TTO extends Array<infer TTOELEM> ? InnerInferredType<TTOELEM>[] : TTO : TCONV extends Array<infer TELEM> ? InnerInferredType<TELEM>[] : TCONV;
930
+ protected _context(explicitContext?: TC): TC | undefined;
931
+ }
1188
932
 
1189
- /**
1190
- * Represents the result of some operation of sequence of operations.
1191
- * @remarks
1192
- * This common contract enables commingled discriminated usage of {@link Success | Success<T>}
1193
- * and {@link Failure | Failure<T>}.
1194
- * @public
1195
- */
1196
- export declare interface IResult<T> {
1197
- /**
1198
- * Indicates whether the operation was successful.
1199
- */
1200
- readonly success: boolean;
1201
- /**
1202
- * Indicates whether this operation was successful. Functions
1203
- * as a type guard for {@link Success | Success<T>}.
1204
- */
1205
- isSuccess(): this is Success<T>;
1206
- /**
1207
- * Indicates whether this operation failed. Functions
1208
- * as a type guard for {@link Failure | Failure<T>}.
1209
- */
1210
- isFailure(): this is Failure<T>;
1211
- /**
1212
- * Gets the value associated with a successful {@link IResult | result},
1213
- * or throws the error message if the corresponding operation failed.
1214
- *
1215
- * Note that `getValueOrThrow` is being superseded by `orThrow` and
1216
- * will eventually be deprecated. Please use orDefault instead.
1217
- *
1218
- * @param logger - An optional {@link IResultLogger | logger} to which the
1219
- * error will also be reported.
1220
- * @returns The return value, if the operation was successful.
1221
- * @throws The error message if the operation failed.
1222
- */
1223
- getValueOrThrow(logger?: IResultLogger): T;
1224
- /**
1225
- * Gets the value associated with a successful {@link IResult | result},
1226
- * or a default value if the corresponding operation failed.
1227
- * @param dflt - The value to be returned if the operation failed (default is
1228
- * `undefined`).
1229
- *
1230
- * Note that `getValueOrDefault` is being superseded by `orDefault` and
1231
- * will eventually be deprecated. Please use orDefault instead.
1232
- *
1233
- * @returns The return value, if the operation was successful. Returns
1234
- * the supplied default value or `undefined` if no default is supplied.
1235
- */
1236
- getValueOrDefault(dflt?: T): T | undefined;
1237
- /**
1238
- * Gets the value associated with a successful {@link IResult | result},
1239
- * or throws the error message if the corresponding operation failed.
1240
- * @param logger - An optional {@link IResultLogger | logger} to which the
1241
- * error will also be reported.
1242
- * @returns The return value, if the operation was successful.
1243
- * @throws The error message if the operation failed.
1244
- */
1245
- orThrow(logger?: IResultLogger): T;
1246
- /**
1247
- * Gets the value associated with a successful {@link IResult | result},
1248
- * or a default value if the corresponding operation failed.
1249
- * @param dflt - The value to be returned if the operation failed (default is
1250
- * `undefined`).
1251
- * @returns The return value, if the operation was successful. Returns
1252
- * the supplied default value or `undefined` if no default is supplied.
1253
- */
1254
- orDefault(dflt?: T): T | undefined;
1255
- /**
1256
- * Calls a supplied {@link SuccessContinuation | success continuation} if
1257
- * the operation was a success.
1258
- * @remarks
1259
- * The {@link SuccessContinuation | success continuation} might return a
1260
- * different result type than {@link IResult} on which it is invoked. This
1261
- * enables chaining of operations with heterogenous return types.
1262
- *
1263
- * @param cb - The {@link SuccessContinuation | success continuation} to
1264
- * be called in the event of success.
1265
- * @returns If this operation was successful, returns the value returned
1266
- * by the {@link SuccessContinuation | success continuation}. If this result
1267
- * failed, propagates the error message from this failure.
1268
- */
1269
- onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;
1270
- /**
1271
- * Calls a supplied {@link FailureContinuation | failed continuation} if
1272
- * the operation failed.
1273
- * @param cb - The {@link FailureContinuation | failure continuation} to
1274
- * be called in the event of failure.
1275
- * @returns If this operation failed, returns the value returned by the
1276
- * {@link FailureContinuation | failure continuation}. If this result
1277
- * was successful, propagates the result value from the successful event.
1278
- */
1279
- onFailure(cb: FailureContinuation<T>): Result<T>;
1280
- /**
1281
- * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},
1282
- * adding a supplied detail if the operation failed.
1283
- * @param detail - The detail to be added if this operation failed.
1284
- * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either
1285
- * the success result or the error message from this {@link IResult}, with
1286
- * the supplied detail (if this event failed) or detail `undefined` (if
1287
- * this result succeeded).
1288
- */
1289
- withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;
1290
- /**
1291
- * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},
1292
- * adding supplied details.
1293
- * @param detail - The default detail to be added to the new {@link DetailedResult}.
1294
- * @param successDetail - An optional detail to be added if this result was successful.
1295
- * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either
1296
- * the success result or the error message from this {@link IResult} and the
1297
- * appropriate added detail.
1298
- */
1299
- withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;
1300
- }
933
+ /**
934
+ * Options used to initialize a {@link Validation.Base.GenericValidator | GenericValidator}.
935
+ * @public
936
+ */
937
+ declare interface GenericValidatorConstructorParams<T, TC> {
938
+ options?: ValidatorOptions<TC>;
939
+ traits?: Partial<ValidatorTraits>;
940
+ validator?: ValidatorFunc<T, TC>;
941
+ }
1301
942
 
1302
- /**
1303
- * Simple logger interface used by {@link IResult.orThrow}.
1304
- * @public
1305
- */
1306
- export declare interface IResultLogger {
1307
- /**
1308
- * Log an error message.
1309
- * @param message - The message to be logged.
1310
- */
1311
- error(message: string): void;
1312
- }
943
+ /**
944
+ * Gets the type of a property specified by key from an arbitrary object.
945
+ * @param key - The key specifying the property to be tested.
946
+ * @param item - The object from which the property is to be tested.
947
+ * @returns The type of the requested property, or `undefined` if the
948
+ * property does not exist.
949
+ * @example
950
+ * Returns `'undefined'` (a string) if the property exists but has the value
951
+ * undefined but `undefined` (the literal) if the property does not exist.
952
+ * @public
953
+ */
954
+ export declare function getTypeOfProperty<T extends object>(key: string | number | symbol, item: T): 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'undefined' | 'object' | 'function' | undefined;
1313
955
 
1314
- /**
1315
- * Helper function to create a {@link Converter} from a supplied type guard function.
1316
- * @param description - a description of the thing to be validated for use in error messages
1317
- * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.
1318
- * @returns A new {@link Converter} which validates the values using the supplied type guard
1319
- * and returns them in place.
1320
- * @public
1321
- */
1322
- declare function isA<T, TC = unknown>(description: string, guard: TypeGuardWithContext<T, TC>): Converter<T, TC>;
956
+ /**
957
+ * Gets the value of a property specified by key from an arbitrary object,
958
+ * or a default value if the property does not exist.
959
+ * @param key - The key specifying the property to be retrieved.
960
+ * @param item - The object from which the property is to be retrieved.
961
+ * @param defaultValue - An optional default value to be returned if the property
962
+ * is not present (default `undefined`).
963
+ * @returns The value of the requested property, or the default value if the
964
+ * requested property does not exist.
965
+ * @public
966
+ */
967
+ export declare function getValueOfPropertyOrDefault<T extends object>(key: string | number | symbol, item: T, defaultValue?: unknown): unknown | undefined;
1323
968
 
1324
- /**
1325
- * Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which
1326
- * validates a value or object in place.
1327
- * @param description - a description of the thing to be validated for use in error messages
1328
- * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.
1329
- * @returns A new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator } which validates
1330
- * the values using the supplied type guard.
1331
- * @public
1332
- */
1333
- declare function isA_2<T, TC>(description: string, guard: TypeGuardWithContext<T, TC>, params?: Omit<TypeGuardValidatorConstructorParams<T, TC>, 'description' | 'guard'>): TypeGuardValidator<T, TC>;
969
+ /**
970
+ * Infers the type that will be returned by an instantiated converter. Works
971
+ * for complex as well as simple types.
972
+ * @example `Infer<typeof Converters.mapOf(Converters.stringArray)>` is `Map<string, string[]>`
973
+ * @beta
974
+ */
975
+ declare type Infer<TCONV> = TCONV extends Converter<infer TTO> ? InnerInferredType<TTO> : never;
976
+
977
+ /**
978
+ * @public
979
+ */
980
+ declare class InMemoryLogger extends LoggerBase {
981
+ protected _messages: string[];
982
+ protected _silent: string[];
983
+ constructor(logLevel?: LogLevel);
984
+ get messages(): string[];
985
+ get silent(): string[];
986
+ clear(): void;
987
+ protected _innerLog(message: string): Success<string | undefined>;
988
+ protected _innerSilent(message: string): Success<string | undefined>;
989
+ }
990
+
991
+ /**
992
+ * internal
993
+ */
994
+ declare type InnerInferredType<TCONV> = TCONV extends Converter<infer TTO> ? TTO extends Array<infer TTOELEM> ? InnerInferredType<TTOELEM>[] : TTO : TCONV extends Array<infer TELEM> ? InnerInferredType<TELEM>[] : TCONV;
1334
995
 
996
+ /**
997
+ * Represents the result of some operation of sequence of operations.
998
+ * @remarks
999
+ * This common contract enables commingled discriminated usage of {@link Success | Success<T>}
1000
+ * and {@link Failure | Failure<T>}.
1001
+ * @public
1002
+ */
1003
+ export declare interface IResult<T> {
1335
1004
  /**
1336
- * Helper type-guard function to report whether a specified key is present in
1337
- * a supplied object.
1338
- * @param key - The key to be tested.
1339
- * @param item - The object to be tested.
1340
- * @returns Returns `true` if the key is present, `false` otherwise.
1341
- * @public
1005
+ * Indicates whether the operation was successful.
1342
1006
  */
1343
- export declare function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T;
1344
-
1007
+ readonly success: boolean;
1345
1008
  /**
1346
- * A {@link Converter} which converts an iso formatted string, a number or a `Date` object to
1347
- * a `Date` object.
1348
- * @public
1009
+ * Indicates whether this operation was successful. Functions
1010
+ * as a type guard for {@link Success | Success<T>}.
1349
1011
  */
1350
- declare const isoDate: Converter<Date, unknown>;
1351
-
1012
+ isSuccess(): this is Success<T>;
1352
1013
  /**
1353
- * @public
1014
+ * Indicates whether this operation failed. Functions
1015
+ * as a type guard for {@link Failure | Failure<T>}.
1354
1016
  */
1355
- declare type JarFieldPicker<T extends JarRecord = JarRecord> = (record: T) => (keyof T)[];
1356
-
1017
+ isFailure(): this is Failure<T>;
1357
1018
  /**
1358
- * Represents a single record in a JAR file
1359
- * @public
1019
+ * Gets the value associated with a successful {@link IResult | result},
1020
+ * or throws the error message if the corresponding operation failed.
1021
+ *
1022
+ * Note that `getValueOrThrow` is being superseded by `orThrow` and
1023
+ * will eventually be deprecated. Please use orDefault instead.
1024
+ *
1025
+ * @param logger - An optional {@link IResultLogger | logger} to which the
1026
+ * error will also be reported.
1027
+ * @returns The return value, if the operation was successful.
1028
+ * @throws The error message if the operation failed.
1029
+ * @deprecated Use {@link IResult.orThrow | orThrow} instead.
1030
+ */
1031
+ getValueOrThrow(logger?: IResultLogger): T;
1032
+ /**
1033
+ * Gets the value associated with a successful {@link IResult | result},
1034
+ * or a default value if the corresponding operation failed.
1035
+ * @param dflt - The value to be returned if the operation failed (default is
1036
+ * `undefined`).
1037
+ *
1038
+ * Note that `getValueOrDefault` is being superseded by `orDefault` and
1039
+ * will eventually be deprecated. Please use orDefault instead.
1040
+ *
1041
+ * @returns The return value, if the operation was successful. Returns
1042
+ * the supplied default value or `undefined` if no default is supplied.
1043
+ * @deprecated Use {@link IResult.orDefault | orDefault} instead.
1360
1044
  */
1361
- declare type JarRecord = Record<string, string | string[]>;
1362
-
1045
+ getValueOrDefault(dflt?: T): T | undefined;
1363
1046
  /**
1364
- * Options for a JAR record parser.
1365
- * @public
1047
+ * Gets the value associated with a successful {@link IResult | result},
1048
+ * or throws the error message if the corresponding operation failed.
1049
+ * @param logger - An optional {@link IResultLogger | logger} to which the
1050
+ * error will also be reported.
1051
+ * @returns The return value, if the operation was successful.
1052
+ * @throws The error message if the operation failed.
1366
1053
  */
1367
- declare interface JarRecordParserOptions {
1368
- readonly arrayFields?: string[] | JarFieldPicker;
1369
- readonly fixedContinuationSize?: number;
1370
- }
1371
-
1054
+ orThrow(logger?: IResultLogger): T;
1372
1055
  /**
1373
- * Options for {@link Converters.(recordOf:3) | Converters.recordOf} and
1374
- * {@link Converters.(mapOf:3) | Converters.mapOf}
1375
- * helper functions.
1376
- * @public
1056
+ * Gets the value associated with a successful {@link IResult | result},
1057
+ * or a default value if the corresponding operation failed.
1058
+ * @param dflt - The value to be returned if the operation failed.
1059
+ * @returns The return value, if the operation was successful. Returns
1060
+ * the supplied default if an error occurred.
1377
1061
  */
1378
- declare interface KeyedConverterOptions<T extends string = string, TC = undefined> {
1379
- /**
1380
- * if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
1381
- * cannot be converted. If `onError` is `'ignore'`, failing elements are silently ignored.
1382
- */
1383
- onError?: 'fail' | 'ignore';
1384
- /**
1385
- * If present, `keyConverter` is used to convert the source object property names to
1386
- * keys in the resulting map or record.
1387
- * @remarks
1388
- * Can be used to coerce key names to supported values and/or strong types.
1389
- */
1390
- keyConverter?: Converter<T, TC>;
1391
- }
1392
-
1062
+ orDefault(dflt: T): T;
1393
1063
  /**
1394
- * Type for factory methods which convert a key-value pair to a new unique value.
1395
- * @public
1064
+ * Gets the value associated with a successful {@link IResult | result},
1065
+ * or a default value if the corresponding operation failed.
1066
+ * @returns The return value, if the operation was successful, or
1067
+ * `undefined` if an error occurs.
1396
1068
  */
1397
- declare type KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;
1398
-
1069
+ orDefault(): T | undefined;
1399
1070
  /**
1400
- * Helper function to create a {@link Converter} which converts `unknown` to some supplied literal value. Succeeds with
1401
- * the supplied value if an identity comparison succeeds, fails otherwise.
1402
- * @param value - The value to be compared.
1403
- * @returns A {@link Converter} which returns the supplied value on success.
1404
- * @public
1071
+ * Calls a supplied {@link SuccessContinuation | success continuation} if
1072
+ * the operation was a success.
1073
+ * @remarks
1074
+ * The {@link SuccessContinuation | success continuation} might return a
1075
+ * different result type than {@link IResult} on which it is invoked. This
1076
+ * enables chaining of operations with heterogenous return types.
1077
+ *
1078
+ * @param cb - The {@link SuccessContinuation | success continuation} to
1079
+ * be called in the event of success.
1080
+ * @returns If this operation was successful, returns the value returned
1081
+ * by the {@link SuccessContinuation | success continuation}. If this result
1082
+ * failed, propagates the error message from this failure.
1083
+ */
1084
+ onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;
1085
+ /**
1086
+ * Calls a supplied {@link FailureContinuation | failed continuation} if
1087
+ * the operation failed.
1088
+ * @param cb - The {@link FailureContinuation | failure continuation} to
1089
+ * be called in the event of failure.
1090
+ * @returns If this operation failed, returns the value returned by the
1091
+ * {@link FailureContinuation | failure continuation}. If this result
1092
+ * was successful, propagates the result value from the successful event.
1405
1093
  */
1406
- declare function literal<T>(value: T): Converter<T, unknown>;
1407
-
1094
+ onFailure(cb: FailureContinuation<T>): Result<T>;
1408
1095
  /**
1409
- * Helper function to create a {@link Validation.Validator} which validates a literal value.
1410
- * @param value - the literal value to be validated
1411
- * @public
1096
+ * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},
1097
+ * adding a supplied detail if the operation failed.
1098
+ * @param detail - The detail to be added if this operation failed.
1099
+ * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either
1100
+ * the success result or the error message from this {@link IResult}, with
1101
+ * the supplied detail (if this event failed) or detail `undefined` (if
1102
+ * this result succeeded).
1412
1103
  */
1413
- declare function literal_2<T extends string | number | boolean | symbol | null | undefined>(value: T): Validator<T>;
1414
-
1104
+ withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;
1415
1105
  /**
1416
- * @public
1106
+ * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},
1107
+ * adding supplied details.
1108
+ * @param detail - The default detail to be added to the new {@link DetailedResult}.
1109
+ * @param successDetail - An optional detail to be added if this result was successful.
1110
+ * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either
1111
+ * the success result or the error message from this {@link IResult} and the
1112
+ * appropriate added detail.
1417
1113
  */
1418
- declare interface Logger {
1419
- log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1420
- detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1421
- info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1422
- warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1423
- warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
1424
- error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
1425
- }
1114
+ withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;
1115
+ }
1426
1116
 
1117
+ /**
1118
+ * Simple logger interface used by {@link IResult.orThrow}.
1119
+ * @public
1120
+ */
1121
+ export declare interface IResultLogger {
1427
1122
  /**
1428
- * @public
1123
+ * Log an error message.
1124
+ * @param message - The message to be logged.
1429
1125
  */
1430
- declare abstract class LoggerBase {
1431
- logLevel: LogLevel;
1432
- constructor(logLevel?: LogLevel);
1433
- detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1434
- info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1435
- warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1436
- warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
1437
- error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
1438
- log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1439
- protected _format(message?: unknown, ...parameters: unknown[]): string;
1440
- protected _innerSilent(__message: string): Success<string | undefined>;
1441
- protected abstract _innerLog(message: string): Success<string | undefined>;
1442
- }
1126
+ error(message: string): void;
1127
+ }
1443
1128
 
1444
- declare namespace Logging {
1445
- export {
1446
- LogLevel,
1447
- Logger,
1448
- LoggerBase,
1449
- InMemoryLogger,
1450
- NoOpLogger
1451
- }
1452
- }
1453
- export { Logging }
1129
+ /**
1130
+ * Helper function to create a {@link Converter} from a supplied type guard function.
1131
+ * @param description - a description of the thing to be validated for use in error messages
1132
+ * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.
1133
+ * @returns A new {@link Converter} which validates the values using the supplied type guard
1134
+ * and returns them in place.
1135
+ * @public
1136
+ */
1137
+ declare function isA<T, TC = unknown>(description: string, guard: TypeGuardWithContext<T, TC>): Converter<T, TC>;
1138
+
1139
+ /**
1140
+ * Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which
1141
+ * validates a value or object in place.
1142
+ * @param description - a description of the thing to be validated for use in error messages
1143
+ * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.
1144
+ * @returns A new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator } which validates
1145
+ * the values using the supplied type guard.
1146
+ * @public
1147
+ */
1148
+ declare function isA_2<T, TC>(description: string, guard: TypeGuardWithContext<T, TC>, params?: Omit<TypeGuardValidatorConstructorParams<T, TC>, 'description' | 'guard'>): TypeGuardValidator<T, TC>;
1149
+
1150
+ /**
1151
+ * Helper type-guard function to report whether a specified key is present in
1152
+ * a supplied object.
1153
+ * @param key - The key to be tested.
1154
+ * @param item - The object to be tested.
1155
+ * @returns Returns `true` if the key is present, `false` otherwise.
1156
+ * @public
1157
+ */
1158
+ export declare function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T;
1159
+
1160
+ /**
1161
+ * A {@link Converter} which converts an iso formatted string, a number or a `Date` object to
1162
+ * a `Date` object.
1163
+ * @public
1164
+ */
1165
+ declare const isoDate: Converter<Date, unknown>;
1454
1166
 
1167
+ /**
1168
+ * Options for {@link Converters.(recordOf:3) | Converters.recordOf} and
1169
+ * {@link Converters.(mapOf:3) | Converters.mapOf}
1170
+ * helper functions.
1171
+ * @public
1172
+ */
1173
+ declare interface KeyedConverterOptions<T extends string = string, TC = undefined> {
1455
1174
  /**
1456
- * @public
1175
+ * if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
1176
+ * cannot be converted. If `onError` is `'ignore'`, failing elements are silently ignored.
1457
1177
  */
1458
- declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1459
-
1178
+ onError?: 'fail' | 'ignore';
1460
1179
  /**
1461
- * Aggregates successful results from a collection of {@link DetailedResult | DetailedResult<T, TD>},
1462
- * optionally ignoring certain error details.
1463
- * @param results - The collection of {@link DetailedResult | DetailedResult<T, TD>} to be mapped.
1464
- * @param ignore - An array of error detail values (of type `<TD>`) that should be ignored.
1465
- * @returns {@link Success} with an array containing all successful results if all results either
1466
- * succeeded or returned error details listed in `ignore`. If any results failed with details
1467
- * that cannot be ignored, returns {@link Failure} with an concatenated summary of all non-ignorable
1468
- * error messages.
1469
- * @public
1470
- */
1471
- export declare function mapDetailedResults<T, TD>(results: Iterable<DetailedResult<T, TD>>, ignore: TD[]): Result<T[]>;
1180
+ * If present, `keyConverter` is used to convert the source object property names to
1181
+ * keys in the resulting map or record.
1182
+ * @remarks
1183
+ * Can be used to coerce key names to supported values and/or strong types.
1184
+ */
1185
+ keyConverter?: Converter<T, TC>;
1186
+ }
1472
1187
 
1473
- /**
1474
- * Aggregates error messages from a collection of {@link Result | Result<T>}.
1475
- * @param results - An iterable collection of {@link Result | Result<T>} for which
1476
- * error messages are aggregated.
1477
- * @returns An array of strings consisting of all error messages returned by
1478
- * {@link Result | results} in the source collection. Ignores {@link Success}
1479
- * results and returns an empty array if there were no errors.
1480
- * @public
1481
- */
1482
- export declare function mapFailures<T>(results: Iterable<Result<T>>): string[];
1483
-
1484
- /**
1485
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1486
- * using a supplied {@link Converter | Converter<T>} to produce a `Map<string, T>`.
1487
- * @remarks
1488
- * The resulting converter fails conversion if any element cannot be converted.
1489
- * @param converter - {@link Converter} used to convert each item in the source object.
1490
- * @returns A {@link Converter} which returns `Map<string, T>`.
1491
- * {@label WITH_DEFAULT}
1492
- * @public
1493
- */
1494
- declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>): Converter<Map<TK, T>, TC>;
1188
+ /**
1189
+ * Type for factory methods which convert a key-value pair to a new unique value.
1190
+ * @public
1191
+ */
1192
+ declare type KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;
1495
1193
 
1496
- /**
1497
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1498
- * using a supplied {@link Converter | Converter<T>} to produce a `Map<string, T>` and optionally
1499
- * specified handling of elements that cannot be converted.
1500
- * @remarks
1501
- * if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
1502
- * cannot be converted. If `onError` is `'ignore'`, failing elements are silently ignored.
1503
- * @param converter - {@link Converter} used to convert each item in the source object.
1504
- * @returns A {@link Converter} which returns `Map<string, T>`.
1505
- * {@label WITH_ON_ERROR}
1506
- * @public
1507
- */
1508
- declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, onError: 'fail' | 'ignore'): Converter<Map<TK, T>, TC>;
1194
+ /**
1195
+ * Helper function to create a {@link Converter} which converts `unknown` to some supplied literal value. Succeeds with
1196
+ * the supplied value if an identity comparison succeeds, fails otherwise.
1197
+ * @param value - The value to be compared.
1198
+ * @returns A {@link Converter} which returns the supplied value on success.
1199
+ * @public
1200
+ */
1201
+ declare function literal<T>(value: T): Converter<T, unknown>;
1509
1202
 
1510
- /**
1511
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1512
- * using a supplied {@link Converter | Converter<T>} to produce a `Map<TK, T>`.
1513
- * @remarks
1514
- * If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
1515
- * converter for keys and/or control the handling of elements that fail conversion.
1516
- * @param converter - {@link Converter} used to convert each item in the source object.
1517
- * @param options - Optional {@link Converters.KeyedConverterOptions | KeyedConverterOptions<TK, TC>} which
1518
- * supplies a key converter and/or error-handling options.
1519
- * @returns A {@link Converter} which returns `Map<TK, T>`.
1520
- * {@label WITH_OPTIONS}
1521
- * @public
1522
- */
1523
- declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, options: KeyedConverterOptions<TK, TC>): Converter<Map<TK, T>, TC>;
1203
+ /**
1204
+ * Helper function to create a {@link Validation.Validator} which validates a literal value.
1205
+ * @param value - the literal value to be validated
1206
+ * @public
1207
+ */
1208
+ declare function literal_2<T extends string | number | boolean | symbol | null | undefined>(value: T): Validator<T>;
1524
1209
 
1525
- /**
1526
- * Helper function to create a {@link Converter} which converts `unknown` to one of a set of supplied enumerated
1527
- * values, mapping any of multiple supplied values to the enumeration.
1528
- * @remarks
1529
- * Enables mapping of multiple input values to a consistent internal representation (so e.g. `'y'`, `'yes'`,
1530
- * `'true'`, `1` and `true` can all map to boolean `true`)
1531
- * @param map - An array of tuples describing the mapping. The first element of each tuple is the result
1532
- * value, the second is the set of values that map to the result. Tuples are evaluated in the order
1533
- * supplied and are not checked for duplicates.
1534
- * @param message - An optional error message.
1535
- * @returns A {@link Converter} which applies the mapping and yields `<T>` on success.
1536
- * @public
1537
- */
1538
- declare function mappedEnumeratedValue<T>(map: [T, unknown[]][], message?: string): Converter<T, undefined>;
1210
+ /**
1211
+ * @public
1212
+ */
1213
+ declare interface Logger {
1214
+ log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1215
+ detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1216
+ info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1217
+ warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1218
+ warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
1219
+ error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
1220
+ }
1539
1221
 
1540
- /**
1541
- * Aggregates successful result values from a collection of {@link Result | Result<T>}.
1542
- * @param results - The collection of {@link Result | Result<T>} to be mapped.
1543
- * @returns If all {@link Result | results} are successful, returns {@link Success} with an
1544
- * array containing all returned values. If any {@link Result | results} failed, returns
1545
- * {@link Failure} with a concatenated summary of all error messages.
1546
- * @public
1547
- */
1548
- export declare function mapResults<T>(results: Iterable<Result<T>>): Result<T[]>;
1222
+ /**
1223
+ * @public
1224
+ */
1225
+ declare abstract class LoggerBase {
1226
+ logLevel: LogLevel;
1227
+ constructor(logLevel?: LogLevel);
1228
+ detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1229
+ info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1230
+ warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1231
+ warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
1232
+ error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
1233
+ log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
1234
+ protected _format(message?: unknown, ...parameters: unknown[]): string;
1235
+ protected _innerSilent(__message: string): Success<string | undefined>;
1236
+ protected abstract _innerLog(message: string): Success<string | undefined>;
1237
+ }
1549
1238
 
1550
- /**
1551
- * Aggregates successful results from a a collection of {@link Result | Result<T>}.
1552
- * @param results - An `Iterable` of {@link Result | Result<T>} from which success
1553
- * results are to be aggregated.
1554
- * @returns {@link Success} with an array of `<T>` if any results were successful. If
1555
- * all {@link Result | results} failed, returns {@link Failure} with a concatenated
1556
- * summary of all error messages.
1557
- * @public
1558
- */
1559
- export declare function mapSuccess<T>(results: Iterable<Result<T>>): Result<T[]>;
1239
+ declare namespace Logging {
1240
+ export {
1241
+ LogLevel,
1242
+ Logger,
1243
+ LoggerBase,
1244
+ InMemoryLogger,
1245
+ NoOpLogger
1246
+ }
1247
+ }
1248
+ export { Logging }
1560
1249
 
1561
- /**
1562
- * Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.
1563
- * @param src - The `Map` object to be converted.
1564
- * @param factory - The factory method used to convert elements.
1565
- * @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or
1566
- * {@link Failure} with an error message if an error occurs.
1567
- * @public
1568
- */
1569
- export declare function mapToRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS>, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
1250
+ /**
1251
+ * @public
1252
+ */
1253
+ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1570
1254
 
1255
+ /**
1256
+ * Aggregates successful results from a collection of {@link DetailedResult | DetailedResult<T, TD>},
1257
+ * optionally ignoring certain error details.
1258
+ * @param results - The collection of {@link DetailedResult | DetailedResult<T, TD>} to be mapped.
1259
+ * @param ignore - An array of error detail values (of type `<TD>`) that should be ignored.
1260
+ * @returns {@link Success} with an array containing all successful results if all results either
1261
+ * succeeded or returned error details listed in `ignore`. If any results failed with details
1262
+ * that cannot be ignored, returns {@link Failure} with an concatenated summary of all non-ignorable
1263
+ * error messages.
1264
+ * @public
1265
+ */
1266
+ export declare function mapDetailedResults<T, TD>(results: Iterable<DetailedResult<T, TD>>, ignore: TD[]): Result<T[]>;
1267
+
1268
+ /**
1269
+ * Aggregates error messages from a collection of {@link Result | Result<T>}.
1270
+ * @param results - An iterable collection of {@link Result | Result<T>} for which
1271
+ * error messages are aggregated.
1272
+ * @returns An array of strings consisting of all error messages returned by
1273
+ * {@link Result | results} in the source collection. Ignores {@link Success}
1274
+ * results and returns an empty array if there were no errors.
1275
+ * @public
1276
+ */
1277
+ export declare function mapFailures<T>(results: Iterable<Result<T>>): string[];
1278
+
1279
+ /**
1280
+ * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1281
+ * using a supplied {@link Converter | Converter<T>} to produce a `Map<string, T>`.
1282
+ * @remarks
1283
+ * The resulting converter fails conversion if any element cannot be converted.
1284
+ * @param converter - {@link Converter} used to convert each item in the source object.
1285
+ * @returns A {@link Converter} which returns `Map<string, T>`.
1286
+ * {@label WITH_DEFAULT}
1287
+ * @public
1288
+ */
1289
+ declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>): Converter<Map<TK, T>, TC>;
1290
+
1291
+ /**
1292
+ * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1293
+ * using a supplied {@link Converter | Converter<T>} to produce a `Map<string, T>` and optionally
1294
+ * specified handling of elements that cannot be converted.
1295
+ * @remarks
1296
+ * if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
1297
+ * cannot be converted. If `onError` is `'ignore'`, failing elements are silently ignored.
1298
+ * @param converter - {@link Converter} used to convert each item in the source object.
1299
+ * @returns A {@link Converter} which returns `Map<string, T>`.
1300
+ * {@label WITH_ON_ERROR}
1301
+ * @public
1302
+ */
1303
+ declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, onError: 'fail' | 'ignore'): Converter<Map<TK, T>, TC>;
1304
+
1305
+ /**
1306
+ * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1307
+ * using a supplied {@link Converter | Converter<T>} to produce a `Map<TK, T>`.
1308
+ * @remarks
1309
+ * If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
1310
+ * converter for keys and/or control the handling of elements that fail conversion.
1311
+ * @param converter - {@link Converter} used to convert each item in the source object.
1312
+ * @param options - Optional {@link Converters.KeyedConverterOptions | KeyedConverterOptions<TK, TC>} which
1313
+ * supplies a key converter and/or error-handling options.
1314
+ * @returns A {@link Converter} which returns `Map<TK, T>`.
1315
+ * {@label WITH_OPTIONS}
1316
+ * @public
1317
+ */
1318
+ declare function mapOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, options: KeyedConverterOptions<TK, TC>): Converter<Map<TK, T>, TC>;
1319
+
1320
+ /**
1321
+ * Helper function to create a {@link Converter} which converts `unknown` to one of a set of supplied enumerated
1322
+ * values, mapping any of multiple supplied values to the enumeration.
1323
+ * @remarks
1324
+ * Enables mapping of multiple input values to a consistent internal representation (so e.g. `'y'`, `'yes'`,
1325
+ * `'true'`, `1` and `true` can all map to boolean `true`)
1326
+ * @param map - An array of tuples describing the mapping. The first element of each tuple is the result
1327
+ * value, the second is the set of values that map to the result. Tuples are evaluated in the order
1328
+ * supplied and are not checked for duplicates.
1329
+ * @param message - An optional error message.
1330
+ * @returns A {@link Converter} which applies the mapping and yields `<T>` on success.
1331
+ * @public
1332
+ */
1333
+ declare function mappedEnumeratedValue<T>(map: [T, unknown[]][], message?: string): Converter<T, undefined>;
1334
+
1335
+ /**
1336
+ * Aggregates successful result values from a collection of {@link Result | Result<T>}.
1337
+ * @param results - The collection of {@link Result | Result<T>} to be mapped.
1338
+ * @returns If all {@link Result | results} are successful, returns {@link Success} with an
1339
+ * array containing all returned values. If any {@link Result | results} failed, returns
1340
+ * {@link Failure} with a concatenated summary of all error messages.
1341
+ * @public
1342
+ */
1343
+ export declare function mapResults<T>(results: Iterable<Result<T>>): Result<T[]>;
1344
+
1345
+ /**
1346
+ * Aggregates successful results from a a collection of {@link Result | Result<T>}.
1347
+ * @param results - An `Iterable` of {@link Result | Result<T>} from which success
1348
+ * results are to be aggregated.
1349
+ * @returns {@link Success} with an array of `<T>` if any results were successful. If
1350
+ * all {@link Result | results} failed, returns {@link Failure} with a concatenated
1351
+ * summary of all error messages.
1352
+ * @public
1353
+ */
1354
+ export declare function mapSuccess<T>(results: Iterable<Result<T>>): Result<T[]>;
1355
+
1356
+ /**
1357
+ * Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.
1358
+ * @param src - The `Map` object to be converted.
1359
+ * @param factory - The factory method used to convert elements.
1360
+ * @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or
1361
+ * {@link Failure} with an error message if an error occurs.
1362
+ * @public
1363
+ */
1364
+ export declare function mapToRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS>, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
1365
+
1366
+ /**
1367
+ * @public
1368
+ */
1369
+ declare class NoOpLogger extends LoggerBase {
1370
+ protected _innerLog(message: string): Success<string | undefined>;
1371
+ }
1372
+
1373
+ /**
1374
+ * Normalizes an arbitrary JSON object
1375
+ * @public
1376
+ */
1377
+ export declare class Normalizer {
1571
1378
  /**
1572
- * @public
1379
+ * Normalizes the supplied value
1380
+ *
1381
+ * @param from - The value to be normalized
1382
+ * @returns A normalized version of the value
1573
1383
  */
1574
- declare class NoOpLogger extends LoggerBase {
1575
- protected _innerLog(message: string): Success<string | undefined>;
1576
- }
1577
-
1384
+ normalize<T>(from: T): Result<T>;
1578
1385
  /**
1579
- * Normalizes an arbitrary JSON object
1580
- * @public
1386
+ * Compares two property names from some object being normalized.
1387
+ * @param k1 - First key to be compared.
1388
+ * @param k2 - Second key to be compared.
1389
+ * @returns `1` if `k1` is greater, `-1` if `k2` is greater and
1390
+ * `0` if they are equal.
1391
+ * @internal
1581
1392
  */
1582
- export declare class Normalizer {
1583
- /**
1584
- * Normalizes the supplied value
1585
- *
1586
- * @param from - The value to be normalized
1587
- * @returns A normalized version of the value
1588
- */
1589
- normalize<T>(from: T): Result<T>;
1590
- /**
1591
- * Compares two property names from some object being normalized.
1592
- * @param k1 - First key to be compared.
1593
- * @param k2 - Second key to be compared.
1594
- * @returns `1` if `k1` is greater, `-1` if `k2` is greater and
1595
- * `0` if they are equal.
1596
- * @internal
1597
- */
1598
- protected _compareKeys(k1: unknown, k2: unknown): number;
1599
- /**
1600
- * Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).
1601
- * @remarks
1602
- * Converts property names (entry key) to string and then sorts as string.
1603
- * @param entries - The entries to be normalized.
1604
- * @returns A normalized sorted array of entries.
1605
- * @internal
1606
- */
1607
- protected _normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[];
1608
- protected _normalizeArray(from: unknown[]): Result<unknown[]>;
1609
- /**
1610
- * Normalizes the supplied literal value
1611
- * @param from - The literal value to be normalized.
1612
- * @returns A normalized value for the literal.
1613
- * @internal
1614
- */
1615
- protected _normalizeLiteral<T>(from: T): Result<T>;
1616
- }
1617
-
1393
+ protected _compareKeys(k1: unknown, k2: unknown): number;
1618
1394
  /**
1619
- * Computes a normalized hash for an arbitrary javascript value.
1620
- * @public
1395
+ * Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).
1396
+ * @remarks
1397
+ * Converts property names (entry key) to string and then sorts as string.
1398
+ * @param entries - The entries to be normalized.
1399
+ * @returns A normalized sorted array of entries.
1400
+ * @internal
1621
1401
  */
1622
- declare class Normalizer_2 {
1623
- /**
1624
- * Computes a normalized md5 hash from an arbitrary supplied object. Not secure and not
1625
- * intended to be secure. Also not fast and not intended to be fast.
1626
- *
1627
- * Normalization just sorts Maps, Sets and object keys by hash so that differences in order
1628
- * do not affect the hash.
1629
- *
1630
- * @param from - The arbitrary `unknown` to be hashed.
1631
- * @returns A normalized md5 hash for the supplied value.
1632
- */
1633
- computeHash(from: unknown): Result<string>;
1634
- /**
1635
- * Compares two property names from some object being normalized.
1636
- * @param k1 - First key to be compared.
1637
- * @param k2 - Second key to be compared.
1638
- * @returns `1` if `k1` is greater, `-1` if `k2` is greater and
1639
- * `0` if they are equal.
1640
- * @internal
1641
- */
1642
- protected _compareKeys(k1: unknown, k2: unknown): number;
1643
- /**
1644
- * Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).
1645
- * @remarks
1646
- * Converts property names (entry key) to string and then sorts as string.
1647
- * @param entries - The entries to be normalized.
1648
- * @returns A normalized sorted array of entries.
1649
- * @internal
1650
- */
1651
- protected _normalizeEntries(entries: Iterable<[unknown, unknown]>): [unknown, unknown][];
1652
- /**
1653
- * Constructs a normalized string representation of some literal value.
1654
- * @param from - The literal value to be normalized.
1655
- * @returns A normalized string representation of the literal.
1656
- * @internal
1657
- */
1658
- protected _normalizeLiteral(from: string | number | bigint | boolean | symbol | undefined | Date | RegExp | null): Result<string>;
1659
- }
1660
-
1402
+ protected _normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[];
1403
+ protected _normalizeArray(from: unknown[]): Result<unknown[]>;
1661
1404
  /**
1662
- * A {@link Converter} which converts `unknown` to a `number`.
1663
- * @remarks
1664
- * Numbers and strings with a numeric format succeed. Anything else fails.
1665
- * @public
1405
+ * Normalizes the supplied literal value
1406
+ * @param from - The literal value to be normalized.
1407
+ * @returns A normalized value for the literal.
1408
+ * @internal
1666
1409
  */
1667
- declare const number: Converter<number, undefined>;
1668
-
1410
+ protected _normalizeLiteral<T>(from: T): Result<T>;
1411
+ }
1412
+
1413
+ /**
1414
+ * A {@link Converter} which converts `unknown` to a `number`.
1415
+ * @remarks
1416
+ * Numbers and strings with a numeric format succeed. Anything else fails.
1417
+ * @public
1418
+ */
1419
+ declare const number: Converter<number, undefined>;
1420
+
1421
+ /**
1422
+ * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.
1423
+ * @public
1424
+ */
1425
+ declare const number_2: Validator<number>;
1426
+
1427
+ /**
1428
+ * {@link Converter | Converter} to convert an `unknown` to an array of `number`.
1429
+ * @remarks
1430
+ * Returns {@link Success | Success} with the the supplied value if it as an array
1431
+ * of numbers, returns {@link Failure | Failure} with an error message otherwise.
1432
+ * @public
1433
+ */
1434
+ declare const numberArray: Converter<number[]>;
1435
+
1436
+ /**
1437
+ * An in-place {@link Validation.Validator | Validator} for `number` values.
1438
+ * @public
1439
+ */
1440
+ declare class NumberValidator<T extends number = number, TC = unknown> extends GenericValidator<T, TC> {
1669
1441
  /**
1670
- * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.
1671
- * @public
1442
+ * Constructs a new {@link Validation.Classes.NumberValidator | NumberValidator}.
1443
+ * @param params - Optional {@link Validation.Classes.NumberValidatorConstructorParams | init params} for the
1444
+ * new {@link Validation.Classes.NumberValidator | NumberValidator}.
1672
1445
  */
1673
- declare const number_2: Validator<number>;
1674
-
1446
+ constructor(params?: NumberValidatorConstructorParams<T, TC>);
1675
1447
  /**
1676
- * {@link Converter | Converter} to convert an `unknown` to an array of `number`.
1677
- * @remarks
1678
- * Returns {@link Success | Success} with the the supplied value if it as an array
1679
- * of numbers, returns {@link Failure | Failure} with an error message otherwise.
1680
- * @public
1448
+ * Static method which validates that a supplied `unknown` value is a `number`.
1449
+ * @param from - The `unknown` value to be tested.
1450
+ * @returns Returns `true` if `from` is a `number`, or {@link Failure} with an error
1451
+ * message if not.
1681
1452
  */
1682
- declare const numberArray: Converter<number[]>;
1683
-
1453
+ static validateNumber<T extends number>(from: unknown): boolean | Failure<T>;
1454
+ }
1455
+
1456
+ /**
1457
+ * Parameters used to construct a {@link Validation.Classes.NumberValidator | NumberValidator}.
1458
+ * @public
1459
+ */
1460
+ declare type NumberValidatorConstructorParams<T extends number = number, TC = unknown> = GenericValidatorConstructorParams<T, TC>;
1461
+
1462
+ /**
1463
+ * Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T>} which converts an object
1464
+ * without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
1465
+ * {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} to further refine conversion behavior.
1466
+ * @remarks
1467
+ * By default, if all of the requested fields exist and can be converted, returns {@link Success}
1468
+ * with a new object that contains the converted values under the original key names. If any required properties
1469
+ * do not exist or cannot be converted, the entire conversion fails, returning {@link Failure} with additional
1470
+ * error information.
1471
+ *
1472
+ * Fields that succeed but convert to undefined are omitted from the result object but do not
1473
+ * fail the conversion.
1474
+ * @param properties - An {@link Conversion.FieldConverters | FieldConverters<T>} defining the shape of the
1475
+ * source object and {@link Converter | converters} to be applied to each properties.
1476
+ * @param options - An {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} containing options
1477
+ * for the object converter.
1478
+ * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
1479
+ * {@label WITH_OPTIONS}
1480
+ * @public
1481
+ */
1482
+ declare function object<T>(properties: FieldConverters<T>, options?: ObjectConverterOptions<T>): ObjectConverter<T>;
1483
+
1484
+ /**
1485
+ * Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T>} which converts an object
1486
+ * without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and a set of
1487
+ * optional properties.
1488
+ * @remarks
1489
+ * By default, if all of the requested fields exist and can be converted, returns {@link Success}
1490
+ * with a new object that contains the converted values under the original key names. If any required properties
1491
+ * do not exist or cannot be converted, the entire conversion fails, returning {@link Failure} with additional
1492
+ * error information.
1493
+ *
1494
+ * Fields that succeed but convert to undefined are omitted from the result object but do not
1495
+ * fail the conversion.
1496
+ * @param properties - An {@link Conversion.FieldConverters | FieldConverters<T>} defining the shape of the
1497
+ * source object and {@link Converter | converters} to be applied to each properties.
1498
+ * @param optional - An array of `(keyof T)` listing the keys to be considered optional.
1499
+ * {@label WITH_KEYS}
1500
+ * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
1501
+ * @public
1502
+ * @deprecated Use {@link Converters.(object:1) | Converters.object(fields, options)} instead.
1503
+ */
1504
+ declare function object<T>(properties: FieldConverters<T>, optional: (keyof T)[]): ObjectConverter<T>;
1505
+
1506
+ /**
1507
+ * Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates
1508
+ * an object in place.
1509
+ * @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}
1510
+ * describing the validations to be applied.
1511
+ * @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}
1512
+ * to refine the behavior of the resulting {@link Validation.Validator | validator}.
1513
+ * @returns A new {@link Validation.Validator | Validator} which validates the desired
1514
+ * object in place.
1515
+ * @public
1516
+ */
1517
+ declare function object_2<T, TC = unknown>(fields: FieldValidators<T, TC>, params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>): ObjectValidator<T, TC>;
1518
+
1519
+ /**
1520
+ * A {@link Converter} which converts an object of type `<T>` without changing shape, given
1521
+ * a {@link Conversion.FieldConverters | FieldConverters<T>} for the fields in the object.
1522
+ * @remarks
1523
+ * By default, if all of the required fields exist and can be converted, returns a new object with
1524
+ * the converted values under the original key names. If any required fields do not exist or cannot
1525
+ * be converted, the entire conversion fails. See {@link Conversion.ObjectConverterOptions | ObjectConverterOptions}
1526
+ * for other conversion options.
1527
+ * @public
1528
+ */
1529
+ declare class ObjectConverter<T, TC = unknown> extends BaseConverter<T, TC> {
1684
1530
  /**
1685
- * An in-place {@link Validation.Validator | Validator} for `number` values.
1686
- * @public
1531
+ * Fields converted by this {@link Conversion.ObjectConverter | ObjectConverter}.
1687
1532
  */
1688
- declare class NumberValidator<T extends number = number, TC = unknown> extends GenericValidator<T, TC> {
1689
- /**
1690
- * Constructs a new {@link Validation.Classes.NumberValidator | NumberValidator}.
1691
- * @param params - Optional {@link Validation.Classes.NumberValidatorConstructorParams | init params} for the
1692
- * new {@link Validation.Classes.NumberValidator | NumberValidator}.
1693
- */
1694
- constructor(params?: NumberValidatorConstructorParams<T, TC>);
1695
- /**
1696
- * Static method which validates that a supplied `unknown` value is a `number`.
1697
- * @param from - The `unknown` value to be tested.
1698
- * @returns Returns `true` if `from` is a `number`, or {@link Failure} with an error
1699
- * message if not.
1700
- */
1701
- static validateNumber<T extends number>(from: unknown): boolean | Failure<T>;
1702
- }
1703
-
1533
+ readonly fields: FieldConverters<T>;
1704
1534
  /**
1705
- * Parameters used to construct a {@link Validation.Classes.NumberValidator | NumberValidator}.
1706
- * @public
1535
+ * Options used to initialize this {@link Conversion.ObjectConverter | ObjectConverter}.
1707
1536
  */
1708
- declare type NumberValidatorConstructorParams<T extends number = number, TC = unknown> = GenericValidatorConstructorParams<T, TC>;
1709
-
1537
+ readonly options: ObjectConverterOptions<T>;
1710
1538
  /**
1711
- * Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T>} which converts an object
1712
- * without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
1713
- * {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} to further refine conversion behavior.
1714
- * @remarks
1715
- * By default, if all of the requested fields exist and can be converted, returns {@link Success}
1716
- * with a new object that contains the converted values under the original key names. If any required properties
1717
- * do not exist or cannot be converted, the entire conversion fails, returning {@link Failure} with additional
1718
- * error information.
1719
- *
1720
- * Fields that succeed but convert to undefined are omitted from the result object but do not
1721
- * fail the conversion.
1722
- * @param properties - An {@link Conversion.FieldConverters | FieldConverters<T>} defining the shape of the
1723
- * source object and {@link Converter | converters} to be applied to each properties.
1724
- * @param options - An {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} containing options
1725
- * for the object converter.
1726
- * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
1539
+ * Constructs a new {@link Conversion.ObjectConverter | ObjectConverter<T>} using options
1540
+ * supplied in a {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.
1541
+ * @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing
1542
+ * a {@link Converter} for each field
1543
+ * @param options - An optional @see ObjectConverterOptions to configure the conversion
1727
1544
  * {@label WITH_OPTIONS}
1728
- * @public
1729
1545
  */
1730
- declare function object<T>(properties: FieldConverters<T>, options?: ObjectConverterOptions<T>): ObjectConverter<T>;
1731
-
1546
+ constructor(fields: FieldConverters<T, TC>, options?: ObjectConverterOptions<T>);
1732
1547
  /**
1733
- * Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T>} which converts an object
1734
- * without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and a set of
1735
- * optional properties.
1736
- * @remarks
1737
- * By default, if all of the requested fields exist and can be converted, returns {@link Success}
1738
- * with a new object that contains the converted values under the original key names. If any required properties
1739
- * do not exist or cannot be converted, the entire conversion fails, returning {@link Failure} with additional
1740
- * error information.
1741
- *
1742
- * Fields that succeed but convert to undefined are omitted from the result object but do not
1743
- * fail the conversion.
1744
- * @param properties - An {@link Conversion.FieldConverters | FieldConverters<T>} defining the shape of the
1745
- * source object and {@link Converter | converters} to be applied to each properties.
1746
- * @param optional - An array of `(keyof T)` listing the keys to be considered optional.
1548
+ * Constructs a new {@link Conversion.ObjectConverter | ObjectConverter<T>} with optional
1549
+ * properties specified as an array of `keyof T`.
1550
+ * @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing
1551
+ * a {@link Converter} for each field.
1552
+ * @param optional - An array of `keyof T` listing fields that are not required.
1747
1553
  * {@label WITH_KEYS}
1748
- * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
1749
- * @public
1750
- * @deprecated Use {@link Converters.(object:1) | Converters.object(fields, options)} instead.
1751
1554
  */
1752
- declare function object<T>(properties: FieldConverters<T>, optional: (keyof T)[]): ObjectConverter<T>;
1753
-
1555
+ constructor(fields: FieldConverters<T, TC>, optional?: (keyof T)[]);
1556
+ /**
1557
+ * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with
1558
+ * new optional properties as specified by a supplied {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.
1559
+ * @param options - The {@link Conversion.ObjectConverterOptions | options} to be applied to the new
1560
+ * converter.
1561
+ * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source properties.
1562
+ * {@label WITH_OPTIONS}
1563
+ */
1564
+ partial(options: ObjectConverterOptions<T>): ObjectConverter<Partial<T>, TC>;
1565
+ /**
1566
+ * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with
1567
+ * new optional properties as specified by a supplied array of `keyof T`.
1568
+ * @param optional - The keys of the source object properties to be made optional.
1569
+ * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source
1570
+ * properties.
1571
+ * {@label WITH_KEYS}
1572
+ */
1573
+ partial(optional?: (keyof T)[]): ObjectConverter<Partial<T>, TC>;
1574
+ /**
1575
+ * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with
1576
+ * new optional properties as specified by a supplied array of `keyof T`.
1577
+ * @param addOptionalProperties - The keys to be made optional.
1578
+ * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source
1579
+ * properties.
1580
+ */
1581
+ addPartial(addOptionalProperties: (keyof T)[]): ObjectConverter<Partial<T>, TC>;
1582
+ }
1583
+
1584
+ /**
1585
+ * Options for an {@link Conversion.ObjectConverter | ObjectConverter}.
1586
+ * @public
1587
+ */
1588
+ declare interface ObjectConverterOptions<T> {
1589
+ /**
1590
+ * If present, lists optional fields. Missing non-optional fields cause an error.
1591
+ */
1592
+ optionalFields?: (keyof T)[];
1593
+ /**
1594
+ * If true, unrecognized fields yield an error. If false or undefined (default),
1595
+ * unrecognized fields are ignored.
1596
+ */
1597
+ strict?: boolean;
1598
+ /**
1599
+ * Optional description to be included in error messages.
1600
+ */
1601
+ description?: string;
1602
+ }
1603
+
1604
+ /**
1605
+ * In-place {@link Validation.Validator | Validator} for an object of type `<T>`.
1606
+ * @remarks
1607
+ * By default, succeeds if all of the required fields exist and are validate, and fails if
1608
+ * any required fields do not exist or are invalid. See {@link Validation.Classes.ObjectValidatorOptions}
1609
+ * for other validation options.
1610
+ * @public
1611
+ */
1612
+ declare class ObjectValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
1613
+ /**
1614
+ * A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a
1615
+ * {@link Validation.Validator | Validator} for each of the expected properties
1616
+ */
1617
+ readonly fields: FieldValidators<T>;
1618
+ /**
1619
+ * {@link Validation.Classes.ObjectValidatorOptions | Options} which apply to this
1620
+ * validator.
1621
+ */
1622
+ readonly options: ObjectValidatorOptions<T, TC>;
1754
1623
  /**
1755
- * Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates
1756
- * an object in place.
1757
- * @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}
1758
- * describing the validations to be applied.
1759
- * @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}
1760
- * to refine the behavior of the resulting {@link Validation.Validator | validator}.
1761
- * @returns A new {@link Validation.Validator | Validator} which validates the desired
1762
- * object in place.
1624
+ * @internal
1625
+ */
1626
+ protected readonly _innerValidators: FieldValidators<T>;
1627
+ /**
1628
+ * @internal
1629
+ */
1630
+ protected readonly _allowedFields?: Set<keyof T>;
1631
+ /**
1632
+ * Constructs a new {@link Validation.Classes.ObjectValidator | ObjectValidator<T>}.
1633
+ * @param fields - A {@link Validation.Classes.FieldValidators | FieldValidators<T>} containing
1634
+ * a {@link Validation.Validator | Validator} for each field.
1635
+ * @param options - An optional {@link Validation.Classes.ObjectValidatorOptions} to configure
1636
+ * validation.
1637
+ */
1638
+ constructor(params: ObjectValidatorConstructorParams<T, TC>);
1639
+ /**
1640
+ * Creates the actual {@link Validation.Classes.FieldValidators | FieldValidators<T>} to be
1641
+ * used by this converter by applying any options or traits defined in the options
1642
+ * to the field converters passed to the constructor.
1643
+ * @param fields - The base {@link Validation.Classes.FieldValidators | FieldValidators<T>} passed
1644
+ * in to the constructor.
1645
+ * @param options - The {@link Validation.Classes.ObjectValidatorOptions | object validator options}
1646
+ * passed in to the constructor.
1647
+ * @returns A new {@link Validation.Classes.FieldValidators | FieldValidators} with the fully-configured
1648
+ * individual {@link Validation.Validator | field validators} to be applied.
1649
+ * @internal
1650
+ */
1651
+ protected static _resolveValidators<T, TC>(fields: FieldValidators<T, TC>, options?: ObjectValidatorOptions<T, TC>): FieldValidators<T, TC>;
1652
+ /**
1653
+ * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with
1654
+ * new optional properties as specified by a supplied
1655
+ * {@link Validation.Classes.ObjectValidatorOptions | ObjectValidatorOptions<T>}.
1656
+ * @param options - The {@link Validation.Classes.ObjectValidatorOptions | options} to be applied to the new
1657
+ * {@link Validation.Classes.ObjectValidator | validator}.
1658
+ * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional
1659
+ * source properties.
1660
+ */
1661
+ partial(options?: ObjectValidatorOptions<T, TC>): ObjectValidator<Partial<T>, TC>;
1662
+ /**
1663
+ * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with
1664
+ * new optional properties as specified by a supplied array of `keyof T`.
1665
+ * @param addOptionalProperties - The keys to be made optional.
1666
+ * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional
1667
+ * source properties.
1668
+ */
1669
+ addPartial(addOptionalFields: (keyof T)[]): ObjectValidator<Partial<T>, TC>;
1670
+ /**
1671
+ * {@inheritdoc Validation.ValidatorBase._validate}
1672
+ * @internal
1673
+ */
1674
+ protected _validate(from: unknown, context?: TC): boolean | Failure<T>;
1675
+ }
1676
+
1677
+ /**
1678
+ * Options for the {@link Validation.Classes.ObjectValidator | ObjectValidator} constructor.
1679
+ * @public
1680
+ */
1681
+ declare interface ObjectValidatorConstructorParams<T, TC> extends ValidatorBaseConstructorParams<T, TC> {
1682
+ /**
1683
+ * A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a
1684
+ * {@link Validation.Validator | Validator} for each of the expected properties
1685
+ * of a result object.
1686
+ */
1687
+ fields: FieldValidators<T>;
1688
+ /**
1689
+ * Optional additional {@link Validation.Classes.ObjectValidatorOptions | ValidatorOptions} to
1690
+ * configure validation.
1691
+ */
1692
+ options?: ObjectValidatorOptions<T, TC>;
1693
+ }
1694
+
1695
+ /**
1696
+ * Options for an {@link Validation.Classes.ObjectValidator | ObjectValidator}.
1697
+ * @public
1698
+ */
1699
+ declare interface ObjectValidatorOptions<T, TC> extends ValidatorOptions<TC> {
1700
+ /**
1701
+ * If present, lists optional fields. Missing non-optional fields cause an error.
1702
+ */
1703
+ optionalFields?: (keyof T)[];
1704
+ /**
1705
+ * If true, unrecognized fields yield an error. If false or undefined (default),
1706
+ * unrecognized fields are ignored.
1707
+ */
1708
+ strict?: boolean;
1709
+ }
1710
+
1711
+ /**
1712
+ * Simple implicit omit function, which picks all of the properties from a supplied
1713
+ * object except those specified for exclusion.
1714
+ * @param from - The object from which keys are to be picked.
1715
+ * @param exclude - The keys of the properties to be excluded from the returned object.
1716
+ * @returns A new object containing all of the properties from `from` that were not
1717
+ * explicitly excluded.
1718
+ * @public
1719
+ */
1720
+ export declare function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K>;
1721
+
1722
+ /**
1723
+ * A helper function to create a {@link Converter} for polymorphic values. Returns a
1724
+ * converter which Invokes the wrapped converters in sequence, returning the first successful
1725
+ * result. Returns an error if none of the supplied converters can convert the value.
1726
+ * @remarks
1727
+ * If `onError` is `ignoreErrors` (default), then errors from any of the
1728
+ * converters are ignored provided that some converter succeeds. If
1729
+ * onError is `failOnError`, then an error from any converter fails the entire
1730
+ * conversion.
1731
+ *
1732
+ * @param converters - An ordered list of {@link Converter | converters} to be considered.
1733
+ * @param onError - Specifies treatment of unconvertible elements.
1734
+ * @returns A new {@link Converter} which yields a value from the union of the types returned
1735
+ * by the wrapped converters.
1736
+ * @public
1737
+ */
1738
+ declare function oneOf<T, TC = unknown>(converters: Array<Converter<T, TC>>, onError?: OnError_2): Converter<T, TC>;
1739
+
1740
+ declare type OnError = 'failOnError' | 'ignoreErrors';
1741
+
1742
+ /**
1743
+ * Action to take on conversion failures.
1744
+ * @public
1745
+ */
1746
+ declare type OnError_2 = 'failOnError' | 'ignoreErrors';
1747
+
1748
+ /**
1749
+ * A {@link Converter} to convert an optional `boolean` value.
1750
+ * @remarks
1751
+ * Values of type `boolean` or strings that match (case-insensitive) `'true'`
1752
+ * or `'false'` are converted and returned. Anything else returns {@link Success}
1753
+ * with value `undefined`.
1754
+ * @public
1755
+ */
1756
+ declare const optionalBoolean: Converter<boolean | undefined>;
1757
+
1758
+ /**
1759
+ * A helper function to create a {@link Converter} which extracts and converts an optional element from an array.
1760
+ * @remarks
1761
+ * The resulting {@link Converter} returns {@link Success} with the converted value if the element exists
1762
+ * in the supplied array and can be converted. Returns {@link Success} with value `undefined` if the parameter
1763
+ * is an array but the index is out of range. Returns {@link Failure} with a message if the supplied parameter
1764
+ * is not an array, if the requested index is negative, or if the element cannot be converted.
1765
+ * @param index - The index of the element to be extracted.
1766
+ * @param converter - A {@link Converter} used to convert the extracted element.
1767
+ * @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
1768
+ * @public
1769
+ */
1770
+ declare function optionalElement<T, TC = undefined>(index: number, converter: Converter<T, TC>): Converter<T | undefined, TC>;
1771
+
1772
+ /**
1773
+ * A helper function to create a {@link Converter} which extracts and convert a property specified
1774
+ * by name from an object.
1775
+ * @remarks
1776
+ * The resulting {@link Converter} returns {@link Success} with the converted value of the corresponding
1777
+ * object property if the field exists and can be converted. Returns {@link Success} with value `undefined`
1778
+ * if the supplied parameter is an object but the named field is not present. Returns {@link Failure} with
1779
+ * an error message otherwise.
1780
+ * @param name - The name of the field to be extracted.
1781
+ * @param converter - {@link Converter} used to convert the extracted field.
1782
+ * @public
1783
+ */
1784
+ declare function optionalField<T, TC = undefined>(name: string, converter: Converter<T, TC>): Converter<T | undefined, TC>;
1785
+
1786
+ /**
1787
+ * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`
1788
+ * @param src - The `ReadonlyMap` object to be converted, or `undefined`.
1789
+ * @param factory - The factory method used to convert elements.
1790
+ * @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.
1791
+ * Returns {@link Failure} with a message if an error occurs.
1763
1792
  * @public
1764
1793
  */
1765
- declare function object_2<T, TC = unknown>(fields: FieldValidators<T, TC>, params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>): ObjectValidator<T, TC>;
1794
+ export declare function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
1795
+
1796
+ /**
1797
+ * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.
1798
+ * @param src - The `Map` object to be converted, or `undefined`.
1799
+ * @param factory - The factory method used to convert elements.
1800
+ * @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if
1801
+ * `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.
1802
+ * @public
1803
+ */
1804
+ export declare function optionalMapToRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD> | undefined>;
1805
+
1806
+ /**
1807
+ * A {@link Converter} which converts an optional `number` value.
1808
+ * @remarks
1809
+ * Values of type `number` or numeric strings are converted and returned.
1810
+ * Anything else returns {@link Success} with value `undefined`.
1811
+ * @public
1812
+ */
1813
+ declare const optionalNumber: Converter<number | undefined>;
1814
+
1815
+ /**
1816
+ * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.
1817
+ * @param src - The `Record` to be converted, or undefined.
1818
+ * @param factory - The factory method used to convert elements.
1819
+ * @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`
1820
+ * if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.
1821
+ * @public
1822
+ */
1823
+ export declare function optionalRecordToMap<TS, TD, TK extends string = string>(src: Record<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD> | undefined>;
1824
+
1825
+ /**
1826
+ * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`
1827
+ * @param src - The `Record` to be converted, or `undefined`.
1828
+ * @param factory - The factory method used to convert elements.
1829
+ * @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.
1830
+ * Returns {@link Failure} with a message if an error occurs.
1831
+ * @public
1832
+ */
1833
+ export declare function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(src: Record<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD>>;
1766
1834
 
1767
1835
  /**
1768
- * A {@link Converter} which converts an object of type `<T>` without changing shape, given
1769
- * a {@link Conversion.FieldConverters | FieldConverters<T>} for the fields in the object.
1770
- * @remarks
1771
- * By default, if all of the required fields exist and can be converted, returns a new object with
1772
- * the converted values under the original key names. If any required fields do not exist or cannot
1773
- * be converted, the entire conversion fails. See {@link Conversion.ObjectConverterOptions | ObjectConverterOptions}
1774
- * for other conversion options.
1836
+ * A {@link Converter} which converts an optional `string` value. Values of type
1837
+ * `string` are returned. Anything else returns {@link Success} with value `undefined`.
1775
1838
  * @public
1776
1839
  */
1777
- declare class ObjectConverter<T, TC = unknown> extends BaseConverter<T, TC> {
1778
- /**
1779
- * Fields converted by this {@link Conversion.ObjectConverter | ObjectConverter}.
1780
- */
1781
- readonly fields: FieldConverters<T>;
1782
- /**
1783
- * Options used to initialize this {@link Conversion.ObjectConverter | ObjectConverter}.
1784
- */
1785
- readonly options: ObjectConverterOptions<T>;
1786
- /**
1787
- * Constructs a new {@link Conversion.ObjectConverter | ObjectConverter<T>} using options
1788
- * supplied in a {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.
1789
- * @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing
1790
- * a {@link Converter} for each field
1791
- * @param options - An optional @see ObjectConverterOptions to configure the conversion
1792
- * {@label WITH_OPTIONS}
1793
- */
1794
- constructor(fields: FieldConverters<T, TC>, options?: ObjectConverterOptions<T>);
1795
- /**
1796
- * Constructs a new {@link Conversion.ObjectConverter | ObjectConverter<T>} with optional
1797
- * properties specified as an array of `keyof T`.
1798
- * @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing
1799
- * a {@link Converter} for each field.
1800
- * @param optional - An array of `keyof T` listing fields that are not required.
1801
- * {@label WITH_KEYS}
1802
- */
1803
- constructor(fields: FieldConverters<T, TC>, optional?: (keyof T)[]);
1804
- /**
1805
- * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with
1806
- * new optional properties as specified by a supplied {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.
1807
- * @param options - The {@link Conversion.ObjectConverterOptions | options} to be applied to the new
1808
- * converter.
1809
- * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source properties.
1810
- * {@label WITH_OPTIONS}
1811
- */
1812
- partial(options: ObjectConverterOptions<T>): ObjectConverter<Partial<T>, TC>;
1813
- /**
1814
- * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with
1815
- * new optional properties as specified by a supplied array of `keyof T`.
1816
- * @param optional - The keys of the source object properties to be made optional.
1817
- * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source
1818
- * properties.
1819
- * {@label WITH_KEYS}
1820
- */
1821
- partial(optional?: (keyof T)[]): ObjectConverter<Partial<T>, TC>;
1822
- /**
1823
- * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with
1824
- * new optional properties as specified by a supplied array of `keyof T`.
1825
- * @param addOptionalProperties - The keys to be made optional.
1826
- * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source
1827
- * properties.
1828
- */
1829
- addPartial(addOptionalProperties: (keyof T)[]): ObjectConverter<Partial<T>, TC>;
1830
- }
1840
+ declare const optionalString: Converter<string | undefined, unknown>;
1831
1841
 
1832
1842
  /**
1833
- * Options for an {@link Conversion.ObjectConverter | ObjectConverter}.
1843
+ * Simple implicit pick function, which picks a set of properties from a supplied
1844
+ * object. Ignores picked properties that do not exist regardless of type signature.
1845
+ * @param from - The object from which keys are to be picked.
1846
+ * @param include - The keys of the properties to be picked from `from`.
1847
+ * @returns A new object containing the requested properties from `from`, where present.
1834
1848
  * @public
1835
1849
  */
1836
- declare interface ObjectConverterOptions<T> {
1837
- /**
1838
- * If present, lists optional fields. Missing non-optional fields cause an error.
1839
- */
1840
- optionalFields?: (keyof T)[];
1841
- /**
1842
- * If true, unrecognized fields yield an error. If false or undefined (default),
1843
- * unrecognized fields are ignored.
1844
- */
1845
- strict?: boolean;
1846
- /**
1847
- * Optional description to be included in error messages.
1848
- */
1849
- description?: string;
1850
- }
1850
+ export declare function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K>;
1851
1851
 
1852
1852
  /**
1853
- * In-place {@link Validation.Validator | Validator} for an object of type `<T>`.
1854
- * @remarks
1855
- * By default, succeeds if all of the required fields exist and are validate, and fails if
1856
- * any required fields do not exist or are invalid. See {@link Validation.Classes.ObjectValidatorOptions}
1857
- * for other validation options.
1853
+ * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
1854
+ * Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a
1855
+ * concatenated list of all error messages.
1856
+ * @param initializers - An object with the shape of the target but with initializer functions for
1857
+ * each property.
1858
+ * @param options - An optional {@link PopulateObjectOptions | set of options} which
1859
+ * modify the behavior of this call.
1860
+ * {@label WITH_OPTIONS}
1858
1861
  * @public
1859
1862
  */
1860
- declare class ObjectValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
1861
- /**
1862
- * A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a
1863
- * {@link Validation.Validator | Validator} for each of the expected properties
1864
- */
1865
- readonly fields: FieldValidators<T>;
1866
- /**
1867
- * {@link Validation.Classes.ObjectValidatorOptions | Options} which apply to this
1868
- * validator.
1869
- */
1870
- readonly options: ObjectValidatorOptions<T, TC>;
1871
- /**
1872
- * @internal
1873
- */
1874
- protected readonly _innerValidators: FieldValidators<T>;
1875
- /**
1876
- * @internal
1877
- */
1878
- protected readonly _allowedFields?: Set<keyof T>;
1879
- /**
1880
- * Constructs a new {@link Validation.Classes.ObjectValidator | ObjectValidator<T>}.
1881
- * @param fields - A {@link Validation.Classes.FieldValidators | FieldValidators<T>} containing
1882
- * a {@link Validation.Validator | Validator} for each field.
1883
- * @param options - An optional {@link Validation.Classes.ObjectValidatorOptions} to configure
1884
- * validation.
1885
- */
1886
- constructor(params: ObjectValidatorConstructorParams<T, TC>);
1887
- /**
1888
- * Creates the actual {@link Validation.Classes.FieldValidators | FieldValidators<T>} to be
1889
- * used by this converter by applying any options or traits defined in the options
1890
- * to the field converters passed to the constructor.
1891
- * @param fields - The base {@link Validation.Classes.FieldValidators | FieldValidators<T>} passed
1892
- * in to the constructor.
1893
- * @param options - The {@link Validation.Classes.ObjectValidatorOptions | object validator options}
1894
- * passed in to the constructor.
1895
- * @returns A new {@link Validation.Classes.FieldValidators | FieldValidators} with the fully-configured
1896
- * individual {@link Validation.Validator | field validators} to be applied.
1897
- * @internal
1898
- */
1899
- protected static _resolveValidators<T, TC>(fields: FieldValidators<T, TC>, options?: ObjectValidatorOptions<T, TC>): FieldValidators<T, TC>;
1900
- /**
1901
- * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with
1902
- * new optional properties as specified by a supplied
1903
- * {@link Validation.Classes.ObjectValidatorOptions | ObjectValidatorOptions<T>}.
1904
- * @param options - The {@link Validation.Classes.ObjectValidatorOptions | options} to be applied to the new
1905
- * {@link Validation.Classes.ObjectValidator | validator}.
1906
- * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional
1907
- * source properties.
1908
- */
1909
- partial(options?: ObjectValidatorOptions<T, TC>): ObjectValidator<Partial<T>, TC>;
1910
- /**
1911
- * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with
1912
- * new optional properties as specified by a supplied array of `keyof T`.
1913
- * @param addOptionalProperties - The keys to be made optional.
1914
- * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional
1915
- * source properties.
1916
- */
1917
- addPartial(addOptionalFields: (keyof T)[]): ObjectValidator<Partial<T>, TC>;
1918
- /**
1919
- * {@inheritdoc Validation.ValidatorBase._validate}
1920
- * @internal
1921
- */
1922
- protected _validate(from: unknown, context?: TC): boolean | Failure<T>;
1923
- }
1863
+ export declare function populateObject<T>(initializers: FieldInitializers<T>, options?: PopulateObjectOptions<T>): Result<T>;
1924
1864
 
1925
1865
  /**
1926
- * Options for the {@link Validation.Classes.ObjectValidator | ObjectValidator} constructor.
1866
+ * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
1867
+ * Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a
1868
+ * concatenated list of all error messages.
1869
+ * @param initializers - An object with the shape of the target but with initializer functions for
1870
+ * each property.
1871
+ * @param order - Optional order in which keys should be written.
1927
1872
  * @public
1873
+ * {@label WITH_ORDER}
1874
+ * @deprecated Pass {@link PopulateObjectOptions} instead.
1928
1875
  */
1929
- declare interface ObjectValidatorConstructorParams<T, TC> extends ValidatorBaseConstructorParams<T, TC> {
1930
- /**
1931
- * A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a
1932
- * {@link Validation.Validator | Validator} for each of the expected properties
1933
- * of a result object.
1934
- */
1935
- fields: FieldValidators<T>;
1936
- /**
1937
- * Optional additional {@link Validation.Classes.ObjectValidatorOptions | ValidatorOptions} to
1938
- * configure validation.
1939
- */
1940
- options?: ObjectValidatorOptions<T, TC>;
1941
- }
1876
+ export declare function populateObject<T>(initializers: FieldInitializers<T>, order: (keyof T)[]): Result<T>;
1942
1877
 
1943
1878
  /**
1944
- * Options for an {@link Validation.Classes.ObjectValidator | ObjectValidator}.
1879
+ * Options for the {@link (populateObject:1)} function.
1945
1880
  * @public
1946
1881
  */
1947
- declare interface ObjectValidatorOptions<T, TC> extends ValidatorOptions<TC> {
1882
+ export declare interface PopulateObjectOptions<T> {
1948
1883
  /**
1949
- * If present, lists optional fields. Missing non-optional fields cause an error.
1884
+ * If present, specifies the order in which property values should
1885
+ * be evaluated. Any keys not listed are evaluated after all listed
1886
+ * keys in indeterminate order. If 'order' is not present, keys
1887
+ * are evaluated in indeterminate order.
1950
1888
  */
1951
- optionalFields?: (keyof T)[];
1889
+ order?: (keyof T)[];
1952
1890
  /**
1953
- * If true, unrecognized fields yield an error. If false or undefined (default),
1954
- * unrecognized fields are ignored.
1891
+ * Specify handling of `undefined` values. By default, successful
1892
+ * `undefined` results are written to the result object. If this value
1893
+ * is `true` then `undefined` results are suppressed for all properties.
1894
+ * If this value is an array of property keys then `undefined` results
1895
+ * are suppressed for those properties only.
1955
1896
  */
1956
- strict?: boolean;
1897
+ suppressUndefined?: boolean | (keyof T)[];
1957
1898
  }
1958
1899
 
1959
1900
  /**
1960
- * Simple implicit omit function, which picks all of the properties from a supplied
1961
- * object except those specified for exclusion.
1962
- * @param from - The object from which keys are to be picked.
1963
- * @param exclude - The keys of the properties to be excluded from the returned object.
1964
- * @returns A new object containing all of the properties from `from` that were not
1965
- * explicitly excluded.
1966
- * @public
1967
- */
1968
- export declare function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K>;
1969
-
1970
- /**
1971
- * A helper function to create a {@link Converter} for polymorphic values. Returns a
1972
- * converter which Invokes the wrapped converters in sequence, returning the first successful
1973
- * result. Returns an error if none of the supplied converters can convert the value.
1974
- * @remarks
1975
- * If `onError` is `ignoreErrors` (default), then errors from any of the
1976
- * converters are ignored provided that some converter succeeds. If
1977
- * onError is `failOnError`, then an error from any converter fails the entire
1978
- * conversion.
1979
- *
1980
- * @param converters - An ordered list of {@link Converter | converters} to be considered.
1981
- * @param onError - Specifies treatment of unconvertible elements.
1982
- * @returns A new {@link Converter} which yields a value from the union of the types returned
1983
- * by the wrapped converters.
1901
+ * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied
1902
+ * event details as appropriate.
1903
+ * @param result - The {@link Result} to be propagated.
1904
+ * @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.
1905
+ * @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`
1906
+ * is omitted or `undefined`, then `detail` will be applied to {@link Success} results.
1907
+ * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error
1908
+ * message from the original `result` but with the specified detail added.
1984
1909
  * @public
1985
1910
  */
1986
- declare function oneOf<T, TC = unknown>(converters: Array<Converter<T, TC>>, onError?: OnError_2): Converter<T, TC>;
1987
-
1988
- declare type OnError = 'failOnError' | 'ignoreErrors';
1989
-
1990
- declare type OnError_2 = 'failOnError' | 'ignoreErrors';
1911
+ export declare function propagateWithDetail<T, TD>(result: Result<T>, detail: TD, successDetail?: TD): DetailedResult<T, TD>;
1991
1912
 
1992
1913
  /**
1993
- * A {@link Converter} to convert an optional `boolean` value.
1914
+ * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1915
+ * using a supplied {@link Converter | Converter<T>} to produce a `Record<string, T>`.
1994
1916
  * @remarks
1995
- * Values of type `boolean` or strings that match (case-insensitive) `'true'`
1996
- * or `'false'` are converted and returned. Anything else returns {@link Success}
1997
- * with value `undefined`.
1917
+ * The resulting converter fails conversion if any element cannot be converted.
1918
+ * @param converter - {@link Converter} used to convert each item in the source object.
1919
+ * @returns A {@link Converter} which returns `Record<string, T>`.
1920
+ * {@label WITH_DEFAULT}
1998
1921
  * @public
1999
1922
  */
2000
- declare const optionalBoolean: Converter<boolean | undefined>;
1923
+ declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>): Converter<Record<TK, T>, TC>;
2001
1924
 
2002
1925
  /**
2003
- * A helper function to create a {@link Converter} which extracts and converts an optional element from an array.
1926
+ * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1927
+ * using a supplied {@link Converter | Converter<T>} to produce a `Record<string, T>` and optionally
1928
+ * specified handling of elements that cannot be converted.
2004
1929
  * @remarks
2005
- * The resulting {@link Converter} returns {@link Success} with the converted value if the element exists
2006
- * in the supplied array and can be converted. Returns {@link Success} with value `undefined` if the parameter
2007
- * is an array but the index is out of range. Returns {@link Failure} with a message if the supplied parameter
2008
- * is not an array, if the requested index is negative, or if the element cannot be converted.
2009
- * @param index - The index of the element to be extracted.
2010
- * @param converter - A {@link Converter} used to convert the extracted element.
2011
- * @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
1930
+ * if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
1931
+ * cannot be converted. If `onError` is `'ignore'`, failing elements are silently ignored.
1932
+ * @param converter - {@link Converter} used to convert each item in the source object.
1933
+ * @returns A {@link Converter} which returns `Record<string, T>`.
1934
+ * {@label WITH_ON_ERROR}
2012
1935
  * @public
2013
1936
  */
2014
- declare function optionalElement<T, TC = undefined>(index: number, converter: Converter<T, TC>): Converter<T | undefined, TC>;
1937
+ declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, onError: 'fail' | 'ignore'): Converter<Record<TK, T>, TC>;
2015
1938
 
2016
1939
  /**
2017
- * A helper function to create a {@link Converter} which extracts and convert a property specified
2018
- * by name from an object.
1940
+ * A helper function to create a {@link Converter} which converts the `string`-keyed properties
1941
+ * using a supplied {@link Converter | Converter<T>} to produce a `Record<TK, T>`.
2019
1942
  * @remarks
2020
- * The resulting {@link Converter} returns {@link Success} with the converted value of the corresponding
2021
- * object property if the field exists and can be converted. Returns {@link Success} with value `undefined`
2022
- * if the supplied parameter is an object but the named field is not present. Returns {@link Failure} with
2023
- * an error message otherwise.
2024
- * @param name - The name of the field to be extracted.
2025
- * @param converter - {@link Converter} used to convert the extracted field.
1943
+ * If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
1944
+ * converter for keys and/or control the handling of elements that fail conversion.
1945
+ * @param converter - {@link Converter} used to convert each item in the source object.
1946
+ * @param options - Optional {@link Converters.KeyedConverterOptions | KeyedConverterOptions<TK, TC>} which
1947
+ * supplies a key converter and/or error-handling options.
1948
+ * @returns A {@link Converter} which returns `Record<TK, T>`.
1949
+ * {@label WITH_OPTIONS}
2026
1950
  * @public
2027
1951
  */
2028
- declare function optionalField<T, TC = undefined>(name: string, converter: Converter<T, TC>): Converter<T | undefined, TC>;
1952
+ declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, options: KeyedConverterOptions<TK, TC>): Converter<Record<TK, T>, TC>;
2029
1953
 
2030
1954
  /**
2031
- * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`
2032
- * @param src - The `ReadonlyMap` object to be converted, or `undefined`.
1955
+ * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.
1956
+ * @param src - The `Record` to be converted.
2033
1957
  * @param factory - The factory method used to convert elements.
2034
- * @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.
2035
- * Returns {@link Failure} with a message if an error occurs.
1958
+ * @returns {@link Success} with the resulting map on success, or {@link Failure} with a
1959
+ * message if an error occurs.
2036
1960
  * @public
2037
1961
  */
2038
- export declare function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
1962
+ export declare function recordToMap<TS, TD, TK extends string = string>(src: Record<TK, TS>, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD>>;
2039
1963
 
2040
1964
  /**
2041
- * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.
2042
- * @param src - The `Map` object to be converted, or `undefined`.
2043
- * @param factory - The factory method used to convert elements.
2044
- * @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if
2045
- * `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.
2046
- * @public
2047
- */
2048
- export declare function optionalMapToRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD> | undefined>;
2049
-
2050
- /**
2051
- * A {@link Converter} which converts an optional `number` value.
2052
- * @remarks
2053
- * Values of type `number` or numeric strings are converted and returned.
2054
- * Anything else returns {@link Success} with value `undefined`.
2055
- * @public
2056
- */
2057
- declare const optionalNumber: Converter<number | undefined>;
2058
-
2059
- /**
2060
- * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.
2061
- * @param src - The `Record` to be converted, or undefined.
2062
- * @param factory - The factory method used to convert elements.
2063
- * @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`
2064
- * if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.
2065
- * @public
2066
- */
2067
- export declare function optionalRecordToMap<TS, TD, TK extends string = string>(src: Record<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD> | undefined>;
2068
-
2069
- /**
2070
- * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`
2071
- * @param src - The `Record` to be converted, or `undefined`.
2072
- * @param factory - The factory method used to convert elements.
2073
- * @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.
2074
- * Returns {@link Failure} with a message if an error occurs.
2075
- * @public
2076
- */
2077
- export declare function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(src: Record<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD>>;
1965
+ * Represents the {@link IResult | result} of some operation or sequence of operations.
1966
+ * @remarks
1967
+ * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common
1968
+ * contract {@link IResult}, enabling commingled discriminated usage.
1969
+ * @public
1970
+ */
1971
+ export declare type Result<T> = Success<T> | Failure<T>;
2078
1972
 
2079
- /**
2080
- * A {@link Converter} which converts an optional `string` value. Values of type
2081
- * `string` are returned. Anything else returns {@link Success} with value `undefined`.
2082
- * @public
2083
- */
2084
- declare const optionalString: Converter<string | undefined, unknown>;
1973
+ /**
1974
+ * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.
1975
+ * @beta
1976
+ */
1977
+ export declare type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;
2085
1978
 
2086
- /**
2087
- * Reads a record-jar from an array of strings, each of which represents one
2088
- * line in the source file.
2089
- * @param lines - the array of strings to be parsed
2090
- * @param options - Optional parser configuration
2091
- * @returns a corresponding array of `Record<string, string>`
2092
- * @public
2093
- */
2094
- declare function parseRecordJarLines(lines: string[], options?: JarRecordParserOptions): Result<JarRecord[]>;
1979
+ /**
1980
+ * Type inference to determine the result type of an {@link Result}.
1981
+ * @beta
1982
+ */
1983
+ export declare type ResultValueType<T> = T extends Result<infer TV> ? TV : never;
2095
1984
 
2096
- /**
2097
- * Simple implicit pick function, which picks a set of properties from a supplied
2098
- * object. Ignores picked properties that do not exist regardless of type signature.
2099
- * @param from - The object from which keys are to be picked.
2100
- * @param include - The keys of the properties to be picked from `from`.
2101
- * @returns A new object containing the requested properties from `from`, where present.
2102
- * @public
2103
- */
2104
- export declare function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K>;
1985
+ /**
1986
+ * Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter} which converts an object
1987
+ * without changing shape, a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
1988
+ * {@link Converters.StrictObjectConverterOptions | StrictObjectConverterOptions<T>} to further refine
1989
+ * conversion behavior.
1990
+ *
1991
+ * @remarks
1992
+ * Fields that succeed but convert to undefined are omitted from the result object but do not
1993
+ * fail the conversion.
1994
+ *
1995
+ * The conversion fails if any unexpected fields are encountered.
1996
+ *
1997
+ * @param properties - An object containing defining the shape and converters to be applied.
1998
+ * @param options - An optional @see StrictObjectConverterOptions<T> containing options for the object converter.
1999
+ * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
2000
+ * {@label WITH_OPTIONS}
2001
+ * @public
2002
+ */
2003
+ declare function strictObject<T>(properties: FieldConverters<T>, options?: StrictObjectConverterOptions<T>): ObjectConverter<T>;
2105
2004
 
2106
- /**
2107
- * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
2108
- * Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a
2109
- * concatenated list of all error messages.
2110
- * @param initializers - An object with the shape of the target but with initializer functions for
2111
- * each property.
2112
- * @param options - An optional {@link PopulateObjectOptions | set of options} which
2113
- * modify the behavior of this call.
2114
- * {@label WITH_OPTIONS}
2115
- * @public
2116
- */
2117
- export declare function populateObject<T>(initializers: FieldInitializers<T>, options?: PopulateObjectOptions<T>): Result<T>;
2118
-
2119
- /**
2120
- * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
2121
- * Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a
2122
- * concatenated list of all error messages.
2123
- * @param initializers - An object with the shape of the target but with initializer functions for
2124
- * each property.
2125
- * @param order - Optional order in which keys should be written.
2126
- * @public
2127
- * {@label WITH_ORDER}
2128
- * @deprecated Pass {@link PopulateObjectOptions} instead.
2129
- */
2130
- export declare function populateObject<T>(initializers: FieldInitializers<T>, order: (keyof T)[]): Result<T>;
2131
-
2132
- /**
2133
- * Options for the {@link (populateObject:1)} function.
2134
- * @public
2135
- */
2136
- export declare interface PopulateObjectOptions<T> {
2137
- /**
2138
- * If present, specifies the order in which property values should
2139
- * be evaluated. Any keys not listed are evaluated after all listed
2140
- * keys in indeterminate order. If 'order' is not present, keys
2141
- * are evaluated in indeterminate order.
2142
- */
2143
- order?: (keyof T)[];
2144
- /**
2145
- * Specify handling of `undefined` values. By default, successful
2146
- * `undefined` results are written to the result object. If this value
2147
- * is `true` then `undefined` results are suppressed for all properties.
2148
- * If this value is an array of property keys then `undefined` results
2149
- * are suppressed for those properties only.
2150
- */
2151
- suppressUndefined?: boolean | (keyof T)[];
2152
- }
2153
-
2154
- /**
2155
- * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied
2156
- * event details as appropriate.
2157
- * @param result - The {@link Result} to be propagated.
2158
- * @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.
2159
- * @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`
2160
- * is omitted or `undefined`, then `detail` will be applied to {@link Success} results.
2161
- * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error
2162
- * message from the original `result` but with the specified detail added.
2163
- * @public
2164
- */
2165
- export declare function propagateWithDetail<T, TD>(result: Result<T>, detail: TD, successDetail?: TD): DetailedResult<T, TD>;
2166
-
2167
- /**
2168
- * Simple implementation of a possibly open-ended range of some comparable
2169
- * type `<T>` with test and formatting.
2170
- * @public
2171
- */
2172
- declare class RangeOf<T> implements RangeOfProperties<T> {
2173
- /**
2174
- * Minimum extent of the range.
2175
- */
2176
- readonly min?: T;
2177
- /**
2178
- * Maximum extent of the range.
2179
- */
2180
- readonly max?: T;
2181
- /**
2182
- * Creates a new {@link Experimental.RangeOf | RangeOf<T>}.
2183
- * @param min - Optional minimum extent of the range.
2184
- * @param max - Optional maximum extent of the range.
2185
- */
2186
- constructor(min?: T, max?: T);
2187
- /**
2188
- * Static constructor for a {@link Experimental.RangeOf | RangeOf<T>}.
2189
- * @param init - {@link Experimental.RangeOfProperties | Range initializer}.
2190
- * @returns A new {@link Experimental.RangeOf | RangeOf<T>}.
2191
- */
2192
- static createRange<T>(init?: RangeOfProperties<T>): Result<RangeOf<T>>;
2193
- /**
2194
- * Gets a formatted description of a {@link Experimental.RangeOfProperties | RangeOfProperties<T>} given an
2195
- * optional set of formats and 'empty' value to use.
2196
- * @param range - The {@link Experimental.RangeOfProperties | RangeOfProperties<T>} to be formatted.
2197
- * @param formats - Optional {@link Experimental.RangeOfFormats | formats} to use. Default is
2198
- * {@link Experimental.DEFAULT_RANGEOF_FORMATS | DEFAULT_RANGEOF_FORMATS}.
2199
- * @param emptyValue - Value which represents unbounded minimum or maximum for this range. Default is `undefined`.
2200
- * @returns A string representation of the range.
2201
- */
2202
- static propertiesToString<T>(range: RangeOfProperties<T>, formats?: RangeOfFormats, emptyValue?: T): string | undefined;
2203
- /**
2204
- * Default comparison uses javascript built-in comparison.
2205
- * @param t1 - First value to be compared.
2206
- * @param t2 - Second value to be compared.
2207
- * @returns `'less'` if `t1` is less than `t2`, `'greater'` if `t1` is larger
2208
- * and `'equal'` if `t1` and `t2` are equal.
2209
- * @internal
2210
- */
2211
- protected static _defaultCompare<T>(t1: T, t2: T): 'less' | 'equal' | 'greater';
2212
- /**
2213
- * Checks if a supplied value is within this range.
2214
- * @param t - The value to be tested.
2215
- * @returns `'included'` if `t` falls within the range, `'less'` if `t` falls
2216
- * below the minimum extent of the range and `'greater'` if `t` is above the
2217
- * maximum extent.
2218
- */
2219
- check(t: T): 'less' | 'included' | 'greater';
2220
- /**
2221
- * Determines if a supplied value is within this range.
2222
- * @param t - The value to be tested.
2223
- * @returns Returns `true` if `t` falls within the range, `false` otherwise.
2224
- */
2225
- includes(t: T): boolean;
2226
- /**
2227
- * Finds the transition value that would bring a supplied value `t` into
2228
- * range.
2229
- * @param t - The value to be tested.
2230
- * @returns The minimum extent of the range if `t` is below the range or
2231
- * the maximum extent of the range if `t` is above the range. Returns
2232
- * `undefined` if `t` already falls within the range.
2233
- */
2234
- findTransition(t: T): T | undefined;
2235
- /**
2236
- * Formats the minimum and maximum values of this range.
2237
- * @param format - A format function used to format the values.
2238
- * @returns A {@link Experimental.RangeOfProperties | RangeOfProperties<string>} containing the
2239
- * formatted representation of the {@link Experimental.RangeOf.min | minimum} and
2240
- * {@link Experimental.RangeOf.max | maximum}
2241
- * extent of the range, or `undefined` for an extent that is not present.
2242
- */
2243
- toFormattedProperties(format: (value: T) => string | undefined): RangeOfProperties<string>;
2244
- /**
2245
- * Formats this range using the supplied format function.
2246
- * @param format - Format function used to format minimum and maximum extent values.
2247
- * @param formats - The {@link Experimental.RangeOfFormats | format strings} used to format the range
2248
- * (default {@link Experimental.DEFAULT_RANGEOF_FORMATS}).
2249
- * @returns Returns a formatted representation of this range.
2250
- */
2251
- format(format: (value: T) => string | undefined, formats?: RangeOfFormats): string | undefined;
2252
- /**
2253
- * Inner compare method can be overridden by a derived class.
2254
- * @param t1 - First value to compare.
2255
- * @param t2 - Second value to compare.
2256
- * @returns `'less'` if `t1` is less than `t2`, `'greater'` if `t1` is larger
2257
- * and `'equal'` if `t1` and `t2` are equal.
2258
- * @internal
2259
- */
2260
- protected _compare(t1: T, t2: T): 'less' | 'equal' | 'greater';
2261
- }
2262
-
2263
- /**
2264
- * A helper wrapper to construct a {@link Converter} which converts to {@link Experimental.RangeOf | RangeOf<T>}
2265
- * where `<T>` is some comparable type.
2266
- * @param converter - {@link Converter} used to convert `min` and `max` extent of the range.
2267
- * @public
2268
- */
2269
- declare function rangeOf<T, TC = unknown>(converter: Converter<T, TC>): Converter<RangeOf<T>, TC>;
2270
-
2271
- /**
2272
- * Format strings (in mustache format) to
2273
- * use for both open-ended and complete
2274
- * {@link Experimental.RangeOf | RangeOf<T>}.
2275
- * @public
2276
- */
2277
- declare interface RangeOfFormats {
2278
- minOnly: string;
2279
- maxOnly: string;
2280
- minMax: string;
2281
- }
2282
-
2283
- /**
2284
- * Represents a generic range of some comparable type `<T>`.
2285
- * @public
2286
- */
2287
- declare interface RangeOfProperties<T> {
2288
- readonly min?: T;
2289
- readonly max?: T;
2290
- }
2291
-
2292
- /**
2293
- * A helper wrapper to construct a {@link Converter} which converts to an arbitrary strongly-typed
2294
- * range of some comparable type.
2295
- * @param converter - {@link Converter} used to convert `min` and `max` extent of the range.
2296
- * @param constructor - Static constructor to instantiate the object.
2297
- * @public
2298
- */
2299
- declare function rangeTypeOf<T, RT extends RangeOf<T>, TC = unknown>(converter: Converter<T, TC>, constructor: (init: RangeOfProperties<T>) => Result<RT>): Converter<RT, TC>;
2300
-
2301
- /**
2302
- * Reads a CSV file from a supplied path.
2303
- * @param srcPath - Source path from which the file is read.
2304
- * @param options - optional parameters to control the processing
2305
- * @returns The contents of the file.
2306
- * @beta
2307
- */
2308
- declare function readCsvFileSync(srcPath: string, options?: CsvOptions): Result<unknown>;
2309
-
2310
- /**
2311
- * Reads a record-jar file from a supplied path.
2312
- * @param srcPath - Source path from which the file is read.
2313
- * @param options - Optional parser configuration
2314
- * @returns The contents of the file as an array of `Record<string, string>`
2315
- * @see https://datatracker.ietf.org/doc/html/draft-phillips-record-jar-01
2316
- * @public
2317
- */
2318
- declare function readRecordJarFileSync(srcPath: string, options?: JarRecordParserOptions): Result<JarRecord[]>;
2319
-
2320
- declare namespace RecordJar {
2321
- export {
2322
- parseRecordJarLines,
2323
- readRecordJarFileSync,
2324
- JarRecord,
2325
- JarFieldPicker,
2326
- JarRecordParserOptions
2327
- }
2328
- }
2329
- export { RecordJar }
2005
+ /**
2006
+ * Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter} which converts an object
2007
+ * without changing shape, a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
2008
+ * {@link Converters.StrictObjectConverterOptions | StrictObjectConverterOptions<T>} to further refine
2009
+ * conversion behavior.
2010
+ *
2011
+ * @remarks
2012
+ * Fields that succeed but convert to undefined are omitted from the result object but do not
2013
+ * fail the conversion.
2014
+ *
2015
+ * The conversion fails if any unexpected fields are encountered.
2016
+ *
2017
+ * @param properties - An object containing defining the shape and converters to be applied.
2018
+ * @param optional - An array of `keyof T` containing keys to be considered optional.
2019
+ * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
2020
+ * {@label WITH_KEYS}
2021
+ * @deprecated Use {@link Converters.(strictObject:1) | Converters.strictObject(options)} instead.
2022
+ * @public
2023
+ */
2024
+ declare function strictObject<T>(properties: FieldConverters<T>, optional: (keyof T)[]): ObjectConverter<T>;
2330
2025
 
2331
- /**
2332
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
2333
- * using a supplied {@link Converter | Converter<T>} to produce a `Record<string, T>`.
2334
- * @remarks
2335
- * The resulting converter fails conversion if any element cannot be converted.
2336
- * @param converter - {@link Converter} used to convert each item in the source object.
2337
- * @returns A {@link Converter} which returns `Record<string, T>`.
2338
- * {@label WITH_DEFAULT}
2339
- * @public
2340
- */
2341
- declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>): Converter<Record<TK, T>, TC>;
2026
+ /**
2027
+ * Options for the {@link Converters.(strictObject:1)} helper function.
2028
+ * @public
2029
+ */
2030
+ declare type StrictObjectConverterOptions<T> = Omit<ObjectConverterOptions<T>, 'strict'>;
2342
2031
 
2343
- /**
2344
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
2345
- * using a supplied {@link Converter | Converter<T>} to produce a `Record<string, T>` and optionally
2346
- * specified handling of elements that cannot be converted.
2347
- * @remarks
2348
- * if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
2349
- * cannot be converted. If `onError` is `'ignore'`, failing elements are silently ignored.
2350
- * @param converter - {@link Converter} used to convert each item in the source object.
2351
- * @returns A {@link Converter} which returns `Record<string, T>`.
2352
- * {@label WITH_ON_ERROR}
2353
- * @public
2354
- */
2355
- declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, onError: 'fail' | 'ignore'): Converter<Record<TK, T>, TC>;
2032
+ /**
2033
+ * A converter to convert unknown to string. Values of type
2034
+ * string succeed. Anything else fails.
2035
+ * @public
2036
+ */
2037
+ declare const string: StringConverter;
2356
2038
 
2357
- /**
2358
- * A helper function to create a {@link Converter} which converts the `string`-keyed properties
2359
- * using a supplied {@link Converter | Converter<T>} to produce a `Record<TK, T>`.
2360
- * @remarks
2361
- * If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
2362
- * converter for keys and/or control the handling of elements that fail conversion.
2363
- * @param converter - {@link Converter} used to convert each item in the source object.
2364
- * @param options - Optional {@link Converters.KeyedConverterOptions | KeyedConverterOptions<TK, TC>} which
2365
- * supplies a key converter and/or error-handling options.
2366
- * @returns A {@link Converter} which returns `Record<TK, T>`.
2367
- * {@label WITH_OPTIONS}
2368
- * @public
2369
- */
2370
- declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC>, options: KeyedConverterOptions<TK, TC>): Converter<Record<TK, T>, TC>;
2039
+ /**
2040
+ * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
2041
+ * @public
2042
+ */
2043
+ declare const string_2: Validator<string>;
2371
2044
 
2372
- /**
2373
- * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.
2374
- * @param src - The `Record` to be converted.
2375
- * @param factory - The factory method used to convert elements.
2376
- * @returns {@link Success} with the resulting map on success, or {@link Failure} with a
2377
- * message if an error occurs.
2378
- * @public
2379
- */
2380
- export declare function recordToMap<TS, TD, TK extends string = string>(src: Record<TK, TS>, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD>>;
2045
+ /**
2046
+ * {@link Converter} to convert an `unknown` to an array of `string`.
2047
+ * @remarks
2048
+ * Returns {@link Success} with the the supplied value if it as an array
2049
+ * of strings, returns {@link Failure} with an error message otherwise.
2050
+ * @public
2051
+ */
2052
+ declare const stringArray: Converter<string[]>;
2381
2053
 
2054
+ /**
2055
+ * The {@link Conversion.StringConverter | StringConverter} class extends
2056
+ * {@link Conversion.BaseConverter | BaseConverter} to provide string-specific
2057
+ * helper methods.
2058
+ * @public
2059
+ */
2060
+ declare class StringConverter<T extends string = string, TC = unknown> extends BaseConverter<T, TC> {
2382
2061
  /**
2383
- * Represents the {@link IResult | result} of some operation or sequence of operations.
2384
- * @remarks
2385
- * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common
2386
- * contract {@link IResult}, enabling commingled discriminated usage.
2387
- * @public
2062
+ * Construct a new {@link Conversion.StringConverter | StringConverter}.
2063
+ * @param defaultContext - Optional context used by the conversion.
2064
+ * @param traits - Optional traits to be applied to the conversion.
2065
+ * @param converter - Optional conversion function to be used for the conversion.
2388
2066
  */
2389
- export declare type Result<T> = Success<T> | Failure<T>;
2390
-
2067
+ constructor(defaultContext?: TC, traits?: ConverterTraits, converter?: (from: unknown, self: Converter<T, TC>, context?: TC) => Result<T>);
2391
2068
  /**
2392
- * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.
2393
- * @beta
2069
+ * @internal
2394
2070
  */
2395
- export declare type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;
2396
-
2071
+ protected static _convert<T extends string>(from: unknown): Result<T>;
2397
2072
  /**
2398
- * Type inference to determine the result type of an {@link Result}.
2399
- * @beta
2073
+ * @internal
2400
2074
  */
2401
- export declare type ResultValueType<T> = T extends Result<infer TV> ? TV : never;
2402
-
2075
+ protected static _wrap<T extends string, TC>(wrapped: StringConverter<T, TC>, converter: (from: T) => Result<T>, traits?: ConverterTraits): StringConverter<T, TC>;
2403
2076
  /**
2404
- * Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter} which converts an object
2405
- * without changing shape, a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
2406
- * {@link Converters.StrictObjectConverterOptions | StrictObjectConverterOptions<T>} to further refine
2407
- * conversion behavior.
2408
- *
2409
- * @remarks
2410
- * Fields that succeed but convert to undefined are omitted from the result object but do not
2411
- * fail the conversion.
2412
- *
2413
- * The conversion fails if any unexpected fields are encountered.
2414
- *
2415
- * @param properties - An object containing defining the shape and converters to be applied.
2416
- * @param options - An optional @see StrictObjectConverterOptions<T> containing options for the object converter.
2417
- * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
2418
- * {@label WITH_OPTIONS}
2419
- * @public
2420
- */
2421
- declare function strictObject<T>(properties: FieldConverters<T>, options?: StrictObjectConverterOptions<T>): ObjectConverter<T>;
2077
+ * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
2078
+ * a supplied string.
2079
+ * @param match - The string to be matched
2080
+ * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.
2081
+ * @returns {@link Success} with a matching string or {@link Failure} with an informative
2082
+ * error if the string does not match.
2083
+ * {@label WITH_STRING}
2084
+ */
2085
+ matching(match: string, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
2086
+ /**
2087
+ * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
2088
+ * one of a supplied array of strings.
2089
+ * @param match - The array of allowed strings.
2090
+ * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.
2091
+ * @returns {@link Success} with a matching string or {@link Failure} with an informative
2092
+ * error if the string does not match.
2093
+ * {@label WITH_ARRAY}
2094
+ */
2095
+ matching(match: string[], options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
2096
+ /**
2097
+ * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
2098
+ * one of a supplied `Set` of strings.
2099
+ * @param match - The `Set` of allowed strings.
2100
+ * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.
2101
+ * @returns {@link Success} with a matching string or {@link Failure} with an informative
2102
+ * error if the string does not match.
2103
+ * {@label WITH_SET}
2104
+ */
2105
+ matching(match: Set<T>, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
2106
+ /**
2107
+ * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
2108
+ * a supplied regular expression.
2109
+ * @param match - The regular expression to be used as a constraint.
2110
+ * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion
2111
+ * @returns {@link Success} with a matching string or {@link Failure} with an informative
2112
+ * error if the string does not match.
2113
+ * {@label WITH_REGEXP}
2114
+ */
2115
+ matching(match: RegExp, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
2116
+ }
2422
2117
 
2423
- /**
2424
- * Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter} which converts an object
2425
- * without changing shape, a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
2426
- * {@link Converters.StrictObjectConverterOptions | StrictObjectConverterOptions<T>} to further refine
2427
- * conversion behavior.
2428
- *
2429
- * @remarks
2430
- * Fields that succeed but convert to undefined are omitted from the result object but do not
2431
- * fail the conversion.
2432
- *
2433
- * The conversion fails if any unexpected fields are encountered.
2434
- *
2435
- * @param properties - An object containing defining the shape and converters to be applied.
2436
- * @param optional - An array of `keyof T` containing keys to be considered optional.
2437
- * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
2438
- * {@label WITH_KEYS}
2439
- * @deprecated Use {@link Converters.(strictObject:1) | Converters.strictObject(options)} instead.
2440
- * @public
2441
- */
2442
- declare function strictObject<T>(properties: FieldConverters<T>, optional: (keyof T)[]): ObjectConverter<T>;
2118
+ /**
2119
+ * Options for {@link Conversion.StringConverter | StringConverter}
2120
+ * matching method
2121
+ * @public
2122
+ */
2123
+ declare interface StringMatchOptions {
2124
+ /**
2125
+ * An optional message to be displayed if a non-matching string
2126
+ * is encountered.
2127
+ */
2128
+ message?: string;
2129
+ }
2443
2130
 
2444
- /**
2445
- * Options for the {@link Converters.(strictObject:1)} helper function.
2446
- * @public
2447
- */
2448
- declare type StrictObjectConverterOptions<T> = Omit<ObjectConverterOptions<T>, 'strict'>;
2131
+ /**
2132
+ * An in-place {@link Validation.Validator | Validator} for `string` values.
2133
+ * @public
2134
+ */
2135
+ declare class StringValidator<T extends string = string, TC = unknown> extends GenericValidator<T, TC> {
2136
+ /**
2137
+ * Constructs a new {@link Validation.Classes.StringValidator | StringValidator}.
2138
+ * @param params - Optional {@link Validation.Classes.StringValidatorConstructorParams | init params}
2139
+ * for the new {@link Validation.Classes.StringValidator | StringValidator}.
2140
+ */
2141
+ constructor(params?: StringValidatorConstructorParams<T, TC>);
2142
+ /**
2143
+ * Static method which validates that a supplied `unknown` value is a `string`.
2144
+ * @param from - The `unknown` value to be tested.
2145
+ * @returns Returns `true` if `from` is a `string`, or {@link Failure} with an error
2146
+ * message if not.
2147
+ */
2148
+ static validateString<T extends string>(from: unknown): boolean | Failure<T>;
2149
+ }
2449
2150
 
2450
- /**
2451
- * A converter to convert unknown to string. Values of type
2452
- * string succeed. Anything else fails.
2453
- * @public
2454
- */
2455
- declare const string: StringConverter;
2151
+ /**
2152
+ * Parameters used to construct a {@link Validation.Classes.StringValidator | StringValidator}.
2153
+ * @public
2154
+ */
2155
+ declare type StringValidatorConstructorParams<T extends string = string, TC = unknown> = GenericValidatorConstructorParams<T, TC>;
2456
2156
 
2457
- /**
2458
- * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
2459
- * @public
2460
- */
2461
- declare const string_2: Validator<string>;
2157
+ /**
2158
+ * Returns {@link Success | Success<T>} with the supplied result value.
2159
+ * @param value - The successful result value to be returned
2160
+ * @public
2161
+ */
2162
+ export declare function succeed<T>(value: T): Success<T>;
2462
2163
 
2463
- /**
2464
- * {@link Converter} to convert an `unknown` to an array of `string`.
2465
- * @remarks
2466
- * Returns {@link Success} with the the supplied value if it as an array
2467
- * of strings, returns {@link Failure} with an error message otherwise.
2468
- * @public
2469
- */
2470
- declare const stringArray: Converter<string[]>;
2164
+ /**
2165
+ * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional
2166
+ * detail.
2167
+ * @param value - The value of type `<T>` to be returned.
2168
+ * @param detail - An optional detail of type `<TD>` to be returned.
2169
+ * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value
2170
+ * and detail, if supplied.
2171
+ * @public
2172
+ */
2173
+ export declare function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
2471
2174
 
2472
- /**
2473
- * The {@link Conversion.StringConverter | StringConverter} class extends
2474
- * {@link Conversion.BaseConverter | BaseConverter} to provide string-specific
2475
- * helper methods.
2476
- * @public
2477
- */
2478
- declare class StringConverter<T extends string = string, TC = unknown> extends BaseConverter<T, TC> {
2479
- /**
2480
- * Construct a new {@link Conversion.StringConverter | StringConverter}.
2481
- * @param defaultContext - Optional context used by the conversion.
2482
- * @param traits - Optional traits to be applied to the conversion.
2483
- * @param converter - Optional conversion function to be used for the conversion.
2484
- */
2485
- constructor(defaultContext?: TC, traits?: ConverterTraits, converter?: (from: unknown, self: Converter<T, TC>, context?: TC) => Result<T>);
2486
- /**
2487
- * @internal
2488
- */
2489
- protected static _convert<T extends string>(from: unknown): Result<T>;
2490
- /**
2491
- * @internal
2492
- */
2493
- protected static _wrap<T extends string, TC>(wrapped: StringConverter<T, TC>, converter: (from: T) => Result<T>, traits?: ConverterTraits): StringConverter<T, TC>;
2494
- /**
2495
- * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
2496
- * a supplied string.
2497
- * @param match - The string to be matched
2498
- * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.
2499
- * @returns {@link Success} with a matching string or {@link Failure} with an informative
2500
- * error if the string does not match.
2501
- * {@label WITH_STRING}
2502
- */
2503
- matching(match: string, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
2504
- /**
2505
- * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
2506
- * one of a supplied array of strings.
2507
- * @param match - The array of allowed strings.
2508
- * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.
2509
- * @returns {@link Success} with a matching string or {@link Failure} with an informative
2510
- * error if the string does not match.
2511
- * {@label WITH_ARRAY}
2512
- */
2513
- matching(match: string[], options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
2514
- /**
2515
- * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
2516
- * one of a supplied `Set` of strings.
2517
- * @param match - The `Set` of allowed strings.
2518
- * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.
2519
- * @returns {@link Success} with a matching string or {@link Failure} with an informative
2520
- * error if the string does not match.
2521
- * {@label WITH_SET}
2522
- */
2523
- matching(match: Set<T>, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
2175
+ /**
2176
+ * Reports a successful {@link IResult | result} from some operation and the
2177
+ * corresponding value.
2178
+ * @public
2179
+ */
2180
+ export declare class Success<T> implements IResult<T> {
2524
2181
  /**
2525
- * Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
2526
- * a supplied regular expression.
2527
- * @param match - The regular expression to be used as a constraint.
2528
- * @param options - Optional {@link Conversion.StringMatchOptions} for this conversion
2529
- * @returns {@link Success} with a matching string or {@link Failure} with an informative
2530
- * error if the string does not match.
2531
- * {@label WITH_REGEXP}
2532
- */
2533
- matching(match: RegExp, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
2534
- }
2535
-
2182
+ * {@inheritdoc IResult.success}
2183
+ */
2184
+ readonly success: true;
2536
2185
  /**
2537
- * Options for {@link Conversion.StringConverter | StringConverter}
2538
- * matching method
2539
- * @public
2186
+ * @internal
2540
2187
  */
2541
- declare interface StringMatchOptions {
2542
- /**
2543
- * An optional message to be displayed if a non-matching string
2544
- * is encountered.
2545
- */
2546
- message?: string;
2547
- }
2548
-
2188
+ private readonly _value;
2549
2189
  /**
2550
- * An in-place {@link Validation.Validator | Validator} for `string` values.
2551
- * @public
2190
+ * Constructs a {@link Success} with the supplied value.
2191
+ * @param value - The value to be returned.
2552
2192
  */
2553
- declare class StringValidator<T extends string = string, TC = unknown> extends GenericValidator<T, TC> {
2554
- /**
2555
- * Constructs a new {@link Validation.Classes.StringValidator | StringValidator}.
2556
- * @param params - Optional {@link Validation.Classes.StringValidatorConstructorParams | init params}
2557
- * for the new {@link Validation.Classes.StringValidator | StringValidator}.
2558
- */
2559
- constructor(params?: StringValidatorConstructorParams<T, TC>);
2560
- /**
2561
- * Static method which validates that a supplied `unknown` value is a `string`.
2562
- * @param from - The `unknown` value to be tested.
2563
- * @returns Returns `true` if `from` is a `string`, or {@link Failure} with an error
2564
- * message if not.
2565
- */
2566
- static validateString<T extends string>(from: unknown): boolean | Failure<T>;
2567
- }
2568
-
2193
+ constructor(value: T);
2569
2194
  /**
2570
- * Parameters used to construct a {@link Validation.Classes.StringValidator | StringValidator}.
2571
- * @public
2195
+ * The result value returned by the successful operation.
2572
2196
  */
2573
- declare type StringValidatorConstructorParams<T extends string = string, TC = unknown> = GenericValidatorConstructorParams<T, TC>;
2574
-
2197
+ get value(): T;
2575
2198
  /**
2576
- * Returns {@link Success | Success<T>} with the supplied result value.
2577
- * @param value - The successful result value to be returned
2578
- * @public
2199
+ * {@inheritdoc IResult.isSuccess}
2579
2200
  */
2580
- export declare function succeed<T>(value: T): Success<T>;
2581
-
2201
+ isSuccess(): this is Success<T>;
2582
2202
  /**
2583
- * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional
2584
- * detail.
2585
- * @param value - The value of type `<T>` to be returned.
2586
- * @param detail - An optional detail of type `<TD>` to be returned.
2587
- * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value
2588
- * and detail, if supplied.
2589
- * @public
2203
+ * {@inheritdoc IResult.isFailure}
2590
2204
  */
2591
- export declare function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
2592
-
2205
+ isFailure(): this is Failure<T>;
2593
2206
  /**
2594
- * Reports a successful {@link IResult | result} from some operation and the
2595
- * corresponding value.
2596
- * @public
2207
+ * {@inheritdoc IResult.orThrow}
2597
2208
  */
2598
- export declare class Success<T> implements IResult<T> {
2599
- /**
2600
- * {@inheritdoc IResult.success}
2601
- */
2602
- readonly success: true;
2603
- /**
2604
- * @internal
2605
- */
2606
- private readonly _value;
2607
- /**
2608
- * Constructs a {@link Success} with the supplied value.
2609
- * @param value - The value to be returned.
2610
- */
2611
- constructor(value: T);
2612
- /**
2613
- * The result value returned by the successful operation.
2614
- */
2615
- get value(): T;
2616
- /**
2617
- * {@inheritdoc IResult.isSuccess}
2618
- */
2619
- isSuccess(): this is Success<T>;
2620
- /**
2621
- * {@inheritdoc IResult.isFailure}
2622
- */
2623
- isFailure(): this is Failure<T>;
2624
- /**
2625
- * {@inheritdoc IResult.orThrow}
2626
- */
2627
- orThrow(__logger?: IResultLogger): T;
2628
- /**
2629
- * {@inheritdoc IResult.orDefault}
2630
- */
2631
- orDefault(dflt?: T): T | undefined;
2632
- /**
2633
- * {@inheritdoc IResult.getValueOrThrow}
2634
- */
2635
- getValueOrThrow(__logger?: IResultLogger): T;
2636
- /**
2637
- * {@inheritdoc IResult.getValueOrDefault}
2638
- */
2639
- getValueOrDefault(dflt?: T): T | undefined;
2640
- /**
2641
- * {@inheritdoc IResult.onSuccess}
2642
- */
2643
- onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;
2644
- /**
2645
- * {@inheritdoc IResult.onFailure}
2646
- */
2647
- onFailure(__: FailureContinuation<T>): Result<T>;
2648
- /**
2649
- * {@inheritdoc IResult.withFailureDetail}
2650
- */
2651
- withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD>;
2652
- /**
2653
- * {@inheritdoc IResult.withDetail}
2654
- */
2655
- withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;
2656
- }
2657
-
2209
+ orThrow(__logger?: IResultLogger): T;
2658
2210
  /**
2659
- * Continuation callback to be called in the event that an
2660
- * {@link Result} is successful.
2661
- * @public
2211
+ * {@inheritdoc IResult.orDefault}
2662
2212
  */
2663
- export declare type SuccessContinuation<T, TN> = (value: T) => Result<TN>;
2664
-
2213
+ orDefault(dflt: T): T;
2214
+ orDefault(): T | undefined;
2665
2215
  /**
2666
- * Helper function to create a {@link Conversion.StringConverter | StringConverter} which converts
2667
- * `unknown` to `string`, applying template conversions supplied at construction time or at
2668
- * runtime as context.
2669
- * @remarks
2670
- * Template conversions are applied using `mustache` syntax.
2671
- * @param defaultContext - Optional default context to use for template values.
2672
- * @returns A new {@link Converter} returning `string`.
2673
- * @public
2216
+ * {@inheritdoc IResult.getValueOrThrow}
2217
+ * @deprecated Use {@link Success.orThrow | orThrow} instead.
2674
2218
  */
2675
- declare function templateString(defaultContext?: unknown): StringConverter<string, unknown>;
2676
-
2219
+ getValueOrThrow(__logger?: IResultLogger): T;
2677
2220
  /**
2678
- * Helper to create a {@link Converter} which converts a source object to a new object with a
2679
- * different shape.
2680
- *
2681
- * @remarks
2682
- * On successful conversion, the resulting {@link Converter} returns {@link Success} with a new
2683
- * object, which contains the converted values under the key names specified at initialization time.
2684
- * It returns {@link Failure} with an error message if any fields to be extracted do not exist
2685
- * or cannot be converted.
2686
- *
2687
- * Fields that succeed but convert to undefined are omitted from the result object but do not
2688
- * fail the conversion.
2689
- *
2690
- * @param properties - An object with key names that correspond to the target object and an
2691
- * appropriate {@link Conversion.FieldConverters | FieldConverter} which extracts and converts
2692
- * a single filed from the source object.
2693
- * @returns A {@link Converter} with the specified conversion behavior.
2694
- * @public
2221
+ * {@inheritdoc IResult.getValueOrDefault}
2222
+ * @deprecated Use {@link Success.orDefault | orDefault} instead.
2695
2223
  */
2696
- declare function transform<T, TC = unknown>(properties: FieldConverters<T, TC>): Converter<T, TC>;
2697
-
2224
+ getValueOrDefault(dflt?: T): T | undefined;
2698
2225
  /**
2699
- * Helper to create a strongly-typed {@link Converter} which converts a source object to a
2700
- * new object with a different shape.
2701
- *
2702
- * @remarks
2703
- * On successful conversion, the resulting {@link Converter} returns {@link Success} with a new
2704
- * object, which contains the converted values under the key names specified at initialization time.
2705
- *
2706
- * It returns {@link Failure} with an error message if any fields to be extracted do not exist
2707
- * or cannot be converted.
2708
- *
2709
- * @param destinationFields - An object with key names that correspond to the target object and an
2710
- * appropriate {@link Converters.FieldTransformers | FieldTransformers} which specifies the name
2711
- * of the corresponding property in the source object, the converter used to convert the source
2712
- * property and any configuration to guide the conversion.
2713
- * @param options - Options which affect the transformation.
2714
- *
2715
- * @returns A {@link Converter} with the specified conversion behavior.
2716
- * @public
2226
+ * {@inheritdoc IResult.onSuccess}
2717
2227
  */
2718
- declare function transformObject<TSRC, TDEST, TC = unknown>(destinationFields: FieldTransformers<TSRC, TDEST, TC>, options?: TransformObjectOptions<TSRC>): Converter<TDEST, TC>;
2719
-
2228
+ onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;
2720
2229
  /**
2721
- * Options for a {@link Converters.transformObject} call.
2722
- * @public
2230
+ * {@inheritdoc IResult.onFailure}
2723
2231
  */
2724
- declare interface TransformObjectOptions<TSRC> {
2725
- /**
2726
- * If `strict` is `true` then unused properties in the source object cause
2727
- * an error, otherwise they are ignored.
2728
- */
2729
- strict: true;
2730
- /**
2731
- * An optional list of source properties to be ignored when strict mode
2732
- * is enabled.
2733
- */
2734
- ignore?: (keyof TSRC)[];
2735
- /**
2736
- * An optional description of this transform to be used for error messages.
2737
- */
2738
- description?: string;
2739
- }
2740
-
2232
+ onFailure(__: FailureContinuation<T>): Result<T>;
2741
2233
  /**
2742
- * An in-place {@link Validation.Validator | Validator} that can be instantiated using a type guard
2743
- * function.
2744
- * @public
2234
+ * {@inheritdoc IResult.withFailureDetail}
2745
2235
  */
2746
- declare class TypeGuardValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
2747
- /**
2748
- * {@link Validation.ValidatorOptions | Options} which apply to this
2749
- * validator.
2750
- */
2751
- readonly options: ValidatorOptions<TC>;
2752
- readonly description: string;
2753
- protected readonly _guard: TypeGuardWithContext<T, TC>;
2754
- /**
2755
- * Constructs a new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.
2756
- * @param params - Optional {@link Validation.Classes.TypeGuardValidatorConstructorParams | init params} for the
2757
- * new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.
2758
- */
2759
- constructor(params: TypeGuardValidatorConstructorParams<T, TC>);
2760
- /**
2761
- * Static method which validates that a supplied `unknown` value matches the supplied
2762
- * type guard, returning a `Failure<T>` containing more information about a failure.
2763
- * @param from - Value to be converted.
2764
- * @param context - Optional validation context.
2765
- * @returns `true` if `from` is valid, {@link Failure | Failure<T>}
2766
- * with an error message if `from` is invalid.
2767
- * @internal
2768
- */
2769
- protected _validate(from: unknown, context?: TC): boolean | Failure<T>;
2770
- }
2771
-
2236
+ withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD>;
2772
2237
  /**
2773
- * Parameters used to construct a {@link Validation.Classes.TypeGuardValidator}.
2774
- * @public
2238
+ * {@inheritdoc IResult.withDetail}
2775
2239
  */
2776
- declare interface TypeGuardValidatorConstructorParams<T, TC = unknown> extends ValidatorBaseConstructorParams<T, TC> {
2777
- guard: TypeGuardWithContext<T, TC>;
2778
- description: string;
2779
- }
2240
+ withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;
2241
+ }
2780
2242
 
2243
+ /**
2244
+ * Continuation callback to be called in the event that an
2245
+ * {@link Result} is successful.
2246
+ * @public
2247
+ */
2248
+ export declare type SuccessContinuation<T, TN> = (value: T) => Result<TN>;
2249
+
2250
+ /**
2251
+ * Helper function to create a {@link Conversion.StringConverter | StringConverter} which converts
2252
+ * `unknown` to `string`, applying template conversions supplied at construction time or at
2253
+ * runtime as context.
2254
+ * @remarks
2255
+ * Template conversions are applied using `mustache` syntax.
2256
+ * @param defaultContext - Optional default context to use for template values.
2257
+ * @returns A new {@link Converter} returning `string`.
2258
+ * @public
2259
+ */
2260
+ declare function templateString(defaultContext?: unknown): StringConverter<string, unknown>;
2261
+
2262
+ /**
2263
+ * Helper to create a {@link Converter} which converts a source object to a new object with a
2264
+ * different shape.
2265
+ *
2266
+ * @remarks
2267
+ * On successful conversion, the resulting {@link Converter} returns {@link Success} with a new
2268
+ * object, which contains the converted values under the key names specified at initialization time.
2269
+ * It returns {@link Failure} with an error message if any fields to be extracted do not exist
2270
+ * or cannot be converted.
2271
+ *
2272
+ * Fields that succeed but convert to undefined are omitted from the result object but do not
2273
+ * fail the conversion.
2274
+ *
2275
+ * @param properties - An object with key names that correspond to the target object and an
2276
+ * appropriate {@link Conversion.FieldConverters | FieldConverter} which extracts and converts
2277
+ * a single filed from the source object.
2278
+ * @returns A {@link Converter} with the specified conversion behavior.
2279
+ * @public
2280
+ */
2281
+ declare function transform<T, TC = unknown>(properties: FieldConverters<T, TC>): Converter<T, TC>;
2282
+
2283
+ /**
2284
+ * Helper to create a strongly-typed {@link Converter} which converts a source object to a
2285
+ * new object with a different shape.
2286
+ *
2287
+ * @remarks
2288
+ * On successful conversion, the resulting {@link Converter} returns {@link Success} with a new
2289
+ * object, which contains the converted values under the key names specified at initialization time.
2290
+ *
2291
+ * It returns {@link Failure} with an error message if any fields to be extracted do not exist
2292
+ * or cannot be converted.
2293
+ *
2294
+ * @param destinationFields - An object with key names that correspond to the target object and an
2295
+ * appropriate {@link Converters.FieldTransformers | FieldTransformers} which specifies the name
2296
+ * of the corresponding property in the source object, the converter used to convert the source
2297
+ * property and any configuration to guide the conversion.
2298
+ * @param options - Options which affect the transformation.
2299
+ *
2300
+ * @returns A {@link Converter} with the specified conversion behavior.
2301
+ * @public
2302
+ */
2303
+ declare function transformObject<TSRC, TDEST, TC = unknown>(destinationFields: FieldTransformers<TSRC, TDEST, TC>, options?: TransformObjectOptions<TSRC>): Converter<TDEST, TC>;
2304
+
2305
+ /**
2306
+ * Options for a {@link Converters.transformObject} call.
2307
+ * @public
2308
+ */
2309
+ declare interface TransformObjectOptions<TSRC> {
2781
2310
  /**
2782
- * A type guard function which validates a specific type, with an optional context
2783
- * that can be used to shape the validation.
2784
- * @public
2311
+ * If `strict` is `true` then unused properties in the source object cause
2312
+ * an error, otherwise they are ignored.
2785
2313
  */
2786
- declare type TypeGuardWithContext<T, TC = unknown> = (from: unknown, context?: TC) => from is T;
2787
-
2314
+ strict: true;
2788
2315
  /**
2789
- * Helper function to create a {@link Converter} from any {@link Validation.Validator}
2790
- * @param validator - the validator to be wrapped
2791
- * @returns A {@link Converter} which uses the supplied validator.
2792
- * @public
2316
+ * An optional list of source properties to be ignored when strict mode
2317
+ * is enabled.
2793
2318
  */
2794
- declare function validated<T, TC = unknown>(validator: Validator<T, TC>): Converter<T, TC>;
2319
+ ignore?: (keyof TSRC)[];
2320
+ /**
2321
+ * An optional description of this transform to be used for error messages.
2322
+ */
2323
+ description?: string;
2324
+ }
2795
2325
 
2326
+ /**
2327
+ * An in-place {@link Validation.Validator | Validator} that can be instantiated using a type guard
2328
+ * function.
2329
+ * @public
2330
+ */
2331
+ declare class TypeGuardValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
2796
2332
  /**
2797
- * Helper function to create a {@link Converter} which validates that a supplied value is
2798
- * of a type validated by a supplied validator function and returns it.
2799
- * @remarks
2800
- * If `validator` succeeds, this {@link Converter} returns {@link Success} with the supplied
2801
- * value of `from` coerced to type `<T>`. Returns a {@link Failure} with additional
2802
- * information otherwise.
2803
- * @param validator - A validator function to determine if the converted value is valid.
2804
- * @param description - A description of the validated type for use in error messages.
2805
- * @returns A new {@link Converter | Converter<T>} which applies the supplied validation.
2806
- * @public
2333
+ * {@link Validation.ValidatorOptions | Options} which apply to this
2334
+ * validator.
2807
2335
  */
2808
- declare function validateWith<T, TC = undefined>(validator: (from: unknown) => from is T, description?: string): Converter<T, TC>;
2809
-
2810
- declare namespace Validation {
2811
- export {
2812
- Base,
2813
- Classes,
2814
- Validators,
2815
- TypeGuardWithContext,
2816
- FunctionConstraintTrait,
2817
- ConstraintTrait,
2818
- ValidatorTraitValues,
2819
- defaultValidatorTraits,
2820
- ValidatorTraits,
2821
- ValidatorOptions,
2822
- Constraint,
2823
- Validator
2824
- }
2336
+ readonly options: ValidatorOptions<TC>;
2337
+ readonly description: string;
2338
+ protected readonly _guard: TypeGuardWithContext<T, TC>;
2339
+ /**
2340
+ * Constructs a new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.
2341
+ * @param params - Optional {@link Validation.Classes.TypeGuardValidatorConstructorParams | init params} for the
2342
+ * new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.
2343
+ */
2344
+ constructor(params: TypeGuardValidatorConstructorParams<T, TC>);
2345
+ /**
2346
+ * Static method which validates that a supplied `unknown` value matches the supplied
2347
+ * type guard, returning a `Failure<T>` containing more information about a failure.
2348
+ * @param from - Value to be converted.
2349
+ * @param context - Optional validation context.
2350
+ * @returns `true` if `from` is valid, {@link Failure | Failure<T>}
2351
+ * with an error message if `from` is invalid.
2352
+ * @internal
2353
+ */
2354
+ protected _validate(from: unknown, context?: TC): boolean | Failure<T>;
2355
+ }
2356
+
2357
+ /**
2358
+ * Parameters used to construct a {@link Validation.Classes.TypeGuardValidator}.
2359
+ * @public
2360
+ */
2361
+ declare interface TypeGuardValidatorConstructorParams<T, TC = unknown> extends ValidatorBaseConstructorParams<T, TC> {
2362
+ guard: TypeGuardWithContext<T, TC>;
2363
+ description: string;
2364
+ }
2365
+
2366
+ /**
2367
+ * A type guard function which validates a specific type, with an optional context
2368
+ * that can be used to shape the validation.
2369
+ * @public
2370
+ */
2371
+ declare type TypeGuardWithContext<T, TC = unknown> = (from: unknown, context?: TC) => from is T;
2372
+
2373
+ /**
2374
+ * Helper function to create a {@link Converter} from any {@link Validation.Validator}
2375
+ * @param validator - the validator to be wrapped
2376
+ * @returns A {@link Converter} which uses the supplied validator.
2377
+ * @public
2378
+ */
2379
+ declare function validated<T, TC = unknown>(validator: Validator<T, TC>): Converter<T, TC>;
2380
+
2381
+ /**
2382
+ * Helper function to create a {@link Converter} which validates that a supplied value is
2383
+ * of a type validated by a supplied validator function and returns it.
2384
+ * @remarks
2385
+ * If `validator` succeeds, this {@link Converter} returns {@link Success} with the supplied
2386
+ * value of `from` coerced to type `<T>`. Returns a {@link Failure} with additional
2387
+ * information otherwise.
2388
+ * @param validator - A validator function to determine if the converted value is valid.
2389
+ * @param description - A description of the validated type for use in error messages.
2390
+ * @returns A new {@link Converter | Converter<T>} which applies the supplied validation.
2391
+ * @public
2392
+ */
2393
+ declare function validateWith<T, TC = undefined>(validator: (from: unknown) => from is T, description?: string): Converter<T, TC>;
2394
+
2395
+ declare namespace Validation {
2396
+ export {
2397
+ Base,
2398
+ Classes,
2399
+ Validators,
2400
+ TypeGuardWithContext,
2401
+ FunctionConstraintTrait,
2402
+ ConstraintTrait,
2403
+ ValidatorTraitValues,
2404
+ defaultValidatorTraits,
2405
+ ValidatorTraits,
2406
+ ValidatorOptions,
2407
+ Constraint,
2408
+ Validator
2825
2409
  }
2826
- export { Validation }
2410
+ }
2411
+ export { Validation }
2827
2412
 
2413
+ /**
2414
+ * In-place validation that a supplied unknown matches some
2415
+ * required characteristics (type, values, etc).
2416
+ * @public
2417
+ */
2418
+ export declare interface Validator<T, TC = undefined> {
2828
2419
  /**
2829
- * In-place validation that a supplied unknown matches some
2830
- * required characteristics (type, values, etc).
2831
- * @public
2420
+ * {@link Validation.ValidatorTraits | Traits} describing this validation.
2832
2421
  */
2833
- export declare interface Validator<T, TC = undefined> {
2834
- /**
2835
- * {@link Validation.ValidatorTraits | Traits} describing this validation.
2836
- */
2837
- readonly traits: ValidatorTraits;
2838
- /**
2839
- * Indicates whether this element is explicitly optional.
2840
- */
2841
- readonly isOptional: boolean;
2842
- /**
2843
- * The brand for a branded type.
2422
+ readonly traits: ValidatorTraits;
2423
+ /**
2424
+ * Indicates whether this element is explicitly optional.
2425
+ */
2426
+ readonly isOptional: boolean;
2427
+ /**
2428
+ * The brand for a branded type.
2429
+ */
2430
+ readonly brand: string | undefined;
2431
+ /**
2432
+ * Tests to see if a supplied `unknown` value matches this
2433
+ * validation.
2434
+ * @param from - The `unknown` value to be tested.
2435
+ * @param context - Optional validation context.
2436
+ * @returns {@link Success} with the typed, validated value,
2437
+ * or {@link Failure} with an error message if validation fails.
2844
2438
  */
2845
- readonly brand: string | undefined;
2846
- /**
2847
- * Tests to see if a supplied `unknown` value matches this
2848
- * validation.
2849
- * @param from - The `unknown` value to be tested.
2850
- * @param context - Optional validation context.
2851
- * @returns {@link Success} with the typed, validated value,
2852
- * or {@link Failure} with an error message if validation fails.
2853
- */
2854
- validate(from: unknown, context?: TC): Result<T>;
2855
- /**
2856
- * Tests to see if a supplied `unknown` value matches this
2857
- * validation. Accepts `undefined`.
2858
- * @param from - The `unknown` value to be tested.
2859
- * @param context - Optional validation context.
2860
- * @returns {@link Success} with the typed, validated value,
2861
- * or {@link Failure} with an error message if validation fails.
2862
- */
2863
- validateOptional(from: unknown, context?: TC): Result<T | undefined>;
2864
- /**
2865
- * Non-throwing type guard
2866
- * @param from - The value to be tested.
2867
- * @param context - Optional validation context.
2868
- */
2869
- guard(from: unknown, context?: TC): from is T;
2870
- /**
2871
- * Creates an {@link Validation.Validator | in-place validator}
2872
- * which is derived from this one but which also matches `undefined`.
2873
- */
2874
- optional(): Validator<T | undefined, TC>;
2875
- /**
2876
- * Creates an {@link Validation.Validator | in-place validator}
2877
- * which is derived from this one but which applies additional constraints.
2878
- * @param constraint - the constraint to be applied
2879
- * @param trait - As optional {@link Validation.ConstraintTrait | ConstraintTrait}
2880
- * to be applied to the resulting {@link Validation.Validator | Validator}.
2881
- * @returns A new {@link Validation.Validator | Validator}.
2882
- */
2883
- withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;
2884
- /**
2885
- * Creates a new {@link Validation.Validator | in-place validator} which
2886
- * is derived from this one but which matches a branded result.
2887
- * @param brand - The brand to be applied.
2888
- */
2889
- withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;
2890
- }
2439
+ validate(from: unknown, context?: TC): Result<T>;
2440
+ /**
2441
+ * Tests to see if a supplied `unknown` value matches this
2442
+ * validation. Accepts `undefined`.
2443
+ * @param from - The `unknown` value to be tested.
2444
+ * @param context - Optional validation context.
2445
+ * @returns {@link Success} with the typed, validated value,
2446
+ * or {@link Failure} with an error message if validation fails.
2447
+ */
2448
+ validateOptional(from: unknown, context?: TC): Result<T | undefined>;
2449
+ /**
2450
+ * Non-throwing type guard
2451
+ * @param from - The value to be tested.
2452
+ * @param context - Optional validation context.
2453
+ */
2454
+ guard(from: unknown, context?: TC): from is T;
2455
+ /**
2456
+ * Creates an {@link Validation.Validator | in-place validator}
2457
+ * which is derived from this one but which also matches `undefined`.
2458
+ */
2459
+ optional(): Validator<T | undefined, TC>;
2460
+ /**
2461
+ * Creates an {@link Validation.Validator | in-place validator}
2462
+ * which is derived from this one but which applies additional constraints.
2463
+ * @param constraint - the constraint to be applied
2464
+ * @param trait - As optional {@link Validation.ConstraintTrait | ConstraintTrait}
2465
+ * to be applied to the resulting {@link Validation.Validator | Validator}.
2466
+ * @returns A new {@link Validation.Validator | Validator}.
2467
+ */
2468
+ withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;
2469
+ /**
2470
+ * Creates a new {@link Validation.Validator | in-place validator} which
2471
+ * is derived from this one but which matches a branded result.
2472
+ * @param brand - The brand to be applied.
2473
+ */
2474
+ withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;
2475
+ }
2891
2476
 
2477
+ /**
2478
+ * Abstract base helper class for specific validator implementations
2479
+ * @internal
2480
+ */
2481
+ declare abstract class ValidatorBase<T, TC = undefined> extends GenericValidator<T, TC> {
2892
2482
  /**
2893
- * Abstract base helper class for specific validator implementations
2483
+ * Inner constructor
2484
+ * @param params - Initialization params.
2894
2485
  * @internal
2895
2486
  */
2896
- declare abstract class ValidatorBase<T, TC = undefined> extends GenericValidator<T, TC> {
2897
- /**
2898
- * Inner constructor
2899
- * @param params - Initialization params.
2900
- * @internal
2901
- */
2902
- protected constructor(params: Partial<ValidatorBaseConstructorParams<T, TC>>);
2903
- /**
2904
- * Abstract validation method to me implemented by derived classes.
2905
- * @param from - Value to be converted.
2906
- * @param context - Optional validation context.
2907
- * @returns `true` if `from` is valid, {@link Failure | Failure<T>}
2908
- * with an error message if `from` is invalid.
2909
- * @internal
2910
- */
2911
- protected abstract _validate(from: unknown, context?: TC): boolean | Failure<T>;
2912
- }
2913
-
2487
+ protected constructor(params: Partial<ValidatorBaseConstructorParams<T, TC>>);
2914
2488
  /**
2489
+ * Abstract validation method to me implemented by derived classes.
2490
+ * @param from - Value to be converted.
2491
+ * @param context - Optional validation context.
2492
+ * @returns `true` if `from` is valid, {@link Failure | Failure<T>}
2493
+ * with an error message if `from` is invalid.
2915
2494
  * @internal
2916
2495
  */
2917
- declare type ValidatorBaseConstructorParams<T, TC> = Omit<GenericValidatorConstructorParams<T, TC>, 'validator'>;
2496
+ protected abstract _validate(from: unknown, context?: TC): boolean | Failure<T>;
2497
+ }
2918
2498
 
2919
- /**
2920
- * Type for a validation function, which validates that a supplied `unknown`
2921
- * value is a valid value of type `<T>`, possibly as influenced by
2922
- * an optionally-supplied validation context of type `<TC>`.
2923
- * @public
2924
- */
2925
- declare type ValidatorFunc<T, TC> = (from: unknown, context?: TC) => boolean | Failure<T>;
2499
+ /**
2500
+ * @internal
2501
+ */
2502
+ declare type ValidatorBaseConstructorParams<T, TC> = Omit<GenericValidatorConstructorParams<T, TC>, 'validator'>;
2926
2503
 
2927
- /**
2928
- * Options that apply to any {@link Validation.Validator | Validator}.
2929
- * @public
2930
- */
2931
- declare interface ValidatorOptions<TC> {
2932
- defaultContext?: TC;
2933
- }
2504
+ /**
2505
+ * Type for a validation function, which validates that a supplied `unknown`
2506
+ * value is a valid value of type `<T>`, possibly as influenced by
2507
+ * an optionally-supplied validation context of type `<TC>`.
2508
+ * @public
2509
+ */
2510
+ declare type ValidatorFunc<T, TC> = (from: unknown, context?: TC) => boolean | Failure<T>;
2934
2511
 
2935
- declare namespace Validators {
2936
- export {
2937
- object_2 as object,
2938
- arrayOf_2 as arrayOf,
2939
- enumeratedValue_2 as enumeratedValue,
2940
- literal_2 as literal,
2941
- isA_2 as isA,
2942
- string_2 as string,
2943
- number_2 as number,
2944
- boolean_2 as boolean
2945
- }
2512
+ /**
2513
+ * Options that apply to any {@link Validation.Validator | Validator}.
2514
+ * @public
2515
+ */
2516
+ declare interface ValidatorOptions<TC> {
2517
+ defaultContext?: TC;
2518
+ }
2519
+
2520
+ declare namespace Validators {
2521
+ export {
2522
+ object_2 as object,
2523
+ arrayOf_2 as arrayOf,
2524
+ enumeratedValue_2 as enumeratedValue,
2525
+ literal_2 as literal,
2526
+ isA_2 as isA,
2527
+ string_2 as string,
2528
+ number_2 as number,
2529
+ boolean_2 as boolean
2946
2530
  }
2947
- export { Validators }
2531
+ }
2532
+ export { Validators }
2948
2533
 
2534
+ /**
2535
+ * Generic implementation of {@link Validation.ValidatorTraitValues | ValidatorTraitValues}.
2536
+ * @public
2537
+ */
2538
+ declare class ValidatorTraits implements ValidatorTraitValues {
2949
2539
  /**
2950
- * Generic implementation of {@link Validation.ValidatorTraitValues | ValidatorTraitValues}.
2951
- * @public
2540
+ * {@inheritdoc Validation.ValidatorTraitValues.isOptional}
2952
2541
  */
2953
- declare class ValidatorTraits implements ValidatorTraitValues {
2954
- /**
2955
- * {@inheritdoc Validation.ValidatorTraitValues.isOptional}
2956
- */
2957
- readonly isOptional: boolean;
2958
- /**
2959
- * {@inheritdoc Validation.ValidatorTraitValues.brand}
2960
- */
2961
- readonly brand?: string;
2962
- /**
2963
- * {@inheritdoc Validation.ValidatorTraitValues.constraints}
2964
- */
2965
- readonly constraints: ConstraintTrait[];
2966
- /**
2967
- * Constructs a new {@link Validation.ValidatorTraits | ValidatorTraits} optionally
2968
- * initialized with the supplied base and initial values.
2969
- * @remarks
2970
- * Initial values take priority over base values, which fall back to the global default values.
2971
- * @param init - Partial initial values to be set in the resulting {@link Validation.Validator | Validator}.
2972
- * @param base - Base values to be used when no initial values are present.
2973
- */
2974
- constructor(init?: Partial<ValidatorTraitValues>, base?: ValidatorTraitValues);
2975
- }
2976
-
2542
+ readonly isOptional: boolean;
2977
2543
  /**
2978
- * Interface describing the supported validator traits.
2979
- * @public
2544
+ * {@inheritdoc Validation.ValidatorTraitValues.brand}
2980
2545
  */
2981
- declare interface ValidatorTraitValues {
2982
- /**
2983
- * Indicates whether the validator accepts `undefined` as
2984
- * a valid value.
2985
- */
2986
- readonly isOptional: boolean;
2987
- /**
2988
- * If present, indicates that the result will be branded
2989
- * with the corresponding brand.
2990
- */
2991
- readonly brand?: string;
2992
- /**
2993
- * Zero or more additional {@link Validation.ConstraintTrait | ConstraintTrait}s
2994
- * describing additional constraints applied by this {@link Validation.Validator | Validator}.
2995
- */
2996
- readonly constraints: ConstraintTrait[];
2997
- }
2546
+ readonly brand?: string;
2547
+ /**
2548
+ * {@inheritdoc Validation.ValidatorTraitValues.constraints}
2549
+ */
2550
+ readonly constraints: ConstraintTrait[];
2551
+ /**
2552
+ * Constructs a new {@link Validation.ValidatorTraits | ValidatorTraits} optionally
2553
+ * initialized with the supplied base and initial values.
2554
+ * @remarks
2555
+ * Initial values take priority over base values, which fall back to the global default values.
2556
+ * @param init - Partial initial values to be set in the resulting {@link Validation.Validator | Validator}.
2557
+ * @param base - Base values to be used when no initial values are present.
2558
+ */
2559
+ constructor(init?: Partial<ValidatorTraitValues>, base?: ValidatorTraitValues);
2560
+ }
2998
2561
 
2562
+ /**
2563
+ * Interface describing the supported validator traits.
2564
+ * @public
2565
+ */
2566
+ declare interface ValidatorTraitValues {
2999
2567
  /**
3000
- * Deprecated alias for @see literal
3001
- * @param value - The value to be compared.
3002
- * @deprecated Use {@link Converters.literal} instead.
3003
- * @internal
2568
+ * Indicates whether the validator accepts `undefined` as
2569
+ * a valid value.
3004
2570
  */
3005
- declare const value: typeof literal;
2571
+ readonly isOptional: boolean;
2572
+ /**
2573
+ * If present, indicates that the result will be branded
2574
+ * with the corresponding brand.
2575
+ */
2576
+ readonly brand?: string;
2577
+ /**
2578
+ * Zero or more additional {@link Validation.ConstraintTrait | ConstraintTrait}s
2579
+ * describing additional constraints applied by this {@link Validation.Validator | Validator}.
2580
+ */
2581
+ readonly constraints: ConstraintTrait[];
2582
+ }
2583
+
2584
+ /**
2585
+ * Deprecated alias for @see literal
2586
+ * @param value - The value to be compared.
2587
+ * @deprecated Use {@link Converters.literal} instead.
2588
+ * @internal
2589
+ */
2590
+ declare const value: typeof literal;
3006
2591
 
3007
- export { }
2592
+ export { }