inlaycms 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +469 -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,221 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { basename, isAbsolute } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { InlayError } from '../errors.js';
5
+ import { fieldValues } from '../fields/walk.js';
6
+ import { isRecord } from '../fields/zod-internals.js';
7
+ import { inspectUpload } from '../media/library.js';
8
+ import { markdownToRichText } from '../richtext/markdown.js';
9
+ import { docLabels } from './schema.js';
10
+ import { contentIssue } from './validate.js';
11
+ const KINDS = new Set(['image', 'file', 'richText', 'ref', 'link']);
12
+ /** The start of a Markdown link target `](inlay:key/<type>` or `](inlay:key/<type>/<key>`; text elsewhere is left alone. */
13
+ const KEY_HREF = /\]\(inlay:key\/([\w-]+)(?:\/([\w-]+))?(?=[\s)])/g;
14
+ /** `root` with the value at `path` replaced, copying only the containers along the path. */
15
+ function setAt(root, path, value) {
16
+ const [head, ...rest] = path;
17
+ if (head === undefined)
18
+ return value;
19
+ if (Array.isArray(root)) {
20
+ const copy = [...root];
21
+ copy[head] = setAt(copy[head], rest, value);
22
+ return copy;
23
+ }
24
+ const record = isRecord(root) ? root : {};
25
+ return { ...record, [head]: setAt(record[head], rest, value) };
26
+ }
27
+ /** The source a `file` value is written as: a URL's href, or the string itself. */
28
+ function fileSource(file) {
29
+ if (file instanceof URL)
30
+ return file.href;
31
+ return typeof file === 'string' ? file : null;
32
+ }
33
+ /**
34
+ * The absolute path a `file` value names, or null if it isn't an absolute path or a file: URL. A source in
35
+ * `shipped` (a loaded release's copies of its files) is read from where the release put it.
36
+ */
37
+ function localPath(file, shipped) {
38
+ const source = fileSource(file);
39
+ const mapped = source === null ? undefined : shipped?.get(source);
40
+ if (mapped !== undefined)
41
+ return mapped;
42
+ try {
43
+ if (file instanceof URL)
44
+ return file.protocol === 'file:' ? fileURLToPath(file) : null;
45
+ if (typeof file !== 'string')
46
+ return null;
47
+ if (file.startsWith('file:'))
48
+ return fileURLToPath(file);
49
+ return isAbsolute(file) ? file : null;
50
+ }
51
+ catch {
52
+ return null;
53
+ }
54
+ }
55
+ /** Shipped content can't contain images in rich text: there is no way to name their files. */
56
+ function withoutImages(opts) {
57
+ return opts && { ...opts, features: opts.features.filter((f) => f !== 'image') };
58
+ }
59
+ /**
60
+ * Turns shipped content as a developer writes it into the stored shape:
61
+ * Markdown strings in rich text fields become rich text, and `{ file, alt? }`
62
+ * in image and file fields is read from disk, checked like an upload, and
63
+ * replaced by `{ media, alt? }`. References to other shipped documents by key
64
+ * become their group ids: `{ key }` in `ref` fields, `{ document: { type, key? } }`
65
+ * in `link` fields and `inlay:key/<type>[/<key>]` links in Markdown. Covers the
66
+ * template fields and every slot that isn't switched off. Returns the files to
67
+ * import and any problems.
68
+ */
69
+ export async function resolveShippedInput(deps, type, input, resolveKey) {
70
+ const { template } = deps.registry.getType(type);
71
+ const files = new Map();
72
+ const issues = [];
73
+ const issue = (path, code, messageId, params = {}) => {
74
+ issues.push(contentIssue(path, docLabels(deps.registry, type, path) ?? path.map(String), code, messageId, params));
75
+ };
76
+ /** The group id `ref` names, or null after reporting it at `path`. */
77
+ const groupOf = (path, ref) => {
78
+ const id = resolveKey(ref);
79
+ if (id === null)
80
+ issue(path, 'not_found', 'issue.shippedKeyUnknown', { type: ref.type, key: ref.key ?? ref.type });
81
+ return id;
82
+ };
83
+ /** A `ref` field's `{ key }`, as a group id; anything else is left as it is. */
84
+ const refValue = (path, target, value) => {
85
+ if (!isRecord(value) || typeof value.key !== 'string')
86
+ return value;
87
+ return groupOf(path, { type: target, key: value.key }) ?? value;
88
+ };
89
+ /** The stored value for one found value, or `undefined` to leave it as it is. */
90
+ const resolve = async (path, meta, value) => {
91
+ if (meta.kind === 'ref') {
92
+ const target = meta.target ?? '';
93
+ if (Array.isArray(value))
94
+ return value.map((item, i) => refValue([...path, i], target, item));
95
+ return refValue(path, target, value);
96
+ }
97
+ if (meta.kind === 'link') {
98
+ if (!isRecord(value) || !isRecord(value.document) || typeof value.document.type !== 'string')
99
+ return undefined;
100
+ const ref = { type: value.document.type };
101
+ if (typeof value.document.key === 'string')
102
+ ref.key = value.document.key;
103
+ const id = groupOf(path, ref);
104
+ return id === null ? undefined : { ...value, document: id };
105
+ }
106
+ if (meta.kind === 'richText') {
107
+ if (typeof value !== 'string')
108
+ return undefined;
109
+ let unknownKey = false;
110
+ const markdown = value.replace(KEY_HREF, (href, refType, key) => {
111
+ const id = groupOf(path, key === undefined ? { type: refType } : { type: refType, key });
112
+ if (id === null)
113
+ unknownKey = true;
114
+ return id === null ? href : `](inlay:document/${id}`;
115
+ });
116
+ if (unknownKey)
117
+ return undefined;
118
+ const result = markdownToRichText(markdown, meta.richText);
119
+ for (const problem of result.ok ? [] : result.problems) {
120
+ issue(path, 'invalid', 'issue.richText', { problem: problem.message });
121
+ }
122
+ // What only the image-free reading finds are images the field allows but shipped content can't name.
123
+ const bare = markdownToRichText(markdown, withoutImages(meta.richText));
124
+ const known = new Set(result.ok ? [] : result.problems.map((p) => p.message));
125
+ const images = bare.ok ? [] : bare.problems.filter((p) => !known.has(p.message));
126
+ for (const image of images)
127
+ issue(path, 'invalid', 'issue.shippedRichTextImage', { line: String(image.line) });
128
+ return result.ok && images.length === 0 ? result.doc : undefined;
129
+ }
130
+ if (!isRecord(value) || !Object.hasOwn(value, 'file'))
131
+ return undefined;
132
+ const source = fileSource(value.file);
133
+ if (deps.shippedFiles && (source === null || !deps.shippedFiles.has(source))) {
134
+ issue(path, 'not_found', 'issue.shippedFileUnknown', { path: String(source ?? value.file) });
135
+ return undefined;
136
+ }
137
+ const file = localPath(value.file, deps.shippedFiles);
138
+ if (file === null) {
139
+ issue(path, 'invalid', 'issue.shippedFilePath', { path: String(value.file) });
140
+ return undefined;
141
+ }
142
+ let bytes;
143
+ try {
144
+ bytes = await readFile(file);
145
+ }
146
+ catch {
147
+ issue(path, 'not_found', 'issue.shippedFileMissing', { path: file });
148
+ return undefined;
149
+ }
150
+ try {
151
+ const info = await inspectUpload(deps, bytes, basename(file));
152
+ files.set(info.id, { bytes, ...info });
153
+ return meta.kind === 'image' && value.alt !== undefined ? { media: info.id, alt: value.alt } : { media: info.id };
154
+ }
155
+ catch (e) {
156
+ if (!(e instanceof InlayError) || e.code !== 'validation')
157
+ throw e;
158
+ issue(path, 'invalid', 'issue.shippedFileInvalid', { problem: e.message });
159
+ return undefined;
160
+ }
161
+ };
162
+ const resolveAll = async (schema, value, prefix) => {
163
+ let out = value;
164
+ for (const found of fieldValues(schema, value, KINDS)) {
165
+ const next = await resolve([...prefix, ...found.path], found.meta, found.value);
166
+ if (next !== undefined)
167
+ out = setAt(out, found.path, next);
168
+ }
169
+ return out;
170
+ };
171
+ const out = { ...input };
172
+ if (input.fields !== undefined) {
173
+ out.fields = (await resolveAll(template.fields, input.fields, ['fields']));
174
+ }
175
+ if (input.slots !== undefined) {
176
+ const slots = {};
177
+ for (const [key, given] of Object.entries(input.slots)) {
178
+ const slot = template.slots[key];
179
+ slots[key] =
180
+ given === false || !slot
181
+ ? given
182
+ : (await resolveAll(slot.block.schema, given, ['slots', key, 'data']));
183
+ }
184
+ out.slots = slots;
185
+ }
186
+ return { input: out, files, issues };
187
+ }
188
+ const FILE_KINDS = new Set(['image', 'file']);
189
+ /**
190
+ * Every `{ file }` named in the registry's shipped content (template fields and slots), once per source: the
191
+ * source as written (a file: URL's href or an absolute path) and the local path it names. Values that don't name
192
+ * a local file are left out; applying the content reports them.
193
+ */
194
+ export function shippedFiles(registry) {
195
+ const found = new Map();
196
+ const collect = (schema, value) => {
197
+ for (const { value: v } of fieldValues(schema, value, FILE_KINDS)) {
198
+ if (!isRecord(v) || !Object.hasOwn(v, 'file'))
199
+ continue;
200
+ const source = fileSource(v.file);
201
+ const path = localPath(v.file);
202
+ if (source !== null && path !== null)
203
+ found.set(source, path);
204
+ }
205
+ };
206
+ for (const [type, documents] of registry.content) {
207
+ const { template } = registry.getType(type);
208
+ for (const doc of documents) {
209
+ for (const input of Object.values(doc.content)) {
210
+ if (input.fields !== undefined)
211
+ collect(template.fields, input.fields);
212
+ for (const [key, given] of Object.entries(input.slots ?? {})) {
213
+ const slot = template.slots[key];
214
+ if (given !== false && slot)
215
+ collect(slot.block.schema, given);
216
+ }
217
+ }
218
+ }
219
+ }
220
+ return [...found].map(([source, path]) => ({ source, path }));
221
+ }
@@ -0,0 +1,112 @@
1
+ import type { Selectable } from 'kysely';
2
+ import type { DocumentsTable } from '../db/schema.js';
3
+ import type { CoreDeps, Ctx, DocumentData, DocumentKind } from '../types.js';
4
+ import { type PendingFile } from './shipped-input.js';
5
+ /** One shipped document in one locale. `documentId` is null for a document a dry run would create. */
6
+ export interface ShippedItem {
7
+ documentId: string | null;
8
+ type: string;
9
+ key: string;
10
+ locale: string;
11
+ edition: number;
12
+ }
13
+ /** What applying shipped content did, or would do in a dry run. Each list is sorted by type, key and locale. */
14
+ export interface ShippedReport {
15
+ created: ShippedItem[];
16
+ replaced: ShippedItem[];
17
+ skipped: ShippedItem[];
18
+ /** References to entries the client deleted, left out of the shipped content written. `field` is the field's label path. */
19
+ deletedRefs: Array<{
20
+ item: ShippedItem;
21
+ target: {
22
+ type: string;
23
+ key: string;
24
+ };
25
+ field: string;
26
+ }>;
27
+ /**
28
+ * A slug or path the shipped content asks for that is already taken, and what was done instead: another slug,
29
+ * the path the document had, or no path. `inlaycms check` reports each as a problem; activation goes ahead.
30
+ */
31
+ warnings: Array<{
32
+ item: ShippedItem;
33
+ message: string;
34
+ }>;
35
+ }
36
+ /**
37
+ * What to do with one shipped document in one locale: `create` it, `replace`
38
+ * the stored row, `skip` it (the client deleted its group), or nothing,
39
+ * since it's `current` (the stored edition is equal or higher).
40
+ */
41
+ export interface ShippedAction {
42
+ mode: 'create' | 'replace' | 'skip' | 'current';
43
+ /** For a create, `documentId` is the id the document gets. */
44
+ item: ShippedItem;
45
+ kind: DocumentKind;
46
+ groupId: string;
47
+ /** The stored row, or null when there is none. */
48
+ row: Selectable<DocumentsTable> | null;
49
+ /**
50
+ * The data a create or replace writes: resolved, validated, with references
51
+ * to deleted entries removed and, for a replace, the head's unknown keys
52
+ * carried. For a skip or current action, the validated data with
53
+ * `validateAll`, else null.
54
+ */
55
+ data: DocumentData | null;
56
+ /** Files the shipped content names, to import. */
57
+ files: Map<string, PendingFile>;
58
+ }
59
+ /** Every shipped document and locale with what to do with it, in report order, and the deleted references left out. */
60
+ export interface ShippedPlan {
61
+ actions: ShippedAction[];
62
+ deletedRefs: ShippedReport['deletedRefs'];
63
+ warnings: ShippedReport['warnings'];
64
+ }
65
+ /**
66
+ * Works out what applying the site's shipped content (spec §6.3) would do,
67
+ * per shipped document and locale: a missing row is created; a row whose
68
+ * edition is lower (or null) is replaced; an equal or higher edition is
69
+ * current; a group the client deleted is skipped. Every create and replace
70
+ * is resolved and checked (with `validateAll`, every shipped document and
71
+ * locale, which changes nothing else); the first problem throws
72
+ * `shipped_content`. A slug or path already taken isn't a problem: the
73
+ * document keeps its stored slug and path (a new one gets a free slug and no path),
74
+ * and a warning says so. Writes nothing. Run it in the transaction that writes
75
+ * the plan, so nothing changes in between.
76
+ */
77
+ export declare function planShippedContent(deps: CoreDeps, opts?: {
78
+ validateAll?: boolean;
79
+ }): Promise<ShippedPlan>;
80
+ /**
81
+ * Puts the files a plan's creates and replaces name in the media store, telling `onFileStored` of each first. Run
82
+ * it before the transaction that writes the plan opens, so that transaction holds the write lock for database
83
+ * writes only: `writeShippedContent` then finds the files stored. Files are named by their content, so storing one
84
+ * that is never written to the database harms nothing (a caller removes those after a failure).
85
+ */
86
+ export declare function storeShippedFiles(deps: CoreDeps, plan: ShippedPlan, onFileStored?: (fileId: string) => void): Promise<void>;
87
+ /**
88
+ * Writes a plan from `planShippedContent`: imports the files, creates and
89
+ * replaces the documents and publishes them, as one publish event. `deps.db`
90
+ * should be the transaction the plan was made in. With `dryRun`, no file is
91
+ * stored and created documents are reported without their ids; rolling back
92
+ * is the caller's. Revisions and the publish event are written with `ctx`
93
+ * (default: the system acting as `release`, without a release id).
94
+ * `onFileStored` hears of each file put in the media store before its row is
95
+ * written, so a caller that rolls back can remove the files no row names. A
96
+ * file already stored (see `storeShippedFiles`) isn't written again.
97
+ */
98
+ export declare function writeShippedContent(deps: CoreDeps, plan: ShippedPlan, opts?: {
99
+ dryRun?: boolean;
100
+ ctx?: Ctx;
101
+ onFileStored?: (fileId: string) => void;
102
+ }): Promise<ShippedReport>;
103
+ /**
104
+ * Applies the site's shipped content (spec §6.3): plans and writes it in one
105
+ * transaction, so a problem writes nothing. With `dryRun`, reports what it
106
+ * would do and rolls back. `validateAll` checks every shipped document, not
107
+ * only what's written.
108
+ */
109
+ export declare function applyShippedContent(deps: CoreDeps, opts?: {
110
+ dryRun?: boolean;
111
+ validateAll?: boolean;
112
+ }): Promise<ShippedReport>;