@scalar/snippetz 0.2.7 → 0.2.9

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 (318) hide show
  1. package/dist/clients.d.ts +6 -0
  2. package/dist/clients.d.ts.map +1 -0
  3. package/dist/clients.js +150 -0
  4. package/dist/httpsnippet-lite/esm/helpers/code-builder.d.ts +8 -0
  5. package/dist/httpsnippet-lite/esm/helpers/code-builder.d.ts.map +1 -0
  6. package/dist/httpsnippet-lite/esm/helpers/code-builder.js +62 -0
  7. package/dist/httpsnippet-lite/esm/helpers/escape.d.ts +29 -0
  8. package/dist/httpsnippet-lite/esm/helpers/escape.d.ts.map +1 -0
  9. package/dist/httpsnippet-lite/esm/helpers/escape.js +74 -0
  10. package/dist/httpsnippet-lite/esm/helpers/form-data.d.ts +3 -0
  11. package/dist/httpsnippet-lite/esm/helpers/form-data.d.ts.map +1 -0
  12. package/dist/httpsnippet-lite/esm/helpers/headers.d.ts +17 -0
  13. package/dist/httpsnippet-lite/esm/helpers/headers.d.ts.map +1 -0
  14. package/dist/httpsnippet-lite/esm/helpers/headers.js +22 -0
  15. package/dist/httpsnippet-lite/esm/helpers/reducer.d.ts +2 -0
  16. package/dist/httpsnippet-lite/esm/helpers/reducer.d.ts.map +1 -0
  17. package/dist/httpsnippet-lite/esm/helpers/shell.d.ts +7 -0
  18. package/dist/httpsnippet-lite/esm/helpers/shell.d.ts.map +1 -0
  19. package/dist/httpsnippet-lite/esm/helpers/shell.js +18 -0
  20. package/dist/httpsnippet-lite/esm/helpers/url.d.ts +5 -0
  21. package/dist/httpsnippet-lite/esm/helpers/url.d.ts.map +1 -0
  22. package/dist/httpsnippet-lite/esm/helpers/utils.d.ts +3 -0
  23. package/dist/httpsnippet-lite/esm/helpers/utils.d.ts.map +1 -0
  24. package/dist/httpsnippet-lite/esm/httpsnippet.d.ts +10 -0
  25. package/dist/httpsnippet-lite/esm/httpsnippet.d.ts.map +1 -0
  26. package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.d.ts +16 -0
  27. package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.d.ts.map +1 -0
  28. package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js +45 -0
  29. package/dist/httpsnippet-lite/esm/targets/c/target.d.ts +26 -0
  30. package/dist/httpsnippet-lite/esm/targets/c/target.d.ts.map +1 -0
  31. package/dist/httpsnippet-lite/esm/targets/clojure/clj_http/client.d.ts +16 -0
  32. package/dist/httpsnippet-lite/esm/targets/clojure/clj_http/client.d.ts.map +1 -0
  33. package/dist/httpsnippet-lite/esm/targets/clojure/clj_http/client.js +189 -0
  34. package/dist/httpsnippet-lite/esm/targets/clojure/target.d.ts +26 -0
  35. package/dist/httpsnippet-lite/esm/targets/clojure/target.d.ts.map +1 -0
  36. package/dist/httpsnippet-lite/esm/targets/csharp/httpclient/client.d.ts +15 -0
  37. package/dist/httpsnippet-lite/esm/targets/csharp/httpclient/client.d.ts.map +1 -0
  38. package/dist/httpsnippet-lite/esm/targets/csharp/httpclient/client.js +169 -0
  39. package/dist/httpsnippet-lite/esm/targets/csharp/restsharp/client.d.ts +17 -0
  40. package/dist/httpsnippet-lite/esm/targets/csharp/restsharp/client.d.ts.map +1 -0
  41. package/dist/httpsnippet-lite/esm/targets/csharp/restsharp/client.js +49 -0
  42. package/dist/httpsnippet-lite/esm/targets/csharp/target.d.ts +41 -0
  43. package/dist/httpsnippet-lite/esm/targets/csharp/target.d.ts.map +1 -0
  44. package/dist/httpsnippet-lite/esm/targets/go/native/client.d.ts +15 -0
  45. package/dist/httpsnippet-lite/esm/targets/go/native/client.d.ts.map +1 -0
  46. package/dist/httpsnippet-lite/esm/targets/go/native/client.js +124 -0
  47. package/dist/httpsnippet-lite/esm/targets/go/target.d.ts +25 -0
  48. package/dist/httpsnippet-lite/esm/targets/go/target.d.ts.map +1 -0
  49. package/dist/httpsnippet-lite/esm/targets/http/http1.1/client.d.ts +22 -0
  50. package/dist/httpsnippet-lite/esm/targets/http/http1.1/client.d.ts.map +1 -0
  51. package/dist/httpsnippet-lite/esm/targets/http/http1.1/client.js +77 -0
  52. package/dist/httpsnippet-lite/esm/targets/http/target.d.ts +27 -0
  53. package/dist/httpsnippet-lite/esm/targets/http/target.d.ts.map +1 -0
  54. package/dist/httpsnippet-lite/esm/targets/java/asynchttp/client.d.ts +15 -0
  55. package/dist/httpsnippet-lite/esm/targets/java/asynchttp/client.d.ts.map +1 -0
  56. package/dist/httpsnippet-lite/esm/targets/java/asynchttp/client.js +47 -0
  57. package/dist/httpsnippet-lite/esm/targets/java/nethttp/client.d.ts +15 -0
  58. package/dist/httpsnippet-lite/esm/targets/java/nethttp/client.d.ts.map +1 -0
  59. package/dist/httpsnippet-lite/esm/targets/java/nethttp/client.js +46 -0
  60. package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.d.ts +15 -0
  61. package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.d.ts.map +1 -0
  62. package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.js +73 -0
  63. package/dist/httpsnippet-lite/esm/targets/java/target.d.ts +67 -0
  64. package/dist/httpsnippet-lite/esm/targets/java/target.d.ts.map +1 -0
  65. package/dist/httpsnippet-lite/esm/targets/java/unirest/client.d.ts +15 -0
  66. package/dist/httpsnippet-lite/esm/targets/java/unirest/client.d.ts.map +1 -0
  67. package/dist/httpsnippet-lite/esm/targets/java/unirest/client.js +47 -0
  68. package/dist/httpsnippet-lite/esm/targets/javascript/axios/client.d.ts +16 -0
  69. package/dist/httpsnippet-lite/esm/targets/javascript/axios/client.d.ts.map +1 -0
  70. package/dist/httpsnippet-lite/esm/targets/javascript/axios/client.js +91 -0
  71. package/dist/httpsnippet-lite/esm/targets/javascript/fetch/client.d.ts +15 -0
  72. package/dist/httpsnippet-lite/esm/targets/javascript/fetch/client.d.ts.map +1 -0
  73. package/dist/httpsnippet-lite/esm/targets/javascript/jquery/client.d.ts +15 -0
  74. package/dist/httpsnippet-lite/esm/targets/javascript/jquery/client.d.ts.map +1 -0
  75. package/dist/httpsnippet-lite/esm/targets/javascript/jquery/client.js +88 -0
  76. package/dist/httpsnippet-lite/esm/targets/javascript/target.d.ts +68 -0
  77. package/dist/httpsnippet-lite/esm/targets/javascript/target.d.ts.map +1 -0
  78. package/dist/httpsnippet-lite/esm/targets/javascript/xhr/client.d.ts +15 -0
  79. package/dist/httpsnippet-lite/esm/targets/javascript/xhr/client.d.ts.map +1 -0
  80. package/dist/httpsnippet-lite/esm/targets/javascript/xhr/client.js +86 -0
  81. package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.d.ts +15 -0
  82. package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.d.ts.map +1 -0
  83. package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.js +73 -0
  84. package/dist/httpsnippet-lite/esm/targets/kotlin/target.d.ts +25 -0
  85. package/dist/httpsnippet-lite/esm/targets/kotlin/target.d.ts.map +1 -0
  86. package/dist/httpsnippet-lite/esm/targets/node/axios/client.d.ts +16 -0
  87. package/dist/httpsnippet-lite/esm/targets/node/axios/client.d.ts.map +1 -0
  88. package/dist/httpsnippet-lite/esm/targets/node/axios/client.js +83 -0
  89. package/dist/httpsnippet-lite/esm/targets/node/fetch/client.d.ts +16 -0
  90. package/dist/httpsnippet-lite/esm/targets/node/fetch/client.d.ts.map +1 -0
  91. package/dist/httpsnippet-lite/esm/targets/node/native/client.d.ts +15 -0
  92. package/dist/httpsnippet-lite/esm/targets/node/native/client.d.ts.map +1 -0
  93. package/dist/httpsnippet-lite/esm/targets/node/request/client.d.ts +17 -0
  94. package/dist/httpsnippet-lite/esm/targets/node/request/client.d.ts.map +1 -0
  95. package/dist/httpsnippet-lite/esm/targets/node/target.d.ts +87 -0
  96. package/dist/httpsnippet-lite/esm/targets/node/target.d.ts.map +1 -0
  97. package/dist/httpsnippet-lite/esm/targets/node/unirest/client.d.ts +17 -0
  98. package/dist/httpsnippet-lite/esm/targets/node/unirest/client.d.ts.map +1 -0
  99. package/dist/httpsnippet-lite/esm/targets/objc/helpers.d.ts +27 -0
  100. package/dist/httpsnippet-lite/esm/targets/objc/helpers.d.ts.map +1 -0
  101. package/dist/httpsnippet-lite/esm/targets/objc/helpers.js +58 -0
  102. package/dist/httpsnippet-lite/esm/targets/objc/nsurlsession/client.d.ts +15 -0
  103. package/dist/httpsnippet-lite/esm/targets/objc/nsurlsession/client.d.ts.map +1 -0
  104. package/dist/httpsnippet-lite/esm/targets/objc/nsurlsession/client.js +132 -0
  105. package/dist/httpsnippet-lite/esm/targets/objc/target.d.ts +25 -0
  106. package/dist/httpsnippet-lite/esm/targets/objc/target.d.ts.map +1 -0
  107. package/dist/httpsnippet-lite/esm/targets/ocaml/cohttp/client.d.ts +15 -0
  108. package/dist/httpsnippet-lite/esm/targets/ocaml/cohttp/client.d.ts.map +1 -0
  109. package/dist/httpsnippet-lite/esm/targets/ocaml/cohttp/client.js +68 -0
  110. package/dist/httpsnippet-lite/esm/targets/ocaml/target.d.ts +25 -0
  111. package/dist/httpsnippet-lite/esm/targets/ocaml/target.d.ts.map +1 -0
  112. package/dist/httpsnippet-lite/esm/targets/php/curl/client.d.ts +18 -0
  113. package/dist/httpsnippet-lite/esm/targets/php/curl/client.d.ts.map +1 -0
  114. package/dist/httpsnippet-lite/esm/targets/php/curl/client.js +134 -0
  115. package/dist/httpsnippet-lite/esm/targets/php/guzzle/client.d.ts +16 -0
  116. package/dist/httpsnippet-lite/esm/targets/php/guzzle/client.d.ts.map +1 -0
  117. package/dist/httpsnippet-lite/esm/targets/php/guzzle/client.js +126 -0
  118. package/dist/httpsnippet-lite/esm/targets/php/helpers.d.ts +3 -0
  119. package/dist/httpsnippet-lite/esm/targets/php/helpers.d.ts.map +1 -0
  120. package/dist/httpsnippet-lite/esm/targets/php/helpers.js +37 -0
  121. package/dist/httpsnippet-lite/esm/targets/php/http1/client.d.ts +17 -0
  122. package/dist/httpsnippet-lite/esm/targets/php/http1/client.d.ts.map +1 -0
  123. package/dist/httpsnippet-lite/esm/targets/php/http2/client.d.ts +17 -0
  124. package/dist/httpsnippet-lite/esm/targets/php/http2/client.d.ts.map +1 -0
  125. package/dist/httpsnippet-lite/esm/targets/php/target.d.ts +75 -0
  126. package/dist/httpsnippet-lite/esm/targets/php/target.d.ts.map +1 -0
  127. package/dist/httpsnippet-lite/esm/targets/powershell/common.d.ts +10 -0
  128. package/dist/httpsnippet-lite/esm/targets/powershell/common.d.ts.map +1 -0
  129. package/dist/httpsnippet-lite/esm/targets/powershell/common.js +53 -0
  130. package/dist/httpsnippet-lite/esm/targets/powershell/restmethod/client.d.ts +18 -0
  131. package/dist/httpsnippet-lite/esm/targets/powershell/restmethod/client.d.ts.map +1 -0
  132. package/dist/httpsnippet-lite/esm/targets/powershell/restmethod/client.js +15 -0
  133. package/dist/httpsnippet-lite/esm/targets/powershell/target.d.ts +45 -0
  134. package/dist/httpsnippet-lite/esm/targets/powershell/target.d.ts.map +1 -0
  135. package/dist/httpsnippet-lite/esm/targets/powershell/webrequest/client.d.ts +18 -0
  136. package/dist/httpsnippet-lite/esm/targets/powershell/webrequest/client.d.ts.map +1 -0
  137. package/dist/httpsnippet-lite/esm/targets/powershell/webrequest/client.js +15 -0
  138. package/dist/httpsnippet-lite/esm/targets/python/helpers.d.ts +9 -0
  139. package/dist/httpsnippet-lite/esm/targets/python/helpers.d.ts.map +1 -0
  140. package/dist/httpsnippet-lite/esm/targets/python/helpers.js +63 -0
  141. package/dist/httpsnippet-lite/esm/targets/python/python3/client.d.ts +19 -0
  142. package/dist/httpsnippet-lite/esm/targets/python/python3/client.d.ts.map +1 -0
  143. package/dist/httpsnippet-lite/esm/targets/python/python3/client.js +95 -0
  144. package/dist/httpsnippet-lite/esm/targets/python/requests/client.d.ts +16 -0
  145. package/dist/httpsnippet-lite/esm/targets/python/requests/client.d.ts.map +1 -0
  146. package/dist/httpsnippet-lite/esm/targets/python/requests/client.js +177 -0
  147. package/dist/httpsnippet-lite/esm/targets/python/target.d.ts +44 -0
  148. package/dist/httpsnippet-lite/esm/targets/python/target.d.ts.map +1 -0
  149. package/dist/httpsnippet-lite/esm/targets/r/httr/client.d.ts +17 -0
  150. package/dist/httpsnippet-lite/esm/targets/r/httr/client.d.ts.map +1 -0
  151. package/dist/httpsnippet-lite/esm/targets/r/httr/client.js +127 -0
  152. package/dist/httpsnippet-lite/esm/targets/r/target.d.ts +27 -0
  153. package/dist/httpsnippet-lite/esm/targets/r/target.d.ts.map +1 -0
  154. package/dist/httpsnippet-lite/esm/targets/ruby/native/client.d.ts +16 -0
  155. package/dist/httpsnippet-lite/esm/targets/ruby/native/client.d.ts.map +1 -0
  156. package/dist/httpsnippet-lite/esm/targets/ruby/native/client.js +72 -0
  157. package/dist/httpsnippet-lite/esm/targets/ruby/target.d.ts +26 -0
  158. package/dist/httpsnippet-lite/esm/targets/ruby/target.d.ts.map +1 -0
  159. package/dist/httpsnippet-lite/esm/targets/shell/curl/client.d.ts +17 -0
  160. package/dist/httpsnippet-lite/esm/targets/shell/curl/client.d.ts.map +1 -0
  161. package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.d.ts +17 -0
  162. package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.d.ts.map +1 -0
  163. package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.js +118 -0
  164. package/dist/httpsnippet-lite/esm/targets/shell/target.d.ts +57 -0
  165. package/dist/httpsnippet-lite/esm/targets/shell/target.d.ts.map +1 -0
  166. package/dist/httpsnippet-lite/esm/targets/shell/wget/client.d.ts +15 -0
  167. package/dist/httpsnippet-lite/esm/targets/shell/wget/client.d.ts.map +1 -0
  168. package/dist/httpsnippet-lite/esm/targets/shell/wget/client.js +54 -0
  169. package/dist/httpsnippet-lite/esm/targets/swift/helpers.d.ts +17 -0
  170. package/dist/httpsnippet-lite/esm/targets/swift/helpers.d.ts.map +1 -0
  171. package/dist/httpsnippet-lite/esm/targets/swift/helpers.js +76 -0
  172. package/dist/httpsnippet-lite/esm/targets/swift/nsurlsession/client.d.ts +15 -0
  173. package/dist/httpsnippet-lite/esm/targets/swift/nsurlsession/client.d.ts.map +1 -0
  174. package/dist/httpsnippet-lite/esm/targets/swift/nsurlsession/client.js +137 -0
  175. package/dist/httpsnippet-lite/esm/targets/swift/target.d.ts +25 -0
  176. package/dist/httpsnippet-lite/esm/targets/swift/target.d.ts.map +1 -0
  177. package/dist/httpsnippet-lite/esm/targets/targets.d.ts +731 -0
  178. package/dist/httpsnippet-lite/esm/targets/targets.d.ts.map +1 -0
  179. package/dist/index.d.ts +1 -1
  180. package/dist/index.d.ts.map +1 -1
  181. package/dist/plugins/c/libcurl/libcurl.d.ts +1 -1
  182. package/dist/plugins/c/libcurl/libcurl.d.ts.map +1 -1
  183. package/dist/plugins/c/libcurl/libcurl.js +3 -2
  184. package/dist/plugins/clojure/clj_http/clj_http.d.ts +1 -1
  185. package/dist/plugins/clojure/clj_http/clj_http.d.ts.map +1 -1
  186. package/dist/plugins/clojure/clj_http/clj_http.js +3 -2
  187. package/dist/plugins/csharp/httpclient/httpclient.d.ts +1 -1
  188. package/dist/plugins/csharp/httpclient/httpclient.d.ts.map +1 -1
  189. package/dist/plugins/csharp/httpclient/httpclient.js +3 -2
  190. package/dist/plugins/csharp/restsharp/restsharp.d.ts +1 -1
  191. package/dist/plugins/csharp/restsharp/restsharp.d.ts.map +1 -1
  192. package/dist/plugins/csharp/restsharp/restsharp.js +3 -2
  193. package/dist/plugins/go/native/native.d.ts +1 -1
  194. package/dist/plugins/go/native/native.d.ts.map +1 -1
  195. package/dist/plugins/go/native/native.js +3 -2
  196. package/dist/plugins/http/http11/http11.d.ts +1 -1
  197. package/dist/plugins/http/http11/http11.d.ts.map +1 -1
  198. package/dist/plugins/http/http11/http11.js +3 -2
  199. package/dist/plugins/java/asynchttp/asynchttp.d.ts +1 -1
  200. package/dist/plugins/java/asynchttp/asynchttp.d.ts.map +1 -1
  201. package/dist/plugins/java/asynchttp/asynchttp.js +3 -2
  202. package/dist/plugins/java/nethttp/nethttp.d.ts +1 -1
  203. package/dist/plugins/java/nethttp/nethttp.d.ts.map +1 -1
  204. package/dist/plugins/java/nethttp/nethttp.js +3 -2
  205. package/dist/plugins/java/okhttp/okhttp.d.ts +1 -1
  206. package/dist/plugins/java/okhttp/okhttp.d.ts.map +1 -1
  207. package/dist/plugins/java/okhttp/okhttp.js +3 -2
  208. package/dist/plugins/java/unirest/unirest.d.ts +1 -1
  209. package/dist/plugins/java/unirest/unirest.d.ts.map +1 -1
  210. package/dist/plugins/java/unirest/unirest.js +3 -2
  211. package/dist/plugins/js/axios/axios.d.ts +1 -1
  212. package/dist/plugins/js/axios/axios.d.ts.map +1 -1
  213. package/dist/plugins/js/axios/axios.js +3 -2
  214. package/dist/plugins/js/fetch/fetch.d.ts +1 -1
  215. package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
  216. package/dist/plugins/js/fetch/fetch.js +3 -2
  217. package/dist/plugins/js/jquery/jquery.d.ts +1 -1
  218. package/dist/plugins/js/jquery/jquery.d.ts.map +1 -1
  219. package/dist/plugins/js/jquery/jquery.js +3 -2
  220. package/dist/plugins/js/ofetch/ofetch.d.ts +1 -1
  221. package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
  222. package/dist/plugins/js/ofetch/ofetch.js +3 -2
  223. package/dist/plugins/js/xhr/xhr.d.ts +1 -1
  224. package/dist/plugins/js/xhr/xhr.d.ts.map +1 -1
  225. package/dist/plugins/js/xhr/xhr.js +3 -2
  226. package/dist/plugins/kotlin/okhttp/okhttp.d.ts +1 -1
  227. package/dist/plugins/kotlin/okhttp/okhttp.d.ts.map +1 -1
  228. package/dist/plugins/kotlin/okhttp/okhttp.js +3 -2
  229. package/dist/plugins/node/axios/axios.d.ts +1 -1
  230. package/dist/plugins/node/axios/axios.d.ts.map +1 -1
  231. package/dist/plugins/node/axios/axios.js +3 -2
  232. package/dist/plugins/node/fetch/fetch.d.ts +1 -1
  233. package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
  234. package/dist/plugins/node/fetch/fetch.js +3 -2
  235. package/dist/plugins/node/ofetch/ofetch.d.ts +1 -1
  236. package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
  237. package/dist/plugins/node/ofetch/ofetch.js +3 -2
  238. package/dist/plugins/node/undici/undici.d.ts +1 -1
  239. package/dist/plugins/node/undici/undici.d.ts.map +1 -1
  240. package/dist/plugins/node/undici/undici.js +3 -2
  241. package/dist/plugins/objc/nsurlsession/nsurlsession.d.ts +1 -1
  242. package/dist/plugins/objc/nsurlsession/nsurlsession.d.ts.map +1 -1
  243. package/dist/plugins/objc/nsurlsession/nsurlsession.js +3 -2
  244. package/dist/plugins/ocaml/cohttp/cohttp.d.ts +1 -1
  245. package/dist/plugins/ocaml/cohttp/cohttp.d.ts.map +1 -1
  246. package/dist/plugins/ocaml/cohttp/cohttp.js +3 -2
  247. package/dist/plugins/php/curl/curl.d.ts +1 -1
  248. package/dist/plugins/php/curl/curl.d.ts.map +1 -1
  249. package/dist/plugins/php/curl/curl.js +3 -2
  250. package/dist/plugins/php/guzzle/guzzle.d.ts +1 -1
  251. package/dist/plugins/php/guzzle/guzzle.d.ts.map +1 -1
  252. package/dist/plugins/php/guzzle/guzzle.js +3 -2
  253. package/dist/plugins/powershell/restmethod/restmethod.d.ts +1 -1
  254. package/dist/plugins/powershell/restmethod/restmethod.d.ts.map +1 -1
  255. package/dist/plugins/powershell/restmethod/restmethod.js +3 -2
  256. package/dist/plugins/powershell/webrequest/webrequest.d.ts +1 -1
  257. package/dist/plugins/powershell/webrequest/webrequest.d.ts.map +1 -1
  258. package/dist/plugins/powershell/webrequest/webrequest.js +3 -2
  259. package/dist/plugins/python/python3/python3.d.ts +1 -1
  260. package/dist/plugins/python/python3/python3.d.ts.map +1 -1
  261. package/dist/plugins/python/python3/python3.js +3 -2
  262. package/dist/plugins/python/requests/requests.d.ts +1 -1
  263. package/dist/plugins/python/requests/requests.d.ts.map +1 -1
  264. package/dist/plugins/python/requests/requests.js +3 -2
  265. package/dist/plugins/r/httr/httr.d.ts +1 -1
  266. package/dist/plugins/r/httr/httr.d.ts.map +1 -1
  267. package/dist/plugins/r/httr/httr.js +3 -2
  268. package/dist/plugins/ruby/native/native.d.ts +1 -1
  269. package/dist/plugins/ruby/native/native.d.ts.map +1 -1
  270. package/dist/plugins/ruby/native/native.js +3 -2
  271. package/dist/plugins/shell/curl/curl.d.ts +1 -1
  272. package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
  273. package/dist/plugins/shell/curl/curl.js +1 -0
  274. package/dist/plugins/shell/httpie/httpie.d.ts +1 -1
  275. package/dist/plugins/shell/httpie/httpie.d.ts.map +1 -1
  276. package/dist/plugins/shell/httpie/httpie.js +3 -2
  277. package/dist/plugins/shell/wget/wget.d.ts +1 -1
  278. package/dist/plugins/shell/wget/wget.d.ts.map +1 -1
  279. package/dist/plugins/shell/wget/wget.js +3 -2
  280. package/dist/plugins/swift/nsurlsession/nsurlsession.d.ts +1 -1
  281. package/dist/plugins/swift/nsurlsession/nsurlsession.d.ts.map +1 -1
  282. package/dist/plugins/swift/nsurlsession/nsurlsession.js +3 -2
  283. package/dist/snippetz.d.ts +4 -6
  284. package/dist/snippetz.d.ts.map +1 -1
  285. package/dist/snippetz.js +10 -91
  286. package/dist/{core/types.d.ts → types/index.d.ts} +15 -4
  287. package/dist/types/index.d.ts.map +1 -0
  288. package/dist/types/index.js +1 -0
  289. package/dist/types/index.test-d.d.ts +2 -0
  290. package/dist/types/index.test-d.d.ts.map +1 -0
  291. package/dist/utils/arrayToObject.d.ts.map +1 -0
  292. package/dist/utils/convertWithHttpSnippetLite.d.ts +6 -0
  293. package/dist/utils/convertWithHttpSnippetLite.d.ts.map +1 -0
  294. package/dist/utils/convertWithHttpSnippetLite.js +95 -0
  295. package/dist/utils/index.d.ts +5 -0
  296. package/dist/utils/index.d.ts.map +1 -0
  297. package/dist/utils/index.js +4 -0
  298. package/dist/utils/needsQuotes.d.ts.map +1 -0
  299. package/dist/utils/objectToString.d.ts.map +1 -0
  300. package/package.json +11 -7
  301. package/dist/core/index.d.ts +0 -5
  302. package/dist/core/index.d.ts.map +0 -1
  303. package/dist/core/index.js +0 -3
  304. package/dist/core/types.d.ts.map +0 -1
  305. package/dist/core/types.test-d.d.ts +0 -2
  306. package/dist/core/types.test-d.d.ts.map +0 -1
  307. package/dist/core/utils/arrayToObject.d.ts.map +0 -1
  308. package/dist/core/utils/convertWithHttpSnippetLite.d.ts +0 -7
  309. package/dist/core/utils/convertWithHttpSnippetLite.d.ts.map +0 -1
  310. package/dist/core/utils/convertWithHttpSnippetLite.js +0 -83
  311. package/dist/core/utils/needsQuotes.d.ts.map +0 -1
  312. package/dist/core/utils/objectToString.d.ts.map +0 -1
  313. /package/dist/{core/utils → utils}/arrayToObject.d.ts +0 -0
  314. /package/dist/{core/utils → utils}/arrayToObject.js +0 -0
  315. /package/dist/{core/utils → utils}/needsQuotes.d.ts +0 -0
  316. /package/dist/{core/utils → utils}/needsQuotes.js +0 -0
  317. /package/dist/{core/utils → utils}/objectToString.d.ts +0 -0
  318. /package/dist/{core/utils → utils}/objectToString.js +0 -0
