@cyclonedx/cyclonedx-library
Version:
Core functionality of CycloneDX for JavaScript (Node.js or WebBrowser).
58 lines (54 loc) • 2.19 kB
JavaScript
/*!
This file is part of CycloneDX JavaScript Library.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright (c) OWASP Foundation. All Rights Reserved.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.XmlValidator = void 0;
const errors_1 = require("../_optPlug.node/errors");
const xmlValidator_1 = __importDefault(require("../_optPlug.node/xmlValidator"));
const resources_node_1 = require("../resources.node");
const baseValidator_1 = require("./baseValidator");
const errors_2 = require("./errors");
class XmlValidator extends baseValidator_1.BaseValidator {
#getSchemaFilePath() {
const s = resources_node_1.FILES.CDX.XML_SCHEMA[this.version];
if (s === undefined) {
throw new errors_2.NotImplementedError(this.version);
}
return s;
}
#validatorCache = undefined;
async #getValidator() {
if (this.#validatorCache === undefined) {
try {
this.#validatorCache = await (0, xmlValidator_1.default)(this.#getSchemaFilePath());
}
catch (err) {
if (err instanceof errors_1.OptPlugError) {
throw new errors_2.MissingOptionalDependencyError(err.message, err);
}
throw err;
}
}
return this.#validatorCache;
}
async validate(data) {
return (await this.#getValidator())(data);
}
}
exports.XmlValidator = XmlValidator;
//# sourceMappingURL=xmlValidator.node.js.map
;