@cyclonedx/cyclonedx-library 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist.node/models/component.js +2 -0
- package/dist.node/models/component.js.map +1 -1
- package/dist.node/models/index.js +1 -0
- package/dist.node/models/index.js.map +1 -1
- package/dist.node/models/property.js +37 -0
- package/dist.node/models/property.js.map +1 -0
- package/dist.node/serialize/json/normalize.js +21 -1
- package/dist.node/serialize/json/normalize.js.map +1 -1
- package/dist.node/serialize/xml/normalize.js +31 -2
- package/dist.node/serialize/xml/normalize.js.map +1 -1
- package/dist.web/lib.dev.js +102 -4
- package/dist.web/lib.dev.js.map +1 -1
- package/dist.web/lib.js +1 -1
- package/package.json +2 -2
- package/res/README.md +1 -1
- package/res/bom-1.4.SNAPSHOT.schema.json +1 -1
- package/res/bom-1.4.SNAPSHOT.xsd +12 -2
- package/res/spdx.SNAPSHOT.schema.json +487 -482
- package/res/spdx.SNAPSHOT.xsd +1069 -1044
- package/src/models/component.ts +5 -1
- package/src/models/index.ts +1 -0
- package/src/models/property.ts +42 -0
- package/src/serialize/json/normalize.ts +24 -0
- package/src/serialize/json/types.ts +6 -0
- package/src/serialize/xml/normalize.ts +34 -1
package/src/models/component.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { OrganizationalEntity } from './organizationalEntity'
|
|
|
27
27
|
import { ExternalReferenceRepository } from './externalReference'
|
|
28
28
|
import { LicenseRepository } from './license'
|
|
29
29
|
import { SWID } from './swid'
|
|
30
|
+
import { PropertyRepository } from './property'
|
|
30
31
|
import { Comparable, SortableSet } from '../helpers/sortableSet'
|
|
31
32
|
import { treeIterator } from '../helpers/tree'
|
|
32
33
|
|
|
@@ -48,6 +49,7 @@ interface OptionalProperties {
|
|
|
48
49
|
dependencies?: Component['dependencies']
|
|
49
50
|
components?: Component['components']
|
|
50
51
|
cpe?: Component['cpe']
|
|
52
|
+
properties?: Component['properties']
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
export class Component implements Comparable {
|
|
@@ -68,6 +70,7 @@ export class Component implements Comparable {
|
|
|
68
70
|
version?: string
|
|
69
71
|
dependencies: BomRefRepository
|
|
70
72
|
components: ComponentRepository
|
|
73
|
+
properties: PropertyRepository
|
|
71
74
|
|
|
72
75
|
/** @see bomRef */
|
|
73
76
|
readonly #bomRef: BomRef
|
|
@@ -78,7 +81,7 @@ export class Component implements Comparable {
|
|
|
78
81
|
/**
|
|
79
82
|
* @throws {TypeError} if {@see op.cpe} is neither {@see CPE} nor {@see undefined}
|
|
80
83
|
*/
|
|
81
|
-
constructor (type:
|
|
84
|
+
constructor (type: Component['type'], name: Component['name'], op: OptionalProperties = {}) {
|
|
82
85
|
this.#bomRef = new BomRef(op.bomRef)
|
|
83
86
|
this.type = type
|
|
84
87
|
this.name = name
|
|
@@ -98,6 +101,7 @@ export class Component implements Comparable {
|
|
|
98
101
|
this.dependencies = op.dependencies ?? new BomRefRepository()
|
|
99
102
|
this.components = op.components ?? new ComponentRepository()
|
|
100
103
|
this.cpe = op.cpe
|
|
104
|
+
this.properties = op.properties ?? new PropertyRepository()
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
get bomRef (): BomRef {
|
package/src/models/index.ts
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
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 { Comparable, SortableSet } from '../helpers/sortableSet'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @see {@link https://github.com/CycloneDX/cyclonedx-property-taxonomy property-taxonomy}
|
|
24
|
+
*/
|
|
25
|
+
export class Property implements Comparable {
|
|
26
|
+
name: string
|
|
27
|
+
value: string
|
|
28
|
+
|
|
29
|
+
constructor (name: Property['name'], value: Property['value']) {
|
|
30
|
+
this.name = name
|
|
31
|
+
this.value = value
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
compare (other: Property): number {
|
|
35
|
+
/* eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
|
|
36
|
+
return this.name.localeCompare(other.name) ||
|
|
37
|
+
this.value.localeCompare(other.value)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class PropertyRepository extends SortableSet<Property> {
|
|
42
|
+
}
|
|
@@ -80,6 +80,10 @@ export class Factory {
|
|
|
80
80
|
return new AttachmentNormalizer(this)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
makeForProperty (): PropertyNormalizer {
|
|
84
|
+
return new PropertyNormalizer(this)
|
|
85
|
+
}
|
|
86
|
+
|
|
83
87
|
makeForDependencyGraph (): DependencyGraphNormalizer {
|
|
84
88
|
return new DependencyGraphNormalizer(this)
|
|
85
89
|
}
|
|
@@ -278,6 +282,9 @@ export class ComponentNormalizer extends Base {
|
|
|
278
282
|
: undefined,
|
|
279
283
|
components: data.components.size > 0
|
|
280
284
|
? this.normalizeRepository(data.components, options)
|
|
285
|
+
: undefined,
|
|
286
|
+
properties: data.properties.size > 0
|
|
287
|
+
? this._factory.makeForProperty().normalizeRepository(data.properties, options)
|
|
281
288
|
: undefined
|
|
282
289
|
}
|
|
283
290
|
: undefined
|
|
@@ -397,6 +404,23 @@ export class AttachmentNormalizer extends Base {
|
|
|
397
404
|
}
|
|
398
405
|
}
|
|
399
406
|
|
|
407
|
+
export class PropertyNormalizer extends Base {
|
|
408
|
+
normalize (data: Models.Property, options: NormalizerOptions): Normalized.Property {
|
|
409
|
+
return {
|
|
410
|
+
name: data.name,
|
|
411
|
+
value: data.value
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
normalizeRepository (data: Models.PropertyRepository, options: NormalizerOptions): Normalized.Property[] {
|
|
416
|
+
return (
|
|
417
|
+
options.sortLists ?? false
|
|
418
|
+
? data.sorted()
|
|
419
|
+
: Array.from(data)
|
|
420
|
+
).map(p => this.normalize(p, options))
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
400
424
|
export class DependencyGraphNormalizer extends Base {
|
|
401
425
|
normalize (data: Models.Bom, options: NormalizerOptions): Normalized.Dependency[] | undefined {
|
|
402
426
|
const allRefs = new Map<Models.BomRef, Models.BomRefRepository>()
|
|
@@ -132,6 +132,7 @@ export namespace Normalized {
|
|
|
132
132
|
modified?: boolean
|
|
133
133
|
externalReferences?: ExternalReference[]
|
|
134
134
|
components?: Component[]
|
|
135
|
+
properties?: Property[]
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
export interface NamedLicense {
|
|
@@ -179,6 +180,11 @@ export namespace Normalized {
|
|
|
179
180
|
encoding?: Enums.AttachmentEncoding
|
|
180
181
|
}
|
|
181
182
|
|
|
183
|
+
export interface Property {
|
|
184
|
+
name?: string
|
|
185
|
+
value?: string
|
|
186
|
+
}
|
|
187
|
+
|
|
182
188
|
export interface Dependency {
|
|
183
189
|
ref: RefType
|
|
184
190
|
dependsOn?: RefType[]
|
|
@@ -80,6 +80,10 @@ export class Factory {
|
|
|
80
80
|
return new AttachmentNormalizer(this)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
makeForProperty (): PropertyNormalizer {
|
|
84
|
+
return new PropertyNormalizer(this)
|
|
85
|
+
}
|
|
86
|
+
|
|
83
87
|
makeForDependencyGraph (): DependencyGraphNormalizer {
|
|
84
88
|
return new DependencyGraphNormalizer(this)
|
|
85
89
|
}
|
|
@@ -347,6 +351,13 @@ export class ComponentNormalizer extends Base {
|
|
|
347
351
|
children: this.normalizeRepository(data.components, options, 'component')
|
|
348
352
|
}
|
|
349
353
|
: undefined
|
|
354
|
+
const properties: SimpleXml.Element | undefined = data.properties.size > 0
|
|
355
|
+
? {
|
|
356
|
+
type: 'element',
|
|
357
|
+
name: 'properties',
|
|
358
|
+
children: this._factory.makeForProperty().normalizeRepository(data.properties, options, 'property')
|
|
359
|
+
}
|
|
360
|
+
: undefined
|
|
350
361
|
return {
|
|
351
362
|
type: 'element',
|
|
352
363
|
name: elementName,
|
|
@@ -370,7 +381,8 @@ export class ComponentNormalizer extends Base {
|
|
|
370
381
|
makeOptionalTextElement(data.purl, 'purl'),
|
|
371
382
|
swid,
|
|
372
383
|
extRefs,
|
|
373
|
-
components
|
|
384
|
+
components,
|
|
385
|
+
properties
|
|
374
386
|
].filter(isNotUndefined)
|
|
375
387
|
}
|
|
376
388
|
}
|
|
@@ -517,6 +529,27 @@ export class AttachmentNormalizer extends Base {
|
|
|
517
529
|
}
|
|
518
530
|
}
|
|
519
531
|
|
|
532
|
+
export class PropertyNormalizer extends Base {
|
|
533
|
+
normalize (data: Models.Property, options: NormalizerOptions, elementName: string): SimpleXml.Element {
|
|
534
|
+
return {
|
|
535
|
+
type: 'element',
|
|
536
|
+
name: elementName,
|
|
537
|
+
attributes: {
|
|
538
|
+
name: data.name
|
|
539
|
+
},
|
|
540
|
+
children: data.value
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
normalizeRepository (data: Models.PropertyRepository, options: NormalizerOptions, elementName: string): SimpleXml.Element[] {
|
|
545
|
+
return (
|
|
546
|
+
options.sortLists ?? false
|
|
547
|
+
? data.sorted()
|
|
548
|
+
: Array.from(data)
|
|
549
|
+
).map(p => this.normalize(p, options, elementName))
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
520
553
|
export class DependencyGraphNormalizer extends Base {
|
|
521
554
|
normalize (data: Models.Bom, options: NormalizerOptions, elementName: string): SimpleXml.Element | undefined {
|
|
522
555
|
const allRefs = new Map<Models.BomRef, Models.BomRefRepository>()
|