react-native-nitro-fetch 1.2.1 → 1.3.1

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 (60) hide show
  1. package/android/src/main/java/com/margelo/nitro/nitrofetch/AutoPrefetcher.kt +114 -31
  2. package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroFetchClient.kt +43 -6
  3. package/ios/NitroAutoPrefetcher.h +21 -0
  4. package/ios/NitroAutoPrefetcher.swift +149 -27
  5. package/ios/NitroFetchClient.swift +17 -6
  6. package/lib/module/CurlGenerator.js.map +1 -1
  7. package/lib/module/HermesProfiler.js.map +2 -1
  8. package/lib/module/NetworkInspector.js +0 -4
  9. package/lib/module/NetworkInspector.js.map +1 -1
  10. package/lib/module/NitroCronet.nitro.js.map +1 -1
  11. package/lib/module/NitroFetch.nitro.js.map +1 -0
  12. package/lib/module/NitroInstances.js.map +1 -1
  13. package/lib/module/Response.js +3 -4
  14. package/lib/module/Response.js.map +2 -1
  15. package/lib/module/fetch.js +26 -6
  16. package/lib/module/fetch.js.map +1 -1
  17. package/lib/module/index.js +1 -1
  18. package/lib/module/index.js.map +2 -1
  19. package/lib/module/index.web.js +1 -2
  20. package/lib/module/utf8.js +19 -8
  21. package/lib/module/utf8.js.map +2 -1
  22. package/lib/typescript/src/NitroFetch.nitro.d.ts +2 -1
  23. package/lib/typescript/src/NitroFetch.nitro.d.ts.map +1 -1
  24. package/lib/typescript/src/Response.d.ts.map +1 -1
  25. package/lib/typescript/src/fetch.d.ts +4 -1
  26. package/lib/typescript/src/fetch.d.ts.map +1 -1
  27. package/lib/typescript/src/index.d.ts +1 -1
  28. package/lib/typescript/src/index.d.ts.map +1 -1
  29. package/lib/typescript/src/utf8.d.ts.map +1 -1
  30. package/nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.cpp +2 -0
  31. package/nitrogen/generated/android/c++/JNitroRequest.hpp +5 -1
  32. package/nitrogen/generated/android/c++/JNitroResponse.hpp +7 -5
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/NitroRequest.kt +5 -2
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/NitroResponse.kt +3 -3
  35. package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.hpp +15 -0
  36. package/nitrogen/generated/ios/c++/HybridNitroFetchClientSpecSwift.hpp +4 -0
  37. package/nitrogen/generated/ios/swift/NitroRequest.swift +19 -1
  38. package/nitrogen/generated/ios/swift/NitroResponse.swift +8 -8
  39. package/nitrogen/generated/shared/c++/NitroRequest.hpp +5 -1
  40. package/nitrogen/generated/shared/c++/NitroResponse.hpp +6 -5
  41. package/package.json +18 -3
  42. package/src/CurlGenerator.js +31 -0
  43. package/src/Headers.js +127 -0
  44. package/src/HermesProfiler.js +22 -0
  45. package/src/NetworkInspector.js +183 -0
  46. package/src/NitroCronet.nitro.js +1 -0
  47. package/src/NitroFetch.nitro.js +1 -0
  48. package/src/NitroFetch.nitro.ts +4 -2
  49. package/src/NitroInstances.js +6 -0
  50. package/src/Request.js +173 -0
  51. package/src/Response.js +258 -0
  52. package/src/Response.ts +2 -1
  53. package/src/fetch.js +772 -0
  54. package/src/fetch.ts +46 -9
  55. package/src/index.js +10 -0
  56. package/src/index.tsx +1 -0
  57. package/src/index.web.js +104 -0
  58. package/src/tokenRefresh.js +104 -0
  59. package/src/utf8.js +40 -0
  60. package/src/utf8.ts +29 -14
@@ -12,6 +12,8 @@
12
12
 
