@powersync/service-module-mongodb 0.0.0-dev-20241111122558 → 0.1.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 +18 -17
- package/dist/api/MongoRouteAPIAdapter.d.ts +1 -0
- package/dist/api/MongoRouteAPIAdapter.js +54 -21
- package/dist/api/MongoRouteAPIAdapter.js.map +1 -1
- package/dist/replication/ChangeStream.d.ts +23 -2
- package/dist/replication/ChangeStream.js +178 -42
- package/dist/replication/ChangeStream.js.map +1 -1
- package/dist/replication/ChangeStreamReplicationJob.js +7 -4
- package/dist/replication/ChangeStreamReplicationJob.js.map +1 -1
- package/dist/replication/MongoErrorRateLimiter.js +0 -6
- package/dist/replication/MongoErrorRateLimiter.js.map +1 -1
- package/dist/replication/MongoRelation.js +5 -2
- package/dist/replication/MongoRelation.js.map +1 -1
- package/dist/replication/replication-utils.d.ts +1 -0
- package/dist/replication/replication-utils.js +1 -0
- package/dist/replication/replication-utils.js.map +1 -1
- package/dist/types/types.d.ts +35 -0
- package/dist/types/types.js +38 -2
- package/dist/types/types.js.map +1 -1
- package/package.json +6 -9
- package/src/api/MongoRouteAPIAdapter.ts +53 -21
- package/src/replication/ChangeStream.ts +277 -121
- package/src/replication/ChangeStreamReplicationJob.ts +6 -4
- package/src/replication/MongoErrorRateLimiter.ts +1 -8
- package/src/replication/MongoRelation.ts +5 -2
- package/src/replication/replication-utils.ts +2 -1
- package/src/types/types.ts +43 -3
- package/test/src/change_stream.test.ts +442 -231
- package/test/src/change_stream_utils.ts +54 -27
- package/test/src/mongo_test.test.ts +180 -46
- package/test/src/slow_tests.test.ts +109 -0
- package/tsconfig.tsbuildinfo +1 -1
package/src/types/types.ts
CHANGED
|
@@ -4,6 +4,42 @@ import * as t from 'ts-codec';
|
|
|
4
4
|
|
|
5
5
|
export const MONGO_CONNECTION_TYPE = 'mongodb' as const;
|
|
6
6
|
|
|
7
|
+
export enum PostImagesOption {
|
|
8
|
+
/**
|
|
9
|
+
* Use fullDocument: updateLookup on the changeStream.
|
|
10
|
+
*
|
|
11
|
+
* This does not guarantee consistency - operations may
|
|
12
|
+
* arrive out of order, especially when there is replication lag.
|
|
13
|
+
*
|
|
14
|
+
* This is the default option for backwards-compatability.
|
|
15
|
+
*/
|
|
16
|
+
OFF = 'off',
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Use fullDocument: required on the changeStream.
|
|
20
|
+
*
|
|
21
|
+
* Collections are automatically configured with:
|
|
22
|
+
* `changeStreamPreAndPostImages: { enabled: true }`
|
|
23
|
+
*
|
|
24
|
+
* This is the recommended behavior for new instances.
|
|
25
|
+
*/
|
|
26
|
+
AUTO_CONFIGURE = 'auto_configure',
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* Use fullDocument: required on the changeStream.
|
|
31
|
+
*
|
|
32
|
+
* Collections are not automatically configured. Each
|
|
33
|
+
* collection must be configured configured manually before
|
|
34
|
+
* replicating with:
|
|
35
|
+
*
|
|
36
|
+
* `changeStreamPreAndPostImages: { enabled: true }`
|
|
37
|
+
*
|
|
38
|
+
* Use when the collMod permission is not available.
|
|
39
|
+
*/
|
|
40
|
+
READ_ONLY = 'read_only'
|
|
41
|
+
}
|
|
42
|
+
|
|
7
43
|
export interface NormalizedMongoConnectionConfig {
|
|
8
44
|
id: string;
|
|
9
45
|
tag: string;
|
|
@@ -13,6 +49,8 @@ export interface NormalizedMongoConnectionConfig {
|
|
|
13
49
|
|
|
14
50
|
username?: string;
|
|
15
51
|
password?: string;
|
|
52
|
+
|
|
53
|
+
postImages: PostImagesOption;
|
|
16
54
|
}
|
|
17
55
|
|
|
18
56
|
export const MongoConnectionConfig = service_types.configFile.DataSourceConfig.and(
|
|
@@ -25,7 +63,9 @@ export const MongoConnectionConfig = service_types.configFile.DataSourceConfig.a
|
|
|
25
63
|
uri: t.string,
|
|
26
64
|
username: t.string.optional(),
|
|
27
65
|
password: t.string.optional(),
|
|
28
|
-
database: t.string.optional()
|
|
66
|
+
database: t.string.optional(),
|
|
67
|
+
|
|
68
|
+
post_images: t.literal('off').or(t.literal('auto_configure')).or(t.literal('read_only')).optional()
|
|
29
69
|
})
|
|
30
70
|
);
|
|
31
71
|
|
|
@@ -48,10 +88,10 @@ export function normalizeConnectionConfig(options: MongoConnectionConfig): Norma
|
|
|
48
88
|
const base = normalizeMongoConfig(options);
|
|
49
89
|
|
|
50
90
|
return {
|
|
91
|
+
...base,
|
|
51
92
|
id: options.id ?? 'default',
|
|
52
93
|
tag: options.tag ?? 'default',
|
|
53
|
-
|
|
54
|
-
...base
|
|
94
|
+
postImages: (options.post_images as PostImagesOption | undefined) ?? PostImagesOption.OFF
|
|
55
95
|
};
|
|
56
96
|
}
|
|
57
97
|
|