@scalar/snippetz 0.7.4 → 0.7.6

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/dist/clients/index.js +168 -169
  2. package/dist/httpsnippet-lite/helpers/code-builder.js +86 -74
  3. package/dist/httpsnippet-lite/helpers/escape.js +69 -44
  4. package/dist/httpsnippet-lite/helpers/headers.js +17 -14
  5. package/dist/httpsnippet-lite/helpers/reducer.js +1 -1
  6. package/dist/httpsnippet-lite/helpers/shell.js +13 -13
  7. package/dist/httpsnippet-lite/helpers/snippet-request.js +1 -1
  8. package/dist/httpsnippet-lite/helpers/url.js +4 -8
  9. package/dist/httpsnippet-lite/targets/c/libcurl/client.js +69 -67
  10. package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +165 -154
  11. package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +35 -38
  12. package/dist/httpsnippet-lite/targets/go/native/client.js +151 -147
  13. package/dist/httpsnippet-lite/targets/java/asynchttp/client.js +32 -35
  14. package/dist/httpsnippet-lite/targets/java/nethttp/client.js +40 -39
  15. package/dist/httpsnippet-lite/targets/java/okhttp/client.js +83 -73
  16. package/dist/httpsnippet-lite/targets/java/unirest/client.js +41 -34
  17. package/dist/httpsnippet-lite/targets/javascript/axios/client.js +81 -76
  18. package/dist/httpsnippet-lite/targets/javascript/jquery/client.js +77 -71
  19. package/dist/httpsnippet-lite/targets/javascript/xhr/client.js +73 -71
  20. package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +83 -73
  21. package/dist/httpsnippet-lite/targets/node/axios/client.js +74 -69
  22. package/dist/httpsnippet-lite/targets/objc/helpers.js +52 -33
  23. package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +123 -121
  24. package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js +60 -49
  25. package/dist/httpsnippet-lite/targets/powershell/common.js +46 -56
  26. package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js +9 -13
  27. package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js +9 -13
  28. package/dist/httpsnippet-lite/targets/python/python3/client.js +85 -68
  29. package/dist/httpsnippet-lite/targets/r/httr/client.js +114 -95
  30. package/dist/httpsnippet-lite/targets/ruby/native/client.js +66 -70
  31. package/dist/httpsnippet-lite/targets/shell/httpie/client.js +121 -107
  32. package/dist/httpsnippet-lite/targets/shell/wget/client.js +48 -43
  33. package/dist/httpsnippet-lite/targets/swift/helpers.js +62 -44
  34. package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js +126 -112
  35. package/dist/httpsnippet-lite/targets/target.js +1 -1
  36. package/dist/index.js +2 -9
  37. package/dist/libs/http.js +68 -56
  38. package/dist/libs/javascript.js +77 -60
  39. package/dist/libs/php.js +59 -49
  40. package/dist/libs/rust.js +60 -33
  41. package/dist/libs/shell.js +14 -5
  42. package/dist/plugins/c/libcurl/index.js +1 -5
  43. package/dist/plugins/c/libcurl/libcurl.js +13 -13
  44. package/dist/plugins/clojure/clj_http/clj_http.js +13 -13
  45. package/dist/plugins/clojure/clj_http/index.js +1 -5
  46. package/dist/plugins/csharp/httpclient/httpclient.js +206 -150
  47. package/dist/plugins/csharp/httpclient/index.js +1 -5
  48. package/dist/plugins/csharp/restsharp/index.js +1 -5
  49. package/dist/plugins/csharp/restsharp/restsharp.js +13 -13
  50. package/dist/plugins/dart/http/http.js +95 -93
  51. package/dist/plugins/dart/http/index.js +1 -5
  52. package/dist/plugins/fsharp/httpclient/httpclient.js +169 -122
  53. package/dist/plugins/fsharp/httpclient/index.js +1 -5
  54. package/dist/plugins/go/native/index.js +1 -5
  55. package/dist/plugins/go/native/native.js +13 -13
  56. package/dist/plugins/http/http11/http11.d.ts.map +1 -1
  57. package/dist/plugins/http/http11/http11.js +104 -85
  58. package/dist/plugins/http/http11/index.js +1 -5
  59. package/dist/plugins/java/asynchttp/asynchttp.js +13 -13
  60. package/dist/plugins/java/asynchttp/index.js +1 -5
  61. package/dist/plugins/java/nethttp/index.js +1 -5
  62. package/dist/plugins/java/nethttp/nethttp.js +13 -13
  63. package/dist/plugins/java/okhttp/index.js +1 -5
  64. package/dist/plugins/java/okhttp/okhttp.js +13 -13
  65. package/dist/plugins/java/unirest/index.js +1 -5
  66. package/dist/plugins/java/unirest/unirest.js +13 -13
  67. package/dist/plugins/js/axios/axios.js +13 -13
  68. package/dist/plugins/js/axios/index.js +1 -5
  69. package/dist/plugins/js/fetch/fetch.js +82 -68
  70. package/dist/plugins/js/fetch/index.js +1 -5
  71. package/dist/plugins/js/jquery/index.js +1 -5
  72. package/dist/plugins/js/jquery/jquery.js +13 -13
  73. package/dist/plugins/js/ofetch/index.js +1 -5
  74. package/dist/plugins/js/ofetch/ofetch.js +61 -48
  75. package/dist/plugins/js/xhr/index.js +1 -5
  76. package/dist/plugins/js/xhr/xhr.js +13 -13
  77. package/dist/plugins/kotlin/okhttp/index.js +1 -5
  78. package/dist/plugins/kotlin/okhttp/okhttp.js +13 -13
  79. package/dist/plugins/node/axios/axios.js +13 -13
  80. package/dist/plugins/node/axios/index.js +1 -5
  81. package/dist/plugins/node/fetch/fetch.js +86 -74
  82. package/dist/plugins/node/fetch/index.js +1 -5
  83. package/dist/plugins/node/ofetch/index.js +1 -5
  84. package/dist/plugins/node/ofetch/ofetch.js +61 -48
  85. package/dist/plugins/node/undici/index.js +1 -5
  86. package/dist/plugins/node/undici/undici.js +60 -47
  87. package/dist/plugins/objc/nsurlsession/index.js +1 -5
  88. package/dist/plugins/objc/nsurlsession/nsurlsession.js +13 -13
  89. package/dist/plugins/ocaml/cohttp/cohttp.js +13 -13
  90. package/dist/plugins/ocaml/cohttp/index.js +1 -5
  91. package/dist/plugins/php/curl/curl.js +143 -101
  92. package/dist/plugins/php/curl/index.js +1 -5
  93. package/dist/plugins/php/guzzle/guzzle.d.ts.map +1 -1
  94. package/dist/plugins/php/guzzle/guzzle.js +109 -83
  95. package/dist/plugins/php/guzzle/index.js +1 -5
  96. package/dist/plugins/powershell/restmethod/index.js +1 -5
  97. package/dist/plugins/powershell/restmethod/restmethod.js +13 -13
  98. package/dist/plugins/powershell/webrequest/index.js +1 -5
  99. package/dist/plugins/powershell/webrequest/webrequest.js +13 -13
  100. package/dist/plugins/python/httpx/async.js +17 -15
  101. package/dist/plugins/python/httpx/index.js +2 -7
  102. package/dist/plugins/python/httpx/sync.js +11 -12
  103. package/dist/plugins/python/python3/index.js +1 -5
  104. package/dist/plugins/python/python3/python3.js +13 -13
  105. package/dist/plugins/python/requests/index.js +1 -5
  106. package/dist/plugins/python/requests/requests.js +11 -12
  107. package/dist/plugins/python/requestsLike.d.ts.map +1 -1
  108. package/dist/plugins/python/requestsLike.js +145 -112
  109. package/dist/plugins/r/httr/httr.js +13 -13
  110. package/dist/plugins/r/httr/index.js +1 -5
  111. package/dist/plugins/ruby/native/index.js +1 -5
  112. package/dist/plugins/ruby/native/native.js +13 -13
  113. package/dist/plugins/rust/reqwest/index.js +1 -5
  114. package/dist/plugins/rust/reqwest/reqwest.js +126 -83
  115. package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
  116. package/dist/plugins/shell/curl/curl.js +129 -97
  117. package/dist/plugins/shell/curl/index.js +1 -5
  118. package/dist/plugins/shell/httpie/httpie.js +13 -13
  119. package/dist/plugins/shell/httpie/index.js +1 -5
  120. package/dist/plugins/shell/wget/index.js +1 -5
  121. package/dist/plugins/shell/wget/wget.js +13 -13
  122. package/dist/plugins/swift/nsurlsession/index.js +1 -5
  123. package/dist/plugins/swift/nsurlsession/nsurlsession.js +13 -13
  124. package/dist/snippetz.js +25 -28
  125. package/dist/utils/convertWithHttpSnippetLite.js +100 -96
  126. package/dist/utils/index.js +1 -5
  127. package/package.json +8 -12
  128. package/dist/clients/index.js.map +0 -7
  129. package/dist/httpsnippet-lite/helpers/code-builder.js.map +0 -7
  130. package/dist/httpsnippet-lite/helpers/escape.js.map +0 -7
  131. package/dist/httpsnippet-lite/helpers/headers.js.map +0 -7
  132. package/dist/httpsnippet-lite/helpers/reducer.js.map +0 -7
  133. package/dist/httpsnippet-lite/helpers/shell.js.map +0 -7
  134. package/dist/httpsnippet-lite/helpers/snippet-request.js.map +0 -7
  135. package/dist/httpsnippet-lite/helpers/url.js.map +0 -7
  136. package/dist/httpsnippet-lite/targets/c/libcurl/client.js.map +0 -7
  137. package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js.map +0 -7
  138. package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js.map +0 -7
  139. package/dist/httpsnippet-lite/targets/go/native/client.js.map +0 -7
  140. package/dist/httpsnippet-lite/targets/java/asynchttp/client.js.map +0 -7
  141. package/dist/httpsnippet-lite/targets/java/nethttp/client.js.map +0 -7
  142. package/dist/httpsnippet-lite/targets/java/okhttp/client.js.map +0 -7
  143. package/dist/httpsnippet-lite/targets/java/unirest/client.js.map +0 -7
  144. package/dist/httpsnippet-lite/targets/javascript/axios/client.js.map +0 -7
  145. package/dist/httpsnippet-lite/targets/javascript/jquery/client.js.map +0 -7
  146. package/dist/httpsnippet-lite/targets/javascript/xhr/client.js.map +0 -7
  147. package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js.map +0 -7
  148. package/dist/httpsnippet-lite/targets/node/axios/client.js.map +0 -7
  149. package/dist/httpsnippet-lite/targets/objc/helpers.js.map +0 -7
  150. package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js.map +0 -7
  151. package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js.map +0 -7
  152. package/dist/httpsnippet-lite/targets/powershell/common.js.map +0 -7
  153. package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js.map +0 -7
  154. package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js.map +0 -7
  155. package/dist/httpsnippet-lite/targets/python/python3/client.js.map +0 -7
  156. package/dist/httpsnippet-lite/targets/r/httr/client.js.map +0 -7
  157. package/dist/httpsnippet-lite/targets/ruby/native/client.js.map +0 -7
  158. package/dist/httpsnippet-lite/targets/shell/httpie/client.js.map +0 -7
  159. package/dist/httpsnippet-lite/targets/shell/wget/client.js.map +0 -7
  160. package/dist/httpsnippet-lite/targets/swift/helpers.js.map +0 -7
  161. package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js.map +0 -7
  162. package/dist/httpsnippet-lite/targets/target.js.map +0 -7
  163. package/dist/index.js.map +0 -7
  164. package/dist/libs/http.js.map +0 -7
  165. package/dist/libs/javascript.js.map +0 -7
  166. package/dist/libs/php.js.map +0 -7
  167. package/dist/libs/rust.js.map +0 -7
  168. package/dist/libs/shell.js.map +0 -7
  169. package/dist/plugins/c/libcurl/index.js.map +0 -7
  170. package/dist/plugins/c/libcurl/libcurl.js.map +0 -7
  171. package/dist/plugins/clojure/clj_http/clj_http.js.map +0 -7
  172. package/dist/plugins/clojure/clj_http/index.js.map +0 -7
  173. package/dist/plugins/csharp/httpclient/httpclient.js.map +0 -7
  174. package/dist/plugins/csharp/httpclient/index.js.map +0 -7
  175. package/dist/plugins/csharp/restsharp/index.js.map +0 -7
  176. package/dist/plugins/csharp/restsharp/restsharp.js.map +0 -7
  177. package/dist/plugins/dart/http/http.js.map +0 -7
  178. package/dist/plugins/dart/http/index.js.map +0 -7
  179. package/dist/plugins/fsharp/httpclient/httpclient.js.map +0 -7
  180. package/dist/plugins/fsharp/httpclient/index.js.map +0 -7
  181. package/dist/plugins/go/native/index.js.map +0 -7
  182. package/dist/plugins/go/native/native.js.map +0 -7
  183. package/dist/plugins/http/http11/http11.js.map +0 -7
  184. package/dist/plugins/http/http11/index.js.map +0 -7
  185. package/dist/plugins/java/asynchttp/asynchttp.js.map +0 -7
  186. package/dist/plugins/java/asynchttp/index.js.map +0 -7
  187. package/dist/plugins/java/nethttp/index.js.map +0 -7
  188. package/dist/plugins/java/nethttp/nethttp.js.map +0 -7
  189. package/dist/plugins/java/okhttp/index.js.map +0 -7
  190. package/dist/plugins/java/okhttp/okhttp.js.map +0 -7
  191. package/dist/plugins/java/unirest/index.js.map +0 -7
  192. package/dist/plugins/java/unirest/unirest.js.map +0 -7
  193. package/dist/plugins/js/axios/axios.js.map +0 -7
  194. package/dist/plugins/js/axios/index.js.map +0 -7
  195. package/dist/plugins/js/fetch/fetch.js.map +0 -7
  196. package/dist/plugins/js/fetch/index.js.map +0 -7
  197. package/dist/plugins/js/jquery/index.js.map +0 -7
  198. package/dist/plugins/js/jquery/jquery.js.map +0 -7
  199. package/dist/plugins/js/ofetch/index.js.map +0 -7
  200. package/dist/plugins/js/ofetch/ofetch.js.map +0 -7
  201. package/dist/plugins/js/xhr/index.js.map +0 -7
  202. package/dist/plugins/js/xhr/xhr.js.map +0 -7
  203. package/dist/plugins/kotlin/okhttp/index.js.map +0 -7
  204. package/dist/plugins/kotlin/okhttp/okhttp.js.map +0 -7
  205. package/dist/plugins/node/axios/axios.js.map +0 -7
  206. package/dist/plugins/node/axios/index.js.map +0 -7
  207. package/dist/plugins/node/fetch/fetch.js.map +0 -7
  208. package/dist/plugins/node/fetch/index.js.map +0 -7
  209. package/dist/plugins/node/ofetch/index.js.map +0 -7
  210. package/dist/plugins/node/ofetch/ofetch.js.map +0 -7
  211. package/dist/plugins/node/undici/index.js.map +0 -7
  212. package/dist/plugins/node/undici/undici.js.map +0 -7
  213. package/dist/plugins/objc/nsurlsession/index.js.map +0 -7
  214. package/dist/plugins/objc/nsurlsession/nsurlsession.js.map +0 -7
  215. package/dist/plugins/ocaml/cohttp/cohttp.js.map +0 -7
  216. package/dist/plugins/ocaml/cohttp/index.js.map +0 -7
  217. package/dist/plugins/php/curl/curl.js.map +0 -7
  218. package/dist/plugins/php/curl/index.js.map +0 -7
  219. package/dist/plugins/php/guzzle/guzzle.js.map +0 -7
  220. package/dist/plugins/php/guzzle/index.js.map +0 -7
  221. package/dist/plugins/powershell/restmethod/index.js.map +0 -7
  222. package/dist/plugins/powershell/restmethod/restmethod.js.map +0 -7
  223. package/dist/plugins/powershell/webrequest/index.js.map +0 -7
  224. package/dist/plugins/powershell/webrequest/webrequest.js.map +0 -7
  225. package/dist/plugins/python/httpx/async.js.map +0 -7
  226. package/dist/plugins/python/httpx/index.js.map +0 -7
  227. package/dist/plugins/python/httpx/sync.js.map +0 -7
  228. package/dist/plugins/python/python3/index.js.map +0 -7
  229. package/dist/plugins/python/python3/python3.js.map +0 -7
  230. package/dist/plugins/python/requests/index.js.map +0 -7
  231. package/dist/plugins/python/requests/requests.js.map +0 -7
  232. package/dist/plugins/python/requestsLike.js.map +0 -7
  233. package/dist/plugins/r/httr/httr.js.map +0 -7
  234. package/dist/plugins/r/httr/index.js.map +0 -7
  235. package/dist/plugins/ruby/native/index.js.map +0 -7
  236. package/dist/plugins/ruby/native/native.js.map +0 -7
  237. package/dist/plugins/rust/reqwest/index.js.map +0 -7
  238. package/dist/plugins/rust/reqwest/reqwest.js.map +0 -7
  239. package/dist/plugins/shell/curl/curl.js.map +0 -7
  240. package/dist/plugins/shell/curl/index.js.map +0 -7
  241. package/dist/plugins/shell/httpie/httpie.js.map +0 -7
  242. package/dist/plugins/shell/httpie/index.js.map +0 -7
  243. package/dist/plugins/shell/wget/index.js.map +0 -7
  244. package/dist/plugins/shell/wget/wget.js.map +0 -7
  245. package/dist/plugins/swift/nsurlsession/index.js.map +0 -7
  246. package/dist/plugins/swift/nsurlsession/nsurlsession.js.map +0 -7
  247. package/dist/snippetz.js.map +0 -7
  248. package/dist/utils/convertWithHttpSnippetLite.js.map +0 -7
  249. package/dist/utils/index.js.map +0 -7
