@nuasite/cms-sidecar 0.58.2 → 0.60.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 +38 -0
- package/dist/cli.js +918 -682
- package/dist/types/index.d.ts +1 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/portable.d.ts +10 -0
- package/dist/types/portable.d.ts.map +1 -0
- package/dist/types/server.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/src/index.ts +1 -24
- package/src/portable.ts +28 -0
- package/src/server.ts +34 -14
package/README.md
CHANGED
|
@@ -14,6 +14,44 @@ 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
|
+
## Hosts outside Node
|
|
18
|
+
|
|
19
|
+
`createServer` is a `Request` → `Response` handler, so a host can mount it without the
|
|
20
|
+
CLI, for example in a Cloudflare Worker with `nodejs_compat`. There, `@nuasite/cms-sidecar`
|
|
21
|
+
and `@nuasite/cms-core` resolve under the `workerd` condition to entries without `node:fs`
|
|
22
|
+
(they still use `node:crypto` and `node:path`). They leave out `createNodeFs`,
|
|
23
|
+
`createLocalStorageAdapter` and `mediaFromEnv`; the host passes its own `CmsFileSystem`.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import {
|
|
27
|
+
commitChangeset,
|
|
28
|
+
createCmsCore,
|
|
29
|
+
createFileSystemStorageAdapter,
|
|
30
|
+
} from '@nuasite/cms-core'
|
|
31
|
+
import { createServer } from '@nuasite/cms-sidecar'
|
|
32
|
+
|
|
33
|
+
const core = createCmsCore(fs, {
|
|
34
|
+
// Uploads stored in the project through the same filesystem.
|
|
35
|
+
media: createFileSystemStorageAdapter(fs, {
|
|
36
|
+
dir: 'public/uploads',
|
|
37
|
+
urlPrefix: '/uploads',
|
|
38
|
+
}),
|
|
39
|
+
// Each mutation runs over a staged view; its changes reach the files only through this.
|
|
40
|
+
commit: changeset => commitInsideTheHostsLock(changeset),
|
|
41
|
+
})
|
|
42
|
+
const server = createServer({ core, fs, root: '/', coreVersion })
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`commit` is the fence against writers the server does not know about, such as an agent
|
|
46
|
+
editing the same checkout. A mutation's changeset lists the version of every file it read,
|
|
47
|
+
tested or changed (`absent`, `present`, or a `sha256:` content digest) and the files it
|
|
48
|
+
writes or removes. The commit applies the changes only when all those versions still hold,
|
|
49
|
+
and otherwise rejects with `CmsCommitConflictError` and applies nothing. The server answers
|
|
50
|
+
that with a `409`: for `PATCH` an entry, the usual `ConflictResponse` with the current
|
|
51
|
+
version. `commitChangeset(fs)` is a reference implementation; it is atomic only when nothing
|
|
52
|
+
else writes between its awaits, so a host with concurrent writers runs the same check
|
|
53
|
+
(`versionOf`, `versionMatches`) and the writes inside its own critical section.
|
|
54
|
+
|
|
17
55
|
## Collections the scan cannot vouch for
|
|
18
56
|
|
|
19
57
|
`GET /cms/v1/collections` lists the collections the scan could read. The scan is a walk
|