mirror of
https://github.com/Kong/insomnia.git
synced 2026-11-03 03:25:26 -05:00
* add package remove workspaceCount from rootLoaderData move unrelevant loaders out add query context adapt tanstack query fix som issues add new ways to load data initial changes clean code remove and fix code add a method to get organization data in main refine the way to get data from tanstack fix issue fix issues fix duplicate calling issue fix unsubscribe issue fix merge issue fix listen issue fix find organization issue for workspace support workspatemeta in tanstack query update types move logic to insomnia-data services remove things change to use service fix the loader bug remove a file fix type issues refine code for workspace-children change style import fix main type issue fix type issue fix data fetching fix delete project issue cache the sidebar data in main add unit tests update cache and cache service fix issues from comment revert organization change fix issues from comment fix test failures fix test failures add comments and refine way to get workspace children fix dedup and import issue remove useless code add duplicate id check fix type failures fix mock server issue resolve conflict 1.remove main process cache add renderer level app data fix issues * fix issues from review
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import type { Query, WorkspaceMeta } from 'insomnia-data';
|
|
import { database as db, models } from 'insomnia-data';
|
|
|
|
const { type } = models.workspaceMeta;
|
|
|
|
export function list(query?: Query<WorkspaceMeta>, sort?: Record<string, any>, limit?: number) {
|
|
return db.find<WorkspaceMeta>(type, query, sort, limit);
|
|
}
|
|
|
|
export const getById = (_id: string) => db.findOne<WorkspaceMeta>(type, { _id });
|
|
|
|
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 getOrCreateByParentId(parentId: string) {
|
|
const doc = await getByParentId(parentId);
|
|
return doc || create({ parentId });
|
|
}
|