56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
// Mirror of `maestro-protocol::routes`. Keep in sync with
|
|
// crates/maestro-protocol/src/routes.rs.
|
|
|
|
import type { Uuid } from "./types.js";
|
|
|
|
export const API_PREFIX = "/api";
|
|
|
|
export const SESSIONS = "/api/sessions";
|
|
export const INFO = "/api/info";
|
|
export const DIRS = "/api/dirs";
|
|
export const RECENT_DIRS = "/api/recent-dirs";
|
|
export const PROJECTS = "/api/projects";
|
|
export const GITROOT = "/api/gitroot";
|
|
export const NAMES = "/api/names";
|
|
export const BRANCHES = "/api/branches";
|
|
export const WORKTREES = "/api/worktrees";
|
|
export const EVENTS = "/api/events";
|
|
|
|
/** Name of the query parameter `DIRS` and `GITROOT` both take. */
|
|
export const PATH_QUERY = "path";
|
|
|
|
/** Name of the query parameter `NAMES` takes. */
|
|
export const COUNT_QUERY = "count";
|
|
|
|
export function session(id: Uuid): string {
|
|
return `${SESSIONS}/${encodeURIComponent(id)}`;
|
|
}
|
|
|
|
export function attach(id: Uuid): string {
|
|
return `${API_PREFIX}/attach/${encodeURIComponent(id)}`;
|
|
}
|
|
|
|
/** `DELETE /api/worktrees/:id` — reclaim one retained worktree (#80). */
|
|
export function worktree(id: Uuid): string {
|
|
return `${WORKTREES}/${encodeURIComponent(id)}`;
|
|
}
|
|
|
|
/** Append the `path` query parameter `DIRS` and `GITROOT` accept. */
|
|
export function withPathQuery(route: string, value: string): string {
|
|
return `${route}?${PATH_QUERY}=${encodeURIComponent(value)}`;
|
|
}
|
|
|
|
/** Same-origin WebSocket base — `wss:` under TLS, `ws:` otherwise. */
|
|
export function wsBase(): string {
|
|
const proto = location.protocol === "https:" ? "wss:" : "ws:";
|
|
return `${proto}//${location.host}`;
|
|
}
|
|
|
|
export function eventsWsUrl(): string {
|
|
return `${wsBase()}${EVENTS}`;
|
|
}
|
|
|
|
export function attachWsUrl(id: Uuid): string {
|
|
return `${wsBase()}${attach(id)}`;
|
|
}
|