react-native-nitro-sse 3.0.0-beta.1 → 3.0.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 (34) hide show
  1. package/README.md +43 -23
  2. package/android/build.gradle +4 -1
  3. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +110 -64
  4. package/android/src/main/java/com/margelo/nitro/nitrosse/SseConnectionHandler.kt +32 -23
  5. package/android/src/main/java/com/margelo/nitro/nitrosse/SseEventBuffer.kt +3 -0
  6. package/android/src/main/java/com/margelo/nitro/nitrosse/SseNetworkMonitor.kt +29 -2
  7. package/ios/NitroSse.swift +53 -17
  8. package/ios/SseConfig+CopyWith.swift +35 -19
  9. package/lib/module/MockSseEngine.js +0 -5
  10. package/lib/module/NitroSseClient.js +55 -7
  11. package/lib/module/createNitroSse.js +24 -0
  12. package/lib/module/index.js +1 -22
  13. package/lib/module/useNitroSse.js +22 -5
  14. package/lib/typescript/src/NitroSse.nitro.d.ts +2 -2
  15. package/lib/typescript/src/NitroSseClient.d.ts +7 -3
  16. package/lib/typescript/src/SseInterface.d.ts +14 -7
  17. package/lib/typescript/src/createNitroSse.d.ts +9 -0
  18. package/lib/typescript/src/index.d.ts +1 -8
  19. package/lib/typescript/src/useNitroSse.d.ts +2 -2
  20. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +8 -8
  21. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.hpp +1 -1
  22. package/nitrogen/generated/android/c++/JSseConfig.hpp +1 -18
  23. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/HybridNitroSseSpec.kt +4 -3
  24. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +4 -13
  25. package/nitrogen/generated/android/nitrosseOnLoad.cpp +2 -2
  26. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.cpp +8 -8
  27. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +104 -104
  28. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +4 -4
  29. package/nitrogen/generated/ios/swift/HybridNitroSseSpec.swift +1 -1
  30. package/nitrogen/generated/ios/swift/HybridNitroSseSpec_cxx.swift +34 -1
  31. package/nitrogen/generated/ios/swift/SseConfig.swift +1 -48
  32. package/nitrogen/generated/shared/c++/HybridNitroSseSpec.hpp +3 -1
  33. package/nitrogen/generated/shared/c++/SseConfig.hpp +2 -8
  34. package/package.json +1 -1
