@nuasite/cms-sidecar 0.56.4 → 0.57.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/README.md +306 -0
- package/dist/cli.js +20627 -19090
- package/dist/types/server.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types.d.ts +6 -1
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/server.ts +157 -73
- package/src/types.ts +6 -1
package/README.md
CHANGED
|
@@ -14,6 +14,312 @@ liveness probe with `{ ok, coreVersion, root }`.
|
|
|
14
14
|
The typed client for this contract is [`@nuasite/cms-client`](../cms-client);
|
|
15
15
|
the wire shapes come from [`@nuasite/cms-types`](../cms-types).
|
|
16
16
|
|
|
17
|
+
## Collections the scan cannot vouch for
|
|
18
|
+
|
|
19
|
+
`GET /cms/v1/collections` lists the collections the scan could read. The scan is a walk
|
|
20
|
+
of the content directory combined with a static read of the content config
|
|
21
|
+
(`src/content.config.ts` or `src/content/config.ts`), so a collection the site declares
|
|
22
|
+
can be missing from the list, or be listed with fewer entries than it has.
|
|
23
|
+
`GET /cms/v1/project` says which ones, in `collectionScan`, next to the `collections` of
|
|
24
|
+
the same scan:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"collections": [],
|
|
29
|
+
"pages": [],
|
|
30
|
+
"capabilities": { "coreVersion": "0.56.4", "features": [] },
|
|
31
|
+
"collectionScan": {
|
|
32
|
+
"contentConfig": "ok",
|
|
33
|
+
"unresolved": [
|
|
34
|
+
{
|
|
35
|
+
"name": "authors",
|
|
36
|
+
"reason": "unsupported-loader",
|
|
37
|
+
"file": "src/data/authors.json"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "docs",
|
|
41
|
+
"reason": "unlisted-entries",
|
|
42
|
+
"base": "src/content/docs",
|
|
43
|
+
"pattern": "**/*.md"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "news",
|
|
47
|
+
"reason": "scan-failed",
|
|
48
|
+
"base": "src/data/news",
|
|
49
|
+
"pattern": "*.md"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`GET /cms/v1/collections` keeps its shape: a bare array, with no place for this.
|
|
57
|
+
|
|
58
|
+
Only `GET /cms/v1/project` builds the report, and it does so on every request: concurrent
|
|
59
|
+
requests share one scan, but a request that comes after one has finished starts a new one.
|
|
60
|
+
Building it adds a listing per declared collection to that scan. The collection and entry
|
|
61
|
+
routes scan without it and do not pay for it.
|
|
62
|
+
|
|
63
|
+
`core.scanCollections()` builds no report unless asked for `{ report: true }`. A host that
|
|
64
|
+
wraps the core's `scanCollections` has to pass its argument on: a wrapper that drops it makes
|
|
65
|
+
`/project` answer without a report, which a consumer reads as "not vouched for".
|
|
66
|
+
|
|
67
|
+
### What is checked
|
|
68
|
+
|
|
69
|
+
The report compares the scan with what Astro 6 loads under nua's defaults. `@nuasite/nua`
|
|
70
|
+
sets `legacy.collectionsBackwardsCompat`, under which a declaration without a loader, and
|
|
71
|
+
a content directory nothing declares, are collections too. Whether a site sets the flag
|
|
72
|
+
cannot be read reliably, so it is taken to be set: a site without it can get a report for
|
|
73
|
+
something Astro does not load, and a site with it cannot have a file missed.
|
|
74
|
+
|
|
75
|
+
A collection is vouched for when every entry file it loads is an entry of some scanned
|
|
76
|
+
collection. Being in `collections` is not enough: a content directory of the declared name
|
|
77
|
+
is read whatever the loader says, and only as deep as `<slug>.<ext>` and
|
|
78
|
+
`<slug>/index.<ext>`. What a collection loads is taken to be:
|
|
79
|
+
|
|
80
|
+
- a `glob()` with a `base` the scan can look under and a literal `pattern` it can run: the
|
|
81
|
+
files the pattern matches. A `glob()` that names no `base` loads from the project root;
|
|
82
|
+
- the same with a `pattern` the scan cannot run, or a list of literal patterns: any file
|
|
83
|
+
under the base, since the pattern could select it;
|
|
84
|
+
- a declaration without a `loader`: every file under `<content dir>/<name>`, paths with a
|
|
85
|
+
segment starting with `_` aside. Astro resolves the name as a URL against the content
|
|
86
|
+
directory, so a name it reads as another path (`a#b`, `a?b`, `a%20b`, a backslash, a
|
|
87
|
+
tab) is unknown;
|
|
88
|
+
- a content directory nothing declares, when the config exports `collections` and no
|
|
89
|
+
declared collection is seen to have a loader: its markdown files at any depth, `_`
|
|
90
|
+
paths aside. With a loader anywhere in the config, or without that export, Astro
|
|
91
|
+
leaves such directories alone, and so does the report;
|
|
92
|
+
- anything else: unknown. That is `file()`, a custom loader, a helper call, a spread or a
|
|
93
|
+
computed key among the options, a `pattern` that is not a literal (it may lead
|
|
94
|
+
anywhere), a pattern with a `..` segment, and a `base` the scan cannot look under.
|
|
95
|
+
|
|
96
|
+
A pattern the scan can run is made of `*`, `**`, `?` and `{a,b}` with plain alternatives.
|
|
97
|
+
It cannot run a character class, an extglob, an escape, a `|` (alternation to Astro), a
|
|
98
|
+
`+` behind a brace (a quantifier), a brace without a comma (`{a}` is a file name to
|
|
99
|
+
Astro), or a brace that holds another brace, a range (`{x,1..3}`), a wildcard or an empty
|
|
100
|
+
alternative; nor the shapes Astro's glob reads wider than the scan does: a `..` segment,
|
|
101
|
+
also one a brace completes (`..{/drafts,x}`), a trailing slash, a negation behind `./`,
|
|
102
|
+
and a final `/**`, which to Astro also matches a file named by what stands before it.
|
|
103
|
+
|
|
104
|
+
A `base` the scan can look under is one Astro reads as the same relative directory. Astro
|
|
105
|
+
resolves the base as a URL against the project root, so these are not: an absolute path or
|
|
106
|
+
a URL; a `%`, `#` or `?`; a backslash, which becomes a slash; whitespace at either end and
|
|
107
|
+
a tab or line break anywhere, which are dropped; a `..` that leads out of the root, which
|
|
108
|
+
is resolved against it. A glob character in the base (`*`, `{`, `}`) is not one either.
|
|
109
|
+
|
|
110
|
+
Which files count as entry files: those ending in `md`, `mdx`, `json`, `yaml`, `yml` or
|
|
111
|
+
`toml`, which Astro's glob loads, and those ending in `mdoc`, `markdown`, `mdown`, `mkdn`,
|
|
112
|
+
`mkd` or `mdwn`, in any letter case, which it loads only with an integration. Counting
|
|
113
|
+
too many makes a report, never a miss. An image next to an entry is not an entry.
|
|
114
|
+
|
|
115
|
+
Dotfiles and files in dot directories are counted only when the pattern asks for them, as
|
|
116
|
+
Astro's glob keeps `*` and `**` from matching a leading dot. A pattern asks by naming the
|
|
117
|
+
dot at the start of a segment or of an alternative (`.well-known/*.json`). It also asks
|
|
118
|
+
with a `*` or a `?` at the start of an alternative, right behind a brace or behind a `|`:
|
|
119
|
+
Astro's glob guards a wildcard against a leading dot only at the start of the pattern and
|
|
120
|
+
behind a slash, so `{guide/,notes/}*.md` loads `guide/.wip.md` and `**/{*.md,*.mdx}` does
|
|
121
|
+
too. In a pattern the scan does not run, such a wildcard counts every dot path under the
|
|
122
|
+
base. And, among the patterns the scan cannot run, by a character class or an extglob,
|
|
123
|
+
which match a leading dot like any other character: in the last segment a dotfile
|
|
124
|
+
(`**/[^_]*.md` loads `guide/.wip.md`), in an earlier one a dot directory (`[^_]*/**/*.md`
|
|
125
|
+
loads `.cache/a.md`). `**/[^_]*.md` does not load `.obsidian/note.md`, and that file is
|
|
126
|
+
not counted. `_` files are counted for a glob loader: Astro loads them when the pattern
|
|
127
|
+
matches, and the scan skips them.
|
|
128
|
+
|
|
129
|
+
Symbolic links are followed, as Astro follows them: a linked file counts under the
|
|
130
|
+
link's own path, and a linked directory is walked as often as a path leads into it. The
|
|
131
|
+
scan itself leaves a linked directory, and a linked file under a glob base, out, so those
|
|
132
|
+
are reported. A link back into a directory already entered through a link on the same
|
|
133
|
+
path is entered once. A linked directory whose real path is outside the project root is
|
|
134
|
+
not walked: the collection it is in is reported as `scan-failed` at once, so a link to `/`
|
|
135
|
+
in a checkout does not have the sidecar list the host's files.
|
|
136
|
+
|
|
137
|
+
The listing for one collection reads at most 20,000 directories behind symbolic links.
|
|
138
|
+
Past that the collection is reported as `scan-failed` instead of being checked in part. A
|
|
139
|
+
link into a very large tree, or links that lead into each other, end there. Directories
|
|
140
|
+
reached without a link do not count: the tree itself is as large as it is.
|
|
141
|
+
|
|
142
|
+
### `unresolved`
|
|
143
|
+
|
|
144
|
+
Each item has a `name` and a `reason` from the set below; later versions may add reasons,
|
|
145
|
+
and a reason a consumer does not know means the collection is not vouched for. The reason says what the scan
|
|
146
|
+
knows, not whether the collection is in `collections`; look the name up to find out.
|
|
147
|
+
|
|
148
|
+
- `unsupported-loader`: what the collection loads is unknown, or its pattern cannot be
|
|
149
|
+
run and a file under its `base` is not an entry of the scan.
|
|
150
|
+
- `scan-failed`: reading the collection, or looking where its loader loads from, threw.
|
|
151
|
+
One markdown entry whose frontmatter is not valid YAML is enough, and so are a
|
|
152
|
+
directory that cannot be read and one with too many directories behind its links to list.
|
|
153
|
+
- `unlisted-entries`: files the collection is known to load are not entries of the scan.
|
|
154
|
+
They could not be read or parsed, or the scan does not take them for entries: a format
|
|
155
|
+
other than md, mdx, json or yaml, a `_` path, a file nested deeper than a content
|
|
156
|
+
directory is read, a data file next to markdown ones, a file behind a symbolic link.
|
|
157
|
+
|
|
158
|
+
`base`, `pattern` and `file` are what is statically known about where the files are, as
|
|
159
|
+
project-root-relative paths: the glob loader's literal `base` (`.` when it names none)
|
|
160
|
+
and `pattern`, the literal path of a `file()` loader, or the content directory the scan
|
|
161
|
+
read. Any of them may be absent.
|
|
162
|
+
|
|
163
|
+
A collection that loads no entry files is an empty collection, not an unresolved one. It
|
|
164
|
+
is in neither list, as before.
|
|
165
|
+
|
|
166
|
+
A content directory whose read threw is listed as `scan-failed` whether or not the config
|
|
167
|
+
declares it and whatever loaders the config has. The scan lists such a directory as a
|
|
168
|
+
collection whenever it can read it, so an answer without it has lost something it would
|
|
169
|
+
have had.
|
|
170
|
+
|
|
171
|
+
### `contentConfig`
|
|
172
|
+
|
|
173
|
+
The reader looks at `src/content.config.ts` and `src/content/config.ts`. Astro takes a
|
|
174
|
+
content config from `content.config.{mjs,js,mts,ts}` in the source directory, and with
|
|
175
|
+
the flag above from `content/config.*` there.
|
|
176
|
+
|
|
177
|
+
- `ok`: the config was read and every key of its `collections` export is known.
|
|
178
|
+
- `missing`: no content config was found. None of Astro's names exists under `src`, and
|
|
179
|
+
none under the directory the Astro config's `srcDir` names, where it names one. Astro
|
|
180
|
+
loads no collections without a content config, so the scan cannot have left any out,
|
|
181
|
+
whatever content directories it lists.
|
|
182
|
+
- `unreadable`: a content config exists, or may exist, and none of it was read. It does
|
|
183
|
+
not parse, it is a `.js`, `.mjs` or `.mts` file, or it is under a `srcDir` other than
|
|
184
|
+
`src`. The same is said when where Astro loads content from cannot be told: the `srcDir`,
|
|
185
|
+
or the `root` every loader's `base` is resolved against. What is declared is unknown.
|
|
186
|
+
- `partial`: the config was read, but not all of what it declares is known. The
|
|
187
|
+
`collections` export is not an object literal (built by a call, re-exported from another
|
|
188
|
+
module, a `let`), the literal has a spread, a method, a `__proto__` or a computed key
|
|
189
|
+
that is not a string in it, the file mentions `collections` in a way that may add to it
|
|
190
|
+
(`Object.assign(collections, …)`, and any other mention the list below does not name),
|
|
191
|
+
the file imports a content config (which may be itself, and then it can change what it
|
|
192
|
+
exports without naming it), or the project has two content config files and the one that
|
|
193
|
+
was read need not be the one Astro uses. `unresolved` covers the names that could be
|
|
194
|
+
read; others may exist.
|
|
195
|
+
|
|
196
|
+
`srcDir` and `root` are read off the code of the Astro config file Astro uses (the first
|
|
197
|
+
of `astro.config.mjs`, `.js`, `.ts`, `.mts`). `srcDir` is where the content config and the
|
|
198
|
+
content directory are; `root` is what every loader's `base` is resolved against, and the
|
|
199
|
+
scan takes it to be the project root. Which mention of either name is Astro's option
|
|
200
|
+
cannot be told without running the file: it may name another plugin's option, a variable,
|
|
201
|
+
a member. So every mention in the code has to be a property given a plain string, with the
|
|
202
|
+
string as the whole value. A mention is the name as an identifier, or a string that is
|
|
203
|
+
exactly the name, anywhere in the code: a string can be made a key in more ways than can
|
|
204
|
+
be listed (`Object.defineProperty(config, 'srcDir', …)`, `const KEY = 'root'`). All
|
|
205
|
+
`srcDir`s have to name the same directory inside the project, and every `root` has to be
|
|
206
|
+
`'.'` or `'./'`. Anything else gives `unreadable`: a value that is not a plain string (a
|
|
207
|
+
template with a hole, a concatenation, a call, a variable), a shorthand, a variable, a
|
|
208
|
+
parameter or a member of that name, a second `srcDir` that disagrees, a path that is
|
|
209
|
+
absolute or starts with `..`, and a file that does not parse. Comments are not code and
|
|
210
|
+
set nothing. Either name given an object literal is another option of that name (Astro's
|
|
211
|
+
are strings) and is passed over. A directory named by `srcDir` with no content config in
|
|
212
|
+
it settles nothing, and `src` is then judged as usual.
|
|
213
|
+
|
|
214
|
+
`as`, `satisfies`, a numeric or quoted key and a `const` of the same file are read
|
|
215
|
+
through, but a `const` only when the file leaves no doubt that it still holds what it was
|
|
216
|
+
declared as. A module-level `const` is followed when every mention of its name in the
|
|
217
|
+
file is one of these:
|
|
218
|
+
|
|
219
|
+
- its one declaration;
|
|
220
|
+
- the value of a property in an object literal the reader reads, the first argument of
|
|
221
|
+
`glob`, `file`, `defineCollection` or `defineCmsCollection` where the reader reads that
|
|
222
|
+
call, or the whole initializer of another `const` (an alias). The reader reads the
|
|
223
|
+
initializer of a `const` that is itself followed, so a name is dropped together with
|
|
224
|
+
the one that holds it;
|
|
225
|
+
- `X.key`, where the declaration gives `key` a string, a number, a boolean or `null`, read
|
|
226
|
+
into a declaration, a property, a call argument, an array, a template, or a binary,
|
|
227
|
+
logical or conditional expression;
|
|
228
|
+
- `export { X }`, `export default X`, a type (`typeof X`) and `Object.keys(X)`.
|
|
229
|
+
|
|
230
|
+
Any other mention drops the name. A call that takes it (`console.log(blog)`,
|
|
231
|
+
`Object.freeze(blog)`, `Object.values(collections)`), a member written, called or read
|
|
232
|
+
(`blog.loader = …`, `OPTIONS.move()`, `blog.type`), an array, a spread, a loop, a
|
|
233
|
+
conditional, a function that mentions it, and a second declaration of the name anywhere
|
|
234
|
+
in the file, a parameter or a local included: which of two declarations a mention means
|
|
235
|
+
is not worked out. `eval` or `Function` anywhere in the file drops every name. A
|
|
236
|
+
`glob`, `file`, `defineCollection` or `defineCmsCollection` that the file declares itself
|
|
237
|
+
is not taken for Astro's, and what is handed to it is dropped. The list names what is
|
|
238
|
+
harmless and not what is harmful, so a use nobody thought of leaves a name unknown and
|
|
239
|
+
not trusted.
|
|
240
|
+
|
|
241
|
+
A `const` that holds a string, a number, a boolean or `null` is followed whatever
|
|
242
|
+
mentions it: neither the binding nor the value can change.
|
|
243
|
+
|
|
244
|
+
A collection behind a name that is not followed is `unsupported-loader`; `collections`
|
|
245
|
+
itself behind one is `partial`.
|
|
246
|
+
|
|
247
|
+
An object literal is read only as far as its own keys settle what it holds. A key given
|
|
248
|
+
twice holds what it was given last. A declaration or a set of `glob` options with a `this`
|
|
249
|
+
anywhere in it is not read: an accessor or a method can change the literal it sits in
|
|
250
|
+
without naming it. A getter, a setter or a method for `loader`, `base`
|
|
251
|
+
or `pattern`, a `__proto__`, and a spread or a computed key after the `loader` (anywhere
|
|
252
|
+
among the options of `glob`) leave that part unknown.
|
|
253
|
+
|
|
254
|
+
### How to read it
|
|
255
|
+
|
|
256
|
+
- **No `collectionScan`** means unknown: the sidecar predates the field, or could not
|
|
257
|
+
build the report. Nothing is known about what it left out. This is not the same as an
|
|
258
|
+
empty list, and a consumer that needs the answer must not take it for one.
|
|
259
|
+
- **`unresolved: []` with `contentConfig` `ok` or `missing`** is the all-clear: as far as
|
|
260
|
+
the limits below allow, every entry file Astro loads into a collection is an entry of
|
|
261
|
+
some scanned collection. `missing` is one because Astro loads nothing without a
|
|
262
|
+
content config. A site with no collections is an ordinary site. A consumer that wants to
|
|
263
|
+
be careful about the first limit below may take `missing` for an all-clear only when the
|
|
264
|
+
site also has no content directory: a site with content and no content config is where a
|
|
265
|
+
moved `srcDir` that the reader could not see would show.
|
|
266
|
+
- **`unreadable` or `partial`** means collections may exist that `unresolved` cannot name.
|
|
267
|
+
- **A `contentConfig` or `reason` value the consumer does not know** means not vouched for.
|
|
268
|
+
Later versions may add values; only `ok` and `missing` are an all-clear.
|
|
269
|
+
|
|
270
|
+
### What an all-clear still does not prove
|
|
271
|
+
|
|
272
|
+
- That `srcDir` and `root` are what the Astro config file's code says. One set where the
|
|
273
|
+
names do not stand is not seen, and the report then speaks about `src` under the project
|
|
274
|
+
root: an imported options object that is spread in, a wrapper around `defineConfig`, a key
|
|
275
|
+
put together from parts (`['src' + 'Dir']`, `JSON.parse('{"srcDir":"./app"}')`), and an
|
|
276
|
+
integration from another module that moves either through `updateConfig`.
|
|
277
|
+
- That Astro is run on that config file from that directory. `astro --config <file>` and
|
|
278
|
+
`astro --root <dir>` move both, and the sidecar cannot know how Astro is started.
|
|
279
|
+
- That nothing changed a value from outside the file: another module that imports what
|
|
280
|
+
the config exports, or code the config imports that reaches it some other way.
|
|
281
|
+
- That `glob`, `file`, `defineCollection` and `defineCmsCollection` are Astro's and nua's.
|
|
282
|
+
A call is recognised by its name. One the file declares itself is not trusted, but one
|
|
283
|
+
imported under that name from another module is; an alias (`import { glob as g }`) is an
|
|
284
|
+
unknown loader.
|
|
285
|
+
- That the scan runs every pattern it takes for runnable exactly as Astro does. The two
|
|
286
|
+
were compared on generated patterns, which is evidence and not a proof.
|
|
287
|
+
- That no integration adds an entry type of its own beyond the extensions above.
|
|
288
|
+
- That the entries themselves are complete or valid. The check is about which files are
|
|
289
|
+
entries.
|
|
290
|
+
|
|
291
|
+
Some reports are stricter than Astro:
|
|
292
|
+
|
|
293
|
+
- A pattern the scan cannot run is reported whenever a file under its `base` is not
|
|
294
|
+
listed, also when the pattern would have left that file out. `**/[^_]*.md` next to a
|
|
295
|
+
`_draft.md` the scan did not list is the usual case.
|
|
296
|
+
- A collection whose loader is unknown is reported also when a content directory of its
|
|
297
|
+
name was read and holds all of its files.
|
|
298
|
+
- On a site that does not set `legacy.collectionsBackwardsCompat`, a declaration without a
|
|
299
|
+
loader and a content directory nothing declares are checked although Astro loads
|
|
300
|
+
neither.
|
|
301
|
+
- Files Astro's glob skips for want of an entry type (`.markdown`, `.MD`) are counted.
|
|
302
|
+
- A flat file and an `index` file that share a slug (`a.md`, `a/index.md`) are two files
|
|
303
|
+
here and one entry to Astro.
|
|
304
|
+
- An empty YAML or JSON data file, and a file nobody can read, are source files that are
|
|
305
|
+
not entries.
|
|
306
|
+
- A linked directory reached by two links is walked twice here.
|
|
307
|
+
- A healthy config that mentions a collection, a loader or an options object in any way
|
|
308
|
+
the list above does not name: `console.log(blog)`, `Object.freeze(OPTIONS)`,
|
|
309
|
+
`Object.values(collections)`, `blog.type`, `[blog, docs].forEach(…)`, a function
|
|
310
|
+
parameter that happens to share the name.
|
|
311
|
+
- An Astro config with a variable, a parameter or a member named `root`, or another
|
|
312
|
+
plugin's option of that name given a string (`vite: { root: … }`), is `unreadable`.
|
|
313
|
+
- A pattern with a class or an extglob counts dot paths below the base that the pattern
|
|
314
|
+
would not reach (`[^_]*.md` next to `guide/.wip.md`), and so does a pattern the scan does
|
|
315
|
+
not run with a wildcard at the start of an alternative (`**/{*.md,*.mdx}` next to
|
|
316
|
+
`.obsidian/note.md`).
|
|
317
|
+
- An Astro config with the string `'root'` or `'srcDir'` anywhere in its code, also where it
|
|
318
|
+
is no key (`label: 'root'`), is `unreadable`.
|
|
319
|
+
- A declaration or a set of `glob` options with a `this` in it, also one that changes nothing.
|
|
320
|
+
- A content config that imports a file named `content.config` or `content/config` from
|
|
321
|
+
anywhere is `partial`.
|
|
322
|
+
|
|
17
323
|
## Media storage
|
|
18
324
|
|
|
19
325
|
The media routes need an adapter, selected by `CMS_MEDIA_ADAPTER`
|