-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract proxy creation into utility
- Loading branch information
1 parent
a91ac71
commit 335fac5
Showing
3 changed files
with
21 additions
and
10 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/cloudflare/src/cli/templates/utils/create-als-proxy.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,18 @@ | ||
import type { AsyncLocalStorage } from "node:async_hooks"; | ||
|
||
/** | ||
* Creates a proxy for to use for an instance of AsyncLocalStorage. | ||
* | ||
* @param als AsyncLocalStorage instance. | ||
*/ | ||
export function createALSProxy<T>(als: AsyncLocalStorage<T>) { | ||
return new Proxy( | ||
{}, | ||
{ | ||
ownKeys: () => Reflect.ownKeys(als.getStore()!), | ||
getOwnPropertyDescriptor: (_, ...args) => Reflect.getOwnPropertyDescriptor(als.getStore()!, ...args), | ||
get: (_, property) => Reflect.get(als.getStore()!, property), | ||
set: (_, property, value) => Reflect.set(als.getStore()!, property, value), | ||
} | ||
); | ||
} |
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 * from "./create-als-proxy"; |
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