tinyzoo 0.0.0-stage → 0.2.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 (392) hide show
  1. package/LICENSE +10 -0
  2. package/README.md +46 -2
  3. package/app/app.config.ts +35 -0
  4. package/app/assets/brand/characters/bright/bird.svg +1 -0
  5. package/app/assets/brand/characters/bright/bunny.svg +1 -0
  6. package/app/assets/brand/characters/bright/elephant.svg +1 -0
  7. package/app/assets/brand/characters/bright/fox.svg +1 -0
  8. package/app/assets/brand/characters/bright/frog.svg +1 -0
  9. package/app/assets/brand/characters/bright/octopus.svg +1 -0
  10. package/app/assets/brand/characters/muted/bee.svg +1 -0
  11. package/app/assets/brand/characters/muted/bird.svg +1 -0
  12. package/app/assets/brand/characters/muted/butterfly.svg +1 -0
  13. package/app/assets/brand/characters/muted/chick.svg +1 -0
  14. package/app/assets/brand/characters/muted/cow.svg +1 -0
  15. package/app/assets/brand/characters/muted/deer.svg +1 -0
  16. package/app/assets/brand/characters/muted/duck.svg +1 -0
  17. package/app/assets/brand/characters/muted/elephant.svg +1 -0
  18. package/app/assets/brand/characters/muted/fox.svg +1 -0
  19. package/app/assets/brand/characters/muted/hedgehog.svg +1 -0
  20. package/app/assets/brand/characters/muted/koala.svg +1 -0
  21. package/app/assets/brand/characters/muted/ladybug.svg +1 -0
  22. package/app/assets/brand/characters/muted/lion.svg +1 -0
  23. package/app/assets/brand/characters/muted/mouse.svg +1 -0
  24. package/app/assets/brand/characters/muted/octopus.svg +1 -0
  25. package/app/assets/brand/characters/muted/owl.svg +1 -0
  26. package/app/assets/brand/characters/muted/panda.svg +1 -0
  27. package/app/assets/brand/characters/muted/penguin.svg +1 -0
  28. package/app/assets/brand/characters/muted/pig.svg +1 -0
  29. package/app/assets/brand/characters/muted/poodle.svg +1 -0
  30. package/app/assets/brand/characters/muted/raccoon.svg +1 -0
  31. package/app/assets/brand/characters/muted/seal.svg +1 -0
  32. package/app/assets/brand/characters/muted/sheep.svg +1 -0
  33. package/app/assets/brand/characters/muted/snail.svg +1 -0
  34. package/app/assets/brand/characters/muted/turtle.svg +1 -0
  35. package/app/assets/brand/characters/muted/whale.svg +1 -0
  36. package/app/assets/brand/logo/favicon.svg +1 -0
  37. package/app/assets/brand/logo/logo-primary-reversed.svg +1 -0
  38. package/app/assets/brand/logo/logo-primary.svg +1 -0
  39. package/app/assets/brand/logo/mascot-reversed.svg +1 -0
  40. package/app/assets/brand/logo/mascot.svg +1 -0
  41. package/app/assets/brand/logo/wordmark-reversed.svg +1 -0
  42. package/app/assets/brand/logo/wordmark.svg +1 -0
  43. package/app/assets/css/cms-admin.css +607 -0
  44. package/app/components/CmsBlocks.vue +30 -0
  45. package/app/components/CmsCell.vue +16 -0
  46. package/app/components/CmsCellBadge.vue +18 -0
  47. package/app/components/CmsCellBlocks.vue +9 -0
  48. package/app/components/CmsCellBoolean.vue +12 -0
  49. package/app/components/CmsCellCode.vue +7 -0
  50. package/app/components/CmsCellColor.vue +13 -0
  51. package/app/components/CmsCellDate.vue +10 -0
  52. package/app/components/CmsCellExcerpt.vue +21 -0
  53. package/app/components/CmsCellGallery.vue +10 -0
  54. package/app/components/CmsCellGroup.vue +23 -0
  55. package/app/components/CmsCellNumber.vue +7 -0
  56. package/app/components/CmsCellRelation.vue +8 -0
  57. package/app/components/CmsCellText.vue +12 -0
  58. package/app/components/CmsCellThumb.vue +18 -0
  59. package/app/components/CmsConfirmDialog.vue +55 -0
  60. package/app/components/CmsContent.vue +103 -0
  61. package/app/components/CmsDayPicker.vue +44 -0
  62. package/app/components/CmsEmptyState.vue +35 -0
  63. package/app/components/CmsField.vue +111 -0
  64. package/app/components/CmsFieldBlocks.vue +353 -0
  65. package/app/components/CmsFieldBoolean.vue +8 -0
  66. package/app/components/CmsFieldColor.vue +42 -0
  67. package/app/components/CmsFieldDate.vue +131 -0
  68. package/app/components/CmsFieldGallery.vue +114 -0
  69. package/app/components/CmsFieldGroup.vue +53 -0
  70. package/app/components/CmsFieldMedia.vue +219 -0
  71. package/app/components/CmsFieldNumber.vue +11 -0
  72. package/app/components/CmsFieldRelationMany.vue +54 -0
  73. package/app/components/CmsFieldRelationOne.vue +47 -0
  74. package/app/components/CmsFieldRichText.vue +45 -0
  75. package/app/components/CmsFieldSelect.vue +41 -0
  76. package/app/components/CmsFieldSlug.vue +46 -0
  77. package/app/components/CmsFieldText.vue +75 -0
  78. package/app/components/CmsFormSections.vue +150 -0
  79. package/app/components/CmsHighlight.vue +22 -0
  80. package/app/components/CmsImage.vue +39 -0
  81. package/app/components/CmsLinkPicker.vue +122 -0
  82. package/app/components/CmsLinkTarget.vue +35 -0
  83. package/app/components/CmsListFilters.vue +107 -0
  84. package/app/components/CmsLiveNotice.vue +64 -0
  85. package/app/components/CmsLoadError.vue +24 -0
  86. package/app/components/CmsMascot.vue +10 -0
  87. package/app/components/CmsMediaLibrary.vue +114 -0
  88. package/app/components/CmsMediaPreview.vue +34 -0
  89. package/app/components/CmsMediaThumb.vue +22 -0
  90. package/app/components/CmsMoment.vue +42 -0
  91. package/app/components/CmsNav.vue +39 -0
  92. package/app/components/CmsPage.vue +86 -0
  93. package/app/components/CmsPasswordInput.vue +22 -0
  94. package/app/components/CmsPresence.vue +29 -0
  95. package/app/components/CmsPreviewPanel.vue +131 -0
  96. package/app/components/CmsPublishReview.vue +102 -0
  97. package/app/components/CmsRevisions.vue +195 -0
  98. package/app/components/CmsRichTextEditor.vue +290 -0
  99. package/app/components/CmsSearch.vue +99 -0
  100. package/app/components/CmsSection.vue +20 -0
  101. package/app/components/CmsSingletonForm.vue +283 -0
  102. package/app/components/CmsStatusBadge.vue +21 -0
  103. package/app/components/CmsTime.vue +16 -0
  104. package/app/components/CmsTranslationRef.vue +27 -0
  105. package/app/components/CmsTreeList.vue +453 -0
  106. package/app/components/CmsUnsavedText.vue +34 -0
  107. package/app/components/CmsWordmark.vue +10 -0
  108. package/app/composables/useCmsAdminHead.ts +18 -0
  109. package/app/composables/useCmsCollab.ts +165 -0
  110. package/app/composables/useCmsConfirm.ts +39 -0
  111. package/app/composables/useCmsEntryActions.ts +75 -0
  112. package/app/composables/useCmsFocus.ts +13 -0
  113. package/app/composables/useCmsForm.ts +273 -0
  114. package/app/composables/useCmsI18n.ts +185 -0
  115. package/app/composables/useCmsLinkTargets.ts +84 -0
  116. package/app/composables/useCmsLive.ts +199 -0
  117. package/app/composables/useCmsSearch.ts +62 -0
  118. package/app/composables/useCmsSeo.ts +99 -0
  119. package/app/composables/useCmsSignedIn.ts +24 -0
  120. package/app/composables/useCmsUiLocale.ts +24 -0
  121. package/app/i18n/cs.ts +781 -0
  122. package/app/i18n/de.ts +781 -0
  123. package/app/i18n/en.ts +782 -0
  124. package/app/i18n/types.ts +22 -0
  125. package/app/layouts/admin.vue +224 -0
  126. package/app/layouts/cms-auth.vue +37 -0
  127. package/app/middleware/cms-api-not-a-page.global.ts +10 -0
  128. package/app/middleware/cms-auth.global.ts +16 -0
  129. package/app/pages/admin/[entity]/[id].vue +1109 -0
  130. package/app/pages/admin/[entity]/index.vue +733 -0
  131. package/app/pages/admin/account.vue +117 -0
  132. package/app/pages/admin/forgot.vue +50 -0
  133. package/app/pages/admin/index.vue +184 -0
  134. package/app/pages/admin/invite/[token].vue +73 -0
  135. package/app/pages/admin/login.vue +84 -0
  136. package/app/pages/admin/media.vue +494 -0
  137. package/app/pages/admin/privacy.vue +193 -0
  138. package/app/pages/admin/reset/[token].vue +52 -0
  139. package/app/pages/admin/setup.vue +87 -0
  140. package/app/pages/admin/styleguide.vue +261 -0
  141. package/app/pages/admin/team.vue +258 -0
  142. package/app/plugins/cmsLivePreview.client.ts +20 -0
  143. package/app/plugins/cmsSignedOut.client.ts +31 -0
  144. package/app/utils/cmsBlockType.ts +11 -0
  145. package/app/utils/cmsBrand.ts +38 -0
  146. package/app/utils/cmsDiff.ts +83 -0
  147. package/app/utils/cmsFetch.ts +7 -0
  148. package/app/utils/cmsFocusInvalid.ts +22 -0
  149. package/app/utils/cmsIssues.ts +128 -0
  150. package/app/utils/cmsJson.ts +28 -0
  151. package/app/utils/cmsMedia.ts +63 -0
  152. package/app/utils/cmsSections.ts +154 -0
  153. package/app/utils/cmsTime.ts +41 -0
  154. package/cli/backup.ts +713 -0
  155. package/cli/breaking.ts +174 -0
  156. package/cli/content-migrate.ts +239 -0
  157. package/cli/db.ts +86 -0
  158. package/cli/export.ts +336 -0
  159. package/cli/generate.ts +146 -0
  160. package/cli/import.ts +643 -0
  161. package/cli/index.ts +140 -0
  162. package/cli/links-convert.ts +291 -0
  163. package/cli/seed-engine.ts +705 -0
  164. package/cli/seed.ts +339 -0
  165. package/cli/status.ts +49 -0
  166. package/cli/tar.ts +304 -0
  167. package/cli/transfer.ts +677 -0
  168. package/cli/up.ts +27 -0
  169. package/cli/upgrade.ts +60 -0
  170. package/cli/versions.ts +60 -0
  171. package/forms/components/CmsForm.vue +186 -0
  172. package/forms/index.ts +203 -0
  173. package/forms/messages.ts +104 -0
  174. package/forms/retention.ts +48 -0
  175. package/forms/server/form.get.ts +12 -0
  176. package/forms/server/form.post.ts +109 -0
  177. package/forms/server/formSettings.ts +12 -0
  178. package/forms/server/forms.ts +127 -0
  179. package/module.ts +373 -0
  180. package/nuxt.config.ts +43 -0
  181. package/package.json +98 -3
  182. package/server/api/cms/[entity]/[id]/revisions/[rev].get.ts +19 -0
  183. package/server/api/cms/[entity]/[id]/revisions/index.get.ts +14 -0
  184. package/server/api/cms/[entity]/[id].delete.ts +52 -0
  185. package/server/api/cms/[entity]/[id].get.ts +21 -0
  186. package/server/api/cms/[entity]/[id].patch.ts +116 -0
  187. package/server/api/cms/[entity]/_export.get.ts +69 -0
  188. package/server/api/cms/[entity]/_move.post.ts +81 -0
  189. package/server/api/cms/[entity]/_order.post.ts +49 -0
  190. package/server/api/cms/[entity]/_tree.get.ts +41 -0
  191. package/server/api/cms/[entity]/index.get.ts +62 -0
  192. package/server/api/cms/[entity]/index.post.ts +38 -0
  193. package/server/api/cms/[entity]/options.get.ts +55 -0
  194. package/server/api/cms/_auth/accept.post.ts +33 -0
  195. package/server/api/cms/_auth/forgot.post.ts +39 -0
  196. package/server/api/cms/_auth/invite/[token].get.ts +18 -0
  197. package/server/api/cms/_auth/login.post.ts +42 -0
  198. package/server/api/cms/_auth/logout.post.ts +7 -0
  199. package/server/api/cms/_auth/me.get.ts +5 -0
  200. package/server/api/cms/_auth/me.patch.ts +32 -0
  201. package/server/api/cms/_auth/password.post.ts +29 -0
  202. package/server/api/cms/_auth/reset.post.ts +34 -0
  203. package/server/api/cms/_auth/setup.post.ts +46 -0
  204. package/server/api/cms/_auth/status.get.ts +18 -0
  205. package/server/api/cms/_collab/session.get.ts +30 -0
  206. package/server/api/cms/_collab/socket.ts +51 -0
  207. package/server/api/cms/_collab/unsaved.delete.ts +16 -0
  208. package/server/api/cms/_graph.get.ts +20 -0
  209. package/server/api/cms/_links/resolve.post.ts +17 -0
  210. package/server/api/cms/_links.get.ts +81 -0
  211. package/server/api/cms/_live.ts +30 -0
  212. package/server/api/cms/_media/[id]/usage.get.ts +14 -0
  213. package/server/api/cms/_media/[id].delete.ts +29 -0
  214. package/server/api/cms/_media/[id].get.ts +13 -0
  215. package/server/api/cms/_media/[id].patch.ts +64 -0
  216. package/server/api/cms/_media/exists.post.ts +15 -0
  217. package/server/api/cms/_media/img/[id]/[file].get.ts +42 -0
  218. package/server/api/cms/_media/index.get.ts +44 -0
  219. package/server/api/cms/_media/index.post.ts +147 -0
  220. package/server/api/cms/_media/raw/[...key].get.ts +85 -0
  221. package/server/api/cms/_media/raw/[...key].head.ts +2 -0
  222. package/server/api/cms/_overview.get.ts +87 -0
  223. package/server/api/cms/_preview.post.ts +17 -0
  224. package/server/api/cms/_privacy/delete.post.ts +14 -0
  225. package/server/api/cms/_privacy/export.post.ts +25 -0
  226. package/server/api/cms/_privacy/lookup.post.ts +27 -0
  227. package/server/api/cms/_search.get.ts +17 -0
  228. package/server/api/cms/_singleton/[name].get.ts +19 -0
  229. package/server/api/cms/_singleton/[name].put.ts +76 -0
  230. package/server/api/cms/_users/[id]/resend.post.ts +25 -0
  231. package/server/api/cms/_users/[id].delete.ts +21 -0
  232. package/server/api/cms/_users/[id].patch.ts +45 -0
  233. package/server/api/cms/_users/index.get.ts +28 -0
  234. package/server/api/cms/_users/index.post.ts +39 -0
  235. package/server/api/content/[entity]/[slug].get.ts +74 -0
  236. package/server/api/content/[entity]/index.get.ts +100 -0
  237. package/server/api/content/_global/[name].get.ts +23 -0
  238. package/server/api/content/_search.get.ts +28 -0
  239. package/server/api/content/_sitemap.get.ts +8 -0
  240. package/server/api/content/_tree/[entity].get.ts +31 -0
  241. package/server/api/content-types.ts.get.ts +17 -0
  242. package/server/api/health/live.get.ts +10 -0
  243. package/server/api/health/ready.get.ts +21 -0
  244. package/server/api/openapi.get.ts +48 -0
  245. package/server/api/openapi.json.get.ts +32 -0
  246. package/server/db/driver.ts +8 -0
  247. package/server/mail/mailer.ts +43 -0
  248. package/server/middleware/cms-0-headers.ts +37 -0
  249. package/server/middleware/cms-0-migrate-gate.ts +14 -0
  250. package/server/middleware/cms-csrf.ts +28 -0
  251. package/server/middleware/cms-limits.ts +20 -0
  252. package/server/middleware/cms-redirects.ts +21 -0
  253. package/server/middleware/cms-session.ts +41 -0
  254. package/server/middleware/cms-z-plugin-access.ts +15 -0
  255. package/server/plugins/cms-0-config-check.ts +35 -0
  256. package/server/plugins/cms-changes.ts +53 -0
  257. package/server/plugins/cms-content-etag.ts +21 -0
  258. package/server/plugins/cms-errors.ts +45 -0
  259. package/server/plugins/cms-migrate.ts +5 -0
  260. package/server/plugins/cms-plugins.ts +17 -0
  261. package/server/plugins/cms-search.ts +12 -0
  262. package/server/plugins/cms-setup-code.ts +15 -0
  263. package/server/routes/sitemap.xml.get.ts +25 -0
  264. package/server/store/redis.ts +95 -0
  265. package/server/store/types.ts +21 -0
  266. package/server/tasks/cms/retention.ts +10 -0
  267. package/server/tasks/cms/scheduled.ts +10 -0
  268. package/server/tasks/cms/search-reindex.ts +12 -0
  269. package/server/utils/cmsAudit.ts +29 -0
  270. package/server/utils/cmsAuth.ts +143 -0
  271. package/server/utils/cmsBlocks.ts +47 -0
  272. package/server/utils/cmsChanges.ts +222 -0
  273. package/server/utils/cmsCollab.ts +286 -0
  274. package/server/utils/cmsCollabServer.ts +451 -0
  275. package/server/utils/cmsCollate.ts +27 -0
  276. package/server/utils/cmsContent.ts +376 -0
  277. package/server/utils/cmsCrud.ts +361 -0
  278. package/server/utils/cmsCsv.ts +24 -0
  279. package/server/utils/cmsDb.ts +23 -0
  280. package/server/utils/cmsDemo.ts +36 -0
  281. package/server/utils/cmsEmails.ts +125 -0
  282. package/server/utils/cmsErrors.ts +40 -0
  283. package/server/utils/cmsFold.ts +17 -0
  284. package/server/utils/cmsImageSizes.ts +51 -0
  285. package/server/utils/cmsJson.ts +6 -0
  286. package/server/utils/cmsLinkAddress.ts +50 -0
  287. package/server/utils/cmsLinks.ts +248 -0
  288. package/server/utils/cmsListQuery.ts +93 -0
  289. package/server/utils/cmsLive.ts +393 -0
  290. package/server/utils/cmsLocales.ts +96 -0
  291. package/server/utils/cmsMail.ts +28 -0
  292. package/server/utils/cmsMediaGc.ts +188 -0
  293. package/server/utils/cmsMediaKeys.ts +62 -0
  294. package/server/utils/cmsMigrate.ts +86 -0
  295. package/server/utils/cmsPreviewDraft.ts +72 -0
  296. package/server/utils/cmsPrivacy.ts +176 -0
  297. package/server/utils/cmsPublished.ts +57 -0
  298. package/server/utils/cmsRange.ts +38 -0
  299. package/server/utils/cmsRateLimit.ts +82 -0
  300. package/server/utils/cmsRedirects.ts +160 -0
  301. package/server/utils/cmsRetention.ts +61 -0
  302. package/server/utils/cmsRevisions.ts +103 -0
  303. package/server/utils/cmsScheduler.ts +45 -0
  304. package/server/utils/cmsScrub.ts +107 -0
  305. package/server/utils/cmsSearch.ts +354 -0
  306. package/server/utils/cmsSession.ts +102 -0
  307. package/server/utils/cmsSetupCode.ts +97 -0
  308. package/server/utils/cmsSitemap.ts +176 -0
  309. package/server/utils/cmsStorage.ts +580 -0
  310. package/server/utils/cmsStore.ts +109 -0
  311. package/server/utils/cmsTiming.ts +14 -0
  312. package/server/utils/cmsTooMany.ts +9 -0
  313. package/server/utils/cmsTranslationWrite.ts +186 -0
  314. package/server/utils/cmsTree.ts +251 -0
  315. package/server/utils/cmsTreeAddress.ts +65 -0
  316. package/server/utils/cmsUpload.ts +228 -0
  317. package/server/utils/cmsWebhooks.ts +104 -0
  318. package/shared/json.ts +11 -0
  319. package/shared/richtext-editor.ts +56 -0
  320. package/shared/richtext-normalize.ts +33 -0
  321. package/shared/richtext-paste.ts +151 -0
  322. package/shared/storage-delivery.ts +53 -0
  323. package/src/blocks.ts +624 -0
  324. package/src/changes.ts +54 -0
  325. package/src/content-shape.ts +340 -0
  326. package/src/deprecate.ts +64 -0
  327. package/src/descriptor.ts +149 -0
  328. package/src/docs.ts +27 -0
  329. package/src/emitter.ts +94 -0
  330. package/src/entity.ts +624 -0
  331. package/src/errorReport.ts +41 -0
  332. package/src/fields.ts +465 -0
  333. package/src/i18n.ts +26 -0
  334. package/src/index.ts +54 -0
  335. package/src/linkref.ts +31 -0
  336. package/src/links.ts +179 -0
  337. package/src/locales.ts +39 -0
  338. package/src/media.ts +48 -0
  339. package/src/migrate.ts +236 -0
  340. package/src/openapi.ts +377 -0
  341. package/src/paths.ts +88 -0
  342. package/src/plugin.ts +505 -0
  343. package/src/presets.ts +230 -0
  344. package/src/richtext.ts +88 -0
  345. package/src/sdk.ts +181 -0
  346. package/src/search.ts +312 -0
  347. package/src/seed.ts +225 -0
  348. package/src/setupCode.ts +30 -0
  349. package/src/system.ts +219 -0
  350. package/src/tree.ts +421 -0
  351. package/src/upgrades.ts +137 -0
  352. package/starter/.env.example +10 -0
  353. package/starter/README.md +65 -0
  354. package/starter/app/app.config.ts +10 -0
  355. package/starter/app/app.vue +12 -0
  356. package/starter/app/assets/css/main.css +15 -0
  357. package/starter/app/components/global/BlockContact.vue +15 -0
  358. package/starter/app/components/global/BlockCta.vue +15 -0
  359. package/starter/app/components/global/BlockHero.vue +23 -0
  360. package/starter/app/components/global/BlockImage.vue +13 -0
  361. package/starter/app/components/global/BlockText.vue +12 -0
  362. package/starter/app/composables/useSite.ts +77 -0
  363. package/starter/app/error.vue +28 -0
  364. package/starter/app/layouts/default.vue +106 -0
  365. package/starter/app/lib/cms-content.ts +152 -0
  366. package/starter/app/pages/[...slug].vue +66 -0
  367. package/starter/app/pages/hledat.vue +59 -0
  368. package/starter/app/pages/index.vue +20 -0
  369. package/starter/cms.config.ts +137 -0
  370. package/starter/compose.yaml +15 -0
  371. package/starter/drizzle.config.ts +8 -0
  372. package/starter/gitignore.txt +8 -0
  373. package/starter/nuxt.config.ts +13 -0
  374. package/starter/package.json +38 -0
  375. package/starter/scripts/typecheck.mjs +38 -0
  376. package/starter/seed/index.ts +297 -0
  377. package/starter/seed/media/about.jpg +0 -0
  378. package/starter/seed/media/hero.jpg +0 -0
  379. package/starter/seed/media/logo.png +0 -0
  380. package/starter/seed/media/news-bread.jpg +0 -0
  381. package/starter/seed/media/news-morning.jpg +0 -0
  382. package/starter/server/db/migrations/0000_init.sql +269 -0
  383. package/starter/server/db/migrations/0001_page_tree.sql +5 -0
  384. package/starter/server/db/migrations/0002_opening_hours_per_language.sql +1 -0
  385. package/starter/server/db/migrations/meta/0000_snapshot.json +1890 -0
  386. package/starter/server/db/migrations/meta/0001_snapshot.json +1887 -0
  387. package/starter/server/db/migrations/meta/0002_snapshot.json +1893 -0
  388. package/starter/server/db/migrations/meta/_journal.json +27 -0
  389. package/starter/server/db/schema.ts +253 -0
  390. package/starter/server/plugins/sitemap.ts +11 -0
  391. package/starter/server/routes/robots.txt.get.ts +12 -0
  392. package/starter/tsconfig.json +9 -0
