@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.
Files changed (422) hide show
  1. package/README.md +254 -301
  2. package/dist/internal/acorn-default.mjs +11 -3
  3. package/dist/internal/page-handler.astro +137 -358
  4. package/dist/ts/node/content.d.ts +4 -0
  5. package/dist/ts/node/content.d.ts.map +1 -0
  6. package/dist/ts/node/content.js +3 -0
  7. package/dist/ts/node/content.js.map +1 -0
  8. package/dist/ts/node/index.d.ts +9 -0
  9. package/dist/ts/node/index.d.ts.map +1 -0
  10. package/dist/ts/node/index.js +14 -0
  11. package/dist/ts/node/index.js.map +1 -0
  12. package/dist/ts/src/asset-ref-base.d.ts +3 -0
  13. package/dist/ts/src/asset-ref-base.d.ts.map +1 -0
  14. package/dist/ts/src/asset-ref-base.js +48 -0
  15. package/dist/ts/src/asset-ref-base.js.map +1 -0
  16. package/dist/ts/src/checks.d.ts +7 -0
  17. package/dist/ts/src/checks.d.ts.map +1 -0
  18. package/dist/ts/src/checks.js +7 -0
  19. package/dist/ts/src/checks.js.map +1 -0
  20. package/dist/{src → ts/src}/cms-handler.d.ts +0 -1
  21. package/dist/ts/src/cms-handler.d.ts.map +1 -0
  22. package/dist/{src → ts/src}/cms-handler.js +11 -131
  23. package/dist/ts/src/cms-handler.js.map +1 -0
  24. package/dist/ts/src/collections.d.ts +161 -0
  25. package/dist/ts/src/collections.d.ts.map +1 -0
  26. package/dist/ts/src/collections.js +178 -0
  27. package/dist/ts/src/collections.js.map +1 -0
  28. package/dist/{src → ts/src}/components/HydrationWrapper.d.ts +1 -1
  29. package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
  30. package/dist/{src → ts/src}/components/HydrationWrapper.js +1 -0
  31. package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
  32. package/dist/{src/components/RenderWithBlocks.d.ts → ts/src/components/RenderWithFragments.d.ts} +8 -4
  33. package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -0
  34. package/dist/ts/src/components/RenderWithFragments.js +133 -0
  35. package/dist/ts/src/components/RenderWithFragments.js.map +1 -0
  36. package/dist/{src → ts/src}/components/RenderWithHydration.d.ts +6 -2
  37. package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
  38. package/dist/{src → ts/src}/components/RenderWithHydration.js +6 -3
  39. package/dist/ts/src/components/RenderWithHydration.js.map +1 -0
  40. package/dist/ts/src/components.d.ts +4 -0
  41. package/dist/ts/src/components.d.ts.map +1 -0
  42. package/dist/ts/src/components.js +4 -0
  43. package/dist/ts/src/components.js.map +1 -0
  44. package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
  45. package/dist/{src → ts/src}/discovery/astro-frontmatter.js +1 -0
  46. package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
  47. package/dist/ts/src/discovery/discover.d.ts +43 -0
  48. package/dist/ts/src/discovery/discover.d.ts.map +1 -0
  49. package/dist/ts/src/discovery/discover.js +87 -0
  50. package/dist/ts/src/discovery/discover.js.map +1 -0
  51. package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
  52. package/dist/{src → ts/src}/discovery/extract-props-ts.js +1 -0
  53. package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
  54. package/dist/{src → ts/src}/discovery/merge-registry.d.ts +3 -3
  55. package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
  56. package/dist/{src → ts/src}/discovery/merge-registry.js +1 -0
  57. package/dist/ts/src/discovery/merge-registry.js.map +1 -0
  58. package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
  59. package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
  60. package/dist/ts/src/discovery/registry-endpoint.js +76 -0
  61. package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
  62. package/dist/{src → ts/src}/discovery/scan-components.d.ts +3 -7
  63. package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
  64. package/dist/{src → ts/src}/discovery/scan-components.js +4 -6
  65. package/dist/ts/src/discovery/scan-components.js.map +1 -0
  66. package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
  67. package/dist/{src → ts/src}/discovery/scan-mdx.js +1 -0
  68. package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
  69. package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
  70. package/dist/{src → ts/src}/discovery/scan-overrides.js +1 -0
  71. package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
  72. package/dist/ts/src/editor-descriptors.d.ts +31 -0
  73. package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
  74. package/dist/ts/src/editor-descriptors.js +84 -0
  75. package/dist/ts/src/editor-descriptors.js.map +1 -0
  76. package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
  77. package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
  78. package/dist/ts/src/handlers/collection-content-api.js +166 -0
  79. package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
  80. package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
  81. package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
  82. package/dist/ts/src/handlers/page-render-core.js +315 -0
  83. package/dist/ts/src/handlers/page-render-core.js.map +1 -0
  84. package/dist/ts/src/hydration.d.ts.map +1 -0
  85. package/dist/{src → ts/src}/hydration.js +1 -0
  86. package/dist/ts/src/hydration.js.map +1 -0
  87. package/dist/ts/src/index.d.ts +21 -0
  88. package/dist/ts/src/index.d.ts.map +1 -0
  89. package/dist/ts/src/index.js +45 -0
  90. package/dist/ts/src/index.js.map +1 -0
  91. package/dist/ts/src/internal/declared-collections.d.ts +30 -0
  92. package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
  93. package/dist/ts/src/internal/declared-collections.js +84 -0
  94. package/dist/ts/src/internal/declared-collections.js.map +1 -0
  95. package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
  96. package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
  97. package/dist/ts/src/internal/page-collection-schema.js +152 -0
  98. package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
  99. package/dist/ts/src/lib/content-config-guard.d.ts +13 -0
  100. package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
  101. package/dist/ts/src/lib/content-config-guard.js +45 -0
  102. package/dist/ts/src/lib/content-config-guard.js.map +1 -0
  103. package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
  104. package/dist/{src → ts/src}/lib/hydration-scanner.js +1 -0
  105. package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
  106. package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
  107. package/dist/{src → ts/src}/lib/hydration-script.js +1 -0
  108. package/dist/ts/src/lib/hydration-script.js.map +1 -0
  109. package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
  110. package/dist/{src → ts/src}/lib/hydration-utils.js +1 -0
  111. package/dist/ts/src/lib/hydration-utils.js.map +1 -0
  112. package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
  113. package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
  114. package/dist/ts/src/lib/resolve-locale.js +16 -0
  115. package/dist/ts/src/lib/resolve-locale.js.map +1 -0
  116. package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
  117. package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
  118. package/dist/ts/src/lib/resolve-site-name.js +12 -0
  119. package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
  120. package/dist/{src → ts/src}/lib/route-utils.d.ts +26 -6
  121. package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
  122. package/dist/{src → ts/src}/lib/route-utils.js +33 -15
  123. package/dist/ts/src/lib/route-utils.js.map +1 -0
  124. package/dist/{src → ts/src}/lib/routing-config.d.ts +7 -1
  125. package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
  126. package/dist/{src → ts/src}/lib/routing-config.js +13 -0
  127. package/dist/ts/src/lib/routing-config.js.map +1 -0
  128. package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
  129. package/dist/{src → ts/src}/lib/serialize-props.js +1 -0
  130. package/dist/ts/src/lib/serialize-props.js.map +1 -0
  131. package/dist/ts/src/lib/unknown-components.d.ts +21 -0
  132. package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
  133. package/dist/ts/src/lib/unknown-components.js +49 -0
  134. package/dist/ts/src/lib/unknown-components.js.map +1 -0
  135. package/dist/{src → ts/src}/lib/virtual-module-generators.d.ts +0 -24
  136. package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
  137. package/dist/ts/src/lib/virtual-module-generators.js +51 -0
  138. package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
  139. package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
  140. package/dist/{src → ts/src}/lib/withHydration.js +1 -0
  141. package/dist/ts/src/lib/withHydration.js.map +1 -0
  142. package/dist/ts/src/loader.d.ts +27 -0
  143. package/dist/ts/src/loader.d.ts.map +1 -0
  144. package/dist/{src → ts/src}/loader.js +33 -4
  145. package/dist/ts/src/loader.js.map +1 -0
  146. package/dist/ts/src/locales-helpers.d.ts.map +1 -0
  147. package/dist/{src → ts/src}/locales-helpers.js +1 -0
  148. package/dist/ts/src/locales-helpers.js.map +1 -0
  149. package/dist/ts/src/mime-types.d.ts.map +1 -0
  150. package/dist/{src → ts/src}/mime-types.js +1 -0
  151. package/dist/ts/src/mime-types.js.map +1 -0
  152. package/dist/ts/src/page-feed.d.ts +13 -0
  153. package/dist/ts/src/page-feed.d.ts.map +1 -0
  154. package/dist/ts/src/page-feed.js +20 -0
  155. package/dist/ts/src/page-feed.js.map +1 -0
  156. package/dist/ts/src/page-schemas.d.ts +6 -0
  157. package/dist/ts/src/page-schemas.d.ts.map +1 -0
  158. package/dist/ts/src/page-schemas.js +6 -0
  159. package/dist/ts/src/page-schemas.js.map +1 -0
  160. package/dist/ts/src/path-validation.d.ts.map +1 -0
  161. package/dist/{src → ts/src}/path-validation.js +1 -0
  162. package/dist/ts/src/path-validation.js.map +1 -0
  163. package/dist/{src → ts/src}/plugin-spa.d.ts +28 -10
  164. package/dist/ts/src/plugin-spa.d.ts.map +1 -0
  165. package/dist/{src → ts/src}/plugin-spa.js +301 -88
  166. package/dist/ts/src/plugin-spa.js.map +1 -0
  167. package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
  168. package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
  169. package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
  170. package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
  171. package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
  172. package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
  173. package/dist/ts/src/puck-manifest/field-projection.js +422 -0
  174. package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
  175. package/dist/ts/src/puck-manifest/index.d.ts +4 -0
  176. package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
  177. package/dist/ts/src/puck-manifest/index.js +3 -0
  178. package/dist/ts/src/puck-manifest/index.js.map +1 -0
  179. package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
  180. package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
  181. package/dist/ts/src/puck-manifest/literal.js +354 -0
  182. package/dist/ts/src/puck-manifest/literal.js.map +1 -0
  183. package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
  184. package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
  185. package/dist/ts/src/puck-manifest/read-config.js +517 -0
  186. package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
  187. package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
  188. package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
  189. package/dist/ts/src/puck-manifest/read-field.js +11 -0
  190. package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
  191. package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
  192. package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
  193. package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
  194. package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
  195. package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
  196. package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
  197. package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
  198. package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
  199. package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
  200. package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
  201. package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
  202. package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
  203. package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
  204. package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
  205. package/dist/ts/src/puck-manifest/source-reference.js +424 -0
  206. package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
  207. package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
  208. package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
  209. package/dist/ts/src/puck-manifest/syntax.js +79 -0
  210. package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
  211. package/dist/ts/src/puck-manifest/types.d.ts +145 -0
  212. package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
  213. package/dist/ts/src/puck-manifest/types.js +2 -0
  214. package/dist/ts/src/puck-manifest/types.js.map +1 -0
  215. package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
  216. package/dist/{src → ts/src}/safe-json-stringify.js +1 -0
  217. package/dist/ts/src/safe-json-stringify.js.map +1 -0
  218. package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
  219. package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
  220. package/dist/ts/src/sandbox-frame-handler.js +27 -0
  221. package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
  222. package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.d.ts +2 -5
  223. package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
  224. package/dist/{src → ts/src}/site-styles/content-wrapper-endpoint.js +5 -8
  225. package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
  226. package/dist/{src → ts/src}/site-styles/render-endpoint.d.ts +4 -9
  227. package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
  228. package/dist/{src → ts/src}/site-styles/render-endpoint.js +1 -0
  229. package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
  230. package/dist/{src → ts/src}/site-styles/styles-endpoint.d.ts +2 -4
  231. package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
  232. package/dist/{src → ts/src}/site-styles/styles-endpoint.js +3 -5
  233. package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
  234. package/dist/ts/src/sitemap-options.d.ts +21 -0
  235. package/dist/ts/src/sitemap-options.d.ts.map +1 -0
  236. package/dist/ts/src/sitemap-options.js +92 -0
  237. package/dist/ts/src/sitemap-options.js.map +1 -0
  238. package/dist/ts/src/tiptap-html-static.d.ts +16 -0
  239. package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
  240. package/dist/ts/src/tiptap-html-static.js +117 -0
  241. package/dist/ts/src/tiptap-html-static.js.map +1 -0
  242. package/dist/{src → ts/src}/types.d.ts +26 -110
  243. package/dist/ts/src/types.d.ts.map +1 -0
  244. package/dist/ts/src/types.js +2 -0
  245. package/dist/ts/src/types.js.map +1 -0
  246. package/dist/virtual-modules.d.ts +12 -93
  247. package/node/content.ts +14 -0
  248. package/node/index.ts +22 -0
  249. package/package.json +161 -73
  250. package/src/asset-ref-base.ts +48 -0
  251. package/src/checks.ts +11 -0
  252. package/src/cms-handler.ts +281 -0
  253. package/src/collections.ts +271 -0
  254. package/src/components/HydrationWrapper.tsx +41 -0
  255. package/src/components/RenderWithFragments.tsx +204 -0
  256. package/src/components/RenderWithHydration.tsx +55 -0
  257. package/src/components.ts +3 -0
  258. package/src/discovery/astro-frontmatter.ts +24 -0
  259. package/src/discovery/discover.ts +108 -0
  260. package/src/discovery/extract-props-ts.ts +255 -0
  261. package/src/discovery/merge-registry.ts +411 -0
  262. package/src/discovery/registry-endpoint.ts +80 -0
  263. package/src/discovery/scan-components.ts +458 -0
  264. package/src/discovery/scan-mdx.ts +190 -0
  265. package/src/discovery/scan-overrides.ts +92 -0
  266. package/src/editor-descriptors.ts +96 -0
  267. package/src/env.d.ts +31 -0
  268. package/src/handlers/collection-content-api.ts +196 -0
  269. package/src/handlers/page-handler.astro +320 -0
  270. package/src/handlers/page-render-core.ts +456 -0
  271. package/src/hydration.ts +7 -0
  272. package/src/index.ts +111 -0
  273. package/src/internal/acorn-default.mjs +37 -0
  274. package/src/internal/declared-collections.ts +98 -0
  275. package/src/internal/page-collection-schema.ts +210 -0
  276. package/src/lib/content-config-guard.ts +53 -0
  277. package/src/lib/hydration-scanner.ts +176 -0
  278. package/src/lib/hydration-script.ts +126 -0
  279. package/src/lib/hydration-utils.ts +120 -0
  280. package/src/lib/resolve-locale.ts +22 -0
  281. package/src/lib/resolve-site-name.ts +10 -0
  282. package/src/lib/route-utils.ts +106 -0
  283. package/src/lib/routing-config.ts +126 -0
  284. package/src/lib/serialize-props.ts +7 -0
  285. package/src/lib/unknown-components.ts +64 -0
  286. package/src/lib/virtual-module-generators.ts +58 -0
  287. package/{dist/withHydration-DkKpkmzJ.d.mts → src/lib/withHydration.ts} +25 -8
  288. package/src/loader.ts +145 -0
  289. package/{dist/locales-helpers-BvYYqnJ5.d.mts → src/locales-helpers.ts} +21 -17
  290. package/src/mime-types.ts +19 -0
  291. package/src/page-feed.ts +26 -0
  292. package/src/page-schemas.ts +19 -0
  293. package/src/path-validation.ts +13 -0
  294. package/src/plugin-spa.ts +1496 -0
  295. package/src/puck-manifest/components-endpoint.ts +55 -0
  296. package/src/puck-manifest/field-projection.ts +510 -0
  297. package/src/puck-manifest/index.ts +3 -0
  298. package/src/puck-manifest/literal.ts +459 -0
  299. package/src/puck-manifest/read-config.ts +577 -0
  300. package/src/puck-manifest/read-field.ts +19 -0
  301. package/src/puck-manifest/read-wrapper.ts +1056 -0
  302. package/src/puck-manifest/reading-budget.ts +127 -0
  303. package/src/puck-manifest/resolve-reference.ts +9 -0
  304. package/src/puck-manifest/source-reference.ts +484 -0
  305. package/src/puck-manifest/syntax.ts +104 -0
  306. package/src/puck-manifest/types.ts +139 -0
  307. package/src/safe-json-stringify.ts +17 -0
  308. package/src/sandbox-frame-handler.ts +31 -0
  309. package/src/site-styles/content-wrapper-endpoint.ts +327 -0
  310. package/src/site-styles/render-endpoint.ts +331 -0
  311. package/src/site-styles/styles-endpoint.ts +184 -0
  312. package/src/sitemap-options.ts +115 -0
  313. package/src/tiptap-html-static.ts +134 -0
  314. package/{dist/types-CS9neadI.d.mts → src/types.ts} +87 -124
  315. package/src/virtual-modules.d.ts +74 -0
  316. package/dist/collections-Bd7EME4b.mjs +0 -129
  317. package/dist/collections-Bd7EME4b.mjs.map +0 -1
  318. package/dist/collections.d.mts +0 -35
  319. package/dist/collections.d.mts.map +0 -1
  320. package/dist/collections.mjs +0 -2
  321. package/dist/components.d.mts +0 -41
  322. package/dist/components.d.mts.map +0 -1
  323. package/dist/components.mjs +0 -223
  324. package/dist/components.mjs.map +0 -1
  325. package/dist/hydration.d.mts +0 -4
  326. package/dist/hydration.mjs +0 -2
  327. package/dist/index.d.mts +0 -108
  328. package/dist/index.d.mts.map +0 -1
  329. package/dist/index.mjs +0 -67
  330. package/dist/index.mjs.map +0 -1
  331. package/dist/internal/cms-handler.d.mts +0 -25
  332. package/dist/internal/cms-handler.d.mts.map +0 -1
  333. package/dist/internal/cms-handler.mjs +0 -314
  334. package/dist/internal/cms-handler.mjs.map +0 -1
  335. package/dist/lib/hydration-script.d.mts +0 -30
  336. package/dist/lib/hydration-script.d.mts.map +0 -1
  337. package/dist/lib/hydration-script.mjs +0 -84
  338. package/dist/lib/hydration-script.mjs.map +0 -1
  339. package/dist/locales-helpers-BvYYqnJ5.d.mts.map +0 -1
  340. package/dist/locales-helpers-qiwh7nxS.mjs +0 -54
  341. package/dist/locales-helpers-qiwh7nxS.mjs.map +0 -1
  342. package/dist/node/content.d.mts +0 -18
  343. package/dist/node/content.d.mts.map +0 -1
  344. package/dist/node/content.d.ts +0 -3
  345. package/dist/node/content.d.ts.map +0 -1
  346. package/dist/node/content.js +0 -2
  347. package/dist/node/content.mjs +0 -2
  348. package/dist/node/index.d.mts +0 -200
  349. package/dist/node/index.d.mts.map +0 -1
  350. package/dist/node/index.d.ts +0 -4
  351. package/dist/node/index.d.ts.map +0 -1
  352. package/dist/node/index.js +0 -3
  353. package/dist/node/index.mjs +0 -2513
  354. package/dist/node/index.mjs.map +0 -1
  355. package/dist/serialize-props-BHoNpzH6.mjs +0 -72
  356. package/dist/serialize-props-BHoNpzH6.mjs.map +0 -1
  357. package/dist/src/cms-handler.d.ts.map +0 -1
  358. package/dist/src/collections.d.ts +0 -32
  359. package/dist/src/collections.d.ts.map +0 -1
  360. package/dist/src/collections.js +0 -50
  361. package/dist/src/components/HydrationWrapper.d.ts.map +0 -1
  362. package/dist/src/components/RenderWithBlocks.d.ts.map +0 -1
  363. package/dist/src/components/RenderWithBlocks.js +0 -129
  364. package/dist/src/components/RenderWithHydration.d.ts.map +0 -1
  365. package/dist/src/components.d.ts +0 -4
  366. package/dist/src/components.d.ts.map +0 -1
  367. package/dist/src/components.js +0 -3
  368. package/dist/src/discovery/astro-frontmatter.d.ts.map +0 -1
  369. package/dist/src/discovery/extract-props-ts.d.ts.map +0 -1
  370. package/dist/src/discovery/merge-registry.d.ts.map +0 -1
  371. package/dist/src/discovery/registry-endpoint.d.ts +0 -42
  372. package/dist/src/discovery/registry-endpoint.d.ts.map +0 -1
  373. package/dist/src/discovery/registry-endpoint.js +0 -81
  374. package/dist/src/discovery/scan-components.d.ts.map +0 -1
  375. package/dist/src/discovery/scan-mdx.d.ts.map +0 -1
  376. package/dist/src/discovery/scan-overrides.d.ts.map +0 -1
  377. package/dist/src/hydration.d.ts.map +0 -1
  378. package/dist/src/index.d.ts +0 -11
  379. package/dist/src/index.d.ts.map +0 -1
  380. package/dist/src/index.js +0 -25
  381. package/dist/src/lib/hydration-scanner.d.ts.map +0 -1
  382. package/dist/src/lib/hydration-script.d.ts.map +0 -1
  383. package/dist/src/lib/hydration-utils.d.ts.map +0 -1
  384. package/dist/src/lib/page-api.d.ts +0 -77
  385. package/dist/src/lib/page-api.d.ts.map +0 -1
  386. package/dist/src/lib/page-api.js +0 -121
  387. package/dist/src/lib/route-utils.d.ts.map +0 -1
  388. package/dist/src/lib/routing-config.d.ts.map +0 -1
  389. package/dist/src/lib/serialize-props.d.ts.map +0 -1
  390. package/dist/src/lib/virtual-module-generators.d.ts.map +0 -1
  391. package/dist/src/lib/virtual-module-generators.js +0 -263
  392. package/dist/src/lib/withHydration.d.ts.map +0 -1
  393. package/dist/src/loader.d.ts +0 -14
  394. package/dist/src/loader.d.ts.map +0 -1
  395. package/dist/src/locales-helpers.d.ts.map +0 -1
  396. package/dist/src/mime-types.d.ts.map +0 -1
  397. package/dist/src/path-validation.d.ts.map +0 -1
  398. package/dist/src/plugin-spa.d.ts.map +0 -1
  399. package/dist/src/safe-json-stringify.d.ts.map +0 -1
  400. package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +0 -1
  401. package/dist/src/site-styles/render-endpoint.d.ts.map +0 -1
  402. package/dist/src/site-styles/styles-endpoint.d.ts.map +0 -1
  403. package/dist/src/types.d.ts.map +0 -1
  404. package/dist/src/types.js +0 -1
  405. package/dist/types-CS9neadI.d.mts.map +0 -1
  406. package/dist/withHydration-C256ox_6.mjs +0 -49
  407. package/dist/withHydration-C256ox_6.mjs.map +0 -1
  408. package/dist/withHydration-DkKpkmzJ.d.mts.map +0 -1
  409. /package/dist/{src → ts/src}/discovery/astro-frontmatter.d.ts +0 -0
  410. /package/dist/{src → ts/src}/discovery/extract-props-ts.d.ts +0 -0
  411. /package/dist/{src → ts/src}/discovery/scan-mdx.d.ts +0 -0
  412. /package/dist/{src → ts/src}/discovery/scan-overrides.d.ts +0 -0
  413. /package/dist/{src → ts/src}/hydration.d.ts +0 -0
  414. /package/dist/{src → ts/src}/lib/hydration-scanner.d.ts +0 -0
  415. /package/dist/{src → ts/src}/lib/hydration-script.d.ts +0 -0
  416. /package/dist/{src → ts/src}/lib/hydration-utils.d.ts +0 -0
  417. /package/dist/{src → ts/src}/lib/serialize-props.d.ts +0 -0
  418. /package/dist/{src → ts/src}/lib/withHydration.d.ts +0 -0
  419. /package/dist/{src → ts/src}/locales-helpers.d.ts +0 -0
  420. /package/dist/{src → ts/src}/mime-types.d.ts +0 -0
  421. /package/dist/{src → ts/src}/path-validation.d.ts +0 -0
  422. /package/dist/{src → ts/src}/safe-json-stringify.d.ts +0 -0
