inlaycms 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +469 -2
- package/assets/admin/admin.css +2 -0
- package/assets/admin/admin.js +1 -0
- package/assets/admin/editor.js +125 -0
- package/dist/adapters/admin/activity.d.ts +17 -0
- package/dist/adapters/admin/activity.js +59 -0
- package/dist/adapters/admin/assets.d.ts +14 -0
- package/dist/adapters/admin/assets.js +64 -0
- package/dist/adapters/admin/attention.d.ts +15 -0
- package/dist/adapters/admin/attention.js +34 -0
- package/dist/adapters/admin/context.d.ts +40 -0
- package/dist/adapters/admin/context.js +142 -0
- package/dist/adapters/admin/form/walk.d.ts +61 -0
- package/dist/adapters/admin/form/walk.js +565 -0
- package/dist/adapters/admin/pages.d.ts +38 -0
- package/dist/adapters/admin/pages.js +66 -0
- package/dist/adapters/admin/publish.d.ts +12 -0
- package/dist/adapters/admin/publish.js +195 -0
- package/dist/adapters/admin/routes.d.ts +47 -0
- package/dist/adapters/admin/routes.js +255 -0
- package/dist/adapters/admin/screens/backups.d.ts +11 -0
- package/dist/adapters/admin/screens/backups.js +223 -0
- package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
- package/dist/adapters/admin/screens/dashboard.js +160 -0
- package/dist/adapters/admin/screens/editor.d.ts +67 -0
- package/dist/adapters/admin/screens/editor.js +416 -0
- package/dist/adapters/admin/screens/history.d.ts +4 -0
- package/dist/adapters/admin/screens/history.js +105 -0
- package/dist/adapters/admin/screens/lists.d.ts +4 -0
- package/dist/adapters/admin/screens/lists.js +297 -0
- package/dist/adapters/admin/screens/media.d.ts +20 -0
- package/dist/adapters/admin/screens/media.js +186 -0
- package/dist/adapters/admin/screens/pickers.d.ts +29 -0
- package/dist/adapters/admin/screens/pickers.js +134 -0
- package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
- package/dist/adapters/admin/screens/preview-pane.js +74 -0
- package/dist/adapters/admin/screens/redirects.d.ts +4 -0
- package/dist/adapters/admin/screens/redirects.js +137 -0
- package/dist/adapters/admin/screens/releases.d.ts +7 -0
- package/dist/adapters/admin/screens/releases.js +287 -0
- package/dist/adapters/admin/screens/search.d.ts +22 -0
- package/dist/adapters/admin/screens/search.js +113 -0
- package/dist/adapters/admin/screens/security.d.ts +4 -0
- package/dist/adapters/admin/screens/security.js +85 -0
- package/dist/adapters/admin/screens/users.d.ts +4 -0
- package/dist/adapters/admin/screens/users.js +330 -0
- package/dist/adapters/admin/theme.d.ts +1 -0
- package/dist/adapters/admin/theme.js +1 -0
- package/dist/adapters/admin/translations.d.ts +16 -0
- package/dist/adapters/admin/translations.js +23 -0
- package/dist/adapters/admin/upload.d.ts +8 -0
- package/dist/adapters/admin/upload.js +116 -0
- package/dist/adapters/admin/views/data-table.d.ts +82 -0
- package/dist/adapters/admin/views/data-table.js +117 -0
- package/dist/adapters/admin/views/icons.d.ts +48 -0
- package/dist/adapters/admin/views/icons.js +47 -0
- package/dist/adapters/admin/views/layout.d.ts +51 -0
- package/dist/adapters/admin/views/layout.js +145 -0
- package/dist/adapters/admin/views/sheet.d.ts +15 -0
- package/dist/adapters/admin/views/sheet.js +6 -0
- package/dist/adapters/admin/views/status.d.ts +32 -0
- package/dist/adapters/admin/views/status.js +74 -0
- package/dist/adapters/auth/handler.d.ts +10 -0
- package/dist/adapters/auth/handler.js +63 -0
- package/dist/adapters/auth/request.d.ts +8 -0
- package/dist/adapters/auth/request.js +14 -0
- package/dist/adapters/cli/bin.d.ts +2 -0
- package/dist/adapters/cli/bin.js +42 -0
- package/dist/adapters/cli/main.d.ts +7 -0
- package/dist/adapters/cli/main.js +982 -0
- package/dist/adapters/cli/remote.d.ts +52 -0
- package/dist/adapters/cli/remote.js +161 -0
- package/dist/adapters/mcp/agent-refs.d.ts +9 -0
- package/dist/adapters/mcp/agent-refs.js +25 -0
- package/dist/adapters/mcp/documents.d.ts +15 -0
- package/dist/adapters/mcp/documents.js +26 -0
- package/dist/adapters/mcp/fetch-url.d.ts +19 -0
- package/dist/adapters/mcp/fetch-url.js +244 -0
- package/dist/adapters/mcp/request-state.d.ts +15 -0
- package/dist/adapters/mcp/request-state.js +38 -0
- package/dist/adapters/mcp/results.d.ts +20 -0
- package/dist/adapters/mcp/results.js +61 -0
- package/dist/adapters/mcp/route.d.ts +34 -0
- package/dist/adapters/mcp/route.js +52 -0
- package/dist/adapters/mcp/server.d.ts +44 -0
- package/dist/adapters/mcp/server.js +49 -0
- package/dist/adapters/mcp/tools/history.d.ts +5 -0
- package/dist/adapters/mcp/tools/history.js +84 -0
- package/dist/adapters/mcp/tools/media.d.ts +5 -0
- package/dist/adapters/mcp/tools/media.js +102 -0
- package/dist/adapters/mcp/tools/publish.d.ts +5 -0
- package/dist/adapters/mcp/tools/publish.js +157 -0
- package/dist/adapters/mcp/tools/read.d.ts +5 -0
- package/dist/adapters/mcp/tools/read.js +279 -0
- package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
- package/dist/adapters/mcp/tools/redirects.js +74 -0
- package/dist/adapters/mcp/tools/write.d.ts +5 -0
- package/dist/adapters/mcp/tools/write.js +304 -0
- package/dist/adapters/site/backup-schedule.d.ts +8 -0
- package/dist/adapters/site/backup-schedule.js +31 -0
- package/dist/adapters/site/cache.d.ts +29 -0
- package/dist/adapters/site/cache.js +63 -0
- package/dist/adapters/site/context.d.ts +29 -0
- package/dist/adapters/site/context.js +278 -0
- package/dist/adapters/site/head.d.ts +23 -0
- package/dist/adapters/site/head.js +44 -0
- package/dist/adapters/site/limiter.d.ts +17 -0
- package/dist/adapters/site/limiter.js +39 -0
- package/dist/adapters/site/lock.d.ts +30 -0
- package/dist/adapters/site/lock.js +143 -0
- package/dist/adapters/site/media-routes.d.ts +4 -0
- package/dist/adapters/site/media-routes.js +55 -0
- package/dist/adapters/site/plugin.d.ts +122 -0
- package/dist/adapters/site/plugin.js +436 -0
- package/dist/adapters/site/preview.d.ts +36 -0
- package/dist/adapters/site/preview.js +82 -0
- package/dist/adapters/site/public.d.ts +6 -0
- package/dist/adapters/site/public.js +87 -0
- package/dist/adapters/site/render.d.ts +45 -0
- package/dist/adapters/site/render.js +191 -0
- package/dist/adapters/site/routes.d.ts +17 -0
- package/dist/adapters/site/routes.js +125 -0
- package/dist/adapters/site/sitemap.d.ts +10 -0
- package/dist/adapters/site/sitemap.js +10 -0
- package/dist/adapters/web.d.ts +22 -0
- package/dist/adapters/web.js +75 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +58 -0
- package/dist/core/agent/format.d.ts +62 -0
- package/dist/core/agent/format.js +211 -0
- package/dist/core/agent/schema.d.ts +6 -0
- package/dist/core/agent/schema.js +86 -0
- package/dist/core/archive.d.ts +12 -0
- package/dist/core/archive.js +72 -0
- package/dist/core/auth/auth.d.ts +4911 -0
- package/dist/core/auth/auth.js +61 -0
- package/dist/core/auth/roles.d.ts +10 -0
- package/dist/core/auth/roles.js +38 -0
- package/dist/core/auth/service.d.ts +118 -0
- package/dist/core/auth/service.js +424 -0
- package/dist/core/auth/upload-token.d.ts +8 -0
- package/dist/core/auth/upload-token.js +27 -0
- package/dist/core/backup/backup.d.ts +28 -0
- package/dist/core/backup/backup.js +126 -0
- package/dist/core/backup/restore.d.ts +41 -0
- package/dist/core/backup/restore.js +264 -0
- package/dist/core/backup/schedule.d.ts +12 -0
- package/dist/core/backup/schedule.js +29 -0
- package/dist/core/boot.d.ts +63 -0
- package/dist/core/boot.js +141 -0
- package/dist/core/check.d.ts +32 -0
- package/dist/core/check.js +111 -0
- package/dist/core/content/activity.d.ts +8 -0
- package/dist/core/content/activity.js +101 -0
- package/dist/core/content/delete.d.ts +5 -0
- package/dist/core/content/delete.js +100 -0
- package/dist/core/content/diff.d.ts +6 -0
- package/dist/core/content/diff.js +129 -0
- package/dist/core/content/dry-run.d.ts +24 -0
- package/dist/core/content/dry-run.js +69 -0
- package/dist/core/content/gaps.d.ts +25 -0
- package/dist/core/content/gaps.js +50 -0
- package/dist/core/content/hidden.d.ts +33 -0
- package/dist/core/content/hidden.js +103 -0
- package/dist/core/content/history.d.ts +15 -0
- package/dist/core/content/history.js +62 -0
- package/dist/core/content/patch.d.ts +40 -0
- package/dist/core/content/patch.js +287 -0
- package/dist/core/content/path.d.ts +6 -0
- package/dist/core/content/path.js +38 -0
- package/dist/core/content/publish.d.ts +26 -0
- package/dist/core/content/publish.js +211 -0
- package/dist/core/content/read.d.ts +99 -0
- package/dist/core/content/read.js +141 -0
- package/dist/core/content/reader.d.ts +37 -0
- package/dist/core/content/reader.js +195 -0
- package/dist/core/content/refs.d.ts +44 -0
- package/dist/core/content/refs.js +161 -0
- package/dist/core/content/release-migrations.d.ts +12 -0
- package/dist/core/content/release-migrations.js +154 -0
- package/dist/core/content/save.d.ts +25 -0
- package/dist/core/content/save.js +87 -0
- package/dist/core/content/schema.d.ts +22 -0
- package/dist/core/content/schema.js +127 -0
- package/dist/core/content/search.d.ts +8 -0
- package/dist/core/content/search.js +89 -0
- package/dist/core/content/shipped-input.d.ts +39 -0
- package/dist/core/content/shipped-input.js +221 -0
- package/dist/core/content/shipped.d.ts +112 -0
- package/dist/core/content/shipped.js +437 -0
- package/dist/core/content/slug.d.ts +23 -0
- package/dist/core/content/slug.js +182 -0
- package/dist/core/content/stats.d.ts +11 -0
- package/dist/core/content/stats.js +30 -0
- package/dist/core/content/translate.d.ts +3 -0
- package/dist/core/content/translate.js +68 -0
- package/dist/core/content/usages.d.ts +13 -0
- package/dist/core/content/usages.js +70 -0
- package/dist/core/content/validate.d.ts +21 -0
- package/dist/core/content/validate.js +124 -0
- package/dist/core/content/write.d.ts +10 -0
- package/dist/core/content/write.js +93 -0
- package/dist/core/core.d.ts +227 -0
- package/dist/core/core.js +251 -0
- package/dist/core/db/connection.d.ts +6 -0
- package/dist/core/db/connection.js +12 -0
- package/dist/core/db/migrate.d.ts +9 -0
- package/dist/core/db/migrate.js +42 -0
- package/dist/core/db/migrations/0001_content.d.ts +2 -0
- package/dist/core/db/migrations/0001_content.js +69 -0
- package/dist/core/db/migrations/0002_media.d.ts +2 -0
- package/dist/core/db/migrations/0002_media.js +26 -0
- package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
- package/dist/core/db/migrations/0003_redirects.js +19 -0
- package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
- package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
- package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
- package/dist/core/db/migrations/0005_site_lock.js +10 -0
- package/dist/core/db/migrations/0006_releases.d.ts +3 -0
- package/dist/core/db/migrations/0006_releases.js +34 -0
- package/dist/core/db/schema.d.ts +155 -0
- package/dist/core/db/schema.js +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +15 -0
- package/dist/core/export/export.d.ts +17 -0
- package/dist/core/export/export.js +185 -0
- package/dist/core/export/format.d.ts +241 -0
- package/dist/core/export/format.js +106 -0
- package/dist/core/export/import.d.ts +54 -0
- package/dist/core/export/import.js +180 -0
- package/dist/core/export/read.d.ts +16 -0
- package/dist/core/export/read.js +234 -0
- package/dist/core/export/replace.d.ts +17 -0
- package/dist/core/export/replace.js +36 -0
- package/dist/core/export/report.d.ts +55 -0
- package/dist/core/export/report.js +50 -0
- package/dist/core/export/schema.d.ts +8 -0
- package/dist/core/export/schema.js +47 -0
- package/dist/core/export/stage.d.ts +25 -0
- package/dist/core/export/stage.js +192 -0
- package/dist/core/fields/builtins.d.ts +70 -0
- package/dist/core/fields/builtins.js +335 -0
- package/dist/core/fields/define.d.ts +86 -0
- package/dist/core/fields/define.js +34 -0
- package/dist/core/fields/walk.d.ts +49 -0
- package/dist/core/fields/walk.js +270 -0
- package/dist/core/fields/widgets.d.ts +27 -0
- package/dist/core/fields/widgets.js +330 -0
- package/dist/core/fields/zod-internals.d.ts +29 -0
- package/dist/core/fields/zod-internals.js +28 -0
- package/dist/core/media/detect.d.ts +5 -0
- package/dist/core/media/detect.js +66 -0
- package/dist/core/media/labels.d.ts +6 -0
- package/dist/core/media/labels.js +17 -0
- package/dist/core/media/library.d.ts +45 -0
- package/dist/core/media/library.js +239 -0
- package/dist/core/media/store.d.ts +11 -0
- package/dist/core/media/store.js +49 -0
- package/dist/core/media/variants.d.ts +10 -0
- package/dist/core/media/variants.js +59 -0
- package/dist/core/messages/en.d.ts +1278 -0
- package/dist/core/messages/en.js +1287 -0
- package/dist/core/messages/index.d.ts +7 -0
- package/dist/core/messages/index.js +14 -0
- package/dist/core/preview.d.ts +16 -0
- package/dist/core/preview.js +42 -0
- package/dist/core/redirects/collapse.d.ts +68 -0
- package/dist/core/redirects/collapse.js +153 -0
- package/dist/core/redirects/csv.d.ts +15 -0
- package/dist/core/redirects/csv.js +68 -0
- package/dist/core/redirects/redirects.d.ts +58 -0
- package/dist/core/redirects/redirects.js +545 -0
- package/dist/core/registry/content.d.ts +26 -0
- package/dist/core/registry/content.js +9 -0
- package/dist/core/registry/define.d.ts +145 -0
- package/dist/core/registry/define.js +41 -0
- package/dist/core/registry/migration.d.ts +44 -0
- package/dist/core/registry/migration.js +4 -0
- package/dist/core/registry/registry.d.ts +18 -0
- package/dist/core/registry/registry.js +255 -0
- package/dist/core/registry/render.d.ts +98 -0
- package/dist/core/registry/render.js +1 -0
- package/dist/core/registry/route.d.ts +42 -0
- package/dist/core/registry/route.js +3 -0
- package/dist/core/release/bundle.d.ts +21 -0
- package/dist/core/release/bundle.js +252 -0
- package/dist/core/release/keys.d.ts +11 -0
- package/dist/core/release/keys.js +60 -0
- package/dist/core/release/manifest.d.ts +103 -0
- package/dist/core/release/manifest.js +138 -0
- package/dist/core/release/pack.d.ts +20 -0
- package/dist/core/release/pack.js +97 -0
- package/dist/core/release/pointer.d.ts +19 -0
- package/dist/core/release/pointer.js +53 -0
- package/dist/core/release/read.d.ts +59 -0
- package/dist/core/release/read.js +256 -0
- package/dist/core/report.d.ts +31 -0
- package/dist/core/report.js +37 -0
- package/dist/core/richtext/html.d.ts +15 -0
- package/dist/core/richtext/html.js +81 -0
- package/dist/core/richtext/markdown.d.ts +19 -0
- package/dist/core/richtext/markdown.js +951 -0
- package/dist/core/richtext/schema.d.ts +98 -0
- package/dist/core/richtext/schema.js +275 -0
- package/dist/core/site/live.d.ts +56 -0
- package/dist/core/site/live.js +145 -0
- package/dist/core/site/paths.d.ts +15 -0
- package/dist/core/site/paths.js +64 -0
- package/dist/core/site/resolve.d.ts +9 -0
- package/dist/core/site/resolve.js +202 -0
- package/dist/core/site/sitemap.d.ts +11 -0
- package/dist/core/site/sitemap.js +24 -0
- package/dist/core/site-lock/site-lock.d.ts +21 -0
- package/dist/core/site-lock/site-lock.js +65 -0
- package/dist/core/site-lock/token.d.ts +7 -0
- package/dist/core/site-lock/token.js +24 -0
- package/dist/core/theme.d.ts +22 -0
- package/dist/core/theme.js +133 -0
- package/dist/core/types.d.ts +253 -0
- package/dist/core/types.js +1 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +5 -0
- package/dist/host/activate.d.ts +53 -0
- package/dist/host/activate.js +162 -0
- package/dist/host/app.d.ts +46 -0
- package/dist/host/app.js +129 -0
- package/dist/host/bin.d.ts +5 -0
- package/dist/host/bin.js +8 -0
- package/dist/host/config.d.ts +36 -0
- package/dist/host/config.js +152 -0
- package/dist/host/dev.d.ts +10 -0
- package/dist/host/dev.js +293 -0
- package/dist/host/diff.d.ts +78 -0
- package/dist/host/diff.js +346 -0
- package/dist/host/hooks.d.ts +41 -0
- package/dist/host/hooks.js +49 -0
- package/dist/host/ipc.d.ts +123 -0
- package/dist/host/ipc.js +61 -0
- package/dist/host/preview-proxy.d.ts +24 -0
- package/dist/host/preview-proxy.js +154 -0
- package/dist/host/preview-worker.d.ts +42 -0
- package/dist/host/preview-worker.js +242 -0
- package/dist/host/primary.d.ts +38 -0
- package/dist/host/primary.js +357 -0
- package/dist/host/push.d.ts +125 -0
- package/dist/host/push.js +420 -0
- package/dist/host/serve.d.ts +16 -0
- package/dist/host/serve.js +150 -0
- package/dist/host/store.d.ts +48 -0
- package/dist/host/store.js +109 -0
- package/dist/host/worker.d.ts +67 -0
- package/dist/host/worker.js +310 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +32 -0
- package/dist/jsx/html.d.ts +16 -0
- package/dist/jsx/html.js +65 -0
- package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
- package/dist/jsx/jsx-dev-runtime.js +5 -0
- package/dist/jsx/jsx-runtime.d.ts +17 -0
- package/dist/jsx/jsx-runtime.js +41 -0
- package/dist/site.d.ts +17 -0
- package/dist/site.js +14 -0
- package/package.json +111 -3
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { basename, isAbsolute } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { InlayError } from '../errors.js';
|
|
5
|
+
import { fieldValues } from '../fields/walk.js';
|
|
6
|
+
import { isRecord } from '../fields/zod-internals.js';
|
|
7
|
+
import { inspectUpload } from '../media/library.js';
|
|
8
|
+
import { markdownToRichText } from '../richtext/markdown.js';
|
|
9
|
+
import { docLabels } from './schema.js';
|
|
10
|
+
import { contentIssue } from './validate.js';
|
|
11
|
+
const KINDS = new Set(['image', 'file', 'richText', 'ref', 'link']);
|
|
12
|
+
/** The start of a Markdown link target `](inlay:key/<type>` or `](inlay:key/<type>/<key>`; text elsewhere is left alone. */
|
|
13
|
+
const KEY_HREF = /\]\(inlay:key\/([\w-]+)(?:\/([\w-]+))?(?=[\s)])/g;
|
|
14
|
+
/** `root` with the value at `path` replaced, copying only the containers along the path. */
|
|
15
|
+
function setAt(root, path, value) {
|
|
16
|
+
const [head, ...rest] = path;
|
|
17
|
+
if (head === undefined)
|
|
18
|
+
return value;
|
|
19
|
+
if (Array.isArray(root)) {
|
|
20
|
+
const copy = [...root];
|
|
21
|
+
copy[head] = setAt(copy[head], rest, value);
|
|
22
|
+
return copy;
|
|
23
|
+
}
|
|
24
|
+
const record = isRecord(root) ? root : {};
|
|
25
|
+
return { ...record, [head]: setAt(record[head], rest, value) };
|
|
26
|
+
}
|
|
27
|
+
/** The source a `file` value is written as: a URL's href, or the string itself. */
|
|
28
|
+
function fileSource(file) {
|
|
29
|
+
if (file instanceof URL)
|
|
30
|
+
return file.href;
|
|
31
|
+
return typeof file === 'string' ? file : null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The absolute path a `file` value names, or null if it isn't an absolute path or a file: URL. A source in
|
|
35
|
+
* `shipped` (a loaded release's copies of its files) is read from where the release put it.
|
|
36
|
+
*/
|
|
37
|
+
function localPath(file, shipped) {
|
|
38
|
+
const source = fileSource(file);
|
|
39
|
+
const mapped = source === null ? undefined : shipped?.get(source);
|
|
40
|
+
if (mapped !== undefined)
|
|
41
|
+
return mapped;
|
|
42
|
+
try {
|
|
43
|
+
if (file instanceof URL)
|
|
44
|
+
return file.protocol === 'file:' ? fileURLToPath(file) : null;
|
|
45
|
+
if (typeof file !== 'string')
|
|
46
|
+
return null;
|
|
47
|
+
if (file.startsWith('file:'))
|
|
48
|
+
return fileURLToPath(file);
|
|
49
|
+
return isAbsolute(file) ? file : null;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Shipped content can't contain images in rich text: there is no way to name their files. */
|
|
56
|
+
function withoutImages(opts) {
|
|
57
|
+
return opts && { ...opts, features: opts.features.filter((f) => f !== 'image') };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Turns shipped content as a developer writes it into the stored shape:
|
|
61
|
+
* Markdown strings in rich text fields become rich text, and `{ file, alt? }`
|
|
62
|
+
* in image and file fields is read from disk, checked like an upload, and
|
|
63
|
+
* replaced by `{ media, alt? }`. References to other shipped documents by key
|
|
64
|
+
* become their group ids: `{ key }` in `ref` fields, `{ document: { type, key? } }`
|
|
65
|
+
* in `link` fields and `inlay:key/<type>[/<key>]` links in Markdown. Covers the
|
|
66
|
+
* template fields and every slot that isn't switched off. Returns the files to
|
|
67
|
+
* import and any problems.
|
|
68
|
+
*/
|
|
69
|
+
export async function resolveShippedInput(deps, type, input, resolveKey) {
|
|
70
|
+
const { template } = deps.registry.getType(type);
|
|
71
|
+
const files = new Map();
|
|
72
|
+
const issues = [];
|
|
73
|
+
const issue = (path, code, messageId, params = {}) => {
|
|
74
|
+
issues.push(contentIssue(path, docLabels(deps.registry, type, path) ?? path.map(String), code, messageId, params));
|
|
75
|
+
};
|
|
76
|
+
/** The group id `ref` names, or null after reporting it at `path`. */
|
|
77
|
+
const groupOf = (path, ref) => {
|
|
78
|
+
const id = resolveKey(ref);
|
|
79
|
+
if (id === null)
|
|
80
|
+
issue(path, 'not_found', 'issue.shippedKeyUnknown', { type: ref.type, key: ref.key ?? ref.type });
|
|
81
|
+
return id;
|
|
82
|
+
};
|
|
83
|
+
/** A `ref` field's `{ key }`, as a group id; anything else is left as it is. */
|
|
84
|
+
const refValue = (path, target, value) => {
|
|
85
|
+
if (!isRecord(value) || typeof value.key !== 'string')
|
|
86
|
+
return value;
|
|
87
|
+
return groupOf(path, { type: target, key: value.key }) ?? value;
|
|
88
|
+
};
|
|
89
|
+
/** The stored value for one found value, or `undefined` to leave it as it is. */
|
|
90
|
+
const resolve = async (path, meta, value) => {
|
|
91
|
+
if (meta.kind === 'ref') {
|
|
92
|
+
const target = meta.target ?? '';
|
|
93
|
+
if (Array.isArray(value))
|
|
94
|
+
return value.map((item, i) => refValue([...path, i], target, item));
|
|
95
|
+
return refValue(path, target, value);
|
|
96
|
+
}
|
|
97
|
+
if (meta.kind === 'link') {
|
|
98
|
+
if (!isRecord(value) || !isRecord(value.document) || typeof value.document.type !== 'string')
|
|
99
|
+
return undefined;
|
|
100
|
+
const ref = { type: value.document.type };
|
|
101
|
+
if (typeof value.document.key === 'string')
|
|
102
|
+
ref.key = value.document.key;
|
|
103
|
+
const id = groupOf(path, ref);
|
|
104
|
+
return id === null ? undefined : { ...value, document: id };
|
|
105
|
+
}
|
|
106
|
+
if (meta.kind === 'richText') {
|
|
107
|
+
if (typeof value !== 'string')
|
|
108
|
+
return undefined;
|
|
109
|
+
let unknownKey = false;
|
|
110
|
+
const markdown = value.replace(KEY_HREF, (href, refType, key) => {
|
|
111
|
+
const id = groupOf(path, key === undefined ? { type: refType } : { type: refType, key });
|
|
112
|
+
if (id === null)
|
|
113
|
+
unknownKey = true;
|
|
114
|
+
return id === null ? href : `](inlay:document/${id}`;
|
|
115
|
+
});
|
|
116
|
+
if (unknownKey)
|
|
117
|
+
return undefined;
|
|
118
|
+
const result = markdownToRichText(markdown, meta.richText);
|
|
119
|
+
for (const problem of result.ok ? [] : result.problems) {
|
|
120
|
+
issue(path, 'invalid', 'issue.richText', { problem: problem.message });
|
|
121
|
+
}
|
|
122
|
+
// What only the image-free reading finds are images the field allows but shipped content can't name.
|
|
123
|
+
const bare = markdownToRichText(markdown, withoutImages(meta.richText));
|
|
124
|
+
const known = new Set(result.ok ? [] : result.problems.map((p) => p.message));
|
|
125
|
+
const images = bare.ok ? [] : bare.problems.filter((p) => !known.has(p.message));
|
|
126
|
+
for (const image of images)
|
|
127
|
+
issue(path, 'invalid', 'issue.shippedRichTextImage', { line: String(image.line) });
|
|
128
|
+
return result.ok && images.length === 0 ? result.doc : undefined;
|
|
129
|
+
}
|
|
130
|
+
if (!isRecord(value) || !Object.hasOwn(value, 'file'))
|
|
131
|
+
return undefined;
|
|
132
|
+
const source = fileSource(value.file);
|
|
133
|
+
if (deps.shippedFiles && (source === null || !deps.shippedFiles.has(source))) {
|
|
134
|
+
issue(path, 'not_found', 'issue.shippedFileUnknown', { path: String(source ?? value.file) });
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
const file = localPath(value.file, deps.shippedFiles);
|
|
138
|
+
if (file === null) {
|
|
139
|
+
issue(path, 'invalid', 'issue.shippedFilePath', { path: String(value.file) });
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
let bytes;
|
|
143
|
+
try {
|
|
144
|
+
bytes = await readFile(file);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
issue(path, 'not_found', 'issue.shippedFileMissing', { path: file });
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const info = await inspectUpload(deps, bytes, basename(file));
|
|
152
|
+
files.set(info.id, { bytes, ...info });
|
|
153
|
+
return meta.kind === 'image' && value.alt !== undefined ? { media: info.id, alt: value.alt } : { media: info.id };
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
if (!(e instanceof InlayError) || e.code !== 'validation')
|
|
157
|
+
throw e;
|
|
158
|
+
issue(path, 'invalid', 'issue.shippedFileInvalid', { problem: e.message });
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const resolveAll = async (schema, value, prefix) => {
|
|
163
|
+
let out = value;
|
|
164
|
+
for (const found of fieldValues(schema, value, KINDS)) {
|
|
165
|
+
const next = await resolve([...prefix, ...found.path], found.meta, found.value);
|
|
166
|
+
if (next !== undefined)
|
|
167
|
+
out = setAt(out, found.path, next);
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
};
|
|
171
|
+
const out = { ...input };
|
|
172
|
+
if (input.fields !== undefined) {
|
|
173
|
+
out.fields = (await resolveAll(template.fields, input.fields, ['fields']));
|
|
174
|
+
}
|
|
175
|
+
if (input.slots !== undefined) {
|
|
176
|
+
const slots = {};
|
|
177
|
+
for (const [key, given] of Object.entries(input.slots)) {
|
|
178
|
+
const slot = template.slots[key];
|
|
179
|
+
slots[key] =
|
|
180
|
+
given === false || !slot
|
|
181
|
+
? given
|
|
182
|
+
: (await resolveAll(slot.block.schema, given, ['slots', key, 'data']));
|
|
183
|
+
}
|
|
184
|
+
out.slots = slots;
|
|
185
|
+
}
|
|
186
|
+
return { input: out, files, issues };
|
|
187
|
+
}
|
|
188
|
+
const FILE_KINDS = new Set(['image', 'file']);
|
|
189
|
+
/**
|
|
190
|
+
* Every `{ file }` named in the registry's shipped content (template fields and slots), once per source: the
|
|
191
|
+
* source as written (a file: URL's href or an absolute path) and the local path it names. Values that don't name
|
|
192
|
+
* a local file are left out; applying the content reports them.
|
|
193
|
+
*/
|
|
194
|
+
export function shippedFiles(registry) {
|
|
195
|
+
const found = new Map();
|
|
196
|
+
const collect = (schema, value) => {
|
|
197
|
+
for (const { value: v } of fieldValues(schema, value, FILE_KINDS)) {
|
|
198
|
+
if (!isRecord(v) || !Object.hasOwn(v, 'file'))
|
|
199
|
+
continue;
|
|
200
|
+
const source = fileSource(v.file);
|
|
201
|
+
const path = localPath(v.file);
|
|
202
|
+
if (source !== null && path !== null)
|
|
203
|
+
found.set(source, path);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
for (const [type, documents] of registry.content) {
|
|
207
|
+
const { template } = registry.getType(type);
|
|
208
|
+
for (const doc of documents) {
|
|
209
|
+
for (const input of Object.values(doc.content)) {
|
|
210
|
+
if (input.fields !== undefined)
|
|
211
|
+
collect(template.fields, input.fields);
|
|
212
|
+
for (const [key, given] of Object.entries(input.slots ?? {})) {
|
|
213
|
+
const slot = template.slots[key];
|
|
214
|
+
if (given !== false && slot)
|
|
215
|
+
collect(slot.block.schema, given);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return [...found].map(([source, path]) => ({ source, path }));
|
|
221
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Selectable } from 'kysely';
|
|
2
|
+
import type { DocumentsTable } from '../db/schema.js';
|
|
3
|
+
import type { CoreDeps, Ctx, DocumentData, DocumentKind } from '../types.js';
|
|
4
|
+
import { type PendingFile } from './shipped-input.js';
|
|
5
|
+
/** One shipped document in one locale. `documentId` is null for a document a dry run would create. */
|
|
6
|
+
export interface ShippedItem {
|
|
7
|
+
documentId: string | null;
|
|
8
|
+
type: string;
|
|
9
|
+
key: string;
|
|
10
|
+
locale: string;
|
|
11
|
+
edition: number;
|
|
12
|
+
}
|
|
13
|
+
/** What applying shipped content did, or would do in a dry run. Each list is sorted by type, key and locale. */
|
|
14
|
+
export interface ShippedReport {
|
|
15
|
+
created: ShippedItem[];
|
|
16
|
+
replaced: ShippedItem[];
|
|
17
|
+
skipped: ShippedItem[];
|
|
18
|
+
/** References to entries the client deleted, left out of the shipped content written. `field` is the field's label path. */
|
|
19
|
+
deletedRefs: Array<{
|
|
20
|
+
item: ShippedItem;
|
|
21
|
+
target: {
|
|
22
|
+
type: string;
|
|
23
|
+
key: string;
|
|
24
|
+
};
|
|
25
|
+
field: string;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* A slug or path the shipped content asks for that is already taken, and what was done instead: another slug,
|
|
29
|
+
* the path the document had, or no path. `inlaycms check` reports each as a problem; activation goes ahead.
|
|
30
|
+
*/
|
|
31
|
+
warnings: Array<{
|
|
32
|
+
item: ShippedItem;
|
|
33
|
+
message: string;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* What to do with one shipped document in one locale: `create` it, `replace`
|
|
38
|
+
* the stored row, `skip` it (the client deleted its group), or nothing,
|
|
39
|
+
* since it's `current` (the stored edition is equal or higher).
|
|
40
|
+
*/
|
|
41
|
+
export interface ShippedAction {
|
|
42
|
+
mode: 'create' | 'replace' | 'skip' | 'current';
|
|
43
|
+
/** For a create, `documentId` is the id the document gets. */
|
|
44
|
+
item: ShippedItem;
|
|
45
|
+
kind: DocumentKind;
|
|
46
|
+
groupId: string;
|
|
47
|
+
/** The stored row, or null when there is none. */
|
|
48
|
+
row: Selectable<DocumentsTable> | null;
|
|
49
|
+
/**
|
|
50
|
+
* The data a create or replace writes: resolved, validated, with references
|
|
51
|
+
* to deleted entries removed and, for a replace, the head's unknown keys
|
|
52
|
+
* carried. For a skip or current action, the validated data with
|
|
53
|
+
* `validateAll`, else null.
|
|
54
|
+
*/
|
|
55
|
+
data: DocumentData | null;
|
|
56
|
+
/** Files the shipped content names, to import. */
|
|
57
|
+
files: Map<string, PendingFile>;
|
|
58
|
+
}
|
|
59
|
+
/** Every shipped document and locale with what to do with it, in report order, and the deleted references left out. */
|
|
60
|
+
export interface ShippedPlan {
|
|
61
|
+
actions: ShippedAction[];
|
|
62
|
+
deletedRefs: ShippedReport['deletedRefs'];
|
|
63
|
+
warnings: ShippedReport['warnings'];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Works out what applying the site's shipped content (spec §6.3) would do,
|
|
67
|
+
* per shipped document and locale: a missing row is created; a row whose
|
|
68
|
+
* edition is lower (or null) is replaced; an equal or higher edition is
|
|
69
|
+
* current; a group the client deleted is skipped. Every create and replace
|
|
70
|
+
* is resolved and checked (with `validateAll`, every shipped document and
|
|
71
|
+
* locale, which changes nothing else); the first problem throws
|
|
72
|
+
* `shipped_content`. A slug or path already taken isn't a problem: the
|
|
73
|
+
* document keeps its stored slug and path (a new one gets a free slug and no path),
|
|
74
|
+
* and a warning says so. Writes nothing. Run it in the transaction that writes
|
|
75
|
+
* the plan, so nothing changes in between.
|
|
76
|
+
*/
|
|
77
|
+
export declare function planShippedContent(deps: CoreDeps, opts?: {
|
|
78
|
+
validateAll?: boolean;
|
|
79
|
+
}): Promise<ShippedPlan>;
|
|
80
|
+
/**
|
|
81
|
+
* Puts the files a plan's creates and replaces name in the media store, telling `onFileStored` of each first. Run
|
|
82
|
+
* it before the transaction that writes the plan opens, so that transaction holds the write lock for database
|
|
83
|
+
* writes only: `writeShippedContent` then finds the files stored. Files are named by their content, so storing one
|
|
84
|
+
* that is never written to the database harms nothing (a caller removes those after a failure).
|
|
85
|
+
*/
|
|
86
|
+
export declare function storeShippedFiles(deps: CoreDeps, plan: ShippedPlan, onFileStored?: (fileId: string) => void): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Writes a plan from `planShippedContent`: imports the files, creates and
|
|
89
|
+
* replaces the documents and publishes them, as one publish event. `deps.db`
|
|
90
|
+
* should be the transaction the plan was made in. With `dryRun`, no file is
|
|
91
|
+
* stored and created documents are reported without their ids; rolling back
|
|
92
|
+
* is the caller's. Revisions and the publish event are written with `ctx`
|
|
93
|
+
* (default: the system acting as `release`, without a release id).
|
|
94
|
+
* `onFileStored` hears of each file put in the media store before its row is
|
|
95
|
+
* written, so a caller that rolls back can remove the files no row names. A
|
|
96
|
+
* file already stored (see `storeShippedFiles`) isn't written again.
|
|
97
|
+
*/
|
|
98
|
+
export declare function writeShippedContent(deps: CoreDeps, plan: ShippedPlan, opts?: {
|
|
99
|
+
dryRun?: boolean;
|
|
100
|
+
ctx?: Ctx;
|
|
101
|
+
onFileStored?: (fileId: string) => void;
|
|
102
|
+
}): Promise<ShippedReport>;
|
|
103
|
+
/**
|
|
104
|
+
* Applies the site's shipped content (spec §6.3): plans and writes it in one
|
|
105
|
+
* transaction, so a problem writes nothing. With `dryRun`, reports what it
|
|
106
|
+
* would do and rolls back. `validateAll` checks every shipped document, not
|
|
107
|
+
* only what's written.
|
|
108
|
+
*/
|
|
109
|
+
export declare function applyShippedContent(deps: CoreDeps, opts?: {
|
|
110
|
+
dryRun?: boolean;
|
|
111
|
+
validateAll?: boolean;
|
|
112
|
+
}): Promise<ShippedReport>;
|