0.8.0 • Published 5 years ago

@trop/dflow v0.8.0

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

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

0.8.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago