joi: correct Extension interfaces

This commit is contained in:
Young Rok Kim
2017-08-21 01:19:36 +09:00
parent 6a0e625e68
commit 38de7bf080
2 changed files with 8 additions and 13 deletions
+7 -13
View File
@@ -854,26 +854,20 @@ export interface AlternativesSchema extends AnySchema<FunctionSchema> {
when(ref: Reference, options: WhenOptions): AlternativesSchema;
}
export interface Terms {
value: any;
state: State;
options: ValidationOptions;
}
export interface Rules {
export interface Rules<P extends object = any> {
name: string;
params?: SchemaMap;
setup?: (this: AnySchema<AnySchema<Schema>>, description: { [key: string]: any }) => AnySchema<AnySchema<Schema>> | void;
validate?: (this: AnySchema<AnySchema<Schema>>, params: { [key: string]: any }, value: any, state: State, options: ValidationOptions) => Err | undefined;
description?: string | Function;
params?: { [key in keyof P]: SchemaLike };
setup?: (this: Schema, params: P) => Schema | void;
validate?: <R = any>(this: Schema, params: P, value: any, state: State, options: ValidationOptions) => Err | R;
description?: string | ((params: P) => string);
}
export interface Extension {
name: string;
base?: Schema;
pre?: (this: AnySchema<AnySchema<Schema>>, params: { [key: string]: any }, value: any, state: State, options: ValidationOptions) => Err | void;
pre?: <R = any>(this: Schema, value: any, state: State, options: ValidationOptions) => Err | R;
language?: LanguageRuleOptions;
describe?: (this: AnySchema<AnySchema<Schema>>, description: Description) => Description;
describe?: (this: Schema, description: Description) => Description;
rules?: Rules[];
}
+1
View File
@@ -919,6 +919,7 @@ const Joi3 = Joi.extend({
asd: 'must be exactly asd(f)',
},
pre(value, state, options) {
return value;
},
describe(description) {
return description;