inlaycms 0.0.0-stage → 0.1.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 (364) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +462 -2
  3. package/assets/admin/admin.css +2 -0
  4. package/assets/admin/admin.js +1 -0
  5. package/assets/admin/editor.js +125 -0
  6. package/dist/adapters/admin/activity.d.ts +17 -0
  7. package/dist/adapters/admin/activity.js +59 -0
  8. package/dist/adapters/admin/assets.d.ts +14 -0
  9. package/dist/adapters/admin/assets.js +64 -0
  10. package/dist/adapters/admin/attention.d.ts +15 -0
  11. package/dist/adapters/admin/attention.js +34 -0
  12. package/dist/adapters/admin/context.d.ts +40 -0
  13. package/dist/adapters/admin/context.js +142 -0
  14. package/dist/adapters/admin/form/walk.d.ts +61 -0
  15. package/dist/adapters/admin/form/walk.js +565 -0
  16. package/dist/adapters/admin/pages.d.ts +38 -0
  17. package/dist/adapters/admin/pages.js +66 -0
  18. package/dist/adapters/admin/publish.d.ts +12 -0
  19. package/dist/adapters/admin/publish.js +195 -0
  20. package/dist/adapters/admin/routes.d.ts +47 -0
  21. package/dist/adapters/admin/routes.js +255 -0
  22. package/dist/adapters/admin/screens/backups.d.ts +11 -0
  23. package/dist/adapters/admin/screens/backups.js +223 -0
  24. package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
  25. package/dist/adapters/admin/screens/dashboard.js +160 -0
  26. package/dist/adapters/admin/screens/editor.d.ts +67 -0
  27. package/dist/adapters/admin/screens/editor.js +416 -0
  28. package/dist/adapters/admin/screens/history.d.ts +4 -0
  29. package/dist/adapters/admin/screens/history.js +105 -0
  30. package/dist/adapters/admin/screens/lists.d.ts +4 -0
  31. package/dist/adapters/admin/screens/lists.js +297 -0
  32. package/dist/adapters/admin/screens/media.d.ts +20 -0
  33. package/dist/adapters/admin/screens/media.js +186 -0
  34. package/dist/adapters/admin/screens/pickers.d.ts +29 -0
  35. package/dist/adapters/admin/screens/pickers.js +134 -0
  36. package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
  37. package/dist/adapters/admin/screens/preview-pane.js +74 -0
  38. package/dist/adapters/admin/screens/redirects.d.ts +4 -0
  39. package/dist/adapters/admin/screens/redirects.js +137 -0
  40. package/dist/adapters/admin/screens/releases.d.ts +7 -0
  41. package/dist/adapters/admin/screens/releases.js +287 -0
  42. package/dist/adapters/admin/screens/search.d.ts +22 -0
  43. package/dist/adapters/admin/screens/search.js +113 -0
  44. package/dist/adapters/admin/screens/security.d.ts +4 -0
  45. package/dist/adapters/admin/screens/security.js +85 -0
  46. package/dist/adapters/admin/screens/users.d.ts +4 -0
  47. package/dist/adapters/admin/screens/users.js +330 -0
  48. package/dist/adapters/admin/theme.d.ts +1 -0
  49. package/dist/adapters/admin/theme.js +1 -0
  50. package/dist/adapters/admin/translations.d.ts +16 -0
  51. package/dist/adapters/admin/translations.js +23 -0
  52. package/dist/adapters/admin/upload.d.ts +8 -0
  53. package/dist/adapters/admin/upload.js +116 -0
  54. package/dist/adapters/admin/views/data-table.d.ts +82 -0
  55. package/dist/adapters/admin/views/data-table.js +117 -0
  56. package/dist/adapters/admin/views/icons.d.ts +48 -0
  57. package/dist/adapters/admin/views/icons.js +47 -0
  58. package/dist/adapters/admin/views/layout.d.ts +51 -0
  59. package/dist/adapters/admin/views/layout.js +145 -0
  60. package/dist/adapters/admin/views/sheet.d.ts +15 -0
  61. package/dist/adapters/admin/views/sheet.js +6 -0
  62. package/dist/adapters/admin/views/status.d.ts +32 -0
  63. package/dist/adapters/admin/views/status.js +74 -0
  64. package/dist/adapters/auth/handler.d.ts +10 -0
  65. package/dist/adapters/auth/handler.js +63 -0
  66. package/dist/adapters/auth/request.d.ts +8 -0
  67. package/dist/adapters/auth/request.js +14 -0
  68. package/dist/adapters/cli/bin.d.ts +2 -0
  69. package/dist/adapters/cli/bin.js +42 -0
  70. package/dist/adapters/cli/main.d.ts +7 -0
  71. package/dist/adapters/cli/main.js +982 -0
  72. package/dist/adapters/cli/remote.d.ts +52 -0
  73. package/dist/adapters/cli/remote.js +161 -0
  74. package/dist/adapters/mcp/agent-refs.d.ts +9 -0
  75. package/dist/adapters/mcp/agent-refs.js +25 -0
  76. package/dist/adapters/mcp/documents.d.ts +15 -0
  77. package/dist/adapters/mcp/documents.js +26 -0
  78. package/dist/adapters/mcp/fetch-url.d.ts +19 -0
  79. package/dist/adapters/mcp/fetch-url.js +244 -0
  80. package/dist/adapters/mcp/request-state.d.ts +15 -0
  81. package/dist/adapters/mcp/request-state.js +38 -0
  82. package/dist/adapters/mcp/results.d.ts +20 -0
  83. package/dist/adapters/mcp/results.js +61 -0
  84. package/dist/adapters/mcp/route.d.ts +34 -0
  85. package/dist/adapters/mcp/route.js +52 -0
  86. package/dist/adapters/mcp/server.d.ts +44 -0
  87. package/dist/adapters/mcp/server.js +49 -0
  88. package/dist/adapters/mcp/tools/history.d.ts +5 -0
  89. package/dist/adapters/mcp/tools/history.js +84 -0
  90. package/dist/adapters/mcp/tools/media.d.ts +5 -0
  91. package/dist/adapters/mcp/tools/media.js +102 -0
  92. package/dist/adapters/mcp/tools/publish.d.ts +5 -0
  93. package/dist/adapters/mcp/tools/publish.js +157 -0
  94. package/dist/adapters/mcp/tools/read.d.ts +5 -0
  95. package/dist/adapters/mcp/tools/read.js +279 -0
  96. package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
  97. package/dist/adapters/mcp/tools/redirects.js +74 -0
  98. package/dist/adapters/mcp/tools/write.d.ts +5 -0
  99. package/dist/adapters/mcp/tools/write.js +304 -0
  100. package/dist/adapters/site/backup-schedule.d.ts +8 -0
  101. package/dist/adapters/site/backup-schedule.js +31 -0
  102. package/dist/adapters/site/cache.d.ts +29 -0
  103. package/dist/adapters/site/cache.js +63 -0
  104. package/dist/adapters/site/context.d.ts +29 -0
  105. package/dist/adapters/site/context.js +278 -0
  106. package/dist/adapters/site/head.d.ts +23 -0
  107. package/dist/adapters/site/head.js +44 -0
  108. package/dist/adapters/site/limiter.d.ts +17 -0
  109. package/dist/adapters/site/limiter.js +39 -0
  110. package/dist/adapters/site/lock.d.ts +30 -0
  111. package/dist/adapters/site/lock.js +143 -0
  112. package/dist/adapters/site/media-routes.d.ts +4 -0
  113. package/dist/adapters/site/media-routes.js +55 -0
  114. package/dist/adapters/site/plugin.d.ts +122 -0
  115. package/dist/adapters/site/plugin.js +436 -0
  116. package/dist/adapters/site/preview.d.ts +36 -0
  117. package/dist/adapters/site/preview.js +82 -0
  118. package/dist/adapters/site/public.d.ts +6 -0
  119. package/dist/adapters/site/public.js +87 -0
  120. package/dist/adapters/site/render.d.ts +45 -0
  121. package/dist/adapters/site/render.js +191 -0
  122. package/dist/adapters/site/routes.d.ts +17 -0
  123. package/dist/adapters/site/routes.js +125 -0
  124. package/dist/adapters/site/sitemap.d.ts +10 -0
  125. package/dist/adapters/site/sitemap.js +10 -0
  126. package/dist/adapters/web.d.ts +22 -0
  127. package/dist/adapters/web.js +75 -0
  128. package/dist/config.d.ts +21 -0
  129. package/dist/config.js +58 -0
  130. package/dist/core/agent/format.d.ts +62 -0
  131. package/dist/core/agent/format.js +211 -0
  132. package/dist/core/agent/schema.d.ts +6 -0
  133. package/dist/core/agent/schema.js +86 -0
  134. package/dist/core/archive.d.ts +12 -0
  135. package/dist/core/archive.js +72 -0
  136. package/dist/core/auth/auth.d.ts +4911 -0
  137. package/dist/core/auth/auth.js +61 -0
  138. package/dist/core/auth/roles.d.ts +10 -0
  139. package/dist/core/auth/roles.js +38 -0
  140. package/dist/core/auth/service.d.ts +118 -0
  141. package/dist/core/auth/service.js +424 -0
  142. package/dist/core/auth/upload-token.d.ts +8 -0
  143. package/dist/core/auth/upload-token.js +27 -0
  144. package/dist/core/backup/backup.d.ts +28 -0
  145. package/dist/core/backup/backup.js +126 -0
  146. package/dist/core/backup/restore.d.ts +41 -0
  147. package/dist/core/backup/restore.js +264 -0
  148. package/dist/core/backup/schedule.d.ts +12 -0
  149. package/dist/core/backup/schedule.js +29 -0
  150. package/dist/core/boot.d.ts +63 -0
  151. package/dist/core/boot.js +141 -0
  152. package/dist/core/check.d.ts +32 -0
  153. package/dist/core/check.js +111 -0
  154. package/dist/core/content/activity.d.ts +8 -0
  155. package/dist/core/content/activity.js +101 -0
  156. package/dist/core/content/delete.d.ts +5 -0
  157. package/dist/core/content/delete.js +100 -0
  158. package/dist/core/content/diff.d.ts +6 -0
  159. package/dist/core/content/diff.js +129 -0
  160. package/dist/core/content/dry-run.d.ts +24 -0
  161. package/dist/core/content/dry-run.js +69 -0
  162. package/dist/core/content/gaps.d.ts +25 -0
  163. package/dist/core/content/gaps.js +50 -0
  164. package/dist/core/content/hidden.d.ts +33 -0
  165. package/dist/core/content/hidden.js +103 -0
  166. package/dist/core/content/history.d.ts +15 -0
  167. package/dist/core/content/history.js +62 -0
  168. package/dist/core/content/patch.d.ts +40 -0
  169. package/dist/core/content/patch.js +287 -0
  170. package/dist/core/content/path.d.ts +6 -0
  171. package/dist/core/content/path.js +38 -0
  172. package/dist/core/content/publish.d.ts +26 -0
  173. package/dist/core/content/publish.js +211 -0
  174. package/dist/core/content/read.d.ts +99 -0
  175. package/dist/core/content/read.js +141 -0
  176. package/dist/core/content/reader.d.ts +37 -0
  177. package/dist/core/content/reader.js +195 -0
  178. package/dist/core/content/refs.d.ts +44 -0
  179. package/dist/core/content/refs.js +161 -0
  180. package/dist/core/content/release-migrations.d.ts +12 -0
  181. package/dist/core/content/release-migrations.js +154 -0
  182. package/dist/core/content/save.d.ts +25 -0
  183. package/dist/core/content/save.js +87 -0
  184. package/dist/core/content/schema.d.ts +22 -0
  185. package/dist/core/content/schema.js +127 -0
  186. package/dist/core/content/search.d.ts +8 -0
  187. package/dist/core/content/search.js +89 -0
  188. package/dist/core/content/shipped-input.d.ts +39 -0
  189. package/dist/core/content/shipped-input.js +221 -0
  190. package/dist/core/content/shipped.d.ts +112 -0
  191. package/dist/core/content/shipped.js +437 -0
  192. package/dist/core/content/slug.d.ts +23 -0
  193. package/dist/core/content/slug.js +182 -0
  194. package/dist/core/content/stats.d.ts +11 -0
  195. package/dist/core/content/stats.js +30 -0
  196. package/dist/core/content/translate.d.ts +3 -0
  197. package/dist/core/content/translate.js +68 -0
  198. package/dist/core/content/usages.d.ts +13 -0
  199. package/dist/core/content/usages.js +70 -0
  200. package/dist/core/content/validate.d.ts +21 -0
  201. package/dist/core/content/validate.js +124 -0
  202. package/dist/core/content/write.d.ts +10 -0
  203. package/dist/core/content/write.js +93 -0
  204. package/dist/core/core.d.ts +227 -0
  205. package/dist/core/core.js +251 -0
  206. package/dist/core/db/connection.d.ts +6 -0
  207. package/dist/core/db/connection.js +12 -0
  208. package/dist/core/db/migrate.d.ts +9 -0
  209. package/dist/core/db/migrate.js +42 -0
  210. package/dist/core/db/migrations/0001_content.d.ts +2 -0
  211. package/dist/core/db/migrations/0001_content.js +69 -0
  212. package/dist/core/db/migrations/0002_media.d.ts +2 -0
  213. package/dist/core/db/migrations/0002_media.js +26 -0
  214. package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
  215. package/dist/core/db/migrations/0003_redirects.js +19 -0
  216. package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
  217. package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
  218. package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
  219. package/dist/core/db/migrations/0005_site_lock.js +10 -0
  220. package/dist/core/db/migrations/0006_releases.d.ts +3 -0
  221. package/dist/core/db/migrations/0006_releases.js +34 -0
  222. package/dist/core/db/schema.d.ts +155 -0
  223. package/dist/core/db/schema.js +1 -0
  224. package/dist/core/errors.d.ts +27 -0
  225. package/dist/core/errors.js +15 -0
  226. package/dist/core/export/export.d.ts +17 -0
  227. package/dist/core/export/export.js +185 -0
  228. package/dist/core/export/format.d.ts +241 -0
  229. package/dist/core/export/format.js +106 -0
  230. package/dist/core/export/import.d.ts +54 -0
  231. package/dist/core/export/import.js +180 -0
  232. package/dist/core/export/read.d.ts +16 -0
  233. package/dist/core/export/read.js +234 -0
  234. package/dist/core/export/replace.d.ts +17 -0
  235. package/dist/core/export/replace.js +36 -0
  236. package/dist/core/export/report.d.ts +55 -0
  237. package/dist/core/export/report.js +50 -0
  238. package/dist/core/export/schema.d.ts +8 -0
  239. package/dist/core/export/schema.js +47 -0
  240. package/dist/core/export/stage.d.ts +25 -0
  241. package/dist/core/export/stage.js +192 -0
  242. package/dist/core/fields/builtins.d.ts +70 -0
  243. package/dist/core/fields/builtins.js +335 -0
  244. package/dist/core/fields/define.d.ts +86 -0
  245. package/dist/core/fields/define.js +34 -0
  246. package/dist/core/fields/walk.d.ts +49 -0
  247. package/dist/core/fields/walk.js +270 -0
  248. package/dist/core/fields/widgets.d.ts +27 -0
  249. package/dist/core/fields/widgets.js +330 -0
  250. package/dist/core/fields/zod-internals.d.ts +29 -0
  251. package/dist/core/fields/zod-internals.js +28 -0
  252. package/dist/core/media/detect.d.ts +5 -0
  253. package/dist/core/media/detect.js +66 -0
  254. package/dist/core/media/labels.d.ts +6 -0
  255. package/dist/core/media/labels.js +17 -0
  256. package/dist/core/media/library.d.ts +45 -0
  257. package/dist/core/media/library.js +239 -0
  258. package/dist/core/media/store.d.ts +11 -0
  259. package/dist/core/media/store.js +49 -0
  260. package/dist/core/media/variants.d.ts +10 -0
  261. package/dist/core/media/variants.js +59 -0
  262. package/dist/core/messages/en.d.ts +1278 -0
  263. package/dist/core/messages/en.js +1287 -0
  264. package/dist/core/messages/index.d.ts +7 -0
  265. package/dist/core/messages/index.js +14 -0
  266. package/dist/core/preview.d.ts +16 -0
  267. package/dist/core/preview.js +42 -0
  268. package/dist/core/redirects/collapse.d.ts +68 -0
  269. package/dist/core/redirects/collapse.js +153 -0
  270. package/dist/core/redirects/csv.d.ts +15 -0
  271. package/dist/core/redirects/csv.js +68 -0
  272. package/dist/core/redirects/redirects.d.ts +58 -0
  273. package/dist/core/redirects/redirects.js +545 -0
  274. package/dist/core/registry/content.d.ts +26 -0
  275. package/dist/core/registry/content.js +9 -0
  276. package/dist/core/registry/define.d.ts +145 -0
  277. package/dist/core/registry/define.js +41 -0
  278. package/dist/core/registry/migration.d.ts +44 -0
  279. package/dist/core/registry/migration.js +4 -0
  280. package/dist/core/registry/registry.d.ts +18 -0
  281. package/dist/core/registry/registry.js +255 -0
  282. package/dist/core/registry/render.d.ts +98 -0
  283. package/dist/core/registry/render.js +1 -0
  284. package/dist/core/registry/route.d.ts +42 -0
  285. package/dist/core/registry/route.js +3 -0
  286. package/dist/core/release/bundle.d.ts +21 -0
  287. package/dist/core/release/bundle.js +252 -0
  288. package/dist/core/release/keys.d.ts +11 -0
  289. package/dist/core/release/keys.js +60 -0
  290. package/dist/core/release/manifest.d.ts +103 -0
  291. package/dist/core/release/manifest.js +138 -0
  292. package/dist/core/release/pack.d.ts +20 -0
  293. package/dist/core/release/pack.js +97 -0
  294. package/dist/core/release/pointer.d.ts +19 -0
  295. package/dist/core/release/pointer.js +53 -0
  296. package/dist/core/release/read.d.ts +59 -0
  297. package/dist/core/release/read.js +256 -0
  298. package/dist/core/report.d.ts +31 -0
  299. package/dist/core/report.js +37 -0
  300. package/dist/core/richtext/html.d.ts +15 -0
  301. package/dist/core/richtext/html.js +81 -0
  302. package/dist/core/richtext/markdown.d.ts +19 -0
  303. package/dist/core/richtext/markdown.js +951 -0
  304. package/dist/core/richtext/schema.d.ts +98 -0
  305. package/dist/core/richtext/schema.js +275 -0
  306. package/dist/core/site/live.d.ts +56 -0
  307. package/dist/core/site/live.js +145 -0
  308. package/dist/core/site/paths.d.ts +15 -0
  309. package/dist/core/site/paths.js +64 -0
  310. package/dist/core/site/resolve.d.ts +9 -0
  311. package/dist/core/site/resolve.js +202 -0
  312. package/dist/core/site/sitemap.d.ts +11 -0
  313. package/dist/core/site/sitemap.js +24 -0
  314. package/dist/core/site-lock/site-lock.d.ts +21 -0
  315. package/dist/core/site-lock/site-lock.js +65 -0
  316. package/dist/core/site-lock/token.d.ts +7 -0
  317. package/dist/core/site-lock/token.js +24 -0
  318. package/dist/core/theme.d.ts +22 -0
  319. package/dist/core/theme.js +133 -0
  320. package/dist/core/types.d.ts +253 -0
  321. package/dist/core/types.js +1 -0
  322. package/dist/core/version.d.ts +1 -0
  323. package/dist/core/version.js +5 -0
  324. package/dist/host/activate.d.ts +53 -0
  325. package/dist/host/activate.js +162 -0
  326. package/dist/host/app.d.ts +46 -0
  327. package/dist/host/app.js +129 -0
  328. package/dist/host/bin.d.ts +5 -0
  329. package/dist/host/bin.js +8 -0
  330. package/dist/host/config.d.ts +36 -0
  331. package/dist/host/config.js +152 -0
  332. package/dist/host/dev.d.ts +10 -0
  333. package/dist/host/dev.js +293 -0
  334. package/dist/host/diff.d.ts +78 -0
  335. package/dist/host/diff.js +346 -0
  336. package/dist/host/hooks.d.ts +41 -0
  337. package/dist/host/hooks.js +49 -0
  338. package/dist/host/ipc.d.ts +123 -0
  339. package/dist/host/ipc.js +61 -0
  340. package/dist/host/preview-proxy.d.ts +24 -0
  341. package/dist/host/preview-proxy.js +154 -0
  342. package/dist/host/preview-worker.d.ts +42 -0
  343. package/dist/host/preview-worker.js +242 -0
  344. package/dist/host/primary.d.ts +38 -0
  345. package/dist/host/primary.js +357 -0
  346. package/dist/host/push.d.ts +125 -0
  347. package/dist/host/push.js +420 -0
  348. package/dist/host/serve.d.ts +16 -0
  349. package/dist/host/serve.js +150 -0
  350. package/dist/host/store.d.ts +48 -0
  351. package/dist/host/store.js +109 -0
  352. package/dist/host/worker.d.ts +67 -0
  353. package/dist/host/worker.js +310 -0
  354. package/dist/index.d.ts +47 -0
  355. package/dist/index.js +32 -0
  356. package/dist/jsx/html.d.ts +16 -0
  357. package/dist/jsx/html.js +65 -0
  358. package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
  359. package/dist/jsx/jsx-dev-runtime.js +5 -0
  360. package/dist/jsx/jsx-runtime.d.ts +17 -0
  361. package/dist/jsx/jsx-runtime.js +41 -0
  362. package/dist/site.d.ts +17 -0
  363. package/dist/site.js +14 -0
  364. package/package.json +111 -3
