@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,216 @@
1
+ import { ReplicationAssertionError } from '@powersync/lib-services-framework';
2
+ import { addChecksums } from '@powersync/service-core';
3
+ import { AVAILABLE_LEASE_EXPR } from './CompactionLease.js';
4
+ /**
5
+ * Perform chunk compaction if at least this many chunks have been added since
6
+ * the latest compaction.
7
+ *
8
+ * A lower value increases compaction frequency and can increase chunk rewrites
9
+ * and object-storage operations. A higher value leaves more small chunks for
10
+ * longer, which can hurt sync performance.
11
+ */
12
+ const MERGE_CHUNKS_THRESHOLD = 8;
13
+ export const FULL_COMPACT_RESCHEDULE_MARGIN_MS = 60 * 1000;
14
+ export var CompactionKind;
15
+ (function (CompactionKind) {
16
+ CompactionKind["Full"] = "full";
17
+ CompactionKind["Chunks"] = "chunks";
18
+ })(CompactionKind || (CompactionKind = {}));
19
+ export class CompactionContext {
20
+ lease;
21
+ kind;
22
+ decision;
23
+ rescheduleNotBefore;
24
+ targetOp;
25
+ constructor(lease, kind, decision, rescheduleNotBefore, targetOp) {
26
+ this.lease = lease;
27
+ this.kind = kind;
28
+ this.decision = decision;
29
+ this.rescheduleNotBefore = rescheduleNotBefore;
30
+ this.targetOp = targetOp;
31
+ }
32
+ get state() {
33
+ return this.lease.state;
34
+ }
35
+ get startedAt() {
36
+ return this.lease.startedAt;
37
+ }
38
+ get lastOp() {
39
+ return this.lease.lastOp;
40
+ }
41
+ }
42
+ export function bucketStats(state) {
43
+ return {
44
+ count: state.bucket_stats.count,
45
+ bytes: state.bucket_stats.bytes,
46
+ chunks: state.bucket_stats.chunks
47
+ };
48
+ }
49
+ export function emptyBucketStats() {
50
+ return { count: 0, bytes: 0n, chunks: 0, checksum: 0 };
51
+ }
52
+ export function statsForDocument(document) {
53
+ return {
54
+ count: document.count,
55
+ bytes: BigInt(document.size),
56
+ chunks: 1,
57
+ checksum: addChecksums(0, Number(document.checksum))
58
+ };
59
+ }
60
+ export function statsForDocuments(documents) {
61
+ let result = emptyBucketStats();
62
+ for (const document of documents) {
63
+ result = combineAdjacentStats(result, statsForDocument(document));
64
+ }
65
+ return result;
66
+ }
67
+ /** A scheduled bucket always has writes awaiting a full compact. */
68
+ export function firstUncompactedWrite(state) {
69
+ if (state.first_uncompacted_write == null) {
70
+ throw new ReplicationAssertionError(`Scheduled V3 bucket ${state._id.b} has no first uncompacted write`);
71
+ }
72
+ return state.first_uncompacted_write;
73
+ }
74
+ export function combineChunkStats(previous, compactedTail, overlappingCompactedChunk) {
75
+ return {
76
+ count: previous.count - overlappingCompactedChunk.count + compactedTail.count,
77
+ bytes: previous.bytes - overlappingCompactedChunk.bytes + compactedTail.bytes,
78
+ chunks: previous.chunks - 1 + compactedTail.chunks,
79
+ checksum: addChecksums(addChecksums(Number(previous.checksum), -overlappingCompactedChunk.checksum), compactedTail.checksum)
80
+ };
81
+ }
82
+ export function combineAdjacentStats(first, second) {
83
+ return {
84
+ count: first.count + second.count,
85
+ bytes: first.bytes + second.bytes,
86
+ chunks: first.chunks + second.chunks,
87
+ checksum: addChecksums(first.checksum, second.checksum)
88
+ };
89
+ }
90
+ export function applyCompactionDelta(total, before, after) {
91
+ return {
92
+ count: total.count - before.count + after.count,
93
+ bytes: total.bytes - before.bytes + after.bytes,
94
+ chunks: total.chunks - before.chunks + after.chunks
95
+ };
96
+ }
97
+ /** Replace one stored range in an accumulated statistics snapshot. */
98
+ export function applyStatsReplacement(total, before, after) {
99
+ return {
100
+ ...applyCompactionDelta(total, before, after),
101
+ checksum: addChecksums(addChecksums(total.checksum, -before.checksum), after.checksum)
102
+ };
103
+ }
104
+ /**
105
+ * This checks that the bucket state hasn't changed by a concurrent write since we checked.
106
+ *
107
+ * If it has changed, we'll re-check in the next batch.
108
+ */
109
+ export function unclaimedSnapshotFilter(state) {
110
+ return {
111
+ _id: state._id,
112
+ last_op: state.last_op,
113
+ next_compact_check: state.next_compact_check,
114
+ first_uncompacted_write: state.first_uncompacted_write ?? { $exists: false },
115
+ bucket_stats: state.bucket_stats,
116
+ compacted_state: state.compacted_state ?? { $exists: false },
117
+ last_full_compact: state.last_full_compact ?? { $exists: false },
118
+ ...AVAILABLE_LEASE_EXPR
119
+ };
120
+ }
121
+ /**
122
+ * Calculate the earliest full compaction time from the first uncompacted
123
+ * write, bounded by the maximum retention interval.
124
+ */
125
+ export function fullCompactionCheckAt(state, config) {
126
+ const firstWrite = firstUncompactedWrite(state);
127
+ const stats = bucketStats(state);
128
+ const lastFull = state.last_full_compact;
129
+ // The number of operations since the last full compact.
130
+ // We may make this more specific in the future, to track new updates and deletes only, ignoring
131
+ // full new inserts, but that requires more granular tracking when replicating.
132
+ const uncompactedCount = lastFull == null ? stats.count : Math.max(0, stats.count - lastFull.count);
133
+ const compactedRows = lastFull?.puts ?? 0;
134
+ // If no full compact has ever been performed: ratio = 1, compact after minCompactFullIntervalMs.
135
+ // If every row has been updated or deleted exactly once since the last full compact: ratio = 0.5, compact after minCompactFullIntervalMs * 2.
136
+ // If 10% of rows has been updated since the last full compact, compact after minCompactFullIntervalMs * 11.
137
+ // If every row has been updated multiple times, the ratio tends closer to 1 again.
138
+ const ratio = uncompactedCount == 0 ? 0 : uncompactedCount / (compactedRows + uncompactedCount);
139
+ const fullIntervalMs = ratio == 0 ? config.maxCompactFullIntervalMs : config.minCompactFullIntervalMs / ratio;
140
+ return new Date(firstWrite.getTime() + Math.min(fullIntervalMs, config.maxCompactFullIntervalMs));
141
+ }
142
+ export function chooseCompactionKind(state, now, config) {
143
+ // For chunk compaction, we consider the number of chunks added.
144
+ // Right now, we trigger a compact if the interval has passed and at least a threshold of chunks were added.
145
+ // A future policy could also use bytes per chunk or records per chunk to
146
+ // decide when to compact.
147
+ const fullCheckAt = fullCompactionCheckAt(state, config);
148
+ // Schedule a little late so a worker using a slightly earlier clock does
149
+ // not wake before the exact full-compaction condition is true.
150
+ const fullCheckWithMargin = new Date(fullCheckAt.getTime() + FULL_COMPACT_RESCHEDULE_MARGIN_MS);
151
+ const compacted = state.compacted_state;
152
+ const chunksSinceCompact = Math.max(0, state.bucket_stats.chunks - (compacted?.chunks ?? 0));
153
+ const shouldCompactChunks = chunksSinceCompact >= MERGE_CHUNKS_THRESHOLD;
154
+ const canCheckChunks = compacted == null || now.getTime() - compacted.at.getTime() >= config.minCompactChunkIntervalMs;
155
+ // Too few new chunks cannot make chunk compaction eligible. Do not poll this
156
+ // bucket at the chunk-compaction interval; only wake it for its full-compact check.
157
+ const nextCompactCheck = !shouldCompactChunks
158
+ ? fullCheckWithMargin
159
+ : {
160
+ $min: [
161
+ fullCheckWithMargin,
162
+ { $dateAdd: { startDate: '$$NOW', unit: 'millisecond', amount: config.minCompactChunkIntervalMs } }
163
+ ]
164
+ };
165
+ let kind = null;
166
+ if (now >= fullCheckAt) {
167
+ kind = CompactionKind.Full;
168
+ }
169
+ else if (canCheckChunks && shouldCompactChunks) {
170
+ kind = CompactionKind.Chunks;
171
+ }
172
+ return {
173
+ kind,
174
+ nextCompactCheck
175
+ };
176
+ }
177
+ export function forcedCompactionKind(state, forceKind, config) {
178
+ if (forceKind == null) {
179
+ return null;
180
+ }
181
+ const maxOpId = config.maxOpIdCap == null || state.last_op < config.maxOpIdCap ? state.last_op : config.maxOpIdCap;
182
+ return state.compacted_state == null || state.compacted_state.op_id < maxOpId ? forceKind : null;
183
+ }
184
+ /**
185
+ * Read one bounded prefix from a compaction cursor.
186
+ *
187
+ * The document that would cross the byte limit is deliberately not returned:
188
+ * pagination resumes past the last returned `_id`, so that document remains
189
+ * eligible for the next query. The first document is always accepted to
190
+ * ensure progress when a single document exceeds the configured byte limit.
191
+ *
192
+ * `hasMore` is conservative when the document limit is reached. An extra empty
193
+ * query is preferable to exhausting the cursor just to determine whether the
194
+ * limited MongoDB query contained another document.
195
+ */
196
+ export async function readCompactionBatch(cursor, options) {
197
+ const documents = [];
198
+ let cumulativeBytes = 0;
199
+ try {
200
+ for await (const document of cursor) {
201
+ if (documents.length > 0 && cumulativeBytes + document.size > options.byteLimit) {
202
+ return { documents, hasMore: true };
203
+ }
204
+ documents.push(document);
205
+ cumulativeBytes += document.size;
206
+ if (documents.length >= options.documentLimit) {
207
+ return { documents, hasMore: true };
208
+ }
209
+ }
210
+ return { documents, hasMore: false };
211
+ }
212
+ finally {
213
+ await cursor.close();
214
+ }
215
+ }
216
+ //# sourceMappingURL=compact-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compact-utils.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/compact-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAgB,MAAM,yBAAyB,CAAC;AAErE,OAAO,EAAE,oBAAoB,EAAmB,MAAM,sBAAsB,CAAC;AAG7E;;;;;;;GAOG;AACH,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAEjC,MAAM,CAAC,MAAM,iCAAiC,GAAG,EAAE,GAAG,IAAI,CAAC;AAsB3D,MAAM,CAAN,IAAY,cAG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C,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Writers use this delay before scheduling their first chunk compaction.
3
+ * Initial replication includes the same delay when it picks up that work.
4
+ */
5
+ export declare const DEFAULT_MIN_COMPACT_CHUNK_INTERVAL_MS: number;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Writers use this delay before scheduling their first chunk compaction.
3
+ * Initial replication includes the same delay when it picks up that work.
4
+ */
5
+ export const DEFAULT_MIN_COMPACT_CHUNK_INTERVAL_MS = 5 * 60 * 1000;
6
+ //# sourceMappingURL=compaction-constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compaction-constants.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/compaction-constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC"}
@@ -1,12 +1,11 @@
1
- import { InternalOpId, SerializedSyncPlan, SyncRuleState } from '@powersync/service-core';
2
- import { BucketDefinitionId, ParameterIndexId } from '@powersync/service-sync-rules';
1
+ import { InternalOpId, JsonValue, PersistedDefinitionMapping, SerializedSyncPlan, SyncRuleState } from '@powersync/service-core';
2
+ import { BucketDefinitionId, EventDefinitionId, ParameterIndexId, ScopedParameterLookup, SqliteJsonValue } from '@powersync/service-sync-rules';
3
3
  import * as bson from 'bson';
4
- import { BucketDataDoc, BucketKey } from '../common/BucketDataDoc.js';
5
- import { BucketDataDocumentBase, BucketDataKey, BucketParameterDocumentBase, BucketStateDocumentBase, CurrentBucket, ReplicaId, SourceTableDocument, SourceTableKey, SyncRuleCheckpointFields, SyncRuleDocumentBase, TaggedBucketParameterDocument } from '../models.js';
4
+ import { BucketDataKey, BucketParameterDocumentBase, CurrentBucket, OpType, ReplicaId, SourceTableDocumentSnapshotStatus, SourceTableKey, SyncRuleCheckpointFields, SyncRuleDocumentBase, TaggedBucketParameterDocument } from '../models.js';
6
5
  /**
7
6
  * Embedded in sync_rules.sync_configs.
8
7
  */
9
- export interface SyncRuleConfigStateV3 extends SyncRuleCheckpointFields<bigint | null> {
8
+ export interface SyncRuleConfigStateV3 extends SyncRuleCheckpointFields {
10
9
  _id: bson.ObjectId;
11
10
  /**
12
11
  * If false, we cannot create any checkpoints.
@@ -30,6 +29,29 @@ export interface ReplicationStreamDocumentV3 extends SyncRuleDocumentBase {
30
29
  * but the model allows multiple configs in any state.
31
30
  */
32
31
  sync_configs: SyncRuleConfigStateV3[];
32
+ /**
33
+ * The monotonic head of the stream's op sequence: the highest op id persisted to bucket data,
34
+ * whether or not yet covered by a checkpoint.
35
+ *
36
+ * This is shared across all sync configs of the stream (they share the global op sequence).
37
+ * It is never cleared, only `$max`-advanced. A newly-appended config that replicates nothing
38
+ * adopts this value as its checkpoint rather than starting at 0.
39
+ *
40
+ * Stored as a mongo Long, nullable.
41
+ */
42
+ last_persisted_op?: bigint | null;
43
+ /**
44
+ * The stream's replication position: all source changes up to this LSN have been processed,
45
+ * and the resulting ops persisted. Replication resumes from here.
46
+ *
47
+ * Like {@link last_persisted_op}, this is shared across all sync configs of the stream -
48
+ * per-config last_checkpoint_lsn values are consistency markers, not replication positions.
49
+ *
50
+ * Set via setResumeLsn() (snapshot start, and per-batch progress during streaming), and
51
+ * advanced on every commit/keepalive - including checkpoint-blocked ones, since commit
52
+ * flushes first and blocking only delays consistency markers, not data persistence.
53
+ */
54
+ resume_lsn?: string | null;
33
55
  }
34
56
  /**
35
57
  * Static sync config definition.
@@ -49,17 +71,10 @@ export interface SyncConfigDefinition {
49
71
  */
50
72
  replication_stream_id: number;
51
73
  content: string;
74
+ /** Optional operator-supplied label identifying this sync config version. */
75
+ version_label?: string;
52
76
  serialized_plan?: SerializedSyncPlan | null;
53
- rule_mapping: {
54
- /**
55
- * Map of uniqueName -> id, unique per replication stream.
56
- */
57
- definitions: Record<string, string>;
58
- /**
59
- * Map of (lookupName, queryId) -> id, unique per replication stream.
60
- */
61
- parameter_indexes: Record<string, string>;
62
- };
77
+ rule_mapping: PersistedDefinitionMapping;
63
78
  }
