react-native-mmkv 4.0.0-beta.1 → 4.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{react-native-mmkv.podspec → NitroMmkv.podspec} +17 -13
- package/README.md +1 -3
- package/android/CMakeLists.txt +31 -30
- package/android/build.gradle +64 -19
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -5
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/mmkv/HybridMMKVPlatformContext.kt +19 -0
- package/android/src/main/java/com/margelo/nitro/mmkv/NitroMmkvPackage.java +33 -0
- package/ios/HybridMMKVPlatformContext.swift +32 -0
- package/lib/__tests__/hooks.test.d.ts +1 -0
- package/lib/__tests__/hooks.test.js +66 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.d.ts +2 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.js +25 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.d.ts +2 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.js +3 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.web.d.ts +2 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.web.js +3 -0
- package/lib/createMMKV/createMMKV.d.ts +3 -0
- package/lib/createMMKV/createMMKV.js +40 -0
- package/lib/createMMKV/createMMKV.mock.d.ts +5 -0
- package/lib/createMMKV/createMMKV.mock.js +53 -0
- package/lib/createMMKV/createMMKV.web.d.ts +3 -0
- package/lib/createMMKV/createMMKV.web.js +117 -0
- package/lib/createMMKV/getDefaultMMKVInstance.d.ts +2 -0
- package/lib/createMMKV/getDefaultMMKVInstance.js +8 -0
- package/lib/hooks/createMMKVHook.d.ts +2 -0
- package/lib/hooks/createMMKVHook.js +49 -0
- package/lib/hooks/useMMKV.d.ts +11 -0
- package/lib/hooks/useMMKV.js +23 -0
- package/lib/hooks/useMMKVBoolean.d.ts +11 -0
- package/lib/hooks/useMMKVBoolean.js +12 -0
- package/lib/hooks/useMMKVBuffer.d.ts +11 -0
- package/lib/hooks/useMMKVBuffer.js +12 -0
- package/lib/hooks/useMMKVKeys.d.ts +12 -0
- package/lib/hooks/useMMKVKeys.js +33 -0
- package/lib/hooks/useMMKVListener.d.ts +15 -0
- package/lib/hooks/useMMKVListener.js +26 -0
- package/lib/hooks/useMMKVNumber.d.ts +11 -0
- package/lib/hooks/useMMKVNumber.js +12 -0
- package/lib/hooks/useMMKVObject.d.ts +17 -0
- package/lib/hooks/useMMKVObject.js +38 -0
- package/lib/hooks/useMMKVString.d.ts +11 -0
- package/lib/hooks/useMMKVString.js +12 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/lib/isTest.d.ts +1 -0
- package/lib/isTest.js +7 -0
- package/lib/specs/MMKV.nitro.d.ts +93 -0
- package/lib/specs/MMKV.nitro.js +1 -0
- package/lib/{typescript/src/NativeMmkv.d.ts → specs/MMKVFactory.nitro.d.ts} +22 -29
- package/lib/specs/MMKVFactory.nitro.js +1 -0
- package/lib/specs/MMKVPlatformContext.nitro.d.ts +15 -0
- package/lib/specs/MMKVPlatformContext.nitro.js +1 -0
- package/lib/{typescript/src → web}/createTextEncoder.d.ts +0 -1
- package/lib/web/createTextEncoder.js +17 -0
- package/nitro.json +27 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroMmkv+autolinking.cmake +80 -0
- package/nitrogen/generated/android/NitroMmkv+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroMmkvOnLoad.cpp +55 -0
- package/nitrogen/generated/android/NitroMmkvOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.cpp +51 -0
- package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.hpp +65 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/HybridMMKVPlatformContextSpec.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/NitroMmkvOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroMmkv+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.cpp +32 -0
- package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.hpp +52 -0
- package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Umbrella.hpp +44 -0
- package/nitrogen/generated/ios/NitroMmkvAutolinking.mm +43 -0
- package/nitrogen/generated/ios/NitroMmkvAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.hpp +81 -0
- package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec.swift +50 -0
- package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec_cxx.swift +135 -0
- package/nitrogen/generated/shared/c++/Configuration.hpp +86 -0
- package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.hpp +69 -0
- package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.hpp +63 -0
- package/nitrogen/generated/shared/c++/HybridMMKVSpec.cpp +34 -0
- package/nitrogen/generated/shared/c++/HybridMMKVSpec.hpp +83 -0
- package/nitrogen/generated/shared/c++/Listener.hpp +67 -0
- package/nitrogen/generated/shared/c++/Mode.hpp +76 -0
- package/package.json +71 -122
- package/react-native.config.js +2 -15
- package/src/__tests__/hooks.test.tsx +34 -34
- package/src/addMemoryWarningListener/addMemoryWarningListener.mock.ts +5 -0
- package/src/{MemoryWarningListener.ts → addMemoryWarningListener/addMemoryWarningListener.ts} +12 -12
- package/src/addMemoryWarningListener/addMemoryWarningListener.web.ts +5 -0
- package/src/createMMKV/createMMKV.mock.ts +56 -0
- package/src/createMMKV/createMMKV.ts +51 -0
- package/src/{createMMKV.web.ts → createMMKV/createMMKV.web.ts} +56 -46
- package/src/createMMKV/getDefaultMMKVInstance.ts +10 -0
- package/src/hooks/createMMKVHook.ts +66 -0
- package/src/hooks/useMMKV.ts +45 -0
- package/src/hooks/useMMKVBoolean.ts +15 -0
- package/src/hooks/useMMKVBuffer.ts +15 -0
- package/src/hooks/useMMKVKeys.ts +36 -0
- package/src/hooks/useMMKVListener.ts +33 -0
- package/src/hooks/useMMKVNumber.ts +15 -0
- package/src/hooks/useMMKVObject.ts +53 -0
- package/src/hooks/useMMKVString.ts +15 -0
- package/src/index.ts +15 -3
- package/src/{PlatformChecker.ts → isTest.ts} +2 -2
- package/src/specs/MMKV.nitro.ts +92 -0
- package/src/specs/MMKVFactory.nitro.ts +87 -0
- package/src/specs/MMKVPlatformContext.nitro.ts +14 -0
- package/src/{createTextEncoder.ts → web/createTextEncoder.ts} +7 -7
- package/android/src/main/cpp/AndroidLogger.cpp +0 -16
- package/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java +0 -44
- package/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java +0 -26
- package/cpp/ManagedMMBuffer.h +0 -32
- package/cpp/MmkvHostObject.cpp +0 -360
- package/cpp/MmkvHostObject.h +0 -31
- package/cpp/MmkvLogger.h +0 -35
- package/cpp/MmkvTypes.h +0 -50
- package/cpp/NativeMmkvModule.cpp +0 -43
- package/cpp/NativeMmkvModule.h +0 -31
- package/ios/AppleLogger.mm +0 -16
- package/ios/MmkvOnLoad.mm +0 -25
- package/ios/MmkvPlatformContext.h +0 -19
- package/ios/MmkvPlatformContextModule.mm +0 -55
- package/lib/commonjs/MMKV.js +0 -124
- package/lib/commonjs/MMKV.js.map +0 -1
- package/lib/commonjs/MemoryWarningListener.js +0 -31
- package/lib/commonjs/MemoryWarningListener.js.map +0 -1
- package/lib/commonjs/MemoryWarningListener.web.js +0 -11
- package/lib/commonjs/MemoryWarningListener.web.js.map +0 -1
- package/lib/commonjs/ModuleNotFoundError.js +0 -75
- package/lib/commonjs/ModuleNotFoundError.js.map +0 -1
- package/lib/commonjs/NativeMmkv.js +0 -47
- package/lib/commonjs/NativeMmkv.js.map +0 -1
- package/lib/commonjs/NativeMmkvPlatformContext.js +0 -22
- package/lib/commonjs/NativeMmkvPlatformContext.js.map +0 -1
- package/lib/commonjs/PlatformChecker.js +0 -14
- package/lib/commonjs/PlatformChecker.js.map +0 -1
- package/lib/commonjs/Types.js +0 -26
- package/lib/commonjs/Types.js.map +0 -1
- package/lib/commonjs/createMMKV.js +0 -43
- package/lib/commonjs/createMMKV.js.map +0 -1
- package/lib/commonjs/createMMKV.mock.js +0 -43
- package/lib/commonjs/createMMKV.mock.js.map +0 -1
- package/lib/commonjs/createMMKV.web.js +0 -110
- package/lib/commonjs/createMMKV.web.js.map +0 -1
- package/lib/commonjs/createTextEncoder.js +0 -23
- package/lib/commonjs/createTextEncoder.js.map +0 -1
- package/lib/commonjs/hooks.js +0 -198
- package/lib/commonjs/hooks.js.map +0 -1
- package/lib/commonjs/index.js +0 -40
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/package.json +0 -1
- package/lib/module/MMKV.js +0 -119
- package/lib/module/MMKV.js.map +0 -1
- package/lib/module/MemoryWarningListener.js +0 -27
- package/lib/module/MemoryWarningListener.js.map +0 -1
- package/lib/module/MemoryWarningListener.web.js +0 -6
- package/lib/module/MemoryWarningListener.web.js.map +0 -1
- package/lib/module/ModuleNotFoundError.js +0 -70
- package/lib/module/ModuleNotFoundError.js.map +0 -1
- package/lib/module/NativeMmkv.js +0 -45
- package/lib/module/NativeMmkv.js.map +0 -1
- package/lib/module/NativeMmkvPlatformContext.js +0 -18
- package/lib/module/NativeMmkvPlatformContext.js.map +0 -1
- package/lib/module/PlatformChecker.js +0 -10
- package/lib/module/PlatformChecker.js.map +0 -1
- package/lib/module/Types.js +0 -25
- package/lib/module/Types.js.map +0 -1
- package/lib/module/createMMKV.js +0 -38
- package/lib/module/createMMKV.js.map +0 -1
- package/lib/module/createMMKV.mock.js +0 -38
- package/lib/module/createMMKV.mock.js.map +0 -1
- package/lib/module/createMMKV.web.js +0 -105
- package/lib/module/createMMKV.web.js.map +0 -1
- package/lib/module/createTextEncoder.js +0 -19
- package/lib/module/createTextEncoder.js.map +0 -1
- package/lib/module/hooks.js +0 -189
- package/lib/module/hooks.js.map +0 -1
- package/lib/module/index.js +0 -6
- package/lib/module/index.js.map +0 -1
- package/lib/module/package.json +0 -1
- package/lib/typescript/src/MMKV.d.ts +0 -34
- package/lib/typescript/src/MMKV.d.ts.map +0 -1
- package/lib/typescript/src/MemoryWarningListener.d.ts +0 -3
- package/lib/typescript/src/MemoryWarningListener.d.ts.map +0 -1
- package/lib/typescript/src/MemoryWarningListener.web.d.ts +0 -3
- package/lib/typescript/src/MemoryWarningListener.web.d.ts.map +0 -1
- package/lib/typescript/src/ModuleNotFoundError.d.ts +0 -7
- package/lib/typescript/src/ModuleNotFoundError.d.ts.map +0 -1
- package/lib/typescript/src/NativeMmkv.d.ts.map +0 -1
- package/lib/typescript/src/NativeMmkvPlatformContext.d.ts +0 -20
- package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +0 -1
- package/lib/typescript/src/PlatformChecker.d.ts +0 -2
- package/lib/typescript/src/PlatformChecker.d.ts.map +0 -1
- package/lib/typescript/src/Types.d.ts +0 -172
- package/lib/typescript/src/Types.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/hooks.test.d.ts +0 -2
- package/lib/typescript/src/__tests__/hooks.test.d.ts.map +0 -1
- package/lib/typescript/src/createMMKV.d.ts +0 -3
- package/lib/typescript/src/createMMKV.d.ts.map +0 -1
- package/lib/typescript/src/createMMKV.mock.d.ts +0 -3
- package/lib/typescript/src/createMMKV.mock.d.ts.map +0 -1
- package/lib/typescript/src/createMMKV.web.d.ts +0 -3
- package/lib/typescript/src/createMMKV.web.d.ts.map +0 -1
- package/lib/typescript/src/createTextEncoder.d.ts.map +0 -1
- package/lib/typescript/src/hooks.d.ts +0 -86
- package/lib/typescript/src/hooks.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -4
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/src/MMKV.ts +0 -142
- package/src/MemoryWarningListener.web.ts +0 -5
- package/src/ModuleNotFoundError.ts +0 -95
- package/src/NativeMmkv.ts +0 -118
- package/src/NativeMmkvPlatformContext.ts +0 -38
- package/src/Types.ts +0 -178
- package/src/createMMKV.mock.ts +0 -38
- package/src/createMMKV.ts +0 -42
- package/src/hooks.ts +0 -247
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
|
|
20
|
+
namespace margelo::nitro::mmkv {
|
|
21
|
+
|
|
22
|
+
using namespace margelo::nitro;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* An abstract base class for `MMKVPlatformContext`
|
|
26
|
+
* Inherit this class to create instances of `HybridMMKVPlatformContextSpec` in C++.
|
|
27
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
28
|
+
* @example
|
|
29
|
+
* ```cpp
|
|
30
|
+
* class HybridMMKVPlatformContext: public HybridMMKVPlatformContextSpec {
|
|
31
|
+
* public:
|
|
32
|
+
* HybridMMKVPlatformContext(...): HybridObject(TAG) { ... }
|
|
33
|
+
* // ...
|
|
34
|
+
* };
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
class HybridMMKVPlatformContextSpec: public virtual HybridObject {
|
|
38
|
+
public:
|
|
39
|
+
// Constructor
|
|
40
|
+
explicit HybridMMKVPlatformContextSpec(): HybridObject(TAG) { }
|
|
41
|
+
|
|
42
|
+
// Destructor
|
|
43
|
+
~HybridMMKVPlatformContextSpec() override = default;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
// Properties
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
// Methods
|
|
51
|
+
virtual std::string getBaseDirectory() = 0;
|
|
52
|
+
virtual std::string getAppGroupDirectory() = 0;
|
|
53
|
+
|
|
54
|
+
protected:
|
|
55
|
+
// Hybrid Setup
|
|
56
|
+
void loadHybridMethods() override;
|
|
57
|
+
|
|
58
|
+
protected:
|
|
59
|
+
// Tag for logging
|
|
60
|
+
static constexpr auto TAG = "MMKVPlatformContext";
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
} // 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 void 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,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-mmkv",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "lib/
|
|
6
|
-
"module": "lib/
|
|
7
|
-
"types": "lib/
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
4
|
+
"description": "react-native-mmkv",
|
|
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
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
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
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
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
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
24
|
+
"ios/**/*.swift",
|
|
25
|
+
"app.plugin.js",
|
|
26
|
+
"nitro.json",
|
|
27
|
+
"*.podspec",
|
|
28
28
|
"README.md"
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
|
-
"
|
|
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",
|
|
31
|
+
"postinstall": "tsc || exit 0;",
|
|
37
32
|
"typecheck": "tsc --noEmit",
|
|
38
|
-
"clean": "
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
33
|
+
"clean": "rm -rf android/build node_modules/**/android/build lib",
|
|
34
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
|
|
35
|
+
"lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
|
|
36
|
+
"typescript": "tsc",
|
|
37
|
+
"specs": "tsc && nitro-codegen --logLevel=\"debug\"",
|
|
38
|
+
"build": "tsc --noEmit false",
|
|
42
39
|
"release": "release-it",
|
|
43
|
-
"
|
|
40
|
+
"test": "jest"
|
|
44
41
|
},
|
|
45
42
|
"keywords": [
|
|
46
43
|
"react-native",
|
|
47
|
-
"
|
|
48
|
-
"android",
|
|
49
|
-
"mmkv",
|
|
50
|
-
"storage",
|
|
51
|
-
"key",
|
|
52
|
-
"value",
|
|
53
|
-
"fast",
|
|
54
|
-
"turbo",
|
|
55
|
-
"async"
|
|
44
|
+
"nitro"
|
|
56
45
|
],
|
|
57
46
|
"repository": {
|
|
58
47
|
"type": "git",
|
|
59
48
|
"url": "git+https://github.com/mrousavy/react-native-mmkv.git"
|
|
60
49
|
},
|
|
61
50
|
"author": "Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
|
|
62
|
-
"license": "
|
|
51
|
+
"license": "MIT",
|
|
63
52
|
"bugs": {
|
|
64
53
|
"url": "https://github.com/mrousavy/react-native-mmkv/issues"
|
|
65
54
|
},
|
|
@@ -68,111 +57,71 @@
|
|
|
68
57
|
"registry": "https://registry.npmjs.org/"
|
|
69
58
|
},
|
|
70
59
|
"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/babel-preset": "^0.81.0",
|
|
76
60
|
"@react-native/eslint-config": "0.81.0",
|
|
77
|
-
"@
|
|
78
|
-
"@
|
|
79
|
-
"@types/
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"eslint": "
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"prettier": "3.3.3",
|
|
61
|
+
"@testing-library/react-native": "^13.3.1",
|
|
62
|
+
"@types/jest": "^29.5.12",
|
|
63
|
+
"@types/react": "^19.0.6",
|
|
64
|
+
"eslint": "^8.57.0",
|
|
65
|
+
"eslint-config-prettier": "^9.1.0",
|
|
66
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
67
|
+
"jest": "^30.0.5",
|
|
68
|
+
"nitro-codegen": "*",
|
|
69
|
+
"prettier": "^3.3.3",
|
|
87
70
|
"react": "19.1.0",
|
|
88
71
|
"react-native": "0.81.0",
|
|
89
|
-
"react-native-
|
|
90
|
-
"react-test-renderer": "19.1.0",
|
|
91
|
-
"release-it": "17.10.0",
|
|
72
|
+
"react-native-nitro-modules": "*",
|
|
92
73
|
"typescript": "^5.8.3"
|
|
93
74
|
},
|
|
94
75
|
"peerDependencies": {
|
|
95
76
|
"react": "*",
|
|
96
|
-
"react-native": "*"
|
|
77
|
+
"react-native": "*",
|
|
78
|
+
"react-native-nitro-modules": "*"
|
|
97
79
|
},
|
|
98
|
-
"
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
]
|
|
80
|
+
"eslintConfig": {
|
|
81
|
+
"root": true,
|
|
82
|
+
"extends": [
|
|
83
|
+
"@react-native",
|
|
84
|
+
"prettier"
|
|
85
|
+
],
|
|
86
|
+
"plugins": [
|
|
87
|
+
"prettier"
|
|
88
|
+
],
|
|
89
|
+
"rules": {
|
|
90
|
+
"prettier/prettier": [
|
|
91
|
+
"warn",
|
|
92
|
+
{
|
|
93
|
+
"quoteProps": "consistent",
|
|
94
|
+
"singleQuote": true,
|
|
95
|
+
"tabWidth": 2,
|
|
96
|
+
"trailingComma": "es5",
|
|
97
|
+
"useTabs": false
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
}
|
|
104
101
|
},
|
|
102
|
+
"eslintIgnore": [
|
|
103
|
+
"node_modules/",
|
|
104
|
+
"lib/"
|
|
105
|
+
],
|
|
105
106
|
"release-it": {
|
|
106
|
-
"git": {
|
|
107
|
-
"commitMessage": "chore: release ${version}",
|
|
108
|
-
"tagName": "v${version}"
|
|
109
|
-
},
|
|
110
107
|
"npm": {
|
|
111
108
|
"publish": true
|
|
112
109
|
},
|
|
110
|
+
"git": false,
|
|
113
111
|
"github": {
|
|
114
|
-
"release":
|
|
112
|
+
"release": false
|
|
115
113
|
},
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
"name": "conventionalcommits",
|
|
120
|
-
"types": [
|
|
121
|
-
{
|
|
122
|
-
"type": "feat",
|
|
123
|
-
"section": "✨ Features"
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
"type": "fix",
|
|
127
|
-
"section": "🐛 Bug Fixes"
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
"type": "perf",
|
|
131
|
-
"section": "💨 Performance Improvements"
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
"type": "chore(deps)",
|
|
135
|
-
"section": "🛠️ Dependency Upgrades"
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
"type": "docs",
|
|
139
|
-
"section": "📚 Documentation"
|
|
140
|
-
}
|
|
141
|
-
]
|
|
142
|
-
}
|
|
143
|
-
}
|
|
114
|
+
"hooks": {
|
|
115
|
+
"before:init": "bun typecheck",
|
|
116
|
+
"after:bump": "bun run build"
|
|
144
117
|
}
|
|
145
118
|
},
|
|
146
|
-
"eslintIgnore": [
|
|
147
|
-
"node_modules/",
|
|
148
|
-
"lib/",
|
|
149
|
-
"MMKV"
|
|
150
|
-
],
|
|
151
119
|
"prettier": {
|
|
152
120
|
"quoteProps": "consistent",
|
|
153
121
|
"singleQuote": true,
|
|
154
122
|
"tabWidth": 2,
|
|
155
123
|
"trailingComma": "es5",
|
|
156
|
-
"useTabs": false
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
"source": "src",
|
|
160
|
-
"output": "lib",
|
|
161
|
-
"targets": [
|
|
162
|
-
"commonjs",
|
|
163
|
-
"module",
|
|
164
|
-
[
|
|
165
|
-
"typescript",
|
|
166
|
-
{
|
|
167
|
-
"project": "tsconfig.json"
|
|
168
|
-
}
|
|
169
|
-
]
|
|
170
|
-
]
|
|
171
|
-
},
|
|
172
|
-
"codegenConfig": {
|
|
173
|
-
"name": "RNMmkvSpec",
|
|
174
|
-
"type": "modules",
|
|
175
|
-
"jsSrcsDir": "src"
|
|
176
|
-
},
|
|
177
|
-
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
|
|
124
|
+
"useTabs": false,
|
|
125
|
+
"semi": false
|
|
126
|
+
}
|
|
178
127
|
}
|
package/react-native.config.js
CHANGED
|
@@ -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
|
-
|
|
21
|
-
codegenConfig: {
|
|
22
|
-
name: 'RNMmkvSpec',
|
|
23
|
-
type: 'modules',
|
|
24
|
-
jsSrcsDir: 'src',
|
|
25
|
-
android: {
|
|
26
|
-
javaPackageName: 'com.mrousavy.mmkv',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
16
|
+
}
|