@uniweb/core 1.6.8 → 1.6.10

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/core",
3
- "version": "1.6.8",
3
+ "version": "1.6.10",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -53,8 +53,8 @@
53
53
  "vitest": "^4.1.7"
54
54
  },
55
55
  "dependencies": {
56
- "@uniweb/theming": "~1.3.2",
57
- "@uniweb/semantic-parser": "~1.13.2"
56
+ "@uniweb/semantic-parser": "~1.13.2",
57
+ "@uniweb/theming": "~1.3.2"
58
58
  },
59
59
  "scripts": {
60
60
  "test": "vitest run"
@@ -14,10 +14,9 @@
14
14
  * and in-flight dedup.
15
15
  */
16
16
 
17
- import { resolveFetchConfigs, pageRouteQuery } from './fetch-config.js'
18
- import { declaredKeys } from './data-keys.js'
17
+ import { resolveFetchConfigs } from './fetch-config.js'
19
18
  import { fillRoutePattern } from './route-match.js'
20
- import { fetchLevels, blockFills, pageRecordConfig, planFor, runPlan, runPlanSync } from './page-data.js'
19
+ import { blockRouteQuery, blockFetchOptions, blockFillsOf, pageRecordConfig, 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
- * The fetches that reach a block — `fetchLevels` (`./page-data.js`), the one rule, read
37
- * off this block's graph. ⛔ Do not spell the levels out here: every lane that has
38
- * needed this answer has written its own list, and each list has drifted.
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`),
@@ -160,13 +77,13 @@ export default class EntityStore {
160
77
 
161
78
  // A block-shaped probe standing for the page itself: its levels, its route query.
162
79
  const probe = { fetch: null, page, website: this.website, dynamicContext: null }
163
- const route = this._route(probe)
80
+ const route = blockRouteQuery(probe)
164
81
  const cfg = route && pageRecordConfig({
165
82
  pageFetch: page.fetch,
166
83
  parent: page.parent ?? null,
167
84
  route,
168
85
  site: this.website?.config?.fetch,
169
- options: this._resolveOptions(probe),
86
+ options: blockFetchOptions(probe),
170
87
  })
171
88
  if (!cfg) return null
172
89
 
@@ -184,36 +101,6 @@ export default class EntityStore {
184
101
  })
185
102
  }
186
103
 
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
104
  /**
218
105
  * ⭐ EVERY RECORD LINKS TO ITS QUERY'S PAGE — `$route`, filled here at render time, on
219
106
  * every lane (ruled 2026-09-14 [Diego]). For each delivered key, the page is the
@@ -297,8 +184,8 @@ export default class EntityStore {
297
184
  */
298
185
  resolve(block, meta) {
299
186
  const dispatcher = this.website?.fetcher
300
- const route = this._route(block)
301
- const fills = this._fills(block, meta, route)
187
+ const route = blockRouteQuery(block)
188
+ const fills = blockFillsOf(block, meta, route)
302
189
  if (fills.size === 0) return { status: 'none', data: null }
303
190
 
304
191
  const ctx = this._ctx(block)
@@ -336,8 +223,8 @@ export default class EntityStore {
336
223
  async fetch(block, meta, { signal, dispatcher = this.website?.fetcher } = {}) {
337
224
  if (!dispatcher) return { data: null, errors: null }
338
225
 
339
- const route = this._route(block)
340
- const fills = this._fills(block, meta, route)
226
+ const route = blockRouteQuery(block)
227
+ const fills = blockFillsOf(block, meta, route)
341
228
  if (fills.size === 0) return { data: null, errors: null }
342
229
 
343
230
  const ctx = this._ctx(block, { signal })
package/src/index.js CHANGED
@@ -111,6 +111,13 @@ export { resolveService, resolveServiceUrl, readServiceOptions } from './service
111
111
  export { applyBasePath } from './base-path.js'
112
112
  // A site's address and the absolute URLs stated on it — also the leaf `@uniweb/core/site-address`.
113
113
  export { siteAddress, pageUrl, absoluteUrl } from './site-address.js'
114
+ // The content parser and its sanitizer, for code a foundation BUNDLES (kit's `Render`, `Icon`,
115
+ // `Scene`). A foundation leaves `@uniweb/core` for the runtime to supply, so what it takes from
116
+ // here is the runtime's copy, the one Block parses every section with, never a second copy frozen
117
+ // at the foundation's build. A foundation imports these by name and a published one never
118
+ // changes, so none of them may leave this entry.
119
+ export { parseContent } from '@uniweb/semantic-parser'
120
+ export { sanitizeSVG, isStyleName } from '@uniweb/semantic-parser/sanitize'
114
121
 
115
122
  /**
116
123
  * The singleton Uniweb instance.
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,134 @@ 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
+
115
243
  /**
116
244
  * The fetch a parametric page's OWN record is asked for with — its route query, resolved.
117
245
  *
@@ -214,7 +342,7 @@ export function* keyProgram(cfg, { dynamicContext = null, route = null, held = u
214
342
  if (external) whole = false
215
343
 
216
344
  // How this fetch uses the page's record: by the query it names (`currentFor`).
217
- const current = forced ?? (dynamicContext ? currentFor(cfg, route) : null)
345
+ const current = forced ?? pageRecordUse(cfg, dynamicContext, route)
218
346
 
219
347
  // What a list of the binding's records is asked as — its first only, for a key holding one — and
220
348
  // the answer cut to it here too, since a source need not honour `narrow` (a foundation's transport).
@@ -309,6 +437,31 @@ export function* keyProgram(cfg, { dynamicContext = null, route = null, held = u
309
437
  return yield* wholeRecordsOf(cfg, cut(answer.data))
310
438
  }
311
439
 
440
+ /**
441
+ * How a filling fetch uses this page's record: on a parametric page, by the query it names
442
+ * (`currentFor`); off one, not at all. One answer for the per-key program and for a caller asking
443
+ * whether a key holds the page's record (`fillIsPageRecord`).
444
+ */
445
+ function pageRecordUse(cfg, dynamicContext, route) {
446
+ return dynamicContext ? currentFor(cfg, route) : null
447
+ }
448
+
449
+ /**
450
+ * Whether a block's key is filled with its page's OWN record — a parametric page's record, which
451
+ * the key's program gives under `current: only` (`keyProgram`) — for a caller that holds the record
452
+ * already: a record page's Markdown writes it once, as the page's (`@uniweb/runtime`'s
453
+ * `section-records.js`).
454
+ *
455
+ * @param {Object} block
456
+ * @param {Object} cfg - the key's filling fetch, resolved (`blockFillsOf`)
457
+ * @param {{ key: string, config: Object, nested: boolean }|null} [route] - the block's page's route
458
+ * query (`blockRouteQuery`)
459
+ * @returns {boolean}
460
+ */
461
+ export function fillIsPageRecord(block, cfg, route = blockRouteQuery(block)) {
462
+ return pageRecordUse(cfg, block.dynamicContext || block.page?.dynamicContext, route) === 'only'
463
+ }
464
+
312
465
  /**
313
466
  * A `single` key's question: the binding's own, cut to its first record. The fetch's `narrow` is
314
467
  * 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 (`EntityStore._route`), from
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
- // (`_route`). A static build replaces a parametric page with one concrete page per
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