@fgv/ts-utils 1.9.3 → 2.0.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 (211) hide show
  1. package/CHANGELOG.json +26 -0
  2. package/CHANGELOG.md +14 -0
  3. package/dist/ts-utils.d.ts +3007 -0
  4. package/dist/tsdoc-metadata.json +11 -0
  5. package/lib/index.d.ts +12 -0
  6. package/lib/index.d.ts.map +1 -0
  7. package/lib/index.js +68 -0
  8. package/lib/index.js.map +1 -0
  9. package/lib/packlets/base/brand.d.ts.map +1 -0
  10. package/lib/packlets/base/brand.js +24 -0
  11. package/lib/packlets/base/brand.js.map +1 -0
  12. package/lib/packlets/base/index.d.ts +7 -0
  13. package/lib/packlets/base/index.d.ts.map +1 -0
  14. package/lib/packlets/base/index.js +58 -0
  15. package/lib/packlets/base/index.js.map +1 -0
  16. package/{logger.d.ts → lib/packlets/base/logger.d.ts} +16 -1
  17. package/lib/packlets/base/logger.d.ts.map +1 -0
  18. package/lib/packlets/base/logger.js +128 -0
  19. package/lib/packlets/base/logger.js.map +1 -0
  20. package/{normalize.d.ts → lib/packlets/base/normalize.d.ts} +6 -0
  21. package/lib/packlets/base/normalize.d.ts.map +1 -0
  22. package/lib/packlets/base/normalize.js +139 -0
  23. package/lib/packlets/base/normalize.js.map +1 -0
  24. package/{result.d.ts → lib/packlets/base/result.d.ts} +16 -15
  25. package/lib/packlets/base/result.d.ts.map +1 -0
  26. package/lib/packlets/base/result.js +571 -0
  27. package/lib/packlets/base/result.js.map +1 -0
  28. package/lib/packlets/base/utils.d.ts.map +1 -0
  29. package/lib/packlets/base/utils.js +200 -0
  30. package/lib/packlets/base/utils.js.map +1 -0
  31. package/{converter.d.ts → lib/packlets/conversion/converter.d.ts} +11 -12
  32. package/lib/packlets/conversion/converter.d.ts.map +1 -0
  33. package/lib/packlets/conversion/converter.js +218 -0
  34. package/lib/packlets/conversion/converter.js.map +1 -0
  35. package/{converters.d.ts → lib/packlets/conversion/converters.d.ts} +52 -216
  36. package/lib/packlets/conversion/converters.d.ts.map +1 -0
  37. package/lib/packlets/conversion/converters.js +739 -0
  38. package/lib/packlets/conversion/converters.js.map +1 -0
  39. package/lib/packlets/conversion/index.d.ts +6 -0
  40. package/lib/packlets/conversion/index.d.ts.map +1 -0
  41. package/lib/packlets/conversion/index.js +56 -0
  42. package/lib/packlets/conversion/index.js.map +1 -0
  43. package/lib/packlets/conversion/objectConverter.d.ts +94 -0
  44. package/lib/packlets/conversion/objectConverter.d.ts.map +1 -0
  45. package/lib/packlets/conversion/objectConverter.js +110 -0
  46. package/lib/packlets/conversion/objectConverter.js.map +1 -0
  47. package/lib/packlets/conversion/stringConverter.d.ts +78 -0
  48. package/lib/packlets/conversion/stringConverter.d.ts.map +1 -0
  49. package/lib/packlets/conversion/stringConverter.js +97 -0
  50. package/lib/packlets/conversion/stringConverter.js.map +1 -0
  51. package/{csvHelpers.d.ts → lib/packlets/csv/csvHelpers.d.ts} +1 -1
  52. package/lib/packlets/csv/csvHelpers.d.ts.map +1 -0
  53. package/lib/packlets/csv/csvHelpers.js +69 -0
  54. package/lib/packlets/csv/csvHelpers.js.map +1 -0
  55. package/lib/packlets/csv/index.d.ts +2 -0
  56. package/lib/packlets/csv/index.d.ts.map +1 -0
  57. package/lib/packlets/csv/index.js +39 -0
  58. package/lib/packlets/csv/index.js.map +1 -0
  59. package/{extendedArray.d.ts → lib/packlets/experimental/extendedArray.d.ts} +7 -7
  60. package/lib/packlets/experimental/extendedArray.d.ts.map +1 -0
  61. package/lib/packlets/experimental/extendedArray.js +106 -0
  62. package/lib/packlets/experimental/extendedArray.js.map +1 -0
  63. package/{formatter.d.ts → lib/packlets/experimental/formatter.d.ts} +6 -6
  64. package/lib/packlets/experimental/formatter.d.ts.map +1 -0
  65. package/lib/packlets/experimental/formatter.js +75 -0
  66. package/lib/packlets/experimental/formatter.js.map +1 -0
  67. package/lib/packlets/experimental/index.d.ts +4 -0
  68. package/lib/packlets/experimental/index.d.ts.map +1 -0
  69. package/lib/packlets/experimental/index.js +41 -0
  70. package/lib/packlets/experimental/index.js.map +1 -0
  71. package/{rangeOf.d.ts → lib/packlets/experimental/rangeOf.d.ts} +21 -24
  72. package/lib/packlets/experimental/rangeOf.d.ts.map +1 -0
  73. package/lib/packlets/experimental/rangeOf.js +185 -0
  74. package/lib/packlets/experimental/rangeOf.js.map +1 -0
  75. package/{hash.d.ts → lib/packlets/hash/hash.d.ts} +1 -1
  76. package/lib/packlets/hash/hash.d.ts.map +1 -0
  77. package/lib/packlets/hash/hash.js +168 -0
  78. package/lib/packlets/hash/hash.js.map +1 -0
  79. package/lib/packlets/hash/index.d.ts +2 -0
  80. package/lib/packlets/hash/index.d.ts.map +1 -0
  81. package/lib/packlets/hash/index.js +39 -0
  82. package/lib/packlets/hash/index.js.map +1 -0
  83. package/lib/packlets/record-jar/index.d.ts +2 -0
  84. package/lib/packlets/record-jar/index.d.ts.map +1 -0
  85. package/lib/packlets/record-jar/index.js +39 -0
  86. package/lib/packlets/record-jar/index.js.map +1 -0
  87. package/{recordJarHelpers.d.ts → lib/packlets/record-jar/recordJarHelpers.d.ts} +1 -1
  88. package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +1 -0
  89. package/lib/packlets/record-jar/recordJarHelpers.js +263 -0
  90. package/lib/packlets/record-jar/recordJarHelpers.js.map +1 -0
  91. package/{validation → lib/packlets/validation}/array.d.ts +2 -2
  92. package/lib/packlets/validation/array.d.ts.map +1 -0
  93. package/lib/packlets/validation/array.js +67 -0
  94. package/lib/packlets/validation/array.js.map +1 -0
  95. package/{validation → lib/packlets/validation}/boolean.d.ts +1 -1
  96. package/lib/packlets/validation/boolean.d.ts.map +1 -0
  97. package/lib/packlets/validation/boolean.js +56 -0
  98. package/lib/packlets/validation/boolean.js.map +1 -0
  99. package/lib/packlets/validation/classes.d.ts.map +1 -0
  100. package/lib/packlets/validation/classes.js +38 -0
  101. package/lib/packlets/validation/classes.js.map +1 -0
  102. package/lib/packlets/validation/common.d.ts.map +1 -0
  103. package/lib/packlets/validation/common.js +24 -0
  104. package/lib/packlets/validation/common.js.map +1 -0
  105. package/{validation → lib/packlets/validation}/field.d.ts +1 -1
  106. package/lib/packlets/validation/field.d.ts.map +1 -0
  107. package/lib/packlets/validation/field.js +71 -0
  108. package/lib/packlets/validation/field.js.map +1 -0
  109. package/{validation → lib/packlets/validation}/genericValidator.d.ts +2 -3
  110. package/lib/packlets/validation/genericValidator.d.ts.map +1 -0
  111. package/lib/packlets/validation/genericValidator.js +137 -0
  112. package/lib/packlets/validation/genericValidator.js.map +1 -0
  113. package/lib/packlets/validation/index.d.ts.map +1 -0
  114. package/{validation → lib/packlets/validation}/index.js +1 -1
  115. package/lib/packlets/validation/index.js.map +1 -0
  116. package/{validation → lib/packlets/validation}/number.d.ts +1 -1
  117. package/lib/packlets/validation/number.d.ts.map +1 -0
  118. package/lib/packlets/validation/number.js +54 -0
  119. package/lib/packlets/validation/number.js.map +1 -0
  120. package/{validation → lib/packlets/validation}/object.d.ts +1 -1
  121. package/lib/packlets/validation/object.d.ts.map +1 -0
  122. package/lib/packlets/validation/object.js +139 -0
  123. package/lib/packlets/validation/object.js.map +1 -0
  124. package/{validation → lib/packlets/validation}/string.d.ts +1 -1
  125. package/lib/packlets/validation/string.d.ts.map +1 -0
  126. package/lib/packlets/validation/string.js +54 -0
  127. package/lib/packlets/validation/string.js.map +1 -0
  128. package/lib/packlets/validation/traits.d.ts.map +1 -0
  129. package/lib/packlets/validation/traits.js +58 -0
  130. package/lib/packlets/validation/traits.js.map +1 -0
  131. package/{validation → lib/packlets/validation}/typeGuard.d.ts +1 -1
  132. package/lib/packlets/validation/typeGuard.d.ts.map +1 -0
  133. package/lib/packlets/validation/typeGuard.js +62 -0
  134. package/lib/packlets/validation/typeGuard.js.map +1 -0
  135. package/{validation → lib/packlets/validation}/validator.d.ts +15 -16
  136. package/lib/packlets/validation/validator.d.ts.map +1 -0
  137. package/lib/packlets/validation/validator.js +24 -0
  138. package/lib/packlets/validation/validator.js.map +1 -0
  139. package/{validation → lib/packlets/validation}/validatorBase.d.ts +1 -1
  140. package/lib/packlets/validation/validatorBase.d.ts.map +1 -0
  141. package/lib/packlets/validation/validatorBase.js +41 -0
  142. package/lib/packlets/validation/validatorBase.js.map +1 -0
  143. package/{validation → lib/packlets/validation}/validators.d.ts +3 -6
  144. package/lib/packlets/validation/validators.d.ts.map +1 -0
  145. package/lib/packlets/validation/validators.js +121 -0
  146. package/lib/packlets/validation/validators.js.map +1 -0
  147. package/package.json +34 -33
  148. package/brand.d.ts.map +0 -1
  149. package/brand.js +0 -24
  150. package/converter.d.ts.map +0 -1
  151. package/converter.js +0 -222
  152. package/converters.d.ts.map +0 -1
  153. package/converters.js +0 -896
  154. package/csvHelpers.d.ts.map +0 -1
  155. package/csvHelpers.js +0 -69
  156. package/extendedArray.d.ts.map +0 -1
  157. package/extendedArray.js +0 -106
  158. package/formatter.d.ts.map +0 -1
  159. package/formatter.js +0 -75
  160. package/hash.d.ts.map +0 -1
  161. package/hash.js +0 -168
  162. package/index.d.ts +0 -15
  163. package/index.d.ts.map +0 -1
  164. package/index.js +0 -70
  165. package/logger.d.ts.map +0 -1
  166. package/logger.js +0 -115
  167. package/normalize.d.ts.map +0 -1
  168. package/normalize.js +0 -139
  169. package/rangeOf.d.ts.map +0 -1
  170. package/rangeOf.js +0 -185
  171. package/recordJarHelpers.d.ts.map +0 -1
  172. package/recordJarHelpers.js +0 -262
  173. package/result.d.ts.map +0 -1
  174. package/result.js +0 -569
  175. package/utils.d.ts.map +0 -1
  176. package/utils.js +0 -200
  177. package/validation/array.d.ts.map +0 -1
  178. package/validation/array.js +0 -67
  179. package/validation/boolean.d.ts.map +0 -1
  180. package/validation/boolean.js +0 -59
  181. package/validation/classes.d.ts.map +0 -1
  182. package/validation/classes.js +0 -38
  183. package/validation/common.d.ts.map +0 -1
  184. package/validation/common.js +0 -24
  185. package/validation/field.d.ts.map +0 -1
  186. package/validation/field.js +0 -72
  187. package/validation/genericValidator.d.ts.map +0 -1
  188. package/validation/genericValidator.js +0 -138
  189. package/validation/index.d.ts.map +0 -1
  190. package/validation/number.d.ts.map +0 -1
  191. package/validation/number.js +0 -57
  192. package/validation/object.d.ts.map +0 -1
  193. package/validation/object.js +0 -143
  194. package/validation/string.d.ts.map +0 -1
  195. package/validation/string.js +0 -57
  196. package/validation/traits.d.ts.map +0 -1
  197. package/validation/traits.js +0 -58
  198. package/validation/typeGuard.d.ts.map +0 -1
  199. package/validation/typeGuard.js +0 -62
  200. package/validation/validator.d.ts.map +0 -1
  201. package/validation/validator.js +0 -24
  202. package/validation/validatorBase.d.ts.map +0 -1
  203. package/validation/validatorBase.js +0 -44
  204. package/validation/validators.d.ts.map +0 -1
  205. package/validation/validators.js +0 -119
  206. /package/{brand.d.ts → lib/packlets/base/brand.d.ts} +0 -0
  207. /package/{utils.d.ts → lib/packlets/base/utils.d.ts} +0 -0
  208. /package/{validation → lib/packlets/validation}/classes.d.ts +0 -0
  209. /package/{validation → lib/packlets/validation}/common.d.ts +0 -0
  210. /package/{validation → lib/packlets/validation}/index.d.ts +0 -0
  211. /package/{validation → lib/packlets/validation}/traits.d.ts +0 -0
