metadatio

6.0.0 • Public • Published

npm version Build Status Coverage Status Dependency Status devDependency Status npm Inline docs

Smart, modular apps using metadata

Metadatio is a library for building complete metadata specifications for defining the required data model for your apps. Our main goal is to let you extract your data model definition to a separate component, with standalone capabilities of validating itself. Thus, you'd be able to define a consistent data model across all the pieces of your application, with zero-duplicity.

Entities and fields

Metadatio is, at its core, a container for entities and fields. It contains enough options for creating a compliant data model for almost any application purpose, and includes a built-in validation system for determining whether the values set to the elements of certain metadata effectively complies with the specification configured.

Modular design

Metadatio core contains the entity and field definitions, the validators, the core exceptions and some helper functions to access your metadata easily from anywhere. It has also built-in methods for storing the metadata in memory, maintaining it accessible throughout all your application's lifecycle. This metadata specification will suffice for static metadata definitions, and for unifying validation across all the pieces of your app.

We are working on several modules that enhance core features, by providing a more specific system depending on the task for which you will use the metadata specification:

  • metadatio-react-forms: Form generator using React. This module should be able to build fully working form-based apps using the metadata definition you provided.
  • metadatio-api: API definitions for managing elements defined through metadata.
  • metadatio-api-contract-testing: Contract-testing system for validating whether an API's features comply with a contract, specified through metadata.
  • metadatio-api-raml: RAML generator for building API definitions.

Installation

You can install Metadatio easily using npm:

    npm install metadatio --save

Usage

Here you have a small guide on how to use Metadatio. In brief, this are the sections you will find below:

  • Creating your entities: Define the data model of your app, using native Entity and Field specification, and attach proper Validators to your fields.
  • Inheritance: Configure hierarchy among your entities, for enriching up the context of the data model.
  • Contextual relationships: Describe model links by setting field's data type as references to other entities.
  • Initialize Metadatio: Tell Metadatio about your data model, and package your data model project.
  • Use your metadata: Include your data model on the different pieces of your app, and see how to leverage the metadata you defined, and perform data validations against metadata validators.

Creating your entities

    import { Entity, Field, DataTypes, Validator, ValidatorTypes } from 'metadatio';
    class Foo extends Entity {
        constructor() {
            super({
                name: 'foo',
                label: 'Foo'
            });

            super.addField(new Field({
                name: 'name',
                dataType: DataTypes.string,
                validators: {
                    'pattern': new Validator(ValidatorTypes.regex, /^_?(\d|[a-zA-Z]|_|-)$/i),
                    'lengths': new Validator(ValidatorTypes.lengths, { min: 2, max: 64 }
                }
            }));
        }

        static getInstance() {
            Foo.instance = new Foo();
            return Foo.instance;
        }
    }

Inheritance

    class Bar extends Foo {
        constructor() {
            super({
                name: 'bar'
            });

            ...
        }

        ...
    }

Contextual relationships

    class Bar extends Entity {
        constructor() {
            super({
                name: 'bar',
                ...
            });

            super.addField(new Field({
                name: 'foo',
                dataType: Foo.getInstance(),
                multiplicity: 'many'
            }));
        }

        ...
    }

Initialize Metadatio

    // index.js

    module.exports = {
        Foo: Foo.getInstance(),
        Bar: Bar.getInstance()
    };

By calling the getInstance() method the entities initialize themselves within Metadatio, and the context is autommatically built.

Export metadata project

Normally you'd like to use your metadata from several projects. A good practice good be to package your metadata definitions as a separate project, that is thereafter included within the different pieces of your app. This example publishes the metadata project as a separate npm module. For corporate project this is useful if you have access to a private npm repository. Otherwise you shall think about using a different packaging and shipping method.

    # publish your package
    npm publish
    (+ my-project-metadata#1.0.0)
# and include it on your consumer projects
npm install --save my-project-metadata

Use your metadata

    import { Foo } from 'my-project-metadata';

    let testItem = {
        name: 'test-value';
    }
    Foo.validate(testItem); // Returns true

    testItem.name = '123n';
    Foo.validate(testItem); // Returns false

Contribute

Metadatio is an ongoing project, and there are many cool things that could we extend through modules, but not without your help. Help us build a rich metadata-based system, for being able to use it in many more ways!

There are several ongoing projects for building up some extensions of Metadatio core:

  • metadatio-react-forms: Form generator using React. This module should be able to build fully working form-based apps using the metadata definition you provided.
  • metadatio-api: API definitions for managing elements defined through metadata.
  • metadatio-api-contract-testing: Contract-testing system for validating whether an API's features comply with a contract, specified through metadata.
  • metadatio-api-raml: RAML generator for building API definitions.

These projects are under analysis or development, and completely opened for your collaboration. We are also working on some other languages to migrate the core:

  • metadatio-java: Java annotation framework and core definer for using Metadatio on Java projects.
  • metadatio-python: Python annotation framework and core definer for using Metadatio on Python projects.
  • metadatio-php: PHP library to build and manage Metadatio features on PHP projects.
  • metadatio-go: GoLang library to build and manage Metadatio features on Go projects.

For maintaining our technology agnostic principle, we are working on a docker container shipping mode, to allow you to use Metadatio on any project you want, even if there's not an language-specific system for the language you are using.

And of course, you can make any other enhancement to the core or any module, or build your custom modules for extending Metadatio even more. But please, if you do any of that, care to share alike :).

License

Metadatio and all its modules are published under MIT license. You are therefore allowed to use any of Metadatio functionality on any project you wish, for either personal use, and business profit.

Package Sidebar

Install

npm i metadatio

Weekly Downloads

2

Version

6.0.0

License

MIT

Last publish

Collaborators

  • pritok