kristianmandrup / json-schema-model-builder

Infrastructure components to easily process JSON schema and build models from it
9 stars 2 forks source link

JSON Schema model builder

Infrastructure components to traverse, build models and cause side effects based on a JSON Schema.

This can be leveraged to build a Declarative Driven Development framework where you build most of your app from a single source of truth (enriched JSON schemas) and keep it in sync on every update.

Status

See Building Blocks for more details

Please check the tests and markdown *.md documentation files for in-depth API documentation (Note: needs update).

Quick start

Use

You can use it something like this...

import { schema } from "./schemas/person.json";
import { config } from "./config";
import {
  createBuilder,
  createState,
  createDispatcher
} from "json-schema-model-builder";

const state = createState({ config });
const dispatcher = createDispatcher({ state, config });
const builder = createBuilder({ state, schema, dispatcher, config });
const built = builder.build();
const rendered = built.render();

// Render the darn thing!
console.log({ rendered });

Note: The Builder and Renderer still need some work, but you can leverage and extend their current implementation already.

Design & Architecture

This project is a result of multiple efforts trying to generate source code or derive models from JSON schemas. There is a need for a framework with a set of well tested, battle-tested building blocks to make this much easier. The goal is to achieve true declarative model driven development.

Your domain and action models across your stack should automatically be derived from the same underlying declarative model (project blueprint).

In the near future we will likely add interactive graph driven development to the mix, using an approach like d3-force-graph-editor

You could in the end simply draw your full application as a directed graph and then assign sufficient meta data to nodes and edges. Then as you draw, have an asortment of pluggable generators generate most (if not all!) of the app for you!

As you reconfigure your graph your app would be auto-coded/generated to reflect the graph in real time!!

Ideally you would then sync the state of the graph with other developers in real time, either using something like AppSync or GraphQL backend or perhaps something like automerge-graph or Immer

Addional projects/resources

Main concepts

Infrastructure delivered by library

Your concerns for output target

The following examples act to demonstrate how you might go about using this infrastructure to generate source code or models.

Usage

The types collected, such as type, enum etc are collected in the store entry of the config object passed in.

const config = {};
const result = createSchema({ schema, config });
const { store } = config;
console.log(store);

Examples

Note: As soon as we have a solid foundation and working examples we will move these into their own projects and publish them on npm

Testing

Uses jest for unit testing.

Please help add more/better test coverage :)

Run tests in watch mode

$ npm run test:watch

Run all tests

$ npm run test

TODO

Author

2018 Kristian Mandrup (CTO@Tecla5)

License

MIT