Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion addons/dexie-cloud/dexie-cloud-import.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"demoUsers": {
"[email protected]": {},
"[email protected]": {}
"[email protected]": {},
"[email protected]": {}
}
}
1 change: 1 addition & 0 deletions addons/dexie-cloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"karma-chrome-launcher": "*",
"karma-firefox-launcher": "*",
"karma-qunit": "*",
"karma-webdriver-launcher": "*",
"qunit": "2.10.0",
"qunitjs": "1.23.1",
"lib0": "^0.2.97",
Expand Down
10 changes: 9 additions & 1 deletion addons/dexie-cloud/src/sync/listClientChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,18 @@ function removeRedundantUpdateOps(muts: DBOperation[]) {
// Only apply optimization to update mutations that are single-key
if (mut.type !== 'update') return true;
if (mut.keys.length !== 1 || mut.changeSpecs.length !== 1) return true;

// Check if this has PropModifications - if so, skip optimization
const changeSpecs = mut.changeSpecs[0];
if (Object.values(changeSpecs).some(v => typeof v === "object" && v && "@@propmod" in v)) {
return true; // Cannot optimize if any PropModification is present
}

// Keep track of properties that aren't overlapped by later transactions
const unoverlappedProps = new Set(Object.keys(mut.changeSpecs[0]));
const strKey = '' + mut.keys[0];
const keyCoverage = updateCoverage.get(strKey)!;
const keyCoverage = updateCoverage.get(strKey);
if (!keyCoverage) return true; // No coverage info - cannot optimize

for (let i = keyCoverage.length - 1; i >= 0; --i) {
const { txid, updateSpec } = keyCoverage[i];
Expand Down
9 changes: 8 additions & 1 deletion addons/dexie-cloud/test/unit/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ module.exports = function (config) {
'addons/dexie-cloud/test/unit/bundle.js',
{ pattern: 'addons/dexie-cloud/test/*.map', watched: false, included: false },
{ pattern: 'addons/dexie-cloud/dist/*.map', watched: false, included: false }
])
]),
// Override plugins to exclude karma-webdriver-launcher for local testing
plugins: [
'karma-qunit',
'karma-mocha-reporter',
'karma-chrome-launcher',
'karma-firefox-launcher'
]
});

cfg.hostname = 'localhost';
Expand Down
42 changes: 41 additions & 1 deletion addons/dexie-cloud/test/unit/tests-github-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,51 @@ import {
deepEqual,
} from 'qunit';
import { promisedTest } from '../promisedTest';
import Dexie from 'dexie';
import Dexie, { add, remove } from 'dexie';
import dexieCloud, { DexieCloudOptions, DexieCloudTable, getTiedRealmId } from '../../src/dexie-cloud-client';

const DBURL = 'https://zv8n7bwcs.dexie.cloud'; // Shall exist in cloud.

module('github-issues');

promisedTest('https://github.com/dexie/Dexie.js/issues/2228', async () => {
const DBNAME = 'Issue2228_DB';
const db = new Dexie(DBNAME, { addons: [dexieCloud] }) as Dexie & {
items2228: DexieCloudTable<{ id: string; drinks: string[] }, 'id'>;
};
db.version(1).stores({ items2228: '@id' });
db.cloud.configure({
databaseUrl: DBURL,
requireAuth: { email: '[email protected]', grant_type: 'demo' }
});
await db.open();

ok(true, 'Cleared existing items in items2228 table');
await db.items2228.clear();
ok(true, 'Now syncing to cloud');
await db.cloud.sync({purpose: 'push', wait: true });

await db.items2228.update('nonExistingId', { drinks: add(['coffee']) });
await db.items2228.update('nonExistingId', { drinks: remove(['coffee']) });

ok(true, 'Now syncing to cloud after adding and removing from non-existing item');
await db.cloud.sync({purpose: 'push', wait: true });

const itemId = await db.items2228.add({ drinks: ['coffee', 'tea'] });
ok(true, `Added item with id ${itemId} and drinks ['coffee', 'tea']`);

await db.items2228.update(itemId, { drinks: add(['milk']) });
await db.items2228.update(itemId, { drinks: remove(['milk']) });

ok(true, 'Now syncing to cloud after adding and removing from existing item');
await db.cloud.sync({purpose: 'push', wait: true });

ok(true, 'Test completed successfully');
db.close();
await Dexie.delete(DBNAME);
console.log('Database deleted successfully');
});

/** Dexie issue #2185
*
* Here are the steps to reproduce the issue:
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.