react-native-nitro-sse 2.4.0 → 2.4.2

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 (38) hide show
  1. package/android/src/main/java/com/margelo/nitro/nitrosse/NetworkInspector.kt +0 -2
  2. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +41 -23
  3. package/android/src/main/java/com/margelo/nitro/nitrosse/SseConnectionHandler.kt +2 -2
  4. package/android/src/main/java/com/margelo/nitro/nitrosse/SseEventBuffer.kt +0 -3
  5. package/android/src/main/java/com/margelo/nitro/nitrosse/SseReconnectStrategy.kt +4 -0
  6. package/ios/NitroSse.swift +39 -23
  7. package/ios/SseConnectionHandler.swift +26 -3
  8. package/ios/SseNetworkMonitor.swift +3 -2
  9. package/ios/SseReconnectStrategy.swift +5 -0
  10. package/lib/module/MockSseEngine.js +212 -0
  11. package/lib/module/MockSseEngine.js.map +1 -0
  12. package/lib/module/NitroSseClient.js +40 -216
  13. package/lib/module/NitroSseClient.js.map +1 -1
  14. package/lib/module/SseDriver.js +125 -0
  15. package/lib/module/SseDriver.js.map +1 -0
  16. package/lib/module/index.js.map +1 -1
  17. package/lib/typescript/src/MockSseEngine.d.ts +31 -0
  18. package/lib/typescript/src/MockSseEngine.d.ts.map +1 -0
  19. package/lib/typescript/src/NitroSseClient.d.ts +5 -5
  20. package/lib/typescript/src/NitroSseClient.d.ts.map +1 -1
  21. package/lib/typescript/src/SseDriver.d.ts +72 -0
  22. package/lib/typescript/src/SseDriver.d.ts.map +1 -0
  23. package/lib/typescript/src/SseInterface.d.ts +2 -0
  24. package/lib/typescript/src/SseInterface.d.ts.map +1 -1
  25. package/nitrogen/generated/android/c++/JSseConfig.hpp +2 -0
  26. package/nitrogen/generated/android/c++/JSseMockConfig.hpp +2 -0
  27. package/nitrogen/generated/android/c++/JSseMockEvent.hpp +9 -3
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockEvent.kt +9 -4
  29. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +15 -15
  30. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +3 -3
  31. package/nitrogen/generated/ios/swift/SseMockEvent.swift +12 -1
  32. package/nitrogen/generated/shared/c++/SseMockEvent.hpp +9 -2
  33. package/package.json +5 -7
  34. package/src/MockSseEngine.ts +254 -0
  35. package/src/NitroSseClient.ts +54 -237
  36. package/src/SseDriver.ts +161 -0
  37. package/src/SseInterface.ts +2 -0
  38. package/src/index.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"SseInterface.d.ts","sourceRoot":"","sources":["../../../src/SseInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,SAAS,GACT,OAAO,GACP,OAAO,GACP,WAAW,GACX,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,YAAY,GACZ,MAAM,GACN,OAAO,GACP,cAAc,GACd,QAAQ,GACR,QAAQ,GACR,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,oCAAoC;IACpC,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;I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
20
21
  #include "SseEventType.hpp"
21
22
  #include "SseMockConfig.hpp"
22
23
  #include "SseMockEvent.hpp"
23
24
  #include "SseMockMode.hpp"
25
+ #include "SseState.hpp"
24
26
  #include <NitroModules/AnyMap.hpp>
25
27
  #include <NitroModules/JAnyMap.hpp>
26
28
  #include <NitroModules/JNICallable.hpp>
@@ -13,9 +13,11 @@
13
13
  #include "JSseEventType.hpp"
14
14
  #include "JSseMockEvent.hpp"
15
15
  #include "JSseMockMode.hpp"
16
+ #include "JSseState.hpp"
16
17
  #include "SseEventType.hpp"
17
18
  #include "SseMockEvent.hpp"
18
19
  #include "SseMockMode.hpp"
20
+ #include "SseState.hpp"
19
21
  #include <NitroModules/AnyMap.hpp>
20
22
  #include <NitroModules/JAnyMap.hpp>
21
23
  #include <optional>
@@ -11,7 +11,9 @@
11
11
  #include "SseMockEvent.hpp"
12
12
 
13
13
  #include "JSseEventType.hpp"
14
+ #include "JSseState.hpp"
14
15
  #include "SseEventType.hpp"
16
+ #include "SseState.hpp"
15
17
  #include <NitroModules/AnyMap.hpp>
16
18
  #include <NitroModules/JAnyMap.hpp>
17
19
  #include <optional>
@@ -54,6 +56,8 @@ namespace margelo::nitro::nitrosse {
54
56
  jni::local_ref<jni::JDouble> retry = this->getFieldValue(fieldRetry);
55
57
  static const auto fieldDelayMs = clazz->getField<jni::JDouble>("delayMs");
56
58
  jni::local_ref<jni::JDouble> delayMs = this->getFieldValue(fieldDelayMs);
59
+ static const auto fieldState = clazz->getField<JSseState>("state");
60
+ jni::local_ref<JSseState> state = this->getFieldValue(fieldState);
57
61
  return SseMockEvent(
58
62
  type != nullptr ? std::make_optional(type->toCpp()) : std::nullopt,
59
63
  data != nullptr ? std::make_optional(data->toStdString()) : std::nullopt,
@@ -63,7 +67,8 @@ namespace margelo::nitro::nitrosse {
63
67
  message != nullptr ? std::make_optional(message->toStdString()) : std::nullopt,
64
68
  statusCode != nullptr ? std::make_optional(statusCode->value()) : std::nullopt,
65
69
  retry != nullptr ? std::make_optional(retry->value()) : std::nullopt,
66
- delayMs != nullptr ? std::make_optional(delayMs->value()) : std::nullopt
70
+ delayMs != nullptr ? std::make_optional(delayMs->value()) : std::nullopt,
71
+ state != nullptr ? std::make_optional(state->toCpp()) : std::nullopt
67
72
  );
68
73
  }
69
74
 
@@ -73,7 +78,7 @@ namespace margelo::nitro::nitrosse {
73
78
  */
74
79
  [[maybe_unused]]
75
80
  static jni::local_ref<JSseMockEvent::javaobject> fromCpp(const SseMockEvent& value) {
76
- using JSignature = JSseMockEvent(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>, jni::alias_ref<jni::JDouble>);
81
+ using JSignature = JSseMockEvent(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>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JSseState>);
77
82
  static const auto clazz = javaClassStatic();
78
83
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
79
84
  return create(
@@ -86,7 +91,8 @@ namespace margelo::nitro::nitrosse {
86
91
  value.message.has_value() ? jni::make_jstring(value.message.value()) : nullptr,
87
92
  value.statusCode.has_value() ? jni::JDouble::valueOf(value.statusCode.value()) : nullptr,
88
93
  value.retry.has_value() ? jni::JDouble::valueOf(value.retry.value()) : nullptr,
89
- value.delayMs.has_value() ? jni::JDouble::valueOf(value.delayMs.value()) : nullptr
94
+ value.delayMs.has_value() ? jni::JDouble::valueOf(value.delayMs.value()) : nullptr,
95
+ value.state.has_value() ? JSseState::fromCpp(value.state.value()) : nullptr
90
96
  );
91
97
  }
92
98
  };
@@ -44,7 +44,10 @@ data class SseMockEvent(
44
44
  val retry: Double?,
45
45
  @DoNotStrip
46
46
  @Keep
47
- val delayMs: Double?
47
+ val delayMs: Double?,
48
+ @DoNotStrip
49
+ @Keep
50
+ val state: SseState?
48
51
  ) {
49
52
  /* primary constructor */
50
53
 
@@ -60,6 +63,7 @@ data class SseMockEvent(
60
63
  && Objects.deepEquals(this.statusCode, other.statusCode)
61
64
  && Objects.deepEquals(this.retry, other.retry)
62
65
  && Objects.deepEquals(this.delayMs, other.delayMs)
66
+ && Objects.deepEquals(this.state, other.state)
63
67
  }
64
68
 
65
69
  override fun hashCode(): Int {
@@ -72,7 +76,8 @@ data class SseMockEvent(
72
76
  message,
73
77
  statusCode,
74
78
  retry,
75
- delayMs
79
+ delayMs,
80
+ state
76
81
  ).contentDeepHashCode()
77
82
  }
78
83
 
@@ -84,8 +89,8 @@ data class SseMockEvent(
84
89
  @Keep
85
90
  @Suppress("unused")
86
91
  @JvmStatic
87
- private fun fromCpp(type: SseEventType?, data: String?, parsedData: AnyMap?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?, delayMs: Double?): SseMockEvent {
88
- return SseMockEvent(type, data, parsedData, id, event, message, statusCode, retry, delayMs)
92
+ private fun fromCpp(type: SseEventType?, data: String?, parsedData: AnyMap?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?, delayMs: Double?, state: SseState?): SseMockEvent {
93
+ return SseMockEvent(type, data, parsedData, id, event, message, statusCode, retry, delayMs, state)
89
94
  }
90
95
  }
91
96
  }
@@ -317,6 +317,21 @@ namespace margelo::nitro::nitrosse::bridge::swift {
317
317
  return optional.value();
318
318
  }
319
319
 
320
+ // pragma MARK: std::optional<SseState>
321
+ /**
322
+ * Specialized version of `std::optional<SseState>`.
323
+ */
324
+ using std__optional_SseState_ = std::optional<SseState>;
325
+ inline std::optional<SseState> create_std__optional_SseState_(const SseState& value) noexcept {
326
+ return std::optional<SseState>(value);
327
+ }
328
+ inline bool has_value_std__optional_SseState_(const std::optional<SseState>& optional) noexcept {
329
+ return optional.has_value();
330
+ }
331
+ inline SseState get_std__optional_SseState_(const std::optional<SseState>& optional) noexcept {
332
+ return optional.value();
333
+ }
334
+
320
335
  // pragma MARK: std::vector<SseMockEvent>
321
336
  /**
322
337
  * Specialized version of `std::vector<SseMockEvent>`.
@@ -343,21 +358,6 @@ namespace margelo::nitro::nitrosse::bridge::swift {
343
358
  return optional.value();
344
359
  }
345
360
 
346
- // pragma MARK: std::optional<SseState>
347
- /**
348
- * Specialized version of `std::optional<SseState>`.
349
- */
350
- using std__optional_SseState_ = std::optional<SseState>;
351
- inline std::optional<SseState> create_std__optional_SseState_(const SseState& value) noexcept {
352
- return std::optional<SseState>(value);
353
- }
354
- inline bool has_value_std__optional_SseState_(const std::optional<SseState>& optional) noexcept {
355
- return optional.has_value();
356
- }
357
- inline SseState get_std__optional_SseState_(const std::optional<SseState>& optional) noexcept {
358
- return optional.value();
359
- }
360
-
361
361
  // pragma MARK: std::vector<SseEvent>
362
362
  /**
363
363
  * Specialized version of `std::vector<SseEvent>`.
@@ -24,10 +24,10 @@ namespace margelo::nitro::nitrosse { enum class SseMockMode; }
24
24
  namespace margelo::nitro::nitrosse { struct SseMockEvent; }
25
25
  // Forward declaration of `SseEventType` to properly resolve imports.
26
26
  namespace margelo::nitro::nitrosse { enum class SseEventType; }
27
- // Forward declaration of `SseEvent` to properly resolve imports.
28
- namespace margelo::nitro::nitrosse { struct SseEvent; }
29
27
  // Forward declaration of `SseState` to properly resolve imports.
30
28
  namespace margelo::nitro::nitrosse { enum class SseState; }
29
+ // Forward declaration of `SseEvent` to properly resolve imports.
30
+ namespace margelo::nitro::nitrosse { struct SseEvent; }
31
31
  // Forward declaration of `SseStats` to properly resolve imports.
32
32
  namespace margelo::nitro::nitrosse { struct SseStats; }
33
33
 
@@ -44,8 +44,8 @@ namespace margelo::nitro::nitrosse { struct SseStats; }
44
44
  #include <vector>
45
45
  #include "SseEventType.hpp"
46
46
  #include <NitroModules/AnyMap.hpp>
47
- #include "SseEvent.hpp"
48
47
  #include "SseState.hpp"
48
+ #include "SseEvent.hpp"
49
49
  #include "SseStats.hpp"
50
50
 
51
51
  #include "NitroSse-Swift-Cxx-Umbrella.hpp"
@@ -18,7 +18,7 @@ public extension SseMockEvent {
18
18
  /**
19
19
  * Create a new instance of `SseMockEvent`.
20
20
  */
21
- init(type: SseEventType?, data: String?, parsedData: AnyMap?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?, delayMs: Double?) {
21
+ init(type: SseEventType?, data: String?, parsedData: AnyMap?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?, delayMs: Double?, state: SseState?) {
22
22
  self.init({ () -> bridge.std__optional_SseEventType_ in
23
23
  if let __unwrappedValue = type {
24
24
  return bridge.create_std__optional_SseEventType_(__unwrappedValue)
@@ -73,6 +73,12 @@ public extension SseMockEvent {
73
73
  } else {
74
74
  return .init()
75
75
  }
76
+ }(), { () -> bridge.std__optional_SseState_ in
77
+ if let __unwrappedValue = state {
78
+ return bridge.create_std__optional_SseState_(__unwrappedValue)
79
+ } else {
80
+ return .init()
81
+ }
76
82
  }())
77
83
  }
78
84
 
@@ -176,4 +182,9 @@ public extension SseMockEvent {
176
182
  }
177
183
  }()
178
184
  }
185
+
186
+ @inline(__always)
187
+ var state: SseState? {
188
+ return self.__state.value
189
+ }
179
190
  }
@@ -30,11 +30,14 @@
30
30
 
31
31
  // Forward declaration of `SseEventType` to properly resolve imports.
32
32
  namespace margelo::nitro::nitrosse { enum class SseEventType; }
33
+ // Forward declaration of `SseState` to properly resolve imports.
34
+ namespace margelo::nitro::nitrosse { enum class SseState; }
33
35
 
34
36
  #include "SseEventType.hpp"
35
37
  #include <optional>
36
38
  #include <string>
37
39
  #include <NitroModules/AnyMap.hpp>
40
+ #include "SseState.hpp"
38
41
 
39
42
  namespace margelo::nitro::nitrosse {
40
43
 
@@ -52,10 +55,11 @@ namespace margelo::nitro::nitrosse {
52
55
  std::optional<double> statusCode SWIFT_PRIVATE;
53
56
  std::optional<double> retry SWIFT_PRIVATE;
54
57
  std::optional<double> delayMs SWIFT_PRIVATE;
58
+ std::optional<SseState> state SWIFT_PRIVATE;
55
59
 
56
60
  public:
57
61
  SseMockEvent() = default;
58
- explicit SseMockEvent(std::optional<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, std::optional<double> delayMs): type(type), data(data), parsedData(parsedData), id(id), event(event), message(message), statusCode(statusCode), retry(retry), delayMs(delayMs) {}
62
+ explicit SseMockEvent(std::optional<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, std::optional<double> delayMs, std::optional<SseState> state): type(type), data(data), parsedData(parsedData), id(id), event(event), message(message), statusCode(statusCode), retry(retry), delayMs(delayMs), state(state) {}
59
63
 
60
64
  public:
61
65
  friend bool operator==(const SseMockEvent& lhs, const SseMockEvent& rhs) = default;
@@ -79,7 +83,8 @@ namespace margelo::nitro {
79
83
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message"))),
80
84
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusCode"))),
81
85
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retry"))),
82
- JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "delayMs")))
86
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "delayMs"))),
87
+ JSIConverter<std::optional<margelo::nitro::nitrosse::SseState>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "state")))
83
88
  );