64
79
  export interface CurrentBucketV3 extends CurrentBucket {
65
80
  def: BucketDefinitionId;
@@ -83,19 +98,168 @@ export interface CurrentDataDocumentV3 {
83
98
  export interface BucketParameterDocumentV3 extends BucketParameterDocumentBase<SourceTableKey> {
84
99
  }
85
100
  export type BucketDataKeyV3 = BucketDataKey;
86
- export interface BucketDataDocumentV3 extends BucketDataDocumentBase {
87
- _id: BucketDataKeyV3;
88
- }
89
- export declare function serializeBucketDataV3(document: BucketDataDoc): BucketDataDocumentV3;
90
- export declare function loadBucketDataDocumentV3(context: Pick<BucketKey, 'replicationStreamId' | 'definitionId'>, doc: BucketDataDocumentV3): BucketDataDoc;
91
101
  export declare function taggedBucketParameterDocumentToV3(document: TaggedBucketParameterDocument): BucketParameterDocumentV3;
92
- export interface SourceTableDocumentV3 extends SourceTableDocument {
102
+ export interface ReplicaIdColumn {
103
+ name: string;
104
+ type_oid?: number;
105
+ type?: string;
106
+ }
107
+ export interface SourceTableDocumentV3 {
108
+ _id: bson.ObjectId;
109
+ connection_id: number;
110
+ relation_id: number | string | undefined;
111
+ schema_name: string;
112
+ table_name: string;
113
+ replica_id_columns: ReplicaIdColumn[];
114
+ snapshot_done: boolean;
115
+ snapshot_status: SourceTableDocumentSnapshotStatus | undefined;
93
116
  bucket_data_source_ids: BucketDefinitionId[];
94
117
  parameter_lookup_source_ids: ParameterIndexId[];
118
+ /**
119
+ * Stream-local ids of the compiled event definitions evaluated by this source table.
120
+ */
121
+ event_definition_ids: EventDefinitionId[];
95
122
  latest_pending_delete?: InternalOpId | undefined;
123
+ /**
124
+ * Source-specific metadata. Absent for legacy records.
125
+ */
126
+ source_metadata?: JsonValue;
96
127
  }
97
- export interface BucketStateDocumentV3 extends BucketStateDocumentBase {
98
- _id: BucketStateDocumentBase['_id'] & {
128
+ export interface BucketStateDocumentV3 {
129
+ _id: {
130
+ b: string;
99
131
  d: BucketDefinitionId;
100
132
  };
133
+ /** Must always identify an actual operation in this logical stream. */
134
+ last_op: bigint;
135
+ /** The next time a compact worker should inspect this bucket. */
136
+ next_compact_check: Date | undefined;
137
+ /**
138
+ * Scheduling epoch for work not covered by a full compact. Writers set the
139
+ * first actual write time; a partial full compact advances it to completion.
140
+ */
141
+ first_uncompacted_write: Date | undefined;
142
+ /**
143
+ * A checksum cache and the statistics captured by the latest compact (full
144
+ * or chunk). Keeping these separate from bucket_stats lets writers only
145
+ * update one set of counters.
146
+ */
147
+ compacted_state?: {
148
+ op_id: InternalOpId;
149
+ checksum: bigint;
150
+ count: number;
151
+ bytes: bigint;
152
+ at: Date;
153
+ chunks: number;
154
+ };
155
+ /** Statistics for the prefix covered by the most recent full compact. */
156
+ last_full_compact?: {
157
+ op_id: InternalOpId;
158
+ count: number;
159
+ at: Date;
160
+ puts: number;
161
+ };
162
+ /** Current aggregate bucket statistics, maintained by writers and compactors. */
163
+ bucket_stats: {
164
+ count: number;
165
+ bytes: bigint;
166
+ chunks: number;
167
+ };
168
+ /** A short-lived ownership marker used to distribute bucket compaction. */
169
+ compact_lease?: {
170
+ expires_at: Date;
171
+ id: unknown;
172
+ };
173
+ }
174
+ export interface BucketOperation {
175
+ o: bigint;
176
+ op: OpType;
177
+ source_table?: bson.ObjectId;
178
+ source_key?: ReplicaId;
179
+ subkey?: string;
180
+ table?: string;
181
+ row_id?: string;
182
+ checksum: bigint;
183
+ data: string | null;
184
+ }
185
+ export interface StorageRef {
186
+ path: string;
187
+ file_size: number;
188
+ }
189
+ export interface ObjectStorageUsageDocument {
190
+ _id: {
191
+ g: number;
192
+ w: string;
193
+ };
194
+ updated_at: Date;
195
+ definitions: Record<BucketDefinitionId, bigint>;
196
+ }
197
+ /** An S3 object that may be deleted once its grace period has elapsed. */
198
+ export interface ObjectStorageDeletionMarker {
199
+ _id: bson.ObjectId;
200
+ path: string;
201
+ delete_after: Date;
202
+ }
203
+ /**
204
+ * A non-empty chunk of a bucket's ordered operation stream.
205
+ *
206
+ * All writers maintain these invariants:
207
+ *
208
+ * - `ops` is non-empty and strictly ordered by `o`.
209
+ * - `min_op` is `ops[0].o` and `_id.o` is `ops[ops.length - 1].o`.
210
+ * - Documents for the same bucket have ordered, disjoint operation ranges,
211
+ * although gaps between ranges are allowed.
212
+ * - `checksum` is the sum of every operation checksum and `count` is
213
+ * `ops.length`.
214
+ *
215
+ * Metadata-only checksum and data queries rely on these invariants to identify
216
+ * boundary-straddling documents without reading `ops`.
217
+ */
218
+ export interface BucketDataDocumentV3 {
219
+ _id: BucketDataKey;
220
+ min_op: bigint;
221
+ checksum: bigint;
222
+ count: number;
223
+ size: number;
224
+ /**
225
+ * The greatest operation boundary that influenced this document's contents.
226
+ * Bucket-data reads propagate it so serving an earlier checkpoint can be
227
+ * invalidated when compaction changed the operations being returned.
228
+ */
229
+ target_op?: bigint | null;
230
+ ops?: BucketOperation[];
231
+ storage_ref?: StorageRef;
232
+ /**
233
+ * Present (and always true) when this document contains a CLEAR operation.
234
+ * In that case, this is the first document in the bucket: all preceding
235
+ * documents have been removed.
236
+ */
237
+ has_clear_op?: true;
238
+ }
239
+ /**
240
+ * v3 Custom checkpoints (new name for legacy write checkpoints) are related to
241
+ * a replication stream and a specific event (in a sync config) which created them.
242
+ * Unchanged events, between sync configs, can share the documents.
243
+ * For v3, we store each replication stream's custom checkpoint requests in their own collection:
244
+ * `custom_checkpoint_requests_${replicationStreamId}_${eventId}`
245
+ */
246
+ export interface CustomCheckpointRequestDocumentV3 {
247
+ _id: bson.ObjectId;
248
+ user_id: string;
249
+ checkpoint: bigint;
250
+ /**
251
+ * Unlike managed write checkpoints, custom write checkpoints are flushed together with
252
+ * normal ops. This means we can assign an op_id for ordering / correlating with read checkpoints.
253
+ *
254
+ * This is not unique - multiple write checkpoints can have the same op_id.
255
+ */
256
+ op_id?: InternalOpId;
257
+ /**
258
+ * Set when this checkpoint was created from a client-supplied checkpoint
259
+ * request rather than a persistent custom write checkpoint.
260
+ */
261
+ checkpoint_requested_at?: Date | null;
101
262
  }
263
+ export declare function serializeParameterLookup(lookup: ScopedParameterLookup): bson.Binary;
264
+ export declare function deserializeParameterLookup(lookup: bson.Binary, indexId: ParameterIndexId): SqliteJsonValue[];
265
+ export declare function taggedBucketParameterDocumentToTagged(document: TaggedBucketParameterDocument): BucketParameterDocumentV3;
@@ -1,33 +1,16 @@
1
- export function serializeBucketDataV3(document) {
2
- const { bucketKey, o } = document;
3
- return {
4
- _id: {
5
- b: bucketKey.bucket,
6
- o: o
7
- },
8
- // List fields directly, so that we don't accidentally persist any unknown fields
9
- op: document.op,
10
- source_table: document.source_table,
11
- source_key: document.source_key,
12
- table: document.table,
13
- row_id: document.row_id,
14
- checksum: document.checksum,
15
- data: document.data,
16
- target_op: document.target_op
17
- };
1
+ import { deserializeParameterLookup as deserializeParameterLookupCore } from '@powersync/service-core';
2
+ import * as bson from 'bson';
3
+ export function taggedBucketParameterDocumentToV3(document) {
4
+ const { index: _index, ...rest } = document;
5
+ return rest;
18
6
  }
19
- export function loadBucketDataDocumentV3(context, doc) {
20
- const { _id, ...rest } = doc;
21
- return {
22
- bucketKey: {
23
- ...context,
24
- bucket: _id.b
25
- },
26
- o: _id.o,
27
- ...rest
28
- };
7
+ export function serializeParameterLookup(lookup) {
8
+ return new bson.Binary(bson.serialize({ l: lookup.values.slice(2) }));
29
9
  }
30
- export function taggedBucketParameterDocumentToV3(document) {
10
+ export function deserializeParameterLookup(lookup, indexId) {
11
+ return [indexId, '', ...deserializeParameterLookupCore(lookup)];
12
+ }
13
+ export function taggedBucketParameterDocumentToTagged(document) {
31
14
  const { index: _index, ...rest } = document;
32
15
  return rest;
33
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/models.ts"],"names":[],"mappings":"AAkHA,MAAM,UAAU,qBAAqB,CAAC,QAAuB;IAC3D,MAAM,EAAE,SAAS,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,IAAiC,CAAC;AAC3C,CAAC;AAkLD,MAAM,UAAU,wBAAwB,CAAC,MAA6B;IACpE,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,MAAmB,EAAE,OAAyB;IACvF,OAAO,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,8BAA8B,CAAC,MAAM,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,qCAAqC,CACnD,QAAuC;IAEvC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;IAC5C,OAAO,IAAiC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { PerformanceTracer } from '@powersync/service-core';
2
+ import { BucketDataDocumentV3, BucketOperation } from '../models.js';
3
+ import { ObjectStorage, ObjectStorageOperationOptions } from './ObjectStorage.js';
4
+ export declare class BucketDataObjectStorage {
5
+ private readonly storage;
6
+ constructor(storage: ObjectStorage);
7
+ store(path: string, ops: BucketOperation[], options?: ObjectStorageOperationOptions): Promise<{
8
+ fileSize: number;
9
+ }>;
10
+ retrieve(path: string, options: ObjectStorageOperationOptions): Promise<BucketOperation[]>;
11
+ delete(paths: string[], options?: ObjectStorageOperationOptions): Promise<void>;
12
+ }
13
+ /**
14
+ * Load offloaded operations and patch them onto their MongoDB metadata documents.
15
+ * The object-storage implementation is responsible for limiting request
16
+ * concurrency across all callers.
17
+ */
18
+ export declare function hydrateBucketDataDocuments(documents: BucketDataDocumentV3[], objectStorage: ObjectStorage | undefined, options: ObjectStorageOperationOptions & {
19
+ tracer?: PerformanceTracer<string>;
20
+ }): Promise<void>;
@@ -0,0 +1,48 @@
1
+ import { storage } from '@powersync/service-core';
2
+ import * as bson from 'bson';
3
+ export class BucketDataObjectStorage {
4
+ storage;
5
+ constructor(storage) {
6
+ this.storage = storage;
7
+ }
8
+ async store(path, ops, options) {
9
+ const bsonBuffer = bson.serialize({ ops });
10
+ await this.storage.put(path, bsonBuffer, { contentType: 'application/bson', contentEncoding: null }, options);
11
+ return { fileSize: bsonBuffer.byteLength };
12
+ }
13
+ async retrieve(path, options) {
14
+ const { data, metadata } = await this.storage.get(path, { signal: options.signal });
15
+ if (metadata.contentEncoding != null) {
16
+ throw new Error(`Unexpected content encoding: ${metadata.contentEncoding}`);
17
+ }
18
+ if (metadata.contentType !== 'application/bson') {
19
+ throw new Error(`Unexpected content type: ${metadata.contentType}`);
20
+ }
21
+ const wrapper = bson.deserialize(data, storage.BSON_DESERIALIZE_INTERNAL_OPTIONS);
22
+ return wrapper.ops;
23
+ }
24
+ async delete(paths, options) {
25
+ return this.storage.delete(paths, options);
26
+ }
27
+ }
28
+ /**
29
+ * Load offloaded operations and patch them onto their MongoDB metadata documents.
30
+ * The object-storage implementation is responsible for limiting request
31
+ * concurrency across all callers.
32
+ */
33
+ export async function hydrateBucketDataDocuments(documents, objectStorage, options) {
34
+ if (!objectStorage) {
35
+ return;
36
+ }
37
+ options.signal?.throwIfAborted();
38
+ const store = new BucketDataObjectStorage(objectStorage);
39
+ const storedDocuments = documents.filter((document) => document.storage_ref);
40
+ if (storedDocuments.length == 0) {
41
+ return;
42
+ }
43
+ using _ = options?.tracer?.span('s3', 'read');
44
+ await Promise.all(storedDocuments.map(async (document) => {
45
+ document.ops = await store.retrieve(document.storage_ref.path, { signal: options.signal });
46
+ }));
47
+ }
48
+ //# sourceMappingURL=BucketDataObjectStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BucketDataObjectStorage.js","sourceRoot":"","sources":["../../../../../src/storage/implementation/v3/object-storage/BucketDataObjectStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,KAAK,IAAI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OAAO,CAAC,CAAC;IAC7C,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,SAAiC,EACjC,aAAwC,EACxC,OAA+E;IAE/E,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,OAAO;IACT,CAAC;IAED,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,KAAK,GAAG,IAAI,uBAAuB,CAAC,aAAa,CAAC,CAAC;IACzD,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC7E,IAAI,eAAe,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAChC,OAAO;IACT,CAAC;IACD,MAAM,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC9C,MAAM,OAAO,CAAC,GAAG,CACf,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QACrC,QAAQ,CAAC,GAAG,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAY,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9F,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,33 @@
1
+ export interface ObjectStoragePutMetadata {
2
+ contentType: string;
3
+ contentEncoding: string | null;
4
+ }
5
+ export declare class ObjectStorageError extends Error {
6
+ readonly retryable: boolean;
7
+ constructor(message: string, options: {
8
+ cause: unknown;
9
+ retryable: boolean;
10
+ });
11
+ }
12
+ export declare function isRetryableObjectStorageError(error: unknown): error is ObjectStorageError;
13
+ export interface ObjectStorageOperationOptions {
14
+ /**
15
+ * Cancels the operation, including while it waits for a concurrency slot.
16
+ *
17
+ * Operations are bounded by their own timeouts regardless, but a signal releases the slot as
18
+ * soon as the caller no longer needs the result.
19
+ */
20
+ signal?: AbortSignal;
21
+ }
22
+ export interface ObjectStorage {
23
+ put(path: string, data: Uint8Array, metadata: ObjectStoragePutMetadata, options?: ObjectStorageOperationOptions): Promise<void>;
24
+ get(path: string, options?: ObjectStorageOperationOptions): Promise<{
25
+ data: Uint8Array;
26
+ metadata: ObjectStoragePutMetadata;
27
+ }>;
28
+ list(prefix: string, options?: ObjectStorageOperationOptions): AsyncIterable<string>;
29
+ delete(paths: string[], options?: ObjectStorageOperationOptions): Promise<void>;
30
+ deletePrefix(prefix: string, options?: ObjectStorageOperationOptions): Promise<{
31
+ objectCount: number;
32
+ }>;
33
+ }