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/cli/index.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
/**
|
|
3
|
+
* `tinyzoo` CLI — thin wrapper over drizzle-kit + the codegen sinks.
|
|
4
|
+
* tinyzoo generate → emit host db/schema.ts from cms.config.ts, then `drizzle-kit generate`;
|
|
5
|
+
* stops on migrations that lose data (--allow-drop keeps them) or may fail
|
|
6
|
+
* on existing rows (--allow-risky keeps them)
|
|
7
|
+
* tinyzoo up → apply migrations + upgrade steps to DATABASE_URL (same runner as the app's start)
|
|
8
|
+
* tinyzoo status → what DATABASE_URL has applied / has pending (exit 1 when something is pending)
|
|
9
|
+
* tinyzoo upgrade → after updating tinyzoo: check versions, generate, regenerate the client, show status
|
|
10
|
+
* tinyzoo client [out] → emit the typed @tinyzoo/client bindings (default cms-content.ts; --stdout)
|
|
11
|
+
* tinyzoo openapi [out] → emit the OpenAPI 3.1 document (default openapi.json; --stdout)
|
|
12
|
+
* tinyzoo content:migrate → rewrite stored blocks/lists/rich text to their current versions (--dry-run reports only)
|
|
13
|
+
* tinyzoo links:convert → turn stored page addresses into links that follow their page (--dry-run reports only)
|
|
14
|
+
* tinyzoo export <file> → the site's content (entries, translations, links, globals, media files)
|
|
15
|
+
* in one .tar.gz archive (--only a,b --no-media --with-revisions …)
|
|
16
|
+
* tinyzoo import <file> → put such an archive into this site (empty target; --replace, --merge,
|
|
17
|
+
* --allow-mismatch, --dry-run). Both are described in cli/export.ts / import.ts
|
|
18
|
+
* tinyzoo backup [file] → database (pg_dump) + media in one tar archive
|
|
19
|
+
* tinyzoo restore <file> → put such an archive back (--yes skips the question, --force replaces a database that has accounts)
|
|
20
|
+
* tinyzoo seed [file] → put the site's seed content (seed/index.ts, `defineSeed`) into a running site
|
|
21
|
+
* through the admin API (--url --email, password in $SEED_PASSWORD; --dry-run, --reset)
|
|
22
|
+
* tinyzoo init <dir> → a new website with the CMS inside (the starter: pages, news,
|
|
23
|
+
* menus, a contact form, cs/en), ready for `pnpm install`
|
|
24
|
+
* Run from the host app root (cwd = host). Designed to run under tsx.
|
|
25
|
+
*/
|
|
26
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
|
|
27
|
+
import { basename, dirname, join, resolve } from 'node:path'
|
|
28
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
29
|
+
import { buildOpenApiDocument, emitContentTypes, emitSchema } from '../src/index'
|
|
30
|
+
import { askYesNo, drizzleKitRunner, generateMigration } from './generate'
|
|
31
|
+
import { status } from './status'
|
|
32
|
+
import { up } from './up'
|
|
33
|
+
import { upgrade } from './upgrade'
|
|
34
|
+
import { runExport } from './export'
|
|
35
|
+
import { runImport } from './import'
|
|
36
|
+
import { reportFailure } from './transfer'
|
|
37
|
+
|
|
38
|
+
const cmd = process.argv[2]
|
|
39
|
+
const cwd = process.cwd()
|
|
40
|
+
const configPath = resolve(cwd, 'cms.config.ts')
|
|
41
|
+
const schemaOut = resolve(cwd, 'server/db/schema.ts')
|
|
42
|
+
|
|
43
|
+
function loadConfig() {
|
|
44
|
+
return import(pathToFileURL(configPath).href)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Positional output path arg (first non-flag after the command), or a default. */
|
|
48
|
+
function outArg(fallback: string): string {
|
|
49
|
+
const arg = process.argv[3]
|
|
50
|
+
return arg && !arg.startsWith('-') ? resolve(cwd, arg) : resolve(cwd, fallback)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Emit schema.ts, then let drizzle-kit write the migration (returns an exit code). */
|
|
54
|
+
async function generate(): Promise<number> {
|
|
55
|
+
const config = await loadConfig()
|
|
56
|
+
const src = emitSchema(config)
|
|
57
|
+
mkdirSync(dirname(schemaOut), { recursive: true })
|
|
58
|
+
writeFileSync(schemaOut, src)
|
|
59
|
+
console.log(`✓ emitted ${schemaOut}`)
|
|
60
|
+
const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY)
|
|
61
|
+
return generateMigration({
|
|
62
|
+
migrationsDir: resolve(cwd, 'server/db/migrations'),
|
|
63
|
+
allowDrop: process.argv.includes('--allow-drop'),
|
|
64
|
+
allowRisky: process.argv.includes('--allow-risky'),
|
|
65
|
+
interactive,
|
|
66
|
+
runDrizzleKit: drizzleKitRunner(cwd, interactive),
|
|
67
|
+
confirm: askYesNo,
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function client() {
|
|
72
|
+
const src = emitContentTypes(await loadConfig())
|
|
73
|
+
if (process.argv.includes('--stdout')) { process.stdout.write(src); return }
|
|
74
|
+
const out = outArg('cms-content.ts')
|
|
75
|
+
mkdirSync(dirname(out), { recursive: true })
|
|
76
|
+
writeFileSync(out, src)
|
|
77
|
+
console.log(`✓ emitted ${out}`)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function openapi() {
|
|
81
|
+
const doc = buildOpenApiDocument(await loadConfig(), { title: 'Content API' })
|
|
82
|
+
const json = JSON.stringify(doc, null, 2) + '\n'
|
|
83
|
+
if (process.argv.includes('--stdout')) { process.stdout.write(json); return }
|
|
84
|
+
const out = outArg('openapi.json')
|
|
85
|
+
mkdirSync(dirname(out), { recursive: true })
|
|
86
|
+
writeFileSync(out, json)
|
|
87
|
+
console.log(`✓ emitted ${out}`)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Copy the starter into a new folder, with versions instead of workspace links. */
|
|
91
|
+
function init() {
|
|
92
|
+
const target = process.argv[3]
|
|
93
|
+
if (!target || target.startsWith('-')) {
|
|
94
|
+
console.error('usage: tinyzoo init <folder>')
|
|
95
|
+
process.exit(1)
|
|
96
|
+
}
|
|
97
|
+
const dest = resolve(cwd, target)
|
|
98
|
+
if (existsSync(dest) && readdirSync(dest).length) {
|
|
99
|
+
console.error(`✗ ${dest} exists and is not empty`)
|
|
100
|
+
process.exit(1)
|
|
101
|
+
}
|
|
102
|
+
const pkgDir = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
103
|
+
const starter = join(pkgDir, 'starter')
|
|
104
|
+
const skip = new Set(['node_modules', '.nuxt', '.output', '.env', '.cms-uploads', '.cms-mail', '.data'])
|
|
105
|
+
cpSync(starter, dest, { recursive: true, filter: (src) => !skip.has(basename(src)) })
|
|
106
|
+
renameSync(join(dest, 'gitignore.txt'), join(dest, '.gitignore'))
|
|
107
|
+
const version = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8')).version as string
|
|
108
|
+
const pkgPath = join(dest, 'package.json')
|
|
109
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
|
|
110
|
+
pkg.name = basename(dest).toLowerCase().replace(/[^a-z0-9-]+/g, '-')
|
|
111
|
+
for (const deps of [pkg.dependencies, pkg.devDependencies]) {
|
|
112
|
+
for (const [name, v] of Object.entries(deps ?? {})) if (String(v).startsWith('workspace:')) deps[name] = `^${version}`
|
|
113
|
+
}
|
|
114
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
|
|
115
|
+
console.log(`✓ created ${dest}\n\n cd ${target}\n pnpm install\n cp .env.example .env\n docker compose up -d\n pnpm db:migrate\n pnpm dev → http://localhost:3000/admin\n\n Demo content (Czech and English), while \`pnpm dev\` runs in another terminal:\n SEED_EMAIL=you@example.com SEED_PASSWORD='a long password' pnpm seed\n (creates the first administrator with those details; run it again any time, it changes nothing twice)\n`)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
switch (cmd) {
|
|
119
|
+
case 'init': init(); break
|
|
120
|
+
case 'generate': process.exit(await generate()); break
|
|
121
|
+
case 'up': process.exit(await up(cwd)); break
|
|
122
|
+
case 'status': process.exit(await status(cwd)); break
|
|
123
|
+
case 'upgrade': process.exit(await upgrade(cwd, resolve(dirname(fileURLToPath(import.meta.url)), '..'), { generate })); break
|
|
124
|
+
case 'client': await client(); break
|
|
125
|
+
case 'openapi': await openapi(); break
|
|
126
|
+
case 'content:migrate': await (await import('./content-migrate')).contentMigrateCommand(await loadConfig(), process.argv.slice(3)); break
|
|
127
|
+
case 'links:convert': await (await import('./links-convert')).linksConvertCommand(await loadConfig(), process.argv.slice(3)); break
|
|
128
|
+
case 'export': await runExport(process.argv.slice(3)).catch(reportFailure); break
|
|
129
|
+
case 'import': await runImport(process.argv.slice(3)).then(() => {}, reportFailure); break
|
|
130
|
+
case 'seed': await (await import('./seed')).seedCommand(await loadConfig(), process.argv.slice(3)).catch(reportFailure); break
|
|
131
|
+
case 'backup': await (await import('./backup')).backup(process.argv.slice(3)); break
|
|
132
|
+
case 'restore': await (await import('./backup')).restore(process.argv.slice(3)); break
|
|
133
|
+
default:
|
|
134
|
+
console.error('usage: tinyzoo <init|generate|up|status|upgrade|client|openapi|content:migrate|export|import|seed|links:convert|backup|restore> [out] [--stdout] [--allow-drop] [--allow-risky] [--dry-run]\n'
|
|
135
|
+
+ ' tinyzoo export <file.tar.gz> [--only a,b] [--no-media] [--with-revisions] [--with-submissions] [--force]\n'
|
|
136
|
+
+ ' tinyzoo import <file.tar.gz> [--replace [--yes] | --merge] [--allow-mismatch] [--dry-run]\n'
|
|
137
|
+
+ ' tinyzoo seed [file] [--url u] [--email e] [--dry-run] [--reset [--yes]] (password: $SEED_PASSWORD)\n'
|
|
138
|
+
+ ' tinyzoo backup [file] · tinyzoo restore <file> [--yes] [--force]')
|
|
139
|
+
process.exit(1)
|
|
140
|
+
}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tinyzoo links:convert` — turn links stored as addresses into links that follow
|
|
3
|
+
* their target.
|
|
4
|
+
*
|
|
5
|
+
* A link an editor picked in an older version is stored as the page's address
|
|
6
|
+
* (`/o-nas`), so renaming the page breaks it. Links picked now are stored as a
|
|
7
|
+
* reference (`cms:page/<id>`) and follow the page. Nothing is converted for you: this
|
|
8
|
+
* command walks every link field and every link in rich text (entries, their
|
|
9
|
+
* translations, globals, menus; lists, blocks and groups inside them) and turns a
|
|
10
|
+
* stored address into a reference when it is exactly the current address of ONE entry
|
|
11
|
+
* that is live now, in the language the link is served in (the entry's own row, and the
|
|
12
|
+
* fields of its default-language content, are served in the default language; a
|
|
13
|
+
* translation, in its language). A reference is served as the target's address in the
|
|
14
|
+
* language asked for, so converting any other match would change what visitors get.
|
|
15
|
+
* Everything else is left as typed and reported: addresses no entry has, addresses that
|
|
16
|
+
* are another language's address of an entry, addresses of entries not published (a
|
|
17
|
+
* reference to a draft serves nothing), addresses two entries share, addresses with a
|
|
18
|
+
* `?query` or `#anchor`. External links, `mailto:`, `tel:` and references are not
|
|
19
|
+
* touched. Saved versions in History are not rewritten.
|
|
20
|
+
*
|
|
21
|
+
* tinyzoo links:convert [--dry-run] [--batch <n>]
|
|
22
|
+
*
|
|
23
|
+
* Connects with DATABASE_URL (or NUXT_CMS_DATABASE_URL) from the environment or the site's .env. Run from the host app root.
|
|
24
|
+
* Entries' `updatedAt` is not touched (this is not an edit), so a cache that keys on
|
|
25
|
+
* it, and the website's, must be purged by hand once the command has run.
|
|
26
|
+
*/
|
|
27
|
+
import { and, asc, eq, gt, inArray, or } from 'drizzle-orm'
|
|
28
|
+
import { drizzle } from 'drizzle-orm/node-postgres'
|
|
29
|
+
import pg from 'pg'
|
|
30
|
+
import { databaseUrl } from './db'
|
|
31
|
+
import { buildRegistry, linkFieldsOf, linkRef, mapRowLinks, propOf, type CmsEntity, type CmsRegistry } from '../src/index'
|
|
32
|
+
import { entryAddresses, addressKeys, isLinkable } from '../server/utils/cmsLinkAddress'
|
|
33
|
+
import { publishedCond } from '../server/utils/cmsPublished'
|
|
34
|
+
|
|
35
|
+
export type LinkSource = 'entries' | 'translations'
|
|
36
|
+
export type UnmatchedReason = 'no-page' | 'several-pages' | 'anchor-or-query' | 'other-language' | 'draft'
|
|
37
|
+
|
|
38
|
+
export interface ConvertFieldReport {
|
|
39
|
+
entity: string
|
|
40
|
+
field: string
|
|
41
|
+
source: LinkSource
|
|
42
|
+
/** Rows that hold this field with a value. */
|
|
43
|
+
scanned: number
|
|
44
|
+
/** Links turned (or, in a dry run, that would be turned) into references. */
|
|
45
|
+
converted: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface UnmatchedLink {
|
|
49
|
+
/** The stored address. */
|
|
50
|
+
value: string
|
|
51
|
+
reason: UnmatchedReason
|
|
52
|
+
/** How many times it is stored. */
|
|
53
|
+
count: number
|
|
54
|
+
/** Where, for the first few: `page 3f2a… · sections.0.url`. */
|
|
55
|
+
places: string[]
|
|
56
|
+
/** For `several-pages`: the entries that have this address. For `other-language`: the entries and the languages it is an address in. */
|
|
57
|
+
candidates?: string[]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ConvertReport {
|
|
61
|
+
dryRun: boolean
|
|
62
|
+
fields: ConvertFieldReport[]
|
|
63
|
+
unmatched: UnmatchedLink[]
|
|
64
|
+
rowsScanned: number
|
|
65
|
+
rowsChanged: number
|
|
66
|
+
linksConverted: number
|
|
67
|
+
/** Blocks stored at an older version than their definition: left alone (run `content:migrate` first). */
|
|
68
|
+
skippedStaleBlocks: number
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ConvertOptions {
|
|
72
|
+
dryRun?: boolean
|
|
73
|
+
batchSize?: number
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** An address as compared: decoded, no trailing slash (except "/"). */
|
|
77
|
+
export function normalizeAddress(address: string): string {
|
|
78
|
+
let p = address
|
|
79
|
+
try { p = decodeURI(p) } catch { /* compare as stored */ }
|
|
80
|
+
return p.length > 1 && p.endsWith('/') ? p.slice(0, -1) : p
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** An entry's address in one language. */
|
|
84
|
+
export interface AddressHit {
|
|
85
|
+
/** `cms:<entity>/<id>`. */
|
|
86
|
+
ref: string
|
|
87
|
+
/** The language this is the address in (null: the site has no languages). */
|
|
88
|
+
locale: string | null
|
|
89
|
+
/** Can visitors reach the entry now (published, scheduling and a page tree's ancestors included)? */
|
|
90
|
+
live: boolean
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The entries of every linkable collection by their addresses, per language: `normalized address → who has it, in which language`. */
|
|
94
|
+
export async function addressIndex(db: any, reg: CmsRegistry, batch = 500): Promise<Map<string, AddressHit[]>> {
|
|
95
|
+
const index = new Map<string, AddressHit[]>()
|
|
96
|
+
for (const e of reg.entities) {
|
|
97
|
+
if (!isLinkable(e)) continue
|
|
98
|
+
const cols: Record<string, any> = { id: e.table.id }
|
|
99
|
+
for (const k of addressKeys(e)) cols[k] = (e.table as any)[k]
|
|
100
|
+
const published = publishedCond(e)
|
|
101
|
+
for (let after: string | null = null; ;) {
|
|
102
|
+
const rows: any[] = await db.select(cols).from(e.table).where(after ? gt(e.table.id, after) : undefined).orderBy(asc(e.table.id)).limit(batch)
|
|
103
|
+
if (!rows.length) break
|
|
104
|
+
const live = published
|
|
105
|
+
? new Set<string>((await db.select({ id: e.table.id }).from(e.table).where(and(inArray(e.table.id, rows.map((r) => r.id)), published)) as any[]).map((r) => r.id))
|
|
106
|
+
: null
|
|
107
|
+
for (const locale of reg.locales?.locales ?? [null]) {
|
|
108
|
+
for (const [id, address] of await entryAddresses(db, reg, e, rows, locale)) {
|
|
109
|
+
if (!address) continue
|
|
110
|
+
const key = normalizeAddress(address)
|
|
111
|
+
const hits = index.get(key) ?? []
|
|
112
|
+
hits.push({ ref: linkRef(e.name, id), locale, live: !live || live.has(id) })
|
|
113
|
+
index.set(key, hits)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
after = rows[rows.length - 1].id
|
|
117
|
+
if (rows.length < batch) break
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return index
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** A stored value that is an address on this site (`/…`), not an external link or a protocol-relative `//host`. */
|
|
124
|
+
const isSiteAddress = (v: string) => v.startsWith('/') && !v.startsWith('//')
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Walk everything and turn stored addresses into references. `db` is a drizzle
|
|
128
|
+
* node-postgres database; every table is reached through the registry.
|
|
129
|
+
*/
|
|
130
|
+
export async function convertLinks(db: any, reg: CmsRegistry, opts: ConvertOptions = {}): Promise<ConvertReport> {
|
|
131
|
+
const dryRun = !!opts.dryRun
|
|
132
|
+
const batch = Math.max(1, opts.batchSize ?? 200)
|
|
133
|
+
const report: ConvertReport = { dryRun, fields: [], unmatched: [], rowsScanned: 0, rowsChanged: 0, linksConverted: 0, skippedStaleBlocks: 0 }
|
|
134
|
+
const index = await addressIndex(db, reg)
|
|
135
|
+
const counters = new Map<string, ConvertFieldReport>()
|
|
136
|
+
const unmatched = new Map<string, UnmatchedLink>()
|
|
137
|
+
const label = (e: CmsEntity, id: string, locale: string | null) => `${e.name} ${id}${locale ? ` [${locale}]` : ''}`
|
|
138
|
+
|
|
139
|
+
/** The links of one row's values turned into references; the changed values by field key. */
|
|
140
|
+
function convertValues(e: CmsEntity, source: LinkSource, id: string, locale: string | null, fields: CmsEntity['fields'], values: Record<string, any>): Record<string, any> {
|
|
141
|
+
for (const key of Object.keys(fields)) {
|
|
142
|
+
if (values[key] == null) continue
|
|
143
|
+
const k = `${e.name}\u0000${source}\u0000${key}`
|
|
144
|
+
let c = counters.get(k)
|
|
145
|
+
if (!c) counters.set(k, c = { entity: e.name, field: key, source, scanned: 0, converted: 0 })
|
|
146
|
+
c.scanned++
|
|
147
|
+
}
|
|
148
|
+
let current = ''
|
|
149
|
+
// The language this row's links are served in: a translation's own, the default language for an entry's own row.
|
|
150
|
+
const served = locale ?? reg.locales?.default ?? null
|
|
151
|
+
const convert = (stored: string): string | undefined => {
|
|
152
|
+
if (!isSiteAddress(stored)) return undefined
|
|
153
|
+
const note = (reason: UnmatchedReason, candidates?: string[]) => {
|
|
154
|
+
const u = unmatched.get(`${reason}\u0000${stored}`) ?? { value: stored, reason, count: 0, places: [], candidates }
|
|
155
|
+
u.count++
|
|
156
|
+
if (u.places.length < 3) u.places.push(`${label(e, id, locale)} · ${current}`)
|
|
157
|
+
unmatched.set(`${reason}\u0000${stored}`, u)
|
|
158
|
+
return undefined
|
|
159
|
+
}
|
|
160
|
+
if (/[?#]/.test(stored)) return note('anchor-or-query')
|
|
161
|
+
const hits = index.get(normalizeAddress(stored))
|
|
162
|
+
if (!hits?.length) return note('no-page')
|
|
163
|
+
// Served in this language: a reference gives the target's address in the language asked for.
|
|
164
|
+
const here = hits.filter((h) => h.locale === served)
|
|
165
|
+
if (!here.length) return note('other-language', [...new Set(hits.map((h) => `${h.ref}${h.locale ? ` [${h.locale}]` : ''}`))].sort())
|
|
166
|
+
const refs = [...new Set(here.map((h) => h.ref))].sort()
|
|
167
|
+
if (refs.length > 1) return note('several-pages', refs)
|
|
168
|
+
// A reference to an entry that is not published serves nothing: the address typed now keeps working.
|
|
169
|
+
if (!here.some((h) => h.live)) return note('draft', refs)
|
|
170
|
+
report.linksConverted++
|
|
171
|
+
const c = counters.get(`${e.name}\u0000${source}\u0000${current}`)
|
|
172
|
+
if (c) c.converted++
|
|
173
|
+
return refs[0]
|
|
174
|
+
}
|
|
175
|
+
const changed: Record<string, any> = {}
|
|
176
|
+
for (const key of Object.keys(fields)) {
|
|
177
|
+
if (values[key] == null) continue
|
|
178
|
+
current = key
|
|
179
|
+
const one = mapRowLinks({ [key]: fields[key] as any }, values, { field: convert, mark: convert, skipStale: true, onStale: () => { report.skippedStaleBlocks++ } })
|
|
180
|
+
if (key in one) changed[key] = one[key]
|
|
181
|
+
}
|
|
182
|
+
return changed
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
for (const e of reg.entities) {
|
|
186
|
+
const own = Object.fromEntries(linkFieldsOf(e.fields as any)) as CmsEntity['fields']
|
|
187
|
+
if (!Object.keys(own).length) continue
|
|
188
|
+
|
|
189
|
+
let after: string | null = null
|
|
190
|
+
for (;;) {
|
|
191
|
+
const done = await db.transaction(async (tx: any) => {
|
|
192
|
+
const rows: any[] = await tx.select().from(e.table).where(after ? gt(e.table.id, after) : undefined).orderBy(asc(e.table.id)).limit(batch).for('update')
|
|
193
|
+
for (const row of rows) {
|
|
194
|
+
report.rowsScanned++
|
|
195
|
+
const changed = convertValues(e, 'entries', row.id, null, own, row)
|
|
196
|
+
if (!Object.keys(changed).length) continue
|
|
197
|
+
report.rowsChanged++
|
|
198
|
+
if (!dryRun) await tx.update(e.table).set(Object.fromEntries(Object.entries(changed).map(([k, v]) => [propOf(k, e.fields[k]!), v]))).where(eq(e.table.id, row.id))
|
|
199
|
+
}
|
|
200
|
+
after = rows.length ? rows[rows.length - 1].id : after
|
|
201
|
+
return rows.length < batch
|
|
202
|
+
})
|
|
203
|
+
if (done) break
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const t = e.localesTable
|
|
207
|
+
const translated = Object.fromEntries(Object.entries(own).filter(([k]) => e.localized.includes(k))) as CmsEntity['fields']
|
|
208
|
+
if (t && Object.keys(translated).length) {
|
|
209
|
+
type Cursor = { parentId: string; locale: string }
|
|
210
|
+
let last = null as Cursor | null
|
|
211
|
+
for (;;) {
|
|
212
|
+
const cursor = last as Cursor | null
|
|
213
|
+
const done = await db.transaction(async (tx: any) => {
|
|
214
|
+
const cond = cursor ? or(gt(t.parentId, cursor.parentId), and(eq(t.parentId, cursor.parentId), gt(t.locale, cursor.locale))) : undefined
|
|
215
|
+
const rows: any[] = await tx.select().from(t).where(cond).orderBy(asc(t.parentId), asc(t.locale)).limit(batch).for('update')
|
|
216
|
+
for (const row of rows) {
|
|
217
|
+
report.rowsScanned++
|
|
218
|
+
const changed = convertValues(e, 'translations', row.parentId, row.locale, translated, row)
|
|
219
|
+
if (!Object.keys(changed).length) continue
|
|
220
|
+
report.rowsChanged++
|
|
221
|
+
if (!dryRun) await tx.update(t).set(changed).where(and(eq(t.parentId, row.parentId), eq(t.locale, row.locale)))
|
|
222
|
+
}
|
|
223
|
+
if (rows.length) last = { parentId: rows[rows.length - 1].parentId, locale: rows[rows.length - 1].locale }
|
|
224
|
+
return rows.length < batch
|
|
225
|
+
})
|
|
226
|
+
if (done) break
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
report.fields = [...counters.values()].filter((c) => c.scanned > 0)
|
|
232
|
+
report.unmatched = [...unmatched.values()].sort((a, b) => a.reason.localeCompare(b.reason) || b.count - a.count || a.value.localeCompare(b.value))
|
|
233
|
+
return report
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const REASONS: Record<UnmatchedReason, string> = {
|
|
237
|
+
'no-page': 'no entry has this address (left as it is: a fixed page of the site — the home page, a list — is not an entry and stays as typed)',
|
|
238
|
+
'several-pages': 'more than one entry has this address (left as it is)',
|
|
239
|
+
'other-language': 'this is an entry’s address in another language than the one this link is served in (left as it is: a reference would serve the address of the language asked for)',
|
|
240
|
+
'draft': 'the entry is not published (left as it is: a reference to it serves nothing until it is)',
|
|
241
|
+
'anchor-or-query': 'has a #anchor or ?query, which a reference cannot carry (left as it is)',
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** The report as the lines the command prints. */
|
|
245
|
+
export function formatConvertReport(r: ConvertReport): string[] {
|
|
246
|
+
const lines: string[] = []
|
|
247
|
+
const rows = r.fields.filter((f) => f.converted > 0)
|
|
248
|
+
for (const f of rows) {
|
|
249
|
+
lines.push(`${`${f.entity}.${f.field}`.padEnd(34)} ${f.source.padEnd(12)} ${String(f.converted).padStart(5)} link${f.converted === 1 ? '' : 's'} ${r.dryRun ? 'would be converted' : 'converted'}`)
|
|
250
|
+
}
|
|
251
|
+
if (!rows.length) lines.push('No stored address matches exactly one entry: nothing to convert.')
|
|
252
|
+
if (r.unmatched.length) {
|
|
253
|
+
lines.push('', `${r.unmatched.length} stored address${r.unmatched.length === 1 ? '' : 'es'} could not be converted:`)
|
|
254
|
+
for (const u of r.unmatched) {
|
|
255
|
+
lines.push(` ${u.value} — ${REASONS[u.reason]}${u.count > 1 ? `, stored ${u.count} times` : ''}`)
|
|
256
|
+
for (const p of u.places) lines.push(` ${p}`)
|
|
257
|
+
if (u.candidates) lines.push(` ${u.reason === 'several-pages' ? 'could be' : 'is the address of'}: ${u.candidates.join(', ')}`)
|
|
258
|
+
}
|
|
259
|
+
lines.push('', 'Fixed pages of the site (the home page, a list, a page the website draws by itself) are not entries: there is nothing for a link to follow, so those addresses can stay as typed. For a link that should follow an entry, pick the entry again in the link picker (or give the entries different addresses). A link to another language’s address, or to an entry that is not published yet, is left as typed on purpose: pick the page once it can be reached.')
|
|
260
|
+
}
|
|
261
|
+
if (r.skippedStaleBlocks) lines.push('', `${r.skippedStaleBlocks} block${r.skippedStaleBlocks === 1 ? ' is' : 's are'} stored at an older version than the code: left alone. Run \`tinyzoo content:migrate\` first, then this command again.`)
|
|
262
|
+
lines.push('', `${r.rowsScanned} rows read, ${r.linksConverted} link${r.linksConverted === 1 ? '' : 's'} ${r.dryRun ? 'would be converted (dry run: nothing was written)' : `converted in ${r.rowsChanged} row${r.rowsChanged === 1 ? '' : 's'}`}.`)
|
|
263
|
+
if (!r.dryRun && r.linksConverted) lines.push('Purge the website’s cache: the content API answers have changed.')
|
|
264
|
+
return lines
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** The command: connect, convert, print. */
|
|
268
|
+
export async function linksConvertCommand(config: Record<string, any>, args: string[]): Promise<void> {
|
|
269
|
+
const dryRun = args.includes('--dry-run')
|
|
270
|
+
const bi = args.indexOf('--batch')
|
|
271
|
+
const batchSize = bi >= 0 ? Number(args[bi + 1]) : undefined
|
|
272
|
+
if (bi >= 0 && !(Number.isInteger(batchSize) && batchSize! > 0)) {
|
|
273
|
+
console.error('usage: tinyzoo links:convert [--dry-run] [--batch <n>]')
|
|
274
|
+
process.exit(1)
|
|
275
|
+
}
|
|
276
|
+
let url: string
|
|
277
|
+
try { url = databaseUrl(process.cwd()) }
|
|
278
|
+
catch (err) {
|
|
279
|
+
console.error(`✗ ${(err as Error).message}`)
|
|
280
|
+
process.exit(1)
|
|
281
|
+
}
|
|
282
|
+
const reg = buildRegistry(config)
|
|
283
|
+
const pool = new pg.Pool({ connectionString: url, max: 2 })
|
|
284
|
+
try {
|
|
285
|
+
const report = await convertLinks(drizzle(pool, { schema: reg.schema }), reg, { dryRun, batchSize })
|
|
286
|
+
for (const line of formatConvertReport(report)) console.log(line)
|
|
287
|
+
}
|
|
288
|
+
finally {
|
|
289
|
+
await pool.end()
|
|
290
|
+
}
|
|
291
|
+
}
|