dexie 4.0.9-alpha.1 → 4.0.9
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 +9 -175
- package/dist/dexie.js +87 -469
- 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 +87 -468
- 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 +86 -430
- package/dist/modern/dexie.mjs.map +1 -1
- package/import-wrapper-prod.mjs +2 -4
- package/import-wrapper.mjs +2 -5
- package/package.json +4 -6
- package/dist/README.md +0 -46
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.9
|
|
7
|
+
* Version 4.0.9, Mon Oct 21 2024
|
|
8
8
|
*
|
|
9
9
|
* https://dexie.org
|
|
10
10
|
*
|
|
@@ -776,6 +776,8 @@
|
|
|
776
776
|
}); });
|
|
777
777
|
});
|
|
778
778
|
});
|
|
779
|
+
if (NativePromise.withResolvers)
|
|
780
|
+
DexiePromise.withResolvers = NativePromise.withResolvers;
|
|
779
781
|
}
|
|
780
782
|
function executePromiseTask(promise, fn) {
|
|
781
783
|
try {
|
|
@@ -1150,7 +1152,7 @@
|
|
|
1150
1152
|
}
|
|
1151
1153
|
}
|
|
1152
1154
|
|
|
1153
|
-
var DEXIE_VERSION = '4.0.9
|
|
1155
|
+
var DEXIE_VERSION = '4.0.9';
|
|
1154
1156
|
var maxString = String.fromCharCode(65535);
|
|
1155
1157
|
var minKey = -Infinity;
|
|
1156
1158
|
var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
|
|
@@ -1268,95 +1270,6 @@
|
|
|
1268
1270
|
return new Uint8Array(a);
|
|
1269
1271
|
}
|
|
1270
1272
|
|
|
1271
|
-
function getDocCache(db) {
|
|
1272
|
-
var _a;
|
|
1273
|
-
var _b;
|
|
1274
|
-
return (_a = (_b = db._novip)['_docCache']) !== null && _a !== void 0 ? _a : (_b['_docCache'] = {
|
|
1275
|
-
cache: {},
|
|
1276
|
-
get size() {
|
|
1277
|
-
return Object.keys(this.cache).length;
|
|
1278
|
-
},
|
|
1279
|
-
find: function (table, primaryKey, ydocProp) {
|
|
1280
|
-
var cacheKey = getYDocCacheKey(table, primaryKey, ydocProp);
|
|
1281
|
-
var docRef = this.cache[cacheKey];
|
|
1282
|
-
return docRef ? docRef.deref() : undefined;
|
|
1283
|
-
},
|
|
1284
|
-
add: function (doc) {
|
|
1285
|
-
var _a = doc.meta, parentTable = _a.parentTable, parentId = _a.parentId, parentProp = _a.parentProp;
|
|
1286
|
-
if (!parentTable || !parentProp || parentId == null)
|
|
1287
|
-
throw new Error("Missing Dexie-related metadata in Y.Doc");
|
|
1288
|
-
var cacheKey = getYDocCacheKey(parentTable, parentId, parentProp);
|
|
1289
|
-
this.cache[cacheKey] = new WeakRef(doc);
|
|
1290
|
-
docRegistry.register(doc, { cache: this.cache, key: cacheKey });
|
|
1291
|
-
},
|
|
1292
|
-
delete: function (doc) {
|
|
1293
|
-
docRegistry.unregister(doc);
|
|
1294
|
-
delete this.cache[getYDocCacheKey(doc.meta.parentTable, doc.meta.parentId, doc.meta.parentProp)];
|
|
1295
|
-
},
|
|
1296
|
-
});
|
|
1297
|
-
}
|
|
1298
|
-
var docRegistry = new FinalizationRegistry(function (_a) {
|
|
1299
|
-
var cache = _a.cache, key = _a.key;
|
|
1300
|
-
delete cache[key];
|
|
1301
|
-
});
|
|
1302
|
-
var destroyed = new WeakSet();
|
|
1303
|
-
function throwIfDestroyed(doc) {
|
|
1304
|
-
if (destroyed.has(doc))
|
|
1305
|
-
throw new Error('Y.Doc has been destroyed');
|
|
1306
|
-
}
|
|
1307
|
-
function getYDocCacheKey(table, primaryKey, ydocProp) {
|
|
1308
|
-
return "".concat(table, "[").concat(primaryKey, "].").concat(ydocProp);
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
function createYDocProperty(db, Y, table, prop, updatesTable) {
|
|
1312
|
-
var pkKeyPath = table.schema.primKey.keyPath;
|
|
1313
|
-
var docCache = getDocCache(db);
|
|
1314
|
-
return {
|
|
1315
|
-
get: function () {
|
|
1316
|
-
var id = getByKeyPath(this, pkKeyPath);
|
|
1317
|
-
var doc = docCache.find(table.name, id, prop);
|
|
1318
|
-
if (doc)
|
|
1319
|
-
return doc;
|
|
1320
|
-
doc = new Y.Doc({
|
|
1321
|
-
meta: {
|
|
1322
|
-
db: db,
|
|
1323
|
-
updatesTable: updatesTable,
|
|
1324
|
-
parentProp: prop,
|
|
1325
|
-
parentTable: table.name,
|
|
1326
|
-
parentId: id
|
|
1327
|
-
},
|
|
1328
|
-
});
|
|
1329
|
-
docCache.add(doc);
|
|
1330
|
-
doc.on('destroy', function () {
|
|
1331
|
-
destroyed.add(doc);
|
|
1332
|
-
docCache.delete(doc);
|
|
1333
|
-
});
|
|
1334
|
-
return doc;
|
|
1335
|
-
},
|
|
1336
|
-
};
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
function builtInDeletionTrigger(table, keys, res) {
|
|
1340
|
-
var yProps = table.schema.yProps;
|
|
1341
|
-
if (!yProps)
|
|
1342
|
-
return res;
|
|
1343
|
-
if (keys && res.numFailures > 0)
|
|
1344
|
-
keys = keys.filter(function (_, i) { return !res.failures[i]; });
|
|
1345
|
-
return Promise.all(yProps.map(function (_a) {
|
|
1346
|
-
var updatesTable = _a.updatesTable;
|
|
1347
|
-
return keys
|
|
1348
|
-
? table.db.table(updatesTable).where('k').anyOf(keys).delete()
|
|
1349
|
-
: table.db.table(updatesTable).clear();
|
|
1350
|
-
})).then(function () { return res; });
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
function getYLibrary(db) {
|
|
1354
|
-
var Y = db._options.Y;
|
|
1355
|
-
if (!Y)
|
|
1356
|
-
throw new exceptions.MissingAPI('Y library not supplied to Dexie constructor');
|
|
1357
|
-
return Y;
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
1273
|
var Table = (function () {
|
|
1361
1274
|
function Table() {
|
|
1362
1275
|
}
|
|
@@ -1432,9 +1345,8 @@
|
|
|
1432
1345
|
console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit from a ") +
|
|
1433
1346
|
"compound index [".concat(keyPaths.join('+'), "]"));
|
|
1434
1347
|
var idxByName = this.schema.idxByName;
|
|
1435
|
-
var idb = this.db._deps.indexedDB;
|
|
1436
1348
|
function equals(a, b) {
|
|
1437
|
-
return
|
|
1349
|
+
return cmp(a, b) === 0;
|
|
1438
1350
|
}
|
|
1439
1351
|
var _a = keyPaths.reduce(function (_a, keyPath) {
|
|
1440
1352
|
var prevIndex = _a[0], prevFilterFn = _a[1];
|
|
@@ -1488,7 +1400,6 @@
|
|
|
1488
1400
|
return this.toCollection().reverse();
|
|
1489
1401
|
};
|
|
1490
1402
|
Table.prototype.mapToClass = function (constructor) {
|
|
1491
|
-
var _this = this;
|
|
1492
1403
|
var _a = this, db = _a.db, tableName = _a.name;
|
|
1493
1404
|
this.schema.mappedClass = constructor;
|
|
1494
1405
|
if (constructor.prototype instanceof Entity) {
|
|
@@ -1506,20 +1417,6 @@
|
|
|
1506
1417
|
return class_1;
|
|
1507
1418
|
}(constructor));
|
|
1508
1419
|
}
|
|
1509
|
-
if (this.schema.yProps) {
|
|
1510
|
-
var Y_1 = getYLibrary(db);
|
|
1511
|
-
constructor = (function (_super) {
|
|
1512
|
-
__extends(class_2, _super);
|
|
1513
|
-
function class_2() {
|
|
1514
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1515
|
-
}
|
|
1516
|
-
return class_2;
|
|
1517
|
-
}(constructor));
|
|
1518
|
-
this.schema.yProps.forEach(function (_a) {
|
|
1519
|
-
var prop = _a.prop, updatesTable = _a.updatesTable;
|
|
1520
|
-
Object.defineProperty(constructor.prototype, prop, createYDocProperty(db, Y_1, _this, prop, updatesTable));
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1523
1420
|
var inheritedProps = new Set();
|
|
1524
1421
|
for (var proto = constructor.prototype; proto; proto = getProto(proto)) {
|
|
1525
1422
|
Object.getOwnPropertyNames(proto).forEach(function (propName) { return inheritedProps.add(propName); });
|
|
@@ -1601,14 +1498,12 @@
|
|
|
1601
1498
|
};
|
|
1602
1499
|
Table.prototype.delete = function (key) {
|
|
1603
1500
|
var _this = this;
|
|
1604
|
-
return this._trans('readwrite', function (trans) { return _this.core.mutate({ trans: trans, type: 'delete', keys: [key] })
|
|
1605
|
-
.then(function (res) { return
|
|
1606
|
-
.then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined; }); });
|
|
1501
|
+
return this._trans('readwrite', function (trans) { return _this.core.mutate({ trans: trans, type: 'delete', keys: [key] }); })
|
|
1502
|
+
.then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined; });
|
|
1607
1503
|
};
|
|
1608
1504
|
Table.prototype.clear = function () {
|
|
1609
1505
|
var _this = this;
|
|
1610
|
-
return this._trans('readwrite', function (trans) { return _this.core.mutate({ trans: trans, type: 'deleteRange', range: AnyRange })
|
|
1611
|
-
.then(function (res) { return builtInDeletionTrigger(_this, null, res); }); })
|
|
1506
|
+
return this._trans('readwrite', function (trans) { return _this.core.mutate({ trans: trans, type: 'deleteRange', range: AnyRange }); })
|
|
1612
1507
|
.then(function (res) { return res.numFailures ? DexiePromise.reject(res.failures[0]) : undefined; });
|
|
1613
1508
|
};
|
|
1614
1509
|
Table.prototype.bulkGet = function (keys) {
|
|
@@ -1735,8 +1630,7 @@
|
|
|
1735
1630
|
var _this = this;
|
|
1736
1631
|
var numKeys = keys.length;
|
|
1737
1632
|
return this._trans('readwrite', function (trans) {
|
|
1738
|
-
return _this.core.mutate({ trans: trans, type: 'delete', keys: keys })
|
|
1739
|
-
.then(function (res) { return builtInDeletionTrigger(_this, keys, res); });
|
|
1633
|
+
return _this.core.mutate({ trans: trans, type: 'delete', keys: keys });
|
|
1740
1634
|
}).then(function (_a) {
|
|
1741
1635
|
var numFailures = _a.numFailures, lastResult = _a.lastResult, failures = _a.failures;
|
|
1742
1636
|
if (numFailures === 0)
|
|
@@ -2028,7 +1922,7 @@
|
|
|
2028
1922
|
var order = this._ctx.dir === "next" ? 1 : -1;
|
|
2029
1923
|
function sorter(a, b) {
|
|
2030
1924
|
var aVal = getval(a, lastIndex), bVal = getval(b, lastIndex);
|
|
2031
|
-
return aVal
|
|
1925
|
+
return cmp(aVal, bVal) * order;
|
|
2032
1926
|
}
|
|
2033
1927
|
return this.toArray(function (a) {
|
|
2034
1928
|
return a.sort(sorter);
|
|
@@ -2260,48 +2154,45 @@
|
|
|
2260
2154
|
totalFailures.push(failures[pos]);
|
|
2261
2155
|
}
|
|
2262
2156
|
};
|
|
2263
|
-
var isUnconditionalDelete = changes === deleteCallback;
|
|
2264
2157
|
return _this.clone().primaryKeys().then(function (keys) {
|
|
2265
2158
|
var criteria = isPlainKeyRange(ctx) &&
|
|
2266
2159
|
ctx.limit === Infinity &&
|
|
2267
|
-
(typeof changes !== 'function' ||
|
|
2160
|
+
(typeof changes !== 'function' || changes === deleteCallback) && {
|
|
2268
2161
|
index: ctx.index,
|
|
2269
2162
|
range: ctx.range
|
|
2270
2163
|
};
|
|
2271
2164
|
var nextChunk = function (offset) {
|
|
2272
2165
|
var count = Math.min(limit, keys.length - offset);
|
|
2273
|
-
|
|
2274
|
-
return (isUnconditionalDelete ? Promise.resolve([]) : coreTable.getMany({
|
|
2166
|
+
return coreTable.getMany({
|
|
2275
2167
|
trans: trans,
|
|
2276
|
-
keys:
|
|
2168
|
+
keys: keys.slice(offset, offset + count),
|
|
2277
2169
|
cache: "immutable"
|
|
2278
|
-
})
|
|
2170
|
+
}).then(function (values) {
|
|
2279
2171
|
var addValues = [];
|
|
2280
2172
|
var putValues = [];
|
|
2281
2173
|
var putKeys = outbound ? [] : null;
|
|
2282
|
-
var deleteKeys =
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
if (
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
putKeys.push(keys[offset + i]);
|
|
2302
|
-
}
|
|
2174
|
+
var deleteKeys = [];
|
|
2175
|
+
for (var i = 0; i < count; ++i) {
|
|
2176
|
+
var origValue = values[i];
|
|
2177
|
+
var ctx_1 = {
|
|
2178
|
+
value: deepClone(origValue),
|
|
2179
|
+
primKey: keys[offset + i]
|
|
2180
|
+
};
|
|
2181
|
+
if (modifyer.call(ctx_1, ctx_1.value, ctx_1) !== false) {
|
|
2182
|
+
if (ctx_1.value == null) {
|
|
2183
|
+
deleteKeys.push(keys[offset + i]);
|
|
2184
|
+
}
|
|
2185
|
+
else if (!outbound && cmp(extractKey(origValue), extractKey(ctx_1.value)) !== 0) {
|
|
2186
|
+
deleteKeys.push(keys[offset + i]);
|
|
2187
|
+
addValues.push(ctx_1.value);
|
|
2188
|
+
}
|
|
2189
|
+
else {
|
|
2190
|
+
putValues.push(ctx_1.value);
|
|
2191
|
+
if (outbound)
|
|
2192
|
+
putKeys.push(keys[offset + i]);
|
|
2303
2193
|
}
|
|
2304
2194
|
}
|
|
2195
|
+
}
|
|
2305
2196
|
return Promise.resolve(addValues.length > 0 &&
|
|
2306
2197
|
coreTable.mutate({ trans: trans, type: 'add', values: addValues })
|
|
2307
2198
|
.then(function (res) {
|
|
@@ -2319,15 +2210,14 @@
|
|
|
2319
2210
|
changeSpec: typeof changes !== 'function'
|
|
2320
2211
|
&& changes,
|
|
2321
2212
|
isAdditionalChunk: offset > 0
|
|
2322
|
-
}).then(function (res) { return applyMutateResult(putValues.length, res); }); }).then(function () { return (deleteKeys.length > 0 || (criteria &&
|
|
2213
|
+
}).then(function (res) { return applyMutateResult(putValues.length, res); }); }).then(function () { return (deleteKeys.length > 0 || (criteria && changes === deleteCallback)) &&
|
|
2323
2214
|
coreTable.mutate({
|
|
2324
2215
|
trans: trans,
|
|
2325
2216
|
type: 'delete',
|
|
2326
2217
|
keys: deleteKeys,
|
|
2327
2218
|
criteria: criteria,
|
|
2328
2219
|
isAdditionalChunk: offset > 0
|
|
2329
|
-
}).then(function (res) { return
|
|
2330
|
-
.then(function (res) { return applyMutateResult(deleteKeys.length, res); }); }).then(function () {
|
|
2220
|
+
}).then(function (res) { return applyMutateResult(deleteKeys.length, res); }); }).then(function () {
|
|
2331
2221
|
return keys.length > offset + count && nextChunk(offset + limit);
|
|
2332
2222
|
});
|
|
2333
2223
|
});
|
|
@@ -2343,7 +2233,6 @@
|
|
|
2343
2233
|
Collection.prototype.delete = function () {
|
|
2344
2234
|
var ctx = this._ctx, range = ctx.range;
|
|
2345
2235
|
if (isPlainKeyRange(ctx) &&
|
|
2346
|
-
!ctx.table.schema.yProps &&
|
|
2347
2236
|
(ctx.isPrimKey || range.type === 3 ))
|
|
2348
2237
|
{
|
|
2349
2238
|
return this._write(function (trans) {
|
|
@@ -2352,7 +2241,7 @@
|
|
|
2352
2241
|
return ctx.table.core.count({ trans: trans, query: { index: primaryKey, range: coreRange } }).then(function (count) {
|
|
2353
2242
|
return ctx.table.core.mutate({ trans: trans, type: 'deleteRange', range: coreRange })
|
|
2354
2243
|
.then(function (_a) {
|
|
2355
|
-
var failures = _a.failures
|
|
2244
|
+
var failures = _a.failures; _a.lastResult; _a.results; var numFailures = _a.numFailures;
|
|
2356
2245
|
if (numFailures)
|
|
2357
2246
|
throw new ModifyError("Could not delete some values", Object.keys(failures).map(function (pos) { return failures[pos]; }), count - numFailures);
|
|
2358
2247
|
return count - numFailures;
|
|
@@ -2954,13 +2843,6 @@
|
|
|
2954
2843
|
function createTransactionConstructor(db) {
|
|
2955
2844
|
return makeClassConstructor(Transaction.prototype, function Transaction(mode, storeNames, dbschema, chromeTransactionDurability, parent) {
|
|
2956
2845
|
var _this = this;
|
|
2957
|
-
if (mode !== 'readonly')
|
|
2958
|
-
storeNames.forEach(function (storeName) {
|
|
2959
|
-
var _a;
|
|
2960
|
-
var yProps = (_a = dbschema[storeName]) === null || _a === void 0 ? void 0 : _a.yProps;
|
|
2961
|
-
if (yProps)
|
|
2962
|
-
storeNames = storeNames.concat(yProps.map(function (p) { return p.updatesTable; }));
|
|
2963
|
-
});
|
|
2964
2846
|
this.db = db;
|
|
2965
2847
|
this.mode = mode;
|
|
2966
2848
|
this.storeNames = storeNames;
|
|
@@ -2996,7 +2878,7 @@
|
|
|
2996
2878
|
});
|
|
2997
2879
|
}
|
|
2998
2880
|
|
|
2999
|
-
function createIndexSpec(name, keyPath, unique, multi, auto, compound, isPrimKey
|
|
2881
|
+
function createIndexSpec(name, keyPath, unique, multi, auto, compound, isPrimKey) {
|
|
3000
2882
|
return {
|
|
3001
2883
|
name: name,
|
|
3002
2884
|
keyPath: keyPath,
|
|
@@ -3004,8 +2886,7 @@
|
|
|
3004
2886
|
multi: multi,
|
|
3005
2887
|
auto: auto,
|
|
3006
2888
|
compound: compound,
|
|
3007
|
-
src: (unique && !isPrimKey ? '&' : '') + (multi ? '*' : '') + (auto ? "++" : "") + nameFromKeyPath(keyPath)
|
|
3008
|
-
type: type
|
|
2889
|
+
src: (unique && !isPrimKey ? '&' : '') + (multi ? '*' : '') + (auto ? "++" : "") + nameFromKeyPath(keyPath)
|
|
3009
2890
|
};
|
|
3010
2891
|
}
|
|
3011
2892
|
function nameFromKeyPath(keyPath) {
|
|
@@ -3014,17 +2895,13 @@
|
|
|
3014
2895
|
keyPath ? ('[' + [].join.call(keyPath, '+') + ']') : "";
|
|
3015
2896
|
}
|
|
3016
2897
|
|
|
3017
|
-
function createTableSchema(name, primKey, indexes
|
|
2898
|
+
function createTableSchema(name, primKey, indexes) {
|
|
3018
2899
|
return {
|
|
3019
2900
|
name: name,
|
|
3020
2901
|
primKey: primKey,
|
|
3021
2902
|
indexes: indexes,
|
|
3022
2903
|
mappedClass: null,
|
|
3023
|
-
|
|
3024
|
-
prop: prop,
|
|
3025
|
-
updatesTable: "$".concat(name, ".").concat(prop, "_updates"),
|
|
3026
|
-
}); }),
|
|
3027
|
-
idxByName: arrayToObject(indexes, function (index) { return [index.name, index]; }),
|
|
2904
|
+
idxByName: arrayToObject(indexes, function (index) { return [index.name, index]; })
|
|
3028
2905
|
};
|
|
3029
2906
|
}
|
|
3030
2907
|
|
|
@@ -3768,15 +3645,10 @@
|
|
|
3768
3645
|
}
|
|
3769
3646
|
function parseIndexSyntax(primKeyAndIndexes) {
|
|
3770
3647
|
return primKeyAndIndexes.split(',').map(function (index, indexNum) {
|
|
3771
|
-
|
|
3772
|
-
var typeSplit = index.split(':');
|
|
3773
|
-
var type = (_a = typeSplit[1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
3774
|
-
index = typeSplit[0].trim();
|
|
3775
|
-
if (type && type !== 'Y')
|
|
3776
|
-
throw new exceptions.Schema("Unsupported type '".concat(type, "'"));
|
|
3648
|
+
index = index.trim();
|
|
3777
3649
|
var name = index.replace(/([&*]|\+\+)/g, "");
|
|
3778
3650
|
var keyPath = /^\[/.test(name) ? name.match(/^\[(.*)\]$/)[1].split('+') : name;
|
|
3779
|
-
return createIndexSpec(name, keyPath || null, /\&/.test(index), /\*/.test(index), /\+\+/.test(index), isArray(keyPath), indexNum === 0
|
|
3651
|
+
return createIndexSpec(name, keyPath || null, /\&/.test(index), /\*/.test(index), /\+\+/.test(index), isArray(keyPath), indexNum === 0);
|
|
3780
3652
|
});
|
|
3781
3653
|
}
|
|
3782
3654
|
|
|
@@ -3784,57 +3656,40 @@
|
|
|
3784
3656
|
function Version() {
|
|
3785
3657
|
}
|
|
3786
3658
|
Version.prototype._parseStoresSpec = function (stores, outSchema) {
|
|
3787
|
-
var _this = this;
|
|
3788
3659
|
keys(stores).forEach(function (tableName) {
|
|
3789
|
-
var _a;
|
|
3790
3660
|
if (stores[tableName] !== null) {
|
|
3791
3661
|
var indexes = parseIndexSyntax(stores[tableName]);
|
|
3792
|
-
var yProps = indexes.filter(function (idx) { return idx.type === 'Y'; }).map(function (idx) { return idx.name; });
|
|
3793
|
-
indexes = indexes.filter(function (idx) { return idx.type !== 'Y'; });
|
|
3794
3662
|
var primKey = indexes.shift();
|
|
3795
|
-
if (!primKey) {
|
|
3796
|
-
throw new exceptions.Schema('Invalid schema for table ' + tableName + ': ' + stores[tableName]);
|
|
3797
|
-
}
|
|
3798
3663
|
primKey.unique = true;
|
|
3799
3664
|
if (primKey.multi)
|
|
3800
|
-
throw new exceptions.Schema(
|
|
3665
|
+
throw new exceptions.Schema("Primary key cannot be multi-valued");
|
|
3801
3666
|
indexes.forEach(function (idx) {
|
|
3802
3667
|
if (idx.auto)
|
|
3803
|
-
throw new exceptions.Schema(
|
|
3668
|
+
throw new exceptions.Schema("Only primary key can be marked as autoIncrement (++)");
|
|
3804
3669
|
if (!idx.keyPath)
|
|
3805
|
-
throw new exceptions.Schema(
|
|
3670
|
+
throw new exceptions.Schema("Index must have a name and cannot be an empty string");
|
|
3806
3671
|
});
|
|
3807
|
-
|
|
3808
|
-
outSchema[tableName] = tblSchema;
|
|
3809
|
-
for (var _i = 0, _b = tblSchema.yProps || []; _i < _b.length; _i++) {
|
|
3810
|
-
var yProp = _b[_i];
|
|
3811
|
-
_this._parseStoresSpec((_a = {}, _a[yProp.updatesTable] = '++i,k', _a), outSchema);
|
|
3812
|
-
}
|
|
3672
|
+
outSchema[tableName] = createTableSchema(tableName, primKey, indexes);
|
|
3813
3673
|
}
|
|
3814
3674
|
});
|
|
3815
3675
|
};
|
|
3816
3676
|
Version.prototype.stores = function (stores) {
|
|
3817
3677
|
var db = this.db;
|
|
3818
|
-
this._cfg.storesSource = this._cfg.storesSource
|
|
3819
|
-
|
|
3820
|
-
|
|
3678
|
+
this._cfg.storesSource = this._cfg.storesSource ?
|
|
3679
|
+
extend(this._cfg.storesSource, stores) :
|
|
3680
|
+
stores;
|
|
3821
3681
|
var versions = db._versions;
|
|
3822
3682
|
var storesSpec = {};
|
|
3823
3683
|
var dbschema = {};
|
|
3824
3684
|
versions.forEach(function (version) {
|
|
3825
3685
|
extend(storesSpec, version._cfg.storesSource);
|
|
3826
|
-
dbschema = version._cfg.dbschema = {};
|
|
3686
|
+
dbschema = (version._cfg.dbschema = {});
|
|
3827
3687
|
version._parseStoresSpec(storesSpec, dbschema);
|
|
3828
3688
|
});
|
|
3829
3689
|
db._dbSchema = dbschema;
|
|
3830
3690
|
removeTablesApi(db, [db._allTables, db, db.Transaction.prototype]);
|
|
3831
3691
|
setApiOnPlace(db, [db._allTables, db, db.Transaction.prototype, this._cfg.tables], keys(dbschema), dbschema);
|
|
3832
3692
|
db._storeNames = keys(dbschema);
|
|
3833
|
-
db._storeNames.forEach(function (tableName) {
|
|
3834
|
-
if (dbschema[tableName].yProps) {
|
|
3835
|
-
db.table(tableName).mapToClass(dbschema[tableName].mappedClass || Object);
|
|
3836
|
-
}
|
|
3837
|
-
});
|
|
3838
3693
|
return this;
|
|
3839
3694
|
};
|
|
3840
3695
|
Version.prototype.upgrade = function (upgradeFunction) {
|
|
@@ -4775,6 +4630,7 @@
|
|
|
4775
4630
|
var extractKey = primaryKey.extractKey, outbound = primaryKey.outbound;
|
|
4776
4631
|
var indexesWithAutoIncPK = primaryKey.autoIncrement && indexes.filter(function (index) { return index.compound && index.keyPath.includes(primaryKey.keyPath); });
|
|
4777
4632
|
var tableClone = __assign(__assign({}, table), { mutate: function (req) {
|
|
4633
|
+
var _a, _b;
|
|
4778
4634
|
var trans = req.trans;
|
|
4779
4635
|
var mutatedParts = req.mutatedParts || (req.mutatedParts = {});
|
|
4780
4636
|
var getRangeSet = function (indexName) {
|
|
@@ -4785,13 +4641,13 @@
|
|
|
4785
4641
|
var pkRangeSet = getRangeSet("");
|
|
4786
4642
|
var delsRangeSet = getRangeSet(":dels");
|
|
4787
4643
|
var type = req.type;
|
|
4788
|
-
var
|
|
4644
|
+
var _c = req.type === "deleteRange"
|
|
4789
4645
|
? [req.range]
|
|
4790
4646
|
: req.type === "delete"
|
|
4791
4647
|
? [req.keys]
|
|
4792
4648
|
: req.values.length < 50
|
|
4793
4649
|
? [getEffectiveKeys(primaryKey, req).filter(function (id) { return id; }), req.values]
|
|
4794
|
-
: [], keys =
|
|
4650
|
+
: [], keys = _c[0], newObjs = _c[1];
|
|
4795
4651
|
var oldCache = req.trans["_cache"];
|
|
4796
4652
|
if (isArray(keys)) {
|
|
4797
4653
|
pkRangeSet.addKeys(keys);
|
|
@@ -4804,7 +4660,10 @@
|
|
|
4804
4660
|
}
|
|
4805
4661
|
}
|
|
4806
4662
|
else if (keys) {
|
|
4807
|
-
var range = {
|
|
4663
|
+
var range = {
|
|
4664
|
+
from: (_a = keys.lower) !== null && _a !== void 0 ? _a : core.MIN_KEY,
|
|
4665
|
+
to: (_b = keys.upper) !== null && _b !== void 0 ? _b : core.MAX_KEY
|
|
4666
|
+
};
|
|
4808
4667
|
delsRangeSet.add(range);
|
|
4809
4668
|
pkRangeSet.add(range);
|
|
4810
4669
|
}
|
|
@@ -5028,12 +4887,27 @@
|
|
|
5028
4887
|
}
|
|
5029
4888
|
}
|
|
5030
4889
|
switch (op.type) {
|
|
5031
|
-
case 'add':
|
|
4890
|
+
case 'add': {
|
|
4891
|
+
var existingKeys_1 = new RangeSet().addKeys(req.values ? result.map(function (v) { return extractPrimKey(v); }) : result);
|
|
5032
4892
|
modifedResult = result.concat(req.values
|
|
5033
|
-
? includedValues
|
|
5034
|
-
|
|
4893
|
+
? includedValues.filter(function (v) {
|
|
4894
|
+
var key = extractPrimKey(v);
|
|
4895
|
+
if (existingKeys_1.hasKey(key))
|
|
4896
|
+
return false;
|
|
4897
|
+
existingKeys_1.addKey(key);
|
|
4898
|
+
return true;
|
|
4899
|
+
})
|
|
4900
|
+
: includedValues
|
|
4901
|
+
.map(function (v) { return extractPrimKey(v); })
|
|
4902
|
+
.filter(function (k) {
|
|
4903
|
+
if (existingKeys_1.hasKey(k))
|
|
4904
|
+
return false;
|
|
4905
|
+
existingKeys_1.addKey(k);
|
|
4906
|
+
return true;
|
|
4907
|
+
}));
|
|
5035
4908
|
break;
|
|
5036
|
-
|
|
4909
|
+
}
|
|
4910
|
+
case 'put': {
|
|
5037
4911
|
var keySet_1 = new RangeSet().addKeys(op.values.map(function (v) { return extractPrimKey(v); }));
|
|
5038
4912
|
modifedResult = result
|
|
5039
4913
|
.filter(
|
|
@@ -5043,9 +4917,12 @@
|
|
|
5043
4917
|
? includedValues
|
|
5044
4918
|
: includedValues.map(function (v) { return extractPrimKey(v); }));
|
|
5045
4919
|
break;
|
|
4920
|
+
}
|
|
5046
4921
|
case 'delete':
|
|
5047
4922
|
var keysToDelete_1 = new RangeSet().addKeys(op.keys);
|
|
5048
|
-
modifedResult = result.filter(function (item) {
|
|
4923
|
+
modifedResult = result.filter(function (item) {
|
|
4924
|
+
return !keysToDelete_1.hasKey(req.values ? extractPrimKey(item) : item);
|
|
4925
|
+
});
|
|
5049
4926
|
break;
|
|
5050
4927
|
case 'deleteRange':
|
|
5051
4928
|
var range_1 = op.range;
|
|
@@ -5259,7 +5136,8 @@
|
|
|
5259
5136
|
var trans = PSD.trans;
|
|
5260
5137
|
if (primKey.outbound ||
|
|
5261
5138
|
trans.db._options.cache === 'disabled' ||
|
|
5262
|
-
trans.explicit
|
|
5139
|
+
trans.explicit ||
|
|
5140
|
+
trans.idbtrans.mode !== 'readwrite'
|
|
5263
5141
|
) {
|
|
5264
5142
|
return downTable.mutate(req);
|
|
5265
5143
|
}
|
|
@@ -5271,6 +5149,8 @@
|
|
|
5271
5149
|
promise.then(function (res) {
|
|
5272
5150
|
var reqWithResolvedKeys = __assign(__assign({}, req), { values: req.values.map(function (value, i) {
|
|
5273
5151
|
var _a;
|
|
5152
|
+
if (res.failures[i])
|
|
5153
|
+
return value;
|
|
5274
5154
|
var valueWithKey = ((_a = primKey.keyPath) === null || _a === void 0 ? void 0 : _a.includes('.'))
|
|
5275
5155
|
? deepClone(value)
|
|
5276
5156
|
: __assign({}, value);
|
|
@@ -5381,140 +5261,6 @@
|
|
|
5381
5261
|
});
|
|
5382
5262
|
}
|
|
5383
5263
|
|
|
5384
|
-
function compressYDocs(db, interval) {
|
|
5385
|
-
var p = Promise.resolve();
|
|
5386
|
-
for (var _i = 0, _a = db.tables; _i < _a.length; _i++) {
|
|
5387
|
-
var table = _a[_i];
|
|
5388
|
-
var _loop_1 = function (yProp) {
|
|
5389
|
-
p = p.then(function () { return compressYDocsTable(db, yProp, interval); });
|
|
5390
|
-
};
|
|
5391
|
-
for (var _b = 0, _c = table.schema.yProps || []; _b < _c.length; _b++) {
|
|
5392
|
-
var yProp = _c[_b];
|
|
5393
|
-
_loop_1(yProp);
|
|
5394
|
-
}
|
|
5395
|
-
}
|
|
5396
|
-
return p;
|
|
5397
|
-
}
|
|
5398
|
-
function compressYDocsTable(db, _a, skipIfRunnedSince
|
|
5399
|
-
) {
|
|
5400
|
-
var updatesTable = _a.updatesTable;
|
|
5401
|
-
var updTbl = db.table(updatesTable);
|
|
5402
|
-
return Promise.all([
|
|
5403
|
-
updTbl
|
|
5404
|
-
.where('i')
|
|
5405
|
-
.startsWith('')
|
|
5406
|
-
.toArray(),
|
|
5407
|
-
db.transaction('rw', updatesTable, function () {
|
|
5408
|
-
return updTbl.get(0).then(function (lastCompressed) {
|
|
5409
|
-
if (lastCompressed &&
|
|
5410
|
-
skipIfRunnedSince &&
|
|
5411
|
-
lastCompressed.lastRun.getTime() > Date.now() - skipIfRunnedSince) {
|
|
5412
|
-
return null;
|
|
5413
|
-
}
|
|
5414
|
-
lastCompressed = lastCompressed || { i: 0, lastCompressed: 0 };
|
|
5415
|
-
return updTbl
|
|
5416
|
-
.put(__assign(__assign({}, lastCompressed), { lastRun: new Date() }))
|
|
5417
|
-
.then(function () { return lastCompressed; });
|
|
5418
|
-
});
|
|
5419
|
-
}),
|
|
5420
|
-
]).then(function (_a) {
|
|
5421
|
-
var syncers = _a[0], stamp = _a[1];
|
|
5422
|
-
if (!stamp)
|
|
5423
|
-
return;
|
|
5424
|
-
var lastCompressedUpdate = stamp.lastCompressed;
|
|
5425
|
-
var unsentFrom = Math.min.apply(Math, syncers.map(function (s) { return s.unsentFrom || Infinity; }));
|
|
5426
|
-
return updTbl
|
|
5427
|
-
.where('i')
|
|
5428
|
-
.between(lastCompressedUpdate, Infinity, false)
|
|
5429
|
-
.toArray(function (addedUpdates) {
|
|
5430
|
-
if (addedUpdates.length <= 1)
|
|
5431
|
-
return;
|
|
5432
|
-
var docsToCompress = [];
|
|
5433
|
-
var lastUpdateToCompress = lastCompressedUpdate + 1;
|
|
5434
|
-
var _loop_2 = function (j) {
|
|
5435
|
-
var updateRow = addedUpdates[j];
|
|
5436
|
-
var i = updateRow.i, f = updateRow.f, k = updateRow.k;
|
|
5437
|
-
if (i >= unsentFrom && (f & 0x01))
|
|
5438
|
-
return "break";
|
|
5439
|
-
var entry = docsToCompress.find(function (entry) { return cmp(entry.docId, k) === 0; });
|
|
5440
|
-
if (entry)
|
|
5441
|
-
entry.updates.push(updateRow);
|
|
5442
|
-
else
|
|
5443
|
-
docsToCompress.push({ docId: k, updates: [updateRow] });
|
|
5444
|
-
lastUpdateToCompress = i;
|
|
5445
|
-
};
|
|
5446
|
-
for (var j = 0; j < addedUpdates.length; ++j) {
|
|
5447
|
-
var state_1 = _loop_2(j);
|
|
5448
|
-
if (state_1 === "break")
|
|
5449
|
-
break;
|
|
5450
|
-
}
|
|
5451
|
-
var p = Promise.resolve();
|
|
5452
|
-
var _loop_3 = function (docId, updates) {
|
|
5453
|
-
p = p.then(function () { return compressUpdatesForDoc(db, updatesTable, docId, updates); });
|
|
5454
|
-
};
|
|
5455
|
-
for (var _i = 0, docsToCompress_1 = docsToCompress; _i < docsToCompress_1.length; _i++) {
|
|
5456
|
-
var _a = docsToCompress_1[_i], docId = _a.docId, updates = _a.updates;
|
|
5457
|
-
_loop_3(docId, updates);
|
|
5458
|
-
}
|
|
5459
|
-
return p.then(function () {
|
|
5460
|
-
return db.transaction('rw', updTbl, function () {
|
|
5461
|
-
return updTbl.get(0).then(function (current) {
|
|
5462
|
-
return updTbl.put(__assign(__assign({}, current), { lastCompressed: Math.max(lastUpdateToCompress, (current === null || current === void 0 ? void 0 : current.lastCompressed) || 0) }));
|
|
5463
|
-
});
|
|
5464
|
-
});
|
|
5465
|
-
});
|
|
5466
|
-
});
|
|
5467
|
-
});
|
|
5468
|
-
}
|
|
5469
|
-
function compressUpdatesForDoc(db, updatesTable, parentId, addedUpdatesToCompress) {
|
|
5470
|
-
if (addedUpdatesToCompress.length < 1)
|
|
5471
|
-
throw new Error('Invalid input');
|
|
5472
|
-
return db.transaction('rw', updatesTable, function (tx) {
|
|
5473
|
-
var updTbl = tx.table(updatesTable);
|
|
5474
|
-
return updTbl.where({ k: parentId }).first(function (mainUpdate) {
|
|
5475
|
-
var updates = [mainUpdate].concat(addedUpdatesToCompress);
|
|
5476
|
-
var Y = getYLibrary(db);
|
|
5477
|
-
var doc = new Y.Doc({ gc: true });
|
|
5478
|
-
updates.forEach(function (update) {
|
|
5479
|
-
Y.applyUpdateV2(doc, update.u);
|
|
5480
|
-
});
|
|
5481
|
-
var compressedUpdate = Y.encodeStateAsUpdateV2(doc);
|
|
5482
|
-
var lastUpdate = updates.pop();
|
|
5483
|
-
return updTbl
|
|
5484
|
-
.put({
|
|
5485
|
-
i: lastUpdate.i,
|
|
5486
|
-
k: parentId,
|
|
5487
|
-
u: compressedUpdate,
|
|
5488
|
-
})
|
|
5489
|
-
.then(function () { return updTbl.bulkDelete(updates.map(function (update) { return update.i; })); });
|
|
5490
|
-
});
|
|
5491
|
-
});
|
|
5492
|
-
}
|
|
5493
|
-
|
|
5494
|
-
var INTERVAL = 10000;
|
|
5495
|
-
function periodicGC(db) {
|
|
5496
|
-
var timer = null;
|
|
5497
|
-
db.on('ready', function (db) {
|
|
5498
|
-
if (db.tables.some(function (tbl) { return tbl.schema.yProps; })) {
|
|
5499
|
-
var gc_1 = function () {
|
|
5500
|
-
if (!db.isOpen())
|
|
5501
|
-
return;
|
|
5502
|
-
compressYDocs(db, INTERVAL).catch(function (err) {
|
|
5503
|
-
console.debug('Error during periodic GC', err);
|
|
5504
|
-
}).then(function () {
|
|
5505
|
-
timer = setTimeout(gc_1, INTERVAL);
|
|
5506
|
-
});
|
|
5507
|
-
};
|
|
5508
|
-
timer = setTimeout(gc_1, INTERVAL);
|
|
5509
|
-
}
|
|
5510
|
-
}, true);
|
|
5511
|
-
db.on('close', function () {
|
|
5512
|
-
if (timer)
|
|
5513
|
-
clearTimeout(timer);
|
|
5514
|
-
timer = null;
|
|
5515
|
-
});
|
|
5516
|
-
}
|
|
5517
|
-
|
|
5518
5264
|
var Dexie$1 = (function () {
|
|
5519
5265
|
function Dexie(name, options) {
|
|
5520
5266
|
var _this = this;
|
|
@@ -5556,18 +5302,7 @@
|
|
|
5556
5302
|
});
|
|
5557
5303
|
this._state = state;
|
|
5558
5304
|
this.name = name;
|
|
5559
|
-
this.on = Events(this, "populate", "blocked", "versionchange", "close",
|
|
5560
|
-
this.once = function (event, callback) {
|
|
5561
|
-
var fn = function () {
|
|
5562
|
-
var args = [];
|
|
5563
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
5564
|
-
args[_i] = arguments[_i];
|
|
5565
|
-
}
|
|
5566
|
-
_this.on(event).unsubscribe(fn);
|
|
5567
|
-
callback.apply(_this, args);
|
|
5568
|
-
};
|
|
5569
|
-
return _this.on(event, fn);
|
|
5570
|
-
};
|
|
5305
|
+
this.on = Events(this, "populate", "blocked", "versionchange", "close", { ready: [promisableChain, nop] });
|
|
5571
5306
|
this.on.ready.subscribe = override(this.on.ready.subscribe, function (subscribe) {
|
|
5572
5307
|
return function (subscriber, bSticky) {
|
|
5573
5308
|
Dexie.vip(function () {
|
|
@@ -5646,8 +5381,6 @@
|
|
|
5646
5381
|
}
|
|
5647
5382
|
});
|
|
5648
5383
|
this.vip = vipDB;
|
|
5649
|
-
if (options === null || options === void 0 ? void 0 : options.Y)
|
|
5650
|
-
periodicGC(this);
|
|
5651
5384
|
addons.forEach(function (addon) { return addon(_this); });
|
|
5652
5385
|
}
|
|
5653
5386
|
Dexie.prototype.version = function (versionNumber) {
|
|
@@ -5710,7 +5443,6 @@
|
|
|
5710
5443
|
function () { return dexieOpen(_this); });
|
|
5711
5444
|
};
|
|
5712
5445
|
Dexie.prototype._close = function () {
|
|
5713
|
-
this.on.close.fire(new CustomEvent('close'));
|
|
5714
5446
|
var state = this._state;
|
|
5715
5447
|
var idx = connections.indexOf(this);
|
|
5716
5448
|
if (idx >= 0)
|
|
@@ -5868,9 +5600,6 @@
|
|
|
5868
5600
|
}
|
|
5869
5601
|
return this._allTables[tableName];
|
|
5870
5602
|
};
|
|
5871
|
-
Dexie.prototype.gc = function () {
|
|
5872
|
-
return compressYDocs(this);
|
|
5873
|
-
};
|
|
5874
5603
|
return Dexie;
|
|
5875
5604
|
}());
|
|
5876
5605
|
|
|
@@ -6171,116 +5900,6 @@
|
|
|
6171
5900
|
return new PropModification({ replacePrefix: [a, b] });
|
|
6172
5901
|
}
|
|
6173
5902
|
|
|
6174
|
-
function observeYDocUpdates(provider, doc, db, parentTableName, updatesTableName, parentId, Y) {
|
|
6175
|
-
var lastUpdateId = 0;
|
|
6176
|
-
var initial = true;
|
|
6177
|
-
var subscription = liveQuery(function () {
|
|
6178
|
-
throwIfDestroyed(doc);
|
|
6179
|
-
var updatesTable = db.table(updatesTableName);
|
|
6180
|
-
return Promise.all([
|
|
6181
|
-
(lastUpdateId > 0
|
|
6182
|
-
? updatesTable
|
|
6183
|
-
.where('i')
|
|
6184
|
-
.between(lastUpdateId, Infinity, false)
|
|
6185
|
-
.toArray()
|
|
6186
|
-
.then(function (updates) {
|
|
6187
|
-
return updates.filter(function (update) { return cmp(update.k, parentId) === 0; });
|
|
6188
|
-
})
|
|
6189
|
-
: updatesTable.where({ k: parentId }).toArray()).then(function (updates) {
|
|
6190
|
-
if (updates.length > 0)
|
|
6191
|
-
lastUpdateId = updates[updates.length - 1].i;
|
|
6192
|
-
return updates;
|
|
6193
|
-
}),
|
|
6194
|
-
db.table(parentTableName).where(':id').equals(parentId).toArray(),
|
|
6195
|
-
]);
|
|
6196
|
-
}).subscribe(function (_a) {
|
|
6197
|
-
var updates = _a[0], parentRow = _a[1];
|
|
6198
|
-
if (parentRow.length === 0) {
|
|
6199
|
-
doc.destroy();
|
|
6200
|
-
return;
|
|
6201
|
-
}
|
|
6202
|
-
throwIfDestroyed(doc);
|
|
6203
|
-
if (updates.length > 0) {
|
|
6204
|
-
Y.transact(doc, function () {
|
|
6205
|
-
updates.forEach(function (update) {
|
|
6206
|
-
Y.applyUpdateV2(doc, update.u);
|
|
6207
|
-
});
|
|
6208
|
-
}, provider, false);
|
|
6209
|
-
}
|
|
6210
|
-
if (initial) {
|
|
6211
|
-
initial = false;
|
|
6212
|
-
provider.on('load').fire(provider);
|
|
6213
|
-
doc.emit('load', [doc]);
|
|
6214
|
-
}
|
|
6215
|
-
}, function (error) {
|
|
6216
|
-
provider.on('error').fire(error);
|
|
6217
|
-
});
|
|
6218
|
-
var onUpdate = function (update, origin) {
|
|
6219
|
-
if (origin === provider)
|
|
6220
|
-
return;
|
|
6221
|
-
db.table(updatesTableName)
|
|
6222
|
-
.add({
|
|
6223
|
-
k: parentId,
|
|
6224
|
-
u: update,
|
|
6225
|
-
f: 1,
|
|
6226
|
-
})
|
|
6227
|
-
.then(function (i) {
|
|
6228
|
-
if (i === lastUpdateId - 1)
|
|
6229
|
-
++lastUpdateId;
|
|
6230
|
-
})
|
|
6231
|
-
.catch(function (error) {
|
|
6232
|
-
provider.on('error').fire(error);
|
|
6233
|
-
});
|
|
6234
|
-
};
|
|
6235
|
-
var stopObserving = function () {
|
|
6236
|
-
subscription.unsubscribe();
|
|
6237
|
-
doc.off('updateV2', onUpdate);
|
|
6238
|
-
doc.off('destroy', stopObserving);
|
|
6239
|
-
};
|
|
6240
|
-
doc.on('updateV2', onUpdate);
|
|
6241
|
-
doc.on('destroy', stopObserving);
|
|
6242
|
-
return stopObserving;
|
|
6243
|
-
}
|
|
6244
|
-
|
|
6245
|
-
function DexieYProvider(doc) {
|
|
6246
|
-
var _a = (doc || {}).meta, db = _a.db, parentTable = _a.parentTable, parentId = _a.parentId, updatesTable = _a.updatesTable;
|
|
6247
|
-
if (!db || !parentTable || !updatesTable)
|
|
6248
|
-
throw new Error('Y.Doc not generated by Dexie');
|
|
6249
|
-
if (!db.table(parentTable) || !db.table(updatesTable)) {
|
|
6250
|
-
throw new Error("Table ".concat(parentTable, " or ").concat(updatesTable, " not found in db"));
|
|
6251
|
-
}
|
|
6252
|
-
throwIfDestroyed(doc);
|
|
6253
|
-
var Y = getYLibrary(db);
|
|
6254
|
-
function createEvents() {
|
|
6255
|
-
return Events(null, "load", "sync", "error");
|
|
6256
|
-
}
|
|
6257
|
-
var on = createEvents();
|
|
6258
|
-
var provider = {
|
|
6259
|
-
destroyed: false,
|
|
6260
|
-
doc: doc,
|
|
6261
|
-
on: on,
|
|
6262
|
-
off: function (name, f) { var _a; (_a = on[name]) === null || _a === void 0 ? void 0 : _a.unsubscribe(f); },
|
|
6263
|
-
whenLoaded: new Promise(function (resolve, reject) {
|
|
6264
|
-
on('load', resolve);
|
|
6265
|
-
on('error', reject);
|
|
6266
|
-
}),
|
|
6267
|
-
whenSynced: new Promise(function (resolve, reject) {
|
|
6268
|
-
on('sync', resolve);
|
|
6269
|
-
on('error', reject);
|
|
6270
|
-
}),
|
|
6271
|
-
destroy: function () {
|
|
6272
|
-
this.destroyed = true;
|
|
6273
|
-
stopObserving();
|
|
6274
|
-
on = this.on = createEvents();
|
|
6275
|
-
}
|
|
6276
|
-
};
|
|
6277
|
-
var stopObserving = observeYDocUpdates(provider, doc, db, parentTable, updatesTable, parentId, Y);
|
|
6278
|
-
doc.on('destroy', provider.destroy.bind(provider));
|
|
6279
|
-
db.on.y.fire(provider, Y);
|
|
6280
|
-
return provider;
|
|
6281
|
-
}
|
|
6282
|
-
DexieYProvider.getDocCache = getDocCache;
|
|
6283
|
-
|
|
6284
5903
|
DexiePromise.rejectionMapper = mapError;
|
|
6285
5904
|
setDebug(debug);
|
|
6286
5905
|
|
|
@@ -6298,8 +5917,7 @@
|
|
|
6298
5917
|
'default': Dexie$1,
|
|
6299
5918
|
RangeSet: RangeSet,
|
|
6300
5919
|
mergeRanges: mergeRanges,
|
|
6301
|
-
rangesOverlap: rangesOverlap
|
|
6302
|
-
DexieYProvider: DexieYProvider
|
|
5920
|
+
rangesOverlap: rangesOverlap
|
|
6303
5921
|
});
|
|
6304
5922
|
|
|
6305
5923
|
__assign(Dexie$1, namedExports, { default: Dexie$1 });
|