@shamilovtim/react-native-nitro-sse 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/NitroSse.podspec +37 -0
  3. package/README.md +144 -0
  4. package/android/CMakeLists.txt +24 -0
  5. package/android/build.gradle +124 -0
  6. package/android/src/main/AndroidManifest.xml +4 -0
  7. package/android/src/main/cpp/cpp-adapter.cpp +10 -0
  8. package/android/src/main/java/com/margelo/nitro/nitrosse/NetworkInspector.kt +94 -0
  9. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +889 -0
  10. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSsePackage.kt +22 -0
  11. package/ios/NitroSse.swift +760 -0
  12. package/ios/NitroSseNetworkInspector.h +24 -0
  13. package/ios/NitroSseNetworkInspector.mm +68 -0
  14. package/lib/module/NitroSse.nitro.js +4 -0
  15. package/lib/module/NitroSse.nitro.js.map +1 -0
  16. package/lib/module/NitroSseClient.js +244 -0
  17. package/lib/module/NitroSseClient.js.map +1 -0
  18. package/lib/module/SseInterface.js +4 -0
  19. package/lib/module/SseInterface.js.map +1 -0
  20. package/lib/module/index.js +26 -0
  21. package/lib/module/index.js.map +1 -0
  22. package/lib/module/package.json +1 -0
  23. package/lib/typescript/package.json +1 -0
  24. package/lib/typescript/src/NitroSse.nitro.d.ts +48 -0
  25. package/lib/typescript/src/NitroSse.nitro.d.ts.map +1 -0
  26. package/lib/typescript/src/NitroSseClient.d.ts +26 -0
  27. package/lib/typescript/src/NitroSseClient.d.ts.map +1 -0
  28. package/lib/typescript/src/SseInterface.d.ts +237 -0
  29. package/lib/typescript/src/SseInterface.d.ts.map +1 -0
  30. package/lib/typescript/src/index.d.ts +11 -0
  31. package/lib/typescript/src/index.d.ts.map +1 -0
  32. package/nitro.json +23 -0
  33. package/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp +138 -0
  34. package/nitrogen/generated/android/c++/JFunc_void_std__vector_SseEvent_.hpp +102 -0
  35. package/nitrogen/generated/android/c++/JHttpMethod.hpp +58 -0
  36. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +134 -0
  37. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.hpp +71 -0
  38. package/nitrogen/generated/android/c++/JSseConfig.hpp +162 -0
  39. package/nitrogen/generated/android/c++/JSseEvent.hpp +90 -0
  40. package/nitrogen/generated/android/c++/JSseEventType.hpp +67 -0
  41. package/nitrogen/generated/android/c++/JSseMockConfig.hpp +101 -0
  42. package/nitrogen/generated/android/c++/JSseMockEvent.hpp +94 -0
  43. package/nitrogen/generated/android/c++/JSseMockMode.hpp +58 -0
  44. package/nitrogen/generated/android/c++/JSseStats.hpp +70 -0
  45. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.kt +80 -0
  46. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/Func_void_std__vector_SseEvent_.kt +80 -0
  47. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/HttpMethod.kt +23 -0
  48. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/HybridNitroSseSpec.kt +91 -0
  49. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +135 -0
  50. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEvent.kt +86 -0
  51. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEventType.kt +26 -0
  52. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockConfig.kt +71 -0
  53. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockEvent.kt +91 -0
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockMode.kt +23 -0
  55. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseStats.kt +66 -0
  56. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/nitrosseOnLoad.kt +35 -0
  57. package/nitrogen/generated/android/nitrosse+autolinking.cmake +81 -0
  58. package/nitrogen/generated/android/nitrosse+autolinking.gradle +27 -0
  59. package/nitrogen/generated/android/nitrosseOnLoad.cpp +58 -0
  60. package/nitrogen/generated/android/nitrosseOnLoad.hpp +34 -0
  61. package/nitrogen/generated/ios/NitroSse+autolinking.rb +62 -0
  62. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.cpp +74 -0
  63. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +415 -0
  64. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +74 -0
  65. package/nitrogen/generated/ios/NitroSseAutolinking.mm +33 -0
  66. package/nitrogen/generated/ios/NitroSseAutolinking.swift +26 -0
  67. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.cpp +11 -0
  68. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +161 -0
  69. package/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.swift +67 -0
  70. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  71. package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___.swift +66 -0
  72. package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__std__string_.swift +54 -0
  73. package/nitrogen/generated/ios/swift/Func_void_std__vector_SseEvent_.swift +46 -0
  74. package/nitrogen/generated/ios/swift/HttpMethod.swift +40 -0
  75. package/nitrogen/generated/ios/swift/HybridNitroSseSpec.swift +63 -0
  76. package/nitrogen/generated/ios/swift/HybridNitroSseSpec_cxx.swift +246 -0
  77. package/nitrogen/generated/ios/swift/SseConfig.swift +346 -0
  78. package/nitrogen/generated/ios/swift/SseEvent.swift +155 -0
  79. package/nitrogen/generated/ios/swift/SseEventType.swift +52 -0
  80. package/nitrogen/generated/ios/swift/SseMockConfig.swift +94 -0
  81. package/nitrogen/generated/ios/swift/SseMockEvent.swift +179 -0
  82. package/nitrogen/generated/ios/swift/SseMockMode.swift +40 -0
  83. package/nitrogen/generated/ios/swift/SseStats.swift +70 -0
  84. package/nitrogen/generated/shared/c++/HttpMethod.hpp +76 -0
  85. package/nitrogen/generated/shared/c++/HybridNitroSseSpec.cpp +29 -0
  86. package/nitrogen/generated/shared/c++/HybridNitroSseSpec.hpp +81 -0
  87. package/nitrogen/generated/shared/c++/SseConfig.hpp +156 -0
  88. package/nitrogen/generated/shared/c++/SseEvent.hpp +115 -0
  89. package/nitrogen/generated/shared/c++/SseEventType.hpp +88 -0
  90. package/nitrogen/generated/shared/c++/SseMockConfig.hpp +105 -0
  91. package/nitrogen/generated/shared/c++/SseMockEvent.hpp +119 -0
  92. package/nitrogen/generated/shared/c++/SseMockMode.hpp +76 -0
  93. package/nitrogen/generated/shared/c++/SseStats.hpp +96 -0
  94. package/package.json +186 -0
  95. package/src/NitroSse.nitro.ts +53 -0
  96. package/src/NitroSseClient.ts +297 -0
  97. package/src/SseInterface.ts +248 -0
  98. package/src/index.ts +31 -0
