@uniweb/build 1.24.1 → 1.24.2

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/build",
3
- "version": "1.24.1",
3
+ "version": "1.24.2",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -57,12 +57,12 @@
57
57
  "js-yaml": "^4.3.2",
58
58
  "sharp": "^0.35.5",
59
59
  "yaml": "^2.5.0",
60
- "@uniweb/schemas": "~1.7.4",
61
60
  "@uniweb/theming": "~1.3.2",
62
- "@uniweb/content-writer": "~1.3.2",
61
+ "@uniweb/schemas": "~1.7.4",
63
62
  "@uniweb/content-reader": "~1.5.11",
64
63
  "@uniweb/semantic-parser": "~1.13.5",
65
- "@uniweb/projections": "~1.2.17"
64
+ "@uniweb/projections": "~1.2.17",
65
+ "@uniweb/content-writer": "~1.3.2"
66
66
  },
67
67
  "optionalDependencies": {
68
68
  "@uniweb/runtime": "~1.6.5"
@@ -28,6 +28,11 @@
28
28
  * - a `keys_from` that names no mapping, or an `@/x` that isn't one of the foundation's;
29
29
  * - a reverse `follow` line's `model` that names no type, or an `@/x` the foundation doesn't define.
30
30
  *
31
+ * A `set` mapping (`shape: set`) reads one file into several linked types: its `model` is the root
32
+ * part's type, and each of its `parts` names its own `model` (and may carry its own `keys_from` and
33
+ * `follow`). Each part is checked, and written in full, as a mapping's top level is; the rest of a
34
+ * set's rules are the backend's to judge.
35
+ *
31
36
  * Mappings are editor-time only: they ride in `schema.json` as `_mappings` and never reach a page.
32
37
  *
33
38
  * @module
@@ -125,35 +130,57 @@ export function mappingProblems(decl, { types, names }) {
125
130
  }
