import { ValidationContext } from '../rules/BaseRule'; import { AsyncRuleBooleanMethod, AsyncRuleMethodSchemaError, RuleBooleanMethod, RuleMethodSchemaError } from '../rules/Rule'; import { WhenConfig } from '../rules/WhenRule'; import { OnlyOnTouch } from '../types/FormKey'; import { ObjectPropertiesSchema } from '../types/SchemaMap'; import { CompileSchemaConfig, Context } from '../types/SchemaTypes'; import { SchemaError } from '../types/types'; import { MessageType } from '../utils/messages'; import { Definitions } from './Definitions'; export type OldTestMethodConfig any> = { /** * When is is "true" errors shows */ message: string | ((messages: MessageType) => string); /** * @deprecated When test is "false" errors shows */ test: Method; /** * Servers to make validation unique, otherwise method cannot be changed */ name?: string; }; export type TestMethodConfig any> = { /** * When is is "true" errors shows */ is: Method; message: string | ((messages: MessageType) => string); /** * Servers to make validation unique, otherwise method cannot be changed */ name?: string; /** * @deprecated When test is "false" errors shows */ test?: Method; }; export declare abstract class Schema { input: Input; final: Final; protected isAsync: boolean; protected def: Definitions; protected message: string; protected abstract rule: RuleBooleanMethod; constructor(message?: string, def?: Definitions); protected clone(): any; protected whenClone(): any; protected compileNormalRules(context: Context): Function[]; protected compileWhenSchema(context: Context): (value: any, validationContext: ValidationContext) => void; protected compileNormalSchema({ context, srcCode }: CompileSchemaConfig): (value: any, validationContext: ValidationContext) => void; protected getRequiredStringCondition: (value: any) => boolean; protected getNotRequiredStringCondition: (value: any) => boolean; private createCondition; private createErrorCondition; protected getMandatoryRules(schema: Schema, fnSrcCode: (value: any, validationContext: ValidationContext) => void): (value: any, validationContext: ValidationContext) => void; protected compileSchema(config: CompileSchemaConfig): (value: any, validationContext: ValidationContext) => void; private addTest; /** * Method for custom validation */ test
(method: TestMethodConfig>): ObjectPropertiesSchema; test(method: RuleMethodSchemaError): ObjectPropertiesSchema; test(method: OldTestMethodConfig>): ObjectPropertiesSchema; /** * Method for async custom validation */ asyncTest(method: TestMethodConfig>): this; asyncTest(method: AsyncRuleMethodSchemaError): this; asyncTest(method: OldTestMethodConfig>): this; /** * Makes schema conditional. Meaning when `is` is true * it will validate with `then schema` otherwise will * validate with `otherwise schema`. * @param {WhenConfig} * @example * ```Typescript * number() * .optional() // Validation will be included in `then` and `otherwise` * .when({ * is: (value, form) => value === 10, * then: (schema) => schema.required() , * otherwise: (schema) => schema.notOptional() * }) * ``` */ when = this>(name: string, config: WhenConfig): this; when = this>(config: WhenConfig): this; /** * Makes schema validation only on touch * (meaning value will only be validated if key * is present in onlyOnTouch: OnlyOnTouch). */ onlyOnTouch(onlyOnTouch?: (schema: this) => this): this; /** * Makes schema validation validation regardless of "touches" * (meaning value will be validated even if key * is present in onlyOnTouch: OnlyOnTouch). */ notOnlyOnTouch(): this; /** * Makes schema validation required (meaning value can not be undefined and null). */ required(message?: string): this; /** * Makes schema validation not required (meaning value can be undefined and null). */ notRequired(): this; /** * Makes schema validation optional (meaning value can be undefined). */ optional(): this; /** * Makes schema validation not optional (meaning value can not be undefined). */ notOptional(message?: string): this; /** * Makes schema validation nullable (meaning value can be null). */ nullable(): this; /** * Makes schema validation not nullable (meaning value can not be null). */ notNullable(message?: string): this; /** * Creates validation method. * @param config - {@link CompileConfig} */ compile(): this; /** * Validates form and returns an array of errors {@link SchemaError} * @param value - form input * @param onlyOnTouch - array of keys that inform the schema if a value * was touched. Works with only with {@link Schema#onlyOnTouch} * @returns {SchemaError} */ validate(value: Input, onlyOnTouch?: OnlyOnTouch): SchemaError[] | Promise; }