react-native-mmkv 2.5.1 → 2.6.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.
Files changed (59) hide show
  1. package/MMKV/Core/MMKV.cpp +13 -0
  2. package/MMKV/Core/MMKVPredef.h +1 -1
  3. package/MMKV/Core/MMKV_IO.cpp +2 -0
  4. package/MMKV/Core/MMKV_OSX.cpp +7 -1
  5. package/README.md +1 -1
  6. package/android/CMakeLists.txt +14 -44
  7. package/android/build.gradle +61 -317
  8. package/android/gradle.properties +5 -3
  9. package/android/src/main/cpp/MmkvHostObject.cpp +1 -0
  10. package/ios/MmkvHostObject.mm +1 -0
  11. package/lib/commonjs/MMKV.js +5 -34
  12. package/lib/commonjs/MMKV.js.map +1 -1
  13. package/lib/commonjs/PlatformChecker.js +0 -2
  14. package/lib/commonjs/PlatformChecker.js.map +1 -1
  15. package/lib/commonjs/createMMKV.js +8 -19
  16. package/lib/commonjs/createMMKV.js.map +1 -1
  17. package/lib/commonjs/createMMKV.mock.js +0 -2
  18. package/lib/commonjs/createMMKV.mock.js.map +1 -1
  19. package/lib/commonjs/createMMKV.web.js +3 -20
  20. package/lib/commonjs/createMMKV.web.js.map +1 -1
  21. package/lib/commonjs/createTextEncoder.js +0 -1
  22. package/lib/commonjs/createTextEncoder.js.map +1 -1
  23. package/lib/commonjs/hooks.js +12 -27
  24. package/lib/commonjs/hooks.js.map +1 -1
  25. package/lib/commonjs/index.js +0 -4
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/module/MMKV.js +5 -29
  28. package/lib/module/MMKV.js.map +1 -1
  29. package/lib/module/PlatformChecker.js +0 -1
  30. package/lib/module/PlatformChecker.js.map +1 -1
  31. package/lib/module/createMMKV.js +8 -15
  32. package/lib/module/createMMKV.js.map +1 -1
  33. package/lib/module/createMMKV.mock.js.map +1 -1
  34. package/lib/module/createMMKV.web.js +4 -16
  35. package/lib/module/createMMKV.web.js.map +1 -1
  36. package/lib/module/createTextEncoder.js.map +1 -1
  37. package/lib/module/hooks.js +12 -23
  38. package/lib/module/hooks.js.map +1 -1
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/typescript/MMKV.d.ts +2 -1
  41. package/lib/typescript/MMKV.d.ts.map +1 -0
  42. package/lib/typescript/PlatformChecker.d.ts +1 -0
  43. package/lib/typescript/PlatformChecker.d.ts.map +1 -0
  44. package/lib/typescript/createMMKV.d.ts +1 -0
  45. package/lib/typescript/createMMKV.d.ts.map +1 -0
  46. package/lib/typescript/createMMKV.mock.d.ts +1 -0
  47. package/lib/typescript/createMMKV.mock.d.ts.map +1 -0
  48. package/lib/typescript/createMMKV.web.d.ts +1 -0
  49. package/lib/typescript/createMMKV.web.d.ts.map +1 -0
  50. package/lib/typescript/createTextEncoder.d.ts +1 -0
  51. package/lib/typescript/createTextEncoder.d.ts.map +1 -0
  52. package/lib/typescript/hooks.d.ts +5 -4
  53. package/lib/typescript/hooks.d.ts.map +1 -0
  54. package/lib/typescript/index.d.ts +1 -0
  55. package/lib/typescript/index.d.ts.map +1 -0
  56. package/package.json +15 -14
  57. package/MMKV/CHANGELOG.md +0 -553
  58. package/MMKV/LICENSE.TXT +0 -193
  59. package/MMKV/README.md +0 -288
@@ -39,6 +39,7 @@ std::vector<jsi::PropNameID> MmkvHostObject::getPropertyNames(jsi::Runtime& rt)
39
39
  std::vector<jsi::PropNameID> result;
40
40
  result.push_back(jsi::PropNameID::forUtf8(rt, std::string("set")));
41
41
  result.push_back(jsi::PropNameID::forUtf8(rt, std::string("getBoolean")));
42
+ result.push_back(jsi::PropNameID::forUtf8(rt, std::string("getBuffer")));
42
43
  result.push_back(jsi::PropNameID::forUtf8(rt, std::string("getString")));
43
44
  result.push_back(jsi::PropNameID::forUtf8(rt, std::string("getNumber")));
44
45
  result.push_back(jsi::PropNameID::forUtf8(rt, std::string("contains")));
@@ -44,6 +44,7 @@ std::vector<jsi::PropNameID> MmkvHostObject::getPropertyNames(jsi::Runtime& rt)
44
44
  std::vector<jsi::PropNameID> result;
45
45
  result.push_back(jsi::PropNameID::forUtf8(rt, std::string("set")));
46
46
  result.push_back(jsi::PropNameID::forUtf8(rt, std::string("getBoolean")));
47
+ result.push_back(jsi::PropNameID::forUtf8(rt, std::string("getBuffer")));
47
48
  result.push_back(jsi::PropNameID::forUtf8(rt, std::string("getString")));
48
49
  result.push_back(jsi::PropNameID::forUtf8(rt, std::string("getNumber")));
49
50
  result.push_back(jsi::PropNameID::forUtf8(rt, std::string("contains")));
@@ -4,143 +4,114 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.MMKV = void 0;
7
-
8
7
  var _createMMKV = require("./createMMKV");
9
-
10
8
  var _createMMKV2 = require("./createMMKV.mock");
11
-
12
9
  var _PlatformChecker = require("./PlatformChecker");
13
-
14
10
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
-
16
11
  const onValueChangedListeners = new Map();
12
+
17
13
  /**
18
14
  * A single MMKV instance.
19
15
  */
