@react-native-async-storage/async-storage
Advanced tools
Comparing version 1.18.2 to 1.19.0
@@ -7,7 +7,4 @@ "use strict"; | ||
exports.default = void 0; | ||
var _mergeOptions = _interopRequireDefault(require("merge-options")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -20,3 +17,5 @@ * Copyright (c) Nicolas Gallagher. | ||
*/ | ||
// @ts-ignore Cannot find module 'merge-options' or its corresponding type declarations | ||
const merge = _mergeOptions.default.bind({ | ||
@@ -26,6 +25,4 @@ concatArrays: true, | ||
}); | ||
function mergeLocalStorageItem(key, value) { | ||
const oldValue = window.localStorage.getItem(key); | ||
if (oldValue) { | ||
@@ -40,3 +37,2 @@ const oldObject = JSON.parse(oldValue); | ||
} | ||
function createPromise(getValue, callback) { | ||
@@ -54,3 +50,2 @@ return new Promise((resolve, reject) => { | ||
} | ||
function createPromiseAll(promises, callback, processResult) { | ||
@@ -66,3 +61,2 @@ return Promise.all(promises).then(result => { | ||
} | ||
const AsyncStorage = { | ||
@@ -75,3 +69,2 @@ /** | ||
}, | ||
/** | ||
@@ -83,3 +76,2 @@ * Sets `value` for `key`. | ||
}, | ||
/** | ||
@@ -91,3 +83,2 @@ * Removes a `key` | ||
}, | ||
/** | ||
@@ -99,3 +90,2 @@ * Merges existing value with input value, assuming they are stringified JSON. | ||
}, | ||
/** | ||
@@ -107,3 +97,2 @@ * Erases *all* AsyncStorage for the domain. | ||
}, | ||
/** | ||
@@ -116,3 +105,2 @@ * Gets *all* keys known to the app, for all callers, libraries, etc. | ||
const keys = []; | ||
for (let i = 0; i < numberOfKeys; i += 1) { | ||
@@ -122,7 +110,5 @@ const key = window.localStorage.key(i) || ''; | ||
} | ||
return keys; | ||
}, callback); | ||
}, | ||
/** | ||
@@ -132,3 +118,2 @@ * (stub) Flushes any pending requests using a single batch call to get the data. | ||
flushGetRequests: () => undefined, | ||
/** | ||
@@ -142,8 +127,5 @@ * multiGet resolves to an array of key-value pair arrays that matches the | ||
const promises = keys.map(key => AsyncStorage.getItem(key)); | ||
const processResult = result => result.map((value, i) => [keys[i], value]); | ||
return createPromiseAll(promises, callback, processResult); | ||
}, | ||
/** | ||
@@ -157,3 +139,2 @@ * Takes an array of key-value array pairs. | ||
}, | ||
/** | ||
@@ -166,3 +147,2 @@ * Delete all the keys in the `keys` array. | ||
}, | ||
/** | ||
@@ -169,0 +149,0 @@ * Takes an array of key-value array pairs and merges them with existing |
@@ -7,9 +7,5 @@ "use strict"; | ||
exports.default = void 0; | ||
var _helpers = require("./helpers"); | ||
var _RCTAsyncStorage = _interopRequireDefault(require("./RCTAsyncStorage")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -21,2 +17,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. | ||
*/ | ||
if (!_RCTAsyncStorage.default) { | ||
@@ -38,2 +35,3 @@ throw new Error(`[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null. | ||
} | ||
/** | ||
@@ -46,4 +44,2 @@ * `AsyncStorage` is a simple, unencrypted, asynchronous, persistent, key-value | ||
*/ | ||
const AsyncStorage = (() => { | ||
@@ -62,6 +58,4 @@ let _getRequests = []; | ||
(0, _helpers.checkValidInput)(key); | ||
_RCTAsyncStorage.default.multiGet([key], (errors, result) => { | ||
var _result$; | ||
// Unpack result to get value from [[key,value]] | ||
@@ -71,3 +65,2 @@ const value = result !== null && result !== void 0 && (_result$ = result[0]) !== null && _result$ !== void 0 && _result$[1] ? result[0][1] : null; | ||
callback === null || callback === void 0 ? void 0 : callback(errs === null || errs === void 0 ? void 0 : errs[0], value); | ||
if (errs) { | ||
@@ -81,3 +74,2 @@ reject(errs[0]); | ||
}, | ||
/** | ||
@@ -91,7 +83,5 @@ * Sets the value for a `key` and invokes a callback upon completion. | ||
(0, _helpers.checkValidInput)(key, value); | ||
_RCTAsyncStorage.default.multiSet([[key, value]], errors => { | ||
const errs = (0, _helpers.convertErrors)(errors); | ||
callback === null || callback === void 0 ? void 0 : callback(errs === null || errs === void 0 ? void 0 : errs[0]); | ||
if (errs) { | ||
@@ -105,3 +95,2 @@ reject(errs[0]); | ||
}, | ||
/** | ||
@@ -115,7 +104,5 @@ * Removes an item for a `key` and invokes a callback upon completion. | ||
(0, _helpers.checkValidInput)(key); | ||
_RCTAsyncStorage.default.multiRemove([key], errors => { | ||
const errs = (0, _helpers.convertErrors)(errors); | ||
callback === null || callback === void 0 ? void 0 : callback(errs === null || errs === void 0 ? void 0 : errs[0]); | ||
if (errs) { | ||
@@ -129,3 +116,2 @@ reject(errs[0]); | ||
}, | ||
/** | ||
@@ -140,7 +126,5 @@ * Merges an existing `key` value with an input value, assuming both values | ||
(0, _helpers.checkValidInput)(key, value); | ||
_RCTAsyncStorage.default.multiMerge([[key, value]], errors => { | ||
const errs = (0, _helpers.convertErrors)(errors); | ||
callback === null || callback === void 0 ? void 0 : callback(errs === null || errs === void 0 ? void 0 : errs[0]); | ||
if (errs) { | ||
@@ -154,3 +138,2 @@ reject(errs[0]); | ||
}, | ||
/** | ||
@@ -168,3 +151,2 @@ * Erases *all* `AsyncStorage` for all clients, libraries, etc. You probably | ||
callback === null || callback === void 0 ? void 0 : callback(err); | ||
if (err) { | ||
@@ -178,3 +160,2 @@ reject(err); | ||
}, | ||
/** | ||
@@ -190,3 +171,2 @@ * Gets *all* keys known to your app; for all callers, libraries, etc. | ||
callback === null || callback === void 0 ? void 0 : callback(err, keys); | ||
if (keys) { | ||
@@ -200,3 +180,2 @@ resolve(keys); | ||
}, | ||
/** | ||
@@ -222,3 +201,2 @@ * The following batched functions are useful for executing a lot of | ||
_getKeys = []; | ||
_RCTAsyncStorage.default.multiGet(getKeys, (errors, result) => { | ||
@@ -238,2 +216,3 @@ // Even though the runtime complexity of this is theoretically worse vs if we used a map, | ||
const reqLength = getRequests.length; | ||
/** | ||
@@ -248,14 +227,9 @@ * As mentioned few lines above, this method could be called with the array of potential error, | ||
*/ | ||
const errorList = (0, _helpers.convertErrors)(errors); | ||
const error = errorList !== null && errorList !== void 0 && errorList.length ? errorList[0] : null; | ||
for (let i = 0; i < reqLength; i++) { | ||
var _request$callback2, _request$resolve; | ||
const request = getRequests[i]; | ||
if (error) { | ||
var _request$callback, _request$reject; | ||
(_request$callback = request.callback) === null || _request$callback === void 0 ? void 0 : _request$callback.call(request, errorList); | ||
@@ -265,3 +239,2 @@ (_request$reject = request.reject) === null || _request$reject === void 0 ? void 0 : _request$reject.call(request, error); | ||
} | ||
const requestResult = request.keys.map(key => [key, map[key]]); | ||
@@ -273,3 +246,2 @@ (_request$callback2 = request.callback) === null || _request$callback2 === void 0 ? void 0 : _request$callback2.call(request, null, requestResult); | ||
}, | ||
/** | ||
@@ -289,3 +261,2 @@ * This allows you to batch the fetching of items given an array of `key` | ||
} | ||
const getRequest = { | ||
@@ -303,6 +274,4 @@ keys: keys, | ||
}); | ||
_getRequests.push(getRequest); // avoid fetching duplicates | ||
_getRequests.push(getRequest); | ||
// avoid fetching duplicates | ||
keys.forEach(key => { | ||
@@ -315,3 +284,2 @@ if (_getKeys.indexOf(key) === -1) { | ||
}, | ||
/** | ||
@@ -330,7 +298,5 @@ * Use this as a batch operation for storing multiple key-value pairs. When | ||
}); | ||
_RCTAsyncStorage.default.multiSet(keyValuePairs, errors => { | ||
const error = (0, _helpers.convertErrors)(errors); | ||
callback === null || callback === void 0 ? void 0 : callback(error); | ||
if (error) { | ||
@@ -344,3 +310,2 @@ reject(error); | ||
}, | ||
/** | ||
@@ -354,7 +319,5 @@ * Call this to batch the deletion of all keys in the `keys` array. | ||
keys.forEach(key => (0, _helpers.checkValidInput)(key)); | ||
_RCTAsyncStorage.default.multiRemove(keys, errors => { | ||
const error = (0, _helpers.convertErrors)(errors); | ||
callback === null || callback === void 0 ? void 0 : callback(error); | ||
if (error) { | ||
@@ -368,3 +331,2 @@ reject(error); | ||
}, | ||
/** | ||
@@ -381,3 +343,2 @@ * Batch operation to merge in existing and new values for a given set of | ||
callback === null || callback === void 0 ? void 0 : callback(error); | ||
if (error) { | ||
@@ -393,5 +354,4 @@ reject(error); | ||
})(); | ||
var _default = AsyncStorage; | ||
exports.default = _default; | ||
//# sourceMappingURL=AsyncStorage.native.js.map |
@@ -10,3 +10,2 @@ "use strict"; | ||
exports.convertErrors = convertErrors; | ||
function checkValidArgs(keyValuePairs, callback) { | ||
@@ -16,3 +15,2 @@ if (!Array.isArray(keyValuePairs) || keyValuePairs.length === 0 || !Array.isArray(keyValuePairs[0])) { | ||
} | ||
if (callback && typeof callback !== 'function') { | ||
@@ -22,7 +20,5 @@ if (Array.isArray(callback)) { | ||
} | ||
throw new Error('[AsyncStorage] Expected function as second argument to multiSet'); | ||
} | ||
} | ||
function checkValidInput() { | ||
@@ -32,9 +28,6 @@ for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) { | ||
} | ||
const [key, value] = input; | ||
if (typeof key !== 'string') { | ||
console.warn(`[AsyncStorage] Using ${typeof key} type for key is not supported. This can lead to unexpected behavior/errors. Use string instead.\nKey passed: ${key}\n`); | ||
} | ||
if (input.length > 1 && typeof value !== 'string') { | ||
@@ -48,3 +41,2 @@ if (value == null) { | ||
} | ||
function convertError(error) { | ||
@@ -54,3 +46,2 @@ if (!error) { | ||
} | ||
const out = new Error(error.message); | ||
@@ -60,3 +51,2 @@ out.key = error.key; | ||
} | ||
function convertErrors(errs) { | ||
@@ -66,3 +56,2 @@ const errors = ensureArray(errs); | ||
} | ||
function ensureArray(e) { | ||
@@ -69,0 +58,0 @@ if (Array.isArray(e)) { |
@@ -7,7 +7,4 @@ "use strict"; | ||
exports.useAsyncStorage = useAsyncStorage; | ||
var _AsyncStorage = _interopRequireDefault(require("./AsyncStorage")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function useAsyncStorage(key) { | ||
@@ -19,3 +16,2 @@ return { | ||
} | ||
return _AsyncStorage.default.getItem(key, ...args); | ||
@@ -27,3 +23,2 @@ }, | ||
} | ||
return _AsyncStorage.default.setItem(key, ...args); | ||
@@ -35,3 +30,2 @@ }, | ||
} | ||
return _AsyncStorage.default.mergeItem(key, ...args); | ||
@@ -43,3 +37,2 @@ }, | ||
} | ||
return _AsyncStorage.default.removeItem(key, ...args); | ||
@@ -46,0 +39,0 @@ } |
@@ -13,11 +13,7 @@ "use strict"; | ||
}); | ||
var _AsyncStorage = _interopRequireDefault(require("./AsyncStorage")); | ||
var _hooks = require("./hooks"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _default = _AsyncStorage.default; | ||
exports.default = _default; | ||
//# sourceMappingURL=index.js.map |
@@ -7,15 +7,14 @@ "use strict"; | ||
exports.default = void 0; | ||
var _reactNative = require("react-native"); | ||
var _shouldFallbackToLegacyNativeModule = require("./shouldFallbackToLegacyNativeModule"); | ||
// @ts-ignore Module '"react-native"' has no exported member 'TurboModuleRegistry'. | ||
// @ts-ignore Module '"react-native"' has no exported member 'TurboModuleRegistry'. | ||
// TurboModuleRegistry falls back to NativeModules so we don't have to try go | ||
// assign NativeModules' counterparts if TurboModuleRegistry would resolve | ||
// with undefined. | ||
let RCTAsyncStorage = _reactNative.TurboModuleRegistry ? _reactNative.TurboModuleRegistry.get('PlatformLocalStorage') || // Support for external modules, like react-native-windows | ||
_reactNative.TurboModuleRegistry.get('RNC_AsyncSQLiteDBStorage') || _reactNative.TurboModuleRegistry.get('RNCAsyncStorage') : _reactNative.NativeModules['PlatformLocalStorage'] || // Support for external modules, like react-native-windows | ||
let RCTAsyncStorage = _reactNative.TurboModuleRegistry ? _reactNative.TurboModuleRegistry.get('PlatformLocalStorage') || | ||
// Support for external modules, like react-native-windows | ||
_reactNative.TurboModuleRegistry.get('RNC_AsyncSQLiteDBStorage') || _reactNative.TurboModuleRegistry.get('RNCAsyncStorage') : _reactNative.NativeModules['PlatformLocalStorage'] || | ||
// Support for external modules, like react-native-windows | ||
_reactNative.NativeModules['RNC_AsyncSQLiteDBStorage'] || _reactNative.NativeModules['RNCAsyncStorage']; | ||
if (!RCTAsyncStorage && (0, _shouldFallbackToLegacyNativeModule.shouldFallbackToLegacyNativeModule)()) { | ||
@@ -28,5 +27,4 @@ if (_reactNative.TurboModuleRegistry) { | ||
} | ||
var _default = RCTAsyncStorage; | ||
exports.default = _default; | ||
//# sourceMappingURL=RCTAsyncStorage.js.map |
@@ -7,10 +7,6 @@ "use strict"; | ||
exports.shouldFallbackToLegacyNativeModule = shouldFallbackToLegacyNativeModule; | ||
var _reactNative = require("react-native"); | ||
function shouldFallbackToLegacyNativeModule() { | ||
var _NativeModules$Native, _NativeModules$Native2; | ||
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; | ||
if (expoConstants) { | ||
@@ -23,2 +19,3 @@ /** | ||
const isLegacySdkVersion = expoConstants.appOwnership && !expoConstants.executionEnvironment; | ||
/** | ||
@@ -33,3 +30,2 @@ * Expo managed apps don't include the @react-native-async-storage/async-storage | ||
*/ | ||
if (isLegacySdkVersion || ['storeClient', 'standalone'].includes(expoConstants.executionEnvironment)) { | ||
@@ -39,5 +35,4 @@ return true; | ||
} | ||
return false; | ||
} | ||
//# sourceMappingURL=shouldFallbackToLegacyNativeModule.js.map |
@@ -8,2 +8,3 @@ /** | ||
*/ | ||
// @ts-ignore Cannot find module 'merge-options' or its corresponding type declarations | ||
@@ -15,6 +16,4 @@ import mergeOptions from 'merge-options'; | ||
}); | ||
function mergeLocalStorageItem(key, value) { | ||
const oldValue = window.localStorage.getItem(key); | ||
if (oldValue) { | ||
@@ -29,3 +28,2 @@ const oldObject = JSON.parse(oldValue); | ||
} | ||
function createPromise(getValue, callback) { | ||
@@ -43,3 +41,2 @@ return new Promise((resolve, reject) => { | ||
} | ||
function createPromiseAll(promises, callback, processResult) { | ||
@@ -55,3 +52,2 @@ return Promise.all(promises).then(result => { | ||
} | ||
const AsyncStorage = { | ||
@@ -64,3 +60,2 @@ /** | ||
}, | ||
/** | ||
@@ -72,3 +67,2 @@ * Sets `value` for `key`. | ||
}, | ||
/** | ||
@@ -80,3 +74,2 @@ * Removes a `key` | ||
}, | ||
/** | ||
@@ -88,3 +81,2 @@ * Merges existing value with input value, assuming they are stringified JSON. | ||
}, | ||
/** | ||
@@ -96,3 +88,2 @@ * Erases *all* AsyncStorage for the domain. | ||
}, | ||
/** | ||
@@ -105,3 +96,2 @@ * Gets *all* keys known to the app, for all callers, libraries, etc. | ||
const keys = []; | ||
for (let i = 0; i < numberOfKeys; i += 1) { | ||
@@ -111,7 +101,5 @@ const key = window.localStorage.key(i) || ''; | ||
} | ||
return keys; | ||
}, callback); | ||
}, | ||
/** | ||
@@ -121,3 +109,2 @@ * (stub) Flushes any pending requests using a single batch call to get the data. | ||
flushGetRequests: () => undefined, | ||
/** | ||
@@ -131,8 +118,5 @@ * multiGet resolves to an array of key-value pair arrays that matches the | ||
const promises = keys.map(key => AsyncStorage.getItem(key)); | ||
const processResult = result => result.map((value, i) => [keys[i], value]); | ||
return createPromiseAll(promises, callback, processResult); | ||
}, | ||
/** | ||
@@ -146,3 +130,2 @@ * Takes an array of key-value array pairs. | ||
}, | ||
/** | ||
@@ -155,3 +138,2 @@ * Delete all the keys in the `keys` array. | ||
}, | ||
/** | ||
@@ -158,0 +140,0 @@ * Takes an array of key-value array pairs and merges them with existing |
@@ -7,5 +7,5 @@ /** | ||
*/ | ||
import { checkValidArgs, checkValidInput, convertError, convertErrors } from './helpers'; | ||
import RCTAsyncStorage from './RCTAsyncStorage'; | ||
if (!RCTAsyncStorage) { | ||
@@ -27,2 +27,3 @@ throw new Error(`[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null. | ||
} | ||
/** | ||
@@ -35,4 +36,2 @@ * `AsyncStorage` is a simple, unencrypted, asynchronous, persistent, key-value | ||
*/ | ||
const AsyncStorage = (() => { | ||
@@ -53,3 +52,2 @@ let _getRequests = []; | ||
var _result$; | ||
// Unpack result to get value from [[key,value]] | ||
@@ -59,3 +57,2 @@ const value = result !== null && result !== void 0 && (_result$ = result[0]) !== null && _result$ !== void 0 && _result$[1] ? result[0][1] : null; | ||
callback === null || callback === void 0 ? void 0 : callback(errs === null || errs === void 0 ? void 0 : errs[0], value); | ||
if (errs) { | ||
@@ -69,3 +66,2 @@ reject(errs[0]); | ||
}, | ||
/** | ||
@@ -82,3 +78,2 @@ * Sets the value for a `key` and invokes a callback upon completion. | ||
callback === null || callback === void 0 ? void 0 : callback(errs === null || errs === void 0 ? void 0 : errs[0]); | ||
if (errs) { | ||
@@ -92,3 +87,2 @@ reject(errs[0]); | ||
}, | ||
/** | ||
@@ -105,3 +99,2 @@ * Removes an item for a `key` and invokes a callback upon completion. | ||
callback === null || callback === void 0 ? void 0 : callback(errs === null || errs === void 0 ? void 0 : errs[0]); | ||
if (errs) { | ||
@@ -115,3 +108,2 @@ reject(errs[0]); | ||
}, | ||
/** | ||
@@ -129,3 +121,2 @@ * Merges an existing `key` value with an input value, assuming both values | ||
callback === null || callback === void 0 ? void 0 : callback(errs === null || errs === void 0 ? void 0 : errs[0]); | ||
if (errs) { | ||
@@ -139,3 +130,2 @@ reject(errs[0]); | ||
}, | ||
/** | ||
@@ -153,3 +143,2 @@ * Erases *all* `AsyncStorage` for all clients, libraries, etc. You probably | ||
callback === null || callback === void 0 ? void 0 : callback(err); | ||
if (err) { | ||
@@ -163,3 +152,2 @@ reject(err); | ||
}, | ||
/** | ||
@@ -175,3 +163,2 @@ * Gets *all* keys known to your app; for all callers, libraries, etc. | ||
callback === null || callback === void 0 ? void 0 : callback(err, keys); | ||
if (keys) { | ||
@@ -185,3 +172,2 @@ resolve(keys); | ||
}, | ||
/** | ||
@@ -221,2 +207,3 @@ * The following batched functions are useful for executing a lot of | ||
const reqLength = getRequests.length; | ||
/** | ||
@@ -231,14 +218,9 @@ * As mentioned few lines above, this method could be called with the array of potential error, | ||
*/ | ||
const errorList = convertErrors(errors); | ||
const error = errorList !== null && errorList !== void 0 && errorList.length ? errorList[0] : null; | ||
for (let i = 0; i < reqLength; i++) { | ||
var _request$callback2, _request$resolve; | ||
const request = getRequests[i]; | ||
if (error) { | ||
var _request$callback, _request$reject; | ||
(_request$callback = request.callback) === null || _request$callback === void 0 ? void 0 : _request$callback.call(request, errorList); | ||
@@ -248,3 +230,2 @@ (_request$reject = request.reject) === null || _request$reject === void 0 ? void 0 : _request$reject.call(request, error); | ||
} | ||
const requestResult = request.keys.map(key => [key, map[key]]); | ||
@@ -256,3 +237,2 @@ (_request$callback2 = request.callback) === null || _request$callback2 === void 0 ? void 0 : _request$callback2.call(request, null, requestResult); | ||
}, | ||
/** | ||
@@ -272,3 +252,2 @@ * This allows you to batch the fetching of items given an array of `key` | ||
} | ||
const getRequest = { | ||
@@ -286,6 +265,4 @@ keys: keys, | ||
}); | ||
_getRequests.push(getRequest); // avoid fetching duplicates | ||
_getRequests.push(getRequest); | ||
// avoid fetching duplicates | ||
keys.forEach(key => { | ||
@@ -298,3 +275,2 @@ if (_getKeys.indexOf(key) === -1) { | ||
}, | ||
/** | ||
@@ -316,3 +292,2 @@ * Use this as a batch operation for storing multiple key-value pairs. When | ||
callback === null || callback === void 0 ? void 0 : callback(error); | ||
if (error) { | ||
@@ -326,3 +301,2 @@ reject(error); | ||
}, | ||
/** | ||
@@ -339,3 +313,2 @@ * Call this to batch the deletion of all keys in the `keys` array. | ||
callback === null || callback === void 0 ? void 0 : callback(error); | ||
if (error) { | ||
@@ -349,3 +322,2 @@ reject(error); | ||
}, | ||
/** | ||
@@ -362,3 +334,2 @@ * Batch operation to merge in existing and new values for a given set of | ||
callback === null || callback === void 0 ? void 0 : callback(error); | ||
if (error) { | ||
@@ -374,4 +345,3 @@ reject(error); | ||
})(); | ||
export default AsyncStorage; | ||
//# sourceMappingURL=AsyncStorage.native.js.map |
@@ -5,3 +5,2 @@ export function checkValidArgs(keyValuePairs, callback) { | ||
} | ||
if (callback && typeof callback !== 'function') { | ||
@@ -11,3 +10,2 @@ if (Array.isArray(callback)) { | ||
} | ||
throw new Error('[AsyncStorage] Expected function as second argument to multiSet'); | ||
@@ -20,9 +18,6 @@ } | ||
} | ||
const [key, value] = input; | ||
if (typeof key !== 'string') { | ||
console.warn(`[AsyncStorage] Using ${typeof key} type for key is not supported. This can lead to unexpected behavior/errors. Use string instead.\nKey passed: ${key}\n`); | ||
} | ||
if (input.length > 1 && typeof value !== 'string') { | ||
@@ -40,3 +35,2 @@ if (value == null) { | ||
} | ||
const out = new Error(error.message); | ||
@@ -50,3 +44,2 @@ out.key = error.key; | ||
} | ||
function ensureArray(e) { | ||
@@ -53,0 +46,0 @@ if (Array.isArray(e)) { |
@@ -8,3 +8,2 @@ import AsyncStorage from './AsyncStorage'; | ||
} | ||
return AsyncStorage.getItem(key, ...args); | ||
@@ -16,3 +15,2 @@ }, | ||
} | ||
return AsyncStorage.setItem(key, ...args); | ||
@@ -24,3 +22,2 @@ }, | ||
} | ||
return AsyncStorage.mergeItem(key, ...args); | ||
@@ -32,3 +29,2 @@ }, | ||
} | ||
return AsyncStorage.removeItem(key, ...args); | ||
@@ -35,0 +31,0 @@ } |
// @ts-ignore Module '"react-native"' has no exported member 'TurboModuleRegistry'. | ||
import { NativeModules, TurboModuleRegistry } from 'react-native'; | ||
import { shouldFallbackToLegacyNativeModule } from './shouldFallbackToLegacyNativeModule'; // TurboModuleRegistry falls back to NativeModules so we don't have to try go | ||
import { shouldFallbackToLegacyNativeModule } from './shouldFallbackToLegacyNativeModule'; | ||
// TurboModuleRegistry falls back to NativeModules so we don't have to try go | ||
// assign NativeModules' counterparts if TurboModuleRegistry would resolve | ||
// with undefined. | ||
let RCTAsyncStorage = TurboModuleRegistry ? TurboModuleRegistry.get('PlatformLocalStorage') || // Support for external modules, like react-native-windows | ||
TurboModuleRegistry.get('RNC_AsyncSQLiteDBStorage') || TurboModuleRegistry.get('RNCAsyncStorage') : NativeModules['PlatformLocalStorage'] || // Support for external modules, like react-native-windows | ||
let RCTAsyncStorage = TurboModuleRegistry ? TurboModuleRegistry.get('PlatformLocalStorage') || | ||
// Support for external modules, like react-native-windows | ||
TurboModuleRegistry.get('RNC_AsyncSQLiteDBStorage') || TurboModuleRegistry.get('RNCAsyncStorage') : NativeModules['PlatformLocalStorage'] || | ||
// Support for external modules, like react-native-windows | ||
NativeModules['RNC_AsyncSQLiteDBStorage'] || NativeModules['RNCAsyncStorage']; | ||
if (!RCTAsyncStorage && shouldFallbackToLegacyNativeModule()) { | ||
@@ -18,4 +20,3 @@ if (TurboModuleRegistry) { | ||
} | ||
export default RCTAsyncStorage; | ||
//# sourceMappingURL=RCTAsyncStorage.js.map |
import { NativeModules } from 'react-native'; | ||
export function shouldFallbackToLegacyNativeModule() { | ||
var _NativeModules$Native, _NativeModules$Native2; | ||
const expoConstants = (_NativeModules$Native = NativeModules['NativeUnimoduleProxy']) === null || _NativeModules$Native === void 0 ? void 0 : (_NativeModules$Native2 = _NativeModules$Native.modulesConstants) === null || _NativeModules$Native2 === void 0 ? void 0 : _NativeModules$Native2.ExponentConstants; | ||
if (expoConstants) { | ||
@@ -14,2 +12,3 @@ /** | ||
const isLegacySdkVersion = expoConstants.appOwnership && !expoConstants.executionEnvironment; | ||
/** | ||
@@ -24,3 +23,2 @@ * Expo managed apps don't include the @react-native-async-storage/async-storage | ||
*/ | ||
if (isLegacySdkVersion || ['storeClient', 'standalone'].includes(expoConstants.executionEnvironment)) { | ||
@@ -30,5 +28,4 @@ return true; | ||
} | ||
return false; | ||
} | ||
//# sourceMappingURL=shouldFallbackToLegacyNativeModule.js.map |
@@ -1,11 +0,11 @@ | ||
export declare type ErrorLike = { | ||
export type ErrorLike = { | ||
message: string; | ||
key: string; | ||
}; | ||
export declare type Callback = (error?: Error | null) => void; | ||
export declare type CallbackWithResult<T> = (error?: Error | null, result?: T | null) => void; | ||
export declare type KeyValuePair = [string, string | null]; | ||
export declare type MultiCallback = (errors?: readonly (Error | null)[] | null) => void; | ||
export declare type MultiGetCallback = (errors?: readonly (Error | null)[] | null, result?: readonly KeyValuePair[]) => void; | ||
export declare type MultiRequest = { | ||
export type Callback = (error?: Error | null) => void; | ||
export type CallbackWithResult<T> = (error?: Error | null, result?: T | null) => void; | ||
export type KeyValuePair = [string, string | null]; | ||
export type MultiCallback = (errors?: readonly (Error | null)[] | null) => void; | ||
export type MultiGetCallback = (errors?: readonly (Error | null)[] | null, result?: readonly KeyValuePair[]) => void; | ||
export type MultiRequest = { | ||
keys: readonly string[]; | ||
@@ -17,3 +17,3 @@ callback?: MultiGetCallback; | ||
}; | ||
export declare type AsyncStorageHook = { | ||
export type AsyncStorageHook = { | ||
getItem: (callback?: CallbackWithResult<string>) => Promise<string | null>; | ||
@@ -31,3 +31,3 @@ setItem: (value: string, callback?: Callback) => Promise<void>; | ||
*/ | ||
export declare type AsyncStorageStatic = { | ||
export type AsyncStorageStatic = { | ||
/** | ||
@@ -34,0 +34,0 @@ * Fetches an item for a `key` and invokes a callback upon completion. |
{ | ||
"name": "@react-native-async-storage/async-storage", | ||
"version": "1.18.2", | ||
"version": "1.19.0", | ||
"description": "Asynchronous, persistent, key-value storage system for React Native.", | ||
@@ -46,5 +46,5 @@ "main": "lib/commonjs/index.js", | ||
"start:android": "react-native run-android", | ||
"start:ios": "react-native run-ios --project-path example/ios", | ||
"start:ios": "react-native run-ios", | ||
"start:macos": "react-native run-macos --project-path example/macos --scheme AsyncStorageExample", | ||
"start:web": "expo start:web", | ||
"start:web": "expo start --web", | ||
"start:windows": "install-windows-test-app -p example/windows && react-native run-windows --root example --logging --no-packager --no-telemetry", | ||
@@ -60,4 +60,4 @@ "build:e2e:android": "scripts/android_e2e.sh 'build'", | ||
"test:ts": "tsc --project tsconfig.all.json", | ||
"test:e2e:android": "detox test -c android.emu.release --maxConcurrency 1", | ||
"test:e2e:ios": "detox test -c ios.sim.release --maxConcurrency 1", | ||
"test:e2e:android": "scripts/android_e2e.sh 'test'", | ||
"test:e2e:ios": "scripts/ios_e2e.sh 'test'", | ||
"test:e2e:macos": "scripts/macos_e2e.sh 'test'" | ||
@@ -72,4 +72,4 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.0", | ||
"@babel/preset-env": "^7.1.6", | ||
"@babel/core": "^7.20.0", | ||
"@babel/preset-env": "^7.20.0", | ||
"@react-native-community/eslint-config": "^3.0.0", | ||
@@ -79,28 +79,34 @@ "@semantic-release/changelog": "^6.0.0", | ||
"@types/lodash": "^4.14.184", | ||
"@types/react": "^17.0.0", | ||
"@types/react-native": "^0.68.0", | ||
"@types/react": "^18.0.0", | ||
"concurrently": "^6.4.0", | ||
"detox": "^19.4.5", | ||
"eslint": "^8.0.0", | ||
"expo": "^45.0.0", | ||
"jest": "^26.6.3", | ||
"jest-circus": "^26.6.1", | ||
"expo": "^48.0.0", | ||
"jest": "^29.2.1", | ||
"jest-circus": "^29.2.1", | ||
"lodash": "^4.17.21", | ||
"prettier": "^2.5.1", | ||
"react": "17.0.2", | ||
"react-dom": "17.0.2", | ||
"react-native": "^0.68.0", | ||
"react": "18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-native": "^0.71.0", | ||
"react-native-builder-bob": "^0.18.0", | ||
"react-native-macos": "^0.68.0", | ||
"react-native-test-app": "^2.3.10", | ||
"react-native-web": "^0.17.0", | ||
"react-native-windows": "^0.68.0", | ||
"react-test-renderer": "17.0.2", | ||
"react-native-codegen": "^0.71.5", | ||
"react-native-macos": "^0.71.0", | ||
"react-native-test-app": "^2.5.8", | ||
"react-native-web": "~0.18.10", | ||
"react-native-windows": "^0.71.0", | ||
"react-test-renderer": "18.2.0", | ||
"semantic-release": "^19.0.0", | ||
"typescript": "^4.5.0" | ||
"typescript": "^4.9.4" | ||
}, | ||
"packageManager": "yarn@3.4.1", | ||
"resolutions": { | ||
"@react-native-community/cli": "^10.2.5", | ||
"@react-native-community/cli-platform-android": "^10.2.0", | ||
"@react-native-community/cli-platform-ios": "^10.2.5", | ||
"body-parser/qs": "^6.7.3", | ||
"find-babel-config/json5": "^2.1.1", | ||
"metro-react-native-babel-preset": "^0.73.10", | ||
"metro-react-native-babel-transformer": "^0.73.10", | ||
"metro-runtime": "^0.73.10", | ||
"metro-source-map": "^0.73.10", | ||
"npm/chalk": "^4.1.2" | ||
@@ -114,37 +120,2 @@ }, | ||
}, | ||
"detox": { | ||
"test-runner": "jest", | ||
"runner-config": "example/e2e/config.json", | ||
"configurations": { | ||
"ios.sim.release": { | ||
"binaryPath": "example/ios/build/Build/Products/Release-iphonesimulator/ReactTestApp.app", | ||
"type": "ios.simulator", | ||
"device": { | ||
"type": "iPhone 13" | ||
} | ||
}, | ||
"android.emu.release": { | ||
"binaryPath": "example/android/app/build/outputs/apk/release/app-release.apk", | ||
"testBinaryPath": "example/android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk", | ||
"type": "android.emulator", | ||
"device": { | ||
"avdName": "E2E_API_30", | ||
"utilBinaryPaths": [ | ||
"/var/tmp/test-butler.apk" | ||
] | ||
} | ||
}, | ||
"android.emu.release.next": { | ||
"binaryPath": "example/android/app/build/outputs/apk/next/app-next.apk", | ||
"testBinaryPath": "example/android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk", | ||
"type": "android.emulator", | ||
"device": { | ||
"avdName": "E2E_API_30", | ||
"utilBinaryPaths": [ | ||
"/var/tmp/test-butler.apk" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"eslintConfig": { | ||
@@ -201,3 +172,11 @@ "extends": [ | ||
] | ||
}, | ||
"codegenConfig": { | ||
"name": "rnasyncstorage", | ||
"type": "modules", | ||
"jsSrcsDir": "./src", | ||
"android": { | ||
"javaPackageName": "com.reactnativecommunity.asyncstorage" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
423677
26
105
2225