@elastic/isomer-sdk 0.0.0 → 0.1.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 (450) hide show
  1. package/LICENSE.txt +93 -0
  2. package/NOTICE.txt +1861 -0
  3. package/README.md +58 -0
  4. package/THIRD_PARTY_LICENSES.md +957 -0
  5. package/dist/author/authored_fields.d.ts +103 -0
  6. package/dist/author/authored_fields.d.ts.map +1 -0
  7. package/dist/author/authored_fields.js +183 -0
  8. package/dist/author/authored_fields.js.map +1 -0
  9. package/dist/author/index.d.ts +5 -0
  10. package/dist/author/index.d.ts.map +1 -0
  11. package/dist/author/index.js +10 -0
  12. package/dist/author/index.js.map +1 -0
  13. package/dist/author/jsx.d.ts +21 -0
  14. package/dist/author/jsx.d.ts.map +1 -0
  15. package/dist/author/jsx.js +20 -0
  16. package/dist/author/jsx.js.map +1 -0
  17. package/dist/author/jsx_shim.d.ts +116 -0
  18. package/dist/author/jsx_shim.d.ts.map +1 -0
  19. package/dist/author/jsx_shim.js +353 -0
  20. package/dist/author/jsx_shim.js.map +1 -0
  21. package/dist/author/prompt.d.ts +58 -0
  22. package/dist/author/prompt.d.ts.map +1 -0
  23. package/dist/author/prompt.js +148 -0
  24. package/dist/author/prompt.js.map +1 -0
  25. package/dist/cjs/author/authored_fields.js +189 -0
  26. package/dist/cjs/author/authored_fields.js.map +1 -0
  27. package/dist/cjs/author/index.js +20 -0
  28. package/dist/cjs/author/index.js.map +1 -0
  29. package/dist/cjs/author/jsx.js +24 -0
  30. package/dist/cjs/author/jsx.js.map +1 -0
  31. package/dist/cjs/author/jsx_shim.js +359 -0
  32. package/dist/cjs/author/jsx_shim.js.map +1 -0
  33. package/dist/cjs/author/prompt.js +153 -0
  34. package/dist/cjs/author/prompt.js.map +1 -0
  35. package/dist/cjs/composition/action_event.js +9 -0
  36. package/dist/cjs/composition/action_event.js.map +1 -0
  37. package/dist/cjs/composition/body_node_base.js +105 -0
  38. package/dist/cjs/composition/body_node_base.js.map +1 -0
  39. package/dist/cjs/composition/composition.js +9 -0
  40. package/dist/cjs/composition/composition.js.map +1 -0
  41. package/dist/cjs/composition/error.js +72 -0
  42. package/dist/cjs/composition/error.js.map +1 -0
  43. package/dist/cjs/composition/index.js +31 -0
  44. package/dist/cjs/composition/index.js.map +1 -0
  45. package/dist/cjs/composition/map_nodes.js +85 -0
  46. package/dist/cjs/composition/map_nodes.js.map +1 -0
  47. package/dist/cjs/composition/named_color.js +20 -0
  48. package/dist/cjs/composition/named_color.js.map +1 -0
  49. package/dist/cjs/composition/node.js +9 -0
  50. package/dist/cjs/composition/node.js.map +1 -0
  51. package/dist/cjs/composition/one_line.js +23 -0
  52. package/dist/cjs/composition/one_line.js.map +1 -0
  53. package/dist/cjs/composition/structured_value.js +21 -0
  54. package/dist/cjs/composition/structured_value.js.map +1 -0
  55. package/dist/cjs/composition/validation_error.js +40 -0
  56. package/dist/cjs/composition/validation_error.js.map +1 -0
  57. package/dist/cjs/define/frame.js +32 -0
  58. package/dist/cjs/define/frame.js.map +1 -0
  59. package/dist/cjs/define/index.js +25 -0
  60. package/dist/cjs/define/index.js.map +1 -0
  61. package/dist/cjs/define/markdown_content.js +12 -0
  62. package/dist/cjs/define/markdown_content.js.map +1 -0
  63. package/dist/cjs/define/primitive_module.js +107 -0
  64. package/dist/cjs/define/primitive_module.js.map +1 -0
  65. package/dist/cjs/define/slack_assets.js +9 -0
  66. package/dist/cjs/define/slack_assets.js.map +1 -0
  67. package/dist/cjs/define/slack_blocks.js +9 -0
  68. package/dist/cjs/define/slack_blocks.js.map +1 -0
  69. package/dist/cjs/define/zod_format.js +122 -0
  70. package/dist/cjs/define/zod_format.js.map +1 -0
  71. package/dist/cjs/define/zod_helpers.js +26 -0
  72. package/dist/cjs/define/zod_helpers.js.map +1 -0
  73. package/dist/cjs/entries/html.js +12 -0
  74. package/dist/cjs/entries/html.js.map +1 -0
  75. package/dist/cjs/entries/index.js +75 -0
  76. package/dist/cjs/entries/index.js.map +1 -0
  77. package/dist/cjs/entries/markdown.js +14 -0
  78. package/dist/cjs/entries/markdown.js.map +1 -0
  79. package/dist/cjs/entries/react.js +20 -0
  80. package/dist/cjs/entries/react.js.map +1 -0
  81. package/dist/cjs/entries/slack.js +26 -0
  82. package/dist/cjs/entries/slack.js.map +1 -0
  83. package/dist/cjs/entries/text.js +12 -0
  84. package/dist/cjs/entries/text.js.map +1 -0
  85. package/dist/cjs/pack/capabilities.js +34 -0
  86. package/dist/cjs/pack/capabilities.js.map +1 -0
  87. package/dist/cjs/pack/compose.js +56 -0
  88. package/dist/cjs/pack/compose.js.map +1 -0
  89. package/dist/cjs/pack/enhancements.js +65 -0
  90. package/dist/cjs/pack/enhancements.js.map +1 -0
  91. package/dist/cjs/pack/index.js +18 -0
  92. package/dist/cjs/pack/index.js.map +1 -0
  93. package/dist/cjs/pack/primitive_pack.js +85 -0
  94. package/dist/cjs/pack/primitive_pack.js.map +1 -0
  95. package/dist/cjs/package.json +3 -0
  96. package/dist/cjs/render/anchors.js +167 -0
  97. package/dist/cjs/render/anchors.js.map +1 -0
  98. package/dist/cjs/render/context_view.js +54 -0
  99. package/dist/cjs/render/context_view.js.map +1 -0
  100. package/dist/cjs/render/format_display_value.js +143 -0
  101. package/dist/cjs/render/format_display_value.js.map +1 -0
  102. package/dist/cjs/render/format_number.js +46 -0
  103. package/dist/cjs/render/format_number.js.map +1 -0
  104. package/dist/cjs/render/html/enhancements.js +30 -0
  105. package/dist/cjs/render/html/enhancements.js.map +1 -0
  106. package/dist/cjs/render/html/envelope.js +218 -0
  107. package/dist/cjs/render/html/envelope.js.map +1 -0
  108. package/dist/cjs/render/html/index.js +12 -0
  109. package/dist/cjs/render/html/index.js.map +1 -0
  110. package/dist/cjs/render/index.js +25 -0
  111. package/dist/cjs/render/index.js.map +1 -0
  112. package/dist/cjs/render/layout_check.js +133 -0
  113. package/dist/cjs/render/layout_check.js.map +1 -0
  114. package/dist/cjs/render/markdown/builder.js +189 -0
  115. package/dist/cjs/render/markdown/builder.js.map +1 -0
  116. package/dist/cjs/render/markdown/envelope.js +33 -0
  117. package/dist/cjs/render/markdown/envelope.js.map +1 -0
  118. package/dist/cjs/render/markdown/format.js +190 -0
  119. package/dist/cjs/render/markdown/format.js.map +1 -0
  120. package/dist/cjs/render/markdown/index.js +15 -0
  121. package/dist/cjs/render/markdown/index.js.map +1 -0
  122. package/dist/cjs/render/measure_dom.js +61 -0
  123. package/dist/cjs/render/measure_dom.js.map +1 -0
  124. package/dist/cjs/render/payload.js +13 -0
  125. package/dist/cjs/render/payload.js.map +1 -0
  126. package/dist/cjs/render/primitive_dispatch.js +187 -0
  127. package/dist/cjs/render/primitive_dispatch.js.map +1 -0
  128. package/dist/cjs/render/react/content.js +44 -0
  129. package/dist/cjs/render/react/content.js.map +1 -0
  130. package/dist/cjs/render/react/enhancements.js +32 -0
  131. package/dist/cjs/render/react/enhancements.js.map +1 -0
  132. package/dist/cjs/render/react/index.js +15 -0
  133. package/dist/cjs/render/react/index.js.map +1 -0
  134. package/dist/cjs/render/slack/assets.js +45 -0
  135. package/dist/cjs/render/slack/assets.js.map +1 -0
  136. package/dist/cjs/render/slack/blocks.js +80 -0
  137. package/dist/cjs/render/slack/blocks.js.map +1 -0
  138. package/dist/cjs/render/slack/envelope.js +551 -0
  139. package/dist/cjs/render/slack/envelope.js.map +1 -0
  140. package/dist/cjs/render/slack/format.js +825 -0
  141. package/dist/cjs/render/slack/format.js.map +1 -0
  142. package/dist/cjs/render/slack/index.js +31 -0
  143. package/dist/cjs/render/slack/index.js.map +1 -0
  144. package/dist/cjs/render/slack/markdown_content.js +358 -0
  145. package/dist/cjs/render/slack/markdown_content.js.map +1 -0
  146. package/dist/cjs/render/text/envelope.js +21 -0
  147. package/dist/cjs/render/text/envelope.js.map +1 -0
  148. package/dist/cjs/render/text/index.js +12 -0
  149. package/dist/cjs/render/text/index.js.map +1 -0
  150. package/dist/cjs/testing/conformance.js +296 -0
  151. package/dist/cjs/testing/conformance.js.map +1 -0
  152. package/dist/cjs/testing/index.js +16 -0
  153. package/dist/cjs/testing/index.js.map +1 -0
  154. package/dist/cjs/testing/registration.js +140 -0
  155. package/dist/cjs/testing/registration.js.map +1 -0
  156. package/dist/cjs/validate/authoring_schema.js +296 -0
  157. package/dist/cjs/validate/authoring_schema.js.map +1 -0
  158. package/dist/cjs/validate/composition_schema.js +135 -0
  159. package/dist/cjs/validate/composition_schema.js.map +1 -0
  160. package/dist/cjs/validate/index.js +52 -0
  161. package/dist/cjs/validate/index.js.map +1 -0
  162. package/dist/cjs/validate/input_budget.js +156 -0
  163. package/dist/cjs/validate/input_budget.js.map +1 -0
  164. package/dist/cjs/validate/json_schema.js +72 -0
  165. package/dist/cjs/validate/json_schema.js.map +1 -0
  166. package/dist/cjs/validate/node_issues.js +65 -0
  167. package/dist/cjs/validate/node_issues.js.map +1 -0
  168. package/dist/cjs/validate/url.js +116 -0
  169. package/dist/cjs/validate/url.js.map +1 -0
  170. package/dist/cjs/validate/validation.js +208 -0
  171. package/dist/cjs/validate/validation.js.map +1 -0
  172. package/dist/cjs/validate/value_schemas.js +53 -0
  173. package/dist/cjs/validate/value_schemas.js.map +1 -0
  174. package/dist/composition/action_event.d.ts +13 -0
  175. package/dist/composition/action_event.d.ts.map +1 -0
  176. package/dist/composition/action_event.js +8 -0
  177. package/dist/composition/action_event.js.map +1 -0
  178. package/dist/composition/body_node_base.d.ts +71 -0
  179. package/dist/composition/body_node_base.d.ts.map +1 -0
  180. package/dist/composition/body_node_base.js +97 -0
  181. package/dist/composition/body_node_base.js.map +1 -0
  182. package/dist/composition/composition.d.ts +71 -0
  183. package/dist/composition/composition.d.ts.map +1 -0
  184. package/dist/composition/composition.js +8 -0
  185. package/dist/composition/composition.js.map +1 -0
  186. package/dist/composition/error.d.ts +60 -0
  187. package/dist/composition/error.d.ts.map +1 -0
  188. package/dist/composition/error.js +68 -0
  189. package/dist/composition/error.js.map +1 -0
  190. package/dist/composition/index.d.ts +11 -0
  191. package/dist/composition/index.d.ts.map +1 -0
  192. package/dist/composition/index.js +14 -0
  193. package/dist/composition/index.js.map +1 -0
  194. package/dist/composition/map_nodes.d.ts +16 -0
  195. package/dist/composition/map_nodes.d.ts.map +1 -0
  196. package/dist/composition/map_nodes.js +81 -0
  197. package/dist/composition/map_nodes.js.map +1 -0
  198. package/dist/composition/named_color.d.ts +9 -0
  199. package/dist/composition/named_color.d.ts.map +1 -0
  200. package/dist/composition/named_color.js +17 -0
  201. package/dist/composition/named_color.js.map +1 -0
  202. package/dist/composition/node.d.ts +11 -0
  203. package/dist/composition/node.d.ts.map +1 -0
  204. package/dist/composition/node.js +8 -0
  205. package/dist/composition/node.js.map +1 -0
  206. package/dist/composition/one_line.d.ts +7 -0
  207. package/dist/composition/one_line.d.ts.map +1 -0
  208. package/dist/composition/one_line.js +17 -0
  209. package/dist/composition/one_line.js.map +1 -0
  210. package/dist/composition/structured_value.d.ts +27 -0
  211. package/dist/composition/structured_value.d.ts.map +1 -0
  212. package/dist/composition/structured_value.js +18 -0
  213. package/dist/composition/structured_value.js.map +1 -0
  214. package/dist/composition/validation_error.d.ts +33 -0
  215. package/dist/composition/validation_error.d.ts.map +1 -0
  216. package/dist/composition/validation_error.js +35 -0
  217. package/dist/composition/validation_error.js.map +1 -0
  218. package/dist/define/frame.d.ts +166 -0
  219. package/dist/define/frame.d.ts.map +1 -0
  220. package/dist/define/frame.js +28 -0
  221. package/dist/define/frame.js.map +1 -0
  222. package/dist/define/index.d.ts +8 -0
  223. package/dist/define/index.d.ts.map +1 -0
  224. package/dist/define/index.js +11 -0
  225. package/dist/define/index.js.map +1 -0
  226. package/dist/define/markdown_content.d.ts +15 -0
  227. package/dist/define/markdown_content.d.ts.map +1 -0
  228. package/dist/define/markdown_content.js +9 -0
  229. package/dist/define/markdown_content.js.map +1 -0
  230. package/dist/define/primitive_module.d.ts +421 -0
  231. package/dist/define/primitive_module.d.ts.map +1 -0
  232. package/dist/define/primitive_module.js +101 -0
  233. package/dist/define/primitive_module.js.map +1 -0
  234. package/dist/define/slack_assets.d.ts +28 -0
  235. package/dist/define/slack_assets.d.ts.map +1 -0
  236. package/dist/define/slack_assets.js +8 -0
  237. package/dist/define/slack_assets.js.map +1 -0
  238. package/dist/define/slack_blocks.d.ts +234 -0
  239. package/dist/define/slack_blocks.d.ts.map +1 -0
  240. package/dist/define/slack_blocks.js +8 -0
  241. package/dist/define/slack_blocks.js.map +1 -0
  242. package/dist/define/zod_format.d.ts +33 -0
  243. package/dist/define/zod_format.d.ts.map +1 -0
  244. package/dist/define/zod_format.js +114 -0
  245. package/dist/define/zod_format.js.map +1 -0
  246. package/dist/define/zod_helpers.d.ts +10 -0
  247. package/dist/define/zod_helpers.d.ts.map +1 -0
  248. package/dist/define/zod_helpers.js +22 -0
  249. package/dist/define/zod_helpers.js.map +1 -0
  250. package/dist/entries/html.d.ts +3 -0
  251. package/dist/entries/html.d.ts.map +1 -0
  252. package/dist/entries/html.js +8 -0
  253. package/dist/entries/html.js.map +1 -0
  254. package/dist/entries/index.d.ts +6 -0
  255. package/dist/entries/index.d.ts.map +1 -0
  256. package/dist/entries/index.js +12 -0
  257. package/dist/entries/index.js.map +1 -0
  258. package/dist/entries/markdown.d.ts +3 -0
  259. package/dist/entries/markdown.d.ts.map +1 -0
  260. package/dist/entries/markdown.js +8 -0
  261. package/dist/entries/markdown.js.map +1 -0
  262. package/dist/entries/react.d.ts +5 -0
  263. package/dist/entries/react.d.ts.map +1 -0
  264. package/dist/entries/react.js +11 -0
  265. package/dist/entries/react.js.map +1 -0
  266. package/dist/entries/slack.d.ts +2 -0
  267. package/dist/entries/slack.d.ts.map +1 -0
  268. package/dist/entries/slack.js +8 -0
  269. package/dist/entries/slack.js.map +1 -0
  270. package/dist/entries/text.d.ts +2 -0
  271. package/dist/entries/text.d.ts.map +1 -0
  272. package/dist/entries/text.js +8 -0
  273. package/dist/entries/text.js.map +1 -0
  274. package/dist/pack/capabilities.d.ts +27 -0
  275. package/dist/pack/capabilities.d.ts.map +1 -0
  276. package/dist/pack/capabilities.js +30 -0
  277. package/dist/pack/capabilities.js.map +1 -0
  278. package/dist/pack/compose.d.ts +21 -0
  279. package/dist/pack/compose.d.ts.map +1 -0
  280. package/dist/pack/compose.js +52 -0
  281. package/dist/pack/compose.js.map +1 -0
  282. package/dist/pack/enhancements.d.ts +65 -0
  283. package/dist/pack/enhancements.d.ts.map +1 -0
  284. package/dist/pack/enhancements.js +59 -0
  285. package/dist/pack/enhancements.js.map +1 -0
  286. package/dist/pack/index.d.ts +5 -0
  287. package/dist/pack/index.d.ts.map +1 -0
  288. package/dist/pack/index.js +11 -0
  289. package/dist/pack/index.js.map +1 -0
  290. package/dist/pack/primitive_pack.d.ts +155 -0
  291. package/dist/pack/primitive_pack.d.ts.map +1 -0
  292. package/dist/pack/primitive_pack.js +81 -0
  293. package/dist/pack/primitive_pack.js.map +1 -0
  294. package/dist/render/anchors.d.ts +82 -0
  295. package/dist/render/anchors.d.ts.map +1 -0
  296. package/dist/render/anchors.js +153 -0
  297. package/dist/render/anchors.js.map +1 -0
  298. package/dist/render/context_view.d.ts +10 -0
  299. package/dist/render/context_view.d.ts.map +1 -0
  300. package/dist/render/context_view.js +49 -0
  301. package/dist/render/context_view.js.map +1 -0
  302. package/dist/render/format_display_value.d.ts +20 -0
  303. package/dist/render/format_display_value.d.ts.map +1 -0
  304. package/dist/render/format_display_value.js +137 -0
  305. package/dist/render/format_display_value.js.map +1 -0
  306. package/dist/render/format_number.d.ts +9 -0
  307. package/dist/render/format_number.d.ts.map +1 -0
  308. package/dist/render/format_number.js +42 -0
  309. package/dist/render/format_number.js.map +1 -0
  310. package/dist/render/html/enhancements.d.ts +10 -0
  311. package/dist/render/html/enhancements.d.ts.map +1 -0
  312. package/dist/render/html/enhancements.js +25 -0
  313. package/dist/render/html/enhancements.js.map +1 -0
  314. package/dist/render/html/envelope.d.ts +182 -0
  315. package/dist/render/html/envelope.d.ts.map +1 -0
  316. package/dist/render/html/envelope.js +214 -0
  317. package/dist/render/html/envelope.js.map +1 -0
  318. package/dist/render/html/index.d.ts +3 -0
  319. package/dist/render/html/index.d.ts.map +1 -0
  320. package/dist/render/html/index.js +8 -0
  321. package/dist/render/html/index.js.map +1 -0
  322. package/dist/render/index.d.ts +6 -0
  323. package/dist/render/index.d.ts.map +1 -0
  324. package/dist/render/index.js +11 -0
  325. package/dist/render/index.js.map +1 -0
  326. package/dist/render/layout_check.d.ts +43 -0
  327. package/dist/render/layout_check.d.ts.map +1 -0
  328. package/dist/render/layout_check.js +129 -0
  329. package/dist/render/layout_check.js.map +1 -0
  330. package/dist/render/markdown/builder.d.ts +48 -0
  331. package/dist/render/markdown/builder.d.ts.map +1 -0
  332. package/dist/render/markdown/builder.js +183 -0
  333. package/dist/render/markdown/builder.js.map +1 -0
  334. package/dist/render/markdown/envelope.d.ts +20 -0
  335. package/dist/render/markdown/envelope.d.ts.map +1 -0
  336. package/dist/render/markdown/envelope.js +29 -0
  337. package/dist/render/markdown/envelope.js.map +1 -0
  338. package/dist/render/markdown/format.d.ts +3 -0
  339. package/dist/render/markdown/format.d.ts.map +1 -0
  340. package/dist/render/markdown/format.js +186 -0
  341. package/dist/render/markdown/format.js.map +1 -0
  342. package/dist/render/markdown/index.d.ts +3 -0
  343. package/dist/render/markdown/index.d.ts.map +1 -0
  344. package/dist/render/markdown/index.js +9 -0
  345. package/dist/render/markdown/index.js.map +1 -0
  346. package/dist/render/measure_dom.d.ts +10 -0
  347. package/dist/render/measure_dom.d.ts.map +1 -0
  348. package/dist/render/measure_dom.js +57 -0
  349. package/dist/render/measure_dom.js.map +1 -0
  350. package/dist/render/payload.d.ts +16 -0
  351. package/dist/render/payload.d.ts.map +1 -0
  352. package/dist/render/payload.js +9 -0
  353. package/dist/render/payload.js.map +1 -0
  354. package/dist/render/primitive_dispatch.d.ts +72 -0
  355. package/dist/render/primitive_dispatch.d.ts.map +1 -0
  356. package/dist/render/primitive_dispatch.js +183 -0
  357. package/dist/render/primitive_dispatch.js.map +1 -0
  358. package/dist/render/react/content.d.ts +40 -0
  359. package/dist/render/react/content.d.ts.map +1 -0
  360. package/dist/render/react/content.js +39 -0
  361. package/dist/render/react/content.js.map +1 -0
  362. package/dist/render/react/enhancements.d.ts +15 -0
  363. package/dist/render/react/enhancements.d.ts.map +1 -0
  364. package/dist/render/react/enhancements.js +28 -0
  365. package/dist/render/react/enhancements.js.map +1 -0
  366. package/dist/render/react/index.d.ts +3 -0
  367. package/dist/render/react/index.d.ts.map +1 -0
  368. package/dist/render/react/index.js +9 -0
  369. package/dist/render/react/index.js.map +1 -0
  370. package/dist/render/slack/assets.d.ts +16 -0
  371. package/dist/render/slack/assets.d.ts.map +1 -0
  372. package/dist/render/slack/assets.js +40 -0
  373. package/dist/render/slack/assets.js.map +1 -0
  374. package/dist/render/slack/blocks.d.ts +72 -0
  375. package/dist/render/slack/blocks.d.ts.map +1 -0
  376. package/dist/render/slack/blocks.js +77 -0
  377. package/dist/render/slack/blocks.js.map +1 -0
  378. package/dist/render/slack/envelope.d.ts +52 -0
  379. package/dist/render/slack/envelope.d.ts.map +1 -0
  380. package/dist/render/slack/envelope.js +547 -0
  381. package/dist/render/slack/envelope.js.map +1 -0
  382. package/dist/render/slack/format.d.ts +95 -0
  383. package/dist/render/slack/format.d.ts.map +1 -0
  384. package/dist/render/slack/format.js +807 -0
  385. package/dist/render/slack/format.js.map +1 -0
  386. package/dist/render/slack/index.d.ts +6 -0
  387. package/dist/render/slack/index.d.ts.map +1 -0
  388. package/dist/render/slack/index.js +12 -0
  389. package/dist/render/slack/index.js.map +1 -0
  390. package/dist/render/slack/markdown_content.d.ts +11 -0
  391. package/dist/render/slack/markdown_content.d.ts.map +1 -0
  392. package/dist/render/slack/markdown_content.js +354 -0
  393. package/dist/render/slack/markdown_content.js.map +1 -0
  394. package/dist/render/text/envelope.d.ts +15 -0
  395. package/dist/render/text/envelope.d.ts.map +1 -0
  396. package/dist/render/text/envelope.js +17 -0
  397. package/dist/render/text/envelope.js.map +1 -0
  398. package/dist/render/text/index.d.ts +2 -0
  399. package/dist/render/text/index.d.ts.map +1 -0
  400. package/dist/render/text/index.js +8 -0
  401. package/dist/render/text/index.js.map +1 -0
  402. package/dist/testing/conformance.d.ts +140 -0
  403. package/dist/testing/conformance.d.ts.map +1 -0
  404. package/dist/testing/conformance.js +287 -0
  405. package/dist/testing/conformance.js.map +1 -0
  406. package/dist/testing/index.d.ts +3 -0
  407. package/dist/testing/index.d.ts.map +1 -0
  408. package/dist/testing/index.js +9 -0
  409. package/dist/testing/index.js.map +1 -0
  410. package/dist/testing/registration.d.ts +32 -0
  411. package/dist/testing/registration.d.ts.map +1 -0
  412. package/dist/testing/registration.js +103 -0
  413. package/dist/testing/registration.js.map +1 -0
  414. package/dist/validate/authoring_schema.d.ts +27 -0
  415. package/dist/validate/authoring_schema.d.ts.map +1 -0
  416. package/dist/validate/authoring_schema.js +291 -0
  417. package/dist/validate/authoring_schema.js.map +1 -0
  418. package/dist/validate/composition_schema.d.ts +80 -0
  419. package/dist/validate/composition_schema.d.ts.map +1 -0
  420. package/dist/validate/composition_schema.js +127 -0
  421. package/dist/validate/composition_schema.js.map +1 -0
  422. package/dist/validate/index.d.ts +9 -0
  423. package/dist/validate/index.d.ts.map +1 -0
  424. package/dist/validate/index.js +15 -0
  425. package/dist/validate/index.js.map +1 -0
  426. package/dist/validate/input_budget.d.ts +35 -0
  427. package/dist/validate/input_budget.d.ts.map +1 -0
  428. package/dist/validate/input_budget.js +151 -0
  429. package/dist/validate/input_budget.js.map +1 -0
  430. package/dist/validate/json_schema.d.ts +32 -0
  431. package/dist/validate/json_schema.d.ts.map +1 -0
  432. package/dist/validate/json_schema.js +68 -0
  433. package/dist/validate/json_schema.js.map +1 -0
  434. package/dist/validate/node_issues.d.ts +12 -0
  435. package/dist/validate/node_issues.d.ts.map +1 -0
  436. package/dist/validate/node_issues.js +61 -0
  437. package/dist/validate/node_issues.js.map +1 -0
  438. package/dist/validate/url.d.ts +50 -0
  439. package/dist/validate/url.d.ts.map +1 -0
  440. package/dist/validate/url.js +107 -0
  441. package/dist/validate/url.js.map +1 -0
  442. package/dist/validate/validation.d.ts +105 -0
  443. package/dist/validate/validation.d.ts.map +1 -0
  444. package/dist/validate/validation.js +200 -0
  445. package/dist/validate/validation.js.map +1 -0
  446. package/dist/validate/value_schemas.d.ts +53 -0
  447. package/dist/validate/value_schemas.d.ts.map +1 -0
  448. package/dist/validate/value_schemas.js +50 -0
  449. package/dist/validate/value_schemas.js.map +1 -0
  450. package/package.json +118 -5
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Returns the URL, trimmed and with control characters stripped, when it
3
+ * satisfies the navigation policy (`https:` / `http:` / `mailto:` / relative
4
+ * path), `null` otherwise.
5
+ */
6
+ export declare const sanitizeNavigationHref: (href: string) => string | null;
7
+ /**
8
+ * Returns the URL, trimmed and with control characters stripped, when it
9
+ * satisfies the asset policy (`https:` / `http:` / relative path /
10
+ * `data:image/*`), `null` otherwise.
11
+ */
12
+ export declare const sanitizeAssetUrl: (url: string) => string | null;
13
+ /** Checks a Markdown parser's decoded destination without decoding it again. */
14
+ export declare const sanitizeParsedNavigationHref: (href: string) => string | null;
15
+ /** Checks a Markdown parser's decoded image destination. */
16
+ export declare const sanitizeParsedAssetUrl: (url: string) => string | null;
17
+ /**
18
+ * Render-time replacement for a navigation href that failed the policy: an
19
+ * inert same-document link, so the label stays visible without a destination.
20
+ */
21
+ export declare const BLOCKED_HREF = "#";
22
+ /** What {@link navigationHref} accepts, for a field description to state. */
23
+ export declare const NAVIGATION_HREF_RULE = "an https, http, or mailto URL, or a relative path";
24
+ /** What {@link assetUrl} accepts, for a field description to state. */
25
+ export declare const ASSET_URL_RULE = "an https, http, or data:image URL, or a relative path";
26
+ /** Validation message for {@link navigationHref}. */
27
+ export declare const NAVIGATION_HREF_MESSAGE = "must be an https, http, or mailto URL, or a relative path";
28
+ /** Validation message for {@link assetUrl}. */
29
+ export declare const ASSET_URL_MESSAGE = "must be an https, http, or data:image URL, or a relative path";
30
+ /** Options for {@link navigationHref} and {@link assetUrl}. */
31
+ export interface UrlSchemaOptions {
32
+ /** Longest accepted value, in characters. */
33
+ max?: number;
34
+ }
35
+ /**
36
+ * Zod schema for an `href`-like field: the validation layer of the two-layer
37
+ * policy, paired with {@link sanitizeNavigationHref} at render time.
38
+ *
39
+ * Its description states the rule, since a refinement's message does not
40
+ * reach the authoring JSON Schema. A field that describes itself should end
41
+ * with {@link NAVIGATION_HREF_RULE} so the model still reads it.
42
+ */
43
+ export declare const navigationHref: (options?: UrlSchemaOptions) => import("zod").ZodString;
44
+ /**
45
+ * Zod schema for a `src`-like field, paired with {@link sanitizeAssetUrl} at
46
+ * render time. Describes itself as {@link navigationHref} does, with
47
+ * {@link ASSET_URL_RULE}.
48
+ */
49
+ export declare const assetUrl: (options?: UrlSchemaOptions) => import("zod").ZodString;
50
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/validate/url.ts"],"names":[],"mappings":"AAsEA;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IACgB,CAAC;AAEhF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,IACgB,CAAC;AAEzE,gFAAgF;AAChF,eAAO,MAAM,4BAA4B,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAGpE,CAAC;AAEF,4DAA4D;AAC5D,eAAO,MAAM,sBAAsB,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,IAG7D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC,6EAA6E;AAC7E,eAAO,MAAM,oBAAoB,sDACoB,CAAC;AAEtD,uEAAuE;AACvE,eAAO,MAAM,cAAc,0DAC8B,CAAC;AAE1D,qDAAqD;AACrD,eAAO,MAAM,uBAAuB,8DAAoC,CAAC;AAEzE,+CAA+C;AAC/C,eAAO,MAAM,iBAAiB,kEAA8B,CAAC;AAE7D,+DAA+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,6CAA6C;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAYD;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,UAAS,gBAAqB,4BAM1D,CAAC;AAEJ;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,UAAS,gBAAqB,4BAMpD,CAAC"}
@@ -0,0 +1,107 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ import { requiredString } from '../define/zod_helpers.js';
8
+ // The one URL trust policy every URL-bearing field goes through, as a Zod
9
+ // refinement and again as render-time sanitization. See `docs/url-trust.md`.
10
+ const NAMED_REFERENCES = {
11
+ bsol: '\\',
12
+ colon: ':',
13
+ gt: '>',
14
+ lt: '<',
15
+ newline: '\n',
16
+ sol: '/',
17
+ tab: '\t',
18
+ };
19
+ // Numeric references, which browsers decode without a trailing `;`, and the
20
+ // named ones that spell a scheme, path, or tag character.
21
+ const CHARACTER_REFERENCE_RE = /&(?:#x([0-9a-f]+);?|#([0-9]+);?|(bsol|colon|gt|lt|newline|sol|tab);)/gi;
22
+ const decodeReference = (match, hex, decimal, name) => {
23
+ if (name)
24
+ return NAMED_REFERENCES[name.toLowerCase()] ?? match;
25
+ const codePoint = Number.parseInt(hex ?? decimal ?? '', hex ? 16 : 10);
26
+ return codePoint > 0 && codePoint <= 0x10ffff
27
+ ? String.fromCodePoint(codePoint)
28
+ : '\ufffd';
29
+ };
30
+ // The control characters browsers drop when parsing a URL.
31
+ const stripControls = (value) =>
32
+ // eslint-disable-next-line no-control-regex -- stripping control characters is the point.
33
+ value.replace(/[\u0000-\u001f\u007f]/g, '').trim();
34
+ // The URL as a sink sees it: references decoded once, then controls stripped,
35
+ // so an obfuscated scheme is checked as it would act. Only the decision reads
36
+ // it; the policy returns the authored value, since a consumer that decodes
37
+ // again must decode what was checked, not a decoded copy.
38
+ const decisionForm = (value) => stripControls(value.replace(CHARACTER_REFERENCE_RE, decodeReference));
39
+ // `<` and `>` must be percent-encoded in a URL, so their unencoded presence
40
+ // means the value is malformed or a parser-confusion attempt (an unterminated
41
+ // `<dest` would otherwise read as a relative path). Reject rather than strip.
42
+ const HAS_ANGLE_BRACKET_RE = /[<>]/;
43
+ const HAS_SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i;
44
+ const NAVIGATION_SCHEME_RE = /^(?:https?|mailto):/i;
45
+ const ASSET_SCHEME_RE = /^(?:https?:|data:image\/)/i;
46
+ // `//host` — and the `\` variants browsers fold into `/` — resolve against the
47
+ // current protocol onto a foreign host, so they are not relative paths.
48
+ const PROTOCOL_RELATIVE_RE = /^[/\\][/\\]/;
49
+ // Whether a URL in decision form passes, given which schemes are allowed.
50
+ const passes = (decided, schemes) => decided !== '' &&
51
+ !PROTOCOL_RELATIVE_RE.test(decided) &&
52
+ !HAS_ANGLE_BRACKET_RE.test(decided) &&
53
+ (!HAS_SCHEME_RE.test(decided) || schemes.test(decided));
54
+ /**
55
+ * Returns the URL, trimmed and with control characters stripped, when it
56
+ * satisfies the navigation policy (`https:` / `http:` / `mailto:` / relative
57
+ * path), `null` otherwise.
58
+ */
59
+ export const sanitizeNavigationHref = (href) => passes(decisionForm(href), NAVIGATION_SCHEME_RE) ? stripControls(href) : null;
60
+ /**
61
+ * Returns the URL, trimmed and with control characters stripped, when it
62
+ * satisfies the asset policy (`https:` / `http:` / relative path /
63
+ * `data:image/*`), `null` otherwise.
64
+ */
65
+ export const sanitizeAssetUrl = (url) => passes(decisionForm(url), ASSET_SCHEME_RE) ? stripControls(url) : null;
66
+ /** Checks a Markdown parser's decoded destination without decoding it again. */
67
+ export const sanitizeParsedNavigationHref = (href) => {
68
+ const normalized = stripControls(href);
69
+ return passes(normalized, NAVIGATION_SCHEME_RE) ? normalized : null;
70
+ };
71
+ /** Checks a Markdown parser's decoded image destination. */
72
+ export const sanitizeParsedAssetUrl = (url) => {
73
+ const normalized = stripControls(url);
74
+ return passes(normalized, ASSET_SCHEME_RE) ? normalized : null;
75
+ };
76
+ /**
77
+ * Render-time replacement for a navigation href that failed the policy: an
78
+ * inert same-document link, so the label stays visible without a destination.
79
+ */
80
+ export const BLOCKED_HREF = '#';
81
+ /** What {@link navigationHref} accepts, for a field description to state. */
82
+ export const NAVIGATION_HREF_RULE = 'an https, http, or mailto URL, or a relative path';
83
+ /** What {@link assetUrl} accepts, for a field description to state. */
84
+ export const ASSET_URL_RULE = 'an https, http, or data:image URL, or a relative path';
85
+ /** Validation message for {@link navigationHref}. */
86
+ export const NAVIGATION_HREF_MESSAGE = `must be ${NAVIGATION_HREF_RULE}`;
87
+ /** Validation message for {@link assetUrl}. */
88
+ export const ASSET_URL_MESSAGE = `must be ${ASSET_URL_RULE}`;
89
+ const urlSchema = (passes, rule, message, { max }) => (max === undefined ? requiredString() : requiredString().max(max))
90
+ .refine(passes, { error: message })
91
+ .describe(`${rule[0].toUpperCase()}${rule.slice(1)}.`);
92
+ /**
93
+ * Zod schema for an `href`-like field: the validation layer of the two-layer
94
+ * policy, paired with {@link sanitizeNavigationHref} at render time.
95
+ *
96
+ * Its description states the rule, since a refinement's message does not
97
+ * reach the authoring JSON Schema. A field that describes itself should end
98
+ * with {@link NAVIGATION_HREF_RULE} so the model still reads it.
99
+ */
100
+ export const navigationHref = (options = {}) => urlSchema((value) => sanitizeNavigationHref(value) !== null, NAVIGATION_HREF_RULE, NAVIGATION_HREF_MESSAGE, options);
101
+ /**
102
+ * Zod schema for a `src`-like field, paired with {@link sanitizeAssetUrl} at
103
+ * render time. Describes itself as {@link navigationHref} does, with
104
+ * {@link ASSET_URL_RULE}.
105
+ */
106
+ export const assetUrl = (options = {}) => urlSchema((value) => sanitizeAssetUrl(value) !== null, ASSET_URL_RULE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Ac,GAAG,CAAC,UAA4B,EAAE,EAAE,EAAE,CAC/D,SAAS,CACP,CAAC,KAAK,EAAE,EAAE,CAAC,sBAAsB,CAAC,KAAK,CAAC,KAAK,IAAI,EACjD,oBAAoB,EACpB,uBAAuB,EACvB,OAAO,CACR,CAAC;AAEJ;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,UAA4B,EAAE,EAAE,EAAE,CACzD,SAAS,CACP,CAAC,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,KAAK,IAAI,EAC3C,cAAc,EACd,iBAAiB,EACjB,OAAO,CACR,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { requiredString } from '../define/zod_helpers';\n\n// The one URL trust policy every URL-bearing field goes through, as a Zod\n// refinement and again as render-time sanitization. See `docs/url-trust.md`.\n\nconst NAMED_REFERENCES: Readonly<Record<string, string>> = {\n bsol: '\\\\',\n colon: ':',\n gt: '>',\n lt: '<',\n newline: '\\n',\n sol: '/',\n tab: '\\t',\n};\n\n// Numeric references, which browsers decode without a trailing `;`, and the\n// named ones that spell a scheme, path, or tag character.\nconst CHARACTER_REFERENCE_RE =\n /&(?:#x([0-9a-f]+);?|#([0-9]+);?|(bsol|colon|gt|lt|newline|sol|tab);)/gi;\n\nconst decodeReference = (\n match: string,\n hex: string | undefined,\n decimal: string | undefined,\n name: string | undefined\n): string => {\n if (name) return NAMED_REFERENCES[name.toLowerCase()] ?? match;\n const codePoint = Number.parseInt(hex ?? decimal ?? '', hex ? 16 : 10);\n return codePoint > 0 && codePoint <= 0x10ffff\n ? String.fromCodePoint(codePoint)\n : '\\ufffd';\n};\n\n// The control characters browsers drop when parsing a URL.\nconst stripControls = (value: string): string =>\n // eslint-disable-next-line no-control-regex -- stripping control characters is the point.\n value.replace(/[\\u0000-\\u001f\\u007f]/g, '').trim();\n\n// The URL as a sink sees it: references decoded once, then controls stripped,\n// so an obfuscated scheme is checked as it would act. Only the decision reads\n// it; the policy returns the authored value, since a consumer that decodes\n// again must decode what was checked, not a decoded copy.\nconst decisionForm = (value: string): string =>\n stripControls(value.replace(CHARACTER_REFERENCE_RE, decodeReference));\n\n// `<` and `>` must be percent-encoded in a URL, so their unencoded presence\n// means the value is malformed or a parser-confusion attempt (an unterminated\n// `<dest` would otherwise read as a relative path). Reject rather than strip.\nconst HAS_ANGLE_BRACKET_RE = /[<>]/;\nconst HAS_SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i;\nconst NAVIGATION_SCHEME_RE = /^(?:https?|mailto):/i;\nconst ASSET_SCHEME_RE = /^(?:https?:|data:image\\/)/i;\n// `//host` — and the `\\` variants browsers fold into `/` — resolve against the\n// current protocol onto a foreign host, so they are not relative paths.\nconst PROTOCOL_RELATIVE_RE = /^[/\\\\][/\\\\]/;\n\n// Whether a URL in decision form passes, given which schemes are allowed.\nconst passes = (decided: string, schemes: RegExp): boolean =>\n decided !== '' &&\n !PROTOCOL_RELATIVE_RE.test(decided) &&\n !HAS_ANGLE_BRACKET_RE.test(decided) &&\n (!HAS_SCHEME_RE.test(decided) || schemes.test(decided));\n\n/**\n * Returns the URL, trimmed and with control characters stripped, when it\n * satisfies the navigation policy (`https:` / `http:` / `mailto:` / relative\n * path), `null` otherwise.\n */\nexport const sanitizeNavigationHref = (href: string): string | null =>\n passes(decisionForm(href), NAVIGATION_SCHEME_RE) ? stripControls(href) : null;\n\n/**\n * Returns the URL, trimmed and with control characters stripped, when it\n * satisfies the asset policy (`https:` / `http:` / relative path /\n * `data:image/*`), `null` otherwise.\n */\nexport const sanitizeAssetUrl = (url: string): string | null =>\n passes(decisionForm(url), ASSET_SCHEME_RE) ? stripControls(url) : null;\n\n/** Checks a Markdown parser's decoded destination without decoding it again. */\nexport const sanitizeParsedNavigationHref = (href: string): string | null => {\n const normalized = stripControls(href);\n return passes(normalized, NAVIGATION_SCHEME_RE) ? normalized : null;\n};\n\n/** Checks a Markdown parser's decoded image destination. */\nexport const sanitizeParsedAssetUrl = (url: string): string | null => {\n const normalized = stripControls(url);\n return passes(normalized, ASSET_SCHEME_RE) ? normalized : null;\n};\n\n/**\n * Render-time replacement for a navigation href that failed the policy: an\n * inert same-document link, so the label stays visible without a destination.\n */\nexport const BLOCKED_HREF = '#';\n\n/** What {@link navigationHref} accepts, for a field description to state. */\nexport const NAVIGATION_HREF_RULE =\n 'an https, http, or mailto URL, or a relative path';\n\n/** What {@link assetUrl} accepts, for a field description to state. */\nexport const ASSET_URL_RULE =\n 'an https, http, or data:image URL, or a relative path';\n\n/** Validation message for {@link navigationHref}. */\nexport const NAVIGATION_HREF_MESSAGE = `must be ${NAVIGATION_HREF_RULE}`;\n\n/** Validation message for {@link assetUrl}. */\nexport const ASSET_URL_MESSAGE = `must be ${ASSET_URL_RULE}`;\n\n/** Options for {@link navigationHref} and {@link assetUrl}. */\nexport interface UrlSchemaOptions {\n /** Longest accepted value, in characters. */\n max?: number;\n}\n\nconst urlSchema = (\n passes: (value: string) => boolean,\n rule: string,\n message: string,\n { max }: UrlSchemaOptions\n) =>\n (max === undefined ? requiredString() : requiredString().max(max))\n .refine(passes, { error: message })\n .describe(`${rule[0]!.toUpperCase()}${rule.slice(1)}.`);\n\n/**\n * Zod schema for an `href`-like field: the validation layer of the two-layer\n * policy, paired with {@link sanitizeNavigationHref} at render time.\n *\n * Its description states the rule, since a refinement's message does not\n * reach the authoring JSON Schema. A field that describes itself should end\n * with {@link NAVIGATION_HREF_RULE} so the model still reads it.\n */\nexport const navigationHref = (options: UrlSchemaOptions = {}) =>\n urlSchema(\n (value) => sanitizeNavigationHref(value) !== null,\n NAVIGATION_HREF_RULE,\n NAVIGATION_HREF_MESSAGE,\n options\n );\n\n/**\n * Zod schema for a `src`-like field, paired with {@link sanitizeAssetUrl} at\n * render time. Describes itself as {@link navigationHref} does, with\n * {@link ASSET_URL_RULE}.\n */\nexport const assetUrl = (options: UrlSchemaOptions = {}) =>\n urlSchema(\n (value) => sanitizeAssetUrl(value) !== null,\n ASSET_URL_RULE,\n ASSET_URL_MESSAGE,\n options\n );\n"]}
@@ -0,0 +1,105 @@
1
+ import { type SurfaceName } from '../composition/body_node_base.js';
2
+ import type { Composition } from '../composition/composition.js';
3
+ import type { PrimitiveNode } from '../composition/node.js';
4
+ import { CompositionValidationError, type ValidationError } from '../composition/validation_error.js';
5
+ import type { AnyPrimitiveDefinition } from '../define/primitive_module.js';
6
+ import { type InputBudget } from './input_budget.js';
7
+ /**
8
+ * A non-fatal validation finding, scoped to the surface it concerns.
9
+ *
10
+ * Warnings carry `surface` because every one of them is a statement about one
11
+ * render target — a composition that draws nothing on `slack` is not news to a
12
+ * caller rendering HTML. Without the scope a host receives every surface's
13
+ * findings on every call and learns to ignore the channel.
14
+ * {@link warningsForSurface} is the filter.
15
+ */
16
+ export interface ValidationWarning {
17
+ /** The render target this finding concerns, never the composition as a whole. */
18
+ surface: SurfaceName;
19
+ /**
20
+ * Path of the offending node within the composition, absent for
21
+ * whole-composition findings.
22
+ */
23
+ path?: string;
24
+ /** Safe to show a user, and phrased for whoever can act on it. */
25
+ message: string;
26
+ }
27
+ /**
28
+ * The outcome of `validate`: errors are fatal, warnings are advisory.
29
+ *
30
+ * `valid` tracks `errors` only — a composition can be valid and still carry
31
+ * warnings, which is the normal case for a surface gap.
32
+ */
33
+ export interface ValidationResult {
34
+ /** True when `errors` is empty, regardless of `warnings`. */
35
+ valid: boolean;
36
+ /** Fatal findings. Empty when `valid`. */
37
+ errors: ValidationError[];
38
+ /** Advisory findings, empty when there are none. */
39
+ warnings: ValidationWarning[];
40
+ }
41
+ declare const checkedComposition: unique symbol;
42
+ /** The copy {@link createCompositionValidator} checked, which a validating render draws in place of the caller's value. The brand is type-only. */
43
+ export type CheckedComposition<TNode extends PrimitiveNode = PrimitiveNode> = Composition<TNode> & {
44
+ readonly [checkedComposition]: true;
45
+ };
46
+ /** A {@link ValidationResult} with the composition it describes. */
47
+ export interface CheckedValidationResult<TNode extends PrimitiveNode = PrimitiveNode> extends ValidationResult {
48
+ /** Undefined only when {@link checkInputBudget} refused the input. */
49
+ composition: CheckedComposition<TNode> | undefined;
50
+ }
51
+ /** Narrows a result's warnings to the surface a caller is about to render. */
52
+ export declare const warningsForSurface: (result: ValidationResult, surface: SurfaceName) => ValidationWarning[];
53
+ /** Whether a render reports validation findings or raises on them. */
54
+ export type ValidationErrorMode = 'collect' | 'throw';
55
+ export { CompositionValidationError };
56
+ /** Raises {@link CompositionValidationError} when `mode` is `throw` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input, which nothing can render. */
57
+ export declare const enforceValidationMode: (result: ValidationResult, mode?: ValidationErrorMode) => void;
58
+ /** The composition `result` checked, which is what a render draws. Throws {@link CompositionValidationError} when `mode` is `'throw'` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input. */
59
+ export declare const compositionToRender: <TNode extends PrimitiveNode>(result: CheckedValidationResult<TNode>, mode?: ValidationErrorMode) => CheckedComposition<TNode>;
60
+ /** Runtime facts the semantic passes need beyond the primitive inventory. */
61
+ export interface CompositionValidatorOptions {
62
+ /**
63
+ * Whether any frame the runtime can draw with sizes itself from node heights,
64
+ * which is what makes a missing `metrics.svgHeight` matter.
65
+ *
66
+ * A runtime-wide question rather than a per-node one, because a frame is a
67
+ * runtime input: any node can be drawn under any frame, so the metric is
68
+ * load-bearing as soon as one frame consults it. Defaults to `false`, so a
69
+ * runtime with no frame at all reports nothing about a value nothing reads.
70
+ */
71
+ sizesFromNodeHeights?: boolean;
72
+ /** Limits checked before the schema runs; see {@link checkInputBudget}. */
73
+ inputBudget?: InputBudget;
74
+ }
75
+ /**
76
+ * Builds the trusted-input validator: {@link checkInputBudget}, then the schema and the semantic passes on its copy, which the result carries.
77
+ *
78
+ * `definitions` is memoized on array identity, so a caller that rebuilds the
79
+ * array per call (`createCompositionValidator(packs.flatMap(…))`) resolves a
80
+ * fresh discriminated union each time. Hold the array `composePacks` returns
81
+ * and reuse it across the validator, the parser, and the authoring context.
82
+ */
83
+ export declare const createCompositionValidator: <TNode extends PrimitiveNode = PrimitiveNode>(definitions: readonly AnyPrimitiveDefinition[], options?: CompositionValidatorOptions) => ((composition: Composition<TNode>) => CheckedValidationResult<TNode>);
84
+ /** The outcome of `parse`. */
85
+ export interface ParsedComposition {
86
+ /** True when the value matched the schema. Says nothing about id uniqueness. */
87
+ valid: boolean;
88
+ /** Schema failures. Empty when `valid`. */
89
+ errors: ValidationError[];
90
+ /** The parsed document, present only when `valid`. */
91
+ composition?: Composition;
92
+ }
93
+ /**
94
+ * Builds the untrusted-input parser: {@link checkInputBudget}, then the schema only on its copy, reported rather than thrown.
95
+ *
96
+ * Deliberately narrower than {@link createCompositionValidator}. This answers
97
+ * "is this a `Composition`", not "is this a good one" — it does not run the
98
+ * duplicate-id pass or produce warnings, so a composition with two nodes
99
+ * sharing an `id` parses as valid. Id uniqueness is a `validate` guarantee, so
100
+ * a caller that wants the semantic checks runs `validate` on the result.
101
+ *
102
+ * Shares {@link createCompositionValidator}'s memoization identity requirement.
103
+ */
104
+ export declare const createCompositionParser: (definitions: readonly AnyPrimitiveDefinition[], { inputBudget }?: Pick<CompositionValidatorOptions, "inputBudget">) => ((value: unknown) => ParsedComposition);
105
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validate/validation.ts"],"names":[],"mappings":"AAOA,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EACL,0BAA0B,EAC1B,KAAK,eAAe,EACrB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA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B,GAAI,KAAK,SAAS,aAAa,EAC7D,QAAQ,uBAAuB,CAAC,KAAK,CAAC,EACtC,OAAO,mBAAmB,KACzB,kBAAkB,CAAC,KAAK,CAO1B,CAAC;AAEF,6EAA6E;AAC7E,MAAM,WAAW,2BAA2B;IAC1C;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,2EAA2E;IAC3E,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAUD;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,GACrC,KAAK,SAAS,aAAa,GAAG,aAAa,EAE3C,aAAa,SAAS,sBAAsB,EAAE,EAC9C,UAAS,2BAAgC,KACxC,CAAC,CAAC,WAAW,EAAE,WAAW,CAAC,KAAK,CAAC,KAAK,uBAAuB,CAAC,KAAK,CAAC,CAuCtE,CAAC;AAEF,8BAA8B;AAC9B,MAAM,WAAW,iBAAiB;IAChC,gFAAgF;IAChF,KAAK,EAAE,OAAO,CAAC;IACf,2CAA2C;IAC3C,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,sDAAsD;IACtD,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GAClC,aAAa,SAAS,sBAAsB,EAAE,EAC9C,kBAAiB,IAAI,CAAC,2BAA2B,EAAE,aAAa,CAAM,KACrE,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,iBAAiB,CAqBxC,CAAC"}
@@ -0,0 +1,200 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ import { BODY_NODE_SURFACES, childNodePath, createChildNodeWalker, isVisibleOnSurface, rendersOnSurface, } from '../composition/body_node_base.js';
8
+ import { quoteText } from '../composition/one_line.js';
9
+ import { CompositionValidationError, } from '../composition/validation_error.js';
10
+ import { getCompositionSchemaForDefinitions } from './composition_schema.js';
11
+ import { checkInputBudget, isInputRefusal, } from './input_budget.js';
12
+ import { createNodeIssueFormatter } from './node_issues.js';
13
+ const checkedComposition = Symbol.for('elastic.isomer.checked_composition');
14
+ /** Narrows a result's warnings to the surface a caller is about to render. */
15
+ export const warningsForSurface = (result, surface) => result.warnings.filter((warning) => warning.surface === surface);
16
+ export { CompositionValidationError };
17
+ /** Raises {@link CompositionValidationError} when `mode` is `throw` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input, which nothing can render. */
18
+ export const enforceValidationMode = (result, mode) => {
19
+ if (!result.valid &&
20
+ (mode === 'throw' || result.errors.some(isInputRefusal))) {
21
+ throw new CompositionValidationError(result.errors);
22
+ }
23
+ };
24
+ /** The composition `result` checked, which is what a render draws. Throws {@link CompositionValidationError} when `mode` is `'throw'` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input. */
25
+ export const compositionToRender = (result, mode) => {
26
+ enforceValidationMode(result, mode);
27
+ const { composition } = result;
28
+ if (composition === undefined) {
29
+ throw new CompositionValidationError(result.errors);
30
+ }
31
+ return composition;
32
+ };
33
+ /** The body's nodes, as {@link IssueRoot}s for a node issue formatter. */
34
+ const bodyRoots = (value) => {
35
+ const { body } = (value ?? {});
36
+ return Array.isArray(body)
37
+ ? body.map((node, index) => [node, `body[${index}]`])
38
+ : [];
39
+ };
40
+ /**
41
+ * Builds the trusted-input validator: {@link checkInputBudget}, then the schema and the semantic passes on its copy, which the result carries.
42
+ *
43
+ * `definitions` is memoized on array identity, so a caller that rebuilds the
44
+ * array per call (`createCompositionValidator(packs.flatMap(…))`) resolves a
45
+ * fresh discriminated union each time. Hold the array `composePacks` returns
46
+ * and reuse it across the validator, the parser, and the authoring context.
47
+ */
48
+ export const createCompositionValidator = (definitions, options = {}) => {
49
+ const schema = getCompositionSchemaForDefinitions(definitions);
50
+ const walk = createChildNodeWalker(definitions);
51
+ const formatIssues = createNodeIssueFormatter(definitions);
52
+ return (composition) => {
53
+ const checked = checkInputBudget(composition, options.inputBudget);
54
+ if (!checked.valid) {
55
+ return {
56
+ valid: false,
57
+ errors: [checked.error],
58
+ warnings: [],
59
+ composition: undefined,
60
+ };
61
+ }
62
+ const plain = checked.value;
63
+ const result = schema.safeParse(plain, { reportInput: true });
64
+ if (result.success) {
65
+ const { body } = plain;
66
+ const idErrors = collectDuplicateNodeIdErrors(body, walk);
67
+ const warnings = [
68
+ ...collectEmptySurfaceWarnings(body, walk),
69
+ ...(options.sizesFromNodeHeights
70
+ ? collectMissingSvgHeightWarnings(body, definitions, walk)
71
+ : []),
72
+ ];
73
+ return {
74
+ valid: idErrors.length === 0,
75
+ errors: idErrors,
76
+ warnings,
77
+ composition: plain,
78
+ };
79
+ }
80
+ return {
81
+ valid: false,
82
+ errors: formatIssues(bodyRoots(plain), result.error.issues),
83
+ warnings: [],
84
+ composition: plain,
85
+ };
86
+ };
87
+ };
88
+ /**
89
+ * Builds the untrusted-input parser: {@link checkInputBudget}, then the schema only on its copy, reported rather than thrown.
90
+ *
91
+ * Deliberately narrower than {@link createCompositionValidator}. This answers
92
+ * "is this a `Composition`", not "is this a good one" — it does not run the
93
+ * duplicate-id pass or produce warnings, so a composition with two nodes
94
+ * sharing an `id` parses as valid. Id uniqueness is a `validate` guarantee, so
95
+ * a caller that wants the semantic checks runs `validate` on the result.
96
+ *
97
+ * Shares {@link createCompositionValidator}'s memoization identity requirement.
98
+ */
99
+ export const createCompositionParser = (definitions, { inputBudget } = {}) => {
100
+ const schema = getCompositionSchemaForDefinitions(definitions);
101
+ const formatIssues = createNodeIssueFormatter(definitions);
102
+ return (value) => {
103
+ const checked = checkInputBudget(value, inputBudget);
104
+ if (!checked.valid) {
105
+ return { valid: false, errors: [checked.error] };
106
+ }
107
+ const result = schema.safeParse(checked.value, { reportInput: true });
108
+ if (result.success) {
109
+ return {
110
+ valid: true,
111
+ errors: [],
112
+ composition: result.data,
113
+ };
114
+ }
115
+ return {
116
+ valid: false,
117
+ errors: formatIssues(bodyRoots(checked.value), result.error.issues),
118
+ };
119
+ };
120
+ };
121
+ /** Warns once per surface that the whole body renders nothing on. */
122
+ const collectEmptySurfaceWarnings = (body, walk) => BODY_NODE_SURFACES.filter((surface) => !body.some((node) => rendersOnSurface(node, surface, walk))).map((surface) => ({
123
+ surface,
124
+ message: `composition renders no nodes on surface "${surface}"`,
125
+ }));
126
+ /**
127
+ * Warns for each node that renders to `svg` but declares no `svgHeight`.
128
+ *
129
+ * `metrics.svgHeight` is optional, so `dispatcher.estimateSvgHeight` returns
130
+ * `0` for such a node and a frame that sums node heights sizes short.
131
+ *
132
+ * Whether a runtime consults the metric at all is the caller's to decide; see
133
+ * {@link CompositionValidatorOptions.sizesFromNodeHeights}. A fixed-size frame
134
+ * never does, and warning about a value nothing reads is how a warning channel
135
+ * gets ignored.
136
+ */
137
+ const collectMissingSvgHeightWarnings = (body, definitions, walk) => {
138
+ const unmeasured = new Set(definitions
139
+ .filter((definition) => !definition.metrics?.svgHeight)
140
+ .map((definition) => definition.type));
141
+ if (unmeasured.size === 0) {
142
+ return [];
143
+ }
144
+ const warnings = [];
145
+ const visit = (node, path) => {
146
+ if (!node || typeof node !== 'object' || !isVisibleOnSurface(node, 'svg')) {
147
+ return;
148
+ }
149
+ const { type } = node;
150
+ if (typeof type === 'string' && unmeasured.has(type)) {
151
+ warnings.push({
152
+ surface: 'svg',
153
+ path,
154
+ message: `${path} type ${quoteText(type)} declares no svgHeight metric and will be measured as 0, sizing the frame short`,
155
+ });
156
+ }
157
+ walk(node).forEach(({ node: child, path: field }) => {
158
+ visit(child, childNodePath(path, field));
159
+ });
160
+ };
161
+ body.forEach((node, index) => visit(node, `body[${index}]`));
162
+ return warnings;
163
+ };
164
+ /**
165
+ * Errors for each node whose `id` repeats one already seen, naming the first
166
+ * use.
167
+ *
168
+ * Errors rather than warnings, because ids are what a host addresses a node by.
169
+ * Run by `validate` and deliberately not by `parse`; see
170
+ * {@link createCompositionParser}.
171
+ */
172
+ const collectDuplicateNodeIdErrors = (body, walk) => {
173
+ const errors = [];
174
+ const seen = new Map();
175
+ const visit = (node, path) => {
176
+ if (!node || typeof node !== 'object') {
177
+ return;
178
+ }
179
+ const { id, type } = node;
180
+ if (typeof id === 'string') {
181
+ const first = seen.get(id);
182
+ if (first) {
183
+ errors.push({
184
+ path: `${path}.id`,
185
+ message: `duplicates id ${quoteText(id)} first used at ${first}`,
186
+ ...(typeof type === 'string' ? { nodeType: type } : {}),
187
+ });
188
+ }
189
+ else {
190
+ seen.set(id, path);
191
+ }
192
+ }
193
+ walk(node).forEach(({ node: child, path: field }) => {
194
+ visit(child, childNodePath(path, field));
195
+ });
196
+ };
197
+ body.forEach((node, index) => visit(node, `body[${index}]`));
198
+ return errors;
199
+ };
200
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validate/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EACL,0BAA0B,GAE3B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,kCAAkC,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EACL,gBAAgB,EAEhB,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAkB,MAAM,eAAe,CAAC;AAsCzE,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAc5E,8EAA8E;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAwB,EACxB,OAAoB,EACC,EAAE,CACvB,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OA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AE,CAAC;iBACxD,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;YAClD,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC;IAC7D,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport {\n BODY_NODE_SURFACES,\n childNodePath,\n createChildNodeWalker,\n isVisibleOnSurface,\n rendersOnSurface,\n type SurfaceName,\n} from '../composition/body_node_base';\nimport type { Composition } from '../composition/composition';\nimport type { PrimitiveNode } from '../composition/node';\nimport { quoteText } from '../composition/one_line';\nimport {\n CompositionValidationError,\n type ValidationError,\n} from '../composition/validation_error';\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport { getCompositionSchemaForDefinitions } from './composition_schema';\nimport {\n checkInputBudget,\n type InputBudget,\n isInputRefusal,\n} from './input_budget';\nimport { createNodeIssueFormatter, type IssueRoot } from './node_issues';\n\n/**\n * A non-fatal validation finding, scoped to the surface it concerns.\n *\n * Warnings carry `surface` because every one of them is a statement about one\n * render target — a composition that draws nothing on `slack` is not news to a\n * caller rendering HTML. Without the scope a host receives every surface's\n * findings on every call and learns to ignore the channel.\n * {@link warningsForSurface} is the filter.\n */\nexport interface ValidationWarning {\n /** The render target this finding concerns, never the composition as a whole. */\n surface: SurfaceName;\n /**\n * Path of the offending node within the composition, absent for\n * whole-composition findings.\n */\n path?: string;\n /** Safe to show a user, and phrased for whoever can act on it. */\n message: string;\n}\n\n/**\n * The outcome of `validate`: errors are fatal, warnings are advisory.\n *\n * `valid` tracks `errors` only — a composition can be valid and still carry\n * warnings, which is the normal case for a surface gap.\n */\nexport interface ValidationResult {\n /** True when `errors` is empty, regardless of `warnings`. */\n valid: boolean;\n /** Fatal findings. Empty when `valid`. */\n errors: ValidationError[];\n /** Advisory findings, empty when there are none. */\n warnings: ValidationWarning[];\n}\n\nconst checkedComposition = Symbol.for('elastic.isomer.checked_composition');\n\n/** The copy {@link createCompositionValidator} checked, which a validating render draws in place of the caller's value. The brand is type-only. */\nexport type CheckedComposition<TNode extends PrimitiveNode = PrimitiveNode> =\n Composition<TNode> & { readonly [checkedComposition]: true };\n\n/** A {@link ValidationResult} with the composition it describes. */\nexport interface CheckedValidationResult<\n TNode extends PrimitiveNode = PrimitiveNode,\n> extends ValidationResult {\n /** Undefined only when {@link checkInputBudget} refused the input. */\n composition: CheckedComposition<TNode> | undefined;\n}\n\n/** Narrows a result's warnings to the surface a caller is about to render. */\nexport const warningsForSurface = (\n result: ValidationResult,\n surface: SurfaceName\n): ValidationWarning[] =>\n result.warnings.filter((warning) => warning.surface === surface);\n\n/** Whether a render reports validation findings or raises on them. */\nexport type ValidationErrorMode = 'collect' | 'throw';\n\nexport { CompositionValidationError };\n\n/** Raises {@link CompositionValidationError} when `mode` is `throw` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input, which nothing can render. */\nexport const enforceValidationMode = (\n result: ValidationResult,\n mode?: ValidationErrorMode\n): void => {\n if (\n !result.valid &&\n (mode === 'throw' || result.errors.some(isInputRefusal))\n ) {\n throw new CompositionValidationError(result.errors);\n }\n};\n\n/** The composition `result` checked, which is what a render draws. Throws {@link CompositionValidationError} when `mode` is `'throw'` and `result` is invalid, or in any mode when {@link checkInputBudget} refused the input. */\nexport const compositionToRender = <TNode extends PrimitiveNode>(\n result: CheckedValidationResult<TNode>,\n mode?: ValidationErrorMode\n): CheckedComposition<TNode> => {\n enforceValidationMode(result, mode);\n const { composition } = result;\n if (composition === undefined) {\n throw new CompositionValidationError(result.errors);\n }\n return composition;\n};\n\n/** Runtime facts the semantic passes need beyond the primitive inventory. */\nexport interface CompositionValidatorOptions {\n /**\n * Whether any frame the runtime can draw with sizes itself from node heights,\n * which is what makes a missing `metrics.svgHeight` matter.\n *\n * A runtime-wide question rather than a per-node one, because a frame is a\n * runtime input: any node can be drawn under any frame, so the metric is\n * load-bearing as soon as one frame consults it. Defaults to `false`, so a\n * runtime with no frame at all reports nothing about a value nothing reads.\n */\n sizesFromNodeHeights?: boolean;\n /** Limits checked before the schema runs; see {@link checkInputBudget}. */\n inputBudget?: InputBudget;\n}\n\n/** The body's nodes, as {@link IssueRoot}s for a node issue formatter. */\nconst bodyRoots = (value: unknown): IssueRoot[] => {\n const { body } = (value ?? {}) as { body?: unknown };\n return Array.isArray(body)\n ? body.map((node, index) => [node, `body[${index}]`] as const)\n : [];\n};\n\n/**\n * Builds the trusted-input validator: {@link checkInputBudget}, then the schema and the semantic passes on its copy, which the result carries.\n *\n * `definitions` is memoized on array identity, so a caller that rebuilds the\n * array per call (`createCompositionValidator(packs.flatMap(…))`) resolves a\n * fresh discriminated union each time. Hold the array `composePacks` returns\n * and reuse it across the validator, the parser, and the authoring context.\n */\nexport const createCompositionValidator = <\n TNode extends PrimitiveNode = PrimitiveNode,\n>(\n definitions: readonly AnyPrimitiveDefinition[],\n options: CompositionValidatorOptions = {}\n): ((composition: Composition<TNode>) => CheckedValidationResult<TNode>) => {\n const schema = getCompositionSchemaForDefinitions(definitions);\n const walk = createChildNodeWalker(definitions);\n const formatIssues = createNodeIssueFormatter(definitions);\n return (composition) => {\n const checked = checkInputBudget(composition, options.inputBudget);\n if (!checked.valid) {\n return {\n valid: false,\n errors: [checked.error],\n warnings: [],\n composition: undefined,\n };\n }\n const plain = checked.value as CheckedComposition<TNode>;\n const result = schema.safeParse(plain, { reportInput: true });\n if (result.success) {\n const { body } = plain;\n const idErrors = collectDuplicateNodeIdErrors(body, walk);\n const warnings = [\n ...collectEmptySurfaceWarnings(body, walk),\n ...(options.sizesFromNodeHeights\n ? collectMissingSvgHeightWarnings(body, definitions, walk)\n : []),\n ];\n return {\n valid: idErrors.length === 0,\n errors: idErrors,\n warnings,\n composition: plain,\n };\n }\n return {\n valid: false,\n errors: formatIssues(bodyRoots(plain), result.error.issues),\n warnings: [],\n composition: plain,\n };\n };\n};\n\n/** The outcome of `parse`. */\nexport interface ParsedComposition {\n /** True when the value matched the schema. Says nothing about id uniqueness. */\n valid: boolean;\n /** Schema failures. Empty when `valid`. */\n errors: ValidationError[];\n /** The parsed document, present only when `valid`. */\n composition?: Composition;\n}\n\n/**\n * Builds the untrusted-input parser: {@link checkInputBudget}, then the schema only on its copy, reported rather than thrown.\n *\n * Deliberately narrower than {@link createCompositionValidator}. This answers\n * \"is this a `Composition`\", not \"is this a good one\" — it does not run the\n * duplicate-id pass or produce warnings, so a composition with two nodes\n * sharing an `id` parses as valid. Id uniqueness is a `validate` guarantee, so\n * a caller that wants the semantic checks runs `validate` on the result.\n *\n * Shares {@link createCompositionValidator}'s memoization identity requirement.\n */\nexport const createCompositionParser = (\n definitions: readonly AnyPrimitiveDefinition[],\n { inputBudget }: Pick<CompositionValidatorOptions, 'inputBudget'> = {}\n): ((value: unknown) => ParsedComposition) => {\n const schema = getCompositionSchemaForDefinitions(definitions);\n const formatIssues = createNodeIssueFormatter(definitions);\n return (value) => {\n const checked = checkInputBudget(value, inputBudget);\n if (!checked.valid) {\n return { valid: false, errors: [checked.error] };\n }\n const result = schema.safeParse(checked.value, { reportInput: true });\n if (result.success) {\n return {\n valid: true,\n errors: [],\n composition: result.data as unknown as Composition,\n };\n }\n return {\n valid: false,\n errors: formatIssues(bodyRoots(checked.value), result.error.issues),\n };\n };\n};\n\n/** Warns once per surface that the whole body renders nothing on. */\nconst collectEmptySurfaceWarnings = (\n body: readonly unknown[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationWarning[] =>\n BODY_NODE_SURFACES.filter(\n (surface) => !body.some((node) => rendersOnSurface(node, surface, walk))\n ).map((surface) => ({\n surface,\n message: `composition renders no nodes on surface \"${surface}\"`,\n }));\n\n/**\n * Warns for each node that renders to `svg` but declares no `svgHeight`.\n *\n * `metrics.svgHeight` is optional, so `dispatcher.estimateSvgHeight` returns\n * `0` for such a node and a frame that sums node heights sizes short.\n *\n * Whether a runtime consults the metric at all is the caller's to decide; see\n * {@link CompositionValidatorOptions.sizesFromNodeHeights}. A fixed-size frame\n * never does, and warning about a value nothing reads is how a warning channel\n * gets ignored.\n */\nconst collectMissingSvgHeightWarnings = (\n body: readonly unknown[],\n definitions: readonly AnyPrimitiveDefinition[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationWarning[] => {\n const unmeasured = new Set(\n definitions\n .filter((definition) => !definition.metrics?.svgHeight)\n .map((definition) => definition.type)\n );\n if (unmeasured.size === 0) {\n return [];\n }\n const warnings: ValidationWarning[] = [];\n const visit = (node: unknown, path: string): void => {\n if (!node || typeof node !== 'object' || !isVisibleOnSurface(node, 'svg')) {\n return;\n }\n const { type } = node as { type?: unknown };\n if (typeof type === 'string' && unmeasured.has(type)) {\n warnings.push({\n surface: 'svg',\n path,\n message: `${path} type ${quoteText(type)} declares no svgHeight metric and will be measured as 0, sizing the frame short`,\n });\n }\n walk(node).forEach(({ node: child, path: field }) => {\n visit(child, childNodePath(path, field));\n });\n };\n body.forEach((node, index) => visit(node, `body[${index}]`));\n return warnings;\n};\n\n/**\n * Errors for each node whose `id` repeats one already seen, naming the first\n * use.\n *\n * Errors rather than warnings, because ids are what a host addresses a node by.\n * Run by `validate` and deliberately not by `parse`; see\n * {@link createCompositionParser}.\n */\nconst collectDuplicateNodeIdErrors = (\n body: readonly unknown[],\n walk: ReturnType<typeof createChildNodeWalker>\n): ValidationError[] => {\n const errors: ValidationError[] = [];\n const seen = new Map<string, string>();\n const visit = (node: unknown, path: string): void => {\n if (!node || typeof node !== 'object') {\n return;\n }\n const { id, type } = node as { id?: unknown; type?: unknown };\n if (typeof id === 'string') {\n const first = seen.get(id);\n if (first) {\n errors.push({\n path: `${path}.id`,\n message: `duplicates id ${quoteText(id)} first used at ${first}`,\n ...(typeof type === 'string' ? { nodeType: type } : {}),\n });\n } else {\n seen.set(id, path);\n }\n }\n walk(node).forEach(({ node: child, path: field }) => {\n visit(child, childNodePath(path, field));\n });\n };\n body.forEach((node, index) => visit(node, `body[${index}]`));\n return errors;\n};\n"]}
@@ -0,0 +1,53 @@
1
+ import { z } from 'zod';
2
+ /** Derived from {@link ALL_NAMED_COLORS} rather than restating the literals. */
3
+ export declare const namedColorSchema: z.ZodEnum<{
4
+ primary: "primary";
5
+ danger: "danger";
6
+ success: "success";
7
+ neutral: "neutral";
8
+ accent: "accent";
9
+ warning: "warning";
10
+ risk: "risk";
11
+ }>;
12
+ /** `RenderTheme`: the light/dark preference a caller asks for. */
13
+ export declare const renderThemeSchema: z.ZodEnum<{
14
+ auto: "auto";
15
+ light: "light";
16
+ dark: "dark";
17
+ }>;
18
+ /**
19
+ * The raw quantity plus a format hint, formatted once in a primitive's model so
20
+ * every surface renders the same string. See `StructuredValue`.
21
+ */
22
+ export declare const structuredValueSchema: z.ZodObject<{
23
+ raw: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
24
+ format: z.ZodOptional<z.ZodEnum<{
25
+ number: "number";
26
+ date: "date";
27
+ compact: "compact";
28
+ percent: "percent";
29
+ currency: "currency";
30
+ bytes: "bytes";
31
+ duration: "duration";
32
+ relativeTime: "relativeTime";
33
+ }>>;
34
+ precision: z.ZodOptional<z.ZodNumber>;
35
+ currency: z.ZodOptional<z.ZodString>;
36
+ }, z.core.$strip>;
37
+ /** Value-bearing fields accept preformatted prose or a structured value. */
38
+ export declare const displayValueSchema: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
39
+ raw: z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>;
40
+ format: z.ZodOptional<z.ZodEnum<{
41
+ number: "number";
42
+ date: "date";
43
+ compact: "compact";
44
+ percent: "percent";
45
+ currency: "currency";
46
+ bytes: "bytes";
47
+ duration: "duration";
48
+ relativeTime: "relativeTime";
49
+ }>>;
50
+ precision: z.ZodOptional<z.ZodNumber>;
51
+ currency: z.ZodOptional<z.ZodString>;
52
+ }, z.core.$strip>]>;
53
+ //# sourceMappingURL=value_schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value_schemas.d.ts","sourceRoot":"","sources":["../../src/validate/value_schemas.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAYxB,gFAAgF;AAChF,eAAO,MAAM,gBAAgB;;;;;;;;EAE5B,CAAC;AAEF,kEAAkE;AAClE,eAAO,MAAM,iBAAiB;;;;EAAwC,CAAC;AAEvE;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;iBAiBhC,CAAC;AAEH,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;mBAM9B,CAAC"}