Metadata schema and interface (contract) definition language
$ npm i metaschemaconst { Schema } = require('metaschema');
const schema = Schema.from({
name: {
first: 'string',
last: 'string',
third: '?string',
},
age: 'number',
levelOne: {
levelTwo: {
levelThree: { type: 'enum', enum: [1, 2, 3] },
},
},
collection: { array: { array: 'number' } },
});
const data = {
name: {
first: 'a',
last: 'b',
},
age: 5,
levelOne: { levelTwo: { levelThree: 1 } },
collection: [
[1, 2, 3],
[3, 5, 6],
],
};
console.log(schema.check(data));
// Output: ValidationResult { errors: [], valid: true }const { Schema } = require('metaschema');
const schema = new Schema('User', {
name: 'string',
email: 'string',
age: 'number',
active: 'boolean',
});
console.log(schema.name); // 'User'
console.log(schema.kind); // 'struct'
console.log(schema.scope); // 'local'const { Model } = require('metaschema');
const types = {
string: { metadata: { pg: 'varchar' } },
number: { metadata: { pg: 'integer' } },
boolean: { metadata: { pg: 'boolean' } },
};
const entities = new Map();
entities.set('User', {
Entity: { scope: 'application', store: 'persistent' },
name: 'string',
email: { type: 'string', unique: true },
age: 'number',
});
const model = new Model(types, entities);
console.log(model.dts); // Generated TypeScript definitionsconst { createSchema, loadSchema, loadModel } = require('metaschema');
// Create schema from string
const schema1 = createSchema('User', "({ name: 'string', age: 'number' })");
// Load schema from file
const schema2 = await loadSchema('./schemas/user.js');
// Load entire model from directory
const model = await loadModel('./schemas');const { Schema, KIND, SCOPE, STORE } = require('metaschema');
console.log(KIND); // ['struct', 'scalar', 'form', 'projection', ...]
console.log(SCOPE); // ['application', 'global', 'local']
console.log(STORE); // ['persistent', 'memory']
const entitySchema = new Schema('Company', {
Entity: { scope: 'application', store: 'persistent' },
name: 'string',
address: 'string',
});Copyright (c) 2017-2025 Metarhia contributors.
Metaschema is MIT licensed.
Metaschema is a part of Metarhia technology stack.