react-native-mmkv 3.0.0-beta.6 → 3.0.0-beta.7

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.
Files changed (52) hide show
  1. package/MMKV/Core/CMakeLists.txt +1 -1
  2. package/MMKV/Core/Core.xcodeproj/project.pbxproj +4 -6
  3. package/MMKV/Core/MMBuffer.h +1 -1
  4. package/MMKV/Core/MMKV.cpp +70 -73
  5. package/MMKV/Core/MMKV.h +126 -11
  6. package/MMKV/Core/MMKVPredef.h +44 -3
  7. package/MMKV/Core/MMKV_IO.cpp +29 -21
  8. package/MMKV/Core/MMKV_OSX.cpp +4 -3
  9. package/MMKV/Core/MemoryFile_Android.cpp +27 -13
  10. package/MMKV/Core/MiniPBCoder.cpp +308 -9
  11. package/MMKV/Core/MiniPBCoder.h +36 -17
  12. package/MMKV/Core/MiniPBCoder_OSX.cpp +1 -0
  13. package/MMKV/Core/PBEncodeItem.hpp +18 -0
  14. package/MMKV/Core/PBUtility.h +0 -12
  15. package/MMKV/Core/core.vcxproj +4 -4
  16. package/MMKV/Core/crc32/Checksum.h +4 -1
  17. package/android/CMakeLists.txt +0 -1
  18. package/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java +9 -0
  19. package/cpp/MmkvHostObject.cpp +35 -37
  20. package/ios/MmkvPlatformContextModule.mm +19 -1
  21. package/lib/commonjs/MMKV.js.map +1 -1
  22. package/lib/commonjs/NativeMmkvPlatformContext.js.map +1 -1
  23. package/lib/commonjs/createMMKV.js +17 -0
  24. package/lib/commonjs/createMMKV.js.map +1 -1
  25. package/lib/commonjs/hooks.js.map +1 -1
  26. package/lib/module/MMKV.js.map +1 -1
  27. package/lib/module/NativeMmkvPlatformContext.js.map +1 -1
  28. package/lib/module/createMMKV.js +17 -0
  29. package/lib/module/createMMKV.js.map +1 -1
  30. package/lib/module/hooks.js.map +1 -1
  31. package/lib/typescript/src/MMKV.d.ts +0 -1
  32. package/lib/typescript/src/MMKV.d.ts.map +1 -1
  33. package/lib/typescript/src/NativeMmkv.d.ts +3 -3
  34. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts +11 -0
  35. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +1 -1
  36. package/lib/typescript/src/Types.d.ts +4 -0
  37. package/lib/typescript/src/Types.d.ts.map +1 -1
  38. package/lib/typescript/src/createMMKV.d.ts +1 -1
  39. package/lib/typescript/src/createMMKV.d.ts.map +1 -1
  40. package/lib/typescript/src/createMMKV.web.d.ts +1 -1
  41. package/lib/typescript/src/createMMKV.web.d.ts.map +1 -1
  42. package/lib/typescript/src/hooks.d.ts +1 -1
  43. package/lib/typescript/src/hooks.d.ts.map +1 -1
  44. package/package.json +6 -6
  45. package/src/MMKV.ts +0 -1
  46. package/src/NativeMmkv.ts +3 -3
  47. package/src/NativeMmkvPlatformContext.ts +11 -0
  48. package/src/Types.ts +4 -0
  49. package/src/createMMKV.ts +20 -2
  50. package/src/createMMKV.web.ts +1 -1
  51. package/src/hooks.ts +1 -1
  52. package/android/src/main/cpp/cpp-adapter.cpp +0 -7
