@scalar/snippetz 0.2.20 → 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.
Files changed (118) hide show
  1. package/dist/clients.d.ts.map +1 -1
  2. package/dist/clients.js +2 -1
  3. package/dist/clients.js.map +2 -2
  4. package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.d.ts.map +1 -1
  5. package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js +37 -8
  6. package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js.map +2 -2
  7. package/dist/httpsnippet-lite/esm/targets/go/native/client.d.ts.map +1 -1
  8. package/dist/httpsnippet-lite/esm/targets/go/native/client.js +76 -30
  9. package/dist/httpsnippet-lite/esm/targets/go/native/client.js.map +2 -2
  10. package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.d.ts.map +1 -1
  11. package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.js +25 -9
  12. package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.js.map +2 -2
  13. package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.d.ts.map +1 -1
  14. package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.js +25 -9
  15. package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.js.map +2 -2
  16. package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.d.ts.map +1 -1
  17. package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.js +11 -0
  18. package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.js.map +2 -2
  19. package/dist/plugins/js/axios/index.d.ts +1 -1
  20. package/dist/plugins/js/axios/index.d.ts.map +1 -1
  21. package/dist/plugins/js/axios/index.js +4 -1
  22. package/dist/plugins/js/axios/index.js.map +2 -2
  23. package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
  24. package/dist/plugins/js/fetch/fetch.js +30 -9
  25. package/dist/plugins/js/fetch/fetch.js.map +2 -2
  26. package/dist/plugins/js/fetch/index.d.ts +1 -1
  27. package/dist/plugins/js/fetch/index.d.ts.map +1 -1
  28. package/dist/plugins/js/fetch/index.js +4 -1
  29. package/dist/plugins/js/fetch/index.js.map +2 -2
  30. package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
  31. package/dist/plugins/js/ofetch/ofetch.js +1 -10
  32. package/dist/plugins/js/ofetch/ofetch.js.map +2 -2
  33. package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
  34. package/dist/plugins/node/fetch/fetch.js +37 -9
  35. package/dist/plugins/node/fetch/fetch.js.map +2 -2
  36. package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
  37. package/dist/plugins/node/ofetch/ofetch.js +1 -10
  38. package/dist/plugins/node/ofetch/ofetch.js.map +2 -2
  39. package/dist/plugins/node/undici/undici.d.ts.map +1 -1
  40. package/dist/plugins/node/undici/undici.js +4 -6
  41. package/dist/plugins/node/undici/undici.js.map +2 -2
  42. package/dist/plugins/python/httpx/async.d.ts +6 -0
  43. package/dist/plugins/python/httpx/async.d.ts.map +1 -0
  44. package/dist/plugins/python/httpx/async.js +16 -0
  45. package/dist/plugins/python/httpx/async.js.map +7 -0
  46. package/dist/plugins/python/httpx/index.d.ts +3 -0
  47. package/dist/plugins/python/httpx/index.d.ts.map +1 -0
  48. package/dist/plugins/python/httpx/index.js +3 -0
  49. package/dist/plugins/python/httpx/index.js.map +7 -0
  50. package/dist/plugins/python/httpx/sync.d.ts +6 -0
  51. package/dist/plugins/python/httpx/sync.d.ts.map +1 -0
  52. package/dist/plugins/python/httpx/sync.js +13 -0
  53. package/dist/plugins/python/httpx/sync.js.map +7 -0
  54. package/dist/plugins/python/requests/requests.d.ts.map +1 -1
  55. package/dist/plugins/python/requests/requests.js +2 -92
  56. package/dist/plugins/python/requests/requests.js.map +2 -2
  57. package/dist/plugins/python/requestsLike.d.ts +3 -0
  58. package/dist/plugins/python/requestsLike.d.ts.map +1 -0
  59. package/dist/plugins/python/requestsLike.js +120 -0
  60. package/dist/plugins/python/requestsLike.js.map +7 -0
  61. package/dist/snippetz.d.ts +1 -1
  62. package/dist/utils/create-search-params.d.ts +4 -0
  63. package/dist/utils/create-search-params.d.ts.map +1 -0
  64. package/dist/utils/create-search-params.js +11 -0
  65. package/dist/utils/create-search-params.js.map +7 -0
  66. package/dist/utils/index.d.ts +0 -1
  67. package/dist/utils/index.d.ts.map +1 -1
  68. package/dist/utils/index.js +0 -1
  69. package/dist/utils/index.js.map +2 -2
  70. package/dist/utils/objectToString.d.ts +8 -0
  71. package/dist/utils/objectToString.d.ts.map +1 -1
  72. package/dist/utils/objectToString.js +20 -15
  73. package/dist/utils/objectToString.js.map +2 -2
  74. package/package.json +10 -5
  75. package/dist/plugins/c/libcurl/libcurl.test.js +0 -200
  76. package/dist/plugins/c/libcurl/libcurl.test.js.map +0 -7
  77. package/dist/plugins/clojure/clj_http/clj_http.test.js +0 -151
  78. package/dist/plugins/clojure/clj_http/clj_http.test.js.map +0 -7
  79. package/dist/plugins/dart/http/http.test.js +0 -550
  80. package/dist/plugins/dart/http/http.test.js.map +0 -7
  81. package/dist/plugins/go/native/native.test.js +0 -367
  82. package/dist/plugins/go/native/native.test.js.map +0 -7
  83. package/dist/plugins/http/http11/http11.test.js +0 -175
  84. package/dist/plugins/http/http11/http11.test.js.map +0 -7
  85. package/dist/plugins/js/fetch/fetch.test.js +0 -111
  86. package/dist/plugins/js/fetch/fetch.test.js.map +0 -7
  87. package/dist/plugins/js/ofetch/ofetch.test.js +0 -123
  88. package/dist/plugins/js/ofetch/ofetch.test.js.map +0 -7
  89. package/dist/plugins/node/fetch/fetch.test.js +0 -111
  90. package/dist/plugins/node/fetch/fetch.test.js.map +0 -7
  91. package/dist/plugins/node/ofetch/ofetch.test.js +0 -123
  92. package/dist/plugins/node/ofetch/ofetch.test.js.map +0 -7
  93. package/dist/plugins/node/undici/undici.test.js +0 -133
  94. package/dist/plugins/node/undici/undici.test.js.map +0 -7
  95. package/dist/plugins/php/curl/curl.test.js +0 -564
  96. package/dist/plugins/php/curl/curl.test.js.map +0 -7
  97. package/dist/plugins/php/guzzle/guzzle.test.js +0 -546
  98. package/dist/plugins/php/guzzle/guzzle.test.js.map +0 -7
  99. package/dist/plugins/python/requests/requests.test.js +0 -390
  100. package/dist/plugins/python/requests/requests.test.js.map +0 -7
  101. package/dist/plugins/ruby/native/native.test.js +0 -240
  102. package/dist/plugins/ruby/native/native.test.js.map +0 -7
  103. package/dist/plugins/shell/curl/curl.test.js +0 -427
  104. package/dist/plugins/shell/curl/curl.test.js.map +0 -7
  105. package/dist/plugins/shell/httpie/httpie.test.js +0 -113
  106. package/dist/plugins/shell/httpie/httpie.test.js.map +0 -7
  107. package/dist/plugins/shell/wget/wget.test.js +0 -143
  108. package/dist/plugins/shell/wget/wget.test.js.map +0 -7
  109. package/dist/plugins/swift/nsurlsession/nsurlsession.test.js +0 -344
  110. package/dist/plugins/swift/nsurlsession/nsurlsession.test.js.map +0 -7
  111. package/dist/snippetz.test.js +0 -79
  112. package/dist/snippetz.test.js.map +0 -7
  113. package/dist/utils/arrayToObject.d.ts +0 -8
  114. package/dist/utils/arrayToObject.d.ts.map +0 -1
  115. package/dist/utils/arrayToObject.js +0 -10
  116. package/dist/utils/arrayToObject.js.map +0 -7
  117. package/dist/utils/convertWithHttpSnippetLite.test.js +0 -106
  118. package/dist/utils/convertWithHttpSnippetLite.test.js.map +0 -7
