@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.
package/dist/index.cjs CHANGED
@@ -3307,7 +3307,7 @@ var urlsession = {
3307
3307
  description: "Foundation's URLSession request",
3308
3308
  extname: ".swift"
3309
3309
  },
3310
- convert: ({ allHeaders, postData, fullUrl, method }, options) => {
3310
+ convert: ({ allHeaders, postData, uriObj, queryObj, method }, options) => {
3311
3311
  const opts = {
3312
3312
  indent: " ",
3313
3313
  pretty: true,
@@ -3381,7 +3381,32 @@ var urlsession = {
3381
3381
  }
3382
3382
  }
3383
3383
  blank();
3384
- push(`var request = URLRequest(url: URL(string: "${fullUrl}")!)`);
3384
+ push(`let url = URL(string: "${uriObj.href}")!`);
3385
+ const queries = queryObj ? Object.entries(queryObj) : [];
3386
+ if (queries.length < 1) {
3387
+ push("var request = URLRequest(url: url)");
3388
+ } else {
3389
+ push("var components = URLComponents(url: url, resolvingAgainstBaseURL: true)!");
3390
+ push("let queryItems: [URLQueryItem] = [");
3391
+ queries.forEach((query) => {
3392
+ const key = query[0];
3393
+ const value = query[1];
3394
+ switch (Object.prototype.toString.call(value)) {
3395
+ case "[object String]":
3396
+ push(`${opts.indent}URLQueryItem(name: "${key}", value: "${value}"),`);
3397
+ break;
3398
+ case "[object Array]":
3399
+ value.forEach((val) => {
3400
+ push(`${opts.indent}URLQueryItem(name: "${key}", value: "${val}"),`);
3401
+ });
3402
+ break;
3403
+ }
3404
+ });
3405
+ push("]");
3406
+ push("components.queryItems = components.queryItems.map { $0 + queryItems } ?? queryItems");
3407
+ blank();
3408
+ push("var request = URLRequest(url: components.url!)");
3409
+ }
3385
3410
  push(`request.httpMethod = "${method}"`);
3386
3411
  if (req.hasHeaders) {
3387
3412
  push("request.allHTTPHeaderFields = headers");
@@ -3390,7 +3415,7 @@ var urlsession = {
3390
3415
  push("request.httpBody = postData");
3391
3416
  }
3392
3417
  blank();
3393
- push("let (data, response) = try await URLSession.shared.data(with: request)");
3418
+ push("let (data, response) = try await URLSession.shared.data(for: request)");
3394
3419
  push("print(String(decoding: data, as: UTF8.self))");
3395
3420
  blank();
3396
3421
  return join();