@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,81 @@
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
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `SseConfig` to properly resolve imports.
17
+ namespace margelo::nitro::nitrosse { struct SseConfig; }
18
+ // Forward declaration of `SseEvent` to properly resolve imports.
19
+ namespace margelo::nitro::nitrosse { struct SseEvent; }
20
+ // Forward declaration of `SseStats` to properly resolve imports.
21
+ namespace margelo::nitro::nitrosse { struct SseStats; }
22
+
23
+ #include "SseConfig.hpp"
24
+ #include "SseEvent.hpp"
25
+ #include <vector>
26
+ #include <functional>
27
+ #include <string>
28
+ #include <unordered_map>
29
+ #include "SseStats.hpp"
30
+
31
+ namespace margelo::nitro::nitrosse {
32
+
33
+ using namespace margelo::nitro;
34
+
35
+ /**
36
+ * An abstract base class for `NitroSse`
37
+ * Inherit this class to create instances of `HybridNitroSseSpec` in C++.
38
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
39
+ * @example
40
+ * ```cpp
41
+ * class HybridNitroSse: public HybridNitroSseSpec {
42
+ * public:
43
+ * HybridNitroSse(...): HybridObject(TAG) { ... }
44
+ * // ...
45
+ * };
46
+ * ```
47
+ */
48
+ class HybridNitroSseSpec: public virtual HybridObject {
49
+ public:
50
+ // Constructor
51
+ explicit HybridNitroSseSpec(): HybridObject(TAG) { }
52
+
53
+ // Destructor
54
+ ~HybridNitroSseSpec() override = default;
55
+
56
+ public:
57
+ // Properties
58
+
59
+
60
+ public:
61
+ // Methods
62
+ virtual void setup(const SseConfig& config, const std::function<void(const std::vector<SseEvent>& /* events */)>& onEvent) = 0;
63
+ virtual void start() = 0;
64
+ virtual void stop() = 0;
65
+ virtual void setLastProcessedId(const std::string& id) = 0;
66
+ virtual void updateHeaders(const std::unordered_map<std::string, std::string>& headers) = 0;
67
+ virtual SseStats getStats() = 0;
68
+ virtual void flush() = 0;
69
+ virtual void restart() = 0;
70
+ virtual bool isConnected() = 0;
71
+
72
+ protected:
73
+ // Hybrid Setup
74
+ void loadHybridMethods() override;
75
+
76
+ protected:
77
+ // Tag for logging
78
+ static constexpr auto TAG = "NitroSse";
79
+ };
80
+
81
+ } // namespace margelo::nitro::nitrosse
@@ -0,0 +1,156 @@
1
+ ///
2
+ /// SseConfig.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+ // Forward declaration of `HttpMethod` to properly resolve imports.
32
+ namespace margelo::nitro::nitrosse { enum class HttpMethod; }
33
+ // Forward declaration of `SseMockConfig` to properly resolve imports.
34
+ namespace margelo::nitro::nitrosse { struct SseMockConfig; }
35
+
36
+ #include <string>
37
+ #include "HttpMethod.hpp"
38
+ #include <optional>
39
+ #include <unordered_map>
40
+ #include <NitroModules/Promise.hpp>
41
+ #include <functional>
42
+ #include "SseMockConfig.hpp"
43
+
44
+ namespace margelo::nitro::nitrosse {
45
+
46
+ /**
47
+ * A struct which can be represented as a JavaScript object (SseConfig).
48
+ */
49
+ struct SseConfig final {
50
+ public:
51
+ std::string url SWIFT_PRIVATE;
52
+ std::optional<HttpMethod> method SWIFT_PRIVATE;
53
+ std::optional<std::unordered_map<std::string, std::string>> headers SWIFT_PRIVATE;
54
+ std::optional<std::string> body SWIFT_PRIVATE;
55
+ std::optional<bool> backgroundExecution SWIFT_PRIVATE;
56
+ std::optional<double> batchingIntervalMs SWIFT_PRIVATE;
57
+ std::optional<double> maxBufferSize SWIFT_PRIVATE;
58
+ std::optional<double> connectionTimeoutMs SWIFT_PRIVATE;
59
+ std::optional<double> readTimeoutMs SWIFT_PRIVATE;
60
+ std::optional<double> retryIntervalMs SWIFT_PRIVATE;
61
+ std::optional<double> maxRetryIntervalMs SWIFT_PRIVATE;
62
+ std::optional<double> jitterFactor SWIFT_PRIVATE;
63
+ std::optional<double> maxReconnectAttempts SWIFT_PRIVATE;
64
+ std::optional<bool> autoParseJSON SWIFT_PRIVATE;
65
+ std::optional<bool> monitorNetwork SWIFT_PRIVATE;
66
+ std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>> onBeforeRequest SWIFT_PRIVATE;
67
+ std::optional<SseMockConfig> mock SWIFT_PRIVATE;
68
+
69
+ public:
70
+ SseConfig() = default;
71
+ explicit SseConfig(std::string url, std::optional<HttpMethod> method, std::optional<std::unordered_map<std::string, std::string>> headers, std::optional<std::string> body, std::optional<bool> backgroundExecution, std::optional<double> batchingIntervalMs, std::optional<double> maxBufferSize, std::optional<double> connectionTimeoutMs, std::optional<double> readTimeoutMs, std::optional<double> retryIntervalMs, std::optional<double> maxRetryIntervalMs, std::optional<double> jitterFactor, std::optional<double> maxReconnectAttempts, std::optional<bool> autoParseJSON, std::optional<bool> monitorNetwork, std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>> onBeforeRequest, std::optional<SseMockConfig> mock): url(url), method(method), headers(headers), body(body), backgroundExecution(backgroundExecution), batchingIntervalMs(batchingIntervalMs), maxBufferSize(maxBufferSize), connectionTimeoutMs(connectionTimeoutMs), readTimeoutMs(readTimeoutMs), retryIntervalMs(retryIntervalMs), maxRetryIntervalMs(maxRetryIntervalMs), jitterFactor(jitterFactor), maxReconnectAttempts(maxReconnectAttempts), autoParseJSON(autoParseJSON), monitorNetwork(monitorNetwork), onBeforeRequest(onBeforeRequest), mock(mock) {}
72
+
73
+ public:
74
+ // SseConfig is not equatable because these properties are not equatable: onBeforeRequest
75
+ };
76
+
77
+ } // namespace margelo::nitro::nitrosse
78
+
79
+ namespace margelo::nitro {
80
+
81
+ // C++ SseConfig <> JS SseConfig (object)
82
+ template <>
83
+ struct JSIConverter<margelo::nitro::nitrosse::SseConfig> final {
84
+ static inline margelo::nitro::nitrosse::SseConfig fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
85
+ jsi::Object obj = arg.asObject(runtime);
86
+ return margelo::nitro::nitrosse::SseConfig(
87
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "url"))),
88
+ JSIConverter<std::optional<margelo::nitro::nitrosse::HttpMethod>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "method"))),
89
+ JSIConverter<std::optional<std::unordered_map<std::string, std::string>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "headers"))),
90
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "body"))),
91
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "backgroundExecution"))),
92
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "batchingIntervalMs"))),
93
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxBufferSize"))),
94
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "connectionTimeoutMs"))),
95
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "readTimeoutMs"))),
96
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retryIntervalMs"))),
97
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxRetryIntervalMs"))),
98
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "jitterFactor"))),
99
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxReconnectAttempts"))),
100
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON"))),
101
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "monitorNetwork"))),
102
+ JSIConverter<std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onBeforeRequest"))),
103
+ JSIConverter<std::optional<margelo::nitro::nitrosse::SseMockConfig>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mock")))
104
+ );
105
+ }
106
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrosse::SseConfig& arg) {
107
+ jsi::Object obj(runtime);
108
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "url"), JSIConverter<std::string>::toJSI(runtime, arg.url));
109
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "method"), JSIConverter<std::optional<margelo::nitro::nitrosse::HttpMethod>>::toJSI(runtime, arg.method));
110
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "headers"), JSIConverter<std::optional<std::unordered_map<std::string, std::string>>>::toJSI(runtime, arg.headers));
111
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "body"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.body));
112
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "backgroundExecution"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.backgroundExecution));
113
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "batchingIntervalMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.batchingIntervalMs));
114
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxBufferSize"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxBufferSize));
115
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "connectionTimeoutMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.connectionTimeoutMs));
116
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "readTimeoutMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.readTimeoutMs));
117
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "retryIntervalMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.retryIntervalMs));
118
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxRetryIntervalMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxRetryIntervalMs));
119
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "jitterFactor"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.jitterFactor));
120
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxReconnectAttempts"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxReconnectAttempts));
121
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.autoParseJSON));
122
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "monitorNetwork"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.monitorNetwork));
123
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "onBeforeRequest"), JSIConverter<std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>>::toJSI(runtime, arg.onBeforeRequest));
124
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "mock"), JSIConverter<std::optional<margelo::nitro::nitrosse::SseMockConfig>>::toJSI(runtime, arg.mock));
125
+ return obj;
126
+ }
127
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
128
+ if (!value.isObject()) {
129
+ return false;
130
+ }
131
+ jsi::Object obj = value.getObject(runtime);
132
+ if (!nitro::isPlainObject(runtime, obj)) {
133
+ return false;
134
+ }
135
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "url")))) return false;
136
+ if (!JSIConverter<std::optional<margelo::nitro::nitrosse::HttpMethod>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "method")))) return false;
137
+ if (!JSIConverter<std::optional<std::unordered_map<std::string, std::string>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "headers")))) return false;
138
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "body")))) return false;
139
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "backgroundExecution")))) return false;
140
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "batchingIntervalMs")))) return false;
141
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxBufferSize")))) return false;
142
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "connectionTimeoutMs")))) return false;
143
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "readTimeoutMs")))) return false;
144
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retryIntervalMs")))) return false;
145
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxRetryIntervalMs")))) return false;
146
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "jitterFactor")))) return false;
147
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxReconnectAttempts")))) return false;
148
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON")))) return false;
149
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "monitorNetwork")))) return false;
150
+ if (!JSIConverter<std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onBeforeRequest")))) return false;
151
+ if (!JSIConverter<std::optional<margelo::nitro::nitrosse::SseMockConfig>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mock")))) return false;
152
+ return true;
153
+ }
154
+ };
155
+
156
+ } // namespace margelo::nitro
@@ -0,0 +1,115 @@
1
+ ///
2
+ /// SseEvent.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+ // Forward declaration of `SseEventType` to properly resolve imports.
32
+ namespace margelo::nitro::nitrosse { enum class SseEventType; }
33
+
34
+ #include "SseEventType.hpp"
35
+ #include <string>
36
+ #include <optional>
37
+ #include <NitroModules/AnyMap.hpp>
38
+
39
+ namespace margelo::nitro::nitrosse {
40
+
41
+ /**
42
+ * A struct which can be represented as a JavaScript object (SseEvent).
43
+ */
44
+ struct SseEvent final {
45
+ public:
46
+ SseEventType type SWIFT_PRIVATE;
47
+ std::optional<std::string> data SWIFT_PRIVATE;
48
+ std::optional<std::shared_ptr<AnyMap>> parsedData SWIFT_PRIVATE;
49
+ std::optional<std::string> id SWIFT_PRIVATE;
50
+ std::optional<std::string> event SWIFT_PRIVATE;
51
+ std::optional<std::string> message SWIFT_PRIVATE;
52
+ std::optional<double> statusCode SWIFT_PRIVATE;
53
+ std::optional<double> retry SWIFT_PRIVATE;
54
+
55
+ public:
56
+ SseEvent() = default;
57
+ explicit SseEvent(SseEventType type, std::optional<std::string> data, std::optional<std::shared_ptr<AnyMap>> parsedData, std::optional<std::string> id, std::optional<std::string> event, std::optional<std::string> message, std::optional<double> statusCode, std::optional<double> retry): type(type), data(data), parsedData(parsedData), id(id), event(event), message(message), statusCode(statusCode), retry(retry) {}
58
+
59
+ public:
60
+ friend bool operator==(const SseEvent& lhs, const SseEvent& rhs) = default;
61
+ };
62
+
63
+ } // namespace margelo::nitro::nitrosse
64
+
65
+ namespace margelo::nitro {
66
+
67
+ // C++ SseEvent <> JS SseEvent (object)
68
+ template <>
69
+ struct JSIConverter<margelo::nitro::nitrosse::SseEvent> final {
70
+ static inline margelo::nitro::nitrosse::SseEvent fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
71
+ jsi::Object obj = arg.asObject(runtime);
72
+ return margelo::nitro::nitrosse::SseEvent(
73
+ JSIConverter<margelo::nitro::nitrosse::SseEventType>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type"))),
74
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data"))),
75
+ JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "parsedData"))),
76
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id"))),
77
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "event"))),
78
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message"))),
79
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusCode"))),
80
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retry")))
81
+ );
82
+ }
83
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrosse::SseEvent& arg) {
84
+ jsi::Object obj(runtime);
85
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "type"), JSIConverter<margelo::nitro::nitrosse::SseEventType>::toJSI(runtime, arg.type));
86
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "data"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.data));
87
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "parsedData"), JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::toJSI(runtime, arg.parsedData));
88
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "id"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.id));
89
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "event"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.event));
90
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "message"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.message));
91
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "statusCode"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.statusCode));
92
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "retry"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.retry));
93
+ return obj;
94
+ }
95
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
96
+ if (!value.isObject()) {
97
+ return false;
98
+ }
99
+ jsi::Object obj = value.getObject(runtime);
100
+ if (!nitro::isPlainObject(runtime, obj)) {
101
+ return false;
102
+ }
103
+ if (!JSIConverter<margelo::nitro::nitrosse::SseEventType>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type")))) return false;
104
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data")))) return false;
105
+ if (!JSIConverter<std::optional<std::shared_ptr<AnyMap>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "parsedData")))) return false;
106
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id")))) return false;
107
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "event")))) return false;
108
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message")))) return false;
109
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusCode")))) return false;
110
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retry")))) return false;
111
+ return true;
112
+ }
113
+ };
114
+
115
+ } // namespace margelo::nitro
@@ -0,0 +1,88 @@
1
+ ///
2
+ /// SseEventType.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/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::nitrosse {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (SseEventType).
30
+ */
31
+ enum class SseEventType {
32
+ OPEN SWIFT_NAME(open) = 0,
33
+ MESSAGE SWIFT_NAME(message) = 1,
34
+ ERROR SWIFT_NAME(error) = 2,
35
+ CLOSE SWIFT_NAME(close) = 3,
36
+ HEARTBEAT SWIFT_NAME(heartbeat) = 4,
37
+ } CLOSED_ENUM;
38
+
39
+ } // namespace margelo::nitro::nitrosse
40
+
41
+ namespace margelo::nitro {
42
+
43
+ // C++ SseEventType <> JS SseEventType (union)
44
+ template <>
45
+ struct JSIConverter<margelo::nitro::nitrosse::SseEventType> final {
46
+ static inline margelo::nitro::nitrosse::SseEventType fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
47
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
48
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
49
+ case hashString("open"): return margelo::nitro::nitrosse::SseEventType::OPEN;
50
+ case hashString("message"): return margelo::nitro::nitrosse::SseEventType::MESSAGE;
51
+ case hashString("error"): return margelo::nitro::nitrosse::SseEventType::ERROR;
52
+ case hashString("close"): return margelo::nitro::nitrosse::SseEventType::CLOSE;
53
+ case hashString("heartbeat"): return margelo::nitro::nitrosse::SseEventType::HEARTBEAT;
54
+ default: [[unlikely]]
55
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum SseEventType - invalid value!");
56
+ }
57
+ }
58
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrosse::SseEventType arg) {
59
+ switch (arg) {
60
+ case margelo::nitro::nitrosse::SseEventType::OPEN: return JSIConverter<std::string>::toJSI(runtime, "open");
61
+ case margelo::nitro::nitrosse::SseEventType::MESSAGE: return JSIConverter<std::string>::toJSI(runtime, "message");
62
+ case margelo::nitro::nitrosse::SseEventType::ERROR: return JSIConverter<std::string>::toJSI(runtime, "error");
63
+ case margelo::nitro::nitrosse::SseEventType::CLOSE: return JSIConverter<std::string>::toJSI(runtime, "close");
64
+ case margelo::nitro::nitrosse::SseEventType::HEARTBEAT: return JSIConverter<std::string>::toJSI(runtime, "heartbeat");
65
+ default: [[unlikely]]
66
+ throw std::invalid_argument("Cannot convert SseEventType to JS - invalid value: "
67
+ + std::to_string(static_cast<int>(arg)) + "!");
68
+ }
69
+ }
70
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
71
+ if (!value.isString()) {
72
+ return false;
73
+ }
74
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
75
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
76
+ case hashString("open"):
77
+ case hashString("message"):
78
+ case hashString("error"):
79
+ case hashString("close"):
80
+ case hashString("heartbeat"):
81
+ return true;
82
+ default:
83
+ return false;
84
+ }
85
+ }
86
+ };
87
+
88
+ } // namespace margelo::nitro
@@ -0,0 +1,105 @@
1
+ ///
2
+ /// SseMockConfig.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+ // Forward declaration of `SseMockMode` to properly resolve imports.
32
+ namespace margelo::nitro::nitrosse { enum class SseMockMode; }
33
+ // Forward declaration of `SseMockEvent` to properly resolve imports.
34
+ namespace margelo::nitro::nitrosse { struct SseMockEvent; }
35
+
36
+ #include "SseMockMode.hpp"
37
+ #include "SseMockEvent.hpp"
38
+ #include <vector>
39
+ #include <optional>
40
+
41
+ namespace margelo::nitro::nitrosse {
42
+
43
+ /**
44
+ * A struct which can be represented as a JavaScript object (SseMockConfig).
45
+ */
46
+ struct SseMockConfig final {
47
+ public:
48
+ SseMockMode mode SWIFT_PRIVATE;
49
+ std::vector<SseMockEvent> data SWIFT_PRIVATE;
50
+ std::optional<double> eventsPerSecond SWIFT_PRIVATE;
51
+ std::optional<bool> loop SWIFT_PRIVATE;
52
+ std::optional<double> errorRate SWIFT_PRIVATE;
53
+
54
+ public:
55
+ SseMockConfig() = default;
56
+ explicit SseMockConfig(SseMockMode mode, std::vector<SseMockEvent> data, std::optional<double> eventsPerSecond, std::optional<bool> loop, std::optional<double> errorRate): mode(mode), data(data), eventsPerSecond(eventsPerSecond), loop(loop), errorRate(errorRate) {}
57
+
58
+ public:
59
+ friend bool operator==(const SseMockConfig& lhs, const SseMockConfig& rhs) = default;
60
+ };
61
+
62
+ } // namespace margelo::nitro::nitrosse
63
+
64
+ namespace margelo::nitro {
65
+
66
+ // C++ SseMockConfig <> JS SseMockConfig (object)
67
+ template <>
68
+ struct JSIConverter<margelo::nitro::nitrosse::SseMockConfig> final {
69
+ static inline margelo::nitro::nitrosse::SseMockConfig fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
70
+ jsi::Object obj = arg.asObject(runtime);
71
+ return margelo::nitro::nitrosse::SseMockConfig(
72
+ JSIConverter<margelo::nitro::nitrosse::SseMockMode>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mode"))),
73
+ JSIConverter<std::vector<margelo::nitro::nitrosse::SseMockEvent>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data"))),
74
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "eventsPerSecond"))),
75
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "loop"))),
76
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "errorRate")))
77
+ );
78
+ }
79
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrosse::SseMockConfig& arg) {
80
+ jsi::Object obj(runtime);
81
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "mode"), JSIConverter<margelo::nitro::nitrosse::SseMockMode>::toJSI(runtime, arg.mode));
82
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "data"), JSIConverter<std::vector<margelo::nitro::nitrosse::SseMockEvent>>::toJSI(runtime, arg.data));
83
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "eventsPerSecond"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.eventsPerSecond));
84
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "loop"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.loop));
85
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "errorRate"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.errorRate));
86
+ return obj;
87
+ }
88
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
89
+ if (!value.isObject()) {
90
+ return false;
91
+ }
92
+ jsi::Object obj = value.getObject(runtime);
93
+ if (!nitro::isPlainObject(runtime, obj)) {
94
+ return false;
95
+ }
96
+ if (!JSIConverter<margelo::nitro::nitrosse::SseMockMode>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mode")))) return false;
97
+ if (!JSIConverter<std::vector<margelo::nitro::nitrosse::SseMockEvent>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data")))) return false;
98
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "eventsPerSecond")))) return false;
99
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "loop")))) return false;
100
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "errorRate")))) return false;
101
+ return true;
102
+ }
103
+ };
104
+
105
+ } // namespace margelo::nitro