import { Result } from '../base'; import { Validator } from '../validation'; import { BaseConverter } from './baseConverter'; import { Converter } from './converter'; /** * Options for an {@link Conversion.ObjectConverter | ObjectConverter}. * @public */ export interface ObjectConverterOptions { /** * If present, lists optional fields. Missing non-optional fields cause an error. */ optionalFields?: (keyof T)[]; /** * If true, unrecognized fields yield an error. If false or undefined (default), * unrecognized fields are ignored. */ strict?: boolean; /** * Optional description to be included in error messages. */ description?: string; /** * Optional modifier to apply to the converter. */ modifier?: 'partial' | 'required'; } /** * Per-property converters or validators for each of the properties in type T. * @remarks * Used to construct a {@link Conversion.ObjectConverter | ObjectConverter} * @public */ export type FieldConverters = { [key in keyof T]: Converter | Validator; }; /** * A {@link Converter | Converter} which converts an object of type `` without changing shape, given * a {@link Conversion.FieldConverters | FieldConverters} for the fields in the object. * @remarks * By default, if all of the required fields exist and can be converted, returns a new object with * the converted values under the original key names. If any required fields do not exist or cannot * be converted, the entire conversion fails. See {@link Conversion.ObjectConverterOptions | ObjectConverterOptions} * for other conversion options. * @public */ export declare class ObjectConverter extends BaseConverter { /** * Fields converted by this {@link Conversion.ObjectConverter | ObjectConverter}. */ readonly fields: FieldConverters; /** * Options used to initialize this {@link Conversion.ObjectConverter | ObjectConverter}. */ readonly options: ObjectConverterOptions; /** * Constructs a new {@link Conversion.ObjectConverter | ObjectConverter} using options * supplied in a {@link Conversion.ObjectConverterOptions | ObjectConverterOptions}. * @param fields - A {@link Conversion.FieldConverters | FieldConverters} containing * a {@link Converter} for each field * @param options - An optional @see ObjectConverterOptions to configure the conversion * {@label WITH_OPTIONS} */ constructor(fields: FieldConverters, options?: ObjectConverterOptions); /** * Constructs a new {@link Conversion.ObjectConverter | ObjectConverter} with optional * properties specified as an array of `keyof T`. * @param fields - A {@link Conversion.FieldConverters | FieldConverters} containing * a {@link Converter} for each field. * @param optional - An array of `keyof T` listing fields that are not required. * {@label WITH_KEYS} * @deprecated Use {@link Conversion.Converter.optional | .optional()} on the individual * fields, or pass {@link Conversion.ObjectConverterOptions | ObjectConverterOptions} to the constructor. */ constructor(fields: FieldConverters, optional?: (keyof T)[]); /** * Converts the supplied object using the {@link Conversion.ObjectConverter | ObjectConverter} * with all fields optional. * @param from - The object to be converted. * @param context - An optional context object passed to the field converters. * @returns A {@link Result} containing the converted object or an error message. */ convertPartial(from: unknown, context?: TC): Result>; /** * Converts the supplied object using the {@link Conversion.ObjectConverter | ObjectConverter} * with all fields required. * @param from - The object to be converted. * @param context - An optional context object passed to the field converters. * @returns A {@link Result} containing the converted object or an error message. */ convertRequired(from: unknown, context?: TC): Result>; /** * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with * all properties optional. * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source properties. * {@label WITHOUT_OPTIONS} */ partial(): ObjectConverter, TC>; /** * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with * new optional properties as specified by a supplied {@link Conversion.ObjectConverterOptions | ObjectConverterOptions}. * @param options - The {@link Conversion.ObjectConverterOptions | options} to be applied to the new * converter. * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source properties. * {@label WITH_OPTIONS} * @deprecated Pass just the keys to be made optional. */ partial(options: ObjectConverterOptions): ObjectConverter, TC>; /** * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with * new optional properties as specified by a supplied array of `keyof T`. * @param optional - The keys of the source object properties to be made optional. * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source * properties. * {@label WITH_KEYS} */ partial(optional: (keyof T)[]): ObjectConverter, TC>; /** * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with * new optional properties as specified by a supplied array of `keyof T`. * @param addOptionalProperties - The keys to be made optional. * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source * properties. */ addPartial(addOptionalProperties: (keyof T)[]): ObjectConverter, TC>; /** * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with * all properties required. * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional required source properties. */ required(): ObjectConverter, TC>; private static _convert; } //# sourceMappingURL=objectConverter.d.ts.map