@cossackframework/cms 0.0.0-stage → 0.9.1

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 (427) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -2
  3. package/agent-docs.json +259 -0
  4. package/app/README.md +78 -0
  5. package/app/cossack-recipe.json +43 -0
  6. package/app/src/auth-bot-check.ts +32 -0
  7. package/app/src/auth-bot-token.ts +11 -0
  8. package/app/src/auth-input.ts +35 -0
  9. package/app/src/auth-options.ts +18 -0
  10. package/app/src/auth-providers.ts +16 -0
  11. package/app/src/auth.ts +1082 -0
  12. package/app/src/brand.ts +68 -0
  13. package/app/src/cms/ai.ts +54 -0
  14. package/app/src/cms/analytics.ts +33 -0
  15. package/app/src/cms/block-errors.ts +55 -0
  16. package/app/src/cms/block-inserter.ts +111 -0
  17. package/app/src/cms/block-panel.ts +68 -0
  18. package/app/src/cms/block-rows.ts +44 -0
  19. package/app/src/cms/block-tree.ts +585 -0
  20. package/app/src/cms/blocks.css +708 -0
  21. package/app/src/cms/builder.ts +126 -0
  22. package/app/src/cms/cache.ts +44 -0
  23. package/app/src/cms/carousel.client.ts +52 -0
  24. package/app/src/cms/collab/presence.ts +69 -0
  25. package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
  26. package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
  27. package/app/src/cms/collab/room.ts +881 -0
  28. package/app/src/cms/compare.client.ts +47 -0
  29. package/app/src/cms/condition-control.ts +109 -0
  30. package/app/src/cms/content-api.ts +143 -0
  31. package/app/src/cms/content.ts +524 -0
  32. package/app/src/cms/countdown.client.ts +37 -0
  33. package/app/src/cms/editor-layout-editor.ts +260 -0
  34. package/app/src/cms/editor-layout-view.ts +37 -0
  35. package/app/src/cms/editor.ts +381 -0
  36. package/app/src/cms/entry.ts +26 -0
  37. package/app/src/cms/feeds.ts +145 -0
  38. package/app/src/cms/field-controls.ts +222 -0
  39. package/app/src/cms/field-group-editor.ts +105 -0
  40. package/app/src/cms/field-group-view.ts +211 -0
  41. package/app/src/cms/form-view.ts +203 -0
  42. package/app/src/cms/form.client.ts +203 -0
  43. package/app/src/cms/guards.ts +27 -0
  44. package/app/src/cms/handoff.ts +202 -0
  45. package/app/src/cms/headings.ts +51 -0
  46. package/app/src/cms/icons.ts +80 -0
  47. package/app/src/cms/import.client.ts +16 -0
  48. package/app/src/cms/index.ts +191 -0
  49. package/app/src/cms/lightbox.client.ts +109 -0
  50. package/app/src/cms/machine.ts +118 -0
  51. package/app/src/cms/maintenance.ts +97 -0
  52. package/app/src/cms/manage.ts +1236 -0
  53. package/app/src/cms/mcp-tools.ts +388 -0
  54. package/app/src/cms/mcp.ts +242 -0
  55. package/app/src/cms/media-chooser.ts +123 -0
  56. package/app/src/cms/media-usage.ts +57 -0
  57. package/app/src/cms/middleware.ts +199 -0
  58. package/app/src/cms/middlewares.ts +13 -0
  59. package/app/src/cms/network-ui.ts +36 -0
  60. package/app/src/cms/network-view.ts +38 -0
  61. package/app/src/cms/notes-announce.ts +65 -0
  62. package/app/src/cms/notes-rail.ts +207 -0
  63. package/app/src/cms/notification-rules.ts +66 -0
  64. package/app/src/cms/recovery.ts +82 -0
  65. package/app/src/cms/replace.ts +63 -0
  66. package/app/src/cms/reserved-paths.ts +19 -0
  67. package/app/src/cms/rich-text-field.ts +325 -0
  68. package/app/src/cms/rich-text-schema.ts +91 -0
  69. package/app/src/cms/rich-text.client.ts +255 -0
  70. package/app/src/cms/search.client.ts +116 -0
  71. package/app/src/cms/seo-head.ts +78 -0
  72. package/app/src/cms/seo.ts +241 -0
  73. package/app/src/cms/settings-draft.ts +218 -0
  74. package/app/src/cms/settings-file.ts +127 -0
  75. package/app/src/cms/settings-form.ts +180 -0
  76. package/app/src/cms/settings-languages.ts +125 -0
  77. package/app/src/cms/settings-nav.ts +102 -0
  78. package/app/src/cms/settings-network.ts +151 -0
  79. package/app/src/cms/settings-permalinks.ts +114 -0
  80. package/app/src/cms/settings-scroll.ts +10 -0
  81. package/app/src/cms/settings-search.ts +77 -0
  82. package/app/src/cms/settings-section.ts +38 -0
  83. package/app/src/cms/share.client.ts +27 -0
  84. package/app/src/cms/site-editing.ts +219 -0
  85. package/app/src/cms/site-editor.client.ts +1008 -0
  86. package/app/src/cms/site-editor.ts +99 -0
  87. package/app/src/cms/site-export.ts +60 -0
  88. package/app/src/cms/site-forms.ts +143 -0
  89. package/app/src/cms/site-import.ts +28 -0
  90. package/app/src/cms/site-session.ts +36 -0
  91. package/app/src/cms/site-taskbar.ts +77 -0
  92. package/app/src/cms/site-view.ts +1014 -0
  93. package/app/src/cms/site.ts +1322 -0
  94. package/app/src/cms/sitemaps.ts +131 -0
  95. package/app/src/cms/stat.client.ts +56 -0
  96. package/app/src/cms/style-controls.ts +252 -0
  97. package/app/src/cms/tabs.client.ts +36 -0
  98. package/app/src/cms/taskbar.ts +134 -0
  99. package/app/src/cms/term-icons.ts +10 -0
  100. package/app/src/cms/traffic.ts +26 -0
  101. package/app/src/cms/ui.ts +170 -0
  102. package/app/src/cms/updates.ts +124 -0
  103. package/app/src/cms/uploads.ts +26 -0
  104. package/app/src/cms/worker.ts +13 -0
  105. package/app/src/config/auth.ts +30 -0
  106. package/app/src/config/cms.ts +18 -0
  107. package/app/src/dashboard/access.ts +344 -0
  108. package/app/src/dashboard/agent-icons.ts +44 -0
  109. package/app/src/dashboard/app-passwords.ts +74 -0
  110. package/app/src/dashboard/avatar-field.ts +58 -0
  111. package/app/src/dashboard/bulk.ts +53 -0
  112. package/app/src/dashboard/head.ts +29 -0
  113. package/app/src/dashboard/icons.ts +15 -0
  114. package/app/src/dashboard/list-table.ts +120 -0
  115. package/app/src/dashboard/modules/roles.ts +15 -0
  116. package/app/src/dashboard/modules/sessions.ts +15 -0
  117. package/app/src/dashboard/modules/settings.ts +15 -0
  118. package/app/src/dashboard/modules/users.ts +18 -0
  119. package/app/src/dashboard/page.ts +67 -0
  120. package/app/src/dashboard/registry.ts +13 -0
  121. package/app/src/dashboard/session-list.ts +98 -0
  122. package/app/src/dashboard/tabs.ts +26 -0
  123. package/app/src/dashboard/time-ago.ts +16 -0
  124. package/app/src/dashboard/types.ts +40 -0
  125. package/app/src/dashboard/user-sections.ts +172 -0
  126. package/app/src/lib/permissions.ts +84 -0
  127. package/app/src/middlewares/auth.ts +117 -0
  128. package/app/src/pages/(site)/[...path]/index.ts +609 -0
  129. package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
  130. package/app/src/pages/(site)/feed/index.ts +12 -0
  131. package/app/src/pages/(site)/index.ts +11 -0
  132. package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
  133. package/app/src/pages/(site)/layout.ts +219 -0
  134. package/app/src/pages/(site)/llms.txt/index.ts +23 -0
  135. package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
  136. package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
  137. package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
  138. package/app/src/pages/(site)/robots.txt/index.ts +29 -0
  139. package/app/src/pages/(site)/search/index.ts +36 -0
  140. package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
  141. package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
  142. package/app/src/pages/api/auth/session.ts +48 -0
  143. package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
  144. package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
  145. package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
  146. package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
  147. package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
  148. package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
  149. package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
  150. package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
  151. package/app/src/pages/api/cms/cache/purge.ts +6 -0
  152. package/app/src/pages/api/cms/collections/index.ts +6 -0
  153. package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
  154. package/app/src/pages/api/cms/comments/[id].ts +9 -0
  155. package/app/src/pages/api/cms/comments/index.ts +126 -0
  156. package/app/src/pages/api/cms/comments/queue.ts +6 -0
  157. package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
  158. package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
  159. package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
  160. package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
  161. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
  162. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
  163. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
  164. package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
  165. package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
  166. package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
  167. package/app/src/pages/api/cms/export/[collection].ts +37 -0
  168. package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
  169. package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
  170. package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
  171. package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
  172. package/app/src/pages/api/cms/import/[collection].ts +23 -0
  173. package/app/src/pages/api/cms/mcp.ts +29 -0
  174. package/app/src/pages/api/cms/me/index.ts +6 -0
  175. package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
  176. package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
  177. package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
  178. package/app/src/pages/api/cms/media/[id].ts +6 -0
  179. package/app/src/pages/api/cms/media.ts +26 -0
  180. package/app/src/pages/api/cms/menus/[location].ts +14 -0
  181. package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
  182. package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
  183. package/app/src/pages/api/cms/network/sites/index.ts +14 -0
  184. package/app/src/pages/api/cms/notes/[id].ts +13 -0
  185. package/app/src/pages/api/cms/notes/index.ts +6 -0
  186. package/app/src/pages/api/cms/payments/webhook.ts +28 -0
  187. package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
  188. package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
  189. package/app/src/pages/api/cms/plugins/index.ts +6 -0
  190. package/app/src/pages/api/cms/recovery.ts +29 -0
  191. package/app/src/pages/api/cms/redirects/index.ts +9 -0
  192. package/app/src/pages/api/cms/roles/index.ts +6 -0
  193. package/app/src/pages/api/cms/schema/[collection].ts +13 -0
  194. package/app/src/pages/api/cms/search.ts +16 -0
  195. package/app/src/pages/api/cms/settings/[group].ts +9 -0
  196. package/app/src/pages/api/cms/settings/index.ts +9 -0
  197. package/app/src/pages/api/cms/site-export.ts +34 -0
  198. package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
  199. package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
  200. package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
  201. package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
  202. package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
  203. package/app/src/pages/api/cms/uploads/index.ts +26 -0
  204. package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
  205. package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
  206. package/app/src/pages/api/cms/users/index.ts +12 -0
  207. package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
  208. package/app/src/pages/api/cms/webhooks/index.ts +9 -0
  209. package/app/src/pages/auth/[provider]/callback.ts +11 -0
  210. package/app/src/pages/auth/[provider]/redirect.ts +9 -0
  211. package/app/src/pages/auth/forgot-password/index.ts +75 -0
  212. package/app/src/pages/auth/layout.ts +32 -0
  213. package/app/src/pages/auth/login/index.ts +198 -0
  214. package/app/src/pages/auth/magic/index.ts +68 -0
  215. package/app/src/pages/auth/register/index.ts +117 -0
  216. package/app/src/pages/auth/reset-password/index.ts +65 -0
  217. package/app/src/pages/auth/setup/index.ts +194 -0
  218. package/app/src/pages/auth/two-factor/index.ts +67 -0
  219. package/app/src/pages/auth/verify/index.ts +62 -0
  220. package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
  221. package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
  222. package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
  223. package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
  224. package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
  225. package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
  226. package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
  227. package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
  228. package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
  229. package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
  230. package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
  231. package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
  232. package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
  233. package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
  234. package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
  235. package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
  236. package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
  237. package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
  238. package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
  239. package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
  240. package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
  241. package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
  242. package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
  243. package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
  244. package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
  245. package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
  246. package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
  247. package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
  248. package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
  249. package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
  250. package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
  251. package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
  252. package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
  253. package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
  254. package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
  255. package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
  256. package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
  257. package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
  258. package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
  259. package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
  260. package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
  261. package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
  262. package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
  263. package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
  264. package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
  265. package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
  266. package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
  267. package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
  268. package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
  269. package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
  270. package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
  271. package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
  272. package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
  273. package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
  274. package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
  275. package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
  276. package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
  277. package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
  278. package/app/src/pages/dashboard/index.ts +214 -0
  279. package/app/src/pages/dashboard/layout.ts +320 -0
  280. package/app/src/pages/dashboard/profile/index.ts +211 -0
  281. package/app/src/pages/dashboard/profile/security/index.ts +255 -0
  282. package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
  283. package/app/src/pages/dashboard/roles/index.ts +134 -0
  284. package/app/src/pages/dashboard/roles/new/index.ts +95 -0
  285. package/app/src/pages/dashboard/sessions/index.ts +105 -0
  286. package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
  287. package/app/src/pages/dashboard/users/index.ts +299 -0
  288. package/app/src/pages/dashboard/users/new/index.ts +123 -0
  289. package/app/src/passkeys.client.ts +18 -0
  290. package/app/src/plugins/default-theme/assets/cover.svg +31 -0
  291. package/app/src/plugins/default-theme/assets/logo.svg +8 -0
  292. package/app/src/plugins/default-theme/parts/comments.ts +66 -0
  293. package/app/src/plugins/default-theme/parts/list.ts +38 -0
  294. package/app/src/plugins/default-theme/parts/media.ts +15 -0
  295. package/app/src/plugins/default-theme/parts/options.ts +45 -0
  296. package/app/src/plugins/default-theme/plugin.json +275 -0
  297. package/app/src/plugins/default-theme/templates/archive.ts +14 -0
  298. package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
  299. package/app/src/plugins/default-theme/templates/entry.ts +27 -0
  300. package/app/src/plugins/default-theme/templates/home.ts +8 -0
  301. package/app/src/plugins/default-theme/templates/layout.ts +40 -0
  302. package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
  303. package/app/src/plugins/default-theme/templates/search.ts +32 -0
  304. package/app/src/services/rbac.ts +65 -0
  305. package/app/src/services/roles.ts +89 -0
  306. package/app/src/services/users.ts +173 -0
  307. package/package.json +123 -3
  308. package/src/automations.ts +95 -0
  309. package/src/bindings.ts +138 -0
  310. package/src/block-references.ts +239 -0
  311. package/src/block-shape.ts +155 -0
  312. package/src/blocks.ts +1157 -0
  313. package/src/cache.ts +54 -0
  314. package/src/checks.ts +198 -0
  315. package/src/cloudflare-workers.d.ts +13 -0
  316. package/src/cloudflare.ts +61 -0
  317. package/src/collab.ts +372 -0
  318. package/src/collections.ts +421 -0
  319. package/src/comments.ts +46 -0
  320. package/src/cron.ts +95 -0
  321. package/src/dashboard-menu.ts +105 -0
  322. package/src/diff.ts +113 -0
  323. package/src/editor-layout.ts +316 -0
  324. package/src/errors.ts +50 -0
  325. package/src/field-groups.ts +498 -0
  326. package/src/fields.ts +411 -0
  327. package/src/form-builder.ts +1053 -0
  328. package/src/forms.ts +109 -0
  329. package/src/highlight.ts +134 -0
  330. package/src/hooks.ts +510 -0
  331. package/src/icon-catalog.ts +55 -0
  332. package/src/icons.ts +128 -0
  333. package/src/images.ts +149 -0
  334. package/src/index.ts +100 -0
  335. package/src/isolate-core.ts +245 -0
  336. package/src/isolate.ts +19 -0
  337. package/src/isolation.ts +69 -0
  338. package/src/mail.ts +182 -0
  339. package/src/manifest.ts +476 -0
  340. package/src/media.ts +193 -0
  341. package/src/menus.ts +287 -0
  342. package/src/module.ts +32 -0
  343. package/src/modules/content.ts +64 -0
  344. package/src/modules/forms.ts +35 -0
  345. package/src/node.ts +66 -0
  346. package/src/notes.ts +237 -0
  347. package/src/permissions.ts +139 -0
  348. package/src/plugin-settings.ts +114 -0
  349. package/src/records.ts +56 -0
  350. package/src/redirects.ts +59 -0
  351. package/src/resource.ts +245 -0
  352. package/src/richtext.ts +402 -0
  353. package/src/schema-json.ts +112 -0
  354. package/src/search.ts +89 -0
  355. package/src/seo.ts +477 -0
  356. package/src/server/accounts.ts +418 -0
  357. package/src/server/ai.ts +33 -0
  358. package/src/server/api-tokens.ts +91 -0
  359. package/src/server/areas.ts +116 -0
  360. package/src/server/audit.ts +94 -0
  361. package/src/server/auth.ts +89 -0
  362. package/src/server/automations.ts +190 -0
  363. package/src/server/autosaves.ts +69 -0
  364. package/src/server/brand-icons.ts +50 -0
  365. package/src/server/brands.ts +86 -0
  366. package/src/server/budget.ts +97 -0
  367. package/src/server/cache.ts +104 -0
  368. package/src/server/capabilities.ts +333 -0
  369. package/src/server/cloudflare.ts +92 -0
  370. package/src/server/comments.ts +237 -0
  371. package/src/server/drafts.ts +176 -0
  372. package/src/server/field-groups.ts +88 -0
  373. package/src/server/files.ts +780 -0
  374. package/src/server/forms.ts +726 -0
  375. package/src/server/handoffs.ts +107 -0
  376. package/src/server/host-schema.ts +312 -0
  377. package/src/server/host.ts +2892 -0
  378. package/src/server/images.ts +34 -0
  379. package/src/server/index.ts +59 -0
  380. package/src/server/indexnow.ts +91 -0
  381. package/src/server/isolation.ts +183 -0
  382. package/src/server/locked.ts +45 -0
  383. package/src/server/mail.ts +93 -0
  384. package/src/server/markdown.ts +24 -0
  385. package/src/server/menus.ts +286 -0
  386. package/src/server/network-policy.ts +60 -0
  387. package/src/server/network.ts +665 -0
  388. package/src/server/notes.ts +275 -0
  389. package/src/server/outbox.ts +213 -0
  390. package/src/server/path-moves.ts +33 -0
  391. package/src/server/payments.ts +59 -0
  392. package/src/server/previews.ts +62 -0
  393. package/src/server/purge.ts +140 -0
  394. package/src/server/reconcile.ts +38 -0
  395. package/src/server/redirects.ts +183 -0
  396. package/src/server/repository.ts +1107 -0
  397. package/src/server/schedules.ts +105 -0
  398. package/src/server/schema.ts +562 -0
  399. package/src/server/security.ts +391 -0
  400. package/src/server/seed.ts +52 -0
  401. package/src/server/shared-fields.ts +34 -0
  402. package/src/server/site-export.ts +151 -0
  403. package/src/server/site-import.ts +482 -0
  404. package/src/server/site-search.ts +289 -0
  405. package/src/server/site-settings.ts +286 -0
  406. package/src/server/sites.ts +243 -0
  407. package/src/server/stores.ts +314 -0
  408. package/src/server/stripe.ts +173 -0
  409. package/src/server/taxonomies.ts +415 -0
  410. package/src/server/tokens.ts +25 -0
  411. package/src/server/traffic.ts +118 -0
  412. package/src/server/users.ts +653 -0
  413. package/src/server/webhooks.ts +245 -0
  414. package/src/settings-controls.ts +54 -0
  415. package/src/settings-document.ts +111 -0
  416. package/src/settings.ts +426 -0
  417. package/src/storage/cloudflare.ts +94 -0
  418. package/src/storage/index.ts +30 -0
  419. package/src/storage/node.ts +114 -0
  420. package/src/taxonomy.ts +51 -0
  421. package/src/theme.ts +1135 -0
  422. package/src/to-markdown.ts +179 -0
  423. package/src/updates.ts +126 -0
  424. package/src/version.ts +2 -0
  425. package/src/vite.d.ts +25 -0
  426. package/src/vite.js +199 -0
  427. package/src/webhooks.ts +107 -0
