Registry / database / jsorm
library1.3.22jsnpmunverified

Jsorm is an isomorphic JavaScript ORM for JSON:API compliant APIs, version 1.3.22. It provides an Active Record-like pattern for fetching, querying, and persisting data, supporting scopes, pagination, sorting, includes, and error handling. Written in TypeScript and compatible with ES5+ environments including browsers and Node.js. Unlike generic HTTP clients, JSORM offers models with decorators (Attr, HasMany, BelongsTo) and chainable query methods, making API interactions declarative. It is part of the jsonapi-suite ecosystem.

npm install jsorm
INSTALL
IMPORT
SIG · JSORM
J
jsorm
databasejavascriptv1.3.22
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.

JSORMBase
import { JSORMBase } from 'jsorm'
const JSORMBase = require('jsorm').JSORMBase
Default export does not exist; use named import.
Model
import { Model } from 'jsorm'
Decorator for classes. TypeScript must have 'experimentalDecorators' enabled.
Attr
import { Attr } from 'jsorm'
Property decorator for attributes.
HasMany
import { HasMany } from 'jsorm'
Property decorator for has-many relationships.
BelongsTo
import { BelongsTo } from 'jsorm'
import { BelongsTo } from 'jsorm'
Available for belongs-to relationships.

Defines models for Person and Pet, then queries for people filtered, paginated, sorted, and including related pets.

import { JSORMBase, Model, Attr, HasMany } from 'jsorm'; @Model() class ApplicationRecord extends JSORMBase { static baseUrl = 'http://localhost:3000'; static apiNamespace = '/api/v1'; } @Model() class Person extends ApplicationRecord { static jsonapiType = 'people'; @Attr() firstName!: string; @Attr() lastName!: string; @HasMany() pets!: Pet[]; get fullName() { return `${this.firstName} ${this.lastName}`; } } @Model() class Pet extends ApplicationRecord { static jsonapiType = 'pets'; @Attr() name!: string; } async function main() { const { data } = await Person .where({ name: 'Joe' }) .page(2).per(10) .sort('name') .includes('pets') .all(); const names = data.map((p: Person) => p.fullName); console.log(names); console.log(data[0].pets[0].name); } main().catch(console.error);
Debug
Known issues
gotchaDecorators like @Model(), @Attr(), @HasMany() require TypeScript's experimentalDecorators to be enabled. Without them, the decorators are ignored and models won't work.
fix
Set 'experimentalDecorators': true in tsconfig.json
affects: >=0.0.0
gotchaJSORMBase must be extended with @Model() decorator on the subclass; otherwise, static baseUrl and apiNamespace are not recognized.
fix
Add @Model() decorator to the class that extends JSORMBase.
affects: >=0.0.0
breakingIn version 1.x, the 'includes' method replaced 'include' (v0.x). Using 'include' will throw an error.
fix
Use .includes('related') instead of .include('related').
affects: >=1.0.0
gotchaThe package does not export a default; importing without named import results in undefined.
fix
Use named imports: import { JSORMBase } from 'jsorm'.
affects: >=0.0.0
gotchaAttribute decorators (@Attr()) must be called with parentheses even if no arguments.
fix
Use @Attr() not @Attr.
affects: >=0.0.0
deprecatedThe package may not be actively maintained (last release 1.3.22 in 2021). Consider alternatives for long-term projects.
fix
Evaluate using other JSON:API clients like 'jsonapi-client' or 'kitsu'.
affects: >=0.0.0
Errors
Common errors & fixes
Uncaught TypeError: Class constructor ApplicationRecord cannot be invoked without 'new'
Missing @Model() decorator on the class extending JSORMBase.
fix
Add @Model() decorator to ApplicationRecord class.
TypeError: (intermediate value).where is not a function
Using model class directly without extending JSORMBase or forgetting to call static methods on the subclass.
fix
Ensure the model class extends JSORMBase and static baseUrl is set.
ReferenceError: require is not defined
Using CommonJS require in an ESM environment, or trying to use default import.
fix
Use named import: import { JSORMBase } from 'jsorm'.
Experimental support for decorators is a feature that is subject to change in a future release
TypeScript decorators used without enabling experimentalDecorators.
fix
Set 'experimentalDecorators': true in tsconfig.json.
Upgrade
Version history
1.3.22latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
packagejsorm