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 | */
|
---|
8 | import { ErrorObject, Format } from 'ajv';
|
---|
9 | import { Observable, SubscribableOrPromise } from 'rxjs';
|
---|
10 | import { JsonArray, JsonObject, JsonValue } from '../interface';
|
---|
11 | export declare type JsonPointer = string & {
|
---|
12 | __PRIVATE_DEVKIT_JSON_POINTER: void;
|
---|
13 | };
|
---|
14 | export interface SchemaValidatorResult {
|
---|
15 | data: JsonValue;
|
---|
16 | success: boolean;
|
---|
17 | errors?: SchemaValidatorError[];
|
---|
18 | }
|
---|
19 | export declare type SchemaValidatorError = Partial<ErrorObject>;
|
---|
20 | export interface SchemaValidatorOptions {
|
---|
21 | applyPreTransforms?: boolean;
|
---|
22 | applyPostTransforms?: boolean;
|
---|
23 | withPrompts?: boolean;
|
---|
24 | }
|
---|
25 | export interface SchemaValidator {
|
---|
26 | (data: JsonValue, options?: SchemaValidatorOptions): Observable<SchemaValidatorResult>;
|
---|
27 | }
|
---|
28 | export declare type SchemaFormatter = Format;
|
---|
29 | export interface SchemaFormat {
|
---|
30 | name: string;
|
---|
31 | formatter: SchemaFormatter;
|
---|
32 | }
|
---|
33 | export interface SmartDefaultProvider<T> {
|
---|
34 | (schema: JsonObject): T | Observable<T>;
|
---|
35 | }
|
---|
36 | export interface SchemaKeywordValidator {
|
---|
37 | (data: JsonValue, schema: JsonValue, parent: JsonObject | JsonArray | undefined, parentProperty: string | number | undefined, pointer: JsonPointer, rootData: JsonValue): boolean | Observable<boolean>;
|
---|
38 | }
|
---|
39 | export interface PromptDefinition {
|
---|
40 | id: string;
|
---|
41 | type: string;
|
---|
42 | message: string;
|
---|
43 | default?: string | string[] | number | boolean | null;
|
---|
44 | validator?: (value: JsonValue) => boolean | string | Promise<boolean | string>;
|
---|
45 | items?: Array<string | {
|
---|
46 | value: JsonValue;
|
---|
47 | label: string;
|
---|
48 | }>;
|
---|
49 | raw?: string | JsonObject;
|
---|
50 | multiselect?: boolean;
|
---|
51 | propertyTypes: Set<string>;
|
---|
52 | }
|
---|
53 | export declare type PromptProvider = (definitions: Array<PromptDefinition>) => SubscribableOrPromise<{
|
---|
54 | [id: string]: JsonValue;
|
---|
55 | }>;
|
---|
56 | export interface SchemaRegistry {
|
---|
57 | compile(schema: Object): Observable<SchemaValidator>;
|
---|
58 | /**
|
---|
59 | * @deprecated since 11.2 without replacement.
|
---|
60 | * Producing a flatten schema document does not in all cases produce a schema with identical behavior to the original.
|
---|
61 | * See: https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.appendix.B.2
|
---|
62 | */
|
---|
63 | flatten(schema: JsonObject | string): Observable<JsonObject>;
|
---|
64 | addFormat(format: SchemaFormat): void;
|
---|
65 | addSmartDefaultProvider<T>(source: string, provider: SmartDefaultProvider<T>): void;
|
---|
66 | usePromptProvider(provider: PromptProvider): void;
|
---|
67 | useXDeprecatedProvider(onUsage: (message: string) => void): void;
|
---|
68 | /**
|
---|
69 | * Add a transformation step before the validation of any Json.
|
---|
70 | * @param {JsonVisitor} visitor The visitor to transform every value.
|
---|
71 | * @param {JsonVisitor[]} deps A list of other visitors to run before.
|
---|
72 | */
|
---|
73 | addPreTransform(visitor: JsonVisitor, deps?: JsonVisitor[]): void;
|
---|
74 | /**
|
---|
75 | * Add a transformation step after the validation of any Json. The JSON will not be validated
|
---|
76 | * after the POST, so if transformations are not compatible with the Schema it will not result
|
---|
77 | * in an error.
|
---|
78 | * @param {JsonVisitor} visitor The visitor to transform every value.
|
---|
79 | * @param {JsonVisitor[]} deps A list of other visitors to run before.
|
---|
80 | */
|
---|
81 | addPostTransform(visitor: JsonVisitor, deps?: JsonVisitor[]): void;
|
---|
82 | }
|
---|
83 | export interface JsonSchemaVisitor {
|
---|
84 | (current: JsonObject | JsonArray, pointer: JsonPointer, parentSchema?: JsonObject | JsonArray, index?: string): void;
|
---|
85 | }
|
---|
86 | export interface JsonVisitor {
|
---|
87 | (value: JsonValue, pointer: JsonPointer, schema?: JsonObject, root?: JsonObject | JsonArray): Observable<JsonValue> | JsonValue;
|
---|
88 | }
|
---|