You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@fastify/request-context

Package Overview
Dependencies
Maintainers
19
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/request-context - npm Package Compare versions

Comparing version

to
6.2.0

2

index.js

@@ -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