@powersync/service-module-postgres 0.0.0-dev-20250618151716 → 0.0.0-dev-20250714131917

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 (32) hide show
  1. package/CHANGELOG.md +40 -6
  2. package/dist/api/PostgresRouteAPIAdapter.js +3 -1
  3. package/dist/api/PostgresRouteAPIAdapter.js.map +1 -1
  4. package/dist/auth/SupabaseKeyCollector.js +3 -1
  5. package/dist/auth/SupabaseKeyCollector.js.map +1 -1
  6. package/dist/module/PostgresModule.js +5 -2
  7. package/dist/module/PostgresModule.js.map +1 -1
  8. package/dist/replication/PgManager.js +3 -2
  9. package/dist/replication/PgManager.js.map +1 -1
  10. package/dist/replication/WalStream.js +4 -1
  11. package/dist/replication/WalStream.js.map +1 -1
  12. package/dist/replication/WalStreamReplicationJob.js +5 -2
  13. package/dist/replication/WalStreamReplicationJob.js.map +1 -1
  14. package/dist/replication/WalStreamReplicator.js +3 -1
  15. package/dist/replication/WalStreamReplicator.js.map +1 -1
  16. package/dist/utils/application-name.d.ts +4 -0
  17. package/dist/utils/application-name.js +8 -0
  18. package/dist/utils/application-name.js.map +1 -0
  19. package/dist/utils/populate_test_data_worker.js +4 -1
  20. package/dist/utils/populate_test_data_worker.js.map +1 -1
  21. package/package.json +10 -10
  22. package/src/api/PostgresRouteAPIAdapter.ts +3 -1
  23. package/src/auth/SupabaseKeyCollector.ts +3 -1
  24. package/src/module/PostgresModule.ts +5 -2
  25. package/src/replication/PgManager.ts +3 -2
  26. package/src/replication/WalStream.ts +5 -1
  27. package/src/replication/WalStreamReplicationJob.ts +5 -2
  28. package/src/replication/WalStreamReplicator.ts +3 -1
  29. package/src/utils/application-name.ts +8 -0
  30. package/src/utils/populate_test_data_worker.ts +4 -1
  31. package/test/src/util.ts +1 -1
  32. package/tsconfig.tsbuildinfo +1 -1
@@ -1,6 +1,7 @@
1
1
  import * as pgwire from '@powersync/service-jpgwire';
2
2
  import semver from 'semver';
3
3
  import { NormalizedPostgresConnectionConfig } from '../types/types.js';
4
+ import { getApplicationName } from '../utils/application-name.js';
4
5
 
5
6
  /**
6
7
  * Shorter timeout for snapshot connections than for replication connections.
@@ -31,7 +32,7 @@ export class PgManager {
31
32
  * Create a new replication connection.
32
33
  */
33
34
  async replicationConnection(): Promise<pgwire.PgConnection> {
34
- const p = pgwire.connectPgWire(this.options, { type: 'replication' });
35
+ const p = pgwire.connectPgWire(this.options, { type: 'replication', applicationName: getApplicationName() });
35
36
  this.connectionPromises.push(p);
36
37
  return await p;
37
38
  }
