@vetrivelan-cp/mongoose 1.0.3 → 1.0.5

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
@@ -18,6 +18,7 @@ This package expects the following peer dependencies to be installed by the cons
18
18
  - `@nestjs/mongoose` (`^9 || ^10`)
19
19
  - `@nestjs/common` (`^9`)
20
20
  - `@nestjs/core` (`^9`)
21
+ - `rxjs` (required for `handleRetry`)
21
22
 
22
23
  ## Usage
23
24
 
@@ -40,12 +41,10 @@ import {
40
41
 
41
42
  ```ts
42
43
  import { Module } from '@nestjs/common';
43
- import { CpbsMongooseModule } from '@vetrivelan-cp/mongoose';
44
+ import { MongooseModule } from '@vetrivelan-cp/mongoose';
44
45
 
45
46
  @Module({
46
- imports: [
47
- CpbsMongooseModule.forRoot('mongodb://localhost:27017/mydb'),
48
- ],
47
+ imports: [MongooseModule.forRoot('mongodb://localhost:27017/mydb')],
49
48
  })
50
49
  export class AppModule {}
51
50
  ```
@@ -88,6 +87,24 @@ export class UsersRepository extends BaseRepository<any> {
88
87
  }
89
88
  ```
90
89
 
90
+ ## Tokens & retry utilities
91
+
92
+ This package also exports token helpers and a retry operator (useful for connection initialization):
93
+
94
+ ```ts
95
+ import {
96
+ getModelToken,
97
+ getConnectionToken,
98
+ handleRetry,
99
+ raw,
100
+ } from '@vetrivelan-cp/mongoose';
101
+ ```
102
+
103
+ - `getModelToken(model: string, connectionName?: string): string`
104
+ - `getConnectionToken(name?: string): string`
105
+ - `handleRetry(retryAttempts?: number, retryDelay?: number, verboseRetryLog?: boolean)`
106
+ - `raw(definition: Record<string, any>): Record<string, any>`
107
+
91
108
  ## Exports
92
109
 
93
110
  This package re-exports commonly used items from:
@@ -99,8 +116,9 @@ including:
99
116
 
100
117
  - Decorators: `Schema`, `Prop`, `SchemaFactory`
101
118
  - Injection helpers: `InjectModel`, `InjectConnection`
102
- - Nest module: `CpbsMongooseModule`
119
+ - Nest module: `MongooseModule`
103
120
  - Repository: `BaseRepository`
121
+ - Tokens/retry: `getModelToken`, `getConnectionToken`, `handleRetry`, `raw`
104
122
  - Types/utilities: `ObjectId`, `toObjectId`, `CpbsDocument`, `FilterQuery`, etc.
105
123
 
106
124
  See `src/index.ts` for the full export surface.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export { Schema, Prop, SchemaFactory, InjectModel, InjectConnection, MongooseModule, } from './decorators';
1
+ export { Schema, Prop, SchemaFactory, InjectModel, InjectConnection, MongooseModule as NestMongooseModule, } from './decorators';
2
2
  export type { SchemaOptions, PropOptions, MongooseModuleOptions, MongooseModuleAsyncOptions, MongooseOptionsFactory, } from './decorators';
3
- export { CpbsMongooseModule } from './module/cpbs-mongoose.module';
3
+ export { MongooseModule } from './module/cpbs-mongoose.module';
4
4
  export { BaseRepository } from './repository/base.repository';
5
+ export { getModelToken, getConnectionToken, handleRetry, raw } from './utils/tokens';
5
6
  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,17 +1,22 @@
1
1
  "use strict";
2
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;
3
+ exports.toObjectId = exports.mongoose = exports.SchemaTypes = exports.Types = exports.MongooseSchema = exports.Connection = exports.Model = exports.Document = exports.raw = exports.handleRetry = exports.getConnectionToken = exports.getModelToken = exports.BaseRepository = exports.MongooseModule = exports.NestMongooseModule = exports.InjectConnection = exports.InjectModel = exports.SchemaFactory = exports.Prop = exports.Schema = void 0;
4
4
  var decorators_1 = require("./decorators");
5
5
  Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return decorators_1.Schema; } });
6
6
  Object.defineProperty(exports, "Prop", { enumerable: true, get: function () { return decorators_1.Prop; } });
7
7
  Object.defineProperty(exports, "SchemaFactory", { enumerable: true, get: function () { return decorators_1.SchemaFactory; } });
8
8
  Object.defineProperty(exports, "InjectModel", { enumerable: true, get: function () { return decorators_1.InjectModel; } });
9
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; } });
10
+ Object.defineProperty(exports, "NestMongooseModule", { enumerable: true, get: function () { return decorators_1.MongooseModule; } });
11
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; } });
12
+ Object.defineProperty(exports, "MongooseModule", { enumerable: true, get: function () { return cpbs_mongoose_module_1.MongooseModule; } });
13
13
  var base_repository_1 = require("./repository/base.repository");
14
14
  Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return base_repository_1.BaseRepository; } });
15
+ var tokens_1 = require("./utils/tokens");
16
+ Object.defineProperty(exports, "getModelToken", { enumerable: true, get: function () { return tokens_1.getModelToken; } });
17
+ Object.defineProperty(exports, "getConnectionToken", { enumerable: true, get: function () { return tokens_1.getConnectionToken; } });
18
+ Object.defineProperty(exports, "handleRetry", { enumerable: true, get: function () { return tokens_1.handleRetry; } });
19
+ Object.defineProperty(exports, "raw", { enumerable: true, get: function () { return tokens_1.raw; } });
15
20
  var types_1 = require("./types");
16
21
  Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return types_1.Document; } });
17
22
  Object.defineProperty(exports, "Model", { enumerable: true, get: function () { return types_1.Model; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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"}
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,gHAAA,cAAc,OAAsB;AAYtC,sEAA+D;AAAtD,sHAAA,cAAc,OAAA;AAGvB,gEAA8D;AAArD,iHAAA,cAAc,OAAA;AAGvB,yCAAqF;AAA5E,uGAAA,aAAa,OAAA;AAAE,4GAAA,kBAAkB,OAAA;AAAE,qGAAA,WAAW,OAAA;AAAE,6FAAA,GAAG,OAAA;AAG5D,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"}
@@ -1,7 +1,7 @@
1
1
  import { DynamicModule } from '@nestjs/common';
2
2
  import { MongooseModuleAsyncOptions, MongooseModuleOptions } from '@nestjs/mongoose';
3
3
  import { ModelDefinition } from '@nestjs/mongoose/dist/interfaces';
4
- export declare class CpbsMongooseModule {
4
+ export declare class MongooseModule {
5
5
  static forRoot(uri: string, options?: MongooseModuleOptions): DynamicModule;
6
6
  static forRootAsync(options: MongooseModuleAsyncOptions): DynamicModule;
7
7
  static forFeature(models: ModelDefinition[], connectionName?: string): DynamicModule;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CpbsMongooseModule = void 0;
3
+ exports.MongooseModule = void 0;
4
4
  const mongoose_1 = require("@nestjs/mongoose");
5
- class CpbsMongooseModule {
5
+ class MongooseModule {
6
6
  static forRoot(uri, options) {
7
7
  return mongoose_1.MongooseModule.forRoot(uri, options);
8
8
  }
@@ -15,5 +15,5 @@ class CpbsMongooseModule {
15
15
  : mongoose_1.MongooseModule.forFeature(models);
16
16
  }
17
17
  }
18
- exports.CpbsMongooseModule = CpbsMongooseModule;
18
+ exports.MongooseModule = MongooseModule;
19
19
  //# sourceMappingURL=cpbs-mongoose.module.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"cpbs-mongoose.module.js","sourceRoot":"","sources":["../../src/module/cpbs-mongoose.module.ts"],"names":[],"mappings":";;;AASA,+CAI0B;AAG1B,MAAa,cAAc;IAOzB,MAAM,CAAC,OAAO,CAAC,GAAW,EAAE,OAA+B;QACzD,OAAO,yBAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAoBD,MAAM,CAAC,YAAY,CAAC,OAAmC;QACrD,OAAO,yBAAkB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;IAgBD,MAAM,CAAC,UAAU,CACf,MAAyB,EACzB,cAAuB;QAEvB,OAAO,cAAc;YACnB,CAAC,CAAC,yBAAkB,CAAC,UAAU,CAAC,MAAM,EAAE,cAAc,CAAC;YACvD,CAAC,CAAC,yBAAkB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;CACF;AAvDD,wCAuDC"}
@@ -0,0 +1,5 @@
1
+ import { Observable } from 'rxjs';
2
+ export declare function getModelToken(model: string, connectionName?: string): string;
3
+ export declare function getConnectionToken(name?: string): string;
4
+ export declare function handleRetry(retryAttempts?: number, retryDelay?: number, verboseRetryLog?: boolean): <T>(source: Observable<T>) => Observable<T>;
5
+ export declare function raw(definition: Record<string, any>): Record<string, any>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.raw = exports.handleRetry = exports.getConnectionToken = exports.getModelToken = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ function getModelToken(model, connectionName) {
6
+ if (connectionName && connectionName !== 'default') {
7
+ return `${connectionName}Connection/${model}Model`;
8
+ }
9
+ return `${model}Model`;
10
+ }
11
+ exports.getModelToken = getModelToken;
12
+ function getConnectionToken(name) {
13
+ if (name && name !== 'default') {
14
+ return `${name}Connection`;
15
+ }
16
+ return 'DatabaseConnection';
17
+ }
18
+ exports.getConnectionToken = getConnectionToken;
19
+ function handleRetry(retryAttempts = 9, retryDelay = 3000, verboseRetryLog = false) {
20
+ return (source) => new rxjs_1.Observable((subscriber) => {
21
+ let attempts = 0;
22
+ const subscribeForRetry = () => {
23
+ const subscription = source.subscribe({
24
+ next: (value) => subscriber.next(value),
25
+ complete: () => subscriber.complete(),
26
+ error: (err) => {
27
+ attempts += 1;
28
+ if (attempts > retryAttempts) {
29
+ subscriber.error(err);
30
+ return;
31
+ }
32
+ if (verboseRetryLog) {
33
+ console.warn(`Mongoose connection failed. Retrying (${attempts}/${retryAttempts}) in ${retryDelay}ms...`);
34
+ }
35
+ setTimeout(() => subscribeForRetry(), retryDelay);
36
+ },
37
+ });
38
+ return subscription;
39
+ };
40
+ const initialSub = subscribeForRetry();
41
+ return () => initialSub?.unsubscribe();
42
+ });
43
+ }
44
+ exports.handleRetry = handleRetry;
45
+ function raw(definition) {
46
+ return definition;
47
+ }
48
+ exports.raw = raw;
49
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/utils/tokens.ts"],"names":[],"mappings":";;;AAAA,+BAAkC;AAOlC,SAAgB,aAAa,CAAC,KAAa,EAAE,cAAuB;IAClE,IAAI,cAAc,IAAI,cAAc,KAAK,SAAS,EAAE;QAClD,OAAO,GAAG,cAAc,cAAc,KAAK,OAAO,CAAC;KACpD;IACD,OAAO,GAAG,KAAK,OAAO,CAAC;AACzB,CAAC;AALD,sCAKC;AAOD,SAAgB,kBAAkB,CAAC,IAAa;IAC9C,IAAI,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;QAC9B,OAAO,GAAG,IAAI,YAAY,CAAC;KAC5B;IACD,OAAO,oBAAoB,CAAC;AAC9B,CAAC;AALD,gDAKC;AAOD,SAAgB,WAAW,CACzB,aAAa,GAAG,CAAC,EACjB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ongoose and @nestjs/mongoose. Shields applications from breaking Mongoose API changes.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",