inlaycms 0.4.1 → 0.6.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 (151) hide show
  1. package/README.md +18 -709
  2. package/assets/admin/admin.css +1 -1
  3. package/assets/admin/admin.js +1 -1
  4. package/assets/admin/editor.js +63 -46
  5. package/assets/site/consent.js +1 -0
  6. package/dist/adapters/admin/context.d.ts +1 -1
  7. package/dist/adapters/admin/context.js +1 -0
  8. package/dist/adapters/admin/publish.js +2 -2
  9. package/dist/adapters/admin/routes.d.ts +2 -0
  10. package/dist/adapters/admin/routes.js +2 -0
  11. package/dist/adapters/admin/screens/backups.js +2 -2
  12. package/dist/adapters/admin/screens/editor.js +5 -2
  13. package/dist/adapters/admin/screens/integrations.d.ts +4 -0
  14. package/dist/adapters/admin/screens/integrations.js +140 -0
  15. package/dist/adapters/admin/screens/lists.js +2 -1
  16. package/dist/adapters/admin/screens/releases.js +9 -4
  17. package/dist/adapters/admin/views/data-table.js +1 -1
  18. package/dist/adapters/admin/views/layout.d.ts +1 -1
  19. package/dist/adapters/admin/views/layout.js +15 -2
  20. package/dist/adapters/cli/bin.js +8 -3
  21. package/dist/adapters/cli/main.js +12 -2
  22. package/dist/adapters/mcp/agent-refs.d.ts +2 -1
  23. package/dist/adapters/mcp/agent-refs.js +4 -4
  24. package/dist/adapters/mcp/tools/publish.js +1 -1
  25. package/dist/adapters/mcp/tools/read.js +19 -4
  26. package/dist/adapters/mcp/tools/write.js +5 -1
  27. package/dist/adapters/site/cache.d.ts +8 -2
  28. package/dist/adapters/site/cache.js +13 -4
  29. package/dist/adapters/site/code-files.d.ts +44 -0
  30. package/dist/adapters/site/code-files.js +212 -0
  31. package/dist/adapters/site/consent.d.ts +9 -0
  32. package/dist/adapters/site/consent.js +26 -0
  33. package/dist/adapters/site/context.d.ts +9 -1
  34. package/dist/adapters/site/context.js +106 -27
  35. package/dist/adapters/site/csp.d.ts +11 -0
  36. package/dist/adapters/site/csp.js +36 -0
  37. package/dist/adapters/site/head.d.ts +2 -0
  38. package/dist/adapters/site/head.js +7 -20
  39. package/dist/adapters/site/headers.d.ts +5 -2
  40. package/dist/adapters/site/headers.js +13 -6
  41. package/dist/adapters/site/integrations.d.ts +48 -0
  42. package/dist/adapters/site/integrations.js +118 -0
  43. package/dist/adapters/site/media-routes.d.ts +2 -0
  44. package/dist/adapters/site/media-routes.js +2 -1
  45. package/dist/adapters/site/plugin.d.ts +2 -0
  46. package/dist/adapters/site/plugin.js +78 -40
  47. package/dist/adapters/site/preview.d.ts +2 -0
  48. package/dist/adapters/site/preview.js +10 -5
  49. package/dist/adapters/site/render.d.ts +31 -14
  50. package/dist/adapters/site/render.js +33 -7
  51. package/dist/adapters/site/routes.d.ts +3 -0
  52. package/dist/adapters/site/routes.js +11 -6
  53. package/dist/adapters/site/scripts.d.ts +6 -0
  54. package/dist/adapters/site/scripts.js +27 -0
  55. package/dist/adapters/site/sitemap.d.ts +2 -1
  56. package/dist/adapters/site/sitemap.js +3 -3
  57. package/dist/core/auth/roles.d.ts +1 -1
  58. package/dist/core/auth/roles.js +1 -0
  59. package/dist/core/boot.d.ts +2 -0
  60. package/dist/core/boot.js +3 -0
  61. package/dist/core/content/shipped-input.js +1 -2
  62. package/dist/core/content/validate.d.ts +7 -0
  63. package/dist/core/content/validate.js +24 -1
  64. package/dist/core/core.d.ts +29 -0
  65. package/dist/core/core.js +10 -2
  66. package/dist/core/db/migrate.js +2 -0
  67. package/dist/core/db/migrations/0008_integrations.d.ts +3 -0
  68. package/dist/core/db/migrations/0008_integrations.js +11 -0
  69. package/dist/core/db/schema.d.ts +11 -0
  70. package/dist/core/export/export.js +4 -0
  71. package/dist/core/export/format.d.ts +11 -0
  72. package/dist/core/export/format.js +4 -0
  73. package/dist/core/export/import.js +2 -1
  74. package/dist/core/export/replace.d.ts +6 -1
  75. package/dist/core/export/replace.js +4 -1
  76. package/dist/core/export/report.d.ts +6 -0
  77. package/dist/core/export/report.js +7 -0
  78. package/dist/core/fields/builtins.d.ts +4 -0
  79. package/dist/core/fields/builtins.js +11 -1
  80. package/dist/core/fields/widgets.js +5 -1
  81. package/dist/core/integrations/integrations.d.ts +32 -0
  82. package/dist/core/integrations/integrations.js +80 -0
  83. package/dist/core/integrations/warnings.d.ts +4 -0
  84. package/dist/core/integrations/warnings.js +29 -0
  85. package/dist/core/media/store.d.ts +2 -0
  86. package/dist/core/media/store.js +17 -1
  87. package/dist/core/media/variants.d.ts +14 -0
  88. package/dist/core/media/variants.js +54 -0
  89. package/dist/core/messages/en.d.ts +83 -2
  90. package/dist/core/messages/en.js +83 -2
  91. package/dist/core/registry/code-image.d.ts +16 -0
  92. package/dist/core/registry/code-image.js +13 -0
  93. package/dist/core/registry/define.d.ts +12 -0
  94. package/dist/core/registry/define.js +3 -0
  95. package/dist/core/registry/designed.d.ts +6 -0
  96. package/dist/core/registry/designed.js +8 -0
  97. package/dist/core/registry/integration.d.ts +48 -0
  98. package/dist/core/registry/integration.js +29 -0
  99. package/dist/core/registry/js.d.ts +9 -0
  100. package/dist/core/registry/js.js +39 -0
  101. package/dist/core/registry/registry.js +46 -0
  102. package/dist/core/registry/render.d.ts +45 -5
  103. package/dist/core/release/bundle.d.ts +3 -1
  104. package/dist/core/release/bundle.js +169 -11
  105. package/dist/core/release/manifest.d.ts +29 -6
  106. package/dist/core/release/manifest.js +26 -25
  107. package/dist/core/release/pack.js +13 -2
  108. package/dist/core/release/pointer.js +14 -3
  109. package/dist/core/release/read.d.ts +4 -2
  110. package/dist/core/release/read.js +12 -12
  111. package/dist/core/release/window.d.ts +11 -0
  112. package/dist/core/release/window.js +34 -0
  113. package/dist/core/report.d.ts +3 -0
  114. package/dist/core/richtext/headings.d.ts +10 -0
  115. package/dist/core/richtext/headings.js +37 -0
  116. package/dist/core/richtext/html.d.ts +10 -1
  117. package/dist/core/richtext/html.js +17 -6
  118. package/dist/core/richtext/markdown-text.d.ts +24 -0
  119. package/dist/core/richtext/markdown-text.js +38 -0
  120. package/dist/core/richtext/markdown.js +44 -3
  121. package/dist/core/richtext/schema.d.ts +12 -3
  122. package/dist/core/richtext/schema.js +34 -0
  123. package/dist/core/site/live.d.ts +6 -0
  124. package/dist/core/site/live.js +25 -0
  125. package/dist/core/site/paths.d.ts +5 -0
  126. package/dist/core/site/paths.js +32 -0
  127. package/dist/core/site/resolve.js +17 -6
  128. package/dist/core/version.d.ts +4 -0
  129. package/dist/core/version.js +4 -0
  130. package/dist/host/activate.js +2 -1
  131. package/dist/host/app.d.ts +2 -0
  132. package/dist/host/app.js +1 -0
  133. package/dist/host/diff.d.ts +11 -0
  134. package/dist/host/diff.js +40 -0
  135. package/dist/host/ipc.d.ts +2 -0
  136. package/dist/host/ipc.js +5 -1
  137. package/dist/host/preview-worker.js +2 -2
  138. package/dist/host/primary.js +15 -4
  139. package/dist/host/push.d.ts +5 -1
  140. package/dist/host/push.js +18 -6
  141. package/dist/host/serve.js +1 -1
  142. package/dist/host/store.d.ts +1 -2
  143. package/dist/host/store.js +32 -6
  144. package/dist/host/worker.js +9 -3
  145. package/dist/image-modules.d.ts +29 -0
  146. package/dist/image-modules.js +1 -0
  147. package/dist/index.d.ts +7 -1
  148. package/dist/index.js +4 -0
  149. package/dist/site.d.ts +9 -2
  150. package/dist/site.js +5 -0
  151. package/package.json +5 -1
