@sclable/nestjs-async-provider
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Nestjs Async Provider

Helper interface and function to create providers asynchronously for dynamic modules.

Install

npm i @sclable/nestjs-async-provider

Usage

import { Module, Provider } from '@nestjs/common'
import { AsyncProvider, createAsyncProviders } from '@sclable/nestjs-async-provider'

@Module({})
export class SomeModule {
  public static forRoot(options: SomeModuleOptions): DynamicModule {
    const optionsProvider: Provider<SomeModuleOptions> = {
      provide: SOME_MODULE_OPTIONS,
      useValue: options,
    }

    return {
      module: SomeModule,
      imports: [...],
      providers: [..., optionsProvider],
      exports: [..., optionsProvider],
    }
  }

  public static forRoorAsync(options: AsyncProvider<SomeModuleOptions>): DynamicModule {
    const asyncProviders = createAsyncProviders(asyncOptions, SOME_MODULE_OPTIONS)

    return {
      module: SomeModule,
      providers: [..., ...asyncProviders],
      exports: [..., ...asyncProviders],
    }
  }
}

API documentation

Github Wiki

Readme

Keywords

none

Package Sidebar

Install

npm i @sclable/nestjs-async-provider

Weekly Downloads

151

Version

1.0.4

License

MIT

Unpacked Size

9.9 kB

Total Files

8

Last publish

Collaborators

  • hakan0xff
  • akoleszar-sclable
  • norbert.lehotzky