From 1beda05e6c28d887d20377ca7b2f6abea12af50b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 6 Jan 2026 20:59:49 +0200 Subject: [PATCH] chore(client/lightweight): basic CLS implementation --- apps/client/src/lightweight/cls_provider.ts | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 apps/client/src/lightweight/cls_provider.ts 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; + } + } +}