Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface FunctionSchema

Hierarchy

Index

Properties

$

0.0.46 provide

Starts a ruleset in order to apply multiple rule options. The set ends when rule(), keep(), message(), or warn() is called.

$_super

0.0.46 provide
$_super: Schema<any>

Parent schema object.

$_terms

0.0.46 provide
$_terms: Record<string, any>

Terms of current schema.

_flags

0.0.46 provide
_flags: Record<string, any>

Flags of current schema.

ruleset

0.0.46 provide

Starts a ruleset in order to apply multiple rule options. The set ends when rule(), keep(), message(), or warn() is called.

Optional type

0.0.46 provide
type: string

Methods

$_addRule

0.0.46 provide

$_compile

0.0.46 provide

$_createError

0.0.46 provide

$_getFlag

0.0.46 provide
  • $_getFlag(name: string): any
  • Get value from given flag.

    Parameters

    • name: string

    Returns any

$_getRule

0.0.46 provide
  • Retrieve some rule configuration.

    Parameters

    • name: string

    Returns undefined | GetRuleOptions

$_mapLabels

0.0.46 provide
  • $_mapLabels(path: string | string[]): string
  • Parameters

    • path: string | string[]

    Returns string

$_match

0.0.46 provide
  • Returns true if validations runs fine on given value.

    Parameters

    Returns boolean

$_modify

0.0.46 provide

$_mutateRebuild

0.0.46 provide

$_mutateRegister

0.0.46 provide

$_property

0.0.46 provide
  • $_property(name: string): any
  • Get value from given property.

    Parameters

    • name: string

    Returns any

$_reach

0.0.46 provide
  • $_reach(path: string[]): Schema<any>
  • Get schema at given path.

    Parameters

    • path: string[]

    Returns Schema<any>

$_rootReferences

0.0.46 provide
  • $_rootReferences(): any
  • Get current schema root references.

    Returns any

$_setFlag

0.0.46 provide
  • Set flag to given value.

    Parameters

    Returns void

$_validate

0.0.46 provide

allow

0.0.46 provide
  • Whitelists a value

    Parameters

    • Rest ...values: any[]

    Returns FunctionSchema

alter

0.0.46 provide
  • Assign target alteration options to a schema that are applied when any.tailor() is called.

    Parameters

    • targets: Record<string, (schema: FunctionSchema) => Schema<any>>

      an object where each key is a target name, and each value is a function that takes an schema and returns an schema.

    Returns FunctionSchema

and

0.0.46 provide
  • Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well.

    Optional settings must be the last argument.

    Parameters

    Returns FunctionSchema

append

0.0.46 provide

arity

0.0.46 provide
  • Specifies the arity of the function where:

    Parameters

    • n: number

      the arity expected.

    Returns FunctionSchema

assert

0.0.46 provide

bind

0.0.46 provide
  • By default, some Joi methods to function properly need to rely on the Joi instance they are attached to because they use this internally. So Joi.string() works but if you extract the function from it and call string() it won't. bind() creates a new Joi instance where all the functions relying on this are bound to the Joi instance.

    Returns FunctionSchema

cache

0.0.46 provide
  • Adds caching to the schema which will attempt to cache the validation results (success and failures) of incoming inputs. If no cache is passed, a default cache is provisioned by using cache.provision() internally.

    Parameters

    Returns FunctionSchema

cast

0.0.46 provide
  • Casts the validated value to the specified type.

    Parameters

    • to: "string" | "number" | "map" | "set"

    Returns FunctionSchema

class

0.0.46 provide
  • Requires the function to be a class.

    Returns FunctionSchema

concat

0.0.46 provide

custom

0.0.46 provide

default

0.0.46 provide
  • Sets a default value if the original value is undefined where:

    Parameters

    • Optional value: null | string | number | boolean | object | any[] | Reference | ((parent: any, helpers: CustomHelpers<any>) => null | string | number | boolean | object | any[] | Reference)

      the default value. One of:

      • a literal value (string, number, object, etc.)
      • a references
      • a function which returns the default value using the signature function(parent, helpers) where:
        • parent - a clone of the object containing the value being validated. Note that since specifying a parent argument performs cloning, do not declare format arguments if you are not using them.
        • helpers - same as thsoe described in any.custom()

      When called without any value on an object schema type, a default value will be automatically generated based on the default values of the object keys.

      Note that if value is an object, any changes to the object after default() is called will change the reference and any future assignment.

    Returns FunctionSchema

describe

0.0.46 provide
  • Returns a plain object representing the schema's rules and properties

    Returns Description

description

0.0.46 provide

disallow

