react-native-nitro-sse 2.2.3 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/ios/NitroSse.swift +55 -9
  2. package/lib/module/NitroSseClient.js +171 -2
  3. package/lib/module/NitroSseClient.js.map +1 -1
  4. package/lib/typescript/src/NitroSseClient.d.ts +5 -0
  5. package/lib/typescript/src/NitroSseClient.d.ts.map +1 -1
  6. package/lib/typescript/src/SseInterface.d.ts +61 -0
  7. package/lib/typescript/src/SseInterface.d.ts.map +1 -1
  8. package/nitrogen/generated/android/c++/JFunc_void_std__vector_SseEvent_.hpp +14 -14
  9. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +17 -5
  10. package/nitrogen/generated/android/c++/JSseConfig.hpp +18 -3
  11. package/nitrogen/generated/android/c++/JSseMockConfig.hpp +101 -0
  12. package/nitrogen/generated/android/c++/JSseMockEvent.hpp +94 -0
  13. package/nitrogen/generated/android/c++/JSseMockMode.hpp +58 -0
  14. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +53 -5
  15. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEvent.kt +27 -0
  16. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockConfig.kt +71 -0
  17. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockEvent.kt +91 -0
  18. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockMode.kt +23 -0
  19. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseStats.kt +19 -0
  20. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +50 -0
  21. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +9 -0
  22. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +12 -3
  23. package/nitrogen/generated/ios/swift/SseConfig.swift +12 -1
  24. package/nitrogen/generated/ios/swift/SseMockConfig.swift +94 -0
  25. package/nitrogen/generated/ios/swift/SseMockEvent.swift +179 -0
  26. package/nitrogen/generated/ios/swift/SseMockMode.swift +40 -0
  27. package/nitrogen/generated/shared/c++/SseConfig.hpp +9 -2
  28. package/nitrogen/generated/shared/c++/SseMockConfig.hpp +105 -0
  29. package/nitrogen/generated/shared/c++/SseMockEvent.hpp +119 -0
  30. package/nitrogen/generated/shared/c++/SseMockMode.hpp +76 -0
  31. package/package.json +12 -10
  32. package/src/NitroSseClient.ts +203 -2
  33. package/src/SseInterface.ts +64 -0
@@ -18,6 +18,12 @@ namespace margelo::nitro::nitrosse { struct SseConfig; }
18
18
  namespace margelo::nitro::nitrosse { enum class SseEventType; }
19
19
  // Forward declaration of `SseEvent` to properly resolve imports.
20
20
  namespace margelo::nitro::nitrosse { struct SseEvent; }
21
+ // Forward declaration of `SseMockConfig` to properly resolve imports.
22
+ namespace margelo::nitro::nitrosse { struct SseMockConfig; }
23
+ // Forward declaration of `SseMockEvent` to properly resolve imports.
24
+ namespace margelo::nitro::nitrosse { struct SseMockEvent; }
25
+ // Forward declaration of `SseMockMode` to properly resolve imports.
26
+ namespace margelo::nitro::nitrosse { enum class SseMockMode; }
21
27
  // Forward declaration of `SseStats` to properly resolve imports.
22
28
  namespace margelo::nitro::nitrosse { struct SseStats; }
23
29
 
@@ -27,6 +33,9 @@ namespace margelo::nitro::nitrosse { struct SseStats; }
27
33
  #include "SseConfig.hpp"
28
34
  #include "SseEvent.hpp"
29
35
  #include "SseEventType.hpp"
36
+ #include "SseMockConfig.hpp"
37
+ #include "SseMockEvent.hpp"
38
+ #include "SseMockMode.hpp"
30
39
  #include "SseStats.hpp"
31
40
  #include <NitroModules/AnyMap.hpp>
32
41
  #include <NitroModules/Promise.hpp>
@@ -16,10 +16,16 @@ namespace NitroSse { class HybridNitroSseSpec_cxx; }
16
16
  namespace margelo::nitro::nitrosse { struct SseConfig; }
17
17
  // Forward declaration of `HttpMethod` to properly resolve imports.
18
18
  namespace margelo::nitro::nitrosse { enum class HttpMethod; }
19
- // Forward declaration of `SseEvent` to properly resolve imports.
20
- namespace margelo::nitro::nitrosse { struct SseEvent; }
19
+ // Forward declaration of `SseMockConfig` to properly resolve imports.
20
+ namespace margelo::nitro::nitrosse { struct SseMockConfig; }
21
+ // Forward declaration of `SseMockMode` to properly resolve imports.
22
+ namespace margelo::nitro::nitrosse { enum class SseMockMode; }
23
+ // Forward declaration of `SseMockEvent` to properly resolve imports.
24
+ namespace margelo::nitro::nitrosse { struct SseMockEvent; }
21
25
  // Forward declaration of `SseEventType` to properly resolve imports.
