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

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 (239) hide show
  1. package/CHANGELOG.md +101 -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 +41 -16
  6. package/dist/storage/MongoBucketStorage.js +226 -71
  7. package/dist/storage/MongoBucketStorage.js.map +1 -1
  8. package/dist/storage/implementation/MongoBucketBatch.d.ts +56 -25
  9. package/dist/storage/implementation/MongoBucketBatch.js +110 -62
  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 +17 -19
  15. package/dist/storage/implementation/MongoCompactor.js +80 -263
  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 +7 -6
  21. package/dist/storage/implementation/MongoParameterCompactor.js +25 -2
  22. package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
  23. package/dist/storage/implementation/MongoParsedSyncConfigSet.d.ts +13 -0
  24. package/dist/storage/implementation/MongoParsedSyncConfigSet.js +64 -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 +123 -0
  31. package/dist/storage/implementation/MongoPersistedSyncConfigContent.js.map +1 -0
  32. package/dist/storage/implementation/MongoStorageProvider.js +39 -4
  33. package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
  34. package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +57 -29
  35. package/dist/storage/implementation/MongoSyncBucketStorage.js +87 -61
  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 +3 -3
  39. package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
  40. package/dist/storage/implementation/MongoWriteCheckpointAPI.d.ts +2 -1
  41. package/dist/storage/implementation/MongoWriteCheckpointAPI.js +171 -24
  42. package/dist/storage/implementation/MongoWriteCheckpointAPI.js.map +1 -1
  43. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.d.ts +8 -0
  44. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js +2 -0
  45. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js.map +1 -0
  46. package/dist/storage/implementation/common/PersistedBatch.d.ts +7 -2
  47. package/dist/storage/implementation/common/PersistedBatch.js +12 -0
  48. package/dist/storage/implementation/common/PersistedBatch.js.map +1 -1
  49. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +1 -1
  50. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -1
  51. package/dist/storage/implementation/createMongoSyncBucketStorage.d.ts +2 -2
  52. package/dist/storage/implementation/createMongoSyncBucketStorage.js +4 -4
  53. package/dist/storage/implementation/createMongoSyncBucketStorage.js.map +1 -1
  54. package/dist/storage/implementation/db.js +17 -15
  55. package/dist/storage/implementation/db.js.map +1 -1
  56. package/dist/storage/implementation/models.d.ts +20 -13
  57. package/dist/storage/implementation/models.js.map +1 -1
  58. package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +9 -1
  59. package/dist/storage/implementation/v1/MongoBucketBatchV1.js +61 -29
  60. package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -1
  61. package/dist/storage/implementation/v1/MongoChecksumsV1.d.ts +4 -4
  62. package/dist/storage/implementation/v1/MongoChecksumsV1.js +119 -7
  63. package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -1
  64. package/dist/storage/implementation/v1/MongoCompactorV1.d.ts +11 -2
  65. package/dist/storage/implementation/v1/MongoCompactorV1.js +251 -2
  66. package/dist/storage/implementation/v1/MongoCompactorV1.js.map +1 -1
  67. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +18 -19
  68. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +82 -58
  69. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -1
  70. package/dist/storage/implementation/v1/SingleBucketStoreV1.d.ts +9 -10
  71. package/dist/storage/implementation/v1/SingleBucketStoreV1.js +2 -8
  72. package/dist/storage/implementation/v1/SingleBucketStoreV1.js.map +1 -1
  73. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.d.ts +2 -1
  74. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js +3 -0
  75. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js.map +1 -1
  76. package/dist/storage/implementation/v1/models.d.ts +10 -1
  77. package/dist/storage/implementation/v3/BucketDataContextV3.d.ts +13 -0
  78. package/dist/storage/implementation/v3/BucketDataContextV3.js +23 -0
  79. package/dist/storage/implementation/v3/BucketDataContextV3.js.map +1 -0
  80. package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +8 -4
  81. package/dist/storage/implementation/v3/MongoBucketBatchV3.js +309 -259
  82. package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
  83. package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +30 -9
  84. package/dist/storage/implementation/v3/MongoChecksumsV3.js +161 -20
  85. package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -1
  86. package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +40 -2
  87. package/dist/storage/implementation/v3/MongoCompactorV3.js +647 -23
  88. package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
  89. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.d.ts +67 -0
  90. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js +351 -0
  91. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js.map +1 -0
  92. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +45 -30
  93. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +272 -140
  94. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -1
  95. package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +6 -3
  96. package/dist/storage/implementation/v3/PersistedBatchV3.js +84 -21
  97. package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -1
  98. package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +3 -3
  99. package/dist/storage/implementation/v3/SourceRecordStoreV3.js +13 -11
  100. package/dist/storage/implementation/v3/SourceRecordStoreV3.js.map +1 -1
  101. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +15 -13
  102. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +32 -27
  103. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -1
  104. package/dist/storage/implementation/v3/bucket-format.d.ts +13 -0
  105. package/dist/storage/implementation/v3/bucket-format.js +77 -0
  106. package/dist/storage/implementation/v3/bucket-format.js.map +1 -0
  107. package/dist/storage/implementation/v3/chunking.d.ts +10 -0
  108. package/dist/storage/implementation/v3/chunking.js +30 -0
  109. package/dist/storage/implementation/v3/chunking.js.map +1 -0
  110. package/dist/storage/implementation/v3/models.d.ts +101 -21
  111. package/dist/storage/implementation/v3/models.js +11 -28
  112. package/dist/storage/implementation/v3/models.js.map +1 -1
  113. package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.d.ts +21 -0
  114. package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js +44 -0
  115. package/dist/storage/implementation/v3/object-storage/BucketDataObjectStorage.js.map +1 -0
  116. package/dist/storage/implementation/v3/object-storage/ObjectStorage.d.ts +30 -0
  117. package/dist/storage/implementation/v3/object-storage/ObjectStorage.js +12 -0
  118. package/dist/storage/implementation/v3/object-storage/ObjectStorage.js.map +1 -0
  119. package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.d.ts +70 -0
  120. package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js +146 -0
  121. package/dist/storage/implementation/v3/object-storage/ObjectStorageLifecycle.js.map +1 -0
  122. package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.d.ts +42 -0
  123. package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js +285 -0
  124. package/dist/storage/implementation/v3/object-storage/S3ObjectStorage.js.map +1 -0
  125. package/dist/storage/implementation/v3/source-table-utils.d.ts +55 -0
  126. package/dist/storage/implementation/v3/source-table-utils.js +214 -0
  127. package/dist/storage/implementation/v3/source-table-utils.js.map +1 -0
  128. package/dist/storage/storage-index.d.ts +4 -4
  129. package/dist/storage/storage-index.js +4 -4
  130. package/dist/storage/storage-index.js.map +1 -1
  131. package/dist/types/types.d.ts +49 -3
  132. package/dist/types/types.js +48 -1
  133. package/dist/types/types.js.map +1 -1
  134. package/dist/utils/test-utils.d.ts +1 -2
  135. package/dist/utils/test-utils.js +7 -1
  136. package/dist/utils/test-utils.js.map +1 -1
  137. package/dist/utils/util.d.ts +9 -2
  138. package/dist/utils/util.js +128 -4
  139. package/dist/utils/util.js.map +1 -1
  140. package/package.json +12 -19
  141. package/src/migrations/db/migrations/1782950400000-checkpoint-requested-at-index.ts +55 -0
  142. package/src/storage/MongoBucketStorage.ts +347 -88
  143. package/src/storage/implementation/MongoBucketBatch.ts +147 -82
  144. package/src/storage/implementation/MongoChecksums.ts +93 -153
  145. package/src/storage/implementation/MongoCompactor.ts +102 -316
  146. package/src/storage/implementation/MongoHydrationState.ts +61 -0
  147. package/src/storage/implementation/MongoParameterCompactor.ts +25 -6
  148. package/src/storage/implementation/MongoParsedSyncConfigSet.ts +88 -0
  149. package/src/storage/implementation/MongoPersistedReplicationStream.ts +118 -0
  150. package/src/storage/implementation/MongoPersistedSyncConfigContent.ts +154 -0
  151. package/src/storage/implementation/MongoStorageProvider.ts +46 -4
  152. package/src/storage/implementation/MongoSyncBucketStorage.ts +121 -87
  153. package/src/storage/implementation/MongoSyncRulesLock.ts +7 -4
  154. package/src/storage/implementation/MongoWriteCheckpointAPI.ts +202 -28
  155. package/src/storage/implementation/common/MongoSyncBucketStorageCheckpoint.ts +9 -0
  156. package/src/storage/implementation/common/PersistedBatch.ts +19 -3
  157. package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +1 -1
  158. package/src/storage/implementation/createMongoSyncBucketStorage.ts +21 -7
  159. package/src/storage/implementation/db.ts +19 -20
  160. package/src/storage/implementation/models.ts +20 -14
  161. package/src/storage/implementation/v1/MongoBucketBatchV1.ts +75 -37
  162. package/src/storage/implementation/v1/MongoChecksumsV1.ts +154 -12
  163. package/src/storage/implementation/v1/MongoCompactorV1.ts +294 -9
  164. package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +142 -105
  165. package/src/storage/implementation/v1/SingleBucketStoreV1.ts +18 -27
  166. package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +11 -1
  167. package/src/storage/implementation/v1/models.ts +11 -1
  168. package/src/storage/implementation/v3/BucketDataContextV3.ts +32 -0
  169. package/src/storage/implementation/v3/MongoBucketBatchV3.ts +382 -321
  170. package/src/storage/implementation/v3/MongoChecksumsV3.ts +250 -32
  171. package/src/storage/implementation/v3/MongoCompactorV3.ts +847 -32
  172. package/src/storage/implementation/v3/MongoStoppedSyncConfigCleanup.ts +482 -0
  173. package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +359 -187
  174. package/src/storage/implementation/v3/PersistedBatchV3.ts +118 -37
  175. package/src/storage/implementation/v3/SourceRecordStoreV3.ts +12 -12
  176. package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +46 -36
  177. package/src/storage/implementation/v3/bucket-format.ts +97 -0
  178. package/src/storage/implementation/v3/chunking.ts +40 -0
  179. package/src/storage/implementation/v3/models.ts +132 -55
  180. package/src/storage/implementation/v3/object-storage/BucketDataObjectStorage.ts +54 -0
  181. package/src/storage/implementation/v3/object-storage/ObjectStorage.ts +29 -0
  182. package/src/storage/implementation/v3/object-storage/ObjectStorageLifecycle.ts +171 -0
  183. package/src/storage/implementation/v3/object-storage/S3ObjectStorage.ts +343 -0
  184. package/src/storage/implementation/v3/source-table-utils.ts +392 -0
  185. package/src/storage/storage-index.ts +12 -4
  186. package/src/types/types.ts +58 -1
  187. package/src/utils/test-utils.ts +8 -3
  188. package/src/utils/util.ts +185 -6
  189. package/test/src/__snapshots__/storage.test.ts.snap +0 -75
  190. package/test/src/__snapshots__/storage_sync.test.ts.snap +35 -617
  191. package/test/src/cleanup-stopped-sync-configs.test.ts +671 -0
  192. package/test/src/helpers/MemoryObjectStorage.ts +53 -0
  193. package/test/src/helpers/s3TestFactory.ts +69 -0
  194. package/test/src/object_storage_lifecycle.test.ts +59 -0
  195. package/test/src/setup.ts +6 -1
  196. package/test/src/storage.test.ts +227 -13
  197. package/test/src/storage_compacting.test.ts +1951 -12
  198. package/test/src/storage_object_storage_inline_threshold.test.ts +116 -0
  199. package/test/src/storage_s3_checksums.test.ts +191 -0
  200. package/test/src/storage_s3_compaction_lifecycle.test.ts +417 -0
  201. package/test/src/storage_s3_reading.test.ts +526 -0
  202. package/test/src/storage_s3_writing.test.ts +135 -0
  203. package/test/src/storage_sync.test.ts +1180 -73
  204. package/test/src/storeCurrentData.test.ts +227 -0
  205. package/test/src/util.ts +2 -1
  206. package/tsconfig.json +1 -4
  207. package/tsconfig.tsbuildinfo +1 -1
  208. package/dist/storage/implementation/BucketDefinitionMapping.d.ts +0 -15
  209. package/dist/storage/implementation/BucketDefinitionMapping.js +0 -58
  210. package/dist/storage/implementation/BucketDefinitionMapping.js.map +0 -1
  211. package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +0 -14
  212. package/dist/storage/implementation/MongoPersistedSyncRules.js +0 -67
  213. package/dist/storage/implementation/MongoPersistedSyncRules.js.map +0 -1
  214. package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +0 -29
  215. package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +0 -76
  216. package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +0 -1
  217. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.d.ts +0 -13
  218. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js +0 -2
  219. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js.map +0 -1
  220. package/dist/storage/implementation/common/SingleBucketStore.d.ts +0 -54
  221. package/dist/storage/implementation/common/SingleBucketStore.js +0 -3
  222. package/dist/storage/implementation/common/SingleBucketStore.js.map +0 -1
  223. package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +0 -9
  224. package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +0 -18
  225. package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +0 -1
  226. package/dist/storage/implementation/v3/MongoParameterLookupV3.d.ts +0 -4
  227. package/dist/storage/implementation/v3/MongoParameterLookupV3.js +0 -9
  228. package/dist/storage/implementation/v3/MongoParameterLookupV3.js.map +0 -1
  229. package/dist/storage/implementation/v3/SingleBucketStoreV3.d.ts +0 -18
  230. package/dist/storage/implementation/v3/SingleBucketStoreV3.js +0 -48
  231. package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +0 -1
  232. package/src/storage/implementation/BucketDefinitionMapping.ts +0 -75
  233. package/src/storage/implementation/MongoPersistedSyncRules.ts +0 -82
  234. package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +0 -101
  235. package/src/storage/implementation/common/MongoSyncBucketStorageContext.ts +0 -15
  236. package/src/storage/implementation/common/SingleBucketStore.ts +0 -63
  237. package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +0 -24
  238. package/src/storage/implementation/v3/MongoParameterLookupV3.ts +0 -11
  239. package/src/storage/implementation/v3/SingleBucketStoreV3.ts +0 -68
