joi: add LanguageOptions

This commit is contained in:
Young Rok Kim 2017-08-20 23:39:09 +09:00
parent 88ebedb61f
commit 100bdfd79c
2 changed files with 31 additions and 5 deletions

19
types/joi/index.d.ts vendored
View File

@ -6,6 +6,19 @@
// TODO express type of Schema in a type-parameter (.default, .valid, .example etc)
export type Types = 'any' | 'alternatives' | 'array' | 'string' | 'number' | 'object' | 'boolean' | 'binary' | 'date' | 'function' | 'lazy';
export type LanguageRuleOptions = string | false | {
[key: string]: LanguageRuleOptions;
};
export type LanguageOptions = {
root?: string;
key?: string;
messages?: { wrapArrays?: boolean; };
} & Partial<Record<Types, LanguageRuleOptions>> & {
[key: string]: LanguageRuleOptions;
};
export interface ValidationOptions {
/**
@ -35,7 +48,7 @@ export interface ValidationOptions {
/**
* overrides individual error messages. Defaults to no override ({}).
*/
language?: Object;
language?: LanguageOptions;
/**
* sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'. Defaults to 'optional'.
*/
@ -844,9 +857,7 @@ export interface Extension {
name: string;
base?: Schema;
pre?: (this: AnySchema<AnySchema<Schema>>, params: { [key: string]: any }, value: any, state: State, options: ValidationOptions) => Err | void;
language?: {
[key: string]: string;
},
language?: LanguageRuleOptions;
describe?: (this: AnySchema<AnySchema<Schema>>, description: any) => any;
rules?: Rules[];
}

View File

@ -53,10 +53,25 @@ validOpts = { stripUnknown: bool };
validOpts = { stripUnknown: { arrays: bool } };
validOpts = { stripUnknown: { objects: bool } };
validOpts = { stripUnknown: { arrays: bool, objects: bool } };
validOpts = { language: bool };
validOpts = { presence: str };
validOpts = { context: obj };
validOpts = { noDefaults: bool };
validOpts = {
language: {
root: str,
key: str,
messages: { wrapArrays: bool },
string: { base: str },
number: { base: str },
object: {
base: false,
children: { childRule: str }
},
customType: {
customRule: str
}
}
};
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---