Skip to content

Commit 894c2ed

Browse files
committed
streamline
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 9efd503 commit 894c2ed

File tree

5 files changed

+20
-42
lines changed

5 files changed

+20
-42
lines changed

src/validation/index.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

2020
export * from './errors'
21-
export * from './validator'
21+
export type { Validator } from './validator'
2222
export * as Validators from './validators'

src/validation/validator.ts

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

20+
import type { Version } from '../spec'
21+
2022
export interface Validator {
2123
/**
2224
* Promise rejects with one of the following
2325
* - {@link Validation.NotImplementedError | NotImplementedError} when there is no validator available for `this.version`
2426
* - {@link Validation.MissingOptionalDependencyError | MissingOptionalDependencyError} when a required dependency was not installed
2527
* - {@link Validation.ValidationError | ValidationError} when `data` was invalid to the schema
2628
*/
27-
validate: (data: any) => Promise<void>
29+
validate: (data: string) => Promise<void>
30+
}
31+
32+
export abstract class BaseValidator implements Validator {
33+
readonly #version: Version
34+
35+
constructor (version: Version) {
36+
this.#version = version
37+
}
38+
39+
get version (): Version {
40+
return this.#version
41+
}
42+
43+
abstract validate (data: string): Promise<void>
2844
}

src/validation/validators/_helpers.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/validation/validators/json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { readFile } from 'fs/promises'
2323

2424
import { FILES } from '../../resources.node'
2525
import { MissingOptionalDependencyError, NotImplementedError, ValidationError } from '../errors'
26-
import { BaseValidator } from './_helpers'
26+
import { BaseValidator } from '../validator'
2727

2828
let _ajv: Ajv | undefined
2929

src/validation/validators/xml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { pathToFileURL } from 'url'
2323

2424
import { FILES } from '../../resources.node'
2525
import { MissingOptionalDependencyError, NotImplementedError, ValidationError } from '../errors'
26-
import { BaseValidator } from './_helpers'
26+
import { BaseValidator } from '../validator'
2727

2828
let _parser: typeof parseXml | undefined
2929

0 commit comments

Comments
 (0)