tsmodels
Implementation of the model system for the TypeScript language
Features
- Convert format fields from server to client and back
- Creates instances of models rather than typing (with conversion)
- Perceives both nested (connected) models and collections of any depth
Installation
Install tsmodels
from npm
or yarn
:
# from `npm` npm i tsmodels --save # from `yarn` yarn add tsmodels --save
Usage
It is necessary to inherit the model from the class Model
:
;
For the model instance, methods will be available _fromJSON(value)
and _toJSON()
methods
Model clear static methods
Model.new<modeType>(<model-type>, <data>)
- Creates an instance of pass model class with dataModel.newCollection<modeType>(<model-type>, <data[]>)
- Creates an instances collection of pass model class with data array
@Alias(...)
Decorator of fields for model
- Optional param
field_name
- Name of server format field - Optional param
type
- Optional. Type of related model
_toJSON()
Convert model to object using Alias's metadata
Parameters: {string[]} only - Array of field's aliases to export
Example
Town model
// ...
User model
// ...
// ... ;; ;
_fromJSON()
User will be:
_toJSON()
User will be: