@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,127 @@
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 { z } from 'zod';
8
+ import { IsomerError } from '../composition/error.js';
9
+ import { renderThemeSchema } from './value_schemas.js';
10
+ /** `Composition.meta`: provenance and freshness, every field optional. */
11
+ export const metaSchema = z.object({
12
+ source: z.string().optional(),
13
+ generatedAt: z.string().optional(),
14
+ ariaLabel: z.string().optional(),
15
+ provenance: z
16
+ .object({
17
+ source: z.string().optional(),
18
+ query: z.string().optional(),
19
+ provider: z.string().optional(),
20
+ })
21
+ .optional(),
22
+ freshness: z
23
+ .object({
24
+ asOf: z.string().optional(),
25
+ stale: z.boolean().optional(),
26
+ ttlSeconds: z.number().optional(),
27
+ })
28
+ .optional(),
29
+ partialFailure: z
30
+ .object({
31
+ degraded: z.boolean().optional(),
32
+ reason: z.string().optional(),
33
+ })
34
+ .optional(),
35
+ });
36
+ /**
37
+ * Wraps a body-node union in the `Composition` envelope.
38
+ *
39
+ * `.strict()`, so an unknown root key is an error rather than silently carried:
40
+ * the format crosses vendor boundaries, and a typo'd field that validates is
41
+ * worse than one that fails. Most callers want
42
+ * {@link getCompositionSchemaForDefinitions} instead, which memoizes.
43
+ */
44
+ export const buildCompositionSchema = ({ bodyNodeSchema, }) => z
45
+ .object({
46
+ type: z.literal('view', { error: 'type must be "view"' }),
47
+ version: z.literal(1).optional(),
48
+ title: z.string().optional(),
49
+ subtitle: z.string().optional(),
50
+ theme: renderThemeSchema.optional(),
51
+ body: z
52
+ .array(bodyNodeSchema)
53
+ .min(1, { error: 'must contain at least one node' }),
54
+ meta: metaSchema.optional(),
55
+ })
56
+ .strict();
57
+ /**
58
+ * Builds a body-node union whose containers reference *this* union.
59
+ *
60
+ * The `z.lazy` closing the recursion is created here and discarded with the
61
+ * vocabulary: it memoizes its getter after the first resolution, so one shared
62
+ * across vocabularies would freeze on whichever union parsed first.
63
+ */
64
+ export const resolveVocabulary = (definitions) => {
65
+ if (definitions.length === 0) {
66
+ throw new IsomerError('EMPTY_VOCABULARY', 'resolveVocabulary: at least one primitive is required');
67
+ }
68
+ // Resolved once the union exists; nothing parses before this function returns.
69
+ const pending = {};
70
+ const resolveUnion = () => {
71
+ if (!pending.union) {
72
+ throw new IsomerError('VOCABULARY_UNRESOLVED', 'resolveVocabulary: body-node union read before its vocabulary resolved');
73
+ }
74
+ return pending.union;
75
+ };
76
+ const members = new Map();
77
+ const memberSchemas = definitions.map((definition) => {
78
+ const schema = definition.schemaFor
79
+ ? // One `z.lazy` per container: the JSON Schema projection gives a shared
80
+ // wrapper its own anonymous `$def` instead of `$ref: #/$defs/bodyNode`.
81
+ definition.schemaFor(z.lazy(resolveUnion))
82
+ : definition.schema;
83
+ members.set(definition.type, schema);
84
+ return schema;
85
+ });
86
+ pending.union = z.discriminatedUnion('type', memberSchemas);
87
+ return { bodyNodeSchema: pending.union, members };
88
+ };
89
+ /**
90
+ * {@link resolveVocabulary}, discarding the member instances.
91
+ *
92
+ * Only for a caller with no id registry to name; anything projecting to JSON
93
+ * Schema needs the members and should use {@link resolveVocabulary}.
94
+ */
95
+ export const buildBodyNodeSchemaFromDefinitions = (definitions) => resolveVocabulary(definitions).bodyNodeSchema;
96
+ /**
97
+ * A fresh `Composition` schema over `definitions`.
98
+ *
99
+ * Builds a new union per call. Prefer
100
+ * {@link getCompositionSchemaForDefinitions} unless a fresh instance is
101
+ * required.
102
+ */
103
+ export const buildCompositionSchemaFromDefinitions = (definitions) => buildCompositionSchema({
104
+ bodyNodeSchema: buildBodyNodeSchemaFromDefinitions(definitions),
105
+ });
106
+ const compositionSchemaCache = new WeakMap();
107
+ const cachedFor = (definitions) => {
108
+ const cached = compositionSchemaCache.get(definitions);
109
+ if (cached) {
110
+ return cached;
111
+ }
112
+ const vocabulary = resolveVocabulary(definitions);
113
+ const entry = {
114
+ vocabulary,
115
+ schema: buildCompositionSchema({
116
+ bodyNodeSchema: vocabulary.bodyNodeSchema,
117
+ }),
118
+ };
119
+ compositionSchemaCache.set(definitions, entry);
120
+ return entry;
121
+ };
122
+ /**
123
+ * {@link buildCompositionSchemaFromDefinitions}, memoized per definition array.
124
+ * Prefer this whenever the caller does not need a fresh schema instance.
125
+ */
126
+ export const getCompositionSchemaForDefinitions = (definitions) => cachedFor(definitions).schema;
127
+ //# sourceMappingURL=composition_schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composition_schema.js","sourceRoot":"","sources":["../../src/validate/composition_schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAgC,MAAM,KAAK,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,UAAU,EAAE,CAAC;SACV,MAAM,CAAC;QACN,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE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ChD,WAA8C,EAC5B,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,cAAc,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,CACnD,WAA8C,EACnC,EAAE,CACb,sBAAsB,CAAC;IACrB,cAAc,EAAE,kCAAkC,CAAC,WAAW,CAAC;CAChE,CAAC,CAAC;AAYL,MAAM,sBAAsB,GAAG,IAAI,OAAO,EAAmC,CAAC;AAE9E,MAAM,SAAS,GAAG,CAChB,WAA8C,EACrB,EAAE;IAC3B,MAAM,MAAM,GAAG,sBAAsB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACvD,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,MAAM,UAAU,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAClD,MAAM,KAAK,GAA4B;QACrC,UAAU;QACV,MAAM,EAAE,sBAAsB,CAAC;YAC7B,cAAc,EAAE,UAAU,CAAC,cAAc;SAC1C,CAAC;KACH,CAAC;IACF,sBAAsB,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC/C,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,WAA8C,EACnC,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,MAAM,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 { z, type ZodObject, type ZodType } from 'zod';\n\nimport { IsomerError } from '../composition/error';\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport { renderThemeSchema } from './value_schemas';\n\n/** `Composition.meta`: provenance and freshness, every field optional. */\nexport const metaSchema = z.object({\n source: z.string().optional(),\n generatedAt: z.string().optional(),\n ariaLabel: z.string().optional(),\n provenance: z\n .object({\n source: z.string().optional(),\n query: z.string().optional(),\n provider: z.string().optional(),\n })\n .optional(),\n freshness: z\n .object({\n asOf: z.string().optional(),\n stale: z.boolean().optional(),\n ttlSeconds: z.number().optional(),\n })\n .optional(),\n partialFailure: z\n .object({\n degraded: z.boolean().optional(),\n reason: z.string().optional(),\n })\n .optional(),\n});\n\n/** Options for the `Composition` envelope schema a body-node union is wrapped in. */\nexport interface CompositionSchemaOptions {\n /** The union the envelope's `body` array holds, as {@link resolveVocabulary} builds it. */\n bodyNodeSchema: ZodType<unknown>;\n}\n\n/**\n * Wraps a body-node union in the `Composition` envelope.\n *\n * `.strict()`, so an unknown root key is an error rather than silently carried:\n * the format crosses vendor boundaries, and a typo'd field that validates is\n * worse than one that fails. Most callers want\n * {@link getCompositionSchemaForDefinitions} instead, which memoizes.\n */\nexport const buildCompositionSchema = ({\n bodyNodeSchema,\n}: CompositionSchemaOptions): ZodObject =>\n z\n .object({\n type: z.literal('view', { error: 'type must be \"view\"' }),\n version: z.literal(1).optional(),\n title: z.string().optional(),\n subtitle: z.string().optional(),\n theme: renderThemeSchema.optional(),\n body: z\n .array(bodyNodeSchema)\n .min(1, { error: 'must contain at least one node' }),\n meta: metaSchema.optional(),\n })\n .strict();\n\n/**\n * One set of definitions resolved into a body-node union, with the schema\n * instance that actually landed in it per primitive type.\n *\n * The members matter to callers because a container's schema in the union is\n * built by `schemaFor` and is therefore *not* `definition.schema`. Anything\n * keyed on identity — the JSON Schema id registry, which names `$defs` — has to\n * be given these, or a container's projection silently loses its name.\n */\nexport interface ResolvedVocabulary {\n /** The discriminated union over every primitive type in this vocabulary. */\n bodyNodeSchema: ZodType<unknown>;\n /** Keyed by node type. A container's value comes from `schemaFor`, not `definition.schema`. */\n members: ReadonlyMap<string, ZodObject>;\n}\n\n/**\n * Builds a body-node union whose containers reference *this* union.\n *\n * The `z.lazy` closing the recursion is created here and discarded with the\n * vocabulary: it memoizes its getter after the first resolution, so one shared\n * across vocabularies would freeze on whichever union parsed first.\n */\nexport const resolveVocabulary = (\n definitions: readonly AnyPrimitiveDefinition[]\n): ResolvedVocabulary => {\n if (definitions.length === 0) {\n throw new IsomerError(\n 'EMPTY_VOCABULARY',\n 'resolveVocabulary: at least one primitive is required'\n );\n }\n // Resolved once the union exists; nothing parses before this function returns.\n const pending: { union?: ZodType<unknown> } = {};\n const resolveUnion = (): ZodType<unknown> => {\n if (!pending.union) {\n throw new IsomerError(\n 'VOCABULARY_UNRESOLVED',\n 'resolveVocabulary: body-node union read before its vocabulary resolved'\n );\n }\n return pending.union;\n };\n\n const members = new Map<string, ZodObject>();\n const memberSchemas = definitions.map((definition) => {\n const schema = definition.schemaFor\n ? // One `z.lazy` per container: the JSON Schema projection gives a shared\n // wrapper its own anonymous `$def` instead of `$ref: #/$defs/bodyNode`.\n definition.schemaFor(z.lazy(resolveUnion))\n : definition.schema;\n members.set(definition.type, schema);\n return schema;\n });\n\n pending.union = z.discriminatedUnion(\n 'type',\n memberSchemas as [ZodObject, ...ZodObject[]]\n );\n return { bodyNodeSchema: pending.union, members };\n};\n\n/**\n * {@link resolveVocabulary}, discarding the member instances.\n *\n * Only for a caller with no id registry to name; anything projecting to JSON\n * Schema needs the members and should use {@link resolveVocabulary}.\n */\nexport const buildBodyNodeSchemaFromDefinitions = (\n definitions: readonly AnyPrimitiveDefinition[]\n): ZodType<unknown> => resolveVocabulary(definitions).bodyNodeSchema;\n\n/**\n * A fresh `Composition` schema over `definitions`.\n *\n * Builds a new union per call. Prefer\n * {@link getCompositionSchemaForDefinitions} unless a fresh instance is\n * required.\n */\nexport const buildCompositionSchemaFromDefinitions = (\n definitions: readonly AnyPrimitiveDefinition[]\n): ZodObject =>\n buildCompositionSchema({\n bodyNodeSchema: buildBodyNodeSchemaFromDefinitions(definitions),\n });\n\n// Keyed on the definition array's identity: a runtime needs the same schema\n// for its validator, parser, and authoring context, so hold the array\n// `composePacks` returns rather than flattening per call. The vocabulary is\n// cached with the schema because the JSON Schema id registry names member\n// instances, and a second resolution would produce different ones.\ninterface CachedCompositionSchema {\n schema: ZodObject;\n vocabulary: ResolvedVocabulary;\n}\n\nconst compositionSchemaCache = new WeakMap<object, CachedCompositionSchema>();\n\nconst cachedFor = (\n definitions: readonly AnyPrimitiveDefinition[]\n): CachedCompositionSchema => {\n const cached = compositionSchemaCache.get(definitions);\n if (cached) {\n return cached;\n }\n const vocabulary = resolveVocabulary(definitions);\n const entry: CachedCompositionSchema = {\n vocabulary,\n schema: buildCompositionSchema({\n bodyNodeSchema: vocabulary.bodyNodeSchema,\n }),\n };\n compositionSchemaCache.set(definitions, entry);\n return entry;\n};\n\n/**\n * {@link buildCompositionSchemaFromDefinitions}, memoized per definition array.\n * Prefer this whenever the caller does not need a fresh schema instance.\n */\nexport const getCompositionSchemaForDefinitions = (\n definitions: readonly AnyPrimitiveDefinition[]\n): ZodObject => cachedFor(definitions).schema;\n"]}
@@ -0,0 +1,9 @@
1
+ export { type AuthoringJsonSchemaOptions, authoringSchemaSubset, buildAuthoringJsonSchema, } from './authoring_schema.js';
2
+ export { type CompositionSchemaOptions, buildBodyNodeSchemaFromDefinitions, buildCompositionSchema, buildCompositionSchemaFromDefinitions, getCompositionSchemaForDefinitions, metaSchema, } from './composition_schema.js';
3
+ export { type InputBudget, type InputBudgetCheck, MAX_INPUT_CHARACTERS, MAX_INPUT_DEPTH, MAX_INPUT_VALUES, checkInputBudget, isInputRefusal, } from './input_budget.js';
4
+ export { type CompositionJsonSchemaOptions, buildCompositionJsonSchema, } from './json_schema.js';
5
+ export { type IssueRoot, createNodeIssueFormatter } from './node_issues.js';
6
+ export { type UrlSchemaOptions, ASSET_URL_MESSAGE, ASSET_URL_RULE, BLOCKED_HREF, NAVIGATION_HREF_MESSAGE, NAVIGATION_HREF_RULE, assetUrl, navigationHref, sanitizeAssetUrl, sanitizeNavigationHref, sanitizeParsedAssetUrl, sanitizeParsedNavigationHref, } from './url.js';
7
+ export { type CheckedComposition, type CheckedValidationResult, type CompositionValidatorOptions, type ParsedComposition, type ValidationErrorMode, type ValidationResult, type ValidationWarning, compositionToRender, CompositionValidationError, createCompositionParser, createCompositionValidator, warningsForSurface, } from './validation.js';
8
+ export { displayValueSchema, namedColorSchema, renderThemeSchema, structuredValueSchema, } from './value_schemas.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,0BAA0B,EAC/B,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,wBAAwB,EAC7B,kCAAkC,EAClC,sBAAsB,EACtB,qCAAqC,EACrC,kCAAkC,EAClC,UAAU,GACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,4BAA4B,EACjC,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,SAAS,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACL,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,uBAAuB,EACvB,oBAAoB,EACpB,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,OAAO,CAAC;AACf,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAChC,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,mBAAmB,EACnB,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,15 @@
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 { authoringSchemaSubset, buildAuthoringJsonSchema, } from './authoring_schema.js';
8
+ export { buildBodyNodeSchemaFromDefinitions, buildCompositionSchema, buildCompositionSchemaFromDefinitions, getCompositionSchemaForDefinitions, metaSchema, } from './composition_schema.js';
9
+ export { MAX_INPUT_CHARACTERS, MAX_INPUT_DEPTH, MAX_INPUT_VALUES, checkInputBudget, isInputRefusal, } from './input_budget.js';
10
+ export { buildCompositionJsonSchema, } from './json_schema.js';
11
+ export { createNodeIssueFormatter } from './node_issues.js';
12
+ export { ASSET_URL_MESSAGE, ASSET_URL_RULE, BLOCKED_HREF, NAVIGATION_HREF_MESSAGE, NAVIGATION_HREF_RULE, assetUrl, navigationHref, sanitizeAssetUrl, sanitizeNavigationHref, sanitizeParsedAssetUrl, sanitizeParsedNavigationHref, } from './url.js';
13
+ export { compositionToRender, CompositionValidationError, createCompositionParser, createCompositionValidator, warningsForSurface, } from './validation.js';
14
+ export { displayValueSchema, namedColorSchema, renderThemeSchema, structuredValueSchema, } from './value_schemas.js';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,kCAAkC,EAClC,sBAAsB,EACtB,qCAAqC,EACrC,kCAAkC,EAClC,UAAU,GACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAkB,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAEL,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,uBAAuB,EACvB,oBAAoB,EACpB,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,OAAO,CAAC;AACf,OAAO,EAQL,mBAAmB,EACnB,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,iBAAiB,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\nexport {\n type AuthoringJsonSchemaOptions,\n authoringSchemaSubset,\n buildAuthoringJsonSchema,\n} from './authoring_schema';\nexport {\n type CompositionSchemaOptions,\n buildBodyNodeSchemaFromDefinitions,\n buildCompositionSchema,\n buildCompositionSchemaFromDefinitions,\n getCompositionSchemaForDefinitions,\n metaSchema,\n} from './composition_schema';\nexport {\n type InputBudget,\n type InputBudgetCheck,\n MAX_INPUT_CHARACTERS,\n MAX_INPUT_DEPTH,\n MAX_INPUT_VALUES,\n checkInputBudget,\n isInputRefusal,\n} from './input_budget';\nexport {\n type CompositionJsonSchemaOptions,\n buildCompositionJsonSchema,\n} from './json_schema';\nexport { type IssueRoot, createNodeIssueFormatter } from './node_issues';\nexport {\n type UrlSchemaOptions,\n ASSET_URL_MESSAGE,\n ASSET_URL_RULE,\n BLOCKED_HREF,\n NAVIGATION_HREF_MESSAGE,\n NAVIGATION_HREF_RULE,\n assetUrl,\n navigationHref,\n sanitizeAssetUrl,\n sanitizeNavigationHref,\n sanitizeParsedAssetUrl,\n sanitizeParsedNavigationHref,\n} from './url';\nexport {\n type CheckedComposition,\n type CheckedValidationResult,\n type CompositionValidatorOptions,\n type ParsedComposition,\n type ValidationErrorMode,\n type ValidationResult,\n type ValidationWarning,\n compositionToRender,\n CompositionValidationError,\n createCompositionParser,\n createCompositionValidator,\n warningsForSurface,\n} from './validation';\nexport {\n displayValueSchema,\n namedColorSchema,\n renderThemeSchema,\n structuredValueSchema,\n} from './value_schemas';\n"]}
@@ -0,0 +1,35 @@
1
+ import type { ValidationError } from '../composition/validation_error.js';
2
+ /** Objects and arrays nested in one another, the input itself included. */
3
+ export declare const MAX_INPUT_DEPTH = 64;
4
+ /** Every object, array, and leaf counts once. */
5
+ export declare const MAX_INPUT_VALUES = 20000;
6
+ /** Every object key and string, and each other leaf as `String` prints it. */
7
+ export declare const MAX_INPUT_CHARACTERS = 1000000;
8
+ /** Overrides for the limits {@link checkInputBudget} enforces; an omitted one keeps its default. */
9
+ export interface InputBudget {
10
+ /** Defaults to {@link MAX_INPUT_DEPTH}. Zod parses what passes recursively, so a few hundred nested containers can exhaust the call stack. */
11
+ depth?: number;
12
+ /** Defaults to {@link MAX_INPUT_VALUES}. */
13
+ values?: number;
14
+ /** Defaults to {@link MAX_INPUT_CHARACTERS}. */
15
+ characters?: number;
16
+ }
17
+ /** Whether `error` is a refusal before parsing, which no validation mode collects. */
18
+ export declare const isInputRefusal: ({ code, }: Pick<ValidationError, "code">) => boolean;
19
+ /** A plain copy of the input to parse in its place, or why there is none. */
20
+ export type InputBudgetCheck = {
21
+ valid: true;
22
+ value: unknown;
23
+ } | {
24
+ valid: false;
25
+ error: ValidationError;
26
+ };
27
+ /**
28
+ * A plain copy of `value` within `budget`, or why there is none: it is over `budget` or is not plain data.
29
+ *
30
+ * Plain data is arrays without holes, objects whose prototype is `Object.prototype` or `null`, enumerable own data properties with string keys, and primitives other than functions.
31
+ * Each property is read once, so a caller that parses the copy parses exactly what was checked; an array's other own properties are left out.
32
+ * Iterative and cycle-safe. Its cost is linear in the input's size: it lists a container's own keys, then refuses past the value limit before reading any of them.
33
+ */
34
+ export declare const checkInputBudget: (value: unknown, budget?: InputBudget) => InputBudgetCheck;
35
+ //# sourceMappingURL=input_budget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input_budget.d.ts","sourceRoot":"","sources":["../../src/validate/input_budget.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,2EAA2E;AAC3E,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,iDAAiD;AACjD,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAEvC,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,UAAY,CAAC;AAE9C,oGAAoG;AACpG,MAAM,WAAW,WAAW;IAC1B,8IAA8I;IAC9I,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAQD,sFAAsF;AACtF,eAAO,MAAM,cAAc,GAAI,WAE5B,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,KAAG,OAAwC,CAAC;AAE5E,6EAA6E;AAC7E,MAAM,MAAM,gBAAgB,GAC1B;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,CAAC;AAiD7E;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAC3B,OAAO,OAAO,EACd,SAAQ,WAAgB,KACvB,gBA6FF,CAAC"}
@@ -0,0 +1,151 @@
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 { ISOMER_ERROR_CODES } from '../composition/error.js';
8
+ /** Objects and arrays nested in one another, the input itself included. */
9
+ export const MAX_INPUT_DEPTH = 64;
10
+ /** Every object, array, and leaf counts once. */
11
+ export const MAX_INPUT_VALUES = 20_000;
12
+ /** Every object key and string, and each other leaf as `String` prints it. */
13
+ export const MAX_INPUT_CHARACTERS = 1_000_000;
14
+ /** The codes {@link checkInputBudget} refuses with. */
15
+ const INPUT_REFUSAL_CODES = new Set([
16
+ ISOMER_ERROR_CODES.INPUT_NOT_PLAIN_DATA,
17
+ ISOMER_ERROR_CODES.INPUT_OVER_BUDGET,
18
+ ]);
19
+ /** Whether `error` is a refusal before parsing, which no validation mode collects. */
20
+ export const isInputRefusal = ({ code, }) => INPUT_REFUSAL_CODES.has(code);
21
+ class Refusal extends Error {
22
+ error;
23
+ constructor(error) {
24
+ super(error.message);
25
+ this.error = error;
26
+ }
27
+ }
28
+ const overBudget = (message) => new Refusal({
29
+ path: '',
30
+ message,
31
+ code: ISOMER_ERROR_CODES.INPUT_OVER_BUDGET,
32
+ });
33
+ const notPlainData = (what) => new Refusal({
34
+ path: '',
35
+ message: `input holds ${what}, which is not plain data`,
36
+ code: ISOMER_ERROR_CODES.INPUT_NOT_PLAIN_DATA,
37
+ });
38
+ const leafLength = (value) => typeof value === 'string' ? value.length : String(value).length;
39
+ /** Reads `key` once, through its descriptor. */
40
+ const plainProperty = (source, key) => {
41
+ const descriptor = Reflect.getOwnPropertyDescriptor(source, key);
42
+ if (descriptor === undefined) {
43
+ throw notPlainData('an array hole');
44
+ }
45
+ if (!('value' in descriptor)) {
46
+ throw notPlainData('an accessor property');
47
+ }
48
+ if (!descriptor.enumerable) {
49
+ throw notPlainData('a non-enumerable property');
50
+ }
51
+ return descriptor.value;
52
+ };
53
+ /**
54
+ * A plain copy of `value` within `budget`, or why there is none: it is over `budget` or is not plain data.
55
+ *
56
+ * Plain data is arrays without holes, objects whose prototype is `Object.prototype` or `null`, enumerable own data properties with string keys, and primitives other than functions.
57
+ * Each property is read once, so a caller that parses the copy parses exactly what was checked; an array's other own properties are left out.
58
+ * Iterative and cycle-safe. Its cost is linear in the input's size: it lists a container's own keys, then refuses past the value limit before reading any of them.
59
+ */
60
+ export const checkInputBudget = (value, budget = {}) => {
61
+ const { depth: maxDepth = MAX_INPUT_DEPTH, values: maxValues = MAX_INPUT_VALUES, characters: maxCharacters = MAX_INPUT_CHARACTERS, } = budget;
62
+ const tooManyValues = `input holds more than ${maxValues} values`;
63
+ const ancestors = new Set();
64
+ const stack = [];
65
+ let values = 0;
66
+ let characters = 0;
67
+ const countCharacters = (count) => {
68
+ characters += count;
69
+ if (characters > maxCharacters) {
70
+ throw overBudget(`input holds more than ${maxCharacters} characters`);
71
+ }
72
+ };
73
+ const enqueue = (child, depth, keyLength) => {
74
+ values += 1;
75
+ if (values > maxValues) {
76
+ throw overBudget(tooManyValues);
77
+ }
78
+ if (typeof child === 'function') {
79
+ throw notPlainData('a function');
80
+ }
81
+ if (typeof child !== 'object' || child === null) {
82
+ countCharacters(keyLength + leafLength(child));
83
+ return child;
84
+ }
85
+ let copy = [];
86
+ if (!Array.isArray(child)) {
87
+ const prototype = Reflect.getPrototypeOf(child);
88
+ if (prototype !== Object.prototype && prototype !== null) {
89
+ throw notPlainData('an object that is not a plain object or array');
90
+ }
91
+ copy = Object.create(prototype);
92
+ }
93
+ countCharacters(keyLength);
94
+ stack.push({ source: child, copy, depth });
95
+ return copy;
96
+ };
97
+ const copyChildren = ({ source, copy, depth }) => {
98
+ const keys = Array.isArray(copy) ? undefined : Reflect.ownKeys(source);
99
+ const count = keys?.length ?? source.length;
100
+ if (values + count > maxValues) {
101
+ throw overBudget(tooManyValues);
102
+ }
103
+ for (let index = 0; index < count; index += 1) {
104
+ const key = keys === undefined ? index : keys[index];
105
+ if (typeof key === 'symbol') {
106
+ throw notPlainData('a symbol key');
107
+ }
108
+ const child = plainProperty(source, key);
109
+ if (Array.isArray(copy)) {
110
+ copy.push(enqueue(child, depth, 0));
111
+ }
112
+ else {
113
+ Object.defineProperty(copy, key, {
114
+ value: enqueue(child, depth, String(key).length),
115
+ writable: true,
116
+ enumerable: true,
117
+ configurable: true,
118
+ });
119
+ }
120
+ }
121
+ };
122
+ try {
123
+ const root = enqueue(value, 1, 0);
124
+ while (stack.length > 0) {
125
+ const entry = stack.pop();
126
+ const { source, depth, leave } = entry;
127
+ if (leave) {
128
+ ancestors.delete(source);
129
+ }
130
+ else if (ancestors.has(source)) {
131
+ throw overBudget('input contains itself');
132
+ }
133
+ else if (depth > maxDepth) {
134
+ throw overBudget(`input nests deeper than ${maxDepth} levels`);
135
+ }
136
+ else {
137
+ ancestors.add(source);
138
+ stack.push({ ...entry, leave: true });
139
+ copyChildren({ ...entry, depth: depth + 1 });
140
+ }
141
+ }
142
+ return { valid: true, value: root };
143
+ }
144
+ catch (error) {
145
+ if (error instanceof Refusal) {
146
+ return { valid: false, error: error.error };
147
+ }
148
+ throw error;
149
+ }
150
+ };
151
+ //# sourceMappingURL=input_budget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input_budget.js","sourceRoot":"","sources":["../../src/validate/input_budget.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,2EAA2E;AAC3E,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC,iDAAiD;AACjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEvC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AAY9C,uDAAuD;AACvD,MAAM,mBAAmB,GAAoC,IAAI,GAAG,CAAC;IACnE,kBAAkB,CAAC,oBAAoB;IACvC,kBAAkB,CAAC,iBAAiB;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iBAAM,CAAC;gBACN,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBACtB,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBACtC,YAAY,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,OAAO,EAAE,CAAC;YAC7B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;QAC9C,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,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 { ISOMER_ERROR_CODES } from '../composition/error';\nimport type { ValidationError } from '../composition/validation_error';\n\n/** Objects and arrays nested in one another, the input itself included. */\nexport const MAX_INPUT_DEPTH = 64;\n\n/** Every object, array, and leaf counts once. */\nexport const MAX_INPUT_VALUES = 20_000;\n\n/** Every object key and string, and each other leaf as `String` prints it. */\nexport const MAX_INPUT_CHARACTERS = 1_000_000;\n\n/** Overrides for the limits {@link checkInputBudget} enforces; an omitted one keeps its default. */\nexport interface InputBudget {\n /** Defaults to {@link MAX_INPUT_DEPTH}. Zod parses what passes recursively, so a few hundred nested containers can exhaust the call stack. */\n depth?: number;\n /** Defaults to {@link MAX_INPUT_VALUES}. */\n values?: number;\n /** Defaults to {@link MAX_INPUT_CHARACTERS}. */\n characters?: number;\n}\n\n/** The codes {@link checkInputBudget} refuses with. */\nconst INPUT_REFUSAL_CODES: ReadonlySet<string | undefined> = new Set([\n ISOMER_ERROR_CODES.INPUT_NOT_PLAIN_DATA,\n ISOMER_ERROR_CODES.INPUT_OVER_BUDGET,\n]);\n\n/** Whether `error` is a refusal before parsing, which no validation mode collects. */\nexport const isInputRefusal = ({\n code,\n}: Pick<ValidationError, 'code'>): boolean => INPUT_REFUSAL_CODES.has(code);\n\n/** A plain copy of the input to parse in its place, or why there is none. */\nexport type InputBudgetCheck =\n { valid: true; value: unknown } | { valid: false; error: ValidationError };\n\ntype PlainContainer = unknown[] | Record<string, unknown>;\n\ninterface Entry {\n source: object;\n copy: PlainContainer;\n depth: number;\n leave?: true;\n}\n\nclass Refusal extends Error {\n constructor(readonly error: ValidationError) {\n super(error.message);\n }\n}\n\nconst overBudget = (message: string): Refusal =>\n new Refusal({\n path: '',\n message,\n code: ISOMER_ERROR_CODES.INPUT_OVER_BUDGET,\n });\n\nconst notPlainData = (what: string): Refusal =>\n new Refusal({\n path: '',\n message: `input holds ${what}, which is not plain data`,\n code: ISOMER_ERROR_CODES.INPUT_NOT_PLAIN_DATA,\n });\n\nconst leafLength = (value: unknown): number =>\n typeof value === 'string' ? value.length : String(value).length;\n\n/** Reads `key` once, through its descriptor. */\nconst plainProperty = (source: object, key: string | number): unknown => {\n const descriptor = Reflect.getOwnPropertyDescriptor(source, key);\n if (descriptor === undefined) {\n throw notPlainData('an array hole');\n }\n if (!('value' in descriptor)) {\n throw notPlainData('an accessor property');\n }\n if (!descriptor.enumerable) {\n throw notPlainData('a non-enumerable property');\n }\n return descriptor.value;\n};\n\n/**\n * A plain copy of `value` within `budget`, or why there is none: it is over `budget` or is not plain data.\n *\n * Plain data is arrays without holes, objects whose prototype is `Object.prototype` or `null`, enumerable own data properties with string keys, and primitives other than functions.\n * Each property is read once, so a caller that parses the copy parses exactly what was checked; an array's other own properties are left out.\n * Iterative and cycle-safe. Its cost is linear in the input's size: it lists a container's own keys, then refuses past the value limit before reading any of them.\n */\nexport const checkInputBudget = (\n value: unknown,\n budget: InputBudget = {}\n): InputBudgetCheck => {\n const {\n depth: maxDepth = MAX_INPUT_DEPTH,\n values: maxValues = MAX_INPUT_VALUES,\n characters: maxCharacters = MAX_INPUT_CHARACTERS,\n } = budget;\n const tooManyValues = `input holds more than ${maxValues} values`;\n const ancestors = new Set<object>();\n const stack: Entry[] = [];\n let values = 0;\n let characters = 0;\n const countCharacters = (count: number): void => {\n characters += count;\n if (characters > maxCharacters) {\n throw overBudget(`input holds more than ${maxCharacters} characters`);\n }\n };\n const enqueue = (\n child: unknown,\n depth: number,\n keyLength: number\n ): unknown => {\n values += 1;\n if (values > maxValues) {\n throw overBudget(tooManyValues);\n }\n if (typeof child === 'function') {\n throw notPlainData('a function');\n }\n if (typeof child !== 'object' || child === null) {\n countCharacters(keyLength + leafLength(child));\n return child;\n }\n let copy: PlainContainer = [];\n if (!Array.isArray(child)) {\n const prototype = Reflect.getPrototypeOf(child);\n if (prototype !== Object.prototype && prototype !== null) {\n throw notPlainData('an object that is not a plain object or array');\n }\n copy = Object.create(prototype) as Record<string, unknown>;\n }\n countCharacters(keyLength);\n stack.push({ source: child, copy, depth });\n return copy;\n };\n const copyChildren = ({ source, copy, depth }: Entry): void => {\n const keys = Array.isArray(copy) ? undefined : Reflect.ownKeys(source);\n const count = keys?.length ?? (source as unknown[]).length;\n if (values + count > maxValues) {\n throw overBudget(tooManyValues);\n }\n for (let index = 0; index < count; index += 1) {\n const key = keys === undefined ? index : keys[index]!;\n if (typeof key === 'symbol') {\n throw notPlainData('a symbol key');\n }\n const child = plainProperty(source, key);\n if (Array.isArray(copy)) {\n copy.push(enqueue(child, depth, 0));\n } else {\n Object.defineProperty(copy, key, {\n value: enqueue(child, depth, String(key).length),\n writable: true,\n enumerable: true,\n configurable: true,\n });\n }\n }\n };\n try {\n const root = enqueue(value, 1, 0);\n while (stack.length > 0) {\n const entry = stack.pop()!;\n const { source, depth, leave } = entry;\n if (leave) {\n ancestors.delete(source);\n } else if (ancestors.has(source)) {\n throw overBudget('input contains itself');\n } else if (depth > maxDepth) {\n throw overBudget(`input nests deeper than ${maxDepth} levels`);\n } else {\n ancestors.add(source);\n stack.push({ ...entry, leave: true });\n copyChildren({ ...entry, depth: depth + 1 });\n }\n }\n return { valid: true, value: root };\n } catch (error) {\n if (error instanceof Refusal) {\n return { valid: false, error: error.error };\n }\n throw error;\n }\n};\n"]}
@@ -0,0 +1,32 @@
1
+ import { type ZodType } from 'zod';
2
+ import type { AnyPrimitiveDefinition } from '../define/primitive_module.js';
3
+ type JsonSchema = Record<string, unknown>;
4
+ /** Options for {@link buildCompositionJsonSchema}. */
5
+ export interface CompositionJsonSchemaOptions {
6
+ /** Base URI for the emitted schema, which `$ref`s resolve against. */
7
+ $id?: string;
8
+ /** Reaches the model, so it keeps the word "view". Defaults to `'View'`. */
9
+ title?: string;
10
+ /** Reaches the model too, so write it as guidance rather than as a type note. */
11
+ description?: string;
12
+ /**
13
+ * Extra schemas to name in `$defs`, for types a pack references by `$ref`.
14
+ * Each `id` becomes the `$defs` key, so it must be unique.
15
+ */
16
+ extraDefs?: readonly {
17
+ schema: ZodType;
18
+ id: string;
19
+ }[];
20
+ /** `ref` gives a repeated schema its own `$def`; `inline` repeats it. Defaults to `ref`. */
21
+ reused?: 'ref' | 'inline';
22
+ }
23
+ /**
24
+ * Projects the composition schema to JSON Schema draft 2020-12, for hosts
25
+ * that validate outside TypeScript.
26
+ *
27
+ * `$defs` are named per primitive type, plus `bodyNode` for the union.
28
+ * Agent-facing prompt text uses `buildAuthoringJsonSchema` instead.
29
+ */
30
+ export declare const buildCompositionJsonSchema: (definitions: readonly AnyPrimitiveDefinition[], options?: CompositionJsonSchemaOptions) => JsonSchema;
31
+ export {};
32
+ //# sourceMappingURL=json_schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json_schema.d.ts","sourceRoot":"","sources":["../../src/validate/json_schema.ts"],"names":[],"mappings":"AAOA,OAAO,EAAK,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAOzE,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C,sDAAsD;AACtD,MAAM,WAAW,4BAA4B;IAC3C,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACvD,4FAA4F;IAC5F,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACrC,aAAa,SAAS,sBAAsB,EAAE,EAC9C,UAAS,4BAAiC,KACzC,UAmDF,CAAC"}
@@ -0,0 +1,68 @@
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 { z } from 'zod';
8
+ import { buildCompositionSchema, resolveVocabulary, } from './composition_schema.js';
9
+ /**
10
+ * Projects the composition schema to JSON Schema draft 2020-12, for hosts
11
+ * that validate outside TypeScript.
12
+ *
13
+ * `$defs` are named per primitive type, plus `bodyNode` for the union.
14
+ * Agent-facing prompt text uses `buildAuthoringJsonSchema` instead.
15
+ */
16
+ export const buildCompositionJsonSchema = (definitions, options = {}) => {
17
+ // Members, not `definition.schema`: a container's member is built by
18
+ // `schemaFor`, and the registry is keyed on identity.
19
+ const composed = resolveVocabulary(definitions);
20
+ const { bodyNodeSchema, members } = composed;
21
+ const compositionSchema = buildCompositionSchema({ bodyNodeSchema });
22
+ // `metadata` replaces `z.toJSONSchema`'s default registry rather than
23
+ // extending it, and `z.globalRegistry` is where every `.describe()` lives,
24
+ // so ids are added to the global registry for the duration of this call
25
+ // and the prior entries restored in `finally`. Only a schema's first
26
+ // registration is recorded: a schema named twice (an `extraDefs` entry that
27
+ // is also a member) must restore its original entry, not the first id.
28
+ const previous = new Map();
29
+ const registerId = (schema, id) => {
30
+ if (!previous.has(schema)) {
31
+ previous.set(schema, z.globalRegistry.get(schema));
32
+ }
33
+ z.globalRegistry.add(schema, { ...z.globalRegistry.get(schema), id });
34
+ };
35
+ registerId(bodyNodeSchema, 'bodyNode');
36
+ for (const extra of options.extraDefs ?? []) {
37
+ registerId(extra.schema, extra.id);
38
+ }
39
+ for (const [type, schema] of members) {
40
+ registerId(schema, type);
41
+ }
42
+ try {
43
+ return {
44
+ ...z.toJSONSchema(compositionSchema, {
45
+ target: 'draft-2020-12',
46
+ metadata: z.globalRegistry,
47
+ reused: options.reused ?? 'ref',
48
+ cycles: 'ref',
49
+ unrepresentable: 'any',
50
+ }),
51
+ ...(options.$id ? { $id: options.$id } : {}),
52
+ title: options.title ?? 'View',
53
+ description: options.description ??
54
+ 'A compact view that may include registered primitives.',
55
+ };
56
+ }
57
+ finally {
58
+ for (const [schema, entry] of previous) {
59
+ if (entry === undefined) {
60
+ z.globalRegistry.remove(schema);
61
+ }
62
+ else {
63
+ z.globalRegistry.add(schema, entry);
64
+ }
65
+ }
66
+ }
67
+ };
68
+ //# sourceMappingURL=json_schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json_schema.js","sourceRoot":"","sources":["../../src/validate/json_schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAgB,MAAM,KAAK,CAAC;AAItC,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAqB9B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,WAA8C,EAC9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e;gBACvB,QAAQ,EAAE,CAAC,CAAC,cAAc;gBAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK;gBAC/B,MAAM,EAAE,KAAK;gBACb,eAAe,EAAE,KAAK;aACvB,CAAC;YACF,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5C,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,MAAM;YAC9B,WAAW,EACT,OAAO,CAAC,WAAW;gBACnB,wDAAwD;SAC3D,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,QAAQ,EAAE,CAAC;YACvC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,KAAc,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;IACH,CAAC;AACH,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 { z, type ZodType } from 'zod';\n\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\n\nimport {\n buildCompositionSchema,\n resolveVocabulary,\n} from './composition_schema';\n\ntype JsonSchema = Record<string, unknown>;\n\n/** Options for {@link buildCompositionJsonSchema}. */\nexport interface CompositionJsonSchemaOptions {\n /** Base URI for the emitted schema, which `$ref`s resolve against. */\n $id?: string;\n /** Reaches the model, so it keeps the word \"view\". Defaults to `'View'`. */\n title?: string;\n /** Reaches the model too, so write it as guidance rather than as a type note. */\n description?: string;\n /**\n * Extra schemas to name in `$defs`, for types a pack references by `$ref`.\n * Each `id` becomes the `$defs` key, so it must be unique.\n */\n extraDefs?: readonly { schema: ZodType; id: string }[];\n /** `ref` gives a repeated schema its own `$def`; `inline` repeats it. Defaults to `ref`. */\n reused?: 'ref' | 'inline';\n}\n\n/**\n * Projects the composition schema to JSON Schema draft 2020-12, for hosts\n * that validate outside TypeScript.\n *\n * `$defs` are named per primitive type, plus `bodyNode` for the union.\n * Agent-facing prompt text uses `buildAuthoringJsonSchema` instead.\n */\nexport const buildCompositionJsonSchema = (\n definitions: readonly AnyPrimitiveDefinition[],\n options: CompositionJsonSchemaOptions = {}\n): JsonSchema => {\n // Members, not `definition.schema`: a container's member is built by\n // `schemaFor`, and the registry is keyed on identity.\n const composed = resolveVocabulary(definitions);\n const { bodyNodeSchema, members } = composed;\n const compositionSchema = buildCompositionSchema({ bodyNodeSchema });\n\n // `metadata` replaces `z.toJSONSchema`'s default registry rather than\n // extending it, and `z.globalRegistry` is where every `.describe()` lives,\n // so ids are added to the global registry for the duration of this call\n // and the prior entries restored in `finally`. Only a schema's first\n // registration is recorded: a schema named twice (an `extraDefs` entry that\n // is also a member) must restore its original entry, not the first id.\n const previous = new Map<ZodType, unknown>();\n const registerId = (schema: ZodType, id: string): void => {\n if (!previous.has(schema)) {\n previous.set(schema, z.globalRegistry.get(schema));\n }\n z.globalRegistry.add(schema, { ...z.globalRegistry.get(schema), id });\n };\n registerId(bodyNodeSchema, 'bodyNode');\n for (const extra of options.extraDefs ?? []) {\n registerId(extra.schema, extra.id);\n }\n for (const [type, schema] of members) {\n registerId(schema, type);\n }\n try {\n return {\n ...z.toJSONSchema(compositionSchema, {\n target: 'draft-2020-12',\n metadata: z.globalRegistry,\n reused: options.reused ?? 'ref',\n cycles: 'ref',\n unrepresentable: 'any',\n }),\n ...(options.$id ? { $id: options.$id } : {}),\n title: options.title ?? 'View',\n description:\n options.description ??\n 'A compact view that may include registered primitives.',\n };\n } finally {\n for (const [schema, entry] of previous) {\n if (entry === undefined) {\n z.globalRegistry.remove(schema);\n } else {\n z.globalRegistry.add(schema, entry as never);\n }\n }\n }\n};\n"]}
@@ -0,0 +1,12 @@
1
+ import type { core } from 'zod';
2
+ import type { ValidationError } from '../composition/validation_error.js';
3
+ import type { AnyPrimitiveDefinition } from '../define/primitive_module.js';
4
+ /** A node an issue path can start from, and its path. */
5
+ export type IssueRoot = readonly [node: unknown, path: string];
6
+ /**
7
+ * Builds the formatter that converts Zod issues with {@link formatZodIssue},
8
+ * each error naming the innermost node its path lands in when that node's type
9
+ * is known, and an unknown key on a node appending {@link declaredFieldsNote}.
10
+ */
11
+ export declare const createNodeIssueFormatter: (definitions: readonly AnyPrimitiveDefinition[]) => ((roots: readonly IssueRoot[], issues: ReadonlyArray<core.$ZodIssue>, basePath?: string) => ValidationError[]);
12
+ //# sourceMappingURL=node_issues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node_issues.d.ts","sourceRoot":"","sources":["../../src/validate/node_issues.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAOhC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAOzE,yDAAyD;AACzD,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AA8B/D;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GACnC,aAAa,SAAS,sBAAsB,EAAE,KAC7C,CAAC,CACF,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,EACrC,QAAQ,CAAC,EAAE,MAAM,KACd,eAAe,EAAE,CAiCrB,CAAC"}
@@ -0,0 +1,61 @@
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 { childNodePath, createChildNodeWalker, } from '../composition/body_node_base.js';
8
+ import { declaredFieldsNote, formatPath, formatZodIssue, } from '../define/zod_format.js';
9
+ /**
10
+ * The raw `type` of each node `walk` reaches from `roots`, keyed by its path.
11
+ * The input has failed a schema, so a node whose children cannot be walked adds none.
12
+ */
13
+ const nodeTypesByPath = (roots, walk) => {
14
+ const types = new Map();
15
+ const visit = (node, path) => {
16
+ if (typeof node !== 'object' || node === null) {
17
+ return;
18
+ }
19
+ types.set(path, node.type);
20
+ let children;
21
+ try {
22
+ children = walk(node);
23
+ }
24
+ catch {
25
+ return;
26
+ }
27
+ children.forEach(({ node: child, path: field }) => {
28
+ visit(child, childNodePath(path, field));
29
+ });
30
+ };
31
+ roots.forEach(([node, path]) => visit(node, path));
32
+ return types;
33
+ };
34
+ /**
35
+ * Builds the formatter that converts Zod issues with {@link formatZodIssue},
36
+ * each error naming the innermost node its path lands in when that node's type
37
+ * is known, and an unknown key on a node appending {@link declaredFieldsNote}.
38
+ */
39
+ export const createNodeIssueFormatter = (definitions) => {
40
+ const walk = createChildNodeWalker(definitions);
41
+ const fieldNotes = new Map(definitions.map(({ type, schema }) => [type, declaredFieldsNote(schema)]));
42
+ const knownType = (type) => typeof type === 'string' && fieldNotes.has(type) ? type : undefined;
43
+ return (roots, issues, basePath = '') => {
44
+ const nodes = nodeTypesByPath(roots, walk);
45
+ const nodeTypeAt = (segments) => segments
46
+ .reduce((paths, segment) => [...paths, formatPath([segment], paths.at(-1))], [basePath])
47
+ .reduce((found, path) => nodes.has(path) ? knownType(nodes.get(path)) : found, undefined);
48
+ return issues.map((issue) => {
49
+ const error = formatZodIssue(issue, basePath);
50
+ const nodeType = nodeTypeAt(issue.path);
51
+ if (nodeType === undefined) {
52
+ return error;
53
+ }
54
+ const message = issue.code === 'unrecognized_keys' && nodes.get(error.path) === nodeType
55
+ ? `${error.message}; ${fieldNotes.get(nodeType)}`
56
+ : error.message;
57
+ return { ...error, message, nodeType };
58
+ });
59
+ };
60
+ };
61
+ //# sourceMappingURL=node_issues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node_issues.js","sourceRoot":"","sources":["../../src/validate/node_issues.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EACL,aAAa,EAEb,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EACL,kBAAkB,EAClB,UAAU,EACV,cAAc,GACf,MAAM,sBAAsB,CAAC;AAK9B;;;GAGG;AACH,MAAM,eAAe,GAAG,CACtB,KAA2B,EAC3B,IAAqB,EACC,EAAE;IACxB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAC;IACzC,MAAM,KAAK,GAAG,CAAC,IAAa,EAAE,IAAY,EAAQ,EAAE;QAClD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAC9C,OAAO;QACT,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,IAAI,EAAG,IAA2B,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,QAAqC,CAAC;QAC1C,IAAI,CAAC;YACH,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;QACT,CAAC;QACD,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;YAChD,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACnD,OAAO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,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC9C,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACxC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,OAAO,KAAK,CAAC;YACf,CAAC;YACD,MAAM,OAAO,GACX,KAAK,CAAC,IAAI,KAAK,mBAAmB,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,QAAQ;gBACtE,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,KAAK,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;gBACjD,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;YACpB,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,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 type { core } from 'zod';\n\nimport {\n childNodePath,\n type ChildNodeWalker,\n createChildNodeWalker,\n} from '../composition/body_node_base';\nimport type { ValidationError } from '../composition/validation_error';\nimport type { AnyPrimitiveDefinition } from '../define/primitive_module';\nimport {\n declaredFieldsNote,\n formatPath,\n formatZodIssue,\n} from '../define/zod_format';\n\n/** A node an issue path can start from, and its path. */\nexport type IssueRoot = readonly [node: unknown, path: string];\n\n/**\n * The raw `type` of each node `walk` reaches from `roots`, keyed by its path.\n * The input has failed a schema, so a node whose children cannot be walked adds none.\n */\nconst nodeTypesByPath = (\n roots: readonly IssueRoot[],\n walk: ChildNodeWalker\n): Map<string, unknown> => {\n const types = new Map<string, unknown>();\n const visit = (node: unknown, path: string): void => {\n if (typeof node !== 'object' || node === null) {\n return;\n }\n types.set(path, (node as { type?: unknown }).type);\n let children: ReturnType<ChildNodeWalker>;\n try {\n children = walk(node);\n } catch {\n return;\n }\n children.forEach(({ node: child, path: field }) => {\n visit(child, childNodePath(path, field));\n });\n };\n roots.forEach(([node, path]) => visit(node, path));\n return types;\n};\n\n/**\n * Builds the formatter that converts Zod issues with {@link formatZodIssue},\n * each error naming the innermost node its path lands in when that node's type\n * is known, and an unknown key on a node appending {@link declaredFieldsNote}.\n */\nexport const createNodeIssueFormatter = (\n definitions: readonly AnyPrimitiveDefinition[]\n): ((\n roots: readonly IssueRoot[],\n issues: ReadonlyArray<core.$ZodIssue>,\n basePath?: string\n) => ValidationError[]) => {\n const walk = createChildNodeWalker(definitions);\n const fieldNotes = new Map(\n definitions.map(({ type, schema }) => [type, declaredFieldsNote(schema)])\n );\n const knownType = (type: unknown): string | undefined =>\n typeof type === 'string' && fieldNotes.has(type) ? type : undefined;\n return (roots, issues, basePath = '') => {\n const nodes = nodeTypesByPath(roots, walk);\n const nodeTypeAt = (segments: readonly PropertyKey[]) =>\n segments\n .reduce(\n (paths, segment) => [...paths, formatPath([segment], paths.at(-1))],\n [basePath]\n )\n .reduce<string | undefined>(\n (found, path) =>\n nodes.has(path) ? knownType(nodes.get(path)) : found,\n undefined\n );\n return issues.map((issue) => {\n const error = formatZodIssue(issue, basePath);\n const nodeType = nodeTypeAt(issue.path);\n if (nodeType === undefined) {\n return error;\n }\n const message =\n issue.code === 'unrecognized_keys' && nodes.get(error.path) === nodeType\n ? `${error.message}; ${fieldNotes.get(nodeType)}`\n : error.message;\n return { ...error, message, nodeType };\n });\n };\n};\n"]}