react-native-nitro-fetch 0.1.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/LICENSE +20 -0
- package/NitroFetch.podspec +30 -0
- package/README.md +134 -0
- package/android/CMakeLists.txt +70 -0
- package/android/build.gradle +131 -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 +91 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/FetchCache.kt +48 -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 +256 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroFetchPackage.kt +22 -0
- package/ios/FetchCache.swift +56 -0
- package/ios/NitroAutoPrefetcher.swift +81 -0
- package/ios/NitroBootstrap.mm +27 -0
- package/ios/NitroFetch.swift +9 -0
- package/ios/NitroFetchClient.swift +205 -0
- package/lib/module/NitroFetch.nitro.js +7 -0
- package/lib/module/NitroFetch.nitro.js.map +1 -0
- package/lib/module/NitroInstances.js +6 -0
- package/lib/module/NitroInstances.js.map +1 -0
- package/lib/module/fetch.js +441 -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/typescript/package.json +1 -0
- package/lib/typescript/src/NitroFetch.nitro.d.ts +39 -0
- package/lib/typescript/src/NitroFetch.nitro.d.ts.map +1 -0
- package/lib/typescript/src/NitroInstances.d.ts +3 -0
- package/lib/typescript/src/NitroInstances.d.ts.map +1 -0
- package/lib/typescript/src/fetch.d.ts +26 -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/nitro.json +21 -0
- package/nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.cpp +96 -0
- package/nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.hpp +65 -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 +103 -0
- package/nitrogen/generated/android/c++/JNitroRequestMethod.hpp +74 -0
- package/nitrogen/generated/android/c++/JNitroResponse.hpp +105 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNitroFetchClientSpec.kt +56 -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 +80 -0
- package/nitrogen/generated/android/nitrofetch+autolinking.gradle +27 -0
- package/nitrogen/generated/android/nitrofetchOnLoad.cpp +54 -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 +73 -0
- package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.hpp +298 -0
- package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Umbrella.hpp +67 -0
- package/nitrogen/generated/ios/NitroFetchAutolinking.mm +41 -0
- package/nitrogen/generated/ios/NitroFetchAutolinking.swift +40 -0
- package/nitrogen/generated/ios/c++/HybridNitroFetchClientSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroFetchClientSpecSwift.hpp +101 -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/HybridNitroFetchClientSpec.swift +50 -0
- package/nitrogen/generated/ios/swift/HybridNitroFetchClientSpec_cxx.swift +149 -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 +199 -0
- package/nitrogen/generated/ios/swift/NitroRequestMethod.swift +60 -0
- package/nitrogen/generated/ios/swift/NitroResponse.swift +155 -0
- package/nitrogen/generated/shared/c++/HybridNitroFetchClientSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridNitroFetchClientSpec.hpp +68 -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 +101 -0
- package/nitrogen/generated/shared/c++/NitroRequestMethod.hpp +96 -0
- package/nitrogen/generated/shared/c++/NitroResponse.hpp +102 -0
- package/package.json +177 -0
- package/src/NitroFetch.nitro.ts +57 -0
- package/src/NitroInstances.ts +8 -0
- package/src/fetch.ts +426 -0
- package/src/index.tsx +17 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridNitroFetchClientSpec.cpp
|
|
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
|
+
#include "JHybridNitroFetchClientSpec.hpp"
|
|
9
|
+
|
|
10
|
+
// Forward declaration of `NitroResponse` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::nitrofetch { struct NitroResponse; }
|
|
12
|
+
// Forward declaration of `NitroHeader` to properly resolve imports.
|
|
13
|
+
namespace margelo::nitro::nitrofetch { struct NitroHeader; }
|
|
14
|
+
// Forward declaration of `ArrayBuffer` to properly resolve imports.
|
|
15
|
+
namespace NitroModules { class ArrayBuffer; }
|
|
16
|
+
// Forward declaration of `NitroRequest` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::nitrofetch { struct NitroRequest; }
|
|
18
|
+
// Forward declaration of `NitroRequestMethod` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::nitrofetch { enum class NitroRequestMethod; }
|
|
20
|
+
|
|
21
|
+
#include "NitroResponse.hpp"
|
|
22
|
+
#include <NitroModules/Promise.hpp>
|
|
23
|
+
#include <NitroModules/JPromise.hpp>
|
|
24
|
+
#include "JNitroResponse.hpp"
|
|
25
|
+
#include <string>
|
|
26
|
+
#include "NitroHeader.hpp"
|
|
27
|
+
#include <vector>
|
|
28
|
+
#include "JNitroHeader.hpp"
|
|
29
|
+
#include <optional>
|
|
30
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
31
|
+
#include <NitroModules/JArrayBuffer.hpp>
|
|
32
|
+
#include <NitroModules/JUnit.hpp>
|
|
33
|
+
#include "NitroRequest.hpp"
|
|
34
|
+
#include "JNitroRequest.hpp"
|
|
35
|
+
#include "NitroRequestMethod.hpp"
|
|
36
|
+
#include "JNitroRequestMethod.hpp"
|
|
37
|
+
|
|
38
|
+
namespace margelo::nitro::nitrofetch {
|
|
39
|
+
|
|
40
|
+
jni::local_ref<JHybridNitroFetchClientSpec::jhybriddata> JHybridNitroFetchClientSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
41
|
+
return makeCxxInstance(jThis);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void JHybridNitroFetchClientSpec::registerNatives() {
|
|
45
|
+
registerHybrid({
|
|
46
|
+
makeNativeMethod("initHybrid", JHybridNitroFetchClientSpec::initHybrid),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
size_t JHybridNitroFetchClientSpec::getExternalMemorySize() noexcept {
|
|
51
|
+
static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
|
|
52
|
+
return method(_javaPart);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
void JHybridNitroFetchClientSpec::dispose() noexcept {
|
|
56
|
+
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
57
|
+
method(_javaPart);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Properties
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
// Methods
|
|
64
|
+
std::shared_ptr<Promise<NitroResponse>> JHybridNitroFetchClientSpec::request(const NitroRequest& req) {
|
|
65
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JNitroRequest> /* req */)>("request");
|
|
66
|
+
auto __result = method(_javaPart, JNitroRequest::fromCpp(req));
|
|
67
|
+
return [&]() {
|
|
68
|
+
auto __promise = Promise<NitroResponse>::create();
|
|
69
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
70
|
+
auto __result = jni::static_ref_cast<JNitroResponse>(__boxedResult);
|
|
71
|
+
__promise->resolve(__result->toCpp());
|
|
72
|
+
});
|
|
73
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
74
|
+
jni::JniException __jniError(__throwable);
|
|
75
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
76
|
+
});
|
|
77
|
+
return __promise;
|
|
78
|
+
}();
|
|
79
|
+
}
|
|
80
|
+
std::shared_ptr<Promise<void>> JHybridNitroFetchClientSpec::prefetch(const NitroRequest& req) {
|
|
81
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JNitroRequest> /* req */)>("prefetch");
|
|
82
|
+
auto __result = method(_javaPart, JNitroRequest::fromCpp(req));
|
|
83
|
+
return [&]() {
|
|
84
|
+
auto __promise = Promise<void>::create();
|
|
85
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
|
|
86
|
+
__promise->resolve();
|
|
87
|
+
});
|
|
88
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
89
|
+
jni::JniException __jniError(__throwable);
|
|
90
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
91
|
+
});
|
|
92
|
+
return __promise;
|
|
93
|
+
}();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
} // namespace margelo::nitro::nitrofetch
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroFetchClientSpec.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
|
+
#include <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridNitroFetchClientSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::nitrofetch {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridNitroFetchClientSpec: public jni::HybridClass<JHybridNitroFetchClientSpec, JHybridObject>,
|
|
22
|
+
public virtual HybridNitroFetchClientSpec {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrofetch/HybridNitroFetchClientSpec;";
|
|
25
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
26
|
+
static void registerNatives();
|
|
27
|
+
|
|
28
|
+
protected:
|
|
29
|
+
// C++ constructor (called from Java via `initHybrid()`)
|
|
30
|
+
explicit JHybridNitroFetchClientSpec(jni::alias_ref<jhybridobject> jThis) :
|
|
31
|
+
HybridObject(HybridNitroFetchClientSpec::TAG),
|
|
32
|
+
HybridBase(jThis),
|
|
33
|
+
_javaPart(jni::make_global(jThis)) {}
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
~JHybridNitroFetchClientSpec() override {
|
|
37
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
38
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public:
|
|
42
|
+
size_t getExternalMemorySize() noexcept override;
|
|
43
|
+
void dispose() noexcept override;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
inline const jni::global_ref<JHybridNitroFetchClientSpec::javaobject>& getJavaPart() const noexcept {
|
|
47
|
+
return _javaPart;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
// Properties
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
// Methods
|
|
56
|
+
std::shared_ptr<Promise<NitroResponse>> request(const NitroRequest& req) override;
|
|
57
|
+
std::shared_ptr<Promise<void>> prefetch(const NitroRequest& req) override;
|
|
58
|
+
|
|
59
|
+
private:
|
|
60
|
+
friend HybridBase;
|
|
61
|
+
using HybridBase::HybridBase;
|
|
62
|
+
jni::global_ref<JHybridNitroFetchClientSpec::javaobject> _javaPart;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace margelo::nitro::nitrofetch
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridNitroFetchSpec.cpp
|
|
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
|
+
#include "JHybridNitroFetchSpec.hpp"
|
|
9
|
+
|
|
10
|
+
// Forward declaration of `HybridNitroFetchClientSpec` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::nitrofetch { class HybridNitroFetchClientSpec; }
|
|
12
|
+
|
|
13
|
+
#include <memory>
|
|
14
|
+
#include "HybridNitroFetchClientSpec.hpp"
|
|
15
|
+
#include "JHybridNitroFetchClientSpec.hpp"
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::nitrofetch {
|
|
18
|
+
|
|
19
|
+
jni::local_ref<JHybridNitroFetchSpec::jhybriddata> JHybridNitroFetchSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
20
|
+
return makeCxxInstance(jThis);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void JHybridNitroFetchSpec::registerNatives() {
|
|
24
|
+
registerHybrid({
|
|
25
|
+
makeNativeMethod("initHybrid", JHybridNitroFetchSpec::initHybrid),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
size_t JHybridNitroFetchSpec::getExternalMemorySize() noexcept {
|
|
30
|
+
static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
|
|
31
|
+
return method(_javaPart);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void JHybridNitroFetchSpec::dispose() noexcept {
|
|
35
|
+
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
36
|
+
method(_javaPart);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Properties
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// Methods
|
|
43
|
+
std::shared_ptr<HybridNitroFetchClientSpec> JHybridNitroFetchSpec::createClient() {
|
|
44
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JHybridNitroFetchClientSpec::javaobject>()>("createClient");
|
|
45
|
+
auto __result = method(_javaPart);
|
|
46
|
+
return __result->cthis()->shared_cast<JHybridNitroFetchClientSpec>();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
} // namespace margelo::nitro::nitrofetch
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroFetchSpec.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
|
+
#include <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridNitroFetchSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::nitrofetch {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridNitroFetchSpec: public jni::HybridClass<JHybridNitroFetchSpec, JHybridObject>,
|
|
22
|
+
public virtual HybridNitroFetchSpec {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrofetch/HybridNitroFetchSpec;";
|
|
25
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
26
|
+
static void registerNatives();
|
|
27
|
+
|
|
28
|
+
protected:
|
|
29
|
+
// C++ constructor (called from Java via `initHybrid()`)
|
|
30
|
+
explicit JHybridNitroFetchSpec(jni::alias_ref<jhybridobject> jThis) :
|
|
31
|
+
HybridObject(HybridNitroFetchSpec::TAG),
|
|
32
|
+
HybridBase(jThis),
|
|
33
|
+
_javaPart(jni::make_global(jThis)) {}
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
~JHybridNitroFetchSpec() override {
|
|
37
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
38
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public:
|
|
42
|
+
size_t getExternalMemorySize() noexcept override;
|
|
43
|
+
void dispose() noexcept override;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
inline const jni::global_ref<JHybridNitroFetchSpec::javaobject>& getJavaPart() const noexcept {
|
|
47
|
+
return _javaPart;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
// Properties
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
// Methods
|
|
56
|
+
std::shared_ptr<HybridNitroFetchClientSpec> createClient() override;
|
|
57
|
+
|
|
58
|
+
private:
|
|
59
|
+
friend HybridBase;
|
|
60
|
+
using HybridBase::HybridBase;
|
|
61
|
+
jni::global_ref<JHybridNitroFetchSpec::javaobject> _javaPart;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
} // namespace margelo::nitro::nitrofetch
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JNitroHeader.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
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "NitroHeader.hpp"
|
|
12
|
+
|
|
13
|
+
#include <string>
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::nitrofetch {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The C++ JNI bridge between the C++ struct "NitroHeader" and the the Kotlin data class "NitroHeader".
|
|
21
|
+
*/
|
|
22
|
+
struct JNitroHeader final: public jni::JavaClass<JNitroHeader> {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrofetch/NitroHeader;";
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
/**
|
|
28
|
+
* Convert this Java/Kotlin-based struct to the C++ struct NitroHeader by copying all values to C++.
|
|
29
|
+
*/
|
|
30
|
+
[[maybe_unused]]
|
|
31
|
+
[[nodiscard]]
|
|
32
|
+
NitroHeader toCpp() const {
|
|
33
|
+
static const auto clazz = javaClassStatic();
|
|
34
|
+
static const auto fieldKey = clazz->getField<jni::JString>("key");
|
|
35
|
+
jni::local_ref<jni::JString> key = this->getFieldValue(fieldKey);
|
|
36
|
+
static const auto fieldValue = clazz->getField<jni::JString>("value");
|
|
37
|
+
jni::local_ref<jni::JString> value = this->getFieldValue(fieldValue);
|
|
38
|
+
return NitroHeader(
|
|
39
|
+
key->toStdString(),
|
|
40
|
+
value->toStdString()
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public:
|
|
45
|
+
/**
|
|
46
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
47
|
+
*/
|
|
48
|
+
[[maybe_unused]]
|
|
49
|
+
static jni::local_ref<JNitroHeader::javaobject> fromCpp(const NitroHeader& value) {
|
|
50
|
+
return newInstance(
|
|
51
|
+
jni::make_jstring(value.key),
|
|
52
|
+
jni::make_jstring(value.value)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
} // namespace margelo::nitro::nitrofetch
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JNitroRequest.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
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "NitroRequest.hpp"
|
|
12
|
+
|
|
13
|
+
#include "JNitroHeader.hpp"
|
|
14
|
+
#include "JNitroRequestMethod.hpp"
|
|
15
|
+
#include "NitroHeader.hpp"
|
|
16
|
+
#include "NitroRequestMethod.hpp"
|
|
17
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
18
|
+
#include <NitroModules/JArrayBuffer.hpp>
|
|
19
|
+
#include <NitroModules/JUnit.hpp>
|
|
20
|
+
#include <optional>
|
|
21
|
+
#include <string>
|
|
22
|
+
#include <vector>
|
|
23
|
+
|
|
24
|
+
namespace margelo::nitro::nitrofetch {
|
|
25
|
+
|
|
26
|
+
using namespace facebook;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The C++ JNI bridge between the C++ struct "NitroRequest" and the the Kotlin data class "NitroRequest".
|
|
30
|
+
*/
|
|
31
|
+
struct JNitroRequest final: public jni::JavaClass<JNitroRequest> {
|
|
32
|
+
public:
|
|
33
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrofetch/NitroRequest;";
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
/**
|
|
37
|
+
* Convert this Java/Kotlin-based struct to the C++ struct NitroRequest by copying all values to C++.
|
|
38
|
+
*/
|
|
39
|
+
[[maybe_unused]]
|
|
40
|
+
[[nodiscard]]
|
|
41
|
+
NitroRequest toCpp() const {
|
|
42
|
+
static const auto clazz = javaClassStatic();
|
|
43
|
+
static const auto fieldUrl = clazz->getField<jni::JString>("url");
|
|
44
|
+
jni::local_ref<jni::JString> url = this->getFieldValue(fieldUrl);
|
|
45
|
+
static const auto fieldMethod = clazz->getField<JNitroRequestMethod>("method");
|
|
46
|
+
jni::local_ref<JNitroRequestMethod> method = this->getFieldValue(fieldMethod);
|
|
47
|
+
static const auto fieldHeaders = clazz->getField<jni::JArrayClass<JNitroHeader>>("headers");
|
|
48
|
+
jni::local_ref<jni::JArrayClass<JNitroHeader>> headers = this->getFieldValue(fieldHeaders);
|
|
49
|
+
static const auto fieldBodyString = clazz->getField<jni::JString>("bodyString");
|
|
50
|
+
jni::local_ref<jni::JString> bodyString = this->getFieldValue(fieldBodyString);
|
|
51
|
+
static const auto fieldBodyBytes = clazz->getField<JArrayBuffer::javaobject>("bodyBytes");
|
|
52
|
+
jni::local_ref<JArrayBuffer::javaobject> bodyBytes = this->getFieldValue(fieldBodyBytes);
|
|
53
|
+
static const auto fieldTimeoutMs = clazz->getField<jni::JDouble>("timeoutMs");
|
|
54
|
+
jni::local_ref<jni::JDouble> timeoutMs = this->getFieldValue(fieldTimeoutMs);
|
|
55
|
+
static const auto fieldFollowRedirects = clazz->getField<jni::JBoolean>("followRedirects");
|
|
56
|
+
jni::local_ref<jni::JBoolean> followRedirects = this->getFieldValue(fieldFollowRedirects);
|
|
57
|
+
return NitroRequest(
|
|
58
|
+
url->toStdString(),
|
|
59
|
+
method != nullptr ? std::make_optional(method->toCpp()) : std::nullopt,
|
|
60
|
+
headers != nullptr ? std::make_optional([&]() {
|
|
61
|
+
size_t __size = headers->size();
|
|
62
|
+
std::vector<NitroHeader> __vector;
|
|
63
|
+
__vector.reserve(__size);
|
|
64
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
65
|
+
auto __element = headers->getElement(__i);
|
|
66
|
+
__vector.push_back(__element->toCpp());
|
|
67
|
+
}
|
|
68
|
+
return __vector;
|
|
69
|
+
}()) : std::nullopt,
|
|
70
|
+
bodyString != nullptr ? std::make_optional(bodyString->toStdString()) : std::nullopt,
|
|
71
|
+
bodyBytes != nullptr ? std::make_optional(bodyBytes->cthis()->getArrayBuffer()) : std::nullopt,
|
|
72
|
+
timeoutMs != nullptr ? std::make_optional(timeoutMs->value()) : std::nullopt,
|
|
73
|
+
followRedirects != nullptr ? std::make_optional(static_cast<bool>(followRedirects->value())) : std::nullopt
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public:
|
|
78
|
+
/**
|
|
79
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
80
|
+
*/
|
|
81
|
+
[[maybe_unused]]
|
|
82
|
+
static jni::local_ref<JNitroRequest::javaobject> fromCpp(const NitroRequest& value) {
|
|
83
|
+
return newInstance(
|
|
84
|
+
jni::make_jstring(value.url),
|
|
85
|
+
value.method.has_value() ? JNitroRequestMethod::fromCpp(value.method.value()) : nullptr,
|
|
86
|
+
value.headers.has_value() ? [&]() {
|
|
87
|
+
size_t __size = value.headers.value().size();
|
|
88
|
+
jni::local_ref<jni::JArrayClass<JNitroHeader>> __array = jni::JArrayClass<JNitroHeader>::newArray(__size);
|
|
89
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
90
|
+
const auto& __element = value.headers.value()[__i];
|
|
91
|
+
__array->setElement(__i, *JNitroHeader::fromCpp(__element));
|
|
92
|
+
}
|
|
93
|
+
return __array;
|
|
94
|
+
}() : nullptr,
|
|
95
|
+
value.bodyString.has_value() ? jni::make_jstring(value.bodyString.value()) : nullptr,
|
|
96
|
+
value.bodyBytes.has_value() ? JArrayBuffer::wrap(value.bodyBytes.value()) : nullptr,
|
|
97
|
+
value.timeoutMs.has_value() ? jni::JDouble::valueOf(value.timeoutMs.value()) : nullptr,
|
|
98
|
+
value.followRedirects.has_value() ? jni::JBoolean::valueOf(value.followRedirects.value()) : nullptr
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
} // namespace margelo::nitro::nitrofetch
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JNitroRequestMethod.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
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "NitroRequestMethod.hpp"
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::nitrofetch {
|
|
14
|
+
|
|
15
|
+
using namespace facebook;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The C++ JNI bridge between the C++ enum "NitroRequestMethod" and the the Kotlin enum "NitroRequestMethod".
|
|
19
|
+
*/
|
|
20
|
+
struct JNitroRequestMethod final: public jni::JavaClass<JNitroRequestMethod> {
|
|
21
|
+
public:
|
|
22
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrofetch/NitroRequestMethod;";
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
/**
|
|
26
|
+
* Convert this Java/Kotlin-based enum to the C++ enum NitroRequestMethod.
|
|
27
|
+
*/
|
|
28
|
+
[[maybe_unused]]
|
|
29
|
+
[[nodiscard]]
|
|
30
|
+
NitroRequestMethod toCpp() const {
|
|
31
|
+
static const auto clazz = javaClassStatic();
|
|
32
|
+
static const auto fieldOrdinal = clazz->getField<int>("value");
|
|
33
|
+
int ordinal = this->getFieldValue(fieldOrdinal);
|
|
34
|
+
return static_cast<NitroRequestMethod>(ordinal);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public:
|
|
38
|
+
/**
|
|
39
|
+
* Create a Java/Kotlin-based enum with the given C++ enum's value.
|
|
40
|
+
*/
|
|
41
|
+
[[maybe_unused]]
|
|
42
|
+
static jni::alias_ref<JNitroRequestMethod> fromCpp(NitroRequestMethod value) {
|
|
43
|
+
static const auto clazz = javaClassStatic();
|
|
44
|
+
static const auto fieldGET = clazz->getStaticField<JNitroRequestMethod>("GET");
|
|
45
|
+
static const auto fieldHEAD = clazz->getStaticField<JNitroRequestMethod>("HEAD");
|
|
46
|
+
static const auto fieldPOST = clazz->getStaticField<JNitroRequestMethod>("POST");
|
|
47
|
+
static const auto fieldPUT = clazz->getStaticField<JNitroRequestMethod>("PUT");
|
|
48
|
+
static const auto fieldPATCH = clazz->getStaticField<JNitroRequestMethod>("PATCH");
|
|
49
|
+
static const auto fieldDELETE = clazz->getStaticField<JNitroRequestMethod>("DELETE");
|
|
50
|
+
static const auto fieldOPTIONS = clazz->getStaticField<JNitroRequestMethod>("OPTIONS");
|
|
51
|
+
|
|
52
|
+
switch (value) {
|
|
53
|
+
case NitroRequestMethod::GET:
|
|
54
|
+
return clazz->getStaticFieldValue(fieldGET);
|
|
55
|
+
case NitroRequestMethod::HEAD:
|
|
56
|
+
return clazz->getStaticFieldValue(fieldHEAD);
|
|
57
|
+
case NitroRequestMethod::POST:
|
|
58
|
+
return clazz->getStaticFieldValue(fieldPOST);
|
|
59
|
+
case NitroRequestMethod::PUT:
|
|
60
|
+
return clazz->getStaticFieldValue(fieldPUT);
|
|
61
|
+
case NitroRequestMethod::PATCH:
|
|
62
|
+
return clazz->getStaticFieldValue(fieldPATCH);
|
|
63
|
+
case NitroRequestMethod::DELETE:
|
|
64
|
+
return clazz->getStaticFieldValue(fieldDELETE);
|
|
65
|
+
case NitroRequestMethod::OPTIONS:
|
|
66
|
+
return clazz->getStaticFieldValue(fieldOPTIONS);
|
|
67
|
+
default:
|
|
68
|
+
std::string stringValue = std::to_string(static_cast<int>(value));
|
|
69
|
+
throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
} // namespace margelo::nitro::nitrofetch
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JNitroResponse.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
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "NitroResponse.hpp"
|
|
12
|
+
|
|
13
|
+
#include "JNitroHeader.hpp"
|
|
14
|
+
#include "NitroHeader.hpp"
|
|
15
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
16
|
+
#include <NitroModules/JArrayBuffer.hpp>
|
|
17
|
+
#include <NitroModules/JUnit.hpp>
|
|
18
|
+
#include <optional>
|
|
19
|
+
#include <string>
|
|
20
|
+
#include <vector>
|
|
21
|
+
|
|
22
|
+
namespace margelo::nitro::nitrofetch {
|
|
23
|
+
|
|
24
|
+
using namespace facebook;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The C++ JNI bridge between the C++ struct "NitroResponse" and the the Kotlin data class "NitroResponse".
|
|
28
|
+
*/
|
|
29
|
+
struct JNitroResponse final: public jni::JavaClass<JNitroResponse> {
|
|
30
|
+
public:
|
|
31
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrofetch/NitroResponse;";
|
|
32
|
+
|
|
33
|
+
public:
|
|
34
|
+
/**
|
|
35
|
+
* Convert this Java/Kotlin-based struct to the C++ struct NitroResponse by copying all values to C++.
|
|
36
|
+
*/
|
|
37
|
+
[[maybe_unused]]
|
|
38
|
+
[[nodiscard]]
|
|
39
|
+
NitroResponse toCpp() const {
|
|
40
|
+
static const auto clazz = javaClassStatic();
|
|
41
|
+
static const auto fieldUrl = clazz->getField<jni::JString>("url");
|
|
42
|
+
jni::local_ref<jni::JString> url = this->getFieldValue(fieldUrl);
|
|
43
|
+
static const auto fieldStatus = clazz->getField<double>("status");
|
|
44
|
+
double status = this->getFieldValue(fieldStatus);
|
|
45
|
+
static const auto fieldStatusText = clazz->getField<jni::JString>("statusText");
|
|
46
|
+
jni::local_ref<jni::JString> statusText = this->getFieldValue(fieldStatusText);
|
|
47
|
+
static const auto fieldOk = clazz->getField<jboolean>("ok");
|
|
48
|
+
jboolean ok = this->getFieldValue(fieldOk);
|
|
49
|
+
static const auto fieldRedirected = clazz->getField<jboolean>("redirected");
|
|
50
|
+
jboolean redirected = this->getFieldValue(fieldRedirected);
|
|
51
|
+
static const auto fieldHeaders = clazz->getField<jni::JArrayClass<JNitroHeader>>("headers");
|
|
52
|
+
jni::local_ref<jni::JArrayClass<JNitroHeader>> headers = this->getFieldValue(fieldHeaders);
|
|
53
|
+
static const auto fieldBodyString = clazz->getField<jni::JString>("bodyString");
|
|
54
|
+
jni::local_ref<jni::JString> bodyString = this->getFieldValue(fieldBodyString);
|
|
55
|
+
static const auto fieldBodyBytes = clazz->getField<JArrayBuffer::javaobject>("bodyBytes");
|
|
56
|
+
jni::local_ref<JArrayBuffer::javaobject> bodyBytes = this->getFieldValue(fieldBodyBytes);
|
|
57
|
+
return NitroResponse(
|
|
58
|
+
url->toStdString(),
|
|
59
|
+
status,
|
|
60
|
+
statusText->toStdString(),
|
|
61
|
+
static_cast<bool>(ok),
|
|
62
|
+
static_cast<bool>(redirected),
|
|
63
|
+
[&]() {
|
|
64
|
+
size_t __size = headers->size();
|
|
65
|
+
std::vector<NitroHeader> __vector;
|
|
66
|
+
__vector.reserve(__size);
|
|
67
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
68
|
+
auto __element = headers->getElement(__i);
|
|
69
|
+
__vector.push_back(__element->toCpp());
|
|
70
|
+
}
|
|
71
|
+
return __vector;
|
|
72
|
+
}(),
|
|
73
|
+
bodyString != nullptr ? std::make_optional(bodyString->toStdString()) : std::nullopt,
|
|
74
|
+
bodyBytes != nullptr ? std::make_optional(bodyBytes->cthis()->getArrayBuffer()) : std::nullopt
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public:
|
|
79
|
+
/**
|
|
80
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
81
|
+
*/
|
|
82
|
+
[[maybe_unused]]
|
|
83
|
+
static jni::local_ref<JNitroResponse::javaobject> fromCpp(const NitroResponse& value) {
|
|
84
|
+
return newInstance(
|
|
85
|
+
jni::make_jstring(value.url),
|
|
86
|
+
value.status,
|
|
87
|
+
jni::make_jstring(value.statusText),
|
|
88
|
+
value.ok,
|
|
89
|
+
value.redirected,
|
|
90
|
+
[&]() {
|
|
91
|
+
size_t __size = value.headers.size();
|
|
92
|
+
jni::local_ref<jni::JArrayClass<JNitroHeader>> __array = jni::JArrayClass<JNitroHeader>::newArray(__size);
|
|
93
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
94
|
+
const auto& __element = value.headers[__i];
|
|
95
|
+
__array->setElement(__i, *JNitroHeader::fromCpp(__element));
|
|
96
|
+
}
|
|
97
|
+
return __array;
|
|
98
|
+
}(),
|
|
99
|
+
value.bodyString.has_value() ? jni::make_jstring(value.bodyString.value()) : nullptr,
|
|
100
|
+
value.bodyBytes.has_value() ? JArrayBuffer::wrap(value.bodyBytes.value()) : nullptr
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
} // namespace margelo::nitro::nitrofetch
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNitroFetchClientSpec.kt
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroFetchClientSpec.kt
|
|
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
|
+
package com.margelo.nitro.nitrofetch
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.*
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A Kotlin class representing the NitroFetchClient HybridObject.
|
|
17
|
+
* Implement this abstract class to create Kotlin-based instances of NitroFetchClient.
|
|
18
|
+
*/
|
|
19
|
+
@DoNotStrip
|
|
20
|
+
@Keep
|
|
21
|
+
@Suppress(
|
|
22
|
+
"KotlinJniMissingFunction", "unused",
|
|
23
|
+
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
|
24
|
+
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
25
|
+
)
|
|
26
|
+
abstract class HybridNitroFetchClientSpec: HybridObject() {
|
|
27
|
+
@DoNotStrip
|
|
28
|
+
private var mHybridData: HybridData = initHybrid()
|
|
29
|
+
|
|
30
|
+
init {
|
|
31
|
+
super.updateNative(mHybridData)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override fun updateNative(hybridData: HybridData) {
|
|
35
|
+
mHybridData = hybridData
|
|
36
|
+
super.updateNative(hybridData)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Properties
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// Methods
|
|
43
|
+
@DoNotStrip
|
|
44
|
+
@Keep
|
|
45
|
+
abstract fun request(req: NitroRequest): Promise<NitroResponse>
|
|
46
|
+
|
|
47
|
+
@DoNotStrip
|
|
48
|
+
@Keep
|
|
49
|
+
abstract fun prefetch(req: NitroRequest): Promise<Unit>
|
|
50
|
+
|
|
51
|
+
private external fun initHybrid(): HybridData
|
|
52
|
+
|
|
53
|
+
companion object {
|
|
54
|
+
private const val TAG = "HybridNitroFetchClientSpec"
|
|
55
|
+
}
|
|
56
|
+
}
|