react-native-mmkv 4.0.0-beta.1 → 4.0.0-beta.2

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 (219) hide show
  1. package/{react-native-mmkv.podspec → NitroMmkv.podspec} +17 -13
  2. package/README.md +1 -3
  3. package/android/CMakeLists.txt +31 -30
  4. package/android/build.gradle +64 -19
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -5
  7. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  8. package/android/src/main/java/com/margelo/nitro/mmkv/HybridMMKVPlatformContext.kt +19 -0
  9. package/android/src/main/java/com/margelo/nitro/mmkv/NitroMmkvPackage.java +33 -0
  10. package/ios/HybridMMKVPlatformContext.swift +32 -0
  11. package/lib/__tests__/hooks.test.d.ts +1 -0
  12. package/lib/__tests__/hooks.test.js +66 -0
  13. package/lib/addMemoryWarningListener/addMemoryWarningListener.d.ts +2 -0
  14. package/lib/addMemoryWarningListener/addMemoryWarningListener.js +25 -0
  15. package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.d.ts +2 -0
  16. package/lib/addMemoryWarningListener/addMemoryWarningListener.mock.js +3 -0
  17. package/lib/addMemoryWarningListener/addMemoryWarningListener.web.d.ts +2 -0
  18. package/lib/addMemoryWarningListener/addMemoryWarningListener.web.js +3 -0
  19. package/lib/createMMKV/createMMKV.d.ts +3 -0
  20. package/lib/createMMKV/createMMKV.js +40 -0
  21. package/lib/createMMKV/createMMKV.mock.d.ts +5 -0
  22. package/lib/createMMKV/createMMKV.mock.js +53 -0
  23. package/lib/createMMKV/createMMKV.web.d.ts +3 -0
  24. package/lib/createMMKV/createMMKV.web.js +117 -0
  25. package/lib/createMMKV/getDefaultMMKVInstance.d.ts +2 -0
  26. package/lib/createMMKV/getDefaultMMKVInstance.js +8 -0
  27. package/lib/hooks/createMMKVHook.d.ts +2 -0
  28. package/lib/hooks/createMMKVHook.js +49 -0
  29. package/lib/hooks/useMMKV.d.ts +11 -0
  30. package/lib/hooks/useMMKV.js +23 -0
  31. package/lib/hooks/useMMKVBoolean.d.ts +11 -0
  32. package/lib/hooks/useMMKVBoolean.js +12 -0
  33. package/lib/hooks/useMMKVBuffer.d.ts +11 -0
  34. package/lib/hooks/useMMKVBuffer.js +12 -0
  35. package/lib/hooks/useMMKVKeys.d.ts +12 -0
  36. package/lib/hooks/useMMKVKeys.js +33 -0
  37. package/lib/hooks/useMMKVListener.d.ts +15 -0
  38. package/lib/hooks/useMMKVListener.js +26 -0
  39. package/lib/hooks/useMMKVNumber.d.ts +11 -0
  40. package/lib/hooks/useMMKVNumber.js +12 -0
  41. package/lib/hooks/useMMKVObject.d.ts +17 -0
  42. package/lib/hooks/useMMKVObject.js +38 -0
  43. package/lib/hooks/useMMKVString.d.ts +11 -0
  44. package/lib/hooks/useMMKVString.js +12 -0
  45. package/lib/index.d.ts +11 -0
  46. package/lib/index.js +11 -0
  47. package/lib/isTest.d.ts +1 -0
  48. package/lib/isTest.js +7 -0
  49. package/lib/specs/MMKV.nitro.d.ts +93 -0
  50. package/lib/specs/MMKV.nitro.js +1 -0
  51. package/lib/{typescript/src/NativeMmkv.d.ts → specs/MMKVFactory.nitro.d.ts} +22 -29
  52. package/lib/specs/MMKVFactory.nitro.js +1 -0
  53. package/lib/specs/MMKVPlatformContext.nitro.d.ts +15 -0
  54. package/lib/specs/MMKVPlatformContext.nitro.js +1 -0
  55. package/lib/{typescript/src → web}/createTextEncoder.d.ts +0 -1
  56. package/lib/web/createTextEncoder.js +17 -0
  57. package/nitro.json +27 -0
  58. package/nitrogen/generated/.gitattributes +1 -0
  59. package/nitrogen/generated/android/NitroMmkv+autolinking.cmake +80 -0
  60. package/nitrogen/generated/android/NitroMmkv+autolinking.gradle +27 -0
  61. package/nitrogen/generated/android/NitroMmkvOnLoad.cpp +55 -0
  62. package/nitrogen/generated/android/NitroMmkvOnLoad.hpp +25 -0
  63. package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.cpp +51 -0
  64. package/nitrogen/generated/android/c++/JHybridMMKVPlatformContextSpec.hpp +65 -0
  65. package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/HybridMMKVPlatformContextSpec.kt +56 -0
  66. package/nitrogen/generated/android/kotlin/com/margelo/nitro/mmkv/NitroMmkvOnLoad.kt +35 -0
  67. package/nitrogen/generated/ios/NitroMmkv+autolinking.rb +60 -0
  68. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.cpp +32 -0
  69. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Bridge.hpp +52 -0
  70. package/nitrogen/generated/ios/NitroMmkv-Swift-Cxx-Umbrella.hpp +44 -0
  71. package/nitrogen/generated/ios/NitroMmkvAutolinking.mm +43 -0
  72. package/nitrogen/generated/ios/NitroMmkvAutolinking.swift +25 -0
  73. package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.cpp +11 -0
  74. package/nitrogen/generated/ios/c++/HybridMMKVPlatformContextSpecSwift.hpp +81 -0
  75. package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec.swift +50 -0
  76. package/nitrogen/generated/ios/swift/HybridMMKVPlatformContextSpec_cxx.swift +135 -0
  77. package/nitrogen/generated/shared/c++/Configuration.hpp +86 -0
  78. package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.cpp +23 -0
  79. package/nitrogen/generated/shared/c++/HybridMMKVFactorySpec.hpp +69 -0
  80. package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.cpp +22 -0
  81. package/nitrogen/generated/shared/c++/HybridMMKVPlatformContextSpec.hpp +63 -0
  82. package/nitrogen/generated/shared/c++/HybridMMKVSpec.cpp +34 -0
  83. package/nitrogen/generated/shared/c++/HybridMMKVSpec.hpp +83 -0
  84. package/nitrogen/generated/shared/c++/Listener.hpp +67 -0
  85. package/nitrogen/generated/shared/c++/Mode.hpp +76 -0
  86. package/package.json +71 -122
  87. package/react-native.config.js +2 -15
  88. package/src/__tests__/hooks.test.tsx +34 -34
  89. package/src/addMemoryWarningListener/addMemoryWarningListener.mock.ts +5 -0
  90. package/src/{MemoryWarningListener.ts → addMemoryWarningListener/addMemoryWarningListener.ts} +12 -12
  91. package/src/addMemoryWarningListener/addMemoryWarningListener.web.ts +5 -0
  92. package/src/createMMKV/createMMKV.mock.ts +56 -0
  93. package/src/createMMKV/createMMKV.ts +51 -0
  94. package/src/{createMMKV.web.ts → createMMKV/createMMKV.web.ts} +56 -46
  95. package/src/createMMKV/getDefaultMMKVInstance.ts +10 -0
  96. package/src/hooks/createMMKVHook.ts +66 -0
  97. package/src/hooks/useMMKV.ts +45 -0
  98. package/src/hooks/useMMKVBoolean.ts +15 -0
  99. package/src/hooks/useMMKVBuffer.ts +15 -0
  100. package/src/hooks/useMMKVKeys.ts +36 -0
  101. package/src/hooks/useMMKVListener.ts +33 -0
  102. package/src/hooks/useMMKVNumber.ts +15 -0
  103. package/src/hooks/useMMKVObject.ts +53 -0
  104. package/src/hooks/useMMKVString.ts +15 -0
  105. package/src/index.ts +15 -3
  106. package/src/{PlatformChecker.ts → isTest.ts} +2 -2
  107. package/src/specs/MMKV.nitro.ts +92 -0
  108. package/src/specs/MMKVFactory.nitro.ts +87 -0
  109. package/src/specs/MMKVPlatformContext.nitro.ts +14 -0
  110. package/src/{createTextEncoder.ts → web/createTextEncoder.ts} +7 -7
  111. package/android/src/main/cpp/AndroidLogger.cpp +0 -16
  112. package/android/src/main/java/com/mrousavy/mmkv/MmkvPackage.java +0 -44
  113. package/android/src/main/java/com/mrousavy/mmkv/MmkvPlatformContextModule.java +0 -26
  114. package/cpp/ManagedMMBuffer.h +0 -32
  115. package/cpp/MmkvHostObject.cpp +0 -360
  116. package/cpp/MmkvHostObject.h +0 -31
  117. package/cpp/MmkvLogger.h +0 -35
  118. package/cpp/MmkvTypes.h +0 -50
  119. package/cpp/NativeMmkvModule.cpp +0 -43
  120. package/cpp/NativeMmkvModule.h +0 -31
  121. package/ios/AppleLogger.mm +0 -16
  122. package/ios/MmkvOnLoad.mm +0 -25
  123. package/ios/MmkvPlatformContext.h +0 -19
  124. package/ios/MmkvPlatformContextModule.mm +0 -55
  125. package/lib/commonjs/MMKV.js +0 -124
  126. package/lib/commonjs/MMKV.js.map +0 -1
  127. package/lib/commonjs/MemoryWarningListener.js +0 -31
  128. package/lib/commonjs/MemoryWarningListener.js.map +0 -1
  129. package/lib/commonjs/MemoryWarningListener.web.js +0 -11
  130. package/lib/commonjs/MemoryWarningListener.web.js.map +0 -1
  131. package/lib/commonjs/ModuleNotFoundError.js +0 -75
  132. package/lib/commonjs/ModuleNotFoundError.js.map +0 -1
  133. package/lib/commonjs/NativeMmkv.js +0 -47
  134. package/lib/commonjs/NativeMmkv.js.map +0 -1
  135. package/lib/commonjs/NativeMmkvPlatformContext.js +0 -22
  136. package/lib/commonjs/NativeMmkvPlatformContext.js.map +0 -1
  137. package/lib/commonjs/PlatformChecker.js +0 -14
  138. package/lib/commonjs/PlatformChecker.js.map +0 -1
  139. package/lib/commonjs/Types.js +0 -26
  140. package/lib/commonjs/Types.js.map +0 -1
  141. package/lib/commonjs/createMMKV.js +0 -43
  142. package/lib/commonjs/createMMKV.js.map +0 -1
  143. package/lib/commonjs/createMMKV.mock.js +0 -43
  144. package/lib/commonjs/createMMKV.mock.js.map +0 -1
  145. package/lib/commonjs/createMMKV.web.js +0 -110
  146. package/lib/commonjs/createMMKV.web.js.map +0 -1
  147. package/lib/commonjs/createTextEncoder.js +0 -23
  148. package/lib/commonjs/createTextEncoder.js.map +0 -1
  149. package/lib/commonjs/hooks.js +0 -198
  150. package/lib/commonjs/hooks.js.map +0 -1
  151. package/lib/commonjs/index.js +0 -40
  152. package/lib/commonjs/index.js.map +0 -1
  153. package/lib/commonjs/package.json +0 -1
  154. package/lib/module/MMKV.js +0 -119
  155. package/lib/module/MMKV.js.map +0 -1
  156. package/lib/module/MemoryWarningListener.js +0 -27
  157. package/lib/module/MemoryWarningListener.js.map +0 -1
  158. package/lib/module/MemoryWarningListener.web.js +0 -6
  159. package/lib/module/MemoryWarningListener.web.js.map +0 -1
  160. package/lib/module/ModuleNotFoundError.js +0 -70
  161. package/lib/module/ModuleNotFoundError.js.map +0 -1
  162. package/lib/module/NativeMmkv.js +0 -45
  163. package/lib/module/NativeMmkv.js.map +0 -1
  164. package/lib/module/NativeMmkvPlatformContext.js +0 -18
  165. package/lib/module/NativeMmkvPlatformContext.js.map +0 -1
  166. package/lib/module/PlatformChecker.js +0 -10
  167. package/lib/module/PlatformChecker.js.map +0 -1
  168. package/lib/module/Types.js +0 -25
  169. package/lib/module/Types.js.map +0 -1
  170. package/lib/module/createMMKV.js +0 -38
  171. package/lib/module/createMMKV.js.map +0 -1
  172. package/lib/module/createMMKV.mock.js +0 -38
  173. package/lib/module/createMMKV.mock.js.map +0 -1
  174. package/lib/module/createMMKV.web.js +0 -105
  175. package/lib/module/createMMKV.web.js.map +0 -1
  176. package/lib/module/createTextEncoder.js +0 -19
  177. package/lib/module/createTextEncoder.js.map +0 -1
  178. package/lib/module/hooks.js +0 -189
  179. package/lib/module/hooks.js.map +0 -1
  180. package/lib/module/index.js +0 -6
  181. package/lib/module/index.js.map +0 -1
  182. package/lib/module/package.json +0 -1
  183. package/lib/typescript/src/MMKV.d.ts +0 -34
  184. package/lib/typescript/src/MMKV.d.ts.map +0 -1
  185. package/lib/typescript/src/MemoryWarningListener.d.ts +0 -3
  186. package/lib/typescript/src/MemoryWarningListener.d.ts.map +0 -1
  187. package/lib/typescript/src/MemoryWarningListener.web.d.ts +0 -3
  188. package/lib/typescript/src/MemoryWarningListener.web.d.ts.map +0 -1
  189. package/lib/typescript/src/ModuleNotFoundError.d.ts +0 -7
  190. package/lib/typescript/src/ModuleNotFoundError.d.ts.map +0 -1
  191. package/lib/typescript/src/NativeMmkv.d.ts.map +0 -1
  192. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts +0 -20
  193. package/lib/typescript/src/NativeMmkvPlatformContext.d.ts.map +0 -1
  194. package/lib/typescript/src/PlatformChecker.d.ts +0 -2
  195. package/lib/typescript/src/PlatformChecker.d.ts.map +0 -1
  196. package/lib/typescript/src/Types.d.ts +0 -172
  197. package/lib/typescript/src/Types.d.ts.map +0 -1
  198. package/lib/typescript/src/__tests__/hooks.test.d.ts +0 -2
  199. package/lib/typescript/src/__tests__/hooks.test.d.ts.map +0 -1
  200. package/lib/typescript/src/createMMKV.d.ts +0 -3
  201. package/lib/typescript/src/createMMKV.d.ts.map +0 -1
  202. package/lib/typescript/src/createMMKV.mock.d.ts +0 -3
  203. package/lib/typescript/src/createMMKV.mock.d.ts.map +0 -1
  204. package/lib/typescript/src/createMMKV.web.d.ts +0 -3
  205. package/lib/typescript/src/createMMKV.web.d.ts.map +0 -1
  206. package/lib/typescript/src/createTextEncoder.d.ts.map +0 -1
  207. package/lib/typescript/src/hooks.d.ts +0 -86
  208. package/lib/typescript/src/hooks.d.ts.map +0 -1
  209. package/lib/typescript/src/index.d.ts +0 -4
  210. package/lib/typescript/src/index.d.ts.map +0 -1
  211. package/src/MMKV.ts +0 -142
  212. package/src/MemoryWarningListener.web.ts +0 -5
  213. package/src/ModuleNotFoundError.ts +0 -95
  214. package/src/NativeMmkv.ts +0 -118
  215. package/src/NativeMmkvPlatformContext.ts +0 -38
  216. package/src/Types.ts +0 -178
  217. package/src/createMMKV.mock.ts +0 -38
  218. package/src/createMMKV.ts +0 -42
  219. package/src/hooks.ts +0 -247
