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/js/compose.mjs
2023-11-25 00:45:54 +01:00

47 lines
No EOL
1 KiB
JavaScript

/**
* Checks if a specificied source is a valid arion-compose.nix file
* @param {string} source Source to check
* @returns {Promise<CheckResult>} Result of the check
*/
export async function check_compose(source) {
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() };
}
}
/**
* @typedef {Object} APIError
* @property {string} code - Error code
*/
/**
* @typedef {Object} CheckSuccess
* @property { true } ok - Indicates that the check was successful
* /
/**
* @typedef {Object} APIError
* @property {string} code - Unique error code
* @property {string} message - Human readable error details
*/
/**
* @typedef {Object} CheckFailure
* @property {false} ok - Indicates that the check has failed
* @property {APIError} error - Info about the encountered error
*/
/**
* @typedef {CheckSuccess | CheckFailure} CheckResult
*/