@powersync/service-module-mongodb 0.0.0-dev-20250102111825 → 0.0.0-dev-20250108073049
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 +8 -5
- package/dist/api/MongoRouteAPIAdapter.d.ts +1 -1
- package/dist/api/MongoRouteAPIAdapter.js +4 -3
- package/dist/api/MongoRouteAPIAdapter.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/module/MongoModule.d.ts +0 -1
- package/dist/module/MongoModule.js +2 -10
- package/dist/module/MongoModule.js.map +1 -1
- package/dist/replication/MongoRelation.js +15 -5
- package/dist/replication/MongoRelation.js.map +1 -1
- package/dist/types/types.d.ts +16 -22
- package/dist/types/types.js +4 -24
- package/dist/types/types.js.map +1 -1
- package/package.json +9 -10
- package/src/api/MongoRouteAPIAdapter.ts +4 -4
- package/src/index.ts +3 -4
- package/src/module/MongoModule.ts +2 -14
- package/src/replication/MongoRelation.ts +13 -5
- package/src/types/types.ts +8 -34
- package/test/src/change_stream.test.ts +2 -4
- package/test/src/env.ts +1 -1
- package/test/src/mongo_test.test.ts +69 -10
- package/test/src/setup.ts +4 -1
- package/test/src/slow_tests.test.ts +5 -12
- package/test/src/util.ts +5 -38
- package/test/tsconfig.json +1 -2
- package/tsconfig.json +6 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/db/db-index.d.ts +0 -1
- package/dist/db/db-index.js +0 -2
- package/dist/db/db-index.js.map +0 -1
- package/dist/db/mongo.d.ts +0 -35
- package/dist/db/mongo.js +0 -73
- package/dist/db/mongo.js.map +0 -1
- package/dist/locks/MongoLockManager.d.ts +0 -25
- package/dist/locks/MongoLockManager.js +0 -79
- package/dist/locks/MongoLockManager.js.map +0 -1
- package/dist/migrations/MongoMigrationAgent.d.ts +0 -12
- package/dist/migrations/MongoMigrationAgent.js +0 -25
- package/dist/migrations/MongoMigrationAgent.js.map +0 -1
- package/dist/migrations/db/migrations/1684951997326-init.d.ts +0 -3
- package/dist/migrations/db/migrations/1684951997326-init.js +0 -30
- package/dist/migrations/db/migrations/1684951997326-init.js.map +0 -1
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.d.ts +0 -2
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js +0 -5
- package/dist/migrations/db/migrations/1688556755264-initial-sync-rules.js.map +0 -1
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.d.ts +0 -3
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js +0 -54
- package/dist/migrations/db/migrations/1702295701188-sync-rule-state.js.map +0 -1
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.d.ts +0 -3
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js +0 -26
- package/dist/migrations/db/migrations/1711543888062-write-checkpoint-index.js.map +0 -1
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.d.ts +0 -3
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js +0 -28
- package/dist/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.js.map +0 -1
- package/dist/migrations/mongo-migration-store.d.ts +0 -7
- package/dist/migrations/mongo-migration-store.js +0 -49
- package/dist/migrations/mongo-migration-store.js.map +0 -1
- package/dist/storage/MongoBucketStorage.d.ts +0 -48
- package/dist/storage/MongoBucketStorage.js +0 -426
- package/dist/storage/MongoBucketStorage.js.map +0 -1
- package/dist/storage/implementation/MongoBucketBatch.d.ts +0 -72
- package/dist/storage/implementation/MongoBucketBatch.js +0 -681
- package/dist/storage/implementation/MongoBucketBatch.js.map +0 -1
- package/dist/storage/implementation/MongoCompactor.d.ts +0 -40
- package/dist/storage/implementation/MongoCompactor.js +0 -300
- package/dist/storage/implementation/MongoCompactor.js.map +0 -1
- package/dist/storage/implementation/MongoIdSequence.d.ts +0 -12
- package/dist/storage/implementation/MongoIdSequence.js +0 -21
- package/dist/storage/implementation/MongoIdSequence.js.map +0 -1
- package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +0 -9
- package/dist/storage/implementation/MongoPersistedSyncRules.js +0 -9
- package/dist/storage/implementation/MongoPersistedSyncRules.js.map +0 -1
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +0 -20
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +0 -26
- package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +0 -1
- package/dist/storage/implementation/MongoStorageProvider.d.ts +0 -6
- package/dist/storage/implementation/MongoStorageProvider.js +0 -34
- package/dist/storage/implementation/MongoStorageProvider.js.map +0 -1
- package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +0 -36
- package/dist/storage/implementation/MongoSyncBucketStorage.js +0 -529
- package/dist/storage/implementation/MongoSyncBucketStorage.js.map +0 -1
- package/dist/storage/implementation/MongoSyncRulesLock.d.ts +0 -16
- package/dist/storage/implementation/MongoSyncRulesLock.js +0 -65
- package/dist/storage/implementation/MongoSyncRulesLock.js.map +0 -1
- package/dist/storage/implementation/MongoWriteCheckpointAPI.d.ts +0 -20
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js +0 -104
- package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +0 -1
- package/dist/storage/implementation/OperationBatch.d.ts +0 -34
- package/dist/storage/implementation/OperationBatch.js +0 -119
- package/dist/storage/implementation/OperationBatch.js.map +0 -1
- package/dist/storage/implementation/PersistedBatch.d.ts +0 -46
- package/dist/storage/implementation/PersistedBatch.js +0 -223
- package/dist/storage/implementation/PersistedBatch.js.map +0 -1
- package/dist/storage/implementation/config.d.ts +0 -19
- package/dist/storage/implementation/config.js +0 -26
- package/dist/storage/implementation/config.js.map +0 -1
- package/dist/storage/implementation/db.d.ts +0 -36
- package/dist/storage/implementation/db.js +0 -47
- package/dist/storage/implementation/db.js.map +0 -1
- package/dist/storage/implementation/models.d.ts +0 -139
- package/dist/storage/implementation/models.js +0 -2
- package/dist/storage/implementation/models.js.map +0 -1
- package/dist/storage/implementation/util.d.ts +0 -41
- package/dist/storage/implementation/util.js +0 -141
- package/dist/storage/implementation/util.js.map +0 -1
- package/dist/storage/storage-index.d.ts +0 -14
- package/dist/storage/storage-index.js +0 -15
- package/dist/storage/storage-index.js.map +0 -1
- package/src/db/db-index.ts +0 -1
- package/src/db/mongo.ts +0 -81
- package/src/locks/MongoLockManager.ts +0 -123
- package/src/migrations/MongoMigrationAgent.ts +0 -39
- package/src/migrations/db/migrations/1684951997326-init.ts +0 -39
- package/src/migrations/db/migrations/1688556755264-initial-sync-rules.ts +0 -5
- package/src/migrations/db/migrations/1702295701188-sync-rule-state.ts +0 -105
- package/src/migrations/db/migrations/1711543888062-write-checkpoint-index.ts +0 -38
- package/src/migrations/db/migrations/1727099539247-custom-write-checkpoint-index.ts +0 -40
- package/src/migrations/mongo-migration-store.ts +0 -62
- package/src/storage/MongoBucketStorage.ts +0 -531
- package/src/storage/implementation/MongoBucketBatch.ts +0 -896
- package/src/storage/implementation/MongoCompactor.ts +0 -381
- package/src/storage/implementation/MongoIdSequence.ts +0 -24
- package/src/storage/implementation/MongoPersistedSyncRules.ts +0 -16
- package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +0 -49
- package/src/storage/implementation/MongoStorageProvider.ts +0 -42
- package/src/storage/implementation/MongoSyncBucketStorage.ts +0 -612
- package/src/storage/implementation/MongoSyncRulesLock.ts +0 -88
- package/src/storage/implementation/MongoWriteCheckpointAPI.ts +0 -146
- package/src/storage/implementation/OperationBatch.ts +0 -129
- package/src/storage/implementation/PersistedBatch.ts +0 -283
- package/src/storage/implementation/config.ts +0 -40
- package/src/storage/implementation/db.ts +0 -87
- package/src/storage/implementation/models.ts +0 -161
- package/src/storage/implementation/util.ts +0 -154
- package/src/storage/storage-index.ts +0 -14
- package/test/src/__snapshots__/storage_sync.test.ts.snap +0 -332
- package/test/src/storage.test.ts +0 -7
- package/test/src/storage_compacting.test.ts +0 -6
- package/test/src/storage_sync.test.ts +0 -113
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test_utils } from '@powersync/service-core-tests';
|
|
2
2
|
|
|
3
3
|
import { PostImagesOption } from '@module/types/types.js';
|
|
4
|
-
import {
|
|
4
|
+
import { storage } from '@powersync/service-core';
|
|
5
5
|
import * as crypto from 'crypto';
|
|
6
6
|
import * as mongo from 'mongodb';
|
|
7
7
|
import { setTimeout } from 'node:timers/promises';
|
|
@@ -9,8 +9,6 @@ import { describe, expect, test, vi } from 'vitest';
|
|
|
9
9
|
import { ChangeStreamTestContext } from './change_stream_utils.js';
|
|
10
10
|
import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
|
|
11
11
|
|
|
12
|
-
type StorageFactory = () => Promise<BucketStorageFactory>;
|
|
13
|
-
|
|
14
12
|
const BASIC_SYNC_RULES = `
|
|
15
13
|
bucket_definitions:
|
|
16
14
|
global:
|
|
@@ -22,7 +20,7 @@ describe('change stream - mongodb', { timeout: 20_000 }, function () {
|
|
|
22
20
|
defineChangeStreamTests(INITIALIZED_MONGO_STORAGE_FACTORY);
|
|
23
21
|
});
|
|
24
22
|
|
|
25
|
-
function defineChangeStreamTests(factory:
|
|
23
|
+
function defineChangeStreamTests(factory: storage.TestStorageFactory) {
|
|
26
24
|
test('replicating basic values', async () => {
|
|
27
25
|
await using context = await ChangeStreamTestContext.open(factory);
|
|
28
26
|
const { db } = context;
|
package/test/src/env.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { utils } from '@powersync/lib-services-framework';
|
|
2
2
|
|
|
3
3
|
export const env = utils.collectEnvironmentVariables({
|
|
4
|
-
MONGO_TEST_DATA_URL: utils.type.string.default('mongodb://localhost:27017/powersync_test_data'),
|
|
5
4
|
MONGO_TEST_URL: utils.type.string.default('mongodb://localhost:27017/powersync_test'),
|
|
5
|
+
MONGO_TEST_DATA_URL: utils.type.string.default('mongodb://localhost:27017/powersync_test_data'),
|
|
6
6
|
CI: utils.type.boolean.default('false'),
|
|
7
7
|
SLOW_TESTS: utils.type.boolean.default('false')
|
|
8
8
|
});
|
|
@@ -45,12 +45,52 @@ describe('mongo data types', () => {
|
|
|
45
45
|
mongo.ObjectId.createFromHexString('66e834cc91d805df11fa0ecb'),
|
|
46
46
|
'mydb',
|
|
47
47
|
{ foo: 'bar' }
|
|
48
|
-
)
|
|
49
|
-
undefined: undefined
|
|
48
|
+
)
|
|
50
49
|
}
|
|
51
50
|
]);
|
|
52
51
|
}
|
|
53
52
|
|
|
53
|
+
async function insertUndefined(db: mongo.Db, collection: string, array?: boolean) {
|
|
54
|
+
// MongoDB has deprecated the `undefined` value, making it really
|
|
55
|
+
// difficult to insert one into the database.
|
|
56
|
+
// mapReduce is also deprecated, but it's one way to still generate
|
|
57
|
+
// the value.
|
|
58
|
+
const mapInput = db.collection('map_input');
|
|
59
|
+
await mapInput.insertOne({ test: 'test' });
|
|
60
|
+
const fin = array ? `return { result: [undefined] }` : `return { result: undefined }`;
|
|
61
|
+
await db.command({
|
|
62
|
+
mapReduce: 'map_input',
|
|
63
|
+
map: new mongo.Code(`function () {
|
|
64
|
+
// We only need to emit once for a single result:
|
|
65
|
+
emit(5, {});
|
|
66
|
+
}`),
|
|
67
|
+
reduce: new mongo.Code(`function (key, values) {
|
|
68
|
+
// Return an object whose property is explicitly set to undefined
|
|
69
|
+
return undefined;
|
|
70
|
+
}`),
|
|
71
|
+
finalize: new mongo.Code(`function (key, reducedVal) {
|
|
72
|
+
${fin};
|
|
73
|
+
}`),
|
|
74
|
+
out: { merge: 'map_output' }
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await db
|
|
78
|
+
.collection('map_output')
|
|
79
|
+
.aggregate([
|
|
80
|
+
{ $set: { undefined: '$value.result' } },
|
|
81
|
+
{ $project: { undefined: 1 } },
|
|
82
|
+
{
|
|
83
|
+
$merge: {
|
|
84
|
+
into: collection
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
])
|
|
88
|
+
.toArray();
|
|
89
|
+
|
|
90
|
+
await mapInput.drop();
|
|
91
|
+
await db.collection('map_output').drop();
|
|
92
|
+
}
|
|
93
|
+
|
|
54
94
|
async function insertNested(collection: mongo.Collection) {
|
|
55
95
|
await collection.insertMany([
|
|
56
96
|
{
|
|
@@ -118,9 +158,11 @@ describe('mongo data types', () => {
|
|
|
118
158
|
js: '{"code":"testcode","scope":null}',
|
|
119
159
|
js2: '{"code":"testcode","scope":{"foo":"bar"}}',
|
|
120
160
|
pointer: '{"collection":"mycollection","oid":"66e834cc91d805df11fa0ecb","fields":{}}',
|
|
121
|
-
pointer2: '{"collection":"mycollection","oid":"66e834cc91d805df11fa0ecb","db":"mydb","fields":{"foo":"bar"}}'
|
|
122
|
-
undefined: null
|
|
161
|
+
pointer2: '{"collection":"mycollection","oid":"66e834cc91d805df11fa0ecb","db":"mydb","fields":{"foo":"bar"}}'
|
|
123
162
|
});
|
|
163
|
+
|
|
164
|
+
// This must specifically be null, and not undefined.
|
|
165
|
+
expect(transformed[4].undefined).toBeNull();
|
|
124
166
|
}
|
|
125
167
|
|
|
126
168
|
function checkResultsNested(transformed: Record<string, any>[]) {
|
|
@@ -158,20 +200,27 @@ describe('mongo data types', () => {
|
|
|
158
200
|
js: '[{"code":"testcode","scope":null}]',
|
|
159
201
|
pointer: '[{"collection":"mycollection","oid":"66e834cc91d805df11fa0ecb","fields":{}}]',
|
|
160
202
|
minKey: '[null]',
|
|
161
|
-
maxKey: '[null]'
|
|
203
|
+
maxKey: '[null]'
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
expect(transformed[4]).toMatchObject({
|
|
162
207
|
undefined: '[null]'
|
|
163
208
|
});
|
|
164
209
|
}
|
|
165
210
|
|
|
166
211
|
test('test direct queries', async () => {
|
|
167
212
|
const { db, client } = await connectMongoData();
|
|
213
|
+
|
|
168
214
|
const collection = db.collection('test_data');
|
|
169
215
|
try {
|
|
170
216
|
await setupTable(db);
|
|
171
|
-
|
|
172
217
|
await insert(collection);
|
|
218
|
+
await insertUndefined(db, 'test_data');
|
|
173
219
|
|
|
174
|
-
const
|
|
220
|
+
const rawResults = await db.collection('test_data').find().toArray();
|
|
221
|
+
// It is tricky to save "undefined" with mongo, so we check that it succeeded.
|
|
222
|
+
expect(rawResults[4].undefined).toBeUndefined();
|
|
223
|
+
const transformed = [...ChangeStream.getQueryData(rawResults)];
|
|
175
224
|
|
|
176
225
|
checkResults(transformed);
|
|
177
226
|
} finally {
|
|
@@ -186,8 +235,11 @@ describe('mongo data types', () => {
|
|
|
186
235
|
await setupTable(db);
|
|
187
236
|
|
|
188
237
|
await insertNested(collection);
|
|
238
|
+
await insertUndefined(db, 'test_data_arrays', true);
|
|
189
239
|
|
|
190
|
-
const
|
|
240
|
+
const rawResults = await db.collection('test_data_arrays').find().toArray();
|
|
241
|
+
expect(rawResults[4].undefined).toEqual([undefined]);
|
|
242
|
+
const transformed = [...ChangeStream.getQueryData(rawResults)];
|
|
191
243
|
|
|
192
244
|
checkResultsNested(transformed);
|
|
193
245
|
} finally {
|
|
@@ -212,8 +264,9 @@ describe('mongo data types', () => {
|
|
|
212
264
|
await stream.tryNext();
|
|
213
265
|
|
|
214
266
|
await insert(collection);
|
|
267
|
+
await insertUndefined(db, 'test_data');
|
|
215
268
|
|
|
216
|
-
const transformed = await getReplicationTx(stream,
|
|
269
|
+
const transformed = await getReplicationTx(stream, 5);
|
|
217
270
|
|
|
218
271
|
checkResults(transformed);
|
|
219
272
|
} finally {
|
|
@@ -236,8 +289,9 @@ describe('mongo data types', () => {
|
|
|
236
289
|
await stream.tryNext();
|
|
237
290
|
|
|
238
291
|
await insertNested(collection);
|
|
292
|
+
await insertUndefined(db, 'test_data_arrays', true);
|
|
239
293
|
|
|
240
|
-
const transformed = await getReplicationTx(stream,
|
|
294
|
+
const transformed = await getReplicationTx(stream, 5);
|
|
241
295
|
|
|
242
296
|
checkResultsNested(transformed);
|
|
243
297
|
} finally {
|
|
@@ -256,6 +310,7 @@ describe('mongo data types', () => {
|
|
|
256
310
|
const collection = db.collection('test_data');
|
|
257
311
|
await setupTable(db);
|
|
258
312
|
await insert(collection);
|
|
313
|
+
await insertUndefined(db, 'test_data');
|
|
259
314
|
|
|
260
315
|
const schema = await adapter.getConnectionSchema();
|
|
261
316
|
const dbSchema = schema.filter((s) => s.name == TEST_CONNECTION_OPTIONS.database)[0];
|
|
@@ -440,6 +495,10 @@ bucket_definitions:
|
|
|
440
495
|
async function getReplicationTx(replicationStream: mongo.ChangeStream, count: number) {
|
|
441
496
|
let transformed: SqliteRow[] = [];
|
|
442
497
|
for await (const doc of replicationStream) {
|
|
498
|
+
// Specifically filter out map_input / map_output collections
|
|
499
|
+
if (!(doc as any)?.ns?.coll?.startsWith('test_data')) {
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
443
502
|
transformed.push(constructAfterRecord((doc as any).fullDocument));
|
|
444
503
|
if (transformed.length == count) {
|
|
445
504
|
break;
|
package/test/src/setup.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
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
|
+
|
|
9
|
+
await test_utils.initMetrics();
|
|
7
10
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { storage } from '@powersync/service-core';
|
|
2
2
|
import * as mongo from 'mongodb';
|
|
3
3
|
import { setTimeout } from 'node:timers/promises';
|
|
4
4
|
import { describe, expect, test } from 'vitest';
|
|
@@ -6,15 +6,6 @@ import { ChangeStreamTestContext, setSnapshotHistorySeconds } from './change_str
|
|
|
6
6
|
import { env } from './env.js';
|
|
7
7
|
import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
|
|
8
8
|
|
|
9
|
-
type StorageFactory = () => Promise<BucketStorageFactory>;
|
|
10
|
-
|
|
11
|
-
const BASIC_SYNC_RULES = `
|
|
12
|
-
bucket_definitions:
|
|
13
|
-
global:
|
|
14
|
-
data:
|
|
15
|
-
- SELECT _id as id, description FROM "test_data"
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
9
|
describe('change stream slow tests - mongodb', { timeout: 60_000 }, function () {
|
|
19
10
|
if (env.CI || env.SLOW_TESTS) {
|
|
20
11
|
defineSlowTests(INITIALIZED_MONGO_STORAGE_FACTORY);
|
|
@@ -24,7 +15,7 @@ describe('change stream slow tests - mongodb', { timeout: 60_000 }, function ()
|
|
|
24
15
|
}
|
|
25
16
|
});
|
|
26
17
|
|
|
27
|
-
function defineSlowTests(factory:
|
|
18
|
+
function defineSlowTests(factory: storage.TestStorageFactory) {
|
|
28
19
|
test('replicating snapshot with lots of data', async () => {
|
|
29
20
|
await using context = await ChangeStreamTestContext.open(factory);
|
|
30
21
|
// Test with low minSnapshotHistoryWindowInSeconds, to trigger:
|
|
@@ -97,7 +88,9 @@ bucket_definitions:
|
|
|
97
88
|
const data = await context.getBucketData('global[]', undefined, { limit: 50_000, chunkLimitBytes: 60_000_000 });
|
|
98
89
|
|
|
99
90
|
const preDocuments = data.filter((d: any) => JSON.parse(d.data! as string).description.startsWith('pre')).length;
|
|
100
|
-
const updatedDocuments = data.filter((d: any) =>
|
|
91
|
+
const updatedDocuments = data.filter((d: any) =>
|
|
92
|
+
JSON.parse(d.data! as string).description.startsWith('updated')
|
|
93
|
+
).length;
|
|
101
94
|
|
|
102
95
|
// If the test works properly, preDocuments should be around 2000-3000.
|
|
103
96
|
// The total should be around 9000-9900.
|
package/test/src/util.ts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import * as types from '@module/types/types.js';
|
|
2
|
-
import { BucketStorageFactory, Metrics } from '@powersync/service-core';
|
|
3
2
|
|
|
4
|
-
import
|
|
5
|
-
import { PowerSyncMongo } from '@module/storage/storage-index.js';
|
|
6
|
-
import { test_utils } from '@powersync/service-core-tests';
|
|
3
|
+
import * as mongo_storage from '@powersync/service-module-mongodb-storage';
|
|
7
4
|
import * as mongo from 'mongodb';
|
|
8
5
|
import { env } from './env.js';
|
|
9
6
|
|
|
10
|
-
// The metrics need to be initialized before they can be used
|
|
11
|
-
await Metrics.initialise({
|
|
12
|
-
disable_telemetry_sharing: true,
|
|
13
|
-
powersync_instance_id: 'test',
|
|
14
|
-
internal_metrics_endpoint: 'unused.for.tests.com'
|
|
15
|
-
});
|
|
16
|
-
Metrics.getInstance().resetCounters();
|
|
17
|
-
|
|
18
7
|
export const TEST_URI = env.MONGO_TEST_DATA_URL;
|
|
19
8
|
|
|
20
9
|
export const TEST_CONNECTION_OPTIONS = types.normalizeConnectionConfig({
|
|
@@ -22,21 +11,10 @@ export const TEST_CONNECTION_OPTIONS = types.normalizeConnectionConfig({
|
|
|
22
11
|
uri: TEST_URI
|
|
23
12
|
});
|
|
24
13
|
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// None of the PG tests insert data into this collection, so it was never created
|
|
31
|
-
if (!(await db.db.listCollections({ name: db.bucket_parameters.collectionName }).hasNext())) {
|
|
32
|
-
await db.db.createCollection('bucket_parameters');
|
|
33
|
-
}
|
|
34
|
-
if (!options?.doNotClear) {
|
|
35
|
-
await db.clear();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return new MongoBucketStorage(db, { slot_name_prefix: 'test_' });
|
|
39
|
-
};
|
|
14
|
+
export const INITIALIZED_MONGO_STORAGE_FACTORY = mongo_storage.MongoTestStorageFactoryGenerator({
|
|
15
|
+
url: env.MONGO_TEST_URL,
|
|
16
|
+
isCI: env.CI
|
|
17
|
+
});
|
|
40
18
|
|
|
41
19
|
export async function clearTestDb(db: mongo.Db) {
|
|
42
20
|
await db.dropDatabase();
|
|
@@ -52,14 +30,3 @@ export async function connectMongoData() {
|
|
|
52
30
|
const dbname = new URL(env.MONGO_TEST_DATA_URL).pathname.substring(1);
|
|
53
31
|
return { client, db: client.db(dbname) };
|
|
54
32
|
}
|
|
55
|
-
|
|
56
|
-
export async function connectMongo() {
|
|
57
|
-
// Short timeout for tests, to fail fast when the server is not available.
|
|
58
|
-
// Slightly longer timeouts for CI, to avoid arbitrary test failures
|
|
59
|
-
const client = new mongo.MongoClient(env.MONGO_TEST_URL, {
|
|
60
|
-
connectTimeoutMS: env.CI ? 15_000 : 5_000,
|
|
61
|
-
socketTimeoutMS: env.CI ? 15_000 : 5_000,
|
|
62
|
-
serverSelectionTimeoutMS: env.CI ? 15_000 : 2_500
|
|
63
|
-
});
|
|
64
|
-
return new PowerSyncMongo(client);
|
|
65
|
-
}
|
package/test/tsconfig.json
CHANGED