@symbo.ls/brender 3.14.0 → 3.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/esm/env.js +1 -80
- package/dist/esm/hydrate.js +1 -535
- package/dist/esm/index.js +1 -53
- package/dist/esm/keys.js +1 -43
- package/dist/esm/load.js +1 -114
- package/dist/esm/metadata.js +1 -7
- package/dist/esm/prefetch.js +1 -235
- package/dist/esm/render.js +50 -1512
- package/dist/esm/scripts/liquidate.js +11 -0
- package/dist/esm/scripts/render.js +12 -0
- package/dist/esm/sitemap.js +10 -19
- package/package.json +27 -17
- package/dist/cjs/env.js +0 -99
- package/dist/cjs/hydrate.js +0 -554
- package/dist/cjs/index.js +0 -72
- package/dist/cjs/keys.js +0 -62
- package/dist/cjs/load.js +0 -143
- package/dist/cjs/metadata.js +0 -26
- package/dist/cjs/prefetch.js +0 -264
- package/dist/cjs/render.js +0 -1602
- package/dist/cjs/sitemap.js +0 -41
- package/env.js +0 -76
- package/hydrate.js +0 -462
- package/index.js +0 -54
- package/keys.js +0 -54
- package/load.js +0 -141
- package/metadata.js +0 -5
- package/prefetch.js +0 -363
- package/render.js +0 -1887
- package/sitemap.js +0 -28
package/dist/esm/index.js
CHANGED
|
@@ -1,53 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { resetKeys, assignKeys, mapKeysToElements } from "./keys.js";
|
|
3
|
-
import { loadProject, loadAndRenderAll } from "./load.js";
|
|
4
|
-
import { render, renderElement, renderRoute, renderPage, resetGlobalCSSCache, getAccumulatedEmotionCSS, replaceEmotionCSS } from "./render.js";
|
|
5
|
-
import { extractMetadata, generateHeadHtml } from "./metadata.js";
|
|
6
|
-
import { collectBrNodes, hydrate } from "./hydrate.js";
|
|
7
|
-
import { generateSitemap } from "./sitemap.js";
|
|
8
|
-
import { prefetchPageData, injectPrefetchedState } from "./prefetch.js";
|
|
9
|
-
var index_default = {
|
|
10
|
-
createEnv,
|
|
11
|
-
resetKeys,
|
|
12
|
-
assignKeys,
|
|
13
|
-
mapKeysToElements,
|
|
14
|
-
loadProject,
|
|
15
|
-
loadAndRenderAll,
|
|
16
|
-
render,
|
|
17
|
-
renderElement,
|
|
18
|
-
renderRoute,
|
|
19
|
-
renderPage,
|
|
20
|
-
resetGlobalCSSCache,
|
|
21
|
-
getAccumulatedEmotionCSS,
|
|
22
|
-
replaceEmotionCSS,
|
|
23
|
-
extractMetadata,
|
|
24
|
-
generateHeadHtml,
|
|
25
|
-
collectBrNodes,
|
|
26
|
-
hydrate,
|
|
27
|
-
generateSitemap,
|
|
28
|
-
prefetchPageData,
|
|
29
|
-
injectPrefetchedState
|
|
30
|
-
};
|
|
31
|
-
export {
|
|
32
|
-
assignKeys,
|
|
33
|
-
collectBrNodes,
|
|
34
|
-
createEnv,
|
|
35
|
-
index_default as default,
|
|
36
|
-
extractMetadata,
|
|
37
|
-
generateHeadHtml,
|
|
38
|
-
generateSitemap,
|
|
39
|
-
getAccumulatedEmotionCSS,
|
|
40
|
-
hydrate,
|
|
41
|
-
injectPrefetchedState,
|
|
42
|
-
loadAndRenderAll,
|
|
43
|
-
loadProject,
|
|
44
|
-
mapKeysToElements,
|
|
45
|
-
prefetchPageData,
|
|
46
|
-
render,
|
|
47
|
-
renderElement,
|
|
48
|
-
renderPage,
|
|
49
|
-
renderRoute,
|
|
50
|
-
replaceEmotionCSS,
|
|
51
|
-
resetGlobalCSSCache,
|
|
52
|
-
resetKeys
|
|
53
|
-
};
|
|
1
|
+
import{createEnv as e}from"./env.js";import{resetKeys as r,assignKeys as t,mapKeysToElements as o}from"./keys.js";import{loadProject as a,loadAndRenderAll as m}from"./load.js";import{render as d,renderElement as n,renderRoute as l,renderPage as p,resetGlobalCSSCache as i,getAccumulatedEmotionCSS as c,replaceEmotionCSS as f}from"./render.js";import{extractMetadata as s,generateHeadHtml as S}from"./metadata.js";import{collectBrNodes as g,hydrate as E}from"./hydrate.js";import{generateSitemap as h}from"./sitemap.js";import{prefetchPageData as u,injectPrefetchedState as y}from"./prefetch.js";var b={createEnv:e,resetKeys:r,assignKeys:t,mapKeysToElements:o,loadProject:a,loadAndRenderAll:m,render:d,renderElement:n,renderRoute:l,renderPage:p,resetGlobalCSSCache:i,getAccumulatedEmotionCSS:c,replaceEmotionCSS:f,extractMetadata:s,generateHeadHtml:S,collectBrNodes:g,hydrate:E,generateSitemap:h,prefetchPageData:u,injectPrefetchedState:y};export{t as assignKeys,g as collectBrNodes,e as createEnv,b as default,s as extractMetadata,S as generateHeadHtml,h as generateSitemap,c as getAccumulatedEmotionCSS,E as hydrate,y as injectPrefetchedState,m as loadAndRenderAll,a as loadProject,o as mapKeysToElements,u as prefetchPageData,d as render,n as renderElement,p as renderPage,l as renderRoute,f as replaceEmotionCSS,i as resetGlobalCSSCache,r as resetKeys};
|
package/dist/esm/keys.js
CHANGED
|
@@ -1,43 +1 @@
|
|
|
1
|
-
let
|
|
2
|
-
const resetKeys = () => {
|
|
3
|
-
_keyCounter = 0;
|
|
4
|
-
};
|
|
5
|
-
const assignKeys = (node) => {
|
|
6
|
-
if (!node) return;
|
|
7
|
-
if (node.nodeType === 1) {
|
|
8
|
-
const key = `br-${_keyCounter++}`;
|
|
9
|
-
node.setAttribute("data-br", key);
|
|
10
|
-
}
|
|
11
|
-
const children = node.childNodes;
|
|
12
|
-
if (children) {
|
|
13
|
-
for (let i = 0; i < children.length; i++) {
|
|
14
|
-
assignKeys(children[i]);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const mapKeysToElements = (element, registry = {}) => {
|
|
19
|
-
if (!element) return registry;
|
|
20
|
-
const node = element.node;
|
|
21
|
-
if (node && node.getAttribute) {
|
|
22
|
-
const brKey = node.getAttribute("data-br");
|
|
23
|
-
if (brKey) {
|
|
24
|
-
if (!element.__ref) element.__ref = {};
|
|
25
|
-
element.__ref.__brKey = brKey;
|
|
26
|
-
registry[brKey] = element;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (element.__ref && element.__ref.__children) {
|
|
30
|
-
for (const childKey of element.__ref.__children) {
|
|
31
|
-
const child = element[childKey];
|
|
32
|
-
if (child && child.__ref) {
|
|
33
|
-
mapKeysToElements(child, registry);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return registry;
|
|
38
|
-
};
|
|
39
|
-
export {
|
|
40
|
-
assignKeys,
|
|
41
|
-
mapKeysToElements,
|
|
42
|
-
resetKeys
|
|
43
|
-
};
|
|
1
|
+
let i=0;const e=()=>{i=0},c=r=>{if(!r)return;if(r.nodeType===1){const t=`br-${i++}`;r.setAttribute("data-br",t)}const _=r.childNodes;if(_)for(let t=0;t<_.length;t++)c(_[t])},s=(r,_={})=>{if(!r)return _;const t=r.node;if(t&&t.getAttribute){const f=t.getAttribute("data-br");f&&(r.__ref||(r.__ref={}),r.__ref.__brKey=f,_[f]=r)}if(r.__ref&&r.__ref.__children)for(const f of r.__ref.__children){const o=r[f];o&&o.__ref&&s(o,_)}return _};export{c as assignKeys,s as mapKeysToElements,e as resetKeys};
|
package/dist/esm/load.js
CHANGED
|
@@ -1,114 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync, unlinkSync } from "fs";
|
|
3
|
-
import { tmpdir } from "os";
|
|
4
|
-
import { randomBytes } from "crypto";
|
|
5
|
-
const bundleAndImport = async (entryPath) => {
|
|
6
|
-
if (!existsSync(entryPath)) return null;
|
|
7
|
-
let esbuild;
|
|
8
|
-
try {
|
|
9
|
-
esbuild = await import("esbuild");
|
|
10
|
-
} catch {
|
|
11
|
-
try {
|
|
12
|
-
return await import(entryPath);
|
|
13
|
-
} catch {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
const outFile = join(tmpdir(), `brender_${randomBytes(8).toString("hex")}.mjs`);
|
|
18
|
-
try {
|
|
19
|
-
await esbuild.build({
|
|
20
|
-
entryPoints: [entryPath],
|
|
21
|
-
bundle: true,
|
|
22
|
-
format: "esm",
|
|
23
|
-
platform: "node",
|
|
24
|
-
outfile: outFile,
|
|
25
|
-
write: true,
|
|
26
|
-
logLevel: "silent",
|
|
27
|
-
// Mark node builtins as external
|
|
28
|
-
external: ["fs", "path", "os", "crypto", "url", "http", "https", "stream", "util", "events", "buffer", "child_process", "worker_threads", "net", "tls", "dns", "dgram", "zlib", "assert", "querystring", "string_decoder", "readline", "perf_hooks", "async_hooks", "v8", "vm", "cluster", "inspector", "module", "process", "tty"]
|
|
29
|
-
});
|
|
30
|
-
const mod = await import(`file://${outFile}`);
|
|
31
|
-
return mod;
|
|
32
|
-
} catch {
|
|
33
|
-
try {
|
|
34
|
-
return await import(entryPath);
|
|
35
|
-
} catch {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
} finally {
|
|
39
|
-
try {
|
|
40
|
-
unlinkSync(outFile);
|
|
41
|
-
} catch {
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const loadProject = async (projectPath) => {
|
|
46
|
-
const symbolsDir = resolve(projectPath, "symbols");
|
|
47
|
-
const [
|
|
48
|
-
appModule,
|
|
49
|
-
stateModule,
|
|
50
|
-
configModule,
|
|
51
|
-
depsModule,
|
|
52
|
-
componentsModule,
|
|
53
|
-
snippetsModule,
|
|
54
|
-
pagesModule,
|
|
55
|
-
functionsModule,
|
|
56
|
-
methodsModule,
|
|
57
|
-
designSystemModule,
|
|
58
|
-
filesModule,
|
|
59
|
-
assetsModule,
|
|
60
|
-
sharedLibsModule
|
|
61
|
-
] = await Promise.all([
|
|
62
|
-
bundleAndImport(join(symbolsDir, "app.js")),
|
|
63
|
-
bundleAndImport(join(symbolsDir, "state.js")),
|
|
64
|
-
bundleAndImport(join(symbolsDir, "config.js")),
|
|
65
|
-
bundleAndImport(join(symbolsDir, "dependencies.js")),
|
|
66
|
-
bundleAndImport(join(symbolsDir, "components", "index.js")),
|
|
67
|
-
bundleAndImport(join(symbolsDir, "snippets", "index.js")),
|
|
68
|
-
bundleAndImport(join(symbolsDir, "pages", "index.js")),
|
|
69
|
-
bundleAndImport(join(symbolsDir, "functions", "index.js")),
|
|
70
|
-
bundleAndImport(join(symbolsDir, "methods", "index.js")),
|
|
71
|
-
bundleAndImport(join(symbolsDir, "designSystem", "index.js")),
|
|
72
|
-
bundleAndImport(join(symbolsDir, "files", "index.js")),
|
|
73
|
-
bundleAndImport(join(symbolsDir, "assets", "index.js")).catch(() => null),
|
|
74
|
-
bundleAndImport(join(symbolsDir, "sharedLibraries.js")).catch(() => null)
|
|
75
|
-
]);
|
|
76
|
-
const result = {
|
|
77
|
-
app: { ...appModule?.default || {} },
|
|
78
|
-
state: { ...stateModule?.default || {} },
|
|
79
|
-
dependencies: { ...depsModule?.default || {} },
|
|
80
|
-
components: { ...componentsModule || {} },
|
|
81
|
-
snippets: { ...snippetsModule || {} },
|
|
82
|
-
pages: { ...pagesModule?.default || {} },
|
|
83
|
-
functions: { ...functionsModule || {} },
|
|
84
|
-
methods: { ...methodsModule || {} },
|
|
85
|
-
designSystem: { ...designSystemModule?.default || {} },
|
|
86
|
-
files: { ...filesModule?.default || {} },
|
|
87
|
-
assets: { ...assetsModule?.default || {} },
|
|
88
|
-
config: { ...configModule?.default || {} },
|
|
89
|
-
sharedLibraries: sharedLibsModule?.default || []
|
|
90
|
-
};
|
|
91
|
-
if (result.sharedLibraries.length) {
|
|
92
|
-
const { resolveSharedLibraries, mergeSharedLibraries } = await import("@symbo.ls/utils");
|
|
93
|
-
const hasStrings = result.sharedLibraries.some((lib) => typeof lib === "string");
|
|
94
|
-
if (hasStrings) {
|
|
95
|
-
result.sharedLibraries = await resolveSharedLibraries(result.sharedLibraries);
|
|
96
|
-
}
|
|
97
|
-
mergeSharedLibraries(result, result.sharedLibraries);
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
};
|
|
101
|
-
const loadAndRenderAll = async (projectPath, renderFn) => {
|
|
102
|
-
const data = await loadProject(projectPath);
|
|
103
|
-
const pages = data.pages || {};
|
|
104
|
-
const routes = Object.keys(pages);
|
|
105
|
-
const results = {};
|
|
106
|
-
for (const route of routes) {
|
|
107
|
-
results[route] = await renderFn(data, { route });
|
|
108
|
-
}
|
|
109
|
-
return results;
|
|
110
|
-
};
|
|
111
|
-
export {
|
|
112
|
-
loadAndRenderAll,
|
|
113
|
-
loadProject
|
|
114
|
-
};
|
|
1
|
+
import{resolve as x,join as s}from"path";import{existsSync as M,unlinkSync as S}from"fs";import{tmpdir as L}from"os";import{randomBytes as k}from"crypto";const t=async r=>{if(!M(r))return null;let e;try{e=await import("esbuild")}catch{try{return await import(r)}catch{return null}}const o=s(L(),`brender_${k(8).toString("hex")}.mjs`);try{return await e.build({entryPoints:[r],bundle:!0,format:"esm",platform:"node",outfile:o,write:!0,logLevel:"silent",external:["fs","path","os","crypto","url","http","https","stream","util","events","buffer","child_process","worker_threads","net","tls","dns","dgram","zlib","assert","querystring","string_decoder","readline","perf_hooks","async_hooks","v8","vm","cluster","inspector","module","process","tty"]}),await import(`file://${o}`)}catch{try{return await import(r)}catch{return null}}finally{try{S(o)}catch{}}},v=async r=>{const e=x(r,"symbols"),[o,n,l,a,d,c,u,p,m,f,h,y,g]=await Promise.all([t(s(e,"app.js")),t(s(e,"state.js")),t(s(e,"config.js")),t(s(e,"dependencies.js")),t(s(e,"components","index.js")),t(s(e,"snippets","index.js")),t(s(e,"pages","index.js")),t(s(e,"functions","index.js")),t(s(e,"methods","index.js")),t(s(e,"designSystem","index.js")),t(s(e,"files","index.js")),t(s(e,"assets","index.js")).catch(()=>null),t(s(e,"sharedLibraries.js")).catch(()=>null)]),i={app:{...o?.default||{}},state:{...n?.default||{}},dependencies:{...a?.default||{}},components:{...d||{}},snippets:{...c||{}},pages:{...u?.default||{}},functions:{...p||{}},methods:{...m||{}},designSystem:{...f?.default||{}},files:{...h?.default||{}},assets:{...y?.default||{}},config:{...l?.default||{}},sharedLibraries:g?.default||[]};if(i.sharedLibraries.length){const{resolveSharedLibraries:b,mergeSharedLibraries:j}=await import("@symbo.ls/utils");i.sharedLibraries.some(w=>typeof w=="string")&&(i.sharedLibraries=await b(i.sharedLibraries)),j(i,i.sharedLibraries)}return i},D=async(r,e)=>{const o=await v(r),n=o.pages||{},l=Object.keys(n),a={};for(const d of l)a[d]=await e(o,{route:d});return a};export{D as loadAndRenderAll,v as loadProject};
|
package/dist/esm/metadata.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export {
|
|
3
|
-
applyMetadata,
|
|
4
|
-
extractMetadata,
|
|
5
|
-
generateHeadHtml,
|
|
6
|
-
resolveMetadata
|
|
7
|
-
};
|
|
1
|
+
import{extractMetadata as t,generateHeadHtml as r,resolveMetadata as d,applyMetadata as l}from"@symbo.ls/helmet";export{l as applyMetadata,t as extractMetadata,r as generateHeadHtml,d as resolveMetadata};
|
package/dist/esm/prefetch.js
CHANGED
|
@@ -1,235 +1 @@
|
|
|
1
|
-
const
|
|
2
|
-
const isArray = (v) => Array.isArray(v);
|
|
3
|
-
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
4
|
-
const resolveParams = (params, mockState) => {
|
|
5
|
-
if (!params) return void 0;
|
|
6
|
-
if (isFunction(params)) {
|
|
7
|
-
try {
|
|
8
|
-
const mockEl = {
|
|
9
|
-
state: mockState || {},
|
|
10
|
-
call: () => void 0,
|
|
11
|
-
__ref: {}
|
|
12
|
-
};
|
|
13
|
-
return params(mockEl, mockState || {});
|
|
14
|
-
} catch {
|
|
15
|
-
return void 0;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return params;
|
|
19
|
-
};
|
|
20
|
-
const normalizeFetchConfig = (cfg, elementState) => {
|
|
21
|
-
if (!cfg) return null;
|
|
22
|
-
if (typeof cfg === "string") return { from: cfg, method: "select" };
|
|
23
|
-
const resolved = isFunction(cfg) ? null : { ...cfg };
|
|
24
|
-
if (!resolved) return null;
|
|
25
|
-
if (!resolved.method) resolved.method = "select";
|
|
26
|
-
if (isFunction(resolved.params)) {
|
|
27
|
-
resolved.params = resolveParams(resolved.params, elementState);
|
|
28
|
-
}
|
|
29
|
-
const isMutation = resolved.method === "insert" || resolved.method === "update" || resolved.method === "upsert" || resolved.method === "delete";
|
|
30
|
-
if (isMutation) return null;
|
|
31
|
-
if (resolved.on && resolved.on !== "create") return null;
|
|
32
|
-
return resolved;
|
|
33
|
-
};
|
|
34
|
-
const collectFetchDeclarations = (def, path = "") => {
|
|
35
|
-
if (!def || typeof def !== "object") return [];
|
|
36
|
-
if (isFunction(def)) return [];
|
|
37
|
-
const results = [];
|
|
38
|
-
const elementState = def.state || {};
|
|
39
|
-
if (def.fetch) {
|
|
40
|
-
const fetchDefs = isArray(def.fetch) ? def.fetch : [def.fetch];
|
|
41
|
-
for (const fd of fetchDefs) {
|
|
42
|
-
const config = normalizeFetchConfig(fd, elementState);
|
|
43
|
-
if (config) {
|
|
44
|
-
results.push({
|
|
45
|
-
config,
|
|
46
|
-
stateKey: config.as,
|
|
47
|
-
path,
|
|
48
|
-
elementState
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
for (const key in def) {
|
|
54
|
-
if (key === "fetch" || key === "state" || key === "props" || key === "attr" || key === "on" || key === "define" || key === "childExtends" || key === "childProps" || key === "childrenAs") continue;
|
|
55
|
-
if (key.charAt(0) >= "A" && key.charAt(0) <= "Z" && isObject(def[key])) {
|
|
56
|
-
results.push(...collectFetchDeclarations(def[key], path ? `${path}.${key}` : key));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return results;
|
|
60
|
-
};
|
|
61
|
-
const createSSRAdapter = async (dbConfig) => {
|
|
62
|
-
if (!dbConfig) return null;
|
|
63
|
-
const { adapter, createClient, url, key, projectId } = dbConfig;
|
|
64
|
-
if (adapter !== "supabase") return null;
|
|
65
|
-
const supabaseUrl = url || projectId && `https://${projectId}.supabase.co`;
|
|
66
|
-
if (!supabaseUrl || !key) return null;
|
|
67
|
-
let clientFactory;
|
|
68
|
-
try {
|
|
69
|
-
const mod = await import("@supabase/supabase-js");
|
|
70
|
-
clientFactory = mod.createClient;
|
|
71
|
-
} catch {
|
|
72
|
-
clientFactory = createClient;
|
|
73
|
-
}
|
|
74
|
-
if (!clientFactory) return null;
|
|
75
|
-
const client = clientFactory(supabaseUrl, key);
|
|
76
|
-
return {
|
|
77
|
-
rpc: ({ from, params }) => client.rpc(from, params),
|
|
78
|
-
select: async ({ from, select: sel, params, limit, offset, order, single }) => {
|
|
79
|
-
let q = client.from(from).select(sel || "*");
|
|
80
|
-
if (params) {
|
|
81
|
-
for (const k in params) {
|
|
82
|
-
const v = params[k];
|
|
83
|
-
if (v === null) q = q.is(k, null);
|
|
84
|
-
else if (Array.isArray(v)) q = q.in(k, v);
|
|
85
|
-
else q = q.eq(k, v);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (order) {
|
|
89
|
-
const orderBy = typeof order === "string" ? order : order.by;
|
|
90
|
-
q = q.order(orderBy, { ascending: order.asc !== false });
|
|
91
|
-
}
|
|
92
|
-
if (limit) q = q.limit(limit);
|
|
93
|
-
if (offset) q = q.range(offset, offset + (limit || 20) - 1);
|
|
94
|
-
if (single) q = q.single();
|
|
95
|
-
return q;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
const executeSingle = async (adapter, config) => {
|
|
100
|
-
try {
|
|
101
|
-
const { method, from, params, transform, limit, offset, order, single } = config;
|
|
102
|
-
let result;
|
|
103
|
-
if (method === "rpc") {
|
|
104
|
-
result = await adapter.rpc({ from, params });
|
|
105
|
-
} else {
|
|
106
|
-
result = await adapter.select({ from, select: config.select, params, limit, offset, order, single });
|
|
107
|
-
}
|
|
108
|
-
let data = result?.data ?? null;
|
|
109
|
-
if (result?.error) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
if (data && transform && isFunction(transform)) {
|
|
113
|
-
try {
|
|
114
|
-
data = transform(data);
|
|
115
|
-
} catch {
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return data;
|
|
119
|
-
} catch {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
const prefetchPageData = async (data, route = "/", options = {}) => {
|
|
124
|
-
const pages = data.pages || {};
|
|
125
|
-
const pageDef = pages[route];
|
|
126
|
-
if (!pageDef) return /* @__PURE__ */ new Map();
|
|
127
|
-
const config = data.config || data.settings || {};
|
|
128
|
-
const dbConfig = config.fetch || data.fetch || config.db || data.db;
|
|
129
|
-
if (!dbConfig) return /* @__PURE__ */ new Map();
|
|
130
|
-
const adapter = await createSSRAdapter(dbConfig);
|
|
131
|
-
if (!adapter) return /* @__PURE__ */ new Map();
|
|
132
|
-
const declarations = collectFetchDeclarations(pageDef);
|
|
133
|
-
if (!declarations.length) return /* @__PURE__ */ new Map();
|
|
134
|
-
const stateUpdates = /* @__PURE__ */ new Map();
|
|
135
|
-
const results = await Promise.allSettled(
|
|
136
|
-
declarations.map(async ({ config: config2, stateKey, path }) => {
|
|
137
|
-
const fetchedData = await executeSingle(adapter, config2);
|
|
138
|
-
if (fetchedData !== null) {
|
|
139
|
-
const existing = stateUpdates.get(path) || {};
|
|
140
|
-
if (stateKey) {
|
|
141
|
-
existing[stateKey] = fetchedData;
|
|
142
|
-
} else if (isObject(fetchedData)) {
|
|
143
|
-
Object.assign(existing, fetchedData);
|
|
144
|
-
}
|
|
145
|
-
stateUpdates.set(path, existing);
|
|
146
|
-
}
|
|
147
|
-
})
|
|
148
|
-
);
|
|
149
|
-
return stateUpdates;
|
|
150
|
-
};
|
|
151
|
-
const fetchSSRTranslations = async (data) => {
|
|
152
|
-
const config = data.config || {};
|
|
153
|
-
const polyglot = config.polyglot || data.polyglot;
|
|
154
|
-
if (!polyglot?.fetch) return null;
|
|
155
|
-
const dbConfig = config.fetch || data.fetch || config.db || data.db;
|
|
156
|
-
if (!dbConfig) return null;
|
|
157
|
-
const adapter = await createSSRAdapter(dbConfig);
|
|
158
|
-
if (!adapter) return null;
|
|
159
|
-
const fetchConfig = polyglot.fetch;
|
|
160
|
-
const rpcName = fetchConfig.rpc || fetchConfig.from || "get_translations_if_changed";
|
|
161
|
-
const languages = polyglot.languages || [polyglot.defaultLang || "en"];
|
|
162
|
-
const translations = {};
|
|
163
|
-
const results = await Promise.allSettled(
|
|
164
|
-
languages.map(async (lang) => {
|
|
165
|
-
try {
|
|
166
|
-
const res = await adapter.rpc({
|
|
167
|
-
from: rpcName,
|
|
168
|
-
params: { p_lang: lang, p_cached_version: 0 }
|
|
169
|
-
});
|
|
170
|
-
if (res.error || !res.data) return;
|
|
171
|
-
const result = res.data;
|
|
172
|
-
if (result.translations) {
|
|
173
|
-
translations[lang] = result.translations;
|
|
174
|
-
}
|
|
175
|
-
} catch (e) {
|
|
176
|
-
console.warn("[brender] SSR translation fetch failed:", e.message);
|
|
177
|
-
}
|
|
178
|
-
})
|
|
179
|
-
);
|
|
180
|
-
return Object.keys(translations).length ? translations : null;
|
|
181
|
-
};
|
|
182
|
-
const preEvaluateChildren = (def, inheritedState) => {
|
|
183
|
-
if (!def || typeof def !== "object") return;
|
|
184
|
-
for (const key in def) {
|
|
185
|
-
if (key === "state" || key === "fetch" || key === "props" || key === "attr" || key === "on" || key === "define" || key === "childExtends" || key === "childProps" || key === "childrenAs") continue;
|
|
186
|
-
if (key.charAt(0) >= "A" && key.charAt(0) <= "Z" && isObject(def[key])) {
|
|
187
|
-
const child = def[key];
|
|
188
|
-
const effectiveState = child.state && typeof child.state === "object" ? { ...inheritedState, ...child.state } : inheritedState;
|
|
189
|
-
if (isFunction(child.children)) {
|
|
190
|
-
try {
|
|
191
|
-
const mockEl = {
|
|
192
|
-
state: effectiveState,
|
|
193
|
-
call: (fn) => {
|
|
194
|
-
if (fn === "getActiveLang" || fn === "getLang") return effectiveState?.lang || "ka";
|
|
195
|
-
if (fn === "polyglot") return arguments[1] || "";
|
|
196
|
-
return void 0;
|
|
197
|
-
},
|
|
198
|
-
__ref: {}
|
|
199
|
-
};
|
|
200
|
-
const result = child.children(mockEl, effectiveState);
|
|
201
|
-
if (isArray(result) && result.length > 0) {
|
|
202
|
-
child.children = result;
|
|
203
|
-
}
|
|
204
|
-
} catch {
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
preEvaluateChildren(child, effectiveState);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
const injectPrefetchedState = (pageDef, stateUpdates) => {
|
|
212
|
-
if (!stateUpdates || !stateUpdates.size) return;
|
|
213
|
-
for (const [path, data] of stateUpdates) {
|
|
214
|
-
let target = pageDef;
|
|
215
|
-
if (path) {
|
|
216
|
-
const parts = path.split(".");
|
|
217
|
-
for (const part of parts) {
|
|
218
|
-
if (!target || typeof target !== "object") break;
|
|
219
|
-
target = target[part];
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (target && typeof target === "object") {
|
|
223
|
-
if (!target.state || typeof target.state !== "object") {
|
|
224
|
-
target.state = {};
|
|
225
|
-
}
|
|
226
|
-
Object.assign(target.state, data);
|
|
227
|
-
preEvaluateChildren(target, target.state);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
export {
|
|
232
|
-
fetchSSRTranslations,
|
|
233
|
-
injectPrefetchedState,
|
|
234
|
-
prefetchPageData
|
|
235
|
-
};
|
|
1
|
+
const m=t=>typeof t=="function",j=t=>Array.isArray(t),w=t=>t!==null&&typeof t=="object"&&!Array.isArray(t),x=(t,r)=>{if(t){if(m(t))try{return t({state:r||{},call:()=>{},__ref:{}},r||{})}catch{return}return t}},M=(t,r)=>{if(!t)return null;if(typeof t=="string")return{from:t,method:"select"};const n=m(t)?null:{...t};return!n||(n.method||(n.method="select"),m(n.params)&&(n.params=x(n.params,r)),n.method==="insert"||n.method==="update"||n.method==="upsert"||n.method==="delete")||n.on&&n.on!=="create"?null:n},S=(t,r="")=>{if(!t||typeof t!="object")return[];if(m(t))return[];const n=[],s=t.state||{};if(t.fetch){const e=j(t.fetch)?t.fetch:[t.fetch];for(const o of e){const c=M(o,s);c&&n.push({config:c,stateKey:c.as,path:r,elementState:s})}}for(const e in t)e==="fetch"||e==="state"||e==="props"||e==="attr"||e==="on"||e==="define"||e==="childExtends"||e==="childProps"||e==="childrenAs"||e.charAt(0)>="A"&&e.charAt(0)<="Z"&&w(t[e])&&n.push(...S(t[e],r?`${r}.${e}`:e));return n},_=async t=>{if(!t)return null;const{adapter:r,createClient:n,url:s,key:e,projectId:o}=t;if(r!=="supabase")return null;const c=s||o&&`https://${o}.supabase.co`;if(!c||!e)return null;let a;try{a=(await import("@supabase/supabase-js")).createClient}catch{a=n}if(!a)return null;const u=a(c,e);return{rpc:({from:p,params:f})=>u.rpc(p,f),select:async({from:p,select:f,params:i,limit:g,offset:y,order:h,single:b})=>{let l=u.from(p).select(f||"*");if(i)for(const d in i){const A=i[d];A===null?l=l.is(d,null):Array.isArray(A)?l=l.in(d,A):l=l.eq(d,A)}if(h){const d=typeof h=="string"?h:h.by;l=l.order(d,{ascending:h.asc!==!1})}return g&&(l=l.limit(g)),y&&(l=l.range(y,y+(g||20)-1)),b&&(l=l.single()),l}}},P=async(t,r)=>{try{const{method:n,from:s,params:e,transform:o,limit:c,offset:a,order:u,single:p}=r;let f;n==="rpc"?f=await t.rpc({from:s,params:e}):f=await t.select({from:s,select:r.select,params:e,limit:c,offset:a,order:u,single:p});let i=f?.data??null;if(f?.error)return null;if(i&&o&&m(o))try{i=o(i)}catch{}return i}catch{return null}},C=async(t,r="/",n={})=>{const e=(t.pages||{})[r];if(!e)return new Map;const o=t.config||t.settings||{},c=o.fetch||t.fetch||o.db||t.db;if(!c)return new Map;const a=await _(c);if(!a)return new Map;const u=S(e);if(!u.length)return new Map;const p=new Map,f=await Promise.allSettled(u.map(async({config:i,stateKey:g,path:y})=>{const h=await P(a,i);if(h!==null){const b=p.get(y)||{};g?b[g]=h:w(h)&&Object.assign(b,h),p.set(y,b)}}));return p},E=async t=>{const r=t.config||{},n=r.polyglot||t.polyglot;if(!n?.fetch)return null;const s=r.fetch||t.fetch||r.db||t.db;if(!s)return null;const e=await _(s);if(!e)return null;const o=n.fetch,c=o.rpc||o.from||"get_translations_if_changed",a=n.languages||[n.defaultLang||"en"],u={},p=await Promise.allSettled(a.map(async f=>{try{const i=await e.rpc({from:c,params:{p_lang:f,p_cached_version:0}});if(i.error||!i.data)return;const g=i.data;g.translations&&(u[f]=g.translations)}catch(i){console.warn("[brender] SSR translation fetch failed:",i.message)}}));return Object.keys(u).length?u:null},k=(t,r)=>{if(!(!t||typeof t!="object")){for(const n in t)if(!(n==="state"||n==="fetch"||n==="props"||n==="attr"||n==="on"||n==="define"||n==="childExtends"||n==="childProps"||n==="childrenAs")&&n.charAt(0)>="A"&&n.charAt(0)<="Z"&&w(t[n])){const s=t[n],e=s.state&&typeof s.state=="object"?{...r,...s.state}:r;if(m(s.children))try{const o={state:e,call:a=>{if(a==="getActiveLang"||a==="getLang")return e?.lang||"ka";if(a==="polyglot")return arguments[1]||""},__ref:{}},c=s.children(o,e);j(c)&&c.length>0&&(s.children=c)}catch{}k(s,e)}}},v=(t,r)=>{if(!(!r||!r.size))for(const[n,s]of r){let e=t;if(n){const o=n.split(".");for(const c of o){if(!e||typeof e!="object")break;e=e[c]}}e&&typeof e=="object"&&((!e.state||typeof e.state!="object")&&(e.state={}),Object.assign(e.state,s),k(e,e.state))}};export{E as fetchSSRTranslations,v as injectPrefetchedState,C as prefetchPageData};
|