@@ -0,0 +1,134 @@
1
+ ///
2
+ /// JHybridNitroSseSpec.cpp
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
+ #include "JHybridNitroSseSpec.hpp"
9
+
10
+ // Forward declaration of `SseStats` to properly resolve imports.
11
+ namespace margelo::nitro::nitrosse { struct SseStats; }
12
+ // Forward declaration of `SseConfig` to properly resolve imports.
13
+ namespace margelo::nitro::nitrosse { struct SseConfig; }
14
+ // Forward declaration of `HttpMethod` to properly resolve imports.
15
+ namespace margelo::nitro::nitrosse { enum class HttpMethod; }
16
+ // Forward declaration of `SseMockConfig` to properly resolve imports.
17
+ namespace margelo::nitro::nitrosse { struct SseMockConfig; }
18
+ // Forward declaration of `SseMockMode` to properly resolve imports.
19
+ namespace margelo::nitro::nitrosse { enum class SseMockMode; }
20
+ // Forward declaration of `SseMockEvent` to properly resolve imports.
21
+ namespace margelo::nitro::nitrosse { struct SseMockEvent; }
22
+ // Forward declaration of `SseEventType` to properly resolve imports.
23
+ namespace margelo::nitro::nitrosse { enum class SseEventType; }
24
+ // Forward declaration of `SseEvent` to properly resolve imports.
25
+ namespace margelo::nitro::nitrosse { struct SseEvent; }
26
+
27
+ #include "SseStats.hpp"
28
+ #include "JSseStats.hpp"
29
+ #include <optional>
30
+ #include <string>
31
+ #include "SseConfig.hpp"
32
+ #include "JSseConfig.hpp"
33
+ #include "HttpMethod.hpp"
34
+ #include "JHttpMethod.hpp"
35
+ #include <unordered_map>
36
+ #include <NitroModules/Promise.hpp>
37
+ #include <functional>
38
+ #include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp"
39
+ #include <NitroModules/JNICallable.hpp>
40
+ #include <NitroModules/JPromise.hpp>
41
+ #include "SseMockConfig.hpp"
42
+ #include "JSseMockConfig.hpp"
43
+ #include "SseMockMode.hpp"
44
+ #include "JSseMockMode.hpp"
45
+ #include "SseMockEvent.hpp"
46
+ #include <vector>
47
+ #include "JSseMockEvent.hpp"
48
+ #include "SseEventType.hpp"
49
+ #include "JSseEventType.hpp"
50
+ #include <NitroModules/AnyMap.hpp>
51
+ #include <NitroModules/JAnyMap.hpp>
52
+ #include "SseEvent.hpp"
53
+ #include "JFunc_void_std__vector_SseEvent_.hpp"
54
+ #include "JSseEvent.hpp"
55
+
56
+ namespace margelo::nitro::nitrosse {
57
+
58
+ std::shared_ptr<JHybridNitroSseSpec> JHybridNitroSseSpec::JavaPart::getJHybridNitroSseSpec() {
59
+ auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
60
+ auto castHybridObject = std::dynamic_pointer_cast<JHybridNitroSseSpec>(hybridObject);
61
+ if (castHybridObject == nullptr) [[unlikely]] {
62
+ throw std::runtime_error("Failed to downcast JHybridObject to JHybridNitroSseSpec!");
63
+ }
64
+ return castHybridObject;
65
+ }
66
+
67
+ jni::local_ref<JHybridNitroSseSpec::CxxPart::jhybriddata> JHybridNitroSseSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
68
+ return makeCxxInstance(jThis);
69
+ }
70
+
71
+ std::shared_ptr<JHybridObject> JHybridNitroSseSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
72
+ auto castJavaPart = jni::dynamic_ref_cast<JHybridNitroSseSpec::JavaPart>(javaPart);
73
+ if (castJavaPart == nullptr) [[unlikely]] {
74
+ throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridNitroSseSpec::JavaPart!");
75
+ }
76
+ return std::make_shared<JHybridNitroSseSpec>(castJavaPart);
77
+ }
78
+
79
+ void JHybridNitroSseSpec::CxxPart::registerNatives() {
80
+ registerHybrid({
81
+ makeNativeMethod("initHybrid", JHybridNitroSseSpec::CxxPart::initHybrid),
82
+ });
83
+ }
84
+
85
+ // Properties
86
+
87
+
88
+ // Methods
89
+ void JHybridNitroSseSpec::setup(const SseConfig& config, const std::function<void(const std::vector<SseEvent>& /* events */)>& onEvent) {
90
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JSseConfig> /* config */, jni::alias_ref<JFunc_void_std__vector_SseEvent_::javaobject> /* onEvent */)>("setup_cxx");
91
+ method(_javaPart, JSseConfig::fromCpp(config), JFunc_void_std__vector_SseEvent__cxx::fromCpp(onEvent));
92
+ }
93
+ void JHybridNitroSseSpec::start() {
94
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("start");
95
+ method(_javaPart);
96
+ }
97
+ void JHybridNitroSseSpec::stop() {
98
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("stop");
99
+ method(_javaPart);
100
+ }
101
+ void JHybridNitroSseSpec::setLastProcessedId(const std::string& id) {
102
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* id */)>("setLastProcessedId");
103
+ method(_javaPart, jni::make_jstring(id));
104
+ }
105
+ void JHybridNitroSseSpec::updateHeaders(const std::unordered_map<std::string, std::string>& headers) {
106
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JMap<jni::JString, jni::JString>> /* headers */)>("updateHeaders");
107
+ method(_javaPart, [&]() -> jni::local_ref<jni::JMap<jni::JString, jni::JString>> {
108
+ auto __map = jni::JHashMap<jni::JString, jni::JString>::create(headers.size());
109
+ for (const auto& __entry : headers) {
110
+ __map->put(jni::make_jstring(__entry.first), jni::make_jstring(__entry.second));
111
+ }
112
+ return __map;
113
+ }());
114
+ }
115
+ SseStats JHybridNitroSseSpec::getStats() {
116
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JSseStats>()>("getStats");
117
+ auto __result = method(_javaPart);
118
+ return __result->toCpp();
119
+ }
120
+ void JHybridNitroSseSpec::flush() {
121
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("flush");
122
+ method(_javaPart);
123
+ }
124
+ void JHybridNitroSseSpec::restart() {
125
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("restart");
126
+ method(_javaPart);
127
+ }
128
+ bool JHybridNitroSseSpec::isConnected() {
129
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isConnected");
130
+ auto __result = method(_javaPart);
131
+ return static_cast<bool>(__result);
132
+ }
133
+
134
+ } // namespace margelo::nitro::nitrosse
@@ -0,0 +1,71 @@
1
+ ///
2
+ /// HybridNitroSseSpec.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
+ #include <NitroModules/JHybridObject.hpp>
11
+ #include <fbjni/fbjni.h>
12
+ #include "HybridNitroSseSpec.hpp"
13
+
14
+
15
+
16
+
17
+ namespace margelo::nitro::nitrosse {
18
+
19
+ using namespace facebook;
20
+
21
+ class JHybridNitroSseSpec: public virtual HybridNitroSseSpec, public virtual JHybridObject {
22
+ public:
23
+ struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrosse/HybridNitroSseSpec;";
25
+ std::shared_ptr<JHybridNitroSseSpec> getJHybridNitroSseSpec();
26
+ };
27
+ struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
28
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrosse/HybridNitroSseSpec$CxxPart;";
29
+ static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
30
+ static void registerNatives();
31
+ using HybridBase::HybridBase;
32
+ protected:
33
+ std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
34
+ };
35
+
36
+ public:
37
+ explicit JHybridNitroSseSpec(const jni::local_ref<JHybridNitroSseSpec::JavaPart>& javaPart):
38
+ HybridObject(HybridNitroSseSpec::TAG),
39
+ JHybridObject(javaPart),
40
+ _javaPart(jni::make_global(javaPart)) {}
41
+ ~JHybridNitroSseSpec() override {
42
+ // Hermes GC can destroy JS objects on a non-JNI Thread.
43
+ jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
44
+ }
45
+
46
+ public:
47
+ inline const jni::global_ref<JHybridNitroSseSpec::JavaPart>& getJavaPart() const noexcept {
48
+ return _javaPart;
49
+ }
50
+
51
+ public:
52
+ // Properties
53
+
54
+
55
+ public:
56
+ // Methods
57
+ void setup(const SseConfig& config, const std::function<void(const std::vector<SseEvent>& /* events */)>& onEvent) override;
58
+ void start() override;
59
+ void stop() override;
60
+ void setLastProcessedId(const std::string& id) override;
61
+ void updateHeaders(const std::unordered_map<std::string, std::string>& headers) override;
62
+ SseStats getStats() override;
63
+ void flush() override;
64
+ void restart() override;
65
+ bool isConnected() override;
66
+
67
+ private:
68
+ jni::global_ref<JHybridNitroSseSpec::JavaPart> _javaPart;
69
+ };
70
+
71
+ } // namespace margelo::nitro::nitrosse
@@ -0,0 +1,162 @@
1
+ ///
2
+ /// JSseConfig.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
+ #include <fbjni/fbjni.h>
11
+ #include "SseConfig.hpp"
12
+
13
+ #include "HttpMethod.hpp"
14
+ #include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp"
15
+ #include "JHttpMethod.hpp"
16
+ #include "JSseEventType.hpp"
17
+ #include "JSseMockConfig.hpp"
18
+ #include "JSseMockEvent.hpp"
19
+ #include "JSseMockMode.hpp"
20
+ #include "SseEventType.hpp"
21
+ #include "SseMockConfig.hpp"
22
+ #include "SseMockEvent.hpp"
23
+ #include "SseMockMode.hpp"
24
+ #include <NitroModules/AnyMap.hpp>
25
+ #include <NitroModules/JAnyMap.hpp>
26
+ #include <NitroModules/JNICallable.hpp>
27
+ #include <NitroModules/JPromise.hpp>
28
+ #include <NitroModules/Promise.hpp>
29
+ #include <functional>
30
+ #include <optional>
31
+ #include <string>
32
+ #include <unordered_map>
33
+ #include <vector>
34
+
35
+ namespace margelo::nitro::nitrosse {
36
+
37
+ using namespace facebook;
38
+
39
+ /**
40
+ * The C++ JNI bridge between the C++ struct "SseConfig" and the the Kotlin data class "SseConfig".
41
+ */
42
+ struct JSseConfig final: public jni::JavaClass<JSseConfig> {
43
+ public:
44
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrosse/SseConfig;";
45
+
46
+ public:
47
+ /**
48
+ * Convert this Java/Kotlin-based struct to the C++ struct SseConfig by copying all values to C++.
49
+ */
50
+ [[maybe_unused]]
51
+ [[nodiscard]]
52
+ SseConfig toCpp() const {
53
+ static const auto clazz = javaClassStatic();
54
+ static const auto fieldUrl = clazz->getField<jni::JString>("url");
55
+ jni::local_ref<jni::JString> url = this->getFieldValue(fieldUrl);
56
+ static const auto fieldMethod = clazz->getField<JHttpMethod>("method");
57
+ jni::local_ref<JHttpMethod> method = this->getFieldValue(fieldMethod);
58
+ static const auto fieldHeaders = clazz->getField<jni::JMap<jni::JString, jni::JString>>("headers");
59
+ jni::local_ref<jni::JMap<jni::JString, jni::JString>> headers = this->getFieldValue(fieldHeaders);
60
+ static const auto fieldBody = clazz->getField<jni::JString>("body");
61
+ jni::local_ref<jni::JString> body = this->getFieldValue(fieldBody);
62
+ static const auto fieldBackgroundExecution = clazz->getField<jni::JBoolean>("backgroundExecution");
63
+ jni::local_ref<jni::JBoolean> backgroundExecution = this->getFieldValue(fieldBackgroundExecution);
64
+ static const auto fieldBatchingIntervalMs = clazz->getField<jni::JDouble>("batchingIntervalMs");
65
+ jni::local_ref<jni::JDouble> batchingIntervalMs = this->getFieldValue(fieldBatchingIntervalMs);
66
+ static const auto fieldMaxBufferSize = clazz->getField<jni::JDouble>("maxBufferSize");
67
+ jni::local_ref<jni::JDouble> maxBufferSize = this->getFieldValue(fieldMaxBufferSize);
68
+ static const auto fieldConnectionTimeoutMs = clazz->getField<jni::JDouble>("connectionTimeoutMs");
69
+ jni::local_ref<jni::JDouble> connectionTimeoutMs = this->getFieldValue(fieldConnectionTimeoutMs);
70
+ static const auto fieldReadTimeoutMs = clazz->getField<jni::JDouble>("readTimeoutMs");
71
+ jni::local_ref<jni::JDouble> readTimeoutMs = this->getFieldValue(fieldReadTimeoutMs);
72
+ static const auto fieldRetryIntervalMs = clazz->getField<jni::JDouble>("retryIntervalMs");
73
+ jni::local_ref<jni::JDouble> retryIntervalMs = this->getFieldValue(fieldRetryIntervalMs);
74
+ static const auto fieldMaxRetryIntervalMs = clazz->getField<jni::JDouble>("maxRetryIntervalMs");
75
+ jni::local_ref<jni::JDouble> maxRetryIntervalMs = this->getFieldValue(fieldMaxRetryIntervalMs);
76
+ static const auto fieldJitterFactor = clazz->getField<jni::JDouble>("jitterFactor");
77
+ jni::local_ref<jni::JDouble> jitterFactor = this->getFieldValue(fieldJitterFactor);
78
+ static const auto fieldMaxReconnectAttempts = clazz->getField<jni::JDouble>("maxReconnectAttempts");
79
+ jni::local_ref<jni::JDouble> maxReconnectAttempts = this->getFieldValue(fieldMaxReconnectAttempts);
80
+ static const auto fieldAutoParseJSON = clazz->getField<jni::JBoolean>("autoParseJSON");
81
+ jni::local_ref<jni::JBoolean> autoParseJSON = this->getFieldValue(fieldAutoParseJSON);
82
+ static const auto fieldMonitorNetwork = clazz->getField<jni::JBoolean>("monitorNetwork");
83
+ jni::local_ref<jni::JBoolean> monitorNetwork = this->getFieldValue(fieldMonitorNetwork);
84
+ static const auto fieldOnBeforeRequest = clazz->getField<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>("onBeforeRequest");
85
+ jni::local_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject> onBeforeRequest = this->getFieldValue(fieldOnBeforeRequest);
86
+ static const auto fieldMock = clazz->getField<JSseMockConfig>("mock");
87
+ jni::local_ref<JSseMockConfig> mock = this->getFieldValue(fieldMock);
88
+ return SseConfig(
89
+ url->toStdString(),
90
+ method != nullptr ? std::make_optional(method->toCpp()) : std::nullopt,
91
+ headers != nullptr ? std::make_optional([&]() {
92
+ std::unordered_map<std::string, std::string> __map;
93
+ __map.reserve(headers->size());
94
+ for (const auto& __entry : *headers) {
95
+ __map.emplace(__entry.first->toStdString(), __entry.second->toStdString());
96
+ }
97
+ return __map;
98
+ }()) : std::nullopt,
99
+ body != nullptr ? std::make_optional(body->toStdString()) : std::nullopt,
100
+ backgroundExecution != nullptr ? std::make_optional(static_cast<bool>(backgroundExecution->value())) : std::nullopt,
101
+ batchingIntervalMs != nullptr ? std::make_optional(batchingIntervalMs->value()) : std::nullopt,
102
+ maxBufferSize != nullptr ? std::make_optional(maxBufferSize->value()) : std::nullopt,
103
+ connectionTimeoutMs != nullptr ? std::make_optional(connectionTimeoutMs->value()) : std::nullopt,
104
+ readTimeoutMs != nullptr ? std::make_optional(readTimeoutMs->value()) : std::nullopt,
105
+ retryIntervalMs != nullptr ? std::make_optional(retryIntervalMs->value()) : std::nullopt,
106
+ maxRetryIntervalMs != nullptr ? std::make_optional(maxRetryIntervalMs->value()) : std::nullopt,
107
+ jitterFactor != nullptr ? std::make_optional(jitterFactor->value()) : std::nullopt,
108
+ maxReconnectAttempts != nullptr ? std::make_optional(maxReconnectAttempts->value()) : std::nullopt,
109
+ autoParseJSON != nullptr ? std::make_optional(static_cast<bool>(autoParseJSON->value())) : std::nullopt,
110
+ monitorNetwork != nullptr ? std::make_optional(static_cast<bool>(monitorNetwork->value())) : std::nullopt,
111
+ onBeforeRequest != nullptr ? std::make_optional([&]() -> std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()> {
112
+ if (onBeforeRequest->isInstanceOf(JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::javaClassStatic())) [[likely]] {
113
+ auto downcast = jni::static_ref_cast<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::javaobject>(onBeforeRequest);
114
+ return downcast->cthis()->getFunction();
115
+ } else {
116
+ auto onBeforeRequestRef = jni::make_global(onBeforeRequest);
117
+ return JNICallable<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____, std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>(std::move(onBeforeRequestRef));
118
+ }
119
+ }()) : std::nullopt,
120
+ mock != nullptr ? std::make_optional(mock->toCpp()) : std::nullopt
121
+ );
122
+ }
123
+
124
+ public:
125
+ /**
126
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
127
+ */
128
+ [[maybe_unused]]
129
+ static jni::local_ref<JSseConfig::javaobject> fromCpp(const SseConfig& value) {
130
+ using JSignature = JSseConfig(jni::alias_ref<jni::JString>, jni::alias_ref<JHttpMethod>, jni::alias_ref<jni::JMap<jni::JString, jni::JString>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>, jni::alias_ref<JSseMockConfig>);
131
+ static const auto clazz = javaClassStatic();
132
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
133
+ return create(
134
+ clazz,
135
+ jni::make_jstring(value.url),
136
+ value.method.has_value() ? JHttpMethod::fromCpp(value.method.value()) : nullptr,
137
+ value.headers.has_value() ? [&]() -> jni::local_ref<jni::JMap<jni::JString, jni::JString>> {
138
+ auto __map = jni::JHashMap<jni::JString, jni::JString>::create(value.headers.value().size());
139
+ for (const auto& __entry : value.headers.value()) {
140
+ __map->put(jni::make_jstring(__entry.first), jni::make_jstring(__entry.second));
141
+ }
142
+ return __map;
143
+ }() : nullptr,
144
+ value.body.has_value() ? jni::make_jstring(value.body.value()) : nullptr,
145
+ value.backgroundExecution.has_value() ? jni::JBoolean::valueOf(value.backgroundExecution.value()) : nullptr,
146
+ value.batchingIntervalMs.has_value() ? jni::JDouble::valueOf(value.batchingIntervalMs.value()) : nullptr,
147
+ value.maxBufferSize.has_value() ? jni::JDouble::valueOf(value.maxBufferSize.value()) : nullptr,
148
+ value.connectionTimeoutMs.has_value() ? jni::JDouble::valueOf(value.connectionTimeoutMs.value()) : nullptr,
149
+ value.readTimeoutMs.has_value() ? jni::JDouble::valueOf(value.readTimeoutMs.value()) : nullptr,
150
+ value.retryIntervalMs.has_value() ? jni::JDouble::valueOf(value.retryIntervalMs.value()) : nullptr,
151
+ value.maxRetryIntervalMs.has_value() ? jni::JDouble::valueOf(value.maxRetryIntervalMs.value()) : nullptr,
152
+ value.jitterFactor.has_value() ? jni::JDouble::valueOf(value.jitterFactor.value()) : nullptr,
153
+ value.maxReconnectAttempts.has_value() ? jni::JDouble::valueOf(value.maxReconnectAttempts.value()) : nullptr,
154
+ value.autoParseJSON.has_value() ? jni::JBoolean::valueOf(value.autoParseJSON.value()) : nullptr,
155
+ value.monitorNetwork.has_value() ? jni::JBoolean::valueOf(value.monitorNetwork.value()) : nullptr,
156
+ value.onBeforeRequest.has_value() ? JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::fromCpp(value.onBeforeRequest.value()) : nullptr,
157
+ value.mock.has_value() ? JSseMockConfig::fromCpp(value.mock.value()) : nullptr
158
+ );
159
+ }
160
+ };
161
+
162
+ } // namespace margelo::nitro::nitrosse
@@ -0,0 +1,90 @@
1
+ ///
2
+ /// JSseEvent.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
+ #include <fbjni/fbjni.h>
11
+ #include "SseEvent.hpp"
12
+
13
+ #include "JSseEventType.hpp"
14
+ #include "SseEventType.hpp"
15
+ #include <NitroModules/AnyMap.hpp>
16
+ #include <NitroModules/JAnyMap.hpp>
17
+ #include <optional>
18
+ #include <string>
19
+
20
+ namespace margelo::nitro::nitrosse {
21
+
22
+ using namespace facebook;
23
+
24
+ /**
25
+ * The C++ JNI bridge between the C++ struct "SseEvent" and the the Kotlin data class "SseEvent".
26
+ */
27
+ struct JSseEvent final: public jni::JavaClass<JSseEvent> {
28
+ public:
29
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrosse/SseEvent;";
30
+
31
+ public:
32
+ /**
33
+ * Convert this Java/Kotlin-based struct to the C++ struct SseEvent by copying all values to C++.
34
+ */
35
+ [[maybe_unused]]
36
+ [[nodiscard]]
37
+ SseEvent toCpp() const {
38
+ static const auto clazz = javaClassStatic();
39
+ static const auto fieldType = clazz->getField<JSseEventType>("type");
40
+ jni::local_ref<JSseEventType> type = this->getFieldValue(fieldType);
41
+ static const auto fieldData = clazz->getField<jni::JString>("data");
42
+ jni::local_ref<jni::JString> data = this->getFieldValue(fieldData);
43
+ static const auto fieldParsedData = clazz->getField<JAnyMap::javaobject>("parsedData");
44
+ jni::local_ref<JAnyMap::javaobject> parsedData = this->getFieldValue(fieldParsedData);
45
+ static const auto fieldId = clazz->getField<jni::JString>("id");
46
+ jni::local_ref<jni::JString> id = this->getFieldValue(fieldId);
47
+ static const auto fieldEvent = clazz->getField<jni::JString>("event");
48
+ jni::local_ref<jni::JString> event = this->getFieldValue(fieldEvent);
49
+ static const auto fieldMessage = clazz->getField<jni::JString>("message");
50
+ jni::local_ref<jni::JString> message = this->getFieldValue(fieldMessage);
51
+ static const auto fieldStatusCode = clazz->getField<jni::JDouble>("statusCode");
52
+ jni::local_ref<jni::JDouble> statusCode = this->getFieldValue(fieldStatusCode);
53
+ static const auto fieldRetry = clazz->getField<jni::JDouble>("retry");
54
+ jni::local_ref<jni::JDouble> retry = this->getFieldValue(fieldRetry);
55
+ return SseEvent(
56
+ type->toCpp(),
57
+ data != nullptr ? std::make_optional(data->toStdString()) : std::nullopt,
58
+ parsedData != nullptr ? std::make_optional(parsedData->cthis()->getMap()) : std::nullopt,
59
+ id != nullptr ? std::make_optional(id->toStdString()) : std::nullopt,
60
+ event != nullptr ? std::make_optional(event->toStdString()) : std::nullopt,
61
+ message != nullptr ? std::make_optional(message->toStdString()) : std::nullopt,
62
+ statusCode != nullptr ? std::make_optional(statusCode->value()) : std::nullopt,
63
+ retry != nullptr ? std::make_optional(retry->value()) : std::nullopt
64
+ );
65
+ }
66
+
67
+ public:
68
+ /**
69
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
70
+ */
71
+ [[maybe_unused]]
72
+ static jni::local_ref<JSseEvent::javaobject> fromCpp(const SseEvent& value) {
73
+ using JSignature = JSseEvent(jni::alias_ref<JSseEventType>, jni::alias_ref<jni::JString>, jni::alias_ref<JAnyMap::javaobject>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
74
+ static const auto clazz = javaClassStatic();
75
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
76
+ return create(
77
+ clazz,
78
+ JSseEventType::fromCpp(value.type),
79
+ value.data.has_value() ? jni::make_jstring(value.data.value()) : nullptr,
80
+ value.parsedData.has_value() ? JAnyMap::create(value.parsedData.value()) : nullptr,
81
+ value.id.has_value() ? jni::make_jstring(value.id.value()) : nullptr,
82
+ value.event.has_value() ? jni::make_jstring(value.event.value()) : nullptr,
83
+ value.message.has_value() ? jni::make_jstring(value.message.value()) : nullptr,
84
+ value.statusCode.has_value() ? jni::JDouble::valueOf(value.statusCode.value()) : nullptr,
85
+ value.retry.has_value() ? jni::JDouble::valueOf(value.retry.value()) : nullptr
86
+ );
87
+ }
88
+ };
89
+
90
+ } // namespace margelo::nitro::nitrosse
@@ -0,0 +1,67 @@
1
+ ///
2
+ /// JSseEventType.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
+ #include <fbjni/fbjni.h>
11
+ #include "SseEventType.hpp"
12
+
13
+ namespace margelo::nitro::nitrosse {
14
+
15
+ using namespace facebook;
16
+
17
+ /**
18
+ * The C++ JNI bridge between the C++ enum "SseEventType" and the the Kotlin enum "SseEventType".
19
+ */
20
+ struct JSseEventType final: public jni::JavaClass<JSseEventType> {
21
+ public:
22
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrosse/SseEventType;";
23
+
24
+ public:
25
+ /**
26
+ * Convert this Java/Kotlin-based enum to the C++ enum SseEventType.
27
+ */
28
+ [[maybe_unused]]
29
+ [[nodiscard]]
30
+ SseEventType 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<SseEventType>(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<JSseEventType> fromCpp(SseEventType value) {
43
+ static const auto clazz = javaClassStatic();
44
+ switch (value) {
45
+ case SseEventType::OPEN:
46
+ static const auto fieldOPEN = clazz->getStaticField<JSseEventType>("OPEN");
47
+ return clazz->getStaticFieldValue(fieldOPEN);
48
+ case SseEventType::MESSAGE:
49
+ static const auto fieldMESSAGE = clazz->getStaticField<JSseEventType>("MESSAGE");
50
+ return clazz->getStaticFieldValue(fieldMESSAGE);
51
+ case SseEventType::ERROR:
52
+ static const auto fieldERROR = clazz->getStaticField<JSseEventType>("ERROR");
53
+ return clazz->getStaticFieldValue(fieldERROR);
54
+ case SseEventType::CLOSE:
55
+ static const auto fieldCLOSE = clazz->getStaticField<JSseEventType>("CLOSE");
56
+ return clazz->getStaticFieldValue(fieldCLOSE);
57
+ case SseEventType::HEARTBEAT:
58
+ static const auto fieldHEARTBEAT = clazz->getStaticField<JSseEventType>("HEARTBEAT");
59
+ return clazz->getStaticFieldValue(fieldHEARTBEAT);
60
+ default:
61
+ std::string stringValue = std::to_string(static_cast<int>(value));
62
+ throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
63
+ }
64
+ }
65
+ };
66
+
67
+ } // namespace margelo::nitro::nitrosse
@@ -0,0 +1,101 @@
1
+ ///
2
+ /// JSseMockConfig.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
+ #include <fbjni/fbjni.h>
11
+ #include "SseMockConfig.hpp"
12
+
13
+ #include "JSseEventType.hpp"
14
+ #include "JSseMockEvent.hpp"
15
+ #include "JSseMockMode.hpp"
16
+ #include "SseEventType.hpp"
17
+ #include "SseMockEvent.hpp"
18
+ #include "SseMockMode.hpp"
19
+ #include <NitroModules/AnyMap.hpp>
20
+ #include <NitroModules/JAnyMap.hpp>
21
+ #include <optional>
22
+ #include <string>
23
+ #include <vector>
24
+
25
+ namespace margelo::nitro::nitrosse {
26
+
27
+ using namespace facebook;
28
+
29
+ /**
30
+ * The C++ JNI bridge between the C++ struct "SseMockConfig" and the the Kotlin data class "SseMockConfig".
31
+ */
32
+ struct JSseMockConfig final: public jni::JavaClass<JSseMockConfig> {
33
+ public:
34
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrosse/SseMockConfig;";
35
+
36
+ public:
37
+ /**
38
+ * Convert this Java/Kotlin-based struct to the C++ struct SseMockConfig by copying all values to C++.
39
+ */
40
+ [[maybe_unused]]
41
+ [[nodiscard]]
42
+ SseMockConfig toCpp() const {
43
+ static const auto clazz = javaClassStatic();
44
+ static const auto fieldMode = clazz->getField<JSseMockMode>("mode");
45
+ jni::local_ref<JSseMockMode> mode = this->getFieldValue(fieldMode);
46
+ static const auto fieldData = clazz->getField<jni::JArrayClass<JSseMockEvent>>("data");
47
+ jni::local_ref<jni::JArrayClass<JSseMockEvent>> data = this->getFieldValue(fieldData);
48
+ static const auto fieldEventsPerSecond = clazz->getField<jni::JDouble>("eventsPerSecond");
49
+ jni::local_ref<jni::JDouble> eventsPerSecond = this->getFieldValue(fieldEventsPerSecond);
50
+ static const auto fieldLoop = clazz->getField<jni::JBoolean>("loop");
51
+ jni::local_ref<jni::JBoolean> loop = this->getFieldValue(fieldLoop);
52
+ static const auto fieldErrorRate = clazz->getField<jni::JDouble>("errorRate");
53
+ jni::local_ref<jni::JDouble> errorRate = this->getFieldValue(fieldErrorRate);
54
+ return SseMockConfig(
55
+ mode->toCpp(),
56
+ [&](auto&& __input) {
57
+ size_t __size = __input->size();
58
+ std::vector<SseMockEvent> __vector;
59
+ __vector.reserve(__size);
60
+ for (size_t __i = 0; __i < __size; __i++) {
61
+ auto __element = __input->getElement(__i);
62
+ __vector.push_back(__element->toCpp());
63
+ }
64
+ return __vector;
65
+ }(data),
66
+ eventsPerSecond != nullptr ? std::make_optional(eventsPerSecond->value()) : std::nullopt,
67
+ loop != nullptr ? std::make_optional(static_cast<bool>(loop->value())) : std::nullopt,
68
+ errorRate != nullptr ? std::make_optional(errorRate->value()) : std::nullopt
69
+ );
70
+ }
71
+
72
+ public:
73
+ /**
74
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
75
+ */
76
+ [[maybe_unused]]
77
+ static jni::local_ref<JSseMockConfig::javaobject> fromCpp(const SseMockConfig& value) {
78
+ using JSignature = JSseMockConfig(jni::alias_ref<JSseMockMode>, jni::alias_ref<jni::JArrayClass<JSseMockEvent>>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>);
79
+ static const auto clazz = javaClassStatic();
80
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
81
+ return create(
82
+ clazz,
83
+ JSseMockMode::fromCpp(value.mode),
84
+ [&](auto&& __input) {
85
+ size_t __size = __input.size();
86
+ jni::local_ref<jni::JArrayClass<JSseMockEvent>> __array = jni::JArrayClass<JSseMockEvent>::newArray(__size);
87
+ for (size_t __i = 0; __i < __size; __i++) {
88
+ const auto& __element = __input[__i];
89
+ auto __elementJni = JSseMockEvent::fromCpp(__element);
90
+ __array->setElement(__i, *__elementJni);
91
+ }
92
+ return __array;
93
+ }(value.data),
94
+ value.eventsPerSecond.has_value() ? jni::JDouble::valueOf(value.eventsPerSecond.value()) : nullptr,
95
+ value.loop.has_value() ? jni::JBoolean::valueOf(value.loop.value()) : nullptr,
96
+ value.errorRate.has_value() ? jni::JDouble::valueOf(value.errorRate.value()) : nullptr
97
+ );
98
+ }
99
+ };
100
+
101
+ } // namespace margelo::nitro::nitrosse