UNPKG

@cyclonedx/cyclonedx-library

Version:

Core functionality of CycloneDX for JavaScript (Node.js or WebBrowser).

72 lines (68 loc) 2.82 kB
"use strict"; /*! 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.JsonStrictValidator = exports.JsonValidator = void 0; const errors_1 = require("../_optPlug.node/errors"); const jsonValidator_1 = __importDefault(require("../_optPlug.node/jsonValidator")); const resources_node_1 = require("../resources.node"); const baseValidator_1 = require("./baseValidator"); const errors_2 = require("./errors"); class BaseJsonValidator extends baseValidator_1.BaseValidator { #getSchemaFilePath() { const s = this._getSchemaFile(); 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, jsonValidator_1.default)(this.#getSchemaFilePath(), { 'http://cyclonedx.org/schema/spdx.SNAPSHOT.schema.json': resources_node_1.FILES.SPDX.JSON_SCHEMA, 'http://cyclonedx.org/schema/jsf-0.82.SNAPSHOT.schema.json': resources_node_1.FILES.JSF.JSON_SCHEMA }); } 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); } } class JsonValidator extends BaseJsonValidator { _getSchemaFile() { return resources_node_1.FILES.CDX.JSON_SCHEMA[this.version]; } } exports.JsonValidator = JsonValidator; class JsonStrictValidator extends BaseJsonValidator { _getSchemaFile() { return resources_node_1.FILES.CDX.JSON_STRICT_SCHEMA[this.version]; } } exports.JsonStrictValidator = JsonStrictValidator; //# sourceMappingURL=jsonValidator.node.js.map