qarpeo 0.1.35 → 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/README.md +114 -26
- package/dist/apps/cms.d.ts +4 -0
- package/dist/apps/comments.d.ts +4 -0
- package/dist/apps/payments.d.ts +4 -0
- package/dist/apps/store.d.ts +4 -0
- package/dist/chunks/auth-schema.mjs +169 -30
- package/dist/chunks/tools.mjs +1680 -0
- package/dist/cli/index.mjs +1256 -221
- package/dist/core/aliases.d.ts +5 -0
- package/dist/core/context.d.ts +10 -0
- package/dist/core/cross-drive.d.ts +2 -0
- package/dist/core/d1-migrate.d.ts +4 -0
- package/dist/core/devtools.d.ts +4 -0
- package/dist/core/nitro.d.ts +4 -0
- package/dist/core/schema.d.ts +4 -0
- package/dist/core/server-utils.d.ts +4 -0
- package/dist/core/wrangler.d.ts +4 -0
- package/dist/dev/wrangler.d.ts +1 -0
- package/dist/fate/index.d.ts +8 -8
- package/dist/features/agents.d.ts +4 -0
- package/dist/features/auth.d.ts +4 -0
- package/dist/features/bots.d.ts +4 -0
- package/dist/features/fate.d.ts +4 -0
- package/dist/features/mail.d.ts +4 -0
- package/dist/features/mcp.d.ts +4 -0
- package/dist/features/multitenant.d.ts +4 -0
- package/dist/features/notifications.d.ts +4 -0
- package/dist/features/realtime.d.ts +4 -0
- package/dist/module.d.ts +10 -2
- package/dist/module.mjs +6313 -5118
- package/dist/primitives/ai.d.ts +4 -0
- package/dist/primitives/analytics.d.ts +4 -0
- package/dist/primitives/blob.d.ts +4 -0
- package/dist/primitives/browser.d.ts +4 -0
- package/dist/primitives/cache.d.ts +4 -0
- package/dist/primitives/d1.d.ts +4 -0
- package/dist/primitives/do.d.ts +4 -0
- package/dist/primitives/email.d.ts +4 -0
- package/dist/primitives/hyperdrive.d.ts +4 -0
- package/dist/primitives/kv.d.ts +4 -0
- package/dist/primitives/queue.d.ts +4 -0
- package/dist/primitives/ratelimit.d.ts +4 -0
- package/dist/primitives/vectorize.d.ts +4 -0
- package/dist/primitives/workflows.d.ts +4 -0
- package/dist/runtime/ai.d.ts +3 -3
- package/dist/runtime/ai.mjs +8 -1
- package/dist/runtime/app/components/RealtimeCursors.vue +2 -2
- package/dist/runtime/app/composables/ai.d.ts +56 -29
- package/dist/runtime/app/composables/analytics.d.ts +26 -106
- package/dist/runtime/app/composables/api-tokens.d.ts +31 -34
- package/dist/runtime/app/composables/auth.d.ts +147 -51
- package/dist/runtime/app/composables/auth.mjs +0 -7
- package/dist/runtime/app/composables/chat.d.ts +38 -35
- package/dist/runtime/app/composables/cms-preview.d.ts +30 -25
- package/dist/runtime/app/composables/cms.d.ts +57 -282
- package/dist/runtime/app/composables/cms.mjs +0 -35
- package/dist/runtime/app/composables/comments.d.ts +32 -5
- package/dist/runtime/app/composables/comments.mjs +29 -1
- package/dist/runtime/app/composables/docs-version.d.ts +25 -28
- package/dist/runtime/app/composables/impersonation.d.ts +22 -5
- package/dist/runtime/app/composables/organization.d.ts +38 -91
- package/dist/runtime/app/composables/passkey.d.ts +22 -6
- package/dist/runtime/app/composables/passwordless.d.ts +24 -7
- package/dist/runtime/app/composables/payments.d.ts +50 -34
- package/dist/runtime/app/composables/payments.mjs +1 -0
- package/dist/runtime/app/composables/sse.d.ts +76 -0
- package/dist/runtime/app/composables/sse.mjs +152 -0
- package/dist/runtime/app/composables/storage.d.ts +53 -65
- package/dist/runtime/app/composables/storage.mjs +17 -0
- package/dist/runtime/app/composables/store.d.ts +198 -0
- package/dist/runtime/app/composables/store.mjs +414 -0
- package/dist/runtime/app/composables/tenant.d.ts +31 -72
- package/dist/runtime/app/composables/turnstile.d.ts +16 -3
- package/dist/runtime/app/composables/two-factor.d.ts +23 -6
- package/dist/runtime/app/pages/devtools/notifications.vue +30 -27
- package/dist/runtime/app/pages/devtools/realtime.vue +19 -31
- package/dist/runtime/app/pages/devtools.vue +0 -7
- package/dist/runtime/auth.d.ts +9 -9
- package/dist/runtime/blob.d.ts +10 -1
- package/dist/runtime/blob.mjs +83 -0
- package/dist/runtime/cache.d.ts +48 -0
- package/dist/runtime/cache.mjs +92 -0
- package/dist/runtime/comments.d.ts +4 -0
- package/dist/runtime/comments.mjs +2 -0
- package/dist/runtime/db.d.ts +21 -1
- package/dist/runtime/db.mjs +54 -0
- package/dist/runtime/drizzle.d.ts +4 -2
- package/dist/runtime/drizzle.mjs +68 -1
- package/dist/runtime/durable-object.d.ts +2 -0
- package/dist/runtime/durable-object.mjs +2 -0
- package/dist/runtime/email.d.ts +1 -1
- package/dist/runtime/email.mjs +1 -1
- package/dist/runtime/kv.mjs +50 -1
- package/dist/runtime/mcp.d.ts +2 -0
- package/dist/runtime/mcp.mjs +2 -0
- package/dist/runtime/queue.d.ts +12 -2
- package/dist/runtime/queue.mjs +19 -1
- package/dist/runtime/ratelimit.d.ts +1 -0
- package/dist/runtime/ratelimit.mjs +7 -0
- package/dist/runtime/schema.d.ts +313 -0
- package/dist/runtime/schema.mjs +259 -0
- package/dist/runtime/server/db/cms-schema.d.ts +1225 -171
- package/dist/runtime/server/db/cms-schema.mjs +69 -70
- package/dist/runtime/server/db/store-schema.d.ts +4344 -0
- package/dist/runtime/server/db/store-schema.mjs +266 -0
- package/dist/runtime/server/durable-objects/agent.mjs +35 -0
- package/dist/runtime/server/durable-objects/room.mjs +0 -1
- package/dist/runtime/server/middleware/ratelimit.mjs +10 -8
- package/dist/runtime/server/plugins/comments.d.ts +7 -0
- package/dist/runtime/server/plugins/comments.mjs +7 -0
- package/dist/runtime/server/plugins/email-inbound.d.ts +5 -0
- package/dist/runtime/server/plugins/email-inbound.mjs +17 -0
- package/dist/runtime/server/plugins/store.d.ts +7 -0
- package/dist/runtime/server/plugins/store.mjs +7 -0
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +2 -2
- package/dist/runtime/server/routes/atom.xml.get.mjs +3 -1
- package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +13 -2
- package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +9 -3
- package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +11 -3
- package/dist/runtime/server/routes/auth/account.delete.mjs +2 -1
- package/dist/runtime/server/routes/auth/audit-logs.get.mjs +1 -1
- package/dist/runtime/server/routes/auth/magic-link/send.post.d.ts +1 -9
- package/dist/runtime/server/routes/auth/magic-link/send.post.mjs +8 -0
- package/dist/runtime/server/routes/auth/organization/sso/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/auth/organization/sso/index.get.mjs +1 -1
- package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/otp/send.post.d.ts +1 -9
- package/dist/runtime/server/routes/auth/otp/send.post.mjs +8 -0
- package/dist/runtime/server/routes/auth/sso/login.get.mjs +3 -3
- package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +1 -1
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +2 -2
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +2 -2
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/[collection]/atom.xml.get.mjs +3 -1
- package/dist/runtime/server/routes/cms/[collection]/feed.xml.get.mjs +3 -1
- package/dist/runtime/server/routes/cms/bookmarks/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/cms/bookmarks/check.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/bookmarks/index.get.mjs +1 -1
- package/dist/runtime/server/routes/cms/bookmarks/index.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/deploy.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/export.post.mjs +4 -3
- package/dist/runtime/server/routes/cms/search.get.mjs +7 -5
- package/dist/runtime/server/routes/cms/sync.post.mjs +2 -1
- package/dist/runtime/server/routes/comments/[id]/react.post.mjs +1 -2
- package/dist/runtime/server/routes/comments/[id]/report.post.d.ts +1 -1
- package/dist/runtime/server/routes/comments/[id]/report.post.mjs +0 -2
- package/dist/runtime/server/routes/comments/[id].delete.mjs +8 -4
- package/dist/runtime/server/routes/comments/[id].get.d.ts +1 -1
- package/dist/runtime/server/routes/comments/[id].get.mjs +1 -2
- package/dist/runtime/server/routes/comments/[id].patch.d.ts +1 -1
- package/dist/runtime/server/routes/comments/[id].patch.mjs +6 -3
- package/dist/runtime/server/routes/comments/batch.post.d.ts +2 -0
- package/dist/runtime/server/routes/comments/batch.post.mjs +33 -0
- package/dist/runtime/server/routes/comments/index.get.d.ts +1 -1
- package/dist/runtime/server/routes/comments/index.get.mjs +6 -4
- package/dist/runtime/server/routes/comments/index.post.d.ts +1 -1
- package/dist/runtime/server/routes/comments/index.post.mjs +6 -2
- package/dist/runtime/server/routes/feed.xml.get.mjs +3 -1
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +3 -1
- package/dist/runtime/server/routes/storage/presigned-r2.post.d.ts +17 -0
- package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +29 -0
- package/dist/runtime/server/routes/store/cart/index.delete.d.ts +6 -0
- package/dist/runtime/server/routes/store/cart/index.delete.mjs +11 -0
- package/dist/runtime/server/routes/store/cart/index.get.d.ts +5 -0
- package/dist/runtime/server/routes/store/cart/index.get.mjs +14 -0
- package/dist/runtime/server/routes/store/cart/items/[id].delete.d.ts +6 -0
- package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +25 -0
- package/dist/runtime/server/routes/store/cart/items/[id].patch.d.ts +6 -0
- package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +29 -0
- package/dist/runtime/server/routes/store/cart/items.post.d.ts +6 -0
- package/dist/runtime/server/routes/store/cart/items.post.mjs +36 -0
- package/dist/runtime/server/routes/store/categories/index.get.d.ts +2 -0
- package/dist/runtime/server/routes/store/categories/index.get.mjs +8 -0
- package/dist/runtime/server/routes/store/checkout.post.d.ts +6 -0
- package/dist/runtime/server/routes/store/checkout.post.mjs +21 -0
- package/dist/runtime/server/routes/store/coupons/apply.post.d.ts +7 -0
- package/dist/runtime/server/routes/store/coupons/apply.post.mjs +18 -0
- package/dist/runtime/server/routes/store/currencies.get.d.ts +15 -0
- package/dist/runtime/server/routes/store/currencies.get.mjs +13 -0
- package/dist/runtime/server/routes/store/orders/[id].get.d.ts +2 -0
- package/dist/runtime/server/routes/store/orders/[id].get.mjs +26 -0
- package/dist/runtime/server/routes/store/orders/download/[token].get.d.ts +7 -0
- package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +57 -0
- package/dist/runtime/server/routes/store/orders/index.get.d.ts +5 -0
- package/dist/runtime/server/routes/store/orders/index.get.mjs +30 -0
- package/dist/runtime/server/routes/store/products/[slug].get.d.ts +2 -0
- package/dist/runtime/server/routes/store/products/[slug].get.mjs +18 -0
- package/dist/runtime/server/routes/store/products/index.get.d.ts +5 -0
- package/dist/runtime/server/routes/store/products/index.get.mjs +33 -0
- package/dist/runtime/server/routes/store/tax/calculate.post.d.ts +9 -0
- package/dist/runtime/server/routes/store/tax/calculate.post.mjs +18 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +14 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +14 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +24 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +6 -0
- package/dist/runtime/server/utils/ai.d.ts +146 -21
- package/dist/runtime/server/utils/ai.mjs +406 -11
- package/dist/runtime/server/utils/analytics-query.d.ts +13 -58
- package/dist/runtime/server/utils/audit.d.ts +5 -4
- package/dist/runtime/server/utils/audit.mjs +25 -14
- package/dist/runtime/server/utils/auth.d.ts +29 -12
- package/dist/runtime/server/utils/auth.mjs +88 -70
- package/dist/runtime/server/utils/bots.d.ts +20 -4
- package/dist/runtime/server/utils/bots.mjs +7 -3
- package/dist/runtime/server/utils/browser-utils.d.ts +23 -23
- package/dist/runtime/server/utils/cache.d.ts +3 -3
- package/dist/runtime/server/utils/cms/collections.d.ts +23 -0
- package/dist/runtime/server/utils/cms/collections.mjs +143 -0
- package/dist/runtime/server/utils/cms/common.d.ts +9 -0
- package/dist/runtime/server/utils/cms/common.mjs +28 -0
- package/dist/runtime/server/utils/cms/git.mjs +2 -2
- package/dist/runtime/server/utils/cms/navigation.d.ts +46 -0
- package/dist/runtime/server/utils/cms/navigation.mjs +683 -0
- package/dist/runtime/server/utils/cms/preview.d.ts +11 -0
- package/dist/runtime/server/utils/cms/preview.mjs +50 -0
- package/dist/runtime/server/utils/cms/search.d.ts +1 -1
- package/dist/runtime/server/utils/cms/search.mjs +11 -7
- package/dist/runtime/server/utils/cms/sync.d.ts +34 -0
- package/dist/runtime/server/utils/cms/sync.mjs +1082 -0
- package/dist/runtime/server/utils/cms/taxonomy.d.ts +103 -0
- package/dist/runtime/server/utils/cms/taxonomy.mjs +348 -0
- package/dist/runtime/server/utils/cms.d.ts +13 -249
- package/dist/runtime/server/utils/cms.mjs +108 -2350
- package/dist/runtime/server/utils/comments-filter.d.ts +45 -0
- package/dist/runtime/server/utils/comments-filter.mjs +541 -0
- package/dist/runtime/server/utils/comments.d.ts +71 -0
- package/dist/runtime/server/utils/comments.mjs +137 -61
- package/dist/runtime/server/utils/config.d.ts +4 -3
- package/dist/runtime/server/utils/config.mjs +7 -6
- package/dist/runtime/server/utils/context.d.ts +14 -0
- package/dist/runtime/server/utils/context.mjs +2 -2
- package/dist/runtime/server/utils/crypto.d.ts +44 -5
- package/dist/runtime/server/utils/crypto.mjs +18 -0
- package/dist/runtime/server/utils/domains.mjs +9 -5
- package/dist/runtime/server/utils/drizzle.d.ts +35 -3
- package/dist/runtime/server/utils/drizzle.mjs +115 -6
- package/dist/runtime/server/utils/durable-object.d.ts +106 -0
- package/dist/runtime/server/utils/durable-object.mjs +628 -0
- package/dist/runtime/server/utils/email-inbound.d.ts +29 -0
- package/dist/runtime/server/utils/email-inbound.mjs +76 -0
- package/dist/runtime/server/utils/impersonation.d.ts +32 -2
- package/dist/runtime/server/utils/impersonation.mjs +16 -13
- package/dist/runtime/server/utils/lock.d.ts +71 -0
- package/dist/runtime/server/utils/lock.mjs +139 -0
- package/dist/runtime/server/utils/mail-suppression.mjs +7 -7
- package/dist/runtime/server/utils/mail.d.ts +30 -19
- package/dist/runtime/server/utils/mcp.d.ts +44 -0
- package/dist/runtime/server/utils/mcp.mjs +308 -0
- package/dist/runtime/server/utils/notifications.d.ts +72 -7
- package/dist/runtime/server/utils/notifications.mjs +67 -55
- package/dist/runtime/server/utils/oauth.d.ts +27 -4
- package/dist/runtime/server/utils/organization.d.ts +63 -7
- package/dist/runtime/server/utils/organization.mjs +26 -21
- package/dist/runtime/server/utils/passwordless.d.ts +62 -33
- package/dist/runtime/server/utils/payments.d.ts +51 -12
- package/dist/runtime/server/utils/payments.mjs +472 -282
- package/dist/runtime/server/utils/queue.d.ts +106 -13
- package/dist/runtime/server/utils/queue.mjs +313 -28
- package/dist/runtime/server/utils/rag.d.ts +42 -14
- package/dist/runtime/server/utils/rag.mjs +169 -4
- package/dist/runtime/server/utils/ratelimit.d.ts +34 -5
- package/dist/runtime/server/utils/ratelimit.mjs +95 -14
- package/dist/runtime/server/utils/realtime.d.ts +68 -52
- package/dist/runtime/server/utils/scheduled-task.d.ts +42 -1
- package/dist/runtime/server/utils/scheduled-task.mjs +29 -0
- package/dist/runtime/server/utils/schema-fallback.d.ts +1 -1
- package/dist/runtime/server/utils/schema-fallback.mjs +1 -1
- package/dist/runtime/server/utils/session.d.ts +84 -10
- package/dist/runtime/server/utils/session.mjs +12 -10
- package/dist/runtime/server/utils/sse.d.ts +75 -0
- package/dist/runtime/server/utils/sse.mjs +147 -0
- package/dist/runtime/server/utils/sso.d.ts +1 -1
- package/dist/runtime/server/utils/storage.d.ts +53 -4
- package/dist/runtime/server/utils/storage.mjs +15 -11
- package/dist/runtime/server/utils/store-localization.d.ts +51 -0
- package/dist/runtime/server/utils/store-localization.mjs +417 -0
- package/dist/runtime/server/utils/store.d.ts +207 -0
- package/dist/runtime/server/utils/store.mjs +2227 -0
- package/dist/runtime/server/utils/table-names.d.ts +51 -0
- package/dist/runtime/server/utils/table-names.mjs +69 -0
- package/dist/runtime/server/utils/tenant.d.ts +26 -2
- package/dist/runtime/server/utils/tenant.mjs +16 -12
- package/dist/runtime/server/utils/tools-registry-fallback.d.ts +1 -0
- package/dist/runtime/server/utils/tools-registry-fallback.mjs +1 -0
- package/dist/runtime/server/utils/totp.d.ts +45 -2
- package/dist/runtime/server/utils/tracker.d.ts +10 -11
- package/dist/runtime/server/utils/turnstile.d.ts +16 -1
- package/dist/runtime/server/utils/workflows.d.ts +92 -0
- package/dist/runtime/server/utils/workflows.mjs +299 -0
- package/dist/runtime/server.d.ts +8 -1
- package/dist/runtime/server.mjs +8 -5
- package/dist/runtime/service.d.ts +10 -10
- package/dist/runtime/storage.d.ts +1 -0
- package/dist/runtime/storage.mjs +1 -0
- package/dist/runtime/store.d.ts +4 -0
- package/dist/runtime/store.mjs +2 -0
- package/dist/runtime/test-utils.d.ts +11 -10
- package/dist/runtime/test-utils.mjs +64 -4
- package/dist/runtime/types/ai.d.ts +21 -2
- package/dist/runtime/types/d1.d.ts +17 -0
- package/dist/runtime/types/drizzle.d.ts +2 -2
- package/dist/runtime/types/durable-object.d.ts +62 -2
- package/dist/runtime/types/email.d.ts +46 -0
- package/dist/runtime/types/imports.d.ts +6 -1
- package/dist/runtime/types/index.d.ts +58 -0
- package/dist/runtime/types/index.mjs +3 -0
- package/dist/runtime/types/mcp.d.ts +83 -0
- package/dist/runtime/types/mcp.mjs +0 -0
- package/dist/runtime/types/queue.d.ts +36 -0
- package/dist/runtime/types/r2.d.ts +41 -0
- package/dist/runtime/types/store.d.ts +313 -0
- package/dist/runtime/types/store.mjs +0 -0
- package/dist/runtime/types/workflows.d.ts +98 -0
- package/dist/runtime/types/workflows.mjs +0 -0
- package/dist/runtime/workflows.d.ts +5 -0
- package/dist/runtime/workflows.mjs +2 -0
- package/dist/types/ai.d.ts +721 -0
- package/dist/types/cms.d.ts +710 -0
- package/dist/types.d.ts +406 -1288
- package/dist/utils/auth-schema.d.ts +3 -2
- package/dist/utils/bots.d.ts +20 -0
- package/dist/utils/comments-schema.d.ts +5 -4
- package/dist/utils/drizzle.d.ts +83 -3
- package/dist/utils/durable-objects.d.ts +10 -0
- package/dist/utils/email-inbound.d.ts +10 -0
- package/dist/utils/local-db.d.ts +1 -3
- package/dist/utils/mcp.d.ts +24 -0
- package/dist/utils/notifications-schema.d.ts +5 -4
- package/dist/utils/payments-schema.d.ts +4 -3
- package/dist/utils/store-schema.d.ts +14 -0
- package/dist/utils/table-names.d.ts +1 -0
- package/dist/utils/tenants-schema.d.ts +4 -3
- package/dist/utils/tools.d.ts +20 -0
- package/dist/utils/workflows.d.ts +8 -0
- package/package.json +34 -4
- package/dist/chunks/wrangler.mjs +0 -897
- package/dist/runtime/app/components/AuthRegister.vue +0 -306
- package/dist/runtime/app/components/AuthSessionsList.vue +0 -137
- package/dist/runtime/app/components/AuthSignIn.vue +0 -298
- package/dist/runtime/app/components/CMSBookmarkButton.vue +0 -59
- package/dist/runtime/app/components/CMSImage.vue +0 -47
- package/dist/runtime/app/components/CMSLocaleSwitcher.vue +0 -110
- package/dist/runtime/app/components/CMSNewsletter.vue +0 -81
- package/dist/runtime/app/components/CMSPreviewBanner.vue +0 -83
- package/dist/runtime/app/components/CMSTableOfContents.vue +0 -84
- package/dist/runtime/app/components/CMSVersionBanner.vue +0 -53
- package/dist/runtime/app/components/CMSVersionSwitcher.vue +0 -140
- package/dist/runtime/app/components/Comments.vue +0 -411
- package/dist/runtime/app/components/FileUpload.vue +0 -200
- package/dist/runtime/app/components/ImpersonationBanner.vue +0 -61
- package/dist/runtime/app/components/NotificationBell.vue +0 -263
- package/dist/runtime/app/components/NotificationList.vue +0 -205
- package/dist/runtime/app/components/NotificationPrompt.vue +0 -133
- package/dist/runtime/app/components/PricingGated.vue +0 -81
- package/dist/runtime/app/components/PricingTable.vue +0 -274
- package/dist/runtime/app/components/RealtimeChat.vue +0 -164
- package/dist/runtime/app/components/RealtimePresence.vue +0 -129
- package/dist/runtime/app/components/RealtimeStatus.vue +0 -79
- package/dist/runtime/app/components/SubscriptionCard.vue +0 -207
- package/dist/runtime/app/components/UserProfile.vue +0 -558
|
@@ -0,0 +1,1082 @@
|
|
|
1
|
+
import { parse as parseYaml } from "yaml";
|
|
2
|
+
import { getKVBinding } from "../../../kv.mjs";
|
|
3
|
+
import { resolveIndexName } from "../table-names.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getCMSDb,
|
|
6
|
+
nanoid,
|
|
7
|
+
getCMSConfig,
|
|
8
|
+
computeContentHash,
|
|
9
|
+
getCMSTenantPrefix,
|
|
10
|
+
cmsCollectionTbl,
|
|
11
|
+
cmsEntryTbl,
|
|
12
|
+
cmsRevisionTbl,
|
|
13
|
+
cmsCategoryTbl,
|
|
14
|
+
cmsTagTbl,
|
|
15
|
+
cmsBookmarkTbl,
|
|
16
|
+
cmsSubscriberTbl,
|
|
17
|
+
cmsEntryFtsTbl
|
|
18
|
+
} from "./common.mjs";
|
|
19
|
+
import { processMarkdown, parseFrontmatter } from "./markdown.mjs";
|
|
20
|
+
import {
|
|
21
|
+
stripOrderPrefix,
|
|
22
|
+
isGroupSegment,
|
|
23
|
+
extractGroupTitle,
|
|
24
|
+
extractOrderPrefix,
|
|
25
|
+
computeEntryPath,
|
|
26
|
+
resolveCollectionForPath,
|
|
27
|
+
extractTOC
|
|
28
|
+
} from "./path.mjs";
|
|
29
|
+
import { registerEnsureCMSSynced } from "./search.mjs";
|
|
30
|
+
import { resolveReferenceFieldsFromFrontmatter } from "../cms.mjs";
|
|
31
|
+
let ensureCMSTablesPromise = null;
|
|
32
|
+
export async function ensureCMSTables(event) {
|
|
33
|
+
const db = getCMSDb(event);
|
|
34
|
+
if (!db) return;
|
|
35
|
+
if (!ensureCMSTablesPromise) {
|
|
36
|
+
ensureCMSTablesPromise = (async () => {
|
|
37
|
+
const colTbl = cmsCollectionTbl(event);
|
|
38
|
+
const entryTbl = cmsEntryTbl(event);
|
|
39
|
+
const revTbl = cmsRevisionTbl(event);
|
|
40
|
+
const catTbl = cmsCategoryTbl(event);
|
|
41
|
+
const tagTbl = cmsTagTbl(event);
|
|
42
|
+
const bmTbl = cmsBookmarkTbl(event);
|
|
43
|
+
const subTbl = cmsSubscriberTbl(event);
|
|
44
|
+
const ftsTbl = cmsEntryFtsTbl(event);
|
|
45
|
+
const tableStatements = [
|
|
46
|
+
`CREATE TABLE IF NOT EXISTS ${colTbl} (id TEXT PRIMARY KEY, tenant_id TEXT, name TEXT NOT NULL, description TEXT, schema_json TEXT NOT NULL DEFAULT '{}', source TEXT NOT NULL DEFAULT 'db', "order" INTEGER NOT NULL DEFAULT 0, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL);`,
|
|
47
|
+
`CREATE TABLE IF NOT EXISTS ${entryTbl} (id TEXT PRIMARY KEY, tenant_id TEXT, collection_id TEXT NOT NULL, slug TEXT NOT NULL, title TEXT NOT NULL, description TEXT, cover_image TEXT, tags TEXT, "order" INTEGER NOT NULL DEFAULT 0, content_md TEXT NOT NULL DEFAULT '', content_html TEXT NOT NULL DEFAULT '', metadata_json TEXT DEFAULT '{}', status TEXT NOT NULL DEFAULT 'draft', source TEXT NOT NULL DEFAULT 'db', path TEXT, file_path TEXT, content_hash TEXT, author_id TEXT, category_id TEXT, sub_category_id TEXT, featured INTEGER NOT NULL DEFAULT 0, view_count INTEGER NOT NULL DEFAULT 0, reading_time INTEGER, locale TEXT NOT NULL DEFAULT 'en', version TEXT NOT NULL DEFAULT 'latest', published_at INTEGER, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL);`,
|
|
48
|
+
`CREATE TABLE IF NOT EXISTS ${revTbl} (id TEXT PRIMARY KEY, entry_id TEXT NOT NULL, title TEXT NOT NULL, content_md TEXT NOT NULL, metadata_json TEXT DEFAULT '{}', author_id TEXT, created_at INTEGER NOT NULL);`,
|
|
49
|
+
`CREATE TABLE IF NOT EXISTS ${catTbl} (id TEXT PRIMARY KEY, tenant_id TEXT, name TEXT NOT NULL, slug TEXT NOT NULL, description TEXT, icon TEXT, parent_id TEXT, "order" INTEGER NOT NULL DEFAULT 0, metadata_json TEXT DEFAULT '{}', created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL);`,
|
|
50
|
+
`CREATE TABLE IF NOT EXISTS ${tagTbl} (id TEXT PRIMARY KEY, tenant_id TEXT, name TEXT NOT NULL, slug TEXT NOT NULL, description TEXT, count INTEGER NOT NULL DEFAULT 0, metadata_json TEXT DEFAULT '{}', created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL);`,
|
|
51
|
+
`CREATE TABLE IF NOT EXISTS ${bmTbl} (id TEXT PRIMARY KEY, tenant_id TEXT, user_id TEXT NOT NULL, entry_id TEXT NOT NULL, created_at INTEGER NOT NULL);`,
|
|
52
|
+
`CREATE TABLE IF NOT EXISTS ${subTbl} (id TEXT PRIMARY KEY, tenant_id TEXT, email TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'active', source TEXT DEFAULT 'website', created_at INTEGER NOT NULL);`
|
|
53
|
+
];
|
|
54
|
+
for (const sql of tableStatements) {
|
|
55
|
+
try {
|
|
56
|
+
await db.exec(sql);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.warn("[qarpeo:cms] ensureCMSTables warning on table creation:", sql, err);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const columnMigrations = [
|
|
62
|
+
// entry
|
|
63
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN tenant_id TEXT;`,
|
|
64
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN path TEXT;`,
|
|
65
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN file_path TEXT;`,
|
|
66
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN content_hash TEXT;`,
|
|
67
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN author_id TEXT;`,
|
|
68
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN category_id TEXT;`,
|
|
69
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN sub_category_id TEXT;`,
|
|
70
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN featured INTEGER NOT NULL DEFAULT 0;`,
|
|
71
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN view_count INTEGER NOT NULL DEFAULT 0;`,
|
|
72
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN reading_time INTEGER;`,
|
|
73
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN locale TEXT NOT NULL DEFAULT 'en';`,
|
|
74
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN version TEXT NOT NULL DEFAULT 'latest';`,
|
|
75
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN published_at INTEGER;`,
|
|
76
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN "order" INTEGER NOT NULL DEFAULT 0;`,
|
|
77
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN cover_image TEXT;`,
|
|
78
|
+
`ALTER TABLE ${entryTbl} ADD COLUMN tags TEXT;`,
|
|
79
|
+
// collection
|
|
80
|
+
`ALTER TABLE ${colTbl} ADD COLUMN tenant_id TEXT;`,
|
|
81
|
+
`ALTER TABLE ${colTbl} ADD COLUMN "order" INTEGER NOT NULL DEFAULT 0;`,
|
|
82
|
+
`ALTER TABLE ${colTbl} ADD COLUMN source TEXT NOT NULL DEFAULT 'db';`,
|
|
83
|
+
// category
|
|
84
|
+
`ALTER TABLE ${catTbl} ADD COLUMN tenant_id TEXT;`,
|
|
85
|
+
`ALTER TABLE ${catTbl} ADD COLUMN "order" INTEGER NOT NULL DEFAULT 0;`,
|
|
86
|
+
// tag
|
|
87
|
+
`ALTER TABLE ${tagTbl} ADD COLUMN tenant_id TEXT;`,
|
|
88
|
+
// bookmark
|
|
89
|
+
`ALTER TABLE ${bmTbl} ADD COLUMN tenant_id TEXT;`,
|
|
90
|
+
// subscriber
|
|
91
|
+
`ALTER TABLE ${subTbl} ADD COLUMN tenant_id TEXT;`
|
|
92
|
+
];
|
|
93
|
+
for (const alterSql of columnMigrations) {
|
|
94
|
+
try {
|
|
95
|
+
await db.exec(alterSql);
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const indexStatements = [
|
|
100
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "collection")} ON ${entryTbl}(collection_id);`,
|
|
101
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "tenant")} ON ${entryTbl}(tenant_id, collection_id);`,
|
|
102
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "slug")} ON ${entryTbl}(COALESCE(tenant_id,''), collection_id, slug);`,
|
|
103
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "status")} ON ${entryTbl}(status);`,
|
|
104
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "order")} ON ${entryTbl}(collection_id, "order");`,
|
|
105
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "path")} ON ${entryTbl}(collection_id, path);`,
|
|
106
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "locale")} ON ${entryTbl}(collection_id, locale);`,
|
|
107
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "path_locale")} ON ${entryTbl}(path, locale);`,
|
|
108
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "version")} ON ${entryTbl}(collection_id, version);`,
|
|
109
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "path_version")} ON ${entryTbl}(path, version);`,
|
|
110
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "published_at")} ON ${entryTbl}(published_at);`,
|
|
111
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "list")} ON ${entryTbl}(collection_id, status, published_at);`,
|
|
112
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "category")} ON ${entryTbl}(collection_id, category_id);`,
|
|
113
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(entryTbl, "featured")} ON ${entryTbl}(collection_id, featured);`,
|
|
114
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(revTbl, "entry")} ON ${revTbl}(entry_id, created_at);`,
|
|
115
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS ${resolveIndexName(catTbl, "slug")} ON ${catTbl}(COALESCE(tenant_id,''), slug);`,
|
|
116
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(catTbl, "parent")} ON ${catTbl}(parent_id);`,
|
|
117
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(catTbl, "tenant")} ON ${catTbl}(tenant_id);`,
|
|
118
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS ${resolveIndexName(tagTbl, "slug")} ON ${tagTbl}(COALESCE(tenant_id,''), slug);`,
|
|
119
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(tagTbl, "tenant")} ON ${tagTbl}(tenant_id);`,
|
|
120
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(bmTbl, "user")} ON ${bmTbl}(user_id);`,
|
|
121
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(bmTbl, "entry")} ON ${bmTbl}(entry_id);`,
|
|
122
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS ${resolveIndexName(bmTbl, "unique")} ON ${bmTbl}(COALESCE(tenant_id,''), user_id, entry_id);`,
|
|
123
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(subTbl, "email")} ON ${subTbl}(email);`,
|
|
124
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS ${resolveIndexName(subTbl, "unique_email")} ON ${subTbl}(COALESCE(tenant_id,''), email);`,
|
|
125
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(subTbl, "status")} ON ${subTbl}(status);`,
|
|
126
|
+
`CREATE INDEX IF NOT EXISTS ${resolveIndexName(subTbl, "tenant")} ON ${subTbl}(tenant_id);`
|
|
127
|
+
];
|
|
128
|
+
for (const sql of indexStatements) {
|
|
129
|
+
try {
|
|
130
|
+
await db.exec(sql);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
console.warn("[qarpeo:cms] ensureCMSTables warning on index creation:", sql, err);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
await db.exec(
|
|
137
|
+
`CREATE VIRTUAL TABLE IF NOT EXISTS ${ftsTbl} USING fts5(id UNINDEXED, slug, title, description, content_md, tags, tokenize = 'unicode61');`
|
|
138
|
+
);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
console.warn("[qarpeo:cms] ensureCMSTables FTS virtual table notice:", err);
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
await db.exec(
|
|
144
|
+
`CREATE TRIGGER IF NOT EXISTS ${entryTbl}_fts_ai AFTER INSERT ON ${entryTbl} BEGIN INSERT INTO ${ftsTbl}(id, slug, title, description, content_md, tags) VALUES (new.id, new.slug, new.title, coalesce(new.description, ''), new.content_md, coalesce(new.tags, '')); END;`
|
|
145
|
+
);
|
|
146
|
+
} catch {
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
await db.exec(
|
|
150
|
+
`CREATE TRIGGER IF NOT EXISTS ${entryTbl}_fts_ad AFTER DELETE ON ${entryTbl} BEGIN DELETE FROM ${ftsTbl} WHERE id = old.id; END;`
|
|
151
|
+
);
|
|
152
|
+
} catch {
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
await db.exec(
|
|
156
|
+
`CREATE TRIGGER IF NOT EXISTS ${entryTbl}_fts_au AFTER UPDATE ON ${entryTbl} BEGIN DELETE FROM ${ftsTbl} WHERE id = old.id; INSERT INTO ${ftsTbl}(id, slug, title, description, content_md, tags) VALUES (new.id, new.slug, new.title, coalesce(new.description, ''), new.content_md, coalesce(new.tags, '')); END;`
|
|
157
|
+
);
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
await db.exec(
|
|
162
|
+
`INSERT INTO ${ftsTbl}(id, slug, title, description, content_md, tags) SELECT e.id, e.slug, e.title, coalesce(e.description, ''), e.content_md, coalesce(e.tags, '') FROM ${entryTbl} e WHERE NOT EXISTS (SELECT 1 FROM ${ftsTbl} fts WHERE fts.id = e.id);`
|
|
163
|
+
);
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
return event;
|
|
167
|
+
})().catch((err) => {
|
|
168
|
+
ensureCMSTablesPromise = null;
|
|
169
|
+
throw err;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return ensureCMSTablesPromise;
|
|
173
|
+
}
|
|
174
|
+
let lastSyncTime = 0;
|
|
175
|
+
let syncPromise = null;
|
|
176
|
+
let hasInitialSynced = false;
|
|
177
|
+
async function _runCMSSync(event) {
|
|
178
|
+
try {
|
|
179
|
+
if (!globalThis.__QARPEO_DEV_ENV__) {
|
|
180
|
+
try {
|
|
181
|
+
const { getOrInitDevProxy } = await import("../dev-proxy.mjs");
|
|
182
|
+
const proxy = await getOrInitDevProxy();
|
|
183
|
+
if (proxy?.env) {
|
|
184
|
+
;
|
|
185
|
+
globalThis.__QARPEO_DEV_ENV__ = proxy.env;
|
|
186
|
+
}
|
|
187
|
+
} catch (proxyErr) {
|
|
188
|
+
console.warn("[qarpeo:cms] Could not init dev proxy in ensureCMSSynced:", proxyErr);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
await ensureCMSTables(event);
|
|
192
|
+
const config = getCMSConfig(event);
|
|
193
|
+
await seedCollectionsFromConfig(event, config.collections);
|
|
194
|
+
await syncLocalContentFiles(
|
|
195
|
+
event,
|
|
196
|
+
config.contentDir,
|
|
197
|
+
config.collections,
|
|
198
|
+
config.sources
|
|
199
|
+
);
|
|
200
|
+
} catch (err) {
|
|
201
|
+
console.error("[qarpeo:cms] Auto-sync failed:", err);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
let prodTablesChecked = false;
|
|
205
|
+
export async function ensureCMSSynced(event) {
|
|
206
|
+
const db = getCMSDb(event);
|
|
207
|
+
if (!db) return;
|
|
208
|
+
if (process.env.NODE_ENV !== "production" || import.meta.dev) {
|
|
209
|
+
if (!hasInitialSynced) {
|
|
210
|
+
if (!syncPromise) {
|
|
211
|
+
syncPromise = _runCMSSync(event).finally(() => {
|
|
212
|
+
hasInitialSynced = true;
|
|
213
|
+
lastSyncTime = Date.now();
|
|
214
|
+
syncPromise = null;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
await syncPromise;
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (syncPromise) {
|
|
221
|
+
await syncPromise;
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const now = Date.now();
|
|
225
|
+
if (now - lastSyncTime > 3e4) {
|
|
226
|
+
lastSyncTime = now;
|
|
227
|
+
syncPromise = _runCMSSync(event).finally(() => {
|
|
228
|
+
syncPromise = null;
|
|
229
|
+
});
|
|
230
|
+
await syncPromise;
|
|
231
|
+
}
|
|
232
|
+
} else {
|
|
233
|
+
if (!prodTablesChecked) {
|
|
234
|
+
prodTablesChecked = true;
|
|
235
|
+
try {
|
|
236
|
+
await ensureCMSTables(event);
|
|
237
|
+
try {
|
|
238
|
+
const { manifestEntries, manifestCollections } = await import("#qarpeo/cms/manifest");
|
|
239
|
+
if (manifestCollections && Object.keys(manifestCollections).length > 0) {
|
|
240
|
+
await seedCollectionsFromConfig(event, manifestCollections);
|
|
241
|
+
}
|
|
242
|
+
if (manifestEntries && manifestEntries.length > 0) {
|
|
243
|
+
await seedEntriesIntoDb(event, manifestEntries, manifestCollections);
|
|
244
|
+
}
|
|
245
|
+
} catch {
|
|
246
|
+
}
|
|
247
|
+
} catch (err) {
|
|
248
|
+
console.warn("[qarpeo:cms] Production ensureCMSTables check failed:", err);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
registerEnsureCMSSynced(ensureCMSSynced);
|
|
254
|
+
export async function seedCollectionsFromConfig(event, collectionsConfig) {
|
|
255
|
+
const db = getCMSDb(event);
|
|
256
|
+
const now = Date.now();
|
|
257
|
+
for (const [id, cfg] of Object.entries(collectionsConfig)) {
|
|
258
|
+
const schemaJson = JSON.stringify(cfg.fields || {});
|
|
259
|
+
const colName = cfg.name || id.charAt(0).toUpperCase() + id.slice(1).replace(/-/g, " ");
|
|
260
|
+
const existing = await db.prepare(`SELECT id, source, schema_json FROM ${cmsCollectionTbl(event)} WHERE id = ?`).bind(id).first();
|
|
261
|
+
if (!existing) {
|
|
262
|
+
await db.prepare(
|
|
263
|
+
`INSERT INTO ${cmsCollectionTbl(event)} (id, name, description, schema_json, source, "order", created_at, updated_at) VALUES (?, ?, ?, ?, 'config', ?, ?, ?)`
|
|
264
|
+
).bind(id, colName, cfg.description ?? null, schemaJson, cfg.order ?? 0, now, now).run();
|
|
265
|
+
} else if (existing.source === "config" && existing.schema_json !== schemaJson) {
|
|
266
|
+
await db.prepare(
|
|
267
|
+
`UPDATE ${cmsCollectionTbl(event)} SET name = ?, description = ?, schema_json = ?, "order" = ?, updated_at = ? WHERE id = ?`
|
|
268
|
+
).bind(colName, cfg.description ?? null, schemaJson, cfg.order ?? 0, now, id).run();
|
|
269
|
+
try {
|
|
270
|
+
const kv = getKVBinding("KV", event);
|
|
271
|
+
const tenantPrefix = getCMSTenantPrefix(event);
|
|
272
|
+
await kv.delete(`${tenantPrefix}cms:schema:${id}`);
|
|
273
|
+
} catch {
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
export async function seedEntriesIntoDb(event, entries, collectionsConfig = {}) {
|
|
279
|
+
const db = getCMSDb(event);
|
|
280
|
+
let synced = 0;
|
|
281
|
+
let skipped = 0;
|
|
282
|
+
let inserted = 0;
|
|
283
|
+
const now = Date.now();
|
|
284
|
+
for (const entry of entries) {
|
|
285
|
+
const colId = entry.collection_id;
|
|
286
|
+
const colConfig = collectionsConfig[colId] || {};
|
|
287
|
+
const mode = colConfig.mode || "db";
|
|
288
|
+
try {
|
|
289
|
+
const existingCol = await db.prepare(`SELECT id FROM ${cmsCollectionTbl(event)} WHERE id = ?`).bind(colId).first();
|
|
290
|
+
if (!existingCol) {
|
|
291
|
+
const colName = colConfig.name || colId.charAt(0).toUpperCase() + colId.slice(1).replace(/-/g, " ");
|
|
292
|
+
await db.prepare(
|
|
293
|
+
`INSERT INTO ${cmsCollectionTbl(event)} (id, name, description, schema_json, source, "order", created_at, updated_at) VALUES (?, ?, ?, '{}', 'config', ?, ?, ?)`
|
|
294
|
+
).bind(colId, colName, `Collection ${colName}`, colConfig.order ?? 0, now, now).run();
|
|
295
|
+
}
|
|
296
|
+
} catch {
|
|
297
|
+
}
|
|
298
|
+
const existing = await db.prepare(
|
|
299
|
+
`SELECT id, source, content_hash, metadata_json, file_path, status FROM ${cmsEntryTbl(event)} WHERE collection_id = ? AND path = ?`
|
|
300
|
+
).bind(colId, entry.path).first();
|
|
301
|
+
if (!existing) {
|
|
302
|
+
const id = entry.id || nanoid();
|
|
303
|
+
await db.prepare(
|
|
304
|
+
`INSERT INTO ${cmsEntryTbl(event)}
|
|
305
|
+
(id, collection_id, slug, path, title, description, cover_image, tags, "order", content_md, content_html, metadata_json, status, source, file_path, content_hash, published_at, created_at, updated_at)
|
|
306
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'file', ?, ?, ?, ?, ?)`
|
|
307
|
+
).bind(
|
|
308
|
+
id,
|
|
309
|
+
colId,
|
|
310
|
+
entry.slug,
|
|
311
|
+
entry.path,
|
|
312
|
+
entry.title,
|
|
313
|
+
entry.description ?? null,
|
|
314
|
+
entry.cover_image ?? null,
|
|
315
|
+
entry.tags ?? null,
|
|
316
|
+
entry.order ?? 0,
|
|
317
|
+
entry.content_md ?? "",
|
|
318
|
+
entry.content_html ?? "",
|
|
319
|
+
entry.metadata_json ?? "{}",
|
|
320
|
+
entry.status ?? "published",
|
|
321
|
+
entry.file_path ?? "",
|
|
322
|
+
entry.content_hash ?? "",
|
|
323
|
+
entry.status === "draft" ? null : now,
|
|
324
|
+
now,
|
|
325
|
+
now
|
|
326
|
+
).run();
|
|
327
|
+
inserted++;
|
|
328
|
+
} else {
|
|
329
|
+
if (mode === "file") {
|
|
330
|
+
if (existing.content_hash !== entry.content_hash || existing.metadata_json !== entry.metadata_json || existing.status !== entry.status) {
|
|
331
|
+
await db.prepare(
|
|
332
|
+
`UPDATE ${cmsEntryTbl(event)} SET
|
|
333
|
+
status = ?, slug = ?, path = ?, title = ?, description = ?, cover_image = ?, tags = ?, "order" = ?,
|
|
334
|
+
content_md = ?, content_html = ?, metadata_json = ?,
|
|
335
|
+
file_path = ?, content_hash = ?, source = 'file', updated_at = ?
|
|
336
|
+
WHERE id = ?`
|
|
337
|
+
).bind(
|
|
338
|
+
entry.status ?? "published",
|
|
339
|
+
entry.slug,
|
|
340
|
+
entry.path,
|
|
341
|
+
entry.title,
|
|
342
|
+
entry.description ?? null,
|
|
343
|
+
entry.cover_image ?? null,
|
|
344
|
+
entry.tags ?? null,
|
|
345
|
+
entry.order ?? 0,
|
|
346
|
+
entry.content_md ?? "",
|
|
347
|
+
entry.content_html ?? "",
|
|
348
|
+
entry.metadata_json ?? "{}",
|
|
349
|
+
entry.file_path ?? "",
|
|
350
|
+
entry.content_hash ?? "",
|
|
351
|
+
now,
|
|
352
|
+
existing.id
|
|
353
|
+
).run();
|
|
354
|
+
synced++;
|
|
355
|
+
} else {
|
|
356
|
+
skipped++;
|
|
357
|
+
}
|
|
358
|
+
} else if (mode === "hybrid") {
|
|
359
|
+
if (existing.source === "file") {
|
|
360
|
+
if (existing.content_hash !== entry.content_hash) {
|
|
361
|
+
await db.prepare(
|
|
362
|
+
`UPDATE ${cmsEntryTbl(event)} SET
|
|
363
|
+
status = ?, slug = ?, path = ?, title = ?, description = ?, cover_image = ?, tags = ?, "order" = ?,
|
|
364
|
+
content_md = ?, content_html = ?, metadata_json = ?,
|
|
365
|
+
file_path = ?, content_hash = ?, updated_at = ?
|
|
366
|
+
WHERE id = ?`
|
|
367
|
+
).bind(
|
|
368
|
+
entry.status ?? "published",
|
|
369
|
+
entry.slug,
|
|
370
|
+
entry.path,
|
|
371
|
+
entry.title,
|
|
372
|
+
entry.description ?? null,
|
|
373
|
+
entry.cover_image ?? null,
|
|
374
|
+
entry.tags ?? null,
|
|
375
|
+
entry.order ?? 0,
|
|
376
|
+
entry.content_md ?? "",
|
|
377
|
+
entry.content_html ?? "",
|
|
378
|
+
entry.metadata_json ?? "{}",
|
|
379
|
+
entry.file_path ?? "",
|
|
380
|
+
entry.content_hash ?? "",
|
|
381
|
+
now,
|
|
382
|
+
existing.id
|
|
383
|
+
).run();
|
|
384
|
+
synced++;
|
|
385
|
+
} else {
|
|
386
|
+
skipped++;
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
if (existing.content_hash !== entry.content_hash) {
|
|
390
|
+
const revId = nanoid();
|
|
391
|
+
await db.prepare(
|
|
392
|
+
`INSERT INTO ${cmsRevisionTbl(event)} (id, entry_id, title, content_md, metadata_json, author_id, created_at) VALUES (?, ?, ?, ?, ?, 'git', ?)`
|
|
393
|
+
).bind(revId, existing.id, entry.title, entry.content_md, entry.metadata_json, now).run();
|
|
394
|
+
synced++;
|
|
395
|
+
} else {
|
|
396
|
+
skipped++;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
} else {
|
|
400
|
+
skipped++;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return { synced, skipped, inserted };
|
|
405
|
+
}
|
|
406
|
+
import { matchesSourceFilters, matchesGlobFilter } from "../cms-filter.mjs";
|
|
407
|
+
export { matchesSourceFilters, matchesGlobFilter };
|
|
408
|
+
export async function syncLocalContentFiles(event, contentDir, collectionsConfig = {}, sources = []) {
|
|
409
|
+
let readdir, readFile, existsSync;
|
|
410
|
+
try {
|
|
411
|
+
const fs = await import("node:fs/promises");
|
|
412
|
+
const fsSync = await import("node:fs");
|
|
413
|
+
readdir = (dir) => fs.readdir(dir, { withFileTypes: true });
|
|
414
|
+
readFile = (p) => fs.readFile(p, "utf8");
|
|
415
|
+
existsSync = fsSync.existsSync;
|
|
416
|
+
} catch {
|
|
417
|
+
return { synced: 0, skipped: 0, inserted: 0 };
|
|
418
|
+
}
|
|
419
|
+
async function readNavJson(dir) {
|
|
420
|
+
const navJsonPath = `${dir}/.navigation.json`;
|
|
421
|
+
if (existsSync(navJsonPath)) {
|
|
422
|
+
try {
|
|
423
|
+
const raw = await readFile(navJsonPath);
|
|
424
|
+
const clean = raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw;
|
|
425
|
+
return JSON.parse(clean);
|
|
426
|
+
} catch {
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const navYmlPath = `${dir}/.navigation.yml`;
|
|
430
|
+
if (existsSync(navYmlPath)) {
|
|
431
|
+
try {
|
|
432
|
+
const raw = await readFile(navYmlPath);
|
|
433
|
+
return parseYaml(raw) || {};
|
|
434
|
+
} catch {
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return {};
|
|
438
|
+
}
|
|
439
|
+
async function readSchemaJson(dir) {
|
|
440
|
+
const schemaPath = `${dir}/.schema.json`;
|
|
441
|
+
if (existsSync(schemaPath)) {
|
|
442
|
+
try {
|
|
443
|
+
const raw = await readFile(schemaPath);
|
|
444
|
+
const clean = raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw;
|
|
445
|
+
const parsed = JSON.parse(clean);
|
|
446
|
+
return {
|
|
447
|
+
scope: parsed.scope || "cascade",
|
|
448
|
+
fields: parsed.fields || {}
|
|
449
|
+
};
|
|
450
|
+
} catch {
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
const db = getCMSDb(event);
|
|
456
|
+
const cmsConfig = getCMSConfig(event);
|
|
457
|
+
let synced = 0, skipped = 0, inserted = 0;
|
|
458
|
+
const now = Date.now();
|
|
459
|
+
try {
|
|
460
|
+
const existingFileRows = await db.prepare(`SELECT id, file_path FROM ${cmsEntryTbl(event)} WHERE source = 'file'`).all();
|
|
461
|
+
for (const r of existingFileRows?.results || []) {
|
|
462
|
+
if (r.file_path && !existsSync(r.file_path)) {
|
|
463
|
+
await db.prepare(`DELETE FROM ${cmsEntryTbl(event)} WHERE id = ?`).bind(r.id).run();
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
} catch {
|
|
467
|
+
}
|
|
468
|
+
async function syncSource(source) {
|
|
469
|
+
if (!source?.resolvedDir || !existsSync(source.resolvedDir)) return;
|
|
470
|
+
let orderCounter = 0;
|
|
471
|
+
const processDir = async (dir, relBase, sectionNavMeta) => {
|
|
472
|
+
let entries;
|
|
473
|
+
try {
|
|
474
|
+
entries = await readdir(dir);
|
|
475
|
+
} catch {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
entries.sort((a, b) => a.name.localeCompare(b.name, void 0, { numeric: true }));
|
|
479
|
+
let navMeta = await readNavJson(dir);
|
|
480
|
+
if (navMeta.private === true || navMeta.draft === true || navMeta.exclude === true) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
if (navMeta.order == null && relBase) {
|
|
484
|
+
const lastSeg = relBase.split("/").filter(Boolean).pop();
|
|
485
|
+
if (lastSeg) {
|
|
486
|
+
const extracted = extractOrderPrefix(lastSeg);
|
|
487
|
+
if (extracted != null) navMeta.order = extracted;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
const isTopLevelSection = Boolean(relBase && !relBase.includes("/"));
|
|
491
|
+
const currentSectionNavMeta = sectionNavMeta || (isTopLevelSection ? {
|
|
492
|
+
title: navMeta.title || stripOrderPrefix(relBase).charAt(0).toUpperCase() + stripOrderPrefix(relBase).slice(1).replace(/-/g, " "),
|
|
493
|
+
icon: navMeta.icon,
|
|
494
|
+
order: navMeta.order ?? extractOrderPrefix(relBase),
|
|
495
|
+
navigation: navMeta.navigation,
|
|
496
|
+
hidden: navMeta.hidden
|
|
497
|
+
} : void 0);
|
|
498
|
+
for (const entry of entries) {
|
|
499
|
+
if (entry.name.startsWith(".") || entry.name.startsWith("_")) continue;
|
|
500
|
+
const subRel = relBase ? `${relBase}/${entry.name}` : entry.name;
|
|
501
|
+
if (entry.isDirectory()) {
|
|
502
|
+
await processDir(`${dir}/${entry.name}`, subRel, currentSectionNavMeta);
|
|
503
|
+
} else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
504
|
+
const combinedExclude = [
|
|
505
|
+
...Array.isArray(cmsConfig?.exclude) ? cmsConfig.exclude : cmsConfig?.exclude ? [cmsConfig.exclude] : [],
|
|
506
|
+
...Array.isArray(source.exclude) ? source.exclude : source.exclude ? [source.exclude] : []
|
|
507
|
+
];
|
|
508
|
+
if (!matchesSourceFilters(subRel, source.include, combinedExclude)) continue;
|
|
509
|
+
const filePath = `${dir}/${entry.name}`;
|
|
510
|
+
const rawContent = await readFile(filePath);
|
|
511
|
+
const fileHash = await computeContentHash(rawContent);
|
|
512
|
+
const { data: fm, content: body } = parseFrontmatter(rawContent);
|
|
513
|
+
const rawRelSegments = subRel.replace(/\.md$/, "").split("/").filter(Boolean);
|
|
514
|
+
const isReadme = entry.name.toLowerCase() === "readme.md";
|
|
515
|
+
const isIndex = entry.name.replace(/\.md$/, "") === "index" || entry.name.replace(/\.md$/, "") === "01.index" || isReadme;
|
|
516
|
+
const groupSegment = rawRelSegments.slice(0, -1).find(isGroupSegment);
|
|
517
|
+
let groupMeta;
|
|
518
|
+
if (groupSegment) {
|
|
519
|
+
const groupOrder = extractOrderPrefix(groupSegment);
|
|
520
|
+
const defaultGroupTitle = extractGroupTitle(groupSegment);
|
|
521
|
+
const groupKey = stripOrderPrefix(groupSegment).replace(/^\(|\)$/g, "");
|
|
522
|
+
const currentDirName = dir.replace(/\\/g, "/").split("/").filter(Boolean).pop();
|
|
523
|
+
const isGroupDir = currentDirName === groupSegment;
|
|
524
|
+
groupMeta = {
|
|
525
|
+
key: groupKey,
|
|
526
|
+
title: isGroupDir && navMeta.title ? navMeta.title : defaultGroupTitle,
|
|
527
|
+
icon: isGroupDir && navMeta.icon ? navMeta.icon : void 0,
|
|
528
|
+
order: groupOrder
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
const cleanedRelSegments = rawRelSegments.filter((seg) => !isGroupSegment(seg)).map(stripOrderPrefix).filter(Boolean);
|
|
532
|
+
if (isIndex && cleanedRelSegments.length > 0) {
|
|
533
|
+
cleanedRelSegments.pop();
|
|
534
|
+
}
|
|
535
|
+
const prefixSegments = (source.normalizedPrefix || "/").split("/").filter(Boolean);
|
|
536
|
+
const combinedSegments = [...prefixSegments, ...cleanedRelSegments];
|
|
537
|
+
const entryPath = "/" + combinedSegments.join("/");
|
|
538
|
+
const defaultCollectionId = prefixSegments[0] || "content";
|
|
539
|
+
const collectionId = resolveCollectionForPath(
|
|
540
|
+
entryPath,
|
|
541
|
+
collectionsConfig,
|
|
542
|
+
defaultCollectionId
|
|
543
|
+
);
|
|
544
|
+
const slug = fm.slug || cleanedRelSegments[cleanedRelSegments.length - 1] || prefixSegments[prefixSegments.length - 1] || "index";
|
|
545
|
+
const title = fm.title || slug;
|
|
546
|
+
const srcOrder = typeof source.order === "number" ? source.order : 0;
|
|
547
|
+
const existingCol = await db.prepare(`SELECT id FROM ${cmsCollectionTbl(event)} WHERE id = ?`).bind(collectionId).first();
|
|
548
|
+
if (!existingCol) {
|
|
549
|
+
const colName = collectionId.charAt(0).toUpperCase() + collectionId.slice(1).replace(/-/g, " ");
|
|
550
|
+
await db.prepare(
|
|
551
|
+
`INSERT INTO ${cmsCollectionTbl(event)} (id, name, description, schema_json, source, "order", created_at, updated_at) VALUES (?, ?, ?, '{}', 'file', ?, ?, ?)`
|
|
552
|
+
).bind(
|
|
553
|
+
collectionId,
|
|
554
|
+
colName,
|
|
555
|
+
`Auto-discovered ${colName} collection`,
|
|
556
|
+
srcOrder,
|
|
557
|
+
now,
|
|
558
|
+
now
|
|
559
|
+
).run();
|
|
560
|
+
}
|
|
561
|
+
const toc = extractTOC(body);
|
|
562
|
+
const { html: contentHtml } = await processMarkdown(body);
|
|
563
|
+
const description = fm.description || null;
|
|
564
|
+
const coverImage = fm.coverImage || fm.cover_image || null;
|
|
565
|
+
const tags = Array.isArray(fm.tags) ? fm.tags.join(",") : fm.tags || null;
|
|
566
|
+
const folderNum = rawRelSegments.length > 1 ? extractOrderPrefix(rawRelSegments[0]) : void 0;
|
|
567
|
+
const effectiveFolderNum = folderNum ?? (typeof currentSectionNavMeta?.order === "number" ? currentSectionNavMeta.order : void 0);
|
|
568
|
+
const folderOrder = effectiveFolderNum != null ? effectiveFolderNum * 1e3 : 5e4;
|
|
569
|
+
let subfolderOffset = 0;
|
|
570
|
+
if (rawRelSegments.length > 2) {
|
|
571
|
+
const subDir = rawRelSegments[1];
|
|
572
|
+
const subDirNum = extractOrderPrefix(subDir);
|
|
573
|
+
const subOrder = subDirNum ?? (typeof groupMeta?.order === "number" ? groupMeta.order : typeof navMeta?.order === "number" ? navMeta.order : void 0);
|
|
574
|
+
subfolderOffset = 500 + (subOrder != null ? subOrder * 50 : 100);
|
|
575
|
+
}
|
|
576
|
+
const fileNum = extractOrderPrefix(entry.name);
|
|
577
|
+
const itemOrder = typeof fm.order === "number" ? fm.order : isIndex ? 0 : fileNum ?? (subfolderOffset > 0 ? 10 + orderCounter++ : 100 + orderCounter++);
|
|
578
|
+
const order = srcOrder * 1e5 + folderOrder + subfolderOffset + itemOrder;
|
|
579
|
+
const itemTitle = fm.navigation?.title || fm.title || slug;
|
|
580
|
+
const {
|
|
581
|
+
slug: _s,
|
|
582
|
+
title: _t,
|
|
583
|
+
description: _d,
|
|
584
|
+
coverImage: _ci,
|
|
585
|
+
tags: _ta,
|
|
586
|
+
order: _o,
|
|
587
|
+
...rest
|
|
588
|
+
} = fm;
|
|
589
|
+
void _s;
|
|
590
|
+
void _t;
|
|
591
|
+
void _d;
|
|
592
|
+
void _ci;
|
|
593
|
+
void _ta;
|
|
594
|
+
void _o;
|
|
595
|
+
const effectiveSection = currentSectionNavMeta?.title ? { title: currentSectionNavMeta.title, icon: currentSectionNavMeta.icon } : navMeta.title ? { title: navMeta.title, icon: navMeta.icon } : void 0;
|
|
596
|
+
const isDraft = Boolean(
|
|
597
|
+
fm.draft === true || fm.private === true || fm.status === "draft" || navMeta.draft === true || navMeta.private === true
|
|
598
|
+
);
|
|
599
|
+
const entryStatus = isDraft ? "draft" : "published";
|
|
600
|
+
const resolvedRest = { ...rest };
|
|
601
|
+
try {
|
|
602
|
+
await resolveReferenceFieldsFromFrontmatter(event, collectionId, resolvedRest);
|
|
603
|
+
} catch {
|
|
604
|
+
}
|
|
605
|
+
const metadataJson = JSON.stringify({
|
|
606
|
+
...resolvedRest,
|
|
607
|
+
navigation: fm.navigation,
|
|
608
|
+
hidden: fm.hidden,
|
|
609
|
+
draft: isDraft,
|
|
610
|
+
_toc: { links: toc },
|
|
611
|
+
_nav: navMeta,
|
|
612
|
+
_section: effectiveSection,
|
|
613
|
+
_sectionOrder: effectiveFolderNum,
|
|
614
|
+
_group: groupMeta,
|
|
615
|
+
_itemTitle: itemTitle,
|
|
616
|
+
_itemOrder: itemOrder,
|
|
617
|
+
_fileOrder: fileNum,
|
|
618
|
+
_isIndex: isIndex,
|
|
619
|
+
_source: source.from || "unknown",
|
|
620
|
+
_sourceLabel: source.label || source.from || "source",
|
|
621
|
+
_sourcePriority: source.priority ?? 0,
|
|
622
|
+
_sourceOrder: source.order ?? srcOrder
|
|
623
|
+
});
|
|
624
|
+
const existing = await db.prepare(
|
|
625
|
+
`SELECT id, source, content_hash, metadata_json, file_path, status FROM ${cmsEntryTbl(event)} WHERE collection_id = ? AND path = ?`
|
|
626
|
+
).bind(collectionId, entryPath).first();
|
|
627
|
+
if (!existing) {
|
|
628
|
+
const id = nanoid();
|
|
629
|
+
await db.prepare(
|
|
630
|
+
`INSERT INTO ${cmsEntryTbl(event)}
|
|
631
|
+
(id, collection_id, slug, path, title, description, cover_image, tags, "order", content_md, content_html, metadata_json, status, source, file_path, content_hash, published_at, created_at, updated_at)
|
|
632
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'file', ?, ?, ?, ?, ?)`
|
|
633
|
+
).bind(
|
|
634
|
+
id,
|
|
635
|
+
collectionId,
|
|
636
|
+
slug,
|
|
637
|
+
entryPath,
|
|
638
|
+
title,
|
|
639
|
+
description,
|
|
640
|
+
coverImage,
|
|
641
|
+
tags,
|
|
642
|
+
order,
|
|
643
|
+
body,
|
|
644
|
+
contentHtml,
|
|
645
|
+
metadataJson,
|
|
646
|
+
entryStatus,
|
|
647
|
+
filePath,
|
|
648
|
+
fileHash,
|
|
649
|
+
isDraft ? null : now,
|
|
650
|
+
now,
|
|
651
|
+
now
|
|
652
|
+
).run();
|
|
653
|
+
inserted++;
|
|
654
|
+
} else if (existing.source === "file" && (existing.content_hash !== fileHash || existing.metadata_json !== metadataJson || existing.file_path !== filePath || existing.status !== entryStatus)) {
|
|
655
|
+
await db.prepare(
|
|
656
|
+
`UPDATE ${cmsEntryTbl(event)} SET
|
|
657
|
+
status = ?, slug = ?, path = ?, title = ?, description = ?, cover_image = ?, tags = ?, "order" = ?,
|
|
658
|
+
content_md = ?, content_html = ?, metadata_json = ?,
|
|
659
|
+
file_path = ?, content_hash = ?, source = 'file', updated_at = ?
|
|
660
|
+
WHERE id = ?`
|
|
661
|
+
).bind(
|
|
662
|
+
entryStatus,
|
|
663
|
+
slug,
|
|
664
|
+
entryPath,
|
|
665
|
+
title,
|
|
666
|
+
description,
|
|
667
|
+
coverImage,
|
|
668
|
+
tags,
|
|
669
|
+
order,
|
|
670
|
+
body,
|
|
671
|
+
contentHtml,
|
|
672
|
+
metadataJson,
|
|
673
|
+
filePath,
|
|
674
|
+
fileHash,
|
|
675
|
+
now,
|
|
676
|
+
existing.id
|
|
677
|
+
).run();
|
|
678
|
+
synced++;
|
|
679
|
+
} else {
|
|
680
|
+
skipped++;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
await processDir(source.resolvedDir, "");
|
|
686
|
+
}
|
|
687
|
+
const lowPrioritySources = (sources || []).filter((s) => (s.priority ?? 0) < 10);
|
|
688
|
+
const highPrioritySources = (sources || []).filter((s) => (s.priority ?? 0) >= 10);
|
|
689
|
+
for (const src of lowPrioritySources) {
|
|
690
|
+
await syncSource(src);
|
|
691
|
+
}
|
|
692
|
+
const targetCollections = {};
|
|
693
|
+
for (const [id, cfg] of Object.entries(collectionsConfig)) {
|
|
694
|
+
targetCollections[id] = {
|
|
695
|
+
directory: cfg.directory || `${contentDir}/${id}`,
|
|
696
|
+
name: cfg.name,
|
|
697
|
+
type: cfg.type || "content",
|
|
698
|
+
order: typeof cfg.order === "number" ? cfg.order : 0
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
const rootMdFiles = [];
|
|
702
|
+
try {
|
|
703
|
+
const rootItems = await readdir(contentDir);
|
|
704
|
+
for (const item of rootItems) {
|
|
705
|
+
if (item.isDirectory()) {
|
|
706
|
+
const colId = stripOrderPrefix(item.name).toLowerCase();
|
|
707
|
+
if (!targetCollections[colId]) {
|
|
708
|
+
targetCollections[colId] = {
|
|
709
|
+
directory: `${contentDir}/${item.name}`,
|
|
710
|
+
name: item.name.charAt(0).toUpperCase() + item.name.slice(1).replace(/-/g, " "),
|
|
711
|
+
type: "content",
|
|
712
|
+
order: extractOrderPrefix(item.name) ?? 0
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
} else if (item.isFile() && (item.name.endsWith(".md") || item.name.endsWith(".json") || item.name.endsWith(".yml") || item.name.endsWith(".yaml"))) {
|
|
716
|
+
if (item.name.endsWith(".md")) {
|
|
717
|
+
rootMdFiles.push(item);
|
|
718
|
+
} else {
|
|
719
|
+
const colId = item.name.replace(/\.(json|ya?ml)$/, "").toLowerCase();
|
|
720
|
+
if (!targetCollections[colId]) {
|
|
721
|
+
targetCollections[colId] = {
|
|
722
|
+
directory: `${contentDir}/${item.name}`,
|
|
723
|
+
name: colId.charAt(0).toUpperCase() + colId.slice(1).replace(/-/g, " "),
|
|
724
|
+
type: "content",
|
|
725
|
+
order: 0,
|
|
726
|
+
isSingleDataFile: true
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
} catch {
|
|
733
|
+
return { synced: 0, skipped: 0, inserted: 0 };
|
|
734
|
+
}
|
|
735
|
+
if (rootMdFiles.length > 0 && !targetCollections["content"]) {
|
|
736
|
+
targetCollections["content"] = {
|
|
737
|
+
directory: contentDir,
|
|
738
|
+
name: "Content",
|
|
739
|
+
type: "page",
|
|
740
|
+
order: 100
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
for (const [collectionId, meta] of Object.entries(targetCollections)) {
|
|
744
|
+
const isPageType = meta.type === "page";
|
|
745
|
+
const folderSchema = await readSchemaJson(meta.directory);
|
|
746
|
+
const initialFields = folderSchema?.fields ? JSON.stringify(folderSchema.fields) : "{}";
|
|
747
|
+
const existingCol = await db.prepare(`SELECT id, source, schema_json FROM ${cmsCollectionTbl(event)} WHERE id = ?`).bind(collectionId).first();
|
|
748
|
+
if (!existingCol) {
|
|
749
|
+
const colName = meta.name || collectionId.charAt(0).toUpperCase() + collectionId.slice(1).replace(/-/g, " ");
|
|
750
|
+
await db.prepare(
|
|
751
|
+
`INSERT INTO ${cmsCollectionTbl(event)} (id, name, description, schema_json, source, "order", created_at, updated_at) VALUES (?, ?, ?, ?, 'file', ?, ?, ?)`
|
|
752
|
+
).bind(
|
|
753
|
+
collectionId,
|
|
754
|
+
colName,
|
|
755
|
+
`Auto-discovered ${colName} collection`,
|
|
756
|
+
initialFields,
|
|
757
|
+
meta.order,
|
|
758
|
+
now,
|
|
759
|
+
now
|
|
760
|
+
).run();
|
|
761
|
+
} else if (folderSchema?.fields && existingCol.schema_json !== initialFields && existingCol.source === "file") {
|
|
762
|
+
await db.prepare(`UPDATE ${cmsCollectionTbl(event)} SET schema_json = ?, updated_at = ? WHERE id = ?`).bind(initialFields, now, collectionId).run();
|
|
763
|
+
}
|
|
764
|
+
if (meta.isSingleDataFile) {
|
|
765
|
+
const filePath = meta.directory;
|
|
766
|
+
let rawContent = "";
|
|
767
|
+
try {
|
|
768
|
+
rawContent = await readFile(filePath);
|
|
769
|
+
} catch {
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
const fileHash = await computeContentHash(rawContent);
|
|
773
|
+
let parsed = {};
|
|
774
|
+
if (filePath.endsWith(".json")) {
|
|
775
|
+
try {
|
|
776
|
+
parsed = JSON.parse(rawContent);
|
|
777
|
+
} catch {
|
|
778
|
+
}
|
|
779
|
+
} else {
|
|
780
|
+
try {
|
|
781
|
+
parsed = parseYaml(rawContent) || {};
|
|
782
|
+
} catch {
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
const slug = parsed.slug || collectionId;
|
|
786
|
+
const title = parsed.title || slug;
|
|
787
|
+
const description = parsed.description || null;
|
|
788
|
+
const entryPath = `/${collectionId}`;
|
|
789
|
+
const metadataJson = JSON.stringify(parsed);
|
|
790
|
+
const existing = await db.prepare(
|
|
791
|
+
`SELECT id, source, content_hash, metadata_json, file_path FROM ${cmsEntryTbl(event)} WHERE collection_id = ? AND slug = ?`
|
|
792
|
+
).bind(collectionId, slug).first();
|
|
793
|
+
if (!existing) {
|
|
794
|
+
const id = nanoid();
|
|
795
|
+
await db.prepare(
|
|
796
|
+
`INSERT INTO ${cmsEntryTbl(event)}
|
|
797
|
+
(id, collection_id, slug, path, title, description, cover_image, tags, "order", content_md, content_html, metadata_json, status, source, file_path, content_hash, published_at, created_at, updated_at)
|
|
798
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0, '', '', ?, 'published', 'file', ?, ?, ?, ?, ?)`
|
|
799
|
+
).bind(
|
|
800
|
+
id,
|
|
801
|
+
collectionId,
|
|
802
|
+
slug,
|
|
803
|
+
entryPath,
|
|
804
|
+
title,
|
|
805
|
+
description,
|
|
806
|
+
null,
|
|
807
|
+
null,
|
|
808
|
+
metadataJson,
|
|
809
|
+
filePath,
|
|
810
|
+
fileHash,
|
|
811
|
+
now,
|
|
812
|
+
now,
|
|
813
|
+
now
|
|
814
|
+
).run();
|
|
815
|
+
inserted++;
|
|
816
|
+
} else if (existing.source === "file" && (existing.content_hash !== fileHash || existing.metadata_json !== metadataJson)) {
|
|
817
|
+
await db.prepare(
|
|
818
|
+
`UPDATE ${cmsEntryTbl(event)} SET
|
|
819
|
+
slug = ?, path = ?, title = ?, description = ?,
|
|
820
|
+
metadata_json = ?, file_path = ?, content_hash = ?, source = 'file', updated_at = ?
|
|
821
|
+
WHERE id = ?`
|
|
822
|
+
).bind(
|
|
823
|
+
slug,
|
|
824
|
+
entryPath,
|
|
825
|
+
title,
|
|
826
|
+
description,
|
|
827
|
+
metadataJson,
|
|
828
|
+
filePath,
|
|
829
|
+
fileHash,
|
|
830
|
+
now,
|
|
831
|
+
existing.id
|
|
832
|
+
).run();
|
|
833
|
+
synced++;
|
|
834
|
+
} else {
|
|
835
|
+
skipped++;
|
|
836
|
+
}
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
839
|
+
if (isPageType) {
|
|
840
|
+
let orderCounter = 0;
|
|
841
|
+
const processDir = async (dir, relBase) => {
|
|
842
|
+
let entries;
|
|
843
|
+
try {
|
|
844
|
+
entries = await readdir(dir);
|
|
845
|
+
} catch {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
entries.sort((a, b) => a.name.localeCompare(b.name, void 0, { numeric: true }));
|
|
849
|
+
for (const entry of entries) {
|
|
850
|
+
if (entry.name.startsWith(".")) continue;
|
|
851
|
+
if (entry.isDirectory()) {
|
|
852
|
+
if (collectionId === "content") continue;
|
|
853
|
+
await processDir(`${dir}/${entry.name}`, `${relBase}/${entry.name}`);
|
|
854
|
+
} else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
855
|
+
const filePath = `${dir}/${entry.name}`;
|
|
856
|
+
const rawContent = await readFile(filePath);
|
|
857
|
+
const fileHash = await computeContentHash(rawContent);
|
|
858
|
+
const { data: fm, content: body } = parseFrontmatter(rawContent);
|
|
859
|
+
const relFilePath = `${relBase}/${entry.name}`.replace(/^\//, "");
|
|
860
|
+
const slug = fm.slug || stripOrderPrefix(entry.name.replace(/\.md$/, ""));
|
|
861
|
+
const title = fm.title || slug;
|
|
862
|
+
const navJson = await readNavJson(dir);
|
|
863
|
+
const navMeta = {
|
|
864
|
+
title: navJson.title,
|
|
865
|
+
icon: navJson.icon
|
|
866
|
+
};
|
|
867
|
+
const rawRelSegments = relFilePath.replace(/\.md$/, "").split("/").filter(Boolean);
|
|
868
|
+
const groupSegment = rawRelSegments.slice(0, -1).find(isGroupSegment);
|
|
869
|
+
let groupMeta;
|
|
870
|
+
if (groupSegment) {
|
|
871
|
+
const groupOrder = extractOrderPrefix(groupSegment);
|
|
872
|
+
const defaultGroupTitle = extractGroupTitle(groupSegment);
|
|
873
|
+
const groupKey = stripOrderPrefix(groupSegment).replace(/^\(|\)$/g, "");
|
|
874
|
+
const currentDirName = dir.replace(/\\/g, "/").split("/").filter(Boolean).pop();
|
|
875
|
+
const isGroupDir = currentDirName === groupSegment;
|
|
876
|
+
groupMeta = {
|
|
877
|
+
key: groupKey,
|
|
878
|
+
title: isGroupDir && navMeta.title ? navMeta.title : defaultGroupTitle,
|
|
879
|
+
icon: isGroupDir && navMeta.icon ? navMeta.icon : void 0,
|
|
880
|
+
order: groupOrder
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
const entryPath = computeEntryPath(relFilePath, collectionId);
|
|
884
|
+
const targetCollectionId = resolveCollectionForPath(
|
|
885
|
+
entryPath,
|
|
886
|
+
collectionsConfig,
|
|
887
|
+
collectionId
|
|
888
|
+
);
|
|
889
|
+
const toc = extractTOC(body);
|
|
890
|
+
const { html: contentHtml } = await processMarkdown(body);
|
|
891
|
+
const description = fm.description || null;
|
|
892
|
+
const coverImage = fm.coverImage || fm.cover_image || null;
|
|
893
|
+
const tags = Array.isArray(fm.tags) ? fm.tags.join(",") : fm.tags || null;
|
|
894
|
+
const order = fm.order ?? orderCounter++;
|
|
895
|
+
const isIndex = entry.name.replace(/\.md$/, "") === "01.index" || entry.name.replace(/\.md$/, "") === "index";
|
|
896
|
+
const itemTitle = fm.navigation?.title || fm.title || slug;
|
|
897
|
+
const {
|
|
898
|
+
slug: _s,
|
|
899
|
+
title: _t,
|
|
900
|
+
description: _d,
|
|
901
|
+
coverImage: _ci,
|
|
902
|
+
tags: _ta,
|
|
903
|
+
order: _o,
|
|
904
|
+
...rest
|
|
905
|
+
} = fm;
|
|
906
|
+
void _s;
|
|
907
|
+
void _t;
|
|
908
|
+
void _d;
|
|
909
|
+
void _ci;
|
|
910
|
+
void _ta;
|
|
911
|
+
void _o;
|
|
912
|
+
const metadataJson = JSON.stringify({
|
|
913
|
+
...rest,
|
|
914
|
+
_toc: { links: toc },
|
|
915
|
+
_nav: navMeta,
|
|
916
|
+
_section: navMeta.title ? { title: navMeta.title, icon: navMeta.icon } : void 0,
|
|
917
|
+
_group: groupMeta,
|
|
918
|
+
_itemTitle: itemTitle,
|
|
919
|
+
_isIndex: isIndex
|
|
920
|
+
});
|
|
921
|
+
const existing = await db.prepare(
|
|
922
|
+
`SELECT id, source, content_hash, metadata_json, file_path FROM ${cmsEntryTbl(event)} WHERE collection_id = ? AND path = ?`
|
|
923
|
+
).bind(targetCollectionId, entryPath).first();
|
|
924
|
+
if (!existing) {
|
|
925
|
+
const id = nanoid();
|
|
926
|
+
await db.prepare(
|
|
927
|
+
`INSERT INTO ${cmsEntryTbl(event)}
|
|
928
|
+
(id, collection_id, slug, path, title, description, cover_image, tags, "order", content_md, content_html, metadata_json, status, source, file_path, content_hash, published_at, created_at, updated_at)
|
|
929
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'published', 'file', ?, ?, ?, ?, ?)`
|
|
930
|
+
).bind(
|
|
931
|
+
id,
|
|
932
|
+
targetCollectionId,
|
|
933
|
+
slug,
|
|
934
|
+
entryPath,
|
|
935
|
+
title,
|
|
936
|
+
description,
|
|
937
|
+
coverImage,
|
|
938
|
+
tags,
|
|
939
|
+
order,
|
|
940
|
+
body,
|
|
941
|
+
contentHtml,
|
|
942
|
+
metadataJson,
|
|
943
|
+
filePath,
|
|
944
|
+
fileHash,
|
|
945
|
+
now,
|
|
946
|
+
now,
|
|
947
|
+
now
|
|
948
|
+
).run();
|
|
949
|
+
inserted++;
|
|
950
|
+
} else if (existing.source === "file" && (existing.content_hash !== fileHash || existing.metadata_json !== metadataJson || existing.file_path !== filePath)) {
|
|
951
|
+
await db.prepare(
|
|
952
|
+
`UPDATE ${cmsEntryTbl(event)} SET
|
|
953
|
+
slug = ?, path = ?, title = ?, description = ?, cover_image = ?, tags = ?, "order" = ?,
|
|
954
|
+
content_md = ?, content_html = ?, metadata_json = ?,
|
|
955
|
+
file_path = ?, content_hash = ?, source = 'file', updated_at = ?
|
|
956
|
+
WHERE id = ?`
|
|
957
|
+
).bind(
|
|
958
|
+
slug,
|
|
959
|
+
entryPath,
|
|
960
|
+
title,
|
|
961
|
+
description,
|
|
962
|
+
coverImage,
|
|
963
|
+
tags,
|
|
964
|
+
order,
|
|
965
|
+
body,
|
|
966
|
+
contentHtml,
|
|
967
|
+
metadataJson,
|
|
968
|
+
filePath,
|
|
969
|
+
fileHash,
|
|
970
|
+
now,
|
|
971
|
+
existing.id
|
|
972
|
+
).run();
|
|
973
|
+
synced++;
|
|
974
|
+
} else {
|
|
975
|
+
skipped++;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
await processDir(meta.directory, "");
|
|
981
|
+
} else {
|
|
982
|
+
let entries;
|
|
983
|
+
try {
|
|
984
|
+
entries = await readdir(meta.directory);
|
|
985
|
+
} catch {
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
for (const entry of entries) {
|
|
989
|
+
if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
|
|
990
|
+
const filePath = `${meta.directory}/${entry.name}`;
|
|
991
|
+
const rawContent = await readFile(filePath);
|
|
992
|
+
const fileHash = await computeContentHash(rawContent);
|
|
993
|
+
const { data: fm, content: body } = parseFrontmatter(rawContent);
|
|
994
|
+
const slug = fm.slug || entry.name.replace(/\.md$/, "");
|
|
995
|
+
const title = fm.title || slug;
|
|
996
|
+
const { html: contentHtml } = await processMarkdown(body);
|
|
997
|
+
const description = fm.description || null;
|
|
998
|
+
const coverImage = fm.coverImage || fm.cover_image || null;
|
|
999
|
+
const tags = Array.isArray(fm.tags) ? fm.tags.join(",") : fm.tags || null;
|
|
1000
|
+
const order = fm.order || 0;
|
|
1001
|
+
const {
|
|
1002
|
+
slug: _s,
|
|
1003
|
+
title: _t,
|
|
1004
|
+
description: _d,
|
|
1005
|
+
coverImage: _ci,
|
|
1006
|
+
tags: _ta,
|
|
1007
|
+
order: _o,
|
|
1008
|
+
...rest
|
|
1009
|
+
} = fm;
|
|
1010
|
+
void _s;
|
|
1011
|
+
void _t;
|
|
1012
|
+
void _d;
|
|
1013
|
+
void _ci;
|
|
1014
|
+
void _ta;
|
|
1015
|
+
void _o;
|
|
1016
|
+
const metadataJson = JSON.stringify({
|
|
1017
|
+
...rest,
|
|
1018
|
+
_source: "local",
|
|
1019
|
+
_sourceLabel: "content",
|
|
1020
|
+
_sourcePriority: 10
|
|
1021
|
+
});
|
|
1022
|
+
const existing = await db.prepare(
|
|
1023
|
+
`SELECT id, source, content_hash FROM ${cmsEntryTbl(event)} WHERE collection_id = ? AND slug = ?`
|
|
1024
|
+
).bind(collectionId, slug).first();
|
|
1025
|
+
if (!existing) {
|
|
1026
|
+
const id = nanoid();
|
|
1027
|
+
await db.prepare(
|
|
1028
|
+
`INSERT INTO ${cmsEntryTbl(event)}
|
|
1029
|
+
(id, collection_id, slug, title, description, cover_image, tags, "order", content_md, content_html, metadata_json, status, source, file_path, content_hash, published_at, created_at, updated_at)
|
|
1030
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'published', 'file', ?, ?, ?, ?, ?)`
|
|
1031
|
+
).bind(
|
|
1032
|
+
id,
|
|
1033
|
+
collectionId,
|
|
1034
|
+
slug,
|
|
1035
|
+
title,
|
|
1036
|
+
description,
|
|
1037
|
+
coverImage,
|
|
1038
|
+
tags,
|
|
1039
|
+
order,
|
|
1040
|
+
body,
|
|
1041
|
+
contentHtml,
|
|
1042
|
+
metadataJson,
|
|
1043
|
+
filePath,
|
|
1044
|
+
fileHash,
|
|
1045
|
+
now,
|
|
1046
|
+
now,
|
|
1047
|
+
now
|
|
1048
|
+
).run();
|
|
1049
|
+
inserted++;
|
|
1050
|
+
} else if (existing.source === "file" && existing.content_hash !== fileHash) {
|
|
1051
|
+
await db.prepare(
|
|
1052
|
+
`UPDATE ${cmsEntryTbl(event)} SET
|
|
1053
|
+
title = ?, description = ?, cover_image = ?, tags = ?, "order" = ?,
|
|
1054
|
+
content_md = ?, content_html = ?, metadata_json = ?,
|
|
1055
|
+
file_path = ?, content_hash = ?, source = 'file', updated_at = ?
|
|
1056
|
+
WHERE id = ?`
|
|
1057
|
+
).bind(
|
|
1058
|
+
title,
|
|
1059
|
+
description,
|
|
1060
|
+
coverImage,
|
|
1061
|
+
tags,
|
|
1062
|
+
order,
|
|
1063
|
+
body,
|
|
1064
|
+
contentHtml,
|
|
1065
|
+
metadataJson,
|
|
1066
|
+
filePath,
|
|
1067
|
+
fileHash,
|
|
1068
|
+
now,
|
|
1069
|
+
existing.id
|
|
1070
|
+
).run();
|
|
1071
|
+
synced++;
|
|
1072
|
+
} else {
|
|
1073
|
+
skipped++;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
for (const src of highPrioritySources) {
|
|
1079
|
+
await syncSource(src);
|
|
1080
|
+
}
|
|
1081
|
+
return { synced, skipped, inserted };
|
|
1082
|
+
}
|