@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
@@ -0,0 +1,206 @@
1
+ import { ReplicationAssertionError } from '@powersync/lib-services-framework';
2
+ import { storage } from '@powersync/service-core';
3
+ export function sourceTableDesiredResolution(syncConfig, ref, mapping, eventById) {
4
+ const matchingSources = syncConfig.getMatchingSources(ref);
5
+ return {
6
+ bucketSourceById: new Map(matchingSources.bucketDataSources.map((source) => [mapping.bucketSourceId(source), source])),
7
+ parameterLookupSourceById: new Map(matchingSources.parameterLookupSources.map((source) => [mapping.parameterLookupId(source), source])),
8
+ eventDefinitionById: new Map([...eventById].filter(([, event]) => event.tableTriggersEvent(ref)))
9
+ };
10
+ }
11
+ export function planSourceTableReconciliation(candidateDocs, context) {
12
+ return new SourceTableReconciliationPlanner(context).plan(candidateDocs);
13
+ }
14
+ function sameStringArray(left, right) {
15
+ return left.length == right.length && left.every((value, index) => value == right[index]);
16
+ }
17
+ function matchingSourcesFor(desired, memberships) {
18
+ return {
19
+ bucketDataSources: memberships.bucketDataSourceIds.map((id) => desired.bucketSourceById.get(id)),
20
+ parameterLookupSources: memberships.parameterLookupSourceIds.map((id) => desired.parameterLookupSourceById.get(id))
21
+ };
22
+ }
23
+ function intersectMembershipIds(doc, desired) {
24
+ return {
25
+ bucketDataSourceIds: doc.bucket_data_source_ids.filter((id) => desired.bucketSourceById.has(id)),
26
+ parameterLookupSourceIds: doc.parameter_lookup_source_ids.filter((id) => desired.parameterLookupSourceById.has(id)),
27
+ eventDefinitionIds: doc.event_definition_ids.filter((id) => desired.eventDefinitionById.has(id))
28
+ };
29
+ }
30
+ function hasMembershipIds(memberships) {
31
+ return (memberships.bucketDataSourceIds.length > 0 ||
32
+ memberships.parameterLookupSourceIds.length > 0 ||
33
+ memberships.eventDefinitionIds.length > 0);
34
+ }
35
+ function sameMembershipIds(doc, memberships) {
36
+ return (sameStringArray(doc.bucket_data_source_ids, memberships.bucketDataSourceIds) &&
37
+ sameStringArray(doc.parameter_lookup_source_ids, memberships.parameterLookupSourceIds) &&
38
+ sameStringArray(doc.event_definition_ids, memberships.eventDefinitionIds));
39
+ }
40
+ class SourceTableReconciliationPlanner {
41
+ context;
42
+ coveredBucketDataSourceIds = new Set();
43
+ coveredParameterLookupSourceIds = new Set();
44
+ coveredEventDefinitionIds = new Set();
45
+ tables = [];
46
+ narrowingUpdates = [];
47
+ constructor(context) {
48
+ this.context = context;
49
+ }
50
+ plan(candidateDocs) {
51
+ for (const doc of candidateDocs) {
52
+ if (this.isCompatible(doc)) {
53
+ this.retainDoc(doc);
54
+ }
55
+ }
56
+ return {
57
+ tables: this.tables,
58
+ narrowingUpdates: this.narrowingUpdates,
59
+ newTableMemberships: this.newTableMemberships(),
60
+ // Compatible records remain available for reuse even when not needed by this config.
61
+ dropDocs: candidateDocs.filter((doc) => !this.isCompatible(doc))
62
+ };
63
+ }
64
+ isCompatible(doc) {
65
+ return this.compatibleTableFor(doc) != null;
66
+ }
67
+ compatibleTableFor(doc) {
68
+ return this.context.sourceCompatibleTables.find((table) => storage.sourceTableIdEquals(table.id, doc._id));
69
+ }
70
+ retainDoc(doc) {
71
+ const memberships = intersectMembershipIds(doc, this.context.desired);
72
+ const coversDesiredMembership = hasMembershipIds(memberships);
73
+ this.recordCoverage(doc, memberships);
74
+ this.planNarrowingUpdate(doc, memberships, coversDesiredMembership);
75
+ if (coversDesiredMembership) {
76
+ this.tables.push(this.sourceTableFor(doc, memberships));
77
+ }
78
+ }
79
+ recordCoverage(doc, memberships) {
80
+ this.addCoverage(doc, 'bucket data source', this.coveredBucketDataSourceIds, memberships.bucketDataSourceIds);
81
+ this.addCoverage(doc, 'parameter lookup source', this.coveredParameterLookupSourceIds, memberships.parameterLookupSourceIds);
82
+ this.addCoverage(doc, 'event definition', this.coveredEventDefinitionIds, memberships.eventDefinitionIds);
83
+ }
84
+ // Membership sets must be pairwise disjoint across the docs of one physical table:
85
+ // each desired id is covered by exactly one doc, so each definition is evaluated through
86
+ // only one SourceTable for a physical row. Different docs may own different event ids.
87
+ // The algorithm maintains this (new docs only get uncovered ids, narrowing only removes ids) -
88
+ // overlap means the persisted state is corrupt.
89
+ addCoverage(doc, kind, covered, ids) {
90
+ const { schema, name } = this.context.identity;
91
+ for (const id of ids) {
92
+ if (covered.has(id)) {
93
+ throw new ReplicationAssertionError(`Source table ${doc._id} duplicates coverage of ${kind} ${id} for ${schema}.${name}`);
94
+ }
95
+ covered.add(id);
96
+ }
97
+ }
98
+ planNarrowingUpdate(doc, memberships, coversDesiredMembership) {
99
+ const shouldNarrow = coversDesiredMembership && !doc.snapshot_done && !sameMembershipIds(doc, memberships);
100
+ if (!shouldNarrow) {
101
+ return;
102
+ }
103
+ this.narrowingUpdates.push({
104
+ id: doc._id,
105
+ memberships
106
+ });
107
+ }
108
+ newTableMemberships() {
109
+ const { desired } = this.context;
110
+ const uncovered = {
111
+ bucketDataSourceIds: [...desired.bucketSourceById.keys()].filter((id) => !this.coveredBucketDataSourceIds.has(id)),
112
+ parameterLookupSourceIds: [...desired.parameterLookupSourceById.keys()].filter((id) => !this.coveredParameterLookupSourceIds.has(id)),
113
+ eventDefinitionIds: [...desired.eventDefinitionById.keys()].filter((id) => !this.coveredEventDefinitionIds.has(id))
114
+ };
115
+ if (hasMembershipIds(uncovered)) {
116
+ return uncovered;
117
+ }
118
+ return null;
119
+ }
120
+ sourceTableFor(doc, memberships) {
121
+ const { connectionTag, syncConfig, mapping, desired, storeCurrentData } = this.context;
122
+ const built = sourceTableFromDocument(doc, connectionTag, syncConfig, mapping, desired.eventDefinitionById, matchingSourcesFor(desired, memberships), memberships);
123
+ // Use any metadata update returned by the reconciler.
124
+ const resolved = this.compatibleTableFor(doc);
125
+ const table = resolved == null ? built : built.withSourceMetadata(resolved.sourceMetadata);
126
+ table.storeCurrentData = storeCurrentData;
127
+ return table;
128
+ }
129
+ }
130
+ export function overlappingSourceTableFilter(connectionId, identity) {
131
+ const clauses = [{ schema_name: identity.schema, table_name: identity.name }];
132
+ if (identity.objectId != null) {
133
+ clauses.push({ relation_id: identity.objectId });
134
+ }
135
+ return {
136
+ connection_id: connectionId,
137
+ $or: clauses
138
+ };
139
+ }
140
+ export function createNewSourceTable(id, memberships, context) {
141
+ const { connectionId, connectionTag, identity, syncConfig, mapping, desired, storeCurrentData, newTableSourceMetadata } = context;
142
+ const doc = {
143
+ _id: id,
144
+ connection_id: connectionId,
145
+ relation_id: identity.objectId,
146
+ schema_name: identity.schema,
147
+ table_name: identity.name,
148
+ replica_id_columns: identity.replicaIdColumns,
149
+ snapshot_done: false,
150
+ snapshot_status: undefined,
151
+ bucket_data_source_ids: memberships.bucketDataSourceIds,
152
+ parameter_lookup_source_ids: memberships.parameterLookupSourceIds,
153
+ event_definition_ids: memberships.eventDefinitionIds,
154
+ // Records created together share the same source metadata.
155
+ source_metadata: newTableSourceMetadata
156
+ };
157
+ const table = sourceTableFromDocument(doc, connectionTag, syncConfig, mapping, desired.eventDefinitionById, matchingSourcesFor(desired, memberships), memberships);
158
+ table.storeCurrentData = storeCurrentData;
159
+ return { doc, table };
160
+ }
161
+ function sourceTableMembershipsFromDocument(doc, syncConfig, mapping) {
162
+ const bucketDataSourceIds = new Set(doc.bucket_data_source_ids);
163
+ const parameterLookupSourceIds = new Set(doc.parameter_lookup_source_ids);
164
+ return {
165
+ bucketDataSources: syncConfig.bucketDataSources.filter((source) => bucketDataSourceIds.has(mapping.bucketSourceId(source))),
166
+ parameterLookupSources: syncConfig.bucketParameterLookupSources.filter((source) => parameterLookupSourceIds.has(mapping.parameterLookupId(source)))
167
+ };
168
+ }
169
+ export function sourceTableFromDocument(doc, connectionTag, syncConfig, mapping, eventById, memberships, membershipIds) {
170
+ const resolvedMemberships = memberships ?? sourceTableMembershipsFromDocument(doc, syncConfig, mapping);
171
+ const resolvedMembershipIds = membershipIds ?? {
172
+ bucketDataSourceIds: resolvedMemberships.bucketDataSources.map((source) => mapping.bucketSourceId(source)),
173
+ parameterLookupSourceIds: resolvedMemberships.parameterLookupSources.map((source) => mapping.parameterLookupId(source)),
174
+ eventDefinitionIds: doc.event_definition_ids.filter((id) => eventById.has(id))
175
+ };
176
+ const table = new storage.SourceTable({
177
+ id: doc._id,
178
+ ref: {
179
+ connectionTag,
180
+ schema: doc.schema_name,
181
+ name: doc.table_name
182
+ },
183
+ objectId: doc.relation_id,
184
+ replicaIdColumns: doc.replica_id_columns?.map((column) => ({ name: column.name, typeId: column.type_oid, type: column.type })) ?? [],
185
+ snapshotComplete: doc.snapshot_done,
186
+ bucketDataSources: resolvedMemberships.bucketDataSources,
187
+ parameterLookupSources: resolvedMemberships.parameterLookupSources,
188
+ bucketDataSourceIds: new Set(resolvedMembershipIds.bucketDataSourceIds),
189
+ parameterLookupSourceIds: new Set(resolvedMembershipIds.parameterLookupSourceIds),
190
+ eventDefinitionIds: new Set(resolvedMembershipIds.eventDefinitionIds),
191
+ sourceMetadata: doc.source_metadata ?? null
192
+ });
193
+ table.syncData = table.bucketDataSources.length > 0;
194
+ table.syncParameters = table.parameterLookupSources.length > 0;
195
+ table.syncEvent = table.eventDefinitionIds.size > 0;
196
+ table.snapshotStatus =
197
+ doc.snapshot_status == null
198
+ ? undefined
199
+ : {
200
+ lastKey: doc.snapshot_status.last_key?.buffer ?? null,
201
+ totalEstimatedCount: doc.snapshot_status.total_estimated_count,
202
+ replicatedCount: doc.snapshot_status.replicated_count
203
+ };
204
+ return table;
205
+ }
206
+ //# sourceMappingURL=source-table-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-table-utils.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/source-table-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAwD,OAAO,EAAE,MAAM,yBAAyB,CAAC;AA4ExG,MAAM,UAAU,4BAA4B,CAC1C,UAA8B,EAC9B,GAAmB,EACnB,OAAgC,EAChC,SAAkE;IAElE,MAAM,eAAe,GAAG,UAAU,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC3D,OAAO;QACL,gBAAgB,EAAE,IAAI,GAAG,CACvB,eAAe,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,CAAU,CAAC,CACrG;QACD,yBAAyB,EAAE,IAAI,GAAG,CAChC,eAAe,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,CAAU,CAAC,CAC7G;QACD,mBAAmB,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC;KAClG,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,aA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C,CAAC,SAAS;YACX,CAAC,CAAC;gBACE,OAAO,EAAE,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,IAAI,IAAI;gBACrD,mBAAmB,EAAE,GAAG,CAAC,eAAe,CAAC,qBAAqB;gBAC9D,eAAe,EAAE,GAAG,CAAC,eAAe,CAAC,gBAAgB;aACtD,CAAC;IACR,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,17 +1,18 @@
1
1
  export * as test_utils from '../utils/test-utils.js';
