@conloca/astro-cms 0.1.15 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/README.md +259 -247
  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/ts/src/cms-handler.d.ts +18 -0
  21. package/dist/ts/src/cms-handler.d.ts.map +1 -0
  22. package/dist/ts/src/cms-handler.js +245 -0
  23. package/dist/ts/src/cms-handler.js.map +1 -0
  24. package/dist/ts/src/collections.d.ts +160 -0
  25. package/dist/ts/src/collections.d.ts.map +1 -0
  26. package/dist/ts/src/collections.js +170 -0
  27. package/dist/ts/src/collections.js.map +1 -0
  28. package/dist/ts/src/components/HydrationWrapper.d.ts +18 -0
  29. package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
  30. package/dist/ts/src/components/HydrationWrapper.js +22 -0
  31. package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
  32. package/dist/ts/src/components/RenderWithFragments.d.ts +27 -0
  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/ts/src/components/RenderWithHydration.d.ts +21 -0
  37. package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
  38. package/dist/ts/src/components/RenderWithHydration.js +39 -0
  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 +18 -0
  45. package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
  46. package/dist/ts/src/discovery/astro-frontmatter.js +25 -0
  47. package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
  48. package/dist/ts/src/discovery/discover.d.ts +43 -0
  49. package/dist/ts/src/discovery/discover.d.ts.map +1 -0
  50. package/dist/ts/src/discovery/discover.js +87 -0
  51. package/dist/ts/src/discovery/discover.js.map +1 -0
  52. package/dist/ts/src/discovery/extract-props-ts.d.ts +41 -0
  53. package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
  54. package/dist/ts/src/discovery/extract-props-ts.js +232 -0
  55. package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
  56. package/dist/ts/src/discovery/merge-registry.d.ts +58 -0
  57. package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
  58. package/dist/ts/src/discovery/merge-registry.js +333 -0
  59. package/dist/ts/src/discovery/merge-registry.js.map +1 -0
  60. package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
  61. package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
  62. package/dist/ts/src/discovery/registry-endpoint.js +76 -0
  63. package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
  64. package/dist/ts/src/discovery/scan-components.d.ts +94 -0
  65. package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
  66. package/dist/ts/src/discovery/scan-components.js +397 -0
  67. package/dist/ts/src/discovery/scan-components.js.map +1 -0
  68. package/dist/ts/src/discovery/scan-mdx.d.ts +63 -0
  69. package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
  70. package/dist/ts/src/discovery/scan-mdx.js +113 -0
  71. package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
  72. package/dist/ts/src/discovery/scan-overrides.d.ts +71 -0
  73. package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
  74. package/dist/ts/src/discovery/scan-overrides.js +34 -0
  75. package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
  76. package/dist/ts/src/editor-descriptors.d.ts +31 -0
  77. package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
  78. package/dist/ts/src/editor-descriptors.js +84 -0
  79. package/dist/ts/src/editor-descriptors.js.map +1 -0
  80. package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
  81. package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
  82. package/dist/ts/src/handlers/collection-content-api.js +166 -0
  83. package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
  84. package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
  85. package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
  86. package/dist/ts/src/handlers/page-render-core.js +315 -0
  87. package/dist/ts/src/handlers/page-render-core.js.map +1 -0
  88. package/dist/ts/src/hydration.d.ts +4 -0
  89. package/dist/ts/src/hydration.d.ts.map +1 -0
  90. package/dist/ts/src/hydration.js +5 -0
  91. package/dist/ts/src/hydration.js.map +1 -0
  92. package/dist/ts/src/index.d.ts +21 -0
  93. package/dist/ts/src/index.d.ts.map +1 -0
  94. package/dist/ts/src/index.js +45 -0
  95. package/dist/ts/src/index.js.map +1 -0
  96. package/dist/ts/src/internal/declared-collections.d.ts +30 -0
  97. package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
  98. package/dist/ts/src/internal/declared-collections.js +84 -0
  99. package/dist/ts/src/internal/declared-collections.js.map +1 -0
  100. package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
  101. package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
  102. package/dist/ts/src/internal/page-collection-schema.js +152 -0
  103. package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
  104. package/dist/ts/src/lib/content-config-guard.d.ts +11 -0
  105. package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
  106. package/dist/ts/src/lib/content-config-guard.js +41 -0
  107. package/dist/ts/src/lib/content-config-guard.js.map +1 -0
  108. package/dist/ts/src/lib/hydration-scanner.d.ts +47 -0
  109. package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
  110. package/dist/ts/src/lib/hydration-scanner.js +136 -0
  111. package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
  112. package/dist/{lib/hydration-script.d.mts → ts/src/lib/hydration-script.d.ts} +7 -10
  113. package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
  114. package/dist/ts/src/lib/hydration-script.js +89 -0
  115. package/dist/ts/src/lib/hydration-script.js.map +1 -0
  116. package/dist/ts/src/lib/hydration-utils.d.ts +51 -0
  117. package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
  118. package/dist/ts/src/lib/hydration-utils.js +84 -0
  119. package/dist/ts/src/lib/hydration-utils.js.map +1 -0
  120. package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
  121. package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
  122. package/dist/ts/src/lib/resolve-locale.js +16 -0
  123. package/dist/ts/src/lib/resolve-locale.js.map +1 -0
  124. package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
  125. package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
  126. package/dist/ts/src/lib/resolve-site-name.js +12 -0
  127. package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
  128. package/dist/ts/src/lib/route-utils.d.ts +61 -0
  129. package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
  130. package/dist/ts/src/lib/route-utils.js +96 -0
  131. package/dist/ts/src/lib/route-utils.js.map +1 -0
  132. package/dist/ts/src/lib/routing-config.d.ts +38 -0
  133. package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
  134. package/dist/ts/src/lib/routing-config.js +106 -0
  135. package/dist/ts/src/lib/routing-config.js.map +1 -0
  136. package/dist/ts/src/lib/serialize-props.d.ts +6 -0
  137. package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
  138. package/dist/ts/src/lib/serialize-props.js +8 -0
  139. package/dist/ts/src/lib/serialize-props.js.map +1 -0
  140. package/dist/ts/src/lib/unknown-components.d.ts +21 -0
  141. package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
  142. package/dist/ts/src/lib/unknown-components.js +49 -0
  143. package/dist/ts/src/lib/unknown-components.js.map +1 -0
  144. package/dist/ts/src/lib/virtual-module-generators.d.ts +33 -0
  145. package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
  146. package/dist/ts/src/lib/virtual-module-generators.js +51 -0
  147. package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
  148. package/dist/{withHydration-HIvO9ysY.d.mts → ts/src/lib/withHydration.d.ts} +7 -11
  149. package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
  150. package/dist/ts/src/lib/withHydration.js +50 -0
  151. package/dist/ts/src/lib/withHydration.js.map +1 -0
  152. package/dist/ts/src/loader.d.ts +27 -0
  153. package/dist/ts/src/loader.d.ts.map +1 -0
  154. package/dist/ts/src/loader.js +118 -0
  155. package/dist/ts/src/loader.js.map +1 -0
  156. package/dist/ts/src/locales-helpers.d.ts +61 -0
  157. package/dist/ts/src/locales-helpers.d.ts.map +1 -0
  158. package/dist/ts/src/locales-helpers.js +50 -0
  159. package/dist/ts/src/locales-helpers.js.map +1 -0
  160. package/dist/ts/src/mime-types.d.ts +3 -0
  161. package/dist/ts/src/mime-types.d.ts.map +1 -0
  162. package/dist/ts/src/mime-types.js +20 -0
  163. package/dist/ts/src/mime-types.js.map +1 -0
  164. package/dist/ts/src/page-feed.d.ts +13 -0
  165. package/dist/ts/src/page-feed.d.ts.map +1 -0
  166. package/dist/ts/src/page-feed.js +20 -0
  167. package/dist/ts/src/page-feed.js.map +1 -0
  168. package/dist/ts/src/page-schemas.d.ts +6 -0
  169. package/dist/ts/src/page-schemas.d.ts.map +1 -0
  170. package/dist/ts/src/page-schemas.js +6 -0
  171. package/dist/ts/src/page-schemas.js.map +1 -0
  172. package/dist/ts/src/path-validation.d.ts +8 -0
  173. package/dist/ts/src/path-validation.d.ts.map +1 -0
  174. package/dist/ts/src/path-validation.js +13 -0
  175. package/dist/ts/src/path-validation.js.map +1 -0
  176. package/dist/ts/src/plugin-spa.d.ts +182 -0
  177. package/dist/ts/src/plugin-spa.d.ts.map +1 -0
  178. package/dist/ts/src/plugin-spa.js +1165 -0
  179. package/dist/ts/src/plugin-spa.js.map +1 -0
  180. package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
  181. package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
  182. package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
  183. package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
  184. package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
  185. package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
  186. package/dist/ts/src/puck-manifest/field-projection.js +422 -0
  187. package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
  188. package/dist/ts/src/puck-manifest/index.d.ts +4 -0
  189. package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
  190. package/dist/ts/src/puck-manifest/index.js +3 -0
  191. package/dist/ts/src/puck-manifest/index.js.map +1 -0
  192. package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
  193. package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
  194. package/dist/ts/src/puck-manifest/literal.js +354 -0
  195. package/dist/ts/src/puck-manifest/literal.js.map +1 -0
  196. package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
  197. package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
  198. package/dist/ts/src/puck-manifest/read-config.js +517 -0
  199. package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
  200. package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
  201. package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
  202. package/dist/ts/src/puck-manifest/read-field.js +11 -0
  203. package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
  204. package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
  205. package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
  206. package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
  207. package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
  208. package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
  209. package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
  210. package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
  211. package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
  212. package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
  213. package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
  214. package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
  215. package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
  216. package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
  217. package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
  218. package/dist/ts/src/puck-manifest/source-reference.js +424 -0
  219. package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
  220. package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
  221. package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
  222. package/dist/ts/src/puck-manifest/syntax.js +79 -0
  223. package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
  224. package/dist/ts/src/puck-manifest/types.d.ts +145 -0
  225. package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
  226. package/dist/ts/src/puck-manifest/types.js +2 -0
  227. package/dist/ts/src/puck-manifest/types.js.map +1 -0
  228. package/dist/ts/src/safe-json-stringify.d.ts +13 -0
  229. package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
  230. package/dist/ts/src/safe-json-stringify.js +7 -0
  231. package/dist/ts/src/safe-json-stringify.js.map +1 -0
  232. package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
  233. package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
  234. package/dist/ts/src/sandbox-frame-handler.js +27 -0
  235. package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
  236. package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts +73 -0
  237. package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
  238. package/dist/ts/src/site-styles/content-wrapper-endpoint.js +224 -0
  239. package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
  240. package/dist/ts/src/site-styles/render-endpoint.d.ts +50 -0
  241. package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
  242. package/dist/ts/src/site-styles/render-endpoint.js +264 -0
  243. package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
  244. package/dist/ts/src/site-styles/styles-endpoint.d.ts +59 -0
  245. package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
  246. package/dist/ts/src/site-styles/styles-endpoint.js +156 -0
  247. package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
  248. package/dist/ts/src/sitemap-options.d.ts +21 -0
  249. package/dist/ts/src/sitemap-options.d.ts.map +1 -0
  250. package/dist/ts/src/sitemap-options.js +92 -0
  251. package/dist/ts/src/sitemap-options.js.map +1 -0
  252. package/dist/ts/src/tiptap-html-static.d.ts +15 -0
  253. package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
  254. package/dist/ts/src/tiptap-html-static.js +67 -0
  255. package/dist/ts/src/tiptap-html-static.js.map +1 -0
  256. package/dist/ts/src/types.d.ts +543 -0
  257. package/dist/ts/src/types.d.ts.map +1 -0
  258. package/dist/ts/src/types.js +2 -0
  259. package/dist/ts/src/types.js.map +1 -0
  260. package/dist/virtual-modules.d.ts +74 -0
  261. package/node/content.ts +14 -0
  262. package/node/index.ts +22 -0
  263. package/package.json +198 -56
  264. package/src/asset-ref-base.ts +48 -0
  265. package/src/checks.ts +10 -0
  266. package/src/cms-handler.ts +280 -0
  267. package/src/collections.ts +262 -0
  268. package/src/components/HydrationWrapper.tsx +41 -0
  269. package/src/components/RenderWithFragments.tsx +204 -0
  270. package/src/components/RenderWithHydration.tsx +55 -0
  271. package/src/components.ts +3 -0
  272. package/src/discovery/astro-frontmatter.ts +24 -0
  273. package/src/discovery/discover.ts +108 -0
  274. package/src/discovery/extract-props-ts.ts +255 -0
  275. package/src/discovery/merge-registry.ts +411 -0
  276. package/src/discovery/registry-endpoint.ts +80 -0
  277. package/src/discovery/scan-components.ts +458 -0
  278. package/src/discovery/scan-mdx.ts +190 -0
  279. package/src/discovery/scan-overrides.ts +92 -0
  280. package/src/editor-descriptors.ts +96 -0
  281. package/src/env.d.ts +31 -0
  282. package/src/handlers/collection-content-api.ts +196 -0
  283. package/src/handlers/page-handler.astro +320 -0
  284. package/src/handlers/page-render-core.ts +456 -0
  285. package/src/hydration.ts +7 -0
  286. package/src/index.ts +111 -0
  287. package/src/internal/acorn-default.mjs +37 -0
  288. package/src/internal/declared-collections.ts +98 -0
  289. package/src/internal/page-collection-schema.ts +210 -0
  290. package/src/lib/content-config-guard.ts +48 -0
  291. package/src/lib/hydration-scanner.ts +176 -0
  292. package/src/lib/hydration-script.ts +126 -0
  293. package/src/lib/hydration-utils.ts +120 -0
  294. package/src/lib/resolve-locale.ts +22 -0
  295. package/src/lib/resolve-site-name.ts +10 -0
  296. package/src/lib/route-utils.ts +106 -0
  297. package/src/lib/routing-config.ts +126 -0
  298. package/src/lib/serialize-props.ts +7 -0
  299. package/src/lib/unknown-components.ts +64 -0
  300. package/src/lib/virtual-module-generators.ts +58 -0
  301. package/src/lib/withHydration.ts +71 -0
  302. package/src/loader.ts +145 -0
  303. package/src/locales-helpers.ts +68 -0
  304. package/src/mime-types.ts +19 -0
  305. package/src/page-feed.ts +26 -0
  306. package/src/page-schemas.ts +19 -0
  307. package/src/path-validation.ts +13 -0
  308. package/src/plugin-spa.ts +1480 -0
  309. package/src/puck-manifest/components-endpoint.ts +55 -0
  310. package/src/puck-manifest/field-projection.ts +510 -0
  311. package/src/puck-manifest/index.ts +3 -0
  312. package/src/puck-manifest/literal.ts +459 -0
  313. package/src/puck-manifest/read-config.ts +577 -0
  314. package/src/puck-manifest/read-field.ts +19 -0
  315. package/src/puck-manifest/read-wrapper.ts +1056 -0
  316. package/src/puck-manifest/reading-budget.ts +127 -0
  317. package/src/puck-manifest/resolve-reference.ts +9 -0
  318. package/src/puck-manifest/source-reference.ts +484 -0
  319. package/src/puck-manifest/syntax.ts +104 -0
  320. package/src/puck-manifest/types.ts +139 -0
  321. package/src/safe-json-stringify.ts +17 -0
  322. package/src/sandbox-frame-handler.ts +31 -0
  323. package/src/site-styles/content-wrapper-endpoint.ts +327 -0
  324. package/src/site-styles/render-endpoint.ts +331 -0
  325. package/src/site-styles/styles-endpoint.ts +184 -0
  326. package/src/sitemap-options.ts +115 -0
  327. package/src/tiptap-html-static.ts +84 -0
  328. package/{dist/types-CVQNmPxF.d.mts → src/types.ts} +232 -79
  329. package/src/virtual-modules.d.ts +74 -0
  330. package/dist/collections.d.mts +0 -36
  331. package/dist/collections.d.mts.map +0 -1
  332. package/dist/collections.mjs +0 -65
  333. package/dist/collections.mjs.map +0 -1
  334. package/dist/components.d.mts +0 -46
  335. package/dist/components.d.mts.map +0 -1
  336. package/dist/components.mjs +0 -226
  337. package/dist/components.mjs.map +0 -1
  338. package/dist/hydration-scanner-B0NjYkZ_.mjs +0 -109
  339. package/dist/hydration-scanner-B0NjYkZ_.mjs.map +0 -1
  340. package/dist/hydration.d.mts +0 -4
  341. package/dist/hydration.mjs +0 -3
  342. package/dist/index.d.mts +0 -139
  343. package/dist/index.d.mts.map +0 -1
  344. package/dist/index.mjs +0 -66
  345. package/dist/index.mjs.map +0 -1
  346. package/dist/internal/cms-handler.d.mts +0 -26
  347. package/dist/internal/cms-handler.d.mts.map +0 -1
  348. package/dist/internal/cms-handler.mjs +0 -267
  349. package/dist/internal/cms-handler.mjs.map +0 -1
  350. package/dist/lib/hydration-script.d.mts.map +0 -1
  351. package/dist/lib/hydration-script.mjs +0 -85
  352. package/dist/lib/hydration-script.mjs.map +0 -1
  353. package/dist/loader-By-AQWHc.mjs +0 -68
  354. package/dist/loader-By-AQWHc.mjs.map +0 -1
  355. package/dist/node/content.d.mts +0 -19
  356. package/dist/node/content.d.mts.map +0 -1
  357. package/dist/node/content.mjs +0 -4
  358. package/dist/node/index.d.mts +0 -52
  359. package/dist/node/index.d.mts.map +0 -1
  360. package/dist/node/index.mjs +0 -753
  361. package/dist/node/index.mjs.map +0 -1
  362. package/dist/serialize-props-Dhv_MnkY.mjs +0 -73
  363. package/dist/serialize-props-Dhv_MnkY.mjs.map +0 -1
  364. package/dist/types-CVQNmPxF.d.mts.map +0 -1
  365. package/dist/withHydration-EzyzBQ-Y.mjs +0 -49
  366. package/dist/withHydration-EzyzBQ-Y.mjs.map +0 -1
  367. package/dist/withHydration-HIvO9ysY.d.mts.map +0 -1
