@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.
- package/CHANGELOG.md +48 -0
- package/dist/api/MSSQLRouteAPIAdapter.d.ts +3 -4
- package/dist/api/MSSQLRouteAPIAdapter.js.map +1 -1
- package/dist/common/MSSQLSourceTable.d.ts +13 -3
- package/dist/common/MSSQLSourceTable.js +25 -8
- package/dist/common/MSSQLSourceTable.js.map +1 -1
- package/dist/common/MSSQLSourceTableCache.js +1 -1
- package/dist/common/MSSQLSourceTableCache.js.map +1 -1
- package/dist/replication/CDCPoller.d.ts +2 -2
- package/dist/replication/CDCPoller.js +1 -1
- package/dist/replication/CDCPoller.js.map +1 -1
- package/dist/replication/CDCReplicationJob.js +1 -1
- package/dist/replication/CDCReplicationJob.js.map +1 -1
- package/dist/replication/CDCReplicator.js +1 -1
- package/dist/replication/CDCReplicator.js.map +1 -1
- package/dist/replication/CDCStream.js +103 -81
- package/dist/replication/CDCStream.js.map +1 -1
- package/dist/replication/MSSQLSnapshotQuery.d.ts +5 -6
- package/dist/replication/MSSQLSnapshotQuery.js +13 -15
- package/dist/replication/MSSQLSnapshotQuery.js.map +1 -1
- package/dist/utils/mssql.js.map +1 -1
- package/dist/utils/schema.d.ts +6 -2
- package/dist/utils/schema.js.map +1 -1
- package/package.json +11 -21
- package/src/api/MSSQLRouteAPIAdapter.ts +3 -4
- package/src/common/MSSQLSourceTable.ts +30 -7
- package/src/common/MSSQLSourceTableCache.ts +1 -1
- package/src/replication/CDCPoller.ts +3 -4
- package/src/replication/CDCReplicationJob.ts +1 -1
- package/src/replication/CDCReplicator.ts +1 -1
- package/src/replication/CDCStream.ts +125 -88
- package/src/replication/MSSQLSnapshotQuery.ts +10 -11
- package/src/utils/mssql.ts +1 -1
- package/src/utils/schema.ts +7 -2
- package/test/src/CDCStreamTestContext.ts +20 -20
- package/test/src/schema-changes.test.ts +0 -2
- package/test/src/util.ts +1 -1
- package/tsconfig.json +0 -3
- 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.
|
|
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
|
|
78
|
+
const replicationStream = await this.factory.updateSyncRules(
|
|
79
79
|
updateSyncRulesFromYaml(content, { validate: true, storageVersion: LEGACY_STORAGE_VERSION })
|
|
80
80
|
);
|
|
81
|
-
this.syncRulesContent =
|
|
82
|
-
this.storage = this.factory.getInstance(
|
|
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
|
|
88
|
-
if (
|
|
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 =
|
|
93
|
-
this.storage =
|
|
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
|
|
99
|
-
if (
|
|
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 =
|
|
104
|
-
this.storage =
|
|
103
|
+
this.syncRulesContent = syncConfig.content;
|
|
104
|
+
this.storage = syncConfig.storage;
|
|
105
105
|
return this.storage!;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
private
|
|
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
|
|
187
|
-
const map = Object.entries(buckets).map(([bucket, start]) => bucketRequest(
|
|
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
|
|
199
|
+
const syncConfigContent = this.getSyncConfigContent();
|
|
200
200
|
const checkpoint = await this.getCheckpoint(options);
|
|
201
|
-
let map = [bucketRequest(
|
|
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(
|
|
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
|
|
231
|
-
const map = [bucketRequest(
|
|
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.
|
|
211
|
+
const storage = (await storageFactory.getActiveSyncConfig())?.storage;
|
|
212
212
|
const cp = await storage?.getCheckpoint();
|
|
213
213
|
if (cp != null) {
|
|
214
214
|
lastCp = cp;
|