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
Exclude<ReferenceOptions,"prefix">
Properties
adjust?
optionaladjust?: (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?
optionalancestor?: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
the number of leading separators of the key, else 1Inherited 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?
optionalin?: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
falseInherited from
Exclude.in
iterables?
optionaliterables?:boolean
Whether the path reaches into the Map and Set objects.
Default
falseInherited from
Exclude.iterables
key
key:
string
The path joined by the separator ('a.b'), or null for the reference to the value itself.
map?
optionalmap?: [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?
optionalprefix?:object
The characters marking the kind of a reference at the start of its key.
global?
optionalglobal?:string
The prefix of the references to the context validation option.
Default
'$'local?
optionallocal?:string
The prefix of the references to the context of an error message or a rule.
Default
'#'root?
optionalroot?:string
The prefix of the references to the root value being validated.
Default
'/'Inherited from
Exclude.prefix
render?
optionalrender?:boolean
Whether the error messages show the resolved value instead of the name of the reference.
Default
falseInherited from
Exclude.render
root
root:
string
The first key of the path.
separator?
optionalseparator?:string|false
The separator of the keys in a path, or false to read the whole path as a single key.
Default
'.'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.