@uniweb/core 1.4.10 → 1.4.12

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.4.10",
3
+ "version": "1.4.12",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -178,7 +178,10 @@ export default class EntityStore {
178
178
  peekRecord: (id) => dispatcher.peekRecord?.(id),
179
179
  })
180
180
  const ctx = this._ctx(probe)
181
- return runPlan(plan, { dispatch: (request) => dispatcher.dispatch(request, ctx) })
181
+ return runPlan(plan, {
182
+ dispatch: (request) => dispatcher.dispatch(request, ctx),
183
+ peek: (request) => dispatcher.peek?.(request, ctx),
184
+ })
182
185
  }
183
186
 
184
187
  /**
@@ -340,6 +343,8 @@ export default class EntityStore {
340
343
  const ctx = this._ctx(block, { signal })
341
344
  const { data, errors } = await runPlan(this._plan(block, fills, route, dispatcher), {
342
345
  dispatch: (request) => dispatcher.dispatch(request, ctx),
346
+ // What the plan uses without asking, when it is held (`keyProgram`'s held steps).
347
+ peek: (request) => dispatcher.peek?.(request, ctx),
343
348
  onFailure: (key, cfg, message) => reportFetchFailure(this.dev, block, key, cfg, message),
344
349
  })
345
350
 
package/src/page-data.js CHANGED
@@ -200,6 +200,8 @@ function heldWhole(peekRecord, match) {
200
200
  export function* keyProgram(cfg, { dynamicContext = null, route = null, held = undefined, peekRecord = null, current: forced = null, opportunistic = false, whole = false, single = false } = {}) {
201
201
  /** A step this caller can do without: a miss answers `{ missing: true }` instead of stopping. */
202
202
  const maybe = (request) => (opportunistic ? { request, optional: true } : request)
203
+ /** A step answered from what is held, on both drivers: never dispatched, `{ missing: true }` when not held. */
204
+ const fromHeld = (request) => ({ request, held: true })
203
205
  // The block holds this fetch's answer already — a static build prerendered it.
204
206
  if (held !== undefined) return { value: held }
205
207
 
@@ -232,6 +234,20 @@ export function* keyProgram(cfg, { dynamicContext = null, route = null, held = u
232
234
  }
233
235
 
234
236
  if (current === 'only' && cfg.ask) {
237
+ // ⭐ WHAT IS HELD, FIRST. A page that lists this query keeps its set, and the record is in it:
238
+ // its brief, and — when another question brought it whole — the record itself, in the record
239
+ // index. Either answers without a request. Only a positive match counts: a held set without the
240
+ // record proves nothing, since the service may answer the set in pages, so the record is asked.
241
+ // ⛔ Until 2026-10-27 this lane asked the record's question even with its query's set held, where
242
+ // the file lane finds the record in the set and asks for it whole only when it is not held whole.
243
+ const set = yield fromHeld(routeSelection(cfg))
244
+ const found = Array.isArray(set.data)
245
+ ? set.data.find(isPageRecord(dynamicContext, cfg.routeField)) ?? null
246
+ : null
247
+ if (found && !whole) return { value: [found] }
248
+ const foundWhole = found ? heldWhole(peekRecord, found) : null
249
+ if (foundWhole) return { value: [foundWhole] }
250
+
235
251
  // ⭐ THE RECORDS SERVICE needs no list to find the record: the record is the query's set
236
252
  // narrowed by the route's handle, so its one question answers the record if the set holds it
237
253
  // and `[]` if not — whole or its brief, as the component expects.
@@ -351,13 +367,24 @@ function recordRequest(cfg, record) {
351
367
  return buildDetailConfig(cfg, { paramName: 'slug', paramValue: String(handle), record })
352
368
  }
353
369
 
354
- /** A yielded step as `{ request, optional }` entries: one request, or several asked together. */
370
+ /**
371
+ * A yielded step as `{ request, optional, held }` entries: one request, or several asked together.
372
+ * `held` is answered from the cache on both drivers and never dispatched.
373
+ */
355
374
  function asSteps(value) {
356
375
  return (Array.isArray(value) ? value : [value]).map((step) =>
357
- step && step.request ? { request: step.request, optional: !!step.optional } : { request: step, optional: false }
376
+ step && step.request
377
+ ? { request: step.request, optional: !!step.optional, held: !!step.held }
378
+ : { request: step, optional: false, held: false }
358
379
  )
359
380
  }
360
381
 
382
+ /** A held step's answer: what the cache holds, or `{ missing: true }` — never a request. */
383
+ function fromCache(peek, request) {
384
+ const cached = typeof peek === 'function' ? peek(request) : null
385
+ return cached ? { data: cached.data } : { missing: true }
386
+ }
387
+
361
388
  /**
362
389
  * Every filling key's program, ready to run.
363
390
  *
@@ -399,11 +426,11 @@ export function runPlanSync(plan, { peek }) {
399
426
  }
400
427
  const answers = []
401
428
  let missed = false
402
- for (const { request, optional } of asSteps(step.value)) {
429
+ for (const { request, optional, held } of asSteps(step.value)) {
403
430
  const cached = peek(request)
404
431
  if (cached) answers.push({ data: cached.data })
405
432
  // The program can do without this one and says what it makes of that.
406
- else if (optional) answers.push({ missing: true })
433
+ else if (optional || held) answers.push({ missing: true })
407
434
  else {
408
435
  missed = true
409
436
  break
@@ -429,13 +456,17 @@ export function runPlanSync(plan, { peek }) {
429
456
  * a page's questions into one POST. A key whose second request depends on its first answer takes a
430
457
  * later tick, and only that key waits; the requests of one step are issued together.
431
458
  *
459
+ * A step the program marks held is answered from `peek` and never dispatched: what is already here
460
+ * is used, and its absence asks nothing.
461
+ *
432
462
  * @param {Map<string, Generator>} plan
433
463
  * @param {Object} io
434
464
  * @param {(request: Object) => Promise<{ data: *, error?: string }>} io.dispatch
465
+ * @param {(request: Object) => ({ data: * }|null|undefined)} [io.peek] - what is held, for a held step
435
466
  * @param {(key: string, cfg: Object|null, message: string) => void} [io.onFailure]
436
467
  * @returns {Promise<{ data: Object, errors: Object|null }>}
437
468
  */
438
- export async function runPlan(plan, { dispatch, onFailure = null }) {
469
+ export async function runPlan(plan, { dispatch, peek = null, onFailure = null }) {
439
470
  const data = {}
440
471
  const errors = {}
441
472
 
@@ -452,8 +483,12 @@ export async function runPlan(plan, { dispatch, onFailure = null }) {
452
483
  }
453
484
  return
454
485
  }
455
- const results = await Promise.all(asSteps(step.value).map(({ request }) => dispatch(request)))
456
- const answers = results.map((result) => ({ data: result?.data, error: result?.error }))
486
+ const results = await Promise.all(
487
+ asSteps(step.value).map(({ request, held }) => (held ? fromCache(peek, request) : dispatch(request)))
488
+ )
489
+ const answers = results.map((result) =>
490
+ result?.missing ? { missing: true } : { data: result?.data, error: result?.error }
491
+ )
457
492
  sent = Array.isArray(step.value) ? answers : answers[0]
458
493
  }
459
494
  }))