20
-
21
16
  class MMKV {
22
17
  /**
23
18
  * Creates a new MMKV instance with the given Configuration.
24
19
  * If no custom `id` is supplied, `'mmkv.default'` will be used.
25
20
  */
26
- constructor(configuration = {
27
- id: 'mmkv.default'
28
- }) {
21
+ constructor() {
22
+ let configuration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
23
+ id: 'mmkv.default'
24
+ };
29
25
  _defineProperty(this, "nativeInstance", void 0);
30
-
31
26
  _defineProperty(this, "functionCache", void 0);
32
-
33
27
  _defineProperty(this, "id", void 0);
34
-
35
28
  this.id = configuration.id;
36
29
  this.nativeInstance = (0, _PlatformChecker.isJest)() ? (0, _createMMKV2.createMockMMKV)() : (0, _createMMKV.createMMKV)(configuration);
37
30
  this.functionCache = {};
38
31
  }
39
-
40
32
  get onValueChangedListeners() {
41
33
  if (!onValueChangedListeners.has(this.id)) {
42
34
  onValueChangedListeners.set(this.id, []);
43
35
  }
44
-
45
36
  return onValueChangedListeners.get(this.id);
46
37
  }
47
-
48
38
  getFunctionFromCache(functionName) {
49
39
  if (this.functionCache[functionName] == null) {
50
40
  this.functionCache[functionName] = this.nativeInstance[functionName];
51
41
  }
52
-
53
42
  return this.functionCache[functionName];
54
43
  }
55
-
56
44
  onValuesChanged(keys) {
57
45
  if (this.onValueChangedListeners.length === 0) return;
58
-
59
46
  for (const key of keys) {
60
47
  for (const listener of this.onValueChangedListeners) {
61
48
  listener(key);
62
49
  }
63
50
  }
64
51
  }
65
-
66
52
  set(key, value) {
67
53
  const func = this.getFunctionFromCache('set');
68
54
  func(key, value);
69
55
  this.onValuesChanged([key]);
70
56
  }
71
-
72
57
  getBoolean(key) {
73
58
  const func = this.getFunctionFromCache('getBoolean');
74
59
  return func(key);
75
60
  }
76
-
77
61
  getString(key) {
78
62
  const func = this.getFunctionFromCache('getString');
79
63
  return func(key);
80
64
  }
81
-
82
65
  getNumber(key) {
83
66
  const func = this.getFunctionFromCache('getNumber');
84
67
  return func(key);
85
68
  }
86
-
87
69
  getBuffer(key) {
88
70
  const func = this.getFunctionFromCache('getBuffer');
89
71
  return func(key);
90
72
  }
91
-
92
73
  contains(key) {
93
74
  const func = this.getFunctionFromCache('contains');
94
75
  return func(key);
95
76
  }
96
-
97
77
  delete(key) {
98
78
  const func = this.getFunctionFromCache('delete');
99
79
  func(key);
100
80
  this.onValuesChanged([key]);
101
81
  }
102
-
103
82
  getAllKeys() {
104
83
  const func = this.getFunctionFromCache('getAllKeys');
105
84
  return func();
106
85
  }
107
-
108
86
  clearAll() {
109
87
  const keys = this.getAllKeys();
110
88
  const func = this.getFunctionFromCache('clearAll');
111
89
  func();
112
90
  this.onValuesChanged(keys);
113
91
  }
114
-
115
92
  recrypt(key) {
116
93
  const func = this.getFunctionFromCache('recrypt');
117
94
  return func(key);
118
95
  }
119
-
120
96
  toString() {
121
97
  return `MMKV (${this.id}): [${this.getAllKeys().join(', ')}]`;
122
98
  }
123
-
124
99
  toJSON() {
125
100
  return {
126
101
  [this.id]: this.getAllKeys()
127
102
  };
128
103
  }
129
-
130
104
  addOnValueChangedListener(onValueChanged) {
131
105
  this.onValueChangedListeners.push(onValueChanged);
132
106
  return {
133
107
  remove: () => {
134
108
  const index = this.onValueChangedListeners.indexOf(onValueChanged);
135
-
136
109
  if (index !== -1) {
137
110
  this.onValueChangedListeners.splice(index, 1);
138
111
  }
139
112
  }
140
113
  };
141
114
  }
142
-
143
115
  }
144
-
145
116
  exports.MMKV = MMKV;
146
117
  //# sourceMappingURL=MMKV.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["MMKV.ts"],"names":["onValueChangedListeners","Map","MMKV","constructor","configuration","id","nativeInstance","functionCache","has","set","get","getFunctionFromCache","functionName","onValuesChanged","keys","length","key","listener","value","func","getBoolean","getString","getNumber","getBuffer","contains","delete","getAllKeys","clearAll","recrypt","toString","join","toJSON","addOnValueChangedListener","onValueChanged","push","remove","index","indexOf","splice"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AA+HA,MAAMA,uBAAuB,GAAG,IAAIC,GAAJ,EAAhC;AAEA;AACA;AACA;;AACO,MAAMC,IAAN,CAAoC;AAKzC;AACF;AACA;AACA;AACEC,EAAAA,WAAW,CAACC,aAAgC,GAAG;AAAEC,IAAAA,EAAE,EAAE;AAAN,GAApC,EAA4D;AAAA;;AAAA;;AAAA;;AACrE,SAAKA,EAAL,GAAUD,aAAa,CAACC,EAAxB;AACA,SAAKC,cAAL,GAAsB,iCAClB,kCADkB,GAElB,4BAAWF,aAAX,CAFJ;AAGA,SAAKG,aAAL,GAAqB,EAArB;AACD;;AAEkC,MAAvBP,uBAAuB,GAAG;AACpC,QAAI,CAACA,uBAAuB,CAACQ,GAAxB,CAA4B,KAAKH,EAAjC,CAAL,EAA2C;AACzCL,MAAAA,uBAAuB,CAACS,GAAxB,CAA4B,KAAKJ,EAAjC,EAAqC,EAArC;AACD;;AACD,WAAOL,uBAAuB,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,WAAO;AACLE,MAAAA,MAAM,EAAE,MAAM;AACZ,cAAMC,KAAK,GAAG,KAAKpC,uBAAL,CAA6BqC,OAA7B,CAAqCJ,cAArC,CAAd;;AACA,YAAIG,KAAK,KAAK,CAAC,CAAf,EAAkB;AAChB,eAAKpC,uBAAL,CAA6BsC,MAA7B,CAAoCF,KAApC,EAA2C,CAA3C;AACD;AACF;AANI,KAAP;AAQD;;AAhHwC","sourcesContent":["import { createMMKV } from './createMMKV';\nimport { createMockMMKV } from './createMMKV.mock';\nimport { isJest } from './PlatformChecker';\n\ninterface Listener {\n remove: () => void;\n}\n\n/**\n * Used for configuration of a single MMKV instance.\n */\nexport interface MMKVConfiguration {\n /**\n * The MMKV instance's ID. If you want to use multiple instances, make sure to use different IDs!\n *\n * @example\n * ```ts\n * const userStorage = new MMKV({ id: `user-${userId}-storage` })\n * const globalStorage = new MMKV({ id: 'global-app-storage' })\n * ```\n *\n * @default 'mmkv.default'\n */\n id: string;\n /**\n * The MMKV instance's root path. By default, MMKV stores file inside `$(Documents)/mmkv/`. You can customize MMKV's root directory on MMKV initialization:\n *\n * @example\n * ```ts\n * const temporaryStorage = new MMKV({ path: '/tmp/' })\n * ```\n */\n path?: string;\n /**\n * 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.\n *\n * Encryption keys can have a maximum length of 16 bytes.\n *\n * @example\n * ```ts\n * const secureStorage = new MMKV({ encryptionKey: 'my-encryption-key!' })\n * ```\n */\n encryptionKey?: string;\n}\n\n/**\n * Represents a single MMKV instance.\n */\ninterface MMKVInterface {\n /**\n * Set a value for the given `key`.\n */\n set: (key: string, value: boolean | string | number | Uint8Array) => void;\n /**\n * Get the boolean value for the given `key`, or `undefined` if it does not exist.\n *\n * @default undefined\n */\n getBoolean: (key: string) => boolean | undefined;\n /**\n * Get the string value for the given `key`, or `undefined` if it does not exist.\n *\n * @default undefined\n */\n getString: (key: string) => string | undefined;\n /**\n * Get the number value for the given `key`, or `undefined` if it does not exist.\n *\n * @default undefined\n */\n getNumber: (key: string) => number | undefined;\n /**\n * Get a raw buffer of unsigned 8-bit (0-255) data.\n *\n * @default undefined\n */\n getBuffer: (key: string) => Uint8Array | undefined;\n /**\n * Checks whether the given `key` is being stored in this MMKV instance.\n */\n contains: (key: string) => boolean;\n /**\n * Delete the given `key`.\n */\n delete: (key: string) => void;\n /**\n * Get all keys.\n *\n * @default []\n */\n getAllKeys: () => string[];\n /**\n * Delete all keys.\n */\n clearAll: () => void;\n /**\n * Sets (or updates) the encryption-key to encrypt all data in this MMKV instance with.\n *\n * To remove encryption, pass `undefined` as a key.\n *\n * Encryption keys can have a maximum length of 16 bytes.\n */\n recrypt: (key: string | undefined) => void;\n /**\n * Adds a value changed listener. The Listener will be called whenever any value\n * in this storage instance changes (set or delete).\n *\n * To unsubscribe from value changes, call `remove()` on the Listener.\n */\n addOnValueChangedListener: (\n onValueChanged: (key: string) => void\n ) => Listener;\n}\n\nexport type NativeMMKV = Pick<\n MMKVInterface,\n | 'clearAll'\n | 'contains'\n | 'delete'\n | 'getAllKeys'\n | 'getBoolean'\n | 'getNumber'\n | 'getString'\n | 'getBuffer'\n | 'set'\n | 'recrypt'\n>;\n\nconst onValueChangedListeners = new Map<string, ((key: string) => void)[]>();\n\n/**\n * A single MMKV instance.\n */\nexport class MMKV implements MMKVInterface {\n private nativeInstance: NativeMMKV;\n private functionCache: Partial<NativeMMKV>;\n private id: string;\n\n /**\n * Creates a new MMKV instance with the given Configuration.\n * If no custom `id` is supplied, `'mmkv.default'` will be used.\n */\n constructor(configuration: MMKVConfiguration = { id: 'mmkv.default' }) {\n this.id = configuration.id;\n this.nativeInstance = isJest()\n ? createMockMMKV()\n : createMMKV(configuration);\n this.functionCache = {};\n }\n\n private get onValueChangedListeners() {\n if (!onValueChangedListeners.has(this.id)) {\n onValueChangedListeners.set(this.id, []);\n }\n return onValueChangedListeners.get(this.id)!;\n }\n\n private getFunctionFromCache<T extends keyof NativeMMKV>(\n functionName: T\n ): NativeMMKV[T] {\n if (this.functionCache[functionName] == null) {\n this.functionCache[functionName] = this.nativeInstance[functionName];\n }\n return this.functionCache[functionName] as NativeMMKV[T];\n }\n\n private onValuesChanged(keys: string[]) {\n if (this.onValueChangedListeners.length === 0) return;\n\n for (const key of keys) {\n for (const listener of this.onValueChangedListeners) {\n listener(key);\n }\n }\n }\n\n set(key: string, value: boolean | string | number | Uint8Array): void {\n const func = this.getFunctionFromCache('set');\n func(key, value);\n\n this.onValuesChanged([key]);\n }\n getBoolean(key: string): boolean | undefined {\n const func = this.getFunctionFromCache('getBoolean');\n return func(key);\n }\n getString(key: string): string | undefined {\n const func = this.getFunctionFromCache('getString');\n return func(key);\n }\n getNumber(key: string): number | undefined {\n const func = this.getFunctionFromCache('getNumber');\n return func(key);\n }\n getBuffer(key: string): Uint8Array | undefined {\n const func = this.getFunctionFromCache('getBuffer');\n return func(key);\n }\n contains(key: string): boolean {\n const func = this.getFunctionFromCache('contains');\n return func(key);\n }\n delete(key: string): void {\n const func = this.getFunctionFromCache('delete');\n func(key);\n\n this.onValuesChanged([key]);\n }\n getAllKeys(): string[] {\n const func = this.getFunctionFromCache('getAllKeys');\n return func();\n }\n clearAll(): void {\n const keys = this.getAllKeys();\n\n const func = this.getFunctionFromCache('clearAll');\n func();\n\n this.onValuesChanged(keys);\n }\n recrypt(key: string | undefined): void {\n const func = this.getFunctionFromCache('recrypt');\n return func(key);\n }\n\n toString(): string {\n return `MMKV (${this.id}): [${this.getAllKeys().join(', ')}]`;\n }\n toJSON(): object {\n return {\n [this.id]: this.getAllKeys(),\n };\n }\n\n addOnValueChangedListener(onValueChanged: (key: string) => void): Listener {\n this.onValueChangedListeners.push(onValueChanged);\n\n return {\n remove: () => {\n const index = this.onValueChangedListeners.indexOf(onValueChanged);\n if (index !== -1) {\n this.onValueChangedListeners.splice(index, 1);\n }\n },\n };\n }\n}\n"]}
