UNPKG

@govtechsg/open-attestation

Version:
23 lines (22 loc) 979 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateSchema = void 0; var logger_1 = require("../logger"); var document_1 = require("../@types/document"); // don't change this otherwise there is a cycle var utils_1 = require("../utils/utils"); var logger = (0, logger_1.getLogger)("validate"); var validateSchema = function (document, validator, kind) { var _a; if (!validator) { throw new Error("No schema validator provided"); } var valid = validator(document.version === document_1.SchemaId.v3 || kind === "raw" ? document : (0, utils_1.getData)(document)); if (!valid) { logger.debug("There are errors in the document: ".concat(JSON.stringify(validator.errors))); return (_a = validator.errors) !== null && _a !== void 0 ? _a : []; } logger.debug("Document is a valid open attestation document v".concat(document.version)); return []; }; exports.validateSchema = validateSchema;