@@ -0,0 +1,189 @@
1
+ import { CodeBuilder } from '../../../helpers/code-builder.js';
2
+ import { getHeaderName, getHeader } from '../../../helpers/headers.js';
3
+
4
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
+ // @ts-nocheck
6
+ /**
7
+ * @description
8
+ * HTTP code snippet generator for Clojure using clj-http.
9
+ *
10
+ * @author
11
+ * @tggreene
12
+ *
13
+ * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
14
+ */
15
+ class Keyword {
16
+ constructor(name) {
17
+ this.name = '';
18
+ this.toString = () => `:${this.name}`;
19
+ this.name = name;
20
+ }
21
+ }
22
+ class File {
23
+ constructor(path) {
24
+ this.path = '';
25
+ this.toString = () => `(clojure.java.io/file "${this.path}")`;
26
+ this.path = path;
27
+ }
28
+ }
29
+ const jsType = (input) => {
30
+ if (input === undefined) {
31
+ return null;
32
+ }
33
+ if (input === null) {
34
+ return 'null';
35
+ }
36
+ return input.constructor.name.toLowerCase();
37
+ };
38
+ const objEmpty = (input) => {
39
+ if (jsType(input) === 'object') {
40
+ return Object.keys(input).length === 0;
41
+ }
42
+ return false;
43
+ };
44
+ const filterEmpty = (input) => {
45
+ Object.keys(input)
46
+ .filter((x) => objEmpty(input[x]))
47
+ .forEach((x) => {
48
+ delete input[x];
49
+ });
50
+ return input;
51
+ };
52
+ const padBlock = (padSize, input) => {
53
+ const padding = ' '.repeat(padSize);
54
+ return input.replace(/\n/g, `\n${padding}`);
55
+ };
56
+ const jsToEdn = (js) => {
57
+ switch (jsType(js)) {
58
+ case 'string':
59
+ return `"${js.replace(/"/g, '\\"')}"`;
60
+ case 'file':
61
+ return js.toString();
62
+ case 'keyword':
63
+ return js.toString();
64
+ case 'null':
65
+ return 'nil';
66
+ case 'regexp':
67
+ return `#"${js.source}"`;
68
+ case 'object': {
69
+ // simple vertical format
70
+ const obj = Object.keys(js)
71
+ .reduce((accumulator, key) => {
72
+ const val = padBlock(key.length + 2, jsToEdn(js[key]));
73
+ return `${accumulator}:${key} ${val}\n `;
74
+ }, '')
75
+ .trim();
76
+ return `{${padBlock(1, obj)}}`;
77
+ }
78
+ case 'array': {
79
+ // simple horizontal format
80
+ const arr = js
81
+ .reduce((accumulator, value) => `${accumulator} ${jsToEdn(value)}`, '')
82
+ .trim();
83
+ return `[${padBlock(1, arr)}]`;
84
+ }
85
+ default: // 'number' 'boolean'
86
+ return js.toString();
87
+ }
88
+ };
89
+ const clj_http = {
90
+ info: {
91
+ key: 'clj_http',
92
+ title: 'clj-http',
93
+ link: 'https://github.com/dakrone/clj-http',
94
+ description: 'An idiomatic clojure http client wrapping the apache client.',
95
+ },
96
+ convert: ({ queryObj, method, postData, url, allHeaders }, options) => {
97
+ const { push, join } = new CodeBuilder({
98
+ indent: options === null || options === void 0 ? void 0 : options.indent,
99
+ });
100
+ const methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
101
+ method = method.toLowerCase();
102
+ if (!methods.includes(method)) {
103
+ push('Method not supported');
104
+ return join();
105
+ }
106
+ const params = {
107
+ 'headers': allHeaders,
108
+ 'query-params': queryObj,
109
+ };
110
+ // Remove query string from URL if queryObj has parameters
111
+ if (queryObj && Object.keys(queryObj).length > 0) {
112
+ url = url.split('?')[0];
113
+ }
114
+ switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
115
+ case 'application/json':
116
+ {
117
+ params['content-type'] = new Keyword('json');
118
+ params['form-params'] = postData.jsonObj;
119
+ const header = getHeaderName(params.headers, 'content-type');
120
+ if (header) {
121
+ delete params.headers[header];
122
+ }
123
+ }
124
+ break;
125
+ case 'application/x-www-form-urlencoded':
126
+ {
127
+ params['form-params'] = postData.paramsObj;
128
+ const header = getHeaderName(params.headers, 'content-type');
129
+ if (header) {
130
+ delete params.headers[header];
131
+ }
132
+ }
133
+ break;
134
+ case 'text/plain':
135
+ {
136
+ params.body = postData.text;
137
+ const header = getHeaderName(params.headers, 'content-type');
138
+ if (header) {
139
+ delete params.headers[header];
140
+ }
141
+ }
142
+ break;
143
+ case 'multipart/form-data': {
144
+ if (postData.params) {
145
+ params.multipart = postData.params.map((param) => {
146
+ if (param.fileName && !param.value) {
147
+ return {
148
+ name: param.name,
149
+ content: new File(param.fileName),
150
+ };
151
+ }
152
+ return {
153
+ name: param.name,
154
+ content: param.value,
155
+ };
156
+ });
157
+ const header = getHeaderName(params.headers, 'content-type');
158
+ if (header) {
159
+ delete params.headers[header];
160
+ }
161
+ }
162
+ break;
163
+ }
164
+ }
165
+ switch (getHeader(params.headers, 'accept')) {
166
+ case 'application/json':
167
+ {
168
+ params.accept = new Keyword('json');
169
+ const header = getHeaderName(params.headers, 'accept');
170
+ if (header) {
171
+ delete params.headers[header];
172
+ }
173
+ }
174
+ break;
175
+ }
176
+ push("(require '[clj-http.client :as client])\n");
177
+ if (objEmpty(filterEmpty(params))) {
178
+ push(`(client/${method} "${url}")`);
179
+ }
180
+ else {
181
+ const padding = 11 + method.length + url.length;
182
+ const formattedParams = padBlock(padding, jsToEdn(filterEmpty(params)));
183
+ push(`(client/${method} "${url}" ${formattedParams})`);
184
+ }
185
+ return join();
186
+ },
187
+ };
188
+
189
+ export { clj_http };
@@ -0,0 +1,26 @@
1
+ export declare const clojure: {
2
+ info: {
3
+ key: string;
4
+ title: string;
5
+ extname: string;
6
+ default: string;
7
+ };
8
+ clientsById: {
9
+ clj_http: {
10
+ info: {
11
+ key: string;
12
+ title: string;
13
+ link: string;
14
+ description: string;
15
+ };
16
+ convert: ({ queryObj, method, postData, url, allHeaders }: {
17
+ queryObj: any;
18
+ method: any;
19
+ postData: any;
20
+ url: any;
21
+ allHeaders: any;
22
+ }, options: any) => any;
23
+ };
24
+ };
25
+ };
26
+ //# sourceMappingURL=target.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/esm/targets/clojure/target.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;CAUnB,CAAA"}
@@ -0,0 +1,15 @@
1
+ export declare const httpclient: {
2
+ info: {
3
+ key: string;
4
+ title: string;
5
+ link: string;
6
+ description: string;
7
+ };
8
+ convert: ({ allHeaders, postData, method, fullUrl }: {
9
+ allHeaders: any;
10
+ postData: any;
11
+ method: any;
12
+ fullUrl: any;
13
+ }, options: any) => any;
14
+ };
15
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/csharp/httpclient/client.ts"],"names":[],"mappings":"AAgCA,eAAO,MAAM,UAAU;;;;;;;;;;;;;CAoJtB,CAAA"}
@@ -0,0 +1,169 @@
1
+ import { CodeBuilder } from '../../../helpers/code-builder.js';
2
+ import { escapeForDoubleQuotes } from '../../../helpers/escape.js';
3
+ import { getHeader } from '../../../helpers/headers.js';
4
+
5
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
+ // @ts-nocheck
7
+ const getDecompressionMethods = (allHeaders) => {
8
+ let acceptEncodings = getHeader(allHeaders, 'accept-encoding');
9
+ if (!acceptEncodings) {
10
+ return []; // no decompression
11
+ }
12
+ const supportedMethods = {
13
+ gzip: 'DecompressionMethods.GZip',
14
+ deflate: 'DecompressionMethods.Deflate',
15
+ };
16
+ const methods = [];
17
+ if (typeof acceptEncodings === 'string') {
18
+ acceptEncodings = [acceptEncodings];
19
+ }
20
+ acceptEncodings.forEach((acceptEncoding) => {
21
+ acceptEncoding.split(',').forEach((encoding) => {
22
+ const match = /\s*([^;\s]+)/.exec(encoding);
23
+ if (match) {
24
+ const method = supportedMethods[match[1]];
25
+ if (method) {
26
+ methods.push(method);
27
+ }
28
+ }
29
+ });
30
+ });
31
+ return methods;
32
+ };
33
+ const httpclient = {
34
+ info: {
35
+ key: 'httpclient',
36
+ title: 'HttpClient',
37
+ link: 'https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient',
38
+ description: '.NET Standard HTTP Client',
39
+ },
40
+ convert: ({ allHeaders, postData, method, fullUrl }, options) => {
41
+ let _a, _b;
42
+ const opts = {
43
+ indent: ' ',
44
+ ...options,
45
+ };
46
+ const { push, join } = new CodeBuilder({ indent: opts.indent });
47
+ push('using System.Net.Http.Headers;');
48
+ let clienthandler = '';
49
+ const cookies = Boolean(allHeaders.cookie);
50
+ const decompressionMethods = getDecompressionMethods(allHeaders);
51
+ if (cookies || decompressionMethods.length) {
52
+ clienthandler = 'clientHandler';
53
+ push('var clientHandler = new HttpClientHandler');
54
+ push('{');
55
+ if (cookies) {
56
+ // enable setting the cookie header
57
+ push('UseCookies = false,', 1);
58
+ }
59
+ if (decompressionMethods.length) {
60
+ // enable decompression for supported methods
61
+ push(`AutomaticDecompression = ${decompressionMethods.join(' | ')},`, 1);
62
+ }
63
+ push('};');
64
+ }
65
+ push(`var client = new HttpClient(${clienthandler});`);
66
+ push('var request = new HttpRequestMessage');
67
+ push('{');
68
+ const methods = [
69
+ 'GET',
70
+ 'POST',
71
+ 'PUT',
72
+ 'DELETE',
73
+ 'PATCH',
74
+ 'HEAD',
75
+ 'OPTIONS',
76
+ 'TRACE',
77
+ ];
78
+ method = method.toUpperCase();
79
+ if (method && methods.includes(method)) {
80
+ // buildin method
81
+ method = `HttpMethod.${method[0]}${method.substring(1).toLowerCase()}`;
82
+ }
83
+ else {
84
+ // custom method
85
+ method = `new HttpMethod("${method}")`;
86
+ }
87
+ push(`Method = ${method},`, 1);
88
+ push(`RequestUri = new Uri("${fullUrl}"),`, 1);
89
+ const headers = Object.keys(allHeaders).filter((header) => {
90
+ switch (header.toLowerCase()) {
91
+ case 'content-type':
92
+ case 'content-length':
93
+ case 'accept-encoding':
94
+ // skip these headers
95
+ return false;
96
+ default:
97
+ return true;
98
+ }
99
+ });
100
+ if (headers.length) {
101
+ push('Headers =', 1);
102
+ push('{', 1);
103
+ headers.forEach((key) => {
104
+ push(`{ "${key}", "${escapeForDoubleQuotes(allHeaders[key])}" },`, 2);
105
+ });
106
+ push('},', 1);
107
+ }
108
+ if (postData === null || postData === void 0 ? void 0 : postData.text) {
109
+ const contentType = postData.mimeType;
110
+ switch (contentType) {
111
+ case 'application/x-www-form-urlencoded':
112
+ push('Content = new FormUrlEncodedContent(new Dictionary<string, string>', 1);
113
+ push('{', 1);
114
+ (_a = postData.params) === null || _a === void 0
115
+ ? void 0
116
+ : _a.forEach((param) => {
117
+ push(`{ "${param.name}", "${param.value}" },`, 2);
118
+ });
119
+ push('}),', 1);
120
+ break;
121
+ case 'multipart/form-data':
122
+ push('Content = new MultipartFormDataContent', 1);
123
+ push('{', 1);
124
+ (_b = postData.params) === null || _b === void 0
125
+ ? void 0
126
+ : _b.forEach((param) => {
127
+ push(`new StringContent(${JSON.stringify(param.value || '')})`, 2);
128
+ push('{', 2);
129
+ push('Headers =', 3);
130
+ push('{', 3);
131
+ if (param.contentType) {
132
+ push(`ContentType = new MediaTypeHeaderValue("${param.contentType}"),`, 4);
133
+ }
134
+ push('ContentDisposition = new ContentDispositionHeaderValue("form-data")', 4);
135
+ push('{', 4);
136
+ push(`Name = "${param.name}",`, 5);
137
+ if (param.fileName) {
138
+ push(`FileName = "${param.fileName}",`, 5);
139
+ }
140
+ push('}', 4);
141
+ push('}', 3);
142
+ push('},', 2);
143
+ });
144
+ push('},', 1);
145
+ break;
146
+ default:
147
+ push(`Content = new StringContent(${JSON.stringify((postData === null || postData === void 0 ? void 0 : postData.text) || '')})`, 1);
148
+ push('{', 1);
149
+ push('Headers =', 2);
150
+ push('{', 2);
151
+ push(`ContentType = new MediaTypeHeaderValue("${contentType}")`, 3);
152
+ push('}', 2);
153
+ push('}', 1);
154
+ break;
155
+ }
156
+ }
157
+ push('};');
158
+ // send and read response
159
+ push('using (var response = await client.SendAsync(request))');
160
+ push('{');
161
+ push('response.EnsureSuccessStatusCode();', 1);
162
+ push('var body = await response.Content.ReadAsStringAsync();', 1);
163
+ push('Console.WriteLine(body);', 1);
164
+ push('}');
165
+ return join();
166
+ },
167
+ };
168
+
169
+ export { httpclient };
@@ -0,0 +1,17 @@
1
+ export declare const restsharp: {
2
+ info: {
3
+ key: string;
4
+ title: string;
5
+ link: string;
6
+ description: string;
7
+ };
8
+ convert: ({ allHeaders, method, fullUrl, headersObj, cookies, postData }: {
9
+ allHeaders: any;
10
+ method: any;
11
+ fullUrl: any;
12
+ headersObj: any;
13
+ cookies: any;
14
+ postData: any;
15
+ }) => any;
16
+ };
17
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/csharp/restsharp/client.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;CA4CrB,CAAA"}
@@ -0,0 +1,49 @@
1
+ import { CodeBuilder } from '../../../helpers/code-builder.js';
2
+ import { escapeForDoubleQuotes } from '../../../helpers/escape.js';
3
+ import { getHeader } from '../../../helpers/headers.js';
4
+
5
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
+ // @ts-nocheck
7
+ const restsharp = {
8
+ info: {
9
+ key: 'restsharp',
10
+ title: 'RestSharp',
11
+ link: 'http://restsharp.org/',
12
+ description: 'Simple REST and HTTP API Client for .NET',
13
+ },
14
+ convert: ({ allHeaders, method, fullUrl, headersObj, cookies, postData }) => {
15
+ const { push, join } = new CodeBuilder();
16
+ const isSupportedMethod = [
17
+ 'GET',
18
+ 'POST',
19
+ 'PUT',
20
+ 'DELETE',
21
+ 'PATCH',
22
+ 'HEAD',
23
+ 'OPTIONS',
24
+ ].includes(method.toUpperCase());
25
+ if (!isSupportedMethod) {
26
+ return 'Method not supported';
27
+ }
28
+ push(`var client = new RestClient("${fullUrl}");`);
29
+ push(`var request = new RestRequest(Method.${method.toUpperCase()});`);
30
+ // Add headers, including the cookies
31
+ Object.keys(headersObj).forEach((key) => {
32
+ push(`request.AddHeader("${key}", "${escapeForDoubleQuotes(headersObj[key])}");`);
33
+ });
34
+ cookies === null || cookies === void 0
35
+ ? void 0
36
+ : cookies.forEach(({ name, value }) => {
37
+ push(`request.AddCookie("${name}", "${value}");`);
38
+ });
39
+ if (postData === null || postData === void 0 ? void 0 : postData.text) {
40
+ const header = getHeader(allHeaders, 'content-type');
41
+ const text = JSON.stringify(postData.text);
42
+ push(`request.AddParameter("${header}", ${text}, ParameterType.RequestBody);`);
43
+ }
44
+ push('IRestResponse response = client.Execute(request);');
45
+ return join();
46
+ },
47
+ };
48
+
49
+ export { restsharp };
@@ -0,0 +1,41 @@
1
+ export declare const csharp: {
2
+ info: {
3
+ key: string;
4
+ title: string;
5
+ extname: string;
6
+ default: string;
7
+ };
8
+ clientsById: {
9
+ httpclient: {
10
+ info: {
11
+ key: string;
12
+ title: string;
13
+ link: string;
14
+ description: string;
15
+ };
16
+ convert: ({ allHeaders, postData, method, fullUrl }: {
17
+ allHeaders: any;
18
+ postData: any;
19
+ method: any;
20
+ fullUrl: any;
21
+ }, options: any) => any;
22
+ };
23
+ restsharp: {
24
+ info: {
25
+ key: string;
26
+ title: string;
27
+ link: string;
28
+ description: string;
29
+ };
30
+ convert: ({ allHeaders, method, fullUrl, headersObj, cookies, postData }: {
31
+ allHeaders: any;
32
+ method: any;
33
+ fullUrl: any;
34
+ headersObj: any;
35
+ cookies: any;
36
+ postData: any;
37
+ }) => any;
38
+ };
39
+ };
40
+ };
41
+ //# sourceMappingURL=target.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/esm/targets/csharp/target.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAWlB,CAAA"}
@@ -0,0 +1,15 @@
1
+ export declare const native: {
2
+ info: {
3
+ key: string;
4
+ title: string;
5
+ link: string;
6
+ description: string;
7
+ };
8
+ convert: ({ postData, method, allHeaders, fullUrl }: {
9
+ postData: any;
10
+ method: any;
11
+ allHeaders: any;
12
+ fullUrl: any;
13
+ }, options?: {}) => any;
14
+ };
15
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/go/native/client.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,MAAM;;;;;;;;;;;;;CAkIlB,CAAA"}
@@ -0,0 +1,124 @@
1
+ import { CodeBuilder } from '../../../helpers/code-builder.js';
2
+ import { escapeForDoubleQuotes } from '../../../helpers/escape.js';
3
+
4
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
+ // @ts-nocheck
6
+ /**
7
+ * @description
8
+ * HTTP code snippet generator for native Go.
9
+ *
10
+ * @author
11
+ * @montanaflynn
12
+ *
13
+ * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
14
+ */
15
+ const native = {
16
+ info: {
17
+ key: 'native',
18
+ title: 'NewRequest',
19
+ link: 'http://golang.org/pkg/net/http/#NewRequest',
20
+ description: 'Golang HTTP client request',
21
+ },
22
+ convert: ({ postData, method, allHeaders, fullUrl }, options = {}) => {
23
+ const { blank, push, join } = new CodeBuilder({ indent: '\t' });
24
+ const { showBoilerplate = true, checkErrors = false, printBody = true, timeout = -1, insecureSkipVerify = false, } = options;
25
+ const errorPlaceholder = checkErrors ? 'err' : '_';
26
+ const indent = showBoilerplate ? 1 : 0;
27
+ const errorCheck = () => {
28
+ if (checkErrors) {
29
+ push('if err != nil {', indent);
30
+ push('panic(err)', indent + 1);
31
+ push('}', indent);
32
+ }
33
+ };
34
+ // Create boilerplate
35
+ if (showBoilerplate) {
36
+ push('package main');
37
+ blank();
38
+ push('import (');
39
+ push('"fmt"', indent);
40
+ if (timeout > 0) {
41
+ push('"time"', indent);
42
+ }
43
+ if (insecureSkipVerify) {
44
+ push('"crypto/tls"', indent);
45
+ }
46
+ if (postData === null || postData === void 0 ? void 0 : postData.text) {
47
+ push('"strings"', indent);
48
+ }
49
+ push('"net/http"', indent);
50
+ if (printBody) {
51
+ push('"io"', indent);
52
+ }
53
+ push(')');
54
+ blank();
55
+ push('func main() {');
56
+ blank();
57
+ }
58
+ // Create an insecure transport for the client
59
+ if (insecureSkipVerify) {
60
+ push('insecureTransport := http.DefaultTransport.(*http.Transport).Clone()', indent);
61
+ push('insecureTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}', indent);
62
+ }
63
+ // Create client
64
+ const hasTimeout = timeout > 0;
65
+ const hasClient = hasTimeout || insecureSkipVerify;
66
+ const client = hasClient ? 'client' : 'http.DefaultClient';
67
+ if (hasClient) {
68
+ push('client := http.Client{', indent);
69
+ if (hasTimeout) {
70
+ push(`Timeout: time.Duration(${timeout} * time.Second),`, indent + 1);
71
+ }
72
+ if (insecureSkipVerify) {
73
+ push('Transport: insecureTransport,', indent + 1);
74
+ }
75
+ push('}', indent);
76
+ blank();
77
+ }
78
+ push(`url := "${fullUrl}"`, indent);
79
+ blank();
80
+ // If we have body content or not create the var and reader or nil
81
+ if (postData === null || postData === void 0 ? void 0 : postData.text) {
82
+ push(`payload := strings.NewReader(${JSON.stringify(postData.text)})`, indent);
83
+ blank();
84
+ push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, payload)`, indent);
85
+ blank();
86
+ }
87
+ else {
88
+ push(`req, ${errorPlaceholder} := http.NewRequest("${method}", url, nil)`, indent);
89
+ blank();
90
+ }
91
+ errorCheck();
92
+ // Add headers
93
+ if (Object.keys(allHeaders).length) {
94
+ Object.keys(allHeaders).forEach((key) => {
95
+ push(`req.Header.Add("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, indent);
96
+ });
97
+ blank();
98
+ }
99
+ // Make request
100
+ push(`res, ${errorPlaceholder} := ${client}.Do(req)`, indent);
101
+ errorCheck();
102
+ // Get Body
103
+ if (printBody) {
104
+ blank();
105
+ push('defer res.Body.Close()', indent);
106
+ push(`body, ${errorPlaceholder} := io.ReadAll(res.Body)`, indent);
107
+ errorCheck();
108
+ }
109
+ // Print it
110
+ blank();
111
+ push('fmt.Println(res)', indent);
112
+ if (printBody) {
113
+ push('fmt.Println(string(body))', indent);
114
+ }
115
+ // End main block
116
+ if (showBoilerplate) {
117
+ blank();
118
+ push('}');
119
+ }
120
+ return join();
121
+ },
122
+ };
123
+
124
+ export { native };