@scalar/snippetz 0.2.5 → 0.2.7
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/README.md +3 -3
- package/dist/core/types.d.ts +46 -11
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/utils/convertWithHttpSnippetLite.d.ts +7 -0
- package/dist/core/utils/convertWithHttpSnippetLite.d.ts.map +1 -0
- package/dist/core/utils/convertWithHttpSnippetLite.js +83 -0
- package/dist/plugins/c/libcurl/index.d.ts +2 -0
- package/dist/plugins/c/libcurl/index.d.ts.map +1 -0
- package/dist/plugins/c/libcurl/index.js +1 -0
- package/dist/plugins/c/libcurl/libcurl.d.ts +6 -0
- package/dist/plugins/c/libcurl/libcurl.d.ts.map +1 -0
- package/dist/plugins/c/libcurl/libcurl.js +16 -0
- package/dist/plugins/clojure/clj_http/clj_http.d.ts +6 -0
- package/dist/plugins/clojure/clj_http/clj_http.d.ts.map +1 -0
- package/dist/plugins/clojure/clj_http/clj_http.js +16 -0
- package/dist/plugins/clojure/clj_http/index.d.ts +2 -0
- package/dist/plugins/clojure/clj_http/index.d.ts.map +1 -0
- package/dist/plugins/clojure/clj_http/index.js +1 -0
- package/dist/plugins/csharp/httpclient/httpclient.d.ts +6 -0
- package/dist/plugins/csharp/httpclient/httpclient.d.ts.map +1 -0
- package/dist/plugins/csharp/httpclient/httpclient.js +16 -0
- package/dist/plugins/csharp/httpclient/index.d.ts +2 -0
- package/dist/plugins/csharp/httpclient/index.d.ts.map +1 -0
- package/dist/plugins/csharp/httpclient/index.js +1 -0
- package/dist/plugins/csharp/restsharp/index.d.ts +2 -0
- package/dist/plugins/csharp/restsharp/index.d.ts.map +1 -0
- package/dist/plugins/csharp/restsharp/index.js +1 -0
- package/dist/plugins/csharp/restsharp/restsharp.d.ts +6 -0
- package/dist/plugins/csharp/restsharp/restsharp.d.ts.map +1 -0
- package/dist/plugins/csharp/restsharp/restsharp.js +16 -0
- package/dist/plugins/go/native/index.d.ts +2 -0
- package/dist/plugins/go/native/index.d.ts.map +1 -0
- package/dist/plugins/go/native/index.js +1 -0
- package/dist/plugins/go/native/native.d.ts +6 -0
- package/dist/plugins/go/native/native.d.ts.map +1 -0
- package/dist/plugins/go/native/native.js +16 -0
- package/dist/plugins/http/http11/http11.d.ts +6 -0
- package/dist/plugins/http/http11/http11.d.ts.map +1 -0
- package/dist/plugins/http/http11/http11.js +16 -0
- package/dist/plugins/http/http11/index.d.ts +2 -0
- package/dist/plugins/http/http11/index.d.ts.map +1 -0
- package/dist/plugins/http/http11/index.js +1 -0
- package/dist/plugins/java/asynchttp/asynchttp.d.ts +6 -0
- package/dist/plugins/java/asynchttp/asynchttp.d.ts.map +1 -0
- package/dist/plugins/java/asynchttp/asynchttp.js +16 -0
- package/dist/plugins/java/asynchttp/index.d.ts +2 -0
- package/dist/plugins/java/asynchttp/index.d.ts.map +1 -0
- package/dist/plugins/java/asynchttp/index.js +1 -0
- package/dist/plugins/java/nethttp/index.d.ts +2 -0
- package/dist/plugins/java/nethttp/index.d.ts.map +1 -0
- package/dist/plugins/java/nethttp/index.js +1 -0
- package/dist/plugins/java/nethttp/nethttp.d.ts +6 -0
- package/dist/plugins/java/nethttp/nethttp.d.ts.map +1 -0
- package/dist/plugins/java/nethttp/nethttp.js +16 -0
- package/dist/plugins/java/okhttp/index.d.ts +2 -0
- package/dist/plugins/java/okhttp/index.d.ts.map +1 -0
- package/dist/plugins/java/okhttp/index.js +1 -0
- package/dist/plugins/java/okhttp/okhttp.d.ts +6 -0
- package/dist/plugins/java/okhttp/okhttp.d.ts.map +1 -0
- package/dist/plugins/java/okhttp/okhttp.js +16 -0
- package/dist/plugins/java/unirest/index.d.ts +2 -0
- package/dist/plugins/java/unirest/index.d.ts.map +1 -0
- package/dist/plugins/java/unirest/index.js +1 -0
- package/dist/plugins/java/unirest/unirest.d.ts +6 -0
- package/dist/plugins/java/unirest/unirest.d.ts.map +1 -0
- package/dist/plugins/java/unirest/unirest.js +16 -0
- package/dist/plugins/js/axios/axios.d.ts +6 -0
- package/dist/plugins/js/axios/axios.d.ts.map +1 -0
- package/dist/plugins/js/axios/axios.js +16 -0
- package/dist/plugins/js/axios/index.d.ts +2 -0
- package/dist/plugins/js/axios/index.d.ts.map +1 -0
- package/dist/plugins/js/axios/index.js +1 -0
- package/dist/plugins/js/fetch/fetch.d.ts +2 -6
- package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/js/fetch/fetch.js +60 -59
- package/dist/plugins/js/fetch/index.js +1 -1
- package/dist/plugins/js/jquery/index.d.ts +2 -0
- package/dist/plugins/js/jquery/index.d.ts.map +1 -0
- package/dist/plugins/js/jquery/index.js +1 -0
- package/dist/plugins/js/jquery/jquery.d.ts +6 -0
- package/dist/plugins/js/jquery/jquery.d.ts.map +1 -0
- package/dist/plugins/js/jquery/jquery.js +16 -0
- package/dist/plugins/js/ofetch/index.js +1 -1
- package/dist/plugins/js/ofetch/ofetch.d.ts +2 -6
- package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/js/ofetch/ofetch.js +65 -64
- package/dist/plugins/js/xhr/index.d.ts +2 -0
- package/dist/plugins/js/xhr/index.d.ts.map +1 -0
- package/dist/plugins/js/xhr/index.js +1 -0
- package/dist/plugins/js/xhr/xhr.d.ts +6 -0
- package/dist/plugins/js/xhr/xhr.d.ts.map +1 -0
- package/dist/plugins/js/xhr/xhr.js +16 -0
- package/dist/plugins/kotlin/okhttp/index.d.ts +2 -0
- package/dist/plugins/kotlin/okhttp/index.d.ts.map +1 -0
- package/dist/plugins/kotlin/okhttp/index.js +1 -0
- package/dist/plugins/kotlin/okhttp/okhttp.d.ts +6 -0
- package/dist/plugins/kotlin/okhttp/okhttp.d.ts.map +1 -0
- package/dist/plugins/kotlin/okhttp/okhttp.js +16 -0
- package/dist/plugins/node/axios/axios.d.ts +6 -0
- package/dist/plugins/node/axios/axios.d.ts.map +1 -0
- package/dist/plugins/node/axios/axios.js +16 -0
- package/dist/plugins/node/axios/index.d.ts +2 -0
- package/dist/plugins/node/axios/index.d.ts.map +1 -0
- package/dist/plugins/node/axios/index.js +1 -0
- package/dist/plugins/node/fetch/fetch.d.ts +2 -6
- package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/node/fetch/fetch.js +60 -59
- package/dist/plugins/node/fetch/index.js +1 -1
- package/dist/plugins/node/ofetch/index.js +1 -1
- package/dist/plugins/node/ofetch/ofetch.d.ts +2 -6
- package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/node/ofetch/ofetch.js +65 -64
- package/dist/plugins/node/undici/index.js +1 -1
- package/dist/plugins/node/undici/undici.d.ts +2 -6
- package/dist/plugins/node/undici/undici.d.ts.map +1 -1
- package/dist/plugins/node/undici/undici.js +60 -59
- package/dist/plugins/objc/nsurlsession/index.d.ts +2 -0
- package/dist/plugins/objc/nsurlsession/index.d.ts.map +1 -0
- package/dist/plugins/objc/nsurlsession/index.js +1 -0
- package/dist/plugins/objc/nsurlsession/nsurlsession.d.ts +6 -0
- package/dist/plugins/objc/nsurlsession/nsurlsession.d.ts.map +1 -0
- package/dist/plugins/objc/nsurlsession/nsurlsession.js +16 -0
- package/dist/plugins/ocaml/cohttp/cohttp.d.ts +6 -0
- package/dist/plugins/ocaml/cohttp/cohttp.d.ts.map +1 -0
- package/dist/plugins/ocaml/cohttp/cohttp.js +16 -0
- package/dist/plugins/ocaml/cohttp/index.d.ts +2 -0
- package/dist/plugins/ocaml/cohttp/index.d.ts.map +1 -0
- package/dist/plugins/ocaml/cohttp/index.js +1 -0
- package/dist/plugins/php/curl/curl.d.ts +6 -0
- package/dist/plugins/php/curl/curl.d.ts.map +1 -0
- package/dist/plugins/php/curl/curl.js +16 -0
- package/dist/plugins/php/curl/index.d.ts +2 -0
- package/dist/plugins/php/curl/index.d.ts.map +1 -0
- package/dist/plugins/php/curl/index.js +1 -0
- package/dist/plugins/php/guzzle/guzzle.d.ts +6 -0
- package/dist/plugins/php/guzzle/guzzle.d.ts.map +1 -0
- package/dist/plugins/php/guzzle/guzzle.js +16 -0
- package/dist/plugins/php/guzzle/index.d.ts +2 -0
- package/dist/plugins/php/guzzle/index.d.ts.map +1 -0
- package/dist/plugins/php/guzzle/index.js +1 -0
- package/dist/plugins/powershell/restmethod/index.d.ts +2 -0
- package/dist/plugins/powershell/restmethod/index.d.ts.map +1 -0
- package/dist/plugins/powershell/restmethod/index.js +1 -0
- package/dist/plugins/powershell/restmethod/restmethod.d.ts +6 -0
- package/dist/plugins/powershell/restmethod/restmethod.d.ts.map +1 -0
- package/dist/plugins/powershell/restmethod/restmethod.js +16 -0
- package/dist/plugins/powershell/webrequest/index.d.ts +2 -0
- package/dist/plugins/powershell/webrequest/index.d.ts.map +1 -0
- package/dist/plugins/powershell/webrequest/index.js +1 -0
- package/dist/plugins/powershell/webrequest/webrequest.d.ts +6 -0
- package/dist/plugins/powershell/webrequest/webrequest.d.ts.map +1 -0
- package/dist/plugins/powershell/webrequest/webrequest.js +16 -0
- package/dist/plugins/python/python3/index.d.ts +2 -0
- package/dist/plugins/python/python3/index.d.ts.map +1 -0
- package/dist/plugins/python/python3/index.js +1 -0
- package/dist/plugins/python/python3/python3.d.ts +6 -0
- package/dist/plugins/python/python3/python3.d.ts.map +1 -0
- package/dist/plugins/python/python3/python3.js +16 -0
- package/dist/plugins/python/requests/index.d.ts +2 -0
- package/dist/plugins/python/requests/index.d.ts.map +1 -0
- package/dist/plugins/python/requests/index.js +1 -0
- package/dist/plugins/python/requests/requests.d.ts +6 -0
- package/dist/plugins/python/requests/requests.d.ts.map +1 -0
- package/dist/plugins/python/requests/requests.js +16 -0
- package/dist/plugins/r/httr/httr.d.ts +6 -0
- package/dist/plugins/r/httr/httr.d.ts.map +1 -0
- package/dist/plugins/r/httr/httr.js +16 -0
- package/dist/plugins/r/httr/index.d.ts +2 -0
- package/dist/plugins/r/httr/index.d.ts.map +1 -0
- package/dist/plugins/r/httr/index.js +1 -0
- package/dist/plugins/ruby/native/index.d.ts +2 -0
- package/dist/plugins/ruby/native/index.d.ts.map +1 -0
- package/dist/plugins/ruby/native/index.js +1 -0
- package/dist/plugins/ruby/native/native.d.ts +6 -0
- package/dist/plugins/ruby/native/native.d.ts.map +1 -0
- package/dist/plugins/ruby/native/native.js +16 -0
- package/dist/plugins/shell/curl/curl.d.ts +2 -6
- package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
- package/dist/plugins/shell/curl/curl.js +95 -95
- package/dist/plugins/shell/curl/index.js +1 -1
- package/dist/plugins/shell/httpie/httpie.d.ts +6 -0
- package/dist/plugins/shell/httpie/httpie.d.ts.map +1 -0
- package/dist/plugins/shell/httpie/httpie.js +16 -0
- package/dist/plugins/shell/httpie/index.d.ts +2 -0
- package/dist/plugins/shell/httpie/index.d.ts.map +1 -0
- package/dist/plugins/shell/httpie/index.js +1 -0
- package/dist/plugins/shell/wget/index.d.ts +2 -0
- package/dist/plugins/shell/wget/index.d.ts.map +1 -0
- package/dist/plugins/shell/wget/index.js +1 -0
- package/dist/plugins/shell/wget/wget.d.ts +6 -0
- package/dist/plugins/shell/wget/wget.d.ts.map +1 -0
- package/dist/plugins/shell/wget/wget.js +16 -0
- package/dist/plugins/swift/nsurlsession/index.d.ts +2 -0
- package/dist/plugins/swift/nsurlsession/index.d.ts.map +1 -0
- package/dist/plugins/swift/nsurlsession/index.js +1 -0
- package/dist/plugins/swift/nsurlsession/nsurlsession.d.ts +6 -0
- package/dist/plugins/swift/nsurlsession/nsurlsession.d.ts.map +1 -0
- package/dist/plugins/swift/nsurlsession/nsurlsession.js +16 -0
- package/dist/snippetz.d.ts +8 -11
- package/dist/snippetz.d.ts.map +1 -1
- package/dist/snippetz.js +78 -23
- package/package.json +146 -1
|
@@ -4,65 +4,66 @@ import { objectToString } from '../../../core/utils/objectToString.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* node/fetch
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
options.headers['Set-Cookie'] = options.headers['Set-Cookie']
|
|
36
|
-
? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
|
|
37
|
-
: `${cookie.name}=${cookie.value}`;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
// Remove undefined keys
|
|
41
|
-
Object.keys(options).forEach((key) => {
|
|
42
|
-
if (options[key] === undefined) {
|
|
43
|
-
delete options[key];
|
|
7
|
+
const nodeFetch = {
|
|
8
|
+
target: 'node',
|
|
9
|
+
client: 'fetch',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// Defaults
|
|
12
|
+
const normalizedRequest = {
|
|
13
|
+
method: 'GET',
|
|
14
|
+
...request,
|
|
15
|
+
};
|
|
16
|
+
// Normalization
|
|
17
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
18
|
+
// Reset fetch defaults
|
|
19
|
+
const options = {
|
|
20
|
+
method: normalizedRequest.method === 'GET'
|
|
21
|
+
? undefined
|
|
22
|
+
: normalizedRequest.method,
|
|
23
|
+
};
|
|
24
|
+
// Query
|
|
25
|
+
const searchParams = new URLSearchParams(normalizedRequest.queryString
|
|
26
|
+
? arrayToObject(normalizedRequest.queryString)
|
|
27
|
+
: undefined);
|
|
28
|
+
const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
|
|
29
|
+
// Headers
|
|
30
|
+
if (normalizedRequest.headers?.length) {
|
|
31
|
+
options.headers = {};
|
|
32
|
+
normalizedRequest.headers.forEach((header) => {
|
|
33
|
+
options.headers[header.name] = header.value;
|
|
34
|
+
});
|
|
44
35
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
// Cookies
|
|
37
|
+
if (normalizedRequest.cookies?.length) {
|
|
38
|
+
options.headers = options.headers || {};
|
|
39
|
+
normalizedRequest.cookies.forEach((cookie) => {
|
|
40
|
+
options.headers['Set-Cookie'] = options.headers['Set-Cookie']
|
|
41
|
+
? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
|
|
42
|
+
: `${cookie.name}=${cookie.value}`;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Remove undefined keys
|
|
46
|
+
Object.keys(options).forEach((key) => {
|
|
47
|
+
if (options[key] === undefined) {
|
|
48
|
+
delete options[key];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
// Add body
|
|
52
|
+
if (normalizedRequest.postData) {
|
|
53
|
+
// Plain text
|
|
54
|
+
options.body = normalizedRequest.postData.text;
|
|
55
|
+
// JSON
|
|
56
|
+
if (normalizedRequest.postData.mimeType === 'application/json') {
|
|
57
|
+
options.body = `JSON.stringify(${objectToString(JSON.parse(options.body))})`;
|
|
58
|
+
}
|
|
53
59
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
target: 'node',
|
|
63
|
-
client: 'fetch',
|
|
64
|
-
code,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
60
|
+
// Transform to JSON
|
|
61
|
+
const jsonOptions = Object.keys(options).length
|
|
62
|
+
? `, ${objectToString(options)}`
|
|
63
|
+
: '';
|
|
64
|
+
// Code Template
|
|
65
|
+
return `fetch('${normalizedRequest.url}${queryString}'${jsonOptions})`;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
67
68
|
|
|
68
|
-
export {
|
|
69
|
+
export { nodeFetch };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { nodeFetch } from './fetch.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { nodeOfetch } from './ofetch.js';
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
declare global {
|
|
3
|
-
interface Clients extends AddClient<'node', 'ofetch'> {
|
|
4
|
-
}
|
|
5
|
-
}
|
|
1
|
+
import { type Plugin } from '../../../core/index.js';
|
|
6
2
|
/**
|
|
7
3
|
* node/ofetch
|
|
8
4
|
*/
|
|
9
|
-
export declare
|
|
5
|
+
export declare const nodeOfetch: Plugin;
|
|
10
6
|
//# sourceMappingURL=ofetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAiC,MAAM,eAAe,CAAA;AAE1E;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAmFxB,CAAA"}
|
|
@@ -4,72 +4,73 @@ import { objectToString } from '../../../core/utils/objectToString.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* node/ofetch
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
searchParams
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
options.headers[header.name] = header.value;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
// Cookies
|
|
37
|
-
if (normalizedRequest.cookies?.length) {
|
|
38
|
-
options.headers = options.headers || {};
|
|
39
|
-
normalizedRequest.cookies.forEach((cookie) => {
|
|
40
|
-
options.headers['Set-Cookie'] = options.headers['Set-Cookie']
|
|
41
|
-
? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
|
|
42
|
-
: `${cookie.name}=${cookie.value}`;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
// Remove undefined keys
|
|
46
|
-
Object.keys(options).forEach((key) => {
|
|
47
|
-
if (options[key] === undefined) {
|
|
48
|
-
delete options[key];
|
|
7
|
+
const nodeOfetch = {
|
|
8
|
+
target: 'node',
|
|
9
|
+
client: 'ofetch',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// Defaults
|
|
12
|
+
const normalizedRequest = {
|
|
13
|
+
method: 'GET',
|
|
14
|
+
...request,
|
|
15
|
+
};
|
|
16
|
+
// Normalization
|
|
17
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
18
|
+
// Reset fetch defaults
|
|
19
|
+
const options = {
|
|
20
|
+
method: normalizedRequest.method === 'GET'
|
|
21
|
+
? undefined
|
|
22
|
+
: normalizedRequest.method,
|
|
23
|
+
};
|
|
24
|
+
// Query
|
|
25
|
+
const searchParams = new URLSearchParams(normalizedRequest.queryString
|
|
26
|
+
? arrayToObject(normalizedRequest.queryString)
|
|
27
|
+
: undefined);
|
|
28
|
+
if (searchParams.size) {
|
|
29
|
+
options.query = {};
|
|
30
|
+
searchParams.forEach((value, key) => {
|
|
31
|
+
options.query[key] = value;
|
|
32
|
+
});
|
|
49
33
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
34
|
+
// Headers
|
|
35
|
+
if (normalizedRequest.headers?.length) {
|
|
36
|
+
options.headers = {};
|
|
37
|
+
normalizedRequest.headers.forEach((header) => {
|
|
38
|
+
options.headers[header.name] = header.value;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// Cookies
|
|
42
|
+
if (normalizedRequest.cookies?.length) {
|
|
43
|
+
options.headers = options.headers || {};
|
|
44
|
+
normalizedRequest.cookies.forEach((cookie) => {
|
|
45
|
+
options.headers['Set-Cookie'] = options.headers['Set-Cookie']
|
|
46
|
+
? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
|
|
47
|
+
: `${cookie.name}=${cookie.value}`;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// Remove undefined keys
|
|
51
|
+
Object.keys(options).forEach((key) => {
|
|
52
|
+
if (options[key] === undefined) {
|
|
53
|
+
delete options[key];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
// Add body
|
|
57
|
+
if (normalizedRequest.postData) {
|
|
58
|
+
// Plain text
|
|
59
|
+
options.body = normalizedRequest.postData.text;
|
|
60
|
+
// JSON
|
|
61
|
+
if (normalizedRequest.postData.mimeType === 'application/json') {
|
|
62
|
+
options.body = JSON.parse(options.body);
|
|
63
|
+
}
|
|
58
64
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const code = `import { ofetch } from 'ofetch'
|
|
65
|
+
// Transform to JSON
|
|
66
|
+
const jsonOptions = Object.keys(options).length
|
|
67
|
+
? `, ${objectToString(options)}`
|
|
68
|
+
: '';
|
|
69
|
+
// Code Template
|
|
70
|
+
return `import { ofetch } from 'ofetch'
|
|
66
71
|
|
|
67
72
|
ofetch('${normalizedRequest.url}'${jsonOptions})`;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
client: 'ofetch',
|
|
71
|
-
code,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
73
|
+
},
|
|
74
|
+
};
|
|
74
75
|
|
|
75
|
-
export {
|
|
76
|
+
export { nodeOfetch };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { nodeUndici } from './undici.js';
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
declare global {
|
|
3
|
-
interface Clients extends AddClient<'node', 'undici'> {
|
|
4
|
-
}
|
|
5
|
-
}
|
|
1
|
+
import { type Plugin } from '../../../core/index.js';
|
|
6
2
|
/**
|
|
7
3
|
* node/undici
|
|
8
4
|
*/
|
|
9
|
-
export declare
|
|
5
|
+
export declare const nodeUndici: Plugin;
|
|
10
6
|
//# sourceMappingURL=undici.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAiC,MAAM,eAAe,CAAA;AAE1E;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MA+ExB,CAAA"}
|
|
@@ -4,67 +4,68 @@ import { objectToString } from '../../../core/utils/objectToString.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* node/undici
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
options.headers['Set-Cookie'] = options.headers['Set-Cookie']
|
|
36
|
-
? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
|
|
37
|
-
: `${cookie.name}=${cookie.value}`;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
// Remove undefined keys
|
|
41
|
-
Object.keys(options).forEach((key) => {
|
|
42
|
-
if (options[key] === undefined) {
|
|
43
|
-
delete options[key];
|
|
7
|
+
const nodeUndici = {
|
|
8
|
+
target: 'node',
|
|
9
|
+
client: 'undici',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// Defaults
|
|
12
|
+
const normalizedRequest = {
|
|
13
|
+
method: 'GET',
|
|
14
|
+
...request,
|
|
15
|
+
};
|
|
16
|
+
// Normalization
|
|
17
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
18
|
+
// Reset undici defaults
|
|
19
|
+
const options = {
|
|
20
|
+
method: normalizedRequest.method === 'GET'
|
|
21
|
+
? undefined
|
|
22
|
+
: normalizedRequest.method,
|
|
23
|
+
};
|
|
24
|
+
// Query
|
|
25
|
+
const searchParams = new URLSearchParams(normalizedRequest.queryString
|
|
26
|
+
? arrayToObject(normalizedRequest.queryString)
|
|
27
|
+
: undefined);
|
|
28
|
+
const queryString = searchParams.size ? `?${searchParams.toString()}` : '';
|
|
29
|
+
// Headers
|
|
30
|
+
if (normalizedRequest.headers?.length) {
|
|
31
|
+
options.headers = {};
|
|
32
|
+
normalizedRequest.headers.forEach((header) => {
|
|
33
|
+
options.headers[header.name] = header.value;
|
|
34
|
+
});
|
|
44
35
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
// Cookies
|
|
37
|
+
if (normalizedRequest.cookies?.length) {
|
|
38
|
+
options.headers = options.headers || {};
|
|
39
|
+
normalizedRequest.cookies.forEach((cookie) => {
|
|
40
|
+
options.headers['Set-Cookie'] = options.headers['Set-Cookie']
|
|
41
|
+
? `${options.headers['Set-Cookie']}; ${cookie.name}=${cookie.value}`
|
|
42
|
+
: `${cookie.name}=${cookie.value}`;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Remove undefined keys
|
|
46
|
+
Object.keys(options).forEach((key) => {
|
|
47
|
+
if (options[key] === undefined) {
|
|
48
|
+
delete options[key];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
// Add body
|
|
52
|
+
if (normalizedRequest.postData) {
|
|
53
|
+
// Plain text
|
|
54
|
+
options.body = normalizedRequest.postData.text;
|
|
55
|
+
// JSON
|
|
56
|
+
if (normalizedRequest.postData.mimeType === 'application/json') {
|
|
57
|
+
options.body = `JSON.stringify(${objectToString(JSON.parse(options.body))})`;
|
|
58
|
+
}
|
|
53
59
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const code = `import { request } from 'undici'
|
|
60
|
+
// Transform to JSON
|
|
61
|
+
const jsonOptions = Object.keys(options).length
|
|
62
|
+
? `, ${objectToString(options)}`
|
|
63
|
+
: '';
|
|
64
|
+
// Code Template
|
|
65
|
+
return `import { request } from 'undici'
|
|
61
66
|
|
|
62
67
|
const { statusCode, body } = await request('${normalizedRequest.url}${queryString}'${jsonOptions})`;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
client: 'undici',
|
|
66
|
-
code,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
69
70
|
|
|
70
|
-
export {
|
|
71
|
+
export { nodeUndici };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/objc/nsurlsession/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { objcNsurlsession } from './nsurlsession.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nsurlsession.d.ts","sourceRoot":"","sources":["../../../../src/plugins/objc/nsurlsession/nsurlsession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAO9B,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
|
|
2
|
+
import { nsurlsession } from '../../../../node_modules/httpsnippet-lite/dist/esm/targets/objc/nsurlsession/client.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* objc/nsurlsession
|
|
6
|
+
*/
|
|
7
|
+
const objcNsurlsession = {
|
|
8
|
+
target: 'objc',
|
|
9
|
+
client: 'nsurlsession',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(nsurlsession, request);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { objcNsurlsession };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cohttp.d.ts","sourceRoot":"","sources":["../../../../src/plugins/ocaml/cohttp/cohttp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,MAOzB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
|
|
2
|
+
import { cohttp } from '../../../../node_modules/httpsnippet-lite/dist/esm/targets/ocaml/cohttp/client.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ocaml/cohttp
|
|
6
|
+
*/
|
|
7
|
+
const ocamlCohttp = {
|
|
8
|
+
target: 'ocaml',
|
|
9
|
+
client: 'cohttp',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(cohttp, request);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { ocamlCohttp };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/ocaml/cohttp/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ocamlCohttp } from './cohttp.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/php/curl/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAOrB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
|
|
2
|
+
import { curl } from '../../../../node_modules/httpsnippet-lite/dist/esm/targets/php/curl/client.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* php/curl
|
|
6
|
+
*/
|
|
7
|
+
const phpCurl = {
|
|
8
|
+
target: 'php',
|
|
9
|
+
client: 'curl',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(curl, request);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { phpCurl };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/php/curl/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { phpCurl } from './curl.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guzzle.d.ts","sourceRoot":"","sources":["../../../../src/plugins/php/guzzle/guzzle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAOvB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
|
|
2
|
+
import { guzzle } from '../../../../node_modules/httpsnippet-lite/dist/esm/targets/php/guzzle/client.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* php/guzzle
|
|
6
|
+
*/
|
|
7
|
+
const phpGuzzle = {
|
|
8
|
+
target: 'php',
|
|
9
|
+
client: 'guzzle',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(guzzle, request);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { phpGuzzle };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/php/guzzle/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { phpGuzzle } from './guzzle.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/powershell/restmethod/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { powershellRestmethod } from './restmethod.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restmethod.d.ts","sourceRoot":"","sources":["../../../../src/plugins/powershell/restmethod/restmethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAOlC,CAAA"}
|