react-native-mmkv 4.0.0-beta.0 → 4.0.0-beta.10

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 (234) 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 +65 -20
  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/app.plugin.js +1 -0
  11. package/cpp/HybridMMKV.cpp +184 -0
  12. package/cpp/HybridMMKV.hpp +47 -0
  13. package/cpp/HybridMMKVFactory.cpp +33 -0
  14. package/cpp/HybridMMKVFactory.hpp +24 -0
  15. package/cpp/{MmkvTypes.h → MMKVTypes.hpp} +1 -1
  16. package/cpp/MMKVValueChangedListenerRegistry.cpp +58 -0
  17. package/cpp/MMKVValueChangedListenerRegistry.hpp +43 -0
  18. package/cpp/{ManagedMMBuffer.h → ManagedMMBuffer.hpp} +13 -5
  19. package/ios/HybridMMKVPlatformContext.swift +43 -0
  20. package/lib/__tests__/hooks.test.d.ts +1 -0
  21. package/lib/__tests__/hooks.test.js +69 -0
  22. package/lib/addMemoryWarningListener/addMemoryWarningListener.d.ts +2 -0
  23. package/lib/addMemoryWarningListener/addMemoryWarningListener.js +25 -0
  24. package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.d.ts +2 -0
  25. package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.js +3 -0
  26. package/lib/addMemoryWarningListener/addMemoryWarningListener.web.d.ts +2 -0
  27. package/lib/addMemoryWarningListener/addMemoryWarningListener.web.js +3 -0
  28. package/lib/createMMKV/createMMKV.d.ts +3 -0
  29. package/lib/createMMKV/createMMKV.js +40 -0
  30. package/lib/createMMKV/createMMKV.mock.d.ts +5 -0
  31. package/lib/createMMKV/createMMKV.mock.js +74 -0
  32. package/lib/createMMKV/createMMKV.web.d.ts +3 -0
  33. package/lib/createMMKV/createMMKV.web.js +117 -0
  34. package/lib/createMMKV/createMockMMKV.d.ts +5 -0
  35. package/lib/createMMKV/createMockMMKV.js +74 -0
  36. package/lib/createMMKV/getDefaultMMKVInstance.d.ts +2 -0
  37. package/lib/createMMKV/getDefaultMMKVInstance.js +8 -0
  38. package/lib/expo-plugin/withMMKV.cjs +26 -0
  39. package/lib/expo-plugin/withMMKV.d.cts +3 -0
  40. package/lib/expo-plugin/withMMKV.d.ts +3 -0
  41. package/lib/expo-plugin/withMMKV.js +17 -0
  42. package/lib/hooks/createMMKVHook.d.ts +2 -0
  43. package/lib/hooks/createMMKVHook.js +49 -0
  44. package/lib/hooks/useMMKV.d.ts +11 -0
  45. package/lib/hooks/useMMKV.js +23 -0
  46. package/lib/hooks/useMMKVBoolean.d.ts +11 -0
  47. package/lib/hooks/useMMKVBoolean.js +12 -0
  48. package/lib/hooks/useMMKVBuffer.d.ts +11 -0
  49. package/lib/hooks/useMMKVBuffer.js +12 -0
  50. package/lib/hooks/useMMKVKeys.d.ts +12 -0
  51. package/lib/hooks/useMMKVKeys.js +33 -0
  52. package/lib/hooks/useMMKVListener.d.ts +15 -0
  53. package/lib/hooks/useMMKVListener.js +26 -0
  54. package/lib/hooks/useMMKVNumber.d.ts +11 -0
  55. package/lib/hooks/useMMKVNumber.js +12 -0
  56. package/lib/hooks/useMMKVObject.d.ts +17 -0
  57. package/lib/hooks/useMMKVObject.js +38 -0
  58. package/lib/hooks/useMMKVString.d.ts +11 -0
  59. package/lib/hooks/useMMKVString.js +12 -0
  60. package/lib/index.d.ts +11 -0
  61. package/lib/index.js +11 -0
  62. package/lib/isTest.d.ts +1 -0
  63. package/lib/isTest.js +7 -0
  64. package/lib/specs/MMKV.nitro.d.ts +94 -0
  65. package/lib/specs/MMKV.nitro.js +1 -0
  66. package/lib/{typescript/src/NativeMmkv.d.ts → specs/MMKVFactory.nitro.d.ts} +26 -33
  67. package/lib/specs/MMKVFactory.nitro.js +1 -0
  68. package/lib/specs/MMKVPlatformContext.nitro.d.ts +18 -0
  69. package/lib/specs/MMKVPlatformContext.nitro.js +1 -0
  70. package/lib/{typescript/src → web}/createTextEncoder.d.ts +0 -1
  71. package/lib/web/createTextEncoder.js +17 -0
  72. package/nitro.json +28 -0
  73. package/nitrogen/generated/.gitattributes +1 -0
  74. package/nitrogen/generated/android/NitroMmkv+autolinking.cmake +80 -0
  75. package/nitrogen/generated/android/NitroMmkv+autolinking.gradle +27 -0
  76. package/nitrogen/generated/android/NitroMmkvOnLoad.cpp +54 -0
  77. package/nitrogen/generated/android/NitroMmkvOnLoad.hpp +25 -0
  78. package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.cpp +52 -0
  79. package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.hpp +65 -0
  80. package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/HybridMMKVPlatformContextSpec.kt +56 -0
  81. package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/NitroMmkvOnLoad.kt +35 -0
  82. package/nitrogen/generated/ios/NitroMmkv+autolinking.rb +60 -0
  83. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.cpp +32 -0
  84. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.hpp +77 -0
  85. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Umbrella.hpp +45 -0
  86. package/nitrogen/generated/ios/NitroMmkvAutolinking.mm +43 -0
  87. package/nitrogen/generated/ios/NitroMmkvAutolinking.swift +25 -0
  88. package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.cpp +11 -0
  89. package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.hpp +82 -0
  90. package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec.swift +50 -0
  91. package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec_cxx.swift +141 -0
  92. package/nitrogen/generated/shared/c++/Configuration.hpp +86 -0
  93. package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.cpp +23 -0
  94. package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.hpp +69 -0
  95. package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.cpp +22 -0
  96. package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.hpp +64 -0
  97. package/nitrogen/generated/shared/c++/HybridMMKVSpec.cpp +34 -0
  98. package/nitrogen/generated/shared/c++/HybridMMKVSpec.hpp +83 -0
  99. package/nitrogen/generated/shared/c++/Listener.hpp +67 -0
  100. package/nitrogen/generated/shared/c++/Mode.hpp +76 -0
  101. package/package.json +78 -125
  102. package/react-native.config.js +2 -15
  103. package/src/__tests__/hooks.test.tsx +39 -34
  104. package/src/addMemoryWarningListener/addMemoryWarningListener.mock.ts +5 -0
  105. package/src/{MemoryWarningListener.ts → addMemoryWarningListener/addMemoryWarningListener.ts} +12 -12
  106. package/src/addMemoryWarningListener/addMemoryWarningListener.web.ts +5 -0
  107. package/src/createMMKV/createMMKV.ts +51 -0
  108. package/src/{createMMKV.web.ts → createMMKV/createMMKV.web.ts} +58 -46
  109. package/src/createMMKV/createMockMMKV.ts +78 -0
  110. package/src/createMMKV/getDefaultMMKVInstance.ts +10 -0
  111. package/src/expo-plugin/withMMKV.cts +31 -0
  112. package/src/hooks/createMMKVHook.ts +66 -0
  113. package/src/hooks/useMMKV.ts +45 -0
  114. package/src/hooks/useMMKVBoolean.ts +15 -0
  115. package/src/hooks/useMMKVBuffer.ts +15 -0
  116. package/src/hooks/useMMKVKeys.ts +36 -0
  117. package/src/hooks/useMMKVListener.ts +33 -0
  118. package/src/hooks/useMMKVNumber.ts +15 -0
  119. package/src/hooks/useMMKVObject.ts +53 -0
  120. package/src/hooks/useMMKVString.ts +15 -0
  121. package/src/index.ts +15 -3
  122. package/src/{PlatformChecker.ts → isTest.ts} +2 -2
  123. package/src/specs/MMKV.nitro.ts +93 -0
  124. package/src/specs/MMKVFactory.nitro.ts +87 -0
  125. package/src/specs/MMKVPlatformContext.nitro.ts +17 -0
  126. package/src/{createTextEncoder.ts → web/createTextEncoder.ts} +7 -7
  127. package/android/src/main/cpp/AndroidLogger.cpp +0 -16
  128. package/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java +0 -44
  129. package/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java +0 -26
  130. package/cpp/MmkvHostObject.cpp +0 -360
  131. package/cpp/MmkvHostObject.h +0 -31
  132. package/cpp/MmkvLogger.h +0 -35
  133. package/cpp/NativeMmkvModule.cpp +0 -43
  134. package/cpp/NativeMmkvModule.h +0 -31
  135. package/ios/AppleLogger.mm +0 -16
  136. package/ios/MmkvOnLoad.mm +0 -25
  137. package/ios/MmkvPlatformContext.h +0 -19
  138. package/ios/MmkvPlatformContextModule.mm +0 -55
  139. package/lib/commonjs/MMKV.js +0 -124
  140. package/lib/commonjs/MMKV.js.map +0 -1
  141. package/lib/commonjs/MemoryWarningListener.js +0 -31
  142. package/lib/commonjs/MemoryWarningListener.js.map +0 -1
  143. package/lib/commonjs/MemoryWarningListener.web.js +0 -11
  144. package/lib/commonjs/MemoryWarningListener.web.js.map +0 -1
  145. package/lib/commonjs/ModuleNotFoundError.js +0 -75
  146. package/lib/commonjs/ModuleNotFoundError.js.map +0 -1
  147. package/lib/commonjs/NativeMmkv.js +0 -47
  148. package/lib/commonjs/NativeMmkv.js.map +0 -1
  149. package/lib/commonjs/NativeMmkvPlatformContext.js +0 -22
  150. package/lib/commonjs/NativeMmkvPlatformContext.js.map +0 -1
  151. package/lib/commonjs/PlatformChecker.js +0 -14
  152. package/lib/commonjs/PlatformChecker.js.map +0 -1
  153. package/lib/commonjs/Types.js +0 -26
  154. package/lib/commonjs/Types.js.map +0 -1
  155. package/lib/commonjs/createMMKV.js +0 -43
  156. package/lib/commonjs/createMMKV.js.map +0 -1
  157. package/lib/commonjs/createMMKV.mock.js +0 -43
  158. package/lib/commonjs/createMMKV.mock.js.map +0 -1
  159. package/lib/commonjs/createMMKV.web.js +0 -110
  160. package/lib/commonjs/createMMKV.web.js.map +0 -1
  161. package/lib/commonjs/createTextEncoder.js +0 -23
  162. package/lib/commonjs/createTextEncoder.js.map +0 -1
  163. package/lib/commonjs/hooks.js +0 -198
  164. package/lib/commonjs/hooks.js.map +0 -1
  165. package/lib/commonjs/index.js +0 -40
  166. package/lib/commonjs/index.js.map +0 -1
  167. package/lib/commonjs/package.json +0 -1
  168. package/lib/module/MMKV.js +0 -119
  169. package/lib/module/MMKV.js.map +0 -1
  170. package/lib/module/MemoryWarningListener.js +0 -27
  171. package/lib/module/MemoryWarningListener.js.map +0 -1
  172. package/lib/module/MemoryWarningListener.web.js +0 -6
  173. package/lib/module/MemoryWarningListener.web.js.map +0 -1
  174. package/lib/module/ModuleNotFoundError.js +0 -70
  175. package/lib/module/ModuleNotFoundError.js.map +0 -1
  176. package/lib/module/NativeMmkv.js +0 -45
  177. package/lib/module/NativeMmkv.js.map +0 -1
  178. package/lib/module/NativeMmkvPlatformContext.js +0 -18
  179. package/lib/module/NativeMmkvPlatformContext.js.map +0 -1
  180. package/lib/module/PlatformChecker.js +0 -10
  181. package/lib/module/PlatformChecker.js.map +0 -1
  182. package/lib/module/Types.js +0 -25
  183. package/lib/module/Types.js.map +0 -1
  184. package/lib/module/createMMKV.js +0 -38
  185. package/lib/module/createMMKV.js.map +0 -1
  186. package/lib/module/createMMKV.mock.js +0 -38
  187. package/lib/module/createMMKV.mock.js.map +0 -1
  188. package/lib/module/createMMKV.web.js +0 -105
  189. package/lib/module/createMMKV.web.js.map +0 -1
  190. package/lib/module/createTextEncoder.js +0 -19
  191. package/lib/module/createTextEncoder.js.map +0 -1
  192. package/lib/module/hooks.js +0 -189
  193. package/lib/module/hooks.js.map +0 -1
  194. package/lib/module/index.js +0 -6
  195. package/lib/module/index.js.map +0 -1
  196. package/lib/module/package.json +0 -1
  197. package/lib/typescript/src/MMKV.d.ts +0 -34
  198. package/lib/typescript/src/MMKV.d.ts.map +0 -1
  199. package/lib/typescript/src/MemoryWarningListener.d.ts +0 -3
  200. package/lib/typescript/src/MemoryWarningListener.d.ts.map +0 -1
  201. package/lib/typescript/src/MemoryWarningListener.web.d.ts +0 -3
  202. package/lib/typescript/src/MemoryWarningListener.web.d.ts.map +0 -1
  203. package/lib/typescript/src/ModuleNotFoundError.d.ts +0 -7
  204. package/lib/typescript/src/ModuleNotFoundError.d.ts.map +0 -1
  205. package/lib/typescript/src/NativeMmkv.d.ts.map +0 -1
  206. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts +0 -20
  207. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +0 -1
  208. package/lib/typescript/src/PlatformChecker.d.ts +0 -2
  209. package/lib/typescript/src/PlatformChecker.d.ts.map +0 -1
  210. package/lib/typescript/src/Types.d.ts +0 -172
  211. package/lib/typescript/src/Types.d.ts.map +0 -1
  212. package/lib/typescript/src/__tests__/hooks.test.d.ts +0 -2
  213. package/lib/typescript/src/__tests__/hooks.test.d.ts.map +0 -1
  214. package/lib/typescript/src/createMMKV.d.ts +0 -3
  215. package/lib/typescript/src/createMMKV.d.ts.map +0 -1
  216. package/lib/typescript/src/createMMKV.mock.d.ts +0 -3
  217. package/lib/typescript/src/createMMKV.mock.d.ts.map +0 -1
  218. package/lib/typescript/src/createMMKV.web.d.ts +0 -3
  219. package/lib/typescript/src/createMMKV.web.d.ts.map +0 -1
  220. package/lib/typescript/src/createTextEncoder.d.ts.map +0 -1
  221. package/lib/typescript/src/hooks.d.ts +0 -86
  222. package/lib/typescript/src/hooks.d.ts.map +0 -1
  223. package/lib/typescript/src/index.d.ts +0 -4
  224. package/lib/typescript/src/index.d.ts.map +0 -1
  225. package/react-native-mmkv.podspec +0 -32
  226. package/src/MMKV.ts +0 -142
  227. package/src/MemoryWarningListener.web.ts +0 -5
  228. package/src/ModuleNotFoundError.ts +0 -95
  229. package/src/NativeMmkv.ts +0 -118
  230. package/src/NativeMmkvPlatformContext.ts +0 -38
  231. package/src/Types.ts +0 -178
  232. package/src/createMMKV.mock.ts +0 -38
  233. package/src/createMMKV.ts +0 -42
  234. package/src/hooks.ts +0 -247
