mirror of
https://github.com/Kong/insomnia.git
synced 2026-06-03 21:55:53 -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
928 B
TypeScript
37 lines
928 B
TypeScript
import type { MockRoute } from 'insomnia-data';
|
|
import { database as db, models } from 'insomnia-data';
|
|
|
|
const { type } = models.mockRoute;
|
|
|
|
export function create(patch: Partial<MockRoute> = {}) {
|
|
if (!patch.parentId) {
|
|
throw new Error('New MockRoute missing `parentId`: ' + JSON.stringify(patch));
|
|
}
|
|
|
|
return db.docCreate<MockRoute>(type, patch);
|
|
}
|
|
|
|
export function update(mockRoute: MockRoute, patch: Partial<MockRoute> = {}) {
|
|
return db.docUpdate<MockRoute>(mockRoute, patch);
|
|
}
|
|
|
|
export function getById(id: string) {
|
|
return db.findOne<MockRoute>(type, { _id: id });
|
|
}
|
|
|
|
export function findByParentId(parentId: string) {
|
|
return db.find<MockRoute>(type, { parentId });
|
|
}
|
|
|
|
export function removeWhere(parentId: string) {
|
|
return db.removeWhere(type, { parentId });
|
|
}
|
|
|
|
export function remove(mockRoute: MockRoute) {
|
|
return db.remove(mockRoute);
|
|
}
|
|
|
|
export function all() {
|
|
return db.find<MockRoute>(type);
|
|
}
|