Validation
@noocodex/dagonizer/validation
The validation module provides the Ajv instance and the unified entity validator used internally by the dispatcher.
Class: Validator
Unified Ajv-backed entity validator. Access per-entity sub-validators via static fields.
import { Validator } from '@noocodex/dagonizer/validation';Validator.dag
Type: EntityValidator<DAG>
Validates raw values against DAGSchema (Ajv 2020-12). Used internally by Dagonizer.load, Dagonizer.fromValue, and Dagonizer.registerDAG.
Validator.dag.validate(value)
Validator.dag.validate(value: unknown): DAGValidates value against DAGSchema. Returns a typed DAG on success. Throws ValidationError with a multi-line message listing every Ajv failure on error.
try {
const dag = Validator.dag.validate(unknownValue);
} catch (error) {
if (error instanceof ValidationError) {
console.error(error.message); // '<instancePath>: <message>' per line
}
}Validator.dag.is(value)
Validator.dag.is(value: unknown): value is DAGType predicate. Returns true when value satisfies DAGSchema.
Validator.dag.errors(value)
Validator.dag.errors(value: unknown): string[] | nullReturns formatted path: message error strings, or null if valid.
Validator.checkpoint
Type: EntityValidator<CheckpointData>
Validates raw values against CheckpointDataSchema. Used by Checkpoint.restore.
Validator.checkpoint.validate(value)
Validator.checkpoint.validate(value: unknown): CheckpointDataReturns a typed CheckpointData or throws ValidationError. Called by Checkpoint.restore before any field access.
EntityValidator<T>
Per-entity validator interface. Every Validator.<entity> field is an EntityValidator.
import type { EntityValidator } from '@noocodex/dagonizer/validation';interface EntityValidator<T> {
is(value: unknown): value is T;
validate(value: unknown): T;
errors(value: unknown): string[] | null;
}Related guides
- Schema & JSON loading
- Persistence —
Validator.checkpointruns insideCheckpoint.recall