-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(common): injectable decorator factory
fix #120
- Loading branch information
1 parent
8a9d6cb
commit 42b2f34
Showing
11 changed files
with
41 additions
and
14 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,2 +1,3 @@ | ||
export * from './injectDecoratorFactory'; | ||
export * from './mixins'; | ||
export * from './options'; |
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 { Inject } from '@nestjs/common'; | ||
|
||
/** | ||
* Creates a decorator that can be used as a convenience to inject a specific token | ||
* | ||
* Instead of using @Inject(SOME_THING_TOKEN) this can be used to create a new named Decorator | ||
* such as @InjectSomeThing() which will hide the token details from users making APIs easier | ||
* to consume | ||
* @param token | ||
*/ | ||
export const makeInjectableDecorator = ( | ||
token: string | symbol | ||
): (() => ParameterDecorator) => () => (target, key, descriptor) => | ||
Inject(token)(target, key, descriptor); |
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,9 +1,12 @@ | ||
import { makeInjectableDecorator } from '@golevelup/nestjs-common'; | ||
import { SetMetadata } from '@nestjs/common'; | ||
import { HASURA_EVENT_HANDLER } from './hasura.constants'; | ||
import { HASURA_EVENT_HANDLER, HASURA_MODULE_CONFIG } from './hasura.constants'; | ||
import { HasuraEventHandlerConfig } from './hasura.interfaces'; | ||
|
||
export const HasuraEventHandler = (config: HasuraEventHandlerConfig) => ( | ||
target, | ||
key, | ||
descriptor | ||
) => SetMetadata(HASURA_EVENT_HANDLER, config)(target, key, descriptor); | ||
|
||
export const InjectHasuraConfig = makeInjectableDecorator(HASURA_MODULE_CONFIG); |
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
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