2.1.0 • Published 6 months ago

@homeofthings/nestjs-utils v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

npm version Build Workflow Coverage Status DeepScan grade Known Vulnerabilities

PRs Welcome License

HomeOfThings - common utilities for NestJs

HomeOfThings

installation

npm install @homeofthings/nestjs-utils

Dynamic Modules

quick start

export const MY_MODULE_OPTIONS_TOKEN = 'MY_MODULE_OPTIONS_TOKEN';
export interface MyModuleOptions {
  ....
}

@Module({
  providers: [MyService],
  exports: [MyService],
})
export class MyModule extends createDynamicRootModule<MyModule, MyModuleOptions>(MY_MODULE_OPTIONS_TOKEN) {
}

NOTE: additional module properties for 'imports', 'exports', 'providers' or 'controllers' can be passed as second parameter to this function

NOTE: of course the module can also be global scoped by the @Global() decorator

  • use it synchronously:
const myModuleOptions: MyModuleOptions = {
  ...
}

@Module({
  imports: [MyModule.forRoot(MyModule, myModuleOptions)],
})
export class AppModule {}
  • use it asynchonously:
const myAsyncModuleOptions: AsyncModuleOptions<MyModuleOptions> = {
  ...
}

@Module({
  imports: [MyModule.forRootAsync(MyModule, myAsyncModuleOptions)],
})
export class AppModule {}

NOTE: forRoot/forRootAsync throws if the module is already registered. You can call register/registerAsync if you really want to register it more than once

  • import it in any child module:
@Module({
  imports: [MyModule.forChild()],
})
export class ChildModule {}

NOTE: no need to do this if the module is global scoped

examples

  • providing single option using either forRoot or forRootAsync

@homeofthings/nestjs-logger

  • providing multiple options using eihter register or registerAsync (e.g. providing multiple connections)

@homeofthings/nestjs-sqlite3

more utilities

  • class LruCache<T> - LRU cache
  • class AsyncContext<T> - asynchronouse contest based on AsyncLocalStorage
2.0.4

10 months ago

2.1.0

6 months ago

2.0.3

12 months ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.6

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago