Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • AnySchema
    • OurJoiSchema

Index

Properties

isJoi

isJoi: boolean

Optional schemaType

schemaType: Types | string

Methods

allow

  • allow(...values: any[]): this
  • allow(values: any[]): this
  • Whitelists a value

    Parameters

    • Rest ...values: any[]

    Returns this

  • Parameters

    • values: any[]

    Returns this

concat

  • concat(schema: this): this
  • Returns a new type that is the result of adding the rules of one type to another.

    Parameters

    • schema: this

    Returns this

default

  • default(value: any, description?: string): this
  • default(): this
  • Sets a default value if the original value is undefined.

    Parameters

    • value: any

      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.

    • Optional description: string

    Returns this

  • Returns this

describe

  • describe(): Description
  • Returns a plain object representing the schema's rules and properties

    Returns Description

description

  • description(desc: string): this
  • Annotates the key

    Parameters

    • desc: string

    Returns this

disallow

  • disallow(...values: any[]): this
  • disallow(values: any[]): this
  • Parameters

    • Rest ...values: any[]

    Returns this

  • Parameters

    • values: any[]

    Returns this

empty

  • empty(schema?: SchemaLike): this
  • Considers anything that matches the schema to be empty (undefined).

    Parameters

    • Optional schema: SchemaLike

      any object or joi schema to match. An undefined schema unsets that rule.

    Returns this

equal

  • equal(...values: any[]): this
  • equal(values: any[]): this
  • Parameters

    • Rest ...values: any[]

    Returns this

  • Parameters

    • values: any[]

    Returns this

error

  • error(err: Error | ValidationErrorFunction): this
  • Overrides the default joi error with a custom error if the rule fails where:

    Parameters

    • err: Error | ValidationErrorFunction

      can be: an instance of Error - the override error. a function(errors), taking an array of errors as argument, where it must either: return a string - substitutes the error message with this text return a single object or an Array of it, where: type - optional parameter providing the type of the error (eg. number.min). message - optional parameter if template is provided, containing the text of the error. template - optional parameter if message is provided, containing a template string, using the same format as usual joi language errors. context - optional parameter, to provide context to your error if you are using the template. return an Error - same as when you directly provide an Error, but you can customize the error message based on the errors.

      Note that if you provide an Error, it will be returned as-is, unmodified and undecorated with any of the normal joi error properties. If validation fails and another error is found before the error override, that error will be returned and the override will be ignored (unless the abortEarly option has been set to false).

    Returns this

example

  • example(value: any): this
  • Annotates the key with an example value, must be valid.

    Parameters

    • value: any

    Returns this

exist

  • exist(): this
  • Returns this

forbidden

  • forbidden(): this
  • Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.

    Returns this

invalid

  • invalid(...values: any[]): this
  • invalid(values: any[]): this
  • Blacklists a value

    Parameters

    • Rest ...values: any[]

    Returns this

  • Parameters

    • values: any[]

    Returns this

label

  • label(name: string): this
  • Overrides the key name in error messages.

    Parameters

    • name: string

    Returns this

meta

  • meta(meta: object): this
  • Attaches metadata to the key.

    Parameters

    • meta: object

    Returns this

not

  • not(...values: any[]): this
  • not(values: any[]): this
  • Parameters

    • Rest ...values: any[]

    Returns this

  • Parameters

    • values: any[]

    Returns this

notes

  • notes(notes: string): this
  • notes(notes: string[]): this
  • Annotates the key

    Parameters

    • notes: string

    Returns this

  • Parameters

    • notes: string[]

    Returns this

only

  • only(...values: any[]): this
  • only(values: any[]): this
  • Parameters

    • Rest ...values: any[]

    Returns this

  • Parameters

    • values: any[]

    Returns this

optional

  • optional(): this
  • 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.

    Returns this

options

  • options(options: ValidationOptions): this
  • Overrides the global validate() options for the current key and any sub-key.

    Parameters

    • options: ValidationOptions

    Returns this

raw

  • raw(isRaw?: boolean): this
  • Outputs the original untouched value instead of the casted value.

    Parameters

    • Optional isRaw: boolean

    Returns this

required

  • required(): this
  • Marks a key as required which will not allow undefined as value. All keys are optional by default.

    Returns this

strict

  • strict(isStrict?: boolean): this
  • Sets the options.convert options to false which prevent type casting for the current key and any child keys.

    Parameters

    • Optional isStrict: boolean

    Returns this

strip

  • strip(): this
  • Marks a key to be removed from a resulting object or array after validation. Used to sanitize output.

    Returns this

tags

  • tags(notes: string): this
  • tags(notes: string[]): this
  • Annotates the key

    Parameters

    • notes: string

    Returns this

  • Parameters

    • notes: string[]

    Returns this

uidType

  • Parameters

    Returns this

unit

  • unit(name: string): this
  • Annotates the key with an unit name.

    Parameters

    • name: string

    Returns this

valid

  • valid(...values: any[]): this
  • valid(values: any[]): this
  • Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.

    Parameters

    • Rest ...values: any[]

    Returns this

  • Parameters

    • values: any[]

    Returns this

validate

  • validate<T>(value: T): ValidationResult<T>
  • validate<T>(value: T, options: ValidationOptions): ValidationResult<T>
  • validate<T, R>(value: T, callback: function): R
  • validate<T, R>(value: T, options: ValidationOptions, callback: function): R
  • Validates a value using the schema and options.

    Type parameters

    • T

    Parameters

    • value: T

    Returns ValidationResult<T>

  • Type parameters

    • T

    Parameters

    • value: T
    • options: ValidationOptions

    Returns ValidationResult<T>

  • Type parameters

    • T

    • R

    Parameters

    • value: T
    • callback: function
        • (err: ValidationError, value: T): R
        • Parameters

          • err: ValidationError
          • value: T

          Returns R

    Returns R

  • Type parameters

    • T

    • R

    Parameters

    • value: T
    • options: ValidationOptions
    • callback: function
        • (err: ValidationError, value: T): R
        • Parameters

          • err: ValidationError
          • value: T

          Returns R

    Returns R

when

  • when(ref: string, options: WhenOptions): AlternativesSchema
  • when(ref: Reference, options: WhenOptions): AlternativesSchema
  • when(ref: Schema, options: WhenSchemaOptions): AlternativesSchema
  • Converts the type into an alternatives type where the conditions are merged into the type definition where:

    Parameters

    • ref: string
    • options: WhenOptions

    Returns AlternativesSchema

  • Parameters

    • ref: Reference
    • options: WhenOptions

    Returns AlternativesSchema

  • Parameters

    • ref: Schema
    • options: WhenSchemaOptions

    Returns AlternativesSchema

Generated using TypeDoc