2
2
  export * from '../utils/util.js';
3
- export * from './implementation/BucketDefinitionMapping.js';
4
3
  export * from './implementation/common/PersistedBatch.js';
5
4
  export * from './implementation/createMongoSyncBucketStorage.js';
6
5
  export * from './implementation/db.js';
7
6
  export * from './implementation/models.js';
8
7
  export * from './implementation/MongoIdSequence.js';
9
- export * from './implementation/MongoPersistedSyncRules.js';
10
- export * from './implementation/MongoPersistedSyncRulesContent.js';
8
+ export * from './implementation/MongoParsedSyncConfigSet.js';
9
+ export * from './implementation/MongoPersistedReplicationStream.js';
11
10
  export * from './implementation/MongoStorageProvider.js';
12
11
  export * from './implementation/MongoSyncRulesLock.js';
13
12
  export * from './implementation/OperationBatch.js';
14
13
  export * from './implementation/v1/models.js';
15
- export * from './implementation/v3/models.js';
14
+ export { loadBucketDataDocument, serializeBucketData } from './implementation/v3/bucket-format.js';
15
+ export { BucketDataDocumentV3, BucketOperation, ObjectStorageUsageDocument, RecordedLookupV3, ReplicationStreamDocumentV3, SyncConfigDefinition, SyncRuleConfigStateV3, taggedBucketParameterDocumentToTagged } from './implementation/v3/models.js';
16
+ export * from './implementation/v3/object-storage/ObjectStorageUsage.js';
16
17
  export * from './MongoBucketStorage.js';
