Skip to content

Commit 9e5de07

Browse files
authored
docs: document Models.BomLink* (#857)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 8a196ea commit 9e5de07

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

HISTORY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Added functionality regarding [_CycloneDX_ BOM-Link](https://cyclonedx.org/capab
3232
* Enum `Vulnerability.RatingMethod` got new members ([#505] via [#843])
3333
New: `CVSSv4`, `SSVC`
3434
* Namespace `Models`
35-
* New classes `BomLinkDocument` and `BomLinkDocument` to represent _CycloneDX_ BOM-Link (via [#843], [#856])
35+
* New classes `BomLinkDocument` and `BomLinkDocument` to represent _CycloneDX_ BOM-Link (via [#843], [#856], [#857])
3636
* New type `BomLink` to represent _CycloneDX_ BOM-Link (via [#843], [#856])
3737
* Namespace `Spec`
3838
* Enum `Version` got new member `v1dot5` to reflect _CycloneDX_ Specification-1.5 ([#505] via [#843])
@@ -52,6 +52,7 @@ Added functionality regarding [_CycloneDX_ BOM-Link](https://cyclonedx.org/capab
5252
[#841]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/841
5353
[#843]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/843
5454
[#856]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/856
55+
[#857]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/857
5556

5657
## 2.1.0 -- 2023-06-10
5758

src/models/bomLink.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ abstract class BomLinkBase implements Stringable, Comparable<Stringable> {
2424
/* @ts-expect-error TS2564 */
2525
#value: string
2626

27+
/** @internal */
2728
protected abstract _isValid (value: any): boolean
2829

30+
/**
31+
* @throws {@link RangeError} if value is invalid
32+
*/
2933
constructor (value: string) {
3034
this.value = value
3135
}
3236

37+
/**
38+
* @throws {@link RangeError} if value is invalid
39+
*/
3340
set value (value: string) {
3441
if (!this._isValid(value)) {
3542
throw new RangeError('invalid value')
@@ -51,41 +58,54 @@ abstract class BomLinkBase implements Stringable, Comparable<Stringable> {
5158
}
5259

5360
/**
61+
* Descriptor for another BOM document.
62+
*
5463
* See [the docs](https://cyclonedx.org/capabilities/bomlink/)
5564
*/
5665
export class BomLinkDocument extends BomLinkBase {
5766
/* regular expressions were taken from the CycloneDX schema definitions. */
5867
static #pattern = /^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]*$/
5968

69+
/**
70+
* Whether the `value` is a valid descriptor for another BOM document.
71+
*/
6072
static isValid (value: any): boolean {
6173
return typeof value === 'string' &&
62-
BomLinkDocument.#pattern.test(value)
74+
this.#pattern.test(value)
6375
}
6476

77+
/** @internal */
6578
protected _isValid (value: any): boolean {
6679
return BomLinkDocument.isValid(value)
6780
}
6881
}
6982

7083
/**
84+
* Descriptor for an element in a BOM document.
85+
*
7186
* See [the docs](https://cyclonedx.org/capabilities/bomlink/)
7287
*/
7388
export class BomLinkElement extends BomLinkBase {
7489
/* regular expressions were taken from the CycloneDX schema definitions. */
7590
static #pattern = /^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]*#.+$/
7691

92+
/**
93+
* Whether the `value` is a valid descriptor for an element in a BOM document.
94+
*/
7795
static isValid (value: any): boolean {
7896
return typeof value === 'string' &&
79-
BomLinkElement.#pattern.test(value)
97+
this.#pattern.test(value)
8098
}
8199

100+
/** @internal */
82101
protected _isValid (value: any): boolean {
83102
return BomLinkElement.isValid(value)
84103
}
85104
}
86105

87106
/**
107+
* Either {@link BomLinkDocument} or {@link BomLinkElement}.
108+
*
88109
* See [the docs](https://cyclonedx.org/capabilities/bomlink/)
89-
* @see {@link isBomLink}
90110
*/
91111
export type BomLink = BomLinkDocument | BomLinkElement

0 commit comments

Comments
 (0)