package/src/fields.ts ADDED
@@ -0,0 +1,411 @@
1
+ import { richTextProblem } from './richtext';
2
+ import { ICON_NAME_SET } from './icons';
3
+
4
+ /**
5
+ * Field kinds of a resource declaration. Each kind maps to one RomeDB field type and
6
+ * CHECK, validates write input, and maps stored values to a JSON-safe public value.
7
+ */
8
+
9
+ export type FieldKind =
10
+ | 'string' | 'text' | 'enum' | 'integer' | 'bigint' | 'number' | 'boolean'
11
+ | 'datetime' | 'reference' | 'json' | 'vector' | 'blocks' | 'richtext' | 'rows';
12
+
13
+ /** Kinds `field.list()` builds a multiple field of. */
14
+ export type ListItemKind = 'string' | 'integer' | 'number';
15
+
16
+ /** Kinds a field can hold several values of, as an array of the kind's values. */
17
+ export const MULTIPLE_KINDS: ReadonlySet<FieldKind> = new Set<FieldKind>(['string', 'text', 'enum', 'integer', 'number', 'datetime', 'reference', 'json', 'richtext']);
18
+ /** Items a multiple field holds at most, by default; media and references hold fewer. */
19
+ export const ITEM_LIMITS = Object.freeze({ max: 1000, media: 200 });
20
+
21
+ export interface FieldDeclaration {
22
+ readonly kind: FieldKind;
23
+ /** Must be present on create. A required field cannot be added to existing records without a backfill step. */
24
+ readonly required?: boolean;
25
+ /** A present field may hold null. */
26
+ readonly nullable?: boolean;
27
+ /** Constant default for new records; a multiple field's is a list of values. */
28
+ readonly default?: string | number | boolean | null | readonly (string | number | boolean)[];
29
+ readonly label?: string;
30
+ readonly description?: string;
31
+ /** string/text: maximum length in characters; rows: the most rows. On a multiple field, the rule of every item. */
32
+ readonly max?: number;
33
+ /** string/text: minimum length; integer/number: minimum value; rows: the fewest rows. On a multiple field, the rule of every item. */
34
+ readonly min?: number;
35
+ /**
36
+ * The field holds several values of its kind, stored as an array, each checked with the
37
+ * kind's rules: a multiple string with `max: 80` holds strings of at most 80 characters.
38
+ * Required means at least one item. Not for booleans, blocks, rows, vectors or big integers.
39
+ */
40
+ readonly multiple?: boolean;
41
+ /** multiple: the fewest items. */
42
+ readonly minItems?: number;
43
+ /** multiple: the most items; 1000 by default, 200 for media and references. */
44
+ readonly maxItems?: number;
45
+ /** multiple: the editor's Add button text; "Add new" by default. */
46
+ readonly addLabel?: string;
47
+ /** enum: allowed values. */
48
+ readonly values?: readonly string[];
49
+ /** enum: labels for values, by value. */
50
+ readonly choices?: { readonly [value: string]: string };
51
+ /** string: regular expression checked on write by the host. */
52
+ readonly pattern?: string;
53
+ /** reference: target resource ID (`owner/name`). */
54
+ readonly target?: string;
55
+ /** vector: dimensions. */
56
+ readonly dimensions?: number;
57
+ /** Include in the resource's full-text index. */
58
+ readonly search?: boolean;
59
+ /** Enforce uniqueness with a unique index. */
60
+ readonly unique?: boolean;
61
+ /** With `unique`: unique among records with the same values of these fields, such as a slug per `locale`. */
62
+ readonly uniqueBy?: readonly string[];
63
+ /**
64
+ * Content collections: `false` keeps one value for an entry and its translations, such as a
65
+ * price or an SKU. Saving any of them copies the value to the others. Text, rich text, blocks,
66
+ * rows, slugs and unique fields are always translated.
67
+ */
68
+ readonly translatable?: boolean;
69
+ /** Create a scalar index. */
70
+ readonly index?: boolean;
71
+ /** Field-level access: permissions needed to read or write the field. */
72
+ readonly access?: { readonly read?: string; readonly write?: string };
73
+ /** string: derive a URL slug from this field when the value is empty. Unique slugs get `-2`, `-3`, … */
74
+ readonly slugFrom?: string;
75
+ /** multiple string: IDs of terms in this taxonomy, checked on write. */
76
+ readonly taxonomy?: string;
77
+ /** string: the ID of a ready media file, checked on write; several when multiple. */
78
+ readonly media?: boolean;
79
+ /** media: the kinds of file the chooser lists first, such as `['image']`; images when omitted. Every kind stays a click away. */
80
+ readonly kinds?: readonly FieldMediaKind[];
81
+ /** string: the editor offers a choice of the site's forms (the value is a slug), collections (a name) or terms (an ID). */
82
+ readonly choicesFrom?: ChoiceSource;
83
+ /** string: the name of an icon of the catalog (`ICON_CATEGORIES`), chosen with the icon picker and checked on write. */
84
+ readonly icon?: boolean;
85
+ /** string: the URL of a profile on a social network; the host adds the network's icon to the rendered block's `icons`, by URL. */
86
+ readonly brand?: boolean;
87
+ /** blocks, richtext: the block types allowed; all when omitted. */
88
+ readonly blocks?: readonly string[];
89
+ /** blocks: the field holds a form, so input blocks and conditions are allowed in it. */
90
+ readonly form?: boolean;
91
+ /** Where the dashboard editor shows the field. Default: by kind. */
92
+ readonly placement?: 'main' | 'sidebar';
93
+ /** text: how the dashboard edits and the site renders the value. */
94
+ /** text: `markdown` for a short passage with formatting, `code` for source edited in a code editor. */
95
+ readonly format?: 'plain' | 'markdown' | 'code';
96
+ /** text with format code: the code editor's language, such as `html`; a block's own `language` field wins. */
97
+ readonly language?: string;
98
+ /** json: a group of declared subfields; the value is an object of them, each optional. rows: the fields of each row. */
99
+ readonly fields?: { readonly [name: string]: FieldDeclaration };
100
+ }
101
+
102
+
103
+ /** A row's identity: 1-40 letters, digits, `_` or `-`, distinct within its list. */
104
+ export const ROW_ID = /^[A-Za-z0-9_-]{1,40}$/;
105
+ /** Rows a field holds at most, by default and at the limit. */
106
+ export const ROW_LIMITS = Object.freeze({ default: 200, max: 1000, depth: 8 });
107
+
108
+ type Options = Omit<FieldDeclaration, 'kind'>;
109
+
110
+ /** Field builders. Every option is data, so declarations serialize into plugin manifests. */
111
+ export const field = {
112
+ string: (options: Options = {}): FieldDeclaration => ({ kind: 'string', max: 255, ...options }),
113
+ text: (options: Options = {}): FieldDeclaration => ({ kind: 'text', max: 100_000, ...options }),
114
+ enum: (values: readonly string[], options: Options = {}): FieldDeclaration => ({ kind: 'enum', values: [...values], ...options }),
115
+ integer: (options: Options = {}): FieldDeclaration => ({ kind: 'integer', ...options }),
116
+ bigint: (options: Omit<Options, 'default' | 'min' | 'max'> = {}): FieldDeclaration => ({ kind: 'bigint', ...options }),
117
+ number: (options: Options = {}): FieldDeclaration => ({ kind: 'number', ...options }),
118
+ boolean: (options: Options = {}): FieldDeclaration => ({ kind: 'boolean', ...options }),
119
+ /** Unix milliseconds. */
120
+ datetime: (options: Options = {}): FieldDeclaration => ({ kind: 'datetime', ...options }),
121
+ reference: (target: string, options: Options = {}): FieldDeclaration => ({ kind: 'reference', target, ...options }),
122
+ /** A JSON object. Values must be plain JSON. */
123
+ json: (options: Omit<Options, 'default'> = {}): FieldDeclaration => ({ kind: 'json', ...options }),
124
+ /** A multiple field of a scalar kind: an array of strings, integers or numbers. */
125
+ list: (items: ListItemKind, options: Options = {}): FieldDeclaration => ({ kind: items, multiple: true, ...options }),
126
+ vector: (dimensions: number, options: Omit<Options, 'default'> = {}): FieldDeclaration => ({ kind: 'vector', dimensions, ...options }),
127
+ /** A unique URL slug derived from another field when left empty. */
128
+ slug: (from: string, options: Options = {}): FieldDeclaration => ({ kind: 'string', max: 200, pattern: SLUG_PATTERN, unique: true, slugFrom: from, ...options }),
129
+ /** Term IDs of a taxonomy, such as `categories`. Indexed, so records can be listed by term. */
130
+ terms: (taxonomy: string, options: Omit<Options, 'default'> = {}): FieldDeclaration => ({ kind: 'string', multiple: true, taxonomy, index: true, ...options }),
131
+ /** A media file ID; with `multiple`, several. */
132
+ media: (options: Options = {}): FieldDeclaration => ({ kind: 'string', max: 80, media: true, nullable: true, ...options }),
133
+ /** An icon of the catalog by name, drawn in the site's icon style. */
134
+ icon: (options: Options = {}): FieldDeclaration => ({ kind: 'string', max: 60, pattern: '(?:[a-z0-9]+(?:-[a-z0-9]+)*)?', icon: true, ...options }),
135
+ /** Several media file IDs. */
136
+ gallery: (options: Options = {}): FieldDeclaration => ({ kind: 'string', max: 80, media: true, multiple: true, ...options }),
137
+ /** An ordered list of content blocks, optionally limited to some block types. */
138
+ blocks: (options: Omit<Options, 'default'> = {}): FieldDeclaration => ({ kind: 'blocks', ...options }),
139
+ /** A rich text document (ProseMirror JSON) edited in the WYSIWYG editor; `blocks` limits the blocks it can embed. */
140
+ richText: (options: Omit<Options, 'default'> = {}): FieldDeclaration => ({ kind: 'richtext', ...options }),
141
+ /**
142
+ * An object of declared subfields, such as an entry's SEO settings. Subfields are scalars,
143
+ * media or multiple ones of those; each is optional and validated like a field.
144
+ */
145
+ group: (fields: { readonly [name: string]: FieldDeclaration }, options: Omit<Options, 'default' | 'fields'> = {}): FieldDeclaration => ({ kind: 'json', fields, nullable: true, ...options }),
146
+ /**
147
+ * A list of rows, each an object of the declared fields with an `_id`, as a repeater: at
148
+ * most `max` rows. Rows nest when a field is itself rows.
149
+ */
150
+ rows: (fields: { readonly [name: string]: FieldDeclaration }, options: Omit<Options, 'default' | 'fields'> = {}): FieldDeclaration => ({ kind: 'rows', fields, ...options }),
151
+ };
152
+
153
+ /** Kinds a group's subfields can have. */
154
+ const GROUP_KINDS = new Set<FieldKind>(['string', 'text', 'enum', 'integer', 'number', 'boolean', 'datetime']);
155
+ /** Kinds a row's fields can have: anything a value in a document can be, but the big or special ones. */
156
+ const ROW_KINDS = new Set<FieldKind>(['string', 'text', 'enum', 'integer', 'number', 'boolean', 'datetime', 'reference', 'json', 'rows']);
157
+
158
+ /** Lowercase letters and digits separated by single hyphens. */
159
+ export const SLUG_PATTERN = '[a-z0-9]+(?:-[a-z0-9]+)*';
160
+
161
+ /**
162
+ * A URL slug: accents removed, lowercase ASCII letters and digits joined by single
163
+ * hyphens, at most `max` characters. Empty when the text has no such characters.
164
+ */
165
+ export function slugify(text: string, max = 200): string {
166
+ const ascii = String(text ?? '').normalize('NFKD').replace(/[\u0300-\u036f]/g, '').replace(/[đĐ]/g, 'd').replace(/ß/g, 'ss').replace(/[æÆ]/g, 'ae').replace(/[øØ]/g, 'o');
167
+ const slug = ascii.toLowerCase().replace(/['’]/g, '').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
168
+ return slug.length <= max ? slug : slug.slice(0, max).replace(/-+[^-]*$/, '') || slug.slice(0, max);
169
+ }
170
+
171
+ export const FIELD_NAME = /^[a-z][a-zA-Z0-9]{0,62}$/;
172
+ export const TAXONOMY_NAME = /^[a-z][a-zA-Z0-9]{0,40}$/;
173
+ /** The kinds of media file a field may ask for, as the library filters them. */
174
+ export const FIELD_MEDIA_KINDS = Object.freeze(['image', 'video', 'audio', 'document', 'archive'] as const);
175
+ export type FieldMediaKind = typeof FIELD_MEDIA_KINDS[number];
176
+ /** What a string field's choice can come from. */
177
+ export const CHOICE_SOURCES = Object.freeze(['forms', 'collections', 'terms', 'locations', 'authors', 'roles'] as const);
178
+ export type ChoiceSource = typeof CHOICE_SOURCES[number];
179
+ const ENUM_VALUE = /^[A-Za-z0-9_.-]{1,64}$/;
180
+ const MAX_SAFE = Number.MAX_SAFE_INTEGER;
181
+
182
+ /** Check a declaration's own consistency. Returns problems; empty when valid. */
183
+ export function fieldProblems(name: string, declaration: FieldDeclaration, depth = 0): string[] {
184
+ const problems: string[] = [];
185
+ const at = `field ${name}`;
186
+ if (!FIELD_NAME.test(name)) problems.push(`${at}: names start with a lowercase letter and use letters and digits only.`);
187
+ const kinds: FieldKind[] = ['string', 'text', 'enum', 'integer', 'bigint', 'number', 'boolean', 'datetime', 'reference', 'json', 'vector', 'blocks', 'richtext', 'rows'];
188
+ if (!kinds.includes(declaration.kind)) return [...problems, `${at}: unknown kind ${String(declaration.kind)}.`];
189
+ const { kind } = declaration;
190
+ const multiple = declaration.multiple === true;
191
+ if (declaration.multiple !== undefined && (typeof declaration.multiple !== 'boolean' || (multiple && !MULTIPLE_KINDS.has(kind)))) problems.push(`${at}: multiple is true or false and applies to strings, text, choices, numbers, times, references, JSON and rich text.`);
192
+ const mostItems = declaration.media || kind === 'reference' ? ITEM_LIMITS.media : ITEM_LIMITS.max;
193
+ if (declaration.maxItems !== undefined && (!multiple || !Number.isSafeInteger(declaration.maxItems) || declaration.maxItems < 1 || declaration.maxItems > mostItems)) problems.push(`${at}: maxItems applies to multiple fields and is 1-${mostItems}.`);
194
+ if (declaration.minItems !== undefined && (!multiple || !Number.isSafeInteger(declaration.minItems) || declaration.minItems < 0 || declaration.minItems > (declaration.maxItems ?? mostItems))) problems.push(`${at}: minItems applies to multiple fields and is 0 to maxItems.`);
195
+ if (declaration.addLabel !== undefined && (!multiple || typeof declaration.addLabel !== 'string' || declaration.addLabel.length > 60)) problems.push(`${at}: addLabel applies to multiple fields and is at most 60 characters.`);
196
+ if (declaration.max !== undefined) {
197
+ if (kind === 'number') {
198
+ if (!Number.isFinite(declaration.max)) problems.push(`${at}: max must be a finite number.`);
199
+ } else if (kind === 'integer' || kind === 'datetime') {
200
+ if (!Number.isSafeInteger(declaration.max)) problems.push(`${at}: max must be a safe integer.`);
201
+ } else if (!Number.isSafeInteger(declaration.max) || declaration.max < 1) problems.push(`${at}: max must be a positive integer.`);
202
+ }
203
+ if (declaration.min !== undefined && !Number.isFinite(declaration.min)) problems.push(`${at}: min must be a finite number.`);
204
+ if (kind === 'enum') {
205
+ if (!declaration.values?.length || declaration.values.some(value => !ENUM_VALUE.test(value)) || new Set(declaration.values).size !== declaration.values.length) {
206
+ problems.push(`${at}: enum values must be 1-64 distinct letters, digits, dots, hyphens or underscores.`);
207
+ }
208
+ }
209
+ if (kind === 'reference' && (typeof declaration.target !== 'string' || !/^[a-z][a-z0-9-]*\/[a-z][a-z0-9_]*$/.test(declaration.target))) problems.push(`${at}: reference target must be a resource ID such as cms/posts.`);
210
+ if (kind === 'vector' && (!Number.isInteger(declaration.dimensions) || declaration.dimensions! < 1 || declaration.dimensions! > 4096)) problems.push(`${at}: vector dimensions must be 1..4096.`);
211
+ if (declaration.pattern !== undefined) {
212
+ if (kind !== 'string') problems.push(`${at}: pattern applies to string fields only.`);
213
+ else try { new RegExp(declaration.pattern, 'u'); } catch { problems.push(`${at}: pattern is not a valid regular expression.`); }
214
+ }
215
+ // Rows are searched through their fields' own `search` flags.
216
+ if (declaration.search && !['string', 'text', 'richtext', 'blocks'].includes(kind)) problems.push(`${at}: only string, text, rich text and blocks fields can be searched.`);
217
+ if (declaration.unique && ['json', 'vector', 'text', 'blocks', 'richtext', 'rows'].includes(kind)) problems.push(`${at}: ${kind} fields cannot be indexed.`);
218
+ else if (declaration.unique && multiple) problems.push(`${at}: multiple fields cannot be unique.`);
219
+ if (declaration.translatable !== undefined && (typeof declaration.translatable !== 'boolean' || (declaration.translatable === false
220
+ && (['text', 'richtext', 'blocks', 'rows', 'vector'].includes(kind) || declaration.slugFrom !== undefined || declaration.unique || (multiple && declaration.search))))) {
221
+ problems.push(`${at}: translatable is true or false; text, rich text, blocks, rows, vectors, slugs and unique fields are always translated.`);
222
+ }
223
+ if (declaration.uniqueBy !== undefined && (!declaration.unique || !Array.isArray(declaration.uniqueBy) || !declaration.uniqueBy.length || declaration.uniqueBy.length > 3 || declaration.uniqueBy.some(other => typeof other !== 'string' || other === name))) problems.push(`${at}: uniqueBy names 1-3 other fields and applies to unique fields.`);
224
+ // A multiple field of a scalar kind has an array index on its path; the big kinds cannot be indexed.
225
+ if (declaration.index && ['json', 'vector', 'text', 'blocks', 'richtext', 'rows'].includes(kind)) problems.push(`${at}: ${kind} fields cannot be indexed.`);
226
+ if (declaration.blocks !== undefined && ((kind !== 'blocks' && kind !== 'richtext') || !Array.isArray(declaration.blocks) || declaration.blocks.some(name => typeof name !== 'string' || !/^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/.test(name)))) problems.push(`${at}: blocks lists block type names and applies to blocks and rich text fields.`);
227
+ if (declaration.form !== undefined && (kind !== 'blocks' || typeof declaration.form !== 'boolean')) problems.push(`${at}: form applies to blocks fields and is true or false.`);
228
+ if (declaration.placement !== undefined && !['main', 'sidebar'].includes(declaration.placement)) problems.push(`${at}: placement is main or sidebar.`);
229
+ if (declaration.slugFrom !== undefined && (kind !== 'string' || multiple || typeof declaration.slugFrom !== 'string' || !FIELD_NAME.test(declaration.slugFrom))) problems.push(`${at}: slugFrom applies to single string fields and names another field.`);
230
+ if (declaration.taxonomy !== undefined && (kind !== 'string' || !multiple || !TAXONOMY_NAME.test(declaration.taxonomy))) problems.push(`${at}: taxonomy applies to multiple string fields and names a taxonomy.`);
231
+ if (declaration.media !== undefined && (kind !== 'string' || typeof declaration.media !== 'boolean')) problems.push(`${at}: media applies to string fields.`);
232
+ if (declaration.kinds !== undefined && (!declaration.media || !Array.isArray(declaration.kinds) || !declaration.kinds.length || declaration.kinds.some(entry => !(FIELD_MEDIA_KINDS as readonly string[]).includes(entry)))) problems.push(`${at}: kinds applies to media fields and lists ${FIELD_MEDIA_KINDS.join(', ')}.`);
233
+ if (declaration.choicesFrom !== undefined && (kind !== 'string' || declaration.media || !(CHOICE_SOURCES as readonly string[]).includes(declaration.choicesFrom))) problems.push(`${at}: choicesFrom applies to string fields and is ${CHOICE_SOURCES.join(', ')}.`);
234
+ if (declaration.icon !== undefined && (kind !== 'string' || typeof declaration.icon !== 'boolean' || declaration.media)) problems.push(`${at}: icon applies to string fields.`);
235
+ if (declaration.brand !== undefined && (kind !== 'string' || typeof declaration.brand !== 'boolean' || declaration.media)) problems.push(`${at}: brand applies to string fields.`);
236
+ if (declaration.format !== undefined && (kind !== 'text' || !['plain', 'markdown', 'code'].includes(declaration.format))) problems.push(`${at}: format applies to text fields and is plain, markdown or code.`);
237
+ if (declaration.language !== undefined && (declaration.format !== 'code' || typeof declaration.language !== 'string' || !/^[a-z0-9+#-]{1,40}$/.test(declaration.language))) problems.push(`${at}: language applies to code fields and names a language, such as html.`);
238
+ if (kind === 'rows') {
239
+ const entries = declaration.fields && typeof declaration.fields === 'object' ? Object.entries(declaration.fields) : [];
240
+ if (!entries.length || entries.length > 48) problems.push(`${at}: rows hold 1-48 fields.`);
241
+ if (depth >= ROW_LIMITS.depth) problems.push(`${at}: rows nest at most ${ROW_LIMITS.depth} levels.`);
242
+ if (declaration.max !== undefined && declaration.max > ROW_LIMITS.max) problems.push(`${at}: rows hold at most ${ROW_LIMITS.max} rows.`);
243
+ if (declaration.min !== undefined && (!Number.isSafeInteger(declaration.min) || declaration.min < 0)) problems.push(`${at}: min rows must be a whole number.`);
244
+ for (const [sub, nested] of entries) {
245
+ if (!nested || !ROW_KINDS.has(nested.kind)) { problems.push(`${at}.${sub}: row fields cannot be blocks, rich text, vectors or big integers.`); continue; }
246
+ // An index on a row field is an array index on its path; uniqueness is within the entry.
247
+ if (nested.slugFrom) problems.push(`${at}.${sub}: row fields cannot be derived.`);
248
+ problems.push(...fieldProblems(sub, nested, depth + 1).map(problem => problem.replace(/^field /, `${at}.`)));
249
+ }
250
+ } else if (declaration.fields !== undefined) {
251
+ const entries = declaration.fields && typeof declaration.fields === 'object' ? Object.entries(declaration.fields) : [];
252
+ if (kind !== 'json' || !entries.length || entries.length > 16) problems.push(`${at}: fields groups 1-16 subfields in a json field.`);
253
+ for (const [sub, nested] of entries) {
254
+ if (!nested || !GROUP_KINDS.has(nested.kind)) { problems.push(`${at}.${sub}: subfields are strings, text, choices, numbers, booleans or times, single or multiple.`); continue; }
255
+ if (nested.unique || nested.index || nested.search || nested.slugFrom || nested.taxonomy || nested.required || nested.fields) problems.push(`${at}.${sub}: subfields cannot be required, indexed, searched or derived.`);
256
+ problems.push(...fieldProblems(sub, nested).map(problem => problem.replace(/^field /, `${at}.`)));
257
+ }
258
+ }
259
+ if (declaration.default !== undefined) {
260
+ const error = validateValue(name, declaration, declaration.default);
261
+ if (error) problems.push(`${at}: default ${error}`);
262
+ }
263
+ for (const key of ['read', 'write'] as const) {
264
+ const permission = declaration.access?.[key];
265
+ if (permission !== undefined && !/^[a-z][a-z0-9:._*-]{0,127}$/.test(permission)) problems.push(`${at}: access.${key} must be a permission name.`);
266
+ }
267
+ return problems;
268
+ }
269
+
270
+ /** RomeDB field type for a declaration: a multiple field is an array of its kind's type. */
271
+ export function storageType(declaration: FieldDeclaration, references: (target: string) => string): string {
272
+ if (declaration.multiple) return `array<${storageType({ ...declaration, multiple: false }, references)}>`;
273
+ switch (declaration.kind) {
274
+ case 'string': case 'text': case 'enum': return 'string';
275
+ case 'integer': case 'bigint': case 'datetime': return 'integer';
276
+ case 'number': return 'number';
277
+ case 'boolean': return 'boolean';
278
+ case 'reference': return `record<${references(declaration.target!)}>`;
279
+ case 'json': return 'object';
280
+ case 'vector': return `vector<${declaration.dimensions}>`;
281
+ case 'blocks': case 'rows': return 'array<object>';
282
+ case 'richtext': return 'object';
283
+ }
284
+ }
285
+
286
+ /** Deterministic CHECK expression, or undefined. Strings are validated, never interpolated raw. */
287
+ export function storageCheck(name: string, declaration: FieldDeclaration): string | undefined {
288
+ const checks: string[] = [];
289
+ // The host checks a multiple field's items.
290
+ if (declaration.multiple) return undefined;
291
+ if ((declaration.kind === 'string' || declaration.kind === 'text') && declaration.max !== undefined) checks.push(`length(${name}) <= ${declaration.max}`);
292
+ if ((declaration.kind === 'string' || declaration.kind === 'text') && declaration.min !== undefined) checks.push(`length(${name}) >= ${Math.trunc(declaration.min)}`);
293
+ if (declaration.kind === 'enum') checks.push(`${name} IN (${declaration.values!.map(value => `'${value}'`).join(', ')})`);
294
+ if ((declaration.kind === 'integer' || declaration.kind === 'datetime')) checks.push(`${name} >= ${declaration.min ?? -MAX_SAFE} AND ${name} <= ${declaration.max ?? MAX_SAFE}`);
295
+ if (declaration.kind === 'number' && declaration.min !== undefined) checks.push(`${name} >= ${declaration.min}`);
296
+ if (declaration.kind === 'number' && declaration.max !== undefined) checks.push(`${name} <= ${declaration.max}`);
297
+ return checks.length ? checks.join(' AND ') : undefined;
298
+ }
299
+
300
+ /** Validate one input value. Returns an error message, or undefined when valid. */
301
+ export function validateValue(name: string, declaration: FieldDeclaration, value: unknown): string | undefined {
302
+ if (value === null) return declaration.nullable ? undefined : 'cannot be null.';
303
+ if (declaration.multiple) {
304
+ const most = declaration.maxItems ?? (declaration.media || declaration.kind === 'reference' ? ITEM_LIMITS.media : ITEM_LIMITS.max);
305
+ const fewest = declaration.minItems ?? (declaration.required ? 1 : 0);
306
+ if (!Array.isArray(value) || value.length > most) return `must be a list of at most ${most} ${most === 1 ? 'item' : 'items'}.`;
307
+ if (value.length < fewest) return `needs at least ${fewest} ${fewest === 1 ? 'item' : 'items'}.`;
308
+ const item: FieldDeclaration = { ...declaration, multiple: false, required: false, nullable: false, minItems: undefined, maxItems: undefined, default: undefined };
309
+ for (const [index, entry] of value.entries()) {
310
+ const error = validateValue(name, item, entry);
311
+ if (error) return `item ${index + 1} ${error}`;
312
+ }
313
+ return undefined;
314
+ }
315
+ switch (declaration.kind) {
316
+ case 'string': case 'text': {
317
+ if (typeof value !== 'string') return 'must be text.';
318
+ // Blank text does not fill a required field.
319
+ if (declaration.required && !value.trim()) return 'is required.';
320
+ if (/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(value)) return 'must be well-formed text.';
321
+ const length = [...value].length;
322
+ if (declaration.max !== undefined && length > declaration.max) return `must be at most ${declaration.max} characters.`;
323
+ if (declaration.min !== undefined && length < declaration.min) return `must be at least ${declaration.min} characters.`;
324
+ if (declaration.pattern !== undefined && !new RegExp(`^(?:${declaration.pattern})$`, 'u').test(value)) return 'has an invalid format.';
325
+ if (declaration.icon && value && !ICON_NAME_SET.has(value)) return 'is not a known icon.';
326
+ return undefined;
327
+ }
328
+ case 'enum': return typeof value === 'string' && declaration.values!.includes(value) ? undefined : `must be one of ${declaration.values!.join(', ')}.`;
329
+ case 'integer': case 'datetime': {
330
+ if (typeof value !== 'number' || !Number.isSafeInteger(value)) return 'must be a safe integer.';
331
+ if (declaration.min !== undefined && value < declaration.min) return `must be at least ${declaration.min}.`;
332
+ if (declaration.max !== undefined && value > declaration.max) return `must be at most ${declaration.max}.`;
333
+ return undefined;
334
+ }
335
+ case 'bigint': {
336
+ const text = typeof value === 'bigint' ? value.toString() : value;
337
+ if (typeof text !== 'string' || !/^(?:0|-?[1-9][0-9]{0,18})$/.test(text)) return 'must be an int64 decimal string.';
338
+ const integer = BigInt(text);
339
+ return integer < -(1n << 63n) || integer >= (1n << 63n) ? 'is outside int64.' : undefined;
340
+ }
341
+ case 'number': {
342
+ if (typeof value !== 'number' || !Number.isFinite(value)) return 'must be a finite number.';
343
+ if (declaration.min !== undefined && value < declaration.min) return `must be at least ${declaration.min}.`;
344
+ if (declaration.max !== undefined && value > declaration.max) return `must be at most ${declaration.max}.`;
345
+ return undefined;
346
+ }
347
+ case 'boolean': return typeof value === 'boolean' ? undefined : 'must be true or false.';
348
+ case 'reference': return typeof value === 'string' && /^[A-Za-z0-9_-]{1,80}$/.test(value) ? undefined : 'must be a record ID.';
349
+ case 'json': {
350
+ if (!isJsonObject(value, 0)) return 'must be a JSON object.';
351
+ if (!declaration.fields) return undefined;
352
+ for (const [key, entry] of Object.entries(value as { [key: string]: unknown })) {
353
+ const nested = Object.hasOwn(declaration.fields, key) ? declaration.fields[key] : undefined;
354
+ if (!nested) return `has no subfield ${key}.`;
355
+ // A missing or null subfield is unset.
356
+ const error = entry === null ? undefined : validateValue(key, nested, entry);
357
+ if (error) return `${nested.label ?? key} ${error}`;
358
+ }
359
+ return undefined;
360
+ }
361
+ case 'vector': return Array.isArray(value) && value.length === declaration.dimensions && value.every(entry => typeof entry === 'number' && Number.isFinite(entry) && Number.isFinite(Math.fround(entry)))
362
+ ? undefined : `must be ${declaration.dimensions} finite numbers.`;
363
+ case 'blocks': {
364
+ const shape = blocksShapeProblem(value);
365
+ if (shape) return shape;
366
+ return (value as { data: unknown }[]).every(block => isJsonObject(block.data, 1)) ? undefined : 'block data must be plain JSON.';
367
+ }
368
+ case 'richtext': return richTextProblem(value) ?? (isJsonObject(value, 0) ? undefined : 'must be plain JSON.');
369
+ case 'rows': {
370
+ const max = declaration.max ?? ROW_LIMITS.default;
371
+ if (!Array.isArray(value) || value.length > max) return `must be a list of at most ${max} rows.`;
372
+ if (declaration.min !== undefined && value.length < declaration.min) return `needs at least ${declaration.min} ${declaration.min === 1 ? 'row' : 'rows'}.`;
373
+ const ids = new Set<string>();
374
+ for (const [index, row] of value.entries()) {
375
+ if (!isJsonObject(row, 0)) return `row ${index + 1} must be an object.`;
376
+ const entries = row as { [key: string]: unknown };
377
+ if (entries._id !== undefined) {
378
+ if (typeof entries._id !== 'string' || !ROW_ID.test(entries._id) || ids.has(entries._id)) return `row ${index + 1} has an invalid or repeated _id.`;
379
+ ids.add(entries._id);
380
+ }
381
+ for (const [key, nested] of Object.entries(declaration.fields ?? {})) {
382
+ const entry = entries[key];
383
+ if (entry === undefined || entry === null || entry === '') {
384
+ if (nested.required) return `row ${index + 1}: ${nested.label ?? key} is required.`;
385
+ continue;
386
+ }
387
+ const error = validateValue(key, nested, entry);
388
+ if (error) return `row ${index + 1}: ${nested.label ?? key} ${error}`;
389
+ }
390
+ for (const key of Object.keys(entries)) if (key !== '_id' && !Object.hasOwn(declaration.fields ?? {}, key)) return `row ${index + 1} has no field ${key}.`;
391
+ }
392
+ return undefined;
393
+ }
394
+ }
395
+ }
396
+
397
+ export { blocksShapeProblem } from './block-shape';
398
+ import { blocksShapeProblem } from './block-shape';
399
+
400
+ function isJsonObject(value: unknown, depth: number): boolean {
401
+ if (depth > 32 || value === null || typeof value !== 'object' || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype) return false;
402
+ return Object.values(value).every(entry => isJsonValue(entry, depth + 1));
403
+ }
404
+
405
+ function isJsonValue(value: unknown, depth: number): boolean {
406
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') return true;
407
+ // Integral numbers are stored as int64; unsafe ones would lose precision.
408
+ if (typeof value === 'number') return Number.isFinite(value) && (!Number.isInteger(value) || Number.isSafeInteger(value));
409
+ if (Array.isArray(value)) return depth <= 32 && value.every(entry => isJsonValue(entry, depth + 1));
410
+ return isJsonObject(value, depth);
411
+ }