@@ -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
@@ -0,0 +1,67 @@
1
+ ///
2
+ /// Listener.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
+
22
+
23
+ #include <functional>
24
+
25
+ namespace margelo::nitro::mmkv {
26
+
27
+ /**
28
+ * A struct which can be represented as a JavaScript object (Listener).
29
+ */
30
+ struct Listener {
31
+ public:
32
+ std::function<void()> remove SWIFT_PRIVATE;
33
+
34
+ public:
35
+ Listener() = default;
36
+ explicit Listener(std::function<void()> remove): remove(remove) {}
37
+ };
38
+
39
+ } // namespace margelo::nitro::mmkv
40
+
41
+ namespace margelo::nitro {
42
+
43
+ // C++ Listener <> JS Listener (object)
44
+ template <>
45
+ struct JSIConverter<margelo::nitro::mmkv::Listener> final {
46
+ static inline margelo::nitro::mmkv::Listener fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
47
+ jsi::Object obj = arg.asObject(runtime);
48
+ return margelo::nitro::mmkv::Listener(
49
+ JSIConverter<std::function<void()>>::fromJSI(runtime, obj.getProperty(runtime, "remove"))
50
+ );
51
+ }
52
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mmkv::Listener& arg) {
53
+ jsi::Object obj(runtime);
54
+ obj.setProperty(runtime, "remove", JSIConverter<std::function<void()>>::toJSI(runtime, arg.remove));
55
+ return obj;
56
+ }
57
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
58
+ if (!value.isObject()) {
59
+ return false;
60
+ }
61
+ jsi::Object obj = value.getObject(runtime);
62
+ if (!JSIConverter<std::function<void()>>::canConvert(runtime, obj.getProperty(runtime, "remove"))) return false;
63
+ return true;
64
+ }
65
+ };
66
+
67
+ } // namespace margelo::nitro
@@ -0,0 +1,76 @@
1
+ ///
2
+ /// Mode.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/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::mmkv {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (Mode).
30
+ */
31
+ enum class Mode {
32
+ SINGLE_PROCESS SWIFT_NAME(singleProcess) = 0,
33
+ MULTI_PROCESS SWIFT_NAME(multiProcess) = 1,
34
+ } CLOSED_ENUM;
35
+
36
+ } // namespace margelo::nitro::mmkv
37
+
38
+ namespace margelo::nitro {
39
+
40
+ // C++ Mode <> JS Mode (union)
41
+ template <>
42
+ struct JSIConverter<margelo::nitro::mmkv::Mode> final {
43
+ static inline margelo::nitro::mmkv::Mode fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
44
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
45
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
46
+ case hashString("single-process"): return margelo::nitro::mmkv::Mode::SINGLE_PROCESS;
47
+ case hashString("multi-process"): return margelo::nitro::mmkv::Mode::MULTI_PROCESS;
48
+ default: [[unlikely]]
49
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum Mode - invalid value!");
50
+ }
51
+ }
52
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::mmkv::Mode arg) {
53
+ switch (arg) {
54
+ case margelo::nitro::mmkv::Mode::SINGLE_PROCESS: return JSIConverter<std::string>::toJSI(runtime, "single-process");
55
+ case margelo::nitro::mmkv::Mode::MULTI_PROCESS: return JSIConverter<std::string>::toJSI(runtime, "multi-process");
56
+ default: [[unlikely]]
57
+ throw std::invalid_argument("Cannot convert Mode to JS - invalid value: "
58
+ + std::to_string(static_cast<int>(arg)) + "!");
59
+ }
60
+ }
61
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
62
+ if (!value.isString()) {
63
+ return false;
64
+ }
65
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
66
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
67
+ case hashString("single-process"):
68
+ case hashString("multi-process"):
69
+ return true;
70
+ default:
71
+ return false;
72
+ }
73
+ }
74
+ };
75
+
76
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,65 +1,57 @@
1
1
  {
2
2
  "name": "react-native-mmkv",
3
- "version": "4.0.0-beta.0",
4
- "description": "The fastest key/value storage for React Native. ~30x faster than AsyncStorage! Works on Android, iOS and Web.",
5
- "main": "lib/commonjs/index",
6
- "module": "lib/module/index",
7
- "types": "lib/typescript/src/index.d.ts",
3
+ "version": "4.0.0-beta.10",
4
+ "description": "⚡️ The fastest key/value storage for React Native.",
5
+ "main": "lib/index",
6
+ "module": "lib/index",
7
+ "types": "lib/index.d.ts",
8
8
  "react-native": "src/index",
9
9
  "source": "src/index",
10
10
  "files": [
11
- "cpp/**/*.h",
12
- "cpp/**/*.cpp",
13
- "android/src",
11
+ "src",
12
+ "react-native.config.js",
13
+ "lib",
14
+ "nitrogen",
14
15
  "android/build.gradle",
15
- "android/CMakeLists.txt",
16
- "android/cpp-adapter.cpp",
17
16
  "android/gradle.properties",
18
- "lib/commonjs",
19
- "lib/module",
20
- "lib/typescript",
17
+ "android/fix-prefab.gradle",
18
+ "android/CMakeLists.txt",
19
+ "android/src",
21
20
  "ios/**/*.h",
22
21
  "ios/**/*.m",
23
22
  "ios/**/*.mm",
24
23
  "ios/**/*.cpp",
25
- "src",
26
- "react-native-mmkv.podspec",
27
- "react-native.config.js",
24
+ "ios/**/*.swift",
25
+ "cpp/**/*.h",
26
+ "cpp/**/*.hpp",
27
+ "cpp/**/*.cpp",
28
+ "app.plugin.js",
29
+ "nitro.json",
30
+ "*.podspec",
28
31
  "README.md"
29
32
  ],
30
33
  "scripts": {
31
- "typescript": "tsc --noEmit",
32
- "lint": "eslint \"**/*.{js,ts,tsx}\"",
33
- "lint-ci": "yarn lint -f ./node_modules/@firmnav/eslint-github-actions-formatter/dist/formatter.js",
34
- "lint-cpp": "scripts/clang-format.sh",
35
- "check-all": "yarn lint --fix && yarn lint-cpp",
36
- "test": "jest",
34
+ "postinstall": "tsc || exit 0;",
37
35
  "typecheck": "tsc --noEmit",
38
- "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
39
- "prepare": "bob build",
40
- "prepack": "bob build",
41
- "pods": "cd example && yarn pods",
36
+ "clean": "rm -rf android/build node_modules/**/android/build lib",
37
+ "lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
38
+ "lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
39
+ "typescript": "tsc",
40
+ "specs": "tsc && nitrogen --logLevel=\"debug\"",
41
+ "build": "tsc --noEmit false",
42
42
  "release": "release-it",
43
- "codegen": "npx react-native codegen"
43
+ "test": "jest"
44
44
  },
45
45
  "keywords": [
46
46
  "react-native",
47
- "ios",
48
- "android",
49
- "mmkv",
50
- "storage",
51
- "key",
52
- "value",
53
- "fast",
54
- "turbo",
55
- "async"
47
+ "nitro"
56
48
  ],
57
49
  "repository": {
58
50
  "type": "git",
59
51
  "url": "git+https://github.com/mrousavy/react-native-mmkv.git"
60
52
  },
61
53
  "author": "Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
62
- "license": "(MIT AND BSD-3-Clause)",
54
+ "license": "MIT",
63
55
  "bugs": {
64
56
  "url": "https://github.com/mrousavy/react-native-mmkv/issues"
65
57
  },
@@ -68,110 +60,71 @@
68
60
  "registry": "https://registry.npmjs.org/"
69
61
  },