1
+ {"version":3,"names":["onValueChangedListeners","Map","MMKV","constructor","configuration","id","nativeInstance","isJest","createMockMMKV","createMMKV","functionCache","has","set","get","getFunctionFromCache","functionName","onValuesChanged","keys","length","key","listener","value","func","getBoolean","getString","getNumber","getBuffer","contains","delete","getAllKeys","clearAll","recrypt","toString","join","toJSON","addOnValueChangedListener","onValueChanged","push","remove","index","indexOf","splice"],"sourceRoot":"../../src","sources":["MMKV.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AAA2C;AA+H3C,MAAMA,uBAAuB,GAAG,IAAIC,GAAG,EAAqC;;AAE5E;AACA;AACA;AACO,MAAMC,IAAI,CAA0B;EAKzC;AACF;AACA;AACA;EACEC,WAAW,GAA4D;IAAA,IAA3DC,aAAgC,uEAAG;MAAEC,EAAE,EAAE;IAAe,CAAC;IAAA;IAAA;IAAA;IACnE,IAAI,CAACA,EAAE,GAAGD,aAAa,CAACC,EAAE;IAC1B,IAAI,CAACC,cAAc,GAAG,IAAAC,uBAAM,GAAE,GAC1B,IAAAC,2BAAc,GAAE,GAChB,IAAAC,sBAAU,EAACL,aAAa,CAAC;IAC7B,IAAI,CAACM,aAAa,GAAG,CAAC,CAAC;EACzB;EAEA,IAAYV,uBAAuB,GAAG;IACpC,IAAI,CAACA,uBAAuB,CAACW,GAAG,CAAC,IAAI,CAACN,EAAE,CAAC,EAAE;MACzCL,uBAAuB,CAACY,GAAG,CAAC,IAAI,CAACP,EAAE,EAAE,EAAE,CAAC;IAC1C;IACA,OAAOL,uBAAuB,CAACa,GAAG,CAAC,IAAI,CAACR,EAAE,CAAC;EAC7C;EAEQS,oBAAoB,CAC1BC,YAAe,EACA;IACf,IAAI,IAAI,CAACL,aAAa,CAACK,YAAY,CAAC,IAAI,IAAI,EAAE;MAC5C,IAAI,CAACL,aAAa,CAACK,YAAY,CAAC,GAAG,IAAI,CAACT,cAAc,CAACS,YAAY,CAAC;IACtE;IACA,OAAO,IAAI,CAACL,aAAa,CAACK,YAAY,CAAC;EACzC;EAEQC,eAAe,CA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
5
5
  });
6
6
  exports.isJest = isJest;
7
-
8
7
  function isJest() {
9
8
  if (global.process == null) {
10
9
  // In a WebBrowser/Electron the `process` variable does not exist
11
10
  return false;
12
11
  }
13
-
14
12
  return process.env.JEST_WORKER_ID != null;
15
13
  }
16
14
  //# sourceMappingURL=PlatformChecker.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["PlatformChecker.ts"],"names":["isJest","global","process","env","JEST_WORKER_ID"],"mappings":";;;;;;;AAAO,SAASA,MAAT,GAA2B;AAChC,MAAIC,MAAM,CAACC,OAAP,IAAkB,IAAtB,EAA4B;AAC1B;AACA,WAAO,KAAP;AACD;;AACD,SAAOA,OAAO,CAACC,GAAR,CAAYC,cAAZ,IAA8B,IAArC;AACD","sourcesContent":["export function isJest(): boolean {\n if (global.process == null) {\n // In a WebBrowser/Electron the `process` variable does not exist\n return false;\n }\n return process.env.JEST_WORKER_ID != null;\n}\n"]}
