model-base
Classes to extend and help create useful data models with strict validation
Installation
yarn add model-base
Usage
# /api/models/analyticsjs 'use strict'; const Model = Model;const ModelCollection = ModelCollection; const AnalyticsAttributes = id: type: 'integer' required: true description: 'analytics datum id' metric: type: 'string' required: true description:'type of analytics datum' value: type:'float' required: true description:'value of metric' ; { superAnalyticsAttributes values; } { superAnalyticsModel values coerce; } moduleexportsAnalyticsModel = AnalyticsModel;moduleexportsAnalyticsAttributes = AnalyticsAttributes;moduleexportsAnalyticsCollection = AnalyticsModelCollection;
# /api/controllers/analyticsjs 'use strict'; let ModelFile = ;let ModelCollection = ModelFileAnalyticsCollection; let collection = resultrows true;return collection;
List Of Validation Types
'array''buffer''string''boolean''ip''url''slug''uuid''fqdn''json''email''alpha''base64''hex''alpha_numeric''phone''function''date''time''datetime''daterange''timestamp''integer''float''number''object'
List Of Attribute Options
-
type (required) - type of validation function to run on value
-
required (default: false) - states whether the value is required or not
-
default_value - any value or function that returns a value that will be set if no value is present
-
custom - array of custom validation functions that allow you to do further validations on a value
- return a string value with the error if there is an error or nothing if no error
-
transform - function to transform input into any output
- must return a value or the value will be set to undefined
-
choices - array of possible values for model attribute
- if the value is not one of the choices an error will be thrown
-
alias - key for other model attribute that keeps the values the same
- it passes the value from the other attribute into this one
Contributing
Installation
git clone <repository-url>
cd model-base
yarn install
Linting
yarn lint
Running tests
yarn test
– Runs the test suite on the current Node Version
License
This project is licensed under the MIT License.