70
62
  "devDependencies": {
71
- "@firmnav/eslint-github-actions-formatter": "1.0.1",
72
- "@jamesacarr/eslint-formatter-github-actions": "0.2.0",
73
- "@react-native-community/cli": "19.1.1",
74
- "@react-native-community/cli-types": "18.0.0",
75
- "@react-native/eslint-config": "0.77.1",
76
- "@release-it/conventional-changelog": "9.0.1",
77
- "@testing-library/react-native": "13.0.1",
78
- "@types/jest": "29.5.13",
79
- "@types/react": "18.3.11",
80
- "del-cli": "6.0.0",
81
- "eslint": "8.51.0",
82
- "eslint-config-prettier": "9.0.0",
83
- "eslint-plugin-prettier": "5.2.1",
84
- "jest": "29.7.0",
85
- "prettier": "3.3.3",
86
- "react": "18.3.1",
87
- "react-native": "0.77.1",
88
- "react-native-builder-bob": "0.37.0",
89
- "react-test-renderer": "18.3.1",
90
- "release-it": "17.10.0",
91
- "typescript": "5.5.4"
63
+ "@expo/config-plugins": "^10.1.2",
64
+ "@react-native/eslint-config": "0.81.0",
65
+ "@testing-library/react-native": "^13.3.1",
66
+ "@types/jest": "^29.5.12",
67
+ "@types/react": "^19.0.6",
68
+ "eslint": "^8.57.0",
69
+ "eslint-config-prettier": "^9.1.0",
70
+ "eslint-plugin-prettier": "^5.2.1",
71
+ "nitrogen": "^0.29.4",
72
+ "prettier": "^3.3.3",
73
+ "react": "19.1.0",
74
+ "react-native": "0.81.0",
75
+ "react-native-nitro-modules": "^0.29.4",
76
+ "typescript": "^5.8.3"
92
77
  },
