/** * A framework-neutral {@linkcode ContextAdapter}, for hosts that have no * request-scoped storage of their own to hand the SDK. * * @module */ import type { ContextAdapter, ContextData } from '../../context/baseContext.js'; /** * The part of Node's `AsyncLocalStorage` this adapter uses. * * Declared structurally rather than imported so the browser build never has to * resolve `node:async_hooks`. */ export type AsyncContextStorage = { getStore(): ContextData | undefined; run(store: ContextData, fn: () => T): T; }; /** * Stores context data in memory. * * A server handling concurrent requests must pass an `AsyncLocalStorage`, or all * of them will share one context: * * @example * ```ts * import { AsyncLocalStorage } from 'node:async_hooks'; * import { configureAdapter, MemoryAdapter } from '@optimizely/cms-sdk/core'; * * const adapter = new MemoryAdapter(new AsyncLocalStorage()); * configureAdapter(adapter); * * // then, per request: * await adapter.run(() => handleRequest(request)); * ``` */ export declare class MemoryAdapter implements ContextAdapter { private storage; private fallback; constructor(storage?: AsyncContextStorage); /** The store for this request, or a process-wide one outside any {@linkcode run}. */ private current; /** Runs `fn` with a context of its own. Wrap a request handler in this. */ run(fn: () => T): T; initializeContext(): void; set(key: K, value: ContextData[K]): void; get(key: K): ContextData[K] | undefined; getData(): ContextData | undefined; setData(value: Partial): void; clear(): void; }