Registry / database / papr
library17.1.0jsnpmunverified

Papr is a lightweight TypeScript-aware MongoDB ORM that leverages MongoDB's JSON Schema validation for runtime document validation (requires MongoDB 3.6+). Current stable version is 17.1.0, requiring Node.js >=22.12.0 and mongodb driver ^7.0.0. It offers a familiar API similar to raw MongoDB methods but with TypeScript-safe schemas, making it a more type-safe alternative to Mongoose. The library is stable with a moderate release cadence, focusing on performance and minimalism.

npm install papr
INSTALL
IMPORT
SIG · PAPR
P
papr
databasejavascriptv17.1.0
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.

Papr
import Papr, { schema, types } from 'papr';
const Papr = require('papr').default;
Papr exports a default class and named exports. In CommonJS, destructure correctly: const { default: Papr, schema, types } = require('papr');
schema
import { schema } from 'papr';
const schema = require('papr').schema;
schema is a named export, not a default export. Ensure destructuring in CommonJS.
types
import { types } from 'papr';
const types = require('papr/types');
types is a named export from the main entry, not a separate module. Do NOT import from 'papr/types' — that path does not exist.

Defines a Papr model with typed schema using papr's schema and types, then queries documents.

import Papr, { schema, types } from 'papr'; const papr = new Papr(); const User = papr.model('users', schema({ age: types.number(), firstName: types.string({ required: true }), lastName: types.string({ required: true }), })); const johnWick = await User.find({ firstName: 'John', lastName: 'Wick' }); console.log(johnWick);
Debug
Known issues
breakingPapr v17 requires Node.js >=22.12.0 and mongodb driver ^7.0.0. Older Node.js versions will cause runtime errors.
fix
Upgrade Node.js to >=22.12.0 and mongodb to ^7.0.0.
affects: >=17.0.0
gotchaMongoDB JSON Schema validation requires MongoDB 3.6+. Using papr with older MongoDB versions will silently skip validation.
fix
Ensure your MongoDB server is 3.6 or later. If using an older version, consider upgrading or adding application-level validation.
affects: all
gotchaPapr does not create indexes or collections automatically. You must create them beforehand for schema validation to apply.
fix
Use MongoDB's createCollection with validator option, or use papr's syncIndexes if available.
affects: all
deprecatedIn papr v16, the 'types' export was restructured. Some type helpers like types.array were removed.
fix
Use types.array() (re-introduced) or define arrays via schema({ field: types.array(types.string()) })
affects: >=16.0.0 <17.0.0
breakingPapr v15 dropped support for callback-based operations. All database methods now return Promises only.
fix
Replace callbacks with async/await or .then() chains.
affects: >=15.0.0
Errors
Common errors & fixes
Error: Cannot find module 'papr'
Package not installed or incorrect import path.
fix
Run: npm install papr@17.1.0
TypeError: papr.model is not a function
Incorrect import; using CommonJS without destructuring the default export.
fix
Use const { default: Papr, schema, types } = require('papr'); then instantiate: new Papr()
Error: The "types" object is not iterable
Attempting to import types from 'papr/types' subpath instead of the main export.
fix
Change import to: import { types } from 'papr';
MongoError: Document failed validation
Document does not conform to the JSON Schema defined on the collection.
fix
Check that you have created the collection with a validator containing the schema generated by papr. Ensure all required fields are present.
Upgrade
Version history
17.1.0latest on npm
Audit
Dependencies
mongodbrequiredPeer dependency; papr wraps the MongoDB Node.js driver and requires it for database operations.
Agent activity
7 hits · last 30 days
node
6
Resources
packagepapr
papr — npm install papr · libregistry