Data Modeling Tool
npm install @trop/dflow$id - $ref
schema/name.json - classical name
json
{
"$id": "//org/name",
"type": "type",
"pattern": "^[a-zA-Z0-9 ]+$"
}
`
File schema/uint.json - unsigned integer
`json
{
"$id": "//org/uint",
"type": "integer",
"minimum": 0
}
`
Step 2. Re-use Basic Schemas
File schema/hero.json - a hero
`json
{
"$id": "//org/hero",
"type": "object",
"additionalProperties": false,
"required": ["name", "strength"],
"properties": {
"name": {"$ref": "//org/name"},
"strength": {"$ref": "//org/uint"}
}
}
`
Step 3. Verify Data
File main.js
`js
const path = require('path')
const {DataFlow} = require('@trop/dflow')
let dir = path.join(__dirname, 'schema')
let flow = new DataFlow([dir])
let id = '//org/hero'
let data = {
name: 'hulk',
strength: 69
}
let error = flow.verify('//org/hero', data)
`
* dir, path to directory contains schema files
* id, identity of schema, correspond with $id keyword
* data, data to be verify
* verify(), validate data follow schema identity
* error`, if data is invalid then return an array contains errors