@dalet-oss/express-http-context
Version:
Modern request-scoped storage support for Express.js based on Asynchronous Local Storage.
37 lines (36 loc) • 1.17 kB
TypeScript
/// <reference types="node" />
import { AsyncLocalStorage } from 'async_hooks';
declare global {
var expressHttpContextStorage: AsyncLocalStorage<Map<string, any>>;
}
/**
* Express.js middleware that is responsible for initializing the context for
* each request.
*
* Declared as type 'any' because otherwise Typescript consumers can get tie
* themselves in knots.
*/
export declare const middleware: any;
/**
* 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 function get<T = any>(key: string): T | undefined;
/**
* Adds a value to the context by key.
*
* If the key already exists, its value will be overwritten.
* No value will be persisted if the context has not yet been initialized.
*
* Returns the value that was set, or undefined if the context has not yet been
* initialized for this request.
*/
export declare function set<T = any>(key: string, value: T): T | undefined;
declare const _default: {
get: typeof get;
middleware: any;
set: typeof set;
};
export default _default;