Skip to content

Commit 9e0d6d4

Browse files
authored
renamed HashRepository -> HashDictionary (#229)
rename HashRepository -> HashDictionary Signed-off-by: Jan Kowalleck <[email protected]>
1 parent dbd3979 commit 9e0d6d4

File tree

11 files changed

+34
-22
lines changed

11 files changed

+34
-22
lines changed

HISTORY.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
## unreleased
66

7+
## 1.5.0 - 2022-09-17
8+
9+
* Deprecated
10+
* The class `HashRepository` will be known as `HashDictionary`. (via [#229])
11+
12+
[#229]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/229
13+
714
## 1.4.2 - 2022-09-10
815

916
Maintenance release.
@@ -196,7 +203,7 @@ Initial release.
196203
* `BomRef`, `BomRefRepository`
197204
* `Component`, `ComponentRepository`
198205
* `ExternalReference`, `ExternalReferenceRepository`
199-
* `HashContent`, `Hash`, `HashRepository`
206+
* `HashContent`, `Hash`, `HashDictionary`
200207
* `LicenseExpression`, `NamedLicense`, `SpdxLicense`, `LicenseRepository`
201208
* `Metadata`
202209
* `OrganizationalContact`, `OrganizationalContactRepository`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ written in _TypeScript_ and compiled for the target.
4444
* `BomRef`, `BomRefRepository`
4545
* `Component`, `ComponentRepository`
4646
* `ExternalReference`, `ExternalReferenceRepository`
47-
* `Hash`, `HashRepository`, `HashContent`
47+
* `Hash`, `HashDictionary`, `HashContent`
4848
* `LicenseExpression`, `NamedLicense`, `SpdxLicense`, `LicenseRepository`
4949
* `Metadata`
5050
* `OrganizationalContact`, `OrganizationalContactRepository`

src/models/component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { treeIteratorSymbol } from '../helpers/tree'
2525
import { CPE, isCPE } from '../types'
2626
import { BomRef, BomRefRepository } from './bomRef'
2727
import { ExternalReferenceRepository } from './externalReference'
28-
import { HashRepository } from './hash'
28+
import { HashDictionary } from './hash'
2929
import { LicenseRepository } from './license'
3030
import { OrganizationalEntity } from './organizationalEntity'
3131
import { PropertyRepository } from './property'
@@ -60,7 +60,7 @@ export class Component implements Comparable {
6060
description?: string
6161
externalReferences: ExternalReferenceRepository
6262
group?: string
63-
hashes: HashRepository
63+
hashes: HashDictionary
6464
licenses: LicenseRepository
6565
publisher?: string
6666
purl?: PackageURL
@@ -90,7 +90,7 @@ export class Component implements Comparable {
9090
this.copyright = op.copyright
9191
this.externalReferences = op.externalReferences ?? new ExternalReferenceRepository()
9292
this.group = op.group
93-
this.hashes = op.hashes ?? new HashRepository()
93+
this.hashes = op.hashes ?? new HashDictionary()
9494
this.licenses = op.licenses ?? new LicenseRepository()
9595
this.publisher = op.publisher
9696
this.purl = op.purl

src/models/hash.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,25 @@ import { HashAlgorithm } from '../enums'
2323
export type HashContent = string
2424

2525
export type Hash = readonly [
26-
// order matters: it must reflect [key, value] of HashRepository -
27-
// this way a HashRepository can be constructed from multiple Hash objects.
26+
// order matters: it must reflect [key, value] of HashDictionary -
27+
// this way a HashDictionary can be constructed from multiple Hash objects.
2828
algorithm: HashAlgorithm,
2929
content: HashContent
3030
]
3131

32-
export class HashRepository extends Map<Hash[0], Hash[1]> {
32+
/** @since 1.5.0 */
33+
export class HashDictionary extends Map<Hash[0], Hash[1]> {
3334
#compareItems ([a1, c1]: Hash, [a2, c2]: Hash): number {
34-
/* eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
35+
/* eslint-disable @typescript-eslint/strict-boolean-expressions -- run compares in weighted order */
3536
return a1.localeCompare(a2) ||
3637
c1.localeCompare(c2)
38+
/* eslint-enable @typescript-eslint/strict-boolean-expressions */
3739
}
3840

3941
sorted (): Hash[] {
4042
return Array.from(this.entries()).sort(this.#compareItems)
4143
}
4244
}
45+
46+
/** @deprecated use {@see HashDictionary} instead of {@link HashRepository} */
47+
export class HashRepository extends HashDictionary {}

src/models/tool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
1919

2020
import { Comparable, SortableSet } from '../helpers/sortableSet'
2121
import { ExternalReferenceRepository } from './externalReference'
22-
import { HashRepository } from './hash'
22+
import { HashDictionary } from './hash'
2323

2424
interface OptionalProperties {
2525
vendor?: Tool['vendor']
@@ -33,14 +33,14 @@ export class Tool implements Comparable {
3333
vendor?: string
3434
name?: string
3535
version?: string
36-
hashes: HashRepository
36+
hashes: HashDictionary
3737
externalReferences: ExternalReferenceRepository
3838

3939
constructor (op: OptionalProperties = {}) {
4040
this.vendor = op.vendor
4141
this.name = op.name
4242
this.version = op.version
43-
this.hashes = op.hashes ?? new HashRepository()
43+
this.hashes = op.hashes ?? new HashDictionary()
4444
this.externalReferences = op.externalReferences ?? new ExternalReferenceRepository()
4545
}
4646

src/serialize/json/normalize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class HashNormalizer extends Base {
198198
: undefined
199199
}
200200

201-
normalizeRepository (data: Models.HashRepository, options: NormalizerOptions): Normalized.Hash[] {
201+
normalizeRepository (data: Models.HashDictionary, options: NormalizerOptions): Normalized.Hash[] {
202202
return (
203203
options.sortLists ?? false
204204
? data.sorted()

src/serialize/xml/normalize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export class HashNormalizer extends Base {
255255
: undefined
256256
}
257257

258-
normalizeRepository (data: Models.HashRepository, options: NormalizerOptions, elementName: string): SimpleXml.Element[] {
258+
normalizeRepository (data: Models.HashDictionary, options: NormalizerOptions, elementName: string): SimpleXml.Element[] {
259259
return (
260260
options.sortLists ?? false
261261
? data.sorted()

tests/_data/models.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports.createComplexStructure = function () {
3838
vendor: 'tool vendor',
3939
name: 'tool name',
4040
version: '0.8.15',
41-
hashes: new Models.HashRepository([
41+
hashes: new Models.HashDictionary([
4242
[Enums.HashAlgorithm.MD5, 'f32a26e2a3a8aa338cd77b6e1263c535'],
4343
[Enums.HashAlgorithm['SHA-1'], '829c3804401b0727f70f73d4415e162400cbe57b']
4444
])

tests/integration/Factories.FromNodePackageJson.PackageUrlFactory.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ suite('Factories.FromNodePackageJson.PackageUrlFactory', () => {
199199
new Models.ExternalReference('', Enums.ExternalReferenceType.VCS),
200200
new Models.ExternalReference('', Enums.ExternalReferenceType.Distribution)
201201
]),
202-
hashes: new Models.HashRepository([
202+
hashes: new Models.HashDictionary([
203203
[Enums.HashAlgorithm['SHA-256'], 'C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2']
204204
])
205205
}
@@ -219,7 +219,7 @@ suite('Factories.FromNodePackageJson.PackageUrlFactory', () => {
219219
externalReferences: new Models.ExternalReferenceRepository([
220220
new Models.ExternalReference('git+https://foo.bar/repo.git', Enums.ExternalReferenceType.VCS)
221221
]),
222-
hashes: new Models.HashRepository([
222+
hashes: new Models.HashDictionary([
223223
[Enums.HashAlgorithm['SHA-256'], 'C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2']
224224
])
225225
}
@@ -239,7 +239,7 @@ suite('Factories.FromNodePackageJson.PackageUrlFactory', () => {
239239
externalReferences: new Models.ExternalReferenceRepository([
240240
new Models.ExternalReference('git+https://foo.bar/repo.git', Enums.ExternalReferenceType.VCS)
241241
]),
242-
hashes: new Models.HashRepository([
242+
hashes: new Models.HashDictionary([
243243
[Enums.HashAlgorithm['SHA-256'], 'C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2'],
244244
[Enums.HashAlgorithm.BLAKE3, 'aa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d']
245245
])

tests/integration/Factories.PackageUrlFactory.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ suite('Factories.PackageUrlFactory', () => {
140140
Enums.ComponentType.Library,
141141
`name-${salt}`,
142142
{
143-
hashes: new Models.HashRepository([
143+
hashes: new Models.HashDictionary([
144144
[Enums.HashAlgorithm['SHA-256'], 'C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2']
145145
])
146146
}
@@ -161,7 +161,7 @@ suite('Factories.PackageUrlFactory', () => {
161161
new Models.ExternalReference('git+https://foo.bar/repo.git', Enums.ExternalReferenceType.VCS),
162162
new Models.ExternalReference('https://foo.bar/download', Enums.ExternalReferenceType.Distribution)
163163
]),
164-
hashes: new Models.HashRepository([
164+
hashes: new Models.HashDictionary([
165165
[Enums.HashAlgorithm['SHA-256'], 'C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2'],
166166
[Enums.HashAlgorithm.BLAKE3, 'aa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d']
167167
])

0 commit comments

Comments
 (0)