wip fix
This commit is contained in:
parent
f025013315
commit
43c397c743
|
|
@ -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",
|
||||
|
|
@ -60,7 +61,7 @@ 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
|
|
@ -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 = {
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
)
|
||||
}
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
||||
|
|
@ -112,7 +113,7 @@ import type * as SRVAPI from "${apiPath}";`
|
|||
)}
|
||||
|
||||
declare global {;
|
||||
const db: prisma.PrismaClient;
|
||||
const db: prisma.PrismaClient & ${prismaExtendType};
|
||||
|
||||
${baseTypings}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = `\
|
||||
{
|
||||
|
||||
}`
|
||||
|
|
@ -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];
|
||||
|
||||
|
|
@ -120,7 +121,7 @@ import type * as SRVAPI from "${apiPath}";`
|
|||
)}
|
||||
|
||||
declare global {
|
||||
const db: prisma.PrismaClient;
|
||||
const db: prisma.PrismaClient & ${prismaExtendType};
|
||||
|
||||
${baseTypings}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = {}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue