react-native-mmkv 3.0.2 → 3.2.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/MMKV.cpp +51 -15
- package/MMKV/Core/MMKV.h +19 -5
- package/MMKV/Core/MMKVPredef.h +2 -2
- package/MMKV/Core/MMKV_Android.cpp +13 -13
- package/MMKV/Core/MMKV_IO.cpp +37 -6
- package/MMKV/Core/MMKV_OSX.cpp +15 -4
- package/MMKV/Core/MemoryFile.cpp +24 -10
- package/MMKV/Core/MemoryFile.h +8 -2
- package/MMKV/Core/MemoryFile_Android.cpp +4 -3
- package/MMKV/Core/MemoryFile_Win32.cpp +22 -11
- package/MMKV/Core/aes/AESCrypt.cpp +19 -24
- package/MMKV/Core/aes/AESCrypt.h +4 -1
- package/MMKV/README.md +354 -0
- package/README.md +5 -0
- package/cpp/MmkvHostObject.cpp +18 -3
- package/cpp/NativeMmkvModule.h +1 -1
- package/lib/commonjs/MMKV.js +5 -5
- package/lib/commonjs/MMKV.js.map +1 -1
- package/lib/commonjs/MemoryWarningListener.js +31 -0
- package/lib/commonjs/MemoryWarningListener.js.map +1 -0
- package/lib/commonjs/MemoryWarningListener.web.js +11 -0
- package/lib/commonjs/MemoryWarningListener.web.js.map +1 -0
- package/lib/commonjs/NativeMmkv.js +10 -5
- package/lib/commonjs/NativeMmkv.js.map +1 -1
- package/lib/commonjs/NativeMmkvPlatformContext.js +4 -4
- package/lib/commonjs/NativeMmkvPlatformContext.js.map +1 -1
- package/lib/commonjs/Types.js +24 -0
- package/lib/commonjs/Types.js.map +1 -1
- package/lib/commonjs/createMMKV.js +7 -0
- package/lib/commonjs/createMMKV.js.map +1 -1
- package/lib/commonjs/createMMKV.mock.js +1 -0
- package/lib/commonjs/createMMKV.mock.js.map +1 -1
- package/lib/commonjs/createMMKV.web.js +1 -0
- package/lib/commonjs/createMMKV.web.js.map +1 -1
- package/lib/commonjs/index.js +3 -10
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/MMKV.js +5 -5
- package/lib/module/MMKV.js.map +1 -1
- package/lib/module/MemoryWarningListener.js +27 -0
- package/lib/module/MemoryWarningListener.js.map +1 -0
- package/lib/module/MemoryWarningListener.web.js +6 -0
- package/lib/module/MemoryWarningListener.web.js.map +1 -0
- package/lib/module/NativeMmkv.js +10 -5
- package/lib/module/NativeMmkv.js.map +1 -1
- package/lib/module/NativeMmkvPlatformContext.js +4 -4
- package/lib/module/NativeMmkvPlatformContext.js.map +1 -1
- package/lib/module/Types.js +23 -0
- package/lib/module/Types.js.map +1 -1
- package/lib/module/createMMKV.js +7 -0
- package/lib/module/createMMKV.js.map +1 -1
- package/lib/module/createMMKV.mock.js +1 -0
- package/lib/module/createMMKV.mock.js.map +1 -1
- package/lib/module/createMMKV.web.js +1 -0
- package/lib/module/createMMKV.web.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/MMKV.d.ts +2 -2
- package/lib/typescript/src/MMKV.d.ts.map +1 -1
- package/lib/typescript/src/MemoryWarningListener.d.ts +3 -0
- package/lib/typescript/src/MemoryWarningListener.d.ts.map +1 -0
- package/lib/typescript/src/MemoryWarningListener.web.d.ts +3 -0
- package/lib/typescript/src/MemoryWarningListener.web.d.ts.map +1 -0
- package/lib/typescript/src/NativeMmkv.d.ts +9 -0
- package/lib/typescript/src/NativeMmkv.d.ts.map +1 -1
- package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +1 -1
- package/lib/typescript/src/Types.d.ts +76 -0
- package/lib/typescript/src/Types.d.ts.map +1 -1
- package/lib/typescript/src/createMMKV.d.ts +1 -2
- package/lib/typescript/src/createMMKV.d.ts.map +1 -1
- package/lib/typescript/src/createMMKV.mock.d.ts.map +1 -1
- package/lib/typescript/src/createMMKV.web.d.ts +1 -2
- package/lib/typescript/src/createMMKV.web.d.ts.map +1 -1
- package/lib/typescript/src/hooks.d.ts +1 -1
- package/lib/typescript/src/hooks.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +12 -14
- package/react-native-mmkv.podspec +1 -1
- package/src/MMKV.ts +11 -7
- package/src/MemoryWarningListener.ts +29 -0
- package/src/MemoryWarningListener.web.ts +5 -0
- package/src/NativeMmkv.ts +14 -5
- package/src/NativeMmkvPlatformContext.ts +6 -4
- package/src/Types.ts +79 -0
- package/src/createMMKV.mock.ts +1 -0
- package/src/createMMKV.ts +9 -2
- package/src/createMMKV.web.ts +2 -2
- package/src/hooks.ts +1 -1
- package/src/index.ts +1 -1
- package/img/banner-dark.png +0 -0
- package/img/banner-light.png +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createTextEncoder","canUseDOM","window","document","createElement","hasAccessToLocalStorage","localStorage","KEY_WILDCARD","inMemoryStorage","Map","createMMKV","config","encryptionKey","Error","path","console","warn","storage","getItem","key","get","setItem","value","set","removeItem","delete","clear","length","size","index","Object","keys","at","domStorage","global","textEncoder","id","includes","keyPrefix","prefixedKey","clearAll","startsWith","toString","getString","undefined","getNumber","Number","getBoolean","getBuffer","encode","getAllKeys","filter","map","slice","contains","recrypt","trim"],"sourceRoot":"../../src","sources":["createMMKV.web.ts"],"mappings":";;AAAA;;
|
|
1
|
+
{"version":3,"names":["createTextEncoder","canUseDOM","window","document","createElement","hasAccessToLocalStorage","localStorage","KEY_WILDCARD","inMemoryStorage","Map","createMMKV","config","encryptionKey","Error","path","console","warn","storage","getItem","key","get","setItem","value","set","removeItem","delete","clear","length","size","index","Object","keys","at","domStorage","global","textEncoder","id","includes","keyPrefix","prefixedKey","clearAll","startsWith","toString","getString","undefined","getNumber","Number","getBoolean","getBuffer","encode","getAllKeys","filter","map","slice","contains","recrypt","isReadOnly","trim"],"sourceRoot":"../../src","sources":["createMMKV.web.ts"],"mappings":";;AAAA;;AAEA,SAASA,iBAAiB,QAAQ,qBAAqB;AAEvD,MAAMC,SAAS,GACb,OA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AAC,CAAC;IAC9C,CAAC;IACD2B,QAAQ,EAAGnC,GAAG,IAAKF,OAAO,CAAC,CAAC,CAACC,OAAO,CAACqB,WAAW,CAACpB,GAAG,CAAC,CAAC,IAAI,IAAI;IAC9DoC,OAAO,EAAEA,CAAA,KAAM;MACb,MAAM,IAAI1C,KAAK,CAAC,wCAAwC,CAAC;IAC3D,CAAC;IACDe,IAAI,EAAE,CAAC;IACP4B,UAAU,EAAE,KAAK;IACjBC,IAAI,EAAEA,CAAA,KAAM;MACV;IAAA;EAEJ,CAAC;AACH,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Mode"
|
|
1
|
+
{"version":3,"names":["Mode"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,cAAc,QAAQ;AACtB,cAAc,SAAS;AAEvB,SAASA,IAAI,QAA4B,SAAS","ignoreList":[]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Configuration } from './
|
|
2
|
-
import type { Listener, MMKVInterface } from './Types';
|
|
1
|
+
import type { Configuration, Listener, MMKVInterface } from './Types';
|
|
3
2
|
/**
|
|
4
3
|
* A single MMKV instance.
|
|
5
4
|
*/
|
|
@@ -16,6 +15,7 @@ export declare class MMKV implements MMKVInterface {
|
|
|
16
15
|
private getFunctionFromCache;
|
|
17
16
|
private onValuesChanged;
|
|
18
17
|
get size(): number;
|
|
18
|
+
get isReadOnly(): boolean;
|
|
19
19
|
set(key: string, value: boolean | string | number | ArrayBuffer): void;
|
|
20
20
|
getBoolean(key: string): boolean | undefined;
|
|
21
21
|
getString(key: string): string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MMKV.d.ts","sourceRoot":"","sources":["../../../src/MMKV.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MMKV.d.ts","sourceRoot":"","sources":["../../../src/MMKV.ts"],"names":[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ot":"","sources":["../../../src/MemoryWarningListener.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CAwBlE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryWarningListener.web.d.ts","sourceRoot":"","sources":["../../../src/MemoryWarningListener.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,eAAO,MAAM,wBAAwB,UAAW,aAAa,KAAG,IAE/D,CAAC"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { TurboModule } from 'react-native';
|
|
2
2
|
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
/**
|
|
4
|
+
* IMPORTANT: These types are also in the Types.ts file.
|
|
5
|
+
* Due to how react-native-codegen works these are required here as the spec types can not be separated from spec.
|
|
6
|
+
* We also need the types separate to allow bypassing importing turbo module registry in web
|
|
7
|
+
*/
|
|
3
8
|
/**
|
|
4
9
|
* Configures the mode of the MMKV instance.
|
|
5
10
|
*/
|
|
@@ -65,6 +70,10 @@ export interface Configuration {
|
|
|
65
70
|
* @default SINGLE_PROCESS
|
|
66
71
|
*/
|
|
67
72
|
mode?: Mode;
|
|
73
|
+
/**
|
|
74
|
+
* If `true`, the MMKV instance can only read from the storage, but not write to it.
|
|
75
|
+
*/
|
|
76
|
+
readOnly?: boolean;
|
|
68
77
|
}
|
|
69
78
|
export interface Spec extends TurboModule {
|
|
70
79
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeMmkv.d.ts","sourceRoot":"","sources":["../../../src/NativeMmkv.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAI9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"version":3,"file":"NativeMmkvPlatformContext.d.ts","sourceRoot":"","sources":["../../../src/NativeMmkvPlatformContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAIhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC;;OAEG;IACH,gBAAgB,IAAI,MAAM,CAAC;IAC3B;;;;;;;;;OASG;IACH,oBAAoB,IAAI,MAAM,GAAG,SAAS,CAAC;CAC5C;AAID,wBAAgB,iCAAiC,IAAI,IAAI,
|
|
1
|
+
{"version":3,"file":"NativeMmkvPlatformContext.d.ts","sourceRoot":"","sources":["../../../src/NativeMmkvPlatformContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAIhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC;;OAEG;IACH,gBAAgB,IAAI,MAAM,CAAC;IAC3B;;;;;;;;;OASG;IACH,oBAAoB,IAAI,MAAM,GAAG,SAAS,CAAC;CAC5C;AAID,wBAAgB,iCAAiC,IAAI,IAAI,CAaxD"}
|
|
@@ -1,3 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IMPORTANT: Some of these types are also in the NativeMmkv.ts file.
|
|
3
|
+
* Due to how react-native-codegen works these are required here as the spec types can not be separated from spec.
|
|
4
|
+
* We also need the types separate to allow bypassing importing turbo module registry in web
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Configures the mode of the MMKV instance.
|
|
8
|
+
*/
|
|
9
|
+
export declare enum Mode {
|
|
10
|
+
/**
|
|
11
|
+
* The MMKV instance is only used from a single process (this app).
|
|
12
|
+
*/
|
|
13
|
+
SINGLE_PROCESS = 0,
|
|
14
|
+
/**
|
|
15
|
+
* The MMKV instance may be used from multiple processes, such as app clips, share extensions or background services.
|
|
16
|
+
*/
|
|
17
|
+
MULTI_PROCESS = 1
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Used for configuration of a single MMKV instance.
|
|
21
|
+
*/
|
|
22
|
+
export interface Configuration {
|
|
23
|
+
/**
|
|
24
|
+
* The MMKV instance's ID. If you want to use multiple instances, make sure to use different IDs!
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const userStorage = new MMKV({ id: `user-${userId}-storage` })
|
|
29
|
+
* const globalStorage = new MMKV({ id: 'global-app-storage' })
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @default 'mmkv.default'
|
|
33
|
+
*/
|
|
34
|
+
id: string;
|
|
35
|
+
/**
|
|
36
|
+
* The MMKV instance's root path. By default, MMKV stores file inside `$(Documents)/mmkv/`. You can customize MMKV's root directory on MMKV initialization:
|
|
37
|
+
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const temporaryStorage = new MMKV({ path: '/tmp/' })
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @note On iOS, if an `AppGroup` is set in `Info.plist` and `path` is `undefined`, MMKV will use the `AppGroup` directory.
|
|
44
|
+
* App Groups allow you to share MMKV storage between apps, widgets and extensions within the same AppGroup bundle.
|
|
45
|
+
* For more information, see [the `Configuration` section](https://github.com/Tencent/MMKV/wiki/iOS_tutorial#configuration).
|
|
46
|
+
*
|
|
47
|
+
* @default undefined
|
|
48
|
+
*/
|
|
49
|
+
path?: string;
|
|
50
|
+
/**
|
|
51
|
+
* 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.
|
|
52
|
+
*
|
|
53
|
+
* Encryption keys can have a maximum length of 16 bytes.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const secureStorage = new MMKV({ encryptionKey: 'my-encryption-key!' })
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @default undefined
|
|
61
|
+
*/
|
|
62
|
+
encryptionKey?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Configure the processing mode for MMKV.
|
|
65
|
+
* - `SINGLE_PROCESS`: The MMKV instance is only used from a single process (this app).
|
|
66
|
+
* - `MULTI_PROCESS`: The MMKV instance may be used from multiple processes, such as app clips, share extensions or background services.
|
|
67
|
+
*
|
|
68
|
+
* @default SINGLE_PROCESS
|
|
69
|
+
*/
|
|
70
|
+
mode?: Mode;
|
|
71
|
+
}
|
|
1
72
|
/**
|
|
2
73
|
* Represents a single MMKV instance.
|
|
3
74
|
*/
|
|
@@ -74,6 +145,11 @@ export interface NativeMMKV {
|
|
|
74
145
|
* Get the current total size of the storage, in bytes.
|
|
75
146
|
*/
|
|
76
147
|
readonly size: number;
|
|
148
|
+
/**
|
|
149
|
+
* Returns whether this instance is in read-only mode or not.
|
|
150
|
+
* If this is `true`, you can only use "get"-functions.
|
|
151
|
+
*/
|
|
152
|
+
readonly isReadOnly: boolean;
|
|
77
153
|
}
|
|
78
154
|
export interface Listener {
|
|
79
155
|
remove: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../../src/Types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,KAAK,IAAI,CAAC;IAC3E;;;;OAIG;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,GAAG,SAAS,CAAC;IACjD;;;;OAIG;IACH,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC/C;;;;OAIG;IACH,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC/C;;;;OAIG;IACH,SAAS,EAAE,CAAC,GAAG,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,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC/C;;;;OAIG;IACH,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC/C;;;;OAIG;IACH,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC;IACpD;;OAEG;IACH,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IACnC;;OAEG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B;;;;OAIG;IACH,UAAU,EAAE,MAAM,MAAM,EAAE,CAAC;IAC3B;;OAEG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB;;;;;;;;OAQG;IACH,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAC3C;;;;;;;;OAQG;IACH,IAAI,IAAI,IAAI,CAAC;IACb;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C;;;;;OAKG;IACH,yBAAyB,EAAE,CACzB,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,KAClC,QAAQ,CAAC;CACf"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type Configuration } from './
|
|
2
|
-
import type { NativeMMKV } from './Types';
|
|
1
|
+
import { type Configuration, type NativeMMKV } from './Types';
|
|
3
2
|
export declare const createMMKV: (config: Configuration) => NativeMMKV;
|
|
4
3
|
//# sourceMappingURL=createMMKV.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMMKV.d.ts","sourceRoot":"","sources":["../../../src/createMMKV.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createMMKV.d.ts","sourceRoot":"","sources":["../../../src/createMMKV.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAQ,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAGpE,eAAO,MAAM,UAAU,WAAY,aAAa,KAAG,UAoClD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMMKV.mock.d.ts","sourceRoot":"","sources":["../../../src/createMMKV.mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C,eAAO,MAAM,cAAc,QAAO,
|
|
1
|
+
{"version":3,"file":"createMMKV.mock.d.ts","sourceRoot":"","sources":["../../../src/createMMKV.mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C,eAAO,MAAM,cAAc,QAAO,UAkCjC,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Configuration } from './
|
|
2
|
-
import type { NativeMMKV } from './Types';
|
|
1
|
+
import type { Configuration, NativeMMKV } from './Types';
|
|
3
2
|
export declare const createMMKV: (config: Configuration) => NativeMMKV;
|
|
4
3
|
//# sourceMappingURL=createMMKV.web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMMKV.web.d.ts","sourceRoot":"","sources":["../../../src/createMMKV.web.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,
|
|
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,SAAS,CAAC;AAoBzD,eAAO,MAAM,UAAU,WAAY,aAAa,KAAG,UAyGlD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,IAAI,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-mmkv",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
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",
|
|
@@ -26,9 +26,7 @@
|
|
|
26
26
|
"src",
|
|
27
27
|
"react-native-mmkv.podspec",
|
|
28
28
|
"react-native.config.js",
|
|
29
|
-
"
|
|
30
|
-
"img/banner-light.png",
|
|
31
|
-
"img/banner-dark.png"
|
|
29
|
+
"README.md"
|
|
32
30
|
],
|
|
33
31
|
"scripts": {
|
|
34
32
|
"typescript": "tsc --noEmit",
|
|
@@ -74,23 +72,23 @@
|
|
|
74
72
|
"devDependencies": {
|
|
75
73
|
"@firmnav/eslint-github-actions-formatter": "^1.0.1",
|
|
76
74
|
"@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
|
|
77
|
-
"@react-native-community/cli-types": "^14.
|
|
78
|
-
"@react-native/eslint-config": "^0.75.
|
|
79
|
-
"@release-it/conventional-changelog": "^
|
|
80
|
-
"@testing-library/react-native": "^12.
|
|
81
|
-
"@types/jest": "^29.5.
|
|
82
|
-
"@types/react": "^18.3.
|
|
83
|
-
"del-cli": "^
|
|
75
|
+
"@react-native-community/cli-types": "^14.1.1",
|
|
76
|
+
"@react-native/eslint-config": "^0.75.4",
|
|
77
|
+
"@release-it/conventional-changelog": "^9.0.1",
|
|
78
|
+
"@testing-library/react-native": "^12.7.2",
|
|
79
|
+
"@types/jest": "^29.5.13",
|
|
80
|
+
"@types/react": "^18.3.11",
|
|
81
|
+
"del-cli": "^6.0.0",
|
|
84
82
|
"eslint": "^8.51.0",
|
|
85
83
|
"eslint-config-prettier": "^9.0.0",
|
|
86
84
|
"eslint-plugin-prettier": "^5.2.1",
|
|
87
85
|
"jest": "^29.7.0",
|
|
88
86
|
"prettier": "^3.3.3",
|
|
89
87
|
"react": "^18.3.1",
|
|
90
|
-
"react-native": "^0.75.
|
|
91
|
-
"react-native-builder-bob": "^0.30.
|
|
88
|
+
"react-native": "^0.75.4",
|
|
89
|
+
"react-native-builder-bob": "^0.30.2",
|
|
92
90
|
"react-test-renderer": "18.3.1",
|
|
93
|
-
"release-it": "^17.
|
|
91
|
+
"release-it": "^17.10.0",
|
|
94
92
|
"typescript": "^5.5.4"
|
|
95
93
|
},
|
|
96
94
|
"resolutions": {
|
|
@@ -14,7 +14,7 @@ Pod::Spec.new do |s|
|
|
|
14
14
|
s.license = package["license"]
|
|
15
15
|
s.authors = package["author"]
|
|
16
16
|
|
|
17
|
-
s.platforms = { :ios => min_ios_version_supported }
|
|
17
|
+
s.platforms = { :ios => min_ios_version_supported, :tvos => "12.0", :osx => "10.14" }
|
|
18
18
|
s.source = { :git => "https://github.com/mrousavy/react-native-mmkv.git", :tag => "#{s.version}" }
|
|
19
19
|
|
|
20
20
|
s.pod_target_xcconfig = {
|
package/src/MMKV.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { AppState } from 'react-native';
|
|
2
1
|
import { createMMKV } from './createMMKV';
|
|
3
2
|
import { createMockMMKV } from './createMMKV.mock';
|
|
4
3
|
import { isTest } from './PlatformChecker';
|
|
5
|
-
import type {
|
|
6
|
-
|
|
4
|
+
import type {
|
|
5
|
+
Configuration,
|
|
6
|
+
Listener,
|
|
7
|
+
MMKVInterface,
|
|
8
|
+
NativeMMKV,
|
|
9
|
+
} from './Types';
|
|
10
|
+
import { addMemoryWarningListener } from './MemoryWarningListener';
|
|
7
11
|
|
|
8
12
|
const onValueChangedListeners = new Map<string, ((key: string) => void)[]>();
|
|
9
13
|
|
|
@@ -26,10 +30,7 @@ export class MMKV implements MMKVInterface {
|
|
|
26
30
|
: createMMKV(configuration);
|
|
27
31
|
this.functionCache = {};
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
// when we have a memory warning, delete unused keys by trimming MMKV
|
|
31
|
-
this.trim();
|
|
32
|
-
});
|
|
33
|
+
addMemoryWarningListener(this);
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
private get onValueChangedListeners() {
|
|
@@ -61,6 +62,9 @@ export class MMKV implements MMKVInterface {
|
|
|
61
62
|
get size(): number {
|
|
62
63
|
return this.nativeInstance.size;
|
|
63
64
|
}
|
|
65
|
+
get isReadOnly(): boolean {
|
|
66
|
+
return this.nativeInstance.isReadOnly;
|
|
67
|
+
}
|
|
64
68
|
set(key: string, value: boolean | string | number | ArrayBuffer): void {
|
|
65
69
|
const func = this.getFunctionFromCache('set');
|
|
66
70
|
func(key, value);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AppState } from 'react-native';
|
|
2
|
+
import type { NativeEventSubscription } from 'react-native';
|
|
3
|
+
import { MMKVInterface } from './Types';
|
|
4
|
+
|
|
5
|
+
export function addMemoryWarningListener(mmkv: MMKVInterface): void {
|
|
6
|
+
if (global.WeakRef != null && global.FinalizationRegistry != null) {
|
|
7
|
+
// 1. Weakify MMKV so we can safely use it inside the memoryWarning event listener
|
|
8
|
+
const weakMmkv = new WeakRef(mmkv);
|
|
9
|
+
const listener = AppState.addEventListener('memoryWarning', () => {
|
|
10
|
+
// 0. Everytime we receive a memoryWarning, we try to trim the MMKV instance (if it is still valid)
|
|
11
|
+
weakMmkv.deref()?.trim();
|
|
12
|
+
});
|
|
13
|
+
// 2. Add a listener to when the MMKV instance is deleted
|
|
14
|
+
const finalization = new FinalizationRegistry(
|
|
15
|
+
(l: NativeEventSubscription) => {
|
|
16
|
+
// 3. When MMKV is deleted, this listener will be called with the memoryWarning listener.
|
|
17
|
+
l.remove();
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
// 2.1. Bind the listener to the actual MMKV instance.
|
|
21
|
+
finalization.register(mmkv, listener);
|
|
22
|
+
} else {
|
|
23
|
+
// WeakRef/FinalizationRegistry is not implemented in this engine.
|
|
24
|
+
// Just add the listener, even if it retains MMKV strong forever.
|
|
25
|
+
AppState.addEventListener('memoryWarning', () => {
|
|
26
|
+
mmkv.trim();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/NativeMmkv.ts
CHANGED
|
@@ -4,6 +4,11 @@ import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
|
4
4
|
import { ModuleNotFoundError } from './ModuleNotFoundError';
|
|
5
5
|
import { getMMKVPlatformContextTurboModule } from './NativeMmkvPlatformContext';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* IMPORTANT: These types are also in the Types.ts file.
|
|
9
|
+
* Due to how react-native-codegen works these are required here as the spec types can not be separated from spec.
|
|
10
|
+
* We also need the types separate to allow bypassing importing turbo module registry in web
|
|
11
|
+
*/
|
|
7
12
|
/**
|
|
8
13
|
* Configures the mode of the MMKV instance.
|
|
9
14
|
*/
|
|
@@ -70,6 +75,10 @@ export interface Configuration {
|
|
|
70
75
|
* @default SINGLE_PROCESS
|
|
71
76
|
*/
|
|
72
77
|
mode?: Mode;
|
|
78
|
+
/**
|
|
79
|
+
* If `true`, the MMKV instance can only read from the storage, but not write to it.
|
|
80
|
+
*/
|
|
81
|
+
readOnly?: boolean;
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
export interface Spec extends TurboModule {
|
|
@@ -85,23 +94,23 @@ export interface Spec extends TurboModule {
|
|
|
85
94
|
createMMKV(configuration: Configuration): UnsafeObject;
|
|
86
95
|
}
|
|
87
96
|
|
|
88
|
-
let
|
|
97
|
+
let mmkvModule: Spec | null;
|
|
89
98
|
|
|
90
99
|
export function getMMKVTurboModule(): Spec {
|
|
91
100
|
try {
|
|
92
|
-
if (
|
|
101
|
+
if (mmkvModule == null) {
|
|
93
102
|
// 1. Load MMKV TurboModule
|
|
94
|
-
|
|
103
|
+
mmkvModule = TurboModuleRegistry.getEnforcing<Spec>('MmkvCxx');
|
|
95
104
|
|
|
96
105
|
// 2. Get the PlatformContext TurboModule as well
|
|
97
106
|
const platformContext = getMMKVPlatformContextTurboModule();
|
|
98
107
|
|
|
99
108
|
// 3. Initialize it with the documents directory from platform-specific context
|
|
100
109
|
const basePath = platformContext.getBaseDirectory();
|
|
101
|
-
|
|
110
|
+
mmkvModule.initialize(basePath);
|
|
102
111
|
}
|
|
103
112
|
|
|
104
|
-
return
|
|
113
|
+
return mmkvModule;
|
|
105
114
|
} catch (cause) {
|
|
106
115
|
// TurboModule could not be found!
|
|
107
116
|
throw new ModuleNotFoundError(cause);
|
|
@@ -20,15 +20,17 @@ export interface Spec extends TurboModule {
|
|
|
20
20
|
getAppGroupDirectory(): string | undefined;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
let
|
|
23
|
+
let mmkvPlatformModule: Spec | null;
|
|
24
24
|
|
|
25
25
|
export function getMMKVPlatformContextTurboModule(): Spec {
|
|
26
26
|
try {
|
|
27
|
-
if (
|
|
27
|
+
if (mmkvPlatformModule == null) {
|
|
28
28
|
// 1. Get the TurboModule
|
|
29
|
-
|
|
29
|
+
mmkvPlatformModule = TurboModuleRegistry.getEnforcing<Spec>(
|
|
30
|
+
'MmkvPlatformContext'
|
|
31
|
+
);
|
|
30
32
|
}
|
|
31
|
-
return
|
|
33
|
+
return mmkvPlatformModule;
|
|
32
34
|
} catch (e) {
|
|
33
35
|
// TurboModule could not be found!
|
|
34
36
|
throw new ModuleNotFoundError(e);
|
package/src/Types.ts
CHANGED
|
@@ -1,3 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IMPORTANT: Some of these types are also in the NativeMmkv.ts file.
|
|
3
|
+
* Due to how react-native-codegen works these are required here as the spec types can not be separated from spec.
|
|
4
|
+
* We also need the types separate to allow bypassing importing turbo module registry in web
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configures the mode of the MMKV instance.
|
|
9
|
+
*/
|
|
10
|
+
export enum Mode {
|
|
11
|
+
/**
|
|
12
|
+
* The MMKV instance is only used from a single process (this app).
|
|
13
|
+
*/
|
|
14
|
+
SINGLE_PROCESS,
|
|
15
|
+
/**
|
|
16
|
+
* The MMKV instance may be used from multiple processes, such as app clips, share extensions or background services.
|
|
17
|
+
*/
|
|
18
|
+
MULTI_PROCESS,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Used for configuration of a single MMKV instance.
|
|
23
|
+
*/
|
|
24
|
+
export interface Configuration {
|
|
25
|
+
/**
|
|
26
|
+
* The MMKV instance's ID. If you want to use multiple instances, make sure to use different IDs!
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const userStorage = new MMKV({ id: `user-${userId}-storage` })
|
|
31
|
+
* const globalStorage = new MMKV({ id: 'global-app-storage' })
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @default 'mmkv.default'
|
|
35
|
+
*/
|
|
36
|
+
id: string;
|
|
37
|
+
/**
|
|
38
|
+
* The MMKV instance's root path. By default, MMKV stores file inside `$(Documents)/mmkv/`. You can customize MMKV's root directory on MMKV initialization:
|
|
39
|
+
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const temporaryStorage = new MMKV({ path: '/tmp/' })
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @note On iOS, if an `AppGroup` is set in `Info.plist` and `path` is `undefined`, MMKV will use the `AppGroup` directory.
|
|
46
|
+
* App Groups allow you to share MMKV storage between apps, widgets and extensions within the same AppGroup bundle.
|
|
47
|
+
* For more information, see [the `Configuration` section](https://github.com/Tencent/MMKV/wiki/iOS_tutorial#configuration).
|
|
48
|
+
*
|
|
49
|
+
* @default undefined
|
|
50
|
+
*/
|
|
51
|
+
path?: string;
|
|
52
|
+
/**
|
|
53
|
+
* 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.
|
|
54
|
+
*
|
|
55
|
+
* Encryption keys can have a maximum length of 16 bytes.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const secureStorage = new MMKV({ encryptionKey: 'my-encryption-key!' })
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @default undefined
|
|
63
|
+
*/
|
|
64
|
+
encryptionKey?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Configure the processing mode for MMKV.
|
|
67
|
+
* - `SINGLE_PROCESS`: The MMKV instance is only used from a single process (this app).
|
|
68
|
+
* - `MULTI_PROCESS`: The MMKV instance may be used from multiple processes, such as app clips, share extensions or background services.
|
|
69
|
+
*
|
|
70
|
+
* @default SINGLE_PROCESS
|
|
71
|
+
*/
|
|
72
|
+
mode?: Mode;
|
|
73
|
+
}
|
|
74
|
+
|
|
1
75
|
/**
|
|
2
76
|
* Represents a single MMKV instance.
|
|
3
77
|
*/
|
|
@@ -74,6 +148,11 @@ export interface NativeMMKV {
|
|
|
74
148
|
* Get the current total size of the storage, in bytes.
|
|
75
149
|
*/
|
|
76
150
|
readonly size: number;
|
|
151
|
+
/**
|
|
152
|
+
* Returns whether this instance is in read-only mode or not.
|
|
153
|
+
* If this is `true`, you can only use "get"-functions.
|
|
154
|
+
*/
|
|
155
|
+
readonly isReadOnly: boolean;
|
|
77
156
|
}
|
|
78
157
|
|
|
79
158
|
export interface Listener {
|
package/src/createMMKV.mock.ts
CHANGED
package/src/createMMKV.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
|
-
import { getMMKVTurboModule
|
|
3
|
-
import type
|
|
2
|
+
import { getMMKVTurboModule } from './NativeMmkv';
|
|
3
|
+
import { type Configuration, Mode, type NativeMMKV } from './Types';
|
|
4
4
|
import { getMMKVPlatformContextTurboModule } from './NativeMmkvPlatformContext';
|
|
5
5
|
|
|
6
6
|
export const createMMKV = (config: Configuration): NativeMMKV => {
|
|
@@ -23,6 +23,13 @@ export const createMMKV = (config: Configuration): NativeMMKV => {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
if (typeof config.mode === 'number') {
|
|
27
|
+
// Code-gen expects enums to be strings. In TS, they might be numbers tho.
|
|
28
|
+
// This sucks, so we need a workaround.
|
|
29
|
+
// @ts-expect-error the native side actually expects a string.
|
|
30
|
+
config.mode = Mode[config.mode];
|
|
31
|
+
}
|
|
32
|
+
|
|
26
33
|
const instance = module.createMMKV(config);
|
|
27
34
|
if (__DEV__) {
|
|
28
35
|
if (typeof instance !== 'object' || instance == null) {
|
package/src/createMMKV.web.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/* global localStorage */
|
|
2
|
-
import type { Configuration } from './
|
|
3
|
-
import type { NativeMMKV } from './Types';
|
|
2
|
+
import type { Configuration, NativeMMKV } from './Types';
|
|
4
3
|
import { createTextEncoder } from './createTextEncoder';
|
|
5
4
|
|
|
6
5
|
const canUseDOM =
|
|
@@ -120,6 +119,7 @@ export const createMMKV = (config: Configuration): NativeMMKV => {
|
|
|
120
119
|
throw new Error('`recrypt(..)` is not supported on Web!');
|
|
121
120
|
},
|
|
122
121
|
size: 0,
|
|
122
|
+
isReadOnly: false,
|
|
123
123
|
trim: () => {
|
|
124
124
|
// no-op
|
|
125
125
|
},
|