@scalar/blocks 0.5.4 → 0.6.2

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 (249) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +13 -29
  3. package/dist/code-example/components/AsyncApiCodeExample.vue.d.ts +19 -0
  4. package/dist/code-example/components/AsyncApiCodeExample.vue.d.ts.map +1 -0
  5. package/dist/code-example/components/AsyncApiCodeExample.vue.js +9 -0
  6. package/dist/code-example/components/AsyncApiCodeExample.vue.js.map +1 -0
  7. package/dist/code-example/components/AsyncApiCodeExample.vue_vue_type_script_setup_true_lang.js +114 -0
  8. package/dist/code-example/components/AsyncApiCodeExample.vue_vue_type_script_setup_true_lang.js.map +1 -0
  9. package/dist/code-example/components/CodeExample.vue.js +4 -4
  10. package/dist/code-example/components/CodeExample.vue.js.map +1 -1
  11. package/dist/code-example/components/CodeExample.vue_vue_type_script_setup_true_lang.js +258 -0
  12. package/dist/code-example/components/CodeExample.vue_vue_type_script_setup_true_lang.js.map +1 -0
  13. package/dist/code-example/components/ExamplePicker.vue.js +1 -1
  14. package/dist/code-example/components/ExamplePicker.vue.js.map +1 -1
  15. package/dist/code-example/components/{ExamplePicker.vue.script.js → ExamplePicker.vue_vue_type_script_setup_true_lang.js} +5 -5
  16. package/dist/code-example/components/ExamplePicker.vue_vue_type_script_setup_true_lang.js.map +1 -0
  17. package/dist/code-example/components/HttpMethod.vue.js +1 -1
  18. package/dist/code-example/components/HttpMethod.vue.js.map +1 -1
  19. package/dist/code-example/components/{HttpMethod.vue.script.js → HttpMethod.vue_vue_type_script_setup_true_lang.js} +1 -1
  20. package/dist/code-example/components/HttpMethod.vue_vue_type_script_setup_true_lang.js.map +1 -0
  21. package/dist/code-example/helpers/filter-clients-by-query.js.map +1 -1
  22. package/dist/code-example/helpers/find-client.js.map +1 -1
  23. package/dist/code-example/helpers/format-language.js.map +1 -1
  24. package/dist/code-example/helpers/generate-client-options.js.map +1 -1
  25. package/dist/code-example/helpers/generate-code-snippet.js.map +1 -1
  26. package/dist/code-example/helpers/get-asyncapi-example-context.d.ts +12 -0
  27. package/dist/code-example/helpers/get-asyncapi-example-context.d.ts.map +1 -0
  28. package/dist/code-example/helpers/get-asyncapi-example-context.js +33 -0
  29. package/dist/code-example/helpers/get-asyncapi-example-context.js.map +1 -0
  30. package/dist/code-example/helpers/get-clients.js.map +1 -1
  31. package/dist/code-example/helpers/get-custom-code-samples.js.map +1 -1
  32. package/dist/code-example/helpers/get-generated-payload-example.d.ts +4 -0
  33. package/dist/code-example/helpers/get-generated-payload-example.d.ts.map +1 -0
  34. package/dist/code-example/helpers/get-generated-payload-example.js +25 -0
  35. package/dist/code-example/helpers/get-generated-payload-example.js.map +1 -0
  36. package/dist/code-example/helpers/get-message-example-content.d.ts +10 -0
  37. package/dist/code-example/helpers/get-message-example-content.d.ts.map +1 -0
  38. package/dist/code-example/helpers/get-message-example-content.js +29 -0
  39. package/dist/code-example/helpers/get-message-example-content.js.map +1 -0
  40. package/dist/code-example/helpers/get-secrets.js.map +1 -1
  41. package/dist/code-example/helpers/get-snippet.js.map +1 -1
  42. package/dist/code-example/helpers/operation-to-har/operation-to-har.js +32 -32
  43. package/dist/code-example/helpers/operation-to-har/operation-to-har.js.map +1 -1
  44. package/dist/code-example/helpers/operation-to-har/process-body.js +41 -47
  45. package/dist/code-example/helpers/operation-to-har/process-body.js.map +1 -1
  46. package/dist/code-example/helpers/operation-to-har/process-parameters.js +51 -55
  47. package/dist/code-example/helpers/operation-to-har/process-parameters.js.map +1 -1
  48. package/dist/code-example/helpers/operation-to-har/process-security-schemes.js +30 -38
  49. package/dist/code-example/helpers/operation-to-har/process-security-schemes.js.map +1 -1
  50. package/dist/code-example/helpers/operation-to-har/process-server-url.js +5 -1
  51. package/dist/code-example/helpers/operation-to-har/process-server-url.js.map +1 -1
  52. package/dist/code-example/index.d.ts +4 -0
  53. package/dist/code-example/index.d.ts.map +1 -1
  54. package/dist/code-example/index.js +17 -14
  55. package/dist/code-example/mount-asyncapi.d.ts +14 -0
  56. package/dist/code-example/mount-asyncapi.d.ts.map +1 -0
  57. package/dist/code-example/mount-asyncapi.js +27 -0
  58. package/dist/code-example/mount-asyncapi.js.map +1 -0
  59. package/dist/code-example/mount.d.ts +4 -2
  60. package/dist/code-example/mount.d.ts.map +1 -1
  61. package/dist/code-example/mount.js +39 -37
  62. package/dist/code-example/mount.js.map +1 -1
  63. package/dist/constants.js +1 -1
  64. package/dist/constants.js.map +1 -1
  65. package/dist/schema/LinkButton.vue.js.map +1 -1
  66. package/dist/schema/RenderString.vue.js +1 -1
  67. package/dist/schema/RenderString.vue.js.map +1 -1
  68. package/dist/schema/{RenderString.vue.script.js → RenderString.vue_vue_type_script_setup_true_lang.js} +1 -1
  69. package/dist/schema/RenderString.vue_vue_type_script_setup_true_lang.js.map +1 -0
  70. package/dist/schema/Schema.vue.js +2 -2
  71. package/dist/schema/Schema.vue.js.map +1 -1
  72. package/dist/schema/{Schema.vue.script.js → Schema.vue_vue_type_script_setup_true_lang.js} +1 -1
  73. package/dist/schema/Schema.vue_vue_type_script_setup_true_lang.js.map +1 -0
  74. package/dist/schema/SchemaCollapsedPreview.vue.js +1 -1
  75. package/dist/schema/SchemaCollapsedPreview.vue.js.map +1 -1
  76. package/dist/schema/{SchemaCollapsedPreview.vue.script.js → SchemaCollapsedPreview.vue_vue_type_script_setup_true_lang.js} +1 -1
  77. package/dist/schema/SchemaCollapsedPreview.vue_vue_type_script_setup_true_lang.js.map +1 -0
  78. package/dist/schema/SchemaComposition.vue.js +2 -2
  79. package/dist/schema/SchemaComposition.vue.js.map +1 -1
  80. package/dist/schema/{SchemaComposition.vue.script.js → SchemaComposition.vue_vue_type_script_setup_true_lang.js} +5 -5
  81. package/dist/schema/SchemaComposition.vue_vue_type_script_setup_true_lang.js.map +1 -0
  82. package/dist/schema/SchemaEnumPropertyItem.vue.js +1 -1
  83. package/dist/schema/SchemaEnumPropertyItem.vue.js.map +1 -1
  84. package/dist/schema/{SchemaEnumPropertyItem.vue.script.js → SchemaEnumPropertyItem.vue_vue_type_script_setup_true_lang.js} +1 -1
  85. package/dist/schema/SchemaEnumPropertyItem.vue_vue_type_script_setup_true_lang.js.map +1 -0
  86. package/dist/schema/SchemaEnums.vue.js +2 -2
  87. package/dist/schema/SchemaEnums.vue.js.map +1 -1
  88. package/dist/schema/{SchemaEnums.vue.script.js → SchemaEnums.vue_vue_type_script_setup_true_lang.js} +1 -1
  89. package/dist/schema/SchemaEnums.vue_vue_type_script_setup_true_lang.js.map +1 -0
  90. package/dist/schema/SchemaGlyphPuck.vue.js +1 -1
  91. package/dist/schema/SchemaGlyphPuck.vue.js.map +1 -1
  92. package/dist/schema/{SchemaGlyphPuck.vue.script.js → SchemaGlyphPuck.vue_vue_type_script_setup_true_lang.js} +1 -1
  93. package/dist/schema/SchemaGlyphPuck.vue_vue_type_script_setup_true_lang.js.map +1 -0
  94. package/dist/schema/SchemaGutterToggle.vue.js +1 -1
  95. package/dist/schema/SchemaGutterToggle.vue.js.map +1 -1
  96. package/dist/schema/{SchemaGutterToggle.vue.script.js → SchemaGutterToggle.vue_vue_type_script_setup_true_lang.js} +1 -1
  97. package/dist/schema/SchemaGutterToggle.vue_vue_type_script_setup_true_lang.js.map +1 -0
  98. package/dist/schema/SchemaHeading.vue.js +2 -2
  99. package/dist/schema/SchemaHeading.vue.js.map +1 -1
  100. package/dist/schema/{SchemaHeading.vue.script.js → SchemaHeading.vue_vue_type_script_setup_true_lang.js} +1 -1
  101. package/dist/schema/SchemaHeading.vue_vue_type_script_setup_true_lang.js.map +1 -0
  102. package/dist/schema/SchemaObjectExampleCodeBlock.vue.js +1 -1
  103. package/dist/schema/SchemaObjectExampleCodeBlock.vue.js.map +1 -1
  104. package/dist/schema/{SchemaObjectExampleCodeBlock.vue.script.js → SchemaObjectExampleCodeBlock.vue_vue_type_script_setup_true_lang.js} +1 -1
  105. package/dist/schema/SchemaObjectExampleCodeBlock.vue_vue_type_script_setup_true_lang.js.map +1 -0
  106. package/dist/schema/SchemaObjectProperties.vue.js +1 -1
  107. package/dist/schema/SchemaObjectProperties.vue.js.map +1 -1
  108. package/dist/schema/{SchemaObjectProperties.vue.script.js → SchemaObjectProperties.vue_vue_type_script_setup_true_lang.js} +3 -3
  109. package/dist/schema/{SchemaObjectProperties.vue.script.js.map → SchemaObjectProperties.vue_vue_type_script_setup_true_lang.js.map} +1 -1
  110. package/dist/schema/SchemaProperty.vue.js +2 -2
  111. package/dist/schema/SchemaProperty.vue.js.map +1 -1
  112. package/dist/schema/{SchemaProperty.vue.script.js → SchemaProperty.vue_vue_type_script_setup_true_lang.js} +3 -7
  113. package/dist/schema/SchemaProperty.vue_vue_type_script_setup_true_lang.js.map +1 -0
  114. package/dist/schema/SchemaPropertyDefault.vue.js +2 -2
  115. package/dist/schema/SchemaPropertyDefault.vue.js.map +1 -1
  116. package/dist/schema/{SchemaPropertyDefault.vue.script.js → SchemaPropertyDefault.vue_vue_type_script_setup_true_lang.js} +1 -1
  117. package/dist/schema/SchemaPropertyDefault.vue_vue_type_script_setup_true_lang.js.map +1 -0
  118. package/dist/schema/SchemaPropertyDetail.vue.js +2 -2
  119. package/dist/schema/SchemaPropertyDetail.vue.js.map +1 -1
  120. package/dist/schema/{SchemaPropertyDetail.vue.script.js → SchemaPropertyDetail.vue_vue_type_script_setup_true_lang.js} +1 -1
  121. package/dist/schema/SchemaPropertyDetail.vue_vue_type_script_setup_true_lang.js.map +1 -0
  122. package/dist/schema/SchemaPropertyExamples.vue.d.ts +2 -0
  123. package/dist/schema/SchemaPropertyExamples.vue.d.ts.map +1 -1
  124. package/dist/schema/SchemaPropertyExamples.vue.js +3 -3
  125. package/dist/schema/SchemaPropertyExamples.vue.js.map +1 -1
  126. package/dist/schema/{SchemaPropertyExamples.vue.script.js → SchemaPropertyExamples.vue_vue_type_script_setup_true_lang.js} +10 -3
  127. package/dist/schema/SchemaPropertyExamples.vue_vue_type_script_setup_true_lang.js.map +1 -0
  128. package/dist/schema/SchemaPropertyHeading.vue.js +2 -2
  129. package/dist/schema/SchemaPropertyHeading.vue.js.map +1 -1
  130. package/dist/schema/{SchemaPropertyHeading.vue.script.js → SchemaPropertyHeading.vue_vue_type_script_setup_true_lang.js} +1 -1
  131. package/dist/schema/SchemaPropertyHeading.vue_vue_type_script_setup_true_lang.js.map +1 -0
  132. package/dist/schema/SchemaPropertyPattern.vue.js +2 -2
  133. package/dist/schema/SchemaPropertyPattern.vue.js.map +1 -1
  134. package/dist/schema/{SchemaPropertyPattern.vue.script.js → SchemaPropertyPattern.vue_vue_type_script_setup_true_lang.js} +1 -1
  135. package/dist/schema/SchemaPropertyPattern.vue_vue_type_script_setup_true_lang.js.map +1 -0
  136. package/dist/schema/SchemaRailPanel.vue.js +1 -1
  137. package/dist/schema/SchemaRailPanel.vue.js.map +1 -1
  138. package/dist/schema/{SchemaRailPanel.vue.script.js → SchemaRailPanel.vue_vue_type_script_setup_true_lang.js} +1 -1
  139. package/dist/schema/SchemaRailPanel.vue_vue_type_script_setup_true_lang.js.map +1 -0
  140. package/dist/schema/components/CopyLinkButton.vue.js +1 -1
  141. package/dist/schema/components/CopyLinkButton.vue.js.map +1 -1
  142. package/dist/schema/components/{CopyLinkButton.vue.script.js → CopyLinkButton.vue_vue_type_script_setup_true_lang.js} +1 -1
  143. package/dist/schema/components/CopyLinkButton.vue_vue_type_script_setup_true_lang.js.map +1 -0
  144. package/dist/schema/components/WithBreadcrumb.vue.js +1 -1
  145. package/dist/schema/components/WithBreadcrumb.vue.js.map +1 -1
  146. package/dist/schema/components/{WithBreadcrumb.vue.script.js → WithBreadcrumb.vue_vue_type_script_setup_true_lang.js} +1 -1
  147. package/dist/schema/components/WithBreadcrumb.vue_vue_type_script_setup_true_lang.js.map +1 -0
  148. package/dist/schema/discriminator-metadata.js.map +1 -1
  149. package/dist/schema/expansion/index.js +1 -2
  150. package/dist/schema/helpers/dynamic-scope.js.map +1 -1
  151. package/dist/schema/helpers/format-example.js.map +1 -1
  152. package/dist/schema/helpers/format-value.js.map +1 -1
  153. package/dist/schema/helpers/get-compositions-to-render.js.map +1 -1
  154. package/dist/schema/helpers/get-discriminator-values.js.map +1 -1
  155. package/dist/schema/helpers/get-enum-values.js.map +1 -1
  156. package/dist/schema/helpers/get-property-description.js.map +1 -1
  157. package/dist/schema/helpers/get-ref-name.js.map +1 -1
  158. package/dist/schema/helpers/get-schema-type.js.map +1 -1
  159. package/dist/schema/helpers/get-type-signature-tokens.js.map +1 -1
  160. package/dist/schema/helpers/has-complex-array-items.js.map +1 -1
  161. package/dist/schema/helpers/is-empty-schema-object.js.map +1 -1
  162. package/dist/schema/helpers/is-model-linkable.js.map +1 -1
  163. package/dist/schema/helpers/is-on-schema-target-path.js.map +1 -1
  164. package/dist/schema/helpers/is-type-object.js.map +1 -1
  165. package/dist/schema/helpers/merge-all-of-schemas.js +24 -25
  166. package/dist/schema/helpers/merge-all-of-schemas.js.map +1 -1
  167. package/dist/schema/helpers/normalize-object-composition.js.map +1 -1
  168. package/dist/schema/helpers/optimize-value-for-display.js +5 -12
  169. package/dist/schema/helpers/optimize-value-for-display.js.map +1 -1
  170. package/dist/schema/helpers/partition-all-of-compositions.js.map +1 -1
  171. package/dist/schema/helpers/schema-composition.js.map +1 -1
  172. package/dist/schema/helpers/schema-cycle.js.map +1 -1
  173. package/dist/schema/helpers/schema-expansion.js +4 -5
  174. package/dist/schema/helpers/schema-expansion.js.map +1 -1
  175. package/dist/schema/helpers/schema-keyboard-nav.js.map +1 -1
  176. package/dist/schema/helpers/schema-name.js.map +1 -1
  177. package/dist/schema/helpers/should-display-description.js.map +1 -1
  178. package/dist/schema/helpers/should-display-heading.js.map +1 -1
  179. package/dist/schema/helpers/should-render-array-item-composition.js.map +1 -1
  180. package/dist/schema/helpers/sort-property-names.js.map +1 -1
  181. package/dist/schema/helpers/unwrap-for-read.js.map +1 -1
  182. package/dist/schema/index.d.ts +1 -0
  183. package/dist/schema/index.d.ts.map +1 -1
  184. package/dist/schema/index.js +6 -5
  185. package/dist/schema/localization/index.d.ts +1 -1
  186. package/dist/schema/localization/index.js.map +1 -1
  187. package/dist/schema/localization/locales/ar.js.map +1 -1
  188. package/dist/schema/localization/locales/de.js.map +1 -1
  189. package/dist/schema/localization/locales/en.js.map +1 -1
  190. package/dist/schema/localization/locales/es.js.map +1 -1
  191. package/dist/schema/localization/locales/fr.js.map +1 -1
  192. package/dist/schema/localization/locales/pt.js.map +1 -1
  193. package/dist/schema/localization/locales/ru.js.map +1 -1
  194. package/dist/schema/localization/locales/zh-cn.js.map +1 -1
  195. package/dist/schema/localization/locales/zh-tw.js.map +1 -1
  196. package/dist/schema/localization/translations.js.map +1 -1
  197. package/dist/schema/request-body-composition-index.js.map +1 -1
  198. package/dist/shared/Badge.vue.js +2 -2
  199. package/dist/shared/Badge.vue.js.map +1 -1
  200. package/dist/shared/{Badge.vue.script.js → Badge.vue_vue_type_script_setup_true_lang.js} +1 -1
  201. package/dist/shared/Badge.vue_vue_type_script_setup_true_lang.js.map +1 -0
  202. package/dist/shared/ExternalDocs.vue.js +1 -1
  203. package/dist/shared/ExternalDocs.vue.js.map +1 -1
  204. package/dist/shared/{ExternalDocs.vue.script.js → ExternalDocs.vue_vue_type_script_setup_true_lang.js} +1 -1
  205. package/dist/shared/ExternalDocs.vue_vue_type_script_setup_true_lang.js.map +1 -0
  206. package/dist/shared/ScreenReader.vue.js +1 -1
  207. package/dist/shared/ScreenReader.vue.js.map +1 -1
  208. package/dist/shared/{ScreenReader.vue.script.js → ScreenReader.vue_vue_type_script_setup_true_lang.js} +1 -1
  209. package/dist/shared/ScreenReader.vue_vue_type_script_setup_true_lang.js.map +1 -0
  210. package/dist/specification-extensions/ExtensionValue.vue.js +1 -1
  211. package/dist/specification-extensions/ExtensionValue.vue.js.map +1 -1
  212. package/dist/specification-extensions/{ExtensionValue.vue.script.js → ExtensionValue.vue_vue_type_script_setup_true_lang.js} +1 -1
  213. package/dist/specification-extensions/ExtensionValue.vue_vue_type_script_setup_true_lang.js.map +1 -0
  214. package/dist/specification-extensions/SpecificationExtensions.vue.js +1 -1
  215. package/dist/specification-extensions/SpecificationExtensions.vue.js.map +1 -1
  216. package/dist/specification-extensions/{SpecificationExtensions.vue.script.js → SpecificationExtensions.vue_vue_type_script_setup_true_lang.js} +1 -1
  217. package/dist/specification-extensions/SpecificationExtensions.vue_vue_type_script_setup_true_lang.js.map +1 -0
  218. package/dist/specification-extensions/index.js +1 -2
  219. package/dist/style.css +68 -31
  220. package/dist/vue-styles.css +1 -1
  221. package/package.json +23 -23
  222. package/dist/code-example/components/CodeExample.vue.script.js +0 -258
  223. package/dist/code-example/components/CodeExample.vue.script.js.map +0 -1
  224. package/dist/code-example/components/ExamplePicker.vue.script.js.map +0 -1
  225. package/dist/code-example/components/HttpMethod.vue.script.js.map +0 -1
  226. package/dist/schema/RenderString.vue.script.js.map +0 -1
  227. package/dist/schema/Schema.vue.script.js.map +0 -1
  228. package/dist/schema/SchemaCollapsedPreview.vue.script.js.map +0 -1
  229. package/dist/schema/SchemaComposition.vue.script.js.map +0 -1
  230. package/dist/schema/SchemaEnumPropertyItem.vue.script.js.map +0 -1
  231. package/dist/schema/SchemaEnums.vue.script.js.map +0 -1
  232. package/dist/schema/SchemaGlyphPuck.vue.script.js.map +0 -1
  233. package/dist/schema/SchemaGutterToggle.vue.script.js.map +0 -1
  234. package/dist/schema/SchemaHeading.vue.script.js.map +0 -1
  235. package/dist/schema/SchemaObjectExampleCodeBlock.vue.script.js.map +0 -1
  236. package/dist/schema/SchemaProperty.vue.script.js.map +0 -1
  237. package/dist/schema/SchemaPropertyDefault.vue.script.js.map +0 -1
  238. package/dist/schema/SchemaPropertyDetail.vue.script.js.map +0 -1
  239. package/dist/schema/SchemaPropertyExamples.vue.script.js.map +0 -1
  240. package/dist/schema/SchemaPropertyHeading.vue.script.js.map +0 -1
  241. package/dist/schema/SchemaPropertyPattern.vue.script.js.map +0 -1
  242. package/dist/schema/SchemaRailPanel.vue.script.js.map +0 -1
  243. package/dist/schema/components/CopyLinkButton.vue.script.js.map +0 -1
  244. package/dist/schema/components/WithBreadcrumb.vue.script.js.map +0 -1
  245. package/dist/shared/Badge.vue.script.js.map +0 -1
  246. package/dist/shared/ExternalDocs.vue.script.js.map +0 -1
  247. package/dist/shared/ScreenReader.vue.script.js.map +0 -1
  248. package/dist/specification-extensions/ExtensionValue.vue.script.js.map +0 -1
  249. package/dist/specification-extensions/SpecificationExtensions.vue.script.js.map +0 -1