22
26
  namespace margelo::nitro::nitrosse { enum class SseEventType; }
27
+ // Forward declaration of `SseEvent` to properly resolve imports.
28
+ namespace margelo::nitro::nitrosse { struct SseEvent; }
23
29
  // Forward declaration of `SseStats` to properly resolve imports.
24
30
  namespace margelo::nitro::nitrosse { struct SseStats; }
25
31
 
@@ -30,10 +36,13 @@ namespace margelo::nitro::nitrosse { struct SseStats; }
30
36
  #include <unordered_map>
31
37
  #include <NitroModules/Promise.hpp>
32
38
  #include <functional>
33
- #include "SseEvent.hpp"
39
+ #include "SseMockConfig.hpp"
40
+ #include "SseMockMode.hpp"
41
+ #include "SseMockEvent.hpp"
34
42
  #include <vector>
35
43
  #include "SseEventType.hpp"
36
44
  #include <NitroModules/AnyMap.hpp>
45
+ #include "SseEvent.hpp"
37
46
  #include "SseStats.hpp"
38
47
 
39
48
  #include "NitroSse-Swift-Cxx-Umbrella.hpp"
@@ -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?, autoParseJSON: Bool?, monitorNetwork: Bool?, onBeforeRequest: (() -> Promise<Promise<Dictionary<String, String>>>)?) {
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?, autoParseJSON: Bool?, monitorNetwork: Bool?, onBeforeRequest: (() -> Promise<Promise<Dictionary<String, String>>>)?, 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)
@@ -118,6 +118,12 @@ public extension SseConfig {
118
118
  } else {
119
119
  return .init()
120
120
  }
121
+ }(), { () -> bridge.std__optional_SseMockConfig_ in
122
+ if let __unwrappedValue = mock {
123
+ return bridge.create_std__optional_SseMockConfig_(__unwrappedValue)
124
+ } else {
125
+ return .init()
126
+ }
121
127
  }())
122
128
  }
123
129
 
@@ -332,4 +338,9 @@ public extension SseConfig {
332
338
  }
333
339
  }()
334
340
  }
341
+
342
+ @inline(__always)
343
+ var mock: SseMockConfig? {
344
+ return self.__mock.value
345
+ }
335
346
  }
