@uniweb/build 1.22.0 → 1.23.1
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 +6 -6
- package/src/foundation/library-mappings.js +109 -0
- package/src/foundation/mappings.js +64 -4
- package/src/foundation/shared-types.js +22 -2
- package/src/i18n/data-strings.js +0 -5
- package/src/i18n/index.js +12 -7
- package/src/i18n/records.js +21 -251
- package/src/index.js +2 -1
- package/src/resolve-data-schema.js +4 -3
- package/src/schema.js +34 -2
- package/src/site/build-site-data.js +17 -57
- package/src/site/content-collector.js +34 -7
- package/src/site/entity-pool.js +10 -0
- package/src/site/index.js +0 -1
- package/src/site/plugin.js +28 -17
- package/src/site/queries-config.js +35 -9
- package/src/site/query-processor.js +63 -13
- package/src/site/standard-type-for.js +22 -0
- package/src/utils/classify-package.js +9 -6
- package/src/uwx/blueprint-file.js +22 -4
- package/src/uwx/blueprint.js +46 -25
- package/src/uwx/index.js +1 -0
- package/src/uwx/records-project.js +49 -9
- package/src/uwx/records.js +42 -40
- package/src/uwx/registry-package.js +32 -20
- package/src/uwx/shown-records.js +2 -2
- package/src/uwx/site-project.js +7 -5
- package/src/uwx/site.js +7 -13
- package/src/uwx/sync-package.js +7 -10
- package/src/validate-data.js +53 -3
- package/src/site/schemaless-data.js +0 -185
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema-less collection data — the set, and its local media.
|
|
3
|
-
*
|
|
4
|
-
* ⭐ **The name carries the scope on purpose.** This is NOT "the site's static
|
|
5
|
-
* data" in general. A site's collections partition by **schema presence**: one
|
|
6
|
-
* that resolves a data schema syncs as folder entities — content a backend
|
|
7
|
-
* genuinely consumes, queryable, editable, with a `brief:` for its lean shape.
|
|
8
|
-
* A **schema-less** collection has no entity model, so its compiled
|
|
9
|
-
* `dist/data/<name>.json` (plus its per-record files, `<name>/<$name>.json`) is
|
|
10
|
-
* delivered as files instead. That fallback tier is all this module is about.
|
|
11
|
-
*
|
|
12
|
-
* { data: { "<relpath under dist/data>": <json> } } // schema-less only
|
|
13
|
-
*
|
|
14
|
-
* ⇒ It is an **in-memory enumeration**, not an artifact. `collectSchemalessData`
|
|
15
|
-
* gathers the set; the CLI's `site-data-upload` lane PUTs each file to the
|
|
16
|
-
* target the backend returns, landing at its serving tail.
|
|
17
|
-
*
|
|
18
|
-
* ## ⛔ It used to be a "data ball", and that is retired (2026-08-18)
|
|
19
|
-
*
|
|
20
|
-
* This merged the whole set into ONE uploaded asset that the backend then had
|
|
21
|
-
* to fetch, parse and fan out. It was the **only aggregate the CLI produced** —
|
|
22
|
-
* media, foundation code and the runtime all upload one object per file — and
|
|
23
|
-
* the only place these bytes ever transited the backend. Nothing in the code or
|
|
24
|
-
* the docs ever justified the bundling.
|
|
25
|
-
*
|
|
26
|
-
* ⇒ **Do not reintroduce a bundle here.** One object per file is what the
|
|
27
|
-
* reader's static arm already assumes: a plain object GET on the verbatim tail,
|
|
28
|
-
* with nothing anywhere that unbundles.
|
|
29
|
-
*
|
|
30
|
-
* **A search index used to ride here too, and deliberately no longer does**
|
|
31
|
-
* (2026-08-01). Only a CLI deploy produced one — a CMS publish produced none —
|
|
32
|
-
* so a site's search existed or vanished depending on who published it, which
|
|
33
|
-
* is the artifact-flicker rule exactly. A host that wants search derives it from
|
|
34
|
-
* the content it already stores. See the note at the removal point below.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
import { existsSync } from 'node:fs'
|
|
38
|
-
import { readFile, readdir } from 'node:fs/promises'
|
|
39
|
-
import { join, relative, sep } from 'node:path'
|
|
40
|
-
import { DATA_DIR } from '@uniweb/core'
|
|
41
|
-
import { isLocalAssetPath } from './assets.js'
|
|
42
|
-
|
|
43
|
-
// Walk a dist subdir for *.json → { "<posix-relpath>": <parsedJson> }. Unparseable
|
|
44
|
-
// files are skipped (build-emitted data is always valid JSON; this just stays safe).
|
|
45
|
-
async function readJsonTree(dir) {
|
|
46
|
-
if (!existsSync(dir)) return {}
|
|
47
|
-
const out = {}
|
|
48
|
-
const entries = await readdir(dir, { withFileTypes: true, recursive: true })
|
|
49
|
-
for (const entry of entries) {
|
|
50
|
-
if (!entry.isFile() || !entry.name.endsWith('.json')) continue
|
|
51
|
-
const full = join(entry.parentPath || entry.path, entry.name)
|
|
52
|
-
const rel = relative(dir, full).split(sep).join('/')
|
|
53
|
-
try {
|
|
54
|
-
out[rel] = JSON.parse(await readFile(full, 'utf8'))
|
|
55
|
-
} catch {
|
|
56
|
-
// not valid JSON — skip
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return out
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// The collection a `dist/data` relpath belongs to: the first path segment, minus a
|
|
63
|
-
// trailing `.json`. `articles.json` → `articles`; `articles/hello.json` → `articles`.
|
|
64
|
-
function queryOf(relPath) {
|
|
65
|
-
const first = relPath.split('/')[0]
|
|
66
|
-
return first.endsWith('.json') ? first.slice(0, -5) : first
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Gather the schema-less set from a built site's dist/ — in memory, one entry per
|
|
71
|
-
* file; nothing is bundled (see the header).
|
|
72
|
-
*
|
|
73
|
-
* @param {string} distDir - the site's built dist/ directory
|
|
74
|
-
* @param {string[]} [schemalessNames] - collection names with no data schema (from
|
|
75
|
-
* `emitSyncPackages(...).schemaless`); only these contribute `data`.
|
|
76
|
-
* @returns {Promise<{ data: Object }|null>} null when there is nothing to deliver.
|
|
77
|
-
*/
|
|
78
|
-
export async function collectSchemalessData(distDir, schemalessNames = []) {
|
|
79
|
-
const schemaless = new Set(schemalessNames)
|
|
80
|
-
const allData = await readJsonTree(join(distDir, DATA_DIR))
|
|
81
|
-
const data = {}
|
|
82
|
-
for (const [relPath, value] of Object.entries(allData)) {
|
|
83
|
-
if (schemaless.has(queryOf(relPath))) data[relPath] = value
|
|
84
|
-
}
|
|
85
|
-
// Agent projections deliberately do NOT ride the ball.
|
|
86
|
-
//
|
|
87
|
-
// A backend that stores the site's content derives them itself at publish —
|
|
88
|
-
// one producer, so shipping ours would upload an artifact to the one host
|
|
89
|
-
// that does not need it, and invite two answers for one site. The projections
|
|
90
|
-
// this build emits into `dist/` are for hosts with no backend to derive them:
|
|
91
|
-
// static hosts and foreign backends. That is `@uniweb/projections`' scope and
|
|
92
|
-
// it is unchanged.
|
|
93
|
-
//
|
|
94
|
-
// (An opt-in `projections` bucket lived here while the delivery contract was
|
|
95
|
-
// open. It never shipped enabled, and the one-producer ruling closed the
|
|
96
|
-
// question — removed rather than left as a flag nobody may turn on.)
|
|
97
|
-
//
|
|
98
|
-
// THE SEARCH INDEX IS ONE OF THOSE PROJECTIONS, and it rode this ball anyway
|
|
99
|
-
// — `const search = readJsonTree(dist/_search)` sat four lines above this
|
|
100
|
-
// comment, doing the exact thing the comment forbids. Removed 2026-08-01.
|
|
101
|
-
//
|
|
102
|
-
// What made it wrong is not symmetry, it is the flicker rule: a CLI deploy
|
|
103
|
-
// produced the index and a CMS publish produced none, so a site's search
|
|
104
|
-
// oscillated with whoever published it. Deriving it from stored content — one
|
|
105
|
-
// input that exists identically on both lanes — makes that unexpressible,
|
|
106
|
-
// which is a stronger guarantee than any producer agreement.
|
|
107
|
-
//
|
|
108
|
-
// The static index for hosts with no backend is UNCHANGED and still emitted:
|
|
109
|
-
// `search-index.json`, bundle lane, what GitHub Pages and every other static
|
|
110
|
-
// target serve. The framework has more targets than one backend, and that is
|
|
111
|
-
// the artifact for the rest of them.
|
|
112
|
-
|
|
113
|
-
if (Object.keys(data).length === 0) return null
|
|
114
|
-
|
|
115
|
-
// The `search` key is gone too, and that was the SECOND step of a two-step
|
|
116
|
-
// retirement, not an afterthought.
|
|
117
|
-
//
|
|
118
|
-
// Step one shipped `search: {}` — content removed, key kept — because an
|
|
119
|
-
// absent field and an empty one are different shapes to a strict
|
|
120
|
-
// deserializer, and a missing required field fails exactly as loudly as an
|
|
121
|
-
// unknown one. (The producer half of this same contract broke pushes earlier
|
|
122
|
-
// the same day by emitting a key the consumer had not declared. Same failure,
|
|
123
|
-
// opposite direction.) Step two is this: the consumer retired the field on
|
|
124
|
-
// 2026-08-01 and said an older CLI still sending it deploys fine, so the key
|
|
125
|
-
// now has nowhere to land and dropping it is safe in both directions.
|
|
126
|
-
//
|
|
127
|
-
// Worth keeping as a shape: **announce, then remove** — the mirror of
|
|
128
|
-
// "declare, then emit". Neither half of a wire can be changed in one step by
|
|
129
|
-
// one side, and which side moves first is decided by which direction the
|
|
130
|
-
// strictness runs.
|
|
131
|
-
return { data }
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// --- local media in the ball -------------------------------------------------
|
|
135
|
-
// Schema-less collection data rides in the ball, so a local image in a schema-less
|
|
136
|
-
// record (e.g. a note's `image: /images/x.png`) needs the same upload + serve-URL
|
|
137
|
-
// rewrite the entity content gets (emitSyncPackages' `assetRewrite`) — otherwise the
|
|
138
|
-
// served `/data/<name>.json` keeps a dangling local path. The deploy collects the
|
|
139
|
-
// ball's refs, uploads them on the SAME asset lane, then rewrites the ball before
|
|
140
|
-
// uploading it. The backend serves a `serve_url` in the ball identically to one in an
|
|
141
|
-
// entity (it unwraps the ball verbatim), so this is purely producer-side.
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Site-root local asset refs anywhere in the ball (`/images/x.png`, `/collections/...`).
|
|
145
|
-
* Built `dist/data` refs are already site-root (the collection processor copied
|
|
146
|
-
* co-located assets to `public/collections/**`), so only `/`-prefixed refs are collected.
|
|
147
|
-
* @param {{data:object}|null} ball
|
|
148
|
-
* @returns {string[]} deduped refs to upload
|
|
149
|
-
*/
|
|
150
|
-
export function collectSchemalessDataAssets(ball) {
|
|
151
|
-
const refs = new Set()
|
|
152
|
-
const walk = (n) => {
|
|
153
|
-
if (typeof n === 'string') {
|
|
154
|
-
if (isLocalAssetPath(n) && n.startsWith('/')) refs.add(n)
|
|
155
|
-
return
|
|
156
|
-
}
|
|
157
|
-
if (Array.isArray(n)) { for (const x of n) walk(x); return }
|
|
158
|
-
if (n && typeof n === 'object') for (const v of Object.values(n)) walk(v)
|
|
159
|
-
}
|
|
160
|
-
walk(ball)
|
|
161
|
-
return [...refs]
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Rewrite the ball: replace every local ref the map covers with its serve URL. Pure —
|
|
166
|
-
* returns a NEW ball (the input is reused elsewhere). A ref the map omits (upload
|
|
167
|
-
* failed/skipped) is left untouched — never a broken URL.
|
|
168
|
-
* @param {{data:object}|null} ball
|
|
169
|
-
* @param {Record<string,string>} map - ref → serve URL
|
|
170
|
-
* @returns {{data:object}|null} a new ball, or the input when there's nothing to do
|
|
171
|
-
*/
|
|
172
|
-
export function rewriteSchemalessDataAssets(ball, map) {
|
|
173
|
-
if (!ball || !map || Object.keys(map).length === 0) return ball
|
|
174
|
-
const walk = (n) => {
|
|
175
|
-
if (typeof n === 'string') return map[n] || n
|
|
176
|
-
if (Array.isArray(n)) return n.map(walk)
|
|
177
|
-
if (n && typeof n === 'object') {
|
|
178
|
-
const out = {}
|
|
179
|
-
for (const [k, v] of Object.entries(n)) out[k] = walk(v)
|
|
180
|
-
return out
|
|
181
|
-
}
|
|
182
|
-
return n
|
|
183
|
-
}
|
|
184
|
-
return walk(ball)
|
|
185
|
-
}
|