@uniweb/core 1.4.10 → 1.4.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 +3 -3
- package/src/entity-store.js +6 -1
- package/src/page-data.js +42 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.11",
|
|
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/
|
|
57
|
-
"@uniweb/
|
|
56
|
+
"@uniweb/theming": "~1.2.1",
|
|
57
|
+
"@uniweb/semantic-parser": "~1.13.0"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"test": "vitest run"
|
package/src/entity-store.js
CHANGED
|
@@ -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, {
|
|
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
|
-
/**
|
|
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
|
|
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(
|
|
456
|
-
|
|
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
|
}))
|