Registry / database / mobx-orm

mobx-orm

JSON →
library0.5.0-alpha.8jsnpmunverified

A MobX-based ORM (Object-Relational Mapping) library for managing API resources and other asynchronous data sources. Current stable version is 0.5.0-alpha.8, with a development cadence that has slowed since 2019. It integrates tightly with MobX, leveraging observable state and computed properties to manage relationships like belongsTo, hasMany, and hasOne. Key differentiators: unlike plain MobX stores, it provides a structured model layer with built-in normalization, foreign key resolution, and query support for API data, reducing boilerplate for complex data-fetching apps. However, it is in early alpha, lacks full CRUD, and may have breaking changes.

npm install mobx-orm
INSTALL
IMPORT
SIG · MOBX-ORM
M
mobx-orm
databasejavascriptv0.5.0-alpha.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Model
import { Model } from 'mobx-orm'
const Model = require('mobx-orm').Model
ESM only; CommonJS require not supported with default export structure.
Repository
import { Repository } from 'mobx-orm'
import Repository from 'mobx-orm'
Repository is a named export, not default.
belongsTo
import { belongsTo } from 'mobx-orm'
A decorator function for belongsTo relations.

Defines Author and Post models with relationships, adds records, and accesses related data via MobX observables.

import { Model, Repository, belongsTo, hasMany } from 'mobx-orm'; import { observable } from 'mobx'; class Author extends Model { static entity = 'authors'; @observable name = ''; @hasMany('Post') posts; } class Post extends Model { static entity = 'posts'; @observable title = ''; @observable text = ''; @belongsTo('Author') author; } // Create repository instances const authorRepo = new Repository(Author); const postRepo = new Repository(Post); // Add records (simulates API response data) authorRepo.add({ id: 1, name: 'Alice' }); postRepo.add({ id: 10, title: 'Hello', text: 'World', author: 1 }); // Access related data via computed properties const post = postRepo.first({ id: 10 }); console.log(post.author?.name); // 'Alice'
Debug
Known issues
breakingMobX-ORM requires MobX v4.10.0+, which introduces breaking changes from MobX v3 (e.g., reaction API changes).
fix
Use MobX v4.10.0+ for compatibility; if on MobX v5+, may need shim or upgrade.
affects: >=0.5.0-alpha.4
deprecatedModel decorators may be deprecated in future versions in favor of standard class syntax.
fix
Consider using non-decorator patterns if stability is required.
affects: >=0.5.0-alpha.0
gotchaRelationships rely on foreign keys stored as property values; incorrect data types can cause silent failures.
fix
Ensure foreign key values match the related model's primary key type (string vs number).
affects: all
gotchaRepository.add() does not deep-merge nested objects; expect flat foreign keys.
fix
Flatten nested API responses manually or use a custom normalization step before adding.
affects: all
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
Model base class import failed or package not properly installed.
fix
Verify mobx-orm is installed with peer dependency mobx: npm install mobx-orm mobx
Module not found: Can't resolve 'mobx'
Missing peer dependency mobx.
fix
Install mobx: npm install mobx
Cannot assign to 'author' because it is a read-only property
Attempting to assign to a @belongsTo property directly (it is computed).
fix
Use repository.update() or set the foreign key value on the model (e.g., post.authorId = 2).
Upgrade
Version history
0.5.0-alpha.8latest on npm
Audit
Dependencies
mobxrequiredCore peer dependency for observables (v4.10.0 or higher).
Agent activity
2 hits · last 30 days
node
2
Resources
mobx-orm — npm install mobx-orm · libregistry