@@ -1,100 +1,10 @@
1
- const LENGTH_CONSIDERED_AS_SHORT = 40;
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
- const normalizedRequest = {
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[param.name] = `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 filesStr = JSON.stringify(value).replace(/"open\((.*?)\)"/g, "open($1)").replace(/":open/g, '": open').replace(/\\"/g, '"');
76
- formattedParams.push(`${key}=${filesStr}`);
77
- } else if (key === "json") {
78
- const jsonString = JSON.stringify(value, null, 2).split("\n").map((line, i) => i === 0 ? line : " " + line).join("\n");
79
- formattedParams.push(`${key}=${jsonString}`);
80
- } else if (key === "data" && normalizedRequest.postData?.mimeType === "application/octet-stream") {
81
- formattedParams.push(`${key}=b"${value}"`);
82
- } else {
83
- const str = JSON.stringify(value, null, 2).split("\n").map((line, i) => i === 0 ? line : " " + line).join("\n");
84
- formattedParams.push(`${key}=${str}`);
85
- }
86
- }
87
- if (normalizedRequest.url.length > LENGTH_CONSIDERED_AS_SHORT) {
88
- return `requests.${method}(
89
- ${formattedParams.join(",\n ")}
90
- )`;
91
- }
92
- if (formattedParams.length <= 1) {
93
- return `requests.${method}(${urlParam})`;
94
- }
95
- return `requests.${method}(${urlParam}${formattedParams.length > 1 ? "," : ""}
96
- ${formattedParams.slice(1).join(",\n ")}
97
- )`;
7
+ return requestsLikeGenerate("requests", request, configuration);
98
8
  }
99
9
  };
100
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'\n\nconst LENGTH_CONSIDERED_AS_SHORT = 40\n\n/**\n * python/requests\n */\nexport const pythonRequests: Plugin = {\n target: 'python',\n client: 'requests',\n title: 'Requests',\n generate(request, configuration) {\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: Record<string, string> = {}\n const formData: Record<string, string> = {}\n\n params.forEach((param) => {\n if (param.fileName !== undefined) {\n files[param.name] = `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(`${key}=(${JSON.stringify(value[0])}, ${JSON.stringify(value[1])})`)\n } else if (key === 'files') {\n const filesStr = JSON.stringify(value)\n .replace(/\"open\\((.*?)\\)\"/g, 'open($1)')\n .replace(/\":open/g, '\": open')\n .replace(/\\\\\"/g, '\"')\n formattedParams.push(`${key}=${filesStr}`)\n } else if (key === 'json') {\n const jsonString = JSON.stringify(value, null, 2)\n .split('\\n')\n .map((line, i) => (i === 0 ? line : ' ' + line))\n .join('\\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 = JSON.stringify(value, null, 2)\n .split('\\n')\n .map((line, i) => (i === 0 ? line : ' ' + line))\n .join('\\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 `requests.${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 `requests.${method}(${urlParam})`\n }\n\n // For short URLs with parameters, maintain the multi-line format\n return `requests.${method}(${urlParam}${formattedParams.length > 1 ? ',' : ''}\\n ${formattedParams.slice(1).join(',\\n ')}\\n)`\n },\n}\n"],
5
- "mappings": "AAEA,MAAM,6BAA6B;AAK5B,MAAM,iBAAyB;AAAA,EACpC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,SAAS,SAAS,eAAe;AAE/B,UAAM,oBAAoB;AAAA,MACxB,KAAK;AAAA,MACL,QAAQ;AAAA,MACR,GAAG;AAAA,IACL;AAGA,UAAM,SAAS,kBAAkB,OAAO,YAAY;AAGpD,UAAM,UAA+B,CAAC;AAGtC,QAAI,kBAAkB,SAAS,QAAQ;AACrC,cAAQ,UAAU,kBAAkB,QAAQ;AAAA,QAC1C,CAAC,KAAK,WAAW;AACf,cAAI,EAAE,OAAO,QAAQ,MAAM;AACzB,gBAAI,OAAO,IAAI,IAAI,OAAO;AAAA,UAC5B;AACA,iBAAO;AAAA,QACT;AAAA,QACA,CAAC;AAAA,MACH;AAAA,IACF;AAGA,QAAI,kBAAkB,aAAa,QAAQ;AACzC,cAAQ,SAAS,OAAO,YAAY,kBAAkB,YAAY,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAAA,IACjG;AAGA,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IACpE;AAGA,QAAI,gBAAgB,UAAU,GAAG;AAC/B,aAAO,YAAY,MAAM,IAAI,QAAQ;AAAA,IACvC;AAGA,WAAO,YAAY,MAAM,IAAI,QAAQ,GAAG,gBAAgB,SAAS,IAAI,MAAM,EAAE;AAAA,MAAS,gBAAgB,MAAM,CAAC,EAAE,KAAK,SAAS,CAAC;AAAA;AAAA,EAChI;AACF;",
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
6
  "names": []
7
7
  }
