mirror of
https://github.com/Kong/insomnia.git
synced 2026-06-03 13:47:23 -04:00
Move insomnia-data models, services, database code, and common utilities into a dedicated workspace package. Update consumers to import from the new package entrypoints and declare workspace dependencies for the extracted package.
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import type { Settings } from 'insomnia-data';
|
|
import { database as db, models } from 'insomnia-data';
|
|
|
|
export async function all() {
|
|
let settingsList = await db.find<Settings>(models.settings.type);
|
|
|
|
if (settingsList?.length === 0) {
|
|
settingsList = [await getOrCreate()];
|
|
}
|
|
|
|
return settingsList;
|
|
}
|
|
|
|
async function create() {
|
|
const settings = await db.docCreate<Settings>(models.settings.type);
|
|
return settings;
|
|
}
|
|
|
|
export async function update(settings: Settings, patch: Partial<Settings>) {
|
|
const updatedSettings = await db.docUpdate<Settings>(settings, patch);
|
|
return updatedSettings;
|
|
}
|
|
|
|
export async function patch(settingsPatch: Partial<Settings>) {
|
|
const settings = await getOrCreate();
|
|
const updatedSettings = await db.docUpdate<Settings>(settings, settingsPatch);
|
|
return updatedSettings;
|
|
}
|
|
|
|
export async function getOrCreate() {
|
|
const result = await db.findOne<Settings>(models.settings.type);
|
|
|
|
if (!result) {
|
|
return await create();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export async function get() {
|
|
return getOrCreate();
|
|
}
|