@@ -0,0 +1,3007 @@
1
+ /**
2
+ * Determines if an iterable collection of {@link Result | Result<T>} were all successful.
3
+ * @param results - The collection of {@link Result | Result<T>} to be tested.
4
+ * @returns Returns {@link Success} with `true` if all {@link Result | results} are successful.
5
+ * If any are unsuccessful, returns {@link Failure} with a concatenated summary the error
6
+ * messages from all failed elements.
7
+ * @public
8
+ */
9
+ export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T): Result<T>;
10
+
11
+ /**
12
+ * A helper function to create a {@link Converter} which converts `unknown` to an array of `<T>`.
13
+ * @remarks
14
+ * If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot
15
+ * be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
16
+ * @param converter - {@link Converter} used to convert each item in the array.
17
+ * @param ignoreErrors - Specifies treatment of unconvertible elements.
18
+ * @returns A {@link Converter} which returns an array of `<T>`.
19
+ * @public
20
+ */
21
+ declare function arrayOf<T, TC = undefined>(converter: Converter<T, TC>, onError?: OnError_2): Converter<T[], TC>;
22
+
23
+ /**
24
+ * Helper function to create a {@link Validation.Classes.ArrayValidator | ArrayValidator} which
25
+ * validates an array in place.
26
+ * @param validateElement - A {@link Validation.Validator | validator} which validates each element.
27
+ * @returns A new {@link Validation.Classes.ArrayValidator | ArrayValidator } which validates the desired
28
+ * array in place.
29
+ * @public
30
+ */
31
+ declare function arrayOf_2<T, TC>(validateElement: Validator<T, TC>, params?: Omit<ArrayValidatorConstructorParams<T, TC>, 'validateElement'>): ArrayValidator<T, TC>;
32
+
33
+ /**
34
+ * An in-place {@link Validator | Validator} for arrays of validated
35
+ * values or objects.
36
+ * @public
37
+ */
38
+ declare class ArrayValidator<T, TC = unknown> extends ValidatorBase<T[], TC> {
39
+ /**
40
+ * {@link Validation.ValidatorOptions | Options} which apply to this
41
+ * validator.
42
+ */
43
+ readonly options: ValidatorOptions<TC>;
44
+ protected readonly _validateElement: Validator<T, TC>;
45
+ /**
46
+ * Constructs a new {@link Validation.Classes.ArrayValidator | ArrayValidator}.
47
+ * @param params - Optional {@link Validation.Classes.ArrayValidatorConstructorParams | init params} for the
48
+ * new {@link Validation.Classes.ArrayValidator | ArrayValidator}.
49
+ */
50
+ constructor(params: ArrayValidatorConstructorParams<T, TC>);
51
+ /**
52
+ * Static method which validates that a supplied `unknown` value is a `array`
53
+ * and that every element of the array can be validated by the supplied array
54
+ * validator.
55
+ * @param from - The `unknown` value to be tested.
56
+ * @param context - Optional validation context will be propagated to element validator.
57
+ * @returns Returns `true` if `from` is an `array` of valid elements, or
58
+ * {@link Failure} with an error message if not.
59
+ */
60
+ protected _validate<T>(from: unknown, context?: TC): boolean | Failure<T>;
61
+ }
62
+
63
+ /**
64
+ * Parameters used to construct a {@link Validation.Classes.ArrayValidator | ArrayValidator}.
65
+ * @public
66
+ */
67
+ declare interface ArrayValidatorConstructorParams<T, TC = unknown> extends ValidatorBaseConstructorParams<T[], TC> {
68
+ validateElement: Validator<T, TC>;
69
+ }
70
+
71
+ declare namespace Base {
72
+ export {
73
+ ValidatorFunc,
74
+ GenericValidatorConstructorParams,
75
+ GenericValidator
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Base templated wrapper to simplify creation of new {@link Converter}s.
81
+ * @public
82
+ */
83
+ declare class BaseConverter<T, TC = undefined> implements Converter<T, TC> {
84
+ /**
85
+ * @internal
86
+ */
87
+ protected readonly _defaultContext?: TC;
88
+ /**
89
+ * @internal
90
+ */
91
+ protected _isOptional: boolean;
92
+ /**
93
+ * @internal
94
+ */
95
+ protected _brand?: string;
96
+ private readonly _converter;
97
+ /**
98
+ * Constructs a new {@link Converter} which uses the supplied function to perform the conversion.
99
+ * @param converter - The conversion function to be applied.
100
+ * @param defaultContext - Optional conversion context to be used by default.
101
+ * @param traits - Optional {@link Conversion.ConverterTraits | traits} to be assigned to the resulting
102
+ * converter.
103
+ */
104
+ constructor(converter: (from: unknown, self: Converter<T, TC>, context?: TC) => Result<T>, defaultContext?: TC, traits?: ConverterTraits);
105
+ /**
106
+ * {@inheritdoc Converter.isOptional}
107
+ */
108
+ get isOptional(): boolean;
109
+ /**
110
+ * {@inheritdoc Converter.brand}
111
+ */
112
+ get brand(): string | undefined;
113
+ /**
114
+ * {@inheritdoc Converter.convert}
115
+ */
116
+ convert(from: unknown, context?: TC): Result<T>;
117
+ /**
118
+ * {@inheritdoc Converter.convertOptional}
119
+ */
120
+ convertOptional(from: unknown, context?: TC, onError?: OnError): Result<T | undefined>;
121
+ /**
122
+ * {@inheritdoc Converter.optional}
123
+ */
124
+ optional(onError?: OnError): Converter<T | undefined, TC>;
125
+ /**
126
+ * {@inheritdoc Converter.map}
127
+ */
128
+ map<T2>(mapper: (from: T) => Result<T2>): Converter<T2, TC>;
129
+ /**
130
+ * {@inheritdoc Converter.mapConvert}
131
+ */
132
+ mapConvert<T2>(mapConverter: Converter<T2>): Converter<T2, TC>;
133
+ /**
134
+ * {@inheritdoc Converter.mapItems}
135
+ */
136
+ mapItems<TI>(mapper: (from: unknown) => Result<TI>): Converter<TI[], TC>;
137
+ /**
138
+ * {@inheritdoc Converter.mapConvertItems}
139
+ */
140
+ mapConvertItems<TI>(mapConverter: Converter<TI, unknown>): Converter<TI[], TC>;
141
+ /**
142
+ * {@inheritdoc Converter.withTypeGuard}
143
+ */
144
+ withTypeGuard<TI>(guard: (from: unknown) => from is TI, message?: string): Converter<TI, TC>;
145
+ /**
146
+ * {@inheritdoc Converter.withItemTypeGuard}
147
+ */
148
+ withItemTypeGuard<TI>(guard: (from: unknown) => from is TI, message?: string): Converter<TI[], TC>;
149
+ /**
150
+ * {@inheritdoc Converter.withConstraint}
151
+ */
152
+ withConstraint(constraint: (val: T) => boolean | Result<T>, options?: ConstraintOptions): Converter<T, TC>;
153
+ /**
154
+ * {@inheritdoc Converter.withBrand}
155
+ */
156
+ withBrand<B extends string>(brand: B): Converter<Brand<T, B>, TC>;
157
+ /**
158
+ * @internal
159
+ */
160
+ protected _context(supplied?: TC): TC | undefined;
161
+ /**
162
+ * @internal
163
+ */
164
+ protected _traits(traits?: Partial<ConverterTraits>): ConverterTraits;
165
+ /**
166
+ * @internal
167
+ */
168
+ protected _with(traits: Partial<ConverterTraits>): this;
169
+ }
170
+
171
+ /**
172
+ * A {@link Converter} which converts `unknown` to `boolean`.
173
+ * @remarks
174
+ * Boolean values or the case-insensitive strings `'true'` and `'false'` succeed.
175
+ * Anything else fails.
176
+ * @public
177
+ */
178
+ declare const boolean: Converter<boolean, undefined>;
179
+
180
+ /**
181
+ * A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.
182
+ * @public
183
+ */
184
+ declare const boolean_2: Validator<boolean>;
185
+
186
+ /**
187
+ * An in-place {@link Validation.Validator | Validator} for `boolean` values.
188
+ * @public
189
+ */
190
+ declare class BooleanValidator<TC = unknown> extends GenericValidator<boolean, TC> {
191
+ /**
192
+ * Constructs a new {@link Validation.Classes.BooleanValidator | BooleanValidator}.
193
+ * @param params - Optional {@link Validation.Classes.BooleanValidatorConstructorParams | init params} for the
194
+ * new {@link Validation.Classes.BooleanValidator | BooleanValidator}.
195
+ */
196
+ constructor(params?: BooleanValidatorConstructorParams<TC>);
197
+ /**
198
+ * Static method which validates that a supplied `unknown` value is a `boolean`.
199
+ * @param from - The `unknown` value to be tested.
200
+ * @returns Returns `true` if `from` is a `boolean`, or {@link Failure} with an error
201
+ * message if not.
202
+ */
203
+ static validateBoolean(from: unknown): boolean | Failure<boolean>;
204
+ }
205
+
206
+ /**
207
+ * Parameters used to construct a {@link Validation.Classes.BooleanValidator | BooleanValidator}.
208
+ * @public
209
+ */
210
+ declare type BooleanValidatorConstructorParams<TC = unknown> = GenericValidatorConstructorParams<boolean, TC>;
211
+
212
+ /**
213
+ * Helper type to brand a simple type to prevent inappropriate use
214
+ * @public
215
+ */
216
+ export declare type Brand<T, B> = T & {
217
+ __brand: B;
218
+ };
219
+
220
+ /**
221
+ * Wraps a function which might throw to convert exception results
222
+ * to {@link Failure}.
223
+ * @param func - The function to be captured.
224
+ * @returns Returns {@link Success} with a value of type `<T>` on
225
+ * success , or {@link Failure} with the thrown error message if
226
+ * `func` throws an `Error`.
227
+ * @public
228
+ */
229
+ export declare function captureResult<T>(func: () => T): Result<T>;
230
+
231
+ declare namespace Classes {
232
+ export {
233
+ ArrayValidator,
234
+ ArrayValidatorConstructorParams,
235
+ StringValidator,
236
+ StringValidatorConstructorParams,
237
+ BooleanValidator,
238
+ BooleanValidatorConstructorParams,
239
+ NumberValidator,
240
+ NumberValidatorConstructorParams,
241
+ FieldValidators,
242
+ ObjectValidator,
243
+ ObjectValidatorConstructorParams,
244
+ ObjectValidatorOptions,
245
+ TypeGuardValidator,
246
+ TypeGuardValidatorConstructorParams
247
+ }
248
+ }
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
+ /**
259
+ * A {@link Validation.Constraint | Constraint<T>} function returns
260
+ * `true` if the supplied value meets the constraint. Can return
261
+ * {@link Failure} with an error message or simply return `false`
262
+ * for a default message.
263
+ * @public
264
+ */
265
+ declare type Constraint<T> = (val: T) => boolean | Failure<T>;
266
+
267
+ /**
268
+ * Options for {@link Converter.withConstraint}.
269
+ * @public
270
+ */
271
+ declare interface ConstraintOptions {
272
+ /**
273
+ * Optional description for error messages when constraint
274
+ * function returns false.
275
+ */
276
+ readonly description: string;
277
+ }
278
+
279
+ /**
280
+ * Union of all supported constraint traits.
281
+ * @public
282
+ */
283
+ declare type ConstraintTrait = FunctionConstraintTrait;
284
+
285
+ declare namespace Conversion {
286
+ export {
287
+ Converters,
288
+ ConverterTraits,
289
+ ConstraintOptions,
290
+ Converter,
291
+ Infer,
292
+ ConvertedToType,
293
+ BaseConverter,
294
+ ObjectConverterOptions,
295
+ FieldConverters,
296
+ ObjectConverter,
297
+ StringMatchOptions,
298
+ StringConverter
299
+ }
300
+ }
301
+ export { Conversion }
302
+
303
+ /**
304
+ * Deprecated name for Infer<T> retained for compatibility
305
+ * @deprecated use @see Infer instead
306
+ * @internal
307
+ */
308
+ declare type ConvertedToType<TCONV> = Infer<TCONV>;
309
+
310
+ /**
311
+ * Generic converter to convert unknown to a templated type `<T>`, using
312
+ * intrinsic rules or as modified by an optional conversion context
313
+ * of optional templated type `<TC>` (default `undefined`).
314
+ * @public
315
+ */
316
+ export declare interface Converter<T, TC = undefined> extends ConverterTraits {
317
+ /**
318
+ * Indicates whether this element is explicitly optional.
319
+ */
320
+ readonly isOptional: boolean;
321
+ /**
322
+ * Returns the brand for a branded type.
323
+ */
324
+ readonly brand?: string;
325
+ /**
326
+ * Converts from `unknown` to `<T>`.
327
+ * @param from - The `unknown` to be converted
328
+ * @param context - An optional conversion context of type `<TC>` to be used in
329
+ * the conversion.
330
+ * @returns A {@link Result} with a {@link Success} and a value on success or an
331
+ * {@link Failure} with a a message on failure.
332
+ */
333
+ convert(from: unknown, context?: TC): Result<T>;
334
+ /**
335
+ * Converts from `unknown` to `<T>` or `undefined`, as appropriate.
336
+ *
337
+ * @remarks
338
+ * If `onError` is `failOnError`, the converter succeeds for
339
+ * `undefined` or any convertible value, but reports an error
340
+ * if it encounters a value that cannot be converted.
341
+ *
342
+ * If `onError` is `ignoreErrors` (default) then values that
343
+ * cannot be converted result in a successful return of `undefined`.
344
+ * @param from - The `unknown` to be converted
345
+ * @param context - An optional conversion context of type `<TC>` to be used in
346
+ * the conversion.
347
+ * @param onError - Specifies handling of values that cannot be converted (default `ignoreErrors`).
348
+ * @returns A {@link Result} with a {@link Success} and a value on success or an
349
+ * {@link Failure} with a a message on failure.
350
+ */
351
+ convertOptional(from: unknown, context?: TC, onError?: OnError): Result<T | undefined>;
352
+ /**
353
+ * Creates a {@link Converter} for an optional value.
354
+ *
355
+ * @remarks
356
+ * If `onError` is `failOnError`, the resulting converter will accept `undefined`
357
+ * or a convertible value, but report an error if it encounters a value that cannot be
358
+ * converted.
359
+ *
360
+ * If `onError` is `ignoreErrors` (default) then values that cannot be converted will
361
+ * result in a successful return of `undefined`.
362
+ *
363
+ * @param onError - Specifies handling of values that cannot be converted (default `ignoreErrors`).
364
+ * @returns A new {@link Converter} returning `<T|undefined>`.
365
+ * */
366
+ optional(onError?: OnError): Converter<T | undefined, TC>;
367
+ /**
368
+ * Creates a {@link Converter} which applies a (possibly) mapping conversion to
369
+ * the converted value of this {@link Converter}.
370
+ * @param mapper - A function which maps from the the result type `<T>` of this
371
+ * converter to a new result type `<T2>`.
372
+ * @returns A new {@link Converter} returning `<T2>`.
373
+ */
374
+ map<T2>(mapper: (from: T) => Result<T2>): Converter<T2, TC>;
375
+ /**
376
+ * Creates a {@link Converter} which applies an additional supplied
377
+ * converter to the result of this converter.
378
+ *
379
+ * @param mapConverter - The {@link Converter} to be applied to the
380
+ * converted result from this {@link Converter}.
381
+ * @returns A new {@link Converter} returning `<T2>`.
382
+ */
383
+ mapConvert<T2>(mapConverter: Converter<T2>): Converter<T2, TC>;
384
+ /**
385
+ * Creates a {@link Converter} which maps the individual items of a collection
386
+ * resulting from this {@link Converter} using the supplied map function.
387
+ *
388
+ * @remarks
389
+ * Fails if `from` is not an array.
390
+ *
391
+ * @param mapper - The map function to be applied to each element of the
392
+ * result of this {@link Converter}.
393
+ * @returns A new {@link Converter} returning `<TI[]>`.
394
+ */
395
+ mapItems<TI>(mapper: (from: unknown) => Result<TI>): Converter<TI[], TC>;
396
+ /**
397
+ * Creates a {@link Converter} which maps the individual items of a collection
398
+ * resulting from this {@link Converter} using the supplied {@link Converter}.
399
+ *
400
+ * @remarks
401
+ * Fails if `from` is not an array.
402
+ *
403
+ * @param mapConverter - The {@link Converter} to be applied to each element of the
404
+ * result of this {@link Converter}.
405
+ * @returns A new {@link Converter} returning `<TI[]>`.
406
+ */
407
+ mapConvertItems<TI>(mapConverter: Converter<TI, unknown>): Converter<TI[], TC>;
408
+ /**
409
+ * Creates a {@link Converter} which applies a supplied type guard to the conversion
410
+ * result.
411
+ * @param guard - The type guard function to apply.
412
+ * @param message - Optional message to be reported if the type guard fails.
413
+ * @returns A new {@link Converter} returning `<TI>`.
414
+ */
415
+ withTypeGuard<TI>(guard: (from: unknown) => from is TI, message?: string): Converter<TI, TC>;
416
+ /**
417
+ * Creates a {@link Converter} which applies a supplied type guard to each member of
418
+ * the conversion result from this converter.
419
+ *
420
+ * @remarks
421
+ * Fails if the conversion result is not an array or if any member fails the
422
+ * type guard.
423
+ * @param guard - The type guard function to apply to each element.
424
+ * @param message - Optional message to be reported if the type guard fails.
425
+ * @returns A new {@link Converter} returning `<TI>`.
426
+ */
427
+ withItemTypeGuard<TI>(guard: (from: unknown) => from is TI, message?: string): Converter<TI[], TC>;
428
+ /**
429
+ * Creates a {@link Converter} which applies an optional constraint to the result
430
+ * of this conversion. If this {@link Converter} (the base converter) succeeds, the new
431
+ * converter calls a supplied constraint evaluation function with the conversion, which
432
+ * fails the entire conversion if the constraint function returns either `false` or
433
+ * {@link Failure | Failure<T>}.
434
+ *
435
+ * @param constraint - Constraint evaluation function.
436
+ * @param options - {@link Conversion.ConstraintOptions | Options} for constraint evaluation.
437
+ * @returns A new {@link Converter} returning `<T>`.
438
+ */
439
+ withConstraint(constraint: (val: T) => boolean | Result<T>, options?: ConstraintOptions): Converter<T, TC>;
440
+ /**
441
+ * returns a converter which adds a brand to the type to prevent mismatched usage
442
+ * of simple types.
443
+ * @param brand - The brand to be applied to the result value.
444
+ * @returns A {@link Converter} returning `Brand<T, B>`.
445
+ */
446
+ withBrand<B extends string>(brand: B): Converter<Brand<T, B>, TC>;
447
+ }
448
+
449
+ declare namespace Converters {
450
+ export {
451
+ templateString,
452
+ enumeratedValue,
453
+ mappedEnumeratedValue,
454
+ literal,
455
+ delimitedString,
456
+ validated,
457
+ isA,
458
+ oneOf,
459
+ arrayOf,
460
+ extendedArrayOf,
461
+ recordOf,
462
+ mapOf,
463
+ validateWith,
464
+ element,
465
+ optionalElement,
466
+ field,
467
+ optionalField,
468
+ object,
469
+ strictObject,
470
+ discriminatedObject,
471
+ transform,
472
+ transformObject,
473
+ rangeTypeOf,
474
+ rangeOf,
475
+ string,
476
+ value,
477
+ number,
478
+ boolean,
479
+ optionalString,
480
+ isoDate,
481
+ optionalNumber,
482
+ optionalBoolean,
483
+ stringArray,
484
+ numberArray,
485
+ KeyedConverterOptions,
486
+ StrictObjectConverterOptions,
487
+ DiscriminatedObjectConverters,
488
+ FieldTransformers,
489
+ TransformObjectOptions
490
+ }
491
+ }
492
+ export { Converters }
493
+
494
+ /**
495
+ * Converter traits.
496
+ * @public
497
+ */
498
+ declare interface ConverterTraits {
499
+ readonly isOptional: boolean;
500
+ readonly brand?: string;
501
+ }
502
+
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
+ /**
527
+ * Default {@link Validation.ValidatorTraitValues | validation traits}.
528
+ * @public
529
+ */
530
+ declare const defaultValidatorTraits: ValidatorTraitValues;
531
+
532
+ /**
533
+ * Helper function to create a {@link Converter} which converts any `string` into an
534
+ * array of `string`, by separating at a supplied delimiter.
535
+ * @remarks
536
+ * Delimiter may also be supplied as context at conversion time.
537
+ * @param delimiter - The delimiter at which to split.
538
+ * @returns A new {@link Converter} returning `string[]`.
539
+ * @public
540
+ */
541
+ declare function delimitedString(delimiter: string, options?: 'filtered' | 'all'): Converter<string[], string>;
542
+
543
+ /**
544
+ * A {@link DetailedFailure} extends {@link Failure} to report optional failure details in
545
+ * addition to the error message.
546
+ * @public
547
+ */
548
+ export declare class DetailedFailure<T, TD> extends Failure<T> {
549
+ /**
550
+ * @internal
551
+ */
552
+ protected _detail: TD;
553
+ /**
554
+ * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied
555
+ * message and detail.
556
+ * @param message - The message to be returned.
557
+ * @param detail - The error detail to be returned.
558
+ */
559
+ constructor(message: string, detail: TD);
560
+ /**
561
+ * The error detail associated with this {@link DetailedFailure}.
562
+ */
563
+ get detail(): TD;
564
+ /**
565
+ * Reports that this {@link DetailedFailure} is a failure.
566
+ * @remarks
567
+ * Always true for {@link DetailedFailure} but can be used as type guard
568
+ * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in
569
+ * a {@link DetailedResult}.
570
+ * @returns `true`
571
+ */
572
+ isFailure(): this is DetailedFailure<T, TD>;
573
+ /**
574
+ * Propagates the error message and detail from this result.
575
+ * @remarks
576
+ * Mutates the success type as the success callback would have, but does not
577
+ * call the success callback.
578
+ * @param _cb - {@link DetailedSuccessContinuation | Success callback} to be called
579
+ * on a {@link DetailedResult} in case of success (ignored).
580
+ * @returns A new {@link DetailedFailure | DetailedFailure<TN, TD>} which contains
581
+ * the error message and detail from this one.
582
+ */
583
+ onSuccess<TN>(__cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD>;
584
+ /**
585
+ * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates
586
+ * its returned {@link DetailedResult | DetailedResult<T, TD>}.
587
+ * @param cb - The {@link DetailedFailureContinuation | failure callback} to be invoked.
588
+ * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.
589
+ */
590
+ onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD>;
591
+ }
592
+
593
+ /**
594
+ * Callback to be called when a {@link DetailedResult} encounters a failure.
595
+ * @remarks
596
+ * A failure callback can change {@link Failure} to {@link Success} (e.g. by returning a default value)
597
+ * or it can change or embellish the error message, but it cannot change the success return type.
598
+ * @public
599
+ */
600
+ export declare type DetailedFailureContinuation<T, TD> = (message: string, detail: TD) => DetailedResult<T, TD>;
601
+
602
+ /**
603
+ * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.
604
+ * @beta
605
+ */
606
+ export declare type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;
607
+
608
+ /**
609
+ * A {@link DetailedSuccess} extends {@link Success} to report optional success details in
610
+ * addition to the error message.
611
+ * @public
612
+ */
613
+ export declare class DetailedSuccess<T, TD> extends Success<T> {
614
+ /**
615
+ * @internal
616
+ */
617
+ protected _detail?: TD;
618
+ /**
619
+ * Constructs a new {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied
620
+ * value and detail.
621
+ * @param value - The value to be returned.
622
+ * @param detail - An optional successful detail to be returned. If omitted, detail
623
+ * will be `undefined`.
624
+ */
625
+ constructor(value: T, detail?: TD);
626
+ /**
627
+ * The success detail associated with this {@link DetailedSuccess}, or `undefined` if
628
+ * no detail was supplied.
629
+ */
630
+ get detail(): TD | undefined;
631
+ /**
632
+ * Reports that this {@link DetailedSuccess} is a success.
633
+ * @remarks
634
+ * Always true for {@link DetailedSuccess} but can be used as type guard
635
+ * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in
636
+ * a {@link DetailedResult}.
637
+ * @returns `true`
638
+ */
639
+ isSuccess(): this is DetailedSuccess<T, TD>;
640
+ /**
641
+ * Invokes the supplied {@link DetailedSuccessContinuation | success callback} and propagates
642
+ * its returned {@link DetailedResult | DetailedResult<TN, TD>}.
643
+ * @remarks
644
+ * The success callback mutates the return type from `<T>` to `<TN>`.
645
+ * @param cb - The {@link DetailedSuccessContinuation | success callback} to be invoked.
646
+ * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.
647
+ */
648
+ onSuccess<TN>(cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD>;
649
+ /**
650
+ * Propagates this {@link DetailedSuccess}.
651
+ * @remarks
652
+ * Failure does not mutate return type so we can return this event directly.
653
+ * @param _cb - {@link DetailedFailureContinuation | Failure callback} to be called
654
+ * on a {@link DetailedResult} in case of failure (ignored).
655
+ * @returns `this`
656
+ */
657
+ onFailure(__cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD>;
658
+ }
659
+
660
+ /**
661
+ * Callback to be called when a {@link DetailedResult} encounters success.
662
+ * @remarks
663
+ * A success callback can return a different result type than it receives, allowing
664
+ * success results to chain through intermediate result types.
665
+ * @public
666
+ */
667
+ export declare type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;
668
+
669
+ /**
670
+ * Helper to create a {@link Converter} which converts a discriminated object without changing shape.
671
+ * @remarks
672
+ * Takes the name of the discriminator property and a
673
+ * {@link Converters.DiscriminatedObjectConverters | string-keyed Record of converters}. During conversion,
674
+ * the resulting {@link Converter} invokes the converter from `converters` that corresponds to the value of
675
+ * the discriminator property in the source object.
676
+ *
677
+ * If the source is not an object, the discriminator property is missing, or the discriminator has
678
+ * a value not present in the converters, conversion fails and returns {@link Failure} with more information.
679
+ * @param discriminatorProp - Name of the property used to discriminate types.
680
+ * @param converters - {@link Converters.DiscriminatedObjectConverters | String-keyed record of converters} to
681
+ * invoke, where each key corresponds to a value of the discriminator property.
682
+ * @returns A {@link Converter} which converts the corresponding discriminated object.
683
+ * @public
684
+ */
685
+ declare function discriminatedObject<T, TD extends string = string, TC = unknown>(discriminatorProp: string, converters: DiscriminatedObjectConverters<T, TD>): Converter<T, TC>;
686
+
687
+ /**
688
+ * A string-keyed `Record<string, Converter>` which maps specific {@link Converter | converters} to the
689
+ * value of a discriminator property.
690
+ * @public
691
+ */
692
+ declare type DiscriminatedObjectConverters<T, TD extends string = string, TC = unknown> = Record<TD, Converter<T, TC>>;
693
+
694
+ /**
695
+ * A helper function to create a {@link Converter} which extracts and converts an element from an array.
696
+ * @remarks
697
+ * The returned {@link Converter} returns {@link Success} with the converted value if the element exists
698
+ * in the supplied array and can be converted. Returns {@link Failure} with an error message otherwise.
699
+ * @param index - The index of the element to be extracted.
700
+ * @param converter - A {@link Converter} used to convert the extracted element.
701
+ * @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
702
+ * @public
703
+ */
704
+ declare function element<T, TC = undefined>(index: number, converter: Converter<T, TC>): Converter<T, TC>;
705
+
706
+ /**
707
+ * @internal
708
+ */
709
+ declare type Entry<T> = [string | number | symbol, T];
710
+
711
+ /**
712
+ * Helper function to create a {@link Converter} which converts `unknown` to one of a set of supplied
713
+ * enumerated values. Anything else fails.
714
+ *
715
+ * @remarks
716
+ * Allowed enumerated values can also be supplied as context at conversion time.
717
+ * @param values - Array of allowed values.
718
+ * @returns A new {@link Converter} returning `<T>`.
719
+ * @public
720
+ */
721
+ declare function enumeratedValue<T>(values: T[]): Converter<T, T[]>;
722
+
723
+ /**
724
+ * Helper function to create a {@link Validation.Validator} which validates an enumerated
725
+ * value in place.
726
+ * @public
727
+ */
728
+ declare function enumeratedValue_2<T extends string>(values: T[]): Validator<T, T[]>;
729
+
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
+ /**
815
+ * Returns {@link Failure | Failure<T>} with the supplied error message.
816
+ * @param message - Error message to be returned.
817
+ * @public
818
+ */
819
+ declare function fail_2<T>(message: string): Failure<T>;
820
+ export { fail_2 as fail }
821
+
822
+ /**
823
+ * Reports a failed {@link IResult | result} from some operation, with an error message.
824
+ * @public
825
+ */
826
+ export declare class Failure<T> implements IResult<T> {
827
+ /**
828
+ * {@inheritdoc IResult.success}
829
+ */
830
+ readonly success: false;
831
+ /**
832
+ * @internal
833
+ */
834
+ private readonly _message;
835
+ /**
836
+ * Constructs a {@link Failure} with the supplied message.
837
+ * @param message - Error message to be reported.
838
+ */
839
+ constructor(message: string);
840
+ /**
841
+ * Gets the error message associated with this error.
842
+ */
843
+ get message(): string;
844
+ /**
845
+ * {@inheritdoc IResult.isSuccess}
846
+ */
847
+ isSuccess(): this is Success<T>;
848
+ /**
849
+ * {@inheritdoc IResult.isFailure}
850
+ */
851
+ isFailure(): this is Failure<T>;
852
+ /**
853
+ * {@inheritdoc IResult.orThrow}
854
+ */
855
+ orThrow(logger?: IResultLogger): never;
856
+ /**
857
+ * {@inheritdoc IResult.orDefault}
858
+ */
859
+ orDefault(dflt?: T): T | undefined;
860
+ /**
861
+ * {@inheritdoc IResult.getValueOrThrow}
862
+ */
863
+ getValueOrThrow(logger?: IResultLogger): never;
864
+ /**
865
+ * {@inheritdoc IResult.getValueOrDefault}
866
+ */
867
+ getValueOrDefault(dflt?: T): T | undefined;
868
+ /**
869
+ * {@inheritdoc IResult.onSuccess}
870
+ */
871
+ onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN>;
872
+ /**
873
+ * {@inheritdoc IResult.onFailure}
874
+ */
875
+ onFailure(cb: FailureContinuation<T>): Result<T>;
876
+ /**
877
+ * {@inheritdoc IResult.withFailureDetail}
878
+ */
879
+ withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;
880
+ /**
881
+ * {@inheritdoc IResult.withDetail}
882
+ */
883
+ withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD>;
884
+ /**
885
+ * Get a 'friendly' string representation of this object.
886
+ * @remarks
887
+ * The string representation of a {@link Failure} value is the error message.
888
+ * @returns A string representing this object.
889
+ */
890
+ toString(): string;
891
+ }
892
+
893
+ /**
894
+ * Continuation callback to be called in the event that an
895
+ * {@link Result} fails.
896
+ * @public
897
+ */
898
+ export declare type FailureContinuation<T> = (message: string) => Result<T>;
899
+
900
+ /**
901
+ * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.
902
+ * @param message - The error message to be returned.
903
+ * @param detail - The event detail to be returned.
904
+ * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error
905
+ * message and detail.
906
+ * @public
907
+ */
908
+ export declare function failWithDetail<T, TD>(message: string, detail: TD): DetailedFailure<T, TD>;
909
+
910
+ /**
911
+ * A helper function to create a {@link Converter} which extracts and convert a property specified
912
+ * by name from an object.
913
+ * @remarks
914
+ * The resulting {@link Converter} returns {@link Success} with the converted value of the corresponding
915
+ * object property if the field exists and can be converted. Returns {@link Failure} with an error message
916
+ * otherwise.
917
+ * @param name - The name of the field to be extracted.
918
+ * @param converter - {@link Converter} used to convert the extracted field.
919
+ * @public
920
+ */
921
+ declare function field<T, TC = undefined>(name: string, converter: Converter<T, TC>): Converter<T, TC>;
922
+
923
+ /**
924
+ * Per-property converters for each of the properties in type T.
925
+ * @remarks
926
+ * Used to construct a {@link Conversion.ObjectConverter | ObjectConverter}
927
+ * @public
928
+ */
929
+ declare type FieldConverters<T, TC = unknown> = {
930
+ [key in keyof T]: Converter<T[key], TC>;
931
+ };
932
+
933
+ /**
934
+ * String-keyed record of initialization functions to be passed to {@link (populateObject:1)}
935
+ * or {@link (populateObject:2)}.
936
+ * @public
937
+ */
938
+ export declare type FieldInitializers<T> = {
939
+ [key in keyof T]: (state: Partial<T>) => Result<T[key]>;
940
+ };
941
+
942
+ /**
943
+ * Per-property converters and configuration for each field in the destination object of
944
+ * a {@link Converters.transformObject} call.
945
+ * @public
946
+ */
947
+ declare type FieldTransformers<TSRC, TDEST, TC = unknown> = {
948
+ [key in keyof TDEST]: {
949
+ /**
950
+ * The name of the property in the source object to be converter.
951
+ */
952
+ from: keyof TSRC;
953
+ /**
954
+ * The converter used to convert the property.
955
+ */
956
+ converter: Converter<TDEST[key], TC>;
957
+ /**
958
+ * If `true` then a missing source property is ignored. If `false` or omitted
959
+ * then a missing source property causes an error.
960
+ */
961
+ optional?: boolean;
962
+ };
963
+ };
964
+
965
+ /**
966
+ * Per-property {@link Validation.Validator | validators} for each of the properties in `<T>`.
967
+ * @public
968
+ */
969
+ declare type FieldValidators<T, TC = unknown> = {
970
+ [key in keyof T]: Validator<T[key], TC>;
971
+ };
972
+
973
+ /**
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
981
+ */
982
+ declare function formatList<T>(format: string, items: T[], itemFormatter: Formatter<T>): Result<string>;
983
+
984
+ /**
985
+ * Interface for an object that can be formatted.
986
+ * @beta
987
+ */
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
+
998
+ /**
999
+ * Base class which adds common formatting.
1000
+ * @beta
1001
+ */
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
+
1017
+ /**
1018
+ * Destination format for some formatted string.
1019
+ * @beta
1020
+ */
1021
+ declare type FormatTargets = 'text' | 'markdown' | 'embed';
1022
+
1023
+ /**
1024
+ * Type definition for a formatting function, which takes a `string` and an
1025
+ * item and returns {@link Result | Result<string>}.
1026
+ * @beta
1027
+ */
1028
+ declare type Formatter<T> = (format: string, item: T) => Result<string>;
1029
+
1030
+ /**
1031
+ * A collection of {@link Experimental.Formatter | formatters} indexed by target name, to enable
1032
+ * different format methods per output target.
1033
+ * @beta
1034
+ */
1035
+ declare type FormattersByExtendedTarget<TFT extends FormatTargets, T> = Record<TFT, Formatter<T>>;
1036
+
1037
+ /**
1038
+ * A collection of {@link Experimental.Formatter | formatters} indexed by the
1039
+ * {@link Experimental.FormatTargets | default supported target formats}.
1040
+ * @beta
1041
+ */
1042
+ declare type FormattersByTarget<T> = FormattersByExtendedTarget<FormatTargets, T>;
1043
+
1044
+ /**
1045
+ * A {@link Validation.ConstraintTrait | ConstraintTrait} indicating that
1046
+ * a {@link Validation.Constraint | Constraint<T>} function provides an
1047
+ * additional constraint implementation.
1048
+ * @public
1049
+ */
1050
+ declare interface FunctionConstraintTrait {
1051
+ type: 'function';
1052
+ }
1053
+
1054
+ /**
1055
+ * Generic base implementation for an in-place {@link Validation.Validator | Validator}.
1056
+ * @public
1057
+ */
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
+
1118
+ /**
1119
+ * Options used to initialize a {@link Validation.Base.GenericValidator | GenericValidator}.
1120
+ * @public
1121
+ */
1122
+ declare interface GenericValidatorConstructorParams<T, TC> {
1123
+ options?: ValidatorOptions<TC>;
1124
+ traits?: Partial<ValidatorTraits>;
1125
+ validator?: ValidatorFunc<T, TC>;
1126
+ }
1127
+
1128
+ /**
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
1138
+ */
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
+
1141
+ /**
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
1151
+ */
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
+
1162
+ /**
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
1167
+ */
1168
+ declare type Infer<TCONV> = TCONV extends Converter<infer TTO> ? InnerInferredType<TTO> : never;
1169
+
1170
+ /**
1171
+ * @public
1172
+ */
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
+
1184
+ /**
1185
+ * internal
1186
+ */
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;
1188
+
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
+ }
1301
+
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
+ }
1313
+
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>;
1323
+
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>;
1334
+
1335
+ /**
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
1342
+ */
1343
+ export declare function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T;
1344
+
1345
+ /**
1346
+ * A {@link Converter} which converts an iso formatted string, a number or a `Date` object to
1347
+ * a `Date` object.
1348
+ * @public
1349
+ */
1350
+ declare const isoDate: Converter<Date, unknown>;
1351
+
1352
+ /**
1353
+ * @public
1354
+ */
1355
+ declare type JarFieldPicker<T extends JarRecord = JarRecord> = (record: T) => (keyof T)[];
1356
+
1357
+ /**
1358
+ * Represents a single record in a JAR file
1359
+ * @public
1360
+ */
1361
+ declare type JarRecord = Record<string, string | string[]>;
1362
+
1363
+ /**
1364
+ * Options for a JAR record parser.
1365
+ * @public
1366
+ */
1367
+ declare interface JarRecordParserOptions {
1368
+ readonly arrayFields?: string[] | JarFieldPicker;
1369
+ readonly fixedContinuationSize?: number;
1370
+ }
1371
+
1372
+ /**
1373
+ * Options for {@link Converters.(recordOf:3) | Converters.recordOf} and
1374
+ * {@link Converters.(mapOf:3) | Converters.mapOf}
1375
+ * helper functions.
1376
+ * @public
1377
+ */
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
+
1393
+ /**
1394
+ * Type for factory methods which convert a key-value pair to a new unique value.
1395
+ * @public
1396
+ */
1397
+ declare type KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;
1398
+
1399
+ /**
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
1405
+ */
1406
+ declare function literal<T>(value: T): Converter<T, unknown>;
1407
+
1408
+ /**
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
1412
+ */
1413
+ declare function literal_2<T extends string | number | boolean | symbol | null | undefined>(value: T): Validator<T>;
1414
+
1415
+ /**
1416
+ * @public
1417
+ */
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
+ }
1426
+
1427
+ /**
1428
+ * @public
1429
+ */
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
+ }
1443
+
1444
+ declare namespace Logging {
1445
+ export {
1446
+ LogLevel,
1447
+ Logger,
1448
+ LoggerBase,
1449
+ InMemoryLogger,
1450
+ NoOpLogger
1451
+ }
1452
+ }
1453
+ export { Logging }
1454
+
1455
+ /**
1456
+ * @public
1457
+ */
1458
+ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
1459
+
1460
+ /**
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[]>;
1472
+
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>;
1495
+
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>;
1509
+
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>;
1524
+
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>;
1539
+
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[]>;
1549
+
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[]>;
1560
+
1561
+ /**
1562
+ * Applies a factory method to convert a `Map<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: Map<TK, TS>, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
1570
+
1571
+ /**
1572
+ * @public
1573
+ */
1574
+ declare class NoOpLogger extends LoggerBase {
1575
+ protected _innerLog(message: string): Success<string | undefined>;
1576
+ }
1577
+
1578
+ /**
1579
+ * Normalizes an arbitrary JSON object
1580
+ * @public
1581
+ */
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
+
1618
+ /**
1619
+ * Computes a normalized hash for an arbitrary javascript value.
1620
+ * @public
1621
+ */
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
+
1661
+ /**
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
1666
+ */
1667
+ declare const number: Converter<number, undefined>;
1668
+
1669
+ /**
1670
+ * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.
1671
+ * @public
1672
+ */
1673
+ declare const number_2: Validator<number>;
1674
+
1675
+ /**
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
1681
+ */
1682
+ declare const numberArray: Converter<number[] | undefined>;
1683
+
1684
+ /**
1685
+ * An in-place {@link Validation.Validator | Validator} for `number` values.
1686
+ * @public
1687
+ */
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
+
1704
+ /**
1705
+ * Parameters used to construct a {@link Validation.Classes.NumberValidator | NumberValidator}.
1706
+ * @public
1707
+ */
1708
+ declare type NumberValidatorConstructorParams<T extends number = number, TC = unknown> = GenericValidatorConstructorParams<T, TC>;
1709
+
1710
+ /**
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.
1727
+ * {@label WITH_OPTIONS}
1728
+ * @public
1729
+ */
1730
+ declare function object<T>(properties: FieldConverters<T>, options?: ObjectConverterOptions<T>): ObjectConverter<T>;
1731
+
1732
+ /**
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.
1747
+ * {@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
+ */
1752
+ declare function object<T>(properties: FieldConverters<T>, optional: (keyof T)[]): ObjectConverter<T>;
1753
+
1754
+ /**
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.
1763
+ * @public
1764
+ */
1765
+ declare function object_2<T, TC = unknown>(fields: FieldValidators<T, TC>, params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>): ObjectValidator<T, TC>;
1766
+
1767
+ /**
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.
1775
+ * @public
1776
+ */
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
+ }
1831
+
1832
+ /**
1833
+ * Options for an {@link Conversion.ObjectConverter | ObjectConverter}.
1834
+ * @public
1835
+ */
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
+ }
1851
+
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.
1858
+ * @public
1859
+ */
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
+ }
1924
+
1925
+ /**
1926
+ * Options for the {@link Validation.Classes.ObjectValidator | ObjectValidator} constructor.
1927
+ * @public
1928
+ */
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
+ }
1942
+
1943
+ /**
1944
+ * Options for an {@link Validation.Classes.ObjectValidator | ObjectValidator}.
1945
+ * @public
1946
+ */
1947
+ declare interface ObjectValidatorOptions<T, TC> extends ValidatorOptions<TC> {
1948
+ /**
1949
+ * If present, lists optional fields. Missing non-optional fields cause an error.
1950
+ */
1951
+ optionalFields?: (keyof T)[];
1952
+ /**
1953
+ * If true, unrecognized fields yield an error. If false or undefined (default),
1954
+ * unrecognized fields are ignored.
1955
+ */
1956
+ strict?: boolean;
1957
+ }
1958
+
1959
+ /**
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.
1984
+ * @public
1985
+ */
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';
1991
+
1992
+ /**
1993
+ * A {@link Converter} to convert an optional `boolean` value.
1994
+ * @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`.
1998
+ * @public
1999
+ */
2000
+ declare const optionalBoolean: Converter<boolean | undefined>;
2001
+
2002
+ /**
2003
+ * A helper function to create a {@link Converter} which extracts and converts an optional element from an array.
2004
+ * @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.
2012
+ * @public
2013
+ */
2014
+ declare function optionalElement<T, TC = undefined>(index: number, converter: Converter<T, TC>): Converter<T | undefined, TC>;
2015
+
2016
+ /**
2017
+ * A helper function to create a {@link Converter} which extracts and convert a property specified
2018
+ * by name from an object.
2019
+ * @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.
2026
+ * @public
2027
+ */
2028
+ declare function optionalField<T, TC = undefined>(name: string, converter: Converter<T, TC>): Converter<T | undefined, TC>;
2029
+
2030
+ /**
2031
+ * Applies a factory method to convert an optional `Map<string, TS>` into a `Record<string, TD>`
2032
+ * @param src - The `Map` object to be converted, or `undefined`.
2033
+ * @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.
2036
+ * @public
2037
+ */
2038
+ export declare function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(src: Map<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
2039
+
2040
+ /**
2041
+ * Applies a factory method to convert an optional `Map<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: Map<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>>;
2078
+
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>;
2085
+
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[]>;
2095
+
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>;
2105
+
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 }
2330
+
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>;
2342
+
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>;
2356
+
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>;
2371
+
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>>;
2381
+
2382
+ /**
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
2388
+ */
2389
+ export declare type Result<T> = Success<T> | Failure<T>;
2390
+
2391
+ /**
2392
+ * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.
2393
+ * @beta
2394
+ */
2395
+ export declare type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;
2396
+
2397
+ /**
2398
+ * Type inference to determine the result type of an {@link Result}.
2399
+ * @beta
2400
+ */
2401
+ export declare type ResultValueType<T> = T extends Result<infer TV> ? TV : never;
2402
+
2403
+ /**
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>;
2422
+
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>;
2443
+
2444
+ /**
2445
+ * Options for the {@link Converters.(strictObject:1)} helper function.
2446
+ * @public
2447
+ */
2448
+ declare type StrictObjectConverterOptions<T> = Omit<ObjectConverterOptions<T>, 'strict'>;
2449
+
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;
2456
+
2457
+ /**
2458
+ * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
2459
+ * @public
2460
+ */
2461
+ declare const string_2: Validator<string>;
2462
+
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[] | undefined>;
2471
+
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>;
2524
+ /**
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
+
2536
+ /**
2537
+ * Options for {@link Conversion.StringConverter | StringConverter}
2538
+ * matching method
2539
+ * @public
2540
+ */
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
+
2549
+ /**
2550
+ * An in-place {@link Validation.Validator | Validator} for `string` values.
2551
+ * @public
2552
+ */
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
+
2569
+ /**
2570
+ * Parameters used to construct a {@link Validation.Classes.StringValidator | StringValidator}.
2571
+ * @public
2572
+ */
2573
+ declare type StringValidatorConstructorParams<T extends string = string, TC = unknown> = GenericValidatorConstructorParams<T, TC>;
2574
+
2575
+ /**
2576
+ * Returns {@link Success | Success<T>} with the supplied result value.
2577
+ * @param value - The successful result value to be returned
2578
+ * @public
2579
+ */
2580
+ export declare function succeed<T>(value: T): Success<T>;
2581
+
2582
+ /**
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
2590
+ */
2591
+ export declare function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
2592
+
2593
+ /**
2594
+ * Reports a successful {@link IResult | result} from some operation and the
2595
+ * corresponding value.
2596
+ * @public
2597
+ */
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
+
2658
+ /**
2659
+ * Continuation callback to be called in the event that an
2660
+ * {@link Result} is successful.
2661
+ * @public
2662
+ */
2663
+ export declare type SuccessContinuation<T, TN> = (value: T) => Result<TN>;
2664
+
2665
+ /**
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
2674
+ */
2675
+ declare function templateString(defaultContext?: unknown): StringConverter<string, unknown>;
2676
+
2677
+ /**
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
2695
+ */
2696
+ declare function transform<T, TC = unknown>(properties: FieldConverters<T, TC>): Converter<T, TC>;
2697
+
2698
+ /**
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
2717
+ */
2718
+ declare function transformObject<TSRC, TDEST, TC = unknown>(destinationFields: FieldTransformers<TSRC, TDEST, TC>, options?: TransformObjectOptions<TSRC>): Converter<TDEST, TC>;
2719
+
2720
+ /**
2721
+ * Options for a {@link Converters.transformObject} call.
2722
+ * @public
2723
+ */
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
+
2741
+ /**
2742
+ * An in-place {@link Validation.Validator | Validator} that can be instantiated using a type guard
2743
+ * function.
2744
+ * @public
2745
+ */
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
+
2772
+ /**
2773
+ * Parameters used to construct a {@link Validation.Classes.TypeGuardValidator}.
2774
+ * @public
2775
+ */
2776
+ declare interface TypeGuardValidatorConstructorParams<T, TC = unknown> extends ValidatorBaseConstructorParams<T, TC> {
2777
+ guard: TypeGuardWithContext<T, TC>;
2778
+ description: string;
2779
+ }
2780
+
2781
+ /**
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
2785
+ */
2786
+ declare type TypeGuardWithContext<T, TC = unknown> = (from: unknown, context?: TC) => from is T;
2787
+
2788
+ /**
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
2793
+ */
2794
+ declare function validated<T, TC = unknown>(validator: Validator<T, TC>): Converter<T, TC>;
2795
+
2796
+ /**
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
2807
+ */
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
+ }
2825
+ }
2826
+ export { Validation }
2827
+
2828
+ /**
2829
+ * In-place validation that a supplied unknown matches some
2830
+ * required characteristics (type, values, etc).
2831
+ * @public
2832
+ */
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.
2844
+ */
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
+ }
2891
+
2892
+ /**
2893
+ * Abstract base helper class for specific validator implementations
2894
+ * @internal
2895
+ */
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
+
2914
+ /**
2915
+ * @internal
2916
+ */
2917
+ declare type ValidatorBaseConstructorParams<T, TC> = Omit<GenericValidatorConstructorParams<T, TC>, 'validator'>;
2918
+
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>;
2926
+
2927
+ /**
2928
+ * Options that apply to any {@link Validation.Validator | Validator}.
2929
+ * @public
2930
+ */
2931
+ declare interface ValidatorOptions<TC> {
2932
+ defaultContext?: TC;
2933
+ }
2934
+
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
+ }
2946
+ }
2947
+ export { Validators }
2948
+
2949
+ /**
2950
+ * Generic implementation of {@link Validation.ValidatorTraitValues | ValidatorTraitValues}.
2951
+ * @public
2952
+ */
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
+
2977
+ /**
2978
+ * Interface describing the supported validator traits.
2979
+ * @public
2980
+ */
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
+ }
2998
+
2999
+ /**
3000
+ * Deprecated alias for @see literal
3001
+ * @param value - The value to be compared.
3002
+ * @deprecated Use {@link Converters.literal} instead.
3003
+ * @internal
3004
+ */
3005
+ declare const value: typeof literal;
3006
+
3007
+ export { }