0.0.46 provide

empty

0.0.46 provide

equal

0.0.46 provide
  • Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.

    Parameters

    • Rest ...values: any[]

    Returns FunctionSchema

error

0.0.46 provide
  • 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 FunctionSchema

example

0.0.46 provide
  • example(value: any, options?: { override: boolean }): FunctionSchema
  • Annotates the key with an example value, must be valid.

    Parameters

    • value: any
    • Optional options: { override: boolean }
      • override: boolean

    Returns FunctionSchema

exist

0.0.46 provide
  • Marks a key as required which will not allow undefined as value. All keys are optional by default.

    Returns FunctionSchema

external

0.0.46 provide
  • Adds an external validation rule.

    Note that external validation rules are only called after the all other validation rules for the entire schema (from the value root) are checked. This means that any changes made to the value by the external rules are not available to any other validation rules during the non-external validation phase. If schema validation failed, no external validation rules are called.

    Parameters

    Returns FunctionSchema

extract

0.0.46 provide
  • extract(path: string | string[]): Schema<any>
  • Returns a sub-schema based on a path of object keys or schema ids.

    Parameters

    • path: string | string[]

      a dot . separated path string or a pre-split array of path keys. The keys must match the sub-schema id or object key (if no id was explicitly set).

    Returns Schema<any>

failover

0.0.46 provide
  • Sets a failover value if the original value fails passing validation.

    Parameters

    • value: any

      the failover value. value supports references. value may be assigned 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. Note that if value is an object, any changes to the object after failover() is called will change the reference and any future assignment. Use a function when setting a dynamic value (e.g. the current time). Using a function with a single argument performs some internal cloning which has a performance impact. If you do not need access to the context, define the function without any arguments.

    Returns FunctionSchema

forbidden

0.0.46 provide
  • Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.

    Returns FunctionSchema

fork

0.0.46 provide
  • Returns a new schema where each of the path keys listed have been modified.

    Parameters

    • key: string | string[] | string[][]

      an array of key strings, a single key string, or an array of arrays of pre-split key strings.

    • adjuster: SchemaFunction

      a function which must return a modified schema.

    Returns FunctionSchema

id

0.0.46 provide
  • Sets a schema id for reaching into the schema via any.extract(). If no id is set, the schema id defaults to the object key it is associated with. If the schema is used in an array or alternatives type and no id is set, the schema in unreachable.

    Parameters

    • Optional name: string

    Returns FunctionSchema

instance

0.0.46 provide
  • Requires the object to be an instance of a given constructor.

    Parameters

    • constructor: Function

      the constructor function that the object must be an instance of.

    • Optional name: string

      an alternate name to use in validation errors. This is useful when the constructor function does not have a name.

    Returns FunctionSchema

invalid

0.0.46 provide

keep

0.0.46 provide
  • Same as rule({ keep: true }).

    Note that keep() will terminate the current ruleset and cannot be followed by another rule option. Use rule() to apply multiple rule options.

    Returns FunctionSchema

keys

0.0.46 provide

label

0.0.46 provide
  • Overrides the key name in error messages.

    Parameters

    • name: string

    Returns FunctionSchema

length

0.0.46 provide
  • Specifies the exact number of keys in the object.

    Parameters

    • limit: number

    Returns FunctionSchema

max

0.0.46 provide
  • Specifies the maximum number of keys in the object.

    Parameters

    Returns FunctionSchema

maxArity

0.0.46 provide
  • Specifies the minimal arity of the function where:

    Parameters

    • n: number

      the minimal arity expected.

    Returns FunctionSchema

message

0.0.46 provide
  • Same as rule({ message }).

    Note that message() will terminate the current ruleset and cannot be followed by another rule option. Use rule() to apply multiple rule options.

    Parameters

    • message: string

    Returns FunctionSchema

messages

0.0.46 provide
  • Same as any.prefs({ messages }). Note that while any.message() applies only to the last rule or ruleset, any.messages() applies to the entire schema.

    Parameters

    • messages: Record<string, string>

    Returns FunctionSchema

meta

0.0.46 provide
  • Attaches metadata to the key.

    Parameters

    • meta: object

    Returns FunctionSchema

min

0.0.46 provide
  • Specifies the minimum number of keys in the object.

    Parameters

    Returns FunctionSchema

minArity

0.0.46 provide
  • Specifies the minimal arity of the function where:

    Parameters

    • n: number

      the minimal arity expected.

    Returns FunctionSchema

nand

0.0.46 provide
  • Defines a relationship between keys where not all peers can be present at the same time.

    Optional settings must be the last argument.

    Parameters

    Returns FunctionSchema

