mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 16:21:25 +02:00
Run oxfmt across repo, add format script and docs
Add .oxfmtignore to skip generated bindings and wasm-pack output. Add npm format script, update DEVELOPMENT.md for Vite+ toolchain, and format all non-generated files with oxfmt. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
export function enableEncryption(workspaceId: string) {
|
||||
return invoke<void>('cmd_enable_encryption', { workspaceId });
|
||||
return invoke<void>("cmd_enable_encryption", { workspaceId });
|
||||
}
|
||||
|
||||
export function revealWorkspaceKey(workspaceId: string) {
|
||||
return invoke<string>('cmd_reveal_workspace_key', { workspaceId });
|
||||
return invoke<string>("cmd_reveal_workspace_key", { workspaceId });
|
||||
}
|
||||
|
||||
export function setWorkspaceKey(args: { workspaceId: string; key: string }) {
|
||||
return invoke<void>('cmd_set_workspace_key', args);
|
||||
return invoke<void>("cmd_set_workspace_key", args);
|
||||
}
|
||||
|
||||
export function disableEncryption(workspaceId: string) {
|
||||
return invoke<void>('cmd_disable_encryption', { workspaceId });
|
||||
return invoke<void>("cmd_disable_encryption", { workspaceId });
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@yaakapp-internal/crypto",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "index.ts"
|
||||
}
|
||||
|
||||
@@ -1,60 +1,66 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { createFastMutation } from '@yaakapp/app/hooks/useFastMutation';
|
||||
import { queryClient } from '@yaakapp/app/lib/queryClient';
|
||||
import { useMemo } from 'react';
|
||||
import { BranchDeleteResult, CloneResult, GitCommit, GitRemote, GitStatusSummary, PullResult, PushResult } from './bindings/gen_git';
|
||||
import { showToast } from '@yaakapp/app/lib/toast';
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { createFastMutation } from "@yaakapp/app/hooks/useFastMutation";
|
||||
import { queryClient } from "@yaakapp/app/lib/queryClient";
|
||||
import { useMemo } from "react";
|
||||
import {
|
||||
BranchDeleteResult,
|
||||
CloneResult,
|
||||
GitCommit,
|
||||
GitRemote,
|
||||
GitStatusSummary,
|
||||
PullResult,
|
||||
PushResult,
|
||||
} from "./bindings/gen_git";
|
||||
import { showToast } from "@yaakapp/app/lib/toast";
|
||||
|
||||
export * from './bindings/gen_git';
|
||||
export * from './bindings/gen_models';
|
||||
export * from "./bindings/gen_git";
|
||||
export * from "./bindings/gen_models";
|
||||
|
||||
export interface GitCredentials {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export type DivergedStrategy = 'force_reset' | 'merge' | 'cancel';
|
||||
export type DivergedStrategy = "force_reset" | "merge" | "cancel";
|
||||
|
||||
export type UncommittedChangesStrategy = 'reset' | 'cancel';
|
||||
export type UncommittedChangesStrategy = "reset" | "cancel";
|
||||
|
||||
export interface GitCallbacks {
|
||||
addRemote: () => Promise<GitRemote | null>;
|
||||
promptCredentials: (
|
||||
result: Extract<PushResult, { type: 'needs_credentials' }>,
|
||||
result: Extract<PushResult, { type: "needs_credentials" }>,
|
||||
) => Promise<GitCredentials | null>;
|
||||
promptDiverged: (
|
||||
result: Extract<PullResult, { type: 'diverged' }>,
|
||||
) => Promise<DivergedStrategy>;
|
||||
promptDiverged: (result: Extract<PullResult, { type: "diverged" }>) => Promise<DivergedStrategy>;
|
||||
promptUncommittedChanges: () => Promise<UncommittedChangesStrategy>;
|
||||
forceSync: () => Promise<void>;
|
||||
}
|
||||
|
||||
const onSuccess = () => queryClient.invalidateQueries({ queryKey: ['git'] });
|
||||
const onSuccess = () => queryClient.invalidateQueries({ queryKey: ["git"] });
|
||||
|
||||
export function useGit(dir: string, callbacks: GitCallbacks, refreshKey?: string) {
|
||||
const mutations = useMemo(() => gitMutations(dir, callbacks), [dir, callbacks]);
|
||||
const fetchAll = useQuery<void, string>({
|
||||
queryKey: ['git', 'fetch_all', dir, refreshKey],
|
||||
queryFn: () => invoke('cmd_git_fetch_all', { dir }),
|
||||
queryKey: ["git", "fetch_all", dir, refreshKey],
|
||||
queryFn: () => invoke("cmd_git_fetch_all", { dir }),
|
||||
refetchInterval: 10 * 60_000,
|
||||
});
|
||||
return [
|
||||
{
|
||||
remotes: useQuery<GitRemote[], string>({
|
||||
queryKey: ['git', 'remotes', dir, refreshKey],
|
||||
queryKey: ["git", "remotes", dir, refreshKey],
|
||||
queryFn: () => getRemotes(dir),
|
||||
placeholderData: (prev) => prev,
|
||||
}),
|
||||
log: useQuery<GitCommit[], string>({
|
||||
queryKey: ['git', 'log', dir, refreshKey],
|
||||
queryFn: () => invoke('cmd_git_log', { dir }),
|
||||
queryKey: ["git", "log", dir, refreshKey],
|
||||
queryFn: () => invoke("cmd_git_log", { dir }),
|
||||
placeholderData: (prev) => prev,
|
||||
}),
|
||||
status: useQuery<GitStatusSummary, string>({
|
||||
refetchOnMount: true,
|
||||
queryKey: ['git', 'status', dir, refreshKey, fetchAll.dataUpdatedAt],
|
||||
queryFn: () => invoke('cmd_git_status', { dir }),
|
||||
queryKey: ["git", "status", dir, refreshKey, fetchAll.dataUpdatedAt],
|
||||
queryFn: () => invoke("cmd_git_status", { dir }),
|
||||
placeholderData: (prev) => prev,
|
||||
}),
|
||||
},
|
||||
@@ -67,151 +73,167 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
const remotes = await getRemotes(dir);
|
||||
if (remotes.length === 0) {
|
||||
const remote = await callbacks.addRemote();
|
||||
if (remote == null) throw new Error('No remote found');
|
||||
if (remote == null) throw new Error("No remote found");
|
||||
}
|
||||
|
||||
const result = await invoke<PushResult>('cmd_git_push', { dir });
|
||||
if (result.type !== 'needs_credentials') return result;
|
||||
const result = await invoke<PushResult>("cmd_git_push", { dir });
|
||||
if (result.type !== "needs_credentials") return result;
|
||||
|
||||
// Needs credentials, prompt for them
|
||||
const creds = await callbacks.promptCredentials(result);
|
||||
if (creds == null) throw new Error('Canceled');
|
||||
if (creds == null) throw new Error("Canceled");
|
||||
|
||||
await invoke('cmd_git_add_credential', {
|
||||
await invoke("cmd_git_add_credential", {
|
||||
remoteUrl: result.url,
|
||||
username: creds.username,
|
||||
password: creds.password,
|
||||
});
|
||||
|
||||
// Push again
|
||||
return invoke<PushResult>('cmd_git_push', { dir });
|
||||
return invoke<PushResult>("cmd_git_push", { dir });
|
||||
};
|
||||
|
||||
const handleError = (err: unknown) => {
|
||||
showToast({
|
||||
id: err instanceof Error ? err.message : String(err),
|
||||
message: err instanceof Error ? err.message : String(err),
|
||||
color: 'danger',
|
||||
color: "danger",
|
||||
timeout: 5000,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
init: createFastMutation<void, string, void>({
|
||||
mutationKey: ['git', 'init'],
|
||||
mutationFn: () => invoke('cmd_git_initialize', { dir }),
|
||||
mutationKey: ["git", "init"],
|
||||
mutationFn: () => invoke("cmd_git_initialize", { dir }),
|
||||
onSuccess,
|
||||
}),
|
||||
add: createFastMutation<void, string, { relaPaths: string[] }>({
|
||||
mutationKey: ['git', 'add', dir],
|
||||
mutationFn: (args) => invoke('cmd_git_add', { dir, ...args }),
|
||||
mutationKey: ["git", "add", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_add", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
addRemote: createFastMutation<GitRemote, string, GitRemote>({
|
||||
mutationKey: ['git', 'add-remote'],
|
||||
mutationFn: (args) => invoke('cmd_git_add_remote', { dir, ...args }),
|
||||
mutationKey: ["git", "add-remote"],
|
||||
mutationFn: (args) => invoke("cmd_git_add_remote", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
rmRemote: createFastMutation<void, string, { name: string }>({
|
||||
mutationKey: ['git', 'rm-remote', dir],
|
||||
mutationFn: (args) => invoke('cmd_git_rm_remote', { dir, ...args }),
|
||||
mutationKey: ["git", "rm-remote", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_rm_remote", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
createBranch: createFastMutation<void, string, { branch: string; base?: string }>({
|
||||
mutationKey: ['git', 'branch', dir],
|
||||
mutationFn: (args) => invoke('cmd_git_branch', { dir, ...args }),
|
||||
mutationKey: ["git", "branch", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_branch", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
mergeBranch: createFastMutation<void, string, { branch: string }>({
|
||||
mutationKey: ['git', 'merge', dir],
|
||||
mutationFn: (args) => invoke('cmd_git_merge_branch', { dir, ...args }),
|
||||
mutationKey: ["git", "merge", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_merge_branch", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
deleteBranch: createFastMutation<BranchDeleteResult, string, { branch: string, force?: boolean }>({
|
||||
mutationKey: ['git', 'delete-branch', dir],
|
||||
mutationFn: (args) => invoke('cmd_git_delete_branch', { dir, ...args }),
|
||||
deleteBranch: createFastMutation<
|
||||
BranchDeleteResult,
|
||||
string,
|
||||
{ branch: string; force?: boolean }
|
||||
>({
|
||||
mutationKey: ["git", "delete-branch", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_delete_branch", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
deleteRemoteBranch: createFastMutation<void, string, { branch: string }>({
|
||||
mutationKey: ['git', 'delete-remote-branch', dir],
|
||||
mutationFn: (args) => invoke('cmd_git_delete_remote_branch', { dir, ...args }),
|
||||
mutationKey: ["git", "delete-remote-branch", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_delete_remote_branch", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
renameBranch: createFastMutation<void, string, { oldName: string, newName: string }>({
|
||||
mutationKey: ['git', 'rename-branch', dir],
|
||||
mutationFn: (args) => invoke('cmd_git_rename_branch', { dir, ...args }),
|
||||
renameBranch: createFastMutation<void, string, { oldName: string; newName: string }>({
|
||||
mutationKey: ["git", "rename-branch", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_rename_branch", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
checkout: createFastMutation<string, string, { branch: string; force: boolean }>({
|
||||
mutationKey: ['git', 'checkout', dir],
|
||||
mutationFn: (args) => invoke('cmd_git_checkout', { dir, ...args }),
|
||||
mutationKey: ["git", "checkout", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_checkout", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
commit: createFastMutation<void, string, { message: string }>({
|
||||
mutationKey: ['git', 'commit', dir],
|
||||
mutationFn: (args) => invoke('cmd_git_commit', { dir, ...args }),
|
||||
mutationKey: ["git", "commit", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_commit", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
commitAndPush: createFastMutation<PushResult, string, { message: string }>({
|
||||
mutationKey: ['git', 'commit_push', dir],
|
||||
mutationKey: ["git", "commit_push", dir],
|
||||
mutationFn: async (args) => {
|
||||
await invoke('cmd_git_commit', { dir, ...args });
|
||||
await invoke("cmd_git_commit", { dir, ...args });
|
||||
return push();
|
||||
},
|
||||
onSuccess,
|
||||
}),
|
||||
|
||||
push: createFastMutation<PushResult, string, void>({
|
||||
mutationKey: ['git', 'push', dir],
|
||||
mutationKey: ["git", "push", dir],
|
||||
mutationFn: push,
|
||||
onSuccess,
|
||||
}),
|
||||
pull: createFastMutation<PullResult, string, void>({
|
||||
mutationKey: ['git', 'pull', dir],
|
||||
mutationKey: ["git", "pull", dir],
|
||||
async mutationFn() {
|
||||
const result = await invoke<PullResult>('cmd_git_pull', { dir });
|
||||
const result = await invoke<PullResult>("cmd_git_pull", { dir });
|
||||
|
||||
if (result.type === 'needs_credentials') {
|
||||
if (result.type === "needs_credentials") {
|
||||
const creds = await callbacks.promptCredentials(result);
|
||||
if (creds == null) throw new Error('Canceled');
|
||||
if (creds == null) throw new Error("Canceled");
|
||||
|
||||
await invoke('cmd_git_add_credential', {
|
||||
await invoke("cmd_git_add_credential", {
|
||||
remoteUrl: result.url,
|
||||
username: creds.username,
|
||||
password: creds.password,
|
||||
});
|
||||
|
||||
// Pull again after credentials
|
||||
return invoke<PullResult>('cmd_git_pull', { dir });
|
||||
return invoke<PullResult>("cmd_git_pull", { dir });
|
||||
}
|
||||
|
||||
if (result.type === 'uncommitted_changes') {
|
||||
void callbacks.promptUncommittedChanges().then(async (strategy) => {
|
||||
if (strategy === 'cancel') return;
|
||||
if (result.type === "uncommitted_changes") {
|
||||
void callbacks
|
||||
.promptUncommittedChanges()
|
||||
.then(async (strategy) => {
|
||||
if (strategy === "cancel") return;
|
||||
|
||||
await invoke('cmd_git_reset_changes', { dir });
|
||||
return invoke<PullResult>('cmd_git_pull', { dir });
|
||||
}).then(async () => { await onSuccess(); await callbacks.forceSync(); }, handleError);
|
||||
await invoke("cmd_git_reset_changes", { dir });
|
||||
return invoke<PullResult>("cmd_git_pull", { dir });
|
||||
})
|
||||
.then(async () => {
|
||||
await onSuccess();
|
||||
await callbacks.forceSync();
|
||||
}, handleError);
|
||||
}
|
||||
|
||||
if (result.type === 'diverged') {
|
||||
void callbacks.promptDiverged(result).then((strategy) => {
|
||||
if (strategy === 'cancel') return;
|
||||
if (result.type === "diverged") {
|
||||
void callbacks
|
||||
.promptDiverged(result)
|
||||
.then((strategy) => {
|
||||
if (strategy === "cancel") return;
|
||||
|
||||
if (strategy === 'force_reset') {
|
||||
return invoke<PullResult>('cmd_git_pull_force_reset', {
|
||||
if (strategy === "force_reset") {
|
||||
return invoke<PullResult>("cmd_git_pull_force_reset", {
|
||||
dir,
|
||||
remote: result.remote,
|
||||
branch: result.branch,
|
||||
});
|
||||
}
|
||||
|
||||
return invoke<PullResult>("cmd_git_pull_merge", {
|
||||
dir,
|
||||
remote: result.remote,
|
||||
branch: result.branch,
|
||||
});
|
||||
}
|
||||
|
||||
return invoke<PullResult>('cmd_git_pull_merge', {
|
||||
dir,
|
||||
remote: result.remote,
|
||||
branch: result.branch,
|
||||
});
|
||||
}).then(async () => { await onSuccess(); await callbacks.forceSync(); }, handleError);
|
||||
})
|
||||
.then(async () => {
|
||||
await onSuccess();
|
||||
await callbacks.forceSync();
|
||||
}, handleError);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -219,20 +241,20 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
onSuccess,
|
||||
}),
|
||||
unstage: createFastMutation<void, string, { relaPaths: string[] }>({
|
||||
mutationKey: ['git', 'unstage', dir],
|
||||
mutationFn: (args) => invoke('cmd_git_unstage', { dir, ...args }),
|
||||
mutationKey: ["git", "unstage", dir],
|
||||
mutationFn: (args) => invoke("cmd_git_unstage", { dir, ...args }),
|
||||
onSuccess,
|
||||
}),
|
||||
resetChanges: createFastMutation<void, string, void>({
|
||||
mutationKey: ['git', 'reset-changes', dir],
|
||||
mutationFn: () => invoke('cmd_git_reset_changes', { dir }),
|
||||
mutationKey: ["git", "reset-changes", dir],
|
||||
mutationFn: () => invoke("cmd_git_reset_changes", { dir }),
|
||||
onSuccess,
|
||||
}),
|
||||
} as const;
|
||||
};
|
||||
|
||||
async function getRemotes(dir: string) {
|
||||
return invoke<GitRemote[]>('cmd_git_remotes', { dir });
|
||||
return invoke<GitRemote[]>("cmd_git_remotes", { dir });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,21 +263,24 @@ async function getRemotes(dir: string) {
|
||||
export async function gitClone(
|
||||
url: string,
|
||||
dir: string,
|
||||
promptCredentials: (args: { url: string; error: string | null }) => Promise<GitCredentials | null>,
|
||||
promptCredentials: (args: {
|
||||
url: string;
|
||||
error: string | null;
|
||||
}) => Promise<GitCredentials | null>,
|
||||
): Promise<CloneResult> {
|
||||
const result = await invoke<CloneResult>('cmd_git_clone', { url, dir });
|
||||
if (result.type !== 'needs_credentials') return result;
|
||||
const result = await invoke<CloneResult>("cmd_git_clone", { url, dir });
|
||||
if (result.type !== "needs_credentials") return result;
|
||||
|
||||
// Prompt for credentials
|
||||
const creds = await promptCredentials({ url: result.url, error: result.error });
|
||||
if (creds == null) return {type: 'cancelled'};
|
||||
if (creds == null) return { type: "cancelled" };
|
||||
|
||||
// Store credentials and retry
|
||||
await invoke('cmd_git_add_credential', {
|
||||
await invoke("cmd_git_add_credential", {
|
||||
remoteUrl: result.url,
|
||||
username: creds.username,
|
||||
password: creds.password,
|
||||
});
|
||||
|
||||
return invoke<CloneResult>('cmd_git_clone', { url, dir });
|
||||
return invoke<CloneResult>("cmd_git_clone", { url, dir });
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@yaakapp-internal/git",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "index.ts"
|
||||
}
|
||||
|
||||
@@ -19,7 +19,12 @@ hyper-util = { version = "0.1.17", default-features = false, features = ["client
|
||||
log = { workspace = true }
|
||||
mime_guess = "2.0.5"
|
||||
regex = "1.11.1"
|
||||
reqwest = { workspace = true, features = ["rustls-tls-manual-roots-no-provider", "socks", "http2", "stream"] }
|
||||
reqwest = { workspace = true, features = [
|
||||
"rustls-tls-manual-roots-no-provider",
|
||||
"socks",
|
||||
"http2",
|
||||
"stream",
|
||||
] }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde_json = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
|
||||
@@ -1,35 +1,39 @@
|
||||
import { atom } from 'jotai';
|
||||
import { atom } from "jotai";
|
||||
|
||||
import { selectAtom } from 'jotai/utils';
|
||||
import type { AnyModel } from '../bindings/gen_models';
|
||||
import { ExtractModel } from './types';
|
||||
import { newStoreData } from './util';
|
||||
import { selectAtom } from "jotai/utils";
|
||||
import type { AnyModel } from "../bindings/gen_models";
|
||||
import { ExtractModel } from "./types";
|
||||
import { newStoreData } from "./util";
|
||||
|
||||
export const modelStoreDataAtom = atom(newStoreData());
|
||||
|
||||
export const cookieJarsAtom = createOrderedModelAtom('cookie_jar', 'name', 'asc');
|
||||
export const environmentsAtom = createOrderedModelAtom('environment', 'sortPriority', 'asc');
|
||||
export const foldersAtom = createModelAtom('folder');
|
||||
export const grpcConnectionsAtom = createOrderedModelAtom('grpc_connection', 'createdAt', 'desc');
|
||||
export const grpcEventsAtom = createOrderedModelAtom('grpc_event', 'createdAt', 'asc');
|
||||
export const grpcRequestsAtom = createModelAtom('grpc_request');
|
||||
export const httpRequestsAtom = createModelAtom('http_request');
|
||||
export const httpResponsesAtom = createOrderedModelAtom('http_response', 'createdAt', 'desc');
|
||||
export const httpResponseEventsAtom = createOrderedModelAtom('http_response_event', 'createdAt', 'asc');
|
||||
export const keyValuesAtom = createModelAtom('key_value');
|
||||
export const pluginsAtom = createModelAtom('plugin');
|
||||
export const settingsAtom = createSingularModelAtom('settings');
|
||||
export const websocketRequestsAtom = createModelAtom('websocket_request');
|
||||
export const websocketEventsAtom = createOrderedModelAtom('websocket_event', 'createdAt', 'asc');
|
||||
export const websocketConnectionsAtom = createOrderedModelAtom(
|
||||
'websocket_connection',
|
||||
'createdAt',
|
||||
'desc',
|
||||
export const cookieJarsAtom = createOrderedModelAtom("cookie_jar", "name", "asc");
|
||||
export const environmentsAtom = createOrderedModelAtom("environment", "sortPriority", "asc");
|
||||
export const foldersAtom = createModelAtom("folder");
|
||||
export const grpcConnectionsAtom = createOrderedModelAtom("grpc_connection", "createdAt", "desc");
|
||||
export const grpcEventsAtom = createOrderedModelAtom("grpc_event", "createdAt", "asc");
|
||||
export const grpcRequestsAtom = createModelAtom("grpc_request");
|
||||
export const httpRequestsAtom = createModelAtom("http_request");
|
||||
export const httpResponsesAtom = createOrderedModelAtom("http_response", "createdAt", "desc");
|
||||
export const httpResponseEventsAtom = createOrderedModelAtom(
|
||||
"http_response_event",
|
||||
"createdAt",
|
||||
"asc",
|
||||
);
|
||||
export const workspaceMetasAtom = createModelAtom('workspace_meta');
|
||||
export const workspacesAtom = createOrderedModelAtom('workspace', 'name', 'asc');
|
||||
export const keyValuesAtom = createModelAtom("key_value");
|
||||
export const pluginsAtom = createModelAtom("plugin");
|
||||
export const settingsAtom = createSingularModelAtom("settings");
|
||||
export const websocketRequestsAtom = createModelAtom("websocket_request");
|
||||
export const websocketEventsAtom = createOrderedModelAtom("websocket_event", "createdAt", "asc");
|
||||
export const websocketConnectionsAtom = createOrderedModelAtom(
|
||||
"websocket_connection",
|
||||
"createdAt",
|
||||
"desc",
|
||||
);
|
||||
export const workspaceMetasAtom = createModelAtom("workspace_meta");
|
||||
export const workspacesAtom = createOrderedModelAtom("workspace", "name", "asc");
|
||||
|
||||
export function createModelAtom<M extends AnyModel['model']>(modelType: M) {
|
||||
export function createModelAtom<M extends AnyModel["model"]>(modelType: M) {
|
||||
return selectAtom(
|
||||
modelStoreDataAtom,
|
||||
(data) => Object.values(data[modelType] ?? {}),
|
||||
@@ -37,19 +41,19 @@ export function createModelAtom<M extends AnyModel['model']>(modelType: M) {
|
||||
);
|
||||
}
|
||||
|
||||
export function createSingularModelAtom<M extends AnyModel['model']>(modelType: M) {
|
||||
export function createSingularModelAtom<M extends AnyModel["model"]>(modelType: M) {
|
||||
return selectAtom(modelStoreDataAtom, (data) => {
|
||||
const modelData = Object.values(data[modelType] ?? {});
|
||||
const item = modelData[0];
|
||||
if (item == null) throw new Error('Failed creating singular model with no data: ' + modelType);
|
||||
if (item == null) throw new Error("Failed creating singular model with no data: " + modelType);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
export function createOrderedModelAtom<M extends AnyModel['model']>(
|
||||
export function createOrderedModelAtom<M extends AnyModel["model"]>(
|
||||
modelType: M,
|
||||
field: keyof ExtractModel<AnyModel, M>,
|
||||
order: 'asc' | 'desc',
|
||||
order: "asc" | "desc",
|
||||
) {
|
||||
return selectAtom(
|
||||
modelStoreDataAtom,
|
||||
@@ -58,7 +62,7 @@ export function createOrderedModelAtom<M extends AnyModel['model']>(
|
||||
return Object.values(modelData).sort(
|
||||
(a: ExtractModel<AnyModel, M>, b: ExtractModel<AnyModel, M>) => {
|
||||
const n = a[field] > b[field] ? 1 : -1;
|
||||
return order === 'desc' ? n * -1 : n;
|
||||
return order === "desc" ? n * -1 : n;
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { AnyModel } from '../bindings/gen_models';
|
||||
import { AnyModel } from "../bindings/gen_models";
|
||||
|
||||
export * from '../bindings/gen_models';
|
||||
export * from '../bindings/gen_util';
|
||||
export * from './store';
|
||||
export * from './atoms';
|
||||
export * from "../bindings/gen_models";
|
||||
export * from "../bindings/gen_util";
|
||||
export * from "./store";
|
||||
export * from "./atoms";
|
||||
|
||||
export function modelTypeLabel(m: AnyModel): string {
|
||||
const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
|
||||
return m.model.split('_').map(capitalize).join(' ');
|
||||
return m.model.split("_").map(capitalize).join(" ");
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
|
||||
import { resolvedModelName } from '@yaakapp/app/lib/resolvedModelName';
|
||||
import { AnyModel, ModelPayload } from '../bindings/gen_models';
|
||||
import { modelStoreDataAtom } from './atoms';
|
||||
import { ExtractModel, JotaiStore, ModelStoreData } from './types';
|
||||
import { newStoreData } from './util';
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import { resolvedModelName } from "@yaakapp/app/lib/resolvedModelName";
|
||||
import { AnyModel, ModelPayload } from "../bindings/gen_models";
|
||||
import { modelStoreDataAtom } from "./atoms";
|
||||
import { ExtractModel, JotaiStore, ModelStoreData } from "./types";
|
||||
import { newStoreData } from "./util";
|
||||
|
||||
let _store: JotaiStore | null = null;
|
||||
|
||||
@@ -12,11 +12,11 @@ export function initModelStore(store: JotaiStore) {
|
||||
_store = store;
|
||||
|
||||
getCurrentWebviewWindow()
|
||||
.listen<ModelPayload>('model_write', ({ payload }) => {
|
||||
.listen<ModelPayload>("model_write", ({ payload }) => {
|
||||
if (shouldIgnoreModel(payload)) return;
|
||||
|
||||
mustStore().set(modelStoreDataAtom, (prev: ModelStoreData) => {
|
||||
if (payload.change.type === 'upsert') {
|
||||
if (payload.change.type === "upsert") {
|
||||
return {
|
||||
...prev,
|
||||
[payload.model.model]: {
|
||||
@@ -36,7 +36,7 @@ export function initModelStore(store: JotaiStore) {
|
||||
|
||||
function mustStore(): JotaiStore {
|
||||
if (_store == null) {
|
||||
throw new Error('Model store was not initialized');
|
||||
throw new Error("Model store was not initialized");
|
||||
}
|
||||
|
||||
return _store;
|
||||
@@ -45,8 +45,8 @@ function mustStore(): JotaiStore {
|
||||
let _activeWorkspaceId: string | null = null;
|
||||
|
||||
export async function changeModelStoreWorkspace(workspaceId: string | null) {
|
||||
console.log('Syncing models with new workspace', workspaceId);
|
||||
const workspaceModelsStr = await invoke<string>('models_workspace_models', {
|
||||
console.log("Syncing models with new workspace", workspaceId);
|
||||
const workspaceModelsStr = await invoke<string>("models_workspace_models", {
|
||||
workspaceId, // NOTE: if no workspace id provided, it will just fetch global models
|
||||
});
|
||||
const workspaceModels = JSON.parse(workspaceModelsStr) as AnyModel[];
|
||||
@@ -57,12 +57,12 @@ export async function changeModelStoreWorkspace(workspaceId: string | null) {
|
||||
|
||||
mustStore().set(modelStoreDataAtom, data);
|
||||
|
||||
console.log('Synced model store with workspace', workspaceId, data);
|
||||
console.log("Synced model store with workspace", workspaceId, data);
|
||||
|
||||
_activeWorkspaceId = workspaceId;
|
||||
}
|
||||
|
||||
export function listModels<M extends AnyModel['model'], T extends ExtractModel<AnyModel, M>>(
|
||||
export function listModels<M extends AnyModel["model"], T extends ExtractModel<AnyModel, M>>(
|
||||
modelType: M | ReadonlyArray<M>,
|
||||
): T[] {
|
||||
let data = mustStore().get(modelStoreDataAtom);
|
||||
@@ -70,7 +70,7 @@ export function listModels<M extends AnyModel['model'], T extends ExtractModel<A
|
||||
return types.flatMap((t) => Object.values(data[t]) as T[]);
|
||||
}
|
||||
|
||||
export function getModel<M extends AnyModel['model'], T extends ExtractModel<AnyModel, M>>(
|
||||
export function getModel<M extends AnyModel["model"], T extends ExtractModel<AnyModel, M>>(
|
||||
modelType: M | ReadonlyArray<M>,
|
||||
id: string,
|
||||
): T | null {
|
||||
@@ -83,9 +83,7 @@ export function getModel<M extends AnyModel['model'], T extends ExtractModel<Any
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getAnyModel(
|
||||
id: string,
|
||||
): AnyModel | null {
|
||||
export function getAnyModel(id: string): AnyModel | null {
|
||||
let data = mustStore().get(modelStoreDataAtom);
|
||||
for (const t of Object.keys(data)) {
|
||||
// oxlint-disable-next-line no-explicit-any
|
||||
@@ -95,7 +93,7 @@ export function getAnyModel(
|
||||
return null;
|
||||
}
|
||||
|
||||
export function patchModelById<M extends AnyModel['model'], T extends ExtractModel<AnyModel, M>>(
|
||||
export function patchModelById<M extends AnyModel["model"], T extends ExtractModel<AnyModel, M>>(
|
||||
model: M,
|
||||
id: string,
|
||||
patch: Partial<T> | ((prev: T) => T),
|
||||
@@ -105,54 +103,54 @@ export function patchModelById<M extends AnyModel['model'], T extends ExtractMod
|
||||
throw new Error(`Failed to get model to patch id=${id} model=${model}`);
|
||||
}
|
||||
|
||||
const newModel = typeof patch === 'function' ? patch(prev) : { ...prev, ...patch };
|
||||
const newModel = typeof patch === "function" ? patch(prev) : { ...prev, ...patch };
|
||||
return updateModel(newModel);
|
||||
}
|
||||
|
||||
export async function patchModel<M extends AnyModel['model'], T extends ExtractModel<AnyModel, M>>(
|
||||
base: Pick<T, 'id' | 'model'>,
|
||||
export async function patchModel<M extends AnyModel["model"], T extends ExtractModel<AnyModel, M>>(
|
||||
base: Pick<T, "id" | "model">,
|
||||
patch: Partial<T>,
|
||||
): Promise<string> {
|
||||
return patchModelById<M, T>(base.model, base.id, patch);
|
||||
}
|
||||
|
||||
export async function updateModel<M extends AnyModel['model'], T extends ExtractModel<AnyModel, M>>(
|
||||
export async function updateModel<M extends AnyModel["model"], T extends ExtractModel<AnyModel, M>>(
|
||||
model: T,
|
||||
): Promise<string> {
|
||||
return invoke<string>('models_upsert', { model });
|
||||
return invoke<string>("models_upsert", { model });
|
||||
}
|
||||
|
||||
export async function deleteModelById<
|
||||
M extends AnyModel['model'],
|
||||
M extends AnyModel["model"],
|
||||
T extends ExtractModel<AnyModel, M>,
|
||||
>(modelType: M | M[], id: string) {
|
||||
let model = getModel<M, T>(modelType, id);
|
||||
await deleteModel(model);
|
||||
}
|
||||
|
||||
export async function deleteModel<M extends AnyModel['model'], T extends ExtractModel<AnyModel, M>>(
|
||||
export async function deleteModel<M extends AnyModel["model"], T extends ExtractModel<AnyModel, M>>(
|
||||
model: T | null,
|
||||
) {
|
||||
if (model == null) {
|
||||
throw new Error('Failed to delete null model');
|
||||
throw new Error("Failed to delete null model");
|
||||
}
|
||||
await invoke<string>('models_delete', { model });
|
||||
await invoke<string>("models_delete", { model });
|
||||
}
|
||||
|
||||
export function duplicateModel<M extends AnyModel['model'], T extends ExtractModel<AnyModel, M>>(
|
||||
export function duplicateModel<M extends AnyModel["model"], T extends ExtractModel<AnyModel, M>>(
|
||||
model: T | null,
|
||||
) {
|
||||
if (model == null) {
|
||||
throw new Error('Failed to duplicate null model');
|
||||
throw new Error("Failed to duplicate null model");
|
||||
}
|
||||
|
||||
// If the model has a name, try to duplicate it with a name that doesn't conflict
|
||||
let name = 'name' in model ? resolvedModelName(model) : undefined;
|
||||
let name = "name" in model ? resolvedModelName(model) : undefined;
|
||||
if (name != null) {
|
||||
const existingModels = listModels(model.model);
|
||||
for (let i = 0; i < 100; i++) {
|
||||
const hasConflict = existingModels.some((m) => {
|
||||
if ('folderId' in m && 'folderId' in model && model.folderId !== m.folderId) {
|
||||
if ("folderId" in m && "folderId" in model && model.folderId !== m.folderId) {
|
||||
return false;
|
||||
} else if (resolvedModelName(m) !== name) {
|
||||
return false;
|
||||
@@ -166,7 +164,7 @@ export function duplicateModel<M extends AnyModel['model'], T extends ExtractMod
|
||||
// Name conflict. Try another one
|
||||
const m: RegExpMatchArray | null = name.match(/ Copy( (?<n>\d+))?$/);
|
||||
if (m != null && m.groups?.n == null) {
|
||||
name = name.substring(0, m.index) + ' Copy 2';
|
||||
name = name.substring(0, m.index) + " Copy 2";
|
||||
} else if (m != null && m.groups?.n != null) {
|
||||
name = name.substring(0, m.index) + ` Copy ${parseInt(m.groups.n) + 1}`;
|
||||
} else {
|
||||
@@ -175,23 +173,23 @@ export function duplicateModel<M extends AnyModel['model'], T extends ExtractMod
|
||||
}
|
||||
}
|
||||
|
||||
return invoke<string>('models_duplicate', { model: { ...model, name } });
|
||||
return invoke<string>("models_duplicate", { model: { ...model, name } });
|
||||
}
|
||||
|
||||
export async function createGlobalModel<T extends Exclude<AnyModel, { workspaceId: string }>>(
|
||||
patch: Partial<T> & Pick<T, 'model'>,
|
||||
patch: Partial<T> & Pick<T, "model">,
|
||||
): Promise<string> {
|
||||
return invoke<string>('models_upsert', { model: patch });
|
||||
return invoke<string>("models_upsert", { model: patch });
|
||||
}
|
||||
|
||||
export async function createWorkspaceModel<T extends Extract<AnyModel, { workspaceId: string }>>(
|
||||
patch: Partial<T> & Pick<T, 'model' | 'workspaceId'>,
|
||||
patch: Partial<T> & Pick<T, "model" | "workspaceId">,
|
||||
): Promise<string> {
|
||||
return invoke<string>('models_upsert', { model: patch });
|
||||
return invoke<string>("models_upsert", { model: patch });
|
||||
}
|
||||
|
||||
export function replaceModelsInStore<
|
||||
M extends AnyModel['model'],
|
||||
M extends AnyModel["model"],
|
||||
T extends Extract<AnyModel, { model: M }>,
|
||||
>(model: M, models: T[]) {
|
||||
const newModels: Record<string, T> = {};
|
||||
@@ -208,7 +206,7 @@ export function replaceModelsInStore<
|
||||
}
|
||||
|
||||
export function mergeModelsInStore<
|
||||
M extends AnyModel['model'],
|
||||
M extends AnyModel["model"],
|
||||
T extends Extract<AnyModel, { model: M }>,
|
||||
>(model: M, models: T[], filter?: (model: T) => boolean) {
|
||||
mustStore().set(modelStoreDataAtom, (prev: ModelStoreData) => {
|
||||
@@ -237,7 +235,7 @@ export function mergeModelsInStore<
|
||||
|
||||
function shouldIgnoreModel({ model, updateSource }: ModelPayload) {
|
||||
// Never ignore updates from non-user sources
|
||||
if (updateSource.type !== 'window') {
|
||||
if (updateSource.type !== "window") {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -247,11 +245,11 @@ function shouldIgnoreModel({ model, updateSource }: ModelPayload) {
|
||||
}
|
||||
|
||||
// Only sync models that belong to this workspace, if a workspace ID is present
|
||||
if ('workspaceId' in model && model.workspaceId !== _activeWorkspaceId) {
|
||||
if ("workspaceId" in model && model.workspaceId !== _activeWorkspaceId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (model.model === 'key_value' && model.namespace === 'no_sync') {
|
||||
if (model.model === "key_value" && model.namespace === "no_sync") {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { createStore } from 'jotai';
|
||||
import { AnyModel } from '../bindings/gen_models';
|
||||
import { createStore } from "jotai";
|
||||
import { AnyModel } from "../bindings/gen_models";
|
||||
|
||||
export type ExtractModel<T, M> = T extends { model: M } ? T : never;
|
||||
export type ModelStoreData<T extends AnyModel = AnyModel> = {
|
||||
[M in T['model']]: Record<string, Extract<T, { model: M }>>;
|
||||
[M in T["model"]]: Record<string, Extract<T, { model: M }>>;
|
||||
};
|
||||
export type JotaiStore = ReturnType<typeof createStore>;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ModelStoreData } from './types';
|
||||
import { ModelStoreData } from "./types";
|
||||
|
||||
export function newStoreData(): ModelStoreData {
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@yaakapp-internal/models",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "guest-js/index.ts"
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse } from './bindings/gen_api';
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse } from "./bindings/gen_api";
|
||||
|
||||
export * from './bindings/gen_models';
|
||||
export * from './bindings/gen_events';
|
||||
export * from './bindings/gen_search';
|
||||
export * from "./bindings/gen_models";
|
||||
export * from "./bindings/gen_events";
|
||||
export * from "./bindings/gen_search";
|
||||
|
||||
export async function searchPlugins(query: string) {
|
||||
return invoke<PluginSearchResponse>('cmd_plugins_search', { query });
|
||||
return invoke<PluginSearchResponse>("cmd_plugins_search", { query });
|
||||
}
|
||||
|
||||
export async function installPlugin(name: string, version: string | null) {
|
||||
return invoke<void>('cmd_plugins_install', { name, version });
|
||||
return invoke<void>("cmd_plugins_install", { name, version });
|
||||
}
|
||||
|
||||
export async function uninstallPlugin(pluginId: string) {
|
||||
return invoke<void>('cmd_plugins_uninstall', { pluginId });
|
||||
return invoke<void>("cmd_plugins_uninstall", { pluginId });
|
||||
}
|
||||
|
||||
export async function checkPluginUpdates() {
|
||||
return invoke<PluginUpdatesResponse>('cmd_plugins_updates', {});
|
||||
return invoke<PluginUpdatesResponse>("cmd_plugins_updates", {});
|
||||
}
|
||||
|
||||
export async function updateAllPlugins() {
|
||||
return invoke<PluginNameVersion[]>('cmd_plugins_update_all', {});
|
||||
return invoke<PluginNameVersion[]>("cmd_plugins_update_all", {});
|
||||
}
|
||||
|
||||
export async function installPluginFromDirectory(directory: string) {
|
||||
return invoke<void>('cmd_plugins_install_from_directory', { directory });
|
||||
return invoke<void>("cmd_plugins_install_from_directory", { directory });
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@yaakapp-internal/plugins",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "index.ts"
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './bindings/sse';
|
||||
export * from "./bindings/sse";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@yaakapp-internal/sse",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "index.ts"
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import { Channel, invoke } from '@tauri-apps/api/core';
|
||||
import { emit } from '@tauri-apps/api/event';
|
||||
import type { WatchResult } from '@yaakapp-internal/tauri';
|
||||
import { SyncOp } from './bindings/gen_sync';
|
||||
import { WatchEvent } from './bindings/gen_watch';
|
||||
import { Channel, invoke } from "@tauri-apps/api/core";
|
||||
import { emit } from "@tauri-apps/api/event";
|
||||
import type { WatchResult } from "@yaakapp-internal/tauri";
|
||||
import { SyncOp } from "./bindings/gen_sync";
|
||||
import { WatchEvent } from "./bindings/gen_watch";
|
||||
|
||||
export * from './bindings/gen_models';
|
||||
export * from "./bindings/gen_models";
|
||||
|
||||
export async function calculateSync(workspaceId: string, syncDir: string) {
|
||||
return invoke<SyncOp[]>('cmd_sync_calculate', {
|
||||
return invoke<SyncOp[]>("cmd_sync_calculate", {
|
||||
workspaceId,
|
||||
syncDir,
|
||||
});
|
||||
}
|
||||
|
||||
export async function calculateSyncFsOnly(dir: string) {
|
||||
return invoke<SyncOp[]>('cmd_sync_calculate_fs', { dir });
|
||||
return invoke<SyncOp[]>("cmd_sync_calculate_fs", { dir });
|
||||
}
|
||||
|
||||
export async function applySync(workspaceId: string, syncDir: string, syncOps: SyncOp[]) {
|
||||
return invoke<void>('cmd_sync_apply', {
|
||||
return invoke<void>("cmd_sync_apply", {
|
||||
workspaceId,
|
||||
syncDir,
|
||||
syncOps: syncOps,
|
||||
@@ -30,10 +30,10 @@ export function watchWorkspaceFiles(
|
||||
syncDir: string,
|
||||
callback: (e: WatchEvent) => void,
|
||||
) {
|
||||
console.log('Watching workspace files', workspaceId, syncDir);
|
||||
console.log("Watching workspace files", workspaceId, syncDir);
|
||||
const channel = new Channel<WatchEvent>();
|
||||
channel.onmessage = callback;
|
||||
const unlistenPromise = invoke<WatchResult>('cmd_sync_watch', {
|
||||
const unlistenPromise = invoke<WatchResult>("cmd_sync_watch", {
|
||||
workspaceId,
|
||||
syncDir,
|
||||
channel,
|
||||
@@ -46,7 +46,7 @@ export function watchWorkspaceFiles(
|
||||
return () =>
|
||||
unlistenPromise
|
||||
.then(async ({ unlistenEvent }) => {
|
||||
console.log('Unwatching workspace files', workspaceId, syncDir);
|
||||
console.log("Unwatching workspace files", workspaceId, syncDir);
|
||||
unlistenToWatcher(unlistenEvent);
|
||||
})
|
||||
.catch(console.error);
|
||||
@@ -59,11 +59,11 @@ function unlistenToWatcher(unlistenEvent: string) {
|
||||
}
|
||||
|
||||
function getWatchKeys() {
|
||||
return sessionStorage.getItem('workspace-file-watchers')?.split(',').filter(Boolean) ?? [];
|
||||
return sessionStorage.getItem("workspace-file-watchers")?.split(",").filter(Boolean) ?? [];
|
||||
}
|
||||
|
||||
function setWatchKeys(keys: string[]) {
|
||||
sessionStorage.setItem('workspace-file-watchers', keys.join(','));
|
||||
sessionStorage.setItem("workspace-file-watchers", keys.join(","));
|
||||
}
|
||||
|
||||
function addWatchKey(key: string) {
|
||||
@@ -79,6 +79,6 @@ function removeWatchKey(key: string) {
|
||||
// On page load, unlisten to all zombie watchers
|
||||
const keys = getWatchKeys();
|
||||
if (keys.length > 0) {
|
||||
console.log('Unsubscribing to zombie file watchers', keys);
|
||||
console.log("Unsubscribing to zombie file watchers", keys);
|
||||
keys.forEach(unlistenToWatcher);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@yaakapp-internal/sync",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "index.ts"
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
const { execSync } = require('node:child_process');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { execSync } = require("node:child_process");
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
if (process.env.SKIP_WASM_BUILD === '1') {
|
||||
console.log('Skipping wasm-pack build (SKIP_WASM_BUILD=1)');
|
||||
if (process.env.SKIP_WASM_BUILD === "1") {
|
||||
console.log("Skipping wasm-pack build (SKIP_WASM_BUILD=1)");
|
||||
return;
|
||||
}
|
||||
|
||||
execSync('wasm-pack build --target bundler', { stdio: 'inherit' });
|
||||
execSync("wasm-pack build --target bundler", { stdio: "inherit" });
|
||||
|
||||
// Rewrite the generated entry to use Vite's ?init import style instead of
|
||||
// the ES Module Integration style that wasm-pack generates, which Vite/rolldown
|
||||
// does not support in production builds.
|
||||
const entry = path.join(__dirname, 'pkg', 'yaak_templates.js');
|
||||
const entry = path.join(__dirname, "pkg", "yaak_templates.js");
|
||||
fs.writeFileSync(
|
||||
entry,
|
||||
[
|
||||
@@ -20,8 +20,8 @@ fs.writeFileSync(
|
||||
'export * from "./yaak_templates_bg.js";',
|
||||
'import * as bg from "./yaak_templates_bg.js";',
|
||||
'const instance = await init({ "./yaak_templates_bg.js": bg });',
|
||||
'bg.__wbg_set_wasm(instance.exports);',
|
||||
'instance.exports.__wbindgen_start();',
|
||||
'',
|
||||
].join('\n'),
|
||||
"bg.__wbg_set_wasm(instance.exports);",
|
||||
"instance.exports.__wbindgen_start();",
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export * from './bindings/parser';
|
||||
import { Tokens } from './bindings/parser';
|
||||
import { escape_template, parse_template, unescape_template } from './pkg';
|
||||
export * from "./bindings/parser";
|
||||
import { Tokens } from "./bindings/parser";
|
||||
import { escape_template, parse_template, unescape_template } from "./pkg";
|
||||
|
||||
export function parseTemplate(template: string) {
|
||||
return parse_template(template) as Tokens;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@yaakapp-internal/templates",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"bootstrap": "npm run build",
|
||||
|
||||
@@ -14,7 +14,10 @@ url = "2"
|
||||
serde_json = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
tokio = { workspace = true, features = ["macros", "time", "test-util", "rt"] }
|
||||
tokio-tungstenite = { version = "0.26.2", default-features = false, features = ["rustls-tls-native-roots", "connect"] }
|
||||
tokio-tungstenite = { version = "0.26.2", default-features = false, features = [
|
||||
"rustls-tls-native-roots",
|
||||
"connect",
|
||||
] }
|
||||
yaak-http = { workspace = true }
|
||||
yaak-tls = { workspace = true }
|
||||
yaak-models = { workspace = true }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { WebsocketConnection } from '@yaakapp-internal/models';
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { WebsocketConnection } from "@yaakapp-internal/models";
|
||||
|
||||
export function deleteWebsocketConnections(requestId: string) {
|
||||
return invoke('cmd_ws_delete_connections', {
|
||||
return invoke("cmd_ws_delete_connections", {
|
||||
requestId,
|
||||
});
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export function connectWebsocket({
|
||||
environmentId: string | null;
|
||||
cookieJarId: string | null;
|
||||
}) {
|
||||
return invoke('cmd_ws_connect', {
|
||||
return invoke("cmd_ws_connect", {
|
||||
requestId,
|
||||
environmentId,
|
||||
cookieJarId,
|
||||
@@ -24,7 +24,7 @@ export function connectWebsocket({
|
||||
}
|
||||
|
||||
export function closeWebsocket({ connectionId }: { connectionId: string }) {
|
||||
return invoke('cmd_ws_close', {
|
||||
return invoke("cmd_ws_close", {
|
||||
connectionId,
|
||||
});
|
||||
}
|
||||
@@ -36,7 +36,7 @@ export function sendWebsocket({
|
||||
connectionId: string;
|
||||
environmentId: string | null;
|
||||
}) {
|
||||
return invoke('cmd_ws_send', {
|
||||
return invoke("cmd_ws_send", {
|
||||
connectionId,
|
||||
environmentId,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@yaakapp-internal/ws",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "index.ts"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user