1 | import { AnyJson, JsonMap } from '@salesforce/ts-types';
|
2 | import { Logger } from '../logger/logger';
|
3 | /**
|
4 | * Loads a JSON schema and performs validations against JSON objects.
|
5 | */
|
6 | export declare class SchemaValidator {
|
7 | private schemaPath;
|
8 | private readonly schemasDir;
|
9 | private readonly logger;
|
10 | private schema?;
|
11 | /**
|
12 | * Creates a new `SchemaValidator` instance given a logger and path to a schema file.
|
13 | *
|
14 | * @param logger An {@link Logger} instance on which to base this class's logger.
|
15 | * @param schemaPath The path to the schema file to load and use for validation.
|
16 | */
|
17 | constructor(logger: Logger, schemaPath: string);
|
18 | /**
|
19 | * Loads a JSON schema from the `schemaPath` parameter provided at instantiation.
|
20 | */
|
21 | load(): Promise<JsonMap>;
|
22 | /**
|
23 | * Loads a JSON schema from the `schemaPath` parameter provided at instantiation.
|
24 | */
|
25 | loadSync(): JsonMap;
|
26 | /**
|
27 | * Performs validation of JSON data against the schema located at the `schemaPath` value provided
|
28 | * at instantiation.
|
29 | *
|
30 | * **Throws** *{'ValidationSchemaFieldError' }* If there are known validations errors.
SfError}{ name: |
31 | * **Throws** *{'ValidationSchemaUnknownError' }* If there are unknown validations errors.
SfError}{ name: |
32 | *
|
33 | * @param json A JSON value to validate against this instance's target schema.
|
34 | * JSON data.
The validated |
35 | */
|
36 | validate(json: AnyJson): Promise<AnyJson>;
|
37 | /**
|
38 | * Performs validation of JSON data against the schema located at the `schemaPath` value provided
|
39 | * at instantiation.
|
40 | *
|
41 | * **Throws** *{@link SfError}{ name: 'ValidationSchemaFieldError' }* If there are known validations errors.
|
42 | * **Throws** *{@link SfError}{ name: 'ValidationSchemaUnknownError' }* If there are unknown validations errors.
|
43 | *
|
44 | * @param json A JSON value to validate against this instance's target schema.
|
45 | * @returns The validated JSON data.
|
46 | */
|
47 | validateSync<T extends AnyJson>(json: T): T;
|
48 | /**
|
49 | * Loads local, external schemas from URIs in the same directory as the local schema file.
|
50 | * Does not support loading from remote URIs.
|
51 | * Returns a map of external schema local URIs to loaded schema JSON objects.
|
52 | *
|
53 | * @param schema The main schema to look up references ($ref) in.
|
54 | * @returns An array of found referenced schemas.
|
55 | */
|
56 | private loadExternalSchemas;
|
57 | /**
|
58 | * Load another schema relative to the primary schema when referenced. Only supports local schema URIs.
|
59 | *
|
60 | * @param uri The first segment of the $ref schema.
|
61 | */
|
62 | private loadExternalSchema;
|
63 | /**
|
64 | * Get a string representation of the schema validation errors.
|
65 | * Adds additional (human friendly) information to certain errors.
|
66 | *
|
67 | * @param errors An array of AJV (DefinedError) objects.
|
68 | */
|
69 | private getErrorsText;
|
70 | }
|