@@ -51,7 +52,7 @@ export class PgManager {
51
52
  * This connection must not be shared between multiple async contexts.
52
53
  */
53
54
  async snapshotConnection(): Promise<pgwire.PgConnection> {
54
- const p = pgwire.connectPgWire(this.options, { type: 'standard' });
55
+ const p = pgwire.connectPgWire(this.options, { type: 'standard', applicationName: getApplicationName() });
55
56
  this.connectionPromises.push(p);
56
57
  const connection = await p;
57
58
 
@@ -1003,7 +1003,11 @@ WHERE oid = $1::regclass`,
1003
1003
  // Big caveat: This _must not_ be used to skip individual messages, since this LSN
1004
1004
  // may be in the middle of the next transaction.
1005
1005
  // It must only be used to associate checkpoints with LSNs.
1006
- await batch.keepalive(chunkLastLsn);
1006
+ const didCommit = await batch.keepalive(chunkLastLsn);
1007
+ if (didCommit) {
1008
+ this.oldestUncommittedChange = null;
1009
+ }
1010
+
1007
1011
  this.isStartingReplication = false;
1008
1012
  }
1009
1013
 
@@ -4,6 +4,7 @@ import { MissingReplicationSlotError, sendKeepAlive, WalStream } from './WalStre
4
4
 
5
5
  import { replication } from '@powersync/service-core';
6
6
  import { ConnectionManagerFactory } from './ConnectionManagerFactory.js';
7
+ import { getApplicationName } from '../utils/application-name.js';
7
8
 
8
9
  export interface WalStreamReplicationJobOptions extends replication.AbstractReplicationJobOptions {
9
10
  connectionFactory: ConnectionManagerFactory;
@@ -21,7 +22,8 @@ export class WalStreamReplicationJob extends replication.AbstractReplicationJob
21
22
  this.connectionManager = this.connectionFactory.create({
22
23
  // Pool connections are only used intermittently.
23
24
  idleTimeout: 30_000,
24
- maxSize: 2
25
+ maxSize: 2,
26
+ applicationName: getApplicationName()
25
27
  });
26
28
  }
27
29
 
@@ -87,7 +89,8 @@ export class WalStreamReplicationJob extends replication.AbstractReplicationJob
87
89
  const connectionManager = this.connectionFactory.create({
88
90
  // Pool connections are only used intermittently.
89
91
  idleTimeout: 30_000,
90
- maxSize: 2
92
+ maxSize: 2,
93
+ applicationName: getApplicationName()
91
94
  });
92
95
  try {
93
96
  await this.rateLimiter?.waitUntilAllowed({ signal: this.abortController.signal });
@@ -1,8 +1,9 @@
1
1
  import { replication, storage } from '@powersync/service-core';
2
+ import { PostgresModule } from '../module/PostgresModule.js';
3
+ import { getApplicationName } from '../utils/application-name.js';
2
4
  import { ConnectionManagerFactory } from './ConnectionManagerFactory.js';
3
5
  import { cleanUpReplicationSlot } from './replication-utils.js';
4
6
  import { WalStreamReplicationJob } from './WalStreamReplicationJob.js';
5
- import { PostgresModule } from '../module/PostgresModule.js';
6
7
 
7
8
  export interface WalStreamReplicatorOptions extends replication.AbstractReplicatorOptions {
8
9
  connectionFactory: ConnectionManagerFactory;
@@ -29,6 +30,7 @@ export class WalStreamReplicator extends replication.AbstractReplicator<WalStrea
29
30
 
30
31
  async cleanUp(syncRulesStorage: storage.SyncRulesBucketStorage): Promise<void> {
31
32
  const connectionManager = this.connectionFactory.create({
33
+ applicationName: getApplicationName(),
32
34
  idleTimeout: 30_000,
33
35
  maxSize: 1
34
36
  });
@@ -0,0 +1,8 @@
1
+ import { POWERSYNC_VERSION } from '@powersync/service-core';
2
+
3
+ /**
4
+ * application_name for PostgreSQL connections to the source database
5
+ */
6
+ export function getApplicationName() {
7
+ return `powersync/${POWERSYNC_VERSION}`;
8
+ }
@@ -29,7 +29,10 @@ if (isMainThread || parentPort == null) {
29
29
 
30
30
  async function populateDataInner(options: PopulateDataOptions) {
31
31
  // Dedicated connection so we can release the memory easily
32
- const initialDb = await pgwire.connectPgWire(options.connection, { type: 'standard' });
32
+ const initialDb = await pgwire.connectPgWire(options.connection, {
33
+ type: 'standard',
34
+ applicationName: 'powersync-tests'
35
+ });
33
36
  const largeDescription = crypto.randomBytes(options.size / 2).toString('hex');
34
37
  let operation_count = 0;
35
38
  for (let i = 0; i < options.num_transactions; i++) {
package/test/src/util.ts CHANGED
@@ -62,7 +62,7 @@ export async function clearTestDb(db: pgwire.PgClient) {
62
62
  }
63
63
 
64
64
  export async function connectPgWire(type?: 'replication' | 'standard') {
65
- const db = await pgwire.connectPgWire(TEST_CONNECTION_OPTIONS, { type });
65
+ const db = await pgwire.connectPgWire(TEST_CONNECTION_OPTIONS, { type, applicationName: 'powersync-tests' });
66
66
  return db;
67
67
  }
68
68