@converse/skeletor 3.1.3 → 3.1.5
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/CHANGES.md +18 -0
- package/README.md +12 -5
- package/dist/skeletor.d.ts +11 -5
- package/dist/skeletor.esm.js +263 -250
- package/dist/skeletor.esm.js.map +1 -1
- package/dist/skeletor.js +263 -250
- package/dist/skeletor.js.map +1 -1
- package/dist/skeletor.min.js +4 -4
- package/dist/skeletor.node.js +264 -251
- package/dist/skeletor.node.mjs +264 -251
- package/package.json +3 -1
- package/src/collection.ts +5 -5
- package/src/declarations.d.ts +11 -0
- package/src/drivers/nodeSQLiteStorage.ts +2 -7
- package/src/drivers/types.ts +8 -2
- package/src/model.ts +6 -6
- package/src/storage.ts +11 -26
package/dist/skeletor.esm.js
CHANGED
|
@@ -1971,7 +1971,7 @@ function getKeyPrefix(options, defaultConfig) {
|
|
|
1971
1971
|
return (options.name || defaultConfig.name) + "/" + (options.storeName || defaultConfig.storeName) + "/";
|
|
1972
1972
|
}
|
|
1973
1973
|
|
|
1974
|
-
function executeCallback
|
|
1974
|
+
function executeCallback(promise, callback) {
|
|
1975
1975
|
if (callback) {
|
|
1976
1976
|
promise.then(function (result) {
|
|
1977
1977
|
callback(null, result);
|
|
@@ -2112,7 +2112,7 @@ function clear$1(callback) {
|
|
|
2112
2112
|
var promise = this.ready().then(function () {
|
|
2113
2113
|
_this._dbInfo.mStore.clear();
|
|
2114
2114
|
});
|
|
2115
|
-
executeCallback
|
|
2115
|
+
executeCallback(promise, callback);
|
|
2116
2116
|
return promise;
|
|
2117
2117
|
}
|
|
2118
2118
|
|
|
@@ -2121,7 +2121,7 @@ function dropInstance$1(_options, _cb) {
|
|
|
2121
2121
|
var outPromise = promise.then(function (keyPrefix) {
|
|
2122
2122
|
Store.resolve(keyPrefix).drop();
|
|
2123
2123
|
});
|
|
2124
|
-
executeCallback
|
|
2124
|
+
executeCallback(outPromise, callback);
|
|
2125
2125
|
return promise;
|
|
2126
2126
|
}
|
|
2127
2127
|
|
|
@@ -2133,7 +2133,7 @@ function getItem$1(key$, callback) {
|
|
|
2133
2133
|
// Deserialise if the result is not null or undefined
|
|
2134
2134
|
return result == null ? null : _this._dbInfo.serializer.deserialize(result); //tslint:disable-line:triple-equals
|
|
2135
2135
|
});
|
|
2136
|
-
executeCallback
|
|
2136
|
+
executeCallback(promise, callback);
|
|
2137
2137
|
return promise;
|
|
2138
2138
|
}
|
|
2139
2139
|
|
|
@@ -2157,7 +2157,7 @@ function iterate$1(iterator, callback) {
|
|
|
2157
2157
|
}
|
|
2158
2158
|
}
|
|
2159
2159
|
});
|
|
2160
|
-
executeCallback
|
|
2160
|
+
executeCallback(promise, callback);
|
|
2161
2161
|
return promise;
|
|
2162
2162
|
}
|
|
2163
2163
|
|
|
@@ -2176,7 +2176,7 @@ function key$1(idx, callback) {
|
|
|
2176
2176
|
}
|
|
2177
2177
|
return result;
|
|
2178
2178
|
});
|
|
2179
|
-
executeCallback
|
|
2179
|
+
executeCallback(promise, callback);
|
|
2180
2180
|
return promise;
|
|
2181
2181
|
}
|
|
2182
2182
|
|
|
@@ -2185,13 +2185,13 @@ function keys$1(callback) {
|
|
|
2185
2185
|
var promise = this.ready().then(function () {
|
|
2186
2186
|
return _this._dbInfo.mStore.keys();
|
|
2187
2187
|
});
|
|
2188
|
-
executeCallback
|
|
2188
|
+
executeCallback(promise, callback);
|
|
2189
2189
|
return promise;
|
|
2190
2190
|
}
|
|
2191
2191
|
|
|
2192
2192
|
function length$1(callback) {
|
|
2193
2193
|
var promise = this.keys().then(function (keys$) { return keys$.length; });
|
|
2194
|
-
executeCallback
|
|
2194
|
+
executeCallback(promise, callback);
|
|
2195
2195
|
return promise;
|
|
2196
2196
|
}
|
|
2197
2197
|
|
|
@@ -2201,7 +2201,7 @@ function removeItem$1(key$, callback) {
|
|
|
2201
2201
|
var promise = this.ready().then(function () {
|
|
2202
2202
|
_this._dbInfo.mStore.rm(key$);
|
|
2203
2203
|
});
|
|
2204
|
-
executeCallback
|
|
2204
|
+
executeCallback(promise, callback);
|
|
2205
2205
|
return promise;
|
|
2206
2206
|
}
|
|
2207
2207
|
|
|
@@ -2231,7 +2231,7 @@ function setItem$1(key$, value, callback) {
|
|
|
2231
2231
|
});
|
|
2232
2232
|
});
|
|
2233
2233
|
});
|
|
2234
|
-
executeCallback
|
|
2234
|
+
executeCallback(promise, callback);
|
|
2235
2235
|
return promise;
|
|
2236
2236
|
}
|
|
2237
2237
|
|
|
@@ -7881,253 +7881,282 @@ function requireLocalforageSetitems () {
|
|
|
7881
7881
|
|
|
7882
7882
|
var localforageSetitemsExports = requireLocalforageSetitems();
|
|
7883
7883
|
|
|
7884
|
-
|
|
7885
|
-
if (getSerializerPromise.result) {
|
|
7886
|
-
return getSerializerPromise.result;
|
|
7887
|
-
}
|
|
7888
|
-
if (!localForageInstance || typeof localForageInstance.getSerializer !== 'function') {
|
|
7889
|
-
return Promise.reject(new Error('localforage.getSerializer() was not available! ' + 'localforage v1.4+ is required!'));
|
|
7890
|
-
}
|
|
7891
|
-
getSerializerPromise.result = localForageInstance.getSerializer();
|
|
7892
|
-
return getSerializerPromise.result;
|
|
7893
|
-
}
|
|
7884
|
+
var localforageGetitems$1 = {exports: {}};
|
|
7894
7885
|
|
|
7886
|
+
var localforageGetitems = localforageGetitems$1.exports;
|
|
7895
7887
|
|
|
7888
|
+
var hasRequiredLocalforageGetitems;
|
|
7896
7889
|
|
|
7897
|
-
function
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7905
|
-
return promise;
|
|
7906
|
-
}
|
|
7890
|
+
function requireLocalforageGetitems () {
|
|
7891
|
+
if (hasRequiredLocalforageGetitems) return localforageGetitems$1.exports;
|
|
7892
|
+
hasRequiredLocalforageGetitems = 1;
|
|
7893
|
+
(function (module, exports) {
|
|
7894
|
+
(function (global, factory) {
|
|
7895
|
+
factory(exports, requireLocalforage()) ;
|
|
7896
|
+
}(localforageGetitems, (function (exports,localforage) {
|
|
7897
|
+
localforage = 'default' in localforage ? localforage['default'] : localforage;
|
|
7907
7898
|
|
|
7908
|
-
function
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
}
|
|
7899
|
+
function getSerializerPromise(localForageInstance) {
|
|
7900
|
+
if (getSerializerPromise.result) {
|
|
7901
|
+
return getSerializerPromise.result;
|
|
7902
|
+
}
|
|
7903
|
+
if (!localForageInstance || typeof localForageInstance.getSerializer !== 'function') {
|
|
7904
|
+
return Promise.reject(new Error('localforage.getSerializer() was not available! ' + 'localforage v1.4+ is required!'));
|
|
7905
|
+
}
|
|
7906
|
+
getSerializerPromise.result = localForageInstance.getSerializer();
|
|
7907
|
+
return getSerializerPromise.result;
|
|
7908
|
+
}
|
|
7919
7909
|
|
|
7920
|
-
function getItemsGeneric(keys /*, callback*/) {
|
|
7921
|
-
var localforageInstance = this;
|
|
7922
|
-
var promise = new Promise(function (resolve, reject) {
|
|
7923
|
-
var itemPromises = [];
|
|
7924
7910
|
|
|
7925
|
-
for (var i = 0, len = keys.length; i < len; i++) {
|
|
7926
|
-
itemPromises.push(getItemKeyValue.call(localforageInstance, keys[i]));
|
|
7927
|
-
}
|
|
7928
7911
|
|
|
7929
|
-
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7912
|
+
function executeCallback(promise, callback) {
|
|
7913
|
+
if (callback) {
|
|
7914
|
+
promise.then(function (result) {
|
|
7915
|
+
callback(null, result);
|
|
7916
|
+
}, function (error) {
|
|
7917
|
+
callback(error);
|
|
7918
|
+
});
|
|
7919
|
+
}
|
|
7920
|
+
return promise;
|
|
7921
|
+
}
|
|
7933
7922
|
|
|
7934
|
-
|
|
7935
|
-
|
|
7936
|
-
|
|
7937
|
-
|
|
7938
|
-
|
|
7939
|
-
|
|
7940
|
-
}
|
|
7923
|
+
function getItemKeyValue(key, callback) {
|
|
7924
|
+
var localforageInstance = this;
|
|
7925
|
+
var promise = localforageInstance.getItem(key).then(function (value) {
|
|
7926
|
+
return {
|
|
7927
|
+
key: key,
|
|
7928
|
+
value: value
|
|
7929
|
+
};
|
|
7930
|
+
});
|
|
7931
|
+
executeCallback(promise, callback);
|
|
7932
|
+
return promise;
|
|
7933
|
+
}
|
|
7941
7934
|
|
|
7935
|
+
function getItemsGeneric(keys /*, callback*/) {
|
|
7936
|
+
var localforageInstance = this;
|
|
7937
|
+
var promise = new Promise(function (resolve, reject) {
|
|
7938
|
+
var itemPromises = [];
|
|
7942
7939
|
|
|
7940
|
+
for (var i = 0, len = keys.length; i < len; i++) {
|
|
7941
|
+
itemPromises.push(getItemKeyValue.call(localforageInstance, keys[i]));
|
|
7942
|
+
}
|
|
7943
7943
|
|
|
7944
|
+
Promise.all(itemPromises).then(function (keyValuePairs) {
|
|
7945
|
+
var result = {};
|
|
7946
|
+
for (var i = 0, len = keyValuePairs.length; i < len; i++) {
|
|
7947
|
+
var keyValuePair = keyValuePairs[i];
|
|
7944
7948
|
|
|
7949
|
+
result[keyValuePair.key] = keyValuePair.value;
|
|
7950
|
+
}
|
|
7951
|
+
resolve(result);
|
|
7952
|
+
}).catch(reject);
|
|
7953
|
+
});
|
|
7954
|
+
return promise;
|
|
7955
|
+
}
|
|
7945
7956
|
|
|
7946
|
-
function getAllItemsUsingIterate() {
|
|
7947
|
-
var localforageInstance = this;
|
|
7948
|
-
var accumulator = {};
|
|
7949
|
-
return localforageInstance.iterate(function (value, key /*, iterationNumber*/) {
|
|
7950
|
-
accumulator[key] = value;
|
|
7951
|
-
}).then(function () {
|
|
7952
|
-
return accumulator;
|
|
7953
|
-
});
|
|
7954
|
-
}
|
|
7955
7957
|
|
|
7956
|
-
function getIDBKeyRange() {
|
|
7957
|
-
/* global IDBKeyRange, webkitIDBKeyRange, mozIDBKeyRange */
|
|
7958
|
-
if (typeof IDBKeyRange !== 'undefined') {
|
|
7959
|
-
return IDBKeyRange;
|
|
7960
|
-
}
|
|
7961
|
-
if (typeof webkitIDBKeyRange !== 'undefined') {
|
|
7962
|
-
return webkitIDBKeyRange;
|
|
7963
|
-
}
|
|
7964
|
-
if (typeof mozIDBKeyRange !== 'undefined') {
|
|
7965
|
-
return mozIDBKeyRange;
|
|
7966
|
-
}
|
|
7967
|
-
}
|
|
7968
7958
|
|
|
7969
|
-
var idbKeyRange = getIDBKeyRange();
|
|
7970
7959
|
|
|
7971
|
-
function getItemsIndexedDB(keys /*, callback*/) {
|
|
7972
|
-
keys = keys.slice();
|
|
7973
|
-
var localforageInstance = this;
|
|
7974
|
-
function comparer(a, b) {
|
|
7975
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
7976
|
-
}
|
|
7977
7960
|
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7961
|
+
function getAllItemsUsingIterate() {
|
|
7962
|
+
var localforageInstance = this;
|
|
7963
|
+
var accumulator = {};
|
|
7964
|
+
return localforageInstance.iterate(function (value, key /*, iterationNumber*/) {
|
|
7965
|
+
accumulator[key] = value;
|
|
7966
|
+
}).then(function () {
|
|
7967
|
+
return accumulator;
|
|
7968
|
+
});
|
|
7969
|
+
}
|
|
7983
7970
|
|
|
7984
|
-
|
|
7971
|
+
function getIDBKeyRange() {
|
|
7972
|
+
/* global IDBKeyRange, webkitIDBKeyRange, mozIDBKeyRange */
|
|
7973
|
+
if (typeof IDBKeyRange !== 'undefined') {
|
|
7974
|
+
return IDBKeyRange;
|
|
7975
|
+
}
|
|
7976
|
+
if (typeof webkitIDBKeyRange !== 'undefined') {
|
|
7977
|
+
return webkitIDBKeyRange;
|
|
7978
|
+
}
|
|
7979
|
+
if (typeof mozIDBKeyRange !== 'undefined') {
|
|
7980
|
+
return mozIDBKeyRange;
|
|
7981
|
+
}
|
|
7982
|
+
}
|
|
7985
7983
|
|
|
7986
|
-
|
|
7984
|
+
var idbKeyRange = getIDBKeyRange();
|
|
7987
7985
|
|
|
7988
|
-
|
|
7986
|
+
function getItemsIndexedDB(keys /*, callback*/) {
|
|
7987
|
+
keys = keys.slice();
|
|
7988
|
+
var localforageInstance = this;
|
|
7989
|
+
function comparer(a, b) {
|
|
7990
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
7991
|
+
}
|
|
7989
7992
|
|
|
7990
|
-
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
value = null;
|
|
7996
|
-
}
|
|
7997
|
-
resolve(value);
|
|
7998
|
-
};
|
|
7999
|
-
} else {
|
|
8000
|
-
req = store.openCursor(keyRangeValue);
|
|
8001
|
-
var result = {};
|
|
8002
|
-
var i = 0;
|
|
7993
|
+
var promise = new Promise(function (resolve, reject) {
|
|
7994
|
+
localforageInstance.ready().then(function () {
|
|
7995
|
+
// Thanks https://hacks.mozilla.org/2014/06/breaking-the-borders-of-indexeddb/
|
|
7996
|
+
var dbInfo = localforageInstance._dbInfo;
|
|
7997
|
+
var store = dbInfo.db.transaction(dbInfo.storeName, 'readonly').objectStore(dbInfo.storeName);
|
|
8003
7998
|
|
|
8004
|
-
|
|
8005
|
-
var cursor = req.result; // event.target.result;
|
|
7999
|
+
var set = keys.sort(comparer);
|
|
8006
8000
|
|
|
8007
|
-
|
|
8008
|
-
resolve(result);
|
|
8009
|
-
return;
|
|
8010
|
-
}
|
|
8001
|
+
var keyRangeValue = idbKeyRange.bound(keys[0], keys[keys.length - 1], false, false);
|
|
8011
8002
|
|
|
8012
|
-
|
|
8003
|
+
var req;
|
|
8013
8004
|
|
|
8014
|
-
|
|
8015
|
-
|
|
8005
|
+
if ('getAll' in store) {
|
|
8006
|
+
req = store.getAll(keyRangeValue);
|
|
8007
|
+
req.onsuccess = function () {
|
|
8008
|
+
var value = req.result;
|
|
8009
|
+
if (value === undefined) {
|
|
8010
|
+
value = null;
|
|
8011
|
+
}
|
|
8012
|
+
resolve(value);
|
|
8013
|
+
};
|
|
8014
|
+
} else {
|
|
8015
|
+
req = store.openCursor(keyRangeValue);
|
|
8016
|
+
var result = {};
|
|
8017
|
+
var i = 0;
|
|
8016
8018
|
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
resolve(result);
|
|
8020
|
-
return;
|
|
8021
|
-
}
|
|
8022
|
-
}
|
|
8019
|
+
req.onsuccess = function () /*event*/{
|
|
8020
|
+
var cursor = req.result; // event.target.result;
|
|
8023
8021
|
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
var value = cursor.value;
|
|
8029
|
-
if (value === undefined) {
|
|
8030
|
-
value = null;
|
|
8031
|
-
}
|
|
8022
|
+
if (!cursor) {
|
|
8023
|
+
resolve(result);
|
|
8024
|
+
return;
|
|
8025
|
+
}
|
|
8032
8026
|
|
|
8033
|
-
|
|
8034
|
-
// onfound(cursor.value);
|
|
8035
|
-
cursor.continue();
|
|
8036
|
-
} else {
|
|
8037
|
-
// cursor.key not yet at set[i]. Forward cursor to the next key to hunt for.
|
|
8038
|
-
cursor.continue(set[i]);
|
|
8039
|
-
}
|
|
8040
|
-
};
|
|
8041
|
-
}
|
|
8027
|
+
var key = cursor.key;
|
|
8042
8028
|
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
};
|
|
8046
|
-
}).catch(reject);
|
|
8047
|
-
});
|
|
8048
|
-
return promise;
|
|
8049
|
-
}
|
|
8029
|
+
while (key > set[i]) {
|
|
8030
|
+
i++; // The cursor has passed beyond this key. Check next.
|
|
8050
8031
|
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
var dbInfo = localforageInstance._dbInfo;
|
|
8058
|
-
dbInfo.db.transaction(function (t) {
|
|
8032
|
+
if (i === set.length) {
|
|
8033
|
+
// There is no next. Stop searching.
|
|
8034
|
+
resolve(result);
|
|
8035
|
+
return;
|
|
8036
|
+
}
|
|
8037
|
+
}
|
|
8059
8038
|
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8063
|
-
|
|
8039
|
+
if (key === set[i]) {
|
|
8040
|
+
// The current cursor value should be included and we should continue
|
|
8041
|
+
// a single step in case next item has the same key or possibly our
|
|
8042
|
+
// next key in set.
|
|
8043
|
+
var value = cursor.value;
|
|
8044
|
+
if (value === undefined) {
|
|
8045
|
+
value = null;
|
|
8046
|
+
}
|
|
8064
8047
|
|
|
8065
|
-
|
|
8048
|
+
result[key] = value;
|
|
8049
|
+
// onfound(cursor.value);
|
|
8050
|
+
cursor.continue();
|
|
8051
|
+
} else {
|
|
8052
|
+
// cursor.key not yet at set[i]. Forward cursor to the next key to hunt for.
|
|
8053
|
+
cursor.continue(set[i]);
|
|
8054
|
+
}
|
|
8055
|
+
};
|
|
8056
|
+
}
|
|
8066
8057
|
|
|
8067
|
-
|
|
8058
|
+
req.onerror = function () /*event*/{
|
|
8059
|
+
reject(req.error);
|
|
8060
|
+
};
|
|
8061
|
+
}).catch(reject);
|
|
8062
|
+
});
|
|
8063
|
+
return promise;
|
|
8064
|
+
}
|
|
8068
8065
|
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8066
|
+
function getItemsWebsql(keys /*, callback*/) {
|
|
8067
|
+
var localforageInstance = this;
|
|
8068
|
+
var promise = new Promise(function (resolve, reject) {
|
|
8069
|
+
localforageInstance.ready().then(function () {
|
|
8070
|
+
return getSerializerPromise(localforageInstance);
|
|
8071
|
+
}).then(function (serializer) {
|
|
8072
|
+
var dbInfo = localforageInstance._dbInfo;
|
|
8073
|
+
dbInfo.db.transaction(function (t) {
|
|
8073
8074
|
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
}
|
|
8075
|
+
var queryParts = new Array(keys.length);
|
|
8076
|
+
for (var i = 0, len = keys.length; i < len; i++) {
|
|
8077
|
+
queryParts[i] = '?';
|
|
8078
|
+
}
|
|
8079
8079
|
|
|
8080
|
-
|
|
8081
|
-
}
|
|
8080
|
+
t.executeSql('SELECT * FROM ' + dbInfo.storeName + ' WHERE (key IN (' + queryParts.join(',') + '))', keys, function (t, results) {
|
|
8082
8081
|
|
|
8083
|
-
|
|
8084
|
-
}, function (t, error) {
|
|
8085
|
-
reject(error);
|
|
8086
|
-
});
|
|
8087
|
-
});
|
|
8088
|
-
}).catch(reject);
|
|
8089
|
-
});
|
|
8090
|
-
return promise;
|
|
8091
|
-
}
|
|
8082
|
+
var result = {};
|
|
8092
8083
|
|
|
8093
|
-
|
|
8094
|
-
|
|
8084
|
+
var rows = results.rows;
|
|
8085
|
+
for (var i = 0, len = rows.length; i < len; i++) {
|
|
8086
|
+
var item = rows.item(i);
|
|
8087
|
+
var value = item.value;
|
|
8095
8088
|
|
|
8096
|
-
|
|
8097
|
-
|
|
8098
|
-
|
|
8099
|
-
|
|
8100
|
-
|
|
8101
|
-
if (currentDriver === localforageInstance.INDEXEDDB) {
|
|
8102
|
-
promise = getItemsIndexedDB.apply(localforageInstance, arguments);
|
|
8103
|
-
} else if (currentDriver === localforageInstance.WEBSQL) {
|
|
8104
|
-
promise = getItemsWebsql.apply(localforageInstance, arguments);
|
|
8105
|
-
} else {
|
|
8106
|
-
promise = getItemsGeneric.apply(localforageInstance, arguments);
|
|
8107
|
-
}
|
|
8108
|
-
}
|
|
8089
|
+
// Check to see if this is serialized content we need to
|
|
8090
|
+
// unpack.
|
|
8091
|
+
if (value) {
|
|
8092
|
+
value = serializer.deserialize(value);
|
|
8093
|
+
}
|
|
8109
8094
|
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
}
|
|
8095
|
+
result[item.key] = value;
|
|
8096
|
+
}
|
|
8113
8097
|
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
|
|
8098
|
+
resolve(result);
|
|
8099
|
+
}, function (t, error) {
|
|
8100
|
+
reject(error);
|
|
8101
|
+
});
|
|
8102
|
+
});
|
|
8103
|
+
}).catch(reject);
|
|
8104
|
+
});
|
|
8105
|
+
return promise;
|
|
8106
|
+
}
|
|
8107
|
+
|
|
8108
|
+
function localforageGetItems(keys, callback) {
|
|
8109
|
+
var localforageInstance = this;
|
|
8110
|
+
|
|
8111
|
+
var promise;
|
|
8112
|
+
if (!arguments.length || keys === null) {
|
|
8113
|
+
promise = getAllItemsUsingIterate.apply(localforageInstance);
|
|
8114
|
+
} else {
|
|
8115
|
+
var currentDriver = localforageInstance.driver();
|
|
8116
|
+
if (currentDriver === localforageInstance.INDEXEDDB) {
|
|
8117
|
+
promise = getItemsIndexedDB.apply(localforageInstance, arguments);
|
|
8118
|
+
} else if (currentDriver === localforageInstance.WEBSQL) {
|
|
8119
|
+
promise = getItemsWebsql.apply(localforageInstance, arguments);
|
|
8120
|
+
} else {
|
|
8121
|
+
promise = getItemsGeneric.apply(localforageInstance, arguments);
|
|
8122
|
+
}
|
|
8123
|
+
}
|
|
8124
|
+
|
|
8125
|
+
executeCallback(promise, callback);
|
|
8126
|
+
return promise;
|
|
8127
|
+
}
|
|
8128
|
+
|
|
8129
|
+
function extendPrototype(localforage$$1) {
|
|
8130
|
+
var localforagePrototype = Object.getPrototypeOf(localforage$$1);
|
|
8131
|
+
if (localforagePrototype) {
|
|
8132
|
+
localforagePrototype.getItems = localforageGetItems;
|
|
8133
|
+
localforagePrototype.getItems.indexedDB = function () {
|
|
8134
|
+
return getItemsIndexedDB.apply(this, arguments);
|
|
8135
|
+
};
|
|
8136
|
+
localforagePrototype.getItems.websql = function () {
|
|
8137
|
+
return getItemsWebsql.apply(this, arguments);
|
|
8138
|
+
};
|
|
8139
|
+
localforagePrototype.getItems.generic = function () {
|
|
8140
|
+
return getItemsGeneric.apply(this, arguments);
|
|
8141
|
+
};
|
|
8142
|
+
}
|
|
8143
|
+
}
|
|
8144
|
+
|
|
8145
|
+
var extendPrototypeResult = extendPrototype(localforage);
|
|
8146
|
+
|
|
8147
|
+
exports.localforageGetItems = localforageGetItems;
|
|
8148
|
+
exports.extendPrototype = extendPrototype;
|
|
8149
|
+
exports.extendPrototypeResult = extendPrototypeResult;
|
|
8150
|
+
exports.getItemsGeneric = getItemsGeneric;
|
|
8151
|
+
|
|
8152
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
8153
|
+
|
|
8154
|
+
})));
|
|
8155
|
+
} (localforageGetitems$1, localforageGetitems$1.exports));
|
|
8156
|
+
return localforageGetitems$1.exports;
|
|
8128
8157
|
}
|
|
8129
8158
|
|
|
8130
|
-
|
|
8159
|
+
var localforageGetitemsExports = requireLocalforageGetitems();
|
|
8131
8160
|
|
|
8132
8161
|
/** Used for built-in method references. */
|
|
8133
8162
|
var objectProto$7 = Object.prototype;
|
|
@@ -8580,7 +8609,7 @@ function sync(method, model, options = {}) {
|
|
|
8580
8609
|
const IN_MEMORY = _driver;
|
|
8581
8610
|
localForage.defineDriver(memoryDriver);
|
|
8582
8611
|
localforageSetitemsExports.extendPrototype(localForage);
|
|
8583
|
-
extendPrototype(localForage);
|
|
8612
|
+
localforageGetitemsExports.extendPrototype(localForage);
|
|
8584
8613
|
// Every storage instance is registered with a WeakRef so that flushAll() can
|
|
8585
8614
|
// reach pending writes without keeping instances alive. There's no leak and no
|
|
8586
8615
|
// lifecycle hook to maintain: an instance is collected once its owning model or
|
|
@@ -8770,33 +8799,17 @@ class PersistentStorage {
|
|
|
8770
8799
|
caughtError = error instanceof Error ? error : new Error(error?.message ?? String(error));
|
|
8771
8800
|
}
|
|
8772
8801
|
}
|
|
8773
|
-
if (
|
|
8774
|
-
|
|
8775
|
-
// When storing, we don't pass back the response (which is
|
|
8776
|
-
// the set attributes returned from localforage because
|
|
8777
|
-
// Skeletor sets them again on the model and due to the async
|
|
8778
|
-
// nature of localforage it can cause stale attributes to be
|
|
8779
|
-
// set on a model after it's been updated in the meantime.
|
|
8780
|
-
const data = method === 'read' ? resp : null;
|
|
8781
|
-
options.success(data, options);
|
|
8782
|
-
}
|
|
8783
|
-
}
|
|
8784
|
-
else if (method === 'read' && !caughtError) {
|
|
8785
|
-
// A read that finds no record is a normal empty result (first run /
|
|
8786
|
-
// empty storage), not an error. Resolve with `null` so the callback
|
|
8787
|
-
// and promise forms of fetch() agree and a first-run read never
|
|
8788
|
-
// rejects.
|
|
8789
|
-
if (options && options.success) {
|
|
8790
|
-
options.success(null, options);
|
|
8791
|
-
}
|
|
8802
|
+
if (caughtError) {
|
|
8803
|
+
options?.error?.(caughtError);
|
|
8792
8804
|
}
|
|
8793
|
-
else {
|
|
8794
|
-
//
|
|
8795
|
-
//
|
|
8796
|
-
//
|
|
8797
|
-
|
|
8798
|
-
|
|
8799
|
-
|
|
8805
|
+
else if (options?.success) {
|
|
8806
|
+
// When storing, we don't pass back the response (which is the set
|
|
8807
|
+
// attributes returned from localforage) because Skeletor sets them
|
|
8808
|
+
// again on the model and due to the async nature of localforage it can
|
|
8809
|
+
// cause stale attributes to be set on a model after it's been updated
|
|
8810
|
+
// in the meantime.
|
|
8811
|
+
const data = method === 'read' ? (resp ?? null) : null;
|
|
8812
|
+
options.success(data, options);
|
|
8800
8813
|
}
|
|
8801
8814
|
}
|
|
8802
8815
|
localSync.__name__ = 'localSync';
|
|
@@ -10907,18 +10920,18 @@ class Model extends EventEmitterObject {
|
|
|
10907
10920
|
this.initialize.apply(this, arguments);
|
|
10908
10921
|
// Reset changed after initial set
|
|
10909
10922
|
this.changed = {};
|
|
10910
|
-
// When autoSync is on, `
|
|
10911
|
-
// uniformly `await model.
|
|
10923
|
+
// When autoSync is on, `hydrated` is always a Promise so callers can
|
|
10924
|
+
// uniformly `await model.hydrated`. It only hydrates from storage when
|
|
10912
10925
|
// there's something to load (storage configured and the model isn't new);
|
|
10913
10926
|
// otherwise it's already ready and resolves immediately.
|
|
10914
10927
|
if (this.autoSync) {
|
|
10915
10928
|
if (getStorage(this) && !this.isNew()) {
|
|
10916
10929
|
__classPrivateFieldSet(this, _Model_state, 'hydrating', "f");
|
|
10917
|
-
this.
|
|
10930
|
+
this.hydrated = __classPrivateFieldGet(this, _Model_instances, "m", _Model_hydrate).call(this);
|
|
10918
10931
|
}
|
|
10919
10932
|
else {
|
|
10920
10933
|
__classPrivateFieldSet(this, _Model_state, 'ready', "f");
|
|
10921
|
-
this.
|
|
10934
|
+
this.hydrated = Promise.resolve();
|
|
10922
10935
|
}
|
|
10923
10936
|
}
|
|
10924
10937
|
else {
|
|
@@ -11091,7 +11104,7 @@ class Model extends EventEmitterObject {
|
|
|
11091
11104
|
// Guard must come after arg normalization: when called as set(obj, opts),
|
|
11092
11105
|
// fromStorage lives in `val` (second arg), not `options` (third arg).
|
|
11093
11106
|
if (this.autoSync && __classPrivateFieldGet(this, _Model_state, "f") === 'hydrating' && !options.fromStorage) {
|
|
11094
|
-
throw new Error(`Skeletor: set() called on an autoSync model before
|
|
11107
|
+
throw new Error(`Skeletor: set() called on an autoSync model before hydration resolved. Await model.hydrated first.`);
|
|
11095
11108
|
}
|
|
11096
11109
|
// Run validation.
|
|
11097
11110
|
if (!this._validate(attrs, options))
|
|
@@ -11531,11 +11544,11 @@ class Collection extends EventEmitterObject {
|
|
|
11531
11544
|
if (models)
|
|
11532
11545
|
this.reset(models, Object.assign({ silent: true }, options));
|
|
11533
11546
|
this[Symbol.iterator] = this.values;
|
|
11534
|
-
// When autoSync is on, `
|
|
11535
|
-
// uniformly `await collection.
|
|
11547
|
+
// When autoSync is on, `hydrated` is always a Promise so callers can
|
|
11548
|
+
// uniformly `await collection.hydrated`; it resolves immediately when
|
|
11536
11549
|
// there's no storage to hydrate from.
|
|
11537
11550
|
if (this.autoSync) {
|
|
11538
|
-
this.
|
|
11551
|
+
this.hydrated = getStorage(this) ? __classPrivateFieldGet(this, _Collection_instances, "m", _Collection_hydrate).call(this) : Promise.resolve();
|
|
11539
11552
|
}
|
|
11540
11553
|
}
|
|
11541
11554
|
get comparator() {
|
|
@@ -11567,7 +11580,7 @@ class Collection extends EventEmitterObject {
|
|
|
11567
11580
|
}
|
|
11568
11581
|
/**
|
|
11569
11582
|
* Override to return `true` to automatically load the collection from
|
|
11570
|
-
* storage on construction. Await `
|
|
11583
|
+
* storage on construction. Await `hydrated` to know when hydration
|
|
11571
11584
|
* is complete.
|
|
11572
11585
|
*
|
|
11573
11586
|
* Note: collection `autoSync` is hydrate-only. Unlike `Model`, it does
|