@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.
- package/dist/clients/index.js +168 -169
- package/dist/httpsnippet-lite/helpers/code-builder.js +86 -74
- package/dist/httpsnippet-lite/helpers/escape.js +69 -44
- package/dist/httpsnippet-lite/helpers/headers.js +17 -14
- package/dist/httpsnippet-lite/helpers/reducer.js +1 -1
- package/dist/httpsnippet-lite/helpers/shell.js +13 -13
- package/dist/httpsnippet-lite/helpers/snippet-request.js +1 -1
- package/dist/httpsnippet-lite/helpers/url.js +4 -8
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js +69 -67
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +165 -154
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +35 -38
- package/dist/httpsnippet-lite/targets/go/native/client.js +151 -147
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js +32 -35
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js +40 -39
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/java/unirest/client.js +41 -34
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js +81 -76
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js +77 -71
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js +73 -71
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/node/axios/client.js +74 -69
- package/dist/httpsnippet-lite/targets/objc/helpers.js +52 -33
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +123 -121
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js +60 -49
- package/dist/httpsnippet-lite/targets/powershell/common.js +46 -56
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js +9 -13
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js +9 -13
- package/dist/httpsnippet-lite/targets/python/python3/client.js +85 -68
- package/dist/httpsnippet-lite/targets/r/httr/client.js +114 -95
- package/dist/httpsnippet-lite/targets/ruby/native/client.js +66 -70
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js +121 -107
- package/dist/httpsnippet-lite/targets/shell/wget/client.js +48 -43
- package/dist/httpsnippet-lite/targets/swift/helpers.js +62 -44
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js +126 -112
- package/dist/httpsnippet-lite/targets/target.js +1 -1
- package/dist/index.js +2 -9
- package/dist/libs/http.js +68 -56
- package/dist/libs/javascript.js +77 -60
- package/dist/libs/php.js +59 -49
- package/dist/libs/rust.js +60 -33
- package/dist/libs/shell.js +14 -5
- package/dist/plugins/c/libcurl/index.js +1 -5
- package/dist/plugins/c/libcurl/libcurl.js +13 -13
- package/dist/plugins/clojure/clj_http/clj_http.js +13 -13
- package/dist/plugins/clojure/clj_http/index.js +1 -5
- package/dist/plugins/csharp/httpclient/httpclient.js +206 -150
- package/dist/plugins/csharp/httpclient/index.js +1 -5
- package/dist/plugins/csharp/restsharp/index.js +1 -5
- package/dist/plugins/csharp/restsharp/restsharp.js +13 -13
- package/dist/plugins/dart/http/http.js +95 -93
- package/dist/plugins/dart/http/index.js +1 -5
- package/dist/plugins/fsharp/httpclient/httpclient.js +169 -122
- package/dist/plugins/fsharp/httpclient/index.js +1 -5
- package/dist/plugins/go/native/index.js +1 -5
- package/dist/plugins/go/native/native.js +13 -13
- package/dist/plugins/http/http11/http11.d.ts.map +1 -1
- package/dist/plugins/http/http11/http11.js +104 -85
- package/dist/plugins/http/http11/index.js +1 -5
- package/dist/plugins/java/asynchttp/asynchttp.js +13 -13
- package/dist/plugins/java/asynchttp/index.js +1 -5
- package/dist/plugins/java/nethttp/index.js +1 -5
- package/dist/plugins/java/nethttp/nethttp.js +13 -13
- package/dist/plugins/java/okhttp/index.js +1 -5
- package/dist/plugins/java/okhttp/okhttp.js +13 -13
- package/dist/plugins/java/unirest/index.js +1 -5
- package/dist/plugins/java/unirest/unirest.js +13 -13
- package/dist/plugins/js/axios/axios.js +13 -13
- package/dist/plugins/js/axios/index.js +1 -5
- package/dist/plugins/js/fetch/fetch.js +82 -68
- package/dist/plugins/js/fetch/index.js +1 -5
- package/dist/plugins/js/jquery/index.js +1 -5
- package/dist/plugins/js/jquery/jquery.js +13 -13
- package/dist/plugins/js/ofetch/index.js +1 -5
- package/dist/plugins/js/ofetch/ofetch.js +61 -48
- package/dist/plugins/js/xhr/index.js +1 -5
- package/dist/plugins/js/xhr/xhr.js +13 -13
- package/dist/plugins/kotlin/okhttp/index.js +1 -5
- package/dist/plugins/kotlin/okhttp/okhttp.js +13 -13
- package/dist/plugins/node/axios/axios.js +13 -13
- package/dist/plugins/node/axios/index.js +1 -5
- package/dist/plugins/node/fetch/fetch.js +86 -74
- package/dist/plugins/node/fetch/index.js +1 -5
- package/dist/plugins/node/ofetch/index.js +1 -5
- package/dist/plugins/node/ofetch/ofetch.js +61 -48
- package/dist/plugins/node/undici/index.js +1 -5
- package/dist/plugins/node/undici/undici.js +60 -47
- package/dist/plugins/objc/nsurlsession/index.js +1 -5
- package/dist/plugins/objc/nsurlsession/nsurlsession.js +13 -13
- package/dist/plugins/ocaml/cohttp/cohttp.js +13 -13
- package/dist/plugins/ocaml/cohttp/index.js +1 -5
- package/dist/plugins/php/curl/curl.js +143 -101
- package/dist/plugins/php/curl/index.js +1 -5
- package/dist/plugins/php/guzzle/guzzle.d.ts.map +1 -1
- package/dist/plugins/php/guzzle/guzzle.js +109 -83
- package/dist/plugins/php/guzzle/index.js +1 -5
- package/dist/plugins/powershell/restmethod/index.js +1 -5
- package/dist/plugins/powershell/restmethod/restmethod.js +13 -13
- package/dist/plugins/powershell/webrequest/index.js +1 -5
- package/dist/plugins/powershell/webrequest/webrequest.js +13 -13
- package/dist/plugins/python/httpx/async.js +17 -15
- package/dist/plugins/python/httpx/index.js +2 -7
- package/dist/plugins/python/httpx/sync.js +11 -12
- package/dist/plugins/python/python3/index.js +1 -5
- package/dist/plugins/python/python3/python3.js +13 -13
- package/dist/plugins/python/requests/index.js +1 -5
- package/dist/plugins/python/requests/requests.js +11 -12
- package/dist/plugins/python/requestsLike.d.ts.map +1 -1
- package/dist/plugins/python/requestsLike.js +145 -112
- package/dist/plugins/r/httr/httr.js +13 -13
- package/dist/plugins/r/httr/index.js +1 -5
- package/dist/plugins/ruby/native/index.js +1 -5
- package/dist/plugins/ruby/native/native.js +13 -13
- package/dist/plugins/rust/reqwest/index.js +1 -5
- package/dist/plugins/rust/reqwest/reqwest.js +126 -83
- package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
- package/dist/plugins/shell/curl/curl.js +129 -97
- package/dist/plugins/shell/curl/index.js +1 -5
- package/dist/plugins/shell/httpie/httpie.js +13 -13
- package/dist/plugins/shell/httpie/index.js +1 -5
- package/dist/plugins/shell/wget/index.js +1 -5
- package/dist/plugins/shell/wget/wget.js +13 -13
- package/dist/plugins/swift/nsurlsession/index.js +1 -5
- package/dist/plugins/swift/nsurlsession/nsurlsession.js +13 -13
- package/dist/snippetz.js +25 -28
- package/dist/utils/convertWithHttpSnippetLite.js +100 -96
- package/dist/utils/index.js +1 -5
- package/package.json +8 -12
- package/dist/clients/index.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/code-builder.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/escape.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/headers.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/reducer.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/shell.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/snippet-request.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/url.js.map +0 -7
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/go/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/unirest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/node/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/common.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/python/python3/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/r/httr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ruby/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/wget/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/target.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/libs/http.js.map +0 -7
- package/dist/libs/javascript.js.map +0 -7
- package/dist/libs/php.js.map +0 -7
- package/dist/libs/rust.js.map +0 -7
- package/dist/libs/shell.js.map +0 -7
- package/dist/plugins/c/libcurl/index.js.map +0 -7
- package/dist/plugins/c/libcurl/libcurl.js.map +0 -7
- package/dist/plugins/clojure/clj_http/clj_http.js.map +0 -7
- package/dist/plugins/clojure/clj_http/index.js.map +0 -7
- package/dist/plugins/csharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/csharp/httpclient/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/restsharp.js.map +0 -7
- package/dist/plugins/dart/http/http.js.map +0 -7
- package/dist/plugins/dart/http/index.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/index.js.map +0 -7
- package/dist/plugins/go/native/index.js.map +0 -7
- package/dist/plugins/go/native/native.js.map +0 -7
- package/dist/plugins/http/http11/http11.js.map +0 -7
- package/dist/plugins/http/http11/index.js.map +0 -7
- package/dist/plugins/java/asynchttp/asynchttp.js.map +0 -7
- package/dist/plugins/java/asynchttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/nethttp.js.map +0 -7
- package/dist/plugins/java/okhttp/index.js.map +0 -7
- package/dist/plugins/java/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/java/unirest/index.js.map +0 -7
- package/dist/plugins/java/unirest/unirest.js.map +0 -7
- package/dist/plugins/js/axios/axios.js.map +0 -7
- package/dist/plugins/js/axios/index.js.map +0 -7
- package/dist/plugins/js/fetch/fetch.js.map +0 -7
- package/dist/plugins/js/fetch/index.js.map +0 -7
- package/dist/plugins/js/jquery/index.js.map +0 -7
- package/dist/plugins/js/jquery/jquery.js.map +0 -7
- package/dist/plugins/js/ofetch/index.js.map +0 -7
- package/dist/plugins/js/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/js/xhr/index.js.map +0 -7
- package/dist/plugins/js/xhr/xhr.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/index.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/node/axios/axios.js.map +0 -7
- package/dist/plugins/node/axios/index.js.map +0 -7
- package/dist/plugins/node/fetch/fetch.js.map +0 -7
- package/dist/plugins/node/fetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/node/undici/index.js.map +0 -7
- package/dist/plugins/node/undici/undici.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/index.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/cohttp.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/index.js.map +0 -7
- package/dist/plugins/php/curl/curl.js.map +0 -7
- package/dist/plugins/php/curl/index.js.map +0 -7
- package/dist/plugins/php/guzzle/guzzle.js.map +0 -7
- package/dist/plugins/php/guzzle/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/restmethod.js.map +0 -7
- package/dist/plugins/powershell/webrequest/index.js.map +0 -7
- package/dist/plugins/powershell/webrequest/webrequest.js.map +0 -7
- package/dist/plugins/python/httpx/async.js.map +0 -7
- package/dist/plugins/python/httpx/index.js.map +0 -7
- package/dist/plugins/python/httpx/sync.js.map +0 -7
- package/dist/plugins/python/python3/index.js.map +0 -7
- package/dist/plugins/python/python3/python3.js.map +0 -7
- package/dist/plugins/python/requests/index.js.map +0 -7
- package/dist/plugins/python/requests/requests.js.map +0 -7
- package/dist/plugins/python/requestsLike.js.map +0 -7
- package/dist/plugins/r/httr/httr.js.map +0 -7
- package/dist/plugins/r/httr/index.js.map +0 -7
- package/dist/plugins/ruby/native/index.js.map +0 -7
- package/dist/plugins/ruby/native/native.js.map +0 -7
- package/dist/plugins/rust/reqwest/index.js.map +0 -7
- package/dist/plugins/rust/reqwest/reqwest.js.map +0 -7
- package/dist/plugins/shell/curl/curl.js.map +0 -7
- package/dist/plugins/shell/curl/index.js.map +0 -7
- package/dist/plugins/shell/httpie/httpie.js.map +0 -7
- package/dist/plugins/shell/httpie/index.js.map +0 -7
- package/dist/plugins/shell/wget/index.js.map +0 -7
- package/dist/plugins/shell/wget/wget.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/index.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/snippetz.js.map +0 -7
- package/dist/utils/convertWithHttpSnippetLite.js.map +0 -7
- package/dist/utils/index.js.map +0 -7
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { python3 } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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,13 +1,12 @@
|
|
|
1
|
-
import { requestsLikeGenerate } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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,
|
|
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
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
options
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
|
|
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
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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,14 +1,14 @@
|
|
|
1
|
-
import { native } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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,96 +1,139 @@
|
|
|
1
|
-
import { buildQueryString, buildUrl, normalizeRequest, processHeaders } from
|
|
2
|
-
import { createChain, formatJson, indent, wrapInDoubleQuotes } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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,
|
|
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"}
|