@aws-amplify/core
Version:
Core category of aws-amplify
58 lines (55 loc) • 2.16 kB
JavaScript
import { __classPrivateFieldSet, __classPrivateFieldGet } from 'tslib';
import { PlatformNotSupportedError } from '../errors/PlatformNotSupportedError.mjs';
import '../errors/errorHelpers.mjs';
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
var _SyncKeyValueStorage_storage;
/**
* @internal
*/
class SyncKeyValueStorage {
constructor(storage) {
_SyncKeyValueStorage_storage.set(this, void 0);
__classPrivateFieldSet(this, _SyncKeyValueStorage_storage, storage, "f");
}
/**
* This is used to set a specific item in storage
* @param {string} key - the key for the item
* @param {object} value - the value
*/
setItem(key, value) {
if (!__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f"))
throw new PlatformNotSupportedError();
__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f").setItem(key, value);
}
/**
* This is used to get a specific key from storage
* @param {string} key - the key for the item
* @returns {string | null} the data item
*/
getItem(key) {
if (!__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f"))
throw new PlatformNotSupportedError();
return __classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f").getItem(key);
}
/**
* This is used to remove an item from storage
* @param {string} key - the key being set
*/
removeItem(key) {
if (!__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f"))
throw new PlatformNotSupportedError();
__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f").removeItem(key);
}
/**
* This is used to clear the storage
*/
clear() {
if (!__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f"))
throw new PlatformNotSupportedError();
__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f").clear();
}
}
_SyncKeyValueStorage_storage = new WeakMap();
export { SyncKeyValueStorage };
//# sourceMappingURL=SyncKeyValueStorage.mjs.map