mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 01:35:39 -04:00
- Create 18 new query modules under `packages/db/src/queries/` covering every domain (availability, cache, colors, credits, cron, discovery, image-cache, imports, integrations, lists, metadata, person, settings, system-health, thumbhash, title, tracking, webhooks) - Remove all direct `db` client imports and raw Drizzle expressions from `@sofa/core` services and `apps/server` procedures/cron; replace with named query functions - Extract cron DB helpers (`startCronRun`, `completeCronRun`, `failCronRun`, `getLibraryTitleIds`, `getStaleLibraryTitles`, etc.) into `packages/core/src/cron.ts` - Extract integration DB helpers into `packages/core/src/integrations.ts` - Add `drizzle-orm` as a direct dependency of `@sofa/db` and remove it from `@sofa/core` - Update `AGENTS.md` to document the strict layered architecture rule
34 lines
782 B
TypeScript
34 lines
782 B
TypeScript
import {
|
|
getSettingValue,
|
|
getUserCount as queryGetUserCount,
|
|
upsertSetting,
|
|
} from "@sofa/db/queries/settings";
|
|
|
|
export function getSetting(key: string): string | null {
|
|
return getSettingValue(key);
|
|
}
|
|
|
|
export function setSetting(key: string, value: string): void {
|
|
upsertSetting(key, value);
|
|
}
|
|
|
|
export function getUserCount(): number {
|
|
return queryGetUserCount();
|
|
}
|
|
|
|
export function getInstanceId(): string {
|
|
const existing = getSetting("instanceId");
|
|
if (existing) return existing;
|
|
const id = Bun.randomUUIDv7();
|
|
setSetting("instanceId", id);
|
|
return id;
|
|
}
|
|
|
|
export function isRegistrationOpen(): boolean {
|
|
const userCount = getUserCount();
|
|
if (userCount === 0) return true;
|
|
|
|
const setting = getSetting("registrationOpen");
|
|
return setting === "true";
|
|
}
|