UNPKG

@sliit-foss/express-http-context

Version:

A rework of the express-http-context package to use the new async_hooks API

23 lines (22 loc) 1.15 kB
import { AsyncLocalStorage } from "async_hooks"; export declare const store: AsyncLocalStorage<unknown>; /** Express.js middleware that is responsible for initializing the context for each request. */ export declare const middleware: (_: Request, __: Response, next: () => unknown) => void; /** Runs a given function in an isolated context */ export declare const isolate: (fn: () => unknown) => void; /** * Gets a value from the context by key. Will return undefined if the context has not yet been initialized for this request or if a value is not found for the specified key. */ export declare const get: (key: string) => any; /** * Adds a value to the context by key. If the key already exists, its value will be overwritten. No value will persist if the context has not yet been initialized. */ export declare const set: (key: string, value: any) => void; declare const _default: { middleware: (_: Request, __: Response, next: () => unknown) => void; isolate: (fn: () => unknown) => void; get: (key: string) => any; set: (key: string, value: any) => void; store: AsyncLocalStorage<unknown>; }; export default _default;