Skip to content

Commit 2c4c303

Browse files
committed
feat: add basic type assertions and adjust to API change
1 parent 67f08dd commit 2c4c303

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

src/bom/validation.mts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { SPDX23 } from '../types/bom/spdx-2.3.schema.ts';
2+
import type { CdxBom, SupportedBom } from '../types/index.mjs';
3+
4+
function parseBomOrString(bomOrString: string | object): CdxBom | SPDX23 | null {
5+
if (typeof bomOrString === 'string') {
6+
try {
7+
return JSON.parse(bomOrString) as CdxBom | SPDX23;
8+
} catch (e) {
9+
return null;
10+
}
11+
}
12+
return bomOrString as CdxBom | SPDX23;
13+
}
14+
15+
export function isCdxBom(bomOrString: string | object): bomOrString is CdxBom {
16+
const bom = parseBomOrString(bomOrString);
17+
return bom !== null && 'components' in bom;
18+
}
19+
20+
export function isSpdxBom(bomOrString: string | object): bomOrString is SPDX23 {
21+
const bom = parseBomOrString(bomOrString);
22+
return bom !== null && 'SPDXID' in bom && bom.SPDXID === 'SPDX';
23+
}
24+
25+
export function isSupportedBom(bomOrString: string | object): bomOrString is SupportedBom {
26+
return isCdxBom(bomOrString) || isSpdxBom(bomOrString);
27+
}

src/index.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export type {
2323
ExternalReference,
2424
Hash,
2525
License,
26+
SPDX23,
27+
SupportedBom,
2628
} from './types/index.mjs';
2729

2830
export { ComponentScope } from './types/index.mjs';
31+
export { isCdxBom, isSpdxBom, isSupportedBom } from './bom/validation.mjs';

src/types/eol-scan.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface EolReport {
3737
}
3838

3939
export interface EolReportQueryResponse {
40-
eol: { report: { result: EolReport | null } };
40+
eol: { report: { report: EolReport | null } };
4141
}
4242

4343
export interface EolReportMutationResponse {

src/types/index.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as CDX from '@cyclonedx/cyclonedx-library';
2+
import type { SPDX23 } from './bom/spdx-2.3.schema.ts';
23

34
export type CdxBom = CDX.Serialize.JSON.Types.Normalized.Bom;
45
export type Component = CDX.Serialize.JSON.Types.Normalized.Component;
@@ -8,4 +9,7 @@ export type License = CDX.Serialize.JSON.Types.Normalized.License;
89
export type ExternalReference =
910
CDX.Serialize.JSON.Types.Normalized.ExternalReference;
1011

12+
export type { SPDX23 };
13+
export type SupportedBom = CdxBom | SPDX23;
14+
1115
export const ComponentScope = CDX.Enums.ComponentScope;

0 commit comments

Comments
 (0)