@elastic/isomer-sdk 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (492) hide show
  1. package/LICENSE.txt +93 -0
  2. package/NOTICE.txt +1861 -0
  3. package/README.md +69 -0
  4. package/THIRD_PARTY_LICENSES.md +957 -0
  5. package/dist/author/authored_fields.d.ts +153 -0
  6. package/dist/author/authored_fields.d.ts.map +1 -0
  7. package/dist/author/authored_fields.js +227 -0
  8. package/dist/author/authored_fields.js.map +1 -0
  9. package/dist/author/authoring_input.d.ts +7 -0
  10. package/dist/author/authoring_input.d.ts.map +1 -0
  11. package/dist/author/authoring_input.js +60 -0
  12. package/dist/author/authoring_input.js.map +1 -0
  13. package/dist/author/authoring_model.d.ts +27 -0
  14. package/dist/author/authoring_model.d.ts.map +1 -0
  15. package/dist/author/authoring_model.js +98 -0
  16. package/dist/author/authoring_model.js.map +1 -0
  17. package/dist/author/declarations.d.ts +13 -0
  18. package/dist/author/declarations.d.ts.map +1 -0
  19. package/dist/author/declarations.js +277 -0
  20. package/dist/author/declarations.js.map +1 -0
  21. package/dist/author/index.d.ts +7 -0
  22. package/dist/author/index.d.ts.map +1 -0
  23. package/dist/author/index.js +12 -0
  24. package/dist/author/index.js.map +1 -0
  25. package/dist/author/jsx.d.ts +21 -0
  26. package/dist/author/jsx.d.ts.map +1 -0
  27. package/dist/author/jsx.js +20 -0
  28. package/dist/author/jsx.js.map +1 -0
  29. package/dist/author/jsx_shim.d.ts +117 -0
  30. package/dist/author/jsx_shim.d.ts.map +1 -0
  31. package/dist/author/jsx_shim.js +270 -0
  32. package/dist/author/jsx_shim.js.map +1 -0
  33. package/dist/author/prompt.d.ts +58 -0
  34. package/dist/author/prompt.d.ts.map +1 -0
  35. package/dist/author/prompt.js +148 -0
  36. package/dist/author/prompt.js.map +1 -0
  37. package/dist/author/schema_to_typescript.d.ts +37 -0
  38. package/dist/author/schema_to_typescript.d.ts.map +1 -0
  39. package/dist/author/schema_to_typescript.js +286 -0
  40. package/dist/author/schema_to_typescript.js.map +1 -0
  41. package/dist/cjs/author/authored_fields.js +233 -0
  42. package/dist/cjs/author/authored_fields.js.map +1 -0
  43. package/dist/cjs/author/authoring_input.js +64 -0
  44. package/dist/cjs/author/authoring_input.js.map +1 -0
  45. package/dist/cjs/author/authoring_model.js +104 -0
  46. package/dist/cjs/author/authoring_model.js.map +1 -0
  47. package/dist/cjs/author/declarations.js +281 -0
  48. package/dist/cjs/author/declarations.js.map +1 -0
  49. package/dist/cjs/author/index.js +25 -0
  50. package/dist/cjs/author/index.js.map +1 -0
  51. package/dist/cjs/author/jsx.js +24 -0
  52. package/dist/cjs/author/jsx.js.map +1 -0
  53. package/dist/cjs/author/jsx_shim.js +276 -0
  54. package/dist/cjs/author/jsx_shim.js.map +1 -0
  55. package/dist/cjs/author/prompt.js +153 -0
  56. package/dist/cjs/author/prompt.js.map +1 -0
  57. package/dist/cjs/author/schema_to_typescript.js +295 -0
  58. package/dist/cjs/author/schema_to_typescript.js.map +1 -0
  59. package/dist/cjs/composition/action_event.js +9 -0
  60. package/dist/cjs/composition/action_event.js.map +1 -0
  61. package/dist/cjs/composition/body_node_base.js +112 -0
  62. package/dist/cjs/composition/body_node_base.js.map +1 -0
  63. package/dist/cjs/composition/composition.js +9 -0
  64. package/dist/cjs/composition/composition.js.map +1 -0
  65. package/dist/cjs/composition/error.js +73 -0
  66. package/dist/cjs/composition/error.js.map +1 -0
  67. package/dist/cjs/composition/index.js +32 -0
  68. package/dist/cjs/composition/index.js.map +1 -0
  69. package/dist/cjs/composition/map_nodes.js +85 -0
  70. package/dist/cjs/composition/map_nodes.js.map +1 -0
  71. package/dist/cjs/composition/named_color.js +20 -0
  72. package/dist/cjs/composition/named_color.js.map +1 -0
  73. package/dist/cjs/composition/node.js +9 -0
  74. package/dist/cjs/composition/node.js.map +1 -0
  75. package/dist/cjs/composition/one_line.js +23 -0
  76. package/dist/cjs/composition/one_line.js.map +1 -0
  77. package/dist/cjs/composition/structured_value.js +21 -0
  78. package/dist/cjs/composition/structured_value.js.map +1 -0
  79. package/dist/cjs/composition/validation_error.js +40 -0
  80. package/dist/cjs/composition/validation_error.js.map +1 -0
  81. package/dist/cjs/define/frame.js +31 -0
  82. package/dist/cjs/define/frame.js.map +1 -0
  83. package/dist/cjs/define/index.js +31 -0
  84. package/dist/cjs/define/index.js.map +1 -0
  85. package/dist/cjs/define/markdown_content.js +12 -0
  86. package/dist/cjs/define/markdown_content.js.map +1 -0
  87. package/dist/cjs/define/primitive_example.js +26 -0
  88. package/dist/cjs/define/primitive_example.js.map +1 -0
  89. package/dist/cjs/define/primitive_icon.js +17 -0
  90. package/dist/cjs/define/primitive_icon.js.map +1 -0
  91. package/dist/cjs/define/primitive_module.js +118 -0
  92. package/dist/cjs/define/primitive_module.js.map +1 -0
  93. package/dist/cjs/define/slack_assets.js +9 -0
  94. package/dist/cjs/define/slack_assets.js.map +1 -0
  95. package/dist/cjs/define/slack_blocks.js +9 -0
  96. package/dist/cjs/define/slack_blocks.js.map +1 -0
  97. package/dist/cjs/define/zod_format.js +122 -0
  98. package/dist/cjs/define/zod_format.js.map +1 -0
  99. package/dist/cjs/define/zod_helpers.js +26 -0
  100. package/dist/cjs/define/zod_helpers.js.map +1 -0
  101. package/dist/cjs/entries/html.js +12 -0
  102. package/dist/cjs/entries/html.js.map +1 -0
  103. package/dist/cjs/entries/index.js +80 -0
  104. package/dist/cjs/entries/index.js.map +1 -0
  105. package/dist/cjs/entries/markdown.js +14 -0
  106. package/dist/cjs/entries/markdown.js.map +1 -0
  107. package/dist/cjs/entries/react.js +20 -0
  108. package/dist/cjs/entries/react.js.map +1 -0
  109. package/dist/cjs/entries/slack.js +25 -0
  110. package/dist/cjs/entries/slack.js.map +1 -0
  111. package/dist/cjs/entries/text.js +12 -0
  112. package/dist/cjs/entries/text.js.map +1 -0
  113. package/dist/cjs/pack/capabilities.js +40 -0
  114. package/dist/cjs/pack/capabilities.js.map +1 -0
  115. package/dist/cjs/pack/compose.js +59 -0
  116. package/dist/cjs/pack/compose.js.map +1 -0
  117. package/dist/cjs/pack/enhancements.js +65 -0
  118. package/dist/cjs/pack/enhancements.js.map +1 -0
  119. package/dist/cjs/pack/index.js +18 -0
  120. package/dist/cjs/pack/index.js.map +1 -0
  121. package/dist/cjs/pack/primitive_pack.js +97 -0
  122. package/dist/cjs/pack/primitive_pack.js.map +1 -0
  123. package/dist/cjs/package.json +3 -0
  124. package/dist/cjs/render/anchors.js +167 -0
  125. package/dist/cjs/render/anchors.js.map +1 -0
  126. package/dist/cjs/render/context_view.js +54 -0
  127. package/dist/cjs/render/context_view.js.map +1 -0
  128. package/dist/cjs/render/format_display_value.js +143 -0
  129. package/dist/cjs/render/format_display_value.js.map +1 -0
  130. package/dist/cjs/render/format_number.js +46 -0
  131. package/dist/cjs/render/format_number.js.map +1 -0
  132. package/dist/cjs/render/html/enhancements.js +30 -0
  133. package/dist/cjs/render/html/enhancements.js.map +1 -0
  134. package/dist/cjs/render/html/envelope.js +218 -0
  135. package/dist/cjs/render/html/envelope.js.map +1 -0
  136. package/dist/cjs/render/html/index.js +12 -0
  137. package/dist/cjs/render/html/index.js.map +1 -0
  138. package/dist/cjs/render/index.js +25 -0
  139. package/dist/cjs/render/index.js.map +1 -0
  140. package/dist/cjs/render/layout_check.js +133 -0
  141. package/dist/cjs/render/layout_check.js.map +1 -0
  142. package/dist/cjs/render/markdown/builder.js +195 -0
  143. package/dist/cjs/render/markdown/builder.js.map +1 -0
  144. package/dist/cjs/render/markdown/envelope.js +33 -0
  145. package/dist/cjs/render/markdown/envelope.js.map +1 -0
  146. package/dist/cjs/render/markdown/format.js +208 -0
  147. package/dist/cjs/render/markdown/format.js.map +1 -0
  148. package/dist/cjs/render/markdown/index.js +15 -0
  149. package/dist/cjs/render/markdown/index.js.map +1 -0
  150. package/dist/cjs/render/measure_dom.js +61 -0
  151. package/dist/cjs/render/measure_dom.js.map +1 -0
  152. package/dist/cjs/render/payload.js +13 -0
  153. package/dist/cjs/render/payload.js.map +1 -0
  154. package/dist/cjs/render/primitive_dispatch.js +173 -0
  155. package/dist/cjs/render/primitive_dispatch.js.map +1 -0
  156. package/dist/cjs/render/react/content.js +44 -0
  157. package/dist/cjs/render/react/content.js.map +1 -0
  158. package/dist/cjs/render/react/enhancements.js +32 -0
  159. package/dist/cjs/render/react/enhancements.js.map +1 -0
  160. package/dist/cjs/render/react/index.js +15 -0
  161. package/dist/cjs/render/react/index.js.map +1 -0
  162. package/dist/cjs/render/slack/assets.js +45 -0
  163. package/dist/cjs/render/slack/assets.js.map +1 -0
  164. package/dist/cjs/render/slack/blocks.js +80 -0
  165. package/dist/cjs/render/slack/blocks.js.map +1 -0
  166. package/dist/cjs/render/slack/envelope.js +551 -0
  167. package/dist/cjs/render/slack/envelope.js.map +1 -0
  168. package/dist/cjs/render/slack/format.js +225 -0
  169. package/dist/cjs/render/slack/format.js.map +1 -0
  170. package/dist/cjs/render/slack/index.js +30 -0
  171. package/dist/cjs/render/slack/index.js.map +1 -0
  172. package/dist/cjs/render/slack/markdown_content.js +409 -0
  173. package/dist/cjs/render/slack/markdown_content.js.map +1 -0
  174. package/dist/cjs/render/text/envelope.js +21 -0
  175. package/dist/cjs/render/text/envelope.js.map +1 -0
  176. package/dist/cjs/render/text/index.js +12 -0
  177. package/dist/cjs/render/text/index.js.map +1 -0
  178. package/dist/cjs/testing/conformance.js +312 -0
  179. package/dist/cjs/testing/conformance.js.map +1 -0
  180. package/dist/cjs/testing/icon.js +248 -0
  181. package/dist/cjs/testing/icon.js.map +1 -0
  182. package/dist/cjs/testing/index.js +18 -0
  183. package/dist/cjs/testing/index.js.map +1 -0
  184. package/dist/cjs/testing/registration.js +142 -0
  185. package/dist/cjs/testing/registration.js.map +1 -0
  186. package/dist/cjs/validate/authoring_schema.js +312 -0
  187. package/dist/cjs/validate/authoring_schema.js.map +1 -0
  188. package/dist/cjs/validate/composition_schema.js +135 -0
  189. package/dist/cjs/validate/composition_schema.js.map +1 -0
  190. package/dist/cjs/validate/index.js +53 -0
  191. package/dist/cjs/validate/index.js.map +1 -0
  192. package/dist/cjs/validate/input_budget.js +156 -0
  193. package/dist/cjs/validate/input_budget.js.map +1 -0
  194. package/dist/cjs/validate/json_schema.js +72 -0
  195. package/dist/cjs/validate/json_schema.js.map +1 -0
  196. package/dist/cjs/validate/node_issues.js +65 -0
  197. package/dist/cjs/validate/node_issues.js.map +1 -0
  198. package/dist/cjs/validate/url.js +116 -0
  199. package/dist/cjs/validate/url.js.map +1 -0
  200. package/dist/cjs/validate/validation.js +165 -0
  201. package/dist/cjs/validate/validation.js.map +1 -0
  202. package/dist/cjs/validate/value_schemas.js +53 -0
  203. package/dist/cjs/validate/value_schemas.js.map +1 -0
  204. package/dist/composition/action_event.d.ts +13 -0
  205. package/dist/composition/action_event.d.ts.map +1 -0
  206. package/dist/composition/action_event.js +8 -0
  207. package/dist/composition/action_event.js.map +1 -0
  208. package/dist/composition/body_node_base.d.ts +72 -0
  209. package/dist/composition/body_node_base.d.ts.map +1 -0
  210. package/dist/composition/body_node_base.js +104 -0
  211. package/dist/composition/body_node_base.js.map +1 -0
  212. package/dist/composition/composition.d.ts +71 -0
  213. package/dist/composition/composition.d.ts.map +1 -0
  214. package/dist/composition/composition.js +8 -0
  215. package/dist/composition/composition.js.map +1 -0
  216. package/dist/composition/error.d.ts +61 -0
  217. package/dist/composition/error.d.ts.map +1 -0
  218. package/dist/composition/error.js +69 -0
  219. package/dist/composition/error.js.map +1 -0
  220. package/dist/composition/index.d.ts +11 -0
  221. package/dist/composition/index.d.ts.map +1 -0
  222. package/dist/composition/index.js +14 -0
  223. package/dist/composition/index.js.map +1 -0
  224. package/dist/composition/map_nodes.d.ts +16 -0
  225. package/dist/composition/map_nodes.d.ts.map +1 -0
  226. package/dist/composition/map_nodes.js +81 -0
  227. package/dist/composition/map_nodes.js.map +1 -0
  228. package/dist/composition/named_color.d.ts +9 -0
  229. package/dist/composition/named_color.d.ts.map +1 -0
  230. package/dist/composition/named_color.js +17 -0
  231. package/dist/composition/named_color.js.map +1 -0
  232. package/dist/composition/node.d.ts +11 -0
  233. package/dist/composition/node.d.ts.map +1 -0
  234. package/dist/composition/node.js +8 -0
  235. package/dist/composition/node.js.map +1 -0
  236. package/dist/composition/one_line.d.ts +7 -0
  237. package/dist/composition/one_line.d.ts.map +1 -0
  238. package/dist/composition/one_line.js +17 -0
  239. package/dist/composition/one_line.js.map +1 -0
  240. package/dist/composition/structured_value.d.ts +27 -0
  241. package/dist/composition/structured_value.d.ts.map +1 -0
  242. package/dist/composition/structured_value.js +18 -0
  243. package/dist/composition/structured_value.js.map +1 -0
  244. package/dist/composition/validation_error.d.ts +33 -0
  245. package/dist/composition/validation_error.d.ts.map +1 -0
  246. package/dist/composition/validation_error.js +35 -0
  247. package/dist/composition/validation_error.js.map +1 -0
  248. package/dist/define/frame.d.ts +155 -0
  249. package/dist/define/frame.d.ts.map +1 -0
  250. package/dist/define/frame.js +27 -0
  251. package/dist/define/frame.js.map +1 -0
  252. package/dist/define/index.d.ts +10 -0
  253. package/dist/define/index.d.ts.map +1 -0
  254. package/dist/define/index.js +13 -0
  255. package/dist/define/index.js.map +1 -0
  256. package/dist/define/markdown_content.d.ts +15 -0
  257. package/dist/define/markdown_content.d.ts.map +1 -0
  258. package/dist/define/markdown_content.js +9 -0
  259. package/dist/define/markdown_content.js.map +1 -0
  260. package/dist/define/primitive_example.d.ts +30 -0
  261. package/dist/define/primitive_example.d.ts.map +1 -0
  262. package/dist/define/primitive_example.js +21 -0
  263. package/dist/define/primitive_example.js.map +1 -0
  264. package/dist/define/primitive_icon.d.ts +11 -0
  265. package/dist/define/primitive_icon.d.ts.map +1 -0
  266. package/dist/define/primitive_icon.js +14 -0
  267. package/dist/define/primitive_icon.js.map +1 -0
  268. package/dist/define/primitive_module.d.ts +435 -0
  269. package/dist/define/primitive_module.d.ts.map +1 -0
  270. package/dist/define/primitive_module.js +112 -0
  271. package/dist/define/primitive_module.js.map +1 -0
  272. package/dist/define/slack_assets.d.ts +28 -0
  273. package/dist/define/slack_assets.d.ts.map +1 -0
  274. package/dist/define/slack_assets.js +8 -0
  275. package/dist/define/slack_assets.js.map +1 -0
  276. package/dist/define/slack_blocks.d.ts +234 -0
  277. package/dist/define/slack_blocks.d.ts.map +1 -0
  278. package/dist/define/slack_blocks.js +8 -0
  279. package/dist/define/slack_blocks.js.map +1 -0
  280. package/dist/define/zod_format.d.ts +33 -0
  281. package/dist/define/zod_format.d.ts.map +1 -0
  282. package/dist/define/zod_format.js +114 -0
  283. package/dist/define/zod_format.js.map +1 -0
  284. package/dist/define/zod_helpers.d.ts +10 -0
  285. package/dist/define/zod_helpers.d.ts.map +1 -0
  286. package/dist/define/zod_helpers.js +22 -0
  287. package/dist/define/zod_helpers.js.map +1 -0
  288. package/dist/entries/html.d.ts +3 -0
  289. package/dist/entries/html.d.ts.map +1 -0
  290. package/dist/entries/html.js +8 -0
  291. package/dist/entries/html.js.map +1 -0
  292. package/dist/entries/index.d.ts +6 -0
  293. package/dist/entries/index.d.ts.map +1 -0
  294. package/dist/entries/index.js +12 -0
  295. package/dist/entries/index.js.map +1 -0
  296. package/dist/entries/markdown.d.ts +3 -0
  297. package/dist/entries/markdown.d.ts.map +1 -0
  298. package/dist/entries/markdown.js +8 -0
  299. package/dist/entries/markdown.js.map +1 -0
  300. package/dist/entries/react.d.ts +5 -0
  301. package/dist/entries/react.d.ts.map +1 -0
  302. package/dist/entries/react.js +11 -0
  303. package/dist/entries/react.js.map +1 -0
  304. package/dist/entries/slack.d.ts +2 -0
  305. package/dist/entries/slack.d.ts.map +1 -0
  306. package/dist/entries/slack.js +8 -0
  307. package/dist/entries/slack.js.map +1 -0
  308. package/dist/entries/text.d.ts +2 -0
  309. package/dist/entries/text.d.ts.map +1 -0
  310. package/dist/entries/text.js +8 -0
  311. package/dist/entries/text.js.map +1 -0
  312. package/dist/pack/capabilities.d.ts +41 -0
  313. package/dist/pack/capabilities.d.ts.map +1 -0
  314. package/dist/pack/capabilities.js +36 -0
  315. package/dist/pack/capabilities.js.map +1 -0
  316. package/dist/pack/compose.d.ts +24 -0
  317. package/dist/pack/compose.d.ts.map +1 -0
  318. package/dist/pack/compose.js +55 -0
  319. package/dist/pack/compose.js.map +1 -0
  320. package/dist/pack/enhancements.d.ts +65 -0
  321. package/dist/pack/enhancements.d.ts.map +1 -0
  322. package/dist/pack/enhancements.js +59 -0
  323. package/dist/pack/enhancements.js.map +1 -0
  324. package/dist/pack/index.d.ts +5 -0
  325. package/dist/pack/index.d.ts.map +1 -0
  326. package/dist/pack/index.js +11 -0
  327. package/dist/pack/index.js.map +1 -0
  328. package/dist/pack/primitive_pack.d.ts +164 -0
  329. package/dist/pack/primitive_pack.d.ts.map +1 -0
  330. package/dist/pack/primitive_pack.js +92 -0
  331. package/dist/pack/primitive_pack.js.map +1 -0
  332. package/dist/render/anchors.d.ts +82 -0
  333. package/dist/render/anchors.d.ts.map +1 -0
  334. package/dist/render/anchors.js +153 -0
  335. package/dist/render/anchors.js.map +1 -0
  336. package/dist/render/context_view.d.ts +10 -0
  337. package/dist/render/context_view.d.ts.map +1 -0
  338. package/dist/render/context_view.js +49 -0
  339. package/dist/render/context_view.js.map +1 -0
  340. package/dist/render/format_display_value.d.ts +20 -0
  341. package/dist/render/format_display_value.d.ts.map +1 -0
  342. package/dist/render/format_display_value.js +137 -0
  343. package/dist/render/format_display_value.js.map +1 -0
  344. package/dist/render/format_number.d.ts +9 -0
  345. package/dist/render/format_number.d.ts.map +1 -0
  346. package/dist/render/format_number.js +42 -0
  347. package/dist/render/format_number.js.map +1 -0
  348. package/dist/render/html/enhancements.d.ts +10 -0
  349. package/dist/render/html/enhancements.d.ts.map +1 -0
  350. package/dist/render/html/enhancements.js +25 -0
  351. package/dist/render/html/enhancements.js.map +1 -0
  352. package/dist/render/html/envelope.d.ts +182 -0
  353. package/dist/render/html/envelope.d.ts.map +1 -0
  354. package/dist/render/html/envelope.js +214 -0
  355. package/dist/render/html/envelope.js.map +1 -0
  356. package/dist/render/html/index.d.ts +3 -0
  357. package/dist/render/html/index.d.ts.map +1 -0
  358. package/dist/render/html/index.js +8 -0
  359. package/dist/render/html/index.js.map +1 -0
  360. package/dist/render/index.d.ts +6 -0
  361. package/dist/render/index.d.ts.map +1 -0
  362. package/dist/render/index.js +11 -0
  363. package/dist/render/index.js.map +1 -0
  364. package/dist/render/layout_check.d.ts +43 -0
  365. package/dist/render/layout_check.d.ts.map +1 -0
  366. package/dist/render/layout_check.js +129 -0
  367. package/dist/render/layout_check.js.map +1 -0
  368. package/dist/render/markdown/builder.d.ts +46 -0
  369. package/dist/render/markdown/builder.d.ts.map +1 -0
  370. package/dist/render/markdown/builder.js +190 -0
  371. package/dist/render/markdown/builder.js.map +1 -0
  372. package/dist/render/markdown/envelope.d.ts +20 -0
  373. package/dist/render/markdown/envelope.d.ts.map +1 -0
  374. package/dist/render/markdown/envelope.js +29 -0
  375. package/dist/render/markdown/envelope.js.map +1 -0
  376. package/dist/render/markdown/format.d.ts +10 -0
  377. package/dist/render/markdown/format.d.ts.map +1 -0
  378. package/dist/render/markdown/format.js +202 -0
  379. package/dist/render/markdown/format.js.map +1 -0
  380. package/dist/render/markdown/index.d.ts +3 -0
  381. package/dist/render/markdown/index.d.ts.map +1 -0
  382. package/dist/render/markdown/index.js +9 -0
  383. package/dist/render/markdown/index.js.map +1 -0
  384. package/dist/render/measure_dom.d.ts +10 -0
  385. package/dist/render/measure_dom.d.ts.map +1 -0
  386. package/dist/render/measure_dom.js +57 -0
  387. package/dist/render/measure_dom.js.map +1 -0
  388. package/dist/render/payload.d.ts +16 -0
  389. package/dist/render/payload.d.ts.map +1 -0
  390. package/dist/render/payload.js +9 -0
  391. package/dist/render/payload.js.map +1 -0
  392. package/dist/render/primitive_dispatch.d.ts +72 -0
  393. package/dist/render/primitive_dispatch.d.ts.map +1 -0
  394. package/dist/render/primitive_dispatch.js +169 -0
  395. package/dist/render/primitive_dispatch.js.map +1 -0
  396. package/dist/render/react/content.d.ts +40 -0
  397. package/dist/render/react/content.d.ts.map +1 -0
  398. package/dist/render/react/content.js +39 -0
  399. package/dist/render/react/content.js.map +1 -0
  400. package/dist/render/react/enhancements.d.ts +15 -0
  401. package/dist/render/react/enhancements.d.ts.map +1 -0
  402. package/dist/render/react/enhancements.js +28 -0
  403. package/dist/render/react/enhancements.js.map +1 -0
  404. package/dist/render/react/index.d.ts +3 -0
  405. package/dist/render/react/index.d.ts.map +1 -0
  406. package/dist/render/react/index.js +9 -0
  407. package/dist/render/react/index.js.map +1 -0
  408. package/dist/render/slack/assets.d.ts +16 -0
  409. package/dist/render/slack/assets.d.ts.map +1 -0
  410. package/dist/render/slack/assets.js +40 -0
  411. package/dist/render/slack/assets.js.map +1 -0
  412. package/dist/render/slack/blocks.d.ts +72 -0
  413. package/dist/render/slack/blocks.d.ts.map +1 -0
  414. package/dist/render/slack/blocks.js +77 -0
  415. package/dist/render/slack/blocks.js.map +1 -0
  416. package/dist/render/slack/envelope.d.ts +52 -0
  417. package/dist/render/slack/envelope.d.ts.map +1 -0
  418. package/dist/render/slack/envelope.js +547 -0
  419. package/dist/render/slack/envelope.js.map +1 -0
  420. package/dist/render/slack/format.d.ts +70 -0
  421. package/dist/render/slack/format.d.ts.map +1 -0
  422. package/dist/render/slack/format.js +209 -0
  423. package/dist/render/slack/format.js.map +1 -0
  424. package/dist/render/slack/index.d.ts +6 -0
  425. package/dist/render/slack/index.d.ts.map +1 -0
  426. package/dist/render/slack/index.js +12 -0
  427. package/dist/render/slack/index.js.map +1 -0
  428. package/dist/render/slack/markdown_content.d.ts +17 -0
  429. package/dist/render/slack/markdown_content.d.ts.map +1 -0
  430. package/dist/render/slack/markdown_content.js +404 -0
  431. package/dist/render/slack/markdown_content.js.map +1 -0
  432. package/dist/render/text/envelope.d.ts +15 -0
  433. package/dist/render/text/envelope.d.ts.map +1 -0
  434. package/dist/render/text/envelope.js +17 -0
  435. package/dist/render/text/envelope.js.map +1 -0
  436. package/dist/render/text/index.d.ts +2 -0
  437. package/dist/render/text/index.d.ts.map +1 -0
  438. package/dist/render/text/index.js +8 -0
  439. package/dist/render/text/index.js.map +1 -0
  440. package/dist/testing/conformance.d.ts +145 -0
  441. package/dist/testing/conformance.d.ts.map +1 -0
  442. package/dist/testing/conformance.js +303 -0
  443. package/dist/testing/conformance.js.map +1 -0
  444. package/dist/testing/icon.d.ts +11 -0
  445. package/dist/testing/icon.d.ts.map +1 -0
  446. package/dist/testing/icon.js +244 -0
  447. package/dist/testing/icon.js.map +1 -0
  448. package/dist/testing/index.d.ts +4 -0
  449. package/dist/testing/index.d.ts.map +1 -0
  450. package/dist/testing/index.js +10 -0
  451. package/dist/testing/index.js.map +1 -0
  452. package/dist/testing/registration.d.ts +32 -0
  453. package/dist/testing/registration.d.ts.map +1 -0
  454. package/dist/testing/registration.js +105 -0
  455. package/dist/testing/registration.js.map +1 -0
  456. package/dist/validate/authoring_schema.d.ts +33 -0
  457. package/dist/validate/authoring_schema.d.ts.map +1 -0
  458. package/dist/validate/authoring_schema.js +306 -0
  459. package/dist/validate/authoring_schema.js.map +1 -0
  460. package/dist/validate/composition_schema.d.ts +80 -0
  461. package/dist/validate/composition_schema.d.ts.map +1 -0
  462. package/dist/validate/composition_schema.js +127 -0
  463. package/dist/validate/composition_schema.js.map +1 -0
  464. package/dist/validate/index.d.ts +9 -0
  465. package/dist/validate/index.d.ts.map +1 -0
  466. package/dist/validate/index.js +15 -0
  467. package/dist/validate/index.js.map +1 -0
  468. package/dist/validate/input_budget.d.ts +35 -0
  469. package/dist/validate/input_budget.d.ts.map +1 -0
  470. package/dist/validate/input_budget.js +151 -0
  471. package/dist/validate/input_budget.js.map +1 -0
  472. package/dist/validate/json_schema.d.ts +32 -0
  473. package/dist/validate/json_schema.d.ts.map +1 -0
  474. package/dist/validate/json_schema.js +68 -0
  475. package/dist/validate/json_schema.js.map +1 -0
  476. package/dist/validate/node_issues.d.ts +12 -0
  477. package/dist/validate/node_issues.d.ts.map +1 -0
  478. package/dist/validate/node_issues.js +61 -0
  479. package/dist/validate/node_issues.js.map +1 -0
  480. package/dist/validate/url.d.ts +50 -0
  481. package/dist/validate/url.d.ts.map +1 -0
  482. package/dist/validate/url.js +107 -0
  483. package/dist/validate/url.js.map +1 -0
  484. package/dist/validate/validation.d.ts +95 -0
  485. package/dist/validate/validation.d.ts.map +1 -0
  486. package/dist/validate/validation.js +157 -0
  487. package/dist/validate/validation.js.map +1 -0
  488. package/dist/validate/value_schemas.d.ts +53 -0
  489. package/dist/validate/value_schemas.d.ts.map +1 -0
  490. package/dist/validate/value_schemas.js +50 -0
  491. package/dist/validate/value_schemas.js.map +1 -0
  492. package/package.json +119 -5
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
+ * or more contributor license agreements. Licensed under the Elastic License
5
+ * 2.0; you may not use this file except in compliance with the Elastic License
6
+ * 2.0.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.assetUrl = exports.navigationHref = exports.ASSET_URL_MESSAGE = exports.NAVIGATION_HREF_MESSAGE = exports.ASSET_URL_RULE = exports.NAVIGATION_HREF_RULE = exports.BLOCKED_HREF = exports.sanitizeParsedAssetUrl = exports.sanitizeParsedNavigationHref = exports.sanitizeAssetUrl = exports.sanitizeNavigationHref = void 0;
10
+ const zod_helpers_1 = require("../define/zod_helpers");
11
+ // The one URL trust policy every URL-bearing field goes through, as a Zod
12
+ // refinement and again as render-time sanitization. See `docs/url-trust.md`.
13
+ const NAMED_REFERENCES = {
14
+ bsol: '\\',
15
+ colon: ':',
16
+ gt: '>',
17
+ lt: '<',
18
+ newline: '\n',
19
+ sol: '/',
20
+ tab: '\t',
21
+ };
22
+ // Numeric references, which browsers decode without a trailing `;`, and the
23
+ // named ones that spell a scheme, path, or tag character.
24
+ const CHARACTER_REFERENCE_RE = /&(?:#x([0-9a-f]+);?|#([0-9]+);?|(bsol|colon|gt|lt|newline|sol|tab);)/gi;
25
+ const decodeReference = (match, hex, decimal, name) => {
26
+ if (name)
27
+ return NAMED_REFERENCES[name.toLowerCase()] ?? match;
28
+ const codePoint = Number.parseInt(hex ?? decimal ?? '', hex ? 16 : 10);
29
+ return codePoint > 0 && codePoint <= 0x10ffff
30
+ ? String.fromCodePoint(codePoint)
31
+ : '\ufffd';
32
+ };
33
+ // The control characters browsers drop when parsing a URL.
34
+ const stripControls = (value) =>
35
+ // eslint-disable-next-line no-control-regex -- stripping control characters is the point.
36
+ value.replace(/[\u0000-\u001f\u007f]/g, '').trim();
37
+ // The URL as a sink sees it: references decoded once, then controls stripped,
38
+ // so an obfuscated scheme is checked as it would act. Only the decision reads
39
+ // it; the policy returns the authored value, since a consumer that decodes
40
+ // again must decode what was checked, not a decoded copy.
41
+ const decisionForm = (value) => stripControls(value.replace(CHARACTER_REFERENCE_RE, decodeReference));
42
+ // `<` and `>` must be percent-encoded in a URL, so their unencoded presence
43
+ // means the value is malformed or a parser-confusion attempt (an unterminated
44
+ // `<dest` would otherwise read as a relative path). Reject rather than strip.
45
+ const HAS_ANGLE_BRACKET_RE = /[<>]/;
46
+ const HAS_SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i;
47
+ const NAVIGATION_SCHEME_RE = /^(?:https?|mailto):/i;
48
+ const ASSET_SCHEME_RE = /^(?:https?:|data:image\/)/i;
49
+ // `//host` — and the `\` variants browsers fold into `/` — resolve against the
50
+ // current protocol onto a foreign host, so they are not relative paths.
51
+ const PROTOCOL_RELATIVE_RE = /^[/\\][/\\]/;
52
+ // Whether a URL in decision form passes, given which schemes are allowed.
53
+ const passes = (decided, schemes) => decided !== '' &&
54
+ !PROTOCOL_RELATIVE_RE.test(decided) &&
55
+ !HAS_ANGLE_BRACKET_RE.test(decided) &&
56
+ (!HAS_SCHEME_RE.test(decided) || schemes.test(decided));
57
+ /**
58
+ * Returns the URL, trimmed and with control characters stripped, when it
59
+ * satisfies the navigation policy (`https:` / `http:` / `mailto:` / relative
60
+ * path), `null` otherwise.
61
+ */
62
+ const sanitizeNavigationHref = (href) => passes(decisionForm(href), NAVIGATION_SCHEME_RE) ? stripControls(href) : null;
63
+ exports.sanitizeNavigationHref = sanitizeNavigationHref;
64
+ /**
65
+ * Returns the URL, trimmed and with control characters stripped, when it
66
+ * satisfies the asset policy (`https:` / `http:` / relative path /
67
+ * `data:image/*`), `null` otherwise.
68
+ */
69
+ const sanitizeAssetUrl = (url) => passes(decisionForm(url), ASSET_SCHEME_RE) ? stripControls(url) : null;
70
+ exports.sanitizeAssetUrl = sanitizeAssetUrl;
71
+ /** Checks a Markdown parser's decoded destination without decoding it again. */
72
+ const sanitizeParsedNavigationHref = (href) => {
73
+ const normalized = stripControls(href);
74
+ return passes(normalized, NAVIGATION_SCHEME_RE) ? normalized : null;
75
+ };
76
+ exports.sanitizeParsedNavigationHref = sanitizeParsedNavigationHref;
77
+ /** Checks a Markdown parser's decoded image destination. */
78
+ const sanitizeParsedAssetUrl = (url) => {
79
+ const normalized = stripControls(url);
80
+ return passes(normalized, ASSET_SCHEME_RE) ? normalized : null;
81
+ };
82
+ exports.sanitizeParsedAssetUrl = sanitizeParsedAssetUrl;
83
+ /**
84
+ * Render-time replacement for a navigation href that failed the policy: an
85
+ * inert same-document link, so the label stays visible without a destination.
86
+ */
87
+ exports.BLOCKED_HREF = '#';
88
+ /** What {@link navigationHref} accepts, for a field description to state. */
89
+ exports.NAVIGATION_HREF_RULE = 'an https, http, or mailto URL, or a relative path';
90
+ /** What {@link assetUrl} accepts, for a field description to state. */
91
+ exports.ASSET_URL_RULE = 'an https, http, or data:image URL, or a relative path';
92
+ /** Validation message for {@link navigationHref}. */
93
+ exports.NAVIGATION_HREF_MESSAGE = `must be ${exports.NAVIGATION_HREF_RULE}`;
94
+ /** Validation message for {@link assetUrl}. */
95
+ exports.ASSET_URL_MESSAGE = `must be ${exports.ASSET_URL_RULE}`;
96
+ const urlSchema = (passes, rule, message, { max }) => (max === undefined ? (0, zod_helpers_1.requiredString)() : (0, zod_helpers_1.requiredString)().max(max))
97
+ .refine(passes, { error: message })
98
+ .describe(`${rule[0].toUpperCase()}${rule.slice(1)}.`);
99
+ /**
100
+ * Zod schema for an `href`-like field: the validation layer of the two-layer
101
+ * policy, paired with {@link sanitizeNavigationHref} at render time.
102
+ *
103
+ * Its description states the rule, since a refinement's message does not
104
+ * reach the authoring JSON Schema. A field that describes itself should end
105
+ * with {@link NAVIGATION_HREF_RULE} so the model still reads it.
106
+ */
107
+ const navigationHref = (options = {}) => urlSchema((value) => (0, exports.sanitizeNavigationHref)(value) !== null, exports.NAVIGATION_HREF_RULE, exports.NAVIGATION_HREF_MESSAGE, options);
108
+ exports.navigationHref = navigationHref;
109
+ /**
110
+ * Zod schema for a `src`-like field, paired with {@link sanitizeAssetUrl} at
111
+ * render time. Describes itself as {@link navigationHref} does, with
112
+ * {@link ASSET_URL_RULE}.
113
+ */
114
+ const assetUrl = (options = {}) => urlSchema((value) => (0, exports.sanitizeAssetUrl)(value) !== null, exports.ASSET_URL_RULE, exports.ASSET_URL_MESSAGE, options);
115
+ exports.assetUrl = assetUrl;
116
+ //# sourceMappingURL=url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.js","sourceRoot":"","sources":["../../../src/validate/url.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uDAAuD;AAEvD,0EAA0E;AAC1E,6EAA6E;AAE7E,MAAM,gBAAgB,GAAqC;IACzD,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,GAAG;IACV,EAAE,EAAE,GAAG;IACP,EAAE,EAAE,GAAG;IACP,OAAO,EAAE,IAAI;IACb,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,IAAI;CACV,CAAC;AAEF,4EAA4E;AAC5E,0DAA0D;AAC1D,MAAM,sBAAsB,GAC1B,wEAAwE,CAAC;AAE3E,MAAM,eAAe,GAAG,CACtB,KAAa,EACb,GAAuB,EACvB,OAA2B,EAC3B,IAAwB,EAChB,EAAE;IACV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;AAC1D,QAAA,cAAc,GACzB,uDAAuD,CAAC;AAE1D,qDAAqD;AACxC,QAAA,uBAAuB,GAAG,WAAW,4BAAoB,EAAE,CAAC;AAEzE,+CAA+C;AAClC,QAAA,iBAAiB,GAAG,WAAW,sBAAc,EAAE,CAAC;AAQ7D,MAAM,SAAS,GAAG,CAChB,MAAkC,EAClC,IAAY,EACZ,OAAe,EACf,EAAE,GAAG,EAAoB,EACzB,EAAE,CACF,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAA,4BAAc,GAAE,CAAC,CAAC,CAAC,IAAA,4BAAc,GAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAC/D,MAAM,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;KAClC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAE5D;;;;;;;GAOG;AACI,MAAM,cAAc,GAAG,CAAC,UAA4B,EAAE,EAAE,EAAE,CAC/D,SAAS,CACP,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,8BAAsB,EAAC,KAAK,CAAC,KAAK,IAAI,EACjD,4BAAoB,EACpB,+BAAuB,EACvB,OAAO,CACR,CAAC;AANS,QAAA,cAAc,kBAMvB;AAEJ;;;;GAIG;AACI,MAAM,QAAQ,GAAG,CAAC,UAA4B,EAAE,EAAE,EAAE,CACzD,SAAS,CACP,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,wBAAgB,EAAC,KAAK,CAAC,KAAK,IAAI,EAC3C,sBAAc,EACd,yBAAiB,EACjB,OAAO,CACR,CAAC;AANS,QAAA,QAAQ,YAMjB","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,165 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
+ * or more contributor license agreements. Licensed under the Elastic License
5
+ * 2.0; you may not use this file except in compliance with the Elastic License
6
+ * 2.0.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createCompositionParser = exports.createCompositionValidator = exports.compositionToRender = exports.enforceValidationMode = exports.CompositionValidationError = exports.warningsForSurface = void 0;
10
+ const body_node_base_1 = require("../composition/body_node_base");
11
+ const one_line_1 = require("../composition/one_line");
12
+ const validation_error_1 = require("../composition/validation_error");
13
+ Object.defineProperty(exports, "CompositionValidationError", { enumerable: true, get: function () { return validation_error_1.CompositionValidationError; } });
14
+ const composition_schema_1 = require("./composition_schema");
15
+ const input_budget_1 = require("./input_budget");
16
+ const node_issues_1 = require("./node_issues");
17
+ const checkedComposition = Symbol.for('elastic.isomer.checked_composition');
18
+ /** Narrows a result's warnings to the surface a caller is about to render. */
19
+ const warningsForSurface = (result, surface) => result.warnings.filter((warning) => warning.surface === surface);
20
+ exports.warningsForSurface = warningsForSurface;
21
+ /** 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. */
22
+ const enforceValidationMode = (result, mode) => {
23
+ if (!result.valid &&
24
+ (mode === 'throw' || result.errors.some(input_budget_1.isInputRefusal))) {
25
+ throw new validation_error_1.CompositionValidationError(result.errors);
26
+ }
27
+ };
28
+ exports.enforceValidationMode = enforceValidationMode;
29
+ /** 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. */
30
+ const compositionToRender = (result, mode) => {
31
+ (0, exports.enforceValidationMode)(result, mode);
32
+ const { composition } = result;
33
+ if (composition === undefined) {
34
+ throw new validation_error_1.CompositionValidationError(result.errors);
35
+ }
36
+ return composition;
37
+ };
38
+ exports.compositionToRender = compositionToRender;
39
+ /** The body's nodes, as {@link IssueRoot}s for a node issue formatter. */
40
+ const bodyRoots = (value) => {
41
+ const { body } = (value ?? {});
42
+ return Array.isArray(body)
43
+ ? body.map((node, index) => [node, `body[${index}]`])
44
+ : [];
45
+ };
46
+ /**
47
+ * Builds the trusted-input validator: {@link checkInputBudget}, then the schema and the semantic passes on its copy, which the result carries.
48
+ *
49
+ * `definitions` is memoized on array identity, so a caller that rebuilds the
50
+ * array per call (`createCompositionValidator(packs.flatMap(…))`) resolves a
51
+ * fresh discriminated union each time. Hold the array `composePacks` returns
52
+ * and reuse it across the validator, the parser, and the authoring context.
53
+ */
54
+ const createCompositionValidator = (definitions, options = {}) => {
55
+ const schema = (0, composition_schema_1.getCompositionSchemaForDefinitions)(definitions);
56
+ const walk = (0, body_node_base_1.createChildNodeWalker)(definitions);
57
+ const formatIssues = (0, node_issues_1.createNodeIssueFormatter)(definitions);
58
+ return (composition) => {
59
+ const checked = (0, input_budget_1.checkInputBudget)(composition, options.inputBudget);
60
+ if (!checked.valid) {
61
+ return {
62
+ valid: false,
63
+ errors: [checked.error],
64
+ warnings: [],
65
+ composition: undefined,
66
+ };
67
+ }
68
+ const plain = checked.value;
69
+ const result = schema.safeParse(plain, { reportInput: true });
70
+ if (result.success) {
71
+ const { body } = plain;
72
+ const idErrors = collectDuplicateNodeIdErrors(body, walk);
73
+ const warnings = collectEmptySurfaceWarnings(body, walk);
74
+ return {
75
+ valid: idErrors.length === 0,
76
+ errors: idErrors,
77
+ warnings,
78
+ composition: plain,
79
+ };
80
+ }
81
+ return {
82
+ valid: false,
83
+ errors: formatIssues(bodyRoots(plain), result.error.issues),
84
+ warnings: [],
85
+ composition: plain,
86
+ };
87
+ };
88
+ };
89
+ exports.createCompositionValidator = createCompositionValidator;
90
+ /**
91
+ * Builds the untrusted-input parser: {@link checkInputBudget}, then the schema only on its copy, reported rather than thrown.
92
+ *
93
+ * Deliberately narrower than {@link createCompositionValidator}. This answers
94
+ * "is this a `Composition`", not "is this a good one" — it does not run the
95
+ * duplicate-id pass or produce warnings, so a composition with two nodes
96
+ * sharing an `id` parses as valid. Id uniqueness is a `validate` guarantee, so
97
+ * a caller that wants the semantic checks runs `validate` on the result.
98
+ *
99
+ * Shares {@link createCompositionValidator}'s memoization identity requirement.
100
+ */
101
+ const createCompositionParser = (definitions, { inputBudget } = {}) => {
102
+ const schema = (0, composition_schema_1.getCompositionSchemaForDefinitions)(definitions);
103
+ const formatIssues = (0, node_issues_1.createNodeIssueFormatter)(definitions);
104
+ return (value) => {
105
+ const checked = (0, input_budget_1.checkInputBudget)(value, inputBudget);
106
+ if (!checked.valid) {
107
+ return { valid: false, errors: [checked.error] };
108
+ }
109
+ const result = schema.safeParse(checked.value, { reportInput: true });
110
+ if (result.success) {
111
+ return {
112
+ valid: true,
113
+ errors: [],
114
+ composition: result.data,
115
+ };
116
+ }
117
+ return {
118
+ valid: false,
119
+ errors: formatIssues(bodyRoots(checked.value), result.error.issues),
120
+ };
121
+ };
122
+ };
123
+ exports.createCompositionParser = createCompositionParser;
124
+ /** Warns once per surface that the whole body renders nothing on. */
125
+ const collectEmptySurfaceWarnings = (body, walk) => body_node_base_1.SURFACE_NAMES.filter((surface) => !body.some((node) => (0, body_node_base_1.rendersOnSurface)(node, surface, walk))).map((surface) => ({
126
+ surface,
127
+ message: `composition renders no nodes on surface "${surface}"`,
128
+ }));
129
+ /**
130
+ * Errors for each node whose `id` repeats one already seen, naming the first
131
+ * use.
132
+ *
133
+ * Errors rather than warnings, because ids are what a host addresses a node by.
134
+ * Run by `validate` and deliberately not by `parse`; see
135
+ * {@link createCompositionParser}.
136
+ */
137
+ const collectDuplicateNodeIdErrors = (body, walk) => {
138
+ const errors = [];
139
+ const seen = new Map();
140
+ const visit = (node, path) => {
141
+ if (!node || typeof node !== 'object') {
142
+ return;
143
+ }
144
+ const { id, type } = node;
145
+ if (typeof id === 'string') {
146
+ const first = seen.get(id);
147
+ if (first) {
148
+ errors.push({
149
+ path: `${path}.id`,
150
+ message: `duplicates id ${(0, one_line_1.quoteText)(id)} first used at ${first}`,
151
+ ...(typeof type === 'string' ? { nodeType: type } : {}),
152
+ });
153
+ }
154
+ else {
155
+ seen.set(id, path);
156
+ }
157
+ }
158
+ walk(node).forEach(({ node: child, path: field }) => {
159
+ visit(child, (0, body_node_base_1.childNodePath)(path, field));
160
+ });
161
+ };
162
+ body.forEach((node, index) => visit(node, `body[${index}]`));
163
+ return errors;
164
+ };
165
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/validate/validation.ts"],"names":[],"mappings":";AA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AO,EAAE,iBAAiB,IAAA,oBAAS,EAAC,EAAE,CAAC,kBAAkB,KAAK,EAAE;oBAChE,GAAG,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,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,IAAA,8BAAa,EAAC,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 childNodePath,\n createChildNodeWalker,\n rendersOnSurface,\n SURFACE_NAMES,\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/** Options for {@link createCompositionValidator}. */\nexport interface CompositionValidatorOptions {\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 = collectEmptySurfaceWarnings(body, walk);\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 SURFACE_NAMES.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 * 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
+ "use strict";
2
+ /*
3
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
+ * or more contributor license agreements. Licensed under the Elastic License
5
+ * 2.0; you may not use this file except in compliance with the Elastic License
6
+ * 2.0.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.displayValueSchema = exports.structuredValueSchema = exports.renderThemeSchema = exports.namedColorSchema = void 0;
10
+ // Zod for the value shapes the sdk already owns types for: `NamedColor`, and
11
+ // the structured display value.
12
+ //
13
+ // Only the shapes the sdk owns belong here. That is what lets any vocabulary
14
+ // package validate a color or a display value without depending on another
15
+ // pack's schemas.
16
+ const zod_1 = require("zod");
17
+ const named_color_1 = require("../composition/named_color");
18
+ const structured_value_1 = require("../composition/structured_value");
19
+ const zod_format_1 = require("../define/zod_format");
20
+ const zod_helpers_1 = require("../define/zod_helpers");
21
+ // An enum whose own message names the accepted values, as validation reports it.
22
+ const closedEnum = (values) => zod_1.z.enum(values, { error: () => (0, zod_format_1.oneOf)(values) });
23
+ /** Derived from {@link ALL_NAMED_COLORS} rather than restating the literals. */
24
+ exports.namedColorSchema = closedEnum(named_color_1.ALL_NAMED_COLORS);
25
+ /** `RenderTheme`: the light/dark preference a caller asks for. */
26
+ exports.renderThemeSchema = closedEnum(['auto', 'light', 'dark']);
27
+ /**
28
+ * The raw quantity plus a format hint, formatted once in a primitive's model so
29
+ * every surface renders the same string. See `StructuredValue`.
30
+ */
31
+ exports.structuredValueSchema = zod_1.z.object({
32
+ raw: zod_1.z.union([zod_1.z.number(), (0, zod_helpers_1.requiredString)()], {
33
+ error: () => 'must be a finite number or a non-empty string',
34
+ }),
35
+ format: closedEnum(structured_value_1.STRUCTURED_VALUE_FORMATS).optional(),
36
+ precision: zod_1.z
37
+ .number({ error: () => 'must be an integer between 0 and 6' })
38
+ .int({ error: 'must be an integer between 0 and 6' })
39
+ .min(0, { error: 'must be an integer between 0 and 6' })
40
+ .max(6, { error: 'must be an integer between 0 and 6' })
41
+ .optional(),
42
+ currency: zod_1.z
43
+ .string({ error: () => 'must be a three-letter currency code' })
44
+ .regex(/^[A-Za-z]{3}$/, {
45
+ error: 'must be a three-letter currency code',
46
+ })
47
+ .optional(),
48
+ });
49
+ /** Value-bearing fields accept preformatted prose or a structured value. */
50
+ exports.displayValueSchema = zod_1.z.union([(0, zod_helpers_1.requiredString)(), exports.structuredValueSchema], {
51
+ error: () => 'must be a non-empty string or a structured value ({ raw, format?, precision?, currency? })',
52
+ });
53
+ //# sourceMappingURL=value_schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value_schemas.js","sourceRoot":"","sources":["../../../src/validate/value_schemas.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,6EAA6E;AAC7E,gCAAgC;AAChC,E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E;QACtB,KAAK,EAAE,sCAAsC;KAC9C,CAAC;SACD,QAAQ,EAAE;CACd,CAAC,CAAC;AAEH,4EAA4E;AAC/D,QAAA,kBAAkB,GAAG,OAAC,CAAC,KAAK,CACvC,CAAC,IAAA,4BAAc,GAAE,EAAE,6BAAqB,CAAC,EACzC;IACE,KAAK,EAAE,GAAG,EAAE,CACV,4FAA4F;CAC/F,CACF,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\n// Zod for the value shapes the sdk already owns types for: `NamedColor`, and\n// the structured display value.\n//\n// Only the shapes the sdk owns belong here. That is what lets any vocabulary\n// package validate a color or a display value without depending on another\n// pack's schemas.\n\nimport { z } from 'zod';\n\nimport { ALL_NAMED_COLORS, type NamedColor } from '../composition/named_color';\nimport { STRUCTURED_VALUE_FORMATS } from '../composition/structured_value';\nimport { oneOf } from '../define/zod_format';\nimport { requiredString } from '../define/zod_helpers';\n\n// An enum whose own message names the accepted values, as validation reports it.\nconst closedEnum = <const T extends readonly [string, ...string[]]>(\n values: T\n) => z.enum(values, { error: () => oneOf(values) });\n\n/** Derived from {@link ALL_NAMED_COLORS} rather than restating the literals. */\nexport const namedColorSchema = closedEnum(\n ALL_NAMED_COLORS as [NamedColor, ...NamedColor[]]\n);\n\n/** `RenderTheme`: the light/dark preference a caller asks for. */\nexport const renderThemeSchema = closedEnum(['auto', 'light', 'dark']);\n\n/**\n * The raw quantity plus a format hint, formatted once in a primitive's model so\n * every surface renders the same string. See `StructuredValue`.\n */\nexport const structuredValueSchema = z.object({\n raw: z.union([z.number(), requiredString()], {\n error: () => 'must be a finite number or a non-empty string',\n }),\n format: closedEnum(STRUCTURED_VALUE_FORMATS).optional(),\n precision: z\n .number({ error: () => 'must be an integer between 0 and 6' })\n .int({ error: 'must be an integer between 0 and 6' })\n .min(0, { error: 'must be an integer between 0 and 6' })\n .max(6, { error: 'must be an integer between 0 and 6' })\n .optional(),\n currency: z\n .string({ error: () => 'must be a three-letter currency code' })\n .regex(/^[A-Za-z]{3}$/, {\n error: 'must be a three-letter currency code',\n })\n .optional(),\n});\n\n/** Value-bearing fields accept preformatted prose or a structured value. */\nexport const displayValueSchema = z.union(\n [requiredString(), structuredValueSchema],\n {\n error: () =>\n 'must be a non-empty string or a structured value ({ raw, format?, precision?, currency? })',\n }\n);\n"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A named event a node can raise, for the host to interpret.
3
+ *
4
+ * The SDK carries the reference and never dispatches it: side effects are the
5
+ * host's, so `name` means whatever its handler decides.
6
+ */
7
+ export interface ActionEventRef {
8
+ /** Agreed between the composition's author and the host's handler. */
9
+ name: string;
10
+ /** Payload passed through untouched, so it must be JSON-serializable. */
11
+ context?: Record<string, unknown>;
12
+ }
13
+ //# sourceMappingURL=action_event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action_event.d.ts","sourceRoot":"","sources":["../../src/composition/action_event.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC"}
@@ -0,0 +1,8 @@
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
+ export {};
8
+ //# sourceMappingURL=action_event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action_event.js","sourceRoot":"","sources":["../../src/composition/action_event.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","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\n/**\n * A named event a node can raise, for the host to interpret.\n *\n * The SDK carries the reference and never dispatches it: side effects are the\n * host's, so `name` means whatever its handler decides.\n */\nexport interface ActionEventRef {\n /** Agreed between the composition's author and the host's handler. */\n name: string;\n /** Payload passed through untouched, so it must be JSON-serializable. */\n context?: Record<string, unknown>;\n}\n"]}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Every surface a node renders on or is hidden from, in render order.
3
+ *
4
+ * `html` is not here: the runtime's `html` surface wraps `react` output in a
5
+ * document, and no node targets it.
6
+ */
7
+ export declare const SURFACE_NAMES: readonly ["react", "snapshot", "text", "markdown", "slack"];
8
+ /** One of the {@link SURFACE_NAMES}. */
9
+ export type SurfaceName = (typeof SURFACE_NAMES)[number];
10
+ /** @deprecated Use {@link SURFACE_NAMES}. */
11
+ export declare const BODY_NODE_SURFACES: readonly SurfaceName[];
12
+ /** The two fields every primitive node carries, whatever its pack. */
13
+ export interface BodyNodeBase {
14
+ /** Unique within a composition, which `validate` enforces and `parse` does not. */
15
+ id?: string;
16
+ /** Surfaces this node appears on. Absent means every surface. */
17
+ surfaces?: SurfaceName[];
18
+ }
19
+ /**
20
+ * A child node together with the field path locating it inside its parent, so
21
+ * an error path can name the field a child actually lives under. A container
22
+ * that returned bare nodes would leave every caller guessing the field name.
23
+ */
24
+ export interface ChildNodeRef {
25
+ /** Erased: one walker spans every pack's node types, so it can name none of them. */
26
+ node: unknown;
27
+ /** Relative to the parent, e.g. `items[0].node`, `items[2].description`. */
28
+ path: string;
29
+ }
30
+ /**
31
+ * Walks nested nodes and, for a hybrid container, reports whether the parent
32
+ * still produces output of its own. A non-empty `children` result is the
33
+ * complete source of rendered content unless
34
+ * {@link ChildNodeWalker.hasOwnContent} is true for that node.
35
+ */
36
+ export type ChildNodeWalker = ((node: unknown) => ChildNodeRef[]) & {
37
+ hasOwnContent?(node: unknown): boolean;
38
+ };
39
+ /**
40
+ * Builds the {@link ChildNodeWalker} for one composition's inventory.
41
+ *
42
+ * Pass every pack's definitions: a walker missing one cannot see children of a
43
+ * container that pack defines, and a tree walk would stop at its boundary.
44
+ */
45
+ export declare const createChildNodeWalker: (definitions: readonly {
46
+ type: string;
47
+ children?: unknown;
48
+ hasOwnContent?: unknown;
49
+ }[]) => ChildNodeWalker;
50
+ /** Joins a parent path with a {@link ChildNodeRef.path} fragment. */
51
+ export declare const childNodePath: (parent: string, child: string) => string;
52
+ /**
53
+ * Whether any node visible on `surface` matches, descending through container
54
+ * children via `walk`. A node (or a container ancestor) hidden from `surface`
55
+ * is skipped along with its children.
56
+ *
57
+ * `walk` must span every pack in the composition: a walker built from one
58
+ * pack's definitions cannot see children of a container defined in another.
59
+ */
60
+ export declare const someBodyNode: (nodes: readonly unknown[], surface: SurfaceName, predicate: (node: unknown) => boolean, walk: ChildNodeWalker) => boolean;
61
+ /** Whether `node`'s own `surfaces` hint admits `surface`, ignoring its children. */
62
+ export declare const isVisibleOnSurface: (node: unknown, surface: SurfaceName) => boolean;
63
+ /**
64
+ * Whether `node` puts anything on `surface` — itself or through a descendant.
65
+ *
66
+ * Stronger than {@link isVisibleOnSurface}: a container every one of whose
67
+ * children is hidden renders nothing, even though its own hint allows the
68
+ * surface. A hybrid container that also owns string fields declares
69
+ * {@link ChildNodeWalker.hasOwnContent} and keeps rendering regardless.
70
+ */
71
+ export declare const rendersOnSurface: (node: unknown, surface: SurfaceName, walk: ChildNodeWalker) => boolean;
72
+ //# sourceMappingURL=body_node_base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body_node_base.d.ts","sourceRoot":"","sources":["../../src/composition/body_node_base.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,6DAMhB,CAAC;AAEX,wCAAwC;AACxC,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,6CAA6C;AAC7C,eAAO,MA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.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
+ /**
8
+ * Every surface a node renders on or is hidden from, in render order.
9
+ *
10
+ * `html` is not here: the runtime's `html` surface wraps `react` output in a
11
+ * document, and no node targets it.
12
+ */
13
+ export const SURFACE_NAMES = [
14
+ 'react',
15
+ 'snapshot',
16
+ 'text',
17
+ 'markdown',
18
+ 'slack',
19
+ ];
20
+ /** @deprecated Use {@link SURFACE_NAMES}. */
21
+ export const BODY_NODE_SURFACES = SURFACE_NAMES;
22
+ /**
23
+ * Builds the {@link ChildNodeWalker} for one composition's inventory.
24
+ *
25
+ * Pass every pack's definitions: a walker missing one cannot see children of a
26
+ * container that pack defines, and a tree walk would stop at its boundary.
27
+ */
28
+ export const createChildNodeWalker = (definitions) => {
29
+ const childrenByType = new Map();
30
+ const ownContentByType = new Map();
31
+ for (const definition of definitions) {
32
+ if (typeof definition.children === 'function') {
33
+ childrenByType.set(definition.type, definition.children);
34
+ }
35
+ if (typeof definition.hasOwnContent === 'function') {
36
+ ownContentByType.set(definition.type, definition.hasOwnContent);
37
+ }
38
+ }
39
+ const walk = ((node) => {
40
+ if (!node || typeof node !== 'object') {
41
+ return [];
42
+ }
43
+ const { type } = node;
44
+ if (typeof type !== 'string') {
45
+ return [];
46
+ }
47
+ return [...(childrenByType.get(type)?.(node) ?? [])];
48
+ });
49
+ walk.hasOwnContent = (node) => {
50
+ if (!node || typeof node !== 'object') {
51
+ return false;
52
+ }
53
+ const { type } = node;
54
+ if (typeof type !== 'string') {
55
+ return false;
56
+ }
57
+ return ownContentByType.get(type)?.(node) ?? false;
58
+ };
59
+ return walk;
60
+ };
61
+ /** Joins a parent path with a {@link ChildNodeRef.path} fragment. */
62
+ export const childNodePath = (parent, child) => `${parent}.${child}`;
63
+ /**
64
+ * Whether any node visible on `surface` matches, descending through container
65
+ * children via `walk`. A node (or a container ancestor) hidden from `surface`
66
+ * is skipped along with its children.
67
+ *
68
+ * `walk` must span every pack in the composition: a walker built from one
69
+ * pack's definitions cannot see children of a container defined in another.
70
+ */
71
+ export const someBodyNode = (nodes, surface, predicate, walk) => nodes.some((node) => {
72
+ if (!isVisibleOnSurface(node, surface)) {
73
+ return false;
74
+ }
75
+ return (predicate(node) ||
76
+ someBodyNode(walk(node).map((child) => child.node), surface, predicate, walk));
77
+ });
78
+ /** Whether `node`'s own `surfaces` hint admits `surface`, ignoring its children. */
79
+ export const isVisibleOnSurface = (node, surface) => {
80
+ if (!node || typeof node !== 'object') {
81
+ return false;
82
+ }
83
+ const { surfaces } = node;
84
+ return !Array.isArray(surfaces) || surfaces.includes(surface);
85
+ };
86
+ /**
87
+ * Whether `node` puts anything on `surface` — itself or through a descendant.
88
+ *
89
+ * Stronger than {@link isVisibleOnSurface}: a container every one of whose
90
+ * children is hidden renders nothing, even though its own hint allows the
91
+ * surface. A hybrid container that also owns string fields declares
92
+ * {@link ChildNodeWalker.hasOwnContent} and keeps rendering regardless.
93
+ */
94
+ export const rendersOnSurface = (node, surface, walk) => {
95
+ if (!isVisibleOnSurface(node, surface)) {
96
+ return false;
97
+ }
98
+ const children = walk(node);
99
+ if (children.length === 0 || walk.hasOwnContent?.(node)) {
100
+ return true;
101
+ }
102
+ return children.some(({ node: child }) => rendersOnSurface(child, surface, walk));
103
+ };
104
+ //# sourceMappingURL=body_node_base.js.map