UNPKG

3.41 kBTypeScriptView Raw
1import { PreferenceItem } from '../../common/preferences/preference-schema';
2import { JSONObject, JSONValue } from '../../../shared/@phosphor/coreutils';
3import { PreferenceSchemaProvider } from './preference-contribution';
4import { PreferenceLanguageOverrideService } from './preference-language-override-service';
5import { IJSONSchema, JsonType } from '../../common/json-schema';
6export interface PreferenceValidator<T> {
7 name: string;
8 validate(value: unknown): T;
9}
10export interface ValidatablePreference extends IJSONSchema, Pick<PreferenceItem, 'defaultValue'> {
11}
12export declare type ValueValidator = (value: JSONValue) => JSONValue;
13export interface PreferenceValidationResult<T extends JSONValue> {
14 original: JSONValue | undefined;
15 valid: T;
16 messages: string[];
17}
18declare type ValidatablePreferenceTuple = ValidatablePreference & ({
19 items: ValidatablePreference[];
20} | {
21 prefixItems: ValidatablePreference[];
22});
23export declare class PreferenceValidationService {
24 protected readonly schemaProvider: PreferenceSchemaProvider;
25 protected readonly languageOverrideService: PreferenceLanguageOverrideService;
26 validateOptions(options: Record<string, JSONValue>): Record<string, JSONValue>;
27 validateByName(preferenceName: string, value: JSONValue): JSONValue;
28 protected doValidateByName(preferenceName: string, value: JSONValue): JSONValue;
29 validateBySchema(key: string, value: JSONValue, schema: ValidatablePreference | undefined): JSONValue;
30 protected getSchema(name: string): ValidatablePreference | undefined;
31 protected validateMultiple(key: string, value: JSONValue, schema: ValidatablePreference & {
32 type: JsonType[];
33 }): JSONValue;
34 protected validateAnyOf(key: string, value: JSONValue, schema: ValidatablePreference & {
35 anyOf: ValidatablePreference[];
36 }): JSONValue;
37 protected validateOneOf(key: string, value: JSONValue, schema: ValidatablePreference & {
38 oneOf: ValidatablePreference[];
39 }): JSONValue;
40 protected mapValidators(key: string, value: JSONValue, validators: Iterable<(value: JSONValue) => JSONValue>): JSONValue;
41 protected validateArray(key: string, value: JSONValue, schema: ValidatablePreference): JSONValue[];
42 protected validateTuple(key: string, value: JSONValue, schema: ValidatablePreferenceTuple): JSONValue[];
43 protected validateConst(key: string, value: JSONValue, schema: ValidatablePreference & {
44 const: JSONValue;
45 }): JSONValue;
46 protected validateEnum(key: string, value: JSONValue, schema: ValidatablePreference & {
47 enum: JSONValue[];
48 }): JSONValue;
49 protected validateBoolean(key: string, value: JSONValue, schema: ValidatablePreference): boolean;
50 protected validateInteger(key: string, value: JSONValue, schema: ValidatablePreference): number;
51 protected validateNumber(key: string, value: JSONValue, schema: ValidatablePreference): number;
52 protected validateObject(key: string, value: JSONValue, schema: ValidatablePreference): JSONObject;
53 protected objectMatchesSchema(key: string, value: JSONValue, schema: ValidatablePreference): value is JSONObject;
54 protected validateString(key: string, value: JSONValue, schema: ValidatablePreference): string;
55 protected getDefaultFromSchema(schema: ValidatablePreference): JSONValue;
56}
57export {};
58//# sourceMappingURL=preference-validation-service.d.ts.map
\No newline at end of file