-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Please use this template for your pull request. --> <!-- Please use the sections that you need and delete other sections --> ## This PR <!-- add the description of the PR here --> - removes experimental warning from context propagation js-docs - improves typing of `setTransactionContext` - adds `AsyncLocalStorageTransactionContextProvider` to server SDK - @beeme1mr @toddbaert I am not 100% sure on this one. To me it makes much sense to add this to the server SDK as it uses the Node default way `async_hooks`/`async_local_storage` which is part of Node since Node 16.x. I expect almost every project using the feature, to build exactly this so I wanted to include it in the SDK. As we are using Node types anyways I do not see a problem here, but still we could leave this out as it couples the implementation closer to Node. Before merging I will have to change the README. --------- Signed-off-by: Lukas Reining <[email protected]>
- Loading branch information
1 parent
8101ff1
commit b1abef1
Showing
10 changed files
with
174 additions
and
60 deletions.
There are no files selected for viewing
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
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
19 changes: 19 additions & 0 deletions
19
...ages/server/src/transaction-context/async-local-storage-transaction-context-propagator.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,19 @@ | ||
import { EvaluationContext } from '@openfeature/core'; | ||
import { TransactionContext, TransactionContextPropagator } from './transaction-context'; | ||
import { AsyncLocalStorage } from 'async_hooks'; | ||
|
||
export class AsyncLocalStorageTransactionContextPropagator implements TransactionContextPropagator { | ||
private asyncLocalStorage = new AsyncLocalStorage<EvaluationContext>(); | ||
|
||
getTransactionContext(): EvaluationContext { | ||
return this.asyncLocalStorage.getStore() ?? {}; | ||
} | ||
|
||
setTransactionContext<TArgs extends unknown[], R>( | ||
transactionContext: TransactionContext, | ||
callback: (...args: TArgs) => R, | ||
...args: TArgs | ||
): void { | ||
this.asyncLocalStorage.run(transactionContext, callback, ...args); | ||
} | ||
} |
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 './transaction-context'; | ||
export * from './no-op-transaction-context-propagator'; | ||
export * from './async-local-storage-transaction-context-propagator'; |
10 changes: 7 additions & 3 deletions
10
packages/server/src/transaction-context/no-op-transaction-context-propagator.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 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
Oops, something went wrong.