@converse/skeletor 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/skeletor.js +1023 -1621
- package/dist/skeletor.js.map +1 -1
- package/dist/skeletor.min.js +2 -2
- package/dist/skeletor.min.js.map +1 -1
- package/package.json +6 -5
- package/src/drivers/sessionStorage.js +30 -39
- package/src/drivers/sessionStorage.js~ +307 -0
- package/src/helpers.js +9 -0
- package/src/model.js +0 -2
- package/src/storage.js +2 -12
- package/src/drivers/indexeddb-getitems.js~ +0 -1116
- package/src/drivers/indexeddb.js~ +0 -1115
- package/src/storage.js~ +0 -269
package/package.json
CHANGED
|
@@ -17,13 +17,18 @@
|
|
|
17
17
|
"JC Brand"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@converse/localforage-getitems": "1.4.3",
|
|
20
21
|
"lit-html": "^2.0.0-rc.2",
|
|
22
|
+
"localforage": "^1.10.0",
|
|
23
|
+
"localforage-driver-memory": "^1.0.5",
|
|
24
|
+
"localforage-setitems": "^1.4.0",
|
|
21
25
|
"lodash-es": "^4.17.21",
|
|
22
26
|
"mergebounce": "0.1.1"
|
|
23
27
|
},
|
|
24
28
|
"devDependencies": {
|
|
25
29
|
"@babel/core": "^7.10.2",
|
|
26
30
|
"@babel/plugin-external-helpers": "^7.10.1",
|
|
31
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
27
32
|
"@babel/plugin-proposal-optional-chaining": "^7.13.12",
|
|
28
33
|
"@babel/preset-env": "^7.9.5",
|
|
29
34
|
"@rollup/plugin-babel": "^5.0.3",
|
|
@@ -38,10 +43,6 @@
|
|
|
38
43
|
"karma-mocha": "^2.0.1",
|
|
39
44
|
"karma-qunit": "^4.1.1",
|
|
40
45
|
"karma-webpack": "^4.0.2",
|
|
41
|
-
"localforage": "^1.7.4",
|
|
42
|
-
"localforage-driver-memory": "^1.0.5",
|
|
43
|
-
"localforage-getitems": "conversejs/localForage-getItems#de039970de16a9d3b54cdaa816aed5adaefb80c9",
|
|
44
|
-
"localforage-setitems": "^1.4.0",
|
|
45
46
|
"mocha": "^7.2.0",
|
|
46
47
|
"qunit": "^2.10.0",
|
|
47
48
|
"rollup": "^1.32.1",
|
|
@@ -59,7 +60,7 @@
|
|
|
59
60
|
"lint": "eslint src/*.js test/*.js"
|
|
60
61
|
},
|
|
61
62
|
"module": "src/main.js",
|
|
62
|
-
"version": "0.0.
|
|
63
|
+
"version": "0.0.8",
|
|
63
64
|
"license": "MIT",
|
|
64
65
|
"repository": {
|
|
65
66
|
"type": "git",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Copyright 2014 Mozilla
|
|
2
2
|
// Copyright 2015 Thodoris Greasidis
|
|
3
3
|
// Copyright 2018 JC Brand
|
|
4
|
-
//
|
|
4
|
+
//
|
|
5
5
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
// you may not use this file except in compliance with the License.
|
|
7
7
|
// You may obtain a copy of the License at
|
|
8
|
-
//
|
|
8
|
+
//
|
|
9
9
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
//
|
|
10
|
+
//
|
|
11
11
|
// Unless required by applicable law or agreed to in writing, software
|
|
12
12
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
13
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
@@ -221,45 +221,36 @@ function removeItem(key, callback) {
|
|
|
221
221
|
// Unlike Gaia's implementation, the callback function is passed the value,
|
|
222
222
|
// in case you want to operate on that value only after you're sure it
|
|
223
223
|
// saved, or something like that.
|
|
224
|
-
function setItem(key, value, callback) {
|
|
224
|
+
async function setItem(key, value, callback) {
|
|
225
225
|
key = normalizeKey(key);
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
e.name === 'QuotaExceededError' ||
|
|
250
|
-
e.name === 'NS_ERROR_DOM_QUOTA_REACHED'
|
|
251
|
-
) {
|
|
252
|
-
reject(e);
|
|
253
|
-
}
|
|
254
|
-
reject(e);
|
|
255
|
-
}
|
|
226
|
+
await this.ready();
|
|
227
|
+
|
|
228
|
+
// Convert undefined values to null.
|
|
229
|
+
// https://github.com/mozilla/localForage/pull/42
|
|
230
|
+
value = value ?? null;
|
|
231
|
+
|
|
232
|
+
// Save the original value to pass to the callback.
|
|
233
|
+
const originalValue = value;
|
|
234
|
+
|
|
235
|
+
dbInfo.serializer.serialize(value, (value, error) => {
|
|
236
|
+
if (error) {
|
|
237
|
+
throw error;
|
|
238
|
+
} else {
|
|
239
|
+
try {
|
|
240
|
+
sessionStorage.setItem(dbInfo.keyPrefix + key, value);
|
|
241
|
+
executeCallback(Promise.resolve(originalValue), callback);
|
|
242
|
+
} catch (e) {
|
|
243
|
+
if (
|
|
244
|
+
e.name === 'QuotaExceededError' ||
|
|
245
|
+
e.name === 'NS_ERROR_DOM_QUOTA_REACHED'
|
|
246
|
+
) {
|
|
247
|
+
console.error("Your sesionStorage capacity is used up.");
|
|
248
|
+
throw e;
|
|
256
249
|
}
|
|
257
|
-
|
|
258
|
-
|
|
250
|
+
throw e;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
259
253
|
});
|
|
260
|
-
|
|
261
|
-
executeCallback(promise, callback);
|
|
262
|
-
return promise;
|
|
263
254
|
}
|
|
264
255
|
|
|
265
256
|
function dropInstance(options, callback) {
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
// Copyright 2014 Mozilla
|
|
2
|
+
// Copyright 2015 Thodoris Greasidis
|
|
3
|
+
// Copyright 2018 JC Brand
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
import executeCallback from 'localforage/src/utils/executeCallback';
|
|
18
|
+
import getCallback from 'localforage/src/utils/getCallback';
|
|
19
|
+
import normalizeKey from 'localforage/src/utils/normalizeKey';
|
|
20
|
+
import serializer from 'localforage/src/utils/serializer';
|
|
21
|
+
|
|
22
|
+
const serialize = serializer["serialize"];
|
|
23
|
+
const deserialize = serializer["deserialize"];
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function isSessionStorageValid () {
|
|
27
|
+
// If the app is running inside a Google Chrome packaged webapp, or some
|
|
28
|
+
// other context where sessionStorage isn't available, we don't use
|
|
29
|
+
// sessionStorage. This feature detection is preferred over the old
|
|
30
|
+
// `if (window.chrome && window.chrome.runtime)` code.
|
|
31
|
+
// See: https://github.com/mozilla/localForage/issues/68
|
|
32
|
+
try {
|
|
33
|
+
// If sessionStorage isn't available, we get outta here!
|
|
34
|
+
// This should be inside a try catch
|
|
35
|
+
if (sessionStorage && ('setItem' in sessionStorage)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.log(e);
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _getKeyPrefix(options, defaultConfig) {
|
|
45
|
+
let keyPrefix = options.name + '/';
|
|
46
|
+
|
|
47
|
+
if (options.storeName !== defaultConfig.storeName) {
|
|
48
|
+
keyPrefix += options.storeName + '/';
|
|
49
|
+
}
|
|
50
|
+
return keyPrefix;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const dbInfo = {
|
|
54
|
+
'serializer': {
|
|
55
|
+
'serialize': serialize,
|
|
56
|
+
'deserialize': deserialize
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function _initStorage(options) {
|
|
61
|
+
dbInfo.keyPrefix = _getKeyPrefix(options, this._defaultConfig);
|
|
62
|
+
if (options) {
|
|
63
|
+
for (const i in options) { // eslint-disable-line guard-for-in
|
|
64
|
+
dbInfo[i] = options[i];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Remove all keys from the datastore, effectively destroying all data in
|
|
70
|
+
// the app's key/value store!
|
|
71
|
+
function clear(callback) {
|
|
72
|
+
const promise = this.ready().then(function() {
|
|
73
|
+
const keyPrefix = dbInfo.keyPrefix;
|
|
74
|
+
|
|
75
|
+
for (let i = sessionStorage.length - 1; i >= 0; i--) {
|
|
76
|
+
const key = sessionStorage.key(i);
|
|
77
|
+
|
|
78
|
+
if (key.indexOf(keyPrefix) === 0) {
|
|
79
|
+
sessionStorage.removeItem(key);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
executeCallback(promise, callback);
|
|
85
|
+
return promise;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Retrieve an item from the store. Unlike the original async_storage
|
|
89
|
+
// library in Gaia, we don't modify return values at all. If a key's value
|
|
90
|
+
// is `undefined`, we pass that value to the callback function.
|
|
91
|
+
function getItem(key, callback) {
|
|
92
|
+
key = normalizeKey(key);
|
|
93
|
+
|
|
94
|
+
const promise = this.ready().then(function() {
|
|
95
|
+
let result = sessionStorage.getItem(dbInfo.keyPrefix + key);
|
|
96
|
+
// If a result was found, parse it from the serialized
|
|
97
|
+
// string into a JS object. If result isn't truthy, the key
|
|
98
|
+
// is likely undefined and we'll pass it straight to the
|
|
99
|
+
// callback.
|
|
100
|
+
if (result) {
|
|
101
|
+
result = dbInfo.serializer.deserialize(result);
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
});
|
|
105
|
+
executeCallback(promise, callback);
|
|
106
|
+
return promise;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Iterate over all items in the store.
|
|
110
|
+
function iterate(iterator, callback) {
|
|
111
|
+
const self = this;
|
|
112
|
+
|
|
113
|
+
const promise = self.ready().then(function() {
|
|
114
|
+
const keyPrefix = dbInfo.keyPrefix;
|
|
115
|
+
const keyPrefixLength = keyPrefix.length;
|
|
116
|
+
const length = sessionStorage.length;
|
|
117
|
+
|
|
118
|
+
// We use a dedicated iterator instead of the `i` variable below
|
|
119
|
+
// so other keys we fetch in sessionStorage aren't counted in
|
|
120
|
+
// the `iterationNumber` argument passed to the `iterate()`
|
|
121
|
+
// callback.
|
|
122
|
+
//
|
|
123
|
+
// See: github.com/mozilla/localForage/pull/435#discussion_r38061530
|
|
124
|
+
let iterationNumber = 1;
|
|
125
|
+
|
|
126
|
+
for (let i = 0; i < length; i++) {
|
|
127
|
+
const key = sessionStorage.key(i);
|
|
128
|
+
if (key.indexOf(keyPrefix) !== 0) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
let value = sessionStorage.getItem(key);
|
|
132
|
+
|
|
133
|
+
// If a result was found, parse it from the serialized
|
|
134
|
+
// string into a JS object. If result isn't truthy, the
|
|
135
|
+
// key is likely undefined and we'll pass it straight
|
|
136
|
+
// to the iterator.
|
|
137
|
+
if (value) {
|
|
138
|
+
value = dbInfo.serializer.deserialize(value);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
value = iterator(
|
|
142
|
+
value,
|
|
143
|
+
key.substring(keyPrefixLength),
|
|
144
|
+
iterationNumber++
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
if (value !== void 0) { // eslint-disable-line no-void
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
executeCallback(promise, callback);
|
|
154
|
+
return promise;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Same as sessionStorage's key() method, except takes a callback.
|
|
158
|
+
function key(n, callback) {
|
|
159
|
+
const self = this;
|
|
160
|
+
const promise = self.ready().then(function() {
|
|
161
|
+
let result;
|
|
162
|
+
try {
|
|
163
|
+
result = sessionStorage.key(n);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
result = null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Remove the prefix from the key, if a key is found.
|
|
169
|
+
if (result) {
|
|
170
|
+
result = result.substring(dbInfo.keyPrefix.length);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return result;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
executeCallback(promise, callback);
|
|
177
|
+
return promise;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function keys(callback) {
|
|
181
|
+
const self = this;
|
|
182
|
+
const promise = self.ready().then(function() {
|
|
183
|
+
const length = sessionStorage.length;
|
|
184
|
+
const keys = [];
|
|
185
|
+
|
|
186
|
+
for (let i = 0; i < length; i++) {
|
|
187
|
+
const itemKey = sessionStorage.key(i);
|
|
188
|
+
if (itemKey.indexOf(dbInfo.keyPrefix) === 0) {
|
|
189
|
+
keys.push(itemKey.substring(dbInfo.keyPrefix.length));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return keys;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
executeCallback(promise, callback);
|
|
196
|
+
return promise;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Supply the number of keys in the datastore to the callback function.
|
|
200
|
+
function length(callback) {
|
|
201
|
+
const self = this;
|
|
202
|
+
const promise = self.keys().then(function(keys) {
|
|
203
|
+
return keys.length;
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
executeCallback(promise, callback);
|
|
207
|
+
return promise;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Remove an item from the store, nice and simple.
|
|
211
|
+
function removeItem(key, callback) {
|
|
212
|
+
key = normalizeKey(key);
|
|
213
|
+
const promise = this.ready().then(function() {
|
|
214
|
+
sessionStorage.removeItem(dbInfo.keyPrefix + key);
|
|
215
|
+
});
|
|
216
|
+
executeCallback(promise, callback);
|
|
217
|
+
return promise;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Set a key's value and run an optional callback once the value is set.
|
|
221
|
+
// Unlike Gaia's implementation, the callback function is passed the value,
|
|
222
|
+
// in case you want to operate on that value only after you're sure it
|
|
223
|
+
// saved, or something like that.
|
|
224
|
+
async function setItem(key, value, callback) {
|
|
225
|
+
key = normalizeKey(key);
|
|
226
|
+
await this.ready();
|
|
227
|
+
|
|
228
|
+
// Convert undefined values to null.
|
|
229
|
+
// https://github.com/mozilla/localForage/pull/42
|
|
230
|
+
value = value ?? null;
|
|
231
|
+
|
|
232
|
+
// Save the original value to pass to the callback.
|
|
233
|
+
const originalValue = value;
|
|
234
|
+
|
|
235
|
+
dbInfo.serializer.serialize(value, (value, error) => {
|
|
236
|
+
if (error) {
|
|
237
|
+
throw error;
|
|
238
|
+
} else {
|
|
239
|
+
try {
|
|
240
|
+
sessionStorage.setItem(dbInfo.keyPrefix + key, value);
|
|
241
|
+
executeCallback(Promise.resolve(originalValue), callback);
|
|
242
|
+
} catch (e) {
|
|
243
|
+
if (
|
|
244
|
+
e.name === 'QuotaExceededError' ||
|
|
245
|
+
e.name === 'NS_ERROR_DOM_QUOTA_REACHED'
|
|
246
|
+
) {
|
|
247
|
+
console.error("Your sesionStorage capacity is used up.");
|
|
248
|
+
throw e;
|
|
249
|
+
}
|
|
250
|
+
throw e;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function dropInstance(options, callback) {
|
|
258
|
+
callback = getCallback.apply(this, arguments);
|
|
259
|
+
|
|
260
|
+
options = (typeof options !== 'function' && options) || {};
|
|
261
|
+
if (!options.name) {
|
|
262
|
+
const currentConfig = this.config();
|
|
263
|
+
options.name = options.name || currentConfig.name;
|
|
264
|
+
options.storeName = options.storeName || currentConfig.storeName;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const self = this;
|
|
268
|
+
let promise;
|
|
269
|
+
if (!options.name) {
|
|
270
|
+
promise = Promise.reject(new Error('Invalid arguments'));
|
|
271
|
+
} else {
|
|
272
|
+
promise = new Promise(function(resolve) {
|
|
273
|
+
if (!options.storeName) {
|
|
274
|
+
resolve(`${options.name}/`);
|
|
275
|
+
} else {
|
|
276
|
+
resolve(_getKeyPrefix(options, self._defaultConfig));
|
|
277
|
+
}
|
|
278
|
+
}).then(function(keyPrefix) {
|
|
279
|
+
for (let i = sessionStorage.length - 1; i >= 0; i--) {
|
|
280
|
+
const key = sessionStorage.key(i);
|
|
281
|
+
if (key.indexOf(keyPrefix) === 0) {
|
|
282
|
+
sessionStorage.removeItem(key);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
executeCallback(promise, callback);
|
|
289
|
+
return promise;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const sessionStorageWrapper = {
|
|
293
|
+
_driver: 'sessionStorageWrapper',
|
|
294
|
+
_initStorage: _initStorage,
|
|
295
|
+
_support: isSessionStorageValid(),
|
|
296
|
+
iterate: iterate,
|
|
297
|
+
getItem: getItem,
|
|
298
|
+
setItem: setItem,
|
|
299
|
+
removeItem: removeItem,
|
|
300
|
+
clear: clear,
|
|
301
|
+
length: length,
|
|
302
|
+
key: key,
|
|
303
|
+
keys: keys,
|
|
304
|
+
dropInstance: dropInstance
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
export default sessionStorageWrapper;
|
package/src/helpers.js
CHANGED
|
@@ -11,6 +11,15 @@ import result from 'lodash-es/result.js';
|
|
|
11
11
|
*/
|
|
12
12
|
export class NotImplementedError extends Error {}
|
|
13
13
|
|
|
14
|
+
function S4() {
|
|
15
|
+
// Generate four random hex digits.
|
|
16
|
+
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function guid() {
|
|
20
|
+
// Generate a pseudo-GUID by concatenating random hexadecimal.
|
|
21
|
+
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
|
|
22
|
+
}
|
|
14
23
|
|
|
15
24
|
// Helpers
|
|
16
25
|
// -------
|
package/src/model.js
CHANGED
|
@@ -27,10 +27,8 @@ import escape from "lodash-es/escape.js";
|
|
|
27
27
|
import extend from "lodash-es/extend.js";
|
|
28
28
|
import has from "lodash-es/has.js";
|
|
29
29
|
import invert from "lodash-es/invert.js";
|
|
30
|
-
import isElement from "lodash-es/isElement.js";
|
|
31
30
|
import isEmpty from "lodash-es/isEmpty.js";
|
|
32
31
|
import isEqual from "lodash-es/isEqual.js";
|
|
33
|
-
import isFunction from "lodash-es/isFunction.js";
|
|
34
32
|
import iteratee from "lodash-es/iteratee.js";
|
|
35
33
|
import omit from "lodash-es/omit.js";
|
|
36
34
|
import pick from "lodash-es/pick.js";
|
package/src/storage.js
CHANGED
|
@@ -8,24 +8,14 @@ import localForage from "localforage/src/localforage";
|
|
|
8
8
|
import mergebounce from 'mergebounce';
|
|
9
9
|
import sessionStorageWrapper from "./drivers/sessionStorage.js";
|
|
10
10
|
import { extendPrototype as extendPrototypeWithSetItems } from 'localforage-setitems';
|
|
11
|
-
import { extendPrototype as extendPrototypeWithGetItems } from 'localforage-getitems';
|
|
11
|
+
import { extendPrototype as extendPrototypeWithGetItems } from '@converse/localforage-getitems';
|
|
12
|
+
import { guid } from './helpers.js';
|
|
12
13
|
|
|
13
14
|
const IN_MEMORY = memoryDriver._driver
|
|
14
15
|
localForage.defineDriver(memoryDriver);
|
|
15
16
|
extendPrototypeWithSetItems(localForage);
|
|
16
17
|
extendPrototypeWithGetItems(localForage);
|
|
17
18
|
|
|
18
|
-
function S4() {
|
|
19
|
-
// Generate four random hex digits.
|
|
20
|
-
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function guid() {
|
|
24
|
-
// Generate a pseudo-GUID by concatenating random hexadecimal.
|
|
25
|
-
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
19
|
class Storage {
|
|
30
20
|
|
|
31
21
|
constructor (id, type, batchedWrites=false) {
|