Skeleton, REST core, variables and JSON editor (M0–M2)

- knock-core: YAML collection format with unknown-field round trip,
  variable resolution across scopes with secrets and dynamic values,
  HTTP engine with manual redirects, cookie jar and large-body spill,
  basic/bearer/API key auth with debug output, assertions and extracts
- Tauri app: collection commands, file watcher, SQLite history,
  keyring-backed secrets
- Svelte UI: sidebar tree, tabs, request editor, response viewer,
  JSON form/code editor with schema hints, environments, settings
This commit is contained in:
2026-11-27 16:42:31 +01:00
commit f6484f4dc8
127 changed files with 22909 additions and 0 deletions
+111
View File
@@ -0,0 +1,111 @@
import { invoke } from '@tauri-apps/api/core';
import type {
CollectionView,
CookieInfo,
Environment,
FolderMeta,
HistoryEntry,
Manifest,
Preview,
Request,
SendResult,
VarInfo
} from './types';
export interface ScopeArgs {
col: string | null;
request_id: string | null;
request: Request;
env: string | null;
}
interface EditResult {
id: string;
collection: CollectionView;
}
export const api = {
collectionOpen: (path: string) => invoke<CollectionView>('collection_open', { path }),
collectionCreate: (path: string, name: string) =>
invoke<CollectionView>('collection_create', { path, name }),
collectionGet: (id: string) => invoke<CollectionView>('collection_get', { id }),
collectionClose: (id: string) => invoke<void>('collection_close', { id }),
recent: () => invoke<string[]>('recent_collections'),
recentForget: (path: string) => invoke<void>('recent_forget', { path }),
requestGet: (col: string, id: string) => invoke<Request>('request_get', { col, id }),
requestSave: (col: string, id: string, request: Request) =>
invoke<CollectionView>('request_save', { col, id, request }),
requestCreate: (col: string, folder: string, request: Request) =>
invoke<EditResult>('request_create', { col, folder, request }),
folderCreate: (col: string, parent: string, name: string) =>
invoke<EditResult>('folder_create', { col, parent, name }),
rename: (col: string, id: string, name: string) =>
invoke<EditResult>('node_rename', { col, id, name }),
duplicate: (col: string, id: string) => invoke<EditResult>('node_duplicate', { col, id }),
remove: (col: string, id: string) => invoke<CollectionView>('node_delete', { col, id }),
move: (col: string, id: string, folder: string, index: number | null) =>
invoke<EditResult>('node_move', { col, id, folder, index }),
folderGet: (col: string, id: string) => invoke<FolderMeta>('folder_get', { col, id }),
folderSave: (col: string, id: string, meta: FolderMeta) =>
invoke<CollectionView>('folder_save', { col, id, meta }),
manifestGet: (col: string) => invoke<Manifest>('manifest_get', { col }),
manifestSave: (col: string, manifest: Manifest) =>
invoke<CollectionView>('manifest_save', { col, manifest }),
envGet: (col: string, id: string) => invoke<Environment>('env_get', { col, id }),
envSave: (col: string, id: string, env: Environment) =>
invoke<CollectionView>('env_save', { col, id, env }),
envDelete: (col: string, id: string) => invoke<CollectionView>('env_delete', { col, id }),
envSecrets: (col: string, env: string) =>
invoke<{ name: string; source: 'envvar' | 'keyring' | 'file' | null; value: string | null }[]>(
'env_secrets',
{ col, env }
),
secretSet: (
col: string,
env: string | null,
name: string,
value: string | null,
target: 'keyring' | 'file'
) => invoke<void>('secret_set', { col, env, name, value, target }),
varsList: (args: ScopeArgs) =>
invoke<{ vars: VarInfo[]; dynamic: [string, string][] }>('vars_list', { args }),
runtimeList: (col: string | null) => invoke<Record<string, string>>('runtime_list', { col }),
runtimeSet: (col: string | null, name: string, value: string | null, persist: boolean) =>
invoke<void>('runtime_set', { col, name, value, persist }),
globalsGet: () => invoke<Record<string, string>>('globals_get'),
globalsSave: (vars: Record<string, string>) => invoke<void>('globals_save', { vars }),
send: (args: ScopeArgs & { tab: string; history_body_limit: number }) =>
invoke<SendResult>('request_send', { args }),
cancel: (tab: string) => invoke<void>('request_cancel', { tab }),
preview: (args: ScopeArgs) => invoke<Preview>('request_preview', { args }),
responseBody: (id: string) => invoke<ArrayBuffer>('response_body', { id }),
responseSave: (id: string, path: string) => invoke<void>('response_save', { id, path }),
cookies: (col: string) => invoke<CookieInfo[]>('cookies_list', { col }),
cookieDelete: (col: string, c?: { domain: string; path: string; name: string }) =>
invoke<void>('cookie_delete', { col, domain: c?.domain, path: c?.path, name: c?.name }),
history: (query: string, limit?: number) =>
invoke<HistoryEntry[]>('history_list', { query, limit }),
historyGet: (id: number) =>
invoke<{ request: Request; response: SendResult['output']['response']; body_id: string | null }>(
'history_get',
{ id }
),
historyDelete: (id: number | null) => invoke<void>('history_delete', { id }),
settingGet: (key: string) => invoke<string | null>('setting_get', { key }),
settingSet: (key: string, value: string) => invoke<void>('setting_set', { key, value }),
pathParams: (url: string) => invoke<string[]>('path_params', { url }),
version: () => invoke<string>('app_version')
};
export function errorText(e: unknown): string {
if (typeof e === 'string') return e;
if (e instanceof Error) return e.message;
return JSON.stringify(e);
}