Giter Club home page Giter Club logo

metaforge's People

Contributors

sashapop10 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

sashapop10

metaforge's Issues

FS Utilities

Describe the problem

Schema.require('/path/to/plans', options); // Map<Schema>
Schema.require('/path/to/plan.js', options); // Schema
schema.saveDTS('/path/to/plan.d.ts'); // Promise<void>
schema.savePlan('/path/to/plan.js'); // Promise<void>

Modular schema

Describe the problem

Separate schema to different modules: test, types, other

Schema.modules // default modules
const module = (schema, options, plan) => {}; // Extend schema
new Schema(plan, { modules }); // provide custom
new Schema(plan); // Will generate schema with default modules 

Benefits

  • lightweight schemas
  • perfomance
  • custom behavior

Generate Schema / Plan from sample

Describe the problem

Schema.fromSample({
   a: 1,
   b: 'test',
   c: [1, 2, 3]
});
// Output
({
   type: 'object',
   properties: {
       a: number,
       b: 'string',
       c: {
           type: 'array',
           items: ['number'],
           condition: 'anyof'
       }
   }
})

Schema namespaces

Describe the problem

const entities = new Map();
entities.set('User', {
    type: 'object',
    properties: {
        job: 'string',
        name: 'string',
        tasks: { type: 'reference', many: 'Task' }, 
        currentTask: { type: 'reference', one: 'Task' }
    }
});

entities.set('Task', { type: 'object', properties: { ends: 'date',  name: 'string' } });

const date = () => ({
    kind: 'scalar',
    test: sample => new Date(sample) ? true : false, 
    // ... Other custom type logic 
});

const namespace = new Namespace({ date }, entities);
const plan = { type: 'object', properties: { users: { type: 'array', items: ['User'] } }  } // May be just 'User'
new Schema(plan, { namespace }); 

JSDOC for type annotations module

Describe the problem

Paste metadata as JSDOC to type annotations

Input

({
 $id: 'User',
 $meta: { name: 'user', description: 'About user' },
 name: 'string',
 age: '?number'
});

// Output

/**
 * @name user
 * @description About user
 */
interface User {
  name: string;
  age?: number;
}

Module for fields calculations

Describe the problem

Calculated schemas another words - Functional fields

const schema = new Schema({
  name: 'string',
  phrase: (parent, root) => 'Hello ' + parent.name + ' !',
})
const mode = true; // true - copy, false - assign; 
const sample = { name: 'Alexander' };
schema.calc(sample,true); // { result: { name: 'Alexander', phrase: 'Hello Alexander !' } };
sample; // { name: 'Alexander' }
schema.calc(sample); 
// If sample not an object in this mode - throw error
sample; // { name: 'Alexander', phrase: 'Hello Alexander !' }

Meta information & Builded tree export

Describe the problem

const plan  = { type: 'number', meta: { key: 'My favorite number' } }; 
new Schema(plan);
( {
    key: 'My favorite number',
    kind: 'scalar',
    type: 'number',
    //...
);

Custom types

Describe the problem

Allow users to pass their custom types

const types = new Map();

types.add('date', { 
   kind: 'scalar',
   build: sample => ...
   // Default structure
});

const plan = {
    type: 'object',
    properties: {
        job: 'string',
        name: 'string',
        // lastEntry: { type: 'date', format: 'd.m.y' }
        lastEntry: 'date' // Custom type
    }
};
new Schema(plan, { types });

Custom checks

Describe the problem

const rule1 = sample => (sample > 5 && sample < 100);
const rule2 = sample => sample.toString().includes('.');
const schema = { type: 'number', rules: { items: [rule1, rule2], condition: 'allof' } };
schema.test(12.34) // true
schema.test(12) // false 
schema.test(3.4) // false

SQL Model

Describe the problem

const model = new Model(new Schema(plan));
model.migrate() // Will return sql migrations for model and submodels

Customizable errors output

Describe the problem

Give some options

{
    throw , // possible 'first' | 'all',  
    warnings, // 'as-errors' | 'warnings' | 'ignore' 
}

Fronted build

Describe the problem

We need to create metaforge browser build for frontend Apps.

  1. npm run build for build generation
  2. export from package.json for browsers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.