Gathering detailed insights and metrics for nestjs-papr
Gathering detailed insights and metrics for nestjs-papr
Gathering detailed insights and metrics for nestjs-papr
Gathering detailed insights and metrics for nestjs-papr
npm install nestjs-papr
Typescript
Module System
Min. Node Version
Node Version
NPM Version
63.6
Supply Chain
96
Quality
75.3
Maintenance
100
Vulnerability
99.6
License
TypeScript (97.94%)
JavaScript (2.06%)
Total Downloads
8,202
Last Day
8
Last Week
65
Last Month
663
Last Year
5,631
MIT License
6 Stars
19 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Sep 13, 2024
Minified
Minified + Gzipped
Latest Version
1.2.1
Package Id
nestjs-papr@1.2.1
Unpacked Size
47.42 kB
Size
13.35 kB
File Count
35
NPM Version
10.2.3
Node Version
20.10.0
Published on
Jan 24, 2024
Cumulative downloads
Total Downloads
Last Day
-76.5%
8
Compared to previous day
Last Week
-34.3%
65
Compared to previous week
Last Month
11.6%
663
Compared to previous month
Last Year
119%
5,631
Compared to previous year
4
4
nestjs-papr is a module that integrates the Papr library with the Nest Framework.
It provides a way to define Papr models and use them in your Nest modules through dependency injection. This integration allows you to easily work with Papr models in your Nest application.
Supports:
1# npm 2npm install nestjs-papr 3 4# pnpm 5pnpm add nestjs-papr 6 7# yarn 8yarn install nestjs-papr
1@Module({ 2 imports: [ 3 PaprModule.forRootAsync({ 4 imports: [ConfigModule], 5 useFactory: (configService: ConfigService) => { 6 const { MONGODB_URI, MONGODB_DATABASE_NAME } = 7 configService.getConfig(); 8 return { 9 uri: MONGODB_URI, 10 databaseName: MONGODB_DATABASE_NAME, 11 autoIndex: true, // Create indexes automatically 12 autoSchema: true, // Create schema validation automatically 13 }; 14 }, 15 inject: [ConfigService], 16 }), 17 ] 18})
1// user.model.ts 2 3import { model, schema, types } from 'nestjs-papr'; 4 5export const UserSchema = schema( 6 { 7 _id: types.objectId({ required: true }), 8 firstName: types.string({ required: true }), 9 }, 10 { 11 timestamps: true, 12 }, 13); 14export type UserDoc = (typeof UserSchema)[0]; 15export type UserProps = Omit<UserDoc, '_id' | 'createdAt' | 'updatedAt'>; 16export type UserCollection = 'users' 17export const UserModelDef = model(UserCollection, UserSchema, { 18 indexes: [ 19 // Optional indexes here (IndexDescription[] type in mongodb); 20 ], 21 collectionOptions: { 22 // Optional collectionOptions here (CollectionOptions type in mongodb); 23 } 24}); 25
1@Module({ 2 imports: [ 3 PaprModule.forFeature([ 4 UserModelDef, 5 ]), 6 ] 7})
1// module.service.ts 2 3import { Injectable } from '@nestjs/common'; 4import { InjectModel } from 'nestjs-papr'; 5import { UserModelDef, UserDoc, UserProps } from './models/user.model'; 6 7@Injectable() 8export class ModuleService { 9 constructor( 10 @InjectModel(UserModelDef) 11 private readonly userModel: typeof UserModelDef.model, 12 ) {} 13 14 async createUser(userProps: UserProps): Promise<UserDoc> { 15 return await this.userModel.insertOne({ ...userProps }); 16 } 17} 18
InjectModel = (modelDef: ModelDef, connectionName?: string)
- inject model
InjectPapr = (connectionName: string)
- inject Papr instance
InjectConnection = (name: string)
- inject MongoClient instance
1export interface PaprModuleOptions { 2 3 // MongoDB connection uri 4 uri?: string; 5 6 // Connection name 7 connectionName?: string; 8 9 // MongoDB database name 10 databaseName?: string; 11 12 // Custom MongoClient options 13 mongoClientOptions?: MongoClientOptions; 14 15 // Custom database options 16 databaseOptions?: DbOptions; 17 18 // Custom options for papr instance 19 paprOptions?: ModelOptions; 20 21 // Number of attempts to connect to database 22 retryAttempts?: number; 23 24 // Number of delay between attempts 25 retryDelay?: number; 26 27 // Whether to create indexes automatically (default: false) 28 autoIndex?: boolean; 29 30 // Whether to schema validation automatically (default: false) 31 autoSchema?: boolean; 32 33 connectionFactory?: (connection: any, name: string) => any; 34 connectionErrorFactory?: (error: Error) => Error; 35}
nestjs-papr is MIT licensed.
No vulnerabilities found.
No security vulnerabilities found.