Registry / database / animal-orm

animal-orm

JSON →
library0.2.36jsnpmunverified

A simple Object-Relational Mapping (ORM) system for FaunaDB, version 0.2.36. It provides Model, Field, RefField, and ManyToManyField classes to define schemas with Zod validation, and automatically generates FaunaDB collections, indexes, and queries. It is actively maintained with monthly releases, but has limited documentation and a small user base. The library is ESM-only and requires Zod as a peer dependency.

npm install animal-orm
INSTALL
IMPORT
SIG · ANIMAL-ORM
A
animal-orm
databasejavascriptv0.2.36
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 'animal-orm'
const Model = require('animal-orm').Model
This is a named export, not a default export. CommonJS require is not supported in this ESM-only package.
Field
import { Field } from 'animal-orm'
import Field from 'animal-orm'
Field is a named export, not the default. The package does not have a default export.
RefField
import { RefField } from 'animal-orm'
import { RefField } from 'animal-orm/RefField'
All symbols are exported from the main package entry; no subpath exports exist.

Defines three models (User, Pet, Trick) with fields and relationships, then generates FaunaDB collection/index creation queries.

import { Model, Field, RefField, ManyToManyField } from 'animal-orm'; import { z } from 'zod'; const User = new Model('User', { name: new Field(z.string()), email: new Field(z.string().email()), password: new Field(z.string(), { hidden: true }) }); const Pet = new Model('Pet', { name: new Field(z.string()), owner: new RefField(User, { reverse: 'pets' }) }); const Trick = new Model('Trick', { name: new Field(z.string()), trainedPets: new ManyToManyField(Pet, { reverse: 'tricks' }) }); // Generate FaunaDB collections, indexes const constructQuery = User.construct(); // Execute constructQuery with FaunaDB client console.log(constructQuery);
Debug
Known issues
breakingPackage is ESM-only and does not support CommonJS require().
fix
Use import syntax or set type: 'module' in package.json.
affects: >=0.1.0
gotchaThe Model.construct() does not execute queries; it only returns FQL expressions. You must call them with a FaunaDB client.
fix
Use the faunadb client's query() method to run the returned expression.
affects: all
gotchaField validation uses Zod, but errors from invalid data are thrown as FaunaDB query errors, not Zod validation errors.
fix
Validate data before creating documents, or wrap in try-catch to handle FaunaDB errors.
affects: all
deprecatedManyToManyField's reverse option uses the string 'tricks' but the generated index name may conflict if multiple models have the same reverse name.
fix
Ensure reverse names are unique across your models.
affects: <0.3.0
Errors
Common errors & fixes
TypeError: animal_orm_1.Model is not a constructor
Using CommonJS require() instead of ESM import.
fix
Replace const { Model } = require('animal-orm') with import { Model } from 'animal-orm'.
Cannot find module 'animal-orm' or its corresponding type declarations.
TypeScript may not resolve module if tsconfig.json is not set to 'node' module resolution.
fix
Set moduleResolution to 'node' or 'nodenext' in tsconfig.json.
Error: [400] Bad request: Invalid field value for 'name'
Data passed to FaunaDB does not pass Zod validation in the field definition.
fix
Ensure the data matches the Zod schema defined in the Field constructor.
Upgrade
Version history
0.2.36latest on npm
Audit
Dependencies
zodrequiredUsed for field validation in model definitions
faunadbrequiredFaunaDB JavaScript driver for database operations
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
animal-orm — npm install animal-orm · libregistry