1
+ {"version":3,"names":["isJest","global","process","env","JEST_WORKER_ID"],"sourceRoot":"../../src","sources":["PlatformChecker.ts"],"mappings":";;;;;;AAAO,SAASA,MAAM,GAAY;EAChC,IAAIC,MAAM,CAACC,OAAO,IAAI,IAAI,EAAE;IAC1B;IACA,OAAO,KAAK;EACd;EACA,OAAOA,OAAO,CAACC,GAAG,CAACC,cAAc,IAAI,IAAI;AAC3C"}
@@ -4,35 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createMMKV = void 0;
7
-
8
7
  var _reactNative = require("react-native");
9
-
10
8
  // Root directory of all MMKV stores
11
9
  const ROOT_DIRECTORY = null;
12
-
13
10
  const createMMKV = config => {
14
11
  // Check if the constructor exists. If not, try installing the JSI bindings.
15
12
  if (global.mmkvCreateNewInstance == null) {
16
13
  // Get the native MMKV ReactModule
17
14
  const MMKVModule = _reactNative.NativeModules.MMKV;
18
-
19
15
  if (MMKVModule == null) {
20
16
  var _NativeModules$Native, _NativeModules$Native2;
21
-
22
17
  let message = 'Failed to create a new MMKV instance: The native MMKV Module could not be found.';
23
18
  message += '\n* Make sure react-native-mmkv is correctly autolinked (run `npx react-native config` to verify)';
24
-
25
19
  if (_reactNative.Platform.OS === 'ios' || _reactNative.Platform.OS === 'macos') {
26
20
  message += '\n* Make sure you ran `pod install` in the ios/ directory.';
27
21
  }
28
-
29
22
  if (_reactNative.Platform.OS === 'android') {
30
23
  message += '\n* Make sure gradle is synced.';
31
- } // check if Expo
32
-
33
-
24
+ }
25
+ // check if Expo
34
26
  const ExpoConstants = (_NativeModules$Native = _reactNative.NativeModules.NativeUnimoduleProxy) === null || _NativeModules$Native === void 0 ? void 0 : (_NativeModules$Native2 = _NativeModules$Native.modulesConstants) === null || _NativeModules$Native2 === void 0 ? void 0 : _NativeModules$Native2.ExponentConstants;
35
-
36
27
  if (ExpoConstants != null) {
37
28
  if (ExpoConstants.appOwnership === 'expo') {
38
29
  // We're running Expo Go
@@ -42,25 +33,23 @@ const createMMKV = config => {
42
33
  message += '\n* Make sure you ran `expo prebuild`.';
43
34
  }
44
35
  }
45
-
46
36
  message += '\n* Make sure you rebuilt the app.';
47
37
  throw new Error(message);
48
- } // Check if we are running on-device (JSI)
49
-
38
+ }
50
39
 
40
+ // Check if we are running on-device (JSI)
51
41
  if (global.nativeCallSyncHook == null || MMKVModule.install == null) {
52
42
  throw new Error('Failed to create a new MMKV instance: React Native is not running on-device. MMKV can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.');
53
- } // Call the synchronous blocking install() function
54
-
43
+ }
55
44
 
45
+ // Call the synchronous blocking install() function
56
46
  const result = MMKVModule.install(ROOT_DIRECTORY);
57
- if (result !== true) throw new Error(`Failed to create a new MMKV instance: The native MMKV Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`); // Check again if the constructor now exists. If not, throw an error.
47
+ if (result !== true) throw new Error(`Failed to create a new MMKV instance: The native MMKV Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`);
58
48
 
49
+ // Check again if the constructor now exists. If not, throw an error.
59
50
  if (global.mmkvCreateNewInstance == null) throw new Error('Failed to create a new MMKV instance, the native initializer function does not exist. Are you trying to use MMKV from different JS Runtimes?');
60
51
  }
61
-
62
52
  return global.mmkvCreateNewInstance(config);
63
53
  };
64
-
65
54
  exports.createMMKV = createMMKV;
66
55
  //# sourceMappingURL=createMMKV.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["createMMKV.ts"],"names":["ROOT_DIRECTORY","createMMKV","config","global","mmkvCreateNewInstance","MMKVModule","NativeModules","MMKV","message","Platform","OS","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","Error","nativeCallSyncHook","install","result"],"mappings":";;;;;;;AAAA;;AASA;AACA,MAAMA,cAA6B,GAAG,IAAtC;;AAEO,MAAMC,UAAU,GAAIC,MAAD,IAA2C;AACnE;AACA,MAAIC,MAAM,CAACC,qBAAP,IAAgC,IAApC,EAA0C;AACxC;AACA,UAAMC,UAAU,GAAGC,2BAAcC,IAAjC;;AACA,QAAIF,UAAU,IAAI,IAAlB,EAAwB;AAAA;;AACtB,UAAIG,OAAO,GACT,kFADF;AAEAA,MAAAA,OAAO,IACL,mGADF;;AAEA,UAAIC,sBAASC,EAAT,KAAgB,KAAhB,IAAyBD,sBAASC,EAAT,KAAgB,OAA7C,EAAsD;AACpDF,QAAAA,OAAO,IAAI,4DAAX;AACD;;AACD,UAAIC,sBAASC,EAAT,KAAgB,SAApB,EAA+B;AAC7BF,QAAAA,OAAO,IAAI,iCAAX;AACD,OAVqB,CAWtB;;;AACA,YAAMG,aAAa,4BACjBL,2BAAcM,oBADG,oFACjB,sBAAoCC,gBADnB,2DACjB,uBAAsDC,iBADxD;;AAEA,UAAIH,aAAa,IAAI,IAArB,EAA2B;AACzB,YAAIA,aAAa,CAACI,YAAd,KAA+B,MAAnC,EAA2C;AACzC;AACA,gBAAM,IAAIC,KAAJ,CACJ,+GADI,CAAN;AAGD,SALD,MAKO;AACL;AACAR,UAAAA,OAAO,IAAI,wCAAX;AACD;AACF;;AAEDA,MAAAA,OAAO,IAAI,oCAAX;AACA,YAAM,IAAIQ,KAAJ,CAAUR,OAAV,CAAN;AACD,KA/BuC,CAiCxC;;;AACA,QAAIL,MAAM,CAACc,kBAAP,IAA6B,IAA7B,IAAqCZ,UAAU,CAACa,OAAX,IAAsB,IAA/D,EAAqE;AACnE,YAAM,IAAIF,KAAJ,CACJ,sQADI,CAAN;AAGD,KAtCuC,CAwCxC;;;AACA,UAAMG,MAAM,GAAGd,UAAU,CAACa,OAAX,CAAmBlB,cAAnB,CAAf;AACA,QAAImB,MAAM,KAAK,IAAf,EACE,MAAM,IAAIH,KAAJ,CACH,sJAAqJG,MAAO,EADzJ,CAAN,CA3CsC,CA+CxC;;AACA,QAAIhB,MAAM,CAACC,qBAAP,IAAgC,IAApC,EACE,MAAM,IAAIY,KAAJ,CACJ,8IADI,CAAN;AAGH;;AAED,SAAOb,MAAM,CAACC,qBAAP,CAA6BF,MAA7B,CAAP;AACD,CAzDM","sourcesContent":["import { NativeModules, Platform } from 'react-native';\nimport type { MMKVConfiguration, NativeMMKV } from 'react-native-mmkv';\n\n// global func declaration for JSI functions\ndeclare global {\n function mmkvCreateNewInstance(configuration: MMKVConfiguration): NativeMMKV;\n function nativeCallSyncHook(): unknown;\n}\n\n// Root directory of all MMKV stores\nconst ROOT_DIRECTORY: string | null = null;\n\nexport const createMMKV = (config: MMKVConfiguration): NativeMMKV => {\n // Check if the constructor exists. If not, try installing the JSI bindings.\n if (global.mmkvCreateNewInstance == null) {\n // Get the native MMKV ReactModule\n const MMKVModule = NativeModules.MMKV;\n if (MMKVModule == null) {\n let message =\n 'Failed to create a new MMKV instance: The native MMKV Module could not be found.';\n message +=\n '\\n* Make sure react-native-mmkv is correctly autolinked (run `npx react-native config` to verify)';\n if (Platform.OS === 'ios' || Platform.OS === 'macos') {\n message += '\\n* Make sure you ran `pod install` in the ios/ directory.';\n }\n if (Platform.OS === 'android') {\n message += '\\n* Make sure gradle is synced.';\n }\n // check if Expo\n const ExpoConstants =\n NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;\n if (ExpoConstants != null) {\n if (ExpoConstants.appOwnership === 'expo') {\n // We're running Expo Go\n throw new Error(\n 'react-native-mmkv is not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.'\n );\n } else {\n // We're running Expo bare / standalone\n message += '\\n* Make sure you ran `expo prebuild`.';\n }\n }\n\n message += '\\n* Make sure you rebuilt the app.';\n throw new Error(message);\n }\n\n // Check if we are running on-device (JSI)\n if (global.nativeCallSyncHook == null || MMKVModule.install == null) {\n throw new Error(\n 'Failed to create a new MMKV instance: React Native is not running on-device. MMKV can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'\n );\n }\n\n // Call the synchronous blocking install() function\n const result = MMKVModule.install(ROOT_DIRECTORY);\n if (result !== true)\n throw new Error(\n `Failed to create a new MMKV instance: The native MMKV Module could not be installed! Looks like something went wrong when installing JSI bindings: ${result}`\n );\n\n // Check again if the constructor now exists. If not, throw an error.\n if (global.mmkvCreateNewInstance == null)\n throw new Error(\n 'Failed to create a new MMKV instance, the native initializer function does not exist. Are you trying to use MMKV from different JS Runtimes?'\n );\n }\n\n return global.mmkvCreateNewInstance(config);\n};\n"]}
