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.
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import type { WorkspaceMeta } from 'insomnia-data';
|
|
import { database as db, models } from 'insomnia-data';
|
|
|
|
const { type } = models.workspaceMeta;
|
|
|
|
export function create(patch: Partial<WorkspaceMeta> = {}) {
|
|
if (!patch.parentId) {
|
|
throw new Error(`New WorkspaceMeta missing parentId ${JSON.stringify(patch)}`);
|
|
}
|
|
|
|
return db.docCreate<WorkspaceMeta>(type, patch);
|
|
}
|
|
|
|
export function update(workspaceMeta: WorkspaceMeta, patch: Partial<WorkspaceMeta> = {}) {
|
|
return db.docUpdate<WorkspaceMeta>(workspaceMeta, patch);
|
|
}
|
|
|
|
export async function updateByParentId(parentId: string, patch: Partial<WorkspaceMeta> = {}) {
|
|
const meta = await getByParentId(parentId);
|
|
return meta && db.docUpdate<WorkspaceMeta>(meta, patch);
|
|
}
|
|
|
|
export async function getByParentId(parentId: string) {
|
|
return db.findOne<WorkspaceMeta>(type, { parentId });
|
|
}
|
|
|
|
export async function getByGitRepositoryId(gitRepositoryId: string) {
|
|
return db.findOne<WorkspaceMeta>(type, { gitRepositoryId });
|
|
}
|
|
|
|
export async function getOrCreateByParentId(parentId: string) {
|
|
const doc = await getByParentId(parentId);
|
|
return doc || create({ parentId });
|
|
}
|
|
|
|
export function all() {
|
|
return db.find<WorkspaceMeta>(type);
|
|
}
|