tinyzoo 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +10 -0
- package/README.md +46 -2
- package/app/app.config.ts +35 -0
- package/app/assets/brand/characters/bright/bird.svg +1 -0
- package/app/assets/brand/characters/bright/bunny.svg +1 -0
- package/app/assets/brand/characters/bright/elephant.svg +1 -0
- package/app/assets/brand/characters/bright/fox.svg +1 -0
- package/app/assets/brand/characters/bright/frog.svg +1 -0
- package/app/assets/brand/characters/bright/octopus.svg +1 -0
- package/app/assets/brand/characters/muted/bee.svg +1 -0
- package/app/assets/brand/characters/muted/bird.svg +1 -0
- package/app/assets/brand/characters/muted/butterfly.svg +1 -0
- package/app/assets/brand/characters/muted/chick.svg +1 -0
- package/app/assets/brand/characters/muted/cow.svg +1 -0
- package/app/assets/brand/characters/muted/deer.svg +1 -0
- package/app/assets/brand/characters/muted/duck.svg +1 -0
- package/app/assets/brand/characters/muted/elephant.svg +1 -0
- package/app/assets/brand/characters/muted/fox.svg +1 -0
- package/app/assets/brand/characters/muted/hedgehog.svg +1 -0
- package/app/assets/brand/characters/muted/koala.svg +1 -0
- package/app/assets/brand/characters/muted/ladybug.svg +1 -0
- package/app/assets/brand/characters/muted/lion.svg +1 -0
- package/app/assets/brand/characters/muted/mouse.svg +1 -0
- package/app/assets/brand/characters/muted/octopus.svg +1 -0
- package/app/assets/brand/characters/muted/owl.svg +1 -0
- package/app/assets/brand/characters/muted/panda.svg +1 -0
- package/app/assets/brand/characters/muted/penguin.svg +1 -0
- package/app/assets/brand/characters/muted/pig.svg +1 -0
- package/app/assets/brand/characters/muted/poodle.svg +1 -0
- package/app/assets/brand/characters/muted/raccoon.svg +1 -0
- package/app/assets/brand/characters/muted/seal.svg +1 -0
- package/app/assets/brand/characters/muted/sheep.svg +1 -0
- package/app/assets/brand/characters/muted/snail.svg +1 -0
- package/app/assets/brand/characters/muted/turtle.svg +1 -0
- package/app/assets/brand/characters/muted/whale.svg +1 -0
- package/app/assets/brand/logo/favicon.svg +1 -0
- package/app/assets/brand/logo/logo-primary-reversed.svg +1 -0
- package/app/assets/brand/logo/logo-primary.svg +1 -0
- package/app/assets/brand/logo/mascot-reversed.svg +1 -0
- package/app/assets/brand/logo/mascot.svg +1 -0
- package/app/assets/brand/logo/wordmark-reversed.svg +1 -0
- package/app/assets/brand/logo/wordmark.svg +1 -0
- package/app/assets/css/cms-admin.css +607 -0
- package/app/components/CmsBlocks.vue +30 -0
- package/app/components/CmsCell.vue +16 -0
- package/app/components/CmsCellBadge.vue +18 -0
- package/app/components/CmsCellBlocks.vue +9 -0
- package/app/components/CmsCellBoolean.vue +12 -0
- package/app/components/CmsCellCode.vue +7 -0
- package/app/components/CmsCellColor.vue +13 -0
- package/app/components/CmsCellDate.vue +10 -0
- package/app/components/CmsCellExcerpt.vue +21 -0
- package/app/components/CmsCellGallery.vue +10 -0
- package/app/components/CmsCellGroup.vue +23 -0
- package/app/components/CmsCellNumber.vue +7 -0
- package/app/components/CmsCellRelation.vue +8 -0
- package/app/components/CmsCellText.vue +12 -0
- package/app/components/CmsCellThumb.vue +18 -0
- package/app/components/CmsConfirmDialog.vue +55 -0
- package/app/components/CmsContent.vue +103 -0
- package/app/components/CmsDayPicker.vue +44 -0
- package/app/components/CmsEmptyState.vue +35 -0
- package/app/components/CmsField.vue +111 -0
- package/app/components/CmsFieldBlocks.vue +353 -0
- package/app/components/CmsFieldBoolean.vue +8 -0
- package/app/components/CmsFieldColor.vue +42 -0
- package/app/components/CmsFieldDate.vue +131 -0
- package/app/components/CmsFieldGallery.vue +114 -0
- package/app/components/CmsFieldGroup.vue +53 -0
- package/app/components/CmsFieldMedia.vue +219 -0
- package/app/components/CmsFieldNumber.vue +11 -0
- package/app/components/CmsFieldRelationMany.vue +54 -0
- package/app/components/CmsFieldRelationOne.vue +47 -0
- package/app/components/CmsFieldRichText.vue +45 -0
- package/app/components/CmsFieldSelect.vue +41 -0
- package/app/components/CmsFieldSlug.vue +46 -0
- package/app/components/CmsFieldText.vue +75 -0
- package/app/components/CmsFormSections.vue +150 -0
- package/app/components/CmsHighlight.vue +22 -0
- package/app/components/CmsImage.vue +39 -0
- package/app/components/CmsLinkPicker.vue +122 -0
- package/app/components/CmsLinkTarget.vue +35 -0
- package/app/components/CmsListFilters.vue +107 -0
- package/app/components/CmsLiveNotice.vue +64 -0
- package/app/components/CmsLoadError.vue +24 -0
- package/app/components/CmsMascot.vue +10 -0
- package/app/components/CmsMediaLibrary.vue +114 -0
- package/app/components/CmsMediaPreview.vue +34 -0
- package/app/components/CmsMediaThumb.vue +22 -0
- package/app/components/CmsMoment.vue +42 -0
- package/app/components/CmsNav.vue +39 -0
- package/app/components/CmsPage.vue +86 -0
- package/app/components/CmsPasswordInput.vue +22 -0
- package/app/components/CmsPresence.vue +29 -0
- package/app/components/CmsPreviewPanel.vue +131 -0
- package/app/components/CmsPublishReview.vue +102 -0
- package/app/components/CmsRevisions.vue +195 -0
- package/app/components/CmsRichTextEditor.vue +290 -0
- package/app/components/CmsSearch.vue +99 -0
- package/app/components/CmsSection.vue +20 -0
- package/app/components/CmsSingletonForm.vue +283 -0
- package/app/components/CmsStatusBadge.vue +21 -0
- package/app/components/CmsTime.vue +16 -0
- package/app/components/CmsTranslationRef.vue +27 -0
- package/app/components/CmsTreeList.vue +453 -0
- package/app/components/CmsUnsavedText.vue +34 -0
- package/app/components/CmsWordmark.vue +10 -0
- package/app/composables/useCmsAdminHead.ts +18 -0
- package/app/composables/useCmsCollab.ts +165 -0
- package/app/composables/useCmsConfirm.ts +39 -0
- package/app/composables/useCmsEntryActions.ts +75 -0
- package/app/composables/useCmsFocus.ts +13 -0
- package/app/composables/useCmsForm.ts +273 -0
- package/app/composables/useCmsI18n.ts +185 -0
- package/app/composables/useCmsLinkTargets.ts +84 -0
- package/app/composables/useCmsLive.ts +199 -0
- package/app/composables/useCmsSearch.ts +62 -0
- package/app/composables/useCmsSeo.ts +99 -0
- package/app/composables/useCmsSignedIn.ts +24 -0
- package/app/composables/useCmsUiLocale.ts +24 -0
- package/app/i18n/cs.ts +781 -0
- package/app/i18n/de.ts +781 -0
- package/app/i18n/en.ts +782 -0
- package/app/i18n/types.ts +22 -0
- package/app/layouts/admin.vue +224 -0
- package/app/layouts/cms-auth.vue +37 -0
- package/app/middleware/cms-api-not-a-page.global.ts +10 -0
- package/app/middleware/cms-auth.global.ts +16 -0
- package/app/pages/admin/[entity]/[id].vue +1109 -0
- package/app/pages/admin/[entity]/index.vue +733 -0
- package/app/pages/admin/account.vue +117 -0
- package/app/pages/admin/forgot.vue +50 -0
- package/app/pages/admin/index.vue +184 -0
- package/app/pages/admin/invite/[token].vue +73 -0
- package/app/pages/admin/login.vue +84 -0
- package/app/pages/admin/media.vue +494 -0
- package/app/pages/admin/privacy.vue +193 -0
- package/app/pages/admin/reset/[token].vue +52 -0
- package/app/pages/admin/setup.vue +87 -0
- package/app/pages/admin/styleguide.vue +261 -0
- package/app/pages/admin/team.vue +258 -0
- package/app/plugins/cmsLivePreview.client.ts +20 -0
- package/app/plugins/cmsSignedOut.client.ts +31 -0
- package/app/utils/cmsBlockType.ts +11 -0
- package/app/utils/cmsBrand.ts +38 -0
- package/app/utils/cmsDiff.ts +83 -0
- package/app/utils/cmsFetch.ts +7 -0
- package/app/utils/cmsFocusInvalid.ts +22 -0
- package/app/utils/cmsIssues.ts +128 -0
- package/app/utils/cmsJson.ts +28 -0
- package/app/utils/cmsMedia.ts +63 -0
- package/app/utils/cmsSections.ts +154 -0
- package/app/utils/cmsTime.ts +41 -0
- package/cli/backup.ts +713 -0
- package/cli/breaking.ts +174 -0
- package/cli/content-migrate.ts +239 -0
- package/cli/db.ts +86 -0
- package/cli/export.ts +336 -0
- package/cli/generate.ts +146 -0
- package/cli/import.ts +643 -0
- package/cli/index.ts +140 -0
- package/cli/links-convert.ts +291 -0
- package/cli/seed-engine.ts +705 -0
- package/cli/seed.ts +339 -0
- package/cli/status.ts +49 -0
- package/cli/tar.ts +304 -0
- package/cli/transfer.ts +677 -0
- package/cli/up.ts +27 -0
- package/cli/upgrade.ts +60 -0
- package/cli/versions.ts +60 -0
- package/forms/components/CmsForm.vue +186 -0
- package/forms/index.ts +203 -0
- package/forms/messages.ts +104 -0
- package/forms/retention.ts +48 -0
- package/forms/server/form.get.ts +12 -0
- package/forms/server/form.post.ts +109 -0
- package/forms/server/formSettings.ts +12 -0
- package/forms/server/forms.ts +127 -0
- package/module.ts +373 -0
- package/nuxt.config.ts +43 -0
- package/package.json +99 -3
- package/server/api/cms/[entity]/[id]/revisions/[rev].get.ts +19 -0
- package/server/api/cms/[entity]/[id]/revisions/index.get.ts +14 -0
- package/server/api/cms/[entity]/[id].delete.ts +52 -0
- package/server/api/cms/[entity]/[id].get.ts +21 -0
- package/server/api/cms/[entity]/[id].patch.ts +116 -0
- package/server/api/cms/[entity]/_export.get.ts +69 -0
- package/server/api/cms/[entity]/_move.post.ts +81 -0
- package/server/api/cms/[entity]/_order.post.ts +49 -0
- package/server/api/cms/[entity]/_tree.get.ts +41 -0
- package/server/api/cms/[entity]/index.get.ts +62 -0
- package/server/api/cms/[entity]/index.post.ts +38 -0
- package/server/api/cms/[entity]/options.get.ts +55 -0
- package/server/api/cms/_auth/accept.post.ts +33 -0
- package/server/api/cms/_auth/forgot.post.ts +39 -0
- package/server/api/cms/_auth/invite/[token].get.ts +18 -0
- package/server/api/cms/_auth/login.post.ts +42 -0
- package/server/api/cms/_auth/logout.post.ts +7 -0
- package/server/api/cms/_auth/me.get.ts +5 -0
- package/server/api/cms/_auth/me.patch.ts +32 -0
- package/server/api/cms/_auth/password.post.ts +29 -0
- package/server/api/cms/_auth/reset.post.ts +34 -0
- package/server/api/cms/_auth/setup.post.ts +46 -0
- package/server/api/cms/_auth/status.get.ts +18 -0
- package/server/api/cms/_collab/session.get.ts +30 -0
- package/server/api/cms/_collab/socket.ts +51 -0
- package/server/api/cms/_collab/unsaved.delete.ts +16 -0
- package/server/api/cms/_graph.get.ts +20 -0
- package/server/api/cms/_links/resolve.post.ts +17 -0
- package/server/api/cms/_links.get.ts +81 -0
- package/server/api/cms/_live.ts +30 -0
- package/server/api/cms/_media/[id]/usage.get.ts +14 -0
- package/server/api/cms/_media/[id].delete.ts +29 -0
- package/server/api/cms/_media/[id].get.ts +13 -0
- package/server/api/cms/_media/[id].patch.ts +64 -0
- package/server/api/cms/_media/exists.post.ts +15 -0
- package/server/api/cms/_media/img/[id]/[file].get.ts +42 -0
- package/server/api/cms/_media/index.get.ts +44 -0
- package/server/api/cms/_media/index.post.ts +147 -0
- package/server/api/cms/_media/raw/[...key].get.ts +85 -0
- package/server/api/cms/_media/raw/[...key].head.ts +2 -0
- package/server/api/cms/_overview.get.ts +87 -0
- package/server/api/cms/_preview.post.ts +17 -0
- package/server/api/cms/_privacy/delete.post.ts +14 -0
- package/server/api/cms/_privacy/export.post.ts +25 -0
- package/server/api/cms/_privacy/lookup.post.ts +27 -0
- package/server/api/cms/_search.get.ts +17 -0
- package/server/api/cms/_singleton/[name].get.ts +19 -0
- package/server/api/cms/_singleton/[name].put.ts +76 -0
- package/server/api/cms/_users/[id]/resend.post.ts +25 -0
- package/server/api/cms/_users/[id].delete.ts +21 -0
- package/server/api/cms/_users/[id].patch.ts +45 -0
- package/server/api/cms/_users/index.get.ts +28 -0
- package/server/api/cms/_users/index.post.ts +39 -0
- package/server/api/content/[entity]/[slug].get.ts +74 -0
- package/server/api/content/[entity]/index.get.ts +100 -0
- package/server/api/content/_global/[name].get.ts +23 -0
- package/server/api/content/_search.get.ts +28 -0
- package/server/api/content/_sitemap.get.ts +8 -0
- package/server/api/content/_tree/[entity].get.ts +31 -0
- package/server/api/content-types.ts.get.ts +17 -0
- package/server/api/health/live.get.ts +10 -0
- package/server/api/health/ready.get.ts +21 -0
- package/server/api/openapi.get.ts +48 -0
- package/server/api/openapi.json.get.ts +32 -0
- package/server/db/driver.ts +8 -0
- package/server/mail/mailer.ts +43 -0
- package/server/middleware/cms-0-headers.ts +37 -0
- package/server/middleware/cms-0-migrate-gate.ts +14 -0
- package/server/middleware/cms-csrf.ts +28 -0
- package/server/middleware/cms-limits.ts +20 -0
- package/server/middleware/cms-redirects.ts +21 -0
- package/server/middleware/cms-session.ts +41 -0
- package/server/middleware/cms-z-plugin-access.ts +15 -0
- package/server/plugins/cms-0-config-check.ts +35 -0
- package/server/plugins/cms-changes.ts +53 -0
- package/server/plugins/cms-content-etag.ts +21 -0
- package/server/plugins/cms-errors.ts +45 -0
- package/server/plugins/cms-migrate.ts +5 -0
- package/server/plugins/cms-plugins.ts +17 -0
- package/server/plugins/cms-search.ts +12 -0
- package/server/plugins/cms-setup-code.ts +15 -0
- package/server/routes/sitemap.xml.get.ts +25 -0
- package/server/store/redis.ts +95 -0
- package/server/store/types.ts +21 -0
- package/server/tasks/cms/retention.ts +10 -0
- package/server/tasks/cms/scheduled.ts +10 -0
- package/server/tasks/cms/search-reindex.ts +12 -0
- package/server/utils/cmsAudit.ts +29 -0
- package/server/utils/cmsAuth.ts +143 -0
- package/server/utils/cmsBlocks.ts +47 -0
- package/server/utils/cmsChanges.ts +222 -0
- package/server/utils/cmsCollab.ts +286 -0
- package/server/utils/cmsCollabServer.ts +451 -0
- package/server/utils/cmsCollate.ts +27 -0
- package/server/utils/cmsContent.ts +376 -0
- package/server/utils/cmsCrud.ts +361 -0
- package/server/utils/cmsCsv.ts +24 -0
- package/server/utils/cmsDb.ts +23 -0
- package/server/utils/cmsDemo.ts +36 -0
- package/server/utils/cmsEmails.ts +125 -0
- package/server/utils/cmsErrors.ts +40 -0
- package/server/utils/cmsFold.ts +17 -0
- package/server/utils/cmsImageSizes.ts +51 -0
- package/server/utils/cmsJson.ts +6 -0
- package/server/utils/cmsLinkAddress.ts +50 -0
- package/server/utils/cmsLinks.ts +248 -0
- package/server/utils/cmsListQuery.ts +93 -0
- package/server/utils/cmsLive.ts +392 -0
- package/server/utils/cmsLocales.ts +96 -0
- package/server/utils/cmsMail.ts +28 -0
- package/server/utils/cmsMediaGc.ts +188 -0
- package/server/utils/cmsMediaKeys.ts +62 -0
- package/server/utils/cmsMigrate.ts +86 -0
- package/server/utils/cmsPreviewDraft.ts +72 -0
- package/server/utils/cmsPrivacy.ts +176 -0
- package/server/utils/cmsPublished.ts +57 -0
- package/server/utils/cmsRange.ts +38 -0
- package/server/utils/cmsRateLimit.ts +82 -0
- package/server/utils/cmsRedirects.ts +160 -0
- package/server/utils/cmsRetention.ts +61 -0
- package/server/utils/cmsRevisions.ts +103 -0
- package/server/utils/cmsScheduler.ts +45 -0
- package/server/utils/cmsScrub.ts +107 -0
- package/server/utils/cmsSearch.ts +354 -0
- package/server/utils/cmsSession.ts +102 -0
- package/server/utils/cmsSetupCode.ts +97 -0
- package/server/utils/cmsSitemap.ts +176 -0
- package/server/utils/cmsStorage.ts +580 -0
- package/server/utils/cmsStore.ts +109 -0
- package/server/utils/cmsTooMany.ts +9 -0
- package/server/utils/cmsTranslationWrite.ts +186 -0
- package/server/utils/cmsTree.ts +251 -0
- package/server/utils/cmsTreeAddress.ts +65 -0
- package/server/utils/cmsUpload.ts +197 -0
- package/server/utils/cmsWebhooks.ts +101 -0
- package/shared/json.ts +11 -0
- package/shared/richtext-editor.ts +56 -0
- package/shared/richtext-normalize.ts +33 -0
- package/shared/richtext-paste.ts +151 -0
- package/shared/storage-delivery.ts +53 -0
- package/src/blocks.ts +624 -0
- package/src/changes.ts +54 -0
- package/src/content-shape.ts +340 -0
- package/src/deprecate.ts +64 -0
- package/src/descriptor.ts +149 -0
- package/src/docs.ts +27 -0
- package/src/emitter.ts +94 -0
- package/src/entity.ts +624 -0
- package/src/errorReport.ts +41 -0
- package/src/fields.ts +465 -0
- package/src/i18n.ts +26 -0
- package/src/index.ts +54 -0
- package/src/linkref.ts +31 -0
- package/src/links.ts +179 -0
- package/src/locales.ts +39 -0
- package/src/media.ts +48 -0
- package/src/migrate.ts +236 -0
- package/src/openapi.ts +377 -0
- package/src/paths.ts +88 -0
- package/src/plugin.ts +505 -0
- package/src/presets.ts +230 -0
- package/src/richtext.ts +88 -0
- package/src/sdk.ts +181 -0
- package/src/search.ts +312 -0
- package/src/seed.ts +225 -0
- package/src/setupCode.ts +30 -0
- package/src/system.ts +219 -0
- package/src/tree.ts +421 -0
- package/src/upgrades.ts +137 -0
- package/starter/.env.example +10 -0
- package/starter/README.md +65 -0
- package/starter/app/app.config.ts +10 -0
- package/starter/app/app.vue +12 -0
- package/starter/app/assets/css/main.css +15 -0
- package/starter/app/components/global/BlockContact.vue +15 -0
- package/starter/app/components/global/BlockCta.vue +15 -0
- package/starter/app/components/global/BlockHero.vue +23 -0
- package/starter/app/components/global/BlockImage.vue +13 -0
- package/starter/app/components/global/BlockText.vue +12 -0
- package/starter/app/composables/useSite.ts +77 -0
- package/starter/app/error.vue +28 -0
- package/starter/app/layouts/default.vue +106 -0
- package/starter/app/lib/cms-content.ts +152 -0
- package/starter/app/pages/[...slug].vue +66 -0
- package/starter/app/pages/hledat.vue +59 -0
- package/starter/app/pages/index.vue +20 -0
- package/starter/cms.config.ts +137 -0
- package/starter/compose.yaml +15 -0
- package/starter/drizzle.config.ts +8 -0
- package/starter/gitignore.txt +8 -0
- package/starter/nuxt.config.ts +13 -0
- package/starter/package.json +38 -0
- package/starter/scripts/typecheck.mjs +38 -0
- package/starter/seed/index.ts +297 -0
- package/starter/seed/media/about.jpg +0 -0
- package/starter/seed/media/hero.jpg +0 -0
- package/starter/seed/media/logo.png +0 -0
- package/starter/seed/media/news-bread.jpg +0 -0
- package/starter/seed/media/news-morning.jpg +0 -0
- package/starter/server/db/migrations/0000_init.sql +269 -0
- package/starter/server/db/migrations/0001_page_tree.sql +5 -0
- package/starter/server/db/migrations/0002_opening_hours_per_language.sql +1 -0
- package/starter/server/db/migrations/meta/0000_snapshot.json +1890 -0
- package/starter/server/db/migrations/meta/0001_snapshot.json +1887 -0
- package/starter/server/db/migrations/meta/0002_snapshot.json +1893 -0
- package/starter/server/db/migrations/meta/_journal.json +27 -0
- package/starter/server/db/schema.ts +253 -0
- package/starter/server/plugins/sitemap.ts +11 -0
- package/starter/server/routes/robots.txt.get.ts +12 -0
- package/starter/tsconfig.json +9 -0
package/src/presets.ts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { eq } from 'drizzle-orm'
|
|
2
|
+
import { type BlockDef, defineBlock } from './blocks'
|
|
3
|
+
import { defineEntity, defineSingleton } from './entity'
|
|
4
|
+
import { f } from './fields'
|
|
5
|
+
import type { LocalizedText } from './i18n'
|
|
6
|
+
import type { PathTemplate } from './paths'
|
|
7
|
+
import { cmsDeprecated } from './deprecate'
|
|
8
|
+
import { defineForm as formsDefineForm, defineFormSettings as formsDefineFormSettings, IMPLICIT_FORMS_REQUIREMENT } from '../forms'
|
|
9
|
+
import { TREE_DEFAULT_MAX_DEPTH } from './tree'
|
|
10
|
+
|
|
11
|
+
const SEO_GROUP = { en: 'Search & sharing', cs: 'Vyhledávače a sdílení', de: 'Suche & Teilen' }
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Reusable SEO/metadata fields. Spread into an entity (or singleton):
|
|
15
|
+
* fields: { ...seo(), title: f.text({ required: true }), … }
|
|
16
|
+
* Produces metaTitle / metaDescription / ogImage columns — plain queryable fields,
|
|
17
|
+
* delivered like any other through the content API. `seo({ localized: true })` makes
|
|
18
|
+
* the title and description translatable (the sharing image stays shared);
|
|
19
|
+
* `definePages({ localized: true })` does this for its pages.
|
|
20
|
+
*/
|
|
21
|
+
export function seo(opts: { localized?: boolean } = {}) {
|
|
22
|
+
// Translatable search texts: each language gets its own title and description.
|
|
23
|
+
const text = () => (opts.localized ? f.text().optional().localized() : f.text().optional())
|
|
24
|
+
return {
|
|
25
|
+
metaTitle: text().position('sidebar').group(SEO_GROUP)
|
|
26
|
+
.label({ en: 'Search title', cs: 'Titulek pro vyhledávače', de: 'Titel für Suchmaschinen' })
|
|
27
|
+
.help({ en: 'Shown in Google results and browser tabs instead of the title. Around 60 characters.', cs: 'Zobrazí se ve výsledcích Googlu a v záložce prohlížeče místo názvu. Zhruba 60 znaků.', de: 'Erscheint statt des Titels in Google-Ergebnissen und Browser-Tabs. Etwa 60 Zeichen.' }),
|
|
28
|
+
metaDescription: text().position('sidebar').group(SEO_GROUP)
|
|
29
|
+
.label({ en: 'Search description', cs: 'Popis pro vyhledávače', de: 'Beschreibung für Suchmaschinen' })
|
|
30
|
+
.help({ en: 'The short text under the title in Google results and when shared. Around 155 characters.', cs: 'Krátký text pod titulkem ve výsledcích Googlu a při sdílení. Zhruba 155 znaků.', de: 'Kurzer Text unter dem Titel in Google-Ergebnissen und beim Teilen. Etwa 155 Zeichen.' }),
|
|
31
|
+
ogImage: f.media({ accept: 'image/*' }).optional().position('sidebar').group(SEO_GROUP)
|
|
32
|
+
.label({ en: 'Sharing image', cs: 'Obrázek pro sdílení', de: 'Bild zum Teilen' })
|
|
33
|
+
.help({ en: 'Shown when the page is shared on social networks and in messages.', cs: 'Zobrazí se při sdílení stránky na sociálních sítích a ve zprávách.', de: 'Erscheint beim Teilen der Seite in sozialen Netzwerken und Nachrichten.' }),
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A link in a menu: label, address, open in a new tab. */
|
|
38
|
+
export function linkBlock() {
|
|
39
|
+
return defineBlock({
|
|
40
|
+
label: { en: 'Link', cs: 'Odkaz', de: 'Link' },
|
|
41
|
+
description: { en: 'A page on this site or another website.', cs: 'Stránka tohoto webu nebo jiný web.', de: 'Eine Seite dieser oder einer anderen Website.' },
|
|
42
|
+
icon: 'i-lucide-link',
|
|
43
|
+
fields: {
|
|
44
|
+
label: f.text({ required: true }).label({ en: 'Label', cs: 'Text odkazu', de: 'Linktext' }),
|
|
45
|
+
url: f.text({ required: true, format: 'link' }).label({ en: 'Address', cs: 'Adresa', de: 'Adresse' })
|
|
46
|
+
.help({ en: 'A page on this site (/contact) or a full address (https://…).', cs: 'Stránka tohoto webu (/kontakt) nebo celá adresa (https://…).', de: 'Eine Seite dieser Website (/kontakt) oder eine vollständige Adresse (https://…).' }),
|
|
47
|
+
newTab: f.boolean().label({ en: 'Open in a new tab', cs: 'Otevřít v nové záložce', de: 'In neuem Tab öffnen' }),
|
|
48
|
+
sub: f.boolean({ needsPrevious: true }).label({ en: 'Under the link above', cs: 'Pod odkazem nad ním', de: 'Unter dem vorherigen Link' })
|
|
49
|
+
.help({ en: 'Shows in the dropdown of the link above it.', cs: 'Zobrazí se v rozbalovacím menu odkazu nad ním.', de: 'Erscheint im Untermenü des vorherigen Links.' }),
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A ready-made pages collection: title, URL address, status and a page built from
|
|
56
|
+
* your blocks, plus search & sharing fields, publishing and draft preview.
|
|
57
|
+
*
|
|
58
|
+
* export const Page = definePages({ blocks: { hero, text, gallery }, localized: true })
|
|
59
|
+
*
|
|
60
|
+
* `localized: true` makes the title, address and blocks translatable (needs
|
|
61
|
+
* `defineLocales`). `path` is the page's address on the website (default '/:slug'),
|
|
62
|
+
* or one per language: { cs: '/:slug', en: '/pages/:slug' }.
|
|
63
|
+
*
|
|
64
|
+
* `tree: true` lets pages sit under each other: every page gets a `parent` and a
|
|
65
|
+
* `position` among its siblings, and its address is its ancestors' address parts and its
|
|
66
|
+
* own ('/o-nas/tym', in each language its own translated parts). Moving a page moves
|
|
67
|
+
* everything below it and leaves redirects (through `defineRedirects`); deleting a page
|
|
68
|
+
* that has subpages is refused. Pages can be nested 4 levels deep, or `{ maxDepth }`
|
|
69
|
+
* (up to 10). Opt-in: a site that does not set it keeps its flat pages; turning it on
|
|
70
|
+
* later needs one migration (`tinyzoo generate`).
|
|
71
|
+
*/
|
|
72
|
+
export function definePages<const B extends Record<string, BlockDef<any>>, const T extends boolean | { maxDepth?: number } | undefined = undefined>(opts: {
|
|
73
|
+
blocks: B
|
|
74
|
+
name?: string
|
|
75
|
+
label?: LocalizedText
|
|
76
|
+
labelSingular?: LocalizedText
|
|
77
|
+
description?: LocalizedText
|
|
78
|
+
localized?: boolean
|
|
79
|
+
path?: PathTemplate
|
|
80
|
+
tree?: T
|
|
81
|
+
/** Row-level rules on top of the roles (as `defineEntity({ access })`): who may read, create, change or delete which pages. */
|
|
82
|
+
access?: Partial<Record<'read' | 'create' | 'update' | 'delete', (ctx: { user: any; table: any }) => unknown>>
|
|
83
|
+
}) {
|
|
84
|
+
const loc = <T extends { localized: () => any }>(d: T): T => (opts.localized ? d.localized() : d)
|
|
85
|
+
const path = opts.path ?? '/:slug'
|
|
86
|
+
const tree = opts.tree ? { maxDepth: typeof opts.tree === 'object' ? opts.tree.maxDepth ?? TREE_DEFAULT_MAX_DEPTH : TREE_DEFAULT_MAX_DEPTH } : null
|
|
87
|
+
// The page tree's own fields (a page points at its parent: itself, so a forward reference).
|
|
88
|
+
const self: { entity: any } = { entity: null }
|
|
89
|
+
const treeFields = (tree ? treePageFields(() => self.entity) : {}) as [T] extends [false | undefined] ? {} : ReturnType<typeof treePageFields>
|
|
90
|
+
const entity = defineEntity(opts.name ?? 'page', {
|
|
91
|
+
label: opts.label ?? { en: 'Pages', cs: 'Stránky', de: 'Seiten' },
|
|
92
|
+
labelSingular: opts.labelSingular ?? { en: 'Page', cs: 'Stránka', de: 'Seite' },
|
|
93
|
+
description: opts.description ?? { en: 'Pages of the website, built from blocks.', cs: 'Stránky webu poskládané z bloků.', de: 'Die Seiten der Website, aus Blöcken aufgebaut.' },
|
|
94
|
+
icon: 'i-lucide-file',
|
|
95
|
+
titleField: 'title',
|
|
96
|
+
admin: { list: { columns: ['title', 'status'], ...(tree ? { orderField: 'position' as any } : {}) } },
|
|
97
|
+
fields: {
|
|
98
|
+
title: loc(f.text({ required: true })).label({ en: 'Title', cs: 'Název', de: 'Titel' }),
|
|
99
|
+
// In a tree the address part only has to be unique under its parent: the whole address is checked instead.
|
|
100
|
+
slug: loc(f.slug({ from: 'title', unique: !tree })).label({ en: 'URL address', cs: 'Adresa (URL)', de: 'Adresse (URL)' }),
|
|
101
|
+
status: f.select({
|
|
102
|
+
options: ['draft', 'published'] as const,
|
|
103
|
+
default: 'draft',
|
|
104
|
+
labels: { draft: { en: 'Draft', cs: 'Koncept', de: 'Entwurf' }, published: { en: 'Published', cs: 'Zveřejněno', de: 'Veröffentlicht' } },
|
|
105
|
+
}),
|
|
106
|
+
sections: loc(f.blocks(opts.blocks)).label({ en: 'Content', cs: 'Obsah', de: 'Inhalte' }),
|
|
107
|
+
...treeFields,
|
|
108
|
+
...seo({ localized: opts.localized }),
|
|
109
|
+
},
|
|
110
|
+
publish: { field: 'status', publishedValue: 'published', draftValue: 'draft', preview: path },
|
|
111
|
+
...(opts.access ? { access: opts.access as {} } : {}),
|
|
112
|
+
content: {
|
|
113
|
+
public: true,
|
|
114
|
+
published: (t: any) => eq(t.status, 'published'),
|
|
115
|
+
slug: 'slug',
|
|
116
|
+
path,
|
|
117
|
+
},
|
|
118
|
+
...((tree ? { tree: { parent: 'parent', order: 'position', maxDepth: tree.maxDepth } } : {}) as {}),
|
|
119
|
+
})
|
|
120
|
+
self.entity = entity
|
|
121
|
+
return entity
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** `parent` and `position`, the fields `definePages({ tree: true })` adds. */
|
|
125
|
+
function treePageFields(entity: () => any) {
|
|
126
|
+
return {
|
|
127
|
+
parent: f.relation({ to: entity, kind: 'many-to-one', onDelete: 'restrict' }).position('sidebar')
|
|
128
|
+
.label({ en: 'Parent page', cs: 'Nadřazená stránka', de: 'Übergeordnete Seite' })
|
|
129
|
+
.help({ en: 'The page this one sits under. Its address continues the parent’s: /about/team.', cs: 'Stránka, pod kterou tato leží. Adresa pokračuje za adresou nadřazené: /o-nas/tym.', de: 'Die Seite, unter der diese liegt. Die Adresse setzt die der übergeordneten fort: /ueber-uns/team.' }),
|
|
130
|
+
position: f.number().withDefault(0).label({ en: 'Position', cs: 'Pořadí', de: 'Reihenfolge' }),
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Site menus as one settings screen: each menu is an ordered list of links.
|
|
136
|
+
*
|
|
137
|
+
* export const Navigation = defineNavigation({ localized: true })
|
|
138
|
+
* // → GET /api/content/_global/navigation → { main: [{ id, type, label, url, newTab, sub }], footer: [...] }
|
|
139
|
+
*/
|
|
140
|
+
export function defineNavigation(opts: { name?: string; menus?: Record<string, LocalizedText>; localized?: boolean } = {}) {
|
|
141
|
+
const menus = opts.menus ?? {
|
|
142
|
+
main: { en: 'Main menu', cs: 'Hlavní menu', de: 'Hauptmenü' },
|
|
143
|
+
footer: { en: 'Footer menu', cs: 'Menu v patičce', de: 'Menü im Seitenfuß' },
|
|
144
|
+
}
|
|
145
|
+
const fields: Record<string, any> = {}
|
|
146
|
+
for (const [key, label] of Object.entries(menus)) {
|
|
147
|
+
// A list of links (stored type 'link', as before); a link marked `sub` belongs in
|
|
148
|
+
// the dropdown of the one above it: `cmsMenuTree()` in @tinyzoo/client nests them.
|
|
149
|
+
const field = f.list({ fields: linkBlock().fields, itemType: 'link', itemLabel: { en: 'Link', cs: 'Odkaz', de: 'Link' } }).label(label)
|
|
150
|
+
fields[key] = opts.localized ? field.localized() : field
|
|
151
|
+
}
|
|
152
|
+
return defineSingleton(opts.name ?? 'navigation', {
|
|
153
|
+
label: { en: 'Navigation', cs: 'Navigace', de: 'Navigation' },
|
|
154
|
+
description: { en: 'The menus of the website.', cs: 'Menu webu.', de: 'Die Menüs der Website.' },
|
|
155
|
+
icon: 'i-lucide-menu',
|
|
156
|
+
titleField: Object.keys(menus)[0]!,
|
|
157
|
+
fields,
|
|
158
|
+
content: { public: true },
|
|
159
|
+
} as any)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Redirects from old addresses to new ones, applied by the server to every page
|
|
164
|
+
* request (301 permanent by default, 302 temporary).
|
|
165
|
+
*
|
|
166
|
+
* export const Redirect = defineRedirects()
|
|
167
|
+
*/
|
|
168
|
+
export function defineRedirects(opts: { name?: string } = {}) {
|
|
169
|
+
const e = defineEntity(opts.name ?? 'redirect', {
|
|
170
|
+
label: { en: 'Redirects', cs: 'Přesměrování', de: 'Weiterleitungen' },
|
|
171
|
+
labelSingular: { en: 'Redirect', cs: 'Přesměrování', de: 'Weiterleitung' },
|
|
172
|
+
description: {
|
|
173
|
+
en: 'Send visitors from an old address to a new one — keeps old links and search results working.',
|
|
174
|
+
cs: 'Pošle návštěvníky ze staré adresy na novou — staré odkazy i výsledky vyhledávání dál fungují.',
|
|
175
|
+
de: 'Leitet Besucher von einer alten Adresse auf eine neue weiter. Alte Links und Suchergebnisse funktionieren weiterhin.',
|
|
176
|
+
},
|
|
177
|
+
icon: 'i-lucide-corner-down-right',
|
|
178
|
+
titleField: 'from',
|
|
179
|
+
// Applied to the website the moment it is saved: authors cannot write redirects.
|
|
180
|
+
live: true,
|
|
181
|
+
admin: { list: { columns: ['from', 'to', 'permanent'] } },
|
|
182
|
+
fields: {
|
|
183
|
+
from: f.text({ required: true, format: 'path' }).unique()
|
|
184
|
+
.label({ en: 'From', cs: 'Z adresy', de: 'Von' })
|
|
185
|
+
.help({ en: 'The old address on this site, e.g. /old-page.', cs: 'Stará adresa na tomto webu, např. /stara-stranka.', de: 'Die alte Adresse auf dieser Website, z. B. /alte-seite.' }),
|
|
186
|
+
to: f.text({ required: true, format: 'link' })
|
|
187
|
+
.label({ en: 'To', cs: 'Na adresu', de: 'Nach' })
|
|
188
|
+
.help({ en: 'Where to send visitors: /new-page or https://…', cs: 'Kam návštěvníky poslat: /nova-stranka nebo https://…', de: 'Zieladresse für Besucher: /neue-seite oder https://…' }),
|
|
189
|
+
permanent: f.boolean({ default: true })
|
|
190
|
+
.label({ en: 'Permanent', cs: 'Trvalé', de: 'Dauerhaft' })
|
|
191
|
+
.help({ en: 'Tells search engines the page moved for good (301).', cs: 'Řekne vyhledávačům, že se stránka přesunula natrvalo (301).', de: 'Teilt Suchmaschinen mit, dass die Seite dauerhaft umgezogen ist (301).' }),
|
|
192
|
+
},
|
|
193
|
+
})
|
|
194
|
+
;(e as any).preset = 'redirects'
|
|
195
|
+
return e
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ── forms: moved to the forms plugin (`tinyzoo/forms`); these keep old sites working ──
|
|
199
|
+
export { FORM_FIELD_TYPES, type FormOptions } from '../forms'
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @deprecated Import `defineForm` from `tinyzoo/forms` and register `formsPlugin()` in
|
|
203
|
+
* `export const plugins = [...]`. Still works (it registers the plugin by itself), same
|
|
204
|
+
* tables and endpoints. Removed in 0.4.
|
|
205
|
+
*/
|
|
206
|
+
export function defineForm<F extends Record<string, any>>(name: string, opts: import('../forms').FormOptions<F>) {
|
|
207
|
+
cmsDeprecated(
|
|
208
|
+
'defineForm',
|
|
209
|
+
'`defineForm()` from "tinyzoo" is replaced by `defineForm()` from "tinyzoo/forms" with `export const plugins = [formsPlugin()]` in cms.config.ts.',
|
|
210
|
+
{ removeIn: '0.4.0' },
|
|
211
|
+
)
|
|
212
|
+
const e = formsDefineForm(name, opts)
|
|
213
|
+
;(e as any).requiresPlugin = IMPLICIT_FORMS_REQUIREMENT
|
|
214
|
+
return e
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @deprecated Import `defineFormSettings` from `tinyzoo/forms` and register `formsPlugin()`.
|
|
219
|
+
* Still works (it registers the plugin by itself). Removed in 0.4.
|
|
220
|
+
*/
|
|
221
|
+
export function defineFormSettings(opts: Parameters<typeof formsDefineFormSettings>[0] = {}) {
|
|
222
|
+
cmsDeprecated(
|
|
223
|
+
'defineFormSettings',
|
|
224
|
+
'`defineFormSettings()` from "tinyzoo" is replaced by `defineFormSettings()` from "tinyzoo/forms" with `export const plugins = [formsPlugin()]` in cms.config.ts.',
|
|
225
|
+
{ removeIn: '0.4.0' },
|
|
226
|
+
)
|
|
227
|
+
const e = formsDefineFormSettings(opts)
|
|
228
|
+
;(e as any).requiresPlugin = IMPLICIT_FORMS_REQUIREMENT
|
|
229
|
+
return e
|
|
230
|
+
}
|
package/src/richtext.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { isLinkRef } from './linkref'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal ProseMirror/TipTap-style document. Stored as jsonb. Sanitized on WRITE
|
|
6
|
+
* (see richTextSchema below) AND again at render by CmsContent — defense in depth —
|
|
7
|
+
* so the doc is safe even for a consumer that renders it without CmsContent. Still:
|
|
8
|
+
* never render rich text with raw `v-html`; use a structured renderer.
|
|
9
|
+
*/
|
|
10
|
+
export type RichTextDoc = { type: 'doc', content?: unknown[] }
|
|
11
|
+
|
|
12
|
+
const SAFE_LINK_SCHEMES = new Set(['http:', 'https:', 'mailto:', 'tel:'])
|
|
13
|
+
const SAFE_IMG_SCHEMES = new Set(['http:', 'https:'])
|
|
14
|
+
// eslint-disable-next-line no-control-regex
|
|
15
|
+
const CONTROL_CHARS = /[\x00-\x1F]/
|
|
16
|
+
|
|
17
|
+
/** Scheme allowlist check. Rejects control chars (closes a validator/sink differential). */
|
|
18
|
+
function schemeAllowed(u: unknown, allowed: Set<string>): boolean {
|
|
19
|
+
const s = String(u ?? '')
|
|
20
|
+
if (CONTROL_CHARS.test(s)) return false
|
|
21
|
+
try {
|
|
22
|
+
return allowed.has(new URL(s.trim(), 'https://x.invalid').protocol)
|
|
23
|
+
} catch {
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Safe as a link target: a site path, #anchor, http(s)/mailto/tel, or a reference to
|
|
30
|
+
* an entry of this site (`cms:<entity>/<id>`, which the content API turns into the
|
|
31
|
+
* entry's address — see links.ts). No control chars or spaces.
|
|
32
|
+
*/
|
|
33
|
+
export function isSafeLink(u: unknown): boolean {
|
|
34
|
+
const s = String(u ?? '')
|
|
35
|
+
if (!s || /\s/.test(s)) return false
|
|
36
|
+
return isLinkRef(s) || schemeAllowed(s, SAFE_LINK_SCHEMES)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function sanitizeNode(node: any): void {
|
|
40
|
+
if (!node || typeof node !== 'object') return
|
|
41
|
+
// Drop link marks with an unsafe href (javascript:/data:/… → keep the text, lose the link).
|
|
42
|
+
if (Array.isArray(node.marks)) {
|
|
43
|
+
node.marks = node.marks.filter((m: any) => !(m?.type === 'link' && !(isLinkRef(m?.attrs?.href) || schemeAllowed(m?.attrs?.href, SAFE_LINK_SCHEMES))))
|
|
44
|
+
}
|
|
45
|
+
// Blank an unsafe image src (CmsContent then renders nothing for it).
|
|
46
|
+
if (node.type === 'image' && node.attrs && !schemeAllowed(node.attrs.src, SAFE_IMG_SCHEMES)) {
|
|
47
|
+
node.attrs.src = ''
|
|
48
|
+
}
|
|
49
|
+
// Clamp heading level to 1–6 (never a value that could become an odd tag).
|
|
50
|
+
if (node.type === 'heading' && node.attrs) {
|
|
51
|
+
node.attrs.level = Math.min(6, Math.max(1, Number(node.attrs.level) || 2))
|
|
52
|
+
}
|
|
53
|
+
if (Array.isArray(node.content)) for (const child of node.content) sanitizeNode(child)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Neutralize XSS-unsafe attrs in a stored doc. Mutates in place; returns the doc. */
|
|
57
|
+
export function sanitizeRichText(doc: RichTextDoc): RichTextDoc {
|
|
58
|
+
if (Array.isArray(doc?.content)) for (const node of doc.content) sanitizeNode(node)
|
|
59
|
+
return doc
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Permissive structure, but every write is sanitized via the transform.
|
|
63
|
+
export const richTextSchema = z.object({
|
|
64
|
+
type: z.literal('doc'),
|
|
65
|
+
content: z.array(z.any()).optional(),
|
|
66
|
+
}).transform(sanitizeRichText) as unknown as z.ZodType<RichTextDoc>
|
|
67
|
+
|
|
68
|
+
export const emptyDoc: RichTextDoc = { type: 'doc', content: [] }
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Changes to the stored shape of a rich-text document, for when a TipTap upgrade
|
|
72
|
+
* renames a node or an attribute. Each step takes a document and returns it in the
|
|
73
|
+
* new shape; steps run in order on every read (content API, admin, search) and in
|
|
74
|
+
* `tinyzoo content:migrate`, so they must be idempotent (renaming `oldNode` to
|
|
75
|
+
* `newNode` is; "wrap every list" is not). Empty today.
|
|
76
|
+
*
|
|
77
|
+
* richTextUpgrades.push({ id: 'tiptap-3-rename-callout', upgrade: (doc) => renameNodes(doc, 'callout', 'note') })
|
|
78
|
+
*/
|
|
79
|
+
export interface RichTextUpgrade { id: string; upgrade: (doc: RichTextDoc) => RichTextDoc }
|
|
80
|
+
export const richTextUpgrades: RichTextUpgrade[] = []
|
|
81
|
+
|
|
82
|
+
/** A stored document in the current shape. The same object when there are no steps (or it is not a document). */
|
|
83
|
+
export function upgradeRichText<T>(doc: T): T {
|
|
84
|
+
if (!richTextUpgrades.length || !doc || typeof doc !== 'object' || (doc as any).type !== 'doc') return doc
|
|
85
|
+
let out = structuredClone(doc) as unknown as RichTextDoc
|
|
86
|
+
for (const step of richTextUpgrades) out = step.upgrade(out)
|
|
87
|
+
return out as unknown as T
|
|
88
|
+
}
|
package/src/sdk.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { buildContentModel, type ContentField, type ContentFieldType, type EmbeddedShape, type RefShape } from './content-shape'
|
|
2
|
+
|
|
3
|
+
// Emit a self-contained, strictly-typed TypeScript client binding for the public
|
|
4
|
+
// content API, generated from cms.config.ts. The output declares one interface per
|
|
5
|
+
// public collection (mirroring the projected response shapes) plus a `ContentSchema`
|
|
6
|
+
// map and a pre-bound `createClient()` over the @tinyzoo/client runtime.
|
|
7
|
+
//
|
|
8
|
+
// A separate frontend (any framework) drops this one file in, `npm i @tinyzoo/client`,
|
|
9
|
+
// and gets fully-typed `cms.<collection>.list()/.get()` with zero schema coupling.
|
|
10
|
+
|
|
11
|
+
export interface SdkOptions {
|
|
12
|
+
/** Import specifier for the runtime client. Default '@tinyzoo/client'. */
|
|
13
|
+
clientModule?: string
|
|
14
|
+
/** Banner comment. */
|
|
15
|
+
banner?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function pascalRef(name: string): string {
|
|
19
|
+
return name.replace(/(^|[_-])([a-z0-9])/g, (_, __, c) => c.toUpperCase())
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** TypeScript type expression for a projected field value (without nullability). */
|
|
23
|
+
function tsType(t: ContentFieldType): string {
|
|
24
|
+
switch (t.kind) {
|
|
25
|
+
case 'scalar':
|
|
26
|
+
if (t.enumValues) return t.enumValues.map((v) => `'${v}'`).join(' | ')
|
|
27
|
+
if (t.scalar === 'integer' || t.scalar === 'number') return 'number'
|
|
28
|
+
if (t.scalar === 'boolean') return 'boolean'
|
|
29
|
+
return 'string' // string + datetime(ISO) both serialize as string
|
|
30
|
+
case 'richtext': return 'RichTextDoc'
|
|
31
|
+
case 'media': return 'CmsMedia'
|
|
32
|
+
case 'gallery': return 'CmsGalleryItem[]'
|
|
33
|
+
case 'relation-one': return t.public ? `${pascalRef(t.target)}Embedded` : `${pascalRef(t.target)}Ref`
|
|
34
|
+
case 'relation-many': return `${t.public ? `${pascalRef(t.target)}Embedded` : `${pascalRef(t.target)}Ref`}[]`
|
|
35
|
+
case 'blocks': {
|
|
36
|
+
const variants = t.blocks.map((b) => {
|
|
37
|
+
const fields = b.fields.map((f) => `${f.key}: ${tsType(f.type)}${f.nullable ? ' | null' : ''}`)
|
|
38
|
+
return `{ id: string; type: '${b.type}'${fields.length ? `; ${fields.join('; ')}` : ''} }`
|
|
39
|
+
})
|
|
40
|
+
return `Array<${variants.length ? variants.join(' | ') : 'never'}>`
|
|
41
|
+
}
|
|
42
|
+
case 'group': {
|
|
43
|
+
const fields = t.fields.map((f) => `${f.key}: ${tsType(f.type)}${f.nullable ? ' | null' : ''}`)
|
|
44
|
+
return `{ ${fields.join('; ')} }`
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function fieldLine(f: ContentField): string {
|
|
50
|
+
const value = f.type.kind === 'relation-many'
|
|
51
|
+
? (f.nullable ? `(${tsType(f.type)}) | null` : tsType(f.type))
|
|
52
|
+
: `${tsType(f.type)}${f.nullable ? ' | null' : ''}`
|
|
53
|
+
return ` ${f.key}: ${value}`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function objectInterface(name: string, fields: ContentField[], opts: { timestamps: boolean; locales?: string[] | null; paths?: boolean; tree?: boolean }): string {
|
|
57
|
+
const lines = [' id: string', ...fields.map(fieldLine)]
|
|
58
|
+
if (opts.timestamps) lines.push(' createdAt: string', ' updatedAt: string')
|
|
59
|
+
if (opts.locales) {
|
|
60
|
+
const union = opts.locales.map((l) => `'${l}'`).join(' | ')
|
|
61
|
+
lines.push(` /** The language this item is served in. */\n locale: ${union}`, ` /** Languages this item exists in (the default and every translation). */\n locales: Array<${union}>`)
|
|
62
|
+
if (opts.paths) lines.push(` /** The item's address in each language it exists in. */\n paths: Partial<Record<${union}, string>>`)
|
|
63
|
+
}
|
|
64
|
+
if (opts.tree) {
|
|
65
|
+
lines.push(
|
|
66
|
+
" /** The page's address in the language served: its ancestors' address parts and its own, language prefix included. */\n path: string | null",
|
|
67
|
+
' /** From the top of the tree down to this page (itself last): title and address of each. */\n breadcrumbs: Array<{ title: string; path: string }>',
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
return `export interface ${name} {\n${lines.join('\n')}\n}`
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function embeddedInterface(e: EmbeddedShape): string {
|
|
74
|
+
return objectInterface(`${e.pascal}Embedded`, e.fields, { timestamps: false })
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function refInterface(r: RefShape): string {
|
|
78
|
+
const titleLine = ` ${r.titleField}: ${tsType(r.titleType)}${r.titleNullable ? ' | null' : ''}`
|
|
79
|
+
return `export interface ${r.pascal}Ref {\n id: string\n${titleLine}\n}`
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function emitContentTypes(config: Record<string, any>, opts: SdkOptions = {}): string {
|
|
83
|
+
const model = buildContentModel(config)
|
|
84
|
+
const clientModule = opts.clientModule ?? '@tinyzoo/client'
|
|
85
|
+
|
|
86
|
+
const out: string[] = []
|
|
87
|
+
out.push(opts.banner ?? '// GENERATED by tinyzoo — DO NOT EDIT.')
|
|
88
|
+
out.push('// Typed client for the public content API. Regenerate with `tinyzoo client`.')
|
|
89
|
+
out.push(`import { createCmsClient, type ClientOptions, type CmsClient } from '${clientModule}'`)
|
|
90
|
+
out.push('')
|
|
91
|
+
|
|
92
|
+
// Shared primitives.
|
|
93
|
+
out.push('/** A ProseMirror/TipTap rich-text document. Render structurally — never as raw HTML. */')
|
|
94
|
+
out.push('export interface RichTextNode {')
|
|
95
|
+
out.push(' type: string')
|
|
96
|
+
out.push(' text?: string')
|
|
97
|
+
out.push(' content?: RichTextNode[]')
|
|
98
|
+
out.push(' marks?: { type: string, attrs?: Record<string, unknown> }[]')
|
|
99
|
+
out.push(' attrs?: Record<string, unknown>')
|
|
100
|
+
out.push(' [k: string]: unknown')
|
|
101
|
+
out.push('}')
|
|
102
|
+
out.push('export interface RichTextDoc {')
|
|
103
|
+
out.push(" type: 'doc'")
|
|
104
|
+
out.push(' content?: RichTextNode[]')
|
|
105
|
+
out.push('}')
|
|
106
|
+
out.push('')
|
|
107
|
+
out.push('/** A populated media field. */')
|
|
108
|
+
out.push('export interface CmsMedia {')
|
|
109
|
+
out.push(' id: string')
|
|
110
|
+
out.push(' url: string')
|
|
111
|
+
out.push(' width: number | null')
|
|
112
|
+
out.push(' height: number | null')
|
|
113
|
+
out.push(' alt: string | null')
|
|
114
|
+
out.push(' mime: string')
|
|
115
|
+
out.push(' /** Focal point in percent (0–100) of width and height: keep it in view when cropping. */')
|
|
116
|
+
out.push(' focal: { x: number; y: number } | null')
|
|
117
|
+
out.push('}')
|
|
118
|
+
out.push('')
|
|
119
|
+
out.push('/** One item of a gallery field: the file, and its caption. */')
|
|
120
|
+
out.push('export interface CmsGalleryItem extends CmsMedia {')
|
|
121
|
+
out.push(' caption: string | null')
|
|
122
|
+
out.push('}')
|
|
123
|
+
out.push('')
|
|
124
|
+
|
|
125
|
+
// Embedded + ref shapes (nested populated targets).
|
|
126
|
+
if (model.embedded.length || model.refs.length) {
|
|
127
|
+
out.push('// ── nested (populated) projections ─────────────────────────────────────────────')
|
|
128
|
+
for (const e of model.embedded) out.push(embeddedInterface(e))
|
|
129
|
+
for (const r of model.refs) out.push(refInterface(r))
|
|
130
|
+
out.push('')
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Top-level collection items.
|
|
134
|
+
out.push('// ── collection items ────────────────────────────────────────────────────────────')
|
|
135
|
+
for (const e of model.entities) out.push(objectInterface(e.pascal, e.fields, { timestamps: true, locales: e.locales, paths: e.paths, tree: e.tree }))
|
|
136
|
+
out.push('')
|
|
137
|
+
|
|
138
|
+
// Globals (singletons).
|
|
139
|
+
if (model.globals.length) {
|
|
140
|
+
out.push('// ── globals ─────────────────────────────────────────────────────────────────────')
|
|
141
|
+
for (const g of model.globals) out.push(objectInterface(g.pascal, g.fields, { timestamps: true, locales: g.locales }))
|
|
142
|
+
out.push('')
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Per-collection filter types.
|
|
146
|
+
out.push('// ── query types ─────────────────────────────────────────────────────────────────')
|
|
147
|
+
for (const e of model.entities) {
|
|
148
|
+
const filterLines = e.filters.map((f) => {
|
|
149
|
+
const t = f.value === 'boolean' ? 'boolean' : f.value === 'datetime' ? 'string | Date' : f.enumValues ? f.enumValues.map((v) => `'${v}'`).join(' | ') : 'string'
|
|
150
|
+
const key = /^[A-Za-z_$][\w$]*$/.test(f.key) ? f.key : `'${f.key}'`
|
|
151
|
+
const doc = f.value === 'datetime' ? ` /** ${f.key.endsWith('.from') ? 'On or after' : 'On or before'} this date or time. */\n` : ''
|
|
152
|
+
return `${doc} ${key}?: ${t}`
|
|
153
|
+
})
|
|
154
|
+
out.push(`export interface ${e.pascal}Filters {${filterLines.length ? `\n${filterLines.join('\n')}\n` : ''}}`)
|
|
155
|
+
}
|
|
156
|
+
out.push('')
|
|
157
|
+
|
|
158
|
+
// The schema map consumed by the runtime client. A `type` alias (not `interface`)
|
|
159
|
+
// so it satisfies the runtime's `Record<string, CollectionSpec>` constraint.
|
|
160
|
+
out.push('/** Maps each collection to its item / sort keys / filters. */')
|
|
161
|
+
out.push('export type ContentSchema = {')
|
|
162
|
+
for (const e of model.entities) {
|
|
163
|
+
const sort = e.sortKeys.map((k) => `'${k}'`).join(' | ')
|
|
164
|
+
out.push(` ${e.name}: { item: ${e.pascal}, sort: ${sort}, filters: ${e.pascal}Filters${e.tree ? ', tree: true' : ''} }`)
|
|
165
|
+
}
|
|
166
|
+
out.push('}')
|
|
167
|
+
out.push('')
|
|
168
|
+
|
|
169
|
+
out.push('/** Maps each global to its object (`cms.global(name)`). */')
|
|
170
|
+
out.push(`export type GlobalSchema = {${model.globals.length ? `\n${model.globals.map((g) => ` ${g.name}: ${g.pascal}`).join('\n')}\n` : ''}}`)
|
|
171
|
+
out.push('')
|
|
172
|
+
|
|
173
|
+
// Pre-bound, fully-typed client factory.
|
|
174
|
+
out.push('/** Create a typed client for this CMS. `baseUrl` is the CMS origin. */')
|
|
175
|
+
out.push('export function createClient(options: ClientOptions): CmsClient<ContentSchema, GlobalSchema> {')
|
|
176
|
+
out.push(' return createCmsClient<ContentSchema, GlobalSchema>(options)')
|
|
177
|
+
out.push('}')
|
|
178
|
+
out.push('')
|
|
179
|
+
|
|
180
|
+
return out.join('\n').replace(/\n{3,}/g, '\n\n')
|
|
181
|
+
}
|