@readme/httpsnippet 10.0.1 → 10.0.3

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.
@@ -3223,7 +3223,7 @@ var urlsession = {
3223
3223
  description: "Foundation's URLSession request",
3224
3224
  extname: ".swift"
3225
3225
  },
3226
- convert: ({ allHeaders, postData, fullUrl, method }, options) => {
3226
+ convert: ({ allHeaders, postData, uriObj, queryObj, method }, options) => {
3227
3227
  const opts = {
3228
3228
  indent: " ",
3229
3229
  pretty: true,
@@ -3297,7 +3297,32 @@ var urlsession = {
3297
3297
  }
3298
3298
  }
3299
3299
  blank();
3300
- push(`var request = URLRequest(url: URL(string: "${fullUrl}")!)`);
3300
+ push(`let url = URL(string: "${uriObj.href}")!`);
3301
+ const queries = queryObj ? Object.entries(queryObj) : [];
3302
+ if (queries.length < 1) {
3303
+ push("var request = URLRequest(url: url)");
3304
+ } else {
3305
+ push("var components = URLComponents(url: url, resolvingAgainstBaseURL: true)!");
3306
+ push("let queryItems: [URLQueryItem] = [");
3307
+ queries.forEach((query) => {
3308
+ const key = query[0];
3309
+ const value = query[1];
3310
+ switch (Object.prototype.toString.call(value)) {
3311
+ case "[object String]":
3312
+ push(`${opts.indent}URLQueryItem(name: "${key}", value: "${value}"),`);
3313
+ break;
3314
+ case "[object Array]":
3315
+ value.forEach((val) => {
3316
+ push(`${opts.indent}URLQueryItem(name: "${key}", value: "${val}"),`);
3317
+ });
3318
+ break;
3319
+ }
3320
+ });
3321
+ push("]");
3322
+ push("components.queryItems = components.queryItems.map { $0 + queryItems } ?? queryItems");
3323
+ blank();
3324
+ push("var request = URLRequest(url: components.url!)");
3325
+ }
3301
3326
  push(`request.httpMethod = "${method}"`);
3302
3327
  if (req.hasHeaders) {
3303
3328
  push("request.allHTTPHeaderFields = headers");
@@ -3306,7 +3331,7 @@ var urlsession = {
3306
3331
  push("request.httpBody = postData");
3307
3332
  }
3308
3333
  blank();
3309
- push("let (data, response) = try await URLSession.shared.data(with: request)");
3334
+ push("let (data, response) = try await URLSession.shared.data(for: request)");
3310
3335
  push("print(String(decoding: data, as: UTF8.self))");
3311
3336
  blank();
3312
3337
  return join();
@@ -3440,4 +3465,4 @@ var addTargetClient = (targetId, client) => {
3440
3465
 
3441
3466
  export { addClientPlugin, addTarget, addTargetClient, getHeaderName, isClient, isTarget, targets };
3442
3467
  //# sourceMappingURL=out.js.map
3443
- //# sourceMappingURL=chunk-M6LAZDIU.js.map
3468
+ //# sourceMappingURL=chunk-ZPGGGDJK.js.map