@trop/dflow

0.8.0 • Public • Published

dflow

Data Modeling Tool - Design, re-use schemas and verify data

Features

  • Specify schemas by JSON Schema Syntax
  • Re-use schemas by keyword pair $id - $ref
  • Load schemas from directories, recursive.
  • Verify data by schema identity.

Usage

Step 1. Design Basic Schemas

File schema/name.json - classical name

{
    "$id": "//org/name",
    "type": "type",
    "pattern": "^[a-zA-Z0-9 ]+$"
}

File schema/uint.json - unsigned integer

{
    "$id": "//org/uint",
    "type": "integer",
    "minimum": 0
}

Step 2. Re-use Basic Schemas

File schema/hero.json - a hero

{
    "$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

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

References

Readme

Keywords

Package Sidebar

Install

npm i @trop/dflow

Weekly Downloads

1

Version

0.8.0

License

ISC

Unpacked Size

15.5 kB

Total Files

18

Last publish

Collaborators

  • kevin.leptons