react-native-mmkv 4.0.0-beta.1 → 4.0.0-beta.11

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 (226) hide show
  1. package/NitroMmkv.podspec +44 -0
  2. package/README.md +1 -3
  3. package/android/CMakeLists.txt +31 -30
  4. package/android/build.gradle +66 -21
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -5
  7. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  8. package/android/src/main/java/com/margelo/nitro/mmkv/HybridMMKVPlatformContext.kt +19 -0
  9. package/android/src/main/java/com/margelo/nitro/mmkv/NitroMmkvPackage.java +33 -0
  10. package/cpp/HybridMMKV.cpp +184 -0
  11. package/cpp/HybridMMKV.hpp +47 -0
  12. package/cpp/HybridMMKVFactory.cpp +33 -0
  13. package/cpp/HybridMMKVFactory.hpp +24 -0
  14. package/cpp/{MmkvTypes.h → MMKVTypes.hpp} +1 -1
  15. package/cpp/MMKVValueChangedListenerRegistry.cpp +58 -0
  16. package/cpp/MMKVValueChangedListenerRegistry.hpp +43 -0
  17. package/cpp/{ManagedMMBuffer.h → ManagedMMBuffer.hpp} +13 -5
  18. package/ios/HybridMMKVPlatformContext.swift +43 -0
  19. package/lib/__tests__/hooks.test.d.ts +1 -0
  20. package/lib/__tests__/hooks.test.js +69 -0
  21. package/lib/addMemoryWarningListener/addMemoryWarningListener.d.ts +2 -0
  22. package/lib/addMemoryWarningListener/addMemoryWarningListener.js +25 -0
  23. package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.d.ts +2 -0
  24. package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.js +3 -0
  25. package/lib/addMemoryWarningListener/addMemoryWarningListener.web.d.ts +2 -0
  26. package/lib/addMemoryWarningListener/addMemoryWarningListener.web.js +3 -0
  27. package/lib/createMMKV/createMMKV.d.ts +3 -0
  28. package/lib/createMMKV/createMMKV.js +40 -0
  29. package/lib/createMMKV/createMMKV.web.d.ts +3 -0
  30. package/lib/createMMKV/createMMKV.web.js +117 -0
  31. package/lib/createMMKV/createMockMMKV.d.ts +5 -0
  32. package/lib/createMMKV/createMockMMKV.js +74 -0
  33. package/lib/createMMKV/getDefaultMMKVInstance.d.ts +2 -0
  34. package/lib/createMMKV/getDefaultMMKVInstance.js +8 -0
  35. package/lib/hooks/createMMKVHook.d.ts +2 -0
  36. package/lib/hooks/createMMKVHook.js +49 -0
  37. package/lib/hooks/useMMKV.d.ts +11 -0
  38. package/lib/hooks/useMMKV.js +23 -0
  39. package/lib/hooks/useMMKVBoolean.d.ts +11 -0
  40. package/lib/hooks/useMMKVBoolean.js +12 -0
  41. package/lib/hooks/useMMKVBuffer.d.ts +11 -0
  42. package/lib/hooks/useMMKVBuffer.js +12 -0
  43. package/lib/hooks/useMMKVKeys.d.ts +12 -0
  44. package/lib/hooks/useMMKVKeys.js +33 -0
  45. package/lib/hooks/useMMKVListener.d.ts +15 -0
  46. package/lib/hooks/useMMKVListener.js +26 -0
  47. package/lib/hooks/useMMKVNumber.d.ts +11 -0
  48. package/lib/hooks/useMMKVNumber.js +12 -0
  49. package/lib/hooks/useMMKVObject.d.ts +17 -0
  50. package/lib/hooks/useMMKVObject.js +38 -0
  51. package/lib/hooks/useMMKVString.d.ts +11 -0
  52. package/lib/hooks/useMMKVString.js +12 -0
  53. package/lib/index.d.ts +11 -0
  54. package/lib/index.js +11 -0
  55. package/lib/isTest.d.ts +1 -0
  56. package/lib/isTest.js +7 -0
  57. package/lib/specs/MMKV.nitro.d.ts +94 -0
  58. package/lib/specs/MMKV.nitro.js +1 -0
  59. package/lib/{typescript/src/NativeMmkv.d.ts → specs/MMKVFactory.nitro.d.ts} +26 -33
  60. package/lib/specs/MMKVFactory.nitro.js +1 -0
  61. package/lib/specs/MMKVPlatformContext.nitro.d.ts +18 -0
  62. package/lib/specs/MMKVPlatformContext.nitro.js +1 -0
  63. package/lib/{typescript/src → web}/createTextEncoder.d.ts +0 -1
  64. package/lib/web/createTextEncoder.js +17 -0
  65. package/nitro.json +28 -0
  66. package/nitrogen/generated/.gitattributes +1 -0
  67. package/nitrogen/generated/android/NitroMmkv+autolinking.cmake +80 -0
  68. package/nitrogen/generated/android/NitroMmkv+autolinking.gradle +27 -0
  69. package/nitrogen/generated/android/NitroMmkvOnLoad.cpp +54 -0
  70. package/nitrogen/generated/android/NitroMmkvOnLoad.hpp +25 -0
  71. package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.cpp +52 -0
  72. package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.hpp +65 -0
  73. package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/HybridMMKVPlatformContextSpec.kt +56 -0
  74. package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/NitroMmkvOnLoad.kt +35 -0
  75. package/nitrogen/generated/ios/NitroMmkv+autolinking.rb +60 -0
  76. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.cpp +32 -0
  77. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.hpp +77 -0
  78. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Umbrella.hpp +45 -0
  79. package/nitrogen/generated/ios/NitroMmkvAutolinking.mm +43 -0
  80. package/nitrogen/generated/ios/NitroMmkvAutolinking.swift +25 -0
  81. package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.cpp +11 -0
  82. package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.hpp +82 -0
  83. package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec.swift +50 -0
  84. package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec_cxx.swift +141 -0
  85. package/nitrogen/generated/shared/c++/Configuration.hpp +86 -0
  86. package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.cpp +23 -0
  87. package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.hpp +69 -0
  88. package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.cpp +22 -0
  89. package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.hpp +64 -0
  90. package/nitrogen/generated/shared/c++/HybridMMKVSpec.cpp +34 -0
  91. package/nitrogen/generated/shared/c++/HybridMMKVSpec.hpp +83 -0
  92. package/nitrogen/generated/shared/c++/Listener.hpp +67 -0
  93. package/nitrogen/generated/shared/c++/Mode.hpp +76 -0
  94. package/package.json +74 -122
  95. package/react-native.config.js +2 -15
  96. package/src/__tests__/hooks.test.tsx +39 -34
  97. package/src/addMemoryWarningListener/addMemoryWarningListener.mock.ts +5 -0
  98. package/src/{MemoryWarningListener.ts → addMemoryWarningListener/addMemoryWarningListener.ts} +12 -12
  99. package/src/addMemoryWarningListener/addMemoryWarningListener.web.ts +5 -0
  100. package/src/createMMKV/createMMKV.ts +51 -0
  101. package/src/{createMMKV.web.ts → createMMKV/createMMKV.web.ts} +58 -46
  102. package/src/createMMKV/createMockMMKV.ts +78 -0
  103. package/src/createMMKV/getDefaultMMKVInstance.ts +10 -0
  104. package/src/hooks/createMMKVHook.ts +66 -0
  105. package/src/hooks/useMMKV.ts +45 -0
  106. package/src/hooks/useMMKVBoolean.ts +15 -0
  107. package/src/hooks/useMMKVBuffer.ts +15 -0
  108. package/src/hooks/useMMKVKeys.ts +36 -0
  109. package/src/hooks/useMMKVListener.ts +33 -0
  110. package/src/hooks/useMMKVNumber.ts +15 -0
  111. package/src/hooks/useMMKVObject.ts +53 -0
  112. package/src/hooks/useMMKVString.ts +15 -0
  113. package/src/index.ts +15 -3
  114. package/src/{PlatformChecker.ts → isTest.ts} +2 -2
  115. package/src/specs/MMKV.nitro.ts +93 -0
  116. package/src/specs/MMKVFactory.nitro.ts +87 -0
  117. package/src/specs/MMKVPlatformContext.nitro.ts +17 -0
  118. package/src/{createTextEncoder.ts → web/createTextEncoder.ts} +7 -7
  119. package/android/src/main/cpp/AndroidLogger.cpp +0 -16
  120. package/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java +0 -44
  121. package/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java +0 -26
  122. package/cpp/MmkvHostObject.cpp +0 -360
  123. package/cpp/MmkvHostObject.h +0 -31
  124. package/cpp/MmkvLogger.h +0 -35
  125. package/cpp/NativeMmkvModule.cpp +0 -43
  126. package/cpp/NativeMmkvModule.h +0 -31
  127. package/ios/AppleLogger.mm +0 -16
  128. package/ios/MmkvOnLoad.mm +0 -25
  129. package/ios/MmkvPlatformContext.h +0 -19
  130. package/ios/MmkvPlatformContextModule.mm +0 -55
  131. package/lib/commonjs/MMKV.js +0 -124
  132. package/lib/commonjs/MMKV.js.map +0 -1
  133. package/lib/commonjs/MemoryWarningListener.js +0 -31
  134. package/lib/commonjs/MemoryWarningListener.js.map +0 -1
  135. package/lib/commonjs/MemoryWarningListener.web.js +0 -11
  136. package/lib/commonjs/MemoryWarningListener.web.js.map +0 -1
  137. package/lib/commonjs/ModuleNotFoundError.js +0 -75
  138. package/lib/commonjs/ModuleNotFoundError.js.map +0 -1
  139. package/lib/commonjs/NativeMmkv.js +0 -47
  140. package/lib/commonjs/NativeMmkv.js.map +0 -1
  141. package/lib/commonjs/NativeMmkvPlatformContext.js +0 -22
  142. package/lib/commonjs/NativeMmkvPlatformContext.js.map +0 -1
  143. package/lib/commonjs/PlatformChecker.js +0 -14
  144. package/lib/commonjs/PlatformChecker.js.map +0 -1
  145. package/lib/commonjs/Types.js +0 -26
  146. package/lib/commonjs/Types.js.map +0 -1
  147. package/lib/commonjs/createMMKV.js +0 -43
  148. package/lib/commonjs/createMMKV.js.map +0 -1
  149. package/lib/commonjs/createMMKV.mock.js +0 -43
  150. package/lib/commonjs/createMMKV.mock.js.map +0 -1
  151. package/lib/commonjs/createMMKV.web.js +0 -110
  152. package/lib/commonjs/createMMKV.web.js.map +0 -1
  153. package/lib/commonjs/createTextEncoder.js +0 -23
  154. package/lib/commonjs/createTextEncoder.js.map +0 -1
  155. package/lib/commonjs/hooks.js +0 -198
  156. package/lib/commonjs/hooks.js.map +0 -1
  157. package/lib/commonjs/index.js +0 -40
  158. package/lib/commonjs/index.js.map +0 -1
  159. package/lib/commonjs/package.json +0 -1
  160. package/lib/module/MMKV.js +0 -119
  161. package/lib/module/MMKV.js.map +0 -1
  162. package/lib/module/MemoryWarningListener.js +0 -27
  163. package/lib/module/MemoryWarningListener.js.map +0 -1
  164. package/lib/module/MemoryWarningListener.web.js +0 -6
  165. package/lib/module/MemoryWarningListener.web.js.map +0 -1
  166. package/lib/module/ModuleNotFoundError.js +0 -70
  167. package/lib/module/ModuleNotFoundError.js.map +0 -1
  168. package/lib/module/NativeMmkv.js +0 -45
  169. package/lib/module/NativeMmkv.js.map +0 -1
  170. package/lib/module/NativeMmkvPlatformContext.js +0 -18
  171. package/lib/module/NativeMmkvPlatformContext.js.map +0 -1
  172. package/lib/module/PlatformChecker.js +0 -10
  173. package/lib/module/PlatformChecker.js.map +0 -1
  174. package/lib/module/Types.js +0 -25
  175. package/lib/module/Types.js.map +0 -1
  176. package/lib/module/createMMKV.js +0 -38
  177. package/lib/module/createMMKV.js.map +0 -1
  178. package/lib/module/createMMKV.mock.js +0 -38
  179. package/lib/module/createMMKV.mock.js.map +0 -1
  180. package/lib/module/createMMKV.web.js +0 -105
  181. package/lib/module/createMMKV.web.js.map +0 -1
  182. package/lib/module/createTextEncoder.js +0 -19
  183. package/lib/module/createTextEncoder.js.map +0 -1
  184. package/lib/module/hooks.js +0 -189
  185. package/lib/module/hooks.js.map +0 -1
  186. package/lib/module/index.js +0 -6
  187. package/lib/module/index.js.map +0 -1
  188. package/lib/module/package.json +0 -1
  189. package/lib/typescript/src/MMKV.d.ts +0 -34
  190. package/lib/typescript/src/MMKV.d.ts.map +0 -1
  191. package/lib/typescript/src/MemoryWarningListener.d.ts +0 -3
  192. package/lib/typescript/src/MemoryWarningListener.d.ts.map +0 -1
  193. package/lib/typescript/src/MemoryWarningListener.web.d.ts +0 -3
  194. package/lib/typescript/src/MemoryWarningListener.web.d.ts.map +0 -1
  195. package/lib/typescript/src/ModuleNotFoundError.d.ts +0 -7
  196. package/lib/typescript/src/ModuleNotFoundError.d.ts.map +0 -1
  197. package/lib/typescript/src/NativeMmkv.d.ts.map +0 -1
  198. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts +0 -20
  199. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +0 -1
  200. package/lib/typescript/src/PlatformChecker.d.ts +0 -2
  201. package/lib/typescript/src/PlatformChecker.d.ts.map +0 -1
  202. package/lib/typescript/src/Types.d.ts +0 -172
  203. package/lib/typescript/src/Types.d.ts.map +0 -1
  204. package/lib/typescript/src/__tests__/hooks.test.d.ts +0 -2
  205. package/lib/typescript/src/__tests__/hooks.test.d.ts.map +0 -1
  206. package/lib/typescript/src/createMMKV.d.ts +0 -3
  207. package/lib/typescript/src/createMMKV.d.ts.map +0 -1
  208. package/lib/typescript/src/createMMKV.mock.d.ts +0 -3
  209. package/lib/typescript/src/createMMKV.mock.d.ts.map +0 -1
  210. package/lib/typescript/src/createMMKV.web.d.ts +0 -3
  211. package/lib/typescript/src/createMMKV.web.d.ts.map +0 -1
  212. package/lib/typescript/src/createTextEncoder.d.ts.map +0 -1
  213. package/lib/typescript/src/hooks.d.ts +0 -86
  214. package/lib/typescript/src/hooks.d.ts.map +0 -1
  215. package/lib/typescript/src/index.d.ts +0 -4
  216. package/lib/typescript/src/index.d.ts.map +0 -1
  217. package/react-native-mmkv.podspec +0 -32
  218. package/src/MMKV.ts +0 -142
  219. package/src/MemoryWarningListener.web.ts +0 -5
  220. package/src/ModuleNotFoundError.ts +0 -95
  221. package/src/NativeMmkv.ts +0 -118
  222. package/src/NativeMmkvPlatformContext.ts +0 -38
  223. package/src/Types.ts +0 -178
  224. package/src/createMMKV.mock.ts +0 -38
  225. package/src/createMMKV.ts +0 -42
  226. package/src/hooks.ts +0 -247