@@ -0,0 +1,97 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { existsSync } from 'node:fs';
3
+ import { copyFile, mkdir, mkdtemp, readdir, readFile, rm, writeFile } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { dirname, join, posix, relative, sep } from 'node:path';
6
+ import { promisify } from 'node:util';
7
+ import * as tar from 'tar';
8
+ import { loadConfig } from '../../config.js';
9
+ import { shippedFiles } from '../content/shipped-input.js';
10
+ import { InlayError } from '../errors.js';
11
+ import { buildRegistry } from '../registry/registry.js';
12
+ import { bundleSite } from './bundle.js';
13
+ import { sign } from './keys.js';
14
+ import { contentPath, manifestOfRegistry, sha256Hex } from './manifest.js';
15
+ /** Every regular file under `dir`, as `/`-separated paths relative to it. Dotfiles and symlinks are left out. */
16
+ export async function listFiles(dir, skipDotfiles = false) {
17
+ const out = [];
18
+ const walk = async (at) => {
19
+ for (const entry of await readdir(at, { withFileTypes: true })) {
20
+ if (skipDotfiles && entry.name.startsWith('.'))
21
+ continue;
22
+ const full = join(at, entry.name);
23
+ if (entry.isDirectory())
24
+ await walk(full);
25
+ else if (entry.isFile())
26
+ out.push(relative(dir, full).split(sep).join(posix.sep));
27
+ }
28
+ };
29
+ await walk(dir);
30
+ return out.sort();
31
+ }
32
+ /** `<short commit>-<YYYYMMDD>` when `dir` is in a git checkout, else the date. */
33
+ export async function releaseName(dir, now) {
34
+ const date = now.toISOString().slice(0, 10).replaceAll('-', '');
35
+ try {
36
+ const { stdout } = await promisify(execFile)('git', ['rev-parse', '--short', 'HEAD'], { cwd: dir });
37
+ const commit = stdout.trim();
38
+ return commit === '' ? date : `${commit}-${date}`;
39
+ }
40
+ catch {
41
+ return date;
42
+ }
43
+ }
44
+ /**
45
+ * Turns the site at `configFile` into a signed release file at `out`: the bundled site code, the files its
46
+ * shipped content names, the `public/` folder beside the config, and a manifest of them signed with `privateKey`.
47
+ * Never runs the bundle.
48
+ */
49
+ export async function packRelease(opts) {
50
+ const now = (opts.now ?? (() => new Date()))();
51
+ const { config, file, dir } = await loadConfig(opts.configFile);
52
+ const registry = buildRegistry(config.site);
53
+ const tmp = await mkdtemp(join(tmpdir(), 'inlay-pack-'));
54
+ try {
55
+ await bundleSite(file, join(tmp, 'site.js'));
56
+ const content = [];
57
+ const sources = shippedFiles(registry);
58
+ if (sources.length > 0)
59
+ await mkdir(join(tmp, 'content'));
60
+ for (const { source, path } of sources) {
61
+ let bytes;
62
+ try {
63
+ bytes = await readFile(path);
64
+ }
65
+ catch {
66
+ throw new InlayError('release', 'error.packFile', { path });
67
+ }
68
+ const target = contentPath(path, bytes);
69
+ await writeFile(join(tmp, target), bytes);
70
+ content.push({ source, path: target });
71
+ }
72
+ const publicDir = join(dir, 'public');
73
+ if (existsSync(publicDir)) {
74
+ for (const path of await listFiles(publicDir, true)) {
75
+ await mkdir(dirname(join(tmp, 'public', path)), { recursive: true });
76
+ await copyFile(join(publicDir, path), join(tmp, 'public', path));
77
+ }
78
+ }
79
+ const files = {};
80
+ for (const path of await listFiles(tmp))
81
+ files[path] = sha256Hex(await readFile(join(tmp, path)));
82
+ const manifest = {
83
+ ...manifestOfRegistry(registry, { name: opts.name ?? (await releaseName(dir, now)), now, content }),
84
+ files,
85
+ };
86
+ const bytes = Buffer.from(JSON.stringify(manifest, null, 2) + '\n');
87
+ await writeFile(join(tmp, 'manifest.json'), bytes);
88
+ await writeFile(join(tmp, 'manifest.sig'), sign(opts.privateKey, bytes));
89
+ const entries = ['manifest.json', 'manifest.sig', 'site.js', 'content', 'public'].filter((e) => existsSync(join(tmp, e)));
90
+ await mkdir(dirname(opts.out), { recursive: true });
91
+ await tar.c({ gzip: true, cwd: tmp, portable: true, file: opts.out }, entries);
92
+ return { manifest, out: opts.out };
93
+ }
94
+ finally {
95
+ await rm(tmp, { recursive: true, force: true });
96
+ }
97
+ }
@@ -0,0 +1,19 @@
1
+ /** What `current.json` holds: the release activation last made current. */
2
+ export interface CurrentPointer {
3
+ id: string;
4
+ name: string;
5
+ activatedAt: string;
6
+ }
7
+ /** The `releases` folder beside the database file, as in the host's data folder. */
8
+ export declare function releasesDirOf(dbPath: string): string;
9
+ /** The folder a stored release is extracted into. */
10
+ export declare function releaseDir(releasesDir: string, id: string): string;
11
+ /** The release `current.json` names, or null before anything has been activated. */
12
+ export declare function readCurrentPointer(releasesDir: string): Promise<CurrentPointer | null>;
13
+ /**
14
+ * Replaces `current.json` in one step, so a reader sees the old pointer or the new one and never half of one. The
15
+ * temporary file's name is this call's own, so two writers at once don't trip over each other: the last rename wins.
16
+ */
17
+ export declare function writeCurrentPointer(releasesDir: string, pointer: CurrentPointer): Promise<void>;
18
+ /** Removes `current.json`, so no release is live. */
19
+ export declare function removeCurrentPointer(releasesDir: string): Promise<void>;
@@ -0,0 +1,53 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { readFile, rename, rm, writeFile } from 'node:fs/promises';
3
+ import { dirname, join } from 'node:path';
4
+ import { z } from 'zod';
5
+ import { InlayError } from '../errors.js';
6
+ const pointerSchema = z.strictObject({ id: z.string().min(1), name: z.string(), activatedAt: z.string() });
7
+ const POINTER = 'current.json';
8
+ /** The `releases` folder beside the database file, as in the host's data folder. */
9
+ export function releasesDirOf(dbPath) {
10
+ return join(dirname(dbPath), 'releases');
11
+ }
12
+ /** The folder a stored release is extracted into. */
13
+ export function releaseDir(releasesDir, id) {
14
+ return join(releasesDir, id);
15
+ }
16
+ /** The release `current.json` names, or null before anything has been activated. */
17
+ export async function readCurrentPointer(releasesDir) {
18
+ const file = join(releasesDir, POINTER);
19
+ let text;
20
+ try {
21
+ text = await readFile(file, 'utf8');
22
+ }
23
+ catch (e) {
24
+ if (e.code === 'ENOENT')
25
+ return null;
26
+ throw e;
27
+ }
28
+ try {
29
+ return pointerSchema.parse(JSON.parse(text));
30
+ }
31
+ catch {
32
+ throw new InlayError('release', 'error.releasePointerInvalid', { file });
33
+ }
34
+ }
35
+ /**
36
+ * Replaces `current.json` in one step, so a reader sees the old pointer or the new one and never half of one. The
37
+ * temporary file's name is this call's own, so two writers at once don't trip over each other: the last rename wins.
38
+ */
39
+ export async function writeCurrentPointer(releasesDir, pointer) {
40
+ const tmp = join(releasesDir, `.${POINTER}.${process.pid}-${randomUUID()}.tmp`);
41
+ try {
42
+ await writeFile(tmp, `${JSON.stringify(pointer, null, 2)}\n`);
43
+ await rename(tmp, join(releasesDir, POINTER));
44
+ }
45
+ catch (e) {
46
+ await rm(tmp, { force: true });
47
+ throw e;
48
+ }
49
+ }
50
+ /** Removes `current.json`, so no release is live. */
51
+ export async function removeCurrentPointer(releasesDir) {
52
+ await rm(join(releasesDir, POINTER), { force: true });
53
+ }
@@ -0,0 +1,59 @@
1
+ import type { SiteDefinition } from '../registry/define.js';
2
+ import { type ReleaseManifest } from './manifest.js';
3
+ export interface LoadedRelease {
4
+ manifest: ReleaseManifest;
5
+ site: SiteDefinition;
6
+ dir: string;
7
+ /** Each shipped file's source as the site names it, to the release's copy. */
8
+ shippedFiles: Map<string, string>;
9
+ publicDir: string | null;
10
+ }
11
+ /**
12
+ * The running copy of each `inlaycms` entry point. Site code must import these files, not another copy of the
13
+ * package (from `src/` the package's own `exports` name `dist/`): field definitions are checked by identity.
14
+ */
15
+ export declare const INLAY_ENTRIES: Readonly<Record<string, string>>;
16
+ /** Throws `error.releaseVersion` when Inlay `version` (default: the running one) isn't in a release's `range`. */
17
+ export declare function checkInlayVersion(range: string, version?: string): void;
18
+ /**
19
+ * Opens the release file at `file` into the empty folder `opts.dir` without running any of it. The signature is
20
+ * checked against `opts.trustedKeys` before anything but the manifest is read, the Inlay version range next, and
21
+ * every file's checksum last. On a failure `dir` is left empty again.
22
+ */
23
+ export declare function openRelease(file: string, opts: {
24
+ dir: string;
25
+ trustedKeys: readonly string[];
26
+ inlayVersion?: string;
27
+ }): Promise<{
28
+ manifest: ReleaseManifest;
29
+ signedBy: string;
30
+ }>;
31
+ /**
32
+ * Opens a release file from the operator's own backup into the empty folder `opts.dir`, trusting its manifest:
33
+ * the signature isn't checked (the release was accepted when it was pushed, and the keys may have changed since),
34
+ * but the release must suit this version of Inlay and the files must be the ones the manifest lists, with its
35
+ * checksums. On a failure `dir` is left empty again.
36
+ */
37
+ export declare function extractRelease(file: string, opts: {
38
+ dir: string;
39
+ inlayVersion?: string;
40
+ }): Promise<{
41
+ manifest: ReleaseManifest;
42
+ }>;
43
+ /**
44
+ * Loads the site code of a release `openRelease` opened into `dir`. `site.js` imports the running `inlaycms`;
45
+ * its default export must be a config with a site that passes `buildRegistry` and asks for the secrets the
46
+ * signed manifest lists. Trusts what `openRelease` checked: call it only on a folder that `openRelease` filled.
47
+ */
48
+ export declare function loadRelease(dir: string, opts?: {
49
+ load?: (siteJs: string) => Promise<unknown>;
50
+ }): Promise<LoadedRelease>;
51
+ /** `openRelease` and then `loadRelease`: checks the release file and loads its site. */
52
+ export declare function readRelease(file: string, opts: {
53
+ dir: string;
54
+ trustedKeys: readonly string[];
55
+ inlayVersion?: string;
56
+ load?: (siteJs: string) => Promise<unknown>;
57
+ }): Promise<LoadedRelease & {
58
+ signedBy: string;
59
+ }>;
@@ -0,0 +1,256 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { existsSync } from 'node:fs';
3
+ import { mkdir, readdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
4
+ import { join } from 'node:path';
5
+ import { fileURLToPath, pathToFileURL } from 'node:url';
6
+ import { isDeepStrictEqual } from 'node:util';
7
+ import { extractArchive } from '../archive.js';
8
+ import { InlayError } from '../errors.js';
9
+ import { buildRegistry } from '../registry/registry.js';
10
+ import { inlayVersion as currentVersion } from '../version.js';
11
+ import { fingerprint, verify } from './keys.js';
12
+ import { manifestSchema, satisfies, sha256Hex } from './manifest.js';
13
+ const SIGNED = new Set(['manifest.json', 'manifest.sig']);
14
+ /** `.ts` when running from `src/` (tsx, vitest), `.js` from `dist/`. */
15
+ const EXT = import.meta.url.endsWith('.ts') ? '.ts' : '.js';
16
+ const entry = (path) => fileURLToPath(new URL(`../../${path}${EXT}`, import.meta.url));
17
+ /**
18
+ * The running copy of each `inlaycms` entry point. Site code must import these files, not another copy of the
19
+ * package (from `src/` the package's own `exports` name `dist/`): field definitions are checked by identity.
20
+ */
21
+ export const INLAY_ENTRIES = {
22
+ inlaycms: entry('index'),
23
+ 'inlaycms/site': entry('site'),
24
+ 'inlaycms/jsx-runtime': entry('jsx/jsx-runtime'),
25
+ 'inlaycms/jsx-dev-runtime': entry('jsx/jsx-dev-runtime'),
26
+ };
27
+ /** The files of the `inlaycms` shim package, by name. */
28
+ function shimFiles() {
29
+ const files = new Map();
30
+ const exports = {};
31
+ for (const [specifier, file] of Object.entries(INLAY_ENTRIES)) {
32
+ const name = specifier === 'inlaycms' ? 'index' : specifier.slice('inlaycms/'.length);
33
+ const url = JSON.stringify(pathToFileURL(file).href);
34
+ files.set(`${name}.js`, `export * from ${url}\n${name === 'index' ? `export { default } from ${url}\n` : ''}`);
35
+ exports[name === 'index' ? '.' : `./${name}`] = `./${name}.js`;
36
+ }
37
+ files.set('package.json', JSON.stringify({ name: 'inlaycms', type: 'module', exports }, null, 2) + '\n');
38
+ return files;
39
+ }
40
+ async function readText(file) {
41
+ try {
42
+ return await readFile(file, 'utf8');
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
48
+ /** Writes `text` to `file` through a temporary file and a rename, unless the file already holds it. */
49
+ async function writeIfChanged(file, text) {
50
+ if ((await readText(file)) === text)
51
+ return;
52
+ const tmp = `${file}.tmp-${process.pid}-${randomUUID()}`;
53
+ try {
54
+ await writeFile(tmp, text);
55
+ await rename(tmp, file);
56
+ }
57
+ catch (e) {
58
+ await rm(tmp, { force: true });
59
+ throw e;
60
+ }
61
+ }
62
+ /**
63
+ * Writes `<dir>/node_modules/inlaycms` as a package of one-line modules that re-export the running copy, so a
64
+ * release's `site.js` resolves `inlaycms` to the code that loads it. (A package's `exports` can't name files
65
+ * outside it, so these are modules, not a map.) `<dir>/package.json` marks `site.js` as a module: without it, tsx
66
+ * would load it as CommonJS, and with it a second copy of `inlaycms`. Each file is replaced on its own through a
67
+ * temporary file and a rename, and left alone when it is already right, so a worker loading the release at the
68
+ * same time never finds a file missing or half written, and two writers at once end with the same files.
69
+ */
70
+ async function writeInlayShim(dir) {
71
+ const shim = join(dir, 'node_modules', 'inlaycms');
72
+ await mkdir(shim, { recursive: true });
73
+ // The modules first and the shim's package.json last, so it never names a module that isn't there yet.
74
+ for (const [name, text] of shimFiles())
75
+ await writeIfChanged(join(shim, name), text);
76
+ await writeIfChanged(join(dir, 'package.json'), '{ "type": "module" }\n');
77
+ }
78
+ function invalid() {
79
+ return new InlayError('release', 'error.releaseInvalid');
80
+ }
81
+ /** Whether a manifest path names something a release may hold. */
82
+ function releasePath(path) {
83
+ return path === 'site.js' || path.startsWith('content/') || path.startsWith('public/');
84
+ }
85
+ /** `1.x` or, before 1.0, `0.3.x`: the versions a caret range accepts. */
86
+ function series(range) {
87
+ const need = range.replace(/^\^/, '');
88
+ const [major = '', minor = ''] = need.split('.');
89
+ return { need, series: major === '0' ? `0.${minor}.x` : `${major}.x` };
90
+ }
91
+ /** Throws `error.releaseVersion` when Inlay `version` (default: the running one) isn't in a release's `range`. */
92
+ export function checkInlayVersion(range, version = currentVersion()) {
93
+ if (!satisfies(version, range))
94
+ throw new InlayError('release', 'error.releaseVersion', { range, version, ...series(range) });
95
+ }
96
+ /** The manifest and signature are small; anything bigger is refused before the signature is checked. */
97
+ const SIGNED_MAX_BYTES = 1024 ** 2;
98
+ /**
99
+ * Opens the release file at `file` into the empty folder `opts.dir` without running any of it. The signature is
100
+ * checked against `opts.trustedKeys` before anything but the manifest is read, the Inlay version range next, and
101
+ * every file's checksum last. On a failure `dir` is left empty again.
102
+ */
103
+ export async function openRelease(file, opts) {
104
+ const { dir } = opts;
105
+ await mustBeEmpty(dir);
106
+ try {
107
+ const { manifest, signedBy } = await checkRelease(file, dir, opts);
108
+ return { manifest, signedBy: signedBy };
109
+ }
110
+ catch (e) {
111
+ await emptyDir(dir);
112
+ throw e;
113
+ }
114
+ }
115
+ /**
116
+ * Opens a release file from the operator's own backup into the empty folder `opts.dir`, trusting its manifest:
117
+ * the signature isn't checked (the release was accepted when it was pushed, and the keys may have changed since),
118
+ * but the release must suit this version of Inlay and the files must be the ones the manifest lists, with its
119
+ * checksums. On a failure `dir` is left empty again.
120
+ */
121
+ export async function extractRelease(file, opts) {
122
+ await mustBeEmpty(opts.dir);
123
+ try {
124
+ const { manifest } = await checkRelease(file, opts.dir, { ...opts, trustedKeys: null });
125
+ return { manifest };
126
+ }
127
+ catch (e) {
128
+ await emptyDir(opts.dir);
129
+ throw e;
130
+ }
131
+ }
132
+ async function mustBeEmpty(dir) {
133
+ let entries;
134
+ try {
135
+ entries = await readdir(dir);
136
+ }
137
+ catch (e) {
138
+ if (e.code === 'ENOENT')
139
+ throw new InlayError('release', 'error.releaseDirMissing', { dir });
140
+ throw e;
141
+ }
142
+ if (entries.length > 0)
143
+ throw new InlayError('release', 'error.releaseDirNotEmpty', { dir });
144
+ }
145
+ /** Removes everything in `dir`, leaving the folder itself. */
146
+ async function emptyDir(dir) {
147
+ for (const entry of await readdir(dir))
148
+ await rm(join(dir, entry), { recursive: true, force: true });
149
+ }
150
+ /** With `trustedKeys: null`, the signature isn't checked and `signedBy` is null. */
151
+ async function checkRelease(file, dir, opts) {
152
+ try {
153
+ await extractArchive(file, dir, (path) => SIGNED.has(path), { maxBytes: SIGNED_MAX_BYTES });
154
+ }
155
+ catch (e) {
156
+ if (e instanceof InlayError && e.messageId === 'error.archiveNoSpace')
157
+ throw invalid();
158
+ throw e;
159
+ }
160
+ const manifestFile = join(dir, 'manifest.json');
161
+ const sigFile = join(dir, 'manifest.sig');
162
+ let signedBy = null;
163
+ if (opts.trustedKeys !== null) {
164
+ if (!existsSync(manifestFile) || !existsSync(sigFile))
165
+ throw new InlayError('release', 'error.releaseSignature');
166
+ const signature = (await readFile(sigFile, 'utf8')).trim();
167
+ const bytes = await readFile(manifestFile);
168
+ const key = opts.trustedKeys.find((k) => verify(k, bytes, signature));
169
+ if (key === undefined)
170
+ throw new InlayError('release', 'error.releaseSignature');
171
+ signedBy = fingerprint(key);
172
+ }
173
+ else if (!existsSync(manifestFile)) {
174
+ throw invalid();
175
+ }
176
+ const bytes = await readFile(manifestFile);
177
+ let manifest;
178
+ try {
179
+ manifest = manifestSchema.parse(JSON.parse(bytes.toString('utf8')));
180
+ }
181
+ catch {
182
+ throw invalid();
183
+ }
184
+ checkInlayVersion(manifest.inlay.range, opts.inlayVersion);
185
+ const listed = Object.keys(manifest.files);
186
+ if (!Object.hasOwn(manifest.files, 'site.js') || !listed.every(releasePath))
187
+ throw invalid();
188
+ if (!manifest.content.every((c) => Object.hasOwn(manifest.files, c.path) && c.path.startsWith('content/'))) {
189
+ throw invalid();
190
+ }
191
+ const unlisted = [];
192
+ const extracted = await extractArchive(file, dir, (path) => {
193
+ if (SIGNED.has(path))
194
+ return false;
195
+ if (Object.hasOwn(manifest.files, path))
196
+ return true;
197
+ unlisted.push(path);
198
+ return false;
199
+ });
200
+ const got = new Set(extracted);
201
+ if (unlisted.length > 0 || got.size !== extracted.length || !listed.every((p) => got.has(p)))
202
+ throw invalid();
203
+ for (const path of listed) {
204
+ if (sha256Hex(await readFile(join(dir, path))) !== manifest.files[path]) {
205
+ throw new InlayError('release', 'error.releaseChecksum', { path });
206
+ }
207
+ }
208
+ return { manifest, signedBy };
209
+ }
210
+ /**
211
+ * Loads the site code of a release `openRelease` opened into `dir`. `site.js` imports the running `inlaycms`;
212
+ * its default export must be a config with a site that passes `buildRegistry` and asks for the secrets the
213
+ * signed manifest lists. Trusts what `openRelease` checked: call it only on a folder that `openRelease` filled.
214
+ */
215
+ export async function loadRelease(dir, opts = {}) {
216
+ let manifest;
217
+ try {
218
+ manifest = manifestSchema.parse(JSON.parse(await readFile(join(dir, 'manifest.json'), 'utf8')));
219
+ }
220
+ catch {
221
+ throw invalid();
222
+ }
223
+ await writeInlayShim(dir);
224
+ const load = opts.load ?? ((f) => import(pathToFileURL(f).href));
225
+ let mod;
226
+ try {
227
+ mod = (await load(join(dir, 'site.js')));
228
+ }
229
+ catch (e) {
230
+ throw new InlayError('release', 'error.releaseLoad', { problem: e instanceof Error ? e.message : String(e) });
231
+ }
232
+ const config = mod?.default;
233
+ if (!config || typeof config !== 'object' || !config.site || typeof config.site !== 'object') {
234
+ throw new InlayError('release', 'error.releaseNoSite');
235
+ }
236
+ const site = config.site;
237
+ buildRegistry(site);
238
+ if (!isDeepStrictEqual([...site.secrets].sort(), [...manifest.secrets].sort())) {
239
+ throw new InlayError('release', 'error.releaseSecretsMismatch', {
240
+ manifest: manifest.secrets.join(', ') || '-',
241
+ site: site.secrets.join(', ') || '-',
242
+ });
243
+ }
244
+ return {
245
+ manifest,
246
+ site,
247
+ dir,
248
+ shippedFiles: new Map(manifest.content.map((c) => [c.source, join(dir, c.path)])),
249
+ publicDir: existsSync(join(dir, 'public')) ? join(dir, 'public') : null,
250
+ };
251
+ }
252
+ /** `openRelease` and then `loadRelease`: checks the release file and loads its site. */
253
+ export async function readRelease(file, opts) {
254
+ const { signedBy } = await openRelease(file, opts);
255
+ return { ...(await loadRelease(opts.dir, opts)), signedBy };
256
+ }
@@ -0,0 +1,31 @@
1
+ import type { ShippedReport } from './content/shipped.js';
2
+ import type { ContentIssue } from './types.js';
3
+ export type ProblemCode = 'shipped_content' | 'release_import' | 'release_forbidden';
4
+ /** One thing that stops the database from being brought up to date. `message` is written for the developer. */
5
+ export interface CheckProblem {
6
+ code: ProblemCode;
7
+ message: string;
8
+ issues?: ContentIssue[];
9
+ }
10
+ /** Something the developer should fix that doesn't stop boot. `message` is written for the developer. */
11
+ export interface CheckWarning {
12
+ code: 'slug_shadowed';
13
+ message: string;
14
+ document: {
15
+ id: string;
16
+ type: string;
17
+ locale: string;
18
+ title: string;
19
+ };
20
+ }
21
+ /** What boot or `inlaycms check` did (or would do) to a database. */
22
+ export interface CheckReport {
23
+ ok: boolean;
24
+ systemMigrations: string[];
25
+ /** What applying shipped content did. */
26
+ shipped: ShippedReport;
27
+ problems: CheckProblem[];
28
+ warnings: CheckWarning[];
29
+ }
30
+ /** The report as lines a person reads: a summary, then one line per problem with its issues indented underneath. */
31
+ export declare function formatReport(report: CheckReport): string[];
@@ -0,0 +1,37 @@
1
+ import { t } from './messages/index.js';
2
+ /** The report as lines a person reads: a summary, then one line per problem with its issues indented underneath. */
3
+ export function formatReport(report) {
4
+ const lines = [];
5
+ if (report.systemMigrations.length > 0) {
6
+ lines.push(t('report.systemMigrations', { names: report.systemMigrations.join(', ') }));
7
+ }
8
+ const { created, replaced, skipped, deletedRefs } = report.shipped;
9
+ if (created.length > 0)
10
+ lines.push(t('report.shippedCreated', { count: created.length }));
11
+ if (replaced.length > 0)
12
+ lines.push(t('report.shippedReplaced', { count: replaced.length }));
13
+ if (skipped.length > 0)
14
+ lines.push(t('report.shippedSkipped', { count: skipped.length }));
15
+ for (const { item, target, field } of deletedRefs) {
16
+ lines.push(t('report.shippedDeletedRefs', {
17
+ type: item.type,
18
+ key: item.key,
19
+ locale: item.locale,
20
+ field,
21
+ targetType: target.type,
22
+ targetKey: target.key,
23
+ }));
24
+ }
25
+ for (const warning of report.shipped.warnings)
26
+ lines.push(t('report.warning', { message: warning.message }));
27
+ if (report.ok && lines.length === 0)
28
+ lines.push(t('report.upToDate'));
29
+ for (const problem of report.problems) {
30
+ lines.push(t('report.problem', { message: problem.message }));
31
+ for (const issue of problem.issues ?? [])
32
+ lines.push(t('report.issue', { message: issue.message }));
33
+ }
34
+ for (const warning of report.warnings)
35
+ lines.push(t('report.warning', { message: warning.message }));
36
+ return lines;
37
+ }
@@ -0,0 +1,15 @@
1
+ import { type RichTextDoc } from './schema.js';
2
+ export interface RichTextImageHtml {
3
+ src: string;
4
+ srcset: string;
5
+ alt: string;
6
+ width: number | null;
7
+ height: number | null;
8
+ }
9
+ export interface RichTextResolver {
10
+ /** The encoded `href` of a document's page, or `null` if it has none. */
11
+ link(groupId: string): string | null;
12
+ image(id: string, alt: string | undefined): RichTextImageHtml | null;
13
+ }
14
+ /** The doc as HTML. Every text and attribute is escaped; only Inlay's own tags are emitted. */
15
+ export declare function richTextToHtml(doc: RichTextDoc, resolve: RichTextResolver): string;
@@ -0,0 +1,81 @@
1
+ import { escapeHtml } from '../../jsx/html.js';
2
+ import { isRichTextHref } from './schema.js';
3
+ function attr(name, value) {
4
+ return value === null || value === '' ? '' : ` ${name}="${escapeHtml(String(value))}"`;
5
+ }
6
+ /** The marks as tags, in stored (canonical) order; internal links that can't be resolved are dropped. */
7
+ function marksOf(marks, resolve) {
8
+ const out = [];
9
+ for (const mark of marks ?? []) {
10
+ if (mark.type === 'bold')
11
+ out.push({ key: 'b', open: '<strong>', close: '</strong>' });
12
+ else if (mark.type === 'italic')
13
+ out.push({ key: 'i', open: '<em>', close: '</em>' });
14
+ else {
15
+ const href = 'href' in mark.attrs ? mark.attrs.href : resolve.link(mark.attrs.document);
16
+ if (href === null || ('href' in mark.attrs && !isRichTextHref(href)))
17
+ continue;
18
+ out.push({ key: `a:${href}`, open: `<a href="${escapeHtml(href)}">`, close: '</a>' });
19
+ }
20
+ }
21
+ return out;
22
+ }
23
+ function leaf(node, resolve) {
24
+ if (node.type === 'text')
25
+ return escapeHtml(node.text);
26
+ if (node.type === 'hardBreak')
27
+ return '<br>';
28
+ const img = resolve.image(node.attrs.media, node.attrs.alt);
29
+ if (!img)
30
+ return '';
31
+ return (`<img${attr('src', img.src)}${attr('srcset', img.srcset)} alt="${escapeHtml(img.alt)}"` +
32
+ `${attr('width', img.width)}${attr('height', img.height)} loading="lazy">`);
33
+ }
34
+ /** Inline content, keeping a mark open across neighbors that share it. */
35
+ function inline(nodes, resolve) {
36
+ let out = '';
37
+ let open = [];
38
+ for (const node of nodes) {
39
+ const marks = marksOf(node.marks, resolve);
40
+ let keep = 0;
41
+ while (keep < open.length && keep < marks.length && open[keep].key === marks[keep].key)
42
+ keep++;
43
+ for (let i = open.length - 1; i >= keep; i--)
44
+ out += open[i].close;
45
+ for (let i = keep; i < marks.length; i++)
46
+ out += marks[i].open;
47
+ open = marks;
48
+ out += leaf(node, resolve);
49
+ }
50
+ for (let i = open.length - 1; i >= 0; i--)
51
+ out += open[i].close;
52
+ return out;
53
+ }
54
+ function block(node, resolve) {
55
+ const children = (nodes) => (nodes ?? []).map((n) => block(n, resolve)).join('');
56
+ switch (node.type) {
57
+ case 'paragraph':
58
+ return `<p>${inline(node.content ?? [], resolve)}</p>`;
59
+ case 'heading': {
60
+ const level = node.attrs.level;
61
+ const tag = Number.isInteger(level) && level >= 1 && level <= 6 ? `h${level}` : 'p';
62
+ return `<${tag}>${inline(node.content ?? [], resolve)}</${tag}>`;
63
+ }
64
+ case 'bulletList':
65
+ return `<ul>${children(node.content)}</ul>`;
66
+ case 'orderedList': {
67
+ const start = node.attrs?.start ?? 1;
68
+ return `<ol${start === 1 ? '' : attr('start', start)}>${children(node.content)}</ol>`;
69
+ }
70
+ case 'listItem':
71
+ return `<li>${children(node.content)}</li>`;
72
+ case 'blockquote':
73
+ return `<blockquote>${children(node.content)}</blockquote>`;
74
+ default:
75
+ return inline([node], resolve);
76
+ }
77
+ }
78
+ /** The doc as HTML. Every text and attribute is escaped; only Inlay's own tags are emitted. */
79
+ export function richTextToHtml(doc, resolve) {
80
+ return doc.content.map((node) => block(node, resolve)).join('');
81
+ }
@@ -0,0 +1,19 @@
1
+ import { type RichTextDoc, type RichTextOptions } from './schema.js';
2
+ export interface RichTextProblem {
3
+ code: 'not_allowed' | 'unsupported' | 'heading_level' | 'image_source' | 'link_url';
4
+ line: number;
5
+ message: string;
6
+ }
7
+ /** The doc as CommonMark: tight lists, `- ` bullets, `inlay:` URIs for internal links and images. */
8
+ export declare function richTextToMarkdown(doc: RichTextDoc): string;
9
+ /**
10
+ * Reads CommonMark into a normalized rich text doc allowed by `opts`. Anything the
11
+ * format or the field can't hold is reported as a line-numbered problem. Never throws.
12
+ */
13
+ export declare function markdownToRichText(markdown: string, opts?: Partial<RichTextOptions>): {
14
+ ok: true;
15
+ doc: RichTextDoc;
16
+ } | {
17
+ ok: false;
18
+ problems: RichTextProblem[];
19
+ };