@pigeonmal/react-native-nitro-fetch 0.1.6
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/NitroFetch.podspec +30 -0
- package/android/CMakeLists.txt +70 -0
- package/android/build.gradle +130 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/AutoPrefetcher.kt +72 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/FetchCache.kt +58 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NativeStorage.kt +102 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroFetch.kt +94 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroFetchClient.kt +331 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroFetchPackage.kt +22 -0
- package/ios/FetchCache.swift +56 -0
- package/ios/NativeStorage.swift +61 -0
- package/ios/NitroAutoPrefetcher.swift +45 -0
- package/ios/NitroBootstrap.mm +27 -0
- package/ios/NitroFetch.swift +9 -0
- package/ios/NitroFetchClient.swift +230 -0
- package/lib/module/NitroFetch.nitro.js +4 -0
- package/lib/module/NitroFetch.nitro.js.map +1 -0
- package/lib/module/NitroInstances.js +8 -0
- package/lib/module/NitroInstances.js.map +1 -0
- package/lib/module/fetch.js +522 -0
- package/lib/module/fetch.js.map +1 -0
- package/lib/module/index.js +12 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/type.js +2 -0
- package/lib/module/type.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NitroFetch.nitro.d.ts +48 -0
- package/lib/typescript/src/NitroFetch.nitro.d.ts.map +1 -0
- package/lib/typescript/src/NitroInstances.d.ts +5 -0
- package/lib/typescript/src/NitroInstances.d.ts.map +1 -0
- package/lib/typescript/src/fetch.d.ts +28 -0
- package/lib/typescript/src/fetch.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/type.d.ts +4 -0
- package/lib/typescript/src/type.d.ts.map +1 -0
- package/nitro.json +25 -0
- package/nitrogen/generated/android/c++/JHybridNativeStorageSpec.cpp +54 -0
- package/nitrogen/generated/android/c++/JHybridNativeStorageSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.cpp +96 -0
- package/nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JHybridNitroFetchSpec.cpp +49 -0
- package/nitrogen/generated/android/c++/JHybridNitroFetchSpec.hpp +64 -0
- package/nitrogen/generated/android/c++/JNitroHeader.hpp +57 -0
- package/nitrogen/generated/android/c++/JNitroRequest.hpp +100 -0
- package/nitrogen/generated/android/c++/JNitroRequestMethod.hpp +74 -0
- package/nitrogen/generated/android/c++/JNitroResponse.hpp +102 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNativeStorageSpec.kt +60 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNitroFetchClientSpec.kt +60 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNitroFetchSpec.kt +52 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/NitroHeader.kt +32 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/NitroRequest.kt +47 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/NitroRequestMethod.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/NitroResponse.kt +50 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/nitrofetchOnLoad.kt +35 -0
- package/nitrogen/generated/android/nitrofetch+autolinking.cmake +85 -0
- package/nitrogen/generated/android/nitrofetch+autolinking.gradle +27 -0
- package/nitrogen/generated/android/nitrofetchOnLoad.cpp +64 -0
- package/nitrogen/generated/android/nitrofetchOnLoad.hpp +25 -0
- package/nitrogen/generated/ios/NitroFetch+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.cpp +90 -0
- package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.hpp +321 -0
- package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Umbrella.hpp +69 -0
- package/nitrogen/generated/ios/NitroFetchAutolinking.mm +49 -0
- package/nitrogen/generated/ios/NitroFetchAutolinking.swift +55 -0
- package/nitrogen/generated/ios/c++/HybridNativeStorageSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNativeStorageSpecSwift.hpp +85 -0
- package/nitrogen/generated/ios/c++/HybridNitroFetchClientSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroFetchClientSpecSwift.hpp +103 -0
- package/nitrogen/generated/ios/c++/HybridNitroFetchSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroFetchSpecSwift.hpp +75 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_NitroResponse.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridNativeStorageSpec.swift +51 -0
- package/nitrogen/generated/ios/swift/HybridNativeStorageSpec_cxx.swift +145 -0
- package/nitrogen/generated/ios/swift/HybridNitroFetchClientSpec.swift +51 -0
- package/nitrogen/generated/ios/swift/HybridNitroFetchClientSpec_cxx.swift +161 -0
- package/nitrogen/generated/ios/swift/HybridNitroFetchSpec.swift +49 -0
- package/nitrogen/generated/ios/swift/HybridNitroFetchSpec_cxx.swift +126 -0
- package/nitrogen/generated/ios/swift/NitroHeader.swift +46 -0
- package/nitrogen/generated/ios/swift/NitroRequest.swift +206 -0
- package/nitrogen/generated/ios/swift/NitroRequestMethod.swift +60 -0
- package/nitrogen/generated/ios/swift/NitroResponse.swift +162 -0
- package/nitrogen/generated/shared/c++/HybridNativeStorageSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridNativeStorageSpec.hpp +64 -0
- package/nitrogen/generated/shared/c++/HybridNitroFetchClientSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridNitroFetchClientSpec.hpp +69 -0
- package/nitrogen/generated/shared/c++/HybridNitroFetchSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridNitroFetchSpec.hpp +64 -0
- package/nitrogen/generated/shared/c++/NitroHeader.hpp +71 -0
- package/nitrogen/generated/shared/c++/NitroRequest.hpp +98 -0
- package/nitrogen/generated/shared/c++/NitroRequestMethod.hpp +96 -0
- package/nitrogen/generated/shared/c++/NitroResponse.hpp +99 -0
- package/package.json +162 -0
- package/src/NitroFetch.nitro.ts +67 -0
- package/src/NitroInstances.ts +14 -0
- package/src/fetch.ts +603 -0
- package/src/index.tsx +17 -0
- package/src/type.ts +3 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroHeader.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 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
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
#include <string>
|
|
24
|
+
|
|
25
|
+
namespace margelo::nitro::nitrofetch {
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A struct which can be represented as a JavaScript object (NitroHeader).
|
|
29
|
+
*/
|
|
30
|
+
struct NitroHeader {
|
|
31
|
+
public:
|
|
32
|
+
std::string key SWIFT_PRIVATE;
|
|
33
|
+
std::string value SWIFT_PRIVATE;
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
NitroHeader() = default;
|
|
37
|
+
explicit NitroHeader(std::string key, std::string value): key(key), value(value) {}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
} // namespace margelo::nitro::nitrofetch
|
|
41
|
+
|
|
42
|
+
namespace margelo::nitro {
|
|
43
|
+
|
|
44
|
+
// C++ NitroHeader <> JS NitroHeader (object)
|
|
45
|
+
template <>
|
|
46
|
+
struct JSIConverter<margelo::nitro::nitrofetch::NitroHeader> final {
|
|
47
|
+
static inline margelo::nitro::nitrofetch::NitroHeader fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
48
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
49
|
+
return margelo::nitro::nitrofetch::NitroHeader(
|
|
50
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "key")),
|
|
51
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "value"))
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrofetch::NitroHeader& arg) {
|
|
55
|
+
jsi::Object obj(runtime);
|
|
56
|
+
obj.setProperty(runtime, "key", JSIConverter<std::string>::toJSI(runtime, arg.key));
|
|
57
|
+
obj.setProperty(runtime, "value", JSIConverter<std::string>::toJSI(runtime, arg.value));
|
|
58
|
+
return obj;
|
|
59
|
+
}
|
|
60
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
61
|
+
if (!value.isObject()) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
jsi::Object obj = value.getObject(runtime);
|
|
65
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "key"))) return false;
|
|
66
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "value"))) return false;
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroRequest.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 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
|
+
|
|
21
|
+
// Forward declaration of `NitroRequestMethod` to properly resolve imports.
|
|
22
|
+
namespace margelo::nitro::nitrofetch { enum class NitroRequestMethod; }
|
|
23
|
+
// Forward declaration of `NitroHeader` to properly resolve imports.
|
|
24
|
+
namespace margelo::nitro::nitrofetch { struct NitroHeader; }
|
|
25
|
+
|
|
26
|
+
#include <string>
|
|
27
|
+
#include "NitroRequestMethod.hpp"
|
|
28
|
+
#include <optional>
|
|
29
|
+
#include "NitroHeader.hpp"
|
|
30
|
+
#include <vector>
|
|
31
|
+
|
|
32
|
+
namespace margelo::nitro::nitrofetch {
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A struct which can be represented as a JavaScript object (NitroRequest).
|
|
36
|
+
*/
|
|
37
|
+
struct NitroRequest {
|
|
38
|
+
public:
|
|
39
|
+
std::string url SWIFT_PRIVATE;
|
|
40
|
+
std::optional<NitroRequestMethod> method SWIFT_PRIVATE;
|
|
41
|
+
std::optional<std::vector<NitroHeader>> headers SWIFT_PRIVATE;
|
|
42
|
+
std::optional<std::string> bodyString SWIFT_PRIVATE;
|
|
43
|
+
std::optional<std::string> bodyBytes SWIFT_PRIVATE;
|
|
44
|
+
std::optional<double> timeoutMs SWIFT_PRIVATE;
|
|
45
|
+
std::optional<bool> followRedirects SWIFT_PRIVATE;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
NitroRequest() = default;
|
|
49
|
+
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<double> timeoutMs, std::optional<bool> followRedirects): url(url), method(method), headers(headers), bodyString(bodyString), bodyBytes(bodyBytes), timeoutMs(timeoutMs), followRedirects(followRedirects) {}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
} // namespace margelo::nitro::nitrofetch
|
|
53
|
+
|
|
54
|
+
namespace margelo::nitro {
|
|
55
|
+
|
|
56
|
+
// C++ NitroRequest <> JS NitroRequest (object)
|
|
57
|
+
template <>
|
|
58
|
+
struct JSIConverter<margelo::nitro::nitrofetch::NitroRequest> final {
|
|
59
|
+
static inline margelo::nitro::nitrofetch::NitroRequest fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
60
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
61
|
+
return margelo::nitro::nitrofetch::NitroRequest(
|
|
62
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "url")),
|
|
63
|
+
JSIConverter<std::optional<margelo::nitro::nitrofetch::NitroRequestMethod>>::fromJSI(runtime, obj.getProperty(runtime, "method")),
|
|
64
|
+
JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroHeader>>>::fromJSI(runtime, obj.getProperty(runtime, "headers")),
|
|
65
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "bodyString")),
|
|
66
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "bodyBytes")),
|
|
67
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "timeoutMs")),
|
|
68
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "followRedirects"))
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrofetch::NitroRequest& arg) {
|
|
72
|
+
jsi::Object obj(runtime);
|
|
73
|
+
obj.setProperty(runtime, "url", JSIConverter<std::string>::toJSI(runtime, arg.url));
|
|
74
|
+
obj.setProperty(runtime, "method", JSIConverter<std::optional<margelo::nitro::nitrofetch::NitroRequestMethod>>::toJSI(runtime, arg.method));
|
|
75
|
+
obj.setProperty(runtime, "headers", JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroHeader>>>::toJSI(runtime, arg.headers));
|
|
76
|
+
obj.setProperty(runtime, "bodyString", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.bodyString));
|
|
77
|
+
obj.setProperty(runtime, "bodyBytes", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.bodyBytes));
|
|
78
|
+
obj.setProperty(runtime, "timeoutMs", JSIConverter<std::optional<double>>::toJSI(runtime, arg.timeoutMs));
|
|
79
|
+
obj.setProperty(runtime, "followRedirects", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.followRedirects));
|
|
80
|
+
return obj;
|
|
81
|
+
}
|
|
82
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
83
|
+
if (!value.isObject()) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
jsi::Object obj = value.getObject(runtime);
|
|
87
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "url"))) return false;
|
|
88
|
+
if (!JSIConverter<std::optional<margelo::nitro::nitrofetch::NitroRequestMethod>>::canConvert(runtime, obj.getProperty(runtime, "method"))) return false;
|
|
89
|
+
if (!JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroHeader>>>::canConvert(runtime, obj.getProperty(runtime, "headers"))) return false;
|
|
90
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "bodyString"))) return false;
|
|
91
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "bodyBytes"))) return false;
|
|
92
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "timeoutMs"))) return false;
|
|
93
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "followRedirects"))) return false;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroRequestMethod.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::nitrofetch {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (NitroRequestMethod).
|
|
30
|
+
*/
|
|
31
|
+
enum class NitroRequestMethod {
|
|
32
|
+
GET SWIFT_NAME(get) = 0,
|
|
33
|
+
HEAD SWIFT_NAME(head) = 1,
|
|
34
|
+
POST SWIFT_NAME(post) = 2,
|
|
35
|
+
PUT SWIFT_NAME(put) = 3,
|
|
36
|
+
PATCH SWIFT_NAME(patch) = 4,
|
|
37
|
+
DELETE SWIFT_NAME(delete) = 5,
|
|
38
|
+
OPTIONS SWIFT_NAME(options) = 6,
|
|
39
|
+
} CLOSED_ENUM;
|
|
40
|
+
|
|
41
|
+
} // namespace margelo::nitro::nitrofetch
|
|
42
|
+
|
|
43
|
+
namespace margelo::nitro {
|
|
44
|
+
|
|
45
|
+
// C++ NitroRequestMethod <> JS NitroRequestMethod (union)
|
|
46
|
+
template <>
|
|
47
|
+
struct JSIConverter<margelo::nitro::nitrofetch::NitroRequestMethod> final {
|
|
48
|
+
static inline margelo::nitro::nitrofetch::NitroRequestMethod fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
49
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
50
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
51
|
+
case hashString("GET"): return margelo::nitro::nitrofetch::NitroRequestMethod::GET;
|
|
52
|
+
case hashString("HEAD"): return margelo::nitro::nitrofetch::NitroRequestMethod::HEAD;
|
|
53
|
+
case hashString("POST"): return margelo::nitro::nitrofetch::NitroRequestMethod::POST;
|
|
54
|
+
case hashString("PUT"): return margelo::nitro::nitrofetch::NitroRequestMethod::PUT;
|
|
55
|
+
case hashString("PATCH"): return margelo::nitro::nitrofetch::NitroRequestMethod::PATCH;
|
|
56
|
+
case hashString("DELETE"): return margelo::nitro::nitrofetch::NitroRequestMethod::DELETE;
|
|
57
|
+
case hashString("OPTIONS"): return margelo::nitro::nitrofetch::NitroRequestMethod::OPTIONS;
|
|
58
|
+
default: [[unlikely]]
|
|
59
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum NitroRequestMethod - invalid value!");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrofetch::NitroRequestMethod arg) {
|
|
63
|
+
switch (arg) {
|
|
64
|
+
case margelo::nitro::nitrofetch::NitroRequestMethod::GET: return JSIConverter<std::string>::toJSI(runtime, "GET");
|
|
65
|
+
case margelo::nitro::nitrofetch::NitroRequestMethod::HEAD: return JSIConverter<std::string>::toJSI(runtime, "HEAD");
|
|
66
|
+
case margelo::nitro::nitrofetch::NitroRequestMethod::POST: return JSIConverter<std::string>::toJSI(runtime, "POST");
|
|
67
|
+
case margelo::nitro::nitrofetch::NitroRequestMethod::PUT: return JSIConverter<std::string>::toJSI(runtime, "PUT");
|
|
68
|
+
case margelo::nitro::nitrofetch::NitroRequestMethod::PATCH: return JSIConverter<std::string>::toJSI(runtime, "PATCH");
|
|
69
|
+
case margelo::nitro::nitrofetch::NitroRequestMethod::DELETE: return JSIConverter<std::string>::toJSI(runtime, "DELETE");
|
|
70
|
+
case margelo::nitro::nitrofetch::NitroRequestMethod::OPTIONS: return JSIConverter<std::string>::toJSI(runtime, "OPTIONS");
|
|
71
|
+
default: [[unlikely]]
|
|
72
|
+
throw std::invalid_argument("Cannot convert NitroRequestMethod to JS - invalid value: "
|
|
73
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
77
|
+
if (!value.isString()) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
81
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
82
|
+
case hashString("GET"):
|
|
83
|
+
case hashString("HEAD"):
|
|
84
|
+
case hashString("POST"):
|
|
85
|
+
case hashString("PUT"):
|
|
86
|
+
case hashString("PATCH"):
|
|
87
|
+
case hashString("DELETE"):
|
|
88
|
+
case hashString("OPTIONS"):
|
|
89
|
+
return true;
|
|
90
|
+
default:
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroResponse.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 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
|
+
|
|
21
|
+
// Forward declaration of `NitroHeader` to properly resolve imports.
|
|
22
|
+
namespace margelo::nitro::nitrofetch { struct NitroHeader; }
|
|
23
|
+
|
|
24
|
+
#include <string>
|
|
25
|
+
#include "NitroHeader.hpp"
|
|
26
|
+
#include <vector>
|
|
27
|
+
#include <optional>
|
|
28
|
+
|
|
29
|
+
namespace margelo::nitro::nitrofetch {
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A struct which can be represented as a JavaScript object (NitroResponse).
|
|
33
|
+
*/
|
|
34
|
+
struct NitroResponse {
|
|
35
|
+
public:
|
|
36
|
+
std::string url SWIFT_PRIVATE;
|
|
37
|
+
double status SWIFT_PRIVATE;
|
|
38
|
+
std::string statusText SWIFT_PRIVATE;
|
|
39
|
+
bool ok SWIFT_PRIVATE;
|
|
40
|
+
bool redirected SWIFT_PRIVATE;
|
|
41
|
+
std::vector<NitroHeader> headers SWIFT_PRIVATE;
|
|
42
|
+
std::optional<std::string> bodyString SWIFT_PRIVATE;
|
|
43
|
+
std::optional<std::string> bodyBytes SWIFT_PRIVATE;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
NitroResponse() = default;
|
|
47
|
+
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) {}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
} // namespace margelo::nitro::nitrofetch
|
|
51
|
+
|
|
52
|
+
namespace margelo::nitro {
|
|
53
|
+
|
|
54
|
+
// C++ NitroResponse <> JS NitroResponse (object)
|
|
55
|
+
template <>
|
|
56
|
+
struct JSIConverter<margelo::nitro::nitrofetch::NitroResponse> final {
|
|
57
|
+
static inline margelo::nitro::nitrofetch::NitroResponse fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
58
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
59
|
+
return margelo::nitro::nitrofetch::NitroResponse(
|
|
60
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "url")),
|
|
61
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "status")),
|
|
62
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "statusText")),
|
|
63
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "ok")),
|
|
64
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "redirected")),
|
|
65
|
+
JSIConverter<std::vector<margelo::nitro::nitrofetch::NitroHeader>>::fromJSI(runtime, obj.getProperty(runtime, "headers")),
|
|
66
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "bodyString")),
|
|
67
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "bodyBytes"))
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrofetch::NitroResponse& arg) {
|
|
71
|
+
jsi::Object obj(runtime);
|
|
72
|
+
obj.setProperty(runtime, "url", JSIConverter<std::string>::toJSI(runtime, arg.url));
|
|
73
|
+
obj.setProperty(runtime, "status", JSIConverter<double>::toJSI(runtime, arg.status));
|
|
74
|
+
obj.setProperty(runtime, "statusText", JSIConverter<std::string>::toJSI(runtime, arg.statusText));
|
|
75
|
+
obj.setProperty(runtime, "ok", JSIConverter<bool>::toJSI(runtime, arg.ok));
|
|
76
|
+
obj.setProperty(runtime, "redirected", JSIConverter<bool>::toJSI(runtime, arg.redirected));
|
|
77
|
+
obj.setProperty(runtime, "headers", JSIConverter<std::vector<margelo::nitro::nitrofetch::NitroHeader>>::toJSI(runtime, arg.headers));
|
|
78
|
+
obj.setProperty(runtime, "bodyString", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.bodyString));
|
|
79
|
+
obj.setProperty(runtime, "bodyBytes", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.bodyBytes));
|
|
80
|
+
return obj;
|
|
81
|
+
}
|
|
82
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
83
|
+
if (!value.isObject()) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
jsi::Object obj = value.getObject(runtime);
|
|
87
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "url"))) return false;
|
|
88
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "status"))) return false;
|
|
89
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "statusText"))) return false;
|
|
90
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "ok"))) return false;
|
|
91
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "redirected"))) return false;
|
|
92
|
+
if (!JSIConverter<std::vector<margelo::nitro::nitrofetch::NitroHeader>>::canConvert(runtime, obj.getProperty(runtime, "headers"))) return false;
|
|
93
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "bodyString"))) return false;
|
|
94
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "bodyBytes"))) return false;
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
} // namespace margelo::nitro
|
package/package.json
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pigeonmal/react-native-nitro-fetch",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "Awesome Fetch :)",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"module": "./lib/module/index.js",
|
|
7
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
8
|
+
"react-native": "src/index",
|
|
9
|
+
"source": "./src/index",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"source": "./src/index.tsx",
|
|
13
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
14
|
+
"default": "./lib/module/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"src",
|
|
20
|
+
"lib",
|
|
21
|
+
"android",
|
|
22
|
+
"ios",
|
|
23
|
+
"cpp",
|
|
24
|
+
"nitrogen",
|
|
25
|
+
"nitro.json",
|
|
26
|
+
"*.podspec",
|
|
27
|
+
"react-native.config.js",
|
|
28
|
+
"!ios/build",
|
|
29
|
+
"!android/build",
|
|
30
|
+
"!android/gradle",
|
|
31
|
+
"!android/gradlew",
|
|
32
|
+
"!android/gradlew.bat",
|
|
33
|
+
"!android/local.properties",
|
|
34
|
+
"!**/__tests__",
|
|
35
|
+
"!**/__fixtures__",
|
|
36
|
+
"!**/__mocks__",
|
|
37
|
+
"!**/.*"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"test": "jest",
|
|
41
|
+
"typecheck": "tsc",
|
|
42
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
43
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
44
|
+
"prepare": "bob build",
|
|
45
|
+
"nitrogen": "nitrogen",
|
|
46
|
+
"release": "release-it --only-version"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"react-native",
|
|
50
|
+
"ios",
|
|
51
|
+
"android"
|
|
52
|
+
],
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/margelo/react-native-nitro-fetch.git"
|
|
56
|
+
},
|
|
57
|
+
"author": "Szymon Kapala <szymon20000@gmail.com'> (https://x.com/Turbo_Szymon)",
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "https://github.com/margelo/react-native-nitro-fetch/issues"
|
|
61
|
+
},
|
|
62
|
+
"homepage": "https://github.com/margelo/react-native-nitro-fetch#readme",
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"registry": "https://registry.npmjs.org/",
|
|
65
|
+
"access": "public"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@commitlint/config-conventional": "^19.6.0",
|
|
69
|
+
"@eslint/compat": "^1.2.7",
|
|
70
|
+
"@eslint/eslintrc": "^3.3.0",
|
|
71
|
+
"@eslint/js": "^9.22.0",
|
|
72
|
+
"@evilmartians/lefthook": "^1.5.0",
|
|
73
|
+
"@react-native/babel-preset": "0.81.0",
|
|
74
|
+
"@react-native/eslint-config": "^0.78.0",
|
|
75
|
+
"@release-it/conventional-changelog": "^9.0.2",
|
|
76
|
+
"@types/jest": "^29.5.5",
|
|
77
|
+
"@types/react": "^19.1.0",
|
|
78
|
+
"commitlint": "^19.6.1",
|
|
79
|
+
"del-cli": "^5.1.0",
|
|
80
|
+
"eslint": "^9.22.0",
|
|
81
|
+
"eslint-config-prettier": "^10.1.1",
|
|
82
|
+
"eslint-plugin-prettier": "^5.2.3",
|
|
83
|
+
"jest": "^29.7.0",
|
|
84
|
+
"nitrogen": "^0.29.2",
|
|
85
|
+
"prettier": "^3.0.3",
|
|
86
|
+
"react": "19.1.0",
|
|
87
|
+
"react-native": "0.81.0",
|
|
88
|
+
"react-native-builder-bob": "^0.40.13",
|
|
89
|
+
"react-native-nitro-modules": "^0.29.2",
|
|
90
|
+
"release-it": "^17.10.0",
|
|
91
|
+
"turbo": "^1.10.7",
|
|
92
|
+
"typescript": "^5.8.3"
|
|
93
|
+
},
|
|
94
|
+
"peerDependencies": {
|
|
95
|
+
"react": "*",
|
|
96
|
+
"react-native": "*",
|
|
97
|
+
"react-native-nitro-modules": "^0.29.2",
|
|
98
|
+
"react-native-worklets-core": "^1.6.0"
|
|
99
|
+
},
|
|
100
|
+
"peerDependenciesMeta": {
|
|
101
|
+
"react-native-worklets-core": {
|
|
102
|
+
"optional": true
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"workspaces": [
|
|
106
|
+
"example"
|
|
107
|
+
],
|
|
108
|
+
"packageManager": "yarn@3.6.1",
|
|
109
|
+
"jest": {
|
|
110
|
+
"preset": "react-native",
|
|
111
|
+
"modulePathIgnorePatterns": [
|
|
112
|
+
"<rootDir>/example/node_modules",
|
|
113
|
+
"<rootDir>/lib/"
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
"release-it": {
|
|
117
|
+
"git": false,
|
|
118
|
+
"npm": {
|
|
119
|
+
"publish": true
|
|
120
|
+
},
|
|
121
|
+
"github": {
|
|
122
|
+
"release": false
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"prettier": {
|
|
126
|
+
"quoteProps": "consistent",
|
|
127
|
+
"singleQuote": true,
|
|
128
|
+
"tabWidth": 2,
|
|
129
|
+
"trailingComma": "es5",
|
|
130
|
+
"useTabs": false
|
|
131
|
+
},
|
|
132
|
+
"react-native-builder-bob": {
|
|
133
|
+
"source": "src",
|
|
134
|
+
"output": "lib",
|
|
135
|
+
"targets": [
|
|
136
|
+
[
|
|
137
|
+
"custom",
|
|
138
|
+
{
|
|
139
|
+
"script": "nitrogen",
|
|
140
|
+
"clean": "nitrogen/"
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
"module",
|
|
145
|
+
{
|
|
146
|
+
"esm": true
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
[
|
|
150
|
+
"typescript",
|
|
151
|
+
{
|
|
152
|
+
"project": "tsconfig.build.json"
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
"create-react-native-library": {
|
|
158
|
+
"languages": "kotlin-swift",
|
|
159
|
+
"type": "nitro-module",
|
|
160
|
+
"version": "0.53.0"
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
|
|
3
|
+
// Minimal request/response types to model WHATWG fetch without streaming.
|
|
4
|
+
export type NitroRequestMethod =
|
|
5
|
+
| 'GET'
|
|
6
|
+
| 'HEAD'
|
|
7
|
+
| 'POST'
|
|
8
|
+
| 'PUT'
|
|
9
|
+
| 'PATCH'
|
|
10
|
+
| 'DELETE'
|
|
11
|
+
| 'OPTIONS';
|
|
12
|
+
|
|
13
|
+
export interface NitroHeader {
|
|
14
|
+
key: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
17
|
+
export interface NitroRequest {
|
|
18
|
+
url: string;
|
|
19
|
+
method?: NitroRequestMethod;
|
|
20
|
+
// Flattened list to keep bridging simple and deterministic
|
|
21
|
+
headers?: NitroHeader[];
|
|
22
|
+
// Body as either UTF-8 string or raw bytes.
|
|
23
|
+
bodyString?: string;
|
|
24
|
+
bodyBytes?: string; //will be ArrayBuffer in future
|
|
25
|
+
// Controls
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
followRedirects?: boolean; // default true
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface NitroResponse {
|
|
31
|
+
url: string; // final URL after redirects
|
|
32
|
+
status: number;
|
|
33
|
+
statusText: string;
|
|
34
|
+
ok: boolean;
|
|
35
|
+
redirected: boolean;
|
|
36
|
+
headers: NitroHeader[];
|
|
37
|
+
// Body as either UTF-8 string or raw bytes (first implementation target)
|
|
38
|
+
bodyString?: string;
|
|
39
|
+
bodyBytes?: string; //will be ArrayBuffer in future
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface NitroFetchClient
|
|
43
|
+
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
44
|
+
// Client-binded request that uses the env configured at creation.
|
|
45
|
+
request(req: NitroRequest): Promise<NitroResponse>;
|
|
46
|
+
// Start a prefetch for a given request; expects a header `prefetchKey`.
|
|
47
|
+
prefetch(req: NitroRequest): Promise<void>;
|
|
48
|
+
|
|
49
|
+
// Synchronous version of request for worklets
|
|
50
|
+
requestSync(req: NitroRequest): NitroResponse;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface NitroFetch
|
|
54
|
+
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
55
|
+
// Create a client bound to a given environment (e.g., cache dir).
|
|
56
|
+
createClient(): NitroFetchClient;
|
|
57
|
+
|
|
58
|
+
// Optional future: global abort/teardown
|
|
59
|
+
// shutdown(): void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface NativeStorage
|
|
63
|
+
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
64
|
+
getString(key: string): string;
|
|
65
|
+
setString(key: string, value: string): void;
|
|
66
|
+
removeString(key: string): void;
|
|
67
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type {
|
|
3
|
+
NitroFetch as NitroFetchType,
|
|
4
|
+
NativeStorage as NativeStorageType,
|
|
5
|
+
} from './NitroFetch.nitro';
|
|
6
|
+
|
|
7
|
+
// Create singletons once per JS runtime
|
|
8
|
+
export const NitroFetch: NitroFetchType =
|
|
9
|
+
NitroModules.createHybridObject<NitroFetchType>('NitroFetch');
|
|
10
|
+
|
|
11
|
+
export const NativeStorage: NativeStorageType =
|
|
12
|
+
NitroModules.createHybridObject<NativeStorageType>('NativeStorage');
|
|
13
|
+
|
|
14
|
+
export const boxedNitroFetch = NitroModules.box(NitroFetch);
|