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 { g } from "utils/global";
|
||||||
import { baseTypings } from "../../web/src/utils/script/types/base";
|
import { baseTypings } from "../../web/src/utils/script/types/base";
|
||||||
import { dir } from "dir";
|
import { dir } from "dir";
|
||||||
|
import { prismaExtendType } from "../../web/src/utils/script/prisma-extend";
|
||||||
|
|
||||||
export const _ = {
|
export const _ = {
|
||||||
url: "/code/:site_id/:action",
|
url: "/code/:site_id/:action",
|
||||||
|
|
@ -60,7 +61,7 @@ import type * as SRVAPI from "${apiPath}";
|
||||||
)}
|
)}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
const db: prisma.PrismaClient;
|
const db: prisma.PrismaClient & ${prismaExtendType};
|
||||||
${baseTypings}
|
${baseTypings}
|
||||||
${iftext(
|
${iftext(
|
||||||
apiPath,
|
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 { dirAsync } from "fs-jetpack";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { gunzipAsync } from "../entity/zlib";
|
import { gunzipAsync } from "../entity/zlib";
|
||||||
|
import { prismaExtendType } from "../../../../web/src/utils/script/prisma-extend";
|
||||||
|
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
const code_startup = {
|
const code_startup = {
|
||||||
|
|
@ -104,14 +105,13 @@ export const code_action: SAction["code"]["action"] = async function (
|
||||||
);
|
);
|
||||||
await Bun.write(
|
await Bun.write(
|
||||||
Bun.file(path.join(dir, "global.d.ts")),
|
Bun.file(path.join(dir, "global.d.ts")),
|
||||||
`\
|
`//@ts-ignore
|
||||||
import type * as SRVAPI from "gen/srv/api/srv";
|
import type * as SRVAPI from "gen/srv/api/srv";
|
||||||
|
|
||||||
import { Server, WebSocketHandler } from "bun";
|
import { Server, WebSocketHandler } from "bun";
|
||||||
import prisma from "./prisma";
|
import prisma from "./prisma";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
const db: prisma.PrismaClient;
|
const db: prisma.PrismaClient & ${prismaExtendType};
|
||||||
|
|
||||||
type Api = typeof SRVAPI;
|
type Api = typeof SRVAPI;
|
||||||
type ApiName = keyof Api;
|
type ApiName = keyof Api;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,44 @@ export const dbProxy = (dburl: string) => {
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
get(_, table: 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("$")) {
|
if (table.startsWith("$")) {
|
||||||
return (...params: any[]) => {
|
return (...params: any[]) => {
|
||||||
return fetchSendDb(
|
return fetchSendDb(
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export const EdScriptSnippet: FC<{}> = ({}) => {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
p.script.do_edit(
|
p.script.do_edit(
|
||||||
`\
|
`\
|
||||||
<div {...props}>
|
<div {...props} className={cx(props.className, "")}>
|
||||||
<Local
|
<Local
|
||||||
name="local"
|
name="local"
|
||||||
value={
|
value={
|
||||||
|
|
@ -59,7 +59,7 @@ effect={async (local) => {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
p.script.do_edit(
|
p.script.do_edit(
|
||||||
`\
|
`\
|
||||||
<div {...props}>
|
<div {...props} className={cx(props.className, "")}>
|
||||||
{[].map((item, idx) => (
|
{[].map((item, idx) => (
|
||||||
<Fragment key={idx}>
|
<Fragment key={idx}>
|
||||||
<PassProp item={item} children={children} />
|
<PassProp item={item} children={children} />
|
||||||
|
|
@ -78,7 +78,7 @@ effect={async (local) => {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
p.script.do_edit(
|
p.script.do_edit(
|
||||||
`\
|
`\
|
||||||
<>{true && <div {...props}>{children}</div>}</>
|
<>{true && <div {...props} className={cx(props.className, "")}>{children}</div>}</>
|
||||||
`,
|
`,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
@ -96,10 +96,10 @@ effect={async (local) => {
|
||||||
/**if condition */
|
/**if condition */
|
||||||
true ? (
|
true ? (
|
||||||
/** then */
|
/** then */
|
||||||
<div {...props}>{children}</div>
|
<div {...props} className={cx(props.className, "")}>{children}</div>
|
||||||
) : (
|
) : (
|
||||||
/** else */
|
/** 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 { PG } from "../../../logic/global";
|
||||||
import { extractProp } from "./types/prop";
|
import { extractProp } from "./types/prop";
|
||||||
import { baseTypings } from "../../../../../utils/script/types/base";
|
import { baseTypings } from "../../../../../utils/script/types/base";
|
||||||
|
import { prismaExtendType } from "../../../../../utils/script/prisma-extend";
|
||||||
export type MonacoEditor = Parameters<OnMount>[0];
|
export type MonacoEditor = Parameters<OnMount>[0];
|
||||||
type Monaco = Parameters<OnMount>[1];
|
type Monaco = Parameters<OnMount>[1];
|
||||||
|
|
||||||
|
|
@ -112,7 +113,7 @@ import type * as SRVAPI from "${apiPath}";`
|
||||||
)}
|
)}
|
||||||
|
|
||||||
declare global {;
|
declare global {;
|
||||||
const db: prisma.PrismaClient;
|
const db: prisma.PrismaClient & ${prismaExtendType};
|
||||||
|
|
||||||
${baseTypings}
|
${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 { w } from "../types/general";
|
||||||
import { baseTypings } from "./types/base";
|
import { baseTypings } from "./types/base";
|
||||||
import { extractProp } from "./types/prop";
|
import { extractProp } from "./types/prop";
|
||||||
|
import { prismaExtendType } from "./prisma-extend";
|
||||||
export type MonacoEditor = Parameters<OnMount>[0];
|
export type MonacoEditor = Parameters<OnMount>[0];
|
||||||
type Monaco = Parameters<OnMount>[1];
|
type Monaco = Parameters<OnMount>[1];
|
||||||
|
|
||||||
|
|
@ -120,7 +121,7 @@ import type * as SRVAPI from "${apiPath}";`
|
||||||
)}
|
)}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
const db: prisma.PrismaClient;
|
const db: prisma.PrismaClient & ${prismaExtendType};
|
||||||
|
|
||||||
${baseTypings}
|
${baseTypings}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ export const serveStatic = {
|
||||||
watch(dir.path(`app/static`), async (_, filename) => {
|
watch(dir.path(`app/static`), async (_, filename) => {
|
||||||
if (filename) {
|
if (filename) {
|
||||||
const path = join("static", filename);
|
const path = join("static", filename);
|
||||||
|
try {
|
||||||
const file = Bun.file(dir.path(`app/${path}`));
|
const file = Bun.file(dir.path(`app/${path}`));
|
||||||
if (await file.exists()) {
|
if (await file.exists()) {
|
||||||
cache.static[`/${filename}`] = {
|
cache.static[`/${filename}`] = {
|
||||||
|
|
@ -65,6 +66,9 @@ export const serveStatic = {
|
||||||
content: await file.arrayBuffer(),
|
content: await file.arrayBuffer(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
} catch (e: any) {
|
||||||
|
cache.static = {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ export const parcelBuild = async () => {
|
||||||
let decoded = false;
|
let decoded = false;
|
||||||
(async () => {
|
(async () => {
|
||||||
if (parcel.stdout) {
|
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("✨")) {
|
if (!decoded && decoder.decode(chunk).includes("✨")) {
|
||||||
resolve();
|
resolve();
|
||||||
decoded = true;
|
decoded = true;
|
||||||
|
|
@ -45,7 +45,7 @@ export const parcelBuild = async () => {
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
if (parcel.stderr) {
|
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);
|
if (output) process.stderr.write(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue