Skip to content

Commit 9697eb8

Browse files
committed
getters for construtor parameters
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 68bd251 commit 9697eb8

14 files changed

+287
-4
lines changed

HISTORY.md

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

55
## unreleased
66

7+
* Added
8+
* Getters/properties that represent the corresponding parameters of class constructor. (via [#])
9+
* `Builders.FromPackageJson.ComponentBuilder.extRefFactory`,
10+
`Builders.FromPackageJson.ComponentBuilder.licenseFactory`
11+
* `Factories.PackageUrlFactory.type`
12+
* `Serialize.JsonSerializer.normalizerFactory`
13+
* `Serialize.XmlBaseSerializer.normalizerFactory`,
14+
`Serialize.XmlSerializer.normalizerFactory`
15+
16+
[#]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/
17+
718
## 1.1.0 - 2022-07-29
819

920
* Added

src/builders/fromPackageJson.node.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export class ToolBuilder {
3333
this.#extRefFactory = extRefFactory
3434
}
3535

36+
get extRefFactory (): Factories.FromPackageJson.ExternalReferenceFactory {
37+
return this.#extRefFactory
38+
}
39+
3640
makeTool (data: PackageJson): Models.Tool | undefined {
3741
const [name, vendor] = typeof data.name === 'string'
3842
? splitNameGroup(data.name)
@@ -61,6 +65,14 @@ export class ComponentBuilder {
6165
this.#licenseFactory = licenseFactory
6266
}
6367

68+
get extRefFactory (): Factories.FromPackageJson.ExternalReferenceFactory {
69+
return this.#extRefFactory
70+
}
71+
72+
get licenseFactory (): Factories.LicenseFactory {
73+
return this.#licenseFactory
74+
}
75+
6476
makeComponent (data: PackageJson, type: Enums.ComponentType = Enums.ComponentType.Library): Models.Component | undefined {
6577
if (typeof data.name !== 'string') {
6678
return undefined

src/factories/packageUrl.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ import { PackageURL } from 'packageurl-js'
2222
import { ExternalReferenceType } from '../enums'
2323

2424
export class PackageUrlFactory {
25-
readonly #type: string
25+
readonly #type: PackageURL['type']
2626

2727
constructor (type: PackageURL['type']) {
2828
this.#type = type
2929
}
3030

31+
get type (): PackageURL['type'] {
32+
return this.#type
33+
}
34+
3135
makeFromComponent (component: Component): PackageURL | undefined {
32-
const qualifiers: { [key: string]: string } = {}
33-
let subpath: string | undefined
36+
const qualifiers: PackageURL['qualifiers'] = {}
37+
let subpath: PackageURL['subpath']
38+
39+
// @TODO add qualifiers.checksum based on hashes
3440

3541
for (const e of component.externalReferences) {
3642
if (e.type === ExternalReferenceType.VCS) {

src/serialize/json/normalize.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ abstract class Base implements Normalizer {
104104
this._factory = factory
105105
}
106106

107+
get factory (): Factory {
108+
return this._factory
109+
}
110+
107111
abstract normalize (data: object, options: NormalizerOptions): object | undefined
108112
}
109113

src/serialize/jsonSerializer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export class JsonSerializer extends BaseSerializer<Normalized.Bom> {
4242
this.#normalizerFactory = normalizerFactory
4343
}
4444

45+
get normalizerFactory (): NormalizerFactory {
46+
return this.#normalizerFactory
47+
}
48+
4549
protected _normalize (
4650
bom: Bom,
4751
options: NormalizerOptions = {}

src/serialize/xml/normalize.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ abstract class Base implements Normalizer {
104104
this._factory = factory
105105
}
106106

107+
get factory (): Factory {
108+
return this._factory
109+
}
110+
107111
/**
108112
* @param {*} data
109113
* @param {NormalizerOptions} options

src/serialize/xmlBaseSerializer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export abstract class XmlBaseSerializer extends BaseSerializer<SimpleXml.Element
4242
this.#normalizerFactory = normalizerFactory
4343
}
4444

45+
get normalizerFactory (): NormalizerFactory {
46+
return this.#normalizerFactory
47+
}
48+
4549
protected _normalize (
4650
bom: Bom,
4751
options: NormalizerOptions = {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict'
2+
/*!
3+
This file is part of CycloneDX JavaScript Library.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
SPDX-License-Identifier: Apache-2.0
18+
Copyright (c) OWASP Foundation. All Rights Reserved.
19+
*/
20+
21+
const assert = require('assert')
22+
const { suite, test } = require('mocha')
23+
24+
const {
25+
Builders: { FromPackageJson: { ComponentBuilder } },
26+
Factories: {
27+
FromPackageJson: { ExternalReferenceFactory },
28+
LicenseFactory
29+
}
30+
} = require('../../')
31+
32+
suite('Builders.FromPackageJson.ToolBuilder', () => {
33+
test('construct', () => {
34+
const extRefFactory = new ExternalReferenceFactory()
35+
const licenseFactory = new LicenseFactory()
36+
37+
const actual = new ComponentBuilder(extRefFactory, licenseFactory)
38+
39+
assert.strictEqual(actual.extRefFactory, extRefFactory)
40+
assert.strictEqual(actual.licenseFactory, licenseFactory)
41+
})
42+
})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict'
2+
/*!
3+
This file is part of CycloneDX JavaScript Library.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
SPDX-License-Identifier: Apache-2.0
18+
Copyright (c) OWASP Foundation. All Rights Reserved.
19+
*/
20+
21+
const assert = require('assert')
22+
const { suite, test } = require('mocha')
23+
24+
const {
25+
Builders: { FromPackageJson: { ToolBuilder } },
26+
Factories: { FromPackageJson: { ExternalReferenceFactory } }
27+
} = require('../../')
28+
29+
suite('Builders.FromPackageJson.ToolBuilder', () => {
30+
test('construct', () => {
31+
const extRefFactory = new ExternalReferenceFactory()
32+
33+
const actual = new ToolBuilder(extRefFactory)
34+
35+
assert.strictEqual(actual.extRefFactory, extRefFactory)
36+
})
37+
})
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict'
2+
/*!
3+
This file is part of CycloneDX JavaScript Library.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
SPDX-License-Identifier: Apache-2.0
18+
Copyright (c) OWASP Foundation. All Rights Reserved.
19+
*/
20+
21+
const assert = require('assert')
22+
const { suite, test } = require('mocha')
23+
24+
const {
25+
Factories: { PackageUrlFactory }
26+
} = require('../../')
27+
28+
suite('Builders.FromPackageJson.ToolBuilder', () => {
29+
test('construct', () => {
30+
const actual = new PackageUrlFactory('asdf')
31+
32+
assert.strictEqual(actual.type, 'asdf')
33+
})
34+
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict'
2+
/*!
3+
This file is part of CycloneDX JavaScript Library.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
SPDX-License-Identifier: Apache-2.0
18+
Copyright (c) OWASP Foundation. All Rights Reserved.
19+
*/
20+
21+
const assert = require('assert')
22+
const { suite, test } = require('mocha')
23+
24+
const {
25+
Serialize: {
26+
JsonSerializer,
27+
JSON: { Normalize: { Factory } }
28+
},
29+
Spec: { Spec1dot4 }
30+
31+
} = require('../../')
32+
33+
suite('Serialize.JsonSerializer', () => {
34+
test('constructor', () => {
35+
const normalizerFactory = new Factory(Spec1dot4)
36+
37+
const actual = new JsonSerializer(normalizerFactory)
38+
39+
assert.strictEqual(actual.normalizerFactory, normalizerFactory)
40+
})
41+
})
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict'
2+
/*!
3+
This file is part of CycloneDX JavaScript Library.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
SPDX-License-Identifier: Apache-2.0
18+
Copyright (c) OWASP Foundation. All Rights Reserved.
19+
*/
20+
21+
const assert = require('assert')
22+
const { suite, test } = require('mocha')
23+
24+
const {
25+
Serialize: {
26+
XmlBaseSerializer,
27+
XML: { Normalize: { Factory } }
28+
},
29+
Spec: { Spec1dot4 }
30+
31+
} = require('../../')
32+
33+
suite('Serialize.XmlBaseSerializer', () => {
34+
test('constructor', () => {
35+
const normalizerFactory = new Factory(Spec1dot4)
36+
37+
class MySerializer extends XmlBaseSerializer {}
38+
39+
const actual = new MySerializer(normalizerFactory)
40+
41+
assert.strictEqual(actual.normalizerFactory, normalizerFactory)
42+
})
43+
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict'
2+
/*!
3+
This file is part of CycloneDX JavaScript Library.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
SPDX-License-Identifier: Apache-2.0
18+
Copyright (c) OWASP Foundation. All Rights Reserved.
19+
*/
20+
21+
const assert = require('assert')
22+
const { suite, test } = require('mocha')
23+
24+
const {
25+
Serialize: {
26+
XmlSerializer,
27+
XML: { Normalize: { Factory } }
28+
},
29+
Spec: { Spec1dot4 }
30+
31+
} = require('../../')
32+
33+
suite('Serialize.XmlSerializer', () => {
34+
test('constructor', () => {
35+
const normalizerFactory = new Factory(Spec1dot4)
36+
37+
const actual = new XmlSerializer(normalizerFactory)
38+
39+
assert.strictEqual(actual.normalizerFactory, normalizerFactory)
40+
})
41+
})

tests/unit/Types/cpe.spec.js renamed to tests/unit/Types.cpe.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const { suite, test } = require('mocha')
2323

2424
const {
2525
Types: { isCPE }
26-
} = require('../../../')
26+
} = require('../../')
2727

2828
suite('Types.cpe', () => {
2929
suite('isCPE()', () => {

0 commit comments

Comments
 (0)