@@ -0,0 +1,889 @@
1
+ /**
2
+ * Reads the component a wrapper call builds — `export const Grid =
3
+ * withLayout(GridInternal)` — on paper, by merging the argument's written-down
4
+ * literal with the wrapper's written-down additions. The wrapper is never run:
5
+ * this reader is handed arbitrary site source, and a manifest is not worth
6
+ * executing a stranger's module for.
7
+ *
8
+ * The shape a wrapper must have is deliberately narrow — one `return` of an
9
+ * object literal, every parameter bound by an argument that resolves to a
10
+ * literal, no destructuring, no rest, no nesting. Each of those rules is here
11
+ * because probing real and adversarial configs showed that dropping it
12
+ * produces a confident wrong answer rather than a gap: a body reading an unbound
13
+ * `opts.label ?? 'fallback'` summarizes as the argument's own label, which is a
14
+ * lie an agent has no way to catch. Everything outside the shape is refused,
15
+ * and every refusal carries the reason, so the caller reports "could not read,
16
+ * because X" instead of a component that appears to accept nothing.
17
+ *
18
+ * The same machinery, read a second way, is how a FIELD declared through a
19
+ * helper is recovered: `buttons: ctaButtonArrayField()` returns one object
20
+ * literal too, and only what that literal is read AS differs. The rules for
21
+ * the body hold for both; the rules for binding do not. A builder is called
22
+ * for its whole answer rather than to decorate an argument, so it may take no
23
+ * parameters, an argument the call omits binds undefined — `{ ...overrides }`
24
+ * then spreads nothing, and a key read off it is left unread and admitted —
25
+ * and a plain value such as `'Title'` binds as itself. The `opts.label ??
26
+ * 'fallback'` above is a wrapper's hazard; in a builder that expression is
27
+ * left unread, and the field admits it.
28
+ *
29
+ * The component walk the wrapper reading ends in is also how the config reads
30
+ * every component, written in place or reached by name: `readComponentWithSpreads`
31
+ * walks a component literal by the same rules with nothing bound, and a spread
32
+ * of a wrapper-built component — `Grid: { ...Grid, label: … }` — merges the
33
+ * wrapper's reading where the spread sits, as `readWrapperCallReading` hands
34
+ * it over.
35
+ *
36
+ * Known limit: a wrapper that MUTATES a shared config at import time —
37
+ * `Object.assign(base, extra)` — defeats any reader that works from source,
38
+ * because the text says one thing and the module's load order does another.
39
+ * Nothing here detects it; it is covered by watching what the site actually
40
+ * renders, not by reading.
41
+ *
42
+ * Known limit: a slot's nesting rules may be written on the field or on the
43
+ * slot the component's `render` draws — `<Items disallow={['Hero']} />` — and
44
+ * the render's are the ones the canvas enforces. Only the field form is read,
45
+ * `render` being code; a slot writing no rules of its own is admitted rather
46
+ * than reported as taking anything, and what really nests inside it is
47
+ * answered the same way, by watching what the site renders.
48
+ */
49
+ import { Node, SyntaxKind, VariableDeclarationKind, } from 'ts-morph';
50
+ import { carryKey, readField, readFieldSet } from './field-projection.js';
51
+ import { asObjectLiteral, excerpt, holdsNothing, namedMember, propertyKey, SPREADS_NOTHING, setsPrototype, spendWork, unwrapExpression, writtenValue, } from './literal.js';
52
+ import { lookUpKey, resolveLiteralValue, resolveLiteralValueReading, resolveObjectLiteral, } from './resolve-reference.js';
53
+ /** The component keys this reader takes a value from, as opposed to the behaviour markers. */
54
+ const DATA_KEYS = new Set(['label', 'fields', 'defaultProps', 'ai']);
55
+ /**
56
+ * Config keys whose value is a function encoding behaviour we cannot read.
57
+ * Each becomes a marker so the agent knows the description is incomplete HERE
58
+ * rather than assuming it is complete everywhere.
59
+ *
60
+ * A Map rather than an object literal: a plain object answers for `toString`
61
+ * and `constructor` as readily as for the three keys written here, so a
62
+ * component carrying either name would be handed the prototype's value and
63
+ * write a marker named `undefined` onto the manifest.
64
+ *
65
+ * A computed key this reader cannot name may be any of the three, setting a
66
+ * behaviour or erasing one, so it takes each marker with it and lists the key
67
+ * in `unreadableKeys` — whether the marker applies cannot be read. A later
68
+ * write of the key, spelled out, settles it again.
69
+ */
70
+ const BEHAVIOUR_MARKERS = new Map([
71
+ ['resolveFields', 'dynamicFields'],
72
+ ['resolveData', 'derivedProps'],
73
+ ['resolvePermissions', 'hasPlacementRules'],
74
+ ]);
75
+ /**
76
+ * Same cap, and the same reason, as the walk in `resolve-reference`: the alias
77
+ * chain being followed comes from someone else's source, so the walk stops on
78
+ * its own terms rather than on the compiler's.
79
+ */
80
+ const MAX_ALIAS_HOPS = 5;
81
+ /**
82
+ * How far a chain of spreads or member accesses may be followed.
83
+ *
84
+ * It bounds depth, not total work: a wide object with fifty spreads side by
85
+ * side is read in full, and only a chain that keeps descending is stopped. A
86
+ * spread that leads back to where it started — `const A = { ...B }` beside
87
+ * `const B = { ...A }` — is source that could not have loaded at runtime
88
+ * either, and following it forever takes the caller down with it rather than
89
+ * reporting anything. Set well past what any config written on purpose
90
+ * reaches, so the cap only ever catches a cycle.
91
+ */
92
+ const MAX_SPREAD_DEPTH = 16;
93
+ /**
94
+ * A refusal is thrown rather than returned so that a rule broken six calls deep
95
+ * — an unresolvable spread inside a nested object — reaches the caller with its
96
+ * own reason instead of arriving as a bare `undefined` that says nothing.
97
+ */
98
+ class Refusal extends Error {
99
+ }
100
+ function refuse(why) {
101
+ throw new Refusal(why);
102
+ }
103
+ /**
104
+ * What a cap says when it is reached. It reports how far the walk went rather
105
+ * than accusing the config of a cycle outright: a chain this long is almost
106
+ * always one, but "stopped after 16" is what was actually observed.
107
+ */
108
+ function capped(what) {
109
+ return refuse(`followed ${what} ${MAX_SPREAD_DEPTH} deep and stopped (usually a cycle: an object that spreads or names itself)`);
110
+ }
111
+ /**
112
+ * The manifest component a `wrapper(inner)` call amounts to.
113
+ *
114
+ * Both of our own sites build their layout primitives this way, and those are
115
+ * exactly the components carrying the slot nesting rules an agent needs, so a
116
+ * reader that stops at the call reports the most structural components on the
117
+ * site as unknown.
118
+ */
119
+ export function readWrapperCall(call) {
120
+ const { reading, reason } = readWrapperCallReading(call);
121
+ return reading ? { component: reading.component } : { reason };
122
+ }
123
+ /**
124
+ * The same reading, kept whole for a caller that MERGES it — `Grid: { ...Grid,
125
+ * label: … }`, where the spread source is a wrapper call.
126
+ *
127
+ * A merge needs more than the component: a key the source wrote in a shape this
128
+ * reader could not take has to overwrite what sits beside it, and only the
129
+ * reading knows which keys were written.
130
+ */
131
+ export function readWrapperCallReading(call) {
132
+ const { read, reason } = caught(() => readCall(call));
133
+ return read ? { reading: read } : { reason };
134
+ }
135
+ /**
136
+ * The manifest field a field-builder call such as `ctaButtonArrayField()`
137
+ * amounts to.
138
+ *
139
+ * A site may declare many of its fields by calling a helper like this one, and
140
+ * a reader that stops at the call reports every one of them as a prop with no
141
+ * shape at all — no type, no bounds, no item fields — which is the difference
142
+ * between an agent that can fill a button array in and one that can only guess
143
+ * at it. The call is the same summarizable shape a wrapper is, so it is read
144
+ * with the same machinery; only the returned literal is read as a field.
145
+ *
146
+ * The depth is how far into a field set the call already sits, so a builder
147
+ * reached from inside another builder's item fields cannot restart the cap that
148
+ * stops a cycle.
149
+ */
150
+ export function readFieldBuilderCall(call, depth = 0) {
151
+ const { read, reason } = caught(() => readBuilderCall(call, depth));
152
+ return read ? { field: read } : { reason };
153
+ }
154
+ /**
155
+ * The component a written-down literal amounts to, with everything it spreads
156
+ * over applied — `const X = { ...Base }`, where Base spreads something of its
157
+ * own.
158
+ *
159
+ * This is how the config reader reads every component entry, written in place or
160
+ * reached by name: reading one with a spread-blind reader answers "accepts
161
+ * nothing" with no marker to say the spread was skipped. Nothing is bound — a
162
+ * literal reached by name has no wrapper parameters in scope — so a caller that
163
+ * can follow a spread this walker cannot, to a wrapper CALL rather than a
164
+ * literal, hands that in.
165
+ */
166
+ export function readComponentWithSpreads(literal, spreads) {
167
+ const { read, reason } = caught(() => readLiteral(literal, new Map(), 0, spreads));
168
+ return read ? { component: read.component } : { reason };
169
+ }
170
+ /**
171
+ * Whether a call reaches a function the source declares — the one kind of call
172
+ * read as a wrapper. A `let` or `var` counts too: the wrapper is written in the
173
+ * config even though its body is not trusted, and its own refusal says why. A
174
+ * call to anything else is a value this reader cannot follow, not a wrapper it
175
+ * refused.
176
+ */
177
+ export function callsDeclaredFunction(call) {
178
+ const { read, reason } = caught(() => calleeDeclaration(call));
179
+ return read !== undefined || reason === DECLARED_WITH_LET_OR_VAR;
180
+ }
181
+ /** Why a call is refused whose function is declared, but with `let` or `var`. */
182
+ const DECLARED_WITH_LET_OR_VAR = 'the function called is declared with let or var, so what it holds when the call runs may not be the function written there';
183
+ /** Turns a refusal thrown deep in a reading into the reason it carries; anything else is a real bug. */
184
+ function caught(read) {
185
+ try {
186
+ return { read: read() };
187
+ }
188
+ catch (error) {
189
+ if (error instanceof Refusal)
190
+ return { reason: error.message };
191
+ throw error;
192
+ }
193
+ }
194
+ /** The reading itself, which refuses by throwing so every rule reports its own reason. */
195
+ function readCall(call) {
196
+ const literals = callArgumentLiterals(call);
197
+ const fn = calleeDeclaration(call);
198
+ const parameters = calleeParameters(fn);
199
+ // A wrapper with nothing to wrap builds its component out of code rather than
200
+ // out of an argument, which is not the shape this reader can see through.
201
+ if (parameters.length === 0)
202
+ refuse('the wrapper takes no parameters, so it builds its component from code rather than from what the call passes');
203
+ // Every parameter must be bound by an argument this reader could resolve. An
204
+ // unbound one is a value the wrapper reads and this reader cannot see, and a
205
+ // body that consults it would be summarized with that branch silently
206
+ // missing — the one wrong answer the probe caught in the wild.
207
+ if (parameters.length !== literals.length) {
208
+ refuse(`the wrapper takes ${parameters.length} parameters but the call passes ${literals.length}`);
209
+ }
210
+ const environment = new Map();
211
+ parameters.forEach((declaration, index) => {
212
+ const literal = literals[index];
213
+ if (literal)
214
+ environment.set(declaration.getName(), { declaration, literal });
215
+ });
216
+ return readLiteral(returnedLiteral(fn, environment, 'component'), environment, 0);
217
+ }
218
+ /**
219
+ * The field a builder call declares, refusing by throwing so every rule reports
220
+ * its own reason.
221
+ *
222
+ * A builder is called for its whole answer rather than to decorate an argument,
223
+ * so — unlike a wrapper — it may take nothing at all, and an argument the call
224
+ * omits is bound rather than refused.
225
+ */
226
+ function readBuilderCall(call, depth) {
227
+ const fn = calleeDeclaration(call);
228
+ const parameters = calleeParameters(fn);
229
+ const environment = bindArguments(parameters, call.getArguments().map(argumentBinding));
230
+ return readFieldWithEnv(returnedLiteral(fn, environment, 'field'), environment, depth);
231
+ }
232
+ /**
233
+ * The literal each argument names, in order. A value that is not an object is
234
+ * refused here: a wrapper is handed a component, and a body spreading anything
235
+ * else produces nothing a component could be read out of.
236
+ */
237
+ function callArgumentLiterals(call) {
238
+ const args = call.getArguments();
239
+ if (args.length === 0)
240
+ refuse('the call passes no arguments, so there is no component for the wrapper to build on');
241
+ return args.map((argument) => {
242
+ const binding = argumentBinding(argument);
243
+ if (binding.literal)
244
+ return binding.literal;
245
+ return refuse(`the call passes ${excerpt(unwrapExpression(argument).getText())}, which is not an object written out in the source or a name for one`);
246
+ });
247
+ }
248
+ /**
249
+ * What one argument binds: the object literal it names, or the plain value it
250
+ * writes down.
251
+ *
252
+ * A nested call is refused rather than followed. A parameter is bound to a
253
+ * literal, and substituting an inner wrapper's returned literal rebinds the
254
+ * parameter to a body that spreads that same parameter, so the merge never
255
+ * terminates. Binding it to the inner call's READING instead — the way the
256
+ * config merges a wrapper-built component it spreads — is not done here.
257
+ */
258
+ function argumentBinding(argument) {
259
+ const expression = unwrapExpression(argument);
260
+ const literal = resolveObjectLiteral(expression);
261
+ if (literal)
262
+ return { literal };
263
+ const value = resolveLiteralValue(expression);
264
+ if (value !== undefined)
265
+ return { value };
266
+ if (expression.isKind(SyntaxKind.CallExpression)) {
267
+ refuse(`the call passes another call's result, ${excerpt(expression.getText())}, which this reader would have to run to know`);
268
+ }
269
+ return refuse(`the call passes ${excerpt(expression.getText())}, which is neither a value written out in the source nor a name for one`);
270
+ }
271
+ /**
272
+ * The function's parameters, bound to what the call passes for each.
273
+ *
274
+ * An argument the call omits binds undefined, which is a fact rather than a
275
+ * guess — and the shape a field builder's plain call takes, with nothing
276
+ * passed: `{ ...overrides }` spreads nothing. A key read off the omitted
277
+ * argument is another matter: `overrides?.max` is undefined at runtime, while
278
+ * `overrides.max` throws before the builder returns, and this reader tells
279
+ * neither apart from a value it cannot see — the key is left unread and
280
+ * admitted. A parameter carrying a DEFAULT is the opposite of an omitted
281
+ * one, the default being an expression this reader would have to evaluate to
282
+ * know what was bound, so it is refused with every other shape whose bound
283
+ * value cannot be seen.
284
+ */
285
+ function bindArguments(parameters, args) {
286
+ if (args.length > parameters.length) {
287
+ refuse(`the function takes ${parameters.length} parameters but the call passes ${args.length}`);
288
+ }
289
+ const environment = new Map();
290
+ parameters.forEach((declaration, index) => {
291
+ const argument = args[index];
292
+ if (!argument && declaration.hasInitializer()) {
293
+ refuse('the call leaves out an argument whose parameter has a default value, which this reader would have to run code to work out');
294
+ }
295
+ environment.set(declaration.getName(), { declaration, ...(argument ?? {}) });
296
+ });
297
+ return environment;
298
+ }
299
+ /** The declaration a callee identifier names, refusing anything that is not a function written down as a const. */
300
+ function calleeDeclaration(call) {
301
+ const identifier = unwrapExpression(call.getExpression()).asKind(SyntaxKind.Identifier);
302
+ if (!identifier)
303
+ refuse('the call is not to a function named directly, so which function runs cannot be read');
304
+ let symbol = identifier.getSymbol();
305
+ // An overloaded wrapper declares its signatures first and its body last, and
306
+ // a signature says nothing at all about what the call returns.
307
+ let signatureOnly;
308
+ for (let hop = 0; symbol && hop < MAX_ALIAS_HOPS; hop++) {
309
+ for (const declaration of symbol.getDeclarations()) {
310
+ if (Node.isFunctionDeclaration(declaration)) {
311
+ if (declaration.getBody())
312
+ return declaration;
313
+ signatureOnly ??= declaration;
314
+ continue;
315
+ }
316
+ if (!Node.isVariableDeclaration(declaration))
317
+ continue;
318
+ // Only `const` is trusted, for the reason `resolve-reference` trusts only
319
+ // `const`: a let or var holds whatever was assigned to it last, which is
320
+ // code this reader never sees.
321
+ if (declaration.getVariableStatement()?.getDeclarationKind() !== VariableDeclarationKind.Const) {
322
+ refuse(DECLARED_WITH_LET_OR_VAR);
323
+ }
324
+ const initializer = declaration.getInitializer();
325
+ const written = initializer && unwrapExpression(initializer);
326
+ if (written && (Node.isArrowFunction(written) || Node.isFunctionExpression(written)))
327
+ return written;
328
+ }
329
+ symbol = symbol.getAliasedSymbol();
330
+ }
331
+ if (signatureOnly)
332
+ return signatureOnly;
333
+ return refuse('the function called is not declared anywhere this reader can see');
334
+ }
335
+ /**
336
+ * The single object literal the callee's body returns — `what` naming the thing
337
+ * the call was read for, so a refusal says what the caller did not get.
338
+ *
339
+ * Exactly one statement, exactly one return: a body doing anything else is
340
+ * computing part of its answer, and the part this reader can see would be
341
+ * reported as the whole.
342
+ */
343
+ function returnedLiteral(fn, environment, what) {
344
+ // An async or generator callee hands back a promise or an iterator. Whatever
345
+ // its body returns, the value the config binds is not the thing being read.
346
+ if (fn.isAsync())
347
+ refuse(`the function is async, so the call returns a promise rather than a ${what}`);
348
+ if (!Node.isArrowFunction(fn) && fn.isGenerator()) {
349
+ refuse(`the function is a generator, so the call returns an iterator rather than a ${what}`);
350
+ }
351
+ const body = fn.getBody();
352
+ if (!body)
353
+ refuse('the function has no body to read');
354
+ // Concise arrow: `config => ({ … })`, or `config => config`, where the return
355
+ // is the body itself.
356
+ const concise = asObjectLiteral(body);
357
+ if (concise)
358
+ return concise;
359
+ if (!Node.isBlock(body))
360
+ return passthroughLiteral(body, environment);
361
+ const statements = body.getStatements();
362
+ if (statements.length !== 1)
363
+ refuse(`the function's body has ${statements.length} statements, and only a body that is a single return can be read without running it`);
364
+ const returned = statements[0]?.asKind(SyntaxKind.ReturnStatement);
365
+ if (!returned)
366
+ refuse("the only statement in the function's body is not a return");
367
+ const expression = returned.getExpression();
368
+ if (!expression)
369
+ refuse('the function returns nothing');
370
+ return asObjectLiteral(expression) ?? passthroughLiteral(expression, environment);
371
+ }
372
+ /**
373
+ * `return config;` — a wrapper that only registers or annotates its argument,
374
+ * which reads as the argument itself. Written in both shapes a body can take,
375
+ * so `(config) => config` is the same wrapper as its block-bodied twin.
376
+ */
377
+ function passthroughLiteral(expression, environment) {
378
+ const identifier = unwrapExpression(expression).asKind(SyntaxKind.Identifier);
379
+ const bound = identifier && boundLiteral(identifier, environment);
380
+ if (bound)
381
+ return bound;
382
+ return refuse('the function returns something other than an object written out in its body or the argument it was passed');
383
+ }
384
+ /** The parameters the callee binds, refusing every shape whose runtime value is not the argument itself. */
385
+ function calleeParameters(fn) {
386
+ const parameters = fn.getParameters();
387
+ for (const parameter of parameters) {
388
+ // `function w(...config)` binds an ARRAY of the arguments, and
389
+ // `(config, extra)` with a rest tail swallows the remainder into one. The
390
+ // shape the body then spreads is not the shape this reader would
391
+ // substitute, and the count check would not catch the difference.
392
+ if (parameter.isRestParameter()) {
393
+ refuse('the function takes a rest parameter, which gathers the arguments into an array rather than binding each one');
394
+ }
395
+ // `function withPick({ label, fields })` binds names this reader would have
396
+ // to model a destructuring for; the argument's own keys are not what the
397
+ // body reads.
398
+ if (!Node.isIdentifier(parameter.getNameNode()))
399
+ refuse('a parameter of the function is destructured, which this reader does not follow');
400
+ }
401
+ return parameters;
402
+ }
403
+ /**
404
+ * The binding a name stands for in THIS call, and nothing else.
405
+ *
406
+ * The symbol check is the whole point. An identifier that merely shares a name
407
+ * with a parameter — a module-level `const config` in the file a spread leads
408
+ * into — resolves to its own declaration, because handing it the wrapper's
409
+ * argument invents a field set out of the argument's own top-level keys.
410
+ */
411
+ function boundBinding(identifier, environment) {
412
+ const binding = environment.get(identifier.getText());
413
+ if (!binding)
414
+ return undefined;
415
+ // The name of a shorthand — `{ label }` — is a property as far as the
416
+ // checker is concerned; the value it stands for is a symbol of its own.
417
+ const shorthand = identifier.getParentIfKind(SyntaxKind.ShorthandPropertyAssignment);
418
+ const symbol = shorthand?.getNameNode() === identifier ? shorthand.getValueSymbol() : identifier.getSymbol();
419
+ return symbol?.getDeclarations().includes(binding.declaration) ? binding : undefined;
420
+ }
421
+ /** The literal bound to a parameter of this call, where the argument named one. */
422
+ function boundLiteral(identifier, environment) {
423
+ return boundBinding(identifier, environment)?.literal;
424
+ }
425
+ function readLiteral(literal, environment, depth, spreads) {
426
+ if (depth > MAX_SPREAD_DEPTH)
427
+ capped('a chain of component spreads');
428
+ const component = { fields: {} };
429
+ const written = new Set();
430
+ for (const property of literal.getProperties()) {
431
+ spendWork();
432
+ const spread = property.asKind(SyntaxKind.SpreadAssignment);
433
+ if (spread) {
434
+ const source = resolveInEnv(spread.getExpression(), environment);
435
+ const base = source ? readLiteral(source, environment, depth + 1, spreads) : spreadReading(spread, spreads);
436
+ applyComponentReading(component, base);
437
+ for (const key of base.written)
438
+ written.add(key);
439
+ continue;
440
+ }
441
+ const member = namedMember(property);
442
+ if (!member)
443
+ continue;
444
+ const name = propertyKey(member);
445
+ if (name === undefined) {
446
+ // A computed key — `[k]: value` — writes a name this reader cannot read,
447
+ // and it may be any key read here. Leaving the earlier readings standing
448
+ // would report a label or a field set the runtime has already
449
+ // overwritten, or behaviour it has written or erased, so every one goes
450
+ // and each is admitted.
451
+ for (const key of DATA_KEYS) {
452
+ clearComponentMember(component, key);
453
+ written.add(key);
454
+ }
455
+ for (const [key, marker] of BEHAVIOUR_MARKERS) {
456
+ delete component[marker];
457
+ admitKey(component, key, true);
458
+ written.add(key);
459
+ }
460
+ continue;
461
+ }
462
+ // Puck reads `fields`, `label` and every behaviour key through the
463
+ // prototype, and nothing a prototype carries is written here to be read.
464
+ if (setsPrototype(member))
465
+ refuse('the component sets its prototype with __proto__, so what it inherits cannot be read');
466
+ const marker = BEHAVIOUR_MARKERS.get(name);
467
+ if (marker) {
468
+ // The last write decides, as for every key: `undefined` or `null`
469
+ // written after a spread leaves Puck nothing to run, and anything else —
470
+ // a write this reader cannot see through included — may be code. Either
471
+ // way the key is spelled out, which settles an earlier admission.
472
+ written.add(name);
473
+ if (writesNothing(member))
474
+ delete component[marker];
475
+ else
476
+ component[marker] = true;
477
+ admitKey(component, name, false);
478
+ continue;
479
+ }
480
+ if (!DATA_KEYS.has(name))
481
+ continue;
482
+ written.add(name);
483
+ // A shorthand names its value and is followed like the name written out.
484
+ // A method or a getter carries no value this reader can take — and at
485
+ // runtime it still overwrites whatever a spread above it put there, so the
486
+ // earlier reading has to go with it.
487
+ const value = writtenValue(member);
488
+ if (value)
489
+ readComponentMember(component, name, value, environment);
490
+ else
491
+ clearComponentMember(component, name);
492
+ }
493
+ return { component, written };
494
+ }
495
+ /**
496
+ * `resolveData: undefined`, `resolveFields: void 0`, `{ resolvePermissions }`
497
+ * beside a `const` bound to `null` — a behaviour key that provably holds no
498
+ * function, and so marks nothing. A getter or method stays marked: its body is
499
+ * never run, so what it returns is not known.
500
+ */
501
+ function writesNothing(member) {
502
+ const value = writtenValue(member);
503
+ return value !== undefined && holdsNothing(value);
504
+ }
505
+ /** The reading a spread source amounts to when it is no literal this walker can reach. */
506
+ function spreadReading(spread, spreads) {
507
+ const { reading, reason } = spreads?.(spread.getExpression()) ?? {};
508
+ if (reading)
509
+ return reading;
510
+ return refuse(reason ??
511
+ `the component spreads ${excerpt(spread.getText())}, which this reader cannot follow to an object written in the source`);
512
+ }
513
+ /**
514
+ * Applies one reading over another at the position its spread sits — the
515
+ * runtime's own rule, every key the source writes winning over what was read
516
+ * above it, together with the admission the source made for it. A behaviour
517
+ * key follows the same rule: the source's write of it decides whether there is
518
+ * code for Puck to run.
519
+ */
520
+ function applyComponentReading(component, base) {
521
+ for (const name of base.written) {
522
+ const marker = BEHAVIOUR_MARKERS.get(name);
523
+ if (marker) {
524
+ if (base.component[marker])
525
+ component[marker] = true;
526
+ else
527
+ delete component[marker];
528
+ admitKey(component, name, isAdmitted(base.component, name));
529
+ continue;
530
+ }
531
+ if (name === 'fields') {
532
+ component.fields = base.component.fields;
533
+ if (base.component.fieldsUnreadable)
534
+ component.fieldsUnreadable = true;
535
+ else
536
+ delete component.fieldsUnreadable;
537
+ continue;
538
+ }
539
+ if (isValueKey(name)) {
540
+ carryKey(component, base.component, name);
541
+ admitKey(component, name, isAdmitted(base.component, name));
542
+ }
543
+ }
544
+ }
545
+ /** The keys `unreadableKeys` can name, in the order it lists them. */
546
+ const ADMITTABLE_KEYS = [
547
+ 'label',
548
+ 'defaultProps',
549
+ 'ai',
550
+ 'resolveFields',
551
+ 'resolveData',
552
+ 'resolvePermissions',
553
+ ];
554
+ /** Whether a reading lists a key in `unreadableKeys`. */
555
+ function isAdmitted(component, key) {
556
+ return component.unreadableKeys?.some((admitted) => admitted === key) ?? false;
557
+ }
558
+ function isValueKey(name) {
559
+ return name === 'label' || name === 'defaultProps' || name === 'ai';
560
+ }
561
+ /**
562
+ * Records whether a key's last write went unread. The admission follows the
563
+ * value's own rule — a later readable write settles it, a later unreadable one
564
+ * raises it again — and the list goes with its last entry, so a component read
565
+ * whole carries no empty `unreadableKeys`.
566
+ */
567
+ function admitKey(component, key, unread) {
568
+ const keys = new Set(component.unreadableKeys);
569
+ if (unread)
570
+ keys.add(key);
571
+ else
572
+ keys.delete(key);
573
+ const listed = ADMITTABLE_KEYS.filter((admitted) => keys.has(admitted));
574
+ if (listed.length > 0)
575
+ component.unreadableKeys = listed;
576
+ else
577
+ delete component.unreadableKeys;
578
+ }
579
+ /** One `label` / `fields` / `defaultProps` / `ai` entry of a component, read with the call's parameters in scope. */
580
+ function readComponentMember(component, name, initializer, environment) {
581
+ switch (name) {
582
+ case 'label': {
583
+ // `label: SHARED_LABEL` is the sidebar name written one line up rather
584
+ // than in place; a reader that stops at the name leaves the component
585
+ // nameless in the manifest.
586
+ // The argument first: `config.label` names what the call passed, and a
587
+ // name typed after another const must not be read as that const.
588
+ const value = boundValue(initializer, environment) ?? resolveLiteralValue(initializer);
589
+ if (typeof value === 'string') {
590
+ component.label = value;
591
+ admitKey(component, name, false);
592
+ }
593
+ else
594
+ clearComponentMember(component, name);
595
+ return;
596
+ }
597
+ case 'fields': {
598
+ // A wrapper that maps over the field set — `Object.fromEntries(…)` — is
599
+ // still worth reading for everything else it says, so this is an
600
+ // admission rather than a refusal.
601
+ const set = readFieldSet(initializer, 0, boundSources(environment));
602
+ if (!set)
603
+ clearComponentMember(component, name);
604
+ else {
605
+ component.fields = set.fields;
606
+ if (set.unreadable)
607
+ component.fieldsUnreadable = true;
608
+ else
609
+ delete component.fieldsUnreadable;
610
+ }
611
+ return;
612
+ }
613
+ case 'defaultProps':
614
+ case 'ai': {
615
+ // Read with the argument in scope: `ai: { hint: config.label }` reads the
616
+ // label the argument declares, or admits it is unknown — never empty as
617
+ // fact. What did read is kept, and the admission says it is not the
618
+ // whole of it. A reading with a gap and nothing else is no reading: an
619
+ // empty object beside the admission would pass for one written empty.
620
+ const reading = readValueObject(initializer, environment);
621
+ if (!reading || (reading.dropped && Object.keys(reading.value).length === 0)) {
622
+ clearComponentMember(component, name);
623
+ }
624
+ else {
625
+ if (name === 'ai')
626
+ component.ai = reading.value;
627
+ else
628
+ component.defaultProps = reading.value;
629
+ admitKey(component, name, reading.dropped);
630
+ }
631
+ return;
632
+ }
633
+ }
634
+ }
635
+ /**
636
+ * A write this reader cannot see through. The last write wins at runtime, so
637
+ * whatever a spread put there earlier has to go with it rather than stand as a
638
+ * stale value — `{ ...config, label: makeLabel() }` is not the argument's label
639
+ * — and the key is admitted, so its absence is not read as "none".
640
+ */
641
+ function clearComponentMember(component, name) {
642
+ if (name === 'fields') {
643
+ component.fields = {};
644
+ component.fieldsUnreadable = true;
645
+ return;
646
+ }
647
+ if (!isValueKey(name))
648
+ return;
649
+ delete component[name];
650
+ admitKey(component, name, true);
651
+ }
652
+ /**
653
+ * The literal a field builder returns, read as a field with the call's
654
+ * arguments in scope.
655
+ *
656
+ * `readField` walks the literal in source order and follows a name to the
657
+ * `const` it stands for; what it cannot see on its own is the CALL — a
658
+ * parameter is bound by the caller rather than written down, so `label: label`
659
+ * and `{ ...overrides }` mean nothing to it. Both are handed over here, and a
660
+ * spread of an argument then merges where it is written, exactly as at runtime:
661
+ * reporting `max: 4` where `ctaButtonArrayField({ max: 2 })` overrides it is
662
+ * the confident wrong answer this module exists to avoid.
663
+ *
664
+ * A spread that leads nowhere at all — anywhere in the field, nested field sets
665
+ * included — is still refused rather than admitted. The caller of a builder has
666
+ * a reason to hand back, and "could not read, because X" beats a field claiming
667
+ * bounds that something invisible may have replaced.
668
+ */
669
+ function readFieldWithEnv(literal, environment, depth) {
670
+ return readField(literal, depth, boundSources(environment, (expression) => refuse(`the field spreads ${excerpt(expression.getText())}, which this reader cannot follow and which may overwrite what is beside it`)));
671
+ }
672
+ /**
673
+ * Where spreads and names lead with a call's parameters in scope: `...config`
674
+ * reaches the argument, `config.fields` the key it declares, and `...config.x`
675
+ * where the argument provably declares no `x` spreads nothing. A spread that
676
+ * leads nowhere is handed to `lost`, whose undefined the field and field-set
677
+ * readers admit — unless the caller would rather refuse.
678
+ */
679
+ function boundSources(environment, lost = () => undefined) {
680
+ return {
681
+ builder: readFieldBuilderCall,
682
+ spread: (expression) => spreadsNothing(expression, environment)
683
+ ? SPREADS_NOTHING
684
+ : (resolveInEnv(expression, environment) ?? lost(expression)),
685
+ bound: (node) => boundValue(node, environment),
686
+ object: (expression) => resolveInEnv(expression, environment),
687
+ };
688
+ }
689
+ /**
690
+ * A value the call binds: a parameter named directly (`label: label`) or a key
691
+ * read out of one (`opts.label`), a name the argument writes for it followed to
692
+ * its `const`. Undefined for anything that does not start at a parameter of
693
+ * this call: a module const is the source's own, and read as such.
694
+ */
695
+ function boundValue(node, environment) {
696
+ const expression = unwrapExpression(node);
697
+ const identifier = expression.asKind(SyntaxKind.Identifier);
698
+ if (identifier)
699
+ return boundBinding(identifier, environment)?.value;
700
+ if (!Node.isPropertyAccessExpression(expression) || !startsAtParameter(expression, environment))
701
+ return undefined;
702
+ const target = resolveInEnv(expression.getExpression(), environment);
703
+ const found = target && lookUpInEnv(target, expression.getName(), environment);
704
+ return found && typeof found !== 'string' ? resolveLiteralValue(found) : undefined;
705
+ }
706
+ /** Whether a chain of key reads — `opts.a.b` — starts at a parameter this call binds. */
707
+ function startsAtParameter(expression, environment) {
708
+ let root = unwrapExpression(expression);
709
+ while (Node.isPropertyAccessExpression(root))
710
+ root = unwrapExpression(root.getExpression());
711
+ const identifier = root.asKind(SyntaxKind.Identifier);
712
+ return identifier !== undefined && boundBinding(identifier, environment) !== undefined;
713
+ }
714
+ /**
715
+ * Whether a spread provably carries nothing: the call omitted the argument it
716
+ * spreads, or it reaches a key the bound argument was shown not to declare.
717
+ */
718
+ function spreadsNothing(node, environment) {
719
+ const identifier = unwrapExpression(node).asKind(SyntaxKind.Identifier);
720
+ if (identifier) {
721
+ const binding = boundBinding(identifier, environment);
722
+ return binding !== undefined && binding.literal === undefined && binding.value === undefined;
723
+ }
724
+ return isAbsentKeyAccess(node, environment);
725
+ }
726
+ /**
727
+ * `defaultProps` and `ai`, and the plain objects inside them: read in source
728
+ * order with spreads resolved against the call's parameters, so `{
729
+ * ...config.defaultProps, layout: … }` means what it means at runtime.
730
+ *
731
+ * Never all-or-nothing. An entry whose value cannot be read is left out; a
732
+ * spread leading nowhere, or a key this reader cannot name, takes the entries
733
+ * before it; `__proto__` hides what the object inherits. Each marks the
734
+ * reading `dropped`, so the owner admits it instead of presenting the rest as
735
+ * the whole. Undefined only where the object itself cannot be reached.
736
+ */
737
+ function readValueObject(node, environment, depth = 0) {
738
+ if (depth > MAX_SPREAD_DEPTH)
739
+ capped('a chain of spreads in defaultProps or ai');
740
+ const literal = resolveInEnv(node, environment);
741
+ if (!literal)
742
+ return undefined;
743
+ const walk = { value: {}, dropped: false, written: new Set(), lost: false };
744
+ for (const property of literal.getProperties()) {
745
+ spendWork();
746
+ const spread = property.asKind(SyntaxKind.SpreadAssignment);
747
+ if (spread) {
748
+ // `{ ...config.defaultProps }` where the argument declares none is an
749
+ // empty spread at runtime, not a value this reader failed to follow.
750
+ if (spreadsNothing(spread.getExpression(), environment))
751
+ continue;
752
+ const base = readValueObject(spread.getExpression(), environment, depth + 1);
753
+ if (base)
754
+ applyValueWalk(walk, base);
755
+ else
756
+ loseEveryKey(walk);
757
+ continue;
758
+ }
759
+ const member = namedMember(property);
760
+ const key = member && propertyKey(member);
761
+ if (!member || key === undefined) {
762
+ loseEveryKey(walk);
763
+ continue;
764
+ }
765
+ // Never written into a record of ours — assigning it replaces the record's
766
+ // prototype — and, written as one, it hides every key the object inherits.
767
+ if (key === '__proto__') {
768
+ walk.dropped = true;
769
+ continue;
770
+ }
771
+ walk.written.add(key);
772
+ const initializer = writtenValue(member);
773
+ const value = initializer && readValueEntry(initializer, environment, depth, walk);
774
+ if (value === undefined) {
775
+ // The last write wins at runtime, so a key set in a shape this reader
776
+ // cannot read takes the earlier value with it.
777
+ delete walk.value[key];
778
+ walk.dropped = true;
779
+ }
780
+ else
781
+ walk.value[key] = value;
782
+ }
783
+ return walk;
784
+ }
785
+ /** One entry of a plain-data object, dropped marks carried up to the object holding it. */
786
+ function readValueEntry(node, environment, depth, walk) {
787
+ const expression = unwrapExpression(node);
788
+ const array = expression.asKind(SyntaxKind.ArrayLiteralExpression);
789
+ if (array) {
790
+ const values = [];
791
+ for (const element of array.getElements()) {
792
+ spendWork();
793
+ // A missing element would shift every later index, so the whole array
794
+ // is unknown rather than partially wrong.
795
+ const value = readValueEntry(element, environment, depth, walk);
796
+ if (value === undefined)
797
+ return undefined;
798
+ values.push(value);
799
+ }
800
+ return values;
801
+ }
802
+ const object = resolveInEnv(expression, environment);
803
+ if (object) {
804
+ // A literal written inside this one walks strictly downward and cannot
805
+ // cycle, so it costs no depth — but it carries the count, because a cycle
806
+ // reached through it would otherwise start over on every lap. A name for
807
+ // one may lead back, and costs a level.
808
+ const nested = readValueObject(object, environment, asObjectLiteral(expression) ? depth : depth + 1);
809
+ if (nested?.dropped)
810
+ walk.dropped = true;
811
+ return nested?.value;
812
+ }
813
+ const bound = boundValue(expression, environment);
814
+ if (bound !== undefined)
815
+ return bound;
816
+ // `items: ITEMS` names an array whose parts may be computed — an item's `id:
817
+ // defaultId()` — and the part that read is kept and admitted, exactly as the
818
+ // same array written in place is.
819
+ const reading = resolveLiteralValueReading(expression);
820
+ if (reading?.dropped)
821
+ walk.dropped = true;
822
+ return reading?.value;
823
+ }
824
+ /** Applies a spread source's reading at the position the spread sits, as `applyComponentReading` does for components. */
825
+ function applyValueWalk(walk, base) {
826
+ if (base.lost) {
827
+ walk.value = {};
828
+ walk.lost = true;
829
+ }
830
+ for (const key of base.written) {
831
+ walk.written.add(key);
832
+ // biome-ignore lint/suspicious/noPrototypeBuiltins: astro-cms compiles against ES2020, where Object.hasOwn does not exist
833
+ if (Object.prototype.hasOwnProperty.call(base.value, key))
834
+ walk.value[key] = base.value[key];
835
+ else
836
+ delete walk.value[key];
837
+ }
838
+ if (base.dropped)
839
+ walk.dropped = true;
840
+ }
841
+ /** A write this reader cannot name, which may be any key — so every one read before it goes. */
842
+ function loseEveryKey(walk) {
843
+ walk.value = {};
844
+ walk.lost = true;
845
+ walk.dropped = true;
846
+ }
847
+ /**
848
+ * The object literal an expression names, with the wrapper's parameters and
849
+ * their subobjects in scope: `config`, `config.fields`, `config.defaultProps`.
850
+ */
851
+ function resolveInEnv(node, environment, depth = 0) {
852
+ if (depth > MAX_SPREAD_DEPTH)
853
+ capped('a chain of property reads like `a.b.c`');
854
+ const expression = unwrapExpression(node);
855
+ const identifier = expression.asKind(SyntaxKind.Identifier);
856
+ if (identifier)
857
+ return boundLiteral(identifier, environment) ?? resolveObjectLiteral(expression);
858
+ if (Node.isPropertyAccessExpression(expression)) {
859
+ const target = resolveInEnv(expression.getExpression(), environment, depth + 1);
860
+ if (!target)
861
+ return undefined;
862
+ const found = lookUpInEnv(target, expression.getName(), environment);
863
+ return typeof found === 'string' ? undefined : resolveObjectLiteral(found);
864
+ }
865
+ return resolveObjectLiteral(expression);
866
+ }
867
+ /**
868
+ * What an object literal assigns to one key — `lookUpKey`'s rules, with its
869
+ * spreads reaching what this call binds. A key an argument inherits through a
870
+ * spread is a key it has; one a getter, a computed name it cannot resolve, or
871
+ * a prototype may supply is unknown rather than absent.
872
+ */
873
+ function lookUpInEnv(literal, name, environment) {
874
+ return lookUpKey(literal, name, (expression) => resolveInEnv(expression, environment));
875
+ }
876
+ /**
877
+ * Whether a member access reaches a key the object was shown not to declare —
878
+ * the one case `{ ...config.defaultProps }` may be read as an empty spread.
879
+ * Anything less certain answers false: a spread this reader could not open may
880
+ * well declare the key.
881
+ */
882
+ function isAbsentKeyAccess(node, environment) {
883
+ const expression = unwrapExpression(node);
884
+ if (!Node.isPropertyAccessExpression(expression))
885
+ return false;
886
+ const target = resolveInEnv(expression.getExpression(), environment);
887
+ return target !== undefined && lookUpInEnv(target, expression.getName(), environment) === 'absent';
888
+ }
889
+ //# sourceMappingURL=read-wrapper.js.map