@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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { reducer } from './chunk-KT7MO6Z4.js';
2
- import { targets, getHeaderName } from './chunk-M6LAZDIU.js';
3
- export { addClientPlugin, addTarget, addTargetClient } from './chunk-M6LAZDIU.js';
2
+ import { targets, getHeaderName } from './chunk-ZPGGGDJK.js';
3
+ export { addClientPlugin, addTarget, addTargetClient } from './chunk-ZPGGGDJK.js';
4
4
  import './chunk-Y7NI4MMY.js';
5
5
  import { parse, format } from 'url';
6
6
  import { stringify } from 'qs';
@@ -3288,7 +3288,7 @@ var urlsession = {
3288
3288
  description: "Foundation's URLSession request",
3289
3289
  extname: ".swift"
3290
3290
  },
3291
- convert: ({ allHeaders, postData, fullUrl, method }, options) => {
3291
+ convert: ({ allHeaders, postData, uriObj, queryObj, method }, options) => {
3292
3292
  const opts = {
3293
3293
  indent: " ",
3294
3294
  pretty: true,
@@ -3362,7 +3362,32 @@ var urlsession = {
3362
3362
  }
3363
3363
  }
3364
3364
  blank();
3365
- push(`var request = URLRequest(url: URL(string: "${fullUrl}")!)`);
3365
+ push(`let url = URL(string: "${uriObj.href}")!`);
3366
+ const queries = queryObj ? Object.entries(queryObj) : [];
3367
+ if (queries.length < 1) {
3368
+ push("var request = URLRequest(url: url)");
3369
+ } else {
3370
+ push("var components = URLComponents(url: url, resolvingAgainstBaseURL: true)!");
3371
+ push("let queryItems: [URLQueryItem] = [");
3372
+ queries.forEach((query) => {
3373
+ const key = query[0];
3374
+ const value = query[1];
3375
+ switch (Object.prototype.toString.call(value)) {
3376
+ case "[object String]":
3377
+ push(`${opts.indent}URLQueryItem(name: "${key}", value: "${value}"),`);
3378
+ break;
3379
+ case "[object Array]":
3380
+ value.forEach((val) => {
3381
+ push(`${opts.indent}URLQueryItem(name: "${key}", value: "${val}"),`);
3382
+ });
3383
+ break;
3384
+ }
3385
+ });
3386
+ push("]");
3387
+ push("components.queryItems = components.queryItems.map { $0 + queryItems } ?? queryItems");
3388
+ blank();
3389
+ push("var request = URLRequest(url: components.url!)");
3390
+ }
3366
3391
  push(`request.httpMethod = "${method}"`);
3367
3392
  if (req.hasHeaders) {
3368
3393
  push("request.allHTTPHeaderFields = headers");
@@ -3371,7 +3396,7 @@ var urlsession = {
3371
3396
  push("request.httpBody = postData");
3372
3397
  }
3373
3398
  blank();
3374
- push("let (data, response) = try await URLSession.shared.data(with: request)");
3399
+ push("let (data, response) = try await URLSession.shared.data(for: request)");
3375
3400
  push("print(String(decoding: data, as: UTF8.self))");
3376
3401
  blank();
3377
3402
  return join();