/** * Module validate provides an implementation of JSON Typedef validation. * * The most important function in this module is {@link validate}, which returns * an array of {@link ValidationError}. You can configure {@link validate} by * passing it a {@link ValidationConfig}. * * @packageDocumentation */ import type { Schema } from './schema'; /** * ValidationConfig represents options you can pass to {@link validate}. */ export interface ValidationConfig { /** * maxDepth is the maximum number of `ref`s to recursively follow before * {@link validate} throws {@link MaxDepthExceededError}. * * If maxDepth is zero, then no maximum depth will be enforced. * {@link validate} will recursively follow `ref`s indefinitely, potentially * causing a stack overflow. * * By default, maxDepth is zero. */ maxDepth?: number; /** * maxErrors is the maximum number of errors to return from {@link validate}. * * If maxErrors is positive, {@link validate} may return fewer errors than * maxErrors, but it will never return more than maxErrors. * * If maxErrors is zero, {@link validate} will return all validation errors. * * By default, maxErrors is zero. */ maxErrors?: number; features?: string[]; } /** * MaxDepthExceededError is the error returned if * {@link ValidationConfig.maxDepth} is exceeded during {@link validate}. */ export declare class MaxDepthExceededError extends Error { } /** * ValidationError represents a JSON Typedef validation error. * * In terms of the formal JSON Typedef specification, ValidationError * corresponds to a JSON Typedef error "indicator". ValidationError is *not* a * subclass of Error. It is just a plain old TypeScript interface. * * Both elements of ValidationError are meant to be used as the path segments of * an [RFC6901 JSON Pointer](https://tools.ietf.org/html/rfc6901). This package * does not provide an implementation of JSON Pointers for you, and you may * choose to not use JSON Pointers at all. */ export interface ValidationError { /** * instancePath is the path to a part of the instance, or "input", that was * rejected. */ instancePath: string[]; /** * schemaPath is the path to the part of the schema that rejected the input. */ schemaPath: string[]; message: string; } /** * validate performs JSON Typedef validation of an instance (or "input") against * a JSON Typedef schema, returning a standardized set of errors. * * This function may throw {@link MaxDepthExceededError} if you have configured * a {@link ValidationConfig.maxDepth}. If you do not configure such a maxDepth, * then this function may cause a stack overflow. That's because of * circularly-defined schemas like this one: * * ```json * { * "ref": "loop", * "definitions": { * "loop": { "ref": "loop" } * } * } * ``` * * If your schema is not circularly defined like this, then there is no risk for * validate to overflow the stack. * * If you are only interested in a certain number of error messages, consider * using {@link ValidationConfig.maxErrors} to get better performance. For * instance, if all you care about is whether the input is OK or if it has * errors, you may want to set maxErrors to 1. * * @param schema The schema to validate data against * @param instance The "input" to validate * @param config Validation options. Optional. */ export declare function validate(schema: Schema, instance: unknown, config?: ValidationConfig): ValidationError[]; //# sourceMappingURL=validate.d.ts.map