validation
Validation types for schema validation.
This module provides the type definitions for validating data against Stately schemas. The validation system supports recursive validation with depth limiting, plugin-based validation hooks, and detailed error reporting.
Interfaces
ValidateArgs
Defined in: validation.ts:116
Context passed to validation hooks in plugins.
Provides all the information needed for a plugin to validate a value at a specific path in the data structure.
Example
Type Parameters
S
S extends StatelySchemas<any, any> = StatelySchemas<any, any>
The StatelySchemas type being validated against
Node
Node extends BaseNode = S["plugin"]["AnyNode"]
The schema node type at this location
Properties
data
data:
any
Defined in: validation.ts:123
The actual data value to validate
options?
optionaloptions:ValidationOptions
Defined in: validation.ts:127
Validation options controlling behavior
path
path:
string
Defined in: validation.ts:121
JSON path to the current location being validated
schema
schema:
Node
Defined in: validation.ts:125
The schema node defining the expected structure
ValidationError
Defined in: validation.ts:27
Represents a single validation error with location and context.
Example
Properties
message
message:
string
Defined in: validation.ts:31
Human-readable description of the validation failure
path
path:
string
Defined in: validation.ts:29
JSON path to the invalid value (e.g., 'user.address.city')
value?
optionalvalue:any
Defined in: validation.ts:33
The actual value that failed validation (optional for security)
ValidationOptions
Defined in: validation.ts:81
Configuration options for validation behavior.
Controls recursion depth, debugging output, and warning callbacks for deeply nested validation.
Example
Properties
debug?
optionaldebug:boolean
Defined in: validation.ts:89
Enable verbose debug output during validation
depth?
optionaldepth:number
Defined in: validation.ts:83
Current recursion depth (used internally)
maxDepth?
optionalmaxDepth:number
Defined in: validation.ts:87
Maximum allowed recursion depth before stopping validation
onDepthWarning()?
optionalonDepthWarning: (path,depth) =>void
Defined in: validation.ts:91
Callback invoked when validation exceeds warnDepth
Parameters
path
string
depth
number
Returns
void
warnDepth?
optionalwarnDepth:number
Defined in: validation.ts:85
Depth at which to trigger warning callback
ValidationResult
Defined in: validation.ts:56
Result of a validation operation.
Contains the overall validity status and an array of any errors encountered during validation.
Example
Properties
errors
errors:
ValidationError[]
Defined in: validation.ts:60
Array of validation errors (empty if valid is true)
valid
valid:
boolean
Defined in: validation.ts:58
Whether the validated data passed all validation rules
Type Aliases
ValidateHook()
ValidateHook<
S> = (args) =>ValidationResult|undefined
Defined in: validation.ts:157
Validation hook function signature for plugins.
Plugins can provide validation hooks that are called during schema
validation. Returning undefined indicates the hook doesn't handle
this validation case and other hooks should be tried.
Type Parameters
S
S extends StatelySchemas<any, any> = StatelySchemas<any, any>
The StatelySchemas type being validated against
Parameters
args
ValidateArgs<S>
Returns
ValidationResult | undefined
ValidationResult if handled, undefined to pass to next hook