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.d.ts
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
|
*
|
|
@@ -588,6 +588,7 @@ export interface DBCorePutRequest {
|
|
|
588
588
|
values: readonly any[];
|
|
589
589
|
keys?: any[];
|
|
590
590
|
mutatedParts?: ObservabilitySet;
|
|
591
|
+
upsert?: boolean; // If true, will insert the object if it does not exist. If false, will only update existing objects using the 'updates' property.
|
|
591
592
|
criteria?: {
|
|
592
593
|
index: string | null;
|
|
593
594
|
range: DBCoreKeyRange;
|
|
@@ -764,6 +765,7 @@ export interface Table<T = any, TKey = any, TInsertType = T> {
|
|
|
764
765
|
value: any;
|
|
765
766
|
primKey: IndexableType;
|
|
766
767
|
}) => void | boolean)): PromiseExtended<number>;
|
|
768
|
+
upsert(key: TKey | T, changes: UpdateSpec<TInsertType>): PromiseExtended<boolean>;
|
|
767
769
|
put(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
|
|
768
770
|
delete(key: TKey): PromiseExtended<void>;
|
|
769
771
|
clear(): PromiseExtended<void>;
|
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.2.
|
|
7
|
+
* Version 4.2.1, Sat Oct 04 2025
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -1152,7 +1152,7 @@
|
|
|
1152
1152
|
}
|
|
1153
1153
|
}
|
|
1154
1154
|
|
|
1155
|
-
var DEXIE_VERSION = '4.2.
|
|
1155
|
+
var DEXIE_VERSION = '4.2.1';
|
|
1156
1156
|
var maxString = String.fromCharCode(65535);
|
|
1157
1157
|
var minKey = -Infinity;
|
|
1158
1158
|
var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
|
|
@@ -1284,6 +1284,76 @@
|
|
|
1284
1284
|
})).then(function () { return res; });
|
|
1285
1285
|
}
|
|
1286
1286
|
|
|
1287
|
+
var PropModification = (function () {
|
|
1288
|
+
function PropModification(spec) {
|
|
1289
|
+
this["@@propmod"] = spec;
|
|
1290
|
+
}
|
|
1291
|
+
PropModification.prototype.execute = function (value) {
|
|
1292
|
+
var _a;
|
|
1293
|
+
var spec = this["@@propmod"];
|
|
1294
|
+
if (spec.add !== undefined) {
|
|
1295
|
+
var term = spec.add;
|
|
1296
|
+
if (isArray(term)) {
|
|
1297
|
+
return __spreadArray(__spreadArray([], (isArray(value) ? value : []), true), term, true).sort();
|
|
1298
|
+
}
|
|
1299
|
+
if (typeof term === 'number')
|
|
1300
|
+
return (Number(value) || 0) + term;
|
|
1301
|
+
if (typeof term === 'bigint') {
|
|
1302
|
+
try {
|
|
1303
|
+
return BigInt(value) + term;
|
|
1304
|
+
}
|
|
1305
|
+
catch (_b) {
|
|
1306
|
+
return BigInt(0) + term;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
throw new TypeError("Invalid term ".concat(term));
|
|
1310
|
+
}
|
|
1311
|
+
if (spec.remove !== undefined) {
|
|
1312
|
+
var subtrahend_1 = spec.remove;
|
|
1313
|
+
if (isArray(subtrahend_1)) {
|
|
1314
|
+
return isArray(value) ? value.filter(function (item) { return !subtrahend_1.includes(item); }).sort() : [];
|
|
1315
|
+
}
|
|
1316
|
+
if (typeof subtrahend_1 === 'number')
|
|
1317
|
+
return Number(value) - subtrahend_1;
|
|
1318
|
+
if (typeof subtrahend_1 === 'bigint') {
|
|
1319
|
+
try {
|
|
1320
|
+
return BigInt(value) - subtrahend_1;
|
|
1321
|
+
}
|
|
1322
|
+
catch (_c) {
|
|
1323
|
+
return BigInt(0) - subtrahend_1;
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
throw new TypeError("Invalid subtrahend ".concat(subtrahend_1));
|
|
1327
|
+
}
|
|
1328
|
+
var prefixToReplace = (_a = spec.replacePrefix) === null || _a === void 0 ? void 0 : _a[0];
|
|
1329
|
+
if (prefixToReplace && typeof value === 'string' && value.startsWith(prefixToReplace)) {
|
|
1330
|
+
return spec.replacePrefix[1] + value.substring(prefixToReplace.length);
|
|
1331
|
+
}
|
|
1332
|
+
return value;
|
|
1333
|
+
};
|
|
1334
|
+
return PropModification;
|
|
1335
|
+
}());
|
|
1336
|
+
|
|
1337
|
+
function applyUpdateSpec(obj, changes) {
|
|
1338
|
+
var keyPaths = keys(changes);
|
|
1339
|
+
var numKeys = keyPaths.length;
|
|
1340
|
+
var anythingModified = false;
|
|
1341
|
+
for (var i = 0; i < numKeys; ++i) {
|
|
1342
|
+
var keyPath = keyPaths[i];
|
|
1343
|
+
var value = changes[keyPath];
|
|
1344
|
+
var origValue = getByKeyPath(obj, keyPath);
|
|
1345
|
+
if (value instanceof PropModification) {
|
|
1346
|
+
setByKeyPath(obj, keyPath, value.execute(origValue));
|
|
1347
|
+
anythingModified = true;
|
|
1348
|
+
}
|
|
1349
|
+
else if (origValue !== value) {
|
|
1350
|
+
setByKeyPath(obj, keyPath, value);
|
|
1351
|
+
anythingModified = true;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
return anythingModified;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1287
1357
|
var Table = (function () {
|
|
1288
1358
|
function Table() {
|
|
1289
1359
|
}
|
|
@@ -1480,6 +1550,26 @@
|
|
|
1480
1550
|
return lastResult;
|
|
1481
1551
|
});
|
|
1482
1552
|
};
|
|
1553
|
+
Table.prototype.upsert = function (key, modifications) {
|
|
1554
|
+
var _this = this;
|
|
1555
|
+
var keyPath = this.schema.primKey.keyPath;
|
|
1556
|
+
return this._trans('readwrite', function (trans) {
|
|
1557
|
+
return _this.core.get({ trans: trans, key: key }).then(function (existing) {
|
|
1558
|
+
var obj = existing !== null && existing !== void 0 ? existing : {};
|
|
1559
|
+
applyUpdateSpec(obj, modifications);
|
|
1560
|
+
if (keyPath)
|
|
1561
|
+
setByKeyPath(obj, keyPath, key);
|
|
1562
|
+
return _this.core.mutate({
|
|
1563
|
+
trans: trans,
|
|
1564
|
+
type: 'put',
|
|
1565
|
+
values: [obj],
|
|
1566
|
+
keys: [key],
|
|
1567
|
+
upsert: true,
|
|
1568
|
+
updates: { keys: [key], changeSpecs: [modifications] }
|
|
1569
|
+
}).then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : !!existing; });
|
|
1570
|
+
});
|
|
1571
|
+
});
|
|
1572
|
+
};
|
|
1483
1573
|
Table.prototype.update = function (keyOrObject, modifications) {
|
|
1484
1574
|
if (typeof keyOrObject === 'object' && !isArray(keyOrObject)) {
|
|
1485
1575
|
var key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath);
|
|
@@ -1821,56 +1911,6 @@
|
|
|
1821
1911
|
});
|
|
1822
1912
|
}
|
|
1823
1913
|
|
|
1824
|
-
var PropModification = (function () {
|
|
1825
|
-
function PropModification(spec) {
|
|
1826
|
-
this["@@propmod"] = spec;
|
|
1827
|
-
}
|
|
1828
|
-
PropModification.prototype.execute = function (value) {
|
|
1829
|
-
var _a;
|
|
1830
|
-
var spec = this["@@propmod"];
|
|
1831
|
-
if (spec.add !== undefined) {
|
|
1832
|
-
var term = spec.add;
|
|
1833
|
-
if (isArray(term)) {
|
|
1834
|
-
return __spreadArray(__spreadArray([], (isArray(value) ? value : []), true), term, true).sort();
|
|
1835
|
-
}
|
|
1836
|
-
if (typeof term === 'number')
|
|
1837
|
-
return (Number(value) || 0) + term;
|
|
1838
|
-
if (typeof term === 'bigint') {
|
|
1839
|
-
try {
|
|
1840
|
-
return BigInt(value) + term;
|
|
1841
|
-
}
|
|
1842
|
-
catch (_b) {
|
|
1843
|
-
return BigInt(0) + term;
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
throw new TypeError("Invalid term ".concat(term));
|
|
1847
|
-
}
|
|
1848
|
-
if (spec.remove !== undefined) {
|
|
1849
|
-
var subtrahend_1 = spec.remove;
|
|
1850
|
-
if (isArray(subtrahend_1)) {
|
|
1851
|
-
return isArray(value) ? value.filter(function (item) { return !subtrahend_1.includes(item); }).sort() : [];
|
|
1852
|
-
}
|
|
1853
|
-
if (typeof subtrahend_1 === 'number')
|
|
1854
|
-
return Number(value) - subtrahend_1;
|
|
1855
|
-
if (typeof subtrahend_1 === 'bigint') {
|
|
1856
|
-
try {
|
|
1857
|
-
return BigInt(value) - subtrahend_1;
|
|
1858
|
-
}
|
|
1859
|
-
catch (_c) {
|
|
1860
|
-
return BigInt(0) - subtrahend_1;
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
throw new TypeError("Invalid subtrahend ".concat(subtrahend_1));
|
|
1864
|
-
}
|
|
1865
|
-
var prefixToReplace = (_a = spec.replacePrefix) === null || _a === void 0 ? void 0 : _a[0];
|
|
1866
|
-
if (prefixToReplace && typeof value === 'string' && value.startsWith(prefixToReplace)) {
|
|
1867
|
-
return spec.replacePrefix[1] + value.substring(prefixToReplace.length);
|
|
1868
|
-
}
|
|
1869
|
-
return value;
|
|
1870
|
-
};
|
|
1871
|
-
return PropModification;
|
|
1872
|
-
}());
|
|
1873
|
-
|
|
1874
1914
|
var Collection = (function () {
|
|
1875
1915
|
function Collection() {
|
|
1876
1916
|
}
|
|
@@ -2137,25 +2177,7 @@
|
|
|
2137
2177
|
modifyer = changes;
|
|
2138
2178
|
}
|
|
2139
2179
|
else {
|
|
2140
|
-
|
|
2141
|
-
var numKeys = keyPaths.length;
|
|
2142
|
-
modifyer = function (item) {
|
|
2143
|
-
var anythingModified = false;
|
|
2144
|
-
for (var i = 0; i < numKeys; ++i) {
|
|
2145
|
-
var keyPath = keyPaths[i];
|
|
2146
|
-
var val = changes[keyPath];
|
|
2147
|
-
var origVal = getByKeyPath(item, keyPath);
|
|
2148
|
-
if (val instanceof PropModification) {
|
|
2149
|
-
setByKeyPath(item, keyPath, val.execute(origVal));
|
|
2150
|
-
anythingModified = true;
|
|
2151
|
-
}
|
|
2152
|
-
else if (origVal !== val) {
|
|
2153
|
-
setByKeyPath(item, keyPath, val);
|
|
2154
|
-
anythingModified = true;
|
|
2155
|
-
}
|
|
2156
|
-
}
|
|
2157
|
-
return anythingModified;
|
|
2158
|
-
};
|
|
2180
|
+
modifyer = function (item) { return applyUpdateSpec(item, changes); };
|
|
2159
2181
|
}
|
|
2160
2182
|
var coreTable = ctx.table.core;
|
|
2161
2183
|
var _a = coreTable.schema.primaryKey, outbound = _a.outbound, extractKey = _a.extractKey;
|
|
@@ -4148,8 +4170,8 @@
|
|
|
4148
4170
|
state.vcFired = true;
|
|
4149
4171
|
db.on("versionchange").fire(ev);
|
|
4150
4172
|
});
|
|
4151
|
-
idbdb.onclose = wrap(function (
|
|
4152
|
-
db.
|
|
4173
|
+
idbdb.onclose = wrap(function () {
|
|
4174
|
+
db.close({ disableAutoOpen: false });
|
|
4153
4175
|
});
|
|
4154
4176
|
if (wasCreated)
|
|
4155
4177
|
_onDatabaseCreated(db._deps, dbName);
|