astrohelm / metaforge Goto Github PK
View Code? Open in Web Editor NEWLibrary ๐ that allow you to describe data structures by subset of JavaScript syntax and validate them at runtime
Home Page: https://astrohelm.ru
License: MIT License
Library ๐ that allow you to describe data structures by subset of JavaScript syntax and validate them at runtime
Home Page: https://astrohelm.ru
License: MIT License
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>
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
const schema = new Schema(plan);
schema.toDTS('MyType')
// type MyType = ...
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'
}
}
})
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 });
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;
}
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 !' }
const plan = { type: 'number', meta: { key: 'My favorite number' } };
new Schema(plan);
( {
key: 'My favorite number',
kind: 'scalar',
type: 'number',
//...
);
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 });
I think that would be good addition to SQL Generator.
We need to provide user-friendly documentation.
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
const model = new Model(new Schema(plan));
model.migrate() // Will return sql migrations for model and submodels
Give some options
{
throw , // possible 'first' | 'all',
warnings, // 'as-errors' | 'warnings' | 'ignore'
}
We need to create metaforge browser build for frontend Apps.
npm run build
for build generationA declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.