Files
vps-tracker/packages/db/src/space-context.ts
T
DenozordecandCursor e360efb885
Docker / build (push) Failing after 20s
feat(spaces): добавить изолированные пространства и multi-user
Полная изоляция данных по space, Share (ACL) и Assign, switcher и участники в UI.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-18 15:42:54 +07:00

25 lines
655 B
TypeScript

import { AsyncLocalStorage } from 'node:async_hooks'
export const MAIN_SPACE_ID = 'space-main'
const storage = new AsyncLocalStorage<{ spaceId: string }>()
export function runWithSpace<T>(spaceId: string, fn: () => T): T {
return storage.run({ spaceId }, fn)
}
export async function runWithSpaceAsync<T>(
spaceId: string,
fn: () => Promise<T>,
): Promise<T> {
return storage.run({ spaceId }, fn)
}
export function getCurrentSpaceId(): string {
return storage.getStore()?.spaceId ?? MAIN_SPACE_ID
}
export function settingsIdForSpace(spaceId: string): string {
return spaceId === MAIN_SPACE_ID ? 'settings-main' : `settings-${spaceId}`
}