{"id":20206,"library":"metadomain","title":"Metadomain","description":"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.","status":"active","version":"2.0.0-alpha.2","language":"javascript","source_language":"en","source_url":"https://github.com/metarhia/metadomain","tags":["javascript","metarhia","model","schema","domain","metamodel","metaschma","database"],"install":[{"cmd":"npm install metadomain","lang":"bash","label":"npm"},{"cmd":"yarn add metadomain","lang":"bash","label":"yarn"},{"cmd":"pnpm add metadomain","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides common utilities used by Metadomain.","package":"@metarhia/common","optional":false},{"reason":"Provides type checking and validation utilities.","package":"metatypes","optional":false}],"imports":[{"note":"ESM-only; no CommonJS support.","wrong":"const Domain = require('metadomain')","symbol":"Domain","correct":"import { Domain } from 'metadomain'"},{"note":"Named export, not default.","wrong":"import Schema from 'metadomain'","symbol":"Schema","correct":"import { Schema } from 'metadomain'"},{"note":"ESM-only.","wrong":"const { Field } = require('metadomain')","symbol":"Field","correct":"import { Field } from 'metadomain'"}],"quickstart":{"code":"import { Domain, Schema, Field } from 'metadomain';\n\nconst schema = new Schema('example', {\n  fields: [\n    new Field('id').integer().primary(),\n    new Field('name').string(100).required(),\n    new Field('email').string().email(),\n  ],\n});\n\nconst domain = new Domain();\ndomain.entity('User', schema);\n\nconst user = domain.create('User', { name: 'John', email: 'john@example.com' });\nconsole.log(user.toObject());\n","lang":"typescript","description":"Demonstrates creating a domain, defining a schema with fields, and creating an entity instance."},"warnings":[{"fix":"Refer to migration guide; use new Field and Schema constructors.","message":"Metadomain v2.0.0-alpha.x is not backward compatible with v1.x; schema definition API has changed.","severity":"breaking","affected_versions":">=2.0.0-alpha.0 <2.0.0"},{"fix":"Upgrade Node.js to version 18, 20, 21, or 22.","message":"Removed support for Node.js versions below 18 in v2.0.0-alpha.","severity":"breaking","affected_versions":">=2.0.0-alpha.0"},{"fix":"Pass configuration object: new Domain({ types: ... }).","message":"The `Domain` constructor with string arguments for types is deprecated; use object configuration.","severity":"deprecated","affected_versions":">=1.0.0 <2.0.0"},{"fix":"Define all fields in the schema constructor.","message":"Fields must be added to a Schema using an array in the constructor; mutations after creation are not reflected.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use ES module imports or dynamic import().","message":"The library is ESM-only; using require() will throw an error.","severity":"gotcha","affected_versions":">=2.0.0-alpha.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install: npm install metadomain. If using CJS, use dynamic import: import('metadomain').","cause":"Package not installed or wrong import path in CJS project.","error":"Cannot find module 'metadomain'"},{"fix":"Switch to ES module syntax: import { Domain } from 'metadomain'.","cause":"Using require() on an ESM-only package.","error":"TypeError: Domain is not a constructor"},{"fix":"Use built-in types: integer, string, boolean, etc. Or define custom type via schema options.","cause":"Trying to use an unsupported field type.","error":"Error: Unknown field type 'custom'"},{"fix":"Ensure field value passes built-in email validation; or remove .email() constraint.","cause":"Email validation fails on entity creation.","error":"Schema validation error: Field 'email' must be a valid email"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}