@vetrivelan-cp/mongoose 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,73 +1,123 @@
1
1
  # @vetrivelan-cp/mongoose
2
2
 
3
- A small helper module for integrating **Mongoose** with **NestJS**, providing a convenient decorator to inject Mongoose models.
3
+ CPBS abstraction layer over **Mongoose** and **@nestjs/mongoose**.
4
+
5
+ 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.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  ```bash
8
10
  npm i @vetrivelan-cp/mongoose
9
11
  ```
10
- ```bash
11
- ## try this command
12
- npm i @vetrivelan-cp/mongoose --legacy-peer-deps
13
- ```
14
12
 
15
13
  ### Peer dependencies
16
14
 
17
- This package expects these to be installed in the consuming project:
15
+ This package expects the following peer dependencies to be installed by the consuming application:
18
16
 
19
- - `@nestjs/common` (`^10 || ^11`)
20
- - `@nestjs/core` (`^10 || ^11`)
21
- - `mongoose` (`^8`)
17
+ - `mongoose` (`^6 || ^7 || ^8`)
18
+ - `@nestjs/mongoose` (`^9 || ^10`)
19
+ - `@nestjs/common` (`^9`)
20
+ - `@nestjs/core` (`^9`)
22
21
 
23
22
  ## Usage
24
23
 
25
- ### 1) Import the module
24
+ ### 1) Import decorators and helpers
26
25
 
27
- Import the module in the NestJS module where you want to use model injection.
26
+ ```ts
27
+ import {
28
+ Schema,
29
+ Prop,
30
+ SchemaFactory,
31
+ InjectModel,
32
+ InjectConnection,
33
+ mongoose,
34
+ SchemaTypes,
35
+ Types,
36
+ } from '@vetrivelan-cp/mongoose';
37
+ ```
38
+
39
+ ### 2) Module setup
28
40
 
29
41
  ```ts
30
42
  import { Module } from '@nestjs/common';
31
- import { VetrivelanMongooseModule } from '@vetrivelan-cp/mongoose';
43
+ import { CpbsMongooseModule } from '@vetrivelan-cp/mongoose';
32
44
 
33
45
  @Module({
34
- imports: [VetrivelanMongooseModule],
46
+ imports: [
47
+ CpbsMongooseModule.forRoot('mongodb://localhost:27017/mydb'),
48
+ ],
35
49
  })
36
50
  export class AppModule {}
37
51
  ```
38
52
 
39
- ### 2) Inject a model with the decorator
53
+ ### 3) Define schemas
40
54
 
41
55
  ```ts
42
- import { Injectable } from '@nestjs/common';
43
- import { InjectModel } from '@vetrivelan-cp/mongoose';
44
- import type { Model } from 'mongoose';
56
+ import { Schema, Prop, SchemaFactory } from '@vetrivelan-cp/mongoose';
45
57
 
46
- import { User, UserDocument } from './schemas/user.schema';
58
+ @Schema({ timestamps: true })
59
+ export class User {
60
+ @Prop({ required: true })
61
+ name!: string;
62
+ }
63
+
64
+ export const UserSchema = SchemaFactory.createForClass(User);
65
+ ```
66
+
67
+ ### 4) Inject models / connections
68
+
69
+ ```ts
70
+ import { Injectable } from '@nestjs/common';
71
+ import { InjectModel, Model } from '@vetrivelan-cp/mongoose';
47
72
 
48
73
  @Injectable()
49
74
  export class UsersService {
50
- constructor(
51
- @InjectModel(User.name)
52
- private readonly userModel: Model<UserDocument>,
53
- ) {}
75
+ constructor(@InjectModel('User') private readonly userModel: Model<any>) {}
54
76
  }
55
77
  ```
56
78
 
57
- > Note: The injected token is derived from the model name.
79
+ ### 5) Repository base class
58
80
 
59
- ## API
81
+ > Note: `Model` is re-exported from Mongoose, so you can import it directly from `@vetrivelan-cp/mongoose`.
60
82
 
61
- ### `@InjectModel(modelName: string)`
83
+ ```ts
84
+ import { BaseRepository } from '@vetrivelan-cp/mongoose';
62
85
 
63
- Injects a Mongoose model by name.
86
+ export class UsersRepository extends BaseRepository<any> {
87
+ // add custom methods here
88
+ }
89
+ ```
64
90
 
65
- ## Development
91
+ ## Exports
66
92
 
