emdash 0.8.0 → 0.9.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/{adapters-BKSf3T9R.d.mts → adapters-DoNJiveC.d.mts} +1 -1
- package/dist/{adapters-BKSf3T9R.d.mts.map → adapters-DoNJiveC.d.mts.map} +1 -1
- package/dist/{apply-x0eMK1lX.mjs → apply-BzltprvY.mjs} +85 -135
- package/dist/apply-BzltprvY.mjs.map +1 -0
- package/dist/astro/index.d.mts +6 -6
- package/dist/astro/index.d.mts.map +1 -1
- package/dist/astro/index.mjs +110 -4
- package/dist/astro/index.mjs.map +1 -1
- package/dist/astro/middleware/auth.d.mts +6 -7
- package/dist/astro/middleware/auth.d.mts.map +1 -1
- package/dist/astro/middleware/auth.mjs +16 -59
- package/dist/astro/middleware/auth.mjs.map +1 -1
- package/dist/astro/middleware/redirect.d.mts.map +1 -1
- package/dist/astro/middleware/redirect.mjs +17 -12
- 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 +9 -6
- package/dist/astro/middleware/request-context.mjs.map +1 -1
- package/dist/astro/middleware/setup.mjs +1 -1
- package/dist/astro/middleware.d.mts.map +1 -1
- package/dist/astro/middleware.mjs +72 -124
- package/dist/astro/middleware.mjs.map +1 -1
- package/dist/astro/types.d.mts +26 -10
- package/dist/astro/types.d.mts.map +1 -1
- package/dist/{base64-MBPo9ozB.mjs → base64-BRICGH2l.mjs} +1 -1
- package/dist/{base64-MBPo9ozB.mjs.map → base64-BRICGH2l.mjs.map} +1 -1
- package/dist/{byline-Chbr2GoP.mjs → byline-BSaNL1w7.mjs} +4 -4
- package/dist/{byline-Chbr2GoP.mjs.map → byline-BSaNL1w7.mjs.map} +1 -1
- package/dist/bylines-CvJ3PYz2.mjs +113 -0
- package/dist/bylines-CvJ3PYz2.mjs.map +1 -0
- package/dist/cache-C6N_hhN7.mjs +65 -0
- package/dist/cache-C6N_hhN7.mjs.map +1 -0
- package/dist/{chunks-HGz06Soa.mjs → chunks-NBQVDOci.mjs} +8 -2
- package/dist/{chunks-HGz06Soa.mjs.map → chunks-NBQVDOci.mjs.map} +1 -1
- package/dist/cli/index.mjs +224 -30
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/cf-access.d.mts +1 -1
- package/dist/client/index.d.mts +1 -1
- package/dist/client/index.mjs +3 -3
- package/dist/client/index.mjs.map +1 -1
- package/dist/{config-BXwuX8Bx.mjs → config-BI0V3ICQ.mjs} +1 -1
- package/dist/{config-BXwuX8Bx.mjs.map → config-BI0V3ICQ.mjs.map} +1 -1
- package/dist/{content-BcQPYxdV.mjs → content-8lOYF0pr.mjs} +32 -15
- package/dist/{content-BcQPYxdV.mjs.map → content-8lOYF0pr.mjs.map} +1 -1
- package/dist/db/index.d.mts +3 -3
- package/dist/db/index.mjs +2 -2
- package/dist/db/libsql.d.mts +1 -1
- package/dist/db/libsql.d.mts.map +1 -1
- package/dist/db/libsql.mjs +7 -2
- package/dist/db/libsql.mjs.map +1 -1
- package/dist/db/postgres.d.mts +1 -1
- package/dist/db/sqlite.d.mts +1 -1
- package/dist/db/sqlite.d.mts.map +1 -1
- package/dist/db/sqlite.mjs +8 -3
- package/dist/db/sqlite.mjs.map +1 -1
- package/dist/{db-errors-l1Qh2RPR.mjs → db-errors-WRezodiz.mjs} +1 -1
- package/dist/{db-errors-l1Qh2RPR.mjs.map → db-errors-WRezodiz.mjs.map} +1 -1
- package/dist/{default-DCVqE5ib.mjs → default-D8ksjWhO.mjs} +1 -1
- package/dist/{default-DCVqE5ib.mjs.map → default-D8ksjWhO.mjs.map} +1 -1
- package/dist/{dialect-helpers-DhTzaUxP.mjs → dialect-helpers-BKCvISIQ.mjs} +19 -2
- package/dist/dialect-helpers-BKCvISIQ.mjs.map +1 -0
- package/dist/{error-zG5T1UGA.mjs → error-D_-tqP-I.mjs} +1 -1
- package/dist/{error-zG5T1UGA.mjs.map → error-D_-tqP-I.mjs.map} +1 -1
- package/dist/{index-DIb-CzNx.d.mts → index-BFRaVcD6.d.mts} +94 -34
- package/dist/index-BFRaVcD6.d.mts.map +1 -0
- package/dist/index.d.mts +11 -11
- package/dist/index.mjs +29 -27
- package/dist/{load-CyEoextb.mjs → load-DDqMMvZL.mjs} +2 -2
- package/dist/{load-CyEoextb.mjs.map → load-DDqMMvZL.mjs.map} +1 -1
- package/dist/{loader-CndGj8kM.mjs → loader-CKLbBnhK.mjs} +27 -7
- package/dist/loader-CKLbBnhK.mjs.map +1 -0
- package/dist/{manifest-schema-DH9xhc6t.mjs → manifest-schema-DqWNC3lM.mjs} +33 -3
- package/dist/manifest-schema-DqWNC3lM.mjs.map +1 -0
- package/dist/media/index.d.mts +1 -1
- package/dist/media/index.mjs +1 -1
- package/dist/media/local-runtime.d.mts +7 -7
- package/dist/media/local-runtime.mjs +3 -3
- package/dist/{media-D8FbNsl0.mjs → media-BW32b4gi.mjs} +2 -2
- package/dist/{media-D8FbNsl0.mjs.map → media-BW32b4gi.mjs.map} +1 -1
- package/dist/{mode-BnAOqItE.mjs → mode-ier8jbBk.mjs} +1 -1
- package/dist/{mode-BnAOqItE.mjs.map → mode-ier8jbBk.mjs.map} +1 -1
- package/dist/options-BVp3UsTS.mjs +117 -0
- package/dist/options-BVp3UsTS.mjs.map +1 -0
- package/dist/page/index.d.mts +2 -2
- package/dist/{placeholder-D29tWZ7o.d.mts → placeholder-BE4o_2dc.d.mts} +1 -1
- package/dist/{placeholder-D29tWZ7o.d.mts.map → placeholder-BE4o_2dc.d.mts.map} +1 -1
- package/dist/{placeholder-C-fk5hYI.mjs → placeholder-CIJejMlK.mjs} +1 -1
- package/dist/{placeholder-C-fk5hYI.mjs.map → placeholder-CIJejMlK.mjs.map} +1 -1
- package/dist/plugins/adapt-sandbox-entry.d.mts +5 -5
- package/dist/plugins/adapt-sandbox-entry.d.mts.map +1 -1
- package/dist/plugins/adapt-sandbox-entry.mjs +6 -5
- package/dist/plugins/adapt-sandbox-entry.mjs.map +1 -1
- package/dist/public-url-DByxYjUw.mjs +51 -0
- package/dist/public-url-DByxYjUw.mjs.map +1 -0
- package/dist/{query-fqEdLFms.mjs → query-Cg9ZKRQ0.mjs} +114 -16
- package/dist/query-Cg9ZKRQ0.mjs.map +1 -0
- package/dist/{redirect-D_pshWdf.mjs → redirect-BhUBKRc1.mjs} +11 -6
- package/dist/redirect-BhUBKRc1.mjs.map +1 -0
- package/dist/{registry-C3Mr0ODu.mjs → registry-Dw70ChxB.mjs} +38 -4
- package/dist/registry-Dw70ChxB.mjs.map +1 -0
- package/dist/{request-cache-Ci7f5pBb.mjs → request-cache-B-bmkipQ.mjs} +1 -1
- package/dist/{request-cache-Ci7f5pBb.mjs.map → request-cache-B-bmkipQ.mjs.map} +1 -1
- package/dist/runner-Bnoj7vjK.d.mts +44 -0
- package/dist/runner-Bnoj7vjK.d.mts.map +1 -0
- package/dist/{runner-tQ7BJ4T7.mjs → runner-C7ADox5q.mjs} +185 -55
- package/dist/{runner-tQ7BJ4T7.mjs.map → runner-C7ADox5q.mjs.map} +1 -1
- package/dist/runtime.d.mts +6 -6
- package/dist/runtime.mjs +4 -4
- package/dist/{search-BoZYFuUk.mjs → search-dOGEccMa.mjs} +129 -83
- package/dist/search-dOGEccMa.mjs.map +1 -0
- package/dist/secrets-CW3reAnU.mjs +314 -0
- package/dist/secrets-CW3reAnU.mjs.map +1 -0
- package/dist/seed/index.d.mts +2 -2
- package/dist/seed/index.mjs +15 -14
- package/dist/seo/index.d.mts +1 -1
- package/dist/storage/local.d.mts +1 -1
- package/dist/storage/local.mjs +1 -1
- package/dist/storage/s3.d.mts +1 -1
- package/dist/storage/s3.mjs +1 -1
- package/dist/{taxonomies-B4IAshV8.mjs → taxonomies-ZlRtD6AG.mjs} +14 -7
- package/dist/taxonomies-ZlRtD6AG.mjs.map +1 -0
- package/dist/{tokens-D9vnZqYS.mjs → tokens-D7zMmWi2.mjs} +2 -2
- package/dist/{tokens-D9vnZqYS.mjs.map → tokens-D7zMmWi2.mjs.map} +1 -1
- package/dist/{transport-C9ugt2Nr.mjs → transport-BeMCmin1.mjs} +6 -5
- package/dist/{transport-C9ugt2Nr.mjs.map → transport-BeMCmin1.mjs.map} +1 -1
- package/dist/{transport-CUnEL3Vs.d.mts → transport-DNEfeMaU.d.mts} +1 -1
- package/dist/{transport-CUnEL3Vs.d.mts.map → transport-DNEfeMaU.d.mts.map} +1 -1
- package/dist/types-4fVtCIm0.mjs +68 -0
- package/dist/types-4fVtCIm0.mjs.map +1 -0
- package/dist/{types-BmPPSUEx.d.mts → types-BSyXeCFW.d.mts} +24 -2
- package/dist/{types-BmPPSUEx.d.mts.map → types-BSyXeCFW.d.mts.map} +1 -1
- package/dist/{types-i36XcA_X.d.mts → types-BuBIptGk.d.mts} +65 -134
- package/dist/types-BuBIptGk.d.mts.map +1 -0
- package/dist/{types-CgqmmMJB.mjs → types-CDbKp7ND.mjs} +1 -1
- package/dist/{types-CgqmmMJB.mjs.map → types-CDbKp7ND.mjs.map} +1 -1
- package/dist/{types-Bm1dn-q3.mjs → types-CIOg5AR8.mjs} +1 -1
- package/dist/{types-Bm1dn-q3.mjs.map → types-CIOg5AR8.mjs.map} +1 -1
- package/dist/{types-BrA0xf5I.d.mts → types-CJsYGpco.d.mts} +1 -1
- package/dist/{types-BrA0xf5I.d.mts.map → types-CJsYGpco.d.mts.map} +1 -1
- package/dist/{types-BIgulNsW.mjs → types-CRxNbK-Z.mjs} +2 -2
- package/dist/{types-BIgulNsW.mjs.map → types-CRxNbK-Z.mjs.map} +1 -1
- package/dist/{types-CS8FIX7L.d.mts → types-CrtWgIvl.d.mts} +1 -1
- package/dist/{types-CS8FIX7L.d.mts.map → types-CrtWgIvl.d.mts.map} +1 -1
- package/dist/{types-DIMwPFub.d.mts → types-M78DQ1lx.d.mts} +1 -1
- package/dist/{types-DIMwPFub.d.mts.map → types-M78DQ1lx.d.mts.map} +1 -1
- package/dist/{validate-CxVsLehf.mjs → validate-Baqf0slj.mjs} +3 -3
- package/dist/{validate-CxVsLehf.mjs.map → validate-Baqf0slj.mjs.map} +1 -1
- package/dist/{validate-DHxmpFJt.d.mts → validate-BfQh_C_y.d.mts} +4 -4
- package/dist/{validate-DHxmpFJt.d.mts.map → validate-BfQh_C_y.d.mts.map} +1 -1
- package/dist/{validation-C-ZpN2GI.mjs → validation-BfEI7tNe.mjs} +6 -6
- package/dist/{validation-C-ZpN2GI.mjs.map → validation-BfEI7tNe.mjs.map} +1 -1
- package/dist/version-DoxrVdYf.mjs +7 -0
- package/dist/{version-Bbq8TCrz.mjs.map → version-DoxrVdYf.mjs.map} +1 -1
- package/dist/{zod-generator-CpwccCIv.mjs → zod-generator-CC0xNe_K.mjs} +4 -4
- package/dist/zod-generator-CC0xNe_K.mjs.map +1 -0
- package/locals.d.ts +1 -6
- package/package.json +9 -8
- package/src/api/handlers/comments.ts +6 -4
- package/src/api/handlers/content.ts +29 -1
- package/src/api/handlers/device-flow.ts +5 -0
- package/src/api/handlers/marketplace.ts +11 -4
- package/src/api/handlers/oauth-authorization.ts +72 -33
- package/src/api/handlers/revision.ts +23 -14
- package/src/api/handlers/taxonomies.ts +3 -6
- package/src/api/public-url.ts +48 -2
- package/src/api/schemas/comments.ts +2 -2
- package/src/api/schemas/content.ts +17 -0
- package/src/api/schemas/sections.ts +3 -3
- package/src/api/schemas/users.ts +1 -1
- package/src/api/types.ts +5 -1
- package/src/astro/integration/index.ts +17 -0
- package/src/astro/integration/runtime.ts +30 -0
- package/src/astro/integration/virtual-modules.ts +32 -2
- package/src/astro/integration/vite-config.ts +6 -1
- package/src/astro/middleware/auth.ts +13 -6
- package/src/astro/middleware/redirect.ts +29 -16
- package/src/astro/middleware/request-context.ts +15 -5
- package/src/astro/middleware.ts +23 -9
- package/src/astro/routes/api/auth/invite/complete.ts +6 -1
- package/src/astro/routes/api/auth/passkey/register/verify.ts +6 -1
- package/src/astro/routes/api/auth/passkey/verify.ts +6 -1
- package/src/astro/routes/api/auth/signup/complete.ts +6 -1
- package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +2 -2
- package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +4 -2
- package/src/astro/routes/api/content/[collection]/[id]/preview-url.ts +34 -12
- package/src/astro/routes/api/content/[collection]/[id]/publish.ts +32 -2
- package/src/astro/routes/api/content/[collection]/[id]/restore.ts +4 -2
- package/src/astro/routes/api/content/[collection]/[id]/revisions.ts +3 -2
- package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +8 -4
- package/src/astro/routes/api/content/[collection]/[id].ts +12 -0
- package/src/astro/routes/api/import/wordpress/execute.ts +3 -1
- package/src/astro/routes/api/import/wordpress/prepare.ts +7 -8
- package/src/astro/routes/api/import/wordpress-plugin/execute.ts +3 -1
- package/src/astro/routes/api/manifest.ts +62 -45
- package/src/astro/routes/api/media/[id]/confirm.ts +10 -1
- package/src/astro/routes/api/media/providers/[providerId]/index.ts +12 -3
- package/src/astro/routes/api/openapi.json.ts +27 -10
- package/src/astro/routes/api/redirects/404s/index.ts +10 -4
- package/src/astro/routes/api/redirects/404s/summary.ts +4 -2
- package/src/astro/routes/api/redirects/[id].ts +10 -4
- package/src/astro/routes/api/redirects/index.ts +7 -3
- package/src/astro/routes/api/revisions/[revisionId]/index.ts +1 -1
- package/src/astro/routes/api/schema/collections/[slug]/fields/[fieldSlug].ts +0 -2
- package/src/astro/routes/api/schema/collections/[slug]/fields/index.ts +0 -1
- package/src/astro/routes/api/schema/collections/[slug]/fields/reorder.ts +0 -1
- package/src/astro/routes/api/schema/collections/[slug]/index.ts +2 -2
- package/src/astro/routes/api/schema/collections/index.ts +1 -1
- package/src/astro/routes/api/search/index.ts +10 -2
- package/src/astro/routes/api/sections/[slug].ts +10 -4
- package/src/astro/routes/api/sections/index.ts +7 -3
- package/src/astro/routes/api/setup/admin-verify.ts +6 -1
- package/src/astro/routes/api/snapshot.ts +44 -18
- package/src/astro/routes/api/taxonomies/index.ts +0 -1
- package/src/astro/routes/api/themes/preview.ts +11 -5
- package/src/astro/types.ts +23 -3
- package/src/auth/allowed-origins.ts +168 -0
- package/src/auth/passkey-config.ts +35 -13
- package/src/bylines/index.ts +37 -88
- package/src/cli/commands/auth.ts +28 -6
- package/src/cli/commands/bundle-utils.ts +11 -2
- package/src/cli/commands/bundle.ts +28 -8
- package/src/cli/commands/content.ts +13 -0
- package/src/cli/commands/login.ts +8 -1
- package/src/cli/commands/publish.ts +24 -0
- package/src/cli/commands/secrets.ts +183 -0
- package/src/cli/credentials.ts +1 -1
- package/src/cli/index.ts +5 -1
- package/src/client/index.ts +4 -4
- package/src/client/transport.ts +17 -7
- package/src/components/Break.astro +2 -2
- package/src/components/EmDashHead.astro +18 -13
- package/src/components/Embed.astro +1 -1
- package/src/components/Gallery.astro +1 -1
- package/src/components/Image.astro +1 -1
- package/src/components/InlinePortableTextEditor.tsx +104 -18
- package/src/config/secrets.ts +528 -0
- package/src/database/dialect-helpers.ts +50 -0
- package/src/database/migrations/034_published_at_index.ts +1 -1
- package/src/database/migrations/035_bounded_404_log.ts +56 -39
- package/src/database/migrations/runner.ts +156 -23
- package/src/database/repositories/content.ts +36 -12
- package/src/database/repositories/redirect.ts +14 -3
- package/src/database/repositories/taxonomy.ts +26 -0
- package/src/db/libsql.ts +1 -3
- package/src/db/sqlite.ts +2 -5
- package/src/emdash-runtime.ts +84 -159
- package/src/index.ts +9 -0
- package/src/loader.ts +24 -1
- package/src/mcp/server.ts +103 -36
- package/src/page/site-identity.ts +58 -0
- package/src/plugins/adapt-sandbox-entry.ts +22 -10
- package/src/plugins/context.ts +13 -10
- package/src/plugins/define-plugin.ts +40 -12
- package/src/plugins/hooks.ts +23 -19
- package/src/plugins/index.ts +9 -0
- package/src/plugins/manifest-schema.ts +37 -2
- package/src/plugins/types.ts +151 -11
- package/src/preview/urls.ts +23 -3
- package/src/query.ts +148 -5
- package/src/redirects/cache.ts +38 -18
- package/src/schema/registry.ts +56 -0
- package/src/schema/zod-generator.ts +27 -5
- package/src/seed/apply.ts +2 -0
- package/src/settings/index.ts +80 -6
- package/src/settings/types.ts +23 -1
- package/src/taxonomies/index.ts +11 -1
- package/dist/apply-x0eMK1lX.mjs.map +0 -1
- package/dist/bylines-CRNsVG88.mjs +0 -157
- package/dist/bylines-CRNsVG88.mjs.map +0 -1
- package/dist/cache-BkKBuIvS.mjs +0 -56
- package/dist/cache-BkKBuIvS.mjs.map +0 -1
- package/dist/chunk-ClPoSABd.mjs +0 -21
- package/dist/dialect-helpers-DhTzaUxP.mjs.map +0 -1
- package/dist/index-DIb-CzNx.d.mts.map +0 -1
- package/dist/loader-CndGj8kM.mjs.map +0 -1
- package/dist/manifest-schema-DH9xhc6t.mjs.map +0 -1
- package/dist/query-fqEdLFms.mjs.map +0 -1
- package/dist/redirect-D_pshWdf.mjs.map +0 -1
- package/dist/registry-C3Mr0ODu.mjs.map +0 -1
- package/dist/runner-OURCaApa.d.mts +0 -34
- package/dist/runner-OURCaApa.d.mts.map +0 -1
- package/dist/search-BoZYFuUk.mjs.map +0 -1
- package/dist/taxonomies-B4IAshV8.mjs.map +0 -1
- package/dist/types-i36XcA_X.d.mts.map +0 -1
- package/dist/version-Bbq8TCrz.mjs +0 -7
- package/dist/zod-generator-CpwccCIv.mjs.map +0 -1
package/src/plugins/types.ts
CHANGED
|
@@ -20,20 +20,151 @@ import type { FieldType } from "../schema/types.js";
|
|
|
20
20
|
// =============================================================================
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Plugin capabilities determine what APIs are available in context
|
|
23
|
+
* Plugin capabilities determine what APIs are available in context.
|
|
24
|
+
*
|
|
25
|
+
* Capabilities follow the formula `<resource>[.<sub-resource>]:<verb>[:<qualifier>]`
|
|
26
|
+
* — resource first, verb second, matching RBAC. The `unrestricted` qualifier
|
|
27
|
+
* (used by `network:request:unrestricted`) is intentionally verbose so that
|
|
28
|
+
* granting it stands out in manifest review.
|
|
29
|
+
*
|
|
30
|
+
* Hook-registration capabilities (`hooks.<family>:register`) are a distinct
|
|
31
|
+
* audit category from data-access capabilities — they gate which hooks a
|
|
32
|
+
* plugin is allowed to register, not which context APIs it gets.
|
|
33
|
+
*
|
|
34
|
+
* @see CAPABILITY_RENAMES for the legacy → current mapping, and
|
|
35
|
+
* `normalizeCapability()` for the runtime alias layer.
|
|
24
36
|
*/
|
|
25
37
|
export type PluginCapability =
|
|
26
|
-
|
|
27
|
-
| "network:
|
|
28
|
-
| "
|
|
29
|
-
|
|
30
|
-
| "read
|
|
31
|
-
| "write
|
|
32
|
-
|
|
38
|
+
// ── Network ─────────────────────────────────────────────────
|
|
39
|
+
| "network:request" // ctx.http is available (host-restricted via allowedHosts)
|
|
40
|
+
| "network:request:unrestricted" // ctx.http is available (unrestricted outbound — use for user-configured URLs)
|
|
41
|
+
// ── Content ─────────────────────────────────────────────────
|
|
42
|
+
| "content:read" // ctx.content.get/list available
|
|
43
|
+
| "content:write" // ctx.content.create/update/delete available
|
|
44
|
+
// ── Media ───────────────────────────────────────────────────
|
|
45
|
+
| "media:read" // ctx.media.get/list available
|
|
46
|
+
| "media:write" // ctx.media.getUploadUrl/delete available
|
|
47
|
+
// ── Users ───────────────────────────────────────────────────
|
|
48
|
+
| "users:read" // ctx.users is available
|
|
49
|
+
// ── Email ───────────────────────────────────────────────────
|
|
33
50
|
| "email:send" // ctx.email is available (when a provider is configured)
|
|
34
|
-
|
|
35
|
-
| "email:
|
|
36
|
-
| "
|
|
51
|
+
// ── Hook registration ───────────────────────────────────────
|
|
52
|
+
| "hooks.email-transport:register" // can register email:deliver exclusive hook (transport provider)
|
|
53
|
+
| "hooks.email-events:register" // can register email:beforeSend / email:afterSend hooks
|
|
54
|
+
| "hooks.page-fragments:register" // can register page:fragments hook (inject scripts/styles into pages)
|
|
55
|
+
// ── Deprecated (legacy aliases) ─────────────────────────────
|
|
56
|
+
// Kept in the union for one minor with @deprecated tags so existing
|
|
57
|
+
// plugins typecheck during migration. Normalized to current names at
|
|
58
|
+
// definition time via normalizeCapability(). Will be removed in the
|
|
59
|
+
// following minor.
|
|
60
|
+
/** @deprecated Use `network:request` instead. */
|
|
61
|
+
| "network:fetch"
|
|
62
|
+
/** @deprecated Use `network:request:unrestricted` instead. */
|
|
63
|
+
| "network:fetch:any"
|
|
64
|
+
/** @deprecated Use `content:read` instead. */
|
|
65
|
+
| "read:content"
|
|
66
|
+
/** @deprecated Use `content:write` instead. */
|
|
67
|
+
| "write:content"
|
|
68
|
+
/** @deprecated Use `media:read` instead. */
|
|
69
|
+
| "read:media"
|
|
70
|
+
/** @deprecated Use `media:write` instead. */
|
|
71
|
+
| "write:media"
|
|
72
|
+
/** @deprecated Use `users:read` instead. */
|
|
73
|
+
| "read:users"
|
|
74
|
+
/** @deprecated Use `hooks.email-transport:register` instead. */
|
|
75
|
+
| "email:provide"
|
|
76
|
+
/** @deprecated Use `hooks.email-events:register` instead. */
|
|
77
|
+
| "email:intercept"
|
|
78
|
+
/** @deprecated Use `hooks.page-fragments:register` instead. */
|
|
79
|
+
| "page:inject";
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Deprecated capability names that map to current names.
|
|
83
|
+
*
|
|
84
|
+
* These are accepted at every external boundary (manifest parse, definePlugin,
|
|
85
|
+
* adaptSandboxEntry) and silently normalized to the new names before reaching
|
|
86
|
+
* the runtime. The runtime never sees deprecated names.
|
|
87
|
+
*
|
|
88
|
+
* Authors are warned at `bundle` / `validate`, and hard-failed at `publish`.
|
|
89
|
+
*/
|
|
90
|
+
export type DeprecatedPluginCapability =
|
|
91
|
+
| "network:fetch"
|
|
92
|
+
| "network:fetch:any"
|
|
93
|
+
| "read:content"
|
|
94
|
+
| "write:content"
|
|
95
|
+
| "read:media"
|
|
96
|
+
| "write:media"
|
|
97
|
+
| "read:users"
|
|
98
|
+
| "email:provide"
|
|
99
|
+
| "email:intercept"
|
|
100
|
+
| "page:inject";
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Current (non-deprecated) capability names.
|
|
104
|
+
*/
|
|
105
|
+
export type CurrentPluginCapability = Exclude<PluginCapability, DeprecatedPluginCapability>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Mapping from deprecated capability names to their current replacements.
|
|
109
|
+
*
|
|
110
|
+
* Used by `normalizeCapability()` and the marketplace `diffCapabilities`
|
|
111
|
+
* helper to compare manifests across the rename without flagging spurious
|
|
112
|
+
* "capability changed" prompts on upgrade.
|
|
113
|
+
*/
|
|
114
|
+
export const CAPABILITY_RENAMES: Readonly<
|
|
115
|
+
Record<DeprecatedPluginCapability, CurrentPluginCapability>
|
|
116
|
+
> = Object.freeze({
|
|
117
|
+
"network:fetch": "network:request",
|
|
118
|
+
"network:fetch:any": "network:request:unrestricted",
|
|
119
|
+
"read:content": "content:read",
|
|
120
|
+
"write:content": "content:write",
|
|
121
|
+
"read:media": "media:read",
|
|
122
|
+
"write:media": "media:write",
|
|
123
|
+
"read:users": "users:read",
|
|
124
|
+
"email:provide": "hooks.email-transport:register",
|
|
125
|
+
"email:intercept": "hooks.email-events:register",
|
|
126
|
+
"page:inject": "hooks.page-fragments:register",
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Type guard: is this capability one of the deprecated legacy names?
|
|
131
|
+
*
|
|
132
|
+
* Uses an own-property check so that prototype keys like "toString" or
|
|
133
|
+
* "constructor" don't accidentally pass.
|
|
134
|
+
*/
|
|
135
|
+
export function isDeprecatedCapability(cap: string): cap is DeprecatedPluginCapability {
|
|
136
|
+
return Object.hasOwn(CAPABILITY_RENAMES, cap);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Normalize a capability string — deprecated names map to current names,
|
|
141
|
+
* current names pass through unchanged. Unknown strings are returned as-is
|
|
142
|
+
* so that downstream validators can produce a precise error.
|
|
143
|
+
*/
|
|
144
|
+
export function normalizeCapability(cap: string): string {
|
|
145
|
+
if (isDeprecatedCapability(cap)) {
|
|
146
|
+
return CAPABILITY_RENAMES[cap];
|
|
147
|
+
}
|
|
148
|
+
return cap;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Normalize an array of capabilities. Deduplicates by normalized name so
|
|
153
|
+
* that a plugin declaring both `read:content` and `content:read` ends up
|
|
154
|
+
* with a single `content:read` entry.
|
|
155
|
+
*/
|
|
156
|
+
export function normalizeCapabilities(caps: readonly string[]): string[] {
|
|
157
|
+
const seen = new Set<string>();
|
|
158
|
+
const out: string[] = [];
|
|
159
|
+
for (const cap of caps) {
|
|
160
|
+
const normalized = normalizeCapability(cap);
|
|
161
|
+
if (!seen.has(normalized)) {
|
|
162
|
+
seen.add(normalized);
|
|
163
|
+
out.push(normalized);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
37
168
|
|
|
38
169
|
// =============================================================================
|
|
39
170
|
// Storage Types
|
|
@@ -1201,6 +1332,15 @@ export interface PortableTextBlockConfig {
|
|
|
1201
1332
|
placeholder?: string;
|
|
1202
1333
|
/** Block Kit form fields for the editing UI. If declared, replaces the simple URL input. */
|
|
1203
1334
|
fields?: PortableTextBlockField[];
|
|
1335
|
+
/**
|
|
1336
|
+
* Optional. Display category in the slash menu. Defaults to "Embeds".
|
|
1337
|
+
*
|
|
1338
|
+
* Plugin authors should pick a meaningful category that reflects what the
|
|
1339
|
+
* block actually is — e.g. "Sections", "Marketing", "Media", "Embeds",
|
|
1340
|
+
* "Layout". Blocks with the same category are grouped together in the
|
|
1341
|
+
* editor's slash menu.
|
|
1342
|
+
*/
|
|
1343
|
+
category?: string;
|
|
1204
1344
|
}
|
|
1205
1345
|
|
|
1206
1346
|
/**
|
package/src/preview/urls.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
import { generatePreviewToken } from "./tokens.js";
|
|
8
8
|
|
|
9
|
+
const REPEATED_SLASHES = /\/{2,}/g;
|
|
10
|
+
|
|
9
11
|
/**
|
|
10
12
|
* Options for generating a preview URL
|
|
11
13
|
*/
|
|
@@ -20,8 +22,18 @@ export interface GetPreviewUrlOptions {
|
|
|
20
22
|
expiresIn?: string | number;
|
|
21
23
|
/** Base URL of the site. If not provided, returns a relative URL. */
|
|
22
24
|
baseUrl?: string;
|
|
23
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Custom path pattern. Supports `{collection}`, `{id}` and `{locale}`
|
|
27
|
+
* placeholders. Default: `"/{collection}/{id}"`.
|
|
28
|
+
*/
|
|
24
29
|
pathPattern?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Locale segment substituted for the `{locale}` placeholder in `pathPattern`.
|
|
32
|
+
* Pass an empty string to omit the locale prefix (e.g. for the default locale
|
|
33
|
+
* when `prefixDefaultLocale` is `false`); adjacent slashes left by an empty
|
|
34
|
+
* value are collapsed and any trailing slash is trimmed.
|
|
35
|
+
*/
|
|
36
|
+
locale?: string;
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
/**
|
|
@@ -65,6 +77,7 @@ export async function getPreviewUrl(options: GetPreviewUrlOptions): Promise<stri
|
|
|
65
77
|
expiresIn = "1h",
|
|
66
78
|
baseUrl,
|
|
67
79
|
pathPattern = "/{collection}/{id}",
|
|
80
|
+
locale = "",
|
|
68
81
|
} = options;
|
|
69
82
|
|
|
70
83
|
// Generate the signed token
|
|
@@ -74,8 +87,15 @@ export async function getPreviewUrl(options: GetPreviewUrlOptions): Promise<stri
|
|
|
74
87
|
secret,
|
|
75
88
|
});
|
|
76
89
|
|
|
77
|
-
// Build the path
|
|
78
|
-
|
|
90
|
+
// Build the path. `{locale}` may resolve to an empty string (default locale
|
|
91
|
+
// without a prefix); collapse the resulting double slashes and trim a
|
|
92
|
+
// trailing slash so the URL stays clean.
|
|
93
|
+
let path = pathPattern
|
|
94
|
+
.replace("{collection}", collection)
|
|
95
|
+
.replace("{id}", id)
|
|
96
|
+
.replace("{locale}", locale);
|
|
97
|
+
path = path.replace(REPEATED_SLASHES, "/");
|
|
98
|
+
if (path.length > 1 && path.endsWith("/")) path = path.slice(0, -1);
|
|
79
99
|
|
|
80
100
|
// Add token as query parameter
|
|
81
101
|
const url = new URL(path, baseUrl || "http://placeholder");
|
package/src/query.ts
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* and sets the context; query functions read it automatically.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import { encodeCursor } from "./database/repositories/types.js";
|
|
15
16
|
import { getFallbackChain, getI18nConfig, isI18nEnabled } from "./i18n/config.js";
|
|
17
|
+
import { CURSOR_RAW_VALUES } from "./loader.js";
|
|
16
18
|
import { requestCached } from "./request-cache.js";
|
|
17
19
|
import { getRequestContext } from "./request-context.js";
|
|
18
20
|
import { isMissingTableError } from "./utils/db-errors.js";
|
|
@@ -279,9 +281,144 @@ export async function getEmDashCollection<T extends string, D = InferCollectionD
|
|
|
279
281
|
// appears on the home page AND in the sidebar) — caching collapses
|
|
280
282
|
// those duplicate queries, along with the bylines and taxonomy-term
|
|
281
283
|
// hydration each call would otherwise re-do.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
+
//
|
|
285
|
+
// Bucket small limits to a shared minimum so a page with several
|
|
286
|
+
// "recent N posts" widgets at slightly different limits (e.g. a
|
|
287
|
+
// post-detail page asking for 4 in the body and 5 in the sidebar)
|
|
288
|
+
// shares one fetch + hydration round-trip rather than running two.
|
|
289
|
+
// Cursor-paginated calls are exempt: their limit is part of the
|
|
290
|
+
// pagination contract.
|
|
291
|
+
const bucketed = bucketFilter(filter);
|
|
292
|
+
const cached = await requestCached(collectionCacheKey(type, bucketed.fetchFilter), () =>
|
|
293
|
+
getEmDashCollectionUncached<T, D>(type, bucketed.fetchFilter),
|
|
284
294
|
);
|
|
295
|
+
return bucketed.requestedLimit === undefined
|
|
296
|
+
? cached
|
|
297
|
+
: sliceCollectionResult(cached, bucketed.requestedLimit, filter?.orderBy);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Threshold for limit bucketing. Page templates routinely render small
|
|
302
|
+
* "recent posts" widgets at limits 3-8; rounding those up to a single
|
|
303
|
+
* shared bucket lets one fetch satisfy several widgets within a request.
|
|
304
|
+
* Above this, the requested limit is honoured exactly — bucketing limit:50
|
|
305
|
+
* to limit:64 would waste hydration work for callers fetching real pages.
|
|
306
|
+
*/
|
|
307
|
+
const BUCKET_LIMIT_THRESHOLD = 10;
|
|
308
|
+
|
|
309
|
+
interface BucketedFilter {
|
|
310
|
+
/** Filter to pass to the loader (with limit possibly raised). */
|
|
311
|
+
fetchFilter: CollectionFilter | undefined;
|
|
312
|
+
/** Original limit; defined only when bucketing was applied. */
|
|
313
|
+
requestedLimit: number | undefined;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** @internal exported for unit tests; not part of the public API. */
|
|
317
|
+
export function bucketFilter(filter: CollectionFilter | undefined): BucketedFilter {
|
|
318
|
+
const limit = filter?.limit;
|
|
319
|
+
if (
|
|
320
|
+
limit === undefined ||
|
|
321
|
+
limit >= BUCKET_LIMIT_THRESHOLD ||
|
|
322
|
+
limit <= 0 ||
|
|
323
|
+
filter?.cursor !== undefined
|
|
324
|
+
) {
|
|
325
|
+
return { fetchFilter: filter, requestedLimit: undefined };
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
fetchFilter: { ...filter, limit: BUCKET_LIMIT_THRESHOLD },
|
|
329
|
+
requestedLimit: limit,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Slice a cached bucketed result down to the originally-requested limit
|
|
335
|
+
* and recompute `nextCursor` from the row that would have been the
|
|
336
|
+
* over-fetch detector for that limit. When truncation is needed, returns
|
|
337
|
+
* a shallow-copied result with a new `entries` array; otherwise returns
|
|
338
|
+
* the cached result unchanged (including error results and results
|
|
339
|
+
* already within the requested limit).
|
|
340
|
+
*/
|
|
341
|
+
/** @internal exported for unit tests; not part of the public API. */
|
|
342
|
+
export function sliceCollectionResult<D>(
|
|
343
|
+
cached: CollectionResult<D>,
|
|
344
|
+
limit: number,
|
|
345
|
+
orderBy: OrderBySpec | undefined,
|
|
346
|
+
): CollectionResult<D> {
|
|
347
|
+
if (cached.error) return cached;
|
|
348
|
+
if (cached.entries.length <= limit) return cached;
|
|
349
|
+
const sliced = cached.entries.slice(0, limit);
|
|
350
|
+
// Mirror the loader's encoding: cursor points at the last returned row,
|
|
351
|
+
// so "next page" picks up at the row immediately after it. See
|
|
352
|
+
// buildCursorCondition in loader.ts — it filters strictly past this row.
|
|
353
|
+
const lastEntry = sliced.at(-1);
|
|
354
|
+
const nextCursor = lastEntry ? encodeEntryCursor(lastEntry, orderBy) : undefined;
|
|
355
|
+
return { ...cached, entries: sliced, nextCursor };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Map of database column names to camelCase keys present on entry.data. */
|
|
359
|
+
const ENTRY_DATA_KEY_MAP: Record<string, string> = {
|
|
360
|
+
created_at: "createdAt",
|
|
361
|
+
updated_at: "updatedAt",
|
|
362
|
+
published_at: "publishedAt",
|
|
363
|
+
scheduled_at: "scheduledAt",
|
|
364
|
+
author_id: "authorId",
|
|
365
|
+
primary_byline_id: "primaryBylineId",
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
// Mirror loader.ts FIELD_NAME_PATTERN. Kept in sync intentionally — diverging
|
|
369
|
+
// would let the encoder accept a field name the loader's getPrimarySort then
|
|
370
|
+
// rejected, producing a cursor that paginates against a different column.
|
|
371
|
+
const FIELD_NAME_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Encode a `nextCursor` from a content entry, mirroring the loader's
|
|
375
|
+
* encoding scheme: `(orderValue, id)` where `orderValue` is the primary
|
|
376
|
+
* sort field's stringified value. For date columns, reads the raw DB
|
|
377
|
+
* string the loader stashed via CURSOR_RAW_VALUES — round-tripping the
|
|
378
|
+
* parsed Date through `toISOString()` would lose precision for stored
|
|
379
|
+
* values that aren't already ISO-with-milliseconds.
|
|
380
|
+
*/
|
|
381
|
+
function encodeEntryCursor<D>(
|
|
382
|
+
entry: ContentEntry<D>,
|
|
383
|
+
orderBy: OrderBySpec | undefined,
|
|
384
|
+
): string | undefined {
|
|
385
|
+
const data = entryData(entry);
|
|
386
|
+
const id = dataStr(data, "id");
|
|
387
|
+
if (!id) return undefined;
|
|
388
|
+
|
|
389
|
+
// Match loader.ts getPrimarySort: take the first valid field, default to created_at.
|
|
390
|
+
let dbField = "created_at";
|
|
391
|
+
if (orderBy) {
|
|
392
|
+
for (const field of Object.keys(orderBy)) {
|
|
393
|
+
if (FIELD_NAME_PATTERN.test(field)) {
|
|
394
|
+
dbField = field;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Date columns: prefer the raw stored string captured by the loader so
|
|
401
|
+
// the cursor matches what a direct loader fetch would emit, regardless
|
|
402
|
+
// of how the DB stored the timestamp.
|
|
403
|
+
const rawDateValuesRaw = Reflect.get(data, CURSOR_RAW_VALUES);
|
|
404
|
+
if (rawDateValuesRaw !== null && typeof rawDateValuesRaw === "object") {
|
|
405
|
+
const raw = Reflect.get(rawDateValuesRaw, dbField);
|
|
406
|
+
if (typeof raw === "string") return encodeCursor(raw, id);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const dataKey = ENTRY_DATA_KEY_MAP[dbField] ?? dbField;
|
|
410
|
+
const value = data[dataKey];
|
|
411
|
+
let orderValue: string;
|
|
412
|
+
if (value instanceof Date) {
|
|
413
|
+
orderValue = value.toISOString();
|
|
414
|
+
} else if (typeof value === "string" || typeof value === "number") {
|
|
415
|
+
orderValue = String(value);
|
|
416
|
+
} else {
|
|
417
|
+
// Match the loader's empty-string fallback for null/undefined order
|
|
418
|
+
// values so cursor decoding stays valid even at the boundary.
|
|
419
|
+
orderValue = "";
|
|
420
|
+
}
|
|
421
|
+
return encodeCursor(orderValue, id);
|
|
285
422
|
}
|
|
286
423
|
|
|
287
424
|
/**
|
|
@@ -562,10 +699,16 @@ async function hydrateEntryBylines<D>(type: string, entries: ContentEntry<D>[]):
|
|
|
562
699
|
try {
|
|
563
700
|
const { getBylinesForEntries } = await import("./bylines/index.js");
|
|
564
701
|
|
|
565
|
-
const
|
|
566
|
-
|
|
702
|
+
const refs = entries
|
|
703
|
+
.map((e) => {
|
|
704
|
+
const data = entryData(e);
|
|
705
|
+
const id = dataStr(data, "id");
|
|
706
|
+
return id ? { id, authorId: dataStr(data, "authorId") || null } : null;
|
|
707
|
+
})
|
|
708
|
+
.filter((r): r is { id: string; authorId: string | null } => r !== null);
|
|
709
|
+
if (refs.length === 0) return;
|
|
567
710
|
|
|
568
|
-
const bylinesMap = await getBylinesForEntries(type,
|
|
711
|
+
const bylinesMap = await getBylinesForEntries(type, refs);
|
|
569
712
|
|
|
570
713
|
for (const entry of entries) {
|
|
571
714
|
const data = entryData(entry);
|
package/src/redirects/cache.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Redirect
|
|
2
|
+
* Redirect rule cache.
|
|
3
3
|
*
|
|
4
|
-
* Module-level cache for
|
|
5
|
-
*
|
|
4
|
+
* Module-level cache for enabled redirect rules. The middleware populates this
|
|
5
|
+
* on first request; route handlers invalidate it on writes.
|
|
6
|
+
*
|
|
7
|
+
* Both exact-match and pattern rules are loaded from one query and cached
|
|
8
|
+
* together: exact rules indexed by source path in a Map, pattern rules
|
|
9
|
+
* pre-compiled into an array. A single warm request issues zero database
|
|
10
|
+
* queries; a cold isolate issues one.
|
|
6
11
|
*
|
|
7
12
|
* This module deliberately has NO Astro imports so it can be safely imported
|
|
8
13
|
* from handlers, seed, CLI, and tests without dragging in `astro:middleware`.
|
|
@@ -17,36 +22,51 @@ export interface CachedRedirectRule {
|
|
|
17
22
|
compiled: CompiledPattern;
|
|
18
23
|
}
|
|
19
24
|
|
|
25
|
+
export interface CachedRedirects {
|
|
26
|
+
/** Exact-match rules indexed by source path (`source` -> `Redirect`). */
|
|
27
|
+
exact: Map<string, Redirect>;
|
|
28
|
+
/** Pattern rules with their compiled regexes, preserving insertion order. */
|
|
29
|
+
patterns: CachedRedirectRule[];
|
|
30
|
+
}
|
|
31
|
+
|
|
20
32
|
/**
|
|
21
|
-
* Cached
|
|
22
|
-
* null = not yet populated,
|
|
33
|
+
* Cached enabled redirects.
|
|
34
|
+
* null = not yet populated, object = cached.
|
|
23
35
|
*/
|
|
24
|
-
let
|
|
36
|
+
let cachedRedirects: CachedRedirects | null = null;
|
|
25
37
|
|
|
26
38
|
/**
|
|
27
|
-
* Invalidate the cached
|
|
39
|
+
* Invalidate the cached redirects (both exact and pattern).
|
|
28
40
|
* Call when redirects are created, updated, or deleted.
|
|
29
41
|
*/
|
|
30
42
|
export function invalidateRedirectCache(): void {
|
|
31
|
-
|
|
43
|
+
cachedRedirects = null;
|
|
32
44
|
}
|
|
33
45
|
|
|
34
46
|
/**
|
|
35
|
-
* Get the cached
|
|
47
|
+
* Get the cached redirects, or null if the cache is cold.
|
|
36
48
|
*/
|
|
37
|
-
export function
|
|
38
|
-
return
|
|
49
|
+
export function getCachedRedirects(): CachedRedirects | null {
|
|
50
|
+
return cachedRedirects;
|
|
39
51
|
}
|
|
40
52
|
|
|
41
53
|
/**
|
|
42
|
-
* Populate the
|
|
54
|
+
* Populate the cache from a list of enabled redirects (both exact and
|
|
55
|
+
* pattern). The caller is responsible for passing only enabled rows — the
|
|
56
|
+
* cache stores them as-is.
|
|
43
57
|
*/
|
|
44
|
-
export function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
export function setCachedRedirects(redirects: Redirect[]): CachedRedirects {
|
|
59
|
+
const exact = new Map<string, Redirect>();
|
|
60
|
+
const patterns: CachedRedirectRule[] = [];
|
|
61
|
+
for (const r of redirects) {
|
|
62
|
+
if (r.isPattern) {
|
|
63
|
+
patterns.push({ redirect: r, compiled: compilePattern(r.source) });
|
|
64
|
+
} else {
|
|
65
|
+
exact.set(r.source, r);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
cachedRedirects = { exact, patterns };
|
|
69
|
+
return cachedRedirects;
|
|
50
70
|
}
|
|
51
71
|
|
|
52
72
|
/**
|
package/src/schema/registry.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { withTransaction } from "../database/transaction.js";
|
|
|
8
8
|
import type { CollectionTable, Database, FieldTable } from "../database/types.js";
|
|
9
9
|
import { validateIdentifier } from "../database/validate.js";
|
|
10
10
|
import { FTSManager } from "../search/fts-manager.js";
|
|
11
|
+
import { chunks, SQL_BATCH_SIZE } from "../utils/chunks.js";
|
|
11
12
|
import {
|
|
12
13
|
type Collection,
|
|
13
14
|
type CollectionSource,
|
|
@@ -143,6 +144,61 @@ export class SchemaRegistry {
|
|
|
143
144
|
return { ...collection, fields };
|
|
144
145
|
}
|
|
145
146
|
|
|
147
|
+
/**
|
|
148
|
+
* List every collection together with its fields in O(1) query shapes
|
|
149
|
+
* — one for collections, then one batched query for the fields of every
|
|
150
|
+
* returned collection — instead of the N+1 pattern of `listCollections`
|
|
151
|
+
* + per-collection `listFields`. The fields query is chunked at
|
|
152
|
+
* `SQL_BATCH_SIZE` to stay under D1's bound-parameter limit, so on
|
|
153
|
+
* sites with more than `SQL_BATCH_SIZE` collections the field fetch
|
|
154
|
+
* becomes `ceil(collectionCount / SQL_BATCH_SIZE)` queries — still
|
|
155
|
+
* a constant factor, not N+1. Typical sites have well under
|
|
156
|
+
* `SQL_BATCH_SIZE` collections, so this is two queries in practice.
|
|
157
|
+
*
|
|
158
|
+
* Used by the manifest build, which previously paid N+1 round-trips on
|
|
159
|
+
* every admin request. Each round-trip costs ~80–150ms against the D1
|
|
160
|
+
* primary on a busy link, so a 10-collection site spent ~1 s rebuilding
|
|
161
|
+
* a manifest that is now built fresh per admin request (no cache).
|
|
162
|
+
*/
|
|
163
|
+
async listCollectionsWithFields(): Promise<CollectionWithFields[]> {
|
|
164
|
+
const collectionRows = await this.db
|
|
165
|
+
.selectFrom("_emdash_collections")
|
|
166
|
+
.selectAll()
|
|
167
|
+
.orderBy("slug", "asc")
|
|
168
|
+
.execute();
|
|
169
|
+
|
|
170
|
+
if (collectionRows.length === 0) return [];
|
|
171
|
+
|
|
172
|
+
const fieldsByCollection = new Map<string, Field[]>();
|
|
173
|
+
// Chunk to stay under D1's bound-parameter limit. Typical sites have
|
|
174
|
+
// well under SQL_BATCH_SIZE collections, so this is a single query
|
|
175
|
+
// in practice; on larger sites it becomes a small constant number
|
|
176
|
+
// of queries, never N+1.
|
|
177
|
+
for (const idChunk of chunks(
|
|
178
|
+
collectionRows.map((c) => c.id),
|
|
179
|
+
SQL_BATCH_SIZE,
|
|
180
|
+
)) {
|
|
181
|
+
const fieldRows = await this.db
|
|
182
|
+
.selectFrom("_emdash_fields")
|
|
183
|
+
.where("collection_id", "in", idChunk)
|
|
184
|
+
.selectAll()
|
|
185
|
+
.orderBy("collection_id", "asc")
|
|
186
|
+
.orderBy("sort_order", "asc")
|
|
187
|
+
.orderBy("created_at", "asc")
|
|
188
|
+
.execute();
|
|
189
|
+
for (const row of fieldRows) {
|
|
190
|
+
const list = fieldsByCollection.get(row.collection_id) ?? [];
|
|
191
|
+
list.push(this.mapFieldRow(row));
|
|
192
|
+
fieldsByCollection.set(row.collection_id, list);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return collectionRows.map((c) => ({
|
|
197
|
+
...this.mapCollectionRow(c),
|
|
198
|
+
fields: fieldsByCollection.get(c.id) ?? [],
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
|
|
146
202
|
/**
|
|
147
203
|
* Create a new collection
|
|
148
204
|
*/
|
|
@@ -35,9 +35,16 @@ export function generateFieldSchema(field: Field): ZodTypeAny {
|
|
|
35
35
|
schema = applyValidation(schema, field);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// Apply required/optional
|
|
38
|
+
// Apply required/optional. Non-required fields use `.nullish()` rather
|
|
39
|
+
// than `.optional()` because the underlying SQLite columns are nullable
|
|
40
|
+
// (see `SchemaRegistry.addFieldColumn` -- non-required fields are added
|
|
41
|
+
// without `NOT NULL`). The admin re-sends what it loaded from the
|
|
42
|
+
// server on autosave, so any field that's actually `null` in the DB
|
|
43
|
+
// must round-trip cleanly through the validator. `.optional()` only
|
|
44
|
+
// accepts `undefined`; `.nullish()` accepts both `undefined` and
|
|
45
|
+
// `null`. (#867 — autosave failures on seeded entries.)
|
|
39
46
|
if (!field.required) {
|
|
40
|
-
schema = schema.
|
|
47
|
+
schema = schema.nullish();
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
// Apply default value
|
|
@@ -68,7 +75,15 @@ function getBaseSchema(type: FieldType, field: Field): ZodTypeAny {
|
|
|
68
75
|
return z.number().int();
|
|
69
76
|
|
|
70
77
|
case "boolean":
|
|
71
|
-
|
|
78
|
+
// Boolean fields map to `INTEGER` columns (`FIELD_TYPE_TO_COLUMN`
|
|
79
|
+
// in `schema/types.ts`) and `serializeValue` in
|
|
80
|
+
// `database/repositories/content.ts` writes booleans as 0/1.
|
|
81
|
+
// `deserializeValue` never converts them back, so reads return
|
|
82
|
+
// numbers. Coerce the stored 0/1 shape here so a GET → POST
|
|
83
|
+
// round-trip on a boolean field passes validation. Other inputs
|
|
84
|
+
// (strings, other numbers) fall through to `z.boolean()` and
|
|
85
|
+
// produce its standard rejection.
|
|
86
|
+
return z.preprocess((v) => (v === 0 || v === 1 ? Boolean(v) : v), z.boolean());
|
|
72
87
|
|
|
73
88
|
case "datetime":
|
|
74
89
|
return z.string().datetime().or(z.string().date());
|
|
@@ -92,12 +107,19 @@ function getBaseSchema(type: FieldType, field: Field): ZodTypeAny {
|
|
|
92
107
|
}
|
|
93
108
|
|
|
94
109
|
case "portableText":
|
|
95
|
-
// Portable Text is an array of blocks
|
|
110
|
+
// Portable Text is an array of blocks. We require `_type` because
|
|
111
|
+
// renderers dispatch on it, but `_key` is intentionally optional:
|
|
112
|
+
// it's a UI-layer concern that the editor regenerates on every
|
|
113
|
+
// change (see `PortableTextEditor`), and the rest of this schema
|
|
114
|
+
// uses `.passthrough()` for everything below the top level. Making
|
|
115
|
+
// `_key` strictly required here was an accidentally tight invariant
|
|
116
|
+
// that rejected any seed/import data not authored against the
|
|
117
|
+
// editor (#867 — autosave failures on seeded template content).
|
|
96
118
|
return z.array(
|
|
97
119
|
z
|
|
98
120
|
.object({
|
|
99
121
|
_type: z.string(),
|
|
100
|
-
_key: z.string(),
|
|
122
|
+
_key: z.string().optional(),
|
|
101
123
|
})
|
|
102
124
|
.passthrough(),
|
|
103
125
|
);
|
package/src/seed/apply.ts
CHANGED
|
@@ -927,6 +927,8 @@ async function applyWidget(
|
|
|
927
927
|
sort_order: sortOrder,
|
|
928
928
|
type: widget.type,
|
|
929
929
|
title: widget.title ?? null,
|
|
930
|
+
// `widget.content` is Portable Text for content-type widgets;
|
|
931
|
+
// for other widget kinds it's null.
|
|
930
932
|
content: widget.content ? JSON.stringify(widget.content) : null,
|
|
931
933
|
menu_name: widget.menuName ?? null,
|
|
932
934
|
component_id: widget.componentId ?? null,
|