@@ -0,0 +1,94 @@
1
+ ///
2
+ /// SseMockConfig.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `SseMockConfig`, backed by a C++ struct.
12
+ */
13
+ public typealias SseMockConfig = margelo.nitro.nitrosse.SseMockConfig
14
+
15
+ public extension SseMockConfig {
16
+ private typealias bridge = margelo.nitro.nitrosse.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `SseMockConfig`.
20
+ */
21
+ init(mode: SseMockMode, data: [SseMockEvent], eventsPerSecond: Double?, loop: Bool?, errorRate: Double?) {
22
+ self.init(mode, { () -> bridge.std__vector_SseMockEvent_ in
23
+ var __vector = bridge.create_std__vector_SseMockEvent_(data.count)
24
+ for __item in data {
25
+ __vector.push_back(__item)
26
+ }
27
+ return __vector
28
+ }(), { () -> bridge.std__optional_double_ in
29
+ if let __unwrappedValue = eventsPerSecond {
30
+ return bridge.create_std__optional_double_(__unwrappedValue)
31
+ } else {
32
+ return .init()
33
+ }
34
+ }(), { () -> bridge.std__optional_bool_ in
35
+ if let __unwrappedValue = loop {
36
+ return bridge.create_std__optional_bool_(__unwrappedValue)
37
+ } else {
38
+ return .init()
39
+ }
40
+ }(), { () -> bridge.std__optional_double_ in
41
+ if let __unwrappedValue = errorRate {
42
+ return bridge.create_std__optional_double_(__unwrappedValue)
43
+ } else {
44
+ return .init()
45
+ }
46
+ }())
47
+ }
48
+
49
+ @inline(__always)
50
+ var mode: SseMockMode {
51
+ return self.__mode
52
+ }
53
+
54
+ @inline(__always)
55
+ var data: [SseMockEvent] {
56
+ return self.__data.map({ __item in __item })
57
+ }
58
+
59
+ @inline(__always)
60
+ var eventsPerSecond: Double? {
61
+ return { () -> Double? in
62
+ if bridge.has_value_std__optional_double_(self.__eventsPerSecond) {
63
+ let __unwrapped = bridge.get_std__optional_double_(self.__eventsPerSecond)
64
+ return __unwrapped
65
+ } else {
66
+ return nil
67
+ }
68
+ }()
69
+ }
70
+
71
+ @inline(__always)
72
+ var loop: Bool? {
73
+ return { () -> Bool? in
74
+ if bridge.has_value_std__optional_bool_(self.__loop) {
75
+ let __unwrapped = bridge.get_std__optional_bool_(self.__loop)
76
+ return __unwrapped
77
+ } else {
78
+ return nil
79
+ }
80
+ }()
81
+ }
82
+
83
+ @inline(__always)
84
+ var errorRate: Double? {
85
+ return { () -> Double? in
86
+ if bridge.has_value_std__optional_double_(self.__errorRate) {
87
+ let __unwrapped = bridge.get_std__optional_double_(self.__errorRate)
88
+ return __unwrapped
89
+ } else {
90
+ return nil
91
+ }
92
+ }()
93
+ }
94
+ }
@@ -0,0 +1,179 @@
1
+ ///
2
+ /// SseMockEvent.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `SseMockEvent`, backed by a C++ struct.
12
+ */
13
+ public typealias SseMockEvent = margelo.nitro.nitrosse.SseMockEvent
14
+
15
+ public extension SseMockEvent {
16
+ private typealias bridge = margelo.nitro.nitrosse.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `SseMockEvent`.
20
+ */
21
+ init(type: SseEventType?, data: String?, parsedData: AnyMap?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?, delayMs: Double?) {
22
+ self.init({ () -> bridge.std__optional_SseEventType_ in
23
+ if let __unwrappedValue = type {
24
+ return bridge.create_std__optional_SseEventType_(__unwrappedValue)
25
+ } else {
26
+ return .init()
27
+ }
28
+ }(), { () -> bridge.std__optional_std__string_ in
29
+ if let __unwrappedValue = data {
30
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
31
+ } else {
32
+ return .init()
33
+ }
34
+ }(), { () -> bridge.std__optional_std__shared_ptr_AnyMap__ in
35
+ if let __unwrappedValue = parsedData {
36
+ return bridge.create_std__optional_std__shared_ptr_AnyMap__(__unwrappedValue.cppPart)
37
+ } else {
38
+ return .init()
39
+ }
40
+ }(), { () -> bridge.std__optional_std__string_ in
41
+ if let __unwrappedValue = id {
42
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
43
+ } else {
44
+ return .init()
45
+ }
46
+ }(), { () -> bridge.std__optional_std__string_ in
47
+ if let __unwrappedValue = event {
48
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
49
+ } else {
50
+ return .init()
51
+ }
52
+ }(), { () -> bridge.std__optional_std__string_ in
53
+ if let __unwrappedValue = message {
54
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
55
+ } else {
56
+ return .init()
57
+ }
58
+ }(), { () -> bridge.std__optional_double_ in
59
+ if let __unwrappedValue = statusCode {
60
+ return bridge.create_std__optional_double_(__unwrappedValue)
61
+ } else {
62
+ return .init()
63
+ }
64
+ }(), { () -> bridge.std__optional_double_ in
65
+ if let __unwrappedValue = retry {
66
+ return bridge.create_std__optional_double_(__unwrappedValue)
67
+ } else {
68
+ return .init()
69
+ }
70
+ }(), { () -> bridge.std__optional_double_ in
71
+ if let __unwrappedValue = delayMs {
72
+ return bridge.create_std__optional_double_(__unwrappedValue)
73
+ } else {
74
+ return .init()
75
+ }
76
+ }())
77
+ }
78
+
79
+ @inline(__always)
80
+ var type: SseEventType? {
81
+ return self.__type.value
82
+ }
83
+
84
+ @inline(__always)
85
+ var data: String? {
86
+ return { () -> String? in
87
+ if bridge.has_value_std__optional_std__string_(self.__data) {
88
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__data)
89
+ return String(__unwrapped)
90
+ } else {
91
+ return nil
92
+ }
93
+ }()
94
+ }
95
+
96
+ @inline(__always)
97
+ var parsedData: AnyMap? {
98
+ return { () -> AnyMap? in
99
+ if bridge.has_value_std__optional_std__shared_ptr_AnyMap__(self.__parsedData) {
100
+ let __unwrapped = bridge.get_std__optional_std__shared_ptr_AnyMap__(self.__parsedData)
101
+ return AnyMap(withCppPart: __unwrapped)
102
+ } else {
103
+ return nil
104
+ }
105
+ }()
106
+ }
107
+
108
+ @inline(__always)
109
+ var id: String? {
110
+ return { () -> String? in
111
+ if bridge.has_value_std__optional_std__string_(self.__id) {
112
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__id)
113
+ return String(__unwrapped)
114
+ } else {
115
+ return nil
116
+ }
117
+ }()
118
+ }
119
+
120
+ @inline(__always)
121
+ var event: String? {
122
+ return { () -> String? in
123
+ if bridge.has_value_std__optional_std__string_(self.__event) {
124
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__event)
125
+ return String(__unwrapped)
126
+ } else {
127
+ return nil
128
+ }
129
+ }()
130
+ }
131
+
132
+ @inline(__always)
133
+ var message: String? {
134
+ return { () -> String? in
135
+ if bridge.has_value_std__optional_std__string_(self.__message) {
136
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__message)
137
+ return String(__unwrapped)
138
+ } else {
139
+ return nil
140
+ }
141
+ }()
142
+ }
143
+
144
+ @inline(__always)
145
+ var statusCode: Double? {
146
+ return { () -> Double? in
147
+ if bridge.has_value_std__optional_double_(self.__statusCode) {
148
+ let __unwrapped = bridge.get_std__optional_double_(self.__statusCode)
149
+ return __unwrapped
150
+ } else {
151
+ return nil
152
+ }
153
+ }()
154
+ }
155
+
156
+ @inline(__always)
157
+ var retry: Double? {
158
+ return { () -> Double? in
159
+ if bridge.has_value_std__optional_double_(self.__retry) {
160
+ let __unwrapped = bridge.get_std__optional_double_(self.__retry)
161
+ return __unwrapped
162
+ } else {
163
+ return nil
164
+ }
165
+ }()
166
+ }
167
+
168
+ @inline(__always)
169
+ var delayMs: Double? {
170
+ return { () -> Double? in
171
+ if bridge.has_value_std__optional_double_(self.__delayMs) {
172
+ let __unwrapped = bridge.get_std__optional_double_(self.__delayMs)
173
+ return __unwrapped
174
+ } else {
175
+ return nil
176
+ }
177
+ }()
178
+ }
179
+ }
@@ -0,0 +1,40 @@
1
+ ///
2
+ /// SseMockMode.swift
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
+ /**
9
+ * Represents the JS union `SseMockMode`, backed by a C++ enum.
10
+ */
11
+ public typealias SseMockMode = margelo.nitro.nitrosse.SseMockMode
12
+
13
+ public extension SseMockMode {
14
+ /**
15
+ * Get a SseMockMode for the given String value, or
16
+ * return `nil` if the given value was invalid/unknown.
17
+ */
18
+ init?(fromString string: String) {
19
+ switch string {
20
+ case "replace":
21
+ self = .replace
22
+ case "inject":
23
+ self = .inject
24
+ default:
25
+ return nil
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Get the String value this SseMockMode represents.
31
+ */
32
+ var stringValue: String {
33
+ switch self {
34
+ case .replace:
35
+ return "replace"
36
+ case .inject:
37
+ return "inject"
38
+ }
39
+ }
40
+ }
@@ -30,6 +30,8 @@
30
30
 
31
31
  // Forward declaration of `HttpMethod` to properly resolve imports.
32
32
  namespace margelo::nitro::nitrosse { enum class HttpMethod; }
33
+ // Forward declaration of `SseMockConfig` to properly resolve imports.
34
+ namespace margelo::nitro::nitrosse { struct SseMockConfig; }
33
35
 
34
36
  #include <string>
35
37
  #include "HttpMethod.hpp"
@@ -37,6 +39,7 @@ namespace margelo::nitro::nitrosse { enum class HttpMethod; }
37
39
  #include <unordered_map>
38
40
  #include <NitroModules/Promise.hpp>
39
41
  #include <functional>
42
+ #include "SseMockConfig.hpp"
40
43
 
41
44
  namespace margelo::nitro::nitrosse {
42
45
 
@@ -61,10 +64,11 @@ namespace margelo::nitro::nitrosse {
61
64
  std::optional<bool> autoParseJSON SWIFT_PRIVATE;
62
65
  std::optional<bool> monitorNetwork SWIFT_PRIVATE;
63
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;
64
68
 
65
69
  public:
66
70
  SseConfig() = default;
67
- 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): 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) {}
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) {}
68
72
 
69
73
  public:
70
74
  // SseConfig is not equatable because these properties are not equatable: onBeforeRequest
@@ -95,7 +99,8 @@ namespace margelo::nitro {
95
99
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxReconnectAttempts"))),
96
100
  JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON"))),
97
101
  JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "monitorNetwork"))),
98
- 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")))
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")))
99
104
  );
100
105
  }
101
106
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrosse::SseConfig& arg) {
@@ -116,6 +121,7 @@ namespace margelo::nitro {
116
121
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.autoParseJSON));
117
122
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "monitorNetwork"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.monitorNetwork));
118
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));
119
125
  return obj;
120
126
  }
121
127
  static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -142,6 +148,7 @@ namespace margelo::nitro {
142
148
  if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "autoParseJSON")))) return false;
143
149
  if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "monitorNetwork")))) return false;
144
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;
145
152
  return true;
146
153
  }
147
154
  };
@@ -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