-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(): rename notify to notification
- Loading branch information
1 parent
33dfed7
commit 0bcb4d5
Showing
15 changed files
with
189 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './nestjs-notify-provider.constant'; | ||
export * from './nestjs-notification-provider.constant'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const NESTJS_NOTIFICATION_OPTIONS = 'NESTJS_NOTIFICATION_OPTIONS'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './interfaces'; | ||
export * from './nestjs-notify.module'; | ||
export * from './nestjs-notify.service'; | ||
export * from './nestjs-notification.module'; | ||
export * from './nestjs-notification.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './nestjs-notify.interface'; | ||
export * from './nestjs-notify-module.interface'; | ||
export * from './nestjs-notify-channel.interface'; | ||
export * from './nestjs-notification.interface'; | ||
export * from './nestjs-notification-module.interface'; | ||
export * from './nestjs-notification-channel.interface'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NestJsNotification } from './nestjs-notification.interface'; | ||
|
||
/** | ||
* @interface INestjsNotificationChannel | ||
* @property send() | ||
*/ | ||
export interface INestjsNotificationChannel { | ||
/** | ||
* Send the given notification | ||
* @param {NestJsNotification} notification | ||
* @return Promise<any> | ||
*/ | ||
send(notification: NestJsNotification): Promise<any>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ModuleMetadata, Provider, Type } from '@nestjs/common'; | ||
|
||
/** | ||
* @interface NestjsNotificationModuleOptionsFactory | ||
* @property createNestjsNotificationOptions() | ||
*/ | ||
export interface NestjsNotificationModuleOptionsFactory { | ||
createNestjsNotificationOptions(): | ||
| Promise<NestjsNotificationModuleOptions> | ||
| NestjsNotificationModuleOptions; | ||
} | ||
|
||
/** | ||
* @interface NestjsNotificationModuleAsyncOptions | ||
* @extends {Pick<ModuleMetadata, 'imports'>} | ||
* @property useExisting | ||
* @property useClass | ||
* @property useFactory | ||
* @property inject | ||
* @property extraProviders | ||
*/ | ||
export interface NestjsNotificationModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> { | ||
useExisting?: Type<NestjsNotificationModuleOptionsFactory>; | ||
useClass?: Type<NestjsNotificationModuleOptionsFactory>; | ||
useFactory?: ( | ||
...args: any[] | ||
) => Promise<NestjsNotificationModuleOptions> | NestjsNotificationModuleOptions; | ||
inject?: any[]; | ||
extraProviders?: Provider[]; | ||
} | ||
|
||
/** | ||
* @interface NestjsNotificationModuleOptions | ||
*/ | ||
export type NestjsNotificationModuleOptions = null; |
10 changes: 5 additions & 5 deletions
10
lib/interfaces/nestjs-notify.interface.ts → ...terfaces/nestjs-notification.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { DynamicModule, Module, Provider, ValueProvider } from '@nestjs/common'; | ||
import { NestjsNotificationService } from './nestjs-notification.service'; | ||
import { | ||
NestjsNotificationModuleAsyncOptions, | ||
NestjsNotificationModuleOptions, | ||
NestjsNotificationModuleOptionsFactory, | ||
} from './interfaces'; | ||
import { NESTJS_NOTIFICATION_OPTIONS } from './constants'; | ||
|
||
@Module({}) | ||
export class NestjsNotificationModule { | ||
/** | ||
* Register module | ||
* @static | ||
* @param {NestjsNotificationModuleOptions} options | ||
* @return DynamicModule | ||
*/ | ||
static register(options: NestjsNotificationModuleOptions): DynamicModule { | ||
const notifyProvider: ValueProvider = { | ||
provide: NESTJS_NOTIFICATION_OPTIONS, | ||
useValue: options, | ||
}; | ||
|
||
return { | ||
module: NestjsNotificationModule, | ||
providers: [NestjsNotificationService, notifyProvider], | ||
exports: [NestjsNotificationService, notifyProvider], | ||
}; | ||
} | ||
|
||
/** | ||
* Register async | ||
* @static | ||
* @param {NestjsNotificationModuleAsyncOptions} options | ||
* @return DynamicModule | ||
*/ | ||
static registerAsync(options: NestjsNotificationModuleAsyncOptions): DynamicModule { | ||
const notifyProvider: ValueProvider = { | ||
provide: NESTJS_NOTIFICATION_OPTIONS, | ||
useValue: options, | ||
}; | ||
|
||
return { | ||
module: NestjsNotificationModule, | ||
imports: options.imports || [], | ||
providers: [NestjsNotificationService, notifyProvider, ...this.createAsyncProviders(options)], | ||
exports: [NestjsNotificationService, notifyProvider], | ||
}; | ||
} | ||
|
||
/** | ||
* Create async providers | ||
* @private | ||
* @param {NestjsNotificationModuleAsyncOptions} options | ||
* @return Provider[] | ||
*/ | ||
private static createAsyncProviders(options: NestjsNotificationModuleAsyncOptions): Provider[] { | ||
if (options.useExisting || options.useFactory) { | ||
return [this.createAsyncConfigProvider(options)]; | ||
} else if (!options.useClass) { | ||
return [ | ||
{ | ||
provide: NESTJS_NOTIFICATION_OPTIONS, | ||
useValue: {}, | ||
inject: options.inject || [], | ||
}, | ||
]; | ||
} | ||
|
||
return [ | ||
this.createAsyncConfigProvider(options), | ||
{ | ||
provide: options.useClass, | ||
useClass: options.useClass, | ||
}, | ||
]; | ||
} | ||
|
||
/** | ||
* Create async config provider | ||
* @private | ||
* @param {NestjsNotificationModuleAsyncOptions} options | ||
* @return Provider<any> | ||
*/ | ||
private static createAsyncConfigProvider( | ||
options: NestjsNotificationModuleAsyncOptions, | ||
): Provider<any> { | ||
if (options.useFactory) { | ||
return { | ||
provide: NESTJS_NOTIFICATION_OPTIONS, | ||
useFactory: options.useFactory, | ||
inject: options.inject || [], | ||
}; | ||
} | ||
|
||
const inject = options.useClass || options.useExisting; | ||
|
||
if (!inject) { | ||
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting'); | ||
} | ||
|
||
return { | ||
provide: NESTJS_NOTIFICATION_OPTIONS, | ||
async useFactory( | ||
optionsFactory: NestjsNotificationModuleOptionsFactory, | ||
): Promise<NestjsNotificationModuleOptions> { | ||
return optionsFactory.createNestjsNotificationOptions(); | ||
}, | ||
inject: [inject], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.