@uniweb/core 1.6.9 → 1.6.11
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 +1 -1
- package/src/entity-store.js +17 -146
- package/src/page-data.js +216 -3
- package/src/website.js +2 -2
package/package.json
CHANGED
package/src/entity-store.js
CHANGED
|
@@ -14,10 +14,9 @@
|
|
|
14
14
|
* and in-flight dedup.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { resolveFetchConfigs
|
|
18
|
-
import { declaredKeys } from './data-keys.js'
|
|
17
|
+
import { resolveFetchConfigs } from './fetch-config.js'
|
|
19
18
|
import { fillRoutePattern } from './route-match.js'
|
|
20
|
-
import {
|
|
19
|
+
import { blockRouteQuery, blockFillsOf, pageRecordPlan, planFor, runPlan, runPlanSync } from './page-data.js'
|
|
21
20
|
|
|
22
21
|
export default class EntityStore {
|
|
23
22
|
/**
|
|
@@ -33,93 +32,11 @@ export default class EntityStore {
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
35
|
+
* ⭐ What a block receives, from which fetch, its page's route query and the options each fetch
|
|
36
|
+
* is resolved with, are read off the graph by `./page-data.js` (`blockFillsOf`,
|
|
37
|
+
* `blockRouteQuery`, `blockFetchOptions`) — the reading a caller reporting what a section
|
|
38
|
+
* received asks too, so the two cannot name different fetches.
|
|
39
39
|
*/
|
|
40
|
-
_levels(block, route = this._route(block)) {
|
|
41
|
-
const page = block.page
|
|
42
|
-
return fetchLevels({
|
|
43
|
-
own: block.fetch,
|
|
44
|
-
page: page?.fetch,
|
|
45
|
-
parent: page?.parent ?? null,
|
|
46
|
-
route,
|
|
47
|
-
site: block.website?.config?.fetch,
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* The options each fetch of a block is resolved with. The rule applied to a fetch
|
|
53
|
-
* (locale normalization, route variables, the record files' pattern) lives in
|
|
54
|
-
* `./fetch-config.js`, shared with every other host that has to answer the same
|
|
55
|
-
* question. Do not re-inline it here — divergence between copies is what the
|
|
56
|
-
* extraction exists to prevent.
|
|
57
|
-
*/
|
|
58
|
-
_resolveOptions(block) {
|
|
59
|
-
const website = block.website
|
|
60
|
-
const dynamicContext = block.dynamicContext || block.page?.dynamicContext
|
|
61
|
-
// The route's variables, for a query that binds `:path` / `:dir` / `:slug` —
|
|
62
|
-
// `routeBinding`'s, carried as `params` by every parametric page this runtime
|
|
63
|
-
// or its build makes. A page that carries only its capture gets the same three
|
|
64
|
-
// names from it: one segment is `:slug` and `:path`, with no `:dir`.
|
|
65
|
-
const variables = dynamicContext
|
|
66
|
-
? (dynamicContext.params ?? (dynamicContext.paramValue !== undefined
|
|
67
|
-
? {
|
|
68
|
-
[dynamicContext.paramName]: dynamicContext.paramValue,
|
|
69
|
-
path: dynamicContext.paramValue,
|
|
70
|
-
dir: '',
|
|
71
|
-
slug: dynamicContext.paramValue,
|
|
72
|
-
}
|
|
73
|
-
: null))
|
|
74
|
-
: null
|
|
75
|
-
return {
|
|
76
|
-
locale: website?.getActiveLocale?.() ?? null,
|
|
77
|
-
defaultLocale: website?.getDefaultLocale?.() ?? null,
|
|
78
|
-
// ⚠️ `queries`, matching `resolveFetchConfigs`. This passed `collections`
|
|
79
|
-
// after the payload key was renamed — a dead option name, silently: the
|
|
80
|
-
// resolver simply saw no queries and stopped injecting `detail:`.
|
|
81
|
-
queries: website?.config?.queries ?? null,
|
|
82
|
-
// The host's services; its `records` row is the live-records lane.
|
|
83
|
-
// Absent on every static site and on local dev, which is why
|
|
84
|
-
// `resolveQuerySource` treats absence as the ordinary case and reads
|
|
85
|
-
// the compiled artifact without comment.
|
|
86
|
-
services: website?.config?.services ?? null,
|
|
87
|
-
variables,
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* ⭐ WHAT THIS SECTION RECEIVES, AND FROM WHICH FETCH — ruled 2026-09-14 [Diego]. The keys
|
|
93
|
-
* its component declares and its foundation's (`website.declaredKeys`), each paired with
|
|
94
|
-
* the fetch that fills it by the one rule (`fillDeclaredKeys`, automatic `as`) over the
|
|
95
|
-
* levels that reach the block. A declared key the block already holds — a tagged data
|
|
96
|
-
* block, or its own fetch's prerendered answer under that name — is not the store's to
|
|
97
|
-
* fill, and a fetch that fills no declared key is not asked. Each filling fetch is
|
|
98
|
-
* resolved on its own, so two fetches of one `as` can fill two keys.
|
|
99
|
-
*
|
|
100
|
-
* ⭐ `held` is the answer the block already holds for a filling fetch, under the fetch's
|
|
101
|
-
* own key: a static build prerenders a section's own fetch into its content by `as`, so
|
|
102
|
-
* a component that names the key differently still receives it without the browser
|
|
103
|
-
* asking again. Only for the first fetch of that key reaching the block — the one whose
|
|
104
|
-
* answer a build put there.
|
|
105
|
-
*
|
|
106
|
-
* ⛔ Until 2026-09-14 every fetch reaching the block was resolved and delivered under its
|
|
107
|
-
* `as` — the first per key — whether the component read it or not, and a component
|
|
108
|
-
* declaring its key under another name received nothing.
|
|
109
|
-
*
|
|
110
|
-
* @returns {Map<string, { cfg: Object, held: * }>} declared key → the resolved config of
|
|
111
|
-
* the fetch that fills it, and the answer the block holds for it (undefined when none)
|
|
112
|
-
*/
|
|
113
|
-
_fills(block, meta, route) {
|
|
114
|
-
const website = block.website
|
|
115
|
-
return blockFills({
|
|
116
|
-
declared: website?.declaredKeys ? website.declaredKeys(meta) : declaredKeys(meta?.data),
|
|
117
|
-
levels: this._levels(block, route),
|
|
118
|
-
holds: block.heldData || {},
|
|
119
|
-
queries: website?.config?.queries ?? null,
|
|
120
|
-
options: this._resolveOptions(block),
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
40
|
|
|
124
41
|
/**
|
|
125
42
|
* The plan for a block — one program per declared key (`planFor`, `./page-data.js`),
|
|
@@ -155,65 +72,19 @@ export default class EntityStore {
|
|
|
155
72
|
* when the page's route query resolves to nothing
|
|
156
73
|
*/
|
|
157
74
|
async fetchPageRecord(page, { dispatcher = this.website?.fetcher } = {}) {
|
|
158
|
-
|
|
159
|
-
if (!dynamicContext || !dispatcher) return null
|
|
75
|
+
if (!page?.dynamicContext || !dispatcher) return null
|
|
160
76
|
|
|
161
|
-
//
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
route,
|
|
168
|
-
site: this.website?.config?.fetch,
|
|
169
|
-
options: this._resolveOptions(probe),
|
|
170
|
-
})
|
|
171
|
-
if (!cfg) return null
|
|
172
|
-
|
|
173
|
-
const plan = planFor(new Map([[route.key, { cfg }]]), {
|
|
174
|
-
dynamicContext,
|
|
175
|
-
route,
|
|
176
|
-
// The page is about ONE record, whatever a section's `current:` says.
|
|
177
|
-
current: 'only',
|
|
178
|
-
peekRecord: (id) => dispatcher.peekRecord?.(id),
|
|
179
|
-
})
|
|
180
|
-
const ctx = this._ctx(probe)
|
|
181
|
-
return runPlan(plan, {
|
|
77
|
+
// The question, as `heldPageRecord` reads its answer back (`./page-data.js`).
|
|
78
|
+
const asked = pageRecordPlan(page, { website: this.website, peekRecord: (id) => dispatcher.peekRecord?.(id) })
|
|
79
|
+
if (!asked) return null
|
|
80
|
+
// A block-shaped probe standing for the page itself, as the context a dispatcher is handed.
|
|
81
|
+
const ctx = this._ctx({ fetch: null, page, website: this.website, dynamicContext: null })
|
|
82
|
+
return runPlan(asked.plan, {
|
|
182
83
|
dispatch: (request) => dispatcher.dispatch(request, ctx),
|
|
183
84
|
peek: (request) => dispatcher.peek?.(request, ctx),
|
|
184
85
|
})
|
|
185
86
|
}
|
|
186
87
|
|
|
187
|
-
/**
|
|
188
|
-
* The ROUTE QUERY of the block's page — the query its URL names one record of —
|
|
189
|
-
* worked out from the same sources `_levels` reads, at the page that
|
|
190
|
-
* captured the URL's variable (`pageRouteQuery`, `./fetch-config.js`): its fetch,
|
|
191
|
-
* its parent's, the site's, and, when none of those declares one, the key its
|
|
192
|
-
* sections share. So what a section receives and what the URL narrows are read
|
|
193
|
-
* off one walk and cannot disagree.
|
|
194
|
-
*
|
|
195
|
-
* ⛔ This was `dynamicContext.schema`, stored on the page by whoever built it —
|
|
196
|
-
* the SPA from `parentSchema`, the static build from the parent's first
|
|
197
|
-
* prerendered fetch — a stored copy of a derived answer, computed by a different
|
|
198
|
-
* rule from the one sections are fed by. Deleted 2026-09-11 [Diego].
|
|
199
|
-
*
|
|
200
|
-
* @returns {{ key: string, config: Object, nested: boolean }|null} null off a
|
|
201
|
-
* parametric page, or when it has no route query
|
|
202
|
-
*/
|
|
203
|
-
_route(block) {
|
|
204
|
-
const dynamicContext = block.dynamicContext || block.page?.dynamicContext
|
|
205
|
-
if (!dynamicContext || !block.page) return null
|
|
206
|
-
return pageRouteQuery(block.page, {
|
|
207
|
-
// a concrete page carries its template's route; its ancestors are templates, or
|
|
208
|
-
// pages the static build expanded, which carry theirs the same way
|
|
209
|
-
routeOf: (p) => p?.dynamicContext?.templateRoute ?? p?.route,
|
|
210
|
-
parentOf: (p) => p?.parent ?? null,
|
|
211
|
-
fetchOf: (p) => p?.fetch,
|
|
212
|
-
sectionsOf: (p) => p?._bodySections,
|
|
213
|
-
site: block.website?.config?.fetch,
|
|
214
|
-
})
|
|
215
|
-
}
|
|
216
|
-
|
|
217
88
|
/**
|
|
218
89
|
* ⭐ EVERY RECORD LINKS TO ITS QUERY'S PAGE — `$route`, filled here at render time, on
|
|
219
90
|
* every lane (ruled 2026-09-14 [Diego]). For each delivered key, the page is the
|
|
@@ -297,8 +168,8 @@ export default class EntityStore {
|
|
|
297
168
|
*/
|
|
298
169
|
resolve(block, meta) {
|
|
299
170
|
const dispatcher = this.website?.fetcher
|
|
300
|
-
const route =
|
|
301
|
-
const fills =
|
|
171
|
+
const route = blockRouteQuery(block)
|
|
172
|
+
const fills = blockFillsOf(block, meta, route)
|
|
302
173
|
if (fills.size === 0) return { status: 'none', data: null }
|
|
303
174
|
|
|
304
175
|
const ctx = this._ctx(block)
|
|
@@ -336,8 +207,8 @@ export default class EntityStore {
|
|
|
336
207
|
async fetch(block, meta, { signal, dispatcher = this.website?.fetcher } = {}) {
|
|
337
208
|
if (!dispatcher) return { data: null, errors: null }
|
|
338
209
|
|
|
339
|
-
const route =
|
|
340
|
-
const fills =
|
|
210
|
+
const route = blockRouteQuery(block)
|
|
211
|
+
const fills = blockFillsOf(block, meta, route)
|
|
341
212
|
if (fills.size === 0) return { data: null, errors: null }
|
|
342
213
|
|
|
343
214
|
const ctx = this._ctx(block, { signal })
|
package/src/page-data.js
CHANGED
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
* @module
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
import { resolveFetchConfigs, fetchEntries, routeSelection, currentFor, othersView, othersOf, siteReaches } from './fetch-config.js'
|
|
32
|
-
import { fillDeclaredKeys } from './data-keys.js'
|
|
31
|
+
import { resolveFetchConfigs, fetchEntries, routeSelection, currentFor, othersView, othersOf, siteReaches, pageRouteQuery } from './fetch-config.js'
|
|
32
|
+
import { fillDeclaredKeys, declaredKeys } from './data-keys.js'
|
|
33
33
|
import { matchesRouteParam } from './route-match.js'
|
|
34
34
|
import { buildDetailConfig } from './detail-url.js'
|
|
35
35
|
|
|
@@ -112,6 +112,194 @@ export function blockFills({ declared, levels, holds = {}, queries = null, optio
|
|
|
112
112
|
return out
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/**
|
|
116
|
+
* ⭐ (a) AND (b) READ OFF THE OBJECT GRAPH — a Block of a Website, where the two functions above take
|
|
117
|
+
* plain data. The entity store fills a section by these (`EntityStore`), and a caller reporting what a
|
|
118
|
+
* section received asks them too (`@uniweb/runtime`'s `section-records.js`, for a page's Markdown):
|
|
119
|
+
* one reading of the graph, so the two cannot name different fetches. ⛔ Do not spell the levels out
|
|
120
|
+
* anywhere else: every lane that has needed this answer has written its own list, and each list has
|
|
121
|
+
* drifted.
|
|
122
|
+
*
|
|
123
|
+
* Each takes a Block, or an object shaped like one where it reads it (`fetch`, `page`, `website`,
|
|
124
|
+
* `dynamicContext`, `heldData`): the store asks for a page's own record with such a probe.
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The ROUTE QUERY of a block's page — the query its URL names one record of — worked out from the
|
|
129
|
+
* same sources the levels read, at the page that captured the URL's variable (`pageRouteQuery`,
|
|
130
|
+
* `./fetch-config.js`): its fetch, its parent's, the site's, and, when none of those declares one,
|
|
131
|
+
* the key its sections share. So what a section receives and what the URL narrows are read off one
|
|
132
|
+
* walk and cannot disagree.
|
|
133
|
+
*
|
|
134
|
+
* ⛔ This was `dynamicContext.schema`, stored on the page by whoever built it — the SPA from
|
|
135
|
+
* `parentSchema`, the static build from the parent's first prerendered fetch — a stored copy of a
|
|
136
|
+
* derived answer, computed by a different rule from the one sections are fed by. Deleted 2026-09-11
|
|
137
|
+
* [Diego].
|
|
138
|
+
*
|
|
139
|
+
* @param {Object} block
|
|
140
|
+
* @returns {{ key: string, config: Object, nested: boolean }|null} null off a parametric page, or when
|
|
141
|
+
* it has no route query
|
|
142
|
+
*/
|
|
143
|
+
export function blockRouteQuery(block) {
|
|
144
|
+
const dynamicContext = block.dynamicContext || block.page?.dynamicContext
|
|
145
|
+
if (!dynamicContext || !block.page) return null
|
|
146
|
+
return pageRouteQuery(block.page, {
|
|
147
|
+
// a concrete page carries its template's route; its ancestors are templates, or
|
|
148
|
+
// pages the static build expanded, which carry theirs the same way
|
|
149
|
+
routeOf: (p) => p?.dynamicContext?.templateRoute ?? p?.route,
|
|
150
|
+
parentOf: (p) => p?.parent ?? null,
|
|
151
|
+
fetchOf: (p) => p?.fetch,
|
|
152
|
+
sectionsOf: (p) => p?._bodySections,
|
|
153
|
+
site: block.website?.config?.fetch,
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The options each fetch of a block is resolved with. The rule applied to a fetch (locale
|
|
159
|
+
* normalization, route variables, the record files' pattern) lives in `./fetch-config.js`, shared
|
|
160
|
+
* with every other host that has to answer the same question. Do not re-inline it — divergence
|
|
161
|
+
* between copies is what the extraction exists to prevent.
|
|
162
|
+
*
|
|
163
|
+
* @param {Object} block
|
|
164
|
+
* @returns {Object} what `resolveFetchConfigs` takes
|
|
165
|
+
*/
|
|
166
|
+
export function blockFetchOptions(block) {
|
|
167
|
+
const website = block.website
|
|
168
|
+
const dynamicContext = block.dynamicContext || block.page?.dynamicContext
|
|
169
|
+
// The route's variables, for a query that binds `:path` / `:dir` / `:slug` —
|
|
170
|
+
// `routeBinding`'s, carried as `params` by every parametric page this runtime
|
|
171
|
+
// or its build makes. A page that carries only its capture gets the same three
|
|
172
|
+
// names from it: one segment is `:slug` and `:path`, with no `:dir`.
|
|
173
|
+
const variables = dynamicContext
|
|
174
|
+
? (dynamicContext.params ?? (dynamicContext.paramValue !== undefined
|
|
175
|
+
? {
|
|
176
|
+
[dynamicContext.paramName]: dynamicContext.paramValue,
|
|
177
|
+
path: dynamicContext.paramValue,
|
|
178
|
+
dir: '',
|
|
179
|
+
slug: dynamicContext.paramValue,
|
|
180
|
+
}
|
|
181
|
+
: null))
|
|
182
|
+
: null
|
|
183
|
+
return {
|
|
184
|
+
locale: website?.getActiveLocale?.() ?? null,
|
|
185
|
+
defaultLocale: website?.getDefaultLocale?.() ?? null,
|
|
186
|
+
// ⚠️ `queries`, matching `resolveFetchConfigs`. This passed `collections`
|
|
187
|
+
// after the payload key was renamed — a dead option name, silently: the
|
|
188
|
+
// resolver simply saw no queries and stopped injecting `detail:`.
|
|
189
|
+
queries: website?.config?.queries ?? null,
|
|
190
|
+
// The host's services; its `records` row is the live-records lane.
|
|
191
|
+
// Absent on every static site and on local dev, which is why
|
|
192
|
+
// `resolveQuerySource` treats absence as the ordinary case and reads
|
|
193
|
+
// the compiled artifact without comment.
|
|
194
|
+
services: website?.config?.services ?? null,
|
|
195
|
+
variables,
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* ⭐ WHAT THIS SECTION RECEIVES, AND FROM WHICH FETCH — ruled 2026-09-14 [Diego]: (b) for a Block.
|
|
201
|
+
* The keys its component declares and its foundation's (`website.declaredKeys`), each paired with the
|
|
202
|
+
* fetch that fills it by the one rule (`fillDeclaredKeys`, automatic `as`) over the levels that reach
|
|
203
|
+
* the block (`fetchLevels`). A declared key the block already holds — a tagged data block, or its own
|
|
204
|
+
* fetch's prerendered answer under that name — is not filled from a request, and a fetch that fills no
|
|
205
|
+
* declared key is not asked. Each filling fetch is resolved on its own, so two fetches of one `as` can
|
|
206
|
+
* fill two keys.
|
|
207
|
+
*
|
|
208
|
+
* ⭐ `held` is the answer the block already holds for a filling fetch, under the fetch's own key: a
|
|
209
|
+
* static build prerenders a section's own fetch into its content by `as`, so a component that names
|
|
210
|
+
* the key differently still receives it without the browser asking again. Only for the first fetch of
|
|
211
|
+
* that key reaching the block — the one whose answer a build put there.
|
|
212
|
+
*
|
|
213
|
+
* ⛔ Until 2026-09-14 every fetch reaching the block was resolved and delivered under its `as` — the
|
|
214
|
+
* first per key — whether the component read it or not, and a component declaring its key under
|
|
215
|
+
* another name received nothing.
|
|
216
|
+
*
|
|
217
|
+
* @param {Object} block
|
|
218
|
+
* @param {Object|null} meta - its component's runtime meta
|
|
219
|
+
* @param {{ key: string, config: Object, nested: boolean }|null} [route] - its page's route query,
|
|
220
|
+
* when the caller has worked it out already (`blockRouteQuery`)
|
|
221
|
+
* @returns {Map<string, { cfg: Object, held: *, whole: boolean, single: boolean }>} `blockFills`'
|
|
222
|
+
* answer: declared key → the resolved config of the fetch that fills it (its `as` among it), and the
|
|
223
|
+
* answer the block holds for it (undefined when none)
|
|
224
|
+
*/
|
|
225
|
+
export function blockFillsOf(block, meta, route = blockRouteQuery(block)) {
|
|
226
|
+
const website = block.website
|
|
227
|
+
const page = block.page
|
|
228
|
+
return blockFills({
|
|
229
|
+
declared: website?.declaredKeys ? website.declaredKeys(meta) : declaredKeys(meta?.data),
|
|
230
|
+
levels: fetchLevels({
|
|
231
|
+
own: block.fetch,
|
|
232
|
+
page: page?.fetch,
|
|
233
|
+
parent: page?.parent ?? null,
|
|
234
|
+
route,
|
|
235
|
+
site: website?.config?.fetch,
|
|
236
|
+
}),
|
|
237
|
+
holds: block.heldData || {},
|
|
238
|
+
queries: website?.config?.queries ?? null,
|
|
239
|
+
options: blockFetchOptions(block),
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The plan for a parametric page's OWN record — its route query's program under `current: only` —
|
|
245
|
+
* read off the graph: the question the page's data step asks (`EntityStore#fetchPageRecord`), and the
|
|
246
|
+
* one `heldPageRecord` answers from what is held.
|
|
247
|
+
*
|
|
248
|
+
* @param {Object} page - a concrete parametric page (it carries `dynamicContext`)
|
|
249
|
+
* @param {Object} where
|
|
250
|
+
* @param {Object} where.website
|
|
251
|
+
* @param {Function} [where.peekRecord] - the record index, for the R1 gate
|
|
252
|
+
* @returns {{ key: string, plan: Map<string, Generator> }|null} null off a parametric page, or when
|
|
253
|
+
* its route query resolves to nothing
|
|
254
|
+
*/
|
|
255
|
+
export function pageRecordPlan(page, { website, peekRecord = null } = {}) {
|
|
256
|
+
const dynamicContext = page?.dynamicContext
|
|
257
|
+
if (!dynamicContext) return null
|
|
258
|
+
// A block-shaped probe standing for the page itself: its levels, its route query.
|
|
259
|
+
const probe = { fetch: null, page, website, dynamicContext: null }
|
|
260
|
+
const route = blockRouteQuery(probe)
|
|
261
|
+
const cfg = route && pageRecordConfig({
|
|
262
|
+
pageFetch: page.fetch,
|
|
263
|
+
parent: page.parent ?? null,
|
|
264
|
+
route,
|
|
265
|
+
site: website?.config?.fetch,
|
|
266
|
+
options: blockFetchOptions(probe),
|
|
267
|
+
})
|
|
268
|
+
if (!cfg) return null
|
|
269
|
+
return {
|
|
270
|
+
key: route.key,
|
|
271
|
+
plan: planFor(new Map([[route.key, { cfg }]]), {
|
|
272
|
+
dynamicContext,
|
|
273
|
+
route,
|
|
274
|
+
// The page is about ONE record, whatever a section's `current:` says.
|
|
275
|
+
current: 'only',
|
|
276
|
+
peekRecord,
|
|
277
|
+
}),
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* A parametric page's own record, from what is held: the answer `pageRecordPlan`'s question got,
|
|
283
|
+
* read back after the page's data step. For a caller reporting what a page held, a record page's
|
|
284
|
+
* Markdown among them (`@uniweb/runtime`'s `section-records.js`).
|
|
285
|
+
*
|
|
286
|
+
* @param {Object} page
|
|
287
|
+
* @param {Object} where
|
|
288
|
+
* @param {Object} where.website
|
|
289
|
+
* @param {(request: Object) => ({ data: * }|null|undefined)} where.peek - the cache
|
|
290
|
+
* @param {Function} [where.peekRecord] - the record index
|
|
291
|
+
* @returns {Object|null|undefined} the record; null when the route names none (its answer is `[]`);
|
|
292
|
+
* undefined off a parametric page, or when nothing held answers the question
|
|
293
|
+
*/
|
|
294
|
+
export function heldPageRecord(page, { website, peek, peekRecord = null } = {}) {
|
|
295
|
+
const asked = pageRecordPlan(page, { website, peekRecord })
|
|
296
|
+
if (!asked) return undefined
|
|
297
|
+
const out = runPlanSync(asked.plan, { peek })
|
|
298
|
+
const found = out.status === 'ready' ? out.data?.[asked.key] : undefined
|
|
299
|
+
if (found === undefined) return undefined
|
|
300
|
+
return Array.isArray(found) ? (found[0] ?? null) : found
|
|
301
|
+
}
|
|
302
|
+
|
|
115
303
|
/**
|
|
116
304
|
* The fetch a parametric page's OWN record is asked for with — its route query, resolved.
|
|
117
305
|
*
|
|
@@ -214,7 +402,7 @@ export function* keyProgram(cfg, { dynamicContext = null, route = null, held = u
|
|
|
214
402
|
if (external) whole = false
|
|
215
403
|
|
|
216
404
|
// How this fetch uses the page's record: by the query it names (`currentFor`).
|
|
217
|
-
const current = forced ?? (
|
|
405
|
+
const current = forced ?? pageRecordUse(cfg, dynamicContext, route)
|
|
218
406
|
|
|
219
407
|
// What a list of the binding's records is asked as — its first only, for a key holding one — and
|
|
220
408
|
// the answer cut to it here too, since a source need not honour `narrow` (a foundation's transport).
|
|
@@ -309,6 +497,31 @@ export function* keyProgram(cfg, { dynamicContext = null, route = null, held = u
|
|
|
309
497
|
return yield* wholeRecordsOf(cfg, cut(answer.data))
|
|
310
498
|
}
|
|
311
499
|
|
|
500
|
+
/**
|
|
501
|
+
* How a filling fetch uses this page's record: on a parametric page, by the query it names
|
|
502
|
+
* (`currentFor`); off one, not at all. One answer for the per-key program and for a caller asking
|
|
503
|
+
* whether a key holds the page's record (`fillIsPageRecord`).
|
|
504
|
+
*/
|
|
505
|
+
function pageRecordUse(cfg, dynamicContext, route) {
|
|
506
|
+
return dynamicContext ? currentFor(cfg, route) : null
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Whether a block's key is filled with its page's OWN record — a parametric page's record, which
|
|
511
|
+
* the key's program gives under `current: only` (`keyProgram`) — for a caller that holds the record
|
|
512
|
+
* already: a record page's Markdown writes it once, as the page's (`@uniweb/runtime`'s
|
|
513
|
+
* `section-records.js`).
|
|
514
|
+
*
|
|
515
|
+
* @param {Object} block
|
|
516
|
+
* @param {Object} cfg - the key's filling fetch, resolved (`blockFillsOf`)
|
|
517
|
+
* @param {{ key: string, config: Object, nested: boolean }|null} [route] - the block's page's route
|
|
518
|
+
* query (`blockRouteQuery`)
|
|
519
|
+
* @returns {boolean}
|
|
520
|
+
*/
|
|
521
|
+
export function fillIsPageRecord(block, cfg, route = blockRouteQuery(block)) {
|
|
522
|
+
return pageRecordUse(cfg, block.dynamicContext || block.page?.dynamicContext, route) === 'only'
|
|
523
|
+
}
|
|
524
|
+
|
|
312
525
|
/**
|
|
313
526
|
* A `single` key's question: the binding's own, cut to its first record. The fetch's `narrow` is
|
|
314
527
|
* where a cut belongs — applied after the query's set on every lane — and a `limit` of its own is at
|
package/src/website.js
CHANGED
|
@@ -577,7 +577,7 @@ export default class Website {
|
|
|
577
577
|
const { paramName, paramValue, variables } = routeBinding(templatePage.route, params, originalData.paramName)
|
|
578
578
|
|
|
579
579
|
// Store dynamic context for components to access. ⛔ No `schema`: the key the
|
|
580
|
-
// URL narrows is worked out where it is read (`
|
|
580
|
+
// URL narrows is worked out where it is read (`blockRouteQuery`, `./page-data.js`), from
|
|
581
581
|
// the page, never stored beside it (deleted 2026-09-11).
|
|
582
582
|
pageData.dynamicContext = {
|
|
583
583
|
templateRoute: templatePage.route,
|
|
@@ -925,7 +925,7 @@ export default class Website {
|
|
|
925
925
|
if (typeof query !== 'string' || !query) return null
|
|
926
926
|
if (!this._recordPages) {
|
|
927
927
|
// ⭐ Every page, by the route PATTERN it answers to — the entity store's reading
|
|
928
|
-
// (`
|
|
928
|
+
// (`blockRouteQuery`). A static build replaces a parametric page with one concrete page per
|
|
929
929
|
// record (`expandDynamicPages`), each carrying its template's route as
|
|
930
930
|
// `dynamicContext.templateRoute`; the payload it prerenders and hydrates holds those,
|
|
931
931
|
// and no template. ⛔ Read from the templates alone, this found no page there, and
|