This commit is contained in:
Rizky 2024-07-12 18:14:55 +07:00
parent 2d42d9e482
commit a2fe29da7a
3 changed files with 53 additions and 78 deletions

File diff suppressed because one or more lines are too long

View File

@ -4,14 +4,9 @@ import { fetchViaProxy } from "../proxy";
export const loadApiProxyDef = async (_url: string, with_types: boolean) => {
const url = trim(_url, "/");
const raw = await fetchViaProxy(urlPath(url, "/_prasi/_"));
let ver = "";
if (raw && (raw as any).prasi) {
ver = (raw as any).prasi;
}
const base = baseUrl(url);
if (ver === "v2") {
await new Promise<void>((done) => {
const d = document;
const script = d.createElement("script");
@ -37,26 +32,6 @@ export const loadApiProxyDef = async (_url: string, with_types: boolean) => {
done();
}
});
} else {
const apiEntry = await fetch(base + "/_prasi/api-entry");
w.prasiApi[url] = {
apiEntry: (await apiEntry.json()).srv,
};
if (with_types) {
const apiTypes = await fetch(base + "/_prasi/api-types");
w.prasiApi[url].apiTypes = await apiTypes.text();
w.prasiApi[url].prismaTypes = {
"prisma.d.ts": await loadText(`${base}/_prasi/prisma/index.d.ts`),
"runtime/index.d.ts": await loadText(
`${base}/_prasi/prisma/runtime/index.d.ts`
),
"runtime/library.d.ts": await loadText(
`${base}/_prasi/prisma/runtime/library.d.ts`
),
};
}
}
};
const baseUrl = (url: string) => {

View File

@ -9,7 +9,7 @@ export const startDevWatcher = async () => {
await dirAsync(dir.path(`app/srv/api`));
watch(dir.path(`app/srv/api`), async (event, filename) => {
const s = file(dir.path(`app/srv/api/${filename}`));
if (s.size === 0) {
if (s.size === 0 && filename?.endsWith(".ts") && (await s.exists())) {
await Bun.write(
`app/srv/api/${filename}`,
`\