Debian Codegraph @

extensions/VisualEditor/lib/ve/src/init/ve.init.SafeStorage.js

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