Metadomain
raw JSON → 2.0.0-alpha.2 verified Sat Apr 25 auth: no javascript
Metadomain is a Metarhia core model library for defining database schemas using a meta-model approach. Current stable version is 1.0.10, with 2.0.0-alpha.2 available for testing. It provides a declarative schema definition using domain objects with relationships, validation, and hooks. Key differentiators: schema-driven data modeling integrated with Metarhia's Impress application server and other Metarhia libraries, supporting PostgreSQL and other databases. Released under the MIT license, it is part of the Metarhia ecosystem for building scalable Node.js applications.
Common errors
error Cannot find module 'metadomain' ↓
cause Package not installed or wrong import path in CJS project.
fix
Install: npm install metadomain. If using CJS, use dynamic import: import('metadomain').
error TypeError: Domain is not a constructor ↓
cause Using require() on an ESM-only package.
fix
Switch to ES module syntax: import { Domain } from 'metadomain'.
error Error: Unknown field type 'custom' ↓
cause Trying to use an unsupported field type.
fix
Use built-in types: integer, string, boolean, etc. Or define custom type via schema options.
error Schema validation error: Field 'email' must be a valid email ↓
cause Email validation fails on entity creation.
fix
Ensure field value passes built-in email validation; or remove .email() constraint.
Warnings
breaking Metadomain v2.0.0-alpha.x is not backward compatible with v1.x; schema definition API has changed. ↓
fix Refer to migration guide; use new Field and Schema constructors.
breaking Removed support for Node.js versions below 18 in v2.0.0-alpha. ↓
fix Upgrade Node.js to version 18, 20, 21, or 22.
deprecated The `Domain` constructor with string arguments for types is deprecated; use object configuration. ↓
fix Pass configuration object: new Domain({ types: ... }).
gotcha Fields must be added to a Schema using an array in the constructor; mutations after creation are not reflected. ↓
fix Define all fields in the schema constructor.
gotcha The library is ESM-only; using require() will throw an error. ↓
fix Use ES module imports or dynamic import().
Install
npm install metadomain yarn add metadomain pnpm add metadomain Imports
- Domain wrong
const Domain = require('metadomain')correctimport { Domain } from 'metadomain' - Schema wrong
import Schema from 'metadomain'correctimport { Schema } from 'metadomain' - Field wrong
const { Field } = require('metadomain')correctimport { Field } from 'metadomain'
Quickstart
import { Domain, Schema, Field } from 'metadomain';
const schema = new Schema('example', {
fields: [
new Field('id').integer().primary(),
new Field('name').string(100).required(),
new Field('email').string().email(),
],
});
const domain = new Domain();
domain.entity('User', schema);
const user = domain.create('User', { name: 'John', email: 'john@example.com' });
console.log(user.toObject());