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