@powersync/service-module-mongodb-storage 0.17.0 → 0.18.1

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 (185) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/storage/MongoBucketStorage.d.ts +34 -16
  3. package/dist/storage/MongoBucketStorage.js +219 -70
  4. package/dist/storage/MongoBucketStorage.js.map +1 -1
  5. package/dist/storage/implementation/MongoBucketBatch.d.ts +42 -23
  6. package/dist/storage/implementation/MongoBucketBatch.js +61 -44
  7. package/dist/storage/implementation/MongoBucketBatch.js.map +1 -1
  8. package/dist/storage/implementation/MongoChecksums.d.ts +10 -9
  9. package/dist/storage/implementation/MongoChecksums.js +3 -111
  10. package/dist/storage/implementation/MongoChecksums.js.map +1 -1
  11. package/dist/storage/implementation/MongoCompactor.d.ts +2 -0
  12. package/dist/storage/implementation/MongoCompactor.js +18 -9
  13. package/dist/storage/implementation/MongoCompactor.js.map +1 -1
  14. package/dist/storage/implementation/MongoHydrationState.d.ts +11 -0
  15. package/dist/storage/implementation/MongoHydrationState.js +49 -0
  16. package/dist/storage/implementation/MongoHydrationState.js.map +1 -0
  17. package/dist/storage/implementation/MongoParameterCompactor.d.ts +6 -5
  18. package/dist/storage/implementation/MongoParameterCompactor.js +24 -1
  19. package/dist/storage/implementation/MongoParameterCompactor.js.map +1 -1
  20. package/dist/storage/implementation/MongoParsedSyncConfigSet.d.ts +13 -0
  21. package/dist/storage/implementation/MongoParsedSyncConfigSet.js +64 -0
  22. package/dist/storage/implementation/MongoParsedSyncConfigSet.js.map +1 -0
  23. package/dist/storage/implementation/MongoPersistedReplicationStream.d.ts +36 -0
  24. package/dist/storage/implementation/MongoPersistedReplicationStream.js +90 -0
  25. package/dist/storage/implementation/MongoPersistedReplicationStream.js.map +1 -0
  26. package/dist/storage/implementation/MongoPersistedSyncConfigContent.d.ts +25 -0
  27. package/dist/storage/implementation/MongoPersistedSyncConfigContent.js +123 -0
  28. package/dist/storage/implementation/MongoPersistedSyncConfigContent.js.map +1 -0
  29. package/dist/storage/implementation/MongoStorageProvider.js +5 -2
  30. package/dist/storage/implementation/MongoStorageProvider.js.map +1 -1
  31. package/dist/storage/implementation/MongoSyncBucketStorage.d.ts +41 -23
  32. package/dist/storage/implementation/MongoSyncBucketStorage.js +51 -43
  33. package/dist/storage/implementation/MongoSyncBucketStorage.js.map +1 -1
  34. package/dist/storage/implementation/MongoSyncRulesLock.d.ts +1 -1
  35. package/dist/storage/implementation/MongoSyncRulesLock.js +3 -3
  36. package/dist/storage/implementation/MongoSyncRulesLock.js.map +1 -1
  37. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.d.ts +6 -0
  38. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js +2 -0
  39. package/dist/storage/implementation/common/MongoSyncBucketStorageCheckpoint.js.map +1 -0
  40. package/dist/storage/implementation/common/PersistedBatch.d.ts +1 -2
  41. package/dist/storage/implementation/common/PersistedBatch.js +5 -0
  42. package/dist/storage/implementation/common/PersistedBatch.js.map +1 -1
  43. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js +1 -1
  44. package/dist/storage/implementation/common/VersionedPowerSyncMongoBase.js.map +1 -1
  45. package/dist/storage/implementation/createMongoSyncBucketStorage.d.ts +2 -2
  46. package/dist/storage/implementation/createMongoSyncBucketStorage.js +4 -4
  47. package/dist/storage/implementation/createMongoSyncBucketStorage.js.map +1 -1
  48. package/dist/storage/implementation/db.js +9 -14
  49. package/dist/storage/implementation/db.js.map +1 -1
  50. package/dist/storage/implementation/models.d.ts +4 -13
  51. package/dist/storage/implementation/models.js.map +1 -1
  52. package/dist/storage/implementation/v1/MongoBucketBatchV1.d.ts +9 -1
  53. package/dist/storage/implementation/v1/MongoBucketBatchV1.js +42 -26
  54. package/dist/storage/implementation/v1/MongoBucketBatchV1.js.map +1 -1
  55. package/dist/storage/implementation/v1/MongoChecksumsV1.js +114 -3
  56. package/dist/storage/implementation/v1/MongoChecksumsV1.js.map +1 -1
  57. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.d.ts +15 -17
  58. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js +47 -45
  59. package/dist/storage/implementation/v1/MongoSyncBucketStorageV1.js.map +1 -1
  60. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.d.ts +2 -1
  61. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js +3 -0
  62. package/dist/storage/implementation/v1/VersionedPowerSyncMongoV1.js.map +1 -1
  63. package/dist/storage/implementation/v1/models.d.ts +10 -1
  64. package/dist/storage/implementation/v3/MongoBucketBatchV3.d.ts +8 -4
  65. package/dist/storage/implementation/v3/MongoBucketBatchV3.js +286 -259
  66. package/dist/storage/implementation/v3/MongoBucketBatchV3.js.map +1 -1
  67. package/dist/storage/implementation/v3/MongoChecksumsV3.d.ts +27 -7
  68. package/dist/storage/implementation/v3/MongoChecksumsV3.js +202 -18
  69. package/dist/storage/implementation/v3/MongoChecksumsV3.js.map +1 -1
  70. package/dist/storage/implementation/v3/MongoCompactorV3.d.ts +19 -2
  71. package/dist/storage/implementation/v3/MongoCompactorV3.js +511 -22
  72. package/dist/storage/implementation/v3/MongoCompactorV3.js.map +1 -1
  73. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.d.ts +62 -0
  74. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js +350 -0
  75. package/dist/storage/implementation/v3/MongoStoppedSyncConfigCleanup.js.map +1 -0
  76. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.d.ts +40 -28
  77. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js +232 -116
  78. package/dist/storage/implementation/v3/MongoSyncBucketStorageV3.js.map +1 -1
  79. package/dist/storage/implementation/v3/PersistedBatchV3.d.ts +1 -1
  80. package/dist/storage/implementation/v3/PersistedBatchV3.js +43 -20
  81. package/dist/storage/implementation/v3/PersistedBatchV3.js.map +1 -1
  82. package/dist/storage/implementation/v3/SingleBucketStoreV3.js +52 -16
  83. package/dist/storage/implementation/v3/SingleBucketStoreV3.js.map +1 -1
  84. package/dist/storage/implementation/v3/SourceRecordStoreV3.d.ts +3 -3
  85. package/dist/storage/implementation/v3/SourceRecordStoreV3.js +13 -11
  86. package/dist/storage/implementation/v3/SourceRecordStoreV3.js.map +1 -1
  87. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.d.ts +13 -12
  88. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js +29 -27
  89. package/dist/storage/implementation/v3/VersionedPowerSyncMongoV3.js.map +1 -1
  90. package/dist/storage/implementation/v3/bucket-format.d.ts +4 -0
  91. package/dist/storage/implementation/v3/bucket-format.js +58 -0
  92. package/dist/storage/implementation/v3/bucket-format.js.map +1 -0
  93. package/dist/storage/implementation/v3/chunking.d.ts +10 -0
  94. package/dist/storage/implementation/v3/chunking.js +28 -0
  95. package/dist/storage/implementation/v3/chunking.js.map +1 -0
  96. package/dist/storage/implementation/v3/models.d.ts +64 -21
  97. package/dist/storage/implementation/v3/models.js +11 -28
  98. package/dist/storage/implementation/v3/models.js.map +1 -1
  99. package/dist/storage/implementation/v3/source-table-utils.d.ts +55 -0
  100. package/dist/storage/implementation/v3/source-table-utils.js +214 -0
  101. package/dist/storage/implementation/v3/source-table-utils.js.map +1 -0
  102. package/dist/storage/storage-index.d.ts +4 -4
  103. package/dist/storage/storage-index.js +4 -4
  104. package/dist/storage/storage-index.js.map +1 -1
  105. package/dist/types/types.d.ts +2 -2
  106. package/dist/utils/test-utils.d.ts +1 -2
  107. package/dist/utils/test-utils.js +5 -1
  108. package/dist/utils/test-utils.js.map +1 -1
  109. package/dist/utils/util.d.ts +1 -1
  110. package/dist/utils/util.js +3 -2
  111. package/dist/utils/util.js.map +1 -1
  112. package/package.json +9 -19
  113. package/src/storage/MongoBucketStorage.ts +334 -87
  114. package/src/storage/implementation/MongoBucketBatch.ts +86 -58
  115. package/src/storage/implementation/MongoChecksums.ts +6 -138
  116. package/src/storage/implementation/MongoCompactor.ts +19 -9
  117. package/src/storage/implementation/MongoHydrationState.ts +61 -0
  118. package/src/storage/implementation/MongoParameterCompactor.ts +24 -5
  119. package/src/storage/implementation/MongoParsedSyncConfigSet.ts +88 -0
  120. package/src/storage/implementation/MongoPersistedReplicationStream.ts +118 -0
  121. package/src/storage/implementation/MongoPersistedSyncConfigContent.ts +154 -0
  122. package/src/storage/implementation/MongoStorageProvider.ts +5 -2
  123. package/src/storage/implementation/MongoSyncBucketStorage.ts +70 -56
  124. package/src/storage/implementation/MongoSyncRulesLock.ts +7 -4
  125. package/src/storage/implementation/common/MongoSyncBucketStorageCheckpoint.ts +7 -0
  126. package/src/storage/implementation/common/PersistedBatch.ts +7 -3
  127. package/src/storage/implementation/common/VersionedPowerSyncMongoBase.ts +1 -1
  128. package/src/storage/implementation/createMongoSyncBucketStorage.ts +21 -7
  129. package/src/storage/implementation/db.ts +11 -19
  130. package/src/storage/implementation/models.ts +4 -14
  131. package/src/storage/implementation/v1/MongoBucketBatchV1.ts +55 -34
  132. package/src/storage/implementation/v1/MongoChecksumsV1.ts +137 -4
  133. package/src/storage/implementation/v1/MongoSyncBucketStorageV1.ts +70 -64
  134. package/src/storage/implementation/v1/VersionedPowerSyncMongoV1.ts +11 -1
  135. package/src/storage/implementation/v1/models.ts +11 -1
  136. package/src/storage/implementation/v3/MongoBucketBatchV3.ts +358 -314
  137. package/src/storage/implementation/v3/MongoChecksumsV3.ts +262 -26
  138. package/src/storage/implementation/v3/MongoCompactorV3.ts +646 -29
  139. package/src/storage/implementation/v3/MongoStoppedSyncConfigCleanup.ts +480 -0
  140. package/src/storage/implementation/v3/MongoSyncBucketStorageV3.ts +315 -157
  141. package/src/storage/implementation/v3/PersistedBatchV3.ts +62 -36
  142. package/src/storage/implementation/v3/SingleBucketStoreV3.ts +59 -19
  143. package/src/storage/implementation/v3/SourceRecordStoreV3.ts +12 -12
  144. package/src/storage/implementation/v3/VersionedPowerSyncMongoV3.ts +41 -36
  145. package/src/storage/implementation/v3/bucket-format.ts +70 -0
  146. package/src/storage/implementation/v3/chunking.ts +38 -0
  147. package/src/storage/implementation/v3/models.ts +93 -55
  148. package/src/storage/implementation/v3/source-table-utils.ts +392 -0
  149. package/src/storage/storage-index.ts +12 -4
  150. package/src/utils/test-utils.ts +6 -3
  151. package/src/utils/util.ts +3 -2
  152. package/test/src/__snapshots__/storage.test.ts.snap +0 -75
  153. package/test/src/__snapshots__/storage_sync.test.ts.snap +48 -48
  154. package/test/src/cleanup-stopped-sync-configs.test.ts +648 -0
  155. package/test/src/storage.test.ts +11 -11
  156. package/test/src/storage_compacting.test.ts +1956 -6
  157. package/test/src/storage_sync.test.ts +1077 -68
  158. package/test/src/storeCurrentData.test.ts +17 -7
  159. package/test/src/util.ts +2 -1
  160. package/tsconfig.json +1 -4
  161. package/tsconfig.tsbuildinfo +1 -1
  162. package/dist/storage/implementation/BucketDefinitionMapping.d.ts +0 -15
  163. package/dist/storage/implementation/BucketDefinitionMapping.js +0 -58
  164. package/dist/storage/implementation/BucketDefinitionMapping.js.map +0 -1
  165. package/dist/storage/implementation/MongoPersistedSyncRules.d.ts +0 -14
  166. package/dist/storage/implementation/MongoPersistedSyncRules.js +0 -67
  167. package/dist/storage/implementation/MongoPersistedSyncRules.js.map +0 -1
  168. package/dist/storage/implementation/MongoPersistedSyncRulesContent.d.ts +0 -29
  169. package/dist/storage/implementation/MongoPersistedSyncRulesContent.js +0 -76
  170. package/dist/storage/implementation/MongoPersistedSyncRulesContent.js.map +0 -1
  171. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.d.ts +0 -13
  172. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js +0 -2
  173. package/dist/storage/implementation/common/MongoSyncBucketStorageContext.js.map +0 -1
  174. package/dist/storage/implementation/v3/MongoParameterCompactorV3.d.ts +0 -9
  175. package/dist/storage/implementation/v3/MongoParameterCompactorV3.js +0 -18
  176. package/dist/storage/implementation/v3/MongoParameterCompactorV3.js.map +0 -1
  177. package/dist/storage/implementation/v3/MongoParameterLookupV3.d.ts +0 -4
  178. package/dist/storage/implementation/v3/MongoParameterLookupV3.js +0 -9
  179. package/dist/storage/implementation/v3/MongoParameterLookupV3.js.map +0 -1
  180. package/src/storage/implementation/BucketDefinitionMapping.ts +0 -75
  181. package/src/storage/implementation/MongoPersistedSyncRules.ts +0 -82
  182. package/src/storage/implementation/MongoPersistedSyncRulesContent.ts +0 -101
  183. package/src/storage/implementation/common/MongoSyncBucketStorageContext.ts +0 -15
  184. package/src/storage/implementation/v3/MongoParameterCompactorV3.ts +0 -24
  185. package/src/storage/implementation/v3/MongoParameterLookupV3.ts +0 -11
