@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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
|
|
2
|
+
import { axios } from '../../../../node_modules/httpsnippet-lite/dist/esm/targets/javascript/axios/client.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* js/axios
|
|
6
|
+
*/
|
|
7
|
+
const jsAxios = {
|
|
8
|
+
target: 'js',
|
|
9
|
+
client: 'axios',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(axios, request);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { jsAxios };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/axios/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { jsAxios } from './axios.js';
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
declare global {
|
|
3
|
-
interface Clients extends AddClient<'js', 'fetch'> {
|
|
4
|
-
}
|
|
5
|
-
}
|
|
1
|
+
import { type Plugin } from '../../../core/index.js';
|
|
6
2
|
/**
|
|
7
3
|
* js/fetch
|
|
8
4
|
*/
|
|
9
|
-
export declare
|
|
5
|
+
export declare const jsFetch: Plugin;
|
|
10
6
|
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAiC,MAAM,eAAe,CAAA;AAE1E;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MA6ErB,CAAA"}
|
|
@@ -4,65 +4,66 @@ import { objectToString } from '../../../core/utils/objectToString.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* js/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 jsFetch = {
|
|
8
|
+
target: 'js',
|
|
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: 'js',
|
|
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 { jsFetch };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { jsFetch } from './fetch.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/jquery/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { jsJquery } from './jquery.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jquery.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/jquery/jquery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MAOtB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
|
|
2
|
+
import { jquery } from '../../../../node_modules/httpsnippet-lite/dist/esm/targets/javascript/jquery/client.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* js/jquery
|
|
6
|
+
*/
|
|
7
|
+
const jsJquery = {
|
|
8
|
+
target: 'js',
|
|
9
|
+
client: 'jquery',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(jquery, request);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { jsJquery };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { jsOfetch } from './ofetch.js';
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
declare global {
|
|
3
|
-
interface Clients extends AddClient<'js', 'ofetch'> {
|
|
4
|
-
}
|
|
5
|
-
}
|
|
1
|
+
import { type Plugin } from '../../../core/index.js';
|
|
6
2
|
/**
|
|
7
3
|
* js/ofetch
|
|
8
4
|
*/
|
|
9
|
-
export declare
|
|
5
|
+
export declare const jsOfetch: Plugin;
|
|
10
6
|
//# sourceMappingURL=ofetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAiC,MAAM,eAAe,CAAA;AAE1E;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MAmFtB,CAAA"}
|
|
@@ -4,72 +4,73 @@ import { objectToString } from '../../../core/utils/objectToString.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* js/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 jsOfetch = {
|
|
8
|
+
target: 'js',
|
|
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 { jsOfetch };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/xhr/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { jsXhr } from './xhr.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xhr.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/xhr/xhr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,KAAK,EAAE,MAOnB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
|
|
2
|
+
import { xhr } from '../../../../node_modules/httpsnippet-lite/dist/esm/targets/javascript/xhr/client.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* js/xhr
|
|
6
|
+
*/
|
|
7
|
+
const jsXhr = {
|
|
8
|
+
target: 'js',
|
|
9
|
+
client: 'xhr',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(xhr, request);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { jsXhr };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/kotlin/okhttp/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { kotlinOkhttp } from './okhttp.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"okhttp.d.ts","sourceRoot":"","sources":["../../../../src/plugins/kotlin/okhttp/okhttp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,MAO1B,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
|
|
2
|
+
import { okhttp } from '../../../../node_modules/httpsnippet-lite/dist/esm/targets/kotlin/okhttp/client.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* kotlin/okhttp
|
|
6
|
+
*/
|
|
7
|
+
const kotlinOkhttp = {
|
|
8
|
+
target: 'kotlin',
|
|
9
|
+
client: 'okhttp',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(okhttp, request);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { kotlinOkhttp };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axios.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/axios/axios.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 { axios } from '../../../../node_modules/httpsnippet-lite/dist/esm/targets/node/axios/client.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* node/axios
|
|
6
|
+
*/
|
|
7
|
+
const nodeAxios = {
|
|
8
|
+
target: 'node',
|
|
9
|
+
client: 'axios',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(axios, request);
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { nodeAxios };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/axios/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { nodeAxios } from './axios.js';
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
declare global {
|
|
3
|
-
interface Clients extends AddClient<'node', 'fetch'> {
|
|
4
|
-
}
|
|
5
|
-
}
|
|
1
|
+
import { type Plugin } from '../../../core/index.js';
|
|
6
2
|
/**
|
|
7
3
|
* node/fetch
|
|
8
4
|
*/
|
|
9
|
-
export declare
|
|
5
|
+
export declare const nodeFetch: Plugin;
|
|
10
6
|
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAiC,MAAM,eAAe,CAAA;AAE1E;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MA6EvB,CAAA"}
|