package/src/NativeMmkv.ts CHANGED
@@ -42,9 +42,9 @@ export interface Configuration {
42
42
  * const temporaryStorage = new MMKV({ path: '/tmp/' })
43
43
  * ```
44
44
  *
45
- * _Notice_: On iOS you can set the AppGroup bundle property to share the same storage between your app and its extensions.
46
- * In this case `path` property will be ignored.
47
- * See more on MMKV configuration [here](https://github.com/Tencent/MMKV/wiki/iOS_tutorial#configuration).
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
48
  *
49
49
  * @default undefined
50
50
  */
@@ -7,6 +7,17 @@ export interface Spec extends TurboModule {
7
7
  * Gets the base directory of the documents storage
8
8
  */
9
9
  getBaseDirectory(): string;
10
+ /**
11
+ * Get the App Group directory if it exists, or `undefined` otherwise.
12
+ *
13
+ * The App Group directory will be used instead of a custom path to use the same
14
+ * MMKV instance between the iOS app, Widgets, and other companion apps.
15
+ *
16
+ * To set an App Group, add a `AppGroup` field to `Info.plist`
17
+ *
18
+ * @platform ios
19
+ */
20
+ getAppGroupDirectory(): string | undefined;
10
21
  }
11
22
 
12
23
  let module: Spec | null;
package/src/Types.ts CHANGED
@@ -4,6 +4,8 @@
4
4
  export interface NativeMMKV {
5
5
  /**
6
6
  * Set a value for the given `key`.
7
+ *
8
+ * @throws an Error if the value cannot be set.
7
9
  */
8
10
  set: (key: string, value: boolean | string | number | ArrayBuffer) => void;
9
11
  /**
@@ -54,6 +56,8 @@ export interface NativeMMKV {
54
56
  * To remove encryption, pass `undefined` as a key.
55
57
  *
56
58
  * Encryption keys can have a maximum length of 16 bytes.
59
+ *
60
+ * @throws an Error if the instance cannot be recrypted.
57
61
  */
58
62
  recrypt: (key: string | undefined) => void;
59
63
  /**
package/src/createMMKV.ts CHANGED
@@ -1,10 +1,28 @@
1
- import type { Configuration } from './MMKV';
2
- import { getMMKVTurboModule } from './NativeMmkv';
1
+ import { Platform } from 'react-native';
2
+ import { getMMKVTurboModule, type Configuration } from './NativeMmkv';
3
3
  import type { NativeMMKV } from './Types';
4
+ import { getMMKVPlatformContextTurboModule } from './NativeMmkvPlatformContext';
4
5
 
5
6
  export const createMMKV = (config: Configuration): NativeMMKV => {
6
7
  const module = getMMKVTurboModule();
7
8
 
9
+ if (Platform.OS === 'ios') {
10
+ if (config.path == null) {
11
+ try {
12
+ // If no `path` was supplied, we check if an `AppGroup` was set in Info.plist
13
+ const appGroupDirectory =
14
+ getMMKVPlatformContextTurboModule().getAppGroupDirectory();
15
+ if (appGroupDirectory != null) {
16
+ // If we have an `AppGroup` in Info.plist, use that as a path.
17
+ config.path = appGroupDirectory;
18
+ }
19
+ } catch (e) {
20
+ // We cannot throw errors here because it is a sync C++ TurboModule func. idk why.
21
+ console.error(e);
22
+ }
23
+ }
24
+ }
25
+
8
26
  const instance = module.createMMKV(config);
9
27
  if (__DEV__) {
10
28
  if (typeof instance !== 'object' || instance == null) {
@@ -1,5 +1,5 @@
1
1
  /* global localStorage */
2
- import type { Configuration } from './MMKV';
2
+ import type { Configuration } from './NativeMmkv';
3
3
  import type { NativeMMKV } from './Types';
4
4
  import { createTextEncoder } from './createTextEncoder';
5
5
 
package/src/hooks.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useRef, useState, useMemo, useCallback, useEffect } from 'react';
2
- import type { Configuration } from './MMKV';
3
2
  import { MMKV } from './MMKV';
3
+ import type { Configuration } from './NativeMmkv';
4
4
 
5
5
  function isConfigurationEqual(
6
6
  left?: Configuration,
@@ -1,7 +0,0 @@
1
- #include <jni.h>
2
-
3
- extern "C" JNIEXPORT jdouble JNICALL Java_com_mmkv_MmkvModule_nativeMultiply(JNIEnv* env,
4
- jclass type, jdouble a,
5
- jdouble b) {
6
- return 5.0;
7
- }