13
13
  #include "JNitroHeader.hpp"
14
14
  #include "NitroHeader.hpp"
15
+ #include <NitroModules/ArrayBuffer.hpp>
16
+ #include <NitroModules/JArrayBuffer.hpp>
15
17
  #include <optional>
16
18
  #include <string>
17
19
  #include <vector>
@@ -49,8 +51,8 @@ namespace margelo::nitro::nitrofetch {
49
51
  jni::local_ref<jni::JArrayClass<JNitroHeader>> headers = this->getFieldValue(fieldHeaders);
50
52
  static const auto fieldBodyString = clazz->getField<jni::JString>("bodyString");
51
53
  jni::local_ref<jni::JString> bodyString = this->getFieldValue(fieldBodyString);
52
- static const auto fieldBodyBytes = clazz->getField<jni::JString>("bodyBytes");
53
- jni::local_ref<jni::JString> bodyBytes = this->getFieldValue(fieldBodyBytes);
54
+ static const auto fieldBodyBytes = clazz->getField<JArrayBuffer::javaobject>("bodyBytes");
55
+ jni::local_ref<JArrayBuffer::javaobject> bodyBytes = this->getFieldValue(fieldBodyBytes);
54
56
  return NitroResponse(
55
57
  url->toStdString(),
56
58
  status,
@@ -68,7 +70,7 @@ namespace margelo::nitro::nitrofetch {
68
70
  return __vector;
69
71
  }(),
70
72
  bodyString != nullptr ? std::make_optional(bodyString->toStdString()) : std::nullopt,
71
- bodyBytes != nullptr ? std::make_optional(bodyBytes->toStdString()) : std::nullopt
73
+ bodyBytes != nullptr ? std::make_optional(bodyBytes->cthis()->getArrayBuffer()) : std::nullopt
72
74
  );
73
75
  }
74
76
 
