dexie 4.2.0 → 4.2.1
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 -1
- package/dist/dexie.js +95 -73
- 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 +95 -73
- 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 +92 -71
- package/dist/modern/dexie.mjs.map +1 -1
- package/package.json +1 -1
package/dist/dexie.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* By David Fahlander, david.fahlander@gmail.com
|
|
6
6
|
*
|
|
7
|
-
* Version 4.2.
|
|
7
|
+
* Version 4.2.1, Sat Oct 04 2025
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -1146,7 +1146,7 @@ function tempTransaction(db, mode, storeNames, fn) {
|
|
|
1146
1146
|
}
|
|
1147
1147
|
}
|
|
1148
1148
|
|
|
1149
|
-
var DEXIE_VERSION = '4.2.
|
|
1149
|
+
var DEXIE_VERSION = '4.2.1';
|
|
1150
1150
|
var maxString = String.fromCharCode(65535);
|
|
1151
1151
|
var minKey = -Infinity;
|
|
1152
1152
|
var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
|
|
@@ -1278,6 +1278,76 @@ function builtInDeletionTrigger(table, keys, res) {
|
|
|
1278
1278
|
})).then(function () { return res; });
|
|
1279
1279
|
}
|
|
1280
1280
|
|
|
1281
|
+
var PropModification = (function () {
|
|
1282
|
+
function PropModification(spec) {
|
|
1283
|
+
this["@@propmod"] = spec;
|
|
1284
|
+
}
|
|
1285
|
+
PropModification.prototype.execute = function (value) {
|
|
1286
|
+
var _a;
|
|
1287
|
+
var spec = this["@@propmod"];
|
|
1288
|
+
if (spec.add !== undefined) {
|
|
1289
|
+
var term = spec.add;
|
|
1290
|
+
if (isArray(term)) {
|
|
1291
|
+
return __spreadArray(__spreadArray([], (isArray(value) ? value : []), true), term, true).sort();
|
|
1292
|
+
}
|
|
1293
|
+
if (typeof term === 'number')
|
|
1294
|
+
return (Number(value) || 0) + term;
|
|
1295
|
+
if (typeof term === 'bigint') {
|
|
1296
|
+
try {
|
|
1297
|
+
return BigInt(value) + term;
|
|
1298
|
+
}
|
|
1299
|
+
catch (_b) {
|
|
1300
|
+
return BigInt(0) + term;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
throw new TypeError("Invalid term ".concat(term));
|
|
1304
|
+
}
|
|
1305
|
+
if (spec.remove !== undefined) {
|
|
1306
|
+
var subtrahend_1 = spec.remove;
|
|
1307
|
+
if (isArray(subtrahend_1)) {
|
|
1308
|
+
return isArray(value) ? value.filter(function (item) { return !subtrahend_1.includes(item); }).sort() : [];
|
|
1309
|
+
}
|
|
1310
|
+
if (typeof subtrahend_1 === 'number')
|
|
1311
|
+
return Number(value) - subtrahend_1;
|
|
1312
|
+
if (typeof subtrahend_1 === 'bigint') {
|
|
1313
|
+
try {
|
|
1314
|
+
return BigInt(value) - subtrahend_1;
|
|
1315
|
+
}
|
|
1316
|
+
catch (_c) {
|
|
1317
|
+
return BigInt(0) - subtrahend_1;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
throw new TypeError("Invalid subtrahend ".concat(subtrahend_1));
|
|
1321
|
+
}
|
|
1322
|
+
var prefixToReplace = (_a = spec.replacePrefix) === null || _a === void 0 ? void 0 : _a[0];
|
|
1323
|
+
if (prefixToReplace && typeof value === 'string' && value.startsWith(prefixToReplace)) {
|
|
1324
|
+
return spec.replacePrefix[1] + value.substring(prefixToReplace.length);
|
|
1325
|
+
}
|
|
1326
|
+
return value;
|
|
1327
|
+
};
|
|
1328
|
+
return PropModification;
|
|
1329
|
+
}());
|
|
1330
|
+
|
|
1331
|
+
function applyUpdateSpec(obj, changes) {
|
|
1332
|
+
var keyPaths = keys(changes);
|
|
1333
|
+
var numKeys = keyPaths.length;
|
|
1334
|
+
var anythingModified = false;
|
|
1335
|
+
for (var i = 0; i < numKeys; ++i) {
|
|
1336
|
+
var keyPath = keyPaths[i];
|
|
1337
|
+
var value = changes[keyPath];
|
|
1338
|
+
var origValue = getByKeyPath(obj, keyPath);
|
|
1339
|
+
if (value instanceof PropModification) {
|
|
1340
|
+
setByKeyPath(obj, keyPath, value.execute(origValue));
|
|
1341
|
+
anythingModified = true;
|
|
1342
|
+
}
|
|
1343
|
+
else if (origValue !== value) {
|
|
1344
|
+
setByKeyPath(obj, keyPath, value);
|
|
1345
|
+
anythingModified = true;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
return anythingModified;
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1281
1351
|
var Table = (function () {
|
|
1282
1352
|
function Table() {
|
|
1283
1353
|
}
|
|
@@ -1474,6 +1544,26 @@ var Table = (function () {
|
|
|
1474
1544
|
return lastResult;
|
|
1475
1545
|
});
|
|
1476
1546
|
};
|
|
1547
|
+
Table.prototype.upsert = function (key, modifications) {
|
|
1548
|
+
var _this = this;
|
|
1549
|
+
var keyPath = this.schema.primKey.keyPath;
|
|
1550
|
+
return this._trans('readwrite', function (trans) {
|
|
1551
|
+
return _this.core.get({ trans: trans, key: key }).then(function (existing) {
|
|
1552
|
+
var obj = existing !== null && existing !== void 0 ? existing : {};
|
|
1553
|
+
applyUpdateSpec(obj, modifications);
|
|
1554
|
+
if (keyPath)
|
|
1555
|
+
setByKeyPath(obj, keyPath, key);
|
|
1556
|
+
return _this.core.mutate({
|
|
1557
|
+
trans: trans,
|
|
1558
|
+
type: 'put',
|
|
1559
|
+
values: [obj],
|
|
1560
|
+
keys: [key],
|
|
1561
|
+
upsert: true,
|
|
1562
|
+
updates: { keys: [key], changeSpecs: [modifications] }
|
|
1563
|
+
}).then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : !!existing; });
|
|
1564
|
+
});
|
|
1565
|
+
});
|
|
1566
|
+
};
|
|
1477
1567
|
Table.prototype.update = function (keyOrObject, modifications) {
|
|
1478
1568
|
if (typeof keyOrObject === 'object' && !isArray(keyOrObject)) {
|
|
1479
1569
|
var key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath);
|
|
@@ -1815,56 +1905,6 @@ function iterate(cursorPromise, filter, fn, valueMapper) {
|
|
|
1815
1905
|
});
|
|
1816
1906
|
}
|
|
1817
1907
|
|
|
1818
|
-
var PropModification = (function () {
|
|
1819
|
-
function PropModification(spec) {
|
|
1820
|
-
this["@@propmod"] = spec;
|
|
1821
|
-
}
|
|
1822
|
-
PropModification.prototype.execute = function (value) {
|
|
1823
|
-
var _a;
|
|
1824
|
-
var spec = this["@@propmod"];
|
|
1825
|
-
if (spec.add !== undefined) {
|
|
1826
|
-
var term = spec.add;
|
|
1827
|
-
if (isArray(term)) {
|
|
1828
|
-
return __spreadArray(__spreadArray([], (isArray(value) ? value : []), true), term, true).sort();
|
|
1829
|
-
}
|
|
1830
|
-
if (typeof term === 'number')
|
|
1831
|
-
return (Number(value) || 0) + term;
|
|
1832
|
-
if (typeof term === 'bigint') {
|
|
1833
|
-
try {
|
|
1834
|
-
return BigInt(value) + term;
|
|
1835
|
-
}
|
|
1836
|
-
catch (_b) {
|
|
1837
|
-
return BigInt(0) + term;
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
throw new TypeError("Invalid term ".concat(term));
|
|
1841
|
-
}
|
|
1842
|
-
if (spec.remove !== undefined) {
|
|
1843
|
-
var subtrahend_1 = spec.remove;
|
|
1844
|
-
if (isArray(subtrahend_1)) {
|
|
1845
|
-
return isArray(value) ? value.filter(function (item) { return !subtrahend_1.includes(item); }).sort() : [];
|
|
1846
|
-
}
|
|
1847
|
-
if (typeof subtrahend_1 === 'number')
|
|
1848
|
-
return Number(value) - subtrahend_1;
|
|
1849
|
-
if (typeof subtrahend_1 === 'bigint') {
|
|
1850
|
-
try {
|
|
1851
|
-
return BigInt(value) - subtrahend_1;
|
|
1852
|
-
}
|
|
1853
|
-
catch (_c) {
|
|
1854
|
-
return BigInt(0) - subtrahend_1;
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
throw new TypeError("Invalid subtrahend ".concat(subtrahend_1));
|
|
1858
|
-
}
|
|
1859
|
-
var prefixToReplace = (_a = spec.replacePrefix) === null || _a === void 0 ? void 0 : _a[0];
|
|
1860
|
-
if (prefixToReplace && typeof value === 'string' && value.startsWith(prefixToReplace)) {
|
|
1861
|
-
return spec.replacePrefix[1] + value.substring(prefixToReplace.length);
|
|
1862
|
-
}
|
|
1863
|
-
return value;
|
|
1864
|
-
};
|
|
1865
|
-
return PropModification;
|
|
1866
|
-
}());
|
|
1867
|
-
|
|
1868
1908
|
var Collection = (function () {
|
|
1869
1909
|
function Collection() {
|
|
1870
1910
|
}
|
|
@@ -2131,25 +2171,7 @@ var Collection = (function () {
|
|
|
2131
2171
|
modifyer = changes;
|
|
2132
2172
|
}
|
|
2133
2173
|
else {
|
|
2134
|
-
|
|
2135
|
-
var numKeys = keyPaths.length;
|
|
2136
|
-
modifyer = function (item) {
|
|
2137
|
-
var anythingModified = false;
|
|
2138
|
-
for (var i = 0; i < numKeys; ++i) {
|
|
2139
|
-
var keyPath = keyPaths[i];
|
|
2140
|
-
var val = changes[keyPath];
|
|
2141
|
-
var origVal = getByKeyPath(item, keyPath);
|
|
2142
|
-
if (val instanceof PropModification) {
|
|
2143
|
-
setByKeyPath(item, keyPath, val.execute(origVal));
|
|
2144
|
-
anythingModified = true;
|
|
2145
|
-
}
|
|
2146
|
-
else if (origVal !== val) {
|
|
2147
|
-
setByKeyPath(item, keyPath, val);
|
|
2148
|
-
anythingModified = true;
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
return anythingModified;
|
|
2152
|
-
};
|
|
2174
|
+
modifyer = function (item) { return applyUpdateSpec(item, changes); };
|
|
2153
2175
|
}
|
|
2154
2176
|
var coreTable = ctx.table.core;
|
|
2155
2177
|
var _a = coreTable.schema.primaryKey, outbound = _a.outbound, extractKey = _a.extractKey;
|
|
@@ -4142,8 +4164,8 @@ function dexieOpen(db) {
|
|
|
4142
4164
|
state.vcFired = true;
|
|
4143
4165
|
db.on("versionchange").fire(ev);
|
|
4144
4166
|
});
|
|
4145
|
-
idbdb.onclose = wrap(function (
|
|
4146
|
-
db.
|
|
4167
|
+
idbdb.onclose = wrap(function () {
|
|
4168
|
+
db.close({ disableAutoOpen: false });
|
|
4147
4169
|
});
|
|
4148
4170
|
if (wasCreated)
|
|
4149
4171
|
_onDatabaseCreated(db._deps, dbName);
|