new ObjectType()
Generates a schema object that matches an object data type.
Extends
Methods
allow(value) → {Type}
Whitelists the provided values.
Parameters:
Name | Type | Description |
---|---|---|
value |
* | Array.<*> | The values to add to the whitelist. It can be an array of values, or multiple values can be passed as individual arguments. |
- Inherited From:
- Source:
Returns:
The class reference so multiple calls can be chained.
- Type
- Type
forbidden() → {Type}
Marks a key as forbidden which will not allow any value except undefined.
Used to explicitly forbid keys.
- Inherited From:
- Source:
Returns:
The class reference so multiple calls can be chained.
- Type
- Type
getRules() → {Object}
Gets a cloned version of the internal rules of this type.
- Inherited From:
- Source:
Returns:
The internal rules.
- Type
- Object
invalid(value) → {Type}
Blacklists the provided values.
Parameters:
Name | Type | Description |
---|---|---|
value |
* | Array.<*> | The values to add to the blacklist. It can be an array of values, or multiple values can be passed as individual arguments. |
- Inherited From:
- Source:
Returns:
The class reference so multiple calls can be chained.
- Type
- Type
keys(keys) → {ObjectType}
Sets the allowed object keys.
Parameters:
Name | Type | Description |
---|---|---|
keys |
Object | Object where each key is assigned a joi type object. |
Returns:
The class reference so multiple calls can be chained.
- Type
- ObjectType
length(limit) → {ObjectType}
Specifies the exact number of keys in the object.
Parameters:
Name | Type | Description |
---|---|---|
limit |
Number | The number of object keys allowed. |
Returns:
The class reference so multiple calls can be chained.
- Type
- ObjectType
max(limit) → {ObjectType}
Specifies the maximum number of keys in the object.
Parameters:
Name | Type | Description |
---|---|---|
limit |
Number | The highest number of keys allowed. |
Returns:
The class reference so multiple calls can be chained.
- Type
- ObjectType
mergeRules(rules) → {Type}
Merges the internal rules of this type with the argument passed.
Parameters:
Name | Type | Description |
---|---|---|
rules |
Object | Internal rules as a plain object. |
- Inherited From:
- Source:
Returns:
The class reference so multiple calls can be chained.
- Type
- Type
min(limit) → {ObjectType}
Specifies the minimum number of keys in the object.
Parameters:
Name | Type | Description |
---|---|---|
limit |
Number | The lowest number of keys allowed. |
Returns:
The class reference so multiple calls can be chained.
- Type
- ObjectType
optional() → {Type}
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.
- Inherited From:
- Source:
Returns:
The class reference so multiple calls can be chained.
- Type
- Type
required() → {Type}
Marks a key as required which will not allow undefined as value.
All keys are optional by default.
- Inherited From:
- Source:
Returns:
The class reference so multiple calls can be chained.
- Type
- Type
setRules(rules) → {Type}
Sets the internal rules of this type using a plain object.
Parameters:
Name | Type | Description |
---|---|---|
rules |
Object | Internal rules as a plain object. |
- Inherited From:
- Source:
Returns:
The class reference so multiple calls can be chained.
- Type
- Type
type(constructor) → {ObjectType}
Requires the object to be an instance of a given constructor
Parameters:
Name | Type | Description |
---|---|---|
constructor |
function | The constructor function that the object must be an instance of. |
Returns:
The class reference so multiple calls can be chained.
- Type
- ObjectType
valid(value) → {Type}
Adds the provided values into the allowed whitelist and marks them as the only
valid values allowed.
Parameters:
Name | Type | Description |
---|---|---|
value |
* | Array.<*> | The values to add to the whitelist. It can be an array of values, or multiple values can be passed as individual arguments. |
- Inherited From:
- Source:
Returns:
The class reference so multiple calls can be chained.
- Type
- Type
validate(…value) → {Boolean}
Validates the passed arguments.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
* |
<repeatable> |
The value. |
- Inherited From:
- Source:
Returns:
Returns true if all arguments are successfully validated, else false.
- Type
- Boolean
validateList(valuesList) → {Boolean}
Validates an array of values.
Parameters:
Name | Type | Description |
---|---|---|
valuesList |
Array.<*> | The array of values. |
- Inherited From:
- Source:
Returns:
Returns true if all elements in the array are successfully
validated, else false.
- Type
- Boolean