diff --git a/types/joi/index.d.ts b/types/joi/index.d.ts index 0453ef7d20..256e35a8c7 100644 --- a/types/joi/index.d.ts +++ b/types/joi/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for joi v13.4.0 +// Type definitions for joi 13.4 // Project: https://github.com/hapijs/joi // Definitions by: Bart van der Schoor // Laurence Dougal Myers @@ -125,7 +125,7 @@ export interface IpOptions { cidr?: string; } -export type GuidVersions = 'uuidv1' | 'uuidv2' | 'uuidv3' | 'uuidv4' | 'uuidv5' +export type GuidVersions = 'uuidv1' | 'uuidv2' | 'uuidv3' | 'uuidv4' | 'uuidv5'; export interface GuidOptions { version: GuidVersions[] | GuidVersions; @@ -181,8 +181,8 @@ export interface ReferenceOptions { } export interface IPOptions { - version?: Array; - cidr?: string + version?: string[]; + cidr?: string; } export interface StringRegexOptions { @@ -236,7 +236,6 @@ export type Schema = AnySchema | LazySchema; export interface AnySchema extends JoiObject { - schemaType?: Types | string; /** @@ -441,7 +440,6 @@ export interface State { } export interface BooleanSchema extends AnySchema { - /** * Allows for additional values to be considered valid booleans by converting them to true during validation. * Accepts a value or an array of values. String comparisons are by default case insensitive, @@ -695,7 +693,9 @@ export interface ArraySchema extends AnySchema { /** * Lists the types in sequence order for the array values where: * @param type - a joi schema object to validate against each array item in sequence order. type can be an array of values, or multiple values can be passed as individual arguments. - * If a given type is .required() then there must be a matching item with the same index position in the array. Errors will contain the number of items that didn't match. Any unmatched item having a label will be mentioned explicitly. + * If a given type is .required() then there must be a matching item with the same index position in the array. + * Errors will contain the number of items that didn't match. + * Any unmatched item having a label will be mentioned explicitly. */ ordered(...types: SchemaLike[]): this; ordered(types: SchemaLike[]): this; @@ -726,7 +726,6 @@ export interface ArraySchema extends AnySchema { } export interface ObjectSchema extends AnySchema { - /** * Sets or extends the allowed object keys. */ @@ -754,9 +753,9 @@ export interface ObjectSchema extends AnySchema { /** * Specify validation rules for unknown keys matching a pattern. - * - * @param pattern - a pattern that can be either a regular expression or a joi schema that will be tested against the unknown key names - * @param schema - the schema object matching keys must validate against + * + * @param pattern - a pattern that can be either a regular expression or a joi schema that will be tested against the unknown key names + * @param schema - the schema object matching keys must validate against */ pattern(pattern: RegExp | SchemaLike, schema: SchemaLike): this; @@ -884,7 +883,6 @@ export interface BinarySchema extends AnySchema { } export interface DateSchema extends AnySchema { - /** * Specifies the oldest date allowed. * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, @@ -927,7 +925,6 @@ export interface DateSchema extends AnySchema { } export interface FunctionSchema extends AnySchema { - /** * Specifies the arity of the function where: * @param n - the arity expected. @@ -961,7 +958,6 @@ export interface AlternativesSchema extends AnySchema { } export interface LazySchema extends AnySchema { - } export interface Reference extends JoiObject { @@ -982,7 +978,7 @@ export type ExtensionBoundSchema = Schema & { * @param options - should the context passed into the `validate` function in a custom rule */ createError(type: string, context: Context, state: State, options: ValidationOptions): Err; -} +}; export interface Rules

