mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-26 19:31:12 +01:00
Model and DB refactor (#61)
- [x] Move from `sqlx` to `rusqlite` - [x] Generate TS types from Rust models
This commit is contained in:
@@ -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 '';
|
||||
|
||||
5
src-web/lib/gen/Cookie.ts
Normal file
5
src-web/lib/gen/Cookie.ts
Normal 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], };
|
||||
3
src-web/lib/gen/CookieDomain.ts
Normal file
3
src-web/lib/gen/CookieDomain.ts
Normal 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";
|
||||
3
src-web/lib/gen/CookieExpires.ts
Normal file
3
src-web/lib/gen/CookieExpires.ts
Normal 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";
|
||||
4
src-web/lib/gen/CookieJar.ts
Normal file
4
src-web/lib/gen/CookieJar.ts
Normal 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>, };
|
||||
3
src-web/lib/gen/Settings.ts
Normal file
3
src-web/lib/gen/Settings.ts
Normal 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, };
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { KeyValue } from './models';
|
||||
import type { KeyValue } from '@yaakapp/api';
|
||||
import { invokeCmd } from './tauri';
|
||||
|
||||
export async function setKeyValue<T>({
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user