@syncular/client 0.70.1 → 0.70.2

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/client.js CHANGED
@@ -2437,6 +2437,8 @@ export class SyncClient {
2437
2437
  if (appliedPlan !== purge.canonicalPlan) {
2438
2438
  throw invalidRequest(`local purge id ${JSON.stringify(purge.purgeId)} was already used with a different plan`);
2439
2439
  }
2440
+ // A retry after a failed rewrite finishes it.
2441
+ this.#erasePurgedPages();
2440
2442
  return { alreadyApplied: true, purgedRows: 0, droppedCommits: 0 };
2441
2443
  }
2442
2444
  // RFC 0005 D7: the container file cannot be a purge target (its name is not
@@ -2445,8 +2447,9 @@ export class SyncClient {
2445
2447
  this.#dropPreviousVersion();
2446
2448
  const priorRejections = [...this.#rejections];
2447
2449
  const priorConflicts = [...this.#conflicts];
2450
+ let result;
2448
2451
  try {
2449
- return this.#applyBatch((batch) => {
2452
+ result = this.#applyBatch((batch) => {
2450
2453
  const targetsByTable = this.#localPurgeTargetsByTable(purge);
2451
2454
  restoreFailedBases(this.#db, this.#schema);
2452
2455
  this.#dropRetainedRows(batch, (table, values) => (targetsByTable.get(table) ?? []).some((target) => target.selectors.every((selector) => selector.values.includes(String(values[selector.column])))));
@@ -2506,15 +2509,16 @@ export class SyncClient {
2506
2509
  }
2507
2510
  }
2508
2511
  if (doomed.length > 0) {
2512
+ // §5.11 purge erasure: the journal keeps a dropped commit's identity and codes,
2513
+ // never its operations, so no purged value survives in it.
2509
2514
  for (const commit of doomed) {
2510
- const results = commit.operations.map((operation, opIndex) => {
2515
+ const results = commit.operations.map((_operation, opIndex) => {
2511
2516
  const rejection = {
2512
2517
  clientCommitId: commit.clientCommitId,
2513
2518
  opIndex,
2514
2519
  code: 'client.local_data_purged',
2515
2520
  message: 'the commit was dropped by an application-authorized local data purge',
2516
2521
  retryable: false,
2517
- operation,
2518
2522
  };
2519
2523
  this.#rejections.push(rejection);
2520
2524
  return { status: 'error', rejection };
@@ -2524,7 +2528,6 @@ export class SyncClient {
2524
2528
  status: 'rejected',
2525
2529
  recordedAtMs: this.#now(),
2526
2530
  results,
2527
- operations: commit.operations,
2528
2531
  });
2529
2532
  }
2530
2533
  pruneCommitOutcomes(this.#db, this.#outcomeRetentionMaxEntries);
@@ -2549,6 +2552,24 @@ export class SyncClient {
2549
2552
  this.#conflicts = priorConflicts;
2550
2553
  throw error;
2551
2554
  }
2555
+ this.#erasePurgedPages();
2556
+ return result;
2557
+ }
2558
+ /**
2559
+ * §5.11 purge erasure: SQLite leaves a deleted value in the freed pages of the database
2560
+ * file, and a file replica's WAL keeps the frames written before the
2561
+ * purge, until either is rewritten. VACUUM rebuilds the file from the
2562
+ * remaining rows, and the checkpoint truncates the WAL.
2563
+ */
2564
+ #erasePurgedPages() {
2565
+ this.#db.exec('PRAGMA secure_delete = ON');
2566
+ try {
2567
+ this.#db.exec('VACUUM');
2568
+ this.#db.exec('PRAGMA wal_checkpoint(TRUNCATE)');
2569
+ }
2570
+ finally {
2571
+ this.#db.exec('PRAGMA secure_delete = OFF');
2572
+ }
2552
2573
  }
2553
2574
  /**
2554
2575
  * Rebuild the server-derived local projection without sacrificing offline
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/client",
3
- "version": "0.70.1",
3
+ "version": "0.70.2",
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.70.1"
124
+ "@syncular/core": "0.70.2"
125
125
  },
126
126
  "devDependencies": {
127
127
  "@electric-sql/pglite": "^0.5.4",
128
- "@syncular/server": "0.70.1",
128
+ "@syncular/server": "0.70.2",
129
129
  "playwright": "1.63.0",
130
130
  "vite": "8.3.4"
131
131
  }
package/src/client.ts CHANGED
@@ -3688,6 +3688,8 @@ export class SyncClient {
3688
3688
  `local purge id ${JSON.stringify(purge.purgeId)} was already used with a different plan`,
3689
3689
  );
3690
3690
  }
3691
+ // A retry after a failed rewrite finishes it.
3692
+ this.#erasePurgedPages();
3691
3693
  return { alreadyApplied: true, purgedRows: 0, droppedCommits: 0 };
3692
3694
  }
3693
3695
  // RFC 0005 D7: the container file cannot be a purge target (its name is not
@@ -3697,8 +3699,9 @@ export class SyncClient {
3697
3699
 
3698
3700
  const priorRejections = [...this.#rejections];
3699
3701
  const priorConflicts = [...this.#conflicts];
3702
+ let result: LocalDataPurgeResult;
3700
3703
  try {
3701
- return this.#applyBatch((batch) => {
3704
+ result = this.#applyBatch((batch) => {
3702
3705
  const targetsByTable = this.#localPurgeTargetsByTable(purge);
3703
3706
  restoreFailedBases(this.#db, this.#schema);
3704
3707
  this.#dropRetainedRows(batch, (table, values) =>
@@ -3780,9 +3783,11 @@ export class SyncClient {
3780
3783
  }
3781
3784
 
3782
3785
  if (doomed.length > 0) {
3786
+ // §5.11 purge erasure: the journal keeps a dropped commit's identity and codes,
3787
+ // never its operations, so no purged value survives in it.
3783
3788
  for (const commit of doomed) {
3784
3789
  const results: CommitOperationOutcome[] = commit.operations.map(
3785
- (operation, opIndex) => {
3790
+ (_operation, opIndex) => {
3786
3791
  const rejection: RejectionRecord = {
3787
3792
  clientCommitId: commit.clientCommitId,
3788
3793
  opIndex,
@@ -3790,7 +3795,6 @@ export class SyncClient {
3790
3795
  message:
3791
3796
  'the commit was dropped by an application-authorized local data purge',
3792
3797
  retryable: false,
3793
- operation,
3794
3798
  };
3795
3799
  this.#rejections.push(rejection);
3796
3800
  return { status: 'error', rejection };
@@ -3801,7 +3805,6 @@ export class SyncClient {
3801
3805
  status: 'rejected',
3802
3806
  recordedAtMs: this.#now(),
3803
3807
  results,
3804
- operations: commit.operations,
3805
3808
  });
3806
3809
  }
3807
3810
  pruneCommitOutcomes(this.#db, this.#outcomeRetentionMaxEntries);
@@ -3825,6 +3828,24 @@ export class SyncClient {
3825
3828
  this.#conflicts = priorConflicts;
3826
3829
  throw error;
3827
3830
  }
3831
+ this.#erasePurgedPages();
3832
+ return result;
3833
+ }
3834
+
3835
+ /**
3836
+ * §5.11 purge erasure: SQLite leaves a deleted value in the freed pages of the database
3837
+ * file, and a file replica's WAL keeps the frames written before the
3838
+ * purge, until either is rewritten. VACUUM rebuilds the file from the
3839
+ * remaining rows, and the checkpoint truncates the WAL.
3840
+ */
3841
+ #erasePurgedPages(): void {
3842
+ this.#db.exec('PRAGMA secure_delete = ON');
3843
+ try {
3844
+ this.#db.exec('VACUUM');
3845
+ this.#db.exec('PRAGMA wal_checkpoint(TRUNCATE)');
3846
+ } finally {
3847
+ this.#db.exec('PRAGMA secure_delete = OFF');
3848
+ }
3828
3849
  }
3829
3850
 
3830
3851
  /**