Options
All
  • Public
  • Public/Protected
  • All
Menu

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
ruleset: LinkSchema

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 LinkSchema

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: LinkSchema) => 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 LinkSchema

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 LinkSchema

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 LinkSchema

cast

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

    Parameters

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

    Returns LinkSchema

concat

0.0.46 provide
  • Same as any.concat() but the schema is merged after the link is resolved which allows merging with schemas of the same type as the resolved link. Will throw an exception during validation if the merged types are not compatible.

    Parameters

    Returns LinkSchema

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 LinkSchema

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 LinkSchema

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 LinkSchema

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 LinkSchema

example

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

    Parameters

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

    Returns LinkSchema

exist

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

    Returns LinkSchema

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 LinkSchema

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 LinkSchema

forbidden

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

    Returns LinkSchema

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 LinkSchema

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 LinkSchema

invalid

0.0.46 provide
  • Disallows values.

    Parameters

    • Rest ...values: any[]

    Returns LinkSchema

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 LinkSchema

label

0.0.46 provide
  • Overrides the key name in error messages.

    Parameters

    • name: string

    Returns LinkSchema

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 LinkSchema

messages

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

meta

0.0.46 provide
  • Attaches metadata to the key.

    Parameters

    • meta: object

    Returns LinkSchema

not

0.0.46 provide
  • Disallows values.

    Parameters

    • Rest ...values: any[]

    Returns LinkSchema

note

0.0.46 provide
  • Annotates the key

    Parameters

    • Rest ...notes: string[]

    Returns LinkSchema

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 LinkSchema

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 LinkSchema

options

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

    Parameters

    Returns LinkSchema

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 LinkSchema

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 LinkSchema

ref

0.0.46 provide
  • Initializes the schema after constructions for cases where the schema has to be constructed first and then initialized. If ref was not passed to the constructor, link.ref() must be called prior to usaged.

    Parameters

    • ref: string

    Returns LinkSchema

required

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

    Returns LinkSchema

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 LinkSchema

shared

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

    Parameters

    Returns LinkSchema

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 LinkSchema

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 LinkSchema

tag

0.0.46 provide
  • Annotates the key

    Parameters

    • Rest ...tags: string[]

    Returns LinkSchema

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 LinkSchema

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 LinkSchema

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 LinkSchema

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 LinkSchema

when

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

    Parameters

    Returns LinkSchema

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

    Parameters

    Returns LinkSchema