validate.d.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. export type JSONSchema4 = import("json-schema").JSONSchema4;
  2. export type JSONSchema6 = import("json-schema").JSONSchema6;
  3. export type JSONSchema7 = import("json-schema").JSONSchema7;
  4. export type ErrorObject = import("ajv").ErrorObject;
  5. export type Extend = {
  6. formatMinimum?: number | undefined;
  7. formatMaximum?: number | undefined;
  8. formatExclusiveMinimum?: boolean | undefined;
  9. formatExclusiveMaximum?: boolean | undefined;
  10. link?: string | undefined;
  11. };
  12. export type Schema = (JSONSchema4 | JSONSchema6 | JSONSchema7) & Extend;
  13. export type SchemaUtilErrorObject = ErrorObject & {
  14. children?: Array<ErrorObject>;
  15. };
  16. export type PostFormatter = (
  17. formattedError: string,
  18. error: SchemaUtilErrorObject
  19. ) => string;
  20. export type ValidationErrorConfiguration = {
  21. name?: string | undefined;
  22. baseDataPath?: string | undefined;
  23. postFormatter?: PostFormatter | undefined;
  24. };
  25. /** @typedef {import("json-schema").JSONSchema4} JSONSchema4 */
  26. /** @typedef {import("json-schema").JSONSchema6} JSONSchema6 */
  27. /** @typedef {import("json-schema").JSONSchema7} JSONSchema7 */
  28. /** @typedef {import("ajv").ErrorObject} ErrorObject */
  29. /**
  30. * @typedef {Object} Extend
  31. * @property {number=} formatMinimum
  32. * @property {number=} formatMaximum
  33. * @property {boolean=} formatExclusiveMinimum
  34. * @property {boolean=} formatExclusiveMaximum
  35. * @property {string=} link
  36. */
  37. /** @typedef {(JSONSchema4 | JSONSchema6 | JSONSchema7) & Extend} Schema */
  38. /** @typedef {ErrorObject & { children?: Array<ErrorObject>}} SchemaUtilErrorObject */
  39. /**
  40. * @callback PostFormatter
  41. * @param {string} formattedError
  42. * @param {SchemaUtilErrorObject} error
  43. * @returns {string}
  44. */
  45. /**
  46. * @typedef {Object} ValidationErrorConfiguration
  47. * @property {string=} name
  48. * @property {string=} baseDataPath
  49. * @property {PostFormatter=} postFormatter
  50. */
  51. /**
  52. * @param {Schema} schema
  53. * @param {Array<object> | object} options
  54. * @param {ValidationErrorConfiguration=} configuration
  55. * @returns {void}
  56. */
  57. export function validate(
  58. schema: Schema,
  59. options: Array<object> | object,
  60. configuration?: ValidationErrorConfiguration | undefined
  61. ): void;
  62. import ValidationError from "./ValidationError";
  63. export { ValidationError };