93
78
  "peerDependencies": {
94
79
  "react": "*",
95
- "react-native": "*"
80
+ "react-native": "*",
81
+ "react-native-nitro-modules": "*"
96
82
  },
97
- "jest": {
98
- "preset": "react-native",
99
- "modulePathIgnorePatterns": [
100
- "<rootDir>/example/node_modules",
101
- "<rootDir>/lib/"
102
- ]
83
+ "eslintConfig": {
84
+ "root": true,
85
+ "extends": [
86
+ "@react-native",
87
+ "prettier"
88
+ ],
89
+ "plugins": [
90
+ "prettier"
91
+ ],
92
+ "rules": {
93
+ "prettier/prettier": [
94
+ "warn",
95
+ {
96
+ "quoteProps": "consistent",
97
+ "singleQuote": true,
98
+ "tabWidth": 2,
99
+ "trailingComma": "es5",
100
+ "useTabs": false
101
+ }
102
+ ]
103
+ }
103
104
  },
105
+ "eslintIgnore": [
106
+ "node_modules/",
107
+ "lib/"
108
+ ],
104
109
  "release-it": {
105
- "git": {
106
- "commitMessage": "chore: release ${version}",
107
- "tagName": "v${version}"
108
- },
109
110
  "npm": {
110
111
  "publish": true
111
112
  },
113
+ "git": false,
112
114
  "github": {
113
- "release": true
115
+ "release": false
114
116
  },
115
- "plugins": {
116
- "@release-it/conventional-changelog": {
117
- "preset": {
118
- "name": "conventionalcommits",
119
- "types": [
120
- {
121
- "type": "feat",
122
- "section": "✨ Features"
123
- },
124
- {
125
- "type": "fix",
126
- "section": "🐛 Bug Fixes"
127
- },
128
- {
129
- "type": "perf",
130
- "section": "💨 Performance Improvements"
131
- },
132
- {
133
- "type": "chore(deps)",
134
- "section": "🛠️ Dependency Upgrades"
135
- },
136
- {
137
- "type": "docs",
138
- "section": "📚 Documentation"
139
- }
140
- ]
141
- }
142
- }
117
+ "hooks": {
118
+ "before:init": "bun typecheck",
119
+ "after:bump": "bun run build"
143
120
  }
144
121
  },
145
- "eslintIgnore": [
146
- "node_modules/",
147
- "lib/",
148
- "MMKV"
149
- ],
150
122
  "prettier": {
151
123
  "quoteProps": "consistent",
152
124
  "singleQuote": true,
153
125
  "tabWidth": 2,
154
126
  "trailingComma": "es5",
155
- "useTabs": false
156
- },
157
- "react-native-builder-bob": {
158
- "source": "src",
159
- "output": "lib",
160
- "targets": [
161
- "commonjs",
162
- "module",
163
- [
164
- "typescript",
165
- {
166
- "project": "tsconfig.json"
167
- }
168
- ]
169
- ]
170
- },
171
- "codegenConfig": {
172
- "name": "RNMmkvSpec",
173
- "type": "modules",
174
- "jsSrcsDir": "src"
175
- },
176
- "packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
127
+ "useTabs": false,
128
+ "semi": false
129
+ }
177
130
  }
