react-native-mmkv 2.10.2 → 2.12.0
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/MMKV/Core/CodedInputData.cpp +28 -4
- package/MMKV/Core/CodedInputData.h +5 -1
- package/MMKV/Core/CodedOutputData.cpp +12 -0
- package/MMKV/Core/CodedOutputData.h +6 -0
- package/MMKV/Core/MMBuffer.cpp +7 -0
- package/MMKV/Core/MMBuffer.h +3 -0
- package/MMKV/Core/MMKV.cpp +114 -19
- package/MMKV/Core/MMKV.h +69 -33
- package/MMKV/Core/MMKVPredef.h +1 -1
- package/MMKV/Core/MMKV_Android.cpp +10 -8
- package/MMKV/Core/MMKV_IO.cpp +386 -60
- package/MMKV/Core/MMKV_OSX.cpp +51 -30
- package/MMKV/Core/MMKV_OSX.h +10 -4
- package/MMKV/Core/MemoryFile.cpp +31 -11
- package/MMKV/Core/MemoryFile.h +8 -3
- package/MMKV/Core/MemoryFile_Android.cpp +2 -2
- package/MMKV/Core/MemoryFile_OSX.cpp +2 -3
- package/MMKV/Core/MemoryFile_Win32.cpp +8 -5
- package/MMKV/Core/MiniPBCoder.cpp +11 -0
- package/MMKV/Core/MiniPBCoder.h +3 -0
- package/MMKV/Core/MiniPBCoder_OSX.cpp +8 -0
- package/MMKV/Core/ThreadLock.cpp +5 -0
- package/MMKV/Core/ThreadLock.h +4 -0
- package/MMKV/Core/aes/openssl/openssl_aes-armv4.S +8 -0
- package/MMKV/Core/core.vcxproj +3 -3
- package/MMKV/README.md +3 -3
- package/README.md +9 -1
- package/android/build.gradle +21 -1
- package/android/src/hasNamespace/AndroidManifest.xml +3 -0
- package/android/src/main/cpp/MmkvHostObject.cpp +191 -204
- package/android/src/main/cpp/MmkvHostObject.h +2 -2
- package/android/src/main/cpp/cpp-adapter.cpp +62 -49
- package/cpp/TypedArray.cpp +69 -76
- package/cpp/TypedArray.h +66 -91
- package/img/banner-dark.png +0 -0
- package/img/banner-light.png +0 -0
- package/ios/JSIUtils.h +27 -39
- package/ios/JSIUtils.mm +110 -138
- package/ios/MmkvHostObject.h +2 -2
- package/ios/MmkvHostObject.mm +188 -205
- package/ios/MmkvModule.mm +68 -52
- package/lib/commonjs/createMMKV.web.js +1 -1
- package/lib/commonjs/createMMKV.web.js.map +1 -1
- package/lib/commonjs/hooks.js +16 -13
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/module/createMMKV.web.js +1 -1
- package/lib/module/createMMKV.web.js.map +1 -1
- package/lib/module/hooks.js +16 -13
- package/lib/module/hooks.js.map +1 -1
- package/lib/typescript/createMMKV.web.d.ts.map +1 -1
- package/lib/typescript/hooks.d.ts.map +1 -1
- package/package.json +13 -3
- package/react-native-mmkv.podspec +1 -1
- package/src/createMMKV.web.ts +4 -2
- package/src/hooks.ts +19 -16
- package/MMKV/LICENSE.TXT +0 -193
package/ios/JSIUtils.mm
CHANGED
|
@@ -7,189 +7,161 @@
|
|
|
7
7
|
//
|
|
8
8
|
|
|
9
9
|
#include "JSIUtils.h"
|
|
10
|
-
#import <React/RCTConvert.h>
|
|
11
10
|
#import <React/RCTBridgeModule.h>
|
|
11
|
+
#import <React/RCTConvert.h>
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* All helper functions are ObjC++ specific.
|
|
15
15
|
*/
|
|
16
|
-
jsi::Value convertNSNumberToJSIBoolean(jsi::Runtime
|
|
17
|
-
|
|
18
|
-
return jsi::Value((bool)[value boolValue]);
|
|
16
|
+
jsi::Value convertNSNumberToJSIBoolean(jsi::Runtime& runtime, NSNumber* value) {
|
|
17
|
+
return jsi::Value((bool)[value boolValue]);
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
jsi::Value convertNSNumberToJSINumber(jsi::Runtime
|
|
22
|
-
|
|
23
|
-
return jsi::Value([value doubleValue]);
|
|
20
|
+
jsi::Value convertNSNumberToJSINumber(jsi::Runtime& runtime, NSNumber* value) {
|
|
21
|
+
return jsi::Value([value doubleValue]);
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
jsi::String convertNSStringToJSIString(jsi::Runtime
|
|
27
|
-
|
|
28
|
-
return jsi::String::createFromUtf8(runtime, [value UTF8String] ?: "");
|
|
24
|
+
jsi::String convertNSStringToJSIString(jsi::Runtime& runtime, NSString* value) {
|
|
25
|
+
return jsi::String::createFromUtf8(runtime, [value UTF8String] ?: "");
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
jsi::Value convertObjCObjectToJSIValue(jsi::Runtime
|
|
28
|
+
jsi::Value convertObjCObjectToJSIValue(jsi::Runtime& runtime, id value);
|
|
32
29
|
|
|
33
|
-
jsi::Object convertNSDictionaryToJSIObject(jsi::Runtime
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return result;
|
|
30
|
+
jsi::Object convertNSDictionaryToJSIObject(jsi::Runtime& runtime, NSDictionary* value) {
|
|
31
|
+
jsi::Object result = jsi::Object(runtime);
|
|
32
|
+
for (NSString* k in value) {
|
|
33
|
+
result.setProperty(runtime, [k UTF8String], convertObjCObjectToJSIValue(runtime, value[k]));
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
40
36
|
}
|
|
41
37
|
|
|
42
|
-
jsi::Array convertNSArrayToJSIArray(jsi::Runtime
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return result;
|
|
38
|
+
jsi::Array convertNSArrayToJSIArray(jsi::Runtime& runtime, NSArray* value) {
|
|
39
|
+
jsi::Array result = jsi::Array(runtime, value.count);
|
|
40
|
+
for (size_t i = 0; i < value.count; i++) {
|
|
41
|
+
result.setValueAtIndex(runtime, i, convertObjCObjectToJSIValue(runtime, value[i]));
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
49
44
|
}
|
|
50
45
|
|
|
51
|
-
std::vector<jsi::Value> convertNSArrayToStdVector(jsi::Runtime
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return result;
|
|
46
|
+
std::vector<jsi::Value> convertNSArrayToStdVector(jsi::Runtime& runtime, NSArray* value) {
|
|
47
|
+
std::vector<jsi::Value> result;
|
|
48
|
+
for (size_t i = 0; i < value.count; i++) {
|
|
49
|
+
result.emplace_back(convertObjCObjectToJSIValue(runtime, value[i]));
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
58
52
|
}
|
|
59
53
|
|
|
60
|
-
jsi::Value convertObjCObjectToJSIValue(jsi::Runtime
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return convertNSNumberToJSIBoolean(runtime, (NSNumber *)value);
|
|
67
|
-
}
|
|
68
|
-
return convertNSNumberToJSINumber(runtime, (NSNumber *)value);
|
|
69
|
-
} else if ([value isKindOfClass:[NSDictionary class]]) {
|
|
70
|
-
return convertNSDictionaryToJSIObject(runtime, (NSDictionary *)value);
|
|
71
|
-
} else if ([value isKindOfClass:[NSArray class]]) {
|
|
72
|
-
return convertNSArrayToJSIArray(runtime, (NSArray *)value);
|
|
73
|
-
} else if (value == (id)kCFNull) {
|
|
74
|
-
return jsi::Value::null();
|
|
54
|
+
jsi::Value convertObjCObjectToJSIValue(jsi::Runtime& runtime, id value) {
|
|
55
|
+
if ([value isKindOfClass:[NSString class]]) {
|
|
56
|
+
return convertNSStringToJSIString(runtime, (NSString*)value);
|
|
57
|
+
} else if ([value isKindOfClass:[NSNumber class]]) {
|
|
58
|
+
if ([value isKindOfClass:[@YES class]]) {
|
|
59
|
+
return convertNSNumberToJSIBoolean(runtime, (NSNumber*)value);
|
|
75
60
|
}
|
|
76
|
-
return
|
|
61
|
+
return convertNSNumberToJSINumber(runtime, (NSNumber*)value);
|
|
62
|
+
} else if ([value isKindOfClass:[NSDictionary class]]) {
|
|
63
|
+
return convertNSDictionaryToJSIObject(runtime, (NSDictionary*)value);
|
|
64
|
+
} else if ([value isKindOfClass:[NSArray class]]) {
|
|
65
|
+
return convertNSArrayToJSIArray(runtime, (NSArray*)value);
|
|
66
|
+
} else if (value == (id)kCFNull) {
|
|
67
|
+
return jsi::Value::null();
|
|
68
|
+
}
|
|
69
|
+
return jsi::Value::undefined();
|
|
77
70
|
}
|
|
78
71
|
|
|
79
|
-
id convertJSIValueToObjCObject(jsi::Runtime
|
|
72
|
+
id convertJSIValueToObjCObject(jsi::Runtime& runtime, const jsi::Value& value);
|
|
80
73
|
|
|
81
|
-
NSString
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return [NSString stringWithUTF8String:string.c_str()];
|
|
74
|
+
NSString* convertJSIStringToNSString(jsi::Runtime& runtime, const jsi::String& value) {
|
|
75
|
+
auto string = value.utf8(runtime);
|
|
76
|
+
return [NSString stringWithUTF8String:string.c_str()];
|
|
85
77
|
}
|
|
86
78
|
|
|
87
|
-
NSArray
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
return [result copy];
|
|
79
|
+
NSArray* convertJSIArrayToNSArray(jsi::Runtime& runtime, const jsi::Array& value) {
|
|
80
|
+
size_t size = value.size(runtime);
|
|
81
|
+
NSMutableArray* result = [NSMutableArray new];
|
|
82
|
+
for (size_t i = 0; i < size; i++) {
|
|
83
|
+
// Insert kCFNull when it's `undefined` value to preserve the indices.
|
|
84
|
+
[result addObject:convertJSIValueToObjCObject(runtime, value.getValueAtIndex(runtime, i))
|
|
85
|
+
?: (id)kCFNull];
|
|
86
|
+
}
|
|
87
|
+
return [result copy];
|
|
98
88
|
}
|
|
99
89
|
|
|
100
|
-
NSDictionary
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (v) {
|
|
111
|
-
result[k] = v;
|
|
112
|
-
}
|
|
90
|
+
NSDictionary* convertJSIObjectToNSDictionary(jsi::Runtime& runtime, const jsi::Object& value) {
|
|
91
|
+
jsi::Array propertyNames = value.getPropertyNames(runtime);
|
|
92
|
+
size_t size = propertyNames.size(runtime);
|
|
93
|
+
NSMutableDictionary* result = [NSMutableDictionary new];
|
|
94
|
+
for (size_t i = 0; i < size; i++) {
|
|
95
|
+
jsi::String name = propertyNames.getValueAtIndex(runtime, i).getString(runtime);
|
|
96
|
+
NSString* k = convertJSIStringToNSString(runtime, name);
|
|
97
|
+
id v = convertJSIValueToObjCObject(runtime, value.getProperty(runtime, name));
|
|
98
|
+
if (v) {
|
|
99
|
+
result[k] = v;
|
|
113
100
|
}
|
|
114
|
-
|
|
101
|
+
}
|
|
102
|
+
return [result copy];
|
|
115
103
|
}
|
|
116
104
|
|
|
117
|
-
RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime
|
|
118
|
-
const jsi::Function
|
|
119
|
-
|
|
120
|
-
__block auto cb = value.getFunction(runtime);
|
|
105
|
+
RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime& runtime,
|
|
106
|
+
const jsi::Function& value) {
|
|
107
|
+
__block auto cb = value.getFunction(runtime);
|
|
121
108
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
109
|
+
return ^(NSArray* responses) {
|
|
110
|
+
cb.call(runtime, convertNSArrayToJSIArray(runtime, responses), 2);
|
|
111
|
+
};
|
|
125
112
|
}
|
|
126
113
|
|
|
127
|
-
id convertJSIValueToObjCObject(jsi::Runtime
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
114
|
+
id convertJSIValueToObjCObject(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
115
|
+
if (value.isUndefined() || value.isNull()) {
|
|
116
|
+
return nil;
|
|
117
|
+
}
|
|
118
|
+
if (value.isBool()) {
|
|
119
|
+
return @(value.getBool());
|
|
120
|
+
}
|
|
121
|
+
if (value.isNumber()) {
|
|
122
|
+
return @(value.getNumber());
|
|
123
|
+
}
|
|
124
|
+
if (value.isString()) {
|
|
125
|
+
return convertJSIStringToNSString(runtime, value.getString(runtime));
|
|
126
|
+
}
|
|
127
|
+
if (value.isObject()) {
|
|
128
|
+
jsi::Object o = value.getObject(runtime);
|
|
129
|
+
if (o.isArray(runtime)) {
|
|
130
|
+
return convertJSIArrayToNSArray(runtime, o.getArray(runtime));
|
|
141
131
|
}
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
if (o.isArray(runtime)) {
|
|
145
|
-
return convertJSIArrayToNSArray(runtime, o.getArray(runtime));
|
|
146
|
-
}
|
|
147
|
-
if (o.isFunction(runtime)) {
|
|
148
|
-
return convertJSIFunctionToCallback(runtime,
|
|
149
|
-
std::move(o.getFunction(runtime)));
|
|
150
|
-
}
|
|
151
|
-
return convertJSIObjectToNSDictionary(runtime, o);
|
|
132
|
+
if (o.isFunction(runtime)) {
|
|
133
|
+
return convertJSIFunctionToCallback(runtime, std::move(o.getFunction(runtime)));
|
|
152
134
|
}
|
|
135
|
+
return convertJSIObjectToNSDictionary(runtime, o);
|
|
136
|
+
}
|
|
153
137
|
|
|
154
|
-
|
|
138
|
+
throw std::runtime_error("Unsupported jsi::jsi::Value kind");
|
|
155
139
|
}
|
|
156
140
|
|
|
157
|
-
Promise::Promise(jsi::Runtime
|
|
158
|
-
: runtime_(rt), resolve_(std::move(resolve)), reject_(std::move(reject)) {}
|
|
141
|
+
Promise::Promise(jsi::Runtime& rt, jsi::Function resolve, jsi::Function reject)
|
|
142
|
+
: runtime_(rt), resolve_(std::move(resolve)), reject_(std::move(reject)) {}
|
|
159
143
|
|
|
160
|
-
void Promise::resolve(const jsi::Value
|
|
161
|
-
|
|
162
|
-
resolve_.call(runtime_, result);
|
|
144
|
+
void Promise::resolve(const jsi::Value& result) {
|
|
145
|
+
resolve_.call(runtime_, result);
|
|
163
146
|
}
|
|
164
147
|
|
|
165
|
-
void Promise::reject(const std::string
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
"message",
|
|
170
|
-
jsi::String::createFromUtf8(runtime_, message));
|
|
171
|
-
reject_.call(runtime_, error);
|
|
148
|
+
void Promise::reject(const std::string& message) {
|
|
149
|
+
jsi::Object error(runtime_);
|
|
150
|
+
error.setProperty(runtime_, "message", jsi::String::createFromUtf8(runtime_, message));
|
|
151
|
+
reject_.call(runtime_, error);
|
|
172
152
|
}
|
|
173
153
|
|
|
174
|
-
jsi::Value createPromiseAsJSIValue(jsi::Runtime
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
jsi::PropNameID::forAscii(rt, "fn"),
|
|
180
|
-
2,
|
|
181
|
-
[func](jsi::Runtime &rt2,
|
|
182
|
-
const jsi::Value &thisVal,
|
|
183
|
-
const jsi::Value *args,
|
|
184
|
-
size_t count) {
|
|
154
|
+
jsi::Value createPromiseAsJSIValue(jsi::Runtime& rt, const PromiseSetupFunctionType func) {
|
|
155
|
+
jsi::Function JSPromise = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
156
|
+
jsi::Function fn = jsi::Function::createFromHostFunction(
|
|
157
|
+
rt, jsi::PropNameID::forAscii(rt, "fn"), 2,
|
|
158
|
+
[func](jsi::Runtime& rt2, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
|
185
159
|
jsi::Function resolve = args[0].getObject(rt2).getFunction(rt2);
|
|
186
160
|
jsi::Function reject = args[1].getObject(rt2).getFunction(rt2);
|
|
187
|
-
auto wrapper = std::make_shared<Promise>(rt2,
|
|
188
|
-
std::move(resolve),
|
|
189
|
-
std::move(reject));
|
|
161
|
+
auto wrapper = std::make_shared<Promise>(rt2, std::move(resolve), std::move(reject));
|
|
190
162
|
func(rt2, wrapper);
|
|
191
163
|
return jsi::Value::undefined();
|
|
192
|
-
|
|
164
|
+
});
|
|
193
165
|
|
|
194
|
-
|
|
166
|
+
return JSPromise.callAsConstructor(rt, fn);
|
|
195
167
|
}
|
package/ios/MmkvHostObject.h
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
#pragma once
|
|
10
10
|
|
|
11
11
|
#import <Foundation/Foundation.h>
|
|
12
|
-
#import <jsi/jsi.h>
|
|
13
12
|
#import <MMKV/MMKV.h>
|
|
13
|
+
#import <jsi/jsi.h>
|
|
14
14
|
|
|
15
15
|
using namespace facebook;
|
|
16
16
|
|
|
17
|
-
class JSI_EXPORT MmkvHostObject: public jsi::HostObject {
|
|
17
|
+
class JSI_EXPORT MmkvHostObject : public jsi::HostObject {
|
|
18
18
|
public:
|
|
19
19
|
MmkvHostObject(NSString* instanceId, NSString* path, NSString* cryptKey);
|
|
20
20
|
|