Skip to content

Commit 5da56e0

Browse files
committed
initial dependency graph work
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 43f7ac1 commit 5da56e0

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

src/models/bom.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import { Metadata } from './metadata'
33
import { ComponentRepository } from './component'
44

55
export class Bom {
6-
// property `bomFormat` is not part of model, it is a runtime information
7-
// property `specVersion` is not part of model, it is a runtime information
8-
96
metadata = new Metadata()
107
components = new ComponentRepository()
118

9+
// Property `bomFormat` is not part of model, it is a runtime information.
10+
// Property `specVersion` is not part of model, it is a runtime information.
11+
12+
// Property `dependencies` is not part of this model, but part of `Component` and other models.
13+
// The dependency grapth can be normalized on rendertime, no need to store it in the bom model.
14+
1215
#version: PositiveInteger = 1
1316
get version (): PositiveInteger {
1417
return this.#version

src/models/component.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PackageURL } from 'packageurl-js'
22

33
import { CPE, isCPE } from '../types'
44
import { ComponentScope, ComponentType } from '../enums'
5-
import { BomRef } from './bomRef'
5+
import { BomRef, BomRefRepository } from './bomRef'
66
import { HashRepository } from './hash'
77
import { OrganizationalEntity } from './organizationalEntity'
88
import { ExternalReferenceRepository } from './externalReference'
@@ -48,6 +48,15 @@ export class Component {
4848
this.#cpe = value
4949
}
5050

51+
#dependencies = new BomRefRepository()
52+
get dependencies (): BomRefRepository {
53+
return this.#dependencies
54+
}
55+
56+
set dependencies (value: BomRefRepository) {
57+
this.#dependencies = value
58+
}
59+
5160
compare (other: Component): number {
5261
const bomRefCompare = this.bomRef.compare(other.bomRef)
5362
if (bomRefCompare !== 0) { return bomRefCompare }

src/serialize/JSON.normalize.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ export class BomNormalizer extends Base {
8686
metadata: this.factory.makeForMetadata().normalize(data.metadata, options),
8787
components: data.components.size > 0
8888
? this.factory.makeForComponent().normalizeIter(data.components, options)
89-
: [] // spec < 1.4 requires `component` to be array
89+
// spec < 1.4 requires `component` to be array
90+
: [],
91+
dependencies: this.factory.spec.supportsDependencyGraph
92+
? undefined // @TODO: render dependency graph
93+
: undefined
9094
}
9195
}
9296
}

src/serialize/JSON.types.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Enums from '../enums'
22
import { SpdxId } from '../SPDX'
33
import { CPE, PositiveInteger, UrnUuid } from '../types'
4-
import { HashContent } from '../models'
4+
import { BomRef, HashContent } from '../models'
55

66
type IriReference = string
77
type IdnEmail = string
@@ -18,6 +18,7 @@ export interface Bom {
1818
metadata?: Metadata
1919
components?: Component[]
2020
externalReferences?: ExternalReference[]
21+
dependencies?: Depndency[]
2122
}
2223

2324
export interface Metadata {
@@ -121,3 +122,8 @@ export interface Attachment {
121122
contentType?: string
122123
encoding?: Enums.AttachmentEncoding
123124
}
125+
126+
export interface Depndency {
127+
ref: BomRef
128+
dependsOn?: BomRef[]
129+
}

src/spec.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export interface Protocol {
2929
supportsHashValue: (hv: HashContent | any) => boolean
3030

3131
supportsExternalReferenceType: (ert: ExternalReferenceType | any) => boolean
32+
33+
readonly supportsDependencyGraph: boolean
3234
}
3335

3436
class Spec implements Protocol {
@@ -38,21 +40,24 @@ class Spec implements Protocol {
3840
readonly #hashAlgorithms: ReadonlySet<HashAlgorithm>
3941
readonly #hashValuePattern: RegExp
4042
readonly #externalReferenceTypes: ReadonlySet<ExternalReferenceType>
43+
readonly #supportsDependencyGraph: boolean
4144

4245
constructor (
4346
version: Version,
4447
formats: Iterable<Format>,
4548
componentTypes: Iterable<ComponentType>,
4649
hashAlgorithms: Iterable<HashAlgorithm>,
4750
hashValuePattern: RegExp,
48-
externalReferenceTypes: Iterable<ExternalReferenceType>
51+
externalReferenceTypes: Iterable<ExternalReferenceType>,
52+
supportsDependencyGraph: boolean
4953
) {
5054
this.#version = version
5155
this.#formats = new Set(formats)
5256
this.#componentTypes = new Set(componentTypes)
5357
this.#hashAlgorithms = new Set(hashAlgorithms)
5458
this.#hashValuePattern = hashValuePattern
5559
this.#externalReferenceTypes = new Set(externalReferenceTypes)
60+
this.#supportsDependencyGraph = supportsDependencyGraph
5661
}
5762

5863
get version (): Version {
@@ -79,6 +84,10 @@ class Spec implements Protocol {
7984
supportsExternalReferenceType (ert: ExternalReferenceType | any): boolean {
8085
return this.#externalReferenceTypes.has(ert)
8186
}
87+
88+
get supportsDependencyGraph (): boolean {
89+
return this.#supportsDependencyGraph
90+
}
8291
}
8392

8493
/** Specification v1.2 */
@@ -129,7 +138,8 @@ export const Spec1dot2: Protocol = Object.freeze(new Spec(
129138
ExternalReferenceType.BuildMeta,
130139
ExternalReferenceType.BuildSystem,
131140
ExternalReferenceType.Other
132-
]
141+
],
142+
true
133143
))
134144

135145
/** Specification v1.3 */
@@ -180,7 +190,8 @@ export const Spec1dot3: Protocol = Object.freeze(new Spec(
180190
ExternalReferenceType.BuildMeta,
181191
ExternalReferenceType.BuildSystem,
182192
ExternalReferenceType.Other
183-
]
193+
],
194+
true
184195
))
185196

186197
/** Specification v1.4 */
@@ -232,7 +243,8 @@ export const Spec1dot4: Protocol = Object.freeze(new Spec(
232243
ExternalReferenceType.BuildSystem,
233244
ExternalReferenceType.ReleaseNotes,
234245
ExternalReferenceType.Other
235-
]
246+
],
247+
true
236248
))
237249

238250
export const SpecVersionDict: { readonly [key in Version]?: Protocol } = Object.freeze(Object.fromEntries([

0 commit comments

Comments
 (0)