const user = "pomdtr";
const workspace = "scratch";
type Result = {
ok: true;
data: {
items: any[];
};
} | {
ok: false;
error: Error;
};
export async function pipes(sql: string): Promise<Result> {
const origin = "https://pipes.turbot.com";
const pathname = `/api/latest/user/${user}/workspace/${workspace}/query`;
const resp = await fetch(`${origin}${pathname}?sql=${encodeURIComponent(sql)}`, {
headers: {
Authorization: `Bearer ${Deno.env.get("PIPES_TOKEN")}`,
},
});
if (!resp.ok) {
return { ok: false, error: new Error(await resp.text()) };
}
return { ok: true, data: await resp.json() };
}