Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ObjectSchema<TSchema>

Type parameters

  • TSchema = any

Hierarchy

Index

Properties

$

0.0.46 provide
$: ObjectSchema<TSchema>

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
ruleset: ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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: ObjectSchema<TSchema>) => 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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

append

0.0.46 provide
  • Appends the allowed object keys. If schema is null, undefined, or {}, no changes will be applied.

    Parameters

    Returns ObjectSchema<TSchema>

  • Type parameters

    • TSchemaExtended = any

    • T = TSchemaExtended

    Parameters

    Returns ObjectSchema<T>

assert

0.0.46 provide
  • Verifies an assertion where.

    Parameters

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

cast

0.0.46 provide
  • cast(to: "string" | "number" | "map" | "set"): ObjectSchema<TSchema>
  • Casts the validated value to the specified type.

    Parameters

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

    Returns ObjectSchema<TSchema>

concat

0.0.46 provide
  • Returns a new type that is the result of adding the rules of one type to another.

    Parameters

    Returns ObjectSchema<TSchema>

custom

0.0.46 provide
  • Adds a custom validation function.

    Parameters

    Returns ObjectSchema<TSchema>

default

0.0.46 provide
  • default(value?: null | string | number | boolean | object | any[] | Reference | ((parent: any, helpers: CustomHelpers<any>) => null | string | number | boolean | object | any[] | Reference)): ObjectSchema<TSchema>
  • 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 ObjectSchema<TSchema>

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
  • Disallows values.

    Parameters

    • Rest ...values: any[]

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

example

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

    Parameters

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

    Returns ObjectSchema<TSchema>

exist

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

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

forbidden

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

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

instance

0.0.46 provide
  • instance(constructor: Function, name?: string): ObjectSchema<TSchema>
  • 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 ObjectSchema<TSchema>

invalid

0.0.46 provide
  • Disallows values.

    Parameters

    • Rest ...values: any[]

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

keys

0.0.46 provide
  • Sets or extends the allowed object keys.

    Parameters

    Returns ObjectSchema<TSchema>

label

0.0.46 provide
  • Overrides the key name in error messages.

    Parameters

    • name: string

    Returns ObjectSchema<TSchema>

length

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

    Parameters

    • limit: number

    Returns ObjectSchema<TSchema>

max

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

    Parameters

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

messages

0.0.46 provide
  • messages(messages: Record<string, string>): ObjectSchema<TSchema>
  • 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 ObjectSchema<TSchema>

meta

0.0.46 provide
  • Attaches metadata to the key.

    Parameters

    • meta: object

    Returns ObjectSchema<TSchema>

min

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

    Parameters

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

not

0.0.46 provide
  • Disallows values.

    Parameters

    • Rest ...values: any[]

    Returns ObjectSchema<TSchema>

note

0.0.46 provide
  • Annotates the key

    Parameters

    • Rest ...notes: string[]

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

options

0.0.46 provide
  • Overrides the global validate() options for the current key and any sub-key.

    Parameters

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

pattern

0.0.46 provide

preferences

0.0.46 provide

prefs

0.0.46 provide
  • Overrides the global validate() options for the current key and any sub-key.

    Parameters

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

ref

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

    Returns ObjectSchema<TSchema>

regex

0.0.46 provide
  • Requires the object to be a RegExp object.

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

required

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

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

tag

0.0.46 provide
  • Annotates the key

    Parameters

    • Rest ...tags: string[]

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

validate

0.0.46 provide

validateAsync

0.0.46 provide
  • Validates a value using the schema and options.

    Parameters

    Returns Promise<any>

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 ObjectSchema<TSchema>

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 ObjectSchema<TSchema>

when

0.0.46 provide
  • Converts the type into an alternatives type where the conditions are merged into the type definition where:

    Parameters

    Returns ObjectSchema<TSchema>

  • Converts the type into an alternatives type where the conditions are merged into the type definition where:

    Parameters

    Returns ObjectSchema<TSchema>

with

0.0.46 provide
  • Requires the presence of other keys whenever the specified key is present.

    Parameters

    Returns ObjectSchema<TSchema>

without

0.0.46 provide
  • Forbids the presence of other keys whenever the specified is present.

    Parameters

    Returns ObjectSchema<TSchema>

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 ObjectSchema<TSchema>