Socket
Socket
Sign inDemoInstall

@react-native-async-storage/async-storage

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-native-async-storage/async-storage - npm Package Compare versions

Comparing version 1.18.2 to 1.21.0

android/config.gradle

2

jest/async-storage-mock.d.ts
import type {
AsyncStorageHook,
AsyncStorageStatic,
} from '../lib/typescript/types';
} from "../lib/typescript/types";

@@ -6,0 +6,0 @@ export function useAsyncStorage(key: string): AsyncStorageHook;

@@ -1,6 +0,4 @@

/**
* @format
*/
/* eslint-disable no-undef */
const merge = require('merge-options').bind({
const merge = require("merge-options").bind({
concatArrays: true,

@@ -7,0 +5,0 @@ ignoreUndefined: true,

@@ -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,7 @@ * Copyright (c) Nicolas Gallagher.

*/
// @ts-ignore Cannot find module 'merge-options' or its corresponding type declarations
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/ban-types
const merge = _mergeOptions.default.bind({

@@ -26,6 +27,4 @@ concatArrays: true,

});
function mergeLocalStorageItem(key, value) {
const oldValue = window.localStorage.getItem(key);
if (oldValue) {

@@ -40,3 +39,2 @@ const oldObject = JSON.parse(oldValue);

}
function createPromise(getValue, callback) {

@@ -54,3 +52,2 @@ return new Promise((resolve, reject) => {

}
function createPromiseAll(promises, callback, processResult) {

@@ -66,3 +63,2 @@ return Promise.all(promises).then(result => {

}
const AsyncStorage = {

@@ -75,3 +71,2 @@ /**

},
/**

@@ -83,3 +78,2 @@ * Sets `value` for `key`.

},
/**

@@ -91,3 +85,2 @@ * Removes a `key`

},
/**

@@ -99,3 +92,2 @@ * Merges existing value with input value, assuming they are stringified JSON.

},
/**

@@ -107,3 +99,2 @@ * Erases *all* AsyncStorage for the domain.

},
/**

@@ -116,12 +107,9 @@ * Gets *all* keys known to the app, for all callers, libraries, etc.

const keys = [];
for (let i = 0; i < numberOfKeys; i += 1) {
const key = window.localStorage.key(i) || '';
const key = window.localStorage.key(i) || "";
keys.push(key);
}
return keys;
}, callback);
},
/**

@@ -131,3 +119,2 @@ * (stub) Flushes any pending requests using a single batch call to get the data.

flushGetRequests: () => undefined,
/**

@@ -141,8 +128,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);
},
/**

@@ -156,3 +140,2 @@ * Takes an array of key-value array pairs.

},
/**

@@ -165,3 +148,2 @@ * Delete all the keys in the `keys` array.

},
/**

@@ -168,0 +150,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) {

@@ -27,13 +24,16 @@ throw new Error(`[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

• Rebuild and restart the app.
• Uninstall, rebuild and restart the app.
• Run the packager with \`--reset-cache\` flag.
• If you are using CocoaPods on iOS, run \`pod install\` in the \`ios\` directory and then rebuild and re-run the app.
• If you are using CocoaPods on iOS, run \`pod install\` in the \`ios\` directory, then rebuild and re-run the app.
• If this happens while testing with Jest, check out docs how to integrate AsyncStorage with it: https://react-native-async-storage.github.io/async-storage/docs/advanced/jest
• Make sure your project's \`package.json\` depends on \`@react-native-async-storage/async-storage\`, even if you only depend on it indirectly through other dependencies. CLI only autolinks native modules found in your \`package.json\`.
If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-async-storage/async-storage/issues
• If this happens while testing with Jest, check out how to integrate AsyncStorage here: https://react-native-async-storage.github.io/async-storage/docs/advanced/jest
If none of these fix the issue, please open an issue on the GitHub repository: https://github.com/react-native-async-storage/async-storage/issues
`);
}
/**

@@ -46,4 +46,2 @@ * `AsyncStorage` is a simple, unencrypted, asynchronous, persistent, key-value

*/
const AsyncStorage = (() => {

@@ -62,6 +60,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 +67,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 +76,2 @@ reject(errs[0]);

},
/**

@@ -91,7 +85,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 +97,2 @@ reject(errs[0]);

},
/**

@@ -115,7 +106,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 +118,2 @@ reject(errs[0]);

},
/**

@@ -140,7 +128,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 +140,2 @@ reject(errs[0]);

},
/**

@@ -168,3 +153,2 @@ * Erases *all* `AsyncStorage` for all clients, libraries, etc. You probably

callback === null || callback === void 0 ? void 0 : callback(err);
if (err) {

@@ -178,3 +162,2 @@ reject(err);

},
/**

@@ -190,3 +173,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 +182,2 @@ resolve(keys);

},
/**

@@ -222,3 +203,2 @@ * The following batched functions are useful for executing a lot of

_getKeys = [];
_RCTAsyncStorage.default.multiGet(getKeys, (errors, result) => {

@@ -232,4 +212,3 @@ // Even though the runtime complexity of this is theoretically worse vs if we used a map,

const map = {};
result === null || result === void 0 ? void 0 : result.forEach(_ref => {
let [key, value] = _ref;
result === null || result === void 0 ? void 0 : result.forEach(([key, value]) => {
map[key] = value;

@@ -239,2 +218,3 @@ return value;

const reqLength = getRequests.length;
/**

@@ -249,14 +229,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);

@@ -266,3 +241,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]]);

@@ -274,3 +248,2 @@ (_request$callback2 = request.callback) === null || _request$callback2 === void 0 ? void 0 : _request$callback2.call(request, null, requestResult);

},
/**

@@ -290,3 +263,2 @@ * This allows you to batch the fetching of items given an array of `key`

}
const getRequest = {

@@ -296,5 +268,3 @@ keys: keys,

// do we need this?
keyIndex: _getKeys.length,
resolve: null,
reject: null
keyIndex: _getKeys.length
};

@@ -305,6 +275,4 @@ const promiseResult = new Promise((resolve, reject) => {

});
_getRequests.push(getRequest); // avoid fetching duplicates
_getRequests.push(getRequest);
// avoid fetching duplicates
keys.forEach(key => {

@@ -317,3 +285,2 @@ if (_getKeys.indexOf(key) === -1) {

},
/**

@@ -328,11 +295,8 @@ * Use this as a batch operation for storing multiple key-value pairs. When

return new Promise((resolve, reject) => {
keyValuePairs.forEach(_ref2 => {
let [key, value] = _ref2;
keyValuePairs.forEach(([key, value]) => {
(0, _helpers.checkValidInput)(key, value);
});
_RCTAsyncStorage.default.multiSet(keyValuePairs, errors => {
const error = (0, _helpers.convertErrors)(errors);
callback === null || callback === void 0 ? void 0 : callback(error);
if (error) {

@@ -346,3 +310,2 @@ reject(error);

},
/**

@@ -356,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) {

@@ -370,3 +331,2 @@ reject(error);

},
/**

@@ -383,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) {

@@ -395,5 +354,4 @@ reject(error);

})();
var _default = AsyncStorage;
exports.default = _default;
//# sourceMappingURL=AsyncStorage.native.js.map

@@ -10,32 +10,24 @@ "use strict";

exports.convertErrors = convertErrors;
function checkValidArgs(keyValuePairs, callback) {
if (!Array.isArray(keyValuePairs) || keyValuePairs.length === 0 || !Array.isArray(keyValuePairs[0])) {
throw new Error('[AsyncStorage] Expected array of key-value pairs as first argument to multiSet');
throw new Error("[AsyncStorage] Expected array of key-value pairs as first argument to multiSet");
}
if (callback && typeof callback !== 'function') {
if (callback && typeof callback !== "function") {
if (Array.isArray(callback)) {
throw new Error('[AsyncStorage] Expected function as second argument to multiSet. Did you forget to wrap key-value pairs in an array for the first argument?');
throw new Error("[AsyncStorage] Expected function as second argument to multiSet. Did you forget to wrap key-value pairs in an array for the first argument?");
}
throw new Error('[AsyncStorage] Expected function as second argument to multiSet');
throw new Error("[AsyncStorage] Expected function as second argument to multiSet");
}
}
function checkValidInput() {
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
input[_key] = arguments[_key];
}
function checkValidInput(...input) {
const [key, value] = input;
if (typeof key !== 'string') {
if (typeof key !== "string") {
// eslint-disable-next-line no-console
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') {
if (input.length > 1 && typeof value !== "string") {
if (value == null) {
throw new Error(`[AsyncStorage] Passing null/undefined as value is not supported. If you want to remove value, Use .removeItem method instead.\nPassed value: ${value}\nPassed key: ${key}\n`);
} else {
// eslint-disable-next-line no-console
console.warn(`[AsyncStorage] The value for key "${key}" is not a string. This can lead to unexpected behavior/errors. Consider stringifying it.\nPassed value: ${value}\nPassed key: ${key}\n`);

@@ -45,3 +37,2 @@ }

}
function convertError(error) {

@@ -51,8 +42,6 @@ if (!error) {

}
const out = new Error(error.message);
out.key = error.key;
out["key"] = error.key;
return out;
}
function convertErrors(errs) {

@@ -62,3 +51,2 @@ const errors = ensureArray(errs);

}
function ensureArray(e) {

@@ -65,0 +53,0 @@ if (Array.isArray(e)) {

@@ -7,39 +7,12 @@ "use strict";

exports.useAsyncStorage = useAsyncStorage;
var _AsyncStorage = _interopRequireDefault(require("./AsyncStorage"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function useAsyncStorage(key) {
return {
getItem: function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _AsyncStorage.default.getItem(key, ...args);
},
setItem: function () {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return _AsyncStorage.default.setItem(key, ...args);
},
mergeItem: function () {
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return _AsyncStorage.default.mergeItem(key, ...args);
},
removeItem: function () {
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
return _AsyncStorage.default.removeItem(key, ...args);
}
getItem: (...args) => _AsyncStorage.default.getItem(key, ...args),
setItem: (...args) => _AsyncStorage.default.setItem(key, ...args),
mergeItem: (...args) => _AsyncStorage.default.mergeItem(key, ...args),
removeItem: (...args) => _AsyncStorage.default.removeItem(key, ...args)
};
}
//# sourceMappingURL=hooks.js.map

@@ -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,25 +7,21 @@ "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'.
// 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
_reactNative.NativeModules['RNC_AsyncSQLiteDBStorage'] || _reactNative.NativeModules['RNCAsyncStorage'];
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)()) {
if (_reactNative.TurboModuleRegistry) {
RCTAsyncStorage = _reactNative.TurboModuleRegistry.get('AsyncSQLiteDBStorage') || _reactNative.TurboModuleRegistry.get('AsyncLocalStorage');
RCTAsyncStorage = _reactNative.TurboModuleRegistry.get("AsyncSQLiteDBStorage") || _reactNative.TurboModuleRegistry.get("AsyncLocalStorage");
} else {
RCTAsyncStorage = _reactNative.NativeModules['AsyncSQLiteDBStorage'] || _reactNative.NativeModules['AsyncLocalStorage'];
RCTAsyncStorage = _reactNative.NativeModules["AsyncSQLiteDBStorage"] || _reactNative.NativeModules["AsyncLocalStorage"];
}
}
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;
var _NativeModules$Native;
const expoConstants = (_NativeModules$Native = _reactNative.NativeModules["NativeUnimoduleProxy"]) === null || _NativeModules$Native === void 0 || (_NativeModules$Native = _NativeModules$Native.modulesConstants) === null || _NativeModules$Native === void 0 ? void 0 : _NativeModules$Native.ExponentConstants;
if (expoConstants) {

@@ -23,2 +19,3 @@ /**

const isLegacySdkVersion = expoConstants.appOwnership && !expoConstants.executionEnvironment;
/**

@@ -33,10 +30,8 @@ * Expo managed apps don't include the @react-native-async-storage/async-storage

*/
if (isLegacySdkVersion || ['storeClient', 'standalone'].includes(expoConstants.executionEnvironment)) {
if (isLegacySdkVersion || ["storeClient", "standalone"].includes(expoConstants.executionEnvironment)) {
return true;
}
}
return false;
}
//# sourceMappingURL=shouldFallbackToLegacyNativeModule.js.map

@@ -8,4 +8,9 @@ /**

*/
// @ts-ignore Cannot find module 'merge-options' or its corresponding type declarations
import mergeOptions from 'merge-options';
import mergeOptions from "merge-options";
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/ban-types
const merge = mergeOptions.bind({

@@ -15,6 +20,4 @@ concatArrays: true,

});
function mergeLocalStorageItem(key, value) {
const oldValue = window.localStorage.getItem(key);
if (oldValue) {

@@ -29,3 +32,2 @@ const oldObject = JSON.parse(oldValue);

}
function createPromise(getValue, callback) {

@@ -43,3 +45,2 @@ return new Promise((resolve, reject) => {

}
function createPromiseAll(promises, callback, processResult) {

@@ -55,3 +56,2 @@ return Promise.all(promises).then(result => {

}
const AsyncStorage = {

@@ -64,3 +64,2 @@ /**

},
/**

@@ -72,3 +71,2 @@ * Sets `value` for `key`.

},
/**

@@ -80,3 +78,2 @@ * Removes a `key`

},
/**

@@ -88,3 +85,2 @@ * Merges existing value with input value, assuming they are stringified JSON.

},
/**

@@ -96,3 +92,2 @@ * Erases *all* AsyncStorage for the domain.

},
/**

@@ -105,12 +100,9 @@ * Gets *all* keys known to the app, for all callers, libraries, etc.

const keys = [];
for (let i = 0; i < numberOfKeys; i += 1) {
const key = window.localStorage.key(i) || '';
const key = window.localStorage.key(i) || "";
keys.push(key);
}
return keys;
}, callback);
},
/**

@@ -120,3 +112,2 @@ * (stub) Flushes any pending requests using a single batch call to get the data.

flushGetRequests: () => undefined,
/**

@@ -130,8 +121,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);
},
/**

@@ -145,3 +133,2 @@ * Takes an array of key-value array pairs.

},
/**

@@ -154,3 +141,2 @@ * Delete all the keys in the `keys` array.

},
/**

@@ -157,0 +143,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';
import { checkValidArgs, checkValidInput, convertError, convertErrors } from "./helpers";
import RCTAsyncStorage from "./RCTAsyncStorage";
if (!RCTAsyncStorage) {

@@ -16,13 +16,16 @@ throw new Error(`[@RNC/AsyncStorage]: NativeModule: AsyncStorage is null.

• Rebuild and restart the app.
• Uninstall, rebuild and restart the app.
• Run the packager with \`--reset-cache\` flag.
• If you are using CocoaPods on iOS, run \`pod install\` in the \`ios\` directory and then rebuild and re-run the app.
• If you are using CocoaPods on iOS, run \`pod install\` in the \`ios\` directory, then rebuild and re-run the app.
• If this happens while testing with Jest, check out docs how to integrate AsyncStorage with it: https://react-native-async-storage.github.io/async-storage/docs/advanced/jest
• Make sure your project's \`package.json\` depends on \`@react-native-async-storage/async-storage\`, even if you only depend on it indirectly through other dependencies. CLI only autolinks native modules found in your \`package.json\`.
If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-async-storage/async-storage/issues
• If this happens while testing with Jest, check out how to integrate AsyncStorage here: https://react-native-async-storage.github.io/async-storage/docs/advanced/jest
If none of these fix the issue, please open an issue on the GitHub repository: https://github.com/react-native-async-storage/async-storage/issues
`);
}
/**

@@ -35,4 +38,2 @@ * `AsyncStorage` is a simple, unencrypted, asynchronous, persistent, key-value

*/
const AsyncStorage = (() => {

@@ -53,3 +54,2 @@ let _getRequests = [];

var _result$;
// Unpack result to get value from [[key,value]]

@@ -59,3 +59,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 +68,2 @@ reject(errs[0]);

},
/**

@@ -82,3 +80,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 +89,2 @@ reject(errs[0]);

},
/**

@@ -105,3 +101,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 +110,2 @@ reject(errs[0]);

},
/**

@@ -129,3 +123,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 +132,2 @@ reject(errs[0]);

},
/**

@@ -153,3 +145,2 @@ * Erases *all* `AsyncStorage` for all clients, libraries, etc. You probably

callback === null || callback === void 0 ? void 0 : callback(err);
if (err) {

@@ -163,3 +154,2 @@ reject(err);

},
/**

@@ -175,3 +165,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 +174,2 @@ resolve(keys);

},
/**

@@ -215,4 +203,3 @@ * The following batched functions are useful for executing a lot of

const map = {};
result === null || result === void 0 ? void 0 : result.forEach(_ref => {
let [key, value] = _ref;
result === null || result === void 0 ? void 0 : result.forEach(([key, value]) => {
map[key] = value;

@@ -222,2 +209,3 @@ return value;

const reqLength = getRequests.length;
/**

@@ -232,14 +220,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);

@@ -249,3 +232,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]]);

@@ -257,3 +239,2 @@ (_request$callback2 = request.callback) === null || _request$callback2 === void 0 ? void 0 : _request$callback2.call(request, null, requestResult);

},
/**

@@ -273,3 +254,2 @@ * This allows you to batch the fetching of items given an array of `key`

}
const getRequest = {

@@ -279,5 +259,3 @@ keys: keys,

// do we need this?
keyIndex: _getKeys.length,
resolve: null,
reject: null
keyIndex: _getKeys.length
};

@@ -288,6 +266,4 @@ const promiseResult = new Promise((resolve, reject) => {

});
_getRequests.push(getRequest); // avoid fetching duplicates
_getRequests.push(getRequest);
// avoid fetching duplicates
keys.forEach(key => {

@@ -300,3 +276,2 @@ if (_getKeys.indexOf(key) === -1) {

},
/**

@@ -311,4 +286,3 @@ * Use this as a batch operation for storing multiple key-value pairs. When

return new Promise((resolve, reject) => {
keyValuePairs.forEach(_ref2 => {
let [key, value] = _ref2;
keyValuePairs.forEach(([key, value]) => {
checkValidInput(key, value);

@@ -319,3 +293,2 @@ });

callback === null || callback === void 0 ? void 0 : callback(error);
if (error) {

@@ -329,3 +302,2 @@ reject(error);

},
/**

@@ -342,3 +314,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) {

@@ -352,3 +323,2 @@ reject(error);

},
/**

@@ -365,3 +335,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) {

@@ -377,4 +346,3 @@ reject(error);

})();
export default AsyncStorage;
//# sourceMappingURL=AsyncStorage.native.js.map
export function checkValidArgs(keyValuePairs, callback) {
if (!Array.isArray(keyValuePairs) || keyValuePairs.length === 0 || !Array.isArray(keyValuePairs[0])) {
throw new Error('[AsyncStorage] Expected array of key-value pairs as first argument to multiSet');
throw new Error("[AsyncStorage] Expected array of key-value pairs as first argument to multiSet");
}
if (callback && typeof callback !== 'function') {
if (callback && typeof callback !== "function") {
if (Array.isArray(callback)) {
throw new Error('[AsyncStorage] Expected function as second argument to multiSet. Did you forget to wrap key-value pairs in an array for the first argument?');
throw new Error("[AsyncStorage] Expected function as second argument to multiSet. Did you forget to wrap key-value pairs in an array for the first argument?");
}
throw new Error('[AsyncStorage] Expected function as second argument to multiSet');
throw new Error("[AsyncStorage] Expected function as second argument to multiSet");
}
}
export function checkValidInput() {
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
input[_key] = arguments[_key];
}
export function checkValidInput(...input) {
const [key, value] = input;
if (typeof key !== 'string') {
if (typeof key !== "string") {
// eslint-disable-next-line no-console
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') {
if (input.length > 1 && typeof value !== "string") {
if (value == null) {
throw new Error(`[AsyncStorage] Passing null/undefined as value is not supported. If you want to remove value, Use .removeItem method instead.\nPassed value: ${value}\nPassed key: ${key}\n`);
} else {
// eslint-disable-next-line no-console
console.warn(`[AsyncStorage] The value for key "${key}" is not a string. This can lead to unexpected behavior/errors. Consider stringifying it.\nPassed value: ${value}\nPassed key: ${key}\n`);

@@ -37,5 +31,4 @@ }

}
const out = new Error(error.message);
out.key = error.key;
out["key"] = error.key;
return out;

@@ -47,3 +40,2 @@ }

}
function ensureArray(e) {

@@ -50,0 +42,0 @@ if (Array.isArray(e)) {

@@ -1,34 +0,10 @@

import AsyncStorage from './AsyncStorage';
import AsyncStorage from "./AsyncStorage";
export function useAsyncStorage(key) {
return {
getItem: function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return AsyncStorage.getItem(key, ...args);
},
setItem: function () {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return AsyncStorage.setItem(key, ...args);
},
mergeItem: function () {
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return AsyncStorage.mergeItem(key, ...args);
},
removeItem: function () {
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
return AsyncStorage.removeItem(key, ...args);
}
getItem: (...args) => AsyncStorage.getItem(key, ...args),
setItem: (...args) => AsyncStorage.setItem(key, ...args),
mergeItem: (...args) => AsyncStorage.mergeItem(key, ...args),
removeItem: (...args) => AsyncStorage.removeItem(key, ...args)
};
}
//# sourceMappingURL=hooks.js.map

@@ -1,4 +0,4 @@

import AsyncStorage from './AsyncStorage';
export { useAsyncStorage } from './hooks';
import AsyncStorage from "./AsyncStorage";
export { useAsyncStorage } from "./hooks";
export default AsyncStorage;
//# sourceMappingURL=index.js.map

@@ -1,20 +0,20 @@

// @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 { NativeModules, TurboModuleRegistry } from "react-native";
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
NativeModules['RNC_AsyncSQLiteDBStorage'] || NativeModules['RNCAsyncStorage'];
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()) {
if (TurboModuleRegistry) {
RCTAsyncStorage = TurboModuleRegistry.get('AsyncSQLiteDBStorage') || TurboModuleRegistry.get('AsyncLocalStorage');
RCTAsyncStorage = TurboModuleRegistry.get("AsyncSQLiteDBStorage") || TurboModuleRegistry.get("AsyncLocalStorage");
} else {
RCTAsyncStorage = NativeModules['AsyncSQLiteDBStorage'] || NativeModules['AsyncLocalStorage'];
RCTAsyncStorage = NativeModules["AsyncSQLiteDBStorage"] || NativeModules["AsyncLocalStorage"];
}
}
export default RCTAsyncStorage;
//# sourceMappingURL=RCTAsyncStorage.js.map

@@ -1,7 +0,5 @@

import { NativeModules } from 'react-native';
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;
var _NativeModules$Native;
const expoConstants = (_NativeModules$Native = NativeModules["NativeUnimoduleProxy"]) === null || _NativeModules$Native === void 0 || (_NativeModules$Native = _NativeModules$Native.modulesConstants) === null || _NativeModules$Native === void 0 ? void 0 : _NativeModules$Native.ExponentConstants;
if (expoConstants) {

@@ -14,2 +12,3 @@ /**

const isLegacySdkVersion = expoConstants.appOwnership && !expoConstants.executionEnvironment;
/**

@@ -24,10 +23,8 @@ * Expo managed apps don't include the @react-native-async-storage/async-storage

*/
if (isLegacySdkVersion || ['storeClient', 'standalone'].includes(expoConstants.executionEnvironment)) {
if (isLegacySdkVersion || ["storeClient", "standalone"].includes(expoConstants.executionEnvironment)) {
return true;
}
}
return false;
}
//# sourceMappingURL=shouldFallbackToLegacyNativeModule.js.map

@@ -8,4 +8,5 @@ /**

*/
import type { AsyncStorageStatic } from './types';
import type { AsyncStorageStatic } from "./types";
declare const AsyncStorage: AsyncStorageStatic;
export default AsyncStorage;
//# sourceMappingURL=AsyncStorage.d.ts.map

@@ -7,3 +7,3 @@ /**

*/
import type { AsyncStorageStatic } from './types';
import type { AsyncStorageStatic } from "./types";
/**

@@ -18,1 +18,2 @@ * `AsyncStorage` is a simple, unencrypted, asynchronous, persistent, key-value

export default AsyncStorage;
//# sourceMappingURL=AsyncStorage.native.d.ts.map

@@ -1,2 +0,2 @@

import type { ErrorLike } from './types';
import type { ErrorLike } from "./types";
export declare function checkValidArgs(keyValuePairs: unknown[], callback: unknown): void;

@@ -6,1 +6,2 @@ export declare function checkValidInput(...input: unknown[]): void;

export declare function convertErrors(errs?: ErrorLike[]): ReadonlyArray<Error | null> | null;
//# sourceMappingURL=helpers.d.ts.map

@@ -1,2 +0,3 @@

import type { AsyncStorageHook } from './types';
import type { AsyncStorageHook } from "./types";
export declare function useAsyncStorage(key: string): AsyncStorageHook;
//# sourceMappingURL=hooks.d.ts.map

@@ -1,4 +0,5 @@

import AsyncStorage from './AsyncStorage';
export { useAsyncStorage } from './hooks';
export type { AsyncStorageStatic } from './types';
import AsyncStorage from "./AsyncStorage";
export { useAsyncStorage } from "./hooks";
export type { AsyncStorageStatic } from "./types";
export default AsyncStorage;
//# sourceMappingURL=index.d.ts.map
declare let RCTAsyncStorage: any;
export default RCTAsyncStorage;
//# sourceMappingURL=RCTAsyncStorage.d.ts.map
export declare function shouldFallbackToLegacyNativeModule(): boolean;
//# sourceMappingURL=shouldFallbackToLegacyNativeModule.d.ts.map

@@ -1,11 +0,11 @@

export declare type ErrorLike = {
export type ErrorLike = {
message: string;
key: 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[];

@@ -15,5 +15,5 @@ callback?: MultiGetCallback;

resolve?: (result: readonly KeyValuePair[]) => void;
reject?: (error?: any) => void;
reject?: (error?: ErrorLike) => void;
};
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 = {
/**

@@ -116,1 +116,2 @@ * Fetches an item for a `key` and invokes a callback upon completion.

};
//# sourceMappingURL=types.d.ts.map
{
"name": "@react-native-async-storage/async-storage",
"version": "1.18.2",
"version": "1.21.0",
"description": "Asynchronous, persistent, key-value storage system for React Native.",

@@ -11,5 +11,5 @@ "main": "lib/commonjs/index.js",

"RNCAsyncStorage.podspec",
"android/build.gradle",
"android/src",
"android/testresults.gradle",
"android/",
"!android/.gradle",
"!android/build",
"ios/",

@@ -38,14 +38,12 @@ "jest/",

"type": "git",
"url": "https://github.com/react-native-async-storage/async-storage.git"
"url": "https://github.com/react-native-async-storage/async-storage.git",
"directory": "packages/default-storage-backend"
},
"scripts": {
"format": "concurrently yarn:format:*",
"format:c": "clang-format -i $(git ls-files '*.cpp' '*.h' '*.m' '*.mm')",
"format:js": "prettier --write $(git ls-files '*.js' '*.json' '*.md' '*.ts' '*.tsx' '*.yml')",
"prepare": "bob build",
"start": "react-native start",
"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",

@@ -57,10 +55,13 @@ "build:e2e:android": "scripts/android_e2e.sh 'build'",

"bundle:ios": "scripts/ios_e2e.sh 'bundle'",
"bundle:macos": "react-native bundle --entry-file index.ts --platform macos --bundle-output example/index.macos.jsbundle",
"bundle:macos": "react-native bundle --entry-file index.ts --platform macos --dev false --bundle-output example/index.macos.jsbundle",
"test": "concurrently -n lint,ts yarn:test:lint yarn:test:ts",
"test:lint": "eslint src/**/*.ts example/**/*.ts jest/*.js",
"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:lint": "eslint $(git ls-files '*.js' '*.ts' '*.tsx')",
"test:ts": "tsc",
"test:e2e:android": "scripts/android_e2e.sh 'test'",
"test:e2e:ios": "scripts/ios_e2e.sh 'test'",
"test:e2e:macos": "scripts/macos_e2e.sh 'test'"
},
"installConfig": {
"hoistingLimits": "workspaces"
},
"dependencies": {

@@ -70,101 +71,39 @@ "merge-options": "^3.0.4"

"peerDependencies": {
"react-native": "^0.0.0-0 || 0.60 - 0.72 || 1000.0.0"
"react-native": "^0.0.0-0 || >=0.60 <1.0"
},
"devDependencies": {
"@babel/core": "^7.12.0",
"@babel/preset-env": "^7.1.6",
"@react-native-community/eslint-config": "^3.0.0",
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@semantic-release/changelog": "^6.0.0",
"@semantic-release/git": "^10.0.0",
"@types/lodash": "^4.14.184",
"@types/react": "^17.0.0",
"@types/react-native": "^0.68.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",
"@types/mocha": "^10.0.1",
"@types/react": "^18.0.0",
"@wdio/appium-service": "^8.24.0",
"@wdio/cli": "^8.24.0",
"@wdio/local-runner": "^8.24.0",
"@wdio/mocha-framework": "^8.11.0",
"@wdio/spec-reporter": "^8.24.0",
"appium": "2.2.2",
"appium-uiautomator2-driver": "^2.34.1",
"appium-xcuitest-driver": "^5.9.1",
"concurrently": "^8.2.2",
"eslint": "^8.54.0",
"expo": "^48.0.0",
"lodash": "^4.17.21",
"prettier": "^2.5.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "^0.68.0",
"prettier": "2.8.8",
"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.33",
"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": "^5.3.0",
"webdriverio": "^8.24.0"
},
"packageManager": "yarn@3.4.1",
"resolutions": {
"body-parser/qs": "^6.7.3",
"find-babel-config/json5": "^2.1.1",
"npm/chalk": "^4.1.2"
},
"jest": {
"preset": "react-native",
"setupFiles": [
"./example/jest.setup.js"
]
},
"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": {
"extends": [
"@react-native-community",
"plugin:jest/recommended"
],
"rules": {
"dot-notation": "off"
}
},
"prettier": {
"endOfLine": "auto",
"singleQuote": true,
"overrides": [
{
"files": "*.md",
"options": {
"proseWrap": "always"
}
}
]
},
"react-native-builder-bob": {

@@ -176,3 +115,8 @@ "source": "src",

"module",
"typescript"
[
"typescript",
{
"project": "tsconfig.build.json"
}
]
]

@@ -182,3 +126,3 @@ },

"branches": [
"master"
"main"
],

@@ -202,3 +146,11 @@ "plugins": [

]
},
"codegenConfig": {
"name": "rnasyncstorage",
"type": "modules",
"jsSrcsDir": "./src",
"android": {
"javaPackageName": "com.reactnativecommunity.asyncstorage"
}
}
}
# React Native Async Storage
An asynchronous, unencrypted, persistent, key-value storage system for React Native.
An asynchronous, unencrypted, persistent, key-value storage system for React
Native.
## Supported platforms
- Android
- iOS
- Android
- [macOS](https://github.com/react-native-async-storage/async-storage/releases/tag/v1.8.1)
- [Web](https://github.com/react-native-async-storage/async-storage/releases/tag/v1.9.0)
- [MacOS](https://github.com/react-native-async-storage/async-storage/releases/tag/v1.8.1)
- [Windows](https://github.com/react-native-async-storage/async-storage/releases/tag/v1.10.0)
## Getting Started
Head over to [documentation](https://react-native-async-storage.github.io/async-storage/docs/install) to learn more.
Head over to the
[documentation](https://react-native-async-storage.github.io/async-storage/docs/install)
to learn more.
## Running E2E locally
### Android
1. Create and start Android Emulator with Play services, API level 29
2. Build app and run tests
```shell
yarn bundle:android
yarn build:e2e:android
yarn test:e2e:android
```
### iOS
1. Create and start iPhone 14 simulator with iOS version 16.4
2. Build app and run tests
```shell
yarn bundle:ios
yarn build:e2e:ios
yarn test:e2e:ios
```
## Contribution
Pull requests are welcome. Please open an issue first to discuss what you would like to change.
See the [CONTRIBUTING](CONTRIBUTING.md) file for more information.
Pull requests are welcome. Please open an issue first to discuss what you would
like to change.
See the [CONTRIBUTING](.github/CONTRIBUTING.md) file for more information.
## License
MIT.
MIT

@@ -13,4 +13,4 @@ /**

convertErrors,
} from './helpers';
import RCTAsyncStorage from './RCTAsyncStorage';
} from "./helpers";
import RCTAsyncStorage from "./RCTAsyncStorage";
import type {

@@ -21,3 +21,3 @@ AsyncStorageStatic,

MultiRequest,
} from './types';
} from "./types";

@@ -29,11 +29,13 @@ if (!RCTAsyncStorage) {

• Rebuild and restart the app.
• Uninstall, rebuild and restart the app.
• Run the packager with \`--reset-cache\` flag.
• If you are using CocoaPods on iOS, run \`pod install\` in the \`ios\` directory and then rebuild and re-run the app.
• If you are using CocoaPods on iOS, run \`pod install\` in the \`ios\` directory, then rebuild and re-run the app.
• If this happens while testing with Jest, check out docs how to integrate AsyncStorage with it: https://react-native-async-storage.github.io/async-storage/docs/advanced/jest
• Make sure your project's \`package.json\` depends on \`@react-native-async-storage/async-storage\`, even if you only depend on it indirectly through other dependencies. CLI only autolinks native modules found in your \`package.json\`.
If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-async-storage/async-storage/issues
• If this happens while testing with Jest, check out how to integrate AsyncStorage here: https://react-native-async-storage.github.io/async-storage/docs/advanced/jest
If none of these fix the issue, please open an issue on the GitHub repository: https://github.com/react-native-async-storage/async-storage/issues
`);

@@ -269,4 +271,2 @@ }

keyIndex: _getKeys.length,
resolve: null as any,
reject: null as any,
};

@@ -273,0 +273,0 @@

@@ -9,4 +9,3 @@ /**

// @ts-ignore Cannot find module 'merge-options' or its corresponding type declarations
import mergeOptions from 'merge-options';
import mergeOptions from "merge-options";
import type {

@@ -16,4 +15,9 @@ AsyncStorageStatic,

MultiGetCallback,
} from './types';
} from "./types";
// eslint-disable-next-line @typescript-eslint/ban-types
type OnMultiResult = Function;
// eslint-disable-next-line @typescript-eslint/ban-types
type OnResult = Function;
const merge = mergeOptions.bind({

@@ -36,3 +40,3 @@ concatArrays: true,

function createPromise<Result, Callback extends Function>(
function createPromise<Result, Callback extends OnResult>(
getValue: () => Result,

@@ -53,3 +57,7 @@ callback?: Callback

function createPromiseAll<ReturnType, Result, ResultProcessor extends Function>(
function createPromiseAll<
ReturnType,
Result,
ResultProcessor extends OnMultiResult
>(
promises: Promise<Result>[],

@@ -119,3 +127,3 @@ callback?: MultiCallback | MultiGetCallback,

for (let i = 0; i < numberOfKeys; i += 1) {
const key = window.localStorage.key(i) || '';
const key = window.localStorage.key(i) || "";
keys.push(key);

@@ -122,0 +130,0 @@ }

@@ -1,2 +0,2 @@

import type { ErrorLike } from './types';
import type { ErrorLike } from "./types";

@@ -10,10 +10,10 @@ export function checkValidArgs(keyValuePairs: unknown[], callback: unknown) {

throw new Error(
'[AsyncStorage] Expected array of key-value pairs as first argument to multiSet'
"[AsyncStorage] Expected array of key-value pairs as first argument to multiSet"
);
}
if (callback && typeof callback !== 'function') {
if (callback && typeof callback !== "function") {
if (Array.isArray(callback)) {
throw new Error(
'[AsyncStorage] Expected function as second argument to multiSet. Did you forget to wrap key-value pairs in an array for the first argument?'
"[AsyncStorage] Expected function as second argument to multiSet. Did you forget to wrap key-value pairs in an array for the first argument?"
);

@@ -23,3 +23,3 @@ }

throw new Error(
'[AsyncStorage] Expected function as second argument to multiSet'
"[AsyncStorage] Expected function as second argument to multiSet"
);

@@ -32,3 +32,4 @@ }

if (typeof key !== 'string') {
if (typeof key !== "string") {
// eslint-disable-next-line no-console
console.warn(

@@ -39,3 +40,3 @@ `[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') {
if (input.length > 1 && typeof value !== "string") {
if (value == null) {

@@ -46,2 +47,3 @@ throw new Error(

} else {
// eslint-disable-next-line no-console
console.warn(

@@ -59,4 +61,4 @@ `[AsyncStorage] The value for key "${key}" is not a string. This can lead to unexpected behavior/errors. Consider stringifying it.\nPassed value: ${value}\nPassed key: ${key}\n`

const out = new Error(error.message);
(out as any).key = error.key;
const out = new Error(error.message) as Error & ErrorLike;
out["key"] = error.key;
return out;

@@ -63,0 +65,0 @@ }

@@ -1,3 +0,3 @@

import AsyncStorage from './AsyncStorage';
import type { AsyncStorageHook } from './types';
import AsyncStorage from "./AsyncStorage";
import type { AsyncStorageHook } from "./types";

@@ -4,0 +4,0 @@ export function useAsyncStorage(key: string): AsyncStorageHook {

@@ -1,7 +0,7 @@

import AsyncStorage from './AsyncStorage';
import AsyncStorage from "./AsyncStorage";
export { useAsyncStorage } from './hooks';
export { useAsyncStorage } from "./hooks";
export type { AsyncStorageStatic } from './types';
export type { AsyncStorageStatic } from "./types";
export default AsyncStorage;

@@ -1,4 +0,3 @@

// @ts-ignore Module '"react-native"' has no exported member 'TurboModuleRegistry'.
import { NativeModules, TurboModuleRegistry } from 'react-native';
import { shouldFallbackToLegacyNativeModule } from './shouldFallbackToLegacyNativeModule';
import { NativeModules, TurboModuleRegistry } from "react-native";
import { shouldFallbackToLegacyNativeModule } from "./shouldFallbackToLegacyNativeModule";

@@ -9,8 +8,8 @@ // TurboModuleRegistry falls back to NativeModules so we don't have to try go

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'];
? 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"];

@@ -20,8 +19,8 @@ if (!RCTAsyncStorage && shouldFallbackToLegacyNativeModule()) {

RCTAsyncStorage =
TurboModuleRegistry.get('AsyncSQLiteDBStorage') ||
TurboModuleRegistry.get('AsyncLocalStorage');
TurboModuleRegistry.get("AsyncSQLiteDBStorage") ||
TurboModuleRegistry.get("AsyncLocalStorage");
} else {
RCTAsyncStorage =
NativeModules['AsyncSQLiteDBStorage'] ||
NativeModules['AsyncLocalStorage'];
NativeModules["AsyncSQLiteDBStorage"] ||
NativeModules["AsyncLocalStorage"];
}

@@ -28,0 +27,0 @@ }

@@ -1,6 +0,6 @@

import { NativeModules } from 'react-native';
import { NativeModules } from "react-native";
export function shouldFallbackToLegacyNativeModule(): boolean {
const expoConstants =
NativeModules['NativeUnimoduleProxy']?.modulesConstants?.ExponentConstants;
NativeModules["NativeUnimoduleProxy"]?.modulesConstants?.ExponentConstants;

@@ -27,3 +27,3 @@ if (expoConstants) {

isLegacySdkVersion ||
['storeClient', 'standalone'].includes(expoConstants.executionEnvironment)
["storeClient", "standalone"].includes(expoConstants.executionEnvironment)
) {

@@ -30,0 +30,0 @@ return true;

export type ErrorLike = {
message: string;
key: string;
key?: string;
};

@@ -27,3 +27,3 @@

resolve?: (result: readonly KeyValuePair[]) => void;
reject?: (error?: any) => void;
reject?: (error?: ErrorLike) => void;
};

@@ -30,0 +30,0 @@

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc