fix code
This commit is contained in:
parent
204430878a
commit
9a02b9baa5
File diff suppressed because one or more lines are too long
|
|
@ -16,6 +16,7 @@ import { SyncType } from "../../type";
|
||||||
import { Packr } from "msgpackr";
|
import { Packr } from "msgpackr";
|
||||||
import { ServerWebSocket } from "bun";
|
import { ServerWebSocket } from "bun";
|
||||||
import { WSData } from "../../../../../../pkgs/core/server/create";
|
import { WSData } from "../../../../../../pkgs/core/server/create";
|
||||||
|
import { g } from "utils/global";
|
||||||
|
|
||||||
const packr = new Packr({ structuredClone: true });
|
const packr = new Packr({ structuredClone: true });
|
||||||
|
|
||||||
|
|
@ -143,9 +144,16 @@ if (typeof global.server_hook === "function") {
|
||||||
{
|
{
|
||||||
name: "prasi",
|
name: "prasi",
|
||||||
setup(setup) {
|
setup(setup) {
|
||||||
|
const reinit = () => {
|
||||||
setup.onEnd((res) => {
|
setup.onEnd((res) => {
|
||||||
server.init(id_site);
|
server.init(id_site);
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
if (g.mode === "dev") {
|
||||||
|
setTimeout(reinit, 1000);
|
||||||
|
} else {
|
||||||
|
reinit();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { g } from "utils/global";
|
||||||
import { codeBuild } from "./build-code";
|
import { codeBuild } from "./build-code";
|
||||||
import { CodeMode, code, codeGlobalTypings } from "./util-code";
|
import { CodeMode, code, codeGlobalTypings } from "./util-code";
|
||||||
|
|
||||||
|
|
@ -13,5 +14,6 @@ export const prepCodeSnapshot = async (id_site: string, mode: CodeMode) => {
|
||||||
.await();
|
.await();
|
||||||
|
|
||||||
await codeBuild(id_site);
|
await codeBuild(id_site);
|
||||||
|
|
||||||
return { ts: code.esbuild[id_site].site_ts };
|
return { ts: code.esbuild[id_site].site_ts };
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ export const treeCacheBuild = async (p: PG, page_id: string) => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const item of page_cache.root.childs) {
|
for (const item of page_cache.root.childs) {
|
||||||
meta_cache.entry.push(item.id);
|
meta_cache.entry.push(item.id);
|
||||||
genMeta(
|
genMeta(
|
||||||
|
|
@ -111,11 +112,14 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
if (item) {
|
if (item) {
|
||||||
await initLoadComp({ comps: p.comp.loaded, meta, mode: "page" }, item, {
|
await initLoadComp({ comps: p.comp.loaded, meta, mode: "page" }, item, {
|
||||||
async load(comp_ids) {
|
async load(comp_ids) {
|
||||||
|
console.log(comp_ids.includes("ca7ac237-8f22-4492-bb9d-4b715b1f5c25"))
|
||||||
for (const id of comp_ids) {
|
for (const id of comp_ids) {
|
||||||
await loadComponent(p, id);
|
await loadComponent(p, id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
console.log(p.comp.loaded["ca7ac237-8f22-4492-bb9d-4b715b1f5c25"]);
|
||||||
|
|
||||||
genMeta(
|
genMeta(
|
||||||
{
|
{
|
||||||
note: "tree-rebuild",
|
note: "tree-rebuild",
|
||||||
|
|
|
||||||
|
|
@ -110,16 +110,18 @@ export const EdSidePropInstance: FC<{ meta: IMeta }> = ({ meta }) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const visible_fn = new Function(
|
let visible_fn = null as any;
|
||||||
...Object.keys(arg),
|
try {
|
||||||
`return ${visible}`
|
visible_fn = new Function(...Object.keys(arg), `return ${visible}`);
|
||||||
);
|
|
||||||
|
|
||||||
const res = visible_fn(...Object.values(arg));
|
const res = visible_fn(...Object.values(arg));
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(visible, arg);
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -16,29 +16,29 @@ export const viLoadSnapshot = async (p: PG) => {
|
||||||
if (api_url && apiURL.hostname) {
|
if (api_url && apiURL.hostname) {
|
||||||
await loadApiProxyDef(api_url, true);
|
await loadApiProxyDef(api_url, true);
|
||||||
|
|
||||||
const api = w.prasiApi[api_url];
|
// const api = w.prasiApi[api_url];
|
||||||
if (api && api.apiTypes && api.prismaTypes) {
|
// if (api && api.apiTypes && api.prismaTypes) {
|
||||||
const zip = JSON.stringify({
|
// const zip = JSON.stringify({
|
||||||
api: api.apiTypes,
|
// api: api.apiTypes,
|
||||||
prisma: api.prismaTypes,
|
// prisma: api.prismaTypes,
|
||||||
});
|
// });
|
||||||
|
|
||||||
const hash = simpleHash(zip);
|
// const hash = simpleHash(zip);
|
||||||
const res = await p.sync?.code.action({
|
// const res = await p.sync?.code.action({
|
||||||
type: "check-typings",
|
// type: "check-typings",
|
||||||
site_id: p.site.id,
|
// site_id: p.site.id,
|
||||||
hash,
|
// hash,
|
||||||
});
|
// });
|
||||||
if (res?.type === "check-typings" && !res.hash) {
|
// if (res?.type === "check-typings" && !res.hash) {
|
||||||
const body = Buffer.from(compress(encoder.encode(zip)));
|
// const body = Buffer.from(compress(encoder.encode(zip)));
|
||||||
p.sync?.code.action({
|
// p.sync?.code.action({
|
||||||
type: "push-typings",
|
// type: "push-typings",
|
||||||
site_id: p.site.id,
|
// site_id: p.site.id,
|
||||||
body,
|
// body,
|
||||||
hash,
|
// hash,
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!p.script.db) p.script.db = dbProxy(api_url);
|
if (!p.script.db) p.script.db = dbProxy(api_url);
|
||||||
if (!p.script.api) p.script.api = apiProxy(api_url);
|
if (!p.script.api) p.script.api = apiProxy(api_url);
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => {
|
||||||
prop.content.name = name;
|
prop.content.name = name;
|
||||||
|
|
||||||
genMeta(
|
genMeta(
|
||||||
{ ...p, mode: "comp" },
|
{ ...p },
|
||||||
{
|
{
|
||||||
item: prop.content,
|
item: prop.content,
|
||||||
root: arg.root || prop.content,
|
root: arg.root || prop.content,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { IItem } from "../../../../utils/types/item";
|
import { IItem } from "../../../../utils/types/item";
|
||||||
|
import { FNComponent } from "../../../../utils/types/meta-fn";
|
||||||
import { GenMetaP, IMeta } from "../../utils/types";
|
import { GenMetaP, IMeta } from "../../utils/types";
|
||||||
import { genMeta } from "../meta";
|
import { genMeta } from "../meta";
|
||||||
|
|
||||||
|
|
@ -14,6 +15,7 @@ export const initLoadComp = async (
|
||||||
) => {
|
) => {
|
||||||
const comp_ids = new Set<string>();
|
const comp_ids = new Set<string>();
|
||||||
const shared = { root: item } as any;
|
const shared = { root: item } as any;
|
||||||
|
const comps = [] as FNComponent[];
|
||||||
genMeta(
|
genMeta(
|
||||||
{
|
{
|
||||||
...p,
|
...p,
|
||||||
|
|
@ -26,36 +28,7 @@ export const initLoadComp = async (
|
||||||
comp_ids.add(id);
|
comp_ids.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
comps.push(component);
|
||||||
if (component?.props) {
|
|
||||||
for (const [name, prop] of Object.entries(component.props)) {
|
|
||||||
if (prop.content) {
|
|
||||||
genMeta(
|
|
||||||
{
|
|
||||||
...p,
|
|
||||||
on: {
|
|
||||||
visit_component: ({ component }) => {
|
|
||||||
if (component) {
|
|
||||||
const { id } = component;
|
|
||||||
if (!p.comps[id]) {
|
|
||||||
if (!_loaded || (_loaded && !_loaded.has(id))) {
|
|
||||||
comp_ids.add(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
visit(meta, vitem) {
|
|
||||||
if (opt.visit) opt.visit(meta, vitem, shared);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
set_meta: false,
|
|
||||||
note: "init-load-comp-prop",
|
|
||||||
},
|
|
||||||
{ item: prop.content }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
visit(meta, vitem) {
|
visit(meta, vitem) {
|
||||||
|
|
@ -69,23 +42,30 @@ export const initLoadComp = async (
|
||||||
);
|
);
|
||||||
|
|
||||||
if (opt.done) opt.done(shared);
|
if (opt.done) opt.done(shared);
|
||||||
if (comp_ids.size > 0) {
|
|
||||||
await opt.load([...comp_ids]);
|
|
||||||
|
|
||||||
let loaded = _loaded;
|
let loaded = _loaded;
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
loaded = new Set<string>();
|
loaded = new Set<string>();
|
||||||
}
|
}
|
||||||
|
if (comp_ids.size > 0) {
|
||||||
|
await opt.load([...comp_ids]);
|
||||||
|
|
||||||
comp_ids.forEach((id) => {
|
comp_ids.forEach((id) => {
|
||||||
if (loaded) loaded.add(id);
|
if (loaded) loaded.add(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const id of [...loaded]) {
|
for (const id of [...loaded]) {
|
||||||
const comp = p.comps[id];
|
const comp = p.comps[id];
|
||||||
|
|
||||||
if (comp) {
|
if (comp) {
|
||||||
await initLoadComp(p, comp, opt, loaded);
|
await initLoadComp(p, comp, opt, loaded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const component of comps) {
|
||||||
|
for (const prop of Object.values(component.props)) {
|
||||||
|
if (prop.meta?.type === "content-element" && prop.content) {
|
||||||
|
await initLoadComp(p, prop.content, opt, loaded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue