UNPKG

1.33 kBTypeScriptView Raw
1// Type definitions for cls-hooked 4.3
2// Project: https://github.com/jeff-lewis/cls-hooked
3// Definitions by: Leo Liang <https://github.com/aleung>
4// Lucian Buzzo <https://github.com/LucianBuzzo>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
7/// <reference types="node" />
8
9import { EventEmitter } from "events";
10
11export interface Namespace<N = Record<string, any>> {
12 active: any;
13
14 set<K extends keyof N = keyof N>(key: K, value: N[K]): N[K];
15 get<K extends keyof N = keyof N>(key: K): N[K];
16 run(fn: (...args: any[]) => void): void;
17 runAndReturn<T>(fn: (...args: any[]) => T): T;
18 runPromise<T>(fn: (...args: any[]) => Promise<T>): Promise<T>;
19 bind<F extends Function>(fn: F, context?: any): F; // tslint:disable-line: ban-types
20 bindEmitter(emitter: EventEmitter): void;
21 createContext(): any;
22 enter(context: any): void;
23 exit(context: any): void;
24}
25
26// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
27export function createNamespace<N = Record<string, any>>(name: string): Namespace<N>;
28// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
29export function getNamespace<N = Record<string, any>>(name: string): Namespace<N> | undefined;
30export function destroyNamespace(name: string): void;
31export function reset(): void;
32
\No newline at end of file