@uniweb/build 0.63.1 → 0.63.3

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": "0.63.1",
3
+ "version": "0.63.3",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -59,9 +59,9 @@
59
59
  "yaml": "^2.5.0",
60
60
  "@uniweb/content-reader": "^1.2.5",
61
61
  "@uniweb/content-writer": "^0.3.4",
62
- "@uniweb/schemas": "^0.7.0",
63
- "@uniweb/projections": "^0.7.3",
64
62
  "@uniweb/semantic-parser": "^1.4.1",
63
+ "@uniweb/projections": "^0.7.3",
64
+ "@uniweb/schemas": "^0.7.0",
65
65
  "@uniweb/theming": "^0.1.15"
66
66
  },
67
67
  "optionalDependencies": {
@@ -19,9 +19,10 @@
19
19
  import { declaredKeys } from '@uniweb/core/data-keys'
20
20
 
21
21
  /**
22
- * The type each data key of a foundation's section types names, where every declaration of the
23
- * key agrees on one — from its built `schema.json`, whose section types sit at the top level
24
- * beside `_self` and `dataSchemas`, each with its `data:`.
22
+ * The type each data key of a foundation names, where every declaration of the key agrees on
23
+ * one — from its built `schema.json`: each section type's `data:` (at the top level, beside
24
+ * `_self` and `dataSchemas`), each layout's (under `_layouts`), and the foundation's own, which
25
+ * reaches every section (`main.js` `data:`, under `_self`).
25
26
  *
26
27
  * @param {object|null} foundationSchema - a foundation's built `dist/meta/schema.json`
27
28
  * @returns {Map<string, string>} data key → its schema ref (`team` → `@/member`)
@@ -29,14 +30,19 @@ import { declaredKeys } from '@uniweb/core/data-keys'
29
30
  export function dataKeyTypes(foundationSchema) {
30
31
  const types = new Map()
31
32
  const conflicted = new Set()
32
- for (const [name, entry] of Object.entries(foundationSchema || {})) {
33
- if (name === '_self' || name === 'dataSchemas' || !entry || typeof entry !== 'object') continue
34
- for (const [key, ref] of declaredKeys(entry.data)) {
33
+ const declare = (data) => {
34
+ for (const [key, ref] of declaredKeys(data)) {
35
35
  if (!ref) continue
36
36
  if (types.has(key) && types.get(key) !== ref) conflicted.add(key)
37
37
  else types.set(key, ref)
38
38
  }
39
39
  }
40
+ for (const [name, entry] of Object.entries(foundationSchema || {})) {
41
+ if (!entry || typeof entry !== 'object' || name === 'dataSchemas') continue
42
+ if (name === '_self') declare(entry.data)
43
+ else if (name === '_layouts') for (const layout of Object.values(entry)) declare(layout?.data)
44
+ else if (!name.startsWith('_')) declare(entry.data)
45
+ }
40
46
  for (const key of conflicted) types.delete(key)
41
47
  return types
42
48
  }
@@ -41,7 +41,7 @@ import yaml from 'js-yaml'
41
41
  import { YAML_OPTIONS } from '../utils/yaml-schema.js'
42
42
  import { parseFrontmatter } from './entity-source.js'
43
43
  import { writeRecordFile, writeQueriesConfig, writeRecordsConfig } from './project-writer.js'
44
- import { defaultSchema, deferredFromSchema, foundationDataSchemas, foundationSchemaJson } from './queries-config.js'
44
+ import { defaultSchema, deferredFromSchema, foundationDataSchemas, foundationSchemaJson, QUERIES_YML_RELPATH } from './queries-config.js'
45
45
  import { dataKeyTypes } from './data-key-types.js'
46
46
  import { poolDirsForSchema, schemaForPoolDirs, resolveRecordsDir } from '../site/entity-pool.js'
47
47
  import { folderYmlPath } from '../site/records-config.js'
@@ -283,7 +283,7 @@ function isDerivedDeferred(d, dataSchemas) {
283
283
  return d.deferred.every((f) => a.has(f))
284
284
  }
285
285
 
286
- function declToFileShape(wire, dataSchemas = null, scope = null, own = null, keyTypes = null) {
286
+ function declToFileShape(wire, dataSchemas = null, scope = null, own = null, keyTypes = null, authored = null) {
287
287
  // ⛔ UNDO THE PRODUCER'S QUALIFICATION FIRST, before anything compares against
288
288
  // `schema`. The push qualifies a foundation-relative `@/x` to `@scope/x`
289
289
  // (`site.js::queriesNested`), and both checks below are keyed by the author's
@@ -317,8 +317,14 @@ function declToFileShape(wire, dataSchemas = null, scope = null, own = null, key
317
317
  // The default is the query's name — or, when no data schema has that name, the type the
318
318
  // foundation declares for the data key of that name (`data-key-types.js`), which is what a
319
319
  // push sent in its place. Either one stays unwritten, so the terse file stays terse.
320
+ // ⛔ UNLESS THE AUTHOR WROTE IT: a `schema:` the local file already states for this query is
321
+ // written back as it is. Until 2026-09-25 a pull into a working copy dropped international's
322
+ // `articles: { schema: '@std/article' }`, because a section types `articles` as `@std/article`.
320
323
  const keyDefault = name && !own?.has(name) ? keyTypes?.get(name) : null
321
- if (d.schema && d.schema !== defaultSchema(name) && d.schema !== keyDefault) decl.schema = d.schema
324
+ const written = name ? authored?.get(name) : undefined
325
+ if (d.schema && (d.schema === written || (d.schema !== defaultSchema(name) && d.schema !== keyDefault))) {
326
+ decl.schema = d.schema
327
+ }
322
328
  setIf(decl, 'sort', d.sort)
323
329
  setIf(decl, 'where', d.where)
324
330
  setIf(decl, 'limit', d.limit)
@@ -383,6 +389,26 @@ function declToFileShape(wire, dataSchemas = null, scope = null, own = null, key
383
389
  * (`info.foundation`, the pinned `@org/name@version`), which is that scope.
384
390
  * @returns {{ collections?: 'updated'|'unchanged' }}
385
391
  */
392
+ // The `schema:` each query's author wrote, by query name — `queries.yml` over `site.yml::queries`,
393
+ // the precedence the build reads them in. A query written without one is absent.
394
+ function authoredQuerySchemas(siteRoot, siteYml) {
395
+ let file = null
396
+ try {
397
+ file = yaml.load(readFileSync(join(siteRoot, QUERIES_YML_RELPATH), 'utf8'), YAML_OPTIONS)
398
+ } catch {
399
+ file = null
400
+ }
401
+ const out = new Map()
402
+ for (const decls of [siteYml?.queries, file]) {
403
+ if (!decls || typeof decls !== 'object') continue
404
+ for (const [name, decl] of Object.entries(decls)) {
405
+ if (typeof decl?.schema === 'string') out.set(name, decl.schema)
406
+ else if (out.has(name)) out.delete(name)
407
+ }
408
+ }
409
+ return out
410
+ }
411
+
386
412
  export function declarationsToQueriesYml({ document, siteRoot, scope, ...rest }) {
387
413
  refuseOrgOption(rest, 'declarationsToQueriesYml')
388
414
  const decls = Array.isArray(document?.queries) ? document.queries : []
@@ -408,10 +434,11 @@ export function declarationsToQueriesYml({ document, siteRoot, scope, ...rest })
408
434
  // (`unresolveSelfScope`) — and the types of its data keys.
409
435
  const own = ownSchemaNames(dataSchemas)
410
436
  const keyTypes = siteYml ? dataKeyTypes(foundationSchemaJson(siteRoot, siteYml)) : null
437
+ const authored = authoredQuerySchemas(siteRoot, siteYml)
411
438
 
412
439
  const queries = {}
413
440
  for (const d of decls) {
414
- const { name, decl } = declToFileShape(d, dataSchemas, selfScope, own, keyTypes)
441
+ const { name, decl } = declToFileShape(d, dataSchemas, selfScope, own, keyTypes, authored)
415
442
  if (!name) continue
416
443
  queries[name] = decl
417
444
  }
@@ -41,6 +41,7 @@ import { validateAndNormalizeSchema, buildDataSchemaMap } from './resolve-data-s
41
41
  export { validateItem, isStaticallyCheckable } from '@uniweb/schemas/conform'
42
42
  import { buildSchema } from './schema.js'
43
43
  import { resolveRecordsDir, readEntityPool, groupPoolBySchema } from './site/entity-pool.js'
44
+ import { dataKeyTypes, keyOfDefaultRef } from './uwx/data-key-types.js'
44
45
  import { readEntityFile } from './uwx/entity-source.js'
45
46
  import { toFetchList } from './site/data-fetcher.js'
46
47
  import { resolveFoundationSrcPath } from './utils/foundation-source-root.js'
@@ -86,6 +87,9 @@ export async function validateDataInputs({ siteRoot, foundationPath }) {
86
87
  const srcDir = resolveFoundationSrcPath(foundationPath)
87
88
  const foundation = await buildSchema(srcDir)
88
89
  const dataSchemas = foundation.dataSchemas || {}
90
+ // The type each data key names — a records folder named for a typed key holds records of
91
+ // that type when no data schema has its name (`uwx/data-key-types.js`).
92
+ const keyTypes = dataKeyTypes(foundation)
89
93
 
90
94
  const site = await collectSiteContent(siteRoot, { foundationPath })
91
95
  const config = site.config || {}
@@ -275,7 +279,7 @@ export async function validateDataInputs({ siteRoot, foundationPath }) {
275
279
  // its folder names. ⭐ The set a push sends: every file in the records directory is
276
280
  // a record and every record is pushed, whether or not a section reads it — and
277
281
  // until 2026-09-24 one that no section read was never checked here.
278
- const files = await validateRecordFiles(siteRoot, { srcDir, dataSchemas, paths: config.paths, checked: checkedRecords })
282
+ const files = await validateRecordFiles(siteRoot, { srcDir, dataSchemas, keyTypes, paths: config.paths, checked: checkedRecords })
279
283
  violations.push(...files.violations)
280
284
  setupErrors.push(...files.setupErrors)
281
285
  for (const ref of files.schemas) schemasSeen.add(ref)
@@ -321,22 +325,34 @@ function listViolation(finding, label, base) {
321
325
  * that names no record of its schema is reported under the rule `ref`, since a push
322
326
  * cannot send it.
323
327
  *
324
- * A folder whose schema resolves to nothing is left out in silence: its records are
325
- * schema-less, delivered as files, and the push says so itself.
328
+ * ⭐ A folder named for a data key the foundation types, when no data schema has its name,
329
+ * holds records of that type and is checked against it — `records/team/` against `@/member`
330
+ * for `data: { team: '@/member' }` — the way a push sends them [Diego, 2026-09-25]
331
+ * (`uwx/data-key-types.js`). A folder whose schema resolves to nothing even so is left out in
332
+ * silence: its records are schema-less, delivered as files, and the push says so itself.
326
333
  *
327
334
  * @returns {Promise<{ violations: object[], setupErrors: object[], schemas: Set<string>, checked: number }>}
328
335
  */
329
- async function validateRecordFiles(siteRoot, { srcDir, dataSchemas, paths, checked }) {
336
+ async function validateRecordFiles(siteRoot, { srcDir, dataSchemas, keyTypes = new Map(), paths, checked }) {
330
337
  const out = { violations: [], setupErrors: [], schemas: new Set(), checked: 0 }
331
338
  const pool = await readEntityPool(siteRoot, { dir: resolveRecordsDir(siteRoot, paths).rel })
332
339
  // Every record is read first: a reference names a record of another schema by its
333
340
  // name — its file's, or its `slug:` — or by the id its file carries.
334
341
  const read = []
335
342
  const names = new Map() // schema (as its folder names it) → the names and ids of its records
336
- for (const [ref, entities] of groupPoolBySchema(pool.entities)) {
337
- const schema = await schemaForRecords(ref, { srcDir, dataSchemas })
343
+ for (const [folderRef, entities] of groupPoolBySchema(pool.entities)) {
344
+ let ref = folderRef
345
+ let schema = await schemaForRecords(folderRef, { srcDir, dataSchemas })
346
+ const typed = schema ? null : keyTypes.get(keyOfDefaultRef(folderRef))
347
+ if (typed) {
348
+ schema = await schemaForRecords(typed, { srcDir, dataSchemas })
349
+ if (schema) ref = typed
350
+ }
351
+ // Records are named under what they ARE — a reference to `@/member` finds the ones kept
352
+ // in `records/team/` — and under the folder's own ref as well.
338
353
  const known = names.get(ref) ?? new Set()
339
354
  names.set(ref, known)
355
+ if (ref !== folderRef) names.set(folderRef, known)
340
356
  for (const pooled of entities) {
341
357
  let records
342
358
  try {