1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { ErrorObject, Format } from 'ajv';
|
9 | import { Observable, ObservableInput } from 'rxjs';
|
10 | import { JsonArray, JsonObject, JsonValue } from '../utils';
|
11 | export 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 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): Promise<SchemaValidatorResult>;
|
27 | }
|
28 | export 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 type PromptProvider = (definitions: Array<PromptDefinition>) => ObservableInput<{
|
54 | [id: string]: JsonValue;
|
55 | }>;
|
56 | export interface SchemaRegistry {
|
57 | compile(schema: Object): Promise<SchemaValidator>;
|
58 |
|
59 | ɵflatten(schema: JsonObject | string): Promise<JsonObject>;
|
60 | addFormat(format: SchemaFormat): void;
|
61 | addSmartDefaultProvider<T>(source: string, provider: SmartDefaultProvider<T>): void;
|
62 | usePromptProvider(provider: PromptProvider): void;
|
63 | useXDeprecatedProvider(onUsage: (message: string) => void): void;
|
64 | |
65 |
|
66 |
|
67 |
|
68 |
|
69 | addPreTransform(visitor: JsonVisitor, deps?: JsonVisitor[]): void;
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | addPostTransform(visitor: JsonVisitor, deps?: JsonVisitor[]): void;
|
78 | }
|
79 | export interface JsonSchemaVisitor {
|
80 | (current: JsonObject | JsonArray, pointer: JsonPointer, parentSchema?: JsonObject | JsonArray, index?: string): void;
|
81 | }
|
82 | export interface JsonVisitor {
|
83 | (value: JsonValue, pointer: JsonPointer, schema?: JsonObject, root?: JsonObject | JsonArray): Observable<JsonValue> | JsonValue;
|
84 | }
|