@@ -78,7 +80,7 @@ namespace margelo::nitro::nitrofetch {
78
80
  */
79
81
  [[maybe_unused]]
80
82
  static jni::local_ref<JNitroResponse::javaobject> fromCpp(const NitroResponse& value) {
81
- using JSignature = JNitroResponse(jni::alias_ref<jni::JString>, double, jni::alias_ref<jni::JString>, jboolean, jboolean, jni::alias_ref<jni::JArrayClass<JNitroHeader>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
83
+ using JSignature = JNitroResponse(jni::alias_ref<jni::JString>, double, jni::alias_ref<jni::JString>, jboolean, jboolean, jni::alias_ref<jni::JArrayClass<JNitroHeader>>, jni::alias_ref<jni::JString>, jni::alias_ref<JArrayBuffer::javaobject>);
82
84
  static const auto clazz = javaClassStatic();
83
85
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
84
86
  return create(
@@ -99,7 +101,7 @@ namespace margelo::nitro::nitrofetch {
99
101
  return __array;
100
102
  }(),
101
103
  value.bodyString.has_value() ? jni::make_jstring(value.bodyString.value()) : nullptr,
102
- value.bodyBytes.has_value() ? jni::make_jstring(value.bodyBytes.value()) : nullptr
104
+ value.bodyBytes.has_value() ? JArrayBuffer::wrap(value.bodyBytes.value()) : nullptr
103
105
  );
104
106
  }
105
107
  };
@@ -43,6 +43,9 @@ data class NitroRequest(
43
43
  val followRedirects: Boolean?,
44
44
  @DoNotStrip
45
45
  @Keep
46
+ val prefetchCacheTtlMs: Double?,
47
+ @DoNotStrip
48
+ @Keep
46
49
  val requestId: String?
47
50
  ) {
48
51
  /* primary constructor */
@@ -55,8 +58,8 @@ data class NitroRequest(
55
58
  @Keep
56
59
  @Suppress("unused")
57
60
  @JvmStatic
58
- private fun fromCpp(url: String, method: NitroRequestMethod?, headers: Array<NitroHeader>?, bodyString: String?, bodyBytes: String?, bodyFormData: Array<NitroFormDataPart>?, timeoutMs: Double?, followRedirects: Boolean?, requestId: String?): NitroRequest {
59
- return NitroRequest(url, method, headers, bodyString, bodyBytes, bodyFormData, timeoutMs, followRedirects, requestId)
61
+ private fun fromCpp(url: String, method: NitroRequestMethod?, headers: Array<NitroHeader>?, bodyString: String?, bodyBytes: String?, bodyFormData: Array<NitroFormDataPart>?, timeoutMs: Double?, followRedirects: Boolean?, prefetchCacheTtlMs: Double?, requestId: String?): NitroRequest {
62
+ return NitroRequest(url, method, headers, bodyString, bodyBytes, bodyFormData, timeoutMs, followRedirects, prefetchCacheTtlMs, requestId)
60
63
  }
61
64
  }
62
65
  }
@@ -9,7 +9,7 @@ package com.margelo.nitro.nitrofetch
9
9
 
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.proguard.annotations.DoNotStrip
12
-
12
+ import com.margelo.nitro.core.ArrayBuffer
13
13
 
14
14
  /**
15
15
  * Represents the JavaScript object/struct "NitroResponse".
@@ -40,7 +40,7 @@ data class NitroResponse(
40
40
  val bodyString: String?,
41
41
  @DoNotStrip
42
42
  @Keep
43
- val bodyBytes: String?
43
+ val bodyBytes: ArrayBuffer?
44
44
  ) {
45
45
  /* primary constructor */
46
46
 
@@ -52,7 +52,7 @@ data class NitroResponse(
52
52
  @Keep
53
53
  @Suppress("unused")
54
54
  @JvmStatic
55
- private fun fromCpp(url: String, status: Double, statusText: String, ok: Boolean, redirected: Boolean, headers: Array<NitroHeader>, bodyString: String?, bodyBytes: String?): NitroResponse {
55
+ private fun fromCpp(url: String, status: Double, statusText: String, ok: Boolean, redirected: Boolean, headers: Array<NitroHeader>, bodyString: String?, bodyBytes: ArrayBuffer?): NitroResponse {
56
56
  return NitroResponse(url, status, statusText, ok, redirected, headers, bodyString, bodyBytes)
57
57
  }
58
58
  }
@@ -393,6 +393,21 @@ namespace margelo::nitro::nitrofetch::bridge::swift {
393
393
  return optional.value();
394
394
  }
395
395
 
396
+ // pragma MARK: std::optional<std::shared_ptr<ArrayBuffer>>
397
+ /**
398
+ * Specialized version of `std::optional<std::shared_ptr<ArrayBuffer>>`.
399
+ */
400
+ using std__optional_std__shared_ptr_ArrayBuffer__ = std::optional<std::shared_ptr<ArrayBuffer>>;
401
+ inline std::optional<std::shared_ptr<ArrayBuffer>> create_std__optional_std__shared_ptr_ArrayBuffer__(const std::shared_ptr<ArrayBuffer>& value) noexcept {
402
+ return std::optional<std::shared_ptr<ArrayBuffer>>(value);
403
+ }
404
+ inline bool has_value_std__optional_std__shared_ptr_ArrayBuffer__(const std::optional<std::shared_ptr<ArrayBuffer>>& optional) noexcept {
405
+ return optional.has_value();
406
+ }
407
+ inline std::shared_ptr<ArrayBuffer> get_std__optional_std__shared_ptr_ArrayBuffer__(const std::optional<std::shared_ptr<ArrayBuffer>>& optional) noexcept {
408
+ return optional.value();
409
+ }
410
+
396
411
  // pragma MARK: std::shared_ptr<Promise<NitroResponse>>
397
412
  /**
398
413
  * Specialized version of `std::shared_ptr<Promise<NitroResponse>>`.
@@ -16,6 +16,8 @@ namespace NitroFetch { class HybridNitroFetchClientSpec_cxx; }
16
16
  namespace margelo::nitro::nitrofetch { struct NitroResponse; }
17
17
  // Forward declaration of `NitroHeader` to properly resolve imports.
18
18
  namespace margelo::nitro::nitrofetch { struct NitroHeader; }
19
+ // Forward declaration of `ArrayBufferHolder` to properly resolve imports.
20
+ namespace NitroModules { class ArrayBufferHolder; }
19
21
  // Forward declaration of `NitroRequest` to properly resolve imports.
20
22
  namespace margelo::nitro::nitrofetch { struct NitroRequest; }
21
23
  // Forward declaration of `NitroRequestMethod` to properly resolve imports.
@@ -29,6 +31,8 @@ namespace margelo::nitro::nitrofetch { struct NitroFormDataPart; }
29
31
  #include "NitroHeader.hpp"
30
32
  #include <vector>
31
33
  #include <optional>
34
+ #include <NitroModules/ArrayBuffer.hpp>
35
+ #include <NitroModules/ArrayBufferHolder.hpp>
32
36
  #include "NitroRequest.hpp"
33
37
  #include "NitroRequestMethod.hpp"
34
38
  #include "NitroFormDataPart.hpp"
@@ -18,7 +18,7 @@ public extension NitroRequest {
18
18
  /**
19
19
  * Create a new instance of `NitroRequest`.
20
20
  */
21
- init(url: String, method: NitroRequestMethod?, headers: [NitroHeader]?, bodyString: String?, bodyBytes: String?, bodyFormData: [NitroFormDataPart]?, timeoutMs: Double?, followRedirects: Bool?, requestId: String?) {
21
+ init(url: String, method: NitroRequestMethod?, headers: [NitroHeader]?, bodyString: String?, bodyBytes: String?, bodyFormData: [NitroFormDataPart]?, timeoutMs: Double?, followRedirects: Bool?, prefetchCacheTtlMs: Double?, requestId: String?) {
22
22
  self.init(std.string(url), { () -> bridge.std__optional_NitroRequestMethod_ in
23
23
  if let __unwrappedValue = method {
24
24
  return bridge.create_std__optional_NitroRequestMethod_(__unwrappedValue)
@@ -73,6 +73,12 @@ public extension NitroRequest {
73
73
  } else {
74
74
  return .init()
75
75
  }
76
+ }(), { () -> bridge.std__optional_double_ in
77
+ if let __unwrappedValue = prefetchCacheTtlMs {
78
+ return bridge.create_std__optional_double_(__unwrappedValue)
79
+ } else {
80
+ return .init()
81
+ }
76
82
  }(), { () -> bridge.std__optional_std__string_ in
77
83
  if let __unwrappedValue = requestId {
78
84
  return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
@@ -182,6 +188,18 @@ public extension NitroRequest {
182
188
  }()
183
189
  }
184
190
 
191
+ @inline(__always)
192
+ var prefetchCacheTtlMs: Double? {
193
+ return { () -> Double? in
194
+ if bridge.has_value_std__optional_double_(self.__prefetchCacheTtlMs) {
195
+ let __unwrapped = bridge.get_std__optional_double_(self.__prefetchCacheTtlMs)
196
+ return __unwrapped
197
+ } else {
198
+ return nil
199
+ }
200
+ }()
201
+ }
202
+
185
203
  @inline(__always)
186
204
  var requestId: String? {
187
205
  return { () -> String? in
@@ -18,7 +18,7 @@ public extension NitroResponse {
18
18
  /**
19
19
  * Create a new instance of `NitroResponse`.
20
20
  */
21
- init(url: String, status: Double, statusText: String, ok: Bool, redirected: Bool, headers: [NitroHeader], bodyString: String?, bodyBytes: String?) {
21
+ init(url: String, status: Double, statusText: String, ok: Bool, redirected: Bool, headers: [NitroHeader], bodyString: String?, bodyBytes: ArrayBuffer?) {
22
22
  self.init(std.string(url), status, std.string(statusText), ok, redirected, { () -> bridge.std__vector_NitroHeader_ in
23
23
  var __vector = bridge.create_std__vector_NitroHeader_(headers.count)
24
24
  for __item in headers {
@@ -31,9 +31,9 @@ public extension NitroResponse {
31
31
  } else {
32
32
  return .init()
33
33
  }
34
- }(), { () -> bridge.std__optional_std__string_ in
34
+ }(), { () -> bridge.std__optional_std__shared_ptr_ArrayBuffer__ in
35
35
  if let __unwrappedValue = bodyBytes {
36
- return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
36
+ return bridge.create_std__optional_std__shared_ptr_ArrayBuffer__(__unwrappedValue.getArrayBuffer())
37
37
  } else {
38
38
  return .init()
39
39
  }
@@ -92,11 +92,11 @@ public extension NitroResponse {
92
92
  }
93
93
 
94
94
  @inline(__always)
95
- var bodyBytes: String? {
96
- return { () -> String? in
97
- if bridge.has_value_std__optional_std__string_(self.__bodyBytes) {
98
- let __unwrapped = bridge.get_std__optional_std__string_(self.__bodyBytes)
99
- return String(__unwrapped)
95
+ var bodyBytes: ArrayBuffer? {
96
+ return { () -> ArrayBuffer? in
97
+ if bridge.has_value_std__optional_std__shared_ptr_ArrayBuffer__(self.__bodyBytes) {
98
+ let __unwrapped = bridge.get_std__optional_std__shared_ptr_ArrayBuffer__(self.__bodyBytes)
99
+ return ArrayBuffer(__unwrapped)
100
100
  } else {
101
101
  return nil
102
102
  }
@@ -57,11 +57,12 @@ namespace margelo::nitro::nitrofetch {
57
57
  std::optional<std::vector<NitroFormDataPart>> bodyFormData SWIFT_PRIVATE;
58
58
  std::optional<double> timeoutMs SWIFT_PRIVATE;
59
59
  std::optional<bool> followRedirects SWIFT_PRIVATE;
60
+ std::optional<double> prefetchCacheTtlMs SWIFT_PRIVATE;
60
61
  std::optional<std::string> requestId SWIFT_PRIVATE;
61
62
 
62
63
  public:
63
64
  NitroRequest() = default;
64
- explicit NitroRequest(std::string url, std::optional<NitroRequestMethod> method, std::optional<std::vector<NitroHeader>> headers, std::optional<std::string> bodyString, std::optional<std::string> bodyBytes, std::optional<std::vector<NitroFormDataPart>> bodyFormData, std::optional<double> timeoutMs, std::optional<bool> followRedirects, std::optional<std::string> requestId): url(url), method(method), headers(headers), bodyString(bodyString), bodyBytes(bodyBytes), bodyFormData(bodyFormData), timeoutMs(timeoutMs), followRedirects(followRedirects), requestId(requestId) {}
65
+ explicit NitroRequest(std::string url, std::optional<NitroRequestMethod> method, std::optional<std::vector<NitroHeader>> headers, std::optional<std::string> bodyString, std::optional<std::string> bodyBytes, std::optional<std::vector<NitroFormDataPart>> bodyFormData, std::optional<double> timeoutMs, std::optional<bool> followRedirects, std::optional<double> prefetchCacheTtlMs, std::optional<std::string> requestId): url(url), method(method), headers(headers), bodyString(bodyString), bodyBytes(bodyBytes), bodyFormData(bodyFormData), timeoutMs(timeoutMs), followRedirects(followRedirects), prefetchCacheTtlMs(prefetchCacheTtlMs), requestId(requestId) {}
65
66
 
66
67
  public:
67
68
  friend bool operator==(const NitroRequest& lhs, const NitroRequest& rhs) = default;
@@ -85,6 +86,7 @@ namespace margelo::nitro {
85
86
  JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroFormDataPart>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyFormData"))),
86
87
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "timeoutMs"))),
87
88
  JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "followRedirects"))),
89
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "prefetchCacheTtlMs"))),
88
90
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "requestId")))
89
91
  );
90
92
  }
@@ -98,6 +100,7 @@ namespace margelo::nitro {
98
100
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "bodyFormData"), JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroFormDataPart>>>::toJSI(runtime, arg.bodyFormData));
99
101
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "timeoutMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.timeoutMs));
100
102
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "followRedirects"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.followRedirects));
103
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "prefetchCacheTtlMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.prefetchCacheTtlMs));
101
104
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "requestId"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.requestId));
102
105
  return obj;
103
106
  }
@@ -117,6 +120,7 @@ namespace margelo::nitro {
117
120
  if (!JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroFormDataPart>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyFormData")))) return false;
118
121
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "timeoutMs")))) return false;
119
122
  if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "followRedirects")))) return false;