67
- ```bash
68
- npm run build
69
- ```
93
+ This package re-exports commonly used items from:
94
+
95
+ - `mongoose`
96
+ - `@nestjs/mongoose`
97
+
98
+ including:
99
+
100
+ - Decorators: `Schema`, `Prop`, `SchemaFactory`
101
+ - Injection helpers: `InjectModel`, `InjectConnection`
102
+ - Nest module: `CpbsMongooseModule`
103
+ - Repository: `BaseRepository`
104
+ - Types/utilities: `ObjectId`, `toObjectId`, `CpbsDocument`, `FilterQuery`, etc.
105
+
106
+ See `src/index.ts` for the full export surface.
107
+
108
+ ## Scripts
109
+
110
+ - `npm run build` – build to `dist/`
111
+ - `npm run build:watch` – build in watch mode
112
+ - `npm test` – run unit tests
113
+ - `npm run test:watch` – run tests in watch mode
114
+ - `npm run test:cov` – run tests with coverage
115
+ - `npm run lint` – run eslint autofix
116
+
117
+ ### Publishing
118
+
119
+ - `npm run prepublishOnly` – runs tests, builds, and removes `dist/tsconfig.build.tsbuildinfo` (if present)
70
120
 
71
121
  ## License
72
122
 
73
- ISC
123
+ MIT
@@ -0,0 +1,2 @@
1
+ export { Schema, Prop, SchemaFactory, InjectModel, InjectConnection, MongooseModule, } from '@nestjs/mongoose';
2
+ export type { SchemaOptions, PropOptions, MongooseModuleOptions, MongooseModuleAsyncOptions, MongooseOptionsFactory, } from '@nestjs/mongoose';
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongooseModule = exports.InjectConnection = exports.InjectModel = exports.SchemaFactory = exports.Prop = exports.Schema = void 0;
4
+ var mongoose_1 = require("@nestjs/mongoose");
5
+ Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return mongoose_1.Schema; } });
6
+ Object.defineProperty(exports, "Prop", { enumerable: true, get: function () { return mongoose_1.Prop; } });
7
+ Object.defineProperty(exports, "SchemaFactory", { enumerable: true, get: function () { return mongoose_1.SchemaFactory; } });
8
+ Object.defineProperty(exports, "InjectModel", { enumerable: true, get: function () { return mongoose_1.InjectModel; } });
9
+ Object.defineProperty(exports, "InjectConnection", { enumerable: true, get: function () { return mongoose_1.InjectConnection; } });
10
+ Object.defineProperty(exports, "MongooseModule", { enumerable: true, get: function () { return mongoose_1.MongooseModule; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;AAWA,6CAO0B;AANxB,kGAAA,MAAM,OAAA;AACN,gGAAA,IAAI,OAAA;AACJ,yGAAA,aAAa,OAAA;AACb,uGAAA,WAAW,OAAA;AACX,4GAAA,gBAAgB,OAAA;AAChB,0GAAA,cAAc,OAAA"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- export * from './mongoose.module';
2
- export * from './decorators/inject-model.decorator';
3
- export * from './utils/get-model-token';
1
+ export { Schema, Prop, SchemaFactory, InjectModel, InjectConnection, MongooseModule, } from './decorators';
2
+ export type { SchemaOptions, PropOptions, MongooseModuleOptions, MongooseModuleAsyncOptions, MongooseOptionsFactory, } from './decorators';
3
+ export { CpbsMongooseModule } from './module/cpbs-mongoose.module';
4
+ export { BaseRepository } from './repository/base.repository';
5
+ export { Document, Model, Connection, Schema as MongooseSchema, Types, SchemaTypes, mongoose, FilterQuery, UpdateQuery, QueryOptions, ProjectionType, PipelineStage, UpdateWithAggregationPipeline, SaveOptions, AggregateOptions, ObjectId, toObjectId, CpbsDocument, MixedType, Mixed, } from './types';
package/dist/index.js CHANGED
@@ -1,20 +1,24 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./mongoose.module"), exports);
18
- __exportStar(require("./decorators/inject-model.decorator"), exports);
19
- __exportStar(require("./utils/get-model-token"), exports);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toObjectId = exports.mongoose = exports.SchemaTypes = exports.Types = exports.MongooseSchema = exports.Connection = exports.Model = exports.Document = exports.BaseRepository = exports.CpbsMongooseModule = exports.MongooseModule = exports.InjectConnection = exports.InjectModel = exports.SchemaFactory = exports.Prop = exports.Schema = void 0;
4
+ var decorators_1 = require("./decorators");
5
+ Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return decorators_1.Schema; } });
6
+ Object.defineProperty(exports, "Prop", { enumerable: true, get: function () { return decorators_1.Prop; } });
7
+ Object.defineProperty(exports, "SchemaFactory", { enumerable: true, get: function () { return decorators_1.SchemaFactory; } });
8
+ Object.defineProperty(exports, "InjectModel", { enumerable: true, get: function () { return decorators_1.InjectModel; } });
9
+ Object.defineProperty(exports, "InjectConnection", { enumerable: true, get: function () { return decorators_1.InjectConnection; } });
10
+ Object.defineProperty(exports, "MongooseModule", { enumerable: true, get: function () { return decorators_1.MongooseModule; } });
11
+ var cpbs_mongoose_module_1 = require("./module/cpbs-mongoose.module");
12
+ Object.defineProperty(exports, "CpbsMongooseModule", { enumerable: true, get: function () { return cpbs_mongoose_module_1.CpbsMongooseModule; } });
13
+ var base_repository_1 = require("./repository/base.repository");
14
+ Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return base_repository_1.BaseRepository; } });
15
+ var types_1 = require("./types");
16
+ Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return types_1.Document; } });
17
+ Object.defineProperty(exports, "Model", { enumerable: true, get: function () { return types_1.Model; } });
18
+ Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return types_1.Connection; } });
19
+ Object.defineProperty(exports, "MongooseSchema", { enumerable: true, get: function () { return types_1.Schema; } });
20
+ Object.defineProperty(exports, "Types", { enumerable: true, get: function () { return types_1.Types; } });
21
+ Object.defineProperty(exports, "SchemaTypes", { enumerable: true, get: function () { return types_1.SchemaTypes; } });
22
+ Object.defineProperty(exports, "mongoose", { enumerable: true, get: function () { return types_1.mongoose; } });
23
+ Object.defineProperty(exports, "toObjectId", { enumerable: true, get: function () { return types_1.toObjectId; } });
20
24
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,oDAAkC;AAClC,sEAAoD;AACpD,0DAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AA+BA,2CAOsB;AANpB,oGAAA,MAAM,OAAA;AACN,kGAAA,IAAI,OAAA;AACJ,2GAAA,aAAa,OAAA;AACb,yGAAA,WAAW,OAAA;AACX,8GAAA,gBAAgB,OAAA;AAChB,4GAAA,cAAc,OAAA;AAYhB,sEAAmE;AAA1D,0HAAA,kBAAkB,OAAA;AAG3B,gEAA8D;AAArD,iHAAA,cAAc,OAAA;AAGvB,iCA0BiB;AAxBf,iGAAA,QAAQ,OAAA;AACR,8FAAA,KAAK,OAAA;AACL,mGAAA,UAAU,OAAA;AACV,uGAAA,MAAM,OAAkB;AACxB,8FAAA,KAAK,OAAA;AACL,oGAAA,WAAW,OAAA;AACX,iGAAA,QAAQ,OAAA;AAcR,mGAAA,UAAU,OAAA"}
@@ -0,0 +1,8 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { MongooseModuleAsyncOptions, MongooseModuleOptions } from '@nestjs/mongoose';
3
+ import { ModelDefinition } from '@nestjs/mongoose/dist/interfaces';
4
+ export declare class CpbsMongooseModule {
5
+ static forRoot(uri: string, options?: MongooseModuleOptions): DynamicModule;
6
+ static forRootAsync(options: MongooseModuleAsyncOptions): DynamicModule;
7
+ static forFeature(models: ModelDefinition[], connectionName?: string): DynamicModule;
8
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CpbsMongooseModule = void 0;
4
+ const mongoose_1 = require("@nestjs/mongoose");
5
+ class CpbsMongooseModule {
6
+ static forRoot(uri, options) {
7
+ return mongoose_1.MongooseModule.forRoot(uri, options);
8
+ }
9
+ static forRootAsync(options) {
10
+ return mongoose_1.MongooseModule.forRootAsync(options);
11
+ }
12
+ static forFeature(models, connectionName) {
13
+ return connectionName
14
+ ? mongoose_1.MongooseModule.forFeature(models, connectionName)
15
+ : mongoose_1.MongooseModule.forFeature(models);
16
+ }
17
+ }
18
+ exports.CpbsMongooseModule = CpbsMongooseModule;
19
+ //# sourceMappingURL=cpbs-mongoose.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cpbs-mongoose.module.js","sourceRoot":"","sources":["../../src/module/cpbs-mongoose.module.ts"],"names":[],"mappings":";;;AASA,+CAI0B;AAG1B,MAAa,kBAAkB;IAO7B,MAAM,CAAC,OAAO,CAAC,GAAW,EAAE,OAA+B;QACzD,OAAO,yBAAc,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAoBD,MAAM,CAAC,YAAY,CAAC,OAAmC;QACrD,OAAO,yBAAc,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAgBD,MAAM,CAAC,UAAU,CACf,MAAyB,EACzB,cAAuB;QAEvB,OAAO,cAAc;YACnB,CAAC,CAAC,yBAAc,CAAC,UAAU,CAAC,MAAM,EAAE,cAAc,CAAC;YACnD,CAAC,CAAC,yBAAc,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;CACF;AAvDD,gDAuDC"}
@@ -0,0 +1,62 @@
1
+ import { Document, FilterQuery, Model, PipelineStage, ProjectionType, QueryOptions, UpdateQuery, UpdateWithAggregationPipeline, SaveOptions, Types } from 'mongoose';
2
+ export declare class BaseRepository<T extends Document> {
3
+ protected readonly model: Model<T>;
4
+ constructor(model: Model<T>);
5
+ create(data: Partial<T> | Partial<T>[]): Promise<T | T[]>;
6
+ insertMany(data: Partial<T>[], options?: Record<string, any>): Promise<T[]>;
7
+ build(data: Partial<T>): T;
8
+ saveDoc(doc: T, options?: SaveOptions): Promise<T>;
9
+ find(filter?: FilterQuery<T>, projection?: ProjectionType<T>, options?: QueryOptions<T>): Promise<T[]>;
10
+ findLean(filter?: FilterQuery<T>, projection?: ProjectionType<T>): Promise<Partial<T>[]>;
11
+ findOneLean(filter: FilterQuery<T>, projection?: ProjectionType<T>, options?: QueryOptions<T>): Promise<Partial<T> | null>;
12
+ findByIdLean(id: string | Types.ObjectId, projection?: ProjectionType<T>, options?: QueryOptions<T>): Promise<Partial<T> | null>;
13
+ findByIds(ids: Array<string | Types.ObjectId>, projection?: ProjectionType<T>, options?: QueryOptions<T>): Promise<T[]>;
14
+ findOne(filter: FilterQuery<T>, projection?: ProjectionType<T>, options?: QueryOptions<T>): Promise<T | null>;
15
+ findById(id: string | Types.ObjectId, projection?: ProjectionType<T>, options?: QueryOptions<T>): Promise<T | null>;
16
+ findWithPagination(filter: FilterQuery<T>, pagination: {
17
+ page: number;
18
+ limit: number;
19
+ }, projection?: ProjectionType<T>, sort?: Record<string, 1 | -1>): Promise<T[]>;
20
+ paginateWithTotal(filter: FilterQuery<T>, pagination: {
21
+ page: number;
22
+ limit: number;
23
+ }, projection?: ProjectionType<T>, sort?: Record<string, 1 | -1>): Promise<{
24
+ data: T[];
25
+ total: number;
26
+ page: number;
27
+ limit: number;
28
+ }>;
29
+ count(filter?: FilterQuery<T>): Promise<number>;
30
+ countDocuments(filter?: FilterQuery<T>): Promise<number>;
31
+ estimatedCount(): Promise<number>;
32
+ updateOne(filter: FilterQuery<T>, update: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions<T>): Promise<import("mongodb").UpdateResult>;
33
+ updateMany(filter: FilterQuery<T>, update: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions<T>): Promise<import("mongodb").UpdateResult>;
34
+ replaceOne(filter: FilterQuery<T>, replacement: Partial<T>, options?: QueryOptions<T>): Promise<import("mongodb").UpdateResult>;
35
+ findOneAndReplace(filter: FilterQuery<T>, replacement: Partial<T>, options?: QueryOptions<T>): Promise<T | null>;
36
+ findByIdAndUpdate(id: string | Types.ObjectId, update: UpdateQuery<T>, options?: QueryOptions<T>): Promise<T | null>;
37
+ findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options?: QueryOptions<T>): Promise<T | null>;
38
+ findByIdAndDelete(id: string | Types.ObjectId, options?: QueryOptions<T>): Promise<T | null>;
39
+ findOneAndDelete(filter: FilterQuery<T>, options?: QueryOptions<T>): Promise<T | null>;
40
+ softDelete(filter: FilterQuery<T>): Promise<import("mongodb").UpdateResult>;
41
+ softDeleteById(id: string | Types.ObjectId): Promise<import("mongodb").UpdateResult>;
42
+ deleteOne(filter: FilterQuery<T>): Promise<import("mongodb").DeleteResult>;
43
+ deleteById(id: string | Types.ObjectId): Promise<import("mongodb").DeleteResult>;
44
+ deleteMany(filter: FilterQuery<T>): Promise<import("mongodb").DeleteResult>;
45
+ aggregate<R = any>(pipeline: PipelineStage[]): Promise<R[]>;
46
+ distinct<R = any>(field: string, filter?: FilterQuery<T>): Promise<R[]>;
47
+ findOneAndPopulate(filter: FilterQuery<T>, populatePaths: Array<{
48
+ path: string;
49
+ select?: string | Record<string, 0 | 1>;
50
+ }>, projection?: ProjectionType<T>): Promise<T | null>;
51
+ findAndPopulate(filter: FilterQuery<T>, populatePaths: Array<{
52
+ path: string;
53
+ select?: string | Record<string, 0 | 1>;
54
+ }>, projection?: ProjectionType<T>): Promise<T[]>;
55
+ bulkWrite(operations: any[], options?: Record<string, any>): Promise<any>;
56
+ upsert(filter: FilterQuery<T>, update: UpdateQuery<T>): Promise<T | null>;
57
+ exists(filter: FilterQuery<T>): Promise<boolean>;
58
+ get rawModel(): Model<T>;
59
+ exportWithFind(query: object, projection: object, options: object, populate: any[], jstream: any, res: any): Promise<any>;
60
+ export(query: object, populate: any, sort: any, jstream: any, res: any): Promise<void>;
61
+ exportAggragate(aggragate: any[], jstream: any, res: any): Promise<void>;
62
+ }
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseRepository = void 0;
4
+ const JSONStream_1 = require("JSONStream");
5
+ class BaseRepository {
6
+ constructor(model) {
7
+ this.model = model;
8
+ }
9
+ async create(data) {
10
+ if (Array.isArray(data)) {
11
+ return this.model.create(data);
12
+ }
13
+ return this.model.create(data);
14
+ }
15
+ async insertMany(data, options) {
16
+ return this.model.insertMany(data, options);
17
+ }
18
+ build(data) {
19
+ return new this.model(data);
20
+ }
21
+ async saveDoc(doc, options) {
22
+ return doc.save(options);
23
+ }
24
+ async find(filter = {}, projection, options) {
25
+ return this.model.find(filter, projection, options).exec();
26
+ }
27
+ async findLean(filter = {}, projection) {
28
+ return this.model.find(filter, projection).lean().exec();
29
+ }
30
+ async findOneLean(filter, projection, options) {
31
+ return this.model
32
+ .findOne(filter, projection, options)
33
+ .lean()
34
+ .exec();
35
+ }
36
+ async findByIdLean(id, projection, options) {
37
+ return this.model
38
+ .findById(id, projection, options)
39
+ .lean()
40
+ .exec();
41
+ }
42
+ async findByIds(ids, projection, options) {
43
+ return this.model
44
+ .find({ _id: { $in: ids } }, projection, options)
45
+ .exec();
46
+ }
47
+ async findOne(filter, projection, options) {
48
+ return this.model.findOne(filter, projection, options).exec();
49
+ }
50
+ async findById(id, projection, options) {
51
+ return this.model.findById(id, projection, options).exec();
52
+ }
53
+ async findWithPagination(filter, pagination, projection, sort = { createdAt: -1 }) {
54
+ const { page, limit } = pagination;
55
+ const skip = page > 0 ? (page - 1) * limit : 0;
56
+ return this.model
57
+ .find(filter, projection)
58
+ .sort(sort)
59
+ .skip(skip)
60
+ .limit(limit)
61
+ .exec();
62
+ }
63
+ async paginateWithTotal(filter, pagination, projection, sort = { createdAt: -1 }) {
64
+ const { page, limit } = pagination;
65
+ const skip = page > 0 ? (page - 1) * limit : 0;
66
+ const [data, total] = await Promise.all([
67
+ this.model
68
+ .find(filter, projection)
69
+ .sort(sort)
70
+ .skip(skip)
71
+ .limit(limit)
72
+ .exec(),
73
+ this.model.countDocuments(filter).exec(),
74
+ ]);
75
+ return { data, total, page, limit };
76
+ }
77
+ async count(filter = {}) {
78
+ return this.model.countDocuments(filter).exec();
79
+ }
80
+ async countDocuments(filter = {}) {
81
+ return this.model.countDocuments(filter).exec();
82
+ }
83
+ async estimatedCount() {
84
+ return this.model.estimatedDocumentCount().exec();
85
+ }
86
+ async updateOne(filter, update, options) {
87
+ return this.model.updateOne(filter, update, options).exec();
88
+ }
89
+ async updateMany(filter, update, options) {
90
+ return this.model.updateMany(filter, update, options).exec();
91
+ }
92
+ async replaceOne(filter, replacement, options) {
93
+ return this.model.replaceOne(filter, replacement, options).exec();
94
+ }
95
+ async findOneAndReplace(filter, replacement, options = { new: true }) {
96
+ return this.model
97
+ .findOneAndReplace(filter, replacement, options)
98
+ .exec();
99
+ }
100
+ async findByIdAndUpdate(id, update, options = { new: true }) {
101
+ return this.model.findByIdAndUpdate(id, update, options).exec();
102
+ }
103
+ async findOneAndUpdate(filter, update, options = { new: true }) {
104
+ return this.model.findOneAndUpdate(filter, update, options).exec();
105
+ }
106
+ async findByIdAndDelete(id, options) {
107
+ return this.model.findByIdAndDelete(id, options).exec();
108
+ }
109
+ async findOneAndDelete(filter, options) {
110
+ return this.model.findOneAndDelete(filter, options).exec();
111
+ }
112
+ async softDelete(filter) {
113
+ return this.model.updateOne(filter, { $set: { isDeleted: true } }).exec();
114
+ }
115
+ async softDeleteById(id) {
116
+ return this.softDelete({ _id: id });
117
+ }
118
+ async deleteOne(filter) {
119
+ return this.model.deleteOne(filter).exec();
120
+ }
121
+ async deleteById(id) {
122
+ return this.deleteOne({ _id: id });
123
+ }
124
+ async deleteMany(filter) {
125
+ return this.model.deleteMany(filter).exec();
126
+ }
127
+ async aggregate(pipeline) {
128
+ return this.model.aggregate(pipeline).exec();
129
+ }
130
+ async distinct(field, filter = {}) {
131
+ return this.model.distinct(field, filter).exec();
132
+ }
133
+ async findOneAndPopulate(filter, populatePaths, projection) {
134
+ let query = this.model.findOne(filter, projection);
135
+ for (const p of populatePaths) {
136
+ query = query.populate(p);
137
+ }
138
+ return query.exec();
139
+ }
140
+ async findAndPopulate(filter, populatePaths, projection) {
141
+ let query = this.model.find(filter, projection);
142
+ for (const p of populatePaths) {
143
+ query = query.populate(p);
144
+ }
145
+ return query.exec();
146
+ }
147
+ async bulkWrite(operations, options) {
148
+ return this.model.bulkWrite(operations, options);
149
+ }
150
+ async upsert(filter, update) {
151
+ return this.model
152
+ .findOneAndUpdate(filter, update, { upsert: true, new: true })
153
+ .exec();
154
+ }
155
+ async exists(filter) {
156
+ const result = await this.model.exists(filter);
157
+ return result !== null;
158
+ }
159
+ get rawModel() {
160
+ return this.model;
161
+ }
162
+ async exportWithFind(query, projection = {}, options = {}, populate = [], jstream, res) {
163
+ const result = await this.model
164
+ .find(query, projection, options)
165
+ .populate(populate)
166
+ .cursor()
167
+ .pipe(JSONStream_1.default.stringify())
168
+ .pipe(jstream)
169
+ .pipe(res);
170
+ return result;
171
+ }
172
+ async export(query, populate = [], sort = {}, jstream, res) {
173
+ return await this.model
174
+ .find(query)
175
+ .sort(sort)
176
+ .populate(populate)
177
+ .cursor()
178
+ .pipe(JSONStream_1.default.stringify())
179
+ .pipe(jstream)
180
+ .pipe(res);
181
+ }
182
+ async exportAggragate(aggragate = [], jstream, res) {
183
+ return await this.model
184
+ .aggregate(aggragate)
185
+ .cursor()
186
+ .pipe(JSONStream_1.default.stringify())
187
+ .pipe(jstream)
188
+ .pipe(res);
189
+ }
190
+ }
191
+ exports.BaseRepository = BaseRepository;
192
+ //# sourceMappingURL=base.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.repository.js","sourceRo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O,CAAC;aACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;CACF;AAxiBD,wCAwiBC"}
@@ -0,0 +1,6 @@
1
+ export { Document, Model, Connection, Schema, FilterQuery, UpdateQuery, QueryOptions, ProjectionType, PipelineStage, UpdateWithAggregationPipeline, SaveOptions, AggregateOptions, Types, SchemaTypes, Mixed, default as mongoose, } from 'mongoose';
2
+ import { Document, Types } from 'mongoose';
3
+ export type ObjectId = Types.ObjectId;
4
+ export declare const toObjectId: (id: string) => Types.ObjectId;
5
+ export type CpbsDocument<T> = T & Document;
6
+ export type MixedType = Record<string, any>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toObjectId = exports.mongoose = exports.SchemaTypes = exports.Types = exports.Schema = exports.Connection = exports.Model = exports.Document = void 0;
4
+ var mongoose_1 = require("mongoose");
5
+ Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return mongoose_1.Document; } });
6
+ Object.defineProperty(exports, "Model", { enumerable: true, get: function () { return mongoose_1.Model; } });
7
+ Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return mongoose_1.Connection; } });
8
+ Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return mongoose_1.Schema; } });
9
+ Object.defineProperty(exports, "Types", { enumerable: true, get: function () { return mongoose_1.Types; } });
10
+ Object.defineProperty(exports, "SchemaTypes", { enumerable: true, get: function () { return mongoose_1.SchemaTypes; } });
11
+ Object.defineProperty(exports, "mongoose", { enumerable: true, get: function () { return mongoose_1.default; } });
12
+ const mongoose_2 = require("mongoose");
13
+ const toObjectId = (id) => new mongoose_2.Types.ObjectId(id);
14
+ exports.toObjectId = toObjectId;
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAOA,qCA4BkB;AA1BhB,oGAAA,QAAQ,OAAA;AACR,iGAAA,KAAK,OAAA;AACL,sGAAA,UAAU,OAAA;AACV,kGAAA,MAAM,OAAA;AAaN,iGAAA,KAAK,OAAA;AAGL,uGAAA,WAAW,OAAA;AAMX,oGAAA,OAAO,OAAY;AAKrB,uCAA2C;AAiBpC,MAAM,UAAU,GAAG,CAAC,EAAU,EAAkB,EAAE,CACvD,IAAI,gBAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AADZ,QAAA,UAAU,cACE"}
package/package.json CHANGED
@@ -1,25 +1,63 @@
1
1
  {
2
2
  "name": "@vetrivelan-cp/mongoose",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
+ "description": "CPBS abstraction layer over Mongoose and @nestjs/mongoose. Shields applications from breaking Mongoose API changes.",
4
5
  "main": "dist/index.js",
5
6
  "types": "dist/index.d.ts",
6
7
  "files": [
7
8
  "dist"
8
9
  ],
9
10
  "scripts": {
10
- "build": "rimraf dist && tsc",
11
- "prepublishOnly": "npm run build"
11
+ "build": "tsc -p tsconfig.build.json",
12
+ "build:watch": "tsc -p tsconfig.build.json --watch",
13
+ "lint": "eslint \"{src,test}/**/*.ts\" --fix",
14
+ "test": "jest",
15
+ "test:watch": "jest --watch",
16
+ "test:cov": "jest --coverage",
17
+ "prepublishOnly": "npm run test && npm run build && node -e \"try{require('fs').unlinkSync('dist/tsconfig.build.tsbuildinfo')}catch(e){}\""
18
+ },
19
+ "jest": {
20
+ "moduleFileExtensions": ["js", "json", "ts"],
21
+ "rootDir": ".",
22
+ "testRegex": ".*\\.spec\\.ts$",
23
+ "transform": {
24
+ "^.+\\.(t|j)s$": "ts-jest"
25
+ },
26
+ "collectCoverageFrom": ["src/**/*.ts"],
27
+ "coverageDirectory": "coverage",
28
+ "testEnvironment": "node"
29
+ },
30
+ "keywords": [
31
+ "mongoose",
32
+ "nestjs",
33
+ "mongodb",
34
+ "cpbs",
35
+ "abstraction",
36
+ "repository-pattern"
37
+ ],
38
+ "author": "CPBS Team",
39
+ "license": "MIT",
40
+ "publishConfig": {
41
+ "access": "public"
12
42
  },
13
- "author": "vetrivelan",
14
- "license": "ISC",
15
43
  "peerDependencies": {
16
- "@nestjs/common": "^10.0.0 || ^11.0.0",
17
- "@nestjs/core": "^10.0.0 || ^11.0.0",
18
- "mongoose": "^8.0.0"
44
+ "@nestjs/common": "^9.0.0",
45
+ "@nestjs/core": "^9.0.0",
46
+ "@nestjs/mongoose": "^9.0.0 || ^10.0.0",
47
+ "mongoose": "^6.0.0 || ^7.0.0 || ^8.0.0"
48
+ },
49
+ "dependencies": {
50
+ "JSONStream": "^1.3.5"
19
51
  },
20
52
  "devDependencies": {
21
- "@types/node": "^22.13.0",
22
- "rimraf": "^5.0.10",
23
- "typescript": "^5.9.3"
53
+ "@nestjs/common": "^9.0.0",
54
+ "@nestjs/core": "^9.0.0",
55
+ "@nestjs/mongoose": "^9.2.2",
56
+ "@types/jest": "^29.0.0",
57
+ "@types/node": "^18.0.0",
58
+ "jest": "^29.0.0",
59
+ "mongoose": "^6.0.0",
60
+ "ts-jest": "^29.0.0",
61
+ "typescript": "^4.9.0"
24
62
  }
25
63
  }