@@ -1 +1,5 @@
1
1
  export declare function inlayVersion(): string;
2
+ /** The oldest Inlay version whose releases this one still runs. See the upgrades spec and CLAUDE.md. */
3
+ export declare const OLDEST_RELEASE = "0.5.0";
4
+ /** The oldest version the next window will keep, when already decided: older releases get a "pack again" warning. */
5
+ export declare const NEXT_OLDEST_RELEASE: string | null;
@@ -3,3 +3,7 @@ export function inlayVersion() {
3
3
  const url = new URL('../../package.json', import.meta.url);
4
4
  return JSON.parse(readFileSync(url, 'utf8')).version;
5
5
  }
6
+ /** The oldest Inlay version whose releases this one still runs. See the upgrades spec and CLAUDE.md. */
7
+ export const OLDEST_RELEASE = '0.5.0';
8
+ /** The oldest version the next window will keep, when already decided: older releases get a "pack again" warning. */
9
+ export const NEXT_OLDEST_RELEASE = null;
@@ -8,6 +8,7 @@ import { DEFAULT_MAX_BYTES, DEFAULT_UPLOAD_TYPES } from '../core/media/detect.js
8
8
  import { fileMediaStore } from '../core/media/store.js';
9
9
  import { buildRegistry } from '../core/registry/registry.js';
10
10
  import { checkInlayVersion } from '../core/release/read.js';
11
+ import { packedVersion } from '../core/release/window.js';
11
12
  import { currentRelease, getRelease, readCurrentPointer, writeCurrentPointer } from './store.js';
12
13
  const noShipped = () => ({ created: [], replaced: [], skipped: [], deletedRefs: [], warnings: [] });
13
14
  /** An activation's result as counts, for the worker that asked for it. */