@@ -18,7 +18,7 @@ public extension SseConfig {
18
18
  /**
19
19
  * Create a new instance of `SseConfig`.
20
20
  */
21
- init(url: String, method: HttpMethod?, headers: Dictionary<String, String>?, body: String?, backgroundExecution: Bool?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, maxAuthRetries: Double?, autoParseJSON: Bool?, monitorNetwork: Bool?, onBeforeRequest: (() -> Promise<Promise<Dictionary<String, String>>>)?, mock: SseMockConfig?) {
21
+ init(url: String, method: HttpMethod?, headers: Dictionary<String, String>?, body: String?, backgroundExecution: Bool?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, maxAuthRetries: Double?, autoParseJSON: Bool?, monitorNetwork: Bool?, mock: SseMockConfig?) {
22
22
  self.init(std.string(url), { () -> bridge.std__optional_HttpMethod_ in
23
23
  if let __unwrappedValue = method {
24
24
  return bridge.create_std__optional_HttpMethod_(__unwrappedValue)
@@ -115,15 +115,6 @@ public extension SseConfig {
115
115
  } else {
116
116
  return .init()
117
117
  }
118
- }(), { () -> bridge.std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________ in
119
- if let __unwrappedValue = onBeforeRequest {
120
- return bridge.create_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________({ () -> bridge.Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ in
121
- let __closureWrapper = Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(__unwrappedValue)
122
- return bridge.create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(__closureWrapper.toUnsafe())
123
- }())
124
- } else {
125
- return .init()
126
- }
127
118
  }(), { () -> bridge.std__optional_SseMockConfig_ in
128
119
  if let __unwrappedValue = mock {
129
120
  return bridge.create_std__optional_SseMockConfig_(__unwrappedValue)
@@ -319,44 +310,6 @@ public extension SseConfig {
319
310
  }()
320
311
  }
321
312
 
322
- @inline(__always)
323
- var onBeforeRequest: (() -> Promise<Promise<Dictionary<String, String>>>)? {
324
- return { () -> (() -> Promise<Promise<Dictionary<String, String>>>)? in
325
- if bridge.has_value_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________(self.__onBeforeRequest) {
326
- let __unwrapped = bridge.get_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________(self.__onBeforeRequest)
327
- return { () -> () -> Promise<Promise<Dictionary<String, String>>> in
328
- let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(__unwrapped)
329
- return { () -> Promise<Promise<Dictionary<String, String>>> in
330
- let __result = __wrappedFunction.call()
331
- return { () -> Promise<Promise<Dictionary<String, String>>> in
332
- let __promise = Promise<Promise<Dictionary<String, String>>>()
333
- let __resolver = { (__result: Promise<Dictionary<String, String>>) in
334
- __promise.resolve(withResult: __result)
335
- }
336
- let __rejecter = { (__error: Error) in
337
- __promise.reject(withError: __error)
338
- }
339
- let __resolverCpp = { () -> bridge.Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___ in
340
- let __closureWrapper = Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___(__resolver)
341
- return bridge.create_Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___(__closureWrapper.toUnsafe())
342
- }()
343
- let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in
344
- let __closureWrapper = Func_void_std__exception_ptr(__rejecter)
345
- return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe())
346
- }()
347
- let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(__result)
348
- __promiseHolder.addOnResolvedListener(__resolverCpp)
349
- __promiseHolder.addOnRejectedListener(__rejecterCpp)
350
- return __promise
351
- }()
352
- }
353
- }()
354
- } else {
355
- return nil
356
- }
357
- }()
358
- }
359
-
360
313
  @inline(__always)
361
314
  var mock: SseMockConfig? {
362
315
  return self.__mock.value
@@ -28,6 +28,8 @@ namespace margelo::nitro::nitrosse { enum class SseState; }
28
28
  #include <functional>
29
29
  #include <string>
30
30
  #include <unordered_map>
31
+ #include <NitroModules/Promise.hpp>
32
+ #include <optional>
31
33
  #include "SseStats.hpp"
32
34
  #include "SseState.hpp"
33
35
 
@@ -62,7 +64,7 @@ namespace margelo::nitro::nitrosse {
62
64
 
63
65
  public:
64
66
  // Methods
65
- virtual void setup(const SseConfig& config, const std::function<void(const std::vector<SseEvent>& /* events */)>& onEvent) = 0;
67
+ virtual void setup(const SseConfig& config, const std::function<void(const std::vector<SseEvent>& /* events */)>& onEvent, const std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>& onBeforeRequest) = 0;
66
68
  virtual void start() = 0;
67
69
  virtual void stop() = 0;
68
70
  virtual void setLastProcessedId(const std::string& id) = 0;
@@ -37,8 +37,6 @@ namespace margelo::nitro::nitrosse { struct SseMockConfig; }
37
37
  #include "HttpMethod.hpp"
38
38
  #include <optional>
39
39
  #include <unordered_map>
40
- #include <NitroModules/Promise.hpp>
41
- #include <functional>
42
40
  #include "SseMockConfig.hpp"
43
41
 
44
42
  namespace margelo::nitro::nitrosse {
@@ -64,15 +62,14 @@ namespace margelo::nitro::nitrosse {
64
62
  std::optional<double> maxAuthRetries SWIFT_PRIVATE;
65
63
  std::optional<bool> autoParseJSON SWIFT_PRIVATE;
66
64
  std::optional<bool> monitorNetwork SWIFT_PRIVATE;
67
- std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>> onBeforeRequest SWIFT_PRIVATE;
68
65
  std::optional<SseMockConfig> mock SWIFT_PRIVATE;
69
66
 
70
67
  public:
71
68
  SseConfig() = default;
72
- 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<double> maxAuthRetries, 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), maxAuthRetries(maxAuthRetries), autoParseJSON(autoParseJSON), monitorNetwork(monitorNetwork), onBeforeRequest(onBeforeRequest), mock(mock) {}
69
+ 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<double> maxAuthRetries, std::optional<bool> autoParseJSON, std::optional<bool> monitorNetwork, 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), maxAuthRetries(maxAuthRetries), autoParseJSON(autoParseJSON), monitorNetwork(monitorNetwork), mock(mock) {}
73
70
 
74
71
  public:
75
- // SseConfig is not equatable because these properties are not equatable: onBeforeRequest
72
+ friend bool operator==(const SseConfig& lhs, const SseConfig& rhs) = default;
76
73
  };
77
74
 
78
75
  } // namespace margelo::nitro::nitrosse
@@ -101,7 +98,6 @@ namespace margelo::nitro {
101
98
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxAuthRetries"))),
102
99
  JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON"))),
103
100
  JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "monitorNetwork"))),
104
- 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"))),
105
101
  JSIConverter<std::optional<margelo::nitro::nitrosse::SseMockConfig>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mock")))
106
102
  );
107
103
  }
@@ -123,7 +119,6 @@ namespace margelo::nitro {
123
119
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxAuthRetries"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxAuthRetries));
124
120
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.autoParseJSON));
125
121
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "monitorNetwork"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.monitorNetwork));
126
- 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));
127
122
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "mock"), JSIConverter<std::optional<margelo::nitro::nitrosse::SseMockConfig>>::toJSI(runtime, arg.mock));
128
123
  return obj;
129
124
  }
@@ -151,7 +146,6 @@ namespace margelo::nitro {
151
146
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxAuthRetries")))) return false;
152
147
  if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON")))) return false;
153
148
  if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "monitorNetwork")))) return false;
154
- 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;
155
149
  if (!JSIConverter<std::optional<margelo::nitro::nitrosse::SseMockConfig>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mock")))) return false;
156
150
  return true;
157
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-sse",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0",
4
4
  "description": "High-performance Server-Sent Events (SSE) for React Native, powered by Nitro Modules.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",