@@ -0,0 +1,3 @@
1
+ import type { HarRequest, PluginConfiguration } from '@scalar/types/snippetz';
2
+ export declare function requestsLikeGenerate(clientVar: string, request?: Partial<HarRequest>, configuration?: PluginConfiguration): string;
3
+ //# sourceMappingURL=requestsLike.d.ts.map
@@ -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,QAAQ;AAAA,MAC1C,CAAC,KAAK,WAAW;AACf,YAAI,EAAE,OAAO,QAAQ,MAAM;AACzB,cAAI,OAAO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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
+ }
@@ -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;
@@ -0,0 +1,4 @@
1
+ import type { HarRequest } from '@scalar/types/snippetz';
2
+ /** Creates a new URL search params object and sets query params so we can handle arrays */
3
+ export declare const createSearchParams: (query?: HarRequest["queryString"]) => URLSearchParams;
4
+ //# sourceMappingURL=create-search-params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-search-params.d.ts","sourceRoot":"","sources":["../../src/utils/create-search-params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAExD,2FAA2F;AAC3F,eAAO,MAAM,kBAAkB,WAAW,UAAU,CAAC,aAAa,CAAC,oBAMlE,CAAA"}
@@ -0,0 +1,11 @@
1
+ const createSearchParams = (query = []) => {
2
+ const searchParams = new URLSearchParams();
3
+ query.forEach((q) => {
4
+ searchParams.append(q.name, q.value);
5
+ });
6
+ return searchParams;
7
+ };
8
+ export {
9
+ createSearchParams
10
+ };
11
+ //# sourceMappingURL=create-search-params.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/create-search-params.ts"],
4
+ "sourcesContent": ["import type { HarRequest } from '@scalar/types/snippetz'\n\n/** Creates a new URL search params object and sets query params so we can handle arrays */\nexport const createSearchParams = (query: HarRequest['queryString'] = []) => {\n const searchParams = new URLSearchParams()\n query.forEach((q) => {\n searchParams.append(q.name, q.value)\n })\n return searchParams\n}\n"],
5
+ "mappings": "AAGO,MAAM,qBAAqB,CAAC,QAAmC,CAAC,MAAM;AAC3E,QAAM,eAAe,IAAI,gBAAgB;AACzC,QAAM,QAAQ,CAAC,MAAM;AACnB,iBAAa,OAAO,EAAE,MAAM,EAAE,KAAK;AAAA,EACrC,CAAC;AACD,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,4 +1,3 @@
1
- export * from './arrayToObject.js';
2
1
  export * from './convertWithHttpSnippetLite.js';
