UNPKG

3.54 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { ValidateFunction } from 'ajv';
9import { Observable } from 'rxjs';
10import { BaseException } from '../../exception';
11import { JsonObject } from '../utils';
12import { JsonVisitor, PromptProvider, SchemaFormat, SchemaRegistry, SchemaValidator, SchemaValidatorError, SmartDefaultProvider } from './interface';
13import { JsonSchema } from './schema';
14export type UriHandler = (uri: string) => Observable<JsonObject> | Promise<JsonObject> | null | undefined;
15export declare class SchemaValidationException extends BaseException {
16 readonly errors: SchemaValidatorError[];
17 constructor(errors?: SchemaValidatorError[], baseMessage?: string);
18 static createMessages(errors?: SchemaValidatorError[]): string[];
19}
20export declare class CoreSchemaRegistry implements SchemaRegistry {
21 private _ajv;
22 private _uriCache;
23 private _uriHandlers;
24 private _pre;
25 private _post;
26 private _currentCompilationSchemaInfo?;
27 private _smartDefaultKeyword;
28 private _promptProvider?;
29 private _sourceMap;
30 constructor(formats?: SchemaFormat[]);
31 private _fetch;
32 /**
33 * Add a transformation step before the validation of any Json.
34 * @param {JsonVisitor} visitor The visitor to transform every value.
35 * @param {JsonVisitor[]} deps A list of other visitors to run before.
36 */
37 addPreTransform(visitor: JsonVisitor, deps?: JsonVisitor[]): void;
38 /**
39 * Add a transformation step after the validation of any Json. The JSON will not be validated
40 * after the POST, so if transformations are not compatible with the Schema it will not result
41 * in an error.
42 * @param {JsonVisitor} visitor The visitor to transform every value.
43 * @param {JsonVisitor[]} deps A list of other visitors to run before.
44 */
45 addPostTransform(visitor: JsonVisitor, deps?: JsonVisitor[]): void;
46 protected _resolver(ref: string, validate?: ValidateFunction): {
47 context?: ValidateFunction;
48 schema?: JsonObject;
49 };
50 /**
51 * Flatten the Schema, resolving and replacing all the refs. Makes it into a synchronous schema
52 * that is also easier to traverse. Does not cache the result.
53 *
54 * Producing a flatten schema document does not in all cases produce a schema with identical behavior to the original.
55 * See: https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.appendix.B.2
56 *
57 * @param schema The schema or URI to flatten.
58 * @returns An Observable of the flattened schema object.
59 * @private since 11.2 without replacement.
60 */
61 ɵflatten(schema: JsonObject): Promise<JsonObject>;
62 /**
63 * Compile and return a validation function for the Schema.
64 *
65 * @param schema The schema to validate. If a string, will fetch the schema before compiling it
66 * (using schema as a URI).
67 */
68 compile(schema: JsonSchema): Promise<SchemaValidator>;
69 private _compile;
70 addFormat(format: SchemaFormat): void;
71 addSmartDefaultProvider<T>(source: string, provider: SmartDefaultProvider<T>): void;
72 registerUriHandler(handler: UriHandler): void;
73 usePromptProvider(provider: PromptProvider): void;
74 private _applyPrompts;
75 private static _set;
76 private _applySmartDefaults;
77 useXDeprecatedProvider(onUsage: (message: string) => void): void;
78 private normalizeDataPathArr;
79}