UNPKG

@pulzar/core

Version:

Next-generation Node.js framework for ultra-fast web applications with zero-reflection DI, GraphQL, WebSockets, events, and edge runtime support

76 lines 2.23 kB
import { User } from "../auth/types"; export interface RequestContext { requestId: string; user?: User; startTime: number; span?: import("@opentelemetry/api").Span; metadata: Record<string, unknown>; } export declare class RequestContextManager { private storage; /** * Create a new request context */ create(requestId: string): RequestContext; /** * Run callback within request context */ run<T>(context: RequestContext, callback: () => T): T; /** * Get current request context */ get(): RequestContext | undefined; /** * Set user in current context */ setUser(user: User): void; /** * Get user from current context */ getUser(): User | undefined; /** * Set span in current context */ setSpan(span: import("@opentelemetry/api").Span): void; /** * Set metadata in current context */ setMetadata(key: string, value: unknown): void; /** * Get metadata from current context */ getMetadata(key: string): unknown; /** * Get request ID from current context */ getRequestId(): string | undefined; getDuration(): number; } export declare const requestContext: RequestContextManager; /** * Fastify middleware to create request context */ export declare function requestContextMiddleware(request: import("fastify").FastifyRequest, reply: import("fastify").FastifyReply): Promise<void>; /** * Register request context plugin for Fastify */ export declare function registerRequestContextPlugin(fastify: import("fastify").FastifyInstance): void; /** * Get current request context */ export declare function getCurrentContext(): RequestContext | undefined; /** * Get current user from context */ export declare function getCurrentUser(): User | undefined; /** * Get current request ID */ export declare function getCurrentRequestId(): string | undefined; /** * Get current span from context */ export declare function getCurrentSpan(): import("@opentelemetry/api").Span | undefined; export declare function getCurrentLocale(): string | undefined; export declare function getRequestDuration(): number; //# sourceMappingURL=requestContext.d.ts.map