@@ -0,0 +1,82 @@
1
+ ///
2
+ /// HybridMMKVPlatformContextSpecSwift.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 "HybridMMKVPlatformContextSpec.hpp"
11
+
12
+ // Forward declaration of `HybridMMKVPlatformContextSpec_cxx` to properly resolve imports.
13
+ namespace NitroMmkv { class HybridMMKVPlatformContextSpec_cxx; }
14
+
15
+
16
+
17
+ #include <string>
18
+ #include <optional>
19
+
20
+ #include "NitroMmkv-Swift-Cxx-Umbrella.hpp"
21
+
22
+ namespace margelo::nitro::mmkv {
23
+
24
+ /**
25
+ * The C++ part of HybridMMKVPlatformContextSpec_cxx.swift.
26
+ *
27
+ * HybridMMKVPlatformContextSpecSwift (C++) accesses HybridMMKVPlatformContextSpec_cxx (Swift), and might
28
+ * contain some additional bridging code for C++ <> Swift interop.
29
+ *
30
+ * Since this obviously introduces an overhead, I hope at some point in
31
+ * the future, HybridMMKVPlatformContextSpec_cxx can directly inherit from the C++ class HybridMMKVPlatformContextSpec
32
+ * to simplify the whole structure and memory management.
33
+ */
34
+ class HybridMMKVPlatformContextSpecSwift: public virtual HybridMMKVPlatformContextSpec {
35
+ public:
36
+ // Constructor from a Swift instance
37
+ explicit HybridMMKVPlatformContextSpecSwift(const NitroMmkv::HybridMMKVPlatformContextSpec_cxx& swiftPart):
38
+ HybridObject(HybridMMKVPlatformContextSpec::TAG),
39
+ _swiftPart(swiftPart) { }
40
+
41
+ public:
42
+ // Get the Swift part
43
+ inline NitroMmkv::HybridMMKVPlatformContextSpec_cxx& getSwiftPart() noexcept {
44
+ return _swiftPart;
45
+ }
46
+
47
+ public:
48
+ inline size_t getExternalMemorySize() noexcept override {
49
+ return _swiftPart.getMemorySize();
50
+ }
51
+ void dispose() noexcept override {
52
+ _swiftPart.dispose();
53
+ }
54
+
55
+ public:
56
+ // Properties
57
+
58
+
59
+ public:
60
+ // Methods
61
+ inline std::string getBaseDirectory() override {
62
+ auto __result = _swiftPart.getBaseDirectory();
63
+ if (__result.hasError()) [[unlikely]] {
64
+ std::rethrow_exception(__result.error());
65
+ }
66
+ auto __value = std::move(__result.value());
67
+ return __value;
68
+ }
69
+ inline std::optional<std::string> getAppGroupDirectory() override {
70
+ auto __result = _swiftPart.getAppGroupDirectory();
71
+ if (__result.hasError()) [[unlikely]] {
72
+ std::rethrow_exception(__result.error());
73
+ }
74
+ auto __value = std::move(__result.value());
75
+ return __value;
76
+ }
77
+
78
+ private:
79
+ NitroMmkv::HybridMMKVPlatformContextSpec_cxx _swiftPart;
80
+ };
81
+
82
+ } // namespace margelo::nitro::mmkv
@@ -0,0 +1,50 @@
1
+ ///
2
+ /// HybridMMKVPlatformContextSpec.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 ``HybridMMKVPlatformContextSpec``
12
+ public protocol HybridMMKVPlatformContextSpec_protocol: HybridObject {
13
+ // Properties
14
+
15
+
16
+ // Methods
17
+ func getBaseDirectory() throws -> String
18
+ func getAppGroupDirectory() throws -> String?
19
+ }
20
+
21
+ /// See ``HybridMMKVPlatformContextSpec``
22
+ open class HybridMMKVPlatformContextSpec_base {
23
+ private weak var cxxWrapper: HybridMMKVPlatformContextSpec_cxx? = nil
24
+ public init() { }
25
+ public func getCxxWrapper() -> HybridMMKVPlatformContextSpec_cxx {
26
+ #if DEBUG
27
+ guard self is HybridMMKVPlatformContextSpec else {
28
+ fatalError("`self` is not a `HybridMMKVPlatformContextSpec`! Did you accidentally inherit from `HybridMMKVPlatformContextSpec_base` instead of `HybridMMKVPlatformContextSpec`?")
29
+ }
30
+ #endif
31
+ if let cxxWrapper = self.cxxWrapper {
32
+ return cxxWrapper
33
+ } else {
34
+ let cxxWrapper = HybridMMKVPlatformContextSpec_cxx(self as! HybridMMKVPlatformContextSpec)
35
+ self.cxxWrapper = cxxWrapper
36
+ return cxxWrapper
37
+ }
38
+ }
39
+ }
40
+
41
+ /**
42
+ * A Swift base-protocol representing the MMKVPlatformContext HybridObject.
43
+ * Implement this protocol to create Swift-based instances of MMKVPlatformContext.
44
+ * ```swift
45
+ * class HybridMMKVPlatformContext : HybridMMKVPlatformContextSpec {
46
+ * // ...
47
+ * }
48
+ * ```
49
+ */
50
+ public typealias HybridMMKVPlatformContextSpec = HybridMMKVPlatformContextSpec_protocol & HybridMMKVPlatformContextSpec_base
@@ -0,0 +1,141 @@
1
+ ///
2
+ /// HybridMMKVPlatformContextSpec_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 HybridMMKVPlatformContextSpec 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 HybridMMKVPlatformContextSpec_cxx {
21
+ /**
22
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::mmkv::bridge::swift`)
23
+ * from `NitroMmkv-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.mmkv.bridge.swift
27
+
28
+ /**
29
+ * Holds an instance of the `HybridMMKVPlatformContextSpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridMMKVPlatformContextSpec
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_HybridMMKVPlatformContextSpec_
37
+
38
+ /**
39
+ * Create a new `HybridMMKVPlatformContextSpec_cxx` that wraps the given `HybridMMKVPlatformContextSpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridMMKVPlatformContextSpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ /* no base class */
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridMMKVPlatformContextSpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridMMKVPlatformContextSpec() -> any HybridMMKVPlatformContextSpec {
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 `HybridMMKVPlatformContextSpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridMMKVPlatformContextSpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridMMKVPlatformContextSpec_cxx {
70
+ return Unmanaged<HybridMMKVPlatformContextSpec_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<HybridMMKVPlatformContextSpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridMMKVPlatformContextSpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if cachedCxxPart.__convertToBool() {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridMMKVPlatformContextSpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridMMKVPlatformContextSpec_(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 getBaseDirectory() -> bridge.Result_std__string_ {
114
+ do {
115
+ let __result = try self.__implementation.getBaseDirectory()
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 getAppGroupDirectory() -> bridge.Result_std__optional_std__string__ {
126
+ do {
127
+ let __result = try self.__implementation.getAppGroupDirectory()
128
+ let __resultCpp = { () -> bridge.std__optional_std__string_ in
129
+ if let __unwrappedValue = __result {
130
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
131
+ } else {
132
+ return .init()
133
+ }
134
+ }()
135
+ return bridge.create_Result_std__optional_std__string__(__resultCpp)
136
+ } catch (let __error) {
137
+ let __exceptionPtr = __error.toCpp()
138
+ return bridge.create_Result_std__optional_std__string__(__exceptionPtr)
139
+ }
140
+ }
141
+ }
@@ -0,0 +1,86 @@
1
+ ///
2
+ /// Configuration.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
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+
21
+ // Forward declaration of `Mode` to properly resolve imports.
22
+ namespace margelo::nitro::mmkv { enum class Mode; }
23
+
24
+ #include <string>
25
+ #include <optional>
26
+ #include "Mode.hpp"
27
+
28
+ namespace margelo::nitro::mmkv {
29
+
30
+ /**
31
+ * A struct which can be represented as a JavaScript object (Configuration).
32
+ */
33
+ struct Configuration {
34
+ public:
35
+ std::string id SWIFT_PRIVATE;
36
+ std::optional<std::string> path SWIFT_PRIVATE;
37
+ std::optional<std::string> encryptionKey SWIFT_PRIVATE;
38
+ std::optional<Mode> mode SWIFT_PRIVATE;
39
+ std::optional<bool> readOnly SWIFT_PRIVATE;
40
+
41
+ public:
42
+ Configuration() = default;
43
+ explicit Configuration(std::string id, std::optional<std::string> path, std::optional<std::string> encryptionKey, std::optional<Mode> mode, std::optional<bool> readOnly): id(id), path(path), encryptionKey(encryptionKey), mode(mode), readOnly(readOnly) {}
44
+ };
45
+
46
+ } // namespace margelo::nitro::mmkv
47
+
48
+ namespace margelo::nitro {
49
+
50
+ // C++ Configuration <> JS Configuration (object)
51
+ template <>
52
+ struct JSIConverter<margelo::nitro::mmkv::Configuration> final {
53
+ static inline margelo::nitro::mmkv::Configuration fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
54
+ jsi::Object obj = arg.asObject(runtime);
55
+ return margelo::nitro::mmkv::Configuration(
56
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "id")),
57
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "path")),
58
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "encryptionKey")),
59
+ JSIConverter<std::optional<margelo::nitro::mmkv::Mode>>::fromJSI(runtime, obj.getProperty(runtime, "mode")),
60
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "readOnly"))
61
+ );
62
+ }
63
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mmkv::Configuration& arg) {
64
+ jsi::Object obj(runtime);
65
+ obj.setProperty(runtime, "id", JSIConverter<std::string>::toJSI(runtime, arg.id));
66
+ obj.setProperty(runtime, "path", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.path));
67
+ obj.setProperty(runtime, "encryptionKey", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.encryptionKey));
68
+ obj.setProperty(runtime, "mode", JSIConverter<std::optional<margelo::nitro::mmkv::Mode>>::toJSI(runtime, arg.mode));
69
+ obj.setProperty(runtime, "readOnly", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.readOnly));
70
+ return obj;
71
+ }
72
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
73
+ if (!value.isObject()) {
74
+ return false;
75
+ }
76
+ jsi::Object obj = value.getObject(runtime);
77
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "id"))) return false;
78
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "path"))) return false;
79
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "encryptionKey"))) return false;
80
+ if (!JSIConverter<std::optional<margelo::nitro::mmkv::Mode>>::canConvert(runtime, obj.getProperty(runtime, "mode"))) return false;
81
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "readOnly"))) return false;
82
+ return true;
83
+ }
84
+ };
85
+
86
+ } // namespace margelo::nitro
@@ -0,0 +1,23 @@
1
+ ///
2
+ /// HybridMMKVFactorySpec.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 "HybridMMKVFactorySpec.hpp"
9
+
10
+ namespace margelo::nitro::mmkv {
11
+
12
+ void HybridMMKVFactorySpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridGetter("defaultMMKVInstanceId", &HybridMMKVFactorySpec::getDefaultMMKVInstanceId);
18
+ prototype.registerHybridMethod("createMMKV", &HybridMMKVFactorySpec::createMMKV);
19
+ prototype.registerHybridMethod("initializeMMKV", &HybridMMKVFactorySpec::initializeMMKV);
20
+ });
21
+ }
22
+
23
+ } // namespace margelo::nitro::mmkv
@@ -0,0 +1,69 @@
1
+ ///
2
+ /// HybridMMKVFactorySpec.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
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `HybridMMKVSpec` to properly resolve imports.
17
+ namespace margelo::nitro::mmkv { class HybridMMKVSpec; }
18
+ // Forward declaration of `Configuration` to properly resolve imports.
19
+ namespace margelo::nitro::mmkv { struct Configuration; }
20
+
21
+ #include <string>
22
+ #include <memory>
23
+ #include "HybridMMKVSpec.hpp"
24
+ #include "Configuration.hpp"
25
+
26
+ namespace margelo::nitro::mmkv {
27
+
28
+ using namespace margelo::nitro;
29
+
30
+ /**
31
+ * An abstract base class for `MMKVFactory`
32
+ * Inherit this class to create instances of `HybridMMKVFactorySpec` in C++.
33
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
34
+ * @example
35
+ * ```cpp
36
+ * class HybridMMKVFactory: public HybridMMKVFactorySpec {
37
+ * public:
38
+ * HybridMMKVFactory(...): HybridObject(TAG) { ... }
39
+ * // ...
40
+ * };
41
+ * ```
42
+ */
43
+ class HybridMMKVFactorySpec: public virtual HybridObject {
44
+ public:
45
+ // Constructor
46
+ explicit HybridMMKVFactorySpec(): HybridObject(TAG) { }
47
+
48
+ // Destructor
49
+ ~HybridMMKVFactorySpec() override = default;
50
+
51
+ public:
52
+ // Properties
53
+ virtual std::string getDefaultMMKVInstanceId() = 0;
54
+
55
+ public:
56
+ // Methods
57
+ virtual std::shared_ptr<HybridMMKVSpec> createMMKV(const Configuration& configuration) = 0;
58
+ virtual void initializeMMKV(const std::string& rootPath) = 0;
59
+
60
+ protected:
61
+ // Hybrid Setup
62
+ void loadHybridMethods() override;
63
+
64
+ protected:
65
+ // Tag for logging
66
+ static constexpr auto TAG = "MMKVFactory";
67
+ };
68
+
69
+ } // namespace margelo::nitro::mmkv
@@ -0,0 +1,22 @@
1
+ ///
2
+ /// HybridMMKVPlatformContextSpec.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 "HybridMMKVPlatformContextSpec.hpp"
9
+
10
+ namespace margelo::nitro::mmkv {
11
+
12
+ void HybridMMKVPlatformContextSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("getBaseDirectory", &HybridMMKVPlatformContextSpec::getBaseDirectory);
18
+ prototype.registerHybridMethod("getAppGroupDirectory", &HybridMMKVPlatformContextSpec::getAppGroupDirectory);
19
+ });
20
+ }
21
+
22
+ } // namespace margelo::nitro::mmkv
@@ -0,0 +1,64 @@
1
+ ///
2
+ /// HybridMMKVPlatformContextSpec.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
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+
17
+
18
+ #include <string>
19
+ #include <optional>
20
+
21
+ namespace margelo::nitro::mmkv {
22
+
23
+ using namespace margelo::nitro;
24
+
25
+ /**
26
+ * An abstract base class for `MMKVPlatformContext`
27
+ * Inherit this class to create instances of `HybridMMKVPlatformContextSpec` in C++.
28
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
29
+ * @example
30
+ * ```cpp
31
+ * class HybridMMKVPlatformContext: public HybridMMKVPlatformContextSpec {
32
+ * public:
33
+ * HybridMMKVPlatformContext(...): HybridObject(TAG) { ... }
34
+ * // ...
35
+ * };
36
+ * ```
37
+ */
38
+ class HybridMMKVPlatformContextSpec: public virtual HybridObject {
39
+ public:
40
+ // Constructor
41
+ explicit HybridMMKVPlatformContextSpec(): HybridObject(TAG) { }
42
+
43
+ // Destructor
44
+ ~HybridMMKVPlatformContextSpec() override = default;
45
+
46
+ public:
47
+ // Properties
48
+
49
+
50
+ public:
51
+ // Methods
52
+ virtual std::string getBaseDirectory() = 0;
53
+ virtual std::optional<std::string> getAppGroupDirectory() = 0;
54
+
55
+ protected:
56
+ // Hybrid Setup
57
+ void loadHybridMethods() override;
58
+
59
+ protected:
60
+ // Tag for logging
61
+ static constexpr auto TAG = "MMKVPlatformContext";
62
+ };
63
+
64
+ } // namespace margelo::nitro::mmkv
@@ -0,0 +1,34 @@
1
+ ///
2
+ /// HybridMMKVSpec.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 "HybridMMKVSpec.hpp"
9
+
10
+ namespace margelo::nitro::mmkv {
11
+
12
+ void HybridMMKVSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridGetter("size", &HybridMMKVSpec::getSize);
18
+ prototype.registerHybridGetter("isReadOnly", &HybridMMKVSpec::getIsReadOnly);
19
+ prototype.registerHybridMethod("set", &HybridMMKVSpec::set);
20
+ prototype.registerHybridMethod("getBoolean", &HybridMMKVSpec::getBoolean);
21
+ prototype.registerHybridMethod("getString", &HybridMMKVSpec::getString);
22
+ prototype.registerHybridMethod("getNumber", &HybridMMKVSpec::getNumber);
23
+ prototype.registerHybridMethod("getBuffer", &HybridMMKVSpec::getBuffer);
24
+ prototype.registerHybridMethod("contains", &HybridMMKVSpec::contains);
25
+ prototype.registerHybridMethod("remove", &HybridMMKVSpec::remove);
26
+ prototype.registerHybridMethod("getAllKeys", &HybridMMKVSpec::getAllKeys);
27
+ prototype.registerHybridMethod("clearAll", &HybridMMKVSpec::clearAll);
28
+ prototype.registerHybridMethod("recrypt", &HybridMMKVSpec::recrypt);
29
+ prototype.registerHybridMethod("trim", &HybridMMKVSpec::trim);
30
+ prototype.registerHybridMethod("addOnValueChangedListener", &HybridMMKVSpec::addOnValueChangedListener);
31
+ });
32
+ }
33
+
34
+ } // namespace margelo::nitro::mmkv
@@ -0,0 +1,83 @@
1
+ ///
2
+ /// HybridMMKVSpec.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
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `ArrayBuffer` to properly resolve imports.
17
+ namespace NitroModules { class ArrayBuffer; }
18
+ // Forward declaration of `Listener` to properly resolve imports.
19
+ namespace margelo::nitro::mmkv { struct Listener; }
20
+
21
+ #include <string>
22
+ #include <NitroModules/ArrayBuffer.hpp>
23
+ #include <variant>
24
+ #include <optional>
25
+ #include <vector>
26
+ #include "Listener.hpp"
27
+ #include <functional>
28
+
29
+ namespace margelo::nitro::mmkv {
30
+
31
+ using namespace margelo::nitro;
32
+
33
+ /**
34
+ * An abstract base class for `MMKV`
35
+ * Inherit this class to create instances of `HybridMMKVSpec` in C++.
36
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
37
+ * @example
38
+ * ```cpp
39
+ * class HybridMMKV: public HybridMMKVSpec {
40
+ * public:
41
+ * HybridMMKV(...): HybridObject(TAG) { ... }
42
+ * // ...
43
+ * };
44
+ * ```
45
+ */
46
+ class HybridMMKVSpec: public virtual HybridObject {
47
+ public:
48
+ // Constructor
49
+ explicit HybridMMKVSpec(): HybridObject(TAG) { }
50
+
51
+ // Destructor
52
+ ~HybridMMKVSpec() override = default;
53
+
54
+ public:
55
+ // Properties
56
+ virtual double getSize() = 0;
57
+ virtual bool getIsReadOnly() = 0;
58
+
59
+ public:
60
+ // Methods
61
+ virtual void set(const std::string& key, const std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>>& value) = 0;
62
+ virtual std::optional<bool> getBoolean(const std::string& key) = 0;
63
+ virtual std::optional<std::string> getString(const std::string& key) = 0;
64
+ virtual std::optional<double> getNumber(const std::string& key) = 0;
65
+ virtual std::optional<std::shared_ptr<ArrayBuffer>> getBuffer(const std::string& key) = 0;
66
+ virtual bool contains(const std::string& key) = 0;
67
+ virtual bool remove(const std::string& key) = 0;
68
+ virtual std::vector<std::string> getAllKeys() = 0;
69
+ virtual void clearAll() = 0;
70
+ virtual void recrypt(const std::optional<std::string>& key) = 0;
71
+ virtual void trim() = 0;
72
+ virtual Listener addOnValueChangedListener(const std::function<void(const std::string& /* key */)>& onValueChanged) = 0;
73
+
74
+ protected:
75
+ // Hybrid Setup
76
+ void loadHybridMethods() override;
77
+
78
+ protected:
79
+ // Tag for logging
80
+ static constexpr auto TAG = "MMKV";
81
+ };
82
+
83
+ } // namespace margelo::nitro::mmkv