123
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "prefetchCacheTtlMs")))) return false;
120
124
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "requestId")))) return false;
121
125
  return true;
122
126
  }
@@ -35,6 +35,7 @@ namespace margelo::nitro::nitrofetch { struct NitroHeader; }
35
35
  #include "NitroHeader.hpp"
36
36
  #include <vector>
37
37
  #include <optional>
38
+ #include <NitroModules/ArrayBuffer.hpp>
38
39
 
39
40
  namespace margelo::nitro::nitrofetch {
40
41
 
@@ -50,11 +51,11 @@ namespace margelo::nitro::nitrofetch {
50
51
  bool redirected SWIFT_PRIVATE;
51
52
  std::vector<NitroHeader> headers SWIFT_PRIVATE;
52
53
  std::optional<std::string> bodyString SWIFT_PRIVATE;
53
- std::optional<std::string> bodyBytes SWIFT_PRIVATE;
54
+ std::optional<std::shared_ptr<ArrayBuffer>> bodyBytes SWIFT_PRIVATE;
54
55
 
55
56
  public:
56
57
  NitroResponse() = default;
57
- explicit NitroResponse(std::string url, double status, std::string statusText, bool ok, bool redirected, std::vector<NitroHeader> headers, std::optional<std::string> bodyString, std::optional<std::string> bodyBytes): url(url), status(status), statusText(statusText), ok(ok), redirected(redirected), headers(headers), bodyString(bodyString), bodyBytes(bodyBytes) {}
58
+ explicit NitroResponse(std::string url, double status, std::string statusText, bool ok, bool redirected, std::vector<NitroHeader> headers, std::optional<std::string> bodyString, std::optional<std::shared_ptr<ArrayBuffer>> bodyBytes): url(url), status(status), statusText(statusText), ok(ok), redirected(redirected), headers(headers), bodyString(bodyString), bodyBytes(bodyBytes) {}
58
59
 
59
60
  public:
60
61
  friend bool operator==(const NitroResponse& lhs, const NitroResponse& rhs) = default;
@@ -77,7 +78,7 @@ namespace margelo::nitro {
77
78
  JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "redirected"))),