@@ -1 +0,0 @@
1
- export declare const InjectModel: (modelName: string) => PropertyDecorator & ParameterDecorator;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InjectModel = void 0;
4
- const common_1 = require("@nestjs/common");
5
- const get_model_token_1 = require("../utils/get-model-token");
6
- const InjectModel = (modelName) => (0, common_1.Inject)((0, get_model_token_1.getModelToken)(modelName));
7
- exports.InjectModel = InjectModel;
8
- //# sourceMappingURL=inject-model.decorator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inject-model.decorator.js","sourceRoot":"","sources":["../../src/decorators/inject-model.decorator.ts"],"names":[],"mappings":";;;AACA,2CAAwC;AACxC,8DAAyD;AAElD,MAAM,WAAW,GAAG,CAAC,SAAiB,EAAE,EAAE,CAC/C,IAAA,eAAM,EAAC,IAAA,+BAAa,EAAC,SAAS,CAAC,CAAC,CAAC;AADtB,QAAA,WAAW,eACW"}
@@ -1,4 +0,0 @@
1
- import { DynamicModule } from '@nestjs/common';
2
- export declare class MongooseModule {
3
- static forFeature(models: any[]): DynamicModule;
4
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var MongooseModule_1;
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.MongooseModule = void 0;
11
- const common_1 = require("@nestjs/common");
12
- const get_model_token_1 = require("./utils/get-model-token");
13
- let MongooseModule = MongooseModule_1 = class MongooseModule {
14
- static forFeature(models) {
15
- const providers = models.map((model) => ({
16
- provide: (0, get_model_token_1.getModelToken)(model.name),
17
- useFactory: (connection) => connection.model(model.name, model.schema),
18
- inject: ['DATABASE_CONNECTION'],
19
- }));
20
- return {
21
- module: MongooseModule_1,
22
- providers,
23
- exports: providers,
24
- };
25
- }
26
- };
27
- exports.MongooseModule = MongooseModule;
28
- exports.MongooseModule = MongooseModule = MongooseModule_1 = __decorate([
29
- (0, common_1.Module)({})
30
- ], MongooseModule);
31
- //# sourceMappingURL=mongoose.module.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mongoose.module.js","sourceRoot":"","sources":["../src/mongoose.module.ts"],"names":[],"mappings":";;;;;;;;;;AACA,2CAAuD;AAEvD,6DAAwD;AAGjD,IAAM,cAAc,sBAApB,MAAM,cAAc;IACzB,MAAM,CAAC,UAAU,CAAC,MAAa;QAC7B,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACvC,OAAO,EAAE,IAAA,+BAAa,EAAC,KAAK,CAAC,IAAI,CAAC;YAClC,UAAU,EAAE,CAAC,UAAsB,EAAE,EAAE,CACrC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC;YAC5C,MAAM,EAAE,CAAC,qBAAqB,CAAC;SAChC,CAAC,CAAC,CAAC;QAEJ,OAAO;YACL,MAAM,EAAE,gBAAc;YACtB,SAAS;YACT,OAAO,EAAE,SAAS;SACnB,CAAC;IACJ,CAAC;CACF,CAAA;AAfY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,cAAc,CAe1B"}
@@ -1 +0,0 @@
1
- export declare const getModelToken: (modelName: string) => string;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getModelToken = void 0;
4
- const getModelToken = (modelName) => {
5
- return `${modelName}Model`;
6
- };
7
- exports.getModelToken = getModelToken;
8
- //# sourceMappingURL=get-model-token.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-model-token.js","sourceRoot":"","sources":["../../src/utils/get-model-token.ts"],"names":[],"mappings":";;;AACO,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAU,EAAE;IACzD,OAAO,GAAG,SAAS,OAAO,CAAC;AAC7B,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB"}