@@ -0,0 +1,33 @@
1
+ import { getResolvedAsyncApiRef as e } from "@scalar/workspace-store/helpers/get-resolved-async-api-ref";
2
+ import { getAllChannelMessages as t, resolveOperationChannel as n, resolveOperationWithTraits as r } from "@scalar/workspace-store/channel-example";
3
+ import { getNameFromRef as i } from "@scalar/workspace-store/helpers/get-name-from-ref";
4
+ import { resolveTraits as a } from "@scalar/workspace-store/helpers/resolve-traits";
5
+ //#region src/code-example/helpers/get-asyncapi-example-context.ts
6
+ var o = (o, s) => {
7
+ let c = e(o.operations?.[s]);
8
+ if (!c) return;
9
+ let l = r(c), u = n(o, l), d = u?.channel, f = (l.messages === void 0 ? d ? t(o, d) : [] : l.messages.flatMap((t, n) => {
10
+ let r = e(t), a = t.$ref && u?.channelName ? i(t.$ref, [
11
+ "channels",
12
+ u.channelName,
13
+ "messages"
14
+ ]) : void 0;
15
+ return r && !("$ref" in r) ? [{
16
+ name: a ?? t.$ref ?? String(n),
17
+ message: r
18
+ }] : [];
19
+ })).map(({ name: e, message: t }) => ({
20
+ name: e,
21
+ message: a(t, t.traits ?? [])
22
+ }));
23
+ return {
24
+ operation: l,
25
+ channelName: u?.channelName,
26
+ channel: d,
27
+ messages: f
28
+ };
29
+ };
30
+ //#endregion
31
+ export { o as getAsyncApiExampleContext };
32
+
33
+ //# sourceMappingURL=get-asyncapi-example-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-asyncapi-example-context.js","names":["getAsyncApiExampleContext","node","getResolvedAsyncApiRef","document","operationName","operation","resolveOperationWithTraits","resolved","resolveOperationChannel","channel","resolvedMessages","getAllChannelMessages","message","ref","name","getNameFromRef","index","resolveTraits"],"sources":["../../../src/code-example/helpers/get-asyncapi-example-context.ts"],"sourcesContent":["import type {\n AsyncApiChannelObject,\n AsyncApiDocument,\n AsyncApiMessageObject,\n AsyncApiOperationObject,\n} from '@scalar/types/asyncapi/3.1'\nimport {\n type ChannelMessageEntry,\n getAllChannelMessages,\n resolveOperationChannel,\n resolveOperationWithTraits,\n} from '@scalar/workspace-store/channel-example'\nimport { getNameFromRef } from '@scalar/workspace-store/helpers/get-name-from-ref'\nimport { getResolvedAsyncApiRef } from '@scalar/workspace-store/helpers/get-resolved-async-api-ref'\nimport { resolveTraits } from '@scalar/workspace-store/helpers/resolve-traits'\n\ntype AsyncApiExampleContext = {\n operation: AsyncApiOperationObject\n channelName: string | undefined\n channel: AsyncApiChannelObject | undefined\n messages: ChannelMessageEntry[]\n}\n\n/** Resolve operation-level samples and only the messages that operation permits. */\nexport const getAsyncApiExampleContext = (\n document: AsyncApiDocument,\n operationName: string,\n): AsyncApiExampleContext | undefined => {\n const node = getResolvedAsyncApiRef(document.operations?.[operationName])\n if (!node) {\n return undefined\n }\n const operation = resolveOperationWithTraits(node)\n const resolved = resolveOperationChannel(document, operation)\n const channel = resolved?.channel\n const messages =\n operation.messages === undefined\n ? channel\n ? getAllChannelMessages(document, channel)\n : []\n : operation.messages.flatMap((ref, index) => {\n const message = getResolvedAsyncApiRef(ref)\n const name =\n ref.$ref && resolved?.channelName\n ? getNameFromRef(ref.$ref, ['channels', resolved.channelName, 'messages'])\n : undefined\n return message && !('$ref' in message) ? [{ name: name ?? ref.$ref ?? String(index), message }] : []\n })\n const resolvedMessages = messages.map(({ name, message }) => ({\n name,\n message: resolveTraits(message, message.traits ?? []) satisfies AsyncApiMessageObject,\n }))\n return { operation, channelName: resolved?.channelName, channel, messages: resolvedMessages }\n}\n"],"mappings":";;;;;AAwBA,IAAaA,KACX,GACA,MACuC;CACvC,IAAMC,IAAOC,EAAuBC,EAAS,aAAaC,EAAc;CACxE,IAAI,CAACH,GACH;CAEF,IAAMI,IAAYC,EAA2BL,CAAI,GAC3CM,IAAWC,EAAwBL,GAAUE,CAAS,GACtDI,IAAUF,GAAU,SAcpBG,KAZJL,EAAU,aAAa,KAAA,IACnBI,IACEE,EAAsBR,GAAUM,CAAO,IACvC,CAAC,IACHJ,EAAU,SAAS,SAAS,GAAK,MAAU;EACzC,IAAMO,IAAUV,EAAuBW,CAAG,GACpCC,IACJD,EAAI,QAAQN,GAAU,cAClBQ,EAAeF,EAAI,MAAM;GAAC;GAAYN,EAAS;GAAa;EAAU,CAAC,IACvE,KAAA;EACN,OAAOK,KAAW,EAAE,UAAUA,KAAW,CAAC;GAAE,MAAME,KAAQD,EAAI,QAAQ,OAAOG,CAAK;GAAG;EAAQ,CAAC,IAAI,CAAC;CACrG,CAAC,EAAA,CAC2B,KAAK,EAAE,SAAM,kBAAe;EAC5D;EACA,SAASC,EAAcL,GAASA,EAAQ,UAAU,CAAC,CAAC;CACtD,EAAE;CACF,OAAO;EAAE;EAAW,aAAaL,GAAU;EAAa;EAAS,UAAUG;CAAiB;AAC9F"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-clients.js","names":[],"sources":["../../../src/code-example/helpers/get-clients.ts"],"sourcesContent":["import type { TargetId } from '@scalar/types/snippetz'\nimport type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation'\n\nimport type { ClientOptionGroup, CustomClientOption, CustomClientOptionGroup } from '../types'\nimport { formatLanguage } from './format-language'\nimport { getCustomClientIds } from './generate-client-options'\nimport { CODE_EXAMPLES_GROUP_LABEL } from './get-custom-code-samples'\n\n/**\n * Merges custom code samples with the client options\n *\n * @param customCodeSamples - The custom code samples from the operation to merge with the client options\n * @param clientOptions - The client options to merge with the custom code samples\n * @param label - The label for the custom samples group (e.g. \"SDK\" or \"Code Examples\")\n * @returns A list of client option groups\n */\nexport const getClients = (\n customCodeSamples: XCodeSample[],\n clientOptions: ClientOptionGroup[],\n label: string = CODE_EXAMPLES_GROUP_LABEL,\n): CustomClientOptionGroup[] => {\n // Handle custom code examples\n if (customCodeSamples.length) {\n // Language-keyed ids so the same sample can be selected across operations\n const ids = getCustomClientIds(customCodeSamples)\n\n const customClients = customCodeSamples.flatMap((sample, index) => {\n const id = ids[index] ?? `custom/${index}`\n if (ids.indexOf(id) !== index) {\n return []\n }\n const label = sample.label || formatLanguage(sample.lang) || id\n const lang = (sample.lang as TargetId) || 'plaintext'\n\n return {\n id,\n lang,\n title: label,\n label,\n clientKey: 'custom',\n } satisfies CustomClientOption\n })\n\n return [\n {\n label,\n key: 'custom',\n options: customClients,\n },\n ...clientOptions,\n ]\n }\n\n return clientOptions\n}\n"],"mappings":";;;;AAgBA,IAAa,KACX,GACA,GACA,IAAgB,MACc;CAE9B,IAAI,EAAkB,QAAQ;EAE5B,IAAM,IAAM,EAAmB,CAAiB;EAmBhD,OAAO,CACL;GACE;GACA,KAAK;GACL,SArBkB,EAAkB,SAAS,GAAQ,MAAU;IACjE,IAAM,IAAK,EAAI,MAAU,UAAU;IACnC,IAAI,EAAI,QAAQ,CAAE,MAAM,GACtB,OAAO,CAAC;IAEV,IAAM,IAAQ,EAAO,SAAS,EAAe,EAAO,IAAI,KAAK;IAG7D,OAAO;KACL;KACA,MAJY,EAAO,QAAqB;KAKxC,OAAO;KACP;KACA,WAAW;IACb;GACF,CAMa;EACX,GACA,GAAG,CACL;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"get-clients.js","names":["getClients","CODE_EXAMPLES_GROUP_LABEL","customCodeSamples","ids","getCustomClientIds","id","index","label","sample","formatLanguage","clientOptions"],"sources":["../../../src/code-example/helpers/get-clients.ts"],"sourcesContent":["import type { TargetId } from '@scalar/types/snippetz'\nimport type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation'\n\nimport type { ClientOptionGroup, CustomClientOption, CustomClientOptionGroup } from '../types'\nimport { formatLanguage } from './format-language'\nimport { getCustomClientIds } from './generate-client-options'\nimport { CODE_EXAMPLES_GROUP_LABEL } from './get-custom-code-samples'\n\n/**\n * Merges custom code samples with the client options\n *\n * @param customCodeSamples - The custom code samples from the operation to merge with the client options\n * @param clientOptions - The client options to merge with the custom code samples\n * @param label - The label for the custom samples group (e.g. \"SDK\" or \"Code Examples\")\n * @returns A list of client option groups\n */\nexport const getClients = (\n customCodeSamples: XCodeSample[],\n clientOptions: ClientOptionGroup[],\n label: string = CODE_EXAMPLES_GROUP_LABEL,\n): CustomClientOptionGroup[] => {\n // Handle custom code examples\n if (customCodeSamples.length) {\n // Language-keyed ids so the same sample can be selected across operations\n const ids = getCustomClientIds(customCodeSamples)\n\n const customClients = customCodeSamples.flatMap((sample, index) => {\n const id = ids[index] ?? `custom/${index}`\n if (ids.indexOf(id) !== index) {\n return []\n }\n const label = sample.label || formatLanguage(sample.lang) || id\n const lang = (sample.lang as TargetId) || 'plaintext'\n\n return {\n id,\n lang,\n title: label,\n label,\n clientKey: 'custom',\n } satisfies CustomClientOption\n })\n\n return [\n {\n label,\n key: 'custom',\n options: customClients,\n },\n ...clientOptions,\n ]\n }\n\n return clientOptions\n}\n"],"mappings":";;;;AAgBA,IAAaA,KACX,GACA,GACA,IAAgBC,MACc;CAE9B,IAAIC,EAAkB,QAAQ;EAE5B,IAAMC,IAAMC,EAAmBF,CAAiB;EAmBhD,OAAO,CACL;GACE;GACA,KAAK;GACL,SArBkBA,EAAkB,SAAS,GAAQ,MAAU;IACjE,IAAMG,IAAKF,EAAIG,MAAU,UAAUA;IACnC,IAAIH,EAAI,QAAQE,CAAE,MAAMC,GACtB,OAAO,CAAC;IAEV,IAAMC,IAAQC,EAAO,SAASC,EAAeD,EAAO,IAAI,KAAKH;IAG7D,OAAO;KACL;KACA,MAJYG,EAAO,QAAqB;KAKxC,OAAOD;KACP;KACA,WAAW;IACb;GACF,CAMa;EACX,GACA,GAAGG,CACL;CACF;CAEA,OAAOA;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-custom-code-samples.js","names":[],"sources":["../../../src/code-example/helpers/get-custom-code-samples.ts"],"sourcesContent":["import type {\n XCodeSample,\n XLanguageExample,\n XReadmeCodeSample,\n} from '@scalar/workspace-store/schemas/extensions/operation'\nimport type { OperationObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\n\n/** Turns a `{ language: source }` map (x-stainless-snippets) into code samples. */\nconst fromSnippetMap = (snippets: Record<string, string> | undefined, label?: string): XCodeSample[] =>\n Object.entries(snippets ?? {}).map(([lang, source]) => ({ lang, source, ...(label ? { label } : {}) }))\n\n/**\n * Turns `x-stainless-examples` / `x-scalar-examples` into code samples.\n *\n * Each example carries per-language request snippets and an optional title that\n * we surface as the picker label. The response is only used for documentation,\n * so it is ignored here.\n */\nconst fromLanguageExamples = (examples: XLanguageExample | XLanguageExample[] | undefined): XCodeSample[] => {\n if (!examples) {\n return []\n }\n\n return (Array.isArray(examples) ? examples : [examples]).flatMap((example) =>\n fromSnippetMap(example.request, example.title),\n )\n}\n\n/** Turns ReadMe's `x-readme.code-samples` into code samples. */\nconst fromReadmeSamples = (samples: XReadmeCodeSample[] | undefined): XCodeSample[] =>\n (samples ?? []).map((sample) => ({\n lang: sample.language,\n source: sample.code,\n ...(sample.name ? { label: sample.name } : {}),\n }))\n\n/** Picker group label for samples generated by an SDK provider (Scalar, Stainless, …). */\nconst SDK_GROUP_LABEL = 'SDK'\n\n/** Picker group label for generic or docs-platform samples (the standard `x-codeSamples` family, ReadMe, …). */\nexport const CODE_EXAMPLES_GROUP_LABEL = 'Code Examples'\n\ntype CustomCodeSampleGroupLabel = typeof SDK_GROUP_LABEL | typeof CODE_EXAMPLES_GROUP_LABEL\n\ntype CustomCodeSamples = {\n /**\n * Group label for the code sample picker.\n *\n * Samples that come from an SDK provider extension (`x-scalar-examples`,\n * `x-stainless-snippets`, `x-stainless-examples`) surface under \"SDK\". Generic\n * or docs-platform samples (`x-readme`, the `x-codeSamples` family) surface\n * under \"Code Examples\".\n */\n label: CustomCodeSampleGroupLabel\n /** The custom code samples, in picker order. */\n samples: XCodeSample[]\n}\n\n/**\n * Grabs any custom code samples from the operation.\n *\n * Several tools write code samples into OpenAPI under different extensions. When\n * more than one is present we use the highest-priority source only, rather than\n * showing duplicates from every tool. Priority, highest first:\n *\n * 1. `x-scalar-examples` (SDK)\n * 2. `x-stainless-snippets` (SDK, overrides `x-stainless-examples`)\n * 3. `x-stainless-examples` (SDK)\n * 4. `x-readme.code-samples` (Code Examples)\n * 5. `x-codeSamples` / `x-code-samples` / `x-custom-examples` (Code Examples)\n *\n * The winning source also determines the picker group label: SDK-provider\n * extensions surface under \"SDK\", everything else under \"Code Examples\".\n *\n * Note that Speakeasy does not have its own extension — it writes into the\n * standard `x-codeSamples`, so its snippets surface under \"Code Examples\".\n *\n * @param operation - The operation to get the custom code samples from\n * @returns The picker group label and the custom code samples which exist in the operation\n */\nexport const getCustomCodeSamples = (operation: OperationObject): CustomCodeSamples => {\n const scalarExamples = operation['x-scalar-examples'] ?? []\n if (scalarExamples.length) {\n return { label: SDK_GROUP_LABEL, samples: scalarExamples }\n }\n\n const stainlessSnippets = fromSnippetMap(operation['x-stainless-snippets'])\n if (stainlessSnippets.length) {\n return { label: SDK_GROUP_LABEL, samples: stainlessSnippets }\n }\n\n const stainlessExamples = fromLanguageExamples(operation['x-stainless-examples'])\n if (stainlessExamples.length) {\n return { label: SDK_GROUP_LABEL, samples: stainlessExamples }\n }\n\n const readmeSamples = fromReadmeSamples(operation['x-readme']?.['code-samples'])\n if (readmeSamples.length) {\n return { label: CODE_EXAMPLES_GROUP_LABEL, samples: readmeSamples }\n }\n\n const customCodeKeys = ['x-custom-examples', 'x-codeSamples', 'x-code-samples'] as const\n return { label: CODE_EXAMPLES_GROUP_LABEL, samples: customCodeKeys.flatMap((key) => operation[key] ?? []) }\n}\n"],"mappings":";AAQA,IAAM,KAAkB,GAA8C,MACpE,OAAO,QAAQ,KAAY,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAM,QAAa;CAAE;CAAM;CAAQ,GAAI,IAAQ,EAAE,SAAM,IAAI,CAAC;AAAG,EAAE,GASlG,KAAwB,MACvB,KAIG,MAAM,QAAQ,CAAQ,IAAI,IAAW,CAAC,CAAQ,EAAA,CAAG,SAAS,MAChE,EAAe,EAAQ,SAAS,EAAQ,KAAK,CAC/C,IALS,CAAC,GASN,KAAqB,OACxB,KAAW,CAAC,EAAA,CAAG,KAAK,OAAY;CAC/B,MAAM,EAAO;CACb,QAAQ,EAAO;CACf,GAAI,EAAO,OAAO,EAAE,OAAO,EAAO,KAAK,IAAI,CAAC;AAC9C,EAAE,GAGE,IAAkB,OAGX,IAA4B,iBAwC5B,KAAwB,MAAkD;CACrF,IAAM,IAAiB,EAAU,wBAAwB,CAAC;CAC1D,IAAI,EAAe,QACjB,OAAO;EAAE,OAAO;EAAiB,SAAS;CAAe;CAG3D,IAAM,IAAoB,EAAe,EAAU,uBAAuB;CAC1E,IAAI,EAAkB,QACpB,OAAO;EAAE,OAAO;EAAiB,SAAS;CAAkB;CAG9D,IAAM,IAAoB,EAAqB,EAAU,uBAAuB;CAChF,IAAI,EAAkB,QACpB,OAAO;EAAE,OAAO;EAAiB,SAAS;CAAkB;CAG9D,IAAM,IAAgB,EAAkB,EAAU,WAAW,GAAG,eAAe;CAM/E,OALI,EAAc,SACT;EAAE,OAAO;EAA2B,SAAS;CAAc,IAI7D;EAAE,OAAO;EAA2B,SAAS;GAD5B;GAAqB;GAAiB;EACV,CAAA,CAAe,SAAS,MAAQ,EAAU,MAAQ,CAAC,CAAC;CAAE;AAC5G"}
1
+ {"version":3,"file":"get-custom-code-samples.js","names":["fromSnippetMap","snippets","lang","source","label","fromLanguageExamples","examples","example","fromReadmeSamples","samples","sample","SDK_GROUP_LABEL","CODE_EXAMPLES_GROUP_LABEL","getCustomCodeSamples","scalarExamples","operation","stainlessSnippets","stainlessExamples","readmeSamples","key"],"sources":["../../../src/code-example/helpers/get-custom-code-samples.ts"],"sourcesContent":["import type {\n XCodeSample,\n XLanguageExample,\n XReadmeCodeSample,\n} from '@scalar/workspace-store/schemas/extensions/operation'\nimport type { OperationObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\n\n/** Turns a `{ language: source }` map (x-stainless-snippets) into code samples. */\nconst fromSnippetMap = (snippets: Record<string, string> | undefined, label?: string): XCodeSample[] =>\n Object.entries(snippets ?? {}).map(([lang, source]) => ({ lang, source, ...(label ? { label } : {}) }))\n\n/**\n * Turns `x-stainless-examples` / `x-scalar-examples` into code samples.\n *\n * Each example carries per-language request snippets and an optional title that\n * we surface as the picker label. The response is only used for documentation,\n * so it is ignored here.\n */\nconst fromLanguageExamples = (examples: XLanguageExample | XLanguageExample[] | undefined): XCodeSample[] => {\n if (!examples) {\n return []\n }\n\n return (Array.isArray(examples) ? examples : [examples]).flatMap((example) =>\n fromSnippetMap(example.request, example.title),\n )\n}\n\n/** Turns ReadMe's `x-readme.code-samples` into code samples. */\nconst fromReadmeSamples = (samples: XReadmeCodeSample[] | undefined): XCodeSample[] =>\n (samples ?? []).map((sample) => ({\n lang: sample.language,\n source: sample.code,\n ...(sample.name ? { label: sample.name } : {}),\n }))\n\n/** Picker group label for samples generated by an SDK provider (Scalar, Stainless, …). */\nconst SDK_GROUP_LABEL = 'SDK'\n\n/** Picker group label for generic or docs-platform samples (the standard `x-codeSamples` family, ReadMe, …). */\nexport const CODE_EXAMPLES_GROUP_LABEL = 'Code Examples'\n\ntype CustomCodeSampleGroupLabel = typeof SDK_GROUP_LABEL | typeof CODE_EXAMPLES_GROUP_LABEL\n\ntype CustomCodeSamples = {\n /**\n * Group label for the code sample picker.\n *\n * Samples that come from an SDK provider extension (`x-scalar-examples`,\n * `x-stainless-snippets`, `x-stainless-examples`) surface under \"SDK\". Generic\n * or docs-platform samples (`x-readme`, the `x-codeSamples` family) surface\n * under \"Code Examples\".\n */\n label: CustomCodeSampleGroupLabel\n /** The custom code samples, in picker order. */\n samples: XCodeSample[]\n}\n\n/**\n * Grabs any custom code samples from the operation.\n *\n * Several tools write code samples into OpenAPI under different extensions. When\n * more than one is present we use the highest-priority source only, rather than\n * showing duplicates from every tool. Priority, highest first:\n *\n * 1. `x-scalar-examples` (SDK)\n * 2. `x-stainless-snippets` (SDK, overrides `x-stainless-examples`)\n * 3. `x-stainless-examples` (SDK)\n * 4. `x-readme.code-samples` (Code Examples)\n * 5. `x-codeSamples` / `x-code-samples` / `x-custom-examples` (Code Examples)\n *\n * The winning source also determines the picker group label: SDK-provider\n * extensions surface under \"SDK\", everything else under \"Code Examples\".\n *\n * Note that Speakeasy does not have its own extension — it writes into the\n * standard `x-codeSamples`, so its snippets surface under \"Code Examples\".\n *\n * @param operation - The operation to get the custom code samples from\n * @returns The picker group label and the custom code samples which exist in the operation\n */\nexport const getCustomCodeSamples = (operation: OperationObject): CustomCodeSamples => {\n const scalarExamples = operation['x-scalar-examples'] ?? []\n if (scalarExamples.length) {\n return { label: SDK_GROUP_LABEL, samples: scalarExamples }\n }\n\n const stainlessSnippets = fromSnippetMap(operation['x-stainless-snippets'])\n if (stainlessSnippets.length) {\n return { label: SDK_GROUP_LABEL, samples: stainlessSnippets }\n }\n\n const stainlessExamples = fromLanguageExamples(operation['x-stainless-examples'])\n if (stainlessExamples.length) {\n return { label: SDK_GROUP_LABEL, samples: stainlessExamples }\n }\n\n const readmeSamples = fromReadmeSamples(operation['x-readme']?.['code-samples'])\n if (readmeSamples.length) {\n return { label: CODE_EXAMPLES_GROUP_LABEL, samples: readmeSamples }\n }\n\n const customCodeKeys = ['x-custom-examples', 'x-codeSamples', 'x-code-samples'] as const\n return { label: CODE_EXAMPLES_GROUP_LABEL, samples: customCodeKeys.flatMap((key) => operation[key] ?? []) }\n}\n"],"mappings":";AAQA,IAAMA,KAAkB,GAA8C,MACpE,OAAO,QAAQC,KAAY,CAAC,CAAC,CAAC,CAAC,KAAK,CAACC,GAAMC,QAAa;CAAE;CAAM;CAAQ,GAAIC,IAAQ,EAAE,SAAM,IAAI,CAAC;AAAG,EAAE,GASlGC,KAAwB,MACvBC,KAIG,MAAM,QAAQA,CAAQ,IAAIA,IAAW,CAACA,CAAQ,EAAA,CAAG,SAAS,MAChEN,EAAeO,EAAQ,SAASA,EAAQ,KAAK,CAC/C,IALS,CAAC,GASNC,KAAqB,OACxBC,KAAW,CAAC,EAAA,CAAG,KAAK,OAAY;CAC/B,MAAMC,EAAO;CACb,QAAQA,EAAO;CACf,GAAIA,EAAO,OAAO,EAAE,OAAOA,EAAO,KAAK,IAAI,CAAC;AAC9C,EAAE,GAGEC,IAAkB,OAGXC,IAA4B,iBAwC5BC,KAAwB,MAAkD;CACrF,IAAMC,IAAiBC,EAAU,wBAAwB,CAAC;CAC1D,IAAID,EAAe,QACjB,OAAO;EAAE,OAAOH;EAAiB,SAASG;CAAe;CAG3D,IAAME,IAAoBhB,EAAee,EAAU,uBAAuB;CAC1E,IAAIC,EAAkB,QACpB,OAAO;EAAE,OAAOL;EAAiB,SAASK;CAAkB;CAG9D,IAAMC,IAAoBZ,EAAqBU,EAAU,uBAAuB;CAChF,IAAIE,EAAkB,QACpB,OAAO;EAAE,OAAON;EAAiB,SAASM;CAAkB;CAG9D,IAAMC,IAAgBV,EAAkBO,EAAU,WAAW,GAAG,eAAe;CAM/E,OALIG,EAAc,SACT;EAAE,OAAON;EAA2B,SAASM;CAAc,IAI7D;EAAE,OAAON;EAA2B,SAAS;GAD5B;GAAqB;GAAiB;EACV,CAAA,CAAe,SAAS,MAAQG,EAAUI,MAAQ,CAAC,CAAC;CAAE;AAC5G"}
@@ -0,0 +1,4 @@
1
+ import type { AsyncApiMessageObject } from '@scalar/types/asyncapi/3.1';
2
+ /** Generate a payload only when the document does not already provide one. */
3
+ export declare const getGeneratedPayloadExample: (message: AsyncApiMessageObject) => unknown;
4
+ //# sourceMappingURL=get-generated-payload-example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-generated-payload-example.d.ts","sourceRoot":"","sources":["../../../src/code-example/helpers/get-generated-payload-example.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAmBvE,8EAA8E;AAC9E,eAAO,MAAM,0BAA0B,GAAI,SAAS,qBAAqB,KAAG,OA4B3E,CAAA"}
@@ -0,0 +1,25 @@
1
+ import { getResolvedAsyncApiRef as e } from "@scalar/workspace-store/helpers/get-resolved-async-api-ref";
2
+ import { isObject as t } from "@scalar/helpers/object/is-object";
3
+ import { resolveAsyncApiSchema as n } from "@scalar/workspace-store/helpers/resolve-async-api-schema";
4
+ import { snapshotSchema as r } from "@scalar/workspace-store/helpers/snapshot-schema";
5
+ import { getExampleFromSchema as i } from "@scalar/workspace-store/request-example";
6
+ //#region src/code-example/helpers/get-generated-payload-example.ts
7
+ var a = (n, r = /* @__PURE__ */ new Set()) => {
8
+ let i = e(n);
9
+ return i === !1 ? !0 : !t(i) || r.has(i) ? !1 : (r.add(i), Array.isArray(i.allOf) && i.allOf.some((e) => a(e, r)));
10
+ }, o = (o) => {
11
+ if (o.examples?.some((t) => e(t)?.payload !== void 0)) return;
12
+ let s = e(o.payload);
13
+ if (typeof s == "boolean" || t(s) && "schemaFormat" in s && typeof e(s.schema) == "boolean") return;
14
+ let c = n(o.payload), l = c?.kind === "schema" ? c.schema : void 0;
15
+ if (!l || a(l)) return;
16
+ let u = r(l);
17
+ return i(u, {
18
+ emptyString: "string",
19
+ includeDeprecated: !0
20
+ });
21
+ };
22
+ //#endregion
23
+ export { o as getGeneratedPayloadExample };
24
+
25
+ //# sourceMappingURL=get-generated-payload-example.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-generated-payload-example.js","names":["hasFalseAllOfMember","schema","getResolvedAsyncApiRef","source","isObject","seen","member","getGeneratedPayloadExample","message","example","payload","resolved","resolveAsyncApiSchema","snapshot","snapshotSchema","getExampleFromSchema"],"sources":["../../../src/code-example/helpers/get-generated-payload-example.ts"],"sourcesContent":["import { isObject } from '@scalar/helpers/object/is-object'\nimport type { AsyncApiMessageObject } from '@scalar/types/asyncapi/3.1'\nimport { getResolvedAsyncApiRef } from '@scalar/workspace-store/helpers/get-resolved-async-api-ref'\nimport { resolveAsyncApiSchema } from '@scalar/workspace-store/helpers/resolve-async-api-schema'\nimport { snapshotSchema } from '@scalar/workspace-store/helpers/snapshot-schema'\nimport { getExampleFromSchema } from '@scalar/workspace-store/request-example'\n\n/** An allOf containing a false schema cannot have a valid example. */\nconst hasFalseAllOfMember = (source: unknown, seen = new Set<unknown>()): boolean => {\n const schema = getResolvedAsyncApiRef(source)\n if (schema === false) {\n return true\n }\n if (!isObject(schema) || seen.has(schema)) {\n return false\n }\n seen.add(schema)\n return Array.isArray(schema.allOf) && schema.allOf.some((member) => hasFalseAllOfMember(member, seen))\n}\n\n/** Generate a payload only when the document does not already provide one. */\nexport const getGeneratedPayloadExample = (message: AsyncApiMessageObject): unknown => {\n if (message.examples?.some((example) => getResolvedAsyncApiRef(example)?.payload !== undefined)) {\n return undefined\n }\n\n const payload = getResolvedAsyncApiRef(message.payload)\n // Boolean schemas describe validation, but do not suggest a representative payload.\n if (\n typeof payload === 'boolean' ||\n (isObject(payload) && 'schemaFormat' in payload && typeof getResolvedAsyncApiRef(payload.schema) === 'boolean')\n ) {\n return undefined\n }\n\n const resolved = resolveAsyncApiSchema(message.payload)\n const schema = resolved?.kind === 'schema' ? resolved.schema : undefined\n if (!schema || hasFalseAllOfMember(schema)) {\n return undefined\n }\n\n // Snapshot reactive schemas so in-place edits do not reuse the generator's identity cache.\n // The generator resolves schema references itself, preserving literal $ref fields in payload data.\n const snapshot = snapshotSchema(schema)\n return getExampleFromSchema(snapshot, {\n emptyString: 'string',\n // Match the message schema, which displays fields regardless of their read/write annotations.\n includeDeprecated: true,\n })\n}\n"],"mappings":";;;;;;AAQA,IAAMA,KAAuB,GAAiB,oBAAO,IAAI,IAAa,MAAe;CACnF,IAAMC,IAASC,EAAuBC,CAAM;CAQ5C,OAPIF,MAAW,KACN,KAEL,CAACG,EAASH,CAAM,KAAKI,EAAK,IAAIJ,CAAM,IAC/B,MAETI,EAAK,IAAIJ,CAAM,GACR,MAAM,QAAQA,EAAO,KAAK,KAAKA,EAAO,MAAM,MAAM,MAAWD,EAAoBM,GAAQD,CAAI,CAAC;AACvG,GAGaE,KAA8B,MAA4C;CACrF,IAAIC,EAAQ,UAAU,MAAM,MAAYN,EAAuBO,CAAO,CAAC,EAAE,YAAY,KAAA,CAAS,GAC5F;CAGF,IAAMC,IAAUR,EAAuBM,EAAQ,OAAO;CAEtD,IACE,OAAOE,KAAY,aAClBN,EAASM,CAAO,KAAK,kBAAkBA,KAAW,OAAOR,EAAuBQ,EAAQ,MAAM,KAAM,WAErG;CAGF,IAAMC,IAAWC,EAAsBJ,EAAQ,OAAO,GAChDP,IAASU,GAAU,SAAS,WAAWA,EAAS,SAAS,KAAA;CAC/D,IAAI,CAACV,KAAUD,EAAoBC,CAAM,GACvC;CAKF,IAAMY,IAAWC,EAAeb,CAAM;CACtC,OAAOc,EAAqBF,GAAU;EACpC,aAAa;EAEb,mBAAmB;CACrB,CAAC;AACH"}
@@ -0,0 +1,10 @@
1
+ /** Keep the displayed sample, language, and clipboard representation together. */
2
+ type MessageExampleContent = {
3
+ content: string;
4
+ lang: 'json' | 'xml' | 'yaml' | 'plaintext';
5
+ structural: boolean;
6
+ };
7
+ /** Format payload values without interpreting non-JSON text as JSON or inventing wire encodings. */
8
+ export declare const getMessageExampleContent: (value: unknown, contentType?: string) => MessageExampleContent | undefined;
9
+ export {};
10
+ //# sourceMappingURL=get-message-example-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-message-example-content.d.ts","sourceRoot":"","sources":["../../../src/code-example/helpers/get-message-example-content.ts"],"names":[],"mappings":"AAMA,kFAAkF;AAClF,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,WAAW,CAAA;IAC3C,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,oGAAoG;AACpG,eAAO,MAAM,wBAAwB,GAAI,OAAO,OAAO,EAAE,cAAc,MAAM,KAAG,qBAAqB,GAAG,SA2BvG,CAAA"}
@@ -0,0 +1,29 @@
1
+ import { isObject as e } from "@scalar/helpers/object/is-object";
2
+ import { isJsonMediaType as t } from "@scalar/helpers/http/is-json-media-type";
3
+ import { isXmlMediaType as n } from "@scalar/helpers/http/is-xml-media-type";
4
+ import { parseMimeType as r } from "@scalar/helpers/http/mime-type";
5
+ import { prettyPrintJson as i } from "@scalar/helpers/json/pretty-print-json";
6
+ //#region src/code-example/helpers/get-message-example-content.ts
7
+ var a = (a, o) => {
8
+ if (a === void 0) return;
9
+ let s = o === void 0 || t(o), c = Array.isArray(a) || e(a), l = !s && c, { subtype: u } = r(o), d = s || l ? "json" : n(o) ? "xml" : u === "yaml" || u === "x-yaml" || u.endsWith("+yaml") ? "yaml" : "plaintext";
10
+ if (a === null || typeof a == "boolean") return {
11
+ content: String(a),
12
+ lang: d,
13
+ structural: l
14
+ };
15
+ if (typeof a == "string") return {
16
+ content: s ? i(a) : a,
17
+ lang: d,
18
+ structural: l
19
+ };
20
+ if (typeof a == "number" || Array.isArray(a) || e(a)) return {
21
+ content: i(a),
22
+ lang: d,
23
+ structural: l
24
+ };
25
+ };
26
+ //#endregion
27
+ export { a as getMessageExampleContent };
28
+
29
+ //# sourceMappingURL=get-message-example-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-message-example-content.js","names":["getMessageExampleContent","value","json","contentType","isJsonMediaType","structured","isObject","structural","parseMimeType","lang","isXmlMediaType","subtype","prettyPrintJson"],"sources":["../../../src/code-example/helpers/get-message-example-content.ts"],"sourcesContent":["import { isJsonMediaType } from '@scalar/helpers/http/is-json-media-type'\nimport { isXmlMediaType } from '@scalar/helpers/http/is-xml-media-type'\nimport { parseMimeType } from '@scalar/helpers/http/mime-type'\nimport { prettyPrintJson } from '@scalar/helpers/json/pretty-print-json'\nimport { isObject } from '@scalar/helpers/object/is-object'\n\n/** Keep the displayed sample, language, and clipboard representation together. */\ntype MessageExampleContent = {\n content: string\n lang: 'json' | 'xml' | 'yaml' | 'plaintext'\n structural: boolean\n}\n\n/** Format payload values without interpreting non-JSON text as JSON or inventing wire encodings. */\nexport const getMessageExampleContent = (value: unknown, contentType?: string): MessageExampleContent | undefined => {\n if (value === undefined) {\n return undefined\n }\n const json = contentType === undefined || isJsonMediaType(contentType)\n const structured = Array.isArray(value) || isObject(value)\n const structural = !json && structured\n const { subtype } = parseMimeType(contentType)\n const lang =\n json || structural\n ? 'json'\n : isXmlMediaType(contentType)\n ? 'xml'\n : subtype === 'yaml' || subtype === 'x-yaml' || subtype.endsWith('+yaml')\n ? 'yaml'\n : 'plaintext'\n\n if (value === null || typeof value === 'boolean') {\n return { content: String(value), lang, structural }\n }\n if (typeof value === 'string') {\n return { content: json ? prettyPrintJson(value) : value, lang, structural }\n }\n if (typeof value === 'number' || Array.isArray(value) || isObject(value)) {\n return { content: prettyPrintJson(value), lang, structural }\n }\n return undefined\n}\n"],"mappings":";;;;;;AAcA,IAAaA,KAA4B,GAAgB,MAA4D;CACnH,IAAIC,MAAU,KAAA,GACZ;CAEF,IAAMC,IAAOC,MAAgB,KAAA,KAAaC,EAAgBD,CAAW,GAC/DE,IAAa,MAAM,QAAQJ,CAAK,KAAKK,EAASL,CAAK,GACnDM,IAAa,CAACL,KAAQG,GACtB,EAAE,eAAYG,EAAcL,CAAW,GACvCM,IACJP,KAAQK,IACJ,SACAG,EAAeP,CAAW,IACxB,QACAQ,MAAY,UAAUA,MAAY,YAAYA,EAAQ,SAAS,OAAO,IACpE,SACA;CAEV,IAAIV,MAAU,QAAQ,OAAOA,KAAU,WACrC,OAAO;EAAE,SAAS,OAAOA,CAAK;EAAG;EAAM;CAAW;CAEpD,IAAI,OAAOA,KAAU,UACnB,OAAO;EAAE,SAASC,IAAOU,EAAgBX,CAAK,IAAIA;EAAO;EAAM;CAAW;CAE5E,IAAI,OAAOA,KAAU,YAAY,MAAM,QAAQA,CAAK,KAAKK,EAASL,CAAK,GACrE,OAAO;EAAE,SAASW,EAAgBX,CAAK;EAAG;EAAM;CAAW;AAG/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-secrets.js","names":[],"sources":["../../../src/code-example/helpers/get-secrets.ts"],"sourcesContent":["import type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport { encode } from 'js-base64'\n\n/** Extract secrets from security schemes */\nexport const getSecrets = (securitySchemes: SecuritySchemeObjectSecret[]): string[] =>\n securitySchemes\n .flatMap((scheme) => {\n if (scheme.type === 'apiKey') {\n return scheme['x-scalar-secret-token']\n }\n if (scheme?.type === 'http') {\n return [\n scheme['x-scalar-secret-token'],\n scheme['x-scalar-secret-username'],\n scheme['x-scalar-secret-password'],\n encode(`${scheme['x-scalar-secret-username']}:${scheme['x-scalar-secret-password']}`),\n ]\n }\n if (scheme.type === 'oauth2') {\n const flows = Object.values(scheme.flows)\n return flows.map((flow) => flow['x-scalar-secret-token'])\n }\n\n return []\n })\n .filter(Boolean)\n"],"mappings":";;AAIA,IAAa,KAAc,MACzB,EACG,SAAS,MACJ,EAAO,SAAS,WACX,EAAO,2BAEZ,GAAQ,SAAS,SACZ;CACL,EAAO;CACP,EAAO;CACP,EAAO;CACP,EAAO,GAAG,EAAO,4BAA4B,GAAG,EAAO,6BAA6B;AACtF,IAEE,EAAO,SAAS,WACJ,OAAO,OAAO,EAAO,KAC5B,CAAA,CAAM,KAAK,MAAS,EAAK,wBAAwB,IAGnD,CAAC,CACT,CAAC,CACD,OAAO,OAAO"}
1
+ {"version":3,"file":"get-secrets.js","names":["getSecrets","securitySchemes","scheme","encode","flow"],"sources":["../../../src/code-example/helpers/get-secrets.ts"],"sourcesContent":["import type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport { encode } from 'js-base64'\n\n/** Extract secrets from security schemes */\nexport const getSecrets = (securitySchemes: SecuritySchemeObjectSecret[]): string[] =>\n securitySchemes\n .flatMap((scheme) => {\n if (scheme.type === 'apiKey') {\n return scheme['x-scalar-secret-token']\n }\n if (scheme?.type === 'http') {\n return [\n scheme['x-scalar-secret-token'],\n scheme['x-scalar-secret-username'],\n scheme['x-scalar-secret-password'],\n encode(`${scheme['x-scalar-secret-username']}:${scheme['x-scalar-secret-password']}`),\n ]\n }\n if (scheme.type === 'oauth2') {\n const flows = Object.values(scheme.flows)\n return flows.map((flow) => flow['x-scalar-secret-token'])\n }\n\n return []\n })\n .filter(Boolean)\n"],"mappings":";;AAIA,IAAaA,KAAc,MACzBC,EACG,SAAS,MACJC,EAAO,SAAS,WACXA,EAAO,2BAEZA,GAAQ,SAAS,SACZ;CACLA,EAAO;CACPA,EAAO;CACPA,EAAO;CACPC,EAAO,GAAGD,EAAO,4BAA4B,GAAGA,EAAO,6BAA6B;AACtF,IAEEA,EAAO,SAAS,WACJ,OAAO,OAAOA,EAAO,KAC5B,CAAA,CAAM,KAAK,MAASE,EAAK,wBAAwB,IAGnD,CAAC,CACT,CAAC,CACD,OAAO,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-snippet.js","names":[],"sources":["../../../src/code-example/helpers/get-snippet.ts"],"sourcesContent":["import type { ErrorResponse } from '@scalar/helpers/errors/normalize-error'\nimport { type ClientId, type TargetId, snippetz } from '@scalar/snippetz'\nimport type { Request as HarRequest } from 'har-format'\n\n/** Key used to hack around the invalid urls */\nconst INVALID_URLS_PREFIX = 'ws://replace.me'\n\n/**\n * Returns a code example for given operation\n */\nexport const getSnippet = <T extends TargetId>(\n target: T | 'javascript',\n client: ClientId<T>,\n harRequest: HarRequest,\n): ErrorResponse<string> => {\n try {\n if (!harRequest.url) {\n return [new Error('Please enter a URL to see a code snippet'), null]\n }\n\n const separator = harRequest.url.startsWith('/') ? '' : '/'\n\n // Hack to get around invalid URLS until we update the snippets lib\n try {\n new URL(harRequest.url)\n } catch {\n harRequest.url = `${INVALID_URLS_PREFIX}${separator}${harRequest.url}`\n }\n\n // Ensure we have valid JSON\n if (harRequest.postData?.mimeType === 'application/json') {\n try {\n JSON.parse(harRequest.postData.text || '{}')\n } catch (error) {\n console.error('[getSnippet] Invalid JSON body', error)\n return [new Error('Invalid JSON body'), null]\n }\n }\n // TODO: Fix this, use js (instead of javascript) everywhere\n const snippetzTargetKey = target.replace('javascript', 'js') as TargetId\n\n if (snippetz().hasPlugin(snippetzTargetKey, client)) {\n const payload = snippetz().print(snippetzTargetKey, client, harRequest)\n if (!payload) {\n return [new Error('Error generating snippet'), null]\n }\n\n return [null, payload.replace(`${INVALID_URLS_PREFIX}${separator}`, '')]\n }\n } catch (error) {\n console.error('[getSnippet] Error generating snippet', error)\n return [new Error('Error generating snippet'), null]\n }\n\n return [new Error('No snippet found'), null]\n}\n"],"mappings":";;AAKA,IAAM,IAAsB,mBAKf,KACX,GACA,GACA,MAC0B;CAC1B,IAAI;EACF,IAAI,CAAC,EAAW,KACd,OAAO,CAAC,gBAAI,MAAM,0CAA0C,GAAG,IAAI;EAGrE,IAAM,IAAY,EAAW,IAAI,WAAW,GAAG,IAAI,KAAK;EAGxD,IAAI;GACF,IAAI,IAAI,EAAW,GAAG;EACxB,QAAQ;GACN,EAAW,MAAM,GAAG,IAAsB,IAAY,EAAW;EACnE;EAGA,IAAI,EAAW,UAAU,aAAa,oBACpC,IAAI;GACF,KAAK,MAAM,EAAW,SAAS,QAAQ,IAAI;EAC7C,SAAS,GAAO;GAEd,OADA,QAAQ,MAAM,kCAAkC,CAAK,GAC9C,CAAC,gBAAI,MAAM,mBAAmB,GAAG,IAAI;EAC9C;EAGF,IAAM,IAAoB,EAAO,QAAQ,cAAc,IAAI;EAE3D,IAAI,EAAS,CAAC,CAAC,UAAU,GAAmB,CAAM,GAAG;GACnD,IAAM,IAAU,EAAS,CAAC,CAAC,MAAM,GAAmB,GAAQ,CAAU;GAKtE,OAJK,IAIE,CAAC,MAAM,EAAQ,QAAQ,GAAG,IAAsB,KAAa,EAAE,CAAC,IAH9D,CAAC,gBAAI,MAAM,0BAA0B,GAAG,IAAI;EAIvD;CACF,SAAS,GAAO;EAEd,OADA,QAAQ,MAAM,yCAAyC,CAAK,GACrD,CAAC,gBAAI,MAAM,0BAA0B,GAAG,IAAI;CACrD;CAEA,OAAO,CAAC,gBAAI,MAAM,kBAAkB,GAAG,IAAI;AAC7C"}
1
+ {"version":3,"file":"get-snippet.js","names":["INVALID_URLS_PREFIX","getSnippet","harRequest","separator","error","snippetzTargetKey","target","snippetz","client","payload"],"sources":["../../../src/code-example/helpers/get-snippet.ts"],"sourcesContent":["import type { ErrorResponse } from '@scalar/helpers/errors/normalize-error'\nimport { type ClientId, type TargetId, snippetz } from '@scalar/snippetz'\nimport type { Request as HarRequest } from 'har-format'\n\n/** Key used to hack around the invalid urls */\nconst INVALID_URLS_PREFIX = 'ws://replace.me'\n\n/**\n * Returns a code example for given operation\n */\nexport const getSnippet = <T extends TargetId>(\n target: T | 'javascript',\n client: ClientId<T>,\n harRequest: HarRequest,\n): ErrorResponse<string> => {\n try {\n if (!harRequest.url) {\n return [new Error('Please enter a URL to see a code snippet'), null]\n }\n\n const separator = harRequest.url.startsWith('/') ? '' : '/'\n\n // Hack to get around invalid URLS until we update the snippets lib\n try {\n new URL(harRequest.url)\n } catch {\n harRequest.url = `${INVALID_URLS_PREFIX}${separator}${harRequest.url}`\n }\n\n // Ensure we have valid JSON\n if (harRequest.postData?.mimeType === 'application/json') {\n try {\n JSON.parse(harRequest.postData.text || '{}')\n } catch (error) {\n console.error('[getSnippet] Invalid JSON body', error)\n return [new Error('Invalid JSON body'), null]\n }\n }\n // TODO: Fix this, use js (instead of javascript) everywhere\n const snippetzTargetKey = target.replace('javascript', 'js') as TargetId\n\n if (snippetz().hasPlugin(snippetzTargetKey, client)) {\n const payload = snippetz().print(snippetzTargetKey, client, harRequest)\n if (!payload) {\n return [new Error('Error generating snippet'), null]\n }\n\n return [null, payload.replace(`${INVALID_URLS_PREFIX}${separator}`, '')]\n }\n } catch (error) {\n console.error('[getSnippet] Error generating snippet', error)\n return [new Error('Error generating snippet'), null]\n }\n\n return [new Error('No snippet found'), null]\n}\n"],"mappings":";;AAKA,IAAMA,IAAsB,mBAKfC,KACX,GACA,GACA,MAC0B;CAC1B,IAAI;EACF,IAAI,CAACC,EAAW,KACd,OAAO,CAAC,gBAAI,MAAM,0CAA0C,GAAG,IAAI;EAGrE,IAAMC,IAAYD,EAAW,IAAI,WAAW,GAAG,IAAI,KAAK;EAGxD,IAAI;GACF,IAAI,IAAIA,EAAW,GAAG;EACxB,QAAQ;GACN,EAAW,MAAM,GAAGF,IAAsBG,IAAYD,EAAW;EACnE;EAGA,IAAIA,EAAW,UAAU,aAAa,oBACpC,IAAI;GACF,KAAK,MAAMA,EAAW,SAAS,QAAQ,IAAI;EAC7C,SAASE,GAAO;GAEd,OADA,QAAQ,MAAM,kCAAkCA,CAAK,GAC9C,CAAC,gBAAI,MAAM,mBAAmB,GAAG,IAAI;EAC9C;EAGF,IAAMC,IAAoBC,EAAO,QAAQ,cAAc,IAAI;EAE3D,IAAIC,EAAS,CAAC,CAAC,UAAUF,GAAmBG,CAAM,GAAG;GACnD,IAAMC,IAAUF,EAAS,CAAC,CAAC,MAAMF,GAAmBG,GAAQN,CAAU;GAKtE,OAJKO,IAIE,CAAC,MAAMA,EAAQ,QAAQ,GAAGT,IAAsBG,KAAa,EAAE,CAAC,IAH9D,CAAC,gBAAI,MAAM,0BAA0B,GAAG,IAAI;EAIvD;CACF,SAASC,GAAO;EAEd,OADA,QAAQ,MAAM,yCAAyCA,CAAK,GACrD,CAAC,gBAAI,MAAM,0BAA0B,GAAG,IAAI;CACrD;CAEA,OAAO,CAAC,gBAAI,MAAM,kBAAkB,GAAG,IAAI;AAC7C"}
@@ -3,25 +3,25 @@ import { processBody as t } from "./process-body.js";
3
3
  import { processParameters as n } from "./process-parameters.js";
