import { rawUrl } from "https://esm.town/v/karfau/rawUrl";
import { raw } from "https://esm.town/v/pomdtr/raw?v=90";
export const getRaw = async (ref: Ref, extension: Ext = "json") => {
const rawExt = ["ts", "md", "json"].includes(extension) ? extension : "json";
const res = await raw(
new Request(rawUrl(ref, rawExt)),
);
if (!res.ok || rawExt !== "json")
return res.text();
const json = await res.json();
return extension !== "json" && extension in json ? json[extension] : json;
};
type Ref = [
user: string,
valName: string,
];
type ValData = {
"id": string;
"author": {
"id": string;
"username": string;
};
"name": string;
"code": string;
"privacy": "public" | "unlisted";
"public": boolean;
"version": number;
"runStartAt": string;
"runEndAt": string;
"logs": string[];
"output": {
"type": string;
"value": string;
};
"error": string | null;
"readme": string | null;
"likeCount": number;
"referenceCount": number;
};
type Ext = "ts" | "json" | "md" | keyof ValData;