@powersync/service-module-mongodb-storage 0.0.0-dev-20260602073133 → 0.0.0-dev-20260909133214

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 (275) hide show
  1. package/CHANGELOG.md +177 -5
  2. package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.d.ts +3 -0
  3. package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.js +41 -0
  4. package/dist/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.js.map +1 -0
  5. package/dist/storage/MongoBucketStorage.d.ts +71 -18
  6. package/dist/storage/MongoBucketStorage.js +516 -202
  7. package/dist/storage/MongoBucketStorage.js.map +1 -1
  8. package/dist/storage/implementation/MongoBucketBatch.d.ts +71 -29
  9. package/dist/storage/implementation/MongoBucketBatch.js +140 -66
  10. package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
  11. package/dist/storage/implementation/MongoChecksums.d.ts +41 -13
  12. package/dist/storage/implementation/MongoChecksums.js +36 -121
  13. package/dist/storage/implementation/MongoChecksums.js.map +1 -1
  14. package/dist/storage/implementation/MongoCompactor.d.ts +28 -90
  15. package/dist/storage/implementation/MongoCompactor.js +87 -481
  16. package/dist/storage/implementation/MongoCompactor.js.map +1 -1
  17. package/dist/storage/implementation/MongoHydrationState.d.ts +11 -0
  18. package/dist/storage/implementation/MongoHydrationState.js +49 -0
  19. package/dist/storage/implementation/MongoHydrationState.js.map +1 -0
  20. package/dist/storage/implementation/MongoParameterCompactor.d.ts +82 -8
  21. package/dist/storage/implementation/MongoParameterCompactor.js +312 -76
  22. package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
  23. package/dist/storage/implementation/MongoParsedSyncConfigSet.d.ts +21 -0
  24. package/dist/storage/implementation/MongoParsedSyncConfigSet.js +93 -0
  25. package/dist/storage/implementation/MongoParsedSyncConfigSet.js.map +1 -0
  26. package/dist/storage/implementation/MongoPersistedReplicationStream.d.ts +36 -0
  27. package/dist/storage/implementation/MongoPersistedReplicationStream.js +90 -0
  28. package/dist/storage/implementation/MongoPersistedReplicationStream.js.map +1 -0
  29. package/dist/storage/implementation/MongoPersistedSyncConfigContent.d.ts +25 -0
  30. package/dist/storage/implementation/MongoPersistedSyncConfigContent.js +125 -0
  31. package/dist/storage/implementation/MongoPersistedSyncConfigContent.js.map +1 -0
  32. package/dist/storage/implementation/MongoStorageProvider.js +41 -4
  33. package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
  34. package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +81 -37
  35. package/dist/storage/implementation/MongoSyncBucketStorage.js +159 -86
  36. package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
  37. package/dist/storage/implementation/MongoSyncRulesLock.d.ts +1 -1
  38. package/dist/storage/implementation/MongoSyncRulesLock.js +23 -11
  39. package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
  40. package/dist/storage/implementation/MongoWriteCheckpointAPI.d.ts +11 -8
  41. package/dist/storage/implementation/MongoWriteCheckpointAPI.js +159 -33
  42. package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
  43. package/dist/storage/implementation/SyncRuleStateUpdate.d.ts +11 -5
  44. package/dist/storage/implementation/SyncRuleStateUpdate.js +14 -6
  45. package/dist/storage/implementation/SyncRuleStateUpdate.js.map +1 -1
  46. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.d.ts +28 -0
  47. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js +2 -0
  48. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js.map +1 -0
  49. package/dist/storage/implementation/common/PersistedBatch.d.ts +34 -2
  50. package/dist/storage/implementation/common/PersistedBatch.js +63 -10
  51. package/dist/storage/implementation/common/PersistedBatch.js.map +1 -1
  52. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +1 -1
  53. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -1
  54. package/dist/storage/implementation/createMongoSyncBucketStorage.d.ts +2 -2
  55. package/dist/storage/implementation/createMongoSyncBucketStorage.js +4 -4
  56. package/dist/storage/implementation/createMongoSyncBucketStorage.js.map +1 -1
  57. package/dist/storage/implementation/db.d.ts +4 -1
  58. package/dist/storage/implementation/db.js +31 -16
  59. package/dist/storage/implementation/db.js.map +1 -1
  60. package/dist/storage/implementation/models.d.ts +55 -13
  61. package/dist/storage/implementation/models.js.map +1 -1
  62. package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +15 -1
  63. package/dist/storage/implementation/v1/MongoBucketBatchV1.js +135 -107
  64. package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -1
  65. package/dist/storage/implementation/v1/MongoChecksumsV1.d.ts +4 -4
  66. package/dist/storage/implementation/v1/MongoChecksumsV1.js +119 -7
  67. package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -1
  68. package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +47 -7
  69. package/dist/storage/implementation/v1/MongoCompactorV1.js +478 -8
  70. package/dist/storage/implementation/v1/MongoCompactorV1.js.map +1 -1
  71. package/dist/storage/implementation/v1/MongoParameterCompactorV1.d.ts +16 -2
  72. package/dist/storage/implementation/v1/MongoParameterCompactorV1.js +20 -9
  73. package/dist/storage/implementation/v1/MongoParameterCompactorV1.js.map +1 -1
  74. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +33 -27
  75. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +146 -73
  76. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -1
  77. package/dist/storage/implementation/v1/SingleBucketStoreV1.d.ts +9 -10
  78. package/dist/storage/implementation/v1/SingleBucketStoreV1.js +2 -8
  79. package/dist/storage/implementation/v1/SingleBucketStoreV1.js.map +1 -1
  80. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.d.ts +2 -1
  81. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js +3 -0
  82. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js.map +1 -1
  83. package/dist/storage/implementation/v1/models.d.ts +10 -1
  84. package/dist/storage/implementation/v1/models.js +1 -0
  85. package/dist/storage/implementation/v1/models.js.map +1 -1
  86. package/dist/storage/implementation/v3/BucketDataContextV3.d.ts +13 -0
  87. package/dist/storage/implementation/v3/BucketDataContextV3.js +23 -0
  88. package/dist/storage/implementation/v3/BucketDataContextV3.js.map +1 -0
  89. package/dist/storage/implementation/v3/CompactionLease.d.ts +50 -0
  90. package/dist/storage/implementation/v3/CompactionLease.js +131 -0
  91. package/dist/storage/implementation/v3/CompactionLease.js.map +1 -0
  92. package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +16 -5
  93. package/dist/storage/implementation/v3/MongoBucketBatchV3.js +393 -262
  94. package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
  95. package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +30 -9
  96. package/dist/storage/implementation/v3/MongoChecksumsV3.js +161 -20
  97. package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -1
  98. package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +108 -18
  99. package/dist/storage/implementation/v3/MongoCompactorV3.js +1115 -47
  100. package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
  101. package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +12 -3
  102. package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +13 -8
  103. package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +1 -1
  104. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.d.ts +54 -0
  105. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js +319 -0
  106. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js.map +1 -0
  107. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +61 -36
  108. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +353 -161
  109. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -1
  110. package/dist/storage/implementation/v3/MongoWriteCheckpointAPIV3.d.ts +26 -0
  111. package/dist/storage/implementation/v3/MongoWriteCheckpointAPIV3.js +82 -0
  112. package/dist/storage/implementation/v3/MongoWriteCheckpointAPIV3.js.map +1 -0
  113. package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +8 -3
  114. package/dist/storage/implementation/v3/PersistedBatchV3.js +131 -29
  115. package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -1
  116. package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +3 -3
  117. package/dist/storage/implementation/v3/SourceRecordStoreV3.js +13 -11
  118. package/dist/storage/implementation/v3/SourceRecordStoreV3.js.map +1 -1
  119. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +26 -14
  120. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +73 -29
  121. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -1
  122. package/dist/storage/implementation/v3/bucket-format.d.ts +13 -0
  123. package/dist/storage/implementation/v3/bucket-format.js +79 -0
  124. package/dist/storage/implementation/v3/bucket-format.js.map +1 -0
  125. package/dist/storage/implementation/v3/chunking.d.ts +10 -0
  126. package/dist/storage/implementation/v3/chunking.js +30 -0
  127. package/dist/storage/implementation/v3/chunking.js.map +1 -0
  128. package/dist/storage/implementation/v3/compact-utils.d.ts +107 -0
  129. package/dist/storage/implementation/v3/compact-utils.js +216 -0
  130. package/dist/storage/implementation/v3/compact-utils.js.map +1 -0
  131. package/dist/storage/implementation/v3/compaction-constants.d.ts +5 -0
  132. package/dist/storage/implementation/v3/compaction-constants.js +6 -0
  133. package/dist/storage/implementation/v3/compaction-constants.js.map +1 -0
  134. package/dist/storage/implementation/v3/models.d.ts +187 -23
  135. package/dist/storage/implementation/v3/models.js +11 -28
  136. package/dist/storage/implementation/v3/models.js.map +1 -1
  137. package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.d.ts +20 -0
  138. package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js +48 -0
  139. package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js.map +1 -0
  140. package/dist/storage/implementation/v3/object-storage/ObjectStorage.d.ts +33 -0
  141. package/dist/storage/implementation/v3/object-storage/ObjectStorage.js +12 -0
  142. package/dist/storage/implementation/v3/object-storage/ObjectStorage.js.map +1 -0
  143. package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.d.ts +68 -0
  144. package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js +154 -0
  145. package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js.map +1 -0
  146. package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.d.ts +37 -0
  147. package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.js +167 -0
  148. package/dist/storage/implementation/v3/object-storage/ObjectStorageUsage.js.map +1 -0
  149. package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.d.ts +67 -0
  150. package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js +439 -0
  151. package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js.map +1 -0
  152. package/dist/storage/implementation/v3/source-table-utils.d.ts +63 -0
  153. package/dist/storage/implementation/v3/source-table-utils.js +206 -0
  154. package/dist/storage/implementation/v3/source-table-utils.js.map +1 -0
  155. package/dist/storage/storage-index.d.ts +5 -4
  156. package/dist/storage/storage-index.js +5 -4
  157. package/dist/storage/storage-index.js.map +1 -1
  158. package/dist/types/types.d.ts +71 -3
  159. package/dist/types/types.js +58 -2
  160. package/dist/types/types.js.map +1 -1
  161. package/dist/utils/test-utils.d.ts +1 -2
  162. package/dist/utils/test-utils.js +7 -1
  163. package/dist/utils/test-utils.js.map +1 -1
  164. package/dist/utils/util.d.ts +9 -2
  165. package/dist/utils/util.js +131 -5
  166. package/dist/utils/util.js.map +1 -1
  167. package/package.json +13 -19
  168. package/src/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.ts +55 -0
  169. package/src/storage/MongoBucketStorage.ts +728 -242
  170. package/src/storage/implementation/MongoBucketBatch.ts +196 -91
  171. package/src/storage/implementation/MongoChecksums.ts +93 -153
  172. package/src/storage/implementation/MongoCompactor.ts +106 -631
  173. package/src/storage/implementation/MongoHydrationState.ts +61 -0
  174. package/src/storage/implementation/MongoParameterCompactor.ts +392 -87
  175. package/src/storage/implementation/MongoParsedSyncConfigSet.ts +122 -0
  176. package/src/storage/implementation/MongoPersistedReplicationStream.ts +118 -0
  177. package/src/storage/implementation/MongoPersistedSyncConfigContent.ts +156 -0
  178. package/src/storage/implementation/MongoStorageProvider.ts +48 -4
  179. package/src/storage/implementation/MongoSyncBucketStorage.ts +226 -118
  180. package/src/storage/implementation/MongoSyncRulesLock.ts +28 -12
  181. package/src/storage/implementation/MongoWriteCheckpointAPI.ts +194 -52
  182. package/src/storage/implementation/SyncRuleStateUpdate.ts +13 -6
  183. package/src/storage/implementation/common/MongoSyncBucketStorageCheckpoint.ts +31 -0
  184. package/src/storage/implementation/common/PersistedBatch.ts +83 -15
  185. package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +1 -1
  186. package/src/storage/implementation/createMongoSyncBucketStorage.ts +21 -7
  187. package/src/storage/implementation/db.ts +40 -22
  188. package/src/storage/implementation/models.ts +58 -14
  189. package/src/storage/implementation/v1/MongoBucketBatchV1.ts +174 -125
  190. package/src/storage/implementation/v1/MongoChecksumsV1.ts +154 -12
  191. package/src/storage/implementation/v1/MongoCompactorV1.ts +594 -25
  192. package/src/storage/implementation/v1/MongoParameterCompactorV1.ts +25 -9
  193. package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +226 -129
  194. package/src/storage/implementation/v1/SingleBucketStoreV1.ts +18 -27
  195. package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +11 -1
  196. package/src/storage/implementation/v1/models.ts +12 -1
  197. package/src/storage/implementation/v3/BucketDataContextV3.ts +32 -0
  198. package/src/storage/implementation/v3/CompactionLease.ts +152 -0
  199. package/src/storage/implementation/v3/MongoBucketBatchV3.ts +502 -324
  200. package/src/storage/implementation/v3/MongoChecksumsV3.ts +250 -32
  201. package/src/storage/implementation/v3/MongoCompactorV3.ts +1439 -70
  202. package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +19 -9
  203. package/src/storage/implementation/v3/MongoStoppedSyncConfigCleanup.ts +473 -0
  204. package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +453 -211
  205. package/src/storage/implementation/v3/MongoWriteCheckpointAPIV3.ts +111 -0
  206. package/src/storage/implementation/v3/PersistedBatchV3.ts +169 -45
  207. package/src/storage/implementation/v3/SourceRecordStoreV3.ts +12 -12
  208. package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +99 -38
  209. package/src/storage/implementation/v3/bucket-format.ts +99 -0
  210. package/src/storage/implementation/v3/chunking.ts +40 -0
  211. package/src/storage/implementation/v3/compact-utils.ts +320 -0
  212. package/src/storage/implementation/v3/compaction-constants.ts +5 -0
  213. package/src/storage/implementation/v3/models.ts +228 -58
  214. package/src/storage/implementation/v3/object-storage/BucketDataObjectStorage.ts +62 -0
  215. package/src/storage/implementation/v3/object-storage/ObjectStorage.ts +44 -0
  216. package/src/storage/implementation/v3/object-storage/ObjectStorageLifecycle.ts +182 -0
  217. package/src/storage/implementation/v3/object-storage/ObjectStorageUsage.ts +230 -0
  218. package/src/storage/implementation/v3/object-storage/S3ObjectStorage.ts +573 -0
  219. package/src/storage/implementation/v3/source-table-utils.ts +398 -0
  220. package/src/storage/storage-index.ts +14 -4
  221. package/src/types/types.ts +76 -2
  222. package/src/utils/test-utils.ts +8 -3
  223. package/src/utils/util.ts +188 -7
  224. package/test/src/__snapshots__/storage.test.ts.snap +4 -54
  225. package/test/src/__snapshots__/storage_sync.test.ts.snap +652 -645
  226. package/test/src/cleanup-stopped-sync-configs.test.ts +698 -0
  227. package/test/src/compact-utils.test.ts +226 -0
  228. package/test/src/helpers/MemoryObjectStorage.ts +61 -0
  229. package/test/src/helpers/s3TestFactory.ts +69 -0
  230. package/test/src/object_storage_lifecycle.test.ts +59 -0
  231. package/test/src/object_storage_usage.test.ts +255 -0
  232. package/test/src/parameter_compacting_v1.test.ts +120 -0
  233. package/test/src/parameter_compacting_v3.test.ts +192 -0
  234. package/test/src/parameter_compaction_fence.test.ts +276 -0
  235. package/test/src/setup.ts +6 -1
  236. package/test/src/storage.test.ts +478 -13
  237. package/test/src/storage_compacting.test.ts +2516 -107
  238. package/test/src/storage_object_storage_inline_threshold.test.ts +116 -0
  239. package/test/src/storage_s3_checksums.test.ts +190 -0
  240. package/test/src/storage_s3_compaction_lifecycle.test.ts +543 -0
  241. package/test/src/storage_s3_reading.test.ts +768 -0
  242. package/test/src/storage_s3_writing.test.ts +136 -0
  243. package/test/src/storage_sync.test.ts +1507 -76
  244. package/test/src/storeCurrentData.test.ts +227 -0
  245. package/test/src/util.ts +3 -2
  246. package/tsconfig.json +1 -4
  247. package/tsconfig.tsbuildinfo +1 -1
  248. package/dist/storage/implementation/BucketDefinitionMapping.d.ts +0 -15
  249. package/dist/storage/implementation/BucketDefinitionMapping.js +0 -58
  250. package/dist/storage/implementation/BucketDefinitionMapping.js.map +0 -1
  251. package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +0 -14
  252. package/dist/storage/implementation/MongoPersistedSyncRules.js +0 -67
  253. package/dist/storage/implementation/MongoPersistedSyncRules.js.map +0 -1
  254. package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +0 -29
  255. package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +0 -76
  256. package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +0 -1
  257. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.d.ts +0 -13
  258. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js +0 -2
  259. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js.map +0 -1
  260. package/dist/storage/implementation/common/SingleBucketStore.d.ts +0 -54
  261. package/dist/storage/implementation/common/SingleBucketStore.js +0 -3
  262. package/dist/storage/implementation/common/SingleBucketStore.js.map +0 -1
  263. package/dist/storage/implementation/v3/MongoParameterLookupV3.d.ts +0 -4
  264. package/dist/storage/implementation/v3/MongoParameterLookupV3.js +0 -9
  265. package/dist/storage/implementation/v3/MongoParameterLookupV3.js.map +0 -1
  266. package/dist/storage/implementation/v3/SingleBucketStoreV3.d.ts +0 -18
  267. package/dist/storage/implementation/v3/SingleBucketStoreV3.js +0 -48
  268. package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +0 -1
  269. package/src/storage/implementation/BucketDefinitionMapping.ts +0 -75
  270. package/src/storage/implementation/MongoPersistedSyncRules.ts +0 -82
  271. package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +0 -101
  272. package/src/storage/implementation/common/MongoSyncBucketStorageContext.ts +0 -15
  273. package/src/storage/implementation/common/SingleBucketStore.ts +0 -63
  274. package/src/storage/implementation/v3/MongoParameterLookupV3.ts +0 -11
  275. package/src/storage/implementation/v3/SingleBucketStoreV3.ts +0 -68
