dexie 4.1.0-beta.45 → 4.2.0-alpha.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/README.md +28 -52
- package/dist/dexie.d.ts +46 -218
- package/dist/dexie.js +107 -910
- 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 +107 -909
- 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 +14 -567
- package/dist/modern/dexie.mjs.map +1 -1
- package/package.json +2 -3
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.
|
|
7
|
+
* Version 4.2.0-alpha.1, Fri Aug 01 2025
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -52,33 +52,6 @@
|
|
|
52
52
|
};
|
|
53
53
|
return __assign.apply(this, arguments);
|
|
54
54
|
};
|
|
55
|
-
function __values(o) {
|
|
56
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
57
|
-
if (m) return m.call(o);
|
|
58
|
-
if (o && typeof o.length === "number") return {
|
|
59
|
-
next: function () {
|
|
60
|
-
if (o && i >= o.length) o = void 0;
|
|
61
|
-
return { value: o && o[i++], done: !o };
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
65
|
-
}
|
|
66
|
-
function __read(o, n) {
|
|
67
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
68
|
-
if (!m) return o;
|
|
69
|
-
var i = m.call(o), r, ar = [], e;
|
|
70
|
-
try {
|
|
71
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
72
|
-
}
|
|
73
|
-
catch (error) { e = { error: error }; }
|
|
74
|
-
finally {
|
|
75
|
-
try {
|
|
76
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
77
|
-
}
|
|
78
|
-
finally { if (e) throw e.error; }
|
|
79
|
-
}
|
|
80
|
-
return ar;
|
|
81
|
-
}
|
|
82
55
|
function __spreadArray(to, from, pack) {
|
|
83
56
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
84
57
|
if (ar || !(i in from)) {
|
|
@@ -1179,7 +1152,7 @@
|
|
|
1179
1152
|
}
|
|
1180
1153
|
}
|
|
1181
1154
|
|
|
1182
|
-
var DEXIE_VERSION = '4.
|
|
1155
|
+
var DEXIE_VERSION = '4.2.0-alpha.1';
|
|
1183
1156
|
var maxString = String.fromCharCode(65535);
|
|
1184
1157
|
var minKey = -Infinity;
|
|
1185
1158
|
var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
|
|
@@ -1218,7 +1191,7 @@
|
|
|
1218
1191
|
}
|
|
1219
1192
|
|
|
1220
1193
|
function Entity() {
|
|
1221
|
-
throw exceptions.Type();
|
|
1194
|
+
throw exceptions.Type("Entity instances must never be new:ed. Instances are generated by the framework bypassing the constructor.");
|
|
1222
1195
|
}
|
|
1223
1196
|
|
|
1224
1197
|
function cmp(a, b) {
|
|
@@ -1297,90 +1270,6 @@
|
|
|
1297
1270
|
return new Uint8Array(a);
|
|
1298
1271
|
}
|
|
1299
1272
|
|
|
1300
|
-
function getDocCache(db) {
|
|
1301
|
-
var _a;
|
|
1302
|
-
var _b;
|
|
1303
|
-
return (_a = (_b = db._novip)['_docCache']) !== null && _a !== void 0 ? _a : (_b['_docCache'] = {
|
|
1304
|
-
cache: {},
|
|
1305
|
-
get size() {
|
|
1306
|
-
return Object.keys(this.cache).length;
|
|
1307
|
-
},
|
|
1308
|
-
find: function (table, primaryKey, ydocProp) {
|
|
1309
|
-
var cacheKey = getYDocCacheKey(table, primaryKey, ydocProp);
|
|
1310
|
-
var docRef = this.cache[cacheKey];
|
|
1311
|
-
return docRef ? docRef.deref() : undefined;
|
|
1312
|
-
},
|
|
1313
|
-
add: function (doc) {
|
|
1314
|
-
var _a;
|
|
1315
|
-
var _b = doc.meta, parentTable = _b.parentTable, parentId = _b.parentId, parentProp = _b.parentProp;
|
|
1316
|
-
if (!parentTable || !parentProp || parentId == null)
|
|
1317
|
-
throw new Error("Missing Dexie-related metadata in Y.Doc");
|
|
1318
|
-
var cacheKey = getYDocCacheKey(parentTable, parentId, parentProp);
|
|
1319
|
-
var existingDoc = (_a = this.cache[cacheKey]) === null || _a === void 0 ? void 0 : _a.deref();
|
|
1320
|
-
if (existingDoc) {
|
|
1321
|
-
docRegistry.unregister(existingDoc);
|
|
1322
|
-
}
|
|
1323
|
-
this.cache[cacheKey] = new WeakRef(doc);
|
|
1324
|
-
docRegistry.register(doc, { cache: this.cache, key: cacheKey });
|
|
1325
|
-
},
|
|
1326
|
-
delete: function (doc) {
|
|
1327
|
-
docRegistry.unregister(doc);
|
|
1328
|
-
var cacheKey = getYDocCacheKey(doc.meta.parentTable, doc.meta.parentId, doc.meta.parentProp);
|
|
1329
|
-
var cacheEntry = this.cache[cacheKey];
|
|
1330
|
-
if ((cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.deref()) === doc) {
|
|
1331
|
-
delete this.cache[cacheKey];
|
|
1332
|
-
}
|
|
1333
|
-
},
|
|
1334
|
-
});
|
|
1335
|
-
}
|
|
1336
|
-
var docRegistry = new FinalizationRegistry(function (_a) {
|
|
1337
|
-
var cache = _a.cache, key = _a.key;
|
|
1338
|
-
delete cache[key];
|
|
1339
|
-
});
|
|
1340
|
-
var destroyedDocs = new WeakSet();
|
|
1341
|
-
function throwIfDestroyed(doc) {
|
|
1342
|
-
if (destroyedDocs.has(doc))
|
|
1343
|
-
throw new Error("Y.Doc ".concat(doc.meta.parentId, " has been destroyed"));
|
|
1344
|
-
}
|
|
1345
|
-
function getYDocCacheKey(table, primaryKey, ydocProp) {
|
|
1346
|
-
return "".concat(table, "[").concat(primaryKey, "].").concat(ydocProp);
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
function getOrCreateDocument(db, docCache, Y, tableName, prop, updatesTable, id) {
|
|
1350
|
-
var doc = docCache.find(tableName, id, prop);
|
|
1351
|
-
if (doc)
|
|
1352
|
-
return doc;
|
|
1353
|
-
doc = new Y.Doc({
|
|
1354
|
-
meta: {
|
|
1355
|
-
db: db,
|
|
1356
|
-
updatesTable: updatesTable,
|
|
1357
|
-
parentProp: prop,
|
|
1358
|
-
parentTable: tableName,
|
|
1359
|
-
parentId: id,
|
|
1360
|
-
},
|
|
1361
|
-
});
|
|
1362
|
-
docCache.add(doc);
|
|
1363
|
-
doc.on('destroy', function () {
|
|
1364
|
-
destroyedDocs.add(doc);
|
|
1365
|
-
docCache.delete(doc);
|
|
1366
|
-
});
|
|
1367
|
-
return doc;
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
function createYDocProperty(db, Y, table, prop, updatesTable) {
|
|
1371
|
-
var pkKeyPath = table.schema.primKey.keyPath;
|
|
1372
|
-
var docCache = getDocCache(db);
|
|
1373
|
-
return {
|
|
1374
|
-
set: function () {
|
|
1375
|
-
throw new TypeError("Y.Doc properties are read-only");
|
|
1376
|
-
},
|
|
1377
|
-
get: function () {
|
|
1378
|
-
var id = getByKeyPath(this, pkKeyPath);
|
|
1379
|
-
return getOrCreateDocument(db, docCache, Y, table.name, prop, updatesTable, id);
|
|
1380
|
-
},
|
|
1381
|
-
};
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
1273
|
function builtInDeletionTrigger(table, keys, res) {
|
|
1385
1274
|
var yProps = table.schema.yProps;
|
|
1386
1275
|
if (!yProps)
|
|
@@ -1395,13 +1284,6 @@
|
|
|
1395
1284
|
})).then(function () { return res; });
|
|
1396
1285
|
}
|
|
1397
1286
|
|
|
1398
|
-
function getYLibrary(db) {
|
|
1399
|
-
var Y = db._options.Y;
|
|
1400
|
-
if (!Y)
|
|
1401
|
-
throw new exceptions.MissingAPI('Y library not supplied to Dexie constructor');
|
|
1402
|
-
return Y;
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
1287
|
var Table = (function () {
|
|
1406
1288
|
function Table() {
|
|
1407
1289
|
}
|
|
@@ -1480,8 +1362,8 @@
|
|
|
1480
1362
|
function equals(a, b) {
|
|
1481
1363
|
return cmp(a, b) === 0;
|
|
1482
1364
|
}
|
|
1483
|
-
var _a =
|
|
1484
|
-
var
|
|
1365
|
+
var _a = keyPaths.reduce(function (_a, keyPath) {
|
|
1366
|
+
var prevIndex = _a[0], prevFilterFn = _a[1];
|
|
1485
1367
|
var index = idxByName[keyPath];
|
|
1486
1368
|
var value = indexOrCrit[keyPath];
|
|
1487
1369
|
return [
|
|
@@ -1494,7 +1376,7 @@
|
|
|
1494
1376
|
} : function (x) { return equals(value, getByKeyPath(x, keyPath)); })
|
|
1495
1377
|
: prevFilterFn
|
|
1496
1378
|
];
|
|
1497
|
-
}, [null, null]),
|
|
1379
|
+
}, [null, null]), idx = _a[0], filterFunction = _a[1];
|
|
1498
1380
|
return idx ?
|
|
1499
1381
|
this.where(idx.name).equals(indexOrCrit[idx.keyPath])
|
|
1500
1382
|
.filter(filterFunction) :
|
|
@@ -1532,7 +1414,6 @@
|
|
|
1532
1414
|
return this.toCollection().reverse();
|
|
1533
1415
|
};
|
|
1534
1416
|
Table.prototype.mapToClass = function (constructor) {
|
|
1535
|
-
var _this = this;
|
|
1536
1417
|
var _a = this, db = _a.db, tableName = _a.name;
|
|
1537
1418
|
this.schema.mappedClass = constructor;
|
|
1538
1419
|
if (constructor.prototype instanceof Entity) {
|
|
@@ -1550,21 +1431,6 @@
|
|
|
1550
1431
|
return class_1;
|
|
1551
1432
|
}(constructor));
|
|
1552
1433
|
}
|
|
1553
|
-
if (this.schema.yProps) {
|
|
1554
|
-
var Y_1 = getYLibrary(db);
|
|
1555
|
-
var DBObjectWithYProps = (function (_super) {
|
|
1556
|
-
__extends(DBObjectWithYProps, _super);
|
|
1557
|
-
function DBObjectWithYProps() {
|
|
1558
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1559
|
-
}
|
|
1560
|
-
return DBObjectWithYProps;
|
|
1561
|
-
}(constructor));
|
|
1562
|
-
constructor = DBObjectWithYProps;
|
|
1563
|
-
this.schema.yProps.forEach(function (_a) {
|
|
1564
|
-
var prop = _a.prop, updatesTable = _a.updatesTable;
|
|
1565
|
-
Object.defineProperty(constructor.prototype, prop, createYDocProperty(db, Y_1, _this, prop, updatesTable));
|
|
1566
|
-
});
|
|
1567
|
-
}
|
|
1568
1434
|
var inheritedProps = new Set();
|
|
1569
1435
|
for (var proto = constructor.prototype; proto; proto = getProto(proto)) {
|
|
1570
1436
|
Object.getOwnPropertyNames(proto).forEach(function (propName) { return inheritedProps.add(propName); });
|
|
@@ -1726,30 +1592,20 @@
|
|
|
1726
1592
|
var resultKeys = [];
|
|
1727
1593
|
var resultObjs = [];
|
|
1728
1594
|
keysAndChanges.forEach(function (_a, idx) {
|
|
1729
|
-
var e_1, _b;
|
|
1730
1595
|
var key = _a.key, changes = _a.changes;
|
|
1731
1596
|
var obj = objs[idx];
|
|
1732
1597
|
if (obj) {
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
if (
|
|
1738
|
-
|
|
1739
|
-
throw new exceptions.Constraint("Cannot update primary key in bulkUpdate()");
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
else {
|
|
1743
|
-
setByKeyPath(obj, keyPath, value);
|
|
1598
|
+
for (var _i = 0, _b = Object.keys(changes); _i < _b.length; _i++) {
|
|
1599
|
+
var keyPath = _b[_i];
|
|
1600
|
+
var value = changes[keyPath];
|
|
1601
|
+
if (keyPath === _this.schema.primKey.keyPath) {
|
|
1602
|
+
if (cmp(value, key) !== 0) {
|
|
1603
|
+
throw new exceptions.Constraint("Cannot update primary key in bulkUpdate()");
|
|
1744
1604
|
}
|
|
1745
1605
|
}
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
finally {
|
|
1749
|
-
try {
|
|
1750
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1606
|
+
else {
|
|
1607
|
+
setByKeyPath(obj, keyPath, value);
|
|
1751
1608
|
}
|
|
1752
|
-
finally { if (e_1) throw e_1.error; }
|
|
1753
1609
|
}
|
|
1754
1610
|
offsetMap.push(idx);
|
|
1755
1611
|
resultKeys.push(key);
|
|
@@ -1769,28 +1625,18 @@
|
|
|
1769
1625
|
}
|
|
1770
1626
|
})
|
|
1771
1627
|
.then(function (_a) {
|
|
1772
|
-
var e_2, _b;
|
|
1773
1628
|
var numFailures = _a.numFailures, failures = _a.failures;
|
|
1774
1629
|
if (numFailures === 0)
|
|
1775
1630
|
return numEntries;
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
failures[mappedOffset] = failure;
|
|
1784
|
-
}
|
|
1631
|
+
for (var _i = 0, _b = Object.keys(failures); _i < _b.length; _i++) {
|
|
1632
|
+
var offset = _b[_i];
|
|
1633
|
+
var mappedOffset = offsetMap[Number(offset)];
|
|
1634
|
+
if (mappedOffset != null) {
|
|
1635
|
+
var failure = failures[offset];
|
|
1636
|
+
delete failures[offset];
|
|
1637
|
+
failures[mappedOffset] = failure;
|
|
1785
1638
|
}
|
|
1786
1639
|
}
|
|
1787
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1788
|
-
finally {
|
|
1789
|
-
try {
|
|
1790
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1791
|
-
}
|
|
1792
|
-
finally { if (e_2) throw e_2.error; }
|
|
1793
|
-
}
|
|
1794
1640
|
throw new BulkError("".concat(_this.name, ".bulkUpdate(): ").concat(numFailures, " of ").concat(numEntries, " operations failed"), failures);
|
|
1795
1641
|
});
|
|
1796
1642
|
});
|
|
@@ -1985,7 +1831,7 @@
|
|
|
1985
1831
|
if (spec.add !== undefined) {
|
|
1986
1832
|
var term = spec.add;
|
|
1987
1833
|
if (isArray(term)) {
|
|
1988
|
-
return __spreadArray(__spreadArray([],
|
|
1834
|
+
return __spreadArray(__spreadArray([], (isArray(value) ? value : []), true), term, true).sort();
|
|
1989
1835
|
}
|
|
1990
1836
|
if (typeof term === 'number')
|
|
1991
1837
|
return (Number(value) || 0) + term;
|
|
@@ -2327,21 +2173,11 @@
|
|
|
2327
2173
|
var successCount = 0;
|
|
2328
2174
|
var failedKeys = [];
|
|
2329
2175
|
var applyMutateResult = function (expectedCount, res) {
|
|
2330
|
-
var e_1, _a;
|
|
2331
2176
|
var failures = res.failures, numFailures = res.numFailures;
|
|
2332
2177
|
successCount += expectedCount - numFailures;
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
totalFailures.push(failures[pos]);
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2340
|
-
finally {
|
|
2341
|
-
try {
|
|
2342
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2343
|
-
}
|
|
2344
|
-
finally { if (e_1) throw e_1.error; }
|
|
2178
|
+
for (var _i = 0, _a = keys(failures); _i < _a.length; _i++) {
|
|
2179
|
+
var pos = _a[_i];
|
|
2180
|
+
totalFailures.push(failures[pos]);
|
|
2345
2181
|
}
|
|
2346
2182
|
};
|
|
2347
2183
|
var isUnconditionalDelete = changes === deleteCallback;
|
|
@@ -3098,16 +2934,12 @@
|
|
|
3098
2934
|
keyPath ? ('[' + [].join.call(keyPath, '+') + ']') : "";
|
|
3099
2935
|
}
|
|
3100
2936
|
|
|
3101
|
-
function createTableSchema(name, primKey, indexes
|
|
2937
|
+
function createTableSchema(name, primKey, indexes) {
|
|
3102
2938
|
return {
|
|
3103
2939
|
name: name,
|
|
3104
2940
|
primKey: primKey,
|
|
3105
2941
|
indexes: indexes,
|
|
3106
2942
|
mappedClass: null,
|
|
3107
|
-
yProps: yProps === null || yProps === void 0 ? void 0 : yProps.map(function (prop) { return ({
|
|
3108
|
-
prop: prop,
|
|
3109
|
-
updatesTable: "$".concat(name, ".").concat(prop, "_updates"),
|
|
3110
|
-
}); }),
|
|
3111
2943
|
idxByName: arrayToObject(indexes, function (index) { return [index.name, index]; }),
|
|
3112
2944
|
};
|
|
3113
2945
|
}
|
|
@@ -3261,11 +3093,11 @@
|
|
|
3261
3093
|
reqs.push(req = store.delete(makeIDBKeyRange(range)));
|
|
3262
3094
|
}
|
|
3263
3095
|
else {
|
|
3264
|
-
var _a =
|
|
3096
|
+
var _a = isAddOrPut ?
|
|
3265
3097
|
outbound ?
|
|
3266
3098
|
[values, keys] :
|
|
3267
3099
|
[values, null] :
|
|
3268
|
-
[keys, null],
|
|
3100
|
+
[keys, null], args1 = _a[0], args2 = _a[1];
|
|
3269
3101
|
if (isAddOrPut) {
|
|
3270
3102
|
for (var i = 0; i < length; ++i) {
|
|
3271
3103
|
reqs.push(req = (args2 && args2[i] !== undefined ?
|
|
@@ -3590,7 +3422,6 @@
|
|
|
3590
3422
|
});
|
|
3591
3423
|
}
|
|
3592
3424
|
function patchCurrentVersion(db, idbUpgradeTrans) {
|
|
3593
|
-
var e_1, _a;
|
|
3594
3425
|
createMissingTables(db._dbSchema, idbUpgradeTrans);
|
|
3595
3426
|
if (idbUpgradeTrans.db.version % 10 === 0 && !idbUpgradeTrans.objectStoreNames.contains('$meta')) {
|
|
3596
3427
|
idbUpgradeTrans.db.createObjectStore('$meta').add(Math.ceil((idbUpgradeTrans.db.version / 10) - 1), 'version');
|
|
@@ -3610,20 +3441,11 @@
|
|
|
3610
3441
|
addIndex(store, idx);
|
|
3611
3442
|
});
|
|
3612
3443
|
};
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
return state_1.value;
|
|
3619
|
-
}
|
|
3620
|
-
}
|
|
3621
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3622
|
-
finally {
|
|
3623
|
-
try {
|
|
3624
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3625
|
-
}
|
|
3626
|
-
finally { if (e_1) throw e_1.error; }
|
|
3444
|
+
for (var _i = 0, _a = diff.change; _i < _a.length; _i++) {
|
|
3445
|
+
var tableChange = _a[_i];
|
|
3446
|
+
var state_1 = _loop_1(tableChange);
|
|
3447
|
+
if (typeof state_1 === "object")
|
|
3448
|
+
return state_1.value;
|
|
3627
3449
|
}
|
|
3628
3450
|
}
|
|
3629
3451
|
function getExistingVersion(db, trans, oldVersion) {
|
|
@@ -3866,106 +3688,26 @@
|
|
|
3866
3688
|
var typeSplit = index.split(':');
|
|
3867
3689
|
var type = (_a = typeSplit[1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
3868
3690
|
index = typeSplit[0].trim();
|
|
3869
|
-
if (type && type !== 'Y')
|
|
3870
|
-
throw new exceptions.Schema("Unsupported type '".concat(type, "'"));
|
|
3871
3691
|
var name = index.replace(/([&*]|\+\+)/g, "");
|
|
3872
3692
|
var keyPath = /^\[/.test(name) ? name.match(/^\[(.*)\]$/)[1].split('+') : name;
|
|
3873
3693
|
return createIndexSpec(name, keyPath || null, /\&/.test(index), /\*/.test(index), /\+\+/.test(index), isArray(keyPath), indexNum === 0, type);
|
|
3874
3694
|
});
|
|
3875
3695
|
}
|
|
3876
3696
|
|
|
3877
|
-
var EMPTY_ARRAY = [];
|
|
3878
|
-
function createYjsMiddleware(dbSchema, Y) {
|
|
3879
|
-
return {
|
|
3880
|
-
stack: 'dbcore',
|
|
3881
|
-
name: 'yjsMiddleware',
|
|
3882
|
-
level: 50,
|
|
3883
|
-
create: function (downCore) {
|
|
3884
|
-
return (__assign(__assign({}, downCore), { table: function (tableName) {
|
|
3885
|
-
var downTable = downCore.table(tableName);
|
|
3886
|
-
var dbTableSchema = dbSchema[tableName];
|
|
3887
|
-
var yProps = dbTableSchema.yProps;
|
|
3888
|
-
if (!yProps || yProps.length === 0)
|
|
3889
|
-
return downTable;
|
|
3890
|
-
var tableMiddleware = __assign(__assign({}, downTable), { mutate: function (req) {
|
|
3891
|
-
if (req.type !== 'add' && req.type !== 'put')
|
|
3892
|
-
return downTable.mutate(req);
|
|
3893
|
-
var reqClone = req;
|
|
3894
|
-
var updateSources = yProps
|
|
3895
|
-
.map(function (p) { return ({
|
|
3896
|
-
p: p,
|
|
3897
|
-
entries: req.values.flatMap(function (value, iter) {
|
|
3898
|
-
if (!value || typeof value !== 'object')
|
|
3899
|
-
throw new TypeError("Table ".concat(tableName, " (with Y-properties) must only contain objects"));
|
|
3900
|
-
if (!hasOwn(value, p.prop))
|
|
3901
|
-
return [];
|
|
3902
|
-
if (reqClone === req)
|
|
3903
|
-
reqClone = __assign(__assign({}, req), { values: req.values.map(function (v) { return (__assign({}, v)); }) });
|
|
3904
|
-
delete reqClone.values[iter][p.prop];
|
|
3905
|
-
var doc = value[p.prop];
|
|
3906
|
-
if (doc === null)
|
|
3907
|
-
throw new TypeError("Cannot set Y property to null");
|
|
3908
|
-
if (doc === undefined)
|
|
3909
|
-
return EMPTY_ARRAY;
|
|
3910
|
-
if (typeof doc !== 'object' || !('whenLoaded' in doc)) {
|
|
3911
|
-
throw new TypeError("Y properties can only be inited with an Y.Doc instance or undefined to create an empty Y.Doc");
|
|
3912
|
-
}
|
|
3913
|
-
if (req.type === 'put')
|
|
3914
|
-
throw new TypeError("Setting ".concat(tableName, ".").concat(p.prop, " (declared as ").concat(p.prop, ":Y) is only allowed when inserting new objects using db.").concat(tableName, ".add(), not put() or update()."));
|
|
3915
|
-
if (Y.encodeStateVector(doc).length === 1) {
|
|
3916
|
-
return EMPTY_ARRAY;
|
|
3917
|
-
}
|
|
3918
|
-
return {
|
|
3919
|
-
iter: iter,
|
|
3920
|
-
u: Y.encodeStateAsUpdateV2(doc),
|
|
3921
|
-
};
|
|
3922
|
-
}),
|
|
3923
|
-
}); })
|
|
3924
|
-
.filter(function (_a) {
|
|
3925
|
-
var entries = _a.entries;
|
|
3926
|
-
return entries.length > 0;
|
|
3927
|
-
});
|
|
3928
|
-
if (req === reqClone)
|
|
3929
|
-
return downTable.mutate(req);
|
|
3930
|
-
return downTable.mutate(reqClone).then(function (res) {
|
|
3931
|
-
if (updateSources.length === 0)
|
|
3932
|
-
return res;
|
|
3933
|
-
return Promise.all(updateSources.map(function (_a) {
|
|
3934
|
-
var p = _a.p, entries = _a.entries;
|
|
3935
|
-
var updatesTable = downCore.table(p.updatesTable);
|
|
3936
|
-
var updatesToInsert = entries.map(function (_a) {
|
|
3937
|
-
var iter = _a.iter, u = _a.u;
|
|
3938
|
-
return ({
|
|
3939
|
-
k: res.results[iter],
|
|
3940
|
-
u: u,
|
|
3941
|
-
f: 1,
|
|
3942
|
-
});
|
|
3943
|
-
});
|
|
3944
|
-
return updatesTable.mutate({
|
|
3945
|
-
type: 'add',
|
|
3946
|
-
values: updatesToInsert,
|
|
3947
|
-
trans: req.trans,
|
|
3948
|
-
});
|
|
3949
|
-
})).then(function () { return res; });
|
|
3950
|
-
});
|
|
3951
|
-
} });
|
|
3952
|
-
return tableMiddleware;
|
|
3953
|
-
} }));
|
|
3954
|
-
},
|
|
3955
|
-
};
|
|
3956
|
-
}
|
|
3957
|
-
|
|
3958
3697
|
var Version = (function () {
|
|
3959
3698
|
function Version() {
|
|
3960
3699
|
}
|
|
3700
|
+
Version.prototype._createTableSchema = function (name, primKey, indexes) {
|
|
3701
|
+
return createTableSchema(name, primKey, indexes);
|
|
3702
|
+
};
|
|
3703
|
+
Version.prototype._parseIndexSyntax = function (primKeyAndIndexes) {
|
|
3704
|
+
return parseIndexSyntax(primKeyAndIndexes);
|
|
3705
|
+
};
|
|
3961
3706
|
Version.prototype._parseStoresSpec = function (stores, outSchema) {
|
|
3962
3707
|
var _this = this;
|
|
3963
3708
|
keys(stores).forEach(function (tableName) {
|
|
3964
|
-
var e_1, _a, _b;
|
|
3965
3709
|
if (stores[tableName] !== null) {
|
|
3966
|
-
var indexes =
|
|
3967
|
-
var yProps = indexes.filter(function (idx) { return idx.type === 'Y'; }).map(function (idx) { return idx.name; });
|
|
3968
|
-
indexes = indexes.filter(function (idx) { return idx.type !== 'Y'; });
|
|
3710
|
+
var indexes = _this._parseIndexSyntax(stores[tableName]);
|
|
3969
3711
|
var primKey = indexes.shift();
|
|
3970
3712
|
if (!primKey) {
|
|
3971
3713
|
throw new exceptions.Schema('Invalid schema for table ' + tableName + ': ' + stores[tableName]);
|
|
@@ -3979,21 +3721,8 @@
|
|
|
3979
3721
|
if (!idx.keyPath)
|
|
3980
3722
|
throw new exceptions.Schema('Index must have a name and cannot be an empty string');
|
|
3981
3723
|
});
|
|
3982
|
-
var tblSchema =
|
|
3724
|
+
var tblSchema = _this._createTableSchema(tableName, primKey, indexes);
|
|
3983
3725
|
outSchema[tableName] = tblSchema;
|
|
3984
|
-
try {
|
|
3985
|
-
for (var _c = __values(tblSchema.yProps || []), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
3986
|
-
var yProp = _d.value;
|
|
3987
|
-
_this._parseStoresSpec((_b = {}, _b[yProp.updatesTable] = '++i,k', _b), outSchema);
|
|
3988
|
-
}
|
|
3989
|
-
}
|
|
3990
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3991
|
-
finally {
|
|
3992
|
-
try {
|
|
3993
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
3994
|
-
}
|
|
3995
|
-
finally { if (e_1) throw e_1.error; }
|
|
3996
|
-
}
|
|
3997
3726
|
}
|
|
3998
3727
|
});
|
|
3999
3728
|
};
|
|
@@ -4014,17 +3743,6 @@
|
|
|
4014
3743
|
removeTablesApi(db, [db._allTables, db, db.Transaction.prototype]);
|
|
4015
3744
|
setApiOnPlace(db, [db._allTables, db, db.Transaction.prototype, this._cfg.tables], keys(dbschema), dbschema);
|
|
4016
3745
|
db._storeNames = keys(dbschema);
|
|
4017
|
-
db._storeNames.forEach(function (tableName) {
|
|
4018
|
-
if (dbschema[tableName].yProps) {
|
|
4019
|
-
db.table(tableName).mapToClass(dbschema[tableName].mappedClass || Object);
|
|
4020
|
-
}
|
|
4021
|
-
});
|
|
4022
|
-
if (Object.values(dbschema).some(function (table) { return table.yProps; })) {
|
|
4023
|
-
db.use(createYjsMiddleware(dbschema, getYLibrary(db)));
|
|
4024
|
-
}
|
|
4025
|
-
else {
|
|
4026
|
-
db.unuse({ stack: 'dbcore', name: 'yjsMiddleware' });
|
|
4027
|
-
}
|
|
4028
3746
|
return this;
|
|
4029
3747
|
};
|
|
4030
3748
|
Version.prototype.upgrade = function (upgradeFunction) {
|
|
@@ -4303,29 +4021,19 @@
|
|
|
4303
4021
|
}
|
|
4304
4022
|
}
|
|
4305
4023
|
function signalSubscribersNow(updatedParts, deleteAffectedCacheEntries) {
|
|
4306
|
-
var e_1, _a;
|
|
4307
4024
|
if (deleteAffectedCacheEntries === void 0) { deleteAffectedCacheEntries = false; }
|
|
4308
4025
|
var queriesToSignal = new Set();
|
|
4309
4026
|
if (updatedParts.all) {
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
collectTableSubscribers(tblCache, updatedParts, queriesToSignal, deleteAffectedCacheEntries);
|
|
4314
|
-
}
|
|
4315
|
-
}
|
|
4316
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4317
|
-
finally {
|
|
4318
|
-
try {
|
|
4319
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4320
|
-
}
|
|
4321
|
-
finally { if (e_1) throw e_1.error; }
|
|
4027
|
+
for (var _i = 0, _a = Object.values(cache); _i < _a.length; _i++) {
|
|
4028
|
+
var tblCache = _a[_i];
|
|
4029
|
+
collectTableSubscribers(tblCache, updatedParts, queriesToSignal, deleteAffectedCacheEntries);
|
|
4322
4030
|
}
|
|
4323
4031
|
}
|
|
4324
4032
|
else {
|
|
4325
4033
|
for (var key in updatedParts) {
|
|
4326
4034
|
var parts = /^idb\:\/\/(.*)\/(.*)\//.exec(key);
|
|
4327
4035
|
if (parts) {
|
|
4328
|
-
var
|
|
4036
|
+
var dbName = parts[1], tableName = parts[2];
|
|
4329
4037
|
var tblCache = cache["idb://".concat(dbName, "/").concat(tableName)];
|
|
4330
4038
|
if (tblCache)
|
|
4331
4039
|
collectTableSubscribers(tblCache, updatedParts, queriesToSignal, deleteAffectedCacheEntries);
|
|
@@ -4335,54 +4043,26 @@
|
|
|
4335
4043
|
queriesToSignal.forEach(function (requery) { return requery(); });
|
|
4336
4044
|
}
|
|
4337
4045
|
function collectTableSubscribers(tblCache, updatedParts, outQueriesToSignal, deleteAffectedCacheEntries) {
|
|
4338
|
-
var e_2, _a, e_3, _b, e_4, _c;
|
|
4339
4046
|
var updatedEntryLists = [];
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
if (obsSetsOverlap(updatedParts, entry.obsSet)) {
|
|
4348
|
-
entry.subscribers.forEach(function (requery) { return outQueriesToSignal.add(requery); });
|
|
4349
|
-
}
|
|
4350
|
-
else if (deleteAffectedCacheEntries) {
|
|
4351
|
-
filteredEntries.push(entry);
|
|
4352
|
-
}
|
|
4353
|
-
}
|
|
4047
|
+
for (var _i = 0, _a = Object.entries(tblCache.queries.query); _i < _a.length; _i++) {
|
|
4048
|
+
var _b = _a[_i], indexName = _b[0], entries = _b[1];
|
|
4049
|
+
var filteredEntries = [];
|
|
4050
|
+
for (var _c = 0, entries_1 = entries; _c < entries_1.length; _c++) {
|
|
4051
|
+
var entry = entries_1[_c];
|
|
4052
|
+
if (obsSetsOverlap(updatedParts, entry.obsSet)) {
|
|
4053
|
+
entry.subscribers.forEach(function (requery) { return outQueriesToSignal.add(requery); });
|
|
4354
4054
|
}
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
try {
|
|
4358
|
-
if (entries_1_1 && !entries_1_1.done && (_b = entries_1.return)) _b.call(entries_1);
|
|
4359
|
-
}
|
|
4360
|
-
finally { if (e_3) throw e_3.error; }
|
|
4055
|
+
else if (deleteAffectedCacheEntries) {
|
|
4056
|
+
filteredEntries.push(entry);
|
|
4361
4057
|
}
|
|
4362
|
-
if (deleteAffectedCacheEntries)
|
|
4363
|
-
updatedEntryLists.push([indexName, filteredEntries]);
|
|
4364
|
-
}
|
|
4365
|
-
}
|
|
4366
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4367
|
-
finally {
|
|
4368
|
-
try {
|
|
4369
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
4370
4058
|
}
|
|
4371
|
-
|
|
4059
|
+
if (deleteAffectedCacheEntries)
|
|
4060
|
+
updatedEntryLists.push([indexName, filteredEntries]);
|
|
4372
4061
|
}
|
|
4373
4062
|
if (deleteAffectedCacheEntries) {
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
tblCache.queries.query[indexName] = filteredEntries;
|
|
4378
|
-
}
|
|
4379
|
-
}
|
|
4380
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
4381
|
-
finally {
|
|
4382
|
-
try {
|
|
4383
|
-
if (updatedEntryLists_1_1 && !updatedEntryLists_1_1.done && (_c = updatedEntryLists_1.return)) _c.call(updatedEntryLists_1);
|
|
4384
|
-
}
|
|
4385
|
-
finally { if (e_4) throw e_4.error; }
|
|
4063
|
+
for (var _d = 0, updatedEntryLists_1 = updatedEntryLists; _d < updatedEntryLists_1.length; _d++) {
|
|
4064
|
+
var _e = updatedEntryLists_1[_d], indexName = _e[0], filteredEntries = _e[1];
|
|
4065
|
+
tblCache.queries.query[indexName] = filteredEntries;
|
|
4386
4066
|
}
|
|
4387
4067
|
}
|
|
4388
4068
|
}
|
|
@@ -4633,7 +4313,6 @@
|
|
|
4633
4313
|
}
|
|
4634
4314
|
function createVirtualIndexMiddleware(down) {
|
|
4635
4315
|
return __assign(__assign({}, down), { table: function (tableName) {
|
|
4636
|
-
var e_1, _a;
|
|
4637
4316
|
var table = down.table(tableName);
|
|
4638
4317
|
var schema = table.schema;
|
|
4639
4318
|
var indexLookup = {};
|
|
@@ -4661,18 +4340,9 @@
|
|
|
4661
4340
|
}
|
|
4662
4341
|
var primaryKey = addVirtualIndexes(schema.primaryKey.keyPath, 0, schema.primaryKey);
|
|
4663
4342
|
indexLookup[":id"] = [primaryKey];
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
addVirtualIndexes(index.keyPath, 0, index);
|
|
4668
|
-
}
|
|
4669
|
-
}
|
|
4670
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
4671
|
-
finally {
|
|
4672
|
-
try {
|
|
4673
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4674
|
-
}
|
|
4675
|
-
finally { if (e_1) throw e_1.error; }
|
|
4343
|
+
for (var _i = 0, _a = schema.indexes; _i < _a.length; _i++) {
|
|
4344
|
+
var index = _a[_i];
|
|
4345
|
+
addVirtualIndexes(index.keyPath, 0, index);
|
|
4676
4346
|
}
|
|
4677
4347
|
function findBestIndex(keyPath) {
|
|
4678
4348
|
var result = indexLookup[getKeyPathAlias(keyPath)];
|
|
@@ -4832,9 +4502,9 @@
|
|
|
4832
4502
|
throw new Error("Keys missing");
|
|
4833
4503
|
req = req.type === 'add' || req.type === 'put' ? __assign(__assign({}, req), { keys: keys }) : __assign({}, req);
|
|
4834
4504
|
if (req.type !== 'delete')
|
|
4835
|
-
req.values = __spreadArray([],
|
|
4505
|
+
req.values = __spreadArray([], req.values, true);
|
|
4836
4506
|
if (req.keys)
|
|
4837
|
-
req.keys = __spreadArray([],
|
|
4507
|
+
req.keys = __spreadArray([], req.keys, true);
|
|
4838
4508
|
return getExistingValues(downTable, req, keys).then(function (existingValues) {
|
|
4839
4509
|
var contexts = keys.map(function (key, i) {
|
|
4840
4510
|
var existingValue = existingValues[i];
|
|
@@ -5024,13 +4694,13 @@
|
|
|
5024
4694
|
var pkRangeSet = getRangeSet("");
|
|
5025
4695
|
var delsRangeSet = getRangeSet(":dels");
|
|
5026
4696
|
var type = req.type;
|
|
5027
|
-
var _c =
|
|
4697
|
+
var _c = req.type === "deleteRange"
|
|
5028
4698
|
? [req.range]
|
|
5029
4699
|
: req.type === "delete"
|
|
5030
4700
|
? [req.keys]
|
|
5031
4701
|
: req.values.length < 50
|
|
5032
4702
|
? [getEffectiveKeys(primaryKey, req).filter(function (id) { return id; }), req.values]
|
|
5033
|
-
: [],
|
|
4703
|
+
: [], keys = _c[0], newObjs = _c[1];
|
|
5034
4704
|
var oldCache = req.trans["_cache"];
|
|
5035
4705
|
if (isArray(keys)) {
|
|
5036
4706
|
pkRangeSet.addKeys(keys);
|
|
@@ -5104,7 +4774,7 @@
|
|
|
5104
4774
|
};
|
|
5105
4775
|
var pkRangeSet_1 = getRangeSet("");
|
|
5106
4776
|
var delsRangeSet_1 = getRangeSet(":dels");
|
|
5107
|
-
var _a =
|
|
4777
|
+
var _a = readSubscribers[method](req), queriedIndex = _a[0], queriedRanges = _a[1];
|
|
5108
4778
|
if (method === 'query' && queriedIndex.isPrimaryKey && !req.values) {
|
|
5109
4779
|
delsRangeSet_1.add(queriedRanges);
|
|
5110
4780
|
}
|
|
@@ -5446,106 +5116,60 @@
|
|
|
5446
5116
|
var ac_1 = new AbortController();
|
|
5447
5117
|
var signal = ac_1.signal;
|
|
5448
5118
|
var endTransaction = function (wasCommitted) { return function () {
|
|
5449
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
5450
5119
|
ac_1.abort();
|
|
5451
5120
|
if (mode === 'readwrite') {
|
|
5452
5121
|
var affectedSubscribers_1 = new Set();
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
if (obsSetsOverlap(entry.obsSet, idbtrans.mutatedParts)) {
|
|
5468
|
-
delArrayItem(entries, entry);
|
|
5469
|
-
entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
|
|
5470
|
-
}
|
|
5471
|
-
}
|
|
5472
|
-
}
|
|
5473
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
5474
|
-
finally {
|
|
5475
|
-
try {
|
|
5476
|
-
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
5477
|
-
}
|
|
5478
|
-
finally { if (e_3) throw e_3.error; }
|
|
5479
|
-
}
|
|
5122
|
+
for (var _i = 0, stores_1 = stores; _i < stores_1.length; _i++) {
|
|
5123
|
+
var storeName = stores_1[_i];
|
|
5124
|
+
var tblCache = cache["idb://".concat(dbName, "/").concat(storeName)];
|
|
5125
|
+
if (tblCache) {
|
|
5126
|
+
var table = core.table(storeName);
|
|
5127
|
+
var ops = tblCache.optimisticOps.filter(function (op) { return op.trans === idbtrans; });
|
|
5128
|
+
if (idbtrans._explicit && wasCommitted && idbtrans.mutatedParts) {
|
|
5129
|
+
for (var _a = 0, _b = Object.values(tblCache.queries.query); _a < _b.length; _a++) {
|
|
5130
|
+
var entries = _b[_a];
|
|
5131
|
+
for (var _c = 0, _d = entries.slice(); _c < _d.length; _c++) {
|
|
5132
|
+
var entry = _d[_c];
|
|
5133
|
+
if (obsSetsOverlap(entry.obsSet, idbtrans.mutatedParts)) {
|
|
5134
|
+
delArrayItem(entries, entry);
|
|
5135
|
+
entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
|
|
5480
5136
|
}
|
|
5481
5137
|
}
|
|
5482
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
5483
|
-
finally {
|
|
5484
|
-
try {
|
|
5485
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
5486
|
-
}
|
|
5487
|
-
finally { if (e_2) throw e_2.error; }
|
|
5488
|
-
}
|
|
5489
5138
|
}
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
idbtrans.mutatedParts
|
|
5139
|
+
}
|
|
5140
|
+
else if (ops.length > 0) {
|
|
5141
|
+
tblCache.optimisticOps = tblCache.optimisticOps.filter(function (op) { return op.trans !== idbtrans; });
|
|
5142
|
+
for (var _e = 0, _f = Object.values(tblCache.queries.query); _e < _f.length; _e++) {
|
|
5143
|
+
var entries = _f[_e];
|
|
5144
|
+
for (var _g = 0, _h = entries.slice(); _g < _h.length; _g++) {
|
|
5145
|
+
var entry = _h[_g];
|
|
5146
|
+
if (entry.res != null &&
|
|
5147
|
+
idbtrans.mutatedParts
|
|
5500
5148
|
) {
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
}
|
|
5512
|
-
}
|
|
5513
|
-
else {
|
|
5514
|
-
if (entry.dirty) {
|
|
5515
|
-
delArrayItem(entries, entry);
|
|
5516
|
-
}
|
|
5517
|
-
entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
|
|
5518
|
-
}
|
|
5519
|
-
}
|
|
5149
|
+
if (wasCommitted && !entry.dirty) {
|
|
5150
|
+
var freezeResults = Object.isFrozen(entry.res);
|
|
5151
|
+
var modRes = applyOptimisticOps(entry.res, entry.req, ops, table, entry, freezeResults);
|
|
5152
|
+
if (entry.dirty) {
|
|
5153
|
+
delArrayItem(entries, entry);
|
|
5154
|
+
entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
|
|
5155
|
+
}
|
|
5156
|
+
else if (modRes !== entry.res) {
|
|
5157
|
+
entry.res = modRes;
|
|
5158
|
+
entry.promise = DexiePromise.resolve({ result: modRes });
|
|
5520
5159
|
}
|
|
5521
5160
|
}
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
if (_o && !_o.done && (_e = _m.return)) _e.call(_m);
|
|
5161
|
+
else {
|
|
5162
|
+
if (entry.dirty) {
|
|
5163
|
+
delArrayItem(entries, entry);
|
|
5526
5164
|
}
|
|
5527
|
-
|
|
5165
|
+
entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
|
|
5528
5166
|
}
|
|
5529
5167
|
}
|
|
5530
5168
|
}
|
|
5531
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
5532
|
-
finally {
|
|
5533
|
-
try {
|
|
5534
|
-
if (_l && !_l.done && (_d = _k.return)) _d.call(_k);
|
|
5535
|
-
}
|
|
5536
|
-
finally { if (e_4) throw e_4.error; }
|
|
5537
|
-
}
|
|
5538
5169
|
}
|
|
5539
5170
|
}
|
|
5540
5171
|
}
|
|
5541
5172
|
}
|
|
5542
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5543
|
-
finally {
|
|
5544
|
-
try {
|
|
5545
|
-
if (stores_1_1 && !stores_1_1.done && (_a = stores_1.return)) _a.call(stores_1);
|
|
5546
|
-
}
|
|
5547
|
-
finally { if (e_1) throw e_1.error; }
|
|
5548
|
-
}
|
|
5549
5173
|
affectedSubscribers_1.forEach(function (requery) { return requery(); });
|
|
5550
5174
|
}
|
|
5551
5175
|
}; };
|
|
@@ -5618,7 +5242,7 @@
|
|
|
5618
5242
|
return downTable.query(req);
|
|
5619
5243
|
var freezeResults = ((_a = PSD.trans) === null || _a === void 0 ? void 0 : _a.db._options.cache) === 'immutable';
|
|
5620
5244
|
var _b = PSD, requery = _b.requery, signal = _b.signal;
|
|
5621
|
-
var _c =
|
|
5245
|
+
var _c = findCompatibleQuery(dbName, tableName, 'query', req), cacheEntry = _c[0], exactMatch = _c[1], tblCache = _c[2], container = _c[3];
|
|
5622
5246
|
if (cacheEntry && exactMatch) {
|
|
5623
5247
|
cacheEntry.obsSet = req.obsSet;
|
|
5624
5248
|
}
|
|
@@ -5692,181 +5316,6 @@
|
|
|
5692
5316
|
});
|
|
5693
5317
|
}
|
|
5694
5318
|
|
|
5695
|
-
function compressYDocs(db, interval) {
|
|
5696
|
-
var e_1, _a, e_2, _b;
|
|
5697
|
-
var p = Promise.resolve();
|
|
5698
|
-
try {
|
|
5699
|
-
for (var _c = __values(db.tables), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
5700
|
-
var table = _d.value;
|
|
5701
|
-
var _loop_1 = function (yProp) {
|
|
5702
|
-
p = p.then(function () { return compressYDocsTable(db, yProp, interval); });
|
|
5703
|
-
};
|
|
5704
|
-
try {
|
|
5705
|
-
for (var _e = (e_2 = void 0, __values(table.schema.yProps || [])), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
5706
|
-
var yProp = _f.value;
|
|
5707
|
-
_loop_1(yProp);
|
|
5708
|
-
}
|
|
5709
|
-
}
|
|
5710
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
5711
|
-
finally {
|
|
5712
|
-
try {
|
|
5713
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
5714
|
-
}
|
|
5715
|
-
finally { if (e_2) throw e_2.error; }
|
|
5716
|
-
}
|
|
5717
|
-
}
|
|
5718
|
-
}
|
|
5719
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
5720
|
-
finally {
|
|
5721
|
-
try {
|
|
5722
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
5723
|
-
}
|
|
5724
|
-
finally { if (e_1) throw e_1.error; }
|
|
5725
|
-
}
|
|
5726
|
-
return p;
|
|
5727
|
-
}
|
|
5728
|
-
function compressYDocsTable(db, _a, skipIfRunnedSince
|
|
5729
|
-
) {
|
|
5730
|
-
var updatesTable = _a.updatesTable;
|
|
5731
|
-
var updTbl = db.table(updatesTable);
|
|
5732
|
-
return Promise.all([
|
|
5733
|
-
updTbl
|
|
5734
|
-
.where('i')
|
|
5735
|
-
.startsWith('')
|
|
5736
|
-
.toArray(),
|
|
5737
|
-
db.transaction('rw', updatesTable, function () {
|
|
5738
|
-
return updTbl.get(0).then(function (lastCompressed) {
|
|
5739
|
-
if (lastCompressed &&
|
|
5740
|
-
skipIfRunnedSince &&
|
|
5741
|
-
lastCompressed.lastRun.getTime() > Date.now() - skipIfRunnedSince) {
|
|
5742
|
-
return null;
|
|
5743
|
-
}
|
|
5744
|
-
lastCompressed = lastCompressed || { i: 0, lastCompressed: 0 };
|
|
5745
|
-
return updTbl
|
|
5746
|
-
.put(__assign(__assign({}, lastCompressed), { lastRun: new Date() }))
|
|
5747
|
-
.then(function () { return lastCompressed; });
|
|
5748
|
-
});
|
|
5749
|
-
}),
|
|
5750
|
-
]).then(function (_a) {
|
|
5751
|
-
var _b = __read(_a, 2), syncers = _b[0], stamp = _b[1];
|
|
5752
|
-
if (!stamp)
|
|
5753
|
-
return;
|
|
5754
|
-
var lastCompressedUpdate = stamp.lastCompressed;
|
|
5755
|
-
var unsyncedFrom = Math.min.apply(Math, __spreadArray([], __read(syncers.map(function (s) {
|
|
5756
|
-
return Math.min(s.unsentFrom || Infinity, s.receivedUntil != null ? s.receivedUntil + 1 : Infinity);
|
|
5757
|
-
})), false));
|
|
5758
|
-
return updTbl
|
|
5759
|
-
.where('i')
|
|
5760
|
-
.between(lastCompressedUpdate, Infinity, false)
|
|
5761
|
-
.toArray(function (addedUpdates) {
|
|
5762
|
-
var e_3, _a;
|
|
5763
|
-
if (addedUpdates.length === 0)
|
|
5764
|
-
return;
|
|
5765
|
-
var docsToCompress = [];
|
|
5766
|
-
var lastUpdateToCompress = lastCompressedUpdate;
|
|
5767
|
-
var _loop_2 = function (j) {
|
|
5768
|
-
var updateRow = addedUpdates[j];
|
|
5769
|
-
var i = updateRow.i, f = updateRow.f, k = updateRow.k;
|
|
5770
|
-
if (i >= unsyncedFrom && f & 0x01)
|
|
5771
|
-
return "break";
|
|
5772
|
-
var entry = docsToCompress.find(function (entry) { return cmp(entry.docId, k) === 0; });
|
|
5773
|
-
if (entry)
|
|
5774
|
-
entry.updates.push(updateRow);
|
|
5775
|
-
else
|
|
5776
|
-
docsToCompress.push({ docId: k, updates: [updateRow] });
|
|
5777
|
-
lastUpdateToCompress = i;
|
|
5778
|
-
};
|
|
5779
|
-
for (var j = 0; j < addedUpdates.length; ++j) {
|
|
5780
|
-
var state_1 = _loop_2(j);
|
|
5781
|
-
if (state_1 === "break")
|
|
5782
|
-
break;
|
|
5783
|
-
}
|
|
5784
|
-
if (lastUpdateToCompress === lastCompressedUpdate)
|
|
5785
|
-
return;
|
|
5786
|
-
var p = Promise.resolve();
|
|
5787
|
-
var _loop_3 = function (docId, updates) {
|
|
5788
|
-
p = p.then(function () {
|
|
5789
|
-
return compressUpdatesForDoc(db, updatesTable, docId, updates);
|
|
5790
|
-
});
|
|
5791
|
-
};
|
|
5792
|
-
try {
|
|
5793
|
-
for (var docsToCompress_1 = __values(docsToCompress), docsToCompress_1_1 = docsToCompress_1.next(); !docsToCompress_1_1.done; docsToCompress_1_1 = docsToCompress_1.next()) {
|
|
5794
|
-
var _b = docsToCompress_1_1.value, docId = _b.docId, updates = _b.updates;
|
|
5795
|
-
_loop_3(docId, updates);
|
|
5796
|
-
}
|
|
5797
|
-
}
|
|
5798
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
5799
|
-
finally {
|
|
5800
|
-
try {
|
|
5801
|
-
if (docsToCompress_1_1 && !docsToCompress_1_1.done && (_a = docsToCompress_1.return)) _a.call(docsToCompress_1);
|
|
5802
|
-
}
|
|
5803
|
-
finally { if (e_3) throw e_3.error; }
|
|
5804
|
-
}
|
|
5805
|
-
return p.then(function () {
|
|
5806
|
-
return db.transaction('rw', updTbl, function () {
|
|
5807
|
-
return updTbl.get(0).then(function (current) {
|
|
5808
|
-
if (current && lastUpdateToCompress <= current.lastCompressed) {
|
|
5809
|
-
return;
|
|
5810
|
-
}
|
|
5811
|
-
return updTbl.put(__assign(__assign({}, current), { lastCompressed: lastUpdateToCompress }));
|
|
5812
|
-
});
|
|
5813
|
-
});
|
|
5814
|
-
});
|
|
5815
|
-
});
|
|
5816
|
-
});
|
|
5817
|
-
}
|
|
5818
|
-
function compressUpdatesForDoc(db, updatesTable, parentId, addedUpdatesToCompress) {
|
|
5819
|
-
if (addedUpdatesToCompress.length < 1)
|
|
5820
|
-
throw new Error('Invalid input');
|
|
5821
|
-
return db.transaction('rw', updatesTable, function (tx) {
|
|
5822
|
-
var updTbl = tx.table(updatesTable);
|
|
5823
|
-
return updTbl.where({ k: parentId }).first(function (mainUpdate) {
|
|
5824
|
-
var updates = [mainUpdate].concat(addedUpdatesToCompress.filter(function (u) { return u.i !== mainUpdate.i; }));
|
|
5825
|
-
var Y = getYLibrary(db);
|
|
5826
|
-
var doc = new Y.Doc({ gc: true });
|
|
5827
|
-
updates.forEach(function (update) {
|
|
5828
|
-
Y.applyUpdateV2(doc, update.u);
|
|
5829
|
-
});
|
|
5830
|
-
var compressedUpdate = Y.encodeStateAsUpdateV2(doc);
|
|
5831
|
-
var lastUpdate = updates.pop();
|
|
5832
|
-
return updTbl
|
|
5833
|
-
.put({
|
|
5834
|
-
i: lastUpdate.i,
|
|
5835
|
-
k: parentId,
|
|
5836
|
-
u: compressedUpdate,
|
|
5837
|
-
})
|
|
5838
|
-
.then(function () { return updTbl.bulkDelete(updates.map(function (update) { return update.i; })); });
|
|
5839
|
-
});
|
|
5840
|
-
});
|
|
5841
|
-
}
|
|
5842
|
-
|
|
5843
|
-
var GC_DELAY = 10000;
|
|
5844
|
-
var GC_INTERVAL = 300000;
|
|
5845
|
-
function periodicGC(db) {
|
|
5846
|
-
var timer = null;
|
|
5847
|
-
db.on('ready', function (db) {
|
|
5848
|
-
if (db.tables.some(function (tbl) { return tbl.schema.yProps; })) {
|
|
5849
|
-
var gc_1 = function () {
|
|
5850
|
-
if (!db.isOpen())
|
|
5851
|
-
return;
|
|
5852
|
-
compressYDocs(db, GC_INTERVAL).catch(function (err) {
|
|
5853
|
-
if (err && err.name === 'DatabaseClosedError')
|
|
5854
|
-
return;
|
|
5855
|
-
console.debug('Error during periodic GC', err);
|
|
5856
|
-
}).then(function () {
|
|
5857
|
-
timer = setTimeout(gc_1, GC_INTERVAL);
|
|
5858
|
-
});
|
|
5859
|
-
};
|
|
5860
|
-
timer = setTimeout(gc_1, GC_DELAY);
|
|
5861
|
-
}
|
|
5862
|
-
}, true);
|
|
5863
|
-
db.on('close', function () {
|
|
5864
|
-
if (timer)
|
|
5865
|
-
clearTimeout(timer);
|
|
5866
|
-
timer = null;
|
|
5867
|
-
});
|
|
5868
|
-
}
|
|
5869
|
-
|
|
5870
5319
|
var Dexie$1 = (function () {
|
|
5871
5320
|
function Dexie(name, options) {
|
|
5872
5321
|
var _this = this;
|
|
@@ -5908,7 +5357,7 @@
|
|
|
5908
5357
|
});
|
|
5909
5358
|
this._state = state;
|
|
5910
5359
|
this.name = name;
|
|
5911
|
-
this.on = Events(this, "populate", "blocked", "versionchange", "close",
|
|
5360
|
+
this.on = Events(this, "populate", "blocked", "versionchange", "close", { ready: [promisableChain, nop] });
|
|
5912
5361
|
this.once = function (event, callback) {
|
|
5913
5362
|
var fn = function () {
|
|
5914
5363
|
var args = [];
|
|
@@ -5998,8 +5447,6 @@
|
|
|
5998
5447
|
}
|
|
5999
5448
|
});
|
|
6000
5449
|
this.vip = vipDB;
|
|
6001
|
-
if ((options === null || options === void 0 ? void 0 : options.Y) && (options === null || options === void 0 ? void 0 : options.gc) !== false)
|
|
6002
|
-
periodicGC(this);
|
|
6003
5450
|
addons.forEach(function (addon) { return addon(_this); });
|
|
6004
5451
|
}
|
|
6005
5452
|
Dexie.prototype.version = function (versionNumber) {
|
|
@@ -6220,9 +5667,6 @@
|
|
|
6220
5667
|
}
|
|
6221
5668
|
return this._allTables[tableName];
|
|
6222
5669
|
};
|
|
6223
|
-
Dexie.prototype.gc = function () {
|
|
6224
|
-
return compressYDocs(this);
|
|
6225
|
-
};
|
|
6226
5670
|
return Dexie;
|
|
6227
5671
|
}());
|
|
6228
5672
|
|
|
@@ -6523,252 +5967,6 @@
|
|
|
6523
5967
|
return new PropModification({ replacePrefix: [a, b] });
|
|
6524
5968
|
}
|
|
6525
5969
|
|
|
6526
|
-
function observeYDocUpdates(provider, doc, db, parentTableName, updatesTableName, parentId, Y) {
|
|
6527
|
-
var lastUpdateId = 0;
|
|
6528
|
-
var initial = true;
|
|
6529
|
-
var subscription = liveQuery(function () {
|
|
6530
|
-
throwIfDestroyed(doc);
|
|
6531
|
-
var updatesTable = db.table(updatesTableName);
|
|
6532
|
-
return Promise.all([
|
|
6533
|
-
(lastUpdateId > 0
|
|
6534
|
-
? updatesTable
|
|
6535
|
-
.where('i')
|
|
6536
|
-
.between(lastUpdateId, Infinity, false)
|
|
6537
|
-
.toArray()
|
|
6538
|
-
.then(function (updates) {
|
|
6539
|
-
return updates.filter(function (update) { return cmp(update.k, parentId) === 0; });
|
|
6540
|
-
})
|
|
6541
|
-
: updatesTable.where({ k: parentId }).toArray()).then(function (updates) {
|
|
6542
|
-
return updates;
|
|
6543
|
-
}),
|
|
6544
|
-
db.table(parentTableName).where(':id').equals(parentId).toArray(),
|
|
6545
|
-
]);
|
|
6546
|
-
}).subscribe(function (_a) {
|
|
6547
|
-
var _b = __read(_a, 2), updates = _b[0], parentRow = _b[1];
|
|
6548
|
-
if (updates.length > 0)
|
|
6549
|
-
lastUpdateId = updates[updates.length - 1].i;
|
|
6550
|
-
if (parentRow.length === 0) {
|
|
6551
|
-
doc.destroy();
|
|
6552
|
-
return;
|
|
6553
|
-
}
|
|
6554
|
-
throwIfDestroyed(doc);
|
|
6555
|
-
if (updates.length > 0) {
|
|
6556
|
-
Y.transact(doc, function () {
|
|
6557
|
-
updates.forEach(function (update) {
|
|
6558
|
-
try {
|
|
6559
|
-
DexieYProvider.currentUpdateRow = update;
|
|
6560
|
-
Y.applyUpdateV2(doc, update.u);
|
|
6561
|
-
}
|
|
6562
|
-
finally {
|
|
6563
|
-
DexieYProvider.currentUpdateRow = null;
|
|
6564
|
-
}
|
|
6565
|
-
});
|
|
6566
|
-
}, provider, false);
|
|
6567
|
-
}
|
|
6568
|
-
if (initial) {
|
|
6569
|
-
initial = false;
|
|
6570
|
-
doc.emit('load', [doc]);
|
|
6571
|
-
}
|
|
6572
|
-
}, function (error) {
|
|
6573
|
-
provider.on('error').fire(error);
|
|
6574
|
-
});
|
|
6575
|
-
var onUpdate = function (update, origin) {
|
|
6576
|
-
if (origin === provider)
|
|
6577
|
-
return;
|
|
6578
|
-
db.table(updatesTableName)
|
|
6579
|
-
.add({
|
|
6580
|
-
k: parentId,
|
|
6581
|
-
u: update,
|
|
6582
|
-
f: 1,
|
|
6583
|
-
})
|
|
6584
|
-
.then(function (i) {
|
|
6585
|
-
if (i === lastUpdateId - 1)
|
|
6586
|
-
++lastUpdateId;
|
|
6587
|
-
})
|
|
6588
|
-
.catch(function (error) {
|
|
6589
|
-
provider.on('error').fire(error);
|
|
6590
|
-
});
|
|
6591
|
-
};
|
|
6592
|
-
var stopObserving = function () {
|
|
6593
|
-
subscription.unsubscribe();
|
|
6594
|
-
doc.off('updateV2', onUpdate);
|
|
6595
|
-
doc.off('destroy', stopObserving);
|
|
6596
|
-
};
|
|
6597
|
-
doc.on('updateV2', onUpdate);
|
|
6598
|
-
doc.on('destroy', stopObserving);
|
|
6599
|
-
return stopObserving;
|
|
6600
|
-
}
|
|
6601
|
-
|
|
6602
|
-
var wm = new WeakMap();
|
|
6603
|
-
function createEvents() {
|
|
6604
|
-
return Events(null, 'load', 'sync', 'error');
|
|
6605
|
-
}
|
|
6606
|
-
var DexieYProvider = (function () {
|
|
6607
|
-
function DexieYProvider(doc) {
|
|
6608
|
-
var _this = this;
|
|
6609
|
-
this.refCount = 1;
|
|
6610
|
-
this.cleanupHandlers = [];
|
|
6611
|
-
this.graceTimeout = -1;
|
|
6612
|
-
this.destroyed = false;
|
|
6613
|
-
this.on = createEvents();
|
|
6614
|
-
this.doc = doc;
|
|
6615
|
-
this.off = function (name, f) { var _a; return (_a = _this.on[name]) === null || _a === void 0 ? void 0 : _a.unsubscribe(f); };
|
|
6616
|
-
if ('dispose' in Symbol) {
|
|
6617
|
-
this[Symbol.dispose] =
|
|
6618
|
-
function () { return DexieYProvider.release(doc); };
|
|
6619
|
-
}
|
|
6620
|
-
doc.on('load', function () { return _this.on('load').fire(); });
|
|
6621
|
-
doc.on('sync', function (sync) { return sync !== false && _this.on('sync').fire(); });
|
|
6622
|
-
doc.on('destroy', this.destroy.bind(this));
|
|
6623
|
-
this.on('error', function (error) {
|
|
6624
|
-
_this._error = error;
|
|
6625
|
-
});
|
|
6626
|
-
var _a = doc.meta || {}, db = _a.db, parentTable = _a.parentTable, parentId = _a.parentId, updatesTable = _a.updatesTable;
|
|
6627
|
-
if (!db || !parentTable || !updatesTable) {
|
|
6628
|
-
throw new Error("Missing Dexie-related metadata in Y.Doc. Documents need to be obtained through Y.Doc properties from dexie queries.");
|
|
6629
|
-
}
|
|
6630
|
-
if (!db.table(parentTable) || !db.table(updatesTable)) {
|
|
6631
|
-
throw new Error("Table ".concat(parentTable, " or ").concat(updatesTable, " not found in db"));
|
|
6632
|
-
}
|
|
6633
|
-
throwIfDestroyed(doc);
|
|
6634
|
-
var Y = getYLibrary(db);
|
|
6635
|
-
this.stopObserving = observeYDocUpdates(this, doc, db, parentTable, updatesTable, parentId, Y);
|
|
6636
|
-
db.on.y.fire(this, Y);
|
|
6637
|
-
}
|
|
6638
|
-
DexieYProvider.getOrCreateDocument = function (db, table, prop, id) {
|
|
6639
|
-
var _a, _b;
|
|
6640
|
-
var docCache = getDocCache(db);
|
|
6641
|
-
var updatesTable = (_b = (_a = db.table(table).schema.yProps) === null || _a === void 0 ? void 0 : _a.find(function (p) { return p.prop === prop; })) === null || _b === void 0 ? void 0 : _b.updatesTable;
|
|
6642
|
-
return getOrCreateDocument(db, docCache, getYLibrary(db), table, prop, updatesTable, id);
|
|
6643
|
-
};
|
|
6644
|
-
DexieYProvider.load = function (doc, options) {
|
|
6645
|
-
var _a;
|
|
6646
|
-
var p = wm.get(doc);
|
|
6647
|
-
if (p) {
|
|
6648
|
-
++p.refCount;
|
|
6649
|
-
if ((options === null || options === void 0 ? void 0 : options.gracePeriod) != null && p.graceTimeout < options.gracePeriod) {
|
|
6650
|
-
p.graceTimeout = options.gracePeriod;
|
|
6651
|
-
}
|
|
6652
|
-
if (p.graceTimer) {
|
|
6653
|
-
clearTimeout(p.graceTimer);
|
|
6654
|
-
p.graceTimer = null;
|
|
6655
|
-
}
|
|
6656
|
-
}
|
|
6657
|
-
else {
|
|
6658
|
-
p = new DexieYProvider(doc);
|
|
6659
|
-
p.graceTimeout = (_a = options === null || options === void 0 ? void 0 : options.gracePeriod) !== null && _a !== void 0 ? _a : -1;
|
|
6660
|
-
wm.set(doc, p);
|
|
6661
|
-
}
|
|
6662
|
-
return p;
|
|
6663
|
-
};
|
|
6664
|
-
DexieYProvider.release = function (doc) {
|
|
6665
|
-
if (!doc || destroyedDocs.has(doc))
|
|
6666
|
-
return;
|
|
6667
|
-
var p = wm.get(doc);
|
|
6668
|
-
if (p) {
|
|
6669
|
-
if (--p.refCount <= 0) {
|
|
6670
|
-
if (p.graceTimeout < 0) {
|
|
6671
|
-
p._release();
|
|
6672
|
-
}
|
|
6673
|
-
else if (!p.graceTimer) {
|
|
6674
|
-
p.graceTimer = setTimeout(function () {
|
|
6675
|
-
p.graceTimer = null;
|
|
6676
|
-
if (p.refCount === 0) {
|
|
6677
|
-
p._release();
|
|
6678
|
-
}
|
|
6679
|
-
}, p.graceTimeout
|
|
6680
|
-
);
|
|
6681
|
-
}
|
|
6682
|
-
}
|
|
6683
|
-
}
|
|
6684
|
-
else {
|
|
6685
|
-
doc.destroy();
|
|
6686
|
-
}
|
|
6687
|
-
};
|
|
6688
|
-
DexieYProvider.prototype._release = function () {
|
|
6689
|
-
var _this = this;
|
|
6690
|
-
if (!this.doc)
|
|
6691
|
-
return;
|
|
6692
|
-
Promise.resolve(DexieYProvider.on('beforeunload').fire(this)).finally(function () {
|
|
6693
|
-
var _a;
|
|
6694
|
-
if (_this.refCount === 0) {
|
|
6695
|
-
(_a = _this.doc) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
6696
|
-
}
|
|
6697
|
-
});
|
|
6698
|
-
};
|
|
6699
|
-
DexieYProvider.for = function (doc) {
|
|
6700
|
-
return wm.get(doc);
|
|
6701
|
-
};
|
|
6702
|
-
Object.defineProperty(DexieYProvider.prototype, "whenLoaded", {
|
|
6703
|
-
get: function () {
|
|
6704
|
-
var _this = this;
|
|
6705
|
-
if (!this._whenLoaded) {
|
|
6706
|
-
this._whenLoaded = new Promise(function (resolve, reject) {
|
|
6707
|
-
if (_this.doc.isLoaded)
|
|
6708
|
-
resolve();
|
|
6709
|
-
else if (_this._error)
|
|
6710
|
-
reject(_this._error);
|
|
6711
|
-
else if (destroyedDocs.has(_this.doc)) {
|
|
6712
|
-
reject(new exceptions.Abort('Document was destroyed before loaded'));
|
|
6713
|
-
}
|
|
6714
|
-
else {
|
|
6715
|
-
_this.on('load', resolve);
|
|
6716
|
-
_this.on('error', reject);
|
|
6717
|
-
_this.doc.on('destroy', function () { return reject(new exceptions.Abort('Document was destroyed before loaded')); });
|
|
6718
|
-
}
|
|
6719
|
-
});
|
|
6720
|
-
}
|
|
6721
|
-
return this._whenLoaded;
|
|
6722
|
-
},
|
|
6723
|
-
enumerable: false,
|
|
6724
|
-
configurable: true
|
|
6725
|
-
});
|
|
6726
|
-
Object.defineProperty(DexieYProvider.prototype, "whenSynced", {
|
|
6727
|
-
get: function () {
|
|
6728
|
-
var _this = this;
|
|
6729
|
-
if (!this._whenSynced) {
|
|
6730
|
-
this._whenSynced = new Promise(function (resolve, reject) {
|
|
6731
|
-
if (_this.doc.isSynced)
|
|
6732
|
-
resolve();
|
|
6733
|
-
else if (_this._error)
|
|
6734
|
-
reject(_this._error);
|
|
6735
|
-
else if (destroyedDocs.has(_this.doc)) {
|
|
6736
|
-
reject(new exceptions.Abort('Document was destroyed before synced'));
|
|
6737
|
-
}
|
|
6738
|
-
else {
|
|
6739
|
-
_this.on('sync', resolve);
|
|
6740
|
-
_this.on('error', reject);
|
|
6741
|
-
_this.doc.on('destroy', function () { return reject(new exceptions.Abort('Document was destroyed before synced')); });
|
|
6742
|
-
}
|
|
6743
|
-
});
|
|
6744
|
-
}
|
|
6745
|
-
return this._whenSynced;
|
|
6746
|
-
},
|
|
6747
|
-
enumerable: false,
|
|
6748
|
-
configurable: true
|
|
6749
|
-
});
|
|
6750
|
-
DexieYProvider.prototype.destroy = function () {
|
|
6751
|
-
var _a, _b;
|
|
6752
|
-
console.debug("YDoc ".concat((_a = this.doc.meta) === null || _a === void 0 ? void 0 : _a.parentId, " was destroyed"));
|
|
6753
|
-
wm.delete(this.doc);
|
|
6754
|
-
this.doc = null;
|
|
6755
|
-
this.destroyed = true;
|
|
6756
|
-
this.refCount = 0;
|
|
6757
|
-
(_b = this.stopObserving) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
6758
|
-
this.on = createEvents();
|
|
6759
|
-
this.cleanupHandlers.forEach(function (cleanup) { return cleanup(); });
|
|
6760
|
-
};
|
|
6761
|
-
DexieYProvider.prototype.addCleanupHandler = function (cleanupHandler) {
|
|
6762
|
-
this.cleanupHandlers.push(typeof cleanupHandler === 'function'
|
|
6763
|
-
? cleanupHandler
|
|
6764
|
-
: function () { return cleanupHandler.unsubscribe(); });
|
|
6765
|
-
};
|
|
6766
|
-
DexieYProvider.on = Events(null, { beforeunload: [promisableChain] });
|
|
6767
|
-
DexieYProvider.getDocCache = getDocCache;
|
|
6768
|
-
DexieYProvider.currentUpdateRow = null;
|
|
6769
|
-
return DexieYProvider;
|
|
6770
|
-
}());
|
|
6771
|
-
|
|
6772
5970
|
DexiePromise.rejectionMapper = mapError;
|
|
6773
5971
|
setDebug(debug);
|
|
6774
5972
|
|
|
@@ -6785,8 +5983,7 @@
|
|
|
6785
5983
|
'default': Dexie$1,
|
|
6786
5984
|
RangeSet: RangeSet,
|
|
6787
5985
|
mergeRanges: mergeRanges,
|
|
6788
|
-
rangesOverlap: rangesOverlap
|
|
6789
|
-
DexieYProvider: DexieYProvider
|
|
5986
|
+
rangesOverlap: rangesOverlap
|
|
6790
5987
|
});
|
|
6791
5988
|
|
|
6792
5989
|
__assign(Dexie$1, namedExports, { default: Dexie$1 });
|