UNPKG

@aws-amplify/core

Version:

Core category of aws-amplify

59 lines (57 loc) • 2.28 kB
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 var _SyncKeyValueStorage_storage; Object.defineProperty(exports, "__esModule", { value: true }); exports.SyncKeyValueStorage = void 0; const tslib_1 = require("tslib"); const errors_1 = require("../errors"); /** * @internal */ class SyncKeyValueStorage { constructor(storage) { _SyncKeyValueStorage_storage.set(this, void 0); tslib_1.__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 (!tslib_1.__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f")) throw new errors_1.PlatformNotSupportedError(); tslib_1.__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 (!tslib_1.__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f")) throw new errors_1.PlatformNotSupportedError(); return tslib_1.__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 (!tslib_1.__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f")) throw new errors_1.PlatformNotSupportedError(); tslib_1.__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f").removeItem(key); } /** * This is used to clear the storage */ clear() { if (!tslib_1.__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f")) throw new errors_1.PlatformNotSupportedError(); tslib_1.__classPrivateFieldGet(this, _SyncKeyValueStorage_storage, "f").clear(); } } exports.SyncKeyValueStorage = SyncKeyValueStorage; _SyncKeyValueStorage_storage = new WeakMap(); //# sourceMappingURL=SyncKeyValueStorage.js.map