Skip to content

Commit

Permalink
feat: add HTTP driver options
Browse files Browse the repository at this point in the history
  • Loading branch information
LayZeeDK committed Oct 31, 2020
1 parent 8d090e9 commit 04a4c09
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ExcludeFromType, LogDriverConfig } from '@ngworker/lumberjack';

import { HttpDriverConfig } from './http-driver-config.token';

export type HttpDriverOptions = ExcludeFromType<HttpDriverConfig, LogDriverConfig>;
13 changes: 13 additions & 0 deletions libs/ngworker/lumberjack/http-driver/src/http-driver.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ModuleWithProviders, NgModule } from '@angular/core';

import { HttpDriverConfig, HttpDriverConfigToken } from './http-driver-config.token';
import { HttpDriverOptions } from './http-driver-options';
import { HttpDriverRootModule } from './http-driver-root.module';

@NgModule()
Expand All @@ -17,6 +18,18 @@ export class HttpDriverModule {
};
}

static withOptions(options: HttpDriverOptions): ModuleWithProviders<HttpDriverRootModule> {
return {
ngModule: HttpDriverRootModule,
providers: [
{
provide: HttpDriverConfigToken,
useValue: options,
},
],
};
}

constructor() {
throw new Error('Do not import HttpDriverModule directly. Use HttpDriverModule.forRoot.');
}
Expand Down
1 change: 1 addition & 0 deletions libs/ngworker/lumberjack/http-driver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

export * from './http-driver-config.token';
export * from './http-driver-options';
export * from './http-driver-root.module';
export * from './http-driver.module';
export * from './http.driver';
1 change: 1 addition & 0 deletions libs/ngworker/lumberjack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './lib/lumberjack-logger.service';
export * from './lib/lumberjack.module';
export * from './lib/lumberjack.service';
export * from './lib/time';
export * from './lib/type-utilities/exclude-from-type';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type ExcludeFromType<T, U> = {
[K in Exclude<keyof T, keyof U>]: T[K];
};

0 comments on commit 04a4c09

Please sign in to comment.