17
18
  export * from './MongoReportStorage.js';
@@ -1,18 +1,19 @@
1
1
  export * as test_utils from '../utils/test-utils.js';
2
2
  export * from '../utils/util.js';
3
- export * from './implementation/BucketDefinitionMapping.js';
4
3
  export * from './implementation/common/PersistedBatch.js';
5
4
  export * from './implementation/createMongoSyncBucketStorage.js';
6
5
  export * from './implementation/db.js';
7
6
  export * from './implementation/models.js';
8
7
  export * from './implementation/MongoIdSequence.js';
9
- export * from './implementation/MongoPersistedSyncRules.js';
10
- export * from './implementation/MongoPersistedSyncRulesContent.js';
8
+ export * from './implementation/MongoParsedSyncConfigSet.js';
9
+ export * from './implementation/MongoPersistedReplicationStream.js';
11
10
  export * from './implementation/MongoStorageProvider.js';
12
11
  export * from './implementation/MongoSyncRulesLock.js';
13
12
  export * from './implementation/OperationBatch.js';
14
13
  export * from './implementation/v1/models.js';
15
- export * from './implementation/v3/models.js';
14
+ export { loadBucketDataDocument, serializeBucketData } from './implementation/v3/bucket-format.js';
15
+ export { taggedBucketParameterDocumentToTagged } from './implementation/v3/models.js';
16
+ export * from './implementation/v3/object-storage/ObjectStorageUsage.js';
16
17
  export * from './MongoBucketStorage.js';
