react-native-nitro-sse 1.4.0 → 1.5.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 (33) hide show
  1. package/NitroSse.podspec +2 -3
  2. package/README.md +4 -1
  3. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +148 -20
  4. package/android/src/test/java/com/margelo/nitro/nitrosse/NitroSseLogicTest.kt +2 -2
  5. package/ios/NitroSse.swift +178 -46
  6. package/lib/module/index.js +3 -2
  7. package/lib/module/index.js.map +1 -1
  8. package/lib/typescript/src/SseInterface.d.ts +17 -0
  9. package/lib/typescript/src/SseInterface.d.ts.map +1 -1
  10. package/lib/typescript/src/index.d.ts.map +1 -1
  11. package/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp +138 -0
  12. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +5 -2
  13. package/nitrogen/generated/android/c++/JSseConfig.hpp +28 -3
  14. package/nitrogen/generated/android/c++/JSseEvent.hpp +11 -3
  15. 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
  16. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +18 -5
  17. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEvent.kt +9 -3
  18. package/nitrogen/generated/android/nitrosseOnLoad.cpp +2 -0
  19. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.cpp +33 -0
  20. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +130 -0
  21. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +1 -0
  22. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +2 -1
  23. package/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.swift +67 -0
  24. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  25. package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___.swift +66 -0
  26. package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__std__string_.swift +54 -0
  27. package/nitrogen/generated/ios/swift/SseConfig.swift +84 -1
  28. package/nitrogen/generated/ios/swift/SseEvent.swift +37 -1
  29. package/nitrogen/generated/shared/c++/SseConfig.hpp +17 -3
  30. package/nitrogen/generated/shared/c++/SseEvent.hpp +10 -2
  31. package/package.json +2 -2
  32. package/src/SseInterface.ts +17 -0
  33. package/src/{index.tsx → index.ts} +4 -3
@@ -11,7 +11,12 @@
11
11
  #include "SseConfig.hpp"
12
12
 
13
13
  #include "HttpMethod.hpp"
14
+ #include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp"
14
15
  #include "JHttpMethod.hpp"
16
+ #include <NitroModules/JNICallable.hpp>
17
+ #include <NitroModules/JPromise.hpp>
18
+ #include <NitroModules/Promise.hpp>
19
+ #include <functional>
15
20
  #include <optional>
16
21
  #include <string>
17
22
  #include <unordered_map>
