This commit is contained in:
Rizky 2024-04-13 17:21:11 +07:00
parent 204430878a
commit 9a02b9baa5
9 changed files with 68 additions and 72 deletions

File diff suppressed because one or more lines are too long

View File

@ -16,6 +16,7 @@ import { SyncType } from "../../type";
import { Packr } from "msgpackr";
import { ServerWebSocket } from "bun";
import { WSData } from "../../../../../../pkgs/core/server/create";
import { g } from "utils/global";
const packr = new Packr({ structuredClone: true });
@ -143,9 +144,16 @@ if (typeof global.server_hook === "function") {
{
name: "prasi",
setup(setup) {
const reinit = () => {
setup.onEnd((res) => {
server.init(id_site);
});
};
if (g.mode === "dev") {
setTimeout(reinit, 1000);
} else {
reinit();
}
},
},
],

View File

@ -1,3 +1,4 @@
import { g } from "utils/global";
import { codeBuild } from "./build-code";
import { CodeMode, code, codeGlobalTypings } from "./util-code";
@ -13,5 +14,6 @@ export const prepCodeSnapshot = async (id_site: string, mode: CodeMode) => {
.await();
await codeBuild(id_site);
return { ts: code.esbuild[id_site].site_ts };
};

View File

@ -58,6 +58,7 @@ export const treeCacheBuild = async (p: PG, page_id: string) => {
},
}
);
for (const item of page_cache.root.childs) {
meta_cache.entry.push(item.id);
genMeta(
@ -111,11 +112,14 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
if (item) {
await initLoadComp({ comps: p.comp.loaded, meta, mode: "page" }, item, {
async load(comp_ids) {
console.log(comp_ids.includes("ca7ac237-8f22-4492-bb9d-4b715b1f5c25"))
for (const id of comp_ids) {
await loadComponent(p, id);
}
},
});
console.log(p.comp.loaded["ca7ac237-8f22-4492-bb9d-4b715b1f5c25"]);
genMeta(
{
note: "tree-rebuild",

View File

@ -110,16 +110,18 @@ export const EdSidePropInstance: FC<{ meta: IMeta }> = ({ meta }) => {
}
}
const visible_fn = new Function(
...Object.keys(arg),
`return ${visible}`
);
let visible_fn = null as any;
try {
visible_fn = new Function(...Object.keys(arg), `return ${visible}`);
const res = visible_fn(...Object.values(arg));
if (!res) {
return;
}
} catch (e) {
console.log(visible, arg);
console.error(e);
}
} catch (e) {
console.error(e);
return;

View File

@ -16,29 +16,29 @@ export const viLoadSnapshot = async (p: PG) => {
if (api_url && apiURL.hostname) {
await loadApiProxyDef(api_url, true);
const api = w.prasiApi[api_url];
if (api && api.apiTypes && api.prismaTypes) {
const zip = JSON.stringify({
api: api.apiTypes,
prisma: api.prismaTypes,
});
// const api = w.prasiApi[api_url];
// if (api && api.apiTypes && api.prismaTypes) {
// const zip = JSON.stringify({
// api: api.apiTypes,
// prisma: api.prismaTypes,
// });
const hash = simpleHash(zip);
const res = await p.sync?.code.action({
type: "check-typings",
site_id: p.site.id,
hash,
});
if (res?.type === "check-typings" && !res.hash) {
const body = Buffer.from(compress(encoder.encode(zip)));
p.sync?.code.action({
type: "push-typings",
site_id: p.site.id,
body,
hash,
});
}
}
// const hash = simpleHash(zip);
// const res = await p.sync?.code.action({
// type: "check-typings",
// site_id: p.site.id,
// hash,
// });
// if (res?.type === "check-typings" && !res.hash) {
// const body = Buffer.from(compress(encoder.encode(zip)));
// p.sync?.code.action({
// type: "push-typings",
// site_id: p.site.id,
// body,
// hash,
// });
// }
// }
if (!p.script.db) p.script.db = dbProxy(api_url);
if (!p.script.api) p.script.api = apiProxy(api_url);

View File

@ -77,7 +77,7 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => {
prop.content.name = name;
genMeta(
{ ...p, mode: "comp" },
{ ...p },
{
item: prop.content,
root: arg.root || prop.content,

View File

@ -1,4 +1,5 @@
import { IItem } from "../../../../utils/types/item";
import { FNComponent } from "../../../../utils/types/meta-fn";
import { GenMetaP, IMeta } from "../../utils/types";
import { genMeta } from "../meta";
@ -14,6 +15,7 @@ export const initLoadComp = async (
) => {
const comp_ids = new Set<string>();
const shared = { root: item } as any;
const comps = [] as FNComponent[];
genMeta(
{
...p,
@ -26,36 +28,7 @@ export const initLoadComp = async (
comp_ids.add(id);
}
}
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 }
);
}
}
}
comps.push(component);
}
},
visit(meta, vitem) {
@ -69,23 +42,30 @@ export const initLoadComp = async (
);
if (opt.done) opt.done(shared);
if (comp_ids.size > 0) {
await opt.load([...comp_ids]);
let loaded = _loaded;
if (!loaded) {
loaded = new Set<string>();
}
if (comp_ids.size > 0) {
await opt.load([...comp_ids]);
comp_ids.forEach((id) => {
if (loaded) loaded.add(id);
});
for (const id of [...loaded]) {
const comp = p.comps[id];
if (comp) {
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);
}
}
}
};