@cyclonedx/cyclonedx-library
Version:
Core functionality of CycloneDX for JavaScript (Node.js or WebBrowser).
123 lines (119 loc) • 4.18 kB
JavaScript
"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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComponentEvidence = exports.ComponentRepository = exports.Component = void 0;
const sortable_1 = require("../_helpers/sortable");
const tree_1 = require("../_helpers/tree");
const cpe_1 = require("../types/cpe");
const bomRef_1 = require("./bomRef");
const copyright_1 = require("./copyright");
const externalReference_1 = require("./externalReference");
const hash_1 = require("./hash");
const license_1 = require("./license");
const property_1 = require("./property");
class Component {
type;
name;
author;
copyright;
description;
externalReferences;
group;
hashes;
licenses;
publisher;
purl;
scope;
supplier;
swid;
version;
components;
properties;
evidence;
#bomRef;
#cpe;
dependencies;
constructor(type, name, op = {}) {
this.#bomRef = new bomRef_1.BomRef(op.bomRef);
this.type = type;
this.name = name;
this.supplier = op.supplier;
this.author = op.author;
this.copyright = op.copyright;
this.externalReferences = op.externalReferences ?? new externalReference_1.ExternalReferenceRepository();
this.group = op.group;
this.hashes = op.hashes ?? new hash_1.HashDictionary();
this.licenses = op.licenses ?? new license_1.LicenseRepository();
this.publisher = op.publisher;
this.purl = op.purl;
this.scope = op.scope;
this.swid = op.swid;
this.version = op.version;
this.description = op.description;
this.components = op.components ?? new ComponentRepository();
this.cpe = op.cpe;
this.properties = op.properties ?? new property_1.PropertyRepository();
this.evidence = op.evidence;
this.dependencies = op.dependencies ?? new bomRef_1.BomRefRepository();
}
get bomRef() {
return this.#bomRef;
}
get cpe() {
return this.#cpe;
}
set cpe(value) {
if (value !== undefined && !(0, cpe_1.isCPE)(value)) {
throw new TypeError('Not CPE nor undefined');
}
this.#cpe = value;
}
compare(other) {
const bomRefCompare = this.bomRef.compare(other.bomRef);
if (bomRefCompare !== 0) {
return bomRefCompare;
}
if (this.purl !== undefined && other.purl !== undefined) {
return this.purl.toString().localeCompare(other.purl.toString());
}
if (this.#cpe !== undefined && other.#cpe !== undefined) {
return this.#cpe.localeCompare(other.#cpe);
}
return (this.group ?? '').localeCompare(other.group ?? '') ||
this.name.localeCompare(other.name) ||
(this.version ?? '').localeCompare(other.version ?? '');
}
}
exports.Component = Component;
class ComponentRepository extends sortable_1.SortableComparables {
*[tree_1.treeIteratorSymbol]() {
for (const component of this) {
yield component;
yield* component.components[tree_1.treeIteratorSymbol]();
}
}
}
exports.ComponentRepository = ComponentRepository;
class ComponentEvidence {
licenses;
copyright;
constructor(op = {}) {
this.licenses = op.licenses ?? new license_1.LicenseRepository();
this.copyright = op.copyright ?? new copyright_1.CopyrightRepository();
}
}
exports.ComponentEvidence = ComponentEvidence;
//# sourceMappingURL=component.js.map