78
79
  JSIConverter<std::vector<margelo::nitro::nitrofetch::NitroHeader>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "headers"))),
79
80
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyString"))),
80
- JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyBytes")))
81
+ JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyBytes")))
81
82
  );
82
83
  }
83
84
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrofetch::NitroResponse& arg) {
@@ -89,7 +90,7 @@ namespace margelo::nitro {
89
90
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "redirected"), JSIConverter<bool>::toJSI(runtime, arg.redirected));
90
91
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "headers"), JSIConverter<std::vector<margelo::nitro::nitrofetch::NitroHeader>>::toJSI(runtime, arg.headers));
91
92
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "bodyString"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.bodyString));
92
- obj.setProperty(runtime, PropNameIDCache::get(runtime, "bodyBytes"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.bodyBytes));
93
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "bodyBytes"), JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::toJSI(runtime, arg.bodyBytes));
93
94
  return obj;
94
95
  }
95
96
  static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -107,7 +108,7 @@ namespace margelo::nitro {
107
108
  if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "redirected")))) return false;
108
109
  if (!JSIConverter<std::vector<margelo::nitro::nitrofetch::NitroHeader>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "headers")))) return false;
109
110
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyString")))) return false;
110
- if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyBytes")))) return false;
111
+ if (!JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyBytes")))) return false;
111
112
  return true;
112
113
  }