84
89
  }
85
90
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrosse::SseMockEvent& arg) {
@@ -93,6 +98,7 @@ namespace margelo::nitro {
93
98
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "statusCode"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.statusCode));
94
99
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "retry"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.retry));
95
100
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "delayMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.delayMs));
101
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "state"), JSIConverter<std::optional<margelo::nitro::nitrosse::SseState>>::toJSI(runtime, arg.state));
96
102
  return obj;
97
103
  }
98
104
  static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -112,6 +118,7 @@ namespace margelo::nitro {
112
118
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusCode")))) return false;
113
119
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retry")))) return false;
114
120
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "delayMs")))) return false;
121
+ if (!JSIConverter<std::optional<margelo::nitro::nitrosse::SseState>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "state")))) return false;
115
122
  return true;
116
123
  }
117
124
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "react-native-nitro-sse",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
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",
7
7
  "exports": {
8
8
  ".": {
9
- "source": "./src/index.tsx",
9
+ "source": "./src/index.ts",
10
10
  "types": "./lib/typescript/src/index.d.ts",
11
11
  "default": "./lib/module/index.js"
12
12
  },
@@ -17,11 +17,9 @@
17
17
  "lib",
18
18
  "android",
19
19
  "ios",
20
- "cpp",
21
20
  "nitrogen",
22
21
  "nitro.json",
23
22
  "*.podspec",
24
- "react-native.config.js",
25
23
  "!ios/build",
26
24
  "!ios/Tests",
27
25
  "!android/build",
@@ -42,10 +40,10 @@
42
40
  "nitrogen": "nitrogen",
43
41
  "typecheck": "tsc",
44
42
  "test": "jest",
45
- "test:android": "cd example/android && ./gradlew :react-native-nitro-sse:testDebugUnitTest",
46
- "test:ios": "cd example/ios && xcodebuild test -workspace NitroSseExample.xcworkspace -scheme NitroSse -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16e'",
43
+ "test:android": "(cd example/android && ./gradlew :react-native-nitro-sse:testDebugUnitTest)",
44
+ "test:ios": "(cd example/ios && xcodebuild test -workspace NitroSseExample.xcworkspace -scheme NitroSse -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 16e')",
47
45
  "test:native": "yarn test:android && yarn test:ios",
48
- "ci": "yarn lint && yarn typecheck && yarn test && yarn prepare && yarn test:native && yarn turbo run build:android build:ios",
46
+ "ci": "yarn lint && yarn typecheck && yarn test && yarn prepare && (cd example/ios && pod install) && yarn test:native && yarn turbo run build:android build:ios",
49
47
  "release": "release-it --only-version",
50
48
  "server": "node example/sse-server.js",
51
49
  "lint": "eslint \"**/*.{js,ts,tsx}\""
@@ -0,0 +1,254 @@
1
+ import type {
2
+ SseEvent,
3
+ SseMockConfig,
4
+ SseMockEvent,
5
+ SseState,
6
+ SseStats,
7
+ } from './SseInterface';
8
+
9
+ /**
10
+ * Encapsulates mock streaming logic for testing and offline simulation.
11
+ * Handles timer intervals, looping, custom delays, simulated error rates, and mock state tracking.
12
+ */
13
+ export class MockSseEngine {
14
+ private _config: SseMockConfig;
15
+ private _emitEvents: (events: SseEvent[]) => void;
16
+ private _mockIntervalId?: ReturnType<typeof setTimeout>;
17
+ private _mockIndex: number = 0;
18
+ private _mockState?: SseState;
19
+
20
+ constructor(config: SseMockConfig, emitEvents: (events: SseEvent[]) => void) {
21
+ this._config = config;
22
+ this._emitEvents = emitEvents;
23
+ }
24
+
25
+ /**
26
+ * Transforms a raw mock event definition or partial SSE event into a full SseEvent DTO.
27
+ */
28
+ static createSseEvent(
29
+ rawMock: Partial<SseMockEvent> | Partial<SseEvent>
30
+ ): SseEvent {
31
+ return {
32
+ type: rawMock.type ?? 'message',
33
+ data: rawMock.data,
34
+ parsedData: rawMock.parsedData,
35
+ id: rawMock.id,
36
+ event: rawMock.event,
37
+ message: rawMock.message,
38
+ statusCode: rawMock.statusCode ?? 200,
39
+ retry: rawMock.retry,
40
+ state: rawMock.state,
41
+ };
42
+ }
43
+
44
+ private _setMockState(state: SseState): void {
45
+ if (this._mockState !== state) {
46
+ this._mockState = state;
47
+ const stateEvent: SseEvent = { type: 'state', state, statusCode: 200 };
48
+ this._emitEvents([stateEvent]);
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Starts mock stream scheduling.
54
+ * @returns true if native stream should be skipped (replace mode), false otherwise (inject mode).
55
+ */
56
+ start(): boolean {
57
+ if (this._mockIntervalId) {
58
+ clearTimeout(this._mockIntervalId);
59
+ this._mockIntervalId = undefined;
60
+ }
61
+
62
+ const {
63
+ mode,
64
+ data,
65
+ eventsPerSecond = 1,
66
+ loop = false,
67
+ errorRate = 0,
68
+ } = this._config;
69
+ this._mockIndex = 0;
70
+
71
+ // Validate and normalize eventsPerSecond (must be a finite positive number, default to 1)
72
+ let validatedEventsPerSecond = Number(eventsPerSecond);
73
+ if (
74
+ Number.isNaN(validatedEventsPerSecond) ||
75
+ !Number.isFinite(validatedEventsPerSecond) ||
76
+ validatedEventsPerSecond <= 0
77
+ ) {
78
+ validatedEventsPerSecond = 1;
79
+ }
80
+
81
+ // Validate and normalize errorRate (must be a finite number within [0,1], default to 0)
82
+ let validatedErrorRate = Number(errorRate);
83
+ if (
84
+ Number.isNaN(validatedErrorRate) ||
85
+ !Number.isFinite(validatedErrorRate)
86
+ ) {
87
+ validatedErrorRate = 0;
88
+ } else {
89
+ validatedErrorRate = Math.max(0, Math.min(1, validatedErrorRate));
90
+ }
91
+
92
+ const delayMs = 1000 / validatedEventsPerSecond;
93
+ // Safeguard: if eventsPerSecond is huge (e.g. 1000), setInterval/setTimeout is too slow.
94
+ // We batch events together in chunks if the calculated interval is under 10ms.
95
+ const batchSize = Math.max(1, Math.round(validatedEventsPerSecond / 100)); // chunk size for 10ms intervals
96
+ const intervalMs = Math.max(10, delayMs * batchSize);
97
+
98
+ const scheduleNext = () => {
99
+ if (this._mockIndex >= data.length) {
100
+ if (loop && data.length > 0) {
101
+ this._mockIndex = 0;
102
+ } else {
103
+ if (this._mockIntervalId) {
104
+ clearTimeout(this._mockIntervalId);
105
+ this._mockIntervalId = undefined;
106
+ }
107
+ if (mode === 'replace') {
108
+ this._setMockState('closed');
109
+ const closeEvent: SseEvent = { type: 'close', statusCode: 200 };
110
+ this._emitEvents([closeEvent]);
111
+ }
112
+ return;
113
+ }
114
+ }
115
+
116
+ // Simulate connection drops
117
+ if (validatedErrorRate && Math.random() < validatedErrorRate) {
118
+ if (mode === 'replace') {
119
+ this._setMockState('reconnecting');
120
+ }
121
+ const errorEvent: SseEvent = {
122
+ type: 'error',
123
+ message: 'Mock Connection Drop (Simulated Error)',
124
+ statusCode: 500,
125
+ };
126
+ this._emitEvents([errorEvent]);
127
+
128
+ // Retry / reconnect delay simulator (e.g. 2000ms)
129
+ this._mockIntervalId = setTimeout(scheduleNext, 2000);
130
+ return;
131
+ }
132
+
133
+ const currentItem = data[this._mockIndex];
134
+ const hasCustomDelay =
135
+ currentItem && typeof currentItem.delayMs === 'number';
136
+
137
+ const batch: SseEvent[] = [];
138
+ if (hasCustomDelay) {
139
+ const rawMock = data[this._mockIndex++];
140
+ if (rawMock) {
141
+ batch.push(MockSseEngine.createSseEvent(rawMock));
142
+ }
143
+ } else {
144
+ for (let i = 0; i < batchSize && this._mockIndex < data.length; i++) {
145
+ const nextItem = data[this._mockIndex];
146
+ if (nextItem && typeof nextItem.delayMs === 'number') {
147
+ break;
148
+ }
149
+ const rawMock = data[this._mockIndex++];
150
+ if (rawMock) {
151
+ batch.push(MockSseEngine.createSseEvent(rawMock));
152
+ }
153
+ }
154
+ }
155
+
156
+ if (batch.length > 0) {
157
+ if (mode === 'replace') {
158
+ this._setMockState('open');
159
+ }
160
+ this._emitEvents(batch);
161
+ }
162
+
163
+ if (this._mockIndex >= data.length) {
164
+ if (loop && data.length > 0) {
165
+ const nextItem = data[0];
166
+ const nextDelay =
167
+ nextItem && typeof nextItem.delayMs === 'number'
168
+ ? nextItem.delayMs
169
+ : intervalMs;
170
+ this._mockIntervalId = setTimeout(scheduleNext, nextDelay);
171
+ } else {
172
+ this._mockIntervalId = setTimeout(scheduleNext, 0);
173
+ }
174
+ } else {
175
+ const nextItem = data[this._mockIndex];
176
+ const nextDelay =
177
+ nextItem && typeof nextItem.delayMs === 'number'
178
+ ? nextItem.delayMs
179
+ : intervalMs;
180
+ this._mockIntervalId = setTimeout(scheduleNext, nextDelay);
181
+ }
182
+ };
183
+
184
+ const firstItem = data[0];
185
+ const firstDelay =
186
+ firstItem && typeof firstItem.delayMs === 'number'
187
+ ? firstItem.delayMs
188
+ : intervalMs;
189
+
190
+ if (mode === 'replace') {
191
+ this._setMockState('connecting');
192
+ this._setMockState('open');
193
+
194
+ // Emit simulated open event
195
+ const openEvent: SseEvent = { type: 'open', statusCode: 200 };
196
+ this._emitEvents([openEvent]);
197
+
198
+ this._mockIntervalId = setTimeout(scheduleNext, firstDelay);
199
+ return true; // Indicates replace mode (skip native start)
200
+ } else if (mode === 'inject') {
201
+ this._mockIntervalId = setTimeout(scheduleNext, firstDelay);
202
+ return false; // Indicates inject mode (continue native start)
203
+ }
204
+
205
+ return false;
206
+ }
207
+
208
+ stop(): void {
209
+ if (this._mockIntervalId) {
210
+ clearTimeout(this._mockIntervalId);
211
+ this._mockIntervalId = undefined;
212
+ }
213
+ if (this._config.mode === 'replace') {
214
+ this._setMockState('closed');
215
+ }
216
+ }
217
+
218
+ restart(): void {
219
+ this.stop();
220
+ this.start();
221
+ }
222
+
223
+ isConnected(): boolean {
224
+ return (
225
+ this._mockState === 'open' ||
226
+ this._mockState === 'connecting' ||
227
+ this._mockState === 'reconnecting'
228
+ );
229
+ }
230
+
231
+ getStats(): SseStats {
232
+ return {
233
+ totalBytesReceived: this._mockIndex * 150,
234
+ reconnectCount: 0,
235
+ };
236
+ }
237
+
238
+ getState(): SseState {
239
+ return this._mockState ?? 'idle';
240
+ }
241
+
242
+ resetState(): void {
243
+ this._mockState = undefined;
244
+ if (this._mockIntervalId) {
245
+ clearTimeout(this._mockIntervalId);
246
+ this._mockIntervalId = undefined;
247
+ }
248
+ }
249
+
250
+ injectEvent(event: Partial<SseEvent>): void {
251
+ const sseEvent = MockSseEngine.createSseEvent(event);
252
+ this._emitEvents([sseEvent]);
253
+ }
254
+ }