react-native-mmkv 4.0.0-beta.1 → 4.0.0-beta.11
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/NitroMmkv.podspec +44 -0
- package/README.md +1 -3
- package/android/CMakeLists.txt +31 -30
- package/android/build.gradle +66 -21
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -5
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/mmkv/HybridMMKVPlatformContext.kt +19 -0
- package/android/src/main/java/com/margelo/nitro/mmkv/NitroMmkvPackage.java +33 -0
- package/cpp/HybridMMKV.cpp +184 -0
- package/cpp/HybridMMKV.hpp +47 -0
- package/cpp/HybridMMKVFactory.cpp +33 -0
- package/cpp/HybridMMKVFactory.hpp +24 -0
- package/cpp/{MmkvTypes.h → MMKVTypes.hpp} +1 -1
- package/cpp/MMKVValueChangedListenerRegistry.cpp +58 -0
- package/cpp/MMKVValueChangedListenerRegistry.hpp +43 -0
- package/cpp/{ManagedMMBuffer.h → ManagedMMBuffer.hpp} +13 -5
- package/ios/HybridMMKVPlatformContext.swift +43 -0
- package/lib/__tests__/hooks.test.d.ts +1 -0
- package/lib/__tests__/hooks.test.js +69 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.d.ts +2 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.js +25 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.d.ts +2 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.js +3 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.web.d.ts +2 -0
- package/lib/addMemoryWarningListener/addMemoryWarningListener.web.js +3 -0
- package/lib/createMMKV/createMMKV.d.ts +3 -0
- package/lib/createMMKV/createMMKV.js +40 -0
- package/lib/createMMKV/createMMKV.web.d.ts +3 -0
- package/lib/createMMKV/createMMKV.web.js +117 -0
- package/lib/createMMKV/createMockMMKV.d.ts +5 -0
- package/lib/createMMKV/createMockMMKV.js +74 -0
- package/lib/createMMKV/getDefaultMMKVInstance.d.ts +2 -0
- package/lib/createMMKV/getDefaultMMKVInstance.js +8 -0
- package/lib/hooks/createMMKVHook.d.ts +2 -0
- package/lib/hooks/createMMKVHook.js +49 -0
- package/lib/hooks/useMMKV.d.ts +11 -0
- package/lib/hooks/useMMKV.js +23 -0
- package/lib/hooks/useMMKVBoolean.d.ts +11 -0
- package/lib/hooks/useMMKVBoolean.js +12 -0
- package/lib/hooks/useMMKVBuffer.d.ts +11 -0
- package/lib/hooks/useMMKVBuffer.js +12 -0
- package/lib/hooks/useMMKVKeys.d.ts +12 -0
- package/lib/hooks/useMMKVKeys.js +33 -0
- package/lib/hooks/useMMKVListener.d.ts +15 -0
- package/lib/hooks/useMMKVListener.js +26 -0
- package/lib/hooks/useMMKVNumber.d.ts +11 -0
- package/lib/hooks/useMMKVNumber.js +12 -0
- package/lib/hooks/useMMKVObject.d.ts +17 -0
- package/lib/hooks/useMMKVObject.js +38 -0
- package/lib/hooks/useMMKVString.d.ts +11 -0
- package/lib/hooks/useMMKVString.js +12 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/lib/isTest.d.ts +1 -0
- package/lib/isTest.js +7 -0
- package/lib/specs/MMKV.nitro.d.ts +94 -0
- package/lib/specs/MMKV.nitro.js +1 -0
- package/lib/{typescript/src/NativeMmkv.d.ts → specs/MMKVFactory.nitro.d.ts} +26 -33
- package/lib/specs/MMKVFactory.nitro.js +1 -0
- package/lib/specs/MMKVPlatformContext.nitro.d.ts +18 -0
- package/lib/specs/MMKVPlatformContext.nitro.js +1 -0
- package/lib/{typescript/src → web}/createTextEncoder.d.ts +0 -1
- package/lib/web/createTextEncoder.js +17 -0
- package/nitro.json +28 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroMmkv+autolinking.cmake +80 -0
- package/nitrogen/generated/android/NitroMmkv+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroMmkvOnLoad.cpp +54 -0
- package/nitrogen/generated/android/NitroMmkvOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.cpp +52 -0
- package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.hpp +65 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/HybridMMKVPlatformContextSpec.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/NitroMmkvOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroMmkv+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.cpp +32 -0
- package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.hpp +77 -0
- package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Umbrella.hpp +45 -0
- package/nitrogen/generated/ios/NitroMmkvAutolinking.mm +43 -0
- package/nitrogen/generated/ios/NitroMmkvAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.hpp +82 -0
- package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec.swift +50 -0
- package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec_cxx.swift +141 -0
- package/nitrogen/generated/shared/c++/Configuration.hpp +86 -0
- package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.hpp +69 -0
- package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.hpp +64 -0
- package/nitrogen/generated/shared/c++/HybridMMKVSpec.cpp +34 -0
- package/nitrogen/generated/shared/c++/HybridMMKVSpec.hpp +83 -0
- package/nitrogen/generated/shared/c++/Listener.hpp +67 -0
- package/nitrogen/generated/shared/c++/Mode.hpp +76 -0
- package/package.json +74 -122
- package/react-native.config.js +2 -15
- package/src/__tests__/hooks.test.tsx +39 -34
- package/src/addMemoryWarningListener/addMemoryWarningListener.mock.ts +5 -0
- package/src/{MemoryWarningListener.ts → addMemoryWarningListener/addMemoryWarningListener.ts} +12 -12
- package/src/addMemoryWarningListener/addMemoryWarningListener.web.ts +5 -0
- package/src/createMMKV/createMMKV.ts +51 -0
- package/src/{createMMKV.web.ts → createMMKV/createMMKV.web.ts} +58 -46
- package/src/createMMKV/createMockMMKV.ts +78 -0
- package/src/createMMKV/getDefaultMMKVInstance.ts +10 -0
- package/src/hooks/createMMKVHook.ts +66 -0
- package/src/hooks/useMMKV.ts +45 -0
- package/src/hooks/useMMKVBoolean.ts +15 -0
- package/src/hooks/useMMKVBuffer.ts +15 -0
- package/src/hooks/useMMKVKeys.ts +36 -0
- package/src/hooks/useMMKVListener.ts +33 -0
- package/src/hooks/useMMKVNumber.ts +15 -0
- package/src/hooks/useMMKVObject.ts +53 -0
- package/src/hooks/useMMKVString.ts +15 -0
- package/src/index.ts +15 -3
- package/src/{PlatformChecker.ts → isTest.ts} +2 -2
- package/src/specs/MMKV.nitro.ts +93 -0
- package/src/specs/MMKVFactory.nitro.ts +87 -0
- package/src/specs/MMKVPlatformContext.nitro.ts +17 -0
- package/src/{createTextEncoder.ts → web/createTextEncoder.ts} +7 -7
- package/android/src/main/cpp/AndroidLogger.cpp +0 -16
- package/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java +0 -44
- package/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java +0 -26
- package/cpp/MmkvHostObject.cpp +0 -360
- package/cpp/MmkvHostObject.h +0 -31
- package/cpp/MmkvLogger.h +0 -35
- package/cpp/NativeMmkvModule.cpp +0 -43
- package/cpp/NativeMmkvModule.h +0 -31
- package/ios/AppleLogger.mm +0 -16
- package/ios/MmkvOnLoad.mm +0 -25
- package/ios/MmkvPlatformContext.h +0 -19
- package/ios/MmkvPlatformContextModule.mm +0 -55
- package/lib/commonjs/MMKV.js +0 -124
- package/lib/commonjs/MMKV.js.map +0 -1
- package/lib/commonjs/MemoryWarningListener.js +0 -31
- package/lib/commonjs/MemoryWarningListener.js.map +0 -1
- package/lib/commonjs/MemoryWarningListener.web.js +0 -11
- package/lib/commonjs/MemoryWarningListener.web.js.map +0 -1
- package/lib/commonjs/ModuleNotFoundError.js +0 -75
- package/lib/commonjs/ModuleNotFoundError.js.map +0 -1
- package/lib/commonjs/NativeMmkv.js +0 -47
- package/lib/commonjs/NativeMmkv.js.map +0 -1
- package/lib/commonjs/NativeMmkvPlatformContext.js +0 -22
- package/lib/commonjs/NativeMmkvPlatformContext.js.map +0 -1
- package/lib/commonjs/PlatformChecker.js +0 -14
- package/lib/commonjs/PlatformChecker.js.map +0 -1
- package/lib/commonjs/Types.js +0 -26
- package/lib/commonjs/Types.js.map +0 -1
- package/lib/commonjs/createMMKV.js +0 -43
- package/lib/commonjs/createMMKV.js.map +0 -1
- package/lib/commonjs/createMMKV.mock.js +0 -43
- package/lib/commonjs/createMMKV.mock.js.map +0 -1
- package/lib/commonjs/createMMKV.web.js +0 -110
- package/lib/commonjs/createMMKV.web.js.map +0 -1
- package/lib/commonjs/createTextEncoder.js +0 -23
- package/lib/commonjs/createTextEncoder.js.map +0 -1
- package/lib/commonjs/hooks.js +0 -198
- package/lib/commonjs/hooks.js.map +0 -1
- package/lib/commonjs/index.js +0 -40
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/package.json +0 -1
- package/lib/module/MMKV.js +0 -119
- package/lib/module/MMKV.js.map +0 -1
- package/lib/module/MemoryWarningListener.js +0 -27
- package/lib/module/MemoryWarningListener.js.map +0 -1
- package/lib/module/MemoryWarningListener.web.js +0 -6
- package/lib/module/MemoryWarningListener.web.js.map +0 -1
- package/lib/module/ModuleNotFoundError.js +0 -70
- package/lib/module/ModuleNotFoundError.js.map +0 -1
- package/lib/module/NativeMmkv.js +0 -45
- package/lib/module/NativeMmkv.js.map +0 -1
- package/lib/module/NativeMmkvPlatformContext.js +0 -18
- package/lib/module/NativeMmkvPlatformContext.js.map +0 -1
- package/lib/module/PlatformChecker.js +0 -10
- package/lib/module/PlatformChecker.js.map +0 -1
- package/lib/module/Types.js +0 -25
- package/lib/module/Types.js.map +0 -1
- package/lib/module/createMMKV.js +0 -38
- package/lib/module/createMMKV.js.map +0 -1
- package/lib/module/createMMKV.mock.js +0 -38
- package/lib/module/createMMKV.mock.js.map +0 -1
- package/lib/module/createMMKV.web.js +0 -105
- package/lib/module/createMMKV.web.js.map +0 -1
- package/lib/module/createTextEncoder.js +0 -19
- package/lib/module/createTextEncoder.js.map +0 -1
- package/lib/module/hooks.js +0 -189
- package/lib/module/hooks.js.map +0 -1
- package/lib/module/index.js +0 -6
- package/lib/module/index.js.map +0 -1
- package/lib/module/package.json +0 -1
- package/lib/typescript/src/MMKV.d.ts +0 -34
- package/lib/typescript/src/MMKV.d.ts.map +0 -1
- package/lib/typescript/src/MemoryWarningListener.d.ts +0 -3
- package/lib/typescript/src/MemoryWarningListener.d.ts.map +0 -1
- package/lib/typescript/src/MemoryWarningListener.web.d.ts +0 -3
- package/lib/typescript/src/MemoryWarningListener.web.d.ts.map +0 -1
- package/lib/typescript/src/ModuleNotFoundError.d.ts +0 -7
- package/lib/typescript/src/ModuleNotFoundError.d.ts.map +0 -1
- package/lib/typescript/src/NativeMmkv.d.ts.map +0 -1
- package/lib/typescript/src/NativeMmkvPlatformContext.d.ts +0 -20
- package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +0 -1
- package/lib/typescript/src/PlatformChecker.d.ts +0 -2
- package/lib/typescript/src/PlatformChecker.d.ts.map +0 -1
- package/lib/typescript/src/Types.d.ts +0 -172
- package/lib/typescript/src/Types.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/hooks.test.d.ts +0 -2
- package/lib/typescript/src/__tests__/hooks.test.d.ts.map +0 -1
- package/lib/typescript/src/createMMKV.d.ts +0 -3
- package/lib/typescript/src/createMMKV.d.ts.map +0 -1
- package/lib/typescript/src/createMMKV.mock.d.ts +0 -3
- package/lib/typescript/src/createMMKV.mock.d.ts.map +0 -1
- package/lib/typescript/src/createMMKV.web.d.ts +0 -3
- package/lib/typescript/src/createMMKV.web.d.ts.map +0 -1
- package/lib/typescript/src/createTextEncoder.d.ts.map +0 -1
- package/lib/typescript/src/hooks.d.ts +0 -86
- package/lib/typescript/src/hooks.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -4
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/react-native-mmkv.podspec +0 -32
- package/src/MMKV.ts +0 -142
- package/src/MemoryWarningListener.web.ts +0 -5
- package/src/ModuleNotFoundError.ts +0 -95
- package/src/NativeMmkv.ts +0 -118
- package/src/NativeMmkvPlatformContext.ts +0 -38
- package/src/Types.ts +0 -178
- package/src/createMMKV.mock.ts +0 -38
- package/src/createMMKV.ts +0 -42
- package/src/hooks.ts +0 -247
package/lib/module/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Mode"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,cAAc,QAAQ;AACtB,cAAc,SAAS;AAEvB,SAASA,IAAI,QAA4B,SAAS","ignoreList":[]}
|
package/lib/module/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Configuration, Listener, MMKVInterface } from './Types';
|
|
2
|
-
/**
|
|
3
|
-
* A single MMKV instance.
|
|
4
|
-
*/
|
|
5
|
-
export declare class MMKV implements MMKVInterface {
|
|
6
|
-
private nativeInstance;
|
|
7
|
-
private functionCache;
|
|
8
|
-
private id;
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new MMKV instance with the given Configuration.
|
|
11
|
-
* If no custom `id` is supplied, `'mmkv.default'` will be used.
|
|
12
|
-
*/
|
|
13
|
-
constructor(configuration?: Configuration);
|
|
14
|
-
private get onValueChangedListeners();
|
|
15
|
-
private getFunctionFromCache;
|
|
16
|
-
private onValuesChanged;
|
|
17
|
-
get size(): number;
|
|
18
|
-
get isReadOnly(): boolean;
|
|
19
|
-
set(key: string, value: boolean | string | number | ArrayBuffer): void;
|
|
20
|
-
getBoolean(key: string): boolean | undefined;
|
|
21
|
-
getString(key: string): string | undefined;
|
|
22
|
-
getNumber(key: string): number | undefined;
|
|
23
|
-
getBuffer(key: string): ArrayBufferLike | undefined;
|
|
24
|
-
contains(key: string): boolean;
|
|
25
|
-
delete(key: string): void;
|
|
26
|
-
getAllKeys(): string[];
|
|
27
|
-
clearAll(): void;
|
|
28
|
-
recrypt(key: string | undefined): void;
|
|
29
|
-
trim(): void;
|
|
30
|
-
toString(): string;
|
|
31
|
-
toJSON(): object;
|
|
32
|
-
addOnValueChangedListener(onValueChanged: (key: string) => void): Listener;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=MMKV.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MMKV.d.ts","sourceRoot":"","sources":["../../../src/MMKV.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EACR,aAAa,EAEd,MAAM,SAAS,CAAC;AAKjB;;GAEG;AACH,qBAAa,IAAK,YAAW,aAAa;IACxC,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,EAAE,CAAS;IAEnB;;;OAGG;gBACS,aAAa,GAAE,aAAsC;IAUjE,OAAO,KAAK,uBAAuB,GAKlC;IAED,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,eAAe;IAUvB,IAAI,IAAI,IAAI,MAAM,CAEjB;IACD,IAAI,UAAU,IAAI,OAAO,CAExB;IACD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,GAAG,IAAI;IAMtE,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAI5C,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI1C,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI1C,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAInD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI9B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAMzB,UAAU,IAAI,MAAM,EAAE;IAItB,QAAQ,IAAI,IAAI;IAQhB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAItC,IAAI,IAAI,IAAI;IAKZ,QAAQ,IAAI,MAAM;IAGlB,MAAM,IAAI,MAAM;IAMhB,yBAAyB,CAAC,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,QAAQ;CAY3E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryWarningListener.d.ts","sourceRoot":"","sources":["../../../src/MemoryWarningListener.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CAwBlE"}
|
|
@@ -1 +0,0 @@
|
|
|
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,GAAI,OAAO,aAAa,KAAG,IAE/D,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ModuleNotFoundError.d.ts","sourceRoot":"","sources":["../../../src/ModuleNotFoundError.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,kBAAkB,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7C;AA2BD,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,KAAK,CAAC,EAAE,OAAO;CA6D5B"}
|
|
@@ -1 +0,0 @@
|
|
|
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;AAI9E;;;;GAIG;AACH;;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;IACZ;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC;;;OAGG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IACtC;;;OAGG;IACH,UAAU,CAAC,aAAa,EAAE,aAAa,GAAG,YAAY,CAAC;CACxD;AAID,wBAAgB,kBAAkB,IAAI,IAAI,CAmBzC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { 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
|
-
* Get the App Group directory if it exists, or `undefined` otherwise.
|
|
9
|
-
*
|
|
10
|
-
* The App Group directory will be used instead of a custom path to use the same
|
|
11
|
-
* MMKV instance between the iOS app, Widgets, and other companion apps.
|
|
12
|
-
*
|
|
13
|
-
* To set an App Group, add a `AppGroup` field to `Info.plist`
|
|
14
|
-
*
|
|
15
|
-
* @platform ios
|
|
16
|
-
*/
|
|
17
|
-
getAppGroupDirectory(): string | undefined;
|
|
18
|
-
}
|
|
19
|
-
export declare function getMMKVPlatformContextTurboModule(): Spec;
|
|
20
|
-
//# sourceMappingURL=NativeMmkvPlatformContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformChecker.d.ts","sourceRoot":"","sources":["../../../src/PlatformChecker.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,IAAI,OAAO,CAQhC"}
|
|
@@ -1,172 +0,0 @@
|
|
|
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
|
-
/**
|
|
72
|
-
* If `true`, the MMKV instance can only read from the storage, but not write to it.
|
|
73
|
-
* This is more efficient if you do not need to write to it.
|
|
74
|
-
* @default false
|
|
75
|
-
*/
|
|
76
|
-
readOnly?: boolean;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Represents a single MMKV instance.
|
|
80
|
-
*/
|
|
81
|
-
export interface NativeMMKV {
|
|
82
|
-
/**
|
|
83
|
-
* Set a value for the given `key`.
|
|
84
|
-
*
|
|
85
|
-
* @throws an Error if the value cannot be set.
|
|
86
|
-
*/
|
|
87
|
-
set: (key: string, value: boolean | string | number | ArrayBuffer) => void;
|
|
88
|
-
/**
|
|
89
|
-
* Get the boolean value for the given `key`, or `undefined` if it does not exist.
|
|
90
|
-
*
|
|
91
|
-
* @default undefined
|
|
92
|
-
*/
|
|
93
|
-
getBoolean: (key: string) => boolean | undefined;
|
|
94
|
-
/**
|
|
95
|
-
* Get the string value for the given `key`, or `undefined` if it does not exist.
|
|
96
|
-
*
|
|
97
|
-
* @default undefined
|
|
98
|
-
*/
|
|
99
|
-
getString: (key: string) => string | undefined;
|
|
100
|
-
/**
|
|
101
|
-
* Get the number value for the given `key`, or `undefined` if it does not exist.
|
|
102
|
-
*
|
|
103
|
-
* @default undefined
|
|
104
|
-
*/
|
|
105
|
-
getNumber: (key: string) => number | undefined;
|
|
106
|
-
/**
|
|
107
|
-
* Get a raw buffer of unsigned 8-bit (0-255) data.
|
|
108
|
-
*
|
|
109
|
-
* @default undefined
|
|
110
|
-
*/
|
|
111
|
-
getBuffer: (key: string) => ArrayBufferLike | undefined;
|
|
112
|
-
/**
|
|
113
|
-
* Checks whether the given `key` is being stored in this MMKV instance.
|
|
114
|
-
*/
|
|
115
|
-
contains: (key: string) => boolean;
|
|
116
|
-
/**
|
|
117
|
-
* Delete the given `key`.
|
|
118
|
-
*/
|
|
119
|
-
delete: (key: string) => void;
|
|
120
|
-
/**
|
|
121
|
-
* Get all keys.
|
|
122
|
-
*
|
|
123
|
-
* @default []
|
|
124
|
-
*/
|
|
125
|
-
getAllKeys: () => string[];
|
|
126
|
-
/**
|
|
127
|
-
* Delete all keys.
|
|
128
|
-
*/
|
|
129
|
-
clearAll: () => void;
|
|
130
|
-
/**
|
|
131
|
-
* Sets (or updates) the encryption-key to encrypt all data in this MMKV instance with.
|
|
132
|
-
*
|
|
133
|
-
* To remove encryption, pass `undefined` as a key.
|
|
134
|
-
*
|
|
135
|
-
* Encryption keys can have a maximum length of 16 bytes.
|
|
136
|
-
*
|
|
137
|
-
* @throws an Error if the instance cannot be recrypted.
|
|
138
|
-
*/
|
|
139
|
-
recrypt: (key: string | undefined) => void;
|
|
140
|
-
/**
|
|
141
|
-
* Trims the storage space and clears memory cache.
|
|
142
|
-
*
|
|
143
|
-
* Since MMKV does not resize itself after deleting keys, you can call `trim()`
|
|
144
|
-
* after deleting a bunch of keys to manually trim the memory- and
|
|
145
|
-
* disk-file to reduce storage and memory usage.
|
|
146
|
-
*
|
|
147
|
-
* In most applications, this is not needed at all.
|
|
148
|
-
*/
|
|
149
|
-
trim(): void;
|
|
150
|
-
/**
|
|
151
|
-
* Get the current total size of the storage, in bytes.
|
|
152
|
-
*/
|
|
153
|
-
readonly size: number;
|
|
154
|
-
/**
|
|
155
|
-
* Returns whether this instance is in read-only mode or not.
|
|
156
|
-
* If this is `true`, you can only use "get"-functions.
|
|
157
|
-
*/
|
|
158
|
-
readonly isReadOnly: boolean;
|
|
159
|
-
}
|
|
160
|
-
export interface Listener {
|
|
161
|
-
remove: () => void;
|
|
162
|
-
}
|
|
163
|
-
export interface MMKVInterface extends NativeMMKV {
|
|
164
|
-
/**
|
|
165
|
-
* Adds a value changed listener. The Listener will be called whenever any value
|
|
166
|
-
* in this storage instance changes (set or delete).
|
|
167
|
-
*
|
|
168
|
-
* To unsubscribe from value changes, call `remove()` on the Listener.
|
|
169
|
-
*/
|
|
170
|
-
addOnValueChangedListener: (onValueChanged: (key: string) => void) => Listener;
|
|
171
|
-
}
|
|
172
|
-
//# sourceMappingURL=Types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../../src/Types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;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;IACZ;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;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,EAAE,MAAM,KAAK,eAAe,GAAG,SAAS,CAAC;IACxD;;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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.test.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/hooks.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
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,GAAI,QAAQ,aAAa,KAAG,UAoClD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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,GAAI,QAAQ,aAAa,KAAG,UAyGlD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createTextEncoder.d.ts","sourceRoot":"","sources":["../../../src/createTextEncoder.ts"],"names":[],"mappings":"AACA,wBAAgB,iBAAiB,IAAI,WAAW,CAc/C"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { MMKV } from './MMKV';
|
|
2
|
-
import type { Configuration } from './Types';
|
|
3
|
-
/**
|
|
4
|
-
* Use the default, shared MMKV instance.
|
|
5
|
-
*/
|
|
6
|
-
export declare function useMMKV(): MMKV;
|
|
7
|
-
/**
|
|
8
|
-
* Use a custom MMKV instance with the given configuration.
|
|
9
|
-
* @param configuration The configuration to initialize the MMKV instance with. Does not have to be memoized.
|
|
10
|
-
*/
|
|
11
|
-
export declare function useMMKV(configuration: Configuration): MMKV;
|
|
12
|
-
/**
|
|
13
|
-
* Use the string value of the given `key` from the given MMKV storage instance.
|
|
14
|
-
*
|
|
15
|
-
* If no instance is provided, a shared default instance will be used.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const [username, setUsername] = useMMKVString("user.name")
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare const useMMKVString: (key: string, instance?: MMKV) => [value: string | undefined, setValue: (value: string | ((current: string | undefined) => string | undefined) | undefined) => void];
|
|
23
|
-
/**
|
|
24
|
-
* Use the number value of the given `key` from the given MMKV storage instance.
|
|
25
|
-
*
|
|
26
|
-
* If no instance is provided, a shared default instance will be used.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* const [age, setAge] = useMMKVNumber("user.age")
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare const useMMKVNumber: (key: string, instance?: MMKV) => [value: number | undefined, setValue: (value: number | ((current: number | undefined) => number | undefined) | undefined) => void];
|
|
34
|
-
/**
|
|
35
|
-
* Use the boolean value of the given `key` from the given MMKV storage instance.
|
|
36
|
-
*
|
|
37
|
-
* If no instance is provided, a shared default instance will be used.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* const [isPremiumAccount, setIsPremiumAccount] = useMMKVBoolean("user.isPremium")
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare const useMMKVBoolean: (key: string, instance?: MMKV) => [value: boolean | undefined, setValue: (value: boolean | ((current: boolean | undefined) => boolean | undefined) | undefined) => void];
|
|
45
|
-
/**
|
|
46
|
-
* Use the buffer value (unsigned 8-bit (0-255)) of the given `key` from the given MMKV storage instance.
|
|
47
|
-
*
|
|
48
|
-
* If no instance is provided, a shared default instance will be used.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* const [privateKey, setPrivateKey] = useMMKVBuffer("user.privateKey")
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export declare const useMMKVBuffer: (key: string, instance?: MMKV) => [value: ArrayBufferLike | undefined, setValue: (value: ArrayBufferLike | ((current: ArrayBufferLike | undefined) => ArrayBufferLike | undefined) | undefined) => void];
|
|
56
|
-
/**
|
|
57
|
-
* Use an object value of the given `key` from the given MMKV storage instance.
|
|
58
|
-
*
|
|
59
|
-
* If no instance is provided, a shared default instance will be used.
|
|
60
|
-
*
|
|
61
|
-
* The object will be serialized using `JSON`.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```ts
|
|
65
|
-
* const [user, setUser] = useMMKVObject<User>("user")
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
export declare function useMMKVObject<T>(key: string, instance?: MMKV): [
|
|
69
|
-
value: T | undefined,
|
|
70
|
-
setValue: (value: T | undefined | ((prevValue: T | undefined) => T | undefined)) => void
|
|
71
|
-
];
|
|
72
|
-
/**
|
|
73
|
-
* Listen for changes in the given MMKV storage instance.
|
|
74
|
-
* If no instance is passed, the default instance will be used.
|
|
75
|
-
* @param valueChangedListener The function to call whenever a value inside the storage instance changes
|
|
76
|
-
* @param instance The instance to listen to changes to (or the default instance)
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```ts
|
|
80
|
-
* useMMKVListener((key) => {
|
|
81
|
-
* console.log(`Value for "${key}" changed!`)
|
|
82
|
-
* })
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export declare function useMMKVListener(valueChangedListener: (key: string) => void, instance?: MMKV): void;
|
|
86
|
-
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,sKAC8B,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 +0,0 @@
|
|
|
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"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
require "json"
|
|
2
|
-
|
|
3
|
-
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
-
|
|
5
|
-
Pod::UI.puts "[react-native-mmkv] Thank you for using react-native-mmkv ❤️"
|
|
6
|
-
Pod::UI.puts "[react-native-mmkv] If you enjoy using react-native-mmkv, please consider sponsoring this project: https://github.com/sponsors/mrousavy"
|
|
7
|
-
|
|
8
|
-
Pod::Spec.new do |s|
|
|
9
|
-
s.name = "react-native-mmkv"
|
|
10
|
-
s.version = package["version"]
|
|
11
|
-
s.summary = package["description"]
|
|
12
|
-
s.homepage = package["homepage"]
|
|
13
|
-
s.license = package["license"]
|
|
14
|
-
s.authors = package["author"]
|
|
15
|
-
|
|
16
|
-
s.platforms = { :ios => min_ios_version_supported, :tvos => "12.0", :osx => "10.14" }
|
|
17
|
-
s.source = { :git => "https://github.com/mrousavy/react-native-mmkv.git", :tag => "#{s.version}" }
|
|
18
|
-
|
|
19
|
-
s.pod_target_xcconfig = {
|
|
20
|
-
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
21
|
-
}
|
|
22
|
-
s.compiler_flags = '-x objective-c++'
|
|
23
|
-
s.libraries = "z", "c++"
|
|
24
|
-
s.source_files = [
|
|
25
|
-
# react-native-mmkv
|
|
26
|
-
"ios/**/*.{h,m,mm}",
|
|
27
|
-
"cpp/**/*.{hpp,cpp,c,h}"
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
s.dependency 'MMKVCore', '>= 2.2.3'
|
|
31
|
-
install_modules_dependencies(s)
|
|
32
|
-
end
|
package/src/MMKV.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { createMMKV } from './createMMKV';
|
|
2
|
-
import { createMockMMKV } from './createMMKV.mock';
|
|
3
|
-
import { isTest } from './PlatformChecker';
|
|
4
|
-
import type {
|
|
5
|
-
Configuration,
|
|
6
|
-
Listener,
|
|
7
|
-
MMKVInterface,
|
|
8
|
-
NativeMMKV,
|
|
9
|
-
} from './Types';
|
|
10
|
-
import { addMemoryWarningListener } from './MemoryWarningListener';
|
|
11
|
-
|
|
12
|
-
const onValueChangedListeners = new Map<string, ((key: string) => void)[]>();
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A single MMKV instance.
|
|
16
|
-
*/
|
|
17
|
-
export class MMKV implements MMKVInterface {
|
|
18
|
-
private nativeInstance: NativeMMKV;
|
|
19
|
-
private functionCache: Partial<NativeMMKV>;
|
|
20
|
-
private id: string;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new MMKV instance with the given Configuration.
|
|
24
|
-
* If no custom `id` is supplied, `'mmkv.default'` will be used.
|
|
25
|
-
*/
|
|
26
|
-
constructor(configuration: Configuration = { id: 'mmkv.default' }) {
|
|
27
|
-
this.id = configuration.id;
|
|
28
|
-
this.nativeInstance = isTest()
|
|
29
|
-
? createMockMMKV()
|
|
30
|
-
: createMMKV(configuration);
|
|
31
|
-
this.functionCache = {};
|
|
32
|
-
|
|
33
|
-
addMemoryWarningListener(this);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private get onValueChangedListeners() {
|
|
37
|
-
if (!onValueChangedListeners.has(this.id)) {
|
|
38
|
-
onValueChangedListeners.set(this.id, []);
|
|
39
|
-
}
|
|
40
|
-
return onValueChangedListeners.get(this.id)!;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private getFunctionFromCache<T extends keyof NativeMMKV>(
|
|
44
|
-
functionName: T
|
|
45
|
-
): NativeMMKV[T] {
|
|
46
|
-
if (this.functionCache[functionName] == null) {
|
|
47
|
-
this.functionCache[functionName] = this.nativeInstance[functionName];
|
|
48
|
-
}
|
|
49
|
-
return this.functionCache[functionName] as NativeMMKV[T];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private onValuesChanged(keys: string[]) {
|
|
53
|
-
if (this.onValueChangedListeners.length === 0) return;
|
|
54
|
-
|
|
55
|
-
for (const key of keys) {
|
|
56
|
-
for (const listener of this.onValueChangedListeners) {
|
|
57
|
-
listener(key);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get size(): number {
|
|
63
|
-
return this.nativeInstance.size;
|
|
64
|
-
}
|
|
65
|
-
get isReadOnly(): boolean {
|
|
66
|
-
return this.nativeInstance.isReadOnly;
|
|
67
|
-
}
|
|
68
|
-
set(key: string, value: boolean | string | number | ArrayBuffer): void {
|
|
69
|
-
const func = this.getFunctionFromCache('set');
|
|
70
|
-
func(key, value);
|
|
71
|
-
|
|
72
|
-
this.onValuesChanged([key]);
|
|
73
|
-
}
|
|
74
|
-
getBoolean(key: string): boolean | undefined {
|
|
75
|
-
const func = this.getFunctionFromCache('getBoolean');
|
|
76
|
-
return func(key);
|
|
77
|
-
}
|
|
78
|
-
getString(key: string): string | undefined {
|
|
79
|
-
const func = this.getFunctionFromCache('getString');
|
|
80
|
-
return func(key);
|
|
81
|
-
}
|
|
82
|
-
getNumber(key: string): number | undefined {
|
|
83
|
-
const func = this.getFunctionFromCache('getNumber');
|
|
84
|
-
return func(key);
|
|
85
|
-
}
|
|
86
|
-
getBuffer(key: string): ArrayBufferLike | undefined {
|
|
87
|
-
const func = this.getFunctionFromCache('getBuffer');
|
|
88
|
-
return func(key);
|
|
89
|
-
}
|
|
90
|
-
contains(key: string): boolean {
|
|
91
|
-
const func = this.getFunctionFromCache('contains');
|
|
92
|
-
return func(key);
|
|
93
|
-
}
|
|
94
|
-
delete(key: string): void {
|
|
95
|
-
const func = this.getFunctionFromCache('delete');
|
|
96
|
-
func(key);
|
|
97
|
-
|
|
98
|
-
this.onValuesChanged([key]);
|
|
99
|
-
}
|
|
100
|
-
getAllKeys(): string[] {
|
|
101
|
-
const func = this.getFunctionFromCache('getAllKeys');
|
|
102
|
-
return func();
|
|
103
|
-
}
|
|
104
|
-
clearAll(): void {
|
|
105
|
-
const keys = this.getAllKeys();
|
|
106
|
-
|
|
107
|
-
const func = this.getFunctionFromCache('clearAll');
|
|
108
|
-
func();
|
|
109
|
-
|
|
110
|
-
this.onValuesChanged(keys);
|
|
111
|
-
}
|
|
112
|
-
recrypt(key: string | undefined): void {
|
|
113
|
-
const func = this.getFunctionFromCache('recrypt');
|
|
114
|
-
return func(key);
|
|
115
|
-
}
|
|
116
|
-
trim(): void {
|
|
117
|
-
const func = this.getFunctionFromCache('trim');
|
|
118
|
-
func();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
toString(): string {
|
|
122
|
-
return `MMKV (${this.id}): [${this.getAllKeys().join(', ')}]`;
|
|
123
|
-
}
|
|
124
|
-
toJSON(): object {
|
|
125
|
-
return {
|
|
126
|
-
[this.id]: this.getAllKeys(),
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
addOnValueChangedListener(onValueChanged: (key: string) => void): Listener {
|
|
131
|
-
this.onValueChangedListeners.push(onValueChanged);
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
remove: () => {
|
|
135
|
-
const index = this.onValueChangedListeners.indexOf(onValueChanged);
|
|
136
|
-
if (index !== -1) {
|
|
137
|
-
this.onValueChangedListeners.splice(index, 1);
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
}
|