feat(joi): v14.3

This commit is contained in:
Simon Schick
2019-01-21 10:57:50 -08:00
parent ca809fa16f
commit ff83b4dadc
3 changed files with 73 additions and 31 deletions

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

@@ -1,4 +1,4 @@
// Type definitions for joi 14.0
// Type definitions for joi 14.3
// Project: https://github.com/hapijs/joi
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// Laurence Dougal Myers <https://github.com/laurence-myers>
@@ -110,9 +110,10 @@ export interface EmailOptions {
export interface HexOptions {
/**
* hex decoded representation must be byte aligned
* hex decoded representation must be byte aligned.
* @default false
*/
byteAligned: boolean;
byteAligned?: boolean;
}
export interface IpOptions {
@@ -211,6 +212,16 @@ export interface JoiObject {
isJoi: boolean;
}
export interface ErrorOptions {
/**
* Boolean value indicating whether the error handler should be used for all errors or only for errors occurring
* on this property (`true` value).
* This concept only makes sense for `array` or `object` schemas as other values don't have children.
* @default false
*/
self?: boolean;
}
export interface ValidationError extends Error, JoiObject {
details: ValidationErrorItem[];
annotate(): string;
@@ -266,6 +277,14 @@ export interface AnySchema extends JoiObject {
allow(...values: any[]): this;
allow(values: any[]): this;
/**
* By default, some Joi methods to function properly need to rely on the Joi instance they are attached to because
* they use `this` internally.
* So `Joi.string()` works but if you extract the function from it and call `string()` it won't.
* `bind()` creates a new Joi instance where all the functions relying on `this` are bound to the Joi instance.
*/
bind(): this;
/**
* Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
*/
@@ -412,7 +431,7 @@ export interface AnySchema extends JoiObject {
* override, that error will be returned and the override will be ignored (unless the `abortEarly`
* option has been set to `false`).
*/
error(err: Error | ValidationErrorFunction): this;
error(err: Error | ValidationErrorFunction, options?: ErrorOptions): this;
/**
* Returns a plain object representing the schema's rules and properties
@@ -681,6 +700,12 @@ export interface SymbolSchema extends AnySchema {
}
export interface ArraySchema extends AnySchema {
/**
* Verifies that an assertion passes for at least one item in the array, where:
* `schema` - the validation rules required to satisfy the assertion. If the `schema` includes references, they are resolved against
* the array item being tested, not the value of the `ref` target.
*/
assertItem(schema: SchemaLike): this;
/**
* Allow this array to be sparse.
* enabled can be used with a falsy value to go back to the default behavior.
@@ -797,6 +822,13 @@ export interface ObjectSchema extends AnySchema {
or(...peers: string[]): this;
or(peers: string[]): this;
/**
* Defines an exclusive relationship between a set of keys where only one is allowed but none are required where:
* `peers` - the exclusive key names that must not appear together but where none are required.
*/
oxor(...peers: string[]): this;
oxor(peers: string[]): this;
/**
* Defines an exclusive relationship between a set of keys. one of them is required but not at the same time where:
*/

View File

@@ -19,28 +19,28 @@ declare const expArr: RegExp[];
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let schema: Joi.Schema = null;
let schema: Joi.Schema = Joi.any();
declare const schemaLike: Joi.SchemaLike;
let anySchema: Joi.AnySchema = null;
let numSchema: Joi.NumberSchema = null;
let strSchema: Joi.StringSchema = null;
let arrSchema: Joi.ArraySchema = null;
let boolSchema: Joi.BooleanSchema = null;
let binSchema: Joi.BinarySchema = null;
let dateSchema: Joi.DateSchema = null;
let funcSchema: Joi.FunctionSchema = null;
let objSchema: Joi.ObjectSchema = null;
let altSchema: Joi.AlternativesSchema = null;
let anySchema: Joi.AnySchema = Joi.any();
let numSchema: Joi.NumberSchema = Joi.number();
let strSchema: Joi.StringSchema = Joi.string();
let arrSchema: Joi.ArraySchema = Joi.array();
let boolSchema: Joi.BooleanSchema = Joi.boolean();
let binSchema: Joi.BinarySchema = Joi.binary();
let dateSchema: Joi.DateSchema = Joi.date();
let funcSchema: Joi.FunctionSchema = Joi.func();
let objSchema: Joi.ObjectSchema = Joi.object();
let altSchema: Joi.AlternativesSchema = Joi.alternatives();
declare const schemaArr: Joi.Schema[];
let ref: Joi.Reference = null;
let description: Joi.Description = null;
let ref: Joi.Reference = Joi.ref('test');
let description: Joi.Description = {};
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let validOpts: Joi.ValidationOptions = null;
let validOpts: Joi.ValidationOptions = {};
validOpts = { abortEarly: bool };
validOpts = { convert: bool };
@@ -72,7 +72,7 @@ validOpts = {
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let renOpts: Joi.RenameOptions = null;
let renOpts: Joi.RenameOptions = {};
renOpts = { alias: bool };
renOpts = { multiple: bool };
@@ -81,7 +81,7 @@ renOpts = { ignoreUndefined: bool };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let emailOpts: Joi.EmailOptions = null;
let emailOpts: Joi.EmailOptions = {};
emailOpts = { errorLevel: num };
emailOpts = { errorLevel: bool };
@@ -91,13 +91,13 @@ emailOpts = { minDomainAtoms: num };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let hexOpts: Joi.HexOptions = null;
let hexOpts: Joi.HexOptions = {};
hexOpts = { byteAligned: bool };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let ipOpts: Joi.IpOptions = null;
let ipOpts: Joi.IpOptions = {};
ipOpts = { version: str };
ipOpts = { version: strArr };
@@ -105,7 +105,7 @@ ipOpts = { cidr: str };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let uriOpts: Joi.UriOptions = null;
let uriOpts: Joi.UriOptions = {};
uriOpts = { scheme: str };
uriOpts = { scheme: exp };
@@ -114,19 +114,21 @@ uriOpts = { scheme: expArr };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let base64Opts: Joi.Base64Options = null;
let base64Opts: Joi.Base64Options = {};
base64Opts = { paddingRequired: bool };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let dataUriOpts: Joi.DataUriOptions = null;
let dataUriOpts: Joi.DataUriOptions = {};
dataUriOpts = { paddingRequired: bool };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let whenOpts: Joi.WhenOptions = null;
let whenOpts: Joi.WhenOptions = {
is: Joi.any(),
};
whenOpts = { is: x };
whenOpts = { is: schema, then: schema };
@@ -135,7 +137,7 @@ whenOpts = { is: schemaLike, then: schemaLike, otherwise: schemaLike };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let whenSchemaOpts: Joi.WhenSchemaOptions = null;
let whenSchemaOpts: Joi.WhenSchemaOptions = {};
whenSchemaOpts = { then: schema };
whenSchemaOpts = { otherwise: schema };
@@ -143,14 +145,14 @@ whenSchemaOpts = { then: schemaLike, otherwise: schemaLike };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let refOpts: Joi.ReferenceOptions = null;
let refOpts: Joi.ReferenceOptions = {};
refOpts = { separator: str };
refOpts = { contextPrefix: str };
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let stringRegexOpts: Joi.StringRegexOptions = null;
let stringRegexOpts: Joi.StringRegexOptions = {};
stringRegexOpts = { name: str };
stringRegexOpts = { invert: bool };
@@ -204,7 +206,7 @@ anySchema = objSchema;
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
let schemaMap: Joi.SchemaMap = null;
let schemaMap: Joi.SchemaMap = {};
schemaMap = {
a: numSchema,
@@ -246,6 +248,7 @@ anySchema = Joi.any();
anySchema = anySchema.allow(x);
anySchema = anySchema.allow(x, x);
anySchema = anySchema.allow([x, x, x]);
anySchema = anySchema.bind();
anySchema = anySchema.valid(x);
anySchema = anySchema.valid(x, x);
anySchema = anySchema.valid([x, x, x]);
@@ -302,12 +305,14 @@ anySchema = Joi.any();
anySchema = anySchema.error(err);
anySchema = anySchema.error(validErrFunc);
anySchema = anySchema.error(validErrFunc, { self: true });
}
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
arrSchema = Joi.array();
arrSchema = arrSchema.assertItem(Joi.any());
arrSchema = arrSchema.sparse();
arrSchema = arrSchema.sparse(bool);
arrSchema = arrSchema.single();
@@ -706,6 +711,11 @@ objSchema = objSchema.or(str, str);
objSchema = objSchema.or(str, str, str);
objSchema = objSchema.or(strArr);
objSchema = objSchema.oxor(str);
objSchema = objSchema.oxor(str, str);
objSchema = objSchema.oxor(str, str, str);
objSchema = objSchema.oxor(strArr);
objSchema = objSchema.xor(str);
objSchema = objSchema.xor(str, str);
objSchema = objSchema.xor(str, str, str);

View File

@@ -6,7 +6,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [