inlaycms 0.2.0 → 0.4.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.
Files changed (122) hide show
  1. package/README.md +334 -1
  2. package/assets/admin/admin.css +1 -1
  3. package/assets/admin/admin.js +1 -1
  4. package/assets/admin/editor.js +59 -44
  5. package/dist/adapters/admin/screens/redirects.js +12 -3
  6. package/dist/adapters/admin/views/layout.js +27 -7
  7. package/dist/adapters/cli/remote.js +9 -1
  8. package/dist/adapters/mcp/tools/redirects.js +16 -2
  9. package/dist/adapters/site/assets.d.ts +11 -0
  10. package/dist/adapters/site/assets.js +71 -0
  11. package/dist/adapters/site/cache.d.ts +2 -1
  12. package/dist/adapters/site/cache.js +6 -1
  13. package/dist/adapters/site/context.d.ts +6 -0
  14. package/dist/adapters/site/context.js +38 -13
  15. package/dist/adapters/site/head.d.ts +30 -7
  16. package/dist/adapters/site/head.js +145 -20
  17. package/dist/adapters/site/headers.d.ts +5 -0
  18. package/dist/adapters/site/headers.js +31 -0
  19. package/dist/adapters/site/plugin.d.ts +2 -0
  20. package/dist/adapters/site/plugin.js +32 -9
  21. package/dist/adapters/site/public.js +7 -24
  22. package/dist/adapters/site/render.d.ts +5 -0
  23. package/dist/adapters/site/render.js +23 -8
  24. package/dist/adapters/site/routes.d.ts +6 -0
  25. package/dist/adapters/site/routes.js +8 -3
  26. package/dist/adapters/site/seo.d.ts +20 -0
  27. package/dist/adapters/site/seo.js +45 -0
  28. package/dist/adapters/site/sitemap.d.ts +1 -1
  29. package/dist/adapters/site/sitemap.js +1 -1
  30. package/dist/config.js +3 -2
  31. package/dist/core/agent/format.js +1 -1
  32. package/dist/core/agent/schema.js +3 -0
  33. package/dist/core/boot.js +7 -0
  34. package/dist/core/check.js +6 -1
  35. package/dist/core/content/dry-run.d.ts +7 -6
  36. package/dist/core/content/dry-run.js +8 -8
  37. package/dist/core/content/publish.d.ts +1 -1
  38. package/dist/core/content/publish.js +5 -3
  39. package/dist/core/content/read.d.ts +3 -0
  40. package/dist/core/content/reader.js +3 -2
  41. package/dist/core/content/refs.js +1 -1
  42. package/dist/core/content/search.js +2 -2
  43. package/dist/core/content/shipped-images.d.ts +32 -0
  44. package/dist/core/content/shipped-images.js +62 -0
  45. package/dist/core/content/shipped-input.d.ts +9 -3
  46. package/dist/core/content/shipped-input.js +165 -28
  47. package/dist/core/content/shipped.js +8 -3
  48. package/dist/core/content/validate.js +7 -1
  49. package/dist/core/core.d.ts +5 -1
  50. package/dist/core/core.js +5 -4
  51. package/dist/core/db/connection.d.ts +6 -0
  52. package/dist/core/db/connection.js +13 -1
  53. package/dist/core/db/migrate.js +2 -0
  54. package/dist/core/db/migrations/0007_published_at.d.ts +3 -0
  55. package/dist/core/db/migrations/0007_published_at.js +16 -0
  56. package/dist/core/db/schema.d.ts +1 -0
  57. package/dist/core/export/export.js +3 -1
  58. package/dist/core/export/format.d.ts +8 -1
  59. package/dist/core/export/format.js +3 -2
  60. package/dist/core/export/read.js +7 -0
  61. package/dist/core/export/stage.d.ts +1 -1
  62. package/dist/core/export/stage.js +24 -1
  63. package/dist/core/fields/builtins.d.ts +28 -0
  64. package/dist/core/fields/builtins.js +103 -11
  65. package/dist/core/fields/define.d.ts +6 -0
  66. package/dist/core/fields/widgets.d.ts +7 -0
  67. package/dist/core/fields/widgets.js +77 -28
  68. package/dist/core/media/library.js +2 -2
  69. package/dist/core/messages/en.d.ts +72 -6
  70. package/dist/core/messages/en.js +72 -6
  71. package/dist/core/redirects/collapse.d.ts +17 -1
  72. package/dist/core/redirects/collapse.js +19 -3
  73. package/dist/core/redirects/redirects.d.ts +13 -12
  74. package/dist/core/redirects/redirects.js +141 -53
  75. package/dist/core/redirects/rule.d.ts +25 -0
  76. package/dist/core/redirects/rule.js +55 -0
  77. package/dist/core/registry/define.d.ts +40 -0
  78. package/dist/core/registry/define.js +3 -0
  79. package/dist/core/registry/registry.d.ts +21 -0
  80. package/dist/core/registry/registry.js +114 -6
  81. package/dist/core/registry/render.d.ts +37 -1
  82. package/dist/core/registry/route.d.ts +4 -0
  83. package/dist/core/release/bundle.js +30 -5
  84. package/dist/core/release/manifest.d.ts +14 -0
  85. package/dist/core/release/manifest.js +42 -17
  86. package/dist/core/release/markdown-file.d.ts +21 -0
  87. package/dist/core/release/markdown-file.js +172 -0
  88. package/dist/core/release/pack.js +2 -2
  89. package/dist/core/release/read.js +4 -1
  90. package/dist/core/release/site-dir.d.ts +4 -0
  91. package/dist/core/release/site-dir.js +8 -0
  92. package/dist/core/report.d.ts +8 -2
  93. package/dist/core/richtext/html.d.ts +3 -1
  94. package/dist/core/richtext/html.js +18 -4
  95. package/dist/core/richtext/inline.d.ts +22 -0
  96. package/dist/core/richtext/inline.js +33 -0
  97. package/dist/core/richtext/markdown.d.ts +19 -1
  98. package/dist/core/richtext/markdown.js +187 -22
  99. package/dist/core/richtext/schema.d.ts +22 -5
  100. package/dist/core/richtext/schema.js +81 -4
  101. package/dist/core/site/live.d.ts +1 -0
  102. package/dist/core/site/live.js +1 -0
  103. package/dist/core/site/paths.d.ts +6 -0
  104. package/dist/core/site/paths.js +13 -0
  105. package/dist/core/site/resolve.d.ts +1 -1
  106. package/dist/core/site/resolve.js +119 -30
  107. package/dist/core/site/sitemap.d.ts +1 -1
  108. package/dist/core/site/sitemap.js +4 -0
  109. package/dist/core/types.d.ts +28 -3
  110. package/dist/host/app.d.ts +5 -0
  111. package/dist/host/app.js +10 -1
  112. package/dist/host/dev.js +3 -7
  113. package/dist/host/diff.d.ts +19 -1
  114. package/dist/host/diff.js +32 -2
  115. package/dist/index.d.ts +2 -2
  116. package/dist/markdown-modules.d.ts +8 -0
  117. package/dist/markdown-modules.js +1 -0
  118. package/dist/site.d.ts +8 -3
  119. package/dist/site.js +6 -0
  120. package/dist/testing.d.ts +22 -0
  121. package/dist/testing.js +155 -0
  122. package/package.json +7 -1
@@ -1,7 +1,8 @@
1
1
  import { sql } from 'kysely';
2
- import { pathTarget, ruleCandidates, ruleIndex } from '../redirects/collapse.js';
2
+ import { nextHops, pathTarget, ruleIndex } from '../redirects/collapse.js';
3
+ import { isUrlTarget } from '../redirects/rule.js';
3
4
  import { liveDocuments, liveQuery, liveSingleton } from './live.js';
4
- import { encodePath, normalizePath, routeRegExp, singletonPath, splitLocale } from './paths.js';
5
+ import { encodePath, lowercaseFallback, normalizePath, routeRegExp, singletonPath, splitLocale } from './paths.js';
5
6
  const notFound = (locale) => ({ kind: 'not_found', locale });
6
7
  const page = (document) => ({ kind: 'page', document });
7
8
  const redirect = (path) => ({ kind: 'redirect', location: encodePath(path), status: 301 });
@@ -48,47 +49,65 @@ async function matchIndex(deps) {
48
49
  }
49
50
  /**
50
51
  * Where a rule sends a request in `locale`: a document target is its URL in `locale` (`null` when it
51
- * isn't live there); a path target gets its params filled in, and the locale prefix when the rule
52
- * matched the unprefixed rest.
52
+ * isn't live there); a URL target is that URL as stored, on another site; a path target gets its params
53
+ * filled in, and the locale prefix when the rule matched the unprefixed rest.
53
54
  */
54
55
  async function ruleTarget(deps, candidate, locale, opts) {
55
56
  const { rule } = candidate;
56
57
  if (rule.to_group_id !== null) {
57
- return (await liveDocuments(deps, [rule.to_group_id], locale, opts)).get(rule.to_group_id)?.path ?? null;
58
+ const path = (await liveDocuments(deps, [rule.to_group_id], locale, opts)).get(rule.to_group_id)?.path ?? null;
59
+ return path === null ? null : { target: path, external: false };
58
60
  }
59
61
  if (rule.to_path === null)
60
62
  return null;
61
- return pathTarget(deps.registry, locale, rule.to_path, candidate);
63
+ if (isUrlTarget(rule.to_path))
64
+ return { target: rule.to_path, external: true };
65
+ return { target: pathTarget(deps.registry, locale, rule.to_path, candidate), external: false };
62
66
  }
63
67
  /**
64
- * The rules that would answer a request for `path`, in `ruleCandidates` order: exact rules before
65
- * pattern rules. Rules whose target isn't live, or is `path` itself, are skipped.
68
+ * The rules that would answer a request for `path`, in `nextHops` order: admin rules then code
69
+ * rules, each with exact rules before pattern rules, and last the lowercase fallback when `path`
70
+ * has one. Rules whose target isn't live, or is `path` itself, are skipped.
66
71
  */
