Class: Schema
An instance of Schema
defines a set of parameters by name and fieldtype (see Field
).
Hierarchy
- Schema
Index
Constructors
Properties
Methods
Constructors
constructor
+ new Schema(fields
: object): Schema
Defined in lib/Schema.ts:15
Parameters:
Name | Type | Default | Description |
---|---|---|---|
fields |
object | {} | See Schema.prototype.fields . |
Returns: Schema
Properties
fields
• fields: object
Defined in lib/Schema.ts:12
An object whose values are all instances of Field
(herein fieldset).
lastError
• lastError: object
Defined in lib/Schema.ts:15
The error message produced by the last call to Schema.prototype.validate
, if it was unsuccessful.
Methods
clone
▸ clone(): Schema
Defined in lib/Schema.ts:28
Returns a copy of the Schema
instance.
Returns: Schema
default
▸ default(values
: object): Schema
Defined in lib/Schema.ts:86
Given an object values
whose keys correspond to fields on the instance's fieldset and whose values represent default values of those fields, applies those default values to the corresponding fields on a clone of the instance.
Parameters:
Name | Type | Description |
---|---|---|
values |
object | An object with keys corresponding to field names and values representing default field values. |
Returns: Schema
A new instance of Schema
.
exclude
▸ exclude(...keys
: Array‹string›): Schema
Defined in lib/Schema.ts:74
Creates a new schema containing a subset of the instance's fields.
Parameters:
Name | Type | Description |
---|---|---|
...keys |
Array‹string› | The names of the fields which should not be transferred to the new schema. |
Returns: Schema
A new instance of Schema
.
extend
▸ extend(fields
: object | Schema): Schema
Defined in lib/Schema.ts:40
Creates a new schema containing all of the instance's fields, plus additional fields
.
Parameters:
Name | Type | Description |
---|---|---|
fields |
object | Schema | A fieldset. |
Returns: Schema
A new instance of Schema
.
flags
▸ flags(values
: object): Schema
Defined in lib/Schema.ts:98
Given an object values
whose keys correspond to fields on the instance's fieldset and whose values represent flag
values, applies those flag values to the corresponding fields on a clone of the instance.
Parameters:
Name | Type | Description |
---|---|---|
values |
object | An object with keys corresponding to field names and values representing flag values. |
Returns: Schema
A new instance of Schema
.
select
▸ select(fields
: object | string, ...keys
: Array‹string›): Schema
Defined in lib/Schema.ts:56
Creates a new schema containing a subset of the instance's fields.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
fields |
object | string | null | - |
...keys |
Array‹string› | - | The names of the fields which should be transferred to the new schema. |
Returns: Schema
A new instance of Schema
.
validate
▸ validate(data
: object): Promise‹object›
Defined in lib/Schema.ts:110
(async) Determines if the key-value pairs in data
match, or can be converted to, the format of the instance's fieldset.
Parameters:
Name | Type | Description |
---|---|---|
data |
object | An object to validate. |
Returns: Promise‹object›
A new object containing only the values that have been parsed by corresponding fields in the fieldset, or undefined if a corresponding value for any field was not present.