@fastify/request-context
Advanced tools
Comparing version
@@ -69,3 +69,3 @@ 'use strict' | ||
module.exports.fastifyRequestContext = fastifyRequestContext | ||
module.exports.asyncLocalStorage = asyncLocalStorage | ||
module.exports.requestContext = requestContext | ||
@@ -72,0 +72,0 @@ |
{ | ||
"name": "@fastify/request-context", | ||
"version": "6.1.0", | ||
"version": "6.2.0", | ||
"description": "Request-scoped storage support, based on Asynchronous Local Storage, with fallback to cls-hooked for older Node versions", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -26,5 +26,5 @@ # @fastify/request-context | ||
| ---------------|-----------------| | ||
| `^6.x` | `^5.x` | | ||
| `^4.x` | `^4.x` | | ||
| `^2.x` | `^3.x` | | ||
| `>=6.x` | `^5.x` | | ||
| `>=4.x <6.x` | `^4.x` | | ||
| `>=2.x <4.x` | `^3.x` | | ||
| `^1.x` | `^2.x` | | ||
@@ -153,3 +153,17 @@ | `^1.x` | `^1.x` | | ||
## Usage outside of a request | ||
If functions depend on requestContext but are not called in a request, i.e. in tests or workers, they can be wrapped in the asyncLocalStorage instance of requestContext: | ||
``` | ||
import { asyncLocalStorage } from '@fastify/request-context'; | ||
it('should set request context', () => { | ||
asyncLocalStorage.run({}, async () => { | ||
requestContext.set('userId', 'some-fake-user-id'); | ||
someCodeThatUsesRequestContext(); // requestContext.get('userId') will work | ||
}) | ||
}) | ||
``` | ||
## License | ||
@@ -156,0 +170,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { AsyncResource } from 'node:async_hooks' | ||
import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks' | ||
import { FastifyPluginCallback, FastifyRequest } from 'fastify' | ||
@@ -57,3 +57,3 @@ | ||
export const requestContext: RequestContext | ||
export const asyncLocalStorage: AsyncLocalStorage<RequestContext> | ||
/** | ||
@@ -60,0 +60,0 @@ * @deprecated Use FastifyRequestContextOptions instead |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14483
4.6%123
1.65%175
8.7%1
Infinity%