@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.
Files changed (32) hide show
  1. package/CHANGELOG.md +18 -17
  2. package/dist/api/MongoRouteAPIAdapter.d.ts +1 -0
  3. package/dist/api/MongoRouteAPIAdapter.js +54 -21
  4. package/dist/api/MongoRouteAPIAdapter.js.map +1 -1
  5. package/dist/replication/ChangeStream.d.ts +23 -2
  6. package/dist/replication/ChangeStream.js +178 -42
  7. package/dist/replication/ChangeStream.js.map +1 -1
  8. package/dist/replication/ChangeStreamReplicationJob.js +7 -4
  9. package/dist/replication/ChangeStreamReplicationJob.js.map +1 -1
  10. package/dist/replication/MongoErrorRateLimiter.js +0 -6
  11. package/dist/replication/MongoErrorRateLimiter.js.map +1 -1
  12. package/dist/replication/MongoRelation.js +5 -2
  13. package/dist/replication/MongoRelation.js.map +1 -1
  14. package/dist/replication/replication-utils.d.ts +1 -0
  15. package/dist/replication/replication-utils.js +1 -0
  16. package/dist/replication/replication-utils.js.map +1 -1
  17. package/dist/types/types.d.ts +35 -0
  18. package/dist/types/types.js +38 -2
  19. package/dist/types/types.js.map +1 -1
  20. package/package.json +6 -9
  21. package/src/api/MongoRouteAPIAdapter.ts +53 -21
  22. package/src/replication/ChangeStream.ts +277 -121
  23. package/src/replication/ChangeStreamReplicationJob.ts +6 -4
  24. package/src/replication/MongoErrorRateLimiter.ts +1 -8
  25. package/src/replication/MongoRelation.ts +5 -2
  26. package/src/replication/replication-utils.ts +2 -1
  27. package/src/types/types.ts +43 -3
  28. package/test/src/change_stream.test.ts +442 -231
  29. package/test/src/change_stream_utils.ts +54 -27
  30. package/test/src/mongo_test.test.ts +180 -46
  31. package/test/src/slow_tests.test.ts +109 -0
  32. package/tsconfig.tsbuildinfo +1 -1
@@ -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