67
- async function* firing(deps, index, path, locale, opts) {
68
- for (const candidate of ruleCandidates(deps.registry, index, path)) {
69
- const target = await ruleTarget(deps, candidate, locale, opts);
70
- if (target !== null && target !== path)
71
- yield { rule: candidate.rule, target };
72
+ async function* firing(deps, sets, path, locale, opts) {
73
+ for (const hop of nextHops(deps.registry, sets, path)) {
74
+ if ('fallback' in hop) {
75
+ yield hop;
76
+ continue;
77
+ }
78
+ const to = await ruleTarget(deps, hop.candidate, locale, opts);
79
+ if (to !== null && to.target !== path)
80
+ yield { rule: hop.candidate.rule, ...to };
72
81
  }
73
82
  }
74
83
  /** The most redirects followed when checking that a redirect doesn't lead round in a loop. */
75
84
  const MAX_HOPS = 32;
76
85
  /**
77
86
  * Follows a visitor sent from `start` to `fired.target`, answering each request as `resolvePath`
78
- * would (pages, normalizing redirects, then the first rule that fires), and gives the `from` of the
79
- * rules passed if a path comes round again, or `null` when the chain ends or runs past `MAX_HOPS`.
87
+ * would (a GET code route, pages, normalizing redirects, then the first rule that fires or else the
88
+ * lowercase fallback), and gives the `from` of the rules passed if a path comes round again, or
89
+ * `null` when the chain ends (at a code route, a page, a not-found or another site) or runs past
90
+ * `MAX_HOPS`.
80
91
  */
81
- async function loopFrom(deps, index, start, fired, opts) {
92
+ async function loopFrom(deps, sets, start, fired, opts) {
93
+ if (fired.external)
94
+ return null;
82
95
  const seen = new Set([start]);
83
96
  const rules = [fired.rule.from];
84
97
  let path = fired.target;
85
98
  for (let hops = 0; hops < MAX_HOPS; hops++) {
99
+ if (deps.registry.getRoutePaths.has(path))
100
+ return null;
86
101
  if (seen.has(path))
87
102
  return rules;
88
103
  seen.add(path);
89
104
  const res = await resolveSite(deps, encodePath(path), opts);
90
105
  if (res.kind === 'page' || res.kind === 'not_found')
91
106
  return null;
107
+ if (res.kind === 'canonical') {
108
+ path = res.canonical;
109
+ continue;
110
+ }
92
111
  if (res.kind === 'redirect') {
93
112
  const next = normalizePath(res.location);
94
113
  if (next === null)
@@ -96,25 +115,37 @@ async function loopFrom(deps, index, start, fired, opts) {
96
115
  path = next;
97
116
  continue;
98
117
  }
99
- const { value: next } = await firing(deps, index, res.path, res.locale, opts).next();
118
+ const { value: next } = await firing(deps, sets, res.path, res.locale, opts).next();
100
119
  if (!next)
101
120
  return null;
121
+ if ('fallback' in next) {
122
+ path = next.fallback;
123
+ continue;
124
+ }
125
+ if (next.external)
126
+ return null;
102
127
  rules.push(next.rule.from);
103
128
  path = next.target;
104
129
  }
105
130
  return null;
106
131
  }
107
132
  /**
108
- * The first redirect rule that applies, as `firing` gives them, skipping any that would send the
109
- * visitor round in a loop. `not_found` with `loop` when only such rules fire.
133
+ * The first redirect rule that applies, as `firing` gives them up to the lowercase fallback, skipping
134
+ * any that would send the visitor round in a loop. `not_found` with `loop` when only such rules fire.
110
135
  */
111
136
  async function matchRedirect(deps, at, opts) {
112
- const index = await matchIndex(deps);
137
+ const sets = [await matchIndex(deps), deps.registry.redirectIndex];
113
138
  const loop = new Set();
114
- for await (const fired of firing(deps, index, at.path, at.locale, opts)) {
115
- const rules = await loopFrom(deps, index, at.path, fired, opts);
116
- if (rules === null)
117
- return { kind: 'redirect', location: encodePath(fired.target), status: fired.rule.status };
139
+ for await (const fired of firing(deps, sets, at.path, at.locale, opts)) {
140
+ if ('fallback' in fired)
141
+ break;
142
+ const rules = await loopFrom(deps, sets, at.path, fired, opts);
143
+ if (rules === null) {
144
+ const { target, rule } = fired;
145
+ return fired.external
146
+ ? { kind: 'redirect', location: target, status: rule.status, external: true }
147
+ : { kind: 'redirect', location: encodePath(target), status: rule.status };
148
+ }
118
149
  for (const from of rules)
119
150
  loop.add(from);
120
151
  }
@@ -126,21 +157,79 @@ function lookupLocales(deps, locale) {
126
157
  /** Resolves a still-encoded URL path (no query string) to a page, a redirect or not-found. */
127
158
  export async function resolvePath(deps, rawPath, opts = {}) {
128
159
  const res = await resolveSite(deps, rawPath, opts);
160
+ if (res.kind === 'canonical') {
161
+ // A mixed-case path that would 404 once canonical goes where the lowercase fallback lands, in one 301.
162
+ const { canonical } = res;
163
+ const lower = lowercaseFallback(canonical);
164
+ if (lower !== null &&
165
+ !deps.registry.getRoutePaths.has(canonical) &&
166
+ (await resolveRules(deps, encodePath(canonical), opts)).kind === 'not_found') {
167
+ return (await landing(deps, lower, opts)) ?? redirect(canonical);
168
+ }
169
+ return redirect(canonical);
170
+ }
129
171
  if (res.kind !== 'rules')
130
172
  return res;
131
- // 7. Redirect rules.
173
+ // 7. Redirect rules: the admin's (7a), then the site's code rules (7b).
132
174
  const rule = await matchRedirect(deps, res, opts);
133
- if (rule)
175
+ if (rule?.kind === 'redirect')
134
176
  return rule;
135
- // 8. Not found.
136
- return notFound(res.locale);
177
+ // 8. Lowercase fallback.
178
+ const lower = lowercaseFallback(res.path);
179
+ const landed = lower === null ? null : await landing(deps, lower, opts);
180
+ if (landed)
181
+ return landed;
182
+ // 9. Not found.
183
+ return rule ?? notFound(res.locale);
184
+ }
185
+ /** Steps 1–7b of `resolvePath`: everything but the lowercase fallback. */
186
+ async function resolveRules(deps, rawPath, opts) {
187
+ const res = await resolveSite(deps, rawPath, opts);
188
+ if (res.kind === 'canonical')
189
+ return redirect(res.canonical);
190
+ if (res.kind !== 'rules')
191
+ return res;
192
+ return (await matchRedirect(deps, res, opts)) ?? notFound(res.locale);
137
193
  }
138
194
  /**
139
- * What `resolvePath` answers before it looks at redirect rules (steps 1–6, then 8): a redirect rule
195
+ * Where the lowercase fallback for a request lands, given its lowercase form `lower`: a GET code
196
+ * route or a page there, a redirect that steps 2–6 or a rule would give, or `null` when nothing
197
+ * answers there. A step 2–3 redirect lands only when something answers at its canonical path.
198
+ */
199
+ async function landing(deps, lower, opts) {
200
+ if (deps.registry.getRoutePaths.has(lower))
201
+ return redirect(lower);
202
+ const res = await resolveSite(deps, encodePath(lower), opts);
203
+ if (res.kind === 'page')
204
+ return redirect(lower);
205
+ if (res.kind === 'canonical')
206
+ return (await answers(deps, res.canonical, opts)) ? redirect(res.canonical) : null;
207
+ if (res.kind === 'redirect')
208
+ return res;
209
+ if (res.kind !== 'rules')
210
+ return null;
211
+ const rule = await matchRedirect(deps, res, opts);
212
+ return rule?.kind === 'redirect' ? rule : null;
213
+ }
214
+ /** Whether a GET code route, a page, a redirect from steps 2–6 or a firing rule answers at a decoded `path`. */
215
+ async function answers(deps, path, opts) {
216
+ if (deps.registry.getRoutePaths.has(path))
217
+ return true;
218
+ const res = await resolveSite(deps, encodePath(path), opts);
219
+ if (res.kind === 'canonical')
220
+ return answers(deps, res.canonical, opts);
221
+ if (res.kind !== 'rules')
222
+ return res.kind !== 'not_found';
223
+ return (await matchRedirect(deps, res, opts))?.kind === 'redirect';
224
+ }
225
+ /**
226
+ * What `resolvePath` answers before it looks at redirect rules (steps 1–6, then 9): a redirect rule
140
227
  * can only fire where this is `not_found`.
141
228
  */
142
229
  export async function resolveWithoutRules(deps, rawPath, opts = {}) {
143
230
  const res = await resolveSite(deps, rawPath, opts);
231
+ if (res.kind === 'canonical')
232
+ return redirect(res.canonical);
144
233
  return res.kind === 'rules' ? notFound(res.locale) : res;
145
234
  }
146
235
  /** Steps 1–6 of `resolvePath`, or where redirect rules are tried next. */
@@ -155,7 +244,7 @@ async function resolveSite(deps, rawPath, opts) {
155
244
  const [, first = '', ...tail] = path.split('/');
156
245
  const canonical = first === registry.defaultLocale ? `/${tail.join('/')}` : path;
157
246
  if (canonical !== path || decodeURIComponent(rawPath) !== path)
158
- return redirect(canonical);
247
+ return { kind: 'canonical', canonical };
159
248
  const { locale, rest } = splitLocale(registry, path);
160
249
  const types = [...registry.types.values()];
161
250
  // 4. Singleton paths.
@@ -1,7 +1,7 @@
1
1
  import type { CoreDeps } from '../types.js';
2
2
  export interface SitemapEntry {
3
3
  path: string;
4
- updatedAt: string;
4
+ updatedAt?: string;
5
5
  alternates: Array<{
6
6
  locale: string;
7
7
  path: string;
@@ -20,5 +20,9 @@ export async function sitemapEntries(deps) {
20
20
  }
21
21
  }
22
22
  }
23
+ for (const route of registry.site.routes) {
24
+ if (route.method === 'GET' && route.sitemap === true)
25
+ out.push({ path: route.path, alternates: [] });
26
+ }
23
27
  return out;
24
28
  }
@@ -199,9 +199,14 @@ export interface LiveDocument {
199
199
  revisionId: number;
200
200
  /** The shown revision's `created_at`. */
201
201
  updatedAt: string;
202
+ /** When Inlay first published the document; `null` if it never has been. */
203
+ publishedAt: string | null;
202
204
  data: DocumentData;
203
205
  }
204
- /** What a request path resolves to. A redirect's `location` is already encoded. */
206
+ /**
207
+ * What a request path resolves to. A redirect's `location` is already encoded: a site path, or with
208
+ * `external` the full https URL of a rule's URL target.
209
+ */
205
210
  export type RouteMatch = {
206
211
  kind: 'page';
207
212
  document: LiveDocument;
@@ -209,6 +214,7 @@ export type RouteMatch = {
209
214
  kind: 'redirect';
210
215
  location: string;
211
216
  status: 301 | 302;
217
+ external?: true;
212
218
  }
213
219
  /** `loop` lists the `from` of redirect rules that were skipped because they would go round in a loop. */
214
220
  | {
@@ -221,11 +227,16 @@ export type RedirectSource = 'manual' | 'auto' | 'import';
221
227
  export interface Redirect {
222
228
  id: number;
223
229
  from: string;
224
- /** A site path (which may use the `:name` params of `from`), or a document's translation group. */
230
+ /**
231
+ * A site path (which may use the `:name` params of `from`), a document's translation group, or a
232
+ * full https URL on another site.
233
+ */
225
234
  to: {
226
235
  path: string;
227
236
  } | {
228
237
  document: string;
238
+ } | {
239
+ url: string;
229
240
  };
230
241
  status: 301 | 302;
231
242
  source: RedirectSource;
@@ -236,13 +247,27 @@ export interface Redirect {
236
247
  export interface RedirectInput {
237
248
  /** A site path, or a full http(s) URL whose origin is dropped. */
238
249
  from: string;
239
- /** A site path, or a document's translation group. */
250
+ /** A site path, a full `https://` URL on another site, or a document's translation group. */
240
251
  to: string | {
241
252
  document: string;
242
253
  };
243
254
  status?: 301 | 302;
244
255
  note?: string;
245
256
  }
257
+ /** A redirect rule from the site's code. Read-only: it changes only with a new release. */
258
+ export interface CodeRedirect {
259
+ from: string;
260
+ to: {
261
+ path: string;
262
+ } | {
263
+ url: string;
264
+ };
265
+ status: 301 | 302;
266
+ /** An admin rule with the same `from` answers first. */
267
+ overridden: boolean;
268
+ /** A published page answers at the exact `from`, so the rule never fires. */
269
+ hidden: boolean;
270
+ }
246
271
  export type ThemeColor = 'base-100' | 'base-200' | 'base-300' | 'base-content' | 'primary' | 'primary-content' | 'secondary' | 'secondary-content' | 'accent' | 'accent-content' | 'neutral' | 'neutral-content' | 'info' | 'info-content' | 'success' | 'success-content' | 'warning' | 'warning-content' | 'error' | 'error-content';
247
272
  export interface CustomTheme {
248
273
  base?: string;
@@ -1,5 +1,6 @@
1
1
  import { type FastifyInstance } from 'fastify';
2
2
  import { type HostApi } from '../adapters/site/plugin.js';
3
+ import type { LoadedConfig } from '../config.js';
3
4
  import type { Core } from '../core/core.js';
4
5
  import { type SiteDefinition } from '../core/registry/define.js';
5
6
  import type { HostConfig } from './config.js';
@@ -13,6 +14,8 @@ export interface SiteSource {
13
14
  /** Each shipped file's source as the site names it, to the file to read. */
14
15
  shippedFiles?: ReadonlyMap<string, string>;
15
16
  }
17
+ /** The source of a site run from its code (`inlaycms dev` and `inlaycms/testing`): its `public/` folder, if it has one. */
18
+ export declare function sourceFromConfig(loaded: LoadedConfig): SiteSource;
16
19
  /**
17
20
  * The Fastify app for one site on the host, ready but not listening. With no `source` it serves the admin and, for
18
21
  * every content page, the `noSite` page: "no site yet" (`'empty'`, the default) for a host that has no release, or
@@ -40,6 +43,8 @@ export declare function createSiteApp(config: HostConfig, source: SiteSource | n
40
43
  diff?: (core: Core) => Promise<ContentDiff>;
41
44
  /** The largest release file a push may send (`PUSH_MAX_BYTES` by default); for tests. */
42
45
  pushMaxBytes?: number;
46
+ /** What routes get as `ctx.fetch`; the global `fetch` by default. */
47
+ fetch?: typeof fetch;
43
48
  }): Promise<{
44
49
  app: FastifyInstance;
45
50
  core: Core;
package/dist/host/app.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
1
3
  import Fastify from 'fastify';
2
4
  import { AUTH, inlay } from '../adapters/site/plugin.js';
3
5
  import { catalogPage } from '../adapters/site/render.js';
@@ -15,6 +17,11 @@ export const EMPTY_SITE = defineSite({
15
17
  defaultLocale: 'en',
16
18
  admin: { name: t('admin.title') },
17
19
  });
20
+ /** The source of a site run from its code (`inlaycms dev` and `inlaycms/testing`): its `public/` folder, if it has one. */
21
+ export function sourceFromConfig(loaded) {
22
+ const publicDir = join(loaded.dir, 'public');
23
+ return { site: loaded.config.site, publicDir: existsSync(publicDir) ? publicDir : null };
24
+ }
18
25
  /**
19
26
  * The Fastify app for one site on the host, ready but not listening. With no `source` it serves the admin and, for
20
27
  * every content page, the `noSite` page: "no site yet" (`'empty'`, the default) for a host that has no release, or
@@ -27,7 +34,8 @@ export const EMPTY_SITE = defineSite({
27
34
  * (what `diff` gives) to requests that didn't come through the proxy.
28
35
  */
29
36
  export async function createSiteApp(config, source, opts) {
30
- const app = Fastify({ logger: opts.logger ?? false, trustProxy: config.trustProxy });
37
+ // No plugin timeout: the site plugin boots the site (migrations, shipped content), which takes as long as it takes.
38
+ const app = Fastify({ logger: opts.logger ?? false, trustProxy: config.trustProxy, pluginTimeout: 0 });
31
39
  const now = opts.now ?? (() => new Date());
32
40
  // Opened once the site has booted (which creates and migrates the database), for the push API, admin and proxy.
33
41
  let db = null;
@@ -87,6 +95,7 @@ export async function createSiteApp(config, source, opts) {
87
95
  publicMaxAge: config.publicMaxAge,
88
96
  ...(source?.publicDir != null && { publicDir: source.publicDir }),
89
97
  secrets: config.secrets(source?.site.secrets ?? []),
98
+ ...(opts.fetch && { fetch: opts.fetch }),
90
99
  content: opts.content,
91
100
  ...(source?.shippedFiles && { shippedFiles: source.shippedFiles }),
92
101
  ...(opts.now && { now: opts.now }),
package/dist/host/dev.js CHANGED
@@ -8,7 +8,7 @@ import { loadConfig } from '../config.js';
8
8
  import { InlayError } from '../core/errors.js';
9
9
  import { t } from '../core/messages/index.js';
10
10
  import { INLAY_ENTRIES } from '../core/release/read.js';
11
- import { createSiteApp } from './app.js';
11
+ import { createSiteApp, sourceFromConfig } from './app.js';
12
12
  import { INLAY_BIN } from './bin.js';
13
13
  import { ensureDataDir, readHostConfig } from './config.js';
14
14
  /** Only for `inlaycms dev` on a developer's computer: the server's own secret when INLAY_SECRET isn't set. */
@@ -147,14 +147,10 @@ async function runSite(configFile, io) {
147
147
  process.on('disconnect', () => void close());
148
148
  try {
149
149
  useRunningInlay();
150
- const { config, dir } = await loadConfig(configFile);
150
+ const loaded = await loadConfig(configFile);
151
151
  const host = readHostConfig(process.env);
152
152
  await ensureDataDir(host);
153
- const publicDir = join(dir, 'public');
154
- app = (await createSiteApp(host, { site: config.site, publicDir: existsSync(publicDir) ? publicDir : null }, {
155
- content: 'apply',
156
- logger: true,
157
- })).app;
153
+ app = (await createSiteApp(host, sourceFromConfig(loaded), { content: 'apply', logger: true })).app;
158
154
  if (closing)
159
155
  return 0;
160
156
  await app.listen({ port: host.port, host: host.host });
@@ -1,8 +1,9 @@
1
- import { type ReleaseManifest } from '../core/release/manifest.js';
1
+ import { type ManifestRedirect, type ReleaseManifest } from '../core/release/manifest.js';
2
2
  import type { ReleaseDiff } from './push.js';
3
3
  type Route = {
4
4
  method: string;
5
5
  path: string;
6
+ sitemap?: true;
6
7
  };
7
8
  type FieldChange = 'added' | 'removed' | 'type' | 'required' | 'optional';
8
9
  type Slot = {
@@ -44,9 +45,26 @@ export interface StructuralDiff {
44
45
  path: string;
45
46
  change: FieldChange;
46
47
  }>;
48
+ /**
49
+ * `sitemap.added`: the staged release's sitemap routes that the current release doesn't list, new routes included.
50
+ * `sitemap.removed`: routes both releases have that the current release lists and the staged one doesn't.
51
+ */
47
52
  routes: {
48
53
  added: Route[];
49
54
  removed: Route[];
55
+ sitemap: {
56
+ added: Route[];
57
+ removed: Route[];
58
+ };
59
+ };
60
+ /** Code redirects by `from`; `changed` holds those whose target or status differs. Absent from a host before 0.3. */
61
+ redirects?: {
62
+ added: ManifestRedirect[];
63
+ removed: ManifestRedirect[];
64
+ changed: Array<{
65
+ before: ManifestRedirect;
66
+ after: ManifestRedirect;
67
+ }>;
50
68
  };
51
69
  /** Every secret the staged release needs. */
52
70
  secrets: string[];
package/dist/host/diff.js CHANGED
@@ -244,6 +244,20 @@ export function structuralDiff(current, staged) {
244
244
  }
245
245
  }
246
246
  }
247
+ const curRedirects = new Map((current?.redirects ?? []).map((r) => [r.from, r]));
248
+ const stagedRedirects = new Map((staged.redirects ?? []).map((r) => [r.from, r]));
249
+ const redirects = { added: [], removed: [], changed: [] };
250
+ for (const [from, after] of stagedRedirects) {
251
+ const before = curRedirects.get(from);
252
+ if (!before)
253
+ redirects.added.push(after);
254
+ else if (before.to !== after.to || before.status !== after.status)
255
+ redirects.changed.push({ before, after });
256
+ }
257
+ for (const [from, before] of curRedirects)
258
+ if (!stagedRedirects.has(from))
259
+ redirects.removed.push(before);
260
+ const listed = new Set((current?.routes ?? []).filter((r) => r.sitemap === true).map(routeKey));
247
261
  return {
248
262
  types: { added: added(curNames, stagedNames), removed: added(stagedNames, curNames), changed },
249
263
  slots,
@@ -252,7 +266,12 @@ export function structuralDiff(current, staged) {
252
266
  routes: {
253
267
  added: added(current?.routes ?? [], staged.routes, routeKey),
254
268
  removed: added(staged.routes, current?.routes ?? [], routeKey),
269
+ sitemap: {
270
+ added: staged.routes.filter((r) => r.sitemap === true && !listed.has(routeKey(r))),
271
+ removed: staged.routes.filter((r) => r.sitemap !== true && listed.has(routeKey(r))),
272
+ },
255
273
  },
274
+ redirects,
256
275
  secrets: [...staged.secrets],
257
276
  migrations: [...staged.migrations],
258
277
  shipped: { stale },
@@ -335,9 +354,20 @@ export function formatDiff(diff) {
335
354
  for (const name of s.migrations)
336
355
  lines.push(t('diff.release.migration', { name }));
337
356
  for (const r of s.routes.added)
338
- lines.push(t('diff.release.routeAdded', r));
357
+ lines.push(t('diff.release.routeAdded', { method: r.method, path: r.path }));
339
358
  for (const r of s.routes.removed)
340
- lines.push(t('diff.release.routeRemoved', r));
359
+ lines.push(t('diff.release.routeRemoved', { method: r.method, path: r.path }));
360
+ for (const r of s.routes.sitemap?.added ?? [])
361
+ lines.push(t('diff.release.routeSitemapAdded', { path: r.path }));
362
+ for (const r of s.routes.sitemap?.removed ?? [])
363
+ lines.push(t('diff.release.routeSitemapRemoved', { path: r.path }));
364
+ for (const r of s.redirects?.added ?? [])
365
+ lines.push(t('diff.release.redirectAdded', { from: r.from, to: r.to, status: r.status }));
366
+ for (const r of s.redirects?.removed ?? [])
367
+ lines.push(t('diff.release.redirectRemoved', { from: r.from, to: r.to }));
368
+ for (const { after } of s.redirects?.changed ?? []) {
369
+ lines.push(t('diff.release.redirectChanged', { from: after.from, to: after.to, status: after.status }));
370
+ }
341
371
  if (lines.length === 0)
342
372
  lines.push(t('diff.release.nothing'));
343
373
  if (s.secrets.length > 0)
package/dist/index.d.ts CHANGED
@@ -39,9 +39,9 @@ export { extractRelease, loadRelease, openRelease, readRelease, type LoadedRelea
39
39
  export { InlayError } from './core/errors.js';
40
40
  export { defineField, type AdminWidget, type FieldMeta, type FormValues, type WidgetProps, } from './core/fields/define.js';
41
41
  export { defineContent, defineEntries, type ShippedContent, type ShippedDocument, type ShippedDocumentRef, } from './core/registry/content.js';
42
- export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, type AdminSettings, type BlockDef, type CollectionDef, type GlobalDef, type SingletonDef, type SingletonPath, type SiteDefinition, type SiteInput, type SlotDef, type TemplateDef, type TemplateRenderProps, type TypeDef, } from './core/registry/define.js';
42
+ export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, type AdminSettings, type BlockDef, type CollectionDef, type GlobalDef, type SingletonDef, type SingletonPath, type SiteDefinition, type RedirectDef, type SiteInput, type SlotDef, type TemplateDef, type TemplateRenderProps, type TypeDef, } from './core/registry/define.js';
43
43
  export { defineRoute, type QueryApi, type RouteContext, type RouteDef, type RouteMethod, type RouteRequest, type RouteResponse, } from './core/registry/route.js';
44
44
  export { defineMigration, type MigrationContext, type MigrationDocument, type ReleaseMigration, } from './core/registry/migration.js';
45
45
  export type { Gap, GapFilter, GapSummary } from './core/content/gaps.js';
46
46
  export type { HiddenContent, HiddenDocuments } from './core/content/hidden.js';
47
- export type { Activity, Actor, ContentInput, ContentIssue, ContentRef, Ctx, DiffEntry, DocumentData, DocumentKind, DocumentSummary, DocumentView, FileValue, ImageValue, IssueCode, LinkValue, LiveDocument, LiveState, MediaInfo, MediaStatus, PathSegment, Redirect, RedirectInput, RedirectSource, RevisionMeta, RevisionSource, Role, ShippedFile, UploadLimits, Usage, } from './core/types.js';
47
+ export type { Activity, Actor, CodeRedirect, ContentInput, ContentIssue, ContentRef, Ctx, DiffEntry, DocumentData, DocumentKind, DocumentSummary, DocumentView, FileValue, ImageValue, IssueCode, LinkValue, LiveDocument, LiveState, MediaInfo, MediaStatus, PathSegment, Redirect, RedirectInput, RedirectSource, RevisionMeta, RevisionSource, Role, ShippedFile, UploadLimits, Usage, } from './core/types.js';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The type of a `.md` file a site imports (`import post from './posts/x.md'`): its text, with relative image targets
3
+ * already pointing at their files. A script file, so the declaration is global wherever it is referenced.
4
+ */
5
+ declare module '*.md' {
6
+ const text: string;
7
+ export default text;
8
+ }
@@ -0,0 +1 @@
1
+ "use strict";
package/dist/site.d.ts CHANGED
@@ -1,17 +1,22 @@
1
+ /// <reference path="markdown-modules.d.ts" preserve="true" />
1
2
  /**
2
3
  * What a site's code imports (`inlaycms/site`): the definitions and the types
3
4
  * templates, routes and migrations use, and nothing that reaches the server.
4
5
  * A release may import only this and the JSX runtime.
5
6
  */
7
+ import { type RichTextDoc } from './core/richtext/schema.js';
6
8
  export { z } from 'zod';
7
9
  export { f } from './core/fields/builtins.js';
8
10
  export { defineConfig, type InlayConfig } from './config.js';
9
11
  export { escapeHtml, raw, SafeHtml, type Html, type Renderable } from './jsx/html.js';
10
12
  export { defineField, type AdminWidget, type FieldMeta, type FormValues, type WidgetProps } from './core/fields/define.js';
11
13
  export { defineContent, defineEntries, type ShippedContent, type ShippedDocument, type ShippedDocumentRef, } from './core/registry/content.js';
12
- export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, type AdminSettings, type BlockDef, type CollectionDef, type GlobalDef, type SingletonDef, type SingletonPath, type SiteDefinition, type SiteInput, type SlotDef, type TemplateDef, type TemplateRenderProps, type TypeDef, } from './core/registry/define.js';
14
+ export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, type AdminSettings, type BlockDef, type CollectionDef, type GlobalDef, type SingletonDef, type SingletonPath, type SiteDefinition, type OgType, type RedirectDef, type SeoSettings, type SiteInput, type SlotDef, type TemplateDef, type TemplateRenderProps, type TypeDef, } from './core/registry/define.js';
13
15
  export { defineRoute, type QueryApi, type RouteContext, type RouteDef, type RouteMethod, type RouteRequest, type RouteResponse, } from './core/registry/route.js';
14
16
  export { defineMigration, type MigrationContext, type MigrationDocument, type ReleaseMigration, } from './core/registry/migration.js';
15
- export type { Entry, PageInfo, QueryOptions, QueryResult, RenderContext, ResolvedFile, ResolvedImage, ResolvedLink, } from './core/registry/render.js';
17
+ export type { Entry, HeadApi, HeadLink, HeadMeta, PageInfo, QueryOptions, QueryResult, RenderContext, ResolvedFile, ResolvedImage, ResolvedLink, } from './core/registry/render.js';
16
18
  export type { AdminTheme, ContentInput, CustomTheme, DocumentData, FileValue, ImageValue, LinkValue, MediaInfo, ShippedFile, ThemeColor, } from './core/types.js';
17
- export type { RichTextDoc, RichTextFeature, RichTextOptions } from './core/richtext/schema.js';
19
+ /** The text of a rich-text or inline-text value without its formatting; `''` for `null` or `undefined`. */
20
+ export declare function plainText(doc: RichTextDoc | null | undefined): string;
21
+ export type { RichTextDoc };
22
+ export type { RichTextFeature, RichTextOptions } from './core/richtext/schema.js';
package/dist/site.js CHANGED
@@ -1,8 +1,10 @@
1
+ /// <reference path="./markdown-modules.ts" preserve="true" />
1
2
  /**
2
3
  * What a site's code imports (`inlaycms/site`): the definitions and the types
3
4
  * templates, routes and migrations use, and nothing that reaches the server.
4
5
  * A release may import only this and the JSX runtime.
5
6
  */
7
+ import { richTextText } from './core/richtext/schema.js';
6
8
  export { z } from 'zod';
7
9
  export { f } from './core/fields/builtins.js';
8
10
  export { defineConfig } from './config.js';
@@ -12,3 +14,7 @@ export { defineContent, defineEntries, } from './core/registry/content.js';
12
14
  export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, } from './core/registry/define.js';
13
15
  export { defineRoute, } from './core/registry/route.js';
14
16
  export { defineMigration, } from './core/registry/migration.js';
17
+ /** The text of a rich-text or inline-text value without its formatting; `''` for `null` or `undefined`. */
18
+ export function plainText(doc) {
19
+ return doc ? richTextText(doc) : '';
20
+ }
@@ -0,0 +1,22 @@
1
+ export interface TestSiteOptions {
2
+ /** The site's inlay.config.ts: a path relative to process.cwd(), or a file: URL (a URL, or a string starting with file:). */
3
+ config: string | URL;
4
+ /** Used for canonical, Open Graph and sitemap URLs. Default http://localhost. */
5
+ baseUrl?: string;
6
+ /** Values for the site's declared secrets. */
7
+ secrets?: Record<string, string>;
8
+ /** What routes get as ctx.fetch. Default: the global fetch. */
9
+ fetch?: typeof fetch;
10
+ /** The clock. Default: real time. */
11
+ now?: () => Date;
12
+ }
13
+ export interface TestSite {
14
+ fetch(path: string, init?: RequestInit): Promise<Response>;
15
+ paths(): Promise<string[]>;
16
+ close(): Promise<void>;
17
+ }
18
+ /**
19
+ * Boots the site of an `inlay.config.ts` the way `inlaycms dev` does, in a temporary data folder, and answers its
20
+ * requests in process (Fastify `inject`): no port, no child process. `close()` stops it and removes the folder.
21
+ */
22
+ export declare function createTestSite(opts: TestSiteOptions): Promise<TestSite>;