emdash 1.5.0 → 1.6.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-DyXQ5VhB.mjs +26 -0
- package/dist/action-token-DyXQ5VhB.mjs.map +1 -0
- package/dist/activation-BRmrunZ3.mjs +387 -0
- package/dist/activation-BRmrunZ3.mjs.map +1 -0
- package/dist/adapters-CMuwJgdX.d.mts +173 -0
- package/dist/adapters-CMuwJgdX.d.mts.map +1 -0
- package/dist/after-B8cG5P6f.mjs +53 -0
- package/dist/after-B8cG5P6f.mjs.map +1 -0
- package/dist/allowed-origins-CUNAP6hl.mjs +116 -0
- package/dist/allowed-origins-CUNAP6hl.mjs.map +1 -0
- package/dist/api/route-utils.d.mts +4 -4
- package/dist/api/route-utils.mjs +6 -5
- package/dist/api/route-utils.mjs.map +1 -1
- package/dist/api/schemas/index.d.mts +2 -2
- package/dist/api/schemas/index.mjs +7 -7
- package/dist/api-tokens-BIwfh_Ke.mjs +173 -0
- package/dist/api-tokens-BIwfh_Ke.mjs.map +1 -0
- package/dist/apply-CmE9k57Q.mjs +1774 -0
- package/dist/apply-CmE9k57Q.mjs.map +1 -0
- package/dist/approvals-DbCK12-7.mjs +460 -0
- package/dist/approvals-DbCK12-7.mjs.map +1 -0
- package/dist/artifact-fetch-DXHP2vKC.mjs +659 -0
- package/dist/artifact-fetch-DXHP2vKC.mjs.map +1 -0
- package/dist/artifacts-a_0bb4Ks.mjs +323 -0
- package/dist/artifacts-a_0bb4Ks.mjs.map +1 -0
- package/dist/astro/image-endpoint.d.mts.map +1 -1
- package/dist/astro/image-endpoint.mjs +12 -4
- package/dist/astro/image-endpoint.mjs.map +1 -1
- package/dist/astro/index.d.mts +17 -17
- package/dist/astro/index.d.mts.map +1 -1
- package/dist/astro/index.mjs +28 -12
- package/dist/astro/index.mjs.map +1 -1
- package/dist/astro/middleware/auth.d.mts +17 -15
- package/dist/astro/middleware/auth.d.mts.map +1 -1
- package/dist/astro/middleware/auth.mjs +31 -20
- package/dist/astro/middleware/auth.mjs.map +1 -1
- package/dist/astro/middleware/media-usage-write-fence.mjs +2 -2
- package/dist/astro/middleware/redirect.d.mts +2 -1
- package/dist/astro/middleware/redirect.d.mts.map +1 -1
- package/dist/astro/middleware/redirect.mjs +29 -19
- package/dist/astro/middleware/redirect.mjs.map +1 -1
- package/dist/astro/middleware/request-context.d.mts.map +1 -1
- package/dist/astro/middleware/request-context.mjs +6 -5
- package/dist/astro/middleware/request-context.mjs.map +1 -1
- package/dist/astro/middleware.d.mts +19 -21
- package/dist/astro/middleware.d.mts.map +1 -1
- package/dist/astro/middleware.mjs +179 -129
- package/dist/astro/middleware.mjs.map +1 -1
- package/dist/astro/routes/PluginRegistry.d.mts +2 -3
- package/dist/astro/routes/PluginRegistry.d.mts.map +1 -1
- package/dist/astro/routes/PluginRegistry.mjs +1 -1
- package/dist/astro/routes/PluginRegistry.mjs.map +1 -1
- package/dist/astro/routes/api/admin/allowed-domains/_domain_.mjs +3 -3
- package/dist/astro/routes/api/admin/allowed-domains/index.mjs +3 -3
- package/dist/astro/routes/api/admin/api-tokens/_id_.mjs +2 -2
- package/dist/astro/routes/api/admin/api-tokens/index.mjs +3 -3
- package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs +4 -5
- package/dist/astro/routes/api/admin/byline-fields/_slug_/usage.mjs.map +1 -1
- package/dist/astro/routes/api/admin/byline-fields/_slug_.d.mts.map +1 -1
- package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs +8 -11
- package/dist/astro/routes/api/admin/byline-fields/_slug_.mjs.map +1 -1
- package/dist/astro/routes/api/admin/byline-fields/index.d.mts.map +1 -1
- package/dist/astro/routes/api/admin/byline-fields/index.mjs +7 -9
- package/dist/astro/routes/api/admin/byline-fields/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/byline-fields/reorder.mjs +6 -7
- package/dist/astro/routes/api/admin/byline-fields/reorder.mjs.map +1 -1
- package/dist/astro/routes/api/admin/bylines/_id_/index.d.mts.map +1 -1
- package/dist/astro/routes/api/admin/bylines/_id_/index.mjs +9 -10
- package/dist/astro/routes/api/admin/bylines/_id_/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/bylines/_id_/translations.d.mts.map +1 -1
- package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs +10 -12
- package/dist/astro/routes/api/admin/bylines/_id_/translations.mjs.map +1 -1
- package/dist/astro/routes/api/admin/bylines/index.mjs +8 -8
- package/dist/astro/routes/api/admin/comments/_id_/status.mjs +8 -8
- package/dist/astro/routes/api/admin/comments/_id_/status.mjs.map +1 -1
- package/dist/astro/routes/api/admin/comments/_id_.d.mts.map +1 -1
- package/dist/astro/routes/api/admin/comments/_id_.mjs +7 -8
- package/dist/astro/routes/api/admin/comments/_id_.mjs.map +1 -1
- package/dist/astro/routes/api/admin/comments/bulk.mjs +9 -9
- package/dist/astro/routes/api/admin/comments/bulk.mjs.map +1 -1
- package/dist/astro/routes/api/admin/comments/counts.mjs +5 -5
- package/dist/astro/routes/api/admin/comments/counts.mjs.map +1 -1
- package/dist/astro/routes/api/admin/comments/index.mjs +7 -7
- package/dist/astro/routes/api/admin/comments/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/core-update.mjs +6 -6
- package/dist/astro/routes/api/admin/hooks/exclusive/_hookName_.mjs +3 -3
- package/dist/astro/routes/api/admin/hooks/exclusive/index.mjs +2 -2
- package/dist/astro/routes/api/admin/media-usage/activation.d.mts.map +1 -1
- package/dist/astro/routes/api/admin/media-usage/activation.mjs +8 -10
- package/dist/astro/routes/api/admin/media-usage/activation.mjs.map +1 -1
- package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs +7 -8
- package/dist/astro/routes/api/admin/media-usage/collection-deletions/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs +7 -8
- package/dist/astro/routes/api/admin/media-usage/collection-deletions/retry.mjs.map +1 -1
- package/dist/astro/routes/api/admin/media-usage/progress.d.mts.map +1 -1
- package/dist/astro/routes/api/admin/media-usage/progress.mjs +6 -8
- package/dist/astro/routes/api/admin/media-usage/progress.mjs.map +1 -1
- package/dist/astro/routes/api/admin/media-usage/repair.mjs +6 -7
- package/dist/astro/routes/api/admin/media-usage/repair.mjs.map +1 -1
- package/dist/astro/routes/api/admin/media-usage/work/index.mjs +7 -8
- package/dist/astro/routes/api/admin/media-usage/work/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/media-usage/work/retry.mjs +7 -8
- package/dist/astro/routes/api/admin/media-usage/work/retry.mjs.map +1 -1
- package/dist/astro/routes/api/admin/oauth-clients/_id_.mjs +3 -3
- package/dist/astro/routes/api/admin/oauth-clients/index.mjs +3 -3
- package/dist/astro/routes/api/admin/plugins/_id_/disable.mjs +4 -4
- package/dist/astro/routes/api/admin/plugins/_id_/enable.mjs +4 -4
- package/dist/astro/routes/api/admin/plugins/_id_/index.mjs +3 -3
- package/dist/astro/routes/api/admin/plugins/_id_/mcp.mjs +4 -4
- package/dist/astro/routes/api/admin/plugins/_id_/settings.mjs +4 -4
- package/dist/astro/routes/api/admin/plugins/_id_/uninstall.mjs +5 -5
- package/dist/astro/routes/api/admin/plugins/_id_/update.mjs +9 -8
- package/dist/astro/routes/api/admin/plugins/_id_/update.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/index.mjs +3 -3
- package/dist/astro/routes/api/admin/plugins/marketplace/_id_/icon.mjs +3 -3
- package/dist/astro/routes/api/admin/plugins/marketplace/_id_/index.mjs +3 -3
- package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs +8 -7
- package/dist/astro/routes/api/admin/plugins/marketplace/_id_/install.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/marketplace/index.mjs +3 -3
- package/dist/astro/routes/api/admin/plugins/registry/_id_/uninstall.mjs +7 -7
- package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs +14 -13
- package/dist/astro/routes/api/admin/plugins/registry/_id_/update.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/registry/artifact.d.mts.map +1 -1
- package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs +6 -6
- package/dist/astro/routes/api/admin/plugins/registry/artifact.mjs.map +1 -1
- package/dist/astro/routes/api/admin/plugins/registry/install.mjs +10 -10
- package/dist/astro/routes/api/admin/plugins/registry/publisher-handle.mjs +4 -4
- package/dist/astro/routes/api/admin/plugins/registry/verify.mjs +8 -8
- package/dist/astro/routes/api/admin/plugins/updates.mjs +7 -7
- package/dist/astro/routes/api/admin/scheduled-policy-rejections/_collection_/_id_.mjs +2 -2
- package/dist/astro/routes/api/admin/themes/marketplace/_id_/index.mjs +3 -3
- package/dist/astro/routes/api/admin/themes/marketplace/_id_/thumbnail.mjs +3 -3
- package/dist/astro/routes/api/admin/themes/marketplace/index.mjs +3 -3
- package/dist/astro/routes/api/admin/transfer/_...path_.mjs +1 -1
- package/dist/astro/routes/api/admin/transfer/approvals/_id_/approve.mjs +7 -8
- package/dist/astro/routes/api/admin/transfer/approvals/_id_/approve.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/approvals/_id_/deny.mjs +7 -8
- package/dist/astro/routes/api/admin/transfer/approvals/_id_/deny.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/approvals/index.mjs +9 -10
- package/dist/astro/routes/api/admin/transfer/approvals/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/capabilities.mjs +9 -10
- package/dist/astro/routes/api/admin/transfer/capabilities.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/exports/_id_/advance.mjs +8 -9
- package/dist/astro/routes/api/admin/transfer/exports/_id_/advance.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/exports/_id_/archive.mjs +9 -10
- package/dist/astro/routes/api/admin/transfer/exports/_id_/archive.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/exports/_id_/files/_...path_.mjs +9 -10
- package/dist/astro/routes/api/admin/transfer/exports/_id_/files/_...path_.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/exports/_id_/index.mjs +8 -9
- package/dist/astro/routes/api/admin/transfer/exports/_id_/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/exports/_id_/manifest.mjs +9 -10
- package/dist/astro/routes/api/admin/transfer/exports/_id_/manifest.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/exports/index.d.mts.map +1 -1
- package/dist/astro/routes/api/admin/transfer/exports/index.mjs +11 -13
- package/dist/astro/routes/api/admin/transfer/exports/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/_id_/abandon.mjs +8 -9
- package/dist/astro/routes/api/admin/transfer/imports/_id_/abandon.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/_id_/advance.mjs +8 -9
- package/dist/astro/routes/api/admin/transfer/imports/_id_/advance.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/_id_/analyze.mjs +10 -11
- package/dist/astro/routes/api/admin/transfer/imports/_id_/analyze.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/_id_/cancel.mjs +8 -9
- package/dist/astro/routes/api/admin/transfer/imports/_id_/cancel.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/_id_/execute.mjs +11 -12
- package/dist/astro/routes/api/admin/transfer/imports/_id_/execute.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/_id_/files/_...path_.mjs +9 -10
- package/dist/astro/routes/api/admin/transfer/imports/_id_/files/_...path_.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/_id_/index.mjs +8 -9
- package/dist/astro/routes/api/admin/transfer/imports/_id_/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/_id_/missing.mjs +10 -11
- package/dist/astro/routes/api/admin/transfer/imports/_id_/missing.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/_id_/plan.mjs +8 -9
- package/dist/astro/routes/api/admin/transfer/imports/_id_/plan.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/_id_/receipt.mjs +8 -9
- package/dist/astro/routes/api/admin/transfer/imports/_id_/receipt.mjs.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/index.d.mts.map +1 -1
- package/dist/astro/routes/api/admin/transfer/imports/index.mjs +13 -15
- package/dist/astro/routes/api/admin/transfer/imports/index.mjs.map +1 -1
- package/dist/astro/routes/api/admin/users/_id_/disable.mjs +2 -2
- package/dist/astro/routes/api/admin/users/_id_/enable.mjs +1 -1
- package/dist/astro/routes/api/admin/users/_id_/index.mjs +4 -4
- package/dist/astro/routes/api/admin/users/_id_/send-recovery.mjs +4 -4
- package/dist/astro/routes/api/admin/users/index.mjs +3 -3
- package/dist/astro/routes/api/auth/dev-bypass.mjs +2 -2
- package/dist/astro/routes/api/auth/handover.mjs +3 -3
- package/dist/astro/routes/api/auth/invite/accept.mjs +1 -1
- package/dist/astro/routes/api/auth/invite/complete.d.mts.map +1 -1
- package/dist/astro/routes/api/auth/invite/complete.mjs +10 -9
- package/dist/astro/routes/api/auth/invite/complete.mjs.map +1 -1
- package/dist/astro/routes/api/auth/invite/index.mjs +6 -6
- package/dist/astro/routes/api/auth/invite/register-options.mjs +6 -6
- package/dist/astro/routes/api/auth/logout.mjs +2 -2
- package/dist/astro/routes/api/auth/magic-link/send.mjs +8 -8
- package/dist/astro/routes/api/auth/magic-link/verify.d.mts.map +1 -1
- package/dist/astro/routes/api/auth/magic-link/verify.mjs +7 -6
- package/dist/astro/routes/api/auth/magic-link/verify.mjs.map +1 -1
- package/dist/astro/routes/api/auth/me.mjs +4 -4
- package/dist/astro/routes/api/auth/mode.mjs +1 -1
- package/dist/astro/routes/api/auth/oauth/_provider_/callback.d.mts.map +1 -1
- package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs +6 -5
- package/dist/astro/routes/api/auth/oauth/_provider_/callback.mjs.map +1 -1
- package/dist/astro/routes/api/auth/oauth/_provider_.mjs +2 -2
- package/dist/astro/routes/api/auth/passkey/_id_.mjs +3 -3
- package/dist/astro/routes/api/auth/passkey/index.mjs +1 -1
- package/dist/astro/routes/api/auth/passkey/options.mjs +9 -9
- package/dist/astro/routes/api/auth/passkey/register/options.mjs +6 -6
- package/dist/astro/routes/api/auth/passkey/register/verify.mjs +7 -7
- package/dist/astro/routes/api/auth/passkey/verify.d.mts.map +1 -1
- package/dist/astro/routes/api/auth/passkey/verify.mjs +10 -9
- package/dist/astro/routes/api/auth/passkey/verify.mjs.map +1 -1
- package/dist/astro/routes/api/auth/signup/complete.d.mts.map +1 -1
- package/dist/astro/routes/api/auth/signup/complete.mjs +10 -9
- package/dist/astro/routes/api/auth/signup/complete.mjs.map +1 -1
- package/dist/astro/routes/api/auth/signup/register-options.d.mts +8 -0
- package/dist/astro/routes/api/auth/signup/register-options.d.mts.map +1 -0
- package/dist/astro/routes/api/auth/signup/register-options.mjs +44 -0
- package/dist/astro/routes/api/auth/signup/register-options.mjs.map +1 -0
- package/dist/astro/routes/api/auth/signup/request.mjs +7 -7
- package/dist/astro/routes/api/auth/signup/verify.mjs +1 -1
- package/dist/astro/routes/api/calendar.mjs +4 -4
- package/dist/astro/routes/api/comments/_collection_/_contentId_/index.d.mts.map +1 -1
- package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs +6 -7
- package/dist/astro/routes/api/comments/_collection_/_contentId_/index.mjs.map +1 -1
- package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.d.mts.map +1 -1
- package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs +11 -12
- package/dist/astro/routes/api/comments/_collection_/_contentId_/reactions.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/compare.mjs +2 -2
- package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs +9 -10
- package/dist/astro/routes/api/content/_collection_/_id_/discard-draft.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs +6 -7
- package/dist/astro/routes/api/content/_collection_/_id_/duplicate.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/lock.d.mts.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs +15 -15
- package/dist/astro/routes/api/content/_collection_/_id_/lock.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/permanent.mjs +2 -2
- package/dist/astro/routes/api/content/_collection_/_id_/plugin-extensions/_pluginId_/_kind_/_extensionId_.mjs +2 -2
- package/dist/astro/routes/api/content/_collection_/_id_/preview-url.mjs +8 -8
- package/dist/astro/routes/api/content/_collection_/_id_/publish.d.mts.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs +9 -10
- package/dist/astro/routes/api/content/_collection_/_id_/publish.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/references/_relation_/children.mjs +6 -7
- 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 +6 -7
- 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 +3 -3
- package/dist/astro/routes/api/content/_collection_/_id_/revisions/editors.mjs +2 -2
- package/dist/astro/routes/api/content/_collection_/_id_/revisions.mjs +6 -6
- package/dist/astro/routes/api/content/_collection_/_id_/room.mjs +4 -4
- package/dist/astro/routes/api/content/_collection_/_id_/schedule.mjs +6 -6
- package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.d.mts.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs +16 -19
- package/dist/astro/routes/api/content/_collection_/_id_/terms/_taxonomy_.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_/translations.mjs +2 -2
- package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs +9 -10
- package/dist/astro/routes/api/content/_collection_/_id_/unpublish.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_.d.mts.map +1 -1
- package/dist/astro/routes/api/content/_collection_/_id_.mjs +19 -19
- package/dist/astro/routes/api/content/_collection_/_id_.mjs.map +1 -1
- package/dist/astro/routes/api/content/_collection_/authors.mjs +2 -2
- package/dist/astro/routes/api/content/_collection_/index.mjs +5 -5
- package/dist/astro/routes/api/content/_collection_/trash.mjs +4 -4
- package/dist/astro/routes/api/dashboard.mjs +6 -6
- package/dist/astro/routes/api/dev/emails.mjs +2 -2
- package/dist/astro/routes/api/dev/scheduled-tasks.mjs +4 -3
- package/dist/astro/routes/api/dev/scheduled-tasks.mjs.map +1 -1
- package/dist/astro/routes/api/health.mjs +3 -3
- package/dist/astro/routes/api/import/probe.d.mts +4 -4
- package/dist/astro/routes/api/import/probe.mjs +6 -6
- package/dist/astro/routes/api/import/wordpress/analyze.d.mts +3 -3
- package/dist/astro/routes/api/import/wordpress/analyze.mjs +3 -3
- package/dist/astro/routes/api/import/wordpress/execute.d.mts +16 -16
- package/dist/astro/routes/api/import/wordpress/execute.mjs +7 -7
- package/dist/astro/routes/api/import/wordpress/execute.mjs.map +1 -1
- package/dist/astro/routes/api/import/wordpress/media.d.mts +15 -15
- package/dist/astro/routes/api/import/wordpress/media.d.mts.map +1 -1
- package/dist/astro/routes/api/import/wordpress/media.mjs +9 -8
- package/dist/astro/routes/api/import/wordpress/media.mjs.map +1 -1
- package/dist/astro/routes/api/import/wordpress/prepare.mjs +7 -7
- package/dist/astro/routes/api/import/wordpress/rewrite-urls.d.mts +16 -16
- package/dist/astro/routes/api/import/wordpress/rewrite-urls.mjs +6 -6
- package/dist/astro/routes/api/import/wordpress-plugin/analyze.d.mts +1 -1
- package/dist/astro/routes/api/import/wordpress-plugin/analyze.mjs +6 -6
- package/dist/astro/routes/api/import/wordpress-plugin/execute.d.mts +16 -16
- package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs +13 -13
- package/dist/astro/routes/api/import/wordpress-plugin/execute.mjs.map +1 -1
- package/dist/astro/routes/api/manifest.mjs +4 -4
- package/dist/astro/routes/api/mcp.mjs +84 -77
- package/dist/astro/routes/api/mcp.mjs.map +1 -1
- package/dist/astro/routes/api/media/_id_/confirm.mjs +7 -7
- package/dist/astro/routes/api/media/_id_/replace.d.mts.map +1 -1
- package/dist/astro/routes/api/media/_id_/replace.mjs +8 -6
- package/dist/astro/routes/api/media/_id_/replace.mjs.map +1 -1
- package/dist/astro/routes/api/media/_id_/upload.mjs +5 -5
- package/dist/astro/routes/api/media/_id_/usage.mjs +6 -6
- package/dist/astro/routes/api/media/_id_.d.mts.map +1 -1
- package/dist/astro/routes/api/media/_id_.mjs +11 -8
- package/dist/astro/routes/api/media/_id_.mjs.map +1 -1
- package/dist/astro/routes/api/media/asset/_id_/_filename_.mjs +3 -3
- package/dist/astro/routes/api/media/file/_...key_.d.mts.map +1 -1
- package/dist/astro/routes/api/media/file/_...key_.mjs +7 -5
- package/dist/astro/routes/api/media/file/_...key_.mjs.map +1 -1
- package/dist/astro/routes/api/media/folders/_id_.mjs +5 -5
- package/dist/astro/routes/api/media/folders/index.mjs +5 -5
- package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.d.mts.map +1 -1
- package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs +10 -4
- package/dist/astro/routes/api/media/providers/_providerId_/_itemId_.mjs.map +1 -1
- package/dist/astro/routes/api/media/providers/_providerId_/index.mjs +2 -2
- package/dist/astro/routes/api/media/providers/index.mjs +2 -2
- package/dist/astro/routes/api/media/upload-url.mjs +7 -7
- package/dist/astro/routes/api/media.mjs +9 -9
- package/dist/astro/routes/api/menus/_name_/items/_id_.d.mts.map +1 -1
- package/dist/astro/routes/api/menus/_name_/items/_id_.mjs +8 -6
- package/dist/astro/routes/api/menus/_name_/items/_id_.mjs.map +1 -1
- package/dist/astro/routes/api/menus/_name_/items.mjs +7 -6
- package/dist/astro/routes/api/menus/_name_/items.mjs.map +1 -1
- package/dist/astro/routes/api/menus/_name_/reorder.mjs +7 -6
- package/dist/astro/routes/api/menus/_name_/reorder.mjs.map +1 -1
- package/dist/astro/routes/api/menus/_name_/translations.d.mts.map +1 -1
- package/dist/astro/routes/api/menus/_name_/translations.mjs +7 -9
- package/dist/astro/routes/api/menus/_name_/translations.mjs.map +1 -1
- package/dist/astro/routes/api/menus/_name_.d.mts.map +1 -1
- package/dist/astro/routes/api/menus/_name_.mjs +9 -6
- package/dist/astro/routes/api/menus/_name_.mjs.map +1 -1
- package/dist/astro/routes/api/menus/index.d.mts.map +1 -1
- package/dist/astro/routes/api/menus/index.mjs +8 -6
- package/dist/astro/routes/api/menus/index.mjs.map +1 -1
- package/dist/astro/routes/api/oauth/authorize.mjs +3 -3
- package/dist/astro/routes/api/oauth/device/authorize.mjs +3 -3
- package/dist/astro/routes/api/oauth/device/code.mjs +6 -6
- package/dist/astro/routes/api/oauth/device/token.mjs +5 -5
- package/dist/astro/routes/api/oauth/register.mjs +4 -4
- package/dist/astro/routes/api/oauth/token/refresh.mjs +3 -3
- package/dist/astro/routes/api/oauth/token/revoke.mjs +3 -3
- package/dist/astro/routes/api/oauth/token.mjs +4 -4
- package/dist/astro/routes/api/openapi.json.mjs +9 -9
- package/dist/astro/routes/api/openapi.json.mjs.map +1 -1
- package/dist/astro/routes/api/plugins/_pluginId_/_...path_.mjs +2 -2
- package/dist/astro/routes/api/redirects/404s/index.d.mts.map +1 -1
- package/dist/astro/routes/api/redirects/404s/index.mjs +8 -11
- package/dist/astro/routes/api/redirects/404s/index.mjs.map +1 -1
- package/dist/astro/routes/api/redirects/404s/summary.mjs +6 -7
- package/dist/astro/routes/api/redirects/404s/summary.mjs.map +1 -1
- package/dist/astro/routes/api/redirects/_id_.d.mts.map +1 -1
- package/dist/astro/routes/api/redirects/_id_.mjs +9 -12
- package/dist/astro/routes/api/redirects/_id_.mjs.map +1 -1
- package/dist/astro/routes/api/redirects/index.d.mts.map +1 -1
- package/dist/astro/routes/api/redirects/index.mjs +8 -10
- package/dist/astro/routes/api/redirects/index.mjs.map +1 -1
- package/dist/astro/routes/api/relations/_id_/index.d.mts.map +1 -1
- package/dist/astro/routes/api/relations/_id_/index.mjs +8 -11
- package/dist/astro/routes/api/relations/_id_/index.mjs.map +1 -1
- package/dist/astro/routes/api/relations/index.d.mts.map +1 -1
- package/dist/astro/routes/api/relations/index.mjs +7 -9
- package/dist/astro/routes/api/relations/index.mjs.map +1 -1
- package/dist/astro/routes/api/revisions/_revisionId_/index.mjs +2 -2
- package/dist/astro/routes/api/revisions/_revisionId_/restore.mjs +6 -6
- package/dist/astro/routes/api/schema/block-types/_slug_/index.d.mts.map +1 -1
- package/dist/astro/routes/api/schema/block-types/_slug_/index.mjs +7 -9
- 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 +6 -7
- 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.d.mts.map +1 -1
- package/dist/astro/routes/api/schema/block-types/index.mjs +7 -9
- package/dist/astro/routes/api/schema/block-types/index.mjs.map +1 -1
- package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.d.mts.map +1 -1
- package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs +8 -11
- package/dist/astro/routes/api/schema/collections/_slug_/fields/_fieldSlug_.mjs.map +1 -1
- package/dist/astro/routes/api/schema/collections/_slug_/fields/index.d.mts.map +1 -1
- package/dist/astro/routes/api/schema/collections/_slug_/fields/index.mjs +7 -9
- 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 +6 -7
- package/dist/astro/routes/api/schema/collections/_slug_/fields/reorder.mjs.map +1 -1
- package/dist/astro/routes/api/schema/collections/_slug_/index.d.mts.map +1 -1
- package/dist/astro/routes/api/schema/collections/_slug_/index.mjs +8 -11
- package/dist/astro/routes/api/schema/collections/_slug_/index.mjs.map +1 -1
- package/dist/astro/routes/api/schema/collections/index.d.mts.map +1 -1
- package/dist/astro/routes/api/schema/collections/index.mjs +7 -9
- package/dist/astro/routes/api/schema/collections/index.mjs.map +1 -1
- package/dist/astro/routes/api/schema/collections/reorder.mjs +6 -7
- package/dist/astro/routes/api/schema/collections/reorder.mjs.map +1 -1
- package/dist/astro/routes/api/schema/index.mjs +4 -5
- package/dist/astro/routes/api/schema/index.mjs.map +1 -1
- package/dist/astro/routes/api/schema/orphans/_slug_.mjs +6 -7
- package/dist/astro/routes/api/schema/orphans/_slug_.mjs.map +1 -1
- package/dist/astro/routes/api/schema/orphans/index.mjs +4 -5
- package/dist/astro/routes/api/schema/orphans/index.mjs.map +1 -1
- package/dist/astro/routes/api/search/enable.d.mts.map +1 -1
- package/dist/astro/routes/api/search/enable.mjs +8 -5
- package/dist/astro/routes/api/search/enable.mjs.map +1 -1
- package/dist/astro/routes/api/search/index.d.mts.map +1 -1
- package/dist/astro/routes/api/search/index.mjs +7 -4
- package/dist/astro/routes/api/search/index.mjs.map +1 -1
- package/dist/astro/routes/api/search/rebuild.d.mts.map +1 -1
- package/dist/astro/routes/api/search/rebuild.mjs +8 -5
- package/dist/astro/routes/api/search/rebuild.mjs.map +1 -1
- package/dist/astro/routes/api/search/stats.d.mts.map +1 -1
- package/dist/astro/routes/api/search/stats.mjs +6 -3
- package/dist/astro/routes/api/search/stats.mjs.map +1 -1
- package/dist/astro/routes/api/search/suggest.d.mts.map +1 -1
- package/dist/astro/routes/api/search/suggest.mjs +7 -4
- package/dist/astro/routes/api/search/suggest.mjs.map +1 -1
- package/dist/astro/routes/api/sections/_slug_.d.mts.map +1 -1
- package/dist/astro/routes/api/sections/_slug_.mjs +8 -11
- package/dist/astro/routes/api/sections/_slug_.mjs.map +1 -1
- package/dist/astro/routes/api/sections/index.d.mts.map +1 -1
- package/dist/astro/routes/api/sections/index.mjs +7 -9
- package/dist/astro/routes/api/sections/index.mjs.map +1 -1
- package/dist/astro/routes/api/settings/backups/archives/_name_.mjs +4 -4
- package/dist/astro/routes/api/settings/backups/archives/index.mjs +3 -3
- package/dist/astro/routes/api/settings/backups/export.mjs +4 -4
- package/dist/astro/routes/api/settings/backups/index.mjs +5 -5
- package/dist/astro/routes/api/settings/domain-notify.mjs +6 -6
- package/dist/astro/routes/api/settings/domain.mjs +6 -6
- package/dist/astro/routes/api/settings/email.mjs +5 -5
- package/dist/astro/routes/api/settings.mjs +5 -5
- package/dist/astro/routes/api/setup/admin-verify.d.mts.map +1 -1
- package/dist/astro/routes/api/setup/admin-verify.mjs +12 -11
- package/dist/astro/routes/api/setup/admin-verify.mjs.map +1 -1
- package/dist/astro/routes/api/setup/admin.mjs +7 -7
- package/dist/astro/routes/api/setup/dev-bypass.mjs +8 -8
- package/dist/astro/routes/api/setup/dev-reset.mjs +1 -1
- package/dist/astro/routes/api/setup/index.mjs +8 -8
- package/dist/astro/routes/api/setup/status.mjs +2 -2
- package/dist/astro/routes/api/site/domain-proof.mjs +2 -2
- package/dist/astro/routes/api/snapshot.mjs +6 -6
- package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs +6 -7
- package/dist/astro/routes/api/taxonomies/_name_/reorder.mjs.map +1 -1
- package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.d.mts.map +1 -1
- package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs +7 -9
- package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_/translations.mjs.map +1 -1
- package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.d.mts.map +1 -1
- package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs +9 -12
- package/dist/astro/routes/api/taxonomies/_name_/terms/_slug_.mjs.map +1 -1
- package/dist/astro/routes/api/taxonomies/_name_/terms/index.d.mts.map +1 -1
- package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs +7 -9
- package/dist/astro/routes/api/taxonomies/_name_/terms/index.mjs.map +1 -1
- package/dist/astro/routes/api/taxonomies/_name_/translations.mjs +6 -7
- package/dist/astro/routes/api/taxonomies/_name_/translations.mjs.map +1 -1
- package/dist/astro/routes/api/taxonomies/_name_.d.mts.map +1 -1
- package/dist/astro/routes/api/taxonomies/_name_.mjs +9 -12
- package/dist/astro/routes/api/taxonomies/_name_.mjs.map +1 -1
- package/dist/astro/routes/api/taxonomies/bulk-tag.mjs +12 -13
- package/dist/astro/routes/api/taxonomies/bulk-tag.mjs.map +1 -1
- package/dist/astro/routes/api/taxonomies/index.d.mts.map +1 -1
- package/dist/astro/routes/api/taxonomies/index.mjs +8 -10
- package/dist/astro/routes/api/taxonomies/index.mjs.map +1 -1
- package/dist/astro/routes/api/themes/preview.mjs +4 -4
- package/dist/astro/routes/api/typegen.mjs +3 -3
- package/dist/astro/routes/api/visual-editing/action-token.mjs +3 -3
- package/dist/astro/routes/api/visual-editing/content/_collection_/_id_/publish.mjs +3 -3
- package/dist/astro/routes/api/visual-editing/toolbar-labels.mjs +1 -1
- package/dist/astro/routes/api/well-known/auth.mjs +1 -1
- package/dist/astro/routes/api/well-known/oauth-authorization-server.mjs +1 -1
- package/dist/astro/routes/api/well-known/oauth-protected-resource.mjs +1 -1
- package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs +6 -5
- package/dist/astro/routes/api/widget-areas/_name_/reorder.mjs.map +1 -1
- package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.d.mts.map +1 -1
- package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs +8 -6
- package/dist/astro/routes/api/widget-areas/_name_/widgets/_id_.mjs.map +1 -1
- package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs +7 -6
- package/dist/astro/routes/api/widget-areas/_name_/widgets.mjs.map +1 -1
- package/dist/astro/routes/api/widget-areas/_name_.d.mts.map +1 -1
- package/dist/astro/routes/api/widget-areas/_name_.mjs +6 -4
- package/dist/astro/routes/api/widget-areas/_name_.mjs.map +1 -1
- package/dist/astro/routes/api/widget-areas/index.d.mts.map +1 -1
- package/dist/astro/routes/api/widget-areas/index.mjs +8 -6
- package/dist/astro/routes/api/widget-areas/index.mjs.map +1 -1
- package/dist/astro/routes/api/widget-components.mjs +2 -2
- package/dist/astro/routes/robots.txt.mjs +2 -2
- package/dist/astro/routes/sitemap-_collection_.xml.mjs +5 -5
- package/dist/astro/routes/sitemap.xml.mjs +3 -3
- package/dist/astro/types.d.mts +82 -69
- package/dist/astro/types.d.mts.map +1 -1
- package/dist/auth/providers/github.d.mts +1 -1
- package/dist/auth/providers/google.d.mts +1 -1
- package/dist/auth/providers/microsoft.d.mts +1 -1
- package/dist/authoritative-records-DFHFmreO.mjs +5183 -0
- package/dist/authoritative-records-DFHFmreO.mjs.map +1 -0
- package/dist/authorize-6a0h5NN5.mjs +74 -0
- package/dist/authorize-6a0h5NN5.mjs.map +1 -0
- package/dist/backup-GBRxixs1.mjs +246 -0
- package/dist/backup-GBRxixs1.mjs.map +1 -0
- package/dist/block-types-BeLZ85Sw.mjs +132 -0
- package/dist/block-types-BeLZ85Sw.mjs.map +1 -0
- package/dist/block-values-BRJZHvF4.mjs +215 -0
- package/dist/block-values-BRJZHvF4.mjs.map +1 -0
- package/dist/byline-BufjxQyd.mjs +930 -0
- package/dist/byline-BufjxQyd.mjs.map +1 -0
- package/dist/byline-fields-Bw7z2opJ.mjs +123 -0
- package/dist/byline-fields-Bw7z2opJ.mjs.map +1 -0
- package/dist/byline-registry-edmv55U7.mjs +406 -0
- package/dist/byline-registry-edmv55U7.mjs.map +1 -0
- package/dist/bylines-C8ZT6iWw.mjs +234 -0
- package/dist/bylines-C8ZT6iWw.mjs.map +1 -0
- package/dist/bylines-a01JW9yq.mjs +150 -0
- package/dist/bylines-a01JW9yq.mjs.map +1 -0
- package/dist/cache-LOb3NthC.mjs +151 -0
- package/dist/cache-LOb3NthC.mjs.map +1 -0
- package/dist/canonical-CUkatNPc.mjs +174 -0
- package/dist/canonical-CUkatNPc.mjs.map +1 -0
- package/dist/capture-triggers-BK2pp_kZ.mjs +362 -0
- package/dist/capture-triggers-BK2pp_kZ.mjs.map +1 -0
- package/dist/checksum-C8lkApUe.mjs +162 -0
- package/dist/checksum-C8lkApUe.mjs.map +1 -0
- package/dist/chunks-CvgCLYip.mjs +25 -0
- package/dist/chunks-CvgCLYip.mjs.map +1 -0
- package/dist/cli/index.mjs +24 -24
- package/dist/client/cf-access.d.mts +1 -1
- package/dist/client/index.d.mts +63 -63
- package/dist/client/index.d.mts.map +1 -1
- package/dist/client/index.mjs +6 -4
- package/dist/client/index.mjs.map +1 -1
- package/dist/collection-slugs-cache-CLR_8fY5.mjs +91 -0
- package/dist/collection-slugs-cache-CLR_8fY5.mjs.map +1 -0
- package/dist/comment-C163Gl_4.mjs +335 -0
- package/dist/comment-C163Gl_4.mjs.map +1 -0
- package/dist/comment-reaction-1Df3G-ij.mjs +85 -0
- package/dist/comment-reaction-1Df3G-ij.mjs.map +1 -0
- package/dist/comments-BFyw2y-m.mjs +99 -0
- package/dist/comments-BFyw2y-m.mjs.map +1 -0
- package/dist/comments-D73Sy_2U.mjs +195 -0
- package/dist/comments-D73Sy_2U.mjs.map +1 -0
- package/dist/components-DjV1sxUL.mjs +112 -0
- package/dist/components-DjV1sxUL.mjs.map +1 -0
- package/dist/config-B27hvMjf.d.mts +7274 -0
- package/dist/config-B27hvMjf.d.mts.map +1 -0
- package/dist/config-DLzKVQBA.d.mts +41 -0
- package/dist/config-DLzKVQBA.d.mts.map +1 -0
- package/dist/config-DeluGa9H.mjs +228 -0
- package/dist/config-DeluGa9H.mjs.map +1 -0
- package/dist/connection-D6aKSo2Y.mjs +36 -0
- package/dist/connection-D6aKSo2Y.mjs.map +1 -0
- package/dist/content-2gjSbGP3.mjs +2295 -0
- package/dist/content-2gjSbGP3.mjs.map +1 -0
- package/dist/content-list-query-B9SlIDbL.d.mts +26 -0
- package/dist/content-list-query-B9SlIDbL.d.mts.map +1 -0
- package/dist/content-repair-Dizo4qiY.mjs +443 -0
- package/dist/content-repair-Dizo4qiY.mjs.map +1 -0
- package/dist/content-save-BKDTKmkx.mjs +202 -0
- package/dist/content-save-BKDTKmkx.mjs.map +1 -0
- package/dist/context-DCQrjN95.mjs +2242 -0
- package/dist/context-DCQrjN95.mjs.map +1 -0
- package/dist/credits-Bxp4F72g.mjs +110 -0
- package/dist/credits-Bxp4F72g.mjs.map +1 -0
- package/dist/cron-DEV8oz3R.mjs +310 -0
- package/dist/cron-DEV8oz3R.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 +2 -2
- package/dist/db/libsql.d.mts +1 -1
- package/dist/db/postgres-migrations.d.mts +1 -1
- package/dist/db/postgres-migrations.mjs +2 -2
- package/dist/db/postgres.d.mts +1 -1
- package/dist/db/sqlite-migrations.d.mts +1 -1
- package/dist/db/sqlite-migrations.mjs +2 -2
- package/dist/db/sqlite.d.mts +1 -1
- package/dist/db/sqlite.mjs +1 -1
- package/dist/default-DKs7zP7m.mjs +81 -0
- package/dist/default-DKs7zP7m.mjs.map +1 -0
- package/dist/deferred-tasks-B5LQWb5F.d.mts +10 -0
- package/dist/deferred-tasks-B5LQWb5F.d.mts.map +1 -0
- package/dist/device-flow-D6kyi3jX.mjs +519 -0
- package/dist/device-flow-D6kyi3jX.mjs.map +1 -0
- package/dist/dialect-helpers-DRe1Y08G.mjs +355 -0
- package/dist/dialect-helpers-DRe1Y08G.mjs.map +1 -0
- package/dist/digest-DSsUd9oL.mjs +194 -0
- package/dist/digest-DSsUd9oL.mjs.map +1 -0
- package/dist/direct-executor-DAcU8MTG.mjs +117 -0
- package/dist/direct-executor-DAcU8MTG.mjs.map +1 -0
- package/dist/email-console-CBZpj1VI.mjs +50 -0
- package/dist/email-console-CBZpj1VI.mjs.map +1 -0
- package/dist/email-locale-CGjBa23b.mjs +25 -0
- package/dist/email-locale-CGjBa23b.mjs.map +1 -0
- package/dist/email-smtp-CE6nESRL.mjs +643 -0
- package/dist/email-smtp-CE6nESRL.mjs.map +1 -0
- package/dist/emdash-runtime-CF6KAut9.mjs +5576 -0
- package/dist/emdash-runtime-CF6KAut9.mjs.map +1 -0
- package/dist/enrich-C4vKniyi.mjs +203 -0
- package/dist/enrich-C4vKniyi.mjs.map +1 -0
- package/dist/entry-lock-DJgDNfMf.mjs +1230 -0
- package/dist/entry-lock-DJgDNfMf.mjs.map +1 -0
- package/dist/entry-lock-GKD0lJI5.mjs +207 -0
- package/dist/entry-lock-GKD0lJI5.mjs.map +1 -0
- package/dist/entry-locks-B58Q9LZh.mjs +173 -0
- package/dist/entry-locks-B58Q9LZh.mjs.map +1 -0
- package/dist/env-types-EL7WTMzr.mjs +38 -0
- package/dist/env-types-EL7WTMzr.mjs.map +1 -0
- package/dist/error-0Y0dFPxm.mjs +82 -0
- package/dist/error-0Y0dFPxm.mjs.map +1 -0
- package/dist/errors-OTWh4SC_.mjs +502 -0
- package/dist/errors-OTWh4SC_.mjs.map +1 -0
- package/dist/errors-u5rZhbVQ.mjs +120 -0
- package/dist/errors-u5rZhbVQ.mjs.map +1 -0
- package/dist/fence-CkdbSoZX.mjs +162 -0
- package/dist/fence-CkdbSoZX.mjs.map +1 -0
- package/dist/field-defs-cache-BW0Y9Wrp.mjs +79 -0
- package/dist/field-defs-cache-BW0Y9Wrp.mjs.map +1 -0
- package/dist/field-map-Bhqs6zUK.mjs +84 -0
- package/dist/field-map-Bhqs6zUK.mjs.map +1 -0
- package/dist/fts-manager-m8GPxogO.mjs +532 -0
- package/dist/fts-manager-m8GPxogO.mjs.map +1 -0
- package/dist/gc-CEhfEMLY.mjs +62 -0
- package/dist/gc-CEhfEMLY.mjs.map +1 -0
- package/dist/hook-result-CG0uHAT5.d.mts +31 -0
- package/dist/hook-result-CG0uHAT5.d.mts.map +1 -0
- package/dist/hook-result-mOyk-VCt.mjs +3855 -0
- package/dist/hook-result-mOyk-VCt.mjs.map +1 -0
- package/dist/hreflang-B1E64c5R.d.mts +51 -0
- package/dist/hreflang-B1E64c5R.d.mts.map +1 -0
- package/dist/hreflang-DaMRoUor.mjs +105 -0
- package/dist/hreflang-DaMRoUor.mjs.map +1 -0
- package/dist/http-route-dispatch-Y8bwyixm.mjs +348 -0
- package/dist/http-route-dispatch-Y8bwyixm.mjs.map +1 -0
- package/dist/identity-cqdOzgy9.mjs +35 -0
- package/dist/identity-cqdOzgy9.mjs.map +1 -0
- package/dist/index-CzbH8FX2.d.mts +261 -0
- package/dist/index-CzbH8FX2.d.mts.map +1 -0
- package/dist/index.d.mts +25 -25
- package/dist/index.mjs +60 -53
- package/dist/index.mjs.map +1 -1
- package/dist/install-finalization-B02IcpqW.mjs +58 -0
- package/dist/install-finalization-B02IcpqW.mjs.map +1 -0
- package/dist/json-recordset-2VNAgija.mjs +12 -0
- package/dist/json-recordset-2VNAgija.mjs.map +1 -0
- package/dist/json-schema-CnImQ4DF.mjs +15 -0
- package/dist/json-schema-CnImQ4DF.mjs.map +1 -0
- package/dist/keys-B5WUGmYK.mjs +61 -0
- package/dist/keys-B5WUGmYK.mjs.map +1 -0
- package/dist/kinds-DyAmbNrx.mjs +974 -0
- package/dist/kinds-DyAmbNrx.mjs.map +1 -0
- package/dist/lifecycle-1Nl01SeB.mjs +53 -0
- package/dist/lifecycle-1Nl01SeB.mjs.map +1 -0
- package/dist/limits-BuiMu9zx.mjs +44 -0
- package/dist/limits-BuiMu9zx.mjs.map +1 -0
- package/dist/load-CEt0TQ4_.mjs +36 -0
- package/dist/load-CEt0TQ4_.mjs.map +1 -0
- package/dist/loader-DF6J1Fpd.mjs +1537 -0
- package/dist/loader-DF6J1Fpd.mjs.map +1 -0
- package/dist/loops-3DdrfQ6y.mjs +217 -0
- package/dist/loops-3DdrfQ6y.mjs.map +1 -0
- package/dist/manifest-builder-Dcfqd9Aw.mjs +196 -0
- package/dist/manifest-builder-Dcfqd9Aw.mjs.map +1 -0
- package/dist/manifest-schema-Pi_JP_Wi.mjs +497 -0
- package/dist/manifest-schema-Pi_JP_Wi.mjs.map +1 -0
- package/dist/marketplace-BsMC_Z7o.mjs +257 -0
- package/dist/marketplace-BsMC_Z7o.mjs.map +1 -0
- package/dist/marketplace-D9fChLav.mjs +965 -0
- package/dist/marketplace-D9fChLav.mjs.map +1 -0
- package/dist/media/image-endpoint.d.mts +33 -1
- package/dist/media/image-endpoint.d.mts.map +1 -1
- package/dist/media/image-endpoint.mjs +77 -1
- package/dist/media/image-endpoint.mjs.map +1 -1
- package/dist/media/index.d.mts +1 -1
- package/dist/media/index.mjs +1 -1
- package/dist/media/local-runtime.d.mts +17 -17
- package/dist/media/local-runtime.mjs +3 -3
- package/dist/media--P-IEycF.mjs +2813 -0
- package/dist/media--P-IEycF.mjs.map +1 -0
- package/dist/media-CTA82rU1.mjs +295 -0
- package/dist/media-CTA82rU1.mjs.map +1 -0
- package/dist/media-Cq_oKN_Y.mjs +425 -0
- package/dist/media-Cq_oKN_Y.mjs.map +1 -0
- package/dist/media-DRDkfiDv.d.mts +203 -0
- package/dist/media-DRDkfiDv.d.mts.map +1 -0
- package/dist/media-allowlist-C_kSleFj.mjs +103 -0
- package/dist/media-allowlist-C_kSleFj.mjs.map +1 -0
- package/dist/media-folders-Lc9Ks8az.mjs +205 -0
- package/dist/media-folders-Lc9Ks8az.mjs.map +1 -0
- package/dist/media-url-BEvOId4Z.mjs +43 -0
- package/dist/media-url-BEvOId4Z.mjs.map +1 -0
- package/dist/media-usage-D6LjfdGn.mjs +282 -0
- package/dist/media-usage-D6LjfdGn.mjs.map +1 -0
- package/dist/media-usage-activation-i6tqb6cn.mjs +78 -0
- package/dist/media-usage-activation-i6tqb6cn.mjs.map +1 -0
- package/dist/media-usage-work-C5HHgfEU.mjs +1036 -0
- package/dist/media-usage-work-C5HHgfEU.mjs.map +1 -0
- package/dist/media-usage-work-CxqS_Ny9.mjs +151 -0
- package/dist/media-usage-work-CxqS_Ny9.mjs.map +1 -0
- package/dist/menu-CvWToneO.mjs +420 -0
- package/dist/menu-CvWToneO.mjs.map +1 -0
- package/dist/menus-BzjHvAM4.mjs +434 -0
- package/dist/menus-BzjHvAM4.mjs.map +1 -0
- package/dist/menus-CnEw5nz8.mjs +92 -0
- package/dist/menus-CnEw5nz8.mjs.map +1 -0
- package/dist/menus-DoVbs2sn.mjs +433 -0
- package/dist/menus-DoVbs2sn.mjs.map +1 -0
- package/dist/migrations/index.d.mts +1 -1
- package/dist/migrations/index.mjs +2 -2
- package/dist/mime-C_YV5Mjm.mjs +90 -0
- package/dist/mime-C_YV5Mjm.mjs.map +1 -0
- package/dist/node-sqlite-compat-DHFDZMe2.mjs +68 -0
- package/dist/node-sqlite-compat-DHFDZMe2.mjs.map +1 -0
- package/dist/oauth-authorization-CvT-8KtG.mjs +287 -0
- package/dist/oauth-authorization-CvT-8KtG.mjs.map +1 -0
- package/dist/oauth-clients-ohsH0FlQ.mjs +266 -0
- package/dist/oauth-clients-ohsH0FlQ.mjs.map +1 -0
- package/dist/oauth-state-store-V4y2qZwD.mjs +80 -0
- package/dist/oauth-state-store-V4y2qZwD.mjs.map +1 -0
- package/dist/oauth-user-lookup-D2NTHxcr.mjs +26 -0
- package/dist/oauth-user-lookup-D2NTHxcr.mjs.map +1 -0
- package/dist/object-cache/memory.d.mts +1 -1
- package/dist/object-cache-I4Re7BOR.mjs +807 -0
- package/dist/object-cache-I4Re7BOR.mjs.map +1 -0
- package/dist/options-CbSYZAwr.d.mts +81 -0
- package/dist/options-CbSYZAwr.d.mts.map +1 -0
- package/dist/page/index.d.mts +2 -2
- package/dist/parse-BTfkfMuL.mjs +82 -0
- package/dist/parse-BTfkfMuL.mjs.map +1 -0
- package/dist/parse-CBM779p-.d.mts +180 -0
- package/dist/parse-CBM779p-.d.mts.map +1 -0
- package/dist/parts-i0nNljq-.mjs +68 -0
- package/dist/parts-i0nNljq-.mjs.map +1 -0
- package/dist/passkey-config-D9iYgt4G.mjs +46 -0
- package/dist/passkey-config-D9iYgt4G.mjs.map +1 -0
- package/dist/paths-B1TgS0ir.mjs +77 -0
- package/dist/paths-B1TgS0ir.mjs.map +1 -0
- package/dist/placeholder-PFMxMYTa.d.mts +316 -0
- package/dist/placeholder-PFMxMYTa.d.mts.map +1 -0
- package/dist/plan-DQoNgF2Y.mjs +135 -0
- package/dist/plan-DQoNgF2Y.mjs.map +1 -0
- package/dist/plugin-settings-CKffVNYE.mjs +162 -0
- package/dist/plugin-settings-CKffVNYE.mjs.map +1 -0
- package/dist/plugin-test-runtime.d.mts +23 -22
- package/dist/plugin-test-runtime.d.mts.map +1 -1
- package/dist/plugin-test-runtime.mjs +9 -8
- package/dist/plugin-types.d.mts +2 -2
- package/dist/plugin-utils.d.mts +15 -15
- package/dist/plugins/adapt-sandbox-entry.d.mts +15 -15
- package/dist/plugins/adapt-sandbox-entry.mjs +4 -4
- package/dist/plugins/host.d.mts +6 -6
- package/dist/plugins/host.mjs +8 -7
- package/dist/plugins-DDiWIA_N.mjs +261 -0
- package/dist/plugins-DDiWIA_N.mjs.map +1 -0
- package/dist/policy-72PGoCgJ.mjs +56 -0
- package/dist/policy-72PGoCgJ.mjs.map +1 -0
- package/dist/portable-text-D18C1jR6.mjs +457 -0
- package/dist/portable-text-D18C1jR6.mjs.map +1 -0
- package/dist/protocol-CbSoh3FE.d.mts +65 -0
- package/dist/protocol-CbSoh3FE.d.mts.map +1 -0
- package/dist/public-plugin-api-routes-Bq55wwHn.mjs +323 -0
- package/dist/public-plugin-api-routes-Bq55wwHn.mjs.map +1 -0
- package/dist/public-submission-BEcSmcWi.mjs +253 -0
- package/dist/public-submission-BEcSmcWi.mjs.map +1 -0
- package/dist/public-url-DYZMfvpa.mjs +123 -0
- package/dist/public-url-DYZMfvpa.mjs.map +1 -0
- package/dist/query-CslUTGOV.mjs +1221 -0
- package/dist/query-CslUTGOV.mjs.map +1 -0
- package/dist/query-Cv8bjIwl.mjs +41 -0
- package/dist/query-Cv8bjIwl.mjs.map +1 -0
- package/dist/range-CzdsIs-O.mjs +51 -0
- package/dist/range-CzdsIs-O.mjs.map +1 -0
- package/dist/rate-limit-iZgsy_oY.mjs +127 -0
- package/dist/rate-limit-iZgsy_oY.mjs.map +1 -0
- package/dist/receipt-CqxAacXn.mjs +43 -0
- package/dist/receipt-CqxAacXn.mjs.map +1 -0
- package/dist/redirect-3A3kqsD-.mjs +19 -0
- package/dist/redirect-3A3kqsD-.mjs.map +1 -0
- package/dist/redirect-DsaFuuQi.mjs +466 -0
- package/dist/redirect-DsaFuuQi.mjs.map +1 -0
- package/dist/redirect-paths-DgkkN0qJ.mjs +36 -0
- package/dist/redirect-paths-DgkkN0qJ.mjs.map +1 -0
- package/dist/redirects-DfvdrgF1.mjs +446 -0
- package/dist/redirects-DfvdrgF1.mjs.map +1 -0
- package/dist/redirects-Yo8YTJMV.mjs +148 -0
- package/dist/redirects-Yo8YTJMV.mjs.map +1 -0
- package/dist/registry/testing.mjs +2 -2
- package/dist/registry-2vAYgqCz.mjs +755 -0
- package/dist/registry-2vAYgqCz.mjs.map +1 -0
- package/dist/registry-COR9pjyi.mjs +1449 -0
- package/dist/registry-COR9pjyi.mjs.map +1 -0
- package/dist/registry-CSLrHSx1.mjs +6139 -0
- package/dist/registry-CSLrHSx1.mjs.map +1 -0
- package/dist/relations-5fVj42fZ.mjs +798 -0
- package/dist/relations-5fVj42fZ.mjs.map +1 -0
- package/dist/request-context.d.mts +2 -2
- package/dist/request-meta-B0TPrDpq.mjs +141 -0
- package/dist/request-meta-B0TPrDpq.mjs.map +1 -0
- package/dist/resolve--EmZidEz.mjs +92 -0
- package/dist/resolve--EmZidEz.mjs.map +1 -0
- package/dist/revision-Dk9VI8Vf.mjs +503 -0
- package/dist/revision-Dk9VI8Vf.mjs.map +1 -0
- package/dist/rooms/index.d.mts +15 -15
- package/dist/rooms/index.mjs +3 -3
- package/dist/rooms/node/index.d.mts +15 -15
- package/dist/rooms/node/index.mjs +6 -6
- package/dist/rooms/notifications.d.mts +15 -15
- package/dist/rooms/notifications.mjs +2 -2
- package/dist/rooms/room.d.mts +15 -15
- package/dist/rooms/room.mjs +2 -2
- package/dist/rooms/site.d.mts +15 -15
- package/dist/rooms/site.mjs +4 -4
- package/dist/rooms-AcO0YNUt.mjs +335 -0
- package/dist/rooms-AcO0YNUt.mjs.map +1 -0
- package/dist/rooms-B2P1xIS_.d.mts +4778 -0
- package/dist/rooms-B2P1xIS_.d.mts.map +1 -0
- package/dist/rooms-C08U-F8Y.mjs +169 -0
- package/dist/rooms-C08U-F8Y.mjs.map +1 -0
- package/dist/route-cache-CvTJlNVT.mjs +30 -0
- package/dist/route-cache-CvTJlNVT.mjs.map +1 -0
- package/dist/route-wire-NAkNES3Z.mjs +197 -0
- package/dist/route-wire-NAkNES3Z.mjs.map +1 -0
- package/dist/routes-BScyES_G.mjs +272 -0
- package/dist/routes-BScyES_G.mjs.map +1 -0
- package/dist/runner-C6gBIcTD.d.mts +79 -0
- package/dist/runner-C6gBIcTD.d.mts.map +1 -0
- package/dist/runner-Nv0yWP-G.mjs +6964 -0
- package/dist/runner-Nv0yWP-G.mjs.map +1 -0
- package/dist/runtime-holder-DkZ_0f7A.mjs +36 -0
- package/dist/runtime-holder-DkZ_0f7A.mjs.map +1 -0
- package/dist/runtime.d.mts +16 -16
- package/dist/runtime.mjs +1 -1
- package/dist/scheduler-health-B5n19775.mjs +31 -0
- package/dist/scheduler-health-B5n19775.mjs.map +1 -0
- package/dist/schema/project-env-types.mjs +6 -6
- package/dist/schema-B7ODIkP4.mjs +13 -0
- package/dist/schema-B7ODIkP4.mjs.map +1 -0
- package/dist/schema-D04_n_7j.mjs +815 -0
- package/dist/schema-D04_n_7j.mjs.map +1 -0
- package/dist/scopes-CHc86VzZ.mjs +34 -0
- package/dist/scopes-CHc86VzZ.mjs.map +1 -0
- package/dist/search-BxBg7Xq1.mjs +503 -0
- package/dist/search-BxBg7Xq1.mjs.map +1 -0
- package/dist/search-SRLBXKJU.mjs +12 -0
- package/dist/search-SRLBXKJU.mjs.map +1 -0
- package/dist/secrets-O25WpEe_.mjs +369 -0
- package/dist/secrets-O25WpEe_.mjs.map +1 -0
- package/dist/sections-BK7soA2U.mjs +222 -0
- package/dist/sections-BK7soA2U.mjs.map +1 -0
- package/dist/sections-CLejSkAG.mjs +129 -0
- package/dist/sections-CLejSkAG.mjs.map +1 -0
- package/dist/seed/index.d.mts +2 -2
- package/dist/seed/index.mjs +4 -4
- package/dist/seo/index.d.mts +3 -3
- package/dist/seo/index.mjs +3 -3
- package/dist/seo-Ie7B6cud.mjs +194 -0
- package/dist/seo-Ie7B6cud.mjs.map +1 -0
- package/dist/service-DbKGSUHC.mjs +150 -0
- package/dist/service-DbKGSUHC.mjs.map +1 -0
- package/dist/session-user-BrCPLyWB.mjs +61 -0
- package/dist/session-user-BrCPLyWB.mjs.map +1 -0
- package/dist/settings-BApLX_aS.mjs +413 -0
- package/dist/settings-BApLX_aS.mjs.map +1 -0
- package/dist/settings-Ces2K0VL.mjs +74 -0
- package/dist/settings-Ces2K0VL.mjs.map +1 -0
- package/dist/settings-DMHIgDyb.mjs +66 -0
- package/dist/settings-DMHIgDyb.mjs.map +1 -0
- package/dist/settings-DgnWX0GN.mjs +157 -0
- package/dist/settings-DgnWX0GN.mjs.map +1 -0
- package/dist/setup-complete-DQ1nNEjm.mjs +65 -0
- package/dist/setup-complete-DQ1nNEjm.mjs.map +1 -0
- package/dist/setup-nonce-5k8BY3W_.mjs +25 -0
- package/dist/setup-nonce-5k8BY3W_.mjs.map +1 -0
- package/dist/site-domain-B2KvJstd.mjs +131 -0
- package/dist/site-domain-B2KvJstd.mjs.map +1 -0
- package/dist/site-settings-B7VxSqP6.mjs +50 -0
- package/dist/site-settings-B7VxSqP6.mjs.map +1 -0
- package/dist/site-title-DHgWlyMw.mjs +14 -0
- package/dist/site-title-DHgWlyMw.mjs.map +1 -0
- package/dist/site-url-OBYES-gb.mjs +45 -0
- package/dist/site-url-OBYES-gb.mjs.map +1 -0
- package/dist/sitemap-name-BZXv5sf0.mjs +26 -0
- package/dist/sitemap-name-BZXv5sf0.mjs.map +1 -0
- package/dist/slug-CFsfrxUp.mjs +16 -0
- package/dist/slug-CFsfrxUp.mjs.map +1 -0
- package/dist/snapshot-BaIv7afB.mjs +466 -0
- package/dist/snapshot-BaIv7afB.mjs.map +1 -0
- package/dist/snapshot-VQM7BcdM.mjs +184 -0
- package/dist/snapshot-VQM7BcdM.mjs.map +1 -0
- package/dist/ssrf-Em0CeaaN.mjs +406 -0
- package/dist/ssrf-Em0CeaaN.mjs.map +1 -0
- package/dist/stage-Ctas_E7M.mjs +662 -0
- package/dist/stage-Ctas_E7M.mjs.map +1 -0
- package/dist/staged-C746SkS0.mjs +686 -0
- package/dist/staged-C746SkS0.mjs.map +1 -0
- package/dist/start-user-session-CdyNie0P.mjs +9 -0
- package/dist/start-user-session-CdyNie0P.mjs.map +1 -0
- package/dist/state-Cdkt6b1h.mjs +282 -0
- package/dist/state-Cdkt6b1h.mjs.map +1 -0
- package/dist/storage/local.d.mts +1 -1
- package/dist/storage/local.mjs +2 -2
- package/dist/storage/s3.d.mts +1 -1
- package/dist/storage/s3.mjs +1 -1
- package/dist/storage-query-DdKo8oes.d.mts +1614 -0
- package/dist/storage-query-DdKo8oes.d.mts.map +1 -0
- package/dist/tar-Tbl91sMI.mjs +449 -0
- package/dist/tar-Tbl91sMI.mjs.map +1 -0
- package/dist/target-Bjxlaj4T.mjs +27 -0
- package/dist/target-Bjxlaj4T.mjs.map +1 -0
- package/dist/taxonomies-D5bavOHA.mjs +937 -0
- package/dist/taxonomies-D5bavOHA.mjs.map +1 -0
- package/dist/taxonomies-DApyZAJq.mjs +722 -0
- package/dist/taxonomies-DApyZAJq.mjs.map +1 -0
- package/dist/taxonomy-D4Fl2smf.mjs +593 -0
- package/dist/taxonomy-D4Fl2smf.mjs.map +1 -0
- package/dist/tokens-DvEbszXd.mjs +171 -0
- package/dist/tokens-DvEbszXd.mjs.map +1 -0
- package/dist/transaction-D5Kq7MTL.mjs +44 -0
- package/dist/transaction-D5Kq7MTL.mjs.map +1 -0
- package/dist/transfer-BwKpOrTV.mjs +8963 -0
- package/dist/transfer-BwKpOrTV.mjs.map +1 -0
- package/dist/transfer-CafpWTD6.mjs +166 -0
- package/dist/transfer-CafpWTD6.mjs.map +1 -0
- package/dist/transfer-download-H8beYs2r.mjs +33 -0
- package/dist/transfer-download-H8beYs2r.mjs.map +1 -0
- package/dist/transformations-DX_dwSfp.mjs +196 -0
- package/dist/transformations-DX_dwSfp.mjs.map +1 -0
- package/dist/transport-7mI_Nvnn.d.mts +42 -0
- package/dist/transport-7mI_Nvnn.d.mts.map +1 -0
- package/dist/transport-Cs1Xl7-v.mjs +144 -0
- package/dist/transport-Cs1Xl7-v.mjs.map +1 -0
- package/dist/trusted-proxy-DaSru7xW.mjs +51 -0
- package/dist/trusted-proxy-DaSru7xW.mjs.map +1 -0
- package/dist/turnstile-DNR0cwtt.mjs +58 -0
- package/dist/turnstile-DNR0cwtt.mjs.map +1 -0
- package/dist/types-8q-gxKfV.d.mts +935 -0
- package/dist/types-8q-gxKfV.d.mts.map +1 -0
- package/dist/types-BBH-w_KS.mjs.map +1 -1
- package/dist/types-BE4og6EZ.d.mts +292 -0
- package/dist/types-BE4og6EZ.d.mts.map +1 -0
- package/dist/types-BbOWBoRk.d.mts +384 -0
- package/dist/types-BbOWBoRk.d.mts.map +1 -0
- package/dist/types-BmBK2cqf.mjs.map +1 -1
- package/dist/types-C3tTVw9y.mjs +37 -0
- package/dist/types-C3tTVw9y.mjs.map +1 -0
- package/dist/types-CTQEkZcI.mjs +16 -0
- package/dist/types-CTQEkZcI.mjs.map +1 -0
- package/dist/types-CbfB5YfA.d.mts +209 -0
- package/dist/types-CbfB5YfA.d.mts.map +1 -0
- package/dist/types-CeknTiV0.d.mts +93 -0
- package/dist/types-CeknTiV0.d.mts.map +1 -0
- package/dist/types-CpFfDrGH.mjs.map +1 -1
- package/dist/types-DHjtQujX.mjs +77 -0
- package/dist/types-DHjtQujX.mjs.map +1 -0
- package/dist/types-EYyvAjNA.d.mts +125 -0
- package/dist/types-EYyvAjNA.d.mts.map +1 -0
- package/dist/types-VMZCO8hc.d.mts +366 -0
- package/dist/types-VMZCO8hc.d.mts.map +1 -0
- package/dist/types-YTpIfKXX.d.mts +1756 -0
- package/dist/types-YTpIfKXX.d.mts.map +1 -0
- package/dist/types-iSBIMGiz.d.mts +227 -0
- package/dist/types-iSBIMGiz.d.mts.map +1 -0
- package/dist/upload-attempts-ChkgAfye.mjs +32 -0
- package/dist/upload-attempts-ChkgAfye.mjs.map +1 -0
- package/dist/url-CBR5ZBBQ.mjs +87 -0
- package/dist/url-CBR5ZBBQ.mjs.map +1 -0
- package/dist/url-pattern-DViEwhDu.mjs +41 -0
- package/dist/url-pattern-DViEwhDu.mjs.map +1 -0
- package/dist/urls-BCnpTM3T.mjs +79 -0
- package/dist/urls-BCnpTM3T.mjs.map +1 -0
- package/dist/user-Cy4kOmtD.mjs +184 -0
- package/dist/user-Cy4kOmtD.mjs.map +1 -0
- package/dist/utils-0R0olFJs.d.mts +374 -0
- package/dist/utils-0R0olFJs.d.mts.map +1 -0
- package/dist/utils-DIfKXQ5o.mjs +450 -0
- package/dist/utils-DIfKXQ5o.mjs.map +1 -0
- package/dist/validate-CYHbSQ-M.d.mts +472 -0
- package/dist/validate-CYHbSQ-M.d.mts.map +1 -0
- package/dist/validate-DBnEN6hU.mjs +524 -0
- package/dist/validate-DBnEN6hU.mjs.map +1 -0
- package/dist/validation-Becbh-zl.mjs +204 -0
- package/dist/validation-Becbh-zl.mjs.map +1 -0
- package/dist/version-BE4RahxC.mjs +7 -0
- package/dist/version-BE4RahxC.mjs.map +1 -0
- package/dist/version-C3C6o1xi.mjs +9 -0
- package/dist/version-C3C6o1xi.mjs.map +1 -0
- package/dist/version-PIyVra05.mjs +49 -0
- package/dist/version-PIyVra05.mjs.map +1 -0
- package/dist/video-Cgw31pIP.mjs +18 -0
- package/dist/video-Cgw31pIP.mjs.map +1 -0
- package/dist/virtual-modules-DAvm-Tct.mjs +565 -0
- package/dist/virtual-modules-DAvm-Tct.mjs.map +1 -0
- package/dist/widgets-HYhp_QtR.mjs +134 -0
- package/dist/widgets-HYhp_QtR.mjs.map +1 -0
- package/dist/wxr-CDtij4U5.mjs +1054 -0
- package/dist/wxr-CDtij4U5.mjs.map +1 -0
- package/dist/wxr-taxonomies-fliLjgKD.mjs +735 -0
- package/dist/wxr-taxonomies-fliLjgKD.mjs.map +1 -0
- package/dist/wxr-taxonomies-uZgPVgPe.d.mts +34 -0
- package/dist/wxr-taxonomies-uZgPVgPe.d.mts.map +1 -0
- package/package.json +11 -10
- package/src/after.ts +17 -10
- package/src/api/error.ts +0 -13
- package/src/api/handlers/manifest.ts +1 -0
- package/src/api/handlers/media-allowlist.ts +66 -7
- package/src/api/handlers/media-usage.ts +2 -1
- package/src/api/handlers/media.ts +4 -2
- package/src/api/handlers/seo.ts +19 -7
- package/src/api/openapi/document.ts +1 -1
- package/src/api/schemas/auth.ts +7 -0
- package/src/api/schemas/media-usage.ts +1 -0
- package/src/api/schemas/media.ts +13 -3
- package/src/api/schemas/schema.ts +14 -0
- package/src/api/search.ts +15 -0
- package/src/api/types.ts +3 -0
- package/src/astro/image-endpoint.ts +30 -4
- package/src/astro/integration/dev-scheduler-bridge.ts +1 -2
- package/src/astro/integration/index.ts +22 -1
- package/src/astro/integration/routes.ts +4 -0
- package/src/astro/integration/virtual-modules.ts +3 -6
- package/src/astro/integration/vite-config.ts +13 -6
- package/src/astro/middleware/auth.ts +18 -11
- package/src/astro/middleware/redirect.ts +41 -23
- package/src/astro/middleware/request-context.ts +4 -2
- package/src/astro/middleware/scoped-db.ts +4 -4
- package/src/astro/middleware.ts +288 -204
- package/src/astro/prefetch.ts +21 -17
- package/src/astro/public-plugin-api-routes.ts +4 -4
- package/src/astro/routes/PluginRegistry.tsx +2 -3
- package/src/astro/routes/api/admin/byline-fields/[slug]/usage.ts +4 -3
- package/src/astro/routes/api/admin/byline-fields/[slug].ts +10 -7
- package/src/astro/routes/api/admin/byline-fields/index.ts +7 -5
- package/src/astro/routes/api/admin/byline-fields/reorder.ts +4 -3
- package/src/astro/routes/api/admin/bylines/[id]/index.ts +4 -3
- package/src/astro/routes/api/admin/bylines/[id]/translations.ts +7 -5
- package/src/astro/routes/api/admin/comments/[id]/status.ts +4 -3
- package/src/astro/routes/api/admin/comments/[id].ts +7 -5
- package/src/astro/routes/api/admin/comments/bulk.ts +4 -3
- package/src/astro/routes/api/admin/comments/counts.ts +4 -3
- package/src/astro/routes/api/admin/comments/index.ts +4 -3
- package/src/astro/routes/api/admin/media-usage/activation.ts +7 -5
- package/src/astro/routes/api/admin/media-usage/collection-deletions/index.ts +4 -3
- package/src/astro/routes/api/admin/media-usage/collection-deletions/retry.ts +4 -3
- package/src/astro/routes/api/admin/media-usage/progress.ts +7 -5
- package/src/astro/routes/api/admin/media-usage/repair.ts +4 -3
- package/src/astro/routes/api/admin/media-usage/work/index.ts +4 -3
- package/src/astro/routes/api/admin/media-usage/work/retry.ts +4 -3
- package/src/astro/routes/api/admin/plugins/registry/artifact.ts +7 -4
- package/src/astro/routes/api/admin/transfer/approvals/[id]/approve.ts +4 -3
- package/src/astro/routes/api/admin/transfer/approvals/[id]/deny.ts +4 -3
- package/src/astro/routes/api/admin/transfer/approvals/index.ts +4 -3
- package/src/astro/routes/api/admin/transfer/capabilities.ts +4 -3
- package/src/astro/routes/api/admin/transfer/exports/[id]/advance.ts +4 -3
- package/src/astro/routes/api/admin/transfer/exports/[id]/archive.ts +4 -3
- package/src/astro/routes/api/admin/transfer/exports/[id]/files/[...path].ts +4 -3
- package/src/astro/routes/api/admin/transfer/exports/[id]/index.ts +4 -3
- package/src/astro/routes/api/admin/transfer/exports/[id]/manifest.ts +4 -3
- package/src/astro/routes/api/admin/transfer/exports/index.ts +7 -5
- package/src/astro/routes/api/admin/transfer/imports/[id]/abandon.ts +4 -3
- package/src/astro/routes/api/admin/transfer/imports/[id]/advance.ts +4 -3
- package/src/astro/routes/api/admin/transfer/imports/[id]/analyze.ts +4 -3
- package/src/astro/routes/api/admin/transfer/imports/[id]/cancel.ts +4 -3
- package/src/astro/routes/api/admin/transfer/imports/[id]/execute.ts +4 -3
- package/src/astro/routes/api/admin/transfer/imports/[id]/files/[...path].ts +4 -3
- package/src/astro/routes/api/admin/transfer/imports/[id]/index.ts +4 -3
- package/src/astro/routes/api/admin/transfer/imports/[id]/missing.ts +4 -3
- package/src/astro/routes/api/admin/transfer/imports/[id]/plan.ts +4 -3
- package/src/astro/routes/api/admin/transfer/imports/[id]/receipt.ts +4 -3
- package/src/astro/routes/api/admin/transfer/imports/index.ts +7 -5
- package/src/astro/routes/api/auth/invite/complete.ts +2 -1
- package/src/astro/routes/api/auth/magic-link/verify.ts +2 -1
- package/src/astro/routes/api/auth/oauth/[provider]/callback.ts +2 -1
- package/src/astro/routes/api/auth/passkey/verify.ts +2 -1
- package/src/astro/routes/api/auth/signup/complete.ts +2 -1
- package/src/astro/routes/api/auth/signup/register-options.ts +69 -0
- package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +7 -5
- package/src/astro/routes/api/comments/[collection]/[contentId]/reactions.ts +7 -5
- package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +3 -13
- package/src/astro/routes/api/content/[collection]/[id]/duplicate.ts +3 -13
- package/src/astro/routes/api/content/[collection]/[id]/lock.ts +19 -19
- package/src/astro/routes/api/content/[collection]/[id]/publish.ts +3 -12
- package/src/astro/routes/api/content/[collection]/[id]/references/[relation]/children.ts +4 -3
- package/src/astro/routes/api/content/[collection]/[id]/references/[relation]/parents.ts +4 -3
- package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +11 -19
- package/src/astro/routes/api/content/[collection]/[id]/unpublish.ts +3 -12
- package/src/astro/routes/api/content/[collection]/[id].ts +12 -34
- package/src/astro/routes/api/import/wordpress/execute.ts +1 -4
- package/src/astro/routes/api/import/wordpress/media.ts +3 -2
- package/src/astro/routes/api/import/wordpress-plugin/execute.ts +1 -4
- package/src/astro/routes/api/media/[id]/replace.ts +11 -2
- package/src/astro/routes/api/media/[id].ts +16 -3
- package/src/astro/routes/api/media/file/[...key].ts +11 -0
- package/src/astro/routes/api/media/providers/[providerId]/[itemId].ts +18 -2
- package/src/astro/routes/api/menus/[name]/items/[id].ts +6 -0
- package/src/astro/routes/api/menus/[name]/items.ts +4 -1
- package/src/astro/routes/api/menus/[name]/reorder.ts +4 -1
- package/src/astro/routes/api/menus/[name]/translations.ts +7 -5
- package/src/astro/routes/api/menus/[name].ts +10 -1
- package/src/astro/routes/api/menus/index.ts +7 -1
- package/src/astro/routes/api/redirects/404s/index.ts +10 -7
- package/src/astro/routes/api/redirects/404s/summary.ts +4 -3
- package/src/astro/routes/api/redirects/[id].ts +10 -7
- package/src/astro/routes/api/redirects/index.ts +7 -5
- package/src/astro/routes/api/relations/[id]/index.ts +10 -7
- package/src/astro/routes/api/relations/index.ts +7 -5
- package/src/astro/routes/api/schema/block-types/[slug]/index.ts +7 -5
- package/src/astro/routes/api/schema/block-types/[slug]/versions/[version]/activate.ts +4 -3
- package/src/astro/routes/api/schema/block-types/index.ts +7 -5
- package/src/astro/routes/api/schema/collections/[slug]/fields/[fieldSlug].ts +10 -7
- package/src/astro/routes/api/schema/collections/[slug]/fields/index.ts +7 -5
- package/src/astro/routes/api/schema/collections/[slug]/fields/reorder.ts +4 -3
- package/src/astro/routes/api/schema/collections/[slug]/index.ts +10 -7
- package/src/astro/routes/api/schema/collections/index.ts +7 -5
- package/src/astro/routes/api/schema/collections/reorder.ts +4 -3
- package/src/astro/routes/api/schema/index.ts +4 -3
- package/src/astro/routes/api/schema/orphans/[slug].ts +4 -3
- package/src/astro/routes/api/schema/orphans/index.ts +4 -3
- package/src/astro/routes/api/search/enable.ts +4 -0
- package/src/astro/routes/api/search/index.ts +5 -3
- package/src/astro/routes/api/search/rebuild.ts +4 -0
- package/src/astro/routes/api/search/stats.ts +4 -0
- package/src/astro/routes/api/search/suggest.ts +4 -0
- package/src/astro/routes/api/sections/[slug].ts +10 -7
- package/src/astro/routes/api/sections/index.ts +7 -5
- package/src/astro/routes/api/setup/admin-verify.ts +2 -1
- package/src/astro/routes/api/taxonomies/[name]/reorder.ts +4 -3
- package/src/astro/routes/api/taxonomies/[name]/terms/[slug]/translations.ts +7 -5
- package/src/astro/routes/api/taxonomies/[name]/terms/[slug].ts +10 -7
- package/src/astro/routes/api/taxonomies/[name]/terms/index.ts +7 -5
- package/src/astro/routes/api/taxonomies/[name]/translations.ts +4 -3
- package/src/astro/routes/api/taxonomies/[name].ts +10 -7
- package/src/astro/routes/api/taxonomies/bulk-tag.ts +4 -3
- package/src/astro/routes/api/taxonomies/index.ts +7 -5
- package/src/astro/routes/api/widget-areas/[name]/reorder.ts +3 -0
- package/src/astro/routes/api/widget-areas/[name]/widgets/[id].ts +6 -0
- package/src/astro/routes/api/widget-areas/[name]/widgets.ts +3 -0
- package/src/astro/routes/api/widget-areas/[name].ts +6 -0
- package/src/astro/routes/api/widget-areas/index.ts +6 -0
- package/src/astro/session-user.ts +8 -4
- package/src/astro/types.ts +77 -53
- package/src/auth/start-user-session.ts +16 -0
- package/src/cleanup.ts +24 -5
- package/src/client/index.ts +5 -3
- package/src/client/portable-text.ts +9 -1
- package/src/comments/public-submission.ts +1 -1
- package/src/components/Code.astro +6 -1
- package/src/components/Comments.astro +17 -6
- package/src/components/InlinePortableTextEditor.tsx +9 -1
- package/src/database/dialect-helpers.ts +18 -3
- package/src/database/migrations/098_user_last_login.ts +13 -0
- package/src/database/migrations/runner.ts +2 -0
- package/src/database/repositories/content.ts +37 -0
- package/src/database/repositories/media-folders.ts +2 -6
- package/src/database/repositories/media.ts +16 -7
- package/src/database/repositories/revision.ts +2 -2
- package/src/database/repositories/seo.ts +34 -10
- package/src/database/repositories/types.ts +2 -2
- package/src/database/repositories/user.ts +2 -2
- package/src/database/types.ts +1 -0
- package/src/db/node-sqlite-compat.ts +13 -0
- package/src/emdash-runtime.ts +775 -308
- package/src/mcp/server.ts +27 -34
- package/src/media/image-endpoint.ts +84 -0
- package/src/media/url.ts +16 -3
- package/src/media/usage/content-fields.ts +7 -5
- package/src/media/usage/content-lock.ts +71 -0
- package/src/media/usage/content-refresh.ts +3 -72
- package/src/media/usage/content-snapshots.ts +26 -0
- package/src/media/usage/extractor.ts +132 -32
- package/src/media/usage/types.ts +3 -1
- package/src/object-cache/index.ts +16 -12
- package/src/plugins/context.ts +22 -1
- package/src/plugins/http-route-dispatch.ts +16 -8
- package/src/plugins/lifecycle.ts +16 -4
- package/src/plugins/sandbox/proxy.ts +2 -2
- package/src/plugins/scheduler/node.ts +17 -11
- package/src/plugins/state.ts +236 -78
- package/src/query.ts +36 -5
- package/src/scheduled-publish.ts +54 -6
- package/src/schema/block-type-contract.ts +35 -4
- package/src/schema/block-type-registry.ts +1 -1
- package/src/schema/types.ts +3 -0
- package/src/search/fts-manager.ts +79 -19
- package/src/search/query.ts +212 -101
- package/src/search/types.ts +6 -1
- package/src/virtual-modules.d.ts +3 -10
- package/dist/action-token-CKphU6ur.mjs +0 -26
- package/dist/action-token-CKphU6ur.mjs.map +0 -1
- package/dist/activation-X5iMalte.mjs +0 -387
- package/dist/activation-X5iMalte.mjs.map +0 -1
- package/dist/adapters-DFsc9XjW.d.mts +0 -173
- package/dist/adapters-DFsc9XjW.d.mts.map +0 -1
- package/dist/after-B3AvMfBQ.mjs +0 -50
- package/dist/after-B3AvMfBQ.mjs.map +0 -1
- package/dist/allowed-origins-BFDNF-05.mjs +0 -116
- package/dist/allowed-origins-BFDNF-05.mjs.map +0 -1
- package/dist/api-tokens-D27OQ0oQ.mjs +0 -173
- package/dist/api-tokens-D27OQ0oQ.mjs.map +0 -1
- package/dist/apply-Culv7QJl.mjs +0 -1774
- package/dist/apply-Culv7QJl.mjs.map +0 -1
- package/dist/approvals-oLE5G5jw.mjs +0 -460
- package/dist/approvals-oLE5G5jw.mjs.map +0 -1
- package/dist/artifact-fetch-ByK_1pck.mjs +0 -659
- package/dist/artifact-fetch-ByK_1pck.mjs.map +0 -1
- package/dist/artifacts-BXKMIV2F.mjs +0 -323
- package/dist/artifacts-BXKMIV2F.mjs.map +0 -1
- package/dist/authoritative-records-Cd5BVXRs.mjs +0 -5183
- package/dist/authoritative-records-Cd5BVXRs.mjs.map +0 -1
- package/dist/authorize-B-4ogCQG.mjs +0 -74
- package/dist/authorize-B-4ogCQG.mjs.map +0 -1
- package/dist/backup-BQhg3MEK.mjs +0 -246
- package/dist/backup-BQhg3MEK.mjs.map +0 -1
- package/dist/block-types-BTzqdEZV.mjs +0 -132
- package/dist/block-types-BTzqdEZV.mjs.map +0 -1
- package/dist/block-values-DzZIh7WN.mjs +0 -215
- package/dist/block-values-DzZIh7WN.mjs.map +0 -1
- package/dist/byline--sweE_MZ.mjs +0 -930
- package/dist/byline--sweE_MZ.mjs.map +0 -1
- package/dist/byline-fields-Czdq4Yad.mjs +0 -123
- package/dist/byline-fields-Czdq4Yad.mjs.map +0 -1
- package/dist/byline-registry-Cr7kjrxM.mjs +0 -406
- package/dist/byline-registry-Cr7kjrxM.mjs.map +0 -1
- package/dist/bylines-DnuH3H8z.mjs +0 -234
- package/dist/bylines-DnuH3H8z.mjs.map +0 -1
- package/dist/bylines-txlwgzIK.mjs +0 -150
- package/dist/bylines-txlwgzIK.mjs.map +0 -1
- package/dist/cache-BjnpmIpb.mjs +0 -151
- package/dist/cache-BjnpmIpb.mjs.map +0 -1
- package/dist/canonical-Cb-rJGRU.mjs +0 -174
- package/dist/canonical-Cb-rJGRU.mjs.map +0 -1
- package/dist/capture-triggers-BZmIEdX2.mjs +0 -362
- package/dist/capture-triggers-BZmIEdX2.mjs.map +0 -1
- package/dist/checksum-CH9TyM-N.mjs +0 -162
- package/dist/checksum-CH9TyM-N.mjs.map +0 -1
- package/dist/chunks-DRnEstVb.mjs +0 -25
- package/dist/chunks-DRnEstVb.mjs.map +0 -1
- package/dist/collection-slugs-cache-CYMrqHZ6.mjs +0 -91
- package/dist/collection-slugs-cache-CYMrqHZ6.mjs.map +0 -1
- package/dist/comment-BGeXmJ8F.mjs +0 -335
- package/dist/comment-BGeXmJ8F.mjs.map +0 -1
- package/dist/comment-reaction-ty-JEDYR.mjs +0 -85
- package/dist/comment-reaction-ty-JEDYR.mjs.map +0 -1
- package/dist/comments-ByrrLvZL.mjs +0 -99
- package/dist/comments-ByrrLvZL.mjs.map +0 -1
- package/dist/comments-DqhARoef.mjs +0 -195
- package/dist/comments-DqhARoef.mjs.map +0 -1
- package/dist/components-u2HE5Mu9.mjs +0 -112
- package/dist/components-u2HE5Mu9.mjs.map +0 -1
- package/dist/config-B4F2ttAZ.d.mts +0 -7230
- package/dist/config-B4F2ttAZ.d.mts.map +0 -1
- package/dist/config-BnrtMvHW.mjs +0 -228
- package/dist/config-BnrtMvHW.mjs.map +0 -1
- package/dist/config-DEse9gaE.d.mts +0 -41
- package/dist/config-DEse9gaE.d.mts.map +0 -1
- package/dist/connection-BaIVuaDX.mjs +0 -36
- package/dist/connection-BaIVuaDX.mjs.map +0 -1
- package/dist/content-Dxztag5t.mjs +0 -2270
- package/dist/content-Dxztag5t.mjs.map +0 -1
- package/dist/content-list-query-yYbBU-dB.d.mts +0 -26
- package/dist/content-list-query-yYbBU-dB.d.mts.map +0 -1
- package/dist/content-repair-2PdahlgZ.mjs +0 -443
- package/dist/content-repair-2PdahlgZ.mjs.map +0 -1
- package/dist/content-save-KMll0S7E.mjs +0 -202
- package/dist/content-save-KMll0S7E.mjs.map +0 -1
- package/dist/context-C3OZjexd.mjs +0 -2225
- package/dist/context-C3OZjexd.mjs.map +0 -1
- package/dist/credits-C8uXoWfN.mjs +0 -110
- package/dist/credits-C8uXoWfN.mjs.map +0 -1
- package/dist/cron-CrjBjDuy.mjs +0 -310
- package/dist/cron-CrjBjDuy.mjs.map +0 -1
- package/dist/default-DPoN3H5H.mjs +0 -81
- package/dist/default-DPoN3H5H.mjs.map +0 -1
- package/dist/deferred-tasks-uSx5qCFn.d.mts +0 -10
- package/dist/deferred-tasks-uSx5qCFn.d.mts.map +0 -1
- package/dist/device-flow-hT8lKWXq.mjs +0 -519
- package/dist/device-flow-hT8lKWXq.mjs.map +0 -1
- package/dist/dialect-helpers-DqUMP9fJ.mjs +0 -350
- package/dist/dialect-helpers-DqUMP9fJ.mjs.map +0 -1
- package/dist/digest-xYRiuW_E.mjs +0 -194
- package/dist/digest-xYRiuW_E.mjs.map +0 -1
- package/dist/direct-executor-CZ2SH1bq.mjs +0 -117
- package/dist/direct-executor-CZ2SH1bq.mjs.map +0 -1
- package/dist/email-console-CochjAlh.mjs +0 -50
- package/dist/email-console-CochjAlh.mjs.map +0 -1
- package/dist/email-locale-BoxaIPG8.mjs +0 -25
- package/dist/email-locale-BoxaIPG8.mjs.map +0 -1
- package/dist/email-smtp-BnHR_Ccx.mjs +0 -643
- package/dist/email-smtp-BnHR_Ccx.mjs.map +0 -1
- package/dist/emdash-runtime-CXsdCQnM.mjs +0 -5262
- package/dist/emdash-runtime-CXsdCQnM.mjs.map +0 -1
- package/dist/enrich-BReo_COC.mjs +0 -203
- package/dist/enrich-BReo_COC.mjs.map +0 -1
- package/dist/entry-lock-BfnhlRhC.mjs +0 -207
- package/dist/entry-lock-BfnhlRhC.mjs.map +0 -1
- package/dist/entry-lock-DsVhZcJN.mjs +0 -1228
- package/dist/entry-lock-DsVhZcJN.mjs.map +0 -1
- package/dist/entry-locks-D_kjygT1.mjs +0 -173
- package/dist/entry-locks-D_kjygT1.mjs.map +0 -1
- package/dist/env-types-CXI9uaMU.mjs +0 -38
- package/dist/env-types-CXI9uaMU.mjs.map +0 -1
- package/dist/error-DcDNU7hZ.mjs +0 -92
- package/dist/error-DcDNU7hZ.mjs.map +0 -1
- package/dist/errors-CJ6711al.mjs +0 -120
- package/dist/errors-CJ6711al.mjs.map +0 -1
- package/dist/errors-CwYHYcWF.mjs +0 -502
- package/dist/errors-CwYHYcWF.mjs.map +0 -1
- package/dist/fence-C3MLClBo.mjs +0 -162
- package/dist/fence-C3MLClBo.mjs.map +0 -1
- package/dist/field-defs-cache-Cpk0eFsQ.mjs +0 -79
- package/dist/field-defs-cache-Cpk0eFsQ.mjs.map +0 -1
- package/dist/field-map-6o9hPcRl.mjs +0 -84
- package/dist/field-map-6o9hPcRl.mjs.map +0 -1
- package/dist/fts-manager-B3iLXCGz.mjs +0 -500
- package/dist/fts-manager-B3iLXCGz.mjs.map +0 -1
- package/dist/gc-D24C-KP7.mjs +0 -62
- package/dist/gc-D24C-KP7.mjs.map +0 -1
- package/dist/hook-result-BU5rI-6M.d.mts +0 -31
- package/dist/hook-result-BU5rI-6M.d.mts.map +0 -1
- package/dist/hook-result-CO4E3zDv.mjs +0 -3854
- package/dist/hook-result-CO4E3zDv.mjs.map +0 -1
- package/dist/hreflang-Bzvlo9Ci.mjs +0 -105
- package/dist/hreflang-Bzvlo9Ci.mjs.map +0 -1
- package/dist/hreflang-Ds0WbBOu.d.mts +0 -51
- package/dist/hreflang-Ds0WbBOu.d.mts.map +0 -1
- package/dist/http-route-dispatch-BsjkWBZF.mjs +0 -348
- package/dist/http-route-dispatch-BsjkWBZF.mjs.map +0 -1
- package/dist/identity-CahxkBZC.mjs +0 -35
- package/dist/identity-CahxkBZC.mjs.map +0 -1
- package/dist/index-BauU0yTw.d.mts +0 -261
- package/dist/index-BauU0yTw.d.mts.map +0 -1
- package/dist/install-finalization-CIl610wT.mjs +0 -58
- package/dist/install-finalization-CIl610wT.mjs.map +0 -1
- package/dist/json-recordset-CrS6ZqMk.mjs +0 -12
- package/dist/json-recordset-CrS6ZqMk.mjs.map +0 -1
- package/dist/json-schema-CBcJlGcY.mjs +0 -15
- package/dist/json-schema-CBcJlGcY.mjs.map +0 -1
- package/dist/keys-DJ62Wt5b.mjs +0 -61
- package/dist/keys-DJ62Wt5b.mjs.map +0 -1
- package/dist/kinds-D7_f3Qu3.mjs +0 -974
- package/dist/kinds-D7_f3Qu3.mjs.map +0 -1
- package/dist/lifecycle-DPCkpFHV.mjs +0 -49
- package/dist/lifecycle-DPCkpFHV.mjs.map +0 -1
- package/dist/limits-Bv6mXNM-.mjs +0 -44
- package/dist/limits-Bv6mXNM-.mjs.map +0 -1
- package/dist/load-r9P0fsRH.mjs +0 -36
- package/dist/load-r9P0fsRH.mjs.map +0 -1
- package/dist/loader-CSEfTKzr.mjs +0 -1537
- package/dist/loader-CSEfTKzr.mjs.map +0 -1
- package/dist/loops-BxzrcxPO.mjs +0 -217
- package/dist/loops-BxzrcxPO.mjs.map +0 -1
- package/dist/manifest-builder-BLWqITXR.mjs +0 -196
- package/dist/manifest-builder-BLWqITXR.mjs.map +0 -1
- package/dist/manifest-schema-BRpk5V7x.mjs +0 -497
- package/dist/manifest-schema-BRpk5V7x.mjs.map +0 -1
- package/dist/marketplace-5YFgYPVr.mjs +0 -257
- package/dist/marketplace-5YFgYPVr.mjs.map +0 -1
- package/dist/marketplace-zPVE4UY5.mjs +0 -965
- package/dist/marketplace-zPVE4UY5.mjs.map +0 -1
- package/dist/media-C5fg1Xte.d.mts +0 -203
- package/dist/media-C5fg1Xte.d.mts.map +0 -1
- package/dist/media-CPETKjop.mjs +0 -424
- package/dist/media-CPETKjop.mjs.map +0 -1
- package/dist/media-Cid3xIHk.mjs +0 -294
- package/dist/media-Cid3xIHk.mjs.map +0 -1
- package/dist/media-DJaAAYI2.mjs +0 -2805
- package/dist/media-DJaAAYI2.mjs.map +0 -1
- package/dist/media-allowlist-B7JwNf-U.mjs +0 -75
- package/dist/media-allowlist-B7JwNf-U.mjs.map +0 -1
- package/dist/media-folders-BI7B7XUM.mjs +0 -210
- package/dist/media-folders-BI7B7XUM.mjs.map +0 -1
- package/dist/media-url-xWuPVfqO.mjs +0 -43
- package/dist/media-url-xWuPVfqO.mjs.map +0 -1
- package/dist/media-usage-SwtWPxy4.mjs +0 -282
- package/dist/media-usage-SwtWPxy4.mjs.map +0 -1
- package/dist/media-usage-activation-BTa1H4wE.mjs +0 -78
- package/dist/media-usage-activation-BTa1H4wE.mjs.map +0 -1
- package/dist/media-usage-work-BxHWfbKq.mjs +0 -1036
- package/dist/media-usage-work-BxHWfbKq.mjs.map +0 -1
- package/dist/media-usage-work-DYenZS8y.mjs +0 -151
- package/dist/media-usage-work-DYenZS8y.mjs.map +0 -1
- package/dist/menu-FtSf33fF.mjs +0 -420
- package/dist/menu-FtSf33fF.mjs.map +0 -1
- package/dist/menus--MSfZ5Eu.mjs +0 -433
- package/dist/menus--MSfZ5Eu.mjs.map +0 -1
- package/dist/menus-C8h6Jtpu.mjs +0 -92
- package/dist/menus-C8h6Jtpu.mjs.map +0 -1
- package/dist/menus-CpFAi_LK.mjs +0 -434
- package/dist/menus-CpFAi_LK.mjs.map +0 -1
- package/dist/mime-Dx6aHTsR.mjs +0 -82
- package/dist/mime-Dx6aHTsR.mjs.map +0 -1
- package/dist/node-sqlite-compat-DvYkqx7Q.mjs +0 -63
- package/dist/node-sqlite-compat-DvYkqx7Q.mjs.map +0 -1
- package/dist/oauth-authorization-CBxtOboy.mjs +0 -287
- package/dist/oauth-authorization-CBxtOboy.mjs.map +0 -1
- package/dist/oauth-clients-HLGHmHqI.mjs +0 -266
- package/dist/oauth-clients-HLGHmHqI.mjs.map +0 -1
- package/dist/oauth-state-store-B4YAveSb.mjs +0 -80
- package/dist/oauth-state-store-B4YAveSb.mjs.map +0 -1
- package/dist/oauth-user-lookup-CTYMaKlq.mjs +0 -26
- package/dist/oauth-user-lookup-CTYMaKlq.mjs.map +0 -1
- package/dist/object-cache-DeATK4vw.mjs +0 -805
- package/dist/object-cache-DeATK4vw.mjs.map +0 -1
- package/dist/options-BJZMHnpx.d.mts +0 -81
- package/dist/options-BJZMHnpx.d.mts.map +0 -1
- package/dist/parse-B1E5cdyD.mjs +0 -82
- package/dist/parse-B1E5cdyD.mjs.map +0 -1
- package/dist/parse-Clt6wmpy.d.mts +0 -178
- package/dist/parse-Clt6wmpy.d.mts.map +0 -1
- package/dist/parts-CMwESQ6e.mjs +0 -68
- package/dist/parts-CMwESQ6e.mjs.map +0 -1
- package/dist/passkey-config-DiVZI-cx.mjs +0 -46
- package/dist/passkey-config-DiVZI-cx.mjs.map +0 -1
- package/dist/paths-NrYImb_h.mjs +0 -77
- package/dist/paths-NrYImb_h.mjs.map +0 -1
- package/dist/placeholder-B0vI-EQ9.d.mts +0 -316
- package/dist/placeholder-B0vI-EQ9.d.mts.map +0 -1
- package/dist/plan-CSb3BdFS.mjs +0 -135
- package/dist/plan-CSb3BdFS.mjs.map +0 -1
- package/dist/plugin-settings-HdYYRFi3.mjs +0 -162
- package/dist/plugin-settings-HdYYRFi3.mjs.map +0 -1
- package/dist/plugins-Bc70Xs37.mjs +0 -261
- package/dist/plugins-Bc70Xs37.mjs.map +0 -1
- package/dist/policy-C-ngDrxa.mjs +0 -56
- package/dist/policy-C-ngDrxa.mjs.map +0 -1
- package/dist/portable-text-T17rOqF7.mjs +0 -454
- package/dist/portable-text-T17rOqF7.mjs.map +0 -1
- package/dist/protocol-CmSX4cXv.d.mts +0 -65
- package/dist/protocol-CmSX4cXv.d.mts.map +0 -1
- package/dist/public-plugin-api-routes-_xsWTlwE.mjs +0 -316
- package/dist/public-plugin-api-routes-_xsWTlwE.mjs.map +0 -1
- package/dist/public-submission-ui3pFYtq.mjs +0 -253
- package/dist/public-submission-ui3pFYtq.mjs.map +0 -1
- package/dist/public-url-DMRZPAiW.mjs +0 -123
- package/dist/public-url-DMRZPAiW.mjs.map +0 -1
- package/dist/query-C1K9PzUc.mjs +0 -41
- package/dist/query-C1K9PzUc.mjs.map +0 -1
- package/dist/query-DdmHrvie.mjs +0 -1201
- package/dist/query-DdmHrvie.mjs.map +0 -1
- package/dist/range-BaF0521t.mjs +0 -51
- package/dist/range-BaF0521t.mjs.map +0 -1
- package/dist/rate-limit-6MngP0_m.mjs +0 -127
- package/dist/rate-limit-6MngP0_m.mjs.map +0 -1
- package/dist/receipt-BFm5eaN7.mjs +0 -43
- package/dist/receipt-BFm5eaN7.mjs.map +0 -1
- package/dist/redirect-ChcHI1KC.mjs +0 -466
- package/dist/redirect-ChcHI1KC.mjs.map +0 -1
- package/dist/redirect-EpidEf_5.mjs +0 -19
- package/dist/redirect-EpidEf_5.mjs.map +0 -1
- package/dist/redirect-paths-B9cXh9Wv.mjs +0 -36
- package/dist/redirect-paths-B9cXh9Wv.mjs.map +0 -1
- package/dist/redirects-D3zHoxhn.mjs +0 -446
- package/dist/redirects-D3zHoxhn.mjs.map +0 -1
- package/dist/redirects-dFPJ0HrD.mjs +0 -148
- package/dist/redirects-dFPJ0HrD.mjs.map +0 -1
- package/dist/registry-CDzYrAFY.mjs +0 -6074
- package/dist/registry-CDzYrAFY.mjs.map +0 -1
- package/dist/registry-Cf9vkVxW.mjs +0 -1449
- package/dist/registry-Cf9vkVxW.mjs.map +0 -1
- package/dist/registry-mZi_lxtT.mjs +0 -755
- package/dist/registry-mZi_lxtT.mjs.map +0 -1
- package/dist/relations-Eyop_U4o.mjs +0 -798
- package/dist/relations-Eyop_U4o.mjs.map +0 -1
- package/dist/request-meta-DsSkOdO0.mjs +0 -141
- package/dist/request-meta-DsSkOdO0.mjs.map +0 -1
- package/dist/resolve-s7ANHtFx.mjs +0 -92
- package/dist/resolve-s7ANHtFx.mjs.map +0 -1
- package/dist/revision-D7EedSdU.mjs +0 -503
- package/dist/revision-D7EedSdU.mjs.map +0 -1
- package/dist/rooms-CSNLTJsG.mjs +0 -331
- package/dist/rooms-CSNLTJsG.mjs.map +0 -1
- package/dist/rooms-CVsLla78.mjs +0 -169
- package/dist/rooms-CVsLla78.mjs.map +0 -1
- package/dist/rooms-CyXG83RZ.d.mts +0 -4653
- package/dist/rooms-CyXG83RZ.d.mts.map +0 -1
- package/dist/route-cache-CBpXPq-N.mjs +0 -30
- package/dist/route-cache-CBpXPq-N.mjs.map +0 -1
- package/dist/route-wire-DKSTaEz_.mjs +0 -197
- package/dist/route-wire-DKSTaEz_.mjs.map +0 -1
- package/dist/routes-QcHRiebw.mjs +0 -272
- package/dist/routes-QcHRiebw.mjs.map +0 -1
- package/dist/runner-4BfB04Rg.mjs +0 -6950
- package/dist/runner-4BfB04Rg.mjs.map +0 -1
- package/dist/runner-CAHS_KER.d.mts +0 -79
- package/dist/runner-CAHS_KER.d.mts.map +0 -1
- package/dist/runtime-holder-0g6pqbzx.mjs +0 -36
- package/dist/runtime-holder-0g6pqbzx.mjs.map +0 -1
- package/dist/scheduler-health-C5HEg2Yl.mjs +0 -31
- package/dist/scheduler-health-C5HEg2Yl.mjs.map +0 -1
- package/dist/schema-DS7ooMmp.mjs +0 -13
- package/dist/schema-DS7ooMmp.mjs.map +0 -1
- package/dist/schema-Mjtj7n1t.mjs +0 -815
- package/dist/schema-Mjtj7n1t.mjs.map +0 -1
- package/dist/scopes-BaR6WUyq.mjs +0 -34
- package/dist/scopes-BaR6WUyq.mjs.map +0 -1
- package/dist/search-B9RFgr0N.mjs +0 -450
- package/dist/search-B9RFgr0N.mjs.map +0 -1
- package/dist/secrets-C4UrjPiG.mjs +0 -369
- package/dist/secrets-C4UrjPiG.mjs.map +0 -1
- package/dist/sections-Bfa0oF8Q.mjs +0 -129
- package/dist/sections-Bfa0oF8Q.mjs.map +0 -1
- package/dist/sections-Bn2C6we7.mjs +0 -222
- package/dist/sections-Bn2C6we7.mjs.map +0 -1
- package/dist/seo-DPW6k5_-.mjs +0 -188
- package/dist/seo-DPW6k5_-.mjs.map +0 -1
- package/dist/service-B4mHMku9.mjs +0 -150
- package/dist/service-B4mHMku9.mjs.map +0 -1
- package/dist/session-user-CF2jNfj7.mjs +0 -61
- package/dist/session-user-CF2jNfj7.mjs.map +0 -1
- package/dist/settings-4r88LLIM.mjs +0 -66
- package/dist/settings-4r88LLIM.mjs.map +0 -1
- package/dist/settings-BB2xxz3Y.mjs +0 -74
- package/dist/settings-BB2xxz3Y.mjs.map +0 -1
- package/dist/settings-BTkGl-bX.mjs +0 -413
- package/dist/settings-BTkGl-bX.mjs.map +0 -1
- package/dist/settings-y8Jx8b7g.mjs +0 -157
- package/dist/settings-y8Jx8b7g.mjs.map +0 -1
- package/dist/setup-complete-BGRiC59t.mjs +0 -65
- package/dist/setup-complete-BGRiC59t.mjs.map +0 -1
- package/dist/setup-nonce-D43FsOgZ.mjs +0 -25
- package/dist/setup-nonce-D43FsOgZ.mjs.map +0 -1
- package/dist/site-domain-CFX7g6ik.mjs +0 -131
- package/dist/site-domain-CFX7g6ik.mjs.map +0 -1
- package/dist/site-settings-C0D9fv7e.mjs +0 -50
- package/dist/site-settings-C0D9fv7e.mjs.map +0 -1
- package/dist/site-title-C0JVN6en.mjs +0 -14
- package/dist/site-title-C0JVN6en.mjs.map +0 -1
- package/dist/site-url-DzVnHJ8j.mjs +0 -45
- package/dist/site-url-DzVnHJ8j.mjs.map +0 -1
- package/dist/sitemap-name-Ja_Cvwx9.mjs +0 -26
- package/dist/sitemap-name-Ja_Cvwx9.mjs.map +0 -1
- package/dist/slug-CO2jtUda.mjs +0 -16
- package/dist/slug-CO2jtUda.mjs.map +0 -1
- package/dist/snapshot-C9OWUtFr.mjs +0 -466
- package/dist/snapshot-C9OWUtFr.mjs.map +0 -1
- package/dist/snapshot-CR5tan8p.mjs +0 -184
- package/dist/snapshot-CR5tan8p.mjs.map +0 -1
- package/dist/ssrf-Lj1KZxYt.mjs +0 -406
- package/dist/ssrf-Lj1KZxYt.mjs.map +0 -1
- package/dist/stage-ChbGIslu.mjs +0 -662
- package/dist/stage-ChbGIslu.mjs.map +0 -1
- package/dist/staged-BN8pRZwX.mjs +0 -686
- package/dist/staged-BN8pRZwX.mjs.map +0 -1
- package/dist/state-DtcE0eN3.mjs +0 -178
- package/dist/state-DtcE0eN3.mjs.map +0 -1
- package/dist/storage-query-BDUX3Cef.d.mts +0 -1608
- package/dist/storage-query-BDUX3Cef.d.mts.map +0 -1
- package/dist/tar-CAvEHFbE.mjs +0 -449
- package/dist/tar-CAvEHFbE.mjs.map +0 -1
- package/dist/target-BM_6fT9m.mjs +0 -27
- package/dist/target-BM_6fT9m.mjs.map +0 -1
- package/dist/taxonomies-BMuFLd53.mjs +0 -722
- package/dist/taxonomies-BMuFLd53.mjs.map +0 -1
- package/dist/taxonomies-ClkYcmcH.mjs +0 -937
- package/dist/taxonomies-ClkYcmcH.mjs.map +0 -1
- package/dist/taxonomy-s1GcBCRo.mjs +0 -593
- package/dist/taxonomy-s1GcBCRo.mjs.map +0 -1
- package/dist/tokens-Cpm6FIKJ.mjs +0 -171
- package/dist/tokens-Cpm6FIKJ.mjs.map +0 -1
- package/dist/transaction-SKrr6u84.mjs +0 -44
- package/dist/transaction-SKrr6u84.mjs.map +0 -1
- package/dist/transfer-B3CsI5MG.mjs +0 -8963
- package/dist/transfer-B3CsI5MG.mjs.map +0 -1
- package/dist/transfer-DqUiK3ca.mjs +0 -166
- package/dist/transfer-DqUiK3ca.mjs.map +0 -1
- package/dist/transfer-download-CWPfhL91.mjs +0 -33
- package/dist/transfer-download-CWPfhL91.mjs.map +0 -1
- package/dist/transformations-ClH4dJeM.mjs +0 -196
- package/dist/transformations-ClH4dJeM.mjs.map +0 -1
- package/dist/transport-C6Ps8ejN.mjs +0 -144
- package/dist/transport-C6Ps8ejN.mjs.map +0 -1
- package/dist/transport-D4hWYmO_.d.mts +0 -42
- package/dist/transport-D4hWYmO_.d.mts.map +0 -1
- package/dist/trusted-proxy-CWX1sqgb.mjs +0 -51
- package/dist/trusted-proxy-CWX1sqgb.mjs.map +0 -1
- package/dist/turnstile-B6zM50Mh.mjs +0 -58
- package/dist/turnstile-B6zM50Mh.mjs.map +0 -1
- package/dist/types-Ba3bWb9D.mjs +0 -37
- package/dist/types-Ba3bWb9D.mjs.map +0 -1
- package/dist/types-C0M6z2A4.mjs +0 -16
- package/dist/types-C0M6z2A4.mjs.map +0 -1
- package/dist/types-CG1dR_Cm.d.mts +0 -934
- package/dist/types-CG1dR_Cm.d.mts.map +0 -1
- package/dist/types-CImd8MBY.d.mts +0 -1756
- package/dist/types-CImd8MBY.d.mts.map +0 -1
- package/dist/types-CML-oGr6.d.mts +0 -293
- package/dist/types-CML-oGr6.d.mts.map +0 -1
- package/dist/types-CZO9f_vJ.d.mts +0 -381
- package/dist/types-CZO9f_vJ.d.mts.map +0 -1
- package/dist/types-DLKviL1s.d.mts +0 -93
- package/dist/types-DLKviL1s.d.mts.map +0 -1
- package/dist/types-Df0R58Wu.mjs +0 -77
- package/dist/types-Df0R58Wu.mjs.map +0 -1
- package/dist/types-DwNwhyWP.d.mts +0 -227
- package/dist/types-DwNwhyWP.d.mts.map +0 -1
- package/dist/types-DwZgl0Zn.d.mts +0 -366
- package/dist/types-DwZgl0Zn.d.mts.map +0 -1
- package/dist/types-Dyb_OuSw.d.mts +0 -125
- package/dist/types-Dyb_OuSw.d.mts.map +0 -1
- package/dist/types-iOnPkHRk.d.mts +0 -209
- package/dist/types-iOnPkHRk.d.mts.map +0 -1
- package/dist/upload-attempts-5Ot7-vsw.mjs +0 -32
- package/dist/upload-attempts-5Ot7-vsw.mjs.map +0 -1
- package/dist/url-ZCjpMO-q.mjs +0 -74
- package/dist/url-ZCjpMO-q.mjs.map +0 -1
- package/dist/url-pattern-BQT-sGmD.mjs +0 -41
- package/dist/url-pattern-BQT-sGmD.mjs.map +0 -1
- package/dist/urls-Cq_hUk4P.mjs +0 -79
- package/dist/urls-Cq_hUk4P.mjs.map +0 -1
- package/dist/user-C4km6fox.mjs +0 -184
- package/dist/user-C4km6fox.mjs.map +0 -1
- package/dist/utils-Cpo0_V09.d.mts +0 -374
- package/dist/utils-Cpo0_V09.d.mts.map +0 -1
- package/dist/utils-DMDmdhU3.mjs +0 -450
- package/dist/utils-DMDmdhU3.mjs.map +0 -1
- package/dist/validate-BNupiQtz.mjs +0 -524
- package/dist/validate-BNupiQtz.mjs.map +0 -1
- package/dist/validate-DBfkJa3O.d.mts +0 -472
- package/dist/validate-DBfkJa3O.d.mts.map +0 -1
- package/dist/validation-W_efZFgP.mjs +0 -204
- package/dist/validation-W_efZFgP.mjs.map +0 -1
- package/dist/version-C61rw8-y.mjs +0 -9
- package/dist/version-C61rw8-y.mjs.map +0 -1
- package/dist/version-DhGLeLRo.mjs +0 -7
- package/dist/version-DhGLeLRo.mjs.map +0 -1
- package/dist/version-eqLBDtcz.mjs +0 -49
- package/dist/version-eqLBDtcz.mjs.map +0 -1
- package/dist/video-My3h7vwE.mjs +0 -18
- package/dist/video-My3h7vwE.mjs.map +0 -1
- package/dist/virtual-modules-BZKqvjRC.mjs +0 -568
- package/dist/virtual-modules-BZKqvjRC.mjs.map +0 -1
- package/dist/widgets-DAdni19y.mjs +0 -134
- package/dist/widgets-DAdni19y.mjs.map +0 -1
- package/dist/wxr-DDPJOgkM.mjs +0 -1054
- package/dist/wxr-DDPJOgkM.mjs.map +0 -1
- package/dist/wxr-taxonomies-B0U2fJgs.mjs +0 -735
- package/dist/wxr-taxonomies-B0U2fJgs.mjs.map +0 -1
- package/dist/wxr-taxonomies-CyP2k4-Q.d.mts +0 -34
- package/dist/wxr-taxonomies-CyP2k4-Q.d.mts.map +0 -1
|
@@ -0,0 +1,2813 @@
|
|
|
1
|
+
import { t as validateIdentifier } from "./validate-DANX1-Qi.mjs";
|
|
2
|
+
import { C as textPosition, u as isPostgres } from "./dialect-helpers-DRe1Y08G.mjs";
|
|
3
|
+
import { getRequestContext } from "./request-context.mjs";
|
|
4
|
+
import { n as chunks, t as SQL_BATCH_SIZE } from "./chunks-CvgCLYip.mjs";
|
|
5
|
+
import { a as InvalidCursorError, l as decodeCursor, u as encodeCursor } from "./types-BBH-w_KS.mjs";
|
|
6
|
+
import { t as withTransaction } from "./transaction-D5Kq7MTL.mjs";
|
|
7
|
+
import { n as normalizeFocalPoint } from "./focal-point-Cup37tLI.mjs";
|
|
8
|
+
import { t as jsonTextValues } from "./json-recordset-2VNAgija.mjs";
|
|
9
|
+
import { n as MediaUsageActivationVersionMismatchError, t as MEDIA_USAGE_ACTIVATION_RUNTIME_GENERATION } from "./activation-BRmrunZ3.mjs";
|
|
10
|
+
import { sql } from "kysely";
|
|
11
|
+
import { ulid } from "ulidx";
|
|
12
|
+
|
|
13
|
+
//#region src/media/usage/projection-fingerprint.ts
|
|
14
|
+
const MEDIA_USAGE_PROJECTION_FINGERPRINT_VERSION = 1;
|
|
15
|
+
const FINGERPRINT_PREFIX = `media-usage-projection:v${MEDIA_USAGE_PROJECTION_FINGERPRINT_VERSION}:sha256:`;
|
|
16
|
+
const FINGERPRINT_PATTERN = new RegExp(`^${FINGERPRINT_PREFIX}[a-f0-9]{64}$`);
|
|
17
|
+
async function buildMediaUsageProjectionFingerprint(input) {
|
|
18
|
+
if (!input.collectionId) throw new Error("Media usage projection fingerprints require a collection identity");
|
|
19
|
+
const canonicalOccurrences = input.occurrences.map((occurrence) => ({
|
|
20
|
+
fieldSlug: occurrence.fieldSlug,
|
|
21
|
+
fieldPath: occurrence.fieldPath,
|
|
22
|
+
occurrenceIndex: occurrence.occurrenceIndex ?? 0,
|
|
23
|
+
referenceType: occurrence.referenceType,
|
|
24
|
+
mediaId: occurrence.mediaId,
|
|
25
|
+
provider: occurrence.provider,
|
|
26
|
+
providerAssetId: occurrence.providerAssetId,
|
|
27
|
+
mediaKind: occurrence.mediaKind ?? null,
|
|
28
|
+
mimeType: occurrence.mimeType ?? null
|
|
29
|
+
})).map((occurrence) => ({
|
|
30
|
+
occurrence,
|
|
31
|
+
key: canonicalJson(occurrence)
|
|
32
|
+
})).toSorted((a, b) => compareCanonicalStrings(a.key, b.key)).map(({ occurrence }) => occurrence);
|
|
33
|
+
return buildCanonicalSha256Fingerprint(FINGERPRINT_PREFIX, {
|
|
34
|
+
fingerprintVersion: MEDIA_USAGE_PROJECTION_FINGERPRINT_VERSION,
|
|
35
|
+
collectionId: input.collectionId,
|
|
36
|
+
extractionSchema: normalizeExtractionFields(input.extractionFields),
|
|
37
|
+
source: {
|
|
38
|
+
sourceKey: input.source.sourceKey,
|
|
39
|
+
sourceType: input.source.sourceType,
|
|
40
|
+
collectionSlug: input.source.collectionSlug ?? null,
|
|
41
|
+
contentId: input.source.contentId ?? null,
|
|
42
|
+
sourceVariant: input.source.sourceVariant,
|
|
43
|
+
locale: input.source.locale ?? null,
|
|
44
|
+
translationGroup: input.source.translationGroup ?? null,
|
|
45
|
+
contentSlug: input.source.contentSlug ?? null,
|
|
46
|
+
contentTitle: input.source.contentTitle ?? null,
|
|
47
|
+
contentStatus: input.source.contentStatus ?? null,
|
|
48
|
+
contentScheduledAt: input.source.contentScheduledAt ?? null,
|
|
49
|
+
contentDeletedAt: input.source.contentDeletedAt ?? null,
|
|
50
|
+
revisionId: input.source.revisionId ?? null,
|
|
51
|
+
schemaVersion: input.source.schemaVersion ?? 1,
|
|
52
|
+
sourceCompleteness: input.source.sourceCompleteness ?? "complete"
|
|
53
|
+
},
|
|
54
|
+
occurrences: canonicalOccurrences
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async function buildCanonicalSha256Fingerprint(prefix, payload) {
|
|
58
|
+
const encodedPayload = new TextEncoder().encode(canonicalJson(payload));
|
|
59
|
+
const digest = await crypto.subtle.digest("SHA-256", encodedPayload);
|
|
60
|
+
return {
|
|
61
|
+
fingerprint: `${prefix}${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("")}`,
|
|
62
|
+
byteLength: encodedPayload.byteLength
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function normalizeExtractionFields(fields) {
|
|
66
|
+
return fields.map((field) => {
|
|
67
|
+
if (field.type === "blocks") return {
|
|
68
|
+
slug: field.slug,
|
|
69
|
+
type: field.type,
|
|
70
|
+
blockTypes: (field.blockTypes ?? []).map((type) => ({
|
|
71
|
+
slug: type.slug,
|
|
72
|
+
currentVersion: type.currentVersion,
|
|
73
|
+
versions: type.versions.map((version) => ({
|
|
74
|
+
version: version.version,
|
|
75
|
+
fingerprint: version.fingerprint
|
|
76
|
+
}))
|
|
77
|
+
}))
|
|
78
|
+
};
|
|
79
|
+
if (field.type !== "repeater") return {
|
|
80
|
+
slug: field.slug,
|
|
81
|
+
type: field.type
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
slug: field.slug,
|
|
85
|
+
type: field.type,
|
|
86
|
+
subFields: (field.validation?.subFields ?? []).map((subField) => ({
|
|
87
|
+
slug: subField.slug,
|
|
88
|
+
type: subField.type
|
|
89
|
+
})).toSorted((a, b) => compareCanonicalStrings(a.slug, b.slug))
|
|
90
|
+
};
|
|
91
|
+
}).toSorted((a, b) => compareCanonicalStrings(String(a.slug), String(b.slug)));
|
|
92
|
+
}
|
|
93
|
+
function compareCanonicalStrings(a, b) {
|
|
94
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
95
|
+
}
|
|
96
|
+
function isMediaUsageProjectionFingerprint(value) {
|
|
97
|
+
return typeof value === "string" && FINGERPRINT_PATTERN.test(value);
|
|
98
|
+
}
|
|
99
|
+
function canonicalJson(value) {
|
|
100
|
+
return JSON.stringify(canonicalize(value));
|
|
101
|
+
}
|
|
102
|
+
function canonicalize(value) {
|
|
103
|
+
if (value === void 0) return null;
|
|
104
|
+
if (typeof value === "bigint") return value.toString();
|
|
105
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
106
|
+
if (Array.isArray(value)) return value.map((item) => canonicalize(item));
|
|
107
|
+
if (!isRecord(value)) return value;
|
|
108
|
+
const canonical = {};
|
|
109
|
+
for (const key of Object.keys(value).toSorted()) canonical[key] = canonicalize(value[key]);
|
|
110
|
+
return canonical;
|
|
111
|
+
}
|
|
112
|
+
function isRecord(value) {
|
|
113
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/media/usage/types.ts
|
|
118
|
+
const CONTENT_SOURCE_SCHEMA_VERSION = 2;
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/database/repositories/media-usage.ts
|
|
122
|
+
const OCCURRENCE_BIND_COLUMNS = 13;
|
|
123
|
+
const D1_MAX_BOUND_PARAMETERS = 100;
|
|
124
|
+
const MEDIA_USAGE_GENERATION_WRITE_LEASE_MS = 3600 * 1e3;
|
|
125
|
+
const OCCURRENCE_INSERT_BATCH_SIZE = Math.max(1, Math.floor(D1_MAX_BOUND_PARAMETERS / OCCURRENCE_BIND_COLUMNS));
|
|
126
|
+
function cleanupDeleteBatchSize(cleanupLease) {
|
|
127
|
+
return cleanupLease ? SQL_BATCH_SIZE - 3 : SQL_BATCH_SIZE;
|
|
128
|
+
}
|
|
129
|
+
function canIssueCleanupStatement(canIssueStatement) {
|
|
130
|
+
return canIssueStatement?.() ?? true;
|
|
131
|
+
}
|
|
132
|
+
function nullableRefMatch(left, right) {
|
|
133
|
+
const leftRef = sql.ref(left);
|
|
134
|
+
const rightRef = sql.ref(right);
|
|
135
|
+
return sql`(
|
|
136
|
+
(${leftRef} IS NULL AND ${rightRef} IS NULL)
|
|
137
|
+
OR ${leftRef} = ${rightRef}
|
|
138
|
+
)`;
|
|
139
|
+
}
|
|
140
|
+
const MAX_JSON_BIND_BYTES = 19e5;
|
|
141
|
+
const MEDIA_USAGE_EVENT_QUERY_CEILING = 900;
|
|
142
|
+
const MEDIA_USAGE_QUERY_RESERVE = 150;
|
|
143
|
+
function chunkJsonRows(rows) {
|
|
144
|
+
const batches = [];
|
|
145
|
+
let batch = [];
|
|
146
|
+
let batchBytes = 2;
|
|
147
|
+
for (const row of rows) {
|
|
148
|
+
const rowBytes = new TextEncoder().encode(JSON.stringify(row)).byteLength + (batch.length > 0 ? 1 : 0);
|
|
149
|
+
if (batch.length > 0 && batchBytes + rowBytes > MAX_JSON_BIND_BYTES) {
|
|
150
|
+
batches.push(batch);
|
|
151
|
+
batch = [];
|
|
152
|
+
batchBytes = 2;
|
|
153
|
+
}
|
|
154
|
+
batch.push(row);
|
|
155
|
+
batchBytes += rowBytes;
|
|
156
|
+
}
|
|
157
|
+
if (batch.length > 0) batches.push(batch);
|
|
158
|
+
return batches;
|
|
159
|
+
}
|
|
160
|
+
function mediaUsageQueryBudgetAllows(queries) {
|
|
161
|
+
const metrics = getRequestContext()?.metrics;
|
|
162
|
+
return !metrics || metrics.dbCount + queries + MEDIA_USAGE_QUERY_RESERVE <= MEDIA_USAGE_EVENT_QUERY_CEILING;
|
|
163
|
+
}
|
|
164
|
+
function mergeInto(target, source) {
|
|
165
|
+
for (const value of source) target.add(value);
|
|
166
|
+
}
|
|
167
|
+
function batchOccurrenceRows(prepared, now) {
|
|
168
|
+
return prepared.flatMap((item) => item.projection.occurrences.map((occurrence) => ({
|
|
169
|
+
id: ulid(),
|
|
170
|
+
source_key: item.row.source_key,
|
|
171
|
+
generation: item.generation,
|
|
172
|
+
field_slug: occurrence.fieldSlug,
|
|
173
|
+
field_path: occurrence.fieldPath,
|
|
174
|
+
occurrence_index: occurrence.occurrenceIndex ?? 0,
|
|
175
|
+
reference_type: occurrence.referenceType,
|
|
176
|
+
media_id: occurrence.mediaId,
|
|
177
|
+
provider: occurrence.provider,
|
|
178
|
+
provider_asset_id: occurrence.providerAssetId,
|
|
179
|
+
media_kind: occurrence.mediaKind ?? null,
|
|
180
|
+
mime_type: occurrence.mimeType ?? null,
|
|
181
|
+
created_at: now,
|
|
182
|
+
lease_token: item.leaseToken
|
|
183
|
+
})));
|
|
184
|
+
}
|
|
185
|
+
function cleanupDurationSeconds(value) {
|
|
186
|
+
if (!Number.isSafeInteger(value) || value < 0) throw new Error("Media usage cleanup duration must be a non-negative whole number of seconds");
|
|
187
|
+
return value;
|
|
188
|
+
}
|
|
189
|
+
const CONTENT_SOURCE_ELIGIBILITY = sql`(
|
|
190
|
+
s.source_variant = 'draft_overlay'
|
|
191
|
+
OR (
|
|
192
|
+
s.source_variant = 'columns'
|
|
193
|
+
AND (
|
|
194
|
+
s.content_status = 'published'
|
|
195
|
+
OR NOT EXISTS (
|
|
196
|
+
SELECT 1
|
|
197
|
+
FROM _emdash_media_usage_sources AS overlay
|
|
198
|
+
WHERE overlay.source_type = 'content'
|
|
199
|
+
AND overlay.collection_slug = s.collection_slug
|
|
200
|
+
AND overlay.content_id = s.content_id
|
|
201
|
+
AND overlay.source_variant = 'draft_overlay'
|
|
202
|
+
AND ${contentSourceMatchesActiveCollection("overlay", "s.collection_id")}
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
)`;
|
|
207
|
+
function contentSourceMatchesActiveCollection(source, currentCollectionId) {
|
|
208
|
+
return sql`(
|
|
209
|
+
NOT EXISTS (
|
|
210
|
+
SELECT 1
|
|
211
|
+
FROM _emdash_media_usage_activation AS activation
|
|
212
|
+
WHERE activation.task_key = 'incremental_capture'
|
|
213
|
+
AND activation.state = 'active'
|
|
214
|
+
)
|
|
215
|
+
OR (
|
|
216
|
+
${sql.ref(`${source}.collection_id`)} = ${sql.ref(currentCollectionId)}
|
|
217
|
+
AND ${sql.ref(`${source}.identity_version`)} = 1
|
|
218
|
+
)
|
|
219
|
+
)`;
|
|
220
|
+
}
|
|
221
|
+
/** Persistence-only repository for the internal media usage projection tables. */
|
|
222
|
+
var MediaUsageRepository = class {
|
|
223
|
+
constructor(db) {
|
|
224
|
+
this.db = db;
|
|
225
|
+
}
|
|
226
|
+
async replaceSource(source, occurrences) {
|
|
227
|
+
const generation = ulid();
|
|
228
|
+
if (!await this.withGenerationWriteLease(source, generation, async (leaseToken, now) => {
|
|
229
|
+
await withTransaction(this.db, async (trx) => {
|
|
230
|
+
if (!await this.lockCanonicalSourceCollection(trx, source)) throw new Error(`Media usage collection is no longer current for ${source.sourceKey}`);
|
|
231
|
+
await this.insertOccurrences(trx, source.sourceKey, generation, occurrences, now);
|
|
232
|
+
if (!await this.upsertSource(trx, source, generation, now, leaseToken)) throw new Error(`Media usage generation lease expired for ${source.sourceKey}`);
|
|
233
|
+
});
|
|
234
|
+
})) throw new Error(`Media usage collection is no longer current for ${source.sourceKey}`);
|
|
235
|
+
const replaced = await this.findSource(source.sourceKey);
|
|
236
|
+
if (!replaced) throw new Error(`Media usage source ${source.sourceKey} was not persisted`);
|
|
237
|
+
return replaced;
|
|
238
|
+
}
|
|
239
|
+
async replaceSourceIfCurrent(source, occurrences, expectedCurrentGeneration) {
|
|
240
|
+
if (expectedCurrentGeneration !== null && await this.projectionMatchesCurrentGeneration(source, expectedCurrentGeneration)) return {
|
|
241
|
+
replaced: false,
|
|
242
|
+
unchanged: true,
|
|
243
|
+
source: null
|
|
244
|
+
};
|
|
245
|
+
const generation = ulid();
|
|
246
|
+
let replaced = false;
|
|
247
|
+
await this.withGenerationWriteLease(source, generation, async (leaseToken, now) => {
|
|
248
|
+
const row = this.buildSourceRow(source, generation, now);
|
|
249
|
+
await withTransaction(this.db, async (trx) => {
|
|
250
|
+
if (!await this.lockCanonicalSourceCollection(trx, source)) return;
|
|
251
|
+
await this.insertOccurrences(trx, source.sourceKey, generation, occurrences, now);
|
|
252
|
+
if (expectedCurrentGeneration === null) {
|
|
253
|
+
replaced = await this.insertSourceIfAbsent(trx, row, leaseToken);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
replaced = await this.updateSourceIfGeneration(trx, row, expectedCurrentGeneration, leaseToken);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
return {
|
|
260
|
+
replaced,
|
|
261
|
+
unchanged: false,
|
|
262
|
+
source: replaced ? null : await this.findSource(source.sourceKey)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
async findSource(sourceKey) {
|
|
266
|
+
const row = await this.db.selectFrom("_emdash_media_usage_sources").selectAll().where("source_key", "=", sourceKey).executeTakeFirst();
|
|
267
|
+
return row ? rowToSource(row) : null;
|
|
268
|
+
}
|
|
269
|
+
async findSources(sourceKeys) {
|
|
270
|
+
const uniqueSourceKeys = [...new Set(sourceKeys)];
|
|
271
|
+
const sources = /* @__PURE__ */ new Map();
|
|
272
|
+
if (uniqueSourceKeys.length === 0) return sources;
|
|
273
|
+
for (const sourceKeyBatch of chunkJsonRows(uniqueSourceKeys)) {
|
|
274
|
+
const result = await sql`
|
|
275
|
+
WITH requested AS (${jsonTextValues(this.db, sourceKeyBatch)})
|
|
276
|
+
SELECT source.*
|
|
277
|
+
FROM _emdash_media_usage_sources AS source
|
|
278
|
+
INNER JOIN requested ON requested.value = source.source_key
|
|
279
|
+
`.execute(this.db);
|
|
280
|
+
for (const row of result.rows) {
|
|
281
|
+
const source = rowToSource(row);
|
|
282
|
+
sources.set(source.sourceKey, source);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return sources;
|
|
286
|
+
}
|
|
287
|
+
async measureSourceGenerationDeletion(sourceKey, generation, maxOccurrences) {
|
|
288
|
+
if (!Number.isSafeInteger(maxOccurrences) || maxOccurrences < 0) throw new Error("Media usage deletion measurement requires a non-negative row limit");
|
|
289
|
+
const payload = sql`
|
|
290
|
+
COALESCE(field_slug, '') || COALESCE(field_path, '') ||
|
|
291
|
+
COALESCE(reference_type, '') || COALESCE(media_id, '') ||
|
|
292
|
+
COALESCE(provider, '') || COALESCE(provider_asset_id, '') ||
|
|
293
|
+
COALESCE(media_kind, '') || COALESCE(mime_type, '')
|
|
294
|
+
`;
|
|
295
|
+
const occurrenceBytes = isPostgres(this.db) ? sql`octet_length(${payload})` : sql`length(CAST(${payload} AS BLOB))`;
|
|
296
|
+
const rows = await this.db.selectFrom("_emdash_media_usage").select(occurrenceBytes.as("occurrence_bytes")).where("source_key", "=", sourceKey).where("generation", "=", generation).limit(maxOccurrences + 1).execute();
|
|
297
|
+
return {
|
|
298
|
+
occurrenceCount: rows.length,
|
|
299
|
+
occurrenceBytes: rows.reduce((total, row) => total + Number(row.occurrence_bytes), 0),
|
|
300
|
+
exceedsOccurrenceLimit: rows.length > maxOccurrences
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
async replaceSourceIfMatching(source, occurrences, expectedSource) {
|
|
304
|
+
if (expectedSource !== null && await this.projectionMatchesExpectedSource(source, expectedSource)) return {
|
|
305
|
+
replaced: false,
|
|
306
|
+
unchanged: true,
|
|
307
|
+
source: null
|
|
308
|
+
};
|
|
309
|
+
const generation = ulid();
|
|
310
|
+
let replaced = false;
|
|
311
|
+
await this.withGenerationWriteLease(source, generation, async (leaseToken, now) => {
|
|
312
|
+
const row = this.buildSourceRow(source, generation, now);
|
|
313
|
+
await withTransaction(this.db, async (trx) => {
|
|
314
|
+
if (!await this.lockCanonicalSourceCollection(trx, source)) return;
|
|
315
|
+
await this.insertOccurrences(trx, source.sourceKey, generation, occurrences, now);
|
|
316
|
+
if (expectedSource === null) {
|
|
317
|
+
replaced = await this.insertSourceIfAbsent(trx, row, leaseToken);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
replaced = await this.updateSourceIfMatching(trx, row, expectedSource, leaseToken);
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
return {
|
|
324
|
+
replaced,
|
|
325
|
+
unchanged: false,
|
|
326
|
+
source: replaced ? null : await this.findSource(source.sourceKey)
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
async replaceNewSourcesBatch(projections) {
|
|
330
|
+
const unique = [...new Map(projections.map((projection) => [projection.source.sourceKey, projection])).values()];
|
|
331
|
+
if (unique.length === 0) return /* @__PURE__ */ new Set();
|
|
332
|
+
const collectionSlug = unique[0]?.source.collectionSlug;
|
|
333
|
+
const collectionId = unique[0]?.source.collectionId;
|
|
334
|
+
if (!collectionSlug || !collectionId) throw new Error("Canonical media usage batch requires collection identity");
|
|
335
|
+
validateIdentifier(collectionSlug, "collection slug");
|
|
336
|
+
if (unique.some((projection) => projection.source.collectionSlug !== collectionSlug || projection.source.collectionId !== collectionId)) throw new Error("Canonical media usage batch must contain one collection");
|
|
337
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
338
|
+
const expiresAt = new Date(Date.now() + MEDIA_USAGE_GENERATION_WRITE_LEASE_MS).toISOString();
|
|
339
|
+
const prepared = unique.map((projection) => {
|
|
340
|
+
const generation = ulid();
|
|
341
|
+
return {
|
|
342
|
+
projection,
|
|
343
|
+
generation,
|
|
344
|
+
leaseToken: ulid(),
|
|
345
|
+
row: this.buildSourceRow(projection.source, generation, now)
|
|
346
|
+
};
|
|
347
|
+
});
|
|
348
|
+
const sourceRows = prepared.map((item) => ({
|
|
349
|
+
...item.row,
|
|
350
|
+
lease_token: item.leaseToken
|
|
351
|
+
}));
|
|
352
|
+
const occurrenceRows = batchOccurrenceRows(prepared, now);
|
|
353
|
+
if (!mediaUsageQueryBudgetAllows(2 + chunkJsonRows(occurrenceRows).length + chunkJsonRows(sourceRows).length)) {
|
|
354
|
+
if (unique.length === 1) return /* @__PURE__ */ new Set();
|
|
355
|
+
const midpoint = Math.ceil(unique.length / 2);
|
|
356
|
+
const inserted = /* @__PURE__ */ new Set();
|
|
357
|
+
mergeInto(inserted, await this.replaceNewSourcesBatch(unique.slice(0, midpoint)));
|
|
358
|
+
mergeInto(inserted, await this.replaceNewSourcesBatch(unique.slice(midpoint)));
|
|
359
|
+
return inserted;
|
|
360
|
+
}
|
|
361
|
+
const leasesPayload = JSON.stringify(prepared.map((item) => ({
|
|
362
|
+
source_key: item.row.source_key,
|
|
363
|
+
collection_id: item.row.collection_id,
|
|
364
|
+
collection_slug: item.row.collection_slug,
|
|
365
|
+
generation: item.generation,
|
|
366
|
+
lease_token: item.leaseToken,
|
|
367
|
+
expires_at: expiresAt,
|
|
368
|
+
created_at: now
|
|
369
|
+
})));
|
|
370
|
+
const leases = this.generationWriteBatchInput(leasesPayload);
|
|
371
|
+
await sql`
|
|
372
|
+
WITH input AS (${leases})
|
|
373
|
+
INSERT INTO _emdash_media_usage_generation_writes (
|
|
374
|
+
source_key, generation, lease_token, expires_at, created_at
|
|
375
|
+
)
|
|
376
|
+
SELECT source_key, generation, lease_token, expires_at, created_at
|
|
377
|
+
FROM input
|
|
378
|
+
WHERE EXISTS (
|
|
379
|
+
SELECT 1
|
|
380
|
+
FROM _emdash_collections AS collection
|
|
381
|
+
INNER JOIN _emdash_media_usage_index_status AS status
|
|
382
|
+
ON status.collection_id = collection.id
|
|
383
|
+
AND status.scope_key = collection.slug
|
|
384
|
+
WHERE collection.id = input.collection_id
|
|
385
|
+
AND collection.slug = input.collection_slug
|
|
386
|
+
AND status.adapter_id = 'content-media'
|
|
387
|
+
AND status.scope_type = 'collection'
|
|
388
|
+
AND status.capture_state = 'active'
|
|
389
|
+
AND NOT EXISTS (
|
|
390
|
+
SELECT 1 FROM _emdash_media_usage_collection_deletions AS deletion
|
|
391
|
+
WHERE deletion.collection_id = input.collection_id
|
|
392
|
+
)
|
|
393
|
+
)
|
|
394
|
+
`.execute(this.db);
|
|
395
|
+
try {
|
|
396
|
+
await this.insertBatchOccurrences(occurrenceRows);
|
|
397
|
+
const tableName = `ec_${collectionSlug}`;
|
|
398
|
+
validateIdentifier(tableName, "content table");
|
|
399
|
+
const inserted = /* @__PURE__ */ new Set();
|
|
400
|
+
for (const sourceRowBatch of chunkJsonRows(sourceRows)) {
|
|
401
|
+
const result = await sql`
|
|
402
|
+
WITH input AS (${this.sourceBatchInput(JSON.stringify(sourceRowBatch))})
|
|
403
|
+
INSERT INTO _emdash_media_usage_sources (
|
|
404
|
+
source_key, source_type, collection_id, collection_slug, content_id,
|
|
405
|
+
source_variant, locale, translation_group, content_slug, content_title,
|
|
406
|
+
content_status, content_scheduled_at, content_deleted_at, revision_id,
|
|
407
|
+
current_generation, schema_version, source_updated_at, source_version,
|
|
408
|
+
source_fingerprint, identity_version, source_completeness,
|
|
409
|
+
last_attempted_at, last_error_code, indexed_at, updated_at
|
|
410
|
+
)
|
|
411
|
+
SELECT
|
|
412
|
+
input.source_key, input.source_type, input.collection_id, input.collection_slug,
|
|
413
|
+
input.content_id, input.source_variant, input.locale, input.translation_group,
|
|
414
|
+
input.content_slug, input.content_title, input.content_status,
|
|
415
|
+
input.content_scheduled_at, input.content_deleted_at, input.revision_id,
|
|
416
|
+
input.current_generation, input.schema_version, input.source_updated_at,
|
|
417
|
+
input.source_version, input.source_fingerprint, input.identity_version,
|
|
418
|
+
input.source_completeness, input.last_attempted_at, input.last_error_code,
|
|
419
|
+
input.indexed_at, input.updated_at
|
|
420
|
+
FROM input
|
|
421
|
+
WHERE EXISTS (
|
|
422
|
+
SELECT 1
|
|
423
|
+
FROM _emdash_media_usage_generation_writes AS writer
|
|
424
|
+
WHERE writer.source_key = input.source_key
|
|
425
|
+
AND writer.generation = input.current_generation
|
|
426
|
+
AND writer.lease_token = input.lease_token
|
|
427
|
+
AND ${this.generationWriteLeaseExpiryIsInFuture("writer.expires_at")}
|
|
428
|
+
)
|
|
429
|
+
AND EXISTS (
|
|
430
|
+
SELECT 1
|
|
431
|
+
FROM _emdash_collections AS collection
|
|
432
|
+
INNER JOIN _emdash_media_usage_index_status AS status
|
|
433
|
+
ON status.collection_id = collection.id
|
|
434
|
+
AND status.scope_key = collection.slug
|
|
435
|
+
WHERE collection.id = input.collection_id
|
|
436
|
+
AND collection.slug = input.collection_slug
|
|
437
|
+
AND status.adapter_id = 'content-media'
|
|
438
|
+
AND status.scope_type = 'collection'
|
|
439
|
+
AND status.capture_state = 'active'
|
|
440
|
+
AND NOT EXISTS (
|
|
441
|
+
SELECT 1
|
|
442
|
+
FROM _emdash_media_usage_collection_deletions AS deletion
|
|
443
|
+
WHERE deletion.collection_id = input.collection_id
|
|
444
|
+
)
|
|
445
|
+
)
|
|
446
|
+
AND EXISTS (
|
|
447
|
+
SELECT 1
|
|
448
|
+
FROM ${sql.ref(tableName)} AS content
|
|
449
|
+
WHERE content.id = input.content_id
|
|
450
|
+
AND content.version = input.source_version
|
|
451
|
+
AND content.updated_at = input.source_updated_at
|
|
452
|
+
AND (
|
|
453
|
+
(input.source_variant = 'columns' AND ${nullableRefMatch("content.live_revision_id", "input.revision_id")})
|
|
454
|
+
OR
|
|
455
|
+
(input.source_variant = 'draft_overlay' AND ${nullableRefMatch("content.draft_revision_id", "input.revision_id")})
|
|
456
|
+
)
|
|
457
|
+
)
|
|
458
|
+
ON CONFLICT (source_key) DO NOTHING
|
|
459
|
+
RETURNING source_key
|
|
460
|
+
`.execute(this.db);
|
|
461
|
+
for (const row of result.rows) inserted.add(row.source_key);
|
|
462
|
+
}
|
|
463
|
+
return inserted;
|
|
464
|
+
} finally {
|
|
465
|
+
await sql`
|
|
466
|
+
WITH input AS (${leases})
|
|
467
|
+
DELETE FROM _emdash_media_usage_generation_writes AS writer
|
|
468
|
+
WHERE EXISTS (
|
|
469
|
+
SELECT 1
|
|
470
|
+
FROM input
|
|
471
|
+
WHERE input.source_key = writer.source_key
|
|
472
|
+
AND input.generation = writer.generation
|
|
473
|
+
AND input.lease_token = writer.lease_token
|
|
474
|
+
)
|
|
475
|
+
`.execute(this.db);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
async replaceExistingSourcesBatch(projections) {
|
|
479
|
+
const unique = [...new Map(projections.map((projection) => [projection.source.sourceKey, projection])).values()];
|
|
480
|
+
if (unique.length === 0) return /* @__PURE__ */ new Set();
|
|
481
|
+
const collectionSlug = unique[0]?.source.collectionSlug;
|
|
482
|
+
const collectionId = unique[0]?.source.collectionId;
|
|
483
|
+
if (!collectionSlug || !collectionId) throw new Error("Canonical media usage batch requires collection identity");
|
|
484
|
+
validateIdentifier(collectionSlug, "collection slug");
|
|
485
|
+
if (unique.some((projection) => projection.source.collectionSlug !== collectionSlug || projection.source.collectionId !== collectionId)) throw new Error("Canonical media usage batch must contain one collection");
|
|
486
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
487
|
+
const expiresAt = new Date(Date.now() + MEDIA_USAGE_GENERATION_WRITE_LEASE_MS).toISOString();
|
|
488
|
+
const prepared = unique.map((projection) => {
|
|
489
|
+
const generation = ulid();
|
|
490
|
+
return {
|
|
491
|
+
projection,
|
|
492
|
+
generation,
|
|
493
|
+
leaseToken: ulid(),
|
|
494
|
+
row: this.buildSourceRow(projection.source, generation, now)
|
|
495
|
+
};
|
|
496
|
+
});
|
|
497
|
+
const sourceRows = prepared.map((item) => ({
|
|
498
|
+
...item.row,
|
|
499
|
+
lease_token: item.leaseToken,
|
|
500
|
+
expected_generation: item.projection.expectedSource.currentGeneration,
|
|
501
|
+
expected_collection_id: item.projection.expectedSource.collectionId,
|
|
502
|
+
expected_updated_at: item.projection.expectedSource.updatedAt,
|
|
503
|
+
expected_source_fingerprint: item.projection.expectedSource.sourceFingerprint,
|
|
504
|
+
expected_source_updated_at: item.projection.expectedSource.sourceUpdatedAt,
|
|
505
|
+
expected_source_version: item.projection.expectedSource.sourceVersion,
|
|
506
|
+
expected_identity_version: item.projection.expectedSource.identityVersion,
|
|
507
|
+
expected_revision_id: item.projection.expectedSource.revisionId,
|
|
508
|
+
expected_source_completeness: item.projection.expectedSource.sourceCompleteness,
|
|
509
|
+
expected_last_attempted_at: item.projection.expectedSource.lastAttemptedAt,
|
|
510
|
+
expected_last_error_code: item.projection.expectedSource.lastErrorCode
|
|
511
|
+
}));
|
|
512
|
+
const occurrenceRows = batchOccurrenceRows(prepared, now);
|
|
513
|
+
if (!mediaUsageQueryBudgetAllows(2 + chunkJsonRows(occurrenceRows).length + chunkJsonRows(sourceRows).length)) {
|
|
514
|
+
if (unique.length === 1) return /* @__PURE__ */ new Set();
|
|
515
|
+
const midpoint = Math.ceil(unique.length / 2);
|
|
516
|
+
const replaced = /* @__PURE__ */ new Set();
|
|
517
|
+
mergeInto(replaced, await this.replaceExistingSourcesBatch(unique.slice(0, midpoint)));
|
|
518
|
+
mergeInto(replaced, await this.replaceExistingSourcesBatch(unique.slice(midpoint)));
|
|
519
|
+
return replaced;
|
|
520
|
+
}
|
|
521
|
+
const leasesPayload = JSON.stringify(prepared.map((item) => ({
|
|
522
|
+
source_key: item.row.source_key,
|
|
523
|
+
collection_id: item.row.collection_id,
|
|
524
|
+
collection_slug: item.row.collection_slug,
|
|
525
|
+
generation: item.generation,
|
|
526
|
+
lease_token: item.leaseToken,
|
|
527
|
+
expires_at: expiresAt,
|
|
528
|
+
created_at: now
|
|
529
|
+
})));
|
|
530
|
+
const leases = this.generationWriteBatchInput(leasesPayload);
|
|
531
|
+
await sql`
|
|
532
|
+
WITH input AS (${leases})
|
|
533
|
+
INSERT INTO _emdash_media_usage_generation_writes (
|
|
534
|
+
source_key, generation, lease_token, expires_at, created_at
|
|
535
|
+
)
|
|
536
|
+
SELECT source_key, generation, lease_token, expires_at, created_at
|
|
537
|
+
FROM input
|
|
538
|
+
WHERE EXISTS (
|
|
539
|
+
SELECT 1
|
|
540
|
+
FROM _emdash_collections AS collection
|
|
541
|
+
INNER JOIN _emdash_media_usage_index_status AS status
|
|
542
|
+
ON status.collection_id = collection.id
|
|
543
|
+
AND status.scope_key = collection.slug
|
|
544
|
+
WHERE collection.id = input.collection_id
|
|
545
|
+
AND collection.slug = input.collection_slug
|
|
546
|
+
AND status.adapter_id = 'content-media'
|
|
547
|
+
AND status.scope_type = 'collection'
|
|
548
|
+
AND status.capture_state = 'active'
|
|
549
|
+
AND NOT EXISTS (
|
|
550
|
+
SELECT 1 FROM _emdash_media_usage_collection_deletions AS deletion
|
|
551
|
+
WHERE deletion.collection_id = input.collection_id
|
|
552
|
+
)
|
|
553
|
+
)
|
|
554
|
+
`.execute(this.db);
|
|
555
|
+
try {
|
|
556
|
+
await this.insertBatchOccurrences(occurrenceRows);
|
|
557
|
+
const tableName = `ec_${collectionSlug}`;
|
|
558
|
+
validateIdentifier(tableName, "content table");
|
|
559
|
+
const replaced = /* @__PURE__ */ new Set();
|
|
560
|
+
for (const sourceRowBatch of chunkJsonRows(sourceRows)) {
|
|
561
|
+
const result = await sql`
|
|
562
|
+
WITH input AS (${this.sourceBatchInput(JSON.stringify(sourceRowBatch))})
|
|
563
|
+
UPDATE _emdash_media_usage_sources AS source
|
|
564
|
+
SET source_type = input.source_type,
|
|
565
|
+
collection_id = input.collection_id,
|
|
566
|
+
collection_slug = input.collection_slug,
|
|
567
|
+
content_id = input.content_id,
|
|
568
|
+
source_variant = input.source_variant,
|
|
569
|
+
locale = input.locale,
|
|
570
|
+
translation_group = input.translation_group,
|
|
571
|
+
content_slug = input.content_slug,
|
|
572
|
+
content_title = input.content_title,
|
|
573
|
+
content_status = input.content_status,
|
|
574
|
+
content_scheduled_at = input.content_scheduled_at,
|
|
575
|
+
content_deleted_at = input.content_deleted_at,
|
|
576
|
+
revision_id = input.revision_id,
|
|
577
|
+
current_generation = input.current_generation,
|
|
578
|
+
schema_version = input.schema_version,
|
|
579
|
+
source_updated_at = input.source_updated_at,
|
|
580
|
+
source_version = input.source_version,
|
|
581
|
+
source_fingerprint = input.source_fingerprint,
|
|
582
|
+
identity_version = input.identity_version,
|
|
583
|
+
source_completeness = input.source_completeness,
|
|
584
|
+
last_attempted_at = input.last_attempted_at,
|
|
585
|
+
last_error_code = input.last_error_code,
|
|
586
|
+
indexed_at = input.indexed_at,
|
|
587
|
+
updated_at = input.updated_at
|
|
588
|
+
FROM input
|
|
589
|
+
WHERE source.source_key = input.source_key
|
|
590
|
+
AND source.current_generation = input.expected_generation
|
|
591
|
+
AND ${this.batchRefsMatch("source.collection_id", "input.expected_collection_id")}
|
|
592
|
+
AND source.updated_at = input.expected_updated_at
|
|
593
|
+
AND ${this.batchRefsMatch("source.source_fingerprint", "input.expected_source_fingerprint")}
|
|
594
|
+
AND ${this.batchRefsMatch("source.source_updated_at", "input.expected_source_updated_at")}
|
|
595
|
+
AND ${this.batchRefsMatch("source.source_version", "input.expected_source_version")}
|
|
596
|
+
AND ${this.batchRefsMatch("source.identity_version", "input.expected_identity_version")}
|
|
597
|
+
AND ${this.batchRefsMatch("source.revision_id", "input.expected_revision_id")}
|
|
598
|
+
AND source.source_completeness = input.expected_source_completeness
|
|
599
|
+
AND ${this.batchRefsMatch("source.last_attempted_at", "input.expected_last_attempted_at")}
|
|
600
|
+
AND ${this.batchRefsMatch("source.last_error_code", "input.expected_last_error_code")}
|
|
601
|
+
AND EXISTS (
|
|
602
|
+
SELECT 1
|
|
603
|
+
FROM _emdash_media_usage_generation_writes AS writer
|
|
604
|
+
WHERE writer.source_key = input.source_key
|
|
605
|
+
AND writer.generation = input.current_generation
|
|
606
|
+
AND writer.lease_token = input.lease_token
|
|
607
|
+
AND ${this.generationWriteLeaseExpiryIsInFuture("writer.expires_at")}
|
|
608
|
+
)
|
|
609
|
+
AND EXISTS (
|
|
610
|
+
SELECT 1
|
|
611
|
+
FROM _emdash_collections AS collection
|
|
612
|
+
INNER JOIN _emdash_media_usage_index_status AS status
|
|
613
|
+
ON status.collection_id = collection.id
|
|
614
|
+
AND status.scope_key = collection.slug
|
|
615
|
+
WHERE collection.id = input.collection_id
|
|
616
|
+
AND collection.slug = input.collection_slug
|
|
617
|
+
AND status.adapter_id = 'content-media'
|
|
618
|
+
AND status.scope_type = 'collection'
|
|
619
|
+
AND status.capture_state = 'active'
|
|
620
|
+
AND NOT EXISTS (
|
|
621
|
+
SELECT 1
|
|
622
|
+
FROM _emdash_media_usage_collection_deletions AS deletion
|
|
623
|
+
WHERE deletion.collection_id = input.collection_id
|
|
624
|
+
)
|
|
625
|
+
)
|
|
626
|
+
AND EXISTS (
|
|
627
|
+
SELECT 1
|
|
628
|
+
FROM ${sql.ref(tableName)} AS content
|
|
629
|
+
WHERE content.id = input.content_id
|
|
630
|
+
AND content.version = input.source_version
|
|
631
|
+
AND content.updated_at = input.source_updated_at
|
|
632
|
+
AND (
|
|
633
|
+
(input.source_variant = 'columns' AND ${nullableRefMatch("content.live_revision_id", "input.revision_id")})
|
|
634
|
+
OR
|
|
635
|
+
(input.source_variant = 'draft_overlay' AND ${nullableRefMatch("content.draft_revision_id", "input.revision_id")})
|
|
636
|
+
)
|
|
637
|
+
)
|
|
638
|
+
RETURNING ${isPostgres(this.db) ? sql`source.source_key` : sql`source_key`} AS source_key
|
|
639
|
+
`.execute(this.db);
|
|
640
|
+
for (const row of result.rows) replaced.add(row.source_key);
|
|
641
|
+
}
|
|
642
|
+
return replaced;
|
|
643
|
+
} finally {
|
|
644
|
+
await sql`
|
|
645
|
+
WITH input AS (${leases})
|
|
646
|
+
DELETE FROM _emdash_media_usage_generation_writes AS writer
|
|
647
|
+
WHERE EXISTS (
|
|
648
|
+
SELECT 1
|
|
649
|
+
FROM input
|
|
650
|
+
WHERE input.source_key = writer.source_key
|
|
651
|
+
AND input.generation = writer.generation
|
|
652
|
+
AND input.lease_token = writer.lease_token
|
|
653
|
+
)
|
|
654
|
+
`.execute(this.db);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
async matchingExistingSourcesBatch(projections) {
|
|
658
|
+
if (projections.length === 0) return /* @__PURE__ */ new Set();
|
|
659
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
660
|
+
const rows = projections.map((projection) => ({
|
|
661
|
+
...this.buildSourceRow(projection.source, projection.expectedSource.currentGeneration, now),
|
|
662
|
+
expected_generation: projection.expectedSource.currentGeneration,
|
|
663
|
+
expected_collection_id: projection.expectedSource.collectionId,
|
|
664
|
+
expected_updated_at: projection.expectedSource.updatedAt,
|
|
665
|
+
expected_source_fingerprint: projection.expectedSource.sourceFingerprint,
|
|
666
|
+
expected_source_updated_at: projection.expectedSource.sourceUpdatedAt,
|
|
667
|
+
expected_source_version: projection.expectedSource.sourceVersion,
|
|
668
|
+
expected_identity_version: projection.expectedSource.identityVersion,
|
|
669
|
+
expected_revision_id: projection.expectedSource.revisionId,
|
|
670
|
+
expected_source_completeness: projection.expectedSource.sourceCompleteness,
|
|
671
|
+
expected_last_attempted_at: projection.expectedSource.lastAttemptedAt,
|
|
672
|
+
expected_last_error_code: projection.expectedSource.lastErrorCode
|
|
673
|
+
}));
|
|
674
|
+
if (!mediaUsageQueryBudgetAllows(chunkJsonRows(rows).length)) {
|
|
675
|
+
if (projections.length === 1) return /* @__PURE__ */ new Set();
|
|
676
|
+
const midpoint = Math.ceil(projections.length / 2);
|
|
677
|
+
const matched = /* @__PURE__ */ new Set();
|
|
678
|
+
mergeInto(matched, await this.matchingExistingSourcesBatch(projections.slice(0, midpoint)));
|
|
679
|
+
mergeInto(matched, await this.matchingExistingSourcesBatch(projections.slice(midpoint)));
|
|
680
|
+
return matched;
|
|
681
|
+
}
|
|
682
|
+
const matched = /* @__PURE__ */ new Set();
|
|
683
|
+
for (const batch of chunkJsonRows(rows)) {
|
|
684
|
+
const result = await sql`
|
|
685
|
+
WITH input AS (${this.sourceBatchInput(JSON.stringify(batch))})
|
|
686
|
+
SELECT source.source_key
|
|
687
|
+
FROM _emdash_media_usage_sources AS source
|
|
688
|
+
INNER JOIN input ON input.source_key = source.source_key
|
|
689
|
+
WHERE source.current_generation = input.expected_generation
|
|
690
|
+
AND ${this.batchRefsMatch("source.collection_id", "input.expected_collection_id")}
|
|
691
|
+
AND source.updated_at = input.expected_updated_at
|
|
692
|
+
AND ${this.batchRefsMatch("source.source_fingerprint", "input.expected_source_fingerprint")}
|
|
693
|
+
AND ${this.batchRefsMatch("source.source_updated_at", "input.expected_source_updated_at")}
|
|
694
|
+
AND ${this.batchRefsMatch("source.source_version", "input.expected_source_version")}
|
|
695
|
+
AND ${this.batchRefsMatch("source.identity_version", "input.expected_identity_version")}
|
|
696
|
+
AND ${this.batchRefsMatch("source.revision_id", "input.expected_revision_id")}
|
|
697
|
+
AND source.source_completeness = input.expected_source_completeness
|
|
698
|
+
AND ${this.batchRefsMatch("source.last_attempted_at", "input.expected_last_attempted_at")}
|
|
699
|
+
AND ${this.batchRefsMatch("source.last_error_code", "input.expected_last_error_code")}
|
|
700
|
+
AND EXISTS (
|
|
701
|
+
SELECT 1
|
|
702
|
+
FROM _emdash_collections AS collection
|
|
703
|
+
WHERE collection.id = source.collection_id
|
|
704
|
+
AND collection.slug = source.collection_slug
|
|
705
|
+
)
|
|
706
|
+
`.execute(this.db);
|
|
707
|
+
for (const row of result.rows) matched.add(row.source_key);
|
|
708
|
+
}
|
|
709
|
+
return matched;
|
|
710
|
+
}
|
|
711
|
+
async markSourceAttempted(source) {
|
|
712
|
+
if (source.collectionId !== void 0 && source.collectionId !== null) {
|
|
713
|
+
const expectedSource = await this.findSource(source.sourceKey);
|
|
714
|
+
if (!(await this.markSourceAttemptedIfMatching(source, expectedSource)).attempted) throw new Error(`Canonical media usage source ${source.sourceKey} is no longer current`);
|
|
715
|
+
const attempted = await this.findSource(source.sourceKey);
|
|
716
|
+
if (!attempted) throw new Error(`Media usage source ${source.sourceKey} was not persisted`);
|
|
717
|
+
return attempted;
|
|
718
|
+
}
|
|
719
|
+
const generation = ulid();
|
|
720
|
+
await this.withGenerationWriteLease(source, generation, async (leaseToken, now) => {
|
|
721
|
+
const row = this.buildAttemptedSourceRow(source, generation, now);
|
|
722
|
+
const updates = this.attemptedSourceUpdateSet(source, row);
|
|
723
|
+
if (((await this.db.insertInto("_emdash_media_usage_sources").values(row).onConflict((oc) => oc.column("source_key").doUpdateSet(updates)).executeTakeFirst()).numInsertedOrUpdatedRows ?? 0n) <= 0n) throw new Error(`Media usage generation lease expired for ${source.sourceKey}`);
|
|
724
|
+
});
|
|
725
|
+
const attempted = await this.findSource(source.sourceKey);
|
|
726
|
+
if (!attempted) throw new Error(`Media usage source ${source.sourceKey} was not persisted`);
|
|
727
|
+
return attempted;
|
|
728
|
+
}
|
|
729
|
+
async markSourceAttemptedIfMatching(source, expectedSource) {
|
|
730
|
+
const generation = ulid();
|
|
731
|
+
let attempted = false;
|
|
732
|
+
if (expectedSource === null) await this.withGenerationWriteLease(source, generation, async (leaseToken, now) => {
|
|
733
|
+
const row = this.buildAttemptedSourceRow(source, generation, now);
|
|
734
|
+
await withTransaction(this.db, async (trx) => {
|
|
735
|
+
if (!await this.lockCanonicalSourceCollection(trx, source)) return;
|
|
736
|
+
attempted = await this.persistSourceIfWriteLease(trx, row, leaseToken, sql`ON CONFLICT (source_key) DO NOTHING`);
|
|
737
|
+
});
|
|
738
|
+
});
|
|
739
|
+
else {
|
|
740
|
+
const row = this.buildAttemptedSourceRow(source, generation, (/* @__PURE__ */ new Date()).toISOString());
|
|
741
|
+
await withTransaction(this.db, async (trx) => {
|
|
742
|
+
if (!await this.lockCanonicalSourceCollection(trx, source)) return;
|
|
743
|
+
attempted = await this.updateAttemptedSourceIfMatching(trx, source, row, expectedSource);
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
return {
|
|
747
|
+
attempted,
|
|
748
|
+
source: attempted ? null : await this.findSource(source.sourceKey)
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
async findActiveEntryCountsByMediaIds(mediaIds) {
|
|
752
|
+
const uniqueMediaIds = [...new Set(mediaIds)];
|
|
753
|
+
const counts = new Map(uniqueMediaIds.map((mediaId) => [mediaId, 0]));
|
|
754
|
+
for (const mediaIdBatch of chunks(uniqueMediaIds, SQL_BATCH_SIZE)) {
|
|
755
|
+
const visibleEntries = this.currentContentMediaUsageBaseQuery().select([
|
|
756
|
+
"u.media_id as media_id",
|
|
757
|
+
"s.collection_slug as collection_slug",
|
|
758
|
+
"s.content_id as content_id"
|
|
759
|
+
]).where("u.media_id", "in", mediaIdBatch).where((eb) => eb.not(eb.exists(eb.selectFrom("_emdash_media_usage_sources as deleted_source").select("deleted_source.source_key").where("deleted_source.source_type", "=", "content").whereRef("deleted_source.collection_slug", "=", "s.collection_slug").whereRef("deleted_source.content_id", "=", "s.content_id").where("deleted_source.source_variant", "in", ["columns", "draft_overlay"]).where(contentSourceMatchesActiveCollection("deleted_source", "collection.id")).where("deleted_source.content_deleted_at", "is not", null)))).distinct().as("visible_entries");
|
|
760
|
+
const rows = await this.db.selectFrom(visibleEntries).select("media_id").select((eb) => eb.fn.countAll().as("usage_count")).groupBy("media_id").execute();
|
|
761
|
+
for (const row of rows) if (row.media_id !== null) counts.set(row.media_id, Number(row.usage_count));
|
|
762
|
+
}
|
|
763
|
+
return counts;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Read collection index status and the named options in one statement.
|
|
767
|
+
* The one-row anchor keeps the option values readable on a site with no
|
|
768
|
+
* collections.
|
|
769
|
+
*/
|
|
770
|
+
async findCoverageWithOptions(identity, optionNames) {
|
|
771
|
+
let query = this.db.selectFrom(this.db.selectNoFrom(sql`1`.as("anchor")).as("anchor")).leftJoin("_emdash_collections as collection", (join) => join.on(sql`1 = 1`)).leftJoin("_emdash_media_usage_index_status as status", (join) => join.on("status.adapter_id", "=", identity.adapterId).on("status.scope_type", "=", identity.scopeType).onRef("status.scope_key", "=", "collection.slug")).select([
|
|
772
|
+
"collection.slug as collection_slug",
|
|
773
|
+
"status.status as status",
|
|
774
|
+
"status.schema_version as schema_version",
|
|
775
|
+
"status.reconciliation_required as reconciliation_required"
|
|
776
|
+
]).orderBy("collection.slug", "asc");
|
|
777
|
+
const optionAliases = optionNames.map((name, index) => [name, `option_${index}`]);
|
|
778
|
+
for (const [name, alias] of optionAliases) query = query.select((eb) => eb.selectFrom("options").select("value").where("name", "=", name).as(alias));
|
|
779
|
+
const rows = await query.execute();
|
|
780
|
+
const scopes = [];
|
|
781
|
+
for (const row of rows) {
|
|
782
|
+
if (typeof row.collection_slug !== "string") continue;
|
|
783
|
+
scopes.push({
|
|
784
|
+
collectionSlug: row.collection_slug,
|
|
785
|
+
status: typeof row.status === "string" ? row.status : null,
|
|
786
|
+
schemaVersion: row.schema_version == null ? null : Number(row.schema_version),
|
|
787
|
+
reconciliationRequired: row.reconciliation_required != null && Number(row.reconciliation_required) !== 0
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
const firstRow = rows[0];
|
|
791
|
+
const options = /* @__PURE__ */ new Map();
|
|
792
|
+
for (const [name, alias] of optionAliases) {
|
|
793
|
+
const value = firstRow?.[alias];
|
|
794
|
+
options.set(name, typeof value === "string" ? value : null);
|
|
795
|
+
}
|
|
796
|
+
return {
|
|
797
|
+
scopes,
|
|
798
|
+
options
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
async findCollectionProgress() {
|
|
802
|
+
const row = (await sql`
|
|
803
|
+
WITH collection_progress AS (
|
|
804
|
+
SELECT
|
|
805
|
+
CASE WHEN status.status = 'complete'
|
|
806
|
+
AND status.schema_version = ${CONTENT_SOURCE_SCHEMA_VERSION}
|
|
807
|
+
AND status.reconciliation_required = 0
|
|
808
|
+
AND status.capture_state = 'active'
|
|
809
|
+
AND NOT EXISTS (
|
|
810
|
+
SELECT 1 FROM _emdash_media_usage_work AS work
|
|
811
|
+
WHERE work.collection_id = collection.id
|
|
812
|
+
AND work.collection_slug = collection.slug
|
|
813
|
+
)
|
|
814
|
+
THEN 1 ELSE 0 END AS is_ready,
|
|
815
|
+
CASE WHEN status.collection_id IS NULL
|
|
816
|
+
OR COALESCE(status.capture_state, '') <> 'active'
|
|
817
|
+
OR status.status NOT IN ('complete', 'never', 'running', 'partial', 'failed', 'stale')
|
|
818
|
+
OR status.status = 'failed'
|
|
819
|
+
OR (
|
|
820
|
+
status.reconciliation_required = 0
|
|
821
|
+
AND (
|
|
822
|
+
status.status <> 'complete'
|
|
823
|
+
OR COALESCE(status.schema_version, -1) <> ${CONTENT_SOURCE_SCHEMA_VERSION}
|
|
824
|
+
)
|
|
825
|
+
AND NOT EXISTS (
|
|
826
|
+
SELECT 1 FROM _emdash_media_usage_work AS work
|
|
827
|
+
WHERE work.collection_id = collection.id
|
|
828
|
+
AND work.collection_slug = collection.slug
|
|
829
|
+
)
|
|
830
|
+
)
|
|
831
|
+
OR EXISTS (
|
|
832
|
+
SELECT 1 FROM _emdash_media_usage_work AS work
|
|
833
|
+
WHERE work.collection_id = collection.id
|
|
834
|
+
AND work.collection_slug = collection.slug
|
|
835
|
+
AND work.state = 'failed'
|
|
836
|
+
)
|
|
837
|
+
OR EXISTS (
|
|
838
|
+
SELECT 1 FROM _emdash_media_usage_reconciliations AS reconciliation
|
|
839
|
+
WHERE reconciliation.collection_id = collection.id
|
|
840
|
+
AND reconciliation.collection_slug = collection.slug
|
|
841
|
+
AND reconciliation.state = 'failed'
|
|
842
|
+
AND status.reconciliation_required = 1
|
|
843
|
+
AND (
|
|
844
|
+
reconciliation.target_epoch IS NULL
|
|
845
|
+
OR reconciliation.target_epoch >= status.change_epoch
|
|
846
|
+
)
|
|
847
|
+
)
|
|
848
|
+
THEN 1 ELSE 0 END AS needs_attention
|
|
849
|
+
FROM _emdash_collections AS collection
|
|
850
|
+
LEFT JOIN _emdash_media_usage_index_status AS status
|
|
851
|
+
ON status.adapter_id = 'content-media'
|
|
852
|
+
AND status.scope_type = 'collection'
|
|
853
|
+
AND status.collection_id = collection.id
|
|
854
|
+
AND status.scope_key = collection.slug
|
|
855
|
+
WHERE NOT EXISTS (
|
|
856
|
+
SELECT 1 FROM _emdash_media_usage_collection_deletions AS deletion
|
|
857
|
+
WHERE deletion.collection_id = collection.id
|
|
858
|
+
AND deletion.collection_slug = collection.slug
|
|
859
|
+
)
|
|
860
|
+
)
|
|
861
|
+
SELECT
|
|
862
|
+
(
|
|
863
|
+
SELECT activation.runtime_generation
|
|
864
|
+
FROM _emdash_media_usage_activation AS activation
|
|
865
|
+
WHERE activation.task_key = 'incremental_capture'
|
|
866
|
+
) AS activation_generation,
|
|
867
|
+
EXISTS (
|
|
868
|
+
SELECT 1 FROM _emdash_media_usage_activation AS activation
|
|
869
|
+
WHERE activation.task_key = 'incremental_capture'
|
|
870
|
+
AND activation.state = 'active'
|
|
871
|
+
) AS activation_active,
|
|
872
|
+
COUNT(*) AS total_collections,
|
|
873
|
+
COALESCE(SUM(is_ready), 0) AS ready_collections,
|
|
874
|
+
EXISTS (
|
|
875
|
+
SELECT 1 FROM _emdash_media_usage_collection_deletions AS deletion
|
|
876
|
+
WHERE deletion.state IN ('pending', 'retry', 'leased')
|
|
877
|
+
) AS cleanup_pending,
|
|
878
|
+
CASE WHEN COALESCE(MAX(needs_attention), 0) = 1 OR EXISTS (
|
|
879
|
+
SELECT 1 FROM _emdash_media_usage_collection_deletions AS deletion
|
|
880
|
+
WHERE deletion.state = 'failed'
|
|
881
|
+
) THEN 1 ELSE 0 END AS needs_attention
|
|
882
|
+
FROM collection_progress
|
|
883
|
+
`.execute(this.db)).rows[0];
|
|
884
|
+
if (!row) throw new Error("Media usage progress query returned no result");
|
|
885
|
+
if (!row.activation_active) return null;
|
|
886
|
+
if (Number(row.activation_generation) !== MEDIA_USAGE_ACTIVATION_RUNTIME_GENERATION) throw new MediaUsageActivationVersionMismatchError("Media usage activation runtime generation is incompatible");
|
|
887
|
+
const readyCollections = Number(row.ready_collections);
|
|
888
|
+
const totalCollections = Number(row.total_collections);
|
|
889
|
+
const cleanupPending = Number(row.cleanup_pending);
|
|
890
|
+
const needsAttention = Number(row.needs_attention);
|
|
891
|
+
if (!Number.isSafeInteger(readyCollections) || !Number.isSafeInteger(totalCollections) || readyCollections < 0 || totalCollections < readyCollections || cleanupPending !== 0 && cleanupPending !== 1 || needsAttention !== 0 && needsAttention !== 1) throw new Error("Media usage progress query returned invalid counts");
|
|
892
|
+
return {
|
|
893
|
+
status: needsAttention ? "needs_attention" : readyCollections === totalCollections && cleanupPending === 0 ? "ready" : "indexing",
|
|
894
|
+
readyCollections,
|
|
895
|
+
totalCollections
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
async findCurrentEntryUsagePageByMediaId(mediaId, options = {}) {
|
|
899
|
+
const requestedLimit = Math.floor(options.limit ?? 50);
|
|
900
|
+
const limit = Number.isFinite(requestedLimit) ? Math.min(Math.max(1, requestedLimit), 100) : 50;
|
|
901
|
+
const cursor = options.cursor ? decodeCursor(options.cursor) : null;
|
|
902
|
+
if (cursor && (cursor.orderValue.length === 0 || cursor.id.length === 0)) throw new InvalidCursorError(options.cursor ?? "");
|
|
903
|
+
let matchedGroups = this.currentContentMediaUsageBaseQuery().select([
|
|
904
|
+
"collection.id as collection_id",
|
|
905
|
+
"s.collection_slug as collection_slug",
|
|
906
|
+
"s.content_id as content_id"
|
|
907
|
+
]).where("u.media_id", "=", mediaId).distinct();
|
|
908
|
+
if (cursor) matchedGroups = matchedGroups.where((eb) => eb.or([eb("s.collection_slug", ">", cursor.orderValue), eb.and([eb("s.collection_slug", "=", cursor.orderValue), eb("s.content_id", ">", cursor.id)])]));
|
|
909
|
+
matchedGroups = matchedGroups.orderBy("s.collection_slug", "asc").orderBy("s.content_id", "asc").limit(limit + 1);
|
|
910
|
+
const rows = await this.db.with("matched_groups", () => matchedGroups).with("page_groups", (db) => db.selectFrom("matched_groups").selectAll().orderBy("collection_slug", "asc").orderBy("content_id", "asc").limit(limit)).with("entry_state", (db) => db.selectFrom("page_groups as page").crossJoin("_emdash_media_usage_sources as state").select([
|
|
911
|
+
"page.collection_id",
|
|
912
|
+
"page.collection_slug",
|
|
913
|
+
"page.content_id"
|
|
914
|
+
]).select((eb) => eb.fn.max("state.content_deleted_at").as("entry_deleted_at")).whereRef("page.collection_slug", "=", "state.collection_slug").whereRef("page.content_id", "=", "state.content_id").where("state.source_type", "=", "content").where("state.source_variant", "in", ["columns", "draft_overlay"]).where(contentSourceMatchesActiveCollection("state", "page.collection_id")).groupBy([
|
|
915
|
+
"page.collection_id",
|
|
916
|
+
"page.collection_slug",
|
|
917
|
+
"page.content_id"
|
|
918
|
+
])).selectFrom("entry_state as page").crossJoin("_emdash_media_usage_sources as s").crossJoin("_emdash_media_usage as u").whereRef("page.collection_slug", "=", "s.collection_slug").whereRef("page.content_id", "=", "s.content_id").where(contentSourceMatchesActiveCollection("s", "page.collection_id")).whereRef("s.source_key", "=", "u.source_key").whereRef("s.current_generation", "=", "u.generation").select(currentUsageSelect).select("page.entry_deleted_at").select(sql`CASE
|
|
919
|
+
WHEN (SELECT COUNT(*) FROM matched_groups) > ${limit} THEN 1
|
|
920
|
+
ELSE 0
|
|
921
|
+
END`.as("has_more")).where("u.media_id", "=", mediaId).where("s.source_type", "=", "content").where("s.collection_slug", "is not", null).where("s.content_id", "is not", null).where("s.source_variant", "in", ["columns", "draft_overlay"]).where(CONTENT_SOURCE_ELIGIBILITY).orderBy("s.collection_slug", "asc").orderBy("s.content_id", "asc").orderBy("s.source_variant", "asc").orderBy("s.source_key", "asc").orderBy("u.field_path", "asc").orderBy("u.occurrence_index", "asc").orderBy("u.id", "asc").execute();
|
|
922
|
+
const items = groupUsageRows(rows);
|
|
923
|
+
const result = { items };
|
|
924
|
+
if (Number(rows[0]?.has_more ?? 0) === 1 && items.length > 0) {
|
|
925
|
+
const last = items.at(-1);
|
|
926
|
+
result.nextCursor = encodeCursor(last.collectionSlug, last.contentId);
|
|
927
|
+
}
|
|
928
|
+
return result;
|
|
929
|
+
}
|
|
930
|
+
async findCurrentUsageByMediaId(mediaId) {
|
|
931
|
+
return (await this.db.selectFrom("_emdash_media_usage_sources as s").innerJoin("_emdash_media_usage as u", (join) => join.onRef("u.source_key", "=", "s.source_key").onRef("u.generation", "=", "s.current_generation")).select(currentUsageSelect).where("u.media_id", "=", mediaId).orderBy("s.source_key", "asc").orderBy("u.field_path", "asc").orderBy("u.occurrence_index", "asc").execute()).map(rowToUsageRecord);
|
|
932
|
+
}
|
|
933
|
+
async findCurrentUsageByProviderAsset(provider, providerAssetId) {
|
|
934
|
+
return (await this.db.selectFrom("_emdash_media_usage_sources as s").innerJoin("_emdash_media_usage as u", (join) => join.onRef("u.source_key", "=", "s.source_key").onRef("u.generation", "=", "s.current_generation")).select(currentUsageSelect).where("u.provider", "=", provider).where("u.provider_asset_id", "=", providerAssetId).orderBy("s.source_key", "asc").orderBy("u.field_path", "asc").orderBy("u.occurrence_index", "asc").execute()).map(rowToUsageRecord);
|
|
935
|
+
}
|
|
936
|
+
async findCurrentUsagePageByMediaId(mediaId, options = {}) {
|
|
937
|
+
return this.findCurrentUsagePage((query) => query.where("u.media_id", "=", mediaId), options);
|
|
938
|
+
}
|
|
939
|
+
async findCurrentUsagePageByProviderAsset(provider, providerAssetId, options = {}) {
|
|
940
|
+
return this.findCurrentUsagePage((query) => query.where("u.provider", "=", provider).where("u.provider_asset_id", "=", providerAssetId), options);
|
|
941
|
+
}
|
|
942
|
+
async deleteSource(sourceKey) {
|
|
943
|
+
return this.deleteSources([sourceKey]);
|
|
944
|
+
}
|
|
945
|
+
async deleteSourceIfCurrent(sourceKey, expectedCurrentGeneration) {
|
|
946
|
+
let deleted = false;
|
|
947
|
+
await withTransaction(this.db, async (trx) => {
|
|
948
|
+
await this.lockCleanupBeforeSourceDelete(trx);
|
|
949
|
+
const result = await trx.deleteFrom("_emdash_media_usage_sources").where("source_key", "=", sourceKey).where("current_generation", "=", expectedCurrentGeneration).executeTakeFirst();
|
|
950
|
+
deleted = Number(result.numDeletedRows ?? 0) > 0;
|
|
951
|
+
if (!deleted) return;
|
|
952
|
+
await this.deleteSourceGenerationOccurrences(trx, sourceKey, expectedCurrentGeneration);
|
|
953
|
+
});
|
|
954
|
+
return {
|
|
955
|
+
deleted,
|
|
956
|
+
source: await this.findSource(sourceKey)
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
async deleteSourceIfMatching(sourceKey, expectedSource) {
|
|
960
|
+
let deleted = false;
|
|
961
|
+
await withTransaction(this.db, async (trx) => {
|
|
962
|
+
await this.lockCleanupBeforeSourceDelete(trx);
|
|
963
|
+
const result = await trx.deleteFrom("_emdash_media_usage_sources").where("source_key", "=", sourceKey).where(this.sourceMatchExpression(expectedSource)).where(this.currentCollectionExists(expectedSource.collectionId, expectedSource.collectionSlug)).executeTakeFirst();
|
|
964
|
+
deleted = Number(result.numDeletedRows ?? 0) > 0;
|
|
965
|
+
if (!deleted) return;
|
|
966
|
+
await this.deleteSourceGenerationOccurrences(trx, sourceKey, expectedSource.currentGeneration);
|
|
967
|
+
});
|
|
968
|
+
return {
|
|
969
|
+
deleted,
|
|
970
|
+
source: await this.findSource(sourceKey)
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
async deleteSourceIfMatchingContentAbsent(sourceKey, expectedSource, collectionSlug, contentId) {
|
|
974
|
+
validateIdentifier(collectionSlug, "collection slug");
|
|
975
|
+
const tableName = `ec_${collectionSlug}`;
|
|
976
|
+
let deleted = false;
|
|
977
|
+
await withTransaction(this.db, async (trx) => {
|
|
978
|
+
await this.lockCleanupBeforeSourceDelete(trx);
|
|
979
|
+
const result = await trx.deleteFrom("_emdash_media_usage_sources").where("source_key", "=", sourceKey).where(this.sourceMatchExpression(expectedSource)).where(this.currentCollectionExists(expectedSource.collectionId, expectedSource.collectionSlug)).where(sql`NOT EXISTS (SELECT 1 FROM ${sql.ref(tableName)} WHERE id = ${contentId})`).executeTakeFirst();
|
|
980
|
+
deleted = Number(result.numDeletedRows ?? 0) > 0;
|
|
981
|
+
if (!deleted) return;
|
|
982
|
+
await this.deleteSourceGenerationOccurrences(trx, sourceKey, expectedSource.currentGeneration);
|
|
983
|
+
});
|
|
984
|
+
const contentPresent = deleted ? false : await this.contentRowExists(tableName, contentId);
|
|
985
|
+
return {
|
|
986
|
+
deleted,
|
|
987
|
+
contentPresent,
|
|
988
|
+
source: deleted || contentPresent ? null : await this.findSource(sourceKey)
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
async deleteSources(sourceKeys) {
|
|
992
|
+
return this.deleteSourceKeys(sourceKeys);
|
|
993
|
+
}
|
|
994
|
+
async deleteContentSources(collectionSlug, contentId) {
|
|
995
|
+
const sourceKeys = (await this.db.selectFrom("_emdash_media_usage_sources").select("source_key").where("source_type", "=", "content").where("collection_slug", "=", collectionSlug).where("content_id", "=", contentId).execute()).map((row) => row.source_key);
|
|
996
|
+
return this.deleteSourceKeys(sourceKeys);
|
|
997
|
+
}
|
|
998
|
+
async deleteCollectionSources(collectionSlug) {
|
|
999
|
+
let deleted = 0;
|
|
1000
|
+
while (true) {
|
|
1001
|
+
const sourceRows = await this.db.selectFrom("_emdash_media_usage_sources").select("source_key").where("source_type", "=", "content").where("collection_slug", "=", collectionSlug).orderBy("source_key", "asc").limit(SQL_BATCH_SIZE).execute();
|
|
1002
|
+
if (sourceRows.length === 0) break;
|
|
1003
|
+
deleted += await this.deleteSourceKeys(sourceRows.map((row) => row.source_key));
|
|
1004
|
+
}
|
|
1005
|
+
return deleted;
|
|
1006
|
+
}
|
|
1007
|
+
async findCollectionContentSources(collectionSlug, collectionId) {
|
|
1008
|
+
let query = this.db.selectFrom("_emdash_media_usage_sources").selectAll().where("source_type", "=", "content").where("collection_slug", "=", collectionSlug).orderBy("source_key", "asc");
|
|
1009
|
+
if (collectionId !== void 0) query = query.where("collection_id", "=", collectionId);
|
|
1010
|
+
return (await query.execute()).map((row) => rowToSource(row));
|
|
1011
|
+
}
|
|
1012
|
+
async claimMediaUsageCleanup(input) {
|
|
1013
|
+
const leaseDurationSeconds = cleanupDurationSeconds(input.leaseDurationSeconds);
|
|
1014
|
+
const nextEligibleDelaySeconds = cleanupDurationSeconds(input.nextEligibleDelaySeconds);
|
|
1015
|
+
const sweepSafetyWindowSeconds = cleanupDurationSeconds(input.sweepSafetyWindowSeconds);
|
|
1016
|
+
const claimedAt = this.cleanupTimestampOffset(0);
|
|
1017
|
+
const leaseExpiresAt = this.cleanupTimestampOffset(leaseDurationSeconds);
|
|
1018
|
+
const nextEligibleAt = this.cleanupTimestampOffset(nextEligibleDelaySeconds);
|
|
1019
|
+
const sweepBeforeAt = this.cleanupTimestampOffset(-sweepSafetyWindowSeconds);
|
|
1020
|
+
const row = await this.db.updateTable("_emdash_media_usage_cleanup").set({
|
|
1021
|
+
lease_token: input.leaseToken,
|
|
1022
|
+
lease_expires_at: leaseExpiresAt,
|
|
1023
|
+
next_eligible_at: nextEligibleAt,
|
|
1024
|
+
last_started_at: claimedAt,
|
|
1025
|
+
updated_at: claimedAt,
|
|
1026
|
+
scan_before_at: sql`CASE
|
|
1027
|
+
WHEN scan_before_at IS NULL THEN ${sweepBeforeAt}
|
|
1028
|
+
ELSE scan_before_at
|
|
1029
|
+
END`
|
|
1030
|
+
}).where("task_key", "=", "projection_gc").where(this.cleanupTimestampIsDue("next_eligible_at")).where((eb) => eb.or([eb("lease_token", "is", null), this.cleanupTimestampIsDue("lease_expires_at")])).returning([
|
|
1031
|
+
"cursor_created_at",
|
|
1032
|
+
"cursor_id",
|
|
1033
|
+
"last_started_at",
|
|
1034
|
+
"scan_before_at",
|
|
1035
|
+
"consecutive_failures"
|
|
1036
|
+
]).executeTakeFirst();
|
|
1037
|
+
if (!row) return null;
|
|
1038
|
+
if (!row.last_started_at || !row.scan_before_at) throw new Error("Media usage cleanup claim did not persist its database timestamps");
|
|
1039
|
+
return {
|
|
1040
|
+
leaseToken: input.leaseToken,
|
|
1041
|
+
cursor: row.cursor_created_at && row.cursor_id ? {
|
|
1042
|
+
createdAt: row.cursor_created_at,
|
|
1043
|
+
id: row.cursor_id
|
|
1044
|
+
} : null,
|
|
1045
|
+
claimedAt: row.last_started_at,
|
|
1046
|
+
scanBeforeAt: row.scan_before_at,
|
|
1047
|
+
consecutiveFailures: row.consecutive_failures
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Scans for reclaimable occurrences, or resolves to `null` when the sweep was
|
|
1052
|
+
* never issued because the lease is gone or the tick is out of budget. An
|
|
1053
|
+
* empty array means the scan ran and found nothing, which lets the caller
|
|
1054
|
+
* retire the sweep window; `null` must leave the cursor where it was.
|
|
1055
|
+
*/
|
|
1056
|
+
async findMediaUsageCleanupCandidates(input) {
|
|
1057
|
+
if (!await this.admitCleanupScan(input.cleanupLease, input.canIssueStatement)) return null;
|
|
1058
|
+
let query = this.db.selectFrom("_emdash_media_usage as u").leftJoin("_emdash_media_usage_sources as s", "s.source_key", "u.source_key").leftJoin("_emdash_media_usage_generation_writes as writer", (join) => join.onRef("writer.source_key", "=", "u.source_key").onRef("writer.generation", "=", "u.generation")).select([
|
|
1059
|
+
"u.id as id",
|
|
1060
|
+
"u.source_key as source_key",
|
|
1061
|
+
"u.generation as generation",
|
|
1062
|
+
"u.created_at as created_at",
|
|
1063
|
+
"s.current_generation as current_generation",
|
|
1064
|
+
"s.indexed_at as indexed_at",
|
|
1065
|
+
"writer.expires_at as write_lease_expires_at"
|
|
1066
|
+
]).where("u.created_at", "<", input.cutoff).orderBy("u.created_at", "asc").orderBy("u.id", "asc").limit(Math.max(0, Math.floor(input.limit)));
|
|
1067
|
+
if (input.cursor) {
|
|
1068
|
+
const cursor = input.cursor;
|
|
1069
|
+
query = query.where((eb) => eb(eb.refTuple("u.created_at", "u.id"), ">", eb.tuple(cursor.createdAt, cursor.id)));
|
|
1070
|
+
}
|
|
1071
|
+
return (await query.execute()).map((row) => ({
|
|
1072
|
+
id: row.id,
|
|
1073
|
+
sourceKey: row.source_key,
|
|
1074
|
+
generation: row.generation,
|
|
1075
|
+
createdAt: row.created_at,
|
|
1076
|
+
currentGeneration: row.current_generation,
|
|
1077
|
+
indexedAt: row.indexed_at,
|
|
1078
|
+
writeLeaseExpiresAt: row.write_lease_expires_at
|
|
1079
|
+
}));
|
|
1080
|
+
}
|
|
1081
|
+
async completeMediaUsageCleanup(input) {
|
|
1082
|
+
const updates = {
|
|
1083
|
+
lease_token: null,
|
|
1084
|
+
lease_expires_at: null,
|
|
1085
|
+
cursor_created_at: input.sweepComplete ? null : input.nextCursor?.createdAt ?? null,
|
|
1086
|
+
cursor_id: input.sweepComplete ? null : input.nextCursor?.id ?? null,
|
|
1087
|
+
...input.sweepComplete ? { scan_before_at: null } : {},
|
|
1088
|
+
consecutive_failures: 0,
|
|
1089
|
+
last_completed_at: this.cleanupTimestampOffset(0),
|
|
1090
|
+
last_candidate_count: input.candidateCount,
|
|
1091
|
+
last_deleted_orphans: input.deletedOrphans,
|
|
1092
|
+
last_deleted_stale: input.deletedStale,
|
|
1093
|
+
last_deleted_abandoned: input.deletedAbandoned,
|
|
1094
|
+
last_deleted_write_leases: input.deletedWriteLeases,
|
|
1095
|
+
last_backlog_lower_bound: input.backlogLowerBound,
|
|
1096
|
+
last_scan_has_more: input.scanHasMore ? 1 : 0,
|
|
1097
|
+
last_duration_ms: input.durationMs,
|
|
1098
|
+
last_error_code: null,
|
|
1099
|
+
updated_at: this.cleanupTimestampOffset(0)
|
|
1100
|
+
};
|
|
1101
|
+
const result = await this.db.updateTable("_emdash_media_usage_cleanup").set(updates).where("task_key", "=", "projection_gc").where("lease_token", "=", input.leaseToken).where(this.cleanupLeaseExpiryIsInFuture("_emdash_media_usage_cleanup.lease_expires_at")).executeTakeFirst();
|
|
1102
|
+
return Number(result.numUpdatedRows ?? 0) > 0;
|
|
1103
|
+
}
|
|
1104
|
+
async failMediaUsageCleanup(input) {
|
|
1105
|
+
const retryDelaySeconds = cleanupDurationSeconds(input.retryDelaySeconds);
|
|
1106
|
+
const result = await this.db.updateTable("_emdash_media_usage_cleanup").set({
|
|
1107
|
+
lease_token: null,
|
|
1108
|
+
lease_expires_at: null,
|
|
1109
|
+
next_eligible_at: this.cleanupTimestampOffset(retryDelaySeconds),
|
|
1110
|
+
consecutive_failures: input.consecutiveFailures,
|
|
1111
|
+
last_completed_at: this.cleanupTimestampOffset(0),
|
|
1112
|
+
last_duration_ms: input.durationMs,
|
|
1113
|
+
last_error_code: input.errorCode,
|
|
1114
|
+
updated_at: this.cleanupTimestampOffset(0)
|
|
1115
|
+
}).where("task_key", "=", "projection_gc").where("lease_token", "=", input.leaseToken).where(this.cleanupLeaseExpiryIsInFuture("_emdash_media_usage_cleanup.lease_expires_at")).executeTakeFirst();
|
|
1116
|
+
return Number(result.numUpdatedRows ?? 0) > 0;
|
|
1117
|
+
}
|
|
1118
|
+
async deleteOrphanOccurrencesOlderThan(cutoff, limit, options = {}) {
|
|
1119
|
+
const batchLimit = Math.floor(limit);
|
|
1120
|
+
if (batchLimit <= 0) return 0;
|
|
1121
|
+
if (options.candidateIds) return this.deleteOrphanCandidateIds(options.candidateIds.slice(0, batchLimit), cutoff, options.cleanupLease, options.canIssueStatement);
|
|
1122
|
+
if (!await this.admitCleanupScan(options.cleanupLease, options.canIssueStatement)) return 0;
|
|
1123
|
+
const rows = await this.db.selectFrom("_emdash_media_usage as u").leftJoin("_emdash_media_usage_sources as s", (join) => join.onRef("s.source_key", "=", "u.source_key")).leftJoin("_emdash_media_usage_generation_writes as writer", (join) => join.onRef("writer.source_key", "=", "u.source_key").onRef("writer.generation", "=", "u.generation")).select("u.id").where("s.source_key", "is", null).where("u.created_at", "<", cutoff).where(this.noActiveGenerationWriteExpression("u")).orderBy("u.created_at", "asc").orderBy("u.id", "asc").limit(batchLimit).execute();
|
|
1124
|
+
return this.deleteOrphanCandidateIds(rows.map((row) => row.id), cutoff, options.cleanupLease, options.canIssueStatement);
|
|
1125
|
+
}
|
|
1126
|
+
async deleteStaleGenerationsOlderThan(cutoff, limit, options = {}) {
|
|
1127
|
+
const batchLimit = Math.floor(limit);
|
|
1128
|
+
if (batchLimit <= 0) return 0;
|
|
1129
|
+
if (options.candidateIds) return this.deleteStaleCandidateIds(options.candidateIds.slice(0, batchLimit), cutoff, options.cleanupLease, options.canIssueStatement);
|
|
1130
|
+
if (!await this.admitCleanupScan(options.cleanupLease, options.canIssueStatement)) return 0;
|
|
1131
|
+
const rows = await this.db.selectFrom("_emdash_media_usage as u").innerJoin("_emdash_media_usage_sources as s", (join) => join.onRef("s.source_key", "=", "u.source_key")).leftJoin("_emdash_media_usage_generation_writes as writer", (join) => join.onRef("writer.source_key", "=", "u.source_key").onRef("writer.generation", "=", "u.generation")).select("u.id").where("u.created_at", "<", cutoff).whereRef("u.generation", "!=", "s.current_generation").whereRef("u.created_at", "<", "s.indexed_at").where(this.noActiveGenerationWriteExpression("u")).orderBy("u.created_at", "asc").orderBy("u.id", "asc").limit(batchLimit).execute();
|
|
1132
|
+
return this.deleteStaleCandidateIds(rows.map((row) => row.id), cutoff, options.cleanupLease, options.canIssueStatement);
|
|
1133
|
+
}
|
|
1134
|
+
async deleteAbandonedGenerationsOlderThan(cutoff, limit, options = {}) {
|
|
1135
|
+
const batchLimit = Math.floor(limit);
|
|
1136
|
+
if (batchLimit <= 0) return 0;
|
|
1137
|
+
if (options.candidateIds) return this.deleteAbandonedCandidateIds(options.candidateIds.slice(0, batchLimit), cutoff, options.cleanupLease, options.canIssueStatement);
|
|
1138
|
+
if (!await this.admitCleanupScan(options.cleanupLease, options.canIssueStatement)) return 0;
|
|
1139
|
+
const rows = await this.db.selectFrom("_emdash_media_usage as u").innerJoin("_emdash_media_usage_sources as s", (join) => join.onRef("s.source_key", "=", "u.source_key")).leftJoin("_emdash_media_usage_generation_writes as writer", (join) => join.onRef("writer.source_key", "=", "u.source_key").onRef("writer.generation", "=", "u.generation")).select("u.id").where("u.created_at", "<", cutoff).whereRef("u.generation", "!=", "s.current_generation").whereRef("u.created_at", ">=", "s.indexed_at").where(this.noActiveGenerationWriteExpression("u")).orderBy("u.created_at", "asc").orderBy("u.id", "asc").limit(batchLimit).execute();
|
|
1140
|
+
return this.deleteAbandonedCandidateIds(rows.map((row) => row.id), cutoff, options.cleanupLease, options.canIssueStatement);
|
|
1141
|
+
}
|
|
1142
|
+
async deleteExpiredGenerationWriteLeases(limit, cleanupLease, canIssueStatement) {
|
|
1143
|
+
const batchLimit = Math.floor(limit);
|
|
1144
|
+
if (batchLimit <= 0) return 0;
|
|
1145
|
+
if (!await this.admitCleanupScan(cleanupLease, canIssueStatement)) return 0;
|
|
1146
|
+
const rows = await this.db.selectFrom("_emdash_media_usage_generation_writes").select("lease_token").where(this.generationWriteLeaseHasExpired("expires_at")).orderBy("expires_at", "asc").orderBy("lease_token", "asc").limit(batchLimit).execute();
|
|
1147
|
+
if (rows.length === 0 || !canIssueCleanupStatement(canIssueStatement)) return 0;
|
|
1148
|
+
let deleteQuery = this.db.deleteFrom("_emdash_media_usage_generation_writes").where("lease_token", "in", rows.map((row) => row.lease_token)).where(this.generationWriteLeaseHasExpired("expires_at"));
|
|
1149
|
+
if (cleanupLease) deleteQuery = deleteQuery.where(this.activeCleanupLeaseExpression(cleanupLease));
|
|
1150
|
+
const result = await deleteQuery.executeTakeFirst();
|
|
1151
|
+
return Number(result.numDeletedRows ?? 0);
|
|
1152
|
+
}
|
|
1153
|
+
async upsertIndexStatus(input) {
|
|
1154
|
+
const now = input.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
1155
|
+
const row = {
|
|
1156
|
+
adapter_id: input.adapterId,
|
|
1157
|
+
scope_type: input.scopeType,
|
|
1158
|
+
scope_key: input.scopeKey,
|
|
1159
|
+
status: input.status,
|
|
1160
|
+
schema_version: input.schemaVersion ?? 1,
|
|
1161
|
+
started_at: input.startedAt ?? null,
|
|
1162
|
+
completed_at: input.completedAt ?? null,
|
|
1163
|
+
cursor: input.cursor ?? null,
|
|
1164
|
+
indexed_source_count: input.indexedSourceCount ?? 0,
|
|
1165
|
+
failed_source_count: input.failedSourceCount ?? 0,
|
|
1166
|
+
last_error_code: input.lastErrorCode ?? null,
|
|
1167
|
+
updated_at: now
|
|
1168
|
+
};
|
|
1169
|
+
await this.db.insertInto("_emdash_media_usage_index_status").values(row).onConflict((oc) => oc.columns([
|
|
1170
|
+
"adapter_id",
|
|
1171
|
+
"scope_type",
|
|
1172
|
+
"scope_key"
|
|
1173
|
+
]).doUpdateSet({
|
|
1174
|
+
status: row.status,
|
|
1175
|
+
schema_version: row.schema_version,
|
|
1176
|
+
started_at: row.started_at,
|
|
1177
|
+
completed_at: row.completed_at,
|
|
1178
|
+
cursor: row.cursor,
|
|
1179
|
+
indexed_source_count: row.indexed_source_count,
|
|
1180
|
+
failed_source_count: row.failed_source_count,
|
|
1181
|
+
last_error_code: row.last_error_code,
|
|
1182
|
+
updated_at: row.updated_at
|
|
1183
|
+
})).execute();
|
|
1184
|
+
const status = await this.findIndexStatus(input);
|
|
1185
|
+
if (!status) throw new Error(`Media usage index status ${input.adapterId}:${input.scopeType}:${input.scopeKey} was not persisted`);
|
|
1186
|
+
return status;
|
|
1187
|
+
}
|
|
1188
|
+
async invalidateIndexStatusForSchemaChange(collectionSlug) {
|
|
1189
|
+
const result = await this.db.updateTable("_emdash_media_usage_index_status as status").set({
|
|
1190
|
+
change_epoch: sql`change_epoch + 1`,
|
|
1191
|
+
status: "stale",
|
|
1192
|
+
completed_at: null,
|
|
1193
|
+
cursor: null,
|
|
1194
|
+
last_error_code: "CONTENT_USAGE_STALE",
|
|
1195
|
+
reconciliation_required: 1,
|
|
1196
|
+
updated_at: this.sortableUtcTimestamp()
|
|
1197
|
+
}).where("status.adapter_id", "=", "content-media").where("status.scope_type", "=", "collection").where("status.scope_key", "=", collectionSlug).where("status.capture_state", "=", "active").where((eb) => eb.exists(eb.selectFrom("_emdash_collections as collection").select("collection.id").whereRef("collection.id", "=", "status.collection_id").whereRef("collection.slug", "=", "status.scope_key"))).where(sql`EXISTS (
|
|
1198
|
+
SELECT 1
|
|
1199
|
+
FROM _emdash_media_usage_activation AS activation
|
|
1200
|
+
WHERE activation.task_key = 'incremental_capture'
|
|
1201
|
+
AND activation.state = 'active'
|
|
1202
|
+
)`).executeTakeFirst();
|
|
1203
|
+
return Number(result.numUpdatedRows ?? 0) === 1;
|
|
1204
|
+
}
|
|
1205
|
+
async beginIndexStatusRepair(input) {
|
|
1206
|
+
return this.upsertIndexStatus({
|
|
1207
|
+
adapterId: input.adapterId,
|
|
1208
|
+
scopeType: input.scopeType,
|
|
1209
|
+
scopeKey: input.scopeKey,
|
|
1210
|
+
status: "running",
|
|
1211
|
+
schemaVersion: input.schemaVersion,
|
|
1212
|
+
startedAt: input.startedAt,
|
|
1213
|
+
completedAt: null,
|
|
1214
|
+
cursor: input.runToken,
|
|
1215
|
+
indexedSourceCount: 0,
|
|
1216
|
+
failedSourceCount: 0,
|
|
1217
|
+
lastErrorCode: null,
|
|
1218
|
+
updatedAt: input.updatedAt
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
async finalizeIndexStatusRepairIfRunning(input) {
|
|
1222
|
+
const updates = {
|
|
1223
|
+
status: input.status,
|
|
1224
|
+
completed_at: input.completedAt,
|
|
1225
|
+
cursor: null,
|
|
1226
|
+
indexed_source_count: input.indexedSourceCount ?? 0,
|
|
1227
|
+
failed_source_count: input.failedSourceCount ?? 0,
|
|
1228
|
+
last_error_code: input.lastErrorCode ?? null,
|
|
1229
|
+
updated_at: input.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
1230
|
+
};
|
|
1231
|
+
if (input.schemaVersion !== void 0) updates.schema_version = input.schemaVersion;
|
|
1232
|
+
const result = await this.db.updateTable("_emdash_media_usage_index_status").set(updates).where("adapter_id", "=", input.adapterId).where("scope_type", "=", input.scopeType).where("scope_key", "=", input.scopeKey).where("status", "=", "running").where("cursor", "=", input.runToken).executeTakeFirst();
|
|
1233
|
+
return {
|
|
1234
|
+
finalized: Number(result.numUpdatedRows ?? 0) > 0,
|
|
1235
|
+
status: await this.findIndexStatus(input)
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
async beginIndexStatusRepairAtCurrentEpoch(input) {
|
|
1239
|
+
const now = this.sortableUtcTimestamp();
|
|
1240
|
+
const row = await this.db.updateTable("_emdash_media_usage_index_status").set({
|
|
1241
|
+
status: "running",
|
|
1242
|
+
schema_version: input.schemaVersion,
|
|
1243
|
+
started_at: now,
|
|
1244
|
+
completed_at: null,
|
|
1245
|
+
cursor: input.runToken,
|
|
1246
|
+
indexed_source_count: 0,
|
|
1247
|
+
failed_source_count: 0,
|
|
1248
|
+
last_error_code: null,
|
|
1249
|
+
reconciliation_required: 1,
|
|
1250
|
+
updated_at: now
|
|
1251
|
+
}).where("adapter_id", "=", input.adapterId).where("scope_type", "=", input.scopeType).where("scope_key", "=", input.scopeKey).where("collection_id", "=", input.collectionId).where("capture_state", "=", "active").where(sql`EXISTS (
|
|
1252
|
+
SELECT 1
|
|
1253
|
+
FROM _emdash_collections AS collection
|
|
1254
|
+
WHERE collection.id = ${input.collectionId}
|
|
1255
|
+
AND collection.slug = ${input.scopeKey}
|
|
1256
|
+
)`).where(sql`EXISTS (
|
|
1257
|
+
SELECT 1
|
|
1258
|
+
FROM _emdash_media_usage_activation AS activation
|
|
1259
|
+
WHERE activation.task_key = 'incremental_capture'
|
|
1260
|
+
AND activation.state = 'active'
|
|
1261
|
+
)`).returning(["change_epoch", "started_at"]).executeTakeFirst();
|
|
1262
|
+
if (!row?.started_at) return null;
|
|
1263
|
+
return {
|
|
1264
|
+
changeEpoch: row.change_epoch,
|
|
1265
|
+
startedAt: row.started_at
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
async finalizeIndexStatusRepairAtEpoch(input) {
|
|
1269
|
+
const now = this.sortableUtcTimestamp();
|
|
1270
|
+
const updates = {
|
|
1271
|
+
status: input.status,
|
|
1272
|
+
schema_version: input.schemaVersion,
|
|
1273
|
+
completed_at: now,
|
|
1274
|
+
cursor: null,
|
|
1275
|
+
indexed_source_count: input.indexedSourceCount,
|
|
1276
|
+
failed_source_count: input.failedSourceCount,
|
|
1277
|
+
last_error_code: input.lastErrorCode,
|
|
1278
|
+
reconciliation_required: input.status === "complete" ? 0 : 1,
|
|
1279
|
+
updated_at: now
|
|
1280
|
+
};
|
|
1281
|
+
let query = this.db.updateTable("_emdash_media_usage_index_status").set(updates).where("adapter_id", "=", input.adapterId).where("scope_type", "=", input.scopeType).where("scope_key", "=", input.scopeKey).where("collection_id", "=", input.collectionId).where("status", "=", "running").where("cursor", "=", input.runToken).where("change_epoch", "=", input.startingEpoch).where(sql`EXISTS (
|
|
1282
|
+
SELECT 1
|
|
1283
|
+
FROM _emdash_collections AS collection
|
|
1284
|
+
WHERE collection.id = ${input.collectionId}
|
|
1285
|
+
AND collection.slug = ${input.scopeKey}
|
|
1286
|
+
)`);
|
|
1287
|
+
if (input.status === "complete") query = query.where(sql`NOT EXISTS (
|
|
1288
|
+
SELECT 1
|
|
1289
|
+
FROM _emdash_media_usage_work AS work
|
|
1290
|
+
WHERE work.collection_id = ${input.collectionId}
|
|
1291
|
+
)`);
|
|
1292
|
+
const result = await query.executeTakeFirst();
|
|
1293
|
+
const finalized = Number(result.numUpdatedRows ?? 0) > 0;
|
|
1294
|
+
if (!finalized) await this.db.updateTable("_emdash_media_usage_index_status").set({
|
|
1295
|
+
status: "stale",
|
|
1296
|
+
completed_at: null,
|
|
1297
|
+
cursor: null,
|
|
1298
|
+
last_error_code: "CONTENT_USAGE_REPAIR_CONFLICT",
|
|
1299
|
+
reconciliation_required: 1,
|
|
1300
|
+
updated_at: this.sortableUtcTimestamp()
|
|
1301
|
+
}).where("adapter_id", "=", input.adapterId).where("scope_type", "=", input.scopeType).where("scope_key", "=", input.scopeKey).where("collection_id", "=", input.collectionId).where("status", "=", "running").where("cursor", "=", input.runToken).execute();
|
|
1302
|
+
return {
|
|
1303
|
+
finalized,
|
|
1304
|
+
status: await this.findIndexStatusForCollection(input, input.collectionId)
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
async recordIncrementalSuccess(input) {
|
|
1308
|
+
const observed = await this.db.selectFrom("_emdash_media_usage_index_status").select("change_epoch").where("adapter_id", "=", "content-media").where("scope_type", "=", "collection").where("scope_key", "=", input.collectionSlug).where("collection_id", "=", input.collectionId).where("capture_state", "=", "active").where(sql`EXISTS (
|
|
1309
|
+
SELECT 1
|
|
1310
|
+
FROM _emdash_collections AS collection
|
|
1311
|
+
WHERE collection.id = ${input.collectionId}
|
|
1312
|
+
AND collection.slug = ${input.collectionSlug}
|
|
1313
|
+
)`).executeTakeFirst();
|
|
1314
|
+
if (!observed) return false;
|
|
1315
|
+
const canComplete = sql`(
|
|
1316
|
+
reconciliation_required = 0
|
|
1317
|
+
AND status IN ('complete', 'stale', 'partial')
|
|
1318
|
+
AND NOT EXISTS (
|
|
1319
|
+
SELECT 1
|
|
1320
|
+
FROM _emdash_media_usage_work AS work
|
|
1321
|
+
WHERE work.collection_id = ${input.collectionId}
|
|
1322
|
+
)
|
|
1323
|
+
)`;
|
|
1324
|
+
const now = this.sortableUtcTimestamp();
|
|
1325
|
+
const result = await this.db.updateTable("_emdash_media_usage_index_status").set({
|
|
1326
|
+
status: sql`CASE WHEN ${canComplete} THEN 'complete' ELSE status END`,
|
|
1327
|
+
completed_at: sql`CASE WHEN ${canComplete} THEN ${now} ELSE completed_at END`,
|
|
1328
|
+
last_error_code: sql`CASE WHEN ${canComplete} THEN NULL ELSE last_error_code END`,
|
|
1329
|
+
cursor: sql`CASE WHEN ${canComplete} THEN NULL ELSE cursor END`,
|
|
1330
|
+
last_incremental_success_at: now,
|
|
1331
|
+
updated_at: now
|
|
1332
|
+
}).where("adapter_id", "=", "content-media").where("scope_type", "=", "collection").where("scope_key", "=", input.collectionSlug).where("collection_id", "=", input.collectionId).where("change_epoch", "=", observed.change_epoch).where("capture_state", "=", "active").where(sql`EXISTS (
|
|
1333
|
+
SELECT 1
|
|
1334
|
+
FROM _emdash_collections AS collection
|
|
1335
|
+
WHERE collection.id = ${input.collectionId}
|
|
1336
|
+
AND collection.slug = ${input.collectionSlug}
|
|
1337
|
+
)`).executeTakeFirst();
|
|
1338
|
+
return Number(result.numUpdatedRows ?? 0) > 0;
|
|
1339
|
+
}
|
|
1340
|
+
async prepareIncrementalFinalization(input) {
|
|
1341
|
+
const observed = await this.db.selectFrom("_emdash_media_usage_index_status").select(["change_epoch", "reconciliation_required"]).where("adapter_id", "=", "content-media").where("scope_type", "=", "collection").where("scope_key", "=", input.collectionSlug).where("collection_id", "=", input.collectionId).where("capture_state", "=", "active").executeTakeFirst();
|
|
1342
|
+
if (!observed) return { outcome: "lost" };
|
|
1343
|
+
if (observed.reconciliation_required !== 0) return { outcome: "not_required" };
|
|
1344
|
+
const marker = `incremental-finalize:${String(observed.change_epoch)}:${ulid()}`;
|
|
1345
|
+
const result = await this.db.updateTable("_emdash_media_usage_index_status").set({
|
|
1346
|
+
cursor: marker,
|
|
1347
|
+
updated_at: this.sortableUtcTimestamp()
|
|
1348
|
+
}).where("adapter_id", "=", "content-media").where("scope_type", "=", "collection").where("scope_key", "=", input.collectionSlug).where("collection_id", "=", input.collectionId).where("capture_state", "=", "active").where("reconciliation_required", "=", 0).where("change_epoch", "=", observed.change_epoch).where(sql`EXISTS (
|
|
1349
|
+
SELECT 1
|
|
1350
|
+
FROM _emdash_collections AS collection
|
|
1351
|
+
WHERE collection.id = ${input.collectionId}
|
|
1352
|
+
AND collection.slug = ${input.collectionSlug}
|
|
1353
|
+
)`).where(sql`NOT EXISTS (
|
|
1354
|
+
SELECT 1
|
|
1355
|
+
FROM _emdash_media_usage_collection_deletions AS deletion
|
|
1356
|
+
WHERE deletion.collection_id = ${input.collectionId}
|
|
1357
|
+
)`).executeTakeFirst();
|
|
1358
|
+
return Number(result.numUpdatedRows ?? 0) > 0 ? {
|
|
1359
|
+
outcome: "marked",
|
|
1360
|
+
marker
|
|
1361
|
+
} : { outcome: "lost" };
|
|
1362
|
+
}
|
|
1363
|
+
async recoverIncrementalFinalizations() {
|
|
1364
|
+
const markerMatchesEpoch = isPostgres(this.db) ? sql`status.cursor LIKE ('incremental-finalize:' || status.change_epoch::text || ':%')` : sql`status.cursor LIKE ('incremental-finalize:' || CAST(status.change_epoch AS text) || ':%')`;
|
|
1365
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1366
|
+
return (await sql`
|
|
1367
|
+
UPDATE _emdash_media_usage_index_status AS status
|
|
1368
|
+
SET status = 'complete',
|
|
1369
|
+
completed_at = ${now},
|
|
1370
|
+
cursor = NULL,
|
|
1371
|
+
last_error_code = NULL,
|
|
1372
|
+
last_incremental_success_at = ${now},
|
|
1373
|
+
updated_at = ${now}
|
|
1374
|
+
WHERE status.adapter_id = 'content-media'
|
|
1375
|
+
AND status.scope_type = 'collection'
|
|
1376
|
+
AND status.capture_state = 'active'
|
|
1377
|
+
AND status.reconciliation_required = 0
|
|
1378
|
+
AND status.cursor IS NOT NULL
|
|
1379
|
+
AND ${markerMatchesEpoch}
|
|
1380
|
+
AND EXISTS (
|
|
1381
|
+
SELECT 1
|
|
1382
|
+
FROM _emdash_collections AS collection
|
|
1383
|
+
WHERE collection.id = status.collection_id
|
|
1384
|
+
AND collection.slug = status.scope_key
|
|
1385
|
+
)
|
|
1386
|
+
AND NOT EXISTS (
|
|
1387
|
+
SELECT 1
|
|
1388
|
+
FROM _emdash_media_usage_collection_deletions AS deletion
|
|
1389
|
+
WHERE deletion.collection_id = status.collection_id
|
|
1390
|
+
)
|
|
1391
|
+
AND NOT EXISTS (
|
|
1392
|
+
SELECT 1
|
|
1393
|
+
FROM _emdash_media_usage_work AS work
|
|
1394
|
+
WHERE work.collection_id = status.collection_id
|
|
1395
|
+
)
|
|
1396
|
+
RETURNING collection_id
|
|
1397
|
+
`.execute(this.db)).rows.length;
|
|
1398
|
+
}
|
|
1399
|
+
async recordIncrementalFailure(input) {
|
|
1400
|
+
const now = this.sortableUtcTimestamp();
|
|
1401
|
+
const automaticRunOwnsCoverage = sql`EXISTS (
|
|
1402
|
+
SELECT 1
|
|
1403
|
+
FROM _emdash_media_usage_reconciliations AS reconciliation
|
|
1404
|
+
WHERE reconciliation.collection_id = ${input.collectionId}
|
|
1405
|
+
AND reconciliation.run_token = cursor
|
|
1406
|
+
)`;
|
|
1407
|
+
const result = await this.db.updateTable("_emdash_media_usage_index_status").set({
|
|
1408
|
+
status: sql`CASE
|
|
1409
|
+
WHEN ${automaticRunOwnsCoverage} THEN status
|
|
1410
|
+
WHEN reconciliation_required = 0 THEN 'partial'
|
|
1411
|
+
WHEN status = 'running' THEN 'stale'
|
|
1412
|
+
ELSE status
|
|
1413
|
+
END`,
|
|
1414
|
+
completed_at: sql`CASE
|
|
1415
|
+
WHEN ${automaticRunOwnsCoverage} THEN completed_at
|
|
1416
|
+
WHEN reconciliation_required = 0 OR status = 'running' THEN NULL
|
|
1417
|
+
ELSE completed_at
|
|
1418
|
+
END`,
|
|
1419
|
+
cursor: sql`CASE
|
|
1420
|
+
WHEN ${automaticRunOwnsCoverage} THEN cursor
|
|
1421
|
+
WHEN status = 'running' THEN NULL
|
|
1422
|
+
ELSE cursor
|
|
1423
|
+
END`,
|
|
1424
|
+
last_error_code: input.errorCode,
|
|
1425
|
+
updated_at: now
|
|
1426
|
+
}).where("adapter_id", "=", "content-media").where("scope_type", "=", "collection").where("scope_key", "=", input.collectionSlug).where("collection_id", "=", input.collectionId).where(sql`EXISTS (
|
|
1427
|
+
SELECT 1
|
|
1428
|
+
FROM _emdash_media_usage_work AS work
|
|
1429
|
+
WHERE work.collection_id = ${input.collectionId}
|
|
1430
|
+
AND work.content_id = ${input.contentId}
|
|
1431
|
+
AND work.work_version = ${input.workVersion}
|
|
1432
|
+
AND work.state = 'failed'
|
|
1433
|
+
AND work.last_error_code = ${input.errorCode}
|
|
1434
|
+
)`).where(sql`EXISTS (
|
|
1435
|
+
SELECT 1
|
|
1436
|
+
FROM _emdash_collections AS collection
|
|
1437
|
+
WHERE collection.id = ${input.collectionId}
|
|
1438
|
+
AND collection.slug = ${input.collectionSlug}
|
|
1439
|
+
)`).executeTakeFirst();
|
|
1440
|
+
return Number(result.numUpdatedRows ?? 0) > 0;
|
|
1441
|
+
}
|
|
1442
|
+
async recordIncrementalFailuresByCollection(input) {
|
|
1443
|
+
const collectionIds = [...new Set(input.collectionIds)];
|
|
1444
|
+
if (collectionIds.length === 0) return /* @__PURE__ */ new Set();
|
|
1445
|
+
const collections = jsonTextValues(this.db, collectionIds);
|
|
1446
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1447
|
+
const result = await sql`
|
|
1448
|
+
WITH failed_collections AS (${collections})
|
|
1449
|
+
UPDATE _emdash_media_usage_index_status AS status
|
|
1450
|
+
SET status = CASE
|
|
1451
|
+
WHEN EXISTS (
|
|
1452
|
+
SELECT 1
|
|
1453
|
+
FROM _emdash_media_usage_reconciliations AS reconciliation
|
|
1454
|
+
WHERE reconciliation.collection_id = status.collection_id
|
|
1455
|
+
AND reconciliation.run_token = status.cursor
|
|
1456
|
+
) THEN status.status
|
|
1457
|
+
WHEN status.reconciliation_required = 0 THEN 'partial'
|
|
1458
|
+
WHEN status.status = 'running' THEN 'stale'
|
|
1459
|
+
ELSE status.status
|
|
1460
|
+
END,
|
|
1461
|
+
completed_at = CASE
|
|
1462
|
+
WHEN EXISTS (
|
|
1463
|
+
SELECT 1
|
|
1464
|
+
FROM _emdash_media_usage_reconciliations AS reconciliation
|
|
1465
|
+
WHERE reconciliation.collection_id = status.collection_id
|
|
1466
|
+
AND reconciliation.run_token = status.cursor
|
|
1467
|
+
) THEN status.completed_at
|
|
1468
|
+
WHEN status.reconciliation_required = 0 OR status.status = 'running' THEN NULL
|
|
1469
|
+
ELSE status.completed_at
|
|
1470
|
+
END,
|
|
1471
|
+
cursor = CASE
|
|
1472
|
+
WHEN EXISTS (
|
|
1473
|
+
SELECT 1
|
|
1474
|
+
FROM _emdash_media_usage_reconciliations AS reconciliation
|
|
1475
|
+
WHERE reconciliation.collection_id = status.collection_id
|
|
1476
|
+
AND reconciliation.run_token = status.cursor
|
|
1477
|
+
) THEN status.cursor
|
|
1478
|
+
WHEN status.status = 'running' THEN NULL
|
|
1479
|
+
ELSE status.cursor
|
|
1480
|
+
END,
|
|
1481
|
+
last_error_code = ${input.errorCode},
|
|
1482
|
+
updated_at = ${now}
|
|
1483
|
+
WHERE status.adapter_id = 'content-media'
|
|
1484
|
+
AND status.scope_type = 'collection'
|
|
1485
|
+
AND status.collection_id IN (SELECT value FROM failed_collections)
|
|
1486
|
+
AND EXISTS (
|
|
1487
|
+
SELECT 1
|
|
1488
|
+
FROM _emdash_media_usage_work AS work
|
|
1489
|
+
WHERE work.collection_id = status.collection_id
|
|
1490
|
+
AND work.state = 'failed'
|
|
1491
|
+
AND work.last_error_code = ${input.errorCode}
|
|
1492
|
+
)
|
|
1493
|
+
AND EXISTS (
|
|
1494
|
+
SELECT 1
|
|
1495
|
+
FROM _emdash_collections AS collection
|
|
1496
|
+
WHERE collection.id = status.collection_id
|
|
1497
|
+
AND collection.slug = status.scope_key
|
|
1498
|
+
)
|
|
1499
|
+
RETURNING collection_id
|
|
1500
|
+
`.execute(this.db);
|
|
1501
|
+
return new Set(result.rows.map((row) => row.collection_id));
|
|
1502
|
+
}
|
|
1503
|
+
async findIndexStatus(identity) {
|
|
1504
|
+
const row = await this.db.selectFrom("_emdash_media_usage_index_status").selectAll().where("adapter_id", "=", identity.adapterId).where("scope_type", "=", identity.scopeType).where("scope_key", "=", identity.scopeKey).executeTakeFirst();
|
|
1505
|
+
return row ? rowToIndexStatus(row) : null;
|
|
1506
|
+
}
|
|
1507
|
+
async findIndexStatusForCollection(identity, collectionId) {
|
|
1508
|
+
const row = await this.db.selectFrom("_emdash_media_usage_index_status").selectAll().where("adapter_id", "=", identity.adapterId).where("scope_type", "=", identity.scopeType).where("scope_key", "=", identity.scopeKey).where("collection_id", "=", collectionId).executeTakeFirst();
|
|
1509
|
+
return row ? rowToIndexStatus(row) : null;
|
|
1510
|
+
}
|
|
1511
|
+
async deleteIndexStatus(identity, collectionId) {
|
|
1512
|
+
let query = this.db.deleteFrom("_emdash_media_usage_index_status").where("adapter_id", "=", identity.adapterId).where("scope_type", "=", identity.scopeType).where("scope_key", "=", identity.scopeKey);
|
|
1513
|
+
if (collectionId !== void 0) query = query.where("collection_id", "=", collectionId);
|
|
1514
|
+
const result = await query.executeTakeFirst();
|
|
1515
|
+
return Number(result.numDeletedRows ?? 0);
|
|
1516
|
+
}
|
|
1517
|
+
sortableUtcTimestamp() {
|
|
1518
|
+
return isPostgres(this.db) ? sql`to_char(clock_timestamp() AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"')` : sql`strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`;
|
|
1519
|
+
}
|
|
1520
|
+
async findCurrentUsagePage(applyFilter, options) {
|
|
1521
|
+
const limit = Math.min(Math.max(1, options.limit ?? 50), 100);
|
|
1522
|
+
let query = applyFilter(this.currentUsageBaseQuery()).orderBy("u.id", "asc").limit(limit + 1);
|
|
1523
|
+
if (options.cursor) {
|
|
1524
|
+
const { id } = decodeCursor(options.cursor);
|
|
1525
|
+
query = query.where("u.id", ">", id);
|
|
1526
|
+
}
|
|
1527
|
+
const rows = await query.execute();
|
|
1528
|
+
const items = rows.slice(0, limit).map(rowToUsageRecord);
|
|
1529
|
+
const result = { items };
|
|
1530
|
+
if (rows.length > limit && items.length > 0) {
|
|
1531
|
+
const last = items.at(-1);
|
|
1532
|
+
result.nextCursor = encodeCursor(last.occurrence.id, last.occurrence.id);
|
|
1533
|
+
}
|
|
1534
|
+
return result;
|
|
1535
|
+
}
|
|
1536
|
+
currentUsageBaseQuery() {
|
|
1537
|
+
return this.db.selectFrom("_emdash_media_usage_sources as s").innerJoin("_emdash_media_usage as u", (join) => join.onRef("u.source_key", "=", "s.source_key").onRef("u.generation", "=", "s.current_generation")).select(currentUsageSelect);
|
|
1538
|
+
}
|
|
1539
|
+
currentContentMediaUsageBaseQuery() {
|
|
1540
|
+
return this.db.selectFrom("_emdash_media_usage as u").crossJoin("_emdash_media_usage_sources as s").innerJoin("_emdash_collections as collection", "collection.slug", "s.collection_slug").whereRef("s.source_key", "=", "u.source_key").whereRef("s.current_generation", "=", "u.generation").where("s.source_type", "=", "content").where("s.collection_slug", "is not", null).where("s.content_id", "is not", null).where("s.source_variant", "in", ["columns", "draft_overlay"]).where(contentSourceMatchesActiveCollection("s", "collection.id")).where(CONTENT_SOURCE_ELIGIBILITY);
|
|
1541
|
+
}
|
|
1542
|
+
async deleteOrphanCandidateIds(ids, cutoff, cleanupLease, canIssueStatement) {
|
|
1543
|
+
let deleted = 0;
|
|
1544
|
+
for (const idBatch of chunks([...ids], cleanupDeleteBatchSize(cleanupLease))) {
|
|
1545
|
+
if (!canIssueCleanupStatement(canIssueStatement)) break;
|
|
1546
|
+
if (cleanupLease) {
|
|
1547
|
+
await this.markOrphanCandidatesForCleanup(idBatch, cutoff, cleanupLease);
|
|
1548
|
+
if (!canIssueCleanupStatement(canIssueStatement)) break;
|
|
1549
|
+
}
|
|
1550
|
+
let query = this.db.deleteFrom("_emdash_media_usage").where("id", "in", idBatch).where("created_at", "<", cutoff).where(sql`NOT EXISTS (SELECT 1 FROM _emdash_media_usage_sources source WHERE source.source_key = _emdash_media_usage.source_key)`).where(this.noActiveGenerationWriteExpression());
|
|
1551
|
+
if (cleanupLease) query = query.where("cleanup_lease_token", "=", cleanupLease.leaseToken).where(this.activeCleanupLeaseExpression(cleanupLease));
|
|
1552
|
+
const result = await query.executeTakeFirst();
|
|
1553
|
+
deleted += Number(result.numDeletedRows ?? 0);
|
|
1554
|
+
}
|
|
1555
|
+
return deleted;
|
|
1556
|
+
}
|
|
1557
|
+
async deleteStaleCandidateIds(ids, cutoff, cleanupLease, canIssueStatement) {
|
|
1558
|
+
let deleted = 0;
|
|
1559
|
+
for (const idBatch of chunks([...ids], cleanupDeleteBatchSize(cleanupLease))) {
|
|
1560
|
+
if (!canIssueCleanupStatement(canIssueStatement)) break;
|
|
1561
|
+
if (cleanupLease) {
|
|
1562
|
+
await this.markStaleCandidatesForCleanup(idBatch, cutoff, cleanupLease);
|
|
1563
|
+
if (!canIssueCleanupStatement(canIssueStatement)) break;
|
|
1564
|
+
}
|
|
1565
|
+
let query = this.db.deleteFrom("_emdash_media_usage").where("id", "in", idBatch).where("created_at", "<", cutoff).where((eb) => eb.exists(eb.selectFrom("_emdash_media_usage_sources as source").select("source.source_key").whereRef("source.source_key", "=", "_emdash_media_usage.source_key").whereRef("source.current_generation", "!=", "_emdash_media_usage.generation").whereRef("_emdash_media_usage.created_at", "<", "source.indexed_at"))).where(this.noActiveGenerationWriteExpression());
|
|
1566
|
+
if (cleanupLease) query = query.where("cleanup_lease_token", "=", cleanupLease.leaseToken).where(this.activeCleanupLeaseExpression(cleanupLease));
|
|
1567
|
+
const result = await query.executeTakeFirst();
|
|
1568
|
+
deleted += Number(result.numDeletedRows ?? 0);
|
|
1569
|
+
}
|
|
1570
|
+
return deleted;
|
|
1571
|
+
}
|
|
1572
|
+
async deleteAbandonedCandidateIds(ids, cutoff, cleanupLease, canIssueStatement) {
|
|
1573
|
+
let deleted = 0;
|
|
1574
|
+
for (const idBatch of chunks([...ids], cleanupDeleteBatchSize(cleanupLease))) {
|
|
1575
|
+
if (!canIssueCleanupStatement(canIssueStatement)) break;
|
|
1576
|
+
if (cleanupLease) {
|
|
1577
|
+
await this.markAbandonedCandidatesForCleanup(idBatch, cutoff, cleanupLease);
|
|
1578
|
+
if (!canIssueCleanupStatement(canIssueStatement)) break;
|
|
1579
|
+
}
|
|
1580
|
+
let query = this.db.deleteFrom("_emdash_media_usage").where("id", "in", idBatch).where("created_at", "<", cutoff).where((eb) => eb.exists(eb.selectFrom("_emdash_media_usage_sources as source").select("source.source_key").whereRef("source.source_key", "=", "_emdash_media_usage.source_key").whereRef("source.current_generation", "!=", "_emdash_media_usage.generation").whereRef("_emdash_media_usage.created_at", ">=", "source.indexed_at"))).where(this.noActiveGenerationWriteExpression());
|
|
1581
|
+
if (cleanupLease) query = query.where("cleanup_lease_token", "=", cleanupLease.leaseToken).where(this.activeCleanupLeaseExpression(cleanupLease));
|
|
1582
|
+
const result = await query.executeTakeFirst();
|
|
1583
|
+
deleted += Number(result.numDeletedRows ?? 0);
|
|
1584
|
+
}
|
|
1585
|
+
return deleted;
|
|
1586
|
+
}
|
|
1587
|
+
async markOrphanCandidatesForCleanup(ids, cutoff, cleanupLease) {
|
|
1588
|
+
await this.db.updateTable("_emdash_media_usage").set({ cleanup_lease_token: cleanupLease.leaseToken }).where("id", "in", ids).where("created_at", "<", cutoff).where(sql`NOT EXISTS (SELECT 1 FROM _emdash_media_usage_sources source WHERE source.source_key = _emdash_media_usage.source_key)`).where(this.noActiveGenerationWriteExpression()).where(this.activeCleanupLeaseExpression(cleanupLease)).execute();
|
|
1589
|
+
}
|
|
1590
|
+
async markStaleCandidatesForCleanup(ids, cutoff, cleanupLease) {
|
|
1591
|
+
await this.db.updateTable("_emdash_media_usage").set({ cleanup_lease_token: cleanupLease.leaseToken }).where("id", "in", ids).where("created_at", "<", cutoff).where((eb) => eb.exists(eb.selectFrom("_emdash_media_usage_sources as source").select("source.source_key").whereRef("source.source_key", "=", "_emdash_media_usage.source_key").whereRef("source.current_generation", "!=", "_emdash_media_usage.generation").whereRef("_emdash_media_usage.created_at", "<", "source.indexed_at"))).where(this.noActiveGenerationWriteExpression()).where(this.activeCleanupLeaseExpression(cleanupLease)).execute();
|
|
1592
|
+
}
|
|
1593
|
+
async markAbandonedCandidatesForCleanup(ids, cutoff, cleanupLease) {
|
|
1594
|
+
await this.db.updateTable("_emdash_media_usage").set({ cleanup_lease_token: cleanupLease.leaseToken }).where("id", "in", ids).where("created_at", "<", cutoff).where((eb) => eb.exists(eb.selectFrom("_emdash_media_usage_sources as source").select("source.source_key").whereRef("source.source_key", "=", "_emdash_media_usage.source_key").whereRef("source.current_generation", "!=", "_emdash_media_usage.generation").whereRef("_emdash_media_usage.created_at", ">=", "source.indexed_at"))).where(this.noActiveGenerationWriteExpression()).where(this.activeCleanupLeaseExpression(cleanupLease)).execute();
|
|
1595
|
+
}
|
|
1596
|
+
noActiveGenerationWriteExpression(usageTable = "_emdash_media_usage") {
|
|
1597
|
+
return sql`NOT EXISTS (
|
|
1598
|
+
SELECT 1
|
|
1599
|
+
FROM _emdash_media_usage_generation_writes AS writer
|
|
1600
|
+
WHERE writer.source_key = ${sql.ref(`${usageTable}.source_key`)}
|
|
1601
|
+
AND writer.generation = ${sql.ref(`${usageTable}.generation`)}
|
|
1602
|
+
AND ${this.generationWriteLeaseExpiryIsInFuture("writer.expires_at")}
|
|
1603
|
+
)`;
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* Gates a bounded cleanup scan on the lease and the tick's statement budget.
|
|
1607
|
+
*
|
|
1608
|
+
* The budget is re-read after the lease row because that read is itself a
|
|
1609
|
+
* statement: an isolate suspended across it can resume with the budget spent.
|
|
1610
|
+
*/
|
|
1611
|
+
async admitCleanupScan(cleanupLease, canIssueStatement) {
|
|
1612
|
+
if (!canIssueCleanupStatement(canIssueStatement)) return false;
|
|
1613
|
+
if (!cleanupLease) return true;
|
|
1614
|
+
return await this.holdsCleanupLease(cleanupLease) && canIssueCleanupStatement(canIssueStatement);
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Reads the lease row on its own so a lost lease can short-circuit a sweep.
|
|
1618
|
+
*
|
|
1619
|
+
* As a row-level `EXISTS` inside a `LIMIT`ed scan this predicate is constant
|
|
1620
|
+
* across every candidate row: when it is false the limit is unreachable and
|
|
1621
|
+
* the scan reads the whole `created_at` range before returning nothing.
|
|
1622
|
+
* Mutating statements still carry {@link activeCleanupLeaseExpression},
|
|
1623
|
+
* which is what actually fences a displaced owner.
|
|
1624
|
+
*/
|
|
1625
|
+
async holdsCleanupLease(cleanupLease) {
|
|
1626
|
+
let query = this.db.selectFrom("_emdash_media_usage_cleanup").select("task_key").where("task_key", "=", "projection_gc").where("lease_token", "=", cleanupLease.leaseToken).where(this.cleanupLeaseExpiryIsInFuture("_emdash_media_usage_cleanup.lease_expires_at"));
|
|
1627
|
+
if (isPostgres(this.db)) query = query.forUpdate();
|
|
1628
|
+
return await query.executeTakeFirst() !== void 0;
|
|
1629
|
+
}
|
|
1630
|
+
activeCleanupLeaseExpression(cleanupLease) {
|
|
1631
|
+
const rowLock = isPostgres(this.db) ? sql` FOR UPDATE` : sql``;
|
|
1632
|
+
return sql`EXISTS (
|
|
1633
|
+
SELECT 1
|
|
1634
|
+
FROM _emdash_media_usage_cleanup AS cleanup
|
|
1635
|
+
WHERE cleanup.task_key = 'projection_gc'
|
|
1636
|
+
AND cleanup.lease_token = ${cleanupLease.leaseToken}
|
|
1637
|
+
AND ${this.cleanupLeaseExpiryIsInFuture("cleanup.lease_expires_at")}
|
|
1638
|
+
${rowLock}
|
|
1639
|
+
)`;
|
|
1640
|
+
}
|
|
1641
|
+
cleanupLeaseExpiryIsInFuture(column) {
|
|
1642
|
+
const leaseExpiresAt = sql.ref(column);
|
|
1643
|
+
return isPostgres(this.db) ? sql`${leaseExpiresAt}::timestamptz > clock_timestamp()` : sql`${leaseExpiresAt} > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`;
|
|
1644
|
+
}
|
|
1645
|
+
cleanupTimestampIsDue(column) {
|
|
1646
|
+
const timestamp = sql.ref(column);
|
|
1647
|
+
return isPostgres(this.db) ? sql`${timestamp}::timestamptz <= clock_timestamp()` : sql`${timestamp} <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`;
|
|
1648
|
+
}
|
|
1649
|
+
cleanupTimestampOffset(offsetSeconds) {
|
|
1650
|
+
if (isPostgres(this.db)) return sql`to_char(
|
|
1651
|
+
(clock_timestamp() AT TIME ZONE 'UTC') + (${offsetSeconds} * INTERVAL '1 second'),
|
|
1652
|
+
'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
|
|
1653
|
+
)`;
|
|
1654
|
+
return sql`strftime(
|
|
1655
|
+
'%Y-%m-%dT%H:%M:%fZ',
|
|
1656
|
+
'now',
|
|
1657
|
+
${`${offsetSeconds >= 0 ? "+" : ""}${offsetSeconds} seconds`}
|
|
1658
|
+
)`;
|
|
1659
|
+
}
|
|
1660
|
+
generationWriteLeaseHasExpired(column) {
|
|
1661
|
+
const leaseExpiresAt = sql.ref(column);
|
|
1662
|
+
return isPostgres(this.db) ? sql`${leaseExpiresAt}::timestamptz <= clock_timestamp()` : sql`${leaseExpiresAt} <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`;
|
|
1663
|
+
}
|
|
1664
|
+
async deleteSourceKeys(sourceKeys) {
|
|
1665
|
+
const uniqueSourceKeys = [...new Set(sourceKeys)];
|
|
1666
|
+
if (uniqueSourceKeys.length === 0) return 0;
|
|
1667
|
+
return withTransaction(this.db, async (trx) => {
|
|
1668
|
+
await this.lockCleanupBeforeSourceDelete(trx);
|
|
1669
|
+
let deleted = 0;
|
|
1670
|
+
for (const sourceKeyBatch of chunks(uniqueSourceKeys, SQL_BATCH_SIZE)) {
|
|
1671
|
+
const result = await trx.deleteFrom("_emdash_media_usage_sources").where("source_key", "in", sourceKeyBatch).executeTakeFirst();
|
|
1672
|
+
deleted += Number(result.numDeletedRows ?? 0);
|
|
1673
|
+
await trx.updateTable("_emdash_media_usage").set({ cleanup_lease_token: null }).where("source_key", "in", sourceKeyBatch).execute();
|
|
1674
|
+
await trx.deleteFrom("_emdash_media_usage").where("source_key", "in", sourceKeyBatch).execute();
|
|
1675
|
+
}
|
|
1676
|
+
return deleted;
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
async deleteSourceGenerationOccurrences(db, sourceKey, generation) {
|
|
1680
|
+
await db.updateTable("_emdash_media_usage").set({ cleanup_lease_token: null }).where("source_key", "=", sourceKey).where("generation", "=", generation).execute();
|
|
1681
|
+
await db.deleteFrom("_emdash_media_usage").where("source_key", "=", sourceKey).where("generation", "=", generation).execute();
|
|
1682
|
+
}
|
|
1683
|
+
async lockCleanupBeforeSourceDelete(db) {
|
|
1684
|
+
if (!isPostgres(this.db)) return;
|
|
1685
|
+
await sql`
|
|
1686
|
+
SELECT 1
|
|
1687
|
+
FROM _emdash_media_usage_cleanup
|
|
1688
|
+
WHERE task_key = 'projection_gc'
|
|
1689
|
+
FOR SHARE
|
|
1690
|
+
`.execute(db);
|
|
1691
|
+
}
|
|
1692
|
+
async insertOccurrences(db, sourceKey, generation, occurrences, now) {
|
|
1693
|
+
if (occurrences.length === 0) return;
|
|
1694
|
+
const rows = occurrences.map((occurrence) => ({
|
|
1695
|
+
id: ulid(),
|
|
1696
|
+
source_key: sourceKey,
|
|
1697
|
+
generation,
|
|
1698
|
+
field_slug: occurrence.fieldSlug,
|
|
1699
|
+
field_path: occurrence.fieldPath,
|
|
1700
|
+
occurrence_index: occurrence.occurrenceIndex ?? 0,
|
|
1701
|
+
reference_type: occurrence.referenceType,
|
|
1702
|
+
media_id: occurrence.mediaId,
|
|
1703
|
+
provider: occurrence.provider,
|
|
1704
|
+
provider_asset_id: occurrence.providerAssetId,
|
|
1705
|
+
media_kind: occurrence.mediaKind ?? null,
|
|
1706
|
+
mime_type: occurrence.mimeType ?? null,
|
|
1707
|
+
created_at: now
|
|
1708
|
+
}));
|
|
1709
|
+
for (const rowBatch of chunks(rows, OCCURRENCE_INSERT_BATCH_SIZE)) await db.insertInto("_emdash_media_usage").values(rowBatch).execute();
|
|
1710
|
+
}
|
|
1711
|
+
async insertBatchOccurrences(rows) {
|
|
1712
|
+
for (const rowBatch of chunkJsonRows(rows)) await sql`
|
|
1713
|
+
WITH input AS (${this.occurrenceBatchInput(JSON.stringify(rowBatch))})
|
|
1714
|
+
INSERT INTO _emdash_media_usage (
|
|
1715
|
+
id, source_key, generation, field_slug, field_path, occurrence_index,
|
|
1716
|
+
reference_type, media_id, provider, provider_asset_id, media_kind,
|
|
1717
|
+
mime_type, created_at
|
|
1718
|
+
)
|
|
1719
|
+
SELECT
|
|
1720
|
+
id, source_key, generation, field_slug, field_path, occurrence_index,
|
|
1721
|
+
reference_type, media_id, provider, provider_asset_id, media_kind,
|
|
1722
|
+
mime_type, created_at
|
|
1723
|
+
FROM input
|
|
1724
|
+
WHERE EXISTS (
|
|
1725
|
+
SELECT 1
|
|
1726
|
+
FROM _emdash_media_usage_generation_writes AS writer
|
|
1727
|
+
WHERE writer.source_key = input.source_key
|
|
1728
|
+
AND writer.generation = input.generation
|
|
1729
|
+
AND writer.lease_token = input.lease_token
|
|
1730
|
+
AND ${this.generationWriteLeaseExpiryIsInFuture("writer.expires_at")}
|
|
1731
|
+
)
|
|
1732
|
+
`.execute(this.db);
|
|
1733
|
+
}
|
|
1734
|
+
occurrenceBatchInput(payload) {
|
|
1735
|
+
if (isPostgres(this.db)) return sql`
|
|
1736
|
+
SELECT
|
|
1737
|
+
entry.value ->> 'id' AS id,
|
|
1738
|
+
entry.value ->> 'source_key' AS source_key,
|
|
1739
|
+
entry.value ->> 'generation' AS generation,
|
|
1740
|
+
entry.value ->> 'field_slug' AS field_slug,
|
|
1741
|
+
entry.value ->> 'field_path' AS field_path,
|
|
1742
|
+
CAST(entry.value ->> 'occurrence_index' AS integer) AS occurrence_index,
|
|
1743
|
+
entry.value ->> 'reference_type' AS reference_type,
|
|
1744
|
+
entry.value ->> 'media_id' AS media_id,
|
|
1745
|
+
entry.value ->> 'provider' AS provider,
|
|
1746
|
+
entry.value ->> 'provider_asset_id' AS provider_asset_id,
|
|
1747
|
+
entry.value ->> 'media_kind' AS media_kind,
|
|
1748
|
+
entry.value ->> 'mime_type' AS mime_type,
|
|
1749
|
+
entry.value ->> 'created_at' AS created_at,
|
|
1750
|
+
entry.value ->> 'lease_token' AS lease_token
|
|
1751
|
+
FROM jsonb_array_elements(${payload}::jsonb) AS entry(value)
|
|
1752
|
+
`;
|
|
1753
|
+
return sql`
|
|
1754
|
+
SELECT
|
|
1755
|
+
json_extract(entry.value, '$.id') AS id,
|
|
1756
|
+
json_extract(entry.value, '$.source_key') AS source_key,
|
|
1757
|
+
json_extract(entry.value, '$.generation') AS generation,
|
|
1758
|
+
json_extract(entry.value, '$.field_slug') AS field_slug,
|
|
1759
|
+
json_extract(entry.value, '$.field_path') AS field_path,
|
|
1760
|
+
CAST(json_extract(entry.value, '$.occurrence_index') AS integer) AS occurrence_index,
|
|
1761
|
+
json_extract(entry.value, '$.reference_type') AS reference_type,
|
|
1762
|
+
json_extract(entry.value, '$.media_id') AS media_id,
|
|
1763
|
+
json_extract(entry.value, '$.provider') AS provider,
|
|
1764
|
+
json_extract(entry.value, '$.provider_asset_id') AS provider_asset_id,
|
|
1765
|
+
json_extract(entry.value, '$.media_kind') AS media_kind,
|
|
1766
|
+
json_extract(entry.value, '$.mime_type') AS mime_type,
|
|
1767
|
+
json_extract(entry.value, '$.created_at') AS created_at,
|
|
1768
|
+
json_extract(entry.value, '$.lease_token') AS lease_token
|
|
1769
|
+
FROM json_each(${payload}) AS entry
|
|
1770
|
+
`;
|
|
1771
|
+
}
|
|
1772
|
+
sourceBatchInput(payload) {
|
|
1773
|
+
if (isPostgres(this.db)) return sql`
|
|
1774
|
+
SELECT
|
|
1775
|
+
entry.value ->> 'source_key' AS source_key,
|
|
1776
|
+
entry.value ->> 'source_type' AS source_type,
|
|
1777
|
+
entry.value ->> 'collection_id' AS collection_id,
|
|
1778
|
+
entry.value ->> 'collection_slug' AS collection_slug,
|
|
1779
|
+
entry.value ->> 'content_id' AS content_id,
|
|
1780
|
+
entry.value ->> 'source_variant' AS source_variant,
|
|
1781
|
+
entry.value ->> 'locale' AS locale,
|
|
1782
|
+
entry.value ->> 'translation_group' AS translation_group,
|
|
1783
|
+
entry.value ->> 'content_slug' AS content_slug,
|
|
1784
|
+
entry.value ->> 'content_title' AS content_title,
|
|
1785
|
+
entry.value ->> 'content_status' AS content_status,
|
|
1786
|
+
entry.value ->> 'content_scheduled_at' AS content_scheduled_at,
|
|
1787
|
+
entry.value ->> 'content_deleted_at' AS content_deleted_at,
|
|
1788
|
+
entry.value ->> 'revision_id' AS revision_id,
|
|
1789
|
+
entry.value ->> 'current_generation' AS current_generation,
|
|
1790
|
+
CAST(entry.value ->> 'schema_version' AS integer) AS schema_version,
|
|
1791
|
+
entry.value ->> 'source_updated_at' AS source_updated_at,
|
|
1792
|
+
CAST(entry.value ->> 'source_version' AS bigint) AS source_version,
|
|
1793
|
+
entry.value ->> 'source_fingerprint' AS source_fingerprint,
|
|
1794
|
+
CAST(entry.value ->> 'identity_version' AS integer) AS identity_version,
|
|
1795
|
+
entry.value ->> 'source_completeness' AS source_completeness,
|
|
1796
|
+
entry.value ->> 'last_attempted_at' AS last_attempted_at,
|
|
1797
|
+
entry.value ->> 'last_error_code' AS last_error_code,
|
|
1798
|
+
entry.value ->> 'indexed_at' AS indexed_at,
|
|
1799
|
+
entry.value ->> 'updated_at' AS updated_at,
|
|
1800
|
+
entry.value ->> 'lease_token' AS lease_token,
|
|
1801
|
+
entry.value ->> 'expected_generation' AS expected_generation,
|
|
1802
|
+
entry.value ->> 'expected_collection_id' AS expected_collection_id,
|
|
1803
|
+
entry.value ->> 'expected_updated_at' AS expected_updated_at,
|
|
1804
|
+
entry.value ->> 'expected_source_fingerprint' AS expected_source_fingerprint,
|
|
1805
|
+
entry.value ->> 'expected_source_updated_at' AS expected_source_updated_at,
|
|
1806
|
+
CAST(entry.value ->> 'expected_source_version' AS bigint) AS expected_source_version,
|
|
1807
|
+
CAST(entry.value ->> 'expected_identity_version' AS integer) AS expected_identity_version,
|
|
1808
|
+
entry.value ->> 'expected_revision_id' AS expected_revision_id,
|
|
1809
|
+
entry.value ->> 'expected_source_completeness' AS expected_source_completeness,
|
|
1810
|
+
entry.value ->> 'expected_last_attempted_at' AS expected_last_attempted_at,
|
|
1811
|
+
entry.value ->> 'expected_last_error_code' AS expected_last_error_code
|
|
1812
|
+
FROM jsonb_array_elements(${payload}::jsonb) AS entry(value)
|
|
1813
|
+
`;
|
|
1814
|
+
return sql`
|
|
1815
|
+
SELECT
|
|
1816
|
+
json_extract(entry.value, '$.source_key') AS source_key,
|
|
1817
|
+
json_extract(entry.value, '$.source_type') AS source_type,
|
|
1818
|
+
json_extract(entry.value, '$.collection_id') AS collection_id,
|
|
1819
|
+
json_extract(entry.value, '$.collection_slug') AS collection_slug,
|
|
1820
|
+
json_extract(entry.value, '$.content_id') AS content_id,
|
|
1821
|
+
json_extract(entry.value, '$.source_variant') AS source_variant,
|
|
1822
|
+
json_extract(entry.value, '$.locale') AS locale,
|
|
1823
|
+
json_extract(entry.value, '$.translation_group') AS translation_group,
|
|
1824
|
+
json_extract(entry.value, '$.content_slug') AS content_slug,
|
|
1825
|
+
json_extract(entry.value, '$.content_title') AS content_title,
|
|
1826
|
+
json_extract(entry.value, '$.content_status') AS content_status,
|
|
1827
|
+
json_extract(entry.value, '$.content_scheduled_at') AS content_scheduled_at,
|
|
1828
|
+
json_extract(entry.value, '$.content_deleted_at') AS content_deleted_at,
|
|
1829
|
+
json_extract(entry.value, '$.revision_id') AS revision_id,
|
|
1830
|
+
json_extract(entry.value, '$.current_generation') AS current_generation,
|
|
1831
|
+
CAST(json_extract(entry.value, '$.schema_version') AS integer) AS schema_version,
|
|
1832
|
+
json_extract(entry.value, '$.source_updated_at') AS source_updated_at,
|
|
1833
|
+
CAST(json_extract(entry.value, '$.source_version') AS integer) AS source_version,
|
|
1834
|
+
json_extract(entry.value, '$.source_fingerprint') AS source_fingerprint,
|
|
1835
|
+
CAST(json_extract(entry.value, '$.identity_version') AS integer) AS identity_version,
|
|
1836
|
+
json_extract(entry.value, '$.source_completeness') AS source_completeness,
|
|
1837
|
+
json_extract(entry.value, '$.last_attempted_at') AS last_attempted_at,
|
|
1838
|
+
json_extract(entry.value, '$.last_error_code') AS last_error_code,
|
|
1839
|
+
json_extract(entry.value, '$.indexed_at') AS indexed_at,
|
|
1840
|
+
json_extract(entry.value, '$.updated_at') AS updated_at,
|
|
1841
|
+
json_extract(entry.value, '$.lease_token') AS lease_token,
|
|
1842
|
+
json_extract(entry.value, '$.expected_generation') AS expected_generation,
|
|
1843
|
+
json_extract(entry.value, '$.expected_collection_id') AS expected_collection_id,
|
|
1844
|
+
json_extract(entry.value, '$.expected_updated_at') AS expected_updated_at,
|
|
1845
|
+
json_extract(entry.value, '$.expected_source_fingerprint') AS expected_source_fingerprint,
|
|
1846
|
+
json_extract(entry.value, '$.expected_source_updated_at') AS expected_source_updated_at,
|
|
1847
|
+
CAST(json_extract(entry.value, '$.expected_source_version') AS integer) AS expected_source_version,
|
|
1848
|
+
CAST(json_extract(entry.value, '$.expected_identity_version') AS integer) AS expected_identity_version,
|
|
1849
|
+
json_extract(entry.value, '$.expected_revision_id') AS expected_revision_id,
|
|
1850
|
+
json_extract(entry.value, '$.expected_source_completeness') AS expected_source_completeness,
|
|
1851
|
+
json_extract(entry.value, '$.expected_last_attempted_at') AS expected_last_attempted_at,
|
|
1852
|
+
json_extract(entry.value, '$.expected_last_error_code') AS expected_last_error_code
|
|
1853
|
+
FROM json_each(${payload}) AS entry
|
|
1854
|
+
`;
|
|
1855
|
+
}
|
|
1856
|
+
generationWriteBatchInput(payload) {
|
|
1857
|
+
if (isPostgres(this.db)) return sql`
|
|
1858
|
+
SELECT
|
|
1859
|
+
entry.value ->> 'source_key' AS source_key,
|
|
1860
|
+
entry.value ->> 'collection_id' AS collection_id,
|
|
1861
|
+
entry.value ->> 'collection_slug' AS collection_slug,
|
|
1862
|
+
entry.value ->> 'generation' AS generation,
|
|
1863
|
+
entry.value ->> 'lease_token' AS lease_token,
|
|
1864
|
+
entry.value ->> 'expires_at' AS expires_at,
|
|
1865
|
+
entry.value ->> 'created_at' AS created_at
|
|
1866
|
+
FROM jsonb_array_elements(${payload}::jsonb) AS entry(value)
|
|
1867
|
+
`;
|
|
1868
|
+
return sql`
|
|
1869
|
+
SELECT
|
|
1870
|
+
json_extract(entry.value, '$.source_key') AS source_key,
|
|
1871
|
+
json_extract(entry.value, '$.collection_id') AS collection_id,
|
|
1872
|
+
json_extract(entry.value, '$.collection_slug') AS collection_slug,
|
|
1873
|
+
json_extract(entry.value, '$.generation') AS generation,
|
|
1874
|
+
json_extract(entry.value, '$.lease_token') AS lease_token,
|
|
1875
|
+
json_extract(entry.value, '$.expires_at') AS expires_at,
|
|
1876
|
+
json_extract(entry.value, '$.created_at') AS created_at
|
|
1877
|
+
FROM json_each(${payload}) AS entry
|
|
1878
|
+
`;
|
|
1879
|
+
}
|
|
1880
|
+
batchRefsMatch(left, right) {
|
|
1881
|
+
const leftRef = sql.ref(left);
|
|
1882
|
+
const rightRef = sql.ref(right);
|
|
1883
|
+
return isPostgres(this.db) ? sql`${leftRef} IS NOT DISTINCT FROM ${rightRef}` : sql`${leftRef} IS ${rightRef}`;
|
|
1884
|
+
}
|
|
1885
|
+
async lockCanonicalSourceCollection(db, source) {
|
|
1886
|
+
if (source.collectionId === void 0 || source.collectionId === null) return true;
|
|
1887
|
+
if (!source.collectionSlug) return false;
|
|
1888
|
+
if (!isPostgres(this.db)) return true;
|
|
1889
|
+
return await db.selectFrom("_emdash_collections").select("id").where("id", "=", source.collectionId).where("slug", "=", source.collectionSlug).forKeyShare().executeTakeFirst() !== void 0;
|
|
1890
|
+
}
|
|
1891
|
+
async upsertSource(db, source, generation, now, leaseToken) {
|
|
1892
|
+
const row = this.buildSourceRow(source, generation, now);
|
|
1893
|
+
return this.persistSourceIfWriteLease(db, row, leaseToken, sql`
|
|
1894
|
+
ON CONFLICT (source_key) DO UPDATE SET
|
|
1895
|
+
source_type = excluded.source_type,
|
|
1896
|
+
collection_id = excluded.collection_id,
|
|
1897
|
+
collection_slug = excluded.collection_slug,
|
|
1898
|
+
content_id = excluded.content_id,
|
|
1899
|
+
source_variant = excluded.source_variant,
|
|
1900
|
+
locale = excluded.locale,
|
|
1901
|
+
translation_group = excluded.translation_group,
|
|
1902
|
+
content_slug = excluded.content_slug,
|
|
1903
|
+
content_title = excluded.content_title,
|
|
1904
|
+
content_status = excluded.content_status,
|
|
1905
|
+
content_scheduled_at = excluded.content_scheduled_at,
|
|
1906
|
+
content_deleted_at = excluded.content_deleted_at,
|
|
1907
|
+
revision_id = excluded.revision_id,
|
|
1908
|
+
current_generation = excluded.current_generation,
|
|
1909
|
+
schema_version = excluded.schema_version,
|
|
1910
|
+
source_updated_at = excluded.source_updated_at,
|
|
1911
|
+
source_version = excluded.source_version,
|
|
1912
|
+
source_fingerprint = excluded.source_fingerprint,
|
|
1913
|
+
identity_version = excluded.identity_version,
|
|
1914
|
+
source_completeness = excluded.source_completeness,
|
|
1915
|
+
last_attempted_at = excluded.last_attempted_at,
|
|
1916
|
+
last_error_code = excluded.last_error_code,
|
|
1917
|
+
indexed_at = excluded.indexed_at,
|
|
1918
|
+
updated_at = excluded.updated_at
|
|
1919
|
+
`);
|
|
1920
|
+
}
|
|
1921
|
+
async insertSourceIfAbsent(db, row, leaseToken) {
|
|
1922
|
+
return this.persistSourceIfWriteLease(db, row, leaseToken, sql`ON CONFLICT (source_key) DO NOTHING`);
|
|
1923
|
+
}
|
|
1924
|
+
async persistSourceIfWriteLease(db, row, leaseToken, conflict) {
|
|
1925
|
+
const result = await sql`
|
|
1926
|
+
INSERT INTO _emdash_media_usage_sources (
|
|
1927
|
+
source_key,
|
|
1928
|
+
source_type,
|
|
1929
|
+
collection_id,
|
|
1930
|
+
collection_slug,
|
|
1931
|
+
content_id,
|
|
1932
|
+
source_variant,
|
|
1933
|
+
locale,
|
|
1934
|
+
translation_group,
|
|
1935
|
+
content_slug,
|
|
1936
|
+
content_title,
|
|
1937
|
+
content_status,
|
|
1938
|
+
content_scheduled_at,
|
|
1939
|
+
content_deleted_at,
|
|
1940
|
+
revision_id,
|
|
1941
|
+
current_generation,
|
|
1942
|
+
schema_version,
|
|
1943
|
+
source_updated_at,
|
|
1944
|
+
source_version,
|
|
1945
|
+
source_fingerprint,
|
|
1946
|
+
identity_version,
|
|
1947
|
+
source_completeness,
|
|
1948
|
+
last_attempted_at,
|
|
1949
|
+
last_error_code,
|
|
1950
|
+
indexed_at,
|
|
1951
|
+
updated_at
|
|
1952
|
+
)
|
|
1953
|
+
SELECT
|
|
1954
|
+
${row.source_key},
|
|
1955
|
+
${row.source_type},
|
|
1956
|
+
${row.collection_id},
|
|
1957
|
+
${row.collection_slug},
|
|
1958
|
+
${row.content_id},
|
|
1959
|
+
${row.source_variant},
|
|
1960
|
+
${row.locale},
|
|
1961
|
+
${row.translation_group},
|
|
1962
|
+
${row.content_slug},
|
|
1963
|
+
${row.content_title},
|
|
1964
|
+
${row.content_status},
|
|
1965
|
+
${row.content_scheduled_at},
|
|
1966
|
+
${row.content_deleted_at},
|
|
1967
|
+
${row.revision_id},
|
|
1968
|
+
${row.current_generation},
|
|
1969
|
+
${row.schema_version},
|
|
1970
|
+
${row.source_updated_at},
|
|
1971
|
+
${row.source_version},
|
|
1972
|
+
${row.source_fingerprint},
|
|
1973
|
+
${row.identity_version},
|
|
1974
|
+
${row.source_completeness},
|
|
1975
|
+
${row.last_attempted_at},
|
|
1976
|
+
${row.last_error_code},
|
|
1977
|
+
${row.indexed_at},
|
|
1978
|
+
${row.updated_at}
|
|
1979
|
+
WHERE EXISTS (
|
|
1980
|
+
SELECT 1
|
|
1981
|
+
FROM _emdash_media_usage_generation_writes
|
|
1982
|
+
WHERE source_key = ${row.source_key}
|
|
1983
|
+
AND generation = ${row.current_generation}
|
|
1984
|
+
AND lease_token = ${leaseToken}
|
|
1985
|
+
AND ${this.generationWriteLeaseExpiryIsInFuture("expires_at")}
|
|
1986
|
+
)
|
|
1987
|
+
AND ${this.currentCollectionExists(row.collection_id, row.collection_slug)}
|
|
1988
|
+
AND ${this.currentCanonicalContentExists(row)}
|
|
1989
|
+
${conflict}
|
|
1990
|
+
`.execute(db);
|
|
1991
|
+
return Number(result.numAffectedRows ?? 0) > 0;
|
|
1992
|
+
}
|
|
1993
|
+
generationWriteLeaseExpression(row, leaseToken) {
|
|
1994
|
+
return (eb) => eb.exists(eb.selectFrom("_emdash_media_usage_generation_writes").select("source_key").where("source_key", "=", row.source_key).where("generation", "=", row.current_generation).where("lease_token", "=", leaseToken).where(this.generationWriteLeaseExpiryIsInFuture("_emdash_media_usage_generation_writes.expires_at")));
|
|
1995
|
+
}
|
|
1996
|
+
generationWriteLeaseExpiryIsInFuture(column) {
|
|
1997
|
+
const leaseExpiresAt = sql.ref(column);
|
|
1998
|
+
return isPostgres(this.db) ? sql`${leaseExpiresAt}::timestamptz > clock_timestamp()` : sql`${leaseExpiresAt} > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`;
|
|
1999
|
+
}
|
|
2000
|
+
async withGenerationWriteLease(source, generation, write) {
|
|
2001
|
+
const leaseToken = ulid();
|
|
2002
|
+
const owner = (await sql`
|
|
2003
|
+
INSERT INTO _emdash_media_usage_generation_writes (
|
|
2004
|
+
source_key, generation, lease_token, expires_at, created_at
|
|
2005
|
+
)
|
|
2006
|
+
SELECT
|
|
2007
|
+
${source.sourceKey},
|
|
2008
|
+
${generation},
|
|
2009
|
+
${leaseToken},
|
|
2010
|
+
${this.generationWriteLeaseTimestampOffset(MEDIA_USAGE_GENERATION_WRITE_LEASE_MS / 1e3)},
|
|
2011
|
+
${this.generationWriteLeaseTimestampOffset(0)}
|
|
2012
|
+
WHERE ${this.currentCollectionExists(source.collectionId ?? null, source.collectionSlug ?? null)}
|
|
2013
|
+
RETURNING created_at
|
|
2014
|
+
`.execute(this.db)).rows[0];
|
|
2015
|
+
if (!owner) return false;
|
|
2016
|
+
try {
|
|
2017
|
+
await write(leaseToken, owner.created_at);
|
|
2018
|
+
return true;
|
|
2019
|
+
} finally {
|
|
2020
|
+
try {
|
|
2021
|
+
await this.db.deleteFrom("_emdash_media_usage_generation_writes").where("source_key", "=", source.sourceKey).where("generation", "=", generation).where("lease_token", "=", leaseToken).execute();
|
|
2022
|
+
} catch (error) {
|
|
2023
|
+
console.error("[media-usage] Failed to release generation write lease:", error);
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
generationWriteLeaseTimestampOffset(offsetSeconds) {
|
|
2028
|
+
if (isPostgres(this.db)) return sql`to_char(
|
|
2029
|
+
(clock_timestamp() AT TIME ZONE 'UTC') + (${offsetSeconds} * INTERVAL '1 second'),
|
|
2030
|
+
'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'
|
|
2031
|
+
)`;
|
|
2032
|
+
return sql`strftime(
|
|
2033
|
+
'%Y-%m-%dT%H:%M:%fZ',
|
|
2034
|
+
'now',
|
|
2035
|
+
${`${offsetSeconds >= 0 ? "+" : ""}${offsetSeconds} seconds`}
|
|
2036
|
+
)`;
|
|
2037
|
+
}
|
|
2038
|
+
async updateSourceIfGeneration(db, row, expectedCurrentGeneration, leaseToken) {
|
|
2039
|
+
const result = await db.updateTable("_emdash_media_usage_sources").set(this.sourceUpdateSet(row)).where("source_key", "=", row.source_key).where("current_generation", "=", expectedCurrentGeneration).where(this.generationWriteLeaseExpression(row, leaseToken)).where(this.currentCollectionExists(row.collection_id, row.collection_slug)).where(this.currentCanonicalContentExists(row)).executeTakeFirst();
|
|
2040
|
+
return Number(result.numUpdatedRows ?? 0) > 0;
|
|
2041
|
+
}
|
|
2042
|
+
async updateSourceIfMatching(db, row, expectedSource, leaseToken) {
|
|
2043
|
+
const result = await db.updateTable("_emdash_media_usage_sources").set(this.sourceUpdateSet(row)).where("source_key", "=", row.source_key).where(this.sourceMatchExpression(expectedSource)).where(this.generationWriteLeaseExpression(row, leaseToken)).where(this.currentCollectionExists(row.collection_id, row.collection_slug)).where(this.currentCanonicalContentExists(row)).executeTakeFirst();
|
|
2044
|
+
return Number(result.numUpdatedRows ?? 0) > 0;
|
|
2045
|
+
}
|
|
2046
|
+
async updateAttemptedSourceIfMatching(db, source, row, expectedSource) {
|
|
2047
|
+
const result = await db.updateTable("_emdash_media_usage_sources").set(this.attemptedSourceUpdateSet(source, row)).where("source_key", "=", row.source_key).where(this.sourceMatchExpression(expectedSource)).where(this.currentCollectionExists(row.collection_id, row.collection_slug)).where(this.currentCanonicalContentExists(row)).executeTakeFirst();
|
|
2048
|
+
return Number(result.numUpdatedRows ?? 0) > 0;
|
|
2049
|
+
}
|
|
2050
|
+
sourceMatchExpression(expectedSource) {
|
|
2051
|
+
return (eb) => eb.and([
|
|
2052
|
+
eb("current_generation", "=", expectedSource.currentGeneration),
|
|
2053
|
+
eb("source_completeness", "=", expectedSource.sourceCompleteness),
|
|
2054
|
+
this.nullableStringExpression(eb, "collection_id", expectedSource.collectionId),
|
|
2055
|
+
this.nullableStringExpression(eb, "updated_at", expectedSource.updatedAt),
|
|
2056
|
+
this.nullableStringExpression(eb, "source_fingerprint", expectedSource.sourceFingerprint),
|
|
2057
|
+
this.nullableStringExpression(eb, "source_updated_at", expectedSource.sourceUpdatedAt),
|
|
2058
|
+
this.nullableNumberExpression(eb, "source_version", expectedSource.sourceVersion),
|
|
2059
|
+
this.nullableNumberExpression(eb, "identity_version", expectedSource.identityVersion),
|
|
2060
|
+
this.nullableStringExpression(eb, "revision_id", expectedSource.revisionId),
|
|
2061
|
+
this.nullableStringExpression(eb, "last_attempted_at", expectedSource.lastAttemptedAt),
|
|
2062
|
+
this.nullableStringExpression(eb, "last_error_code", expectedSource.lastErrorCode)
|
|
2063
|
+
]);
|
|
2064
|
+
}
|
|
2065
|
+
async projectionMatchesCurrentGeneration(source, expectedCurrentGeneration) {
|
|
2066
|
+
const fingerprint = source.sourceFingerprint;
|
|
2067
|
+
if (!isMediaUsageProjectionFingerprint(fingerprint)) return false;
|
|
2068
|
+
return await this.db.selectFrom("_emdash_media_usage_sources").select("source_key").where("source_key", "=", source.sourceKey).where("current_generation", "=", expectedCurrentGeneration).where("source_fingerprint", "=", fingerprint).where("source_completeness", "=", source.sourceCompleteness ?? "complete").where("last_error_code", "is", null).where(this.currentCollectionExists(source.collectionId ?? null, source.collectionSlug ?? null)).executeTakeFirst() !== void 0;
|
|
2069
|
+
}
|
|
2070
|
+
async projectionMatchesExpectedSource(source, expectedSource) {
|
|
2071
|
+
const fingerprint = source.sourceFingerprint;
|
|
2072
|
+
if (!isMediaUsageProjectionFingerprint(fingerprint) || expectedSource.sourceFingerprint !== fingerprint || expectedSource.sourceCompleteness !== (source.sourceCompleteness ?? "complete") || expectedSource.lastErrorCode !== null) return false;
|
|
2073
|
+
return await this.db.selectFrom("_emdash_media_usage_sources").select("source_key").where("source_key", "=", source.sourceKey).where(this.sourceMatchExpression(expectedSource)).where(this.currentCollectionExists(source.collectionId ?? null, source.collectionSlug ?? null)).executeTakeFirst() !== void 0;
|
|
2074
|
+
}
|
|
2075
|
+
nullableStringExpression(eb, column, value) {
|
|
2076
|
+
return value === null ? eb(column, "is", null) : eb(column, "=", value);
|
|
2077
|
+
}
|
|
2078
|
+
currentCollectionExists(collectionId, collectionSlug) {
|
|
2079
|
+
if (collectionId === null) return sql`1 = 1`;
|
|
2080
|
+
return sql`EXISTS (
|
|
2081
|
+
SELECT 1
|
|
2082
|
+
FROM _emdash_collections
|
|
2083
|
+
WHERE id = ${collectionId}
|
|
2084
|
+
AND slug = ${collectionSlug}
|
|
2085
|
+
)`;
|
|
2086
|
+
}
|
|
2087
|
+
currentCanonicalContentExists(row) {
|
|
2088
|
+
if (row.collection_id === null || row.identity_version !== 1 || row.source_type !== "content") return sql`1 = 1`;
|
|
2089
|
+
if (!row.collection_slug || !row.content_id || row.source_version === null || row.source_updated_at === null) return sql`1 = 0`;
|
|
2090
|
+
validateIdentifier(row.collection_slug, "collection slug");
|
|
2091
|
+
const tableName = `ec_${row.collection_slug}`;
|
|
2092
|
+
validateIdentifier(tableName, "content table");
|
|
2093
|
+
const revisionColumn = row.source_variant === "columns" ? "live_revision_id" : row.source_variant === "draft_overlay" ? "draft_revision_id" : null;
|
|
2094
|
+
if (!revisionColumn) return sql`1 = 0`;
|
|
2095
|
+
const revision = sql.ref(`content.${revisionColumn}`);
|
|
2096
|
+
const revisionMatches = row.revision_id === null ? sql`${revision} IS NULL` : sql`${revision} = ${row.revision_id}`;
|
|
2097
|
+
return sql`EXISTS (
|
|
2098
|
+
SELECT 1
|
|
2099
|
+
FROM ${sql.ref(tableName)} AS content
|
|
2100
|
+
WHERE content.id = ${row.content_id}
|
|
2101
|
+
AND content.version = ${row.source_version}
|
|
2102
|
+
AND content.updated_at = ${row.source_updated_at}
|
|
2103
|
+
AND ${revisionMatches}
|
|
2104
|
+
)`;
|
|
2105
|
+
}
|
|
2106
|
+
nullableNumberExpression(eb, column, value) {
|
|
2107
|
+
return value === null ? eb(column, "is", null) : eb(column, "=", value);
|
|
2108
|
+
}
|
|
2109
|
+
async contentRowExists(tableName, contentId) {
|
|
2110
|
+
return (await sql`
|
|
2111
|
+
SELECT id
|
|
2112
|
+
FROM ${sql.ref(tableName)}
|
|
2113
|
+
WHERE id = ${contentId}
|
|
2114
|
+
LIMIT 1
|
|
2115
|
+
`.execute(this.db)).rows.length > 0;
|
|
2116
|
+
}
|
|
2117
|
+
buildSourceRow(source, generation, now) {
|
|
2118
|
+
return {
|
|
2119
|
+
source_key: source.sourceKey,
|
|
2120
|
+
source_type: source.sourceType,
|
|
2121
|
+
collection_id: source.collectionId ?? null,
|
|
2122
|
+
collection_slug: source.collectionSlug ?? null,
|
|
2123
|
+
content_id: source.contentId ?? null,
|
|
2124
|
+
source_variant: source.sourceVariant,
|
|
2125
|
+
locale: source.locale ?? null,
|
|
2126
|
+
translation_group: source.translationGroup ?? null,
|
|
2127
|
+
content_slug: source.contentSlug ?? null,
|
|
2128
|
+
content_title: source.contentTitle ?? null,
|
|
2129
|
+
content_status: source.contentStatus ?? null,
|
|
2130
|
+
content_scheduled_at: source.contentScheduledAt ?? null,
|
|
2131
|
+
content_deleted_at: source.contentDeletedAt ?? null,
|
|
2132
|
+
revision_id: source.revisionId ?? null,
|
|
2133
|
+
current_generation: generation,
|
|
2134
|
+
schema_version: source.schemaVersion ?? 1,
|
|
2135
|
+
source_updated_at: source.sourceUpdatedAt ?? null,
|
|
2136
|
+
source_version: source.sourceVersion ?? null,
|
|
2137
|
+
source_fingerprint: source.sourceFingerprint ?? null,
|
|
2138
|
+
identity_version: source.identityVersion ?? null,
|
|
2139
|
+
source_completeness: source.sourceCompleteness ?? "complete",
|
|
2140
|
+
last_attempted_at: source.lastAttemptedAt ?? now,
|
|
2141
|
+
last_error_code: null,
|
|
2142
|
+
indexed_at: now,
|
|
2143
|
+
updated_at: now
|
|
2144
|
+
};
|
|
2145
|
+
}
|
|
2146
|
+
buildAttemptedSourceRow(source, generation, now) {
|
|
2147
|
+
return {
|
|
2148
|
+
source_key: source.sourceKey,
|
|
2149
|
+
source_type: source.sourceType,
|
|
2150
|
+
collection_id: source.collectionId ?? null,
|
|
2151
|
+
collection_slug: source.collectionSlug ?? null,
|
|
2152
|
+
content_id: source.contentId ?? null,
|
|
2153
|
+
source_variant: source.sourceVariant,
|
|
2154
|
+
locale: source.locale ?? null,
|
|
2155
|
+
translation_group: source.translationGroup ?? null,
|
|
2156
|
+
content_slug: source.contentSlug ?? null,
|
|
2157
|
+
content_title: source.contentTitle ?? null,
|
|
2158
|
+
content_status: source.contentStatus ?? null,
|
|
2159
|
+
content_scheduled_at: source.contentScheduledAt ?? null,
|
|
2160
|
+
content_deleted_at: source.contentDeletedAt ?? null,
|
|
2161
|
+
revision_id: source.revisionId ?? null,
|
|
2162
|
+
current_generation: generation,
|
|
2163
|
+
schema_version: source.schemaVersion ?? 1,
|
|
2164
|
+
source_updated_at: source.sourceUpdatedAt ?? null,
|
|
2165
|
+
source_version: source.sourceVersion ?? null,
|
|
2166
|
+
source_fingerprint: source.sourceFingerprint ?? null,
|
|
2167
|
+
identity_version: source.identityVersion ?? null,
|
|
2168
|
+
source_completeness: source.sourceCompleteness ?? (source.lastErrorCode ? "failed" : "unknown"),
|
|
2169
|
+
last_attempted_at: source.lastAttemptedAt ?? now,
|
|
2170
|
+
last_error_code: source.lastErrorCode ?? null,
|
|
2171
|
+
indexed_at: now,
|
|
2172
|
+
updated_at: now
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
attemptedSourceUpdateSet(source, row) {
|
|
2176
|
+
const updates = {
|
|
2177
|
+
source_type: row.source_type,
|
|
2178
|
+
source_variant: row.source_variant,
|
|
2179
|
+
source_completeness: row.source_completeness,
|
|
2180
|
+
last_attempted_at: row.last_attempted_at,
|
|
2181
|
+
last_error_code: row.last_error_code,
|
|
2182
|
+
updated_at: row.updated_at
|
|
2183
|
+
};
|
|
2184
|
+
if (source.collectionSlug !== void 0) updates.collection_slug = row.collection_slug;
|
|
2185
|
+
if (source.collectionId !== void 0) updates.collection_id = row.collection_id;
|
|
2186
|
+
if (source.contentId !== void 0) updates.content_id = row.content_id;
|
|
2187
|
+
if (source.locale !== void 0) updates.locale = row.locale;
|
|
2188
|
+
if (source.translationGroup !== void 0) updates.translation_group = row.translation_group;
|
|
2189
|
+
if (source.contentSlug !== void 0) updates.content_slug = row.content_slug;
|
|
2190
|
+
if (source.contentTitle !== void 0) updates.content_title = row.content_title;
|
|
2191
|
+
if (source.contentStatus !== void 0) updates.content_status = row.content_status;
|
|
2192
|
+
if (source.contentScheduledAt !== void 0) updates.content_scheduled_at = row.content_scheduled_at;
|
|
2193
|
+
if (source.contentDeletedAt !== void 0) updates.content_deleted_at = row.content_deleted_at;
|
|
2194
|
+
if (source.revisionId !== void 0) updates.revision_id = row.revision_id;
|
|
2195
|
+
if (source.schemaVersion !== void 0) updates.schema_version = row.schema_version;
|
|
2196
|
+
if (source.sourceUpdatedAt !== void 0) updates.source_updated_at = row.source_updated_at;
|
|
2197
|
+
if (source.sourceVersion !== void 0) updates.source_version = row.source_version;
|
|
2198
|
+
if (source.sourceFingerprint !== void 0) updates.source_fingerprint = row.source_fingerprint;
|
|
2199
|
+
if (source.identityVersion !== void 0) updates.identity_version = row.identity_version;
|
|
2200
|
+
return updates;
|
|
2201
|
+
}
|
|
2202
|
+
sourceUpdateSet(row) {
|
|
2203
|
+
return {
|
|
2204
|
+
source_type: row.source_type,
|
|
2205
|
+
collection_id: row.collection_id,
|
|
2206
|
+
collection_slug: row.collection_slug,
|
|
2207
|
+
content_id: row.content_id,
|
|
2208
|
+
source_variant: row.source_variant,
|
|
2209
|
+
locale: row.locale,
|
|
2210
|
+
translation_group: row.translation_group,
|
|
2211
|
+
content_slug: row.content_slug,
|
|
2212
|
+
content_title: row.content_title,
|
|
2213
|
+
content_status: row.content_status,
|
|
2214
|
+
content_scheduled_at: row.content_scheduled_at,
|
|
2215
|
+
content_deleted_at: row.content_deleted_at,
|
|
2216
|
+
revision_id: row.revision_id,
|
|
2217
|
+
current_generation: row.current_generation,
|
|
2218
|
+
schema_version: row.schema_version,
|
|
2219
|
+
source_updated_at: row.source_updated_at,
|
|
2220
|
+
source_version: row.source_version,
|
|
2221
|
+
source_fingerprint: row.source_fingerprint,
|
|
2222
|
+
identity_version: row.identity_version,
|
|
2223
|
+
source_completeness: row.source_completeness,
|
|
2224
|
+
last_attempted_at: row.last_attempted_at,
|
|
2225
|
+
last_error_code: row.last_error_code,
|
|
2226
|
+
indexed_at: row.indexed_at,
|
|
2227
|
+
updated_at: row.updated_at
|
|
2228
|
+
};
|
|
2229
|
+
}
|
|
2230
|
+
};
|
|
2231
|
+
const currentUsageSelect = [
|
|
2232
|
+
"s.source_key as source_key",
|
|
2233
|
+
"s.source_type as source_type",
|
|
2234
|
+
"s.collection_id as collection_id",
|
|
2235
|
+
"s.collection_slug as collection_slug",
|
|
2236
|
+
"s.content_id as content_id",
|
|
2237
|
+
"s.source_variant as source_variant",
|
|
2238
|
+
"s.locale as locale",
|
|
2239
|
+
"s.translation_group as translation_group",
|
|
2240
|
+
"s.content_slug as content_slug",
|
|
2241
|
+
"s.content_title as content_title",
|
|
2242
|
+
"s.content_status as content_status",
|
|
2243
|
+
"s.content_scheduled_at as content_scheduled_at",
|
|
2244
|
+
"s.content_deleted_at as content_deleted_at",
|
|
2245
|
+
"s.revision_id as revision_id",
|
|
2246
|
+
"s.current_generation as current_generation",
|
|
2247
|
+
"s.schema_version as schema_version",
|
|
2248
|
+
"s.source_updated_at as source_updated_at",
|
|
2249
|
+
"s.source_version as source_version",
|
|
2250
|
+
"s.source_fingerprint as source_fingerprint",
|
|
2251
|
+
"s.identity_version as identity_version",
|
|
2252
|
+
"s.source_completeness as source_completeness",
|
|
2253
|
+
"s.last_attempted_at as last_attempted_at",
|
|
2254
|
+
"s.last_error_code as last_error_code",
|
|
2255
|
+
"s.indexed_at as indexed_at",
|
|
2256
|
+
"s.created_at as source_created_at",
|
|
2257
|
+
"s.updated_at as source_row_updated_at",
|
|
2258
|
+
"u.id as occurrence_id",
|
|
2259
|
+
"u.generation as generation",
|
|
2260
|
+
"u.field_slug as field_slug",
|
|
2261
|
+
"u.field_path as field_path",
|
|
2262
|
+
"u.occurrence_index as occurrence_index",
|
|
2263
|
+
"u.reference_type as reference_type",
|
|
2264
|
+
"u.media_id as media_id",
|
|
2265
|
+
"u.provider as provider",
|
|
2266
|
+
"u.provider_asset_id as provider_asset_id",
|
|
2267
|
+
"u.media_kind as media_kind",
|
|
2268
|
+
"u.mime_type as mime_type",
|
|
2269
|
+
"u.created_at as occurrence_created_at"
|
|
2270
|
+
];
|
|
2271
|
+
function groupUsageRows(rows) {
|
|
2272
|
+
const groups = [];
|
|
2273
|
+
for (const row of rows) {
|
|
2274
|
+
if (row.collection_slug === null || row.content_id === null) continue;
|
|
2275
|
+
const record = rowToUsageRecord(row);
|
|
2276
|
+
let group = groups.at(-1);
|
|
2277
|
+
if (!group || group.collectionSlug !== row.collection_slug || group.contentId !== row.content_id) {
|
|
2278
|
+
group = {
|
|
2279
|
+
collectionSlug: row.collection_slug,
|
|
2280
|
+
contentId: row.content_id,
|
|
2281
|
+
contentDeletedAt: row.entry_deleted_at,
|
|
2282
|
+
sources: []
|
|
2283
|
+
};
|
|
2284
|
+
groups.push(group);
|
|
2285
|
+
}
|
|
2286
|
+
let source = group.sources.at(-1);
|
|
2287
|
+
if (!source || source.source.sourceKey !== record.source.sourceKey) {
|
|
2288
|
+
source = {
|
|
2289
|
+
source: record.source,
|
|
2290
|
+
occurrences: []
|
|
2291
|
+
};
|
|
2292
|
+
group.sources.push(source);
|
|
2293
|
+
}
|
|
2294
|
+
source.occurrences.push(record.occurrence);
|
|
2295
|
+
}
|
|
2296
|
+
return groups;
|
|
2297
|
+
}
|
|
2298
|
+
function rowToSource(row) {
|
|
2299
|
+
return {
|
|
2300
|
+
sourceKey: row.source_key,
|
|
2301
|
+
sourceType: row.source_type,
|
|
2302
|
+
collectionId: row.collection_id,
|
|
2303
|
+
collectionSlug: row.collection_slug,
|
|
2304
|
+
contentId: row.content_id,
|
|
2305
|
+
sourceVariant: row.source_variant,
|
|
2306
|
+
locale: row.locale,
|
|
2307
|
+
translationGroup: row.translation_group,
|
|
2308
|
+
contentSlug: row.content_slug,
|
|
2309
|
+
contentTitle: row.content_title,
|
|
2310
|
+
contentStatus: row.content_status,
|
|
2311
|
+
contentScheduledAt: row.content_scheduled_at,
|
|
2312
|
+
contentDeletedAt: row.content_deleted_at,
|
|
2313
|
+
revisionId: row.revision_id,
|
|
2314
|
+
currentGeneration: row.current_generation,
|
|
2315
|
+
schemaVersion: Number(row.schema_version),
|
|
2316
|
+
sourceUpdatedAt: row.source_updated_at,
|
|
2317
|
+
sourceVersion: row.source_version === null ? null : Number(row.source_version),
|
|
2318
|
+
sourceFingerprint: row.source_fingerprint,
|
|
2319
|
+
identityVersion: row.identity_version === null ? null : Number(row.identity_version),
|
|
2320
|
+
sourceCompleteness: row.source_completeness,
|
|
2321
|
+
lastAttemptedAt: row.last_attempted_at,
|
|
2322
|
+
lastErrorCode: row.last_error_code,
|
|
2323
|
+
indexedAt: row.indexed_at,
|
|
2324
|
+
createdAt: row.created_at,
|
|
2325
|
+
updatedAt: row.updated_at
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
function rowToOccurrence(row) {
|
|
2329
|
+
return {
|
|
2330
|
+
id: row.id,
|
|
2331
|
+
sourceKey: row.source_key,
|
|
2332
|
+
generation: row.generation,
|
|
2333
|
+
fieldSlug: row.field_slug,
|
|
2334
|
+
fieldPath: row.field_path,
|
|
2335
|
+
occurrenceIndex: Number(row.occurrence_index),
|
|
2336
|
+
referenceType: row.reference_type,
|
|
2337
|
+
mediaId: row.media_id,
|
|
2338
|
+
provider: row.provider,
|
|
2339
|
+
providerAssetId: row.provider_asset_id,
|
|
2340
|
+
mediaKind: row.media_kind,
|
|
2341
|
+
mimeType: row.mime_type,
|
|
2342
|
+
createdAt: row.created_at
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
function rowToUsageRecord(row) {
|
|
2346
|
+
return {
|
|
2347
|
+
source: rowToSource({
|
|
2348
|
+
source_key: row.source_key,
|
|
2349
|
+
source_type: row.source_type,
|
|
2350
|
+
collection_id: row.collection_id,
|
|
2351
|
+
collection_slug: row.collection_slug,
|
|
2352
|
+
content_id: row.content_id,
|
|
2353
|
+
source_variant: row.source_variant,
|
|
2354
|
+
locale: row.locale,
|
|
2355
|
+
translation_group: row.translation_group,
|
|
2356
|
+
content_slug: row.content_slug,
|
|
2357
|
+
content_title: row.content_title,
|
|
2358
|
+
content_status: row.content_status,
|
|
2359
|
+
content_scheduled_at: row.content_scheduled_at,
|
|
2360
|
+
content_deleted_at: row.content_deleted_at,
|
|
2361
|
+
revision_id: row.revision_id,
|
|
2362
|
+
current_generation: row.current_generation,
|
|
2363
|
+
schema_version: row.schema_version,
|
|
2364
|
+
source_updated_at: row.source_updated_at,
|
|
2365
|
+
source_version: row.source_version,
|
|
2366
|
+
source_fingerprint: row.source_fingerprint,
|
|
2367
|
+
identity_version: row.identity_version,
|
|
2368
|
+
source_completeness: row.source_completeness,
|
|
2369
|
+
last_attempted_at: row.last_attempted_at,
|
|
2370
|
+
last_error_code: row.last_error_code,
|
|
2371
|
+
indexed_at: row.indexed_at,
|
|
2372
|
+
created_at: row.source_created_at,
|
|
2373
|
+
updated_at: row.source_row_updated_at
|
|
2374
|
+
}),
|
|
2375
|
+
occurrence: rowToOccurrence({
|
|
2376
|
+
id: row.occurrence_id,
|
|
2377
|
+
source_key: row.source_key,
|
|
2378
|
+
generation: row.generation,
|
|
2379
|
+
field_slug: row.field_slug,
|
|
2380
|
+
field_path: row.field_path,
|
|
2381
|
+
occurrence_index: row.occurrence_index,
|
|
2382
|
+
reference_type: row.reference_type,
|
|
2383
|
+
media_id: row.media_id,
|
|
2384
|
+
provider: row.provider,
|
|
2385
|
+
provider_asset_id: row.provider_asset_id,
|
|
2386
|
+
media_kind: row.media_kind,
|
|
2387
|
+
mime_type: row.mime_type,
|
|
2388
|
+
created_at: row.occurrence_created_at,
|
|
2389
|
+
cleanup_lease_token: null
|
|
2390
|
+
})
|
|
2391
|
+
};
|
|
2392
|
+
}
|
|
2393
|
+
function rowToIndexStatus(row) {
|
|
2394
|
+
return {
|
|
2395
|
+
adapterId: row.adapter_id,
|
|
2396
|
+
scopeType: row.scope_type,
|
|
2397
|
+
scopeKey: row.scope_key,
|
|
2398
|
+
status: row.status,
|
|
2399
|
+
schemaVersion: Number(row.schema_version),
|
|
2400
|
+
startedAt: row.started_at,
|
|
2401
|
+
completedAt: row.completed_at,
|
|
2402
|
+
cursor: row.cursor,
|
|
2403
|
+
indexedSourceCount: Number(row.indexed_source_count),
|
|
2404
|
+
failedSourceCount: Number(row.failed_source_count),
|
|
2405
|
+
lastErrorCode: row.last_error_code,
|
|
2406
|
+
updatedAt: row.updated_at
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
//#endregion
|
|
2411
|
+
//#region src/database/repositories/media.ts
|
|
2412
|
+
/** Escape LIKE wildcard characters and the escape char itself in user-supplied values */
|
|
2413
|
+
function escapeLike(value) {
|
|
2414
|
+
return value.replaceAll("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_");
|
|
2415
|
+
}
|
|
2416
|
+
/**
|
|
2417
|
+
* Normalize a mimeType filter (string or array) into a clean string[].
|
|
2418
|
+
* Entries that are empty strings are dropped.
|
|
2419
|
+
*/
|
|
2420
|
+
function normalizeMimeFilter(input) {
|
|
2421
|
+
if (!input) return [];
|
|
2422
|
+
return (Array.isArray(input) ? input : [input]).filter((entry) => typeof entry === "string" && entry.length > 0).map((entry) => entry.endsWith("/") ? entry.toLowerCase() : entry.split(";")[0].trim().toLowerCase());
|
|
2423
|
+
}
|
|
2424
|
+
function normalizeListLimit(limit) {
|
|
2425
|
+
const integer = typeof limit === "number" && !Number.isNaN(limit) ? Math.trunc(limit) : 50;
|
|
2426
|
+
return Math.min(Math.max(integer, 1), 100);
|
|
2427
|
+
}
|
|
2428
|
+
/**
|
|
2429
|
+
* Build a WHERE clause that matches `mime_type` against any of the given
|
|
2430
|
+
* filter entries — exact equality for full MIMEs, LIKE prefix for entries
|
|
2431
|
+
* ending in "/".
|
|
2432
|
+
*/
|
|
2433
|
+
function mimeMatchExpr(eb, filters) {
|
|
2434
|
+
return eb.or(filters.map((entry) => entry.endsWith("/") ? sql`mime_type LIKE ${`${escapeLike(entry)}%`} ESCAPE '\\'` : eb("mime_type", "=", entry)));
|
|
2435
|
+
}
|
|
2436
|
+
const UPLOAD_ATTEMPT_CLEANUP_AGE_MS = 3600 * 1e3;
|
|
2437
|
+
const UPLOAD_ATTEMPT_CLEANUP_BATCH_SIZE = 100;
|
|
2438
|
+
/**
|
|
2439
|
+
* Media repository for database operations
|
|
2440
|
+
*/
|
|
2441
|
+
var MediaRepository = class {
|
|
2442
|
+
constructor(db) {
|
|
2443
|
+
this.db = db;
|
|
2444
|
+
}
|
|
2445
|
+
/**
|
|
2446
|
+
* Create a new media item
|
|
2447
|
+
*/
|
|
2448
|
+
async create(input) {
|
|
2449
|
+
const id = ulid();
|
|
2450
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2451
|
+
const row = {
|
|
2452
|
+
id,
|
|
2453
|
+
filename: input.filename,
|
|
2454
|
+
mime_type: input.mimeType,
|
|
2455
|
+
size: input.size ?? null,
|
|
2456
|
+
width: input.width ?? null,
|
|
2457
|
+
height: input.height ?? null,
|
|
2458
|
+
focal_x: null,
|
|
2459
|
+
focal_y: null,
|
|
2460
|
+
alt: input.alt ?? null,
|
|
2461
|
+
caption: input.caption ?? null,
|
|
2462
|
+
storage_key: input.storageKey,
|
|
2463
|
+
content_hash: input.contentHash ?? null,
|
|
2464
|
+
blurhash: input.blurhash ?? null,
|
|
2465
|
+
dominant_color: input.dominantColor ?? null,
|
|
2466
|
+
status: input.status ?? "ready",
|
|
2467
|
+
created_at: now,
|
|
2468
|
+
author_id: input.authorId ?? null,
|
|
2469
|
+
folder_id: input.folderId ?? null
|
|
2470
|
+
};
|
|
2471
|
+
await this.db.insertInto("media").values(row).execute();
|
|
2472
|
+
return this.rowToItem(row);
|
|
2473
|
+
}
|
|
2474
|
+
/**
|
|
2475
|
+
* Create a pending media item (for signed URL upload flow)
|
|
2476
|
+
*/
|
|
2477
|
+
async createPending(input) {
|
|
2478
|
+
return this.create({
|
|
2479
|
+
...input,
|
|
2480
|
+
status: "pending"
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
async createUploadAttempt(mediaId, storageKey) {
|
|
2484
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2485
|
+
await this.db.insertInto("_emdash_media_upload_attempts").values({
|
|
2486
|
+
media_id: mediaId,
|
|
2487
|
+
storage_key: storageKey,
|
|
2488
|
+
status: "active",
|
|
2489
|
+
created_at: now,
|
|
2490
|
+
updated_at: now
|
|
2491
|
+
}).execute();
|
|
2492
|
+
}
|
|
2493
|
+
/**
|
|
2494
|
+
* Register a stored object for cleanup before its media row is removed,
|
|
2495
|
+
* so a failed storage delete is retried by the cleanup sweep instead of
|
|
2496
|
+
* leaving the object unreferenced and unreachable.
|
|
2497
|
+
*/
|
|
2498
|
+
async trackStorageKeyForCleanup(mediaId, storageKey) {
|
|
2499
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2500
|
+
await this.db.insertInto("_emdash_media_upload_attempts").values({
|
|
2501
|
+
media_id: mediaId,
|
|
2502
|
+
storage_key: storageKey,
|
|
2503
|
+
status: "cleanup",
|
|
2504
|
+
created_at: now,
|
|
2505
|
+
updated_at: now
|
|
2506
|
+
}).onConflict((oc) => oc.column("storage_key").doUpdateSet({
|
|
2507
|
+
status: "cleanup",
|
|
2508
|
+
updated_at: now
|
|
2509
|
+
})).execute();
|
|
2510
|
+
}
|
|
2511
|
+
async hasUploadAttempt(storageKey) {
|
|
2512
|
+
return await this.db.selectFrom("_emdash_media_upload_attempts").select("storage_key").where("storage_key", "=", storageKey).executeTakeFirst() !== void 0;
|
|
2513
|
+
}
|
|
2514
|
+
async claimUploadAttemptForCleanup(storageKey) {
|
|
2515
|
+
const result = await this.db.updateTable("_emdash_media_upload_attempts").set({
|
|
2516
|
+
status: "cleanup",
|
|
2517
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2518
|
+
}).where("storage_key", "=", storageKey).where((eb) => eb.not(eb.exists(eb.selectFrom("media").select("media.id").whereRef("media.storage_key", "=", "_emdash_media_upload_attempts.storage_key")))).executeTakeFirst();
|
|
2519
|
+
return Number(result.numUpdatedRows ?? 0) > 0;
|
|
2520
|
+
}
|
|
2521
|
+
async deleteUploadAttempt(storageKey) {
|
|
2522
|
+
await this.db.deleteFrom("_emdash_media_upload_attempts").where("storage_key", "=", storageKey).execute();
|
|
2523
|
+
}
|
|
2524
|
+
async deferUploadAttemptCleanup(storageKey) {
|
|
2525
|
+
await this.db.updateTable("_emdash_media_upload_attempts").set({ updated_at: (/* @__PURE__ */ new Date()).toISOString() }).where("storage_key", "=", storageKey).execute();
|
|
2526
|
+
}
|
|
2527
|
+
async deleteCompletedUploadAttempts() {
|
|
2528
|
+
const result = await this.db.deleteFrom("_emdash_media_upload_attempts").where("status", "=", "active").where((eb) => eb.exists(eb.selectFrom("media").select("media.id").whereRef("media.id", "=", "_emdash_media_upload_attempts.media_id").whereRef("media.storage_key", "=", "_emdash_media_upload_attempts.storage_key").where("media.status", "=", "ready"))).executeTakeFirst();
|
|
2529
|
+
return Number(result.numDeletedRows ?? 0);
|
|
2530
|
+
}
|
|
2531
|
+
async findUploadAttemptsForCleanup(maxAgeMs = UPLOAD_ATTEMPT_CLEANUP_AGE_MS, limit = UPLOAD_ATTEMPT_CLEANUP_BATCH_SIZE) {
|
|
2532
|
+
const cutoff = new Date(Date.now() - maxAgeMs).toISOString();
|
|
2533
|
+
return (await this.db.selectFrom("_emdash_media_upload_attempts").select("storage_key").where((eb) => eb.or([eb("status", "=", "cleanup"), eb("created_at", "<", cutoff)])).where((eb) => eb.not(eb.exists(eb.selectFrom("media").select("media.id").whereRef("media.storage_key", "=", "_emdash_media_upload_attempts.storage_key")))).orderBy("updated_at", "asc").limit(limit).execute()).map((row) => row.storage_key);
|
|
2534
|
+
}
|
|
2535
|
+
async publishPendingStorageKey(id, expectedStorageKey, storageKey, contentHash) {
|
|
2536
|
+
const result = await this.db.updateTable("media").set({
|
|
2537
|
+
storage_key: storageKey,
|
|
2538
|
+
...contentHash !== void 0 ? { content_hash: contentHash } : {}
|
|
2539
|
+
}).where("id", "=", id).where("status", "=", "pending").where("storage_key", "=", expectedStorageKey).where((eb) => eb.exists(eb.selectFrom("_emdash_media_upload_attempts").select("storage_key").where("media_id", "=", id).where("storage_key", "=", storageKey).where("status", "=", "active"))).executeTakeFirst();
|
|
2540
|
+
return Number(result.numUpdatedRows ?? 0) > 0;
|
|
2541
|
+
}
|
|
2542
|
+
/**
|
|
2543
|
+
* Confirm upload (mark as ready)
|
|
2544
|
+
*/
|
|
2545
|
+
async confirmUpload(id, metadata, expectedStorageKey) {
|
|
2546
|
+
const updates = { status: "ready" };
|
|
2547
|
+
if (metadata?.width !== void 0) updates.width = metadata.width;
|
|
2548
|
+
if (metadata?.height !== void 0) updates.height = metadata.height;
|
|
2549
|
+
if (metadata?.size !== void 0) updates.size = metadata.size;
|
|
2550
|
+
if (metadata?.blurhash !== void 0) updates.blurhash = metadata.blurhash;
|
|
2551
|
+
if (metadata?.dominantColor !== void 0) updates.dominant_color = metadata.dominantColor;
|
|
2552
|
+
if (metadata?.contentHash !== void 0) updates.content_hash = metadata.contentHash;
|
|
2553
|
+
let query = this.db.updateTable("media").set(updates).where("id", "=", id).where("status", "=", "pending");
|
|
2554
|
+
if (expectedStorageKey !== void 0) query = query.where("storage_key", "=", expectedStorageKey);
|
|
2555
|
+
const row = await query.returningAll().executeTakeFirst();
|
|
2556
|
+
return row ? this.rowToItem(row) : null;
|
|
2557
|
+
}
|
|
2558
|
+
/**
|
|
2559
|
+
* Mark upload as failed
|
|
2560
|
+
*/
|
|
2561
|
+
async markFailed(id, expectedStorageKey) {
|
|
2562
|
+
let query = this.db.updateTable("media").set({ status: "failed" }).where("id", "=", id);
|
|
2563
|
+
if (expectedStorageKey !== void 0) query = query.where("status", "=", "pending").where("storage_key", "=", expectedStorageKey);
|
|
2564
|
+
const row = await query.returningAll().executeTakeFirst();
|
|
2565
|
+
return row ? this.rowToItem(row) : null;
|
|
2566
|
+
}
|
|
2567
|
+
/**
|
|
2568
|
+
* Find the pending media row minted for a signed upload URL.
|
|
2569
|
+
*/
|
|
2570
|
+
async findPendingByStorageKey(storageKey) {
|
|
2571
|
+
const row = await this.db.selectFrom("media").selectAll().where("storage_key", "=", storageKey).where("status", "=", "pending").executeTakeFirst();
|
|
2572
|
+
return row ? this.rowToItem(row) : null;
|
|
2573
|
+
}
|
|
2574
|
+
/**
|
|
2575
|
+
* Find media by ID
|
|
2576
|
+
*/
|
|
2577
|
+
async findById(id) {
|
|
2578
|
+
const row = await this.db.selectFrom("media").selectAll().where("id", "=", id).executeTakeFirst();
|
|
2579
|
+
return row ? this.rowToItem(row) : null;
|
|
2580
|
+
}
|
|
2581
|
+
/**
|
|
2582
|
+
* Map each storage key to the id of its media item, in one query per JSON
|
|
2583
|
+
* bind's worth of keys. Unknown keys are left out.
|
|
2584
|
+
*/
|
|
2585
|
+
async findIdsByStorageKeys(storageKeys) {
|
|
2586
|
+
const ids = /* @__PURE__ */ new Map();
|
|
2587
|
+
for (const batch of chunkJsonRows(storageKeys)) {
|
|
2588
|
+
const result = await sql`
|
|
2589
|
+
WITH requested AS (${jsonTextValues(this.db, batch)})
|
|
2590
|
+
SELECT media.id, media.storage_key
|
|
2591
|
+
FROM media
|
|
2592
|
+
INNER JOIN requested ON requested.value = media.storage_key
|
|
2593
|
+
ORDER BY media.id
|
|
2594
|
+
`.execute(this.db);
|
|
2595
|
+
for (const row of result.rows) if (!ids.has(row.storage_key)) ids.set(row.storage_key, row.id);
|
|
2596
|
+
}
|
|
2597
|
+
return ids;
|
|
2598
|
+
}
|
|
2599
|
+
/**
|
|
2600
|
+
* Find the original upload filename for a storage key.
|
|
2601
|
+
*
|
|
2602
|
+
* Used by the public media file route to name the download after the file
|
|
2603
|
+
* the editor uploaded rather than after its storage key. Selects the single
|
|
2604
|
+
* column it needs: this runs on every unauthenticated download.
|
|
2605
|
+
*/
|
|
2606
|
+
async findFilenameByStorageKey(storageKey) {
|
|
2607
|
+
return (await this.db.selectFrom("media").select("filename").where("storage_key", "=", storageKey).executeTakeFirst())?.filename ?? null;
|
|
2608
|
+
}
|
|
2609
|
+
/**
|
|
2610
|
+
* Find media by filename
|
|
2611
|
+
* Useful for idempotent imports
|
|
2612
|
+
*/
|
|
2613
|
+
async findByFilename(filename) {
|
|
2614
|
+
const row = await this.db.selectFrom("media").selectAll().where("filename", "=", filename).executeTakeFirst();
|
|
2615
|
+
return row ? this.rowToItem(row) : null;
|
|
2616
|
+
}
|
|
2617
|
+
async findAvailableFilename(filename) {
|
|
2618
|
+
const exists = async (candidate) => Boolean(await this.db.selectFrom("media").select("id").where(sql`lower(filename)`, "=", candidate.toLowerCase()).executeTakeFirst());
|
|
2619
|
+
if (!await exists(filename)) return filename;
|
|
2620
|
+
const extensionIndex = filename.lastIndexOf(".");
|
|
2621
|
+
const hasExtension = extensionIndex > 0;
|
|
2622
|
+
const extension = hasExtension ? filename.slice(extensionIndex) : "";
|
|
2623
|
+
const stem = hasExtension ? filename.slice(0, extensionIndex) : filename;
|
|
2624
|
+
let copyNumber = 2;
|
|
2625
|
+
let candidate = `${stem}-${copyNumber}${extension}`;
|
|
2626
|
+
while (await exists(candidate)) {
|
|
2627
|
+
copyNumber += 1;
|
|
2628
|
+
candidate = `${stem}-${copyNumber}${extension}`;
|
|
2629
|
+
}
|
|
2630
|
+
return candidate;
|
|
2631
|
+
}
|
|
2632
|
+
/**
|
|
2633
|
+
* Find media by content hash
|
|
2634
|
+
* Used for deduplication - same content = same hash
|
|
2635
|
+
*/
|
|
2636
|
+
async findByContentHash(contentHash) {
|
|
2637
|
+
const row = await this.db.selectFrom("media").selectAll().where("content_hash", "=", contentHash).where("status", "=", "ready").executeTakeFirst();
|
|
2638
|
+
return row ? this.rowToItem(row) : null;
|
|
2639
|
+
}
|
|
2640
|
+
/**
|
|
2641
|
+
* Find many media items with cursor pagination
|
|
2642
|
+
*
|
|
2643
|
+
* Uses keyset pagination (cursor-based) for consistent results.
|
|
2644
|
+
* The cursor encodes the created_at and id of the last item.
|
|
2645
|
+
*/
|
|
2646
|
+
async findMany(options = {}) {
|
|
2647
|
+
const limit = normalizeListLimit(options.limit);
|
|
2648
|
+
let query = this.applyListFilters(this.db.selectFrom("media"), options).selectAll().orderBy("created_at", "desc").orderBy("id", "desc").limit(limit + 1);
|
|
2649
|
+
if (options.cursor) {
|
|
2650
|
+
const { orderValue: createdAt, id: cursorId } = decodeCursor(options.cursor);
|
|
2651
|
+
query = query.where((eb) => eb.or([eb("created_at", "<", createdAt), eb.and([eb("created_at", "=", createdAt), eb("id", "<", cursorId)])]));
|
|
2652
|
+
}
|
|
2653
|
+
const rows = await query.execute();
|
|
2654
|
+
const hasMore = rows.length > limit;
|
|
2655
|
+
const items = rows.slice(0, limit).map((row) => this.rowToItem(row));
|
|
2656
|
+
let nextCursor;
|
|
2657
|
+
if (hasMore && items.length > 0) {
|
|
2658
|
+
const lastItem = items.at(-1);
|
|
2659
|
+
nextCursor = encodeCursor(lastItem.createdAt, lastItem.id);
|
|
2660
|
+
}
|
|
2661
|
+
return {
|
|
2662
|
+
items,
|
|
2663
|
+
nextCursor
|
|
2664
|
+
};
|
|
2665
|
+
}
|
|
2666
|
+
async findPage(options) {
|
|
2667
|
+
const limit = normalizeListLimit(options.limit);
|
|
2668
|
+
const offset = (options.page - 1) * limit;
|
|
2669
|
+
const filtered = this.applyListFilters(this.db.selectFrom("media"), options);
|
|
2670
|
+
const rows = await filtered.selectAll().orderBy("created_at", "desc").orderBy("id", "desc").limit(limit).offset(offset).execute();
|
|
2671
|
+
const count = await filtered.select((eb) => eb.fn.count("id").as("count")).executeTakeFirst();
|
|
2672
|
+
return {
|
|
2673
|
+
items: rows.map((row) => this.rowToItem(row)),
|
|
2674
|
+
totalCount: Number(count?.count ?? 0)
|
|
2675
|
+
};
|
|
2676
|
+
}
|
|
2677
|
+
/**
|
|
2678
|
+
* Update media metadata
|
|
2679
|
+
*/
|
|
2680
|
+
async update(id, input) {
|
|
2681
|
+
if (!await this.findById(id)) return null;
|
|
2682
|
+
const updates = {};
|
|
2683
|
+
if (input.alt !== void 0) updates.alt = input.alt;
|
|
2684
|
+
if (input.caption !== void 0) updates.caption = input.caption;
|
|
2685
|
+
if (input.width !== void 0) updates.width = input.width;
|
|
2686
|
+
if (input.height !== void 0) updates.height = input.height;
|
|
2687
|
+
if (input.folderId !== void 0) updates.folder_id = input.folderId;
|
|
2688
|
+
if (input.focalX !== void 0 && input.focalY !== void 0) {
|
|
2689
|
+
updates.focal_x = input.focalX;
|
|
2690
|
+
updates.focal_y = input.focalY;
|
|
2691
|
+
}
|
|
2692
|
+
if (Object.keys(updates).length > 0) await this.db.updateTable("media").set(updates).where("id", "=", id).execute();
|
|
2693
|
+
return this.findById(id);
|
|
2694
|
+
}
|
|
2695
|
+
async updateReadyMetadata(id, input) {
|
|
2696
|
+
const updates = {};
|
|
2697
|
+
if (input.alt !== void 0) updates.alt = input.alt;
|
|
2698
|
+
if (input.caption !== void 0) updates.caption = input.caption;
|
|
2699
|
+
if (input.focalX !== void 0 && input.focalY !== void 0) {
|
|
2700
|
+
updates.focal_x = input.focalX;
|
|
2701
|
+
updates.focal_y = input.focalY;
|
|
2702
|
+
}
|
|
2703
|
+
if (Object.keys(updates).length === 0) throw new TypeError("Media metadata update requires at least one field");
|
|
2704
|
+
const row = await this.db.updateTable("media").set(updates).where("id", "=", id).where("status", "=", "ready").returningAll().executeTakeFirst();
|
|
2705
|
+
return row ? this.rowToItem(row) : null;
|
|
2706
|
+
}
|
|
2707
|
+
async replaceReadyFile(id, expectedStorageKey, input) {
|
|
2708
|
+
const row = await this.db.updateTable("media").set({
|
|
2709
|
+
size: input.size,
|
|
2710
|
+
width: input.width,
|
|
2711
|
+
height: input.height,
|
|
2712
|
+
content_hash: input.contentHash,
|
|
2713
|
+
blurhash: null,
|
|
2714
|
+
dominant_color: null,
|
|
2715
|
+
focal_x: null,
|
|
2716
|
+
focal_y: null
|
|
2717
|
+
}).where("id", "=", id).where("status", "=", "ready").where("storage_key", "=", expectedStorageKey).returningAll().executeTakeFirst();
|
|
2718
|
+
return row ? this.rowToItem(row) : null;
|
|
2719
|
+
}
|
|
2720
|
+
/**
|
|
2721
|
+
* Delete media item
|
|
2722
|
+
*/
|
|
2723
|
+
async deleteWithStorageKey(id) {
|
|
2724
|
+
const deleted = await this.db.deleteFrom("media").where("id", "=", id).returning("storage_key").executeTakeFirst();
|
|
2725
|
+
if (deleted) return deleted.storage_key;
|
|
2726
|
+
return null;
|
|
2727
|
+
}
|
|
2728
|
+
async isStorageKeyReferenced(storageKey) {
|
|
2729
|
+
return await this.db.selectFrom("media").select("id").where("storage_key", "=", storageKey).executeTakeFirst() !== void 0;
|
|
2730
|
+
}
|
|
2731
|
+
async delete(id) {
|
|
2732
|
+
return await this.deleteWithStorageKey(id) !== null;
|
|
2733
|
+
}
|
|
2734
|
+
/**
|
|
2735
|
+
* Count media items
|
|
2736
|
+
*/
|
|
2737
|
+
async count(mimeType) {
|
|
2738
|
+
const filters = normalizeMimeFilter(mimeType);
|
|
2739
|
+
let query = this.db.selectFrom("media").select((eb) => eb.fn.count("id").as("count"));
|
|
2740
|
+
if (filters.length > 0) query = query.where((eb) => mimeMatchExpr(eb, filters));
|
|
2741
|
+
const result = await query.executeTakeFirst();
|
|
2742
|
+
return Number(result?.count || 0);
|
|
2743
|
+
}
|
|
2744
|
+
applyListFilters(query, options) {
|
|
2745
|
+
const mimeFilters = normalizeMimeFilter(options.mimeType);
|
|
2746
|
+
if (mimeFilters.length > 0) query = query.where((eb) => mimeMatchExpr(eb, mimeFilters));
|
|
2747
|
+
let term = options.q?.trim() ?? "";
|
|
2748
|
+
if (term.includes("/")) {
|
|
2749
|
+
const queryIndex = term.indexOf("?");
|
|
2750
|
+
if (queryIndex !== -1) term = term.slice(0, queryIndex);
|
|
2751
|
+
const fragmentIndex = term.indexOf("#");
|
|
2752
|
+
if (fragmentIndex !== -1) term = term.slice(0, fragmentIndex);
|
|
2753
|
+
term = term.slice(term.lastIndexOf("/") + 1).trim();
|
|
2754
|
+
}
|
|
2755
|
+
if (term) query = query.where((eb) => eb.or([
|
|
2756
|
+
"filename",
|
|
2757
|
+
"storage_key",
|
|
2758
|
+
"id"
|
|
2759
|
+
].map((column) => eb(textPosition(this.db, sql`lower(${sql.ref(column)})`, sql`lower(${term})`), ">", 0))));
|
|
2760
|
+
if (options.status !== "all") query = query.where("status", "=", options.status ?? "ready");
|
|
2761
|
+
if (options.folderId === null) query = query.where("folder_id", "is", null);
|
|
2762
|
+
else if (options.folderId !== void 0) query = query.where("folder_id", "=", options.folderId);
|
|
2763
|
+
return query;
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Delete pending uploads older than the given age.
|
|
2767
|
+
* Pending uploads that were never confirmed indicate abandoned upload flows.
|
|
2768
|
+
*
|
|
2769
|
+
* Returns the storage keys of deleted rows so callers can remove the
|
|
2770
|
+
* corresponding files from object storage.
|
|
2771
|
+
*/
|
|
2772
|
+
async cleanupPendingUploads(maxAgeMs = 3600 * 1e3) {
|
|
2773
|
+
const cutoff = new Date(Date.now() - maxAgeMs).toISOString();
|
|
2774
|
+
const keys = (await this.db.deleteFrom("media").where("status", "=", "pending").where("created_at", "<", cutoff).returning("storage_key").execute()).map((r) => r.storage_key);
|
|
2775
|
+
if (keys.length === 0) return keys;
|
|
2776
|
+
const stillReferenced = /* @__PURE__ */ new Set();
|
|
2777
|
+
for (const batch of chunks(keys, SQL_BATCH_SIZE)) {
|
|
2778
|
+
const refs = await this.db.selectFrom("media").select("storage_key").where("storage_key", "in", batch).execute();
|
|
2779
|
+
for (const ref of refs) stillReferenced.add(ref.storage_key);
|
|
2780
|
+
}
|
|
2781
|
+
return keys.filter((key) => !stillReferenced.has(key));
|
|
2782
|
+
}
|
|
2783
|
+
/**
|
|
2784
|
+
* Convert database row to MediaItem
|
|
2785
|
+
*/
|
|
2786
|
+
rowToItem(row) {
|
|
2787
|
+
const focalPoint = normalizeFocalPoint(row.focal_x, row.focal_y);
|
|
2788
|
+
return {
|
|
2789
|
+
id: row.id,
|
|
2790
|
+
filename: row.filename,
|
|
2791
|
+
mimeType: row.mime_type,
|
|
2792
|
+
size: row.size,
|
|
2793
|
+
width: row.width,
|
|
2794
|
+
height: row.height,
|
|
2795
|
+
focalX: focalPoint?.focalX ?? null,
|
|
2796
|
+
focalY: focalPoint?.focalY ?? null,
|
|
2797
|
+
alt: row.alt,
|
|
2798
|
+
caption: row.caption,
|
|
2799
|
+
storageKey: row.storage_key,
|
|
2800
|
+
contentHash: row.content_hash,
|
|
2801
|
+
blurhash: row.blurhash,
|
|
2802
|
+
dominantColor: row.dominant_color,
|
|
2803
|
+
status: row.status,
|
|
2804
|
+
createdAt: row.created_at,
|
|
2805
|
+
authorId: row.author_id,
|
|
2806
|
+
folderId: row.folder_id
|
|
2807
|
+
};
|
|
2808
|
+
}
|
|
2809
|
+
};
|
|
2810
|
+
|
|
2811
|
+
//#endregion
|
|
2812
|
+
export { buildMediaUsageProjectionFingerprint as a, buildCanonicalSha256Fingerprint as i, MediaUsageRepository as n, CONTENT_SOURCE_SCHEMA_VERSION as r, MediaRepository as t };
|
|
2813
|
+
//# sourceMappingURL=media--P-IEycF.mjs.map
|