Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aligned MongooseModuleOptions with MongooseModuleAsyncOptions #245

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/interfaces/mongoose-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 3 additions & 9 deletions lib/mongoose-core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -54,7 +51,7 @@ export class MongooseCoreModule implements OnApplicationShutdown {
useFactory: async (): Promise<any> =>
await defer(async () =>
mongooseConnectionFactory(
mongoose.createConnection(uri, mongooseOptions),
mongoose.createConnection(options.uri, mongooseOptions),
mongooseConnectionName,
),
)
Expand Down Expand Up @@ -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,
),
)
Expand Down
7 changes: 2 additions & 5 deletions lib/mongoose.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ import {

@Module({})
export class MongooseModule {
static forRoot(
uri: string,
options: MongooseModuleOptions = {},
): DynamicModule {
static forRoot(options: MongooseModuleOptions): DynamicModule {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change, could we support both cases in this module and add a deprecation warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, technically. Yes.

Although I'm more in favour to add a single breaking change & document it properly. Adaptation for consumers for this breaking change should be simple enough.

But either way: I'm not really willing to invest more time into this PR and make further changes, since it seems like to me that this PR will not get merged (open for more than 1 year)...

return {
module: MongooseModule,
imports: [MongooseCoreModule.forRoot(uri, options)],
imports: [MongooseCoreModule.forRoot(options)],
};
}

Expand Down