import { pb } from '~/services/pocketbase'; import { DEFAULT_SETTINGS, SETTINGS_COLLECTION } from '~/data/settings/constants'; import type { AppSettings, SettingKey } from '~/types/settings'; const settings = () => pb.collection(SETTINGS_COLLECTION); // A single settings record, seeded by the migration; defaults apply if it is missing export async function getSettings(): Promise { const { items } = await settings().getList(1, 1); return items[0] ?? DEFAULT_SETTINGS; } export async function updateSetting(key: SettingKey, value: boolean) { const current = await getSettings(); if (!current.id) throw new Error('Settings are not set up yet'); return settings().update(current.id, { [key]: value }); }