Model and DB refactor (#61)

- [x] Move from `sqlx` to `rusqlite`
- [x] Generate TS types from Rust models
This commit is contained in:
Gregory Schier
2024-08-05 07:58:20 -07:00
committed by GitHub
parent 71013fd701
commit 989b5a8058
193 changed files with 7083 additions and 8337 deletions

View File

@@ -1,4 +1,4 @@
import type { GrpcRequest, HttpRequest } from './models';
import type { GrpcRequest, HttpRequest } from '@yaakapp/api';
export function fallbackRequestName(r: HttpRequest | GrpcRequest | null): string {
if (r == null) return '';

View File

@@ -0,0 +1,5 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { CookieDomain } from "./CookieDomain";
import type { CookieExpires } from "./CookieExpires";
export type Cookie = { raw_cookie: string, domain: CookieDomain, expires: CookieExpires, path: [string, boolean], };

View File

@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type CookieDomain = { "HostOnly": string } | { "Suffix": string } | "NotPresent" | "Empty";

View File

@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type CookieExpires = { "AtUtc": string } | "SessionEnd";

View File

@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Cookie } from "./Cookie";
export type CookieJar = { id: string, model: "cookie_jar", createdAt: string, updatedAt: string, workspaceId: string, name: string, cookies: Array<Cookie>, };

View File

@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type Settings = { id: string, model: "settings", createdAt: string, updatedAt: string, theme: string, appearance: string, themeDark: string, themeLight: string, updateChannel: string, interfaceFontSize: number, interfaceScale: number, editorFontSize: number, editorSoftWrap: boolean, openWorkspaceNewWindow: boolean | null, };

View File

@@ -1,4 +1,4 @@
import type { KeyValue } from './models';
import type { KeyValue } from '@yaakapp/api';
import { invokeCmd } from './tauri';
export async function setKeyValue<T>({

View File

@@ -1,17 +1,20 @@
import type {
BaseModel,
Workspace,
HttpResponse,
HttpRequest,
HttpHeader,
Folder,
GrpcRequest,
GrpcEvent,
GrpcConnection,
Environment,
Folder,
GrpcConnection,
GrpcEvent,
GrpcRequest,
HttpRequest,
HttpResponse,
KeyValue,
Workspace,
HttpResponseHeader,
} from '@yaakapp/api';
import type { Cookie } from './gen/Cookie';
import type { CookieJar } from './gen/CookieJar';
import type { Settings } from './gen/Settings';
export * from '@yaakapp/api';
export type { CookieJar, Cookie, Settings };
export const BODY_TYPE_NONE = null;
export const BODY_TYPE_GRAPHQL = 'graphql';
@@ -39,34 +42,6 @@ export type Model =
| Environment
| CookieJar;
export interface Settings extends BaseModel {
readonly model: 'settings';
theme: string;
appearance: string;
themeLight: string;
themeDark: string;
updateChannel: string;
interfaceFontSize: number;
interfaceScale: number;
editorFontSize: number;
editorSoftWrap: boolean;
openWorkspaceNewWindow: boolean | null;
}
export interface CookieJar extends BaseModel {
readonly model: 'cookie_jar';
workspaceId: string;
name: string;
cookies: Cookie[];
}
export interface Cookie {
raw_cookie: string;
domain: { HostOnly: string } | { Suffix: string } | 'NotPresent' | 'Empty';
expires: { AtUtc: string } | 'SessionEnd';
path: [string, boolean];
}
export function cookieDomain(cookie: Cookie): string {
if (cookie.domain === 'NotPresent' || cookie.domain === 'Empty') {
return 'n/a';
@@ -80,13 +55,6 @@ export function cookieDomain(cookie: Cookie): string {
return 'unknown';
}
export interface KeyValue extends Omit<BaseModel, 'id'> {
readonly model: 'key_value';
readonly key: string;
readonly namespace: string;
value: string;
}
export function isResponseLoading(response: HttpResponse | GrpcConnection): boolean {
return response.elapsed === 0;
}
@@ -101,6 +69,6 @@ export function modelsEq(a: Model, b: Model) {
return false;
}
export function getContentTypeHeader(headers: HttpHeader[]): string | null {
export function getContentTypeHeader(headers: HttpResponseHeader[]): string | null {
return headers.find((h) => h.name.toLowerCase() === 'content-type')?.value ?? null;
}

View File

@@ -1,5 +1,5 @@
import { readFile, readTextFile } from '@tauri-apps/plugin-fs';
import type { HttpResponse } from './models';
import type { HttpResponse } from '@yaakapp/api';
export async function getResponseBodyText(response: HttpResponse): Promise<string | null> {
if (response.bodyPath) {

View File

@@ -1,4 +1,4 @@
import type { HttpRequest, HttpResponse } from './models';
import type { HttpRequest, HttpResponse } from '@yaakapp/api';
import { invokeCmd } from './tauri';
export async function sendEphemeralRequest(

View File

@@ -1,12 +1,6 @@
import type {
CookieJar,
Environment,
Folder,
GrpcRequest,
HttpRequest,
Settings,
Workspace,
} from './models';
import type { Environment, Folder, GrpcRequest, HttpRequest, Workspace } from '@yaakapp/api';
import type { CookieJar } from './gen/CookieJar';
import type { Settings } from './gen/Settings';
import { invokeCmd } from './tauri';
export async function getSettings(): Promise<Settings> {