From 63a1cb55b4f46a16b894b0a6d19880204d1898d9 Mon Sep 17 00:00:00 2001 From: BorntraegerMarc Date: Sun, 26 Jan 2020 19:57:58 +0100 Subject: [PATCH 1/3] chore(): Aligned MongooseModuleOptions with MongooseModuleAsyncOptions Fixes #244 --- lib/interfaces/mongoose-options.interface.ts | 2 +- lib/mongoose-core.module.ts | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/interfaces/mongoose-options.interface.ts b/lib/interfaces/mongoose-options.interface.ts index e07e7d50..5309ef14 100644 --- a/lib/interfaces/mongoose-options.interface.ts +++ b/lib/interfaces/mongoose-options.interface.ts @@ -3,7 +3,7 @@ import { ModuleMetadata } from '@nestjs/common/interfaces'; import { ConnectionOptions } from 'mongoose'; export interface MongooseModuleOptions extends ConnectionOptions { - uri?: string; + uri: string; retryAttempts?: number; retryDelay?: number; connectionName?: string; diff --git a/lib/mongoose-core.module.ts b/lib/mongoose-core.module.ts index 8e4e081c..a5b9f440 100644 --- a/lib/mongoose-core.module.ts +++ b/lib/mongoose-core.module.ts @@ -29,10 +29,7 @@ export class MongooseCoreModule implements OnApplicationShutdown { private readonly moduleRef: ModuleRef, ) {} - static forRoot( - uri: string, - options: MongooseModuleOptions = {}, - ): DynamicModule { + static forRoot(options: MongooseModuleOptions): DynamicModule { const { retryAttempts, retryDelay, @@ -54,7 +51,7 @@ export class MongooseCoreModule implements OnApplicationShutdown { useFactory: async (): Promise => await defer(async () => mongooseConnectionFactory( - mongoose.createConnection(uri, mongooseOptions), + mongoose.createConnection(options.uri, mongooseOptions), mongooseConnectionName, ), ) @@ -95,10 +92,7 @@ export class MongooseCoreModule implements OnApplicationShutdown { return await defer(async () => mongooseConnectionFactory( - mongoose.createConnection( - mongooseModuleOptions.uri as string, - mongooseOptions, - ), + mongoose.createConnection(uri, mongooseOptions), mongooseConnectionName, ), ) From 64f9721a9c372e16ca2e4a0ef6a3e1f8e6868948 Mon Sep 17 00:00:00 2001 From: BorntraegerMarc Date: Sun, 26 Jan 2020 19:57:58 +0100 Subject: [PATCH 2/3] chore(): Aligned MongooseModuleOptions with MongooseModuleAsyncOptions Fixes #244 BREAKING CHANGE: Removed URI param in MongooseCoreModule.forRoot and made it non-optional in option object --- lib/interfaces/mongoose-options.interface.ts | 2 +- lib/mongoose-core.module.ts | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/interfaces/mongoose-options.interface.ts b/lib/interfaces/mongoose-options.interface.ts index e07e7d50..5309ef14 100644 --- a/lib/interfaces/mongoose-options.interface.ts +++ b/lib/interfaces/mongoose-options.interface.ts @@ -3,7 +3,7 @@ import { ModuleMetadata } from '@nestjs/common/interfaces'; import { ConnectionOptions } from 'mongoose'; export interface MongooseModuleOptions extends ConnectionOptions { - uri?: string; + uri: string; retryAttempts?: number; retryDelay?: number; connectionName?: string; diff --git a/lib/mongoose-core.module.ts b/lib/mongoose-core.module.ts index 8e4e081c..a5b9f440 100644 --- a/lib/mongoose-core.module.ts +++ b/lib/mongoose-core.module.ts @@ -29,10 +29,7 @@ export class MongooseCoreModule implements OnApplicationShutdown { private readonly moduleRef: ModuleRef, ) {} - static forRoot( - uri: string, - options: MongooseModuleOptions = {}, - ): DynamicModule { + static forRoot(options: MongooseModuleOptions): DynamicModule { const { retryAttempts, retryDelay, @@ -54,7 +51,7 @@ export class MongooseCoreModule implements OnApplicationShutdown { useFactory: async (): Promise => await defer(async () => mongooseConnectionFactory( - mongoose.createConnection(uri, mongooseOptions), + mongoose.createConnection(options.uri, mongooseOptions), mongooseConnectionName, ), ) @@ -95,10 +92,7 @@ export class MongooseCoreModule implements OnApplicationShutdown { return await defer(async () => mongooseConnectionFactory( - mongoose.createConnection( - mongooseModuleOptions.uri as string, - mongooseOptions, - ), + mongoose.createConnection(uri, mongooseOptions), mongooseConnectionName, ), ) From b6e46d07339a958b5345dc444258f22d52393dc2 Mon Sep 17 00:00:00 2001 From: BorntraegerMarc Date: Sun, 26 Jan 2020 20:08:39 +0100 Subject: [PATCH 3/3] chore(): Fixed CI --- lib/mongoose.module.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/mongoose.module.ts b/lib/mongoose.module.ts index f94daec7..0b64d96a 100644 --- a/lib/mongoose.module.ts +++ b/lib/mongoose.module.ts @@ -12,13 +12,10 @@ import { @Module({}) export class MongooseModule { - static forRoot( - uri: string, - options: MongooseModuleOptions = {}, - ): DynamicModule { + static forRoot(options: MongooseModuleOptions): DynamicModule { return { module: MongooseModule, - imports: [MongooseCoreModule.forRoot(uri, options)], + imports: [MongooseCoreModule.forRoot(options)], }; }