staxman-old/static/scripts/compose.ts

37 lines
701 B
TypeScript

/**
* Checks if a specificied source is a valid arion-compose.nix file
* @param source Source to check
* @returns Result of the check
*/
export async function check_compose(source: string): Promise<CheckResult> {
const response = await fetch("/stack/_/check", {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "text/plain",
},
body: source
});
if (response.ok) {
return { ok: true };
} else {
return { ok: false, error: await response.json() };
}
}
export interface APIError {
/** Error code */
code: string;
/** Human readable error details */
message: string;
}
export type CheckResult = {
ok: true;
} | {
ok: false;
error: APIError;
}