@uniweb/core 1.6.10 → 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 +8 -24
- package/src/page-data.js +60 -0
package/package.json
CHANGED
package/src/entity-store.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { resolveFetchConfigs } from './fetch-config.js'
|
|
18
18
|
import { fillRoutePattern } from './route-match.js'
|
|
19
|
-
import { blockRouteQuery,
|
|
19
|
+
import { blockRouteQuery, blockFillsOf, pageRecordPlan, planFor, runPlan, runPlanSync } from './page-data.js'
|
|
20
20
|
|
|
21
21
|
export default class EntityStore {
|
|
22
22
|
/**
|
|
@@ -72,30 +72,14 @@ export default class EntityStore {
|
|
|
72
72
|
* when the page's route query resolves to nothing
|
|
73
73
|
*/
|
|
74
74
|
async fetchPageRecord(page, { dispatcher = this.website?.fetcher } = {}) {
|
|
75
|
-
|
|
76
|
-
if (!dynamicContext || !dispatcher) return null
|
|
75
|
+
if (!page?.dynamicContext || !dispatcher) return null
|
|
77
76
|
|
|
78
|
-
//
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
route,
|
|
85
|
-
site: this.website?.config?.fetch,
|
|
86
|
-
options: blockFetchOptions(probe),
|
|
87
|
-
})
|
|
88
|
-
if (!cfg) return null
|
|
89
|
-
|
|
90
|
-
const plan = planFor(new Map([[route.key, { cfg }]]), {
|
|
91
|
-
dynamicContext,
|
|
92
|
-
route,
|
|
93
|
-
// The page is about ONE record, whatever a section's `current:` says.
|
|
94
|
-
current: 'only',
|
|
95
|
-
peekRecord: (id) => dispatcher.peekRecord?.(id),
|
|
96
|
-
})
|
|
97
|
-
const ctx = this._ctx(probe)
|
|
98
|
-
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, {
|
|
99
83
|
dispatch: (request) => dispatcher.dispatch(request, ctx),
|
|
100
84
|
peek: (request) => dispatcher.peek?.(request, ctx),
|
|
101
85
|
})
|
package/src/page-data.js
CHANGED
|
@@ -240,6 +240,66 @@ export function blockFillsOf(block, meta, route = blockRouteQuery(block)) {
|
|
|
240
240
|
})
|
|
241
241
|
}
|
|
242
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
|
+
|
|
243
303
|
/**
|
|
244
304
|
* The fetch a parametric page's OWN record is asked for with — its route query, resolved.
|
|
245
305
|
*
|