Skip to content

Interface: Reference ​

A reference to another value, resolved during the validation: a sibling key ('b'), a key of an ancestor ('...b', '/root.key'), or a value of the global context ('$key'). Created by DTO.Ref(key) (DTO.In(key) for a list of values), and given in place of a value to the rules accepting one (min(), valid(), default()…).

Extends ​

Properties ​

adjust? ​

optional adjust?: (value) => any

A function adjusting the resolved value, like (value) => value + 5. The adjusted value is not validated: it must be what the rule using the reference expects. Cannot be combined with map.

Parameters ​

value ​

any

Returns ​

any

Inherited from ​

Exclude.adjust


ancestor? ​

optional ancestor?: number

The starting point of the reference: 0 for the value itself, 1 for its parent (the object holding it), 2 for the grandparent… Cannot be combined with a key starting with separators ('...a').

Default ​

ts
the number of leading separators of the key, else 1

Inherited from ​

Exclude.ancestor


depth ​

depth: number

The number of keys in the path.


display ​

display: string

The text of the reference in the descriptions and the error messages, like ref:a.b or ref:global:key.


in? ​

optional in?: boolean

Whether the reference resolves to an array of values the value must be one of (what DTO.In() creates), in valid() and invalid().

Default ​

ts
false

Inherited from ​

Exclude.in


iterables? ​

optional iterables?: boolean

Whether the path reaches into the Map and Set objects.

Default ​

ts
false

Inherited from ​

Exclude.iterables


key ​

key: string

The path joined by the separator ('a.b'), or null for the reference to the value itself.


map? ​

optional map?: [any, any][]

Pairs [[from, to], …] mapping the resolved value to another one; a value not in the map is used as is. Cannot be combined with adjust.

Inherited from ​

Exclude.map


path ​

path: string[]

The keys of the path, from the starting point of the reference.


prefix? ​

optional prefix?: object

The characters marking the kind of a reference at the start of its key.

global? ​

optional global?: string

The prefix of the references to the context validation option.

Default ​
ts
'$'

local? ​

optional local?: string

The prefix of the references to the context of an error message or a rule.

Default ​
ts
'#'

root? ​

optional root?: string

The prefix of the references to the root value being validated.

Default ​
ts
'/'

Inherited from ​

Exclude.prefix


render? ​

optional render?: boolean

Whether the error messages show the resolved value instead of the name of the reference.

Default ​

ts
false

Inherited from ​

Exclude.render


root ​

root: string

The first key of the path.


separator? ​

optional separator?: string | false

The separator of the keys in a path, or false to read the whole path as a single key.

Default ​

ts
'.'

Inherited from ​

Exclude.separator


type ​

type: string

What the reference reaches: value (the validated value), global (the context validation option) or local (the context of an error message).

Methods ​

toString() ​

toString(): string

The text of the reference (display).

Returns ​

string

The text, like ref:a.b.

Released under the MIT License.