@@ -1,15 +0,0 @@
1
- import { BucketDataSource, BucketDefinitionId, ParameterIndexId, ParameterIndexLookupCreator, SyncConfigWithErrors } from '@powersync/service-sync-rules';
2
- import { SyncConfigDefinition } from '../storage-index.js';
3
- export declare class BucketDefinitionMapping {
4
- private definitions;
5
- private parameterLookupMapping;
6
- static fromSyncConfig(doc: Pick<SyncConfigDefinition, 'rule_mapping'>): BucketDefinitionMapping;
7
- static fromParsedSyncRules(syncRules: SyncConfigWithErrors): BucketDefinitionMapping;
8
- constructor(definitions?: Record<string, BucketDefinitionId>, parameterLookupMapping?: Record<string, ParameterIndexId>);
9
- bucketSourceId(source: BucketDataSource): BucketDefinitionId;
10
- allBucketDefinitionIds(): BucketDefinitionId[];
11
- allParameterIndexIds(): ParameterIndexId[];
12
- parameterLookupId(source: ParameterIndexLookupCreator): ParameterIndexId;
13
- private parameterLookupKey;
14
- serialize(): SyncConfigDefinition['rule_mapping'];
15
- }
@@ -1,58 +0,0 @@
1
- import { ServiceAssertionError } from '@powersync/lib-services-framework';
2
- export class BucketDefinitionMapping {
3
- definitions;
4
- parameterLookupMapping;
5
- static fromSyncConfig(doc) {
6
- return new BucketDefinitionMapping(doc.rule_mapping?.definitions ?? {}, doc.rule_mapping?.parameter_indexes ?? {});
7
- }
8
- static fromParsedSyncRules(syncRules) {
9
- const definitionNames = syncRules.config.bucketDataSources.map((source) => source.uniqueName).sort();
10
- const parameterKeys = syncRules.config.bucketParameterLookupSources
11
- .map((source) => `${source.sourceId.lookupName}#${source.sourceId.queryId}`)
12
- .sort();
13
- const definitions = {};
14
- const parameterLookups = {};
15
- for (const [index, uniqueName] of definitionNames.entries()) {
16
- definitions[uniqueName] = (index + 1).toString(16);
17
- }
18
- for (const [index, key] of parameterKeys.entries()) {
19
- parameterLookups[key] = (index + 1).toString(16);
20
- }
21
- return new BucketDefinitionMapping(definitions, parameterLookups);
22
- }
23
- constructor(definitions = {}, parameterLookupMapping = {}) {
24
- this.definitions = definitions;
25
- this.parameterLookupMapping = parameterLookupMapping;
26
- }
27
- bucketSourceId(source) {
28
- const defId = this.definitions[source.uniqueName];
29
- if (defId == null) {
30
- throw new ServiceAssertionError(`No mapping found for bucket source ${source.uniqueName}`);
31
- }
32
- return defId;
33
- }
34
- allBucketDefinitionIds() {
35
- return Object.values(this.definitions);
36
- }
37
- allParameterIndexIds() {
38
- return Object.values(this.parameterLookupMapping);
39
- }
40
- parameterLookupId(source) {
41
- const key = this.parameterLookupKey(source.sourceId.lookupName, source.sourceId.queryId);
42
- const defId = this.parameterLookupMapping[key];
43
- if (defId == null) {
44
- throw new ServiceAssertionError(`No mapping found for parameter lookup source ${key}`);
45
- }
46
- return defId;
47
- }
48
- parameterLookupKey(lookupName, queryId) {
49
- return `${lookupName}#${queryId}`;
50
- }
51
- serialize() {
52
- return {
53
- definitions: { ...this.definitions },
54
- parameter_indexes: { ...this.parameterLookupMapping }
55
- };
56
- }
57
- }
58
- //# sourceMappingURL=BucketDefinitionMapping.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BucketDefinitionMapping.js","sourceRoot":"","sources":["../../../src/storage/implementation/BucketDefinitionMapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAU1E,MAAM,OAAO,uBAAuB;IAyBxB;IACA;IAzBV,MAAM,CAAC,cAAc,CAAC,GAA+C;QACnE,OAAO,IAAI,uB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IAEJ,cAAc,CAAC,MAAwB;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAClD,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,qBAAqB,CAAC,sCAAsC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAC7F,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,sBAAsB;QACpB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,oBAAoB;QAClB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACpD,CAAC;IAED,iBAAiB,CAAC,MAAmC;QACnD,MAAM,GAAG,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACzF,MAAM,KAAK,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,qBAAqB,CAAC,gDAAgD,GAAG,EAAE,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,kBAAkB,CAAC,UAAkB,EAAE,OAAe;QAC5D,OAAO,GAAG,UAAU,IAAI,OAAO,EAAE,CAAC;IACpC,CAAC;IAED,SAAS;QACP,OAAO;YACL,WAAW,EAAE,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE;YACpC,iBAAiB,EAAE,EAAE,GAAG,IAAI,CAAC,sBAAsB,EAAE;SACtD,CAAC;IACJ,CAAC;CACF"}
@@ -1,14 +0,0 @@
1
- import { storage } from '@powersync/service-core';
2
- import { HydratedSyncConfig, HydrationState, SyncConfigWithErrors } from '@powersync/service-sync-rules';
3
- import { BucketDefinitionMapping } from './BucketDefinitionMapping.js';
4
- import { StorageConfig } from './models.js';
5
- export declare class MongoPersistedSyncRules implements storage.PersistedSyncRules {
6
- readonly id: number;
7
- readonly syncConfigWithErrors: SyncConfigWithErrors;
8
- readonly slot_name: string;
9
- private readonly mapping;
10
- private readonly storageConfig;
11
- readonly hydrationState: HydrationState;
12
- constructor(id: number, syncConfigWithErrors: SyncConfigWithErrors, slot_name: string, mapping: BucketDefinitionMapping | null, storageConfig: StorageConfig);
13
- hydratedSyncConfig(): HydratedSyncConfig;
14
- }
@@ -1,67 +0,0 @@
1
- import * as sqlite from 'node:sqlite';
2
- import { ServiceAssertionError } from '@powersync/lib-services-framework';
3
- import { CompatibilityOption, DEFAULT_HYDRATION_STATE, nodeSqlite, versionedHydrationState } from '@powersync/service-sync-rules';
4
- export class MongoPersistedSyncRules {
5
- id;
6
- syncConfigWithErrors;
7
- slot_name;
8
- mapping;
9
- storageConfig;
10
- hydrationState;
11
- constructor(id, syncConfigWithErrors, slot_name, mapping, storageConfig) {
12
- this.id = id;
13
- this.syncConfigWithErrors = syncConfigWithErrors;
14
- this.slot_name = slot_name;
15
- this.mapping = mapping;
16
- this.storageConfig = storageConfig;
17
- if (this.storageConfig.incrementalReprocessing) {
18
- if (this.mapping == null) {
19
- throw new ServiceAssertionError(`mapping is required for v3 storage`);
20
- }
21
- this.hydrationState = new MongoHydrationState(this.mapping, this.id);
22
- }
23
- else if (!this.syncConfigWithErrors.config.compatibility.isEnabled(CompatibilityOption.versionedBucketIds) &&
24
- !this.storageConfig.versionedBuckets) {
25
- this.hydrationState = DEFAULT_HYDRATION_STATE;
26
- }
27
- else {
28
- this.hydrationState = versionedHydrationState(this.id);
29
- }
30
- }
31
- hydratedSyncConfig() {
32
- return this.syncConfigWithErrors.config.hydrate({
33
- hydrationState: this.hydrationState,
34
- sqlite: nodeSqlite(sqlite)
35
- });
36
- }
37
- }
38
- class MongoHydrationState {
39
- mapping;
40
- version;
41
- constructor(mapping, version) {
42
- this.mapping = mapping;
43
- this.version = version;
44
- }
45
- getBucketSourceScope(source) {
46
- // Keep this aligned with versionedHydrationState() for now.
47
- //
48
- // Previous Mongo-specific behavior:
49
- // return {
50
- // bucketPrefix: defId,
51
- // source
52
- // };
53
- return {
54
- bucketPrefix: `${this.version}#${source.uniqueName}`,
55
- source
56
- };
57
- }
58
- getParameterIndexLookupScope(source) {
59
- const defId = this.mapping.parameterLookupId(source);
60
- return {
61
- lookupName: defId,
62
- queryId: '',
63
- source
64
- };
65
- }
66
- }
67
- //# sourceMappingURL=MongoPersistedSyncRules.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongoPersistedSyncRules.js","sourceRoot":"","sources":["../../../src/storage/implementation/MongoPersistedSyncRules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,OAAO,EAGL,mBAAmB,EACnB,uBAAuB,EAGvB,UAAU,EAIV,uBAAuB,EACxB,MAAM,+BAA+B,CAAC;AAIvC,MAAM,OAAO,uBAAuB;IAIhB;IACA;IACA;IACC;IACA;IAPH,cAAc,CAAiB;IAE/C,YACkB,EAAU,EACV,oBAA0C,EAC1C,SAAiB,EAChB,OAAuC,EACvC,aAA4B;QAJ7B,OAAE,GAAF,EAAE,CAAQ;QACV,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,cAAS,GAAT,SAAS,CAAQ;QAChB,YAAO,GAAP,OAAO,CAAgC;QACvC,kBAAa,GAAb,aAAa,CAAe;QAE7C,IAAI,IAAI,CAAC,aAAa,CAAC,uBAAuB,EAAE,CAAC;YAC/C,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;gBACzB,MAAM,IAAI,qBAAqB,CAAC,oCAAoC,CAAC,CAAC;YACxE,CAAC;YACD,IAAI,CAAC,cAAc,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QACvE,CAAC;aAAM,IACL,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,mBAAmB,CAAC,kBAAkB,CAAC;YACjG,CAAC,IAAI,CAAC,aAAa,CAAC,gBAAgB,EACpC,CAAC;YACD,IAAI,CAAC,cAAc,GAAG,uBAAuB,CAAC;QAChD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,cAAc,GAAG,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED,kBAAkB;QAChB,OAAO,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,OAAO,CAAC;YAC9C,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,mBAAmB;IAEJ;IACA;IAFnB,YACmB,OAAgC,EAChC,OAAe;QADf,YAAO,GAAP,OAAO,CAAyB;QAChC,YAAO,GAAP,OAAO,CAAQ;IAC/B,CAAC;IAEJ,oBAAoB,CAAC,MAAwB;QAC3C,4DAA4D;QAC5D,EAAE;QACF,oCAAoC;QACpC,WAAW;QACX,yBAAyB;QACzB,WAAW;QACX,KAAK;QACL,OAAO;YACL,YAAY,EAAE,GAAG,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,UAAU,EAAE;YACpD,MAAM;SACP,CAAC;IACJ,CAAC;IAED,4BAA4B,CAAC,MAAmC;QAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;QACrD,OAAO;YACL,UAAU,EAAE,KAAK;YACjB,OAAO,EAAE,EAAE;YACX,MAAM;SACP,CAAC;IACJ,CAAC;CACF"}
@@ -1,29 +0,0 @@
1
- import { mongo } from '@powersync/lib-service-mongodb';
2
- import { storage } from '@powersync/service-core';
3
- import * as bson from 'bson';
4
- import { ReplicationStreamDocumentV3, SyncConfigDefinition } from '../storage-index.js';
5
- import { BucketDefinitionMapping } from './BucketDefinitionMapping.js';
6
- import { MongoSyncRulesLock } from './MongoSyncRulesLock.js';
7
- import { PowerSyncMongo } from './db.js';
8
- import { SyncRuleDocumentV1 } from './v1/models.js';
9
- declare abstract class MongoPersistedSyncRulesContentBase extends storage.PersistedSyncRulesContent {
10
- protected readonly db: PowerSyncMongo;
11
- current_lock: MongoSyncRulesLock | null;
12
- readonly mapping: BucketDefinitionMapping;
13
- readonly syncConfigId: bson.ObjectId | null;
14
- protected constructor(db: PowerSyncMongo, options: ConstructorParameters<typeof storage.PersistedSyncRulesContent>[0] & {
15
- mapping: BucketDefinitionMapping;
16
- syncConfigId: bson.ObjectId | null;
17
- });
18
- getStorageConfig(): import("./models.js").StorageConfig;
19
- parsed(options: storage.ParseSyncRulesOptions): storage.PersistedSyncRules;
20
- lock(session?: mongo.ClientSession): Promise<MongoSyncRulesLock>;
21
- }
22
- export declare class MongoPersistedSyncRulesContentV1 extends MongoPersistedSyncRulesContentBase {
23
- constructor(db: PowerSyncMongo, doc: SyncRuleDocumentV1);
24
- }
25
- export declare class MongoPersistedSyncRulesContentV3 extends MongoPersistedSyncRulesContentBase {
26
- readonly syncConfigId: bson.ObjectId;
27
- constructor(db: PowerSyncMongo, doc: ReplicationStreamDocumentV3, config: SyncConfigDefinition);
28
- }
29
- export {};
@@ -1,76 +0,0 @@
1
- import { ServiceAssertionError } from '@powersync/lib-services-framework';
2
- import { storage, SyncRuleState } from '@powersync/service-core';
3
- import { BucketDefinitionMapping } from './BucketDefinitionMapping.js';
4
- import { MongoPersistedSyncRules } from './MongoPersistedSyncRules.js';
5
- import { MongoSyncRulesLock } from './MongoSyncRulesLock.js';
6
- import { getMongoStorageConfig } from './models.js';
7
- class MongoPersistedSyncRulesContentBase extends storage.PersistedSyncRulesContent {
8
- db;
9
- current_lock = null;
10
- mapping;
11
- syncConfigId;
12
- constructor(db, options) {
13
- const { mapping, syncConfigId, ...base } = options;
14
- super(base);
15
- this.db = db;
16
- this.mapping = mapping;
17
- this.syncConfigId = syncConfigId;
18
- }
19
- getStorageConfig() {
20
- return getMongoStorageConfig(this.storageVersion);
21
- }
22
- parsed(options) {
23
- const parsed = super.parsed(options);
24
- const storageConfig = this.getStorageConfig();
25
- return new MongoPersistedSyncRules(parsed.id, parsed.syncConfigWithErrors, parsed.slot_name, storageConfig.incrementalReprocessing ? this.mapping : null, storageConfig);
26
- }
27
- async lock(session) {
28
- const lock = await MongoSyncRulesLock.createLock(this.db.versioned(this.getStorageConfig()), this, session);
29
- this.current_lock = lock;
30
- return lock;
31
- }
32
- }
33
- export class MongoPersistedSyncRulesContentV1 extends MongoPersistedSyncRulesContentBase {
34
- constructor(db, doc) {
35
- super(db, {
36
- id: doc._id,
37
- sync_rules_content: doc.content,
38
- compiled_plan: doc.serialized_plan ?? null,
39
- last_checkpoint_lsn: doc.last_checkpoint_lsn,
40
- // Handle legacy values
41
- slot_name: doc.slot_name ?? `powersync_${doc._id}`,
42
- last_fatal_error: doc.last_fatal_error,
43
- last_fatal_error_ts: doc.last_fatal_error_ts,
44
- last_checkpoint_ts: doc.last_checkpoint_ts,
45
- last_keepalive_ts: doc.last_keepalive_ts,
46
- active: doc.state == SyncRuleState.ACTIVE,
47
- storageVersion: doc.storage_version ?? storage.LEGACY_STORAGE_VERSION,
48
- mapping: new BucketDefinitionMapping(),
49
- syncConfigId: null
50
- });
51
- }
52
- }
53
- export class MongoPersistedSyncRulesContentV3 extends MongoPersistedSyncRulesContentBase {
54
- constructor(db, doc, config) {
55
- const state = doc.sync_configs.find((c) => c._id.equals(config._id));
56
- if (state == null) {
57
- throw new ServiceAssertionError(`Cannot find sync config ${config._id} in replication stream ${doc._id}`);
58
- }
59
- super(db, {
60
- id: doc._id,
61
- sync_rules_content: config.content,
62
- compiled_plan: config.serialized_plan ?? null,
63
- last_checkpoint_lsn: state?.last_checkpoint_lsn ?? null,
64
- slot_name: doc.slot_name ?? `powersync_${doc._id}`,
65
- last_fatal_error: doc.last_fatal_error,
66
- last_fatal_error_ts: doc.last_fatal_error_ts,
67
- last_checkpoint_ts: doc.last_checkpoint_ts,
68
- last_keepalive_ts: doc.last_keepalive_ts,
69
- active: doc.state == SyncRuleState.ACTIVE && state.state == SyncRuleState.ACTIVE,
70
- storageVersion: doc.storage_version,
71
- mapping: BucketDefinitionMapping.fromSyncConfig(config),
72
- syncConfigId: config._id
73
- });
74
- }
75
- }
76
- //# sourceMappingURL=MongoPersistedSyncRulesContent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongoPersistedSyncRulesContent.js","sourceRoot":"","sources":["../../../src/storage/implementation/MongoPersistedSyncRulesContent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGpD,MAAe,kCAAmC,SAAQ,OAAO,CAAC,yBAAyB;IAMpE;IALd,YAAY,GAA8B,IAAI,CAAC;IACtC,OAAO,CAA0B;IACjC,YAAY,CAAuB;IAEnD,YACqB,EAAkB,EACrC,OAGC;QAED,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;QACnD,KAAK,CAAC,IAAI,CAAC,CAAC;QAPO,OAAE,GAAF,EAAE,CAAgB;QAQrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,gBAAgB;QACd,OAAO,qBAAqB,CAAC,IAAI,CAAC,cA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AM,CAAC;YACvD,YAAY,EAAE,MAAM,CAAC,GAAG;SACzB,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,13 +0,0 @@
1
- import { InternalOpId } from '@powersync/service-core';
2
- import * as bson from 'bson';
3
- import { BucketDefinitionMapping } from '../BucketDefinitionMapping.js';
4
- import type { VersionedPowerSyncMongo } from '../db.js';
5
- export interface MongoSyncBucketStorageContext<TDb extends VersionedPowerSyncMongo = VersionedPowerSyncMongo> {
6
- db: TDb;
7
- group_id: number;
8
- mapping: BucketDefinitionMapping;
9
- }
10
- export interface MongoSyncBucketStorageCheckpoint {
11
- checkpoint: InternalOpId;
12
- snapshotTime: bson.Timestamp;
13
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=MongoSyncBucketStorageContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongoSyncBucketStorageContext.js","sourceRoot":"","sources":["../../../../src/storage/implementation/common/MongoSyncBucketStorageContext.ts"],"names":[],"mappings":""}
@@ -1,54 +0,0 @@
1
- import { mongo } from '@powersync/lib-service-mongodb';
2
- import { InternalOpId } from '@powersync/service-core';
3
- import { BucketDataProperties } from '../models.js';
4
- import { BucketDataDoc, BucketKey } from './BucketDataDoc.js';
5
- declare const GENERIC_ID: unique symbol;
6
- export type BucketDataDocumentGenericId = {
7
- b: string;
8
- o: InternalOpId;
9
- [GENERIC_ID]: true;
10
- };
11
- /**
12
- * This document is never actually constructed - we use it as a "virtual" type.
13
- *
14
- * The actual implementations are BucketDataDocumentV1 or BucketDataDocumentV3.
15
- * They don't fully satisfy this interface, but this works to share common implementations.
16
- *
17
- * The idea is that we can have a common implementation between V1 & V3, using this type,
18
- * and operate on MongoDB collections.
19
- *
20
- * This interface serves two primary purposes:
21
- * 1. Captures properties that exist on both V1 and V3 storage models.
22
- * 2. Gives a common reference when querying or modifying collections.
23
- *
24
- * Generics would've been ideal, but they don't play well with MongoDB collections.
25
- */
26
- export interface BucketDataDocumentGeneric extends BucketDataProperties {
27
- _id: BucketDataDocumentGenericId;
28
- }
29
- /**
30
- * Represent read/write access for a single bucket.
31
- *
32
- * This does not implement the actual collection operations, but supports the required conversions
33
- * between in-memory BucketDataDoc and the specific storage formats.
34
- */
35
- export interface SingleBucketStore {
36
- readonly key: BucketKey;
37
- readonly collection: mongo.Collection<BucketDataDocumentGeneric>;
38
- docId(o: InternalOpId): BucketDataDocumentGenericId;
39
- readonly minId: BucketDataDocumentGenericId;
40
- readonly maxId: BucketDataDocumentGenericId;
41
- /**
42
- * Convert in-memory document -> persisted document.
43
- */
44
- toPersistedDocument(source: Omit<BucketDataDoc, 'bucketKey'>): BucketDataDocumentGeneric;
45
- /**
46
- * Convert persisted document -> in-memory document.
47
- */
48
- fromPersistedDocument(doc: BucketDataDocumentGeneric): BucketDataDoc;
49
- /**
50
- * Convert partial persisted document -> partial in-memory document.
51
- */
52
- fromPartialPersistedDocument<T extends keyof BucketDataProperties>(doc: Pick<BucketDataDocumentGeneric, '_id' | T>): Pick<BucketDataDoc, 'bucketKey' | 'o' | T>;
53
- }
54
- export {};
@@ -1,3 +0,0 @@
1
- const GENERIC_ID = Symbol('BucketDataDocumentGenericId');
2
- export {};
3
- //# sourceMappingURL=SingleBucketStore.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SingleBucketStore.js","sourceRoot":"","sources":["../../../../src/storage/implementation/common/SingleBucketStore.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC"}
@@ -1,9 +0,0 @@
1
- import { mongo } from '@powersync/lib-service-mongodb';
2
- import { MongoParameterCompactor } from '../MongoParameterCompactor.js';
3
- import { VersionedPowerSyncMongoV3 } from './VersionedPowerSyncMongoV3.js';
4
- export declare class MongoParameterCompactorV3 extends MongoParameterCompactor {
5
- protected readonly db: VersionedPowerSyncMongoV3;
6
- protected getCollections(): Promise<mongo.Collection<mongo.Document>[]>;
7
- protected collectionFilter(): mongo.Document;
8
- protected deleteFilter(doc: mongo.Document): mongo.Document;
9
- }
@@ -1,18 +0,0 @@
1
- import { MongoParameterCompactor } from '../MongoParameterCompactor.js';
2
- export class MongoParameterCompactorV3 extends MongoParameterCompactor {
3
- async getCollections() {
4
- const collections = await this.db.listParameterIndexCollectionsV3(this.group_id);
5
- return collections.map((collection) => collection.collection);
6
- }
7
- collectionFilter() {
8
- return {};
9
- }
10
- deleteFilter(doc) {
11
- return {
12
- lookup: doc.lookup,
13
- _id: { $lte: doc._id },
14
- key: doc.key
15
- };
16
- }
17
- }
18
- //# sourceMappingURL=MongoParameterCompactorV3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongoParameterCompactorV3.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/MongoParameterCompactorV3.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAGxE,MAAM,OAAO,yBAA0B,SAAQ,uBAAuB;IAG1D,KAAK,CAAC,cAAc;QAC5B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,+BAA+B,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjF,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,UAAyD,CAAC,CAAC;IAC/G,CAAC;IAES,gBAAgB;QACxB,OAAO,EAAE,CAAC;IACZ,CAAC;IAES,YAAY,CAAC,GAAmB;QACxC,OAAO;YACL,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,GAAG,EAAE;YACtB,GAAG,EAAE,GAAG,CAAC,GAAG;SACb,CAAC;IACJ,CAAC;CACF"}
@@ -1,4 +0,0 @@
1
- import { ParameterIndexId, ScopedParameterLookup, SqliteJsonValue } from '@powersync/service-sync-rules';
2
- import * as bson from 'bson';
3
- export declare function serializeParameterLookupV3(lookup: ScopedParameterLookup): bson.Binary;
4
- export declare function deserializeParameterLookupV3(lookup: bson.Binary, indexId: ParameterIndexId): SqliteJsonValue[];
@@ -1,9 +0,0 @@
1
- import { deserializeParameterLookup } from '@powersync/service-core';
2
- import * as bson from 'bson';
3
- export function serializeParameterLookupV3(lookup) {
4
- return new bson.Binary(bson.serialize({ l: lookup.values.slice(2) }));
5
- }
6
- export function deserializeParameterLookupV3(lookup, indexId) {
7
- return [indexId, '', ...deserializeParameterLookup(lookup)];
8
- }
9
- //# sourceMappingURL=MongoParameterLookupV3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongoParameterLookupV3.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/MongoParameterLookupV3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,UAAU,0BAA0B,CAAC,MAA6B;IACtE,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,4BAA4B,CAAC,MAAmB,EAAE,OAAyB;IACzF,OAAO,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC"}
@@ -1,18 +0,0 @@
1
- import { mongo } from '@powersync/lib-service-mongodb';
2
- import { InternalOpId } from '@powersync/service-core';
3
- import { BucketDataDoc, BucketKey } from '../common/BucketDataDoc.js';
4
- import { BucketDataDocumentGeneric, BucketDataDocumentGenericId, SingleBucketStore } from '../common/SingleBucketStore.js';
5
- import { BucketDataProperties } from '../models.js';
6
- import { VersionedPowerSyncMongoV3 } from './VersionedPowerSyncMongoV3.js';
7
- export declare class SingleBucketStoreV3 implements SingleBucketStore {
8
- private db;
9
- readonly key: BucketKey;
10
- readonly collection: mongo.Collection<BucketDataDocumentGeneric>;
11
- constructor(db: VersionedPowerSyncMongoV3, key: BucketKey);
12
- docId(o: InternalOpId): BucketDataDocumentGenericId;
13
- get minId(): BucketDataDocumentGenericId;
14
- get maxId(): BucketDataDocumentGenericId;
15
- toPersistedDocument(source: Omit<BucketDataDoc, 'bucketKey'>): BucketDataDocumentGeneric;
16
- fromPersistedDocument(doc: BucketDataDocumentGeneric): BucketDataDoc;
17
- fromPartialPersistedDocument<T extends keyof BucketDataProperties>(doc: Pick<BucketDataDocumentGeneric, '_id' | T>): Pick<BucketDataDoc, 'bucketKey' | 'o' | T>;
18
- }
@@ -1,48 +0,0 @@
1
- import { mongo } from '@powersync/lib-service-mongodb';
2
- import { loadBucketDataDocumentV3, serializeBucketDataV3 } from './models.js';
3
- export class SingleBucketStoreV3 {
4
- db;
5
- key;
6
- collection;
7
- constructor(db, key) {
8
- this.db = db;
9
- this.key = key;
10
- this.collection = db.bucketDataV3(key.replicationStreamId, key.definitionId);
11
- }
12
- docId(o) {
13
- // `satisfies BucketDataKeyV3` checks that we use the correct type for V3 storage
14
- // `as BucketDataDocumentGenericId` does a cast to get the interface virtual type
15
- return {
16
- b: this.key.bucket,
17
- o
18
- };
19
- }
20
- get minId() {
21
- return {
22
- b: this.key.bucket,
23
- o: new mongo.MinKey()
24
- }; // No way to properly type this
25
- }
26
- get maxId() {
27
- return {
28
- b: this.key.bucket,
29
- o: new mongo.MaxKey()
30
- }; // No way to properly type this
31
- }
32
- toPersistedDocument(source) {
33
- return serializeBucketDataV3({ bucketKey: this.key, ...source });
34
- }
35
- fromPersistedDocument(doc) {
36
- return loadBucketDataDocumentV3(this.key, doc);
37
- }
38
- fromPartialPersistedDocument(doc) {
39
- const document = doc;
40
- const { _id, ...rest } = document;
41
- return {
42
- bucketKey: this.key,
43
- o: _id.o,
44
- ...rest
45
- };
46
- }
47
- }
48
- //# sourceMappingURL=SingleBucketStoreV3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SingleBucketStoreV3.js","sourceRoot":"","sources":["../../../../src/storage/implementation/v3/SingleBucketStoreV3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAUvD,OAAO,EAAyC,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAErH,MAAM,OAAO,mBAAmB;IAIpB;IACQ;IAJF,UAAU,CAA8C;IAExE,YACU,EAA6B,EACrB,GAAc;QADtB,OAAE,GAAF,EAAE,CAA2B;QACrB,QAAG,GAAH,GAAG,CAAW;QAE9B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,YAAY,CAC/B,GAAG,CAAC,mBAAmB,EACvB,GAAG,CAAC,YAAY,CACyC,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,CAAe;QACnB,iFAAiF;QACjF,iFAAiF;QACjF,OAAO;YACL,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM;YAClB,CAAC;SACuD,CAAC;IAC7D,CAAC;IAED,IAAI,KAAK;QACP,OAAO;YACL,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM;YAClB,CAAC,EAAE,IAAI,KAAK,CAAC,MAAM,EAAE;SACf,CAAC,CAAC,+BAA+B;IAC3C,CAAC;IAED,IAAI,KAAK;QACP,OAAO;YACL,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM;YAClB,CAAC,EAAE,IAAI,KAAK,CAAC,MAAM,EAAE;SACf,CAAC,CAAC,+BAA+B;IAC3C,CAAC;IAED,mBAAmB,CAAC,MAAwC;QAC1D,OAAO,qBAAqB,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,EAAE,CAA8B,CAAC;IAChG,CAAC;IAED,qBAAqB,CAAC,GAA8B;QAClD,OAAO,wBAAwB,CAAC,IAAI,CAAC,GAAG,EAAE,GAA2B,CAAC,CAAC;IACzE,CAAC;IAED,4BAA4B,CAC1B,GAA+C;QAE/C,MAAM,QAAQ,GAAG,GAA4C,CAAC;QAC9D,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;QAClC,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,GAAG;YACnB,CAAC,EAAE,GAAG,CAAC,CAAC;YACR,GAAG,IAAI;SACsC,CAAC;IAClD,CAAC;CACF"}
@@ -1,75 +0,0 @@
1
- import { ServiceAssertionError } from '@powersync/lib-services-framework';
2
- import {
3
- BucketDataSource,
4
- BucketDefinitionId,
5
- ParameterIndexId,
6
- ParameterIndexLookupCreator,
7
- SyncConfigWithErrors
8
- } from '@powersync/service-sync-rules';
9
- import { SyncConfigDefinition } from '../storage-index.js';
10
-
11
- export class BucketDefinitionMapping {
12
- static fromSyncConfig(doc: Pick<SyncConfigDefinition, 'rule_mapping'>): BucketDefinitionMapping {
13
- return new BucketDefinitionMapping(doc.rule_mapping?.definitions ?? {}, doc.rule_mapping?.parameter_indexes ?? {});
14
- }
15
-
16
- static fromParsedSyncRules(syncRules: SyncConfigWithErrors): BucketDefinitionMapping {
17
- const definitionNames = syncRules.config.bucketDataSources.map((source) => source.uniqueName).sort();
18
- const parameterKeys = syncRules.config.bucketParameterLookupSources
19
- .map((source) => `${source.sourceId.lookupName}#${source.sourceId.queryId}`)
20
- .sort();
21
-
22
- const definitions: Record<string, BucketDefinitionId> = {};
23
- const parameterLookups: Record<string, ParameterIndexId> = {};
24
-
25
- for (const [index, uniqueName] of definitionNames.entries()) {
26
- definitions[uniqueName] = (index + 1).toString(16);
27
- }
28
- for (const [index, key] of parameterKeys.entries()) {
29
- parameterLookups[key] = (index + 1).toString(16);
30
- }
31
-
32
- return new BucketDefinitionMapping(definitions, parameterLookups);
33
- }
34
-
35
- constructor(
36
- private definitions: Record<string, BucketDefinitionId> = {},
37
- private parameterLookupMapping: Record<string, ParameterIndexId> = {}
38
- ) {}
39
-
40
- bucketSourceId(source: BucketDataSource): BucketDefinitionId {
41
- const defId = this.definitions[source.uniqueName];
42
- if (defId == null) {
43
- throw new ServiceAssertionError(`No mapping found for bucket source ${source.uniqueName}`);
44
- }
45
- return defId;
46
- }
47
-
48
- allBucketDefinitionIds(): BucketDefinitionId[] {
49
- return Object.values(this.definitions);
50
- }
51
-
52
- allParameterIndexIds(): ParameterIndexId[] {
53
- return Object.values(this.parameterLookupMapping);
54
- }
55
-
56
- parameterLookupId(source: ParameterIndexLookupCreator): ParameterIndexId {
57
- const key = this.parameterLookupKey(source.sourceId.lookupName, source.sourceId.queryId);
58
- const defId = this.parameterLookupMapping[key];
59
- if (defId == null) {
60
- throw new ServiceAssertionError(`No mapping found for parameter lookup source ${key}`);
61
- }
62
- return defId;
63
- }
64
-
65
- private parameterLookupKey(lookupName: string, queryId: string) {
66
- return `${lookupName}#${queryId}`;
67
- }
68
-
69
- serialize(): SyncConfigDefinition['rule_mapping'] {
70
- return {
71
- definitions: { ...this.definitions },
72
- parameter_indexes: { ...this.parameterLookupMapping }
73
- };
74
- }
75
- }