@powersync/service-module-postgres 0.2.3 → 0.3.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @powersync/service-module-postgres
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - fea550f: Added minor typing utilities
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [fea550f]
12
+ - Updated dependencies [fea550f]
13
+ - Updated dependencies [48320b5]
14
+ - Updated dependencies [fea550f]
15
+ - @powersync/service-core@0.14.0
16
+ - @powersync/lib-services-framework@0.3.0
17
+ - @powersync/service-sync-rules@0.23.1
18
+ - @powersync/service-types@0.7.0
19
+ - @powersync/service-jpgwire@0.18.5
20
+
21
+ ## 0.2.4
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [0bf1309]
26
+ - Updated dependencies [a66be3b]
27
+ - Updated dependencies [010f6e2]
28
+ - @powersync/service-core@0.13.0
29
+ - @powersync/service-types@0.6.0
30
+ - @powersync/service-sync-rules@0.23.0
31
+ - @powersync/service-jpgwire@0.18.4
32
+
3
33
  ## 0.2.3
4
34
 
5
35
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './module/PostgresModule.js';
2
+ export * as pg_utils from './utils/pgwire_utils.js';
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './module/PostgresModule.js';
2
+ export * as pg_utils from './utils/pgwire_utils.js';
2
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAE3C,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC"}
@@ -6,9 +6,9 @@ import { ConnectionManagerFactory } from '../replication/ConnectionManagerFactor
6
6
  import { PgManager } from '../replication/PgManager.js';
7
7
  import { PostgresErrorRateLimiter } from '../replication/PostgresErrorRateLimiter.js';
8
8
  import { checkSourceConfiguration, cleanUpReplicationSlot } from '../replication/replication-utils.js';
9
+ import { PUBLICATION_NAME } from '../replication/WalStream.js';
9
10
  import { WalStreamReplicator } from '../replication/WalStreamReplicator.js';
10
11
  import * as types from '../types/types.js';
