@uniweb/runtime 0.15.0 → 0.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/runtime",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "Minimal runtime for loading Uniweb foundations",
5
5
  "type": "module",
6
6
  "exports": {
@@ -36,7 +36,7 @@
36
36
  "node": ">=20.19"
37
37
  },
38
38
  "dependencies": {
39
- "@uniweb/core": "^0.20.0",
39
+ "@uniweb/core": "^0.22.0",
40
40
  "@uniweb/theming": "^0.1.15"
41
41
  },
42
42
  "devDependencies": {
@@ -44,7 +44,7 @@
44
44
  "esbuild": "^0.21.0 || ^0.23.0 || ^0.24.0 || ^0.25.0 || ^0.27.0",
45
45
  "vite": "^7.3.1",
46
46
  "vitest": "^4.1.7",
47
- "@uniweb/build": "0.37.1"
47
+ "@uniweb/build": "0.39.0"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "react": "^19.0.0",
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Every record a site's declared queries return — for a host building something
3
+ * over the whole corpus rather than rendering one page.
4
+ *
5
+ * ## Why this is framework's and not the caller's
6
+ *
7
+ * A host that indexes a site has to ask the same questions the site's pages ask.
8
+ * ⛔ **If it composes its own, the index and the page can disagree**, and the way
9
+ * they disagree is the worst one available: the index offers a result whose page
10
+ * then renders empty. That is the two-answers-to-one-question failure the GET
11
+ * lane was retired for, reintroduced one lane over.
12
+ *
13
+ * ⇒ So the composition is not duplicated here either. This walks the site's
14
+ * `config.queries`, hands each one to `resolveFetchConfigs` — **the same rule a
15
+ * page render uses**, applying each saved query's own `scope` / `where` / `sort`
16
+ * / `limit` — and asks through the same client. What differs from a page is two
17
+ * fields and nothing else: `depth: 'brief'` (an index wants what a list shows)
18
+ * and `exhaustive: true` (a corpus is not a page, so it follows `cursors` to the
19
+ * end; the records contract bounds a single answer at 100).
20
+ *
21
+ * ## What the caller supplies
22
+ *
23
+ * ⭐ **The transport, and nothing else.** A host outside a browser decides how a
24
+ * site-relative address is dispatched — through its own origin, a service
25
+ * binding, a forwarding table that turns `/_…` into an upstream — and hands that
26
+ * in as `fetch`. **Framework decides what to ask and how to read the answer;
27
+ * the host decides how the bytes travel.** That split is the whole of the
28
+ * boundary here.
29
+ *
30
+ * ⛔ **A site with no records service is not an error.** It has no live records,
31
+ * so this returns empty rather than throwing: a static site's corpus comes from
32
+ * its own compiled artifacts, which the caller already has.
33
+ */
34
+
35
+ import { resolveFetchConfigs } from '@uniweb/core/fetch-config'
36
+ import { resolveRecordsService } from '@uniweb/core/records-service'
37
+ import { createDefaultFetcher } from './default-fetcher.js'
38
+
39
+ /**
40
+ * Ask a site's records service for every record its declared queries return.
41
+ *
42
+ * @param {Object} content - the render payload (`config.services`, `config.queries`)
43
+ * @param {Object} options
44
+ * @param {string} options.locale - the locale to ask in; it is a route segment
45
+ * of the service's address, so there is no asking without one
46
+ * @param {Function} options.fetch - the transport, `(url, init) => Response`
47
+ * @param {AbortSignal} [options.signal]
48
+ * @param {string[]} [options.only] - restrict to these query names
49
+ * @returns {Promise<{records: Object, errors: Object|null, meta: Object}>}
50
+ * `records` is keyed by query NAME, each a flat array; `errors` is keyed the
51
+ * same and is null when nothing failed; `meta[name]` carries `{ depth, pages,
52
+ * truncated? }` — `truncated` meaning the loop hit its own bound, never that
53
+ * the site has more.
54
+ */
55
+ export async function collectSiteRecords(content, { locale, fetch, signal, only = null } = {}) {
56
+ const config = content?.config
57
+ const services = config?.services ?? null
58
+ const queries = config?.queries ?? null
59
+
60
+ // No service, no queries, or no locale to ask in ⇒ nothing to collect. Each is
61
+ // an ordinary state of a site, not a fault: the caller reads its own artifacts.
62
+ if (!queries || typeof queries !== 'object') return empty()
63
+ if (!resolveRecordsService(services, locale)) return empty()
64
+
65
+ const names = Object.keys(queries).filter((n) => (only ? only.includes(n) : true))
66
+ if (names.length === 0) return empty()
67
+
68
+ // One synthetic source per query — `as` is the query's own name, so the answer
69
+ // comes back under the name the caller asked by.
70
+ const configs = resolveFetchConfigs(
71
+ names.map((name) => ({ query: name, as: name })),
72
+ { services, queries, locale, defaultLocale: config?.defaultLanguage ?? locale },
73
+ )
74
+
75
+ const fetcher = createDefaultFetcher({ fetch, basePath: config?.base ?? '' })
76
+ const records = {}
77
+ const errors = {}
78
+ const meta = {}
79
+
80
+ await Promise.all([...configs].map(async ([name, cfg]) => {
81
+ // ⛔ Only a config the service answers. A query that resolved to a compiled
82
+ // `path` has no live lane, and reading that file is the caller's business,
83
+ // not ours — it is in the site's own URL space and they already serve it.
84
+ if (!cfg.ask) return
85
+ const result = await fetcher.resolve({ ...cfg, depth: 'brief', exhaustive: true }, { signal })
86
+ if (result?.error) {
87
+ errors[name] = result.error
88
+ return
89
+ }
90
+ records[name] = Array.isArray(result?.data) ? result.data : []
91
+ if (result?.meta) meta[name] = result.meta
92
+ }))
93
+
94
+ return { records, errors: Object.keys(errors).length ? errors : null, meta }
95
+ }
96
+
97
+ function empty() {
98
+ return { records: {}, errors: null, meta: {} }
99
+ }
@@ -6,22 +6,19 @@
6
6
  * starter/docs/marketing templates hitting /data/*.json — ride on this path
7
7
  * with zero config, and so does a site a host serves live.
8
8
  *
9
- * ⭐ It speaks exactly THREE lanes, and takes NO site-level vocabulary for a
9
+ * ⭐ It speaks exactly TWO lanes, and takes NO site-level vocabulary for a
10
10
  * backend of the author's own:
11
11
  *
12
12
  * - a compiled file — `path:` under the site's base (`/data/<query>.json`,
13
13
  * a per-record file), or a plain JSON `url:` the author wrote;
14
- * - the host's ADDRESS DOOR — `endpoint:`, resolved upstream from the
15
- * `config.records` stamp (`@uniweb/core/query-address`), unwrapped with
16
- * the stamp's own `envelope.records`;
17
- * - the host's QUESTION DOOR — `door:`, one POST per tick carrying every
18
- * question the page asked, answered per key (the records door's contract,
19
- * as this client reads it).
14
+ * - the host's RECORDS SERVICE — `ask:`, one POST per tick carrying every
15
+ * question the page asked, answered per key (the records contract, as this
16
+ * client reads it).
20
17
  *
21
18
  * `where:` / `sort:` / `limit:` are evaluated HERE, locally, over what the
22
- * first two lanes return — with `@uniweb/core`'s one evaluator, the same the
23
- * build uses to materialize a file — and by the source on the third. Nothing
24
- * decides that per site: the LANE decides.
19
+ * first lane returns — with `@uniweb/core`'s one evaluator, the same the build
20
+ * uses to materialize a file — and at the source when asked. Nothing decides
21
+ * that per site: the LANE decides.
25
22
  *
26
23
  * ⛔ RETIRED 2026-09-04 [Diego]: `fetcher.baseUrl`, `headers`, `envelope`,
27
24
  * `supports`, `request.style` / `request.rename` and the `json-body`
@@ -67,9 +64,6 @@ import {
67
64
  * for subpath deployments. Remote URLs pass through unchanged.
68
65
  * @param {boolean} [options.dev=false] - Dev-mode diagnostics: a bad `sort:`
69
66
  * throws instead of delivering the records unsorted.
70
- * @param {Object|null} [options.records=null] - The host's `config.records`
71
- * stamp; its `envelope.records` names the key a list sits under on the
72
- * address door.
73
67
  * @param {Function|null} [options.fetch=null] - The transport. A host executing
74
68
  * fetches outside a browser (an SSR isolate) decides how a site-relative
75
69
  * address is dispatched — through its own origin or a service binding — and
@@ -77,51 +71,49 @@ import {
77
71
  * test stub installed later is honoured.
78
72
  * @returns {{ cacheKey: (req: Object) => string, resolve: (req: Object, ctx: Object) => Promise<{ data, error?, meta? }> }}
79
73
  */
80
- export function createDefaultFetcher({ basePath = '', dev = false, records = null, fetch: fetchImpl = null } = {}) {
74
+ export function createDefaultFetcher({ basePath = '', dev = false, fetch: fetchImpl = null } = {}) {
81
75
  const doFetch = (input, init) => (fetchImpl || globalThis.fetch)(input, init)
82
76
  const pathPrefix = basePath && basePath !== '/' ? basePath.replace(/\/$/, '') : ''
83
77
 
84
- // ⭐ The LIVE LANE's envelope is the backend's. `config.records` is stamped by the backend
85
- // that answers a records request, so where the array sits in ITS response is its to
86
- // declare: `records.envelope.records` — the KEY says what it holds, the VALUE is the JSON
87
- // key the array sits under (`{ records: "entries" }` ⇒ body.entries). That spelling is the
88
- // agreed one (2026-08-30: `collection` retired; ⛔ not `list`, which is a URL pattern on the
89
- // same stamp). It applies only to a request that resolved to that lane (`endpoint` set).
90
- // Ruled 2026-09-03 [Diego]: the backend sets `config.records`; the fetch comes from the
91
- // runtime.
92
- const stampedArrayKey = (records?.envelope && typeof records.envelope === 'object'
93
- && typeof records.envelope.records === 'string' && records.envelope.records.length)
94
- ? records.envelope.records
95
- : null
96
- const laneEnvelope = stampedArrayKey ? { list: stampedArrayKey } : null
97
78
 
98
- // ⭐ THE QUESTION DOOR — a batch of the misses, one POST, merged per key.
79
+ // ⭐ THE RECORDS SERVICE — a batch of the misses, one POST, merged per key.
99
80
  //
100
81
  // The entity store dispatches every config a page needs in one synchronous
101
- // loop before awaiting any of them, so a door request enqueued here and
102
- // flushed on the next microtask carries every miss of that page in one body
103
- // The batch response is never cached as
104
- // one: each request gets its own answer, keyed by its own question.
105
- const doorQueues = new Map()
106
- const askDoor = (request, ctx) =>
107
- new Promise((resolve) => {
108
- const url = resolveServiceUrl(request.door, pathPrefix)
109
- let queue = doorQueues.get(url)
82
+ // loop before awaiting any of them, so a question enqueued here and flushed
83
+ // on the next microtask carries every miss of that page in one body. The
84
+ // batch response is never cached as one: each request gets its own answer,
85
+ // keyed by its own question.
86
+ const askQueues = new Map()
87
+ const askRecords = (request, ctx) => {
88
+ // A question needs the query's Model ref. A payload that offers the
89
+ // service and carries no `config.queries` entry for the query cannot ask;
90
+ // that is a producer defect and it is said here, per key, with no request.
91
+ if (typeof request.schema !== 'string' || !request.schema) {
92
+ return Promise.resolve({
93
+ data: null,
94
+ error: `the payload offers the records service but carries no Model ref for query ` +
95
+ `"${request.query ?? request.as}" (config.queries) — it cannot be asked`,
96
+ })
97
+ }
98
+ return new Promise((resolve) => {
99
+ const url = resolveServiceUrl(request.ask, pathPrefix)
100
+ let queue = askQueues.get(url)
110
101
  if (!queue) {
111
102
  queue = []
112
- doorQueues.set(url, queue)
103
+ askQueues.set(url, queue)
113
104
  queueMicrotask(() => {
114
- doorQueues.delete(url)
115
- flushDoor(url, queue, doFetch)
105
+ askQueues.delete(url)
106
+ flushAsked(url, queue, doFetch)
116
107
  })
117
108
  }
118
109
  queue.push({ request, ctx, resolve })
119
110
  })
111
+ }
120
112
 
121
113
  return {
122
114
  /**
123
- * The cache identity is the request's ADDRESS — or, on a question door,
124
- * the QUESTION (`deriveCacheKey` hashes every operator of an address-less
115
+ * The cache identity is the request's ADDRESS — or, when asked of the
116
+ * records service, the QUESTION (`deriveCacheKey` hashes every operator of an address-less
125
117
  * request). Operators evaluated here run over a shared cached value and
126
118
  * must NOT split the cache: two pages declaring different `where:` clauses
127
119
  * against the same path share one entry — the file is fetched once and
@@ -133,8 +125,8 @@ export function createDefaultFetcher({ basePath = '', dev = false, records = nul
133
125
 
134
126
  async resolve(request, ctx = {}) {
135
127
  if (!request) return { data: null }
136
- if (request.door) return askDoor(request, ctx)
137
- const { path, url, endpoint, transform, body: rawBody } = request
128
+ if (request.ask) return askRecords(request, ctx)
129
+ const { path, url, transform, body: rawBody } = request
138
130
 
139
131
  // Normalize method. Only GET and POST are supported by the default
140
132
  // fetcher — mutations (PUT/PATCH/DELETE) are a different feature
@@ -146,24 +138,7 @@ export function createDefaultFetcher({ basePath = '', dev = false, records = nul
146
138
  }
147
139
 
148
140
  let target
149
- if (endpoint) {
150
- // The host's address door, resolved upstream from the pattern it
151
- // published. FINAL ON ARRIVAL: the site `base` is applied to a rooted
152
- // address — the same rule every other site-relative address follows,
153
- // shared with `resolveServiceUrl` rather than spelled a second time —
154
- // and nothing else is joined onto it. A pattern may carry a site id,
155
- // its own root, any layout at all; none of it is ours.
156
- target = resolveServiceUrl(endpoint, pathPrefix)
157
- // ⭐ The locale rides as a query param on the address door — the config
158
- // carries one only on a non-default-locale live request (F1). Until
159
- // 2026-09-04 nothing put it on the wire, so localized fields arrived as
160
- // `{lang: …}` maps; hosting confirmed that day that an appended `?locale=`
161
- // passes through their reshape verbatim, on both the browser and the
162
- // isolate path, and backend answers it with the locale's strings.
163
- if (typeof request.locale === 'string' && request.locale) {
164
- target += (target.includes('?') ? '&' : '?') + 'locale=' + encodeURIComponent(request.locale)
165
- }
166
- } else if (path) {
141
+ if (path) {
167
142
  // Local file under public/ — basePath applies for subpath deploys.
168
143
  target = pathPrefix && path.startsWith('/') && !path.startsWith('//')
169
144
  ? pathPrefix + path
@@ -172,7 +147,7 @@ export function createDefaultFetcher({ basePath = '', dev = false, records = nul
172
147
  // A URL the author wrote, sent exactly as written.
173
148
  target = url
174
149
  } else {
175
- return { data: [], error: 'No path, url or endpoint specified' }
150
+ return { data: [], error: 'No path, url or ask specified' }
176
151
  }
177
152
 
178
153
  const init = { signal: ctx.signal, method }
@@ -196,11 +171,10 @@ export function createDefaultFetcher({ basePath = '', dev = false, records = nul
196
171
  const response = await doFetch(target, init)
197
172
 
198
173
  // A per-request envelope (set by the object form of `detail:`) describes
199
- // this one response; on the address door the stamp describes the lane.
200
- const requestEnvelope = (request.envelope && typeof request.envelope === 'object')
174
+ // this one response.
175
+ const envelope = (request.envelope && typeof request.envelope === 'object')
201
176
  ? request.envelope
202
- : null
203
- const envelope = requestEnvelope ?? (endpoint && laneEnvelope ? laneEnvelope : {})
177
+ : {}
204
178
 
205
179
  if (!response.ok) {
206
180
  // If `envelope.error` names a path, try to extract a human message
@@ -256,11 +230,10 @@ export function createDefaultFetcher({ basePath = '', dev = false, records = nul
256
230
  // it returned.
257
231
  data = applyOperators(data, request, { dev })
258
232
 
259
- // ⭐ Say what depth was delivered, so the record index can file it. On
260
- // the address door that is what the config asked for a list at brief
261
- // depth when the query has a per-record source, a record in full so
262
- // the config's `depth` is echoed. A door that reports `depths` per key
263
- // will override this with what it actually served.
233
+ // ⭐ Say what depth was delivered, so the record index can file it — what
234
+ // the config asked for, echoed: a list at brief depth when the query has
235
+ // a per-record source, a record in full. (The service reports `depths` per
236
+ // key and overrides this with what it actually served.)
264
237
  const depth = request.depth === 'brief' || request.depth === 'full' ? request.depth : undefined
265
238
  return depth ? { data: data ?? [], meta: { depth } } : { data: data ?? [] }
266
239
  } catch (error) {
@@ -274,16 +247,16 @@ export function createDefaultFetcher({ basePath = '', dev = false, records = nul
274
247
  }
275
248
 
276
249
  /**
277
- * One question of a door batch, in the door's own vocabulary
278
- * (the records door's contract, §2): `schema` required, `scope` a bare
279
- * path, `sort` one key spelled `date` / `-date`, `depth` brief or full. The
280
- * where-object crosses as authored except for the two spellings the language
281
- * settled differently from the evaluator's: `nin` is `not_in` there, and a
282
- * top-level `path: { under }` — the file lane's way of naming a folder branch —
283
- * is the door's `scope`. Anything the door does not accept (`like`, a dotted
284
- * path) is sent as written and refused there by name: loud, never approximated.
250
+ * One question of a batch, in the records service's own vocabulary
251
+ * (the records contract, §2): `schema` required, `scope` a bare path, `sort`
252
+ * one key spelled `date` / `-date`, `depth` brief or full. The where-object
253
+ * crosses as authored except for the two spellings the language settled
254
+ * differently from the evaluator's: `nin` is `not_in` there, and a top-level
255
+ * `path: { under }` — the file lane's way of naming a folder branch — is
256
+ * `scope`. Anything the service does not accept (`like`, a dotted path) is
257
+ * sent as written and refused there by name: loud, never approximated.
285
258
  */
286
- function doorQuestion(request) {
259
+ function toQuestion(request) {
287
260
  const q = { schema: request.schema }
288
261
  let where = request.where && typeof request.where === 'object' ? request.where : null
289
262
  let scope = typeof request.scope === 'string' && request.scope ? request.scope : null
@@ -298,31 +271,61 @@ function doorQuestion(request) {
298
271
  if (sort) q.sort = sort
299
272
  if (typeof request.limit === 'number' && request.limit > 0) q.limit = request.limit
300
273
  if (request.depth === 'brief' || request.depth === 'full') q.depth = request.depth
274
+ // ⭐ `cursor` is the ONLY field here that is not the author's: it is opaque and
275
+ // it comes from a previous answer's `cursors` (the records contract §2). ⛔ And
276
+ // `exhaustive` deliberately does NOT cross — it is a client instruction about
277
+ // how many times to ask, not part of the question being asked.
278
+ if (typeof request.cursor === 'string' && request.cursor) q.cursor = request.cursor
301
279
  return q
302
280
  }
303
281
 
304
- const DOOR_OPERATOR = { nin: 'not_in' }
282
+ const OPERATOR_ALIAS = { nin: 'not_in' }
305
283
  function renameOperators(where) {
306
284
  if (Array.isArray(where)) return where.map(renameOperators)
307
285
  if (!where || typeof where !== 'object') return where
308
286
  const out = {}
309
287
  for (const [key, value] of Object.entries(where)) {
310
- out[DOOR_OPERATOR[key] ?? key] = value && typeof value === 'object' ? renameOperators(value) : value
288
+ out[OPERATOR_ALIAS[key] ?? key] = value && typeof value === 'object' ? renameOperators(value) : value
311
289
  }
312
290
  return out
313
291
  }
314
292
 
315
293
  /**
316
- * Send one batch to a door and hand each question its own answer.
294
+ * Send one batch to the records service and hand each question its own answer.
295
+ *
296
+ * The response is `{ data, depths?, errors?, cursors?, limits? }` (contract §5):
297
+ * `data` answers exactly the keys sent, `[]` when nothing matched; a key that
298
+ * ERRORED is absent from `data` and present in `errors`; `depths` says what was
299
+ * actually served, which the record index files rather than what was asked for.
300
+ * A key missing from both is a protocol violation and is reported as an error,
301
+ * never as silence.
302
+ *
303
+ * ⭐ `cursors` AND `limits` ARE READ — 2026-09-06 [Diego], reversing the ruling
304
+ * that had them "received and IGNORED, because framework has no paging concept."
305
+ * ⛔ **That ruling described our client and was silently wrong about our USERS:**
306
+ * the service bounds every answer at 100 (the records contract §4.2/§5), and a
307
+ * `cursors` entry is how it says there is more. Discarding both meant a hosted
308
+ * list of 500 rendered 100 — no error, no warning, no way for an author to tell
309
+ * a bound from the end of the data. **The silent class, on a visitor's page.**
317
310
  *
318
- * The response is `{ data, depths?, errors? }` (contract §5): `data` answers
319
- * exactly the keys sent, `[]` when nothing matched; a key that ERRORED is absent
320
- * from `data` and present in `errors`; `depths` says what was actually served,
321
- * which the record index files rather than what was asked for. A key missing
322
- * from both is a protocol violation and is reported as an error, never as
323
- * silence.
311
+ * Two behaviours, deliberately not one:
312
+ *
313
+ * - **a page render REPORTS** `meta.truncated` and `meta.bound` ride the
314
+ * answer, and nothing pages automatically. Auto-paging here would put
315
+ * unbounded round trips in front of paint for a section that may only show
316
+ * ten rows.
317
+ * - **an exhaustive caller PAGES** — `request.exhaustive` follows `cursors`
318
+ * until the service stops issuing them. `collectSiteRecords` is the caller
319
+ * that wants it (a corpus is not a page), and `maxPages` bounds the loop so
320
+ * a service that always answers with a cursor cannot spin.
324
321
  */
325
- async function flushDoor(url, queue, doFetch) {
322
+
323
+ /** Pages an exhaustive request will follow before giving up and reporting truncation. */
324
+ const MAX_PAGES = 50
325
+ async function flushAsked(url, queue, doFetch) {
326
+ // One shared page loop: the batch is sent, and any entry that asked to be
327
+ // exhaustive and came back with a cursor is re-sent alone until it is done.
328
+ const pending = new Map()
326
329
  const body = {}
327
330
  const keys = []
328
331
  for (const entry of queue) {
@@ -330,7 +333,7 @@ async function flushDoor(url, queue, doFetch) {
330
333
  let key = base
331
334
  for (let n = 2; key in body; n += 1) key = `${base}#${n}`
332
335
  keys.push(key)
333
- body[key] = doorQuestion(entry.request)
336
+ body[key] = toQuestion(entry.request)
334
337
  }
335
338
  let parsed
336
339
  try {
@@ -340,7 +343,19 @@ async function flushDoor(url, queue, doFetch) {
340
343
  body: JSON.stringify(body),
341
344
  })
342
345
  if (!response.ok) {
343
- const error = `HTTP ${response.status}: ${response.statusText}`
346
+ // A protocol violation is refused for the WHOLE request with a problem body
347
+ // whose `detail` names the key and the fault (an unknown operator, an empty
348
+ // binding key, a non-BCP-47 locale segment…). Surface that sentence on every
349
+ // key of the batch rather than the bare status: the author reads
350
+ // `block.dataError` and the status alone says nothing they can act on.
351
+ let detail = null
352
+ try {
353
+ const problem = safeParseJSON(await response.text())
354
+ if (problem && typeof problem.detail === 'string' && problem.detail) detail = problem.detail
355
+ } catch { /* an unreadable body falls back to the status line */ }
356
+ const error = detail
357
+ ? `HTTP ${response.status}: ${detail}`
358
+ : `HTTP ${response.status}: ${response.statusText}`
344
359
  for (const entry of queue) entry.resolve({ data: null, error })
345
360
  return
346
361
  }
@@ -353,22 +368,79 @@ async function flushDoor(url, queue, doFetch) {
353
368
  const data = parsed && typeof parsed.data === 'object' && parsed.data ? parsed.data : {}
354
369
  const errors = parsed && typeof parsed.errors === 'object' && parsed.errors ? parsed.errors : {}
355
370
  const depths = parsed && typeof parsed.depths === 'object' && parsed.depths ? parsed.depths : {}
371
+ // Both absent when empty, never `{}` (the records contract §5).
372
+ const cursors = parsed && typeof parsed.cursors === 'object' && parsed.cursors ? parsed.cursors : {}
373
+ const limits = parsed && typeof parsed.limits === 'object' && parsed.limits ? parsed.limits : {}
356
374
  queue.forEach((entry, i) => {
357
375
  const key = keys[i]
358
376
  if (key in errors) {
377
+ // A per-key error is `{ code, detail }` — `schema_not_found`,
378
+ // `field_not_in_brief`, `scope_not_found`… The sentence is `detail`; `code`
379
+ // rides beside it for a reader that wants to branch on it.
359
380
  const e = errors[key]
360
- entry.resolve({ data: null, error: typeof e === 'string' ? e : (e?.message || JSON.stringify(e)) })
381
+ const detail = typeof e === 'string' ? e : (e?.detail || e?.message || JSON.stringify(e))
382
+ const out = { data: null, error: detail }
383
+ if (e && typeof e === 'object' && typeof e.code === 'string') out.code = e.code
384
+ entry.resolve(out)
361
385
  return
362
386
  }
363
387
  if (!(key in data)) {
364
- entry.resolve({ data: null, error: `the records door answered without the key "${key}"` })
388
+ entry.resolve({ data: null, error: `the records service answered without the key "${key}"` })
365
389
  return
366
390
  }
367
391
  const depth = depths[key] === 'brief' || depths[key] === 'full'
368
392
  ? depths[key]
369
393
  : (entry.request.depth === 'brief' || entry.request.depth === 'full' ? entry.request.depth : undefined)
370
- entry.resolve(depth ? { data: data[key], meta: { depth } } : { data: data[key] })
394
+
395
+ const cursor = typeof cursors[key] === 'string' && cursors[key] ? cursors[key] : null
396
+ const bound = typeof limits[key] === 'number' ? limits[key] : undefined
397
+ const rows = Array.isArray(data[key]) ? data[key] : data[key]
398
+
399
+ // An exhaustive caller collects the page and asks for the next one.
400
+ if (cursor && entry.request.exhaustive && Array.isArray(rows)) {
401
+ const acc = entry.collected ? entry.collected.concat(rows) : rows.slice()
402
+ const page = (entry.page || 1) + 1
403
+ if (page <= MAX_PAGES) {
404
+ pending.set(entry, { cursor, collected: acc, page, depth, bound })
405
+ return
406
+ }
407
+ // The loop's own bound, not the service's: report rather than spin.
408
+ entry.resolve({ data: acc, meta: withMeta({ depth, bound, truncated: true, pages: MAX_PAGES }) })
409
+ return
410
+ }
411
+
412
+ const collected = entry.collected ? entry.collected.concat(Array.isArray(rows) ? rows : []) : rows
413
+ const meta = withMeta({
414
+ depth,
415
+ bound,
416
+ // ⭐ A cursor IS the truncation signal, and it is the only one for a query
417
+ // that declared no `limit`: `limits` is reported only when an author's own
418
+ // limit was clamped (the records contract §5).
419
+ truncated: cursor ? true : undefined,
420
+ pages: entry.page && entry.page > 1 ? entry.page : undefined,
421
+ })
422
+ entry.resolve(meta ? { data: collected, meta } : { data: collected })
371
423
  })
424
+
425
+ if (pending.size === 0) return
426
+ // Re-ask each unfinished key on its own — the cursor is per key, so a batch
427
+ // would have to correlate several independent positions through one body.
428
+ await Promise.all([...pending].map(([entry, state]) => {
429
+ const next = {
430
+ ...entry,
431
+ request: { ...entry.request, cursor: state.cursor },
432
+ collected: state.collected,
433
+ page: state.page,
434
+ }
435
+ return flushAsked(url, [next], doFetch)
436
+ }))
437
+ }
438
+
439
+ /** Build a `meta` from the fields that are actually present, or `undefined`. */
440
+ function withMeta(fields) {
441
+ const out = {}
442
+ for (const [k, v] of Object.entries(fields)) if (v !== undefined) out[k] = v
443
+ return Object.keys(out).length ? out : undefined
372
444
  }
373
445
 
374
446
  /**
@@ -17,7 +17,8 @@
17
17
  * ⛔ A floor is a promise about a VERSION, not a rename guard. A site on a newer
18
18
  * runtime with a renamed export is still a missing symbol; the test above is what
19
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).
20
+ * ours to send, because a consumer that bundles this package by workspace link
21
+ * gets the change at commit time, with no version to pin against.
21
22
  *
22
23
  * ⛔ Not `runtime-pin.json`. That file is emitted per FOUNDATION build and records an
23
24
  * observed fact ("built against"), never a guarantee; an isolate-API floor is a
@@ -27,8 +28,46 @@
27
28
  * "since" is the first PUBLISHED version (git tag) whose `@uniweb/runtime/ssr`
28
29
  * exported the name — measured with `git log --reverse -S<name> -- src/ssr.js` and
29
30
  * `git tag --contains`, 2026-09-04.
31
+ *
32
+ * ## ⭐ `UNRELEASED` — and why the mechanism needed it
33
+ *
34
+ * ⛔ **This file had no way to stamp an export that has not shipped, and the gap
35
+ * was invisible because it was written retrospectively** (2026-09-04, at 0.14.2,
36
+ * stamping names that had all already published). The first genuinely new export
37
+ * hit it immediately: the test demands every export be stamped, a stamp must be
38
+ * `<=` package.json's version, and the version an export will ship in **does not
39
+ * exist until the publish that creates it** — versions are derived from commits
40
+ * at publish time and never hand-edited.
41
+ *
42
+ * ⚠️ **The tempting fix is the dangerous one.** Stamping the current version
43
+ * (`0.16.0`) would satisfy every check and be **false**: backend reads
44
+ * `isolateApiFloor` from the channel index and refuses to serve a site below it,
45
+ * so a floor of 0.16.0 would promise an export that 0.16.0 does not contain —
46
+ * and a host at the floor is entitled to skip feature detection. That is a
47
+ * guarantee broken in the one direction the floor exists to prevent.
48
+ *
49
+ * ⇒ **`UNRELEASED` says the true thing: this export exists in the tree and in no
50
+ * published version.** It is stamped like any other name, so nothing rides out
51
+ * unnoticed, and it is EXCLUDED from the floor — which therefore never promises
52
+ * more than a published artifact delivers. **The floor rises one step after the
53
+ * publish, not one step before it**, and the sequence is:
54
+ *
55
+ * 1. land the export stamped `UNRELEASED` — the floor does not move;
56
+ * 2. publish (Diego; agents never publish);
57
+ * 3. replace `UNRELEASED` with the version that publish produced — the floor
58
+ * moves here, and the runtime channel's `isolateApiFloor` follows at the
59
+ * next channel publish;
60
+ * 4. tell backend, which holds the number and must ratchet it.
61
+ *
62
+ * ⚖️ **Step 3 is a real obligation, not bookkeeping**: an export left
63
+ * `UNRELEASED` after it ships keeps the floor below its own API forever, so a
64
+ * host feature-detects something it could have relied on. The guard is the
65
+ * test's own message.
30
66
  */
31
67
 
68
+ /** An export present in the tree and in no published version. Excluded from the floor. */
69
+ export const UNRELEASED = 'UNRELEASED'
70
+
32
71
  /** Every export of `@uniweb/runtime/ssr`, with the version it first shipped in. */
33
72
  export const ISOLATE_API = Object.freeze({
34
73
  // props preparation
@@ -66,13 +105,22 @@ export const ISOLATE_API = Object.freeze({
66
105
  // the composed render entry
67
106
  createPageRenderer: '0.14.2',
68
107
  prefetchAndHydrate: '0.14.2',
108
+ // the whole corpus, for a host that indexes rather than renders
109
+ collectSiteRecords: UNRELEASED,
69
110
  })
70
111
 
71
112
  /**
72
113
  * The runtime version at or above which EVERY name in `ISOLATE_API` is exported —
73
114
  * the absolute floor a host may rely on with no feature detection.
74
115
  */
75
- export const ISOLATE_API_FLOOR = Object.values(ISOLATE_API).reduce((max, v) => (compareVersions(v, max) > 0 ? v : max), '0.0.0')
116
+ export const ISOLATE_API_FLOOR = Object.values(ISOLATE_API)
117
+ .filter((v) => v !== UNRELEASED)
118
+ .reduce((max, v) => (compareVersions(v, max) > 0 ? v : max), '0.0.0')
119
+
120
+ /** The exports that exist here and in no published version — empty is the steady state. */
121
+ export const UNRELEASED_EXPORTS = Object.freeze(
122
+ Object.entries(ISOLATE_API).filter(([, v]) => v === UNRELEASED).map(([name]) => name),
123
+ )
76
124
 
77
125
  /** Compare two `x.y.z` versions numerically. Returns <0, 0 or >0. */
78
126
  export function compareVersions(a, b) {
@@ -18,8 +18,8 @@
18
18
  *
19
19
  * - **Shell assembly.** The shell arrives built. The import map, the CDN base and
20
20
  * cache headers are host layout, and a runtime that assembled them would be
21
- * modelling a deployment it cannot see (hosting drew this line themselves,
22
- * 2026-09-03; `framework/CLAUDE.md` § *Serve locations are read, never constructed*).
21
+ * modelling a deployment it cannot see (the host drew this line itself,
22
+ * 2026-09-03: a serve location is read from the payload, never constructed here).
23
23
  * - **Init and hydration.** The two lanes differ REALLY here, not incidentally: a
24
24
  * build initializes once and hydrates every collection up front, an isolate
25
25
  * initializes per locale and prefetches per route. Folding either in would fit