126
131
  if (!('model' in decl)) {
127
132
  found.push("`model` is missing: name the type the mapping translates, `model: '@/vehicle'`.")
128
- } else {
129
- const problem = refProblem('model', decl.model, 'type')
133
+ }
134
+ found.push(...ruleProblems(decl, '', { types, names }))
135
+ if (Array.isArray(decl.parts)) {
136
+ for (const [i, part] of decl.parts.entries()) {
137
+ const at = `parts[${i}].`
138
+ if (!isMap(part)) continue
139
+ if (!('model' in part)) found.push(`\`${at}model\` is missing: name the type this part reads, \`model: '@/lesson'\`.`)
140
+ found.push(...ruleProblems(part, at, { types, names }))
141
+ }
142
+ }
143
+ return found
144
+ }
145
+
146
+ /** The names one rule set gives — a mapping's top level, or one part of a `set` — checked. */
147
+ function ruleProblems(rules, at, { types, names }) {
148
+ const found = []
149
+ if ('model' in rules) {
150
+ const problem = refProblem(`${at}model`, rules.model, 'type')
130
151
  if (problem) found.push(problem)
131
- else if (decl.model.startsWith('@/') && !types.has(decl.model)) {
132
- found.push(`\`model\` is \`${decl.model}\`, which is not one of the foundation's types (src/schemas/).`)
152
+ else if (rules.model.startsWith('@/') && !types.has(rules.model)) {
153
+ found.push(`\`${at}model\` is \`${rules.model}\`, which is not one of the foundation's types (src/schemas/).`)
133
154
  }
134
155
  }
135
- if ('keys_from' in decl) {
136
- const problem = refProblem('keys_from', decl.keys_from, 'mapping')
156
+ if ('keys_from' in rules) {
157
+ const problem = refProblem(`${at}keys_from`, rules.keys_from, 'mapping')
137
158
  if (problem) found.push(problem)
138
- else if (decl.keys_from.startsWith('@/') && !names.has(decl.keys_from)) {
139
- found.push(`\`keys_from\` is \`${decl.keys_from}\`, which is not one of the foundation's mappings (src/${MAPPINGS_DIR}/).`)
159
+ else if (rules.keys_from.startsWith('@/') && !names.has(rules.keys_from)) {
160
+ found.push(`\`${at}keys_from\` is \`${rules.keys_from}\`, which is not one of the foundation's mappings (src/${MAPPINGS_DIR}/).`)
140
161
  }
141
162
  }
142
- found.push(...followProblems(decl.follow, types))
163
+ found.push(...followProblems(rules.follow, types, at))
143
164
  return found
144
165
  }
145
166
 
146
167
  /**
147
168
  * A mapping with every type and mapping it names in full (`scoped`: `@/x` → `@scope/x`): its `model`,
148
- * its `keys_from` and a reverse `follow` line's `model`. Nothing else moves, and the file's own object
149
- * is never touched.
169
+ * its `keys_from` and a reverse `follow` line's `model`, and the same in each of a `set`'s `parts`.
170
+ * Nothing else moves, and the file's own object is never touched.
150
171
  *
151
172
  * @param {object} decl - as written
152
173
  * @param {(ref: string) => string} scoped
153
174
  * @returns {object}
154
175
  */
155
176
  export function mappingInFull(decl, scoped) {
156
- const out = { ...decl }
177
+ const out = rulesInFull(decl, scoped)
178
+ if (Array.isArray(out.parts)) out.parts = out.parts.map((part) => (isMap(part) ? rulesInFull(part, scoped) : part))
179
+ return out
180
+ }
181
+
182
+ function rulesInFull(rules, scoped) {
183
+ const out = { ...rules }
157
184
  if (typeof out.model === 'string') out.model = scoped(out.model)
158
185
  if (typeof out.keys_from === 'string') out.keys_from = scoped(out.keys_from)
159
186
  if (Array.isArray(out.follow)) {
@@ -187,9 +214,10 @@ export function followModels(follow) {
187
214
  return out
188
215
  }
189
216
 
190
- function followProblems(follow, types) {
217
+ function followProblems(follow, types, prefix = '') {
191
218
  const found = []
192
- for (const { at, spec } of followModels(follow)) {
219
+ for (const { at: where, spec } of followModels(follow)) {
220
+ const at = `${prefix}${where}`
193
221
  const problem = refProblem(at, spec.model, 'type')
194
222
  if (problem) found.push(problem)
195
223
  else if (spec.model.startsWith('@/') && !types.has(spec.model)) {
@@ -53,6 +53,8 @@ import { existsSync, readFileSync } from 'node:fs'
53
53
  import { join, resolve } from 'node:path'
54
54
  import yaml from 'js-yaml'
55
55
  import { qualifyRef } from '@uniweb/schemas/refs'
56
+ import { dataRefOf } from '@uniweb/core/data-keys'
57
+ import { isBackendModel } from '../backend-models.js'
56
58
  import { YAML_OPTIONS } from '../utils/yaml-schema.js'
57
59
  import { unresolveSelfScope, bareOrg } from './self-scope.js'
58
60
  import { writeYamlFile } from './project-writer.js'
@@ -440,6 +442,29 @@ function readSiteYml(siteRoot) {
440
442
  }
441
443
  }
442
444
 
445
+ /**
446
+ * The Models only a site backend holds (`@uniweb/catalog`) that a foundation's section types, layouts or
447
+ * main.js declare as data. Its `schema.json` carries no copy of one (`../backend-models.js`), so its
448
+ * data keys say it is a type the foundation renders, as a site backend counts it when it starts
449
+ * (backend, 2026-11-17: a blueprint line opening the catalog is applied once a foundation declares it).
450
+ */
451
+ function backendModelsRendered(schema) {
452
+ const out = new Set()
453
+ const visit = (data) => {
454
+ if (!isMap(data)) return
455
+ for (const value of Object.values(data)) {
456
+ const { ref } = dataRefOf(value)
457
+ if (isBackendModel(ref)) out.add(ref)
458
+ }
459
+ }
460
+ for (const [key, entry] of Object.entries(schema || {})) {
461
+ if (key === '_self') visit(entry?.data)
462
+ else if (key === '_layouts' && isMap(entry)) for (const layout of Object.values(entry)) visit(layout?.data)
463
+ else if (key !== 'dataSchemas' && !key.startsWith('_')) visit(entry?.data)
464
+ }
465
+ return out
466
+ }
467
+
443
468
  /**
444
469
  * The types a site's foundations declare, each in full — the data schemas a backend started from the
445
470
  * site installs: its foundation's and each extension's, the `dataSchemas` `register` registers.
@@ -477,6 +502,7 @@ export async function siteDeclaredTypes(siteRoot, siteYml, { scope = null, found
477
502
  if (!schema) unread.push('its foundation could not be read')
478
503
  else {
479
504
  for (const ref of Object.keys(schema.dataSchemas || {})) types.add(qualifyRef(ref, scope))
505
+ for (const ref of backendModelsRendered(schema)) types.add(ref)
480
506
  for (const ref of Object.keys(schema._mappings || {})) mappings.add(qualifyRef(ref, scope))
481
507
  addVendors(schema, scope)
482
508
  }
@@ -502,6 +528,7 @@ export async function siteDeclaredTypes(siteRoot, siteYml, { scope = null, found
502
528
  }
503
529
  types.add(qualifyRef(ref, extScope))
504
530
  }
531
+ for (const ref of backendModelsRendered(schema)) types.add(ref)
505
532
  for (const ref of Object.keys(schema._mappings || {})) mappings.add(qualifyRef(ref, extScope))
506
533
  addVendors(schema, extScope)
507
534
  }
@@ -216,7 +216,7 @@ function buildDataSchemaEntities(dataSchemas, scope) {
216
216
  * One `@uniweb/mapping-schema` entity per mapping the foundation defines (`schema._mappings`,
217
217
  * `foundation/mappings.js`): its identity flat, as a data schema's is, and the rest of the file under
218
218
  * `rules` — the envelope's `model:` names the exchange type, so the mapping's own `model:` cannot sit
219
- * beside it. `rules.model`, `rules.keys_from` and a reverse `follow` line's `model` are named in
219
+ * beside it. `rules.model`, `rules.keys_from` and a reverse `follow` line's `model` (and the same in each of a `set`'s `parts`) are named in
220
220
  * full; nothing else in `rules` is touched, since a backend judges it. A mapping another one names in `keys_from` comes first.
221
221
  *
222
222
  * @param {Object<string, object>} mappings - `{ '@/<name>': declaration }`