11
- import { PUBLICATION_NAME } from '../replication/WalStream.js';
12
12
  export class PostgresModule extends replication.ReplicationModule {
13
13
  constructor() {
14
14
  super({
@@ -1 +1 @@
1
- {"version":3,"file":"PostgresModule.js","sourceRoot":"","sources":["../../src/module/PostgresModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,IAAI,EAAE,kCAAkC,EAAW,WAAW,EAAU,MAAM,yBAAyB,CAAC;AACtH,OAAO,KAAK,OAAO,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AACvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,MAAM,OAAO,cAAe,SAAQ,WAAW,CAAC,iBAAiD;IAC/F;QACE,KAAK,CAAC;YACJ,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,KAAK,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,CAAC,iCAAiC,EAAE,EAAE,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;aAClB,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAClB,MAAM,YAAY,GAAG,IAAI,oBAAoB,CAAC,MAAO,CAAC,CAAC;YACvD,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,YAAY,EAAE;gBAClD,0BAA0B;gBAC1B,IAAI,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE;aAC1C,CAAC,CAAC;YACH,aAAa,CAAC,eAAe,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC;QACzF,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,MAAgC;QACnD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC1B,MAAM,gBAAgB,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,aAAc,CAAC,CAAC;QACjE,MAAM,iBAAiB,GAAG,IAAI,SAAS,CAAC,gBAAgB,EAAE;YACxD,WAAW,EAAE,KAAM;YACnB,OAAO,EAAE,CAAC;SACX,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,MAAM,iBAAiB,CAAC,kBAAkB,EAAE,CAAC;QAChE,IAAI,CAAC;YACH,OAAO,MAAM,wBAAwB,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;QACtE,CAAC;gBAAS,CAAC;YACT,MAAM,iBAAiB,CAAC,GAAG,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;CACF"}
@@ -1,3 +1,4 @@
1
+ import * as service_types from '@powersync/service-types';
1
2
  import * as t from 'ts-codec';
2
3
  export declare const POSTGRES_CONNECTION_TYPE: "postgresql";
3
4
  export interface NormalizedPostgresConnectionConfig {
@@ -62,6 +63,7 @@ export type ResolvedConnectionConfig = PostgresConnectionConfig & NormalizedPost
62
63
  * Returns destructured options.
63
64
  */
64
65
  export declare function normalizeConnectionConfig(options: PostgresConnectionConfig): NormalizedPostgresConnectionConfig;
66
+ export declare function isPostgresConfig(config: service_types.configFile.DataSourceConfig): config is PostgresConnectionConfig;
65
67
  /**
66
68
  * Check whether the port is in a "safe" range.
67
69
  *
@@ -83,6 +83,9 @@ export function normalizeConnectionConfig(options) {
83
83
  client_private_key: options.client_private_key ?? undefined
84
84
  };
85
85
  }
86
+ export function isPostgresConfig(config) {
87
+ return config.type == POSTGRES_CONNECTION_TYPE;
88
+ }
86
89
  /**
87
90
  * Check whether the port is in a "safe" range.
88
91
  *
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,KAAK,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAqB,CAAC;AAoB9D,MAAM,CAAC,MAAM,wBAAwB,GAAG,aAAa,CAAC,UAAU,CAAC,gBAAgB,CAAC,GAAG,CACnF,CAAC,CAAC,MAAM,CAAC;IACP,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,wBAAwB,CAAC;IACzC,2FAA2F;IAC3F,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;IACvB,8FAA8F;IAC9F,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;IACxB,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;IACxB,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;IAC7B,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE;IACnD,QAAQ,EAAE,CA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IACjE,OAAO,gBAAgB,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;AAChF,CAAC"}
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.2.3",
8
+ "version": "0.3.0",
9
9
  "main": "dist/index.js",
10
10
  "license": "FSL-1.1-Apache-2.0",
11
11
  "type": "module",
@@ -24,18 +24,20 @@
24
24
  "dependencies": {
25
25
  "pgwire": "github:kagis/pgwire#f1cb95f9a0f42a612bb5a6b67bb2eb793fc5fc87",
26
26
  "jose": "^4.15.1",
27
- "ts-codec": "^1.2.2",
27
+ "ts-codec": "^1.3.0",
28
28
  "uuid": "^9.0.1",
29
29
  "uri-js": "^4.4.1",
30
- "@powersync/lib-services-framework": "0.2.0",
31
- "@powersync/service-core": "0.12.2",
32
- "@powersync/service-jpgwire": "0.18.3",
30
+ "@powersync/lib-services-framework": "0.3.0",
31
+ "@powersync/service-core": "0.14.0",
32
+ "@powersync/service-jpgwire": "0.18.5",
33
33
  "@powersync/service-jsonbig": "0.17.10",
34
- "@powersync/service-sync-rules": "0.22.0",
35
- "@powersync/service-types": "0.5.0"
34
+ "@powersync/service-sync-rules": "0.23.1",
35
+ "@powersync/service-types": "0.7.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@types/uuid": "^9.0.4"
38
+ "@types/uuid": "^9.0.4",
39
+ "@powersync/service-core-tests": "0.2.0",
40
+ "@powersync/service-module-mongodb-storage": "0.1.0"
39
41
  },
40
42
  "scripts": {
41
43
  "build": "tsc -b",
package/src/index.ts CHANGED
@@ -1 +1,3 @@
1
1
  export * from './module/PostgresModule.js';
2
+
3
+ export * as pg_utils from './utils/pgwire_utils.js';
@@ -6,10 +6,10 @@ import { ConnectionManagerFactory } from '../replication/ConnectionManagerFactor
6
6
  import { PgManager } from '../replication/PgManager.js';
7
7
  import { PostgresErrorRateLimiter } from '../replication/PostgresErrorRateLimiter.js';
8
8
  import { checkSourceConfiguration, cleanUpReplicationSlot } from '../replication/replication-utils.js';
9
+ import { PUBLICATION_NAME } from '../replication/WalStream.js';
9
10
  import { WalStreamReplicator } from '../replication/WalStreamReplicator.js';
10
11
  import * as types from '../types/types.js';
11
12
  import { PostgresConnectionConfig } from '../types/types.js';
12
- import { PUBLICATION_NAME } from '../replication/WalStream.js';
13
13
 
14
14
  export class PostgresModule extends replication.ReplicationModule<types.PostgresConnectionConfig> {
15
15
  constructor() {
@@ -133,6 +133,12 @@ export function normalizeConnectionConfig(options: PostgresConnectionConfig): No
133
133
  };
134
134
  }
135
135
 
136
+ export function isPostgresConfig(
137
+ config: service_types.configFile.DataSourceConfig
138
+ ): config is PostgresConnectionConfig {
139
+ return config.type == POSTGRES_CONNECTION_TYPE;
140
+ }
141
+
136
142
  /**
137
143
  * Check whether the port is in a "safe" range.
138
144
  *
package/test/src/env.ts CHANGED
@@ -2,6 +2,7 @@ import { utils } from '@powersync/lib-services-framework';
2
2
 
3
3
  export const env = utils.collectEnvironmentVariables({
4
4
  PG_TEST_URL: utils.type.string.default('postgres://postgres:postgres@localhost:5432/powersync_test'),
5
+ MONGO_TEST_URL: utils.type.string.default('mongodb://localhost:27017/powersync_test'),
5
6
  CI: utils.type.boolean.default('false'),
6
7
  SLOW_TESTS: utils.type.boolean.default('false')
7
8
  });
@@ -1,17 +1,16 @@
1
- import { MONGO_STORAGE_FACTORY, StorageFactory, StorageOptions } from '@core-tests/util.js';
1
+ import { Metrics, storage } from '@powersync/service-core';
2
+ import * as timers from 'timers/promises';
2
3
  import { describe, expect, test } from 'vitest';
3
4
  import { populateData } from '../../dist/utils/populate_test_data.js';
4
5
  import { env } from './env.js';
5
- import { TEST_CONNECTION_OPTIONS } from './util.js';
6
+ import { INITIALIZED_MONGO_STORAGE_FACTORY, TEST_CONNECTION_OPTIONS } from './util.js';
6
7
  import { WalStreamTestContext } from './wal_stream_utils.js';
7
- import * as timers from 'timers/promises';
8
- import { Metrics } from '@powersync/service-core';
9
8
 
10
9
  describe('batch replication tests - mongodb', { timeout: 120_000 }, function () {
11
10
  // These are slow but consistent tests.
12
11
  // Not run on every test run, but we do run on CI, or when manually debugging issues.
13
12
  if (env.CI || env.SLOW_TESTS) {
14
- defineBatchTests(MONGO_STORAGE_FACTORY);
13
+ defineBatchTests(INITIALIZED_MONGO_STORAGE_FACTORY);
15
14
  } else {
16
15
  // Need something in this file.
17
16
  test('no-op', () => {});
@@ -23,7 +22,7 @@ const BASIC_SYNC_RULES = `bucket_definitions:
23
22
  data:
24
23
  - SELECT id, description, other FROM "test_data"`;
25
24
 
26
- function defineBatchTests(factory: StorageFactory) {
25
+ function defineBatchTests(factory: storage.TestStorageFactory) {
27
26
  test('update large record', async () => {
28
27
  await using context = await WalStreamTestContext.open(factory);
29
28
  // This test generates a large transaction in MongoDB, despite the replicated data
@@ -1,8 +1,9 @@
1
- import { compareIds, putOp, removeOp } from '@core-tests/stream_utils.js';
2
- import { reduceBucket } from '@powersync/service-core';
3
- import { setTimeout } from 'node:timers/promises';
1
+ import { compareIds, putOp, reduceBucket, removeOp, test_utils } from '@powersync/service-core-tests';
2
+ import * as timers from 'timers/promises';
4
3
  import { describe, expect, test } from 'vitest';
5
- import { INITIALIZED_MONGO_STORAGE_FACTORY, StorageFactory } from './util.js';
4
+
5
+ import { storage } from '@powersync/service-core';
6
+ import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
6
7
  import { WalStreamTestContext } from './wal_stream_utils.js';
7
8
 
8
9
  describe('schema changes', { timeout: 20_000 }, function () {
@@ -16,14 +17,14 @@ bucket_definitions:
16
17
  - SELECT id, * FROM "test_data"
17
18
  `;
18
19
 
19
- const PUT_T1 = putOp('test_data', { id: 't1', description: 'test1' });
20
- const PUT_T2 = putOp('test_data', { id: 't2', description: 'test2' });
21
- const PUT_T3 = putOp('test_data', { id: 't3', description: 'test3' });
20
+ const PUT_T1 = test_utils.putOp('test_data', { id: 't1', description: 'test1' });
21
+ const PUT_T2 = test_utils.putOp('test_data', { id: 't2', description: 'test2' });
22
+ const PUT_T3 = test_utils.putOp('test_data', { id: 't3', description: 'test3' });
22
23
 
23
- const REMOVE_T1 = removeOp('test_data', 't1');
24
- const REMOVE_T2 = removeOp('test_data', 't2');
24
+ const REMOVE_T1 = test_utils.removeOp('test_data', 't1');
25
+ const REMOVE_T2 = test_utils.removeOp('test_data', 't2');
25
26
 
26
- function defineTests(factory: StorageFactory) {
27
+ function defineTests(factory: storage.TestStorageFactory) {
27
28
  test('re-create table', async () => {
28
29
  await using context = await WalStreamTestContext.open(factory);
29
30
 
@@ -544,7 +545,7 @@ function defineTests(factory: StorageFactory) {
544
545
  );
545
546
 
546
547
  // Need some delay for the snapshot to be triggered
547
- await setTimeout(5);
548
+ await timers.setTimeout(5);
548
549
 
549
550
  let stop = false;
550
551
 
package/test/src/setup.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { container } from '@powersync/lib-services-framework';
2
+ import { test_utils } from '@powersync/service-core-tests';
2
3
  import { beforeAll } from 'vitest';
3
4
 
4
- beforeAll(() => {
5
+ beforeAll(async () => {
5
6
  // Executes for every test file
6
7
  container.registerDefaults();
8
+ await test_utils.initMetrics();
7
9
  });
@@ -2,30 +2,35 @@ import * as bson from 'bson';
2
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
- import { clearTestDb, connectPgPool, getClientCheckpoint, TEST_CONNECTION_OPTIONS } from './util.js';
5
+ import {
6
+ clearTestDb,
7
+ connectPgPool,
8
+ getClientCheckpoint,
9
+ INITIALIZED_MONGO_STORAGE_FACTORY,
10
+ TEST_CONNECTION_OPTIONS
11
+ } from './util.js';
6
12
 
7
13
  import * as pgwire from '@powersync/service-jpgwire';
8
14
  import { SqliteRow } from '@powersync/service-sync-rules';
9
15
 
10
- import { mapOpEntry, MongoBucketStorage } from '@/storage/storage-index.js';
11
- import { validateCompactedBucket } from '@core-tests/bucket_validation.js';
12
- import { MONGO_STORAGE_FACTORY, StorageFactory } from '@core-tests/util.js';
13
16
  import { PgManager } from '@module/replication/PgManager.js';
17
+ import { storage } from '@powersync/service-core';
18
+ import { test_utils } from '@powersync/service-core-tests';
19
+ import * as mongo_storage from '@powersync/service-module-mongodb-storage';
14
20
  import * as timers from 'node:timers/promises';
15
- import { reduceBucket } from '@powersync/service-core';
16
21
 
17
22
  describe('slow tests - mongodb', function () {
18
23
  // These are slow, inconsistent tests.
19
24
  // Not run on every test run, but we do run on CI, or when manually debugging issues.
20
25
  if (env.CI || env.SLOW_TESTS) {
21
- defineSlowTests(MONGO_STORAGE_FACTORY);
26
+ defineSlowTests(INITIALIZED_MONGO_STORAGE_FACTORY);
22
27
  } else {
23
28
  // Need something in this file.
24
29
  test('no-op', () => {});
25
30
  }
26
31
  });
27
32
 
28
- function defineSlowTests(factory: StorageFactory) {
33
+ function defineSlowTests(factory: storage.TestStorageFactory) {
29
34
  let walStream: WalStream | undefined;
30
35
  let connections: PgManager | undefined;
31
36
  let abortController: AbortController | undefined;
@@ -74,7 +79,7 @@ function defineSlowTests(factory: StorageFactory) {
74
79
  const replicationConnection = await connections.replicationConnection();
75
80
  const pool = connections.pool;
76
81
  await clearTestDb(pool);
77
- const f = (await factory()) as MongoBucketStorage;
82
+ const f = (await factory()) as mongo_storage.storage.MongoBucketStorage;
78
83
 
79
84
  const syncRuleContent = `
80
85
  bucket_definitions:
@@ -171,13 +176,13 @@ bucket_definitions:
171
176
  const checkpoint = BigInt((await storage.getCheckpoint()).checkpoint);
172
177
  const opsBefore = (await f.db.bucket_data.find().sort({ _id: 1 }).toArray())
173
178
  .filter((row) => row._id.o <= checkpoint)
174
- .map(mapOpEntry);
179
+ .map(mongo_storage.storage.mapOpEntry);
175
180
  await storage.compact({ maxOpId: checkpoint });
176
181
  const opsAfter = (await f.db.bucket_data.find().sort({ _id: 1 }).toArray())
177
182
  .filter((row) => row._id.o <= checkpoint)
178
- .map(mapOpEntry);
183
+ .map(mongo_storage.storage.mapOpEntry);
179
184
 
180
- validateCompactedBucket(opsBefore, opsAfter);
185
+ test_utils.validateCompactedBucket(opsBefore, opsAfter);
181
186
  }
182
187
  };
183
188
 
@@ -202,8 +207,8 @@ bucket_definitions:
202
207
  const ops = await f.db.bucket_data.find().sort({ _id: 1 }).toArray();
203
208
 
204
209
  // All a single bucket in this test
205
- const bucket = ops.map((op) => mapOpEntry(op));
206
- const reduced = reduceBucket(bucket);
210
+ const bucket = ops.map((op) => mongo_storage.storage.mapOpEntry(op));
211
+ const reduced = test_utils.reduceBucket(bucket);
207
212
  expect(reduced).toMatchObject([
208
213
  {
209
214
  op_id: '0',
package/test/src/util.ts CHANGED
@@ -1,46 +1,25 @@
1
- import { connectMongo } from '@core-tests/util.js';
1
+ import { PostgresRouteAPIAdapter } from '@module/api/PostgresRouteAPIAdapter.js';
2
2
  import * as types from '@module/types/types.js';
3
3
  import * as pg_utils from '@module/utils/pgwire_utils.js';
4
4
  import { logger } from '@powersync/lib-services-framework';
5
- import { BucketStorageFactory, Metrics, MongoBucketStorage, OpId } from '@powersync/service-core';
5
+ import { BucketStorageFactory, OpId } from '@powersync/service-core';
6
6
  import * as pgwire from '@powersync/service-jpgwire';
7
- import { pgwireRows } from '@powersync/service-jpgwire';
7
+ import * as mongo_storage from '@powersync/service-module-mongodb-storage';
8
8
  import { env } from './env.js';
9
- import { PostgresRouteAPIAdapter } from '@module/api/PostgresRouteAPIAdapter.js';
10
-
11
- // The metrics need to be initialized before they can be used
12
- await Metrics.initialise({
13
- disable_telemetry_sharing: true,
14
- powersync_instance_id: 'test',
15
- internal_metrics_endpoint: 'unused.for.tests.com'
16
- });
17
- Metrics.getInstance().resetCounters();
18
9
 
19
10
  export const TEST_URI = env.PG_TEST_URL;
20
11
 
12
+ export const INITIALIZED_MONGO_STORAGE_FACTORY = mongo_storage.MongoTestStorageFactoryGenerator({
13
+ url: env.MONGO_TEST_URL,
14
+ isCI: env.CI
15
+ });
16
+
21
17
  export const TEST_CONNECTION_OPTIONS = types.normalizeConnectionConfig({
22
18
  type: 'postgresql',
23
19
  uri: TEST_URI,
24
20
  sslmode: 'disable'
25
21
  });
26
22
 
27
- export type StorageFactory = () => Promise<BucketStorageFactory>;
28
-
29
- export const INITIALIZED_MONGO_STORAGE_FACTORY: StorageFactory = async () => {
30
- const db = await connectMongo();
31
-
32
- // None of the PG tests insert data into this collection, so it was never created
33
- if (!(await db.db.listCollections({ name: db.bucket_parameters.collectionName }).hasNext())) {
34
- await db.db.createCollection('bucket_parameters');
35
- }
36
-
37
- await db.clear();
38
-
39
- return new MongoBucketStorage(db, {
40
- slot_name_prefix: 'test_'
41
- });
42
- };
43
-
44
23
  export async function clearTestDb(db: pgwire.PgClient) {
45
24
  await db.query(
46
25
  "select pg_drop_replication_slot(slot_name) from pg_replication_slots where active = false and slot_name like 'test_%'"
@@ -1,10 +1,12 @@
1
- import { MONGO_STORAGE_FACTORY } from '@core-tests/util.js';
2
1
  import { getDebugTablesInfo } from '@module/replication/replication-utils.js';
3
2
  import { expect, test } from 'vitest';
3
+
4
+ // Not quite a walStreamTest, but it helps to manage the connection
5
+ import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
4
6
  import { WalStreamTestContext } from './wal_stream_utils.js';
5
7
 
6
8
  test('validate tables', async () => {
7
- await using context = await WalStreamTestContext.open(MONGO_STORAGE_FACTORY);
9
+ await using context = await WalStreamTestContext.open(INITIALIZED_MONGO_STORAGE_FACTORY);
8
10
  const { pool } = context;
9
11
 
10
12
  await pool.query(`CREATE TABLE test_data(id uuid primary key default uuid_generate_v4(), description text)`);
@@ -1,13 +1,11 @@
1
- import { putOp, removeOp } from '@core-tests/stream_utils.js';
2
- import { MONGO_STORAGE_FACTORY } from '@core-tests/util.js';
3
- import { BucketStorageFactory, Metrics } from '@powersync/service-core';
1
+ import { MissingReplicationSlotError } from '@module/replication/WalStream.js';
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
+ import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
7
8
  import { WalStreamTestContext } from './wal_stream_utils.js';
8
- import { MissingReplicationSlotError } from '@module/replication/WalStream.js';
9
-
10
- type StorageFactory = () => Promise<BucketStorageFactory>;
11
9
 
12
10
  const BASIC_SYNC_RULES = `
13
11
  bucket_definitions:
@@ -17,10 +15,10 @@ bucket_definitions:
17
15
  `;
18
16
 
19
17
  describe('wal stream - mongodb', { timeout: 20_000 }, function () {
20
- defineWalStreamTests(MONGO_STORAGE_FACTORY);
18
+ defineWalStreamTests(INITIALIZED_MONGO_STORAGE_FACTORY);
21
19
  });
22
20
 
23
- function defineWalStreamTests(factory: StorageFactory) {
21
+ function defineWalStreamTests(factory: storage.TestStorageFactory) {
24
22
  test('replicating basic values', async () => {
25
23
  await using context = await WalStreamTestContext.open(factory);
26
24
  const { pool } = context;
@@ -1,10 +1,9 @@
1
- import { fromAsync } from '@core-tests/stream_utils.js';
2
1
  import { PgManager } from '@module/replication/PgManager.js';
3
2
  import { PUBLICATION_NAME, WalStream, WalStreamOptions } from '@module/replication/WalStream.js';
4
- import { BucketStorageFactory, OplogEntry, SyncRulesBucketStorage } from '@powersync/service-core';
3
+ import { BucketStorageFactory, OplogEntry, storage, SyncRulesBucketStorage } from '@powersync/service-core';
4
+ import { test_utils } from '@powersync/service-core-tests';
5
5
  import * as pgwire from '@powersync/service-jpgwire';
6
6
  import { clearTestDb, getClientCheckpoint, TEST_CONNECTION_OPTIONS } from './util.js';
7
- import { StorageOptions } from '@core-tests/util.js';
8
7
 
9
8
  export class WalStreamTestContext implements AsyncDisposable {
10
9
  private _walStream?: WalStream;
@@ -20,7 +19,7 @@ export class WalStreamTestContext implements AsyncDisposable {
20
19
  * This configures all the context, and tears it down afterwards.
21
20
  */
22
21
  static async open(
23
- factory: (options: StorageOptions) => Promise<BucketStorageFactory>,
22
+ factory: (options: storage.TestStorageOptions) => Promise<BucketStorageFactory>,
24
23
  options?: { doNotClear?: boolean }
25
24
  ) {
26
25
  const f = await factory({ doNotClear: options?.doNotClear });
@@ -132,7 +131,7 @@ export class WalStreamTestContext implements AsyncDisposable {
132
131
  async getBucketsDataBatch(buckets: Record<string, string>, options?: { timeout?: number }) {
133
132
  let checkpoint = await this.getCheckpoint(options);
134
133
  const map = new Map<string, string>(Object.entries(buckets));
135
- return fromAsync(this.storage!.getBucketDataBatch(checkpoint, map));
134
+ return test_utils.fromAsync(this.storage!.getBucketDataBatch(checkpoint, map));
136
135
  }
137
136
 
138
137
  /**
@@ -146,7 +145,7 @@ export class WalStreamTestContext implements AsyncDisposable {
146
145
  while (true) {
147
146
  const batch = this.storage!.getBucketDataBatch(checkpoint, map);
148
147
 
149
- const batches = await fromAsync(batch);
148
+ const batches = await test_utils.fromAsync(batch);
150
149
  data = data.concat(batches[0]?.batch.data ?? []);
151
150
  if (batches.length == 0 || !batches[0]!.batch.has_more) {
152
151
  break;
@@ -164,7 +163,7 @@ export class WalStreamTestContext implements AsyncDisposable {
164
163
  const { checkpoint } = await this.storage!.getCheckpoint();
165
164
  const map = new Map<string, string>([[bucket, start]]);
166
165
  const batch = this.storage!.getBucketDataBatch(checkpoint, map);
167
- const batches = await fromAsync(batch);
166
+ const batches = await test_utils.fromAsync(batch);
168
167
  return batches[0]?.batch.data ?? [];
169
168
  }
170
169
  }