Skip to content

Commit cdf642c

Browse files
authored
BC: make Spec.Protocol internal (#958)
* BC: make `Spec.Protocol` private Signed-off-by: Jan Kowalleck <[email protected]> * reorder Signed-off-by: Jan Kowalleck <[email protected]> * docs Signed-off-by: Jan Kowalleck <[email protected]> * docs Signed-off-by: Jan Kowalleck <[email protected]> * history Signed-off-by: Jan Kowalleck <[email protected]> * history Signed-off-by: Jan Kowalleck <[email protected]> --------- Signed-off-by: Jan Kowalleck <[email protected]>
1 parent d284224 commit cdf642c

File tree

7 files changed

+238
-157
lines changed

7 files changed

+238
-157
lines changed

HISTORY.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ All notable changes to this project will be documented in this file.
44

55
## unreleased
66

7+
* BREAKING
8+
* Interface `Spec.Protocol` was removed from public API ([#957] via [#958])
9+
This is only a breaking change if you custom-implemented this TypeScript interface downstream; internal usage is non-breaking.
10+
This change was necessary, so that implementing more spec-features cause no breaking changes.
11+
12+
[#957]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/957
13+
[#958]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/958
14+
715
## 5.0.0 -- 2023-08-16
816

917
* BREAKING
1018
* Interface `Spec.Protocol` now defines new mandatory methods (via [#946])
11-
This is only a breaking change if you custom-implemented this interface downstream; internal usage is non-breaking.
19+
This is only a breaking change if you custom-implemented this TypeScript interface downstream; internal usage is non-breaking.
1220
* Added
1321
* New enum `Enums.Lifecycle` with corresponding values from _CycloneDX_ Specification-1.5 ([#937] via [#946])
1422
* New class `Models.NamedLifecycle` ([#937] via [#946])
@@ -53,7 +61,7 @@ Added functionality regarding [_CycloneDX_ BOM-Link](https://cyclonedx.org/capab
5361

5462
* BREAKING
5563
* Interface `Spec.Protocol` now defines new mandatory methods (via [#843])
56-
This is only a breaking change if you custom-implemented this interface downstream; internal usage is non-breaking.
64+
This is only a breaking change if you custom-implemented this TypeScript interface downstream; internal usage is non-breaking.
5765
* Changed
5866
* Normalizers support _CycloneDX_ Specification-1.5 ([#505] via [#843])
5967
* Validators support _CycloneDX_ Specification-1.5 ([#505] via [#843])
@@ -67,7 +75,7 @@ Added functionality regarding [_CycloneDX_ BOM-Link](https://cyclonedx.org/capab
6775

6876
* BREAKING
6977
* Interface `Spec.Protocol` now defines a new mandatory method `supportsVulnerabilityRatingMethod()` (via [#843])
70-
This is only a breaking change if you custom-implemented this interface downstream; internal usage is non-breaking.
78+
This is only a breaking change if you custom-implemented this TypeScript interface downstream; internal usage is non-breaking.
7179
* Changed
7280
* Namespace `Models`
7381
* Method `BomRef.compare()` accepts every stringable now, was `Models.BomRef` only (via [#856])

src/serialize/json/normalize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import type { Stringable } from '../../_helpers/stringable'
2323
import { treeIteratorSymbol } from '../../_helpers/tree'
2424
import * as Models from '../../models'
2525
import { isSupportedSpdxId } from '../../spdx'
26-
import type { Protocol as Spec } from '../../spec'
2726
import { Version as SpecVersion } from '../../spec'
27+
import type { _SpecProtocol as Spec } from '../../spec/_protocol'
2828
import type { NormalizerOptions } from '../types'
2929
import type { Normalized } from './types'
3030
import { JsonSchema } from './types'

src/serialize/xml/normalize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import type { Stringable } from '../../_helpers/stringable'
2323
import { treeIteratorSymbol } from '../../_helpers/tree'
2424
import * as Models from '../../models'
2525
import { isSupportedSpdxId } from '../../spdx'
26-
import type { Protocol as Spec } from '../../spec'
2726
import { Version as SpecVersion } from '../../spec'
27+
import type { _SpecProtocol as Spec } from '../../spec/_protocol'
2828
import type { NormalizerOptions } from '../types'
2929
import type { SimpleXml } from './types'
3030
import { XmlSchema } from './types'

src/spec/_protocol.ts

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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 { ComponentType, ExternalReferenceType, HashAlgorithm, Vulnerability } from '../enums'
21+
import type { HashContent } from '../models'
22+
import type { Format, Version } from './enums'
23+
24+
/**
25+
* This interface is not intended to be public API.
26+
* This interface may be affected by breaking changes without notice.
27+
*
28+
* See the public exported constants, like {@link Spec.Spec1dot4}, that provide objects implementing this interface.
29+
* See also {@link Spec.SpecVersionDict} for implementations.
30+
*/
31+
export interface _SpecProtocol {
32+
version: Version
33+
supportsFormat: (f: Format | any) => boolean
34+
supportsComponentType: (ct: ComponentType | any) => boolean
35+
supportsHashAlgorithm: (ha: HashAlgorithm | any) => boolean
36+
supportsHashValue: (hv: HashContent | any) => boolean
37+
supportsExternalReferenceType: (ert: ExternalReferenceType | any) => boolean
38+
supportsDependencyGraph: boolean
39+
supportsToolReferences: boolean
40+
requiresComponentVersion: boolean
41+
supportsProperties: (model: any) => boolean
42+
supportsVulnerabilities: boolean
43+
supportsVulnerabilityRatingMethod: (rm: Vulnerability.RatingMethod | any) => boolean
44+
supportsComponentEvidence: boolean
45+
supportsMetadataLifecycles: boolean
46+
}
47+
48+
/**
49+
* This class was never intended to be public API,
50+
*
51+
* This is a helper to get the exact spec-versions implemented according to {@link _SpecProtocol | Specification}.
52+
*
53+
* @internal as this class may be affected by breaking changes without notice
54+
*/
55+
export class _Spec implements _SpecProtocol {
56+
readonly #version: Version
57+
readonly #formats: ReadonlySet<Format>
58+
readonly #componentTypes: ReadonlySet<ComponentType>
59+
readonly #hashAlgorithms: ReadonlySet<HashAlgorithm>
60+
readonly #hashValuePattern: RegExp
61+
readonly #externalReferenceTypes: ReadonlySet<ExternalReferenceType>
62+
readonly #vulnerabilityRatingMethods: ReadonlySet<Vulnerability.RatingMethod>
63+
readonly #supportsDependencyGraph: boolean
64+
readonly #supportsToolReferences: boolean
65+
readonly #requiresComponentVersion: boolean
66+
readonly #supportsProperties: boolean
67+
readonly #supportsVulnerabilities: boolean
68+
readonly #supportsComponentEvidence: boolean
69+
readonly #supportsMetadataLifecycles: boolean
70+
71+
constructor (
72+
version: Version,
73+
formats: Iterable<Format>,
74+
componentTypes: Iterable<ComponentType>,
75+
hashAlgorithms: Iterable<HashAlgorithm>,
76+
hashValuePattern: RegExp,
77+
externalReferenceTypes: Iterable<ExternalReferenceType>,
78+
supportsDependencyGraph: boolean,
79+
supportsToolReferences: boolean,
80+
requiresComponentVersion: boolean,
81+
supportsProperties: boolean,
82+
supportsVulnerabilities: boolean,
83+
vulnerabilityRatingMethods: Iterable<Vulnerability.RatingMethod>,
84+
supportsComponentEvidence: boolean,
85+
supportsMetadataLifecycles: boolean
86+
) {
87+
this.#version = version
88+
this.#formats = new Set(formats)
89+
this.#componentTypes = new Set(componentTypes)
90+
this.#hashAlgorithms = new Set(hashAlgorithms)
91+
this.#hashValuePattern = hashValuePattern
92+
this.#externalReferenceTypes = new Set(externalReferenceTypes)
93+
this.#supportsDependencyGraph = supportsDependencyGraph
94+
this.#supportsToolReferences = supportsToolReferences
95+
this.#requiresComponentVersion = requiresComponentVersion
96+
this.#supportsProperties = supportsProperties
97+
this.#supportsVulnerabilities = supportsVulnerabilities
98+
this.#vulnerabilityRatingMethods = new Set(vulnerabilityRatingMethods)
99+
this.#supportsComponentEvidence = supportsComponentEvidence
100+
this.#supportsMetadataLifecycles = supportsMetadataLifecycles
101+
}
102+
103+
get version (): Version {
104+
return this.#version
105+
}
106+
107+
supportsFormat (f: Format | any): boolean {
108+
return this.#formats.has(f)
109+
}
110+
111+
supportsComponentType (ct: ComponentType | any): boolean {
112+
return this.#componentTypes.has(ct)
113+
}
114+
115+
supportsHashAlgorithm (ha: HashAlgorithm | any): boolean {
116+
return this.#hashAlgorithms.has(ha)
117+
}
118+
119+
supportsHashValue (hv: HashContent | any): boolean {
120+
return typeof hv === 'string' &&
121+
this.#hashValuePattern.test(hv)
122+
}
123+
124+
supportsExternalReferenceType (ert: ExternalReferenceType | any): boolean {
125+
return this.#externalReferenceTypes.has(ert)
126+
}
127+
128+
get supportsDependencyGraph (): boolean {
129+
return this.#supportsDependencyGraph
130+
}
131+
132+
get supportsToolReferences (): boolean {
133+
return this.#supportsToolReferences
134+
}
135+
136+
get requiresComponentVersion (): boolean {
137+
return this.#requiresComponentVersion
138+
}
139+
140+
supportsProperties (): boolean {
141+
// currently a global allow/deny -- might work based on input, in the future
142+
return this.#supportsProperties
143+
}
144+
145+
get supportsVulnerabilities (): boolean {
146+
return this.#supportsVulnerabilities
147+
}
148+
149+
supportsVulnerabilityRatingMethod (rm: Vulnerability.RatingMethod | any): boolean {
150+
return this.#vulnerabilityRatingMethods.has(rm)
151+
}
152+
153+
get supportsComponentEvidence (): boolean {
154+
return this.#supportsComponentEvidence
155+
}
156+
157+
get supportsMetadataLifecycles (): boolean {
158+
return this.#supportsMetadataLifecycles
159+
}
160+
}

0 commit comments

Comments
 (0)