@scalar/snippetz 0.9.16 → 0.9.17
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libcurl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/c/libcurl/libcurl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAuB,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"libcurl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/c/libcurl/libcurl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAuB,MAAM,wBAAwB,CAAA;AA6FzE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MAqHtB,CAAA"}
|
|
@@ -52,6 +52,26 @@ const formatJsonBody = (text) => {
|
|
|
52
52
|
return text;
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Builds the CURLOPT_POSTFIELDS statement.
|
|
57
|
+
*
|
|
58
|
+
* Multi-line bodies (like pretty-printed JSON) are emitted as adjacent C string
|
|
59
|
+
* literals — one per line — so the generated code stays readable instead of
|
|
60
|
+
* collapsing the whole payload onto a single line of escaped text.
|
|
61
|
+
*/
|
|
62
|
+
const buildPostFields = (value) => {
|
|
63
|
+
const sourceLines = value.split('\n');
|
|
64
|
+
if (sourceLines.length <= 1) {
|
|
65
|
+
return [` curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "${escapeCString(value)}");`];
|
|
66
|
+
}
|
|
67
|
+
return [
|
|
68
|
+
' curl_easy_setopt(curl, CURLOPT_POSTFIELDS,',
|
|
69
|
+
...sourceLines.map((line, index) => {
|
|
70
|
+
const isLastLine = index === sourceLines.length - 1;
|
|
71
|
+
return ` "${escapeCString(line)}${isLastLine ? '' : '\\n'}"${isLastLine ? ');' : ''}`;
|
|
72
|
+
}),
|
|
73
|
+
];
|
|
74
|
+
};
|
|
55
75
|
/**
|
|
56
76
|
* c/libcurl
|
|
57
77
|
*/
|
|
@@ -133,11 +153,11 @@ export const cLibcurl = {
|
|
|
133
153
|
}
|
|
134
154
|
}
|
|
135
155
|
else if (body.mimeType === 'application/json' && body.text !== undefined) {
|
|
136
|
-
lines.push('',
|
|
156
|
+
lines.push('', ...buildPostFields(formatJsonBody(body.text)));
|
|
137
157
|
}
|
|
138
158
|
else if (body.text !== undefined) {
|
|
139
159
|
const fallbackBody = body.mimeType === 'application/octet-stream' ? body.text : formatJsonBody(body.text);
|
|
140
|
-
lines.push('',
|
|
160
|
+
lines.push('', ...buildPostFields(fallbackBody));
|
|
141
161
|
}
|
|
142
162
|
}
|
|
143
163
|
lines.push('', ' CURLcode res = curl_easy_perform(curl);');
|
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
|
+
"version": "0.9.17",
|
|
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/
|
|
244
|
-
"@scalar/
|
|
243
|
+
"@scalar/types": "0.14.0",
|
|
244
|
+
"@scalar/helpers": "0.8.2"
|
|
245
245
|
},
|
|
246
246
|
"devDependencies": {
|
|
247
247
|
"@types/stringify-object": "^4.0.5",
|