@uniweb/runtime 0.21.0 → 0.23.0
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/ssr.js +46 -37
- package/dist/ssr.js.map +1 -1
- package/package.json +3 -3
- package/src/default-fetcher.js +22 -57
- package/src/isolate-api.js +12 -8
- package/src/prefetch.js +69 -15
package/dist/ssr.js
CHANGED
|
@@ -9,10 +9,11 @@ import { DEFAULT_ICON_BASE, iconUrl } from "@uniweb/core/icon-corpus";
|
|
|
9
9
|
import { buildTheme, FONT_LINKS_MARKER, buildSectionOverrides } from "@uniweb/theming";
|
|
10
10
|
import "@uniweb/core/services";
|
|
11
11
|
import "@uniweb/core/tracker";
|
|
12
|
-
import {
|
|
12
|
+
import { pageRouteQuery, siteReaches, resolveFetchConfigs, currentOf, othersView, routeSelection } from "@uniweb/core/fetch-config";
|
|
13
13
|
import { deriveCacheKey as deriveCacheKey$1 } from "@uniweb/core/datastore";
|
|
14
14
|
import { buildDetailConfig } from "@uniweb/core/detail-url";
|
|
15
15
|
import { resolveDefaultLocale as resolveDefaultLocale$1 } from "@uniweb/core/locale-config";
|
|
16
|
+
import { findLayoutEntry } from "@uniweb/core/layout-name";
|
|
16
17
|
import { resolveRecordsService } from "@uniweb/core/records-service";
|
|
17
18
|
function guaranteeItemStructure(item) {
|
|
18
19
|
return {
|
|
@@ -911,28 +912,12 @@ function createDefaultFetcher({ basePath = "", dev = false, fetch: fetchImpl = n
|
|
|
911
912
|
try {
|
|
912
913
|
const response = await readOnce(target, init);
|
|
913
914
|
if (ctx.signal?.aborted) return { data: [], error: "aborted" };
|
|
914
|
-
const envelope = request.envelope && typeof request.envelope === "object" ? request.envelope : {};
|
|
915
915
|
if (!response.ok) {
|
|
916
|
-
|
|
917
|
-
if (envelope.error && typeof response.text === "string") {
|
|
918
|
-
const body = safeParseJSON(response.text);
|
|
919
|
-
if (body !== void 0) {
|
|
920
|
-
const candidate = getNestedValue(body, envelope.error);
|
|
921
|
-
if (typeof candidate === "string" && candidate.length) {
|
|
922
|
-
extracted = candidate;
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
return {
|
|
927
|
-
data: [],
|
|
928
|
-
error: extracted ?? `HTTP ${response.status}: ${response.statusText}`
|
|
929
|
-
};
|
|
916
|
+
return { data: [], error: `HTTP ${response.status}: ${response.statusText}` };
|
|
930
917
|
}
|
|
931
918
|
let data = response.body;
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
if (effectiveTransform && data !== null && data !== void 0) {
|
|
935
|
-
data = getNestedValue(data, effectiveTransform);
|
|
919
|
+
if (transform && data !== null && data !== void 0) {
|
|
920
|
+
data = getNestedValue(data, transform);
|
|
936
921
|
}
|
|
937
922
|
data = applyOperators(data, request, { dev });
|
|
938
923
|
const whole = typeof request.whole === "boolean" ? request.whole : void 0;
|
|
@@ -951,7 +936,7 @@ function toQuestion(request) {
|
|
|
951
936
|
const where = request.where && typeof request.where === "object" ? request.where : null;
|
|
952
937
|
const scope = typeof request.scope === "string" && request.scope ? request.scope : null;
|
|
953
938
|
if (scope) q.scope = scope;
|
|
954
|
-
if (where) q.where =
|
|
939
|
+
if (where) q.where = where;
|
|
955
940
|
if (request.match && typeof request.match === "object") q.match = request.match;
|
|
956
941
|
const sort = sortToWire(request.sort);
|
|
957
942
|
if (sort) q.sort = sort;
|
|
@@ -960,16 +945,6 @@ function toQuestion(request) {
|
|
|
960
945
|
if (typeof request.cursor === "string" && request.cursor) q.cursor = request.cursor;
|
|
961
946
|
return q;
|
|
962
947
|
}
|
|
963
|
-
const OPERATOR_ALIAS = { nin: "not_in" };
|
|
964
|
-
function renameOperators(where) {
|
|
965
|
-
if (Array.isArray(where)) return where.map(renameOperators);
|
|
966
|
-
if (!where || typeof where !== "object") return where;
|
|
967
|
-
const out = {};
|
|
968
|
-
for (const [key, value] of Object.entries(where)) {
|
|
969
|
-
out[OPERATOR_ALIAS[key] ?? key] = value && typeof value === "object" ? renameOperators(value) : value;
|
|
970
|
-
}
|
|
971
|
-
return out;
|
|
972
|
-
}
|
|
973
948
|
const DEFAULT_MAX_PAGES = 20;
|
|
974
949
|
async function flushAsked(url, queue, doFetch) {
|
|
975
950
|
const pending = /* @__PURE__ */ new Map();
|
|
@@ -1140,12 +1115,27 @@ function safeParseJSON(text) {
|
|
|
1140
1115
|
return void 0;
|
|
1141
1116
|
}
|
|
1142
1117
|
}
|
|
1143
|
-
const isRefinement = (f) => f && typeof f === "object" && f.refine === true;
|
|
1144
1118
|
function parentPageOf(page, pages) {
|
|
1145
1119
|
const byRoute = new Map(pages.filter((p) => p?.route).map((p) => [p.route, p]));
|
|
1146
1120
|
const route = parentRouteOf(page.route, { declared: page.parent ?? null, has: (r) => byRoute.has(r) });
|
|
1147
1121
|
return route ? byRoute.get(route) : null;
|
|
1148
1122
|
}
|
|
1123
|
+
function layoutSectionsFor(content, page) {
|
|
1124
|
+
const sets = content?.layouts && typeof content.layouts === "object" ? content.layouts : {};
|
|
1125
|
+
const name = typeof page?.layout?.name === "string" && page.layout.name ? page.layout.name : null;
|
|
1126
|
+
const named = name ? findLayoutEntry(sets, name) : void 0;
|
|
1127
|
+
const chosen = name ? named ? [named] : [] : Object.values(sets);
|
|
1128
|
+
const out = [];
|
|
1129
|
+
const walk = (sections) => {
|
|
1130
|
+
for (const s of sections || []) {
|
|
1131
|
+
if (!s || typeof s !== "object") continue;
|
|
1132
|
+
out.push(s);
|
|
1133
|
+
walk(s.subsections);
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
for (const set of chosen) for (const area of Object.values(set || {})) walk(area?.sections);
|
|
1137
|
+
return out;
|
|
1138
|
+
}
|
|
1149
1139
|
function resolvePageFetchConfigs(content, route, { locale = null } = {}) {
|
|
1150
1140
|
const { page, params } = findPageForRoute(content, route);
|
|
1151
1141
|
if (!page) return [];
|
|
@@ -1160,7 +1150,15 @@ function resolvePageFetchConfigs(content, route, { locale = null } = {}) {
|
|
|
1160
1150
|
variables: binding?.variables ?? null
|
|
1161
1151
|
};
|
|
1162
1152
|
const siteFetch = content?.config?.fetch ?? null;
|
|
1163
|
-
const
|
|
1153
|
+
const chosen = binding ? pageRouteQuery(page, {
|
|
1154
|
+
routeOf: (p) => p.route,
|
|
1155
|
+
parentOf: (p) => parentPageOf(p, pages),
|
|
1156
|
+
fetchOf: (p) => p.fetch ?? null,
|
|
1157
|
+
sectionsOf: (p) => p.sections,
|
|
1158
|
+
site: siteFetch
|
|
1159
|
+
}) : null;
|
|
1160
|
+
const routeKey = chosen?.key ?? null;
|
|
1161
|
+
const routeSource = chosen?.nested ? chosen.config : null;
|
|
1164
1162
|
const out = /* @__PURE__ */ new Map();
|
|
1165
1163
|
const put = (cfg) => {
|
|
1166
1164
|
const key = deriveCacheKey$1(cfg);
|
|
@@ -1168,21 +1166,32 @@ function resolvePageFetchConfigs(content, route, { locale = null } = {}) {
|
|
|
1168
1166
|
};
|
|
1169
1167
|
const add = (sources) => {
|
|
1170
1168
|
for (const cfg of resolveFetchConfigs(sources, options).values()) {
|
|
1171
|
-
|
|
1172
|
-
if (
|
|
1169
|
+
const current = routeKey && cfg.as === routeKey ? currentOf(cfg) : null;
|
|
1170
|
+
if (current === "exclude") {
|
|
1171
|
+
put(othersView(cfg));
|
|
1172
|
+
continue;
|
|
1173
|
+
}
|
|
1174
|
+
if (current !== "only") {
|
|
1175
|
+
put(cfg);
|
|
1176
|
+
continue;
|
|
1177
|
+
}
|
|
1178
|
+
if (cfg.detail && binding.paramValue !== void 0) {
|
|
1173
1179
|
const detailCfg = buildDetailConfig(cfg, { paramName: binding.paramName, paramValue: String(binding.paramValue) });
|
|
1174
1180
|
if (detailCfg) put(detailCfg);
|
|
1175
1181
|
}
|
|
1182
|
+
put(cfg.ask ? cfg : routeSelection(cfg));
|
|
1176
1183
|
}
|
|
1177
1184
|
};
|
|
1178
|
-
|
|
1185
|
+
const siteForPage = siteReaches(parent) ? siteFetch : null;
|
|
1186
|
+
add([page.fetch ?? null, parent?.fetch ?? null, routeSource, siteForPage]);
|
|
1179
1187
|
const walk = (sections) => {
|
|
1180
1188
|
for (const s of sections || []) {
|
|
1181
|
-
if (s?.fetch
|
|
1189
|
+
if (s?.fetch) add([s.fetch, page.fetch ?? null, parent?.fetch ?? null, routeSource, siteForPage]);
|
|
1182
1190
|
if (s?.subsections) walk(s.subsections);
|
|
1183
1191
|
}
|
|
1184
1192
|
};
|
|
1185
1193
|
walk(page.sections);
|
|
1194
|
+
for (const s of layoutSectionsFor(content, page)) add([s.fetch ?? null, siteFetch]);
|
|
1186
1195
|
return [...out.values()];
|
|
1187
1196
|
}
|
|
1188
1197
|
async function executeFetchConfigs(configs, { content, fetch: fetch2 = null, dev = false, prerender = "always" } = {}) {
|