This repository has been archived on 2024-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
staxman-old/static/scripts/compose.ts
2023-11-30 10:14:32 +01:00

36 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;
}