/** * @example * ``` javascript * import { Schema } from 'hord'; * * const person = new Schema({ * first: String, * last: String, * age: 'integer', * hobbies: { * type: Array, * content: String * } * }); * * person.validate({ * first: 'John', * last: 'Doe', * age: 21 * }); * // => [] * ``` * * @class Schema * @classdesc Schema enforcement. * * @param {SchemaDefinition} schema */ export default class Schema { constructor(schema: any); /** * Validate an item against the schema. * * @memberOf Schema * @instance * * @param {object} item - The object validate against this schema. * @param {Array} [path=[]] - If provided then only the value at that path will be validated. * * @returns {SchemaError[]} */ validate(item: object, path?: any[]): SchemaError[]; /** * Enforce an items structure against the schema. This function mutates the original item. * * @memberOf Schema * @instance * * @param {object} item - The object enforce against this schema. * @param {Array} [path=[]] - If provided then only the value at that path will be enforced. * @param {unknown} [replace] - If the current value at path is invalid, replace it with this. * * @returns {SchemaError[]} */ enforce(item: object, path?: any[], replace?: unknown): SchemaError[]; /** * Calls a callback for each rule that will be used to validate this schema. * * @memberOf Schema * @instance * * @param {Function} callback - Provides two args: the path and the rule. If true is returned then no more callbacks will happen further down this branch, but will continue up a level. */ eachRule(callback: Function): void; /** * Returns a new Schema with the rules from the provided schema [superimposed](https://github.com/DarrenPaulWright/object-agent/blob/master/docs/superimpose.md) on the rules from this schema. If no args are provided, then the returned Schema is effectively a clone of this one. * * @memberOf Schema * @instance * * @param {SchemaDefinition|Schema} schema - The schema to superimpose on this one. * * @returns {Schema} */ extend(schema: SchemaDefinition | Schema): Schema; } /** * Schema validation errors */ export type SchemaError = object; /** * Schema type definitions. Can be just the type as defined below, or an array of types, or an object with the following options. Any extra options provided will be copied to the rule, which can be accessed via the schema.eachRule() method. * * '*' can be used as a key to indicate that any keys are allowed in an object. */ export type SchemaDefinition = any | object; //# sourceMappingURL=Schema.d.ts.map