@@ -10,20 +10,7 @@ module.exports = {
10
10
  /**
11
11
  * @type {import('@react-native-community/cli-types').AndroidDependencyParams}
12
12
  */
13
- android: {
14
- cxxModuleCMakeListsModuleName: 'react-native-mmkv',
15
- cxxModuleCMakeListsPath: 'CMakeLists.txt',
16
- cxxModuleHeaderName: 'NativeMmkvModule',
17
- },
13
+ android: {},
18
14
  },
19
15
  },
20
- // Codegen configuration for TurboModules
21
- codegenConfig: {
22
- name: 'RNMmkvSpec',
23
- type: 'modules',
24
- jsSrcsDir: 'src',
25
- android: {
26
- javaPackageName: 'com.mrousavy.mmkv',
27
- },
28
- },
29
- };
16
+ }
@@ -1,44 +1,49 @@
1
- import React from 'react';
2
- import { Button, Text } from 'react-native';
1
+ import React from 'react'
2
+ import { Button, Text } from 'react-native'
3
3
  import {
4
4
  act,
5
5
  fireEvent,
6
6
  render,
7
7
  renderHook,
8
8
  screen,
9
- } from '@testing-library/react-native';
10
- import { MMKV, useMMKVNumber, useMMKVString } from '..';
9
+ cleanup,
10
+ } from '@testing-library/react-native'
11
+ import { createMMKV, useMMKVNumber, useMMKVString } from '..'
11
12
 
