Models

Models

This is, effectively, the Model manager and factory.

Methods

(static) create(Model, data, allowIncompleteopt) → {Model}

Source:

Create a model instance.

Parameters:
Name Type Attributes Default Description
Model class The model class to instantiate.
data object the data with which to bootstrap the new model instantiation.
allowIncomplete boolean <optional>
false True if missing required fields should be allowed, false if not.
Returns:
an instance of the passed Model class.
Type
Model

(async, static) deleteModel(instance)

Source:
Delete a model from the back end.
Parameters:
Name Type Description
instance Model A model instance.

(async, static) loadModel(Model, recordName) → {Model}

Source:
Load a model from file (i.e. create a model, then assign values to it based on stored data. We do it in this order to ensure data validation runs)
Parameters:
Name Type Description
Model class The model class to instantiate.
recordName String The recordName associated with the required instance.
Returns:
a previously stored instance of the passed Model class.
Type
Model

(static) register(…models) → {Array.<schema>}

Source:

register all model classes so that we know whether or not they still match their previously stored schema. If not, this will throw and you should run a schema migration before your model-related code will run without errors.

If a backend store is used, this function will run async, returning a Promise that can be awaited, or handled with .then()

When no backend is used, this function will run synchronously.

Parameters:
Name Type Attributes Description
models Array.<Model> <repeatable>
one or more Model class instances
Returns:
A list of model-associated schemas, mapped per input model
Type
Array.<schema>

(static) resetRegistrations()

Source:
Forget all registered models

(async, static) saveModel(instance)

Source:
Save a model to the back end, but skip any default values because models are bootstrapped with the model's default values before data gets loaded in.
Parameters:
Name Type Description
instance Model A model instance.

(static) setStore(store)

Source:
Used by save/load functions.
Parameters:
Name Type Description
store *
Returns:
the static Models class, for call chaining purposes.

(async, static) useDefaultStore(path)

Source:
Async dynamic import, so that we don't end up bundling `fs` related file storage during a client-bundling operation.
Parameters:
Name Type Description
path *