import { AsyncLocalStorage } from 'node:async_hooks' const tenantStorage = new AsyncLocalStorage() export function runWithCacheTenant(tenantId: string | null, fn: () => T): T export function runWithCacheTenant(tenantId: string | null, fn: () => Promise): Promise export function runWithCacheTenant(tenantId: string | null, fn: () => T | Promise): T | Promise { return tenantStorage.run(tenantId ?? null, fn) } export function getCurrentCacheTenant(): string | null { return tenantStorage.getStore() ?? null }