@scalar/snippetz 0.9.12 → 0.9.14

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 (34) hide show
  1. package/dist/httpsnippet-lite/helpers/shell.d.ts +0 -1
  2. package/dist/httpsnippet-lite/helpers/shell.d.ts.map +1 -1
  3. package/dist/httpsnippet-lite/helpers/shell.js +0 -1
  4. package/dist/plugins/clojure/clj_http/clj_http.d.ts.map +1 -1
  5. package/dist/plugins/clojure/clj_http/clj_http.js +197 -5
  6. package/dist/plugins/csharp/restsharp/restsharp.d.ts.map +1 -1
  7. package/dist/plugins/csharp/restsharp/restsharp.js +134 -5
  8. package/dist/plugins/kotlin/okhttp/okhttp.d.ts.map +1 -1
  9. package/dist/plugins/kotlin/okhttp/okhttp.js +65 -5
  10. package/dist/plugins/objc/nsurlsession/nsurlsession.d.ts.map +1 -1
  11. package/dist/plugins/objc/nsurlsession/nsurlsession.js +124 -5
  12. package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
  13. package/dist/plugins/shell/curl/curl.js +8 -5
  14. package/dist/plugins/shell/wget/wget.d.ts.map +1 -1
  15. package/dist/plugins/shell/wget/wget.js +103 -5
  16. package/package.json +4 -4
  17. package/dist/httpsnippet-lite/targets/clojure/clj_http/client.d.ts +0 -12
  18. package/dist/httpsnippet-lite/targets/clojure/clj_http/client.d.ts.map +0 -1
  19. package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +0 -186
  20. package/dist/httpsnippet-lite/targets/csharp/restsharp/client.d.ts +0 -3
  21. package/dist/httpsnippet-lite/targets/csharp/restsharp/client.d.ts.map +0 -1
  22. package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +0 -36
  23. package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.d.ts +0 -12
  24. package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.d.ts.map +0 -1
  25. package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +0 -87
  26. package/dist/httpsnippet-lite/targets/objc/helpers.d.ts +0 -21
  27. package/dist/httpsnippet-lite/targets/objc/helpers.d.ts.map +0 -1
  28. package/dist/httpsnippet-lite/targets/objc/helpers.js +0 -57
  29. package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.d.ts +0 -12
  30. package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.d.ts.map +0 -1
  31. package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +0 -125
  32. package/dist/httpsnippet-lite/targets/shell/wget/client.d.ts +0 -12
  33. package/dist/httpsnippet-lite/targets/shell/wget/client.d.ts.map +0 -1
  34. package/dist/httpsnippet-lite/targets/shell/wget/client.js +0 -49
@@ -1 +1 @@
1
- {"version":3,"file":"wget.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shell/wget/wget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAKpD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAQvB,CAAA"}
1
+ {"version":3,"file":"wget.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shell/wget/wget.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AA6BpD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAsFvB,CAAA"}
@@ -1,5 +1,29 @@
1
- import { wget } from '../../../httpsnippet-lite/targets/shell/wget/client.js';
2
- import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
1
+ import { parseMimeType } from '@scalar/helpers/http/mime-type';
2
+ import { escapeSingleQuotes } from '../../../libs/shell.js';
3
+ /**
4
+ * True for `application/json`, any RFC 6839 `+json` structured-syntax suffix
5
+ * (e.g. `application/vnd.api+json`), and parameterized variants
6
+ * (e.g. `application/json;charset=utf-8`). Case-insensitive.
7
+ */
8
+ const isJsonContentType = (value) => {
9
+ if (!value) {
10
+ return false;
11
+ }
12
+ const { subtype } = parseMimeType(value);
13
+ return subtype === 'json' || subtype.endsWith('+json');
14
+ };
15
+ /**
16
+ * Pretty-prints a JSON string and falls back to the original value when it
17
+ * cannot be parsed. Keeps the generated snippet readable, mirroring curl.
18
+ */
19
+ const prettyPrintJson = (text) => {
20
+ try {
21
+ return JSON.stringify(JSON.parse(text), null, 2);
22
+ }
23
+ catch {
24
+ return text;
25
+ }
26
+ };
3
27
  /**
4
28
  * shell/wget
5
29
  */
