-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to inject tx directly as Proxy
- Loading branch information
Showing
8 changed files
with
292 additions
and
25 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
23 changes: 23 additions & 0 deletions
23
packages/transactional/src/lib/inject-transaction.decorator.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Inject } from '@nestjs/common'; | ||
const TRANSACTION_TOKEN = Symbol('TRANSACTION_TOKEN'); | ||
|
||
/** | ||
* Get injection token for the Transaction instance. | ||
* If name is omitted, the default instance is used. | ||
*/ | ||
export function getTransactionToken(connectionName?: string) { | ||
return connectionName | ||
? Symbol.for(`${TRANSACTION_TOKEN.description}_${connectionName}`) | ||
: TRANSACTION_TOKEN; | ||
} | ||
|
||
/** | ||
* Inject the Transaction instance directly (that is the `tx` property of the TransactionHost) | ||
* | ||
* Optionally, you can provide a connection name to inject a named instance. | ||
* | ||
* A shorthand for `Inject(getTransactionToken(connectionName))` | ||
*/ | ||
export function InjectTransaction(connectionName?: string) { | ||
return Inject(getTransactionToken(connectionName)); | ||
} |
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,9 +1,9 @@ | ||
export const TRANSACTION_CONNECTION = Symbol('TRANSACTION_CONNECTION'); | ||
export const TRANSACTIONAL_ADAPTER_OPTIONS = Symbol('TRANSACTIONAL_OPTIONS'); | ||
|
||
const TRANSACTIONAL_INSTANCE = Symbol('TRANSACTIONAL_CLIENT'); | ||
const TRANSACTION_CLS_KEY = Symbol('TRANSACTION_CLS_KEY'); | ||
|
||
export const getTransactionalInstanceSymbol = (connectionName?: string) => | ||
export const getTransactionClsKey = (connectionName?: string) => | ||
connectionName | ||
? Symbol.for(`${TRANSACTIONAL_INSTANCE.toString()}_${connectionName}`) | ||
: TRANSACTIONAL_INSTANCE; | ||
? Symbol.for(`${TRANSACTION_CLS_KEY.description}_${connectionName}`) | ||
: TRANSACTION_CLS_KEY; |
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.