All files / src/init ve.init.SafeStorage.js

90.9% Statements 10/11
100% Branches 0/0
0% Functions 0/1
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114                    1x                         1x                       1x                   1x                     1x                       1x                       1x                   1x                     1x                     1x  
/**
 * A wrapper for an HTML5 Storage interface (`localStorage` or `sessionStorage`)
 * that is safe to call on all browsers.
 *
 * @abstract
 * @class ve.init.SafeStorage
 *
 * @constructor
 * @param {Storage|undefined} store The Storage instance to wrap around
 */
ve.init.SafeStorage = function ( store ) {
	this.store = store;
};
 
/**
 * Retrieve value from device storage.
 *
 * @abstract
 * @method
 * @param {string} key Key of item to retrieve
 * @return {string|null|boolean} String value, null if no value exists, or false
 *  if storage is not available.
 */
ve.init.SafeStorage.prototype.get = null;
 
/**
 * Set a value in device storage.
 *
 * @abstract
 * @method
 * @param {string} key Key name to store under
 * @param {string} value Value to be stored
 * @param {number} [expiry] Number of seconds after which this item can be deleted
 * @return {boolean} The value was set
 */
ve.init.SafeStorage.prototype.set = null;
 
/**
 * Remove a value from device storage.
 *
 * @abstract
 * @method
 * @param {string} key Key of item to remove
 * @return {boolean} Whether the save succeeded or not
 */
ve.init.SafeStorage.prototype.remove = null;
 
/**
 * Retrieve JSON object from device storage.
 *
 * @abstract
 * @method
 * @param {string} key Key of item to retrieve
 * @return {Object|null|boolean} Object, null if no value exists or value
 *  is not JSON-parseable, or false if storage is not available.
 */
ve.init.SafeStorage.prototype.getObject = null;
 
/**
 * Set an object value in device storage by JSON encoding
 *
 * @abstract
 * @method
 * @param {string} key Key name to store under
 * @param {Object} value Object value to be stored
 * @param {number} [expiry] Number of seconds after which this item can be deleted
 * @return {boolean} The value was set
 */
ve.init.SafeStorage.prototype.setObject = null;
 
/**
 * Set the expiry time for an item in the store
 *
 * @abstract
 * @method
 * @param {string} key Key name
 * @param {number} [expiry] Number of seconds after which this item can be deleted,
 *  omit to clear the expiry (either making the item never expire, or to clean up
 *  when deleting a key).
 */
ve.init.SafeStorage.prototype.setExpires = null;
 
/**
 * Clear any expired items from the store
 *
 * @abstract
 * @method
 * @protected
 * @return {jQuery.Promise} Resolves when items have been expired
 */
ve.init.SafeStorage.prototype.clearExpired = null;
 
/**
 * Get all keys with expiry values
 *
 * @abstract
 * @method
 * @protected
 * @return {jQuery.Promise} Promise resolving with all the keys which have
 *  expiry values (unprefixed), or as many could be retrieved in the allocated time.
 */
ve.init.SafeStorage.prototype.getExpiryKeys = null;
 
/**
 * Check if a given key has expired
 *
 * @abstract
 * @method
 * @protected
 * @param {string} key Key name
 * @return {boolean} Whether key is expired
 */
ve.init.SafeStorage.prototype.isExpired = null;