@@ -0,0 +1,577 @@
1
+ import { existsSync, statSync } from 'node:fs';
2
+ import { dirname, join, relative } from 'node:path';
3
+ import { Node, type Project, type SourceFile, SyntaxKind, ts, VariableDeclarationKind } from 'ts-morph';
4
+ import { createScanProject } from '../discovery/extract-props-ts.js';
5
+ import {
6
+ excerpt,
7
+ holdsNothing,
8
+ type LiteralWalk,
9
+ type LiteralWalkHooks,
10
+ limitOutput,
11
+ mayHoldUnread,
12
+ namedMember,
13
+ OutputBudgetExceeded,
14
+ type UnreadWrite,
15
+ unwrapExpression,
16
+ WorkBudgetExceeded,
17
+ walkIsWhole,
18
+ walkLiteral,
19
+ withReadingSession,
20
+ } from './literal.js';
21
+ import { readFieldSet } from './read-field.js';
22
+ import {
23
+ type ComponentReading,
24
+ callsDeclaredFunction,
25
+ readComponentWithSpreads,
26
+ readWrapperCall,
27
+ readWrapperCallReading,
28
+ type SpreadReading,
29
+ } from './read-wrapper.js';
30
+ import { lookUpKey, resolveCallExpression, resolveLiteralValue, resolveObjectLiteral } from './resolve-reference.js';
31
+ import type { JsonValue, PuckManifest } from './types.js';
32
+
33
+ export interface ReadPuckConfigOptions {
34
+ /** Absolute path of the site's puck config (conlocaCMS `puckConfigPath`). */
35
+ configPath: string;
36
+ /**
37
+ * Host tsconfig, so path aliases like `@/components` resolve.
38
+ *
39
+ * Left out, the nearest `tsconfig.json` above the config is used instead —
40
+ * which matters more than it sounds. Real configs are `.tsx`, and a project
41
+ * with no `jsx` option resolves a relative import of a `.tsx` file to nothing
42
+ * at all, with no error: the config would read as every component
43
+ * unresolved, silently.
44
+ */
45
+ tsConfigFilePath?: string;
46
+ }
47
+
48
+ /**
49
+ * Reads a site's Puck config into a manifest, from source and without
50
+ * executing it.
51
+ *
52
+ * Everything unreadable is named rather than dropped: a component whose
53
+ * definition cannot be followed lands in `unresolved`, so an agent is told what
54
+ * it does not know instead of being handed a component that appears to accept
55
+ * nothing.
56
+ *
57
+ * A config that cannot be read at all — no file to open, a file it loads that
58
+ * does not parse, no default export, a default export that is not an object this reader
59
+ * can follow — is refused as a whole with the reason, and so is one that would
60
+ * cost more to read, or produce a bigger manifest, than the reader allows:
61
+ * refused, never read or sent in part.
62
+ *
63
+ * Never throws. A reading that fails in a way nothing above anticipates is
64
+ * refused too, with the error it stopped on as the reason: the caller serves
65
+ * this manifest, and a config it cannot read is an answer, not a crash.
66
+ */
67
+ export function readPuckConfig(options: ReadPuckConfigOptions): PuckManifest {
68
+ return withReadingSession(() => {
69
+ try {
70
+ const manifest = readConfigFile(options);
71
+ limitOutput(manifest);
72
+ return manifest;
73
+ } catch (error) {
74
+ return refusal(stoppedReason(error));
75
+ }
76
+ });
77
+ }
78
+
79
+ /**
80
+ * Why a reading that threw is refused. A budget says what it measured; any
81
+ * other error is quoted as it is, because the reader cannot tell a fault of
82
+ * its own from a limit of the runtime it runs on — except the call stack,
83
+ * which source nested thousands of levels deep runs out of, and says so.
84
+ */
85
+ function stoppedReason(error: unknown): string {
86
+ if (error instanceof WorkBudgetExceeded || error instanceof OutputBudgetExceeded) return error.message;
87
+ const quoted = excerpt(error instanceof Error ? `${error.name}: ${error.message}` : String(error));
88
+ const stack = error instanceof RangeError && /call stack/i.test(error.message);
89
+ return stack
90
+ ? `reading the config ran out of call stack (${quoted}) — usually source nested thousands of levels deep — so its components are unknown`
91
+ : `reading the config stopped on an error (${quoted}), so its components are unknown`;
92
+ }
93
+
94
+ /** A config refused as a whole: no component names to report, so the manifest carries the gap and its reason. */
95
+ function refusal(reason: string): PuckManifest {
96
+ return { components: {}, unresolved: [], unreadable: true, unreadableReason: reason };
97
+ }
98
+
99
+ function readConfigFile(options: ReadPuckConfigOptions): PuckManifest {
100
+ const manifest: PuckManifest = { components: {}, unresolved: [] };
101
+
102
+ const project = createScanProject(options.tsConfigFilePath ?? nearestTsConfig(dirname(options.configPath)));
103
+ // A project whose options say nothing about `jsx` resolves an import of a
104
+ // `.tsx` file to nothing at all and reports no error — every component would
105
+ // read as unresolved with nothing to explain why. Reachable from three
106
+ // directions: no tsconfig, one that cannot be parsed, and one that simply
107
+ // never mentions jsx. Set before the first file is added, because changing
108
+ // compiler options reparses everything already in the project.
109
+ if (project.compilerOptions.get().jsx === undefined) {
110
+ project.compilerOptions.set({ jsx: ts.JsxEmit.Preserve });
111
+ }
112
+
113
+ let file: SourceFile;
114
+ try {
115
+ file = project.addSourceFileAtPath(options.configPath);
116
+ } catch (error) {
117
+ // An unreadable path is a missing config, not a crash in the caller. A
118
+ // file that IS there and still would not open — nested deeper than the
119
+ // parser's call stack goes — is not missing, and is refused for what
120
+ // stopped it.
121
+ if (isFile(options.configPath)) throw error;
122
+ return refusal(
123
+ 'the config file could not be opened: it is missing, or its path is not a file this reader can read',
124
+ );
125
+ }
126
+ const directory = dirname(options.configPath);
127
+ // A file that does not parse fails to load, however much of it the parser
128
+ // recovers into something this reader could otherwise read.
129
+ const broken = syntaxError(project.getProgram().compilerObject, file.compilerNode, directory);
130
+ if (broken) return refusal(`the config file, ${broken}, so it fails to load and its components are unknown`);
131
+
132
+ const exported = defaultExport(file);
133
+ if (typeof exported === 'string') return refusal(exported);
134
+ // The file is there and its config is not: `export default defineConfig(…)`.
135
+ const configObject = resolveObjectLiteral(exported);
136
+ if (!configObject) {
137
+ return refusal(
138
+ `the config's default export, ${excerpt(exported.getText())}, ${whyNotFollowed(exported)}, so its components are unknown`,
139
+ );
140
+ }
141
+
142
+ // The config is walked by the same rules as every literal in it: `{
143
+ // ...base, components: … }` reads base's categories and root, and the last
144
+ // write of a key is the one Puck gets.
145
+ const config = walkLiteral(configObject, CONFIG_KEYS);
146
+
147
+ const components = configKey(config, 'components');
148
+ if (components === 'unknown') {
149
+ manifest.unreadable = true;
150
+ manifest.unreadableReason = `${unknownComponentsReason(config)}, so its components are unknown`;
151
+ } else if (components !== 'absent') readComponents(components, manifest);
152
+
153
+ const categories = configKey(config, 'categories');
154
+ if (categories === 'unknown') manifest.categoriesUnreadable = true;
155
+ else if (categories !== 'absent') readCategories(categories, manifest);
156
+
157
+ const root = configKey(config, 'root');
158
+ if (root === 'unknown') manifest.root = { fields: {}, fieldsUnreadable: true };
159
+ else if (root !== 'absent') {
160
+ const read = readRoot(root);
161
+ if (read) manifest.root = read;
162
+ }
163
+
164
+ // A module the reading went through that does not parse fails to load, and
165
+ // takes the config down with it — whatever the parser recovered of it.
166
+ const brokenImport = brokenModule(project, directory);
167
+ if (brokenImport) {
168
+ return refusal(
169
+ `a module the config loads, ${brokenImport}, so the config fails to load and its components are unknown`,
170
+ );
171
+ }
172
+ return manifest;
173
+ }
174
+
175
+ /** The config's own keys, each handed over as the node its last write assigns — spreads followed to the literal they name. */
176
+ const CONFIG_KEYS: LiteralWalkHooks<Node> = {
177
+ kind: 'config',
178
+ read: (value) => value,
179
+ spread: (expression) => resolveObjectLiteral(expression),
180
+ };
181
+
182
+ /**
183
+ * What the config provably says about one of its keys: the node its last
184
+ * write assigns; `absent` where nothing writes it — or the write holds nothing,
185
+ * as `root: undefined` does; or `unknown` where a write this reader cannot read
186
+ * may be it — a getter, a spread or a computed name it cannot follow, a
187
+ * prototype.
188
+ */
189
+ function configKey(config: LiteralWalk<Node>, key: string): Node | 'absent' | 'unknown' {
190
+ const value = config.entries.get(key);
191
+ if (value) return holdsNothing(value) ? 'absent' : value;
192
+ return mayHoldUnread(config, key) ? 'unknown' : 'absent';
193
+ }
194
+
195
+ /** Whether a path names a file that is there — as opposed to nothing, or a directory. */
196
+ function isFile(path: string): boolean {
197
+ return statSync(path, { throwIfNoEntry: false })?.isFile() ?? false;
198
+ }
199
+
200
+ /**
201
+ * Where a file fails to parse, as a reason names it — `Hero.ts, has a syntax
202
+ * error at line 3 (',' expected)` — or undefined when it parses. The path is
203
+ * taken from the config's directory. Only the parser is asked, which costs
204
+ * nothing the reading would not pay anyway.
205
+ */
206
+ function syntaxError(program: ts.Program, file: ts.SourceFile, directory: string): string | undefined {
207
+ const [first] = program.getSyntacticDiagnostics(file);
208
+ if (!first) return undefined;
209
+ const message = ts.flattenDiagnosticMessageText(first.messageText, ' ');
210
+ const line = file.getLineAndCharacterOfPosition(first.start).line + 1;
211
+ return `${relative(directory, file.fileName)}, has a syntax error at line ${line} (${excerpt(message)})`;
212
+ }
213
+
214
+ /**
215
+ * The first file the reading loaded that does not parse, named as
216
+ * `syntaxError` names it. Only syntax counts — a type error still loads — and
217
+ * declaration files and packages are left out: neither is the site's source.
218
+ */
219
+ function brokenModule(project: Project, directory: string): string | undefined {
220
+ const program = project.getProgram().compilerObject;
221
+ for (const file of program.getSourceFiles()) {
222
+ const external = program.isSourceFileFromExternalLibrary(file) || file.fileName.includes('/node_modules/');
223
+ if (file.isDeclarationFile || external) continue;
224
+ const broken = syntaxError(program, file, directory);
225
+ if (broken) return broken;
226
+ }
227
+ return undefined;
228
+ }
229
+
230
+ /**
231
+ * The node the config's default export is written as — the expression of
232
+ * `export default …`, or the name `export { config as default }` and `export
233
+ * { default } from './real'` hand over — or the reason there is none this
234
+ * reader can read.
235
+ *
236
+ * The default exports are counted from the statements rather than asked of
237
+ * the compiler, which keeps the first of two and says nothing of the second:
238
+ * a module with two does not load at all.
239
+ */
240
+ function defaultExport(file: SourceFile): Node | string {
241
+ const written = file.getStatements().flatMap(defaultExportsOf);
242
+ if (written.length > 1) {
243
+ const lines = written.map((declaration) => declaration.getStartLineNumber()).join(' and ');
244
+ return `the config file has ${written.length} default exports, on lines ${lines}, and a module with more than one fails to load, so its components are unknown`;
245
+ }
246
+ const [declaration] = written;
247
+ if (!declaration) {
248
+ return file.getExportAssignment((node) => node.isExportEquals())
249
+ ? 'the config file exports with `export =`, which this reader does not read as a default export, so its components are unknown'
250
+ : 'the config file has no default export, so there is no config to read';
251
+ }
252
+ if (Node.isExportAssignment(declaration)) return declaration.getExpression();
253
+ if (Node.isExportSpecifier(declaration)) return declaration.getNameNode();
254
+ if (Node.isExportDeclaration(declaration)) {
255
+ return "the config's default export is a module namespace, which this reader does not read, so its components are unknown";
256
+ }
257
+ const kind = Node.isClassDeclaration(declaration) ? 'a class' : 'a function';
258
+ return `the config's default export is ${kind}, not an object written out in the source, so its components are unknown`;
259
+ }
260
+
261
+ /**
262
+ * The default exports one statement makes that exist at runtime. An overload
263
+ * signature and a type-only export make none — a function's overloads are one
264
+ * function, its body — and `export =` is no default export. `export * as
265
+ * default from './real'` makes one: the module's namespace.
266
+ */
267
+ function defaultExportsOf(statement: Node): Node[] {
268
+ if (Node.isExportAssignment(statement)) return statement.isExportEquals() ? [] : [statement];
269
+ if (Node.isFunctionDeclaration(statement) || Node.isClassDeclaration(statement)) {
270
+ const signatureOnly = Node.isFunctionDeclaration(statement) && !statement.hasBody();
271
+ return statement.isDefaultExport() && !signatureOnly && !statement.hasDeclareKeyword() ? [statement] : [];
272
+ }
273
+ if (!Node.isExportDeclaration(statement) || statement.isTypeOnly()) return [];
274
+ const namespace = statement.getNamespaceExport();
275
+ if (namespace && exportName(namespace.getNameNode()) === 'default') return [statement];
276
+ return statement.getNamedExports().filter((specifier) => {
277
+ const exported = specifier.getAliasNode() ?? specifier.getNameNode();
278
+ return exportName(exported) === 'default' && !specifier.isTypeOnly();
279
+ });
280
+ }
281
+
282
+ /** The name an export is made under, written as a name or — `export { x as 'default' }` — a string. */
283
+ function exportName(name: Node): string {
284
+ return Node.isStringLiteral(name) ? name.getLiteralValue() : name.getText();
285
+ }
286
+
287
+ /**
288
+ * Why a node that was to lead to an object does not, as the clause a reason
289
+ * puts after quoting it. What this reader can tell apart is named — a call, a
290
+ * name it cannot find, a `let` — and anything else is admitted plainly, never
291
+ * guessed at.
292
+ */
293
+ function whyNotFollowed(node: Node): string {
294
+ const expression = unwrapExpression(node);
295
+ if (Node.isCallExpression(expression)) return "is a call's result, which this reader would have to run to know";
296
+ const identifier = expression.asKind(SyntaxKind.Identifier);
297
+ if (identifier) {
298
+ const declarations = declarationsOf(identifier);
299
+ if (declarations.length === 0) {
300
+ return 'names nothing this reader can find — an import it cannot resolve, or a global';
301
+ }
302
+ const letOrVar = declarations.some(
303
+ (declaration) =>
304
+ Node.isVariableDeclaration(declaration) &&
305
+ declaration.getVariableStatement()?.getDeclarationKind() !== VariableDeclarationKind.Const,
306
+ );
307
+ if (letOrVar)
308
+ return 'is declared with let or var, and what it holds when Puck reads it may not be what is written there';
309
+ }
310
+ return 'is not an object written out in the source or a name this reader can follow to one';
311
+ }
312
+
313
+ /** How many imports and re-exports `declarationsOf` follows before it gives up. */
314
+ const MAX_ALIAS_HOPS = 5;
315
+
316
+ /** The declarations a name stands for, across imports and re-exports; none when it stands for nothing this reader can find. */
317
+ function declarationsOf(identifier: Node): Node[] {
318
+ // A shorthand's name is a property to the checker; the value it stands for
319
+ // is a symbol of its own.
320
+ const shorthand = identifier.getParentIfKind(SyntaxKind.ShorthandPropertyAssignment);
321
+ let symbol = shorthand?.getNameNode() === identifier ? shorthand.getValueSymbol() : identifier.getSymbol();
322
+ for (let hop = 0; symbol?.isAlias() && hop < MAX_ALIAS_HOPS; hop++) symbol = symbol.getAliasedSymbol();
323
+ return symbol?.getDeclarations() ?? [];
324
+ }
325
+
326
+ /**
327
+ * Why the config's `components` key is unknown: what writes it may be code, or
328
+ * a write this reader cannot name, or a prototype.
329
+ */
330
+ function unknownComponentsReason(config: LiteralWalk<Node>): string {
331
+ const unread = config.unread.get('components');
332
+ if (unread === 'code')
333
+ return 'the config declares components with a getter or a method, whose code this reader does not run';
334
+ if (unread === 'setter')
335
+ return 'the config writes components last with a setter, which reads back as undefined — or, beside a getter, runs code this reader does not run';
336
+ if (config.lost) return `${unnamedWrite(config, 'the config')}, and it may set the components map`;
337
+ return 'the config sets its prototype with __proto__, and the components map may be inherited through it';
338
+ }
339
+
340
+ /**
341
+ * The write a walk could not name, as a reason puts it: the spread it could
342
+ * not follow — or that led to one it could not — or the computed name it could
343
+ * not work out.
344
+ */
345
+ function unnamedWrite(walk: LiteralWalk<unknown>, owner: string): string {
346
+ const spread = walk.lostAt?.asKind(SyntaxKind.SpreadAssignment);
347
+ if (spread)
348
+ return `${owner} spreads ${excerpt(spread.getExpression().getText())}, which this reader cannot follow to the keys it writes`;
349
+ const name = walk.lostAt && namedMember(walk.lostAt)?.getNameNode();
350
+ if (name)
351
+ return `${owner} writes a key under a computed name, ${excerpt(name.getText())}, that this reader cannot work out`;
352
+ return `${owner} writes a key this reader cannot name`;
353
+ }
354
+
355
+ /**
356
+ * The nearest `tsconfig.json` at or above a directory. Absent one, the caller
357
+ * falls back to permissive defaults, which is the best that can be done for a
358
+ * project that has no TypeScript config of its own.
359
+ */
360
+ function nearestTsConfig(fromDirectory: string): string | undefined {
361
+ let directory = fromDirectory;
362
+ for (;;) {
363
+ const candidate = join(directory, 'tsconfig.json');
364
+ if (existsSync(candidate)) return candidate;
365
+ const parent = dirname(directory);
366
+ if (parent === directory) return undefined;
367
+ directory = parent;
368
+ }
369
+ }
370
+
371
+ /** Why a name is admitted when a later write the components map cannot name may have replaced it. */
372
+ const MAY_BE_REPLACED =
373
+ 'a later entry of the components map — a spread or a computed name this reader cannot follow — may replace this component';
374
+
375
+ /**
376
+ * Why a name is admitted when the components map declares it in a shape that
377
+ * carries no value to read. `['__proto__']` has no reason: none can be recorded
378
+ * under that name, and `value` never arises — every definition reads as a
379
+ * component or a reason of its own.
380
+ */
381
+ function unreadReason(why: UnreadWrite): string | undefined {
382
+ switch (why) {
383
+ case 'code':
384
+ return 'the components map declares it with a getter or a method, whose code this reader does not run';
385
+ case 'setter':
386
+ return 'the components map writes it last with a setter, which reads back as undefined — or, beside a getter, runs code this reader does not run';
387
+ default:
388
+ return undefined;
389
+ }
390
+ }
391
+
392
+ /**
393
+ * Reads the `components` map, whether it is written in the config, named
394
+ * (`components: siteComponents`) or handed over as a shorthand.
395
+ *
396
+ * A map that cannot be followed at all leaves no names behind to report, so the
397
+ * manifest itself is marked unreadable — the difference between a site with no
398
+ * components and a site whose components this reader could not see.
399
+ *
400
+ * The map is walked by the runtime's own rules, spreads merged where they sit
401
+ * and the last entry for a name winning. A later write the walk cannot name —
402
+ * `[name]: …`, `...buildComponents()` — may replace any component written
403
+ * before it, so those move to `unresolved` with that reason, and may add
404
+ * components no name here reveals, so the manifest is marked unreadable too; so
405
+ * does a prototype, through which Puck looks a component up as well.
406
+ */
407
+ function readComponents(node: Node, manifest: PuckManifest): void {
408
+ const literal = resolveObjectLiteral(node);
409
+ if (!literal) {
410
+ manifest.unreadable = true;
411
+ manifest.unreadableReason = `the config's components map, ${excerpt(node.getText())}, ${whyNotFollowed(node)}, so its components are unknown`;
412
+ return;
413
+ }
414
+
415
+ const walk = walkLiteral(literal, COMPONENT_ENTRIES);
416
+ for (const [name, { component, reason }] of walk.entries) {
417
+ if (component) manifest.components[name] = component;
418
+ else admitComponent(manifest, name, reason);
419
+ }
420
+ for (const [name, why] of walk.unread) admitComponent(manifest, name, unreadReason(why));
421
+ for (const name of walk.cleared) admitComponent(manifest, name, MAY_BE_REPLACED);
422
+ if (walk.lost || walk.inherits) {
423
+ manifest.unreadable = true;
424
+ manifest.unreadableReason = walk.lost
425
+ ? `${unnamedWrite(walk, 'the components map')}, so it may declare components not listed here`
426
+ : 'the components map sets its prototype with __proto__, and Puck finds components through it too, so it may declare components not listed here';
427
+ }
428
+ }
429
+
430
+ /** The components map's entries, each read as a definition — `components: { ...shared, Badge: … }` inlines a second map. */
431
+ const COMPONENT_ENTRIES: LiteralWalkHooks<ComponentReading> = {
432
+ kind: 'components map',
433
+ read: (value) => resolveComponentDefinition(value),
434
+ spread: (expression) => resolveObjectLiteral(expression),
435
+ };
436
+
437
+ /** Names a component in `unresolved`, with the reason where one is known. */
438
+ function admitComponent(manifest: PuckManifest, name: string, reason: string | undefined): void {
439
+ manifest.unresolved.push(name);
440
+ // `__proto__` would replace the record's prototype rather than add a reason.
441
+ if (!reason || name === '__proto__') return;
442
+ manifest.unresolvedReasons ??= {};
443
+ manifest.unresolvedReasons[name] = reason;
444
+ }
445
+
446
+ /**
447
+ * A component definition reached through a name or written in place: the
448
+ * resolved literal read with its spreads applied, or — when the name stands for
449
+ * a wrapper call — the wrapper's symbolic reading. The reason, when set, names
450
+ * the refusing rule for the manifest.
451
+ *
452
+ * One walker reads both, in source order and by the runtime's own rules, so a
453
+ * component written `{ ...Grid, label: … }` in the config means here exactly
454
+ * what it means inside a wrapper body.
455
+ */
456
+ function resolveComponentDefinition(node: Node): ComponentReading {
457
+ const literal = resolveObjectLiteral(node);
458
+ if (literal) return readComponentWithSpreads(literal, wrapperBuiltSpread);
459
+ const call = resolveCallExpression(node);
460
+ return call ? readWrapperCall(call) : {};
461
+ }
462
+
463
+ /**
464
+ * The one spread source the walker cannot reach as text: a name standing for a
465
+ * wrapper CALL. Both of our own configs rename wrapper-built components this
466
+ * way — `Grid: { ...Grid, label: … }` — and the override literal on its own is
467
+ * a label and no fields, so reported as the component it would claim the
468
+ * component accepts nothing.
469
+ *
470
+ * Only a call to a function declared in the source is a wrapper. `...mk()`
471
+ * with `mk` nowhere to be found is a spread that cannot be followed, and the
472
+ * walker's own reason says so; the wrapper reader's would blame a wrapper the
473
+ * config never wrote.
474
+ */
475
+ function wrapperBuiltSpread(expression: Node): SpreadReading {
476
+ const call = resolveCallExpression(expression);
477
+ return call && callsDeclaredFunction(call) ? readWrapperCallReading(call) : {};
478
+ }
479
+
480
+ /** One category, as the manifest carries it. */
481
+ type Category = NonNullable<PuckManifest['categories']>[string];
482
+
483
+ /** One category entry read: what it provably declares, and whether any of the part the manifest carries went unread. */
484
+ interface CategoryReading {
485
+ category?: Category;
486
+ admitted: boolean;
487
+ }
488
+
489
+ /** A category's own keys: values followed to the `const` they name, spreads to the literal they name. */
490
+ const CATEGORY_KEYS: LiteralWalkHooks<JsonValue> = {
491
+ kind: 'category',
492
+ read: (value) => resolveLiteralValue(value),
493
+ spread: (expression) => resolveObjectLiteral(expression),
494
+ };
495
+
496
+ /**
497
+ * Sidebar grouping, walked by the runtime's own rules. A category that cannot
498
+ * be read — or whose name cannot be — is left out and admitted with
499
+ * `categoriesUnreadable`, as is any other part of the value the walk could not
500
+ * see, so a missing category is never mistaken for one the config lacks.
501
+ */
502
+ function readCategories(node: Node, manifest: PuckManifest): void {
503
+ const literal = resolveObjectLiteral(node);
504
+ if (!literal) {
505
+ manifest.categoriesUnreadable = true;
506
+ return;
507
+ }
508
+ const walk = walkLiteral(literal, CATEGORY_ENTRIES);
509
+
510
+ const categories: [string, Category][] = [];
511
+ let admitted = !walkIsWhole(walk);
512
+ for (const [name, reading] of walk.entries) {
513
+ if (reading.admitted) admitted = true;
514
+ if (reading.category) categories.push([name, reading.category]);
515
+ }
516
+ manifest.categories = Object.fromEntries(categories);
517
+ if (admitted) manifest.categoriesUnreadable = true;
518
+ }
519
+
520
+ /**
521
+ * One category. One whose component list is provably never written says
522
+ * nothing and is left out; one whose list or title may be written but could
523
+ * not be read is admitted — the list by leaving the category out, the title by
524
+ * listing the category without it.
525
+ */
526
+ /** The categories map's entries, each read as a category; a spread inlines a second map. */
527
+ const CATEGORY_ENTRIES: LiteralWalkHooks<CategoryReading> = {
528
+ kind: 'categories',
529
+ read: (value) => readCategory(value),
530
+ spread: (expression) => resolveObjectLiteral(expression),
531
+ };
532
+
533
+ function readCategory(node: Node): CategoryReading {
534
+ const literal = resolveObjectLiteral(node);
535
+ if (!literal) return { admitted: true };
536
+ const walk = walkLiteral(literal, CATEGORY_KEYS);
537
+
538
+ const components = walk.entries.get('components');
539
+ if (!isStringList(components)) {
540
+ return { admitted: components !== undefined || mayHoldUnread(walk, 'components') };
541
+ }
542
+ const title = walk.entries.get('title');
543
+ if (typeof title === 'string') return { category: { title, components }, admitted: false };
544
+ return { category: { components }, admitted: title !== undefined || mayHoldUnread(walk, 'title') };
545
+ }
546
+
547
+ function isStringList(value: JsonValue | undefined): value is string[] {
548
+ return Array.isArray(value) && value.every((entry) => typeof entry === 'string');
549
+ }
550
+
551
+ /**
552
+ * Page-level fields, which Puck declares as a component in all but name. The
553
+ * `fields` key is looked up by the runtime's rule — the last write wins,
554
+ * spreads included — and a write that may be it but cannot be read admits the
555
+ * set rather than reporting a page with no fields. A root that cannot be read
556
+ * at all — `root: buildRoot()` — is admitted the same way, because it may
557
+ * declare page fields too.
558
+ */
559
+ function readRoot(node: Node): PuckManifest['root'] {
560
+ const literal = resolveObjectLiteral(node);
561
+ if (!literal) return { fields: {}, fieldsUnreadable: true };
562
+
563
+ const written = lookUpKey(literal, 'fields');
564
+ if (written === 'absent') return undefined;
565
+ const set = written === 'unknown' ? undefined : readFieldSet(written);
566
+ if (!set) return { fields: {}, fieldsUnreadable: true };
567
+ return set.unreadable ? { fields: set.fields, fieldsUnreadable: true } : { fields: set.fields };
568
+ }
569
+
570
+ /**
571
+ * The dev endpoint's response body. Kept beside the reader so the dev route
572
+ * and a build that publishes the manifest serialize identically — one JSON
573
+ * shape, one place.
574
+ */
575
+ export function componentsEndpointBody(options: ReadPuckConfigOptions): string {
576
+ return JSON.stringify(readPuckConfig(options));
577
+ }
@@ -0,0 +1,19 @@
1
+ import type { Node, ObjectLiteralExpression } from 'ts-morph';
2
+ import {
3
+ type FieldSources,
4
+ readField as projectField,
5
+ readFieldSet as projectFieldSet,
6
+ WRITTEN_DOWN,
7
+ } from './field-projection.js';
8
+ import { readFieldBuilderCall } from './read-wrapper.js';
9
+
10
+ export { carryKey, type FieldSetReading, type FieldSources } from './field-projection.js';
11
+
12
+ /** Public reader entry points retain builder support without a projection/wrapper import cycle. */
13
+ export function readField(node: ObjectLiteralExpression, depth = 0, sources: FieldSources = WRITTEN_DOWN) {
14
+ return projectField(node, depth, { ...sources, builder: sources.builder ?? readFieldBuilderCall });
15
+ }
16
+
17
+ export function readFieldSet(node: Node | undefined, depth = 0, sources: FieldSources = WRITTEN_DOWN) {
18
+ return projectFieldSet(node, depth, { ...sources, builder: sources.builder ?? readFieldBuilderCall });
19
+ }