@@ -1,14 +1,14 @@
1
- import { python3 } from "../../../httpsnippet-lite/targets/python/python3/client.js";
2
- import { convertWithHttpSnippetLite } from "../../../utils/convertWithHttpSnippetLite.js";
3
- const pythonPython3 = {
4
- target: "python",
5
- client: "python3",
6
- title: "http.client",
7
- generate(request) {
8
- return convertWithHttpSnippetLite(python3, request);
9
- }
1
+ import { python3 } from '../../../httpsnippet-lite/targets/python/python3/client.js';
2
+ import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
3
+ /**
4
+ * python/python3
5
+ */
6
+ export const pythonPython3 = {
7
+ target: 'python',
8
+ client: 'python3',
9
+ title: 'http.client',
10
+ generate(request) {
11
+ // TODO: Write an own converter
12
+ return convertWithHttpSnippetLite(python3, request);
13
+ },
10
14
  };
11
- export {
12
- pythonPython3
13
- };
14
- //# sourceMappingURL=python3.js.map
@@ -1,5 +1 @@
1
- import { pythonRequests } from "./requests.js";
2
- export {
3
- pythonRequests
4
- };
5
- //# sourceMappingURL=index.js.map
1
+ export { pythonRequests } from './requests.js';
@@ -1,13 +1,12 @@
1
- import { requestsLikeGenerate } from "../../../plugins/python/requestsLike.js";
2
- const pythonRequests = {
3
- target: "python",
4
- client: "requests",
5
- title: "Requests",
6
- generate(request, configuration) {
7
- return requestsLikeGenerate("requests", request, configuration);
8
- }
1
+ import { requestsLikeGenerate } from '../../../plugins/python/requestsLike.js';
2
+ /**
3
+ * python/requests
4
+ */
5
+ export const pythonRequests = {
6
+ target: 'python',
7
+ client: 'requests',
8
+ title: 'Requests',
9
+ generate(request, configuration) {
10
+ return requestsLikeGenerate('requests', request, configuration);
11
+ },
9
12
  };
10
- export {
11
- pythonRequests
12
- };
13
- //# sourceMappingURL=requests.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestsLike.d.ts","sourceRoot":"","sources":["../../../src/plugins/python/requestsLike.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AA0B7E,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,EAC7B,aAAa,CAAC,EAAE,mBAAmB,UAsIpC"}
1
+ {"version":3,"file":"requestsLike.d.ts","sourceRoot":"","sources":["../../../src/plugins/python/requestsLike.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AA0B7E,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,EAC7B,aAAa,CAAC,EAAE,mBAAmB,UAuJpC"}
@@ -1,121 +1,154 @@
1
- import { reduceQueryParams } from "../../libs/http.js";
1
+ import { reduceQueryParams } from '../../libs/http.js';
2
2
  const LENGTH_CONSIDERED_AS_SHORT = 40;
3
+ // Function to convert JavaScript boolean and null values to Python equivalents
3
4
  function convertToPythonSyntax(str) {
4
- const replacements = [
5
- ["true", "True"],
6
- ["false", "False"],
7
- ["null", "None"]
8
- ];
9
- let result = str;
10
- for (const [jsonVal, pythonVal] of replacements) {
11
- const patterns = [`(: )${jsonVal}(?=,|\\n)`, `^( +)${jsonVal}(?=,|\\n)`];
12
- for (const pattern of patterns) {
13
- result = result.replace(new RegExp(pattern, "gm"), `$1${pythonVal}`);
5
+ const replacements = [
6
+ ['true', 'True'],
7
+ ['false', 'False'],
8
+ ['null', 'None'],
9
+ ];
10
+ let result = str;
11
+ for (const [jsonVal, pythonVal] of replacements) {
12
+ const patterns = [`(: )${jsonVal}(?=,|\\n)`, `^( +)${jsonVal}(?=,|\\n)`];
13
+ for (const pattern of patterns) {
14
+ result = result.replace(new RegExp(pattern, 'gm'), `$1${pythonVal}`);
15
+ }
14
16
  }
15
- }
16
- return result;
17
+ return result;
17
18
  }
18
- function requestsLikeGenerate(clientVar, request, configuration) {
19
- const normalizedRequest = {
20
- url: "https://example.com",
21
- method: "get",
22
- ...request
23
- };
24
- const method = normalizedRequest.method.toLowerCase();
25
- const options = {};
26
- if (normalizedRequest.headers?.length) {
27
- options.headers = normalizedRequest.headers.reduce(
28
- (acc, header) => {
29
- if (!(header.name in acc)) {
30
- acc[header.name] = header.value;
19
+ export function requestsLikeGenerate(clientVar, request, configuration) {
20
+ // Normalize request with defaults
21
+ const normalizedRequest = {
22
+ url: 'https://example.com',
23
+ method: 'get',
24
+ ...request,
25
+ };
26
+ // Normalize method to lowercase for requests library
27
+ const method = normalizedRequest.method.toLowerCase();
28
+ // Build options object
29
+ const options = {};
30
+ // Add headers if present
31
+ if (normalizedRequest.headers?.length) {
32
+ options.headers = normalizedRequest.headers.reduce((acc, header) => {
33
+ if (!(header.name in acc)) {
34
+ acc[header.name] = header.value;
35
+ }
36
+ return acc;
37
+ }, {});
38
+ }
39
+ // Add query parameters if present
40
+ if (normalizedRequest.queryString?.length) {
41
+ options.params = reduceQueryParams(normalizedRequest.queryString);
42
+ }
43
+ // Add cookies if present
44
+ if (normalizedRequest.cookies?.length) {
45
+ options.cookies = Object.fromEntries(normalizedRequest.cookies.map((c) => [c.name, c.value]));
46
+ }
47
+ // Add auth if present
48
+ if (configuration?.auth?.username && configuration?.auth?.password) {
49
+ options.auth = [configuration.auth.username, configuration.auth.password];
50
+ }
51
+ // Handle request body
52
+ if (normalizedRequest.postData) {
53
+ const { mimeType, text, params } = normalizedRequest.postData;
54
+ if (mimeType === 'application/json' && text) {
55
+ try {
56
+ options.json = JSON.parse(text);
57
+ }
58
+ catch {
59
+ options.data = text;
60
+ }
61
+ }
62
+ else if (mimeType === 'application/octet-stream' && text) {
63
+ options.data = text; // Store raw text, we'll handle the b"..." formatting later
64
+ }
65
+ else if (mimeType === 'multipart/form-data' && params) {
66
+ const files = [];
67
+ const formData = {};
68
+ params.forEach((param) => {
69
+ if (param.fileName !== undefined) {
70
+ const name = JSON.stringify(param.name);
71
+ const fileName = JSON.stringify(param.fileName);
72
+ const file = `open(${fileName}, "rb")`;
73
+ if (param.contentType) {
74
+ const contentType = JSON.stringify(param.contentType);
75
+ files.push(`(${name}, (${fileName}, ${file}, ${contentType}))`);
76
+ }
77
+ else {
78
+ files.push(`(${name}, ${file})`);
79
+ }
80
+ }
81
+ else if (param.value !== undefined) {
82
+ if (param.contentType) {
83
+ const name = JSON.stringify(param.name);
84
+ const value = JSON.stringify(param.value);
85
+ const contentType = JSON.stringify(param.contentType);
86
+ files.push(`(${name}, (None, ${value}, ${contentType}))`);
87
+ }
88
+ else {
89
+ formData[param.name] = param.value;
90
+ }
91
+ }
92
+ });
93
+ if (files.length) {
94
+ options.files = files;
95
+ }
96
+ if (Object.keys(formData).length) {
97
+ options.data = formData;
98
+ }
99
+ }
100
+ else if (mimeType === 'application/x-www-form-urlencoded' && params) {
101
+ options.data = Object.fromEntries(params.map((p) => [p.name, p.value]));
31
102
  }
32
- return acc;
33
- },
34
- {}
35
- );
36
- }
37
- if (normalizedRequest.queryString?.length) {
38
- options.params = reduceQueryParams(normalizedRequest.queryString);
39
- }
40
- if (normalizedRequest.cookies?.length) {
41
- options.cookies = Object.fromEntries(normalizedRequest.cookies.map((c) => [c.name, c.value]));
42
- }
43
- if (configuration?.auth?.username && configuration?.auth?.password) {
44
- options.auth = [configuration.auth.username, configuration.auth.password];
45
- }
46
- if (normalizedRequest.postData) {
47
- const { mimeType, text, params } = normalizedRequest.postData;
48
- if (mimeType === "application/json" && text) {
49
- try {
50
- options.json = JSON.parse(text);
51
- } catch {
52
- options.data = text;
53
- }
54
- } else if (mimeType === "application/octet-stream" && text) {
55
- options.data = text;
56
- } else if (mimeType === "multipart/form-data" && params) {
57
- const files = [];
58
- const formData = {};
59
- params.forEach((param) => {
60
- if (param.fileName !== void 0) {
61
- files.push({ key: param.name, file: `open("${param.fileName}", "rb")` });
62
- } else if (param.value !== void 0) {
63
- formData[param.name] = param.value;
103
+ }
104
+ // Format all parameters
105
+ const formattedParams = [];
106
+ // Format URL based on length
107
+ const urlParam = `"${normalizedRequest.url}"`;
108
+ if (normalizedRequest.url.length > LENGTH_CONSIDERED_AS_SHORT) {
109
+ formattedParams.push(urlParam);
110
+ }
111
+ else {
112
+ // Will be handled in the return statement for short URLs
113
+ formattedParams.push('');
114
+ }
115
+ // Format options
116
+ for (const [key, value] of Object.entries(options)) {
117
+ if (key === 'auth') {
118
+ formattedParams.push(`${key}=(${convertToPythonSyntax(JSON.stringify(value[0]))}, ${convertToPythonSyntax(JSON.stringify(value[1]))})`);
119
+ }
120
+ else if (key === 'files') {
121
+ const filesTuples = value.map((tuple) => ` ${tuple}`);
122
+ const filesStr = '[\n' + filesTuples.join(',\n') + '\n ]';
123
+ formattedParams.push(`${key}=${filesStr}`);
64
124
  }
65
- });
66
- if (Object.keys(files).length) {
67
- options.files = files;
68
- }
69
- if (Object.keys(formData).length) {
70
- options.data = formData;
71
- }
72
- } else if (mimeType === "application/x-www-form-urlencoded" && params) {
73
- options.data = Object.fromEntries(params.map((p) => [p.name, p.value]));
125
+ else if (key === 'json') {
126
+ const jsonString = convertToPythonSyntax(JSON.stringify(value, null, 2)
127
+ .split('\n')
128
+ .map((line, i) => (i === 0 ? line : ' ' + line))
129
+ .join('\n'));
130
+ formattedParams.push(`${key}=${jsonString}`);
131
+ }
132
+ else if (key === 'data' && normalizedRequest.postData?.mimeType === 'application/octet-stream') {
133
+ // Special handling for binary data
134
+ formattedParams.push(`${key}=b"${value}"`);
135
+ }
136
+ else {
137
+ const str = convertToPythonSyntax(JSON.stringify(value, null, 2)
138
+ .split('\n')
139
+ .map((line, i) => (i === 0 ? line : ' ' + line))
140
+ .join('\n'));
141
+ formattedParams.push(`${key}=${str}`);
142
+ }
143
+ }
144
+ // Build the final request string with conditional URL formatting
145
+ if (normalizedRequest.url.length > LENGTH_CONSIDERED_AS_SHORT) {
146
+ return `${clientVar}.${method}(\n ${formattedParams.join(',\n ')}\n)`;
74
147
  }
75
- }
76
- const formattedParams = [];
77
- const urlParam = `"${normalizedRequest.url}"`;
78
- if (normalizedRequest.url.length > LENGTH_CONSIDERED_AS_SHORT) {
79
- formattedParams.push(urlParam);
80
- } else {
81
- formattedParams.push("");
82
- }
83
- for (const [key, value] of Object.entries(options)) {
84
- if (key === "auth") {
85
- formattedParams.push(
86
- `${key}=(${convertToPythonSyntax(JSON.stringify(value[0]))}, ${convertToPythonSyntax(JSON.stringify(value[1]))})`
87
- );
88
- } else if (key === "files") {
89
- const filesTuples = value.map(({ key: key2, file }) => ` ("${key2}", ${file})`);
90
- const filesStr = "[\n" + filesTuples.join(",\n") + "\n ]";
91
- formattedParams.push(`${key}=${filesStr}`);
92
- } else if (key === "json") {
93
- const jsonString = convertToPythonSyntax(
94
- JSON.stringify(value, null, 2).split("\n").map((line, i) => i === 0 ? line : " " + line).join("\n")
95
- );
96
- formattedParams.push(`${key}=${jsonString}`);
97
- } else if (key === "data" && normalizedRequest.postData?.mimeType === "application/octet-stream") {
98
- formattedParams.push(`${key}=b"${value}"`);
99
- } else {
100
- const str = convertToPythonSyntax(
101
- JSON.stringify(value, null, 2).split("\n").map((line, i) => i === 0 ? line : " " + line).join("\n")
102
- );
103
- formattedParams.push(`${key}=${str}`);
148
+ // For short URLs with no additional parameters, return a single-line format
149
+ if (formattedParams.length <= 1) {
150
+ return `${clientVar}.${method}(${urlParam})`;
104
151
  }
105
- }
106
- if (normalizedRequest.url.length > LENGTH_CONSIDERED_AS_SHORT) {
107
- return `${clientVar}.${method}(
108
- ${formattedParams.join(",\n ")}
109
- )`;
110
- }
111
- if (formattedParams.length <= 1) {
112
- return `${clientVar}.${method}(${urlParam})`;
113
- }
114
- return `${clientVar}.${method}(${urlParam}${formattedParams.length > 1 ? "," : ""}
115
- ${formattedParams.slice(1).join(",\n ")}
116
- )`;
152
+ // For short URLs with parameters, maintain the multi-line format
153
+ return `${clientVar}.${method}(${urlParam}${formattedParams.length > 1 ? ',' : ''}\n ${formattedParams.slice(1).join(',\n ')}\n)`;
117
154
  }
118
- export {
119
- requestsLikeGenerate
120
- };
121
- //# sourceMappingURL=requestsLike.js.map
@@ -1,14 +1,14 @@
1
- import { httr } from "../../../httpsnippet-lite/targets/r/httr/client.js";
2
- import { convertWithHttpSnippetLite } from "../../../utils/convertWithHttpSnippetLite.js";
3
- const rHttr = {
4
- target: "r",
5
- client: "httr",
6
- title: "httr",
7
- generate(request) {
8
- return convertWithHttpSnippetLite(httr, request);
9
- }
1
+ import { httr } from '../../../httpsnippet-lite/targets/r/httr/client.js';
2
+ import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
3
+ /**
4
+ * r/httr
5
+ */
6
+ export const rHttr = {
7
+ target: 'r',
8
+ client: 'httr',
9
+ title: 'httr',
10
+ generate(request) {
11
+ // TODO: Write an own converter
12
+ return convertWithHttpSnippetLite(httr, request);
13
+ },
10
14
  };
11
- export {
12
- rHttr
13
- };
14
- //# sourceMappingURL=httr.js.map
@@ -1,5 +1 @@
1
- import { rHttr } from "./httr.js";
2
- export {
3
- rHttr
4
- };
5
- //# sourceMappingURL=index.js.map
1
+ export { rHttr } from './httr.js';
@@ -1,5 +1 @@
1
- import { rubyNative } from "./native.js";
2
- export {
3
- rubyNative
4
- };
5
- //# sourceMappingURL=index.js.map
1
+ export { rubyNative } from './native.js';
@@ -1,14 +1,14 @@
1
- import { native } from "../../../httpsnippet-lite/targets/ruby/native/client.js";
2
- import { convertWithHttpSnippetLite } from "../../../utils/convertWithHttpSnippetLite.js";
3
- const rubyNative = {
4
- target: "ruby",
5
- client: "native",
6
- title: "net::http",
7
- generate(request) {
8
- return convertWithHttpSnippetLite(native, request);
9
- }
1
+ import { native } from '../../../httpsnippet-lite/targets/ruby/native/client.js';
2
+ import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
3
+ /**
4
+ * ruby/native
5
+ */
6
+ export const rubyNative = {
7
+ target: 'ruby',
8
+ client: 'native',
9
+ title: 'net::http',
10
+ generate(request) {
11
+ // TODO: Write an own converter
12
+ return convertWithHttpSnippetLite(native, request);
13
+ },
10
14
  };
11
- export {
12
- rubyNative
13
- };
14
- //# sourceMappingURL=native.js.map
@@ -1,5 +1 @@
1
- import { rustReqwest } from "./reqwest.js";
2
- export {
3
- rustReqwest
4
- };
5
- //# sourceMappingURL=index.js.map
1
+ export { rustReqwest } from './reqwest.js';
@@ -1,96 +1,139 @@
1
- import { buildQueryString, buildUrl, normalizeRequest, processHeaders } from "../../../libs/http.js";
2
- import { createChain, formatJson, indent, wrapInDoubleQuotes } from "../../../libs/rust.js";
3
- const rustReqwest = {
4
- target: "rust",
5
- client: "reqwest",
6
- title: "reqwest",
7
- generate(request, options) {
8
- if (!request) {
9
- return "";
10
- }
11
- const normalizedRequest = normalizeRequest(request);
12
- const queryString = buildQueryString(normalizedRequest.queryString);
13
- const url = buildUrl(normalizedRequest.url || "", queryString);
14
- const headers = processHeaders(normalizedRequest);
15
- const chainedCalls = [];
16
- const authCall = createAuthCall(options?.auth);
17
- if (authCall) {
18
- chainedCalls.push(authCall);
19
- }
20
- chainedCalls.push(...createHeaderCalls(headers));
21
- const bodyCall = createBodyCall(normalizedRequest.postData);
22
- if (bodyCall) {
23
- chainedCalls.push(bodyCall);
24
- }
25
- return buildRustCode(url, normalizedRequest.method, chainedCalls);
26
- }
1
+ import { buildQueryString, buildUrl, normalizeRequest, processHeaders } from '../../../libs/http.js';
2
+ import { createChain, formatJson, indent, wrapInDoubleQuotes } from '../../../libs/rust.js';
3
+ /**
4
+ * rust/reqwest plugin for generating Rust reqwest HTTP client code
5
+ */
6
+ export const rustReqwest = {
7
+ target: 'rust',
8
+ client: 'reqwest',
9
+ title: 'reqwest',
10
+ generate(request, options) {
11
+ if (!request) {
12
+ return '';
13
+ }
14
+ // Normalization
15
+ const normalizedRequest = normalizeRequest(request);
16
+ // Query string
17
+ const queryString = buildQueryString(normalizedRequest.queryString);
18
+ const url = buildUrl(normalizedRequest.url || '', queryString);
19
+ // Headers and cookies
20
+ const headers = processHeaders(normalizedRequest);
21
+ // Chained calls
22
+ const chainedCalls = [];
23
+ // Auth
24
+ const authCall = createAuthCall(options?.auth);
25
+ if (authCall) {
26
+ chainedCalls.push(authCall);
27
+ }
28
+ // Headers
29
+ chainedCalls.push(...createHeaderCalls(headers));
30
+ // Body
31
+ const bodyCall = createBodyCall(normalizedRequest.postData);
32
+ if (bodyCall) {
33
+ chainedCalls.push(bodyCall);
34
+ }
35
+ // Code
36
+ return buildRustCode(url, normalizedRequest.method, chainedCalls);
37
+ },
27
38
  };
39
+ /**
40
+ * Helper function to create multipart form parts with proper indentation
41
+ */
28
42
  const createMultipartPart = (param) => {
29
- if (param.fileName) {
30
- return [
31
- indent(2, `let part = reqwest::multipart::Part::text(${wrapInDoubleQuotes(param.value || "")})`),
32
- indent(3, `.file_name(${wrapInDoubleQuotes(param.fileName)});`),
33
- indent(2, `form = form.part(${wrapInDoubleQuotes(param.name)}, part);`)
34
- ].join("\n");
35
- }
36
- return indent(2, `form = form.text(${wrapInDoubleQuotes(param.name)}, ${wrapInDoubleQuotes(param.value || "")});`);
43
+ if (param.fileName) {
44
+ const part = [
45
+ indent(2, `let part = reqwest::multipart::Part::text(${wrapInDoubleQuotes(param.value || '')})`),
46
+ indent(3, `.file_name(${wrapInDoubleQuotes(param.fileName)})`),
47
+ ];
48
+ if (param.contentType) {
49
+ part.push(indent(3, `.mime_str(${wrapInDoubleQuotes(param.contentType)})`));
50
+ part.push(indent(3, '.unwrap();'));
51
+ }
52
+ else {
53
+ part[part.length - 1] += ';';
54
+ }
55
+ part.push(indent(2, `form = form.part(${wrapInDoubleQuotes(param.name)}, part);`));
56
+ return part.join('\n');
57
+ }
58
+ if (param.contentType) {
59
+ return [
60
+ indent(2, `let part = reqwest::multipart::Part::text(${wrapInDoubleQuotes(param.value || '')})`),
61
+ indent(3, `.mime_str(${wrapInDoubleQuotes(param.contentType)})`),
62
+ indent(3, '.unwrap();'),
63
+ indent(2, `form = form.part(${wrapInDoubleQuotes(param.name)}, part);`),
64
+ ].join('\n');
65
+ }
66
+ return indent(2, `form = form.text(${wrapInDoubleQuotes(param.name)}, ${wrapInDoubleQuotes(param.value || '')});`);
37
67
  };
68
+ /**
69
+ * Creates authentication chained call if credentials are provided
70
+ */
38
71
  const createAuthCall = (auth) => {
39
- if (!auth?.username || !auth?.password) {
40
- return null;
41
- }
42
- return createChain("basic_auth", wrapInDoubleQuotes(auth.username), wrapInDoubleQuotes(auth.password));
72
+ if (!auth?.username || !auth?.password) {
73
+ return null;
74
+ }
75
+ return createChain('basic_auth', wrapInDoubleQuotes(auth.username), wrapInDoubleQuotes(auth.password));
43
76
  };
77
+ /**
78
+ * Creates header chained calls from headers object
79
+ */
44
80
  const createHeaderCalls = (headers) => {
45
- return Object.entries(headers).map(
46
- ([key, value]) => createChain("header", wrapInDoubleQuotes(key), wrapInDoubleQuotes(value))
47
- );
81
+ return Object.entries(headers).map(([key, value]) => createChain('header', wrapInDoubleQuotes(key), wrapInDoubleQuotes(value)));
48
82
  };
83
+ /**
84
+ * Creates body chained call based on content type
85
+ */
49
86
  const createBodyCall = (postData) => {
50
- if (!postData) {
51
- return null;
52
- }
53
- const { mimeType, text, params } = postData;
54
- switch (mimeType) {
55
- case "application/json": {
56
- const formattedJson = formatJson(text);
57
- return createChain("json", `&serde_json::json!(${formattedJson})`);
58
- }
59
- case "application/x-www-form-urlencoded": {
60
- const formData = params?.map((param) => `(${wrapInDoubleQuotes(param.name)}, ${wrapInDoubleQuotes(param.value || "")})`).join(", ") || "";
61
- return createChain("form", `&[${formData}]`);
87
+ if (!postData) {
88
+ return null;
62
89
  }
63
- case "multipart/form-data": {
64
- const formParts = params?.map(createMultipartPart).join("\n") || "";
65
- const multipartBlock = [
66
- ".multipart({",
67
- indent(2, "let mut form = reqwest::multipart::Form::new();"),
68
- formParts,
69
- indent(3, "form"),
70
- indent(2, "})")
71
- ].join("\n");
72
- return indent(1, multipartBlock);
90
+ const { mimeType, text, params } = postData;
91
+ switch (mimeType) {
92
+ case 'application/json': {
93
+ const formattedJson = formatJson(text);
94
+ return createChain('json', `&serde_json::json!(${formattedJson})`);
95
+ }
96
+ case 'application/x-www-form-urlencoded': {
97
+ const formData = params
98
+ ?.map((param) => `(${wrapInDoubleQuotes(param.name)}, ${wrapInDoubleQuotes(param.value || '')})`)
99
+ .join(', ') || '';
100
+ return createChain('form', `&[${formData}]`);
101
+ }
102
+ case 'multipart/form-data': {
103
+ const formParts = params?.map(createMultipartPart).join('\n') || '';
104
+ const multipartBlock = [
105
+ '.multipart({',
106
+ indent(2, 'let mut form = reqwest::multipart::Form::new();'),
107
+ formParts,
108
+ indent(3, 'form'),
109
+ indent(2, '})'),
110
+ ].join('\n');
111
+ return indent(1, multipartBlock);
112
+ }
113
+ default:
114
+ return createChain('body', wrapInDoubleQuotes(text || ''));
73
115
  }
74
- default:
75
- return createChain("body", wrapInDoubleQuotes(text || ""));
76
- }
77
116
  };
117
+ /**
118
+ * Builds the complete Rust code by assembling all code
119
+ */
78
120
  const buildRustCode = (url, method, chainedCalls) => {
79
- const code = ["let client = reqwest::Client::new();", ""];
80
- if (chainedCalls.length > 0) {
81
- code.push("let request = client");
82
- code.push(indent(1, `.${method.toLowerCase()}(${wrapInDoubleQuotes(url)})`));
83
- code.push(...chainedCalls);
84
- } else {
85
- code.push(`let request = client.${method.toLowerCase()}(${wrapInDoubleQuotes(url)})`);
86
- }
87
- const lastPart = code[code.length - 1];
88
- code[code.length - 1] = lastPart + ";";
89
- code.push("");
90
- code.push("let response = request.send().await?;");
91
- return code.join("\n");
92
- };
93
- export {
94
- rustReqwest
121
+ const code = ['let client = reqwest::Client::new();', ''];
122
+ // Add chained calls with proper formatting
123
+ if (chainedCalls.length > 0) {
124
+ code.push('let request = client');
125
+ code.push(indent(1, `.${method.toLowerCase()}(${wrapInDoubleQuotes(url)})`));
126
+ // Add a newline before the first chained call
127
+ code.push(...chainedCalls);
128
+ }
129
+ else {
130
+ code.push(`let request = client.${method.toLowerCase()}(${wrapInDoubleQuotes(url)})`);
131
+ }
132
+ // Add semicolon to the last chained call
133
+ const lastPart = code[code.length - 1];
134
+ code[code.length - 1] = lastPart + ';';
135
+ // Add response handling
136
+ code.push('');
137
+ code.push('let response = request.send().await?;');
138
+ return code.join('\n');
95
139
  };
96
- //# sourceMappingURL=reqwest.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shell/curl/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAIpD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAmIvB,CAAA"}
1
+ {"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shell/curl/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAIpD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAoIvB,CAAA"}