Skip to content

Commit

Permalink
feat(*): deprecate forRoot and forRootAsync
Browse files Browse the repository at this point in the history
Add register and registerAsync in their place

Signed-off-by: Will Soto <[email protected]>
  • Loading branch information
willsoto committed Feb 15, 2020
1 parent 7fdecaf commit 5b2db23
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {

@Module({})
export class ObjectionCoreModule {
public static forRoot(options: ObjectionModuleOptions): DynamicModule {
public static register(options: ObjectionModuleOptions): DynamicModule {
const BaseModel = options.Model || Model;
const connection = Knex(options.config);

Expand Down Expand Up @@ -48,7 +48,7 @@ export class ObjectionCoreModule {
};
}

public static forRootAsync(
public static registerAsync(
options: ObjectionModuleAsyncOptions = {}
): DynamicModule {
const knexConnectionProvider: Provider = {
Expand Down
23 changes: 20 additions & 3 deletions lib/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable new-cap */
import { DynamicModule, Module } from "@nestjs/common";
import { DynamicModule, Logger, Module } from "@nestjs/common";
import { ObjectionCoreModule } from "./core";
import {
ObjectionModuleAsyncOptions,
Expand All @@ -9,19 +9,36 @@ import {
@Module({})
export class ObjectionModule {
public static forRoot(options: ObjectionModuleOptions): DynamicModule {
Logger.warn(
"ObjectionModule#forRoot has been deprecated and will be removed in the next major version. Please use ObjectionModule#register instead."
);
return ObjectionModule.register(options);
}

public static register(options: ObjectionModuleOptions): DynamicModule {
return {
module: ObjectionModule,
imports: [ObjectionCoreModule.forRoot(options)],
imports: [ObjectionCoreModule.register(options)],
exports: [ObjectionCoreModule]
};
}

public static forRootAsync(
options: ObjectionModuleAsyncOptions
): DynamicModule {
Logger.warn(
"ObjectionModule#forRootAsync has been deprecated and will be removed in the next major version. Please use ObjectionModule#registerAsync instead."
);

return ObjectionModule.registerAsync(options);
}

public static registerAsync(
options: ObjectionModuleAsyncOptions
): DynamicModule {
return {
module: ObjectionModule,
imports: [ObjectionCoreModule.forRootAsync(options)],
imports: [ObjectionCoreModule.registerAsync(options)],
exports: [ObjectionCoreModule]
};
}
Expand Down
10 changes: 5 additions & 5 deletions tests/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ describe("ObjectionCoreModule", () => {
}
};

describe("#forRoot", () => {
describe("#register", () => {
beforeEach(async () => {
testingModule = await Test.createTestingModule({
imports: [
ObjectionCoreModule.forRoot({
ObjectionCoreModule.register({
config
})
]
Expand All @@ -46,11 +46,11 @@ describe("ObjectionCoreModule", () => {
});
});

describe("#forRootAsync", () => {
describe("#registerAsync", () => {
beforeEach(async () => {
testingModule = await Test.createTestingModule({
imports: [
ObjectionCoreModule.forRootAsync({
ObjectionCoreModule.registerAsync({
useFactory() {
return {
config
Expand Down Expand Up @@ -183,7 +183,7 @@ describe("ObjectionCoreModule", () => {

await Test.createTestingModule({
imports: [
ObjectionCoreModule.forRootAsync({
ObjectionCoreModule.registerAsync({
useClass: ModuleOptionsFactory
})
]
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ConnectionCheck {

@Module({
imports: [
ObjectionModule.forRoot({
ObjectionModule.register({
config: {
client: "sqlite3",
useNullAsDefault: true,
Expand Down
8 changes: 4 additions & 4 deletions tests/module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ describe("ObjectionModule", () => {
}
};

describe("#forRoot", () => {
describe("#register", () => {
beforeEach(async () => {
testingModule = await Test.createTestingModule({
imports: [
ObjectionModule.forRoot({
ObjectionModule.register({
config
})
]
Expand All @@ -37,11 +37,11 @@ describe("ObjectionModule", () => {
});
});

describe("#forRootAsync", () => {
describe("#registerAsync", () => {
beforeEach(async () => {
testingModule = await Test.createTestingModule({
imports: [
ObjectionModule.forRootAsync({
ObjectionModule.registerAsync({
useFactory() {
return {
config
Expand Down

0 comments on commit 5b2db23

Please sign in to comment.