import { AsyncLocalStorage } from 'node:async_hooks'; interface UseContext { /** * Get the current context. Throws if no context is set. */ use: () => T; /** * Get the current context. Returns `null` when no context is set. */ tryUse: () => T | null; /** * Set the context as Singleton Pattern. */ set: (instance?: T, replace?: boolean) => void; /** * Clear current context. */ unset: () => void; /** * Exclude a synchronous function with the provided context. */ call: (instance: T, callback: () => R) => R; /** * Exclude an asynchronous function with the provided context. * Requires installing the transform plugin to work properly. */ callAsync: (instance: T, callback: () => R | Promise) => Promise; } interface ContextOptions { asyncContext?: boolean; AsyncLocalStorage?: typeof AsyncLocalStorage; } declare function createContext(opts?: ContextOptions): UseContext; interface ContextNamespace { get: (key: string, opts?: ContextOptions) => UseContext; } declare function createNamespace(defaultOpts?: ContextOptions): { get(key: any, opts?: ContextOptions): UseContext; }; declare const defaultNamespace: ContextNamespace; declare const getContext: (key: string, opts?: ContextOptions) => UseContext; declare const useContext: (key: string, opts?: ContextOptions) => () => T; type AsyncFunction = () => Promise; declare function executeAsync(function_: AsyncFunction): [Promise, () => void]; declare function withAsyncContext(function_: AsyncFunction, transformed?: boolean): AsyncFunction; export { ContextNamespace, ContextOptions, UseContext, createContext, createNamespace, defaultNamespace, executeAsync, getContext, useContext, withAsyncContext };