{ name: string; @@ -1134,7 +1130,7 @@ export function reach(schema: ObjectSchema, path: string[]): T /** * Creates a new Joi instance customized with the extension(s) you provide included. */ -export function extend(extension: Extension|Extension[], ...extensions: (Extension|Extension[])[]): any; +export function extend(extension: Extension|Extension[], ...extensions: Array): any; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- @@ -1160,8 +1156,8 @@ export function defaults(fn: DefaultsFunction): Root; export function describe(schema: Schema): Description; /** -* Whitelists a value -*/ + * Whitelists a value + */ export function allow(value: any, ...values: any[]): Schema; export function allow(values: any[]): Schema; diff --git a/types/joi/joi-tests.ts b/types/joi/joi-tests.ts index 49ff810263..5defe20cc1 100644 --- a/types/joi/joi-tests.ts +++ b/types/joi/joi-tests.ts @@ -3,29 +3,24 @@ import Joi = require('joi'); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- let x: any = null; -let value: any = null; -let num: number = 0; -let str: string = ''; -let bool: boolean = false; -let exp: RegExp = null; -let obj: object = null; -let date: Date = null; -let err: Error = null; -let func: Function = null; +declare const value: any; +let num = 0; +let str = ''; +declare const bool: boolean; +declare const exp: RegExp; +declare const obj: object; +declare const date: Date; +declare const err: Error; +declare const func: Function; -let anyArr: any[] = []; -let numArr: number[] = []; -let strArr: string[] = []; -let boolArr: boolean[] = []; -let expArr: RegExp[] = []; -let objArr: object[] = []; -let errArr: Error[] = []; -let funcArr: Function[] = []; +declare const numArr: number[]; +declare const strArr: string[]; +declare const expArr: RegExp[]; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- let schema: Joi.Schema = null; -let schemaLike: Joi.SchemaLike = null; +declare const schemaLike: Joi.SchemaLike; let anySchema: Joi.AnySchema = null; let numSchema: Joi.NumberSchema = null; @@ -38,7 +33,7 @@ let funcSchema: Joi.FunctionSchema = null; let objSchema: Joi.ObjectSchema = null; let altSchema: Joi.AlternativesSchema = null; -let schemaArr: Joi.Schema[] = []; +declare const schemaArr: Joi.Schema[]; let ref: Joi.Reference = null; let description: Joi.Description = null; @@ -156,7 +151,7 @@ stringRegexOpts = { invert: bool }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -let validErr: Joi.ValidationError = null; +declare const validErr: Joi.ValidationError; let validErrItem: Joi.ValidationErrorItem; let validErrFunc: Joi.ValidationErrorFunction; @@ -235,13 +230,13 @@ schemaMap = { { c1: true }, { c2: null } ] -} +}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- anySchema = Joi.any(); -namespace common { +{ // common anySchema = anySchema.allow(x); anySchema = anySchema.allow(x, x); anySchema = anySchema.allow([x, x, x]); @@ -323,7 +318,6 @@ arrSchema = arrSchema.unique(); arrSchema = arrSchema.unique((a, b) => a.test === b.test); arrSchema = arrSchema.unique('customer.id'); - arrSchema = arrSchema.items(numSchema); arrSchema = arrSchema.items(numSchema, strSchema, schemaLike); arrSchema = arrSchema.items([numSchema, strSchema, schemaLike]); @@ -333,7 +327,7 @@ arrSchema = arrSchema.items([schemaMap, schemaMap, schemaLike]); // - - - - - - - - -namespace common_copy_paste { +{ // common copy paste // use search & replace from any arrSchema = arrSchema.allow(x); arrSchema = arrSchema.allow(x, x); @@ -387,7 +381,7 @@ namespace common_copy_paste { boolSchema = Joi.bool(); boolSchema = Joi.boolean(); -namespace common_copy_paste { +{ // common copy paste boolSchema = boolSchema.allow(x); boolSchema = boolSchema.allow(x, x); boolSchema = boolSchema.allow([x, x, x]); @@ -462,7 +456,7 @@ binSchema = binSchema.min(num); binSchema = binSchema.max(num); binSchema = binSchema.length(num); -namespace common { +{ // common binSchema = binSchema.allow(x); binSchema = binSchema.allow(x, x); binSchema = binSchema.allow([x, x, x]); @@ -535,7 +529,7 @@ dateSchema = dateSchema.timestamp(); dateSchema = dateSchema.timestamp('javascript'); dateSchema = dateSchema.timestamp('unix'); -namespace common { +{ // common dateSchema = dateSchema.allow(x); dateSchema = dateSchema.allow(x, x); dateSchema = dateSchema.allow([x, x, x]); @@ -611,7 +605,7 @@ numSchema = numSchema.positive(); numSchema = numSchema.negative(); numSchema = numSchema.port(); -namespace common { +{ // common numSchema = numSchema.allow(x); numSchema = numSchema.allow(x, x); numSchema = numSchema.allow([x, x, x]); @@ -729,7 +723,7 @@ objSchema = objSchema.forbiddenKeys(str); objSchema = objSchema.forbiddenKeys(str, str); objSchema = objSchema.forbiddenKeys(strArr); -namespace common { +{ // common objSchema = objSchema.allow(x); objSchema = objSchema.allow(x, x); objSchema = objSchema.allow([x, x, x]); @@ -809,7 +803,7 @@ strSchema = strSchema.ip(ipOpts); strSchema = strSchema.uri(); strSchema = strSchema.uri(uriOpts); strSchema = strSchema.guid(); -strSchema = strSchema.guid({ version: ['uuidv1', 'uuidv2', 'uuidv3', 'uuidv4', 'uuidv5'] } as Joi.GuidOptions); +strSchema = strSchema.guid({ version: ['uuidv1', 'uuidv2', 'uuidv3', 'uuidv4', 'uuidv5'] }); strSchema = strSchema.guid({ version: 'uuidv4' }); strSchema = strSchema.hex(); strSchema = strSchema.hex(hexOpts); @@ -825,7 +819,7 @@ strSchema = strSchema.normalize('NFKC'); strSchema = strSchema.base64(); strSchema = strSchema.base64(base64Opts); -namespace common { +{ // common strSchema = strSchema.allow(x); strSchema = strSchema.allow(x, x); strSchema = strSchema.allow([x, x, x]); @@ -891,11 +885,11 @@ schema = Joi.alt(schema, anySchema, boolSchema); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -schema = Joi.lazy(() => schema) +schema = Joi.lazy(() => schema); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -namespace validate_tests { +{ // validate tests { Joi.validate(value, obj); Joi.validate(value, schema); @@ -925,7 +919,7 @@ namespace validate_tests { { let value = { username: 'example', password: 'example' }; - let schema = Joi.object().keys({ + const schema = Joi.object().keys({ username: Joi.string().max(255).required(), password: Joi.string().regex(/^[a-zA-Z0-9]{3,255}$/).required(), }); @@ -951,12 +945,11 @@ namespace validate_tests { returnValue .then(val => JSON.stringify(val, null, 2)) - .then(val => { throw 'one error'; }) + .then(val => { throw new Error('one error'); }) .catch(e => {}); } } - // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- schema = Joi.compile(obj); diff --git a/types/joi/tslint.json b/types/joi/tslint.json index a41bf5d19a..87b70df769 100644 --- a/types/joi/tslint.json +++ b/types/joi/tslint.json @@ -1,79 +1,13 @@ { "extends": "dtslint/dt.json", "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, + // All are TODOs "ban-types": false, "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false + "unified-signatures": false } } diff --git a/types/joi/v10/index.d.ts b/types/joi/v10/index.d.ts index e8202d77dd..8e0026a5fe 100644 --- a/types/joi/v10/index.d.ts +++ b/types/joi/v10/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for joi v10.6.0 +// Type definitions for joi 10.6 // Project: https://github.com/hapijs/joi // Definitions by: Bart van der Schoor // Laurence Dougal Myers @@ -114,7 +114,7 @@ export interface IpOptions { cidr?: string; } -export type GuidVersions = 'uuidv1' | 'uuidv2' | 'uuidv3' | 'uuidv4' | 'uuidv5' +export type GuidVersions = 'uuidv1' | 'uuidv2' | 'uuidv3' | 'uuidv4' | 'uuidv5'; export interface GuidOptions { version: GuidVersions[] | GuidVersions; @@ -160,8 +160,8 @@ export interface ReferenceOptions { } export interface IPOptions { - version?: Array; - cidr?: string + version?: string[]; + cidr?: string; } export interface JoiObject { @@ -210,7 +210,6 @@ export type Schema = AnySchema | LazySchema; export interface AnySchema extends JoiObject { - /** * Validates a value using the schema and options. */ @@ -411,7 +410,6 @@ export interface State { } export interface BooleanSchema extends AnySchema { - /** * Allows for additional values to be considered valid booleans by converting them to true during validation. * Accepts a value or an array of values. String comparisons are by default case insensitive, @@ -514,7 +512,6 @@ export interface StringSchema extends AnySchema { max(limit: number, encoding?: string): this; max(limit: Reference, encoding?: string): this; - /** * Specifies whether the string.max() limit should be used as a truncation. * @param enabled - optional parameter defaulting to true which allows you to reset the behavior of truncate by providing a falsy value. @@ -651,7 +648,9 @@ export interface ArraySchema extends AnySchema { /** * Lists the types in sequence order for the array values where: * @param type - a joi schema object to validate against each array item in sequence order. type can be an array of values, or multiple values can be passed as individual arguments. - * If a given type is .required() then there must be a matching item with the same index position in the array. Errors will contain the number of items that didn't match. Any unmatched item having a label will be mentioned explicitly. + * If a given type is .required() then there must be a matching item with the same index position in the array. + * Errors will contain the number of items that didn't match. + * Any unmatched item having a label will be mentioned explicitly. */ ordered(...types: SchemaLike[]): this; ordered(types: SchemaLike[]): this; @@ -682,7 +681,6 @@ export interface ArraySchema extends AnySchema { } export interface ObjectSchema extends AnySchema { - /** * Sets the allowed object keys. */ @@ -819,7 +817,6 @@ export interface BinarySchema extends AnySchema { } export interface DateSchema extends AnySchema { - /** * Specifies the oldest date allowed. * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, @@ -862,7 +859,6 @@ export interface DateSchema extends AnySchema { } export interface FunctionSchema extends AnySchema { - /** * Specifies the arity of the function where: * @param n - the arity expected. @@ -896,7 +892,6 @@ export interface AlternativesSchema extends AnySchema { } export interface LazySchema extends AnySchema { - } export interface Reference extends JoiObject { @@ -917,7 +912,7 @@ export type ExtensionBoundSchema = Schema & { * @param options - should the context passed into the `validate` function in a custom rule */ createError(type: string, context: Context, state: State, options: ValidationOptions): Err; -} +}; export interface Rules

{ name: string; @@ -1078,8 +1073,8 @@ export function extend(extention: Extension): any; export function describe(schema: Schema): Description; /** -* Whitelists a value -*/ + * Whitelists a value + */ export function allow(value: any, ...values: any[]): Schema; export function allow(values: any[]): Schema; diff --git a/types/joi/v10/joi-tests.ts b/types/joi/v10/joi-tests.ts index e1194f5b76..8782a46dfa 100644 --- a/types/joi/v10/joi-tests.ts +++ b/types/joi/v10/joi-tests.ts @@ -2,50 +2,45 @@ import Joi = require('joi'); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var x: any = null; -var value: any = null; -var num: number = 0; -var str: string = ''; -var bool: boolean = false; -var exp: RegExp = null; -var obj: object = null; -var date: Date = null; -var err: Error = null; -var func: Function = null; +let x: any = null; +declare const value: any; +let num = 0; +let str = ''; +declare const bool: boolean; +declare const exp: RegExp; +declare const obj: object; +declare const date: Date; +declare const err: Error; +declare const func: Function; -var anyArr: any[] = []; -var numArr: number[] = []; -var strArr: string[] = []; -var boolArr: boolean[] = []; -var expArr: RegExp[] = []; -var objArr: object[] = []; -var errArr: Error[] = []; -var funcArr: Function[] = []; +declare const numArr: number[]; +declare const strArr: string[]; +declare const expArr: RegExp[]; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var schema: Joi.Schema = null; -var schemaLike: Joi.SchemaLike = null; +let schema: Joi.Schema = null; +declare const schemaLike: Joi.SchemaLike; -var anySchema: Joi.AnySchema = null; -var numSchema: Joi.NumberSchema = null; -var strSchema: Joi.StringSchema = null; -var arrSchema: Joi.ArraySchema = null; -var boolSchema: Joi.BooleanSchema = null; -var binSchema: Joi.BinarySchema = null; -var dateSchema: Joi.DateSchema = null; -var funcSchema: Joi.FunctionSchema = null; -var objSchema: Joi.ObjectSchema = null; -var altSchema: Joi.AlternativesSchema = null; +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; -var schemaArr: Joi.Schema[] = []; +declare const schemaArr: Joi.Schema[]; -var ref: Joi.Reference = null; -var description: Joi.Description = null; +let ref: Joi.Reference = null; +let description: Joi.Description = null; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var validOpts: Joi.ValidationOptions = null; +let validOpts: Joi.ValidationOptions = null; validOpts = { abortEarly: bool }; validOpts = { convert: bool }; @@ -77,7 +72,7 @@ validOpts = { // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var renOpts: Joi.RenameOptions = null; +let renOpts: Joi.RenameOptions; renOpts = { alias: bool }; renOpts = { multiple: bool }; @@ -86,7 +81,7 @@ renOpts = { ignoreUndefined: bool }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var emailOpts: Joi.EmailOptions = null; +let emailOpts: Joi.EmailOptions; emailOpts = { errorLevel: num }; emailOpts = { errorLevel: bool }; @@ -96,7 +91,7 @@ emailOpts = { minDomainAtoms: num }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var ipOpts: Joi.IpOptions = null; +let ipOpts: Joi.IpOptions; ipOpts = { version: str }; ipOpts = { version: strArr }; @@ -104,7 +99,7 @@ ipOpts = { cidr: str }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var uriOpts: Joi.UriOptions = null; +let uriOpts: Joi.UriOptions; uriOpts = { scheme: str }; uriOpts = { scheme: exp }; @@ -113,7 +108,7 @@ uriOpts = { scheme: expArr }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var whenOpts: Joi.WhenOptions = null; +let whenOpts: Joi.WhenOptions; whenOpts = { is: x }; whenOpts = { is: schema, then: schema }; @@ -122,7 +117,7 @@ whenOpts = { is: schemaLike, then: schemaLike, otherwise: schemaLike }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var whenSchemaOpts: Joi.WhenSchemaOptions = null; +let whenSchemaOpts: Joi.WhenSchemaOptions; whenSchemaOpts = { then: schema }; whenSchemaOpts = { otherwise: schema }; @@ -130,16 +125,16 @@ whenSchemaOpts = { then: schemaLike, otherwise: schemaLike }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var refOpts: Joi.ReferenceOptions = null; +let refOpts: Joi.ReferenceOptions; refOpts = { separator: str }; refOpts = { contextPrefix: str }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var validErr: Joi.ValidationError = null; -var validErrItem: Joi.ValidationErrorItem; -var validErrFunc: Joi.ValidationErrorFunction; +declare const validErr: Joi.ValidationError; +let validErrItem: Joi.ValidationErrorItem; +let validErrFunc: Joi.ValidationErrorFunction; validErrItem = { message: str, @@ -184,7 +179,7 @@ anySchema = objSchema; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var schemaMap: Joi.SchemaMap = null; +let schemaMap: Joi.SchemaMap; schemaMap = { a: numSchema, @@ -216,13 +211,13 @@ schemaMap = { { c1: true }, { c2: null } ] -} +}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- anySchema = Joi.any(); -namespace common { +{ // common anySchema = anySchema.allow(x); anySchema = anySchema.allow(x, x); anySchema = anySchema.allow([x, x, x]); @@ -304,7 +299,6 @@ arrSchema = arrSchema.unique(); arrSchema = arrSchema.unique((a, b) => a.test === b.test); arrSchema = arrSchema.unique('customer.id'); - arrSchema = arrSchema.items(numSchema); arrSchema = arrSchema.items(numSchema, strSchema, schemaLike); arrSchema = arrSchema.items([numSchema, strSchema, schemaLike]); @@ -314,7 +308,7 @@ arrSchema = arrSchema.items([schemaMap, schemaMap, schemaLike]); // - - - - - - - - -namespace common_copy_paste { +{ // common copy paste // use search & replace from any arrSchema = arrSchema.allow(x); arrSchema = arrSchema.allow(x, x); @@ -368,7 +362,7 @@ namespace common_copy_paste { boolSchema = Joi.bool(); boolSchema = Joi.boolean(); -namespace common_copy_paste { +{ // common copy paste boolSchema = boolSchema.allow(x); boolSchema = boolSchema.allow(x, x); boolSchema = boolSchema.allow([x, x, x]); @@ -443,7 +437,7 @@ binSchema = binSchema.min(num); binSchema = binSchema.max(num); binSchema = binSchema.length(num); -namespace common { +{ // common binSchema = binSchema.allow(x); binSchema = binSchema.allow(x, x); binSchema = binSchema.allow([x, x, x]); @@ -516,7 +510,7 @@ dateSchema = dateSchema.timestamp(); dateSchema = dateSchema.timestamp('javascript'); dateSchema = dateSchema.timestamp('unix'); -namespace common { +{ // common dateSchema = dateSchema.allow(x); dateSchema = dateSchema.allow(x, x); dateSchema = dateSchema.allow([x, x, x]); @@ -591,7 +585,7 @@ numSchema = numSchema.multiple(num); numSchema = numSchema.positive(); numSchema = numSchema.negative(); -namespace common { +{ // common numSchema = numSchema.allow(x); numSchema = numSchema.allow(x, x); numSchema = numSchema.allow([x, x, x]); @@ -702,7 +696,7 @@ objSchema = objSchema.optionalKeys(str); objSchema = objSchema.optionalKeys(str, str); objSchema = objSchema.optionalKeys(strArr); -namespace common { +{ // common objSchema = objSchema.allow(x); objSchema = objSchema.allow(x, x); objSchema = objSchema.allow([x, x, x]); @@ -781,7 +775,7 @@ strSchema = strSchema.ip(ipOpts); strSchema = strSchema.uri(); strSchema = strSchema.uri(uriOpts); strSchema = strSchema.guid(); -strSchema = strSchema.guid({ version: ['uuidv1', 'uuidv2', 'uuidv3', 'uuidv4', 'uuidv5'] } as Joi.GuidOptions); +strSchema = strSchema.guid({ version: ['uuidv1', 'uuidv2', 'uuidv3', 'uuidv4', 'uuidv5'] }); strSchema = strSchema.guid({ version: 'uuidv4' }); strSchema = strSchema.hex(); strSchema = strSchema.hostname(); @@ -794,7 +788,7 @@ strSchema = strSchema.truncate(false); strSchema = strSchema.normalize(); strSchema = strSchema.normalize('NFKC'); -namespace common { +{ // common strSchema = strSchema.allow(x); strSchema = strSchema.allow(x, x); strSchema = strSchema.allow([x, x, x]); @@ -860,11 +854,11 @@ schema = Joi.alt(schema, anySchema, boolSchema); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -schema = Joi.lazy(() => schema) +schema = Joi.lazy(() => schema); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -namespace validate_tests { +{ // validate tests { Joi.validate(value, obj); Joi.validate(value, schema); @@ -894,7 +888,7 @@ namespace validate_tests { { let value = { username: 'example', password: 'example' }; - let schema = Joi.object().keys({ + const schema = Joi.object().keys({ username: Joi.string().max(255).required(), password: Joi.string().regex(/^[a-zA-Z0-9]{3,255}$/).required(), }); @@ -920,7 +914,6 @@ namespace validate_tests { } } - // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- schema = Joi.compile(obj); diff --git a/types/joi/v10/tslint.json b/types/joi/v10/tslint.json index a41bf5d19a..0b8095b5e1 100644 --- a/types/joi/v10/tslint.json +++ b/types/joi/v10/tslint.json @@ -1,79 +1,12 @@ { "extends": "dtslint/dt.json", "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, + // All are TODOs "ban-types": false, "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false + "unified-signatures": false } } diff --git a/types/joi/v6/index.d.ts b/types/joi/v6/index.d.ts index d9ee7c20d1..5f5fb5625d 100644 --- a/types/joi/v6/index.d.ts +++ b/types/joi/v6/index.d.ts @@ -1,778 +1,773 @@ -// Type definitions for joi v6.5.0 +// Type definitions for joi 6.5 // Project: https://github.com/spumko/joi -// Definitions by: Bart van der Schoor , Laurence Dougal Myers , Christopher Glantschnig , David Broder-Rodgers +// Definitions by: Bart van der Schoor +// Laurence Dougal Myers +// Christopher Glantschnig +// David Broder-Rodgers // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TODO express type of Schema in a type-parameter (.default, .valid, .example etc) -declare module 'joi' { - - export interface ValidationOptions { - /** - * when true, stops validation on the first error, otherwise returns all the errors found. Defaults to true. - */ - abortEarly?: boolean; - /** - * when true, attempts to cast values to the required types (e.g. a string to a number). Defaults to true. - */ - convert?: boolean; - /** - * when true, allows object to contain unknown keys which are ignored. Defaults to false. - */ - allowUnknown?: boolean; - /** - * when true, ignores unknown keys with a function value. Defaults to false. - */ - skipFunctions?: boolean; - /** - * when true, unknown keys are deleted (only when value is an object). Defaults to false. - */ - stripUnknown?: boolean; - /** - * overrides individual error messages. Defaults to no override ({}). - */ - language?: Object; - /** - * sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'. Defaults to 'optional'. - */ - presence?: string; - /** - * provides an external data set to be used in references - */ - context?: Object; - } - - export interface RenameOptions { - /** - * if true, does not delete the old key name, keeping both the new and old keys in place. Defaults to false. - */ - alias?: boolean; - /** - * if true, allows renaming multiple keys to the same destination where the last rename wins. Defaults to false. - */ - multiple?: boolean; - /** - * if true, allows renaming a key over an existing key. Defaults to false. - */ - override?: boolean; - /** - * if true, skip renaming of a key if it's undefined. Defaults to false. - */ - ignoreUndefined?: boolean; - } - - export interface EmailOptions { - /** - * Numerical threshold at which an email address is considered invalid - */ - errorLevel?: number | boolean; - /** - * Specifies a list of acceptable TLDs. - */ - tldWhitelist?: string[] | Object; - /** - * Number of atoms required for the domain. Be careful since some domains, such as io, directly allow email. - */ - minDomainAtoms?: number; - } - - export interface IpOptions { - /** - * One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture - */ - version ?: string | string[]; - /** - * Used to determine if a CIDR is allowed or not. Valid values: optional, required, forbidden - */ - cidr?: string; - } - - export interface UriOptions { - /** - * Specifies one or more acceptable Schemes, should only include the scheme name. - * Can be an Array or String (strings are automatically escaped for use in a Regular Expression). - */ - scheme ?: string | RegExp | Array; - } - - export interface WhenOptions { - /** - * the required condition joi type. - */ - is: T; - /** - * the alternative schema type if the condition is true. Required if otherwise is missing. - */ - then?: Schema; - /** - * the alternative schema type if the condition is false. Required if then is missing - */ - otherwise?: Schema; - } - - export interface ReferenceOptions { - separator?: string; - contextPrefix?: string; - } - - export interface IPOptions { - version?: Array; - cidr?: string - } - - export interface ValidationError extends Error { - message: string; - details: ValidationErrorItem[]; - simple(): string; - annotated(): string; - } - - export interface ValidationErrorItem { - message: string; - type: string; - path: string; - options?: ValidationOptions; - } - - export interface ValidationResult { - error: ValidationError; - value: T; - } - - export interface SchemaMap { - [key: string]: Schema; - } - - export interface Schema extends AnySchema { - - } - - export interface Reference extends Schema { - - } - - export interface AnySchema> { - /** - * Whitelists a value - */ - allow(value: any, ...values: any[]): T; - allow(values: any[]): T; - - /** - * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed. - */ - valid(value: any, ...values: any[]): T; - valid(values: any[]): T; - only(value: any, ...values : any[]): T; - only(values: any[]): T; - equal(value: any, ...values : any[]): T; - equal(values: any[]): T; - - /** - * Blacklists a value - */ - invalid(value: any, ...values: any[]): T; - invalid(values: any[]): T; - disallow(value: any, ...values : any[]): T; - disallow(values: any[]): T; - not(value: any, ...values : any[]): T; - not(values: any[]): T; - - /** - * Marks a key as required which will not allow undefined as value. All keys are optional by default. - */ - required(): T; - - /** - * Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default. - */ - optional(): T; - - /** - * Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys. - */ - forbidden(): T; - - /** - * Marks a key to be removed from a resulting object or array after validation. Used to sanitize output. - */ - strip(): T; - - /** - * Annotates the key - */ - description(desc: string): T; - - /** - * Annotates the key - */ - notes(notes: string): T; - notes(notes: string[]): T; - - /** - * Annotates the key - */ - tags(notes: string): T; - tags(notes: string[]): T; - - /** - * Attaches metadata to the key. - */ - meta(meta: Object): T; - - /** - * Annotates the key with an example value, must be valid. - */ - example(value: any): T; - - /** - * Annotates the key with an unit name. - */ - unit(name: string): T; - - /** - * Overrides the global validate() options for the current key and any sub-key. - */ - options(options: ValidationOptions): T; - - /** - * Sets the options.convert options to false which prevent type casting for the current key and any child keys. - */ - strict(isStrict?: boolean): T; - - /** - * Sets a default value if the original value is undefined. - * @param value - the value. - * value supports references. - * value may also be a function which returns the default value. - * If value is specified as a function that accepts a single parameter, that parameter will be a context - * object that can be used to derive the resulting value. This clones the object however, which incurs some - * overhead so if you don't need access to the context define your method so that it does not accept any - * parameters. - * Without any value, default has no effect, except for object that will then create nested defaults - * (applying inner defaults of that object). - * - * Note that if value is an object, any changes to the object after default() is called will change the - * reference and any future assignment. - * - * Additionally, when specifying a method you must either have a description property on your method or the - * second parameter is required. - */ - default(value: any, description?: string): T; - default(): T; - - /** - * Returns a new type that is the result of adding the rules of one type to another. - */ - concat(schema: T): T; - - /** - * Converts the type into an alternatives type where the conditions are merged into the type definition where: - */ - when(ref: string, options: WhenOptions): AlternativesSchema; - when(ref: Reference, options: WhenOptions): AlternativesSchema; - - /** - * Overrides the key name in error messages. - */ - label(name: string): T; - - /** - * Outputs the original untouched value instead of the casted value. - */ - raw(isRaw?: boolean): T; - - /** - * Considers anything that matches the schema to be empty (undefined). - * @param schema - any object or joi schema to match. An undefined schema unsets that rule. - */ - empty(schema?: any) : T; - } - - export interface BooleanSchema extends AnySchema { - - } - - export interface NumberSchema extends AnySchema { - /** - * Specifies the minimum value. - * It can also be a reference to another field. - */ - min(limit: number): NumberSchema; - min(limit: Reference): NumberSchema; - - /** - * Specifies the maximum value. - * It can also be a reference to another field. - */ - max(limit: number): NumberSchema; - max(limit: Reference): NumberSchema; - - /** - * Specifies that the value must be greater than limit. - * It can also be a reference to another field. - */ - greater(limit: number): NumberSchema; - greater(limit: Reference): NumberSchema; - - /** - * Specifies that the value must be less than limit. - * It can also be a reference to another field. - */ - less(limit: number): NumberSchema; - less(limit: Reference): NumberSchema; - - /** - * Requires the number to be an integer (no floating point). - */ - integer(): NumberSchema; - - /** - * Specifies the maximum number of decimal places where: - * limit - the maximum number of decimal places allowed. - */ - precision(limit: number): NumberSchema; - - /** - * Specifies that the value must be a multiple of base. - */ - multiple(base: number): NumberSchema; - - /** - * Requires the number to be positive. - */ - positive(): NumberSchema; - - /** - * Requires the number to be negative. - */ - negative(): NumberSchema; - } - - export interface StringSchema extends AnySchema { - /** - * Allows the value to match any whitelist of blacklist item in a case insensitive comparison. - */ - insensitive(): StringSchema; - - /** - * Specifies the minimum number string characters. - * @param limit - the minimum number of string characters required. It can also be a reference to another field. - * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. - */ - min(limit: number, encoding?: string): StringSchema; - min(limit: Reference, encoding?: string): StringSchema; - - /** - * Specifies the maximum number of string characters. - * @param limit - the maximum number of string characters allowed. It can also be a reference to another field. - * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. - */ - max(limit: number, encoding?: string): StringSchema; - max(limit: Reference, encoding?: string): StringSchema; - - /** - * Requires the number to be a credit card number (Using Lunh Algorithm). - */ - creditCard(): StringSchema; - - /** - * Specifies the exact string length required - * @param limit - the required string length. It can also be a reference to another field. - * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. - */ - length(limit: number, encoding?: string): StringSchema; - length(limit: Reference, encoding?: string): StringSchema; - - /** - * Defines a regular expression rule. - * @param pattern - a regular expression object the string value must match against. - * @param name - optional name for patterns (useful with multiple patterns). Defaults to 'required'. - */ - regex(pattern: RegExp, name?: string): StringSchema; - - /** - * Replace characters matching the given pattern with the specified replacement string where: - * @param pattern - a regular expression object to match against, or a string of which all occurrences will be replaced. - * @param replacement - the string that will replace the pattern. - */ - replace(pattern: RegExp, replacement: string): StringSchema; - replace(pattern: string, replacement: string): StringSchema; - - /** - * Requires the string value to only contain a-z, A-Z, and 0-9. - */ - alphanum(): StringSchema; - - /** - * Requires the string value to only contain a-z, A-Z, 0-9, and underscore _. - */ - token(): StringSchema; - - /** - * Requires the string value to be a valid email address. - */ - email(options?: EmailOptions): StringSchema; - - /** - * Requires the string value to be a valid ip address. - */ - ip(options?: IpOptions): StringSchema; - - /** - * Requires the string value to be a valid RFC 3986 URI. - */ - uri(options?: UriOptions): StringSchema; - - /** - * Requires the string value to be a valid GUID. - */ - guid(): StringSchema; - - /** - * Requires the string value to be a valid hexadecimal string. - */ - hex(): StringSchema; - - /** - * Requires the string value to be a valid hostname as per RFC1123. - */ - hostname(): StringSchema; - - /** - * Requires the string value to be in valid ISO 8601 date format. - */ - isoDate(): StringSchema; - - /** - * Requires the string value to be all lowercase. If the validation convert option is on (enabled by default), the string will be forced to lowercase. - */ - lowercase(): StringSchema; - - /** - * Requires the string value to be all uppercase. If the validation convert option is on (enabled by default), the string will be forced to uppercase. - */ - uppercase(): StringSchema; - - /** - * Requires the string value to contain no whitespace before or after. If the validation convert option is on (enabled by default), the string will be trimmed. - */ - trim(): StringSchema; - } - - export interface ArraySchema extends AnySchema { - /** - * Allow this array to be sparse. - * enabled can be used with a falsy value to go back to the default behavior. - */ - sparse(enabled?: any): ArraySchema; - - /** - * Allow single values to be checked against rules as if it were provided as an array. - * enabled can be used with a falsy value to go back to the default behavior. - */ - single(enabled?: any): ArraySchema; - - /** - * List the types allowed for the array values. - * type can be an array of values, or multiple values can be passed as individual arguments. - * If a given type is .required() then there must be a matching item in the array. - * If a type is .forbidden() then it cannot appear in the array. - * Required items can be added multiple times to signify that multiple items must be found. - * Errors will contain the number of items that didn't match. - * Any unmatched item having a label will be mentioned explicitly. - * - * @param type - a joi schema object to validate each array item against. - */ - items(type: Schema, ...types: Schema[]): ArraySchema; - items(types: Schema[]): ArraySchema; - - /** - * Specifies the minimum number of items in the array. - */ - min(limit: number): ArraySchema; - - /** - * Specifies the maximum number of items in the array. - */ - max(limit: number): ArraySchema; - - /** - * Specifies the exact number of items in the array. - */ - length(limit: number): ArraySchema; - - /** - * Requires the array values to be unique. - * Be aware that a deep equality is performed on elements of the array having a type of object, - * a performance penalty is to be expected for this kind of operation. - */ - unique(): ArraySchema; - } - - export interface ObjectSchema extends AnySchema { - /** - * Sets the allowed object keys. - */ - keys(schema?: SchemaMap): ObjectSchema; - - /** - * Specifies the minimum number of keys in the object. - */ - min(limit: number): ObjectSchema; - - /** - * Specifies the maximum number of keys in the object. - */ - max(limit: number): ObjectSchema; - - /** - * Specifies the exact number of keys in the object. - */ - length(limit: number): ObjectSchema; - - /** - * Specify validation rules for unknown keys matching a pattern. - */ - pattern(regex: RegExp, schema: Schema): ObjectSchema; - - /** - * Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well. - * @param peers - the key names of which if one present, all are required. peers can be a single string value, - * an array of string values, or each peer provided as an argument. - */ - and(peer1: string, ...peers: string[]): ObjectSchema; - and(peers: string[]): ObjectSchema; - - /** - * Defines a relationship between keys where not all peers can be present at the same time. - * @param peers - the key names of which if one present, the others may not all be present. - * peers can be a single string value, an array of string values, or each peer provided as an argument. - */ - nand(peer1: string, ...peers: string[]): ObjectSchema; - nand(peers: string[]): ObjectSchema; - - /** - * Defines a relationship between keys where one of the peers is required (and more than one is allowed). - */ - or(peer1: string, ...peers: string[]): ObjectSchema; - or(peers: string[]): ObjectSchema; - - /** - * Defines an exclusive relationship between a set of keys. one of them is required but not at the same time where: - */ - xor(peer1: string, ...peers: string[]): ObjectSchema; - xor(peers: string[]): ObjectSchema; - - /** - * Requires the presence of other keys whenever the specified key is present. - */ - with(key: string, peers: string): ObjectSchema; - with(key: string, peers: string[]): ObjectSchema; - - /** - * Forbids the presence of other keys whenever the specified is present. - */ - without(key: string, peers: string): ObjectSchema; - without(key: string, peers: string[]): ObjectSchema; - - /** - * Renames a key to another name (deletes the renamed key). - */ - rename(from: string, to: string, options?: RenameOptions): ObjectSchema; - - /** - * Verifies an assertion where. - */ - assert(ref: string, schema: Schema, message?: string): ObjectSchema; - assert(ref: Reference, schema: Schema, message?: string): ObjectSchema; - - /** - * Overrides the handling of unknown keys for the scope of the current object only (does not apply to children). - */ - unknown(allow?: boolean): ObjectSchema; - - /** - * Requires the object to be an instance of a given constructor. - * - * @param constructor - the constructor function that the object must be an instance of. - * @param name - an alternate name to use in validation errors. This is useful when the constructor function does not have a name. - */ - type(constructor: Function, name?: string): ObjectSchema; - - /** - * Sets the specified children to required. - * - * @param children - can be a single string value, an array of string values, or each child provided as an argument. - * - * var schema = Joi.object().keys({ a: { b: Joi.number() }, c: { d: Joi.string() } }); - * var requiredSchema = schema.requiredKeys('', 'a.b', 'c', 'c.d'); - * - * Note that in this example '' means the current object, a is not required but b is, as well as c and d. - */ - requiredKeys(children: string): ObjectSchema; - requiredKeys(children: string[]): ObjectSchema; - requiredKeys(child:string, ...children: string[]): ObjectSchema; - - /** - * Sets the specified children to optional. - * - * @param children - can be a single string value, an array of string values, or each child provided as an argument. - * - * The behavior is exactly the same as requiredKeys. - */ - optionalKeys(children: string): ObjectSchema; - optionalKeys(children: string[]): ObjectSchema; - optionalKeys(child:string, ...children: string[]): ObjectSchema; - } - - export interface BinarySchema extends AnySchema { - /** - * Sets the string encoding format if a string input is converted to a buffer. - */ - encoding(encoding: string): BinarySchema; - - /** - * Specifies the minimum length of the buffer. - */ - min(limit: number): BinarySchema; - - /** - * Specifies the maximum length of the buffer. - */ - max(limit: number): BinarySchema; - - /** - * Specifies the exact length of the buffer: - */ - length(limit: number): BinarySchema; - } - - export interface DateSchema extends AnySchema { - - /** - * Specifies the oldest date allowed. - * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, - * allowing to explicitly ensure a date is either in the past or in the future. - * It can also be a reference to another field. - */ - min(date: Date): DateSchema; - min(date: number): DateSchema; - min(date: string): DateSchema; - min(date: Reference): DateSchema; - - /** - * Specifies the latest date allowed. - * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, - * allowing to explicitly ensure a date is either in the past or in the future. - * It can also be a reference to another field. - */ - max(date: Date): DateSchema; - max(date: number): DateSchema; - max(date: string): DateSchema; - max(date: Reference): DateSchema; - - /** - * Specifies the allowed date format: - * @param format - string or array of strings that follow the moment.js format. - */ - format(format: string): DateSchema; - format(format: string[]): DateSchema; - - /** - * Requires the string value to be in valid ISO 8601 date format. - */ - iso(): DateSchema; - } - - export interface FunctionSchema extends AnySchema { - - } - - export interface AlternativesSchema extends AnySchema { - try(schemas: Schema[]): AlternativesSchema; - when(ref: string, options: WhenOptions): AlternativesSchema; - when(ref: Reference, options: WhenOptions): AlternativesSchema; - } - - // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- - +export interface ValidationOptions { /** - * Generates a schema object that matches any data type. + * when true, stops validation on the first error, otherwise returns all the errors found. Defaults to true. */ - export function any(): Schema; - + abortEarly?: boolean; /** - * Generates a schema object that matches an array data type. + * when true, attempts to cast values to the required types (e.g. a string to a number). Defaults to true. */ - export function array(): ArraySchema; - + convert?: boolean; /** - * Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via bool(). + * when true, allows object to contain unknown keys which are ignored. Defaults to false. */ - export function bool(): BooleanSchema; - - export function boolean(): BooleanSchema; - + allowUnknown?: boolean; /** - * Generates a schema object that matches a Buffer data type (as well as the strings which will be converted to Buffers). + * when true, ignores unknown keys with a function value. Defaults to false. */ - export function binary(): BinarySchema; - + skipFunctions?: boolean; /** - * Generates a schema object that matches a date type (as well as a JavaScript date string or number of milliseconds). + * when true, unknown keys are deleted (only when value is an object). Defaults to false. */ - export function date(): DateSchema; - + stripUnknown?: boolean; /** - * Generates a schema object that matches a function type. + * overrides individual error messages. Defaults to no override ({}). */ - export function func(): FunctionSchema; - + language?: Object; /** - * Generates a schema object that matches a number data type (as well as strings that can be converted to numbers). + * sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'. Defaults to 'optional'. */ - export function number(): NumberSchema; - + presence?: string; /** - * Generates a schema object that matches an object data type (as well as JSON strings that parsed into objects). + * provides an external data set to be used in references */ - export function object(schema?: SchemaMap): ObjectSchema; - - /** - * Generates a schema object that matches a string data type. Note that empty strings are not allowed by default and must be enabled with allow(''). - */ - export function string(): StringSchema; - - /** - * Generates a type that will match one of the provided alternative schemas - */ - export function alternatives(types: Schema[]): Schema; - export function alternatives(type1: Schema, type2: Schema, ...types: Schema[]): Schema; - - /** - * Validates a value using the given schema and options. - */ - export function validate(value: T, schema: Schema, callback: (err: ValidationError, value: T) => void): void; - export function validate(value: T, schema: Object, callback: (err: ValidationError, value: T) => void): void; - export function validate(value: T, schema: Object, options?: ValidationOptions, callback?: (err: ValidationError, value: T) => void): ValidationResult; - - /** - * Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object). - */ - export function compile(schema: Object): Schema; - - /** - * Validates a value against a schema and throws if validation fails. - * - * @param value - the value to validate. - * @param schema - the schema object. - * @param message - optional message string prefix added in front of the error message. may also be an Error object. - */ - export function assert(value: any, schema: Schema, message?: string | Error): void; - - /** - * Generates a reference to the value of the named key. - */ - export function ref(key: string, options?: ReferenceOptions): Reference; + context?: Object; } + +export interface RenameOptions { + /** + * if true, does not delete the old key name, keeping both the new and old keys in place. Defaults to false. + */ + alias?: boolean; + /** + * if true, allows renaming multiple keys to the same destination where the last rename wins. Defaults to false. + */ + multiple?: boolean; + /** + * if true, allows renaming a key over an existing key. Defaults to false. + */ + override?: boolean; + /** + * if true, skip renaming of a key if it's undefined. Defaults to false. + */ + ignoreUndefined?: boolean; +} + +export interface EmailOptions { + /** + * Numerical threshold at which an email address is considered invalid + */ + errorLevel?: number | boolean; + /** + * Specifies a list of acceptable TLDs. + */ + tldWhitelist?: string[] | Object; + /** + * Number of atoms required for the domain. Be careful since some domains, such as io, directly allow email. + */ + minDomainAtoms?: number; +} + +export interface IpOptions { + /** + * One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture + */ + version ?: string | string[]; + /** + * Used to determine if a CIDR is allowed or not. Valid values: optional, required, forbidden + */ + cidr?: string; +} + +export interface UriOptions { + /** + * Specifies one or more acceptable Schemes, should only include the scheme name. + * Can be an Array or String (strings are automatically escaped for use in a Regular Expression). + */ + scheme ?: string | RegExp | Array; +} + +export interface WhenOptions { + /** + * the required condition joi type. + */ + is: T; + /** + * the alternative schema type if the condition is true. Required if otherwise is missing. + */ + then?: Schema; + /** + * the alternative schema type if the condition is false. Required if then is missing + */ + otherwise?: Schema; +} + +export interface ReferenceOptions { + separator?: string; + contextPrefix?: string; +} + +export interface IPOptions { + version?: string[]; + cidr?: string; +} + +export interface ValidationError extends Error { + message: string; + details: ValidationErrorItem[]; + simple(): string; + annotated(): string; +} + +export interface ValidationErrorItem { + message: string; + type: string; + path: string; + options?: ValidationOptions; +} + +export interface ValidationResult { + error: ValidationError; + value: T; +} + +export interface SchemaMap { + [key: string]: Schema; +} + +export interface Schema extends AnySchema { +} + +export interface Reference extends Schema { +} + +export interface AnySchema> { + /** + * Whitelists a value + */ + allow(value: any, ...values: any[]): T; + allow(values: any[]): T; + + /** + * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed. + */ + valid(value: any, ...values: any[]): T; + valid(values: any[]): T; + only(value: any, ...values: any[]): T; + only(values: any[]): T; + equal(value: any, ...values: any[]): T; + equal(values: any[]): T; + + /** + * Blacklists a value + */ + invalid(value: any, ...values: any[]): T; + invalid(values: any[]): T; + disallow(value: any, ...values: any[]): T; + disallow(values: any[]): T; + not(value: any, ...values: any[]): T; + not(values: any[]): T; + + /** + * Marks a key as required which will not allow undefined as value. All keys are optional by default. + */ + required(): T; + + /** + * Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default. + */ + optional(): T; + + /** + * Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys. + */ + forbidden(): T; + + /** + * Marks a key to be removed from a resulting object or array after validation. Used to sanitize output. + */ + strip(): T; + + /** + * Annotates the key + */ + description(desc: string): T; + + /** + * Annotates the key + */ + notes(notes: string): T; + notes(notes: string[]): T; + + /** + * Annotates the key + */ + tags(notes: string): T; + tags(notes: string[]): T; + + /** + * Attaches metadata to the key. + */ + meta(meta: Object): T; + + /** + * Annotates the key with an example value, must be valid. + */ + example(value: any): T; + + /** + * Annotates the key with an unit name. + */ + unit(name: string): T; + + /** + * Overrides the global validate() options for the current key and any sub-key. + */ + options(options: ValidationOptions): T; + + /** + * Sets the options.convert options to false which prevent type casting for the current key and any child keys. + */ + strict(isStrict?: boolean): T; + + /** + * Sets a default value if the original value is undefined. + * @param value - the value. + * value supports references. + * value may also be a function which returns the default value. + * If value is specified as a function that accepts a single parameter, that parameter will be a context + * object that can be used to derive the resulting value. This clones the object however, which incurs some + * overhead so if you don't need access to the context define your method so that it does not accept any + * parameters. + * Without any value, default has no effect, except for object that will then create nested defaults + * (applying inner defaults of that object). + * + * Note that if value is an object, any changes to the object after default() is called will change the + * reference and any future assignment. + * + * Additionally, when specifying a method you must either have a description property on your method or the + * second parameter is required. + */ + default(value: any, description?: string): T; + default(): T; + + /** + * Returns a new type that is the result of adding the rules of one type to another. + */ + concat(schema: T): T; + + /** + * Converts the type into an alternatives type where the conditions are merged into the type definition where: + */ + when(ref: string, options: WhenOptions): AlternativesSchema; + when(ref: Reference, options: WhenOptions): AlternativesSchema; + + /** + * Overrides the key name in error messages. + */ + label(name: string): T; + + /** + * Outputs the original untouched value instead of the casted value. + */ + raw(isRaw?: boolean): T; + + /** + * Considers anything that matches the schema to be empty (undefined). + * @param schema - any object or joi schema to match. An undefined schema unsets that rule. + */ + empty(schema?: any): T; +} + +export interface BooleanSchema extends AnySchema { +} + +export interface NumberSchema extends AnySchema { + /** + * Specifies the minimum value. + * It can also be a reference to another field. + */ + min(limit: number): NumberSchema; + min(limit: Reference): NumberSchema; + + /** + * Specifies the maximum value. + * It can also be a reference to another field. + */ + max(limit: number): NumberSchema; + max(limit: Reference): NumberSchema; + + /** + * Specifies that the value must be greater than limit. + * It can also be a reference to another field. + */ + greater(limit: number): NumberSchema; + greater(limit: Reference): NumberSchema; + + /** + * Specifies that the value must be less than limit. + * It can also be a reference to another field. + */ + less(limit: number): NumberSchema; + less(limit: Reference): NumberSchema; + + /** + * Requires the number to be an integer (no floating point). + */ + integer(): NumberSchema; + + /** + * Specifies the maximum number of decimal places where: + * limit - the maximum number of decimal places allowed. + */ + precision(limit: number): NumberSchema; + + /** + * Specifies that the value must be a multiple of base. + */ + multiple(base: number): NumberSchema; + + /** + * Requires the number to be positive. + */ + positive(): NumberSchema; + + /** + * Requires the number to be negative. + */ + negative(): NumberSchema; +} + +export interface StringSchema extends AnySchema { + /** + * Allows the value to match any whitelist of blacklist item in a case insensitive comparison. + */ + insensitive(): StringSchema; + + /** + * Specifies the minimum number string characters. + * @param limit - the minimum number of string characters required. It can also be a reference to another field. + * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. + */ + min(limit: number, encoding?: string): StringSchema; + min(limit: Reference, encoding?: string): StringSchema; + + /** + * Specifies the maximum number of string characters. + * @param limit - the maximum number of string characters allowed. It can also be a reference to another field. + * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. + */ + max(limit: number, encoding?: string): StringSchema; + max(limit: Reference, encoding?: string): StringSchema; + + /** + * Requires the number to be a credit card number (Using Lunh Algorithm). + */ + creditCard(): StringSchema; + + /** + * Specifies the exact string length required + * @param limit - the required string length. It can also be a reference to another field. + * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. + */ + length(limit: number, encoding?: string): StringSchema; + length(limit: Reference, encoding?: string): StringSchema; + + /** + * Defines a regular expression rule. + * @param pattern - a regular expression object the string value must match against. + * @param name - optional name for patterns (useful with multiple patterns). Defaults to 'required'. + */ + regex(pattern: RegExp, name?: string): StringSchema; + + /** + * Replace characters matching the given pattern with the specified replacement string where: + * @param pattern - a regular expression object to match against, or a string of which all occurrences will be replaced. + * @param replacement - the string that will replace the pattern. + */ + replace(pattern: RegExp, replacement: string): StringSchema; + replace(pattern: string, replacement: string): StringSchema; + + /** + * Requires the string value to only contain a-z, A-Z, and 0-9. + */ + alphanum(): StringSchema; + + /** + * Requires the string value to only contain a-z, A-Z, 0-9, and underscore _. + */ + token(): StringSchema; + + /** + * Requires the string value to be a valid email address. + */ + email(options?: EmailOptions): StringSchema; + + /** + * Requires the string value to be a valid ip address. + */ + ip(options?: IpOptions): StringSchema; + + /** + * Requires the string value to be a valid RFC 3986 URI. + */ + uri(options?: UriOptions): StringSchema; + + /** + * Requires the string value to be a valid GUID. + */ + guid(): StringSchema; + + /** + * Requires the string value to be a valid hexadecimal string. + */ + hex(): StringSchema; + + /** + * Requires the string value to be a valid hostname as per RFC1123. + */ + hostname(): StringSchema; + + /** + * Requires the string value to be in valid ISO 8601 date format. + */ + isoDate(): StringSchema; + + /** + * Requires the string value to be all lowercase. If the validation convert option is on (enabled by default), the string will be forced to lowercase. + */ + lowercase(): StringSchema; + + /** + * Requires the string value to be all uppercase. If the validation convert option is on (enabled by default), the string will be forced to uppercase. + */ + uppercase(): StringSchema; + + /** + * Requires the string value to contain no whitespace before or after. If the validation convert option is on (enabled by default), the string will be trimmed. + */ + trim(): StringSchema; +} + +export interface ArraySchema extends AnySchema { + /** + * Allow this array to be sparse. + * enabled can be used with a falsy value to go back to the default behavior. + */ + sparse(enabled?: any): ArraySchema; + + /** + * Allow single values to be checked against rules as if it were provided as an array. + * enabled can be used with a falsy value to go back to the default behavior. + */ + single(enabled?: any): ArraySchema; + + /** + * List the types allowed for the array values. + * type can be an array of values, or multiple values can be passed as individual arguments. + * If a given type is .required() then there must be a matching item in the array. + * If a type is .forbidden() then it cannot appear in the array. + * Required items can be added multiple times to signify that multiple items must be found. + * Errors will contain the number of items that didn't match. + * Any unmatched item having a label will be mentioned explicitly. + * + * @param type - a joi schema object to validate each array item against. + */ + items(type: Schema, ...types: Schema[]): ArraySchema; + items(types: Schema[]): ArraySchema; + + /** + * Specifies the minimum number of items in the array. + */ + min(limit: number): ArraySchema; + + /** + * Specifies the maximum number of items in the array. + */ + max(limit: number): ArraySchema; + + /** + * Specifies the exact number of items in the array. + */ + length(limit: number): ArraySchema; + + /** + * Requires the array values to be unique. + * Be aware that a deep equality is performed on elements of the array having a type of object, + * a performance penalty is to be expected for this kind of operation. + */ + unique(): ArraySchema; +} + +export interface ObjectSchema extends AnySchema { + /** + * Sets the allowed object keys. + */ + keys(schema?: SchemaMap): ObjectSchema; + + /** + * Specifies the minimum number of keys in the object. + */ + min(limit: number): ObjectSchema; + + /** + * Specifies the maximum number of keys in the object. + */ + max(limit: number): ObjectSchema; + + /** + * Specifies the exact number of keys in the object. + */ + length(limit: number): ObjectSchema; + + /** + * Specify validation rules for unknown keys matching a pattern. + */ + pattern(regex: RegExp, schema: Schema): ObjectSchema; + + /** + * Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well. + * @param peers - the key names of which if one present, all are required. peers can be a single string value, + * an array of string values, or each peer provided as an argument. + */ + and(peer1: string, ...peers: string[]): ObjectSchema; + and(peers: string[]): ObjectSchema; + + /** + * Defines a relationship between keys where not all peers can be present at the same time. + * @param peers - the key names of which if one present, the others may not all be present. + * peers can be a single string value, an array of string values, or each peer provided as an argument. + */ + nand(peer1: string, ...peers: string[]): ObjectSchema; + nand(peers: string[]): ObjectSchema; + + /** + * Defines a relationship between keys where one of the peers is required (and more than one is allowed). + */ + or(peer1: string, ...peers: string[]): ObjectSchema; + or(peers: string[]): ObjectSchema; + + /** + * Defines an exclusive relationship between a set of keys. one of them is required but not at the same time where: + */ + xor(peer1: string, ...peers: string[]): ObjectSchema; + xor(peers: string[]): ObjectSchema; + + /** + * Requires the presence of other keys whenever the specified key is present. + */ + with(key: string, peers: string): ObjectSchema; + with(key: string, peers: string[]): ObjectSchema; + + /** + * Forbids the presence of other keys whenever the specified is present. + */ + without(key: string, peers: string): ObjectSchema; + without(key: string, peers: string[]): ObjectSchema; + + /** + * Renames a key to another name (deletes the renamed key). + */ + rename(from: string, to: string, options?: RenameOptions): ObjectSchema; + + /** + * Verifies an assertion where. + */ + assert(ref: string, schema: Schema, message?: string): ObjectSchema; + assert(ref: Reference, schema: Schema, message?: string): ObjectSchema; + + /** + * Overrides the handling of unknown keys for the scope of the current object only (does not apply to children). + */ + unknown(allow?: boolean): ObjectSchema; + + /** + * Requires the object to be an instance of a given constructor. + * + * @param constructor - the constructor function that the object must be an instance of. + * @param name - an alternate name to use in validation errors. This is useful when the constructor function does not have a name. + */ + type(constructor: Function, name?: string): ObjectSchema; + + /** + * Sets the specified children to required. + * + * @param children - can be a single string value, an array of string values, or each child provided as an argument. + * + * var schema = Joi.object().keys({ a: { b: Joi.number() }, c: { d: Joi.string() } }); + * var requiredSchema = schema.requiredKeys('', 'a.b', 'c', 'c.d'); + * + * Note that in this example '' means the current object, a is not required but b is, as well as c and d. + */ + requiredKeys(children: string): ObjectSchema; + requiredKeys(children: string[]): ObjectSchema; + requiredKeys(child: string, ...children: string[]): ObjectSchema; + + /** + * Sets the specified children to optional. + * + * @param children - can be a single string value, an array of string values, or each child provided as an argument. + * + * The behavior is exactly the same as requiredKeys. + */ + optionalKeys(children: string): ObjectSchema; + optionalKeys(children: string[]): ObjectSchema; + optionalKeys(child: string, ...children: string[]): ObjectSchema; +} + +export interface BinarySchema extends AnySchema { + /** + * Sets the string encoding format if a string input is converted to a buffer. + */ + encoding(encoding: string): BinarySchema; + + /** + * Specifies the minimum length of the buffer. + */ + min(limit: number): BinarySchema; + + /** + * Specifies the maximum length of the buffer. + */ + max(limit: number): BinarySchema; + + /** + * Specifies the exact length of the buffer: + */ + length(limit: number): BinarySchema; +} + +export interface DateSchema extends AnySchema { + /** + * Specifies the oldest date allowed. + * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, + * allowing to explicitly ensure a date is either in the past or in the future. + * It can also be a reference to another field. + */ + min(date: Date): DateSchema; + min(date: number): DateSchema; + min(date: string): DateSchema; + min(date: Reference): DateSchema; + + /** + * Specifies the latest date allowed. + * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, + * allowing to explicitly ensure a date is either in the past or in the future. + * It can also be a reference to another field. + */ + max(date: Date): DateSchema; + max(date: number): DateSchema; + max(date: string): DateSchema; + max(date: Reference): DateSchema; + + /** + * Specifies the allowed date format: + * @param format - string or array of strings that follow the moment.js format. + */ + format(format: string): DateSchema; + format(format: string[]): DateSchema; + + /** + * Requires the string value to be in valid ISO 8601 date format. + */ + iso(): DateSchema; +} + +export interface FunctionSchema extends AnySchema { +} + +export interface AlternativesSchema extends AnySchema { + try(schemas: Schema[]): AlternativesSchema; + when(ref: string, options: WhenOptions): AlternativesSchema; + when(ref: Reference, options: WhenOptions): AlternativesSchema; +} + +// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- + +/** + * Generates a schema object that matches any data type. + */ +export function any(): Schema; + +/** + * Generates a schema object that matches an array data type. + */ +export function array(): ArraySchema; + +/** + * Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via bool(). + */ +export function bool(): BooleanSchema; + +export function boolean(): BooleanSchema; + +/** + * Generates a schema object that matches a Buffer data type (as well as the strings which will be converted to Buffers). + */ +export function binary(): BinarySchema; + +/** + * Generates a schema object that matches a date type (as well as a JavaScript date string or number of milliseconds). + */ +export function date(): DateSchema; + +/** + * Generates a schema object that matches a function type. + */ +export function func(): FunctionSchema; + +/** + * Generates a schema object that matches a number data type (as well as strings that can be converted to numbers). + */ +export function number(): NumberSchema; + +/** + * Generates a schema object that matches an object data type (as well as JSON strings that parsed into objects). + */ +export function object(schema?: SchemaMap): ObjectSchema; + +/** + * Generates a schema object that matches a string data type. Note that empty strings are not allowed by default and must be enabled with allow(''). + */ +export function string(): StringSchema; + +/** + * Generates a type that will match one of the provided alternative schemas + */ +export function alternatives(types: Schema[]): Schema; +export function alternatives(type1: Schema, type2: Schema, ...types: Schema[]): Schema; + +/** + * Validates a value using the given schema and options. + */ +export function validate(value: T, schema: Schema, callback: (err: ValidationError, value: T) => void): void; +export function validate(value: T, schema: Object, callback: (err: ValidationError, value: T) => void): void; +export function validate(value: T, schema: Object, options?: ValidationOptions, callback?: (err: ValidationError, value: T) => void): ValidationResult; + +/** + * Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object). + */ +export function compile(schema: Object): Schema; + +/** + * Validates a value against a schema and throws if validation fails. + * + * @param value - the value to validate. + * @param schema - the schema object. + * @param message - optional message string prefix added in front of the error message. may also be an Error object. + */ +export function assert(value: any, schema: Schema, message?: string | Error): void; + +/** + * Generates a reference to the value of the named key. + */ +export function ref(key: string, options?: ReferenceOptions): Reference; diff --git a/types/joi/v6/joi-tests.ts b/types/joi/v6/joi-tests.ts index 33923b500a..d8c5a99ae2 100644 --- a/types/joi/v6/joi-tests.ts +++ b/types/joi/v6/joi-tests.ts @@ -2,48 +2,42 @@ import Joi = require('joi'); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var x: any = null; -var value: any = null; -var num: number = 0; -var str: string = ''; -var bool: boolean = false; -var exp: RegExp = null; -var obj: Object = null; -var date: Date = null; -var err: Error = null; -var func: Function = null; +let x: any = null; +declare const value: any; +let num = 0; +let str = ''; +declare const bool: boolean; +declare const exp: RegExp; +declare const obj: Object; +declare const date: Date; +declare const err: Error; +declare const func: Function; -var anyArr: any[] = []; -var numArr: number[] = []; -var strArr: string[] = []; -var boolArr: boolean[] = []; -var expArr: RegExp[] = []; -var objArr: Object[] = []; -var errArr: Error[] = []; -var funcArr: Function[] = []; +declare const strArr: string[]; +declare const expArr: RegExp[]; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var schema: Joi.Schema = null; +let schema: Joi.Schema = null; -var anySchema: Joi.AnySchema = null; -var numSchema: Joi.NumberSchema = null; -var strSchema: Joi.StringSchema = null; -var arrSchema: Joi.ArraySchema = null; -var boolSchema: Joi.BooleanSchema = null; -var binSchema: Joi.BinarySchema = null; -var dateSchema: Joi.DateSchema = null; -var funcSchema: Joi.FunctionSchema = null; -var objSchema: Joi.ObjectSchema = null; -var altSchema: Joi.AlternativesSchema = null; +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; -var schemaArr: Joi.Schema[] = []; +declare const schemaArr: Joi.Schema[]; -var ref: Joi.Reference = null; +let ref: Joi.Reference = null; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var validOpts: Joi.ValidationOptions = null; +let validOpts: Joi.ValidationOptions = null; validOpts = {abortEarly: bool}; validOpts = {convert: bool}; @@ -56,7 +50,7 @@ validOpts = {context: obj}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var renOpts: Joi.RenameOptions = null; +let renOpts: Joi.RenameOptions = null; renOpts = {alias: bool}; renOpts = {multiple: bool}; @@ -65,7 +59,7 @@ renOpts = {ignoreUndefined: bool}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var emailOpts: Joi.EmailOptions = null; +let emailOpts: Joi.EmailOptions = null; emailOpts = {errorLevel: num}; emailOpts = {errorLevel: bool}; @@ -75,7 +69,7 @@ emailOpts = {minDomainAtoms: num}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var ipOpts: Joi.IpOptions = null; +let ipOpts: Joi.IpOptions = null; ipOpts = {version: str}; ipOpts = {version: strArr}; @@ -83,7 +77,7 @@ ipOpts = {cidr: str}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var uriOpts: Joi.UriOptions = null; +let uriOpts: Joi.UriOptions = null; uriOpts = {scheme: str}; uriOpts = {scheme: exp}; @@ -92,7 +86,7 @@ uriOpts = {scheme: expArr}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var whenOpts: Joi.WhenOptions = null; +let whenOpts: Joi.WhenOptions = null; whenOpts = {is: x}; whenOpts = {is: schema, then: schema}; @@ -100,17 +94,17 @@ whenOpts = {is: schema, otherwise: schema}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var refOpts: Joi.ReferenceOptions = null; +let refOpts: Joi.ReferenceOptions = null; refOpts = {separator: str}; refOpts = {contextPrefix: str}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var validErr: Joi.ValidationError = null; -var validErrItem: Joi.ValidationErrorItem; +declare const validErr: Joi.ValidationError; +let validErrItem: Joi.ValidationErrorItem; -validErrItem= { +validErrItem = { message: str, type: str, path: str @@ -149,7 +143,7 @@ anySchema = objSchema; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- -var schemaMap: Joi.SchemaMap = null; +let schemaMap: Joi.SchemaMap = null; schemaMap = { a: numSchema, @@ -160,7 +154,7 @@ schemaMap = { anySchema = Joi.any(); -namespace common { +{ // common anySchema = anySchema.allow(x); anySchema = anySchema.allow(x, x); anySchema = anySchema.allow([x, x, x]); @@ -235,10 +229,9 @@ arrSchema = arrSchema.items(numSchema); arrSchema = arrSchema.items(numSchema, strSchema); arrSchema = arrSchema.items([numSchema, strSchema]); - // - - - - - - - - -namespace common_copy_paste { +{ // common copy paste // use search & replace from any arrSchema = arrSchema.allow(x); arrSchema = arrSchema.allow(x, x); @@ -291,7 +284,7 @@ namespace common_copy_paste { boolSchema = Joi.bool(); boolSchema = Joi.boolean(); -namespace common_copy_paste { +{ // common copy paste boolSchema = boolSchema.allow(x); boolSchema = boolSchema.allow(x, x); boolSchema = boolSchema.allow([x, x, x]); @@ -347,7 +340,7 @@ binSchema = binSchema.min(num); binSchema = binSchema.max(num); binSchema = binSchema.length(num); -namespace common { +{ // common binSchema = binSchema.allow(x); binSchema = binSchema.allow(x, x); binSchema = binSchema.allow([x, x, x]); @@ -415,7 +408,7 @@ dateSchema = dateSchema.format(strArr); dateSchema = dateSchema.iso(); -namespace common { +{ // common dateSchema = dateSchema.allow(x); dateSchema = dateSchema.allow(x, x); dateSchema = dateSchema.allow([x, x, x]); @@ -484,7 +477,7 @@ numSchema = numSchema.multiple(num); numSchema = numSchema.positive(); numSchema = numSchema.negative(); -namespace common { +{ // common numSchema = numSchema.allow(x); numSchema = numSchema.allow(x, x); numSchema = numSchema.allow([x, x, x]); @@ -593,7 +586,7 @@ objSchema = objSchema.optionalKeys(str); objSchema = objSchema.optionalKeys(str, str); objSchema = objSchema.optionalKeys(strArr); -namespace common { +{ // common objSchema = objSchema.allow(x); objSchema = objSchema.allow(x, x); objSchema = objSchema.allow([x, x, x]); @@ -678,7 +671,7 @@ strSchema = strSchema.lowercase(); strSchema = strSchema.uppercase(); strSchema = strSchema.trim(); -namespace common { +{ // common strSchema = strSchema.allow(x); strSchema = strSchema.allow(x, x); strSchema = strSchema.allow([x, x, x]); diff --git a/types/joi/v6/tslint.json b/types/joi/v6/tslint.json index a41bf5d19a..0b8095b5e1 100644 --- a/types/joi/v6/tslint.json +++ b/types/joi/v6/tslint.json @@ -1,79 +1,12 @@ { "extends": "dtslint/dt.json", "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, + // All are TODOs "ban-types": false, "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false + "unified-signatures": false } }