MetaForge v0.8.0 🕵️
Describe your data structures by subset of JavaScript and:
- 📝 Generate data relational structures (types, jsdoc, diagrams, migrations, etc.)
- 🔎 Validate it in runtime with strict & partial validations
- 👀 Send it to other server to validate data consistency
- 🛠️ Handle it with custom modules
- 💉 Calculate fields
Installation
npm i metaforge --save
Usage example
const userSchema = new Schema({
$id: 'userSchema',
$meta: { '@name': 'User', '@description': 'Schema for user testing' },
phone: { $type: 'union', types: ['number', 'string'] },
name: { $type: 'set', items: ['string', '?string'] },
phrase: (sample, parent, root) => 'Hello ' + [...parent.name].join(' ') + ' !',
mask: { $type: 'array', items: 'string' },
ip: {
$meta: { '@description': 'User ip adress' },
$type: 'array',
$required: false,
$rules: [ip => ip[0] === '192'],
items: { $type: 'union', types: ['string', '?number'], condition: 'oneof', $required: false },
},
type: ['elite', 'member', 'guest'],
'/[a-Z]+Id/': { $type: '?number', isPattern: true },
address: 'string',
secondAddress: '?string',
options: { notifications: 'boolean', lvls: ['number', 'string'] },
});
const systemSchema = new Schema({ $type: 'array', items: userSchema });
const sample = [
{
myId: 1,
phone: '7(***)...',
ip: ['192', 168, '1', null],
type: 'elite',
mask: ['255', '255', '255', '0'],
name: new Set(['Alexander', null]),
options: { notifications: true, lvls: [2, '["admin", "user"]'] },
address: 'Pushkin street',
},
];
systemSchema.warnings;
systemSchema.calculate(sample);
systemSchema.test(sample);
systemSchema.dts('SystemInterface');
systemSchema.pull('userSchema').test(sample[0]);
systemSchema.pull('userSchema').test({ phone: 123 }, 'root', true);
systemSchema.pull('userSchema');
Docs
Copyright & contributors
Copyright © 2023 Astrohelm contributors.
This library is MIT licensed.
And it is part of Astrohelm ecosystem.