@@ -49,6 +54,12 @@ namespace margelo::nitro::nitrosse {
49
54
  jni::local_ref<jni::JDouble> batchingIntervalMs = this->getFieldValue(fieldBatchingIntervalMs);
50
55
  static const auto fieldMaxBufferSize = clazz->getField<jni::JDouble>("maxBufferSize");
51
56
  jni::local_ref<jni::JDouble> maxBufferSize = this->getFieldValue(fieldMaxBufferSize);
57
+ static const auto fieldConnectionTimeoutMs = clazz->getField<jni::JDouble>("connectionTimeoutMs");
58
+ jni::local_ref<jni::JDouble> connectionTimeoutMs = this->getFieldValue(fieldConnectionTimeoutMs);
59
+ static const auto fieldReadTimeoutMs = clazz->getField<jni::JDouble>("readTimeoutMs");
60
+ jni::local_ref<jni::JDouble> readTimeoutMs = this->getFieldValue(fieldReadTimeoutMs);
61
+ static const auto fieldOnBeforeRequest = clazz->getField<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>("onBeforeRequest");
62
+ jni::local_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject> onBeforeRequest = this->getFieldValue(fieldOnBeforeRequest);
52
63
  return SseConfig(
53
64
  url->toStdString(),
54
65
  method != nullptr ? std::make_optional(method->toCpp()) : std::nullopt,
@@ -63,7 +74,18 @@ namespace margelo::nitro::nitrosse {
63
74
  body != nullptr ? std::make_optional(body->toStdString()) : std::nullopt,
64
75
  backgroundExecution != nullptr ? std::make_optional(static_cast<bool>(backgroundExecution->value())) : std::nullopt,
65
76
  batchingIntervalMs != nullptr ? std::make_optional(batchingIntervalMs->value()) : std::nullopt,
66
- maxBufferSize != nullptr ? std::make_optional(maxBufferSize->value()) : std::nullopt
77
+ maxBufferSize != nullptr ? std::make_optional(maxBufferSize->value()) : std::nullopt,
78
+ connectionTimeoutMs != nullptr ? std::make_optional(connectionTimeoutMs->value()) : std::nullopt,
79
+ readTimeoutMs != nullptr ? std::make_optional(readTimeoutMs->value()) : std::nullopt,
80
+ onBeforeRequest != nullptr ? std::make_optional([&]() -> std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()> {
81
+ if (onBeforeRequest->isInstanceOf(JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::javaClassStatic())) [[likely]] {
82
+ auto downcast = jni::static_ref_cast<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::javaobject>(onBeforeRequest);
83
+ return downcast->cthis()->getFunction();
84
+ } else {
85
+ auto onBeforeRequestRef = jni::make_global(onBeforeRequest);
86
+ return JNICallable<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____, std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>(std::move(onBeforeRequestRef));
87
+ }
88
+ }()) : std::nullopt
67
89
  );
68
90
  }
69
91
 
@@ -73,7 +95,7 @@ namespace margelo::nitro::nitrosse {
73
95
  */
74
96
  [[maybe_unused]]
75
97
  static jni::local_ref<JSseConfig::javaobject> fromCpp(const SseConfig& value) {
76
- using JSignature = JSseConfig(jni::alias_ref<jni::JString>, jni::alias_ref<JHttpMethod>, jni::alias_ref<jni::JMap<jni::JString, jni::JString>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
98
+ using JSignature = JSseConfig(jni::alias_ref<jni::JString>, jni::alias_ref<JHttpMethod>, jni::alias_ref<jni::JMap<jni::JString, jni::JString>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>);
77
99
  static const auto clazz = javaClassStatic();
78
100
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
79
101
  return create(
@@ -90,7 +112,10 @@ namespace margelo::nitro::nitrosse {
90
112
  value.body.has_value() ? jni::make_jstring(value.body.value()) : nullptr,
91
113
  value.backgroundExecution.has_value() ? jni::JBoolean::valueOf(value.backgroundExecution.value()) : nullptr,
92
114
  value.batchingIntervalMs.has_value() ? jni::JDouble::valueOf(value.batchingIntervalMs.value()) : nullptr,
93
- value.maxBufferSize.has_value() ? jni::JDouble::valueOf(value.maxBufferSize.value()) : nullptr
115
+ value.maxBufferSize.has_value() ? jni::JDouble::valueOf(value.maxBufferSize.value()) : nullptr,
116
+ value.connectionTimeoutMs.has_value() ? jni::JDouble::valueOf(value.connectionTimeoutMs.value()) : nullptr,
117
+ value.readTimeoutMs.has_value() ? jni::JDouble::valueOf(value.readTimeoutMs.value()) : nullptr,
118
+ value.onBeforeRequest.has_value() ? JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::fromCpp(value.onBeforeRequest.value()) : nullptr
94
119
  );
95
120
  }
96
121
  };
@@ -44,12 +44,18 @@ namespace margelo::nitro::nitrosse {
44
44
  jni::local_ref<jni::JString> event = this->getFieldValue(fieldEvent);
45
45
  static const auto fieldMessage = clazz->getField<jni::JString>("message");
46
46
  jni::local_ref<jni::JString> message = this->getFieldValue(fieldMessage);
47
+ static const auto fieldStatusCode = clazz->getField<jni::JDouble>("statusCode");
48
+ jni::local_ref<jni::JDouble> statusCode = this->getFieldValue(fieldStatusCode);
49
+ static const auto fieldRetry = clazz->getField<jni::JDouble>("retry");
50
+ jni::local_ref<jni::JDouble> retry = this->getFieldValue(fieldRetry);
47
51
  return SseEvent(
48
52
  type->toCpp(),
49
53
  data != nullptr ? std::make_optional(data->toStdString()) : std::nullopt,
50
54
  id != nullptr ? std::make_optional(id->toStdString()) : std::nullopt,
51
55
  event != nullptr ? std::make_optional(event->toStdString()) : std::nullopt,
52
- message != nullptr ? std::make_optional(message->toStdString()) : std::nullopt
56
+ message != nullptr ? std::make_optional(message->toStdString()) : std::nullopt,
57
+ statusCode != nullptr ? std::make_optional(statusCode->value()) : std::nullopt,
58
+ retry != nullptr ? std::make_optional(retry->value()) : std::nullopt
53
59
  );
54
60
  }
55
61
 
@@ -59,7 +65,7 @@ namespace margelo::nitro::nitrosse {
59
65
  */
60
66
  [[maybe_unused]]
61
67
  static jni::local_ref<JSseEvent::javaobject> fromCpp(const SseEvent& value) {
62
- using JSignature = JSseEvent(jni::alias_ref<JSseEventType>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
68
+ using JSignature = JSseEvent(jni::alias_ref<JSseEventType>, jni::alias_ref<jni::JString>, 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>);
63
69
  static const auto clazz = javaClassStatic();
64
70
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
65
71
  return create(
@@ -68,7 +74,9 @@ namespace margelo::nitro::nitrosse {
68
74
  value.data.has_value() ? jni::make_jstring(value.data.value()) : nullptr,
69
75
  value.id.has_value() ? jni::make_jstring(value.id.value()) : nullptr,
70
76
  value.event.has_value() ? jni::make_jstring(value.event.value()) : nullptr,
71
- value.message.has_value() ? jni::make_jstring(value.message.value()) : nullptr
77
+ value.message.has_value() ? jni::make_jstring(value.message.value()) : nullptr,
78
+ value.statusCode.has_value() ? jni::JDouble::valueOf(value.statusCode.value()) : nullptr,
79
+ value.retry.has_value() ? jni::JDouble::valueOf(value.retry.value()) : nullptr
72
80
  );
73
81
  }
74
82
  };
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.kt
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
+ package com.margelo.nitro.nitrosse
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.jni.HybridData
12
+ import com.facebook.proguard.annotations.DoNotStrip
13
+ import dalvik.annotation.optimization.FastNative
14
+ import com.margelo.nitro.core.Promise
15
+
16
+ /**
17
+ * Represents the JavaScript callback `() => std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>`.
18
+ * This can be either implemented in C++ (in which case it might be a callback coming from JS),
19
+ * or in Kotlin/Java (in which case it is a native callback).
20
+ */
21
+ @DoNotStrip
22
+ @Keep
23
+ @Suppress("ClassName", "RedundantUnitReturnType")
24
+ fun interface Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____: () -> Promise<Promise<Map<String, String>>> {
25
+ /**
26
+ * Call the given JS callback.
27
+ * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
28
+ */
29
+ @DoNotStrip
30
+ @Keep
31
+ override fun invoke(): Promise<Promise<Map<String, String>>>
32
+ }
33
+
34
+ /**
35
+ * Represents the JavaScript callback `() => std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>`.
36
+ * This is implemented in C++, via a `std::function<...>`.
37
+ * The callback might be coming from JS.
38
+ */
39
+ @DoNotStrip
40
+ @Keep
41
+ @Suppress(
42
+ "KotlinJniMissingFunction", "unused",
43
+ "RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
44
+ "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
45
+ )
46
+ class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ {
47
+ @DoNotStrip
48
+ @Keep
49
+ private val mHybridData: HybridData
50
+
51
+ @DoNotStrip
52
+ @Keep
53
+ private constructor(hybridData: HybridData) {
54
+ mHybridData = hybridData
55
+ }
56
+
57
+ @DoNotStrip
58
+ @Keep
59
+ override fun invoke(): Promise<Promise<Map<String, String>>>
60
+ = invoke_cxx()
61
+
62
+ @FastNative
63
+ private external fun invoke_cxx(): Promise<Promise<Map<String, String>>>
64
+ }
65
+
66
+ /**
67
+ * Represents the JavaScript callback `() => std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>`.
68
+ * This is implemented in Java/Kotlin, via a `() -> Promise<Promise<Map<String, String>>>`.
69
+ * The callback is always coming from native.
70
+ */
71
+ @DoNotStrip
72
+ @Keep
73
+ @Suppress("ClassName", "RedundantUnitReturnType", "unused")
74
+ class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______java(private val function: () -> Promise<Promise<Map<String, String>>>): Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ {
75
+ @DoNotStrip
76
+ @Keep
77
+ override fun invoke(): Promise<Promise<Map<String, String>>> {
78
+ return this.function()
79
+ }
80
+ }
@@ -9,7 +9,7 @@ package com.margelo.nitro.nitrosse
9
9
 
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.proguard.annotations.DoNotStrip
12
-
12
+ import com.margelo.nitro.core.Promise
13
13
 
14
14
  /**
15
15
  * Represents the JavaScript object/struct "SseConfig".
@@ -37,9 +37,22 @@ data class SseConfig(
37
37
  val batchingIntervalMs: Double?,
38
38
  @DoNotStrip
39
39
  @Keep
40
- val maxBufferSize: Double?
40
+ val maxBufferSize: Double?,
41
+ @DoNotStrip
42
+ @Keep
43
+ val connectionTimeoutMs: Double?,
44
+ @DoNotStrip
45
+ @Keep
46
+ val readTimeoutMs: Double?,
47
+ @DoNotStrip
48
+ @Keep
49
+ val onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?
41
50
  ) {
42
- /* primary constructor */
51
+ /**
52
+ * Create a new instance of SseConfig from Kotlin
53
+ */
54
+ constructor(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, onBeforeRequest: (() -> Promise<Promise<Map<String, String>>>)?):
55
+ this(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, onBeforeRequest?.let { Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______java(it) })
43
56
 
44
57
  companion object {
45
58
  /**
@@ -49,8 +62,8 @@ data class SseConfig(
49
62
  @Keep
50
63
  @Suppress("unused")
51
64
  @JvmStatic
52
- private fun fromCpp(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?): SseConfig {
53
- return SseConfig(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize)
65
+ private fun fromCpp(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?): SseConfig {
66
+ return SseConfig(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, onBeforeRequest)
54
67
  }
55
68
  }
56
69
  }
@@ -31,7 +31,13 @@ data class SseEvent(
31
31
  val event: String?,
32
32
  @DoNotStrip
33
33
  @Keep
34
- val message: String?
34
+ val message: String?,
35
+ @DoNotStrip
36
+ @Keep
37
+ val statusCode: Double?,
38
+ @DoNotStrip
39
+ @Keep
40
+ val retry: Double?
35
41
  ) {
36
42
  /* primary constructor */
37
43
 
@@ -43,8 +49,8 @@ data class SseEvent(
43
49
  @Keep
44
50
  @Suppress("unused")
45
51
  @JvmStatic
46
- private fun fromCpp(type: SseEventType, data: String?, id: String?, event: String?, message: String?): SseEvent {
47
- return SseEvent(type, data, id, event, message)
52
+ private fun fromCpp(type: SseEventType, data: String?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?): SseEvent {
53
+ return SseEvent(type, data, id, event, message, statusCode, retry)
48
54
  }
49
55
  }
50
56
  }
@@ -16,6 +16,7 @@
16
16
  #include <NitroModules/HybridObjectRegistry.hpp>
17
17
 
18
18
  #include "JHybridNitroSseSpec.hpp"
19
+ #include "JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp"
19
20
  #include "JFunc_void_std__vector_SseEvent_.hpp"
20
21
  #include <NitroModules/DefaultConstructableObject.hpp>
21
22
 
@@ -42,6 +43,7 @@ void registerAllNatives() {
42
43
 
43
44
  // Register native JNI methods
44
45
  margelo::nitro::nitrosse::JHybridNitroSseSpec::CxxPart::registerNatives();
46
+ margelo::nitro::nitrosse::JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::registerNatives();
45
47
  margelo::nitro::nitrosse::JFunc_void_std__vector_SseEvent__cxx::registerNatives();
46
48
 
47
49
  // Register Nitro Hybrid Objects
@@ -14,6 +14,39 @@
14
14
 
15
15
  namespace margelo::nitro::nitrosse::bridge::swift {
16
16
 
17
+ // pragma MARK: std::function<void(const std::unordered_map<std::string, std::string>& /* result */)>
18
+ Func_void_std__unordered_map_std__string__std__string_ create_Func_void_std__unordered_map_std__string__std__string_(void* NON_NULL swiftClosureWrapper) noexcept {
19
+ auto swiftClosure = NitroSse::Func_void_std__unordered_map_std__string__std__string_::fromUnsafe(swiftClosureWrapper);
20
+ return [swiftClosure = std::move(swiftClosure)](const std::unordered_map<std::string, std::string>& result) mutable -> void {
21
+ swiftClosure.call(result);
22
+ };
23
+ }
24
+
25
+ // pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
26
+ Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept {
27
+ auto swiftClosure = NitroSse::Func_void_std__exception_ptr::fromUnsafe(swiftClosureWrapper);
28
+ return [swiftClosure = std::move(swiftClosure)](const std::exception_ptr& error) mutable -> void {
29
+ swiftClosure.call(error);
30
+ };
31
+ }
32
+
33
+ // pragma MARK: std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>
34
+ Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(void* NON_NULL swiftClosureWrapper) noexcept {
35
+ auto swiftClosure = NitroSse::Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::fromUnsafe(swiftClosureWrapper);
36
+ return [swiftClosure = std::move(swiftClosure)]() mutable -> std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>> {
37
+ auto __result = swiftClosure.call();
38
+ return __result;
39
+ };
40
+ }
41
+
42
+ // pragma MARK: std::function<void(const std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>& /* result */)>
43
+ Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___ create_Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___(void* NON_NULL swiftClosureWrapper) noexcept {
44
+ auto swiftClosure = NitroSse::Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___::fromUnsafe(swiftClosureWrapper);
45
+ return [swiftClosure = std::move(swiftClosure)](const std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>& result) mutable -> void {
46
+ swiftClosure.call(result);
47
+ };
48
+ }
49
+
17
50
  // pragma MARK: std::function<void(const std::vector<SseEvent>& /* events */)>
18
51
  Func_void_std__vector_SseEvent_ create_Func_void_std__vector_SseEvent_(void* NON_NULL swiftClosureWrapper) noexcept {
19
52
  auto swiftClosure = NitroSse::Func_void_std__vector_SseEvent_::fromUnsafe(swiftClosureWrapper);
@@ -29,6 +29,8 @@ namespace NitroSse { class HybridNitroSseSpec_cxx; }
29
29
  #include "SseEvent.hpp"
30
30
  #include "SseEventType.hpp"
31
31
  #include "SseStats.hpp"
32
+ #include <NitroModules/Promise.hpp>
33
+ #include <NitroModules/PromiseHolder.hpp>
32
34
  #include <NitroModules/Result.hpp>
33
35
  #include <exception>
34
36
  #include <functional>
@@ -144,6 +146,134 @@ namespace margelo::nitro::nitrosse::bridge::swift {
144
146
  return optional.value();
145
147
  }
146
148
 
149
+ // pragma MARK: std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>
150
+ /**
151
+ * Specialized version of `std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>`.
152
+ */
153
+ using std__shared_ptr_Promise_std__unordered_map_std__string__std__string___ = std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>;
154
+ inline std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>> create_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___() noexcept {
155
+ return Promise<std::unordered_map<std::string, std::string>>::create();
156
+ }
157
+ inline PromiseHolder<std::unordered_map<std::string, std::string>> wrap_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___(std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>> promise) noexcept {
158
+ return PromiseHolder<std::unordered_map<std::string, std::string>>(std::move(promise));
159
+ }
160
+
161
+ // pragma MARK: std::function<void(const std::unordered_map<std::string, std::string>& /* result */)>
162
+ /**
163
+ * Specialized version of `std::function<void(const std::unordered_map<std::string, std::string>&)>`.
164
+ */
165
+ using Func_void_std__unordered_map_std__string__std__string_ = std::function<void(const std::unordered_map<std::string, std::string>& /* result */)>;
166
+ /**
167
+ * Wrapper class for a `std::function<void(const std::unordered_map<std::string, std::string>& / * result * /)>`, this can be used from Swift.
168
+ */
169
+ class Func_void_std__unordered_map_std__string__std__string__Wrapper final {
170
+ public:
171
+ explicit Func_void_std__unordered_map_std__string__std__string__Wrapper(std::function<void(const std::unordered_map<std::string, std::string>& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::unordered_map<std::string, std::string>& /* result */)>>(std::move(func))) {}
172
+ inline void call(std::unordered_map<std::string, std::string> result) const noexcept {
173
+ _function->operator()(result);
174
+ }
175
+ private:
176
+ std::unique_ptr<std::function<void(const std::unordered_map<std::string, std::string>& /* result */)>> _function;
177
+ } SWIFT_NONCOPYABLE;
178
+ Func_void_std__unordered_map_std__string__std__string_ create_Func_void_std__unordered_map_std__string__std__string_(void* NON_NULL swiftClosureWrapper) noexcept;
179
+ inline Func_void_std__unordered_map_std__string__std__string__Wrapper wrap_Func_void_std__unordered_map_std__string__std__string_(Func_void_std__unordered_map_std__string__std__string_ value) noexcept {
180
+ return Func_void_std__unordered_map_std__string__std__string__Wrapper(std::move(value));
181
+ }
182
+
183
+ // pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
184
+ /**
185
+ * Specialized version of `std::function<void(const std::exception_ptr&)>`.
186
+ */
187
+ using Func_void_std__exception_ptr = std::function<void(const std::exception_ptr& /* error */)>;
188
+ /**
189
+ * Wrapper class for a `std::function<void(const std::exception_ptr& / * error * /)>`, this can be used from Swift.
190
+ */
191
+ class Func_void_std__exception_ptr_Wrapper final {
192
+ public:
193
+ explicit Func_void_std__exception_ptr_Wrapper(std::function<void(const std::exception_ptr& /* error */)>&& func): _function(std::make_unique<std::function<void(const std::exception_ptr& /* error */)>>(std::move(func))) {}
194
+ inline void call(std::exception_ptr error) const noexcept {
195
+ _function->operator()(error);
196
+ }
197
+ private:
198
+ std::unique_ptr<std::function<void(const std::exception_ptr& /* error */)>> _function;
199
+ } SWIFT_NONCOPYABLE;
200
+ Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept;
201
+ inline Func_void_std__exception_ptr_Wrapper wrap_Func_void_std__exception_ptr(Func_void_std__exception_ptr value) noexcept {
202
+ return Func_void_std__exception_ptr_Wrapper(std::move(value));
203
+ }
204
+
205
+ // pragma MARK: std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>
206
+ /**
207
+ * Specialized version of `std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>`.
208
+ */
209
+ using Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ = std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>;
210
+ /**
211
+ * Wrapper class for a `std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>`, this can be used from Swift.
212
+ */
213
+ class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______Wrapper final {
214
+ public:
215
+ explicit Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______Wrapper(std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>&& func): _function(std::make_unique<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>(std::move(func))) {}
216
+ inline std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>> call() const noexcept {
217
+ auto __result = _function->operator()();
218
+ return __result;
219
+ }
220
+ private:
221
+ std::unique_ptr<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>> _function;
222
+ } SWIFT_NONCOPYABLE;
223
+ Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(void* NON_NULL swiftClosureWrapper) noexcept;
224
+ inline Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______Wrapper wrap_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ value) noexcept {
225
+ return Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______Wrapper(std::move(value));
226
+ }
227
+
228
+ // pragma MARK: std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>
229
+ /**
230
+ * Specialized version of `std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>`.
231
+ */
232
+ using std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ = std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>;
233
+ inline std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>> create_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____() noexcept {
234
+ return Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>::create();
235
+ }
236
+ inline PromiseHolder<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>> wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>> promise) noexcept {
237
+ return PromiseHolder<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>(std::move(promise));
238
+ }
239
+
240
+ // pragma MARK: std::function<void(const std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>& /* result */)>
241
+ /**
242
+ * Specialized version of `std::function<void(const std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>&)>`.
243
+ */
244
+ using Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___ = std::function<void(const std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>& /* result */)>;
245
+ /**
246
+ * Wrapper class for a `std::function<void(const std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>& / * result * /)>`, this can be used from Swift.
247
+ */
248
+ class Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string____Wrapper final {
249
+ public:
250
+ explicit Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string____Wrapper(std::function<void(const std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>& /* result */)>>(std::move(func))) {}
251
+ inline void call(std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>> result) const noexcept {
252
+ _function->operator()(result);
253
+ }
254
+ private:
255
+ std::unique_ptr<std::function<void(const std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>& /* result */)>> _function;
256
+ } SWIFT_NONCOPYABLE;
257
+ Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___ create_Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___(void* NON_NULL swiftClosureWrapper) noexcept;
258
+ inline Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string____Wrapper wrap_Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___(Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___ value) noexcept {
259
+ return Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string____Wrapper(std::move(value));
260
+ }
261
+
262
+ // pragma MARK: std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>
263
+ /**
264
+ * Specialized version of `std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>`.
265
+ */
266
+ using std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________ = std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>;
267
+ inline std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>> create_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________(const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>& value) noexcept {
268
+ return std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>(value);
269
+ }
270
+ inline bool has_value_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________(const std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>& optional) noexcept {
271
+ return optional.has_value();
272
+ }
273
+ inline std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()> get_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________(const std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>& optional) noexcept {
274
+ return optional.value();
275
+ }
276
+
147
277
  // pragma MARK: std::vector<SseEvent>
148
278
  /**
149
279
  * Specialized version of `std::vector<SseEvent>`.
@@ -28,6 +28,7 @@ namespace margelo::nitro::nitrosse { struct SseStats; }
28
28
  #include "SseEvent.hpp"
29
29
  #include "SseEventType.hpp"
30
30
  #include "SseStats.hpp"
31
+ #include <NitroModules/Promise.hpp>
31
32
  #include <NitroModules/Result.hpp>
32
33
  #include <exception>
33
34
  #include <functional>
@@ -28,9 +28,10 @@ namespace margelo::nitro::nitrosse { struct SseStats; }
28
28
  #include "HttpMethod.hpp"
29
29
  #include <optional>
30
30
  #include <unordered_map>
31
+ #include <NitroModules/Promise.hpp>
32
+ #include <functional>
31
33
  #include "SseEvent.hpp"
32
34
  #include <vector>
33
- #include <functional>
34
35
  #include "SseEventType.hpp"
35
36
  #include "SseStats.hpp"
36
37
 
@@ -0,0 +1,67 @@
1
+ ///
2
+ /// Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.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
+ * Wraps a Swift `() -> Promise<Promise<Dictionary<String, String>>>` as a class.
12
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
+ */
14
+ public final class Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ {
15
+ public typealias bridge = margelo.nitro.nitrosse.bridge.swift
16
+
17
+ private let closure: () -> Promise<Promise<Dictionary<String, String>>>
18
+
19
+ public init(_ closure: @escaping () -> Promise<Promise<Dictionary<String, String>>>) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call() -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ {
25
+ let __result: Promise<Promise<Dictionary<String, String>>> = self.closure()
26
+ return { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ in
27
+ let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____()
28
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(__promise)
29
+ __result
30
+ .then({ __result in __promiseHolder.resolve({ () -> bridge.std__shared_ptr_Promise_std__unordered_map_std__string__std__string___ in
31
+ let __promise = bridge.create_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___()
32
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___(__promise)
33
+ __result
34
+ .then({ __result in __promiseHolder.resolve({ () -> bridge.std__unordered_map_std__string__std__string_ in
35
+ var __map = bridge.create_std__unordered_map_std__string__std__string_(__result.count)
36
+ for (__k, __v) in __result {
37
+ bridge.emplace_std__unordered_map_std__string__std__string_(&__map, std.string(__k), std.string(__v))
38
+ }
39
+ return __map
40
+ }()) })
41
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
42
+ return __promise
43
+ }()) })
44
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
45
+ return __promise
46
+ }()
47
+ }
48
+
49
+ /**
50
+ * Casts this instance to a retained unsafe raw pointer.
51
+ * This acquires one additional strong reference on the object!
52
+ */
53
+ @inline(__always)
54
+ public func toUnsafe() -> UnsafeMutableRawPointer {
55
+ return Unmanaged.passRetained(self).toOpaque()
56
+ }
57
+
58
+ /**
59
+ * Casts an unsafe pointer to a `Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____`.
60
+ * The pointer has to be a retained opaque `Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____>`.
61
+ * This removes one strong reference from the object!
62
+ */
63
+ @inline(__always)
64
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ {
65
+ return Unmanaged<Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____>.fromOpaque(pointer).takeRetainedValue()
66
+ }
67
+ }
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Func_void_std__exception_ptr.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
+ * Wraps a Swift `(_ error: Error) -> Void` as a class.
12
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
+ */
14
+ public final class Func_void_std__exception_ptr {
15
+ public typealias bridge = margelo.nitro.nitrosse.bridge.swift
16
+
17
+ private let closure: (_ error: Error) -> Void
18
+
19
+ public init(_ closure: @escaping (_ error: Error) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(error: std.exception_ptr) -> Void {
25
+ self.closure(RuntimeError.from(cppError: error))
26
+ }
27
+
28
+ /**
29
+ * Casts this instance to a retained unsafe raw pointer.
30
+ * This acquires one additional strong reference on the object!
31
+ */
32
+ @inline(__always)
33
+ public func toUnsafe() -> UnsafeMutableRawPointer {
34
+ return Unmanaged.passRetained(self).toOpaque()
35
+ }
36
+
37
+ /**
38
+ * Casts an unsafe pointer to a `Func_void_std__exception_ptr`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__exception_ptr>`.
40
+ * This removes one strong reference from the object!
41
+ */
42
+ @inline(__always)
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__exception_ptr {
44
+ return Unmanaged<Func_void_std__exception_ptr>.fromOpaque(pointer).takeRetainedValue()
45
+ }
46
+ }