@conloca/astro-cms 0.1.16 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +254 -301
- package/dist/internal/acorn-default.mjs +11 -3
- package/dist/internal/page-handler.astro +137 -358
- package/dist/ts/node/content.d.ts +4 -0
- package/dist/ts/node/content.d.ts.map +1 -0
- package/dist/ts/node/content.js +3 -0
- package/dist/ts/node/content.js.map +1 -0
- package/dist/ts/node/index.d.ts +9 -0
- package/dist/ts/node/index.d.ts.map +1 -0
- package/dist/ts/node/index.js +14 -0
- package/dist/ts/node/index.js.map +1 -0
- package/dist/ts/src/asset-ref-base.d.ts +3 -0
- package/dist/ts/src/asset-ref-base.d.ts.map +1 -0
- package/dist/ts/src/asset-ref-base.js +48 -0
- package/dist/ts/src/asset-ref-base.js.map +1 -0
- package/dist/ts/src/checks.d.ts +7 -0
- package/dist/ts/src/checks.d.ts.map +1 -0
- package/dist/ts/src/checks.js +7 -0
- package/dist/ts/src/checks.js.map +1 -0
- package/dist/{src → ts/src}/cms-handler.d.ts +0 -1
- package/dist/ts/src/cms-handler.d.ts.map +1 -0
- package/dist/{src → ts/src}/cms-handler.js +11 -131
- package/dist/ts/src/cms-handler.js.map +1 -0
- package/dist/ts/src/collections.d.ts +161 -0
- package/dist/ts/src/collections.d.ts.map +1 -0
- package/dist/ts/src/collections.js +178 -0
- package/dist/ts/src/collections.js.map +1 -0
- package/dist/{src → ts/src}/components/HydrationWrapper.d.ts +1 -1
- package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/{src → ts/src}/components/HydrationWrapper.js +1 -0
- package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
- package/dist/{src/components/RenderWithBlocks.d.ts → ts/src/components/RenderWithFragments.d.ts} +8 -4
- package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.js +133 -0
- package/dist/ts/src/components/RenderWithFragments.js.map +1 -0
- package/dist/{src → ts/src}/components/RenderWithHydration.d.ts +6 -2
- package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/{src → ts/src}/components/RenderWithHydration.js +6 -3
- package/dist/ts/src/components/RenderWithHydration.js.map +1 -0
- package/dist/ts/src/components.d.ts +4 -0
- package/dist/ts/src/components.d.ts.map +1 -0
- package/dist/ts/src/components.js +4 -0
- package/dist/ts/src/components.js.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/astro-frontmatter.js +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
- package/dist/ts/src/discovery/discover.d.ts +43 -0
- package/dist/ts/src/discovery/discover.d.ts.map +1 -0
- package/dist/ts/src/discovery/discover.js +87 -0
- package/dist/ts/src/discovery/discover.js.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/extract-props-ts.js +1 -0
- package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
- package/dist/{src → ts/src}/discovery/merge-registry.d.ts +3 -3
- package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/merge-registry.js +1 -0
- package/dist/ts/src/discovery/merge-registry.js.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.js +76 -0
- package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-components.d.ts +3 -7
- package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-components.js +4 -6
- package/dist/ts/src/discovery/scan-components.js.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-mdx.js +1 -0
- package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/{src → ts/src}/discovery/scan-overrides.js +1 -0
- package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
- package/dist/ts/src/editor-descriptors.d.ts +31 -0
- package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
- package/dist/ts/src/editor-descriptors.js +84 -0
- package/dist/ts/src/editor-descriptors.js.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.js +166 -0
- package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
- package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
- package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
- package/dist/ts/src/handlers/page-render-core.js +315 -0
- package/dist/ts/src/handlers/page-render-core.js.map +1 -0
- package/dist/ts/src/hydration.d.ts.map +1 -0
- package/dist/{src → ts/src}/hydration.js +1 -0
- package/dist/ts/src/hydration.js.map +1 -0
- package/dist/ts/src/index.d.ts +21 -0
- package/dist/ts/src/index.d.ts.map +1 -0
- package/dist/ts/src/index.js +45 -0
- package/dist/ts/src/index.js.map +1 -0
- package/dist/ts/src/internal/declared-collections.d.ts +30 -0
- package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
- package/dist/ts/src/internal/declared-collections.js +84 -0
- package/dist/ts/src/internal/declared-collections.js.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.js +152 -0
- package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
- package/dist/ts/src/lib/content-config-guard.d.ts +13 -0
- package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
- package/dist/ts/src/lib/content-config-guard.js +45 -0
- package/dist/ts/src/lib/content-config-guard.js.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-scanner.js +1 -0
- package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
- package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-script.js +1 -0
- package/dist/ts/src/lib/hydration-script.js.map +1 -0
- package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/hydration-utils.js +1 -0
- package/dist/ts/src/lib/hydration-utils.js.map +1 -0
- package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
- package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-locale.js +16 -0
- package/dist/ts/src/lib/resolve-locale.js.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.js +12 -0
- package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
- package/dist/{src → ts/src}/lib/route-utils.d.ts +26 -6
- package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/route-utils.js +33 -15
- package/dist/ts/src/lib/route-utils.js.map +1 -0
- package/dist/{src → ts/src}/lib/routing-config.d.ts +7 -1
- package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/routing-config.js +13 -0
- package/dist/ts/src/lib/routing-config.js.map +1 -0
- package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/serialize-props.js +1 -0
- package/dist/ts/src/lib/serialize-props.js.map +1 -0
- package/dist/ts/src/lib/unknown-components.d.ts +21 -0
- package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
- package/dist/ts/src/lib/unknown-components.js +49 -0
- package/dist/ts/src/lib/unknown-components.js.map +1 -0
- package/dist/{src → ts/src}/lib/virtual-module-generators.d.ts +0 -24
- package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.js +51 -0
- package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
- package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
- package/dist/{src → ts/src}/lib/withHydration.js +1 -0
- package/dist/ts/src/lib/withHydration.js.map +1 -0
- package/dist/ts/src/loader.d.ts +27 -0
- package/dist/ts/src/loader.d.ts.map +1 -0
- package/dist/{src → ts/src}/loader.js +33 -4
- package/dist/ts/src/loader.js.map +1 -0
- package/dist/ts/src/locales-helpers.d.ts.map +1 -0
- package/dist/{src → ts/src}/locales-helpers.js +1 -0
- package/dist/ts/src/locales-helpers.js.map +1 -0
- package/dist/ts/src/mime-types.d.ts.map +1 -0
- package/dist/{src → ts/src}/mime-types.js +1 -0
- package/dist/ts/src/mime-types.js.map +1 -0
- package/dist/ts/src/page-feed.d.ts +13 -0
- package/dist/ts/src/page-feed.d.ts.map +1 -0
- package/dist/ts/src/page-feed.js +20 -0
- package/dist/ts/src/page-feed.js.map +1 -0
- package/dist/ts/src/page-schemas.d.ts +6 -0
- package/dist/ts/src/page-schemas.d.ts.map +1 -0
- package/dist/ts/src/page-schemas.js +6 -0
- package/dist/ts/src/page-schemas.js.map +1 -0
- package/dist/ts/src/path-validation.d.ts.map +1 -0
- package/dist/{src → ts/src}/path-validation.js +1 -0
- package/dist/ts/src/path-validation.js.map +1 -0
- package/dist/{src → ts/src}/plugin-spa.d.ts +28 -10
- package/dist/ts/src/plugin-spa.d.ts.map +1 -0
- package/dist/{src → ts/src}/plugin-spa.js +301 -88
- package/dist/ts/src/plugin-spa.js.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.js +422 -0
- package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
- package/dist/ts/src/puck-manifest/index.d.ts +4 -0
- package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/index.js +3 -0
- package/dist/ts/src/puck-manifest/index.js.map +1 -0
- package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
- package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/literal.js +354 -0
- package/dist/ts/src/puck-manifest/literal.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.js +517 -0
- package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.js +11 -0
- package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
- package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.js +424 -0
- package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.js +79 -0
- package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
- package/dist/ts/src/puck-manifest/types.d.ts +145 -0
- package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/types.js +2 -0
- package/dist/ts/src/puck-manifest/types.js.map +1 -0
- package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
- package/dist/{src → ts/src}/safe-json-stringify.js +1 -0
- package/dist/ts/src/safe-json-stringify.js.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.js +27 -0
- package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
- package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.d.ts +2 -5
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.js +5 -8
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
- package/dist/{src → ts/src}/site-styles/render-endpoint.d.ts +4 -9
- package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/render-endpoint.js +1 -0
- package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
- package/dist/{src → ts/src}/site-styles/styles-endpoint.d.ts +2 -4
- package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/{src → ts/src}/site-styles/styles-endpoint.js +3 -5
- package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
- package/dist/ts/src/sitemap-options.d.ts +21 -0
- package/dist/ts/src/sitemap-options.d.ts.map +1 -0
- package/dist/ts/src/sitemap-options.js +92 -0
- package/dist/ts/src/sitemap-options.js.map +1 -0
- package/dist/ts/src/tiptap-html-static.d.ts +16 -0
- package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
- package/dist/ts/src/tiptap-html-static.js +117 -0
- package/dist/ts/src/tiptap-html-static.js.map +1 -0
- package/dist/{src → ts/src}/types.d.ts +26 -110
- package/dist/ts/src/types.d.ts.map +1 -0
- package/dist/ts/src/types.js +2 -0
- package/dist/ts/src/types.js.map +1 -0
- package/dist/virtual-modules.d.ts +12 -93
- package/node/content.ts +14 -0
- package/node/index.ts +22 -0
- package/package.json +161 -73
- package/src/asset-ref-base.ts +48 -0
- package/src/checks.ts +11 -0
- package/src/cms-handler.ts +281 -0
- package/src/collections.ts +271 -0
- package/src/components/HydrationWrapper.tsx +41 -0
- package/src/components/RenderWithFragments.tsx +204 -0
- package/src/components/RenderWithHydration.tsx +55 -0
- package/src/components.ts +3 -0
- package/src/discovery/astro-frontmatter.ts +24 -0
- package/src/discovery/discover.ts +108 -0
- package/src/discovery/extract-props-ts.ts +255 -0
- package/src/discovery/merge-registry.ts +411 -0
- package/src/discovery/registry-endpoint.ts +80 -0
- package/src/discovery/scan-components.ts +458 -0
- package/src/discovery/scan-mdx.ts +190 -0
- package/src/discovery/scan-overrides.ts +92 -0
- package/src/editor-descriptors.ts +96 -0
- package/src/env.d.ts +31 -0
- package/src/handlers/collection-content-api.ts +196 -0
- package/src/handlers/page-handler.astro +320 -0
- package/src/handlers/page-render-core.ts +456 -0
- package/src/hydration.ts +7 -0
- package/src/index.ts +111 -0
- package/src/internal/acorn-default.mjs +37 -0
- package/src/internal/declared-collections.ts +98 -0
- package/src/internal/page-collection-schema.ts +210 -0
- package/src/lib/content-config-guard.ts +53 -0
- package/src/lib/hydration-scanner.ts +176 -0
- package/src/lib/hydration-script.ts +126 -0
- package/src/lib/hydration-utils.ts +120 -0
- package/src/lib/resolve-locale.ts +22 -0
- package/src/lib/resolve-site-name.ts +10 -0
- package/src/lib/route-utils.ts +106 -0
- package/src/lib/routing-config.ts +126 -0
- package/src/lib/serialize-props.ts +7 -0
- package/src/lib/unknown-components.ts +64 -0
- package/src/lib/virtual-module-generators.ts +58 -0
- package/{dist/withHydration-DkKpkmzJ.d.mts → src/lib/withHydration.ts} +25 -8
- package/src/loader.ts +145 -0
- package/{dist/locales-helpers-BvYYqnJ5.d.mts → src/locales-helpers.ts} +21 -17
- package/src/mime-types.ts +19 -0
- package/src/page-feed.ts +26 -0
- package/src/page-schemas.ts +19 -0
- package/src/path-validation.ts +13 -0
- package/src/plugin-spa.ts +1496 -0
- package/src/puck-manifest/components-endpoint.ts +55 -0
- package/src/puck-manifest/field-projection.ts +510 -0
- package/src/puck-manifest/index.ts +3 -0
- package/src/puck-manifest/literal.ts +459 -0
- package/src/puck-manifest/read-config.ts +577 -0
- package/src/puck-manifest/read-field.ts +19 -0
- package/src/puck-manifest/read-wrapper.ts +1056 -0
- package/src/puck-manifest/reading-budget.ts +127 -0
- package/src/puck-manifest/resolve-reference.ts +9 -0
- package/src/puck-manifest/source-reference.ts +484 -0
- package/src/puck-manifest/syntax.ts +104 -0
- package/src/puck-manifest/types.ts +139 -0
- package/src/safe-json-stringify.ts +17 -0
- package/src/sandbox-frame-handler.ts +31 -0
- package/src/site-styles/content-wrapper-endpoint.ts +327 -0
- package/src/site-styles/render-endpoint.ts +331 -0
- package/src/site-styles/styles-endpoint.ts +184 -0
- package/src/sitemap-options.ts +115 -0
- package/src/tiptap-html-static.ts +134 -0
- package/{dist/types-CS9neadI.d.mts → src/types.ts} +87 -124
- package/src/virtual-modules.d.ts +74 -0
- package/dist/collections-Bd7EME4b.mjs +0 -129
- package/dist/collections-Bd7EME4b.mjs.map +0 -1
- package/dist/collections.d.mts +0 -35
- package/dist/collections.d.mts.map +0 -1
- package/dist/collections.mjs +0 -2
- package/dist/components.d.mts +0 -41
- package/dist/components.d.mts.map +0 -1
- package/dist/components.mjs +0 -223
- package/dist/components.mjs.map +0 -1
- package/dist/hydration.d.mts +0 -4
- package/dist/hydration.mjs +0 -2
- package/dist/index.d.mts +0 -108
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -67
- package/dist/index.mjs.map +0 -1
- package/dist/internal/cms-handler.d.mts +0 -25
- package/dist/internal/cms-handler.d.mts.map +0 -1
- package/dist/internal/cms-handler.mjs +0 -314
- package/dist/internal/cms-handler.mjs.map +0 -1
- package/dist/lib/hydration-script.d.mts +0 -30
- package/dist/lib/hydration-script.d.mts.map +0 -1
- package/dist/lib/hydration-script.mjs +0 -84
- package/dist/lib/hydration-script.mjs.map +0 -1
- package/dist/locales-helpers-BvYYqnJ5.d.mts.map +0 -1
- package/dist/locales-helpers-qiwh7nxS.mjs +0 -54
- package/dist/locales-helpers-qiwh7nxS.mjs.map +0 -1
- package/dist/node/content.d.mts +0 -18
- package/dist/node/content.d.mts.map +0 -1
- package/dist/node/content.d.ts +0 -3
- package/dist/node/content.d.ts.map +0 -1
- package/dist/node/content.js +0 -2
- package/dist/node/content.mjs +0 -2
- package/dist/node/index.d.mts +0 -200
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.d.ts +0 -4
- package/dist/node/index.d.ts.map +0 -1
- package/dist/node/index.js +0 -3
- package/dist/node/index.mjs +0 -2513
- package/dist/node/index.mjs.map +0 -1
- package/dist/serialize-props-BHoNpzH6.mjs +0 -72
- package/dist/serialize-props-BHoNpzH6.mjs.map +0 -1
- package/dist/src/cms-handler.d.ts.map +0 -1
- package/dist/src/collections.d.ts +0 -32
- package/dist/src/collections.d.ts.map +0 -1
- package/dist/src/collections.js +0 -50
- package/dist/src/components/HydrationWrapper.d.ts.map +0 -1
- package/dist/src/components/RenderWithBlocks.d.ts.map +0 -1
- package/dist/src/components/RenderWithBlocks.js +0 -129
- package/dist/src/components/RenderWithHydration.d.ts.map +0 -1
- package/dist/src/components.d.ts +0 -4
- package/dist/src/components.d.ts.map +0 -1
- package/dist/src/components.js +0 -3
- package/dist/src/discovery/astro-frontmatter.d.ts.map +0 -1
- package/dist/src/discovery/extract-props-ts.d.ts.map +0 -1
- package/dist/src/discovery/merge-registry.d.ts.map +0 -1
- package/dist/src/discovery/registry-endpoint.d.ts +0 -42
- package/dist/src/discovery/registry-endpoint.d.ts.map +0 -1
- package/dist/src/discovery/registry-endpoint.js +0 -81
- package/dist/src/discovery/scan-components.d.ts.map +0 -1
- package/dist/src/discovery/scan-mdx.d.ts.map +0 -1
- package/dist/src/discovery/scan-overrides.d.ts.map +0 -1
- package/dist/src/hydration.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -11
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -25
- package/dist/src/lib/hydration-scanner.d.ts.map +0 -1
- package/dist/src/lib/hydration-script.d.ts.map +0 -1
- package/dist/src/lib/hydration-utils.d.ts.map +0 -1
- package/dist/src/lib/page-api.d.ts +0 -77
- package/dist/src/lib/page-api.d.ts.map +0 -1
- package/dist/src/lib/page-api.js +0 -121
- package/dist/src/lib/route-utils.d.ts.map +0 -1
- package/dist/src/lib/routing-config.d.ts.map +0 -1
- package/dist/src/lib/serialize-props.d.ts.map +0 -1
- package/dist/src/lib/virtual-module-generators.d.ts.map +0 -1
- package/dist/src/lib/virtual-module-generators.js +0 -263
- package/dist/src/lib/withHydration.d.ts.map +0 -1
- package/dist/src/loader.d.ts +0 -14
- package/dist/src/loader.d.ts.map +0 -1
- package/dist/src/locales-helpers.d.ts.map +0 -1
- package/dist/src/mime-types.d.ts.map +0 -1
- package/dist/src/path-validation.d.ts.map +0 -1
- package/dist/src/plugin-spa.d.ts.map +0 -1
- package/dist/src/safe-json-stringify.d.ts.map +0 -1
- package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +0 -1
- package/dist/src/site-styles/render-endpoint.d.ts.map +0 -1
- package/dist/src/site-styles/styles-endpoint.d.ts.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -1
- package/dist/types-CS9neadI.d.mts.map +0 -1
- package/dist/withHydration-C256ox_6.mjs +0 -49
- package/dist/withHydration-C256ox_6.mjs.map +0 -1
- package/dist/withHydration-DkKpkmzJ.d.mts.map +0 -1
- /package/dist/{src → ts/src}/discovery/astro-frontmatter.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/extract-props-ts.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/scan-mdx.d.ts +0 -0
- /package/dist/{src → ts/src}/discovery/scan-overrides.d.ts +0 -0
- /package/dist/{src → ts/src}/hydration.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-scanner.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-script.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/hydration-utils.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/serialize-props.d.ts +0 -0
- /package/dist/{src → ts/src}/lib/withHydration.d.ts +0 -0
- /package/dist/{src → ts/src}/locales-helpers.d.ts +0 -0
- /package/dist/{src → ts/src}/mime-types.d.ts +0 -0
- /package/dist/{src → ts/src}/path-validation.d.ts +0 -0
- /package/dist/{src → ts/src}/safe-json-stringify.d.ts +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createContentAPI } from '@conloca/content-api/reader';
|
|
2
|
+
import type { Loader, LoaderContext } from 'astro/loaders';
|
|
3
|
+
|
|
4
|
+
// Both registries are per-process, not per-config-evaluation: a dev-server
|
|
5
|
+
// config reload re-runs content.config without clearing them. So a collection
|
|
6
|
+
// dropped from the config stays declared, and a passing check is not repeated
|
|
7
|
+
// for a directory that appears later — not until the server restarts. Both are
|
|
8
|
+
// deliberately open: a stale registry can only miss a complaint, never invent
|
|
9
|
+
// one. Only successful checks are memoised, so a failing one is retried on the
|
|
10
|
+
// next load and a leftover can never keep failing a build the user has since
|
|
11
|
+
// fixed in content.config.ts.
|
|
12
|
+
const declared = new Set<string>();
|
|
13
|
+
const checks = new Map<string, Promise<void>>();
|
|
14
|
+
|
|
15
|
+
export type ConlocaCollectionKind = 'page' | 'data' | 'fragment';
|
|
16
|
+
|
|
17
|
+
/** Registry entries carry their kind: a data collection `general` must not cover an undeclared fragment FOLDER `general`. */
|
|
18
|
+
export type QualifiedCollectionName = `${ConlocaCollectionKind}:${string}`;
|
|
19
|
+
|
|
20
|
+
const qualifiedName = (kind: ConlocaCollectionKind, name: string): QualifiedCollectionName => `${kind}:${name}`;
|
|
21
|
+
|
|
22
|
+
/** 'data:faqs' → 'the data collection "faqs"' — the registry key is internal, the error is for a human. */
|
|
23
|
+
function describeQualified(qualified: QualifiedCollectionName): string {
|
|
24
|
+
const separator = qualified.indexOf(':');
|
|
25
|
+
return `the ${qualified.slice(0, separator)} collection "${qualified.slice(separator + 1)}"`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Factories call this as content.config evaluates; the registry is complete before any loader runs. */
|
|
29
|
+
export function declareConlocaCollection(kind: ConlocaCollectionKind, name: string): void {
|
|
30
|
+
declared.add(qualifiedName(kind, name));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Test hook — the registry is module state shared across a config evaluation. */
|
|
34
|
+
export function resetDeclaredCollections(): void {
|
|
35
|
+
declared.clear();
|
|
36
|
+
checks.clear();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Every Conloca collection on disk must be declared in content.config, or its
|
|
41
|
+
* entries silently never build. The reverse — declared with no directory yet —
|
|
42
|
+
* is the schema-first workflow (the directory appears with the first saved
|
|
43
|
+
* entry) and is allowed.
|
|
44
|
+
*/
|
|
45
|
+
export function assertCollectionsDeclared(onDisk: Iterable<QualifiedCollectionName>): void {
|
|
46
|
+
// A qualified name repeats only when one iterable carries duplicates —
|
|
47
|
+
// dedupe so nothing is ever reported twice.
|
|
48
|
+
const undeclared = [...new Set(onDisk)].filter((name) => !declared.has(name));
|
|
49
|
+
if (undeclared.length === 0) return;
|
|
50
|
+
throw new Error(
|
|
51
|
+
`[conloca] content on disk has collections that content.config.ts does not declare: ${undeclared
|
|
52
|
+
.map(describeQualified)
|
|
53
|
+
.join(', ')}. Declare each one (conlocaPages / conlocaData / conlocaFragments) or its entries will not be built.`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Enumerates every collection kind on disk and checks the registry covers them. */
|
|
58
|
+
async function assertDiskDeclared(options: { contentRoot: string; site: string }): Promise<void> {
|
|
59
|
+
const api = await createContentAPI({ contentRoot: options.contentRoot });
|
|
60
|
+
assertCollectionsDeclared([
|
|
61
|
+
...[...(api.getSite(options.site)?.collections ?? [])].map((name) => qualifiedName('page', name)),
|
|
62
|
+
...[...api.data.collections].map((name) => qualifiedName('data', name)),
|
|
63
|
+
...[...api.fragments.collections].map((name) => qualifiedName('fragment', name)),
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Wraps a factory-created loader so a config evaluation checks the disk once
|
|
69
|
+
* per content root and site. createConlocaCollections' loaders are not wrapped
|
|
70
|
+
* — its contract IS discovery.
|
|
71
|
+
*
|
|
72
|
+
* Astro runs every loader concurrently through one Promise.all, so the check is
|
|
73
|
+
* memoised as a promise rather than a done-flag: one scan per root and site,
|
|
74
|
+
* and every loader awaits the same result instead of racing past a check still
|
|
75
|
+
* running.
|
|
76
|
+
*/
|
|
77
|
+
export function withDeclarationCheck(loader: Loader, options: { contentRoot: string; site: string }): Loader {
|
|
78
|
+
return {
|
|
79
|
+
...loader,
|
|
80
|
+
async load(context: LoaderContext): Promise<void> {
|
|
81
|
+
// NUL separates the two halves — a space collides with paths containing spaces.
|
|
82
|
+
const key = `${options.contentRoot}\0${options.site}`;
|
|
83
|
+
let check = checks.get(key);
|
|
84
|
+
if (!check) {
|
|
85
|
+
check = assertDiskDeclared(options).catch((error: unknown) => {
|
|
86
|
+
// Only a successful check is memoised: module state outlives a
|
|
87
|
+
// dev-server config reload, so a cached rejection would keep failing
|
|
88
|
+
// after the user has declared the collection it asked for.
|
|
89
|
+
checks.delete(key);
|
|
90
|
+
throw error;
|
|
91
|
+
});
|
|
92
|
+
checks.set(key, check);
|
|
93
|
+
}
|
|
94
|
+
await check;
|
|
95
|
+
return loader.load(context);
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { type PageSchemas, toPageSchemaDescriptor } from '@conloca/cms-spa/page-schema-define';
|
|
2
|
+
import type { ContentMeta } from '@conloca/content-api';
|
|
3
|
+
import { type PageMeta, pageMetaSchema } from '@conloca/content-api/schemas';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { LOADER_RESERVED_FIELDS } from '../loader.js';
|
|
6
|
+
|
|
7
|
+
const CORE_FIELD_NAMES = new Set(Object.keys(pageMetaSchema.shape));
|
|
8
|
+
const RESERVED_FIELD_NAMES = new Set<string>(LOADER_RESERVED_FIELDS);
|
|
9
|
+
|
|
10
|
+
type RewriteKind = 'default' | 'catch' | 'transform' | 'coerce';
|
|
11
|
+
|
|
12
|
+
type ZodDef = {
|
|
13
|
+
type?: string;
|
|
14
|
+
coerce?: boolean;
|
|
15
|
+
innerType?: z.ZodType;
|
|
16
|
+
in?: z.ZodType;
|
|
17
|
+
shape?: Record<string, z.ZodType> | (() => Record<string, z.ZodType>);
|
|
18
|
+
element?: z.ZodType;
|
|
19
|
+
options?: z.ZodType[];
|
|
20
|
+
items?: z.ZodType[];
|
|
21
|
+
valueType?: z.ZodType;
|
|
22
|
+
keyType?: z.ZodType;
|
|
23
|
+
rest?: z.ZodType;
|
|
24
|
+
left?: z.ZodType;
|
|
25
|
+
right?: z.ZodType;
|
|
26
|
+
getter?: () => z.ZodType;
|
|
27
|
+
catchall?: z.ZodType;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `seen` breaks cycles through shared schema instances, but a z.lazy whose
|
|
32
|
+
* factory builds fresh instances on every call defeats it — the depth cap is
|
|
33
|
+
* the backstop. No real page-meta schema nests this deep.
|
|
34
|
+
*/
|
|
35
|
+
const MAX_REWRITE_WALK_DEPTH = 32;
|
|
36
|
+
|
|
37
|
+
function findRewrite(
|
|
38
|
+
schema: z.ZodType,
|
|
39
|
+
path: string,
|
|
40
|
+
seen: Set<z.ZodType>,
|
|
41
|
+
depth = 0,
|
|
42
|
+
): { kind: RewriteKind; path: string } | null {
|
|
43
|
+
if (seen.has(schema) || depth > MAX_REWRITE_WALK_DEPTH) return null;
|
|
44
|
+
seen.add(schema);
|
|
45
|
+
const def = schema.def as ZodDef;
|
|
46
|
+
if (def.type === 'default') return { kind: 'default', path };
|
|
47
|
+
if (def.type === 'catch') return { kind: 'catch', path };
|
|
48
|
+
if (def.type === 'pipe') return { kind: 'transform', path };
|
|
49
|
+
if (def.coerce) return { kind: 'coerce', path };
|
|
50
|
+
|
|
51
|
+
// Every child schema paired with the path it is reported under, in the
|
|
52
|
+
// order the walk visits them — the first rewrite found is the one named
|
|
53
|
+
// in the error, so this order is part of the contract.
|
|
54
|
+
const shape = typeof def.shape === 'function' ? def.shape() : def.shape;
|
|
55
|
+
const children: [z.ZodType | undefined, string][] = [[def.innerType ?? def.in, path]];
|
|
56
|
+
for (const [key, child] of Object.entries(shape ?? {})) {
|
|
57
|
+
children.push([child, path ? `${path}.${key}` : key]);
|
|
58
|
+
}
|
|
59
|
+
children.push([def.element, `${path}[]`]);
|
|
60
|
+
for (const option of def.options ?? []) {
|
|
61
|
+
children.push([option, path]);
|
|
62
|
+
}
|
|
63
|
+
for (const [index, item] of (def.items ?? []).entries()) {
|
|
64
|
+
children.push([item, `${path}[${index}]`]);
|
|
65
|
+
}
|
|
66
|
+
children.push(
|
|
67
|
+
[def.rest, `${path}[]`],
|
|
68
|
+
[def.keyType, path],
|
|
69
|
+
[def.valueType, path],
|
|
70
|
+
[def.left, path],
|
|
71
|
+
[def.right, path],
|
|
72
|
+
[def.getter?.(), path],
|
|
73
|
+
[def.catchall, `${path}[*]`],
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
for (const [child, childPath] of children) {
|
|
77
|
+
if (!child) continue;
|
|
78
|
+
const found = findRewrite(child, childPath, seen, depth + 1);
|
|
79
|
+
if (found) return found;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function assertHostFieldsAreSafe(shape: z.ZodRawShape): void {
|
|
85
|
+
for (const [name, schema] of Object.entries(shape)) {
|
|
86
|
+
if (CORE_FIELD_NAMES.has(name)) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`[conloca] pageSchemas cannot redeclare Conloca field "${name}". ` +
|
|
89
|
+
'Title, pathname, locale, and the other core fields come from the CMS — put constraints on them in the editor schema, not here.',
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (RESERVED_FIELD_NAMES.has(name)) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`[conloca] pageSchemas cannot declare "${name}". ` +
|
|
95
|
+
'That field is owned by the content loader; a host schema of the same name would replace page content on every page.',
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
const rewrite = findRewrite(schema as z.ZodType, name, new Set());
|
|
99
|
+
if (rewrite) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`[conloca] pageSchemas field "${rewrite.path}" uses .${rewrite.kind}(), which rewrites values when Astro validates the collection ` +
|
|
102
|
+
'and does not run in the editor preview. Use a plain field (optional string, array, …) and parse in one reader instead.',
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Fold every page-schema descriptor into one Zod object of host meta fields.
|
|
110
|
+
* Requiredness is not preserved — the caller always `.partial()`s this for the
|
|
111
|
+
* collection, because Astro validates the whole `pages` pile.
|
|
112
|
+
*
|
|
113
|
+
* The merged object has one slot per field name, so two descriptors may only
|
|
114
|
+
* declare the same name by sharing the same field schema instance — last-wins
|
|
115
|
+
* would silently rewrite what the earlier prefix's pages are validated
|
|
116
|
+
* against, failing them with a Zod error that names neither descriptor.
|
|
117
|
+
*/
|
|
118
|
+
export function hostFieldsFromPageSchemas(pageSchemas: PageSchemas): z.ZodObject<z.ZodRawShape> {
|
|
119
|
+
// z.ZodRawShape's index signature is readonly, so the accumulator is spelled
|
|
120
|
+
// with a mutable one.
|
|
121
|
+
const shape: Record<string, z.ZodRawShape[string]> = {};
|
|
122
|
+
const fieldOwner = new Map<string, string>();
|
|
123
|
+
for (const [key, entry] of Object.entries(pageSchemas)) {
|
|
124
|
+
const descriptor = toPageSchemaDescriptor(entry);
|
|
125
|
+
// Rebuilding from .shape below silently drops object-level refinements,
|
|
126
|
+
// so the refusal written for them has to run here, on the public path.
|
|
127
|
+
assertNoObjectRefinements(descriptor.schema);
|
|
128
|
+
// 'minimal'/'none' descriptors declare title for the form; strip those names so the collection guard does not fire.
|
|
129
|
+
const mode = descriptor.coreFields?.mode;
|
|
130
|
+
const stripCore = mode === 'minimal' || mode === 'none';
|
|
131
|
+
for (const [name, field] of Object.entries(descriptor.schema.shape)) {
|
|
132
|
+
if (stripCore && CORE_FIELD_NAMES.has(name)) continue;
|
|
133
|
+
const owner = fieldOwner.get(name);
|
|
134
|
+
if (owner !== undefined && shape[name] !== field) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`[conloca] pageSchemas "${owner}" and "${key}" both declare field "${name}" with different schemas. ` +
|
|
137
|
+
'The merged collection schema has one slot per field name — declare the field once and import it ' +
|
|
138
|
+
'into both schemas, or rename one of the fields.',
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
fieldOwner.set(name, owner ?? key);
|
|
142
|
+
shape[name] = field;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return z.object(shape);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A page collection entry as the loader delivers it: the validated
|
|
150
|
+
* `pageMetaSchema` fields, the loader-written record fields (`created`,
|
|
151
|
+
* `modified`, `name`, `puckData` — admitted by the loose index at runtime),
|
|
152
|
+
* and the host's meta fields through `ContentMeta`/`HostPageMeta`.
|
|
153
|
+
*/
|
|
154
|
+
export type ConlocaPageEntry = ContentMeta &
|
|
155
|
+
PageMeta & {
|
|
156
|
+
created?: string | Date;
|
|
157
|
+
modified?: string | Date;
|
|
158
|
+
name?: string;
|
|
159
|
+
puckData?: unknown;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The schema Astro validates page entries against: the host's page-meta fields
|
|
164
|
+
* (all optional) with conloca's structural fields layered over them, loose so
|
|
165
|
+
* undeclared top-level fields still reach the rendered page.
|
|
166
|
+
*
|
|
167
|
+
* Looseness is TOP-LEVEL ONLY. A nested `z.object()` still strips undeclared
|
|
168
|
+
* nested keys; a host that wants them preserved has to write `z.looseObject()`.
|
|
169
|
+
*
|
|
170
|
+
* Rewrite bans (.default / .coerce / .transform / .catch) walk nested objects,
|
|
171
|
+
* arrays, and unions. `.partial()` is still shallow.
|
|
172
|
+
*
|
|
173
|
+
* Internal on purpose: `src/collections.ts` is a published entry (the
|
|
174
|
+
* `./collections` subpath), so anything exported from there is frozen under
|
|
175
|
+
* semver. Nothing outside this package consumes it.
|
|
176
|
+
*/
|
|
177
|
+
export function buildPageCollectionSchema(hostFields: z.ZodObject<z.ZodRawShape>): z.ZodType<ConlocaPageEntry> {
|
|
178
|
+
assertNoObjectRefinements(hostFields);
|
|
179
|
+
assertHostFieldsAreSafe(hostFields.shape);
|
|
180
|
+
// The one declared seam in the typed-collections design: the runtime
|
|
181
|
+
// schema validates core + host fields and loosely admits the loader-written
|
|
182
|
+
// record fields, but TypeScript cannot see host fields through the loose
|
|
183
|
+
// index. The static type is asserted as the flattened entry instead, which
|
|
184
|
+
// is the same contract listings already rely on — a host declaring
|
|
185
|
+
// `HostPageMeta` promises it matches its `pageSchemas`. Pinned by the type
|
|
186
|
+
// proofs here and in the type proofs of a site that declares `HostPageMeta`.
|
|
187
|
+
return z.looseObject({
|
|
188
|
+
...hostFields.partial().shape,
|
|
189
|
+
...pageMetaSchema.shape,
|
|
190
|
+
}) as unknown as z.ZodType<ConlocaPageEntry>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* .partial() throws on a refined object, and a refined object still satisfies
|
|
195
|
+
* both the host-fields signature and the pageSchemas field type, so the raw
|
|
196
|
+
* zod error would surface while Astro loads content.config.ts naming neither
|
|
197
|
+
* conloca nor pageSchemas. Refuse it with something the host can act on —
|
|
198
|
+
* both on the fold over pageSchemas (which would otherwise silently DROP the
|
|
199
|
+
* refinement while rebuilding from .shape) and on direct host-fields callers.
|
|
200
|
+
*/
|
|
201
|
+
function assertNoObjectRefinements(schema: z.ZodObject<z.ZodRawShape>): void {
|
|
202
|
+
if ((schema.def.checks?.length ?? 0) > 0) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
'[conloca] pageSchemas cannot carry object-level refinements (.refine, .superRefine or .check). ' +
|
|
205
|
+
'Conloca makes every host field optional — page schemas are prefix-scoped in the editor while ' +
|
|
206
|
+
'Astro validates a whole collection — and Zod cannot make a refined object partial. ' +
|
|
207
|
+
'Move the rule onto the individual field schemas instead.',
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/** Where Astro looks for a content config, newest location first. */
|
|
5
|
+
const CONTENT_CONFIG_CANDIDATES = [
|
|
6
|
+
'src/content.config.ts',
|
|
7
|
+
'src/content.config.mts',
|
|
8
|
+
'src/content.config.mjs',
|
|
9
|
+
'src/content.config.js',
|
|
10
|
+
'src/content/config.ts',
|
|
11
|
+
'src/content/config.mjs',
|
|
12
|
+
'src/content/config.js',
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export type ContentConfigProblem = 'missing' | 'not-wired';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Any of these in the config means Conloca's collections get registered —
|
|
19
|
+
* the factories, the deprecated wrapper, or a hand-rolled
|
|
20
|
+
* `defineCollection({ loader: conlocaLoader(...) })` (a supported shape;
|
|
21
|
+
* the loader carries its own mounted-key guard).
|
|
22
|
+
*/
|
|
23
|
+
const WIRED_MARKERS = ['createConlocaCollections', 'conlocaPages', 'conlocaData', 'conlocaFragments', 'conlocaLoader'];
|
|
24
|
+
|
|
25
|
+
/** The content config file Astro loads for a project, or null when it has none. */
|
|
26
|
+
export function findContentConfig(projectRoot: string): string | null {
|
|
27
|
+
return (
|
|
28
|
+
CONTENT_CONFIG_CANDIDATES.map((candidate) => join(projectRoot, candidate)).find((path) => existsSync(path)) ?? null
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Detect the single most common Conloca misconfiguration: a project whose
|
|
34
|
+
* content config never registers Conloca's collections, so every page 404s
|
|
35
|
+
* with no other symptom. Astro exposes no hook that reveals resolved
|
|
36
|
+
* collections, so this reads the file instead.
|
|
37
|
+
*/
|
|
38
|
+
export function findContentConfigProblem(projectRoot: string): ContentConfigProblem | null {
|
|
39
|
+
const found = findContentConfig(projectRoot);
|
|
40
|
+
if (!found) return 'missing';
|
|
41
|
+
|
|
42
|
+
const source = readFileSync(found, 'utf8');
|
|
43
|
+
return WIRED_MARKERS.some((marker) => source.includes(marker)) ? null : 'not-wired';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The copy-pasteable fix printed with either problem. */
|
|
47
|
+
export const CONTENT_CONFIG_SNIPPET = `// src/content.config.ts
|
|
48
|
+
import { conlocaFragments, conlocaPages } from '@conloca/astro-cms/node/content';
|
|
49
|
+
|
|
50
|
+
export const collections = {
|
|
51
|
+
pages: conlocaPages(),
|
|
52
|
+
...conlocaFragments(),
|
|
53
|
+
};`;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
3
|
+
import fg from 'fast-glob';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Result of scanning a component file for withHydration usage.
|
|
7
|
+
*/
|
|
8
|
+
export interface HydrationDiscovery {
|
|
9
|
+
/** Component name derived from filename (PascalCase) */
|
|
10
|
+
componentName: string;
|
|
11
|
+
/** Absolute path to the component file */
|
|
12
|
+
filePath: string;
|
|
13
|
+
/** Hydration strategy extracted from withHydration call */
|
|
14
|
+
strategy: 'load' | 'visible' | 'idle';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Regex to check if file imports withHydration from @conloca/astro-cms or @conloca/astro-cms/hydration
|
|
18
|
+
// This is faster than es-module-lexer for JSX files and avoids parse errors
|
|
19
|
+
export const HYDRATION_IMPORT_PATTERN =
|
|
20
|
+
/import\s+\{[^}]*withHydration[^}]*\}\s+from\s+['"]@conloca\/astro-cms(?:\/hydration)?['"]/;
|
|
21
|
+
|
|
22
|
+
// Regex to find withHydration calls and extract strategy
|
|
23
|
+
// Matches: withHydration(ComponentName, 'strategy') or withHydration(ComponentName, "strategy")
|
|
24
|
+
export const HYDRATION_PATTERN = /withHydration\s*\(\s*\w+\s*,\s*['"](\w+)['"]\s*\)/g;
|
|
25
|
+
|
|
26
|
+
// Valid hydration strategies
|
|
27
|
+
const VALID_STRATEGIES = new Set(['load', 'visible', 'idle']);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Derives component scan paths from puckConfigPath.
|
|
31
|
+
*
|
|
32
|
+
* Convention: puckConfigPath directory + '/components/puck'
|
|
33
|
+
* Example: './src/puck.config.tsx' -> './src/components/puck'
|
|
34
|
+
*
|
|
35
|
+
* If explicitPaths provided, they extend (not replace) the auto-discovered path.
|
|
36
|
+
*
|
|
37
|
+
* @param puckConfigPath - Path to the puck config (e.g., './src/puck.config.tsx')
|
|
38
|
+
* @param explicitPaths - Optional additional paths to scan
|
|
39
|
+
* @returns Array of paths to scan for hydratable components
|
|
40
|
+
*/
|
|
41
|
+
export function deriveComponentPaths(puckConfigPath: string, explicitPaths?: string[]): string[] {
|
|
42
|
+
const puckDir = dirname(puckConfigPath);
|
|
43
|
+
const defaultScanPath = join(puckDir, 'components', 'puck');
|
|
44
|
+
|
|
45
|
+
if (explicitPaths && explicitPaths.length > 0) {
|
|
46
|
+
return [defaultScanPath, ...explicitPaths];
|
|
47
|
+
}
|
|
48
|
+
return [defaultScanPath];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Derives a PascalCase component name from a file path.
|
|
53
|
+
*
|
|
54
|
+
* @param filePath - Absolute path to the component file
|
|
55
|
+
* @returns Component name in PascalCase
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* deriveComponentName('/src/components/puck/TestimonialGrid.tsx')
|
|
59
|
+
* // => 'TestimonialGrid'
|
|
60
|
+
*
|
|
61
|
+
* deriveComponentName('/src/components/puck/blog-post-grid.tsx')
|
|
62
|
+
* // => 'BlogPostGrid'
|
|
63
|
+
*/
|
|
64
|
+
function deriveComponentName(filePath: string): string {
|
|
65
|
+
const filename = basename(filePath, extname(filePath));
|
|
66
|
+
// Convert kebab-case to PascalCase if needed
|
|
67
|
+
if (filename.includes('-')) {
|
|
68
|
+
return filename
|
|
69
|
+
.split('-')
|
|
70
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
71
|
+
.join('');
|
|
72
|
+
}
|
|
73
|
+
// Ensure first letter is uppercase
|
|
74
|
+
return filename.charAt(0).toUpperCase() + filename.slice(1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Scans component directories for files using withHydration wrapper.
|
|
79
|
+
*
|
|
80
|
+
* This function performs static analysis to discover components marked
|
|
81
|
+
* for hydration, without executing any component code.
|
|
82
|
+
*
|
|
83
|
+
* @param componentPaths - Relative paths to scan (e.g., ['src/components/puck'])
|
|
84
|
+
* @param projectRoot - Absolute path to the project root
|
|
85
|
+
* @returns Array of discovered hydratable components with their strategies
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const discoveries = await scanForHydratableComponents(
|
|
90
|
+
* ['src/components/puck'],
|
|
91
|
+
* '/path/to/project'
|
|
92
|
+
* )
|
|
93
|
+
* // => [{ componentName: 'TestimonialGrid', filePath: '...', strategy: 'visible' }]
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export async function scanForHydratableComponents(
|
|
97
|
+
componentPaths: string[],
|
|
98
|
+
projectRoot: string,
|
|
99
|
+
): Promise<HydrationDiscovery[]> {
|
|
100
|
+
const discoveries: HydrationDiscovery[] = [];
|
|
101
|
+
const seenNames = new Map<string, string>(); // componentName -> first filePath
|
|
102
|
+
|
|
103
|
+
for (const scanPath of componentPaths) {
|
|
104
|
+
const absolutePath = resolve(projectRoot, scanPath);
|
|
105
|
+
|
|
106
|
+
// Find all .tsx files in the directory and subdirectories
|
|
107
|
+
const files = await fg('**/*.tsx', {
|
|
108
|
+
cwd: absolutePath,
|
|
109
|
+
absolute: true,
|
|
110
|
+
onlyFiles: true,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
for (const filePath of files) {
|
|
114
|
+
try {
|
|
115
|
+
const content = await readFile(filePath, 'utf-8');
|
|
116
|
+
|
|
117
|
+
// Fast path: check if file imports withHydration from @conloca/astro-cms
|
|
118
|
+
// Using simple regex instead of es-module-lexer to avoid JSX parse errors
|
|
119
|
+
if (!HYDRATION_IMPORT_PATTERN.test(content)) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Find withHydration calls with regex
|
|
124
|
+
const matches = [...content.matchAll(HYDRATION_PATTERN)];
|
|
125
|
+
|
|
126
|
+
if (matches.length === 0) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (matches.length > 1) {
|
|
131
|
+
console.warn(
|
|
132
|
+
`[Conloca Hydration] Multiple withHydration calls in ${filePath}. ` +
|
|
133
|
+
'Consider splitting into separate component files. Using first call.',
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const match = matches[0];
|
|
138
|
+
const rawStrategy = match[1];
|
|
139
|
+
|
|
140
|
+
// Validate strategy
|
|
141
|
+
if (!VALID_STRATEGIES.has(rawStrategy)) {
|
|
142
|
+
console.warn(
|
|
143
|
+
`[Conloca Hydration] Invalid strategy '${rawStrategy}' in ${filePath}. ` +
|
|
144
|
+
`Valid options: ${[...VALID_STRATEGIES].join(', ')}. Skipping component.`,
|
|
145
|
+
);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const strategy = rawStrategy as 'load' | 'visible' | 'idle';
|
|
150
|
+
const componentName = deriveComponentName(filePath);
|
|
151
|
+
|
|
152
|
+
// Check for naming conflicts
|
|
153
|
+
const existingPath = seenNames.get(componentName);
|
|
154
|
+
if (existingPath) {
|
|
155
|
+
console.warn(
|
|
156
|
+
`[Conloca Hydration] Duplicate component name '${componentName}'. ` +
|
|
157
|
+
`Found in: ${existingPath} and ${filePath}. Using first occurrence.`,
|
|
158
|
+
);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
seenNames.set(componentName, filePath);
|
|
163
|
+
discoveries.push({
|
|
164
|
+
componentName,
|
|
165
|
+
filePath,
|
|
166
|
+
strategy,
|
|
167
|
+
});
|
|
168
|
+
} catch (err) {
|
|
169
|
+
// Log error but continue scanning other files
|
|
170
|
+
console.warn(`[Conloca Hydration] Error reading ${filePath}:`, err);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return discoveries;
|
|
176
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { hydrateRoot } from 'react-dom/client';
|
|
3
|
+
|
|
4
|
+
import type { HydrationStrategy } from '../types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Async loader that returns a React component.
|
|
8
|
+
* The registry generator handles extraction from ComponentConfig at build time.
|
|
9
|
+
*/
|
|
10
|
+
type ComponentLoader = () => Promise<React.ComponentType<unknown>>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Registry entry with loader and strategy.
|
|
14
|
+
* Generated by the scanner from withHydration metadata.
|
|
15
|
+
*/
|
|
16
|
+
interface ComponentRegistryEntry {
|
|
17
|
+
loader: ComponentLoader;
|
|
18
|
+
strategy: HydrationStrategy;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Registry mapping component names to their loaders and strategies.
|
|
23
|
+
* Generated by virtual:conloca-hydration-registry at build time.
|
|
24
|
+
*/
|
|
25
|
+
export type ComponentRegistry = Record<string, ComponentRegistryEntry>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Hydrate a single element with its corresponding React component.
|
|
29
|
+
*/
|
|
30
|
+
async function hydrateElement(element: HTMLElement, entry: ComponentRegistryEntry): Promise<void> {
|
|
31
|
+
const componentName = element.dataset.hydrate;
|
|
32
|
+
const propsJson = element.dataset.props || '{}';
|
|
33
|
+
|
|
34
|
+
if (!componentName) {
|
|
35
|
+
console.warn('[Conloca Hydration] Element missing data-hydrate attribute');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const props = JSON.parse(propsJson);
|
|
41
|
+
const Component = await entry.loader();
|
|
42
|
+
hydrateRoot(element, createElement(Component, props));
|
|
43
|
+
|
|
44
|
+
// Clean up data attributes after successful hydration
|
|
45
|
+
delete element.dataset.hydrate;
|
|
46
|
+
delete element.dataset.hydrateStrategy;
|
|
47
|
+
delete element.dataset.props;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(`[Conloca Hydration] Failed to hydrate ${componentName}:`, error);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Hydrate immediately on page load.
|
|
55
|
+
*/
|
|
56
|
+
function hydrateOnLoad(element: HTMLElement, entry: ComponentRegistryEntry): void {
|
|
57
|
+
hydrateElement(element, entry);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Hydrate when element becomes visible in viewport.
|
|
62
|
+
*/
|
|
63
|
+
function hydrateOnVisible(element: HTMLElement, entry: ComponentRegistryEntry): void {
|
|
64
|
+
const observer = new IntersectionObserver(
|
|
65
|
+
(entries, obs) => {
|
|
66
|
+
for (const ioEntry of entries) {
|
|
67
|
+
if (ioEntry.isIntersecting) {
|
|
68
|
+
obs.unobserve(ioEntry.target);
|
|
69
|
+
hydrateElement(ioEntry.target as HTMLElement, entry);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{ rootMargin: '50px' },
|
|
74
|
+
);
|
|
75
|
+
observer.observe(element);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Hydrate when browser is idle.
|
|
80
|
+
* Uses requestIdleCallback with setTimeout fallback for Safari.
|
|
81
|
+
*/
|
|
82
|
+
function hydrateOnIdle(element: HTMLElement, entry: ComponentRegistryEntry): void {
|
|
83
|
+
const scheduleIdle =
|
|
84
|
+
window.requestIdleCallback ??
|
|
85
|
+
((cb: IdleRequestCallback) => window.setTimeout(() => cb({ didTimeout: false, timeRemaining: () => 50 }), 1));
|
|
86
|
+
|
|
87
|
+
scheduleIdle(() => hydrateElement(element, entry), { timeout: 2000 });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Initialize hydration for all marked components on the page.
|
|
92
|
+
*
|
|
93
|
+
* Finds all elements with [data-hydrate] attribute and hydrates them
|
|
94
|
+
* according to their strategy from the registry.
|
|
95
|
+
*/
|
|
96
|
+
export function initHydration(registry: ComponentRegistry): void {
|
|
97
|
+
const elements = document.querySelectorAll<HTMLElement>('[data-hydrate]');
|
|
98
|
+
|
|
99
|
+
for (const element of elements) {
|
|
100
|
+
const componentName = element.dataset.hydrate;
|
|
101
|
+
if (!componentName) continue;
|
|
102
|
+
|
|
103
|
+
const entry = registry[componentName];
|
|
104
|
+
if (!entry) {
|
|
105
|
+
console.warn(`[Conloca Hydration] Unknown component: ${componentName}`);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Use strategy from registry (set at build time via withHydration)
|
|
110
|
+
const strategy = entry.strategy;
|
|
111
|
+
|
|
112
|
+
switch (strategy) {
|
|
113
|
+
case 'load':
|
|
114
|
+
hydrateOnLoad(element, entry);
|
|
115
|
+
break;
|
|
116
|
+
case 'visible':
|
|
117
|
+
hydrateOnVisible(element, entry);
|
|
118
|
+
break;
|
|
119
|
+
case 'idle':
|
|
120
|
+
hydrateOnIdle(element, entry);
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
hydrateOnLoad(element, entry);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|