Skip to content

Commit 9f7b632

Browse files
authored
cdx1.5 dev update existing simple models (#835)
* cdx1.5 simple model updates Signed-off-by: Jan Kowalleck <[email protected]> * cs-fix Signed-off-by: Jan Kowalleck <[email protected]> --------- Signed-off-by: Jan Kowalleck <[email protected]>
1 parent c911183 commit 9f7b632

File tree

5 files changed

+64
-4
lines changed

5 files changed

+64
-4
lines changed

src/models/license.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2020
import type { Sortable } from '../_helpers/sortable'
2121
import type { SpdxId } from '../spdx'
2222
import type { Attachment } from './attachment'
23+
import { BomRef } from './bomRef'
2324

2425
/**
2526
* (SPDX) License Expression.
@@ -59,10 +60,12 @@ export class LicenseExpression {
5960
}
6061

6162
class DisjunctiveLicenseBase {
63+
bomRef: BomRef
6264
text?: Attachment
6365
#url?: URL | string
6466

6567
constructor (op: OptionalDisjunctiveLicenseProperties = {}) {
68+
this.bomRef = new BomRef(op.bomRef)
6669
this.text = op.text
6770
this.url = op.url
6871
}
@@ -79,6 +82,7 @@ class DisjunctiveLicenseBase {
7982
}
8083

8184
interface OptionalDisjunctiveLicenseProperties {
85+
bomRef?: BomRef['value']
8286
text?: DisjunctiveLicenseBase['text']
8387
url?: DisjunctiveLicenseBase['url']
8488
}
@@ -94,7 +98,10 @@ export class NamedLicense extends DisjunctiveLicenseBase {
9498
}
9599

96100
compare (other: NamedLicense): number {
97-
return this.name.localeCompare(other.name)
101+
/* eslint-disable @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
102+
return this.name.localeCompare(other.name) ||
103+
this.bomRef.compare(other.bomRef)
104+
/* eslint-enable @typescript-eslint/strict-boolean-expressions */
98105
}
99106
}
100107

@@ -134,7 +141,10 @@ export class SpdxLicense extends DisjunctiveLicenseBase {
134141
}
135142

136143
compare (other: SpdxLicense): number {
137-
return this.#id.localeCompare(other.#id)
144+
/* eslint-disable @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
145+
return this.#id.localeCompare(other.#id) ||
146+
this.bomRef.compare(other.bomRef)
147+
/* eslint-enable @typescript-eslint/strict-boolean-expressions */
138148
}
139149
}
140150

src/models/organizationalContact.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,23 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
1919

2020
import type { Comparable } from '../_helpers/sortable'
2121
import { SortableComparables } from '../_helpers/sortable'
22+
import { BomRef } from './bomRef'
2223

2324
export interface OptionalOrganizationalContactProperties {
25+
bomRef?: BomRef['value']
2426
name?: OrganizationalContact['name']
2527
email?: OrganizationalContact['email']
2628
phone?: OrganizationalContact['phone']
2729
}
2830

2931
export class OrganizationalContact implements Comparable<OrganizationalContact> {
32+
bomRef: BomRef
3033
name?: string
3134
email?: string
3235
phone?: string
3336

3437
constructor (op: OptionalOrganizationalContactProperties = {}) {
38+
this.bomRef = new BomRef(op.bomRef)
3539
this.name = op.name
3640
this.email = op.email
3741
this.phone = op.phone
@@ -41,7 +45,8 @@ export class OrganizationalContact implements Comparable<OrganizationalContact>
4145
/* eslint-disable @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
4246
return (this.name ?? '').localeCompare(other.name ?? '') ||
4347
(this.email ?? '').localeCompare(other.email ?? '') ||
44-
(this.phone ?? '').localeCompare(other.phone ?? '')
48+
(this.phone ?? '').localeCompare(other.phone ?? '') ||
49+
this.bomRef.compare(other.bomRef)
4550
/* eslint-enable @typescript-eslint/strict-boolean-expressions */
4651
}
4752
}

src/models/organizationalEntity.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
1919

2020
import type { Comparable } from '../_helpers/sortable'
2121
import { SortableComparables, SortableStringables } from '../_helpers/sortable'
22+
import { BomRef } from './bomRef'
2223
import { OrganizationalContactRepository } from './organizationalContact'
2324

2425
export interface OptionalOrganizationalEntityProperties {
26+
bomRef?: BomRef['value']
2527
name?: OrganizationalEntity['name']
2628
url?: OrganizationalEntity['url']
2729
contact?: OrganizationalEntity['contact']
2830
}
2931

3032
export class OrganizationalEntity implements Comparable<OrganizationalEntity> {
33+
bomRef: BomRef
3134
name?: string
3235
url: Set<URL | string>
3336
contact: OrganizationalContactRepository
3437

3538
constructor (op: OptionalOrganizationalEntityProperties = {}) {
39+
this.bomRef = new BomRef(op.bomRef)
3640
this.name = op.name
3741
this.url = op.url ?? new Set()
3842
this.contact = op.contact ?? new OrganizationalContactRepository()
@@ -42,7 +46,8 @@ export class OrganizationalEntity implements Comparable<OrganizationalEntity> {
4246
/* eslint-disable @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
4347
return (this.name ?? '').localeCompare(other.name ?? '') ||
4448
this.contact.compare(other.contact) ||
45-
(new SortableStringables(this.url)).compare(new SortableStringables(other.url))
49+
(new SortableStringables(this.url)).compare(new SortableStringables(other.url)) ||
50+
this.bomRef.compare(other.bomRef)
4651
/* eslint-enable @typescript-eslint/strict-boolean-expressions */
4752
}
4853
}

src/types/bomLink.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
/** @see {@link isBomLinkDocument} */
21+
export type BomLinkDocument = string
22+
/** @see {@link isBomLinkElement} */
23+
export type BomLinkElement = string
24+
/** @see {@link https://cyclonedx.org/capabilities/bomlink/} */
25+
export type BomLink = BomLinkDocument | BomLinkElement
26+
27+
/* regular expressions were taken from the CycloneDX schema definitions. */
28+
const bomLinkDocumentPattern = /urn:cdx:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/[1-9][0-9]*/
29+
const bomLinkElementPattern = /urn:cdx:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/[1-9][0-9]*#.+/
30+
31+
export function isBomLinkDocument (value: any): value is BomLinkDocument {
32+
return typeof value === 'string' &&
33+
bomLinkDocumentPattern.test(value)
34+
}
35+
36+
export function isBomLinkElement (value: any): value is BomLinkElement {
37+
return typeof value === 'string' &&
38+
bomLinkElementPattern.test(value)
39+
}

src/types/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20+
export * from './bomLink'
2021
export * from './cpe'
2122
export * from './cwe'
2223
export * from './integer'

0 commit comments

Comments
 (0)