mirror of
https://github.com/Kong/insomnia.git
synced 2026-06-04 06:10:24 -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.
26 lines
613 B
TypeScript
26 lines
613 B
TypeScript
import type { UserSession } from 'insomnia-data';
|
|
import { database as db, models } from 'insomnia-data';
|
|
|
|
const { type } = models.userSession;
|
|
|
|
export async function get() {
|
|
const result = await db.findOne<UserSession>(type);
|
|
|
|
if (!result) {
|
|
const user = await db.docCreate<UserSession>(type);
|
|
return user;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export async function update(patch: Partial<UserSession>) {
|
|
const user = await get();
|
|
const updatedUser = await db.docUpdate<UserSession>(user, patch);
|
|
return updatedUser;
|
|
}
|
|
|
|
export async function remove() {
|
|
const user = await get();
|
|
await db.remove(user);
|
|
}
|