@@ -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,MA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rors } 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,mBAA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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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e;YACnC,OAAO,EAAE,uBAAuB,CAAC,cAAc,CAAC,MAAM,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,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,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
- }
@@ -1,82 +0,0 @@
1
- import * as sqlite from 'node:sqlite';
2
-
3
- import { ServiceAssertionError } from '@powersync/lib-services-framework';
4
- import { storage } from '@powersync/service-core';
5
- import {
6
- BucketDataScope,
7
- BucketDataSource,
8
- CompatibilityOption,
9
- DEFAULT_HYDRATION_STATE,
10
- HydratedSyncConfig,
11
- HydrationState,
12
- nodeSqlite,
13
- ParameterIndexLookupCreator,
14
- ParameterLookupScope,
15
- SyncConfigWithErrors,
16
- versionedHydrationState
17
- } from '@powersync/service-sync-rules';
18
- import { BucketDefinitionMapping } from './BucketDefinitionMapping.js';
19
- import { StorageConfig } from './models.js';
20
-
21
- export class MongoPersistedSyncRules implements storage.PersistedSyncRules {
22
- public readonly hydrationState: HydrationState;
23
-
24
- constructor(
25
- public readonly id: number,
26
- public readonly syncConfigWithErrors: SyncConfigWithErrors,
27
- public readonly slot_name: string,
28
- private readonly mapping: BucketDefinitionMapping | null,
29
- private readonly storageConfig: StorageConfig
30
- ) {
31
- if (this.storageConfig.incrementalReprocessing) {
32
- if (this.mapping == null) {
33
- throw new ServiceAssertionError(`mapping is required for v3 storage`);
34
- }
35
- this.hydrationState = new MongoHydrationState(this.mapping, this.id);
36
- } else if (
37
- !this.syncConfigWithErrors.config.compatibility.isEnabled(CompatibilityOption.versionedBucketIds) &&
38
- !this.storageConfig.versionedBuckets
39
- ) {
40
- this.hydrationState = DEFAULT_HYDRATION_STATE;
41
- } else {
42
- this.hydrationState = versionedHydrationState(this.id);
43
- }
44
- }
45
-
46
- hydratedSyncConfig(): HydratedSyncConfig {
47
- return this.syncConfigWithErrors.config.hydrate({
48
- hydrationState: this.hydrationState,
49
- sqlite: nodeSqlite(sqlite)
50
- });
51
- }
52
- }
53
-
54
- class MongoHydrationState implements HydrationState {
55
- constructor(
56
- private readonly mapping: BucketDefinitionMapping,
57
- private readonly version: number
58
- ) {}
59
-
60
- getBucketSourceScope(source: BucketDataSource): BucketDataScope {
61
- // Keep this aligned with versionedHydrationState() for now.
62
- //
63
- // Previous Mongo-specific behavior:
64
- // return {
65
- // bucketPrefix: defId,
66
- // source
67
- // };
68
- return {
69
- bucketPrefix: `${this.version}#${source.uniqueName}`,
70
- source
71
- };
72
- }
73
-
74
- getParameterIndexLookupScope(source: ParameterIndexLookupCreator): ParameterLookupScope {
75
- const defId = this.mapping.parameterLookupId(source);
76
- return {
77
- lookupName: defId,
78
- queryId: '',
79
- source
80
- };
81
- }
82
- }
@@ -1,101 +0,0 @@
1
- import { mongo } from '@powersync/lib-service-mongodb';
2
- import { ServiceAssertionError } from '@powersync/lib-services-framework';
3
- import { storage, SyncRuleState } from '@powersync/service-core';
4
- import * as bson from 'bson';
5
- import { ReplicationStreamDocumentV3, SyncConfigDefinition } from '../storage-index.js';
6
- import { BucketDefinitionMapping } from './BucketDefinitionMapping.js';
7
- import { MongoPersistedSyncRules } from './MongoPersistedSyncRules.js';
8
- import { MongoSyncRulesLock } from './MongoSyncRulesLock.js';
9
- import { PowerSyncMongo } from './db.js';
10
- import { getMongoStorageConfig } from './models.js';
11
- import { SyncRuleDocumentV1 } from './v1/models.js';
12
-
13
- abstract class MongoPersistedSyncRulesContentBase extends storage.PersistedSyncRulesContent {
14
- public current_lock: MongoSyncRulesLock | null = null;
15
- public readonly mapping: BucketDefinitionMapping;
16
- public readonly syncConfigId: bson.ObjectId | null;
17
-
18
- protected constructor(
19
- protected readonly db: PowerSyncMongo,
20
- options: ConstructorParameters<typeof storage.PersistedSyncRulesContent>[0] & {
21
- mapping: BucketDefinitionMapping;
22
- syncConfigId: bson.ObjectId | null;
23
- }
24
- ) {
25
- const { mapping, syncConfigId, ...base } = options;
26
- super(base);
27
- this.mapping = mapping;
28
- this.syncConfigId = syncConfigId;
29
- }
30
-
31
- getStorageConfig() {
32
- return getMongoStorageConfig(this.storageVersion);
33
- }
34
-
35
- parsed(options: storage.ParseSyncRulesOptions): storage.PersistedSyncRules {
36
- const parsed = super.parsed(options);
37
- const storageConfig = this.getStorageConfig();
38
-
39
- return new MongoPersistedSyncRules(
40
- parsed.id,
41
- parsed.syncConfigWithErrors,
42
- parsed.slot_name,
43
- storageConfig.incrementalReprocessing ? this.mapping : null,
44
- storageConfig
45
- );
46
- }
47
-
48
- async lock(session?: mongo.ClientSession) {
49
- const lock = await MongoSyncRulesLock.createLock(this.db.versioned(this.getStorageConfig()), this, session);
50
- this.current_lock = lock;
51
- return lock;
52
- }
53
- }
54
-
55
- export class MongoPersistedSyncRulesContentV1 extends MongoPersistedSyncRulesContentBase {
56
- constructor(db: PowerSyncMongo, doc: SyncRuleDocumentV1) {
57
- super(db, {
58
- id: doc._id,
59
- sync_rules_content: doc.content,
60
- compiled_plan: doc.serialized_plan ?? null,
61
- last_checkpoint_lsn: doc.last_checkpoint_lsn,
62
- // Handle legacy values
63
- slot_name: doc.slot_name ?? `powersync_${doc._id}`,
64
- last_fatal_error: doc.last_fatal_error,
65
- last_fatal_error_ts: doc.last_fatal_error_ts,
66
- last_checkpoint_ts: doc.last_checkpoint_ts,
67
- last_keepalive_ts: doc.last_keepalive_ts,
68
- active: doc.state == SyncRuleState.ACTIVE,
69
- storageVersion: doc.storage_version ?? storage.LEGACY_STORAGE_VERSION,
70
- mapping: new BucketDefinitionMapping(),
71
- syncConfigId: null
72
- });
73
- }
74
- }
75
-
76
- export class MongoPersistedSyncRulesContentV3 extends MongoPersistedSyncRulesContentBase {
77
- declare public readonly syncConfigId: bson.ObjectId;
78
-
79
- constructor(db: PowerSyncMongo, doc: ReplicationStreamDocumentV3, config: SyncConfigDefinition) {
80
- const state = doc.sync_configs.find((c) => c._id.equals(config._id));
81
- if (state == null) {
82
- throw new ServiceAssertionError(`Cannot find sync config ${config._id} in replication stream ${doc._id}`);
83
- }
84
- super(db, {
85
- id: doc._id,
86
- sync_rules_content: config.content,
87
- compiled_plan: config.serialized_plan ?? null,
88
-
89
- last_checkpoint_lsn: state?.last_checkpoint_lsn ?? null,
90
- slot_name: doc.slot_name ?? `powersync_${doc._id}`,
91
- last_fatal_error: doc.last_fatal_error,
92
- last_fatal_error_ts: doc.last_fatal_error_ts,
93
- last_checkpoint_ts: doc.last_checkpoint_ts,
94
- last_keepalive_ts: doc.last_keepalive_ts,
95
- active: doc.state == SyncRuleState.ACTIVE && state.state == SyncRuleState.ACTIVE,
96
- storageVersion: doc.storage_version,
97
- mapping: BucketDefinitionMapping.fromSyncConfig(config),
98
- syncConfigId: config._id
99
- });
100
- }
101
- }
@@ -1,15 +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
-
6
- export interface MongoSyncBucketStorageContext<TDb extends VersionedPowerSyncMongo = VersionedPowerSyncMongo> {
7
- db: TDb;
8
- group_id: number;
9
- mapping: BucketDefinitionMapping;
10
- }
11
-
12
- export interface MongoSyncBucketStorageCheckpoint {
13
- checkpoint: InternalOpId;
14
- snapshotTime: bson.Timestamp;
15
- }