17
18
  export * from './MongoReportStorage.js';
18
19
  //# sourceMappingURL=storage-index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,cAAc,kBAAkB,CAAC;AACjC,cAAc,6CAA6C,CAAC;AAC5D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kDAAkD,CAAC;AACjE,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,oDAAoD,CAAC;AACnE,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"storage-index.js","sourceRoot":"","sources":["../../src/storage/storage-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,cAAc,kBAAkB,CAAC;AACjC,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kDAAkD,CAAC;AACjE,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,qDAAqD,CAAC;AACpE,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AACnG,OAAO,EAQL,qCAAqC,EACtC,MAAM,+BAA+B,CAAC;AACvC,cAAc,0DAA0D,CAAC;AACzE,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
@@ -1,20 +1,88 @@
1
1
  import * as service_types from '@powersync/service-types';
2
2
  import * as t from 'ts-codec';
3
+ /**
4
+ * AWS defaults mode, as used by the AWS SDK.
5
+ *
6
+ * This is the baseline for the object storage request timeouts, so that they do not each need to be
7
+ * configured individually.
8
+ *
9
+ * The SDK's `legacy` and `auto` modes are not selectable here: `legacy` defines no timeouts at all,
10
+ * and `auto` makes the timeouts depend on where the process happens to be running. Both are still
11
+ * handled when they come from the AWS environment, and are then treated as `standard`.
12
+ */
13
+ export declare const S3DefaultsMode: t.Codec<"standard" | "in-region" | "cross-region" | "mobile", "standard" | "in-region" | "cross-region" | "mobile">;
14
+ export type S3DefaultsMode = t.Encoded<typeof S3DefaultsMode>;
15
+ export declare const MongoStorageReadPreference: t.Codec<"primary" | "primaryPreferred" | "secondary" | "secondaryPreferred" | "nearest", "primary" | "primaryPreferred" | "secondary" | "secondaryPreferred" | "nearest">;
16
+ export type MongoStorageReadPreference = t.Encoded<typeof MongoStorageReadPreference>;
3
17
  export declare const MongoStorageConfig: t.Intersection<t.Codec<{
4
- uri: string;
18
+ type: string;
19
+ max_pool_size?: number | undefined;
20
+ default_storage_version?: number | undefined;
21
+ } & {
5
22
  type: "mongodb";
23
+ uri: string;
6
24
  database?: string | undefined;
7
25
  username?: string | undefined;
8
26
  password?: string | undefined;
9
27
  reject_ip_ranges?: string[] | undefined;
10
28
  }, {
11
- uri: string;
29
+ type: string;
30
+ max_pool_size?: number | undefined;
31
+ default_storage_version?: number | undefined;
32
+ } & {
12
33
  type: "mongodb";
34
+ uri: string;
13
35
  database?: string | undefined;
14
36
  username?: string | undefined;
15
37
  password?: string | undefined;
16
38
  reject_ip_ranges?: string[] | undefined;
17
- }, string, t.CodecProps>, t.ObjectCodec<{}>>;
39
+ }, string, t.CodecProps>, t.ObjectCodec<{
40
+ /**
41
+ * Read preference for bulk checksum and bucket data reads.
42
+ *
43
+ * If unset, MongoDB driver defaults are used for backwards compatibility.
44
+ *
45
+ * This is an experimental option, and may be removed in a future release.
46
+ */
47
+ bulk_read_preference: t.OptionalCodec<t.Codec<"primary" | "primaryPreferred" | "secondary" | "secondaryPreferred" | "nearest", "primary" | "primaryPreferred" | "secondary" | "secondaryPreferred" | "nearest", string, t.CodecProps>>;
48
+ /**
49
+ * Throttle clear operations after sync config deploys, by pausing between batches.
50
+ * The rate produces a pause proportional to the previous batch duration.
51
+ *
52
+ * Increase this to reduce impact of clear operations on the storage cluster.
53
+ * Use 0 to clear as fast as possible.
54
+ *
55
+ * Defaults to 0.2.
56
+ */
57
+ clear_batch_throttle_rate: t.OptionalCodec<t.Codec<number, number, string, t.CodecProps>>;
58
+ object_storage: t.OptionalCodec<t.Codec<{
59
+ type: "s3";
60
+ bucket: string;
61
+ region?: string | undefined;
62
+ prefix?: string | undefined;
63
+ endpoint?: string | undefined;
64
+ force_path_style?: boolean | undefined;
65
+ access_key_id?: string | undefined;
66
+ secret_access_key?: string | undefined;
67
+ concurrency_limit?: number | undefined;
68
+ defaults_mode?: "standard" | "in-region" | "cross-region" | "mobile" | undefined;
69
+ inline_threshold_bytes?: number | undefined;
70
+ }, {
71
+ type: "s3";
72
+ bucket: string;
73
+ region?: string | undefined;
74
+ prefix?: string | undefined;
75
+ endpoint?: string | undefined;
76
+ force_path_style?: boolean | undefined;
77
+ access_key_id?: string | undefined;
78
+ secret_access_key?: string | undefined;
79
+ concurrency_limit?: number | undefined;
80
+ defaults_mode?: "standard" | "in-region" | "cross-region" | "mobile" | undefined;
81
+ inline_threshold_bytes?: number | undefined;
82
+ }, string, t.CodecProps>>;
83
+ }>>;
18
84
  export type MongoStorageConfig = t.Encoded<typeof MongoStorageConfig>;
19
85
  export type MongoStorageConfigDecoded = t.Decoded<typeof MongoStorageConfig>;
86
+ export declare const DEFAULT_CLEAR_BATCH_THROTTLE_RATE = 0.2;
87
+ export declare function normalizeClearBatchThrottleRate(value: number | undefined): number;
20
88
  export declare function isMongoStorageConfig(config: service_types.configFile.GenericStorageConfig): config is MongoStorageConfig;
@@ -1,8 +1,64 @@
1
1
  import * as lib_mongo from '@powersync/lib-service-mongodb';
2
+ import { ErrorCode, ServiceError } from '@powersync/lib-services-framework';
3
+ import * as service_types from '@powersync/service-types';
2
4
  import * as t from 'ts-codec';
3
- export const MongoStorageConfig = lib_mongo.BaseMongoConfig.and(t.object({
4
- // Add any mongo specific storage settings here in future
5
+ /**
6
+ * AWS defaults mode, as used by the AWS SDK.
7
+ *
8
+ * This is the baseline for the object storage request timeouts, so that they do not each need to be
9
+ * configured individually.
10
+ *
11
+ * The SDK's `legacy` and `auto` modes are not selectable here: `legacy` defines no timeouts at all,
12
+ * and `auto` makes the timeouts depend on where the process happens to be running. Both are still
13
+ * handled when they come from the AWS environment, and are then treated as `standard`.
14
+ */
15
+ export const S3DefaultsMode = service_types.enumLiteral('standard', 'in-region', 'cross-region', 'mobile');
16
+ const S3ObjectStorageConfig = t.object({
17
+ type: t.literal('s3'),
18
+ bucket: t.string,
19
+ region: t.string.optional(),
20
+ prefix: t.string.optional(),
21
+ endpoint: t.string.optional(),
22
+ force_path_style: t.boolean.optional(),
23
+ access_key_id: t.string.optional(),
24
+ secret_access_key: t.string.optional(),
25
+ concurrency_limit: t.number.optional(),
26
+ // Defaults to the AWS_DEFAULTS_MODE environment variable.
27
+ defaults_mode: S3DefaultsMode.optional(),
28
+ // Chunks whose BSON-serialized size falls below this byte threshold
29
+ // stay inline in MongoDB instead of being offloaded to S3. Default 1024.
30
+ inline_threshold_bytes: t.number.optional()
31
+ });
32
+ export const MongoStorageReadPreference = service_types.enumLiteral('primary', 'primaryPreferred', 'secondary', 'secondaryPreferred', 'nearest');
33
+ export const MongoStorageConfig = service_types.configFile.BaseStorageConfig.and(lib_mongo.BaseMongoConfig).and(t.object({
34
+ /**
35
+ * Read preference for bulk checksum and bucket data reads.
36
+ *
37
+ * If unset, MongoDB driver defaults are used for backwards compatibility.
38
+ *
39
+ * This is an experimental option, and may be removed in a future release.
40
+ */
41
+ bulk_read_preference: MongoStorageReadPreference.optional(),
42
+ /**
43
+ * Throttle clear operations after sync config deploys, by pausing between batches.
44
+ * The rate produces a pause proportional to the previous batch duration.
45
+ *
46
+ * Increase this to reduce impact of clear operations on the storage cluster.
47
+ * Use 0 to clear as fast as possible.
48
+ *
49
+ * Defaults to 0.2.
50
+ */
51
+ clear_batch_throttle_rate: t.number.optional(),
52
+ object_storage: S3ObjectStorageConfig.optional()
5
53
  }));
54
+ export const DEFAULT_CLEAR_BATCH_THROTTLE_RATE = 0.2;
55
+ export function normalizeClearBatchThrottleRate(value) {
56
+ const rate = value ?? DEFAULT_CLEAR_BATCH_THROTTLE_RATE;
57
+ if (!Number.isFinite(rate) || rate < 0 || rate > 20) {
58
+ throw new ServiceError(ErrorCode.PSYNC_S3201, 'storage.clear_batch_throttle_rate must be a finite number between 0 and 20');
59
+ }
60
+ return rate;
61
+ }
6
62
  export function isMongoStorageConfig(config) {
7
63
  return config.type == lib_mongo.MONGO_CONNECTION_TYPE;
8
64
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"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5,7 @@ import { PowerSyncMongo } from '../storage/implementation/db.js';
5
5
  export type MongoTestStorageOptions = {
6
6
  url: string;
7
7
  isCI: boolean;
8
- internalOptions?: MongoBucketStorageOptions;
9
- };
8
+ } & Omit<MongoBucketStorageOptions, 'replicationStreamNamePrefix'>;
10
9
  export declare function mongoTestStorageFactoryGenerator(factoryOptions: MongoTestStorageOptions): {
11
10
  factory: (options?: TestStorageOptions) => Promise<MongoBucketStorage>;
12
11
  tableIdStrings: boolean;
@@ -15,7 +15,13 @@ export function mongoTestStorageFactoryGenerator(factoryOptions) {
15
15
  if (!options?.doNotClear) {
16
16
  await db.clear();
17
17
  }
18
- return new MongoBucketStorage(db, { slot_name_prefix: 'test_' }, factoryOptions.internalOptions);
18
+ return new MongoBucketStorage(db, {
19
+ replicationStreamNamePrefix: 'test_',
20
+ checksumOptions: factoryOptions.checksumOptions,
21
+ supportsMultipleSyncConfigs: factoryOptions.supportsMultipleSyncConfigs,
22
+ objectStorage: factoryOptions.objectStorage,
23
+ inlineThresholdBytes: factoryOptions.inlineThresholdBytes
24
+ });
19
25
  },
20
26
  tableIdStrings: false
21
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../src/utils/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAA6B,MAAM,kCAAkC,CAAC;AACjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAQjE,MAAM,UAAU,gCAAgC,CAAC,cAAuC;IACtF,OAAO;QACL,OAAO,EAAE,KAAK,EAAE,OAA4B,EAAE,EAAE;YAC9C,MAAM,EAAE,GAAG,oBAAoB,CAAC,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;YAEzE,8EAA8E;YAC9E,IAAI,CAAC,CA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BAC/C,2BAA2B,EAAE,cAAc,CAAC,2BAA2B;gBACvE,aAAa,EAAE,cAAc,CAAC,aAAa;gBAC3C,oBAAoB,EAAE,cAAc,CAAC,oBAAoB;aAC1D,CAAC,CAAC;QACL,CAAC;QACD,cAAc,EAAE,KAAK;KACtB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sCAAsC,CAAC,cAAuC;IAC5F,OAAO,KAAK,EAAE,OAA4B,EAAE,EAAE;QAC5C,MAAM,EAAE,GAAG,oBAAoB,CAAC,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;QAEzE,MAAM,EAAE,CAAC,mCAAmC,EAAE,CAAC;QAE/C,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC;YACzB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;QAED,OAAO,IAAI,kBAAkB,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAE,IAAa,EAAE,EAAE;IACjE,0EAA0E;IAC1E,oEAAoE;IACpE,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACxC,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;QACvC,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;QACtC,wBAAwB,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;KAChD,CAAC,CAAC;IACH,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC,CAAC"}
@@ -1,10 +1,14 @@
1
1
  import * as lib_mongo from '@powersync/lib-service-mongodb';
2
2
  import { mongo } from '@powersync/lib-service-mongodb';
3
+ import { Logger } from '@powersync/lib-services-framework';
3
4
  import { storage, utils } from '@powersync/service-core';
4
5
  import * as bson from 'bson';
5
6
  import { BucketDataDoc } from '../storage/implementation/common/BucketDataDoc.js';
6
- export declare function idPrefixFilter<T>(prefix: Partial<T>, rest: (keyof T)[]): mongo.Condition<T>;
7
- export declare function generateSlotName(prefix: string, sync_rules_id: number): string;
7
+ type ClearCollectionFilter<T extends mongo.Document> = mongo.Filter<T> & {
8
+ _id: mongo.FilterOperators<mongo.InferIdType<T>>;
9
+ };
10
+ export declare function idPrefixFilter<T>(prefix: Partial<T>, rest: (keyof T)[]): mongo.FilterOperators<T>;
11
+ export declare function generateReplicationStreamName(prefix: string, replicationStreamId: number): string;
8
12
  /**
9
13
  * Read a single batch of data from a cursor, then close it.
10
14
  *
@@ -30,6 +34,8 @@ export declare function retryOnMongoMaxTimeMSExpired<T>(operation: () => Promise
30
34
  retryDelayMs: number;
31
35
  onRetry?: (retryCount: number) => void;
32
36
  }): Promise<T>;
37
+ export declare function clearCollectionInIdRanges<T extends mongo.Document>(logger: Logger, label: string, collection: mongo.Collection<T>, filter: ClearCollectionFilter<T>, signal?: AbortSignal, throttleRate?: number): Promise<number>;
38
+ export declare function clearCollectionInIdBatches<T extends mongo.Document>(logger: Logger, label: string, collection: mongo.Collection<T>, filter: mongo.Filter<T>, signal?: AbortSignal, throttleRate?: number): Promise<number>;
33
39
  export declare const createPaginatedConnectionQuery: <T extends mongo.Document>(query: mongo.Filter<T>, collection: mongo.Collection<T>, limit: number, cursor?: string) => Promise<{
34
40
  items: lib_mongo.mongo.WithId<T>[];
35
41
  count: number;
@@ -37,3 +43,4 @@ export declare const createPaginatedConnectionQuery: <T extends mongo.Document>(
37
43
  cursor: any;
38
44
  more: boolean;
39
45
  }>;
46
+ export {};