Files
insomnia/packages/insomnia-data/node-src/services/o-auth-2-token.ts
Bingbing b09cde814d refactor: extract insomnia-data into workspace package (#10010)
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.
2026-06-02 09:49:10 +00:00

43 lines
959 B
TypeScript

import type { OAuth2Token } from 'insomnia-data';
import { database as db, models } from 'insomnia-data';
const { type } = models.oAuth2Token;
export function create(patch: Partial<OAuth2Token> = {}) {
if (!patch.parentId) {
throw new Error(`New OAuth2Token missing \`parentId\` ${JSON.stringify(patch)}`);
}
return db.docCreate<OAuth2Token>(type, patch);
}
export function update(token: OAuth2Token, patch: Partial<OAuth2Token>) {
return db.docUpdate(token, patch);
}
export function remove(token: OAuth2Token) {
return db.remove(token);
}
export function getByParentId(parentId: string) {
return db.findOne<OAuth2Token>(type, { parentId });
}
export async function getOrCreateByParentId(parentId: string) {
let token = await db.findOne<OAuth2Token>(type, {
parentId,
});
if (!token) {
token = await create({
parentId,
});
}
return token;
}
export function all() {
return db.find<OAuth2Token>(type);
}