113
114
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-fetch",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "Awesome Fetch :)",
5
5
  "main": "./lib/module/index.js",
6
6
  "module": "./lib/module/index.js",
@@ -118,11 +118,26 @@
118
118
  ],
119
119
  "packageManager": "yarn@3.6.1",
120
120
  "jest": {
121
- "preset": "react-native",
121
+ "preset": "ts-jest",
122
+ "testEnvironment": "node",
123
+ "moduleFileExtensions": [
124
+ "ts",
125
+ "tsx",
126
+ "js",
127
+ "jsx",
128
+ "json"
129
+ ],
122
130
  "modulePathIgnorePatterns": [
123
131
  "<rootDir>/example/node_modules",
124
132
  "<rootDir>/lib/"
125
- ]
133
+ ],
134
+ "globals": {
135
+ "ts-jest": {
136
+ "tsconfig": {
137
+ "jsx": "react"
138
+ }
139
+ }
140
+ }
126
141
  },
127
142
  "release-it": {
128
143
  "git": false,
@@ -0,0 +1,31 @@
1
+ function shellEscape(str) {
2
+ if (/^[a-zA-Z0-9._\-/:=@,+]+$/.test(str))
3
+ return str;
4
+ return "'" + str.replace(/'/g, "'\\''") + "'";
5
+ }
6
+ export function generateCurl(options) {
7
+ const parts = ['curl'];
8
+ if (options.method && options.method !== 'GET') {
9
+ parts.push('-X', shellEscape(options.method));
10
+ }
11
+ if (options.headers) {
12
+ for (const h of options.headers) {
13
+ if (h.key.toLowerCase() === 'prefetchkey')
14
+ continue;
15
+ parts.push('-H', shellEscape(`${h.key}: ${h.value}`));
16
+ }
17
+ }
18
+ if (options.body) {
19
+ const maxLen = 10_000;
20
+ const truncated = options.body.length > maxLen
21
+ ? options.body.slice(0, maxLen) + '...[truncated]'
22
+ : options.body;
23
+ parts.push('-d', shellEscape(truncated));
24
+ }
25
+ if (options.verbose)
26
+ parts.push('-v');
27
+ if (options.compressed)
28
+ parts.push('--compressed');
29
+ parts.push(shellEscape(options.url));
30
+ return parts.join(' ');
31
+ }
package/src/Headers.js ADDED
@@ -0,0 +1,127 @@
1
+ function normalizeName(name) {
2
+ return name.toLowerCase();
3
+ }
4
+ export class NitroHeaders {
5
+ _map;
6
+ constructor(init) {
7
+ this._map = new Map();
8
+ if (!init)
9
+ return;
10
+ if (init instanceof NitroHeaders) {
11
+ init._map.forEach((values, key) => {
12
+ this._map.set(key, [...values]);
13
+ });
14
+ }
15
+ else if (typeof init === 'object' &&
16
+ !Array.isArray(init) &&
17
+ typeof init.forEach === 'function' &&
18
+ typeof init.get === 'function') {
19
+ // Headers-like object (standard Headers or duck-typed)
20
+ init.forEach((value, key) => {
21
+ this._map.set(normalizeName(key), [value]);
22
+ });
23
+ }
24
+ else if (Array.isArray(init)) {
25
+ for (const entry of init) {
26
+ if (Array.isArray(entry) && entry.length >= 2) {
27
+ // [string, string] tuple
28
+ const key = normalizeName(String(entry[0]));
29
+ const value = String(entry[1]);
30
+ const existing = this._map.get(key);
31
+ if (existing)
32
+ existing.push(value);
33
+ else
34
+ this._map.set(key, [value]);
35
+ }
36
+ else if (entry &&
37
+ typeof entry === 'object' &&
38
+ 'key' in entry &&
39
+ 'value' in entry) {
40
+ // NitroHeader object
41
+ const key = normalizeName(entry.key);
42
+ const value = entry.value;
43
+ const existing = this._map.get(key);
44
+ if (existing)
45
+ existing.push(value);
46
+ else
47
+ this._map.set(key, [value]);
48
+ }
49
+ }
50
+ }
51
+ else if (typeof init === 'object' && init !== null) {
52
+ const keys = Object.keys(init);
53
+ for (let i = 0; i < keys.length; i++) {
54
+ const k = keys[i];
55
+ const v = init[k];
56
+ if (v !== undefined) {
57
+ this._map.set(normalizeName(k), [String(v)]);
58
+ }
59
+ }
60
+ }
61
+ }
62
+ append(name, value) {
63
+ const key = normalizeName(name);
64
+ const existing = this._map.get(key);
65
+ if (existing)
66
+ existing.push(value);
67
+ else
68
+ this._map.set(key, [value]);
69
+ }
70
+ delete(name) {
71
+ this._map.delete(normalizeName(name));
72
+ }
73
+ get(name) {
74
+ const values = this._map.get(normalizeName(name));
75
+ if (!values || values.length === 0)
76
+ return null;
77
+ return values.join(', ');
78
+ }
79
+ getSetCookie() {
80
+ return this._map.get('set-cookie') ?? [];
81
+ }
82
+ has(name) {
83
+ return this._map.has(normalizeName(name));
84
+ }
85
+ set(name, value) {
86
+ this._map.set(normalizeName(name), [value]);
87
+ }
88
+ forEach(callback, thisArg) {
89
+ const sortedKeys = Array.from(this._map.keys()).sort();
90
+ for (const key of sortedKeys) {
91
+ callback.call(thisArg, this._map.get(key).join(', '), key, this);
92
+ }
93
+ }
94
+ entries() {
95
+ const map = this._map;
96
+ const sortedKeys = Array.from(map.keys()).sort();
97
+ function* gen() {
98
+ for (const key of sortedKeys) {
99
+ yield [key, map.get(key).join(', ')];
100
+ }
101
+ }
102
+ return gen();
103
+ }
104
+ keys() {
105
+ const map = this._map;
106
+ const sortedKeys = Array.from(map.keys()).sort();
107
+ function* gen() {
108
+ for (const key of sortedKeys) {
109
+ yield key;
110
+ }
111
+ }
112
+ return gen();
113
+ }
114
+ values() {
115
+ const map = this._map;
116
+ const sortedKeys = Array.from(map.keys()).sort();
117
+ function* gen() {
118
+ for (const key of sortedKeys) {
119
+ yield map.get(key).join(', ');
120
+ }
121
+ }
122
+ return gen();
123
+ }
124
+ [Symbol.iterator]() {
125
+ return this.entries();
126
+ }
127
+ }
@@ -0,0 +1,22 @@
1
+ export async function profileFetch(fn, outputPath) {
2
+ const hermes = global.HermesInternal;
3
+ if (!hermes) {
4
+ const result = await fn();
5
+ return { result };
6
+ }
7
+ const path = outputPath ?? `/tmp/nitrofetch-profile-${Date.now()}.cpuprofile`;
8
+ hermes.enableSamplingProfiler();
9
+ try {
10
+ const result = await fn();
11
+ return { result, profilePath: path };
12
+ }
13
+ finally {
14
+ hermes.disableSamplingProfiler();
15
+ try {
16
+ hermes.dumpSamplingProfiler(path);
17
+ }
18
+ catch {
19
+ // Profile dump may fail on some platforms
20
+ }
21
+ }
22
+ }