2023-09-18 07:53:25 +00:00
|
|
|
import { AquaConfig, Aqua, Call, Input, Path } from "./aqua-api.js";
|
2023-08-09 14:32:27 +00:00
|
|
|
|
|
|
|
function getConfig({
|
|
|
|
constants = [],
|
|
|
|
logLevel = "info",
|
|
|
|
noRelay = false,
|
|
|
|
noXor = false,
|
|
|
|
targetType = "air",
|
|
|
|
tracing = false,
|
|
|
|
}) {
|
|
|
|
return new AquaConfig(
|
|
|
|
logLevel,
|
|
|
|
constants,
|
|
|
|
noXor,
|
|
|
|
noRelay,
|
|
|
|
{
|
|
|
|
ts: "typescript",
|
|
|
|
js: "javascript",
|
|
|
|
air: "air",
|
|
|
|
}[targetType],
|
|
|
|
tracing,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-20 16:56:09 +00:00
|
|
|
async function compile(...args) {
|
|
|
|
try {
|
|
|
|
const res = await Aqua.compile(...args);
|
|
|
|
return res;
|
|
|
|
} catch (error) {
|
|
|
|
if (
|
|
|
|
typeof error === "object" &&
|
|
|
|
error !== null &&
|
|
|
|
"message" in error &&
|
|
|
|
typeof error.message === "string"
|
|
|
|
) {
|
|
|
|
throw new Error(error.message);
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
2023-08-09 14:32:27 +00:00
|
|
|
}
|
|
|
|
|
2023-09-20 16:56:09 +00:00
|
|
|
export function compileFromString({ code, imports = [], ...commonArgs }) {
|
|
|
|
return compile(new Input(code), imports, getConfig(commonArgs));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function compileFromPath({ filePath, imports = [], ...commonArgs }) {
|
|
|
|
return compile(new Path(filePath), imports, getConfig(commonArgs));
|
2023-08-09 14:32:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function compileAquaCallFromString({
|
|
|
|
code,
|
|
|
|
funcCall,
|
|
|
|
data,
|
2023-09-20 16:56:09 +00:00
|
|
|
imports = [],
|
2023-08-09 14:32:27 +00:00
|
|
|
...commonArgs
|
|
|
|
}) {
|
2023-09-20 16:56:09 +00:00
|
|
|
return compile(
|
2023-08-09 14:32:27 +00:00
|
|
|
new Call(funcCall, data, new Input(code)),
|
|
|
|
imports,
|
2023-09-20 16:56:09 +00:00
|
|
|
getConfig(commonArgs),
|
2023-08-09 14:32:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function compileAquaCallFromPath({
|
|
|
|
filePath,
|
|
|
|
funcCall,
|
|
|
|
data,
|
2023-09-20 16:56:09 +00:00
|
|
|
imports = [],
|
2023-08-09 14:32:27 +00:00
|
|
|
...commonArgs
|
|
|
|
}) {
|
2023-09-20 16:56:09 +00:00
|
|
|
return compile(
|
2023-08-09 14:32:27 +00:00
|
|
|
new Call(funcCall, data, new Input(filePath)),
|
|
|
|
imports,
|
2023-09-20 16:56:09 +00:00
|
|
|
getConfig(commonArgs),
|
2023-08-09 14:32:27 +00:00
|
|
|
);
|
|
|
|
}
|