@uniweb/build 1.23.1 → 1.23.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 +5 -5
- package/src/site/plugin.js +7 -9
- package/src/site/query-processor.js +86 -18
- package/src/site/undeclared-fields.js +60 -0
- package/src/uwx/records.js +10 -2
- package/src/validate-data.js +43 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.3",
|
|
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.2",
|
|
61
60
|
"@uniweb/projections": "~1.2.17",
|
|
62
|
-
"@uniweb/content-writer": "~1.3.2",
|
|
63
61
|
"@uniweb/content-reader": "~1.5.10",
|
|
64
|
-
"@uniweb/
|
|
65
|
-
"@uniweb/theming": "~1.3.2"
|
|
62
|
+
"@uniweb/schemas": "~1.7.4",
|
|
63
|
+
"@uniweb/theming": "~1.3.2",
|
|
64
|
+
"@uniweb/content-writer": "~1.3.2",
|
|
65
|
+
"@uniweb/semantic-parser": "~1.13.4"
|
|
66
66
|
},
|
|
67
67
|
"optionalDependencies": {
|
|
68
68
|
"@uniweb/runtime": "~1.6.3"
|
package/src/site/plugin.js
CHANGED
|
@@ -487,8 +487,10 @@ export function siteContentPlugin(options = {}) {
|
|
|
487
487
|
* @param {Object|undefined} config - the collected `config`, for the default locale a `sort` collates in
|
|
488
488
|
*/
|
|
489
489
|
async function materializeQueries(queries, config) {
|
|
490
|
-
|
|
491
|
-
|
|
490
|
+
// A site with no queries still has its records checked: `processQueries` stops on a folder
|
|
491
|
+
// whose data schema resolves to nothing, as a push does, and compiles nothing.
|
|
492
|
+
if (queries) console.log('[site-content] Materializing queries...')
|
|
493
|
+
const byQuery = await processQueries(resolvedSitePath, queries || {}, resolvedRecordsDir, basePath, {
|
|
492
494
|
locale: resolveDefaultLocale(config ?? {}) ?? null,
|
|
493
495
|
// ⭐ A draft is previewable here, as a hidden page is — `pnpm dev` is where the
|
|
494
496
|
// author looks at it. A production build leaves it out (`buildStart`).
|
|
@@ -676,10 +678,7 @@ export function siteContentPlugin(options = {}) {
|
|
|
676
678
|
resolvedRecordsDir = resolveRecordsDir(resolvedSitePath, paths).rel
|
|
677
679
|
resolvedMountPaths = mountEntriesOf(paths).map(([, rel]) => resolve(resolvedSitePath, rel))
|
|
678
680
|
|
|
679
|
-
|
|
680
|
-
console.log('[site-content] Materializing queries...')
|
|
681
|
-
await materializeQueries(queriesConfig, earlyContent.config)
|
|
682
|
-
}
|
|
681
|
+
await materializeQueries(queriesConfig, earlyContent.config)
|
|
683
682
|
} catch (err) {
|
|
684
683
|
console.warn('[site-content] Early query materialization failed:', err.message)
|
|
685
684
|
}
|
|
@@ -717,9 +716,8 @@ export function siteContentPlugin(options = {}) {
|
|
|
717
716
|
// In production, do it here — by the same call, so a `sort` collates in the site's default
|
|
718
717
|
// language in both. ⛔ Until 2026-10-25 this called `processQueries` with no language, and
|
|
719
718
|
// the built file was collated in English whatever the site's language.
|
|
720
|
-
if (isProduction
|
|
721
|
-
|
|
722
|
-
await materializeQueries(siteContent.config.queries, siteContent.config)
|
|
719
|
+
if (isProduction) {
|
|
720
|
+
await materializeQueries(siteContent.config?.queries, siteContent.config)
|
|
723
721
|
}
|
|
724
722
|
|
|
725
723
|
// Execute data fetches in dev mode
|
|
@@ -70,7 +70,9 @@ import { resolveRecordSchemas, resolveQueriesConfig, dataKeyTyping } from './que
|
|
|
70
70
|
import { keyOfDefaultRef } from '../uwx/data-key-types.js'
|
|
71
71
|
import { standardTypeFor } from './standard-type-for.js'
|
|
72
72
|
import { parseFrontmatter } from '../utils/frontmatter.js'
|
|
73
|
-
import { toDeliveredRecord, toStoredRecord, storedPath, briefFieldMap, contentBodyField, misplacedFields, mapReferences, recordLayout } from '@uniweb/schemas/conform'
|
|
73
|
+
import { toDeliveredRecord, toStoredRecord, storedPath, briefFieldMap, contentBodyField, misplacedFields, undeclaredFields, withoutUndeclared, mapReferences, recordLayout } from '@uniweb/schemas/conform'
|
|
74
|
+
import { ownsType, undeclaredAdvice, listOf } from './undeclared-fields.js'
|
|
75
|
+
import { siteSelfScope } from '../uwx/self-scope.js'
|
|
74
76
|
import { collectNestedRefs } from '@uniweb/schemas/format'
|
|
75
77
|
import { labelIn } from './entry-label.js'
|
|
76
78
|
import { fileRecordValue, makeFilePreview } from './file-records.js'
|
|
@@ -591,8 +593,14 @@ export const WHOLE_RECORD = Symbol.for('uniweb.query.whole')
|
|
|
591
593
|
*
|
|
592
594
|
* A record whose data schema this build cannot read (`resolveRecordSchemas`: a foundation that
|
|
593
595
|
* is not local, a schema registered under another scope) is delivered as its file holds it, a
|
|
594
|
-
* markdown body as `content
|
|
595
|
-
*
|
|
596
|
+
* markdown body as `content`. One whose schema the build can read and finds nothing for stops the
|
|
597
|
+
* build (`processQueries`).
|
|
598
|
+
*
|
|
599
|
+
* ⭐ ONE SHAPE ON BOTH LANES [Diego, 2026-11-11: "drop it, one shape on both lanes"]: what a
|
|
600
|
+
* record's schema has no place for is left out, as a host never holds it, since a push refuses it —
|
|
601
|
+
* a key no field declares (`withoutUndeclared`), and a markdown body with no field to hold it. The
|
|
602
|
+
* build says so (`noteUnsendable`). ⛔ Until 2026-11-11 both were delivered, the body as `content`,
|
|
603
|
+
* and a component reading one worked on a static site only. A markdown record
|
|
596
604
|
* also gets `excerpt` and `image` where it states none, derived from its body: the
|
|
597
605
|
* static lane's own, and not what a host adds.
|
|
598
606
|
*
|
|
@@ -629,14 +637,16 @@ function deliverRecord(file, config, where, body = null) {
|
|
|
629
637
|
} else {
|
|
630
638
|
const misplaced = misplacedFields(schema, record)
|
|
631
639
|
if (misplaced.length) throw new Error(flatFormRefusal(where, config.schema, schema, misplaced))
|
|
632
|
-
|
|
640
|
+
noteUnsendable(config, where, schema, record, body)
|
|
641
|
+
const declared = withoutUndeclared(schema, record)
|
|
642
|
+
out = { ...toDeliveredRecord(schema, declared) }
|
|
633
643
|
if (body) {
|
|
634
644
|
placeBody(out, schema, body)
|
|
635
645
|
out.excerpt = extractExcerpt(out, body.doc, config.excerpt)
|
|
636
646
|
out.image = out.image || extractFirstImage(body.doc)
|
|
637
647
|
}
|
|
638
648
|
if (config.references) out = config.references.deliver(schema, out, where)
|
|
639
|
-
out[WHOLE_RECORD] = storedRecord(
|
|
649
|
+
out[WHOLE_RECORD] = storedRecord(declared, schema, config, where, body, out)
|
|
640
650
|
}
|
|
641
651
|
if (handle !== undefined && handle !== null && handle !== '') {
|
|
642
652
|
out.$name = String(handle)
|
|
@@ -648,6 +658,55 @@ function deliverRecord(file, config, where, body = null) {
|
|
|
648
658
|
return out
|
|
649
659
|
}
|
|
650
660
|
|
|
661
|
+
/**
|
|
662
|
+
* Keep, for the note a build ends with, what a record holds that a push cannot carry: a key its
|
|
663
|
+
* data schema has no place for (`@uniweb/schemas/conform`'s `undeclaredFields`), and a markdown body
|
|
664
|
+
* with no field to hold it. The record is delivered without them, as a host delivers it
|
|
665
|
+
* (`deliverRecord`). ⭐ A note, never a stop: a static site is not held back by its schemas (`uniweb deploy` warns and ships), and
|
|
666
|
+
* `uniweb validate`, which the push and the publish run first, reports the same records. ⛔ Until
|
|
667
|
+
* 2026-11-11 nothing before the push said so.
|
|
668
|
+
*/
|
|
669
|
+
function noteUnsendable(config, where, schema, record, body) {
|
|
670
|
+
const notes = config.unsendable
|
|
671
|
+
if (!notes || notes.has(where)) return
|
|
672
|
+
const undeclared = undeclaredFields(schema, record)
|
|
673
|
+
const strandedBody = !!body && typeof body.markdown === 'string' && body.markdown.trim() !== '' && !contentBodyField(schema)
|
|
674
|
+
if (undeclared.length || strandedBody) notes.set(where, { ref: config.schema, undeclared, strandedBody })
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* The note for each record a push cannot carry (`noteUnsendable`), one line per file.
|
|
679
|
+
*
|
|
680
|
+
* @param {Map<string, { ref: string, undeclared: Array<{ path: string, declared: string[] }>, strandedBody: boolean }>} notes
|
|
681
|
+
* @param {string} siteDir - to read the foundation's scope, which says whose types it defines
|
|
682
|
+
*/
|
|
683
|
+
async function warnUnsendable(notes, siteDir) {
|
|
684
|
+
if (notes.size === 0) return
|
|
685
|
+
let scope
|
|
686
|
+
for (const [where, { ref, undeclared, strandedBody }] of notes) {
|
|
687
|
+
if (scope === undefined && !ownsType(ref, null) && !String(ref).startsWith('@std/')) scope = (await siteSelfScope(siteDir).catch(() => null)) ?? null
|
|
688
|
+
const owned = ownsType(ref, scope ?? null)
|
|
689
|
+
const parts = []
|
|
690
|
+
if (undeclared.length) {
|
|
691
|
+
const one = undeclared.length === 1
|
|
692
|
+
const paths = undeclared.map((u) => u.path)
|
|
693
|
+
const top = paths.every((p) => !/[.[]/.test(p))
|
|
694
|
+
parts.push(
|
|
695
|
+
`${listOf(paths.map((p) => `"${p}"`))} ${one ? 'is not a field' : 'are not fields'} of ${ref}, so the site ` +
|
|
696
|
+
`leaves ${one ? 'it' : 'them'} out, as a host does, and a push refuses ${one ? 'it' : 'them'}. ` +
|
|
697
|
+
undeclaredAdvice({ type: ref, owned, declared: top ? undeclared[0].declared : [], count: undeclared.length })
|
|
698
|
+
)
|
|
699
|
+
}
|
|
700
|
+
if (strandedBody) {
|
|
701
|
+
parts.push(
|
|
702
|
+
`its markdown body has no field in ${ref} to hold it (a \`markdown\` or \`richtext\` field), so the site leaves it ` +
|
|
703
|
+
'out, as a host does, and a push refuses it.'
|
|
704
|
+
)
|
|
705
|
+
}
|
|
706
|
+
console.warn(`[records] ${where}: ${parts.join(' And ')}`)
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
651
710
|
/**
|
|
652
711
|
* The record WHOLE, as stored — what its own file serves and a whole question answers: its file's
|
|
653
712
|
* fields under their sections (`toStoredRecord`), its markdown body in the content body field's
|
|
@@ -691,15 +750,13 @@ function placeBodyInFile(file, schema, body) {
|
|
|
691
750
|
/**
|
|
692
751
|
* Put a markdown body where the delivered record carries its schema's content body
|
|
693
752
|
* field (`contentBodyField`) — unless the record already states that field, or the body
|
|
694
|
-
* is empty. With no such field the body
|
|
753
|
+
* is empty. With no such field the body is left out, as a host has no place for it either
|
|
754
|
+
* (`deliverRecord`); ⛔ until 2026-11-11 it was delivered as `content`, at the top.
|
|
695
755
|
*/
|
|
696
756
|
function placeBody(out, schema, body) {
|
|
697
757
|
const blank = !body.markdown || !body.markdown.trim()
|
|
698
758
|
const target = contentBodyField(schema)
|
|
699
|
-
if (!target)
|
|
700
|
-
if (!blank) out.content = body.doc
|
|
701
|
-
return
|
|
702
|
-
}
|
|
759
|
+
if (!target) return
|
|
703
760
|
if (blank) return
|
|
704
761
|
const value = target.field?.type === 'text' ? body.markdown : body.doc
|
|
705
762
|
if (!target.section) {
|
|
@@ -862,7 +919,7 @@ async function processFileRecord(e, config, siteDir, recordsRoot, basePath) {
|
|
|
862
919
|
* its file carries. One that names no record of its schema is delivered as written, with
|
|
863
920
|
* a warning; `uniweb validate` reports it too.
|
|
864
921
|
*/
|
|
865
|
-
function referenceHydrator({ poolBySchema, dataSchemas, siteDir, recordsRoot, basePath, includeDrafts }) {
|
|
922
|
+
function referenceHydrator({ poolBySchema, dataSchemas, siteDir, recordsRoot, basePath, includeDrafts, unsendable = null }) {
|
|
866
923
|
const targets = new Map() // schema ref → Map(name or own id → the delivered reference)
|
|
867
924
|
const warned = new Set()
|
|
868
925
|
|
|
@@ -871,7 +928,7 @@ function referenceHydrator({ poolBySchema, dataSchemas, siteDir, recordsRoot, ba
|
|
|
871
928
|
const pooled = poolBySchema.get(ref) || []
|
|
872
929
|
const byName = new Map()
|
|
873
930
|
if (!schema || pooled.length === 0) return byName
|
|
874
|
-
const config = { schema: ref, dataSchema: schema, includeDrafts, excerpt: { maxLength: 160 }, references: null }
|
|
931
|
+
const config = { schema: ref, dataSchema: schema, includeDrafts, excerpt: { maxLength: 160 }, references: null, unsendable }
|
|
875
932
|
const keys = briefKeysOf(schema)
|
|
876
933
|
for (const result of await readPooledRecords(pooled, config, siteDir, recordsRoot, basePath)) {
|
|
877
934
|
for (const record of [result].flat()) {
|
|
@@ -1142,6 +1199,8 @@ function briefBuilder(schema) {
|
|
|
1142
1199
|
* draft is a record that is not delivered while the site is published.
|
|
1143
1200
|
* @param {Object} [options.dataSchemas] - normalized data schemas by ref, to deliver the
|
|
1144
1201
|
* records in; resolved from the site's foundation when absent (`resolveRecordSchemas`)
|
|
1202
|
+
* @param {boolean} [options.noteUnsendable=true] - end with a note for each record a push cannot
|
|
1203
|
+
* carry (`noteUnsendable`). Off for `uniweb validate`, which reports them itself
|
|
1145
1204
|
* @returns {Promise<Object>} Map of query name to items array
|
|
1146
1205
|
*
|
|
1147
1206
|
* @example
|
|
@@ -1150,11 +1209,15 @@ function briefBuilder(schema) {
|
|
|
1150
1209
|
* })
|
|
1151
1210
|
* // { articles: [...] }
|
|
1152
1211
|
*/
|
|
1153
|
-
export async function processQueries(siteDir,
|
|
1154
|
-
const { locale = null, includeDrafts = false } = options
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1212
|
+
export async function processQueries(siteDir, queriesConfigIn, recordsDir, basePath = '/', options = {}) {
|
|
1213
|
+
const { locale = null, includeDrafts = false, noteUnsendable: noting = true } = options
|
|
1214
|
+
// ⭐ A SITE WITH NO QUERIES STILL HAS ITS RECORDS CHECKED. Every file in the records directory is
|
|
1215
|
+
// a record a push sends, read by a query or not, so a folder whose data schema resolves to nothing
|
|
1216
|
+
// stops this as it stops the push (`refuseRecordsWithoutSchema`), and nothing is compiled. ⛔ Until
|
|
1217
|
+
// 2026-11-11 this returned at once with no queries, and so did `uniweb validate`, which compiles
|
|
1218
|
+
// through it: a site whose records no query read built, and conformed, and its push refused them.
|
|
1219
|
+
const queriesConfig = queriesConfigIn && typeof queriesConfigIn === 'object' ? queriesConfigIn : {}
|
|
1220
|
+
const hasQueries = Object.keys(queriesConfig).length > 0
|
|
1158
1221
|
|
|
1159
1222
|
// ⭐ ONE WALK FOR EVERY QUERY. Two queries over the same schema read one set of
|
|
1160
1223
|
// files; a query reads none of another schema's.
|
|
@@ -1162,6 +1225,7 @@ export async function processQueries(siteDir, queriesConfig, recordsDir, basePat
|
|
|
1162
1225
|
if (pool.errors.length) {
|
|
1163
1226
|
for (const e of pool.errors) console.warn(`[query-processor] ${e}`)
|
|
1164
1227
|
}
|
|
1228
|
+
if (!hasQueries && pool.entities.length === 0) return {}
|
|
1165
1229
|
|
|
1166
1230
|
// ⭐ EVERY FILE IN `records/` IS A RECORD (ruled 2026-09-21 [Diego]), so every one
|
|
1167
1231
|
// is compiled; `records/folder.yml` only says which folder each sits in (`$branch`),
|
|
@@ -1219,7 +1283,9 @@ export async function processQueries(siteDir, queriesConfig, recordsDir, basePat
|
|
|
1219
1283
|
refuseRecordsWithoutSchema(resolved.missing, { dir: pool.dir, poolBySchema, queriesConfig })
|
|
1220
1284
|
dataSchemas = resolved.schemas
|
|
1221
1285
|
}
|
|
1222
|
-
|
|
1286
|
+
// What a push cannot carry, by file, said once when every query has compiled (`noteUnsendable`).
|
|
1287
|
+
const unsendable = noting ? new Map() : null
|
|
1288
|
+
const references = referenceHydrator({ poolBySchema, dataSchemas, siteDir, recordsRoot, basePath, includeDrafts, unsendable })
|
|
1223
1289
|
|
|
1224
1290
|
const results = {}
|
|
1225
1291
|
|
|
@@ -1238,6 +1304,7 @@ export async function processQueries(siteDir, queriesConfig, recordsDir, basePat
|
|
|
1238
1304
|
parsed.includeDrafts = includeDrafts
|
|
1239
1305
|
parsed.dataSchema = (parsed.schema && dataSchemas[parsed.schema]) || null
|
|
1240
1306
|
parsed.references = references
|
|
1307
|
+
parsed.unsendable = unsendable
|
|
1241
1308
|
if (parsed.poolEntities.length === 0) {
|
|
1242
1309
|
const dirs = folderRef ? poolDirsForSchema(folderRef) : null
|
|
1243
1310
|
console.warn(
|
|
@@ -1251,6 +1318,7 @@ export async function processQueries(siteDir, queriesConfig, recordsDir, basePat
|
|
|
1251
1318
|
results[name] = items
|
|
1252
1319
|
console.log(`[query-processor] Processed ${name}: ${items.length} items`)
|
|
1253
1320
|
}
|
|
1321
|
+
if (unsendable) await warnUnsendable(unsendable, siteDir)
|
|
1254
1322
|
|
|
1255
1323
|
return results
|
|
1256
1324
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What to tell an author whose record holds a field its data schema has no place for: one wording
|
|
3
|
+
* for `uniweb validate` (`validate-data.js`), which reports it, and for the push
|
|
4
|
+
* (`uwx/records.js`), which refuses it. The rule that finds such a field is `@uniweb/schemas/conform`'s
|
|
5
|
+
* `undeclaredFields`.
|
|
6
|
+
*
|
|
7
|
+
* ⭐ WHO CAN CHANGE THE TYPE DECIDES THE ADVICE. A type the site's foundation defines (`@/x`, or
|
|
8
|
+
* a name in its scope) can be given the field. A standard type (`@std/x`), or a type of another
|
|
9
|
+
* scope, cannot be changed from the site: the advice names the fields it has and a type of the
|
|
10
|
+
* site's own. ⛔ Until 2026-11-11 the push said "Declare it in the schema" for every type, which
|
|
11
|
+
* nobody whose records are `@std/testimonial` can do.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Whether the site's foundation defines a type, and so can declare a field on it.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} type - the type as a record's folder or query names it (`@/member`, `@std/article`)
|
|
18
|
+
* @param {string|null} scope - the foundation's scope, with or without its `@`; null when unknown
|
|
19
|
+
* @returns {boolean}
|
|
20
|
+
*/
|
|
21
|
+
export function ownsType(type, scope) {
|
|
22
|
+
if (typeof type !== 'string') return true
|
|
23
|
+
if (type.startsWith('@/')) return true
|
|
24
|
+
const bare = typeof scope === 'string' ? scope.replace(/^@/, '') : ''
|
|
25
|
+
return bare !== '' && type.startsWith(`@${bare}/`)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The advice for one record's undeclared fields: declare or remove them, for a type the site
|
|
30
|
+
* owns; otherwise what the type has, and a type of the site's own.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} params
|
|
33
|
+
* @param {string} params.type - the type, as it is named to the author
|
|
34
|
+
* @param {boolean} params.owned - `ownsType`
|
|
35
|
+
* @param {string[]} [params.declared] - the names the type has where the fields were written
|
|
36
|
+
* @param {number} [params.count=1] - how many fields the advice is about
|
|
37
|
+
* @returns {string}
|
|
38
|
+
*/
|
|
39
|
+
export function undeclaredAdvice({ type, owned, declared = [], count = 1 }) {
|
|
40
|
+
const it = count === 1 ? 'it' : 'them'
|
|
41
|
+
if (owned) return `Declare ${it} in the schema, or remove ${it}.`
|
|
42
|
+
const which = type.startsWith('@std/') ? `${type} is a standard type` : `${type} is defined outside this site's foundation`
|
|
43
|
+
const values = count === 1 ? 'the value' : 'the values'
|
|
44
|
+
const has = declared.length ? ` It has ${listOf(declared)}: move ${values} into one of those,` : ''
|
|
45
|
+
return (
|
|
46
|
+
`${which}, and a site cannot add a field to it.${has}${has ? '' : ' Either'} remove ${it}, or ` +
|
|
47
|
+
'give these records a type of your own (`schemas/<name>.yml` in the foundation, the records in `records/<name>/`).'
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* `a`, `a and b`, `a, b and c`.
|
|
53
|
+
*
|
|
54
|
+
* @param {string[]} items
|
|
55
|
+
* @returns {string}
|
|
56
|
+
*/
|
|
57
|
+
export function listOf(items) {
|
|
58
|
+
if (items.length <= 1) return items.join('')
|
|
59
|
+
return `${items.slice(0, -1).join(', ')} and ${items[items.length - 1]}`
|
|
60
|
+
}
|
package/src/uwx/records.js
CHANGED
|
@@ -61,6 +61,7 @@ import { recordFileLayout, contentBodyTarget } from './record-layout.js'
|
|
|
61
61
|
import { emitEntitySyncPackage } from './entity-document.js'
|
|
62
62
|
import { qualifyRef } from '@uniweb/schemas/refs'
|
|
63
63
|
import { standardTypeFor } from '../site/standard-type-for.js'
|
|
64
|
+
import { ownsType, undeclaredAdvice } from '../site/undeclared-fields.js'
|
|
64
65
|
import { siteSelfScope, refuseOrgOption } from './self-scope.js'
|
|
65
66
|
import { sha256Hex, toJsonBuffer } from './manifest.js'
|
|
66
67
|
import { isUuid } from './uuid.js'
|
|
@@ -238,6 +239,8 @@ function encodeFieldValue(value, field, sourceLocale, translations, context = nu
|
|
|
238
239
|
* localized scalar fields per-locale (from loadLocaleTranslations)
|
|
239
240
|
* @param {{ resolve: (model: string, value: *) => object }} [params.refs] - what a
|
|
240
241
|
* reference sends (`refResolver`). Without it a reference is sent as written.
|
|
242
|
+
* @param {boolean} [params.owned=true] - whether the site's foundation defines the Model
|
|
243
|
+
* (`ownsType`), so a field it lacks can be declared on it; a refusal says what else to do
|
|
241
244
|
* @returns {{ entities: object[], warnings: string[], refusals: string[] }} each
|
|
242
245
|
* entity is `{ id, uuid, slug, model, file, document, namesNew }` — `document` is the
|
|
243
246
|
* section-keyed body, and `namesNew` how many of its references name a record this
|
|
@@ -252,6 +255,7 @@ export function recordsToEntities({
|
|
|
252
255
|
translations,
|
|
253
256
|
refs = null,
|
|
254
257
|
kept = null,
|
|
258
|
+
owned = true,
|
|
255
259
|
}) {
|
|
256
260
|
if (!declaration || !declaration.name) {
|
|
257
261
|
throw new Error('uwx/records: a declaration with a name is required')
|
|
@@ -329,11 +333,14 @@ export function recordsToEntities({
|
|
|
329
333
|
if (enc.misplaced.length) refusals.push(bySectionRefusal(where, declaration.name, layout, enc.misplaced))
|
|
330
334
|
if (enc.undeclared.length) {
|
|
331
335
|
const one = enc.undeclared.length === 1
|
|
336
|
+
// What the type has where the keys were written, named when they all sit at the top.
|
|
337
|
+
const top = enc.undeclared.every((path) => !/[.[]/.test(path))
|
|
338
|
+
const declared = !top ? [] : layout.flat ? Object.keys(layout.sections[0][1].fields || {}) : layout.sections.map(([n]) => n)
|
|
332
339
|
refusals.push(
|
|
333
340
|
`${where}: ${quoted(enc.undeclared)} ${one ? 'is not a field' : 'are not fields'} of ` +
|
|
334
341
|
`${declaration.name} — a push cannot carry ${one ? 'it' : 'them'}, and the next pull would ` +
|
|
335
|
-
`drop ${one ? 'it' : 'them'} from the file.
|
|
336
|
-
|
|
342
|
+
`drop ${one ? 'it' : 'them'} from the file. ` +
|
|
343
|
+
undeclaredAdvice({ type: declaration.name, owned, declared, count: enc.undeclared.length })
|
|
337
344
|
)
|
|
338
345
|
}
|
|
339
346
|
for (const problem of enc.shape) refusals.push(`${where}: ${problem}`)
|
|
@@ -1308,6 +1315,7 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
|
|
|
1308
1315
|
translations,
|
|
1309
1316
|
refs,
|
|
1310
1317
|
kept,
|
|
1318
|
+
owned: ownsType(declaration.name, scope),
|
|
1311
1319
|
})
|
|
1312
1320
|
// Free-form per-locale body overrides (a full localized doc beats the structural
|
|
1313
1321
|
// map) — only meaningful for a multi-locale site with a prosemirror content field.
|
package/src/validate-data.js
CHANGED
|
@@ -31,7 +31,7 @@ import { YAML_OPTIONS } from './utils/yaml-schema.js'
|
|
|
31
31
|
import { queryNameFromUrl, declaredKeys, fillDeclaredKeys, fetchLevels, pageRouteQuery } from '@uniweb/core'
|
|
32
32
|
import { parentRouteOf } from '@uniweb/core/route-match'
|
|
33
33
|
|
|
34
|
-
import { validateItem, validateRecordFile, validateBound, validateKeyValue, contentBodyField, rootListSection, referencesOf } from '@uniweb/schemas/conform'
|
|
34
|
+
import { validateItem, validateRecordFile, validateBound, validateKeyValue, contentBodyField, rootListSection, referencesOf, undeclaredFields } from '@uniweb/schemas/conform'
|
|
35
35
|
import { normalizeData } from '@uniweb/schemas/foundation'
|
|
36
36
|
import { isUuid } from './uwx/uuid.js'
|
|
37
37
|
import { validateAndNormalizeSchema, buildDataSchemaMap } from './resolve-data-schema.js'
|
|
@@ -48,6 +48,8 @@ import { toFetchList } from './site/data-fetcher.js'
|
|
|
48
48
|
import { resolveFoundationSrcPath } from './utils/foundation-source-root.js'
|
|
49
49
|
import { collectSiteContent } from './site/content-collector.js'
|
|
50
50
|
import { processQueries } from './site/query-processor.js'
|
|
51
|
+
import { ownsType, undeclaredAdvice } from './site/undeclared-fields.js'
|
|
52
|
+
import { siteSelfScope } from './uwx/self-scope.js'
|
|
51
53
|
|
|
52
54
|
// --- the join: sections ↔ schemas -------------------------------------------
|
|
53
55
|
|
|
@@ -142,12 +144,11 @@ export async function validateDataInputs({ siteRoot, foundationPath }) {
|
|
|
142
144
|
// Compile file-based byQuery in-memory (the same step the data-only
|
|
143
145
|
// pipeline runs). Full records — `writeQueryFiles` is the stage that
|
|
144
146
|
// strips `deferred:` fields, and we skip it.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
147
|
+
// Drafts included: a draft is content the site will deliver, so it is checked now.
|
|
148
|
+
// noteUnsendable: what a push cannot carry is reported below, as a violation (`validateRecordFiles`).
|
|
149
|
+
// ⭐ Run with no queries too: it stops on a records folder whose data schema resolves to nothing,
|
|
150
|
+
// as a push does. ⛔ Until 2026-11-11 it ran only for a site that declares queries.
|
|
151
|
+
const byQuery = await processQueries(siteRoot, config.queries || {}, resolveRecordsDir(siteRoot, config.paths).rel, basePath, { includeDrafts: true, noteUnsendable: false })
|
|
151
152
|
|
|
152
153
|
// Declared here rather than beside pass 2's other accumulators because pass 1
|
|
153
154
|
// now writes to it as well — see THE JOIN, RUN THE OTHER WAY below.
|
|
@@ -355,7 +356,9 @@ export async function validateDataInputs({ siteRoot, foundationPath }) {
|
|
|
355
356
|
// its folder names. ⭐ The set a push sends: every file in the records directory is
|
|
356
357
|
// a record and every record is pushed, whether or not a section reads it — and
|
|
357
358
|
// until 2026-09-24 one that no section read was never checked here.
|
|
358
|
-
|
|
359
|
+
// The foundation's scope says which types it defines, and so which can be given a field.
|
|
360
|
+
const scope = await siteSelfScope(siteRoot, { foundationDir: foundationPath })
|
|
361
|
+
const files = await validateRecordFiles(siteRoot, { srcDir, dataSchemas, keyTypes, paths: config.paths, checked: checkedRecords, scope })
|
|
359
362
|
violations.push(...files.violations)
|
|
360
363
|
setupErrors.push(...files.setupErrors)
|
|
361
364
|
for (const ref of files.schemas) schemasSeen.add(ref)
|
|
@@ -410,7 +413,7 @@ function listViolation(finding, label, base) {
|
|
|
410
413
|
*
|
|
411
414
|
* @returns {Promise<{ violations: object[], setupErrors: object[], schemas: Set<string>, checked: number }>}
|
|
412
415
|
*/
|
|
413
|
-
async function validateRecordFiles(siteRoot, { srcDir, dataSchemas, keyTypes = new Map(), paths, checked }) {
|
|
416
|
+
async function validateRecordFiles(siteRoot, { srcDir, dataSchemas, keyTypes = new Map(), paths, checked, scope = null }) {
|
|
414
417
|
const out = { violations: [], setupErrors: [], schemas: new Set(), checked: 0 }
|
|
415
418
|
const pool = await readEntityPool(siteRoot, { dir: resolveRecordsDir(siteRoot, paths).rel })
|
|
416
419
|
// Every record is read first: a reference names a record of another schema by its
|
|
@@ -466,6 +469,37 @@ async function validateRecordFiles(siteRoot, { srcDir, dataSchemas, keyTypes = n
|
|
|
466
469
|
out.violations.push({ file: pooled.relPath, schema: ref, item: r.slug, users: [], ...finding })
|
|
467
470
|
}
|
|
468
471
|
}
|
|
472
|
+
// ⭐ WHAT A PUSH CANNOT CARRY, in every record file, whichever pass checked the rest: a key
|
|
473
|
+
// its schema has no place for (`undeclaredFields`), and a markdown body with no field to hold
|
|
474
|
+
// it. The push refuses both (`uwx/records.js`), and runs this check first. ⛔ Until 2026-11-11
|
|
475
|
+
// neither was reported here, so `uniweb validate` passed a site whose push then stopped.
|
|
476
|
+
const owned = ownsType(ref, scope)
|
|
477
|
+
for (const { path, declared } of undeclaredFields(schema, record)) {
|
|
478
|
+
out.violations.push({
|
|
479
|
+
file: pooled.relPath,
|
|
480
|
+
schema: ref,
|
|
481
|
+
item: r.slug,
|
|
482
|
+
users: [],
|
|
483
|
+
field: path,
|
|
484
|
+
rule: 'undeclared',
|
|
485
|
+
message:
|
|
486
|
+
`not a field of ${ref}, so a push cannot carry it, and a pull would drop it from the file. ` +
|
|
487
|
+
undeclaredAdvice({ type: ref, owned, declared: path.includes('.') || path.includes('[') ? [] : declared }),
|
|
488
|
+
})
|
|
489
|
+
}
|
|
490
|
+
if (typeof r.body === 'string' && r.body.trim() !== '' && !contentBodyField(schema)) {
|
|
491
|
+
out.violations.push({
|
|
492
|
+
file: pooled.relPath,
|
|
493
|
+
schema: ref,
|
|
494
|
+
item: r.slug,
|
|
495
|
+
users: [],
|
|
496
|
+
field: '',
|
|
497
|
+
rule: 'body',
|
|
498
|
+
message:
|
|
499
|
+
`the file has a markdown body, and ${ref} has no field for it (a \`markdown\` or \`richtext\` field), ` +
|
|
500
|
+
`so a push cannot carry it. ${owned ? 'Add one to the schema, or move the text into a field.' : 'Move the text into a field, or give these records a type of your own.'}`,
|
|
501
|
+
})
|
|
502
|
+
}
|
|
469
503
|
// ⭐ A reference must name a record — a push refuses one that does not. A uuid is
|
|
470
504
|
// left alone: it may be a record the backend holds and this project does not.
|
|
471
505
|
for (const { path, ref: target, value } of referencesOf(schema, record)) {
|