dexie 4.0.1-beta.6 → 4.0.1-beta.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/dexie.d.ts +3 -3
- package/dist/dexie.js +154 -78
- package/dist/dexie.js.map +1 -1
- package/dist/dexie.min.js +1 -1
- package/dist/dexie.min.js.map +1 -1
- package/dist/dexie.mjs +154 -78
- package/dist/dexie.mjs.map +1 -1
- package/dist/modern/dexie.min.mjs +1 -1
- package/dist/modern/dexie.min.mjs.map +1 -1
- package/dist/modern/dexie.mjs +146 -73
- package/dist/modern/dexie.mjs.map +1 -1
- package/package.json +2 -2
- package/tunnel.pid +0 -1
package/dist/dexie.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* By David Fahlander, david.fahlander@gmail.com
|
|
6
6
|
*
|
|
7
|
-
* Version 4.0.1-beta.
|
|
7
|
+
* Version 4.0.1-beta.8, Wed Feb 07 2024
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -1120,7 +1120,7 @@ export type InsertType<T, OptionalProps extends keyof T> = Omit<T, OptionalProps
|
|
|
1120
1120
|
export type IDType<T, TKeyPropNameOrKeyType> = IsStrictlyAny<T> extends true ? TKeyPropNameOrKeyType : TKeyPropNameOrKeyType extends string ? TKeyPropNameOrKeyType extends keyof T ? T[TKeyPropNameOrKeyType] : TKeyPropNameOrKeyType : TKeyPropNameOrKeyType;
|
|
1121
1121
|
export type EntityTable<T, TKeyPropName extends keyof T = never, TInsertType = InsertType<T, TKeyPropName>> = Table<T, IDType<T, TKeyPropName>, TInsertType>;
|
|
1122
1122
|
export declare var Dexie: DexieConstructor;
|
|
1123
|
-
export interface _Table<T, TKey> extends Table<T, TKey> {
|
|
1123
|
+
export interface _Table<T, TKey, TInsertType> extends Table<T, TKey, TInsertType> {
|
|
1124
1124
|
}
|
|
1125
1125
|
export interface _Collection<T, TKey> extends Collection<T, TKey> {
|
|
1126
1126
|
}
|
|
@@ -1128,7 +1128,7 @@ export declare module Dexie {
|
|
|
1128
1128
|
// The "Dexie.Promise" type.
|
|
1129
1129
|
type Promise<T = any> = PromiseExtended<T>; // Because many samples have been Dexie.Promise.
|
|
1130
1130
|
// The "Dexie.Table" interface. Same as named exported interface Table.
|
|
1131
|
-
interface Table<T = any, Key = any> extends _Table<T, Key> {
|
|
1131
|
+
interface Table<T = any, Key = any, TInsertType = T> extends _Table<T, Key, TInsertType> {
|
|
1132
1132
|
} // Because all samples have been Dexie.Table<...>
|
|
1133
1133
|
// The "Dexie.Collection" interface. Same as named exported interface Collection.
|
|
1134
1134
|
interface Collection<T = any, Key = any> extends _Collection<T, Key> {
|
package/dist/dexie.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* By David Fahlander, david.fahlander@gmail.com
|
|
6
6
|
*
|
|
7
|
-
* Version 4.0.1-beta.
|
|
7
|
+
* Version 4.0.1-beta.8, Wed Feb 07 2024
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -232,7 +232,7 @@
|
|
|
232
232
|
function flatten(a) {
|
|
233
233
|
return concat.apply([], a);
|
|
234
234
|
}
|
|
235
|
-
var intrinsicTypeNames = "Array,Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey"
|
|
235
|
+
var intrinsicTypeNames = "BigUint64Array,BigInt64Array,Array,Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey"
|
|
236
236
|
.split(',').concat(flatten([8, 16, 32, 64].map(function (num) { return ["Int", "Uint", "Float"].map(function (t) { return t + num + "Array"; }); }))).filter(function (t) { return _global[t]; });
|
|
237
237
|
var intrinsicTypes = new Set(intrinsicTypeNames.map(function (t) { return _global[t]; }));
|
|
238
238
|
function cloneSimpleObjectTree(o) {
|
|
@@ -1235,7 +1235,7 @@
|
|
|
1235
1235
|
return rejection(new exceptions.DatabaseClosed(db._state.dbOpenError));
|
|
1236
1236
|
}
|
|
1237
1237
|
if (!db._state.isBeingOpened) {
|
|
1238
|
-
if (!db.
|
|
1238
|
+
if (!db._state.autoOpen)
|
|
1239
1239
|
return rejection(new exceptions.DatabaseClosed());
|
|
1240
1240
|
db.open().catch(nop);
|
|
1241
1241
|
}
|
|
@@ -1271,7 +1271,7 @@
|
|
|
1271
1271
|
}
|
|
1272
1272
|
}
|
|
1273
1273
|
|
|
1274
|
-
var DEXIE_VERSION = '4.0.1-beta.
|
|
1274
|
+
var DEXIE_VERSION = '4.0.1-beta.8';
|
|
1275
1275
|
var maxString = String.fromCharCode(65535);
|
|
1276
1276
|
var minKey = -Infinity;
|
|
1277
1277
|
var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
|
|
@@ -1454,7 +1454,7 @@
|
|
|
1454
1454
|
.equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
|
|
1455
1455
|
}
|
|
1456
1456
|
if (!compoundIndex && debug)
|
|
1457
|
-
console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit
|
|
1457
|
+
console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit from a ") +
|
|
1458
1458
|
"compound index [".concat(keyPaths.join('+'), "]"));
|
|
1459
1459
|
var idxByName = this.schema.idxByName;
|
|
1460
1460
|
var idb = this.db._deps.indexedDB;
|
|
@@ -3410,6 +3410,10 @@
|
|
|
3410
3410
|
}
|
|
3411
3411
|
function runUpgraders(db, oldVersion, idbUpgradeTrans, reject) {
|
|
3412
3412
|
var globalSchema = db._dbSchema;
|
|
3413
|
+
if (idbUpgradeTrans.objectStoreNames.contains('$meta') && !globalSchema.$meta) {
|
|
3414
|
+
globalSchema.$meta = createTableSchema("$meta", parseIndexSyntax("")[0], []);
|
|
3415
|
+
db._storeNames.push('$meta');
|
|
3416
|
+
}
|
|
3413
3417
|
var trans = db._createTransaction('readwrite', db._storeNames, globalSchema);
|
|
3414
3418
|
trans.create(idbUpgradeTrans);
|
|
3415
3419
|
trans._completion.catch(reject);
|
|
@@ -3425,16 +3429,60 @@
|
|
|
3425
3429
|
generateMiddlewareStacks(db, idbUpgradeTrans);
|
|
3426
3430
|
DexiePromise.follow(function () { return db.on.populate.fire(trans); }).catch(rejectTransaction);
|
|
3427
3431
|
}
|
|
3428
|
-
else
|
|
3429
|
-
|
|
3432
|
+
else {
|
|
3433
|
+
generateMiddlewareStacks(db, idbUpgradeTrans);
|
|
3434
|
+
return getExistingVersion(db, trans, oldVersion)
|
|
3435
|
+
.then(function (oldVersion) { return updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans); })
|
|
3436
|
+
.catch(rejectTransaction);
|
|
3437
|
+
}
|
|
3430
3438
|
});
|
|
3431
3439
|
}
|
|
3440
|
+
function patchCurrentVersion(db, idbUpgradeTrans) {
|
|
3441
|
+
createMissingTables(db._dbSchema, idbUpgradeTrans);
|
|
3442
|
+
if (idbUpgradeTrans.db.version % 10 === 0 && !idbUpgradeTrans.objectStoreNames.contains('$meta')) {
|
|
3443
|
+
idbUpgradeTrans.db.createObjectStore('$meta').add(Math.ceil((idbUpgradeTrans.db.version / 10) - 1), 'version');
|
|
3444
|
+
}
|
|
3445
|
+
var globalSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
|
|
3446
|
+
adjustToExistingIndexNames(db, db._dbSchema, idbUpgradeTrans);
|
|
3447
|
+
var diff = getSchemaDiff(globalSchema, db._dbSchema);
|
|
3448
|
+
var _loop_1 = function (tableChange) {
|
|
3449
|
+
if (tableChange.change.length || tableChange.recreate) {
|
|
3450
|
+
console.warn("Unable to patch indexes of table ".concat(tableChange.name, " because it has changes on the type of index or primary key."));
|
|
3451
|
+
return { value: void 0 };
|
|
3452
|
+
}
|
|
3453
|
+
var store = idbUpgradeTrans.objectStore(tableChange.name);
|
|
3454
|
+
tableChange.add.forEach(function (idx) {
|
|
3455
|
+
if (debug)
|
|
3456
|
+
console.debug("Dexie upgrade patch: Creating missing index ".concat(tableChange.name, ".").concat(idx.src));
|
|
3457
|
+
addIndex(store, idx);
|
|
3458
|
+
});
|
|
3459
|
+
};
|
|
3460
|
+
for (var _i = 0, _a = diff.change; _i < _a.length; _i++) {
|
|
3461
|
+
var tableChange = _a[_i];
|
|
3462
|
+
var state_1 = _loop_1(tableChange);
|
|
3463
|
+
if (typeof state_1 === "object")
|
|
3464
|
+
return state_1.value;
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
function getExistingVersion(db, trans, oldVersion) {
|
|
3468
|
+
if (trans.storeNames.includes('$meta')) {
|
|
3469
|
+
return trans.table('$meta').get('version').then(function (metaVersion) {
|
|
3470
|
+
return metaVersion != null ? metaVersion : oldVersion;
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
else {
|
|
3474
|
+
return DexiePromise.resolve(oldVersion);
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3432
3477
|
function updateTablesAndIndexes(db, oldVersion, trans, idbUpgradeTrans) {
|
|
3433
3478
|
var queue = [];
|
|
3434
3479
|
var versions = db._versions;
|
|
3435
3480
|
var globalSchema = db._dbSchema = buildGlobalSchema(db, db.idbdb, idbUpgradeTrans);
|
|
3436
3481
|
var anyContentUpgraderHasRun = false;
|
|
3437
3482
|
var versToRun = versions.filter(function (v) { return v._cfg.version >= oldVersion; });
|
|
3483
|
+
if (versToRun.length === 0) {
|
|
3484
|
+
return DexiePromise.resolve();
|
|
3485
|
+
}
|
|
3438
3486
|
versToRun.forEach(function (version) {
|
|
3439
3487
|
queue.push(function () {
|
|
3440
3488
|
var oldSchema = globalSchema;
|
|
@@ -3499,6 +3547,18 @@
|
|
|
3499
3547
|
setApiOnPlace(db, [db.Transaction.prototype], db._storeNames, db._dbSchema);
|
|
3500
3548
|
trans.schema = db._dbSchema;
|
|
3501
3549
|
});
|
|
3550
|
+
queue.push(function (idbtrans) {
|
|
3551
|
+
if (db.idbdb.objectStoreNames.contains('$meta')) {
|
|
3552
|
+
if (Math.ceil(db.idbdb.version / 10) === version._cfg.version) {
|
|
3553
|
+
db.idbdb.deleteObjectStore('$meta');
|
|
3554
|
+
delete db._dbSchema.$meta;
|
|
3555
|
+
db._storeNames = db._storeNames.filter(function (name) { return name !== '$meta'; });
|
|
3556
|
+
}
|
|
3557
|
+
else {
|
|
3558
|
+
idbtrans.objectStore('$meta').put(version._cfg.version, 'version');
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
});
|
|
3502
3562
|
});
|
|
3503
3563
|
function runQueue() {
|
|
3504
3564
|
return queue.length ? DexiePromise.resolve(queue.shift()(trans.idbtrans)).then(runQueue) :
|
|
@@ -3573,6 +3633,8 @@
|
|
|
3573
3633
|
function createMissingTables(newSchema, idbtrans) {
|
|
3574
3634
|
keys(newSchema).forEach(function (tableName) {
|
|
3575
3635
|
if (!idbtrans.db.objectStoreNames.contains(tableName)) {
|
|
3636
|
+
if (debug)
|
|
3637
|
+
console.debug('Dexie: Creating missing table', tableName);
|
|
3576
3638
|
createTable(idbtrans, tableName, newSchema[tableName].primKey, newSchema[tableName].indexes);
|
|
3577
3639
|
}
|
|
3578
3640
|
});
|
|
@@ -3591,7 +3653,7 @@
|
|
|
3591
3653
|
dbStoreNames.forEach(function (storeName) {
|
|
3592
3654
|
var store = tmpTrans.objectStore(storeName);
|
|
3593
3655
|
var keyPath = store.keyPath;
|
|
3594
|
-
var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || "",
|
|
3656
|
+
var primKey = createIndexSpec(nameFromKeyPath(keyPath), keyPath || "", true, false, !!store.autoIncrement, keyPath && typeof keyPath !== "string", true);
|
|
3595
3657
|
var indexes = [];
|
|
3596
3658
|
for (var j = 0; j < store.indexNames.length; ++j) {
|
|
3597
3659
|
var idbindex = store.index(store.indexNames[j]);
|
|
@@ -3658,6 +3720,7 @@
|
|
|
3658
3720
|
if (stores[tableName] !== null) {
|
|
3659
3721
|
var indexes = parseIndexSyntax(stores[tableName]);
|
|
3660
3722
|
var primKey = indexes.shift();
|
|
3723
|
+
primKey.unique = true;
|
|
3661
3724
|
if (primKey.multi)
|
|
3662
3725
|
throw new exceptions.Schema("Primary key cannot be multi-valued");
|
|
3663
3726
|
indexes.forEach(function (idx) {
|
|
@@ -3941,7 +4004,7 @@
|
|
|
3941
4004
|
}
|
|
3942
4005
|
|
|
3943
4006
|
function obsSetsOverlap(os1, os2) {
|
|
3944
|
-
return Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); });
|
|
4007
|
+
return os1.all || os2.all || Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); });
|
|
3945
4008
|
}
|
|
3946
4009
|
|
|
3947
4010
|
var cache = {};
|
|
@@ -3963,13 +4026,21 @@
|
|
|
3963
4026
|
function signalSubscribersNow(updatedParts, deleteAffectedCacheEntries) {
|
|
3964
4027
|
if (deleteAffectedCacheEntries === void 0) { deleteAffectedCacheEntries = false; }
|
|
3965
4028
|
var queriesToSignal = new Set();
|
|
3966
|
-
|
|
3967
|
-
var
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
4029
|
+
if (updatedParts.all) {
|
|
4030
|
+
for (var _i = 0, _a = Object.values(cache); _i < _a.length; _i++) {
|
|
4031
|
+
var tblCache = _a[_i];
|
|
4032
|
+
signalTableSubscribersNow(tblCache, updatedParts, queriesToSignal, deleteAffectedCacheEntries);
|
|
4033
|
+
}
|
|
4034
|
+
}
|
|
4035
|
+
else {
|
|
4036
|
+
for (var key in updatedParts) {
|
|
4037
|
+
var parts = /^idb\:\/\/(.*)\/(.*)\//.exec(key);
|
|
4038
|
+
if (parts) {
|
|
4039
|
+
var dbName = parts[1], tableName = parts[2];
|
|
4040
|
+
var tblCache = cache["idb://".concat(dbName, "/").concat(tableName)];
|
|
4041
|
+
if (tblCache)
|
|
4042
|
+
signalTableSubscribersNow(tblCache, updatedParts, queriesToSignal, deleteAffectedCacheEntries);
|
|
4043
|
+
}
|
|
3973
4044
|
}
|
|
3974
4045
|
}
|
|
3975
4046
|
queriesToSignal.forEach(function (requery) { return requery(); });
|
|
@@ -4011,6 +4082,8 @@
|
|
|
4011
4082
|
state.dbOpenError = null;
|
|
4012
4083
|
state.openComplete = false;
|
|
4013
4084
|
var openCanceller = state.openCanceller;
|
|
4085
|
+
var nativeVerToOpen = Math.round(db.verno * 10);
|
|
4086
|
+
var schemaPatchMode = false;
|
|
4014
4087
|
function throwIfCancelled() {
|
|
4015
4088
|
if (state.openCanceller !== openCanceller)
|
|
4016
4089
|
throw new exceptions.DatabaseClosed('db.open() was cancelled');
|
|
@@ -4022,9 +4095,9 @@
|
|
|
4022
4095
|
if (!indexedDB)
|
|
4023
4096
|
throw new exceptions.MissingAPI();
|
|
4024
4097
|
var dbName = db.name;
|
|
4025
|
-
var req = state.autoSchema ?
|
|
4098
|
+
var req = state.autoSchema || !nativeVerToOpen ?
|
|
4026
4099
|
indexedDB.open(dbName) :
|
|
4027
|
-
indexedDB.open(dbName,
|
|
4100
|
+
indexedDB.open(dbName, nativeVerToOpen);
|
|
4028
4101
|
if (!req)
|
|
4029
4102
|
throw new exceptions.MissingAPI();
|
|
4030
4103
|
req.onerror = eventRejectHandler(reject);
|
|
@@ -4045,6 +4118,9 @@
|
|
|
4045
4118
|
var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
|
|
4046
4119
|
wasCreated = oldVer < 1;
|
|
4047
4120
|
db.idbdb = req.result;
|
|
4121
|
+
if (schemaPatchMode) {
|
|
4122
|
+
patchCurrentVersion(db, upgradeTransaction);
|
|
4123
|
+
}
|
|
4048
4124
|
runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
|
|
4049
4125
|
}
|
|
4050
4126
|
}, reject);
|
|
@@ -4059,8 +4135,12 @@
|
|
|
4059
4135
|
readGlobalSchema(db, idbdb, tmpTrans);
|
|
4060
4136
|
else {
|
|
4061
4137
|
adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
|
|
4062
|
-
if (!verifyInstalledSchema(db, tmpTrans)) {
|
|
4063
|
-
console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version().
|
|
4138
|
+
if (!verifyInstalledSchema(db, tmpTrans) && !schemaPatchMode) {
|
|
4139
|
+
console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Dexie will add missing parts and increment native version number to workaround this.");
|
|
4140
|
+
idbdb.close();
|
|
4141
|
+
nativeVerToOpen = idbdb.version + 1;
|
|
4142
|
+
schemaPatchMode = true;
|
|
4143
|
+
return resolve(tryOpenDB());
|
|
4064
4144
|
}
|
|
4065
4145
|
}
|
|
4066
4146
|
generateMiddlewareStacks(db, tmpTrans);
|
|
@@ -4080,14 +4160,22 @@
|
|
|
4080
4160
|
resolve();
|
|
4081
4161
|
}, reject);
|
|
4082
4162
|
}).catch(function (err) {
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4163
|
+
switch (err === null || err === void 0 ? void 0 : err.name) {
|
|
4164
|
+
case "UnknownError":
|
|
4165
|
+
if (state.PR1398_maxLoop > 0) {
|
|
4166
|
+
state.PR1398_maxLoop--;
|
|
4167
|
+
console.warn('Dexie: Workaround for Chrome UnknownError on open()');
|
|
4168
|
+
return tryOpenDB();
|
|
4169
|
+
}
|
|
4170
|
+
break;
|
|
4171
|
+
case "VersionError":
|
|
4172
|
+
if (nativeVerToOpen > 0) {
|
|
4173
|
+
nativeVerToOpen = 0;
|
|
4174
|
+
return tryOpenDB();
|
|
4175
|
+
}
|
|
4176
|
+
break;
|
|
4090
4177
|
}
|
|
4178
|
+
return DexiePromise.reject(err);
|
|
4091
4179
|
}); };
|
|
4092
4180
|
return DexiePromise.race([
|
|
4093
4181
|
openCanceller,
|
|
@@ -4811,6 +4899,8 @@
|
|
|
4811
4899
|
if (!ops || ops.length === 0)
|
|
4812
4900
|
return result;
|
|
4813
4901
|
var index = req.query.index;
|
|
4902
|
+
var multiEntry = index.multiEntry;
|
|
4903
|
+
var queryRange = req.query.range;
|
|
4814
4904
|
var primaryKey = table.schema.primaryKey;
|
|
4815
4905
|
var extractPrimKey = primaryKey.extractKey;
|
|
4816
4906
|
var extractIndex = index.extractKey;
|
|
@@ -4819,7 +4909,10 @@
|
|
|
4819
4909
|
var modifedResult = result;
|
|
4820
4910
|
var includedValues = op.type === 'add' || op.type === 'put'
|
|
4821
4911
|
? op.values.filter(function (v) {
|
|
4822
|
-
|
|
4912
|
+
var key = extractIndex(v);
|
|
4913
|
+
return multiEntry && isArray(key)
|
|
4914
|
+
? key.some(function (k) { return isWithinRange(k, queryRange); })
|
|
4915
|
+
: isWithinRange(key, queryRange);
|
|
4823
4916
|
}).map(function (v) {
|
|
4824
4917
|
v = deepClone(v);
|
|
4825
4918
|
if (immutable)
|
|
@@ -5198,7 +5291,8 @@
|
|
|
5198
5291
|
cancelOpen: nop,
|
|
5199
5292
|
openCanceller: null,
|
|
5200
5293
|
autoSchema: true,
|
|
5201
|
-
PR1398_maxLoop: 3
|
|
5294
|
+
PR1398_maxLoop: 3,
|
|
5295
|
+
autoOpen: options.autoOpen,
|
|
5202
5296
|
};
|
|
5203
5297
|
state.dbReadyPromise = new DexiePromise(function (resolve) {
|
|
5204
5298
|
state.dbReadyResolve = resolve;
|
|
@@ -5315,7 +5409,7 @@
|
|
|
5315
5409
|
return reject(new exceptions.DatabaseClosed(_this._state.dbOpenError));
|
|
5316
5410
|
}
|
|
5317
5411
|
if (!_this._state.isBeingOpened) {
|
|
5318
|
-
if (!_this.
|
|
5412
|
+
if (!_this._state.autoOpen) {
|
|
5319
5413
|
reject(new exceptions.DatabaseClosed());
|
|
5320
5414
|
return;
|
|
5321
5415
|
}
|
|
@@ -5370,10 +5464,14 @@
|
|
|
5370
5464
|
};
|
|
5371
5465
|
Dexie.prototype.close = function (_a) {
|
|
5372
5466
|
var _b = _a === void 0 ? { disableAutoOpen: true } : _a, disableAutoOpen = _b.disableAutoOpen;
|
|
5467
|
+
var wasOpen = this.isOpen();
|
|
5373
5468
|
this._close();
|
|
5374
5469
|
var state = this._state;
|
|
5375
5470
|
if (disableAutoOpen)
|
|
5376
|
-
this.
|
|
5471
|
+
this._state.autoOpen = false;
|
|
5472
|
+
else if (wasOpen && this._options.autoOpen) {
|
|
5473
|
+
this._state.autoOpen = true;
|
|
5474
|
+
}
|
|
5377
5475
|
state.dbOpenError = new exceptions.DatabaseClosed();
|
|
5378
5476
|
if (state.isBeingOpened)
|
|
5379
5477
|
state.cancelOpen(state.dbOpenError);
|
|
@@ -5749,62 +5847,40 @@
|
|
|
5749
5847
|
}
|
|
5750
5848
|
var propagatingLocally = false;
|
|
5751
5849
|
|
|
5850
|
+
var bc;
|
|
5851
|
+
var createBC = function () { };
|
|
5752
5852
|
if (typeof BroadcastChannel !== 'undefined') {
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5853
|
+
createBC = function () {
|
|
5854
|
+
bc = new BroadcastChannel(STORAGE_MUTATED_DOM_EVENT_NAME);
|
|
5855
|
+
bc.onmessage = function (ev) { return ev.data && propagateLocally(ev.data); };
|
|
5856
|
+
};
|
|
5857
|
+
createBC();
|
|
5858
|
+
if (typeof bc.unref === 'function') {
|
|
5859
|
+
bc.unref();
|
|
5756
5860
|
}
|
|
5757
5861
|
globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, function (changedParts) {
|
|
5758
5862
|
if (!propagatingLocally) {
|
|
5759
|
-
|
|
5863
|
+
bc.postMessage(changedParts);
|
|
5760
5864
|
}
|
|
5761
5865
|
});
|
|
5762
|
-
bc_1.onmessage = function (ev) {
|
|
5763
|
-
if (ev.data)
|
|
5764
|
-
propagateLocally(ev.data);
|
|
5765
|
-
};
|
|
5766
5866
|
}
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
});
|
|
5783
|
-
});
|
|
5784
|
-
}
|
|
5785
|
-
}
|
|
5867
|
+
|
|
5868
|
+
if (typeof addEventListener !== 'undefined') {
|
|
5869
|
+
addEventListener('pagehide', function (event) {
|
|
5870
|
+
if (event.persisted) {
|
|
5871
|
+
bc === null || bc === void 0 ? void 0 : bc.close();
|
|
5872
|
+
}
|
|
5873
|
+
for (var _i = 0, connections_1 = connections; _i < connections_1.length; _i++) {
|
|
5874
|
+
var db = connections_1[_i];
|
|
5875
|
+
db.close({ disableAutoOpen: false });
|
|
5876
|
+
}
|
|
5877
|
+
});
|
|
5878
|
+
addEventListener('pageshow', function (event) {
|
|
5879
|
+
if (event.persisted) {
|
|
5880
|
+
createBC();
|
|
5881
|
+
propagateLocally({ all: new RangeSet(-Infinity, [[]]) });
|
|
5786
5882
|
}
|
|
5787
|
-
catch (_a) { }
|
|
5788
5883
|
});
|
|
5789
|
-
if (typeof addEventListener !== 'undefined') {
|
|
5790
|
-
addEventListener('storage', function (ev) {
|
|
5791
|
-
if (ev.key === STORAGE_MUTATED_DOM_EVENT_NAME) {
|
|
5792
|
-
var data = JSON.parse(ev.newValue);
|
|
5793
|
-
if (data)
|
|
5794
|
-
propagateLocally(data.changedParts);
|
|
5795
|
-
}
|
|
5796
|
-
});
|
|
5797
|
-
}
|
|
5798
|
-
var swContainer = self.document && navigator.serviceWorker;
|
|
5799
|
-
if (swContainer) {
|
|
5800
|
-
swContainer.addEventListener('message', propagateMessageLocally);
|
|
5801
|
-
}
|
|
5802
|
-
}
|
|
5803
|
-
function propagateMessageLocally(_a) {
|
|
5804
|
-
var data = _a.data;
|
|
5805
|
-
if (data && data.type === STORAGE_MUTATED_DOM_EVENT_NAME) {
|
|
5806
|
-
propagateLocally(data.changedParts);
|
|
5807
|
-
}
|
|
5808
5884
|
}
|
|
5809
5885
|
|
|
5810
5886
|
DexiePromise.rejectionMapper = mapError;
|