@uniweb/build 1.15.2 → 1.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/build",
3
- "version": "1.15.2",
3
+ "version": "1.15.4",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -56,15 +56,15 @@
56
56
  "js-yaml": "^4.3.2",
57
57
  "sharp": "^0.35.5",
58
58
  "yaml": "^2.5.0",
59
- "@uniweb/content-reader": "~1.5.8",
60
59
  "@uniweb/schemas": "~1.6.7",
60
+ "@uniweb/content-reader": "~1.5.8",
61
+ "@uniweb/theming": "~1.2.1",
61
62
  "@uniweb/content-writer": "~1.3.1",
62
63
  "@uniweb/semantic-parser": "~1.13.2",
63
- "@uniweb/theming": "~1.2.1",
64
64
  "@uniweb/projections": "~1.2.11"
65
65
  },
66
66
  "optionalDependencies": {
67
- "@uniweb/runtime": "~1.4.2"
67
+ "@uniweb/runtime": "~1.4.5"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
@@ -73,8 +73,8 @@
73
73
  "@tailwindcss/vite": "^4.0.0",
74
74
  "@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
75
75
  "vite-plugin-svgr": "^4.0.0",
76
- "@uniweb/core": "~1.6.3",
77
- "@uniweb/runtime": "~1.4.2"
76
+ "@uniweb/runtime": "~1.4.5",
77
+ "@uniweb/core": "~1.6.4"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "vite": {
package/src/prerender.js CHANGED
@@ -685,6 +685,17 @@ function dedupeByAddress(entries) {
685
685
  return out
686
686
  }
687
687
 
688
+ /** The icons a page's HTML already carries in `__ICON_CACHE__`, by key; none when it carries none. */
689
+ function embeddedIcons(html) {
690
+ const script = html.match(/<script[^>]*id="__ICON_CACHE__"[^>]*>([\s\S]*?)<\/script>/)
691
+ if (!script) return {}
692
+ try {
693
+ return JSON.parse(script[1])
694
+ } catch {
695
+ return {}
696
+ }
697
+ }
698
+
688
699
  /**
689
700
  * Inject build-specific data into HTML (theme CSS, __SITE_CONTENT__, icon cache).
690
701
  * Called after the shared injectPageContent for build-specific additions.
@@ -760,9 +771,16 @@ export function injectBuildData(html, siteContent, { splitContent = false, curre
760
771
  )
761
772
  }
762
773
 
763
- // Inject icon cache so client can render icons immediately without CDN fetches
774
+ // ⭐ THE PAGE'S ICONS, so the browser draws them without fetching: the site's content icons,
775
+ // which every page embeds so the next page a visit opens has them too, and whatever else this
776
+ // page drew, which its render wrote here (`injectPageContent`): a link's icon, a param's, a
777
+ // record's. Those follow in key order, so a build writes the same page every time. Replacing the
778
+ // render's copy instead would blank them in the browser's first render.
764
779
  if (siteContent._iconCache) {
765
- const iconScript = `<script id="__ICON_CACHE__" type="application/json">${jsonForScript(siteContent._iconCache)}</script>`
780
+ const icons = { ...siteContent._iconCache }
781
+ const drawn = embeddedIcons(result)
782
+ for (const key of Object.keys(drawn).sort()) if (!(key in icons)) icons[key] = drawn[key]
783
+ const iconScript = `<script id="__ICON_CACHE__" type="application/json">${jsonForScript(icons)}</script>`
766
784
  if (result.includes('__ICON_CACHE__')) {
767
785
  result = result.replace(
768
786
  /<script[^>]*id="__ICON_CACHE__"[^>]*>[\s\S]*?<\/script>/,
@@ -1110,8 +1128,12 @@ export async function prerenderSite(siteDir, options = {}) {
1110
1128
  fetch: fileTransport,
1111
1129
  prerender: 'author',
1112
1130
  cache: buildDataCache,
1113
- // This lane's icons are `prefetchIcons`'s, the whole site's, which every page embeds.
1114
- icons: false,
1131
+ // ⭐ The icons the site names for this page beyond the ones `prefetchIcons` already holds,
1132
+ // the image icons of the whole site's content: a link's icon, a param's, a tagged data
1133
+ // block's, a record's. One the graph holds is not asked again, so a build fetches each
1134
+ // icon once. ⛔ Until 2026-11-04 this said `false`, and every such icon was a blank box in
1135
+ // the built page until the browser fetched it.
1136
+ icons: true,
1115
1137
  })
1116
1138
  // Filed under this page, the way a route-bound view always has been: `scopeFetchedData`
1117
1139
  // embeds it in this page's HTML and nowhere else, and one address embedded twice collapses.
package/src/uwx/folder.js CHANGED
@@ -57,6 +57,12 @@ import { fileLeaf } from './file-records.js'
57
57
  export const FOLDER_MODEL_NAME = '@uniweb/folder'
58
58
  export const FOLDER_ENTITY_KEY = '@folder'
59
59
 
60
+ // ⭐ A MOVED RECORD'S ENTRY IS FOUND BY THE ENTITY IT HELD. A record moved to another data schema
61
+ // goes up as a new entity, so its leaf names it by `$ref` and carries no entity uuid to look the
62
+ // entry up by. The entity it held does: this key, on the leaf, carries it to the stamping below.
63
+ // A symbol, so it never reaches the wire (`JSON.stringify` skips it) or the folder's hash.
64
+ const MOVED_FROM = Symbol('movedFrom')
65
+
60
66
  // Point one authored leaf at the record entity it names. The folder's `contents`
61
67
  // field is polymorphic (it can reference any data schema), so the ref uses the
62
68
  // entity_ref OPEN form `{ schema, entity }` — not a bare uuid (a bare uuid is only
@@ -129,6 +135,7 @@ function contentsFromNodes(nodes, byEntityId, missing, sourceLocale, byLinkId =
129
135
  continue
130
136
  }
131
137
  const leaf = refLeaf(entity)
138
+ if (entity.movedFrom) leaf[MOVED_FROM] = entity.movedFrom
132
139
  // ⭐ What the folder says about the record (`records/folder.yml`, ruled 2026-09-27
133
140
  // [Diego]): its display text, localized as a branch's is, and its tags, in the order
134
141
  // written. A records service answers them beside the record as `$label` and `$tags`.
@@ -146,7 +153,8 @@ function recordOf(item) {
146
153
  if (item?.kind !== 'ref') return null
147
154
  const e = item.entry
148
155
  const uuid = e && typeof e === 'object' ? e.entity : e
149
- return typeof uuid === 'string' && uuid ? uuid : null
156
+ if (typeof uuid === 'string' && uuid) return uuid
157
+ return typeof item[MOVED_FROM] === 'string' ? item[MOVED_FROM] : null
150
158
  }
151
159
 
152
160
  /**
@@ -198,6 +206,25 @@ export function collectFolderItemUuids(doc) {
198
206
  return out
199
207
  }
200
208
 
209
+ /**
210
+ * What a stored folder says each record is: its entity's uuid → the data schema its entry names
211
+ * (`entry: { schema, entity }`, the schema's scoped name). Banked beside the placements, so a push
212
+ * can tell a record whose file moved to another schema (`records.js`, `heldTypes`).
213
+ *
214
+ * @param {object} doc - a stored `@uniweb/folder` document
215
+ * @returns {Record<string,string>}
216
+ */
217
+ export function collectFolderRecordTypes(doc) {
218
+ const out = {}
219
+ walkFolderItems(doc?.contents, (_at, item) => {
220
+ const e = item?.kind === 'ref' ? item.entry : null
221
+ if (e && typeof e === 'object' && typeof e.entity === 'string' && e.entity && typeof e.schema === 'string' && e.schema) {
222
+ out[e.entity] = e.schema
223
+ }
224
+ })
225
+ return out
226
+ }
227
+
201
228
  /**
202
229
  * Stamp known `$uuid`s onto a folder document about to be sent, so the backend
203
230
  * matches its stored rows instead of reading every item as new.
package/src/uwx/index.js CHANGED
@@ -60,6 +60,7 @@ export {
60
60
  export { editYamlText, setYamlKey, replaceInYamlList } from './yaml-edit.js'
61
61
  export { buildFolderEntity,
62
62
  collectFolderItemUuids,
63
+ collectFolderRecordTypes,
63
64
  stampFolderItemUuids
64
65
  } from './folder.js'
65
66
  // The identity of a record's list items — banked per record from what a push sent and
@@ -118,6 +119,7 @@ export {
118
119
  listSyncedBackends,
119
120
  updateBackendState,
120
121
  updateBackendMap,
122
+ setBackendMap,
121
123
  carryServed,
122
124
  clearBackend,
123
125
  clearBackendSections,
@@ -554,7 +554,7 @@ function describeUnresolved({ path, model, value, invalid, ambiguous }) {
554
554
  // `{ $ref: <$id> }` for a record of the same package. A uuid it did not mint is never
555
555
  // sent (see `buildRecordEntities`).
556
556
  const AMBIGUOUS = Symbol('ambiguous')
557
- function refResolver(readSchemas, recordMap) {
557
+ function refResolver(readSchemas, recordMap, moved = new Map()) {
558
558
  const byModel = new Map() // Model → handle → the record: its own id (null before its first push) and `$id`
559
559
  const byOwnId = new Map() // the record's own id → the record
560
560
  for (const { declaration, flat } of readSchemas) {
@@ -567,7 +567,8 @@ function refResolver(readSchemas, recordMap) {
567
567
  if (own) byOwnId.set(own, record)
568
568
  }
569
569
  }
570
- const sent = ({ own, id }) => (own && recordMap[own] ? { uuid: recordMap[own] } : { ref: id })
570
+ // A record moved to another data schema is new on the wire, so a reference names it by `$id`.
571
+ const sent = ({ own, id }) => (own && recordMap[own] && !moved.has(own) ? { uuid: recordMap[own] } : { ref: id })
571
572
  return {
572
573
  resolve(model, value) {
573
574
  if (typeof value !== 'string' || value === '') return { invalid: true }
@@ -582,6 +583,22 @@ function refResolver(readSchemas, recordMap) {
582
583
  }
583
584
  }
584
585
 
586
+ // A data schema's scoped name, `@scope/name` — not the unqualified `@/name`.
587
+ const SCOPED = /^@[^/\s]+\/[^/\s]+$/
588
+
589
+ // The fields of a record file holding `#ref`, the marker a pull writes for a set secret. A moved
590
+ // record's entity is new, and a new entity holds no secret, so these arrive unset
591
+ // [backend, 2026-11-04]: the push names them, to be set again.
592
+ function setSecretFields(data, prefix = '') {
593
+ const out = []
594
+ for (const [key, value] of Object.entries(data && typeof data === 'object' ? data : {})) {
595
+ if (key.startsWith('$')) continue
596
+ if (value === '#ref') out.push(prefix + key)
597
+ else if (value && typeof value === 'object' && !Array.isArray(value)) out.push(...setSecretFields(value, `${prefix}${key}.`))
598
+ }
599
+ return out
600
+ }
601
+
585
602
  // "a", "a and b", "a, b and c" — items are already formatted.
586
603
  function listOf(items) {
587
604
  if (items.length <= 1) return items.join('')
@@ -871,9 +888,11 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
871
888
  // lists it and nothing leaves it out. `records/folder.yml` only sorts records into
872
889
  // sub-folders. A file named with a leading `_` is not read, so it is not a record.
873
890
  //
874
- // ⛔ A PUSHED RECORD IS NOT LIVE. It sits in the site's folder on the backend and
875
- // is served once the SITE is published — publishing the site publishes its folder
876
- // and what is in it. Nothing here decides that for a record.
891
+ // ⛔ A RECORD IS NOT LIVE BECAUSE ITS FILE IS HERE. A push puts it in the site's folder on
892
+ // the backend, and the site's first publish opens that folder to the live site. From then on
893
+ // the live site reads its records from the folder as it stands, so a later push adds, changes
894
+ // or removes them there with no republish [backend, 2026-11-04 — `delivery-orientation.md`].
895
+ // Nothing here decides that for a record.
877
896
  //
878
897
  // ⛔ UNTIL 2026-09-21 THE SET WAS `records.yml`'s: an unlisted entity was not
879
898
  // pushed, and a missing `records.yml` pushed nothing. The inert state moved with
@@ -1058,6 +1077,20 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
1058
1077
  // file and the map is identity — exactly what happened before this change, so a
1059
1078
  // single-backend project behaves as it always did.
1060
1079
  const recordMap = opts.backend ? readBackendState(siteRoot, opts.backend).records || {} : {}
1080
+ // ⭐ WHAT THIS BACKEND HOLDS EACH RECORD AS: its uuid → the data schema its folder entry names
1081
+ // (`sync.json::backends.<B>.types`, banked from every folder a push or pull hands back). An
1082
+ // entity keeps its data schema for life, so an entry never changes.
1083
+ //
1084
+ // A record whose file now sits under another schema has MOVED. It goes up as a new entity of
1085
+ // the new schema (no `$uuid`, its `$id` for references), and its folder entry keeps its own
1086
+ // `$uuid`, found by the record it held, so the entry stays the row it was whatever the file is
1087
+ // now called. One push moves it (backend `entity-sync-wire.md` §11.3). The old entity is kept,
1088
+ // in no folder. ⛔ Until 2026-11-04 the push sent it with its `$uuid` and was refused
1089
+ // (`type_changed`), and the author's way round was to delete the line, which lost the entry
1090
+ // too whenever the file was renamed in the same move.
1091
+ const heldTypes = opts.backend ? readBackendState(siteRoot, opts.backend).types || {} : {}
1092
+ // the record's own id → { uuid: the entity it was, from, to }
1093
+ const moved = new Map()
1061
1094
 
1062
1095
  const entities = []
1063
1096
  const index = []
@@ -1186,6 +1219,14 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
1186
1219
  } else if (ownId) {
1187
1220
  fileByOwnId.set(ownId, pooled.relPath)
1188
1221
  }
1222
+ const held = ownId ? recordMap[ownId] : undefined
1223
+ const heldAs = held ? heldTypes[held] : undefined
1224
+ // ⛔ Only two fully scoped names compare. An unqualified `@/x` (a foundation whose scope is not
1225
+ // known here) would differ from the backend's `@acme/x` without the record having moved, and
1226
+ // read as a move it would send the record as new on every push.
1227
+ if (heldAs && SCOPED.test(heldAs) && SCOPED.test(declaration.name) && heldAs !== declaration.name) {
1228
+ moved.set(ownId, { uuid: held, from: heldAs, to: declaration.name })
1229
+ }
1189
1230
  flat.push(rec)
1190
1231
  sourceBySlug.set(r.slug, r)
1191
1232
  produced.push({ id: rec.$id, slug: r.slug })
@@ -1194,14 +1235,14 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
1194
1235
  }
1195
1236
  readSchemas.push({ label, declaration, flat, sourceBySlug })
1196
1237
  }
1197
- const refs = refResolver(readSchemas, recordMap)
1238
+ const refs = refResolver(readSchemas, recordMap, moved)
1198
1239
 
1199
1240
  for (const { label, declaration, flat, sourceBySlug } of readSchemas) {
1200
1241
  const ownIds = new Map()
1201
1242
  const onWire = flat.map((rec) => {
1202
1243
  const own = typeof rec.$uuid === 'string' && rec.$uuid ? rec.$uuid : null
1203
1244
  ownIds.set(rec.slug, own)
1204
- const minted = own ? recordMap[own] : undefined
1245
+ const minted = own && !moved.has(own) ? recordMap[own] : undefined
1205
1246
  const { $uuid: _own, ...rest } = rec
1206
1247
  return minted ? { ...rest, $uuid: minted } : rest
1207
1248
  })
@@ -1236,6 +1277,10 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
1236
1277
  )
1237
1278
  }
1238
1279
  seen.add(dupKey)
1280
+ // A moved record's folder entry is found by the entity it held (`folder.js`).
1281
+ const own = ownIds.get(e.slug) ?? null
1282
+ const move = own ? moved.get(own) : undefined
1283
+ if (move) e.movedFrom = move.uuid
1239
1284
  // The verb back-fills the minted `$uuid` into this source file, matched
1240
1285
  // back from the finalized response by ($schema, $id).
1241
1286
  const src = sourceBySlug.get(e.slug)
@@ -1254,6 +1299,8 @@ export async function buildRecordEntities(siteRoot, opts = {}) {
1254
1299
  multiRecord: src ? src.multiRecord : false,
1255
1300
  // Sent disabled, so the back-fill can check that the backend kept it that way.
1256
1301
  draft: e.document.$disabled === true,
1302
+ // Moved to another data schema: what it was held as, and what it is now.
1303
+ ...(move ? { moved: { from: move.from, to: move.to, uuid: move.uuid, secrets: setSecretFields(src?.data) } } : {}),
1257
1304
  })
1258
1305
  }
1259
1306
  entities.push(...mappedOut.entities)
@@ -43,9 +43,12 @@ const VERSION = 1
43
43
  /**
44
44
  * Map sections — merged entry by entry. Anything else in a patch replaces.
45
45
  * `recordItems` is keyed by a record's uuid here, each entry that record's list items
46
- * (`record-items.js`) — replaced whole, one record at a time.
46
+ * (`record-items.js`) — replaced whole, one record at a time. `types` is keyed by a record's
47
+ * uuid too, each entry the data schema the backend holds it as, written whole from each folder the
48
+ * backend hands back (`setBackendMap`), so it names what the folder places. `retired` is the same
49
+ * shape: the records a push took out of the folder, which the backend keeps until they are deleted.
47
50
  */
48
- const MAP_SECTIONS = new Set(['records', 'items', 'queries', 'folders', 'assets', 'recordItems', 'files'])
51
+ const MAP_SECTIONS = new Set(['records', 'items', 'queries', 'folders', 'assets', 'recordItems', 'files', 'types', 'retired'])
49
52
 
50
53
  const storePath = (siteDir) => join(siteDir, SYNC_STORE_FILE)
51
54
 
@@ -241,6 +244,32 @@ export function updateBackendMap(siteDir, origin, section, entries, merge) {
241
244
  return { added, changed, written: writeStore(siteDir, backends) }
242
245
  }
243
246
 
247
+ /**
248
+ * Write one map section whole, replacing what it held — for a section that is a snapshot of what
249
+ * the backend says, such as `types`, rather than an accumulation. An empty map removes the section.
250
+ *
251
+ * @param {string} siteDir
252
+ * @param {string} origin
253
+ * @param {string} section - a map section
254
+ * @param {Record<string, *>} map
255
+ * @returns {{ prior: Record<string, *>, written: boolean }} the section as it was before
256
+ */
257
+ export function setBackendMap(siteDir, origin, section, map) {
258
+ const key = normalizeOrigin(origin)
259
+ if (!key || !MAP_SECTIONS.has(section) || !map || typeof map !== 'object') return { prior: {}, written: false }
260
+ const { backends } = readSyncStore(siteDir)
261
+ const state = backends[key] || {}
262
+ const prior = state[section] || {}
263
+ const next = { ...state }
264
+ if (Object.keys(map).length) next[section] = { ...map }
265
+ else delete next[section]
266
+ if (JSON.stringify(sortedKeys(prior)) === JSON.stringify(sortedKeys(map))) return { prior, written: false }
267
+ backends[key] = next
268
+ return { prior, written: writeStore(siteDir, backends) }
269
+ }
270
+
271
+ const sortedKeys = (map) => Object.fromEntries(Object.keys(map).sort().map((k) => [k, map[k]]))
272
+
244
273
  /**
245
274
  * The merge rule for the `assets` section — pass it to `updateBackendMap`.
246
275
  *