1
+ {"version":3,"names":["ROOT_DIRECTORY","createMMKV","config","global","mmkvCreateNewInstance","MMKVModule","NativeModules","MMKV","message","Platform","OS","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","Error","nativeCallSyncHook","install","result"],"sourceRoot":"../../src","sources":["createMMKV.ts"],"mappings":";;;;;;AAAA;AASA;AACA,MAAMA,cAA6B,GAAG,IAAI;AAEnC,MAAMC,UAAU,GAAIC,MAAyB,IAAiB;EACnE;EACA,IAAIC,MAAM,CAACC,qBAAqB,IAAI,IAAI,EAAE;IACxC;IACA,MAAM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 Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createMockMMKV = void 0;
7
-
8
7
  /* Mock MMKV instance for use in tests */
9
8
  const createMockMMKV = () => {
10
9
  const storage = new Map();
@@ -35,6 +34,5 @@ const createMockMMKV = () => {
35
34
  }
36
35
  };
37
36
  };
38
-
39
37
  exports.createMockMMKV = createMockMMKV;
40
38
  //# sourceMappingURL=createMMKV.mock.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["createMMKV.mock.ts"],"names":["createMockMMKV","storage","Map","clearAll","clear","delete","key","set","value","getString","result","get","undefined","getNumber","getBoolean","getBuffer","Uint8Array","getAllKeys","Array","from","keys","contains","has","recrypt","console","warn"],"mappings":";;;;;;;AAEA;AACO,MAAMA,cAAc,GAAG,MAAkB;AAC9C,QAAMC,OAAO,GAAG,IAAIC,GAAJ,EAAhB;AAEA,SAAO;AACLC,IAAAA,QAAQ,EAAE,MAAMF,OAAO,CAACG,KAAR,EADX;AAELC,IAAAA,MAAM,EAAGC,GAAD,IAASL,OAAO,CAACI,MAAR,CAAeC,GAAf,CAFZ;AAGLC,IAAAA,GAAG,EAAE,CAACD,GAAD,EAAME,KAAN,KAAgBP,OAAO,CAACM,GAAR,CAAYD,GAAZ,EAAiBE,KAAjB,CAHhB;AAILC,IAAAA,SAAS,EAAGH,GAAD,IAAS;AAClB,YAAMI,MAAM,GAAGT,OAAO,CAACU,GAAR,CAAYL,GAAZ,CAAf;AACA,aAAO,OAAOI,MAAP,KAAkB,QAAlB,GAA6BA,MAA7B,GAAsCE,SAA7C;AACD,KAPI;AAQLC,IAAAA,SAAS,EAAGP,GAAD,IAAS;AAClB,YAAMI,MAAM,GAAGT,OAAO,CAACU,GAAR,CAAYL,GAAZ,CAAf;AACA,aAAO,OAAOI,MAAP,KAAkB,QAAlB,GAA6BA,MAA7B,GAAsCE,SAA7C;AACD,KAXI;AAYLE,IAAAA,UAAU,EAAGR,GAAD,IAAS;AACnB,YAAMI,MAAM,GAAGT,OAAO,CAACU,GAAR,CAAYL,GAAZ,CAAf;AACA,aAAO,OAAOI,MAAP,KAAkB,SAAlB,GAA8BA,MAA9B,GAAuCE,SAA9C;AACD,KAfI;AAgBLG,IAAAA,SAAS,EAAGT,GAAD,IAAS;AAClB,YAAMI,MAAM,GAAGT,OAAO,CAACU,GAAR,CAAYL,GAAZ,CAAf;AACA,aAAOI,MAAM,YAAYM,UAAlB,GAA+BN,MAA/B,GAAwCE,SAA/C;AACD,KAnBI;AAoBLK,IAAAA,UAAU,EAAE,MAAMC,KAAK,CAACC,IAAN,CAAWlB,OAAO,CAACmB,IAAR,EAAX,CApBb;AAqBLC,IAAAA,QAAQ,EAAGf,GAAD,IAASL,OAAO,CAACqB,GAAR,CAAYhB,GAAZ,CArBd;AAsBLiB,IAAAA,OAAO,EAAE,MAAM;AACbC,MAAAA,OAAO,CAACC,IAAR,CAAa,uDAAb;AACD;AAxBI,GAAP;AA0BD,CA7BM","sourcesContent":["import type { NativeMMKV } from 'react-native-mmkv';\n\n/* Mock MMKV instance for use in tests */\nexport const createMockMMKV = (): NativeMMKV => {\n const storage = new Map<string, string | boolean | number | Uint8Array>();\n\n return {\n clearAll: () => storage.clear(),\n delete: (key) => storage.delete(key),\n set: (key, value) => storage.set(key, value),\n getString: (key) => {\n const result = storage.get(key);\n return typeof result === 'string' ? result : undefined;\n },\n getNumber: (key) => {\n const result = storage.get(key);\n return typeof result === 'number' ? result : undefined;\n },\n getBoolean: (key) => {\n const result = storage.get(key);\n return typeof result === 'boolean' ? result : undefined;\n },\n getBuffer: (key) => {\n const result = storage.get(key);\n return result instanceof Uint8Array ? result : undefined;\n },\n getAllKeys: () => Array.from(storage.keys()),\n contains: (key) => storage.has(key),\n recrypt: () => {\n console.warn('Encryption is not supported in mocked MMKV instances!');\n },\n };\n};\n"]}
