dexie-cloud-addon 4.1.0-beta.39 → 4.1.0-beta.40
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/modern/dexie-cloud-addon.d.ts +0 -1
- package/dist/modern/dexie-cloud-addon.js +159 -159
- package/dist/modern/dexie-cloud-addon.js.map +1 -1
- package/dist/modern/dexie-cloud-addon.min.js +1 -1
- package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
- package/dist/modern/dexie-cloud-client.d.ts +1 -0
- package/dist/modern/service-worker.js +3 -3
- package/dist/modern/service-worker.js.map +1 -1
- package/dist/modern/service-worker.min.js +1 -1
- package/dist/modern/service-worker.min.js.map +1 -1
- package/dist/umd/dexie-cloud-addon.d.ts +0 -1
- package/dist/umd/dexie-cloud-addon.js +159 -159
- package/dist/umd/dexie-cloud-addon.js.map +1 -1
- package/dist/umd/dexie-cloud-addon.min.js +1 -1
- package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
- package/dist/umd/dexie-cloud-client.d.ts +1 -0
- package/dist/umd/service-worker.js +3 -3
- package/dist/umd/service-worker.js.map +1 -1
- package/dist/umd/service-worker.min.js +1 -1
- package/dist/umd/service-worker.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* ==========================================================================
|
|
10
10
|
*
|
|
11
|
-
* Version 4.1.0-beta.
|
|
11
|
+
* Version 4.1.0-beta.40, Mon Jan 20 2025
|
|
12
12
|
*
|
|
13
13
|
* https://dexie.org
|
|
14
14
|
*
|
|
@@ -8125,6 +8125,162 @@ function getTiedObjectId(realmId) {
|
|
|
8125
8125
|
return realmId.startsWith('rlm~') ? realmId.substr(4) : null;
|
|
8126
8126
|
}
|
|
8127
8127
|
|
|
8128
|
+
const ydocTriggers = {};
|
|
8129
|
+
const docIsAlreadyHooked = new WeakSet();
|
|
8130
|
+
const middlewares = new WeakMap();
|
|
8131
|
+
const createMiddleware = (db) => ({
|
|
8132
|
+
stack: 'dbcore',
|
|
8133
|
+
level: 10,
|
|
8134
|
+
name: 'yTriggerMiddleware',
|
|
8135
|
+
create: (down) => {
|
|
8136
|
+
return Object.assign(Object.assign({}, down), { transaction: (stores, mode, options) => {
|
|
8137
|
+
const idbtrans = down.transaction(stores, mode, options);
|
|
8138
|
+
idbtrans.addEventListener('complete', onTransactionCommitted);
|
|
8139
|
+
return idbtrans;
|
|
8140
|
+
}, table: (tblName) => {
|
|
8141
|
+
const coreTable = down.table(tblName);
|
|
8142
|
+
const triggerSpec = ydocTriggers[tblName];
|
|
8143
|
+
if (!triggerSpec)
|
|
8144
|
+
return coreTable;
|
|
8145
|
+
const { trigger, parentTable, prop } = triggerSpec;
|
|
8146
|
+
return Object.assign(Object.assign({}, coreTable), { mutate(req) {
|
|
8147
|
+
switch (req.type) {
|
|
8148
|
+
case 'add': {
|
|
8149
|
+
for (const yUpdateRow of req.values) {
|
|
8150
|
+
if (yUpdateRow.k == undefined)
|
|
8151
|
+
continue; // A syncer or garbage collection state does not point to a key
|
|
8152
|
+
const primaryKey = yUpdateRow.k;
|
|
8153
|
+
const doc = DexieYProvider.getDocCache(db).find(parentTable, primaryKey, prop);
|
|
8154
|
+
if (doc) {
|
|
8155
|
+
if (!docIsAlreadyHooked.has(doc)) {
|
|
8156
|
+
hookToDoc(doc, primaryKey, trigger);
|
|
8157
|
+
docIsAlreadyHooked.add(doc);
|
|
8158
|
+
}
|
|
8159
|
+
}
|
|
8160
|
+
else {
|
|
8161
|
+
enqueueTrigger(db, tblName, primaryKey, trigger);
|
|
8162
|
+
}
|
|
8163
|
+
}
|
|
8164
|
+
break;
|
|
8165
|
+
}
|
|
8166
|
+
case 'delete':
|
|
8167
|
+
// @ts-ignore
|
|
8168
|
+
if (req.trans._rejecting_y_ypdate) {
|
|
8169
|
+
// The deletion came from a rejection, not garbage collection.
|
|
8170
|
+
// When that happens, let the triggers run to compute new values
|
|
8171
|
+
// based on the deleted updates.
|
|
8172
|
+
coreTable
|
|
8173
|
+
.getMany({
|
|
8174
|
+
keys: req.keys,
|
|
8175
|
+
trans: req.trans,
|
|
8176
|
+
cache: 'immutable',
|
|
8177
|
+
})
|
|
8178
|
+
.then((updates) => {
|
|
8179
|
+
const keySet = new RangeSet();
|
|
8180
|
+
for (const { k } of updates) {
|
|
8181
|
+
if (k != undefined)
|
|
8182
|
+
keySet.addKey(k);
|
|
8183
|
+
}
|
|
8184
|
+
for (const interval of keySet) {
|
|
8185
|
+
enqueueTrigger(db, tblName, interval.from, trigger);
|
|
8186
|
+
}
|
|
8187
|
+
});
|
|
8188
|
+
}
|
|
8189
|
+
break;
|
|
8190
|
+
}
|
|
8191
|
+
return coreTable.mutate(req);
|
|
8192
|
+
} });
|
|
8193
|
+
} });
|
|
8194
|
+
},
|
|
8195
|
+
});
|
|
8196
|
+
let triggerExecPromise = null;
|
|
8197
|
+
let triggerScheduled = false;
|
|
8198
|
+
let scheduledTriggers = [];
|
|
8199
|
+
function $Y(db) {
|
|
8200
|
+
const $Y = db._options.Y;
|
|
8201
|
+
if (!$Y)
|
|
8202
|
+
throw new Error('Y library not supplied to Dexie constructor');
|
|
8203
|
+
return $Y;
|
|
8204
|
+
}
|
|
8205
|
+
function executeTriggers(triggersToRun) {
|
|
8206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
8207
|
+
for (const { db, parentId, trigger, updatesTable } of triggersToRun) {
|
|
8208
|
+
// Load entire document into an Y.Doc instance:
|
|
8209
|
+
const updates = yield db
|
|
8210
|
+
.table(updatesTable)
|
|
8211
|
+
.where({ k: parentId })
|
|
8212
|
+
.toArray();
|
|
8213
|
+
const Y = $Y(db);
|
|
8214
|
+
const yDoc = new Y.Doc();
|
|
8215
|
+
for (const update of updates) {
|
|
8216
|
+
Y.applyUpdateV2(yDoc, update.u);
|
|
8217
|
+
}
|
|
8218
|
+
try {
|
|
8219
|
+
yield trigger(yDoc, parentId);
|
|
8220
|
+
}
|
|
8221
|
+
catch (error) {
|
|
8222
|
+
console.error(`Error in YDocTrigger ${error}`);
|
|
8223
|
+
}
|
|
8224
|
+
}
|
|
8225
|
+
});
|
|
8226
|
+
}
|
|
8227
|
+
function enqueueTrigger(db, updatesTable, parentId, trigger) {
|
|
8228
|
+
scheduledTriggers.push({
|
|
8229
|
+
db,
|
|
8230
|
+
updatesTable,
|
|
8231
|
+
parentId,
|
|
8232
|
+
trigger,
|
|
8233
|
+
});
|
|
8234
|
+
}
|
|
8235
|
+
function onTransactionCommitted() {
|
|
8236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
8237
|
+
if (!triggerScheduled && scheduledTriggers.length > 0) {
|
|
8238
|
+
triggerScheduled = true;
|
|
8239
|
+
if (triggerExecPromise)
|
|
8240
|
+
yield triggerExecPromise.catch(() => { });
|
|
8241
|
+
setTimeout(() => {
|
|
8242
|
+
// setTimeout() is to escape from Promise.PSD zones and never run within liveQueries or transaction scopes
|
|
8243
|
+
triggerScheduled = false;
|
|
8244
|
+
const triggersToRun = scheduledTriggers;
|
|
8245
|
+
scheduledTriggers = [];
|
|
8246
|
+
triggerExecPromise = executeTriggers(triggersToRun).finally(() => (triggerExecPromise = null));
|
|
8247
|
+
}, 0);
|
|
8248
|
+
}
|
|
8249
|
+
});
|
|
8250
|
+
}
|
|
8251
|
+
function hookToDoc(doc, parentId, trigger) {
|
|
8252
|
+
// From now on, keep listening to doc updates and execute the trigger when it happens there instead
|
|
8253
|
+
doc.on('updateV2', (update, origin) => {
|
|
8254
|
+
//Dexie.ignoreTransaction(()=>{
|
|
8255
|
+
trigger(doc, parentId);
|
|
8256
|
+
//});
|
|
8257
|
+
});
|
|
8258
|
+
/*
|
|
8259
|
+
NOT NEEDED because DexieYProvider's docCache will also listen to destroy and remove it from its cache:
|
|
8260
|
+
doc.on('destroy', ()=>{
|
|
8261
|
+
docIsAlreadyHooked.delete(doc);
|
|
8262
|
+
})
|
|
8263
|
+
*/
|
|
8264
|
+
}
|
|
8265
|
+
function defineYDocTrigger(table, prop, trigger) {
|
|
8266
|
+
var _a, _b;
|
|
8267
|
+
const updatesTable = (_b = (_a = table.schema.yProps) === null || _a === void 0 ? void 0 : _a.find((p) => p.prop === prop)) === null || _b === void 0 ? void 0 : _b.updatesTable;
|
|
8268
|
+
if (!updatesTable)
|
|
8269
|
+
throw new Error(`Table ${table.name} does not have a Yjs property named ${prop}`);
|
|
8270
|
+
ydocTriggers[updatesTable] = {
|
|
8271
|
+
trigger,
|
|
8272
|
+
parentTable: table.name,
|
|
8273
|
+
prop,
|
|
8274
|
+
};
|
|
8275
|
+
const db = table.db._novip;
|
|
8276
|
+
let mw = middlewares.get(db);
|
|
8277
|
+
if (!mw) {
|
|
8278
|
+
mw = createMiddleware(db);
|
|
8279
|
+
middlewares.set(db, mw);
|
|
8280
|
+
}
|
|
8281
|
+
db.use(mw);
|
|
8282
|
+
}
|
|
8283
|
+
|
|
8128
8284
|
const DEFAULT_OPTIONS = {
|
|
8129
8285
|
nameSuffix: true,
|
|
8130
8286
|
};
|
|
@@ -8165,7 +8321,7 @@ function dexieCloud(dexie) {
|
|
|
8165
8321
|
const syncComplete = new Subject();
|
|
8166
8322
|
dexie.cloud = {
|
|
8167
8323
|
// @ts-ignore
|
|
8168
|
-
version: "4.1.0-beta.
|
|
8324
|
+
version: "4.1.0-beta.40",
|
|
8169
8325
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
8170
8326
|
schema: null,
|
|
8171
8327
|
get currentUserId() {
|
|
@@ -8483,164 +8639,8 @@ function dexieCloud(dexie) {
|
|
|
8483
8639
|
}
|
|
8484
8640
|
}
|
|
8485
8641
|
// @ts-ignore
|
|
8486
|
-
dexieCloud.version = "4.1.0-beta.
|
|
8642
|
+
dexieCloud.version = "4.1.0-beta.40";
|
|
8487
8643
|
Dexie.Cloud = dexieCloud;
|
|
8488
8644
|
|
|
8489
|
-
const ydocTriggers = {};
|
|
8490
|
-
const docIsAlreadyHooked = new WeakSet();
|
|
8491
|
-
const middlewares = new WeakMap();
|
|
8492
|
-
const createMiddleware = (db) => ({
|
|
8493
|
-
stack: 'dbcore',
|
|
8494
|
-
level: 10,
|
|
8495
|
-
name: 'yTriggerMiddleware',
|
|
8496
|
-
create: (down) => {
|
|
8497
|
-
return Object.assign(Object.assign({}, down), { transaction: (stores, mode, options) => {
|
|
8498
|
-
const idbtrans = down.transaction(stores, mode, options);
|
|
8499
|
-
idbtrans.addEventListener('complete', onTransactionCommitted);
|
|
8500
|
-
return idbtrans;
|
|
8501
|
-
}, table: (tblName) => {
|
|
8502
|
-
const coreTable = down.table(tblName);
|
|
8503
|
-
const triggerSpec = ydocTriggers[tblName];
|
|
8504
|
-
if (!triggerSpec)
|
|
8505
|
-
return coreTable;
|
|
8506
|
-
const { trigger, parentTable, prop } = triggerSpec;
|
|
8507
|
-
return Object.assign(Object.assign({}, coreTable), { mutate(req) {
|
|
8508
|
-
switch (req.type) {
|
|
8509
|
-
case 'add': {
|
|
8510
|
-
for (const yUpdateRow of req.values) {
|
|
8511
|
-
if (yUpdateRow.k == undefined)
|
|
8512
|
-
continue; // A syncer or garbage collection state does not point to a key
|
|
8513
|
-
const primaryKey = yUpdateRow.k;
|
|
8514
|
-
const doc = DexieYProvider.getDocCache(db).find(parentTable, primaryKey, prop);
|
|
8515
|
-
if (doc) {
|
|
8516
|
-
if (!docIsAlreadyHooked.has(doc)) {
|
|
8517
|
-
hookToDoc(doc, primaryKey, trigger);
|
|
8518
|
-
docIsAlreadyHooked.add(doc);
|
|
8519
|
-
}
|
|
8520
|
-
}
|
|
8521
|
-
else {
|
|
8522
|
-
enqueueTrigger(db, tblName, primaryKey, trigger);
|
|
8523
|
-
}
|
|
8524
|
-
}
|
|
8525
|
-
break;
|
|
8526
|
-
}
|
|
8527
|
-
case 'delete':
|
|
8528
|
-
// @ts-ignore
|
|
8529
|
-
if (req.trans._rejecting_y_ypdate) {
|
|
8530
|
-
// The deletion came from a rejection, not garbage collection.
|
|
8531
|
-
// When that happens, let the triggers run to compute new values
|
|
8532
|
-
// based on the deleted updates.
|
|
8533
|
-
coreTable
|
|
8534
|
-
.getMany({
|
|
8535
|
-
keys: req.keys,
|
|
8536
|
-
trans: req.trans,
|
|
8537
|
-
cache: 'immutable',
|
|
8538
|
-
})
|
|
8539
|
-
.then((updates) => {
|
|
8540
|
-
const keySet = new RangeSet();
|
|
8541
|
-
for (const { k } of updates) {
|
|
8542
|
-
if (k != undefined)
|
|
8543
|
-
keySet.addKey(k);
|
|
8544
|
-
}
|
|
8545
|
-
for (const interval of keySet) {
|
|
8546
|
-
enqueueTrigger(db, tblName, interval.from, trigger);
|
|
8547
|
-
}
|
|
8548
|
-
});
|
|
8549
|
-
}
|
|
8550
|
-
break;
|
|
8551
|
-
}
|
|
8552
|
-
return coreTable.mutate(req);
|
|
8553
|
-
} });
|
|
8554
|
-
} });
|
|
8555
|
-
},
|
|
8556
|
-
});
|
|
8557
|
-
let triggerExecPromise = null;
|
|
8558
|
-
let triggerScheduled = false;
|
|
8559
|
-
let scheduledTriggers = [];
|
|
8560
|
-
function $Y(db) {
|
|
8561
|
-
const $Y = db._options.Y;
|
|
8562
|
-
if (!$Y)
|
|
8563
|
-
throw new Error('Y library not supplied to Dexie constructor');
|
|
8564
|
-
return $Y;
|
|
8565
|
-
}
|
|
8566
|
-
function executeTriggers(triggersToRun) {
|
|
8567
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
8568
|
-
for (const { db, parentId, trigger, updatesTable } of triggersToRun) {
|
|
8569
|
-
// Load entire document into an Y.Doc instance:
|
|
8570
|
-
const updates = yield db
|
|
8571
|
-
.table(updatesTable)
|
|
8572
|
-
.where({ k: parentId })
|
|
8573
|
-
.toArray();
|
|
8574
|
-
const Y = $Y(db);
|
|
8575
|
-
const yDoc = new Y.Doc();
|
|
8576
|
-
for (const update of updates) {
|
|
8577
|
-
Y.applyUpdateV2(yDoc, update.u);
|
|
8578
|
-
}
|
|
8579
|
-
try {
|
|
8580
|
-
yield trigger(yDoc, parentId);
|
|
8581
|
-
}
|
|
8582
|
-
catch (error) {
|
|
8583
|
-
console.error(`Error in YDocTrigger ${error}`);
|
|
8584
|
-
}
|
|
8585
|
-
}
|
|
8586
|
-
});
|
|
8587
|
-
}
|
|
8588
|
-
function enqueueTrigger(db, updatesTable, parentId, trigger) {
|
|
8589
|
-
scheduledTriggers.push({
|
|
8590
|
-
db,
|
|
8591
|
-
updatesTable,
|
|
8592
|
-
parentId,
|
|
8593
|
-
trigger,
|
|
8594
|
-
});
|
|
8595
|
-
}
|
|
8596
|
-
function onTransactionCommitted() {
|
|
8597
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
8598
|
-
if (!triggerScheduled && scheduledTriggers.length > 0) {
|
|
8599
|
-
triggerScheduled = true;
|
|
8600
|
-
if (triggerExecPromise)
|
|
8601
|
-
yield triggerExecPromise.catch(() => { });
|
|
8602
|
-
setTimeout(() => {
|
|
8603
|
-
// setTimeout() is to escape from Promise.PSD zones and never run within liveQueries or transaction scopes
|
|
8604
|
-
triggerScheduled = false;
|
|
8605
|
-
const triggersToRun = scheduledTriggers;
|
|
8606
|
-
scheduledTriggers = [];
|
|
8607
|
-
triggerExecPromise = executeTriggers(triggersToRun).finally(() => (triggerExecPromise = null));
|
|
8608
|
-
}, 0);
|
|
8609
|
-
}
|
|
8610
|
-
});
|
|
8611
|
-
}
|
|
8612
|
-
function hookToDoc(doc, parentId, trigger) {
|
|
8613
|
-
// From now on, keep listening to doc updates and execute the trigger when it happens there instead
|
|
8614
|
-
doc.on('updateV2', (update, origin) => {
|
|
8615
|
-
//Dexie.ignoreTransaction(()=>{
|
|
8616
|
-
trigger(doc, parentId);
|
|
8617
|
-
//});
|
|
8618
|
-
});
|
|
8619
|
-
/*
|
|
8620
|
-
NOT NEEDED because DexieYProvider's docCache will also listen to destroy and remove it from its cache:
|
|
8621
|
-
doc.on('destroy', ()=>{
|
|
8622
|
-
docIsAlreadyHooked.delete(doc);
|
|
8623
|
-
})
|
|
8624
|
-
*/
|
|
8625
|
-
}
|
|
8626
|
-
function defineYDocTrigger(table, prop, trigger) {
|
|
8627
|
-
var _a, _b;
|
|
8628
|
-
const updatesTable = (_b = (_a = table.schema.yProps) === null || _a === void 0 ? void 0 : _a.find((p) => p.prop === prop)) === null || _b === void 0 ? void 0 : _b.updatesTable;
|
|
8629
|
-
if (!updatesTable)
|
|
8630
|
-
throw new Error(`Table ${table.name} does not have a Yjs property named ${prop}`);
|
|
8631
|
-
ydocTriggers[updatesTable] = {
|
|
8632
|
-
trigger,
|
|
8633
|
-
parentTable: table.name,
|
|
8634
|
-
prop,
|
|
8635
|
-
};
|
|
8636
|
-
const db = table.db._novip;
|
|
8637
|
-
let mw = middlewares.get(db);
|
|
8638
|
-
if (!mw) {
|
|
8639
|
-
mw = createMiddleware(db);
|
|
8640
|
-
middlewares.set(db, mw);
|
|
8641
|
-
}
|
|
8642
|
-
db.use(mw);
|
|
8643
|
-
}
|
|
8644
|
-
|
|
8645
8645
|
export { dexieCloud as default, defineYDocTrigger, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };
|
|
8646
8646
|
//# sourceMappingURL=dexie-cloud-addon.js.map
|