5.0.3 • Published 3 months ago

@jbiskur/nestjs-options-module-factory v5.0.3

Weekly downloads
20
License
MIT
Repository
github
Last release
3 months ago

nestjs-options-module-factory

The Options Module Factory provides a way to pass an options provider in the current import context by forcing the options provider to be resolved first. This is done through creating a module purely for containing and exporting the options provider.

Installation

Install using npm.

npm install --save @jbiskur/nestjs-options-module-factory @jbiskur/nestjs-async-module

using yarn.

yarn add @jbiskur/nestjs-options-module-factory @jbiskur/nestjs-async-module

Usage

The library provides a utility factory function that creates a module with the options provided. These options are exported and can be used in the import context as seen in the example below. The InnerTestModule injects the options module and uses the const import to inject in the options.

// ...nestjs and async module imports
import { createOptionsModule } from "@jbiskur/nestjs-options-module-factory";

@Module({
  providers: [InnerTestService],
})
class InnerTestModule extends createAsyncModule<Options>() {}

@Module({})
class TestModule extends AsyncModule {
  public static registerAsync(options: AsyncOptions<Options>): DynamicModule {
    const optionsModule = createOptionsModule(OPTIONS_NAME, options);

    return this.doRegisterAsync(TestModule, null, null, {
      imports: [
        optionsModule,
        InnerTestModule.registerAsync(
          {
            imports: [optionsModule],
            inject: [OPTIONS_NAME],
            useFactory: (outerOptions: Options) => ({
              value: outerOptions.value,
            }),
          },
          InnerTestModule
        ),
      ],
      providers: [TestService],
    });
  }
}
5.0.3

3 months ago

5.0.2

6 months ago

5.0.1

11 months ago

5.0.0

11 months ago

4.1.0

1 year ago

3.12.2

1 year ago

3.11.0

1 year ago

3.13.0

1 year ago

3.12.1

1 year ago

3.12.0

1 year ago

4.0.0

1 year ago

4.0.2

1 year ago

3.9.0

2 years ago

3.10.1

2 years ago

3.8.0

2 years ago

3.10.0

2 years ago

3.10.2

2 years ago

3.7.0

2 years ago

3.6.0

2 years ago

3.5.0

2 years ago

3.4.0

2 years ago

3.3.1

2 years ago

3.2.2

2 years ago

3.3.0

2 years ago

3.2.1

2 years ago

3.2.5

2 years ago

3.2.4

2 years ago

3.4.1

2 years ago

3.2.3

2 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.4.1

3 years ago

2.4.2

3 years ago

2.3.0

3 years ago

2.4.0

3 years ago

2.3.1

3 years ago

2.2.1

3 years ago

2.2.2

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.2

3 years ago

2.1.0

3 years ago

1.1.5

3 years ago

2.0.0

3 years ago

1.1.4

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago