@uniweb/runtime 0.14.2 → 0.15.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.
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The isolate API — what `@uniweb/runtime/ssr` promises a host that renders in an
3
+ * isolate, and the runtime version below which that promise does not hold.
4
+ *
5
+ * ⭐ THE ONE PLACE THE NUMBER IS STATED. A host loads the SITE'S pinned runtime as a
6
+ * dynamically-loaded artifact — never an import — so it cannot link-check what it
7
+ * calls; it feature-detects, and an export that is missing looks exactly like an old
8
+ * runtime. The backend evaluates a site's runtime at publish and holds this floor as
9
+ * a constant of its own [Diego, 2026-09-04: "We will set a runtime version floor that
10
+ * guarantees they are there"], composing it as `max(absoluteFloor, foundationFloors)`.
11
+ * That constant is copied from here, and `tests/isolate-api.test.js` is what keeps
12
+ * this file honest: every export of `src/ssr.js` must appear below with the version
13
+ * it first shipped in, and every name below must still be exported — by the source
14
+ * and by the built `dist/ssr.js` when it is present. Forgetting to stamp a new export
15
+ * fails HERE, in the repo where the change happens; a rename fails here too.
16
+ *
17
+ * ⛔ A floor is a promise about a VERSION, not a rename guard. A site on a newer
18
+ * runtime with a renamed export is still a missing symbol; the test above is what
19
+ * makes that fail before it ships, and the announcement to the consumer is still
20
+ * ours to send (`framework/CLAUDE.md` § Decoupling is the architecture).
21
+ *
22
+ * ⛔ Not `runtime-pin.json`. That file is emitted per FOUNDATION build and records an
23
+ * observed fact ("built against"), never a guarantee; an isolate-API floor is a
24
+ * guarantee and is not a property of any foundation. Different kind of claim,
25
+ * different home.
26
+ *
27
+ * "since" is the first PUBLISHED version (git tag) whose `@uniweb/runtime/ssr`
28
+ * exported the name — measured with `git log --reverse -S<name> -- src/ssr.js` and
29
+ * `git tag --contains`, 2026-09-04.
30
+ */
31
+
32
+ /** Every export of `@uniweb/runtime/ssr`, with the version it first shipped in. */
33
+ export const ISOLATE_API = Object.freeze({
34
+ // props preparation
35
+ prepareProps: '0.2.15',
36
+ applySchemas: '0.2.15',
37
+ applyDefaults: '0.2.15',
38
+ guaranteeContentStructure: '0.2.15',
39
+ getComponentMeta: '0.2.15',
40
+ getComponentDefaults: '0.2.15',
41
+ // rendering
42
+ getWrapperProps: '0.6.14',
43
+ renderBackground: '0.6.14',
44
+ renderBlock: '0.6.14',
45
+ renderBlocks: '0.6.14',
46
+ renderLayout: '0.6.14',
47
+ renderPage: '0.2.15',
48
+ classifyRenderError: '0.6.14',
49
+ injectPageContent: '0.6.14',
50
+ escapeHtml: '0.6.14',
51
+ generate404Html: '0.6.16',
52
+ // initialization
53
+ initPrerender: '0.6.14',
54
+ initPrerenderForLocale: '0.8.9',
55
+ sliceContentForLocale: '0.8.9',
56
+ hydrateDataStore: '0.8.9',
57
+ prefetchIcons: '0.6.14',
58
+ renderAppearanceBootScript: '0.8.30',
59
+ // page resolution
60
+ resolvePage: '0.9.5',
61
+ // server-side prefetch — the runtime executing a page's fetches for a host
62
+ findPageForRoute: '0.14.1',
63
+ resolvePageFetchConfigs: '0.14.1',
64
+ executeFetchConfigs: '0.14.1',
65
+ prefetchPageData: '0.14.1',
66
+ // the composed render entry
67
+ createPageRenderer: '0.14.2',
68
+ prefetchAndHydrate: '0.14.2',
69
+ })
70
+
71
+ /**
72
+ * The runtime version at or above which EVERY name in `ISOLATE_API` is exported —
73
+ * the absolute floor a host may rely on with no feature detection.
74
+ */
75
+ export const ISOLATE_API_FLOOR = Object.values(ISOLATE_API).reduce((max, v) => (compareVersions(v, max) > 0 ? v : max), '0.0.0')
76
+
77
+ /** Compare two `x.y.z` versions numerically. Returns <0, 0 or >0. */
78
+ export function compareVersions(a, b) {
79
+ const pa = String(a).split('.').map((n) => parseInt(n, 10) || 0)
80
+ const pb = String(b).split('.').map((n) => parseInt(n, 10) || 0)
81
+ for (let i = 0; i < Math.max(pa.length, pb.length); i += 1) {
82
+ const d = (pa[i] || 0) - (pb[i] || 0)
83
+ if (d !== 0) return d
84
+ }
85
+ return 0
86
+ }
package/src/prefetch.js CHANGED
@@ -15,7 +15,7 @@
15
15
  *
16
16
  * ⛔ Contract with the host, deliberately small:
17
17
  * - `content` the render payload (`site-content.json` / `__DATA__`), config included —
18
- * `config.records`, `config.fetcher`, `config.base` are read from it.
18
+ * `config.records` and `config.base` are read from it.
19
19
  * - `route` the page to prefetch for; a `[slug]` template resolves through the same
20
20
  * matcher the SPA uses, so `/blog/post-1` finds `/blog/:slug`.
21
21
  * - `fetch` how to dispatch a request. The runtime composes the address; the host
@@ -37,7 +37,7 @@
37
37
  * (`build/src/prerender.js`) and never calls this. `'author'` is the explicit opt-in
38
38
  * for a caller that bakes; omitting the option must not silently reproduce the
39
39
  * 2026-07-28 outcome — prefetch a no-op on a live-data template, page still 200.
40
- * - returns one entry per DECLARED config, `{ config, outcome, data, error? }`, keyed
40
+ * - returns one entry per DECLARED config, `{ config, outcome, data, meta?, error? }`, keyed
41
41
  * downstream by `deriveCacheKey(config)`. `outcome` is `fetched`, `failed`
42
42
  * (transport or HTTP error, `error` says which) or `skipped` (the author
43
43
  * deferred it to the browser with `prerender: false`). `hydrateDataStore`
@@ -50,13 +50,18 @@
50
50
  */
51
51
  import { resolveFetchConfigs } from '@uniweb/core/fetch-config'
52
52
  import { deriveCacheKey } from '@uniweb/core/datastore'
53
- import { routePatternToRegex } from '@uniweb/core/route-match'
53
+ import { routePatternToRegex, decodeRouteValue, splitPathCapture } from '@uniweb/core/route-match'
54
+ import { buildDetailConfig } from '@uniweb/core/detail-url'
54
55
  import { resolveDefaultLocale } from '@uniweb/core/locale-config'
55
56
  import { createDefaultFetcher } from './default-fetcher.js'
56
57
 
57
58
  const isRefinement = (f) => f && typeof f === 'object' && f.refine === true
58
59
 
59
- /** The page a route names — exact first, then the `[slug]` templates, like the SPA. */
60
+ /**
61
+ * The page a route names — exact first, then the `[slug]` / `[...path]` templates, like
62
+ * the SPA. Captured params are decoded the way `matchDynamicRoute` decodes them (a
63
+ * catch-all per segment), so the values are what the site's query is bound against.
64
+ */
60
65
  export function findPageForRoute(content, route) {
61
66
  const pages = content?.pages || []
62
67
  const exact = pages.find((p) => p.route === route)
@@ -65,11 +70,35 @@ export function findPageForRoute(content, route) {
65
70
  if (!page.isDynamic || !page.route) continue
66
71
  const compiled = routePatternToRegex(page.route)
67
72
  const m = compiled?.regex ? compiled.regex.exec(route) : null
68
- if (m) return { page, params: Object.fromEntries((compiled.paramNames || []).map((n, i) => [n, m[i + 1]])) }
73
+ if (m) {
74
+ const params = {}
75
+ ;(compiled.paramNames || []).forEach((n, i) => {
76
+ const raw = m[i + 1]
77
+ params[n] = n === compiled.catchAll ? raw.split('/').map(decodeRouteValue).join('/') : decodeRouteValue(raw)
78
+ })
79
+ return { page, params }
80
+ }
69
81
  }
70
82
  return { page: null, params: {} }
71
83
  }
72
84
 
85
+ /**
86
+ * The route's variables and the delivery param for a matched template page — the same
87
+ * binding the SPA makes in `Website._createDynamicPage`: `[slug]` binds the one capture
88
+ * under the folder's own name; `[...path]` splits its capture into `path` / `dir` /
89
+ * `slug` and delivers by `slug`, the record's handle.
90
+ */
91
+ function routeBinding(page, params) {
92
+ const { catchAll } = routePatternToRegex(page.route)
93
+ if (catchAll && params[catchAll] !== undefined) {
94
+ const parts = splitPathCapture(params[catchAll])
95
+ const paramName = page.paramName || 'slug'
96
+ return { paramName, paramValue: parts.slug, variables: { ...params, ...parts } }
97
+ }
98
+ const paramName = page.paramName || Object.keys(params)[0]
99
+ return { paramName, paramValue: params[paramName], variables: { ...params } }
100
+ }
101
+
73
102
  /**
74
103
  * Every fetch config a page will need at render time, resolved once and de-duplicated by
75
104
  * cache key: the site-level fetch, the page's, its parent's, and each section's own
@@ -79,15 +108,17 @@ export function findPageForRoute(content, route) {
79
108
  * @returns {Object[]} resolved fetch configs
80
109
  */
81
110
  export function resolvePageFetchConfigs(content, route, { locale = null } = {}) {
82
- const { page } = findPageForRoute(content, route)
111
+ const { page, params } = findPageForRoute(content, route)
83
112
  if (!page) return []
84
113
  const pages = content?.pages || []
85
114
  const parent = page.parent ? pages.find((p) => p.route === page.parent) : null
115
+ const binding = page.isDynamic && Object.keys(params).length ? routeBinding(page, params) : null
86
116
  const options = {
87
117
  locale,
88
118
  defaultLocale: resolveDefaultLocale(content?.config) ?? null,
89
119
  queries: content?.config?.queries ?? null,
90
120
  records: content?.config?.records ?? null,
121
+ variables: binding?.variables ?? null,
91
122
  }
92
123
  const out = new Map()
93
124
  const add = (sources) => {
@@ -105,6 +136,23 @@ export function resolvePageFetchConfigs(content, route, { locale = null } = {})
105
136
  }
106
137
  }
107
138
  walk(page.sections)
139
+
140
+ // ⭐ A template page is ABOUT one record, and the record is a fetch of its own.
141
+ // The list the page inherits is what the entity store matches the route param
142
+ // against; when that query has a per-record source (a live lane's record address,
143
+ // a `deferred:` query's per-record file), the record itself comes from a second
144
+ // request — which this helper never built, so a host prerendering a template page
145
+ // got the BRIEF and the body arrived after hydration as a client fetch. The
146
+ // detail config is built by the one rule the
147
+ // entity store uses (`buildDetailConfig`), keyed by the route's param.
148
+ if (binding && binding.paramValue !== undefined && page.parentSchema) {
149
+ const listCfg = [...out.values()].find((cfg) => cfg.as === page.parentSchema && cfg.detail)
150
+ const detailCfg = listCfg ? buildDetailConfig(listCfg, { paramName: binding.paramName, paramValue: String(binding.paramValue) }) : null
151
+ if (detailCfg) {
152
+ const key = deriveCacheKey(detailCfg)
153
+ if (!out.has(key)) out.set(key, detailCfg)
154
+ }
155
+ }
108
156
  return [...out.values()]
109
157
  }
110
158
 
@@ -114,7 +162,7 @@ export function resolvePageFetchConfigs(content, route, { locale = null } = {})
114
162
  * @param {Object[]} configs resolved configs (from `resolvePageFetchConfigs` or the host's own
115
163
  * call to `resolveFetchConfigs`)
116
164
  * @param {Object} opts
117
- * @param {Object} opts.content the payload — `config.base`, `config.fetcher`, `config.records`
165
+ * @param {Object} opts.content the payload — `config.base`, `config.records`
118
166
  * @param {Function} [opts.fetch] the transport; defaults to the global `fetch`
119
167
  * @param {boolean} [opts.dev]
120
168
  * @returns {Promise<Array<{ config: Object, outcome: 'fetched'|'failed'|'skipped', data: any, error?: string }>>}
@@ -125,26 +173,24 @@ export async function executeFetchConfigs(configs, { content, fetch = null, dev
125
173
  }
126
174
  const fetcher = createDefaultFetcher({
127
175
  basePath: content?.config?.base || '',
128
- config: content?.config?.fetcher ?? {},
129
176
  records: content?.config?.records ?? null,
130
177
  dev,
131
178
  fetch,
132
179
  })
133
180
  const ctx = { website: null }
134
- const out = []
135
- for (const config of configs || []) {
136
- if (!config) continue
181
+ // Dispatched together, not one after another: a question door batches the
182
+ // requests issued in one tick into one POST, and a page's configs are
183
+ // independent of each other. Order is preserved in the result.
184
+ return Promise.all((configs || []).filter(Boolean).map(async (config) => {
137
185
  if (prerender === 'author' && config.prerender === false) {
138
186
  // The author deferred this one to the browser and the caller honours that. Present, so a
139
187
  // host can count what was declared against what was tried; not hydrated.
140
- out.push({ config, outcome: 'skipped', data: null })
141
- continue
188
+ return { config, outcome: 'skipped', data: null }
142
189
  }
143
190
  const result = await fetcher.resolve(config, ctx)
144
- if (result?.error) out.push({ config, outcome: 'failed', data: null, error: result.error })
145
- else out.push({ config, outcome: 'fetched', data: result?.data ?? null })
146
- }
147
- return out
191
+ if (result?.error) return { config, outcome: 'failed', data: null, error: result.error }
192
+ return { config, outcome: 'fetched', data: result?.data ?? null, ...(result?.meta ? { meta: result.meta } : {}) }
193
+ }))
148
194
  }
149
195
 
150
196
  /** Resolve and execute in one call: what a host passes the isolate as `fetchedData`. */
@@ -266,7 +266,7 @@ function applyRichSchemaToValue(value, schema) {
266
266
  * form-definition schema — which cannot name the author's fields — can never
267
267
  * reach into them. It fills the envelope defaults its own author declared.
268
268
  *
269
- * (Established with the editor team, 2026-07-31, channel frontend-framework-066d.
269
+ * (Established with the editor team, 2026-07-31, channel frontendframework.
270
270
  * The editor shadows a foundation's `form` declaration with its own builder via
271
271
  * `builtinSchemas()`; that is about the EDITING UI and is orthogonal to whether a
272
272
  * foundation declares a schema for validation.)
package/src/setup.js CHANGED
@@ -240,15 +240,17 @@ function buildDefaultFetcher(content) {
240
240
  // serve data wherever it likes — including intercepting a site-local path and
241
241
  // proxying it onward — with no framework change.
242
242
  const basePath = content?.config?.base || import.meta.env?.BASE_URL || ''
243
- // Per-site transport config from `site.yml fetcher:`. The default fetcher
244
- // recognizes `baseUrl` and `envelope`; foundations with their own fetchers
245
- // may read additional keys from the same block via ctx.website.config.fetcher.
246
- const config = content?.config?.fetcher ?? {}
243
+ // `site.yml fetcher:` is NOT read here — the default fetcher takes no
244
+ // site-level vocabulary (retired 2026-09-04: baseUrl / headers / envelope /
245
+ // supports / request). The block is the site's SELECTION of foundation
246
+ // transports (`fetcher.transports`) plus a transport's own binding config,
247
+ // which a transport reads through ctx.website.config.fetcher.
248
+ //
247
249
  // The host's live-records stamp (`config.records`), when a backend set one: the fetcher
248
250
  // reads its `envelope` for requests that resolved to that lane.
249
251
  const records = content?.config?.records ?? null
250
252
  const dev = !!(import.meta.env && import.meta.env.DEV)
251
- return createDefaultFetcher({ basePath, config, dev, records })
253
+ return createDefaultFetcher({ basePath, dev, records })
252
254
  }
253
255
 
254
256
  /**
@@ -166,7 +166,9 @@ export function hydrateDataStore(website, fetchedData) {
166
166
  // A `prefetchPageData` list carries every declared config with an `outcome`; only what was
167
167
  // actually fetched enters the store. A list without outcomes (the SSG lane's) is all fetched.
168
168
  if (entry.outcome && entry.outcome !== 'fetched') continue
169
- website.dataStore.set(deriveCacheKey(entry.config), { data: entry.data })
169
+ // `meta` (the depth the records were fetched at) rides along, so the store
170
+ // files them in its record index exactly as a runtime fetch would.
171
+ website.dataStore.set(deriveCacheKey(entry.config), entry.meta ? { data: entry.data, meta: entry.meta } : { data: entry.data })
170
172
  }
171
173
  }
172
174