|
1 | 1 | import { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema'; |
2 | 2 | import { ErrorObject } from 'ajv'; |
3 | 3 |
|
4 | | -type Schema = JSONSchema4 | JSONSchema6 | JSONSchema7; |
5 | | -type PostFormatter = (formattedError: string, error: ErrorObject) => string; |
6 | | - |
7 | 4 | declare namespace SchemaUtils { |
| 5 | + type Schema = JSONSchema4 | JSONSchema6 | JSONSchema7; |
| 6 | + type SchemaUtilErrorObject = ErrorObject & { |
| 7 | + children?: SchemaUtilErrorObject[]; |
| 8 | + }; |
| 9 | + type PostFormatter = ( |
| 10 | + formattedError: string, |
| 11 | + error: SchemaUtilErrorObject |
| 12 | + ) => string; |
| 13 | + |
| 14 | + interface ValidationErrorConfiguration { |
| 15 | + name: string; |
| 16 | + baseDataPath: string; |
| 17 | + postFormatter: PostFormatter; |
| 18 | + } |
| 19 | + |
8 | 20 | class ValidationError extends Error { |
9 | 21 | constructor( |
10 | | - errors: Array<ErrorObject>, |
| 22 | + errors: Array<SchemaUtilErrorObject>, |
11 | 23 | schema: Schema, |
12 | 24 | configuration?: Partial<ValidationErrorConfiguration> |
13 | 25 | ); |
14 | 26 |
|
15 | 27 | name: string; |
16 | | - errors: Array<ErrorObject>; |
| 28 | + errors: Array<SchemaUtilErrorObject>; |
17 | 29 | schema: Schema; |
18 | 30 | headerName: string; |
19 | 31 | baseDataPath: string; |
20 | 32 | postFormatter: PostFormatter | null; |
21 | 33 | message: string; |
22 | 34 | } |
23 | | - |
24 | | - interface ValidationErrorConfiguration { |
25 | | - name: string; |
26 | | - baseDataPath: string; |
27 | | - postFormatter: PostFormatter; |
28 | | - } |
29 | 35 | } |
30 | 36 |
|
31 | | -declare var validate: { |
| 37 | +declare const validate: { |
32 | 38 | ( |
33 | | - schema: Schema, |
| 39 | + schema: SchemaUtils.Schema, |
34 | 40 | options: Array<object> | object, |
35 | 41 | configuration?: Partial<SchemaUtils.ValidationErrorConfiguration> |
36 | 42 | ): void; |
|
0 commit comments