emdash 0.40.0 → 0.41.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/dist/action-token-CbKDcPJi.mjs +26 -0
- package/dist/action-token-CbKDcPJi.mjs.map +1 -0
- package/dist/activation-PtniBLt9.mjs +382 -0
- package/dist/activation-PtniBLt9.mjs.map +1 -0
- package/dist/adapters-C_Tf5x90.d.mts +171 -0
- package/dist/adapters-C_Tf5x90.d.mts.map +1 -0
- package/dist/allowed-origins-U1z4TdEZ.mjs +116 -0
- package/dist/allowed-origins-U1z4TdEZ.mjs.map +1 -0
- package/dist/api/route-utils.d.mts +4 -4
- package/dist/api/route-utils.mjs +46 -45
- package/dist/api/route-utils.mjs.map +1 -1
- package/dist/api/schemas/index.d.mts +2 -2
- package/dist/api/schemas/index.mjs +10 -10
- package/dist/api-CXwQkV_m.mjs +5122 -0
- package/dist/api-CXwQkV_m.mjs.map +1 -0
- package/dist/api-tokens-89WlohEN.mjs +166 -0
- package/dist/api-tokens-89WlohEN.mjs.map +1 -0
- package/dist/apply-Do3KNnUk.mjs +1659 -0
- package/dist/apply-Do3KNnUk.mjs.map +1 -0
- package/dist/approvals-CAX9Yw33.mjs +460 -0
- package/dist/approvals-CAX9Yw33.mjs.map +1 -0
- package/dist/artifact-fetch-B9W4CEST.mjs +659 -0
- package/dist/artifact-fetch-B9W4CEST.mjs.map +1 -0
- package/dist/astro/index.d.mts +14 -14
- package/dist/astro/index.mjs +26 -30
- package/dist/astro/index.mjs.map +1 -1
- package/dist/astro/middleware/auth.d.mts +12 -12
- package/dist/astro/middleware/auth.mjs +10 -10
- package/dist/astro/middleware/media-usage-write-fence.mjs +5 -5
- package/dist/astro/middleware/redirect.mjs +7 -7
- package/dist/astro/middleware/request-context.mjs +3 -3
- package/dist/astro/middleware/setup.mjs +1 -1
- package/dist/astro/middleware.d.mts +12 -12
- package/dist/astro/middleware.d.mts.map +1 -1
- package/dist/astro/middleware.mjs +110 -106
- package/dist/astro/middleware.mjs.map +1 -1
- package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +14 -14
- package/dist/astro/routes/api/admin/allowed-domains/index.mjs +14 -14
- package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +6 -6
- package/dist/astro/routes/api/admin/api-tokens/index.mjs +7 -7
- package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +7 -7
- package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +17 -17
- package/dist/astro/routes/api/admin/byline-fields/index.mjs +17 -17
- package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +17 -17
- package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +23 -23
- package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +23 -23
- package/dist/astro/routes/api/admin/bylines/index.mjs +23 -23
- package/dist/astro/routes/api/admin/comments/_id_/status.mjs +18 -18
- package/dist/astro/routes/api/admin/comments/_id_.mjs +7 -7
- package/dist/astro/routes/api/admin/comments/bulk.mjs +17 -17
- package/dist/astro/routes/api/admin/comments/counts.mjs +7 -7
- package/dist/astro/routes/api/admin/comments/index.mjs +17 -17
- package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +6 -6
- package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +5 -5
- package/dist/astro/routes/api/admin/media-usage/activation.mjs +20 -20
- package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs +22 -22
- package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs +22 -22
- package/dist/astro/routes/api/admin/media-usage/progress.mjs +25 -25
- package/dist/astro/routes/api/admin/media-usage/repair.mjs +31 -31
- package/dist/astro/routes/api/admin/media-usage/work/index.mjs +22 -22
- package/dist/astro/routes/api/admin/media-usage/work/retry.mjs +22 -22
- package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +6 -6
- package/dist/astro/routes/api/admin/oauth-clients/index.mjs +6 -6
- package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +8 -8
- package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +8 -8
- package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +72 -68
- package/dist/astro/routes/api/admin/plugins/_id_/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs +7 -7
- package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs +71 -67
- package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +72 -68
- package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +82 -78
- package/dist/astro/routes/api/admin/plugins/_id_/update.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/index.mjs +72 -68
- package/dist/astro/routes/api/admin/plugins/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +5 -5
- package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +71 -67
- package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +81 -77
- package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +71 -67
- package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +72 -68
- package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +83 -79
- package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs +9 -9
- package/dist/astro/routes/api/admin/plugins/registry/install.mjs +74 -70
- package/dist/astro/routes/api/admin/plugins/registry/install.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/registry/publisher-handle.mjs +7 -7
- package/dist/astro/routes/api/admin/plugins/registry/verify.mjs +72 -68
- package/dist/astro/routes/api/admin/plugins/registry/verify.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/updates.mjs +71 -67
- package/dist/astro/routes/api/admin/plugins/updates.mjs.map +1 -1
- package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.mjs +6 -6
- package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +71 -67
- package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +5 -5
- package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +71 -67
- package/dist/astro/routes/api/admin/themes/marketplace/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/_...path_.mjs +4 -4
- package/dist/astro/routes/api/admin/transfer/approvals/_id_/approve.mjs +40 -40
- package/dist/astro/routes/api/admin/transfer/approvals/_id_/deny.mjs +40 -40
- package/dist/astro/routes/api/admin/transfer/approvals/index.mjs +42 -42
- package/dist/astro/routes/api/admin/transfer/capabilities.mjs +42 -42
- package/dist/astro/routes/api/admin/transfer/exports/_id_/advance.mjs +42 -42
- package/dist/astro/routes/api/admin/transfer/exports/_id_/archive.mjs +43 -43
- package/dist/astro/routes/api/admin/transfer/exports/_id_/files/_...path_.mjs +43 -43
- package/dist/astro/routes/api/admin/transfer/exports/_id_/index.mjs +42 -42
- package/dist/astro/routes/api/admin/transfer/exports/_id_/manifest.mjs +43 -43
- package/dist/astro/routes/api/admin/transfer/exports/index.mjs +44 -44
- package/dist/astro/routes/api/admin/transfer/imports/_id_/abandon.mjs +42 -42
- package/dist/astro/routes/api/admin/transfer/imports/_id_/advance.mjs +42 -42
- package/dist/astro/routes/api/admin/transfer/imports/_id_/analyze.mjs +44 -44
- package/dist/astro/routes/api/admin/transfer/imports/_id_/cancel.mjs +42 -42
- package/dist/astro/routes/api/admin/transfer/imports/_id_/execute.mjs +44 -44
- package/dist/astro/routes/api/admin/transfer/imports/_id_/files/_...path_.mjs +42 -42
- package/dist/astro/routes/api/admin/transfer/imports/_id_/index.mjs +42 -42
- package/dist/astro/routes/api/admin/transfer/imports/_id_/missing.mjs +44 -44
- package/dist/astro/routes/api/admin/transfer/imports/_id_/plan.mjs +42 -42
- package/dist/astro/routes/api/admin/transfer/imports/_id_/receipt.mjs +42 -42
- package/dist/astro/routes/api/admin/transfer/imports/index.mjs +44 -44
- package/dist/astro/routes/api/admin/users/_id_/disable.mjs +5 -5
- package/dist/astro/routes/api/admin/users/_id_/enable.mjs +4 -4
- package/dist/astro/routes/api/admin/users/_id_/index.mjs +15 -15
- package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +6 -6
- package/dist/astro/routes/api/admin/users/index.mjs +14 -14
- package/dist/astro/routes/api/auth/dev-bypass.mjs +6 -6
- package/dist/astro/routes/api/auth/invite/accept.mjs +4 -4
- package/dist/astro/routes/api/auth/invite/complete.mjs +18 -18
- package/dist/astro/routes/api/auth/invite/index.mjs +16 -16
- package/dist/astro/routes/api/auth/invite/register-options.mjs +17 -17
- package/dist/astro/routes/api/auth/logout.mjs +5 -5
- package/dist/astro/routes/api/auth/magic-link/send.mjs +18 -18
- package/dist/astro/routes/api/auth/magic-link/verify.mjs +14 -14
- package/dist/astro/routes/api/auth/me.mjs +15 -15
- package/dist/astro/routes/api/auth/mode.mjs +5 -5
- package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +3 -3
- package/dist/astro/routes/api/auth/oauth/_provider_.mjs +2 -2
- package/dist/astro/routes/api/auth/passkey/_id_.mjs +14 -14
- package/dist/astro/routes/api/auth/passkey/index.mjs +4 -4
- package/dist/astro/routes/api/auth/passkey/options.mjs +19 -19
- package/dist/astro/routes/api/auth/passkey/register/options.mjs +17 -17
- package/dist/astro/routes/api/auth/passkey/register/verify.mjs +18 -18
- package/dist/astro/routes/api/auth/passkey/verify.mjs +18 -18
- package/dist/astro/routes/api/auth/signup/complete.mjs +18 -18
- package/dist/astro/routes/api/auth/signup/request.mjs +17 -17
- package/dist/astro/routes/api/auth/signup/verify.mjs +4 -4
- package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +12 -12
- package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +18 -18
- package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +5 -5
- package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +17 -17
- package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +5 -5
- package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs +17 -17
- package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +5 -5
- package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.mjs +11 -11
- package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +31 -31
- package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +17 -17
- package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.d.mts +1 -2
- package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.d.mts.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs +42 -53
- package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs +34 -29
- package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/parents.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/restore.mjs +5 -5
- package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +5 -5
- package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +17 -17
- package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +25 -24
- package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +5 -5
- package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +17 -17
- package/dist/astro/routes/api/content/_collection_/_id_.d.mts.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_.mjs +18 -18
- package/dist/astro/routes/api/content/_collection_/_id_.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/authors.mjs +5 -5
- package/dist/astro/routes/api/content/_collection_/index.mjs +15 -15
- package/dist/astro/routes/api/content/_collection_/trash.mjs +15 -15
- package/dist/astro/routes/api/dashboard.mjs +10 -9
- package/dist/astro/routes/api/dashboard.mjs.map +1 -1
- package/dist/astro/routes/api/dev/emails.mjs +5 -5
- package/dist/astro/routes/api/health.mjs +6 -6
- package/dist/astro/routes/api/import/probe.d.mts +3 -3
- package/dist/astro/routes/api/import/probe.mjs +23 -23
- package/dist/astro/routes/api/import/wordpress/analyze.mjs +6 -6
- package/dist/astro/routes/api/import/wordpress/execute.d.mts +13 -13
- package/dist/astro/routes/api/import/wordpress/execute.mjs +16 -16
- package/dist/astro/routes/api/import/wordpress/media.d.mts +12 -12
- package/dist/astro/routes/api/import/wordpress/media.mjs +19 -19
- package/dist/astro/routes/api/import/wordpress/prepare.mjs +18 -18
- package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +13 -13
- package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +28 -28
- package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
- package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +23 -23
- package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +13 -13
- package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +34 -34
- package/dist/astro/routes/api/manifest.mjs +6 -6
- package/dist/astro/routes/api/mcp.mjs +98 -118
- package/dist/astro/routes/api/mcp.mjs.map +1 -1
- package/dist/astro/routes/api/media/_id_/confirm.mjs +19 -19
- package/dist/astro/routes/api/media/_id_/replace.mjs +16 -16
- package/dist/astro/routes/api/media/_id_/upload.mjs +9 -9
- package/dist/astro/routes/api/media/_id_/usage.mjs +33 -33
- package/dist/astro/routes/api/media/_id_.mjs +31 -31
- package/dist/astro/routes/api/media/asset/_id_/_filename_.mjs +6 -6
- package/dist/astro/routes/api/media/file/_...key_.mjs +9 -9
- package/dist/astro/routes/api/media/folders/_id_.mjs +16 -16
- package/dist/astro/routes/api/media/folders/index.mjs +16 -16
- package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +5 -5
- package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +5 -5
- package/dist/astro/routes/api/media/providers/index.mjs +5 -5
- package/dist/astro/routes/api/media/upload-url.mjs +18 -18
- package/dist/astro/routes/api/media.mjs +35 -35
- package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +17 -17
- package/dist/astro/routes/api/menus/_name_/items.mjs +17 -17
- package/dist/astro/routes/api/menus/_name_/reorder.mjs +17 -17
- package/dist/astro/routes/api/menus/_name_/translations.mjs +17 -17
- package/dist/astro/routes/api/menus/_name_.mjs +17 -17
- package/dist/astro/routes/api/menus/index.mjs +17 -17
- package/dist/astro/routes/api/oauth/authorize.mjs +6 -6
- package/dist/astro/routes/api/oauth/device/authorize.d.mts +2 -1
- package/dist/astro/routes/api/oauth/device/authorize.d.mts.map +1 -1
- package/dist/astro/routes/api/oauth/device/authorize.mjs +23 -9
- package/dist/astro/routes/api/oauth/device/authorize.mjs.map +1 -1
- package/dist/astro/routes/api/oauth/device/code.mjs +11 -11
- package/dist/astro/routes/api/oauth/device/token.mjs +10 -10
- package/dist/astro/routes/api/oauth/register.mjs +5 -5
- package/dist/astro/routes/api/oauth/token/refresh.mjs +8 -8
- package/dist/astro/routes/api/oauth/token/revoke.mjs +8 -8
- package/dist/astro/routes/api/oauth/token.mjs +8 -8
- package/dist/astro/routes/api/openapi.json.mjs +20 -20
- package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +11 -11
- package/dist/astro/routes/api/redirects/404s/index.mjs +19 -19
- package/dist/astro/routes/api/redirects/404s/summary.mjs +19 -19
- package/dist/astro/routes/api/redirects/_id_.mjs +19 -19
- package/dist/astro/routes/api/redirects/index.mjs +19 -19
- package/dist/astro/routes/api/relations/_id_/index.mjs +34 -29
- package/dist/astro/routes/api/relations/_id_/index.mjs.map +1 -1
- package/dist/astro/routes/api/relations/index.mjs +36 -31
- package/dist/astro/routes/api/relations/index.mjs.map +1 -1
- package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +5 -5
- package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +5 -5
- package/dist/astro/routes/api/schema/block-types/_slug_/index.mjs +71 -67
- package/dist/astro/routes/api/schema/block-types/_slug_/index.mjs.map +1 -1
- package/dist/astro/routes/api/schema/block-types/_slug_/versions/_version_/activate.mjs +71 -67
- package/dist/astro/routes/api/schema/block-types/_slug_/versions/_version_/activate.mjs.map +1 -1
- package/dist/astro/routes/api/schema/block-types/index.mjs +71 -67
- package/dist/astro/routes/api/schema/block-types/index.mjs.map +1 -1
- package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +73 -69
- package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs.map +1 -1
- package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +71 -67
- package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs.map +1 -1
- package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs +71 -67
- package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs.map +1 -1
- package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +71 -67
- package/dist/astro/routes/api/schema/collections/_slug_/index.mjs.map +1 -1
- package/dist/astro/routes/api/schema/collections/index.mjs +71 -67
- package/dist/astro/routes/api/schema/collections/index.mjs.map +1 -1
- package/dist/astro/routes/api/schema/collections/reorder.mjs +71 -67
- package/dist/astro/routes/api/schema/collections/reorder.mjs.map +1 -1
- package/dist/astro/routes/api/schema/index.mjs +16 -16
- package/dist/astro/routes/api/schema/orphans/_slug_.mjs +71 -67
- package/dist/astro/routes/api/schema/orphans/_slug_.mjs.map +1 -1
- package/dist/astro/routes/api/schema/orphans/index.mjs +71 -67
- package/dist/astro/routes/api/schema/orphans/index.mjs.map +1 -1
- package/dist/astro/routes/api/search/enable.mjs +19 -19
- package/dist/astro/routes/api/search/index.mjs +18 -18
- package/dist/astro/routes/api/search/rebuild.mjs +19 -19
- package/dist/astro/routes/api/search/stats.mjs +9 -9
- package/dist/astro/routes/api/search/suggest.mjs +18 -18
- package/dist/astro/routes/api/sections/_slug_.mjs +18 -18
- package/dist/astro/routes/api/sections/index.mjs +18 -18
- package/dist/astro/routes/api/settings/backups/archives/_name_.mjs +7 -7
- package/dist/astro/routes/api/settings/backups/archives/index.mjs +7 -7
- package/dist/astro/routes/api/settings/backups/export.mjs +7 -7
- package/dist/astro/routes/api/settings/backups/index.mjs +8 -8
- package/dist/astro/routes/api/settings/email.mjs +6 -6
- package/dist/astro/routes/api/settings.mjs +21 -21
- package/dist/astro/routes/api/setup/admin-verify.mjs +19 -19
- package/dist/astro/routes/api/setup/admin.mjs +18 -18
- package/dist/astro/routes/api/setup/dev-bypass.mjs +45 -39
- package/dist/astro/routes/api/setup/dev-bypass.mjs.map +1 -1
- package/dist/astro/routes/api/setup/dev-reset.mjs +4 -4
- package/dist/astro/routes/api/setup/index.d.mts.map +1 -1
- package/dist/astro/routes/api/setup/index.mjs +80 -49
- package/dist/astro/routes/api/setup/index.mjs.map +1 -1
- package/dist/astro/routes/api/setup/status.mjs +6 -6
- package/dist/astro/routes/api/snapshot.mjs +9 -9
- package/dist/astro/routes/api/snapshot.mjs.map +1 -1
- package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs +23 -23
- package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +23 -23
- package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +23 -23
- package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +23 -23
- package/dist/astro/routes/api/taxonomies/_name_/translations.mjs +22 -22
- package/dist/astro/routes/api/taxonomies/_name_.mjs +23 -23
- package/dist/astro/routes/api/taxonomies/bulk-tag.mjs +36 -35
- package/dist/astro/routes/api/taxonomies/bulk-tag.mjs.map +1 -1
- package/dist/astro/routes/api/taxonomies/index.mjs +23 -23
- package/dist/astro/routes/api/themes/preview.mjs +6 -6
- package/dist/astro/routes/api/typegen.mjs +8 -8
- package/dist/astro/routes/api/visual-editing/action-token.mjs +6 -6
- package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.mjs +19 -19
- package/dist/astro/routes/api/visual-editing/toolbar-labels.mjs +4 -4
- package/dist/astro/routes/api/well-known/auth.mjs +1 -1
- package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +2 -2
- package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +2 -2
- package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +16 -16
- package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +19 -19
- package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +19 -19
- package/dist/astro/routes/api/widget-areas/_name_.mjs +9 -9
- package/dist/astro/routes/api/widget-areas/index.mjs +19 -19
- package/dist/astro/routes/api/widget-components.mjs +5 -5
- package/dist/astro/routes/robots.txt.mjs +6 -6
- package/dist/astro/routes/sitemap-_collection_.xml.mjs +9 -9
- package/dist/astro/routes/sitemap.xml.mjs +7 -7
- package/dist/astro/types.d.mts +28 -18
- package/dist/astro/types.d.mts.map +1 -1
- package/dist/audit-CrgmE9LE.mjs +127 -0
- package/dist/audit-CrgmE9LE.mjs.map +1 -0
- package/dist/auth/providers/github.d.mts +1 -1
- package/dist/auth/providers/google.d.mts +1 -1
- package/dist/authoritative-records-C2YzIdbu.mjs +5172 -0
- package/dist/authoritative-records-C2YzIdbu.mjs.map +1 -0
- package/dist/authorize-WgdKF8QY.mjs +49 -0
- package/dist/authorize-WgdKF8QY.mjs.map +1 -0
- package/dist/backup-Ck8_lMO3.mjs +246 -0
- package/dist/backup-Ck8_lMO3.mjs.map +1 -0
- package/dist/block-types-BQ90asVI.mjs +132 -0
- package/dist/block-types-BQ90asVI.mjs.map +1 -0
- package/dist/block-values-ACFqgB1D.mjs +175 -0
- package/dist/block-values-ACFqgB1D.mjs.map +1 -0
- package/dist/bundle-Db1iNMv_.mjs +667 -0
- package/dist/bundle-Db1iNMv_.mjs.map +1 -0
- package/dist/byline-BayaYGoj.mjs +909 -0
- package/dist/byline-BayaYGoj.mjs.map +1 -0
- package/dist/byline-fields-B8HH-35f.mjs +254 -0
- package/dist/byline-fields-B8HH-35f.mjs.map +1 -0
- package/dist/byline-fields-hMPjf6Eu.mjs +123 -0
- package/dist/byline-fields-hMPjf6Eu.mjs.map +1 -0
- package/dist/byline-registry-B_EK_TQf.mjs +406 -0
- package/dist/byline-registry-B_EK_TQf.mjs.map +1 -0
- package/dist/bylines-DFAaFXWi.mjs +214 -0
- package/dist/bylines-DFAaFXWi.mjs.map +1 -0
- package/dist/bylines-DkIxUxmr.mjs +232 -0
- package/dist/bylines-DkIxUxmr.mjs.map +1 -0
- package/dist/cache-DkvhQ8XE.mjs +108 -0
- package/dist/cache-DkvhQ8XE.mjs.map +1 -0
- package/dist/canonical-CcSuuTlH.mjs +174 -0
- package/dist/canonical-CcSuuTlH.mjs.map +1 -0
- package/dist/capture-triggers-DJEoOTOq.mjs +362 -0
- package/dist/capture-triggers-DJEoOTOq.mjs.map +1 -0
- package/dist/challenge-store-CvBl81AQ.mjs +51 -0
- package/dist/challenge-store-CvBl81AQ.mjs.map +1 -0
- package/dist/checksum-CClweQzI.mjs +162 -0
- package/dist/checksum-CClweQzI.mjs.map +1 -0
- package/dist/chrome-tags-D5caJwwp.mjs +24 -0
- package/dist/chrome-tags-D5caJwwp.mjs.map +1 -0
- package/dist/chunks-DwBaj8aT.mjs +25 -0
- package/dist/chunks-DwBaj8aT.mjs.map +1 -0
- package/dist/cli/index.mjs +374 -761
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/cf-access.d.mts +1 -1
- package/dist/client/index.d.mts +18 -18
- package/dist/client/index.mjs +2 -2
- package/dist/collection-deletion-CLCdXsnV.mjs +436 -0
- package/dist/collection-deletion-CLCdXsnV.mjs.map +1 -0
- package/dist/collection-deletion-processor-hNw8x01F.mjs +217 -0
- package/dist/collection-deletion-processor-hNw8x01F.mjs.map +1 -0
- package/dist/collection-slugs-cache-CUuiduLq.mjs +85 -0
- package/dist/collection-slugs-cache-CUuiduLq.mjs.map +1 -0
- package/dist/comment-D2uvL63j.mjs +313 -0
- package/dist/comment-D2uvL63j.mjs.map +1 -0
- package/dist/comment-reaction-DevUuzg4.mjs +85 -0
- package/dist/comment-reaction-DevUuzg4.mjs.map +1 -0
- package/dist/comments-Cq0s7_hO.mjs +195 -0
- package/dist/comments-Cq0s7_hO.mjs.map +1 -0
- package/dist/comments-M4EDYAHw.mjs +99 -0
- package/dist/comments-M4EDYAHw.mjs.map +1 -0
- package/dist/components-CuIGwXMs.mjs +108 -0
- package/dist/components-CuIGwXMs.mjs.map +1 -0
- package/dist/config-52Ea5IWt.d.mts +39 -0
- package/dist/config-52Ea5IWt.d.mts.map +1 -0
- package/dist/config-CCz3xOLc.mjs +242 -0
- package/dist/config-CCz3xOLc.mjs.map +1 -0
- package/dist/config-D3d5Qudq.d.mts +6669 -0
- package/dist/config-D3d5Qudq.d.mts.map +1 -0
- package/dist/content-CbnufDsM.mjs +2018 -0
- package/dist/content-CbnufDsM.mjs.map +1 -0
- package/dist/content-list-query-D_7B1FE5.d.mts +26 -0
- package/dist/content-list-query-D_7B1FE5.d.mts.map +1 -0
- package/dist/content-policy-CYu6K1KB.mjs +46 -0
- package/dist/content-policy-CYu6K1KB.mjs.map +1 -0
- package/dist/content-repair-DlDUgFGp.mjs +442 -0
- package/dist/content-repair-DlDUgFGp.mjs.map +1 -0
- package/dist/context-CGQLA1-a.mjs +1922 -0
- package/dist/context-CGQLA1-a.mjs.map +1 -0
- package/dist/cron-c4D5C5Fx.mjs +284 -0
- package/dist/cron-c4D5C5Fx.mjs.map +1 -0
- package/dist/dashboard-CBq9kmOn.mjs +151 -0
- package/dist/dashboard-CBq9kmOn.mjs.map +1 -0
- package/dist/db/index.d.mts +3 -3
- package/dist/db/index.mjs +1 -1
- package/dist/db/libsql-migrations.d.mts +1 -1
- package/dist/db/libsql-migrations.mjs +4 -4
- package/dist/db/libsql.d.mts +1 -1
- package/dist/db/postgres-migrations.d.mts +1 -1
- package/dist/db/postgres-migrations.mjs +4 -4
- package/dist/db/postgres.d.mts +1 -1
- package/dist/db/sqlite-migrations.d.mts +1 -1
- package/dist/db/sqlite-migrations.mjs +4 -4
- package/dist/db/sqlite.d.mts +1 -1
- package/dist/db/sqlite.mjs +1 -1
- package/dist/default-DPsys51U.mjs +81 -0
- package/dist/default-DPsys51U.mjs.map +1 -0
- package/dist/deferred-tasks-CZ7rzBdo.d.mts +9 -0
- package/dist/deferred-tasks-CZ7rzBdo.d.mts.map +1 -0
- package/dist/dev-typegen-HRxwLRcT.mjs +29 -0
- package/dist/dev-typegen-HRxwLRcT.mjs.map +1 -0
- package/dist/device-flow-OcSqE9uY.mjs +521 -0
- package/dist/device-flow-OcSqE9uY.mjs.map +1 -0
- package/dist/digest-DVZ--cE9.mjs +194 -0
- package/dist/digest-DVZ--cE9.mjs.map +1 -0
- package/dist/direct-executor-DyjAqkpT.mjs +104 -0
- package/dist/direct-executor-DyjAqkpT.mjs.map +1 -0
- package/dist/dist-FPR93_xf.mjs +810 -0
- package/dist/dist-FPR93_xf.mjs.map +1 -0
- package/dist/email-console-DyQIgEnz.mjs +50 -0
- package/dist/email-console-DyQIgEnz.mjs.map +1 -0
- package/dist/email-locale-BYb16rVd.mjs +25 -0
- package/dist/email-locale-BYb16rVd.mjs.map +1 -0
- package/dist/emdash-runtime-CrzxJFmF.mjs +4214 -0
- package/dist/emdash-runtime-CrzxJFmF.mjs.map +1 -0
- package/dist/enrich-DBtCncE2.mjs +194 -0
- package/dist/enrich-DBtCncE2.mjs.map +1 -0
- package/dist/entry-lock-BN5y4YbO.d.mts +4481 -0
- package/dist/entry-lock-BN5y4YbO.d.mts.map +1 -0
- package/dist/entry-lock-BaRBHCsH.mjs +1173 -0
- package/dist/entry-lock-BaRBHCsH.mjs.map +1 -0
- package/dist/entry-lock-C6NcnZPV.mjs +163 -0
- package/dist/entry-lock-C6NcnZPV.mjs.map +1 -0
- package/dist/entry-locks-BTyQLdbC.mjs +167 -0
- package/dist/entry-locks-BTyQLdbC.mjs.map +1 -0
- package/dist/error-BfsNNrIE.mjs +90 -0
- package/dist/error-BfsNNrIE.mjs.map +1 -0
- package/dist/errors-BN1QAnEY.mjs +460 -0
- package/dist/errors-BN1QAnEY.mjs.map +1 -0
- package/dist/errors-Bt3goF8I.mjs +120 -0
- package/dist/errors-Bt3goF8I.mjs.map +1 -0
- package/dist/escape-BveidMa2.mjs +9 -0
- package/dist/escape-BveidMa2.mjs.map +1 -0
- package/dist/fence-Bb_IbCxI.mjs +162 -0
- package/dist/fence-Bb_IbCxI.mjs.map +1 -0
- package/dist/field-defs-cache-CsZctvbu.mjs +77 -0
- package/dist/field-defs-cache-CsZctvbu.mjs.map +1 -0
- package/dist/field-map-6m9rF49t.mjs +83 -0
- package/dist/field-map-6m9rF49t.mjs.map +1 -0
- package/dist/focal-point-CZ3d1wK5.mjs +23 -0
- package/dist/focal-point-CZ3d1wK5.mjs.map +1 -0
- package/dist/fts-manager-CCaZTp8y.mjs +443 -0
- package/dist/fts-manager-CCaZTp8y.mjs.map +1 -0
- package/dist/gc-xowRjczI.mjs +75 -0
- package/dist/gc-xowRjczI.mjs.map +1 -0
- package/dist/hash-COVK27Pc.mjs +37 -0
- package/dist/hash-COVK27Pc.mjs.map +1 -0
- package/dist/hook-result-CYSk0XFe.d.mts +31 -0
- package/dist/hook-result-CYSk0XFe.d.mts.map +1 -0
- package/dist/hreflang-CChPV7jx.mjs +105 -0
- package/dist/hreflang-CChPV7jx.mjs.map +1 -0
- package/dist/hreflang-DRslq3QI.d.mts +50 -0
- package/dist/hreflang-DRslq3QI.d.mts.map +1 -0
- package/dist/http-route-dispatch-CAdp2onn.mjs +339 -0
- package/dist/http-route-dispatch-CAdp2onn.mjs.map +1 -0
- package/dist/identity-NVTOOQyq.mjs +35 -0
- package/dist/identity-NVTOOQyq.mjs.map +1 -0
- package/dist/import-wpSO2N0x.mjs +2020 -0
- package/dist/import-wpSO2N0x.mjs.map +1 -0
- package/dist/index-CDs2wq4X.d.mts +623 -0
- package/dist/index-CDs2wq4X.d.mts.map +1 -0
- package/dist/index.d.mts +24 -24
- package/dist/index.mjs +103 -101
- package/dist/install-finalization-D9R9R-W8.mjs +58 -0
- package/dist/install-finalization-D9R9R-W8.mjs.map +1 -0
- package/dist/keys-Bck6LBfF.mjs +61 -0
- package/dist/keys-Bck6LBfF.mjs.map +1 -0
- package/dist/kinds-CYmRESWj.mjs +974 -0
- package/dist/kinds-CYmRESWj.mjs.map +1 -0
- package/dist/lifecycle-C815ZQfV.mjs +25 -0
- package/dist/lifecycle-C815ZQfV.mjs.map +1 -0
- package/dist/load-D99axixL.mjs +28 -0
- package/dist/load-D99axixL.mjs.map +1 -0
- package/dist/loader-CrRPfkHS.mjs +1197 -0
- package/dist/loader-CrRPfkHS.mjs.map +1 -0
- package/dist/loops-DMKlygqX.mjs +203 -0
- package/dist/loops-DMKlygqX.mjs.map +1 -0
- package/dist/manifest-builder-BQzCHNgB.mjs +189 -0
- package/dist/manifest-builder-BQzCHNgB.mjs.map +1 -0
- package/dist/manifest-schema-Ci2gmd0u.mjs +492 -0
- package/dist/manifest-schema-Ci2gmd0u.mjs.map +1 -0
- package/dist/media/image-endpoint.mjs +1 -1
- package/dist/media/index.d.mts +1 -1
- package/dist/media/index.mjs +4 -4
- package/dist/media/local-runtime.d.mts +14 -14
- package/dist/media/local-runtime.mjs +6 -6
- package/dist/media-BUQePMxP.mjs +373 -0
- package/dist/media-BUQePMxP.mjs.map +1 -0
- package/dist/media-DH8ibNlY.mjs +294 -0
- package/dist/media-DH8ibNlY.mjs.map +1 -0
- package/dist/media-OEIQ3bVc.mjs +408 -0
- package/dist/media-OEIQ3bVc.mjs.map +1 -0
- package/dist/media-allowlist-pYtaBA95.mjs +44 -0
- package/dist/media-allowlist-pYtaBA95.mjs.map +1 -0
- package/dist/media-folders-Bf8_s4de.mjs +210 -0
- package/dist/media-folders-Bf8_s4de.mjs.map +1 -0
- package/dist/media-url-C6klEuNd.mjs +43 -0
- package/dist/media-url-C6klEuNd.mjs.map +1 -0
- package/dist/media-usage-D7Y64m6v.mjs +1629 -0
- package/dist/media-usage-D7Y64m6v.mjs.map +1 -0
- package/dist/media-usage-activation-DrqbmgLA.mjs +78 -0
- package/dist/media-usage-activation-DrqbmgLA.mjs.map +1 -0
- package/dist/media-usage-work-DommYhYA.mjs +152 -0
- package/dist/media-usage-work-DommYhYA.mjs.map +1 -0
- package/dist/media-usage-work-HU63hNDu.mjs +586 -0
- package/dist/media-usage-work-HU63hNDu.mjs.map +1 -0
- package/dist/menus-BQfusWEC.mjs +3608 -0
- package/dist/menus-BQfusWEC.mjs.map +1 -0
- package/dist/menus-BtwjQt5s.mjs +753 -0
- package/dist/menus-BtwjQt5s.mjs.map +1 -0
- package/dist/menus-p_M1V7J_.mjs +139 -0
- package/dist/menus-p_M1V7J_.mjs.map +1 -0
- package/dist/migrations/index.d.mts +1 -1
- package/dist/migrations/index.mjs +3 -3
- package/dist/mime-C94qBG-P.mjs +36 -0
- package/dist/mime-C94qBG-P.mjs.map +1 -0
- package/dist/mode-DpYW3w6U.mjs +23 -0
- package/dist/mode-DpYW3w6U.mjs.map +1 -0
- package/dist/node-sqlite-compat-pWFw0lcc.mjs +46 -0
- package/dist/node-sqlite-compat-pWFw0lcc.mjs.map +1 -0
- package/dist/normalize-DduyxBjf.mjs +191 -0
- package/dist/normalize-DduyxBjf.mjs.map +1 -0
- package/dist/oauth-authorization-DAXsH1H9.mjs +274 -0
- package/dist/oauth-authorization-DAXsH1H9.mjs.map +1 -0
- package/dist/oauth-clients-DENiDQri.mjs +266 -0
- package/dist/oauth-clients-DENiDQri.mjs.map +1 -0
- package/dist/oauth-state-store-y8mEYVq9.mjs +50 -0
- package/dist/oauth-state-store-y8mEYVq9.mjs.map +1 -0
- package/dist/oauth-user-lookup-CtTYAy-O.mjs +26 -0
- package/dist/oauth-user-lookup-CtTYAy-O.mjs.map +1 -0
- package/dist/object-cache/memory.d.mts +1 -1
- package/dist/options-BYa1FgIM.d.mts +81 -0
- package/dist/options-BYa1FgIM.d.mts.map +1 -0
- package/dist/page/index.d.mts +2 -2
- package/dist/page/index.mjs +5 -5
- package/dist/parse-CORGGhHf.mjs +81 -0
- package/dist/parse-CORGGhHf.mjs.map +1 -0
- package/dist/parse-avNM1xWV.d.mts +168 -0
- package/dist/parse-avNM1xWV.d.mts.map +1 -0
- package/dist/passkey-config-Dih5YeIS.mjs +46 -0
- package/dist/passkey-config-Dih5YeIS.mjs.map +1 -0
- package/dist/paths-d51RFm8M.mjs +77 -0
- package/dist/paths-d51RFm8M.mjs.map +1 -0
- package/dist/patterns-CoqlXUvk.mjs +145 -0
- package/dist/patterns-CoqlXUvk.mjs.map +1 -0
- package/dist/placeholder-D2aksPMF.d.mts +306 -0
- package/dist/placeholder-D2aksPMF.d.mts.map +1 -0
- package/dist/plan-DqeZKuaR.mjs +135 -0
- package/dist/plan-DqeZKuaR.mjs.map +1 -0
- package/dist/plugin-test-runtime.d.mts +14 -14
- package/dist/plugin-test-runtime.mjs +110 -107
- package/dist/plugin-types.d.mts +2 -2
- package/dist/plugin-utils.d.mts +12 -12
- package/dist/plugins/adapt-sandbox-entry.d.mts +12 -12
- package/dist/plugins/adapt-sandbox-entry.mjs +3 -3
- package/dist/plugins/host.d.mts +5 -5
- package/dist/plugins/host.mjs +42 -41
- package/dist/plugins-Bb7oqjQA.mjs +277 -0
- package/dist/plugins-Bb7oqjQA.mjs.map +1 -0
- package/dist/policy-BcEqut3n.mjs +45 -0
- package/dist/policy-BcEqut3n.mjs.map +1 -0
- package/dist/portable-text-DXE8ymtD.mjs +307 -0
- package/dist/portable-text-DXE8ymtD.mjs.map +1 -0
- package/dist/preview-DEDWbwA_.mjs +107 -0
- package/dist/preview-DEDWbwA_.mjs.map +1 -0
- package/dist/protocol-BJbTzvwl.d.mts +61 -0
- package/dist/protocol-BJbTzvwl.d.mts.map +1 -0
- package/dist/public-submission-D9c9S14m.mjs +250 -0
- package/dist/public-submission-D9c9S14m.mjs.map +1 -0
- package/dist/public-url-CIRe-2T6.mjs +101 -0
- package/dist/public-url-CIRe-2T6.mjs.map +1 -0
- package/dist/query-BzifXlPS.mjs +1156 -0
- package/dist/query-BzifXlPS.mjs.map +1 -0
- package/dist/query-OzMJ6vJP.mjs +41 -0
- package/dist/query-OzMJ6vJP.mjs.map +1 -0
- package/dist/rate-limit-Csp60Vik.mjs +120 -0
- package/dist/rate-limit-Csp60Vik.mjs.map +1 -0
- package/dist/receipt-B-aU4hpJ.mjs +43 -0
- package/dist/receipt-B-aU4hpJ.mjs.map +1 -0
- package/dist/redirect-CDSw1sU3.mjs +17 -0
- package/dist/redirect-CDSw1sU3.mjs.map +1 -0
- package/dist/redirect-D1ArbO85.mjs +411 -0
- package/dist/redirect-D1ArbO85.mjs.map +1 -0
- package/dist/redirects-BjTwDTsV.mjs +148 -0
- package/dist/redirects-BjTwDTsV.mjs.map +1 -0
- package/dist/redirects-Ck50kH3n.mjs +446 -0
- package/dist/redirects-Ck50kH3n.mjs.map +1 -0
- package/dist/registry/testing.mjs +3 -3
- package/dist/registry-CFcNCayZ.mjs +6754 -0
- package/dist/registry-CFcNCayZ.mjs.map +1 -0
- package/dist/relations-Cfaa1fDl.mjs +776 -0
- package/dist/relations-Cfaa1fDl.mjs.map +1 -0
- package/dist/request-cache-iHRlHx1d.mjs +104 -0
- package/dist/request-cache-iHRlHx1d.mjs.map +1 -0
- package/dist/request-context.d.mts +1 -1
- package/dist/request-meta-D47mqyev.mjs +141 -0
- package/dist/request-meta-D47mqyev.mjs.map +1 -0
- package/dist/resolve-BPE8sMvx.mjs +99 -0
- package/dist/resolve-BPE8sMvx.mjs.map +1 -0
- package/dist/resolve-C0s1E_fH.mjs +199 -0
- package/dist/resolve-C0s1E_fH.mjs.map +1 -0
- package/dist/revision-j1p4-bOj.mjs +302 -0
- package/dist/revision-j1p4-bOj.mjs.map +1 -0
- package/dist/route-wire-C9PJV9aL.mjs +197 -0
- package/dist/route-wire-C9PJV9aL.mjs.map +1 -0
- package/dist/routes-lyYw0mMf.mjs +272 -0
- package/dist/routes-lyYw0mMf.mjs.map +1 -0
- package/dist/runner-B3eyB9Gb.mjs +6121 -0
- package/dist/runner-B3eyB9Gb.mjs.map +1 -0
- package/dist/runner-DoYH2Jcu.d.mts +68 -0
- package/dist/runner-DoYH2Jcu.d.mts.map +1 -0
- package/dist/runtime.d.mts +13 -13
- package/dist/runtime.mjs +3 -3
- package/dist/schema-BAayK46S.mjs +13 -0
- package/dist/schema-BAayK46S.mjs.map +1 -0
- package/dist/schema-Gqcl-8G4.mjs +815 -0
- package/dist/schema-Gqcl-8G4.mjs.map +1 -0
- package/dist/scopes-BqPOKoKf.mjs +34 -0
- package/dist/scopes-BqPOKoKf.mjs.map +1 -0
- package/dist/search-YJKPIEV6.mjs +448 -0
- package/dist/search-YJKPIEV6.mjs.map +1 -0
- package/dist/sections-BR_e-wK5.mjs +346 -0
- package/dist/sections-BR_e-wK5.mjs.map +1 -0
- package/dist/seed/index.d.mts +2 -2
- package/dist/seed/index.mjs +37 -31
- package/dist/seo/index.d.mts +3 -3
- package/dist/seo/index.mjs +22 -21
- package/dist/seo/index.mjs.map +1 -1
- package/dist/seo-Dsj8hy3j.mjs +114 -0
- package/dist/seo-Dsj8hy3j.mjs.map +1 -0
- package/dist/seo-XvH4LNNp.mjs +133 -0
- package/dist/seo-XvH4LNNp.mjs.map +1 -0
- package/dist/service-BsVG05gS.mjs +150 -0
- package/dist/service-BsVG05gS.mjs.map +1 -0
- package/dist/session-user-DgKbYrlj.mjs +51 -0
- package/dist/session-user-DgKbYrlj.mjs.map +1 -0
- package/dist/settings-CNPUntkh.mjs +51 -0
- package/dist/settings-CNPUntkh.mjs.map +1 -0
- package/dist/settings-D5EHi0Tk.mjs +439 -0
- package/dist/settings-D5EHi0Tk.mjs.map +1 -0
- package/dist/settings-DSfE7wOa.mjs +61 -0
- package/dist/settings-DSfE7wOa.mjs.map +1 -0
- package/dist/setup-complete-B8W8sJ9v.mjs +26 -0
- package/dist/setup-complete-B8W8sJ9v.mjs.map +1 -0
- package/dist/setup-nonce-DnSBP260.mjs +25 -0
- package/dist/setup-nonce-DnSBP260.mjs.map +1 -0
- package/dist/site-settings-NGzdrt7O.mjs +50 -0
- package/dist/site-settings-NGzdrt7O.mjs.map +1 -0
- package/dist/site-url-D6JB7tLW.mjs +16 -0
- package/dist/site-url-D6JB7tLW.mjs.map +1 -0
- package/dist/snapshot-CdcwwWAf.mjs +414 -0
- package/dist/snapshot-CdcwwWAf.mjs.map +1 -0
- package/dist/ssrf-Dv0_tRpo.mjs +406 -0
- package/dist/ssrf-Dv0_tRpo.mjs.map +1 -0
- package/dist/stage-CUjhED3P.mjs +662 -0
- package/dist/stage-CUjhED3P.mjs.map +1 -0
- package/dist/staged-C36IWXff.mjs +659 -0
- package/dist/staged-C36IWXff.mjs.map +1 -0
- package/dist/state-CKouMCSY.mjs +153 -0
- package/dist/state-CKouMCSY.mjs.map +1 -0
- package/dist/status-lzyj4Uu7.mjs +30 -0
- package/dist/status-lzyj4Uu7.mjs.map +1 -0
- package/dist/storage/local.d.mts +1 -1
- package/dist/storage/local.mjs +1 -1
- package/dist/storage/s3.d.mts +1 -1
- package/dist/storage/s3.mjs +1 -1
- package/dist/storage-query-B-cWcTjJ.d.mts +1594 -0
- package/dist/storage-query-B-cWcTjJ.d.mts.map +1 -0
- package/dist/tar-DsTXX6ch.mjs +449 -0
- package/dist/tar-DsTXX6ch.mjs.map +1 -0
- package/dist/target-DLQCwp_Z.mjs +27 -0
- package/dist/target-DLQCwp_Z.mjs.map +1 -0
- package/dist/taxonomies-BlAjr4BL.mjs +697 -0
- package/dist/taxonomies-BlAjr4BL.mjs.map +1 -0
- package/dist/taxonomies-Byyo7LOZ.mjs +939 -0
- package/dist/taxonomies-Byyo7LOZ.mjs.map +1 -0
- package/dist/taxonomy-CKDwM61Y.mjs +525 -0
- package/dist/taxonomy-CKDwM61Y.mjs.map +1 -0
- package/dist/tokens-BojXlk49.mjs +171 -0
- package/dist/tokens-BojXlk49.mjs.map +1 -0
- package/dist/transaction-DLPQWik1.mjs +29 -0
- package/dist/transaction-DLPQWik1.mjs.map +1 -0
- package/dist/transfer-XSTh2BCr.mjs +8706 -0
- package/dist/transfer-XSTh2BCr.mjs.map +1 -0
- package/dist/transfer-download-DkoCDA9d.mjs +33 -0
- package/dist/transfer-download-DkoCDA9d.mjs.map +1 -0
- package/dist/transfer-iQ26J-RT.mjs +166 -0
- package/dist/transfer-iQ26J-RT.mjs.map +1 -0
- package/dist/transformations-C7RQabKQ.mjs +196 -0
- package/dist/transformations-C7RQabKQ.mjs.map +1 -0
- package/dist/transport-D3RulfD6.mjs +136 -0
- package/dist/transport-D3RulfD6.mjs.map +1 -0
- package/dist/transport-DhlZlf4D.d.mts +42 -0
- package/dist/transport-DhlZlf4D.d.mts.map +1 -0
- package/dist/trusted-proxy-B6ECOZJc.mjs +51 -0
- package/dist/trusted-proxy-B6ECOZJc.mjs.map +1 -0
- package/dist/turnstile-lqUiY7lP.mjs +53 -0
- package/dist/turnstile-lqUiY7lP.mjs.map +1 -0
- package/dist/types-4Dn9bZhu.mjs +77 -0
- package/dist/types-4Dn9bZhu.mjs.map +1 -0
- package/dist/types-5LSo7PPx.d.mts +85 -0
- package/dist/types-5LSo7PPx.d.mts.map +1 -0
- package/dist/types-BQ3hwYJT.d.mts +896 -0
- package/dist/types-BQ3hwYJT.d.mts.map +1 -0
- package/dist/types-BYEk7qo3.d.mts +198 -0
- package/dist/types-BYEk7qo3.d.mts.map +1 -0
- package/dist/types-CJKsWVFR.mjs +199 -0
- package/dist/types-CJKsWVFR.mjs.map +1 -0
- package/dist/types-Ca_w8mmY.d.mts +363 -0
- package/dist/types-Ca_w8mmY.d.mts.map +1 -0
- package/dist/types-CkE41ZAG.mjs +18 -0
- package/dist/types-CkE41ZAG.mjs.map +1 -0
- package/dist/types-D0aJW2uR.d.mts +1641 -0
- package/dist/types-D0aJW2uR.d.mts.map +1 -0
- package/dist/types-DbpN4Qto.d.mts +372 -0
- package/dist/types-DbpN4Qto.d.mts.map +1 -0
- package/dist/types-ILDI1sdY.mjs +16 -0
- package/dist/types-ILDI1sdY.mjs.map +1 -0
- package/dist/types-OC5c-edM.mjs +22 -0
- package/dist/types-OC5c-edM.mjs.map +1 -0
- package/dist/types-aOOxRSx6.mjs +103 -0
- package/dist/types-aOOxRSx6.mjs.map +1 -0
- package/dist/types-m1WbUffD.d.mts +198 -0
- package/dist/types-m1WbUffD.d.mts.map +1 -0
- package/dist/types-uxLoPBio.d.mts +124 -0
- package/dist/types-uxLoPBio.d.mts.map +1 -0
- package/dist/types-we5uR-tV.d.mts +287 -0
- package/dist/types-we5uR-tV.d.mts.map +1 -0
- package/dist/upload-attempts-DduMy6B0.mjs +32 -0
- package/dist/upload-attempts-DduMy6B0.mjs.map +1 -0
- package/dist/url-pattern-B3EwxAAk.mjs +33 -0
- package/dist/url-pattern-B3EwxAAk.mjs.map +1 -0
- package/dist/user-ElwQjTQT.mjs +171 -0
- package/dist/user-ElwQjTQT.mjs.map +1 -0
- package/dist/utils-BlAXmfOG.mjs +439 -0
- package/dist/utils-BlAXmfOG.mjs.map +1 -0
- package/dist/validate-CH0X5b2c.d.mts +468 -0
- package/dist/validate-CH0X5b2c.d.mts.map +1 -0
- package/dist/validate-CfgRpcjA.mjs +492 -0
- package/dist/validate-CfgRpcjA.mjs.map +1 -0
- package/dist/validation-DvYJtv4k.mjs +218 -0
- package/dist/validation-DvYJtv4k.mjs.map +1 -0
- package/dist/version-DgYjhTud.mjs +9 -0
- package/dist/version-DgYjhTud.mjs.map +1 -0
- package/dist/version-Dq71scUb.mjs +7 -0
- package/dist/version-Dq71scUb.mjs.map +1 -0
- package/dist/widgets-ChFIj0be.mjs +126 -0
- package/dist/widgets-ChFIj0be.mjs.map +1 -0
- package/dist/wxr-taxonomies-CBZMp2YX.mjs +372 -0
- package/dist/wxr-taxonomies-CBZMp2YX.mjs.map +1 -0
- package/dist/wxr-taxonomies-DlKDpWN1.d.mts +34 -0
- package/dist/wxr-taxonomies-DlKDpWN1.d.mts.map +1 -0
- package/dist/zod-generator-DmTKI-Ig.mjs +426 -0
- package/dist/zod-generator-DmTKI-Ig.mjs.map +1 -0
- package/package.json +7 -6
- package/src/api/handlers/content.ts +593 -16
- package/src/api/handlers/device-flow.ts +74 -21
- package/src/api/handlers/index.ts +1 -0
- package/src/api/handlers/manifest.ts +79 -5
- package/src/api/handlers/media-upload.ts +17 -71
- package/src/api/handlers/media.ts +97 -3
- package/src/api/handlers/relations.ts +638 -157
- package/src/api/handlers/revision.ts +30 -0
- package/src/api/handlers/schema.ts +403 -1
- package/src/api/handlers/snapshot.ts +257 -3
- package/src/api/handlers/staged-references.ts +142 -0
- package/src/api/handlers/validate-references.ts +146 -0
- package/src/api/schemas/content.ts +13 -0
- package/src/api/schemas/relations.ts +54 -44
- package/src/api/schemas/schema.ts +14 -0
- package/src/astro/integration/routes.ts +15 -19
- package/src/astro/integration/vite-config.ts +10 -4
- package/src/astro/middleware.ts +1 -0
- package/src/astro/routes/api/content/[collection]/[id]/references/[relation]/children.ts +11 -54
- package/src/astro/routes/api/content/[collection]/[id].ts +3 -1
- package/src/astro/routes/api/oauth/device/authorize.ts +33 -4
- package/src/astro/routes/api/relations/index.ts +4 -4
- package/src/astro/routes/api/schema/collections/[slug]/fields/[fieldSlug].ts +6 -2
- package/src/astro/routes/api/setup/index.ts +66 -23
- package/src/astro/routes/api/snapshot.ts +2 -1
- package/src/astro/types.ts +10 -0
- package/src/cleanup.ts +10 -0
- package/src/cli/commands/export-seed.ts +510 -89
- package/src/components/Columns.astro +3 -1
- package/src/components/Cover.astro +3 -1
- package/src/components/WidgetArea.astro +3 -2
- package/src/database/migrations/086_relations_structural.ts +197 -0
- package/src/database/migrations/087_reference_field_relations.ts +407 -0
- package/src/database/migrations/runner.ts +4 -0
- package/src/database/reference-backfill.ts +141 -0
- package/src/database/repositories/content.ts +43 -8
- package/src/database/repositories/media.ts +40 -1
- package/src/database/repositories/redirect.ts +17 -34
- package/src/database/repositories/relation.ts +620 -208
- package/src/database/repositories/revision.ts +16 -0
- package/src/database/repositories/types.ts +38 -0
- package/src/database/transaction.ts +12 -1
- package/src/database/types.ts +14 -5
- package/src/emdash-runtime.ts +114 -11
- package/src/index.ts +11 -0
- package/src/loader.ts +169 -22
- package/src/mcp/server.ts +13 -48
- package/src/query.ts +455 -25
- package/src/references/field-map.ts +115 -0
- package/src/references/resolve.ts +160 -0
- package/src/references/staged.ts +117 -0
- package/src/references/types.ts +16 -0
- package/src/registry/artifact-fetch.ts +45 -271
- package/src/schema/registry.ts +99 -24
- package/src/schema/types.ts +58 -0
- package/src/schema/zod-generator.ts +67 -1
- package/src/seed/apply.ts +841 -103
- package/src/seed/types.ts +36 -2
- package/src/seed/validate.ts +78 -2
- package/src/transfer/analyze/unique-keys.ts +3 -12
- package/src/transfer/analyze/validate.ts +65 -39
- package/src/transfer/analyze/values.ts +12 -1
- package/src/transfer/export/readers.ts +12 -8
- package/src/transfer/format/columns.ts +26 -6
- package/src/transfer/format/kinds.ts +21 -5
- package/src/transfer/import/context.ts +8 -1
- package/src/transfer/ops/package-index.ts +1 -1
- package/dist/action-token-DYwe4Pk0.mjs +0 -26
- package/dist/action-token-DYwe4Pk0.mjs.map +0 -1
- package/dist/activation-LOkDM5WT.mjs +0 -382
- package/dist/activation-LOkDM5WT.mjs.map +0 -1
- package/dist/adapters-B64LbYcB.d.mts +0 -171
- package/dist/adapters-B64LbYcB.d.mts.map +0 -1
- package/dist/allowed-origins-CHB8oZNM.mjs +0 -116
- package/dist/allowed-origins-CHB8oZNM.mjs.map +0 -1
- package/dist/api-cFFZpyS0.mjs +0 -4718
- package/dist/api-cFFZpyS0.mjs.map +0 -1
- package/dist/api-tokens-s4i4aUp_.mjs +0 -166
- package/dist/api-tokens-s4i4aUp_.mjs.map +0 -1
- package/dist/apply-CoT603H3.mjs +0 -1163
- package/dist/apply-CoT603H3.mjs.map +0 -1
- package/dist/approvals-CqMfNxak.mjs +0 -460
- package/dist/approvals-CqMfNxak.mjs.map +0 -1
- package/dist/artifact-fetch-DZMOGZ3-.mjs +0 -818
- package/dist/artifact-fetch-DZMOGZ3-.mjs.map +0 -1
- package/dist/astro/routes/api/relations/_id_/translations.d.mts +0 -8
- package/dist/astro/routes/api/relations/_id_/translations.d.mts.map +0 -1
- package/dist/astro/routes/api/relations/_id_/translations.mjs +0 -47
- package/dist/astro/routes/api/relations/_id_/translations.mjs.map +0 -1
- package/dist/audit-RfCugiSB.mjs +0 -127
- package/dist/audit-RfCugiSB.mjs.map +0 -1
- package/dist/authoritative-records-CoJvBXAD.mjs +0 -5172
- package/dist/authoritative-records-CoJvBXAD.mjs.map +0 -1
- package/dist/authorize-seCifOMJ.mjs +0 -49
- package/dist/authorize-seCifOMJ.mjs.map +0 -1
- package/dist/backup-CBu0LrXf.mjs +0 -246
- package/dist/backup-CBu0LrXf.mjs.map +0 -1
- package/dist/block-type-registry-DUI_3KxT.mjs +0 -6709
- package/dist/block-type-registry-DUI_3KxT.mjs.map +0 -1
- package/dist/block-types-BmZmLmAD.mjs +0 -132
- package/dist/block-types-BmZmLmAD.mjs.map +0 -1
- package/dist/block-values-C_VIPr5t.mjs +0 -175
- package/dist/block-values-C_VIPr5t.mjs.map +0 -1
- package/dist/byline-DYmkXqvo.mjs +0 -909
- package/dist/byline-DYmkXqvo.mjs.map +0 -1
- package/dist/byline-fields-D28AT-Fh.mjs +0 -123
- package/dist/byline-fields-D28AT-Fh.mjs.map +0 -1
- package/dist/byline-registry-gnKscbQX.mjs +0 -406
- package/dist/byline-registry-gnKscbQX.mjs.map +0 -1
- package/dist/bylines-BPwJqoYH.mjs +0 -232
- package/dist/bylines-BPwJqoYH.mjs.map +0 -1
- package/dist/bylines-ukLaYpVZ.mjs +0 -214
- package/dist/bylines-ukLaYpVZ.mjs.map +0 -1
- package/dist/cache-m7UEkRFV.mjs +0 -108
- package/dist/cache-m7UEkRFV.mjs.map +0 -1
- package/dist/canonical-YhEQezjg.mjs +0 -174
- package/dist/canonical-YhEQezjg.mjs.map +0 -1
- package/dist/capture-triggers-kJyl_yyM.mjs +0 -362
- package/dist/capture-triggers-kJyl_yyM.mjs.map +0 -1
- package/dist/challenge-store-ppU6Uv13.mjs +0 -51
- package/dist/challenge-store-ppU6Uv13.mjs.map +0 -1
- package/dist/checksum-B2IINIlN.mjs +0 -162
- package/dist/checksum-B2IINIlN.mjs.map +0 -1
- package/dist/chrome-tags-DApCQSIk.mjs +0 -24
- package/dist/chrome-tags-DApCQSIk.mjs.map +0 -1
- package/dist/chunks-Dms7Uxbt.mjs +0 -25
- package/dist/chunks-Dms7Uxbt.mjs.map +0 -1
- package/dist/collection-deletion-BIm28mo3.mjs +0 -436
- package/dist/collection-deletion-BIm28mo3.mjs.map +0 -1
- package/dist/collection-deletion-processor-Br6rxs3u.mjs +0 -217
- package/dist/collection-deletion-processor-Br6rxs3u.mjs.map +0 -1
- package/dist/collection-slugs-cache-CjGk__zp.mjs +0 -85
- package/dist/collection-slugs-cache-CjGk__zp.mjs.map +0 -1
- package/dist/comment-CrBl22OF.mjs +0 -313
- package/dist/comment-CrBl22OF.mjs.map +0 -1
- package/dist/comment-reaction-JEQ2Fpd8.mjs +0 -85
- package/dist/comment-reaction-JEQ2Fpd8.mjs.map +0 -1
- package/dist/comments-2ah9du9y.mjs +0 -195
- package/dist/comments-2ah9du9y.mjs.map +0 -1
- package/dist/comments-fHZ8ON9O.mjs +0 -99
- package/dist/comments-fHZ8ON9O.mjs.map +0 -1
- package/dist/components-CXbq7CSM.mjs +0 -108
- package/dist/components-CXbq7CSM.mjs.map +0 -1
- package/dist/config-5ii2haYu.d.mts +0 -6528
- package/dist/config-5ii2haYu.d.mts.map +0 -1
- package/dist/config-IhybvkIQ.mjs +0 -242
- package/dist/config-IhybvkIQ.mjs.map +0 -1
- package/dist/config-Py43JK9r.d.mts +0 -39
- package/dist/config-Py43JK9r.d.mts.map +0 -1
- package/dist/content-DFaIEDj9.mjs +0 -2281
- package/dist/content-DFaIEDj9.mjs.map +0 -1
- package/dist/content-list-query-Dra4Dalc.d.mts +0 -26
- package/dist/content-list-query-Dra4Dalc.d.mts.map +0 -1
- package/dist/content-policy-DFNw91-d.mjs +0 -46
- package/dist/content-policy-DFNw91-d.mjs.map +0 -1
- package/dist/content-repair-Q8IUrpLL.mjs +0 -442
- package/dist/content-repair-Q8IUrpLL.mjs.map +0 -1
- package/dist/context-BeGccdUX.mjs +0 -1921
- package/dist/context-BeGccdUX.mjs.map +0 -1
- package/dist/cron-7DCJwPXq.mjs +0 -284
- package/dist/cron-7DCJwPXq.mjs.map +0 -1
- package/dist/dashboard-DjrB-xxZ.mjs +0 -151
- package/dist/dashboard-DjrB-xxZ.mjs.map +0 -1
- package/dist/default-DQ6vsviu.mjs +0 -81
- package/dist/default-DQ6vsviu.mjs.map +0 -1
- package/dist/deferred-tasks-BPxXUB4x.d.mts +0 -9
- package/dist/deferred-tasks-BPxXUB4x.d.mts.map +0 -1
- package/dist/dev-typegen-CZaPLl3V.mjs +0 -29
- package/dist/dev-typegen-CZaPLl3V.mjs.map +0 -1
- package/dist/device-flow-CRd6DXmW.mjs +0 -466
- package/dist/device-flow-CRd6DXmW.mjs.map +0 -1
- package/dist/digest-BarSh-pN.mjs +0 -194
- package/dist/digest-BarSh-pN.mjs.map +0 -1
- package/dist/direct-executor-BmuFJJZV.mjs +0 -104
- package/dist/direct-executor-BmuFJJZV.mjs.map +0 -1
- package/dist/dist-BNwANFJR.mjs +0 -810
- package/dist/dist-BNwANFJR.mjs.map +0 -1
- package/dist/email-console-bJn3ctqA.mjs +0 -50
- package/dist/email-console-bJn3ctqA.mjs.map +0 -1
- package/dist/email-locale-CN6WAMx0.mjs +0 -25
- package/dist/email-locale-CN6WAMx0.mjs.map +0 -1
- package/dist/emdash-runtime-DAjghyEG.mjs +0 -4186
- package/dist/emdash-runtime-DAjghyEG.mjs.map +0 -1
- package/dist/enrich-Dl3kZ-lP.mjs +0 -194
- package/dist/enrich-Dl3kZ-lP.mjs.map +0 -1
- package/dist/entry-lock-BJYdBfXb.mjs +0 -1097
- package/dist/entry-lock-BJYdBfXb.mjs.map +0 -1
- package/dist/entry-lock-DHQOxN7R.mjs +0 -163
- package/dist/entry-lock-DHQOxN7R.mjs.map +0 -1
- package/dist/entry-lock-DVhCt49A.d.mts +0 -4368
- package/dist/entry-lock-DVhCt49A.d.mts.map +0 -1
- package/dist/entry-locks-D0foLdjQ.mjs +0 -167
- package/dist/entry-locks-D0foLdjQ.mjs.map +0 -1
- package/dist/error-CfvOHP0M.mjs +0 -90
- package/dist/error-CfvOHP0M.mjs.map +0 -1
- package/dist/errors-BF0_LFhW.mjs +0 -460
- package/dist/errors-BF0_LFhW.mjs.map +0 -1
- package/dist/errors-DgE1zJGG.mjs +0 -120
- package/dist/errors-DgE1zJGG.mjs.map +0 -1
- package/dist/escape-CuaZhZvL.mjs +0 -9
- package/dist/escape-CuaZhZvL.mjs.map +0 -1
- package/dist/fence-CMDXJYc_.mjs +0 -162
- package/dist/fence-CMDXJYc_.mjs.map +0 -1
- package/dist/field-defs-cache-HIgBbqZZ.mjs +0 -77
- package/dist/field-defs-cache-HIgBbqZZ.mjs.map +0 -1
- package/dist/focal-point-Gr34o-4o.mjs +0 -23
- package/dist/focal-point-Gr34o-4o.mjs.map +0 -1
- package/dist/fts-manager-S-K0laoS.mjs +0 -443
- package/dist/fts-manager-S-K0laoS.mjs.map +0 -1
- package/dist/gc-DjKY0Ay1.mjs +0 -75
- package/dist/gc-DjKY0Ay1.mjs.map +0 -1
- package/dist/hash-SDAW6zC-.mjs +0 -37
- package/dist/hash-SDAW6zC-.mjs.map +0 -1
- package/dist/hook-result-B5bXDgS2.d.mts +0 -31
- package/dist/hook-result-B5bXDgS2.d.mts.map +0 -1
- package/dist/hreflang-D5uNnsGJ.d.mts +0 -50
- package/dist/hreflang-D5uNnsGJ.d.mts.map +0 -1
- package/dist/hreflang-DMFBL2eb.mjs +0 -105
- package/dist/hreflang-DMFBL2eb.mjs.map +0 -1
- package/dist/http-route-dispatch-BitqzwMy.mjs +0 -339
- package/dist/http-route-dispatch-BitqzwMy.mjs.map +0 -1
- package/dist/identity-IyNWwXr6.mjs +0 -35
- package/dist/identity-IyNWwXr6.mjs.map +0 -1
- package/dist/import-C3JZplWq.mjs +0 -2020
- package/dist/import-C3JZplWq.mjs.map +0 -1
- package/dist/index-D-hdtLe8.d.mts +0 -623
- package/dist/index-D-hdtLe8.d.mts.map +0 -1
- package/dist/install-finalization-DfM1fj5x.mjs +0 -58
- package/dist/install-finalization-DfM1fj5x.mjs.map +0 -1
- package/dist/keys-yxLm5l35.mjs +0 -61
- package/dist/keys-yxLm5l35.mjs.map +0 -1
- package/dist/kinds-CRu_T5T5.mjs +0 -961
- package/dist/kinds-CRu_T5T5.mjs.map +0 -1
- package/dist/lifecycle-BzeGPeQ-.mjs +0 -25
- package/dist/lifecycle-BzeGPeQ-.mjs.map +0 -1
- package/dist/load-XgJiE6_3.mjs +0 -28
- package/dist/load-XgJiE6_3.mjs.map +0 -1
- package/dist/loader-BzqeR1ZN.mjs +0 -1086
- package/dist/loader-BzqeR1ZN.mjs.map +0 -1
- package/dist/loops-BQSzv5Zn.mjs +0 -203
- package/dist/loops-BQSzv5Zn.mjs.map +0 -1
- package/dist/manifest-builder-B8zR-73J.mjs +0 -189
- package/dist/manifest-builder-B8zR-73J.mjs.map +0 -1
- package/dist/manifest-schema-CY3zng_M.mjs +0 -492
- package/dist/manifest-schema-CY3zng_M.mjs.map +0 -1
- package/dist/media-Pu1L6xir.mjs +0 -408
- package/dist/media-Pu1L6xir.mjs.map +0 -1
- package/dist/media-Qp5S3eH3.mjs +0 -355
- package/dist/media-Qp5S3eH3.mjs.map +0 -1
- package/dist/media-allowlist-BSoa9Vvm.mjs +0 -44
- package/dist/media-allowlist-BSoa9Vvm.mjs.map +0 -1
- package/dist/media-folders-BE0oo2eX.mjs +0 -210
- package/dist/media-folders-BE0oo2eX.mjs.map +0 -1
- package/dist/media-h7tOiDLj.mjs +0 -221
- package/dist/media-h7tOiDLj.mjs.map +0 -1
- package/dist/media-url-jArBpzIG.mjs +0 -43
- package/dist/media-url-jArBpzIG.mjs.map +0 -1
- package/dist/media-usage-My-Vi-ex.mjs +0 -1629
- package/dist/media-usage-My-Vi-ex.mjs.map +0 -1
- package/dist/media-usage-activation-HKp7zk7W.mjs +0 -78
- package/dist/media-usage-activation-HKp7zk7W.mjs.map +0 -1
- package/dist/media-usage-work-C2OZLCAd.mjs +0 -586
- package/dist/media-usage-work-C2OZLCAd.mjs.map +0 -1
- package/dist/media-usage-work-DwUNbgvS.mjs +0 -152
- package/dist/media-usage-work-DwUNbgvS.mjs.map +0 -1
- package/dist/menus-BM7BPLOb.mjs +0 -139
- package/dist/menus-BM7BPLOb.mjs.map +0 -1
- package/dist/menus-ITeAbcIF.mjs +0 -753
- package/dist/menus-ITeAbcIF.mjs.map +0 -1
- package/dist/menus-TsSGmSR4.mjs +0 -3608
- package/dist/menus-TsSGmSR4.mjs.map +0 -1
- package/dist/mime-ChLqYwDk.mjs +0 -36
- package/dist/mime-ChLqYwDk.mjs.map +0 -1
- package/dist/mode-CCuKXUci.mjs +0 -23
- package/dist/mode-CCuKXUci.mjs.map +0 -1
- package/dist/node-sqlite-compat-CONMsl-x.mjs +0 -46
- package/dist/node-sqlite-compat-CONMsl-x.mjs.map +0 -1
- package/dist/normalize-CO2P8-iE.mjs +0 -191
- package/dist/normalize-CO2P8-iE.mjs.map +0 -1
- package/dist/oauth-authorization-DlMIL5_h.mjs +0 -274
- package/dist/oauth-authorization-DlMIL5_h.mjs.map +0 -1
- package/dist/oauth-clients-Djq9r_KP.mjs +0 -266
- package/dist/oauth-clients-Djq9r_KP.mjs.map +0 -1
- package/dist/oauth-state-store-BbjnZXNC.mjs +0 -50
- package/dist/oauth-state-store-BbjnZXNC.mjs.map +0 -1
- package/dist/oauth-user-lookup-vue9a64A.mjs +0 -26
- package/dist/oauth-user-lookup-vue9a64A.mjs.map +0 -1
- package/dist/options-SQCHQCPH.d.mts +0 -81
- package/dist/options-SQCHQCPH.d.mts.map +0 -1
- package/dist/parse-CVgO-Qai.d.mts +0 -168
- package/dist/parse-CVgO-Qai.d.mts.map +0 -1
- package/dist/parse-DY6OD1j_.mjs +0 -81
- package/dist/parse-DY6OD1j_.mjs.map +0 -1
- package/dist/passkey-config-X_H8128a.mjs +0 -46
- package/dist/passkey-config-X_H8128a.mjs.map +0 -1
- package/dist/paths-JxokKIbr.mjs +0 -77
- package/dist/paths-JxokKIbr.mjs.map +0 -1
- package/dist/patterns-BhAvqO0S.mjs +0 -145
- package/dist/patterns-BhAvqO0S.mjs.map +0 -1
- package/dist/placeholder-MSEd8gty.d.mts +0 -306
- package/dist/placeholder-MSEd8gty.d.mts.map +0 -1
- package/dist/plan-xjcWrAah.mjs +0 -135
- package/dist/plan-xjcWrAah.mjs.map +0 -1
- package/dist/plugins-DUXUt8B9.mjs +0 -277
- package/dist/plugins-DUXUt8B9.mjs.map +0 -1
- package/dist/policy-CUvwAARc.mjs +0 -45
- package/dist/policy-CUvwAARc.mjs.map +0 -1
- package/dist/portable-text-5O_ZGUjB.mjs +0 -307
- package/dist/portable-text-5O_ZGUjB.mjs.map +0 -1
- package/dist/preview-CIUcPYr6.mjs +0 -107
- package/dist/preview-CIUcPYr6.mjs.map +0 -1
- package/dist/protocol-B97DZaFr.d.mts +0 -61
- package/dist/protocol-B97DZaFr.d.mts.map +0 -1
- package/dist/public-submission-BFBUrqst.mjs +0 -250
- package/dist/public-submission-BFBUrqst.mjs.map +0 -1
- package/dist/public-url-Bn7U0D7-.mjs +0 -101
- package/dist/public-url-Bn7U0D7-.mjs.map +0 -1
- package/dist/query-B48peoRT.mjs +0 -890
- package/dist/query-B48peoRT.mjs.map +0 -1
- package/dist/query-C4IH0uhR.mjs +0 -41
- package/dist/query-C4IH0uhR.mjs.map +0 -1
- package/dist/rate-limit-BZ6nybgc.mjs +0 -120
- package/dist/rate-limit-BZ6nybgc.mjs.map +0 -1
- package/dist/receipt-B4wJj5Jq.mjs +0 -43
- package/dist/receipt-B4wJj5Jq.mjs.map +0 -1
- package/dist/redirect-Cd1E7VUt.mjs +0 -17
- package/dist/redirect-Cd1E7VUt.mjs.map +0 -1
- package/dist/redirect-iJf5fltD.mjs +0 -415
- package/dist/redirect-iJf5fltD.mjs.map +0 -1
- package/dist/redirects-CYu1u1aK.mjs +0 -446
- package/dist/redirects-CYu1u1aK.mjs.map +0 -1
- package/dist/redirects-Cv9apQKj.mjs +0 -148
- package/dist/redirects-Cv9apQKj.mjs.map +0 -1
- package/dist/relation-M4NUCb0b.mjs +0 -334
- package/dist/relation-M4NUCb0b.mjs.map +0 -1
- package/dist/relations-CCif47Oq.mjs +0 -403
- package/dist/relations-CCif47Oq.mjs.map +0 -1
- package/dist/relations-CK9CYUyr.mjs +0 -310
- package/dist/relations-CK9CYUyr.mjs.map +0 -1
- package/dist/request-cache-DzLYKm_x.mjs +0 -104
- package/dist/request-cache-DzLYKm_x.mjs.map +0 -1
- package/dist/request-meta-sZXt3sRo.mjs +0 -141
- package/dist/request-meta-sZXt3sRo.mjs.map +0 -1
- package/dist/resolve-2WbQsCvT.mjs +0 -199
- package/dist/resolve-2WbQsCvT.mjs.map +0 -1
- package/dist/route-wire--1hLuACz.mjs +0 -197
- package/dist/route-wire--1hLuACz.mjs.map +0 -1
- package/dist/routes-CUsM40Cc.mjs +0 -272
- package/dist/routes-CUsM40Cc.mjs.map +0 -1
- package/dist/runner-1y4J9fJB.mjs +0 -5742
- package/dist/runner-1y4J9fJB.mjs.map +0 -1
- package/dist/runner-D5_LzKXI.d.mts +0 -68
- package/dist/runner-D5_LzKXI.d.mts.map +0 -1
- package/dist/schema-BABiRdsH.mjs +0 -13
- package/dist/schema-BABiRdsH.mjs.map +0 -1
- package/dist/schema-Du3MzCG0.mjs +0 -446
- package/dist/schema-Du3MzCG0.mjs.map +0 -1
- package/dist/scopes-Dbk-ElhT.mjs +0 -34
- package/dist/scopes-Dbk-ElhT.mjs.map +0 -1
- package/dist/search-Bt1PL1jf.mjs +0 -448
- package/dist/search-Bt1PL1jf.mjs.map +0 -1
- package/dist/sections-Ddptx_o9.mjs +0 -346
- package/dist/sections-Ddptx_o9.mjs.map +0 -1
- package/dist/seo-CZT2oLtT.mjs +0 -114
- package/dist/seo-CZT2oLtT.mjs.map +0 -1
- package/dist/seo-D5w3-Azy.mjs +0 -133
- package/dist/seo-D5w3-Azy.mjs.map +0 -1
- package/dist/service-DuykXPyW.mjs +0 -150
- package/dist/service-DuykXPyW.mjs.map +0 -1
- package/dist/session-user-BhaVp8w0.mjs +0 -51
- package/dist/session-user-BhaVp8w0.mjs.map +0 -1
- package/dist/settings-2xNYr90o.mjs +0 -51
- package/dist/settings-2xNYr90o.mjs.map +0 -1
- package/dist/settings-CgjRWGW9.mjs +0 -439
- package/dist/settings-CgjRWGW9.mjs.map +0 -1
- package/dist/settings-DYidIB26.mjs +0 -61
- package/dist/settings-DYidIB26.mjs.map +0 -1
- package/dist/setup-complete-bOogcHWG.mjs +0 -26
- package/dist/setup-complete-bOogcHWG.mjs.map +0 -1
- package/dist/setup-nonce-0EGuKM4s.mjs +0 -25
- package/dist/setup-nonce-0EGuKM4s.mjs.map +0 -1
- package/dist/site-settings-DOgRUoFX.mjs +0 -50
- package/dist/site-settings-DOgRUoFX.mjs.map +0 -1
- package/dist/site-url-BU_bbxwj.mjs +0 -16
- package/dist/site-url-BU_bbxwj.mjs.map +0 -1
- package/dist/snapshot-CugwUqKQ.mjs +0 -237
- package/dist/snapshot-CugwUqKQ.mjs.map +0 -1
- package/dist/ssrf-CJUnJymJ.mjs +0 -406
- package/dist/ssrf-CJUnJymJ.mjs.map +0 -1
- package/dist/stage-DgrBz_du.mjs +0 -662
- package/dist/stage-DgrBz_du.mjs.map +0 -1
- package/dist/state-DDiPySSG.mjs +0 -153
- package/dist/state-DDiPySSG.mjs.map +0 -1
- package/dist/status-DZKIG4a9.mjs +0 -30
- package/dist/status-DZKIG4a9.mjs.map +0 -1
- package/dist/storage-query-Bdv7A62k.d.mts +0 -1576
- package/dist/storage-query-Bdv7A62k.d.mts.map +0 -1
- package/dist/tar-_1AgTYFu.mjs +0 -449
- package/dist/tar-_1AgTYFu.mjs.map +0 -1
- package/dist/target-_7pn2Gbg.mjs +0 -27
- package/dist/target-_7pn2Gbg.mjs.map +0 -1
- package/dist/taxonomies-C1IwNe8Q.mjs +0 -697
- package/dist/taxonomies-C1IwNe8Q.mjs.map +0 -1
- package/dist/taxonomies-C_XMoRcX.mjs +0 -939
- package/dist/taxonomies-C_XMoRcX.mjs.map +0 -1
- package/dist/taxonomy-C3Fu1YeH.mjs +0 -525
- package/dist/taxonomy-C3Fu1YeH.mjs.map +0 -1
- package/dist/tokens-u78jETkX.mjs +0 -171
- package/dist/tokens-u78jETkX.mjs.map +0 -1
- package/dist/transaction-BcJO4Tmc.mjs +0 -29
- package/dist/transaction-BcJO4Tmc.mjs.map +0 -1
- package/dist/transfer-BhUCrgDc.mjs +0 -8675
- package/dist/transfer-BhUCrgDc.mjs.map +0 -1
- package/dist/transfer-DIGvR9Af.mjs +0 -166
- package/dist/transfer-DIGvR9Af.mjs.map +0 -1
- package/dist/transfer-download-Pml7RMio.mjs +0 -33
- package/dist/transfer-download-Pml7RMio.mjs.map +0 -1
- package/dist/transformations-9gfpwY65.mjs +0 -196
- package/dist/transformations-9gfpwY65.mjs.map +0 -1
- package/dist/transport-BIfH7_hx.d.mts +0 -42
- package/dist/transport-BIfH7_hx.d.mts.map +0 -1
- package/dist/transport-DKWIq53q.mjs +0 -136
- package/dist/transport-DKWIq53q.mjs.map +0 -1
- package/dist/trusted-proxy-tKiVtyTD.mjs +0 -51
- package/dist/trusted-proxy-tKiVtyTD.mjs.map +0 -1
- package/dist/turnstile-DpsoyOfg.mjs +0 -53
- package/dist/turnstile-DpsoyOfg.mjs.map +0 -1
- package/dist/types-B4sUC2p1.d.mts +0 -198
- package/dist/types-B4sUC2p1.d.mts.map +0 -1
- package/dist/types-B7Lmsh1E.d.mts +0 -887
- package/dist/types-B7Lmsh1E.d.mts.map +0 -1
- package/dist/types-BZakh7Ym.mjs +0 -22
- package/dist/types-BZakh7Ym.mjs.map +0 -1
- package/dist/types-B_CppEmv.d.mts +0 -264
- package/dist/types-B_CppEmv.d.mts.map +0 -1
- package/dist/types-BcrBrE6-.mjs +0 -159
- package/dist/types-BcrBrE6-.mjs.map +0 -1
- package/dist/types-BkUg2yHx.mjs +0 -92
- package/dist/types-BkUg2yHx.mjs.map +0 -1
- package/dist/types-CAZgq9fO.d.mts +0 -124
- package/dist/types-CAZgq9fO.d.mts.map +0 -1
- package/dist/types-Cd-O03VG.d.mts +0 -363
- package/dist/types-Cd-O03VG.d.mts.map +0 -1
- package/dist/types-Cr-Kg-3D.d.mts +0 -1641
- package/dist/types-Cr-Kg-3D.d.mts.map +0 -1
- package/dist/types-D2fvWd1i.d.mts +0 -359
- package/dist/types-D2fvWd1i.d.mts.map +0 -1
- package/dist/types-D7HUsguf.mjs +0 -77
- package/dist/types-D7HUsguf.mjs.map +0 -1
- package/dist/types-DA1Te3Oy.d.mts +0 -198
- package/dist/types-DA1Te3Oy.d.mts.map +0 -1
- package/dist/types-DhV6Q5bP.mjs +0 -18
- package/dist/types-DhV6Q5bP.mjs.map +0 -1
- package/dist/types-DnnVSl6Y.d.mts +0 -85
- package/dist/types-DnnVSl6Y.d.mts.map +0 -1
- package/dist/types-VT4-BugW.mjs +0 -16
- package/dist/types-VT4-BugW.mjs.map +0 -1
- package/dist/upload-attempts-B68ZGNu9.mjs +0 -32
- package/dist/upload-attempts-B68ZGNu9.mjs.map +0 -1
- package/dist/url-pattern-CCeZMGOh.mjs +0 -33
- package/dist/url-pattern-CCeZMGOh.mjs.map +0 -1
- package/dist/user-DDSL-sGw.mjs +0 -171
- package/dist/user-DDSL-sGw.mjs.map +0 -1
- package/dist/utils-DdhmO9w9.mjs +0 -439
- package/dist/utils-DdhmO9w9.mjs.map +0 -1
- package/dist/validate-CHosPEhs.mjs +0 -453
- package/dist/validate-CHosPEhs.mjs.map +0 -1
- package/dist/validate-CM79QXYE.d.mts +0 -432
- package/dist/validate-CM79QXYE.d.mts.map +0 -1
- package/dist/validation-BFecQczG.mjs +0 -218
- package/dist/validation-BFecQczG.mjs.map +0 -1
- package/dist/version-BRZXVifl.mjs +0 -9
- package/dist/version-BRZXVifl.mjs.map +0 -1
- package/dist/version-DUQDHgrf.mjs +0 -7
- package/dist/version-DUQDHgrf.mjs.map +0 -1
- package/dist/widgets-WdV72brA.mjs +0 -126
- package/dist/widgets-WdV72brA.mjs.map +0 -1
- package/dist/wxr-taxonomies-BHTdqkmZ.d.mts +0 -34
- package/dist/wxr-taxonomies-BHTdqkmZ.d.mts.map +0 -1
- package/dist/wxr-taxonomies-DP6ESgMN.mjs +0 -372
- package/dist/wxr-taxonomies-DP6ESgMN.mjs.map +0 -1
- package/dist/zod-generator-D6uE4WiS.mjs +0 -389
- package/dist/zod-generator-D6uE4WiS.mjs.map +0 -1
- package/src/astro/routes/api/relations/[id]/translations.ts +0 -33
- /package/dist/{api-tokens-CE1ECIg0.mjs → api-tokens-FaG1zPsj.mjs} +0 -0
- /package/dist/{ssrf-DpBH7aOt.mjs → ssrf-DZOt8Qof.mjs} +0 -0
|
@@ -1,2281 +0,0 @@
|
|
|
1
|
-
import { u as __exportAll } from "./runner-1y4J9fJB.mjs";
|
|
2
|
-
import { n as isMissingTableError } from "./db-errors-CBD5yMro.mjs";
|
|
3
|
-
import { t as validateIdentifier } from "./validate-DANX1-Qi.mjs";
|
|
4
|
-
import { c as executeAtomicBatchIfSupported } from "./dialect-helpers-7_IqPdh9.mjs";
|
|
5
|
-
import { i as normalizeExplicitDatetime, n as normalizeContentDatetimes, r as normalizeDatetime, t as DatetimeNormalizationError } from "./datetime-normalization-PeiEdcRY.mjs";
|
|
6
|
-
import { l as invalidateCollectionCache } from "./object-cache-CqWNY5uP.mjs";
|
|
7
|
-
import { d as isIndexableFieldType } from "./types-BcrBrE6-.mjs";
|
|
8
|
-
import { n as chunks, t as SQL_BATCH_SIZE } from "./chunks-Dms7Uxbt.mjs";
|
|
9
|
-
import { n as slugify } from "./slugify-T5GHH42D.mjs";
|
|
10
|
-
import { a as ScheduledNotDueError, i as InvalidCursorError, n as ContentMutationConflictError, o as decodeCursor, r as EmDashValidationError, s as encodeCursor, t as ContentCollectionNotFoundError } from "./types-BkUg2yHx.mjs";
|
|
11
|
-
import { t as withTransaction } from "./transaction-BcJO4Tmc.mjs";
|
|
12
|
-
import { sql } from "kysely";
|
|
13
|
-
import { monotonicFactory, ulid } from "ulidx";
|
|
14
|
-
|
|
15
|
-
//#region src/content/known-fields.ts
|
|
16
|
-
/**
|
|
17
|
-
* Reconcile an entry's keys with the fields its collection currently declares.
|
|
18
|
-
*
|
|
19
|
-
* A draft revision stores the whole `data` as JSON, so deleting a field leaves the old
|
|
20
|
-
* value inside the revision. Every content-write surface needs the same two rules to keep
|
|
21
|
-
* that from stranding the entry, so they live here rather than in one caller.
|
|
22
|
-
*/
|
|
23
|
-
/** Keys EmDash reserves (`_slug` and the like). No field declares them. */
|
|
24
|
-
function isReservedKey(key) {
|
|
25
|
-
return key.startsWith("_");
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* The entry data without the keys the collection has no field for.
|
|
29
|
-
*
|
|
30
|
-
* Reserved keys are kept.
|
|
31
|
-
*/
|
|
32
|
-
function keepKnownFields(data, knownFieldSlugs) {
|
|
33
|
-
const result = {};
|
|
34
|
-
for (const [key, value] of Object.entries(data)) if (isReservedKey(key) || knownFieldSlugs.has(key)) result[key] = value;
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Incoming keys with no matching field that the entry already stores.
|
|
39
|
-
*
|
|
40
|
-
* Dropping these lets a read-then-write save succeed after the field was deleted. A key the
|
|
41
|
-
* entry has never stored is not returned, so a genuinely unknown field is still reported.
|
|
42
|
-
*/
|
|
43
|
-
function staleStoredKeys(data, stored, knownFieldSlugs) {
|
|
44
|
-
return Object.keys(data).filter((key) => !isReservedKey(key) && !knownFieldSlugs.has(key) && Object.hasOwn(stored, key));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/search/match.ts
|
|
49
|
-
/**
|
|
50
|
-
* FTS5 match-expression builder for structured (non-user-syntax) queries.
|
|
51
|
-
*
|
|
52
|
-
* Unlike `escapeQuery` in `query.ts` (which powers the public search API and
|
|
53
|
-
* deliberately passes through FTS5 operators like AND/OR/NOT), this builder
|
|
54
|
-
* treats the input as plain words: every term is double-quoted with interior
|
|
55
|
-
* quotes escaped, so the result can never produce an FTS5 syntax error. Used
|
|
56
|
-
* by the admin content-list filter, where the input is a filter box, not a
|
|
57
|
-
* search-syntax field.
|
|
58
|
-
*/
|
|
59
|
-
const WHITESPACE_RE = /\s+/;
|
|
60
|
-
const DOUBLE_QUOTE_RE = /"/g;
|
|
61
|
-
const GLOB_SPECIAL_RE = /[[\]*?]/g;
|
|
62
|
-
/**
|
|
63
|
-
* Build a prefix-matching FTS5 MATCH expression from free-form input.
|
|
64
|
-
*
|
|
65
|
-
* `hello wor` becomes `"hello"* "wor"*` — implicit AND with per-term prefix
|
|
66
|
-
* matching. Returns `""` when the input contains no usable terms; callers
|
|
67
|
-
* must fall back to their non-FTS path in that case.
|
|
68
|
-
*/
|
|
69
|
-
function buildFtsPrefixMatch(input) {
|
|
70
|
-
const terms = input.trim().split(WHITESPACE_RE).map((term) => term.replace(DOUBLE_QUOTE_RE, "\"\"")).filter((term) => term.length > 0);
|
|
71
|
-
if (terms.length === 0) return "";
|
|
72
|
-
return terms.map((term) => `"${term}"*`).join(" ");
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Build a GLOB prefix pattern from free-form input, treating GLOB
|
|
76
|
-
* metacharacters (`* ? [ ]`) literally by wrapping each in a character
|
|
77
|
-
* class (GLOB has no ESCAPE clause).
|
|
78
|
-
*
|
|
79
|
-
* GLOB (unlike default LIKE) is case-sensitive, so with a lowercased
|
|
80
|
-
* pattern it matches slugs (lowercase by construction) while staying
|
|
81
|
-
* servable by the ordinary BINARY-collated slug index — SQLite's GLOB
|
|
82
|
-
* optimization turns a `prefix*` pattern into an index range scan.
|
|
83
|
-
*/
|
|
84
|
-
function buildSlugGlobPrefix(input) {
|
|
85
|
-
return `${input.trim().toLowerCase().replace(GLOB_SPECIAL_RE, (c) => `[${c}]`)}*`;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/database/content-datetime.ts
|
|
90
|
-
function repeaterDatetimeFields(validation) {
|
|
91
|
-
if (!validation) return [];
|
|
92
|
-
let parsed;
|
|
93
|
-
try {
|
|
94
|
-
parsed = JSON.parse(validation);
|
|
95
|
-
} catch {
|
|
96
|
-
return [];
|
|
97
|
-
}
|
|
98
|
-
if (typeof parsed !== "object" || parsed === null || !("subFields" in parsed)) return [];
|
|
99
|
-
const subFields = parsed.subFields;
|
|
100
|
-
if (!Array.isArray(subFields)) return [];
|
|
101
|
-
return subFields.filter((field) => typeof field === "object" && field !== null && "type" in field && field.type === "datetime" && "slug" in field && typeof field.slug === "string").map((field) => field.slug);
|
|
102
|
-
}
|
|
103
|
-
var ContentDatetimeNormalizer = class {
|
|
104
|
-
constructor(db, contexts) {
|
|
105
|
-
this.db = db;
|
|
106
|
-
this.contexts = contexts;
|
|
107
|
-
}
|
|
108
|
-
context(collection) {
|
|
109
|
-
if (!this.contexts) return this.loadContext(collection);
|
|
110
|
-
let context = this.contexts.get(collection);
|
|
111
|
-
if (!context) {
|
|
112
|
-
context = this.loadContext(collection);
|
|
113
|
-
this.contexts.set(collection, context);
|
|
114
|
-
}
|
|
115
|
-
return context;
|
|
116
|
-
}
|
|
117
|
-
async loadContext(collection) {
|
|
118
|
-
const [rows, timezoneRow] = await Promise.all([this.db.selectFrom("_emdash_fields as field").innerJoin("_emdash_collections as collection", "collection.id", "field.collection_id").select([
|
|
119
|
-
"field.slug",
|
|
120
|
-
"field.type",
|
|
121
|
-
"field.validation"
|
|
122
|
-
]).where("collection.slug", "=", collection).where("field.type", "in", ["datetime", "repeater"]).execute(), this.db.selectFrom("options").select("value").where("name", "=", "site:timezone").executeTakeFirst()]);
|
|
123
|
-
let timezone = "UTC";
|
|
124
|
-
if (timezoneRow) try {
|
|
125
|
-
const configured = JSON.parse(timezoneRow.value);
|
|
126
|
-
if (typeof configured === "string" && configured) timezone = configured;
|
|
127
|
-
} catch {}
|
|
128
|
-
return {
|
|
129
|
-
timezone,
|
|
130
|
-
fields: rows.map((row) => row.type === "datetime" ? {
|
|
131
|
-
slug: row.slug,
|
|
132
|
-
type: "datetime"
|
|
133
|
-
} : {
|
|
134
|
-
slug: row.slug,
|
|
135
|
-
type: "repeater",
|
|
136
|
-
datetimeSubFields: repeaterDatetimeFields(row.validation)
|
|
137
|
-
})
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
async normalizeData(collection, data) {
|
|
141
|
-
const [normalized] = await this.normalizeDataMany(collection, [data]);
|
|
142
|
-
return normalized ?? data;
|
|
143
|
-
}
|
|
144
|
-
async normalizeDataMany(collection, items) {
|
|
145
|
-
const context = await this.context(collection);
|
|
146
|
-
try {
|
|
147
|
-
return items.map((data) => normalizeContentDatetimes(data, context.fields, context.timezone).value);
|
|
148
|
-
} catch (error) {
|
|
149
|
-
if (error instanceof DatetimeNormalizationError) throw new EmDashValidationError(error.message);
|
|
150
|
-
throw error;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
async normalizeValue(collection, value) {
|
|
154
|
-
const context = await this.context(collection);
|
|
155
|
-
try {
|
|
156
|
-
return normalizeDatetime(value, context.timezone).value;
|
|
157
|
-
} catch (error) {
|
|
158
|
-
if (error instanceof DatetimeNormalizationError) throw new EmDashValidationError(error.message);
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
//#endregion
|
|
165
|
-
//#region src/database/repositories/revision.ts
|
|
166
|
-
const monotonic = monotonicFactory();
|
|
167
|
-
function createRevisionId() {
|
|
168
|
-
return monotonic();
|
|
169
|
-
}
|
|
170
|
-
function normalizeRevisionLimit(value) {
|
|
171
|
-
const numeric = Number(value);
|
|
172
|
-
if (!Number.isFinite(numeric)) return 50;
|
|
173
|
-
return Math.max(1, Math.min(Math.trunc(numeric), 100));
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Revision repository for version history
|
|
177
|
-
*
|
|
178
|
-
* Each revision stores a JSON snapshot of the content at a point in time.
|
|
179
|
-
* Used when collection has `supports: ["revisions"]` enabled.
|
|
180
|
-
*/
|
|
181
|
-
var RevisionRepository = class {
|
|
182
|
-
datetimes;
|
|
183
|
-
constructor(db, datetimeContexts) {
|
|
184
|
-
this.db = db;
|
|
185
|
-
this.datetimes = new ContentDatetimeNormalizer(db, datetimeContexts);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Create a new revision
|
|
189
|
-
*/
|
|
190
|
-
async create(input) {
|
|
191
|
-
const id = createRevisionId();
|
|
192
|
-
const data = await this.datetimes.normalizeData(input.collection, input.data);
|
|
193
|
-
const row = {
|
|
194
|
-
id,
|
|
195
|
-
collection: input.collection,
|
|
196
|
-
entry_id: input.entryId,
|
|
197
|
-
data: JSON.stringify(data),
|
|
198
|
-
author_id: input.authorId ?? null
|
|
199
|
-
};
|
|
200
|
-
await this.db.insertInto("revisions").values(row).execute();
|
|
201
|
-
const revision = await this.findById(id);
|
|
202
|
-
if (!revision) throw new Error("Failed to create revision");
|
|
203
|
-
await this.queuePruning(input.collection, input.entryId, id);
|
|
204
|
-
return revision;
|
|
205
|
-
}
|
|
206
|
-
async queuePruning(collection, entryId, revisionId) {
|
|
207
|
-
try {
|
|
208
|
-
await this.db.insertInto("_emdash_revision_prune_queue").values({
|
|
209
|
-
collection,
|
|
210
|
-
entry_id: entryId,
|
|
211
|
-
revision_id: revisionId
|
|
212
|
-
}).onConflict((conflict) => conflict.columns(["collection", "entry_id"]).doUpdateSet({ revision_id: revisionId })).execute();
|
|
213
|
-
} catch (error) {
|
|
214
|
-
console.error(`[revisions] Failed to queue revision pruning for ${collection}/${entryId}:`, error);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Find revision by ID
|
|
219
|
-
*/
|
|
220
|
-
async findById(id) {
|
|
221
|
-
const row = await this.db.selectFrom("revisions").selectAll().where("id", "=", id).executeTakeFirst();
|
|
222
|
-
return row ? this.normalizeRow(row) : null;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Get all revisions for an entry (newest first)
|
|
226
|
-
*
|
|
227
|
-
* Orders by monotonic ULID (descending). The monotonic factory
|
|
228
|
-
* guarantees strictly increasing IDs even within the same millisecond.
|
|
229
|
-
*/
|
|
230
|
-
async findByEntry(collection, entryId, options = {}) {
|
|
231
|
-
let query = this.db.selectFrom("revisions").selectAll().where("collection", "=", collection).where("entry_id", "=", entryId).orderBy("id", "desc");
|
|
232
|
-
if (options.limit) query = query.limit(options.limit);
|
|
233
|
-
const rows = await query.execute();
|
|
234
|
-
const data = await this.datetimes.normalizeDataMany(collection, rows.map((row) => JSON.parse(row.data)));
|
|
235
|
-
return rows.map((row, index) => {
|
|
236
|
-
const normalized = data[index];
|
|
237
|
-
if (!normalized) throw new Error("Failed to normalize revision data");
|
|
238
|
-
return this.rowToRevision(row, normalized);
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
/** Read revisions only when the owning content row is visible in the same statement snapshot. */
|
|
242
|
-
async findVisibleByEntry(collection, entryId, options = {}) {
|
|
243
|
-
validateIdentifier(collection, "collection");
|
|
244
|
-
const tableName = `ec_${collection}`;
|
|
245
|
-
const limit = normalizeRevisionLimit(options.limit);
|
|
246
|
-
const result = await sql`
|
|
247
|
-
SELECT revisions.* FROM revisions
|
|
248
|
-
WHERE revisions.collection = ${collection}
|
|
249
|
-
AND revisions.entry_id = ${entryId}
|
|
250
|
-
AND EXISTS (
|
|
251
|
-
SELECT 1 FROM ${sql.ref(tableName)} AS content
|
|
252
|
-
WHERE content.id = ${entryId}
|
|
253
|
-
AND content.deleted_at IS NULL
|
|
254
|
-
)
|
|
255
|
-
ORDER BY revisions.id DESC
|
|
256
|
-
LIMIT ${limit}
|
|
257
|
-
`.execute(this.db);
|
|
258
|
-
const data = await this.datetimes.normalizeDataMany(collection, result.rows.map((row) => JSON.parse(row.data)));
|
|
259
|
-
return result.rows.map((row, index) => {
|
|
260
|
-
const normalized = data[index];
|
|
261
|
-
if (!normalized) throw new Error("Failed to normalize revision data");
|
|
262
|
-
return this.rowToRevision(row, normalized);
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
/** Read one revision only when its owning content row is visible in the same statement snapshot. */
|
|
266
|
-
async findVisibleById(collection, entryId, revisionId) {
|
|
267
|
-
validateIdentifier(collection, "collection");
|
|
268
|
-
const tableName = `ec_${collection}`;
|
|
269
|
-
const row = (await sql`
|
|
270
|
-
SELECT revisions.* FROM revisions
|
|
271
|
-
WHERE revisions.id = ${revisionId}
|
|
272
|
-
AND revisions.collection = ${collection}
|
|
273
|
-
AND revisions.entry_id = ${entryId}
|
|
274
|
-
AND EXISTS (
|
|
275
|
-
SELECT 1 FROM ${sql.ref(tableName)} AS content
|
|
276
|
-
WHERE content.id = ${entryId}
|
|
277
|
-
AND content.deleted_at IS NULL
|
|
278
|
-
)
|
|
279
|
-
LIMIT 1
|
|
280
|
-
`.execute(this.db)).rows[0];
|
|
281
|
-
return row ? this.normalizeRow(row) : null;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Get the most recent revision for an entry
|
|
285
|
-
*/
|
|
286
|
-
async findLatest(collection, entryId) {
|
|
287
|
-
const row = await this.db.selectFrom("revisions").selectAll().where("collection", "=", collection).where("entry_id", "=", entryId).orderBy("id", "desc").limit(1).executeTakeFirst();
|
|
288
|
-
return row ? this.normalizeRow(row) : null;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Count revisions for an entry
|
|
292
|
-
*/
|
|
293
|
-
async countByEntry(collection, entryId) {
|
|
294
|
-
const result = await this.db.selectFrom("revisions").select((eb) => eb.fn.count("id").as("count")).where("collection", "=", collection).where("entry_id", "=", entryId).executeTakeFirst();
|
|
295
|
-
return Number(result?.count || 0);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Delete all revisions for an entry (use when entry is deleted)
|
|
299
|
-
*/
|
|
300
|
-
async deleteByEntry(collection, entryId) {
|
|
301
|
-
const result = await this.db.deleteFrom("revisions").where("collection", "=", collection).where("entry_id", "=", entryId).executeTakeFirst();
|
|
302
|
-
try {
|
|
303
|
-
await this.db.deleteFrom("_emdash_revision_prune_queue").where("collection", "=", collection).where("entry_id", "=", entryId).execute();
|
|
304
|
-
} catch (error) {
|
|
305
|
-
console.error(`[revisions] Failed to clear queued revision pruning for ${collection}/${entryId}:`, error);
|
|
306
|
-
}
|
|
307
|
-
return Number(result.numDeletedRows ?? 0);
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Delete old revisions, keeping the most recent N
|
|
311
|
-
*/
|
|
312
|
-
async pruneOldRevisions(collection, entryId, keepCount, throughRevisionId) {
|
|
313
|
-
validateIdentifier(collection, "collection");
|
|
314
|
-
const tableName = `ec_${collection}`;
|
|
315
|
-
let keepQuery = this.db.selectFrom("revisions").select("id").where("collection", "=", collection).where("entry_id", "=", entryId).orderBy("created_at", "desc").orderBy("id", "desc").limit(keepCount);
|
|
316
|
-
if (throughRevisionId) keepQuery = keepQuery.where("id", "<=", throughRevisionId);
|
|
317
|
-
const keepIds = (await keepQuery.execute()).map((r) => r.id);
|
|
318
|
-
if (keepIds.length === 0) return 0;
|
|
319
|
-
const result = await sql`
|
|
320
|
-
DELETE FROM revisions
|
|
321
|
-
WHERE collection = ${collection}
|
|
322
|
-
AND entry_id = ${entryId}
|
|
323
|
-
${throughRevisionId ? sql`AND id <= ${throughRevisionId}` : sql``}
|
|
324
|
-
AND id NOT IN (${sql.join(keepIds.map((id) => sql`${id}`))})
|
|
325
|
-
AND NOT EXISTS (
|
|
326
|
-
SELECT 1 FROM ${sql.ref(tableName)} AS content
|
|
327
|
-
WHERE content.live_revision_id = revisions.id
|
|
328
|
-
OR content.draft_revision_id = revisions.id
|
|
329
|
-
)
|
|
330
|
-
`.execute(this.db);
|
|
331
|
-
return Number(result.numAffectedRows ?? 0);
|
|
332
|
-
}
|
|
333
|
-
async pruneQueuedEntry(collection, entryId, queuedRevisionId, keepCount) {
|
|
334
|
-
const pruned = await this.pruneOldRevisions(collection, entryId, keepCount, queuedRevisionId);
|
|
335
|
-
await this.db.deleteFrom("_emdash_revision_prune_queue").where("collection", "=", collection).where("entry_id", "=", entryId).where("revision_id", "=", queuedRevisionId).execute();
|
|
336
|
-
return pruned;
|
|
337
|
-
}
|
|
338
|
-
async deleteIfUnreferenced(collection, entryId, revisionId) {
|
|
339
|
-
validateIdentifier(collection, "collection");
|
|
340
|
-
const tableName = `ec_${collection}`;
|
|
341
|
-
return ((await sql`
|
|
342
|
-
DELETE FROM revisions
|
|
343
|
-
WHERE id = ${revisionId}
|
|
344
|
-
AND collection = ${collection}
|
|
345
|
-
AND entry_id = ${entryId}
|
|
346
|
-
AND NOT EXISTS (
|
|
347
|
-
SELECT 1 FROM ${sql.ref(tableName)} AS content
|
|
348
|
-
WHERE content.live_revision_id = revisions.id
|
|
349
|
-
OR content.draft_revision_id = revisions.id
|
|
350
|
-
)
|
|
351
|
-
`.execute(this.db)).numAffectedRows ?? 0n) > 0n;
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Convert database row to Revision object
|
|
355
|
-
*/
|
|
356
|
-
async normalizeRow(row) {
|
|
357
|
-
const data = await this.datetimes.normalizeData(row.collection, JSON.parse(row.data));
|
|
358
|
-
return this.rowToRevision(row, data);
|
|
359
|
-
}
|
|
360
|
-
rowToRevision(row, data) {
|
|
361
|
-
return {
|
|
362
|
-
id: row.id,
|
|
363
|
-
collection: row.collection,
|
|
364
|
-
entryId: row.entry_id,
|
|
365
|
-
data,
|
|
366
|
-
authorId: row.author_id,
|
|
367
|
-
createdAt: row.created_at
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
//#endregion
|
|
373
|
-
//#region src/database/repositories/content.ts
|
|
374
|
-
var content_exports = /* @__PURE__ */ __exportAll({
|
|
375
|
-
ContentRepository: () => ContentRepository,
|
|
376
|
-
isConfirmedStatementFailure: () => isConfirmedStatementFailure,
|
|
377
|
-
isSystemOrderField: () => isSystemOrderField
|
|
378
|
-
});
|
|
379
|
-
const ULID_PATTERN = /^[0-9A-Z]{26}$/;
|
|
380
|
-
const SQLSTATE_PATTERN = /^[0-9A-Z]{5}$/;
|
|
381
|
-
const MAX_DRAFT_STAGE_ATTEMPTS = 32;
|
|
382
|
-
const LIKE_WILDCARD_RE = /[\\%_]/g;
|
|
383
|
-
const MAX_INDEXED_FIELD_FILTERS = 20;
|
|
384
|
-
const MAX_IN_FILTER_VALUES = SQL_BATCH_SIZE;
|
|
385
|
-
const MAX_FILTER_STRING_LENGTH = 2048;
|
|
386
|
-
function assertRevisionPrecondition(item, expected) {
|
|
387
|
-
if (expected && (item.version !== expected.version || item.updatedAt !== expected.updatedAt)) throw new ContentMutationConflictError();
|
|
388
|
-
}
|
|
389
|
-
function nullableColumnMatch(column, value) {
|
|
390
|
-
validateIdentifier(column, "content column");
|
|
391
|
-
return value === null ? sql`${sql.ref(column)} IS NULL` : sql`${sql.ref(column)} = ${value}`;
|
|
392
|
-
}
|
|
393
|
-
function sameStoredValue(left, right) {
|
|
394
|
-
return Object.is(serializeValue(left), serializeValue(right));
|
|
395
|
-
}
|
|
396
|
-
function matchesPublication(observed, existing, revision, revisionId, slug, publishedAt, updatedAt) {
|
|
397
|
-
if (observed.version !== existing.version + 1 || observed.status !== "published" || observed.slug !== slug || observed.liveRevisionId !== revisionId || observed.draftRevisionId !== null || observed.scheduledAt !== null || observed.publishedAt !== publishedAt || observed.updatedAt !== updatedAt) return false;
|
|
398
|
-
return Object.entries(revision.data).every(([key, value]) => SYSTEM_COLUMNS.has(key) || key.startsWith("_") || sameStoredValue(observed.data[key], value));
|
|
399
|
-
}
|
|
400
|
-
function matchesLifecyclePublication(observed, existing, liveRevisionId, publishedAt, updatedAt) {
|
|
401
|
-
if (observed.version !== existing.version + 1 || observed.status !== "published" || observed.slug !== existing.slug || observed.liveRevisionId !== liveRevisionId || observed.draftRevisionId !== null || observed.scheduledAt !== null || observed.publishedAt !== publishedAt || observed.updatedAt !== updatedAt) return false;
|
|
402
|
-
return Object.entries(existing.data).every(([key, value]) => sameStoredValue(observed.data[key], value));
|
|
403
|
-
}
|
|
404
|
-
function matchesPublicationFence(observed, existing) {
|
|
405
|
-
return observed.version === existing.version && observed.status === existing.status && observed.liveRevisionId === existing.liveRevisionId && observed.draftRevisionId === existing.draftRevisionId && observed.scheduledAt === existing.scheduledAt;
|
|
406
|
-
}
|
|
407
|
-
function isConfirmedStatementFailure(error) {
|
|
408
|
-
if (typeof error !== "object" || error === null || !("code" in error)) return false;
|
|
409
|
-
const code = error.code;
|
|
410
|
-
return typeof code === "string" && (code === "ERR_SQLITE_ERROR" || code.startsWith("SQLITE_") || SQLSTATE_PATTERN.test(code));
|
|
411
|
-
}
|
|
412
|
-
function encodeIndexedFieldCursor(field, value, id) {
|
|
413
|
-
const payload = {
|
|
414
|
-
version: 1,
|
|
415
|
-
field,
|
|
416
|
-
value
|
|
417
|
-
};
|
|
418
|
-
return encodeCursor(JSON.stringify(payload), id);
|
|
419
|
-
}
|
|
420
|
-
function decodeIndexedFieldCursor(cursor, field) {
|
|
421
|
-
const { orderValue, id } = decodeCursor(cursor);
|
|
422
|
-
let payload;
|
|
423
|
-
try {
|
|
424
|
-
payload = JSON.parse(orderValue);
|
|
425
|
-
} catch {
|
|
426
|
-
throw new InvalidCursorError(cursor);
|
|
427
|
-
}
|
|
428
|
-
if (payload === null || typeof payload !== "object") throw new InvalidCursorError(cursor);
|
|
429
|
-
const candidate = payload;
|
|
430
|
-
const validValue = candidate.value === null || typeof candidate.value === "string" || typeof candidate.value === "number";
|
|
431
|
-
if (candidate.version !== 1 || candidate.field !== field || !validValue) throw new InvalidCursorError(cursor);
|
|
432
|
-
return {
|
|
433
|
-
value: candidate.value,
|
|
434
|
-
id
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Whitelist mapping a public date-filter field to its physical column. Keeping
|
|
439
|
-
* this separate from `mapOrderField` makes the filterable set explicit and
|
|
440
|
-
* prevents filtering on arbitrary columns.
|
|
441
|
-
*/
|
|
442
|
-
const DATE_FILTER_COLUMNS = {
|
|
443
|
-
createdAt: "created_at",
|
|
444
|
-
updatedAt: "updated_at",
|
|
445
|
-
publishedAt: "published_at"
|
|
446
|
-
};
|
|
447
|
-
/**
|
|
448
|
-
* Built-in sort fields → their physical columns. A closed set that blocks
|
|
449
|
-
* sorting by arbitrary columns; per-collection fields are allowed
|
|
450
|
-
* separately via `mapOrderField`'s `sortableExtras`.
|
|
451
|
-
*/
|
|
452
|
-
const ORDER_FIELD_COLUMNS = {
|
|
453
|
-
createdAt: "created_at",
|
|
454
|
-
updatedAt: "updated_at",
|
|
455
|
-
publishedAt: "published_at",
|
|
456
|
-
scheduledAt: "scheduled_at",
|
|
457
|
-
deletedAt: "deleted_at",
|
|
458
|
-
title: "title",
|
|
459
|
-
name: "name",
|
|
460
|
-
slug: "slug",
|
|
461
|
-
status: "status",
|
|
462
|
-
locale: "locale"
|
|
463
|
-
};
|
|
464
|
-
/** True when `field` maps to a system column and needs no per-collection resolution. */
|
|
465
|
-
function isSystemOrderField(field) {
|
|
466
|
-
return field in ORDER_FIELD_COLUMNS;
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* System columns that exist in every ec_* table
|
|
470
|
-
*/
|
|
471
|
-
const SYSTEM_COLUMNS = new Set([
|
|
472
|
-
"id",
|
|
473
|
-
"slug",
|
|
474
|
-
"status",
|
|
475
|
-
"author_id",
|
|
476
|
-
"primary_byline_id",
|
|
477
|
-
"created_at",
|
|
478
|
-
"updated_at",
|
|
479
|
-
"published_at",
|
|
480
|
-
"scheduled_at",
|
|
481
|
-
"deleted_at",
|
|
482
|
-
"version",
|
|
483
|
-
"live_revision_id",
|
|
484
|
-
"draft_revision_id",
|
|
485
|
-
"locale",
|
|
486
|
-
"translation_group"
|
|
487
|
-
]);
|
|
488
|
-
/**
|
|
489
|
-
* Get the table name for a collection type
|
|
490
|
-
*/
|
|
491
|
-
function getTableName(type) {
|
|
492
|
-
validateIdentifier(type, "collection type");
|
|
493
|
-
return `ec_${type}`;
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Serialize a value for database storage
|
|
497
|
-
* Objects/arrays are JSON-stringified
|
|
498
|
-
* Booleans are converted to 0/1 for SQLite
|
|
499
|
-
*/
|
|
500
|
-
function serializeValue(value) {
|
|
501
|
-
if (value === null || value === void 0) return null;
|
|
502
|
-
if (typeof value === "boolean") return value ? 1 : 0;
|
|
503
|
-
if (typeof value === "object") return JSON.stringify(value);
|
|
504
|
-
return value;
|
|
505
|
-
}
|
|
506
|
-
function writableContentData(data) {
|
|
507
|
-
const writable = {};
|
|
508
|
-
for (const [key, value] of Object.entries(data)) {
|
|
509
|
-
if (SYSTEM_COLUMNS.has(key)) continue;
|
|
510
|
-
validateIdentifier(key, "content field name");
|
|
511
|
-
writable[key] = value;
|
|
512
|
-
}
|
|
513
|
-
return writable;
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Deserialize a value from database storage
|
|
517
|
-
* Attempts to parse JSON strings that look like objects/arrays
|
|
518
|
-
*/
|
|
519
|
-
function deserializeValue(value) {
|
|
520
|
-
if (typeof value === "string") {
|
|
521
|
-
if (value.startsWith("{") || value.startsWith("[")) try {
|
|
522
|
-
return JSON.parse(value);
|
|
523
|
-
} catch {
|
|
524
|
-
return value;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
return value;
|
|
528
|
-
}
|
|
529
|
-
/** Pattern for escaping special regex characters */
|
|
530
|
-
const REGEX_ESCAPE_PATTERN = /[.*+?^${}()|[\]\\]/g;
|
|
531
|
-
/**
|
|
532
|
-
* Escape special regex characters in a string for use in `new RegExp()`
|
|
533
|
-
*/
|
|
534
|
-
function escapeRegExp(s) {
|
|
535
|
-
return s.replace(REGEX_ESCAPE_PATTERN, "\\$&");
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* Repository for content CRUD operations
|
|
539
|
-
*
|
|
540
|
-
* Content is stored in per-collection tables (ec_posts, ec_pages, etc.)
|
|
541
|
-
* Each field becomes a real column in the table.
|
|
542
|
-
*/
|
|
543
|
-
var ContentRepository = class {
|
|
544
|
-
datetimes;
|
|
545
|
-
constructor(db, datetimeContexts) {
|
|
546
|
-
this.db = db;
|
|
547
|
-
this.datetimeContexts = datetimeContexts;
|
|
548
|
-
this.datetimes = new ContentDatetimeNormalizer(db, datetimeContexts);
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Create a new content item
|
|
552
|
-
*/
|
|
553
|
-
async create(input) {
|
|
554
|
-
const id = input.id ?? ulid();
|
|
555
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
556
|
-
const { type, slug, data: inputData, status = "draft", authorId, primaryBylineId, locale, translationOf, inheritFields = [], publishedAt, createdAt } = input;
|
|
557
|
-
const data = await this.datetimes.normalizeData(type, inputData);
|
|
558
|
-
const normalizedCreatedAt = createdAt ? await this.datetimes.normalizeValue(type, createdAt) : now;
|
|
559
|
-
const normalizedPublishedAt = publishedAt ? await this.datetimes.normalizeValue(type, publishedAt) : null;
|
|
560
|
-
if (!type) throw new EmDashValidationError("Content type is required");
|
|
561
|
-
const tableName = getTableName(type);
|
|
562
|
-
const columns = [
|
|
563
|
-
"id",
|
|
564
|
-
"slug",
|
|
565
|
-
"status",
|
|
566
|
-
"author_id",
|
|
567
|
-
"primary_byline_id",
|
|
568
|
-
"created_at",
|
|
569
|
-
"updated_at",
|
|
570
|
-
"published_at",
|
|
571
|
-
"version",
|
|
572
|
-
"locale",
|
|
573
|
-
"translation_group"
|
|
574
|
-
];
|
|
575
|
-
const values = [
|
|
576
|
-
id,
|
|
577
|
-
slug || null,
|
|
578
|
-
status,
|
|
579
|
-
authorId || null,
|
|
580
|
-
primaryBylineId ?? null,
|
|
581
|
-
normalizedCreatedAt,
|
|
582
|
-
now,
|
|
583
|
-
normalizedPublishedAt,
|
|
584
|
-
1,
|
|
585
|
-
locale || "en",
|
|
586
|
-
id
|
|
587
|
-
];
|
|
588
|
-
const inherited = new Set(inheritFields);
|
|
589
|
-
for (const field of inherited) {
|
|
590
|
-
validateIdentifier(field, "inherited content field name");
|
|
591
|
-
if (!SYSTEM_COLUMNS.has(field) && !Object.hasOwn(data, field)) {
|
|
592
|
-
columns.push(field);
|
|
593
|
-
values.push(null);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
if (data && typeof data === "object") {
|
|
597
|
-
for (const [key, value] of Object.entries(data)) if (!SYSTEM_COLUMNS.has(key)) {
|
|
598
|
-
validateIdentifier(key, "content field name");
|
|
599
|
-
columns.push(key);
|
|
600
|
-
values.push(serializeValue(value));
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
const columnRefs = columns.map((c) => sql.ref(c));
|
|
604
|
-
const valuePlaceholders = values.map((value, index) => {
|
|
605
|
-
const column = columns[index];
|
|
606
|
-
if (translationOf && column === "translation_group") return sql`COALESCE(${sql.ref("translation_source.translation_group")}, ${sql.ref("translation_source.id")})`;
|
|
607
|
-
if (translationOf && inherited.has(column)) return sql.ref(`translation_source.${column}`);
|
|
608
|
-
return value === null ? sql`NULL` : sql`${value}`;
|
|
609
|
-
});
|
|
610
|
-
if (translationOf) await sql`
|
|
611
|
-
INSERT INTO ${sql.ref(tableName)} (${sql.join(columnRefs, sql`, `)})
|
|
612
|
-
SELECT ${sql.join(valuePlaceholders, sql`, `)}
|
|
613
|
-
FROM ${sql.ref(tableName)} AS translation_source
|
|
614
|
-
WHERE translation_source.id = ${translationOf}
|
|
615
|
-
AND translation_source.deleted_at IS NULL
|
|
616
|
-
`.execute(this.db);
|
|
617
|
-
else await sql`
|
|
618
|
-
INSERT INTO ${sql.ref(tableName)} (${sql.join(columnRefs, sql`, `)})
|
|
619
|
-
VALUES (${sql.join(valuePlaceholders, sql`, `)})
|
|
620
|
-
`.execute(this.db);
|
|
621
|
-
invalidateCollectionCache(type);
|
|
622
|
-
const item = await this.findById(type, id);
|
|
623
|
-
if (!item) {
|
|
624
|
-
if (translationOf) throw new EmDashValidationError("Translation source content not found");
|
|
625
|
-
throw new Error("Failed to create content");
|
|
626
|
-
}
|
|
627
|
-
return item;
|
|
628
|
-
}
|
|
629
|
-
/**
|
|
630
|
-
* Generate a unique slug for a content item within a collection.
|
|
631
|
-
*
|
|
632
|
-
* Checks the collection table for existing slugs that match `baseSlug`
|
|
633
|
-
* (optionally scoped to a locale) and appends a numeric suffix (`-1`,
|
|
634
|
-
* `-2`, etc.) on collision to guarantee uniqueness.
|
|
635
|
-
*
|
|
636
|
-
* Returns null when slug normalization cannot produce a value.
|
|
637
|
-
*/
|
|
638
|
-
async generateUniqueSlug(type, text, locale) {
|
|
639
|
-
const baseSlug = slugify(text);
|
|
640
|
-
if (!baseSlug) return null;
|
|
641
|
-
const tableName = getTableName(type);
|
|
642
|
-
if ((locale ? await sql`
|
|
643
|
-
SELECT slug FROM ${sql.ref(tableName)}
|
|
644
|
-
WHERE slug = ${baseSlug}
|
|
645
|
-
AND locale = ${locale}
|
|
646
|
-
LIMIT 1
|
|
647
|
-
`.execute(this.db) : await sql`
|
|
648
|
-
SELECT slug FROM ${sql.ref(tableName)}
|
|
649
|
-
WHERE slug = ${baseSlug}
|
|
650
|
-
LIMIT 1
|
|
651
|
-
`.execute(this.db)).rows.length === 0) return baseSlug;
|
|
652
|
-
const pattern = `${baseSlug}-%`;
|
|
653
|
-
const candidates = locale ? await sql`
|
|
654
|
-
SELECT slug FROM ${sql.ref(tableName)}
|
|
655
|
-
WHERE (slug = ${baseSlug} OR slug LIKE ${pattern})
|
|
656
|
-
AND locale = ${locale}
|
|
657
|
-
`.execute(this.db) : await sql`
|
|
658
|
-
SELECT slug FROM ${sql.ref(tableName)}
|
|
659
|
-
WHERE slug = ${baseSlug} OR slug LIKE ${pattern}
|
|
660
|
-
`.execute(this.db);
|
|
661
|
-
let maxSuffix = 0;
|
|
662
|
-
const suffixPattern = new RegExp(`^${escapeRegExp(baseSlug)}-(\\d+)$`);
|
|
663
|
-
for (const row of candidates.rows) {
|
|
664
|
-
const match = suffixPattern.exec(row.slug);
|
|
665
|
-
if (match) {
|
|
666
|
-
const n = parseInt(match[1], 10);
|
|
667
|
-
if (n > maxSuffix) maxSuffix = n;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return `${baseSlug}-${maxSuffix + 1}`;
|
|
671
|
-
}
|
|
672
|
-
/**
|
|
673
|
-
* Duplicate a content item
|
|
674
|
-
* Creates a new draft copy with "(Copy)" appended to the title.
|
|
675
|
-
* A slug is auto-generated from the new title by the handler layer.
|
|
676
|
-
*/
|
|
677
|
-
async duplicate(type, id, authorId) {
|
|
678
|
-
const original = await this.findById(type, id);
|
|
679
|
-
if (!original) throw new EmDashValidationError("Content item not found");
|
|
680
|
-
const newData = { ...original.data };
|
|
681
|
-
if (typeof newData.title === "string") newData.title = `${newData.title} (Copy)`;
|
|
682
|
-
else if (typeof newData.name === "string") newData.name = `${newData.name} (Copy)`;
|
|
683
|
-
const slugSource = typeof newData.title === "string" ? newData.title : typeof newData.name === "string" ? newData.name : null;
|
|
684
|
-
const slug = slugSource ? await this.generateUniqueSlug(type, slugSource, original.locale ?? void 0) : null;
|
|
685
|
-
return this.create({
|
|
686
|
-
type,
|
|
687
|
-
slug,
|
|
688
|
-
data: newData,
|
|
689
|
-
status: "draft",
|
|
690
|
-
authorId: authorId || original.authorId || void 0,
|
|
691
|
-
locale: original.locale ?? void 0
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
/**
|
|
695
|
-
* Find content by ID
|
|
696
|
-
*/
|
|
697
|
-
async findById(type, id) {
|
|
698
|
-
const tableName = getTableName(type);
|
|
699
|
-
const row = (await sql`
|
|
700
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
701
|
-
WHERE id = ${id}
|
|
702
|
-
AND deleted_at IS NULL
|
|
703
|
-
`.execute(this.db)).rows[0];
|
|
704
|
-
if (!row) return null;
|
|
705
|
-
return this.mapRow(type, row);
|
|
706
|
-
}
|
|
707
|
-
async findManyByIds(type, ids) {
|
|
708
|
-
const items = /* @__PURE__ */ new Map();
|
|
709
|
-
if (ids.length === 0) return items;
|
|
710
|
-
const tableName = getTableName(type);
|
|
711
|
-
for (const batch of chunks([...new Set(ids)], SQL_BATCH_SIZE)) {
|
|
712
|
-
const result = await sql`
|
|
713
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
714
|
-
WHERE id IN (${sql.join(batch)}) AND deleted_at IS NULL
|
|
715
|
-
`.execute(this.db);
|
|
716
|
-
for (const row of result.rows) {
|
|
717
|
-
const item = this.mapRow(type, row);
|
|
718
|
-
items.set(item.id, item);
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
return items;
|
|
722
|
-
}
|
|
723
|
-
async findManyBySlugsInLocale(type, slugs, locale) {
|
|
724
|
-
const items = /* @__PURE__ */ new Map();
|
|
725
|
-
if (slugs.length === 0) return items;
|
|
726
|
-
const tableName = getTableName(type);
|
|
727
|
-
for (const batch of chunks([...new Set(slugs)], SQL_BATCH_SIZE)) {
|
|
728
|
-
const result = await sql`
|
|
729
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
730
|
-
WHERE slug IN (${sql.join(batch)}) AND locale = ${locale} AND deleted_at IS NULL
|
|
731
|
-
`.execute(this.db);
|
|
732
|
-
for (const row of result.rows) {
|
|
733
|
-
const item = this.mapRow(type, row);
|
|
734
|
-
if (item.slug !== null) items.set(item.slug, item);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
return items;
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
|
-
* Find content by id, including trashed (soft-deleted) items.
|
|
741
|
-
* Used by restore endpoint for ownership checks.
|
|
742
|
-
*/
|
|
743
|
-
async findByIdIncludingTrashed(type, id) {
|
|
744
|
-
const tableName = getTableName(type);
|
|
745
|
-
const row = (await sql`
|
|
746
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
747
|
-
WHERE id = ${id}
|
|
748
|
-
`.execute(this.db)).rows[0];
|
|
749
|
-
if (!row) return null;
|
|
750
|
-
return this.mapRow(type, row);
|
|
751
|
-
}
|
|
752
|
-
/**
|
|
753
|
-
* Find content by ID or slug. Tries ID first if it looks like a ULID,
|
|
754
|
-
* otherwise tries slug. Falls back to the other if the first lookup misses.
|
|
755
|
-
*/
|
|
756
|
-
async findByIdOrSlug(type, identifier, locale) {
|
|
757
|
-
return this._findByIdOrSlug(type, identifier, false, locale);
|
|
758
|
-
}
|
|
759
|
-
/**
|
|
760
|
-
* Find content by ID or slug, including trashed (soft-deleted) items.
|
|
761
|
-
* Used by restore/permanent-delete endpoints.
|
|
762
|
-
*/
|
|
763
|
-
async findByIdOrSlugIncludingTrashed(type, identifier, locale) {
|
|
764
|
-
return this._findByIdOrSlug(type, identifier, true, locale);
|
|
765
|
-
}
|
|
766
|
-
async isTrashed(type, id) {
|
|
767
|
-
const tableName = getTableName(type);
|
|
768
|
-
return await this.db.selectFrom(tableName).select("id").where("id", "=", id).where("deleted_at", "is not", null).executeTakeFirst() !== void 0;
|
|
769
|
-
}
|
|
770
|
-
async _findByIdOrSlug(type, identifier, includeTrashed, locale) {
|
|
771
|
-
const looksLikeUlid = ULID_PATTERN.test(identifier);
|
|
772
|
-
const findById = includeTrashed ? (t, id) => this.findByIdIncludingTrashed(t, id) : (t, id) => this.findById(t, id);
|
|
773
|
-
const findBySlug = includeTrashed ? (t, s) => this.findBySlugIncludingTrashed(t, s, locale) : (t, s) => this.findBySlug(t, s, locale);
|
|
774
|
-
try {
|
|
775
|
-
if (looksLikeUlid) {
|
|
776
|
-
const byId = await findById(type, identifier);
|
|
777
|
-
if (byId) return byId;
|
|
778
|
-
return await findBySlug(type, identifier);
|
|
779
|
-
}
|
|
780
|
-
const bySlug = await findBySlug(type, identifier);
|
|
781
|
-
if (bySlug) return bySlug;
|
|
782
|
-
return await findById(type, identifier);
|
|
783
|
-
} catch (error) {
|
|
784
|
-
if (isMissingTableError(error)) return null;
|
|
785
|
-
throw error;
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* Find content by slug
|
|
790
|
-
*/
|
|
791
|
-
async findBySlug(type, slug, locale) {
|
|
792
|
-
const tableName = getTableName(type);
|
|
793
|
-
const row = (locale ? await sql`
|
|
794
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
795
|
-
WHERE slug = ${slug}
|
|
796
|
-
AND locale = ${locale}
|
|
797
|
-
AND deleted_at IS NULL
|
|
798
|
-
`.execute(this.db) : await sql`
|
|
799
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
800
|
-
WHERE slug = ${slug}
|
|
801
|
-
AND deleted_at IS NULL
|
|
802
|
-
ORDER BY locale ASC
|
|
803
|
-
LIMIT 1
|
|
804
|
-
`.execute(this.db)).rows[0];
|
|
805
|
-
if (!row) return null;
|
|
806
|
-
return this.mapRow(type, row);
|
|
807
|
-
}
|
|
808
|
-
/**
|
|
809
|
-
* Find content by slug, including trashed (soft-deleted) items.
|
|
810
|
-
* Used by restore/permanent-delete endpoints.
|
|
811
|
-
*/
|
|
812
|
-
async findBySlugIncludingTrashed(type, slug, locale) {
|
|
813
|
-
const tableName = getTableName(type);
|
|
814
|
-
const row = (locale ? await sql`
|
|
815
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
816
|
-
WHERE slug = ${slug}
|
|
817
|
-
AND locale = ${locale}
|
|
818
|
-
`.execute(this.db) : await sql`
|
|
819
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
820
|
-
WHERE slug = ${slug}
|
|
821
|
-
ORDER BY locale ASC
|
|
822
|
-
LIMIT 1
|
|
823
|
-
`.execute(this.db)).rows[0];
|
|
824
|
-
if (!row) return null;
|
|
825
|
-
return this.mapRow(type, row);
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
* Find many content items with filtering and pagination
|
|
829
|
-
*/
|
|
830
|
-
async findMany(type, options = {}) {
|
|
831
|
-
const tableName = getTableName(type);
|
|
832
|
-
const limit = Math.min(options.limit || 50, 100);
|
|
833
|
-
const orderField = options.orderBy?.field || "createdAt";
|
|
834
|
-
const orderDirection = options.orderBy?.direction || "desc";
|
|
835
|
-
const resolvedOrderField = await this.resolveOrderField(type, orderField, options.sortableExtras);
|
|
836
|
-
const dbField = resolvedOrderField.column;
|
|
837
|
-
const resolvedFieldFilters = await this.resolveFieldFilters(type, options.where?.fieldFilters);
|
|
838
|
-
const safeOrderDirection = orderDirection.toLowerCase() === "asc" ? "ASC" : "DESC";
|
|
839
|
-
let query = this.db.selectFrom(tableName).selectAll().where("deleted_at", "is", null);
|
|
840
|
-
if (options.where?.status) query = query.where("status", "=", options.where.status);
|
|
841
|
-
if (options.where?.authorId) query = query.where("author_id", "=", options.where.authorId);
|
|
842
|
-
if (options.where?.locale) query = query.where("locale", "=", options.where.locale);
|
|
843
|
-
query = this.applySearchFilter(query, options.where, type);
|
|
844
|
-
query = this.applyDateFilter(query, options.where);
|
|
845
|
-
query = this.applyBylineFilter(query, options.where, type);
|
|
846
|
-
query = this.applyFieldFilters(query, resolvedFieldFilters);
|
|
847
|
-
if (options.cursor) if (resolvedOrderField.indexedCustomField) {
|
|
848
|
-
const { value, id: cursorId } = decodeIndexedFieldCursor(options.cursor, orderField);
|
|
849
|
-
const isPresent = sql`${sql.ref(dbField)} IS NOT NULL`;
|
|
850
|
-
const falseLiteral = sql`FALSE`;
|
|
851
|
-
const trueLiteral = sql`TRUE`;
|
|
852
|
-
if (safeOrderDirection === "ASC" && value === null) query = query.where(sql`
|
|
853
|
-
(${isPresent}) > ${falseLiteral}
|
|
854
|
-
OR ((${isPresent}) = ${falseLiteral} AND ${sql.ref("id")} > ${cursorId})
|
|
855
|
-
`);
|
|
856
|
-
else if (safeOrderDirection === "DESC" && value === null) query = query.where(sql`
|
|
857
|
-
(${isPresent}) = ${falseLiteral} AND ${sql.ref("id")} < ${cursorId}
|
|
858
|
-
`);
|
|
859
|
-
else if (safeOrderDirection === "ASC") query = query.where(sql`
|
|
860
|
-
(${isPresent}, ${sql.ref(dbField)}, ${sql.ref("id")})
|
|
861
|
-
> (${trueLiteral}, ${value}, ${cursorId})
|
|
862
|
-
`);
|
|
863
|
-
else query = query.where(sql`
|
|
864
|
-
(${isPresent}, ${sql.ref(dbField)}, ${sql.ref("id")})
|
|
865
|
-
< (${trueLiteral}, ${value}, ${cursorId})
|
|
866
|
-
`);
|
|
867
|
-
} else {
|
|
868
|
-
const { orderValue, id: cursorId } = decodeCursor(options.cursor);
|
|
869
|
-
if (safeOrderDirection === "DESC") query = query.where((eb) => eb.or([eb(dbField, "<", orderValue), eb.and([eb(dbField, "=", orderValue), eb("id", "<", cursorId)])]));
|
|
870
|
-
else query = query.where((eb) => eb.or([eb(dbField, ">", orderValue), eb.and([eb(dbField, "=", orderValue), eb("id", ">", cursorId)])]));
|
|
871
|
-
}
|
|
872
|
-
const indexedOrderFilter = resolvedOrderField.indexedCustomField ? resolvedFieldFilters.find((filter) => filter.column === dbField) : void 0;
|
|
873
|
-
if (resolvedOrderField.indexedCustomField && !indexedOrderFilter) query = query.orderBy(sql`${sql.ref(dbField)} IS NOT NULL`, safeOrderDirection === "ASC" ? "asc" : "desc");
|
|
874
|
-
if (indexedOrderFilter?.kind !== "null") query = query.orderBy(dbField, safeOrderDirection === "ASC" ? "asc" : "desc");
|
|
875
|
-
query = query.orderBy("id", safeOrderDirection === "ASC" ? "asc" : "desc").limit(limit + 1);
|
|
876
|
-
const [rowsResult, countResult] = await Promise.allSettled([query.execute(), this.countWithResolvedFilters(type, options.where, resolvedFieldFilters)]);
|
|
877
|
-
if (rowsResult.status === "rejected") throw rowsResult.reason;
|
|
878
|
-
if (countResult.status === "rejected") throw countResult.reason;
|
|
879
|
-
const rows = rowsResult.value;
|
|
880
|
-
const total = countResult.value;
|
|
881
|
-
const hasMore = rows.length > limit;
|
|
882
|
-
const items = rows.slice(0, limit);
|
|
883
|
-
const mappedResult = {
|
|
884
|
-
items: items.map((row) => this.mapRow(type, row)),
|
|
885
|
-
total
|
|
886
|
-
};
|
|
887
|
-
if (hasMore && items.length > 0) {
|
|
888
|
-
const lastRow = items.at(-1);
|
|
889
|
-
const lastOrderValue = lastRow[dbField];
|
|
890
|
-
if (resolvedOrderField.indexedCustomField) {
|
|
891
|
-
if (lastOrderValue !== null && typeof lastOrderValue !== "string" && typeof lastOrderValue !== "number") throw new EmDashValidationError(`Invalid indexed value for order field: ${orderField}`);
|
|
892
|
-
mappedResult.nextCursor = encodeIndexedFieldCursor(orderField, lastOrderValue, String(lastRow.id));
|
|
893
|
-
} else mappedResult.nextCursor = encodeCursor(typeof lastOrderValue === "string" || typeof lastOrderValue === "number" ? String(lastOrderValue) : "", String(lastRow.id));
|
|
894
|
-
}
|
|
895
|
-
return mappedResult;
|
|
896
|
-
}
|
|
897
|
-
/**
|
|
898
|
-
* Update content
|
|
899
|
-
*/
|
|
900
|
-
async update(type, id, input) {
|
|
901
|
-
const tableName = getTableName(type);
|
|
902
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
903
|
-
const updates = {};
|
|
904
|
-
if (input.status !== void 0) updates.status = input.status;
|
|
905
|
-
if (input.slug !== void 0) updates.slug = input.slug;
|
|
906
|
-
if (input.publishedAt !== void 0) updates.published_at = input.publishedAt === null ? null : await this.datetimes.normalizeValue(type, input.publishedAt);
|
|
907
|
-
if (input.scheduledAt !== void 0) updates.scheduled_at = input.scheduledAt === null ? null : await this.datetimes.normalizeValue(type, input.scheduledAt);
|
|
908
|
-
if (input.authorId !== void 0) updates.author_id = input.authorId;
|
|
909
|
-
if (input.primaryBylineId !== void 0) updates.primary_byline_id = input.primaryBylineId;
|
|
910
|
-
if (input.data !== void 0 && typeof input.data === "object") {
|
|
911
|
-
const data = await this.datetimes.normalizeData(type, writableContentData(input.data));
|
|
912
|
-
for (const [key, value] of Object.entries(data)) updates[key] = serializeValue(value);
|
|
913
|
-
}
|
|
914
|
-
const hasColumnWrites = Object.keys(updates).length > 0;
|
|
915
|
-
if (hasColumnWrites) updates.updated_at = now;
|
|
916
|
-
updates.version = sql`version + 1`;
|
|
917
|
-
await this.db.updateTable(tableName).set(updates).where("id", "=", id).where("deleted_at", "is", null).execute();
|
|
918
|
-
if (hasColumnWrites) invalidateCollectionCache(type);
|
|
919
|
-
const updated = await this.findById(type, id);
|
|
920
|
-
if (!updated) throw new Error("Content not found");
|
|
921
|
-
return updated;
|
|
922
|
-
}
|
|
923
|
-
async restoreRevision(type, id, revisionData, authorId) {
|
|
924
|
-
const tableName = getTableName(type);
|
|
925
|
-
const existing = await this.findById(type, id);
|
|
926
|
-
if (!existing) throw new EmDashValidationError("Content item not found");
|
|
927
|
-
const normalizedSnapshot = await this.datetimes.normalizeData(type, revisionData);
|
|
928
|
-
const { _slug, ...snapshotFields } = normalizedSnapshot;
|
|
929
|
-
const fieldData = writableContentData(snapshotFields);
|
|
930
|
-
const revisionId = createRevisionId();
|
|
931
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
932
|
-
const assignments = [];
|
|
933
|
-
if (typeof _slug === "string") assignments.push(sql`slug = ${_slug}`);
|
|
934
|
-
for (const [field, value] of Object.entries(fieldData)) {
|
|
935
|
-
validateIdentifier(field, "content field name");
|
|
936
|
-
assignments.push(sql`${sql.ref(field)} = ${serializeValue(value)}`);
|
|
937
|
-
}
|
|
938
|
-
assignments.push(sql`draft_revision_id = ${revisionId}`, sql`updated_at = ${now}`, sql`version = version + 1`);
|
|
939
|
-
const buildQueries = () => {
|
|
940
|
-
return [
|
|
941
|
-
sql`
|
|
942
|
-
INSERT INTO revisions (id, collection, entry_id, data, author_id)
|
|
943
|
-
VALUES (${revisionId}, ${type}, ${id}, ${JSON.stringify(normalizedSnapshot)}, ${authorId})
|
|
944
|
-
RETURNING id
|
|
945
|
-
`,
|
|
946
|
-
sql`
|
|
947
|
-
UPDATE ${sql.ref(tableName)}
|
|
948
|
-
SET ${sql.join(assignments, sql`, `)}
|
|
949
|
-
WHERE id = ${id}
|
|
950
|
-
AND deleted_at IS NULL
|
|
951
|
-
AND version = ${existing.version}
|
|
952
|
-
AND updated_at = ${existing.updatedAt}
|
|
953
|
-
AND status = ${existing.status}
|
|
954
|
-
AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
|
|
955
|
-
AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
|
|
956
|
-
AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
|
|
957
|
-
RETURNING id
|
|
958
|
-
`,
|
|
959
|
-
sql`
|
|
960
|
-
DELETE FROM revisions
|
|
961
|
-
WHERE id = ${revisionId}
|
|
962
|
-
AND NOT EXISTS (
|
|
963
|
-
SELECT 1 FROM ${sql.ref(tableName)}
|
|
964
|
-
WHERE id = ${id}
|
|
965
|
-
AND draft_revision_id = ${revisionId}
|
|
966
|
-
AND version = ${existing.version + 1}
|
|
967
|
-
)
|
|
968
|
-
`,
|
|
969
|
-
sql`
|
|
970
|
-
UPDATE ${sql.ref(tableName)}
|
|
971
|
-
SET draft_revision_id = ${existing.draftRevisionId}
|
|
972
|
-
WHERE id = ${id}
|
|
973
|
-
AND draft_revision_id = ${revisionId}
|
|
974
|
-
AND version = ${existing.version + 1}
|
|
975
|
-
RETURNING id
|
|
976
|
-
`
|
|
977
|
-
];
|
|
978
|
-
};
|
|
979
|
-
const batched = await executeAtomicBatchIfSupported(this.db, buildQueries());
|
|
980
|
-
if (batched) {
|
|
981
|
-
if (batched[0]?.rows.length !== 1 || batched[1]?.rows.length !== 1 || batched[3]?.rows.length !== 1) throw new ContentMutationConflictError();
|
|
982
|
-
} else await withTransaction(this.db, async (trx) => {
|
|
983
|
-
const [audit, update, removeUnappliedAudit, releaseMarker] = buildQueries();
|
|
984
|
-
if ((await audit.execute(trx)).rows.length !== 1) throw new ContentMutationConflictError();
|
|
985
|
-
const updateResult = await update.execute(trx);
|
|
986
|
-
await removeUnappliedAudit.execute(trx);
|
|
987
|
-
const releaseResult = await releaseMarker.execute(trx);
|
|
988
|
-
if (updateResult.rows.length !== 1 || releaseResult.rows.length !== 1) throw new ContentMutationConflictError();
|
|
989
|
-
});
|
|
990
|
-
invalidateCollectionCache(type);
|
|
991
|
-
const item = await this.findById(type, id);
|
|
992
|
-
if (!item) throw new Error("Content not found");
|
|
993
|
-
await new RevisionRepository(this.db, this.datetimeContexts).queuePruning(type, id, revisionId);
|
|
994
|
-
return {
|
|
995
|
-
item,
|
|
996
|
-
revisionId
|
|
997
|
-
};
|
|
998
|
-
}
|
|
999
|
-
async restoreDraftRevision(type, id, revisionData, authorId) {
|
|
1000
|
-
const tableName = getTableName(type);
|
|
1001
|
-
const existing = await this.findById(type, id);
|
|
1002
|
-
if (!existing) return null;
|
|
1003
|
-
const normalizedSnapshot = await this.datetimes.normalizeData(type, revisionData);
|
|
1004
|
-
const revisionId = createRevisionId();
|
|
1005
|
-
const buildQueries = () => {
|
|
1006
|
-
return [
|
|
1007
|
-
sql`
|
|
1008
|
-
INSERT INTO revisions (id, collection, entry_id, data, author_id)
|
|
1009
|
-
VALUES (${revisionId}, ${type}, ${id}, ${JSON.stringify(normalizedSnapshot)}, ${authorId})
|
|
1010
|
-
RETURNING id
|
|
1011
|
-
`,
|
|
1012
|
-
sql`
|
|
1013
|
-
UPDATE ${sql.ref(tableName)}
|
|
1014
|
-
SET draft_revision_id = ${revisionId},
|
|
1015
|
-
version = version + 1
|
|
1016
|
-
WHERE id = ${id}
|
|
1017
|
-
AND deleted_at IS NULL
|
|
1018
|
-
AND version = ${existing.version}
|
|
1019
|
-
AND updated_at = ${existing.updatedAt}
|
|
1020
|
-
AND status = ${existing.status}
|
|
1021
|
-
AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
|
|
1022
|
-
AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
|
|
1023
|
-
AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
|
|
1024
|
-
RETURNING id
|
|
1025
|
-
`,
|
|
1026
|
-
sql`
|
|
1027
|
-
DELETE FROM revisions
|
|
1028
|
-
WHERE id = ${revisionId}
|
|
1029
|
-
AND NOT EXISTS (
|
|
1030
|
-
SELECT 1 FROM ${sql.ref(tableName)}
|
|
1031
|
-
WHERE id = ${id}
|
|
1032
|
-
AND draft_revision_id = ${revisionId}
|
|
1033
|
-
AND version = ${existing.version + 1}
|
|
1034
|
-
)
|
|
1035
|
-
`
|
|
1036
|
-
];
|
|
1037
|
-
};
|
|
1038
|
-
const batched = await executeAtomicBatchIfSupported(this.db, buildQueries());
|
|
1039
|
-
if (batched) {
|
|
1040
|
-
if (batched[0]?.rows.length !== 1 || batched[1]?.rows.length !== 1) throw new ContentMutationConflictError();
|
|
1041
|
-
} else await withTransaction(this.db, async (trx) => {
|
|
1042
|
-
const [audit, stage, removeUnstagedAudit] = buildQueries();
|
|
1043
|
-
if ((await audit.execute(trx)).rows.length !== 1) throw new ContentMutationConflictError();
|
|
1044
|
-
const stageResult = await stage.execute(trx);
|
|
1045
|
-
await removeUnstagedAudit.execute(trx);
|
|
1046
|
-
if (stageResult.rows.length !== 1) throw new ContentMutationConflictError();
|
|
1047
|
-
});
|
|
1048
|
-
invalidateCollectionCache(type);
|
|
1049
|
-
await new RevisionRepository(this.db, this.datetimeContexts).queuePruning(type, id, revisionId);
|
|
1050
|
-
return revisionId;
|
|
1051
|
-
}
|
|
1052
|
-
/**
|
|
1053
|
-
* Update plugin-authored fields without letting content columns diverge
|
|
1054
|
-
* from the revision pointers that publication promotes.
|
|
1055
|
-
*/
|
|
1056
|
-
async updateDraftAware(type, id, input) {
|
|
1057
|
-
const data = input.data ? await this.datetimes.normalizeData(type, writableContentData(input.data)) : {};
|
|
1058
|
-
const stagedSlug = typeof input.slug === "string" ? input.slug : void 0;
|
|
1059
|
-
if (!(Object.keys(data).length > 0 || stagedSlug !== void 0)) return this.update(type, id, {
|
|
1060
|
-
...input,
|
|
1061
|
-
data
|
|
1062
|
-
});
|
|
1063
|
-
const collectionRows = await this.db.selectFrom("_emdash_collections as collection").leftJoin("_emdash_fields as field", "field.collection_id", "collection.id").select(["collection.supports", "field.slug as fieldSlug"]).where("collection.slug", "=", type).execute();
|
|
1064
|
-
const supportsRaw = collectionRows[0]?.supports;
|
|
1065
|
-
const supports = supportsRaw ? JSON.parse(supportsRaw) : [];
|
|
1066
|
-
if (!Array.isArray(supports) || !supports.includes("revisions")) return this.update(type, id, {
|
|
1067
|
-
...input,
|
|
1068
|
-
data
|
|
1069
|
-
});
|
|
1070
|
-
const fieldSlugs = new Set(collectionRows.map((row) => row.fieldSlug).filter((slug) => Boolean(slug)));
|
|
1071
|
-
const revisionRepo = new RevisionRepository(this.db, this.datetimeContexts);
|
|
1072
|
-
let existing = await this.findById(type, id);
|
|
1073
|
-
let incoming = data;
|
|
1074
|
-
if (existing) {
|
|
1075
|
-
let stored = existing.data ?? {};
|
|
1076
|
-
if (existing.draftRevisionId) {
|
|
1077
|
-
const draft = await revisionRepo.findById(existing.draftRevisionId);
|
|
1078
|
-
if (draft?.data) stored = draft.data;
|
|
1079
|
-
}
|
|
1080
|
-
const stale = staleStoredKeys(data, stored, fieldSlugs);
|
|
1081
|
-
if (stale.length > 0) {
|
|
1082
|
-
incoming = { ...data };
|
|
1083
|
-
for (const key of stale) delete incoming[key];
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
for (const field of Object.keys(incoming)) if (!fieldSlugs.has(field)) throw new EmDashValidationError(`Unknown field '${field}' in collection '${type}'`);
|
|
1087
|
-
for (let attempt = 0; existing && attempt < MAX_DRAFT_STAGE_ATTEMPTS; attempt++) {
|
|
1088
|
-
let baseData = existing.data;
|
|
1089
|
-
if (existing.draftRevisionId) {
|
|
1090
|
-
const draft = await revisionRepo.findById(existing.draftRevisionId);
|
|
1091
|
-
if (draft) baseData = draft.data;
|
|
1092
|
-
}
|
|
1093
|
-
const mergedData = keepKnownFields({
|
|
1094
|
-
...baseData,
|
|
1095
|
-
...incoming
|
|
1096
|
-
}, fieldSlugs);
|
|
1097
|
-
if (stagedSlug !== void 0) mergedData._slug = stagedSlug;
|
|
1098
|
-
const revision = await revisionRepo.create({
|
|
1099
|
-
collection: type,
|
|
1100
|
-
entryId: id,
|
|
1101
|
-
data: mergedData,
|
|
1102
|
-
...input.revisionAuthorId ? { authorId: input.revisionAuthorId } : {}
|
|
1103
|
-
});
|
|
1104
|
-
let staged;
|
|
1105
|
-
try {
|
|
1106
|
-
staged = await this.replaceDraftRevisionForUpdate(type, id, revision.id, existing, input);
|
|
1107
|
-
} catch (error) {
|
|
1108
|
-
await this.deleteUnstagedRevision(revisionRepo, type, id, revision.id);
|
|
1109
|
-
throw error;
|
|
1110
|
-
}
|
|
1111
|
-
if (staged) {
|
|
1112
|
-
const updated = await this.findById(type, id);
|
|
1113
|
-
if (!updated) throw new Error("Content not found");
|
|
1114
|
-
const draftData = {};
|
|
1115
|
-
for (const [key, value] of Object.entries(mergedData)) if (!key.startsWith("_")) draftData[key] = value;
|
|
1116
|
-
return {
|
|
1117
|
-
...updated,
|
|
1118
|
-
data: {
|
|
1119
|
-
...updated.data,
|
|
1120
|
-
...draftData
|
|
1121
|
-
}
|
|
1122
|
-
};
|
|
1123
|
-
}
|
|
1124
|
-
await this.deleteUnstagedRevision(revisionRepo, type, id, revision.id);
|
|
1125
|
-
existing = await this.findById(type, id);
|
|
1126
|
-
}
|
|
1127
|
-
if (!existing) throw new Error("Content not found");
|
|
1128
|
-
throw new ContentMutationConflictError();
|
|
1129
|
-
}
|
|
1130
|
-
async deleteUnstagedRevision(revisionRepo, type, id, revisionId) {
|
|
1131
|
-
try {
|
|
1132
|
-
await revisionRepo.deleteIfUnreferenced(type, id, revisionId);
|
|
1133
|
-
} catch (error) {
|
|
1134
|
-
console.error(`[content] Failed to clean up unstaged revision ${revisionId}:`, error);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
async replaceDraftRevisionForUpdate(type, id, revisionId, expected, input) {
|
|
1138
|
-
const tableName = getTableName(type);
|
|
1139
|
-
const assignments = [sql`draft_revision_id = ${revisionId}`];
|
|
1140
|
-
let liveMetadataChanged = false;
|
|
1141
|
-
if (input.status !== void 0) {
|
|
1142
|
-
assignments.push(sql`status = ${input.status}`);
|
|
1143
|
-
liveMetadataChanged = true;
|
|
1144
|
-
}
|
|
1145
|
-
if (input.slug === null) {
|
|
1146
|
-
assignments.push(sql`slug = NULL`);
|
|
1147
|
-
liveMetadataChanged = true;
|
|
1148
|
-
}
|
|
1149
|
-
if (input.publishedAt !== void 0) {
|
|
1150
|
-
const publishedAt = input.publishedAt === null ? null : await this.datetimes.normalizeValue(type, input.publishedAt);
|
|
1151
|
-
assignments.push(sql`published_at = ${publishedAt}`);
|
|
1152
|
-
liveMetadataChanged = true;
|
|
1153
|
-
}
|
|
1154
|
-
if (input.scheduledAt !== void 0) {
|
|
1155
|
-
const scheduledAt = input.scheduledAt === null ? null : await this.datetimes.normalizeValue(type, input.scheduledAt);
|
|
1156
|
-
assignments.push(sql`scheduled_at = ${scheduledAt}`);
|
|
1157
|
-
liveMetadataChanged = true;
|
|
1158
|
-
}
|
|
1159
|
-
if (input.authorId !== void 0) {
|
|
1160
|
-
assignments.push(sql`author_id = ${input.authorId}`);
|
|
1161
|
-
liveMetadataChanged = true;
|
|
1162
|
-
}
|
|
1163
|
-
if (input.primaryBylineId !== void 0) {
|
|
1164
|
-
assignments.push(sql`primary_byline_id = ${input.primaryBylineId}`);
|
|
1165
|
-
liveMetadataChanged = true;
|
|
1166
|
-
}
|
|
1167
|
-
if (liveMetadataChanged) assignments.push(sql`updated_at = ${(/* @__PURE__ */ new Date()).toISOString()}`);
|
|
1168
|
-
assignments.push(sql`version = version + 1`);
|
|
1169
|
-
const changed = ((await sql`
|
|
1170
|
-
UPDATE ${sql.ref(tableName)}
|
|
1171
|
-
SET ${sql.join(assignments, sql`, `)}
|
|
1172
|
-
WHERE id = ${id}
|
|
1173
|
-
AND deleted_at IS NULL
|
|
1174
|
-
AND version = ${expected.version}
|
|
1175
|
-
AND ${nullableColumnMatch("live_revision_id", expected.liveRevisionId)}
|
|
1176
|
-
AND ${nullableColumnMatch("draft_revision_id", expected.draftRevisionId)}
|
|
1177
|
-
AND EXISTS (
|
|
1178
|
-
SELECT 1 FROM revisions
|
|
1179
|
-
WHERE revisions.id = ${revisionId}
|
|
1180
|
-
AND revisions.collection = ${type}
|
|
1181
|
-
AND revisions.entry_id = ${id}
|
|
1182
|
-
)
|
|
1183
|
-
`.execute(this.db)).numAffectedRows ?? 0n) > 0n;
|
|
1184
|
-
if (changed && liveMetadataChanged) invalidateCollectionCache(type);
|
|
1185
|
-
return changed;
|
|
1186
|
-
}
|
|
1187
|
-
/**
|
|
1188
|
-
* Copy non-translatable field values to every other entry in the
|
|
1189
|
-
* translation group, trashed entries included.
|
|
1190
|
-
*
|
|
1191
|
-
* Only the fields present in `data` are copied. With `previous`, `data` is
|
|
1192
|
-
* the entry's complete new state and only the fields whose value differs
|
|
1193
|
-
* from `previous` are copied, an absent field as null. An entry that already
|
|
1194
|
-
* holds every copied value is left untouched, so its `updated_at` does not
|
|
1195
|
-
* move.
|
|
1196
|
-
*
|
|
1197
|
-
* On collections with revisions a changed entry also gets a new live
|
|
1198
|
-
* revision, because republishing and unpublishing read that revision rather
|
|
1199
|
-
* than the columns. A pending draft takes a value only where it still holds
|
|
1200
|
-
* the entry's previous value, so an unpublished edit to the field survives.
|
|
1201
|
-
*/
|
|
1202
|
-
async syncNonTranslatableFields(type, sourceId, translationGroup, data, options = {}) {
|
|
1203
|
-
const tableName = getTableName(type);
|
|
1204
|
-
const collectionRows = await this.db.selectFrom("_emdash_collections as collection").leftJoin("_emdash_fields as field", (join) => join.onRef("field.collection_id", "=", "collection.id").on("field.translatable", "=", 0)).select(["collection.supports", "field.slug as fieldSlug"]).where("collection.slug", "=", type).execute();
|
|
1205
|
-
const { previous } = options;
|
|
1206
|
-
const values = {};
|
|
1207
|
-
for (const { fieldSlug } of collectionRows) {
|
|
1208
|
-
if (!fieldSlug) continue;
|
|
1209
|
-
if (previous) {
|
|
1210
|
-
if (!sameStoredValue(previous[fieldSlug], data[fieldSlug])) values[fieldSlug] = data[fieldSlug] ?? null;
|
|
1211
|
-
} else if (fieldSlug in data) values[fieldSlug] = data[fieldSlug];
|
|
1212
|
-
}
|
|
1213
|
-
if (Object.keys(values).length === 0) return;
|
|
1214
|
-
const normalizedValues = await this.datetimes.normalizeData(type, values);
|
|
1215
|
-
const supportsRaw = collectionRows[0]?.supports;
|
|
1216
|
-
const supports = supportsRaw ? JSON.parse(supportsRaw) : [];
|
|
1217
|
-
const usesRevisions = Array.isArray(supports) && supports.includes("revisions");
|
|
1218
|
-
const siblings = await sql`
|
|
1219
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
1220
|
-
WHERE translation_group = ${translationGroup}
|
|
1221
|
-
AND id != ${sourceId}
|
|
1222
|
-
`.execute(this.db);
|
|
1223
|
-
let changed = false;
|
|
1224
|
-
for (const row of siblings.rows) if (await this.syncSiblingValues(type, this.mapRow(type, row), normalizedValues, usesRevisions)) changed = true;
|
|
1225
|
-
if (changed) invalidateCollectionCache(type);
|
|
1226
|
-
}
|
|
1227
|
-
async syncSiblingValues(type, initial, values, usesRevisions) {
|
|
1228
|
-
const tableName = getTableName(type);
|
|
1229
|
-
const revisionRepo = new RevisionRepository(this.db, this.datetimeContexts);
|
|
1230
|
-
let sibling = initial;
|
|
1231
|
-
for (let attempt = 0; sibling && attempt < MAX_DRAFT_STAGE_ATTEMPTS; attempt++) {
|
|
1232
|
-
const current = sibling;
|
|
1233
|
-
const changed = {};
|
|
1234
|
-
for (const [field, value] of Object.entries(values)) if (!sameStoredValue(current.data[field], value)) changed[field] = value;
|
|
1235
|
-
if (Object.keys(changed).length === 0) return false;
|
|
1236
|
-
const assignments = [];
|
|
1237
|
-
for (const [field, value] of Object.entries(changed)) {
|
|
1238
|
-
validateIdentifier(field, "content field name");
|
|
1239
|
-
assignments.push(sql`${sql.ref(field)} = ${serializeValue(value)}`);
|
|
1240
|
-
}
|
|
1241
|
-
const createdRevisionIds = [];
|
|
1242
|
-
const cleanUp = async () => {
|
|
1243
|
-
for (const revisionId of createdRevisionIds) await this.deleteUnstagedRevision(revisionRepo, type, current.id, revisionId);
|
|
1244
|
-
};
|
|
1245
|
-
let synced;
|
|
1246
|
-
try {
|
|
1247
|
-
const live = usesRevisions && current.liveRevisionId ? await revisionRepo.findById(current.liveRevisionId) : null;
|
|
1248
|
-
if (live) {
|
|
1249
|
-
const revision = await revisionRepo.create({
|
|
1250
|
-
collection: type,
|
|
1251
|
-
entryId: current.id,
|
|
1252
|
-
data: {
|
|
1253
|
-
...live.data,
|
|
1254
|
-
...changed
|
|
1255
|
-
}
|
|
1256
|
-
});
|
|
1257
|
-
createdRevisionIds.push(revision.id);
|
|
1258
|
-
assignments.push(sql`live_revision_id = ${revision.id}`);
|
|
1259
|
-
}
|
|
1260
|
-
const draft = usesRevisions && current.draftRevisionId ? await revisionRepo.findById(current.draftRevisionId) : null;
|
|
1261
|
-
const carried = {};
|
|
1262
|
-
for (const [field, value] of Object.entries(changed)) if (draft && sameStoredValue(draft.data[field], current.data[field])) carried[field] = value;
|
|
1263
|
-
if (draft && Object.keys(carried).length > 0) {
|
|
1264
|
-
const revision = await revisionRepo.create({
|
|
1265
|
-
collection: type,
|
|
1266
|
-
entryId: current.id,
|
|
1267
|
-
data: {
|
|
1268
|
-
...draft.data,
|
|
1269
|
-
...carried
|
|
1270
|
-
}
|
|
1271
|
-
});
|
|
1272
|
-
createdRevisionIds.push(revision.id);
|
|
1273
|
-
assignments.push(sql`draft_revision_id = ${revision.id}`);
|
|
1274
|
-
}
|
|
1275
|
-
assignments.push(sql`updated_at = ${(/* @__PURE__ */ new Date()).toISOString()}`, sql`version = version + 1`);
|
|
1276
|
-
synced = ((await sql`
|
|
1277
|
-
UPDATE ${sql.ref(tableName)}
|
|
1278
|
-
SET ${sql.join(assignments, sql`, `)}
|
|
1279
|
-
WHERE id = ${current.id}
|
|
1280
|
-
AND version = ${current.version}
|
|
1281
|
-
AND ${nullableColumnMatch("live_revision_id", current.liveRevisionId)}
|
|
1282
|
-
AND ${nullableColumnMatch("draft_revision_id", current.draftRevisionId)}
|
|
1283
|
-
`.execute(this.db)).numAffectedRows ?? 0n) > 0n;
|
|
1284
|
-
} catch (error) {
|
|
1285
|
-
await cleanUp();
|
|
1286
|
-
throw error;
|
|
1287
|
-
}
|
|
1288
|
-
if (synced) return true;
|
|
1289
|
-
await cleanUp();
|
|
1290
|
-
sibling = await this.findByIdIncludingTrashed(type, current.id);
|
|
1291
|
-
}
|
|
1292
|
-
if (!sibling) return false;
|
|
1293
|
-
throw new ContentMutationConflictError();
|
|
1294
|
-
}
|
|
1295
|
-
/**
|
|
1296
|
-
* Delete content (soft delete - moves to trash)
|
|
1297
|
-
*/
|
|
1298
|
-
async delete(type, id) {
|
|
1299
|
-
const tableName = getTableName(type);
|
|
1300
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1301
|
-
const changed = ((await sql`
|
|
1302
|
-
UPDATE ${sql.ref(tableName)}
|
|
1303
|
-
SET deleted_at = ${now}
|
|
1304
|
-
WHERE id = ${id}
|
|
1305
|
-
AND deleted_at IS NULL
|
|
1306
|
-
`.execute(this.db)).numAffectedRows ?? 0n) > 0n;
|
|
1307
|
-
if (changed) invalidateCollectionCache(type);
|
|
1308
|
-
return changed;
|
|
1309
|
-
}
|
|
1310
|
-
/**
|
|
1311
|
-
* Restore content from trash
|
|
1312
|
-
*
|
|
1313
|
-
* The entry comes back as a draft with no schedule. The live version is not
|
|
1314
|
-
* copied into a draft revision: collections without revisions save to the
|
|
1315
|
-
* columns, and a draft revision would hide those saves.
|
|
1316
|
-
*/
|
|
1317
|
-
async restore(type, id, expectedRevision) {
|
|
1318
|
-
const tableName = getTableName(type);
|
|
1319
|
-
const existing = await this.findByIdOrSlugIncludingTrashed(type, id);
|
|
1320
|
-
if (!existing) return null;
|
|
1321
|
-
assertRevisionPrecondition(existing, expectedRevision);
|
|
1322
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1323
|
-
const restored = (await sql`
|
|
1324
|
-
UPDATE ${sql.ref(tableName)}
|
|
1325
|
-
SET deleted_at = NULL,
|
|
1326
|
-
live_revision_id = NULL,
|
|
1327
|
-
status = 'draft',
|
|
1328
|
-
scheduled_at = NULL,
|
|
1329
|
-
updated_at = ${now},
|
|
1330
|
-
version = ${existing.version + 1}
|
|
1331
|
-
WHERE id = ${existing.id}
|
|
1332
|
-
AND deleted_at IS NOT NULL
|
|
1333
|
-
AND version = ${existing.version}
|
|
1334
|
-
AND updated_at = ${existing.updatedAt}
|
|
1335
|
-
RETURNING *
|
|
1336
|
-
`.execute(this.db)).rows[0];
|
|
1337
|
-
if (!restored) throw new ContentMutationConflictError("Content changed while restoring");
|
|
1338
|
-
invalidateCollectionCache(type);
|
|
1339
|
-
return this.mapRow(type, restored);
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
|
-
* Permanently delete content (cannot be undone)
|
|
1343
|
-
*/
|
|
1344
|
-
/**
|
|
1345
|
-
* Permanently delete a soft-deleted content row.
|
|
1346
|
-
*
|
|
1347
|
-
* Returns `true` only when a soft-deleted (trashed) row was removed.
|
|
1348
|
-
* Returns `false` when no row exists OR when the row exists but is live —
|
|
1349
|
-
* the caller is responsible for distinguishing these cases (typically via
|
|
1350
|
-
* a follow-up `findByIdOrSlugIncludingTrashed` to surface NOT_FOUND vs
|
|
1351
|
-
* NOT_TRASHED). The `AND deleted_at IS NOT NULL` clause is the safety net
|
|
1352
|
-
* that prevents permanent delete from bypassing the trash workflow.
|
|
1353
|
-
*/
|
|
1354
|
-
async permanentDelete(type, id) {
|
|
1355
|
-
const tableName = getTableName(type);
|
|
1356
|
-
const changed = ((await sql`
|
|
1357
|
-
DELETE FROM ${sql.ref(tableName)}
|
|
1358
|
-
WHERE id = ${id}
|
|
1359
|
-
AND deleted_at IS NOT NULL
|
|
1360
|
-
`.execute(this.db)).numAffectedRows ?? 0n) > 0n;
|
|
1361
|
-
if (changed) invalidateCollectionCache(type);
|
|
1362
|
-
return changed;
|
|
1363
|
-
}
|
|
1364
|
-
/**
|
|
1365
|
-
* Find trashed content items
|
|
1366
|
-
*/
|
|
1367
|
-
async findTrashed(type, options = {}) {
|
|
1368
|
-
const tableName = getTableName(type);
|
|
1369
|
-
const limit = Math.min(options.limit || 50, 100);
|
|
1370
|
-
const orderField = options.orderBy?.field || "deletedAt";
|
|
1371
|
-
const orderDirection = options.orderBy?.direction || "desc";
|
|
1372
|
-
const dbField = this.mapOrderField(orderField);
|
|
1373
|
-
const safeOrderDirection = orderDirection.toLowerCase() === "asc" ? "ASC" : "DESC";
|
|
1374
|
-
let query = this.db.selectFrom(tableName).selectAll().where("deleted_at", "is not", null);
|
|
1375
|
-
if (options.where?.locale) query = query.where("locale", "=", options.where.locale);
|
|
1376
|
-
if (options.cursor) {
|
|
1377
|
-
const { orderValue, id: cursorId } = decodeCursor(options.cursor);
|
|
1378
|
-
if (safeOrderDirection === "DESC") query = query.where((eb) => eb.or([eb(dbField, "<", orderValue), eb.and([eb(dbField, "=", orderValue), eb("id", "<", cursorId)])]));
|
|
1379
|
-
else query = query.where((eb) => eb.or([eb(dbField, ">", orderValue), eb.and([eb(dbField, "=", orderValue), eb("id", ">", cursorId)])]));
|
|
1380
|
-
}
|
|
1381
|
-
query = query.orderBy(dbField, safeOrderDirection === "ASC" ? "asc" : "desc").orderBy("id", safeOrderDirection === "ASC" ? "asc" : "desc").limit(limit + 1);
|
|
1382
|
-
const rows = await query.execute();
|
|
1383
|
-
const hasMore = rows.length > limit;
|
|
1384
|
-
const items = rows.slice(0, limit);
|
|
1385
|
-
const mappedResult = { items: items.map((row) => {
|
|
1386
|
-
const record = row;
|
|
1387
|
-
return {
|
|
1388
|
-
...this.mapRow(type, record),
|
|
1389
|
-
deletedAt: typeof record.deleted_at === "string" ? record.deleted_at : ""
|
|
1390
|
-
};
|
|
1391
|
-
}) };
|
|
1392
|
-
if (hasMore && items.length > 0) {
|
|
1393
|
-
const lastRow = items.at(-1);
|
|
1394
|
-
const lastOrderValue = lastRow[dbField];
|
|
1395
|
-
mappedResult.nextCursor = encodeCursor(typeof lastOrderValue === "string" || typeof lastOrderValue === "number" ? String(lastOrderValue) : "", String(lastRow.id));
|
|
1396
|
-
}
|
|
1397
|
-
return mappedResult;
|
|
1398
|
-
}
|
|
1399
|
-
/**
|
|
1400
|
-
* Count trashed content items
|
|
1401
|
-
*/
|
|
1402
|
-
async countTrashed(type, options = {}) {
|
|
1403
|
-
const tableName = getTableName(type);
|
|
1404
|
-
let query = this.db.selectFrom(tableName).select((eb) => eb.fn.count("id").as("count")).where("deleted_at", "is not", null);
|
|
1405
|
-
if (options.locale) query = query.where("locale", "=", options.locale);
|
|
1406
|
-
const result = await query.executeTakeFirst();
|
|
1407
|
-
return Number(result?.count || 0);
|
|
1408
|
-
}
|
|
1409
|
-
/**
|
|
1410
|
-
* Apply the optional `q` filter.
|
|
1411
|
-
*
|
|
1412
|
-
* When the handler sets `useFts` (collection has a healthy FTS5 index
|
|
1413
|
-
* covering the display columns; SQLite only), the filter is served from
|
|
1414
|
-
* the index: a token-prefix MATCH against `_emdash_fts_<slug>` OR'd with
|
|
1415
|
-
* an index-served `slug GLOB 'term*'` prefix (the slug is not in the FTS
|
|
1416
|
-
* index). Both sides are index-backed, so SQLite's OR optimization avoids
|
|
1417
|
-
* the full-table scan the LIKE fallback needs (#1517). The trade-off is
|
|
1418
|
-
* search semantics: token-prefix matching instead of arbitrary substring.
|
|
1419
|
-
*
|
|
1420
|
-
* Fallback (Postgres, search disabled, or no usable terms): case-
|
|
1421
|
-
* insensitive substring LIKE across the handler-resolved `searchColumns`
|
|
1422
|
-
* (OR'd). User input is treated literally (LIKE wildcards escaped) and
|
|
1423
|
-
* `lower()` is applied on both sides for SQLite/Postgres parity.
|
|
1424
|
-
*/
|
|
1425
|
-
applySearchFilter(query, where, type) {
|
|
1426
|
-
const term = where?.q?.trim();
|
|
1427
|
-
const columns = where?.searchColumns;
|
|
1428
|
-
if (!term || !columns || columns.length === 0) return query;
|
|
1429
|
-
if (where.useFts) {
|
|
1430
|
-
const match = buildFtsPrefixMatch(term);
|
|
1431
|
-
if (match) {
|
|
1432
|
-
validateIdentifier(type, "collection slug");
|
|
1433
|
-
const ftsTable = `_emdash_fts_${type}`;
|
|
1434
|
-
const slugPrefix = buildSlugGlobPrefix(term);
|
|
1435
|
-
return query.where((eb) => eb.or([sql`id IN (SELECT id FROM ${sql.ref(ftsTable)} WHERE ${sql.ref(ftsTable)} MATCH ${match})`, sql`slug GLOB ${slugPrefix}`]));
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
const pattern = `%${term.replace(LIKE_WILDCARD_RE, (c) => `\\${c}`)}%`;
|
|
1439
|
-
return query.where((eb) => eb.or(columns.map((col) => {
|
|
1440
|
-
validateIdentifier(col, "search column");
|
|
1441
|
-
return sql`lower(CAST(${sql.ref(col)} AS TEXT)) LIKE lower(${pattern}) ESCAPE '\\'`;
|
|
1442
|
-
})));
|
|
1443
|
-
}
|
|
1444
|
-
/**
|
|
1445
|
-
* Apply the optional inclusive date-range filter. The field is mapped
|
|
1446
|
-
* through `DATE_FILTER_COLUMNS` (a closed whitelist), and bounds compare
|
|
1447
|
-
* lexicographically against the stored ISO 8601 timestamps. A `publishedAt`
|
|
1448
|
-
* range naturally excludes never-published rows (their column is NULL).
|
|
1449
|
-
*/
|
|
1450
|
-
applyDateFilter(query, where) {
|
|
1451
|
-
const filter = where?.dateFilter;
|
|
1452
|
-
if (!filter) return query;
|
|
1453
|
-
const column = DATE_FILTER_COLUMNS[filter.field];
|
|
1454
|
-
if (!column) throw new EmDashValidationError(`Invalid date filter field: ${filter.field}`);
|
|
1455
|
-
const { from, to } = filter;
|
|
1456
|
-
if (!from && !to) return query;
|
|
1457
|
-
let next = query;
|
|
1458
|
-
if (from) next = next.where((eb) => eb(column, ">=", from));
|
|
1459
|
-
if (to) next = next.where((eb) => eb(column, "<=", to));
|
|
1460
|
-
return next;
|
|
1461
|
-
}
|
|
1462
|
-
/**
|
|
1463
|
-
* Apply the optional byline filter as a correlated (NOT) EXISTS against
|
|
1464
|
-
* `_emdash_content_bylines`.
|
|
1465
|
-
*
|
|
1466
|
-
* Correlating from the content table preserves the outer sort index so
|
|
1467
|
-
* `LIMIT` can short-circuit. `mode: "none"` tests the junction rather than
|
|
1468
|
-
* `primary_byline_id` because the two are written in the same call but
|
|
1469
|
-
* are not atomically consistent, so the junction is authoritative.
|
|
1470
|
-
*
|
|
1471
|
-
* Whether a credit *renders* is locale-scoped; whether one *exists* is
|
|
1472
|
-
* not. Both are needed: the first decides what the filter matches, the
|
|
1473
|
-
* second decides whether the author fallback applies at all.
|
|
1474
|
-
*/
|
|
1475
|
-
applyBylineFilter(query, where, type) {
|
|
1476
|
-
const filter = where?.bylineFilter;
|
|
1477
|
-
if (!filter) return query;
|
|
1478
|
-
const tableName = getTableName(type);
|
|
1479
|
-
const idColumn = `${tableName}.id`;
|
|
1480
|
-
const authorColumn = `${tableName}.author_id`;
|
|
1481
|
-
const localeColumn = `${tableName}.locale`;
|
|
1482
|
-
const creditRenders = (eb, bylineIds) => {
|
|
1483
|
-
let sub = eb.selectFrom("_emdash_content_bylines as cb").innerJoin("_emdash_bylines as b", "b.translation_group", "cb.byline_id").select("cb.id").where("cb.collection_slug", "=", type).whereRef("cb.content_id", "=", idColumn);
|
|
1484
|
-
sub = filter.locale ? sub.where("b.locale", "=", filter.locale) : sub.whereRef("b.locale", "=", localeColumn);
|
|
1485
|
-
if (bylineIds) sub = sub.where("cb.byline_id", "in", bylineIds);
|
|
1486
|
-
return eb.exists(sub);
|
|
1487
|
-
};
|
|
1488
|
-
const hasExplicitCredit = (eb) => eb.exists(eb.selectFrom("_emdash_content_bylines as cb").select("cb.id").where("cb.collection_slug", "=", type).whereRef("cb.content_id", "=", idColumn));
|
|
1489
|
-
const authorHasByline = (eb, bylineIds) => {
|
|
1490
|
-
let sub = eb.selectFrom("_emdash_bylines as b").select("b.id").whereRef("b.user_id", "=", authorColumn);
|
|
1491
|
-
sub = filter.locale ? sub.where("b.locale", "=", filter.locale) : sub.whereRef("b.locale", "=", localeColumn);
|
|
1492
|
-
if (bylineIds) sub = sub.where("b.translation_group", "in", bylineIds);
|
|
1493
|
-
return eb.exists(sub);
|
|
1494
|
-
};
|
|
1495
|
-
if (filter.mode === "none") return query.where((eb) => {
|
|
1496
|
-
const uncredited = eb.not(creditRenders(eb));
|
|
1497
|
-
return filter.includeInferred ? eb.and([uncredited, eb.or([hasExplicitCredit(eb), eb.not(authorHasByline(eb))])]) : uncredited;
|
|
1498
|
-
});
|
|
1499
|
-
const bylineIds = filter.bylineIds ?? [];
|
|
1500
|
-
if (bylineIds.length === 0) return query.where(() => sql`1 = 0`);
|
|
1501
|
-
return query.where((eb) => {
|
|
1502
|
-
if (!filter.includeInferred) return creditRenders(eb, bylineIds);
|
|
1503
|
-
return eb.or([creditRenders(eb, bylineIds), eb.and([eb.not(hasExplicitCredit(eb)), authorHasByline(eb, bylineIds)])]);
|
|
1504
|
-
});
|
|
1505
|
-
}
|
|
1506
|
-
/**
|
|
1507
|
-
* Count content items
|
|
1508
|
-
*/
|
|
1509
|
-
async count(type, where) {
|
|
1510
|
-
const resolvedFieldFilters = await this.resolveFieldFilters(type, where?.fieldFilters);
|
|
1511
|
-
return this.countWithResolvedFilters(type, where, resolvedFieldFilters);
|
|
1512
|
-
}
|
|
1513
|
-
async countWithResolvedFilters(type, where, resolvedFieldFilters) {
|
|
1514
|
-
const tableName = getTableName(type);
|
|
1515
|
-
let query = this.db.selectFrom(tableName).select((eb) => eb.fn.count("id").as("count")).where("deleted_at", "is", null);
|
|
1516
|
-
if (where?.status) query = query.where("status", "=", where.status);
|
|
1517
|
-
if (where?.authorId) query = query.where("author_id", "=", where.authorId);
|
|
1518
|
-
if (where?.locale) query = query.where("locale", "=", where.locale);
|
|
1519
|
-
query = this.applySearchFilter(query, where, type);
|
|
1520
|
-
query = this.applyDateFilter(query, where);
|
|
1521
|
-
query = this.applyBylineFilter(query, where, type);
|
|
1522
|
-
query = this.applyFieldFilters(query, resolvedFieldFilters);
|
|
1523
|
-
const result = await query.executeTakeFirst();
|
|
1524
|
-
return Number(result?.count || 0);
|
|
1525
|
-
}
|
|
1526
|
-
/**
|
|
1527
|
-
* Distinct, non-null `author_id` values across the collection's live
|
|
1528
|
-
* (non-trashed) content. Used to populate the admin author filter with
|
|
1529
|
-
* only the users who have actually authored entries, rather than the
|
|
1530
|
-
* full user directory (which requires admin privileges to read).
|
|
1531
|
-
*/
|
|
1532
|
-
async findDistinctAuthorIds(type) {
|
|
1533
|
-
const tableName = getTableName(type);
|
|
1534
|
-
return (await this.db.selectFrom(tableName).select("author_id").distinct().where("deleted_at", "is", null).where("author_id", "is not", null).execute()).map((row) => row.author_id).filter((id) => id !== null);
|
|
1535
|
-
}
|
|
1536
|
-
async getStats(type, now = /* @__PURE__ */ new Date()) {
|
|
1537
|
-
const tableName = getTableName(type);
|
|
1538
|
-
const nowIso = now.toISOString();
|
|
1539
|
-
const result = await this.db.selectFrom(tableName).select((eb) => [
|
|
1540
|
-
eb.fn.count("id").as("total"),
|
|
1541
|
-
eb.fn.sum(eb.case().when("status", "=", "published").then(1).else(0).end()).as("published"),
|
|
1542
|
-
eb.fn.sum(eb.case().when("status", "=", "draft").then(1).else(0).end()).as("draft"),
|
|
1543
|
-
sql`SUM(CASE WHEN scheduled_at IS NOT NULL THEN 1 ELSE 0 END)`.as("scheduled"),
|
|
1544
|
-
sql`SUM(CASE WHEN scheduled_at IS NOT NULL AND scheduled_at <= ${nowIso} THEN 1 ELSE 0 END)`.as("overdue_scheduled")
|
|
1545
|
-
]).where("deleted_at", "is", null).executeTakeFirst();
|
|
1546
|
-
return {
|
|
1547
|
-
total: Number(result?.total || 0),
|
|
1548
|
-
published: Number(result?.published || 0),
|
|
1549
|
-
draft: Number(result?.draft || 0),
|
|
1550
|
-
scheduled: Number(result?.scheduled || 0),
|
|
1551
|
-
overdueScheduled: Number(result?.overdue_scheduled || 0)
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
/**
|
|
1555
|
-
* Schedule content for future publishing
|
|
1556
|
-
*
|
|
1557
|
-
* Sets status to 'scheduled' and stores the scheduled publish time.
|
|
1558
|
-
* The content will be auto-published when the scheduled time is reached.
|
|
1559
|
-
*/
|
|
1560
|
-
async schedule(type, id, scheduledAt, currentTime = /* @__PURE__ */ new Date(), expectedRevision) {
|
|
1561
|
-
const tableName = getTableName(type);
|
|
1562
|
-
const now = currentTime.toISOString();
|
|
1563
|
-
const normalizedScheduledAt = await this.datetimes.normalizeValue(type, scheduledAt);
|
|
1564
|
-
if (new Date(normalizedScheduledAt) <= currentTime) throw new EmDashValidationError("Scheduled date must be in the future");
|
|
1565
|
-
const existing = await this.findById(type, id);
|
|
1566
|
-
if (!existing) throw new EmDashValidationError("Content item not found");
|
|
1567
|
-
assertRevisionPrecondition(existing, expectedRevision);
|
|
1568
|
-
const newStatus = existing.status === "published" ? "published" : "scheduled";
|
|
1569
|
-
if (((await sql`
|
|
1570
|
-
UPDATE ${sql.ref(tableName)}
|
|
1571
|
-
SET status = ${newStatus},
|
|
1572
|
-
scheduled_at = ${normalizedScheduledAt},
|
|
1573
|
-
updated_at = ${now}
|
|
1574
|
-
WHERE id = ${id}
|
|
1575
|
-
AND deleted_at IS NULL
|
|
1576
|
-
AND version = ${existing.version}
|
|
1577
|
-
AND updated_at = ${existing.updatedAt}
|
|
1578
|
-
AND status = ${existing.status}
|
|
1579
|
-
AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
|
|
1580
|
-
`.execute(this.db)).numAffectedRows ?? 0n) === 0n) throw new ContentMutationConflictError("Content changed while scheduling");
|
|
1581
|
-
invalidateCollectionCache(type);
|
|
1582
|
-
const updated = await this.findById(type, id);
|
|
1583
|
-
if (!updated) throw new Error("Content not found");
|
|
1584
|
-
return updated;
|
|
1585
|
-
}
|
|
1586
|
-
/**
|
|
1587
|
-
* Unschedule content
|
|
1588
|
-
*
|
|
1589
|
-
* Clears the scheduled time. Published posts stay published;
|
|
1590
|
-
* draft/scheduled posts revert to 'draft'.
|
|
1591
|
-
*/
|
|
1592
|
-
async unschedule(type, id, expectedRevision) {
|
|
1593
|
-
const tableName = getTableName(type);
|
|
1594
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1595
|
-
const existing = await this.findById(type, id);
|
|
1596
|
-
if (!existing) throw new EmDashValidationError("Content item not found");
|
|
1597
|
-
assertRevisionPrecondition(existing, expectedRevision);
|
|
1598
|
-
const newStatus = existing.status === "published" ? "published" : "draft";
|
|
1599
|
-
const result = await sql`
|
|
1600
|
-
UPDATE ${sql.ref(tableName)}
|
|
1601
|
-
SET status = ${newStatus},
|
|
1602
|
-
scheduled_at = NULL,
|
|
1603
|
-
updated_at = ${now}
|
|
1604
|
-
WHERE id = ${id}
|
|
1605
|
-
AND scheduled_at IS NOT NULL
|
|
1606
|
-
AND deleted_at IS NULL
|
|
1607
|
-
AND version = ${existing.version}
|
|
1608
|
-
AND updated_at = ${existing.updatedAt}
|
|
1609
|
-
AND status = ${existing.status}
|
|
1610
|
-
AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
|
|
1611
|
-
`.execute(this.db);
|
|
1612
|
-
if (existing.scheduledAt !== null && (result.numAffectedRows ?? 0n) === 0n) throw new ContentMutationConflictError("Content changed while unscheduling");
|
|
1613
|
-
invalidateCollectionCache(type);
|
|
1614
|
-
const updated = await this.findById(type, id);
|
|
1615
|
-
if (!updated) throw new Error("Content not found");
|
|
1616
|
-
return updated;
|
|
1617
|
-
}
|
|
1618
|
-
/**
|
|
1619
|
-
* Find content that is ready to be published
|
|
1620
|
-
*
|
|
1621
|
-
* Returns all content where scheduled_at <= now, regardless of status.
|
|
1622
|
-
* This covers both draft-scheduled posts (status='scheduled') and
|
|
1623
|
-
* published posts with scheduled draft changes (status='published').
|
|
1624
|
-
*
|
|
1625
|
-
* `limit` (optional) caps how many due rows are returned, oldest-due first.
|
|
1626
|
-
* The scheduled-publishing sweep passes a limit so a large backlog can't
|
|
1627
|
-
* fan out unbounded publish/webhook work in a single tick (and blow a Worker
|
|
1628
|
-
* invocation's CPU/subrequest budget); the remainder drains on later ticks.
|
|
1629
|
-
*/
|
|
1630
|
-
async findReadyToPublish(type, limit, currentTime = /* @__PURE__ */ new Date(), after) {
|
|
1631
|
-
const tableName = getTableName(type);
|
|
1632
|
-
const now = currentTime.toISOString();
|
|
1633
|
-
const limitClause = typeof limit === "number" && Number.isInteger(limit) && limit > 0 ? sql`LIMIT ${limit}` : sql``;
|
|
1634
|
-
const afterClause = after ? sql`AND (scheduled_at > ${after.scheduledAt} OR (scheduled_at = ${after.scheduledAt} AND id > ${after.id}))` : sql``;
|
|
1635
|
-
return (await sql`
|
|
1636
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
1637
|
-
WHERE scheduled_at IS NOT NULL
|
|
1638
|
-
AND scheduled_at <= ${now}
|
|
1639
|
-
AND deleted_at IS NULL
|
|
1640
|
-
${afterClause}
|
|
1641
|
-
ORDER BY scheduled_at ASC, id ASC
|
|
1642
|
-
${limitClause}
|
|
1643
|
-
`.execute(this.db)).rows.map((row) => this.mapRow(type, row));
|
|
1644
|
-
}
|
|
1645
|
-
async findTranslationIds(type, translationGroup) {
|
|
1646
|
-
const tableName = getTableName(type);
|
|
1647
|
-
return (await sql`
|
|
1648
|
-
SELECT id FROM ${sql.ref(tableName)}
|
|
1649
|
-
WHERE translation_group = ${translationGroup}
|
|
1650
|
-
AND deleted_at IS NULL
|
|
1651
|
-
`.execute(this.db)).rows.map((row) => row.id);
|
|
1652
|
-
}
|
|
1653
|
-
async findTranslationIdsForGroups(type, translationGroups) {
|
|
1654
|
-
const ids = /* @__PURE__ */ new Map();
|
|
1655
|
-
if (translationGroups.length === 0) return ids;
|
|
1656
|
-
const tableName = getTableName(type);
|
|
1657
|
-
for (const batch of chunks([...new Set(translationGroups)], SQL_BATCH_SIZE)) {
|
|
1658
|
-
const result = await sql`
|
|
1659
|
-
SELECT id, translation_group FROM ${sql.ref(tableName)}
|
|
1660
|
-
WHERE translation_group IN (${sql.join(batch)}) AND deleted_at IS NULL
|
|
1661
|
-
`.execute(this.db);
|
|
1662
|
-
for (const row of result.rows) {
|
|
1663
|
-
const group = ids.get(row.translation_group) ?? [];
|
|
1664
|
-
group.push(row.id);
|
|
1665
|
-
ids.set(row.translation_group, group);
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
return ids;
|
|
1669
|
-
}
|
|
1670
|
-
/**
|
|
1671
|
-
* Find all translations in a translation group
|
|
1672
|
-
*/
|
|
1673
|
-
async findTranslations(type, translationGroup) {
|
|
1674
|
-
const tableName = getTableName(type);
|
|
1675
|
-
return (await sql`
|
|
1676
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
1677
|
-
WHERE translation_group = ${translationGroup}
|
|
1678
|
-
AND deleted_at IS NULL
|
|
1679
|
-
ORDER BY locale ASC
|
|
1680
|
-
`.execute(this.db)).rows.map((row) => this.mapRow(type, row));
|
|
1681
|
-
}
|
|
1682
|
-
/** Whether any row of `translationGroup` exists, trashed rows included. */
|
|
1683
|
-
async hasTranslationsIncludingTrashed(type, translationGroup) {
|
|
1684
|
-
const tableName = getTableName(type);
|
|
1685
|
-
return (await sql`
|
|
1686
|
-
SELECT id FROM ${sql.ref(tableName)}
|
|
1687
|
-
WHERE translation_group = ${translationGroup}
|
|
1688
|
-
LIMIT 1
|
|
1689
|
-
`.execute(this.db)).rows.length > 0;
|
|
1690
|
-
}
|
|
1691
|
-
/**
|
|
1692
|
-
* Batch variant of {@link findTranslations}: every (non-deleted) locale
|
|
1693
|
-
* variant for any of `translationGroups`, in one `WHERE translation_group IN
|
|
1694
|
-
* (...)` query chunked at `SQL_BATCH_SIZE` for D1's bind-parameter limit.
|
|
1695
|
-
* Lets callers resolve many edge groups without an N+1 per group. The caller
|
|
1696
|
-
* groups the flat result by `translationGroup` itself.
|
|
1697
|
-
*
|
|
1698
|
-
* `translation_group` leads the sort so the ordering follows
|
|
1699
|
-
* `idx_{table}_del_tg_locale` past its `deleted_at` equality; callers group by
|
|
1700
|
-
* `translationGroup`, so the per-group locale order they rely on is preserved.
|
|
1701
|
-
*
|
|
1702
|
-
* `publishedOnly` restricts the result to `status = 'published'` — reference
|
|
1703
|
-
* reads pass this for callers without `content:read_drafts` so draft/scheduled
|
|
1704
|
-
* entries never leak through an edge traversal.
|
|
1705
|
-
*
|
|
1706
|
-
* A reference edge stores only a collection slug (no SQL FK), so the table may
|
|
1707
|
-
* have been dropped since the edge was written. That is a tolerated dangling
|
|
1708
|
-
* state, not an error: a missing table resolves to no rows, mirroring how the
|
|
1709
|
-
* content read handlers treat `isMissingTableError`.
|
|
1710
|
-
*/
|
|
1711
|
-
async findTranslationsForGroups(type, translationGroups, options = {}) {
|
|
1712
|
-
if (translationGroups.length === 0) return [];
|
|
1713
|
-
const tableName = getTableName(type);
|
|
1714
|
-
const publishedFilter = options.publishedOnly ? sql`AND status = 'published'` : sql``;
|
|
1715
|
-
const items = [];
|
|
1716
|
-
try {
|
|
1717
|
-
for (const chunk of chunks(translationGroups, SQL_BATCH_SIZE)) {
|
|
1718
|
-
const result = await sql`
|
|
1719
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
1720
|
-
WHERE translation_group IN (${sql.join(chunk)})
|
|
1721
|
-
AND deleted_at IS NULL
|
|
1722
|
-
${publishedFilter}
|
|
1723
|
-
ORDER BY translation_group ASC, locale ASC
|
|
1724
|
-
`.execute(this.db);
|
|
1725
|
-
for (const row of result.rows) items.push(this.mapRow(type, row));
|
|
1726
|
-
}
|
|
1727
|
-
} catch (error) {
|
|
1728
|
-
if (isMissingTableError(error)) return [];
|
|
1729
|
-
throw error;
|
|
1730
|
-
}
|
|
1731
|
-
return items;
|
|
1732
|
-
}
|
|
1733
|
-
/**
|
|
1734
|
-
* Batch variant of {@link findByIdOrSlug}: resolve many identifiers (each an
|
|
1735
|
-
* id OR a slug) within `type` in a constant number of queries — one `WHERE id
|
|
1736
|
-
* IN (...)` and one `WHERE slug IN (...)`, each chunked at `SQL_BATCH_SIZE`.
|
|
1737
|
-
* Returns a map from the input identifier to its resolved item; identifiers
|
|
1738
|
-
* that match nothing are absent. Used on write paths that accept a list of
|
|
1739
|
-
* references, so a single request doesn't fan out to an N+1 of point lookups.
|
|
1740
|
-
*
|
|
1741
|
-
* Resolution mirrors {@link findByIdOrSlug}: a ULID-shaped identifier prefers
|
|
1742
|
-
* the id match and falls back to slug; anything else prefers the slug match
|
|
1743
|
-
* and falls back to id. Slug matches collapse to the lowest-locale variant
|
|
1744
|
-
* (`ORDER BY locale ASC`), matching the slug-without-locale lookup.
|
|
1745
|
-
*/
|
|
1746
|
-
async findManyByIdOrSlug(type, identifiers) {
|
|
1747
|
-
const resolved = /* @__PURE__ */ new Map();
|
|
1748
|
-
const unique = [...new Set(identifiers)];
|
|
1749
|
-
if (unique.length === 0) return resolved;
|
|
1750
|
-
const tableName = getTableName(type);
|
|
1751
|
-
const byId = /* @__PURE__ */ new Map();
|
|
1752
|
-
const bySlug = /* @__PURE__ */ new Map();
|
|
1753
|
-
try {
|
|
1754
|
-
for (const chunk of chunks(unique, SQL_BATCH_SIZE)) {
|
|
1755
|
-
const idRows = await sql`
|
|
1756
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
1757
|
-
WHERE id IN (${sql.join(chunk)})
|
|
1758
|
-
AND deleted_at IS NULL
|
|
1759
|
-
`.execute(this.db);
|
|
1760
|
-
for (const row of idRows.rows) {
|
|
1761
|
-
const item = this.mapRow(type, row);
|
|
1762
|
-
byId.set(item.id, item);
|
|
1763
|
-
}
|
|
1764
|
-
const slugRows = await sql`
|
|
1765
|
-
SELECT * FROM ${sql.ref(tableName)}
|
|
1766
|
-
WHERE slug IN (${sql.join(chunk)})
|
|
1767
|
-
AND deleted_at IS NULL
|
|
1768
|
-
ORDER BY locale ASC
|
|
1769
|
-
`.execute(this.db);
|
|
1770
|
-
for (const row of slugRows.rows) {
|
|
1771
|
-
const item = this.mapRow(type, row);
|
|
1772
|
-
if (item.slug != null && !bySlug.has(item.slug)) bySlug.set(item.slug, item);
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
} catch (error) {
|
|
1776
|
-
if (isMissingTableError(error)) return resolved;
|
|
1777
|
-
throw error;
|
|
1778
|
-
}
|
|
1779
|
-
for (const identifier of unique) {
|
|
1780
|
-
const item = ULID_PATTERN.test(identifier) ? byId.get(identifier) ?? bySlug.get(identifier) : bySlug.get(identifier) ?? byId.get(identifier);
|
|
1781
|
-
if (item) resolved.set(identifier, item);
|
|
1782
|
-
}
|
|
1783
|
-
return resolved;
|
|
1784
|
-
}
|
|
1785
|
-
/**
|
|
1786
|
-
* Publish the current draft
|
|
1787
|
-
*
|
|
1788
|
-
* Promotes draft_revision_id to live_revision_id and clears draft pointer.
|
|
1789
|
-
* Syncs the draft revision's data into the content table columns so the
|
|
1790
|
-
* content table always reflects the published version.
|
|
1791
|
-
* If no draft revision exists, creates one from current data and publishes it.
|
|
1792
|
-
* When `promoteRevision` is false, publishes the current content-table data
|
|
1793
|
-
* by changing lifecycle metadata only.
|
|
1794
|
-
*
|
|
1795
|
-
* `publishedAt` (optional) overrides the publication timestamp. If omitted,
|
|
1796
|
-
* the existing `published_at` is preserved (idempotent re-publish keeps the
|
|
1797
|
-
* original date) and falls back to the current time on first publish. Pass
|
|
1798
|
-
* an explicit value to backdate a publish (e.g. when migrating content from
|
|
1799
|
-
* another CMS).
|
|
1800
|
-
*
|
|
1801
|
-
* `requireDue` gates the final update on the row still being due.
|
|
1802
|
-
* `expectedScheduledAt` additionally fences changes made after a sweep
|
|
1803
|
-
* selected the row but before publication preparation began.
|
|
1804
|
-
*/
|
|
1805
|
-
async publish(type, id, publishedAt, requireDue = false, expectedScheduledAt, promoteRevision = true, requireSlug = true, expectedRevision, currentTime = /* @__PURE__ */ new Date()) {
|
|
1806
|
-
const tableName = getTableName(type);
|
|
1807
|
-
const now = currentTime.toISOString();
|
|
1808
|
-
const existing = await this.findById(type, id);
|
|
1809
|
-
if (!existing) throw new EmDashValidationError("Content item not found");
|
|
1810
|
-
assertRevisionPrecondition(existing, expectedRevision);
|
|
1811
|
-
const requestedPublishedAt = publishedAt ? await this.datetimes.normalizeValue(type, publishedAt) : void 0;
|
|
1812
|
-
const currentPublishedAt = existing.publishedAt ? await this.datetimes.normalizeValue(type, existing.publishedAt) : null;
|
|
1813
|
-
if (requireDue && expectedScheduledAt !== void 0 && existing.scheduledAt !== expectedScheduledAt) throw new ScheduledNotDueError();
|
|
1814
|
-
if (!promoteRevision && requireSlug && !existing.slug?.trim()) throw new EmDashValidationError("Cannot publish routable content without a slug");
|
|
1815
|
-
if (!promoteRevision) {
|
|
1816
|
-
const revisionRepo = new RevisionRepository(this.db, this.datetimeContexts);
|
|
1817
|
-
let provisionalRevisionId = null;
|
|
1818
|
-
try {
|
|
1819
|
-
let liveRevisionId = existing.liveRevisionId;
|
|
1820
|
-
if (!liveRevisionId) {
|
|
1821
|
-
const revision = await revisionRepo.create({
|
|
1822
|
-
collection: type,
|
|
1823
|
-
entryId: id,
|
|
1824
|
-
data: existing.data
|
|
1825
|
-
});
|
|
1826
|
-
liveRevisionId = revision.id;
|
|
1827
|
-
provisionalRevisionId = revision.id;
|
|
1828
|
-
}
|
|
1829
|
-
const intendedPublishedAt = requestedPublishedAt ?? currentPublishedAt ?? now;
|
|
1830
|
-
const duePredicate = requireDue ? sql`AND scheduled_at IS NOT NULL AND scheduled_at <= ${now}` : sql``;
|
|
1831
|
-
let published = false;
|
|
1832
|
-
try {
|
|
1833
|
-
published = ((await sql`
|
|
1834
|
-
UPDATE ${sql.ref(tableName)}
|
|
1835
|
-
SET live_revision_id = ${liveRevisionId},
|
|
1836
|
-
draft_revision_id = NULL,
|
|
1837
|
-
status = 'published',
|
|
1838
|
-
scheduled_at = NULL,
|
|
1839
|
-
published_at = ${intendedPublishedAt},
|
|
1840
|
-
updated_at = ${now},
|
|
1841
|
-
version = version + 1
|
|
1842
|
-
WHERE id = ${id}
|
|
1843
|
-
AND deleted_at IS NULL
|
|
1844
|
-
AND version = ${existing.version}
|
|
1845
|
-
AND updated_at = ${existing.updatedAt}
|
|
1846
|
-
AND status = ${existing.status}
|
|
1847
|
-
AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
|
|
1848
|
-
AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
|
|
1849
|
-
AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
|
|
1850
|
-
${duePredicate}
|
|
1851
|
-
`.execute(this.db)).numAffectedRows ?? 0n) > 0n;
|
|
1852
|
-
} catch (error) {
|
|
1853
|
-
if (isConfirmedStatementFailure(error)) throw error;
|
|
1854
|
-
let observed;
|
|
1855
|
-
try {
|
|
1856
|
-
observed = await this.findById(type, id);
|
|
1857
|
-
} catch (reconciliationError) {
|
|
1858
|
-
throw new Error("Unable to confirm whether content publication completed", { cause: reconciliationError });
|
|
1859
|
-
}
|
|
1860
|
-
if (!observed) throw new Error("Unable to confirm whether content publication completed", { cause: error });
|
|
1861
|
-
published = matchesLifecyclePublication(observed, existing, liveRevisionId, intendedPublishedAt, now);
|
|
1862
|
-
if (!published && matchesPublicationFence(observed, existing)) throw error;
|
|
1863
|
-
if (!published) throw new Error("Unable to confirm whether content publication completed", { cause: error });
|
|
1864
|
-
}
|
|
1865
|
-
if (!published) throw requireDue ? new ScheduledNotDueError() : new ContentMutationConflictError();
|
|
1866
|
-
invalidateCollectionCache(type);
|
|
1867
|
-
const updated = await this.findById(type, id);
|
|
1868
|
-
if (!updated) throw new Error("Content not found");
|
|
1869
|
-
return updated;
|
|
1870
|
-
} catch (error) {
|
|
1871
|
-
if (provisionalRevisionId) try {
|
|
1872
|
-
await revisionRepo.deleteIfUnreferenced(type, id, provisionalRevisionId);
|
|
1873
|
-
} catch (cleanupError) {
|
|
1874
|
-
console.error(`[content] Failed to clean up provisional revision ${provisionalRevisionId}:`, cleanupError);
|
|
1875
|
-
}
|
|
1876
|
-
throw error;
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
const revisionRepo = new RevisionRepository(this.db, this.datetimeContexts);
|
|
1880
|
-
let provisionalRevisionId = null;
|
|
1881
|
-
try {
|
|
1882
|
-
let revisionToPublish = existing.draftRevisionId || existing.liveRevisionId;
|
|
1883
|
-
if (!revisionToPublish) {
|
|
1884
|
-
const revision = await revisionRepo.create({
|
|
1885
|
-
collection: type,
|
|
1886
|
-
entryId: id,
|
|
1887
|
-
data: existing.data
|
|
1888
|
-
});
|
|
1889
|
-
revisionToPublish = revision.id;
|
|
1890
|
-
provisionalRevisionId = revision.id;
|
|
1891
|
-
}
|
|
1892
|
-
const revision = await revisionRepo.findById(revisionToPublish);
|
|
1893
|
-
if (!revision || revision.collection !== type || revision.entryId !== id) throw new EmDashValidationError("Revision does not belong to the specified content item");
|
|
1894
|
-
const stagedSlug = typeof revision.data._slug === "string" ? revision.data._slug : null;
|
|
1895
|
-
const intendedSlug = stagedSlug ?? existing.slug;
|
|
1896
|
-
if (requireSlug && !intendedSlug?.trim()) throw new EmDashValidationError("Cannot publish routable content without a slug");
|
|
1897
|
-
const intendedPublishedAt = requestedPublishedAt ?? currentPublishedAt ?? now;
|
|
1898
|
-
if (stagedSlug !== null && stagedSlug !== existing.slug && existing.locale !== null) {
|
|
1899
|
-
const conflict = await this.findBySlugIncludingTrashed(type, stagedSlug, existing.locale);
|
|
1900
|
-
if (conflict && conflict.id !== id) throw new EmDashValidationError(`Cannot publish: slug '${stagedSlug}' is already used by another entry in this collection (id: ${conflict.id}). Choose a different slug.`, { code: "SLUG_CONFLICT" });
|
|
1901
|
-
}
|
|
1902
|
-
const assignments = [];
|
|
1903
|
-
if (stagedSlug !== null) assignments.push(sql`slug = ${stagedSlug}`);
|
|
1904
|
-
for (const [key, value] of Object.entries(revision.data)) {
|
|
1905
|
-
if (SYSTEM_COLUMNS.has(key) || key.startsWith("_")) continue;
|
|
1906
|
-
validateIdentifier(key, "content field name");
|
|
1907
|
-
assignments.push(sql`${sql.ref(key)} = ${serializeValue(value)}`);
|
|
1908
|
-
}
|
|
1909
|
-
assignments.push(sql`live_revision_id = ${revisionToPublish}`, sql`draft_revision_id = NULL`, sql`status = 'published'`, sql`scheduled_at = NULL`, sql`published_at = ${intendedPublishedAt}`, sql`updated_at = ${now}`, sql`version = version + 1`);
|
|
1910
|
-
const duePredicate = requireDue ? sql`AND scheduled_at IS NOT NULL AND scheduled_at <= ${now}` : sql``;
|
|
1911
|
-
let promoted = false;
|
|
1912
|
-
try {
|
|
1913
|
-
promoted = ((await sql`
|
|
1914
|
-
UPDATE ${sql.ref(tableName)}
|
|
1915
|
-
SET ${sql.join(assignments, sql`, `)}
|
|
1916
|
-
WHERE id = ${id}
|
|
1917
|
-
AND deleted_at IS NULL
|
|
1918
|
-
AND version = ${existing.version}
|
|
1919
|
-
AND updated_at = ${existing.updatedAt}
|
|
1920
|
-
AND status = ${existing.status}
|
|
1921
|
-
AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
|
|
1922
|
-
AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
|
|
1923
|
-
AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
|
|
1924
|
-
${duePredicate}
|
|
1925
|
-
AND EXISTS (
|
|
1926
|
-
SELECT 1 FROM revisions
|
|
1927
|
-
WHERE revisions.id = ${revisionToPublish}
|
|
1928
|
-
AND revisions.collection = ${type}
|
|
1929
|
-
AND revisions.entry_id = ${id}
|
|
1930
|
-
)
|
|
1931
|
-
`.execute(this.db)).numAffectedRows ?? 0n) > 0n;
|
|
1932
|
-
} catch (error) {
|
|
1933
|
-
if (isConfirmedStatementFailure(error)) throw error;
|
|
1934
|
-
let observed;
|
|
1935
|
-
try {
|
|
1936
|
-
observed = await this.findById(type, id);
|
|
1937
|
-
} catch (reconciliationError) {
|
|
1938
|
-
throw new Error("Unable to confirm whether content publication completed", { cause: reconciliationError });
|
|
1939
|
-
}
|
|
1940
|
-
if (!observed) throw new Error("Unable to confirm whether content publication completed", { cause: error });
|
|
1941
|
-
promoted = matchesPublication(observed, existing, revision, revisionToPublish, intendedSlug, intendedPublishedAt, now);
|
|
1942
|
-
if (!promoted && matchesPublicationFence(observed, existing)) throw error;
|
|
1943
|
-
if (!promoted) throw new Error("Unable to confirm whether content publication completed", { cause: error });
|
|
1944
|
-
}
|
|
1945
|
-
if (!promoted) throw requireDue ? new ScheduledNotDueError() : new ContentMutationConflictError();
|
|
1946
|
-
invalidateCollectionCache(type);
|
|
1947
|
-
const updated = await this.findById(type, id);
|
|
1948
|
-
if (!updated) throw new Error("Content not found");
|
|
1949
|
-
return updated;
|
|
1950
|
-
} catch (error) {
|
|
1951
|
-
if (provisionalRevisionId) try {
|
|
1952
|
-
await revisionRepo.deleteIfUnreferenced(type, id, provisionalRevisionId);
|
|
1953
|
-
} catch (cleanupError) {
|
|
1954
|
-
console.error(`[content] Failed to clean up provisional revision ${provisionalRevisionId}:`, cleanupError);
|
|
1955
|
-
}
|
|
1956
|
-
throw error;
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
/**
|
|
1960
|
-
* Unpublish content
|
|
1961
|
-
*
|
|
1962
|
-
* Removes live pointer and cancels any pending schedule, but preserves the
|
|
1963
|
-
* draft and publication date. If no draft exists, creates one from the live
|
|
1964
|
-
* version so the content isn't lost.
|
|
1965
|
-
*/
|
|
1966
|
-
async unpublish(type, id, expectedRevision) {
|
|
1967
|
-
const tableName = getTableName(type);
|
|
1968
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1969
|
-
const existing = await this.findById(type, id);
|
|
1970
|
-
if (!existing) throw new EmDashValidationError("Content item not found");
|
|
1971
|
-
assertRevisionPrecondition(existing, expectedRevision);
|
|
1972
|
-
if (existing.status === "draft" && !existing.liveRevisionId && !existing.scheduledAt) return existing;
|
|
1973
|
-
const revisionRepo = new RevisionRepository(this.db, this.datetimeContexts);
|
|
1974
|
-
let provisionalRevisionId = null;
|
|
1975
|
-
try {
|
|
1976
|
-
let draftRevisionId = existing.draftRevisionId;
|
|
1977
|
-
if (!draftRevisionId && existing.liveRevisionId) {
|
|
1978
|
-
const liveRevision = await revisionRepo.findById(existing.liveRevisionId);
|
|
1979
|
-
if (liveRevision) {
|
|
1980
|
-
const draft = await revisionRepo.create({
|
|
1981
|
-
collection: type,
|
|
1982
|
-
entryId: id,
|
|
1983
|
-
data: liveRevision.data
|
|
1984
|
-
});
|
|
1985
|
-
draftRevisionId = draft.id;
|
|
1986
|
-
provisionalRevisionId = draft.id;
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
|
-
if (((await sql`
|
|
1990
|
-
UPDATE ${sql.ref(tableName)}
|
|
1991
|
-
SET live_revision_id = NULL,
|
|
1992
|
-
draft_revision_id = ${draftRevisionId},
|
|
1993
|
-
status = 'draft',
|
|
1994
|
-
scheduled_at = NULL,
|
|
1995
|
-
updated_at = ${now},
|
|
1996
|
-
version = version + 1
|
|
1997
|
-
WHERE id = ${id}
|
|
1998
|
-
AND deleted_at IS NULL
|
|
1999
|
-
AND version = ${existing.version}
|
|
2000
|
-
AND updated_at = ${existing.updatedAt}
|
|
2001
|
-
AND status = ${existing.status}
|
|
2002
|
-
AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
|
|
2003
|
-
AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
|
|
2004
|
-
AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
|
|
2005
|
-
`.execute(this.db)).numAffectedRows ?? 0n) === 0n) throw new ContentMutationConflictError();
|
|
2006
|
-
invalidateCollectionCache(type);
|
|
2007
|
-
const updated = await this.findById(type, id);
|
|
2008
|
-
if (!updated) throw new Error("Content not found");
|
|
2009
|
-
return updated;
|
|
2010
|
-
} catch (error) {
|
|
2011
|
-
if (provisionalRevisionId) try {
|
|
2012
|
-
await revisionRepo.deleteIfUnreferenced(type, id, provisionalRevisionId);
|
|
2013
|
-
} catch (cleanupError) {
|
|
2014
|
-
console.error(`[content] Failed to clean up provisional revision ${provisionalRevisionId}:`, cleanupError);
|
|
2015
|
-
}
|
|
2016
|
-
throw error;
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
|
-
/**
|
|
2020
|
-
* Set the draft revision pointer for a content item.
|
|
2021
|
-
*
|
|
2022
|
-
* Used by seed/import paths that stage a new revision's data before
|
|
2023
|
-
* promoting it to live via `publish()`.
|
|
2024
|
-
*
|
|
2025
|
-
* Validates that the content item exists and is not soft-deleted, that
|
|
2026
|
-
* the revision exists, and that the revision belongs to the same
|
|
2027
|
-
* collection and entry. Without these checks, a caller could leave the
|
|
2028
|
-
* content row pointing at a missing or unrelated revision.
|
|
2029
|
-
*/
|
|
2030
|
-
async setDraftRevision(type, id, revisionId) {
|
|
2031
|
-
const existing = await this.findById(type, id);
|
|
2032
|
-
if (!existing) throw new EmDashValidationError("Content item not found");
|
|
2033
|
-
const revision = await new RevisionRepository(this.db, this.datetimeContexts).findById(revisionId);
|
|
2034
|
-
if (!revision) throw new EmDashValidationError("Revision not found");
|
|
2035
|
-
if (revision.collection !== type || revision.entryId !== id) throw new EmDashValidationError("Revision does not belong to the specified content item");
|
|
2036
|
-
if (!await this.replaceDraftRevision(type, id, revisionId, existing)) throw new ContentMutationConflictError();
|
|
2037
|
-
}
|
|
2038
|
-
async replaceDraftRevision(type, id, revisionId, expected) {
|
|
2039
|
-
const tableName = getTableName(type);
|
|
2040
|
-
return ((await sql`
|
|
2041
|
-
UPDATE ${sql.ref(tableName)}
|
|
2042
|
-
SET draft_revision_id = ${revisionId},
|
|
2043
|
-
version = version + 1
|
|
2044
|
-
WHERE id = ${id}
|
|
2045
|
-
AND deleted_at IS NULL
|
|
2046
|
-
AND version = ${expected.version}
|
|
2047
|
-
AND ${nullableColumnMatch("live_revision_id", expected.liveRevisionId)}
|
|
2048
|
-
AND ${nullableColumnMatch("draft_revision_id", expected.draftRevisionId)}
|
|
2049
|
-
AND EXISTS (
|
|
2050
|
-
SELECT 1 FROM revisions
|
|
2051
|
-
WHERE revisions.id = ${revisionId}
|
|
2052
|
-
AND revisions.collection = ${type}
|
|
2053
|
-
AND revisions.entry_id = ${id}
|
|
2054
|
-
)
|
|
2055
|
-
`.execute(this.db)).numAffectedRows ?? 0n) > 0n;
|
|
2056
|
-
}
|
|
2057
|
-
/**
|
|
2058
|
-
* Discard pending draft changes
|
|
2059
|
-
*
|
|
2060
|
-
* Clears draft_revision_id. The content table columns already hold the
|
|
2061
|
-
* published version, so no data sync is needed.
|
|
2062
|
-
*/
|
|
2063
|
-
async discardDraft(type, id, expectedRevision) {
|
|
2064
|
-
const tableName = getTableName(type);
|
|
2065
|
-
const existing = await this.findById(type, id);
|
|
2066
|
-
if (!existing) throw new EmDashValidationError("Content item not found");
|
|
2067
|
-
assertRevisionPrecondition(existing, expectedRevision);
|
|
2068
|
-
if (!existing.draftRevisionId) return existing;
|
|
2069
|
-
if (((await sql`
|
|
2070
|
-
UPDATE ${sql.ref(tableName)}
|
|
2071
|
-
SET draft_revision_id = NULL,
|
|
2072
|
-
version = version + 1
|
|
2073
|
-
WHERE id = ${id}
|
|
2074
|
-
AND deleted_at IS NULL
|
|
2075
|
-
AND version = ${existing.version}
|
|
2076
|
-
AND updated_at = ${existing.updatedAt}
|
|
2077
|
-
AND status = ${existing.status}
|
|
2078
|
-
AND ${nullableColumnMatch("live_revision_id", existing.liveRevisionId)}
|
|
2079
|
-
AND ${nullableColumnMatch("draft_revision_id", existing.draftRevisionId)}
|
|
2080
|
-
AND ${nullableColumnMatch("scheduled_at", existing.scheduledAt)}
|
|
2081
|
-
`.execute(this.db)).numAffectedRows ?? 0n) === 0n) throw new ContentMutationConflictError();
|
|
2082
|
-
const updated = await this.findById(type, id);
|
|
2083
|
-
if (!updated) throw new Error("Content not found");
|
|
2084
|
-
return updated;
|
|
2085
|
-
}
|
|
2086
|
-
/**
|
|
2087
|
-
* Count content items with a pending schedule.
|
|
2088
|
-
* Includes both draft-scheduled (status='scheduled') and published
|
|
2089
|
-
* posts with scheduled draft changes (status='published', scheduled_at set).
|
|
2090
|
-
*/
|
|
2091
|
-
async countScheduled(type) {
|
|
2092
|
-
const tableName = getTableName(type);
|
|
2093
|
-
const result = await sql`
|
|
2094
|
-
SELECT COUNT(id) as count FROM ${sql.ref(tableName)}
|
|
2095
|
-
WHERE scheduled_at IS NOT NULL
|
|
2096
|
-
AND deleted_at IS NULL
|
|
2097
|
-
`.execute(this.db);
|
|
2098
|
-
return Number(result.rows[0]?.count || 0);
|
|
2099
|
-
}
|
|
2100
|
-
/**
|
|
2101
|
-
* Map database row to ContentItem
|
|
2102
|
-
* Extracts system columns and puts content fields in data
|
|
2103
|
-
* Excludes null values from data to match input semantics
|
|
2104
|
-
*/
|
|
2105
|
-
mapRow(type, row) {
|
|
2106
|
-
const data = {};
|
|
2107
|
-
for (const [key, value] of Object.entries(row)) if (!SYSTEM_COLUMNS.has(key) && value !== null) data[key] = deserializeValue(value);
|
|
2108
|
-
return {
|
|
2109
|
-
id: row.id,
|
|
2110
|
-
type,
|
|
2111
|
-
slug: row.slug,
|
|
2112
|
-
status: row.status,
|
|
2113
|
-
data,
|
|
2114
|
-
authorId: row.author_id,
|
|
2115
|
-
primaryBylineId: row.primary_byline_id ?? null,
|
|
2116
|
-
createdAt: row.created_at,
|
|
2117
|
-
updatedAt: row.updated_at,
|
|
2118
|
-
publishedAt: row.published_at,
|
|
2119
|
-
scheduledAt: row.scheduled_at,
|
|
2120
|
-
liveRevisionId: row.live_revision_id ?? null,
|
|
2121
|
-
draftRevisionId: row.draft_revision_id ?? null,
|
|
2122
|
-
version: typeof row.version === "number" ? row.version : 1,
|
|
2123
|
-
locale: row.locale ?? null,
|
|
2124
|
-
translationGroup: row.translation_group ?? null
|
|
2125
|
-
};
|
|
2126
|
-
}
|
|
2127
|
-
normalizeFilterScalar(field, type, value) {
|
|
2128
|
-
if (type === "number" || type === "integer") {
|
|
2129
|
-
if (typeof value !== "number" || !Number.isFinite(value)) throw new EmDashValidationError(`Filter for field "${field}" must use a finite number`);
|
|
2130
|
-
if (type === "integer" && !Number.isInteger(value)) throw new EmDashValidationError(`Filter for field "${field}" must use an integer`);
|
|
2131
|
-
return value;
|
|
2132
|
-
}
|
|
2133
|
-
if (type === "boolean") {
|
|
2134
|
-
if (typeof value !== "boolean") throw new EmDashValidationError(`Filter for field "${field}" must use a boolean`);
|
|
2135
|
-
return value ? 1 : 0;
|
|
2136
|
-
}
|
|
2137
|
-
if (typeof value !== "string") throw new EmDashValidationError(`Filter for field "${field}" must use a string`);
|
|
2138
|
-
if (value.length > MAX_FILTER_STRING_LENGTH) throw new EmDashValidationError(`Filter value for field "${field}" exceeds ${MAX_FILTER_STRING_LENGTH} characters`);
|
|
2139
|
-
if (type === "datetime") try {
|
|
2140
|
-
return normalizeExplicitDatetime(value);
|
|
2141
|
-
} catch {
|
|
2142
|
-
throw new EmDashValidationError(`Filter for datetime field "${field}" must use an ISO 8601 datetime with Z or an explicit offset`);
|
|
2143
|
-
}
|
|
2144
|
-
return value;
|
|
2145
|
-
}
|
|
2146
|
-
normalizeFieldFilter(field, type, value) {
|
|
2147
|
-
if (value === null) return {
|
|
2148
|
-
column: field,
|
|
2149
|
-
kind: "null"
|
|
2150
|
-
};
|
|
2151
|
-
if (typeof value !== "object") return {
|
|
2152
|
-
column: field,
|
|
2153
|
-
kind: "exact",
|
|
2154
|
-
value: this.normalizeFilterScalar(field, type, value)
|
|
2155
|
-
};
|
|
2156
|
-
if (Array.isArray(value)) throw new EmDashValidationError(`Invalid filter for field "${field}"`);
|
|
2157
|
-
const record = value;
|
|
2158
|
-
const keys = Object.keys(record);
|
|
2159
|
-
if (keys.length === 1 && keys[0] === "in") {
|
|
2160
|
-
if (!Array.isArray(record.in) || record.in.length === 0) throw new EmDashValidationError(`IN filter for field "${field}" must not be empty`);
|
|
2161
|
-
if (record.in.length > MAX_IN_FILTER_VALUES) throw new EmDashValidationError(`IN filter for field "${field}" exceeds ${MAX_IN_FILTER_VALUES} values`);
|
|
2162
|
-
return {
|
|
2163
|
-
column: field,
|
|
2164
|
-
kind: "in",
|
|
2165
|
-
values: record.in.map((entry) => this.normalizeFilterScalar(field, type, entry))
|
|
2166
|
-
};
|
|
2167
|
-
}
|
|
2168
|
-
const rangeKeys = new Set([
|
|
2169
|
-
"gt",
|
|
2170
|
-
"gte",
|
|
2171
|
-
"lt",
|
|
2172
|
-
"lte"
|
|
2173
|
-
]);
|
|
2174
|
-
if (keys.length === 0 || keys.some((key) => !rangeKeys.has(key))) throw new EmDashValidationError(`Invalid filter operator for field "${field}"`);
|
|
2175
|
-
if (type === "boolean") throw new EmDashValidationError(`Boolean field "${field}" does not support range filters`);
|
|
2176
|
-
const bounds = {};
|
|
2177
|
-
for (const key of keys) {
|
|
2178
|
-
if (record[key] === void 0) continue;
|
|
2179
|
-
bounds[key] = this.normalizeFilterScalar(field, type, record[key]);
|
|
2180
|
-
}
|
|
2181
|
-
if (Object.keys(bounds).length === 0) throw new EmDashValidationError(`Range filter for field "${field}" has no bounds`);
|
|
2182
|
-
return {
|
|
2183
|
-
column: field,
|
|
2184
|
-
kind: "range",
|
|
2185
|
-
bounds
|
|
2186
|
-
};
|
|
2187
|
-
}
|
|
2188
|
-
async collectionExists(type) {
|
|
2189
|
-
return await this.db.selectFrom("_emdash_collections").where("slug", "=", type).select("id").executeTakeFirst() !== void 0;
|
|
2190
|
-
}
|
|
2191
|
-
async resolveFieldFilters(type, filters) {
|
|
2192
|
-
const resolvedFilters = filters ?? {};
|
|
2193
|
-
const fields = Object.keys(resolvedFilters);
|
|
2194
|
-
if (fields.length === 0) return [];
|
|
2195
|
-
if (fields.length > MAX_INDEXED_FIELD_FILTERS) {
|
|
2196
|
-
if (!await this.collectionExists(type)) return [];
|
|
2197
|
-
throw new EmDashValidationError(`Content list queries support at most ${MAX_INDEXED_FIELD_FILTERS} indexed field filters`);
|
|
2198
|
-
}
|
|
2199
|
-
const rows = await this.db.selectFrom("_emdash_fields as field").innerJoin("_emdash_collections as collection", "collection.id", "field.collection_id").where("collection.slug", "=", type).where("field.slug", "in", fields).where("field.indexed", "=", 1).select(["field.slug", "field.type"]).execute();
|
|
2200
|
-
const metadata = new Map(rows.map((row) => [row.slug, row.type]));
|
|
2201
|
-
if (metadata.size === 0 && !await this.collectionExists(type)) return [];
|
|
2202
|
-
for (const field of fields) try {
|
|
2203
|
-
validateIdentifier(field, "content filter field");
|
|
2204
|
-
} catch {
|
|
2205
|
-
throw new EmDashValidationError(`Invalid content filter field: ${field}`);
|
|
2206
|
-
}
|
|
2207
|
-
const normalized = fields.map((field) => {
|
|
2208
|
-
const fieldType = metadata.get(field);
|
|
2209
|
-
if (!fieldType || !isIndexableFieldType(fieldType)) throw new EmDashValidationError(`Cannot filter by field "${field}". Custom fields must be indexed before filtering.`);
|
|
2210
|
-
return this.normalizeFieldFilter(field, fieldType, resolvedFilters[field]);
|
|
2211
|
-
});
|
|
2212
|
-
if (normalized.reduce((total, filter) => {
|
|
2213
|
-
if (filter.kind === "null") return total;
|
|
2214
|
-
if (filter.kind === "exact") return total + 1;
|
|
2215
|
-
if (filter.kind === "in") return total + filter.values.length;
|
|
2216
|
-
return total + Object.keys(filter.bounds).length;
|
|
2217
|
-
}, 0) > SQL_BATCH_SIZE) throw new EmDashValidationError(`Indexed field filters have a total operand budget of ${SQL_BATCH_SIZE}`);
|
|
2218
|
-
return normalized;
|
|
2219
|
-
}
|
|
2220
|
-
applyFieldFilters(query, filters) {
|
|
2221
|
-
let next = query;
|
|
2222
|
-
for (const filter of filters) {
|
|
2223
|
-
const column = sql.ref(filter.column);
|
|
2224
|
-
const isPresent = sql`${column} IS NOT NULL`;
|
|
2225
|
-
if (filter.kind === "null") {
|
|
2226
|
-
next = next.where(() => sql`(${isPresent}) = FALSE AND ${column} IS NULL`);
|
|
2227
|
-
continue;
|
|
2228
|
-
}
|
|
2229
|
-
if (filter.kind === "exact") {
|
|
2230
|
-
next = next.where(() => sql`(${isPresent}) = TRUE AND ${column} = ${filter.value}`);
|
|
2231
|
-
continue;
|
|
2232
|
-
}
|
|
2233
|
-
if (filter.kind === "in") {
|
|
2234
|
-
const values = sql.join(filter.values.map((value) => sql`${value}`), sql`, `);
|
|
2235
|
-
next = next.where(() => sql`(${isPresent}) = TRUE AND ${column} IN (${values})`);
|
|
2236
|
-
continue;
|
|
2237
|
-
}
|
|
2238
|
-
next = next.where(() => sql`(${isPresent}) = TRUE`);
|
|
2239
|
-
if (filter.bounds.gt !== void 0) next = next.where(() => sql`${column} > ${filter.bounds.gt}`);
|
|
2240
|
-
if (filter.bounds.gte !== void 0) next = next.where(() => sql`${column} >= ${filter.bounds.gte}`);
|
|
2241
|
-
if (filter.bounds.lt !== void 0) next = next.where(() => sql`${column} < ${filter.bounds.lt}`);
|
|
2242
|
-
if (filter.bounds.lte !== void 0) next = next.where(() => sql`${column} <= ${filter.bounds.lte}`);
|
|
2243
|
-
}
|
|
2244
|
-
return next;
|
|
2245
|
-
}
|
|
2246
|
-
/**
|
|
2247
|
-
* Map order field names to database columns.
|
|
2248
|
-
* Only allows known fields to prevent column enumeration via crafted orderBy values.
|
|
2249
|
-
*/
|
|
2250
|
-
mapOrderField(field, sortableExtras = []) {
|
|
2251
|
-
const mapped = ORDER_FIELD_COLUMNS[field];
|
|
2252
|
-
if (mapped) return mapped;
|
|
2253
|
-
if (sortableExtras.includes(field)) {
|
|
2254
|
-
validateIdentifier(field, "order field");
|
|
2255
|
-
return field;
|
|
2256
|
-
}
|
|
2257
|
-
throw new EmDashValidationError(`Invalid order field: ${field}`);
|
|
2258
|
-
}
|
|
2259
|
-
async resolveOrderField(type, field, sortableExtras = []) {
|
|
2260
|
-
try {
|
|
2261
|
-
return {
|
|
2262
|
-
column: this.mapOrderField(field, sortableExtras),
|
|
2263
|
-
indexedCustomField: false
|
|
2264
|
-
};
|
|
2265
|
-
} catch (error) {
|
|
2266
|
-
if (!(error instanceof EmDashValidationError)) throw error;
|
|
2267
|
-
}
|
|
2268
|
-
const customField = await this.db.selectFrom("_emdash_collections as collection").leftJoin("_emdash_fields as field", (join) => join.onRef("field.collection_id", "=", "collection.id").on("field.slug", "=", field).on("field.indexed", "=", 1)).where("collection.slug", "=", type).select(["collection.id as collectionId", "field.slug as fieldSlug"]).executeTakeFirst();
|
|
2269
|
-
if (!customField) throw new ContentCollectionNotFoundError(type);
|
|
2270
|
-
if (!customField.fieldSlug) throw new EmDashValidationError(`Invalid order field: ${field}. Custom fields must be indexed before sorting.`);
|
|
2271
|
-
validateIdentifier(customField.fieldSlug, "content order field");
|
|
2272
|
-
return {
|
|
2273
|
-
column: customField.fieldSlug,
|
|
2274
|
-
indexedCustomField: true
|
|
2275
|
-
};
|
|
2276
|
-
}
|
|
2277
|
-
};
|
|
2278
|
-
|
|
2279
|
-
//#endregion
|
|
2280
|
-
export { normalizeRevisionLimit as a, RevisionRepository as i, content_exports as n, keepKnownFields as o, isSystemOrderField as r, staleStoredKeys as s, ContentRepository as t };
|
|
2281
|
-
//# sourceMappingURL=content-DFaIEDj9.mjs.map
|