@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,55 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import type { Connect } from 'vite';
|
|
4
|
+
import { componentsEndpointBody, type ReadPuckConfigOptions } from './read-config.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where the endpoint reads from: the config itself, and the host tsconfig that
|
|
8
|
+
* makes the config's imports resolve. Both are taken against the one project
|
|
9
|
+
* root, so a relative `puckConfigPath` and the tsconfig can never come from
|
|
10
|
+
* two different directories. A build that publishes the components reads
|
|
11
|
+
* through the same options, so what it publishes is what dev serves.
|
|
12
|
+
*
|
|
13
|
+
* The tsconfig is handed over only when it is really there. Naming a file that
|
|
14
|
+
* does not exist would silence the reader's own search for the nearest
|
|
15
|
+
* tsconfig above the config, and a project with no `jsx` option resolves an
|
|
16
|
+
* import of a `.tsx` file to nothing at all with no error — the site would
|
|
17
|
+
* read as every component unresolved and nothing would say why.
|
|
18
|
+
*/
|
|
19
|
+
export function endpointReaderOptions(paths: { puckConfigPath: string; projectRoot: string }): ReadPuckConfigOptions {
|
|
20
|
+
const hostTsConfig = join(paths.projectRoot, 'tsconfig.json');
|
|
21
|
+
return {
|
|
22
|
+
configPath: resolve(paths.projectRoot, paths.puckConfigPath),
|
|
23
|
+
...(existsSync(hostTsConfig) && { tsConfigFilePath: hostTsConfig }),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Vite middleware that returns the Puck component vocabulary as JSON: every
|
|
29
|
+
* component the config declares and what each accepts, read from source and
|
|
30
|
+
* never executed.
|
|
31
|
+
*
|
|
32
|
+
* The config is read per request — a few hundred milliseconds cold — so an
|
|
33
|
+
* edit to it shows up without a dev-server restart, the way the registry
|
|
34
|
+
* rescan does.
|
|
35
|
+
*/
|
|
36
|
+
export function createComponentsEndpoint(options: ReadPuckConfigOptions): Connect.NextHandleFunction {
|
|
37
|
+
return (_req, res, _next) => {
|
|
38
|
+
try {
|
|
39
|
+
const body = componentsEndpointBody(options);
|
|
40
|
+
res.statusCode = 200;
|
|
41
|
+
res.setHeader('content-type', 'application/json; charset=utf-8');
|
|
42
|
+
res.setHeader('cache-control', 'no-store');
|
|
43
|
+
res.end(body);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
// A config that cannot be read is answered with an empty manifest rather
|
|
46
|
+
// than an error, so anything arriving here is a fault in the reader
|
|
47
|
+
// itself and worth saying out loud.
|
|
48
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
49
|
+
console.warn('[conloca:puck-manifest] components endpoint failed:', message);
|
|
50
|
+
res.statusCode = 500;
|
|
51
|
+
res.setHeader('content-type', 'application/json; charset=utf-8');
|
|
52
|
+
res.end(JSON.stringify({ error: message }));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import { type CallExpression, type Node, type ObjectLiteralExpression, SyntaxKind } from 'ts-morph';
|
|
2
|
+
import {
|
|
3
|
+
inheritsNothing,
|
|
4
|
+
literalObjectReading,
|
|
5
|
+
type NamedMember,
|
|
6
|
+
namedMember,
|
|
7
|
+
propertyKey,
|
|
8
|
+
SPREADS_NOTHING,
|
|
9
|
+
setsPrototype,
|
|
10
|
+
spendWork,
|
|
11
|
+
type ValueReading,
|
|
12
|
+
writtenValue,
|
|
13
|
+
} from './literal.js';
|
|
14
|
+
import { resolveCallExpression, resolveLiteralValueReading, resolveObjectLiteral } from './resolve-reference.js';
|
|
15
|
+
import type { JsonValue, ManifestField } from './types.js';
|
|
16
|
+
|
|
17
|
+
/** Field types Puck cannot infer a shape for — they need an `ai.schema` to mean anything to an agent. */
|
|
18
|
+
const OPAQUE_TYPES = new Set(['custom', 'external']);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Every key of a field this reader takes a value from, apart from the `type`
|
|
22
|
+
* every field must have — the ones a spread can overwrite or drop.
|
|
23
|
+
*
|
|
24
|
+
* A Set rather than an array or an object: a plain object answers for
|
|
25
|
+
* `toString` as readily as for the keys written here, and a field carrying that
|
|
26
|
+
* name would be handed the prototype's value.
|
|
27
|
+
*/
|
|
28
|
+
type DroppableKey = Exclude<keyof ManifestField, 'type' | 'opaque' | 'unreadable'>;
|
|
29
|
+
const DROPPABLE_KEYS: ReadonlySet<string> = new Set<DroppableKey>([
|
|
30
|
+
'label',
|
|
31
|
+
'options',
|
|
32
|
+
'arrayFields',
|
|
33
|
+
'objectFields',
|
|
34
|
+
'min',
|
|
35
|
+
'max',
|
|
36
|
+
'allow',
|
|
37
|
+
'disallow',
|
|
38
|
+
'ai',
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
/** Every key of a field this reader models, `type` included — what a write it cannot name may have replaced. */
|
|
42
|
+
const MODELED_KEYS: readonly string[] = ['type', ...DROPPABLE_KEYS];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* How deep a field may nest before the reader stops. Each nested field set is
|
|
46
|
+
* one level, and so is each spread followed.
|
|
47
|
+
*
|
|
48
|
+
* Following names made cycles reachable: `const F = { type: 'object',
|
|
49
|
+
* objectFields: { a: F } }`, or `const A = { ...B }` beside `const B = { ...A
|
|
50
|
+
* }`, is source that could never have loaded at runtime, but this reader is
|
|
51
|
+
* handed text rather than a running module, and chasing it exhausts the stack
|
|
52
|
+
* and takes the caller down instead of reporting anything. Set well past what a
|
|
53
|
+
* field written on purpose reaches, so the cap only ever catches a cycle — and
|
|
54
|
+
* reaching it is an admission, never a crash.
|
|
55
|
+
*/
|
|
56
|
+
const MAX_FIELD_DEPTH = 16;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Where a field's spreads lead, and what a caller binds for the values the
|
|
60
|
+
* source does not write down.
|
|
61
|
+
*
|
|
62
|
+
* A field written in a config is read with both left empty: a spread leads to
|
|
63
|
+
* whatever name it stands for, and nothing is bound. A field a BUILDER returns
|
|
64
|
+
* is read with the call's arguments in scope, so `{ ...overrides }` reaches the
|
|
65
|
+
* literal the call passed and `label: label` reaches its value. The same
|
|
66
|
+
* sources reach every field set and entry nested inside, so a name bound at the
|
|
67
|
+
* top means the same thing three levels down.
|
|
68
|
+
*/
|
|
69
|
+
export interface FieldSources {
|
|
70
|
+
/** The caller owns builder interpretation; projection never imports the wrapper layer. */
|
|
71
|
+
builder?(call: CallExpression, depth: number): { field?: ManifestField; reason?: string };
|
|
72
|
+
/**
|
|
73
|
+
* The literal a spread reaches, `SPREADS_NOTHING` where the caller proved it
|
|
74
|
+
* carries none, or undefined where it could not be followed at all.
|
|
75
|
+
*/
|
|
76
|
+
spread(expression: Node): ObjectLiteralExpression | typeof SPREADS_NOTHING | undefined;
|
|
77
|
+
/** The value a caller's argument binds for a key the source names rather than writes down. */
|
|
78
|
+
bound(expression: Node): JsonValue | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* The literal a key's value names — `arrayFields: o.items` — reached through
|
|
81
|
+
* what the call binds before any name the source declares.
|
|
82
|
+
*/
|
|
83
|
+
object(expression: Node): ObjectLiteralExpression | undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A field written in a config: spreads lead to the names they stand for, and nothing is bound. */
|
|
87
|
+
export const WRITTEN_DOWN: FieldSources = {
|
|
88
|
+
spread: (expression) => resolveObjectLiteral(expression),
|
|
89
|
+
bound: () => undefined,
|
|
90
|
+
object: (expression) => resolveObjectLiteral(expression),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** Whether an expression is a function written in place — code, and so unreadable. */
|
|
94
|
+
function isFunctionExpression(node: Node): boolean {
|
|
95
|
+
return node.isKind(SyntaxKind.ArrowFunction) || node.isKind(SyntaxKind.FunctionExpression);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The choices a `radio` or `select` offers, or `undefined` when they are not
|
|
100
|
+
* written down as whole `{ label, value }` pairs. Half a list is worse than
|
|
101
|
+
* none: an agent would write a value Puck rejects and have no way to know why.
|
|
102
|
+
*
|
|
103
|
+
* Puck lets a label or a value be an object, and one with a part left out —
|
|
104
|
+
* `value: { x: 1, y: make() }` — would be handed on as the whole value. The
|
|
105
|
+
* reading only says that something somewhere in the list went unread, so any
|
|
106
|
+
* object label or value in a list with a part missing refuses the list; a
|
|
107
|
+
* string or a number cannot be read in part, and a gap beside one — an
|
|
108
|
+
* option's `icon: make()` — leaves the pair whole.
|
|
109
|
+
*/
|
|
110
|
+
function readOptions(reading: ValueReading | undefined): ManifestField['options'] | undefined {
|
|
111
|
+
const value = reading?.value;
|
|
112
|
+
if (!Array.isArray(value)) return undefined;
|
|
113
|
+
|
|
114
|
+
const options: NonNullable<ManifestField['options']> = [];
|
|
115
|
+
for (const entry of value) {
|
|
116
|
+
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) return undefined;
|
|
117
|
+
if (!('label' in entry) || !('value' in entry)) return undefined;
|
|
118
|
+
if (reading?.dropped && (isObject(entry.label) || isObject(entry.value))) return undefined;
|
|
119
|
+
options.push({ label: entry.label, value: entry.value });
|
|
120
|
+
}
|
|
121
|
+
return options;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Whether a JSON value is an object or an array — the kinds that can be read in part. */
|
|
125
|
+
function isObject(value: JsonValue | undefined): boolean {
|
|
126
|
+
return typeof value === 'object' && value !== null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* What one key amounts to: the value the caller binds for it, or the one the
|
|
131
|
+
* source writes down, and whether a part of it was left out.
|
|
132
|
+
*
|
|
133
|
+
* A bound value is read as whole as a written one — `max: o.max` beside `b({
|
|
134
|
+
* max: 7 })` IS 7 — so it admits nothing. A key whose value neither reaches is
|
|
135
|
+
* left unread, and admitted there.
|
|
136
|
+
*
|
|
137
|
+
* A written value with a part left out is kept and says so. A string, a number
|
|
138
|
+
* or a list of strings cannot be read in part, so only the options list has a
|
|
139
|
+
* gap to answer for, and `readOptions` does.
|
|
140
|
+
*/
|
|
141
|
+
function keyValue(node: Node, sources: FieldSources): ValueReading | undefined {
|
|
142
|
+
// The binding goes first: `o.label`, with `o` a parameter, names what the
|
|
143
|
+
// call passed, and nothing the source declares can stand in for it.
|
|
144
|
+
const bound = sources.bound(node);
|
|
145
|
+
return bound === undefined ? resolveLiteralValueReading(node) : { value: bound, dropped: false };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The name a shorthand member stands for. */
|
|
149
|
+
function shorthandName(member: NamedMember): Node | undefined {
|
|
150
|
+
return member.asKind(SyntaxKind.ShorthandPropertyAssignment)?.getNameNode();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Whether a name is one of the keys this reader models, and so one it can carry or drop. */
|
|
154
|
+
function isDroppable(name: string): name is DroppableKey {
|
|
155
|
+
return DROPPABLE_KEYS.has(name);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* One key of a spread source, carried over what was read above it — or dropped
|
|
160
|
+
* where the source read nothing for it. Shared by every reader that merges a
|
|
161
|
+
* spread by the runtime's rule, field or component.
|
|
162
|
+
*/
|
|
163
|
+
export function carryKey<T extends object, K extends keyof T>(target: T, base: T, key: K): void {
|
|
164
|
+
const value = base[key];
|
|
165
|
+
if (value === undefined) delete target[key];
|
|
166
|
+
else target[key] = value;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** One field literal walked in source order, plus what it — or anything it spreads — writes. */
|
|
170
|
+
interface FieldWalk {
|
|
171
|
+
field: ManifestField;
|
|
172
|
+
/**
|
|
173
|
+
* Every key the source writes, whether or not this reader could take the
|
|
174
|
+
* value. A key a spread source WRITES unreadably is a different thing from
|
|
175
|
+
* one it never mentions: the first overwrites what sits beside it, the second
|
|
176
|
+
* leaves it alone.
|
|
177
|
+
*/
|
|
178
|
+
written: Set<string>;
|
|
179
|
+
/**
|
|
180
|
+
* Written keys whose value was not read in full and no later readable write
|
|
181
|
+
* settled. `unreadable` says only that something went unread; this says
|
|
182
|
+
* what, so a custom field is called opaque only while nothing unread could be
|
|
183
|
+
* its schema.
|
|
184
|
+
*/
|
|
185
|
+
unknown: Set<string>;
|
|
186
|
+
/** The literal sets its own prototype, so a key it does not write itself may be inherited. */
|
|
187
|
+
inherits: boolean;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* A key written in a shape this reader cannot take. The value goes with it,
|
|
192
|
+
* because the last write wins at runtime and a spread's value left standing
|
|
193
|
+
* would be reported as the field's own.
|
|
194
|
+
*/
|
|
195
|
+
function clearKey(walk: FieldWalk, name: string): void {
|
|
196
|
+
walk.field.unreadable = true;
|
|
197
|
+
if (name === 'type') walk.field.type = 'unknown';
|
|
198
|
+
else if (isDroppable(name)) delete walk.field[name];
|
|
199
|
+
if (MODELED_KEYS.includes(name)) walk.unknown.add(name);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* A write this reader cannot name — `[key]: …`, or a spread leading nowhere —
|
|
204
|
+
* which may be any key at all, so every one read before it goes.
|
|
205
|
+
*/
|
|
206
|
+
function clearEveryKey(walk: FieldWalk): void {
|
|
207
|
+
for (const name of MODELED_KEYS) {
|
|
208
|
+
walk.written.add(name);
|
|
209
|
+
clearKey(walk, name);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Applies one walk over another at the position its spread sits — the runtime's own rule. */
|
|
214
|
+
function applyFieldWalk(walk: FieldWalk, base: FieldWalk): void {
|
|
215
|
+
for (const name of base.written) {
|
|
216
|
+
walk.written.add(name);
|
|
217
|
+
if (name === 'type') walk.field.type = base.field.type;
|
|
218
|
+
else if (isDroppable(name)) carryKey(walk.field, base.field, name);
|
|
219
|
+
if (base.unknown.has(name)) walk.unknown.add(name);
|
|
220
|
+
else walk.unknown.delete(name);
|
|
221
|
+
}
|
|
222
|
+
// A spread copies only what the source writes itself, so a prototype the
|
|
223
|
+
// source sets is not carried across it.
|
|
224
|
+
if (base.field.unreadable) walk.field.unreadable = true;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Reads one field declaration. Never throws: an unreadable field is reported,
|
|
229
|
+
* not dropped.
|
|
230
|
+
*
|
|
231
|
+
* What the WHOLE declaration amounts to is settled here rather than inside the
|
|
232
|
+
* walk, because a spread source is a fragment and not a declaration of its own:
|
|
233
|
+
* `{ max: 2 }` mentions no type because it is an override, and admitting it as
|
|
234
|
+
* no field at all would carry that admission into every field it overrides.
|
|
235
|
+
*/
|
|
236
|
+
export function readField(node: ObjectLiteralExpression, depth: number, sources: FieldSources): ManifestField {
|
|
237
|
+
const { field, written, unknown, inherits } = walkField(node, depth, sources);
|
|
238
|
+
|
|
239
|
+
// Puck has no field without a `type`, so an object that never mentions one —
|
|
240
|
+
// itself or through a spread — is something else wearing a field's place:
|
|
241
|
+
// `icon: ICONS`, where the name stands for a lookup table rather than a
|
|
242
|
+
// declaration. Reported as a plain `unknown` it poses as a field whose shape
|
|
243
|
+
// merely went unwritten; the admission says the entry itself is not a field
|
|
244
|
+
// this reader could read. A field with a prototype may inherit any key it
|
|
245
|
+
// does not write, which is the same admission.
|
|
246
|
+
if (!written.has('type') || inherits) field.unreadable = true;
|
|
247
|
+
|
|
248
|
+
// Puck takes a slot's nesting rules from the field OR from props on the slot
|
|
249
|
+
// its `render` draws — `<Items disallow={['Hero']} />` — and on the canvas
|
|
250
|
+
// the render's props are the ones that bind. `render` is code, which this
|
|
251
|
+
// reader never follows, so a slot that writes neither rule here has rules
|
|
252
|
+
// that are unknown rather than absent. Read as a slot anything may go into,
|
|
253
|
+
// it would be the confident wrong answer this reader exists to avoid.
|
|
254
|
+
if (field.type === 'slot' && field.allow === undefined && field.disallow === undefined) field.unreadable = true;
|
|
255
|
+
|
|
256
|
+
// `opaque` asserts that nothing describes the field, so it is claimed only
|
|
257
|
+
// when the `ai` block was read whole — or provably never written.
|
|
258
|
+
const schema = (field.ai as { schema?: unknown } | undefined)?.schema;
|
|
259
|
+
const aiUnread = unknown.has('ai') || (inherits && !written.has('ai'));
|
|
260
|
+
if (OPAQUE_TYPES.has(field.type) && schema === undefined && !aiUnread) field.opaque = true;
|
|
261
|
+
|
|
262
|
+
return field;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* The walk itself: the literal's members in source order, so a spread applies
|
|
267
|
+
* where it is written and the key after it wins, exactly as at runtime.
|
|
268
|
+
*/
|
|
269
|
+
function walkField(node: ObjectLiteralExpression, depth: number, sources: FieldSources): FieldWalk {
|
|
270
|
+
const walk: FieldWalk = { field: { type: 'unknown' }, written: new Set(), unknown: new Set(), inherits: false };
|
|
271
|
+
if (depth > MAX_FIELD_DEPTH) {
|
|
272
|
+
clearEveryKey(walk);
|
|
273
|
+
return walk;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
for (const property of node.getProperties()) {
|
|
277
|
+
spendWork();
|
|
278
|
+
const spread = property.asKind(SyntaxKind.SpreadAssignment);
|
|
279
|
+
if (spread) {
|
|
280
|
+
const source = sources.spread(spread.getExpression());
|
|
281
|
+
// A spread that carries nothing overwrites nothing at runtime either.
|
|
282
|
+
if (source === SPREADS_NOTHING) continue;
|
|
283
|
+
// One that cannot be followed may overwrite any key beside it.
|
|
284
|
+
if (source) applyFieldWalk(walk, walkField(source, depth + 1, sources));
|
|
285
|
+
else clearEveryKey(walk);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const member = namedMember(property);
|
|
290
|
+
const name = member && propertyKey(member);
|
|
291
|
+
if (!member || name === undefined) {
|
|
292
|
+
clearEveryKey(walk);
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (setsPrototype(member)) {
|
|
296
|
+
walk.inherits = true;
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
walk.written.add(name);
|
|
300
|
+
|
|
301
|
+
// `defaultItemProps() { … }`, `get max() { … }` — each writes its key with
|
|
302
|
+
// something this reader cannot take, and at runtime still overwrites
|
|
303
|
+
// whatever a spread above it put there. A shorthand of a key the manifest
|
|
304
|
+
// ignores names code as often as not, and is admitted the same way.
|
|
305
|
+
const value = member.isKind(SyntaxKind.PropertyAssignment)
|
|
306
|
+
? member.getInitializerOrThrow()
|
|
307
|
+
: MODELED_KEYS.includes(name)
|
|
308
|
+
? shorthandName(member)
|
|
309
|
+
: undefined;
|
|
310
|
+
if (value) readFieldMember(walk, name, value, depth, sources);
|
|
311
|
+
else clearKey(walk, name);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return walk;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* One `type` / `label` / `options` / … entry of a field declaration, and what
|
|
319
|
+
* became of it: taken whole, taken in part, not taken at all, or a key the
|
|
320
|
+
* manifest does not model.
|
|
321
|
+
*/
|
|
322
|
+
function readFieldMember(walk: FieldWalk, name: string, initializer: Node, depth: number, sources: FieldSources): void {
|
|
323
|
+
const outcome = readFieldValue(walk.field, name, initializer, depth, sources);
|
|
324
|
+
if (outcome === 'unread') clearKey(walk, name);
|
|
325
|
+
else if (outcome === 'partial') {
|
|
326
|
+
// What did read is kept; the field admits the rest.
|
|
327
|
+
walk.field.unreadable = true;
|
|
328
|
+
walk.unknown.add(name);
|
|
329
|
+
} else if (outcome === 'read') walk.unknown.delete(name);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function readFieldValue(
|
|
333
|
+
field: ManifestField,
|
|
334
|
+
name: string,
|
|
335
|
+
initializer: Node,
|
|
336
|
+
depth: number,
|
|
337
|
+
sources: FieldSources,
|
|
338
|
+
): 'read' | 'partial' | 'unread' | 'unmodeled' {
|
|
339
|
+
switch (name) {
|
|
340
|
+
case 'type':
|
|
341
|
+
case 'label': {
|
|
342
|
+
const value = keyValue(initializer, sources)?.value;
|
|
343
|
+
if (typeof value !== 'string') return 'unread';
|
|
344
|
+
field[name] = value;
|
|
345
|
+
return 'read';
|
|
346
|
+
}
|
|
347
|
+
case 'min':
|
|
348
|
+
case 'max': {
|
|
349
|
+
const value = keyValue(initializer, sources)?.value;
|
|
350
|
+
if (typeof value !== 'number') return 'unread';
|
|
351
|
+
field[name] = value;
|
|
352
|
+
return 'read';
|
|
353
|
+
}
|
|
354
|
+
case 'options': {
|
|
355
|
+
const options = readOptions(keyValue(initializer, sources));
|
|
356
|
+
if (!options) return 'unread';
|
|
357
|
+
field.options = options;
|
|
358
|
+
return 'read';
|
|
359
|
+
}
|
|
360
|
+
case 'allow':
|
|
361
|
+
case 'disallow': {
|
|
362
|
+
const value = keyValue(initializer, sources)?.value;
|
|
363
|
+
if (!Array.isArray(value) || !value.every((entry) => typeof entry === 'string')) return 'unread';
|
|
364
|
+
field[name] = value as string[];
|
|
365
|
+
return 'read';
|
|
366
|
+
}
|
|
367
|
+
case 'arrayFields':
|
|
368
|
+
case 'objectFields': {
|
|
369
|
+
const nested = readFieldSet(initializer, depth + 1, sources);
|
|
370
|
+
if (!nested) return 'unread';
|
|
371
|
+
field[name] = nested.fields;
|
|
372
|
+
return nested.unreadable ? 'partial' : 'read';
|
|
373
|
+
}
|
|
374
|
+
case 'ai': {
|
|
375
|
+
// `ai: HERO_AI` names the annotation rather than writing it out, and a
|
|
376
|
+
// reader that stops at the name calls the field opaque with the schema
|
|
377
|
+
// that describes it two lines up. The names inside it — `...BASE_AI`,
|
|
378
|
+
// `schema: SCHEMA` — are followed too, as a component's are.
|
|
379
|
+
const reading = literalObjectReading(sources.object(initializer) ?? initializer);
|
|
380
|
+
// A reading with a gap and nothing else is no reading: `ai: {}` beside
|
|
381
|
+
// the admission would pass for an annotation written empty.
|
|
382
|
+
if (!reading || (reading.dropped && Object.keys(reading.value).length === 0)) return 'unread';
|
|
383
|
+
field.ai = reading.value;
|
|
384
|
+
// An entry left out may be the schema itself.
|
|
385
|
+
return reading.dropped ? 'partial' : 'read';
|
|
386
|
+
}
|
|
387
|
+
default: {
|
|
388
|
+
// A function-valued key (defaultItemProps, getItemSummary, render) is
|
|
389
|
+
// the readable/unreadable boundary. Say so rather than staying silent.
|
|
390
|
+
if (isFunctionExpression(initializer)) field.unreadable = true;
|
|
391
|
+
return 'unmodeled';
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** A field set read in source order: the entries it provably declares, and whether it may declare more. */
|
|
397
|
+
export interface FieldSetReading {
|
|
398
|
+
fields: Record<string, ManifestField>;
|
|
399
|
+
/**
|
|
400
|
+
* Something the set writes could not be read — a spread leading nowhere, a
|
|
401
|
+
* key this reader cannot name, a prototype whose entries Puck also walks —
|
|
402
|
+
* and may have added or replaced any entry.
|
|
403
|
+
* The entries above are the ones written after it, which stand whatever it
|
|
404
|
+
* turns out to write; any other prop may exist too.
|
|
405
|
+
*/
|
|
406
|
+
unreadable: boolean;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Reads a `Record<string, Field>` — a component's `fields`, a nested
|
|
411
|
+
* array/object field set, or the page's `root.fields` — the one field-set
|
|
412
|
+
* reader every owner of one shares.
|
|
413
|
+
*
|
|
414
|
+
* Walked in source order, spreads included, so `{ ...BASE, x }` reads BASE's
|
|
415
|
+
* entries and then `x`, the later write of a name winning as it does at
|
|
416
|
+
* runtime. A spread that cannot be followed, and a key this reader cannot name
|
|
417
|
+
* (`[key]: …`), may each write any entry, so the entries before them go and
|
|
418
|
+
* the set is admitted; the owner turns that into its own admission. A spread
|
|
419
|
+
* shown to carry nothing — an argument the call omits — writes nothing, and
|
|
420
|
+
* `__proto__: base` hands the set entries Puck's `for…in` reaches too, so it
|
|
421
|
+
* is admitted the same way.
|
|
422
|
+
*
|
|
423
|
+
* An entry written as a name (`layout: layoutField`) is followed to the
|
|
424
|
+
* declaration it stands for, and one a helper builds (`buttons:
|
|
425
|
+
* ctaButtonArrayField()`) is read from the helper, so a field set split across
|
|
426
|
+
* files or behind a builder reads the same as one written in place. An entry
|
|
427
|
+
* this reader cannot follow — a getter, a method, a name leading nowhere —
|
|
428
|
+
* keeps its place: the prop is real and an agent may write to it, so the
|
|
429
|
+
* manifest names it and admits the constraints are unknown.
|
|
430
|
+
*
|
|
431
|
+
* The set itself may be named too — `fields: sharedFields`, `objectFields:
|
|
432
|
+
* sub` — and is followed the same way. Undefined is left for the name that
|
|
433
|
+
* cannot be followed at all, which the caller turns into its own admission.
|
|
434
|
+
*/
|
|
435
|
+
export function readFieldSet(
|
|
436
|
+
node: Node | undefined,
|
|
437
|
+
depth: number,
|
|
438
|
+
sources: FieldSources,
|
|
439
|
+
): FieldSetReading | undefined {
|
|
440
|
+
const literal = node && sources.object(node);
|
|
441
|
+
return literal && walkFieldSet(literal, depth, sources);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function walkFieldSet(literal: ObjectLiteralExpression, depth: number, sources: FieldSources): FieldSetReading {
|
|
445
|
+
if (depth > MAX_FIELD_DEPTH) return { fields: {}, unreadable: true };
|
|
446
|
+
const reading: FieldSetReading = { fields: {}, unreadable: false };
|
|
447
|
+
|
|
448
|
+
for (const property of literal.getProperties()) {
|
|
449
|
+
spendWork();
|
|
450
|
+
const spread = property.asKind(SyntaxKind.SpreadAssignment);
|
|
451
|
+
if (spread) {
|
|
452
|
+
const source = sources.spread(spread.getExpression());
|
|
453
|
+
if (source === SPREADS_NOTHING) continue;
|
|
454
|
+
const merged = source && walkFieldSet(source, depth + 1, sources);
|
|
455
|
+
if (!merged || merged.unreadable) {
|
|
456
|
+
reading.fields = {};
|
|
457
|
+
reading.unreadable = true;
|
|
458
|
+
}
|
|
459
|
+
if (merged) Object.assign(reading.fields, merged.fields);
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const member = namedMember(property);
|
|
464
|
+
const key = member && propertyKey(member);
|
|
465
|
+
if (!member || key === undefined) {
|
|
466
|
+
reading.fields = {};
|
|
467
|
+
reading.unreadable = true;
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
// Puck walks a field set with `for…in`, which reaches every entry the
|
|
471
|
+
// prototype carries — none of them written here, so the set is admitted.
|
|
472
|
+
// A `null` prototype carries nothing.
|
|
473
|
+
if (setsPrototype(member)) {
|
|
474
|
+
if (!inheritsNothing(member)) reading.unreadable = true;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
// `['__proto__']: …` is an ordinary own entry at runtime, and one no record
|
|
478
|
+
// of ours can hold: assigning it replaces the record's prototype instead of
|
|
479
|
+
// adding a key, so someone else's config could reach through this reader
|
|
480
|
+
// and change what every later object inherits. It is admitted instead.
|
|
481
|
+
if (key === '__proto__') {
|
|
482
|
+
reading.unreadable = true;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
const value = writtenValue(member);
|
|
486
|
+
reading.fields[key] = (value && readFieldDeclaration(value, depth, sources)) ?? {
|
|
487
|
+
type: 'unknown',
|
|
488
|
+
unreadable: true,
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
return reading;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* One entry of a field set: the declaration a name stands for, or the field a
|
|
496
|
+
* helper call builds. Undefined when neither can be followed, which the caller
|
|
497
|
+
* reports as a prop whose shape is unknown.
|
|
498
|
+
*
|
|
499
|
+
* An entry sits at the depth of the set holding it: the set is the level, and
|
|
500
|
+
* counting the entry again would stop a field written on purpose at half the
|
|
501
|
+
* depth the cap promises.
|
|
502
|
+
*/
|
|
503
|
+
function readFieldDeclaration(node: Node, depth: number, sources: FieldSources): ManifestField | undefined {
|
|
504
|
+
const literal = sources.object(node);
|
|
505
|
+
if (literal) return readField(literal, depth, sources);
|
|
506
|
+
const call = resolveCallExpression(node);
|
|
507
|
+
// The refusal's reason is dropped: there is nowhere on a field to record why
|
|
508
|
+
// a builder was refused, and the entry says the shape is unknown either way.
|
|
509
|
+
return call ? sources.builder?.(call, depth).field : undefined;
|
|
510
|
+
}
|