Registry / database / tyranid

tyranid

JSON →
library0.6.264jsnpmunverified

A metadata-driven library for Node.js that facilitates working generically with data, primarily MongoDB, serving as an ODM. Current stable version is 0.6.264, with frequent releases. Key differentiators: schema-first approach, TypeScript-first (ships types), runtime type validation, and tight coupling with MongoDB driver v3.1.10. Provides a declarative schema definition with automatic collection management, query building, and data transformations.

npm install tyranid
INSTALL
IMPORT
SIG · TYRANID
T
tyranid
databasejavascriptv0.6.264
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.

Tyranid
import { Tyranid } from 'tyranid'
const Tyranid = require('tyranid').default
Libraries main export is a named export, not default. CommonJS require must use destructuring.
Collection
import { Collection } from 'tyranid'
import { TyranidCollection } from 'tyranid'
Use Collection, not TyranidCollection. TypeScript types are included.
Schema
import { Schema } from 'tyranid'
import { TyranidSchema } from 'tyranid/graphql'
Schema is exported directly from tyranid, not a subpath.

Creates a Tyranid instance, defines a user schema, and saves a new user document.

import { Tyranid } from 'tyranid'; const tyranid = new Tyranid({ db: { host: process.env.MONGO_HOST ?? 'localhost', port: 27017, name: 'my_db' } }); const userSchema = { name: 'user', fields: { _id: { type: 'objectId' }, name: { type: 'string' }, email: { type: 'string' } } }; const User = tyranid.collection(userSchema); const user = new User({ name: 'Alice', email: 'alice@example.com' }); user.save().then(() => console.log('User saved')); tyranid.connect().then(() => { console.log('Connected to MongoDB'); });
Debug
Known issues
breakingv0.6.0: Replaced 'init()' with 'connect()' method. Old 'init' no longer works.
fix
Replace Tyranid.prototype.init() with Tyranid.prototype.connect()
affects: <0.6.0
gotchaCollection names are inferred from schema name but can be overridden. If schema name does not match collection name, queries may fail silently.
fix
Explicitly set collectionName in schema options if different from schema name.
affects: >=0.0.0
deprecatedv0.6.0: 'Tyranid.prototype.collection()' now returns a Collection instance; previously returned a constructor. You must use 'new' with the returned object.
fix
If upgrading from <0.6.0, wrap collection call with 'new' or adjust code.
affects: <0.6.0
gotchaTypeScript peer dependency is exactly 3.8.3; using other versions may cause type errors.
fix
Install TypeScript 3.8.3 as a devDependency.
affects: >=0.0.0
gotchaMongoDB driver peer dependency is exactly 3.1.10; newer versions may break due to driver API changes.
fix
Ensure mongodb@3.1.10 is installed.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Tyranid is not a constructor
Using default import with CommonJS require incorrectly.
fix
Use 'const { Tyranid } = require('tyranid');'
TypeError: tyranid.init is not a function
Using deprecated init method from pre-v0.6.0.
fix
Replace 'tyranid.init()' with 'tyranid.connect()'
Cannot find module 'fast-csv'
Missing optional peer dependency when using CSV features.
fix
npm install fast-csv@^2.5.0
Upgrade
Version history
0.6.264latest on npm
Audit
Dependencies
fast-csvoptionalRequired for CSV import/export functionality.
mongodbrequiredRequired MongoDB driver for database operations.
typescriptoptionalPeer dependency for TypeScript users; library ships with type definitions.
Agent activity
21 hits · last 30 days
node
18
Meta
2
OpenAI (training)
1
Resources
tyranid — npm install tyranid · libregistry