Skip to content

Commit faa6b2e

Browse files
committed
prep structures
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent d868be7 commit faa6b2e

File tree

8 files changed

+207
-0
lines changed

8 files changed

+207
-0
lines changed

src/index.node.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export * from './index.common'
2424
export * as Builders from './builders/index.node'
2525
export * as Factories from './factories/index.node'
2626
export * as Serialize from './serialize/index.node'
27+
export * as Validation from './validation/index.node'
2728

2829
/**
2930
* Internal, until the resources-module was finalized and shows any value

src/validation/errors.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 class ValidationError extends Error {
21+
readonly #details: any | undefined
22+
23+
constructor (message?: string, details?: any) {
24+
super(message)
25+
this.#details = details
26+
}
27+
28+
get details (): any | undefined {
29+
return this.#details
30+
}
31+
}

src/validation/index.node.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 './errors'
21+
export * from './validator'
22+
export * as Validators from './validators'

src/validation/validator.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
* @throws {@link Validation.ValidationError | ValidationError} in case of validation errors
23+
*/
24+
validate: (data: any) => void
25+
}

src/validation/validators/_helpers.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
import {Version} from "../../spec";
21+
import {Validator} from "../validator";
22+
23+
export abstract class BaseValidator implements Validator {
24+
readonly #version: Version;
25+
26+
constructor(version: Version) {
27+
this.#version = version
28+
}
29+
30+
get version(): Version {
31+
return this.#version
32+
}
33+
34+
abstract validate(data: any): void
35+
}

src/validation/validators/index.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 './json'
21+
export * from './xml'

src/validation/validators/json.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
import { ValidationError } from '../errors'
21+
import { BaseValidator } from './_helpers'
22+
23+
export class JsonValidator extends BaseValidator {
24+
/**
25+
* @throws {@link Validation.ValidationError | ValidationError} in case of validation errors
26+
*/
27+
validate (data: any): void {
28+
// TODO
29+
throw new ValidationError('not implemented')
30+
}
31+
}
32+
33+
export class JsonStrictValidator extends BaseValidator {
34+
/**
35+
* @throws {@link Validation.ValidationError | ValidationError} in case of validation errors
36+
*/
37+
validate (data: any): void {
38+
// TODO
39+
throw new ValidationError('not implemented')
40+
}
41+
}

src/validation/validators/xml.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
import { ValidationError } from '../errors'
21+
import { BaseValidator } from './_helpers'
22+
23+
export class XmlValidator extends BaseValidator {
24+
/**
25+
* @throws {@link Validation.ValidationError | ValidationError} in case of validation errors
26+
*/
27+
validate (data: any): void {
28+
// TODO
29+
throw new ValidationError('not implemented')
30+
}
31+
}

0 commit comments

Comments
 (0)