managarten/apps/mana/apps/web/src/lib/data/scope/index.ts
Till JS a6c5397d10 refactor(scope): smart hook stamps active-Space id, revert explicit stamps
Replaces the silent `_personal:<userId>` literal in the creating-hook
with `getEffectiveSpaceId()`, which returns the currently-active Space
when one is loaded and falls back to the personal sentinel for
guests / pre-bootstrap windows. Side-effect: writes during a Brand /
Family / Team session now land under that Space's UUID instead of
silently routing to Personal once `reconcileSentinels` runs — the
underlying tenancy bug Schicht A was supposed to catch.

With the hook doing the right thing automatically, the 16 explicit
`spaceId: getEffectiveSpaceId()` stamps from Etappe 1 are redundant
boilerplate. Reverted across:

  picture/stores/boards (boards + boardItems)
  events/stores/{guests,items}
  companion/stores/chat (conversations + messages)
  calc/stores/{calculations,saved-formulas}
  quotes/stores/{favorites,custom-quotes}
  skilltree/stores/{skills,achievements}
  moodlit/stores/moods
  plants/mutations
  questions/stores/answers (manual + research draft)
  data/ai/agents/{bootstrap,kontext}

Helper plumbing:

- `getEffectiveSpaceId()` lives in `scope/active-space.svelte.ts` (no
  db dependency) so the creating-hook in `database.ts` can import it
  without an ESM cycle. Inlined the `_personal:<userId>` literal there
  instead of pulling `personalSpaceSentinel` from `bootstrap.ts`,
  which would otherwise tangle the import graph.
- Re-exported via `scope/index.ts` for callers outside the hook.
- `setActiveSpace` and `loadActiveSpace` already funnel through the
  shared `applyActiveSpace` helper, so the hook's view of the active
  Space stays in sync with the rest of the scope layer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 15:49:42 +02:00

39 lines
934 B
TypeScript

/**
* Spaces scope layer — barrel.
*
* Module code should import everything it needs from here rather than
* reaching into the individual files, so future refactors of the
* internals stay invisible to consumers.
*
* See docs/plans/spaces-foundation.md for the full RFC.
*/
export {
getActiveSpace,
getActiveSpaceId,
getEffectiveSpaceId,
getActiveSpaceStatus,
getActiveSpaceError,
setActiveSpace,
loadActiveSpace,
getEffectiveTier,
writeActiveSpaceHint,
type ActiveSpace,
type ActiveSpaceStatus,
} from './active-space.svelte';
export { reconcileSentinels, personalSpaceSentinel } from './bootstrap';
export {
scopedTable,
scopedForModule,
scopedGet,
assertModuleAllowed,
getInScopeSpaceIds,
ScopeNotReadyError,
ModuleNotInSpaceError,
} from './scoped-db';
export { applyVisibility, isVisibleToCurrentUser, type Visibility } from './visibility';
export { authFetch, authBaseUrl } from './auth-fetch';