Metaschema
Schema definition and validation 🤝
Install / Use
/learn @metarhia/MetaschemaREADME
Metaschema
Metadata schema and interface (contract) definition language
Installation
$ npm i metaschema
Examples
Basic Schema Usage
const { 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 }
Schema Constructor
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'
Model Usage
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 definitions
Loader Functions
const { 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');
Schema Kinds and Metadata
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',
});
License & Contributors
Copyright (c) 2017-2025 Metarhia contributors.
Metaschema is MIT licensed.
Metaschema is a part of Metarhia technology stack.
Related Skills
notion
341.2kNotion API for creating and managing pages, databases, and blocks.
feishu-drive
341.2k|
things-mac
341.2kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
clawhub
341.2kUse the ClawHub CLI to search, install, update, and publish agent skills from clawhub.com
