UNPKG

@gati-framework/runtime

Version:

Gati runtime execution engine for running handler-based applications

62 lines 1.96 kB
/** * @module runtime/local-context * @description Local context manager for request-scoped data in Gati framework */ import type { LocalContext, LocalContextOptions, WebSocketCoordinator } from './types/context.js'; import { VersionRegistry } from './timescape/registry.js'; /** * Creates a local context instance for a single request * * @param options - Configuration options for the local context * @param wsCoordinator - WebSocket coordinator for event handling * @returns LocalContext instance * * @example * ```typescript * const lctx = createLocalContext({ * requestId: 'custom-id', * state: { userId: '123' }, * }); * ``` */ export declare function createLocalContext(options?: LocalContextOptions, wsCoordinator?: WebSocketCoordinator, registry?: VersionRegistry): LocalContext; /** * Cleans up the local context, calling all registered cleanup hooks * * @param lctx - Local context instance * @param wsCoordinator - WebSocket coordinator for cleanup * @returns Promise that resolves when all cleanup hooks complete * * @example * ```typescript * await cleanupLocalContext(lctx); * ``` */ export declare function cleanupLocalContext(lctx: LocalContext, wsCoordinator?: WebSocketCoordinator): Promise<void>; /** * Sets a value in the local context state * * @param lctx - Local context instance * @param key - State key * @param value - State value * * @example * ```typescript * setState(lctx, 'userId', '123'); * ``` */ export declare function setState(lctx: LocalContext, key: string, value: unknown): void; /** * Gets a value from the local context state * * @param lctx - Local context instance * @param key - State key * @returns State value or undefined if not found * * @example * ```typescript * const userId = getState<string>(lctx, 'userId'); * ``` */ export declare function getState<T = unknown>(lctx: LocalContext, key: string): T | undefined; //# sourceMappingURL=local-context.d.ts.map