react-native-mmkv 4.0.0-beta.5 → 4.0.0-beta.6
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/cpp/HybridMMKV.hpp +47 -0
- package/cpp/HybridMMKVFactory.hpp +24 -0
- package/cpp/MMKVTypes.hpp +50 -0
- package/cpp/MMKVValueChangedListenerRegistry.hpp +43 -0
- package/cpp/ManagedMMBuffer.hpp +40 -0
- package/package.json +2 -2
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HybridMMKV.hpp
|
|
3
|
+
// react-native-mmkv
|
|
4
|
+
//
|
|
5
|
+
// Created by Marc Rousavy on 21.08.2025.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "Configuration.hpp"
|
|
11
|
+
#include "HybridMMKVSpec.hpp"
|
|
12
|
+
#include "MMKVTypes.hpp"
|
|
13
|
+
|
|
14
|
+
namespace margelo::nitro::mmkv {
|
|
15
|
+
|
|
16
|
+
class HybridMMKV final : public HybridMMKVSpec {
|
|
17
|
+
public:
|
|
18
|
+
explicit HybridMMKV(const Configuration& configuration);
|
|
19
|
+
|
|
20
|
+
public:
|
|
21
|
+
// Properties
|
|
22
|
+
double getSize() override;
|
|
23
|
+
bool getIsReadOnly() override;
|
|
24
|
+
|
|
25
|
+
public:
|
|
26
|
+
// Methods
|
|
27
|
+
void set(const std::string& key, const std::variant<std::string, double, bool, std::shared_ptr<ArrayBuffer>>& value) override;
|
|
28
|
+
std::optional<bool> getBoolean(const std::string& key) override;
|
|
29
|
+
std::optional<std::string> getString(const std::string& key) override;
|
|
30
|
+
std::optional<double> getNumber(const std::string& key) override;
|
|
31
|
+
std::optional<std::shared_ptr<ArrayBuffer>> getBuffer(const std::string& key) override;
|
|
32
|
+
bool contains(const std::string& key) override;
|
|
33
|
+
void remove(const std::string& key) override;
|
|
34
|
+
std::vector<std::string> getAllKeys() override;
|
|
35
|
+
void clearAll() override;
|
|
36
|
+
void recrypt(const std::optional<std::string>& key) override;
|
|
37
|
+
void trim() override;
|
|
38
|
+
Listener addOnValueChangedListener(const std::function<void(const std::string& /* key */)>& onValueChanged) override;
|
|
39
|
+
|
|
40
|
+
private:
|
|
41
|
+
static MMKVMode getMMKVMode(const Configuration& config);
|
|
42
|
+
|
|
43
|
+
private:
|
|
44
|
+
MMKV* instance;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
} // namespace margelo::nitro::mmkv
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HybridMMKVFactory.hpp
|
|
3
|
+
// react-native-mmkv
|
|
4
|
+
//
|
|
5
|
+
// Created by Marc Rousavy on 21.08.2025.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "HybridMMKVFactorySpec.hpp"
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro::mmkv {
|
|
13
|
+
|
|
14
|
+
class HybridMMKVFactory final : public HybridMMKVFactorySpec {
|
|
15
|
+
public:
|
|
16
|
+
HybridMMKVFactory() : HybridObject(TAG) {}
|
|
17
|
+
|
|
18
|
+
public:
|
|
19
|
+
std::string getDefaultMMKVInstanceId() override;
|
|
20
|
+
std::shared_ptr<HybridMMKVSpec> createMMKV(const Configuration& configuration) override;
|
|
21
|
+
void initializeMMKV(const std::string& rootPath) override;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
} // namespace margelo::nitro::mmkv
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MMKVTypes.h
|
|
3
|
+
// react-native-mmkv
|
|
4
|
+
//
|
|
5
|
+
// Created by Brad Anderson on 10.08.2025.
|
|
6
|
+
// Platform-specific MMKV type unification header
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
// Platform-specific MMKV includes
|
|
12
|
+
#ifdef __ANDROID__
|
|
13
|
+
#include <MMKV/MMKV.h>
|
|
14
|
+
|
|
15
|
+
// On Android, bring global namespace types into mmkv namespace for consistency
|
|
16
|
+
namespace mmkv {
|
|
17
|
+
using MMKV = ::MMKV;
|
|
18
|
+
using MMKVMode = ::MMKVMode;
|
|
19
|
+
using MMKVLogLevel = ::MMKVLogLevel;
|
|
20
|
+
|
|
21
|
+
// Constants - bring into mmkv namespace
|
|
22
|
+
constexpr auto MMKVLogDebug = ::MMKVLogDebug;
|
|
23
|
+
constexpr auto MMKVLogInfo = ::MMKVLogInfo;
|
|
24
|
+
constexpr auto MMKVLogWarning = ::MMKVLogWarning;
|
|
25
|
+
constexpr auto MMKVLogError = ::MMKVLogError;
|
|
26
|
+
constexpr auto MMKVLogNone = ::MMKVLogNone;
|
|
27
|
+
|
|
28
|
+
constexpr auto MMKV_SINGLE_PROCESS = ::MMKV_SINGLE_PROCESS;
|
|
29
|
+
constexpr auto MMKV_MULTI_PROCESS = ::MMKV_MULTI_PROCESS;
|
|
30
|
+
constexpr auto MMKV_READ_ONLY = ::MMKVMode::MMKV_READ_ONLY;
|
|
31
|
+
} // namespace mmkv
|
|
32
|
+
|
|
33
|
+
#else
|
|
34
|
+
#include <MMKVCore/MMKV.h>
|
|
35
|
+
// iOS already has everything in mmkv:: namespace
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Unified MMKV namespace usage for cross-platform compatibility.
|
|
40
|
+
*
|
|
41
|
+
* After including this header, use:
|
|
42
|
+
* - mmkv::MMKV for the main class
|
|
43
|
+
* - mmkv::MMKVMode for mode enum
|
|
44
|
+
* - mmkv::MMKVLogLevel for log level enum
|
|
45
|
+
* - mmkv::MMBuffer for buffer type
|
|
46
|
+
* - mmkv::MMKV_SINGLE_PROCESS / mmkv::MMKV_MULTI_PROCESS for modes
|
|
47
|
+
* - mmkv::MMKVLogDebug, etc. for log levels
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
using namespace mmkv;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MMKVValueChangedListenerRegistry.hpp
|
|
3
|
+
// react-native-mmkv
|
|
4
|
+
//
|
|
5
|
+
// Created by Marc Rousavy on 21.08.2025.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#include "MMKVTypes.hpp"
|
|
9
|
+
#include <atomic>
|
|
10
|
+
#include <unordered_map>
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro::mmkv {
|
|
13
|
+
|
|
14
|
+
using ListenerID = size_t;
|
|
15
|
+
using MMKVID = std::string;
|
|
16
|
+
|
|
17
|
+
struct ListenerSubscription {
|
|
18
|
+
ListenerID id;
|
|
19
|
+
std::function<void(const std::string& /* key */)> callback;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Listeners are tracked across instances - so we need an extra static class for
|
|
24
|
+
* the registry.
|
|
25
|
+
*/
|
|
26
|
+
class MMKVValueChangedListenerRegistry final {
|
|
27
|
+
public:
|
|
28
|
+
MMKVValueChangedListenerRegistry() = delete;
|
|
29
|
+
~MMKVValueChangedListenerRegistry() = delete;
|
|
30
|
+
|
|
31
|
+
public:
|
|
32
|
+
static ListenerID addListener(const std::string& mmkvID, const std::function<void(const std::string& /* key */)>& callback);
|
|
33
|
+
static void removeListener(const std::string& mmkvID, ListenerID id);
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
static void notifyOnValueChanged(const std::string& mmkvID, const std::string& key);
|
|
37
|
+
|
|
38
|
+
private:
|
|
39
|
+
static std::atomic<ListenerID> _listenersCounter;
|
|
40
|
+
static std::unordered_map<MMKVID, std::vector<ListenerSubscription>> _listeners;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
} // namespace margelo::nitro::mmkv
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ManagedMMBuffer.h
|
|
3
|
+
// react-native-mmkv
|
|
4
|
+
//
|
|
5
|
+
// Created by Marc Rousavy on 25.03.24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "MMKVTypes.hpp"
|
|
11
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::mmkv {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
An ArrayBuffer subclass that manages MMBuffer memory (by ownership).
|
|
17
|
+
*/
|
|
18
|
+
class ManagedMMBuffer : public ArrayBuffer {
|
|
19
|
+
public:
|
|
20
|
+
explicit ManagedMMBuffer(MMBuffer&& buffer) : _buffer(std::move(buffer)) {}
|
|
21
|
+
|
|
22
|
+
public:
|
|
23
|
+
bool isOwner() const noexcept override {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public:
|
|
28
|
+
uint8_t* data() override {
|
|
29
|
+
return static_cast<uint8_t*>(_buffer.getPtr());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
size_t size() const override {
|
|
33
|
+
return _buffer.length();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private:
|
|
37
|
+
MMBuffer _buffer;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
} // namespace margelo::nitro::mmkv
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-mmkv",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.6",
|
|
4
4
|
"description": "react-native-mmkv",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"module": "lib/index",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"ios/**/*.cpp",
|
|
24
24
|
"ios/**/*.swift",
|
|
25
25
|
"cpp/**/*.h",
|
|
26
|
-
"cpp/**/*.
|
|
26
|
+
"cpp/**/*.hpp",
|
|
27
27
|
"cpp/**/*.cpp",
|
|
28
28
|
"app.plugin.js",
|
|
29
29
|
"nitro.json",
|