@vetrivelan-cp/mongoose 1.0.0 → 1.0.2

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 ADDED
@@ -0,0 +1,123 @@
1
+ # @vetrivelan-cp/mongoose
2
+
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.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm i @vetrivelan-cp/mongoose
11
+ ```
12
+
13
+ ### Peer dependencies
14
+
15
+ This package expects the following peer dependencies to be installed by the consuming application:
16
+
17
+ - `mongoose` (`^6 || ^7 || ^8`)
18
+ - `@nestjs/mongoose` (`^9 || ^10`)
19
+ - `@nestjs/common` (`^9`)
20
+ - `@nestjs/core` (`^9`)
21
+
22
+ ## Usage
23
+
24
+ ### 1) Import decorators and helpers
25
+
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
40
+
41
+ ```ts
42
+ import { Module } from '@nestjs/common';
43
+ import { CpbsMongooseModule } from '@vetrivelan-cp/mongoose';
44
+
45
+ @Module({
46
+ imports: [
47
+ CpbsMongooseModule.forRoot('mongodb://localhost:27017/mydb'),
48
+ ],
49
+ })
50
+ export class AppModule {}
51
+ ```
52
+
53
+ ### 3) Define schemas
54
+
55
+ ```ts
56
+ import { Schema, Prop, SchemaFactory } from '@vetrivelan-cp/mongoose';
57
+
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';
72
+
73
+ @Injectable()
74
+ export class UsersService {
75
+ constructor(@InjectModel('User') private readonly userModel: Model<any>) {}
76
+ }
77
+ ```
78
+
79
+ ### 5) Repository base class
80
+
81
+ > Note: `Model` is re-exported from Mongoose, so you can import it directly from `@vetrivelan-cp/mongoose`.
82
+
83
+ ```ts
84
+ import { BaseRepository } from '@vetrivelan-cp/mongoose';
85
+
86
+ export class UsersRepository extends BaseRepository<any> {
87
+ // add custom methods here
88
+ }
89
+ ```
90
+
91
+ ## Exports
92
+
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)
120
+
121
+ ## License
122
+
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,36 @@
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
+ build(data: Partial<T>): T;
7
+ saveDoc(doc: T, options?: SaveOptions): Promise<T>;
8
+ find(filter?: FilterQuery<T>, projection?: ProjectionType<T>, options?: QueryOptions<T>): Promise<T[]>;
9
+ findLean(filter?: FilterQuery<T>, projection?: ProjectionType<T>): Promise<Partial<T>[]>;
10
+ findOne(filter: FilterQuery<T>, projection?: ProjectionType<T>, options?: QueryOptions<T>): Promise<T | null>;
11
+ findById(id: string | Types.ObjectId, projection?: ProjectionType<T>, options?: QueryOptions<T>): Promise<T | null>;
12
+ findWithPagination(filter: FilterQuery<T>, pagination: {
13
+ page: number;
14
+ limit: number;
15
+ }, projection?: ProjectionType<T>, sort?: Record<string, 1 | -1>): Promise<T[]>;
16
+ count(filter?: FilterQuery<T>): Promise<number>;
17
+ updateOne(filter: FilterQuery<T>, update: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions<T>): Promise<import("mongodb").UpdateResult>;
18
+ updateMany(filter: FilterQuery<T>, update: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions<T>): Promise<import("mongodb").UpdateResult>;
19
+ findByIdAndUpdate(id: string | Types.ObjectId, update: UpdateQuery<T>, options?: QueryOptions<T>): Promise<T | null>;
20
+ findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options?: QueryOptions<T>): Promise<T | null>;
21
+ softDelete(filter: FilterQuery<T>): Promise<import("mongodb").UpdateResult>;
22
+ deleteOne(filter: FilterQuery<T>): Promise<import("mongodb").DeleteResult>;
23
+ deleteMany(filter: FilterQuery<T>): Promise<import("mongodb").DeleteResult>;
24
+ aggregate<R = any>(pipeline: PipelineStage[]): Promise<R[]>;
25
+ findOneAndPopulate(filter: FilterQuery<T>, populatePaths: Array<{
26
+ path: string;
27
+ select?: string | Record<string, 0 | 1>;
28
+ }>, projection?: ProjectionType<T>): Promise<T | null>;
29
+ findAndPopulate(filter: FilterQuery<T>, populatePaths: Array<{
30
+ path: string;
31
+ select?: string | Record<string, 0 | 1>;
32
+ }>, projection?: ProjectionType<T>): Promise<T[]>;
33
+ upsert(filter: FilterQuery<T>, update: UpdateQuery<T>): Promise<T | null>;
34
+ exists(filter: FilterQuery<T>): Promise<boolean>;
35
+ get rawModel(): Model<T>;
36
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseRepository = void 0;
4
+ class BaseRepository {
5
+ constructor(model) {
6
+ this.model = model;
7
+ }
8
+ async create(data) {
9
+ if (Array.isArray(data)) {
10
+ return this.model.create(data);
11
+ }
12
+ return this.model.create(data);
13
+ }
14
+ build(data) {
15
+ return new this.model(data);
16
+ }
17
+ async saveDoc(doc, options) {
18
+ return doc.save(options);
19
+ }
20
+ async find(filter = {}, projection, options) {
21
+ return this.model.find(filter, projection, options).exec();
22
+ }
23
+ async findLean(filter = {}, projection) {
24
+ return this.model.find(filter, projection).lean().exec();
25
+ }
26
+ async findOne(filter, projection, options) {
27
+ return this.model.findOne(filter, projection, options).exec();
28
+ }
29
+ async findById(id, projection, options) {
30
+ return this.model.findById(id, projection, options).exec();
31
+ }
32
+ async findWithPagination(filter, pagination, projection, sort = { createdAt: -1 }) {
33
+ const { page, limit } = pagination;
34
+ const skip = page > 0 ? (page - 1) * limit : 0;
35
+ return this.model
36
+ .find(filter, projection)
37
+ .sort(sort)
38
+ .skip(skip)
39
+ .limit(limit)
40
+ .exec();
41
+ }
42
+ async count(filter = {}) {
43
+ return this.model.countDocuments(filter).exec();
44
+ }
45
+ async updateOne(filter, update, options) {
46
+ return this.model.updateOne(filter, update, options).exec();
47
+ }
48
+ async updateMany(filter, update, options) {
49
+ return this.model.updateMany(filter, update, options).exec();
50
+ }
51
+ async findByIdAndUpdate(id, update, options = { new: true }) {
52
+ return this.model.findByIdAndUpdate(id, update, options).exec();
53
+ }
54
+ async findOneAndUpdate(filter, update, options = { new: true }) {
55
+ return this.model.findOneAndUpdate(filter, update, options).exec();
56
+ }
57
+ async softDelete(filter) {
58
+ return this.model.updateOne(filter, { $set: { isDeleted: true } }).exec();
59
+ }
60
+ async deleteOne(filter) {
61
+ return this.model.deleteOne(filter).exec();
62
+ }
63
+ async deleteMany(filter) {
64
+ return this.model.deleteMany(filter).exec();
65
+ }
66
+ async aggregate(pipeline) {
67
+ return this.model.aggregate(pipeline).exec();
68
+ }
69
+ async findOneAndPopulate(filter, populatePaths, projection) {
70
+ let query = this.model.findOne(filter, projection);
71
+ for (const p of populatePaths) {
72
+ query = query.populate(p);
73
+ }
74
+ return query.exec();
75
+ }
76
+ async findAndPopulate(filter, populatePaths, projection) {
77
+ let query = this.model.find(filter, projection);
78
+ for (const p of populatePaths) {
79
+ query = query.populate(p);
80
+ }
81
+ return query.exec();
82
+ }
83
+ async upsert(filter, update) {
84
+ return this.model
85
+ .findOneAndUpdate(filter, update, { upsert: true, new: true })
86
+ .exec();
87
+ }
88
+ async exists(filter) {
89
+ const result = await this.model.exists(filter);
90
+ return result !== null;
91
+ }
92
+ get rawModel() {
93
+ return this.model;
94
+ }
95
+ }
96
+ exports.BaseRepository = BaseRepository;
97
+ //# sourceMappingURL=base.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.repository.js","sourceRoot":"","sources":["../../src/repository/base.repository.ts"],"names":[],"mappings":";;;AA+BA,MAAa,cAAc;IACzB,YAA+B,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;IAAG,CAAC;IAWlD,KAAK,CAAC,MAAM,CAAC,IAA+B;QAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACvB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAmB,CAAC;SAClD;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAiB,CAAC;IACjD,CAAC;IAWD,KAAK,CAAC,IAAgB;QACpB,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;IACnC,CAAC;IAUD,KAAK,CAAC,OAAO,CAAC,GAAM,EAAE,OAAqB;QACzC,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAYD,KAAK,CAAC,IAAI,CACR,SAAyB,EAAE,EAC3B,UAA8B,EAC9B,OAAyB;QAEzB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,EAAkB,CAAC;IAC7E,CAAC;IAMD,KAAK,CAAC,QAAQ,CACZ,SAAyB,EAAE,EAC3B,UAA8B;QAE9B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAsC,CAAC;IAC/F,CAAC;IASD,KAAK,CAAC,OAAO,CACX,MAAsB,EACtB,UAA8B,EAC9B,OAAyB;QAEzB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC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,CAAC,IAAI,aAAa,EAAE;YAC7B,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAQ,CAAC;SAClC;QACD,OAAO,KAAK,CAAC,IAAI,EAAuB,CAAC;IAC3C,CAAC;IAKD,KAAK,CAAC,eAAe,CACnB,MAAsB,EACtB,aAA+E,EAC/E,UAA8B;QAE9B,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAChD,KAAK,MAAM,CAAC,IAAI,aAAa,EAAE;YAC7B,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAQ,CAAC;SAClC;QACD,OAAO,KAAK,CAAC,IAAI,EAAkB,CAAC;IACtC,CAAC;IAUD,KAAK,CAAC,MAAM,CACV,MAAsB,EACtB,MAAsB;QAEtB,OAAO,IAAI,CAAC,KAAK;aACd,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;aAC7D,IAAI,EAAuB,CAAC;IACjC,CAAC;IAUD,KAAK,CAAC,MAAM,CAAC,MAAsB;QACjC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/C,OAAO,MAAM,KAAK,IAAI,CAAC;IACzB,CAAC;IAQD,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AAhVD,wCAgVC"}
@@ -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,60 @@
1
1
  {
2
2
  "name": "@vetrivelan-cp/mongoose",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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"
19
48
  },
20
49
  "devDependencies": {
21
- "@types/node": "^22.13.0",
22
- "rimraf": "^5.0.10",
23
- "typescript": "^5.9.3"
50
+ "@nestjs/common": "^9.0.0",
51
+ "@nestjs/core": "^9.0.0",
52
+ "@nestjs/mongoose": "^9.2.2",
53
+ "@types/jest": "^29.0.0",
54
+ "@types/node": "^18.0.0",
55
+ "jest": "^29.0.0",
56
+ "mongoose": "^6.0.0",
57
+ "ts-jest": "^29.0.0",
58
+ "typescript": "^4.9.0"
24
59
  }
25
60
  }
@@ -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 CpMongooseModule {
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 CpMongooseModule_1;
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.CpMongooseModule = void 0;
11
- const common_1 = require("@nestjs/common");
12
- const get_model_token_1 = require("./utils/get-model-token");
13
- let CpMongooseModule = CpMongooseModule_1 = class CpMongooseModule {
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: CpMongooseModule_1,
22
- providers,
23
- exports: providers,
24
- };
25
- }
26
- };
27
- exports.CpMongooseModule = CpMongooseModule;
28
- exports.CpMongooseModule = CpMongooseModule = CpMongooseModule_1 = __decorate([
29
- (0, common_1.Module)({})
30
- ], CpMongooseModule);
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,gBAAgB,wBAAtB,MAAM,gBAAgB;IAC3B,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,kBAAgB;YACxB,SAAS;YACT,OAAO,EAAE,SAAS;SACnB,CAAC;IACJ,CAAC;CACF,CAAA;AAfY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,gBAAgB,CAe5B"}
@@ -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"}