@scalar/snippetz 0.3.0 → 0.3.1
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.d.ts.map +1 -1
- package/dist/clients.js +2 -1
- package/dist/clients.js.map +2 -2
- package/dist/plugins/python/httpx/async.d.ts +6 -0
- package/dist/plugins/python/httpx/async.d.ts.map +1 -0
- package/dist/plugins/python/httpx/async.js +16 -0
- package/dist/plugins/python/httpx/async.js.map +7 -0
- package/dist/plugins/python/httpx/index.d.ts +3 -0
- package/dist/plugins/python/httpx/index.d.ts.map +1 -0
- package/dist/plugins/python/httpx/index.js +3 -0
- package/dist/plugins/python/httpx/index.js.map +7 -0
- package/dist/plugins/python/httpx/sync.d.ts +6 -0
- package/dist/plugins/python/httpx/sync.d.ts.map +1 -0
- package/dist/plugins/python/httpx/sync.js +13 -0
- package/dist/plugins/python/httpx/sync.js.map +7 -0
- package/dist/plugins/python/requests/requests.d.ts.map +1 -1
- package/dist/plugins/python/requests/requests.js +2 -93
- package/dist/plugins/python/requests/requests.js.map +3 -3
- package/dist/plugins/python/requestsLike.d.ts +3 -0
- package/dist/plugins/python/requestsLike.d.ts.map +1 -0
- package/dist/plugins/python/requestsLike.js +120 -0
- package/dist/plugins/python/requestsLike.js.map +7 -0
- package/dist/snippetz.d.ts +1 -1
- package/package.json +8 -3
- package/dist/plugins/c/libcurl/libcurl.test.js +0 -208
- package/dist/plugins/c/libcurl/libcurl.test.js.map +0 -7
- package/dist/plugins/clojure/clj_http/clj_http.test.js +0 -151
- package/dist/plugins/clojure/clj_http/clj_http.test.js.map +0 -7
- package/dist/plugins/dart/http/http.test.js +0 -550
- package/dist/plugins/dart/http/http.test.js.map +0 -7
- package/dist/plugins/go/native/native.test.js +0 -366
- package/dist/plugins/go/native/native.test.js.map +0 -7
- package/dist/plugins/http/http11/http11.test.js +0 -175
- package/dist/plugins/http/http11/http11.test.js.map +0 -7
- package/dist/plugins/java/okhttp/okhttp.test.js +0 -164
- package/dist/plugins/java/okhttp/okhttp.test.js.map +0 -7
- package/dist/plugins/js/fetch/fetch.test.js +0 -214
- package/dist/plugins/js/fetch/fetch.test.js.map +0 -7
- package/dist/plugins/js/ofetch/ofetch.test.js +0 -126
- package/dist/plugins/js/ofetch/ofetch.test.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/okhttp.test.js +0 -164
- package/dist/plugins/kotlin/okhttp/okhttp.test.js.map +0 -7
- package/dist/plugins/node/fetch/fetch.test.js +0 -200
- package/dist/plugins/node/fetch/fetch.test.js.map +0 -7
- package/dist/plugins/node/ofetch/ofetch.test.js +0 -126
- package/dist/plugins/node/ofetch/ofetch.test.js.map +0 -7
- package/dist/plugins/node/undici/undici.test.js +0 -133
- package/dist/plugins/node/undici/undici.test.js.map +0 -7
- package/dist/plugins/php/curl/curl.test.js +0 -564
- package/dist/plugins/php/curl/curl.test.js.map +0 -7
- package/dist/plugins/php/guzzle/guzzle.test.js +0 -546
- package/dist/plugins/php/guzzle/guzzle.test.js.map +0 -7
- package/dist/plugins/python/requests/requests.test.js +0 -419
- package/dist/plugins/python/requests/requests.test.js.map +0 -7
- package/dist/plugins/ruby/native/native.test.js +0 -240
- package/dist/plugins/ruby/native/native.test.js.map +0 -7
- package/dist/plugins/shell/curl/curl.test.js +0 -427
- package/dist/plugins/shell/curl/curl.test.js.map +0 -7
- package/dist/plugins/shell/httpie/httpie.test.js +0 -113
- package/dist/plugins/shell/httpie/httpie.test.js.map +0 -7
- package/dist/plugins/shell/wget/wget.test.js +0 -143
- package/dist/plugins/shell/wget/wget.test.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/nsurlsession.test.js +0 -344
- package/dist/plugins/swift/nsurlsession/nsurlsession.test.js.map +0 -7
- package/dist/snippetz.test.js +0 -79
- package/dist/snippetz.test.js.map +0 -7
- package/dist/utils/convertWithHttpSnippetLite.test.js +0 -106
- package/dist/utils/convertWithHttpSnippetLite.test.js.map +0 -7
- package/dist/utils/create-search-params.test.js +0 -49
- package/dist/utils/create-search-params.test.js.map +0 -7
package/dist/clients.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clients.d.ts","sourceRoot":"","sources":["../src/clients.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clients.d.ts","sourceRoot":"","sources":["../src/clients.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAEpD;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAAM,EAmH3B,CAAA"}
|
package/dist/clients.js
CHANGED
|
@@ -27,6 +27,7 @@ import { powershellRestmethod } from "./plugins/powershell/restmethod/index.js";
|
|
|
27
27
|
import { powershellWebrequest } from "./plugins/powershell/webrequest/index.js";
|
|
28
28
|
import { pythonPython3 } from "./plugins/python/python3/index.js";
|
|
29
29
|
import { pythonRequests } from "./plugins/python/requests/index.js";
|
|
30
|
+
import { pythonHttpxSync, pythonHttpxAsync } from "./plugins/python/httpx/index.js";
|
|
30
31
|
import { rHttr } from "./plugins/r/httr/index.js";
|
|
31
32
|
import { rubyNative } from "./plugins/ruby/native/index.js";
|
|
32
33
|
import { shellCurl } from "./plugins/shell/curl/index.js";
|
|
@@ -122,7 +123,7 @@ const clients = [
|
|
|
122
123
|
key: "python",
|
|
123
124
|
title: "Python",
|
|
124
125
|
default: "python3",
|
|
125
|
-
clients: [pythonPython3, pythonRequests]
|
|
126
|
+
clients: [pythonPython3, pythonRequests, pythonHttpxSync, pythonHttpxAsync]
|
|
126
127
|
},
|
|
127
128
|
{
|
|
128
129
|
key: "r",
|
package/dist/clients.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/clients.ts"],
|
|
4
|
-
"sourcesContent": ["import { cLibcurl } from '@/plugins/c/libcurl/libcurl'\nimport { clojureCljhttp } from '@/plugins/clojure/clj_http'\nimport { csharpHttpclient } from '@/plugins/csharp/httpclient'\nimport { csharpRestsharp } from '@/plugins/csharp/restsharp'\nimport { dartHttp } from '@/plugins/dart/http'\nimport { goNative } from '@/plugins/go/native'\nimport { httpHttp11 } from '@/plugins/http/http11'\nimport { javaAsynchttp } from '@/plugins/java/asynchttp'\nimport { javaNethttp } from '@/plugins/java/nethttp/nethttp'\nimport { javaOkhttp } from '@/plugins/java/okhttp/okhttp'\nimport { javaUnirest } from '@/plugins/java/unirest/unirest'\nimport { jsAxios } from '@/plugins/js/axios'\nimport { jsFetch } from '@/plugins/js/fetch'\nimport { jsJquery } from '@/plugins/js/jquery'\nimport { jsOfetch } from '@/plugins/js/ofetch'\nimport { jsXhr } from '@/plugins/js/xhr'\nimport { kotlinOkhttp } from '@/plugins/kotlin/okhttp'\nimport { nodeAxios } from '@/plugins/node/axios'\nimport { nodeFetch } from '@/plugins/node/fetch'\nimport { nodeOfetch } from '@/plugins/node/ofetch'\nimport { nodeUndici } from '@/plugins/node/undici'\nimport { objcNsurlsession } from '@/plugins/objc/nsurlsession'\nimport { ocamlCohttp } from '@/plugins/ocaml/cohttp'\nimport { phpCurl } from '@/plugins/php/curl'\nimport { phpGuzzle } from '@/plugins/php/guzzle'\nimport { powershellRestmethod } from '@/plugins/powershell/restmethod'\nimport { powershellWebrequest } from '@/plugins/powershell/webrequest'\nimport { pythonPython3 } from '@/plugins/python/python3'\nimport { pythonRequests } from '@/plugins/python/requests'\nimport { rHttr } from '@/plugins/r/httr'\nimport { rubyNative } from '@/plugins/ruby/native'\nimport { shellCurl } from '@/plugins/shell/curl'\nimport { shellHttpie } from '@/plugins/shell/httpie'\nimport { shellWget } from '@/plugins/shell/wget'\nimport { swiftNsurlsession } from '@/plugins/swift/nsurlsession'\nimport type { Target } from '@scalar/types/snippetz'\n\n/**\n * All available clients\n */\nexport const clients: Target[] = [\n {\n key: 'c',\n title: 'C',\n default: 'libcurl',\n clients: [cLibcurl],\n },\n {\n key: 'csharp',\n title: 'C#',\n default: 'restsharp',\n clients: [csharpHttpclient, csharpRestsharp],\n },\n {\n key: 'clojure',\n title: 'Clojure',\n default: 'clj_http',\n clients: [clojureCljhttp],\n },\n {\n key: 'dart',\n title: 'Dart',\n default: 'http',\n clients: [dartHttp],\n },\n {\n key: 'go',\n title: 'Go',\n default: 'native',\n clients: [goNative],\n },\n {\n key: 'http',\n title: 'HTTP',\n default: 'http1.1',\n clients: [httpHttp11],\n },\n {\n key: 'java',\n title: 'Java',\n default: 'unirest',\n clients: [javaAsynchttp, javaNethttp, javaOkhttp, javaUnirest],\n },\n {\n key: 'js',\n title: 'JavaScript',\n default: 'fetch',\n clients: [jsFetch, jsAxios, jsOfetch, jsJquery, jsXhr],\n },\n {\n key: 'kotlin',\n title: 'Kotlin',\n default: 'okhttp',\n clients: [kotlinOkhttp],\n },\n {\n key: 'node',\n title: 'Node.js',\n default: 'fetch',\n clients: [nodeFetch, nodeAxios, nodeOfetch, nodeUndici],\n },\n {\n key: 'objc',\n title: 'Objective-C',\n default: 'nsurlsession',\n clients: [objcNsurlsession],\n },\n {\n key: 'ocaml',\n title: 'OCaml',\n default: 'cohttp',\n clients: [ocamlCohttp],\n },\n {\n key: 'php',\n title: 'PHP',\n default: 'curl',\n clients: [phpCurl, phpGuzzle],\n },\n {\n key: 'powershell',\n title: 'Powershell',\n default: 'webrequest',\n clients: [powershellWebrequest, powershellRestmethod],\n },\n {\n key: 'python',\n title: 'Python',\n default: 'python3',\n clients: [pythonPython3, pythonRequests],\n },\n {\n key: 'r',\n title: 'R',\n default: 'httr',\n clients: [rHttr],\n },\n {\n key: 'ruby',\n title: 'Ruby',\n default: 'native',\n clients: [rubyNative],\n },\n {\n key: 'shell',\n title: 'Shell',\n default: 'curl',\n clients: [shellCurl, shellWget, shellHttpie],\n },\n {\n key: 'swift',\n title: 'Swift',\n default: 'nsurlsession',\n clients: [swiftNsurlsession],\n },\n]\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;A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;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,UAAU;AAAA,EACtB;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,eAAe,aAAa,YAAY,WAAW;AAAA,EAC/D;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,SAAS,SAAS,UAAU,UAAU,KAAK;AAAA,EACvD;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,YAAY;AAAA,EACxB;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,WAAW,WAAW,YAAY,UAAU;AAAA,EACxD;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,gBAAgB;AAAA,EAC5B;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,WAAW;AAAA,EACvB;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,SAAS,SAAS;AAAA,EAC9B;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,sBAAsB,oBAAoB;AAAA,EACtD;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,eAAe,
|
|
4
|
+
"sourcesContent": ["import { cLibcurl } from '@/plugins/c/libcurl/libcurl'\nimport { clojureCljhttp } from '@/plugins/clojure/clj_http'\nimport { csharpHttpclient } from '@/plugins/csharp/httpclient'\nimport { csharpRestsharp } from '@/plugins/csharp/restsharp'\nimport { dartHttp } from '@/plugins/dart/http'\nimport { goNative } from '@/plugins/go/native'\nimport { httpHttp11 } from '@/plugins/http/http11'\nimport { javaAsynchttp } from '@/plugins/java/asynchttp'\nimport { javaNethttp } from '@/plugins/java/nethttp/nethttp'\nimport { javaOkhttp } from '@/plugins/java/okhttp/okhttp'\nimport { javaUnirest } from '@/plugins/java/unirest/unirest'\nimport { jsAxios } from '@/plugins/js/axios'\nimport { jsFetch } from '@/plugins/js/fetch'\nimport { jsJquery } from '@/plugins/js/jquery'\nimport { jsOfetch } from '@/plugins/js/ofetch'\nimport { jsXhr } from '@/plugins/js/xhr'\nimport { kotlinOkhttp } from '@/plugins/kotlin/okhttp'\nimport { nodeAxios } from '@/plugins/node/axios'\nimport { nodeFetch } from '@/plugins/node/fetch'\nimport { nodeOfetch } from '@/plugins/node/ofetch'\nimport { nodeUndici } from '@/plugins/node/undici'\nimport { objcNsurlsession } from '@/plugins/objc/nsurlsession'\nimport { ocamlCohttp } from '@/plugins/ocaml/cohttp'\nimport { phpCurl } from '@/plugins/php/curl'\nimport { phpGuzzle } from '@/plugins/php/guzzle'\nimport { powershellRestmethod } from '@/plugins/powershell/restmethod'\nimport { powershellWebrequest } from '@/plugins/powershell/webrequest'\nimport { pythonPython3 } from '@/plugins/python/python3'\nimport { pythonRequests } from '@/plugins/python/requests'\nimport { pythonHttpxSync, pythonHttpxAsync } from '@/plugins/python/httpx'\nimport { rHttr } from '@/plugins/r/httr'\nimport { rubyNative } from '@/plugins/ruby/native'\nimport { shellCurl } from '@/plugins/shell/curl'\nimport { shellHttpie } from '@/plugins/shell/httpie'\nimport { shellWget } from '@/plugins/shell/wget'\nimport { swiftNsurlsession } from '@/plugins/swift/nsurlsession'\nimport type { Target } from '@scalar/types/snippetz'\n\n/**\n * All available clients\n */\nexport const clients: Target[] = [\n {\n key: 'c',\n title: 'C',\n default: 'libcurl',\n clients: [cLibcurl],\n },\n {\n key: 'csharp',\n title: 'C#',\n default: 'restsharp',\n clients: [csharpHttpclient, csharpRestsharp],\n },\n {\n key: 'clojure',\n title: 'Clojure',\n default: 'clj_http',\n clients: [clojureCljhttp],\n },\n {\n key: 'dart',\n title: 'Dart',\n default: 'http',\n clients: [dartHttp],\n },\n {\n key: 'go',\n title: 'Go',\n default: 'native',\n clients: [goNative],\n },\n {\n key: 'http',\n title: 'HTTP',\n default: 'http1.1',\n clients: [httpHttp11],\n },\n {\n key: 'java',\n title: 'Java',\n default: 'unirest',\n clients: [javaAsynchttp, javaNethttp, javaOkhttp, javaUnirest],\n },\n {\n key: 'js',\n title: 'JavaScript',\n default: 'fetch',\n clients: [jsFetch, jsAxios, jsOfetch, jsJquery, jsXhr],\n },\n {\n key: 'kotlin',\n title: 'Kotlin',\n default: 'okhttp',\n clients: [kotlinOkhttp],\n },\n {\n key: 'node',\n title: 'Node.js',\n default: 'fetch',\n clients: [nodeFetch, nodeAxios, nodeOfetch, nodeUndici],\n },\n {\n key: 'objc',\n title: 'Objective-C',\n default: 'nsurlsession',\n clients: [objcNsurlsession],\n },\n {\n key: 'ocaml',\n title: 'OCaml',\n default: 'cohttp',\n clients: [ocamlCohttp],\n },\n {\n key: 'php',\n title: 'PHP',\n default: 'curl',\n clients: [phpCurl, phpGuzzle],\n },\n {\n key: 'powershell',\n title: 'Powershell',\n default: 'webrequest',\n clients: [powershellWebrequest, powershellRestmethod],\n },\n {\n key: 'python',\n title: 'Python',\n default: 'python3',\n clients: [pythonPython3, pythonRequests, pythonHttpxSync, pythonHttpxAsync],\n },\n {\n key: 'r',\n title: 'R',\n default: 'httr',\n clients: [rHttr],\n },\n {\n key: 'ruby',\n title: 'Ruby',\n default: 'native',\n clients: [rubyNative],\n },\n {\n key: 'shell',\n title: 'Shell',\n default: 'curl',\n clients: [shellCurl, shellWget, shellHttpie],\n },\n {\n key: 'swift',\n title: 'Swift',\n default: 'nsurlsession',\n clients: [swiftNsurlsession],\n },\n]\n"],
|
|
5
|
+
"m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AAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,KAAK;AAAA,EACjB;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,UAAU;AAAA,EACtB;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,WAAW,WAAW,WAAW;AAAA,EAC7C;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS,CAAC,iBAAiB;AAAA,EAC7B;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../../../src/plugins/python/httpx/async.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAGpD;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAc9B,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { requestsLikeGenerate } from "../../../plugins/python/requestsLike.js";
|
|
2
|
+
const pythonHttpxAsync = {
|
|
3
|
+
target: "python",
|
|
4
|
+
client: "httpx_async",
|
|
5
|
+
title: "HTTPX (Async)",
|
|
6
|
+
generate(request, configuration) {
|
|
7
|
+
let formattedReq = requestsLikeGenerate("await client", request, configuration);
|
|
8
|
+
formattedReq = formattedReq.split("\n").map((line) => line.trim() === "" ? line : " " + line).join("\n");
|
|
9
|
+
return `with httpx.AsyncClient() as client:
|
|
10
|
+
${formattedReq}`;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
pythonHttpxAsync
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=async.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/plugins/python/httpx/async.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\nimport { requestsLikeGenerate } from '@/plugins/python/requestsLike'\n\n/**\n * python/httpx_async\n */\nexport const pythonHttpxAsync: Plugin = {\n target: 'python',\n client: 'httpx_async',\n title: 'HTTPX (Async)',\n generate(request, configuration) {\n let formattedReq = requestsLikeGenerate('await client', request, configuration)\n // add indent\n formattedReq = formattedReq\n .split('\\n')\n .map((line) => (line.trim() === '' ? line : ' ' + line))\n .join('\\n')\n\n return `with httpx.AsyncClient() as client:\\n${formattedReq}`\n },\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,4BAA4B;AAK9B,MAAM,mBAA2B;AAAA,EACtC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS,eAAe;AAC/B,QAAI,eAAe,qBAAqB,gBAAgB,SAAS,aAAa;AAE9E,mBAAe,aACZ,MAAM,IAAI,EACV,IAAI,CAAC,SAAU,KAAK,KAAK,MAAM,KAAK,OAAO,SAAS,IAAK,EACzD,KAAK,IAAI;AAEZ,WAAO;AAAA,EAAwC,YAAY;AAAA,EAC7D;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/python/httpx/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../../src/plugins/python/httpx/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAGpD;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAO7B,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { requestsLikeGenerate } from "../../../plugins/python/requestsLike.js";
|
|
2
|
+
const pythonHttpxSync = {
|
|
3
|
+
target: "python",
|
|
4
|
+
client: "httpx_sync",
|
|
5
|
+
title: "HTTPX (Sync)",
|
|
6
|
+
generate(request, configuration) {
|
|
7
|
+
return requestsLikeGenerate("httpx", request, configuration);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
pythonHttpxSync
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/plugins/python/httpx/sync.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\nimport { requestsLikeGenerate } from '@/plugins/python/requestsLike'\n\n/**\n * python/httpx_sync\n */\nexport const pythonHttpxSync: Plugin = {\n target: 'python',\n client: 'httpx_sync',\n title: 'HTTPX (Sync)',\n generate(request, configuration) {\n return requestsLikeGenerate('httpx', request, configuration)\n },\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,4BAA4B;AAK9B,MAAM,kBAA0B;AAAA,EACrC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS,eAAe;AAC/B,WAAO,qBAAqB,SAAS,SAAS,aAAa;AAAA,EAC7D;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../../src/plugins/python/requests/requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../../src/plugins/python/requests/requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAGpD;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAO5B,CAAA"}
|
|
@@ -1,101 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { requestsLikeGenerate } from "../../../plugins/python/requestsLike.js";
|
|
2
2
|
const pythonRequests = {
|
|
3
3
|
target: "python",
|
|
4
4
|
client: "requests",
|
|
5
5
|
title: "Requests",
|
|
6
6
|
generate(request, configuration) {
|
|
7
|
-
|
|
8
|
-
url: "https://example.com",
|
|
9
|
-
method: "get",
|
|
10
|
-
...request
|
|
11
|
-
};
|
|
12
|
-
const method = normalizedRequest.method.toLowerCase();
|
|
13
|
-
const options = {};
|
|
14
|
-
if (normalizedRequest.headers?.length) {
|
|
15
|
-
options.headers = normalizedRequest.headers.reduce(
|
|
16
|
-
(acc, header) => {
|
|
17
|
-
if (!(header.name in acc)) {
|
|
18
|
-
acc[header.name] = header.value;
|
|
19
|
-
}
|
|
20
|
-
return acc;
|
|
21
|
-
},
|
|
22
|
-
{}
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
if (normalizedRequest.queryString?.length) {
|
|
26
|
-
options.params = Object.fromEntries(normalizedRequest.queryString.map((q) => [q.name, q.value]));
|
|
27
|
-
}
|
|
28
|
-
if (normalizedRequest.cookies?.length) {
|
|
29
|
-
options.cookies = Object.fromEntries(normalizedRequest.cookies.map((c) => [c.name, c.value]));
|
|
30
|
-
}
|
|
31
|
-
if (configuration?.auth?.username && configuration?.auth?.password) {
|
|
32
|
-
options.auth = [configuration.auth.username, configuration.auth.password];
|
|
33
|
-
}
|
|
34
|
-
if (normalizedRequest.postData) {
|
|
35
|
-
const { mimeType, text, params } = normalizedRequest.postData;
|
|
36
|
-
if (mimeType === "application/json" && text) {
|
|
37
|
-
try {
|
|
38
|
-
options.json = JSON.parse(text);
|
|
39
|
-
} catch {
|
|
40
|
-
options.data = text;
|
|
41
|
-
}
|
|
42
|
-
} else if (mimeType === "application/octet-stream" && text) {
|
|
43
|
-
options.data = text;
|
|
44
|
-
} else if (mimeType === "multipart/form-data" && params) {
|
|
45
|
-
const files = [];
|
|
46
|
-
const formData = {};
|
|
47
|
-
params.forEach((param) => {
|
|
48
|
-
if (param.fileName !== void 0) {
|
|
49
|
-
files.push({ key: param.name, file: `open("${param.fileName}", "rb")` });
|
|
50
|
-
} else if (param.value !== void 0) {
|
|
51
|
-
formData[param.name] = param.value;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
if (Object.keys(files).length) {
|
|
55
|
-
options.files = files;
|
|
56
|
-
}
|
|
57
|
-
if (Object.keys(formData).length) {
|
|
58
|
-
options.data = formData;
|
|
59
|
-
}
|
|
60
|
-
} else if (mimeType === "application/x-www-form-urlencoded" && params) {
|
|
61
|
-
options.data = Object.fromEntries(params.map((p) => [p.name, p.value]));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const formattedParams = [];
|
|
65
|
-
const urlParam = `"${normalizedRequest.url}"`;
|
|
66
|
-
if (normalizedRequest.url.length > LENGTH_CONSIDERED_AS_SHORT) {
|
|
67
|
-
formattedParams.push(urlParam);
|
|
68
|
-
} else {
|
|
69
|
-
formattedParams.push("");
|
|
70
|
-
}
|
|
71
|
-
for (const [key, value] of Object.entries(options)) {
|
|
72
|
-
if (key === "auth") {
|
|
73
|
-
formattedParams.push(`${key}=(${JSON.stringify(value[0])}, ${JSON.stringify(value[1])})`);
|
|
74
|
-
} else if (key === "files") {
|
|
75
|
-
const filesTuples = value.map(({ key: key2, file }) => ` ("${key2}", ${file})`);
|
|
76
|
-
const filesStr = "[\n" + filesTuples.join(",\n") + "\n ]";
|
|
77
|
-
formattedParams.push(`${key}=${filesStr}`);
|
|
78
|
-
} else if (key === "json") {
|
|
79
|
-
const jsonString = JSON.stringify(value, null, 2).split("\n").map((line, i) => i === 0 ? line : " " + line).join("\n");
|
|
80
|
-
formattedParams.push(`${key}=${jsonString}`);
|
|
81
|
-
} else if (key === "data" && normalizedRequest.postData?.mimeType === "application/octet-stream") {
|
|
82
|
-
formattedParams.push(`${key}=b"${value}"`);
|
|
83
|
-
} else {
|
|
84
|
-
const str = JSON.stringify(value, null, 2).split("\n").map((line, i) => i === 0 ? line : " " + line).join("\n");
|
|
85
|
-
formattedParams.push(`${key}=${str}`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (normalizedRequest.url.length > LENGTH_CONSIDERED_AS_SHORT) {
|
|
89
|
-
return `requests.${method}(
|
|
90
|
-
${formattedParams.join(",\n ")}
|
|
91
|
-
)`;
|
|
92
|
-
}
|
|
93
|
-
if (formattedParams.length <= 1) {
|
|
94
|
-
return `requests.${method}(${urlParam})`;
|
|
95
|
-
}
|
|
96
|
-
return `requests.${method}(${urlParam}${formattedParams.length > 1 ? "," : ""}
|
|
97
|
-
${formattedParams.slice(1).join(",\n ")}
|
|
98
|
-
)`;
|
|
7
|
+
return requestsLikeGenerate("requests", request, configuration);
|
|
99
8
|
}
|
|
100
9
|
};
|
|
101
10
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/python/requests/requests.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import type { Plugin } from '@scalar/types/snippetz'\nimport { requestsLikeGenerate } from '@/plugins/python/requestsLike'\n\n/**\n * python/requests\n */\nexport const pythonRequests: Plugin = {\n target: 'python',\n client: 'requests',\n title: 'Requests',\n generate(request, configuration) {\n return requestsLikeGenerate('requests', request, configuration)\n },\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,4BAA4B;AAK9B,MAAM,iBAAyB;AAAA,EACpC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS,eAAe;AAC/B,WAAO,qBAAqB,YAAY,SAAS,aAAa;AAAA,EAChE;AACF;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +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;AAwB7E,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,EAC7B,aAAa,CAAC,EAAE,mBAAmB,UAsIpC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const LENGTH_CONSIDERED_AS_SHORT = 40;
|
|
2
|
+
function convertToPythonSyntax(str) {
|
|
3
|
+
const replacements = [
|
|
4
|
+
["true", "True"],
|
|
5
|
+
["false", "False"],
|
|
6
|
+
["null", "None"]
|
|
7
|
+
];
|
|
8
|
+
let result = str;
|
|
9
|
+
for (const [jsonVal, pythonVal] of replacements) {
|
|
10
|
+
const patterns = [`(: )${jsonVal}(?=,|\\n)`, `^( +)${jsonVal}(?=,|\\n)`];
|
|
11
|
+
for (const pattern of patterns) {
|
|
12
|
+
result = result.replace(new RegExp(pattern, "gm"), `$1${pythonVal}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
function requestsLikeGenerate(clientVar, request, configuration) {
|
|
18
|
+
const normalizedRequest = {
|
|
19
|
+
url: "https://example.com",
|
|
20
|
+
method: "get",
|
|
21
|
+
...request
|
|
22
|
+
};
|
|
23
|
+
const method = normalizedRequest.method.toLowerCase();
|
|
24
|
+
const options = {};
|
|
25
|
+
if (normalizedRequest.headers?.length) {
|
|
26
|
+
options.headers = normalizedRequest.headers.reduce(
|
|
27
|
+
(acc, header) => {
|
|
28
|
+
if (!(header.name in acc)) {
|
|
29
|
+
acc[header.name] = header.value;
|
|
30
|
+
}
|
|
31
|
+
return acc;
|
|
32
|
+
},
|
|
33
|
+
{}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (normalizedRequest.queryString?.length) {
|
|
37
|
+
options.params = Object.fromEntries(normalizedRequest.queryString.map((q) => [q.name, q.value]));
|
|
38
|
+
}
|
|
39
|
+
if (normalizedRequest.cookies?.length) {
|
|
40
|
+
options.cookies = Object.fromEntries(normalizedRequest.cookies.map((c) => [c.name, c.value]));
|
|
41
|
+
}
|
|
42
|
+
if (configuration?.auth?.username && configuration?.auth?.password) {
|
|
43
|
+
options.auth = [configuration.auth.username, configuration.auth.password];
|
|
44
|
+
}
|
|
45
|
+
if (normalizedRequest.postData) {
|
|
46
|
+
const { mimeType, text, params } = normalizedRequest.postData;
|
|
47
|
+
if (mimeType === "application/json" && text) {
|
|
48
|
+
try {
|
|
49
|
+
options.json = JSON.parse(text);
|
|
50
|
+
} catch {
|
|
51
|
+
options.data = text;
|
|
52
|
+
}
|
|
53
|
+
} else if (mimeType === "application/octet-stream" && text) {
|
|
54
|
+
options.data = text;
|
|
55
|
+
} else if (mimeType === "multipart/form-data" && params) {
|
|
56
|
+
const files = [];
|
|
57
|
+
const formData = {};
|
|
58
|
+
params.forEach((param) => {
|
|
59
|
+
if (param.fileName !== void 0) {
|
|
60
|
+
files.push({ key: param.name, file: `open("${param.fileName}", "rb")` });
|
|
61
|
+
} else if (param.value !== void 0) {
|
|
62
|
+
formData[param.name] = param.value;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
if (Object.keys(files).length) {
|
|
66
|
+
options.files = files;
|
|
67
|
+
}
|
|
68
|
+
if (Object.keys(formData).length) {
|
|
69
|
+
options.data = formData;
|
|
70
|
+
}
|
|
71
|
+
} else if (mimeType === "application/x-www-form-urlencoded" && params) {
|
|
72
|
+
options.data = Object.fromEntries(params.map((p) => [p.name, p.value]));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const formattedParams = [];
|
|
76
|
+
const urlParam = `"${normalizedRequest.url}"`;
|
|
77
|
+
if (normalizedRequest.url.length > LENGTH_CONSIDERED_AS_SHORT) {
|
|
78
|
+
formattedParams.push(urlParam);
|
|
79
|
+
} else {
|
|
80
|
+
formattedParams.push("");
|
|
81
|
+
}
|
|
82
|
+
for (const [key, value] of Object.entries(options)) {
|
|
83
|
+
if (key === "auth") {
|
|
84
|
+
formattedParams.push(
|
|
85
|
+
`${key}=(${convertToPythonSyntax(JSON.stringify(value[0]))}, ${convertToPythonSyntax(JSON.stringify(value[1]))})`
|
|
86
|
+
);
|
|
87
|
+
} else if (key === "files") {
|
|
88
|
+
const filesTuples = value.map(({ key: key2, file }) => ` ("${key2}", ${file})`);
|
|
89
|
+
const filesStr = "[\n" + filesTuples.join(",\n") + "\n ]";
|
|
90
|
+
formattedParams.push(`${key}=${filesStr}`);
|
|
91
|
+
} else if (key === "json") {
|
|
92
|
+
const jsonString = convertToPythonSyntax(
|
|
93
|
+
JSON.stringify(value, null, 2).split("\n").map((line, i) => i === 0 ? line : " " + line).join("\n")
|
|
94
|
+
);
|
|
95
|
+
formattedParams.push(`${key}=${jsonString}`);
|
|
96
|
+
} else if (key === "data" && normalizedRequest.postData?.mimeType === "application/octet-stream") {
|
|
97
|
+
formattedParams.push(`${key}=b"${value}"`);
|
|
98
|
+
} else {
|
|
99
|
+
const str = convertToPythonSyntax(
|
|
100
|
+
JSON.stringify(value, null, 2).split("\n").map((line, i) => i === 0 ? line : " " + line).join("\n")
|
|
101
|
+
);
|
|
102
|
+
formattedParams.push(`${key}=${str}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (normalizedRequest.url.length > LENGTH_CONSIDERED_AS_SHORT) {
|
|
106
|
+
return `${clientVar}.${method}(
|
|
107
|
+
${formattedParams.join(",\n ")}
|
|
108
|
+
)`;
|
|
109
|
+
}
|
|
110
|
+
if (formattedParams.length <= 1) {
|
|
111
|
+
return `${clientVar}.${method}(${urlParam})`;
|
|
112
|
+
}
|
|
113
|
+
return `${clientVar}.${method}(${urlParam}${formattedParams.length > 1 ? "," : ""}
|
|
114
|
+
${formattedParams.slice(1).join(",\n ")}
|
|
115
|
+
)`;
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
requestsLikeGenerate
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=requestsLike.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/python/requestsLike.ts"],
|
|
4
|
+
"sourcesContent": ["import type { HarRequest, PluginConfiguration } from '@scalar/types/snippetz'\n\nconst LENGTH_CONSIDERED_AS_SHORT = 40\n\n// Function to convert JavaScript boolean and null values to Python equivalents\nfunction convertToPythonSyntax(str: string): string {\n const replacements = [\n ['true', 'True'],\n ['false', 'False'],\n ['null', 'None'],\n ]\n\n let result = str\n for (const [jsonVal, pythonVal] of replacements) {\n const patterns = [`(: )${jsonVal}(?=,|\\\\n)`, `^( +)${jsonVal}(?=,|\\\\n)`]\n\n for (const pattern of patterns) {\n result = result.replace(new RegExp(pattern, 'gm'), `$1${pythonVal}`)\n }\n }\n\n return result\n}\n\nexport function requestsLikeGenerate(\n clientVar: string,\n request?: Partial<HarRequest>,\n configuration?: PluginConfiguration,\n) {\n // Normalize request with defaults\n const normalizedRequest = {\n url: 'https://example.com',\n method: 'get',\n ...request,\n }\n\n // Normalize method to lowercase for requests library\n const method = normalizedRequest.method.toLowerCase()\n\n // Build options object\n const options: Record<string, any> = {}\n\n // Add headers if present\n if (normalizedRequest.headers?.length) {\n options.headers = normalizedRequest.headers.reduce(\n (acc, header) => {\n if (!(header.name in acc)) {\n acc[header.name] = header.value\n }\n return acc\n },\n {} as Record<string, string>,\n )\n }\n\n // Add query parameters if present\n if (normalizedRequest.queryString?.length) {\n options.params = Object.fromEntries(normalizedRequest.queryString.map((q) => [q.name, q.value]))\n }\n\n // Add cookies if present\n if (normalizedRequest.cookies?.length) {\n options.cookies = Object.fromEntries(normalizedRequest.cookies.map((c) => [c.name, c.value]))\n }\n\n // Add auth if present\n if (configuration?.auth?.username && configuration?.auth?.password) {\n options.auth = [configuration.auth.username, configuration.auth.password]\n }\n\n // Handle request body\n if (normalizedRequest.postData) {\n const { mimeType, text, params } = normalizedRequest.postData\n\n if (mimeType === 'application/json' && text) {\n try {\n options.json = JSON.parse(text)\n } catch {\n options.data = text\n }\n } else if (mimeType === 'application/octet-stream' && text) {\n options.data = text // Store raw text, we'll handle the b\"...\" formatting later\n } else if (mimeType === 'multipart/form-data' && params) {\n const files: { key: string; file: string }[] = []\n const formData: Record<string, string> = {}\n\n params.forEach((param) => {\n if (param.fileName !== undefined) {\n files.push({ key: param.name, file: `open(\"${param.fileName}\", \"rb\")` })\n } else if (param.value !== undefined) {\n formData[param.name] = param.value\n }\n })\n\n if (Object.keys(files).length) {\n options.files = files\n }\n if (Object.keys(formData).length) {\n options.data = formData\n }\n } else if (mimeType === 'application/x-www-form-urlencoded' && params) {\n options.data = Object.fromEntries(params.map((p) => [p.name, p.value]))\n }\n }\n\n // Format all parameters\n const formattedParams: string[] = []\n\n // Format URL based on length\n const urlParam = `\"${normalizedRequest.url}\"`\n if (normalizedRequest.url.length > LENGTH_CONSIDERED_AS_SHORT) {\n formattedParams.push(urlParam)\n } else {\n // Will be handled in the return statement for short URLs\n formattedParams.push('')\n }\n\n // Format options\n for (const [key, value] of Object.entries(options)) {\n if (key === 'auth') {\n formattedParams.push(\n `${key}=(${convertToPythonSyntax(JSON.stringify(value[0]))}, ${convertToPythonSyntax(JSON.stringify(value[1]))})`,\n )\n } else if (key === 'files') {\n const filesTuples = value.map(({ key, file }: { key: string; file: string }) => ` (\"${key}\", ${file})`)\n const filesStr = '[\\n' + filesTuples.join(',\\n') + '\\n ]'\n formattedParams.push(`${key}=${filesStr}`)\n } else if (key === 'json') {\n const jsonString = convertToPythonSyntax(\n JSON.stringify(value, null, 2)\n .split('\\n')\n .map((line, i) => (i === 0 ? line : ' ' + line))\n .join('\\n'),\n )\n formattedParams.push(`${key}=${jsonString}`)\n } else if (key === 'data' && normalizedRequest.postData?.mimeType === 'application/octet-stream') {\n // Special handling for binary data\n formattedParams.push(`${key}=b\"${value}\"`)\n } else {\n const str = convertToPythonSyntax(\n JSON.stringify(value, null, 2)\n .split('\\n')\n .map((line, i) => (i === 0 ? line : ' ' + line))\n .join('\\n'),\n )\n formattedParams.push(`${key}=${str}`)\n }\n }\n\n // Build the final request string with conditional URL formatting\n if (normalizedRequest.url.length > LENGTH_CONSIDERED_AS_SHORT) {\n return `${clientVar}.${method}(\\n ${formattedParams.join(',\\n ')}\\n)`\n }\n\n // For short URLs with no additional parameters, return a single-line format\n if (formattedParams.length <= 1) {\n return `${clientVar}.${method}(${urlParam})`\n }\n\n // For short URLs with parameters, maintain the multi-line format\n return `${clientVar}.${method}(${urlParam}${formattedParams.length > 1 ? ',' : ''}\\n ${formattedParams.slice(1).join(',\\n ')}\\n)`\n}\n"],
|
|
5
|
+
"mappings": "AAEA,MAAM,6BAA6B;AAGnC,SAAS,sBAAsB,KAAqB;AAClD,QAAM,eAAe;AAAA,IACnB,CAAC,QAAQ,MAAM;AAAA,IACf,CAAC,SAAS,OAAO;AAAA,IACjB,CAAC,QAAQ,MAAM;AAAA,EACjB;AAEA,MAAI,SAAS;AACb,aAAW,CAAC,SAAS,SAAS,KAAK,cAAc;AAC/C,UAAM,WAAW,CAAC,OAAO,OAAO,aAAa,QAAQ,OAAO,WAAW;AAEvE,eAAW,WAAW,UAAU;AAC9B,eAAS,OAAO,QAAQ,IAAI,OAAO,SAAS,IAAI,GAAG,KAAK,SAAS,EAAE;AAAA,IACrE;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,qBACd,WACA,SACA,eACA;AAEA,QAAM,oBAAoB;AAAA,IACxB,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,GAAG;AAAA,EACL;AAGA,QAAM,SAAS,kBAAkB,OAAO,YAAY;AAGpD,QAAM,UAA+B,CAAC;AAGtC,MAAI,kBAAkB,SAAS,QAAQ;AACrC,YAAQ,UAAU,kBAAkB,Q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,IAC7C,WAAW,QAAQ,UAAU,kBAAkB,UAAU,aAAa,4BAA4B;AAEhG,sBAAgB,KAAK,GAAG,GAAG,MAAM,KAAK,GAAG;AAAA,IAC3C,OAAO;AACL,YAAM,MAAM;AAAA,QACV,KAAK,UAAU,OAAO,MAAM,CAAC,EAC1B,MAAM,IAAI,EACV,IAAI,CAAC,MAAM,MAAO,MAAM,IAAI,OAAO,SAAS,IAAK,EACjD,KAAK,IAAI;AAAA,MACd;AACA,sBAAgB,KAAK,GAAG,GAAG,IAAI,GAAG,EAAE;AAAA,IACtC;AAAA,EACF;AAGA,MAAI,kBAAkB,IAAI,SAAS,4BAA4B;AAC7D,WAAO,GAAG,SAAS,IAAI,MAAM;AAAA,MAAU,gBAAgB,KAAK,SAAS,CAAC;AAAA;AAAA,EACxE;AAGA,MAAI,gBAAgB,UAAU,GAAG;AAC/B,WAAO,GAAG,SAAS,IAAI,MAAM,IAAI,QAAQ;AAAA,EAC3C;AAGA,SAAO,GAAG,SAAS,IAAI,MAAM,IAAI,QAAQ,GAAG,gBAAgB,SAAS,IAAI,MAAM,EAAE;AAAA,MAAS,gBAAgB,MAAM,CAAC,EAAE,KAAK,SAAS,CAAC;AAAA;AACpI;",
|
|
6
|
+
"names": ["key"]
|
|
7
|
+
}
|
package/dist/snippetz.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare function snippetz(): {
|
|
|
7
7
|
clients(): import("@scalar/types/snippetz").Target[];
|
|
8
8
|
plugins(): {
|
|
9
9
|
target: "c" | "clojure" | "csharp" | "go" | "http" | "java" | "js" | "kotlin" | "node" | "objc" | "ocaml" | "php" | "powershell" | "python" | "r" | "ruby" | "shell" | "swift" | "dart";
|
|
10
|
-
client: "libcurl" | "clj_http" | "httpclient" | "restsharp" | "native" | "http" | "http1.1" | "asynchttp" | "nethttp" | "okhttp" | "unirest" | "axios" | "fetch" | "jquery" | "ofetch" | "xhr" | "undici" | "nsurlsession" | "cohttp" | "curl" | "guzzle" | "restmethod" | "webrequest" | "python3" | "requests" | "httr" | "httpie" | "wget";
|
|
10
|
+
client: "libcurl" | "clj_http" | "httpclient" | "restsharp" | "native" | "http" | "http1.1" | "asynchttp" | "nethttp" | "okhttp" | "unirest" | "axios" | "fetch" | "jquery" | "ofetch" | "xhr" | "undici" | "nsurlsession" | "cohttp" | "curl" | "guzzle" | "restmethod" | "webrequest" | "python3" | "requests" | "httpx_sync" | "httpx_async" | "httr" | "httpie" | "wget";
|
|
11
11
|
}[];
|
|
12
12
|
findPlugin: <T extends TargetId>(target: T | string, client: ClientId<T> | string) => import("@scalar/types/snippetz").Plugin | undefined;
|
|
13
13
|
hasPlugin<T extends TargetId>(target: T | string, client: ClientId<T> | string): boolean;
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/scalar/scalar.git",
|
|
10
10
|
"directory": "packages/snippetz"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.3.
|
|
12
|
+
"version": "0.3.1",
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=20"
|
|
15
15
|
},
|
|
@@ -156,6 +156,11 @@
|
|
|
156
156
|
"types": "./dist/plugins/powershell/webrequest/index.d.ts",
|
|
157
157
|
"default": "./dist/plugins/powershell/webrequest/index.js"
|
|
158
158
|
},
|
|
159
|
+
"./plugins/python/httpx": {
|
|
160
|
+
"import": "./dist/plugins/python/httpx/index.js",
|
|
161
|
+
"types": "./dist/plugins/python/httpx/index.d.ts",
|
|
162
|
+
"default": "./dist/plugins/python/httpx/index.js"
|
|
163
|
+
},
|
|
159
164
|
"./plugins/python/python3": {
|
|
160
165
|
"import": "./dist/plugins/python/python3/index.js",
|
|
161
166
|
"types": "./dist/plugins/python/python3/index.d.ts",
|
|
@@ -212,8 +217,8 @@
|
|
|
212
217
|
},
|
|
213
218
|
"devDependencies": {
|
|
214
219
|
"vite": "5.4.19",
|
|
215
|
-
"@scalar/build-tooling": "0.2.
|
|
216
|
-
"@scalar/types": "0.2.
|
|
220
|
+
"@scalar/build-tooling": "0.2.3",
|
|
221
|
+
"@scalar/types": "0.2.3"
|
|
217
222
|
},
|
|
218
223
|
"scripts": {
|
|
219
224
|
"build": "scalar-build-esbuild",
|