@syncular/client 0.79.1 → 0.79.3
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/apply.js +12 -8
- package/dist/wasm-database.js +3 -1
- package/package.json +3 -3
- package/src/apply.ts +15 -9
- package/src/wasm-database.ts +3 -1
package/dist/apply.js
CHANGED
|
@@ -215,6 +215,11 @@ export function ownsLocalRow(table, effective, owners, values) {
|
|
|
215
215
|
return (matchesLocalScopes(table, effective, values) &&
|
|
216
216
|
!owners.some((owner) => matchesLocalScopes(table, owner, values)));
|
|
217
217
|
}
|
|
218
|
+
/** Whether the failed overlay (§7.4.4) retains rows of `table`. */
|
|
219
|
+
function retainsRows(db, table) {
|
|
220
|
+
return (db.query(`SELECT 1 FROM ${RETAINED_ROWS} WHERE tbl=? LIMIT 1`, [table.name])
|
|
221
|
+
.length > 0);
|
|
222
|
+
}
|
|
218
223
|
function scopedRows(db, table, scope) {
|
|
219
224
|
return scope
|
|
220
225
|
? db.query(`SELECT ${quoteIdent(table.primaryKey)} AS id FROM ${quoteIdent(table.name)} WHERE ${scope.sql}`, scope.params)
|
|
@@ -235,9 +240,10 @@ export function deleteScopedRows(db, table, effective, owners) {
|
|
|
235
240
|
if (!scope)
|
|
236
241
|
return;
|
|
237
242
|
const { sql, params } = scope;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
243
|
+
if (retainsRows(db, table))
|
|
244
|
+
for (const row of scopedRows(db, table, scope)) {
|
|
245
|
+
retainedBaseWrite(db, table, String(row.id));
|
|
246
|
+
}
|
|
241
247
|
db.exec(`DELETE FROM ${quoteIdent(table.name)} WHERE ${sql}`, params);
|
|
242
248
|
}
|
|
243
249
|
/**
|
|
@@ -376,10 +382,7 @@ export async function applySqliteSegment(db, schema, table, bytes, descriptor, o
|
|
|
376
382
|
const started = now();
|
|
377
383
|
let chunk = 0;
|
|
378
384
|
const first = applied === 0;
|
|
379
|
-
const replay = countOutbox(db) ||
|
|
380
|
-
db.query(`SELECT 1 FROM ${RETAINED_ROWS} WHERE tbl=? LIMIT 1`, [
|
|
381
|
-
table.name,
|
|
382
|
-
]).length;
|
|
385
|
+
const replay = countOutbox(db) || retainsRows(db, table);
|
|
383
386
|
const rows = replay
|
|
384
387
|
? db.query(`SELECT * FROM ${source} WHERE ${where}`, params)
|
|
385
388
|
: [];
|
|
@@ -477,7 +480,8 @@ export async function applyRowsSegment(db, schema, table, segment, options, encr
|
|
|
477
480
|
(options.transaction ?? ((fn) => db.transaction(fn)))(() => {
|
|
478
481
|
const scope = [
|
|
479
482
|
...(hasUniqueIndex(table) ? [JSON.stringify([table.name])] : []),
|
|
480
|
-
|
|
483
|
+
// The clear's rows matter only to a replay (§7.8), as in an image chunk.
|
|
484
|
+
...(clearThisBlock && (countOutbox(db) || retainsRows(db, table))
|
|
481
485
|
? bootstrapScope(db, table, options.effective, options.owners())
|
|
482
486
|
: []),
|
|
483
487
|
...rows.map((row) => JSON.stringify([
|
package/dist/wasm-database.js
CHANGED
|
@@ -347,8 +347,10 @@ export async function openPersistentWasmDatabase(name, options) {
|
|
|
347
347
|
const database = new WasmClientDatabase(db, sqlite3, { util, lease }, { fenced: false, siblings: new Set() });
|
|
348
348
|
// §5.3: a new replica uses 64 KiB pages, because every sync-access-handle
|
|
349
349
|
// call costs the same whatever its size. A database with tables keeps its
|
|
350
|
-
// page size.
|
|
350
|
+
// page size. The page cache holds 64 MiB: SQLite's 2,000 KiB default is
|
|
351
|
+
// 31 such pages, and a cache miss is a sync-access-handle call.
|
|
351
352
|
database.exec('PRAGMA page_size=65536');
|
|
353
|
+
database.exec('PRAGMA cache_size=-65536');
|
|
352
354
|
return database;
|
|
353
355
|
}
|
|
354
356
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/client",
|
|
3
|
-
"version": "0.79.
|
|
3
|
+
"version": "0.79.3",
|
|
4
4
|
"description": "Syncular TypeScript client core — offline-first sync over SQLite (WASM/OPFS, Bun, Node)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Benjamin Kniffler",
|
|
@@ -121,11 +121,11 @@
|
|
|
121
121
|
},
|
|
122
122
|
"dependencies": {
|
|
123
123
|
"@sqlite.org/sqlite-wasm": "^3.53.0-build1",
|
|
124
|
-
"@syncular/core": "0.79.
|
|
124
|
+
"@syncular/core": "0.79.3"
|
|
125
125
|
},
|
|
126
126
|
"devDependencies": {
|
|
127
127
|
"@electric-sql/pglite": "^0.5.4",
|
|
128
|
-
"@syncular/server": "0.79.
|
|
128
|
+
"@syncular/server": "0.79.3",
|
|
129
129
|
"playwright": "1.63.0",
|
|
130
130
|
"vite": "8.3.4"
|
|
131
131
|
}
|
package/src/apply.ts
CHANGED
|
@@ -359,6 +359,14 @@ export function ownsLocalRow(
|
|
|
359
359
|
);
|
|
360
360
|
}
|
|
361
361
|
|
|
362
|
+
/** Whether the failed overlay (§7.4.4) retains rows of `table`. */
|
|
363
|
+
function retainsRows(db: ClientDatabase, table: CompiledClientTable): boolean {
|
|
364
|
+
return (
|
|
365
|
+
db.query(`SELECT 1 FROM ${RETAINED_ROWS} WHERE tbl=? LIMIT 1`, [table.name])
|
|
366
|
+
.length > 0
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
|
|
362
370
|
function scopedRows(
|
|
363
371
|
db: ClientDatabase,
|
|
364
372
|
table: CompiledClientTable,
|
|
@@ -408,9 +416,10 @@ export function deleteScopedRows(
|
|
|
408
416
|
const scope = localScopePredicate(table, effective, owners);
|
|
409
417
|
if (!scope) return;
|
|
410
418
|
const { sql, params } = scope;
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
419
|
+
if (retainsRows(db, table))
|
|
420
|
+
for (const row of scopedRows(db, table, scope)) {
|
|
421
|
+
retainedBaseWrite(db, table, String(row.id));
|
|
422
|
+
}
|
|
414
423
|
db.exec(`DELETE FROM ${quoteIdent(table.name)} WHERE ${sql}`, params);
|
|
415
424
|
}
|
|
416
425
|
|
|
@@ -643,11 +652,7 @@ export async function applySqliteSegment(
|
|
|
643
652
|
const started = now();
|
|
644
653
|
let chunk = 0;
|
|
645
654
|
const first = applied === 0;
|
|
646
|
-
const replay =
|
|
647
|
-
countOutbox(db) ||
|
|
648
|
-
db.query(`SELECT 1 FROM ${RETAINED_ROWS} WHERE tbl=? LIMIT 1`, [
|
|
649
|
-
table.name,
|
|
650
|
-
]).length;
|
|
655
|
+
const replay = countOutbox(db) || retainsRows(db, table);
|
|
651
656
|
const rows = replay
|
|
652
657
|
? db.query(`SELECT * FROM ${source} WHERE ${where}`, params)
|
|
653
658
|
: [];
|
|
@@ -796,7 +801,8 @@ export async function applyRowsSegment(
|
|
|
796
801
|
(options.transaction ?? ((fn) => db.transaction(fn)))(() => {
|
|
797
802
|
const scope: OverlayScope = [
|
|
798
803
|
...(hasUniqueIndex(table) ? [JSON.stringify([table.name])] : []),
|
|
799
|
-
|
|
804
|
+
// The clear's rows matter only to a replay (§7.8), as in an image chunk.
|
|
805
|
+
...(clearThisBlock && (countOutbox(db) || retainsRows(db, table))
|
|
800
806
|
? bootstrapScope(db, table, options.effective, options.owners())
|
|
801
807
|
: []),
|
|
802
808
|
...rows.map((row) =>
|
package/src/wasm-database.ts
CHANGED
|
@@ -569,8 +569,10 @@ export async function openPersistentWasmDatabase(
|
|
|
569
569
|
);
|
|
570
570
|
// §5.3: a new replica uses 64 KiB pages, because every sync-access-handle
|
|
571
571
|
// call costs the same whatever its size. A database with tables keeps its
|
|
572
|
-
// page size.
|
|
572
|
+
// page size. The page cache holds 64 MiB: SQLite's 2,000 KiB default is
|
|
573
|
+
// 31 such pages, and a cache miss is a sync-access-handle call.
|
|
573
574
|
database.exec('PRAGMA page_size=65536');
|
|
575
|
+
database.exec('PRAGMA cache_size=-65536');
|
|
574
576
|
return database;
|
|
575
577
|
} catch (error) {
|
|
576
578
|
db?.close();
|