This commit is contained in:
Rizky 2024-03-07 20:54:39 +07:00
parent f025013315
commit 43c397c743
10 changed files with 157 additions and 78 deletions

View File

@ -5,6 +5,7 @@ import { apiContext } from "../../../pkgs/core/server/api/api-ctx";
import { g } from "utils/global";
import { baseTypings } from "../../web/src/utils/script/types/base";
import { dir } from "dir";
import { prismaExtendType } from "../../web/src/utils/script/prisma-extend";
export const _ = {
url: "/code/:site_id/:action",
@ -57,10 +58,10 @@ ${iftext(
import "./api-types";
import type * as SRVAPI from "${apiPath}";
`
)}
)}
declare global {
const db: prisma.PrismaClient;
const db: prisma.PrismaClient & ${prismaExtendType};
${baseTypings}
${iftext(
apiPath,

File diff suppressed because one or more lines are too long

View File

@ -8,6 +8,7 @@ import { SyncConnection } from "../type";
import { dirAsync } from "fs-jetpack";
import path from "path";
import { gunzipAsync } from "../entity/zlib";
import { prismaExtendType } from "../../../../web/src/utils/script/prisma-extend";
const decoder = new TextDecoder();
const code_startup = {
@ -80,7 +81,7 @@ export const code_action: SAction["code"]["action"] = async function (
) {
return { type: "check-typings", hash: true };
}
} catch (e) {}
} catch (e) { }
return { type: "check-typings", hash: false };
}
case "push-typings": {
@ -104,14 +105,13 @@ export const code_action: SAction["code"]["action"] = async function (
);
await Bun.write(
Bun.file(path.join(dir, "global.d.ts")),
`\
`//@ts-ignore
import type * as SRVAPI from "gen/srv/api/srv";
import { Server, WebSocketHandler } from "bun";
import prisma from "./prisma";
declare global {
const db: prisma.PrismaClient;
const db: prisma.PrismaClient & ${prismaExtendType};
type Api = typeof SRVAPI;
type ApiName = keyof Api;

View File

@ -7,6 +7,44 @@ export const dbProxy = (dburl: string) => {
{},
{
get(_, table: string) {
if (table === "_schema") {
return {
tables: async () => {
return fetchSendDb(
{
name,
action: "schema_tables",
table: "",
params: [],
},
dburl
);
},
columns: async (table: string) => {
return fetchSendDb(
{
name,
action: "schema_columns",
table,
params: [],
},
dburl
);
},
rels: async (table: string) => {
return fetchSendDb(
{
name,
action: "schema_rels",
table,
params: [],
},
dburl
);
},
};
}
if (table.startsWith("$")) {
return (...params: any[]) => {
return fetchSendDb(

View File

@ -19,7 +19,7 @@ export const EdScriptSnippet: FC<{}> = ({}) => {
onClick={() => {
p.script.do_edit(
`\
<div {...props}>
<div {...props} className={cx(props.className, "")}>
<Local
name="local"
value={
@ -59,7 +59,7 @@ effect={async (local) => {
onClick={() => {
p.script.do_edit(
`\
<div {...props}>
<div {...props} className={cx(props.className, "")}>
{[].map((item, idx) => (
<Fragment key={idx}>
<PassProp item={item} children={children} />
@ -78,7 +78,7 @@ effect={async (local) => {
onClick={() => {
p.script.do_edit(
`\
<>{true && <div {...props}>{children}</div>}</>
<>{true && <div {...props} className={cx(props.className, "")}>{children}</div>}</>
`,
true
);
@ -96,10 +96,10 @@ effect={async (local) => {
/**if condition */
true ? (
/** then */
<div {...props}>{children}</div>
<div {...props} className={cx(props.className, "")}>{children}</div>
) : (
/** else */
<div {...props}>ELSE CONDITION</div>
<div {...props} className={cx(props.className, "")}>ELSE CONDITION</div>
)
}
</>

View File

@ -3,6 +3,7 @@ import { w } from "../../../../../utils/types/general";
import { PG } from "../../../logic/global";
import { extractProp } from "./types/prop";
import { baseTypings } from "../../../../../utils/script/types/base";
import { prismaExtendType } from "../../../../../utils/script/prisma-extend";
export type MonacoEditor = Parameters<OnMount>[0];
type Monaco = Parameters<OnMount>[1];
@ -109,10 +110,10 @@ ${iftext(
`\
import "./api"
import type * as SRVAPI from "${apiPath}";`
)}
)}
declare global {;
const db: prisma.PrismaClient;
const db: prisma.PrismaClient & ${prismaExtendType};
${baseTypings}

View File

@ -0,0 +1,34 @@
export const prismaExtendType = `\
{
_schema: {
tables: () => Promise<string[]>;
columns: (table: string) => Promise<
Record<
string,
{
is_pk: boolean;
type: string;
optional: boolean;
db_type: string;
default?: any
}
>
>;
rels: (table: string) => Promise<{
type: 'has-many' | 'has-one';
to: {
table: string,
fields: string[]
};
from: {
table: string,
fields: string[]
}
}>;
}
}`
const rel_types = `\
{
}`

View File

@ -2,6 +2,7 @@ import type { OnMount } from "@monaco-editor/react";
import { w } from "../types/general";
import { baseTypings } from "./types/base";
import { extractProp } from "./types/prop";
import { prismaExtendType } from "./prisma-extend";
export type MonacoEditor = Parameters<OnMount>[0];
type Monaco = Parameters<OnMount>[1];
@ -117,10 +118,10 @@ ${iftext(
`\
import "./api"
import type * as SRVAPI from "${apiPath}";`
)}
)}
declare global {
const db: prisma.PrismaClient;
const db: prisma.PrismaClient & ${prismaExtendType};
${baseTypings}

View File

@ -57,6 +57,7 @@ export const serveStatic = {
watch(dir.path(`app/static`), async (_, filename) => {
if (filename) {
const path = join("static", filename);
try {
const file = Bun.file(dir.path(`app/${path}`));
if (await file.exists()) {
cache.static[`/${filename}`] = {
@ -65,6 +66,9 @@ export const serveStatic = {
content: await file.arrayBuffer(),
};
}
} catch (e: any) {
cache.static = {}
}
}
});
}

View File

@ -33,7 +33,7 @@ export const parcelBuild = async () => {
let decoded = false;
(async () => {
if (parcel.stdout) {
for await (const chunk of parcel.stdout) {
for await (const chunk of parcel.stdout as any) {
if (!decoded && decoder.decode(chunk).includes("✨")) {
resolve();
decoded = true;
@ -45,7 +45,7 @@ export const parcelBuild = async () => {
(async () => {
if (parcel.stderr) {
for await (const chunk of parcel.stderr) {
for await (const chunk of parcel.stderr as any) {
if (output) process.stderr.write(chunk);
}
}