diff --git a/apps/client/src/lightweight/cls_provider.ts b/apps/client/src/lightweight/cls_provider.ts new file mode 100644 index 000000000..20ff5dda9 --- /dev/null +++ b/apps/client/src/lightweight/cls_provider.ts @@ -0,0 +1,33 @@ +import { ExecutionContext } from "@triliumnext/core"; + +export default class BrowserExecutionContext implements ExecutionContext { + private store: Map | null = null; + + get(key: string): T | undefined { + return this.store?.get(key); + } + + set(key: string, value: any): void { + if (!this.store) { + throw new Error("ExecutionContext not initialized"); + } + this.store.set(key, value); + } + + reset(): void { + this.store = null; + } + + init(callback: () => T): T { + // Create a fresh context for this request + const prev = this.store; + this.store = new Map(); + + try { + return callback(); + } finally { + // Always clean up + this.store = prev; + } + } +}