Members
(static) schema :DocumentSchema
Define the data schema for documents of this type.
Type:
(protected) _id :string|null
The primary identifier for the Document to which this data object applies. This identifier is unique within the parent collection which contains the Document.
Type:
- string | null
Methods
(protected, static) _getFieldDefaultValue(field, data) → {undefined|*}
Get the default value for a schema field, conditional on the provided data
Parameters:
Name | Type | Description |
---|---|---|
field |
DocumentField | The configured data field |
data |
object | The provided data object |
Returns:
The default value for the field
- Type
- undefined | *
(static) defineSchema() → {DocumentSchema}
Define the data schema for documents of this type. The schema is populated the first time it is accessed and cached for future reuse.
Returns:
- Type
- DocumentSchema
(static) fromJSON(json) → {DocumentData}
Create a DocumentData instance using a provided serialized JSON string.
Parameters:
Name | Type | Description |
---|---|---|
json |
string | Serialized document data in string format |
Returns:
A constructed data instance
- Type
- DocumentData
(protected) _getInvalidFieldValueErrorMessage(name, field, value) → {string}
Build and return the error message for an Invalid Field Value
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The named field that is invalid |
field |
DocumentField | The configured DocumentField from the Schema |
value |
The value that is invalid |
Returns:
The error message
- Type
- string
(protected) _getMissingFieldErrorMessage(name, field) → {string}
Build and return the error message for a Missing Field
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The named field that is missing |
field |
DocumentField | The configured DocumentField from the Schema |
Returns:
The error message
- Type
- string
(protected) _initialize()
Initialize the instance by copying data from the source object to instance attributes.
(protected) _initializeSource(data) → {object}
Initialize the source data object in-place
Parameters:
Name | Type | Description |
---|---|---|
data |
object |
Returns:
- Type
- object
(protected) _initializeType(type, value) → {*}
Initialize the value for a given data type
Parameters:
Name | Type | Description |
---|---|---|
type |
* | The type of the data field |
value |
* | The un-initialized value |
Returns:
The initialized value
- Type
- *
(protected) _validateDocument()
Jointly validate the overall document after each field has been individually validated. Throw an Error if any issue is encountered.
(protected) _validateField(name, field, value, childrenopt)
Validate a single field in the data object. Assert that required fields are present and that each value passes it's validator function if one is provided.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | The named field being validated |
|
field |
DocumentField | The configured DocumentField from the Schema |
|
value |
* | The current field value |
|
children |
boolean |
<optional> |
Validate the data of child embedded documents? Default is true. |
reset()
Reset the state of this data instance back to mirror the contained source data, erasing any changes.
toJSON() → {object}
Extract the source data for the DocumentData into a simple object format that can be serialized.
Returns:
The document source data expressed as a plain object
- Type
- object
toObject(sourceopt) → {object}
Copy and transform the DocumentData into a plain object. Draw the values of the extracted object from the data source (by default) otherwise from its transformed values.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
source |
boolean |
<optional> |
true
|
Draw values from the underlying data source rather than transformed values |
Returns:
The extracted primitive object
- Type
- object
update(data, options) → {object}
- See:
-
- utils.mergeObject
Update the data by applying a new data object. Data is compared against and merged with the existing data. Updating data which already exists is strict - it must pass validation or else the update is rejected. An object is returned which documents the set of changes which were applied to the original data.
Parameters:
Name | Type | Description |
---|---|---|
data |
object | New values with which to update the Data object |
options |
object | Options which determine how the new data is merged |
Returns:
The changed keys and values which are different than the previous data
- Type
- object
updateCollection(collection, documentData, optionsopt)
Update an EmbeddedCollection using an array of provided document data
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
collection |
EmbeddedCollection | The EmbeddedCollection to update |
||
documentData |
Array.<DocumentData> | An array of provided Document data |
||
options |
object |
<optional> |
{}
|
Additional options which modify how the collection is updated |
validate(options) → {boolean}
Validate the data contained in the document to check for type and content This function throws an error if data within the document is not valid
Parameters:
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | Optional parameters which customize how validation occurs. Properties
|
Returns:
An indicator for whether or not the document contains valid data
- Type
- boolean