Methods
isValidType(modelType) → {Boolean}
Returns true if the model type object provided appears to be a class or constructor function, otherwise a
false value is returned.
Parameters
-
modelType
Modeling.AnyModelTypeThe model "class" or constructor function to be checked.
Returns
-
Boolean
Source
map(modelType) → {Map.<String, Modeling.PropertyDefinition>}
Returns a map of modeled properties (keys) and their definitions (values). The value is a property definition
that details how the modeled property maps to the underlying storage, including the actual storage target.
The modeled property (key) is not always the same as the "target" property - it is the property that is represented through the model itself, which may have a definition pointing to a "target" property.
Parameters
-
modelType
Modeling.AnyModelTypeThe model "class" or constructor function.
Returns
-
Map.<String, Modeling.PropertyDefinition>
Source
model(modelType, method, …objects)
Use a given model type to to convert the given storage object(s) into a model (instance) of the specified model type. If a property is not mapped in the model, the property (and value) will not be assigned to the model.
This method is called by StashKu after a response is returned by the underlying engine (and a model is being used) but before it is handed back to the caller.
Parameters
-
modelType
TThe model "class" or constructor function.
-
method
StringThe method of the request being processed, typically: "get", "post", "put", "patch", "delete", or "options".
-
objects
any<repeatable>
The raw objects to be transmuted into a model.
Throws
-
500
RESTErrorif the "modelType" argument is missing or not a supported StashKu model type object. -
500
RESTErrorif the "method" argument is missing or not a string.
Source
pk(modelType) → {Array.<String>}
Returns the "primary key" property names as specified on a model configuration type.
Parameters
-
modelType
Modeling.AnyModelTypeThe model "class" or constructor function.
Returns
-
Array.<String>
Source
resource(modelType, methodopt) → {String}
Returns the StashKu resource name for the given model, if specified. Optionally checks for a specific action name configuration and uses it if specified. If the resource is a function, it is called with and the return value is returned as the resource name.
If a resource static property is not available on the model's $stashku property, the model constructor
name is used instead.
Parameters
-
modelType
Modeling.AnyModelTypeThe model "class" or constructor function.
-
method
String<optional>
The name of the method that should override the default value if it is explicitly specified. If it is not found, but an
allor'*'property is found, it is used instead.
Returns
-
String
Source
schema(modelType) → {*}
Takes a model type and generates an object with the same properties used to define the model - all
property definitions and the $stashku configuration. If the $stashku property is not found it is generated
with a resource property and derived value.
Parameters
-
modelType
Modeling.AnyModelTypeThe model "class" or constructor function.
Returns
-
*
Throws
500 RESTError if the "modelType" argument is missing or not a supported StashKu model type object.
Source
unmodel(modelType, method, …models)
Use a specified model type to revert models back to a regular (untyped) object.
Certain StashKu requests will call this automatically before the request is sent to the underlying engine.
A PATCH request will attempt to unmodel it's template.
A PUT & POST request will attempt to unmodel it's objects.
Parameters
-
modelType
TThe model "class" or constructor function.
-
method
StringThe method of the request being processed, typically: "get", "post", "put", "patch", "delete", or "options".
-
models
Constructor.<T><repeatable>
The modeled objects to be transformed back into a storage object.
Throws
-
500
RESTErrorif the "modelType" argument is missing or not a supported StashKu model type object. -
500
RESTErrorif the "method" argument is missing or not a string.
Source
unmodelFilters(modelType, …filters)
Translates one or more Filter instances and the underlying conditions by changing modeled property names
into their target property names.
If a Filter instance condition cannot be translated, it is left as-is.
Parameters
-
modelType
TThe model "class" or constructor function.
-
filters
Filter<repeatable>
The
Sortinstances to be modeled.
Throws
500 RESTError if the "modelType" argument is missing or not a supported StashKu model type object.
Source
unmodelProperties(modelType, …propertyNames) → {Array.<String>}
Translates one or more modelled property names by changing them into their target property names.
If a property name cannot be translated (it is not found on the model), it is left as-is.
Parameters
-
modelType
TThe model "class" or constructor function.
-
propertyNames
String<repeatable>
The property names to be unmodelled.
Returns
-
Array.<String>Returns an array of the unmodelled property names.
Throws
500 RESTError if the "modelType" argument is missing or not a supported StashKu model type object.
Source
unmodelPropertyOmit(modelType, propKey, propertyDef, method, model) → {Boolean}
Determines whether a property should be omitted when unmodeling.
Parameters
-
modelType
TThe model type used for unmodelling.
-
propKey
StringThe model's property key.
-
propertyDef
Modeling.PropertyDefinitionThe model's property definition under the specified key.
-
method
StringThe method being used.
-
model
module:modeling/model-utility~Constructor.<T>The model being evaluated.
Returns
-
Boolean
Source
unmodelSorts(modelType, …sorts)
Translates one or more Sort instance's modeled property names by changing them into their target
property names.
If a Sort property name cannot be translated (it is not found on the model), it is left as-is.
Parameters
-
modelType
TThe model "class" or constructor function.
-
sorts
Sort<repeatable>
The
Sortinstances to be modeled.
Throws
500 RESTError if the "modelType" argument is missing or not a supported StashKu model type object.