@powersync/service-module-mssql 0.6.4 → 0.8.0

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 (39) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/api/MSSQLRouteAPIAdapter.d.ts +3 -4
  3. package/dist/api/MSSQLRouteAPIAdapter.js.map +1 -1
  4. package/dist/common/MSSQLSourceTable.d.ts +13 -3
  5. package/dist/common/MSSQLSourceTable.js +25 -8
  6. package/dist/common/MSSQLSourceTable.js.map +1 -1
  7. package/dist/common/MSSQLSourceTableCache.js +1 -1
  8. package/dist/common/MSSQLSourceTableCache.js.map +1 -1
  9. package/dist/replication/CDCPoller.d.ts +2 -2
  10. package/dist/replication/CDCPoller.js +1 -1
  11. package/dist/replication/CDCPoller.js.map +1 -1
  12. package/dist/replication/CDCReplicationJob.js +1 -1
  13. package/dist/replication/CDCReplicationJob.js.map +1 -1
  14. package/dist/replication/CDCReplicator.js +1 -1
  15. package/dist/replication/CDCReplicator.js.map +1 -1
  16. package/dist/replication/CDCStream.js +103 -81
  17. package/dist/replication/CDCStream.js.map +1 -1
  18. package/dist/replication/MSSQLSnapshotQuery.d.ts +5 -6
  19. package/dist/replication/MSSQLSnapshotQuery.js +13 -15
  20. package/dist/replication/MSSQLSnapshotQuery.js.map +1 -1
  21. package/dist/utils/mssql.js.map +1 -1
  22. package/dist/utils/schema.d.ts +6 -2
  23. package/dist/utils/schema.js.map +1 -1
  24. package/package.json +11 -21
  25. package/src/api/MSSQLRouteAPIAdapter.ts +3 -4
  26. package/src/common/MSSQLSourceTable.ts +30 -7
  27. package/src/common/MSSQLSourceTableCache.ts +1 -1
  28. package/src/replication/CDCPoller.ts +3 -4
  29. package/src/replication/CDCReplicationJob.ts +1 -1
  30. package/src/replication/CDCReplicator.ts +1 -1
  31. package/src/replication/CDCStream.ts +125 -88
  32. package/src/replication/MSSQLSnapshotQuery.ts +10 -11
  33. package/src/utils/mssql.ts +1 -1
  34. package/src/utils/schema.ts +7 -2
  35. package/test/src/CDCStreamTestContext.ts +20 -20
  36. package/test/src/schema-changes.test.ts +0 -2
  37. package/test/src/util.ts +1 -1
  38. package/tsconfig.json +0 -3
  39. package/tsconfig.tsbuildinfo +1 -1
