react-native-mmkv 4.0.0 → 4.0.1
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.cpp +3 -0
- package/cpp/HybridMMKV.hpp +1 -0
- package/lib/createMMKV/createMMKV.js +1 -1
- package/lib/createMMKV/createMMKV.web.js +5 -3
- package/lib/createMMKV/createMockMMKV.d.ts +2 -1
- package/lib/createMMKV/createMockMMKV.js +6 -5
- package/lib/specs/MMKV.nitro.d.ts +13 -9
- package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.cpp +6 -0
- package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.hpp +1 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/HybridMMKVPlatformContextSpec.kt +5 -0
- package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.cpp +1 -0
- package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.hpp +3 -0
- package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec.swift +7 -0
- package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec_cxx.swift +9 -1
- package/nitrogen/generated/shared/c++/HybridMMKVSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridMMKVSpec.hpp +1 -0
- package/package.json +3 -4
- package/src/createMMKV/createMMKV.ts +1 -1
- package/src/createMMKV/createMMKV.web.ts +5 -3
- package/src/createMMKV/createMockMMKV.ts +9 -5
- package/src/specs/MMKV.nitro.ts +13 -9
package/cpp/HybridMMKV.cpp
CHANGED
package/cpp/HybridMMKV.hpp
CHANGED
|
@@ -8,7 +8,7 @@ let platformContext;
|
|
|
8
8
|
export function createMMKV(configuration) {
|
|
9
9
|
if (isTest()) {
|
|
10
10
|
// In a test environment, we mock the MMKV instance.
|
|
11
|
-
return createMockMMKV();
|
|
11
|
+
return createMockMMKV(configuration);
|
|
12
12
|
}
|
|
13
13
|
if (platformContext == null) {
|
|
14
14
|
// Lazy-init the platform-context HybridObject
|
|
@@ -59,6 +59,9 @@ export function createMMKV(config = { id: 'mmkv.default' }) {
|
|
|
59
59
|
listeners.forEach((l) => l(key));
|
|
60
60
|
};
|
|
61
61
|
return {
|
|
62
|
+
id: config.id,
|
|
63
|
+
size: 0,
|
|
64
|
+
isReadOnly: false,
|
|
62
65
|
clearAll: () => {
|
|
63
66
|
const keys = Object.keys(storage());
|
|
64
67
|
for (const key of keys) {
|
|
@@ -69,7 +72,8 @@ export function createMMKV(config = { id: 'mmkv.default' }) {
|
|
|
69
72
|
}
|
|
70
73
|
},
|
|
71
74
|
remove: (key) => {
|
|
72
|
-
|
|
75
|
+
storage().removeItem(prefixedKey(key));
|
|
76
|
+
const wasRemoved = storage().getItem(prefixedKey(key)) === null;
|
|
73
77
|
if (wasRemoved)
|
|
74
78
|
callListeners(key);
|
|
75
79
|
return wasRemoved;
|
|
@@ -109,8 +113,6 @@ export function createMMKV(config = { id: 'mmkv.default' }) {
|
|
|
109
113
|
recrypt: () => {
|
|
110
114
|
throw new Error('`recrypt(..)` is not supported on Web!');
|
|
111
115
|
},
|
|
112
|
-
size: 0,
|
|
113
|
-
isReadOnly: false,
|
|
114
116
|
trim: () => {
|
|
115
117
|
// no-op
|
|
116
118
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { MMKV } from '../specs/MMKV.nitro';
|
|
2
|
+
import type { Configuration } from '../specs/MMKVFactory.nitro';
|
|
2
3
|
/**
|
|
3
4
|
* Mock MMKV instance when used in a Jest/Test environment.
|
|
4
5
|
*/
|
|
5
|
-
export declare function createMockMMKV(): MMKV;
|
|
6
|
+
export declare function createMockMMKV(config?: Configuration): MMKV;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Mock MMKV instance when used in a Jest/Test environment.
|
|
3
3
|
*/
|
|
4
|
-
export function createMockMMKV() {
|
|
4
|
+
export function createMockMMKV(config = { id: 'mmkv.default' }) {
|
|
5
5
|
const storage = new Map();
|
|
6
6
|
const listeners = new Set();
|
|
7
7
|
const notifyListeners = (key) => {
|
|
@@ -10,6 +10,11 @@ export function createMockMMKV() {
|
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
12
|
return {
|
|
13
|
+
id: config.id,
|
|
14
|
+
get size() {
|
|
15
|
+
return storage.size;
|
|
16
|
+
},
|
|
17
|
+
isReadOnly: false,
|
|
13
18
|
clearAll: () => {
|
|
14
19
|
const keysBefore = storage.keys();
|
|
15
20
|
storage.clear();
|
|
@@ -52,10 +57,6 @@ export function createMockMMKV() {
|
|
|
52
57
|
recrypt: () => {
|
|
53
58
|
console.warn('Encryption is not supported in mocked MMKV instances!');
|
|
54
59
|
},
|
|
55
|
-
get size() {
|
|
56
|
-
return storage.size;
|
|
57
|
-
},
|
|
58
|
-
isReadOnly: false,
|
|
59
60
|
trim: () => {
|
|
60
61
|
// no-op
|
|
61
62
|
},
|
|
@@ -6,6 +6,19 @@ export interface MMKV extends HybridObject<{
|
|
|
6
6
|
ios: 'c++';
|
|
7
7
|
android: 'c++';
|
|
8
8
|
}> {
|
|
9
|
+
/**
|
|
10
|
+
* Get the ID of this {@linkcode MMKV} instance.
|
|
11
|
+
*/
|
|
12
|
+
readonly id: string;
|
|
13
|
+
/**
|
|
14
|
+
* Get the current total size of the storage, in bytes.
|
|
15
|
+
*/
|
|
16
|
+
readonly size: number;
|
|
17
|
+
/**
|
|
18
|
+
* Returns whether this instance is in read-only mode or not.
|
|
19
|
+
* If this is `true`, you can only use "get"-functions.
|
|
20
|
+
*/
|
|
21
|
+
readonly isReadOnly: boolean;
|
|
9
22
|
/**
|
|
10
23
|
* Set a {@linkcode value} for the given {@linkcode key}.
|
|
11
24
|
*
|
|
@@ -76,15 +89,6 @@ export interface MMKV extends HybridObject<{
|
|
|
76
89
|
* In most applications, this is not needed at all.
|
|
77
90
|
*/
|
|
78
91
|
trim(): void;
|
|
79
|
-
/**
|
|
80
|
-
* Get the current total size of the storage, in bytes.
|
|
81
|
-
*/
|
|
82
|
-
readonly size: number;
|
|
83
|
-
/**
|
|
84
|
-
* Returns whether this instance is in read-only mode or not.
|
|
85
|
-
* If this is `true`, you can only use "get"-functions.
|
|
86
|
-
*/
|
|
87
|
-
readonly isReadOnly: boolean;
|
|
88
92
|
/**
|
|
89
93
|
* Adds a value changed listener. The Listener will be called whenever any value
|
|
90
94
|
* in this storage instance changes (set or delete).
|
|
@@ -34,6 +34,12 @@ namespace margelo::nitro::mmkv {
|
|
|
34
34
|
method(_javaPart);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
std::string JHybridMMKVPlatformContextSpec::toString() {
|
|
38
|
+
static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
|
|
39
|
+
auto javaString = method(_javaPart);
|
|
40
|
+
return javaString->toStdString();
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
// Properties
|
|
38
44
|
|
|
39
45
|
|
|
@@ -41,6 +41,7 @@ namespace margelo::nitro::mmkv {
|
|
|
41
41
|
public:
|
|
42
42
|
size_t getExternalMemorySize() noexcept override;
|
|
43
43
|
void dispose() noexcept override;
|
|
44
|
+
std::string toString() override;
|
|
44
45
|
|
|
45
46
|
public:
|
|
46
47
|
inline const jni::global_ref<JHybridMMKVPlatformContextSpec::javaobject>& getJavaPart() const noexcept {
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/HybridMMKVPlatformContextSpec.kt
CHANGED
|
@@ -36,6 +36,11 @@ abstract class HybridMMKVPlatformContextSpec: HybridObject() {
|
|
|
36
36
|
super.updateNative(hybridData)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
// Default implementation of `HybridObject.toString()`
|
|
40
|
+
override fun toString(): String {
|
|
41
|
+
return "[HybridObject MMKVPlatformContext]"
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
// Properties
|
|
40
45
|
|
|
41
46
|
|
|
@@ -18,6 +18,13 @@ public protocol HybridMMKVPlatformContextSpec_protocol: HybridObject {
|
|
|
18
18
|
func getAppGroupDirectory() throws -> String?
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
public extension HybridMMKVPlatformContextSpec_protocol {
|
|
22
|
+
/// Default implementation of ``HybridObject.toString``
|
|
23
|
+
func toString() -> String {
|
|
24
|
+
return "[HybridObject MMKVPlatformContext]"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
/// See ``HybridMMKVPlatformContextSpec``
|
|
22
29
|
open class HybridMMKVPlatformContextSpec_base {
|
|
23
30
|
private weak var cxxWrapper: HybridMMKVPlatformContextSpec_cxx? = nil
|
|
@@ -76,7 +76,7 @@ open class HybridMMKVPlatformContextSpec_cxx {
|
|
|
76
76
|
*/
|
|
77
77
|
public func getCxxPart() -> bridge.std__shared_ptr_HybridMMKVPlatformContextSpec_ {
|
|
78
78
|
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
-
if cachedCxxPart
|
|
79
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
80
80
|
return cachedCxxPart
|
|
81
81
|
} else {
|
|
82
82
|
let newCxxPart = bridge.create_std__shared_ptr_HybridMMKVPlatformContextSpec_(self.toUnsafe())
|
|
@@ -105,6 +105,14 @@ open class HybridMMKVPlatformContextSpec_cxx {
|
|
|
105
105
|
self.__implementation.dispose()
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Call toString() on the Swift class.
|
|
110
|
+
*/
|
|
111
|
+
@inline(__always)
|
|
112
|
+
public func toString() -> String {
|
|
113
|
+
return self.__implementation.toString()
|
|
114
|
+
}
|
|
115
|
+
|
|
108
116
|
// Properties
|
|
109
117
|
|
|
110
118
|
|
|
@@ -14,6 +14,7 @@ namespace margelo::nitro::mmkv {
|
|
|
14
14
|
HybridObject::loadHybridMethods();
|
|
15
15
|
// load custom methods/properties
|
|
16
16
|
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("id", &HybridMMKVSpec::getId);
|
|
17
18
|
prototype.registerHybridGetter("size", &HybridMMKVSpec::getSize);
|
|
18
19
|
prototype.registerHybridGetter("isReadOnly", &HybridMMKVSpec::getIsReadOnly);
|
|
19
20
|
prototype.registerHybridMethod("set", &HybridMMKVSpec::set);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-mmkv",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "⚡️ The fastest key/value storage for React Native.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"module": "lib/index",
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"README.md"
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
|
-
"postinstall": "tsc || exit 0;",
|
|
35
34
|
"typecheck": "tsc --noEmit",
|
|
36
35
|
"clean": "rm -rf android/build node_modules/**/android/build lib",
|
|
37
36
|
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
|
|
@@ -68,11 +67,11 @@
|
|
|
68
67
|
"eslint": "^8.57.0",
|
|
69
68
|
"eslint-config-prettier": "^9.1.0",
|
|
70
69
|
"eslint-plugin-prettier": "^5.2.1",
|
|
71
|
-
"nitrogen": "0.31.
|
|
70
|
+
"nitrogen": "0.31.7",
|
|
72
71
|
"prettier": "^3.3.3",
|
|
73
72
|
"react": "19.1.1",
|
|
74
73
|
"react-native": "0.82.0",
|
|
75
|
-
"react-native-nitro-modules": "0.31.
|
|
74
|
+
"react-native-nitro-modules": "0.31.7",
|
|
76
75
|
"typescript": "^5.8.3"
|
|
77
76
|
},
|
|
78
77
|
"peerDependencies": {
|
|
@@ -13,7 +13,7 @@ let platformContext: MMKVPlatformContext | undefined
|
|
|
13
13
|
export function createMMKV(configuration?: Configuration): MMKV {
|
|
14
14
|
if (isTest()) {
|
|
15
15
|
// In a test environment, we mock the MMKV instance.
|
|
16
|
-
return createMockMMKV()
|
|
16
|
+
return createMockMMKV(configuration)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
if (platformContext == null) {
|
|
@@ -85,6 +85,9 @@ export function createMMKV(
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
return {
|
|
88
|
+
id: config.id,
|
|
89
|
+
size: 0,
|
|
90
|
+
isReadOnly: false,
|
|
88
91
|
clearAll: () => {
|
|
89
92
|
const keys = Object.keys(storage())
|
|
90
93
|
for (const key of keys) {
|
|
@@ -95,7 +98,8 @@ export function createMMKV(
|
|
|
95
98
|
}
|
|
96
99
|
},
|
|
97
100
|
remove: (key) => {
|
|
98
|
-
|
|
101
|
+
storage().removeItem(prefixedKey(key))
|
|
102
|
+
const wasRemoved = storage().getItem(prefixedKey(key)) === null
|
|
99
103
|
if (wasRemoved) callListeners(key)
|
|
100
104
|
return wasRemoved
|
|
101
105
|
},
|
|
@@ -130,8 +134,6 @@ export function createMMKV(
|
|
|
130
134
|
recrypt: () => {
|
|
131
135
|
throw new Error('`recrypt(..)` is not supported on Web!')
|
|
132
136
|
},
|
|
133
|
-
size: 0,
|
|
134
|
-
isReadOnly: false,
|
|
135
137
|
trim: () => {
|
|
136
138
|
// no-op
|
|
137
139
|
},
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { MMKV } from '../specs/MMKV.nitro'
|
|
2
|
+
import type { Configuration } from '../specs/MMKVFactory.nitro'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Mock MMKV instance when used in a Jest/Test environment.
|
|
5
6
|
*/
|
|
6
|
-
export function createMockMMKV(
|
|
7
|
+
export function createMockMMKV(
|
|
8
|
+
config: Configuration = { id: 'mmkv.default' }
|
|
9
|
+
): MMKV {
|
|
7
10
|
const storage = new Map<string, string | boolean | number | ArrayBuffer>()
|
|
8
11
|
const listeners = new Set<(key: string) => void>()
|
|
9
12
|
|
|
@@ -14,6 +17,11 @@ export function createMockMMKV(): MMKV {
|
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
return {
|
|
20
|
+
id: config.id,
|
|
21
|
+
get size(): number {
|
|
22
|
+
return storage.size
|
|
23
|
+
},
|
|
24
|
+
isReadOnly: false,
|
|
17
25
|
clearAll: () => {
|
|
18
26
|
const keysBefore = storage.keys()
|
|
19
27
|
storage.clear()
|
|
@@ -55,10 +63,6 @@ export function createMockMMKV(): MMKV {
|
|
|
55
63
|
recrypt: () => {
|
|
56
64
|
console.warn('Encryption is not supported in mocked MMKV instances!')
|
|
57
65
|
},
|
|
58
|
-
get size(): number {
|
|
59
|
-
return storage.size
|
|
60
|
-
},
|
|
61
|
-
isReadOnly: false,
|
|
62
66
|
trim: () => {
|
|
63
67
|
// no-op
|
|
64
68
|
},
|
package/src/specs/MMKV.nitro.ts
CHANGED
|
@@ -5,6 +5,19 @@ export interface Listener {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export interface MMKV extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
|
|
8
|
+
/**
|
|
9
|
+
* Get the ID of this {@linkcode MMKV} instance.
|
|
10
|
+
*/
|
|
11
|
+
readonly id: string
|
|
12
|
+
/**
|
|
13
|
+
* Get the current total size of the storage, in bytes.
|
|
14
|
+
*/
|
|
15
|
+
readonly size: number
|
|
16
|
+
/**
|
|
17
|
+
* Returns whether this instance is in read-only mode or not.
|
|
18
|
+
* If this is `true`, you can only use "get"-functions.
|
|
19
|
+
*/
|
|
20
|
+
readonly isReadOnly: boolean
|
|
8
21
|
/**
|
|
9
22
|
* Set a {@linkcode value} for the given {@linkcode key}.
|
|
10
23
|
*
|
|
@@ -75,15 +88,6 @@ export interface MMKV extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
|
|
|
75
88
|
* In most applications, this is not needed at all.
|
|
76
89
|
*/
|
|
77
90
|
trim(): void
|
|
78
|
-
/**
|
|
79
|
-
* Get the current total size of the storage, in bytes.
|
|
80
|
-
*/
|
|
81
|
-
readonly size: number
|
|
82
|
-
/**
|
|
83
|
-
* Returns whether this instance is in read-only mode or not.
|
|
84
|
-
* If this is `true`, you can only use "get"-functions.
|
|
85
|
-
*/
|
|
86
|
-
readonly isReadOnly: boolean
|
|
87
91
|
/**
|
|
88
92
|
* Adds a value changed listener. The Listener will be called whenever any value
|
|
89
93
|
* in this storage instance changes (set or delete).
|