validator.js 861 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Validator = void 0;
  4. const dereference_js_1 = require("./dereference.js");
  5. const validate_js_1 = require("./validate.js");
  6. class Validator {
  7. schema;
  8. draft;
  9. shortCircuit;
  10. lookup;
  11. constructor(schema, draft = '2019-09', shortCircuit = true) {
  12. this.schema = schema;
  13. this.draft = draft;
  14. this.shortCircuit = shortCircuit;
  15. this.lookup = (0, dereference_js_1.dereference)(schema);
  16. }
  17. validate(instance) {
  18. return (0, validate_js_1.validate)(instance, this.schema, this.draft, this.lookup, this.shortCircuit);
  19. }
  20. addSchema(schema, id) {
  21. if (id) {
  22. schema = { ...schema, $id: id };
  23. }
  24. (0, dereference_js_1.dereference)(schema, this.lookup);
  25. }
  26. }
  27. exports.Validator = Validator;