1
+ {"version":3,"names":["createMockMMKV","storage","Map","clearAll","clear","delete","key","set","value","getString","result","get","undefined","getNumber","getBoolean","getBuffer","Uint8Array","getAllKeys","Array","from","keys","contains","has","recrypt","console","warn"],"sourceRoot":"../../src","sources":["createMMKV.mock.ts"],"mappings":";;;;;;AAEA;AACO,MAAMA,cAAc,GAAG,MAAkB;EAC9C,MAAMC,OAAO,GAAG,IAAIC,GAAG,EAAkD;EAEzE,OAAO;IACLC,QAAQ,EAAE,MAAMF,OAAO,CAACG,KAAK,EAAE;IAC/BC,MAAM,EAAGC,GAAG,IAAKL,OAAO,CAACI,MAAM,CAACC,GAAG,CAAC;IACpCC,GAAG,EAAE,CAACD,GAAG,EAAEE,KAAK,KAAKP,OAAO,CAACM,GAAG,CAACD,GAAG,EAAEE,KAAK,CAAC;IAC5CC,SAAS,EAAGH,GAAG,IAAK;MAClB,MAAMI,MAAM,GAAGT,OAAO,CAACU,GAAG,CAACL,GAAG,CAAC;MAC/B,OAAO,OAAOI,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAGE,SAAS;IACxD,CAAC;IACDC,SAAS,EAAGP,GAAG,IAAK;MAClB,MAAMI,MAAM,GAAGT,OAAO,CAACU,GAAG,CAACL,GAAG,CAAC;MAC/B,OAAO,OAAOI,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAGE,SAAS;IACxD,CAAC;IACDE,UAAU,EAAGR,GAAG,IAAK;MACnB,MAAMI,MAAM,GAAGT,OAAO,CAACU,GAAG,CAACL,GAAG,CAAC;MAC/B,OAAO,OAAOI,MAAM,KAAK,SAAS,GAAGA,MAAM,GAAGE,SAAS;IACzD,CAAC;IACDG,SAAS,EAAGT,GAAG,IAAK;MAClB,MAAMI,MAAM,GAAGT,OAAO,CAACU,GAAG,CAACL,GAAG,CAAC;MAC/B,OAAOI,MAAM,YAAYM,UAAU,GAAGN,MAAM,GAAGE,SAAS;IAC1D,CAAC;IACDK,UAAU,EAAE,MAAMC,KAAK,CAACC,IAAI,CAAClB,OAAO,CAACmB,IAAI,EAAE,CAAC;IAC5CC,QAAQ,EAAGf,GAAG,IAAKL,OAAO,CAACqB,GAAG,CAAChB,GAAG,CAAC;IACnCiB,OAAO,EAAE,MAAM;MACbC,OAAO,CAACC,IAAI,CAAC,uDAAuD,CAAC;IACvE;EACF,CAAC;AACH,CAAC;AAAC"}
@@ -4,52 +4,36 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createMMKV = void 0;
7
-
8
7
  var _createTextEncoder = require("./createTextEncoder");
9
-
10
8
  var _window$document;
11
-
12
9
  const canUseDOM = typeof window !== 'undefined' && ((_window$document = window.document) === null || _window$document === void 0 ? void 0 : _window$document.createElement) != null;
