@powersync/service-module-postgres 0.0.0-dev-20250310210938 → 0.0.0-dev-20250312090341

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.
@@ -1,5 +1,5 @@
1
1
  import * as bson from 'bson';
2
- import { afterEach, beforeAll, describe, expect, test } from 'vitest';
2
+ import { afterEach, describe, expect, test } from 'vitest';
3
3
  import { WalStream, WalStreamOptions } from '../../src/replication/WalStream.js';
4
4
  import { env } from './env.js';
5
5
  import {
@@ -15,8 +15,8 @@ import * as pgwire from '@powersync/service-jpgwire';
15
15
  import { SqliteRow } from '@powersync/service-sync-rules';
16
16
 
17
17
  import { PgManager } from '@module/replication/PgManager.js';
18
- import { createCoreReplicationMetrics, initializeCoreReplicationMetrics, storage } from '@powersync/service-core';
19
- import { METRICS_HELPER, test_utils } from '@powersync/service-core-tests';
18
+ import { storage } from '@powersync/service-core';
19
+ import { test_utils } from '@powersync/service-core-tests';
20
20
  import * as mongo_storage from '@powersync/service-module-mongodb-storage';
21
21
  import * as postgres_storage from '@powersync/service-module-postgres-storage';
22
22
  import * as timers from 'node:timers/promises';
@@ -49,11 +49,6 @@ function defineSlowTests(factory: storage.TestStorageFactory) {
49
49
  let abortController: AbortController | undefined;
50
50
  let streamPromise: Promise<void> | undefined;
51
51
 
52
- beforeAll(async () => {
53
- createCoreReplicationMetrics(METRICS_HELPER.metricsEngine);
54
- initializeCoreReplicationMetrics(METRICS_HELPER.metricsEngine);
55
- });
56
-
57
52
  afterEach(async () => {
58
53
  // This cleans up, similar to WalStreamTestContext.dispose().
59
54
  // These tests are a little more complex than what is supported by WalStreamTestContext.
@@ -103,8 +98,7 @@ bucket_definitions:
103
98
  const options: WalStreamOptions = {
104
99
  abort_signal: abortController.signal,
105
100
  connections,
106
- storage: storage,
107
- metrics: METRICS_HELPER.metricsEngine
101
+ storage: storage
108
102
  };
109
103
  walStream = new WalStream(options);
110
104
 
@@ -350,14 +344,13 @@ bucket_definitions:
350
344
  const connections = new PgManager(TEST_CONNECTION_OPTIONS, {});
351
345
  const replicationConnection = await connections.replicationConnection();
352
346
 
353
- abortController = new AbortController();
354
- const options: WalStreamOptions = {
355
- abort_signal: abortController.signal,
356
- connections,
357
- storage: storage,
358
- metrics: METRICS_HELPER.metricsEngine
359
- };
360
- walStream = new WalStream(options);
347
+ abortController = new AbortController();
348
+ const options: WalStreamOptions = {
349
+ abort_signal: abortController.signal,
350
+ connections,
351
+ storage: storage
352
+ };
353
+ walStream = new WalStream(options);
361
354
 
362
355
  await storage.clear();
363
356
 
@@ -1,13 +1,12 @@
1
1
  import { MissingReplicationSlotError } from '@module/replication/WalStream.js';
2
- import { storage } from '@powersync/service-core';
3
- import { METRICS_HELPER, putOp, removeOp } from '@powersync/service-core-tests';
2
+ import { Metrics, storage } from '@powersync/service-core';
3
+ import { putOp, removeOp } from '@powersync/service-core-tests';
4
4
  import { pgwireRows } from '@powersync/service-jpgwire';
5
5
  import * as crypto from 'crypto';
6
6
  import { describe, expect, test } from 'vitest';
7
7
  import { env } from './env.js';
8
8
  import { INITIALIZED_MONGO_STORAGE_FACTORY, INITIALIZED_POSTGRES_STORAGE_FACTORY } from './util.js';
9
9
  import { WalStreamTestContext } from './wal_stream_utils.js';
10
- import { ReplicationMetric } from '@powersync/service-types';
11
10
 
12
11
  const BASIC_SYNC_RULES = `
13
12
  bucket_definitions:
@@ -41,8 +40,9 @@ bucket_definitions:
41
40
 
42
41
  await context.replicateSnapshot();
43
42
 
44
- const startRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
45
- const startTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
43
+ const startRowCount = (await Metrics.getInstance().getMetricValueForTests('powersync_rows_replicated_total')) ?? 0;
44
+ const startTxCount =
45
+ (await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
46
46
 
47
47
  context.startStreaming();
48
48
 
@@ -55,8 +55,9 @@ bucket_definitions:
55
55
  const data = await context.getBucketData('global[]');
56
56
 
57
57
  expect(data).toMatchObject([putOp('test_data', { id: test_id, description: 'test1', num: 1152921504606846976n })]);
58
- const endRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
59
- const endTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
58
+ const endRowCount = (await Metrics.getInstance().getMetricValueForTests('powersync_rows_replicated_total')) ?? 0;
59
+ const endTxCount =
60
+ (await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
60
61
  expect(endRowCount - startRowCount).toEqual(1);
61
62
  expect(endTxCount - startTxCount).toEqual(1);
62
63
  });
@@ -76,8 +77,9 @@ bucket_definitions:
76
77
 
77
78
  await context.replicateSnapshot();
78
79
 
79
- const startRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
80
- const startTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
80
+ const startRowCount = (await Metrics.getInstance().getMetricValueForTests('powersync_rows_replicated_total')) ?? 0;
81
+ const startTxCount =
82
+ (await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
81
83
 
82
84
  context.startStreaming();
83
85
 
@@ -88,8 +90,9 @@ bucket_definitions:
88
90
  const data = await context.getBucketData('global[]');
89
91
 
90
92
  expect(data).toMatchObject([putOp('test_DATA', { id: test_id, description: 'test1' })]);
91
- const endRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
92
- const endTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
93
+ const endRowCount = (await Metrics.getInstance().getMetricValueForTests('powersync_rows_replicated_total')) ?? 0;
94
+ const endTxCount =
95
+ (await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
93
96
  expect(endRowCount - startRowCount).toEqual(1);
94
97
  expect(endTxCount - startTxCount).toEqual(1);
95
98
  });
@@ -271,8 +274,9 @@ bucket_definitions:
271
274
 
272
275
  await context.replicateSnapshot();
273
276
 
274
- const startRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
275
- const startTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
277
+ const startRowCount = (await Metrics.getInstance().getMetricValueForTests('powersync_rows_replicated_total')) ?? 0;
278
+ const startTxCount =
279
+ (await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
276
280
 
277
281
  context.startStreaming();
278
282
 
@@ -283,8 +287,9 @@ bucket_definitions:
283
287
  const data = await context.getBucketData('global[]');
284
288
 
285
289
  expect(data).toMatchObject([]);
286
- const endRowCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.ROWS_REPLICATED)) ?? 0;
287
- const endTxCount = (await METRICS_HELPER.getMetricValueForTests(ReplicationMetric.TRANSACTIONS_REPLICATED)) ?? 0;
290
+ const endRowCount = (await Metrics.getInstance().getMetricValueForTests('powersync_rows_replicated_total')) ?? 0;
291
+ const endTxCount =
292
+ (await Metrics.getInstance().getMetricValueForTests('powersync_transactions_replicated_total')) ?? 0;
288
293
 
289
294
  // There was a transaction, but we should not replicate any actual data
290
295
  expect(endRowCount - startRowCount).toEqual(0);
@@ -2,14 +2,12 @@ import { PgManager } from '@module/replication/PgManager.js';
2
2
  import { PUBLICATION_NAME, WalStream, WalStreamOptions } from '@module/replication/WalStream.js';
3
3
  import {
4
4
  BucketStorageFactory,
5
- createCoreReplicationMetrics,
6
- initializeCoreReplicationMetrics,
7
5
  InternalOpId,
8
6
  OplogEntry,
9
7
  storage,
10
8
  SyncRulesBucketStorage
11
9
  } from '@powersync/service-core';
12
- import { METRICS_HELPER, test_utils } from '@powersync/service-core-tests';
10
+ import { test_utils } from '@powersync/service-core-tests';
13
11
  import * as pgwire from '@powersync/service-jpgwire';
14
12
  import { clearTestDb, getClientCheckpoint, TEST_CONNECTION_OPTIONS } from './util.js';
15
13
 
@@ -43,10 +41,7 @@ export class WalStreamTestContext implements AsyncDisposable {
43
41
  constructor(
44
42
  public factory: BucketStorageFactory,
45
43
  public connectionManager: PgManager
46
- ) {
47
- createCoreReplicationMetrics(METRICS_HELPER.metricsEngine);
48
- initializeCoreReplicationMetrics(METRICS_HELPER.metricsEngine);
49
- }
44
+ ) {}
50
45
 
51
46
  async [Symbol.asyncDispose]() {
52
47
  await this.dispose();
@@ -106,7 +101,6 @@ export class WalStreamTestContext implements AsyncDisposable {
106
101
  }
107
102
  const options: WalStreamOptions = {
108
103
  storage: this.storage,
109
- metrics: METRICS_HELPER.metricsEngine,
110
104
  connections: this.connectionManager,
111
105
  abort_signal: this.abortController.signal
112
106
  };