@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/dist/cjs/load.js DELETED
@@ -1,143 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var load_exports = {};
29
- __export(load_exports, {
30
- loadAndRenderAll: () => loadAndRenderAll,
31
- loadProject: () => loadProject
32
- });
33
- module.exports = __toCommonJS(load_exports);
34
- var import_path = require("path");
35
- var import_fs = require("fs");
36
- var import_os = require("os");
37
- var import_crypto = require("crypto");
38
- const bundleAndImport = async (entryPath) => {
39
- if (!(0, import_fs.existsSync)(entryPath)) return null;
40
- let esbuild;
41
- try {
42
- esbuild = await import("esbuild");
43
- } catch {
44
- try {
45
- return await import(entryPath);
46
- } catch {
47
- return null;
48
- }
49
- }
50
- const outFile = (0, import_path.join)((0, import_os.tmpdir)(), `brender_${(0, import_crypto.randomBytes)(8).toString("hex")}.mjs`);
51
- try {
52
- await esbuild.build({
53
- entryPoints: [entryPath],
54
- bundle: true,
55
- format: "esm",
56
- platform: "node",
57
- outfile: outFile,
58
- write: true,
59
- logLevel: "silent",
60
- // Mark node builtins as external
61
- 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"]
62
- });
63
- const mod = await import(`file://${outFile}`);
64
- return mod;
65
- } catch {
66
- try {
67
- return await import(entryPath);
68
- } catch {
69
- return null;
70
- }
71
- } finally {
72
- try {
73
- (0, import_fs.unlinkSync)(outFile);
74
- } catch {
75
- }
76
- }
77
- };
78
- const loadProject = async (projectPath) => {
79
- const symbolsDir = (0, import_path.resolve)(projectPath, "symbols");
80
- const [
81
- appModule,
82
- stateModule,
83
- configModule,
84
- depsModule,
85
- componentsModule,
86
- snippetsModule,
87
- pagesModule,
88
- functionsModule,
89
- methodsModule,
90
- designSystemModule,
91
- filesModule,
92
- assetsModule,
93
- sharedLibsModule
94
- ] = await Promise.all([
95
- bundleAndImport((0, import_path.join)(symbolsDir, "app.js")),
96
- bundleAndImport((0, import_path.join)(symbolsDir, "state.js")),
97
- bundleAndImport((0, import_path.join)(symbolsDir, "config.js")),
98
- bundleAndImport((0, import_path.join)(symbolsDir, "dependencies.js")),
99
- bundleAndImport((0, import_path.join)(symbolsDir, "components", "index.js")),
100
- bundleAndImport((0, import_path.join)(symbolsDir, "snippets", "index.js")),
101
- bundleAndImport((0, import_path.join)(symbolsDir, "pages", "index.js")),
102
- bundleAndImport((0, import_path.join)(symbolsDir, "functions", "index.js")),
103
- bundleAndImport((0, import_path.join)(symbolsDir, "methods", "index.js")),
104
- bundleAndImport((0, import_path.join)(symbolsDir, "designSystem", "index.js")),
105
- bundleAndImport((0, import_path.join)(symbolsDir, "files", "index.js")),
106
- bundleAndImport((0, import_path.join)(symbolsDir, "assets", "index.js")).catch(() => null),
107
- bundleAndImport((0, import_path.join)(symbolsDir, "sharedLibraries.js")).catch(() => null)
108
- ]);
109
- const result = {
110
- app: { ...appModule?.default || {} },
111
- state: { ...stateModule?.default || {} },
112
- dependencies: { ...depsModule?.default || {} },
113
- components: { ...componentsModule || {} },
114
- snippets: { ...snippetsModule || {} },
115
- pages: { ...pagesModule?.default || {} },
116
- functions: { ...functionsModule || {} },
117
- methods: { ...methodsModule || {} },
118
- designSystem: { ...designSystemModule?.default || {} },
119
- files: { ...filesModule?.default || {} },
120
- assets: { ...assetsModule?.default || {} },
121
- config: { ...configModule?.default || {} },
122
- sharedLibraries: sharedLibsModule?.default || []
123
- };
124
- if (result.sharedLibraries.length) {
125
- const { resolveSharedLibraries, mergeSharedLibraries } = await import("@symbo.ls/utils");
126
- const hasStrings = result.sharedLibraries.some((lib) => typeof lib === "string");
127
- if (hasStrings) {
128
- result.sharedLibraries = await resolveSharedLibraries(result.sharedLibraries);
129
- }
130
- mergeSharedLibraries(result, result.sharedLibraries);
131
- }
132
- return result;
133
- };
134
- const loadAndRenderAll = async (projectPath, renderFn) => {
135
- const data = await loadProject(projectPath);
136
- const pages = data.pages || {};
137
- const routes = Object.keys(pages);
138
- const results = {};
139
- for (const route of routes) {
140
- results[route] = await renderFn(data, { route });
141
- }
142
- return results;
143
- };
@@ -1,26 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var metadata_exports = {};
19
- __export(metadata_exports, {
20
- applyMetadata: () => import_helmet.applyMetadata,
21
- extractMetadata: () => import_helmet.extractMetadata,
22
- generateHeadHtml: () => import_helmet.generateHeadHtml,
23
- resolveMetadata: () => import_helmet.resolveMetadata
24
- });
25
- module.exports = __toCommonJS(metadata_exports);
26
- var import_helmet = require("@symbo.ls/helmet");
@@ -1,264 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var prefetch_exports = {};
29
- __export(prefetch_exports, {
30
- fetchSSRTranslations: () => fetchSSRTranslations,
31
- injectPrefetchedState: () => injectPrefetchedState,
32
- prefetchPageData: () => prefetchPageData
33
- });
34
- module.exports = __toCommonJS(prefetch_exports);
35
- const isFunction = (v) => typeof v === "function";
36
- const isArray = (v) => Array.isArray(v);
37
- const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
38
- const resolveParams = (params, mockState) => {
39
- if (!params) return void 0;
40
- if (isFunction(params)) {
41
- try {
42
- const mockEl = {
43
- state: mockState || {},
44
- call: () => void 0,
45
- __ref: {}
46
- };
47
- return params(mockEl, mockState || {});
48
- } catch {
49
- return void 0;
50
- }
51
- }
52
- return params;
53
- };
54
- const normalizeFetchConfig = (cfg, elementState) => {
55
- if (!cfg) return null;
56
- if (typeof cfg === "string") return { from: cfg, method: "select" };
57
- const resolved = isFunction(cfg) ? null : { ...cfg };
58
- if (!resolved) return null;
59
- if (!resolved.method) resolved.method = "select";
60
- if (isFunction(resolved.params)) {
61
- resolved.params = resolveParams(resolved.params, elementState);
62
- }
63
- const isMutation = resolved.method === "insert" || resolved.method === "update" || resolved.method === "upsert" || resolved.method === "delete";
64
- if (isMutation) return null;
65
- if (resolved.on && resolved.on !== "create") return null;
66
- return resolved;
67
- };
68
- const collectFetchDeclarations = (def, path = "") => {
69
- if (!def || typeof def !== "object") return [];
70
- if (isFunction(def)) return [];
71
- const results = [];
72
- const elementState = def.state || {};
73
- if (def.fetch) {
74
- const fetchDefs = isArray(def.fetch) ? def.fetch : [def.fetch];
75
- for (const fd of fetchDefs) {
76
- const config = normalizeFetchConfig(fd, elementState);
77
- if (config) {
78
- results.push({
79
- config,
80
- stateKey: config.as,
81
- path,
82
- elementState
83
- });
84
- }
85
- }
86
- }
87
- for (const key in def) {
88
- if (key === "fetch" || key === "state" || key === "props" || key === "attr" || key === "on" || key === "define" || key === "childExtends" || key === "childProps" || key === "childrenAs") continue;
89
- if (key.charAt(0) >= "A" && key.charAt(0) <= "Z" && isObject(def[key])) {
90
- results.push(...collectFetchDeclarations(def[key], path ? `${path}.${key}` : key));
91
- }
92
- }
93
- return results;
94
- };
95
- const createSSRAdapter = async (dbConfig) => {
96
- if (!dbConfig) return null;
97
- const { adapter, createClient, url, key, projectId } = dbConfig;
98
- if (adapter !== "supabase") return null;
99
- const supabaseUrl = url || projectId && `https://${projectId}.supabase.co`;
100
- if (!supabaseUrl || !key) return null;
101
- let clientFactory;
102
- try {
103
- const mod = await import("@supabase/supabase-js");
104
- clientFactory = mod.createClient;
105
- } catch {
106
- clientFactory = createClient;
107
- }
108
- if (!clientFactory) return null;
109
- const client = clientFactory(supabaseUrl, key);
110
- return {
111
- rpc: ({ from, params }) => client.rpc(from, params),
112
- select: async ({ from, select: sel, params, limit, offset, order, single }) => {
113
- let q = client.from(from).select(sel || "*");
114
- if (params) {
115
- for (const k in params) {
116
- const v = params[k];
117
- if (v === null) q = q.is(k, null);
118
- else if (Array.isArray(v)) q = q.in(k, v);
119
- else q = q.eq(k, v);
120
- }
121
- }
122
- if (order) {
123
- const orderBy = typeof order === "string" ? order : order.by;
124
- q = q.order(orderBy, { ascending: order.asc !== false });
125
- }
126
- if (limit) q = q.limit(limit);
127
- if (offset) q = q.range(offset, offset + (limit || 20) - 1);
128
- if (single) q = q.single();
129
- return q;
130
- }
131
- };
132
- };
133
- const executeSingle = async (adapter, config) => {
134
- try {
135
- const { method, from, params, transform, limit, offset, order, single } = config;
136
- let result;
137
- if (method === "rpc") {
138
- result = await adapter.rpc({ from, params });
139
- } else {
140
- result = await adapter.select({ from, select: config.select, params, limit, offset, order, single });
141
- }
142
- let data = result?.data ?? null;
143
- if (result?.error) {
144
- return null;
145
- }
146
- if (data && transform && isFunction(transform)) {
147
- try {
148
- data = transform(data);
149
- } catch {
150
- }
151
- }
152
- return data;
153
- } catch {
154
- return null;
155
- }
156
- };
157
- const prefetchPageData = async (data, route = "/", options = {}) => {
158
- const pages = data.pages || {};
159
- const pageDef = pages[route];
160
- if (!pageDef) return /* @__PURE__ */ new Map();
161
- const config = data.config || data.settings || {};
162
- const dbConfig = config.fetch || data.fetch || config.db || data.db;
163
- if (!dbConfig) return /* @__PURE__ */ new Map();
164
- const adapter = await createSSRAdapter(dbConfig);
165
- if (!adapter) return /* @__PURE__ */ new Map();
166
- const declarations = collectFetchDeclarations(pageDef);
167
- if (!declarations.length) return /* @__PURE__ */ new Map();
168
- const stateUpdates = /* @__PURE__ */ new Map();
169
- const results = await Promise.allSettled(
170
- declarations.map(async ({ config: config2, stateKey, path }) => {
171
- const fetchedData = await executeSingle(adapter, config2);
172
- if (fetchedData !== null) {
173
- const existing = stateUpdates.get(path) || {};
174
- if (stateKey) {
175
- existing[stateKey] = fetchedData;
176
- } else if (isObject(fetchedData)) {
177
- Object.assign(existing, fetchedData);
178
- }
179
- stateUpdates.set(path, existing);
180
- }
181
- })
182
- );
183
- return stateUpdates;
184
- };
185
- const fetchSSRTranslations = async (data) => {
186
- const config = data.config || {};
187
- const polyglot = config.polyglot || data.polyglot;
188
- if (!polyglot?.fetch) return null;
189
- const dbConfig = config.fetch || data.fetch || config.db || data.db;
190
- if (!dbConfig) return null;
191
- const adapter = await createSSRAdapter(dbConfig);
192
- if (!adapter) return null;
193
- const fetchConfig = polyglot.fetch;
194
- const rpcName = fetchConfig.rpc || fetchConfig.from || "get_translations_if_changed";
195
- const languages = polyglot.languages || [polyglot.defaultLang || "en"];
196
- const translations = {};
197
- const results = await Promise.allSettled(
198
- languages.map(async (lang) => {
199
- try {
200
- const res = await adapter.rpc({
201
- from: rpcName,
202
- params: { p_lang: lang, p_cached_version: 0 }
203
- });
204
- if (res.error || !res.data) return;
205
- const result = res.data;
206
- if (result.translations) {
207
- translations[lang] = result.translations;
208
- }
209
- } catch (e) {
210
- console.warn("[brender] SSR translation fetch failed:", e.message);
211
- }
212
- })
213
- );
214
- return Object.keys(translations).length ? translations : null;
215
- };
216
- const preEvaluateChildren = (def, inheritedState) => {
217
- if (!def || typeof def !== "object") return;
218
- for (const key in def) {
219
- if (key === "state" || key === "fetch" || key === "props" || key === "attr" || key === "on" || key === "define" || key === "childExtends" || key === "childProps" || key === "childrenAs") continue;
220
- if (key.charAt(0) >= "A" && key.charAt(0) <= "Z" && isObject(def[key])) {
221
- const child = def[key];
222
- const effectiveState = child.state && typeof child.state === "object" ? { ...inheritedState, ...child.state } : inheritedState;
223
- if (isFunction(child.children)) {
224
- try {
225
- const mockEl = {
226
- state: effectiveState,
227
- call: (fn) => {
228
- if (fn === "getActiveLang" || fn === "getLang") return effectiveState?.lang || "ka";
229
- if (fn === "polyglot") return arguments[1] || "";
230
- return void 0;
231
- },
232
- __ref: {}
233
- };
234
- const result = child.children(mockEl, effectiveState);
235
- if (isArray(result) && result.length > 0) {
236
- child.children = result;
237
- }
238
- } catch {
239
- }
240
- }
241
- preEvaluateChildren(child, effectiveState);
242
- }
243
- }
244
- };
245
- const injectPrefetchedState = (pageDef, stateUpdates) => {
246
- if (!stateUpdates || !stateUpdates.size) return;
247
- for (const [path, data] of stateUpdates) {
248
- let target = pageDef;
249
- if (path) {
250
- const parts = path.split(".");
251
- for (const part of parts) {
252
- if (!target || typeof target !== "object") break;
253
- target = target[part];
254
- }
255
- }
256
- if (target && typeof target === "object") {
257
- if (!target.state || typeof target.state !== "object") {
258
- target.state = {};
259
- }
260
- Object.assign(target.state, data);
261
- preEvaluateChildren(target, target.state);
262
- }
263
- }
264
- };