npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vetrivelan-cp/mongoose

v1.0.5

Published

CPBS abstraction layer over Mongoose and @nestjs/mongoose. Shields applications from breaking Mongoose API changes.

Readme

@vetrivelan-cp/mongoose

CPBS abstraction layer over Mongoose and @nestjs/mongoose.

All applications should import from @vetrivelan-cp/mongoose — never directly from mongoose or @nestjs/mongoose. This shields applications from breaking Mongoose API changes by centralizing upgrades in this package.

Installation

npm i @vetrivelan-cp/mongoose

Peer dependencies

This package expects the following peer dependencies to be installed by the consuming application:

  • mongoose (^6 || ^7 || ^8)
  • @nestjs/mongoose (^9 || ^10)
  • @nestjs/common (^9)
  • @nestjs/core (^9)
  • rxjs (required for handleRetry)

Usage

1) Import decorators and helpers

import {
  Schema,
  Prop,
  SchemaFactory,
  InjectModel,
  InjectConnection,
  mongoose,
  SchemaTypes,
  Types,
} from '@vetrivelan-cp/mongoose';

2) Module setup

import { Module } from '@nestjs/common';
import { MongooseModule } from '@vetrivelan-cp/mongoose';

@Module({
  imports: [MongooseModule.forRoot('mongodb://localhost:27017/mydb')],
})
export class AppModule {}

3) Define schemas

import { Schema, Prop, SchemaFactory } from '@vetrivelan-cp/mongoose';

@Schema({ timestamps: true })
export class User {
  @Prop({ required: true })
  name!: string;
}

export const UserSchema = SchemaFactory.createForClass(User);

4) Inject models / connections

import { Injectable } from '@nestjs/common';
import { InjectModel, Model } from '@vetrivelan-cp/mongoose';

@Injectable()
export class UsersService {
  constructor(@InjectModel('User') private readonly userModel: Model<any>) {}
}

5) Repository base class

Note: Model is re-exported from Mongoose, so you can import it directly from @vetrivelan-cp/mongoose.

import { BaseRepository } from '@vetrivelan-cp/mongoose';

export class UsersRepository extends BaseRepository<any> {
  // add custom methods here
}

Tokens & retry utilities

This package also exports token helpers and a retry operator (useful for connection initialization):

import {
  getModelToken,
  getConnectionToken,
  handleRetry,
  raw,
} from '@vetrivelan-cp/mongoose';
  • getModelToken(model: string, connectionName?: string): string
  • getConnectionToken(name?: string): string
  • handleRetry(retryAttempts?: number, retryDelay?: number, verboseRetryLog?: boolean)
  • raw(definition: Record<string, any>): Record<string, any>

Exports

This package re-exports commonly used items from:

  • mongoose
  • @nestjs/mongoose

including:

  • Decorators: Schema, Prop, SchemaFactory
  • Injection helpers: InjectModel, InjectConnection
  • Nest module: MongooseModule
  • Repository: BaseRepository
  • Tokens/retry: getModelToken, getConnectionToken, handleRetry, raw
  • Types/utilities: ObjectId, toObjectId, CpbsDocument, FilterQuery, etc.

See src/index.ts for the full export surface.

Scripts

  • npm run build – build to dist/
  • npm run build:watch – build in watch mode
  • npm test – run unit tests
  • npm run test:watch – run tests in watch mode
  • npm run test:cov – run tests with coverage
  • npm run lint – run eslint autofix

Publishing

  • npm run prepublishOnly – runs tests, builds, and removes dist/tsconfig.build.tsbuildinfo (if present)

License

MIT