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

1.0.5 • 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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @sclable/nestjs-async-provider

      Weekly Downloads

      118

      Version

      1.0.5

      License

      MIT

      Unpacked Size

      10.2 kB

      Total Files

      8

      Last publish

      Collaborators

      • hakan0xff
      • akoleszar-sclable
      • norbert.lehotzky