@powersync/service-module-postgres 0.0.0-dev-20250102111825 → 0.0.0-dev-20250108084515
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 +7 -6
- package/package.json +8 -8
- package/test/src/large_batch.test.ts +2 -3
- package/test/src/schema_changes.test.ts +5 -2
- package/test/src/setup.ts +3 -1
- package/test/src/slow_tests.test.ts +14 -8
- package/test/src/util.ts +7 -41
- package/test/src/wal_stream.test.ts +3 -5
- package/test/src/wal_stream_utils.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @powersync/service-module-postgres
|
|
2
2
|
|
|
3
|
-
## 0.0.0-dev-
|
|
3
|
+
## 0.0.0-dev-20250108084515
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
- Updated dependencies [697d44b]
|
|
12
12
|
- Updated dependencies [697d44b]
|
|
13
|
+
- Updated dependencies [48320b5]
|
|
13
14
|
- Updated dependencies [697d44b]
|
|
14
|
-
- @powersync/service-core@0.0.0-dev-
|
|
15
|
-
- @powersync/lib-services-framework@0.0.0-dev-
|
|
16
|
-
- @powersync/service-sync-rules@0.0.0-dev-
|
|
17
|
-
- @powersync/service-types@0.0.0-dev-
|
|
18
|
-
- @powersync/service-jpgwire@0.0.0-dev-
|
|
15
|
+
- @powersync/service-core@0.0.0-dev-20250108084515
|
|
16
|
+
- @powersync/lib-services-framework@0.0.0-dev-20250108084515
|
|
17
|
+
- @powersync/service-sync-rules@0.0.0-dev-20250108084515
|
|
18
|
+
- @powersync/service-types@0.0.0-dev-20250108084515
|
|
19
|
+
- @powersync/service-jpgwire@0.0.0-dev-20250108084515
|
|
19
20
|
|
|
20
21
|
## 0.2.4
|
|
21
22
|
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.0.0-dev-
|
|
8
|
+
"version": "0.0.0-dev-20250108084515",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"license": "FSL-1.1-Apache-2.0",
|
|
11
11
|
"type": "module",
|
|
@@ -27,17 +27,17 @@
|
|
|
27
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.0.0-dev-
|
|
31
|
-
"@powersync/service-core": "0.0.0-dev-
|
|
32
|
-
"@powersync/service-jpgwire": "0.0.0-dev-
|
|
30
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20250108084515",
|
|
31
|
+
"@powersync/service-core": "0.0.0-dev-20250108084515",
|
|
32
|
+
"@powersync/service-jpgwire": "0.0.0-dev-20250108084515",
|
|
33
33
|
"@powersync/service-jsonbig": "0.17.10",
|
|
34
|
-
"@powersync/service-sync-rules": "0.0.0-dev-
|
|
35
|
-
"@powersync/service-types": "0.0.0-dev-
|
|
34
|
+
"@powersync/service-sync-rules": "0.0.0-dev-20250108084515",
|
|
35
|
+
"@powersync/service-types": "0.0.0-dev-20250108084515"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/uuid": "^9.0.4",
|
|
39
|
-
"@powersync/service-core-tests": "0.0.0-dev-
|
|
40
|
-
"@powersync/service-module-mongodb": "0.0.0-dev-
|
|
39
|
+
"@powersync/service-core-tests": "0.0.0-dev-20250108084515",
|
|
40
|
+
"@powersync/service-module-mongodb-storage": "0.0.0-dev-20250108084515"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "tsc -b",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Metrics } from '@powersync/service-core';
|
|
2
|
-
import { test_utils } from '@powersync/service-core-tests';
|
|
1
|
+
import { Metrics, storage } from '@powersync/service-core';
|
|
3
2
|
import * as timers from 'timers/promises';
|
|
4
3
|
import { describe, expect, test } from 'vitest';
|
|
5
4
|
import { populateData } from '../../dist/utils/populate_test_data.js';
|
|
@@ -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:
|
|
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,11 @@
|
|
|
1
1
|
import { compareIds, putOp, reduceBucket, removeOp, test_utils } from '@powersync/service-core-tests';
|
|
2
2
|
import * as timers from 'timers/promises';
|
|
3
3
|
import { describe, expect, test } from 'vitest';
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
import { storage } from '@powersync/service-core';
|
|
6
|
+
import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
|
|
5
7
|
import { WalStreamTestContext } from './wal_stream_utils.js';
|
|
8
|
+
|
|
6
9
|
describe('schema changes', { timeout: 20_000 }, function () {
|
|
7
10
|
defineTests(INITIALIZED_MONGO_STORAGE_FACTORY);
|
|
8
11
|
});
|
|
@@ -21,7 +24,7 @@ const PUT_T3 = test_utils.putOp('test_data', { id: 't3', description: 'test3' })
|
|
|
21
24
|
const REMOVE_T1 = test_utils.removeOp('test_data', 't1');
|
|
22
25
|
const REMOVE_T2 = test_utils.removeOp('test_data', 't2');
|
|
23
26
|
|
|
24
|
-
function defineTests(factory:
|
|
27
|
+
function defineTests(factory: storage.TestStorageFactory) {
|
|
25
28
|
test('re-create table', async () => {
|
|
26
29
|
await using context = await WalStreamTestContext.open(factory);
|
|
27
30
|
|
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,16 +2,22 @@ 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 {
|
|
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
16
|
import { PgManager } from '@module/replication/PgManager.js';
|
|
17
|
+
import { storage } from '@powersync/service-core';
|
|
11
18
|
import { test_utils } from '@powersync/service-core-tests';
|
|
12
|
-
import * as
|
|
19
|
+
import * as mongo_storage from '@powersync/service-module-mongodb-storage';
|
|
13
20
|
import * as timers from 'node:timers/promises';
|
|
14
|
-
import { reduceBucket } from '@powersync/service-core';
|
|
15
21
|
|
|
16
22
|
describe('slow tests - mongodb', function () {
|
|
17
23
|
// These are slow, inconsistent tests.
|
|
@@ -24,7 +30,7 @@ describe('slow tests - mongodb', function () {
|
|
|
24
30
|
}
|
|
25
31
|
});
|
|
26
32
|
|
|
27
|
-
function defineSlowTests(factory:
|
|
33
|
+
function defineSlowTests(factory: storage.TestStorageFactory) {
|
|
28
34
|
let walStream: WalStream | undefined;
|
|
29
35
|
let connections: PgManager | undefined;
|
|
30
36
|
let abortController: AbortController | undefined;
|
|
@@ -73,7 +79,7 @@ function defineSlowTests(factory: test_utils.StorageFactory) {
|
|
|
73
79
|
const replicationConnection = await connections.replicationConnection();
|
|
74
80
|
const pool = connections.pool;
|
|
75
81
|
await clearTestDb(pool);
|
|
76
|
-
const f = (await factory()) as
|
|
82
|
+
const f = (await factory()) as mongo_storage.storage.MongoBucketStorage;
|
|
77
83
|
|
|
78
84
|
const syncRuleContent = `
|
|
79
85
|
bucket_definitions:
|
|
@@ -170,11 +176,11 @@ bucket_definitions:
|
|
|
170
176
|
const checkpoint = BigInt((await storage.getCheckpoint()).checkpoint);
|
|
171
177
|
const opsBefore = (await f.db.bucket_data.find().sort({ _id: 1 }).toArray())
|
|
172
178
|
.filter((row) => row._id.o <= checkpoint)
|
|
173
|
-
.map(
|
|
179
|
+
.map(mongo_storage.storage.mapOpEntry);
|
|
174
180
|
await storage.compact({ maxOpId: checkpoint });
|
|
175
181
|
const opsAfter = (await f.db.bucket_data.find().sort({ _id: 1 }).toArray())
|
|
176
182
|
.filter((row) => row._id.o <= checkpoint)
|
|
177
|
-
.map(
|
|
183
|
+
.map(mongo_storage.storage.mapOpEntry);
|
|
178
184
|
|
|
179
185
|
test_utils.validateCompactedBucket(opsBefore, opsAfter);
|
|
180
186
|
}
|
|
@@ -201,7 +207,7 @@ bucket_definitions:
|
|
|
201
207
|
const ops = await f.db.bucket_data.find().sort({ _id: 1 }).toArray();
|
|
202
208
|
|
|
203
209
|
// All a single bucket in this test
|
|
204
|
-
const bucket = ops.map((op) =>
|
|
210
|
+
const bucket = ops.map((op) => mongo_storage.storage.mapOpEntry(op));
|
|
205
211
|
const reduced = test_utils.reduceBucket(bucket);
|
|
206
212
|
expect(reduced).toMatchObject([
|
|
207
213
|
{
|
package/test/src/util.ts
CHANGED
|
@@ -2,58 +2,24 @@ 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,
|
|
6
|
-
import { test_utils } from '@powersync/service-core-tests';
|
|
5
|
+
import { BucketStorageFactory, OpId } from '@powersync/service-core';
|
|
7
6
|
import * as pgwire from '@powersync/service-jpgwire';
|
|
8
|
-
import * as
|
|
7
|
+
import * as mongo_storage from '@powersync/service-module-mongodb-storage';
|
|
9
8
|
import { env } from './env.js';
|
|
10
9
|
|
|
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
|
-
|
|
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 (options?: test_utils.StorageOptions) => {
|
|
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
|
-
if (!options?.doNotClear) {
|
|
38
|
-
await db.clear();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return new mongo_module.storage.MongoBucketStorage(db, {
|
|
42
|
-
slot_name_prefix: 'test_'
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export async function connectMongo() {
|
|
47
|
-
// Short timeout for tests, to fail fast when the server is not available.
|
|
48
|
-
// Slightly longer timeouts for CI, to avoid arbitrary test failures
|
|
49
|
-
const client = mongo_module.storage.createMongoClient(env.MONGO_TEST_URL, {
|
|
50
|
-
connectTimeoutMS: env.CI ? 15_000 : 5_000,
|
|
51
|
-
socketTimeoutMS: env.CI ? 15_000 : 5_000,
|
|
52
|
-
serverSelectionTimeoutMS: env.CI ? 15_000 : 2_500
|
|
53
|
-
});
|
|
54
|
-
return new mongo_module.storage.PowerSyncMongo(client);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
23
|
export async function clearTestDb(db: pgwire.PgClient) {
|
|
58
24
|
await db.query(
|
|
59
25
|
"select pg_drop_replication_slot(slot_name) from pg_replication_slots where active = false and slot_name like 'test_%'"
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MissingReplicationSlotError } from '@module/replication/WalStream.js';
|
|
2
|
+
import { Metrics, storage } from '@powersync/service-core';
|
|
2
3
|
import { putOp, removeOp } from '@powersync/service-core-tests';
|
|
3
4
|
import { pgwireRows } from '@powersync/service-jpgwire';
|
|
4
5
|
import * as crypto from 'crypto';
|
|
5
6
|
import { describe, expect, test } from 'vitest';
|
|
6
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:
|
|
@@ -20,7 +18,7 @@ describe('wal stream - mongodb', { timeout: 20_000 }, function () {
|
|
|
20
18
|
defineWalStreamTests(INITIALIZED_MONGO_STORAGE_FACTORY);
|
|
21
19
|
});
|
|
22
20
|
|
|
23
|
-
function defineWalStreamTests(factory:
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import { PgManager } from '@module/replication/PgManager.js';
|
|
2
2
|
import { PUBLICATION_NAME, WalStream, WalStreamOptions } from '@module/replication/WalStream.js';
|
|
3
|
-
import { BucketStorageFactory, OplogEntry, SyncRulesBucketStorage } from '@powersync/service-core';
|
|
4
|
-
import {
|
|
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
7
|
|
|
@@ -19,7 +19,7 @@ export class WalStreamTestContext implements AsyncDisposable {
|
|
|
19
19
|
* This configures all the context, and tears it down afterwards.
|
|
20
20
|
*/
|
|
21
21
|
static async open(
|
|
22
|
-
factory: (options:
|
|
22
|
+
factory: (options: storage.TestStorageOptions) => Promise<BucketStorageFactory>,
|
|
23
23
|
options?: { doNotClear?: boolean }
|
|
24
24
|
) {
|
|
25
25
|
const f = await factory({ doNotClear: options?.doNotClear });
|