File tree Expand file tree Collapse file tree 4 files changed +35
-1
lines changed
Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ export type {
2323 ExternalReference ,
2424 Hash ,
2525 License ,
26+ SPDX23 ,
27+ SupportedBom ,
2628} from './types/index.mjs' ;
2729
2830export { ComponentScope } from './types/index.mjs' ;
31+ export { isCdxBom , isSpdxBom , isSupportedBom } from './bom/validation.mjs' ;
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ export interface EolReport {
3737}
3838
3939export interface EolReportQueryResponse {
40- eol : { report : { result : EolReport | null } } ;
40+ eol : { report : { report : EolReport | null } } ;
4141}
4242
4343export interface EolReportMutationResponse {
Original file line number Diff line number Diff line change 11import * as CDX from '@cyclonedx/cyclonedx-library' ;
2+ import type { SPDX23 } from './bom/spdx-2.3.schema.ts' ;
23
34export type CdxBom = CDX . Serialize . JSON . Types . Normalized . Bom ;
45export type Component = CDX . Serialize . JSON . Types . Normalized . Component ;
@@ -8,4 +9,7 @@ export type License = CDX.Serialize.JSON.Types.Normalized.License;
89export type ExternalReference =
910 CDX . Serialize . JSON . Types . Normalized . ExternalReference ;
1011
12+ export type { SPDX23 } ;
13+ export type SupportedBom = CdxBom | SPDX23 ;
14+
1115export const ComponentScope = CDX . Enums . ComponentScope ;
You can’t perform that action at this time.
0 commit comments