react-native-nitro-fetch 0.1.7 → 0.2.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.
- package/android/src/main/java/com/margelo/nitro/nitrofetch/AutoPrefetcher.kt +3 -1
- package/android/src/main/java/com/margelo/nitro/nitrofetch/CronetExtensions.kt +31 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroCronet.kt +89 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroFetchClient.kt +115 -28
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroUrlRequest.kt +35 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroUrlRequestBuilder.kt +181 -0
- package/ios/HybridNitroCronet.swift +31 -0
- package/ios/HybridUrlRequest.swift +41 -0
- package/ios/HybridUrlRequestBuilder.swift +255 -0
- package/ios/NitroAutoPrefetcher.swift +3 -1
- package/ios/NitroFetchClient.swift +87 -5
- package/ios/URLSessionExtensions.swift +36 -0
- package/lib/module/NitroCronet.nitro.js +4 -0
- package/lib/module/NitroCronet.nitro.js.map +1 -0
- package/lib/module/NitroInstances.js +1 -0
- package/lib/module/NitroInstances.js.map +1 -1
- package/lib/module/fetch.js +179 -9
- package/lib/module/fetch.js.map +1 -1
- package/lib/typescript/src/NitroCronet.nitro.d.ts +53 -0
- package/lib/typescript/src/NitroCronet.nitro.d.ts.map +1 -0
- package/lib/typescript/src/NitroFetch.nitro.d.ts +10 -0
- package/lib/typescript/src/NitroFetch.nitro.d.ts.map +1 -1
- package/lib/typescript/src/NitroInstances.d.ts +3 -1
- package/lib/typescript/src/NitroInstances.d.ts.map +1 -1
- package/lib/typescript/src/fetch.d.ts +5 -2
- package/lib/typescript/src/fetch.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/nitro.json +34 -6
- package/nitrogen/generated/android/c++/JFunc_void_UrlResponseInfo.hpp +82 -0
- package/nitrogen/generated/android/c++/JFunc_void_UrlResponseInfo_std__shared_ptr_ArrayBuffer__double.hpp +84 -0
- package/nitrogen/generated/android/c++/JFunc_void_UrlResponseInfo_std__string.hpp +82 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__optional_UrlResponseInfo_.hpp +83 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__optional_UrlResponseInfo__RequestException.hpp +85 -0
- package/nitrogen/generated/android/c++/JHttpHeader.hpp +61 -0
- package/nitrogen/generated/android/c++/JHybridNativeStorageSpec.cpp +23 -16
- package/nitrogen/generated/android/c++/JHybridNativeStorageSpec.hpp +20 -21
- package/nitrogen/generated/android/c++/JHybridNitroCronetSpec.cpp +57 -0
- package/nitrogen/generated/android/c++/JHybridNitroCronetSpec.hpp +63 -0
- package/nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.cpp +32 -16
- package/nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.hpp +21 -21
- package/nitrogen/generated/android/c++/JHybridNitroFetchSpec.cpp +22 -15
- package/nitrogen/generated/android/c++/JHybridNitroFetchSpec.hpp +20 -21
- package/nitrogen/generated/android/c++/JHybridUrlRequestBuilderSpec.cpp +123 -0
- package/nitrogen/generated/android/c++/JHybridUrlRequestBuilderSpec.hpp +73 -0
- package/nitrogen/generated/android/c++/JHybridUrlRequestSpec.cpp +69 -0
- package/nitrogen/generated/android/c++/JHybridUrlRequestSpec.hpp +67 -0
- package/nitrogen/generated/android/c++/JNitroFormDataPart.hpp +74 -0
- package/nitrogen/generated/android/c++/JNitroHeader.hpp +7 -3
- package/nitrogen/generated/android/c++/JNitroRequest.hpp +39 -6
- package/nitrogen/generated/android/c++/JNitroRequestMethod.hpp +9 -10
- package/nitrogen/generated/android/c++/JNitroResponse.hpp +9 -4
- package/nitrogen/generated/android/c++/JRequestException.hpp +57 -0
- package/nitrogen/generated/android/c++/JUrlResponseInfo.hpp +146 -0
- package/nitrogen/generated/android/c++/JVariant_ArrayBuffer_String.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_ArrayBuffer_String.hpp +70 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/Func_void_UrlResponseInfo.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/Func_void_UrlResponseInfo_std__shared_ptr_ArrayBuffer__double.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/Func_void_UrlResponseInfo_std__string.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/Func_void_std__optional_UrlResponseInfo_.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/Func_void_std__optional_UrlResponseInfo__RequestException.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HttpHeader.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNativeStorageSpec.kt +18 -16
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNitroCronetSpec.kt +54 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNitroFetchClientSpec.kt +23 -16
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNitroFetchSpec.kt +18 -16
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridUrlRequestBuilderSpec.kt +125 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridUrlRequestSpec.kt +70 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/NitroFormDataPart.kt +50 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/NitroHeader.kt +19 -10
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/NitroRequest.kt +40 -25
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/NitroRequestMethod.kt +3 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/NitroResponse.kt +39 -30
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/RequestException.kt +38 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/UrlResponseInfo.kt +65 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/Variant_ArrayBuffer_String.kt +53 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/nitrofetchOnLoad.kt +1 -1
- package/nitrogen/generated/android/nitrofetch+autolinking.cmake +8 -1
- package/nitrogen/generated/android/nitrofetch+autolinking.gradle +1 -1
- package/nitrogen/generated/android/nitrofetchOnLoad.cpp +85 -33
- package/nitrogen/generated/android/nitrofetchOnLoad.hpp +14 -5
- package/nitrogen/generated/ios/NitroFetch+autolinking.rb +2 -2
- package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.cpp +102 -10
- package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.hpp +359 -24
- package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Umbrella.hpp +32 -1
- package/nitrogen/generated/ios/NitroFetchAutolinking.mm +9 -1
- package/nitrogen/generated/ios/NitroFetchAutolinking.swift +29 -22
- package/nitrogen/generated/ios/c++/HybridNativeStorageSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridNativeStorageSpecSwift.hpp +10 -1
- package/nitrogen/generated/ios/c++/HybridNitroCronetSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroCronetSpecSwift.hpp +85 -0
- package/nitrogen/generated/ios/c++/HybridNitroFetchClientSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridNitroFetchClientSpecSwift.hpp +22 -4
- package/nitrogen/generated/ios/c++/HybridNitroFetchSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridNitroFetchSpecSwift.hpp +10 -1
- package/nitrogen/generated/ios/c++/HybridUrlRequestBuilderSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridUrlRequestBuilderSpecSwift.hpp +163 -0
- package/nitrogen/generated/ios/c++/HybridUrlRequestSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridUrlRequestSpecSwift.hpp +106 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +1 -2
- package/nitrogen/generated/ios/swift/Func_void_NitroResponse.swift +1 -2
- package/nitrogen/generated/ios/swift/Func_void_UrlResponseInfo.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_UrlResponseInfo_std__shared_ptr_ArrayBuffer__double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_UrlResponseInfo_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -2
- package/nitrogen/generated/ios/swift/Func_void_std__optional_UrlResponseInfo_.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_UrlResponseInfo__RequestException.swift +46 -0
- package/nitrogen/generated/ios/swift/HttpHeader.swift +34 -0
- package/nitrogen/generated/ios/swift/HybridNativeStorageSpec.swift +10 -4
- package/nitrogen/generated/ios/swift/HybridNativeStorageSpec_cxx.swift +18 -3
- package/nitrogen/generated/ios/swift/HybridNitroCronetSpec.swift +55 -0
- package/nitrogen/generated/ios/swift/HybridNitroCronetSpec_cxx.swift +141 -0
- package/nitrogen/generated/ios/swift/HybridNitroFetchClientSpec.swift +11 -4
- package/nitrogen/generated/ios/swift/HybridNitroFetchClientSpec_cxx.swift +29 -3
- package/nitrogen/generated/ios/swift/HybridNitroFetchSpec.swift +10 -4
- package/nitrogen/generated/ios/swift/HybridNitroFetchSpec_cxx.swift +18 -3
- package/nitrogen/generated/ios/swift/HybridUrlRequestBuilderSpec.swift +65 -0
- package/nitrogen/generated/ios/swift/HybridUrlRequestBuilderSpec_cxx.swift +305 -0
- package/nitrogen/generated/ios/swift/HybridUrlRequestSpec.swift +59 -0
- package/nitrogen/generated/ios/swift/HybridUrlRequestSpec_cxx.swift +182 -0
- package/nitrogen/generated/ios/swift/NitroFormDataPart.swift +101 -0
- package/nitrogen/generated/ios/swift/NitroHeader.swift +5 -17
- package/nitrogen/generated/ios/swift/NitroRequest.swift +111 -121
- package/nitrogen/generated/ios/swift/NitroRequestMethod.swift +1 -1
- package/nitrogen/generated/ios/swift/NitroResponse.swift +40 -97
- package/nitrogen/generated/ios/swift/RequestException.swift +29 -0
- package/nitrogen/generated/ios/swift/UrlResponseInfo.swift +118 -0
- package/nitrogen/generated/ios/swift/Variant_ArrayBuffer_String.swift +18 -0
- package/nitrogen/generated/shared/c++/HttpHeader.hpp +87 -0
- package/nitrogen/generated/shared/c++/HybridNativeStorageSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNativeStorageSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNitroCronetSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridNitroCronetSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/HybridNitroFetchClientSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridNitroFetchClientSpec.hpp +3 -1
- package/nitrogen/generated/shared/c++/HybridNitroFetchSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNitroFetchSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUrlRequestBuilderSpec.cpp +31 -0
- package/nitrogen/generated/shared/c++/HybridUrlRequestBuilderSpec.hpp +85 -0
- package/nitrogen/generated/shared/c++/HybridUrlRequestSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridUrlRequestSpec.hpp +66 -0
- package/nitrogen/generated/shared/c++/NitroFormDataPart.hpp +100 -0
- package/nitrogen/generated/shared/c++/NitroHeader.hpp +24 -8
- package/nitrogen/generated/shared/c++/NitroRequest.hpp +51 -24
- package/nitrogen/generated/shared/c++/NitroRequestMethod.hpp +1 -1
- package/nitrogen/generated/shared/c++/NitroResponse.hpp +42 -26
- package/nitrogen/generated/shared/c++/RequestException.hpp +83 -0
- package/nitrogen/generated/shared/c++/UrlResponseInfo.hpp +123 -0
- package/package.json +13 -10
- package/src/NitroCronet.nitro.ts +72 -0
- package/src/NitroFetch.nitro.ts +28 -6
- package/src/NitroInstances.ts +4 -0
- package/src/fetch.ts +214 -13
- package/src/index.tsx +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// RequestException.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
#include <string>
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::nitrofetch {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (RequestException).
|
|
39
|
+
*/
|
|
40
|
+
struct RequestException final {
|
|
41
|
+
public:
|
|
42
|
+
std::string message SWIFT_PRIVATE;
|
|
43
|
+
|
|
44
|
+
public:
|
|
45
|
+
RequestException() = default;
|
|
46
|
+
explicit RequestException(std::string message): message(message) {}
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
friend bool operator==(const RequestException& lhs, const RequestException& rhs) = default;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
} // namespace margelo::nitro::nitrofetch
|
|
53
|
+
|
|
54
|
+
namespace margelo::nitro {
|
|
55
|
+
|
|
56
|
+
// C++ RequestException <> JS RequestException (object)
|
|
57
|
+
template <>
|
|
58
|
+
struct JSIConverter<margelo::nitro::nitrofetch::RequestException> final {
|
|
59
|
+
static inline margelo::nitro::nitrofetch::RequestException fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
60
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
61
|
+
return margelo::nitro::nitrofetch::RequestException(
|
|
62
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message")))
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrofetch::RequestException& arg) {
|
|
66
|
+
jsi::Object obj(runtime);
|
|
67
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "message"), JSIConverter<std::string>::toJSI(runtime, arg.message));
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
71
|
+
if (!value.isObject()) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
jsi::Object obj = value.getObject(runtime);
|
|
75
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message")))) return false;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// UrlResponseInfo.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
// Forward declaration of `HttpHeader` to properly resolve imports.
|
|
32
|
+
namespace margelo::nitro::nitrofetch { struct HttpHeader; }
|
|
33
|
+
|
|
34
|
+
#include <string>
|
|
35
|
+
#include <unordered_map>
|
|
36
|
+
#include "HttpHeader.hpp"
|
|
37
|
+
#include <vector>
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro::nitrofetch {
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A struct which can be represented as a JavaScript object (UrlResponseInfo).
|
|
43
|
+
*/
|
|
44
|
+
struct UrlResponseInfo final {
|
|
45
|
+
public:
|
|
46
|
+
std::string url SWIFT_PRIVATE;
|
|
47
|
+
double httpStatusCode SWIFT_PRIVATE;
|
|
48
|
+
std::string httpStatusText SWIFT_PRIVATE;
|
|
49
|
+
std::unordered_map<std::string, std::string> allHeaders SWIFT_PRIVATE;
|
|
50
|
+
std::vector<HttpHeader> allHeadersAsList SWIFT_PRIVATE;
|
|
51
|
+
std::vector<std::string> urlChain SWIFT_PRIVATE;
|
|
52
|
+
std::string negotiatedProtocol SWIFT_PRIVATE;
|
|
53
|
+
std::string proxyServer SWIFT_PRIVATE;
|
|
54
|
+
double receivedByteCount SWIFT_PRIVATE;
|
|
55
|
+
bool wasCached SWIFT_PRIVATE;
|
|
56
|
+
|
|
57
|
+
public:
|
|
58
|
+
UrlResponseInfo() = default;
|
|
59
|
+
explicit UrlResponseInfo(std::string url, double httpStatusCode, std::string httpStatusText, std::unordered_map<std::string, std::string> allHeaders, std::vector<HttpHeader> allHeadersAsList, std::vector<std::string> urlChain, std::string negotiatedProtocol, std::string proxyServer, double receivedByteCount, bool wasCached): url(url), httpStatusCode(httpStatusCode), httpStatusText(httpStatusText), allHeaders(allHeaders), allHeadersAsList(allHeadersAsList), urlChain(urlChain), negotiatedProtocol(negotiatedProtocol), proxyServer(proxyServer), receivedByteCount(receivedByteCount), wasCached(wasCached) {}
|
|
60
|
+
|
|
61
|
+
public:
|
|
62
|
+
friend bool operator==(const UrlResponseInfo& lhs, const UrlResponseInfo& rhs) = default;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace margelo::nitro::nitrofetch
|
|
66
|
+
|
|
67
|
+
namespace margelo::nitro {
|
|
68
|
+
|
|
69
|
+
// C++ UrlResponseInfo <> JS UrlResponseInfo (object)
|
|
70
|
+
template <>
|
|
71
|
+
struct JSIConverter<margelo::nitro::nitrofetch::UrlResponseInfo> final {
|
|
72
|
+
static inline margelo::nitro::nitrofetch::UrlResponseInfo fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
73
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
74
|
+
return margelo::nitro::nitrofetch::UrlResponseInfo(
|
|
75
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "url"))),
|
|
76
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "httpStatusCode"))),
|
|
77
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "httpStatusText"))),
|
|
78
|
+
JSIConverter<std::unordered_map<std::string, std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "allHeaders"))),
|
|
79
|
+
JSIConverter<std::vector<margelo::nitro::nitrofetch::HttpHeader>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "allHeadersAsList"))),
|
|
80
|
+
JSIConverter<std::vector<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "urlChain"))),
|
|
81
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "negotiatedProtocol"))),
|
|
82
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "proxyServer"))),
|
|
83
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "receivedByteCount"))),
|
|
84
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "wasCached")))
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrofetch::UrlResponseInfo& arg) {
|
|
88
|
+
jsi::Object obj(runtime);
|
|
89
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "url"), JSIConverter<std::string>::toJSI(runtime, arg.url));
|
|
90
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "httpStatusCode"), JSIConverter<double>::toJSI(runtime, arg.httpStatusCode));
|
|
91
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "httpStatusText"), JSIConverter<std::string>::toJSI(runtime, arg.httpStatusText));
|
|
92
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "allHeaders"), JSIConverter<std::unordered_map<std::string, std::string>>::toJSI(runtime, arg.allHeaders));
|
|
93
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "allHeadersAsList"), JSIConverter<std::vector<margelo::nitro::nitrofetch::HttpHeader>>::toJSI(runtime, arg.allHeadersAsList));
|
|
94
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "urlChain"), JSIConverter<std::vector<std::string>>::toJSI(runtime, arg.urlChain));
|
|
95
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "negotiatedProtocol"), JSIConverter<std::string>::toJSI(runtime, arg.negotiatedProtocol));
|
|
96
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "proxyServer"), JSIConverter<std::string>::toJSI(runtime, arg.proxyServer));
|
|
97
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "receivedByteCount"), JSIConverter<double>::toJSI(runtime, arg.receivedByteCount));
|
|
98
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "wasCached"), JSIConverter<bool>::toJSI(runtime, arg.wasCached));
|
|
99
|
+
return obj;
|
|
100
|
+
}
|
|
101
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
102
|
+
if (!value.isObject()) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
jsi::Object obj = value.getObject(runtime);
|
|
106
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "url")))) return false;
|
|
110
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "httpStatusCode")))) return false;
|
|
111
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "httpStatusText")))) return false;
|
|
112
|
+
if (!JSIConverter<std::unordered_map<std::string, std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "allHeaders")))) return false;
|
|
113
|
+
if (!JSIConverter<std::vector<margelo::nitro::nitrofetch::HttpHeader>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "allHeadersAsList")))) return false;
|
|
114
|
+
if (!JSIConverter<std::vector<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "urlChain")))) return false;
|
|
115
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "negotiatedProtocol")))) return false;
|
|
116
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "proxyServer")))) return false;
|
|
117
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "receivedByteCount")))) return false;
|
|
118
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "wasCached")))) return false;
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
} // namespace margelo::nitro
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-fetch",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Awesome Fetch :)",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
@@ -69,23 +69,23 @@
|
|
|
69
69
|
"@eslint/eslintrc": "^3.3.0",
|
|
70
70
|
"@eslint/js": "^9.22.0",
|
|
71
71
|
"@evilmartians/lefthook": "^1.5.0",
|
|
72
|
-
"@react-native/babel-preset": "0.
|
|
73
|
-
"@react-native/eslint-config": "^0.
|
|
72
|
+
"@react-native/babel-preset": "0.85.0-rc.0",
|
|
73
|
+
"@react-native/eslint-config": "^0.85.0-rc.0",
|
|
74
74
|
"@release-it/conventional-changelog": "^9.0.2",
|
|
75
75
|
"@types/jest": "^29.5.5",
|
|
76
|
-
"@types/react": "^19.
|
|
76
|
+
"@types/react": "^19.2.0",
|
|
77
77
|
"commitlint": "^19.6.1",
|
|
78
78
|
"del-cli": "^5.1.0",
|
|
79
79
|
"eslint": "^9.22.0",
|
|
80
80
|
"eslint-config-prettier": "^10.1.1",
|
|
81
81
|
"eslint-plugin-prettier": "^5.2.3",
|
|
82
82
|
"jest": "^29.7.0",
|
|
83
|
-
"nitrogen": "^0.
|
|
83
|
+
"nitrogen": "^0.35.2",
|
|
84
84
|
"prettier": "^3.0.3",
|
|
85
|
-
"react": "19.
|
|
86
|
-
"react-native": "0.
|
|
85
|
+
"react": "19.2.3",
|
|
86
|
+
"react-native": "0.85.0-rc.0",
|
|
87
87
|
"react-native-builder-bob": "^0.40.13",
|
|
88
|
-
"react-native-nitro-modules": "^0.
|
|
88
|
+
"react-native-nitro-modules": "^0.35.2",
|
|
89
89
|
"release-it": "^17.10.0",
|
|
90
90
|
"turbo": "^1.10.7",
|
|
91
91
|
"typescript": "^5.8.3"
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"react": "*",
|
|
95
95
|
"react-native": "*",
|
|
96
|
-
"react-native-nitro-modules": "^0.
|
|
96
|
+
"react-native-nitro-modules": "^0.35.2",
|
|
97
97
|
"react-native-worklets-core": "^1.6.0"
|
|
98
98
|
},
|
|
99
99
|
"peerDependenciesMeta": {
|
|
@@ -101,6 +101,9 @@
|
|
|
101
101
|
"optional": true
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
|
+
"dependencies": {
|
|
105
|
+
"web-streams-polyfill": "^4.2.0"
|
|
106
|
+
},
|
|
104
107
|
"workspaces": [
|
|
105
108
|
"example"
|
|
106
109
|
],
|
|
@@ -118,7 +121,7 @@
|
|
|
118
121
|
"publish": true
|
|
119
122
|
},
|
|
120
123
|
"github": {
|
|
121
|
-
"release":
|
|
124
|
+
"release": true
|
|
122
125
|
}
|
|
123
126
|
},
|
|
124
127
|
"prettier": {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
|
|
3
|
+
export interface HttpHeader {
|
|
4
|
+
key: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface UrlResponseInfo {
|
|
9
|
+
url: string;
|
|
10
|
+
httpStatusCode: number;
|
|
11
|
+
httpStatusText: string;
|
|
12
|
+
allHeaders: Record<string, string>;
|
|
13
|
+
allHeadersAsList: HttpHeader[];
|
|
14
|
+
urlChain: string[];
|
|
15
|
+
negotiatedProtocol: string;
|
|
16
|
+
proxyServer: string;
|
|
17
|
+
receivedByteCount: number;
|
|
18
|
+
wasCached: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface RequestException {
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface UrlRequest extends HybridObject<{
|
|
26
|
+
android: 'kotlin';
|
|
27
|
+
ios: 'swift';
|
|
28
|
+
}> {
|
|
29
|
+
start(): void;
|
|
30
|
+
followRedirect(): void;
|
|
31
|
+
read(): void;
|
|
32
|
+
cancel(): void;
|
|
33
|
+
isDone(): boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface UrlRequestBuilder extends HybridObject<{
|
|
37
|
+
android: 'kotlin';
|
|
38
|
+
ios: 'swift';
|
|
39
|
+
}> {
|
|
40
|
+
setHttpMethod(httpMethod: string): void;
|
|
41
|
+
addHeader(name: string, value: string): void;
|
|
42
|
+
setUploadBody(body: ArrayBuffer | string): void;
|
|
43
|
+
disableCache(): void;
|
|
44
|
+
onSucceeded(callback: (info: UrlResponseInfo) => void): void;
|
|
45
|
+
onFailed(
|
|
46
|
+
callback: (
|
|
47
|
+
info: UrlResponseInfo | undefined,
|
|
48
|
+
error: RequestException
|
|
49
|
+
) => void
|
|
50
|
+
): void;
|
|
51
|
+
onCanceled(callback: (info: UrlResponseInfo | undefined) => void): void;
|
|
52
|
+
onRedirectReceived(
|
|
53
|
+
callback: (info: UrlResponseInfo, newLocationUrl: string) => void
|
|
54
|
+
): void;
|
|
55
|
+
onResponseStarted(callback: (info: UrlResponseInfo) => void): void;
|
|
56
|
+
onReadCompleted(
|
|
57
|
+
callback: (
|
|
58
|
+
info: UrlResponseInfo,
|
|
59
|
+
byteBuffer: ArrayBuffer,
|
|
60
|
+
bytesRead: number
|
|
61
|
+
) => void
|
|
62
|
+
): void;
|
|
63
|
+
build(): UrlRequest;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The new streaming client — separate from NitroFetchClient
|
|
67
|
+
export interface NitroCronet extends HybridObject<{
|
|
68
|
+
android: 'kotlin';
|
|
69
|
+
ios: 'swift';
|
|
70
|
+
}> {
|
|
71
|
+
newUrlRequestBuilder(url: string): UrlRequestBuilder;
|
|
72
|
+
}
|
package/src/NitroFetch.nitro.ts
CHANGED
|
@@ -14,6 +14,15 @@ export interface NitroHeader {
|
|
|
14
14
|
key: string;
|
|
15
15
|
value: string;
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
export interface NitroFormDataPart {
|
|
19
|
+
name: string;
|
|
20
|
+
value?: string;
|
|
21
|
+
fileUri?: string;
|
|
22
|
+
fileName?: string;
|
|
23
|
+
mimeType?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
17
26
|
export interface NitroRequest {
|
|
18
27
|
url: string;
|
|
19
28
|
method?: NitroRequestMethod;
|
|
@@ -22,9 +31,13 @@ export interface NitroRequest {
|
|
|
22
31
|
// Body as either UTF-8 string or raw bytes.
|
|
23
32
|
bodyString?: string;
|
|
24
33
|
bodyBytes?: string; //will be ArrayBuffer in future
|
|
34
|
+
// Multipart form data parts (for file uploads)
|
|
35
|
+
bodyFormData?: NitroFormDataPart[];
|
|
25
36
|
// Controls
|
|
26
37
|
timeoutMs?: number;
|
|
27
38
|
followRedirects?: boolean; // default true
|
|
39
|
+
// Optional ID used for cancellation via cancelRequest()
|
|
40
|
+
requestId?: string;
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
export interface NitroResponse {
|
|
@@ -39,8 +52,10 @@ export interface NitroResponse {
|
|
|
39
52
|
bodyBytes?: string; //will be ArrayBuffer in future
|
|
40
53
|
}
|
|
41
54
|
|
|
42
|
-
export interface NitroFetchClient
|
|
43
|
-
|
|
55
|
+
export interface NitroFetchClient extends HybridObject<{
|
|
56
|
+
ios: 'swift';
|
|
57
|
+
android: 'kotlin';
|
|
58
|
+
}> {
|
|
44
59
|
// Client-binded request that uses the env configured at creation.
|
|
45
60
|
request(req: NitroRequest): Promise<NitroResponse>;
|
|
46
61
|
// Start a prefetch for a given request; expects a header `prefetchKey`.
|
|
@@ -48,10 +63,15 @@ export interface NitroFetchClient
|
|
|
48
63
|
|
|
49
64
|
// Synchronous version of request for worklets
|
|
50
65
|
requestSync(req: NitroRequest): NitroResponse;
|
|
66
|
+
|
|
67
|
+
// Cancel an in-flight request by its requestId
|
|
68
|
+
cancelRequest(requestId: string): void;
|
|
51
69
|
}
|
|
52
70
|
|
|
53
|
-
export interface NitroFetch
|
|
54
|
-
|
|
71
|
+
export interface NitroFetch extends HybridObject<{
|
|
72
|
+
ios: 'swift';
|
|
73
|
+
android: 'kotlin';
|
|
74
|
+
}> {
|
|
55
75
|
// Create a client bound to a given environment (e.g., cache dir).
|
|
56
76
|
createClient(): NitroFetchClient;
|
|
57
77
|
|
|
@@ -59,8 +79,10 @@ export interface NitroFetch
|
|
|
59
79
|
// shutdown(): void;
|
|
60
80
|
}
|
|
61
81
|
|
|
62
|
-
export interface NativeStorage
|
|
63
|
-
|
|
82
|
+
export interface NativeStorage extends HybridObject<{
|
|
83
|
+
ios: 'swift';
|
|
84
|
+
android: 'kotlin';
|
|
85
|
+
}> {
|
|
64
86
|
getString(key: string): string;
|
|
65
87
|
setString(key: string, value: string): void;
|
|
66
88
|
removeString(key: string): void;
|
package/src/NitroInstances.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
NitroFetch as NitroFetchType,
|
|
4
4
|
NativeStorage as NativeStorageType,
|
|
5
5
|
} from './NitroFetch.nitro';
|
|
6
|
+
import type { NitroCronet } from './NitroCronet.nitro';
|
|
6
7
|
|
|
7
8
|
// Create singletons once per JS runtime
|
|
8
9
|
export const NitroFetch: NitroFetchType =
|
|
@@ -12,3 +13,6 @@ export const NativeStorage: NativeStorageType =
|
|
|
12
13
|
NitroModules.createHybridObject<NativeStorageType>('NativeStorage');
|
|
13
14
|
|
|
14
15
|
export const boxedNitroFetch = NitroModules.box(NitroFetch);
|
|
16
|
+
|
|
17
|
+
export const NitroCronetSingleton =
|
|
18
|
+
NitroModules.createHybridObject<NitroCronet>('NitroCronet');
|