/** * Schema defines a type and its validation and mapping functions. */ export interface Schema { type: () => string; validateBeforeMap: (value: unknown, ctxt: SchemaContextCreator) => SchemaValidationError[]; validateBeforeUnmap: (value: unknown, ctxt: SchemaContextCreator) => SchemaValidationError[]; map: (value: S, ctxt: SchemaContextCreator) => T; unmap: (value: T, ctxt: SchemaContextCreator) => S; validateBeforeMapXml: (value: unknown, ctxt: SchemaContextCreator) => SchemaValidationError[]; mapXml: (value: any, ctxt: SchemaContextCreator) => T; unmapXml: (value: T, ctxt: SchemaContextCreator) => any; } /** * Type for a Schema */ export type SchemaType> = ReturnType; /** * Mapped type for the Schema */ export type SchemaMappedType> = ReturnType; /** * Schema context when validating or mapping */ export interface SchemaContext { readonly value: unknown; readonly type: string; readonly branch: unknown[]; readonly path: Array; strictValidation?: boolean; } /** * SchemaContextCreator provides schema context as well as utility methods for * interacting with the context from inside the validation or mapping methods. */ export interface SchemaContextCreator extends SchemaContext { createChild>(key: any, value: T, childSchema: S): SchemaContextCreator; flatmapChildren, R>(items: Array<[K, T]>, itemSchema: S, mapper: (item: [K, T], childCtxt: SchemaContextCreator) => R[]): R[]; mapChildren, R>(items: Array<[K, T]>, itemSchema: S, mapper: (item: [K, T], childCtxt: SchemaContextCreator) => R): R[]; fail(message?: string): SchemaValidationError[]; } /** * Validation result after running validation. */ export type ValidationResult = { errors: false; result: T; } | { errors: SchemaValidationError[]; }; /** * Schema validation error */ export interface SchemaValidationError extends SchemaContext { readonly message?: string; } /** * Check if the value is valid for the given schema. * * @param value Value to validate * @param schema Schema for type */ export declare function isMappedValueValidForSchema(value: unknown, schema: Schema): value is T; /** * Validate and map the value using the given schema. * * This method should be used after JSON deserialization. * * @param value Value to map * @param schema Schema for type */ export declare function validateAndMap>(value: SchemaMappedType, schema: T): ValidationResult>; /** * Valudate and unmap the value using the given schema. * * This method should be used before JSON serializatin. * * @param value Value to unmap * @param schema Schema for type */ export declare function validateAndUnmap>(value: SchemaType, schema: T): ValidationResult>; /** * Validate and map the value using the given schema. * * This method should be used after XML deserialization. * * @param value Value to map * @param schema Schema for type */ export declare function validateAndMapXml>(value: unknown, schema: T): ValidationResult>; /** * Valudate and unmap the value using the given schema. * * This method should be used before XML serialization. * * @param value Value to unmap * @param schema Schema for type */ export declare function validateAndUnmapXml>(value: SchemaType, schema: T): ValidationResult; //# sourceMappingURL=schema.d.ts.map