@uniweb/build 1.23.1 → 1.23.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 +3 -3
- package/src/site/plugin.js +7 -9
- package/src/site/query-processor.js +71 -9
- 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.2",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -57,11 +57,11 @@
|
|
|
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",
|
|
62
|
+
"@uniweb/content-writer": "~1.3.2",
|
|
64
63
|
"@uniweb/semantic-parser": "~1.13.4",
|
|
64
|
+
"@uniweb/schemas": "~1.7.3",
|
|
65
65
|
"@uniweb/theming": "~1.3.2"
|
|
66
66
|
},
|
|
67
67
|
"optionalDependencies": {
|
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, 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'
|
|
@@ -629,6 +631,7 @@ function deliverRecord(file, config, where, body = null) {
|
|
|
629
631
|
} else {
|
|
630
632
|
const misplaced = misplacedFields(schema, record)
|
|
631
633
|
if (misplaced.length) throw new Error(flatFormRefusal(where, config.schema, schema, misplaced))
|
|
634
|
+
noteUnsendable(config, where, schema, record, body)
|
|
632
635
|
out = { ...toDeliveredRecord(schema, record) }
|
|
633
636
|
if (body) {
|
|
634
637
|
placeBody(out, schema, body)
|
|
@@ -648,6 +651,54 @@ function deliverRecord(file, config, where, body = null) {
|
|
|
648
651
|
return out
|
|
649
652
|
}
|
|
650
653
|
|
|
654
|
+
/**
|
|
655
|
+
* Keep, for the note a build ends with, what a record holds that a push cannot carry: a key its
|
|
656
|
+
* data schema has no place for (`@uniweb/schemas/conform`'s `undeclaredFields`), and a markdown body
|
|
657
|
+
* with no field to hold it. The record is still delivered as its file holds it. ⭐ A note, never a
|
|
658
|
+
* stop: a static site is not held back by its schemas (`uniweb deploy` warns and ships), and
|
|
659
|
+
* `uniweb validate`, which the push and the publish run first, reports the same records. ⛔ Until
|
|
660
|
+
* 2026-11-11 nothing before the push said so.
|
|
661
|
+
*/
|
|
662
|
+
function noteUnsendable(config, where, schema, record, body) {
|
|
663
|
+
const notes = config.unsendable
|
|
664
|
+
if (!notes || notes.has(where)) return
|
|
665
|
+
const undeclared = undeclaredFields(schema, record)
|
|
666
|
+
const strandedBody = !!body && typeof body.markdown === 'string' && body.markdown.trim() !== '' && !contentBodyField(schema)
|
|
667
|
+
if (undeclared.length || strandedBody) notes.set(where, { ref: config.schema, undeclared, strandedBody })
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* The note for each record a push cannot carry (`noteUnsendable`), one line per file.
|
|
672
|
+
*
|
|
673
|
+
* @param {Map<string, { ref: string, undeclared: Array<{ path: string, declared: string[] }>, strandedBody: boolean }>} notes
|
|
674
|
+
* @param {string} siteDir - to read the foundation's scope, which says whose types it defines
|
|
675
|
+
*/
|
|
676
|
+
async function warnUnsendable(notes, siteDir) {
|
|
677
|
+
if (notes.size === 0) return
|
|
678
|
+
let scope
|
|
679
|
+
for (const [where, { ref, undeclared, strandedBody }] of notes) {
|
|
680
|
+
if (scope === undefined && !ownsType(ref, null) && !String(ref).startsWith('@std/')) scope = (await siteSelfScope(siteDir).catch(() => null)) ?? null
|
|
681
|
+
const owned = ownsType(ref, scope ?? null)
|
|
682
|
+
const parts = []
|
|
683
|
+
if (undeclared.length) {
|
|
684
|
+
const one = undeclared.length === 1
|
|
685
|
+
const paths = undeclared.map((u) => u.path)
|
|
686
|
+
const top = paths.every((p) => !/[.[]/.test(p))
|
|
687
|
+
parts.push(
|
|
688
|
+
`${listOf(paths.map((p) => `"${p}"`))} ${one ? 'is not a field' : 'are not fields'} of ${ref}, so a push cannot ` +
|
|
689
|
+
`carry ${one ? 'it' : 'them'}. ` +
|
|
690
|
+
undeclaredAdvice({ type: ref, owned, declared: top ? undeclared[0].declared : [], count: undeclared.length })
|
|
691
|
+
)
|
|
692
|
+
}
|
|
693
|
+
if (strandedBody) {
|
|
694
|
+
parts.push(
|
|
695
|
+
`its markdown body has no field in ${ref} to hold it (a \`markdown\` or \`richtext\` field), so a push cannot carry it.`
|
|
696
|
+
)
|
|
697
|
+
}
|
|
698
|
+
console.warn(`[records] ${where}: ${parts.join(' And ')}`)
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
651
702
|
/**
|
|
652
703
|
* The record WHOLE, as stored — what its own file serves and a whole question answers: its file's
|
|
653
704
|
* fields under their sections (`toStoredRecord`), its markdown body in the content body field's
|
|
@@ -862,7 +913,7 @@ async function processFileRecord(e, config, siteDir, recordsRoot, basePath) {
|
|
|
862
913
|
* its file carries. One that names no record of its schema is delivered as written, with
|
|
863
914
|
* a warning; `uniweb validate` reports it too.
|
|
864
915
|
*/
|
|
865
|
-
function referenceHydrator({ poolBySchema, dataSchemas, siteDir, recordsRoot, basePath, includeDrafts }) {
|
|
916
|
+
function referenceHydrator({ poolBySchema, dataSchemas, siteDir, recordsRoot, basePath, includeDrafts, unsendable = null }) {
|
|
866
917
|
const targets = new Map() // schema ref → Map(name or own id → the delivered reference)
|
|
867
918
|
const warned = new Set()
|
|
868
919
|
|
|
@@ -871,7 +922,7 @@ function referenceHydrator({ poolBySchema, dataSchemas, siteDir, recordsRoot, ba
|
|
|
871
922
|
const pooled = poolBySchema.get(ref) || []
|
|
872
923
|
const byName = new Map()
|
|
873
924
|
if (!schema || pooled.length === 0) return byName
|
|
874
|
-
const config = { schema: ref, dataSchema: schema, includeDrafts, excerpt: { maxLength: 160 }, references: null }
|
|
925
|
+
const config = { schema: ref, dataSchema: schema, includeDrafts, excerpt: { maxLength: 160 }, references: null, unsendable }
|
|
875
926
|
const keys = briefKeysOf(schema)
|
|
876
927
|
for (const result of await readPooledRecords(pooled, config, siteDir, recordsRoot, basePath)) {
|
|
877
928
|
for (const record of [result].flat()) {
|
|
@@ -1142,6 +1193,8 @@ function briefBuilder(schema) {
|
|
|
1142
1193
|
* draft is a record that is not delivered while the site is published.
|
|
1143
1194
|
* @param {Object} [options.dataSchemas] - normalized data schemas by ref, to deliver the
|
|
1144
1195
|
* records in; resolved from the site's foundation when absent (`resolveRecordSchemas`)
|
|
1196
|
+
* @param {boolean} [options.noteUnsendable=true] - end with a note for each record a push cannot
|
|
1197
|
+
* carry (`noteUnsendable`). Off for `uniweb validate`, which reports them itself
|
|
1145
1198
|
* @returns {Promise<Object>} Map of query name to items array
|
|
1146
1199
|
*
|
|
1147
1200
|
* @example
|
|
@@ -1150,11 +1203,15 @@ function briefBuilder(schema) {
|
|
|
1150
1203
|
* })
|
|
1151
1204
|
* // { articles: [...] }
|
|
1152
1205
|
*/
|
|
1153
|
-
export async function processQueries(siteDir,
|
|
1154
|
-
const { locale = null, includeDrafts = false } = options
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1206
|
+
export async function processQueries(siteDir, queriesConfigIn, recordsDir, basePath = '/', options = {}) {
|
|
1207
|
+
const { locale = null, includeDrafts = false, noteUnsendable: noting = true } = options
|
|
1208
|
+
// ⭐ A SITE WITH NO QUERIES STILL HAS ITS RECORDS CHECKED. Every file in the records directory is
|
|
1209
|
+
// a record a push sends, read by a query or not, so a folder whose data schema resolves to nothing
|
|
1210
|
+
// stops this as it stops the push (`refuseRecordsWithoutSchema`), and nothing is compiled. ⛔ Until
|
|
1211
|
+
// 2026-11-11 this returned at once with no queries, and so did `uniweb validate`, which compiles
|
|
1212
|
+
// through it: a site whose records no query read built, and conformed, and its push refused them.
|
|
1213
|
+
const queriesConfig = queriesConfigIn && typeof queriesConfigIn === 'object' ? queriesConfigIn : {}
|
|
1214
|
+
const hasQueries = Object.keys(queriesConfig).length > 0
|
|
1158
1215
|
|
|
1159
1216
|
// ⭐ ONE WALK FOR EVERY QUERY. Two queries over the same schema read one set of
|
|
1160
1217
|
// files; a query reads none of another schema's.
|
|
@@ -1162,6 +1219,7 @@ export async function processQueries(siteDir, queriesConfig, recordsDir, basePat
|
|
|
1162
1219
|
if (pool.errors.length) {
|
|
1163
1220
|
for (const e of pool.errors) console.warn(`[query-processor] ${e}`)
|
|
1164
1221
|
}
|
|
1222
|
+
if (!hasQueries && pool.entities.length === 0) return {}
|
|
1165
1223
|
|
|
1166
1224
|
// ⭐ EVERY FILE IN `records/` IS A RECORD (ruled 2026-09-21 [Diego]), so every one
|
|
1167
1225
|
// is compiled; `records/folder.yml` only says which folder each sits in (`$branch`),
|
|
@@ -1219,7 +1277,9 @@ export async function processQueries(siteDir, queriesConfig, recordsDir, basePat
|
|
|
1219
1277
|
refuseRecordsWithoutSchema(resolved.missing, { dir: pool.dir, poolBySchema, queriesConfig })
|
|
1220
1278
|
dataSchemas = resolved.schemas
|
|
1221
1279
|
}
|
|
1222
|
-
|
|
1280
|
+
// What a push cannot carry, by file, said once when every query has compiled (`noteUnsendable`).
|
|
1281
|
+
const unsendable = noting ? new Map() : null
|
|
1282
|
+
const references = referenceHydrator({ poolBySchema, dataSchemas, siteDir, recordsRoot, basePath, includeDrafts, unsendable })
|
|
1223
1283
|
|
|
1224
1284
|
const results = {}
|
|
1225
1285
|
|
|
@@ -1238,6 +1298,7 @@ export async function processQueries(siteDir, queriesConfig, recordsDir, basePat
|
|
|
1238
1298
|
parsed.includeDrafts = includeDrafts
|
|
1239
1299
|
parsed.dataSchema = (parsed.schema && dataSchemas[parsed.schema]) || null
|
|
1240
1300
|
parsed.references = references
|
|
1301
|
+
parsed.unsendable = unsendable
|
|
1241
1302
|
if (parsed.poolEntities.length === 0) {
|
|
1242
1303
|
const dirs = folderRef ? poolDirsForSchema(folderRef) : null
|
|
1243
1304
|
console.warn(
|
|
@@ -1251,6 +1312,7 @@ export async function processQueries(siteDir, queriesConfig, recordsDir, basePat
|
|
|
1251
1312
|
results[name] = items
|
|
1252
1313
|
console.log(`[query-processor] Processed ${name}: ${items.length} items`)
|
|
1253
1314
|
}
|
|
1315
|
+
if (unsendable) await warnUnsendable(unsendable, siteDir)
|
|
1254
1316
|
|
|
1255
1317
|
return results
|
|
1256
1318
|
}
|
|
@@ -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)) {
|