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.
37 lines
908 B
TypeScript
37 lines
908 B
TypeScript
import type { ProtoFile } from 'insomnia-data';
|
|
import { database as db, models } from 'insomnia-data';
|
|
|
|
const { type } = models.protoFile;
|
|
|
|
export function create(patch: Partial<ProtoFile> = {}) {
|
|
if (!patch.parentId) {
|
|
throw new Error('New ProtoFile missing `parentId`');
|
|
}
|
|
|
|
return db.docCreate<ProtoFile>(type, patch);
|
|
}
|
|
|
|
export function remove(protoFile: ProtoFile) {
|
|
return db.remove(protoFile);
|
|
}
|
|
|
|
export function update(protoFile: ProtoFile, patch: Partial<ProtoFile> = {}) {
|
|
return db.docUpdate<ProtoFile>(protoFile, patch);
|
|
}
|
|
|
|
export function getById(_id: string) {
|
|
return db.findOne<ProtoFile>(type, { _id });
|
|
}
|
|
|
|
export function getByParentId(parentId: string) {
|
|
return db.findOne<ProtoFile>(type, { parentId });
|
|
}
|
|
|
|
export function findByParentId(parentId: string) {
|
|
return db.find<ProtoFile>(type, { parentId });
|
|
}
|
|
|
|
export function all() {
|
|
return db.find<ProtoFile>(type);
|
|
}
|