12
- const mmkv = new MMKV();
13
+ const mmkv = createMMKV()
13
14
 
14
15
  beforeEach(() => {
15
- mmkv.clearAll();
16
- mmkv.trim();
17
- });
16
+ mmkv.clearAll()
17
+ mmkv.trim()
18
+ })
19
+
20
+ afterEach(() => {
21
+ cleanup()
22
+ })
18
23
 
19
24
  test('hooks update when the value is changed directly through the instance', () => {
20
- const { result } = renderHook(() => useMMKVString('string-key', mmkv));
25
+ const { result } = renderHook(() => useMMKVString('string-key', mmkv))
21
26
 
22
- expect(result.current[0]).toBeUndefined();
27
+ expect(result.current[0]).toBeUndefined()
23
28
 
24
29
  // First, make a "normal" change
25
30
  act(() => {
26
- result.current[1]('value 1');
27
- });
31
+ result.current[1]('value 1')
32
+ })
28
33
 
29
- expect(result.current[0]).toStrictEqual('value 1');
34
+ expect(result.current[0]).toStrictEqual('value 1')
30
35
 
31
36
  // Now, make the change directly through the instance.
32
37
  act(() => {
33
- mmkv.set('string-key', 'value 2');
34
- });
35
- expect(result.current[0]).toStrictEqual('value 2');
36
- });
38
+ mmkv.set('string-key', 'value 2')
39
+ })
40
+ expect(result.current[0]).toStrictEqual('value 2')
41
+ })
37
42
 
