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,287 @@
1
+ import { assertCan } from '../auth/roles.js';
2
+ import { InlayError } from '../errors.js';
3
+ import { fieldMeta } from '../fields/define.js';
4
+ import { defOf, innerOf, isRecord } from '../fields/zod-internals.js';
5
+ import { whereVisible } from './read.js';
6
+ import { writeDraft } from './save.js';
7
+ import { docLabels } from './schema.js';
8
+ import { contentIssue, mergeIssues, validateContent } from './validate.js';
9
+ import { validationError } from './write.js';
10
+ /** The object shape or list element behind any wrappers and pipes, merging union options. */
11
+ function structure(schema) {
12
+ const inner = innerOf(schema);
13
+ if (inner)
14
+ return structure(inner);
15
+ const def = defOf(schema);
16
+ if (def.type === 'object' && def.shape)
17
+ return { shape: def.shape };
18
+ if (def.type === 'array' && def.element)
19
+ return { element: def.element };
20
+ if (def.type === 'union' && def.options) {
21
+ const shape = {};
22
+ for (const option of def.options)
23
+ Object.assign(shape, structure(option).shape);
24
+ return Object.keys(shape).length > 0 ? { shape } : {};
25
+ }
26
+ return {};
27
+ }
28
+ class Rejected extends Error {
29
+ issues;
30
+ constructor(issues) {
31
+ super(issues[0]?.message);
32
+ this.issues = issues;
33
+ }
34
+ }
35
+ const labelsOf = (registry, type, p) => docLabels(registry, type, p) ?? p.map(String);
36
+ /** `segment` under `parent` isn't one of `valid` (key and label pairs). */
37
+ function unknownIssue(registry, type, parent, segment, valid) {
38
+ const at = [...parent, segment];
39
+ const labels = labelsOf(registry, type, parent);
40
+ const name = String(segment);
41
+ const names = valid.map(([key, label]) => (label === key ? key : `${key} (${label})`)).join(', ');
42
+ const slots = parent.length === 1 && parent[0] === 'slots';
43
+ const messageId = valid.length === 0 ? (slots ? 'issue.noSlots' : 'issue.noFields') : slots ? 'issue.unknownSlot' : 'issue.unknownField';
44
+ return contentIssue(at, labels, 'unknown_field', messageId, { name, valid: names });
45
+ }
46
+ const shapeNames = (shape) => Object.entries(shape).map(([key, child]) => [key, fieldMeta(child)?.label ?? key]);
47
+ const slotNames = (registry, type) => Object.entries(registry.getType(type).template.slots).map(([k, s]) => [k, s.label ?? s.block.label]);
48
+ const topNames = (registry, type) => ['slug', 'path', 'fields', 'slots'].flatMap((k) => {
49
+ const labels = docLabels(registry, type, [k]);
50
+ return labels === null ? [] : [[k, labels.at(-1) ?? k]];
51
+ });
52
+ /** Every key of `value` that isn't in the schema, down through groups, objects and lists (not into leaf fields). */
53
+ function unknownKeys(registry, type, sch, value, at) {
54
+ const meta = fieldMeta(sch);
55
+ if (meta && meta.kind !== 'group' && meta.kind !== 'list')
56
+ return [];
57
+ const { shape, element } = structure(sch);
58
+ if (shape && isRecord(value)) {
59
+ return Object.entries(value).flatMap(([key, child]) => Object.hasOwn(shape, key)
60
+ ? unknownKeys(registry, type, shape[key], child, [...at, key])
61
+ : [unknownIssue(registry, type, at, key, shapeNames(shape))]);
62
+ }
63
+ if (element && Array.isArray(value))
64
+ return value.flatMap((item, i) => unknownKeys(registry, type, element, item, [...at, i]));
65
+ return [];
66
+ }
67
+ /**
68
+ * Every key of whole content (as `createEntry` takes it, with `{ enabled, data }` slots) that `type` doesn't have:
69
+ * slug or path where they don't apply, fields, slots and slot parts. Saving would drop them silently.
70
+ */
71
+ export function unknownContentKeys(registry, type, content) {
72
+ const { template } = registry.getType(type);
73
+ const top = topNames(registry, type);
74
+ const issues = [];
75
+ for (const key of ['slug', 'path']) {
76
+ if (content[key] !== undefined && !top.some(([k]) => k === key))
77
+ issues.push(unknownIssue(registry, type, [], key, top));
78
+ }
79
+ issues.push(...unknownKeys(registry, type, template.fields, content.fields, ['fields']));
80
+ if (!isRecord(content.slots))
81
+ return issues;
82
+ for (const [key, slot] of Object.entries(content.slots)) {
83
+ const def = template.slots[key];
84
+ if (!def) {
85
+ issues.push(unknownIssue(registry, type, ['slots'], key, slotNames(registry, type)));
86
+ continue;
87
+ }
88
+ if (isRecord(slot))
89
+ issues.push(...unknownKeys(registry, type, def.block.schema, slot.data, ['slots', key, 'data']));
90
+ }
91
+ return issues;
92
+ }
93
+ function applyOp(registry, type, data, op) {
94
+ const { path } = op;
95
+ const def = registry.getType(type);
96
+ const invalid = (at) => {
97
+ throw new Rejected([contentIssue(at, labelsOf(registry, type, at), 'invalid', 'issue.invalid')]);
98
+ };
99
+ const unknown = (parent, segment, valid) => {
100
+ throw new Rejected([unknownIssue(registry, type, parent, segment, valid)]);
101
+ };
102
+ /** Rejects every key of `value` that isn't in the schema. */
103
+ const checkValue = (sch, value, at) => {
104
+ const found = unknownKeys(registry, type, sch, value, at);
105
+ if (found.length > 0)
106
+ throw new Rejected(found);
107
+ };
108
+ const top = topNames(registry, type);
109
+ const [head, ...rest] = path;
110
+ if (head === undefined)
111
+ return invalid([]);
112
+ if (typeof head !== 'string' || !top.some(([k]) => k === head))
113
+ return unknown([], head, top);
114
+ const root = data;
115
+ if (head === 'slug' || head === 'path') {
116
+ if (rest.length > 0)
117
+ return invalid(path);
118
+ setKey(root, head, op.value);
119
+ return;
120
+ }
121
+ if (head === 'fields') {
122
+ const schema = def.template.fields;
123
+ if (rest.length === 0) {
124
+ if (op.value === undefined)
125
+ return invalid(['fields']);
126
+ checkValue(schema, op.value, ['fields']);
127
+ root.fields = op.value;
128
+ return;
129
+ }
130
+ root.fields = isRecord(root.fields) ? root.fields : {};
131
+ descend(schema, root.fields, ['fields'], rest);
132
+ return;
133
+ }
134
+ const [key, part, ...more] = rest;
135
+ if (key === undefined)
136
+ return invalid(['slots']);
137
+ if (typeof key !== 'string' || !Object.hasOwn(def.template.slots, key)) {
138
+ return unknown(['slots'], key, slotNames(registry, type));
139
+ }
140
+ const schema = def.template.slots[key].block.schema;
141
+ const partNames = [
142
+ ['enabled', docLabels(registry, type, ['slots', key, 'enabled']).at(-1)],
143
+ ['data', 'data'],
144
+ ];
145
+ const slots = (root.slots = isRecord(root.slots) ? root.slots : {});
146
+ if (part === undefined) {
147
+ if (op.value === undefined)
148
+ return invalid(['slots', key]);
149
+ if (isRecord(op.value)) {
150
+ const parts = Object.keys(op.value).filter((k) => k !== 'enabled' && k !== 'data');
151
+ const found = [
152
+ ...parts.map((k) => unknownIssue(registry, type, ['slots', key], k, partNames)),
153
+ ...unknownKeys(registry, type, schema, op.value.data, ['slots', key, 'data']),
154
+ ];
155
+ if (found.length > 0)
156
+ throw new Rejected(found);
157
+ }
158
+ slots[key] = op.value;
159
+ return;
160
+ }
161
+ if (part !== 'enabled' && part !== 'data')
162
+ return unknown(['slots', key], part, partNames);
163
+ const slot = (slots[key] = isRecord(slots[key]) ? slots[key] : { enabled: true, data: {} });
164
+ if (part === 'enabled') {
165
+ if (more.length > 0 || op.value === undefined)
166
+ return invalid(['slots', key, 'enabled']);
167
+ slot.enabled = op.value;
168
+ return;
169
+ }
170
+ const base = ['slots', key, 'data'];
171
+ if (more.length === 0) {
172
+ if (op.value === undefined)
173
+ return invalid(base);
174
+ checkValue(schema, op.value, base);
175
+ slot.data = op.value;
176
+ return;
177
+ }
178
+ slot.data = isRecord(slot.data) ? slot.data : {};
179
+ descend(schema, slot.data, base, more);
180
+ function setKey(target, key, value) {
181
+ if (value === undefined)
182
+ delete target[key];
183
+ else
184
+ target[key] = value;
185
+ }
186
+ function descend(sch, node, at, remaining) {
187
+ const [segment, ...after] = remaining;
188
+ if (segment === undefined)
189
+ return;
190
+ const { shape, element } = structure(sch);
191
+ if (shape) {
192
+ if (typeof segment !== 'string')
193
+ return invalid([...at, segment]);
194
+ if (!Object.hasOwn(shape, segment))
195
+ return unknown(at, segment, shapeNames(shape));
196
+ const target = node;
197
+ const here = [...at, segment];
198
+ const child = shape[segment];
199
+ if (after.length === 0) {
200
+ checkValue(child, op.value, here);
201
+ return setKey(target, segment, op.value);
202
+ }
203
+ const next = structure(child);
204
+ if (target[segment] === undefined || target[segment] === null) {
205
+ if (op.value === undefined)
206
+ return invalid(here);
207
+ target[segment] = next.element ? [] : {};
208
+ }
209
+ return descend(child, target[segment], here, after);
210
+ }
211
+ if (element) {
212
+ const list = node;
213
+ if (typeof segment !== 'number' || !Number.isInteger(segment) || segment < 0 || segment > list.length) {
214
+ return invalid([...at, segment]);
215
+ }
216
+ const here = [...at, segment];
217
+ if (after.length === 0) {
218
+ if (op.value === undefined)
219
+ return invalid(here);
220
+ checkValue(element, op.value, here);
221
+ list[segment] = op.value;
222
+ return;
223
+ }
224
+ if (segment === list.length)
225
+ return invalid(here);
226
+ const next = structure(element);
227
+ if (list[segment] === undefined || list[segment] === null)
228
+ list[segment] = next.element ? [] : {};
229
+ return descend(element, list[segment], here, after);
230
+ }
231
+ return invalid(at);
232
+ }
233
+ }
234
+ /** Applies each op of `ops` that it can to a copy of `data`, collecting the problems of those it can't. */
235
+ function applyEach(registry, type, data, ops) {
236
+ let next = structuredClone(data);
237
+ const issues = [];
238
+ for (const op of ops) {
239
+ const attempt = structuredClone(next);
240
+ try {
241
+ applyOp(registry, type, attempt, op);
242
+ next = attempt;
243
+ }
244
+ catch (e) {
245
+ if (!(e instanceof Rejected))
246
+ throw e;
247
+ issues.push(...e.issues);
248
+ }
249
+ }
250
+ return { next, issues };
251
+ }
252
+ /**
253
+ * Applies `ops` in order to a copy of `data`. Every path must exist in the
254
+ * document's schema; each op that doesn't is rejected with the valid names at
255
+ * that level. The result is not yet validated against the schema.
256
+ */
257
+ export function applyPatch(registry, type, data, ops) {
258
+ const { next, issues } = applyEach(registry, type, data, ops);
259
+ return issues.length > 0 ? { ok: false, issues } : { ok: true, data: next };
260
+ }
261
+ /**
262
+ * Every problem `ops` have on `data`: the ops that can't be applied, then what checking the rest as a draft
263
+ * finds, leaving out what falls under a path already reported. Empty when the patch would save.
264
+ */
265
+ export function patchProblems(registry, type, data, ops) {
266
+ const { next, issues } = applyEach(registry, type, data, ops);
267
+ const validated = validateContent(registry, type, next, 'draft');
268
+ return mergeIssues(issues, validated.ok ? [] : validated.issues);
269
+ }
270
+ /** Applies field-path patch operations to the head draft, with the same rules as `saveDraft`. */
271
+ export async function patchDraft(deps, documentId, input, ctx) {
272
+ assertCan(ctx, 'content.write');
273
+ const doc = await deps.db
274
+ .selectFrom('documents')
275
+ .select('type')
276
+ .where('id', '=', documentId)
277
+ .$call(whereVisible(deps.registry))
278
+ .executeTakeFirst();
279
+ if (!doc)
280
+ throw new InlayError('not_found', 'error.notFound', { name: documentId });
281
+ return writeDraft(deps, documentId, input, ctx, (head) => {
282
+ const result = applyPatch(deps.registry, doc.type, head, input.ops);
283
+ if (!result.ok)
284
+ throw validationError(patchProblems(deps.registry, doc.type, head, input.ops));
285
+ return result.data;
286
+ });
287
+ }
@@ -0,0 +1,6 @@
1
+ import type { ContentIssue, CoreDeps } from '../types.js';
2
+ /**
3
+ * A `path_taken` issue if the custom `path` can't be used by a `type` entry in `locale` (a site route, a
4
+ * reserved path or another page has it), else `null`.
5
+ */
6
+ export declare function pathIssue(deps: CoreDeps, type: string, locale: string, path: string, excludeDocumentId?: string): Promise<ContentIssue | null>;
@@ -0,0 +1,38 @@
1
+ import { isReserved, routeRegExp, singletonPath } from '../site/paths.js';
2
+ import { docLabels } from './schema.js';
3
+ import { contentIssue } from './validate.js';
4
+ /**
5
+ * A `path_taken` issue if the custom `path` can't be used by a `type` entry in `locale` (a site route, a
6
+ * reserved path or another page has it), else `null`.
7
+ */
8
+ export async function pathIssue(deps, type, locale, path, excludeDocumentId) {
9
+ const { registry } = deps;
10
+ const at = ['path'];
11
+ const labels = docLabels(registry, type, at) ?? at;
12
+ if (registry.site.routes.some((r) => r.path === path))
13
+ return contentIssue(at, labels, 'path_taken', 'issue.pathRoute', { path });
14
+ const first = path.split('/')[1] ?? '';
15
+ let taken = isReserved(path) || registry.locales.includes(first);
16
+ for (const def of registry.types.values()) {
17
+ if (taken)
18
+ break;
19
+ if (def.kind === 'singleton')
20
+ taken = singletonPath(def, locale, registry.defaultLocale) === path;
21
+ else if (def.kind === 'collection' && def.route !== null)
22
+ taken = routeRegExp(def.route).test(path);
23
+ }
24
+ if (!taken) {
25
+ let query = deps.db
26
+ .selectFrom('documents')
27
+ .select('id')
28
+ .where('locale', '=', locale)
29
+ .where('deleted_at', 'is', null)
30
+ .where((eb) => eb.or([eb('head_path', '=', path), eb('published_path', '=', path)]));
31
+ if (excludeDocumentId !== undefined)
32
+ query = query.where('id', '!=', excludeDocumentId);
33
+ taken = (await query.executeTakeFirst()) !== undefined;
34
+ }
35
+ if (!taken)
36
+ return null;
37
+ return contentIssue(at, labels, 'path_taken', 'issue.pathTaken', { path });
38
+ }
@@ -0,0 +1,26 @@
1
+ import type { CoreDeps, Ctx, DocumentSummary } from '../types.js';
2
+ export interface PublishResult {
3
+ eventId: number | null;
4
+ items: Array<{
5
+ documentId: string;
6
+ revisionId: number | null;
7
+ action: 'publish' | 'unpublish';
8
+ }>;
9
+ }
10
+ export declare function recordEvent(deps: CoreDeps, ctx: Ctx, message: string | null, items: PublishResult['items']): Promise<number | null>;
11
+ export declare function publish(deps: CoreDeps, documentIds: string[], ctx: Ctx, opts?: {
12
+ message?: string;
13
+ expect?: Record<string, number>;
14
+ dryRun?: boolean;
15
+ }): Promise<PublishResult>;
16
+ export declare function unpublish(deps: CoreDeps, documentIds: string[], ctx: Ctx, opts?: {
17
+ dryRun?: boolean;
18
+ }): Promise<PublishResult>;
19
+ /** Non-deleted documents never published or changed since, newest head first. */
20
+ export declare function listPendingChanges(deps: CoreDeps): Promise<DocumentSummary[]>;
21
+ /** What publishing each document would change, as readable lines (at most 12 each, plus a "more" line). */
22
+ export declare function describeChanges(deps: CoreDeps, documentIds: string[]): Promise<Array<{
23
+ document: DocumentSummary;
24
+ isNew: boolean;
25
+ lines: string[];
26
+ }>>;
@@ -0,0 +1,211 @@
1
+ import { assertCan } from '../auth/roles.js';
2
+ import { InlayError } from '../errors.js';
3
+ import { autoRedirect } from '../redirects/redirects.js';
4
+ import { t } from '../messages/index.js';
5
+ import { runTransaction } from './dry-run.js';
6
+ import { diffRevisions } from './history.js';
7
+ import { formatDiff } from './diff.js';
8
+ import { documentTitle, parseData, summaryQuery, toSummary, whereVisible } from './read.js';
9
+ import { documentRefPaths, mediaRefPaths, syncRefs } from './refs.js';
10
+ import { docLabels } from './schema.js';
11
+ import { contentIssue, validateContent } from './validate.js';
12
+ export async function recordEvent(deps, ctx, message, items) {
13
+ if (items.length === 0)
14
+ return null;
15
+ const row = await deps.db
16
+ .insertInto('publish_events')
17
+ .values({
18
+ at: deps.now().toISOString(),
19
+ user_id: ctx.actor.id,
20
+ user_name: ctx.actor.name,
21
+ source: ctx.source,
22
+ message,
23
+ items: JSON.stringify(items),
24
+ })
25
+ .returning('id')
26
+ .executeTakeFirstOrThrow();
27
+ return row.id;
28
+ }
29
+ export async function publish(deps, documentIds, ctx, opts = {}) {
30
+ assertCan(ctx, 'content.publish');
31
+ const ids = [...new Set(documentIds)];
32
+ return runTransaction(deps, async (tx) => {
33
+ const trx = tx.db;
34
+ const failures = [];
35
+ const items = [];
36
+ const docs = new Map();
37
+ for (const id of ids) {
38
+ const doc = await trx
39
+ .selectFrom('documents')
40
+ .selectAll()
41
+ .where('id', '=', id)
42
+ .$call(whereVisible(deps.registry))
43
+ .executeTakeFirst();
44
+ if (!doc || doc.head_rev === null) {
45
+ failures.push({
46
+ documentId: id,
47
+ title: id,
48
+ issues: [contentIssue([], [], 'not_found', 'issue.documentMissing')],
49
+ });
50
+ continue;
51
+ }
52
+ const rev = await trx
53
+ .selectFrom('revisions')
54
+ .select('data')
55
+ .where('id', '=', doc.head_rev)
56
+ .executeTakeFirstOrThrow();
57
+ const data = parseData(tx, doc.type, rev.data);
58
+ const title = documentTitle(tx, doc, data, doc.head_slug);
59
+ if (doc.deleted_at !== null) {
60
+ failures.push({
61
+ documentId: id,
62
+ title,
63
+ issues: [contentIssue([], [], 'invalid', 'issue.documentDeleted')],
64
+ });
65
+ continue;
66
+ }
67
+ const expected = opts.expect?.[id];
68
+ if (expected !== undefined && doc.head_rev !== expected) {
69
+ throw new InlayError('conflict', 'error.publishChanged', { title });
70
+ }
71
+ if (doc.published_rev === doc.head_rev)
72
+ continue;
73
+ const issues = [];
74
+ const validated = validateContent(deps.registry, doc.type, data, 'strict');
75
+ if (!validated.ok)
76
+ issues.push(...validated.issues);
77
+ const found = documentRefPaths(tx, doc.type, data);
78
+ if (found.length > 0) {
79
+ const targets = await trx
80
+ .selectFrom('documents')
81
+ .select(['group_id', 'deleted_at'])
82
+ .where('group_id', 'in', [...new Set(found.map((r) => r.ref.id))])
83
+ .$call(whereVisible(deps.registry))
84
+ .execute();
85
+ const visible = new Set(targets.map((d) => d.group_id));
86
+ const gone = new Set(targets.filter((d) => d.deleted_at !== null).map((d) => d.group_id));
87
+ for (const ref of found) {
88
+ const missing = !visible.has(ref.ref.id);
89
+ if (!missing && !gone.has(ref.ref.id))
90
+ continue;
91
+ const labels = docLabels(deps.registry, doc.type, ref.path) ?? ref.path.map(String);
92
+ issues.push(missing
93
+ ? contentIssue(ref.path, labels, 'not_found', 'issue.notFound')
94
+ : contentIssue(ref.path, labels, 'deleted_reference', 'issue.deletedReference'));
95
+ }
96
+ }
97
+ const mediaFound = mediaRefPaths(tx, doc.type, data);
98
+ if (mediaFound.length > 0) {
99
+ const mediaIds = [...new Set(mediaFound.map((r) => r.ref.id))];
100
+ const present = new Set((await trx.selectFrom('media').select('id').where('id', 'in', mediaIds).execute()).map((m) => m.id));
101
+ const dels = await trx
102
+ .selectFrom('media_deletions')
103
+ .select(['media_id', 'filename'])
104
+ .where('media_id', 'in', mediaIds)
105
+ .orderBy('id', 'asc')
106
+ .execute();
107
+ const filenames = new Map(dels.map((d) => [d.media_id, d.filename]));
108
+ for (const ref of mediaFound) {
109
+ if (present.has(ref.ref.id))
110
+ continue;
111
+ const labels = docLabels(deps.registry, doc.type, ref.path) ?? ref.path.map(String);
112
+ const filename = filenames.get(ref.ref.id);
113
+ issues.push(filename !== undefined
114
+ ? contentIssue(ref.path, labels, 'missing_media', 'issue.missingMedia', { filename })
115
+ : contentIssue(ref.path, labels, 'missing_media', 'issue.mediaNotFound'));
116
+ }
117
+ }
118
+ if (issues.length > 0) {
119
+ failures.push({ documentId: id, title, issues });
120
+ continue;
121
+ }
122
+ items.push({ documentId: id, revisionId: doc.head_rev, action: 'publish' });
123
+ docs.set(id, doc);
124
+ }
125
+ if (failures.length > 0) {
126
+ throw new InlayError('validation', 'error.publishFailed', { count: failures.length }, { documents: failures });
127
+ }
128
+ if (opts.dryRun)
129
+ return { eventId: null, items };
130
+ for (const item of items) {
131
+ await autoRedirect(tx, ctx, docs.get(item.documentId));
132
+ await trx
133
+ .updateTable('documents')
134
+ .set((eb) => ({
135
+ published_rev: eb.ref('head_rev'),
136
+ published_slug: eb.ref('head_slug'),
137
+ published_path: eb.ref('head_path'),
138
+ }))
139
+ .where('id', '=', item.documentId)
140
+ .execute();
141
+ await syncRefs(tx, item.documentId);
142
+ }
143
+ return { eventId: await recordEvent(tx, ctx, opts.message ?? null, items), items };
144
+ }, opts);
145
+ }
146
+ export async function unpublish(deps, documentIds, ctx, opts = {}) {
147
+ assertCan(ctx, 'content.publish');
148
+ const ids = [...new Set(documentIds)];
149
+ return runTransaction(deps, async (tx) => {
150
+ const trx = tx.db;
151
+ const items = [];
152
+ for (const id of ids) {
153
+ const doc = await trx
154
+ .selectFrom('documents')
155
+ .selectAll()
156
+ .where('id', '=', id)
157
+ .$call(whereVisible(deps.registry))
158
+ .executeTakeFirst();
159
+ if (!doc)
160
+ throw new InlayError('not_found', 'error.notFound', { name: id });
161
+ if (doc.kind !== 'entry')
162
+ throw new InlayError('invalid_operation', 'error.unpublishNotAllowed');
163
+ if (doc.published_rev === null)
164
+ continue;
165
+ items.push({ documentId: id, revisionId: null, action: 'unpublish' });
166
+ }
167
+ if (opts.dryRun)
168
+ return { eventId: null, items };
169
+ for (const item of items) {
170
+ await trx
171
+ .updateTable('documents')
172
+ .set({ published_rev: null, published_slug: null, published_path: null })
173
+ .where('id', '=', item.documentId)
174
+ .execute();
175
+ await syncRefs(tx, item.documentId);
176
+ }
177
+ return { eventId: await recordEvent(tx, ctx, null, items), items };
178
+ }, opts);
179
+ }
180
+ /** Non-deleted documents never published or changed since, newest head first. */
181
+ export async function listPendingChanges(deps) {
182
+ const rows = await summaryQuery(deps)
183
+ .where('documents.deleted_at', 'is', null)
184
+ .where((eb) => eb.or([eb('documents.published_rev', 'is', null), eb('documents.head_rev', '!=', eb.ref('documents.published_rev'))]))
185
+ .orderBy('documents.head_rev', 'desc')
186
+ .execute();
187
+ return rows.map((row) => toSummary(deps, row));
188
+ }
189
+ const MAX_CHANGE_LINES = 12;
190
+ /** What publishing each document would change, as readable lines (at most 12 each, plus a "more" line). */
191
+ export async function describeChanges(deps, documentIds) {
192
+ const ids = [...new Set(documentIds)];
193
+ const rows = ids.length === 0 ? [] : await summaryQuery(deps).where('documents.id', 'in', ids).execute();
194
+ const byId = new Map(rows.map((row) => [row.id, row]));
195
+ const out = [];
196
+ for (const id of ids) {
197
+ const row = byId.get(id);
198
+ if (!row)
199
+ throw new InlayError('not_found', 'error.notFound', { name: id });
200
+ const document = toSummary(deps, row);
201
+ const isNew = document.publishedRev === null;
202
+ const all = document.publishedRev === document.headRev
203
+ ? []
204
+ : formatDiff(await diffRevisions(deps, document.publishedRev, document.headRev));
205
+ const lines = all.slice(0, MAX_CHANGE_LINES);
206
+ if (all.length > MAX_CHANGE_LINES)
207
+ lines.push(t('changes.more', { count: all.length - MAX_CHANGE_LINES }));
208
+ out.push({ document, isNew, lines });
209
+ }
210
+ return out;
211
+ }
@@ -0,0 +1,99 @@
1
+ import { type Selectable, type SelectQueryBuilder } from 'kysely';
2
+ import type { Database, DocumentsTable, RevisionsTable } from '../db/schema.js';
3
+ import type { Registry } from '../registry/registry.js';
4
+ import type { CoreDeps, DocumentData, DocumentSummary, DocumentView, RevisionMeta } from '../types.js';
5
+ type DocumentRow = Selectable<DocumentsTable>;
6
+ type RevisionRow = Selectable<RevisionsTable>;
7
+ /** Stored revision JSON read against the current schema: defaults filled, unfit values absent, unknown keys carried. */
8
+ export declare function parseData(deps: CoreDeps, type: string, json: string): DocumentData;
9
+ /** Singleton/global → type label; entry → title field if non-blank, else slug, else "Untitled". */
10
+ export declare function documentTitle(deps: CoreDeps, doc: Pick<DocumentRow, 'kind' | 'type'>, data: DocumentData, slug: string | null): string;
11
+ export declare function revisionMeta(rev: RevisionRow): RevisionMeta;
12
+ /**
13
+ * Query modifier (for `$call`) keeping only visible documents: those whose
14
+ * type is in the site and whose locale is one of its locales. Documents of
15
+ * removed types or locales stay in the database but are hidden.
16
+ */
17
+ export declare function whereVisible(registry: Registry): <DB, TB extends keyof DB, O>(qb: SelectQueryBuilder<DB, TB, O>) => SelectQueryBuilder<DB, TB, O>;
18
+ /** Documents (hidden ones included) joined with their head revision's data and time. */
19
+ export declare function headQuery(deps: CoreDeps): SelectQueryBuilder<Database, "documents" | "revisions", {
20
+ created_at: string;
21
+ deleted_at: string | null;
22
+ edition: number | null;
23
+ group_id: string;
24
+ head_path: string | null;
25
+ head_rev: number | null;
26
+ head_slug: string | null;
27
+ id: string;
28
+ key: string | null;
29
+ kind: "entry" | "global" | "singleton";
30
+ locale: string;
31
+ published_path: string | null;
32
+ published_rev: number | null;
33
+ published_slug: string | null;
34
+ type: string;
35
+ } & {
36
+ head_created_at: string;
37
+ head_data: string;
38
+ }>;
39
+ /** Visible documents joined with their head revision's data and time. */
40
+ export declare function summaryQuery(deps: CoreDeps): SelectQueryBuilder<Database, "documents" | "revisions", {
41
+ created_at: string;
42
+ deleted_at: string | null;
43
+ edition: number | null;
44
+ group_id: string;
45
+ head_path: string | null;
46
+ head_rev: number | null;
47
+ head_slug: string | null;
48
+ id: string;
49
+ key: string | null;
50
+ kind: "entry" | "global" | "singleton";
51
+ locale: string;
52
+ published_path: string | null;
53
+ published_rev: number | null;
54
+ published_slug: string | null;
55
+ type: string;
56
+ } & {
57
+ head_created_at: string;
58
+ head_data: string;
59
+ }>;
60
+ type SummaryRow = DocumentRow & {
61
+ head_data: string;
62
+ head_created_at: string;
63
+ };
64
+ export declare function toSummary(deps: CoreDeps, row: SummaryRow): DocumentSummary;
65
+ /** Visible documents joined with their published revision's data and time (documents never published are left out). */
66
+ export declare function summaryBase(deps: CoreDeps): SelectQueryBuilder<Database, "documents" | "revisions", {
67
+ created_at: string;
68
+ deleted_at: string | null;
69
+ edition: number | null;
70
+ group_id: string;
71
+ head_path: string | null;
72
+ head_rev: number | null;
73
+ head_slug: string | null;
74
+ id: string;
75
+ key: string | null;
76
+ kind: "entry" | "global" | "singleton";
77
+ locale: string;
78
+ published_path: string | null;
79
+ published_rev: number | null;
80
+ published_slug: string | null;
81
+ type: string;
82
+ } & {
83
+ published_created_at: string;
84
+ published_data: string;
85
+ }>;
86
+ /** A summary of `doc` titled from the given revision JSON (its slug too, else the head's); `updatedAt` is that revision's time. */
87
+ export declare function summarizeRevision(deps: CoreDeps, doc: DocumentRow, json: string, updatedAt: string): DocumentSummary;
88
+ export declare function getDocument(deps: CoreDeps, id: string, opts?: {
89
+ state?: 'head' | 'published';
90
+ }): Promise<DocumentView | null>;
91
+ /** The document of a singleton or global in `locale` (default locale if omitted). */
92
+ export declare function findSingleton(deps: CoreDeps, type: string, locale?: string): Promise<DocumentSummary | null>;
93
+ export declare function findTranslation(deps: CoreDeps, groupId: string, locale: string): Promise<DocumentSummary | null>;
94
+ /** Entries of collection `type` in `locale` (default locale if omitted), newest head first. */
95
+ export declare function listEntries(deps: CoreDeps, type: string, opts?: {
96
+ locale?: string;
97
+ includeDeleted?: boolean;
98
+ }): Promise<DocumentSummary[]>;
99
+ export {};