import { AsyncLocalStorage } from 'node:async_hooks'; import Config from './config.js'; import ServiceInterface from './interface.js'; /** * CLS 语义的上下文是键值集合;AsyncLocalStorage 的 context 是单个值, * 因此用 Map 承载,保持 get(key)/set(key, value) 的消费方式不变。 */ type ClsContext = Map; export declare class Store { get(...args: unknown[]): unknown; set(...args: unknown[]): this; bind(...args: unknown[]): unknown; reset(): this; active(): unknown; run(callback: (context?: unknown, ...args: unknown[]) => unknown, ...args: unknown[]): unknown; bindEmitter(...args: unknown[]): unknown; getContext(): unknown; createContext(): unknown; } export declare class NullStore extends Store { constructor(...args: unknown[]); } export declare class NsStore extends Store { name: string; storage: AsyncLocalStorage; constructor(name: string); get(key: string): unknown; set(key: string, value: unknown): this; bind unknown>(fn: T): T; active(): ClsContext | undefined; run(callback: (context: ClsContext, ...args: unknown[]) => unknown, ...args: unknown[]): unknown; bindEmitter(emitter: unknown): unknown; getContext(): NsStore; createContext(): ClsContext; reset(): this; } interface NamespaceConfig { enable?: boolean; } declare class Namespace extends ServiceInterface { config: NamespaceConfig; defaultName: string; store: Store | null; name: string | null; static dependencies: (typeof Config)[]; constructor(config: Config); isEnabled(): boolean | undefined; getDefaultName(): string; setDefaultName(name: string): this; getName(): string | null; getStore(): Store; destroy(name: string): this; use(ns?: string | null): Store; get(key: string): unknown; set(key: string, value: unknown): unknown; bind(...args: unknown[]): unknown; active(): unknown; run(...args: unknown[]): unknown; bindEmitter(...args: unknown[]): unknown; createContext(): unknown; } export default Namespace;