not

0.0.46 provide
  • Disallows values.

    Parameters

    • Rest ...values: any[]

    Returns FunctionSchema

note

0.0.46 provide
  • Annotates the key

    Parameters

    • Rest ...notes: string[]

    Returns FunctionSchema

only

0.0.46 provide
  • Requires the validated value to match of the provided any.allow() values. It has not effect when called together with any.valid() since it already sets the requirements. When used with any.allow() it converts it to an any.valid().

    Returns FunctionSchema

optional

0.0.46 provide
  • 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 FunctionSchema

options

0.0.46 provide

or

0.0.46 provide
  • Defines a relationship between keys where one of the peers is required (and more than one is allowed).

    Optional settings must be the last argument.

    Parameters

    Returns FunctionSchema

oxor

0.0.46 provide
  • Defines an exclusive relationship between a set of keys where only one is allowed but none are required.

    Optional settings must be the last argument.

    Parameters

    Returns FunctionSchema

pattern

0.0.46 provide

preferences

0.0.46 provide

prefs

0.0.46 provide

presence

0.0.46 provide

raw

0.0.46 provide
  • Outputs the original untouched value instead of the casted value.

    Parameters

    • Optional enabled: boolean

    Returns FunctionSchema

ref

0.0.46 provide
  • Requires the object to be a Joi reference.

    Returns FunctionSchema

regex

0.0.46 provide

rename

0.0.46 provide
  • Renames a key to another name (deletes the renamed key).

    Parameters

    • from: string | RegExp
    • to: string
    • Optional options: RenameOptions

    Returns FunctionSchema

required

0.0.46 provide
  • Marks a key as required which will not allow undefined as value. All keys are optional by default.

    Returns FunctionSchema

rule

0.0.46 provide
  • Applies a set of rule options to the current ruleset or last rule added.

    When applying rule options, the last rule (e.g. min()) is used unless there is an active ruleset defined (e.g. $.min().max()) in which case the options are applied to all the provided rules. Once rule() is called, the previous rules can no longer be modified and any active ruleset is terminated.

    Rule modifications can only be applied to supported rules. Most of the any methods do not support rule modifications because they are implemented using schema flags (e.g. required()) or special internal implementation (e.g. valid()). In those cases, use the any.messages() method to override the error codes for the errors you want to customize.

    Parameters

    Returns FunctionSchema

schema

0.0.46 provide

shared

0.0.46 provide
  • Registers a schema to be used by decendents of the current schema in named link references.

    Parameters

    Returns FunctionSchema

strict

0.0.46 provide
  • Sets the options.convert options to false which prevent type casting for the current key and any child keys.

    Parameters

    • Optional isStrict: boolean

    Returns FunctionSchema

strip

0.0.46 provide
  • Marks a key to be removed from a resulting object or array after validation. Used to sanitize output.

    Parameters

    • Optional enabled: boolean

    Returns FunctionSchema

tag

0.0.46 provide
  • Annotates the key

    Parameters

    • Rest ...tags: string[]

    Returns FunctionSchema

tailor

0.0.46 provide
  • tailor(targets: string | string[]): Schema<any>
  • Applies any assigned target alterations to a copy of the schema that were applied via any.alter().

    Parameters

    • targets: string | string[]

    Returns Schema<any>

unit

0.0.46 provide
  • Annotates the key with an unit name.

    Parameters

    • name: string

    Returns FunctionSchema

unknown

0.0.46 provide
  • Overrides the handling of unknown keys for the scope of the current object only (does not apply to children).

    Parameters

    • Optional allow: boolean

    Returns FunctionSchema

valid

0.0.46 provide
  • Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.

    Parameters

    • Rest ...values: any[]

    Returns FunctionSchema

validate

0.0.46 provide

validateAsync

0.0.46 provide

warn

0.0.46 provide
  • Same as rule({ warn: true }). Note that warn() will terminate the current ruleset and cannot be followed by another rule option. Use rule() to apply multiple rule options.

    Returns FunctionSchema

warning

0.0.46 provide
  • Generates a warning. When calling any.validateAsync(), set the warning option to true to enable warnings. Warnings are reported separately from errors alongside the result value via the warning key (i.e. { value, warning }). Warning are always included when calling any.validate().

    Parameters

    Returns FunctionSchema

when

0.0.46 provide

with

0.0.46 provide

without

0.0.46 provide

xor

0.0.46 provide
  • Defines an exclusive relationship between a set of keys. one of them is required but not at the same time.

    Optional settings must be the last argument.

    Parameters

    Returns FunctionSchema