Skip to content

Commit 8a93e14

Browse files
committed
namespace adjusts for validation
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 3bc26cd commit 8a93e14

14 files changed

+87
-21
lines changed

src/index.web.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ export * from './index.common'
2323

2424
export * as Factories from './factories/index.web'
2525
export * as Serialize from './serialize/index.web'
26+
export * as Validation from './validation/index.web'
2627

2728
// endregion web-specifics

src/validation/validator.ts renamed to src/validation/baseValidator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface Validator {
2929
validate: (data: string) => Promise<void>
3030
}
3131

32-
export abstract class BaseValidator implements Validator {
32+
export abstract class BaseValidator implements BaseValidator {
3333
readonly #version: Version
3434

3535
constructor (version: Version) {

src/validation/validators/index.ts renamed to src/validation/index.common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20-
export * from './json'
21-
export * from './xml'
20+
export * from './errors'
21+
export * from './types'

src/validation/index.node.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20-
export * from './errors'
21-
export type { Validator } from './validator'
22-
export * as Validators from './validators'
20+
export * from './index.common'
21+
22+
// region node-specifics
23+
24+
export * from './jsonValidator'
25+
export * from './xmlValidator.node'
26+
27+
// endregion node-specifics

src/validation/index.web.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
export * from './index.common'
21+
22+
// region web-specifics
23+
24+
// json validator is experimental, and not public to web, yet
25+
// export * from './jsonValidator'
26+
27+
// there is no XML validator for the web, yet
28+
29+
// endregion web-specifics

src/validation/validators/json.ts renamed to src/validation/jsonValidator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import type Ajv from 'ajv'
2121
import { type ValidateFunction } from 'ajv'
2222
import { readFile } from 'fs/promises'
2323

24-
import { FILES } from '../../resources.node'
25-
import { MissingOptionalDependencyError, NotImplementedError, ValidationError } from '../errors'
26-
import { BaseValidator } from '../validator'
24+
import { FILES } from '../resources.node'
25+
import { BaseValidator } from './baseValidator'
26+
import { MissingOptionalDependencyError, NotImplementedError, ValidationError } from './errors'
2727

2828
let _ajv: Ajv | undefined
2929

src/validation/types.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
export interface Validator {
21+
/**
22+
* Promise rejects with one of the following
23+
* - {@link Validation.NotImplementedError | NotImplementedError} when there is no validator available for `this.version`
24+
* - {@link Validation.MissingOptionalDependencyError | MissingOptionalDependencyError} when a required dependency was not installed
25+
* - {@link Validation.ValidationError | ValidationError} when `data` was invalid to the schema
26+
*/
27+
validate: (data: string) => Promise<void>
28+
}

src/validation/validators/xml.ts renamed to src/validation/xmlValidator.node.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import { readFile } from 'fs/promises'
2121
import type { Document, ParserOptions, parseXml } from 'libxmljs2'
2222
import { pathToFileURL } from 'url'
2323

24-
import { FILES } from '../../resources.node'
25-
import { MissingOptionalDependencyError, NotImplementedError, ValidationError } from '../errors'
26-
import { BaseValidator } from '../validator'
24+
import { FILES } from '../resources.node'
25+
import { BaseValidator } from './baseValidator'
26+
import { MissingOptionalDependencyError, NotImplementedError, ValidationError } from './errors'
2727

2828
let _parser: typeof parseXml | undefined
2929

tests/integration/Serialize.JsonSerialize.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const {
3232
Spec: { Spec1dot2, Spec1dot3, Spec1dot4 },
3333
Validation: {
3434
ValidationError, MissingOptionalDependencyError,
35-
Validators: { JsonStrictValidator }
35+
JsonStrictValidator
3636
}
3737
} = require('../../')
3838

tests/integration/Serialize.XmlSerialize.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const {
3232
Spec: { Spec1dot2, Spec1dot3, Spec1dot4 },
3333
Validation: {
3434
ValidationError, MissingOptionalDependencyError,
35-
Validators: { XmlValidator }
35+
XmlValidator
3636
}
3737
} = require('../../')
3838

0 commit comments

Comments
 (0)