inlaycms 0.4.0 → 0.5.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 (131) hide show
  1. package/README.md +18 -709
  2. package/assets/admin/admin.css +1 -1
  3. package/assets/admin/editor.js +63 -46
  4. package/assets/site/consent.js +1 -0
  5. package/dist/adapters/admin/context.d.ts +1 -1
  6. package/dist/adapters/admin/context.js +1 -0
  7. package/dist/adapters/admin/routes.d.ts +2 -0
  8. package/dist/adapters/admin/routes.js +2 -0
  9. package/dist/adapters/admin/screens/backups.js +2 -2
  10. package/dist/adapters/admin/screens/editor.js +2 -1
  11. package/dist/adapters/admin/screens/integrations.d.ts +4 -0
  12. package/dist/adapters/admin/screens/integrations.js +140 -0
  13. package/dist/adapters/admin/screens/lists.js +2 -1
  14. package/dist/adapters/admin/screens/releases.js +1 -1
  15. package/dist/adapters/admin/views/layout.js +3 -0
  16. package/dist/adapters/cli/bin.js +8 -3
  17. package/dist/adapters/mcp/tools/read.js +17 -2
  18. package/dist/adapters/mcp/tools/write.js +4 -0
  19. package/dist/adapters/site/cache.d.ts +8 -2
  20. package/dist/adapters/site/cache.js +13 -4
  21. package/dist/adapters/site/code-files.d.ts +44 -0
  22. package/dist/adapters/site/code-files.js +212 -0
  23. package/dist/adapters/site/consent.d.ts +9 -0
  24. package/dist/adapters/site/consent.js +26 -0
  25. package/dist/adapters/site/context.d.ts +5 -0
  26. package/dist/adapters/site/context.js +97 -20
  27. package/dist/adapters/site/csp.d.ts +11 -0
  28. package/dist/adapters/site/csp.js +36 -0
  29. package/dist/adapters/site/head.js +1 -14
  30. package/dist/adapters/site/headers.d.ts +5 -2
  31. package/dist/adapters/site/headers.js +13 -6
  32. package/dist/adapters/site/integrations.d.ts +48 -0
  33. package/dist/adapters/site/integrations.js +118 -0
  34. package/dist/adapters/site/media-routes.d.ts +2 -0
  35. package/dist/adapters/site/media-routes.js +2 -1
  36. package/dist/adapters/site/plugin.d.ts +2 -0
  37. package/dist/adapters/site/plugin.js +64 -34
  38. package/dist/adapters/site/render.d.ts +31 -14
  39. package/dist/adapters/site/render.js +26 -5
  40. package/dist/adapters/site/routes.d.ts +3 -0
  41. package/dist/adapters/site/routes.js +7 -3
  42. package/dist/adapters/site/scripts.d.ts +6 -0
  43. package/dist/adapters/site/scripts.js +27 -0
  44. package/dist/core/auth/roles.d.ts +1 -1
  45. package/dist/core/auth/roles.js +1 -0
  46. package/dist/core/boot.d.ts +2 -0
  47. package/dist/core/boot.js +3 -0
  48. package/dist/core/content/shipped-input.js +1 -2
  49. package/dist/core/content/validate.d.ts +7 -0
  50. package/dist/core/content/validate.js +24 -1
  51. package/dist/core/core.d.ts +29 -0
  52. package/dist/core/core.js +10 -2
  53. package/dist/core/db/migrate.js +2 -0
  54. package/dist/core/db/migrations/0008_integrations.d.ts +3 -0
  55. package/dist/core/db/migrations/0008_integrations.js +11 -0
  56. package/dist/core/db/schema.d.ts +11 -0
  57. package/dist/core/export/export.js +4 -0
  58. package/dist/core/export/format.d.ts +11 -0
  59. package/dist/core/export/format.js +4 -0
  60. package/dist/core/export/import.js +2 -1
  61. package/dist/core/export/replace.d.ts +6 -1
  62. package/dist/core/export/replace.js +4 -1
  63. package/dist/core/export/report.d.ts +6 -0
  64. package/dist/core/export/report.js +7 -0
  65. package/dist/core/fields/builtins.d.ts +4 -0
  66. package/dist/core/fields/builtins.js +11 -1
  67. package/dist/core/fields/widgets.js +5 -1
  68. package/dist/core/integrations/integrations.d.ts +32 -0
  69. package/dist/core/integrations/integrations.js +80 -0
  70. package/dist/core/integrations/warnings.d.ts +4 -0
  71. package/dist/core/integrations/warnings.js +29 -0
  72. package/dist/core/media/store.d.ts +2 -0
  73. package/dist/core/media/store.js +17 -1
  74. package/dist/core/media/variants.d.ts +14 -0
  75. package/dist/core/media/variants.js +54 -0
  76. package/dist/core/messages/en.d.ts +73 -0
  77. package/dist/core/messages/en.js +73 -0
  78. package/dist/core/registry/code-image.d.ts +16 -0
  79. package/dist/core/registry/code-image.js +13 -0
  80. package/dist/core/registry/define.d.ts +7 -0
  81. package/dist/core/registry/define.js +2 -0
  82. package/dist/core/registry/designed.d.ts +6 -0
  83. package/dist/core/registry/designed.js +8 -0
  84. package/dist/core/registry/integration.d.ts +48 -0
  85. package/dist/core/registry/integration.js +29 -0
  86. package/dist/core/registry/js.d.ts +9 -0
  87. package/dist/core/registry/js.js +39 -0
  88. package/dist/core/registry/registry.js +46 -0
  89. package/dist/core/registry/render.d.ts +39 -4
  90. package/dist/core/release/bundle.d.ts +3 -1
  91. package/dist/core/release/bundle.js +169 -11
  92. package/dist/core/release/manifest.d.ts +29 -1
  93. package/dist/core/release/manifest.js +26 -1
  94. package/dist/core/release/pack.js +13 -2
  95. package/dist/core/release/pointer.js +14 -3
  96. package/dist/core/release/read.d.ts +2 -0
  97. package/dist/core/release/read.js +1 -0
  98. package/dist/core/report.d.ts +3 -0
  99. package/dist/core/richtext/headings.d.ts +10 -0
  100. package/dist/core/richtext/headings.js +37 -0
  101. package/dist/core/richtext/html.d.ts +10 -1
  102. package/dist/core/richtext/html.js +17 -6
  103. package/dist/core/richtext/markdown-text.d.ts +24 -0
  104. package/dist/core/richtext/markdown-text.js +38 -0
  105. package/dist/core/richtext/markdown.js +44 -3
  106. package/dist/core/richtext/schema.d.ts +12 -3
  107. package/dist/core/richtext/schema.js +34 -0
  108. package/dist/core/site/live.d.ts +6 -0
  109. package/dist/core/site/live.js +25 -0
  110. package/dist/host/app.d.ts +2 -0
  111. package/dist/host/app.js +1 -0
  112. package/dist/host/diff.d.ts +11 -0
  113. package/dist/host/diff.js +40 -0
  114. package/dist/host/drain.d.ts +12 -0
  115. package/dist/host/drain.js +34 -0
  116. package/dist/host/ipc.d.ts +2 -0
  117. package/dist/host/ipc.js +5 -1
  118. package/dist/host/preview-worker.js +2 -2
  119. package/dist/host/primary.js +15 -4
  120. package/dist/host/push.js +1 -1
  121. package/dist/host/serve.js +1 -1
  122. package/dist/host/store.d.ts +1 -2
  123. package/dist/host/store.js +32 -6
  124. package/dist/host/worker.js +6 -0
  125. package/dist/image-modules.d.ts +29 -0
  126. package/dist/image-modules.js +1 -0
  127. package/dist/index.d.ts +7 -1
  128. package/dist/index.js +4 -0
  129. package/dist/site.d.ts +8 -1
  130. package/dist/site.js +5 -0
  131. package/package.json +5 -1
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)
@@ -0,0 +1,12 @@
1
+ import type { Server } from 'node:http';
2
+ /** How long a draining worker keeps its idle keep-alive connections open for a client's next request. */
3
+ export declare const DRAIN_GRACE_MS = 2000;
4
+ /**
5
+ * Lets a worker of `inlaycms serve` stop without dropping a visitor's request. `server.close()` also closes every
6
+ * idle keep-alive socket at once, and a client that was just then sending its next request down one gets
7
+ * ECONNRESET. The returned `drain` instead stops accepting connections (in a cluster worker, the primary hands new
8
+ * ones to the other workers) and answers every request on the sockets still open with `Connection: close`. Clients
9
+ * may keep an idle connection for over a minute (Fastify tells them 72 seconds), so the ones still idle after
10
+ * `graceMs` are closed then; it resolves once no connection is left. Call it before the server starts listening.
11
+ */
12
+ export declare function drainable(server: Server, graceMs?: number): () => Promise<void>;
@@ -0,0 +1,34 @@
1
+ import { Server as NetServer } from 'node:net';
2
+ /** How long a draining worker keeps its idle keep-alive connections open for a client's next request. */
3
+ export const DRAIN_GRACE_MS = 2_000;
4
+ /**
5
+ * Lets a worker of `inlaycms serve` stop without dropping a visitor's request. `server.close()` also closes every
6
+ * idle keep-alive socket at once, and a client that was just then sending its next request down one gets
7
+ * ECONNRESET. The returned `drain` instead stops accepting connections (in a cluster worker, the primary hands new
8
+ * ones to the other workers) and answers every request on the sockets still open with `Connection: close`. Clients
9
+ * may keep an idle connection for over a minute (Fastify tells them 72 seconds), so the ones still idle after
10
+ * `graceMs` are closed then; it resolves once no connection is left. Call it before the server starts listening.
11
+ */
12
+ export function drainable(server, graceMs = DRAIN_GRACE_MS) {
13
+ let draining = false;
14
+ const open = new Set();
15
+ server.prependListener('request', (_req, res) => {
16
+ if (draining)
17
+ return void res.setHeader('Connection', 'close');
18
+ open.add(res);
19
+ res.on('close', () => open.delete(res));
20
+ });
21
+ return () => {
22
+ draining = true;
23
+ for (const res of open)
24
+ if (!res.headersSent)
25
+ res.setHeader('Connection', 'close');
26
+ open.clear();
27
+ const timer = setTimeout(() => server.closeIdleConnections(), graceMs);
28
+ // `net.Server#close`, not `http.Server#close`, which closes idle sockets first.
29
+ return new Promise((done) => NetServer.prototype.close.call(server, () => {
30
+ clearTimeout(timer);
31
+ done();
32
+ }));
33
+ };
34
+ }
@@ -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);
package/dist/host/push.js CHANGED
@@ -407,7 +407,7 @@ export function registerPushRoutes(app, opts) {
407
407
  return reply;
408
408
  const { id } = request.params;
409
409
  try {
410
- await deleteRelease({ db, releasesDir }, id);
410
+ await deleteRelease({ db, releasesDir, mediaDir: opts.config.paths.media }, id);
411
411
  }
412
412
  catch (e) {
413
413
  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
@@ -7,6 +7,7 @@ import { t } from '../core/messages/index.js';
7
7
  import { checkInlayVersion, loadRelease } from '../core/release/read.js';
8
8
  import { activateRelease, summarize } from './activate.js';
9
9
  import { createSiteApp } from './app.js';
10
+ import { drainable } from './drain.js';
10
11
  import { runPreviewWorker } from './preview-worker.js';
11
12
  import { ACTIVATION_TIMEOUT_MS, activationError, isPrimaryMessage, PREVIEW_START_TIMEOUT_MS, toIpcError, } from './ipc.js';
12
13
  import { currentRelease, getRelease, openCurrentRelease, readCurrentPointer, releaseDir, writeCurrentPointer } from './store.js';
@@ -109,6 +110,7 @@ export async function runWorker(config, env, io) {
109
110
  }
110
111
  const log = io.log ?? ((id, params) => console.error(t(id, params)));
111
112
  let app = null;
113
+ let drain = null;
112
114
  let listening = false;
113
115
  let stopping = false;
114
116
  let exiting = false;
@@ -117,6 +119,9 @@ export async function runWorker(config, env, io) {
117
119
  return;
118
120
  exiting = true;
119
121
  try {
122
+ // Finish with the visitors' open connections first, so a swap never resets a request.
123
+ if (listening)
124
+ await drain?.();
120
125
  await app?.close();
121
126
  }
122
127
  finally {
@@ -145,6 +150,7 @@ export async function runWorker(config, env, io) {
145
150
  ...(opts.noSite && { noSite: opts.noSite }),
146
151
  ...(opts.release && { release: opts.release }),
147
152
  })).app;
153
+ drain = drainable(app.server);
148
154
  return app;
149
155
  };
150
156
  const listen = async () => {
@@ -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.
@@ -12,11 +13,17 @@ export { escapeHtml, raw, SafeHtml, type Html, type Renderable } from './jsx/htm
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
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 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.0",
3
+ "version": "0.5.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 .",