@powersync/service-module-postgres 0.0.0-dev-20250122110924 → 0.0.0-dev-20250227082606

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +102 -11
  2. package/dist/api/PostgresRouteAPIAdapter.d.ts +2 -1
  3. package/dist/api/PostgresRouteAPIAdapter.js +16 -9
  4. package/dist/api/PostgresRouteAPIAdapter.js.map +1 -1
  5. package/dist/auth/SupabaseKeyCollector.js +6 -5
  6. package/dist/auth/SupabaseKeyCollector.js.map +1 -1
  7. package/dist/module/PostgresModule.js +2 -2
  8. package/dist/module/PostgresModule.js.map +1 -1
  9. package/dist/replication/ConnectionManagerFactory.js +2 -0
  10. package/dist/replication/ConnectionManagerFactory.js.map +1 -1
  11. package/dist/replication/PgManager.d.ts +5 -0
  12. package/dist/replication/PgManager.js +17 -2
  13. package/dist/replication/PgManager.js.map +1 -1
  14. package/dist/replication/PostgresErrorRateLimiter.js +5 -7
  15. package/dist/replication/PostgresErrorRateLimiter.js.map +1 -1
  16. package/dist/replication/WalStream.d.ts +18 -3
  17. package/dist/replication/WalStream.js +132 -17
  18. package/dist/replication/WalStream.js.map +1 -1
  19. package/dist/replication/WalStreamReplicationJob.js +9 -7
  20. package/dist/replication/WalStreamReplicationJob.js.map +1 -1
  21. package/dist/replication/WalStreamReplicator.js +2 -1
  22. package/dist/replication/WalStreamReplicator.js.map +1 -1
  23. package/dist/types/types.d.ts +3 -0
  24. package/dist/utils/migration_lib.js +1 -3
  25. package/dist/utils/migration_lib.js.map +1 -1
  26. package/dist/utils/populate_test_data.js +1 -1
  27. package/dist/utils/populate_test_data.js.map +1 -1
  28. package/package.json +14 -12
  29. package/src/api/PostgresRouteAPIAdapter.ts +13 -8
  30. package/src/replication/PgManager.ts +10 -0
  31. package/src/replication/WalStream.ts +152 -20
  32. package/src/replication/WalStreamReplicationJob.ts +5 -5
  33. package/test/src/checkpoints.test.ts +74 -0
  34. package/test/src/slow_tests.test.ts +102 -114
  35. package/test/src/storage_combination.test.ts +35 -0
  36. package/test/src/util.ts +5 -4
  37. package/test/src/wal_stream_utils.ts +1 -2
  38. package/tsconfig.tsbuildinfo +1 -1
package/test/src/util.ts CHANGED
@@ -62,13 +62,13 @@ export function connectPgPool() {
62
62
 
63
63
  export async function getClientCheckpoint(
64
64
  db: pgwire.PgClient,
65
- bucketStorage: BucketStorageFactory,
65
+ storageFactory: BucketStorageFactory,
66
66
  options?: { timeout?: number }
67
67
  ): Promise<OpId> {
68
68
  const start = Date.now();
69
69
 
70
70
  const api = new PostgresRouteAPIAdapter(db);
71
- const lsn = await api.getReplicationHead();
71
+ const lsn = await api.createReplicationHead(async (lsn) => lsn);
72
72
 
73
73
  // This old API needs a persisted checkpoint id.
74
74
  // Since we don't use LSNs anymore, the only way to get that is to wait.
@@ -77,8 +77,9 @@ export async function getClientCheckpoint(
77
77
 
78
78
  logger.info(`Waiting for LSN checkpoint: ${lsn}`);
79
79
  while (Date.now() - start < timeout) {
80
- const cp = await bucketStorage.getActiveCheckpoint();
81
- if (!cp.hasSyncRules()) {
80
+ const storage = await storageFactory.getActiveStorage();
81
+ const cp = await storage?.getCheckpoint();
82
+ if (cp == null) {
82
83
  throw new Error('No sync rules available');
83
84
  }
84
85
  if (cp.lsn && cp.lsn >= lsn) {
@@ -45,7 +45,6 @@ export class WalStreamTestContext implements AsyncDisposable {
45
45
  this.abortController.abort();
46
46
  await this.streamPromise;
47
47
  await this.connectionManager.destroy();
48
- this.storage?.[Symbol.dispose]();
49
48
  await this.factory?.[Symbol.asyncDispose]();
50
49
  }
51
50
 
@@ -62,7 +61,7 @@ export class WalStreamTestContext implements AsyncDisposable {
62
61
  }
63
62
 
64
63
  async updateSyncRules(content: string) {
65
- const syncRules = await this.factory.updateSyncRules({ content: content });
64
+ const syncRules = await this.factory.updateSyncRules({ content: content, validate: true });
66
65
  this.storage = this.factory.getInstance(syncRules);
67
66
  return this.storage!;
68
67
  }