@AppKu/StashKu

@AppKu/StashKu

v1.0.46

Class

ModelUtility

A utility class for working with StashKu-compatible model objects.

Constructor

new ModelUtility()

Source

Methods

static

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

Returns

  • Boolean

Source

static

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

Returns

Source

generatorstatic

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 T

    The model "class" or constructor function.

  • method String

    The 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

  1. 500 RESTError if the "modelType" argument is missing or not a supported StashKu model type object.

  2. 500 RESTError if the "method" argument is missing or not a string.

Source

static

pk(modelType) → {Array.<String>}

Returns the "primary key" property names as specified on a model configuration type.

Parameters

Returns

  • Array.<String>

Source

static

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.AnyModelType

    The 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 all or '*' property is found, it is used instead.

Returns

  • String

Source

static

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

Returns

  • *

Throws

500 RESTError if the "modelType" argument is missing or not a supported StashKu model type object.

Source

generatorstatic

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 T

    The model "class" or constructor function.

  • method String

    The 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

  1. 500 RESTError if the "modelType" argument is missing or not a supported StashKu model type object.

  2. 500 RESTError if the "method" argument is missing or not a string.

Source

static

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 T

    The model "class" or constructor function.

  • filters Filter <repeatable>

    The Sort instances to be modeled.

Throws

500 RESTError if the "modelType" argument is missing or not a supported StashKu model type object.

Source

static

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 T

    The 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

static

unmodelPropertyOmit(modelType, propKey, propertyDef, method, model) → {Boolean}

Determines whether a property should be omitted when unmodeling.

Parameters

Returns

  • Boolean

Source

static

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 T

    The model "class" or constructor function.

  • sorts Sort <repeatable>

    The Sort instances to be modeled.

Throws

500 RESTError if the "modelType" argument is missing or not a supported StashKu model type object.

Source