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,145 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { Renderable, SafeHtml } from '../../jsx/html.js';
|
|
3
|
+
import type { AdminTheme } from '../types.js';
|
|
4
|
+
import type { ShippedContent } from './content.js';
|
|
5
|
+
import type { ReleaseMigration } from './migration.js';
|
|
6
|
+
import type { PageInfo, RenderContext } from './render.js';
|
|
7
|
+
import type { RouteDef } from './route.js';
|
|
8
|
+
export interface BlockDef<S extends z.ZodObject = z.ZodObject> {
|
|
9
|
+
kind: 'block';
|
|
10
|
+
name: string;
|
|
11
|
+
label: string;
|
|
12
|
+
help?: string;
|
|
13
|
+
schema: S;
|
|
14
|
+
/** Receives the slot's stored data. */
|
|
15
|
+
render?(props: z.output<S>, ctx: RenderContext): Renderable;
|
|
16
|
+
}
|
|
17
|
+
export interface BlockInput<S extends z.ZodObject> {
|
|
18
|
+
name: string;
|
|
19
|
+
label: string;
|
|
20
|
+
help?: string;
|
|
21
|
+
schema: S;
|
|
22
|
+
render?: (props: z.output<S>, ctx: RenderContext) => Renderable;
|
|
23
|
+
}
|
|
24
|
+
export declare function defineBlock<S extends z.ZodObject>(def: BlockInput<S>): BlockDef<S>;
|
|
25
|
+
export interface SlotDef {
|
|
26
|
+
block: BlockDef;
|
|
27
|
+
label?: string;
|
|
28
|
+
optional?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export type Slots = Record<string, SlotDef>;
|
|
31
|
+
export interface TemplateRenderProps<F extends z.ZodObject, S extends Slots> {
|
|
32
|
+
fields: z.output<F>;
|
|
33
|
+
/** Each slot's rendered block; `null` when an optional slot is off. */
|
|
34
|
+
slots: {
|
|
35
|
+
[K in keyof S]: SafeHtml | null;
|
|
36
|
+
};
|
|
37
|
+
/** Each slot's stored data; `null` when an optional slot is off. */
|
|
38
|
+
data: {
|
|
39
|
+
[K in keyof S]: z.output<S[K]['block']['schema']> | null;
|
|
40
|
+
};
|
|
41
|
+
page: PageInfo;
|
|
42
|
+
}
|
|
43
|
+
export interface TemplateDef<F extends z.ZodObject = z.ZodObject, S extends Slots = Slots> {
|
|
44
|
+
kind: 'template';
|
|
45
|
+
name: string;
|
|
46
|
+
label?: string;
|
|
47
|
+
fields: F;
|
|
48
|
+
/** Slot order is key order. */
|
|
49
|
+
slots: S;
|
|
50
|
+
render?(props: TemplateRenderProps<F, S>, ctx: RenderContext): Renderable;
|
|
51
|
+
}
|
|
52
|
+
export interface TemplateInput<F extends z.ZodObject, S extends Slots> {
|
|
53
|
+
name: string;
|
|
54
|
+
label?: string;
|
|
55
|
+
fields: F;
|
|
56
|
+
slots?: S;
|
|
57
|
+
render?: (props: TemplateRenderProps<F, S>, ctx: RenderContext) => Renderable;
|
|
58
|
+
}
|
|
59
|
+
export declare function defineTemplate<F extends z.ZodObject, S extends Slots = {}>(def: TemplateInput<F, S>): TemplateDef<F, S>;
|
|
60
|
+
export type SingletonPath = string | Record<string, string> | null;
|
|
61
|
+
export interface SingletonDef {
|
|
62
|
+
kind: 'singleton';
|
|
63
|
+
name: string;
|
|
64
|
+
label: string;
|
|
65
|
+
help?: string;
|
|
66
|
+
template: TemplateDef;
|
|
67
|
+
path: SingletonPath;
|
|
68
|
+
}
|
|
69
|
+
export declare function defineSingleton(def: Omit<SingletonDef, 'kind'>): SingletonDef;
|
|
70
|
+
export interface GlobalDef<T extends TemplateDef = TemplateDef> {
|
|
71
|
+
kind: 'global';
|
|
72
|
+
name: string;
|
|
73
|
+
label: string;
|
|
74
|
+
help?: string;
|
|
75
|
+
template: T;
|
|
76
|
+
}
|
|
77
|
+
export declare function defineGlobal<T extends TemplateDef>(def: Omit<GlobalDef<T>, 'kind'>): GlobalDef<T>;
|
|
78
|
+
export interface CollectionDef<T extends TemplateDef = TemplateDef> {
|
|
79
|
+
kind: 'collection';
|
|
80
|
+
name: string;
|
|
81
|
+
label: string;
|
|
82
|
+
help?: string;
|
|
83
|
+
template: T;
|
|
84
|
+
/** URL pattern containing `:slug`; `null` for a data collection. */
|
|
85
|
+
route: string | null;
|
|
86
|
+
customPaths: boolean;
|
|
87
|
+
titleField: string;
|
|
88
|
+
}
|
|
89
|
+
export interface CollectionInput<T extends TemplateDef = TemplateDef> {
|
|
90
|
+
name: string;
|
|
91
|
+
label: string;
|
|
92
|
+
help?: string;
|
|
93
|
+
template: T;
|
|
94
|
+
route?: string | null;
|
|
95
|
+
customPaths?: boolean;
|
|
96
|
+
titleField?: string;
|
|
97
|
+
}
|
|
98
|
+
export declare function defineCollection<T extends TemplateDef>(def: CollectionInput<T>): CollectionDef<T>;
|
|
99
|
+
export type TypeDef = SingletonDef | GlobalDef | CollectionDef;
|
|
100
|
+
export interface AdminSettings {
|
|
101
|
+
/** Shown in the admin's header; defaults to "Inlay". */
|
|
102
|
+
name?: string;
|
|
103
|
+
/** A URL path under `/public/`, such as `/public/logo.svg`, shown in place of the name. */
|
|
104
|
+
logo?: string;
|
|
105
|
+
/** A built-in daisyUI theme name, or colors laid over a base theme. */
|
|
106
|
+
theme?: AdminTheme;
|
|
107
|
+
}
|
|
108
|
+
export interface SiteDefinition {
|
|
109
|
+
locales: string[];
|
|
110
|
+
defaultLocale: string;
|
|
111
|
+
singletons: SingletonDef[];
|
|
112
|
+
collections: CollectionDef[];
|
|
113
|
+
globals: GlobalDef[];
|
|
114
|
+
/** Serve the default-locale page when a translation is missing (default `true`). */
|
|
115
|
+
translationFallback: boolean;
|
|
116
|
+
/** Content shipped with the site, activated by editions. */
|
|
117
|
+
content: ShippedContent[];
|
|
118
|
+
guide?: string;
|
|
119
|
+
admin: AdminSettings;
|
|
120
|
+
/** A singleton with `path: null`, rendered with status 404 when no page matches. */
|
|
121
|
+
notFound: string | null;
|
|
122
|
+
/** Exact paths that answer without the site password, such as a health check. */
|
|
123
|
+
publicPaths: string[];
|
|
124
|
+
/** Names of the secrets the host provides, such as `SLACK_WEBHOOK`. */
|
|
125
|
+
secrets: string[];
|
|
126
|
+
routes: RouteDef[];
|
|
127
|
+
migrations: ReleaseMigration[];
|
|
128
|
+
}
|
|
129
|
+
export interface SiteInput {
|
|
130
|
+
locales: string[];
|
|
131
|
+
defaultLocale: string;
|
|
132
|
+
singletons?: SingletonDef[];
|
|
133
|
+
collections?: CollectionDef[];
|
|
134
|
+
globals?: GlobalDef[];
|
|
135
|
+
translationFallback?: boolean;
|
|
136
|
+
content?: ShippedContent[];
|
|
137
|
+
guide?: string;
|
|
138
|
+
admin?: AdminSettings;
|
|
139
|
+
notFound?: string | null;
|
|
140
|
+
publicPaths?: string[];
|
|
141
|
+
secrets?: string[];
|
|
142
|
+
routes?: RouteDef[];
|
|
143
|
+
migrations?: ReleaseMigration[];
|
|
144
|
+
}
|
|
145
|
+
export declare function defineSite(def: SiteInput): SiteDefinition;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function defineBlock(def) {
|
|
2
|
+
return { ...def, kind: 'block' };
|
|
3
|
+
}
|
|
4
|
+
export function defineTemplate(def) {
|
|
5
|
+
return {
|
|
6
|
+
...def,
|
|
7
|
+
kind: 'template',
|
|
8
|
+
slots: def.slots ?? {},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function defineSingleton(def) {
|
|
12
|
+
return { ...def, kind: 'singleton' };
|
|
13
|
+
}
|
|
14
|
+
export function defineGlobal(def) {
|
|
15
|
+
return { ...def, kind: 'global' };
|
|
16
|
+
}
|
|
17
|
+
export function defineCollection(def) {
|
|
18
|
+
return {
|
|
19
|
+
...def,
|
|
20
|
+
kind: 'collection',
|
|
21
|
+
route: def.route ?? null,
|
|
22
|
+
customPaths: def.customPaths ?? false,
|
|
23
|
+
titleField: def.titleField ?? 'title',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function defineSite(def) {
|
|
27
|
+
return {
|
|
28
|
+
...def,
|
|
29
|
+
singletons: def.singletons ?? [],
|
|
30
|
+
collections: def.collections ?? [],
|
|
31
|
+
globals: def.globals ?? [],
|
|
32
|
+
translationFallback: def.translationFallback ?? true,
|
|
33
|
+
content: def.content ?? [],
|
|
34
|
+
admin: def.admin ?? {},
|
|
35
|
+
notFound: def.notFound ?? null,
|
|
36
|
+
publicPaths: def.publicPaths ?? [],
|
|
37
|
+
secrets: def.secrets ?? [],
|
|
38
|
+
routes: def.routes ?? [],
|
|
39
|
+
migrations: def.migrations ?? [],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ContentInput, DocumentData, MediaInfo } from '../types.js';
|
|
2
|
+
export interface MigrationDocument {
|
|
3
|
+
id: string;
|
|
4
|
+
groupId: string;
|
|
5
|
+
type: string;
|
|
6
|
+
locale: string;
|
|
7
|
+
slug: string | null;
|
|
8
|
+
key: string | null;
|
|
9
|
+
edition: number | null;
|
|
10
|
+
deleted: boolean;
|
|
11
|
+
/** The type or locale is not in the current site. */
|
|
12
|
+
hidden: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface MigrationContext {
|
|
15
|
+
/** Every type with documents, hidden ones included. */
|
|
16
|
+
types(): Promise<string[]>;
|
|
17
|
+
list(type: string, opts?: {
|
|
18
|
+
locale?: string;
|
|
19
|
+
includeDeleted?: boolean;
|
|
20
|
+
}): Promise<MigrationDocument[]>;
|
|
21
|
+
read(id: string): Promise<{
|
|
22
|
+
head: DocumentData | null;
|
|
23
|
+
published: DocumentData | null;
|
|
24
|
+
}>;
|
|
25
|
+
create(type: string, input: ContentInput & {
|
|
26
|
+
locale?: string;
|
|
27
|
+
key?: string;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
id: string;
|
|
30
|
+
groupId: string;
|
|
31
|
+
}>;
|
|
32
|
+
/** Writes `data` (the stored shape `read` returns) as the head draft. */
|
|
33
|
+
save(id: string, data: DocumentData): Promise<void>;
|
|
34
|
+
publish(ids: string[]): Promise<void>;
|
|
35
|
+
media: {
|
|
36
|
+
list(): Promise<MediaInfo[]>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export interface ReleaseMigration {
|
|
40
|
+
name: string;
|
|
41
|
+
run(ctx: MigrationContext): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/** A migration function: runs once per release, at activation (spec §8.3). */
|
|
44
|
+
export declare function defineMigration(def: ReleaseMigration): ReleaseMigration;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ShippedDocument } from './content.js';
|
|
2
|
+
import type { BlockDef, SiteDefinition, TemplateDef, TypeDef } from './define.js';
|
|
3
|
+
export interface Registry {
|
|
4
|
+
site: SiteDefinition;
|
|
5
|
+
locales: readonly string[];
|
|
6
|
+
defaultLocale: string;
|
|
7
|
+
types: ReadonlyMap<string, TypeDef>;
|
|
8
|
+
/** Every block used by any type, by name. */
|
|
9
|
+
blocks: ReadonlyMap<string, BlockDef>;
|
|
10
|
+
/** Every template used by any type, by name. */
|
|
11
|
+
templates: ReadonlyMap<string, TemplateDef>;
|
|
12
|
+
/** Shipped documents by type. */
|
|
13
|
+
content: ReadonlyMap<string, readonly ShippedDocument[]>;
|
|
14
|
+
/** Throws `InlayError('not_found')` for an unknown type. */
|
|
15
|
+
getType(name: string): TypeDef;
|
|
16
|
+
}
|
|
17
|
+
/** Checks a site definition and indexes its types. Throws `InlayError('definition')` naming the offender. */
|
|
18
|
+
export declare function buildRegistry(site: SiteDefinition): Registry;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { resolveTheme } from '../theme.js';
|
|
2
|
+
import { InlayError } from '../errors.js';
|
|
3
|
+
import { fieldMeta } from '../fields/define.js';
|
|
4
|
+
import { defOf, unwrap } from '../fields/zod-internals.js';
|
|
5
|
+
import { isReserved, normalizePath, routeRegExp, singletonPath, withLocale } from '../site/paths.js';
|
|
6
|
+
import { KEY_PATTERN } from './content.js';
|
|
7
|
+
const LOCALE = /^[a-z]{2,3}(-[A-Za-z0-9]+)*$/;
|
|
8
|
+
const NAME = /^[a-z][A-Za-z0-9_]*$/;
|
|
9
|
+
const SECRET = /^[A-Z][A-Z0-9_]*$/;
|
|
10
|
+
function fail(messageId, params) {
|
|
11
|
+
throw new InlayError('definition', messageId, params);
|
|
12
|
+
}
|
|
13
|
+
/** Checks every field of `shape` at any depth; `where` is the developer-facing dotted path prefix. */
|
|
14
|
+
function checkShape(shape, where, collections) {
|
|
15
|
+
for (const [key, schema] of Object.entries(shape)) {
|
|
16
|
+
const field = `${where}.${key}`;
|
|
17
|
+
if (!NAME.test(key))
|
|
18
|
+
fail('definition.fieldName', { field });
|
|
19
|
+
const meta = fieldMeta(schema);
|
|
20
|
+
if (!meta)
|
|
21
|
+
fail('definition.fieldWithoutMeta', { field });
|
|
22
|
+
if (meta.kind === 'ref' && (meta.target === undefined || !collections.has(meta.target))) {
|
|
23
|
+
fail('definition.refUnknown', { field, target: meta.target ?? '' });
|
|
24
|
+
}
|
|
25
|
+
const def = defOf(unwrap(schema));
|
|
26
|
+
if (meta.kind === 'group' && def.shape)
|
|
27
|
+
checkShape(def.shape, field, collections);
|
|
28
|
+
if (meta.kind === 'list' && def.element) {
|
|
29
|
+
const item = defOf(unwrap(def.element));
|
|
30
|
+
if (item.shape)
|
|
31
|
+
checkShape(item.shape, field, collections);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function checkTemplate(template, collections, checked) {
|
|
36
|
+
if (checked.has(template))
|
|
37
|
+
return;
|
|
38
|
+
checked.add(template);
|
|
39
|
+
checkShape(template.fields.shape, template.name, collections);
|
|
40
|
+
for (const [key, slot] of Object.entries(template.slots)) {
|
|
41
|
+
if (!NAME.test(key))
|
|
42
|
+
fail('definition.slotName', { name: key, template: template.name });
|
|
43
|
+
checkShape(slot.block.schema.shape, slot.block.name, collections);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function checkPath(name, path, locales) {
|
|
47
|
+
const first = path.split('/')[1] ?? '';
|
|
48
|
+
if (normalizePath(path) !== path || /[?#]/.test(path) || isReserved(path) || locales.includes(first)) {
|
|
49
|
+
fail('definition.path', { name, path });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function checkType(type, site) {
|
|
53
|
+
switch (type.kind) {
|
|
54
|
+
case 'singleton':
|
|
55
|
+
if (type.path !== null && typeof type.path === 'object' && !Object.hasOwn(type.path, site.defaultLocale)) {
|
|
56
|
+
fail('definition.pathDefaultLocale', { name: type.name, locale: site.defaultLocale });
|
|
57
|
+
}
|
|
58
|
+
if (type.path !== null) {
|
|
59
|
+
for (const p of typeof type.path === 'string' ? [type.path] : Object.values(type.path)) {
|
|
60
|
+
checkPath(type.name, p, site.locales);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case 'collection': {
|
|
65
|
+
const route = type.route;
|
|
66
|
+
if (route !== null && (!route.startsWith('/') || route.split(':slug').length !== 2 || /[?#]/.test(route))) {
|
|
67
|
+
fail('definition.route', { name: type.name, route });
|
|
68
|
+
}
|
|
69
|
+
if (route !== null) {
|
|
70
|
+
const prefix = route.split(':slug')[0].replace(/\/$/, '');
|
|
71
|
+
if (prefix !== '')
|
|
72
|
+
checkPath(type.name, prefix, site.locales);
|
|
73
|
+
}
|
|
74
|
+
const shape = type.template.fields.shape;
|
|
75
|
+
const title = Object.hasOwn(shape, type.titleField) ? shape[type.titleField] : undefined;
|
|
76
|
+
if (!title || fieldMeta(title)?.kind !== 'text') {
|
|
77
|
+
fail('definition.titleField', { name: type.name, field: type.titleField });
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function checkSettings(site, types) {
|
|
84
|
+
resolveTheme(site.admin.theme);
|
|
85
|
+
if (site.notFound !== null) {
|
|
86
|
+
const def = types.get(site.notFound);
|
|
87
|
+
if (!def || def.kind !== 'singleton' || def.path !== null || !def.template.render) {
|
|
88
|
+
fail('definition.notFound', { name: String(site.notFound) });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const path of site.publicPaths) {
|
|
92
|
+
if (typeof path !== 'string' || !path.startsWith('/'))
|
|
93
|
+
fail('definition.publicPath', { path: String(path) });
|
|
94
|
+
}
|
|
95
|
+
const secrets = new Set();
|
|
96
|
+
for (const name of site.secrets) {
|
|
97
|
+
if (typeof name !== 'string' || !SECRET.test(name) || secrets.has(name))
|
|
98
|
+
fail('definition.secretName', { name: String(name) });
|
|
99
|
+
secrets.add(name);
|
|
100
|
+
}
|
|
101
|
+
const migrations = new Set();
|
|
102
|
+
for (const { name } of site.migrations) {
|
|
103
|
+
if (typeof name !== 'string' || name.trim() === '' || migrations.has(name))
|
|
104
|
+
fail('definition.migrationName', { name: String(name) });
|
|
105
|
+
migrations.add(name);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Paths a route can't take: Inlay's reserved paths and the home page. */
|
|
109
|
+
const isRouteReserved = (path) => path === '/' || isReserved(path);
|
|
110
|
+
/** The type whose pages `path` would hide, in any locale, with or without its locale prefix. */
|
|
111
|
+
function shadowedType(registry, path) {
|
|
112
|
+
const { site } = registry;
|
|
113
|
+
for (const locale of site.locales) {
|
|
114
|
+
for (const def of site.singletons) {
|
|
115
|
+
const p = singletonPath(def, locale, site.defaultLocale);
|
|
116
|
+
if (p !== null && (p === path || withLocale(registry, locale, p) === path))
|
|
117
|
+
return def.name;
|
|
118
|
+
}
|
|
119
|
+
for (const def of site.collections) {
|
|
120
|
+
if (def.route === null)
|
|
121
|
+
continue;
|
|
122
|
+
if (routeRegExp(def.route).test(path) || routeRegExp(withLocale(registry, locale, def.route)).test(path))
|
|
123
|
+
return def.name;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
function checkRoutes(registry) {
|
|
129
|
+
const seen = new Set();
|
|
130
|
+
for (const { method, path } of registry.site.routes) {
|
|
131
|
+
if (method !== 'GET' && method !== 'POST')
|
|
132
|
+
fail('definition.routeMethod', { method: String(method), path: String(path) });
|
|
133
|
+
if (typeof path !== 'string' || normalizePath(path) !== path || /[:*?#%]/.test(path)) {
|
|
134
|
+
fail('definition.routePath', { path: String(path) });
|
|
135
|
+
}
|
|
136
|
+
if (isRouteReserved(path))
|
|
137
|
+
fail('definition.routeReserved', { path });
|
|
138
|
+
const name = shadowedType(registry, path);
|
|
139
|
+
if (name !== null)
|
|
140
|
+
fail('definition.routeShadows', { path, name });
|
|
141
|
+
const key = `${method} ${path}`;
|
|
142
|
+
if (seen.has(key))
|
|
143
|
+
fail('definition.routeDuplicate', { method, path });
|
|
144
|
+
seen.add(key);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** Checks a site definition and indexes its types. Throws `InlayError('definition')` naming the offender. */
|
|
148
|
+
export function buildRegistry(site) {
|
|
149
|
+
const seenLocales = new Set();
|
|
150
|
+
for (const locale of site.locales) {
|
|
151
|
+
if (!LOCALE.test(locale))
|
|
152
|
+
fail('definition.localeInvalid', { locale });
|
|
153
|
+
if (seenLocales.has(locale))
|
|
154
|
+
fail('definition.localeDuplicate', { locale });
|
|
155
|
+
seenLocales.add(locale);
|
|
156
|
+
}
|
|
157
|
+
if (!seenLocales.has(site.defaultLocale)) {
|
|
158
|
+
fail('definition.defaultLocale', {
|
|
159
|
+
locale: site.defaultLocale,
|
|
160
|
+
locales: site.locales.join(', '),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
const all = [...site.singletons, ...site.collections, ...site.globals];
|
|
164
|
+
const types = new Map();
|
|
165
|
+
for (const type of all) {
|
|
166
|
+
if (!NAME.test(type.name))
|
|
167
|
+
fail('definition.typeName', { name: type.name });
|
|
168
|
+
if (types.has(type.name))
|
|
169
|
+
fail('definition.typeDuplicate', { name: type.name });
|
|
170
|
+
types.set(type.name, type);
|
|
171
|
+
}
|
|
172
|
+
const collections = new Set(site.collections.map((c) => c.name));
|
|
173
|
+
const checked = new Set();
|
|
174
|
+
const blocks = new Map();
|
|
175
|
+
const templates = new Map();
|
|
176
|
+
for (const type of all) {
|
|
177
|
+
const known = templates.get(type.template.name);
|
|
178
|
+
if (known && known !== type.template)
|
|
179
|
+
fail('definition.templateDuplicate', { name: type.template.name });
|
|
180
|
+
templates.set(type.template.name, type.template);
|
|
181
|
+
for (const { block } of Object.values(type.template.slots)) {
|
|
182
|
+
const seen = blocks.get(block.name);
|
|
183
|
+
if (seen && seen !== block)
|
|
184
|
+
fail('definition.blockDuplicate', { name: block.name });
|
|
185
|
+
blocks.set(block.name, block);
|
|
186
|
+
}
|
|
187
|
+
checkTemplate(type.template, collections, checked);
|
|
188
|
+
checkType(type, site);
|
|
189
|
+
}
|
|
190
|
+
for (const locale of site.locales) {
|
|
191
|
+
const seen = new Set();
|
|
192
|
+
for (const type of site.singletons) {
|
|
193
|
+
const path = singletonPath(type, locale, site.defaultLocale);
|
|
194
|
+
if (path === null)
|
|
195
|
+
continue;
|
|
196
|
+
if (seen.has(path))
|
|
197
|
+
fail('definition.pathDuplicate', { path, locale });
|
|
198
|
+
seen.add(path);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
checkSettings(site, types);
|
|
202
|
+
const content = new Map();
|
|
203
|
+
for (const shipped of site.content) {
|
|
204
|
+
const type = types.get(shipped.type);
|
|
205
|
+
if (!type)
|
|
206
|
+
fail('definition.contentType', { type: shipped.type });
|
|
207
|
+
if (type.kind === 'collection' && shipped.via !== 'entries') {
|
|
208
|
+
fail('definition.contentUseEntries', { type: shipped.type });
|
|
209
|
+
}
|
|
210
|
+
if (type.kind !== 'collection' && shipped.via !== 'content') {
|
|
211
|
+
fail('definition.contentUseContent', { type: shipped.type });
|
|
212
|
+
}
|
|
213
|
+
if (content.has(shipped.type))
|
|
214
|
+
fail('definition.contentDuplicate', { type: shipped.type });
|
|
215
|
+
const keys = new Set();
|
|
216
|
+
for (const doc of shipped.documents) {
|
|
217
|
+
const ref = { type: shipped.type, key: doc.key };
|
|
218
|
+
if (shipped.via === 'entries' && (!KEY_PATTERN.test(doc.key) || doc.key.length > 100)) {
|
|
219
|
+
fail('definition.contentKey', ref);
|
|
220
|
+
}
|
|
221
|
+
if (keys.has(doc.key))
|
|
222
|
+
fail('definition.contentKeyDuplicate', ref);
|
|
223
|
+
keys.add(doc.key);
|
|
224
|
+
if (!Number.isInteger(doc.edition) || doc.edition < 1) {
|
|
225
|
+
fail('definition.contentEdition', { ...ref, edition: doc.edition });
|
|
226
|
+
}
|
|
227
|
+
const locales = Object.keys(doc.content);
|
|
228
|
+
if (locales.length === 0)
|
|
229
|
+
fail('definition.contentNoLocales', ref);
|
|
230
|
+
for (const locale of locales) {
|
|
231
|
+
if (!seenLocales.has(locale)) {
|
|
232
|
+
fail('definition.contentLocale', { ...ref, locale, locales: site.locales.join(', ') });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
content.set(shipped.type, shipped.documents);
|
|
237
|
+
}
|
|
238
|
+
const registry = {
|
|
239
|
+
site,
|
|
240
|
+
locales: [...site.locales],
|
|
241
|
+
defaultLocale: site.defaultLocale,
|
|
242
|
+
types,
|
|
243
|
+
blocks,
|
|
244
|
+
templates,
|
|
245
|
+
content,
|
|
246
|
+
getType(name) {
|
|
247
|
+
const type = types.get(name);
|
|
248
|
+
if (!type)
|
|
249
|
+
throw new InlayError('not_found', 'error.typeNotFound', { name });
|
|
250
|
+
return type;
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
checkRoutes(registry);
|
|
254
|
+
return registry;
|
|
255
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { SafeHtml } from '../../jsx/html.js';
|
|
3
|
+
import type { VariantFormat } from '../media/variants.js';
|
|
4
|
+
import type { RichTextDoc } from '../richtext/schema.js';
|
|
5
|
+
import type { FileValue, ImageValue, LinkValue } from '../types.js';
|
|
6
|
+
import type { CollectionDef, GlobalDef, TemplateDef } from './define.js';
|
|
7
|
+
export interface ResolvedImage {
|
|
8
|
+
id: string;
|
|
9
|
+
/** The original: `/media/<id>`. */
|
|
10
|
+
url: string;
|
|
11
|
+
alt: string;
|
|
12
|
+
width: number | null;
|
|
13
|
+
height: number | null;
|
|
14
|
+
mime: string;
|
|
15
|
+
/** The smallest variant at least `width` wide (or the largest); `webp` by default. */
|
|
16
|
+
src(width: number, format?: VariantFormat): string;
|
|
17
|
+
/** Every variant up to the original's width; `webp` by default. */
|
|
18
|
+
srcset(format?: VariantFormat): string;
|
|
19
|
+
}
|
|
20
|
+
export interface ResolvedFile {
|
|
21
|
+
id: string;
|
|
22
|
+
url: string;
|
|
23
|
+
filename: string;
|
|
24
|
+
mime: string;
|
|
25
|
+
size: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ResolvedLink {
|
|
28
|
+
/** Encoded. */
|
|
29
|
+
href: string;
|
|
30
|
+
text: string;
|
|
31
|
+
external: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface Entry<F = Record<string, unknown>> {
|
|
34
|
+
/** The translation group. */
|
|
35
|
+
id: string;
|
|
36
|
+
type: string;
|
|
37
|
+
/** The locale whose content is shown. */
|
|
38
|
+
locale: string;
|
|
39
|
+
fallback: boolean;
|
|
40
|
+
/** The encoded site path, or `null` for data entries. */
|
|
41
|
+
url: string | null;
|
|
42
|
+
title: string;
|
|
43
|
+
slug: string | null;
|
|
44
|
+
updatedAt: string;
|
|
45
|
+
fields: F;
|
|
46
|
+
}
|
|
47
|
+
export interface QueryOptions<F = Record<string, unknown>> {
|
|
48
|
+
filter?: (e: Entry<F>) => boolean;
|
|
49
|
+
sort?: 'newest' | 'oldest' | {
|
|
50
|
+
field: string;
|
|
51
|
+
direction?: 'asc' | 'desc';
|
|
52
|
+
};
|
|
53
|
+
limit?: number;
|
|
54
|
+
/** 1-based; ignored without `limit`. */
|
|
55
|
+
page?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface QueryResult<F = Record<string, unknown>> {
|
|
58
|
+
items: Entry<F>[];
|
|
59
|
+
total: number;
|
|
60
|
+
page: number;
|
|
61
|
+
pages: number;
|
|
62
|
+
}
|
|
63
|
+
export interface PageInfo {
|
|
64
|
+
title: string;
|
|
65
|
+
type: string;
|
|
66
|
+
/** The requested locale. */
|
|
67
|
+
locale: string;
|
|
68
|
+
/** The locale whose content is shown. */
|
|
69
|
+
contentLocale: string;
|
|
70
|
+
fallback: boolean;
|
|
71
|
+
/** The decoded site path; `''` for a page without one. */
|
|
72
|
+
path: string;
|
|
73
|
+
page: number;
|
|
74
|
+
}
|
|
75
|
+
export interface RenderContext {
|
|
76
|
+
locale: string;
|
|
77
|
+
defaultLocale: string;
|
|
78
|
+
locales: readonly string[];
|
|
79
|
+
preview: boolean;
|
|
80
|
+
page: number;
|
|
81
|
+
baseUrl: string;
|
|
82
|
+
alternates: Array<{
|
|
83
|
+
locale: string;
|
|
84
|
+
path: string;
|
|
85
|
+
fallback: boolean;
|
|
86
|
+
}>;
|
|
87
|
+
/** Alt is the value's, then the media's default, then `''`. `null` when the media is missing. */
|
|
88
|
+
image(v: ImageValue | null | undefined): ResolvedImage | null;
|
|
89
|
+
file(v: FileValue | null | undefined): ResolvedFile | null;
|
|
90
|
+
/** `null` when the target document isn't live. Text is the value's, then the target's title, then the URL. */
|
|
91
|
+
link(v: LinkValue | null | undefined): ResolvedLink | null;
|
|
92
|
+
richText(doc: RichTextDoc | null | undefined): SafeHtml;
|
|
93
|
+
/** Live entries in the given order; ones that aren't live are skipped. */
|
|
94
|
+
entries<F = Record<string, unknown>>(ids: string | readonly string[] | null | undefined): Promise<Entry<F>[]>;
|
|
95
|
+
/** Every live entry of the collection, filtered, sorted (`newest` by default) and paginated. */
|
|
96
|
+
query<T extends TemplateDef = TemplateDef>(collection: string | CollectionDef<T>, opts?: QueryOptions<z.output<T['fields']>>): Promise<QueryResult<z.output<T['fields']>>>;
|
|
97
|
+
global<T extends TemplateDef = TemplateDef>(g: string | GlobalDef<T>): Promise<z.output<T['fields']> | null>;
|
|
98
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ContentInput } from '../types.js';
|
|
2
|
+
import type { TemplateDef } from './define.js';
|
|
3
|
+
import type { RenderContext } from './render.js';
|
|
4
|
+
export type RouteMethod = 'GET' | 'POST';
|
|
5
|
+
export interface RouteRequest {
|
|
6
|
+
method: RouteMethod;
|
|
7
|
+
path: string;
|
|
8
|
+
query: Record<string, string>;
|
|
9
|
+
/** Lower-cased, without `cookie` and `authorization`: routes are anonymous. */
|
|
10
|
+
headers: Record<string, string>;
|
|
11
|
+
/** Form fields for a urlencoded body, parsed JSON for a JSON body, `null` otherwise. */
|
|
12
|
+
body: Record<string, string> | unknown | null;
|
|
13
|
+
/** The `locale` query or form field when it names a site locale, else the default locale. */
|
|
14
|
+
locale: string;
|
|
15
|
+
}
|
|
16
|
+
export interface RouteResponse {
|
|
17
|
+
/** Defaults to 200, or 204 when neither `body` nor `json` is given. */
|
|
18
|
+
status?: number;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
body?: string;
|
|
21
|
+
/** Wins over `body`. */
|
|
22
|
+
json?: unknown;
|
|
23
|
+
}
|
|
24
|
+
/** Published content only. */
|
|
25
|
+
export type QueryApi = Pick<RenderContext, 'query' | 'global' | 'entries'>;
|
|
26
|
+
export interface RouteContext {
|
|
27
|
+
query: QueryApi;
|
|
28
|
+
render(template: TemplateDef, data?: ContentInput, opts?: {
|
|
29
|
+
status?: number;
|
|
30
|
+
}): Promise<RouteResponse>;
|
|
31
|
+
fetch: typeof fetch;
|
|
32
|
+
secrets: Readonly<Record<string, string>>;
|
|
33
|
+
redirect(location: string, status?: 302 | 303): RouteResponse;
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
locale: string;
|
|
36
|
+
}
|
|
37
|
+
export interface RouteDef {
|
|
38
|
+
method: RouteMethod;
|
|
39
|
+
path: string;
|
|
40
|
+
handler: (request: RouteRequest, ctx: RouteContext) => Promise<RouteResponse> | RouteResponse;
|
|
41
|
+
}
|
|
42
|
+
export declare function defineRoute(def: RouteDef): RouteDef;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** What a release's `site.js` may import; everything else is bundled into it or refused. */
|
|
2
|
+
export declare const RELEASE_IMPORTS: readonly string[];
|
|
3
|
+
/**
|
|
4
|
+
* Bundles the config module at `configFile` and everything it imports into one ESM file at `outFile` for the CLI
|
|
5
|
+
* to import, so loading a site's TypeScript and JSX needs nothing but Inlay. `inlaycms` imports point at the running
|
|
6
|
+
* copy, as a release's do; nothing is refused, since `bundleSite` is what holds a release to its boundary. A build
|
|
7
|
+
* failure is `cli.configFailed`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function bundleConfig(configFile: string, outFile: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Bundles the config module at `configFile` and everything it imports into one ESM file at `outFile`, leaving
|
|
12
|
+
* `inlaycms/site` and the JSX runtime to the host. `import.meta.url` in each module keeps naming its source file,
|
|
13
|
+
* so `new URL('./x', import.meta.url)` in content means what it meant before bundling. Refuses Node built-ins and
|
|
14
|
+
* any other import left outside the bundle (`inlaycms` itself included) with `error.packImport`, and site code
|
|
15
|
+
* (not installed packages) that reaches for the server with `error.packForbidden`; other build failures are
|
|
16
|
+
* `error.packBundle`. These checks catch mistakes: the release's signature is what makes it trusted. Returns the
|
|
17
|
+
* imports left in the bundle.
|
|
18
|
+
*/
|
|
19
|
+
export declare function bundleSite(configFile: string, outFile: string): Promise<{
|
|
20
|
+
imports: string[];
|
|
21
|
+
}>;
|