13
-
14
10
  const createMMKV = config => {
15
11
  if (config.id !== 'mmkv.default') {
16
12
  throw new Error("MMKV: 'id' is not supported on Web!");
17
13
  }
18
-
19
14
  if (config.encryptionKey != null) {
20
15
  throw new Error("MMKV: 'encryptionKey' is not supported on Web!");
21
16
  }
22
-
23
17
  if (config.path != null) {
24
18
  throw new Error("MMKV: 'path' is not supported on Web!");
25
19
  }
26
-
27
20
  const storage = () => {
28
- var _ref, _global$localStorage, _global, _window;
29
-
21
+ var _global, _window;
30
22
  if (!canUseDOM) {
31
23
  throw new Error('Tried to access storage on the server. Did you forget to call this in useEffect?');
32
24
  }
33
-
34
- const domStorage = (_ref = (_global$localStorage = (_global = global) === null || _global === void 0 ? void 0 : _global.localStorage) !== null && _global$localStorage !== void 0 ? _global$localStorage : (_window = window) === null || _window === void 0 ? void 0 : _window.localStorage) !== null && _ref !== void 0 ? _ref : localStorage;
35
-
25
+ const domStorage = ((_global = global) === null || _global === void 0 ? void 0 : _global.localStorage) ?? ((_window = window) === null || _window === void 0 ? void 0 : _window.localStorage) ?? localStorage;
36
26
  if (domStorage == null) {
37
27
  throw new Error(`Could not find 'localStorage' instance!`);
38
28
  }
39
-
40
29
  return domStorage;
41
30
  };
42
-
43
31
  const textEncoder = (0, _createTextEncoder.createTextEncoder)();
44
32
  return {
45
33
  clearAll: () => storage().clear(),
46
34
  delete: key => storage().removeItem(key),
47
35
  set: (key, value) => storage().setItem(key, value.toString()),
48
- getString: key => {
49
- var _storage$getItem;
50
-
51
- return (_storage$getItem = storage().getItem(key)) !== null && _storage$getItem !== void 0 ? _storage$getItem : undefined;
52
- },
36
+ getString: key => storage().getItem(key) ?? undefined,
53
37
  getNumber: key => {
54
38
  const value = storage().getItem(key);
55
39
  if (value == null) return undefined;
@@ -72,6 +56,5 @@ const createMMKV = config => {
72
56
  }
73
57
  };
74
58
  };
75
-
76
59
  exports.createMMKV = createMMKV;
77
60
  //# sourceMappingURL=createMMKV.web.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["createMMKV.web.ts"],"names":["canUseDOM","window","document","createElement","createMMKV","config","id","Error","encryptionKey","path","storage","domStorage","global","localStorage","textEncoder","clearAll","clear","delete","key","removeItem","set","value","setItem","toString","getString","getItem","undefined","getNumber","Number","getBoolean","getBuffer","encode","getAllKeys","Object","keys","contains","recrypt"],"mappings":";;;;;;;AAEA;;;;AAEA,MAAMA,SAAS,GACb,OAAOC,MAAP,KAAkB,WAAlB,IAAiC,qBAAAA,MAAM,CAACC,QAAP,sEAAiBC,aAAjB,KAAkC,IADrE;;AAGO,MAAMC,UAAU,GAAIC,MAAD,IAA2C;AACnE,MAAIA,MAAM,CAACC,EAAP,KAAc,cAAlB,EAAkC;AAChC,UAAM,IAAIC,KAAJ,CAAU,qCAAV,CAAN;AACD;;AACD,MAAIF,MAAM,CAACG,aAAP,IAAwB,IAA5B,EAAkC;AAChC,UAAM,IAAID,KAAJ,CAAU,gDAAV,CAAN;AACD;;AACD,MAAIF,MAAM,CAACI,IAAP,IAAe,IAAnB,EAAyB;AACvB,UAAM,IAAIF,KAAJ,CAAU,uCAAV,CAAN;AACD;;AAED,QAAMG,OAAO,GAAG,MAAM;AAAA;;AACpB,QAAI,CAACV,SAAL,EAAgB;AACd,YAAM,IAAIO,KAAJ,CACJ,kFADI,CAAN;AAGD;;AACD,UAAMI,UAAU,8CACdC,MADc,4CACd,QAAQC,YADM,kFACUZ,MADV,4CACU,QAAQY,YADlB,u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,EAAE,MAAMC,MAAM,CAACC,IAAP,CAAYxB,OAAO,EAAnB,CApBb;AAqBLyB,IAAAA,QAAQ,EAAGjB,GAAD,IAASR,OAAO,GAAGe,OAAV,CAAkBP,GAAlB,KAA0B,IArBxC;AAsBLkB,IAAAA,OAAO,EAAE,MAAM;AACb,YAAM,IAAI7B,KAAJ,CAAU,wCAAV,CAAN;AACD;AAxBI,GAAP;AA0BD,CArDM","sourcesContent":["/* global localStorage */\nimport type { MMKVConfiguration, NativeMMKV } from 'react-native-mmkv';\nimport { createTextEncoder } from './createTextEncoder';\n\nconst canUseDOM =\n typeof window !== 'undefined' && window.document?.createElement != null;\n\nexport const createMMKV = (config: MMKVConfiguration): NativeMMKV => {\n if (config.id !== 'mmkv.default') {\n throw new Error(\"MMKV: 'id' is not supported on Web!\");\n }\n if (config.encryptionKey != null) {\n throw new Error(\"MMKV: 'encryptionKey' is not supported on Web!\");\n }\n if (config.path != null) {\n throw new Error(\"MMKV: 'path' is not supported on Web!\");\n }\n\n const storage = () => {\n if (!canUseDOM) {\n throw new Error(\n 'Tried to access storage on the server. Did you forget to call this in useEffect?'\n );\n }\n const domStorage =\n global?.localStorage ?? window?.localStorage ?? localStorage;\n if (domStorage == null) {\n throw new Error(`Could not find 'localStorage' instance!`);\n }\n return domStorage;\n };\n\n const textEncoder = createTextEncoder();\n\n return {\n clearAll: () => storage().clear(),\n delete: (key) => storage().removeItem(key),\n set: (key, value) => storage().setItem(key, value.toString()),\n getString: (key) => storage().getItem(key) ?? undefined,\n getNumber: (key) => {\n const value = storage().getItem(key);\n if (value == null) return undefined;\n return Number(value);\n },\n getBoolean: (key) => {\n const value = storage().getItem(key);\n if (value == null) return undefined;\n return value === 'true';\n },\n getBuffer: (key) => {\n const value = storage().getItem(key);\n if (value == null) return undefined;\n return textEncoder.encode(value);\n },\n getAllKeys: () => Object.keys(storage()),\n contains: (key) => storage().getItem(key) != null,\n recrypt: () => {\n throw new Error('`recrypt(..)` is not supported on Web!');\n },\n };\n};\n"]}
1
+ {"version":3,"names":["canUseDOM","window","document","createElement","createMMKV","config","id","Error","encryptionKey","path","storage","domStorage","global","localStorage","textEncoder","createTextEncoder","clearAll","clear","delete","key","removeItem","set","value","setItem","toString","getString","getItem","undefined","getNumber","Number","getBoolean","getBuffer","encode","getAllKeys","Object","keys","contains","recrypt"],"sourceRoot":"../../src","sources":["createMMKV.web.ts"],"mappings":";;;;;;AAEA;AAAwD;AAExD,MAAMA,SAAS,GACb,OAAOC,MAAM,KAAK,WAAW,IAAI,qBAAAA,MAAM,CAACC,QAAQ,qDAAf,iBAAiBC,aAAa,KAAI,IAAI;AAElE,MAAMC,UAAU,GAAIC,MAAyB,IAAiB;EACnE,IAAIA,MAAM,CAACC,EAAE,KAAK,cAAc,EAAE;IAChC,MAAM,IAAIC,KAAK,CAAC,qCAAqC,CAAC;EACxD;EACA,IAAIF,MAAM,CAACG,aAAa,IAAI,IAAI,EAAE;IAChC,MAAM,IAAID,KAAK,CAAC,gDAAgD,CAAC;EACnE;EACA,IAAIF,MAAM,CAACI,IAAI,IAAI,IAAI,EAAE;IACvB,MAAM,IAAIF,KAAK,CAAC,uCAAuC,CAAC;EAC1D;EAEA,MAAMG,OAAO,GAAG,MAAM;IAAA;IACpB,IAAI,CAACV,SAAS,EAAE;MACd,MAAM,IAAIO,KAAK,CACb,kFAAkF,CACnF;IACH;IACA,MAAMI,UAAU,GACd,YAAAC,MAAM,4CAAN,QAAQC,YAAY,iBAAIZ,MAAM,4CAAN,QAAQY,YAAY,KAAIA,YAAY;IAC9D,IAAIF,UAAU,IAAI,IAAI,EAAE;MACtB,MAAM,IAAIJ,KAAK,CAAE,yCAAwC,CAAC;IAC5D;IACA,OAAOI,UAAU;EACnB,CAAC;EAED,MAAMG,WAAW,GAAG,IAAAC,oCAAiB,GAAE;EAEvC,OAAO;IACLC,QAAQ,EAAE,MAAMN,OAAO,EAAE,CAACO,KAAK,EAAE;IACjCC,MAAM,EAAGC,GAAG,IAAKT,OAAO,EA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oder;
7
-
8
7
  /* global TextEncoder */
9
8
  function createTextEncoder() {
10
9
  if (global.TextEncoder != null) {
@@ -1 +1 @@
1
- {"version":3,"sources":["createTextEncoder.ts"],"names":["createTextEncoder","global","TextEncoder","encode","Error","encodeInto","encoding"],"mappings":";;;;;;;AAAA;AACO,SAASA,iBAAT,GAA0C;AAC/C,MAAIC,MAAM,CAACC,WAAP,IAAsB,IAA1B,EAAgC;AAC9B,WAAO,IAAID,MAAM,CAACC,WAAX,EAAP;AACD,GAFD,MAEO;AACL,WAAO;AACLC,MAAAA,MAAM,EAAE,MAAM;AACZ,cAAM,IAAIC,KAAJ,CAAU,mDAAV,CAAN;AACD,OAHI;AAILC,MAAAA,UAAU,EAAE,MAAM;AAChB,cAAM,IAAID,KAAJ,CAAU,mDAAV,CAAN;AACD,OANI;AAOLE,MAAAA,QAAQ,EAAE;AAPL,KAAP;AASD;AACF","sourcesContent":["/* global TextEncoder */\nexport function createTextEncoder(): TextEncoder {\n if (global.TextEncoder != null) {\n return new global.TextEncoder();\n } else {\n return {\n encode: () => {\n throw new Error('TextEncoder is not supported in this environment!');\n },\n encodeInto: () => {\n throw new Error('TextEncoder is not supported in this environment!');\n },\n encoding: 'utf-8',\n };\n }\n}\n"]}
1
+ {"version":3,"names":["createTextEncoder","global","TextEncoder","encode","Error","encodeInto","encoding"],"sourceRoot":"../../src","sources":["createTextEncoder.ts"],"mappings":";;;;;;AAAA;AACO,SAASA,iBAAiB,GAAgB;EAC/C,IAAIC,MAAM,CAACC,WAAW,IAAI,IAAI,EAAE;IAC9B,OAAO,IAAID,MAAM,CAACC,WAAW,EAAE;EACjC,CAAC,MAAM;IACL,OAAO;MACLC,MAAM,EAAE,MAAM;QACZ,MAAM,IAAIC,KAAK,CAAC,mDAAmD,CAAC;MACtE,CAAC;MACDC,UAAU,EAAE,MAAM;QAChB,MAAM,IAAID,KAAK,CAAC,mDAAmD,CAAC;MACtE,CAAC;MACDE,QAAQ,EAAE;IACZ,CAAC;EACH;AACF"}
@@ -9,73 +9,64 @@ exports.useMMKVListener = useMMKVListener;
9
9
  exports.useMMKVNumber = void 0;
10
10
  exports.useMMKVObject = useMMKVObject;
11
11
  exports.useMMKVString = void 0;
12
-
13
12
  var _react = require("react");
14
-
15
13
  var _MMKV = require("./MMKV");
16
-
17
14
  function isConfigurationEqual(left, right) {
18
15
  if (left == null || right == null) return left == null && right == null;
19
16
  return left.encryptionKey === right.encryptionKey && left.id === right.id && left.path === right.path;
20
17
  }
21
-
22
18
  let defaultInstance = null;
23
-
24
19
  function getDefaultInstance() {
25
20
  if (defaultInstance == null) {
26
21
  defaultInstance = new _MMKV.MMKV();
27
22
  }
28
-
29
23
  return defaultInstance;
30
24
  }
25
+
31
26
  /**
32
27
  * Use the default, shared MMKV instance.
33
28
  */
34
29
 
35
-
36
30
  function useMMKV(configuration) {
37
31
  const instance = (0, _react.useRef)();
38
32
  const lastConfiguration = (0, _react.useRef)();
39
33
  if (configuration == null) return getDefaultInstance();
40
-
41
34
  if (instance.current == null || !isConfigurationEqual(lastConfiguration.current, configuration)) {
42
35
  lastConfiguration.current = configuration;
43
36
  instance.current = new _MMKV.MMKV(configuration);
44
37
  }
45
-
46
38
  return instance.current;
47
39
  }
48
-
49
40
  function createMMKVHook(getter) {
50
41
  return (key, instance) => {
51
- const mmkv = instance !== null && instance !== void 0 ? instance : getDefaultInstance();
42
+ const mmkv = instance ?? getDefaultInstance();
52
43
  const [value, setValue] = (0, _react.useState)(() => getter(mmkv, key));
53
44
  const valueRef = (0, _react.useRef)(value);
54
- valueRef.current = value; // update value by user set
45
+ valueRef.current = value;
55
46
 
47
+ // update value by user set
56
48
  const set = (0, _react.useCallback)(v => {
57
49
  const newValue = typeof v === 'function' ? v(valueRef.current) : v;
58
-
59
50
  switch (typeof newValue) {
60
51
  case 'number':
61
52
  case 'string':
62
53
  case 'boolean':
63
54
  mmkv.set(key, newValue);
64
55
  break;
65
-
66
56
  case 'undefined':
67
57
  mmkv.delete(key);
68
58
  break;
69
-
70
59
  default:
71
60
  throw new Error(`MMKV: Type ${typeof newValue} is not supported!`);
72
61
  }
73
- }, [key, mmkv]); // update value if key or instance changes
62
+ }, [key, mmkv]);
74
63
 
64
+ // update value if key or instance changes
75
65
  (0, _react.useEffect)(() => {
76
66
  setValue(getter(mmkv, key));
77
- }, [key, mmkv]); // update value if it changes somewhere else (second hook, same key)
67
+ }, [key, mmkv]);
78
68
 
69
+ // update value if it changes somewhere else (second hook, same key)
79
70
  (0, _react.useEffect)(() => {
80
71
  const listener = mmkv.addOnValueChangedListener(changedKey => {
81
72
  if (changedKey === key) {
@@ -87,6 +78,7 @@ function createMMKVHook(getter) {
87
78
  return [value, set];
88
79
  };
89
80
  }
81
+
90
82
  /**
91
83
  * Use the string value of the given `key` from the given MMKV storage instance.
92
84
  *
@@ -97,9 +89,8 @@ function createMMKVHook(getter) {
97
89
  * const [username, setUsername] = useMMKVString("user.name")
98
90
  * ```
99
91
  */
100
-
101
-
102
92
  const useMMKVString = createMMKVHook((instance, key) => instance.getString(key));
93
+
103
94
  /**
104
95
  * Use the number value of the given `key` from the given MMKV storage instance.
105
96
  *
@@ -110,7 +101,6 @@ const useMMKVString = createMMKVHook((instance, key) => instance.getString(key))
110
101
  * const [age, setAge] = useMMKVNumber("user.age")
111
102
  * ```
112
103
  */
113
-
114
104
  exports.useMMKVString = useMMKVString;
115
105
  const useMMKVNumber = createMMKVHook((instance, key) => instance.getNumber(key));
116
106
  /**
@@ -123,7 +113,6 @@ const useMMKVNumber = createMMKVHook((instance, key) => instance.getNumber(key))
123
113
  * const [isPremiumAccount, setIsPremiumAccount] = useMMKVBoolean("user.isPremium")
124
114
  * ```
125
115
  */
126
-
127
116
  exports.useMMKVNumber = useMMKVNumber;
128
117
  const useMMKVBoolean = createMMKVHook((instance, key) => instance.getBoolean(key));
129
118
  /**
@@ -136,7 +125,6 @@ const useMMKVBoolean = createMMKVHook((instance, key) => instance.getBoolean(key
136
125
  * const [privateKey, setPrivateKey] = useMMKVBuffer("user.privateKey")
137
126
  * ```
138
127
  */
139
-
140
128
  exports.useMMKVBoolean = useMMKVBoolean;
141
129
  const useMMKVBuffer = createMMKVHook((instance, key) => instance.getBuffer(key));
142
130
  /**
@@ -151,9 +139,7 @@ const useMMKVBuffer = createMMKVHook((instance, key) => instance.getBuffer(key))
151
139
  * const [user, setUser] = useMMKVObject<User>("user")
152
140
  * ```
153
141
  */
154
-
155
142
  exports.useMMKVBuffer = useMMKVBuffer;
156
-
157
143
  function useMMKVObject(key, instance) {
158
144
  const [string, setString] = useMMKVString(key, instance);
159
145
  const value = (0, _react.useMemo)(() => {
@@ -171,6 +157,7 @@ function useMMKVObject(key, instance) {
171
157
  }, [setString]);
172
158
  return [value, setValue];
173
159
  }
160
+
174
161
  /**
175
162
  * Listen for changes in the given MMKV storage instance.
176
163
  * If no instance is passed, the default instance will be used.
@@ -184,12 +171,10 @@ function useMMKVObject(key, instance) {
184
171
  * })
185
172
  * ```
186
173
  */
187
-
188
-
189
174
  function useMMKVListener(valueChangedListener, instance) {
190
175
  const ref = (0, _react.useRef)(valueChangedListener);
191
176
  ref.current = valueChangedListener;
192
- const mmkv = instance !== null && instance !== void 0 ? instance : getDefaultInstance();
177
+ const mmkv = instance ?? getDefaultInstance();
193
178
  (0, _react.useEffect)(() => {
194
179
  const listener = mmkv.addOnValueChangedListener(changedKey => {
195
180
  ref.current(changedKey);