@fgv/ts-utils 4.0.2 → 4.2.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.
- package/CHANGELOG.json +36 -0
- package/CHANGELOG.md +22 -1
- package/dist/ts-utils.d.ts +553 -54
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +23 -8
- package/lib/index.js.map +1 -1
- package/lib/packlets/base/index.js +17 -7
- package/lib/packlets/base/index.js.map +1 -1
- package/lib/packlets/base/mapResults.js +6 -7
- package/lib/packlets/base/mapResults.js.map +1 -1
- package/lib/packlets/base/result.js +7 -7
- package/lib/packlets/base/result.js.map +1 -1
- package/lib/packlets/base/utils.js +11 -12
- package/lib/packlets/base/utils.js.map +1 -1
- package/lib/packlets/collections/common.d.ts +6 -0
- package/lib/packlets/collections/common.d.ts.map +1 -0
- package/lib/packlets/collections/common.js +24 -0
- package/lib/packlets/collections/common.js.map +1 -0
- package/lib/packlets/collections/index.d.ts +8 -0
- package/lib/packlets/collections/index.d.ts.map +1 -0
- package/lib/packlets/collections/index.js +68 -0
- package/lib/packlets/collections/index.js.map +1 -0
- package/lib/packlets/collections/readonlyResultMap.d.ts +58 -0
- package/lib/packlets/collections/readonlyResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/readonlyResultMap.js +24 -0
- package/lib/packlets/collections/readonlyResultMap.js.map +1 -0
- package/lib/packlets/collections/resultMap.d.ts +155 -0
- package/lib/packlets/collections/resultMap.d.ts.map +1 -0
- package/lib/packlets/collections/resultMap.js +216 -0
- package/lib/packlets/collections/resultMap.js.map +1 -0
- package/lib/packlets/collections/resultMapValidator.d.ts +82 -0
- package/lib/packlets/collections/resultMapValidator.d.ts.map +1 -0
- package/lib/packlets/collections/resultMapValidator.js +104 -0
- package/lib/packlets/collections/resultMapValidator.js.map +1 -0
- package/lib/packlets/collections/utils.d.ts +69 -0
- package/lib/packlets/collections/utils.d.ts.map +1 -0
- package/lib/packlets/collections/utils.js +116 -0
- package/lib/packlets/collections/utils.js.map +1 -0
- package/lib/packlets/collections/validatingResultMap.d.ts +66 -0
- package/lib/packlets/collections/validatingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/validatingResultMap.js +93 -0
- package/lib/packlets/collections/validatingResultMap.js.map +1 -0
- package/lib/packlets/conversion/baseConverter.d.ts +7 -3
- package/lib/packlets/conversion/baseConverter.d.ts.map +1 -1
- package/lib/packlets/conversion/baseConverter.js +10 -0
- package/lib/packlets/conversion/baseConverter.js.map +1 -1
- package/lib/packlets/conversion/converter.d.ts +19 -3
- package/lib/packlets/conversion/converter.d.ts.map +1 -1
- package/lib/packlets/conversion/converter.js.map +1 -1
- package/lib/packlets/conversion/converters.d.ts +42 -42
- package/lib/packlets/conversion/converters.d.ts.map +1 -1
- package/lib/packlets/conversion/converters.js +30 -30
- package/lib/packlets/conversion/converters.js.map +1 -1
- package/lib/packlets/conversion/defaultingConverter.d.ts +6 -2
- package/lib/packlets/conversion/defaultingConverter.d.ts.map +1 -1
- package/lib/packlets/conversion/defaultingConverter.js +7 -0
- package/lib/packlets/conversion/defaultingConverter.js.map +1 -1
- package/lib/packlets/conversion/index.js +17 -7
- package/lib/packlets/conversion/index.js.map +1 -1
- package/lib/packlets/conversion/objectConverter.d.ts +3 -3
- package/lib/packlets/conversion/objectConverter.d.ts.map +1 -1
- package/lib/packlets/conversion/objectConverter.js.map +1 -1
- package/lib/packlets/validation/field.d.ts +1 -1
- package/lib/packlets/validation/field.d.ts.map +1 -1
- package/lib/packlets/validation/field.js.map +1 -1
- package/lib/packlets/validation/genericValidator.d.ts +6 -2
- package/lib/packlets/validation/genericValidator.d.ts.map +1 -1
- package/lib/packlets/validation/genericValidator.js +19 -2
- package/lib/packlets/validation/genericValidator.js.map +1 -1
- package/lib/packlets/validation/index.js +17 -7
- package/lib/packlets/validation/index.js.map +1 -1
- package/lib/packlets/validation/traits.d.ts.map +1 -1
- package/lib/packlets/validation/traits.js +2 -0
- package/lib/packlets/validation/traits.js.map +1 -1
- package/lib/packlets/validation/validator.d.ts +18 -1
- package/lib/packlets/validation/validator.d.ts.map +1 -1
- package/lib/packlets/validation/validator.js.map +1 -1
- package/lib/packlets/validation/validatorBase.d.ts +1 -1
- package/lib/packlets/validation/validatorBase.d.ts.map +1 -1
- package/lib/packlets/validation/validatorBase.js.map +1 -1
- package/lib/packlets/validation/validators.js +7 -7
- package/lib/packlets/validation/validators.js.map +1 -1
- package/package.json +18 -19
|
@@ -38,7 +38,7 @@ export declare function enumeratedValue<T>(values: T[]): Converter<T, T[]>;
|
|
|
38
38
|
* @returns A {@link Converter | Converter} which applies the mapping and yields `<T>` on success.
|
|
39
39
|
* @public
|
|
40
40
|
*/
|
|
41
|
-
export declare function mappedEnumeratedValue<T>(map: [T, unknown[]][], message?: string): Converter<T,
|
|
41
|
+
export declare function mappedEnumeratedValue<T, TC = unknown>(map: [T, unknown[]][], message?: string): Converter<T, TC>;
|
|
42
42
|
/**
|
|
43
43
|
* Helper function to create a {@link Converter | Converter} which converts `unknown` to some supplied literal value. Succeeds with
|
|
44
44
|
* the supplied value if an identity comparison succeeds, fails otherwise.
|
|
@@ -46,7 +46,7 @@ export declare function mappedEnumeratedValue<T>(map: [T, unknown[]][], message?
|
|
|
46
46
|
* @returns A {@link Converter | Converter} which returns the supplied value on success.
|
|
47
47
|
* @public
|
|
48
48
|
*/
|
|
49
|
-
export declare function literal<T>(value: T): Converter<T,
|
|
49
|
+
export declare function literal<T, TC = unknown>(value: T): Converter<T, TC>;
|
|
50
50
|
/**
|
|
51
51
|
* Deprecated alias for @see literal
|
|
52
52
|
* @param value - The value to be compared.
|
|
@@ -60,7 +60,7 @@ export declare const value: typeof literal;
|
|
|
60
60
|
* Numbers and strings with a numeric format succeed. Anything else fails.
|
|
61
61
|
* @public
|
|
62
62
|
*/
|
|
63
|
-
export declare const number: Converter<number,
|
|
63
|
+
export declare const number: Converter<number, unknown>;
|
|
64
64
|
/**
|
|
65
65
|
* A {@link Converter | Converter} which converts `unknown` to `boolean`.
|
|
66
66
|
* @remarks
|
|
@@ -68,7 +68,7 @@ export declare const number: Converter<number, undefined>;
|
|
|
68
68
|
* Anything else fails.
|
|
69
69
|
* @public
|
|
70
70
|
*/
|
|
71
|
-
export declare const boolean: Converter<boolean,
|
|
71
|
+
export declare const boolean: Converter<boolean, unknown>;
|
|
72
72
|
/**
|
|
73
73
|
* A {@link Converter | Converter} which converts an optional `string` value. Values of type
|
|
74
74
|
* `string` are returned. Anything else returns {@link Success | Success} with value `undefined`.
|
|
@@ -108,7 +108,7 @@ export declare function isA<T, TC = unknown>(description: string, guard: TypeGua
|
|
|
108
108
|
* Anything else returns {@link Success | Success} with value `undefined`.
|
|
109
109
|
* @public
|
|
110
110
|
*/
|
|
111
|
-
export declare const optionalNumber: Converter<number | undefined>;
|
|
111
|
+
export declare const optionalNumber: Converter<number | undefined, unknown>;
|
|
112
112
|
/**
|
|
113
113
|
* A {@link Converter | Converter} to convert an optional `boolean` value.
|
|
114
114
|
* @remarks
|
|
@@ -117,7 +117,7 @@ export declare const optionalNumber: Converter<number | undefined>;
|
|
|
117
117
|
* with value `undefined`.
|
|
118
118
|
* @public
|
|
119
119
|
*/
|
|
120
|
-
export declare const optionalBoolean: Converter<boolean | undefined>;
|
|
120
|
+
export declare const optionalBoolean: Converter<boolean | undefined, unknown>;
|
|
121
121
|
/**
|
|
122
122
|
* A helper function to create a {@link Converter | Converter} for polymorphic values.
|
|
123
123
|
* Returns a converter which invokes the wrapped converters in sequence, returning the
|
|
@@ -148,7 +148,7 @@ export declare function oneOf<T, TC = unknown>(converters: Array<Converter<T, TC
|
|
|
148
148
|
* @returns A {@link Converter | Converter} which returns an array of `<T>`.
|
|
149
149
|
* @public
|
|
150
150
|
*/
|
|
151
|
-
export declare function arrayOf<T, TC =
|
|
151
|
+
export declare function arrayOf<T, TC = unknown>(converter: Converter<T, TC> | Validator<T, TC>, onError?: OnError): Converter<T[], TC>;
|
|
152
152
|
/**
|
|
153
153
|
* {@link Converter | Converter} to convert an `unknown` to an array of `string`.
|
|
154
154
|
* @remarks
|
|
@@ -156,7 +156,7 @@ export declare function arrayOf<T, TC = undefined>(converter: Converter<T, TC> |
|
|
|
156
156
|
* of strings, returns {@link Failure | Failure} with an error message otherwise.
|
|
157
157
|
* @public
|
|
158
158
|
*/
|
|
159
|
-
export declare const stringArray: Converter<string[]>;
|
|
159
|
+
export declare const stringArray: Converter<string[], unknown>;
|
|
160
160
|
/**
|
|
161
161
|
* {@link Converter | Converter} to convert an `unknown` to an array of `number`.
|
|
162
162
|
* @remarks
|
|
@@ -164,14 +164,14 @@ export declare const stringArray: Converter<string[]>;
|
|
|
164
164
|
* of numbers, returns {@link Failure | Failure} with an error message otherwise.
|
|
165
165
|
* @public
|
|
166
166
|
*/
|
|
167
|
-
export declare const numberArray: Converter<number[]>;
|
|
167
|
+
export declare const numberArray: Converter<number[], unknown>;
|
|
168
168
|
/**
|
|
169
169
|
* Options for {@link Converters.(recordOf:3) | Converters.recordOf} and
|
|
170
170
|
* {@link Converters.(mapOf:3) | Converters.mapOf}
|
|
171
171
|
* helper functions.
|
|
172
172
|
* @public
|
|
173
173
|
*/
|
|
174
|
-
export interface KeyedConverterOptions<T extends string = string, TC =
|
|
174
|
+
export interface KeyedConverterOptions<T extends string = string, TC = unknown> {
|
|
175
175
|
/**
|
|
176
176
|
* if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
|
|
177
177
|
* cannot be converted. If `onError` is `'ignore'`, failing elements are silently ignored.
|
|
@@ -187,7 +187,7 @@ export interface KeyedConverterOptions<T extends string = string, TC = undefined
|
|
|
187
187
|
}
|
|
188
188
|
/**
|
|
189
189
|
* A helper function to create a {@link Converter | Converter} which converts the `string`-keyed
|
|
190
|
-
* properties using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to
|
|
190
|
+
* properties using a supplied {@link Converter | Converter<T, TC>} or {@link Validator | Validator<T>} to
|
|
191
191
|
* produce a `Record<string, T>`.
|
|
192
192
|
* @remarks
|
|
193
193
|
* The resulting converter fails conversion if any element cannot be converted.
|
|
@@ -197,10 +197,10 @@ export interface KeyedConverterOptions<T extends string = string, TC = undefined
|
|
|
197
197
|
* {@label WITH_DEFAULT}
|
|
198
198
|
* @public
|
|
199
199
|
*/
|
|
200
|
-
export declare function recordOf<T, TC =
|
|
200
|
+
export declare function recordOf<T, TC = unknown, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>): Converter<Record<TK, T>, TC>;
|
|
201
201
|
/**
|
|
202
202
|
* A helper function to create a {@link Converter | Converter} which converts the `string`-keyed properties
|
|
203
|
-
* using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce a
|
|
203
|
+
* using a supplied {@link Converter | Converter<T, TC>} or {@link Validator | Validator<T>} to produce a
|
|
204
204
|
* `Record<string, T>` and optionally specified handling of elements that cannot be converted.
|
|
205
205
|
* @remarks
|
|
206
206
|
* if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
|
|
@@ -211,10 +211,10 @@ export declare function recordOf<T, TC = undefined, TK extends string = string>(
|
|
|
211
211
|
* {@label WITH_ON_ERROR}
|
|
212
212
|
* @public
|
|
213
213
|
*/
|
|
214
|
-
export declare function recordOf<T, TC =
|
|
214
|
+
export declare function recordOf<T, TC = unknown, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>, onError: 'fail' | 'ignore'): Converter<Record<TK, T>, TC>;
|
|
215
215
|
/**
|
|
216
216
|
* A helper function to create a {@link Converter | Converter} or which converts the `string`-keyed properties
|
|
217
|
-
* using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce a
|
|
217
|
+
* using a supplied {@link Converter | Converter<T, TC>} or {@link Validator | Validator<T>} to produce a
|
|
218
218
|
* `Record<TK, T>`.
|
|
219
219
|
* @remarks
|
|
220
220
|
* If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
|
|
@@ -226,10 +226,10 @@ export declare function recordOf<T, TC = undefined, TK extends string = string>(
|
|
|
226
226
|
* {@label WITH_OPTIONS}
|
|
227
227
|
* @public
|
|
228
228
|
*/
|
|
229
|
-
export declare function recordOf<T, TC =
|
|
229
|
+
export declare function recordOf<T, TC = unknown, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>, options: KeyedConverterOptions<TK, TC>): Converter<Record<TK, T>, TC>;
|
|
230
230
|
/**
|
|
231
231
|
* A helper function to create a {@link Converter | Converter} which converts the `string`-keyed properties
|
|
232
|
-
* using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce a
|
|
232
|
+
* using a supplied {@link Converter | Converter<T, TC>} or {@link Validator | Validator<T>} to produce a
|
|
233
233
|
* `Map<string, T>`.
|
|
234
234
|
* @remarks
|
|
235
235
|
* The resulting converter fails conversion if any element cannot be converted.
|
|
@@ -239,10 +239,10 @@ export declare function recordOf<T, TC = undefined, TK extends string = string>(
|
|
|
239
239
|
* {@label WITH_DEFAULT}
|
|
240
240
|
* @public
|
|
241
241
|
*/
|
|
242
|
-
export declare function mapOf<T, TC =
|
|
242
|
+
export declare function mapOf<T, TC = unknown, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>): Converter<Map<TK, T>, TC>;
|
|
243
243
|
/**
|
|
244
244
|
* A helper function to create a {@link Converter | Converter} which converts the `string`-keyed properties
|
|
245
|
-
* using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce a
|
|
245
|
+
* using a supplied {@link Converter | Converter<T, TC>} or {@link Validator | Validator<T>} to produce a
|
|
246
246
|
* `Map<string, T>` and specified handling of elements that cannot be converted.
|
|
247
247
|
* @remarks
|
|
248
248
|
* if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
|
|
@@ -253,10 +253,10 @@ export declare function mapOf<T, TC = undefined, TK extends string = string>(con
|
|
|
253
253
|
* {@label WITH_ON_ERROR}
|
|
254
254
|
* @public
|
|
255
255
|
*/
|
|
256
|
-
export declare function mapOf<T, TC =
|
|
256
|
+
export declare function mapOf<T, TC = unknown, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>, onError: 'fail' | 'ignore'): Converter<Map<TK, T>, TC>;
|
|
257
257
|
/**
|
|
258
258
|
* A helper function to create a {@link Converter | Converter} which converts the `string`-keyed properties
|
|
259
|
-
* using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce
|
|
259
|
+
* using a supplied {@link Converter | Converter<T, TC>} or {@link Validator | Validator<T>} to produce
|
|
260
260
|
* a `Map<TK,T>`.
|
|
261
261
|
* @remarks
|
|
262
262
|
* If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
|
|
@@ -269,7 +269,7 @@ export declare function mapOf<T, TC = undefined, TK extends string = string>(con
|
|
|
269
269
|
* {@label WITH_OPTIONS}
|
|
270
270
|
* @public
|
|
271
271
|
*/
|
|
272
|
-
export declare function mapOf<T, TC =
|
|
272
|
+
export declare function mapOf<T, TC = unknown, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>, options: KeyedConverterOptions<TK, TC>): Converter<Map<TK, T>, TC>;
|
|
273
273
|
/**
|
|
274
274
|
* Helper function to create a {@link Converter | Converter} which validates that a supplied value is
|
|
275
275
|
* of a type validated by a supplied validator function and returns it.
|
|
@@ -279,10 +279,10 @@ export declare function mapOf<T, TC = undefined, TK extends string = string>(con
|
|
|
279
279
|
* information otherwise.
|
|
280
280
|
* @param validator - A validator function to determine if the converted value is valid.
|
|
281
281
|
* @param description - A description of the validated type for use in error messages.
|
|
282
|
-
* @returns A new {@link Converter | Converter<T>} which applies the supplied validation.
|
|
282
|
+
* @returns A new {@link Converter | Converter<T, TC>} which applies the supplied validation.
|
|
283
283
|
* @public
|
|
284
284
|
*/
|
|
285
|
-
export declare function validateWith<T, TC =
|
|
285
|
+
export declare function validateWith<T, TC = unknown>(validator: (from: unknown) => from is T, description?: string): Converter<T, TC>;
|
|
286
286
|
/**
|
|
287
287
|
* A helper function to create a {@link Converter | Converter} which extracts and converts an element from an array.
|
|
288
288
|
* @remarks
|
|
@@ -290,10 +290,10 @@ export declare function validateWith<T, TC = undefined>(validator: (from: unknow
|
|
|
290
290
|
* in the supplied array and can be converted. Returns {@link Failure | Failure} with an error message otherwise.
|
|
291
291
|
* @param index - The index of the element to be extracted.
|
|
292
292
|
* @param converter - A {@link Converter | Converter} or {@link Validator | Validator} for the extracted element.
|
|
293
|
-
* @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
|
|
293
|
+
* @returns A {@link Converter | Converter<T, TC>} which extracts the specified element from an array.
|
|
294
294
|
* @public
|
|
295
295
|
*/
|
|
296
|
-
export declare function element<T, TC =
|
|
296
|
+
export declare function element<T, TC = unknown>(index: number, converter: Converter<T, TC> | Validator<T, TC>): Converter<T, TC>;
|
|
297
297
|
/**
|
|
298
298
|
* A helper function to create a {@link Converter | Converter} which extracts and converts an optional element from an array.
|
|
299
299
|
* @remarks
|
|
@@ -303,10 +303,10 @@ export declare function element<T, TC = undefined>(index: number, converter: Con
|
|
|
303
303
|
* is not an array, if the requested index is negative, or if the element cannot be converted.
|
|
304
304
|
* @param index - The index of the element to be extracted.
|
|
305
305
|
* @param converter - A {@link Converter | Converter} or {@link Validator | Validator} used for the extracted element.
|
|
306
|
-
* @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
|
|
306
|
+
* @returns A {@link Converter | Converter<T, TC>} which extracts the specified element from an array.
|
|
307
307
|
* @public
|
|
308
308
|
*/
|
|
309
|
-
export declare function optionalElement<T, TC =
|
|
309
|
+
export declare function optionalElement<T, TC = unknown>(index: number, converter: Converter<T, TC> | Validator<T, TC>): Converter<T | undefined, TC>;
|
|
310
310
|
/**
|
|
311
311
|
* A helper function to create a {@link Converter | Converter} which extracts and convert a property specified
|
|
312
312
|
* by name from an object.
|
|
@@ -319,7 +319,7 @@ export declare function optionalElement<T, TC = undefined>(index: number, conver
|
|
|
319
319
|
* field.
|
|
320
320
|
* @public
|
|
321
321
|
*/
|
|
322
|
-
export declare function field<T, TC =
|
|
322
|
+
export declare function field<T, TC = unknown>(name: string, converter: Converter<T, TC> | Validator<T, TC>): Converter<T, TC>;
|
|
323
323
|
/**
|
|
324
324
|
* A helper function to create a {@link Converter | Converter} which extracts and convert a property specified
|
|
325
325
|
* by name from an object.
|
|
@@ -332,10 +332,10 @@ export declare function field<T, TC = undefined>(name: string, converter: Conver
|
|
|
332
332
|
* @param converter - {@link Converter | Converter} or {@link Validator | Validator} to use for the extracted field.
|
|
333
333
|
* @public
|
|
334
334
|
*/
|
|
335
|
-
export declare function optionalField<T, TC =
|
|
335
|
+
export declare function optionalField<T, TC = unknown>(name: string, converter: Converter<T, TC> | Validator<T, TC>): Converter<T | undefined, TC>;
|
|
336
336
|
/**
|
|
337
|
-
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T>} which converts an object
|
|
338
|
-
* without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
|
|
337
|
+
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T, TC>} which converts an object
|
|
338
|
+
* without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T, TC>} and an optional
|
|
339
339
|
* {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} to further refine conversion behavior.
|
|
340
340
|
* @remarks
|
|
341
341
|
* By default, if all of the requested fields exist and can be converted, returns {@link Success | Success}
|
|
@@ -345,7 +345,7 @@ export declare function optionalField<T, TC = undefined>(name: string, converter
|
|
|
345
345
|
*
|
|
346
346
|
* Fields that succeed but convert to undefined are omitted from the result object but do not
|
|
347
347
|
* fail the conversion.
|
|
348
|
-
* @param properties - An {@link Conversion.FieldConverters | FieldConverters<T>} defining the shape of the
|
|
348
|
+
* @param properties - An {@link Conversion.FieldConverters | FieldConverters<T, TC>} defining the shape of the
|
|
349
349
|
* source object and {@link Converter | converters} to be applied to each properties.
|
|
350
350
|
* @param options - An {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} containing options
|
|
351
351
|
* for the object converter.
|
|
@@ -353,10 +353,10 @@ export declare function optionalField<T, TC = undefined>(name: string, converter
|
|
|
353
353
|
* {@label WITH_OPTIONS}
|
|
354
354
|
* @public
|
|
355
355
|
*/
|
|
356
|
-
export declare function object<T>(properties: FieldConverters<T>, options?: ObjectConverterOptions<T>): ObjectConverter<T>;
|
|
356
|
+
export declare function object<T, TC = unknown>(properties: FieldConverters<T, TC>, options?: ObjectConverterOptions<T>): ObjectConverter<T, TC>;
|
|
357
357
|
/**
|
|
358
|
-
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T>} which converts an object
|
|
359
|
-
* without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and a set of
|
|
358
|
+
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T, TC>} which converts an object
|
|
359
|
+
* without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T, TC>} and a set of
|
|
360
360
|
* optional properties.
|
|
361
361
|
* @remarks
|
|
362
362
|
* By default, if all of the requested fields exist and can be converted, returns {@link Success | Success}
|
|
@@ -366,7 +366,7 @@ export declare function object<T>(properties: FieldConverters<T>, options?: Obje
|
|
|
366
366
|
*
|
|
367
367
|
* Fields that succeed but convert to undefined are omitted from the result object but do not
|
|
368
368
|
* fail the conversion.
|
|
369
|
-
* @param properties - An {@link Conversion.FieldConverters | FieldConverters<T>} defining the shape of the
|
|
369
|
+
* @param properties - An {@link Conversion.FieldConverters | FieldConverters<T, TC>} defining the shape of the
|
|
370
370
|
* source object and {@link Converter | converters} to be applied to each properties.
|
|
371
371
|
* @param optional - An array of `(keyof T)` listing the keys to be considered optional.
|
|
372
372
|
* {@label WITH_KEYS}
|
|
@@ -374,7 +374,7 @@ export declare function object<T>(properties: FieldConverters<T>, options?: Obje
|
|
|
374
374
|
* @public
|
|
375
375
|
* @deprecated Use {@link Converters.(object:1) | Converters.object(fields, options)} instead.
|
|
376
376
|
*/
|
|
377
|
-
export declare function object<T>(properties: FieldConverters<T>, optional: (keyof T)[]): ObjectConverter<T>;
|
|
377
|
+
export declare function object<T, TC = unknown>(properties: FieldConverters<T, TC>, optional: (keyof T)[]): ObjectConverter<T, TC>;
|
|
378
378
|
/**
|
|
379
379
|
* Options for the {@link Converters.(strictObject:1)} helper function.
|
|
380
380
|
* @public
|
|
@@ -382,7 +382,7 @@ export declare function object<T>(properties: FieldConverters<T>, optional: (key
|
|
|
382
382
|
export type StrictObjectConverterOptions<T> = Omit<ObjectConverterOptions<T>, 'strict'>;
|
|
383
383
|
/**
|
|
384
384
|
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter} which converts an object
|
|
385
|
-
* without changing shape, a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
|
|
385
|
+
* without changing shape, a {@link Conversion.FieldConverters | FieldConverters<T, TC>} and an optional
|
|
386
386
|
* {@link Converters.StrictObjectConverterOptions | StrictObjectConverterOptions<T>} to further refine
|
|
387
387
|
* conversion behavior.
|
|
388
388
|
*
|
|
@@ -398,10 +398,10 @@ export type StrictObjectConverterOptions<T> = Omit<ObjectConverterOptions<T>, 's
|
|
|
398
398
|
* {@label WITH_OPTIONS}
|
|
399
399
|
* @public
|
|
400
400
|
*/
|
|
401
|
-
export declare function strictObject<T>(properties: FieldConverters<T>, options?: StrictObjectConverterOptions<T>): ObjectConverter<T>;
|
|
401
|
+
export declare function strictObject<T, TC = unknown>(properties: FieldConverters<T, TC>, options?: StrictObjectConverterOptions<T>): ObjectConverter<T, TC>;
|
|
402
402
|
/**
|
|
403
403
|
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter} which converts an object
|
|
404
|
-
* without changing shape, a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
|
|
404
|
+
* without changing shape, a {@link Conversion.FieldConverters | FieldConverters<T, TC>} and an optional
|
|
405
405
|
* {@link Converters.StrictObjectConverterOptions | StrictObjectConverterOptions<T>} to further refine
|
|
406
406
|
* conversion behavior.
|
|
407
407
|
*
|
|
@@ -418,7 +418,7 @@ export declare function strictObject<T>(properties: FieldConverters<T>, options?
|
|
|
418
418
|
* @deprecated Use {@link Converters.(strictObject:1) | Converters.strictObject(options)} instead.
|
|
419
419
|
* @public
|
|
420
420
|
*/
|
|
421
|
-
export declare function strictObject<T>(properties: FieldConverters<T>, optional: (keyof T)[]): ObjectConverter<T>;
|
|
421
|
+
export declare function strictObject<T, TC = unknown>(properties: FieldConverters<T, TC>, optional: (keyof T)[]): ObjectConverter<T, TC>;
|
|
422
422
|
/**
|
|
423
423
|
* A string-keyed `Record<string, Converter>` which maps specific {@link Converter | converters} or
|
|
424
424
|
* {@link Validator | Validators} to the value of a discriminator property.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/packlets/conversion/converters.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB;;;;GAIG;AACH,eAAO,MAAM,MAAM,EAAE,eAAuC,CAAC;AAE7D;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAMjE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/packlets/conversion/converters.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,M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AO,EACvD,iBAAiB,EAAE,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,EACrD,OAAO,CAAC,EAAE,sBAAsB,CAAC,IAAI,CAAC,GACrC,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC,CA2CtB"}
|
|
@@ -21,7 +21,27 @@
|
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.
|
|
24
|
+
exports.numberArray = exports.stringArray = exports.optionalBoolean = exports.optionalNumber = exports.optionalString = exports.boolean = exports.number = exports.value = exports.string = void 0;
|
|
25
|
+
exports.enumeratedValue = enumeratedValue;
|
|
26
|
+
exports.mappedEnumeratedValue = mappedEnumeratedValue;
|
|
27
|
+
exports.literal = literal;
|
|
28
|
+
exports.delimitedString = delimitedString;
|
|
29
|
+
exports.validated = validated;
|
|
30
|
+
exports.isA = isA;
|
|
31
|
+
exports.oneOf = oneOf;
|
|
32
|
+
exports.arrayOf = arrayOf;
|
|
33
|
+
exports.recordOf = recordOf;
|
|
34
|
+
exports.mapOf = mapOf;
|
|
35
|
+
exports.validateWith = validateWith;
|
|
36
|
+
exports.element = element;
|
|
37
|
+
exports.optionalElement = optionalElement;
|
|
38
|
+
exports.field = field;
|
|
39
|
+
exports.optionalField = optionalField;
|
|
40
|
+
exports.object = object;
|
|
41
|
+
exports.strictObject = strictObject;
|
|
42
|
+
exports.discriminatedObject = discriminatedObject;
|
|
43
|
+
exports.transform = transform;
|
|
44
|
+
exports.transformObject = transformObject;
|
|
25
45
|
const base_1 = require("../base");
|
|
26
46
|
const baseConverter_1 = require("./baseConverter");
|
|
27
47
|
const objectConverter_1 = require("./objectConverter");
|
|
@@ -49,7 +69,6 @@ function enumeratedValue(values) {
|
|
|
49
69
|
return index >= 0 ? (0, base_1.succeed)(v[index]) : (0, base_1.fail)(`Invalid enumerated value ${JSON.stringify(from)}`);
|
|
50
70
|
});
|
|
51
71
|
}
|
|
52
|
-
exports.enumeratedValue = enumeratedValue;
|
|
53
72
|
/**
|
|
54
73
|
* Helper function to create a {@link Converter | Converter} which converts `unknown` to one of a set of supplied enumerated
|
|
55
74
|
* values, mapping any of multiple supplied values to the enumeration.
|
|
@@ -75,7 +94,6 @@ function mappedEnumeratedValue(map, message) {
|
|
|
75
94
|
: `Cannot map '${JSON.stringify(from)}' to a supported value`);
|
|
76
95
|
});
|
|
77
96
|
}
|
|
78
|
-
exports.mappedEnumeratedValue = mappedEnumeratedValue;
|
|
79
97
|
/**
|
|
80
98
|
* Helper function to create a {@link Converter | Converter} which converts `unknown` to some supplied literal value. Succeeds with
|
|
81
99
|
* the supplied value if an identity comparison succeeds, fails otherwise.
|
|
@@ -90,7 +108,6 @@ function literal(value) {
|
|
|
90
108
|
: (0, base_1.fail)(`${JSON.stringify(from)}: does not match ${JSON.stringify(value)}`);
|
|
91
109
|
});
|
|
92
110
|
}
|
|
93
|
-
exports.literal = literal;
|
|
94
111
|
/**
|
|
95
112
|
* Deprecated alias for @see literal
|
|
96
113
|
* @param value - The value to be compared.
|
|
@@ -161,7 +178,6 @@ function delimitedString(delimiter, options = 'filtered') {
|
|
|
161
178
|
return (0, base_1.fail)(result.message);
|
|
162
179
|
});
|
|
163
180
|
}
|
|
164
|
-
exports.delimitedString = delimitedString;
|
|
165
181
|
/**
|
|
166
182
|
* Helper function to create a {@link Converter | Converter} from any {@link Validation.Validator}
|
|
167
183
|
* @param validator - the validator to be wrapped
|
|
@@ -173,7 +189,6 @@ function validated(validator) {
|
|
|
173
189
|
return validator.validate(from, context);
|
|
174
190
|
});
|
|
175
191
|
}
|
|
176
|
-
exports.validated = validated;
|
|
177
192
|
/**
|
|
178
193
|
* Helper function to create a {@link Converter | Converter} from a supplied type guard function.
|
|
179
194
|
* @param description - a description of the thing to be validated for use in error messages
|
|
@@ -190,7 +205,6 @@ function isA(description, guard) {
|
|
|
190
205
|
return (0, base_1.fail)(`invalid ${description} (${JSON.stringify(from)})`);
|
|
191
206
|
});
|
|
192
207
|
}
|
|
193
|
-
exports.isA = isA;
|
|
194
208
|
/**
|
|
195
209
|
* A {@link Converter | Converter} which converts an optional `number` value.
|
|
196
210
|
* @remarks
|
|
@@ -244,7 +258,6 @@ function oneOf(converters, onError = 'ignoreErrors') {
|
|
|
244
258
|
return (0, base_1.fail)(`No matching converter for ${JSON.stringify(from)}: ${errors.join('\n')}`);
|
|
245
259
|
});
|
|
246
260
|
}
|
|
247
|
-
exports.oneOf = oneOf;
|
|
248
261
|
/**
|
|
249
262
|
* A helper function to create a {@link Converter | Converter} which converts `unknown` to an array of `<T>`.
|
|
250
263
|
* @remarks
|
|
@@ -275,7 +288,6 @@ function arrayOf(converter, onError = 'failOnError') {
|
|
|
275
288
|
return errors.length === 0 || onError === 'ignoreErrors' ? (0, base_1.succeed)(successes) : (0, base_1.fail)(errors.join('\n'));
|
|
276
289
|
});
|
|
277
290
|
}
|
|
278
|
-
exports.arrayOf = arrayOf;
|
|
279
291
|
/**
|
|
280
292
|
* {@link Converter | Converter} to convert an `unknown` to an array of `string`.
|
|
281
293
|
* @remarks
|
|
@@ -293,9 +305,9 @@ exports.stringArray = arrayOf(exports.string);
|
|
|
293
305
|
*/
|
|
294
306
|
exports.numberArray = arrayOf(exports.number);
|
|
295
307
|
/**
|
|
296
|
-
* Concrete implementation of {@link Converters.(recordOf:1) | Converters.recordOf(Converter<T>)},
|
|
297
|
-
* {@link Converters.(recordOf:2) | Converters.recordOf(Converter<T>, 'fail' or 'ignore')}, and
|
|
298
|
-
* {@link Converters.(recordOf:3) | Converters.recordOf(Converter<T>, KeyedConverterOptions)}.
|
|
308
|
+
* Concrete implementation of {@link Converters.(recordOf:1) | Converters.recordOf(Converter<T, TC>)},
|
|
309
|
+
* {@link Converters.(recordOf:2) | Converters.recordOf(Converter<T, TC>, 'fail' or 'ignore')}, and
|
|
310
|
+
* {@link Converters.(recordOf:3) | Converters.recordOf(Converter<T, TC>, KeyedConverterOptions)}.
|
|
299
311
|
* @internal
|
|
300
312
|
*/
|
|
301
313
|
function recordOf(converter, option = 'fail') {
|
|
@@ -326,11 +338,10 @@ function recordOf(converter, option = 'fail') {
|
|
|
326
338
|
return errors.length === 0 || options.onError === 'ignore' ? (0, base_1.succeed)(record) : (0, base_1.fail)(errors.join('\n'));
|
|
327
339
|
});
|
|
328
340
|
}
|
|
329
|
-
exports.recordOf = recordOf;
|
|
330
341
|
/**
|
|
331
|
-
* Concrete implementation of {@link Converters.(mapOf:1) | Converters.mapOf(Converter<T>)},
|
|
332
|
-
* {@link Converters.(mapOf:2) | Converters.mapOf(Converter<T>, 'fail' or 'ignore')}, and
|
|
333
|
-
* {@link Converters.(mapOf:3) | Converters.mapOf(Converter<T>, KeyedConverterOptions)}.
|
|
342
|
+
* Concrete implementation of {@link Converters.(mapOf:1) | Converters.mapOf(Converter<T, TC>)},
|
|
343
|
+
* {@link Converters.(mapOf:2) | Converters.mapOf(Converter<T, TC>, 'fail' or 'ignore')}, and
|
|
344
|
+
* {@link Converters.(mapOf:3) | Converters.mapOf(Converter<T, TC>, KeyedConverterOptions)}.
|
|
334
345
|
* @internal
|
|
335
346
|
*/
|
|
336
347
|
function mapOf(converter, option = 'fail') {
|
|
@@ -361,7 +372,6 @@ function mapOf(converter, option = 'fail') {
|
|
|
361
372
|
return errors.length === 0 || options.onError === 'ignore' ? (0, base_1.succeed)(map) : (0, base_1.fail)(errors.join('\n'));
|
|
362
373
|
});
|
|
363
374
|
}
|
|
364
|
-
exports.mapOf = mapOf;
|
|
365
375
|
/**
|
|
366
376
|
* Helper function to create a {@link Converter | Converter} which validates that a supplied value is
|
|
367
377
|
* of a type validated by a supplied validator function and returns it.
|
|
@@ -371,7 +381,7 @@ exports.mapOf = mapOf;
|
|
|
371
381
|
* information otherwise.
|
|
372
382
|
* @param validator - A validator function to determine if the converted value is valid.
|
|
373
383
|
* @param description - A description of the validated type for use in error messages.
|
|
374
|
-
* @returns A new {@link Converter | Converter<T>} which applies the supplied validation.
|
|
384
|
+
* @returns A new {@link Converter | Converter<T, TC>} which applies the supplied validation.
|
|
375
385
|
* @public
|
|
376
386
|
*/
|
|
377
387
|
function validateWith(validator, description) {
|
|
@@ -382,7 +392,6 @@ function validateWith(validator, description) {
|
|
|
382
392
|
return (0, base_1.fail)(`${JSON.stringify(from)}: invalid ${description !== null && description !== void 0 ? description : 'value'}`);
|
|
383
393
|
});
|
|
384
394
|
}
|
|
385
|
-
exports.validateWith = validateWith;
|
|
386
395
|
/**
|
|
387
396
|
* A helper function to create a {@link Converter | Converter} which extracts and converts an element from an array.
|
|
388
397
|
* @remarks
|
|
@@ -390,7 +399,7 @@ exports.validateWith = validateWith;
|
|
|
390
399
|
* in the supplied array and can be converted. Returns {@link Failure | Failure} with an error message otherwise.
|
|
391
400
|
* @param index - The index of the element to be extracted.
|
|
392
401
|
* @param converter - A {@link Converter | Converter} or {@link Validator | Validator} for the extracted element.
|
|
393
|
-
* @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
|
|
402
|
+
* @returns A {@link Converter | Converter<T, TC>} which extracts the specified element from an array.
|
|
394
403
|
* @public
|
|
395
404
|
*/
|
|
396
405
|
function element(index, converter) {
|
|
@@ -407,7 +416,6 @@ function element(index, converter) {
|
|
|
407
416
|
return converter.convert(from[index], context);
|
|
408
417
|
});
|
|
409
418
|
}
|
|
410
|
-
exports.element = element;
|
|
411
419
|
/**
|
|
412
420
|
* A helper function to create a {@link Converter | Converter} which extracts and converts an optional element from an array.
|
|
413
421
|
* @remarks
|
|
@@ -417,7 +425,7 @@ exports.element = element;
|
|
|
417
425
|
* is not an array, if the requested index is negative, or if the element cannot be converted.
|
|
418
426
|
* @param index - The index of the element to be extracted.
|
|
419
427
|
* @param converter - A {@link Converter | Converter} or {@link Validator | Validator} used for the extracted element.
|
|
420
|
-
* @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
|
|
428
|
+
* @returns A {@link Converter | Converter<T, TC>} which extracts the specified element from an array.
|
|
421
429
|
* @public
|
|
422
430
|
*/
|
|
423
431
|
function optionalElement(index, converter) {
|
|
@@ -434,7 +442,6 @@ function optionalElement(index, converter) {
|
|
|
434
442
|
return converter.convert(from[index], context);
|
|
435
443
|
});
|
|
436
444
|
}
|
|
437
|
-
exports.optionalElement = optionalElement;
|
|
438
445
|
/**
|
|
439
446
|
* A helper function to create a {@link Converter | Converter} which extracts and convert a property specified
|
|
440
447
|
* by name from an object.
|
|
@@ -460,7 +467,6 @@ function field(name, converter) {
|
|
|
460
467
|
return (0, base_1.fail)(`Cannot convert field "${name}" from non-object ${JSON.stringify(from)}`);
|
|
461
468
|
});
|
|
462
469
|
}
|
|
463
|
-
exports.field = field;
|
|
464
470
|
/**
|
|
465
471
|
* A helper function to create a {@link Converter | Converter} which extracts and convert a property specified
|
|
466
472
|
* by name from an object.
|
|
@@ -492,7 +498,6 @@ function optionalField(name, converter) {
|
|
|
492
498
|
return (0, base_1.fail)(`Cannot convert field "${name}" from non-object ${JSON.stringify(from)}`);
|
|
493
499
|
}, undefined, { isOptional: true });
|
|
494
500
|
}
|
|
495
|
-
exports.optionalField = optionalField;
|
|
496
501
|
/**
|
|
497
502
|
* Concrete implementation of {@link Converters.(object:1) | Converters.object(fields, options)}
|
|
498
503
|
* and {@link Converters.(object:2) | Converters.objects(fields, optionalKeys)}.
|
|
@@ -501,7 +506,6 @@ exports.optionalField = optionalField;
|
|
|
501
506
|
function object(properties, options) {
|
|
502
507
|
return new objectConverter_1.ObjectConverter(properties, options);
|
|
503
508
|
}
|
|
504
|
-
exports.object = object;
|
|
505
509
|
/**
|
|
506
510
|
* Concrete implementation for {@link Converters.(strictObject:1) | Converters.strictObject(fields, options)}
|
|
507
511
|
* and {@link Converters.strictObject | Converters.strictObject(fields, optional)}.
|
|
@@ -511,7 +515,6 @@ function strictObject(properties, opt) {
|
|
|
511
515
|
const options = opt && Array.isArray(opt) ? { strict: true, optionalFields: opt } : Object.assign(Object.assign({}, (opt !== null && opt !== void 0 ? opt : {})), { strict: true });
|
|
512
516
|
return new objectConverter_1.ObjectConverter(properties, options);
|
|
513
517
|
}
|
|
514
|
-
exports.strictObject = strictObject;
|
|
515
518
|
/**
|
|
516
519
|
* Helper to create a {@link Converter | Converter} which converts a discriminated object without changing shape.
|
|
517
520
|
* @remarks
|
|
@@ -544,7 +547,6 @@ function discriminatedObject(discriminatorProp, converters) {
|
|
|
544
547
|
return converter.convert(from);
|
|
545
548
|
});
|
|
546
549
|
}
|
|
547
|
-
exports.discriminatedObject = discriminatedObject;
|
|
548
550
|
/**
|
|
549
551
|
* Helper to create a {@link Converter | Converter} which converts a source object to a new object with a
|
|
550
552
|
* different shape.
|
|
@@ -584,7 +586,6 @@ function transform(properties) {
|
|
|
584
586
|
return errors.length === 0 ? (0, base_1.succeed)(converted) : (0, base_1.fail)(errors.join('\n'));
|
|
585
587
|
});
|
|
586
588
|
}
|
|
587
|
-
exports.transform = transform;
|
|
588
589
|
/**
|
|
589
590
|
* Helper to create a strongly-typed {@link Converter | Converter} which converts a source object to a
|
|
590
591
|
* new object with a different shape.
|
|
@@ -648,5 +649,4 @@ function transformObject(destinationFields, options) {
|
|
|
648
649
|
: (0, base_1.fail)((options === null || options === void 0 ? void 0 : options.description) ? `${options.description}:\n ${errors.join('\n ')}` : errors.join('\n'));
|
|
649
650
|
});
|
|
650
651
|
}
|
|
651
|
-
exports.transformObject = transformObject;
|
|
652
652
|
//# sourceMappingURL=converters.js.map
|