ProtectedisWhether the schema requires a non-null/non-undefined value.
Sets the requirement flag. Must be a boolean.
ProtectedpreprocessorsA list of preprocessors associated with the Builder
ProtectedtypeThe string identifier of the schema type (e.g. 'string', 'number', 'object').
Sets the schema type identifier. Must be a non-empty string.
ProtectedvalidatorsA list of validators associated with the Builder
Adds a preprocessor to a preprocessors list
ProtectedassureEnsures a ValidationErrorMessageProvider is valid.
If provider is undefined, falls back to defaultValue.
Function providers are bound to this for access to schema state.
the provider to validate, or undefined
fallback provider when provider is not supplied
a valid ValidationErrorMessageProvider
Clears type set by call to .hasType<T>(), default schema type inference will be used
for schema returned by this call.
Clear max length of the valid array value for schema.
Clear minimal length of the valid array value for schema.
Clears the element schema set by of(). After this call,
array items of any type will be accepted.
Remove all preprocessors for this schema.
Remove all validators for this schema.
ProtectedgetResolves a ValidationErrorMessageProvider to a string error message.
Handles both string providers and function providers (sync or async).
the error message provider (string or function)
the value that caused the validation error
the resolved error message string
Set type of schema explicitly. notUsed param is needed only for case when JS is used. E.g. when you
can't call method like schema.hasType<Date>(), so instead you can call schema.hasType(new Date())
with the same result.
Optional_notUsed: TGenerates a serializable object describing the defined schema
Schema of array item (if defined)
If set to false, schema will be optional (null or undefined values
will be considered as valid).
Max length of a valid array
Max length validation error message provider. If not provided, default error message provider is used.
Min length of a valid array
Min length validation error message provider. If not provided, default error message provider is used.
Array of preprocessor functions
Custom error message provider for the 'is required' validation error.
String id of schema type, e.g. string', numberorobject`.
Array of validator functions
Set max length of the valid array value for schema.
OptionalerrorMessage: ValidationErrorMessageProvider<Custom error message provider.
Set minimal length of the valid array value for schema.
OptionalerrorMessage: ValidationErrorMessageProvider<Custom error message provider.
Set a schema that every array item has to satisfy. If it is not set, Item of any type is allowed.
Schema that every array item has to satisfy
ProtectedpreRuns preprocessors, validators, and the required/optional check on object.
Subclasses call this at the start of their validate() implementation to get
a preprocessed value wrapped in a transaction, along with any early errors.
the value to pre-validate
Optionalcontext: ValidationContext<SchemaBuilder<any, any>>optional validation context settings
a PreValidationResult containing the preprocessed transaction, context, and any errors
Performs validation of the schema over object. Basically runs
validators, preprocessors and checks for required (if schema is not optional).
Optionalcontext: ValidationContextOptional ValidationContext settings.
Similar to the
Arraytype in TypeScript. It can be used to validate arrays of any type. It can also be used to validate arrays of specific type. For example, if you want to validate an array of numbers, you can usearray(number())to create a schema builder. If you want to validate an array of users, you can usearray().of(object({ name: string(), age: number() }))to create a schema builder. If you want to validate an array of numbers or strings, you can usearray(union(number()).or(string())).Also you can limit the length of the array by using
minLengthandmaxLengthmethods.NOTE this class is exported only to give opportunity to extend it by inheriting. It is not recommended to create an instance of this class directly. Use array() function instead.
See
array