package/src/openapi.ts ADDED
@@ -0,0 +1,377 @@
1
+ import { buildContentModel, type ContentField, type ContentFieldType, type ContentShape } from './content-shape'
2
+
3
+ // Emit an OpenAPI 3.1 document describing the PUBLIC content API, generated from
4
+ // cms.config.ts. Every public collection gets concrete `/api/content/<name>` and
5
+ // `/<name>/{slug}` paths (concrete, not templated — far better codegen DX), and the
6
+ // response schemas mirror the actual projected shapes (see content-shape.ts).
7
+
8
+ export interface OpenApiOptions {
9
+ title?: string
10
+ version?: string
11
+ description?: string
12
+ servers?: { url: string; description?: string }[]
13
+ /** When true, declare + require the content API token security scheme. */
14
+ tokenAuth?: boolean
15
+ }
16
+
17
+ type JsonSchema = Record<string, any>
18
+
19
+ const REF = (name: string): JsonSchema => ({ $ref: `#/components/schemas/${name}` })
20
+
21
+ const MEDIA_PROPERTIES: JsonSchema = {
22
+ id: { type: 'string', format: 'uuid' },
23
+ url: { type: 'string', format: 'uri' },
24
+ width: { type: ['integer', 'null'] },
25
+ height: { type: ['integer', 'null'] },
26
+ alt: { type: ['string', 'null'] },
27
+ mime: { type: 'string' },
28
+ focal: {
29
+ type: ['object', 'null'],
30
+ additionalProperties: false,
31
+ properties: { x: { type: 'integer', minimum: 0, maximum: 100 }, y: { type: 'integer', minimum: 0, maximum: 100 } },
32
+ required: ['x', 'y'],
33
+ },
34
+ }
35
+ const MEDIA_REQUIRED = ['id', 'url', 'width', 'height', 'alt', 'mime', 'focal']
36
+
37
+ /** Wrap a schema so the value may also be JSON `null` (OpenAPI 3.1 style). */
38
+ function nullable(schema: JsonSchema, isNullable: boolean): JsonSchema {
39
+ if (!isNullable) return schema
40
+ if (schema.$ref) return { anyOf: [schema, { type: 'null' }] }
41
+ const t = schema.type
42
+ if (typeof t === 'string') {
43
+ const out: JsonSchema = { ...schema, type: [t, 'null'] }
44
+ // A nullable enum must list null, else strict 2020-12 validators reject null.
45
+ if (Array.isArray(out.enum) && !out.enum.includes(null)) out.enum = [...out.enum, null]
46
+ return out
47
+ }
48
+ return { anyOf: [schema, { type: 'null' }] }
49
+ }
50
+
51
+ function scalarSchema(t: Extract<ContentFieldType, { kind: 'scalar' }>): JsonSchema {
52
+ switch (t.scalar) {
53
+ case 'integer': return { type: 'integer' }
54
+ case 'number': return { type: 'number' }
55
+ case 'boolean': return { type: 'boolean' }
56
+ case 'datetime': return { type: 'string', format: 'date-time' }
57
+ case 'string': {
58
+ const s: JsonSchema = { type: 'string' }
59
+ if (t.enumValues) s.enum = [...t.enumValues]
60
+ if (t.pattern) s.pattern = t.pattern
61
+ return s
62
+ }
63
+ }
64
+ }
65
+
66
+ /** Map a projected field's value-type to a JSON Schema (relations → $refs). */
67
+ function fieldSchema(t: ContentFieldType): JsonSchema {
68
+ switch (t.kind) {
69
+ case 'scalar': return scalarSchema(t)
70
+ case 'richtext': return REF('RichTextDoc')
71
+ case 'media': return REF('CmsMedia')
72
+ case 'gallery': return { type: 'array', items: REF('CmsGalleryItem') }
73
+ case 'relation-one': return REF(t.public ? `${pascalRef(t.target)}Embedded` : `${pascalRef(t.target)}Ref`)
74
+ case 'relation-many': return { type: 'array', items: REF(t.public ? `${pascalRef(t.target)}Embedded` : `${pascalRef(t.target)}Ref`) }
75
+ case 'blocks': {
76
+ const variants = t.blocks.map((b) => {
77
+ const properties: JsonSchema = { id: { type: 'string' }, type: { type: 'string', const: b.type } }
78
+ for (const f of b.fields) properties[f.key] = nullable(fieldSchema(f.type), f.nullable)
79
+ return { type: 'object', properties, required: ['id', 'type', ...b.fields.map((f) => f.key)], additionalProperties: false }
80
+ })
81
+ return { type: 'array', items: variants.length === 1 ? variants[0] : { oneOf: variants, discriminator: { propertyName: 'type' } } }
82
+ }
83
+ case 'group': {
84
+ const properties: JsonSchema = {}
85
+ for (const f of t.fields) properties[f.key] = nullable(fieldSchema(f.type), f.nullable)
86
+ return { type: 'object', properties, required: t.fields.map((f) => f.key), additionalProperties: false }
87
+ }
88
+ }
89
+ }
90
+
91
+ // content-shape already pascal-cases; we only have the entity name on relation
92
+ // targets, so re-derive here with the same rule (snake/kebab → Pascal).
93
+ function pascalRef(name: string): string {
94
+ return name.replace(/(^|[_-])([a-z0-9])/g, (_, __, c) => c.toUpperCase())
95
+ }
96
+
97
+ /** An object schema for a list of projected fields, with id + optional timestamps. */
98
+ function objectSchema(fields: ContentField[], opts: { timestamps: boolean; locales?: string[] | null; paths?: boolean; tree?: boolean }): JsonSchema {
99
+ const properties: JsonSchema = { id: { type: 'string', format: 'uuid' } }
100
+ const required = ['id']
101
+ for (const f of fields) {
102
+ properties[f.key] = nullable(fieldSchema(f.type), f.nullable)
103
+ required.push(f.key)
104
+ }
105
+ if (opts.timestamps) {
106
+ properties.createdAt = { type: 'string', format: 'date-time' }
107
+ properties.updatedAt = { type: 'string', format: 'date-time' }
108
+ required.push('createdAt', 'updatedAt')
109
+ }
110
+ if (opts.locales) {
111
+ properties.locale = { type: 'string', enum: [...opts.locales], description: 'The language this item is served in.' }
112
+ properties.locales = { type: 'array', items: { type: 'string', enum: [...opts.locales] }, description: 'Languages this item exists in.' }
113
+ required.push('locale', 'locales')
114
+ if (opts.paths) {
115
+ properties.paths = { type: 'object', additionalProperties: { type: 'string' }, description: "The item's address in each language it exists in." }
116
+ required.push('paths')
117
+ }
118
+ }
119
+ if (opts.tree) {
120
+ properties.path = { type: ['string', 'null'], description: "The page's address in the language served: its ancestors' address parts and its own (/o-nas/tym), language prefix included." }
121
+ properties.breadcrumbs = {
122
+ type: 'array',
123
+ description: 'From the top of the tree down to this page (the page itself last): title and address of each, in the language served. Only live pages.',
124
+ items: { type: 'object', additionalProperties: false, properties: { title: { type: 'string' }, path: { type: 'string' } }, required: ['title', 'path'] },
125
+ }
126
+ required.push('path', 'breadcrumbs')
127
+ }
128
+ return { type: 'object', additionalProperties: false, properties, required }
129
+ }
130
+
131
+ function localeParam(shape: ContentShape): JsonSchema[] {
132
+ if (!shape.locales) return []
133
+ return [{
134
+ name: 'locale', in: 'query',
135
+ description: 'Language to serve. Untranslated fields fall back to the default language.',
136
+ schema: { type: 'string', enum: [...shape.locales], default: shape.locales[0] },
137
+ }]
138
+ }
139
+
140
+ function listParams(shape: ContentShape): JsonSchema[] {
141
+ const params: JsonSchema[] = [
142
+ { name: 'page', in: 'query', schema: { type: 'integer', minimum: 1, default: 1 } },
143
+ { name: 'limit', in: 'query', schema: { type: 'integer', minimum: 1, maximum: 100, default: 20 } },
144
+ { name: 'sort', in: 'query', schema: { type: 'string', enum: shape.sortKeys, default: 'createdAt' } },
145
+ { name: 'dir', in: 'query', schema: { type: 'string', enum: ['asc', 'desc'], default: 'desc' } },
146
+ { name: 'q', in: 'query', description: `Substring match against \`${shape.titleField}\`.`, schema: { type: 'string' } },
147
+ ...localeParam(shape),
148
+ ]
149
+ for (const filter of shape.filters) {
150
+ if (filter.value === 'datetime') {
151
+ const from = filter.key.endsWith('.from')
152
+ params.push({
153
+ name: filter.key,
154
+ in: 'query',
155
+ description: from ? 'Only items on or after this date or time (ISO 8601).' : 'Only items on or before this date or time (ISO 8601; a bare date includes the whole day).',
156
+ schema: { type: 'string' },
157
+ })
158
+ continue
159
+ }
160
+ params.push({
161
+ name: filter.key,
162
+ in: 'query',
163
+ description: 'Exact-match filter.',
164
+ schema: filter.value === 'boolean' ? { type: 'boolean' } : filter.enumValues ? { type: 'string', enum: [...filter.enumValues] } : { type: 'string' },
165
+ })
166
+ }
167
+ return params
168
+ }
169
+
170
+ export function buildOpenApiDocument(config: Record<string, any>, opts: OpenApiOptions = {}): JsonSchema {
171
+ const model = buildContentModel(config)
172
+ const tokenAuth = !!opts.tokenAuth
173
+
174
+ const schemas: JsonSchema = {
175
+ RichTextNode: {
176
+ type: 'object',
177
+ description: 'A ProseMirror/TipTap node. Render with a structured renderer — never raw HTML.',
178
+ properties: {
179
+ type: { type: 'string' },
180
+ text: { type: 'string' },
181
+ content: { type: 'array', items: REF('RichTextNode') },
182
+ marks: { type: 'array', items: { type: 'object', additionalProperties: true } },
183
+ attrs: { type: 'object', additionalProperties: true },
184
+ },
185
+ required: ['type'],
186
+ additionalProperties: true,
187
+ },
188
+ RichTextDoc: {
189
+ type: 'object',
190
+ properties: { type: { type: 'string', const: 'doc' }, content: { type: 'array', items: REF('RichTextNode') } },
191
+ required: ['type'],
192
+ additionalProperties: true,
193
+ },
194
+ CmsMedia: { type: 'object', additionalProperties: false, properties: MEDIA_PROPERTIES, required: MEDIA_REQUIRED },
195
+ // Spelled out (not allOf CmsMedia): CmsMedia forbids extra properties, so an allOf
196
+ // with it would reject every item for carrying `caption`.
197
+ CmsGalleryItem: {
198
+ type: 'object',
199
+ additionalProperties: false,
200
+ properties: { ...MEDIA_PROPERTIES, caption: { type: ['string', 'null'] } },
201
+ required: [...MEDIA_REQUIRED, 'caption'],
202
+ },
203
+ }
204
+
205
+ // Embedded (nested public) + ref (nested non-public) target schemas.
206
+ for (const emb of model.embedded) schemas[`${emb.pascal}Embedded`] = objectSchema(emb.fields, { timestamps: false })
207
+ for (const ref of model.refs) {
208
+ schemas[`${ref.pascal}Ref`] = {
209
+ type: 'object',
210
+ additionalProperties: false,
211
+ // The title key is ALWAYS present (publicProjection sets it); only its value
212
+ // may be null — so it stays `required`, the schema just allows null.
213
+ properties: { id: { type: 'string', format: 'uuid' }, [ref.titleField]: nullable(fieldSchema(ref.titleType), ref.titleNullable) },
214
+ required: ['id', ref.titleField],
215
+ }
216
+ }
217
+
218
+ // Top-level item + list-wrapper schemas, plus paths.
219
+ const paths: JsonSchema = {}
220
+ const tag = (name: string) => name
221
+ for (const shape of model.entities) {
222
+ schemas[shape.pascal] = objectSchema(shape.fields, { timestamps: true, locales: shape.locales, paths: shape.paths, tree: shape.tree })
223
+ schemas[`${shape.pascal}List`] = {
224
+ type: 'object',
225
+ additionalProperties: false,
226
+ properties: {
227
+ items: { type: 'array', items: REF(shape.pascal) },
228
+ total: { type: 'integer' },
229
+ page: { type: 'integer' },
230
+ limit: { type: 'integer' },
231
+ },
232
+ required: ['items', 'total', 'page', 'limit'],
233
+ }
234
+
235
+ const lookupBy = shape.slugField ? `\`${shape.slugField}\` (falling back to id)` : 'id'
236
+ paths[`/api/content/${shape.name}`] = {
237
+ get: {
238
+ operationId: `list${shape.pascal}`,
239
+ tags: [tag(shape.name)],
240
+ summary: `List ${shape.name} items`,
241
+ description: shape.gated ? 'Returns only published items.' : undefined,
242
+ parameters: listParams(shape),
243
+ responses: {
244
+ 200: { description: 'OK', content: { 'application/json': { schema: REF(`${shape.pascal}List`) } } },
245
+ ...(tokenAuth ? { 401: { description: 'Missing or invalid API token' } } : {}),
246
+ },
247
+ },
248
+ }
249
+ paths[`/api/content/${shape.name}/{slug}`] = {
250
+ get: {
251
+ operationId: `get${shape.pascal}`,
252
+ tags: [tag(shape.name)],
253
+ summary: `Get one ${shape.name} by ${shape.tree ? 'its address (the chain of address parts, o-nas/tym) or id' : lookupBy}`,
254
+ description: shape.tree ? 'The key is the chain of address parts from the top of the tree down, as one path segment with the slashes escaped (`o-nas%2Ftym`), looked up in the language asked for and then in the default one. A page under an unpublished page is not found.' : undefined,
255
+ parameters: [{ name: 'slug', in: 'path', required: true, schema: { type: 'string' } }, ...localeParam(shape)],
256
+ responses: {
257
+ 200: { description: 'OK', content: { 'application/json': { schema: { type: 'object', additionalProperties: false, properties: { item: REF(shape.pascal) }, required: ['item'] } } } },
258
+ 404: { description: 'Not found or not published' },
259
+ ...(tokenAuth ? { 401: { description: 'Missing or invalid API token' } } : {}),
260
+ },
261
+ },
262
+ }
263
+ }
264
+
265
+ const treeNodes = model.entities.filter((s) => s.tree)
266
+ if (treeNodes.length) {
267
+ schemas.CmsTreeNode = {
268
+ type: 'object',
269
+ additionalProperties: false,
270
+ properties: {
271
+ id: { type: 'string', format: 'uuid' },
272
+ title: { type: 'string' },
273
+ path: { type: ['string', 'null'] },
274
+ children: { type: 'array', items: REF('CmsTreeNode') },
275
+ },
276
+ required: ['id', 'title', 'path', 'children'],
277
+ }
278
+ }
279
+ for (const shape of treeNodes) {
280
+ paths[`/api/content/_tree/${shape.name}`] = {
281
+ get: {
282
+ operationId: `tree${shape.pascal}`,
283
+ tags: [shape.name],
284
+ summary: `The ${shape.name} tree, for navigation`,
285
+ description: 'Live pages only, top level first, each level in the order editors arranged it. A page under an unpublished page is left out with everything below it.',
286
+ parameters: localeParam(shape),
287
+ responses: {
288
+ 200: { description: 'OK', content: { 'application/json': { schema: { type: 'object', additionalProperties: false, properties: { items: { type: 'array', items: REF('CmsTreeNode') } }, required: ['items'] } } } },
289
+ ...(tokenAuth ? { 401: { description: 'Missing or invalid API token' } } : {}),
290
+ },
291
+ },
292
+ }
293
+ }
294
+
295
+ for (const g of model.globals) {
296
+ schemas[g.pascal] = objectSchema(g.fields, { timestamps: true, locales: g.locales })
297
+ paths[`/api/content/_global/${g.name}`] = {
298
+ get: {
299
+ operationId: `getGlobal${g.pascal}`,
300
+ tags: ['globals'],
301
+ summary: `Get the ${g.name} global`,
302
+ parameters: localeParam(g),
303
+ responses: {
304
+ 200: { description: 'OK (item is null until it is first saved)', content: { 'application/json': { schema: { type: 'object', additionalProperties: false, properties: { item: { anyOf: [REF(g.pascal), { type: 'null' }] } }, required: ['item'] } } } },
305
+ ...(tokenAuth ? { 401: { description: 'Missing or invalid API token' } } : {}),
306
+ },
307
+ },
308
+ }
309
+ }
310
+
311
+ // The website search, when some collection lives at an address.
312
+ if (model.search.collections.length) {
313
+ const ranges = { type: 'array', items: { type: 'array', items: { type: 'integer' }, minItems: 2, maxItems: 2 }, description: '[start, end) character ranges of the words found' }
314
+ schemas.CmsSearchItem = {
315
+ type: 'object',
316
+ additionalProperties: false,
317
+ properties: {
318
+ entity: { type: 'string', enum: model.search.collections },
319
+ id: { type: 'string', format: 'uuid' },
320
+ title: { type: 'string' },
321
+ titleHighlights: ranges,
322
+ excerpt: { type: 'string', description: 'Text around the first word found; empty when only the title matched' },
323
+ highlights: ranges,
324
+ path: { type: ['string', 'null'], description: 'The entry\'s address on the website, in the searched language' },
325
+ locale: { type: ['string', 'null'] },
326
+ updatedAt: { type: 'string', format: 'date-time' },
327
+ },
328
+ required: ['entity', 'id', 'title', 'titleHighlights', 'excerpt', 'highlights', 'path', 'locale', 'updatedAt'],
329
+ }
330
+ paths['/api/content/_search'] = {
331
+ get: {
332
+ operationId: 'search',
333
+ tags: ['search'],
334
+ summary: 'Search the website',
335
+ description: `Published entries of ${model.search.collections.join(', ')}, best matches first. Every word must appear (in any order, accents and case ignored); fewer than two letters return nothing.`,
336
+ parameters: [
337
+ { name: 'q', in: 'query', required: true, schema: { type: 'string', maxLength: 100 } },
338
+ { name: 'limit', in: 'query', schema: { type: 'integer', minimum: 1, maximum: 50, default: 10 } },
339
+ { name: 'entity', in: 'query', description: 'Only these collections (comma-separated)', schema: { type: 'string' } },
340
+ ...(model.search.locales ? [{ name: 'locale', in: 'query', description: 'Language to search in: only entries translated into it.', schema: { type: 'string', enum: model.search.locales } }] : []),
341
+ ],
342
+ responses: {
343
+ 200: {
344
+ description: 'OK',
345
+ content: { 'application/json': { schema: { type: 'object', additionalProperties: false, properties: { query: { type: 'string' }, items: { type: 'array', items: REF('CmsSearchItem') }, total: { type: 'integer' } }, required: ['query', 'items', 'total'] } } },
346
+ },
347
+ 429: { description: 'Too many searches from this visitor' },
348
+ ...(tokenAuth ? { 401: { description: 'Missing or invalid API token' } } : {}),
349
+ },
350
+ },
351
+ }
352
+ }
353
+
354
+ const doc: JsonSchema = {
355
+ openapi: '3.1.0',
356
+ info: {
357
+ title: opts.title ?? 'Content API',
358
+ version: opts.version ?? '1.0.0',
359
+ description: opts.description ?? 'Public, read-only content delivery API generated from cms.config.ts.',
360
+ },
361
+ servers: opts.servers ?? [{ url: '/' }],
362
+ paths,
363
+ components: {
364
+ schemas,
365
+ ...(tokenAuth
366
+ ? {
367
+ securitySchemes: {
368
+ ApiKey: { type: 'apiKey', in: 'header', name: 'x-api-key' },
369
+ BearerToken: { type: 'http', scheme: 'bearer' },
370
+ },
371
+ }
372
+ : {}),
373
+ },
374
+ ...(tokenAuth ? { security: [{ ApiKey: [] }, { BearerToken: [] }] } : {}),
375
+ }
376
+ return doc
377
+ }
package/src/paths.ts ADDED
@@ -0,0 +1,88 @@
1
+ import type { LocalesDef } from './locales'
2
+
3
+ /**
4
+ * An entry's address on the website, with `:field` placeholders: one template
5
+ * ('/blog/:slug'), or one per language when the address itself is translated
6
+ * ({ cs: '/aktuality/:slug', en: '/news/:slug' }). A language left out of the map
7
+ * has no page for this collection.
8
+ *
9
+ * The language prefix (`defineLocales({ prefix })`, e.g. '/en') is added on top.
10
+ */
11
+ export type PathTemplate = string | Record<string, string>
12
+
13
+ /** The address prefix of a language ('/en'), per `defineLocales({ prefix })`. */
14
+ export function sitePrefix(locales: LocalesDef | null, locale: string | null): string {
15
+ if (!locales || !locale || locales.prefix === 'none') return ''
16
+ if (locales.prefix === 'except-default' && locale === locales.default) return ''
17
+ return `/${locale}`
18
+ }
19
+
20
+ /** The template for one language (null: that language has no page). */
21
+ export function pathTemplateFor(template: PathTemplate | undefined | null, locale: string | null, locales: LocalesDef | null): string | null {
22
+ if (!template) return null
23
+ if (typeof template === 'string') return template
24
+ return template[locale ?? locales?.default ?? ''] ?? null
25
+ }
26
+
27
+ /** Placeholder keys of a template ('/blog/:slug' → ['slug']); for a map, of every language's. */
28
+ export function pathTemplateKeys(template: PathTemplate | undefined | null): string[] {
29
+ if (!template) return []
30
+ const all = typeof template === 'string' ? [template] : Object.values(template)
31
+ return [...new Set(all.flatMap((t) => [...t.matchAll(/:(\w+)/g)].map((m) => m[1]!)))]
32
+ }
33
+
34
+ /**
35
+ * A template filled in from a row ('/blog/:slug' → '/blog/hello'), or null when a part is
36
+ * empty. A part can be a list of address parts (a page tree: ['o-nas', 'tym']): each is
37
+ * escaped and they are joined with '/' ('/o-nas/tym').
38
+ */
39
+ export function fillPathTemplate(template: string, row: Record<string, any>): string | null {
40
+ let ok = true
41
+ const out = template.replace(/:(\w+)/g, (_m, key: string) => {
42
+ const v = row[key]
43
+ if (Array.isArray(v)) {
44
+ if (!v.length || v.some((x) => x === null || x === undefined || x === '')) ok = false
45
+ return v.map((x) => encodeURIComponent(String(x ?? ''))).join('/')
46
+ }
47
+ if (v === null || v === undefined || v === '') ok = false
48
+ return encodeURIComponent(String(v ?? ''))
49
+ })
50
+ return ok ? out : null
51
+ }
52
+
53
+ /**
54
+ * The full address of a row in one language (prefix included), or null. This is the one
55
+ * place addresses are put together: a page tree passes its address parts as a list
56
+ * (`{ slug: ['o-nas', 'tym'] }`, see src/tree.ts) and gets the nested address.
57
+ */
58
+ export function sitePath(locales: LocalesDef | null, template: PathTemplate | undefined | null, locale: string | null, row: Record<string, any>): string | null {
59
+ const t = pathTemplateFor(template, locale, locales)
60
+ const filled = t ? fillPathTemplate(t, row) : null
61
+ return filled === null ? null : sitePrefix(locales, locale) + filled
62
+ }
63
+
64
+ /**
65
+ * Per-language templates with the prefix already in front, for the admin's preview:
66
+ * { cs: '/aktuality/:slug', en: '/en/news/:slug' }; without languages, { '': '/blog/:slug' }.
67
+ */
68
+ export function prefixedTemplates(template: PathTemplate | undefined | null, locales: LocalesDef | null): Record<string, string> | null {
69
+ if (!template) return null
70
+ if (!locales) return typeof template === 'string' ? { '': template } : null
71
+ const out: Record<string, string> = {}
72
+ for (const l of locales.locales) {
73
+ const t = pathTemplateFor(template, l, locales)
74
+ if (t) out[l] = sitePrefix(locales, l) + t
75
+ }
76
+ return out
77
+ }
78
+
79
+ /** Configuration errors of a template: a map needs languages, and only known ones. */
80
+ export function pathTemplateProblem(template: PathTemplate | undefined | null, locales: LocalesDef | null): string | null {
81
+ if (!template || typeof template === 'string') return null
82
+ if (!locales) return 'has an address per language, but no languages are defined (defineLocales)'
83
+ const unknown = Object.keys(template).filter((l) => !locales.locales.includes(l))
84
+ if (unknown.length) return `has an address for unknown language${unknown.length > 1 ? 's' : ''} ${unknown.join(', ')}`
85
+ if (!template[locales.default]) return `needs an address for the default language "${locales.default}"`
86
+ for (const t of Object.values(template)) if (typeof t !== 'string' || !t.startsWith('/')) return `has an address that does not start with "/" (${String(t)})`
87
+ return null
88
+ }