@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,135 @@
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.getCompositionSchemaForDefinitions = exports.buildCompositionSchemaFromDefinitions = exports.buildBodyNodeSchemaFromDefinitions = exports.resolveVocabulary = exports.buildCompositionSchema = exports.metaSchema = void 0;
10
+ const zod_1 = require("zod");
11
+ const error_1 = require("../composition/error");
12
+ const value_schemas_1 = require("./value_schemas");
13
+ /** `Composition.meta`: provenance and freshness, every field optional. */
14
+ exports.metaSchema = zod_1.z.object({
15
+ source: zod_1.z.string().optional(),
16
+ generatedAt: zod_1.z.string().optional(),
17
+ ariaLabel: zod_1.z.string().optional(),
18
+ provenance: zod_1.z
19
+ .object({
20
+ source: zod_1.z.string().optional(),
21
+ query: zod_1.z.string().optional(),
22
+ provider: zod_1.z.string().optional(),
23
+ })
24
+ .optional(),
25
+ freshness: zod_1.z
26
+ .object({
27
+ asOf: zod_1.z.string().optional(),
28
+ stale: zod_1.z.boolean().optional(),
29
+ ttlSeconds: zod_1.z.number().optional(),
30
+ })
31
+ .optional(),
32
+ partialFailure: zod_1.z
33
+ .object({
34
+ degraded: zod_1.z.boolean().optional(),
35
+ reason: zod_1.z.string().optional(),
36
+ })
37
+ .optional(),
38
+ });
39
+ /**
40
+ * Wraps a body-node union in the `Composition` envelope.
41
+ *
42
+ * `.strict()`, so an unknown root key is an error rather than silently carried:
43
+ * the format crosses vendor boundaries, and a typo'd field that validates is
44
+ * worse than one that fails. Most callers want
45
+ * {@link getCompositionSchemaForDefinitions} instead, which memoizes.
46
+ */
47
+ const buildCompositionSchema = ({ bodyNodeSchema, }) => zod_1.z
48
+ .object({
49
+ type: zod_1.z.literal('view', { error: 'type must be "view"' }),
50
+ version: zod_1.z.literal(1).optional(),
51
+ title: zod_1.z.string().optional(),
52
+ subtitle: zod_1.z.string().optional(),
53
+ theme: value_schemas_1.renderThemeSchema.optional(),
54
+ body: zod_1.z
55
+ .array(bodyNodeSchema)
56
+ .min(1, { error: 'must contain at least one node' }),
57
+ meta: exports.metaSchema.optional(),
58
+ })
59
+ .strict();
60
+ exports.buildCompositionSchema = buildCompositionSchema;
61
+ /**
62
+ * Builds a body-node union whose containers reference *this* union.
63
+ *
64
+ * The `z.lazy` closing the recursion is created here and discarded with the
65
+ * vocabulary: it memoizes its getter after the first resolution, so one shared
66
+ * across vocabularies would freeze on whichever union parsed first.
67
+ */
68
+ const resolveVocabulary = (definitions) => {
69
+ if (definitions.length === 0) {
70
+ throw new error_1.IsomerError('EMPTY_VOCABULARY', 'resolveVocabulary: at least one primitive is required');
71
+ }
72
+ // Resolved once the union exists; nothing parses before this function returns.
73
+ const pending = {};
74
+ const resolveUnion = () => {
75
+ if (!pending.union) {
76
+ throw new error_1.IsomerError('VOCABULARY_UNRESOLVED', 'resolveVocabulary: body-node union read before its vocabulary resolved');
77
+ }
78
+ return pending.union;
79
+ };
80
+ const members = new Map();
81
+ const memberSchemas = definitions.map((definition) => {
82
+ const schema = definition.schemaFor
83
+ ? // One `z.lazy` per container: the JSON Schema projection gives a shared
84
+ // wrapper its own anonymous `$def` instead of `$ref: #/$defs/bodyNode`.
85
+ definition.schemaFor(zod_1.z.lazy(resolveUnion))
86
+ : definition.schema;
87
+ members.set(definition.type, schema);
88
+ return schema;
89
+ });
90
+ pending.union = zod_1.z.discriminatedUnion('type', memberSchemas);
91
+ return { bodyNodeSchema: pending.union, members };
92
+ };
93
+ exports.resolveVocabulary = resolveVocabulary;
94
+ /**
95
+ * {@link resolveVocabulary}, discarding the member instances.
96
+ *
97
+ * Only for a caller with no id registry to name; anything projecting to JSON
98
+ * Schema needs the members and should use {@link resolveVocabulary}.
99
+ */
100
+ const buildBodyNodeSchemaFromDefinitions = (definitions) => (0, exports.resolveVocabulary)(definitions).bodyNodeSchema;
101
+ exports.buildBodyNodeSchemaFromDefinitions = buildBodyNodeSchemaFromDefinitions;
102
+ /**
103
+ * A fresh `Composition` schema over `definitions`.
104
+ *
105
+ * Builds a new union per call. Prefer
106
+ * {@link getCompositionSchemaForDefinitions} unless a fresh instance is
107
+ * required.
108
+ */
109
+ const buildCompositionSchemaFromDefinitions = (definitions) => (0, exports.buildCompositionSchema)({
110
+ bodyNodeSchema: (0, exports.buildBodyNodeSchemaFromDefinitions)(definitions),
111
+ });
112
+ exports.buildCompositionSchemaFromDefinitions = buildCompositionSchemaFromDefinitions;
113
+ const compositionSchemaCache = new WeakMap();
114
+ const cachedFor = (definitions) => {
115
+ const cached = compositionSchemaCache.get(definitions);
116
+ if (cached) {
117
+ return cached;
118
+ }
119
+ const vocabulary = (0, exports.resolveVocabulary)(definitions);
120
+ const entry = {
121
+ vocabulary,
122
+ schema: (0, exports.buildCompositionSchema)({
123
+ bodyNodeSchema: vocabulary.bodyNodeSchema,
124
+ }),
125
+ };
126
+ compositionSchemaCache.set(definitions, entry);
127
+ return entry;
128
+ };
129
+ /**
130
+ * {@link buildCompositionSchemaFromDefinitions}, memoized per definition array.
131
+ * Prefer this whenever the caller does not need a fresh schema instance.
132
+ */
133
+ const getCompositionSchemaForDefinitions = (definitions) => cachedFor(definitions).schema;
134
+ exports.getCompositionSchemaForDefinitions = getCompositionSchemaForDefinitions;
135
+ //# 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,6BAAsD;AAEtD,gDAAmD;AAGnD,mDAAoD;AAEpD,0EAA0E;AAC7D,QAAA,UAAU,GAAG,OAAC,CAAC,MAAM,CAAC;IACjC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,UAAU,EAAE,OAAC;SACV,MAAM,CAAC;QACN,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC7B,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC5B,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAChC,CAAC;SACD,QAAQ,EAAE;IACb,SAAS,EAAE,OAAC;SACT,MAAM,CAAC;QACN,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC3B,KAAK,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QAC7B,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAClC,CAAC;SACD,QAAQ,EAAE;IACb,cAAc,EAAE,OAAC;SACd,MAAM,CAAC;QACN,QAAQ,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QAChC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAC9B,CAAC;SACD,QAAQ,EAAE;CACd,CAAC,CAAC;AAQH;;;;;;;GAOG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U;QACV,MAAM,EAAE,IAAA,8BAAsB,EAAC;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;AACI,MAAM,kCAAkC,GAAG,CAChD,WAA8C,EACnC,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC;AAFjC,QAAA,kCAAkC,sCAED","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,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.structuredValueSchema = exports.renderThemeSchema = exports.namedColorSchema = exports.displayValueSchema = exports.warningsForSurface = exports.createCompositionValidator = exports.createCompositionParser = exports.CompositionValidationError = exports.compositionToRender = exports.sanitizeParsedNavigationHref = exports.sanitizeParsedAssetUrl = exports.sanitizeNavigationHref = exports.sanitizeAssetUrl = exports.navigationHref = exports.assetUrl = exports.NAVIGATION_HREF_RULE = exports.NAVIGATION_HREF_MESSAGE = exports.BLOCKED_HREF = exports.ASSET_URL_RULE = exports.ASSET_URL_MESSAGE = exports.createNodeIssueFormatter = exports.buildCompositionJsonSchema = exports.isInputRefusal = exports.checkInputBudget = exports.MAX_INPUT_VALUES = exports.MAX_INPUT_DEPTH = exports.MAX_INPUT_CHARACTERS = exports.metaSchema = exports.getCompositionSchemaForDefinitions = exports.buildCompositionSchemaFromDefinitions = exports.buildCompositionSchema = exports.buildBodyNodeSchemaFromDefinitions = exports.buildAuthoringJsonSchema = exports.authoringSchemaSubset = exports.authoringBodySchema = void 0;
10
+ var authoring_schema_1 = require("./authoring_schema");
11
+ Object.defineProperty(exports, "authoringBodySchema", { enumerable: true, get: function () { return authoring_schema_1.authoringBodySchema; } });
12
+ Object.defineProperty(exports, "authoringSchemaSubset", { enumerable: true, get: function () { return authoring_schema_1.authoringSchemaSubset; } });
13
+ Object.defineProperty(exports, "buildAuthoringJsonSchema", { enumerable: true, get: function () { return authoring_schema_1.buildAuthoringJsonSchema; } });
14
+ var composition_schema_1 = require("./composition_schema");
15
+ Object.defineProperty(exports, "buildBodyNodeSchemaFromDefinitions", { enumerable: true, get: function () { return composition_schema_1.buildBodyNodeSchemaFromDefinitions; } });
16
+ Object.defineProperty(exports, "buildCompositionSchema", { enumerable: true, get: function () { return composition_schema_1.buildCompositionSchema; } });
17
+ Object.defineProperty(exports, "buildCompositionSchemaFromDefinitions", { enumerable: true, get: function () { return composition_schema_1.buildCompositionSchemaFromDefinitions; } });
18
+ Object.defineProperty(exports, "getCompositionSchemaForDefinitions", { enumerable: true, get: function () { return composition_schema_1.getCompositionSchemaForDefinitions; } });
19
+ Object.defineProperty(exports, "metaSchema", { enumerable: true, get: function () { return composition_schema_1.metaSchema; } });
20
+ var input_budget_1 = require("./input_budget");
21
+ Object.defineProperty(exports, "MAX_INPUT_CHARACTERS", { enumerable: true, get: function () { return input_budget_1.MAX_INPUT_CHARACTERS; } });
22
+ Object.defineProperty(exports, "MAX_INPUT_DEPTH", { enumerable: true, get: function () { return input_budget_1.MAX_INPUT_DEPTH; } });
23
+ Object.defineProperty(exports, "MAX_INPUT_VALUES", { enumerable: true, get: function () { return input_budget_1.MAX_INPUT_VALUES; } });
24
+ Object.defineProperty(exports, "checkInputBudget", { enumerable: true, get: function () { return input_budget_1.checkInputBudget; } });
25
+ Object.defineProperty(exports, "isInputRefusal", { enumerable: true, get: function () { return input_budget_1.isInputRefusal; } });
26
+ var json_schema_1 = require("./json_schema");
27
+ Object.defineProperty(exports, "buildCompositionJsonSchema", { enumerable: true, get: function () { return json_schema_1.buildCompositionJsonSchema; } });
28
+ var node_issues_1 = require("./node_issues");
29
+ Object.defineProperty(exports, "createNodeIssueFormatter", { enumerable: true, get: function () { return node_issues_1.createNodeIssueFormatter; } });
30
+ var url_1 = require("./url");
31
+ Object.defineProperty(exports, "ASSET_URL_MESSAGE", { enumerable: true, get: function () { return url_1.ASSET_URL_MESSAGE; } });
32
+ Object.defineProperty(exports, "ASSET_URL_RULE", { enumerable: true, get: function () { return url_1.ASSET_URL_RULE; } });
33
+ Object.defineProperty(exports, "BLOCKED_HREF", { enumerable: true, get: function () { return url_1.BLOCKED_HREF; } });
34
+ Object.defineProperty(exports, "NAVIGATION_HREF_MESSAGE", { enumerable: true, get: function () { return url_1.NAVIGATION_HREF_MESSAGE; } });
35
+ Object.defineProperty(exports, "NAVIGATION_HREF_RULE", { enumerable: true, get: function () { return url_1.NAVIGATION_HREF_RULE; } });
36
+ Object.defineProperty(exports, "assetUrl", { enumerable: true, get: function () { return url_1.assetUrl; } });
37
+ Object.defineProperty(exports, "navigationHref", { enumerable: true, get: function () { return url_1.navigationHref; } });
38
+ Object.defineProperty(exports, "sanitizeAssetUrl", { enumerable: true, get: function () { return url_1.sanitizeAssetUrl; } });
39
+ Object.defineProperty(exports, "sanitizeNavigationHref", { enumerable: true, get: function () { return url_1.sanitizeNavigationHref; } });
40
+ Object.defineProperty(exports, "sanitizeParsedAssetUrl", { enumerable: true, get: function () { return url_1.sanitizeParsedAssetUrl; } });
41
+ Object.defineProperty(exports, "sanitizeParsedNavigationHref", { enumerable: true, get: function () { return url_1.sanitizeParsedNavigationHref; } });
42
+ var validation_1 = require("./validation");
43
+ Object.defineProperty(exports, "compositionToRender", { enumerable: true, get: function () { return validation_1.compositionToRender; } });
44
+ Object.defineProperty(exports, "CompositionValidationError", { enumerable: true, get: function () { return validation_1.CompositionValidationError; } });
45
+ Object.defineProperty(exports, "createCompositionParser", { enumerable: true, get: function () { return validation_1.createCompositionParser; } });
46
+ Object.defineProperty(exports, "createCompositionValidator", { enumerable: true, get: function () { return validation_1.createCompositionValidator; } });
47
+ Object.defineProperty(exports, "warningsForSurface", { enumerable: true, get: function () { return validation_1.warningsForSurface; } });
48
+ var value_schemas_1 = require("./value_schemas");
49
+ Object.defineProperty(exports, "displayValueSchema", { enumerable: true, get: function () { return value_schemas_1.displayValueSchema; } });
50
+ Object.defineProperty(exports, "namedColorSchema", { enumerable: true, get: function () { return value_schemas_1.namedColorSchema; } });
51
+ Object.defineProperty(exports, "renderThemeSchema", { enumerable: true, get: function () { return value_schemas_1.renderThemeSchema; } });
52
+ Object.defineProperty(exports, "structuredValueSchema", { enumerable: true, get: function () { return value_schemas_1.structuredValueSchema; } });
53
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validate/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uDAK4B;AAH1B,uHAAA,mBAAmB,OAAA;AACnB,yHAAA,qBAAqB,OAAA;AACrB,4HAAA,wBAAwB,OAAA;AAE1B,2DAO8B;AAL5B,wIAAA,kCAAkC,OAAA;AAClC,4HAAA,sBAAsB,OAAA;AACtB,2IAAA,qCAAqC,OAAA;AACrC,wIAAA,kCAAkC,OAAA;AAClC,gHAAA,UAAU,OAAA;AAEZ,+CAQwB;AALtB,oHAAA,oBAAoB,OAAA;AACpB,+GAAA,eAAe,OAAA;AACf,gHAAA,gBAAgB,OAAA;AAChB,gHAAA,gBAAgB,OAAA;AAChB,8GAAA,cAAc,OAAA;AAEhB,6CAGuB;AADrB,yHAAA,0BAA0B,OAAA;AAE5B,6CAAyE;AAAhD,uHAAA,wBAAwB,OAAA;AACjD,6BAae;AAXb,wGAAA,iBAAiB,OAAA;AACjB,qGAAA,cAAc,OAAA;AACd,mGAAA,YAAY,OAAA;AACZ,8GAAA,uBAAuB,OAAA;AACvB,2GAAA,oBAAoB,OAAA;AACpB,+FAAA,QAAQ,OAAA;AACR,qGAAA,cAAc,OAAA;AACd,uGAAA,gBAAgB,OAAA;AAChB,6GAAA,sBAAsB,OAAA;AACtB,6GAAA,sBAAsB,OAAA;AACtB,mHAAA,4BAA4B,OAAA;AAE9B,2CAasB;AALpB,iHAAA,mBAAmB,OAAA;AACnB,wHAAA,0BAA0B,OAAA;AAC1B,qHAAA,uBAAuB,OAAA;AACvB,wHAAA,0BAA0B,OAAA;AAC1B,gHAAA,kBAAkB,OAAA;AAEpB,iDAKyB;AAJvB,mHAAA,kBAAkB,OAAA;AAClB,iHAAA,gBAAgB,OAAA;AAChB,kHAAA,iBAAiB,OAAA;AACjB,sHAAA,qBAAqB,OAAA","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 authoringBodySchema,\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,156 @@
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.checkInputBudget = exports.isInputRefusal = exports.MAX_INPUT_CHARACTERS = exports.MAX_INPUT_VALUES = exports.MAX_INPUT_DEPTH = void 0;
10
+ const error_1 = require("../composition/error");
11
+ /** Objects and arrays nested in one another, the input itself included. */
12
+ exports.MAX_INPUT_DEPTH = 64;
13
+ /** Every object, array, and leaf counts once. */
14
+ exports.MAX_INPUT_VALUES = 20_000;
15
+ /** Every object key and string, and each other leaf as `String` prints it. */
16
+ exports.MAX_INPUT_CHARACTERS = 1_000_000;
17
+ /** The codes {@link checkInputBudget} refuses with. */
18
+ const INPUT_REFUSAL_CODES = new Set([
19
+ error_1.ISOMER_ERROR_CODES.INPUT_NOT_PLAIN_DATA,
20
+ error_1.ISOMER_ERROR_CODES.INPUT_OVER_BUDGET,
21
+ ]);
22
+ /** Whether `error` is a refusal before parsing, which no validation mode collects. */
23
+ const isInputRefusal = ({ code, }) => INPUT_REFUSAL_CODES.has(code);
24
+ exports.isInputRefusal = isInputRefusal;
25
+ class Refusal extends Error {
26
+ error;
27
+ constructor(error) {
28
+ super(error.message);
29
+ this.error = error;
30
+ }
31
+ }
32
+ const overBudget = (message) => new Refusal({
33
+ path: '',
34
+ message,
35
+ code: error_1.ISOMER_ERROR_CODES.INPUT_OVER_BUDGET,
36
+ });
37
+ const notPlainData = (what) => new Refusal({
38
+ path: '',
39
+ message: `input holds ${what}, which is not plain data`,
40
+ code: error_1.ISOMER_ERROR_CODES.INPUT_NOT_PLAIN_DATA,
41
+ });
42
+ const leafLength = (value) => typeof value === 'string' ? value.length : String(value).length;
43
+ /** Reads `key` once, through its descriptor. */
44
+ const plainProperty = (source, key) => {
45
+ const descriptor = Reflect.getOwnPropertyDescriptor(source, key);
46
+ if (descriptor === undefined) {
47
+ throw notPlainData('an array hole');
48
+ }
49
+ if (!('value' in descriptor)) {
50
+ throw notPlainData('an accessor property');
51
+ }
52
+ if (!descriptor.enumerable) {
53
+ throw notPlainData('a non-enumerable property');
54
+ }
55
+ return descriptor.value;
56
+ };
57
+ /**
58
+ * A plain copy of `value` within `budget`, or why there is none: it is over `budget` or is not plain data.
59
+ *
60
+ * 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.
61
+ * 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.
62
+ * 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.
63
+ */
64
+ const checkInputBudget = (value, budget = {}) => {
65
+ const { depth: maxDepth = exports.MAX_INPUT_DEPTH, values: maxValues = exports.MAX_INPUT_VALUES, characters: maxCharacters = exports.MAX_INPUT_CHARACTERS, } = budget;
66
+ const tooManyValues = `input holds more than ${maxValues} values`;
67
+ const ancestors = new Set();
68
+ const stack = [];
69
+ let values = 0;
70
+ let characters = 0;
71
+ const countCharacters = (count) => {
72
+ characters += count;
73
+ if (characters > maxCharacters) {
74
+ throw overBudget(`input holds more than ${maxCharacters} characters`);
75
+ }
76
+ };
77
+ const enqueue = (child, depth, keyLength) => {
78
+ values += 1;
79
+ if (values > maxValues) {
80
+ throw overBudget(tooManyValues);
81
+ }
82
+ if (typeof child === 'function') {
83
+ throw notPlainData('a function');
84
+ }
85
+ if (typeof child !== 'object' || child === null) {
86
+ countCharacters(keyLength + leafLength(child));
87
+ return child;
88
+ }
89
+ let copy = [];
90
+ if (!Array.isArray(child)) {
91
+ const prototype = Reflect.getPrototypeOf(child);
92
+ if (prototype !== Object.prototype && prototype !== null) {
93
+ throw notPlainData('an object that is not a plain object or array');
94
+ }
95
+ copy = Object.create(prototype);
96
+ }
97
+ countCharacters(keyLength);
98
+ stack.push({ source: child, copy, depth });
99
+ return copy;
100
+ };
101
+ const copyChildren = ({ source, copy, depth }) => {
102
+ const keys = Array.isArray(copy) ? undefined : Reflect.ownKeys(source);
103
+ const count = keys?.length ?? source.length;
104
+ if (values + count > maxValues) {
105
+ throw overBudget(tooManyValues);
106
+ }
107
+ for (let index = 0; index < count; index += 1) {
108
+ const key = keys === undefined ? index : keys[index];
109
+ if (typeof key === 'symbol') {
110
+ throw notPlainData('a symbol key');
111
+ }
112
+ const child = plainProperty(source, key);
113
+ if (Array.isArray(copy)) {
114
+ copy.push(enqueue(child, depth, 0));
115
+ }
116
+ else {
117
+ Object.defineProperty(copy, key, {
118
+ value: enqueue(child, depth, String(key).length),
119
+ writable: true,
120
+ enumerable: true,
121
+ configurable: true,
122
+ });
123
+ }
124
+ }
125
+ };
126
+ try {
127
+ const root = enqueue(value, 1, 0);
128
+ while (stack.length > 0) {
129
+ const entry = stack.pop();
130
+ const { source, depth, leave } = entry;
131
+ if (leave) {
132
+ ancestors.delete(source);
133
+ }
134
+ else if (ancestors.has(source)) {
135
+ throw overBudget('input contains itself');
136
+ }
137
+ else if (depth > maxDepth) {
138
+ throw overBudget(`input nests deeper than ${maxDepth} levels`);
139
+ }
140
+ else {
141
+ ancestors.add(source);
142
+ stack.push({ ...entry, leave: true });
143
+ copyChildren({ ...entry, depth: depth + 1 });
144
+ }
145
+ }
146
+ return { valid: true, value: root };
147
+ }
148
+ catch (error) {
149
+ if (error instanceof Refusal) {
150
+ return { valid: false, error: error.error };
151
+ }
152
+ throw error;
153
+ }
154
+ };
155
+ exports.checkInputBudget = checkInputBudget;
156
+ //# 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,gDAA0D;AAG1D,2EAA2E;AAC9D,QAAA,eAAe,GAAG,EAAE,CAAC;AAElC,iDAAiD;AACpC,QAAA,gBAAgB,GAAG,MAAM,CAAC;AAEvC,8EAA8E;AACjE,QAAA,oBAAoB,GAAG,SAAS,CAAC;AAY9C,uDAAuD;AACvD,MAAM,mBAAmB,GAAoC,IAAI,GAAG,CAAC;IACnE,0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AAU,CAAC,2BAA2B,QAAQ,SAAS,CAAC,CAAC;YACjE,CAAC;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;AAhGW,QAAA,gBAAgB,oBAgG3B","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,72 @@
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.buildCompositionJsonSchema = void 0;
10
+ const zod_1 = require("zod");
11
+ const composition_schema_1 = require("./composition_schema");
12
+ /**
13
+ * Projects the composition schema to JSON Schema draft 2020-12, for hosts
14
+ * that validate outside TypeScript.
15
+ *
16
+ * `$defs` are named per primitive type, plus `bodyNode` for the union.
17
+ * Agent-facing prompt text uses `buildAuthoringJsonSchema` instead.
18
+ */
19
+ const buildCompositionJsonSchema = (definitions, options = {}) => {
20
+ // Members, not `definition.schema`: a container's member is built by
21
+ // `schemaFor`, and the registry is keyed on identity.
22
+ const composed = (0, composition_schema_1.resolveVocabulary)(definitions);
23
+ const { bodyNodeSchema, members } = composed;
24
+ const compositionSchema = (0, composition_schema_1.buildCompositionSchema)({ bodyNodeSchema });
25
+ // `metadata` replaces `z.toJSONSchema`'s default registry rather than
26
+ // extending it, and `z.globalRegistry` is where every `.describe()` lives,
27
+ // so ids are added to the global registry for the duration of this call
28
+ // and the prior entries restored in `finally`. Only a schema's first
29
+ // registration is recorded: a schema named twice (an `extraDefs` entry that
30
+ // is also a member) must restore its original entry, not the first id.
31
+ const previous = new Map();
32
+ const registerId = (schema, id) => {
33
+ if (!previous.has(schema)) {
34
+ previous.set(schema, zod_1.z.globalRegistry.get(schema));
35
+ }
36
+ zod_1.z.globalRegistry.add(schema, { ...zod_1.z.globalRegistry.get(schema), id });
37
+ };
38
+ registerId(bodyNodeSchema, 'bodyNode');
39
+ for (const extra of options.extraDefs ?? []) {
40
+ registerId(extra.schema, extra.id);
41
+ }
42
+ for (const [type, schema] of members) {
43
+ registerId(schema, type);
44
+ }
45
+ try {
46
+ return {
47
+ ...zod_1.z.toJSONSchema(compositionSchema, {
48
+ target: 'draft-2020-12',
49
+ metadata: zod_1.z.globalRegistry,
50
+ reused: options.reused ?? 'ref',
51
+ cycles: 'ref',
52
+ unrepresentable: 'any',
53
+ }),
54
+ ...(options.$id ? { $id: options.$id } : {}),
55
+ title: options.title ?? 'View',
56
+ description: options.description ??
57
+ 'A compact view that may include registered primitives.',
58
+ };
59
+ }
60
+ finally {
61
+ for (const [schema, entry] of previous) {
62
+ if (entry === undefined) {
63
+ zod_1.z.globalRegistry.remove(schema);
64
+ }
65
+ else {
66
+ zod_1.z.globalRegistry.add(schema, entry);
67
+ }
68
+ }
69
+ }
70
+ };
71
+ exports.buildCompositionJsonSchema = buildCompositionJsonSchema;
72
+ //# 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,6BAAsC;AAItC,6DAG8B;AAqB9B;;;;;;GAMG;AACI,MAAM,0BAA0B,GAAG,CACxC,WAA8C,EAC9C,UAAwC,EAAE,EAC9B,EAAE;IACd,qEAAqE;IACrE,sDAAsD;IACtD,MAAM,QAAQ,GAAG,IAAA,sCAAiB,EAAC,WAAW,CAAC,CAAC;IAChD,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IAC7C,MAAM,iBAAiB,GAAG,IAAA,2CAAsB,EAAC,EAAE,cA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AAO,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,OAAC,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,OAAC,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,KAAc,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAtDW,QAAA,0BAA0B,8BAsDrC","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,65 @@
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.createNodeIssueFormatter = void 0;
10
+ const body_node_base_1 = require("../composition/body_node_base");
11
+ const zod_format_1 = require("../define/zod_format");
12
+ /**
13
+ * The raw `type` of each node `walk` reaches from `roots`, keyed by its path.
14
+ * The input has failed a schema, so a node whose children cannot be walked adds none.
15
+ */
16
+ const nodeTypesByPath = (roots, walk) => {
17
+ const types = new Map();
18
+ const visit = (node, path) => {
19
+ if (typeof node !== 'object' || node === null) {
20
+ return;
21
+ }
22
+ types.set(path, node.type);
23
+ let children;
24
+ try {
25
+ children = walk(node);
26
+ }
27
+ catch {
28
+ return;
29
+ }
30
+ children.forEach(({ node: child, path: field }) => {
31
+ visit(child, (0, body_node_base_1.childNodePath)(path, field));
32
+ });
33
+ };
34
+ roots.forEach(([node, path]) => visit(node, path));
35
+ return types;
36
+ };
37
+ /**
38
+ * Builds the formatter that converts Zod issues with {@link formatZodIssue},
39
+ * each error naming the innermost node its path lands in when that node's type
40
+ * is known, and an unknown key on a node appending {@link declaredFieldsNote}.
41
+ */
42
+ const createNodeIssueFormatter = (definitions) => {
43
+ const walk = (0, body_node_base_1.createChildNodeWalker)(definitions);
44
+ const fieldNotes = new Map(definitions.map(({ type, schema }) => [type, (0, zod_format_1.declaredFieldsNote)(schema)]));
45
+ const knownType = (type) => typeof type === 'string' && fieldNotes.has(type) ? type : undefined;
46
+ return (roots, issues, basePath = '') => {
47
+ const nodes = nodeTypesByPath(roots, walk);
48
+ const nodeTypeAt = (segments) => segments
49
+ .reduce((paths, segment) => [...paths, (0, zod_format_1.formatPath)([segment], paths.at(-1))], [basePath])
50
+ .reduce((found, path) => nodes.has(path) ? knownType(nodes.get(path)) : found, undefined);
51
+ return issues.map((issue) => {
52
+ const error = (0, zod_format_1.formatZodIssue)(issue, basePath);
53
+ const nodeType = nodeTypeAt(issue.path);
54
+ if (nodeType === undefined) {
55
+ return error;
56
+ }
57
+ const message = issue.code === 'unrecognized_keys' && nodes.get(error.path) === nodeType
58
+ ? `${error.message}; ${fieldNotes.get(nodeType)}`
59
+ : error.message;
60
+ return { ...error, message, nodeType };
61
+ });
62
+ };
63
+ };
64
+ exports.createNodeIssueFormatter = createNodeIssueFormatter;
65
+ //# 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,kEAIuC;AAGvC,qDAI8B;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,IAAA,8BAAa,EAAC,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;I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MAAM,KAAK,GAAG,IAAA,2BAAc,EAAC,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;AAvCW,QAAA,wBAAwB,4BAuCnC","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"]}