@@ -27,6 +27,7 @@ export const PAGE_SHELL_VECTORS = [
27
27
  config: {
28
28
  name: `Café & "Co" <Ltd>'s`,
29
29
  favicon: '/favicon.svg?v=2',
30
+ touchIcon: '/touch-icon.png?a="1"',
30
31
  activeLocale: 'fr',
31
32
  extensions: ['https://assets.test/effects/entry.js', { url: '/ext/charts/entry.js' }, null],
32
33
  },
package/src/page-shell.js CHANGED
@@ -80,8 +80,8 @@ const extensionUrl = (entry) => (typeof entry === 'string' ? entry : entry?.url)
80
80
  *
81
81
  * @param {Object} input
82
82
  * @param {Object} input.content - one locale's content as the host stamped it: `config` (`name`,
83
- * `favicon`, `activeLocale`, `extensions` — each extension's entry URL, in declared order), the
84
- * pages, and any `fetchedData`
83
+ * `favicon`, `touchIcon`, `activeLocale`, `extensions` — each extension's entry URL, in declared
84
+ * order), the pages, and any `fetchedData`
85
85
  * @param {string} [input.route] - the served page's route as the content names it, so a split
86
86
  * site's `__DATA__` carries that page's sections (`dataScript`)
87
87
  * @param {{ url: string, cssUrl?: string }} input.foundation - the foundation's entry; its
@@ -113,6 +113,8 @@ export function pageShell({ content, route = null, foundation, runtime }) {
113
113
  config.favicon
114
114
  ? `<link rel="icon"${faviconType(config.favicon) ? ` type="${faviconType(config.favicon)}"` : ''} href="${escapeHtml(config.favicon)}">`
115
115
  : null,
116
+ // The icon iOS puts on a home screen and Safari on its start page — a PNG; neither uses an SVG favicon.
117
+ config.touchIcon ? `<link rel="apple-touch-icon" href="${escapeHtml(config.touchIcon)}">` : null,
116
118
  cssUrl ? `<link rel="stylesheet" href="${escapeHtml(cssUrl)}">` : null,
117
119
  // Before the module script and every preload: a browser reads an import map only ahead of them.
118
120
  `<script type="importmap">${jsonForScript({ imports: importMap })}</script>`,