38
43
  test('functional updates to hooks', () => {
39
44
  const Component: React.FC = () => {
40
- const [state, setState] = React.useState(0);
41
- const [value, setValue] = useMMKVNumber('number-key', mmkv);
45
+ const [state, setState] = React.useState(0)
46
+ const [value, setValue] = useMMKVNumber('number-key', mmkv)
42
47
 
43
48
  return (
44
49
  <>
@@ -47,43 +52,43 @@ test('functional updates to hooks', () => {
47
52
  title="Double Increment Me"
48
53
  onPress={() => {
49
54
  // Increment the state value twice, using the function form of useState.
50
- setState((current) => current + 1);
51
- setState((current) => current + 1);
55
+ setState((current) => current + 1)
56
+ setState((current) => current + 1)
52
57
 
53
58
  // Increment the MMKV value twice, using the same function form.
54
- setValue((current) => (current ?? 0) + 1);
55
- setValue((current) => (current ?? 0) + 1);
59
+ setValue((current) => (current ?? 0) + 1)
60
+ setValue((current) => (current ?? 0) + 1)
56
61
  }}
57
62
  />
58
63
  <Text testID="state-value">State: {state.toString()}</Text>
59
64
  <Text testID="mmkv-value">MMKV: {(value ?? 0).toString()}</Text>
60
65
  </>
61
- );
62
- };
66
+ )
67
+ }
63
68
 
64
- render(<Component />);
69
+ render(<Component />)
65
70
 
66
- const button = screen.getByTestId('button');
71
+ const button = screen.getByTestId('button')
67
72
 
68
73
  // Why these assertions:
69
74
  // https://github.com/mrousavy/react-native-mmkv/issues/599
70
- fireEvent.press(button);
75
+ fireEvent.press(button)
71
76
  expect(screen.getByTestId('state-value').children).toStrictEqual([
72
77
  'State: ',
73
78
  '2',
74
- ]);
79
+ ])
75
80
  expect(screen.getByTestId('mmkv-value').children).toStrictEqual([
76
81
  'MMKV: ',
77
82
  '2',
78
- ]);
83
+ ])
79
84
 
80
- fireEvent.press(button);
85
+ fireEvent.press(button)
81
86
  expect(screen.getByTestId('state-value').children).toStrictEqual([
82
87
  'State: ',
83
88
  '4',
84
- ]);
89
+ ])
85
90
  expect(screen.getByTestId('mmkv-value').children).toStrictEqual([
86
91
  'MMKV: ',
87
92
  '4',
88
- ]);
89
- });
93
+ ])
94
+ })
@@ -0,0 +1,5 @@
1
+ import type { MMKV } from '../specs/MMKV.nitro'
2
+
3
+ export function addMemoryWarningListener(_mmkv: MMKV): void {
4
+ // This is no-op in a mocked environment.
5
+ }