@@ -1,198 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useMMKV = useMMKV;
7
- exports.useMMKVBuffer = exports.useMMKVBoolean = void 0;
8
- exports.useMMKVListener = useMMKVListener;
9
- exports.useMMKVNumber = void 0;
10
- exports.useMMKVObject = useMMKVObject;
11
- exports.useMMKVString = void 0;
12
- var _react = require("react");
13
- var _MMKV = require("./MMKV");
14
- function isConfigurationEqual(left, right) {
15
- if (left == null || right == null) return left == null && right == null;
16
- return left.encryptionKey === right.encryptionKey && left.id === right.id && left.path === right.path && left.mode === right.mode;
17
- }
18
- let defaultInstance = null;
19
- function getDefaultInstance() {
20
- if (defaultInstance == null) {
21
- defaultInstance = new _MMKV.MMKV();
22
- }
23
- return defaultInstance;
24
- }
25
-
26
- /**
27
- * Use the default, shared MMKV instance.
28
- */
29
-
30
- /**
31
- * Use a custom MMKV instance with the given configuration.
32
- * @param configuration The configuration to initialize the MMKV instance with. Does not have to be memoized.
33
- */
34
-
35
- function useMMKV(configuration) {
36
- const instance = (0, _react.useRef)(undefined);
37
- const lastConfiguration = (0, _react.useRef)(undefined);
38
- if (configuration == null) return getDefaultInstance();
39
- if (instance.current == null || !isConfigurationEqual(lastConfiguration.current, configuration)) {
40
- lastConfiguration.current = configuration;
41
- instance.current = new _MMKV.MMKV(configuration);
42
- }
43
- return instance.current;
44
- }
45
- function createMMKVHook(getter) {
46
- return (key, instance) => {
47
- const mmkv = instance ?? getDefaultInstance();
48
- const [bump, setBump] = (0, _react.useState)(0);
49
- const value = (0, _react.useMemo)(() => {
50
- // bump is here as an additional outside dependency, so this useMemo
51
- // re-computes the value each time bump changes, effectively acting as a hint
52
- // that the outside value (storage) has changed. setting bump refreshes this value.
53
- bump;
54
- return getter(mmkv, key);
55
- }, [mmkv, key, bump]);
56
-
57
- // update value by user set
58
- const set = (0, _react.useCallback)(v => {
59
- const newValue = typeof v === 'function' ? v(getter(mmkv, key)) : v;
60
- switch (typeof newValue) {
61
- case 'number':
62
- case 'string':
63
- case 'boolean':
64
- mmkv.set(key, newValue);
65
- break;
66
- case 'undefined':
67
- mmkv.delete(key);
68
- break;
69
- case 'object':
70
- if (newValue instanceof ArrayBuffer) {
71
- mmkv.set(key, newValue);
72
- break;
73
- } else {
74
- throw new Error(`MMKV: Type object (${newValue}) is not supported!`);
75
- }
76
- default:
77
- throw new Error(`MMKV: Type ${typeof newValue} is not supported!`);
78
- }
79
- }, [key, mmkv]);
80
-
81
- // update value if it changes somewhere else (second hook, same key)
82
- (0, _react.useEffect)(() => {
83
- const listener = mmkv.addOnValueChangedListener(changedKey => {
84
- if (changedKey === key) {
85
- setBump(b => b + 1);
86
- }
87
- });
88
- return () => listener.remove();
89
- }, [key, mmkv]);
90
- return [value, set];
91
- };
92
- }
93
-
94
- /**
95
- * Use the string value of the given `key` from the given MMKV storage instance.
96
- *
97
- * If no instance is provided, a shared default instance will be used.
98
- *
99
- * @example
100
- * ```ts
101
- * const [username, setUsername] = useMMKVString("user.name")
102
- * ```
103
- */
104
- const useMMKVString = exports.useMMKVString = createMMKVHook((instance, key) => instance.getString(key));
105
-
106
- /**
107
- * Use the number value of the given `key` from the given MMKV storage instance.
108
- *
109
- * If no instance is provided, a shared default instance will be used.
110
- *
111
- * @example
112
- * ```ts
113
- * const [age, setAge] = useMMKVNumber("user.age")
114
- * ```
115
- */
116
- const useMMKVNumber = exports.useMMKVNumber = createMMKVHook((instance, key) => instance.getNumber(key));
117
- /**
118
- * Use the boolean value of the given `key` from the given MMKV storage instance.
119
- *
120
- * If no instance is provided, a shared default instance will be used.
121
- *
122
- * @example
123
- * ```ts
124
- * const [isPremiumAccount, setIsPremiumAccount] = useMMKVBoolean("user.isPremium")
125
- * ```
126
- */
127
- const useMMKVBoolean = exports.useMMKVBoolean = createMMKVHook((instance, key) => instance.getBoolean(key));
128
- /**
129
- * Use the buffer value (unsigned 8-bit (0-255)) of the given `key` from the given MMKV storage instance.
130
- *
131
- * If no instance is provided, a shared default instance will be used.
132
- *
133
- * @example
134
- * ```ts
135
- * const [privateKey, setPrivateKey] = useMMKVBuffer("user.privateKey")
136
- * ```
137
- */
138
- const useMMKVBuffer = exports.useMMKVBuffer = createMMKVHook((instance, key) => instance.getBuffer(key));
139
- /**
140
- * Use an object value of the given `key` from the given MMKV storage instance.
141
- *
142
- * If no instance is provided, a shared default instance will be used.
143
- *
144
- * The object will be serialized using `JSON`.
145
- *
146
- * @example
147
- * ```ts
148
- * const [user, setUser] = useMMKVObject<User>("user")
149
- * ```
150
- */
151
- function useMMKVObject(key, instance) {
152
- const [json, setJson] = useMMKVString(key, instance);
153
- const value = (0, _react.useMemo)(() => {
154
- if (json == null) return undefined;
155
- return JSON.parse(json);
156
- }, [json]);
157
- const setValue = (0, _react.useCallback)(v => {
158
- if (v instanceof Function) {
159
- setJson(currentJson => {
160
- const currentValue = currentJson != null ? JSON.parse(currentJson) : undefined;
161
- const newValue = v(currentValue);
162
- // Store the Object as a serialized Value or clear the value
163
- return newValue != null ? JSON.stringify(newValue) : undefined;
164
- });
165
- } else {
166
- // Store the Object as a serialized Value or clear the value
167
- const newValue = v != null ? JSON.stringify(v) : undefined;
168
- setJson(newValue);
169
- }
170
- }, [setJson]);
171
- return [value, setValue];
172
- }
173
-
174
- /**
175
- * Listen for changes in the given MMKV storage instance.
176
- * If no instance is passed, the default instance will be used.
177
- * @param valueChangedListener The function to call whenever a value inside the storage instance changes
178
- * @param instance The instance to listen to changes to (or the default instance)
179
- *
180
- * @example
181
- * ```ts
182
- * useMMKVListener((key) => {
183
- * console.log(`Value for "${key}" changed!`)
184
- * })
185
- * ```
186
- */
187
- function useMMKVListener(valueChangedListener, instance) {
188
- const ref = (0, _react.useRef)(valueChangedListener);
189
- ref.current = valueChangedListener;
190
- const mmkv = instance ?? getDefaultInstance();
191
- (0, _react.useEffect)(() => {
192
- const listener = mmkv.addOnValueChangedListener(changedKey => {
193
- ref.current(changedKey);
194
- });
195
- return () => listener.remove();
196
- }, [mmkv]);
197
- }
198
- //# sourceMappingURL=hooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","require","_MMKV","isConfigurationEqual","left","right","encryptionKey","id","path","mode","defaultInstance","getDefaultInstance","MMKV","useMMKV","configuration","instance","useRef","undefined","lastConfiguration","current","createMMKVHook","getter","key","mmkv","bump","setBump","useState","value","useMemo","set","useCallback","v","newValue","delete","ArrayBuffer","Error","useEffect","listener","addOnValueChangedListener","changedKey","b","remove","useMMKVString","exports","getString","useMMKVNumber","getNumber","useMMKVBoolean","getBoolean","useMMKVBuffer","getBuffer","useMMKVObject","json","setJson","JSON","parse","setValue","Function","currentJson","currentValue","stringify","useMMKVListener","valueChangedListener","ref"],"sourceRoot":"../../src","sources":["hooks.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAGA,SAASE,oBAAoBA,CAC3BC,IAAoB,EACpBC,KAAqB,EACZ;EACT,IAAID,IAAI,IAAI,IAAI,IAAIC,KAAK,IAAI,IAAI,EAAE,OAAOD,IAAI,IAAI,IAAI,IAAIC,KAAK,IAAI,IAAI;EAEvE,OACED,IAAI,CAACE,aAAa,KAAKD,KAAK,CAACC,aAAa,IAC1CF,IAAI,CAACG,EAAE,KAAKF,KAAK,CAACE,EAAE,IACpBH,IAAI,CAACI,IAAI,KAAKH,KAAK,CAACG,IAAI,IACxBJ,IAAI,CAACK,IAAI,KAAKJ,KAAK,CAACI,IAAI;AAE5B;AAEA,IAAIC,eAA4B,GAAG,IAAI;AACvC,SAASC,kBAAkBA,CAAA,EAAS;EAClC,IAAID,eAAe,IAAI,IAAI,EAAE;IAC3BA,eAAe,GAAG,IAAIE,UAAI,CAAC,CAAC;EAC9B;EACA,OAAOF,eAAe;AACxB;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEO,SAASG,OAAOA,CAACC,aAA6B,EAAQ;EAC3D,MAAMC,QAAQ,GAAG,IAAAC,aAAM,EAAOC,SAAS,CAAC;EACxC,MAAMC,iBAAiB,GAAG,IAAAF,aAAM,EAAgBC,SAAS,CAAC;EAE1D,IAAIH,aAAa,IAAI,IAAI,EAAE,OAAOH,kBAAkB,CAAC,CAAC;EAEtD,IACEI,QAAQ,CAACI,OAAO,IAAI,IAAI,IACxB,CAAChB,oBAAoB,CAACe,iBAAiB,CAACC,OAAO,EAAEL,aAAa,CAAC,EAC/D;IACAI,iBAAiB,CAACC,OAAO,GAAGL,aAAa;IACzCC,QAAQ,CAACI,OAAO,GAAG,IAAI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G2C,oBAAoB;EAElC,MAAMvC,IAAI,GAAGR,QAAQ,IAAIJ,kBAAkB,CAAC,CAAC;EAE7C,IAAAyB,gBAAS,EAAC,MAAM;IACd,MAAMC,QAAQ,GAAGd,IAAI,CAACe,yBAAyB,CAAEC,UAAU,IAAK;MAC9DwB,GAAG,CAAC5C,OAAO,CAACoB,UAAU,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,MAAMF,QAAQ,CAACI,MAAM,CAAC,CAAC;EAChC,CAAC,EAAE,CAAClB,IAAI,CAAC,CAAC;AACZ","ignoreList":[]}
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- Mode: true
8
- };
9
- Object.defineProperty(exports, "Mode", {
10
- enumerable: true,
11
- get: function () {
12
- return _Types.Mode;
13
- }
14
- });
15
- var _MMKV = require("./MMKV");
16
- Object.keys(_MMKV).forEach(function (key) {
17
- if (key === "default" || key === "__esModule") return;
18
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
19
- if (key in exports && exports[key] === _MMKV[key]) return;
20
- Object.defineProperty(exports, key, {
21
- enumerable: true,
22
- get: function () {
23
- return _MMKV[key];
24
- }
25
- });
26
- });
27
- var _hooks = require("./hooks");
28
- Object.keys(_hooks).forEach(function (key) {
29
- if (key === "default" || key === "__esModule") return;
30
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
31
- if (key in exports && exports[key] === _hooks[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _hooks[key];
36
- }
37
- });
38
- });
39
- var _Types = require("./Types");
40
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_MMKV","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_hooks","_Types"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,MAAA,GAAAb,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAW,MAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,MAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AAEA,IAAAU,MAAA,GAAAd,OAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,119 +0,0 @@
1
- "use strict";
2
-
3
- import { createMMKV } from './createMMKV';
4
- import { createMockMMKV } from './createMMKV.mock';
5
- import { isTest } from './PlatformChecker';
6
- import { addMemoryWarningListener } from './MemoryWarningListener';
7
- const onValueChangedListeners = new Map();
8
-
9
- /**
10
- * A single MMKV instance.
11
- */
12
- export class MMKV {
13
- /**
14
- * Creates a new MMKV instance with the given Configuration.
15
- * If no custom `id` is supplied, `'mmkv.default'` will be used.
16
- */
17
- constructor(configuration = {
18
- id: 'mmkv.default'
19
- }) {
20
- this.id = configuration.id;
21
- this.nativeInstance = isTest() ? createMockMMKV() : createMMKV(configuration);
22
- this.functionCache = {};
23
- addMemoryWarningListener(this);
24
- }
25
- get onValueChangedListeners() {
26
- if (!onValueChangedListeners.has(this.id)) {
27
- onValueChangedListeners.set(this.id, []);
28
- }
29
- return onValueChangedListeners.get(this.id);
30
- }
31
- getFunctionFromCache(functionName) {
32
- if (this.functionCache[functionName] == null) {
33
- this.functionCache[functionName] = this.nativeInstance[functionName];
34
- }
35
- return this.functionCache[functionName];
36
- }
37
- onValuesChanged(keys) {
38
- if (this.onValueChangedListeners.length === 0) return;
39
- for (const key of keys) {
40
- for (const listener of this.onValueChangedListeners) {
41
- listener(key);
42
- }
43
- }
44
- }
45
- get size() {
46
- return this.nativeInstance.size;
47
- }
48
- get isReadOnly() {
49
- return this.nativeInstance.isReadOnly;
50
- }
51
- set(key, value) {
52
- const func = this.getFunctionFromCache('set');
53
- func(key, value);
54
- this.onValuesChanged([key]);
55
- }
56
- getBoolean(key) {
57
- const func = this.getFunctionFromCache('getBoolean');
58
- return func(key);
59
- }
60
- getString(key) {
61
- const func = this.getFunctionFromCache('getString');
62
- return func(key);
63
- }
64
- getNumber(key) {
65
- const func = this.getFunctionFromCache('getNumber');
66
- return func(key);
67
- }
68
- getBuffer(key) {
69
- const func = this.getFunctionFromCache('getBuffer');
70
- return func(key);
71
- }
72
- contains(key) {
73
- const func = this.getFunctionFromCache('contains');
74
- return func(key);
75
- }
76
- delete(key) {
77
- const func = this.getFunctionFromCache('delete');
78
- func(key);
79
- this.onValuesChanged([key]);
80
- }
81
- getAllKeys() {
82
- const func = this.getFunctionFromCache('getAllKeys');
83
- return func();
84
- }
85
- clearAll() {
86
- const keys = this.getAllKeys();
87
- const func = this.getFunctionFromCache('clearAll');
88
- func();
89
- this.onValuesChanged(keys);
90
- }
91
- recrypt(key) {
92
- const func = this.getFunctionFromCache('recrypt');
93
- return func(key);
94
- }
95
- trim() {
96
- const func = this.getFunctionFromCache('trim');
97
- func();
98
- }
99
- toString() {
100
- return `MMKV (${this.id}): [${this.getAllKeys().join(', ')}]`;
101
- }
102
- toJSON() {
103
- return {
104
- [this.id]: this.getAllKeys()
105
- };
106
- }
107
- addOnValueChangedListener(onValueChanged) {
108
- this.onValueChangedListeners.push(onValueChanged);
109
- return {
110
- remove: () => {
111
- const index = this.onValueChangedListeners.indexOf(onValueChanged);
112
- if (index !== -1) {
113
- this.onValueChangedListeners.splice(index, 1);
114
- }
115
- }
116
- };
117
- }
118
- }
119
- //# sourceMappingURL=MMKV.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["createMMKV","createMockMMKV","isTest","addMemoryWarningListener","onValueChangedListeners","Map","MMKV","constructor","configuration","id","nativeInstance","functionCache","has","set","get","getFunctionFromCache","functionName","onValuesChanged","keys","length","key","listener","size","isReadOnly","value","func","getBoolean","getString","getNumber","getBuffer","contains","delete","getAllKeys","clearAll","recrypt","trim","toString","join","toJSON","addOnValueChangedListener","onValueChanged","push","remove","index","indexOf","splice"],"sourceRoot":"../../src","sources":["MMKV.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,cAAc;AACzC,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,MAAM,QAAQ,mBAAmB;AAO1C,SAASC,wBAAwB,QAAQ,yBAAyB;AAElE,MAAMC,uBAAuB,GAAG,IAAIC,GAAG,CAAoC,CAAC;;AAE5E;AACA;AACA;AACA,OAAO,MAAMC,IAAI,CAA0B;EAKzC;AACF;AACA;AACA;EACEC,WAAWA,CAACC,aAA4B,GAAG;IAAEC,EAAE,EAAE;EAAe,CAAC,EAAE;IACjE,IAAI,CAACA,EAAE,GAAGD,aAAa,CAACC,EAAE;IAC1B,IAAI,CAACC,cAAc,GAAGR,MAAM,CAAC,CAAC,GAC1BD,cAAc,CAAC,CAAC,GAChBD,UAAU,CAACQ,aAAa,CAAC;IAC7B,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AuB,EAAQ;IACrC,MAAMK,IAAI,GAAG,IAAI,CAACV,oBAAoB,CAAC,SAAS,CAAC;IACjD,OAAOU,IAAI,CAACL,GAAG,CAAC;EAClB;EACAe,IAAIA,CAAA,EAAS;IACX,MAAMV,IAAI,GAAG,IAAI,CAACV,oBAAoB,CAAC,MAAM,CAAC;IAC9CU,IAAI,CAAC,CAAC;EACR;EAEAW,QAAQA,CAAA,EAAW;IACjB,OAAO,SAAS,IAAI,CAAC3B,EAAE,OAAO,IAAI,CAACuB,UAAU,CAAC,CAAC,CAACK,IAAI,CAAC,IAAI,CAAC,GAAG;EAC/D;EACAC,MAAMA,CAAA,EAAW;IACf,OAAO;MACL,CAAC,IAAI,CAAC7B,EAAE,GAAG,IAAI,CAACuB,UAAU,CAAC;IAC7B,CAAC;EACH;EAEAO,yBAAyBA,CAACC,cAAqC,EAAY;IACzE,IAAI,CAACpC,uBAAuB,CAACqC,IAAI,CAACD,cAAc,CAAC;IAEjD,OAAO;MACLE,MAAM,EAAEA,CAAA,KAAM;QACZ,MAAMC,KAAK,GAAG,IAAI,CAACvC,uBAAuB,CAACwC,OAAO,CAACJ,cAAc,CAAC;QAClE,IAAIG,KAAK,KAAK,CAAC,CAAC,EAAE;UAChB,IAAI,CAACvC,uBAAuB,CAACyC,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;QAC/C;MACF;IACF,CAAC;EACH;AACF","ignoreList":[]}
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- import { AppState } from 'react-native';
4
- export function addMemoryWarningListener(mmkv) {
5
- if (global.WeakRef != null && global.FinalizationRegistry != null) {
6
- // 1. Weakify MMKV so we can safely use it inside the memoryWarning event listener
7
- const weakMmkv = new WeakRef(mmkv);
8
- const listener = AppState.addEventListener('memoryWarning', () => {
9
- // 0. Everytime we receive a memoryWarning, we try to trim the MMKV instance (if it is still valid)
10
- weakMmkv.deref()?.trim();
11
- });
12
- // 2. Add a listener to when the MMKV instance is deleted
13
- const finalization = new FinalizationRegistry(l => {
14
- // 3. When MMKV is deleted, this listener will be called with the memoryWarning listener.
15
- l.remove();
16
- });
17
- // 2.1. Bind the listener to the actual MMKV instance.
18
- finalization.register(mmkv, listener);
19
- } else {
20
- // WeakRef/FinalizationRegistry is not implemented in this engine.
21
- // Just add the listener, even if it retains MMKV strong forever.
22
- AppState.addEventListener('memoryWarning', () => {
23
- mmkv.trim();
24
- });
25
- }
26
- }
27
- //# sourceMappingURL=MemoryWarningListener.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["AppState","addMemoryWarningListener","mmkv","global","WeakRef","FinalizationRegistry","weakMmkv","listener","addEventListener","deref","trim","finalization","l","remove","register"],"sourceRoot":"../../src","sources":["MemoryWarningListener.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,cAAc;AAIvC,OAAO,SAASC,wBAAwBA,CAACC,IAAmB,EAAQ;EAClE,IAAIC,MAAM,CAACC,OAAO,IAAI,IAAI,IAAID,MAAM,CAACE,oBAAoB,IAAI,IAAI,EAAE;IACjE;IACA,MAAMC,QAAQ,GAAG,IAAIF,OAAO,CAACF,IAAI,CAAC;IAClC,MAAMK,QAAQ,GAAGP,QAAQ,CAACQ,gBAAgB,CAAC,eAAe,EAAE,MAAM;MAChE;MACAF,QAAQ,CAACG,KAAK,CAAC,CAAC,EAAEC,IAAI,CAAC,CAAC;IAC1B,CAAC,CAAC;IACF;IACA,MAAMC,YAAY,GAAG,IAAIN,oBAAoB,CAC1CO,CAA0B,IAAK;MAC9B;MACAA,CAAC,CAACC,MAAM,CAAC,CAAC;IACZ,CACF,CAAC;IACD;IACAF,YAAY,CAACG,QAAQ,CAACZ,IAAI,EAAEK,QAAQ,CAAC;EACvC,CAAC,MAAM;IACL;IACA;IACAP,QAAQ,CAACQ,gBAAgB,CAAC,eAAe,EAAE,MAAM;MAC/CN,IAAI,CAACQ,IAAI,CAAC,CAAC;IACb,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- export const addMemoryWarningListener = _mmkv => {
4
- //no-op function, there is not a web equivalent to memory warning
5
- };
6
- //# sourceMappingURL=MemoryWarningListener.web.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["addMemoryWarningListener","_mmkv"],"sourceRoot":"../../src","sources":["MemoryWarningListener.web.ts"],"mappings":";;AAEA,OAAO,MAAMA,wBAAwB,GAAIC,KAAoB,IAAW;EACtE;AAAA,CACD","ignoreList":[]}
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- import { NativeModules, Platform } from 'react-native';
4
- const BULLET_POINT = '\n* ';
5
- function messageWithSuggestions(message, suggestions) {
6
- return message + BULLET_POINT + suggestions.join(BULLET_POINT);
7
- }
8
- function getFrameworkType() {
9
- // check if Expo
10
- const ExpoConstants = NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;
11
- if (ExpoConstants != null) {
12
- if (ExpoConstants.appOwnership === 'expo') {
13
- // We're running Expo Go
14
- return 'expo-go';
15
- } else {
16
- // We're running Expo bare / standalone
17
- return 'expo';
18
- }
19
- }
20
- return 'react-native';
21
- }
22
- export class ModuleNotFoundError extends Error {
23
- constructor(cause) {
24
- // TurboModule not found, something went wrong!
25
- if (global.__turboModuleProxy == null) {
26
- // TurboModules are not available/new arch is not enabled.
27
- // react-native-mmkv 3.x.x requires new arch (react-native >0.74)
28
- // react-native-mmkv 2.x.x works on old arch (react-native <0.74)
29
- const message = 'Failed to create a new MMKV instance: react-native-mmkv 3.x.x requires TurboModules, but the new architecture is not enabled!';
30
- const suggestions = [];
31
- suggestions.push('Downgrade to react-native-mmkv 2.x.x if you want to stay on the old architecture.');
32
- suggestions.push('Enable the new architecture in your app to use react-native-mmkv 3.x.x. (See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md)');
33
- const error = messageWithSuggestions(message, suggestions);
34
- super(error, {
35
- cause: cause
36
- });
37
- return;
38
- }
39
- const framework = getFrameworkType();
40
- if (framework === 'expo-go') {
41
- super('react-native-mmkv is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.');
42
- return;
43
- }
44
- const message = 'Failed to create a new MMKV instance: The native MMKV Module could not be found.';
45
- const suggestions = [];
46
- suggestions.push('Make sure react-native-mmkv is correctly autolinked (run `npx react-native config` to verify)');
47
- suggestions.push('Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the react-native-mmkv specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md');
48
- suggestions.push('Make sure you are using react-native 0.74.0 or higher, because react-native-mmkv is a C++ TurboModule.');
49
- suggestions.push('Make sure you rebuilt the app.');
50
- if (framework === 'expo') {
51
- suggestions.push('Make sure you ran `expo prebuild`.');
52
- }
53
- switch (Platform.OS) {
54
- case 'ios':
55
- case 'macos':
56
- suggestions.push('Make sure you ran `pod install` in the ios/ directory.');
57
- break;
58
- case 'android':
59
- suggestions.push('Make sure gradle is synced.');
60
- break;
61
- default:
62
- throw new Error(`MMKV is not supported on ${Platform.OS}!`);
63
- }
64
- const error = messageWithSuggestions(message, suggestions);
65
- super(error, {
66
- cause: cause
67
- });
68
- }
69
- }
70
- //# sourceMappingURL=ModuleNotFoundError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["NativeModules","Platform","BULLET_POINT","messageWithSuggestions","message","suggestions","join","getFrameworkType","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","ModuleNotFoundError","Error","constructor","cause","global","__turboModuleProxy","push","error","framework","OS"],"sourceRoot":"../../src","sources":["ModuleNotFoundError.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAOtD,MAAMC,YAAY,GAAG,MAAM;AAE3B,SAASC,sBAAsBA,CAC7BC,OAAe,EACfC,WAAqB,EACb;EACR,OAAOD,OAAO,GAAGF,YAAY,GAAGG,WAAW,CAACC,IAAI,CAACJ,YAAY,CAAC;AAChE;AAEA,SAASK,gBAAgBA,CAAA,EAAwC;EAC/D;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WAAW,CAACc,IAAI,CACd,wDACF,CAAC;QACD;MACF,KAAK,SAAS;QACZd,WAAW,CAACc,IAAI,CAAC,6BAA6B,CAAC;QAC/C;MACF;QACE,MAAM,IAAIL,KAAK,CAAC,4BAA4Bb,QAAQ,CAACqB,EAAE,GAAG,CAAC;IAC/D;IAEA,MAAMF,KAAK,GAAGjB,sBAAsB,CAACC,OAAO,EAAEC,WAAW,CAAC;IAC1D,KAAK,CAACe,KAAK,EAAE;MAAEJ,KAAK,EAAEA;IAAM,CAAC,CAAC;EAChC;AACF","ignoreList":[]}
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- import { TurboModuleRegistry } from 'react-native';
4
- import { ModuleNotFoundError } from './ModuleNotFoundError';
5
- import { getMMKVPlatformContextTurboModule } from './NativeMmkvPlatformContext';
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
- */
12
- /**
13
- * Configures the mode of the MMKV instance.
14
- */
15
- export let Mode = /*#__PURE__*/function (Mode) {
16
- Mode[Mode["SINGLE_PROCESS"] = 0] = "SINGLE_PROCESS";
17
- Mode[Mode["MULTI_PROCESS"] = 1] = "MULTI_PROCESS";
18
- return Mode;
19
- }({});
20
-
21
- /**
22
- * Used for configuration of a single MMKV instance.
23
- */
24
-
25
- let mmkvModule;
26
- export function getMMKVTurboModule() {
27
- try {
28
- if (mmkvModule == null) {
29
- // 1. Load MMKV TurboModule
30
- mmkvModule = TurboModuleRegistry.getEnforcing('MmkvCxx');
31
-
32
- // 2. Get the PlatformContext TurboModule as well
33
- const platformContext = getMMKVPlatformContextTurboModule();
34
-
35
- // 3. Initialize it with the documents directory from platform-specific context
36
- const basePath = platformContext.getBaseDirectory();
37
- mmkvModule.initialize(basePath);
38
- }
39
- return mmkvModule;
40
- } catch (cause) {
41
- // TurboModule could not be found!
42
- throw new ModuleNotFoundError(cause);
43
- }
44
- }
45
- //# sourceMappingURL=NativeMmkv.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["TurboModuleRegistry","ModuleNotFoundError","getMMKVPlatformContextTurboModule","Mode","mmkvModule","getMMKVTurboModule","getEnforcing","platformContext","basePath","getBaseDirectory","initialize","cause"],"sourceRoot":"../../src","sources":["NativeMmkv.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAElD,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,iCAAiC,QAAQ,6BAA6B;;AAE/E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAYC,IAAI,0BAAJA,IAAI;EAAJA,IAAI,CAAJA,IAAI;EAAJA,IAAI,CAAJA,IAAI;EAAA,OAAJA,IAAI;AAAA;;AAWhB;AACA;AACA;;AAqEA,IAAIC,UAAuB;AAE3B,OAAO,SAASC,kBAAkBA,CAAA,EAAS;EACzC,IAAI;IACF,IAAID,UAAU,IAAI,IAAI,EAAE;MACtB;MACAA,UAAU,GAAGJ,mBAAmB,CAACM,YAAY,CAAO,SAAS,CAAC;;MAE9D;MACA,MAAMC,eAAe,GAAGL,iCAAiC,CAAC,CAAC;;MAE3D;MACA,MAAMM,QAAQ,GAAGD,eAAe,CAACE,gBAAgB,CAAC,CAAC;MACnDL,UAAU,CAACM,UAAU,CAACF,QAAQ,CAAC;IACjC;IAEA,OAAOJ,UAAU;EACnB,CAAC,CAAC,OAAOO,KAAK,EAAE;IACd;IACA,MAAM,IAAIV,mBAAmB,CAACU,KAAK,CAAC;EACtC;AACF","ignoreList":[]}
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- import { TurboModuleRegistry } from 'react-native';
4
- import { ModuleNotFoundError } from './ModuleNotFoundError';
5
- let mmkvPlatformModule;
6
- export function getMMKVPlatformContextTurboModule() {
7
- try {
8
- if (mmkvPlatformModule == null) {
9
- // 1. Get the TurboModule
10
- mmkvPlatformModule = TurboModuleRegistry.getEnforcing('MmkvPlatformContext');
11
- }
12
- return mmkvPlatformModule;
13
- } catch (e) {
14
- // TurboModule could not be found!
15
- throw new ModuleNotFoundError(e);
16
- }
17
- }
18
- //# sourceMappingURL=NativeMmkvPlatformContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["TurboModuleRegistry","ModuleNotFoundError","mmkvPlatformModule","getMMKVPlatformContextTurboModule","getEnforcing","e"],"sourceRoot":"../../src","sources":["NativeMmkvPlatformContext.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAClD,SAASC,mBAAmB,QAAQ,uBAAuB;AAoB3D,IAAIC,kBAA+B;AAEnC,OAAO,SAASC,iCAAiCA,CAAA,EAAS;EACxD,IAAI;IACF,IAAID,kBAAkB,IAAI,IAAI,EAAE;MAC9B;MACAA,kBAAkB,GAAGF,mBAAmB,CAACI,YAAY,CACnD,qBACF,CAAC;IACH;IACA,OAAOF,kBAAkB;EAC3B,CAAC,CAAC,OAAOG,CAAC,EAAE;IACV;IACA,MAAM,IAAIJ,mBAAmB,CAACI,CAAC,CAAC;EAClC;AACF","ignoreList":[]}
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- export function isTest() {
4
- if (global.process == null) {
5
- // In a WebBrowser/Electron the `process` variable does not exist
6
- return false;
7
- }
8
- return process.env.JEST_WORKER_ID != null || process.env.VITEST_WORKER_ID != null;
9
- }
10
- //# sourceMappingURL=PlatformChecker.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["isTest","global","process","env","JEST_WORKER_ID","VITEST_WORKER_ID"],"sourceRoot":"../../src","sources":["PlatformChecker.ts"],"mappings":";;AAAA,OAAO,SAASA,MAAMA,CAAA,EAAY;EAChC,IAAIC,MAAM,CAACC,OAAO,IAAI,IAAI,EAAE;IAC1B;IACA,OAAO,KAAK;EACd;EACA,OACEA,OAAO,CAACC,GAAG,CAACC,cAAc,IAAI,IAAI,IAAIF,OAAO,CAACC,GAAG,CAACE,gBAAgB,IAAI,IAAI;AAE9E","ignoreList":[]}
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * IMPORTANT: Some of these types are also in the NativeMmkv.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
- */
8
-
9
- /**
10
- * Configures the mode of the MMKV instance.
11
- */
12
- export let Mode = /*#__PURE__*/function (Mode) {
13
- Mode[Mode["SINGLE_PROCESS"] = 0] = "SINGLE_PROCESS";
14
- Mode[Mode["MULTI_PROCESS"] = 1] = "MULTI_PROCESS";
15
- return Mode;
16
- }({});
17
-
18
- /**
19
- * Used for configuration of a single MMKV instance.
20
- */
21
-
22
- /**
23
- * Represents a single MMKV instance.
24
- */
25
- //# sourceMappingURL=Types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["Mode"],"sourceRoot":"../../src","sources":["Types.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,WAAYA,IAAI,0BAAJA,IAAI;EAAJA,IAAI,CAAJA,IAAI;EAAJA,IAAI,CAAJA,IAAI;EAAA,OAAJA,IAAI;AAAA;;AAWhB;AACA;AACA;;AA0DA;AACA;AACA","ignoreList":[]}