@@ -26,7 +26,7 @@ export class CDCStreamTestContext implements AsyncDisposable {
26
26
  private _cdcStream?: CDCStream;
27
27
  private abortController = new AbortController();
28
28
  private streamPromise?: Promise<void>;
29
- private syncRulesContent?: storage.PersistedSyncRulesContent;
29
+ private syncRulesContent?: storage.PersistedSyncConfigContent;
30
30
  public storage?: SyncRulesBucketStorage;
31
31
  private snapshotPromise?: Promise<void>;
32
32
  private replicationDone = false;
@@ -75,37 +75,37 @@ export class CDCStreamTestContext implements AsyncDisposable {
75
75
  }
76
76
 
77
77
  async updateSyncRules(content: string) {
78
- const syncRules = await this.factory.updateSyncRules(
78
+ const replicationStream = await this.factory.updateSyncRules(
79
79
  updateSyncRulesFromYaml(content, { validate: true, storageVersion: LEGACY_STORAGE_VERSION })
80
80
  );
81
- this.syncRulesContent = syncRules;
82
- this.storage = this.factory.getInstance(syncRules);
81
+ this.syncRulesContent = replicationStream.syncConfigContent[0];
82
+ this.storage = this.factory.getInstance(replicationStream);
83
83
  return this.storage!;
84
84
  }
85
85
 
86
86
  async loadNextSyncRules() {
87
- const syncRules = await this.factory.getNextSyncRulesContent();
88
- if (syncRules == null) {
87
+ const syncConfig = await this.factory.getDeployingSyncConfig();
88
+ if (syncConfig == null) {
89
89
  throw new Error(`Next replication stream not available`);
90
90
  }
91
91
 
92
- this.syncRulesContent = syncRules;
93
- this.storage = this.factory.getInstance(syncRules);
92
+ this.syncRulesContent = syncConfig.content;
93
+ this.storage = syncConfig.storage;
94
94
  return this.storage!;
95
95
  }
96
96
 
97
97
  async loadActiveSyncRules() {
98
- const syncRules = await this.factory.getActiveSyncRulesContent();
99
- if (syncRules == null) {
98
+ const syncConfig = await this.factory.getActiveSyncConfig();
99
+ if (syncConfig == null) {
100
100
  throw new Error(`Active replication stream not available`);
101
101
  }
102
102
 
103
- this.syncRulesContent = syncRules;
104
- this.storage = this.factory.getInstance(syncRules);
103
+ this.syncRulesContent = syncConfig.content;
104
+ this.storage = syncConfig.storage;
105
105
  return this.storage!;
106
106
  }
107
107
 
108
- private getSyncRulesContent(): storage.PersistedSyncRulesContent {
108
+ private getSyncConfigContent(): storage.PersistedSyncConfigContent {
109
109
  if (this.syncRulesContent == null) {
110
110
  throw new Error('Sync config not configured - call updateSyncRules() first');
111
111
  }
@@ -183,8 +183,8 @@ export class CDCStreamTestContext implements AsyncDisposable {
183
183
 
184
184
  async getBucketsDataBatch(buckets: Record<string, InternalOpId>, options?: { timeout?: number }) {
185
185
  let checkpoint = await this.getCheckpoint(options);
186
- const syncRules = this.getSyncRulesContent();
187
- const map = Object.entries(buckets).map(([bucket, start]) => bucketRequest(syncRules, bucket, start));
186
+ const syncConfigContent = this.getSyncConfigContent();
187
+ const map = Object.entries(buckets).map(([bucket, start]) => bucketRequest(syncConfigContent, bucket, start));
188
188
  return test_utils.fromAsync(this.storage!.getBucketDataBatch(checkpoint, map));
189
189
  }
190
190
 
@@ -196,9 +196,9 @@ export class CDCStreamTestContext implements AsyncDisposable {
196
196
  if (typeof start == 'string') {
197
197
  start = BigInt(start);
198
198
  }
199
- const syncRules = this.getSyncRulesContent();
199
+ const syncConfigContent = this.getSyncConfigContent();
200
200
  const checkpoint = await this.getCheckpoint(options);
201
- let map = [bucketRequest(syncRules, bucket, start)];
201
+ let map = [bucketRequest(syncConfigContent, bucket, start)];
202
202
  let data: OplogEntry[] = [];
203
203
  while (true) {
204
204
  const batch = this.storage!.getBucketDataBatch(checkpoint, map);
@@ -208,7 +208,7 @@ export class CDCStreamTestContext implements AsyncDisposable {
208
208
  if (batches.length == 0 || !batches[0]!.chunkData.has_more) {
209
209
  break;
210
210
  }
211
- map = [bucketRequest(syncRules, bucket, BigInt(batches[0]!.chunkData.next_after))];
211
+ map = [bucketRequest(syncConfigContent, bucket, BigInt(batches[0]!.chunkData.next_after))];
212
212
  }
213
213
  return data;
214
214
  }
@@ -227,8 +227,8 @@ export class CDCStreamTestContext implements AsyncDisposable {
227
227
  start = BigInt(start);
228
228
  }
229
229
  const { checkpoint } = await this.storage!.getCheckpoint();
230
- const syncRules = this.getSyncRulesContent();
231
- const map = [bucketRequest(syncRules, bucket, start)];
230
+ const syncConfigContent = this.getSyncConfigContent();
231
+ const map = [bucketRequest(syncConfigContent, bucket, start)];
232
232
  const batch = this.storage!.getBucketDataBatch(checkpoint, map);
233
233
  const batches = await test_utils.fromAsync(batch);
234
234
  return batches[0]?.chunkData.data ?? [];
@@ -339,9 +339,7 @@ function defineSchemaChangesTests(config: storage.TestStorageConfig) {
339
339
  await context.replicateSnapshot();
340
340
  await context.startStreaming();
341
341
 
342
- const schemaSpy = vi.spyOn(context.cdcStream, 'handleSchemaChange');
343
342
  await enableCDCForTable({ connectionManager, table: 'test_data' });
344
- await expectedSchemaChange(schemaSpy, SchemaChangeType.NEW_CAPTURE_INSTANCE);
345
343
 
346
344
  let data = await context.getBucketData('global[]');
347
345
  expect(data).toMatchObject([putOp('test_data', testData1)]);
package/test/src/util.ts CHANGED
@@ -208,7 +208,7 @@ export async function getClientCheckpoint(
208
208
 
209
209
  logger.info(`Test Assertion: Waiting for LSN checkpoint: ${lsn}`);
210
210
  while (Date.now() - start < timeout) {
211
- const storage = await storageFactory.getActiveStorage();
211
+ const storage = (await storageFactory.getActiveSyncConfig())?.storage;
212
212
  const cp = await storage?.getCheckpoint();
213
213
  if (cp != null) {
214
214
  lastCp = cp;
package/tsconfig.json CHANGED
@@ -3,9 +3,6 @@
3
3
  "compilerOptions": {
4
4
  "rootDir": "src",
5
5
  "outDir": "dist",
6
- "esModuleInterop": true,
7
- "skipLibCheck": true,
8
- "sourceMap": true,
9
6
  "typeRoots": ["./node_modules/@types"]
10
7
  },
11
8
  "include": ["src"],