@@ -7,8 +31,82 @@ export const shellWget = {
7
31
  target: 'shell',
8
32
  client: 'wget',
9
33
  title: 'Wget',
10
- generate(request) {
11
- // TODO: Write an own converter
12
- return convertWithHttpSnippetLite(wget, request);
34
+ generate(request, configuration) {
35
+ // Defaults and normalization. Resolving the method from `request` directly guards
36
+ // against an explicit `method: undefined`, which would otherwise overwrite the default.
37
+ const normalizedRequest = {
38
+ ...request,
39
+ method: (request?.method ?? 'GET').toUpperCase(),
40
+ };
41
+ // Build the URL, joining extra query parameters with `&` when the URL already carries a query string
42
+ const baseUrl = normalizedRequest.url ?? '';
43
+ const separator = baseUrl.includes('?') ? '&' : '?';
44
+ const queryString = normalizedRequest.queryString?.length
45
+ ? separator + normalizedRequest.queryString.map((param) => `${param.name}=${param.value}`).join('&')
46
+ : '';
47
+ const url = `${baseUrl}${queryString}`;
48
+ // Quote the URL whenever it contains anything the shell could interpret (spaces, query separators, globs, …)
49
+ const isShellSafe = /^[A-Za-z0-9._~:/%@+,=-]*$/.test(url);
50
+ const urlPart = isShellSafe ? url : `'${escapeSingleQuotes(url)}'`;
51
+ // Wget runs quietly and writes to stdout so the snippet stays focused on the request
52
+ const parts = ['wget --quiet', `--method ${normalizedRequest.method}`];
53
+ // Basic Auth
54
+ if (configuration?.auth?.username && configuration?.auth?.password) {
55
+ parts.push(`--user '${escapeSingleQuotes(configuration.auth.username)}'`);
56
+ parts.push(`--password '${escapeSingleQuotes(configuration.auth.password)}'`);
57
+ }
58
+ // Headers
59
+ if (normalizedRequest.headers?.length) {
60
+ normalizedRequest.headers.forEach((header) => {
61
+ const headerValue = escapeSingleQuotes(`${header.name}: ${header.value}`);
62
+ parts.push(`--header '${headerValue}'`);
63
+ });
64
+ }
65
+ // Cookies (wget sends cookies through a Cookie header)
66
+ if (normalizedRequest.cookies?.length) {
67
+ const cookieString = normalizedRequest.cookies
68
+ .map((cookie) => `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`)
69
+ .join('; ');
70
+ parts.push(`--header 'Cookie: ${escapeSingleQuotes(cookieString)}'`);
71
+ }
72
+ // Body
73
+ if (normalizedRequest.postData) {
74
+ const { mimeType, text, params } = normalizedRequest.postData;
75
+ if (isJsonContentType(mimeType)) {
76
+ if (text) {
77
+ parts.push(`--body-data '${escapeSingleQuotes(prettyPrintJson(text))}'`);
78
+ }
79
+ }
80
+ else if (mimeType === 'application/octet-stream') {
81
+ parts.push(`--body-data '${escapeSingleQuotes(text ?? '')}'`);
82
+ }
83
+ else if (mimeType === 'application/x-www-form-urlencoded' && params) {
84
+ // Join all fields into a single body, encoding names and values since wget sends --body-data as the raw request body
85
+ const body = params
86
+ .map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value ?? '')}`)
87
+ .join('&');
88
+ parts.push(`--body-data '${escapeSingleQuotes(body)}'`);
89
+ }
90
+ else if (mimeType === 'multipart/form-data' && params) {
91
+ // Wget has no native multipart support, so we approximate it: files are
92
+ // streamed with --body-file and plain fields are sent as --body-data.
93
+ params.forEach((param) => {
94
+ if (param.fileName !== undefined) {
95
+ parts.push(`--body-file='${escapeSingleQuotes(param.fileName)}'`);
96
+ }
97
+ else {
98
+ const rawValue = param.value ?? '';
99
+ const displayValue = isJsonContentType(param.contentType) && rawValue ? prettyPrintJson(rawValue) : rawValue;
100
+ parts.push(`--body-data '${escapeSingleQuotes(`${param.name}=${displayValue}`)}'`);
101
+ }
102
+ });
103
+ }
104
+ else if (text) {
105
+ // Fall back to the raw text, pretty-printing it when it happens to be JSON
106
+ parts.push(`--body-data '${escapeSingleQuotes(prettyPrintJson(text))}'`);
107
+ }
108
+ }
109
+ parts.push('--output-document', `- ${urlPart}`);
110
+ return parts.join(' \\\n ');
13
111
  },
14
112
  };
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.9.12",
12
+ "version": "0.9.14",
13
13
  "engines": {
14
14
  "node": ">=22"
15
15
  },
@@ -240,8 +240,8 @@
240
240
  "dependencies": {
241
241
  "js-base64": "^3.7.8",
242
242
  "stringify-object": "^6.0.0",
243
- "@scalar/helpers": "0.8.1",
244
- "@scalar/types": "0.12.3"
243
+ "@scalar/helpers": "0.8.2",
244
+ "@scalar/types": "0.13.1"
245
245
  },
246
246
  "devDependencies": {
247
247
  "@types/stringify-object": "^4.0.5",
@@ -254,6 +254,6 @@
254
254
  "generate:markdown-docs": "tsx scripts/generate-markdown-docs.ts",
255
255
  "postbuild": "pnpm generate:dotnet-enums && pnpm generate:java-enums && pnpm generate:markdown-docs",
256
256
  "test": "vitest --run",
257
- "types:check": "tsc --noEmit"
257
+ "types:check": "tsgo --noEmit"
258
258
  }
259
259
  }
@@ -1,12 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for Clojure using clj-http.
4
- *
5
- * @author
6
- * @tggreene
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
11
- export declare const clj_http: Client;
12
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/clojure/clj_http/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAgF/D,eAAO,MAAM,QAAQ,EAAE,MAuGtB,CAAA"}
@@ -1,186 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for Clojure using clj-http.
4
- *
5
- * @author
6
- * @tggreene
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
11
- import { getHeader, getHeaderName } from '../../../../httpsnippet-lite/helpers/headers.js';
12
- class Keyword {
13
- name;
14
- toString;
15
- constructor(name) {
16
- this.name = '';
17
- this.toString = () => `:${this.name}`;
18
- this.name = name;
19
- }
20
- }
21
- class File {
22
- path;
23
- toString;
24
- constructor(path) {
25
- this.path = '';
26
- this.toString = () => `(clojure.java.io/file "${this.path}")`;
27
- this.path = path;
28
- }
29
- }
30
- const jsType = (input) => {
31
- if (input === undefined) {
32
- return null;
33
- }
34
- if (input === null) {
35
- return 'null';
36
- }
37
- return input.constructor.name.toLowerCase();
38
- };
39
- const objEmpty = (input) => {
40
- if (jsType(input) === 'object') {
41
- return Object.keys(input).length === 0;
42
- }
43
- return false;
44
- };
45
- const filterEmpty = (input) => {
46
- Object.keys(input)
47
- .filter((x) => objEmpty(input[x]))
48
- .forEach((x) => {
49
- delete input[x];
50
- });
51
- return input;
52
- };
53
- const padBlock = (padSize, input) => {
54
- const padding = ' '.repeat(padSize);
55
- return input.replace(/\n/g, `\n${padding}`);
56
- };
57
- const jsToEdn = (js) => {
58
- switch (jsType(js)) {
59
- case 'string':
60
- return `"${js.replace(/"/g, '\\"')}"`;
61
- case 'file':
62
- return js.toString();
63
- case 'keyword':
64
- return js.toString();
65
- case 'null':
66
- return 'nil';
67
- case 'regexp':
68
- return `#"${js.source}"`;
69
- case 'object': {
70
- // simple vertical format
71
- const obj = Object.keys(js)
72
- .reduce((accumulator, key) => {
73
- const val = padBlock(key.length + 2, jsToEdn(js[key]));
74
- return `${accumulator}:${key} ${val}\n `;
75
- }, '')
76
- .trim();
77
- return `{${padBlock(1, obj)}}`;
78
- }
79
- case 'array': {
80
- // simple horizontal format
81
- const arr = js.reduce((accumulator, value) => `${accumulator} ${jsToEdn(value)}`, '').trim();
82
- return `[${padBlock(1, arr)}]`;
83
- }
84
- default: // 'number' 'boolean'
85
- return js.toString();
86
- }
87
- };
88
- export const clj_http = {
89
- info: {
90
- key: 'clj_http',
91
- title: 'clj-http',
92
- link: 'https://github.com/dakrone/clj-http',
93
- description: 'An idiomatic clojure http client wrapping the apache client.',
94
- },
95
- convert: ({ queryObj, method, postData, url, allHeaders }, options) => {
96
- const { push, join } = new CodeBuilder({
97
- indent: options === null || options === void 0 ? void 0 : options.indent,
98
- });
99
- const methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
100
- method = method.toLowerCase();
101
- if (!methods.includes(method)) {
102
- push('Method not supported');
103
- return join();
104
- }
105
- const params = {
106
- 'headers': allHeaders,
107
- 'query-params': queryObj,
108
- };
109
- // Remove query string from URL if queryObj has parameters
110
- if (queryObj && Object.keys(queryObj).length > 0) {
111
- url = url.split('?')[0];
112
- }
113
- switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
114
- case 'application/json':
115
- {
116
- params['content-type'] = new Keyword('json');
117
- params['form-params'] = postData.jsonObj;
118
- const header = getHeaderName(params.headers, 'content-type');
119
- if (header) {
120
- delete params.headers[header];
121
- }
122
- }
123
- break;
124
- case 'application/x-www-form-urlencoded':
125
- {
126
- params['form-params'] = postData.paramsObj;
127
- const header = getHeaderName(params.headers, 'content-type');
128
- if (header) {
129
- delete params.headers[header];
130
- }
131
- }
132
- break;
133
- case 'text/plain':
134
- {
135
- params.body = postData.text;
136
- const header = getHeaderName(params.headers, 'content-type');
137
- if (header) {
138
- delete params.headers[header];
139
- }
140
- }
141
- break;
142
- case 'multipart/form-data': {
143
- if (postData?.params) {
144
- params.multipart = postData.params.map((param) => {
145
- if (param.fileName && !param.value) {
146
- return {
147
- name: param.name,
148
- content: new File(param.fileName),
149
- };
150
- }
151
- return {
152
- name: param.name,
153
- content: param.value,
154
- };
155
- });
156
- const header = getHeaderName(params.headers, 'content-type');
157
- if (header) {
158
- delete params.headers[header];
159
- }
160
- }
161
- break;
162
- }
163
- }
164
- switch (getHeader(params.headers, 'accept')) {
165
- case 'application/json':
166
- {
167
- params.accept = new Keyword('json');
168
- const header = getHeaderName(params.headers, 'accept');
169
- if (header) {
170
- delete params.headers[header];
171
- }
172
- }
173
- break;
174
- }
175
- push("(require '[clj-http.client :as client])\n");
176
- if (objEmpty(filterEmpty(params))) {
177
- push(`(client/${method} "${url}")`);
178
- }
179
- else {
180
- const padding = 11 + method.length + url.length;
181
- const formattedParams = padBlock(padding, jsToEdn(filterEmpty(params)));
182
- push(`(client/${method} "${url}" ${formattedParams})`);
183
- }
184
- return join();
185
- },
186
- };
@@ -1,3 +0,0 @@
1
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
2
- export declare const restsharp: Client;
3
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/csharp/restsharp/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,SAAS,EAAE,MAkCvB,CAAA"}
@@ -1,36 +0,0 @@
1
- import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
2
- import { escapeForDoubleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
3
- import { getHeader } from '../../../../httpsnippet-lite/helpers/headers.js';
4
- export const restsharp = {
5
- info: {
6
- key: 'restsharp',
7
- title: 'RestSharp',
8
- link: 'http://restsharp.org/',
9
- description: 'Simple REST and HTTP API Client for .NET',
10
- },
11
- convert: ({ allHeaders, method, fullUrl, headersObj, cookies, postData }) => {
12
- const { push, join } = new CodeBuilder();
13
- const isSupportedMethod = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'].includes(method.toUpperCase());
14
- if (!isSupportedMethod) {
15
- return 'Method not supported';
16
- }
17
- push(`var client = new RestClient("${fullUrl}");`);
18
- push(`var request = new RestRequest(Method.${method.toUpperCase()});`);
19
- // Add headers, including the cookies
20
- Object.keys(headersObj).forEach((key) => {
21
- push(`request.AddHeader("${key}", "${escapeForDoubleQuotes(headersObj[key])}");`);
22
- });
23
- cookies === null || cookies === void 0
24
- ? void 0
25
- : cookies.forEach(({ name, value }) => {
26
- push(`request.AddCookie("${name}", "${value}");`);
27
- });
28
- if (postData === null || postData === void 0 ? void 0 : postData.text) {
29
- const header = getHeader(allHeaders, 'content-type');
30
- const text = JSON.stringify(postData.text);
31
- push(`request.AddParameter("${header}", ${text}, ParameterType.RequestBody);`);
32
- }
33
- push('IRestResponse response = client.Execute(request);');
34
- return join();
35
- },
36
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for Kotlin using OkHttp.
4
- *
5
- * @author
6
- * @seanghay
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
11
- export declare const okhttp: Client;
12
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/kotlin/okhttp/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,MAAM,EAAE,MAuEpB,CAAA"}
@@ -1,87 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for Kotlin using OkHttp.
4
- *
5
- * @author
6
- * @seanghay
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
11
- import { escapeForDoubleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
12
- export const okhttp = {
13
- info: {
14
- key: 'okhttp',
15
- title: 'OkHttp',
16
- link: 'http://square.github.io/okhttp/',
17
- description: 'An HTTP Request Client Library',
18
- },
19
- convert: ({ postData, fullUrl, method, allHeaders }, options) => {
20
- const opts = {
21
- indent: ' ',
22
- ...options,
23
- };
24
- const { blank, join, push } = new CodeBuilder({ indent: opts.indent });
25
- const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'];
26
- const methodsWithBody = ['POST', 'PUT', 'DELETE', 'PATCH'];
27
- push('val client = OkHttpClient()');
28
- blank();
29
- if (postData !== null && postData !== void 0) {
30
- if (postData.mimeType === 'application/x-www-form-urlencoded' && postData.params) {
31
- push('val formBody = FormBody.Builder()');
32
- postData.params.forEach((param) => {
33
- push(`.addEncoded("${param.name}", "${param.value}")`, 1);
34
- });
35
- push('.build()', 1);
36
- blank();
37
- }
38
- else if (postData.mimeType === 'multipart/form-data' && postData.params) {
39
- push('val body = MultipartBody.Builder()');
40
- push('.setType(MultipartBody.FORM)', 1);
41
- postData.params.forEach((param) => {
42
- if (param.fileName !== undefined) {
43
- push(`.addFormDataPart("${param.name}", "${param.fileName}", RequestBody.create(MediaType.parse("application/octet-stream"), File("${param.fileName}")))`, 1);
44
- }
45
- else if (param.value !== undefined) {
46
- push(`.addFormDataPart("${param.name}", "${param.value}")`, 1);
47
- }
48
- });
49
- push('.build()', 1);
50
- blank();
51
- }
52
- else {
53
- push(`val mediaType = MediaType.parse("${postData.mimeType}")`);
54
- push(`val body = RequestBody.create(mediaType, ${JSON.stringify(postData.text)})`);
55
- }
56
- }
57
- push('val request = Request.Builder()');
58
- push(`.url("${fullUrl}")`, 1);
59
- if (!methods.includes(method.toUpperCase())) {
60
- if (postData === null || postData === void 0 ? void 0 : postData.text) {
61
- push(`.method("${method.toUpperCase()}", body)`, 1);
62
- }
63
- else {
64
- push(`.method("${method.toUpperCase()}", null)`, 1);
65
- }
66
- }
67
- else if (methodsWithBody.includes(method.toUpperCase())) {
68
- if (postData === null || postData === void 0 ? void 0 : postData.text || postData.params) {
69
- push(`.${method.toLowerCase()}(body)`, 1);
70
- }
71
- else {
72
- push(`.${method.toLowerCase()}(null)`, 1);
73
- }
74
- }
75
- else {
76
- push(`.${method.toLowerCase()}()`, 1);
77
- }
78
- // Add headers, including the cookies
79
- Object.keys(allHeaders).forEach((key) => {
80
- push(`.addHeader("${key}", "${escapeForDoubleQuotes(allHeaders[key])}")`, 1);
81
- });
82
- push('.build()', 1);
83
- blank();
84
- push('val response = client.newCall(request).execute()');
85
- return join();
86
- },
87
- };
@@ -1,21 +0,0 @@
1
- /**
2
- * Create a string corresponding to a valid declaration and initialization of an Objective-C object literal.
3
- *
4
- * @param nsClass Class of the literal
5
- * @param name Desired name of the instance
6
- * @param parameters Key-value object of parameters to translate to an Objective-C object literal
7
- * @param indent If true, will declare the literal by indenting each new key/value pair.
8
- * @return A valid Objective-C declaration and initialization of an Objective-C object literal.
9
- *
10
- * @example
11
- * nsDeclaration('NSDictionary', 'params', {a: 'b', c: 'd'}, true)
12
- * // returns:
13
- * NSDictionary *params = @{ @"a": @"b",
14
- * @"c": @"d" };
15
- *
16
- * nsDeclaration('NSDictionary', 'params', {a: 'b', c: 'd'})
17
- * // returns:
18
- * NSDictionary *params = @{ @"a": @"b", @"c": @"d" };
19
- */
20
- export declare const nsDeclaration: (nsClass: string, name: string, parameters: unknown, indent: boolean) => string;
21
- //# sourceMappingURL=helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/httpsnippet-lite/targets/objc/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,EAAE,MAAM,MAAM,EAAE,YAAY,OAAO,EAAE,QAAQ,OAAO,KAAG,MAInG,CAAA"}
@@ -1,57 +0,0 @@
1
- /**
2
- * Create a string corresponding to a valid declaration and initialization of an Objective-C object literal.
3
- *
4
- * @param nsClass Class of the literal
5
- * @param name Desired name of the instance
6
- * @param parameters Key-value object of parameters to translate to an Objective-C object literal
7
- * @param indent If true, will declare the literal by indenting each new key/value pair.
8
- * @return A valid Objective-C declaration and initialization of an Objective-C object literal.
9
- *
10
- * @example
11
- * nsDeclaration('NSDictionary', 'params', {a: 'b', c: 'd'}, true)
12
- * // returns:
13
- * NSDictionary *params = @{ @"a": @"b",
14
- * @"c": @"d" };
15
- *
16
- * nsDeclaration('NSDictionary', 'params', {a: 'b', c: 'd'})
17
- * // returns:
18
- * NSDictionary *params = @{ @"a": @"b", @"c": @"d" };
19
- */
20
- export const nsDeclaration = (nsClass, name, parameters, indent) => {
21
- const opening = `${nsClass} *${name} = `;
22
- const literal = literalRepresentation(parameters, indent ? opening.length : undefined);
23
- return `${opening}${literal};`;
24
- };
25
- /**
26
- * Create a valid Objective-C string of a literal value according to its type.
27
- *
28
- * @param value Any JavaScript literal
29
- */
30
- const literalRepresentation = (value, indentation) => {
31
- const join = indentation === undefined ? ', ' : `,\n ${' '.repeat(indentation)}`;
32
- switch (Object.prototype.toString.call(value)) {
33
- case '[object Number]':
34
- return `@${value}`;
35
- case '[object Array]': {
36
- const valuesRepresentation = value.map((value) => literalRepresentation(value));
37
- return `@[ ${valuesRepresentation.join(join)} ]`;
38
- }
39
- case '[object Object]': {
40
- const keyValuePairs = [];
41
- const _value = value;
42
- for (const key in _value) {
43
- if (Object.hasOwn(_value, key)) {
44
- keyValuePairs.push(`@"${key}": ${literalRepresentation(_value[key])}`);
45
- }
46
- }
47
- return `@{ ${keyValuePairs.join(join)} }`;
48
- }
49
- case '[object Boolean]':
50
- return value ? '@YES' : '@NO';
51
- default:
52
- if (value === null || value === undefined) {
53
- return '';
54
- }
55
- return `@"${value.toString().replace(/"/g, '\\"')}"`;
56
- }
57
- };
@@ -1,12 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for Objective-C using NSURLSession.
4
- *
5
- * @author
6
- * @thibaultCha
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
- import type { Client } from '../../../../httpsnippet-lite/targets/target.js';
11
- export declare const nsurlsession: Client;
12
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/httpsnippet-lite/targets/objc/nsurlsession/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE/D,eAAO,MAAM,YAAY,EAAE,MA+H1B,CAAA"}