@@ -105,7 +106,7 @@ export async function activateRelease(deps, releaseId) {
105
106
  throw new InlayError('not_found', 'error.releaseUnknown', { id: releaseId });
106
107
  if (row.state === 'deleted')
107
108
  throw new InlayError('release', 'error.releaseDeleted', { name: row.name });
108
- checkInlayVersion(row.inlay_range);
109
+ checkInlayVersion(packedVersion(row.inlay_range));
109
110
  if (row.state === 'current') {
110
111
  // A retry after a commit whose pointer write was lost: the database already says it's current.
111
112
  const pointer = await readCurrentPointer(deps.releasesDir).catch(() => null);
@@ -13,6 +13,8 @@ export interface SiteSource {
13
13
  publicDir: string | null;
14
14
  /** Each shipped file's source as the site names it, to the file to read. */
15
15
  shippedFiles?: ReadonlyMap<string, string>;
16
+ /** As `shippedFiles`, only the images `.md` files the site imports name. */
17
+ codeFiles?: ReadonlyMap<string, string>;
16
18
  }
17
19
  /** The source of a site run from its code (`inlaycms dev` and `inlaycms/testing`): its `public/` folder, if it has one. */
18
20
  export declare function sourceFromConfig(loaded: LoadedConfig): SiteSource;
package/dist/host/app.js CHANGED
@@ -98,6 +98,7 @@ export async function createSiteApp(config, source, opts) {
98
98
  ...(opts.fetch && { fetch: opts.fetch }),
99
99
  content: opts.content,
100
100
  ...(source?.shippedFiles && { shippedFiles: source.shippedFiles }),
101
+ ...(source?.codeFiles && { codeFiles: source.codeFiles }),
101
102
  ...(opts.now && { now: opts.now }),
102
103
  ...(opts.host && { host: opts.host }),
103
104
  ...(opts.readOnly && { readOnly: true }),
@@ -66,6 +66,17 @@ export interface StructuralDiff {
66
66
  after: ManifestRedirect;
67
67
  }>;
68
68
  };
69
+ /** Integrations by name; `changed` when the label, consent category or sources differ. Absent from an older host. */
70
+ integrations?: {
71
+ added: string[];
72
+ removed: string[];
73
+ changed: string[];
74
+ };
75
+ /** What the site may newly load and no longer may, as `<directive> <source>`, over the site's sources and every integration's. */
76
+ csp?: {
77
+ added: string[];
78
+ removed: string[];
79
+ };
69
80
  /** Every secret the staged release needs. */
70
81
  secrets: string[];
71
82
  /** Every migration function of the staged release, in order. */
package/dist/host/diff.js CHANGED
@@ -257,6 +257,21 @@ export function structuralDiff(current, staged) {
257
257
  for (const [from, before] of curRedirects)
258
258
  if (!stagedRedirects.has(from))
259
259
  redirects.removed.push(before);
260
+ const curIntegrations = new Map((current?.integrations ?? []).map((i) => [i.name, i]));
261
+ const stagedIntegrations = new Map((staged.integrations ?? []).map((i) => [i.name, i]));
262
+ const integrations = { added: [], removed: [], changed: [] };
263
+ for (const [name, after] of stagedIntegrations) {
264
+ const before = curIntegrations.get(name);
265
+ if (!before)
266
+ integrations.added.push(name);
267
+ else if (canonicalJson(before) !== canonicalJson(after))
268
+ integrations.changed.push(name);
269
+ }
270
+ for (const name of curIntegrations.keys())
271
+ if (!stagedIntegrations.has(name))
272
+ integrations.removed.push(name);
273
+ const curCsp = cspSources(current);
274
+ const stagedCsp = cspSources(staged);
260
275
  const listed = new Set((current?.routes ?? []).filter((r) => r.sitemap === true).map(routeKey));
261
276
  return {
262
277
  types: { added: added(curNames, stagedNames), removed: added(stagedNames, curNames), changed },
@@ -272,11 +287,26 @@ export function structuralDiff(current, staged) {
272
287
  },
273
288
  },
274
289
  redirects,
290
+ integrations,
291
+ csp: { added: added(curCsp, stagedCsp), removed: added(stagedCsp, curCsp) },
275
292
  secrets: [...staged.secrets],
276
293
  migrations: [...staged.migrations],
277
294
  shipped: { stale },
278
295
  };
279
296
  }
297
+ /** Every `<directive> <source>` a manifest lets the site load, its own and its integrations'. */
298
+ function cspSources(m) {
299
+ const out = new Set();
300
+ const add = (csp) => {
301
+ for (const [directive, sources] of Object.entries(csp ?? {}))
302
+ for (const source of sources)
303
+ out.add(`${directive} ${source}`);
304
+ };
305
+ add(m?.csp);
306
+ for (const i of m?.integrations ?? [])
307
+ add(i.csp);
308
+ return [...out];
309
+ }
280
310
  /** How a line names a shipped document: a singleton by its type, an entry as `type/key`. */
281
311
  const docName = (type, key) => (key === type ? type : `${type}/${key}`);
282
312
  /** A field's path as a line shows it: `seo.title` for the type's own fields, `slots.hero.headline` for a slot's. */
@@ -368,6 +398,16 @@ export function formatDiff(diff) {
368
398
  for (const { after } of s.redirects?.changed ?? []) {
369
399
  lines.push(t('diff.release.redirectChanged', { from: after.from, to: after.to, status: after.status }));
370
400
  }
401
+ for (const name of s.integrations?.added ?? [])
402
+ lines.push(t('diff.release.integrationAdded', { name }));
403
+ for (const name of s.integrations?.removed ?? [])
404
+ lines.push(t('diff.release.integrationRemoved', { name }));
405
+ for (const name of s.integrations?.changed ?? [])
406
+ lines.push(t('diff.release.integrationChanged', { name }));
407
+ for (const source of s.csp?.added ?? [])
408
+ lines.push(t('diff.release.cspAdded', { source }));
409
+ for (const source of s.csp?.removed ?? [])
410
+ lines.push(t('diff.release.cspRemoved', { source }));
371
411
  if (lines.length === 0)
372
412
  lines.push(t('diff.release.nothing'));
373
413
  if (s.secrets.length > 0)
@@ -121,3 +121,5 @@ export declare function isPrimaryMessage(m: unknown): m is PrimaryMessage;
121
121
  */
122
122
  export declare function activationError(error: IpcError): InlayError;
123
123
  export declare function toIpcError(e: unknown): IpcError;
124
+ /** Whether `dir` is a push's scratch folder: `.push-*` right inside the releases folder. */
125
+ export declare function isScratchDir(releasesDir: string, dir: string): boolean;
package/dist/host/ipc.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { join } from 'node:path';
2
+ import { basename, dirname, join, resolve } from 'node:path';
3
3
  import { InlayError } from '../core/errors.js';
4
4
  import { en } from '../core/messages/en.js';
5
5
  /**
@@ -59,3 +59,7 @@ export function toIpcError(e) {
59
59
  return { code: e.code, message: e.message, messageId: e.messageId, params: e.params };
60
60
  return { code: 'release', message: e instanceof Error ? e.message : String(e) };
61
61
  }
62
+ /** Whether `dir` is a push's scratch folder: `.push-*` right inside the releases folder. */
63
+ export function isScratchDir(releasesDir, dir) {
64
+ return resolve(dirname(dir)) === resolve(releasesDir) && /^\.push-[A-Za-z0-9_-]+$/.test(basename(dir));
65
+ }
@@ -8,8 +8,8 @@ import { InlayError } from '../core/errors.js';
8
8
  import { t } from '../core/messages/index.js';
9
9
  import { loadRelease } from '../core/release/read.js';
10
10
  import { createSiteApp } from './app.js';
11
- import { previewSocket, toIpcError } from './ipc.js';
12
- import { getRelease, isScratchDir, releaseDir } from './store.js';
11
+ import { isScratchDir, previewSocket, toIpcError } from './ipc.js';
12
+ import { getRelease, releaseDir } from './store.js';
13
13
  /** Where the preview of `releaseId` keeps its copy of the database (`dir`) and listens (`socket`). */
14
14
  export function previewPaths(config, releaseId) {
15
15
  return { dir: join(config.dataDir, 'run', `preview-${releaseId}`), socket: previewSocket(config.dataDir, releaseId) };
@@ -1,7 +1,7 @@
1
1
  import { InlayError } from '../core/errors.js';
2
2
  import { t } from '../core/messages/index.js';
3
- import { ACTIVATION_TIMEOUT_MS, activationError, PREVIEW_IDLE_MS, PREVIEW_START_TIMEOUT_MS, previewSocket, toIpcError, } from './ipc.js';
4
- import { isScratchDir, readCurrentPointer } from './store.js';
3
+ import { readCurrentPointer } from '../core/release/pointer.js';
4
+ import { ACTIVATION_TIMEOUT_MS, activationError, isScratchDir, PREVIEW_IDLE_MS, PREVIEW_START_TIMEOUT_MS, previewSocket, toIpcError, } from './ipc.js';
5
5
  /** A current worker that stops unexpectedly is started again at most this many times within the window. */
6
6
  export const RESTART_LIMIT = 5;
7
7
  export const RESTART_WINDOW_MS = 10 * 60_000;
@@ -239,10 +239,15 @@ export function createSupervisor(config, deps) {
239
239
  forget(releaseId, preview);
240
240
  void shutdown(preview.tracked);
241
241
  }
242
- /** Previews run on a copy of the database made when they started: after an activation every one is out of date. */
242
+ /**
243
+ * Previews run on a copy of the database made when they started: after an activation every one is out of date.
244
+ * Resolves once they have all exited.
245
+ */
243
246
  function stopPreviews() {
247
+ const exits = [...previews.values()].map((preview) => preview.tracked.exited);
244
248
  for (const releaseId of [...previews.keys()])
245
249
  stopPreview(releaseId);
250
+ return Promise.all(exits).then(() => { });
246
251
  }
247
252
  /**
248
253
  * Waits for an activation worker: ready, or the failure it reports, or its exit. Once it said `activated`, the
@@ -294,6 +299,11 @@ export function createSupervisor(config, deps) {
294
299
  });
295
300
  }
296
301
  async function swap(releaseId, onSwapped) {
302
+ if (stopping)
303
+ throw new InlayError('invalid_operation', 'error.hostStopping');
304
+ // The previews go first, even if the activation then fails (the next request starts them again): with them
305
+ // running, a swap would hold a whole worker more in memory for each.
306
+ await stopPreviews();
297
307
  if (stopping)
298
308
  throw new InlayError('invalid_operation', 'error.hostStopping');
299
309
  const next = spawn(workerEnv({ release: releaseId, activate: true }));
@@ -312,7 +322,8 @@ export function createSupervisor(config, deps) {
312
322
  }
313
323
  firstReady?.resolve();
314
324
  firstReady = null;
315
- stopPreviews();
325
+ // Any started during the swap.
326
+ void stopPreviews();
316
327
  onSwapped(activation);
317
328
  if (old)
318
329
  void shutdown(old);
@@ -62,7 +62,11 @@ export declare const RELEASE_NAME_MAX = 100;
62
62
  /** With `activate`, how long the content half of the diff may take in all (preview start and answer): the activation waits. */
63
63
  export declare const ACTIVATE_DIFF_TIMEOUT_MS = 10000;
64
64
  /** A release row as the push API sends it: without the schema JSON, which is only kept for the record. */
65
- export type ReleaseInfo = Omit<ReleaseRow, 'schema'>;
65
+ export type ReleaseInfo = Omit<ReleaseRow, 'schema'> & {
66
+ warning?: string;
67
+ };
68
+ /** The advance "pack again" warning for a release packed with the version in `row.inlay_range`, or null. */
69
+ export declare function packAgainWarning(row: Pick<ReleaseRow, 'inlay_range' | 'state'>): string | null;
66
70
  export declare function releaseInfo(row: ReleaseRow): ReleaseInfo;
67
71
  /**
68
72
  * The manifest of what the site runs now: the current release's, or, for a site run from source with no current
package/dist/host/push.js CHANGED
@@ -9,6 +9,7 @@ import { openDatabase } from '../core/db/connection.js';
9
9
  import { InlayError } from '../core/errors.js';
10
10
  import { t } from '../core/messages/index.js';
11
11
  import { manifestOfRegistry, manifestSchema } from '../core/release/manifest.js';
12
+ import { packedVersion, releaseFit } from '../core/release/window.js';
12
13
  import { structuralDiff } from './diff.js';
13
14
  import { currentRelease, deleteRelease, getRelease, listReleases, releaseDir, storeRelease } from './store.js';
14
15
  /** The largest release file a push may send. */
@@ -23,9 +24,17 @@ const RELEASE_TYPES = new Set(['application/gzip', 'application/x-gzip', 'applic
23
24
  const DIFF_PATH = '/_inlay/internal/diff';
24
25
  const DIFF_TIMEOUT_MS = 60_000;
25
26
  const problemOf = (e) => (e instanceof Error ? e.message : String(e));
27
+ /** The advance "pack again" warning for a release packed with the version in `row.inlay_range`, or null. */
28
+ export function packAgainWarning(row) {
29
+ if (row.state === 'deleted')
30
+ return null;
31
+ const packed = packedVersion(row.inlay_range);
32
+ return releaseFit(packed) === 'warn' ? t('release.packAgain', { packed }) : null;
33
+ }
26
34
  export function releaseInfo(row) {
27
35
  const { schema: _schema, ...info } = row;
28
- return info;
36
+ const warning = packAgainWarning(row);
37
+ return warning === null ? info : { ...info, warning };
29
38
  }
30
39
  async function readManifest(file) {
31
40
  return manifestSchema.parse(JSON.parse(await readFile(file, 'utf8')));
@@ -161,12 +170,14 @@ export async function pushRelease(opts, file, push) {
161
170
  throw new InlayError('release', 'error.releaseSecretsMissing', { names: missing.join(', ') });
162
171
  const staged = await readManifest(join(releaseDir(work, row.id), 'manifest.json'));
163
172
  const structural = structuralDiff(await currentManifest(opts), staged);
173
+ const packed = staged.inlay.version;
174
+ const packAgain = releaseFit(packed) === 'warn' ? [t('push.packAgain', { packed })] : [];
164
175
  if (push.dryRun) {
165
176
  if (opts.host?.startPreview === undefined)
166
- return { release: null, diff: { structural, content: null }, warnings: [] };
177
+ return { release: null, diff: { structural, content: null }, warnings: packAgain };
167
178
  try {
168
179
  const { content, warnings } = await contentDiff(opts, row.id, { dir: work });
169
- return { release: null, diff: { structural, content }, warnings };
180
+ return { release: null, diff: { structural, content }, warnings: [...warnings, ...packAgain] };
170
181
  }
171
182
  finally {
172
183
  await opts.host.stopPreview?.(row.id).catch(() => { });
@@ -190,7 +201,7 @@ export async function pushRelease(opts, file, push) {
190
201
  }
191
202
  structural.migrations = await pendingMigrations(opts.db, row.id, structural.migrations);
192
203
  const { content, warnings } = await contentDiff(opts, row.id, push.activate ? { deadlineMs: opts.activateDiffTimeoutMs ?? ACTIVATE_DIFF_TIMEOUT_MS } : {});
193
- return { release: row, diff: { structural, content }, warnings };
204
+ return { release: row, diff: { structural, content }, warnings: [...warnings, ...packAgain] };
194
205
  }
195
206
  finally {
196
207
  await scratch.destroy();
@@ -249,7 +260,8 @@ function statusOf(e) {
249
260
  switch (e.messageId) {
250
261
  case 'error.releaseSignature':
251
262
  return 403;
252
- case 'error.releaseVersion':
263
+ case 'error.releaseTooOld':
264
+ case 'error.releaseTooNew':
253
265
  case 'error.releaseSecretsMissing':
254
266
  case 'error.releaseCurrent':
255
267
  case 'error.releaseDeleted':
@@ -407,7 +419,7 @@ export function registerPushRoutes(app, opts) {
407
419
  return reply;
408
420
  const { id } = request.params;
409
421
  try {
410
- await deleteRelease({ db, releasesDir }, id);
422
+ await deleteRelease({ db, releasesDir, mediaDir: opts.config.paths.media }, id);
411
423
  }
412
424
  catch (e) {
413
425
  return sendError(request, reply, e);
@@ -7,7 +7,6 @@ import { INLAY_BIN } from './bin.js';
7
7
  import { ensureDataDir, readHostConfig } from './config.js';
8
8
  import { isPrimaryMessage, isWorkerMessage } from './ipc.js';
9
9
  import { createSupervisor } from './primary.js';
10
- import { readWorkerEnv, runWorker } from './worker.js';
11
10
  function forkWorker(env) {
12
11
  const worker = cluster.fork(env);
13
12
  return {
@@ -60,6 +59,7 @@ async function worker(io) {
60
59
  // The primary decides when a worker stops; a signal sent to the whole process group must not cut requests off.
61
60
  process.on('SIGINT', () => { });
62
61
  process.on('SIGTERM', () => { });
62
+ const { readWorkerEnv, runWorker } = await import('./worker.js');
63
63
  let sent = Promise.resolve();
64
64
  const exit = (code) => void sent.then(() => process.exit(code));
65
65
  const config = readConfig(io);
@@ -3,8 +3,6 @@ import type { Database, ReleasesTable } from '../core/db/schema.js';
3
3
  import { type CurrentPointer } from '../core/release/pointer.js';
4
4
  import { type LoadedRelease } from '../core/release/read.js';
5
5
  export { readCurrentPointer, releaseDir, releasesDirOf, removeCurrentPointer, writeCurrentPointer, type CurrentPointer, } from '../core/release/pointer.js';
6
- /** Whether `dir` is a push's scratch folder: `.push-*` right inside the releases folder. */
7
- export declare function isScratchDir(releasesDir: string, dir: string): boolean;
8
6
  /** A `releases` row with its secret names parsed. `schema` stays the JSON text it was stored as. */
9
7
  export interface ReleaseRow extends Omit<Selectable<ReleasesTable>, 'secrets'> {
10
8
  secrets: string[];
@@ -31,6 +29,7 @@ export declare function currentRelease(db: Kysely<Database>): Promise<ReleaseRow
31
29
  export declare function deleteRelease(deps: {
32
30
  db: Kysely<Database>;
33
31
  releasesDir: string;
32
+ mediaDir?: string;
34
33
  }, id: string): Promise<void>;
35
34
  /**
36
35
  * Loads the current release for a worker: null with no pointer, `missing` when the pointer names a release whose
@@ -1,16 +1,13 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
2
  import { createReadStream, existsSync } from 'node:fs';
3
- import { copyFile, mkdir, rm } from 'node:fs/promises';
4
- import { basename, dirname, join, resolve } from 'node:path';
3
+ import { copyFile, mkdir, readFile, rm } from 'node:fs/promises';
4
+ import { extname, join } from 'node:path';
5
5
  import { sql } from 'kysely';
6
6
  import { InlayError } from '../core/errors.js';
7
+ import { sweepCodeVariants } from '../core/media/store.js';
7
8
  import { readCurrentPointer, releaseDir } from '../core/release/pointer.js';
8
9
  import { loadRelease, openRelease } from '../core/release/read.js';
9
10
  export { readCurrentPointer, releaseDir, releasesDirOf, removeCurrentPointer, writeCurrentPointer, } from '../core/release/pointer.js';
10
- /** Whether `dir` is a push's scratch folder: `.push-*` right inside the releases folder. */
11
- export function isScratchDir(releasesDir, dir) {
12
- return resolve(dirname(dir)) === resolve(releasesDir) && /^\.push-[A-Za-z0-9_-]+$/.test(basename(dir));
13
- }
14
11
  function toRow(row) {
15
12
  return { ...row, secrets: JSON.parse(row.secrets) };
16
13
  }
@@ -93,6 +90,35 @@ export async function deleteRelease(deps, id) {
93
90
  if (row)
94
91
  await rm(join(deps.releasesDir, row.file), { force: true });
95
92
  await rm(releaseDir(deps.releasesDir, id), { recursive: true, force: true });
93
+ if (deps.mediaDir === undefined)
94
+ return;
95
+ try {
96
+ await sweepUnusedCodeVariants(deps.db, deps.releasesDir, deps.mediaDir);
97
+ }
98
+ catch {
99
+ // Best effort: the release is gone either way, and the next delete sweeps again.
100
+ }
101
+ }
102
+ /** Removes the cached variants of code images that no remaining release names. */
103
+ async function sweepUnusedCodeVariants(db, releasesDir, mediaDir) {
104
+ const keep = new Set();
105
+ for (const row of await listReleases(db)) {
106
+ if (row.state === 'deleted')
107
+ continue;
108
+ try {
109
+ const manifest = JSON.parse(await readFile(join(releaseDir(releasesDir, row.id), 'manifest.json'), 'utf8'));
110
+ for (const entry of manifest.content ?? []) {
111
+ if (entry.code !== true || typeof entry.path !== 'string')
112
+ continue;
113
+ const name = entry.path.slice(entry.path.lastIndexOf('/') + 1);
114
+ keep.add(name.slice(0, name.length - extname(name).length));
115
+ }
116
+ }
117
+ catch {
118
+ continue;
119
+ }
120
+ }
121
+ await sweepCodeVariants(mediaDir, keep);
96
122
  }
97
123
  /**
98
124
  * Loads the current release for a worker: null with no pointer, `missing` when the pointer names a release whose
@@ -5,6 +5,7 @@ import { openDatabase } from '../core/db/connection.js';
5
5
  import { InlayError } from '../core/errors.js';
6
6
  import { t } from '../core/messages/index.js';
7
7
  import { checkInlayVersion, loadRelease } from '../core/release/read.js';
8
+ import { packedVersion, releaseFit } from '../core/release/window.js';
8
9
  import { activateRelease, summarize } from './activate.js';
9
10
  import { createSiteApp } from './app.js';
10
11
  import { drainable } from './drain.js';
@@ -82,12 +83,14 @@ async function chooseRelease(config, log) {
82
83
  log('host.pointerRepaired', { name: row.name });
83
84
  }
84
85
  try {
85
- checkInlayVersion(row.inlay_range);
86
+ checkInlayVersion(packedVersion(row.inlay_range));
86
87
  }
87
88
  catch (e) {
88
- if (!(e instanceof InlayError) || e.messageId !== 'error.releaseVersion')
89
+ if (!(e instanceof InlayError))
89
90
  throw e;
90
- log('host.releaseVersion', { ...e.params, name: row.name });
91
+ if (e.messageId !== 'error.releaseTooOld' && e.messageId !== 'error.releaseTooNew')
92
+ throw e;
93
+ log(e.messageId === 'error.releaseTooOld' ? 'host.releaseTooOld' : 'host.releaseTooNew', { ...e.params, name: row.name });
91
94
  return { page: 'unavailable', id: row.id };
92
95
  }
93
96
  const opened = await openCurrentRelease({ releasesDir: config.paths.releases });
@@ -95,6 +98,9 @@ async function chooseRelease(config, log) {
95
98
  log('host.releaseMissing', { name: row.name });
96
99
  return { page: 'unavailable', id: row.id };
97
100
  }
101
+ const packed = packedVersion(row.inlay_range);
102
+ if (releaseFit(packed) === 'warn')
103
+ log('host.releasePackAgain', { name: row.name, packed });
98
104
  return { loaded: opened.loaded, id: row.id, name: row.name };
99
105
  }
100
106
  /**
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The type of an image a site imports (`import hero from './hero.jpg'`): a `CodeImage` measured when the site is
3
+ * bundled, for `ctx.image`. One declaration per extension in `MARKDOWN_IMAGE_TYPES`. A script file, so the
4
+ * declarations are global wherever it is referenced.
5
+ */
6
+ declare module '*.png' {
7
+ const image: import('./core/registry/code-image.js').CodeImage;
8
+ export default image;
9
+ }
10
+ declare module '*.jpg' {
11
+ const image: import('./core/registry/code-image.js').CodeImage;
12
+ export default image;
13
+ }
14
+ declare module '*.jpeg' {
15
+ const image: import('./core/registry/code-image.js').CodeImage;
16
+ export default image;
17
+ }
18
+ declare module '*.gif' {
19
+ const image: import('./core/registry/code-image.js').CodeImage;
20
+ export default image;
21
+ }
22
+ declare module '*.webp' {
23
+ const image: import('./core/registry/code-image.js').CodeImage;
24
+ export default image;
25
+ }
26
+ declare module '*.avif' {
27
+ const image: import('./core/registry/code-image.js').CodeImage;
28
+ export default image;
29
+ }
@@ -0,0 +1 @@
1
+ "use strict";
package/dist/index.d.ts CHANGED
@@ -7,7 +7,8 @@ export type { CdnOptions } from './adapters/site/cache.js';
7
7
  export type { AuthInfo } from './adapters/mcp/route.js';
8
8
  export { AUTH_BASE_PATH } from './core/auth/auth.js';
9
9
  export { escapeHtml, raw, renderToString, SafeHtml, type Html, type Renderable } from './jsx/html.js';
10
- export type { Entry, PageInfo, QueryOptions, QueryResult, RenderContext, ResolvedFile, ResolvedImage, ResolvedLink, } from './core/registry/render.js';
10
+ export type { Entry, PageInfo, QueryOptions, QueryResult, RenderContext, ScriptApi, ScriptInput, ResolvedFile, ResolvedImage, ResolvedLink, } from './core/registry/render.js';
11
+ export type { CodeImage } from './core/registry/code-image.js';
11
12
  export { bootInlay, type BootOptions, type BootResult } from './core/boot.js';
12
13
  export { createBackup, listBackups, type BackupInfo, type BackupReason } from './core/backup/backup.js';
13
14
  export { restoreBackup, type RestoreBackupResult } from './core/backup/restore.js';
@@ -20,6 +21,10 @@ export { checkDatabase } from './core/check.js';
20
21
  export { defineConfig, type InlayConfig, type LoadedConfig } from './config.js';
21
22
  export { formatReport, type CheckProblem, type CheckReport } from './core/report.js';
22
23
  export { richTextToMarkdown, markdownToRichText, type RichTextProblem } from './core/richtext/markdown.js';
24
+ export { js, JsCode } from './core/registry/js.js';
25
+ export { richTextHeadings, type RichTextHeading } from './core/richtext/headings.js';
26
+ export { markdownHeadings } from './core/richtext/markdown-text.js';
27
+ export type { CodeHighlighter, RichTextRenderOptions } from './core/richtext/html.js';
23
28
  export type { RichTextDoc, RichTextFeature, RichTextOptions } from './core/richtext/schema.js';
24
29
  export { missingMediaLabel } from './core/media/labels.js';
25
30
  export { IMAGE_WIDTHS, type VariantFormat } from './core/media/variants.js';
@@ -40,6 +45,7 @@ export { InlayError } from './core/errors.js';
40
45
  export { defineField, type AdminWidget, type FieldMeta, type FormValues, type WidgetProps, } from './core/fields/define.js';
41
46
  export { defineContent, defineEntries, type ShippedContent, type ShippedDocument, type ShippedDocumentRef, } from './core/registry/content.js';
42
47
  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';
48
+ export { defineIntegration, type ConsentCategory, type CspDirective, type CspSources, type IntegrationDef, type IntegrationPage, type IntegrationRender, } from './core/registry/integration.js';
43
49
  export { defineRoute, type QueryApi, type RouteContext, type RouteDef, type RouteMethod, type RouteRequest, type RouteResponse, } from './core/registry/route.js';
44
50
  export { defineMigration, type MigrationContext, type MigrationDocument, type ReleaseMigration, } from './core/registry/migration.js';
45
51
  export type { Gap, GapFilter, GapSummary } from './core/content/gaps.js';
package/dist/index.js CHANGED
@@ -14,6 +14,9 @@ export { checkDatabase } from './core/check.js';
14
14
  export { defineConfig } from './config.js';
15
15
  export { formatReport } from './core/report.js';
16
16
  export { richTextToMarkdown, markdownToRichText } from './core/richtext/markdown.js';
17
+ export { js, JsCode } from './core/registry/js.js';
18
+ export { richTextHeadings } from './core/richtext/headings.js';
19
+ export { markdownHeadings } from './core/richtext/markdown-text.js';
17
20
  export { missingMediaLabel } from './core/media/labels.js';
18
21
  export { IMAGE_WIDTHS } from './core/media/variants.js';
19
22
  export { openDatabase } from './core/db/connection.js';
@@ -28,5 +31,6 @@ export { InlayError } from './core/errors.js';
28
31
  export { defineField, } from './core/fields/define.js';
29
32
  export { defineContent, defineEntries, } from './core/registry/content.js';
30
33
  export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, } from './core/registry/define.js';
34
+ export { defineIntegration, } from './core/registry/integration.js';
31
35
  export { defineRoute, } from './core/registry/route.js';
32
36
  export { defineMigration, } from './core/registry/migration.js';
package/dist/site.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference path="markdown-modules.d.ts" preserve="true" />
2
+ /// <reference path="image-modules.d.ts" preserve="true" />
2
3
  /**
3
4
  * What a site's code imports (`inlaycms/site`): the definitions and the types
4
5
  * templates, routes and migrations use, and nothing that reaches the server.
@@ -11,12 +12,18 @@ export { defineConfig, type InlayConfig } from './config.js';
11
12
  export { escapeHtml, raw, SafeHtml, type Html, type Renderable } from './jsx/html.js';
12
13
  export { defineField, type AdminWidget, type FieldMeta, type FormValues, type WidgetProps } from './core/fields/define.js';
13
14
  export { defineContent, defineEntries, type ShippedContent, type ShippedDocument, type ShippedDocumentRef, } from './core/registry/content.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';
15
+ 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 TrailingSlash, type TypeDef, } from './core/registry/define.js';
16
+ export { defineIntegration, type ConsentCategory, type CspDirective, type CspSources, type IntegrationDef, type IntegrationPage, type IntegrationRender, } from './core/registry/integration.js';
15
17
  export { defineRoute, type QueryApi, type RouteContext, type RouteDef, type RouteMethod, type RouteRequest, type RouteResponse, } from './core/registry/route.js';
16
18
  export { defineMigration, type MigrationContext, type MigrationDocument, type ReleaseMigration, } from './core/registry/migration.js';
17
- export type { Entry, HeadApi, HeadLink, HeadMeta, PageInfo, QueryOptions, QueryResult, RenderContext, ResolvedFile, ResolvedImage, ResolvedLink, } from './core/registry/render.js';
19
+ export type { Entry, HeadApi, HeadLink, HeadMeta, PageInfo, QueryOptions, QueryResult, RenderContext, ScriptApi, ScriptInput, ResolvedFile, ResolvedImage, ResolvedLink, } from './core/registry/render.js';
18
20
  export type { AdminTheme, ContentInput, CustomTheme, DocumentData, FileValue, ImageValue, LinkValue, MediaInfo, ShippedFile, ThemeColor, } from './core/types.js';
19
21
  /** The text of a rich-text or inline-text value without its formatting; `''` for `null` or `undefined`. */
20
22
  export declare function plainText(doc: RichTextDoc | null | undefined): string;
23
+ export type { CodeImage } from './core/registry/code-image.js';
24
+ export { js, JsCode } from './core/registry/js.js';
25
+ export { richTextHeadings, type RichTextHeading } from './core/richtext/headings.js';
26
+ export { markdownHeadings } from './core/richtext/markdown-text.js';
21
27
  export type { RichTextDoc };
28
+ export type { CodeHighlighter, RichTextRenderOptions } from './core/richtext/html.js';
22
29
  export type { RichTextFeature, RichTextOptions } from './core/richtext/schema.js';
package/dist/site.js CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference path="./markdown-modules.ts" preserve="true" />
2
+ /// <reference path="./image-modules.ts" preserve="true" />
2
3
  /**
3
4
  * What a site's code imports (`inlaycms/site`): the definitions and the types
4
5
  * templates, routes and migrations use, and nothing that reaches the server.
@@ -12,9 +13,13 @@ export { escapeHtml, raw, SafeHtml } from './jsx/html.js';
12
13
  export { defineField } from './core/fields/define.js';
13
14
  export { defineContent, defineEntries, } from './core/registry/content.js';
14
15
  export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, } from './core/registry/define.js';
16
+ export { defineIntegration, } from './core/registry/integration.js';
15
17
  export { defineRoute, } from './core/registry/route.js';
16
18
  export { defineMigration, } from './core/registry/migration.js';
17
19
  /** The text of a rich-text or inline-text value without its formatting; `''` for `null` or `undefined`. */
18
20
  export function plainText(doc) {
19
21
  return doc ? richTextText(doc) : '';
20
22
  }
23
+ export { js, JsCode } from './core/registry/js.js';
24
+ export { richTextHeadings } from './core/richtext/headings.js';
25
+ export { markdownHeadings } from './core/richtext/markdown-text.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inlaycms",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "description": "A code-first CMS for content sites: templates, schemas and content in code, one SQLite file, signed releases.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -84,6 +84,7 @@
84
84
  "@tiptap/extension-blockquote": "^3.32.2",
85
85
  "@tiptap/extension-bold": "^3.32.2",
86
86
  "@tiptap/extension-code": "^3.32.2",
87
+ "@tiptap/extension-code-block": "^3.32.2",
87
88
  "@tiptap/extension-document": "^3.32.2",
88
89
  "@tiptap/extension-hard-break": "^3.32.2",
89
90
  "@tiptap/extension-heading": "^3.32.2",
@@ -112,6 +113,9 @@
112
113
  "build:admin": "node scripts/build-admin.mjs",
113
114
  "build": "pnpm run build:admin && node -e \"fs.rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
114
115
  "dev": "node scripts/dev.mjs",
116
+ "docs:dev": "pnpm --dir website run dev",
117
+ "docs:build": "pnpm --dir website run build",
118
+ "docs:preview": "pnpm --dir website run preview",
115
119
  "example:check": "tsx src/adapters/cli/bin.ts check --config example/inlay.config.ts",
116
120
  "example:pack": "tsx src/adapters/cli/bin.ts pack --config example/inlay.config.ts --key example/keys/dev.key --out example/data/release.tgz --no-typecheck",
117
121
  "image": "docker build -t inlaycms .",