123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- "use strict";
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
- var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
- var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
- var _CoreManager = _interopRequireDefault(require("./CoreManager"));
- /**
- * Copyright (c) 2015-present, Parse, LLC.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @flow
- */
- var Storage = {
- async: function ()
- /*: boolean*/
- {
- var controller = _CoreManager.default.getStorageController();
- return !!controller.async;
- },
- getItem: function (path
- /*: string*/
- )
- /*: ?string*/
- {
- var controller = _CoreManager.default.getStorageController();
- if (controller.async === 1) {
- throw new Error('Synchronous storage is not supported by the current storage controller');
- }
- return controller.getItem(path);
- },
- getItemAsync: function (path
- /*: string*/
- )
- /*: Promise<string>*/
- {
- var controller = _CoreManager.default.getStorageController();
- if (controller.async === 1) {
- return controller.getItemAsync(path);
- }
- return _promise.default.resolve(controller.getItem(path));
- },
- setItem: function (path
- /*: string*/
- , value
- /*: string*/
- )
- /*: void*/
- {
- var controller = _CoreManager.default.getStorageController();
- if (controller.async === 1) {
- throw new Error('Synchronous storage is not supported by the current storage controller');
- }
- return controller.setItem(path, value);
- },
- setItemAsync: function (path
- /*: string*/
- , value
- /*: string*/
- )
- /*: Promise<void>*/
- {
- var controller = _CoreManager.default.getStorageController();
- if (controller.async === 1) {
- return controller.setItemAsync(path, value);
- }
- return _promise.default.resolve(controller.setItem(path, value));
- },
- removeItem: function (path
- /*: string*/
- )
- /*: void*/
- {
- var controller = _CoreManager.default.getStorageController();
- if (controller.async === 1) {
- throw new Error('Synchronous storage is not supported by the current storage controller');
- }
- return controller.removeItem(path);
- },
- removeItemAsync: function (path
- /*: string*/
- )
- /*: Promise<void>*/
- {
- var controller = _CoreManager.default.getStorageController();
- if (controller.async === 1) {
- return controller.removeItemAsync(path);
- }
- return _promise.default.resolve(controller.removeItem(path));
- },
- getAllKeys: function ()
- /*: Array<string>*/
- {
- var controller = _CoreManager.default.getStorageController();
- if (controller.async === 1) {
- throw new Error('Synchronous storage is not supported by the current storage controller');
- }
- return controller.getAllKeys();
- },
- getAllKeysAsync: function ()
- /*: Promise<Array<string>>*/
- {
- var controller = _CoreManager.default.getStorageController();
- if (controller.async === 1) {
- return controller.getAllKeysAsync();
- }
- return _promise.default.resolve(controller.getAllKeys());
- },
- generatePath: function (path
- /*: string*/
- )
- /*: string*/
- {
- var _context;
- if (!_CoreManager.default.get('APPLICATION_ID')) {
- throw new Error('You need to call Moralis.start with an applicationId before using Moralis.');
- }
- if (typeof path !== 'string') {
- throw new Error('Tried to get a Storage path that was not a String.');
- }
- if (path[0] === '/') {
- path = path.substr(1);
- }
- return (0, _concat.default)(_context = "Parse/".concat(_CoreManager.default.get('APPLICATION_ID'), "/")).call(_context, path);
- },
- _clear: function () {
- var controller = _CoreManager.default.getStorageController();
- if (controller.hasOwnProperty('clear')) {
- controller.clear();
- }
- }
- };
- module.exports = Storage;
- _CoreManager.default.setStorageController(require('./StorageController.browser'));
|