3
2
  export * from './needsQuotes.js';
4
3
  export * from './objectToString.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
@@ -1,4 +1,3 @@
1
- export * from "./arrayToObject.js";
2
1
  export * from "./convertWithHttpSnippetLite.js";
3
2
  export * from "./needsQuotes.js";
4
3
  export * from "./objectToString.js";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/index.ts"],
4
- "sourcesContent": ["export * from './arrayToObject'\nexport * from './convertWithHttpSnippetLite'\nexport * from './needsQuotes'\nexport * from './objectToString'\n"],
5
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "sourcesContent": ["export * from './convertWithHttpSnippetLite'\nexport * from './needsQuotes'\nexport * from './objectToString'\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Represents a raw code that should not be quoted, e.g. `JSON.stringify(...)`.
3
+ * If consists of multiple lines, they will be indented properly.
4
+ */
5
+ export declare class Unquoted {
6
+ value: string;
7
+ constructor(value: string);
8
+ }
1
9
  /**
2
10
  * Converts an object into a string representation with proper formatting and indentation
3
11
  *
@@ -1 +1 @@
1
- {"version":3,"file":"objectToString.d.ts","sourceRoot":"","sources":["../../src/utils/objectToString.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,SAAI,GAAG,MAAM,CAoD3E"}
1
+ {"version":3,"file":"objectToString.d.ts","sourceRoot":"","sources":["../../src/utils/objectToString.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,QAAQ;IACA,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;CACjC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,SAAI,GAAG,MAAM,CAkD3E"}
@@ -1,11 +1,28 @@
1
1
  import { needsQuotes } from "./needsQuotes.js";
2
+ class Unquoted {
3
+ constructor(value) {
4
+ this.value = value;
5
+ }
6
+ }
2
7
  function objectToString(obj, indent = 0) {
3
8
  const parts = [];
4
9
  const indentation = " ".repeat(indent);
5
10
  const innerIndentation = " ".repeat(indent + 2);
6
11
  for (const [key, value] of Object.entries(obj)) {
7
12
  const formattedKey = needsQuotes(key) ? `'${key}'` : key;
8
- if (Array.isArray(value)) {
13
+ if (value instanceof Unquoted) {
14
+ const lines = value.value.split("\n");
15
+ let formattedValue = `${value.value}`;
16
+ if (lines.length > 1) {
17
+ formattedValue = lines.map((line, index) => {
18
+ if (index === 0) {
19
+ return line;
20
+ }
21
+ return `${innerIndentation}${line}`;
22
+ }).join("\n");
23
+ }
24
+ parts.push(`${innerIndentation}${formattedKey}: ${formattedValue}`);
25
+ } else if (Array.isArray(value)) {
9
26
  const arrayString = value.map((item) => {
10
27
  if (typeof item === "string") {
11
28
  return `'${item}'`;
@@ -19,20 +36,7 @@ function objectToString(obj, indent = 0) {
19
36
  } else if (value && typeof value === "object") {
20
37
  parts.push(`${innerIndentation}${formattedKey}: ${objectToString(value, indent + 2)}`);
21
38
  } else if (typeof value === "string") {
22
- let formattedValue = `${value}`;
23
- if (value.startsWith("JSON.stringify")) {
24
- const lines = value.split("\n");
25
- if (lines.length > 1) {
26
- formattedValue = lines.map((line, index) => {
27
- if (index === 0) {
28
- return line;
29
- }
30
- return `${innerIndentation}${line}`;
31
- }).join("\n");
32
- }
33
- } else {
34
- formattedValue = `'${value}'`;
35
- }
39
+ const formattedValue = `'${value}'`;
36
40
  parts.push(`${innerIndentation}${formattedKey}: ${formattedValue}`);
37
41
  } else {
38
42
  parts.push(`${innerIndentation}${formattedKey}: ${value}`);
@@ -43,6 +47,7 @@ ${parts.join(",\n")}
43
47
  ${indentation}}`;
44
48
  }
45
49
  export {
50
+ Unquoted,
46
51
  objectToString
47
52
  };
48
53
  //# sourceMappingURL=objectToString.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/objectToString.ts"],
4
- "sourcesContent": ["import { needsQuotes } from './needsQuotes'\n\n/**\n * Converts an object into a string representation with proper formatting and indentation\n *\n * Handles nested objects, arrays, and special string values\n */\nexport function objectToString(obj: Record<string, any>, indent = 0): string {\n const parts = []\n const indentation = ' '.repeat(indent)\n const innerIndentation = ' '.repeat(indent + 2)\n\n for (const [key, value] of Object.entries(obj)) {\n const formattedKey = needsQuotes(key) ? `'${key}'` : key\n\n if (Array.isArray(value)) {\n const arrayString = value\n .map((item) => {\n if (typeof item === 'string') {\n return `'${item}'`\n }\n if (item && typeof item === 'object') {\n return objectToString(item, indent + 2)\n }\n return item\n })\n .join(`, ${innerIndentation}`)\n parts.push(`${innerIndentation}${formattedKey}: [${arrayString}]`)\n } else if (value && typeof value === 'object') {\n parts.push(`${innerIndentation}${formattedKey}: ${objectToString(value, indent + 2)}`)\n } else if (typeof value === 'string') {\n let formattedValue = `${value}`\n\n if (value.startsWith('JSON.stringify')) {\n // If it has more than one line, add indentation to the other lines\n const lines = value.split('\\n')\n\n if (lines.length > 1) {\n formattedValue = lines\n .map((line, index) => {\n if (index === 0) {\n return line\n }\n\n return `${innerIndentation}${line}`\n })\n .join('\\n')\n }\n } else {\n formattedValue = `'${value}'`\n }\n\n parts.push(`${innerIndentation}${formattedKey}: ${formattedValue}`)\n } else {\n parts.push(`${innerIndentation}${formattedKey}: ${value}`)\n }\n }\n\n return `{\\n${parts.join(',\\n')}\\n${indentation}}`\n}\n"],
5
- "mappings": "AAAA,SAAS,mBAAmB;AAOrB,SAAS,eAAe,KAA0B,SAAS,GAAW;AAC3E,QAAM,QAAQ,CAAC;AACf,QAAM,cAAc,IAAI,OAAO,MAAM;AACrC,QAAM,mBAAmB,IAAI,OAAO,SAAS,CAAC;AAE9C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,UAAM,eAAe,YAAY,GAAG,IAAI,IAAI,GAAG,MAAM;AAErD,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,YAAM,cAAc,MACjB,IAAI,CAAC,SAAS;AACb,YAAI,OAAO,SAAS,UAAU;AAC5B,iBAAO,IAAI,IAAI;AAAA,QACjB;AACA,YAAI,QAAQ,OAAO,SAAS,UAAU;AACpC,iBAAO,eAAe,MAAM,SAAS,CAAC;AAAA,QACxC;AACA,eAAO;AAAA,MACT,CAAC,EACA,KAAK,KAAK,gBAAgB,EAAE;AAC/B,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,MAAM,WAAW,GAAG;AAAA,IACnE,WAAW,SAAS,OAAO,UAAU,UAAU;AAC7C,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,eAAe,OAAO,SAAS,CAAC,CAAC,EAAE;AAAA,IACvF,WAAW,OAAO,UAAU,UAAU;AACpC,UAAI,iBAAiB,GAAG,KAAK;AAE7B,UAAI,MAAM,WAAW,gBAAgB,GAAG;AAEtC,cAAM,QAAQ,MAAM,MAAM,IAAI;AAE9B,YAAI,MAAM,SAAS,GAAG;AACpB,2BAAiB,MACd,IAAI,CAAC,MAAM,UAAU;AACpB,gBAAI,UAAU,GAAG;AACf,qBAAO;AAAA,YACT;AAEA,mBAAO,GAAG,gBAAgB,GAAG,IAAI;AAAA,UACnC,CAAC,EACA,KAAK,IAAI;AAAA,QACd;AAAA,MACF,OAAO;AACL,yBAAiB,IAAI,KAAK;AAAA,MAC5B;AAEA,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,cAAc,EAAE;AAAA,IACpE,OAAO;AACL,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,KAAK,EAAE;AAAA,IAC3D;AAAA,EACF;AAEA,SAAO;AAAA,EAAM,MAAM,KAAK,KAAK,CAAC;AAAA,EAAK,WAAW;AAChD;",
4
+ "sourcesContent": ["import { needsQuotes } from './needsQuotes'\n\n/**\n * Represents a raw code that should not be quoted, e.g. `JSON.stringify(...)`.\n * If consists of multiple lines, they will be indented properly.\n */\nexport class Unquoted {\n constructor(public value: string) {}\n}\n\n/**\n * Converts an object into a string representation with proper formatting and indentation\n *\n * Handles nested objects, arrays, and special string values\n */\nexport function objectToString(obj: Record<string, any>, indent = 0): string {\n const parts = []\n const indentation = ' '.repeat(indent)\n const innerIndentation = ' '.repeat(indent + 2)\n\n for (const [key, value] of Object.entries(obj)) {\n const formattedKey = needsQuotes(key) ? `'${key}'` : key\n\n if (value instanceof Unquoted) {\n const lines = value.value.split('\\n')\n let formattedValue = `${value.value}`\n\n if (lines.length > 1) {\n formattedValue = lines\n .map((line, index) => {\n if (index === 0) {\n return line\n }\n\n return `${innerIndentation}${line}`\n })\n .join('\\n')\n }\n\n parts.push(`${innerIndentation}${formattedKey}: ${formattedValue}`)\n } else if (Array.isArray(value)) {\n const arrayString = value\n .map((item) => {\n if (typeof item === 'string') {\n return `'${item}'`\n }\n if (item && typeof item === 'object') {\n return objectToString(item, indent + 2)\n }\n return item\n })\n .join(`, ${innerIndentation}`)\n parts.push(`${innerIndentation}${formattedKey}: [${arrayString}]`)\n } else if (value && typeof value === 'object') {\n parts.push(`${innerIndentation}${formattedKey}: ${objectToString(value, indent + 2)}`)\n } else if (typeof value === 'string') {\n const formattedValue = `'${value}'`\n\n parts.push(`${innerIndentation}${formattedKey}: ${formattedValue}`)\n } else {\n parts.push(`${innerIndentation}${formattedKey}: ${value}`)\n }\n }\n\n return `{\\n${parts.join(',\\n')}\\n${indentation}}`\n}\n"],
5
+ "mappings": "AAAA,SAAS,mBAAmB;AAMrB,MAAM,SAAS;AAAA,EACpB,YAAmB,OAAe;AAAf;AAAA,EAAgB;AACrC;AAOO,SAAS,eAAe,KAA0B,SAAS,GAAW;AAC3E,QAAM,QAAQ,CAAC;AACf,QAAM,cAAc,IAAI,OAAO,MAAM;AACrC,QAAM,mBAAmB,IAAI,OAAO,SAAS,CAAC;AAE9C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,UAAM,eAAe,YAAY,GAAG,IAAI,IAAI,GAAG,MAAM;AAErD,QAAI,iBAAiB,UAAU;AAC7B,YAAM,QAAQ,MAAM,MAAM,MAAM,IAAI;AACpC,UAAI,iBAAiB,GAAG,MAAM,KAAK;AAEnC,UAAI,MAAM,SAAS,GAAG;AACpB,yBAAiB,MACd,IAAI,CAAC,MAAM,UAAU;AACpB,cAAI,UAAU,GAAG;AACf,mBAAO;AAAA,UACT;AAEA,iBAAO,GAAG,gBAAgB,GAAG,IAAI;AAAA,QACnC,CAAC,EACA,KAAK,IAAI;AAAA,MACd;AAEA,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,cAAc,EAAE;AAAA,IACpE,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,YAAM,cAAc,MACjB,IAAI,CAAC,SAAS;AACb,YAAI,OAAO,SAAS,UAAU;AAC5B,iBAAO,IAAI,IAAI;AAAA,QACjB;AACA,YAAI,QAAQ,OAAO,SAAS,UAAU;AACpC,iBAAO,eAAe,MAAM,SAAS,CAAC;AAAA,QACxC;AACA,eAAO;AAAA,MACT,CAAC,EACA,KAAK,KAAK,gBAAgB,EAAE;AAC/B,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,MAAM,WAAW,GAAG;AAAA,IACnE,WAAW,SAAS,OAAO,UAAU,UAAU;AAC7C,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,eAAe,OAAO,SAAS,CAAC,CAAC,EAAE;AAAA,IACvF,WAAW,OAAO,UAAU,UAAU;AACpC,YAAM,iBAAiB,IAAI,KAAK;AAEhC,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,cAAc,EAAE;AAAA,IACpE,OAAO;AACL,YAAM,KAAK,GAAG,gBAAgB,GAAG,YAAY,KAAK,KAAK,EAAE;AAAA,IAC3D;AAAA,EACF;AAEA,SAAO;AAAA,EAAM,MAAM,KAAK,KAAK,CAAC;AAAA,EAAK,WAAW;AAChD;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -9,9 +9,9 @@
9
9
  "url": "git+https://github.com/scalar/scalar.git",
10
10
  "directory": "packages/snippetz"
11
11
  },
12
- "version": "0.2.20",
12
+ "version": "0.3.1",
13
13
  "engines": {
14
- "node": ">=18"
14
+ "node": ">=20"
15
15
  },
16
16
  "type": "module",
17
17
  "types": "./dist/index.d.ts",
@@ -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",
@@ -211,9 +216,9 @@
211
216
  "stringify-object": "^5.0.0"
212
217
  },
213
218
  "devDependencies": {
214
- "vite": "^5.4.10",
215
- "@scalar/build-tooling": "0.1.19",
216
- "@scalar/types": "0.1.14"
219
+ "vite": "5.4.19",
220
+ "@scalar/build-tooling": "0.2.3",
221
+ "@scalar/types": "0.2.3"
217
222
  },
218
223
  "scripts": {
219
224
  "build": "scalar-build-esbuild",