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",
|
||||||
|
|
@ -52,24 +53,24 @@ import {
|
||||||
} from "react";
|
} from "react";
|
||||||
import * as prisma from "./prisma";
|
import * as prisma from "./prisma";
|
||||||
${iftext(
|
${iftext(
|
||||||
apiPath,
|
apiPath,
|
||||||
`\
|
`\
|
||||||
import "./api-types";
|
import "./api-types";
|
||||||
import type * as SRVAPI from "${apiPath}";
|
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,
|
||||||
`\
|
`\
|
||||||
type Api = typeof SRVAPI;
|
type Api = typeof SRVAPI;
|
||||||
type ApiName = keyof Api;
|
type ApiName = keyof Api;
|
||||||
const api: { [k in ApiName]: Awaited<Api[k]["handler"]>["_"]["api"] };
|
const api: { [k in ApiName]: Awaited<Api[k]["handler"]>["_"]["api"] };
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
}
|
}
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
|
||||||
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 = {
|
||||||
|
|
@ -80,7 +81,7 @@ export const code_action: SAction["code"]["action"] = async function (
|
||||||
) {
|
) {
|
||||||
return { type: "check-typings", hash: true };
|
return { type: "check-typings", hash: true };
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) { }
|
||||||
return { type: "check-typings", hash: false };
|
return { type: "check-typings", hash: false };
|
||||||
}
|
}
|
||||||
case "push-typings": {
|
case "push-typings": {
|
||||||
|
|
@ -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>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</>
|
</>
|
||||||
|
|
@ -107,7 +107,7 @@ true ? (
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<If Else />
|
<If Else />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
|
|
||||||
|
|
@ -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];
|
||||||
|
|
||||||
|
|
@ -47,9 +48,9 @@ declare module "ts:runtime/library" {
|
||||||
`\
|
`\
|
||||||
declare module "ts:prisma" {
|
declare module "ts:prisma" {
|
||||||
${prisma["prisma.d.ts"].replace(
|
${prisma["prisma.d.ts"].replace(
|
||||||
`import * as runtime from './runtime/library.js';`,
|
`import * as runtime from './runtime/library.js';`,
|
||||||
`import * as runtime from 'ts:runtime/library';`
|
`import * as runtime from 'ts:runtime/library';`
|
||||||
)}
|
)}
|
||||||
}`,
|
}`,
|
||||||
`ts:prisma.d.ts`
|
`ts:prisma.d.ts`
|
||||||
);
|
);
|
||||||
|
|
@ -105,27 +106,27 @@ import {
|
||||||
import prisma from 'ts:prisma';
|
import prisma from 'ts:prisma';
|
||||||
|
|
||||||
${iftext(
|
${iftext(
|
||||||
apiTypes,
|
apiTypes,
|
||||||
`\
|
`\
|
||||||
import "./api"
|
import "./api"
|
||||||
import type * as SRVAPI from "${apiPath}";`
|
import type * as SRVAPI from "${apiPath}";`
|
||||||
)}
|
)}
|
||||||
|
|
||||||
declare global {;
|
declare global {;
|
||||||
const db: prisma.PrismaClient;
|
const db: prisma.PrismaClient & ${prismaExtendType};
|
||||||
|
|
||||||
${baseTypings}
|
${baseTypings}
|
||||||
|
|
||||||
${propText.join("\n")}
|
${propText.join("\n")}
|
||||||
|
|
||||||
${iftext(
|
${iftext(
|
||||||
apiTypes,
|
apiTypes,
|
||||||
`
|
`
|
||||||
type Api = typeof SRVAPI;
|
type Api = typeof SRVAPI;
|
||||||
type ApiName = keyof Api;
|
type ApiName = keyof Api;
|
||||||
const api: { [k in ApiName]: Awaited<Api[k]["handler"]>["_"]["api"] };
|
const api: { [k in ApiName]: Awaited<Api[k]["handler"]>["_"]["api"] };
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
}
|
}
|
||||||
|
|
||||||
`,
|
`,
|
||||||
|
|
|
||||||
|
|
@ -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];
|
||||||
|
|
||||||
|
|
@ -51,14 +52,14 @@ declare module "ts:runtime/library" {
|
||||||
`\
|
`\
|
||||||
declare module "ts:prisma" {
|
declare module "ts:prisma" {
|
||||||
${prisma["prisma.d.ts"]
|
${prisma["prisma.d.ts"]
|
||||||
.replace(
|
.replace(
|
||||||
`import * as runtime from './runtime/library.js';`,
|
`import * as runtime from './runtime/library.js';`,
|
||||||
`import * as runtime from 'ts:runtime/library';`
|
`import * as runtime from 'ts:runtime/library';`
|
||||||
)
|
)
|
||||||
.replace(
|
.replace(
|
||||||
`import * as runtime from './runtime/library';`,
|
`import * as runtime from './runtime/library';`,
|
||||||
`import * as runtime from 'ts:runtime/library';`
|
`import * as runtime from 'ts:runtime/library';`
|
||||||
)}
|
)}
|
||||||
}`,
|
}`,
|
||||||
`ts:prisma.d.ts`
|
`ts:prisma.d.ts`
|
||||||
);
|
);
|
||||||
|
|
@ -113,27 +114,27 @@ import {
|
||||||
import prisma from 'ts:prisma';
|
import prisma from 'ts:prisma';
|
||||||
|
|
||||||
${iftext(
|
${iftext(
|
||||||
apiTypes,
|
apiTypes,
|
||||||
`\
|
`\
|
||||||
import "./api"
|
import "./api"
|
||||||
import type * as SRVAPI from "${apiPath}";`
|
import type * as SRVAPI from "${apiPath}";`
|
||||||
)}
|
)}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
const db: prisma.PrismaClient;
|
const db: prisma.PrismaClient & ${prismaExtendType};
|
||||||
|
|
||||||
${baseTypings}
|
${baseTypings}
|
||||||
|
|
||||||
${propText.join("\n")}
|
${propText.join("\n")}
|
||||||
|
|
||||||
${iftext(
|
${iftext(
|
||||||
apiTypes,
|
apiTypes,
|
||||||
`
|
`
|
||||||
type Api = typeof SRVAPI;
|
type Api = typeof SRVAPI;
|
||||||
type ApiName = keyof Api;
|
type ApiName = keyof Api;
|
||||||
const api: { [k in ApiName]: Awaited<Api[k]["handler"]>["_"]["api"] };
|
const api: { [k in ApiName]: Awaited<Api[k]["handler"]>["_"]["api"] };
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
}
|
}
|
||||||
|
|
||||||
`,
|
`,
|
||||||
|
|
|
||||||
|
|
@ -57,13 +57,17 @@ 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);
|
||||||
const file = Bun.file(dir.path(`app/${path}`));
|
try {
|
||||||
if (await file.exists()) {
|
const file = Bun.file(dir.path(`app/${path}`));
|
||||||
cache.static[`/${filename}`] = {
|
if (await file.exists()) {
|
||||||
type: mime.getType(path) || "application/octet-stream",
|
cache.static[`/${filename}`] = {
|
||||||
compression: g.mode === "prod" ? "br" : "",
|
type: mime.getType(path) || "application/octet-stream",
|
||||||
content: await file.arrayBuffer(),
|
compression: g.mode === "prod" ? "br" : "",
|
||||||
};
|
content: await file.arrayBuffer(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (e: any) {
|
||||||
|
cache.static = {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -77,7 +81,7 @@ export const serveStatic = {
|
||||||
if (file) {
|
if (file) {
|
||||||
return new Response(file.content, {
|
return new Response(file.content, {
|
||||||
headers: {
|
headers: {
|
||||||
...CORS_HEADERS,
|
...CORS_HEADERS,
|
||||||
...{ "content-type": file.type },
|
...{ "content-type": file.type },
|
||||||
...(file.compression ? { "content-encoding": file.compression } : {}),
|
...(file.compression ? { "content-encoding": file.compression } : {}),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -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