dexie 4.0.1-beta.7 → 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 +1 -1
- package/dist/dexie.js +104 -20
- 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 +104 -20
- 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 +99 -21
- package/dist/modern/dexie.mjs.map +1 -1
- package/package.json +2 -2
package/dist/dexie.d.ts
CHANGED
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>.";
|
|
@@ -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
|
});
|
|
@@ -4020,6 +4082,8 @@
|
|
|
4020
4082
|
state.dbOpenError = null;
|
|
4021
4083
|
state.openComplete = false;
|
|
4022
4084
|
var openCanceller = state.openCanceller;
|
|
4085
|
+
var nativeVerToOpen = Math.round(db.verno * 10);
|
|
4086
|
+
var schemaPatchMode = false;
|
|
4023
4087
|
function throwIfCancelled() {
|
|
4024
4088
|
if (state.openCanceller !== openCanceller)
|
|
4025
4089
|
throw new exceptions.DatabaseClosed('db.open() was cancelled');
|
|
@@ -4031,9 +4095,9 @@
|
|
|
4031
4095
|
if (!indexedDB)
|
|
4032
4096
|
throw new exceptions.MissingAPI();
|
|
4033
4097
|
var dbName = db.name;
|
|
4034
|
-
var req = state.autoSchema ?
|
|
4098
|
+
var req = state.autoSchema || !nativeVerToOpen ?
|
|
4035
4099
|
indexedDB.open(dbName) :
|
|
4036
|
-
indexedDB.open(dbName,
|
|
4100
|
+
indexedDB.open(dbName, nativeVerToOpen);
|
|
4037
4101
|
if (!req)
|
|
4038
4102
|
throw new exceptions.MissingAPI();
|
|
4039
4103
|
req.onerror = eventRejectHandler(reject);
|
|
@@ -4054,6 +4118,9 @@
|
|
|
4054
4118
|
var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
|
|
4055
4119
|
wasCreated = oldVer < 1;
|
|
4056
4120
|
db.idbdb = req.result;
|
|
4121
|
+
if (schemaPatchMode) {
|
|
4122
|
+
patchCurrentVersion(db, upgradeTransaction);
|
|
4123
|
+
}
|
|
4057
4124
|
runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
|
|
4058
4125
|
}
|
|
4059
4126
|
}, reject);
|
|
@@ -4068,8 +4135,12 @@
|
|
|
4068
4135
|
readGlobalSchema(db, idbdb, tmpTrans);
|
|
4069
4136
|
else {
|
|
4070
4137
|
adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
|
|
4071
|
-
if (!verifyInstalledSchema(db, tmpTrans)) {
|
|
4072
|
-
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());
|
|
4073
4144
|
}
|
|
4074
4145
|
}
|
|
4075
4146
|
generateMiddlewareStacks(db, tmpTrans);
|
|
@@ -4089,14 +4160,22 @@
|
|
|
4089
4160
|
resolve();
|
|
4090
4161
|
}, reject);
|
|
4091
4162
|
}).catch(function (err) {
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
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;
|
|
4099
4177
|
}
|
|
4178
|
+
return DexiePromise.reject(err);
|
|
4100
4179
|
}); };
|
|
4101
4180
|
return DexiePromise.race([
|
|
4102
4181
|
openCanceller,
|
|
@@ -5212,7 +5291,8 @@
|
|
|
5212
5291
|
cancelOpen: nop,
|
|
5213
5292
|
openCanceller: null,
|
|
5214
5293
|
autoSchema: true,
|
|
5215
|
-
PR1398_maxLoop: 3
|
|
5294
|
+
PR1398_maxLoop: 3,
|
|
5295
|
+
autoOpen: options.autoOpen,
|
|
5216
5296
|
};
|
|
5217
5297
|
state.dbReadyPromise = new DexiePromise(function (resolve) {
|
|
5218
5298
|
state.dbReadyResolve = resolve;
|
|
@@ -5329,7 +5409,7 @@
|
|
|
5329
5409
|
return reject(new exceptions.DatabaseClosed(_this._state.dbOpenError));
|
|
5330
5410
|
}
|
|
5331
5411
|
if (!_this._state.isBeingOpened) {
|
|
5332
|
-
if (!_this.
|
|
5412
|
+
if (!_this._state.autoOpen) {
|
|
5333
5413
|
reject(new exceptions.DatabaseClosed());
|
|
5334
5414
|
return;
|
|
5335
5415
|
}
|
|
@@ -5384,10 +5464,14 @@
|
|
|
5384
5464
|
};
|
|
5385
5465
|
Dexie.prototype.close = function (_a) {
|
|
5386
5466
|
var _b = _a === void 0 ? { disableAutoOpen: true } : _a, disableAutoOpen = _b.disableAutoOpen;
|
|
5467
|
+
var wasOpen = this.isOpen();
|
|
5387
5468
|
this._close();
|
|
5388
5469
|
var state = this._state;
|
|
5389
5470
|
if (disableAutoOpen)
|
|
5390
|
-
this.
|
|
5471
|
+
this._state.autoOpen = false;
|
|
5472
|
+
else if (wasOpen && this._options.autoOpen) {
|
|
5473
|
+
this._state.autoOpen = true;
|
|
5474
|
+
}
|
|
5391
5475
|
state.dbOpenError = new exceptions.DatabaseClosed();
|
|
5392
5476
|
if (state.isBeingOpened)
|
|
5393
5477
|
state.cancelOpen(state.dbOpenError);
|