Registry / database / front-orm

front-orm

JSON →
library0.3.0-beta.9jsnpmunverified

front-orm (v0.3.0-beta.9) is a client-side ORM for building reactive data layers with RESTful APIs. It provides an EntityManager that manages model definitions, field types (PrimaryKey, StringField, NumberField, CollectionField, EntityField), and auto-fetching of missing properties. Unlike alternatives like remult or redux-orm, front-orm integrates reactivity via an optional setReactivity callback (e.g., using watch-object) and supports lazy loading, CRUD hooks, and a flush-based commit pattern. It is in beta, with monthly releases, and is best suited for small apps and prototypes. Requires a server that can signal data changes (e.g., WebSockets) for full real-time support.

npm install front-orm
INSTALL
IMPORT
SIG · FRONT-ORM
F
front-orm
databasejavascriptv0.3.0-beta.9
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.

EntityManager
import { EntityManager } from 'front-orm'
const EntityManager = require('front-orm')
ESM-only; no CommonJS support declared. Ensure bundler or Node version supports ESM.
PrimaryKey, StringField, NumberField, CollectionField, EntityField
const PrimaryKey = em.defaultClasses.fields.PrimaryKey; const StringField = em.defaultClasses.fields.StringField; const NumberField = em.defaultClasses.fields.NumberField; const CollectionField = em.defaultClasses.fields.CollectionField; const EntityField = em.defaultClasses.fields.EntityField
import { PrimaryKey } from 'front-orm'
These field classes are not exported from the package root; they are accessed via em.defaultClasses.fields after creating an EntityManager instance.
Collection, Entity
const Collection = em.defaultClasses.types.Collection; const Entity = em.defaultClasses.types.Entity
import { Collection } from 'front-orm'
Similar to fields, these types are accessed via em.defaultClasses.types, not directly imported.

Sets up EntityManager, defines Author and Book models with fields, adds CRUD hooks using fetch, and demonstrates finding an author and creating a new one via flush.

import { EntityManager } from 'front-orm'; const setReactivity = (data) => { if (typeof window !== 'undefined' && (window as any).watch) { (window as any).watch(data, (newVal: any, oldVal: any, prop: string) => { console.log(`${prop} changed from ${oldVal} to ${newVal}`); }); } return data; }; const em = new EntityManager(setReactivity); const PrimaryKey = em.defaultClasses.fields.PrimaryKey; const StringField = em.defaultClasses.fields.StringField; const NumberField = em.defaultClasses.fields.NumberField; const CollectionField = em.defaultClasses.fields.CollectionField; const EntityField = em.defaultClasses.fields.EntityField; function Author(em: any) { return { id: new PrimaryKey(em), name: new StringField(em), age: new NumberField(em), books: new CollectionField(em, 'Book') }; } function Book(em: any) { return { id: new PrimaryKey(em), title: new StringField(em), author: new EntityField(em, 'Author') }; } const Collection = em.defaultClasses.types.Collection; const Entity = em.defaultClasses.types.Entity; em.setModel(Author, { find: new Entity(em, async (value: any) => { const response = await fetch('/api/authors/' + value.id); return response.json(); }) }); em.setModel(Book, { findAll: new Collection(em, async (params: any) => { const response = await fetch('/api/books', { method: 'GET' }); return response.json(); }) }); em.setHooks({ get: async (model: any, pk: any) => { const response = await fetch(`/api/${model.name}/${pk}`); return response.json(); }, create: async (modelData: any, value: any) => { const response = await fetch(`/api/${modelData.name}`, { method: 'POST', body: JSON.stringify(value), headers: { 'Content-Type': 'application/json' } }); return response.json(); }, update: async (modelData: any, value: any) => { const response = await fetch(`/api/${modelData.name}/${value.id}`, { method: 'PUT', body: JSON.stringify(value), headers: { 'Content-Type': 'application/json' } }); return response.json(); }, delete: async (modelData: any, pk: any) => { const response = await fetch(`/api/${modelData.name}/${pk}`, { method: 'DELETE' }); return response.json(); } }); (async () => { const author = await em.repositories.Author.find({ id: 1 }); console.log('Author:', author); const newAuthor = em.post({ name: 'New Author', age: 30 }, em.models.Author); await em.flush(); console.log('Created author:', newAuthor); })();
Debug
Known issues
breakingThe package is in beta (0.3.0-beta.9). API may change without warning. Not recommended for production.
fix
Consider using a stable ORM like remult or redux-orm for production.
affects: >=0.0.0
gotchaEntityManager constructor requires a setReactivity function. If not provided, reactive updates may not work. The package does not provide reactivity out of the box.
fix
Pass a reactivity function (e.g., from watch-object or a custom proxy) to enable automatic UI updates.
affects: >=0.0.0
deprecatedModel functions are defined by returning a plain object. As of current version, there is no plan for class-based models. This may change.
fix
Stick to the documented function pattern; watch future releases for breaking changes.
affects: >=0.0.0
gotchaField classes (PrimaryKey, StringField, etc.) and type classes (Collection, Entity) are not exported from the package. They must be accessed via em.defaultClasses.fields and em.defaultClasses.types.
fix
After creating EntityManager, destructure from em.defaultClasses.fields or em.defaultClasses.types.
affects: >=0.0.0
gotchaThe package is ESM-only. Using require() will fail. Ensure your environment supports ES modules (Node >= 12 with type: module, or bundler like Webpack/Vite).
fix
Switch to import syntax or configure bundler to handle ESM.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'front-orm' or its corresponding type declarations.
TypeScript cannot resolve the module; the package may not have type declarations or they are not installed.
fix
Install types: npm install --save-dev @types/front-orm (if available) or declare module 'front-orm' in a .d.ts file.
Uncaught ReferenceError: require is not defined
Using require() in an ESM-only environment.
fix
Use import syntax: import { EntityManager } from 'front-orm';
Property 'defaultClasses' does not exist on type 'EntityManager'
TypeScript strict mode or incorrect type definitions. The package's types may be incomplete or outdated.
fix
Cast to any: (em as any).defaultClasses.fields.PrimaryKey or extend the types.
Cannot read properties of undefined (reading 'fields')
Accessing em.defaultClasses before creating EntityManager instance.
fix
Ensure em is created with new EntityManager() before accessing defaultClasses.
Upgrade
Version history
0.3.0-beta.9latest on npm
Audit
Dependencies
watch-objectoptionalOptional dependency for reactivity; used in setReactivity example
Agent activity
11 hits · last 30 days
node
10
Resources
front-orm — npm install front-orm · libregistry