@@ -67,7 +67,7 @@ export abstract class BaseVersionedPowerSyncMongo {
67
67
  }
68
68
 
69
69
  protected async listCollectionsByPrefix<T extends mongo.Document>(prefix: string): Promise<mongo.Collection<T>[]> {
70
- const collections = await this.db.listCollections({ name: new RegExp(`^${prefix}`) }, { nameOnly: true }).toArray();
70
+ const collections = await this.db.listCollections({ name: { $regex: `^${prefix}` } }, { nameOnly: true }).toArray();
71
71
 
72
72
  return collections
73
73
  .filter((collection) => collection.name.startsWith(prefix))
@@ -1,6 +1,6 @@
1
1
  import { storage } from '@powersync/service-core';
2
2
  import { MongoBucketStorage } from '../MongoBucketStorage.js';
3
- import { MongoPersistedSyncRulesContentV1 } from './MongoPersistedSyncRulesContent.js';
3
+ import { MongoPersistedReplicationStream } from './MongoPersistedReplicationStream.js';
4
4
  import { MongoSyncBucketStorage, MongoSyncBucketStorageOptions } from './MongoSyncBucketStorage.js';
5
5
  import { MongoSyncBucketStorageV1 } from './v1/MongoSyncBucketStorageV1.js';
6
6
  import { MongoSyncBucketStorageV3 } from './v3/MongoSyncBucketStorageV3.js';
@@ -11,15 +11,29 @@ export type { MongoSyncBucketStorage };
11
11
 
12
12
  export function createMongoSyncBucketStorage(
13
13
  factory: MongoBucketStorage,
14
- group_id: number,
15
- sync_rules: MongoPersistedSyncRulesContentV1,
16
- slot_name: string,
14
+ replicationStreamId: number,
15
+ replicationStream: MongoPersistedReplicationStream,
16
+ replicationStreamName: string,
17
17
  writeCheckpointMode: storage.WriteCheckpointMode | undefined,
18
18
  options: MongoSyncBucketStorageOptions
19
19
  ): MongoSyncBucketStorage {
20
- if (sync_rules.getStorageConfig().incrementalReprocessing) {
21
- return new MongoSyncBucketStorageV3(factory, group_id, sync_rules, slot_name, writeCheckpointMode, options);
20
+ if (replicationStream.getStorageConfig().incrementalReprocessing) {
21
+ return new MongoSyncBucketStorageV3(
22
+ factory,
23
+ replicationStreamId,
24
+ replicationStream,
25
+ replicationStreamName,
26
+ writeCheckpointMode,
27
+ options
28
+ );
22
29
  }
23
30
 
24
- return new MongoSyncBucketStorageV1(factory, group_id, sync_rules, slot_name, writeCheckpointMode, options);
31
+ return new MongoSyncBucketStorageV1(
32
+ factory,
33
+ replicationStreamId,
34
+ replicationStream,
35
+ replicationStreamName,
36
+ writeCheckpointMode,
37
+ options
38
+ );
25
39
  }
@@ -24,8 +24,9 @@ import {
24
24
  CurrentDataDocument
25
25
  } from './v1/models.js';
26
26
  import { VersionedPowerSyncMongoV1 } from './v1/VersionedPowerSyncMongoV1.js';
27
- import { BucketDataDocumentV3 } from './v3/models.js';
28
- import { VersionedPowerSyncMongoV3 } from './v3/VersionedPowerSyncMongoV3.js';
27
+ import { BucketDataDocumentV3, CustomCheckpointRequestDocumentV3 } from './v3/models.js';
28
+ import type { CustomCheckpointRequestCollectionSpecifier } from './v3/VersionedPowerSyncMongoV3.js';
29
+ import { OBJECT_STORAGE_USAGE_COLLECTION, VersionedPowerSyncMongoV3 } from './v3/VersionedPowerSyncMongoV3.js';
29
30
 
30
31
  export interface PowerSyncMongoOptions {
31
32
  /**
@@ -81,7 +82,7 @@ export class PowerSyncMongo {
81
82
  versioned(storageConfig: StorageConfig & { incrementalReprocessing: false }): VersionedPowerSyncMongoV1;
82
83
  versioned(storageConfig: StorageConfig): VersionedPowerSyncMongo;
83
84
  versioned(storageConfig: StorageConfig): VersionedPowerSyncMongo {
84
- if (storageConfig.incrementalReprocessing) {
85
+ if (storageConfig.version >= storage.STORAGE_VERSION_3) {
85
86
  return new VersionedPowerSyncMongoV3(this, storageConfig);
86
87
  }
87
88
 
@@ -93,22 +94,18 @@ export class PowerSyncMongo {
93
94
  */
94
95
  async listBucketDataCollectionsV3(groupId?: number): Promise<mongo.Collection<BucketDataDocumentV3>[]> {
95
96
  const prefix = groupId == null ? 'bucket_data_' : `bucket_data_${groupId}_`;
96
- const collections = await this.db.listCollections({ name: new RegExp(`^${prefix}`) }, { nameOnly: true }).toArray();
97
-
98
- return collections
99
- .filter((collection) => collection.name.startsWith(prefix))
100
- .map((collection) => this.db.collection<BucketDataDocumentV3>(collection.name));
97
+ return this.collectionsByPrefix<BucketDataDocumentV3>(prefix);
101
98
  }
102
99
 
103
100
  /**
104
101
  * Not safe for user-provided prefix - only for hardcoded values.
105
102
  */
106
- private async collectionsByPrefix(prefix: string): Promise<mongo.Collection<never>[]> {
107
- const collections = await this.db.listCollections({ name: new RegExp(`^${prefix}`) }, { nameOnly: true }).toArray();
103
+ private async collectionsByPrefix<T extends mongo.Document = never>(prefix: string): Promise<mongo.Collection<T>[]> {
104
+ const collections = await this.db.listCollections({ name: { $regex: `^${prefix}` } }, { nameOnly: true }).toArray();
108
105
 
109
106
  return collections
110
107
  .filter((collection) => collection.name.startsWith(prefix))
111
- .map((collection) => this.db.collection<never>(collection.name));
108
+ .map((collection) => this.db.collection<T>(collection.name));
112
109
  }
113
110
 
114
111
  /**
@@ -141,19 +138,29 @@ export class PowerSyncMongo {
141
138
  return `source_table_${replicationStreamId}`;
142
139
  }
143
140
 
144
- async listSourceTableCollections(
141
+ customCheckpointRequestCollectionName(options: CustomCheckpointRequestCollectionSpecifier) {
142
+ return `custom_checkpoint_requests_${options.replicationStreamId}_${options.eventId}`;
143
+ }
144
+
145
+ async listCustomCheckpointRequestCollections(
145
146
  replicationStreamId?: number
146
- ): Promise<mongo.Collection<CommonSourceTableDocument>[]> {
147
- const filter =
147
+ ): Promise<mongo.Collection<CustomCheckpointRequestDocumentV3>[]> {
148
+ const prefix =
148
149
  replicationStreamId == null
149
- ? { name: new RegExp('^source_table_') }
150
- : { name: this.sourceTableCollectionName(replicationStreamId) };
151
- const prefix = replicationStreamId == null ? 'source_table_' : this.sourceTableCollectionName(replicationStreamId);
152
- const collections = await this.db.listCollections(filter, { nameOnly: true }).toArray();
150
+ ? 'custom_checkpoint_requests_'
151
+ : `custom_checkpoint_requests_${replicationStreamId}_`;
152
+ return this.collectionsByPrefix(prefix);
153
+ }
153
154
 
154
- return collections
155
- .filter((collection) => collection.name.startsWith(prefix))
156
- .map((collection) => this.db.collection<CommonSourceTableDocument>(collection.name));
155
+ async listSourceTableCollections(
156
+ replicationStreamId?: number
157
+ ): Promise<mongo.Collection<CommonSourceTableDocument>[]> {
158
+ if (replicationStreamId == null) {
159
+ return this.collectionsByPrefix('source_table_');
160
+ }
161
+ const name = this.sourceTableCollectionName(replicationStreamId);
162
+ const collections = await this.db.listCollections({ name }, { nameOnly: true }).toArray();
163
+ return collections.map((c) => this.db.collection<CommonSourceTableDocument>(c.name));
157
164
  }
158
165
 
159
166
  /**
@@ -186,6 +193,10 @@ export class PowerSyncMongo {
186
193
  await this.locks.deleteMany({});
187
194
  await this.bucket_state.deleteMany({});
188
195
  await this.custom_write_checkpoints.deleteMany({});
196
+ await this.db.collection(OBJECT_STORAGE_USAGE_COLLECTION).deleteMany({});
197
+ for (const collection of await this.listCustomCheckpointRequestCollections()) {
198
+ await collection.drop();
199
+ }
189
200
  }
190
201
 
191
202
  /**
@@ -203,7 +214,14 @@ export class PowerSyncMongo {
203
214
  * This is used in a similar way to the Postgres NOTIFY functionality.
204
215
  */
205
216
  async notifyCheckpoint() {
206
- await this.checkpoint_events.insertOne({} as any, { forceServerObjectId: true });
217
+ await this.checkpoint_events.insertOne({} as any, {
218
+ forceServerObjectId: true,
219
+ // No correctness issue if this write is missed / rolled back.
220
+ // It could cause some sync delays, that will resolve in at most a minute, but no consistency issues.
221
+ writeConcern: {
222
+ w: 1
223
+ }
224
+ });
207
225
  }
208
226
 
209
227
  /**
@@ -4,7 +4,7 @@ import { ParameterIndexId, SqliteJsonValue } from '@powersync/service-sync-rules
4
4
  import { event_types } from '@powersync/service-types';
5
5
  import * as bson from 'bson';
6
6
  import type { CurrentDataDocument, SourceTableDocumentV1 } from './v1/models.js';
7
- import type { CurrentBucketV3, CurrentDataDocumentV3, RecordedLookupV3, SourceTableDocumentV3 } from './v3/models.js';
7
+ import type { CurrentDataDocumentV3, RecordedLookupV3 } from './v3/models.js';
8
8
 
9
9
  /**
10
10
  * Replica id uniquely identifying a row on the source database.
@@ -74,10 +74,21 @@ export interface BucketDataProperties {
74
74
  op: OpType;
75
75
  source_table?: bson.ObjectId;
76
76
  source_key?: ReplicaId;
77
+ /**
78
+ * Stable identifier for the source record in the client protocol.
79
+ *
80
+ * This is derived from (source_table, source_key), so persistence is optional but preferred.
81
+ */
82
+ subkey?: string;
77
83
  table?: string;
78
84
  row_id?: string;
79
85
  checksum: bigint;
80
86
  data: string | null;
87
+ /**
88
+ * V1-only.
89
+ *
90
+ * V3 stores this on the BucketDataDocumentV3 instead of the individual ops.
91
+ */
81
92
  target_op?: bigint | null;
82
93
  }
83
94
 
@@ -105,6 +116,10 @@ export interface SourceTableDocument {
105
116
  replica_id_columns2: { name: string; type_oid?: number; type?: string }[] | undefined;
106
117
  snapshot_done: boolean | undefined;
107
118
  snapshot_status: SourceTableDocumentSnapshotStatus | undefined;
119
+ /**
120
+ * Source-specific metadata. Absent for legacy records.
121
+ */
122
+ source_metadata?: storage.JsonValue;
108
123
  }
109
124
 
110
125
  export interface SourceTableDocumentSnapshotStatus {
@@ -206,9 +221,37 @@ export interface SyncRuleDocumentBase {
206
221
  } | null;
207
222
 
208
223
  storage_version?: number;
224
+
225
+ /** Optional operator-supplied label identifying the sync config version. */
226
+ version_label?: string | null;
227
+
228
+ /**
229
+ * Incremental parameter compaction state for the replication stream.
230
+ *
231
+ * Operation ids are allocated across all parameter indexes of a stream, so this is
232
+ * stream-level state, shared by all sync configs of the stream.
233
+ */
234
+ parameter_compaction?: {
235
+ /**
236
+ * The exclusive operation-id boundary through which every parameter index in this stream has
237
+ * been compacted.
238
+ */
239
+ compacted_before: InternalOpId;
240
+
241
+ /**
242
+ * Parameter entries below this boundary may no longer be available for checkpoint change
243
+ * detection, since compaction may have deleted them.
244
+ *
245
+ * This is advanced before the first delete of a compaction pass, while
246
+ * {@link compacted_before} is only advanced after every delete of the pass completed.
247
+ * A checkpoint transition starting below this boundary must conservatively invalidate all
248
+ * parameter buckets, since the individual changes may no longer be available.
249
+ */
250
+ checkpoint_changes_invalid_before?: InternalOpId;
251
+ };
209
252
  }
210
253
 
211
- export interface SyncRuleCheckpointFields<TKeepaliveOp extends string | bigint | null> {
254
+ export interface SyncRuleCheckpointFields {
212
255
  /**
213
256
  * The last consistent checkpoint.
214
257
  *
@@ -225,16 +268,6 @@ export interface SyncRuleCheckpointFields<TKeepaliveOp extends string | bigint |
225
268
  * If set, no new checkpoints may be created < this value.
226
269
  */
227
270
  no_checkpoint_before: string | null;
228
-
229
- /**
230
- * Goes together with no_checkpoint_before.
231
- *
232
- * If a keepalive is triggered that creates the checkpoint > no_checkpoint_before,
233
- * then the checkpoint must be equal to this keepalive_op.
234
- *
235
- * This is a string in V1, bigint in V3.
236
- */
237
- keepalive_op: TKeepaliveOp;
238
271
  }
239
272
 
240
273
  export interface StorageConfig extends storage.StorageVersionConfig {
@@ -283,6 +316,11 @@ export interface CustomWriteCheckpointDocument {
283
316
  * This is not unique - multiple write checkpoints can have the same op_id.
284
317
  */
285
318
  op_id?: InternalOpId;
319
+ /**
320
+ * Set when this checkpoint was created from a client-supplied checkpoint
321
+ * request rather than a persistent custom write checkpoint.
322
+ */
323
+ checkpoint_requested_at?: Date | null;
286
324
  }
287
325
 
288
326
  export interface WriteCheckpointDocument {
@@ -296,6 +334,12 @@ export interface WriteCheckpointDocument {
296
334
  * between two checkpoints.
297
335
  */
298
336
  processed_at_lsn: string | null;
337
+ /**
338
+ * Set when this checkpoint was created from a client-supplied checkpoint request
339
+ * rather than a server-generated id. A missing/null value means this is not a
340
+ * checkpoint request.
341
+ */
342
+ checkpoint_requested_at?: Date | null;
299
343
  }
300
344
 
301
345
  export interface InstanceDocument {
@@ -306,6 +350,6 @@ export interface InstanceDocument {
306
350
  export interface ClientConnectionDocument extends event_types.ClientConnection {}
307
351
 
308
352
  export type CurrentDataDocumentId = CurrentDataDocument['_id'] | CurrentDataDocumentV3['_id'];
309
- export type CommonCurrentBucket = CurrentBucket | CurrentBucketV3;
353
+ export type CommonCurrentBucket = CurrentBucket;
310
354
  export type CommonCurrentLookup = bson.Binary | RecordedLookupV3;
311
- export type CommonSourceTableDocument = SourceTableDocumentV1 | SourceTableDocumentV3;
355
+ export type CommonSourceTableDocument = Pick<SourceTableDocumentV1, '_id' | 'snapshot_status'>;