@scalar/snippetz 0.2.7 → 0.2.9
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 +6 -0
- package/dist/clients.d.ts.map +1 -0
- package/dist/clients.js +150 -0
- package/dist/httpsnippet-lite/esm/helpers/code-builder.d.ts +8 -0
- package/dist/httpsnippet-lite/esm/helpers/code-builder.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/helpers/code-builder.js +62 -0
- package/dist/httpsnippet-lite/esm/helpers/escape.d.ts +29 -0
- package/dist/httpsnippet-lite/esm/helpers/escape.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/helpers/escape.js +74 -0
- package/dist/httpsnippet-lite/esm/helpers/form-data.d.ts +3 -0
- package/dist/httpsnippet-lite/esm/helpers/form-data.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/helpers/headers.d.ts +17 -0
- package/dist/httpsnippet-lite/esm/helpers/headers.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/helpers/headers.js +22 -0
- package/dist/httpsnippet-lite/esm/helpers/reducer.d.ts +2 -0
- package/dist/httpsnippet-lite/esm/helpers/reducer.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/helpers/shell.d.ts +7 -0
- package/dist/httpsnippet-lite/esm/helpers/shell.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/helpers/shell.js +18 -0
- package/dist/httpsnippet-lite/esm/helpers/url.d.ts +5 -0
- package/dist/httpsnippet-lite/esm/helpers/url.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/helpers/utils.d.ts +3 -0
- package/dist/httpsnippet-lite/esm/helpers/utils.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/httpsnippet.d.ts +10 -0
- package/dist/httpsnippet-lite/esm/httpsnippet.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.d.ts +16 -0
- package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js +45 -0
- package/dist/httpsnippet-lite/esm/targets/c/target.d.ts +26 -0
- package/dist/httpsnippet-lite/esm/targets/c/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/clojure/clj_http/client.d.ts +16 -0
- package/dist/httpsnippet-lite/esm/targets/clojure/clj_http/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/clojure/clj_http/client.js +189 -0
- package/dist/httpsnippet-lite/esm/targets/clojure/target.d.ts +26 -0
- package/dist/httpsnippet-lite/esm/targets/clojure/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/httpclient/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/httpclient/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/httpclient/client.js +169 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/restsharp/client.d.ts +17 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/restsharp/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/restsharp/client.js +49 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/target.d.ts +41 -0
- package/dist/httpsnippet-lite/esm/targets/csharp/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/go/native/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/go/native/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/go/native/client.js +124 -0
- package/dist/httpsnippet-lite/esm/targets/go/target.d.ts +25 -0
- package/dist/httpsnippet-lite/esm/targets/go/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/http/http1.1/client.d.ts +22 -0
- package/dist/httpsnippet-lite/esm/targets/http/http1.1/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/http/http1.1/client.js +77 -0
- package/dist/httpsnippet-lite/esm/targets/http/target.d.ts +27 -0
- package/dist/httpsnippet-lite/esm/targets/http/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/java/asynchttp/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/java/asynchttp/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/java/asynchttp/client.js +47 -0
- package/dist/httpsnippet-lite/esm/targets/java/nethttp/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/java/nethttp/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/java/nethttp/client.js +46 -0
- package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.js +73 -0
- package/dist/httpsnippet-lite/esm/targets/java/target.d.ts +67 -0
- package/dist/httpsnippet-lite/esm/targets/java/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/java/unirest/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/java/unirest/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/java/unirest/client.js +47 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/axios/client.d.ts +16 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/axios/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/axios/client.js +91 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/fetch/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/fetch/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/jquery/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/jquery/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/jquery/client.js +88 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/target.d.ts +68 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/xhr/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/xhr/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/javascript/xhr/client.js +86 -0
- package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.js +73 -0
- package/dist/httpsnippet-lite/esm/targets/kotlin/target.d.ts +25 -0
- package/dist/httpsnippet-lite/esm/targets/kotlin/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/node/axios/client.d.ts +16 -0
- package/dist/httpsnippet-lite/esm/targets/node/axios/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/node/axios/client.js +83 -0
- package/dist/httpsnippet-lite/esm/targets/node/fetch/client.d.ts +16 -0
- package/dist/httpsnippet-lite/esm/targets/node/fetch/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/node/native/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/node/native/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/node/request/client.d.ts +17 -0
- package/dist/httpsnippet-lite/esm/targets/node/request/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/node/target.d.ts +87 -0
- package/dist/httpsnippet-lite/esm/targets/node/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/node/unirest/client.d.ts +17 -0
- package/dist/httpsnippet-lite/esm/targets/node/unirest/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/objc/helpers.d.ts +27 -0
- package/dist/httpsnippet-lite/esm/targets/objc/helpers.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/objc/helpers.js +58 -0
- package/dist/httpsnippet-lite/esm/targets/objc/nsurlsession/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/objc/nsurlsession/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/objc/nsurlsession/client.js +132 -0
- package/dist/httpsnippet-lite/esm/targets/objc/target.d.ts +25 -0
- package/dist/httpsnippet-lite/esm/targets/objc/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/ocaml/cohttp/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/ocaml/cohttp/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/ocaml/cohttp/client.js +68 -0
- package/dist/httpsnippet-lite/esm/targets/ocaml/target.d.ts +25 -0
- package/dist/httpsnippet-lite/esm/targets/ocaml/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/php/curl/client.d.ts +18 -0
- package/dist/httpsnippet-lite/esm/targets/php/curl/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/php/curl/client.js +134 -0
- package/dist/httpsnippet-lite/esm/targets/php/guzzle/client.d.ts +16 -0
- package/dist/httpsnippet-lite/esm/targets/php/guzzle/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/php/guzzle/client.js +126 -0
- package/dist/httpsnippet-lite/esm/targets/php/helpers.d.ts +3 -0
- package/dist/httpsnippet-lite/esm/targets/php/helpers.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/php/helpers.js +37 -0
- package/dist/httpsnippet-lite/esm/targets/php/http1/client.d.ts +17 -0
- package/dist/httpsnippet-lite/esm/targets/php/http1/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/php/http2/client.d.ts +17 -0
- package/dist/httpsnippet-lite/esm/targets/php/http2/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/php/target.d.ts +75 -0
- package/dist/httpsnippet-lite/esm/targets/php/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/common.d.ts +10 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/common.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/common.js +53 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/restmethod/client.d.ts +18 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/restmethod/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/restmethod/client.js +15 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/target.d.ts +45 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/webrequest/client.d.ts +18 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/webrequest/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/powershell/webrequest/client.js +15 -0
- package/dist/httpsnippet-lite/esm/targets/python/helpers.d.ts +9 -0
- package/dist/httpsnippet-lite/esm/targets/python/helpers.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/python/helpers.js +63 -0
- package/dist/httpsnippet-lite/esm/targets/python/python3/client.d.ts +19 -0
- package/dist/httpsnippet-lite/esm/targets/python/python3/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/python/python3/client.js +95 -0
- package/dist/httpsnippet-lite/esm/targets/python/requests/client.d.ts +16 -0
- package/dist/httpsnippet-lite/esm/targets/python/requests/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/python/requests/client.js +177 -0
- package/dist/httpsnippet-lite/esm/targets/python/target.d.ts +44 -0
- package/dist/httpsnippet-lite/esm/targets/python/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/r/httr/client.d.ts +17 -0
- package/dist/httpsnippet-lite/esm/targets/r/httr/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/r/httr/client.js +127 -0
- package/dist/httpsnippet-lite/esm/targets/r/target.d.ts +27 -0
- package/dist/httpsnippet-lite/esm/targets/r/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/ruby/native/client.d.ts +16 -0
- package/dist/httpsnippet-lite/esm/targets/ruby/native/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/ruby/native/client.js +72 -0
- package/dist/httpsnippet-lite/esm/targets/ruby/target.d.ts +26 -0
- package/dist/httpsnippet-lite/esm/targets/ruby/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/shell/curl/client.d.ts +17 -0
- package/dist/httpsnippet-lite/esm/targets/shell/curl/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.d.ts +17 -0
- package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.js +118 -0
- package/dist/httpsnippet-lite/esm/targets/shell/target.d.ts +57 -0
- package/dist/httpsnippet-lite/esm/targets/shell/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/shell/wget/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/shell/wget/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/shell/wget/client.js +54 -0
- package/dist/httpsnippet-lite/esm/targets/swift/helpers.d.ts +17 -0
- package/dist/httpsnippet-lite/esm/targets/swift/helpers.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/swift/helpers.js +76 -0
- package/dist/httpsnippet-lite/esm/targets/swift/nsurlsession/client.d.ts +15 -0
- package/dist/httpsnippet-lite/esm/targets/swift/nsurlsession/client.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/swift/nsurlsession/client.js +137 -0
- package/dist/httpsnippet-lite/esm/targets/swift/target.d.ts +25 -0
- package/dist/httpsnippet-lite/esm/targets/swift/target.d.ts.map +1 -0
- package/dist/httpsnippet-lite/esm/targets/targets.d.ts +731 -0
- package/dist/httpsnippet-lite/esm/targets/targets.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/plugins/c/libcurl/libcurl.d.ts +1 -1
- package/dist/plugins/c/libcurl/libcurl.d.ts.map +1 -1
- package/dist/plugins/c/libcurl/libcurl.js +3 -2
- package/dist/plugins/clojure/clj_http/clj_http.d.ts +1 -1
- package/dist/plugins/clojure/clj_http/clj_http.d.ts.map +1 -1
- package/dist/plugins/clojure/clj_http/clj_http.js +3 -2
- package/dist/plugins/csharp/httpclient/httpclient.d.ts +1 -1
- package/dist/plugins/csharp/httpclient/httpclient.d.ts.map +1 -1
- package/dist/plugins/csharp/httpclient/httpclient.js +3 -2
- package/dist/plugins/csharp/restsharp/restsharp.d.ts +1 -1
- package/dist/plugins/csharp/restsharp/restsharp.d.ts.map +1 -1
- package/dist/plugins/csharp/restsharp/restsharp.js +3 -2
- package/dist/plugins/go/native/native.d.ts +1 -1
- package/dist/plugins/go/native/native.d.ts.map +1 -1
- package/dist/plugins/go/native/native.js +3 -2
- package/dist/plugins/http/http11/http11.d.ts +1 -1
- package/dist/plugins/http/http11/http11.d.ts.map +1 -1
- package/dist/plugins/http/http11/http11.js +3 -2
- package/dist/plugins/java/asynchttp/asynchttp.d.ts +1 -1
- package/dist/plugins/java/asynchttp/asynchttp.d.ts.map +1 -1
- package/dist/plugins/java/asynchttp/asynchttp.js +3 -2
- package/dist/plugins/java/nethttp/nethttp.d.ts +1 -1
- package/dist/plugins/java/nethttp/nethttp.d.ts.map +1 -1
- package/dist/plugins/java/nethttp/nethttp.js +3 -2
- package/dist/plugins/java/okhttp/okhttp.d.ts +1 -1
- package/dist/plugins/java/okhttp/okhttp.d.ts.map +1 -1
- package/dist/plugins/java/okhttp/okhttp.js +3 -2
- package/dist/plugins/java/unirest/unirest.d.ts +1 -1
- package/dist/plugins/java/unirest/unirest.d.ts.map +1 -1
- package/dist/plugins/java/unirest/unirest.js +3 -2
- package/dist/plugins/js/axios/axios.d.ts +1 -1
- package/dist/plugins/js/axios/axios.d.ts.map +1 -1
- package/dist/plugins/js/axios/axios.js +3 -2
- package/dist/plugins/js/fetch/fetch.d.ts +1 -1
- package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/js/fetch/fetch.js +3 -2
- package/dist/plugins/js/jquery/jquery.d.ts +1 -1
- package/dist/plugins/js/jquery/jquery.d.ts.map +1 -1
- package/dist/plugins/js/jquery/jquery.js +3 -2
- package/dist/plugins/js/ofetch/ofetch.d.ts +1 -1
- package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/js/ofetch/ofetch.js +3 -2
- package/dist/plugins/js/xhr/xhr.d.ts +1 -1
- package/dist/plugins/js/xhr/xhr.d.ts.map +1 -1
- package/dist/plugins/js/xhr/xhr.js +3 -2
- package/dist/plugins/kotlin/okhttp/okhttp.d.ts +1 -1
- package/dist/plugins/kotlin/okhttp/okhttp.d.ts.map +1 -1
- package/dist/plugins/kotlin/okhttp/okhttp.js +3 -2
- package/dist/plugins/node/axios/axios.d.ts +1 -1
- package/dist/plugins/node/axios/axios.d.ts.map +1 -1
- package/dist/plugins/node/axios/axios.js +3 -2
- package/dist/plugins/node/fetch/fetch.d.ts +1 -1
- package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/node/fetch/fetch.js +3 -2
- package/dist/plugins/node/ofetch/ofetch.d.ts +1 -1
- package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/node/ofetch/ofetch.js +3 -2
- package/dist/plugins/node/undici/undici.d.ts +1 -1
- package/dist/plugins/node/undici/undici.d.ts.map +1 -1
- package/dist/plugins/node/undici/undici.js +3 -2
- package/dist/plugins/objc/nsurlsession/nsurlsession.d.ts +1 -1
- package/dist/plugins/objc/nsurlsession/nsurlsession.d.ts.map +1 -1
- package/dist/plugins/objc/nsurlsession/nsurlsession.js +3 -2
- package/dist/plugins/ocaml/cohttp/cohttp.d.ts +1 -1
- package/dist/plugins/ocaml/cohttp/cohttp.d.ts.map +1 -1
- package/dist/plugins/ocaml/cohttp/cohttp.js +3 -2
- package/dist/plugins/php/curl/curl.d.ts +1 -1
- package/dist/plugins/php/curl/curl.d.ts.map +1 -1
- package/dist/plugins/php/curl/curl.js +3 -2
- package/dist/plugins/php/guzzle/guzzle.d.ts +1 -1
- package/dist/plugins/php/guzzle/guzzle.d.ts.map +1 -1
- package/dist/plugins/php/guzzle/guzzle.js +3 -2
- package/dist/plugins/powershell/restmethod/restmethod.d.ts +1 -1
- package/dist/plugins/powershell/restmethod/restmethod.d.ts.map +1 -1
- package/dist/plugins/powershell/restmethod/restmethod.js +3 -2
- package/dist/plugins/powershell/webrequest/webrequest.d.ts +1 -1
- package/dist/plugins/powershell/webrequest/webrequest.d.ts.map +1 -1
- package/dist/plugins/powershell/webrequest/webrequest.js +3 -2
- package/dist/plugins/python/python3/python3.d.ts +1 -1
- package/dist/plugins/python/python3/python3.d.ts.map +1 -1
- package/dist/plugins/python/python3/python3.js +3 -2
- package/dist/plugins/python/requests/requests.d.ts +1 -1
- package/dist/plugins/python/requests/requests.d.ts.map +1 -1
- package/dist/plugins/python/requests/requests.js +3 -2
- package/dist/plugins/r/httr/httr.d.ts +1 -1
- package/dist/plugins/r/httr/httr.d.ts.map +1 -1
- package/dist/plugins/r/httr/httr.js +3 -2
- package/dist/plugins/ruby/native/native.d.ts +1 -1
- package/dist/plugins/ruby/native/native.d.ts.map +1 -1
- package/dist/plugins/ruby/native/native.js +3 -2
- package/dist/plugins/shell/curl/curl.d.ts +1 -1
- package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
- package/dist/plugins/shell/curl/curl.js +1 -0
- package/dist/plugins/shell/httpie/httpie.d.ts +1 -1
- package/dist/plugins/shell/httpie/httpie.d.ts.map +1 -1
- package/dist/plugins/shell/httpie/httpie.js +3 -2
- package/dist/plugins/shell/wget/wget.d.ts +1 -1
- package/dist/plugins/shell/wget/wget.d.ts.map +1 -1
- package/dist/plugins/shell/wget/wget.js +3 -2
- package/dist/plugins/swift/nsurlsession/nsurlsession.d.ts +1 -1
- package/dist/plugins/swift/nsurlsession/nsurlsession.d.ts.map +1 -1
- package/dist/plugins/swift/nsurlsession/nsurlsession.js +3 -2
- package/dist/snippetz.d.ts +4 -6
- package/dist/snippetz.d.ts.map +1 -1
- package/dist/snippetz.js +10 -91
- package/dist/{core/types.d.ts → types/index.d.ts} +15 -4
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.test-d.d.ts +2 -0
- package/dist/types/index.test-d.d.ts.map +1 -0
- package/dist/utils/arrayToObject.d.ts.map +1 -0
- package/dist/utils/convertWithHttpSnippetLite.d.ts +6 -0
- package/dist/utils/convertWithHttpSnippetLite.d.ts.map +1 -0
- package/dist/utils/convertWithHttpSnippetLite.js +95 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/needsQuotes.d.ts.map +1 -0
- package/dist/utils/objectToString.d.ts.map +1 -0
- package/package.json +11 -7
- package/dist/core/index.d.ts +0 -5
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -3
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.test-d.d.ts +0 -2
- package/dist/core/types.test-d.d.ts.map +0 -1
- package/dist/core/utils/arrayToObject.d.ts.map +0 -1
- package/dist/core/utils/convertWithHttpSnippetLite.d.ts +0 -7
- package/dist/core/utils/convertWithHttpSnippetLite.d.ts.map +0 -1
- package/dist/core/utils/convertWithHttpSnippetLite.js +0 -83
- package/dist/core/utils/needsQuotes.d.ts.map +0 -1
- package/dist/core/utils/objectToString.d.ts.map +0 -1
- /package/dist/{core/utils → utils}/arrayToObject.d.ts +0 -0
- /package/dist/{core/utils → utils}/arrayToObject.js +0 -0
- /package/dist/{core/utils → utils}/needsQuotes.d.ts +0 -0
- /package/dist/{core/utils → utils}/needsQuotes.js +0 -0
- /package/dist/{core/utils → utils}/objectToString.d.ts +0 -0
- /package/dist/{core/utils → utils}/objectToString.js +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const httpie: {
|
|
2
|
+
info: {
|
|
3
|
+
key: string;
|
|
4
|
+
title: string;
|
|
5
|
+
link: string;
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
convert: ({ allHeaders, postData, queryObj, fullUrl, method, url }: {
|
|
9
|
+
allHeaders: any;
|
|
10
|
+
postData: any;
|
|
11
|
+
queryObj: any;
|
|
12
|
+
fullUrl: any;
|
|
13
|
+
method: any;
|
|
14
|
+
url: any;
|
|
15
|
+
}, options: any) => any;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/shell/httpie/client.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;CA0GlB,CAAA"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { CodeBuilder } from '../../../helpers/code-builder.js';
|
|
2
|
+
import { quote } from '../../../helpers/shell.js';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
5
|
+
// @ts-nocheck
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* HTTP code snippet generator for the Shell using HTTPie.
|
|
9
|
+
*
|
|
10
|
+
* @author
|
|
11
|
+
* @AhmadNassri
|
|
12
|
+
*
|
|
13
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
14
|
+
*/
|
|
15
|
+
const httpie = {
|
|
16
|
+
info: {
|
|
17
|
+
key: 'httpie',
|
|
18
|
+
title: 'HTTPie',
|
|
19
|
+
link: 'http://httpie.org/',
|
|
20
|
+
description: 'a CLI, cURL-like tool for humans',
|
|
21
|
+
},
|
|
22
|
+
convert: ({ allHeaders, postData, queryObj, fullUrl, method, url }, options) => {
|
|
23
|
+
const opts = {
|
|
24
|
+
body: false,
|
|
25
|
+
cert: false,
|
|
26
|
+
headers: false,
|
|
27
|
+
indent: ' ',
|
|
28
|
+
pretty: false,
|
|
29
|
+
print: false,
|
|
30
|
+
queryParams: false,
|
|
31
|
+
short: false,
|
|
32
|
+
style: false,
|
|
33
|
+
timeout: false,
|
|
34
|
+
verbose: false,
|
|
35
|
+
verify: false,
|
|
36
|
+
...options,
|
|
37
|
+
};
|
|
38
|
+
const { push, join, unshift } = new CodeBuilder({
|
|
39
|
+
indent: opts.indent,
|
|
40
|
+
// @ts-expect-error SEEMS LEGIT
|
|
41
|
+
join: opts.indent !== false ? ` \\\n${opts.indent}` : ' ',
|
|
42
|
+
});
|
|
43
|
+
let raw = false;
|
|
44
|
+
const flags = [];
|
|
45
|
+
if (opts.headers) {
|
|
46
|
+
flags.push(opts.short ? '-h' : '--headers');
|
|
47
|
+
}
|
|
48
|
+
if (opts.body) {
|
|
49
|
+
flags.push(opts.short ? '-b' : '--body');
|
|
50
|
+
}
|
|
51
|
+
if (opts.verbose) {
|
|
52
|
+
flags.push(opts.short ? '-v' : '--verbose');
|
|
53
|
+
}
|
|
54
|
+
if (opts.print) {
|
|
55
|
+
flags.push(`${opts.short ? '-p' : '--print'}=${opts.print}`);
|
|
56
|
+
}
|
|
57
|
+
if (opts.verify) {
|
|
58
|
+
flags.push(`--verify=${opts.verify}`);
|
|
59
|
+
}
|
|
60
|
+
if (opts.cert) {
|
|
61
|
+
flags.push(`--cert=${opts.cert}`);
|
|
62
|
+
}
|
|
63
|
+
if (opts.pretty) {
|
|
64
|
+
flags.push(`--pretty=${opts.pretty}`);
|
|
65
|
+
}
|
|
66
|
+
if (opts.style) {
|
|
67
|
+
flags.push(`--style=${opts.style}`);
|
|
68
|
+
}
|
|
69
|
+
if (opts.timeout) {
|
|
70
|
+
flags.push(`--timeout=${opts.timeout}`);
|
|
71
|
+
}
|
|
72
|
+
// construct query params
|
|
73
|
+
if (opts.queryParams) {
|
|
74
|
+
Object.keys(queryObj).forEach((name) => {
|
|
75
|
+
const value = queryObj[name];
|
|
76
|
+
if (Array.isArray(value)) {
|
|
77
|
+
value.forEach((val) => {
|
|
78
|
+
push(`${name}==${quote(val)}`);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
push(`${name}==${quote(value)}`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// construct headers
|
|
87
|
+
Object.keys(allHeaders)
|
|
88
|
+
.sort()
|
|
89
|
+
.forEach((key) => {
|
|
90
|
+
push(`${key}:${quote(allHeaders[key])}`);
|
|
91
|
+
});
|
|
92
|
+
if ((postData === null || postData === void 0
|
|
93
|
+
? void 0
|
|
94
|
+
: postData.mimeType) === 'application/x-www-form-urlencoded') {
|
|
95
|
+
// construct post params
|
|
96
|
+
if (postData.params?.length) {
|
|
97
|
+
flags.push(opts.short ? '-f' : '--form');
|
|
98
|
+
postData.params.forEach((param) => {
|
|
99
|
+
push(`${param.name}=${quote(param.value)}`);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
raw = true;
|
|
105
|
+
}
|
|
106
|
+
const cliFlags = flags.length ? `${flags.join(' ')} ` : '';
|
|
107
|
+
url = quote(opts.queryParams ? url : fullUrl);
|
|
108
|
+
unshift(`http ${cliFlags}${method} ${url}`);
|
|
109
|
+
if (raw &&
|
|
110
|
+
(postData === null || postData === void 0 ? void 0 : postData.text)) {
|
|
111
|
+
const postDataText = quote(postData.text);
|
|
112
|
+
unshift(`echo ${postDataText} | `);
|
|
113
|
+
}
|
|
114
|
+
return join();
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export { httpie };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export declare const shell: {
|
|
2
|
+
info: {
|
|
3
|
+
key: string;
|
|
4
|
+
title: string;
|
|
5
|
+
extname: string;
|
|
6
|
+
default: string;
|
|
7
|
+
};
|
|
8
|
+
clientsById: {
|
|
9
|
+
curl: {
|
|
10
|
+
info: {
|
|
11
|
+
key: string;
|
|
12
|
+
title: string;
|
|
13
|
+
link: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
convert: ({ fullUrl, method, httpVersion, headersObj, allHeaders, postData }: {
|
|
17
|
+
fullUrl: any;
|
|
18
|
+
method: any;
|
|
19
|
+
httpVersion: any;
|
|
20
|
+
headersObj: any;
|
|
21
|
+
allHeaders: any;
|
|
22
|
+
postData: any;
|
|
23
|
+
}, options?: {}) => any;
|
|
24
|
+
};
|
|
25
|
+
httpie: {
|
|
26
|
+
info: {
|
|
27
|
+
key: string;
|
|
28
|
+
title: string;
|
|
29
|
+
link: string;
|
|
30
|
+
description: string;
|
|
31
|
+
};
|
|
32
|
+
convert: ({ allHeaders, postData, queryObj, fullUrl, method, url }: {
|
|
33
|
+
allHeaders: any;
|
|
34
|
+
postData: any;
|
|
35
|
+
queryObj: any;
|
|
36
|
+
fullUrl: any;
|
|
37
|
+
method: any;
|
|
38
|
+
url: any;
|
|
39
|
+
}, options: any) => any;
|
|
40
|
+
};
|
|
41
|
+
wget: {
|
|
42
|
+
info: {
|
|
43
|
+
key: string;
|
|
44
|
+
title: string;
|
|
45
|
+
link: string;
|
|
46
|
+
description: string;
|
|
47
|
+
};
|
|
48
|
+
convert: ({ method, postData, allHeaders, fullUrl }: {
|
|
49
|
+
method: any;
|
|
50
|
+
postData: any;
|
|
51
|
+
allHeaders: any;
|
|
52
|
+
fullUrl: any;
|
|
53
|
+
}, options: any) => any;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/esm/targets/shell/target.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAYjB,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const wget: {
|
|
2
|
+
info: {
|
|
3
|
+
key: string;
|
|
4
|
+
title: string;
|
|
5
|
+
link: string;
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
convert: ({ method, postData, allHeaders, fullUrl }: {
|
|
9
|
+
method: any;
|
|
10
|
+
postData: any;
|
|
11
|
+
allHeaders: any;
|
|
12
|
+
fullUrl: any;
|
|
13
|
+
}, options: any) => any;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/shell/wget/client.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,IAAI;;;;;;;;;;;;;CAqChB,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CodeBuilder } from '../../../helpers/code-builder.js';
|
|
2
|
+
import { quote, escape } from '../../../helpers/shell.js';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
5
|
+
// @ts-nocheck
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* HTTP code snippet generator for the Shell using Wget.
|
|
9
|
+
*
|
|
10
|
+
* @author
|
|
11
|
+
* @AhmadNassri
|
|
12
|
+
*
|
|
13
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
14
|
+
*/
|
|
15
|
+
const wget = {
|
|
16
|
+
info: {
|
|
17
|
+
key: 'wget',
|
|
18
|
+
title: 'Wget',
|
|
19
|
+
link: 'https://www.gnu.org/software/wget/',
|
|
20
|
+
description: 'a free software package for retrieving files using HTTP, HTTPS',
|
|
21
|
+
},
|
|
22
|
+
convert: ({ method, postData, allHeaders, fullUrl }, options) => {
|
|
23
|
+
const opts = {
|
|
24
|
+
indent: ' ',
|
|
25
|
+
short: false,
|
|
26
|
+
verbose: false,
|
|
27
|
+
...options,
|
|
28
|
+
};
|
|
29
|
+
const { push, join } = new CodeBuilder({
|
|
30
|
+
indent: opts.indent,
|
|
31
|
+
// @ts-expect-error SEEMS LEGIT
|
|
32
|
+
join: opts.indent !== false ? ` \\\n${opts.indent}` : ' ',
|
|
33
|
+
});
|
|
34
|
+
if (opts.verbose) {
|
|
35
|
+
push(`wget ${opts.short ? '-v' : '--verbose'}`);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
push(`wget ${opts.short ? '-q' : '--quiet'}`);
|
|
39
|
+
}
|
|
40
|
+
push(`--method ${quote(method)}`);
|
|
41
|
+
Object.keys(allHeaders).forEach((key) => {
|
|
42
|
+
const header = `${key}: ${allHeaders[key]}`;
|
|
43
|
+
push(`--header ${quote(header)}`);
|
|
44
|
+
});
|
|
45
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
46
|
+
push(`--body-data ${escape(quote(postData.text))}`);
|
|
47
|
+
}
|
|
48
|
+
push(opts.short ? '-O' : '--output-document');
|
|
49
|
+
push(`- ${quote(fullUrl)}`);
|
|
50
|
+
return join();
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { wget };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a string corresponding to a valid declaration and initialization of a Swift array or dictionary literal
|
|
3
|
+
*
|
|
4
|
+
* @param name Desired name of the instance
|
|
5
|
+
* @param parameters Key-value object of parameters to translate to a Swift object litearal
|
|
6
|
+
* @param opts Target options
|
|
7
|
+
* @return {string}
|
|
8
|
+
*/
|
|
9
|
+
export declare const literalDeclaration: (name: any, parameters: any, opts: any) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a valid Swift string of a literal value according to its type.
|
|
12
|
+
*
|
|
13
|
+
* @param value Any JavaScript literal
|
|
14
|
+
* @param opts Target options
|
|
15
|
+
*/
|
|
16
|
+
export declare const literalRepresentation: (value: any, opts: any, indentLevel: any) => any;
|
|
17
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/esm/targets/swift/helpers.ts"],"names":[],"mappings":"AAqBA;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,mDAC6B,CAAA;AAC5D;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,kDA0CjC,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/**
|
|
4
|
+
* Create an string of given length filled with blank spaces
|
|
5
|
+
*
|
|
6
|
+
* @param length Length of the array to return
|
|
7
|
+
* @param str String to pad out with
|
|
8
|
+
*/
|
|
9
|
+
const buildString = (length, str) => str.repeat(length);
|
|
10
|
+
/**
|
|
11
|
+
* Create a string corresponding to a Dictionary or Array literal representation with pretty option and indentation.
|
|
12
|
+
*/
|
|
13
|
+
const concatArray = (arr, pretty, indentation, indentLevel) => {
|
|
14
|
+
const currentIndent = buildString(indentLevel, indentation);
|
|
15
|
+
const closingBraceIndent = buildString(indentLevel - 1, indentation);
|
|
16
|
+
const join = pretty ? `,\n${currentIndent}` : ', ';
|
|
17
|
+
if (pretty) {
|
|
18
|
+
return `[\n${currentIndent}${arr.join(join)}\n${closingBraceIndent}]`;
|
|
19
|
+
}
|
|
20
|
+
return `[${arr.join(join)}]`;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Create a string corresponding to a valid declaration and initialization of a Swift array or dictionary literal
|
|
24
|
+
*
|
|
25
|
+
* @param name Desired name of the instance
|
|
26
|
+
* @param parameters Key-value object of parameters to translate to a Swift object litearal
|
|
27
|
+
* @param opts Target options
|
|
28
|
+
* @return {string}
|
|
29
|
+
*/
|
|
30
|
+
const literalDeclaration = (name, parameters, opts) => `let ${name} = ${literalRepresentation(parameters, opts)}`;
|
|
31
|
+
/**
|
|
32
|
+
* Create a valid Swift string of a literal value according to its type.
|
|
33
|
+
*
|
|
34
|
+
* @param value Any JavaScript literal
|
|
35
|
+
* @param opts Target options
|
|
36
|
+
*/
|
|
37
|
+
const literalRepresentation = (value, opts, indentLevel) => {
|
|
38
|
+
indentLevel = indentLevel === undefined ? 1 : indentLevel + 1;
|
|
39
|
+
switch (Object.prototype.toString.call(value)) {
|
|
40
|
+
case '[object Number]':
|
|
41
|
+
return value;
|
|
42
|
+
case '[object Array]': {
|
|
43
|
+
// Don't prettify arrays nto not take too much space
|
|
44
|
+
let pretty = false;
|
|
45
|
+
const valuesRepresentation = value.map((v) => {
|
|
46
|
+
// Switch to prettify if the value is a dictionary with multiple keys
|
|
47
|
+
if (Object.prototype.toString.call(v) === '[object Object]') {
|
|
48
|
+
pretty = Object.keys(v).length > 1;
|
|
49
|
+
}
|
|
50
|
+
return literalRepresentation(v, opts, indentLevel);
|
|
51
|
+
});
|
|
52
|
+
// @ts-expect-error needs better types
|
|
53
|
+
return concatArray(valuesRepresentation, pretty, opts.indent, indentLevel);
|
|
54
|
+
}
|
|
55
|
+
case '[object Object]': {
|
|
56
|
+
const keyValuePairs = [];
|
|
57
|
+
for (const key in value) {
|
|
58
|
+
keyValuePairs.push(`"${key}": ${literalRepresentation(value[key], opts, indentLevel)}`);
|
|
59
|
+
}
|
|
60
|
+
return concatArray(keyValuePairs,
|
|
61
|
+
// @ts-expect-error needs better types
|
|
62
|
+
opts.pretty && keyValuePairs.length > 1,
|
|
63
|
+
// @ts-expect-error needs better types
|
|
64
|
+
opts.indent, indentLevel);
|
|
65
|
+
}
|
|
66
|
+
case '[object Boolean]':
|
|
67
|
+
return value.toString();
|
|
68
|
+
default:
|
|
69
|
+
if (value === null || value === undefined) {
|
|
70
|
+
return '';
|
|
71
|
+
}
|
|
72
|
+
return `"${value.toString().replace(/"/g, '\\"')}"`;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { literalDeclaration, literalRepresentation };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const nsurlsession: {
|
|
2
|
+
info: {
|
|
3
|
+
key: string;
|
|
4
|
+
title: string;
|
|
5
|
+
link: string;
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
convert: ({ allHeaders, postData, fullUrl, method }: {
|
|
9
|
+
allHeaders: any;
|
|
10
|
+
postData: any;
|
|
11
|
+
fullUrl: any;
|
|
12
|
+
method: any;
|
|
13
|
+
}, options: any) => any;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/httpsnippet-lite/esm/targets/swift/nsurlsession/client.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,YAAY;;;;;;;;;;;;;CAgJxB,CAAA"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { CodeBuilder } from '../../../helpers/code-builder.js';
|
|
2
|
+
import { literalDeclaration } from '../helpers.js';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
5
|
+
// @ts-nocheck
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* HTTP code snippet generator for Swift using NSURLSession.
|
|
9
|
+
*
|
|
10
|
+
* @author
|
|
11
|
+
* @thibaultCha
|
|
12
|
+
*
|
|
13
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
14
|
+
*/
|
|
15
|
+
const nsurlsession = {
|
|
16
|
+
info: {
|
|
17
|
+
key: 'nsurlsession',
|
|
18
|
+
title: 'NSURLSession',
|
|
19
|
+
link: 'https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSURLSession_class/index.html',
|
|
20
|
+
description: "Foundation's NSURLSession request",
|
|
21
|
+
},
|
|
22
|
+
convert: ({ allHeaders, postData, fullUrl, method }, options) => {
|
|
23
|
+
let _a;
|
|
24
|
+
const opts = {
|
|
25
|
+
indent: ' ',
|
|
26
|
+
pretty: true,
|
|
27
|
+
timeout: '10',
|
|
28
|
+
...options,
|
|
29
|
+
};
|
|
30
|
+
const { push, blank, join } = new CodeBuilder({ indent: opts.indent });
|
|
31
|
+
// Markers for headers to be created as litteral objects and later be set on the NSURLRequest if exist
|
|
32
|
+
const req = {
|
|
33
|
+
hasHeaders: false,
|
|
34
|
+
hasBody: false,
|
|
35
|
+
};
|
|
36
|
+
// We just want to make sure people understand that is the only dependency
|
|
37
|
+
push('import Foundation');
|
|
38
|
+
if (Object.keys(allHeaders).length) {
|
|
39
|
+
req.hasHeaders = true;
|
|
40
|
+
blank();
|
|
41
|
+
push(literalDeclaration('headers', allHeaders, opts));
|
|
42
|
+
}
|
|
43
|
+
if (postData && (postData.text || postData.jsonObj || postData.params)) {
|
|
44
|
+
req.hasBody = true;
|
|
45
|
+
switch (postData.mimeType) {
|
|
46
|
+
case 'application/x-www-form-urlencoded':
|
|
47
|
+
// By appending parameters one by one in the resulting snippet,
|
|
48
|
+
// we make it easier for the user to edit it according to his or her needs after pasting.
|
|
49
|
+
// The user can just add/remove lines adding/removing body parameters.
|
|
50
|
+
blank();
|
|
51
|
+
if ((_a = postData.params) === null || _a === void 0
|
|
52
|
+
? void 0
|
|
53
|
+
: _a.length) {
|
|
54
|
+
const [head, ...tail] = postData.params;
|
|
55
|
+
push(`let postData = NSMutableData(data: "${head.name}=${head.value}".data(using: String.Encoding.utf8)!)`);
|
|
56
|
+
tail.forEach(({ name, value }) => {
|
|
57
|
+
push(`postData.append("&${name}=${value}".data(using: String.Encoding.utf8)!)`);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
req.hasBody = false;
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case 'application/json':
|
|
65
|
+
if (postData.jsonObj) {
|
|
66
|
+
push(`${literalDeclaration('parameters', postData.jsonObj, opts)} as [String : Any]`);
|
|
67
|
+
blank();
|
|
68
|
+
push('let postData = JSONSerialization.data(withJSONObject: parameters, options: [])');
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
case 'multipart/form-data':
|
|
72
|
+
/**
|
|
73
|
+
* By appending multipart parameters one by one in the resulting snippet,
|
|
74
|
+
* we make it easier for the user to edit it according to his or her needs after pasting.
|
|
75
|
+
* The user can just edit the parameters NSDictionary or put this part of a snippet in a multipart builder method.
|
|
76
|
+
*/
|
|
77
|
+
push(literalDeclaration('parameters', postData.params, opts));
|
|
78
|
+
blank();
|
|
79
|
+
push(`let boundary = "${postData.boundary}"`);
|
|
80
|
+
blank();
|
|
81
|
+
push('var body = ""');
|
|
82
|
+
push('var error: NSError? = nil');
|
|
83
|
+
push('for param in parameters {');
|
|
84
|
+
push('let paramName = param["name"]!', 1);
|
|
85
|
+
push('body += "--\\(boundary)\\r\\n"', 1);
|
|
86
|
+
push('body += "Content-Disposition:form-data; name=\\"\\(paramName)\\""', 1);
|
|
87
|
+
push('if let filename = param["fileName"] {', 1);
|
|
88
|
+
push('let contentType = param["content-type"]!', 2);
|
|
89
|
+
push('let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)', 2);
|
|
90
|
+
push('if (error != nil) {', 2);
|
|
91
|
+
push('print(error as Any)', 3);
|
|
92
|
+
push('}', 2);
|
|
93
|
+
push('body += "; filename=\\"\\(filename)\\"\\r\\n"', 2);
|
|
94
|
+
push('body += "Content-Type: \\(contentType)\\r\\n\\r\\n"', 2);
|
|
95
|
+
push('body += fileContent', 2);
|
|
96
|
+
push('} else if let paramValue = param["value"] {', 1);
|
|
97
|
+
push('body += "\\r\\n\\r\\n\\(paramValue)"', 2);
|
|
98
|
+
push('}', 1);
|
|
99
|
+
push('}');
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
blank();
|
|
103
|
+
push(`let postData = NSData(data: "${postData.text}".data(using: String.Encoding.utf8)!)`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
blank();
|
|
107
|
+
// NSURLRequestUseProtocolCachePolicy is the default policy, let's just always set it to avoid confusion.
|
|
108
|
+
push(`let request = NSMutableURLRequest(url: NSURL(string: "${fullUrl}")! as URL,`);
|
|
109
|
+
push(' cachePolicy: .useProtocolCachePolicy,');
|
|
110
|
+
push(
|
|
111
|
+
// @ts-expect-error needs better types
|
|
112
|
+
` timeoutInterval: ${parseInt(opts.timeout, 10).toFixed(1)})`);
|
|
113
|
+
push(`request.httpMethod = "${method}"`);
|
|
114
|
+
if (req.hasHeaders) {
|
|
115
|
+
push('request.allHTTPHeaderFields = headers');
|
|
116
|
+
}
|
|
117
|
+
if (req.hasBody) {
|
|
118
|
+
push('request.httpBody = postData as Data');
|
|
119
|
+
}
|
|
120
|
+
blank();
|
|
121
|
+
// Retrieving the shared session will be less verbose than creating a new one.
|
|
122
|
+
push('let session = URLSession.shared');
|
|
123
|
+
push('let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in');
|
|
124
|
+
push('if (error != nil) {', 1);
|
|
125
|
+
push('print(error as Any)', 2);
|
|
126
|
+
push('} else {', 1); // Casting the NSURLResponse to NSHTTPURLResponse so the user can see the status .
|
|
127
|
+
push('let httpResponse = response as? HTTPURLResponse', 2);
|
|
128
|
+
push('print(httpResponse)', 2);
|
|
129
|
+
push('}', 1);
|
|
130
|
+
push('})');
|
|
131
|
+
blank();
|
|
132
|
+
push('dataTask.resume()');
|
|
133
|
+
return join();
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export { nsurlsession };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const swift: {
|
|
2
|
+
info: {
|
|
3
|
+
key: string;
|
|
4
|
+
title: string;
|
|
5
|
+
extname: string;
|
|
6
|
+
default: string;
|
|
7
|
+
};
|
|
8
|
+
clientsById: {
|
|
9
|
+
nsurlsession: {
|
|
10
|
+
info: {
|
|
11
|
+
key: string;
|
|
12
|
+
title: string;
|
|
13
|
+
link: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
convert: ({ allHeaders, postData, fullUrl, method }: {
|
|
17
|
+
allHeaders: any;
|
|
18
|
+
postData: any;
|
|
19
|
+
fullUrl: any;
|
|
20
|
+
method: any;
|
|
21
|
+
}, options: any) => any;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/esm/targets/swift/target.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;CAUjB,CAAA"}
|