4
4
  import { processSecuritySchemes as r } from "./process-security-schemes.js";
5
5
  import { processServerUrl as i } from "./process-server-url.js";
6
- import { getResolvedRef as a } from "@scalar/workspace-store/helpers/get-resolved-ref";
7
- import { isElectron as o } from "@scalar/helpers/general/is-electron";
8
- import { filterGlobalCookie as s, getDefaultHeaders as c, restoreConventionalDefaultHeaderNames as l } from "@scalar/workspace-store/request-example";
6
+ import { filterGlobalCookie as a, getDefaultHeaders as o, restoreConventionalDefaultHeaderNames as s } from "@scalar/workspace-store/request-example";
7
+ import { getResolvedRef as c } from "@scalar/workspace-store/helpers/get-resolved-ref";
8
+ import { isElectron as l } from "@scalar/helpers/general/is-electron";
9
9
  //#region src/code-example/helpers/operation-to-har/operation-to-har.ts
10
10
  var u = ({ includeDefaultHeaders: u = !1, operation: d, contentType: f, method: p, path: m, server: h = null, example: g, securitySchemes: _, globalCookies: v, openapiVersion: y, requestBodyCompositionSelection: b, defaultDisabledParameters: x = !1 }) => {
11
- let S = l(u ? c({
11
+ let S = u ? o({
12
12
  method: p,
13
13
  operation: d,
14
14
  exampleName: g ?? "default",
15
15
  hideDisabledHeaders: !0,
16
16
  hideOverriddenHeaders: !0,
17
17
  options: {
18
- isElectron: o(),
18
+ isElectron: l(),
19
19
  appVersion: e
20
20
  }
21
- }) : {}), C = d["x-scalar-disable-parameters"]?.["global-cookies"]?.[g ?? "default"] ?? {}, w = {
21
+ }) : {}, C = s(S), w = d["x-scalar-disable-parameters"]?.["global-cookies"]?.[g ?? "default"] ?? {}, T = {
22
22
  method: p,
23
23
  url: i(h, m),
24
- headers: Object.entries(S).map(([e, t]) => ({
24
+ headers: Object.entries(C).map(([e, t]) => ({
25
25
  name: e,
26
26
  value: t
27
27
  })),
@@ -31,59 +31,59 @@ var u = ({ includeDefaultHeaders: u = !1, operation: d, contentType: f, method:
31
31
  cookies: [],
32
32
  headersSize: -1,
33
33
  bodySize: -1
34
- }, T = !1, E = !1;
34
+ }, E = !1, D = !1;
35
35
  if (d.parameters) {
36
- let { url: e, headers: t, queryString: r, cookies: i, hasCookieStyleEntries: a, hasSerializedQuery: o } = n({
37
- harRequest: w,
36
+ let { url: e, headers: t, queryString: r, cookies: i, hasCookieStyleEntries: o, hasSerializedQuery: s } = n({
37
+ harRequest: T,
38
38
  parameters: d.parameters,
39
39
  openapiVersion: y,
40
40
  example: g,
41
41
  defaultDisabled: x
42
- }), c = v?.filter((t) => s({
42
+ }), c = v?.filter((t) => a({
43
43
  cookie: t,
44
44
  url: e,
45
- disabledGlobalCookies: C
45
+ disabledGlobalCookies: w
46
46
  }))?.map((e) => ({
47
47
  name: e.name,
48
48
  value: e.value
49
49
  })) ?? [];
50
- T = a, E = o ?? !1, w.url = e, w.headers = t, w.queryString = r, w.cookies = [...c, ...i];
50
+ E = o, D = s ?? !1, T.url = e, T.headers = t, T.queryString = r, T.cookies = [...c, ...i];
51
51
  }
52
- let D = a(d.requestBody);
53
- if (D?.content) {
52
+ let O = c(d.requestBody);
53
+ if (O?.content) {
54
54
  let e = t({
55
- requestBody: D,
55
+ requestBody: O,
56
56
  contentType: f,
57
57
  example: g,
58
58
  openapiVersion: y,
59
59
  requestBodyCompositionSelection: b
60
60
  });
61
- if (e && (w.postData = e, w.bodySize = e.text?.length ?? -1, e.mimeType)) {
62
- let t = w.headers.find((e) => e.name.toLowerCase() === "content-type");
63
- t && (!t.value || e.mimeType.startsWith("multipart/") && e.mimeType.includes("boundary=") && e.text !== void 0) ? t.value = e.mimeType : t || w.headers.push({
61
+ if (e && (T.postData = e, T.bodySize = e.text?.length ?? -1, e.mimeType)) {
62
+ let t = T.headers.find((e) => e.name.toLowerCase() === "content-type");
63
+ t && (!t.value || e.mimeType.startsWith("multipart/") && e.mimeType.includes("boundary=") && e.text !== void 0) ? t.value = e.mimeType : t || T.headers.push({
64
64
  name: "Content-Type",
65
65
  value: e.mimeType
66
66
  });
67
67
  }
68
68
  }
69
- let O = E || d.parameters?.some((e) => a(e)?.in === "querystring");
69
+ let k = D || d.parameters?.some((e) => c(e)?.in === "querystring");
70
70
  if (_) {
71
71
  let { headers: e, queryString: t, cookies: n } = r(_);
72
- w.headers.push(...e), w.queryString.push(...t), w.cookies.push(...n);
72
+ T.headers.push(...e), T.queryString.push(...t), T.cookies.push(...n);
73
73
  }
74
- let k = w.headers.find((e) => e.name.toLowerCase() === "cookie");
75
- if (T && k && w.cookies.length) {
76
- let e = w.cookies.map((e) => `${encodeURIComponent(e.name)}=${encodeURIComponent(e.value)}`).join("; ");
77
- k.value = k.value ? `${k.value}; ${e}` : e, w.cookies = [];
74
+ let A = T.headers.find((e) => e.name.toLowerCase() === "cookie");
75
+ if (E && A && T.cookies.length) {
76
+ let e = T.cookies.map((e) => `${encodeURIComponent(e.name)}=${encodeURIComponent(e.value)}`).join("; ");
77
+ A.value = A.value ? `${A.value}; ${e}` : e, T.cookies = [];
78
78
  }
79
- if (O && w.queryString.length) {
80
- let e = w.url.indexOf("#"), t = e === -1 ? "" : w.url.slice(e), n = e === -1 ? w.url : w.url.slice(0, e), r = w.queryString.map(({ name: e, value: t }) => `${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&");
81
- w.url = `${n}${n.includes("?") ? "&" : "?"}${r}${t}`, w.queryString = [];
79
+ if (k && T.queryString.length) {
80
+ let e = T.url.indexOf("#"), t = e === -1 ? "" : T.url.slice(e), n = e === -1 ? T.url : T.url.slice(0, e), r = T.queryString.map(({ name: e, value: t }) => `${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&");
81
+ T.url = `${n}${n.includes("?") ? "&" : "?"}${r}${t}`, T.queryString = [];
82
82
  }
83
- w.postData?.mimeType === "multipart/form-data" && w.postData.params?.some((e) => e.fileName !== void 0) && (w.headers = w.headers.filter((e) => e.name.toLowerCase() !== "content-type"));
84
- let A = 0;
85
- for (let e of w.headers) A += (e.name?.length ?? 0) + 2 + (e.value?.length ?? 0) + 2;
86
- return w.headersSize = A, w;
83
+ T.postData?.mimeType === "multipart/form-data" && T.postData.params?.some((e) => e.fileName !== void 0) && (T.headers = T.headers.filter((e) => e.name.toLowerCase() !== "content-type"));
84
+ let j = 0;
85
+ for (let e of T.headers) j += (e.name?.length ?? 0) + 2 + (e.value?.length ?? 0) + 2;
86
+ return T.headersSize = j, T;
87
87
  };
88
88
  //#endregion
89
89
  export { u as operationToHar };
@@ -1 +1 @@
1
- {"version":3,"file":"operation-to-har.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/operation-to-har.ts"],"sourcesContent":["import { isElectron } from '@scalar/helpers/general/is-electron'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n type SecuritySchemeObjectSecret,\n filterGlobalCookie,\n getDefaultHeaders,\n restoreConventionalDefaultHeaderNames,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport type { Request as HarRequest } from 'har-format'\n\nimport { APP_VERSION } from '@/constants'\n\nimport { processBody } from './process-body'\nimport { processParameters } from './process-parameters'\nimport { processSecuritySchemes } from './process-security-schemes'\nimport { processServerUrl } from './process-server-url'\n\nexport type OperationToHarProps = {\n /** OpenAPI Operation object */\n operation: OperationObject\n /** HTTP method of the operation */\n method: string\n /** Path of the operation */\n path: string\n /**\n * Name of the currently selected operation example\n *\n * Applies to both the body and the parameters\n */\n example?: string\n /**\n * Content type of the operation\n *\n * Applies to both the body and the parameters (if applicable)\n * @defaults to the first content type in the MediaTypeObject\n */\n contentType?: string\n /** OpenAPI Server object */\n server?: ServerObject | null\n /** OpenAPI SecurityScheme objects which are applicable to the operation */\n securitySchemes?: SecuritySchemeObjectSecret[]\n /** Workspace + document cookies */\n globalCookies?: XScalarCookie[]\n /**\n * Whether to include default headers (e.g., Accept, Content-Type) automatically.\n * If false, default headers will be omitted from the HAR request.\n * @default true\n */\n includeDefaultHeaders?: boolean\n /**\n * Selected oneOf/anyOf variants for nested request body example generation\n * (e.g. from the schema dropdowns in the API reference).\n */\n /** Originating OpenAPI version, used for version-specific serialization. */\n openapiVersion?: string\n requestBodyCompositionSelection?: Record<string, number>\n /**\n * Whether to disable parameters by default.\n * @default false\n */\n defaultDisabledParameters?: boolean\n}\n\n/**\n * Converts an OpenAPI Operation to a HarRequest format for generating HTTP request snippets.\n *\n * This function transforms OpenAPI 3.1 operation objects into HAR (HTTP Archive) format requests,\n * which can be used to generate code snippets for various programming languages and HTTP clients.\n *\n * The conversion handles:\n * - Server URL processing and path parameter substitution\n * - Query parameter formatting based on OpenAPI parameter styles\n * - Request body processing with content type handling\n * - Security scheme integration (API keys, etc.)\n *\n * The resulting HarRequest object follows the HAR specification and includes:\n * - HTTP method and URL\n * - Headers and query parameters\n * - Request body (if present)\n * - Cookie information\n * - Size calculations for headers and body\n *\n * @see https://w3c.github.io/web-performance/specs/HAR/Overview.html\n * @see https://spec.openapis.org/oas/v3.1.0#operation-object\n */\nexport const operationToHar = ({\n includeDefaultHeaders = false,\n operation,\n contentType,\n method,\n path,\n server = null,\n example,\n securitySchemes,\n globalCookies,\n openapiVersion,\n requestBodyCompositionSelection,\n defaultDisabledParameters = false,\n}: OperationToHarProps): HarRequest => {\n const defaultHeaders = includeDefaultHeaders\n ? getDefaultHeaders({\n method,\n operation,\n exampleName: example ?? 'default',\n hideDisabledHeaders: true,\n hideOverriddenHeaders: true,\n options: { isElectron: isElectron(), appVersion: APP_VERSION },\n })\n : {}\n const defaultHeadersWithConventionalNames = restoreConventionalDefaultHeaderNames(defaultHeaders)\n\n const disabledGlobalCookies =\n operation['x-scalar-disable-parameters']?.['global-cookies']?.[example ?? 'default'] ?? {}\n\n const serverUrl = processServerUrl(server, path)\n\n // Initialize the HAR request with basic properties\n const harRequest: HarRequest = {\n method,\n url: serverUrl,\n headers: Object.entries(defaultHeadersWithConventionalNames).map(([name, value]) => ({ name, value })),\n queryString: [],\n postData: undefined,\n httpVersion: 'HTTP/1.1',\n cookies: [],\n headersSize: -1,\n bodySize: -1,\n }\n\n let hasCookieStyleEntries = false\n let hasSerializedQuery = false\n\n // Handle parameters\n if (operation.parameters) {\n const {\n url,\n headers,\n queryString,\n cookies,\n hasCookieStyleEntries: processedCookieStyleEntries,\n hasSerializedQuery: processedSerializedQuery,\n } = processParameters({\n harRequest,\n parameters: operation.parameters,\n openapiVersion,\n example,\n defaultDisabled: defaultDisabledParameters,\n })\n\n // Correctly filter the global cookies by the processed url\n const filteredGlobalCookies =\n globalCookies\n ?.filter((cookie) => filterGlobalCookie({ cookie, url, disabledGlobalCookies }))\n ?.map((cookie) => ({ name: cookie.name, value: cookie.value })) ?? []\n\n hasCookieStyleEntries = processedCookieStyleEntries\n hasSerializedQuery = processedSerializedQuery ?? false\n harRequest.url = url\n harRequest.headers = headers\n harRequest.queryString = queryString\n harRequest.cookies = [...filteredGlobalCookies, ...cookies]\n }\n\n const body = getResolvedRef(operation.requestBody)\n\n // Handle request body\n if (body?.content) {\n const postData = processBody({\n requestBody: body,\n contentType,\n example,\n openapiVersion,\n requestBodyCompositionSelection,\n })\n\n if (postData) {\n harRequest.postData = postData\n harRequest.bodySize = postData.text?.length ?? -1\n\n // Add or update Content-Type header\n if (postData.mimeType) {\n const existingContentTypeHeader = harRequest.headers.find(\n (header) => header.name.toLowerCase() === 'content-type',\n )\n // Update existing header if it has an empty value\n if (\n existingContentTypeHeader &&\n (!existingContentTypeHeader.value ||\n (postData.mimeType.startsWith('multipart/') &&\n postData.mimeType.includes('boundary=') &&\n postData.text !== undefined))\n ) {\n existingContentTypeHeader.value = postData.mimeType\n }\n // Add new header if none exists\n else if (!existingContentTypeHeader) {\n harRequest.headers.push({\n name: 'Content-Type',\n value: postData.mimeType,\n })\n }\n }\n }\n }\n\n const hasUriReadyQuery =\n hasSerializedQuery || operation.parameters?.some((parameter) => getResolvedRef(parameter)?.in === 'querystring')\n\n // Handle security schemes\n if (securitySchemes) {\n const { headers, queryString, cookies } = processSecuritySchemes(securitySchemes)\n harRequest.headers.push(...headers)\n harRequest.queryString.push(...queryString)\n harRequest.cookies.push(...cookies)\n }\n\n // Keep authentication and global cookies in the explicit header as well, so\n // snippet generators cannot replace cookie-style parameters with their own header.\n const cookieHeader = harRequest.headers.find((header) => header.name.toLowerCase() === 'cookie')\n if (hasCookieStyleEntries && cookieHeader && harRequest.cookies.length) {\n const extraCookies = harRequest.cookies\n .map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`)\n .join('; ')\n cookieHeader.value = cookieHeader.value ? `${cookieHeader.value}; ${extraCookies}` : extraCookies\n harRequest.cookies = []\n }\n\n // Whole-query content and serialized examples must retain their authored URI encoding.\n // Keeping all query data in the URL avoids snippet generators introducing a second question mark.\n if (hasUriReadyQuery && harRequest.queryString.length) {\n const hashIndex = harRequest.url.indexOf('#')\n const hash = hashIndex === -1 ? '' : harRequest.url.slice(hashIndex)\n const url = hashIndex === -1 ? harRequest.url : harRequest.url.slice(0, hashIndex)\n const query = harRequest.queryString\n .map(({ name, value }) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`)\n .join('&')\n harRequest.url = `${url}${url.includes('?') ? '&' : '?'}${query}${hash}`\n harRequest.queryString = []\n }\n\n // Multipart file parts are encoded by the HTTP client, which owns the boundary.\n // Raw multipart text already has its boundary and must retain its Content-Type.\n if (\n harRequest.postData?.mimeType === 'multipart/form-data' &&\n harRequest.postData.params?.some((param) => param.fileName !== undefined)\n ) {\n harRequest.headers = harRequest.headers.filter((header) => header.name.toLowerCase() !== 'content-type')\n }\n\n // Calculate headers size without allocating a large joined string\n let headersSize = 0\n for (const h of harRequest.headers) {\n // name + \": \" + value + \"\\r\\n\"\n headersSize += (h.name?.length ?? 0) + 2 + (h.value?.length ?? 0) + 2\n }\n harRequest.headersSize = headersSize\n\n return harRequest\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"operation-to-har.js","names":["operationToHar","defaultHeaders","includeDefaultHeaders","getDefaultHeaders","example","isElectron","APP_VERSION","defaultHeadersWithConventionalNames","restoreConventionalDefaultHeaderNames","disabledGlobalCookies","operation","harRequest","processServerUrl","server","path","name","value","hasCookieStyleEntries","hasSerializedQuery","processedCookieStyleEntries","processedSerializedQuery","processParameters","defaultDisabledParameters","filteredGlobalCookies","globalCookies","filterGlobalCookie","cookie","url","headers","queryString","cookies","body","getResolvedRef","postData","processBody","existingContentTypeHeader","header","hasUriReadyQuery","parameter","securitySchemes","processSecuritySchemes","cookieHeader","extraCookies","hashIndex","hash","query","param","headersSize","h"],"sources":["../../../../src/code-example/helpers/operation-to-har/operation-to-har.ts"],"sourcesContent":["import { isElectron } from '@scalar/helpers/general/is-electron'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n type SecuritySchemeObjectSecret,\n filterGlobalCookie,\n getDefaultHeaders,\n restoreConventionalDefaultHeaderNames,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport type { Request as HarRequest } from 'har-format'\n\nimport { APP_VERSION } from '@/constants'\n\nimport { processBody } from './process-body'\nimport { processParameters } from './process-parameters'\nimport { processSecuritySchemes } from './process-security-schemes'\nimport { processServerUrl } from './process-server-url'\n\nexport type OperationToHarProps = {\n /** OpenAPI Operation object */\n operation: OperationObject\n /** HTTP method of the operation */\n method: string\n /** Path of the operation */\n path: string\n /**\n * Name of the currently selected operation example\n *\n * Applies to both the body and the parameters\n */\n example?: string\n /**\n * Content type of the operation\n *\n * Applies to both the body and the parameters (if applicable)\n * @defaults to the first content type in the MediaTypeObject\n */\n contentType?: string\n /** OpenAPI Server object */\n server?: ServerObject | null\n /** OpenAPI SecurityScheme objects which are applicable to the operation */\n securitySchemes?: SecuritySchemeObjectSecret[]\n /** Workspace + document cookies */\n globalCookies?: XScalarCookie[]\n /**\n * Whether to include default headers (e.g., Accept, Content-Type) automatically.\n * If false, default headers will be omitted from the HAR request.\n * @default true\n */\n includeDefaultHeaders?: boolean\n /**\n * Selected oneOf/anyOf variants for nested request body example generation\n * (e.g. from the schema dropdowns in the API reference).\n */\n /** Originating OpenAPI version, used for version-specific serialization. */\n openapiVersion?: string\n requestBodyCompositionSelection?: Record<string, number>\n /**\n * Whether to disable parameters by default.\n * @default false\n */\n defaultDisabledParameters?: boolean\n}\n\n/**\n * Converts an OpenAPI Operation to a HarRequest format for generating HTTP request snippets.\n *\n * This function transforms OpenAPI 3.1 operation objects into HAR (HTTP Archive) format requests,\n * which can be used to generate code snippets for various programming languages and HTTP clients.\n *\n * The conversion handles:\n * - Server URL processing and path parameter substitution\n * - Query parameter formatting based on OpenAPI parameter styles\n * - Request body processing with content type handling\n * - Security scheme integration (API keys, etc.)\n *\n * The resulting HarRequest object follows the HAR specification and includes:\n * - HTTP method and URL\n * - Headers and query parameters\n * - Request body (if present)\n * - Cookie information\n * - Size calculations for headers and body\n *\n * @see https://w3c.github.io/web-performance/specs/HAR/Overview.html\n * @see https://spec.openapis.org/oas/v3.1.0#operation-object\n */\nexport const operationToHar = ({\n includeDefaultHeaders = false,\n operation,\n contentType,\n method,\n path,\n server = null,\n example,\n securitySchemes,\n globalCookies,\n openapiVersion,\n requestBodyCompositionSelection,\n defaultDisabledParameters = false,\n}: OperationToHarProps): HarRequest => {\n const defaultHeaders = includeDefaultHeaders\n ? getDefaultHeaders({\n method,\n operation,\n exampleName: example ?? 'default',\n hideDisabledHeaders: true,\n hideOverriddenHeaders: true,\n options: { isElectron: isElectron(), appVersion: APP_VERSION },\n })\n : {}\n const defaultHeadersWithConventionalNames = restoreConventionalDefaultHeaderNames(defaultHeaders)\n\n const disabledGlobalCookies =\n operation['x-scalar-disable-parameters']?.['global-cookies']?.[example ?? 'default'] ?? {}\n\n const serverUrl = processServerUrl(server, path)\n\n // Initialize the HAR request with basic properties\n const harRequest: HarRequest = {\n method,\n url: serverUrl,\n headers: Object.entries(defaultHeadersWithConventionalNames).map(([name, value]) => ({ name, value })),\n queryString: [],\n postData: undefined,\n httpVersion: 'HTTP/1.1',\n cookies: [],\n headersSize: -1,\n bodySize: -1,\n }\n\n let hasCookieStyleEntries = false\n let hasSerializedQuery = false\n\n // Handle parameters\n if (operation.parameters) {\n const {\n url,\n headers,\n queryString,\n cookies,\n hasCookieStyleEntries: processedCookieStyleEntries,\n hasSerializedQuery: processedSerializedQuery,\n } = processParameters({\n harRequest,\n parameters: operation.parameters,\n openapiVersion,\n example,\n defaultDisabled: defaultDisabledParameters,\n })\n\n // Correctly filter the global cookies by the processed url\n const filteredGlobalCookies =\n globalCookies\n ?.filter((cookie) => filterGlobalCookie({ cookie, url, disabledGlobalCookies }))\n ?.map((cookie) => ({ name: cookie.name, value: cookie.value })) ?? []\n\n hasCookieStyleEntries = processedCookieStyleEntries\n hasSerializedQuery = processedSerializedQuery ?? false\n harRequest.url = url\n harRequest.headers = headers\n harRequest.queryString = queryString\n harRequest.cookies = [...filteredGlobalCookies, ...cookies]\n }\n\n const body = getResolvedRef(operation.requestBody)\n\n // Handle request body\n if (body?.content) {\n const postData = processBody({\n requestBody: body,\n contentType,\n example,\n openapiVersion,\n requestBodyCompositionSelection,\n })\n\n if (postData) {\n harRequest.postData = postData\n harRequest.bodySize = postData.text?.length ?? -1\n\n // Add or update Content-Type header\n if (postData.mimeType) {\n const existingContentTypeHeader = harRequest.headers.find(\n (header) => header.name.toLowerCase() === 'content-type',\n )\n // Update existing header if it has an empty value\n if (\n existingContentTypeHeader &&\n (!existingContentTypeHeader.value ||\n (postData.mimeType.startsWith('multipart/') &&\n postData.mimeType.includes('boundary=') &&\n postData.text !== undefined))\n ) {\n existingContentTypeHeader.value = postData.mimeType\n }\n // Add new header if none exists\n else if (!existingContentTypeHeader) {\n harRequest.headers.push({\n name: 'Content-Type',\n value: postData.mimeType,\n })\n }\n }\n }\n }\n\n const hasUriReadyQuery =\n hasSerializedQuery || operation.parameters?.some((parameter) => getResolvedRef(parameter)?.in === 'querystring')\n\n // Handle security schemes\n if (securitySchemes) {\n const { headers, queryString, cookies } = processSecuritySchemes(securitySchemes)\n harRequest.headers.push(...headers)\n harRequest.queryString.push(...queryString)\n harRequest.cookies.push(...cookies)\n }\n\n // Keep authentication and global cookies in the explicit header as well, so\n // snippet generators cannot replace cookie-style parameters with their own header.\n const cookieHeader = harRequest.headers.find((header) => header.name.toLowerCase() === 'cookie')\n if (hasCookieStyleEntries && cookieHeader && harRequest.cookies.length) {\n const extraCookies = harRequest.cookies\n .map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`)\n .join('; ')\n cookieHeader.value = cookieHeader.value ? `${cookieHeader.value}; ${extraCookies}` : extraCookies\n harRequest.cookies = []\n }\n\n // Whole-query content and serialized examples must retain their authored URI encoding.\n // Keeping all query data in the URL avoids snippet generators introducing a second question mark.\n if (hasUriReadyQuery && harRequest.queryString.length) {\n const hashIndex = harRequest.url.indexOf('#')\n const hash = hashIndex === -1 ? '' : harRequest.url.slice(hashIndex)\n const url = hashIndex === -1 ? harRequest.url : harRequest.url.slice(0, hashIndex)\n const query = harRequest.queryString\n .map(({ name, value }) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`)\n .join('&')\n harRequest.url = `${url}${url.includes('?') ? '&' : '?'}${query}${hash}`\n harRequest.queryString = []\n }\n\n // Multipart file parts are encoded by the HTTP client, which owns the boundary.\n // Raw multipart text already has its boundary and must retain its Content-Type.\n if (\n harRequest.postData?.mimeType === 'multipart/form-data' &&\n harRequest.postData.params?.some((param) => param.fileName !== undefined)\n ) {\n harRequest.headers = harRequest.headers.filter((header) => header.name.toLowerCase() !== 'content-type')\n }\n\n // Calculate headers size without allocating a large joined string\n let headersSize = 0\n for (const h of harRequest.headers) {\n // name + \": \" + value + \"\\r\\n\"\n headersSize += (h.name?.length ?? 0) + 2 + (h.value?.length ?? 0) + 2\n }\n harRequest.headersSize = headersSize\n\n return harRequest\n}\n"],"mappings":"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"}
@@ -1,9 +1,9 @@
1
- import { getResolvedRef as e, mergeSiblingReferences as t } from "@scalar/workspace-store/helpers/get-resolved-ref";
2
- import { buildRequestBody as n, coerceLeafValueToSchemaType as r, getExample as i, getExampleFromBody as a, getExampleFromSchema as o, needsMultipartEncoding as s, resolveLeafSchema as c, serializeFormPropertyWithEncoding as l, serializeMultipartArray as u, serializeMultipartBody as d } from "@scalar/workspace-store/request-example";
3
- import { isXmlMediaType as f } from "@scalar/helpers/http/is-xml-media-type";
4
- import { getExampleValue as p, getExplicitExampleText as m } from "@scalar/workspace-store/helpers/get-example-value";
5
- import { serializeStreamExample as h } from "@scalar/workspace-store/helpers/serialize-stream-example";
6
- import { snapshotSchema as g } from "@scalar/workspace-store/helpers/snapshot-schema";
1
+ import { snapshotSchema as e } from "@scalar/workspace-store/helpers/snapshot-schema";
2
+ import { buildRequestBody as t, coerceLeafValueToSchemaType as n, getExample as r, getExampleFromBody as i, getExampleFromSchema as a, needsMultipartEncoding as o, resolveLeafSchema as s, serializeFormPropertyWithEncoding as c, serializeMultipartArray as l, serializeMultipartBody as u } from "@scalar/workspace-store/request-example";
3
+ import { isXmlMediaType as d } from "@scalar/helpers/http/is-xml-media-type";
4
+ import { getResolvedRef as f, mergeSiblingReferences as p } from "@scalar/workspace-store/helpers/get-resolved-ref";
5
+ import { getExampleValue as m, getExplicitExampleText as h } from "@scalar/workspace-store/helpers/get-example-value";
6
+ import { serializeStreamExample as g } from "@scalar/workspace-store/helpers/serialize-stream-example";
7
7
  import { unpackProxyObject as _ } from "@scalar/workspace-store/helpers/unpack-proxy";
8
8
  //#region src/code-example/helpers/operation-to-har/process-body.ts
9
9
  var v = (e, t, n) => ({
@@ -11,29 +11,23 @@ var v = (e, t, n) => ({
11
11
  value: `@${t}`,
12
12
  fileName: t,
13
13
  ...n ? { contentType: n } : {}
14
- }), y = (e) => !!e && "type" in e && e.type === "string" && "format" in e && e.format === "binary", b = (e, t) => typeof e == "string" && e.startsWith("@") && y(t) ? e.slice(1) : void 0, x = (e, t, n, i = !1, a) => {
15
- let o = [], s = Array.isArray(e) ? e.filter((e) => !e.isDisabled).map((e) => [String(e.name), e.value]) : Object.entries(e);
16
- for (let [d, f] of s) {
14
+ }), y = (e) => !!e && "type" in e && e.type === "string" && "format" in e && e.format === "binary", b = (e, t) => typeof e == "string" && e.startsWith("@") && y(t) ? e.slice(1) : void 0, x = (e, t, r, i = !1, a) => {
15
+ let o = [], u = Array.isArray(e) ? e.filter((e) => !e.isDisabled).map((e) => [String(e.name), e.value]) : Object.entries(e);
16
+ for (let [d, f] of u) {
17
17
  if (f == null) continue;
18
- let s = n ? void 0 : t?.[d];
19
- if (i && !n) {
20
- let t = Array.isArray(e) ? r(f, c(a, [d])) : f, n = u(d, Array.isArray(t) ? t : f, s);
21
- if (n) {
22
- for (let e of n) {
23
- if (e.value instanceof File) {
24
- o.push(v(e.key, e.value.name, e.contentType ?? e.value.type));
25
- continue;
26
- }
27
- o.push({
28
- name: e.key,
29
- value: e.value,
30
- ...e.contentType ? { contentType: e.contentType } : {}
31
- });
32
- }
18
+ let u = r ? void 0 : t?.[d];
19
+ if (i && !r) {
20
+ let t = Array.isArray(e) ? n(f, s(a, [d])) : f, r = l(d, Array.isArray(t) ? t : f, u);
21
+ if (r) {
22
+ for (let e of r) e.value instanceof File ? o.push(v(e.key, e.value.name, e.contentType ?? e.value.type)) : o.push({
23
+ name: e.key,
24
+ value: e.value,
25
+ ...e.contentType ? { contentType: e.contentType } : {}
26
+ });
33
27
  continue;
34
28
  }
35
29
  }
36
- let p = s && (s.style !== void 0 || s.explode !== void 0 || s.allowReserved !== void 0), m = p || !i ? void 0 : s?.contentType, h = i && !n ? b(f, c(a, [d])) : void 0, g = n ? null : l(d, f, s);
30
+ let p = u && (u.style !== void 0 || u.explode !== void 0 || u.allowReserved !== void 0), m = p || !i ? void 0 : u?.contentType, h = i && !r ? b(f, s(a, [d])) : void 0, g = r ? null : c(d, f, u);
37
31
  if (g) for (let e of g) o.push({
38
32
  name: e.key,
39
33
  value: e.value
@@ -47,7 +41,7 @@ var v = (e, t, n) => ({
47
41
  value: JSON.stringify(_(f)),
48
42
  contentType: m
49
43
  });
50
- else if (i && !n && !p && typeof f == "object" && !Array.isArray(f)) o.push({
44
+ else if (i && !r && !p && typeof f == "object" && !Array.isArray(f)) o.push({
51
45
  name: d,
52
46
  value: JSON.stringify(_(f)),
53
47
  contentType: "application/json"
@@ -72,15 +66,15 @@ var v = (e, t, n) => ({
72
66
  });
73
67
  }
74
68
  return o;
75
- }, S = ({ requestBody: r, contentType: c, example: l, openapiVersion: u, requestBodyCompositionSelection: v }) => {
76
- let y = c || Object.keys(r.content)[0] || "", b = y === "other" ? "" : y, S = (e) => `@${_(e).name || "filename"}`, C = r.content[y]?.encoding, w = r.content[y];
77
- if (w && s(y, w)) {
78
- let e = l ?? Object.keys(w.examples ?? {})[0] ?? "default", t = n({
79
- ...r,
69
+ }, S = ({ requestBody: n, contentType: s, example: c, openapiVersion: l, requestBodyCompositionSelection: v }) => {
70
+ let y = s || Object.keys(n.content)[0] || "", b = y === "other" ? "" : y, S = (e) => `@${_(e).name || "filename"}`, C = n.content[y]?.encoding, w = n.content[y];
71
+ if (w && o(y, w)) {
72
+ let e = c ?? Object.keys(w.examples ?? {})[0] ?? "default", r = t({
73
+ ...n,
80
74
  "x-scalar-selected-content-type": { [e]: y }
81
75
  }, e, v);
82
- if (t?.mode === "multipart") {
83
- let e = d(t.value, t.contentType);
76
+ if (r?.mode === "multipart") {
77
+ let e = u(r.value, r.contentType);
84
78
  return {
85
79
  mimeType: e.contentType,
86
80
  text: e.chunks.map((e) => e instanceof File ? S(e) : e instanceof Blob ? "BINARY" : String(e)).join("")
@@ -88,45 +82,45 @@ var v = (e, t, n) => ({
88
82
  }
89
83
  }
90
84
  let T = y === "multipart/form-data" || y === "application/x-www-form-urlencoded";
91
- if (f(y)) {
92
- let e = a(r, y, l ?? "", v, u);
85
+ if (d(y)) {
86
+ let e = i(n, y, c ?? "", v, l);
93
87
  return e ? {
94
88
  mimeType: b,
95
89
  text: e.value
96
90
  } : void 0;
97
91
  }
98
- let E = p(i(r, l, c)), D = m(E, y);
92
+ let E = m(r(n, c, s)), D = h(E, y);
99
93
  if (D !== void 0) return {
100
94
  mimeType: b,
101
95
  text: D
102
96
  };
103
97
  let O = E?.value;
104
98
  if (O !== void 0) {
105
- let n = typeof O == "object" && O ? _(O) : O;
106
- return T && typeof n == "object" && n ? {
99
+ let e = typeof O == "object" && O ? _(O) : O;
100
+ return T && typeof e == "object" && e ? {
107
101
  mimeType: b,
108
- params: x(n, C, void 0, y === "multipart/form-data", e(r.content[y]?.schema, t))
109
- } : n instanceof File ? {
102
+ params: x(e, C, void 0, y === "multipart/form-data", f(n.content[y]?.schema, p))
103
+ } : e instanceof File ? {
110
104
  mimeType: b,
111
- text: S(n)
105
+ text: S(e)
112
106
  } : {
113
107
  mimeType: b,
114
- text: typeof n == "string" ? n : h(n, y, !1) ?? JSON.stringify(n)
108
+ text: typeof e == "string" ? e : g(e, y, !1) ?? JSON.stringify(e)
115
109
  };
116
110
  }
117
- let k = r.content[y], A = e(k?.schema ?? k?.itemSchema);
111
+ let k = n.content[y], A = f(k?.schema ?? k?.itemSchema);
118
112
  if (A !== void 0) {
119
- let e = o(g(A), {
113
+ let t = a(e(A), {
120
114
  compositionSelection: v,
121
115
  mode: "write",
122
116
  binaryAsFile: y === "multipart/form-data"
123
117
  }, { schemaPath: ["requestBody"] });
124
- if (e !== void 0) return T && typeof e == "object" && e ? {
118
+ if (t !== void 0) return T && typeof t == "object" && t ? {
125
119
  mimeType: b,
126
- params: x(e, C, void 0, y === "multipart/form-data", A)
120
+ params: x(t, C, void 0, y === "multipart/form-data", A)
127
121
  } : {
128
122
  mimeType: b,
129
- text: h(e, y, k?.schema === void 0) ?? (typeof e == "string" ? e : JSON.stringify(e))
123
+ text: g(t, y, k?.schema === void 0) ?? (typeof t == "string" ? t : JSON.stringify(t))
130
124
  };
131
125
  }
132
126
  };