react-native-mmkv 2.12.2 → 3.0.0-beta.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/LICENSE +1 -200
- package/MMKV/Core/Core.xcodeproj/project.pbxproj +4 -2
- package/MMKV/Core/MMKVPredef.h +1 -1
- package/MMKV/Core/MMKV_IO.cpp +5 -1
- package/MMKV/Core/MemoryFile.cpp +1 -0
- package/MMKV/Core/MemoryFile_OSX.cpp +2 -1
- package/MMKV/README.md +8 -8
- package/README.md +7 -1
- package/android/CMakeLists.txt +20 -28
- package/android/build.gradle +59 -89
- package/android/gradle.properties +4 -5
- package/android/src/main/AndroidManifest.xml +2 -2
- package/android/src/{hasNamespace/AndroidManifest.xml → main/AndroidManifestNew.xml} +0 -1
- package/android/src/main/cpp/AndroidLogger.cpp +16 -0
- package/android/src/main/cpp/cpp-adapter.cpp +4 -80
- package/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java +44 -0
- package/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java +17 -0
- package/cpp/Logger.h +35 -0
- package/cpp/MMKVManagedBuffer.h +37 -0
- package/{android/src/main/cpp → cpp}/MmkvHostObject.cpp +126 -63
- package/{android/src/main/cpp → cpp}/MmkvHostObject.h +14 -3
- package/cpp/NativeMmkvModule.cpp +40 -0
- package/cpp/NativeMmkvModule.h +37 -0
- package/ios/AppleLogger.mm +16 -0
- package/ios/MmkvOnLoad.mm +25 -0
- package/ios/MmkvPlatformContext.h +19 -0
- package/ios/MmkvPlatformContextModule.mm +37 -0
- package/lib/commonjs/MMKV.js +34 -4
- package/lib/commonjs/MMKV.js.map +1 -1
- package/lib/commonjs/NativeMmkv.js +66 -0
- package/lib/commonjs/NativeMmkv.js.map +1 -0
- package/lib/commonjs/NativeMmkvPlatformContext.js +9 -0
- package/lib/commonjs/NativeMmkvPlatformContext.js.map +1 -0
- package/lib/commonjs/PlatformChecker.js.map +1 -1
- package/lib/commonjs/createMMKV.js +7 -43
- package/lib/commonjs/createMMKV.js.map +1 -1
- package/lib/commonjs/createMMKV.mock.js +5 -1
- package/lib/commonjs/createMMKV.mock.js.map +1 -1
- package/lib/commonjs/createMMKV.web.js +8 -4
- package/lib/commonjs/createMMKV.web.js.map +1 -1
- package/lib/commonjs/createTextEncoder.js.map +1 -1
- package/lib/commonjs/hooks.js +11 -10
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/MMKV.js +23 -4
- package/lib/module/MMKV.js.map +1 -1
- package/lib/module/NativeMmkv.js +63 -0
- package/lib/module/NativeMmkv.js.map +1 -0
- package/lib/module/NativeMmkvPlatformContext.js +3 -0
- package/lib/module/NativeMmkvPlatformContext.js.map +1 -0
- package/lib/module/PlatformChecker.js.map +1 -1
- package/lib/module/createMMKV.js +7 -43
- package/lib/module/createMMKV.js.map +1 -1
- package/lib/module/createMMKV.mock.js +5 -1
- package/lib/module/createMMKV.mock.js.map +1 -1
- package/lib/module/createMMKV.web.js +6 -4
- package/lib/module/createMMKV.web.js.map +1 -1
- package/lib/module/createTextEncoder.js.map +1 -1
- package/lib/module/hooks.js +7 -2
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/{MMKV.d.ts → src/MMKV.d.ts} +26 -49
- package/lib/typescript/src/MMKV.d.ts.map +1 -0
- package/lib/typescript/src/NativeMmkv.d.ts +79 -0
- package/lib/typescript/src/NativeMmkv.d.ts.map +1 -0
- package/lib/typescript/src/NativeMmkvPlatformContext.d.ts +9 -0
- package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +1 -0
- package/lib/typescript/src/PlatformChecker.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/hooks.test.d.ts +2 -0
- package/lib/typescript/src/__tests__/hooks.test.d.ts.map +1 -0
- package/lib/typescript/src/createMMKV.d.ts +3 -0
- package/lib/typescript/src/createMMKV.d.ts.map +1 -0
- package/lib/typescript/src/createMMKV.mock.d.ts +3 -0
- package/lib/typescript/src/createMMKV.mock.d.ts.map +1 -0
- package/lib/typescript/src/createMMKV.web.d.ts +3 -0
- package/lib/typescript/src/createMMKV.web.d.ts.map +1 -0
- package/lib/typescript/src/createTextEncoder.d.ts.map +1 -0
- package/lib/typescript/{hooks.d.ts → src/hooks.d.ts} +7 -4
- package/lib/typescript/src/hooks.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +49 -40
- package/react-native-mmkv.podspec +17 -18
- package/src/MMKV.ts +40 -62
- package/src/NativeMmkv.ts +132 -0
- package/src/NativeMmkvPlatformContext.ts +12 -0
- package/src/__tests__/hooks.test.tsx +88 -0
- package/src/createMMKV.mock.ts +7 -3
- package/src/createMMKV.ts +9 -63
- package/src/createMMKV.web.ts +6 -2
- package/src/hooks.ts +17 -11
- package/android/src/main/java/com/reactnativemmkv/MmkvModule.java +0 -49
- package/android/src/main/java/com/reactnativemmkv/MmkvPackage.java +0 -26
- package/cpp/TypedArray.cpp +0 -322
- package/cpp/TypedArray.h +0 -153
- package/ios/JSIUtils.h +0 -38
- package/ios/JSIUtils.mm +0 -167
- package/ios/Mmkv.xcodeproj/project.pbxproj +0 -291
- package/ios/MmkvHostObject.h +0 -27
- package/ios/MmkvHostObject.mm +0 -295
- package/ios/MmkvModule.h +0 -5
- package/ios/MmkvModule.mm +0 -101
- package/lib/typescript/MMKV.d.ts.map +0 -1
- package/lib/typescript/PlatformChecker.d.ts.map +0 -1
- package/lib/typescript/createMMKV.d.ts +0 -7
- package/lib/typescript/createMMKV.d.ts.map +0 -1
- package/lib/typescript/createMMKV.mock.d.ts +0 -3
- package/lib/typescript/createMMKV.mock.d.ts.map +0 -1
- package/lib/typescript/createMMKV.web.d.ts +0 -3
- package/lib/typescript/createMMKV.web.d.ts.map +0 -1
- package/lib/typescript/createTextEncoder.d.ts.map +0 -1
- package/lib/typescript/hooks.d.ts.map +0 -1
- package/lib/typescript/index.d.ts.map +0 -1
- /package/lib/typescript/{PlatformChecker.d.ts → src/PlatformChecker.d.ts} +0 -0
- /package/lib/typescript/{createTextEncoder.d.ts → src/createTextEncoder.d.ts} +0 -0
- /package/lib/typescript/{index.d.ts → src/index.d.ts} +0 -0
- /package/src/{index.ts → index.tsx} +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/// <reference types="react-native/types/modules/Codegen" />
|
|
2
|
+
import { TurboModule } from 'react-native';
|
|
3
|
+
import { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
+
/**
|
|
5
|
+
* Configures the mode of the MMKV instance.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum Mode {
|
|
8
|
+
/**
|
|
9
|
+
* The MMKV instance is only used from a single process (this app).
|
|
10
|
+
*/
|
|
11
|
+
SINGLE_PROCESS = 0,
|
|
12
|
+
/**
|
|
13
|
+
* The MMKV instance may be used from multiple processes, such as app clips, share extensions or background services.
|
|
14
|
+
*/
|
|
15
|
+
MULTI_PROCESS = 1
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Used for configuration of a single MMKV instance.
|
|
19
|
+
*/
|
|
20
|
+
export interface Configuration {
|
|
21
|
+
/**
|
|
22
|
+
* The MMKV instance's ID. If you want to use multiple instances, make sure to use different IDs!
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const userStorage = new MMKV({ id: `user-${userId}-storage` })
|
|
27
|
+
* const globalStorage = new MMKV({ id: 'global-app-storage' })
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @default 'mmkv.default'
|
|
31
|
+
*/
|
|
32
|
+
id: string;
|
|
33
|
+
/**
|
|
34
|
+
* The MMKV instance's root path. By default, MMKV stores file inside `$(Documents)/mmkv/`. You can customize MMKV's root directory on MMKV initialization:
|
|
35
|
+
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const temporaryStorage = new MMKV({ path: '/tmp/' })
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* _Notice_: On iOS you can set the AppGroup bundle property to share the same storage between your app and its extensions.
|
|
42
|
+
* In this case `path` property will be ignored.
|
|
43
|
+
* See more on MMKV configuration [here](https://github.com/Tencent/MMKV/wiki/iOS_tutorial#configuration).
|
|
44
|
+
*
|
|
45
|
+
* @default undefined
|
|
46
|
+
*/
|
|
47
|
+
path?: string;
|
|
48
|
+
/**
|
|
49
|
+
* The MMKV instance's encryption/decryption key. By default, MMKV stores all key-values in plain text on file, relying on iOS's sandbox to make sure the file is encrypted. Should you worry about information leaking, you can choose to encrypt MMKV.
|
|
50
|
+
*
|
|
51
|
+
* Encryption keys can have a maximum length of 16 bytes.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const secureStorage = new MMKV({ encryptionKey: 'my-encryption-key!' })
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @default undefined
|
|
59
|
+
*/
|
|
60
|
+
encryptionKey?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Configure the processing mode for MMKV.
|
|
63
|
+
* - `SINGLE_PROCESS`: The MMKV instance is only used from a single process (this app).
|
|
64
|
+
* - `MULTI_PROCESS`: The MMKV instance may be used from multiple processes, such as app clips, share extensions or background services.
|
|
65
|
+
*
|
|
66
|
+
* @default SINGLE_PROCESS
|
|
67
|
+
*/
|
|
68
|
+
mode?: Mode;
|
|
69
|
+
}
|
|
70
|
+
export interface Spec extends TurboModule {
|
|
71
|
+
initialize(basePath: string): boolean;
|
|
72
|
+
createMMKV(configuration: Configuration): UnsafeObject;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get the MMKV TurboModule, and initialize it if this is the first time calling.
|
|
76
|
+
* This will throw an error if the module cannot be found.
|
|
77
|
+
*/
|
|
78
|
+
export declare function getMMKVTurboModule(): Spec;
|
|
79
|
+
//# sourceMappingURL=NativeMmkv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeMmkv.d.ts","sourceRoot":"","sources":["../../../src/NativeMmkv.ts"],"names":[],"mappings":";AAAA,OAAO,EAA2B,WAAW,EAAE,MAAM,cAAc,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAGzE;;GAEG;AACH,oBAAY,IAAI;IACd;;OAEG;IACH,cAAc,IAAA;IACd;;OAEG;IACH,aAAa,IAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;OAUG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IACtC,UAAU,CAAC,aAAa,EAAE,aAAa,GAAG,YAAY,CAAC;CACxD;AAKD;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CA8CzC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TurboModule } from 'react-native';
|
|
2
|
+
export interface Spec extends TurboModule {
|
|
3
|
+
/**
|
|
4
|
+
* Gets the base directory of the documents storage
|
|
5
|
+
*/
|
|
6
|
+
getBaseDirectory(): string;
|
|
7
|
+
}
|
|
8
|
+
export declare const PlatformContext: Spec;
|
|
9
|
+
//# sourceMappingURL=NativeMmkvPlatformContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeMmkvPlatformContext.d.ts","sourceRoot":"","sources":["../../../src/NativeMmkvPlatformContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAuB,MAAM,cAAc,CAAC;AAEhE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC;;OAEG;IACH,gBAAgB,IAAI,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,eAAe,MAE3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformChecker.d.ts","sourceRoot":"","sources":["../../../src/PlatformChecker.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,IAAI,OAAO,CAMhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.test.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/hooks.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMMKV.d.ts","sourceRoot":"","sources":["../../../src/createMMKV.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAKxD,eAAO,MAAM,UAAU,WAAY,aAAa,KAAG,UAUlD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMMKV.mock.d.ts","sourceRoot":"","sources":["../../../src/createMMKV.mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGzC,eAAO,MAAM,cAAc,QAAO,UAiCjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMMKV.web.d.ts","sourceRoot":"","sources":["../../../src/createMMKV.web.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAoBxD,eAAO,MAAM,UAAU,WAAY,aAAa,KAAG,UAwGlD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTextEncoder.d.ts","sourceRoot":"","sources":["../../../src/createTextEncoder.ts"],"names":[],"mappings":"AACA,wBAAgB,iBAAiB,IAAI,WAAW,CAc/C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MMKV,
|
|
1
|
+
import { MMKV, Configuration } from './MMKV';
|
|
2
2
|
/**
|
|
3
3
|
* Use the default, shared MMKV instance.
|
|
4
4
|
*/
|
|
@@ -7,7 +7,7 @@ export declare function useMMKV(): MMKV;
|
|
|
7
7
|
* Use a custom MMKV instance with the given configuration.
|
|
8
8
|
* @param configuration The configuration to initialize the MMKV instance with. Does not have to be memoized.
|
|
9
9
|
*/
|
|
10
|
-
export declare function useMMKV(configuration:
|
|
10
|
+
export declare function useMMKV(configuration: Configuration): MMKV;
|
|
11
11
|
/**
|
|
12
12
|
* Use the string value of the given `key` from the given MMKV storage instance.
|
|
13
13
|
*
|
|
@@ -51,7 +51,7 @@ export declare const useMMKVBoolean: (key: string, instance?: MMKV) => [value: b
|
|
|
51
51
|
* const [privateKey, setPrivateKey] = useMMKVBuffer("user.privateKey")
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
|
-
export declare const useMMKVBuffer: (key: string, instance?: MMKV) => [value:
|
|
54
|
+
export declare const useMMKVBuffer: (key: string, instance?: MMKV) => [value: ArrayBuffer | undefined, setValue: (value: ArrayBuffer | ((current: ArrayBuffer | undefined) => ArrayBuffer | undefined) | undefined) => void];
|
|
55
55
|
/**
|
|
56
56
|
* Use an object value of the given `key` from the given MMKV storage instance.
|
|
57
57
|
*
|
|
@@ -64,7 +64,10 @@ export declare const useMMKVBuffer: (key: string, instance?: MMKV) => [value: Ui
|
|
|
64
64
|
* const [user, setUser] = useMMKVObject<User>("user")
|
|
65
65
|
* ```
|
|
66
66
|
*/
|
|
67
|
-
export declare function useMMKVObject<T>(key: string, instance?: MMKV): [
|
|
67
|
+
export declare function useMMKVObject<T>(key: string, instance?: MMKV): [
|
|
68
|
+
value: T | undefined,
|
|
69
|
+
setValue: (value: T | undefined | ((prevValue: T | undefined) => T | undefined)) => void
|
|
70
|
+
];
|
|
68
71
|
/**
|
|
69
72
|
* Listen for changes in the given MMKV storage instance.
|
|
70
73
|
* If no instance is passed, the default instance will be used.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAwB7C;;GAEG;AACH,wBAAgB,OAAO,IAAI,IAAI,CAAC;AAChC;;;GAGG;AACH,wBAAgB,OAAO,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI,CAAC;AAiF5D;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,QAnEjB,MAAM,aACA,IAAI,kIAC8B,IAAI,CAmEpD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,QAjFjB,MAAM,aACA,IAAI,kIAC8B,IAAI,CAiFpD,CAAC;AACF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,QA9FlB,MAAM,aACA,IAAI,sIAC8B,IAAI,CA8FpD,CAAC;AACF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,QA3GjB,MAAM,aACA,IAAI,sJAC8B,IAAI,CA2GpD,CAAC;AACF;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,IAAI,GACd;IACD,KAAK,EAAE,CAAC,GAAG,SAAS;IACpB,QAAQ,EAAE,CACR,KAAK,EAAE,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,SAAS,CAAC,KACjE,IAAI;CACV,CA4BA;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,oBAAoB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,EAC3C,QAAQ,CAAC,EAAE,IAAI,GACd,IAAI,CAYN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-mmkv",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"description": "The fastest key/value storage for React Native. ~30x faster than AsyncStorage! Works on Android, iOS and Web.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
7
|
-
"types": "lib/typescript/index.d.ts",
|
|
8
|
-
"react-native": "
|
|
7
|
+
"types": "lib/typescript/src/index.d.ts",
|
|
8
|
+
"react-native": "src/index",
|
|
9
9
|
"source": "src/index",
|
|
10
10
|
"files": [
|
|
11
11
|
"android/src",
|
|
12
12
|
"android/build.gradle",
|
|
13
|
-
"android/gradle.properties",
|
|
14
13
|
"android/CMakeLists.txt",
|
|
14
|
+
"android/cpp-adapter.cpp",
|
|
15
|
+
"android/gradle.properties",
|
|
15
16
|
"cpp",
|
|
16
17
|
"MMKV/Core",
|
|
17
18
|
"lib/commonjs",
|
|
@@ -21,7 +22,6 @@
|
|
|
21
22
|
"ios/**/*.m",
|
|
22
23
|
"ios/**/*.mm",
|
|
23
24
|
"ios/**/*.cpp",
|
|
24
|
-
"ios/Mmkv.xcodeproj/project.pbxproj",
|
|
25
25
|
"src",
|
|
26
26
|
"react-native-mmkv.podspec",
|
|
27
27
|
"README.md",
|
|
@@ -34,21 +34,32 @@
|
|
|
34
34
|
"lint-ci": "yarn lint -f ./node_modules/@firmnav/eslint-github-actions-formatter/dist/formatter.js",
|
|
35
35
|
"lint-cpp": "scripts/clang-format.sh",
|
|
36
36
|
"test": "jest",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
37
39
|
"prepare": "git submodule update --init --recursive && bob build",
|
|
38
40
|
"prepack": "bob build",
|
|
39
41
|
"update-submodule": "git submodule update --remote --merge",
|
|
40
|
-
"release": "release-it",
|
|
41
|
-
"example": "yarn --cwd example",
|
|
42
42
|
"pods": "cd example && yarn pods",
|
|
43
|
-
"
|
|
43
|
+
"release": "release-it",
|
|
44
|
+
"codegen": "npx react-native codegen"
|
|
44
45
|
},
|
|
45
46
|
"keywords": [
|
|
46
47
|
"react-native",
|
|
47
48
|
"ios",
|
|
48
|
-
"android"
|
|
49
|
+
"android",
|
|
50
|
+
"mmkv",
|
|
51
|
+
"storage",
|
|
52
|
+
"key",
|
|
53
|
+
"value",
|
|
54
|
+
"fast",
|
|
55
|
+
"turbo",
|
|
56
|
+
"async"
|
|
49
57
|
],
|
|
50
|
-
"repository":
|
|
51
|
-
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://github.com/mrousavy/react-native-mmkv.git"
|
|
61
|
+
},
|
|
62
|
+
"author": "Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
|
|
52
63
|
"license": "(MIT AND BSD-3-Clause)",
|
|
53
64
|
"bugs": {
|
|
54
65
|
"url": "https://github.com/mrousavy/react-native-mmkv/issues"
|
|
@@ -58,33 +69,30 @@
|
|
|
58
69
|
"registry": "https://registry.npmjs.org/"
|
|
59
70
|
},
|
|
60
71
|
"devDependencies": {
|
|
61
|
-
"@
|
|
62
|
-
"@react-native
|
|
63
|
-
"@react-native-community/eslint-plugin": "^1.3.0",
|
|
72
|
+
"@react-native-community/cli-types": "^14.0.0-alpha.1",
|
|
73
|
+
"@react-native/eslint-config": "^0.75.0-main",
|
|
64
74
|
"@release-it/conventional-changelog": "^8.0.1",
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"@typescript-eslint/parser": "^7.0.1",
|
|
72
|
-
"eslint": "^8.56.0",
|
|
73
|
-
"eslint-plugin-ft-flow": "^3.0.4",
|
|
74
|
-
"eslint-plugin-jest": "^27.8.0",
|
|
75
|
+
"@types/jest": "^29.5.5",
|
|
76
|
+
"@types/react": "^18.2.70",
|
|
77
|
+
"del-cli": "^5.1.0",
|
|
78
|
+
"eslint": "^8.51.0",
|
|
79
|
+
"eslint-config-prettier": "^9.0.0",
|
|
80
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
75
81
|
"jest": "^29.7.0",
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"react": "
|
|
79
|
-
"react-native": "^0.
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
"prettier": "^3.0.3",
|
|
83
|
+
"react": "18.2.0",
|
|
84
|
+
"react-native": "0.74.0-rc.5",
|
|
85
|
+
"react-native-builder-bob": "^0.23.2",
|
|
86
|
+
"release-it": "^17.1.1",
|
|
87
|
+
"typescript": "^5.2.2"
|
|
88
|
+
},
|
|
89
|
+
"resolutions": {
|
|
90
|
+
"@types/react": "^18.2.44",
|
|
91
|
+
"@react-native-community/cli": "^14.0.0-alpha.1"
|
|
84
92
|
},
|
|
85
93
|
"peerDependencies": {
|
|
86
94
|
"react": "*",
|
|
87
|
-
"react-native": "
|
|
95
|
+
"react-native": "*"
|
|
88
96
|
},
|
|
89
97
|
"jest": {
|
|
90
98
|
"preset": "react-native",
|
|
@@ -137,12 +145,9 @@
|
|
|
137
145
|
"eslintConfig": {
|
|
138
146
|
"root": true,
|
|
139
147
|
"extends": [
|
|
140
|
-
"@react-native
|
|
148
|
+
"@react-native",
|
|
141
149
|
"prettier"
|
|
142
150
|
],
|
|
143
|
-
"plugins": [
|
|
144
|
-
"jest"
|
|
145
|
-
],
|
|
146
151
|
"rules": {
|
|
147
152
|
"prettier/prettier": [
|
|
148
153
|
"error",
|
|
@@ -182,8 +187,12 @@
|
|
|
182
187
|
]
|
|
183
188
|
},
|
|
184
189
|
"codegenConfig": {
|
|
185
|
-
"name": "
|
|
190
|
+
"name": "RNMmkvSpec",
|
|
186
191
|
"type": "modules",
|
|
187
|
-
"jsSrcsDir": "
|
|
188
|
-
}
|
|
192
|
+
"jsSrcsDir": "src"
|
|
193
|
+
},
|
|
194
|
+
"dependencies": {
|
|
195
|
+
"@testing-library/react-native": "^12.4.4"
|
|
196
|
+
},
|
|
197
|
+
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
|
|
189
198
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require "json"
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
4
5
|
|
|
5
6
|
Pod::Spec.new do |s|
|
|
6
7
|
s.name = "react-native-mmkv"
|
|
@@ -10,27 +11,25 @@ Pod::Spec.new do |s|
|
|
|
10
11
|
s.license = package["license"]
|
|
11
12
|
s.authors = package["author"]
|
|
12
13
|
|
|
13
|
-
s.platforms = { :ios =>
|
|
14
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
15
|
s.source = { :git => "https://github.com/mrousavy/react-native-mmkv.git", :tag => "#{s.version}" }
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
s.pod_target_xcconfig = {
|
|
18
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
|
|
19
|
+
"CLANG_CXX_LIBRARY" => "libc++",
|
|
20
|
+
"CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF" => "NO",
|
|
21
|
+
# FORCE_POSIX ensures we are using C++ types instead of Objective-C types for MMKV.
|
|
22
|
+
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FORCE_POSIX",
|
|
23
|
+
}
|
|
24
|
+
s.compiler_flags = '-x objective-c++'
|
|
25
|
+
|
|
18
26
|
s.source_files = [
|
|
19
|
-
|
|
20
|
-
"ios
|
|
21
|
-
"cpp/**/*.{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
# Otherwise there will be a nameclash, since CocoaPods flattens out any header directories
|
|
25
|
-
# See https://github.com/firebase/firebase-ios-sdk/issues/4035 for more details.
|
|
26
|
-
s.preserve_paths = [
|
|
27
|
-
'ios/**/*.h'
|
|
27
|
+
# react-native-mmkv
|
|
28
|
+
"ios/**/*.{h,m,mm}",
|
|
29
|
+
"cpp/**/*.{hpp,cpp,c,h}",
|
|
30
|
+
# MMKV/Core
|
|
31
|
+
"MMKV/Core/**/*.{h,cpp,hpp,S}",
|
|
28
32
|
]
|
|
29
33
|
|
|
30
|
-
s
|
|
31
|
-
if respond_to?(:install_modules_dependencies, true)
|
|
32
|
-
install_modules_dependencies(s)
|
|
33
|
-
else
|
|
34
|
-
s.dependency "React-Core"
|
|
35
|
-
end
|
|
34
|
+
install_modules_dependencies(s)
|
|
36
35
|
end
|
package/src/MMKV.ts
CHANGED
|
@@ -1,61 +1,22 @@
|
|
|
1
|
+
import { AppState } from 'react-native';
|
|
1
2
|
import { createMMKV } from './createMMKV';
|
|
2
3
|
import { createMockMMKV } from './createMMKV.mock';
|
|
3
4
|
import { isJest } from './PlatformChecker';
|
|
5
|
+
import { Configuration } from './NativeMmkv';
|
|
6
|
+
export { Configuration, Mode } from './NativeMmkv';
|
|
4
7
|
|
|
5
8
|
interface Listener {
|
|
6
9
|
remove: () => void;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
/**
|
|
10
|
-
* Used for configuration of a single MMKV instance.
|
|
11
|
-
*/
|
|
12
|
-
export interface MMKVConfiguration {
|
|
13
|
-
/**
|
|
14
|
-
* The MMKV instance's ID. If you want to use multiple instances, make sure to use different IDs!
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* const userStorage = new MMKV({ id: `user-${userId}-storage` })
|
|
19
|
-
* const globalStorage = new MMKV({ id: 'global-app-storage' })
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @default 'mmkv.default'
|
|
23
|
-
*/
|
|
24
|
-
id: string;
|
|
25
|
-
/**
|
|
26
|
-
* The MMKV instance's root path. By default, MMKV stores file inside `$(Documents)/mmkv/`. You can customize MMKV's root directory on MMKV initialization:
|
|
27
|
-
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const temporaryStorage = new MMKV({ path: '/tmp/' })
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* _Notice_: On iOS you can set the AppGroup bundle property to share the same storage between your app and its extensions.
|
|
34
|
-
* In this case `path` property will be ignored.
|
|
35
|
-
* See more on MMKV configuration [here](https://github.com/Tencent/MMKV/wiki/iOS_tutorial#configuration).
|
|
36
|
-
*/
|
|
37
|
-
path?: string;
|
|
38
|
-
/**
|
|
39
|
-
* The MMKV instance's encryption/decryption key. By default, MMKV stores all key-values in plain text on file, relying on iOS's sandbox to make sure the file is encrypted. Should you worry about information leaking, you can choose to encrypt MMKV.
|
|
40
|
-
*
|
|
41
|
-
* Encryption keys can have a maximum length of 16 bytes.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* const secureStorage = new MMKV({ encryptionKey: 'my-encryption-key!' })
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
encryptionKey?: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
12
|
/**
|
|
52
13
|
* Represents a single MMKV instance.
|
|
53
14
|
*/
|
|
54
|
-
interface
|
|
15
|
+
export interface NativeMMKV {
|
|
55
16
|
/**
|
|
56
17
|
* Set a value for the given `key`.
|
|
57
18
|
*/
|
|
58
|
-
set: (key: string, value: boolean | string | number |
|
|
19
|
+
set: (key: string, value: boolean | string | number | ArrayBuffer) => void;
|
|
59
20
|
/**
|
|
60
21
|
* Get the boolean value for the given `key`, or `undefined` if it does not exist.
|
|
61
22
|
*
|
|
@@ -79,7 +40,7 @@ interface MMKVInterface {
|
|
|
79
40
|
*
|
|
80
41
|
* @default undefined
|
|
81
42
|
*/
|
|
82
|
-
getBuffer: (key: string) =>
|
|
43
|
+
getBuffer: (key: string) => ArrayBuffer | undefined;
|
|
83
44
|
/**
|
|
84
45
|
* Checks whether the given `key` is being stored in this MMKV instance.
|
|
85
46
|
*/
|
|
@@ -106,6 +67,23 @@ interface MMKVInterface {
|
|
|
106
67
|
* Encryption keys can have a maximum length of 16 bytes.
|
|
107
68
|
*/
|
|
108
69
|
recrypt: (key: string | undefined) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Trims the storage space and clears memory cache.
|
|
72
|
+
*
|
|
73
|
+
* Since MMKV does not resize itself after deleting keys, you can call `trim()`
|
|
74
|
+
* after deleting a bunch of keys to manually trim the memory- and
|
|
75
|
+
* disk-file to reduce storage and memory usage.
|
|
76
|
+
*
|
|
77
|
+
* In most applications, this is not needed at all.
|
|
78
|
+
*/
|
|
79
|
+
trim(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Get the current total size of the storage, in bytes.
|
|
82
|
+
*/
|
|
83
|
+
readonly size: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface MMKVInterface extends NativeMMKV {
|
|
109
87
|
/**
|
|
110
88
|
* Adds a value changed listener. The Listener will be called whenever any value
|
|
111
89
|
* in this storage instance changes (set or delete).
|
|
@@ -117,20 +95,6 @@ interface MMKVInterface {
|
|
|
117
95
|
) => Listener;
|
|
118
96
|
}
|
|
119
97
|
|
|
120
|
-
export type NativeMMKV = Pick<
|
|
121
|
-
MMKVInterface,
|
|
122
|
-
| 'clearAll'
|
|
123
|
-
| 'contains'
|
|
124
|
-
| 'delete'
|
|
125
|
-
| 'getAllKeys'
|
|
126
|
-
| 'getBoolean'
|
|
127
|
-
| 'getNumber'
|
|
128
|
-
| 'getString'
|
|
129
|
-
| 'getBuffer'
|
|
130
|
-
| 'set'
|
|
131
|
-
| 'recrypt'
|
|
132
|
-
>;
|
|
133
|
-
|
|
134
98
|
const onValueChangedListeners = new Map<string, ((key: string) => void)[]>();
|
|
135
99
|
|
|
136
100
|
/**
|
|
@@ -145,12 +109,19 @@ export class MMKV implements MMKVInterface {
|
|
|
145
109
|
* Creates a new MMKV instance with the given Configuration.
|
|
146
110
|
* If no custom `id` is supplied, `'mmkv.default'` will be used.
|
|
147
111
|
*/
|
|
148
|
-
constructor(configuration:
|
|
112
|
+
constructor(configuration: Configuration = { id: 'mmkv.default' }) {
|
|
149
113
|
this.id = configuration.id;
|
|
150
114
|
this.nativeInstance = isJest()
|
|
151
115
|
? createMockMMKV()
|
|
152
116
|
: createMMKV(configuration);
|
|
153
117
|
this.functionCache = {};
|
|
118
|
+
|
|
119
|
+
if ('WeakRef' in global) {
|
|
120
|
+
const weakSelf = new WeakRef(this);
|
|
121
|
+
AppState.addEventListener('memoryWarning', () => {
|
|
122
|
+
weakSelf.deref()?.trim();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
154
125
|
}
|
|
155
126
|
|
|
156
127
|
private get onValueChangedListeners() {
|
|
@@ -179,7 +150,10 @@ export class MMKV implements MMKVInterface {
|
|
|
179
150
|
}
|
|
180
151
|
}
|
|
181
152
|
|
|
182
|
-
|
|
153
|
+
get size(): number {
|
|
154
|
+
return this.nativeInstance.size;
|
|
155
|
+
}
|
|
156
|
+
set(key: string, value: boolean | string | number | ArrayBuffer): void {
|
|
183
157
|
const func = this.getFunctionFromCache('set');
|
|
184
158
|
func(key, value);
|
|
185
159
|
|
|
@@ -197,7 +171,7 @@ export class MMKV implements MMKVInterface {
|
|
|
197
171
|
const func = this.getFunctionFromCache('getNumber');
|
|
198
172
|
return func(key);
|
|
199
173
|
}
|
|
200
|
-
getBuffer(key: string):
|
|
174
|
+
getBuffer(key: string): ArrayBuffer | undefined {
|
|
201
175
|
const func = this.getFunctionFromCache('getBuffer');
|
|
202
176
|
return func(key);
|
|
203
177
|
}
|
|
@@ -227,6 +201,10 @@ export class MMKV implements MMKVInterface {
|
|
|
227
201
|
const func = this.getFunctionFromCache('recrypt');
|
|
228
202
|
return func(key);
|
|
229
203
|
}
|
|
204
|
+
trim(): void {
|
|
205
|
+
const func = this.getFunctionFromCache('trim');
|
|
206
|
+
func();
|
|
207
|
+
}
|
|
230
208
|
|
|
231
209
|
toString(): string {
|
|
232
210
|
return `MMKV (${this.id}): [${this.getAllKeys().join(', ')}]`;
|