react-native-nitro-fetch 0.1.3 → 0.1.5
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.
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/margelo/nitro/nitrofetch/AutoPrefetcher.kt +7 -28
- package/android/src/main/java/com/margelo/nitro/nitrofetch/FetchCache.kt +11 -1
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NativeStorage.kt +102 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/NitroFetchClient.kt +53 -29
- package/ios/NativeStorage.swift +61 -0
- package/ios/NitroAutoPrefetcher.swift +5 -41
- package/ios/NitroFetchClient.swift +25 -0
- package/lib/module/NitroFetch.nitro.js +0 -3
- package/lib/module/NitroFetch.nitro.js.map +1 -1
- package/lib/module/NitroInstances.js +2 -0
- package/lib/module/NitroInstances.js.map +1 -1
- package/lib/module/fetch.js +79 -125
- package/lib/module/fetch.js.map +1 -1
- package/lib/typescript/src/NitroFetch.nitro.d.ts +9 -0
- package/lib/typescript/src/NitroFetch.nitro.d.ts.map +1 -1
- package/lib/typescript/src/NitroInstances.d.ts +3 -1
- package/lib/typescript/src/NitroInstances.d.ts.map +1 -1
- package/lib/typescript/src/fetch.d.ts.map +1 -1
- package/nitro.json +4 -0
- package/nitrogen/generated/android/c++/JHybridNativeStorageSpec.cpp +54 -0
- package/nitrogen/generated/android/c++/JHybridNativeStorageSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.cpp +5 -0
- package/nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.hpp +1 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNativeStorageSpec.kt +60 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNitroFetchClientSpec.kt +4 -0
- package/nitrogen/generated/android/nitrofetch+autolinking.cmake +9 -4
- package/nitrogen/generated/android/nitrofetchOnLoad.cpp +10 -0
- package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Bridge.hpp +44 -0
- package/nitrogen/generated/ios/NitroFetch-Swift-Cxx-Umbrella.hpp +5 -0
- package/nitrogen/generated/ios/NitroFetchAutolinking.mm +8 -0
- package/nitrogen/generated/ios/NitroFetchAutolinking.swift +15 -0
- package/nitrogen/generated/ios/c++/HybridNativeStorageSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNativeStorageSpecSwift.hpp +85 -0
- package/nitrogen/generated/ios/c++/HybridNitroFetchClientSpecSwift.hpp +8 -0
- package/nitrogen/generated/ios/swift/HybridNativeStorageSpec.swift +51 -0
- package/nitrogen/generated/ios/swift/HybridNativeStorageSpec_cxx.swift +145 -0
- package/nitrogen/generated/ios/swift/HybridNitroFetchClientSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridNitroFetchClientSpec_cxx.swift +12 -0
- package/nitrogen/generated/shared/c++/HybridNativeStorageSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridNativeStorageSpec.hpp +64 -0
- package/nitrogen/generated/shared/c++/HybridNitroFetchClientSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridNitroFetchClientSpec.hpp +1 -0
- package/package.json +8 -24
- package/src/NitroFetch.nitro.ts +15 -5
- package/src/NitroInstances.ts +7 -1
- package/src/fetch.ts +158 -122
- package/LICENSE +0 -20
- package/README.md +0 -151
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNativeStorageSpec.kt
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeStorageSpec.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.nitrofetch
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.*
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A Kotlin class representing the NativeStorage HybridObject.
|
|
17
|
+
* Implement this abstract class to create Kotlin-based instances of NativeStorage.
|
|
18
|
+
*/
|
|
19
|
+
@DoNotStrip
|
|
20
|
+
@Keep
|
|
21
|
+
@Suppress(
|
|
22
|
+
"KotlinJniMissingFunction", "unused",
|
|
23
|
+
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
|
24
|
+
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
25
|
+
)
|
|
26
|
+
abstract class HybridNativeStorageSpec: HybridObject() {
|
|
27
|
+
@DoNotStrip
|
|
28
|
+
private var mHybridData: HybridData = initHybrid()
|
|
29
|
+
|
|
30
|
+
init {
|
|
31
|
+
super.updateNative(mHybridData)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override fun updateNative(hybridData: HybridData) {
|
|
35
|
+
mHybridData = hybridData
|
|
36
|
+
super.updateNative(hybridData)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Properties
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// Methods
|
|
43
|
+
@DoNotStrip
|
|
44
|
+
@Keep
|
|
45
|
+
abstract fun getString(key: String): String
|
|
46
|
+
|
|
47
|
+
@DoNotStrip
|
|
48
|
+
@Keep
|
|
49
|
+
abstract fun setString(key: String, value: String): Unit
|
|
50
|
+
|
|
51
|
+
@DoNotStrip
|
|
52
|
+
@Keep
|
|
53
|
+
abstract fun removeString(key: String): Unit
|
|
54
|
+
|
|
55
|
+
private external fun initHybrid(): HybridData
|
|
56
|
+
|
|
57
|
+
companion object {
|
|
58
|
+
private const val TAG = "HybridNativeStorageSpec"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrofetch/HybridNitroFetchClientSpec.kt
CHANGED
|
@@ -47,6 +47,10 @@ abstract class HybridNitroFetchClientSpec: HybridObject() {
|
|
|
47
47
|
@DoNotStrip
|
|
48
48
|
@Keep
|
|
49
49
|
abstract fun prefetch(req: NitroRequest): Promise<Unit>
|
|
50
|
+
|
|
51
|
+
@DoNotStrip
|
|
52
|
+
@Keep
|
|
53
|
+
abstract fun requestSync(req: NitroRequest): NitroResponse
|
|
50
54
|
|
|
51
55
|
private external fun initHybrid(): HybridData
|
|
52
56
|
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/nitrofetch+autolinking.cmake)
|
|
14
14
|
# ```
|
|
15
15
|
|
|
16
|
+
# Define a flag to check if we are building properly
|
|
17
|
+
add_definitions(-DBUILDING_NITROFETCH_WITH_GENERATED_CMAKE_PROJECT)
|
|
18
|
+
|
|
19
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
20
|
+
add_definitions(-DRN_SERIALIZABLE_STATE)
|
|
21
|
+
|
|
16
22
|
# Add all headers that were generated by Nitrogen
|
|
17
23
|
include_directories(
|
|
18
24
|
"../nitrogen/generated/shared/c++"
|
|
@@ -29,17 +35,16 @@ target_sources(
|
|
|
29
35
|
# Shared Nitrogen C++ sources
|
|
30
36
|
../nitrogen/generated/shared/c++/HybridNitroFetchClientSpec.cpp
|
|
31
37
|
../nitrogen/generated/shared/c++/HybridNitroFetchSpec.cpp
|
|
38
|
+
../nitrogen/generated/shared/c++/HybridNativeStorageSpec.cpp
|
|
32
39
|
# Android-specific Nitrogen C++ sources
|
|
33
40
|
../nitrogen/generated/android/c++/JHybridNitroFetchClientSpec.cpp
|
|
34
41
|
../nitrogen/generated/android/c++/JHybridNitroFetchSpec.cpp
|
|
42
|
+
../nitrogen/generated/android/c++/JHybridNativeStorageSpec.cpp
|
|
35
43
|
)
|
|
36
44
|
|
|
37
|
-
# Define a flag to check if we are building properly
|
|
38
|
-
add_definitions(-DBUILDING_NITROFETCH_WITH_GENERATED_CMAKE_PROJECT)
|
|
39
|
-
|
|
40
45
|
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
41
46
|
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
|
42
|
-
|
|
47
|
+
target_compile_definitions(
|
|
43
48
|
nitrofetch PRIVATE
|
|
44
49
|
-DFOLLY_NO_CONFIG=1
|
|
45
50
|
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
#include "JHybridNitroFetchClientSpec.hpp"
|
|
19
19
|
#include "JHybridNitroFetchSpec.hpp"
|
|
20
|
+
#include "JHybridNativeStorageSpec.hpp"
|
|
20
21
|
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
21
22
|
|
|
22
23
|
namespace margelo::nitro::nitrofetch {
|
|
@@ -30,6 +31,7 @@ int initialize(JavaVM* vm) {
|
|
|
30
31
|
// Register native JNI methods
|
|
31
32
|
margelo::nitro::nitrofetch::JHybridNitroFetchClientSpec::registerNatives();
|
|
32
33
|
margelo::nitro::nitrofetch::JHybridNitroFetchSpec::registerNatives();
|
|
34
|
+
margelo::nitro::nitrofetch::JHybridNativeStorageSpec::registerNatives();
|
|
33
35
|
|
|
34
36
|
// Register Nitro Hybrid Objects
|
|
35
37
|
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
@@ -48,6 +50,14 @@ int initialize(JavaVM* vm) {
|
|
|
48
50
|
return instance->cthis()->shared();
|
|
49
51
|
}
|
|
50
52
|
);
|
|
53
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
54
|
+
"NativeStorage",
|
|
55
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
56
|
+
static DefaultConstructableObject<JHybridNativeStorageSpec::javaobject> object("com/margelo/nitro/nitrofetch/NativeStorage");
|
|
57
|
+
auto instance = object.create();
|
|
58
|
+
return instance->cthis()->shared();
|
|
59
|
+
}
|
|
60
|
+
);
|
|
51
61
|
});
|
|
52
62
|
}
|
|
53
63
|
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#include "NitroFetch-Swift-Cxx-Bridge.hpp"
|
|
9
9
|
|
|
10
10
|
// Include C++ implementation defined types
|
|
11
|
+
#include "HybridNativeStorageSpecSwift.hpp"
|
|
11
12
|
#include "HybridNitroFetchClientSpecSwift.hpp"
|
|
12
13
|
#include "HybridNitroFetchSpecSwift.hpp"
|
|
13
14
|
#include "NitroFetch-Swift-Cxx-Umbrella.hpp"
|
|
@@ -69,5 +70,21 @@ namespace margelo::nitro::nitrofetch::bridge::swift {
|
|
|
69
70
|
NitroFetch::HybridNitroFetchSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
|
|
70
71
|
return swiftPart.toUnsafe();
|
|
71
72
|
}
|
|
73
|
+
|
|
74
|
+
// pragma MARK: std::shared_ptr<HybridNativeStorageSpec>
|
|
75
|
+
std::shared_ptr<HybridNativeStorageSpec> create_std__shared_ptr_HybridNativeStorageSpec_(void* _Nonnull swiftUnsafePointer) noexcept {
|
|
76
|
+
NitroFetch::HybridNativeStorageSpec_cxx swiftPart = NitroFetch::HybridNativeStorageSpec_cxx::fromUnsafe(swiftUnsafePointer);
|
|
77
|
+
return std::make_shared<margelo::nitro::nitrofetch::HybridNativeStorageSpecSwift>(swiftPart);
|
|
78
|
+
}
|
|
79
|
+
void* _Nonnull get_std__shared_ptr_HybridNativeStorageSpec_(std__shared_ptr_HybridNativeStorageSpec_ cppType) noexcept {
|
|
80
|
+
std::shared_ptr<margelo::nitro::nitrofetch::HybridNativeStorageSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::nitrofetch::HybridNativeStorageSpecSwift>(cppType);
|
|
81
|
+
#ifdef NITRO_DEBUG
|
|
82
|
+
if (swiftWrapper == nullptr) [[unlikely]] {
|
|
83
|
+
throw std::runtime_error("Class \"HybridNativeStorageSpec\" is not implemented in Swift!");
|
|
84
|
+
}
|
|
85
|
+
#endif
|
|
86
|
+
NitroFetch::HybridNativeStorageSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
|
|
87
|
+
return swiftPart.toUnsafe();
|
|
88
|
+
}
|
|
72
89
|
|
|
73
90
|
} // namespace margelo::nitro::nitrofetch::bridge::swift
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
10
|
// Forward declarations of C++ defined types
|
|
11
|
+
// Forward declaration of `HybridNativeStorageSpec` to properly resolve imports.
|
|
12
|
+
namespace margelo::nitro::nitrofetch { class HybridNativeStorageSpec; }
|
|
11
13
|
// Forward declaration of `HybridNitroFetchClientSpec` to properly resolve imports.
|
|
12
14
|
namespace margelo::nitro::nitrofetch { class HybridNitroFetchClientSpec; }
|
|
13
15
|
// Forward declaration of `HybridNitroFetchSpec` to properly resolve imports.
|
|
@@ -20,12 +22,15 @@ namespace margelo::nitro::nitrofetch { enum class NitroRequestMethod; }
|
|
|
20
22
|
namespace margelo::nitro::nitrofetch { struct NitroResponse; }
|
|
21
23
|
|
|
22
24
|
// Forward declarations of Swift defined types
|
|
25
|
+
// Forward declaration of `HybridNativeStorageSpec_cxx` to properly resolve imports.
|
|
26
|
+
namespace NitroFetch { class HybridNativeStorageSpec_cxx; }
|
|
23
27
|
// Forward declaration of `HybridNitroFetchClientSpec_cxx` to properly resolve imports.
|
|
24
28
|
namespace NitroFetch { class HybridNitroFetchClientSpec_cxx; }
|
|
25
29
|
// Forward declaration of `HybridNitroFetchSpec_cxx` to properly resolve imports.
|
|
26
30
|
namespace NitroFetch { class HybridNitroFetchSpec_cxx; }
|
|
27
31
|
|
|
28
32
|
// Include C++ defined types
|
|
33
|
+
#include "HybridNativeStorageSpec.hpp"
|
|
29
34
|
#include "HybridNitroFetchClientSpec.hpp"
|
|
30
35
|
#include "HybridNitroFetchSpec.hpp"
|
|
31
36
|
#include "NitroHeader.hpp"
|
|
@@ -253,6 +258,15 @@ namespace margelo::nitro::nitrofetch::bridge::swift {
|
|
|
253
258
|
return Result<std::shared_ptr<Promise<void>>>::withError(error);
|
|
254
259
|
}
|
|
255
260
|
|
|
261
|
+
// pragma MARK: Result<NitroResponse>
|
|
262
|
+
using Result_NitroResponse_ = Result<NitroResponse>;
|
|
263
|
+
inline Result_NitroResponse_ create_Result_NitroResponse_(const NitroResponse& value) noexcept {
|
|
264
|
+
return Result<NitroResponse>::withValue(value);
|
|
265
|
+
}
|
|
266
|
+
inline Result_NitroResponse_ create_Result_NitroResponse_(const std::exception_ptr& error) noexcept {
|
|
267
|
+
return Result<NitroResponse>::withError(error);
|
|
268
|
+
}
|
|
269
|
+
|
|
256
270
|
// pragma MARK: std::shared_ptr<HybridNitroFetchSpec>
|
|
257
271
|
/**
|
|
258
272
|
* Specialized version of `std::shared_ptr<HybridNitroFetchSpec>`.
|
|
@@ -273,5 +287,35 @@ namespace margelo::nitro::nitrofetch::bridge::swift {
|
|
|
273
287
|
inline Result_std__shared_ptr_HybridNitroFetchClientSpec__ create_Result_std__shared_ptr_HybridNitroFetchClientSpec__(const std::exception_ptr& error) noexcept {
|
|
274
288
|
return Result<std::shared_ptr<HybridNitroFetchClientSpec>>::withError(error);
|
|
275
289
|
}
|
|
290
|
+
|
|
291
|
+
// pragma MARK: std::shared_ptr<HybridNativeStorageSpec>
|
|
292
|
+
/**
|
|
293
|
+
* Specialized version of `std::shared_ptr<HybridNativeStorageSpec>`.
|
|
294
|
+
*/
|
|
295
|
+
using std__shared_ptr_HybridNativeStorageSpec_ = std::shared_ptr<HybridNativeStorageSpec>;
|
|
296
|
+
std::shared_ptr<HybridNativeStorageSpec> create_std__shared_ptr_HybridNativeStorageSpec_(void* _Nonnull swiftUnsafePointer) noexcept;
|
|
297
|
+
void* _Nonnull get_std__shared_ptr_HybridNativeStorageSpec_(std__shared_ptr_HybridNativeStorageSpec_ cppType) noexcept;
|
|
298
|
+
|
|
299
|
+
// pragma MARK: std::weak_ptr<HybridNativeStorageSpec>
|
|
300
|
+
using std__weak_ptr_HybridNativeStorageSpec_ = std::weak_ptr<HybridNativeStorageSpec>;
|
|
301
|
+
inline std__weak_ptr_HybridNativeStorageSpec_ weakify_std__shared_ptr_HybridNativeStorageSpec_(const std::shared_ptr<HybridNativeStorageSpec>& strong) noexcept { return strong; }
|
|
302
|
+
|
|
303
|
+
// pragma MARK: Result<std::string>
|
|
304
|
+
using Result_std__string_ = Result<std::string>;
|
|
305
|
+
inline Result_std__string_ create_Result_std__string_(const std::string& value) noexcept {
|
|
306
|
+
return Result<std::string>::withValue(value);
|
|
307
|
+
}
|
|
308
|
+
inline Result_std__string_ create_Result_std__string_(const std::exception_ptr& error) noexcept {
|
|
309
|
+
return Result<std::string>::withError(error);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// pragma MARK: Result<void>
|
|
313
|
+
using Result_void_ = Result<void>;
|
|
314
|
+
inline Result_void_ create_Result_void_() noexcept {
|
|
315
|
+
return Result<void>::withValue();
|
|
316
|
+
}
|
|
317
|
+
inline Result_void_ create_Result_void_(const std::exception_ptr& error) noexcept {
|
|
318
|
+
return Result<void>::withError(error);
|
|
319
|
+
}
|
|
276
320
|
|
|
277
321
|
} // namespace margelo::nitro::nitrofetch::bridge::swift
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
10
|
// Forward declarations of C++ defined types
|
|
11
|
+
// Forward declaration of `HybridNativeStorageSpec` to properly resolve imports.
|
|
12
|
+
namespace margelo::nitro::nitrofetch { class HybridNativeStorageSpec; }
|
|
11
13
|
// Forward declaration of `HybridNitroFetchClientSpec` to properly resolve imports.
|
|
12
14
|
namespace margelo::nitro::nitrofetch { class HybridNitroFetchClientSpec; }
|
|
13
15
|
// Forward declaration of `HybridNitroFetchSpec` to properly resolve imports.
|
|
@@ -22,6 +24,7 @@ namespace margelo::nitro::nitrofetch { struct NitroRequest; }
|
|
|
22
24
|
namespace margelo::nitro::nitrofetch { struct NitroResponse; }
|
|
23
25
|
|
|
24
26
|
// Include C++ defined types
|
|
27
|
+
#include "HybridNativeStorageSpec.hpp"
|
|
25
28
|
#include "HybridNitroFetchClientSpec.hpp"
|
|
26
29
|
#include "HybridNitroFetchSpec.hpp"
|
|
27
30
|
#include "NitroHeader.hpp"
|
|
@@ -46,6 +49,8 @@ namespace margelo::nitro::nitrofetch { struct NitroResponse; }
|
|
|
46
49
|
#include <NitroModules/DateToChronoDate.hpp>
|
|
47
50
|
|
|
48
51
|
// Forward declarations of Swift defined types
|
|
52
|
+
// Forward declaration of `HybridNativeStorageSpec_cxx` to properly resolve imports.
|
|
53
|
+
namespace NitroFetch { class HybridNativeStorageSpec_cxx; }
|
|
49
54
|
// Forward declaration of `HybridNitroFetchClientSpec_cxx` to properly resolve imports.
|
|
50
55
|
namespace NitroFetch { class HybridNitroFetchClientSpec_cxx; }
|
|
51
56
|
// Forward declaration of `HybridNitroFetchSpec_cxx` to properly resolve imports.
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
#include "HybridNitroFetchSpecSwift.hpp"
|
|
14
14
|
#include "HybridNitroFetchClientSpecSwift.hpp"
|
|
15
|
+
#include "HybridNativeStorageSpecSwift.hpp"
|
|
15
16
|
|
|
16
17
|
@interface NitroFetchAutolinking : NSObject
|
|
17
18
|
@end
|
|
@@ -36,6 +37,13 @@
|
|
|
36
37
|
return hybridObject;
|
|
37
38
|
}
|
|
38
39
|
);
|
|
40
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
41
|
+
"NativeStorage",
|
|
42
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
43
|
+
std::shared_ptr<HybridNativeStorageSpec> hybridObject = NitroFetch::NitroFetchAutolinking::createNativeStorage();
|
|
44
|
+
return hybridObject;
|
|
45
|
+
}
|
|
46
|
+
);
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
@end
|
|
@@ -37,4 +37,19 @@ public final class NitroFetchAutolinking {
|
|
|
37
37
|
return __cxxWrapped.getCxxPart()
|
|
38
38
|
}()
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates an instance of a Swift class that implements `HybridNativeStorageSpec`,
|
|
43
|
+
* and wraps it in a Swift class that can directly interop with C++ (`HybridNativeStorageSpec_cxx`)
|
|
44
|
+
*
|
|
45
|
+
* This is generated by Nitrogen and will initialize the class specified
|
|
46
|
+
* in the `"autolinking"` property of `nitro.json` (in this case, `NativeStorage`).
|
|
47
|
+
*/
|
|
48
|
+
public static func createNativeStorage() -> bridge.std__shared_ptr_HybridNativeStorageSpec_ {
|
|
49
|
+
let hybridObject = NativeStorage()
|
|
50
|
+
return { () -> bridge.std__shared_ptr_HybridNativeStorageSpec_ in
|
|
51
|
+
let __cxxWrapped = hybridObject.getCxxWrapper()
|
|
52
|
+
return __cxxWrapped.getCxxPart()
|
|
53
|
+
}()
|
|
54
|
+
}
|
|
40
55
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeStorageSpecSwift.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridNativeStorageSpecSwift.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::nitrofetch {
|
|
11
|
+
} // namespace margelo::nitro::nitrofetch
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeStorageSpecSwift.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "HybridNativeStorageSpec.hpp"
|
|
11
|
+
|
|
12
|
+
// Forward declaration of `HybridNativeStorageSpec_cxx` to properly resolve imports.
|
|
13
|
+
namespace NitroFetch { class HybridNativeStorageSpec_cxx; }
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
#include <string>
|
|
18
|
+
|
|
19
|
+
#include "NitroFetch-Swift-Cxx-Umbrella.hpp"
|
|
20
|
+
|
|
21
|
+
namespace margelo::nitro::nitrofetch {
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The C++ part of HybridNativeStorageSpec_cxx.swift.
|
|
25
|
+
*
|
|
26
|
+
* HybridNativeStorageSpecSwift (C++) accesses HybridNativeStorageSpec_cxx (Swift), and might
|
|
27
|
+
* contain some additional bridging code for C++ <> Swift interop.
|
|
28
|
+
*
|
|
29
|
+
* Since this obviously introduces an overhead, I hope at some point in
|
|
30
|
+
* the future, HybridNativeStorageSpec_cxx can directly inherit from the C++ class HybridNativeStorageSpec
|
|
31
|
+
* to simplify the whole structure and memory management.
|
|
32
|
+
*/
|
|
33
|
+
class HybridNativeStorageSpecSwift: public virtual HybridNativeStorageSpec {
|
|
34
|
+
public:
|
|
35
|
+
// Constructor from a Swift instance
|
|
36
|
+
explicit HybridNativeStorageSpecSwift(const NitroFetch::HybridNativeStorageSpec_cxx& swiftPart):
|
|
37
|
+
HybridObject(HybridNativeStorageSpec::TAG),
|
|
38
|
+
_swiftPart(swiftPart) { }
|
|
39
|
+
|
|
40
|
+
public:
|
|
41
|
+
// Get the Swift part
|
|
42
|
+
inline NitroFetch::HybridNativeStorageSpec_cxx& getSwiftPart() noexcept {
|
|
43
|
+
return _swiftPart;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
inline size_t getExternalMemorySize() noexcept override {
|
|
48
|
+
return _swiftPart.getMemorySize();
|
|
49
|
+
}
|
|
50
|
+
void dispose() noexcept override {
|
|
51
|
+
_swiftPart.dispose();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
// Properties
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
// Methods
|
|
60
|
+
inline std::string getString(const std::string& key) override {
|
|
61
|
+
auto __result = _swiftPart.getString(key);
|
|
62
|
+
if (__result.hasError()) [[unlikely]] {
|
|
63
|
+
std::rethrow_exception(__result.error());
|
|
64
|
+
}
|
|
65
|
+
auto __value = std::move(__result.value());
|
|
66
|
+
return __value;
|
|
67
|
+
}
|
|
68
|
+
inline void setString(const std::string& key, const std::string& value) override {
|
|
69
|
+
auto __result = _swiftPart.setString(key, value);
|
|
70
|
+
if (__result.hasError()) [[unlikely]] {
|
|
71
|
+
std::rethrow_exception(__result.error());
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
inline void removeString(const std::string& key) override {
|
|
75
|
+
auto __result = _swiftPart.removeString(key);
|
|
76
|
+
if (__result.hasError()) [[unlikely]] {
|
|
77
|
+
std::rethrow_exception(__result.error());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private:
|
|
82
|
+
NitroFetch::HybridNativeStorageSpec_cxx _swiftPart;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
} // namespace margelo::nitro::nitrofetch
|
|
@@ -87,6 +87,14 @@ namespace margelo::nitro::nitrofetch {
|
|
|
87
87
|
auto __value = std::move(__result.value());
|
|
88
88
|
return __value;
|
|
89
89
|
}
|
|
90
|
+
inline NitroResponse requestSync(const NitroRequest& req) override {
|
|
91
|
+
auto __result = _swiftPart.requestSync(req);
|
|
92
|
+
if (__result.hasError()) [[unlikely]] {
|
|
93
|
+
std::rethrow_exception(__result.error());
|
|
94
|
+
}
|
|
95
|
+
auto __value = std::move(__result.value());
|
|
96
|
+
return __value;
|
|
97
|
+
}
|
|
90
98
|
|
|
91
99
|
private:
|
|
92
100
|
NitroFetch::HybridNitroFetchClientSpec_cxx _swiftPart;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeStorageSpec.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/// See ``HybridNativeStorageSpec``
|
|
12
|
+
public protocol HybridNativeStorageSpec_protocol: HybridObject {
|
|
13
|
+
// Properties
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// Methods
|
|
17
|
+
func getString(key: String) throws -> String
|
|
18
|
+
func setString(key: String, value: String) throws -> Void
|
|
19
|
+
func removeString(key: String) throws -> Void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// See ``HybridNativeStorageSpec``
|
|
23
|
+
open class HybridNativeStorageSpec_base {
|
|
24
|
+
private weak var cxxWrapper: HybridNativeStorageSpec_cxx? = nil
|
|
25
|
+
public init() { }
|
|
26
|
+
public func getCxxWrapper() -> HybridNativeStorageSpec_cxx {
|
|
27
|
+
#if DEBUG
|
|
28
|
+
guard self is HybridNativeStorageSpec else {
|
|
29
|
+
fatalError("`self` is not a `HybridNativeStorageSpec`! Did you accidentally inherit from `HybridNativeStorageSpec_base` instead of `HybridNativeStorageSpec`?")
|
|
30
|
+
}
|
|
31
|
+
#endif
|
|
32
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
33
|
+
return cxxWrapper
|
|
34
|
+
} else {
|
|
35
|
+
let cxxWrapper = HybridNativeStorageSpec_cxx(self as! HybridNativeStorageSpec)
|
|
36
|
+
self.cxxWrapper = cxxWrapper
|
|
37
|
+
return cxxWrapper
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A Swift base-protocol representing the NativeStorage HybridObject.
|
|
44
|
+
* Implement this protocol to create Swift-based instances of NativeStorage.
|
|
45
|
+
* ```swift
|
|
46
|
+
* class HybridNativeStorage : HybridNativeStorageSpec {
|
|
47
|
+
* // ...
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
public typealias HybridNativeStorageSpec = HybridNativeStorageSpec_protocol & HybridNativeStorageSpec_base
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeStorageSpec_cxx.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A class implementation that bridges HybridNativeStorageSpec over to C++.
|
|
13
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
14
|
+
*
|
|
15
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
16
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
17
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
18
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
19
|
+
*/
|
|
20
|
+
open class HybridNativeStorageSpec_cxx {
|
|
21
|
+
/**
|
|
22
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::nitrofetch::bridge::swift`)
|
|
23
|
+
* from `NitroFetch-Swift-Cxx-Bridge.hpp`.
|
|
24
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
25
|
+
*/
|
|
26
|
+
public typealias bridge = margelo.nitro.nitrofetch.bridge.swift
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Holds an instance of the `HybridNativeStorageSpec` Swift protocol.
|
|
30
|
+
*/
|
|
31
|
+
private var __implementation: any HybridNativeStorageSpec
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
35
|
+
*/
|
|
36
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridNativeStorageSpec_
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new `HybridNativeStorageSpec_cxx` that wraps the given `HybridNativeStorageSpec`.
|
|
40
|
+
* All properties and methods bridge to C++ types.
|
|
41
|
+
*/
|
|
42
|
+
public init(_ implementation: any HybridNativeStorageSpec) {
|
|
43
|
+
self.__implementation = implementation
|
|
44
|
+
self.__cxxPart = .init()
|
|
45
|
+
/* no base class */
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the actual `HybridNativeStorageSpec` instance this class wraps.
|
|
50
|
+
*/
|
|
51
|
+
@inline(__always)
|
|
52
|
+
public func getHybridNativeStorageSpec() -> any HybridNativeStorageSpec {
|
|
53
|
+
return __implementation
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
58
|
+
* This acquires one additional strong reference on the object!
|
|
59
|
+
*/
|
|
60
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
61
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Casts an unsafe pointer to a `HybridNativeStorageSpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridNativeStorageSpec_cxx>`.
|
|
67
|
+
* This removes one strong reference from the object!
|
|
68
|
+
*/
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridNativeStorageSpec_cxx {
|
|
70
|
+
return Unmanaged<HybridNativeStorageSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
75
|
+
* The C++ part is a `std::shared_ptr<HybridNativeStorageSpec>`.
|
|
76
|
+
*/
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridNativeStorageSpec_ {
|
|
78
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
+
if cachedCxxPart.__convertToBool() {
|
|
80
|
+
return cachedCxxPart
|
|
81
|
+
} else {
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridNativeStorageSpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridNativeStorageSpec_(newCxxPart)
|
|
84
|
+
return newCxxPart
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
92
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
93
|
+
*/
|
|
94
|
+
@inline(__always)
|
|
95
|
+
public var memorySize: Int {
|
|
96
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Call dispose() on the Swift class.
|
|
101
|
+
* This _may_ be called manually from JS.
|
|
102
|
+
*/
|
|
103
|
+
@inline(__always)
|
|
104
|
+
public func dispose() {
|
|
105
|
+
self.__implementation.dispose()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Properties
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
// Methods
|
|
112
|
+
@inline(__always)
|
|
113
|
+
public final func getString(key: std.string) -> bridge.Result_std__string_ {
|
|
114
|
+
do {
|
|
115
|
+
let __result = try self.__implementation.getString(key: String(key))
|
|
116
|
+
let __resultCpp = std.string(__result)
|
|
117
|
+
return bridge.create_Result_std__string_(__resultCpp)
|
|
118
|
+
} catch (let __error) {
|
|
119
|
+
let __exceptionPtr = __error.toCpp()
|
|
120
|
+
return bridge.create_Result_std__string_(__exceptionPtr)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@inline(__always)
|
|
125
|
+
public final func setString(key: std.string, value: std.string) -> bridge.Result_void_ {
|
|
126
|
+
do {
|
|
127
|
+
try self.__implementation.setString(key: String(key), value: String(value))
|
|
128
|
+
return bridge.create_Result_void_()
|
|
129
|
+
} catch (let __error) {
|
|
130
|
+
let __exceptionPtr = __error.toCpp()
|
|
131
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@inline(__always)
|
|
136
|
+
public final func removeString(key: std.string) -> bridge.Result_void_ {
|
|
137
|
+
do {
|
|
138
|
+
try self.__implementation.removeString(key: String(key))
|
|
139
|
+
return bridge.create_Result_void_()
|
|
140
|
+
} catch (let __error) {
|
|
141
|
+
let __exceptionPtr = __error.toCpp()
|
|
142
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -16,6 +16,7 @@ public protocol HybridNitroFetchClientSpec_protocol: HybridObject {
|
|
|
16
16
|
// Methods
|
|
17
17
|
func request(req: NitroRequest) throws -> Promise<NitroResponse>
|
|
18
18
|
func prefetch(req: NitroRequest) throws -> Promise<Void>
|
|
19
|
+
func requestSync(req: NitroRequest) throws -> NitroResponse
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
/// See ``HybridNitroFetchClientSpec``
|
|
@@ -146,4 +146,16 @@ open class HybridNitroFetchClientSpec_cxx {
|
|
|
146
146
|
return bridge.create_Result_std__shared_ptr_Promise_void___(__exceptionPtr)
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
+
|
|
150
|
+
@inline(__always)
|
|
151
|
+
public final func requestSync(req: NitroRequest) -> bridge.Result_NitroResponse_ {
|
|
152
|
+
do {
|
|
153
|
+
let __result = try self.__implementation.requestSync(req: req)
|
|
154
|
+
let __resultCpp = __result
|
|
155
|
+
return bridge.create_Result_NitroResponse_(__resultCpp)
|
|
156
|
+
} catch (let __error) {
|
|
157
|
+
let __exceptionPtr = __error.toCpp()
|
|
158
|
+
return bridge.create_Result_NitroResponse_(__exceptionPtr)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
149
161
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNativeStorageSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridNativeStorageSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::nitrofetch {
|
|
11
|
+
|
|
12
|
+
void HybridNativeStorageSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("getString", &HybridNativeStorageSpec::getString);
|
|
18
|
+
prototype.registerHybridMethod("setString", &HybridNativeStorageSpec::setString);
|
|
19
|
+
prototype.registerHybridMethod("removeString", &HybridNativeStorageSpec::removeString);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
} // namespace margelo::nitro::nitrofetch
|