Skip to content

Commit 9d6fd34

Browse files
committed
feat: basic Services
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 40eb623 commit 9d6fd34

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

HISTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file.
66

77
<!-- add unreleased items here -->
88

9+
[#1164]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1164
10+
911
## 6.11.1 -- 2024-10-24
1012

1113
* Fixed

src/models/bom.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2020
import type { PositiveInteger } from '../types/integer'
2121
import { isPositiveInteger } from '../types/integer'
2222
import { ComponentRepository } from './component'
23+
import { ServiceRepository } from './service'
2324
import { Metadata } from './metadata'
2425
import { VulnerabilityRepository } from './vulnerability/vulnerability'
2526

2627
export interface OptionalBomProperties {
2728
metadata?: Bom['metadata']
2829
components?: Bom['components']
30+
services?: Bom['services']
2931
version?: Bom['version']
3032
vulnerabilities?: Bom['vulnerabilities']
3133
serialNumber?: Bom['serialNumber']
@@ -34,6 +36,7 @@ export interface OptionalBomProperties {
3436
export class Bom {
3537
metadata: Metadata
3638
components: ComponentRepository
39+
services: ServiceRepository
3740
vulnerabilities: VulnerabilityRepository
3841

3942
/** @see {@link version} */
@@ -54,6 +57,7 @@ export class Bom {
5457
constructor (op: OptionalBomProperties = {}) {
5558
this.metadata = op.metadata ?? new Metadata()
5659
this.components = op.components ?? new ComponentRepository()
60+
this.services= op.services?? new ServiceRepository()
5761
this.version = op.version ?? this.version
5862
this.vulnerabilities = op.vulnerabilities ?? new VulnerabilityRepository()
5963
this.serialNumber = op.serialNumber

src/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export * from './metadata'
3030
export * from './organizationalContact'
3131
export * from './organizationalEntity'
3232
export * from './property'
33+
export * from './service'
3334
export * from './swid'
3435
export * from './tool'
3536
export * as Vulnerability from './vulnerability'

src/models/service.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
import {type Comparable, SortableComparables} from "../_helpers/sortable";
21+
import {BomRef} from "./bomRef";
22+
import {ExternalReferenceRepository} from "./externalReference";
23+
import {LicenseRepository} from "./license";
24+
import type {OrganizationalEntity} from "./organizationalEntity";
25+
import {PropertyRepository} from "./property";
26+
27+
export interface OptionalToolProperties {
28+
provider?: Service['provider']
29+
}
30+
31+
32+
export interface OptionalComponentProperties {
33+
bomRef?: BomRef['value']
34+
provider?: Service['provider']
35+
group?: Service['group']
36+
version?: Service['version']
37+
description?: Service['description']
38+
licenses?: Service['licenses']
39+
externalReferences?: Service['externalReferences']
40+
services?: Service['services']
41+
properties?: Service['properties']
42+
}
43+
44+
export class Service implements Comparable<Service> {
45+
provider?: OrganizationalEntity
46+
group?: string
47+
name: string
48+
version?: string
49+
description?: string
50+
licenses: LicenseRepository
51+
externalReferences: ExternalReferenceRepository
52+
services: ServiceRepository
53+
properties: PropertyRepository
54+
55+
56+
/** @see {@link bomRef} */
57+
readonly #bomRef: BomRef
58+
59+
constructor(name: Service['name'], op: OptionalComponentProperties = {}) {
60+
this.#bomRef = new BomRef(op.bomRef)
61+
this.provider = op.provider
62+
this.group = op.group
63+
this.name = name
64+
this.version = op.version
65+
this.description = op.description
66+
this.licenses = op.licenses ?? new LicenseRepository()
67+
this.externalReferences = op.externalReferences ?? new ExternalReferenceRepository()
68+
this.services = op.services ?? new ServiceRepository()
69+
this.properties = op.properties ?? new PropertyRepository()
70+
}
71+
72+
get bomRef(): BomRef {
73+
return this.#bomRef
74+
}
75+
76+
compare(other: Service): number {
77+
// The purpose of this method is not to test for equality, but have deterministic comparability.
78+
const bomRefCompare = this.bomRef.compare(other.bomRef)
79+
if (bomRefCompare !== 0) {
80+
return bomRefCompare
81+
}
82+
/* eslint-disable @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
83+
return (this.group ?? '').localeCompare(other.group ?? '') ||
84+
this.name.localeCompare(other.name) ||
85+
(this.version ?? '').localeCompare(other.version ?? '')
86+
/* eslint-enable @typescript-eslint/strict-boolean-expressions */
87+
}
88+
89+
}
90+
91+
export class ServiceRepository extends SortableComparables<Service> {
92+
}

0 commit comments

Comments
 (0)