Where all things good come from! This Class uses JSON Schema Draft 4 to build basic models for the rest of the application. Please See json-schema.org and also ajv validator for the basics.
import {SchemaClass} from 'json-schema-class'; export MyClass extends 'SchemaClass'{ constructor(){ super({ "title": "Example Schema", "type": "object", "properties": { "firstName": { "type": "string" }, "lastName": { "type": "string" }, "age": { "description": "Age in years", "type": "integer", "minimum": 0 } }, "required": ["firstName", "lastName"] }); let model = this; model.firstName = "My" model.lastName = "Class" this.validate(model) //Validate model and add missing defaults ) } Copy
import {SchemaClass} from 'json-schema-class'; export MyClass extends 'SchemaClass'{ constructor(){ super({ "title": "Example Schema", "type": "object", "properties": { "firstName": { "type": "string" }, "lastName": { "type": "string" }, "age": { "description": "Age in years", "type": "integer", "minimum": 0 } }, "required": ["firstName", "lastName"] }); let model = this; model.firstName = "My" model.lastName = "Class" this.validate(model) //Validate model and add missing defaults ) }
Accepts a JSON Schema pattern for Model Building
Schema for the new Class
Event Emitter
https://nodejs.org/api/events.html
A Merge utility for JavaScript Objects
https://github.com/yeikos/js.merge
Abstract
The Schema for this Class
http://json-schema.org/
Class Validator - Instance of ajv.compile()
https://www.npmjs.com/package/ajv#compileobject-schema---functionobject-data
Get the Current Schema
Validate data against the current schema
data
Where all things good come from! This Class uses JSON Schema Draft 4 to build basic models for the rest of the application. Please See json-schema.org and also ajv validator for the basics.
Example