uniweb 0.33.0 → 0.34.0
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 +8 -8
- package/partials/agents.md +73 -38
- package/src/backend/site-sync.js +144 -22
- package/src/commands/build.js +17 -17
- package/src/commands/clone.js +7 -7
- package/src/commands/content.js +2 -3
- package/src/commands/doctor.js +34 -10
- package/src/commands/i18n.js +53 -39
- package/src/commands/publish.js +28 -6
- package/src/commands/pull.js +57 -22
- package/src/commands/push.js +25 -11
- package/src/commands/validate.js +1 -1
- package/src/framework-index.json +8 -8
- package/src/utils/flag-guard.js +2 -2
- package/src/utils/git.js +8 -2
- package/src/utils/records-guard.js +80 -0
- package/src/utils/schemaless-report.js +4 -4
- package/src/utils/site-data-upload.js +2 -2
- package/templates/site/site.yml.hbs +24 -6
package/src/commands/content.js
CHANGED
|
@@ -162,8 +162,7 @@ async function contentExport(args) {
|
|
|
162
162
|
if (entity.layout_sections?.length)
|
|
163
163
|
counts.layout_sections = entity.layout_sections.length
|
|
164
164
|
if (entity.extensions?.length) counts.extensions = entity.extensions.length
|
|
165
|
-
if (entity.
|
|
166
|
-
counts.collections = entity.collections.length
|
|
165
|
+
if (entity.queries?.length) counts.queries = entity.queries.length
|
|
167
166
|
}
|
|
168
167
|
|
|
169
168
|
console.log('')
|
|
@@ -198,6 +197,6 @@ async function contentExport(args) {
|
|
|
198
197
|
)
|
|
199
198
|
}
|
|
200
199
|
console.log('')
|
|
201
|
-
say.warn('v0 scope: media bytes,
|
|
200
|
+
say.warn('v0 scope: media bytes, records, and @-nested section')
|
|
202
201
|
say.dim('hierarchy are not yet carried (documented).')
|
|
203
202
|
}
|
package/src/commands/doctor.js
CHANGED
|
@@ -153,8 +153,8 @@ function loadSiteYml(dir) {
|
|
|
153
153
|
/**
|
|
154
154
|
* Diagnose the compiled-collection output directory.
|
|
155
155
|
*
|
|
156
|
-
* `public/<DATA_DIR>/` holds what the build compiles from `
|
|
157
|
-
* nothing else — `
|
|
156
|
+
* `public/<DATA_DIR>/` holds what the build compiles from `entities/`, and
|
|
157
|
+
* nothing else — `entities/` + `records.yml` is the only supported way to provide
|
|
158
158
|
* structured data. Two consequences, both checked here:
|
|
159
159
|
*
|
|
160
160
|
* 1. **The mapping is a bijection.** Every entry should be backed by a
|
|
@@ -548,9 +548,33 @@ export async function checkFormSubmitTarget({ sitePath, siteName, siteYml, issue
|
|
|
548
548
|
)
|
|
549
549
|
}
|
|
550
550
|
|
|
551
|
+
/** The bare map in `queries.yml`, or `{}` when there is none. */
|
|
552
|
+
function readQueriesYml(sitePath) {
|
|
553
|
+
try {
|
|
554
|
+
const doc = yaml.load(readFileSync(join(sitePath, 'queries.yml'), 'utf8'))
|
|
555
|
+
return doc && typeof doc === 'object' && !Array.isArray(doc) ? doc : {}
|
|
556
|
+
} catch {
|
|
557
|
+
return {}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
551
561
|
function checkGeneratedDataDir({ sitePath, siteName, siteYml, issues, shouldFix, fixed }) {
|
|
552
562
|
const dataDir = join(sitePath, 'public', DATA_DIR)
|
|
553
|
-
|
|
563
|
+
// ⚠️ THE QUERIES, not the pool. `public/<DATA_DIR>/x.json` is a query's
|
|
564
|
+
// MATERIALIZATION — one file per named query — so the bijection is with the
|
|
565
|
+
// declared queries, never with the schema folders under `entities/`.
|
|
566
|
+
//
|
|
567
|
+
// ⛔ BOTH HOMES, or this reports every compiled file as an orphan. A site that
|
|
568
|
+
// keeps its queries in `queries.yml` has none in `site.yml`, and reading one
|
|
569
|
+
// file would turn the whole check into a false positive — the loudest possible
|
|
570
|
+
// failure for a check whose job is to find stale output.
|
|
571
|
+
//
|
|
572
|
+
// Read directly rather than through `resolveQueriesConfig`: this pass is
|
|
573
|
+
// synchronous, and it needs the NAMES rather than resolved declarations.
|
|
574
|
+
const declared = new Set([
|
|
575
|
+
...Object.keys(siteYml.queries || {}),
|
|
576
|
+
...Object.keys(readQueriesYml(sitePath))
|
|
577
|
+
])
|
|
554
578
|
|
|
555
579
|
if (existsSync(dataDir)) {
|
|
556
580
|
// A collection `x` owns `x.json` (the cascade) and `x/` (per-record files
|
|
@@ -565,16 +589,16 @@ function checkGeneratedDataDir({ sitePath, siteName, siteYml, issues, shouldFix,
|
|
|
565
589
|
.map((entry) => (entry.isDirectory() ? `${entry.name}/` : entry.name))
|
|
566
590
|
|
|
567
591
|
if (orphans.length > 0) {
|
|
568
|
-
const id = 'orphaned-
|
|
592
|
+
const id = 'orphaned-query-output'
|
|
569
593
|
issues.push({
|
|
570
594
|
id,
|
|
571
595
|
type: 'warning',
|
|
572
596
|
site: siteName,
|
|
573
|
-
message: `${orphans.length} entr${orphans.length === 1 ? 'y' : 'ies'} in public/${DATA_DIR}/ with no declared
|
|
597
|
+
message: `${orphans.length} entr${orphans.length === 1 ? 'y' : 'ies'} in public/${DATA_DIR}/ with no declared query`
|
|
574
598
|
})
|
|
575
599
|
warn(`[${id}] Stale output in public/${DATA_DIR}/: ${orphans.join(', ')}`)
|
|
576
600
|
log(
|
|
577
|
-
` No
|
|
601
|
+
` No query produces ${orphans.length === 1 ? 'it' : 'these'}. ` +
|
|
578
602
|
`${orphans.length === 1 ? 'It is' : 'They are'} still served and deployed.`
|
|
579
603
|
)
|
|
580
604
|
if (shouldFix(id)) {
|
|
@@ -614,7 +638,7 @@ function checkGeneratedDataDir({ sitePath, siteName, siteYml, issues, shouldFix,
|
|
|
614
638
|
const body = existing === null ? '' : existing.replace(/\n*$/, '\n')
|
|
615
639
|
writeFileSync(
|
|
616
640
|
gitignorePath,
|
|
617
|
-
`${body}\n# Compiled
|
|
641
|
+
`${body}\n# Compiled query results — generated from entities/ + queries.yml\n${rule}\n`
|
|
618
642
|
)
|
|
619
643
|
fixed(`added ${rule} to ${gitignorePath}`)
|
|
620
644
|
if (existsSync(dataDir)) {
|
|
@@ -891,9 +915,9 @@ export async function doctor(args = []) {
|
|
|
891
915
|
}
|
|
892
916
|
|
|
893
917
|
// `public/<DATA_DIR>/` is the build's output directory and nothing else —
|
|
894
|
-
// `
|
|
895
|
-
// makes the mapping a bijection: every entry there should be backed
|
|
896
|
-
// declared
|
|
918
|
+
// `entities/` + `records.yml` is the only supported way to provide structured
|
|
919
|
+
// data. That makes the mapping a bijection: every entry there should be backed
|
|
920
|
+
// by a declared QUERY, so anything else is stale, and identifiable.
|
|
897
921
|
//
|
|
898
922
|
// It matters because the directory is written into the source tree rather
|
|
899
923
|
// than dist/, so what lands there persists and gets deployed. A collection
|
package/src/commands/i18n.js
CHANGED
|
@@ -242,13 +242,13 @@ async function loadSiteConfig(siteRoot) {
|
|
|
242
242
|
async function runExtract(siteRoot, config, args) {
|
|
243
243
|
const verbose = args.includes('--verbose') || args.includes('-v')
|
|
244
244
|
const dryRun = args.includes('--dry-run')
|
|
245
|
-
const
|
|
246
|
-
args.includes('--
|
|
247
|
-
const
|
|
245
|
+
const recordsOnly =
|
|
246
|
+
args.includes('--records-only') || args.includes('--records')
|
|
247
|
+
const noRecords = args.includes('--no-records')
|
|
248
248
|
// --with-collections is now a no-op (collections are included by default)
|
|
249
249
|
|
|
250
|
-
// Extract page content (unless --
|
|
251
|
-
if (!
|
|
250
|
+
// Extract page content (unless --records-only)
|
|
251
|
+
if (!recordsOnly) {
|
|
252
252
|
log(
|
|
253
253
|
`\n${colors.cyan}Extracting translatable content${dryRun ? ' (dry run)' : ''}...${colors.reset}\n`
|
|
254
254
|
)
|
|
@@ -309,43 +309,43 @@ async function runExtract(siteRoot, config, args) {
|
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
// Extract collection content (by default, skip with --no-
|
|
313
|
-
if (!
|
|
312
|
+
// Extract collection content (by default, skip with --no-records)
|
|
313
|
+
if (!noRecords) {
|
|
314
314
|
log(
|
|
315
|
-
`\n${colors.cyan}Extracting
|
|
315
|
+
`\n${colors.cyan}Extracting record content${dryRun ? ' (dry run)' : ''}...${colors.reset}\n`
|
|
316
316
|
)
|
|
317
317
|
|
|
318
318
|
// Check if collections exist
|
|
319
319
|
const dataDir = join(siteRoot, 'public', DATA_DIR)
|
|
320
320
|
if (!existsSync(dataDir)) {
|
|
321
|
-
if (
|
|
322
|
-
error('No
|
|
321
|
+
if (recordsOnly) {
|
|
322
|
+
error('No records found. Add entities under entities/ and list them in records.yml.')
|
|
323
323
|
process.exit(1)
|
|
324
324
|
}
|
|
325
|
-
log(`${colors.dim}No
|
|
325
|
+
log(`${colors.dim}No records found in public/data/.${colors.reset}`)
|
|
326
326
|
return
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
try {
|
|
330
|
-
const {
|
|
330
|
+
const { extractRecordManifest, formatSyncReport } =
|
|
331
331
|
await import('@uniweb/build/i18n')
|
|
332
332
|
|
|
333
|
-
const
|
|
333
|
+
const recordManifestPath = join(
|
|
334
334
|
siteRoot,
|
|
335
335
|
config.localesDir,
|
|
336
|
-
'
|
|
336
|
+
'records',
|
|
337
337
|
'manifest.json'
|
|
338
338
|
)
|
|
339
|
-
const isUpdate = existsSync(
|
|
339
|
+
const isUpdate = existsSync(recordManifestPath)
|
|
340
340
|
|
|
341
|
-
const { manifest, report } = await
|
|
341
|
+
const { manifest, report } = await extractRecordManifest(siteRoot, {
|
|
342
342
|
localesDir: config.localesDir,
|
|
343
343
|
dryRun
|
|
344
344
|
})
|
|
345
345
|
|
|
346
346
|
const unitCount = Object.keys(manifest.units).length
|
|
347
347
|
if (unitCount > 0) {
|
|
348
|
-
success(`Extracted ${unitCount} translatable strings from
|
|
348
|
+
success(`Extracted ${unitCount} translatable strings from records`)
|
|
349
349
|
|
|
350
350
|
if (report && isUpdate) {
|
|
351
351
|
log('')
|
|
@@ -356,18 +356,18 @@ async function runExtract(siteRoot, config, args) {
|
|
|
356
356
|
log(`\n${colors.dim}Dry run — no files were modified.${colors.reset}`)
|
|
357
357
|
} else {
|
|
358
358
|
log(
|
|
359
|
-
`\nManifest written to: ${colors.dim}${config.localesDir}/
|
|
359
|
+
`\nManifest written to: ${colors.dim}${config.localesDir}/records/manifest.json${colors.reset}`
|
|
360
360
|
)
|
|
361
361
|
}
|
|
362
362
|
} else {
|
|
363
363
|
log(
|
|
364
|
-
`${colors.dim}No translatable content found in
|
|
364
|
+
`${colors.dim}No translatable content found in records.${colors.reset}`
|
|
365
365
|
)
|
|
366
366
|
}
|
|
367
367
|
} catch (err) {
|
|
368
|
-
error(`
|
|
368
|
+
error(`Record extraction failed: ${err.message}`)
|
|
369
369
|
if (verbose) console.error(err)
|
|
370
|
-
if (
|
|
370
|
+
if (recordsOnly) process.exit(1)
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
}
|
|
@@ -652,7 +652,7 @@ async function runStatusFreeform(siteRoot, config, locale, options = {}) {
|
|
|
652
652
|
const allPaths = [
|
|
653
653
|
...discovered.pages,
|
|
654
654
|
...discovered.pageIds,
|
|
655
|
-
...discovered.
|
|
655
|
+
...discovered.records
|
|
656
656
|
]
|
|
657
657
|
|
|
658
658
|
// Check staleness
|
|
@@ -988,11 +988,11 @@ async function runAudit(siteRoot, config, args) {
|
|
|
988
988
|
* Usage:
|
|
989
989
|
* uniweb i18n init-freeform es pages/about hero
|
|
990
990
|
* uniweb i18n init-freeform es page-ids/installation intro
|
|
991
|
-
* uniweb i18n init-freeform es
|
|
991
|
+
* uniweb i18n init-freeform es entities/article getting-started
|
|
992
992
|
*/
|
|
993
993
|
async function runInitFreeform(siteRoot, config, args) {
|
|
994
994
|
const locale = args[0]
|
|
995
|
-
const pathType = args[1] // pages/about, page-ids/installation,
|
|
995
|
+
const pathType = args[1] // pages/about, page-ids/installation, entities/article
|
|
996
996
|
const sectionId = args[2] // hero, intro, getting-started
|
|
997
997
|
|
|
998
998
|
if (!locale || !pathType || !sectionId) {
|
|
@@ -1001,7 +1001,7 @@ async function runInitFreeform(siteRoot, config, args) {
|
|
|
1001
1001
|
log(' uniweb i18n init-freeform es pages/about hero')
|
|
1002
1002
|
log(' uniweb i18n init-freeform es page-ids/installation intro')
|
|
1003
1003
|
log(
|
|
1004
|
-
` uniweb i18n init-freeform es
|
|
1004
|
+
` uniweb i18n init-freeform es entities/article getting-started${colors.reset}`
|
|
1005
1005
|
)
|
|
1006
1006
|
process.exit(1)
|
|
1007
1007
|
}
|
|
@@ -1057,15 +1057,29 @@ async function runInitFreeform(siteRoot, config, args) {
|
|
|
1057
1057
|
if (sourceContent) break
|
|
1058
1058
|
}
|
|
1059
1059
|
}
|
|
1060
|
-
} else if (pathType.startsWith('
|
|
1061
|
-
//
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
)
|
|
1060
|
+
} else if (pathType.startsWith('entities/')) {
|
|
1061
|
+
// ⛔ ADDRESSED BY THE RECORD, matching where the loader reads. The freeform
|
|
1062
|
+
// tree is `entities/<schema dirs>/<slug>.md`; this used to take
|
|
1063
|
+
// `collections/<query>` and write a path nothing read — the loader moved
|
|
1064
|
+
// and this did not.
|
|
1065
|
+
//
|
|
1066
|
+
// The record's CONTENT still lives in a query's materialization, so the
|
|
1067
|
+
// query that covers this schema is resolved rather than named.
|
|
1068
|
+
const poolDirs = pathType.replace('entities/', '')
|
|
1069
|
+
const { resolveQueriesConfig, poolDirsForSchema } = await import('@uniweb/build/uwx')
|
|
1070
|
+
let queryName = null
|
|
1071
|
+
try {
|
|
1072
|
+
const { declarations } = await resolveQueriesConfig(siteRoot)
|
|
1073
|
+
for (const [name, decl] of Object.entries(declarations || {})) {
|
|
1074
|
+
const dirs = decl.schema ? poolDirsForSchema(decl.schema) : null
|
|
1075
|
+
if (dirs && dirs.join('/') === poolDirs) { queryName = name; break }
|
|
1076
|
+
}
|
|
1077
|
+
} catch {
|
|
1078
|
+
/* no resolvable config — fall through to the not-found message below */
|
|
1079
|
+
}
|
|
1080
|
+
const dataPath = queryName
|
|
1081
|
+
? join(siteRoot, 'public', 'data', `${queryName}.json`)
|
|
1082
|
+
: join(siteRoot, 'public', 'data', '__none__.json')
|
|
1069
1083
|
|
|
1070
1084
|
if (existsSync(dataPath)) {
|
|
1071
1085
|
const dataRaw = await readFile(dataPath, 'utf-8')
|
|
@@ -1607,8 +1621,8 @@ ${colors.bright}Options:${colors.reset}
|
|
|
1607
1621
|
--freeform (status/prune) Include free-form translation status
|
|
1608
1622
|
--json (status) Output as JSON for translation tools
|
|
1609
1623
|
--by-page (status --missing) Group missing strings by page
|
|
1610
|
-
--
|
|
1611
|
-
--no-
|
|
1624
|
+
--records-only (extract/status/audit) Process only records
|
|
1625
|
+
--no-records (extract/status/audit) Skip records (pages only)
|
|
1612
1626
|
--all-stale (update-hash) Update all stale translations at once
|
|
1613
1627
|
|
|
1614
1628
|
${colors.bright}Configuration:${colors.reset}
|
|
@@ -1638,14 +1652,14 @@ ${colors.bright}File Structure:${colors.reset}
|
|
|
1638
1652
|
.manifest.json Staleness tracking
|
|
1639
1653
|
pages/about/hero.md Translated content for /about page, hero section
|
|
1640
1654
|
page-ids/install/intro.md Translated content by page ID
|
|
1641
|
-
|
|
1655
|
+
entities/article/getting-started.md
|
|
1642
1656
|
|
|
1643
1657
|
${colors.bright}Examples:${colors.reset}
|
|
1644
1658
|
${colors.dim}# Hash-based workflow${colors.reset}
|
|
1645
1659
|
uniweb i18n extract # Extract all translatable strings
|
|
1646
1660
|
uniweb i18n extract --dry-run # Preview without writing
|
|
1647
1661
|
uniweb i18n extract --verbose # Show extracted strings
|
|
1648
|
-
uniweb i18n extract --no-
|
|
1662
|
+
uniweb i18n extract --no-records # Pages only (skip records)
|
|
1649
1663
|
uniweb i18n generate es fr # Create starter files for Spanish and French
|
|
1650
1664
|
uniweb i18n generate --empty # Create files with empty values (for translators)
|
|
1651
1665
|
uniweb i18n generate --force # Overwrite existing locale files
|
|
@@ -1658,7 +1672,7 @@ ${colors.bright}Examples:${colors.reset}
|
|
|
1658
1672
|
${colors.dim}# Free-form workflow (complete section replacement)${colors.reset}
|
|
1659
1673
|
uniweb i18n init-freeform es pages/about hero
|
|
1660
1674
|
uniweb i18n init-freeform es page-ids/installation intro
|
|
1661
|
-
uniweb i18n init-freeform es
|
|
1675
|
+
uniweb i18n init-freeform es entities/article getting-started
|
|
1662
1676
|
uniweb i18n status --freeform # Show free-form translation status
|
|
1663
1677
|
uniweb i18n update-hash es --all-stale # Update hashes after review
|
|
1664
1678
|
uniweb i18n move pages/docs/setup pages/getting-started
|
package/src/commands/publish.js
CHANGED
|
@@ -70,6 +70,7 @@ import {
|
|
|
70
70
|
readSiteIdentity
|
|
71
71
|
} from '../utils/site-identity.js'
|
|
72
72
|
import { isNonInteractive, confirm } from '../utils/interactive.js'
|
|
73
|
+
import { guardEmptyRecords } from '../utils/records-guard.js'
|
|
73
74
|
import { headProvenance } from '../utils/git.js'
|
|
74
75
|
import {
|
|
75
76
|
makeModelResolver,
|
|
@@ -93,7 +94,7 @@ import {
|
|
|
93
94
|
readPaymentRefusal,
|
|
94
95
|
reportPaymentRefusal
|
|
95
96
|
} from '../backend/payment-handoff.js'
|
|
96
|
-
import {
|
|
97
|
+
import { reportSchemalessQueries } from '../utils/schemaless-report.js'
|
|
97
98
|
import { uploadSiteData } from '../utils/site-data-upload.js'
|
|
98
99
|
|
|
99
100
|
const c = {
|
|
@@ -113,7 +114,20 @@ const say = {
|
|
|
113
114
|
dim: (m) => console.log(` ${c.dim}${m}${c.reset}`)
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
// Origin-relative serve path → clickable absolute URL
|
|
117
|
+
// Origin-relative serve path → clickable absolute URL.
|
|
118
|
+
//
|
|
119
|
+
// ⭐ THE TWO SHAPES ARE A CONTRACT, NOT AN INCONSISTENCY — ratified 2026-08-29 and
|
|
120
|
+
// documented in the backend's `wire-layer.md` rather than merely observed. A publish
|
|
121
|
+
// returns an ABSOLUTE url when Cloudflare hosts the site (another origin entirely)
|
|
122
|
+
// and an ORIGIN-RELATIVE path when the backend serves it itself, where its own
|
|
123
|
+
// external origin is not reliably self-reportable from behind an ALB.
|
|
124
|
+
//
|
|
125
|
+
// ⇒ So this branch is implementing the contract, not defending against drift. I
|
|
126
|
+
// reported the two shapes as a violation of "finished values only" in collab
|
|
127
|
+
// framework-backend-812b; the backend checked, found the adjacent ruling that
|
|
128
|
+
// explains the relative arm, and ratified both. Do not "fix" it by demanding one
|
|
129
|
+
// shape — the caller's own origin is the missing half on the relative arm, and we
|
|
130
|
+
// are the caller.
|
|
117
131
|
function absolutizeServeUrl(origin, url) {
|
|
118
132
|
if (!url || typeof url !== 'string') return null
|
|
119
133
|
if (/^https?:\/\//.test(url)) return url
|
|
@@ -436,6 +450,14 @@ export async function publish(args = []) {
|
|
|
436
450
|
// Non-local @std/registry Model schemas resolve through the backend (same as push).
|
|
437
451
|
const resolveModel = makeModelResolver({ client, offline: false })
|
|
438
452
|
|
|
453
|
+
// ⛔ AN EMPTY `records.yml` REMOVES. It is the one path where an ordinary act is
|
|
454
|
+
// destructive — a placeholder file, created meaning to fill it in — so the count
|
|
455
|
+
// is reported and confirmed before anything is sent.
|
|
456
|
+
{
|
|
457
|
+
const guard = await guardEmptyRecords({ siteDir, args, warn: say.warn, note: say.dim })
|
|
458
|
+
if (!guard.ok) return { exitCode: 1 }
|
|
459
|
+
}
|
|
460
|
+
|
|
439
461
|
// 3. Partition collections by schema presence (a first emit reads `schemaless`
|
|
440
462
|
// — collections with no data schema, delivered statically via the ball).
|
|
441
463
|
let probe
|
|
@@ -456,7 +478,7 @@ export async function publish(args = []) {
|
|
|
456
478
|
// A product decision the author is usually making unknowingly — say it at warn
|
|
457
479
|
// level, not dim among everything else. See the helper for what the old
|
|
458
480
|
// message got wrong.
|
|
459
|
-
|
|
481
|
+
reportSchemalessQueries(probe.schemaless, say)
|
|
460
482
|
const localAssets = probe.localAssets || []
|
|
461
483
|
|
|
462
484
|
// 3a. A clone with no `$uuid` is bound to no backend site, so every cached map
|
|
@@ -579,7 +601,7 @@ export async function publish(args = []) {
|
|
|
579
601
|
// `client.discover()` is the mechanism if that changes — `DISCOVERY_DEFAULTS`
|
|
580
602
|
// makes an absent key non-breaking by construction.
|
|
581
603
|
if (ball) {
|
|
582
|
-
say.info('Uploading
|
|
604
|
+
say.info('Uploading schema-less record data…')
|
|
583
605
|
try {
|
|
584
606
|
const r = await uploadSiteData({
|
|
585
607
|
apiBase: client.origin,
|
|
@@ -595,9 +617,9 @@ export async function publish(args = []) {
|
|
|
595
617
|
for (const f of r.failed) say.dim(` ${f.path} (HTTP ${f.status})`)
|
|
596
618
|
return { exitCode: 1 }
|
|
597
619
|
}
|
|
598
|
-
say.dim(`
|
|
620
|
+
say.dim(`Record data : ${r.uploaded.length} file(s) [${r.mode}]`)
|
|
599
621
|
} catch (err) {
|
|
600
|
-
say.err(`
|
|
622
|
+
say.err(`Record data upload failed: ${err.message}`)
|
|
601
623
|
return { exitCode: 1 }
|
|
602
624
|
}
|
|
603
625
|
}
|
package/src/commands/pull.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* - content lane → `siteContentDocumentToProject` (site.yml/theme.yml/head.html,
|
|
12
12
|
* pages/**, layout/**), and
|
|
13
|
-
* - folder lane → `
|
|
13
|
+
* - folder lane → `recordsToProject` (the folder + record files).
|
|
14
14
|
*
|
|
15
15
|
* Pull is a CHECKOUT, not a merge — the "git-pull-like" it used to claim here was
|
|
16
16
|
* misleading. It reconciles the working tree to the backend: section bodies are
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
*
|
|
37
37
|
* Usage:
|
|
38
38
|
* uniweb pull GET both lanes, project to files, prune orphans
|
|
39
|
-
* uniweb pull --no-
|
|
39
|
+
* uniweb pull --no-records Pull pages only; skip the folder (records) lane
|
|
40
40
|
* uniweb pull --no-delete Project, but keep files with no backend item
|
|
41
41
|
* uniweb pull --merge Three-way merge local changes with the backend's
|
|
42
42
|
* uniweb pull --force Pull over uncommitted local changes (discards them)
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
* A project that never pushed has no `$uuid` to pull by — pull is a no-op with a
|
|
53
53
|
* clear message. The backend serves each lane as a `.uwx` (ZIP: `manifest.json` +
|
|
54
54
|
* `entities/<uuid>.json`); `readPullDocuments` reads the entity files out of it, with
|
|
55
|
-
* a tolerant JSON fallback (`extractDocument` / `
|
|
55
|
+
* a tolerant JSON fallback (`extractDocument` / `splitRecordsPull`). Verified live
|
|
56
56
|
* against the playground backend, 2026-06-17.
|
|
57
57
|
*/
|
|
58
58
|
|
|
@@ -71,11 +71,11 @@ import yaml from 'js-yaml'
|
|
|
71
71
|
import { downloadMissingAssets } from '../backend/asset-download.js'
|
|
72
72
|
import {
|
|
73
73
|
siteContentDocumentToProject,
|
|
74
|
-
|
|
75
|
-
resolveCollectionsConfig,
|
|
74
|
+
recordsToProject,
|
|
76
75
|
readZip,
|
|
77
76
|
computeUnitHashes,
|
|
78
|
-
collectUnitUuids
|
|
77
|
+
collectUnitUuids,
|
|
78
|
+
collectQueryUuids
|
|
79
79
|
} from '@uniweb/build/uwx'
|
|
80
80
|
import {
|
|
81
81
|
readWritten,
|
|
@@ -84,6 +84,8 @@ import {
|
|
|
84
84
|
} from '../utils/pull-written.js'
|
|
85
85
|
import {
|
|
86
86
|
makeModelResolver,
|
|
87
|
+
rebankSyncHashes,
|
|
88
|
+
writeQueryUuids,
|
|
87
89
|
mergeBaseVersions,
|
|
88
90
|
mergeItemBaseVersions,
|
|
89
91
|
writeUnitBases,
|
|
@@ -200,7 +202,7 @@ export function extractDocument(payload) {
|
|
|
200
202
|
// Split a collections pull (the folder + the entities it references) into the
|
|
201
203
|
// folder document and the record documents. Tolerant of an array, an
|
|
202
204
|
// `{ entities }` / `{ documents }` list, or an explicit `{ folder, records }`.
|
|
203
|
-
export function
|
|
205
|
+
export function splitRecordsPull(payload) {
|
|
204
206
|
if (payload?.folder)
|
|
205
207
|
return { folderDoc: payload.folder, recordDocs: payload.records || [] }
|
|
206
208
|
const list = Array.isArray(payload)
|
|
@@ -237,7 +239,7 @@ export function readPullDocuments(buf) {
|
|
|
237
239
|
}
|
|
238
240
|
return docs
|
|
239
241
|
}
|
|
240
|
-
// JSON fallback — flatten any envelope
|
|
242
|
+
// JSON fallback — flatten any envelope splitRecordsPull understands into a
|
|
241
243
|
// flat `$`-document list (a raw doc, a list, `{entities}`/`{documents}`, or
|
|
242
244
|
// `{folder, records}`).
|
|
243
245
|
let payload
|
|
@@ -516,8 +518,8 @@ export async function pull(args = [], deps = {}) {
|
|
|
516
518
|
const dryRun = args.includes('--dry-run')
|
|
517
519
|
const tokenFlag = flagValue(args, '--token')
|
|
518
520
|
const prune = !(args.includes('--no-delete') || args.includes('--no-prune')) // git-like by default
|
|
519
|
-
const
|
|
520
|
-
args.includes('--no-
|
|
521
|
+
const noRecords =
|
|
522
|
+
args.includes('--no-records') || args.includes('--content-only')
|
|
521
523
|
const force = args.includes('--force')
|
|
522
524
|
const mergeMode = args.includes('--merge')
|
|
523
525
|
|
|
@@ -595,7 +597,7 @@ export async function pull(args = [], deps = {}) {
|
|
|
595
597
|
info(
|
|
596
598
|
`Dry run — would pull content from ${colors.dim}${client.origin}${colors.reset}`
|
|
597
599
|
)
|
|
598
|
-
if (!
|
|
600
|
+
if (!noRecords) info(`Dry run — would also pull records`)
|
|
599
601
|
return { exitCode: 0 }
|
|
600
602
|
}
|
|
601
603
|
|
|
@@ -686,6 +688,10 @@ export async function pull(args = [], deps = {}) {
|
|
|
686
688
|
// Per-item identity for the next push. Without it the backend reads our
|
|
687
689
|
// records as new and re-mints every page and section row.
|
|
688
690
|
writeItemUuids(siteDir, collectUnitUuids(siteDoc))
|
|
691
|
+
// The collections section's identity has no file to live in either — same
|
|
692
|
+
// reason, same remedy, keyed by name. A pull is the other route by which a
|
|
693
|
+
// copy can recover it (see readQueryUuids).
|
|
694
|
+
writeQueryUuids(siteDir, collectQueryUuids(siteDoc))
|
|
689
695
|
// Bring the media down BEFORE projecting: a newly-landed asset gains a map
|
|
690
696
|
// entry, and the projection reads that map to put authored paths back. Run
|
|
691
697
|
// after, and this pull's new assets would project as URLs and only restore
|
|
@@ -770,13 +776,13 @@ export async function pull(args = [], deps = {}) {
|
|
|
770
776
|
// Lane 2 — folder → the folder + record files, keyed by the SAME site-content uuid
|
|
771
777
|
// (the backend resolves the site's `@uniweb/folder` from it; the framework never
|
|
772
778
|
// holds a folder uuid). Models are resolved by name (async) up front, so
|
|
773
|
-
//
|
|
774
|
-
if (!
|
|
775
|
-
const folder = await getDocs('
|
|
779
|
+
// recordsToProject keeps its synchronous contract. A 304 leaves files as-is.
|
|
780
|
+
if (!noRecords) {
|
|
781
|
+
const folder = await getDocs('records', () =>
|
|
776
782
|
client.pullFolder(siteContentUuid, { etag: etagFolder })
|
|
777
783
|
)
|
|
778
784
|
if (folder && !folder.notModified && folder.docs?.length) {
|
|
779
|
-
const { folderDoc, recordDocs } =
|
|
785
|
+
const { folderDoc, recordDocs } = splitRecordsPull(folder.docs)
|
|
780
786
|
const resolveModel = makeModelResolver({ client })
|
|
781
787
|
const declByModel = new Map()
|
|
782
788
|
for (const model of [
|
|
@@ -788,18 +794,20 @@ export async function pull(args = [], deps = {}) {
|
|
|
788
794
|
note(`! could not resolve model ${model}: ${err.message}`)
|
|
789
795
|
}
|
|
790
796
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
797
|
+
// ⛔ NO QUERY CONFIG. A record's home is decided by what it IS — its
|
|
798
|
+
// `$model` names the pool folder — not by any query that happens to select
|
|
799
|
+
// it. `recordsToProject` reads `site.yml::$org` itself, so a `@/x`
|
|
800
|
+
// model the producer resolved to `@org/x` is placed back where the author
|
|
801
|
+
// wrote it.
|
|
802
|
+
const report = recordsToProject({
|
|
795
803
|
folderDoc,
|
|
796
804
|
recordDocs,
|
|
797
805
|
siteRoot: siteDir,
|
|
798
806
|
opts: {
|
|
799
|
-
resolveDeclaration: (name) => declByModel.get(name) || null
|
|
800
|
-
collectionsConfig
|
|
807
|
+
resolveDeclaration: (name) => declByModel.get(name) || null
|
|
801
808
|
}
|
|
802
809
|
})
|
|
810
|
+
if (report.records === 'updated') info('Wrote records.yml')
|
|
803
811
|
records += report.placed.length + report.updated.length
|
|
804
812
|
for (const s of report.skipped)
|
|
805
813
|
note(`↷ ${s.slug ?? s.uuid ?? '(record)'}: ${s.reason}`)
|
|
@@ -833,13 +841,40 @@ export async function pull(args = [], deps = {}) {
|
|
|
833
841
|
siteDir,
|
|
834
842
|
[
|
|
835
843
|
...wrote,
|
|
836
|
-
...['site.yml', 'theme.yml', 'head.html', '
|
|
844
|
+
...['site.yml', 'theme.yml', 'head.html', 'queries.yml', 'records.yml'].map((f) =>
|
|
837
845
|
join(siteDir, f)
|
|
838
846
|
)
|
|
839
847
|
],
|
|
840
848
|
removed
|
|
841
849
|
)
|
|
842
850
|
|
|
851
|
+
// ⛔ RE-BANK THE SEND-ONLY-CHANGED HASHES OVER WHAT WE JUST WROTE.
|
|
852
|
+
//
|
|
853
|
+
// The projection above is canonical, not byte-identical to what was on disk: it
|
|
854
|
+
// moves section ordering out of filename prefixes (`1-hero.md` → `hero.md` plus an
|
|
855
|
+
// explicit `sections:` list) and stamps each section's `id`. Lossless, and a
|
|
856
|
+
// different document — which is exactly why the `local` unit base is cleared above.
|
|
857
|
+
//
|
|
858
|
+
// ⚠️ That same reasoning was never carried to the hashes, so they were left STALE
|
|
859
|
+
// rather than unknown, and `uniweb status` reported unpushed content immediately
|
|
860
|
+
// after a pull, permanently. Measured on matinee 2026-08-29: push → pull reported
|
|
861
|
+
// 1 changed of 8, with nothing edited in between.
|
|
862
|
+
//
|
|
863
|
+
// Re-banking rather than clearing, because after a pull the on-disk state IS the
|
|
864
|
+
// agreed state — it came from the backend, so a push with no edits should send
|
|
865
|
+
// nothing. Clearing would make it send everything.
|
|
866
|
+
//
|
|
867
|
+
// Best-effort: a failure here costs an unnecessary re-send on the next push, never
|
|
868
|
+
// wrong content, and must not fail a pull whose files are already written.
|
|
869
|
+
if (!dryRun) {
|
|
870
|
+
try {
|
|
871
|
+
await rebankSyncHashes(siteDir)
|
|
872
|
+
} catch (err) {
|
|
873
|
+
note(`! could not re-bank the sync cache: ${err.message}`)
|
|
874
|
+
note(' The next push will re-send content that is already current.')
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
843
878
|
success(
|
|
844
879
|
`Pulled — ${pages} page(s), ${sections} section(s), ${records} record(s)` +
|
|
845
880
|
(deleted ? `, ${deleted} deleted` : '')
|