@powersync/service-module-mssql 0.0.0-dev-20260602073133 → 0.0.0-dev-20260909133214
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +209 -4
- package/dist/api/MSSQLRouteAPIAdapter.d.ts +4 -5
- package/dist/api/MSSQLRouteAPIAdapter.js +33 -39
- package/dist/api/MSSQLRouteAPIAdapter.js.map +1 -1
- package/dist/common/MSSQLSourceTable.d.ts +12 -2
- package/dist/common/MSSQLSourceTable.js +30 -4
- package/dist/common/MSSQLSourceTable.js.map +1 -1
- package/dist/module/MSSQLModule.js +2 -1
- package/dist/module/MSSQLModule.js.map +1 -1
- package/dist/replication/CDCPoller.d.ts +13 -36
- package/dist/replication/CDCPoller.js +173 -129
- 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.d.ts +11 -14
- package/dist/replication/CDCStream.js +124 -115
- package/dist/replication/CDCStream.js.map +1 -1
- package/dist/replication/CaptureReconciler.d.ts +47 -0
- package/dist/replication/CaptureReconciler.js +155 -0
- package/dist/replication/CaptureReconciler.js.map +1 -0
- package/dist/replication/MSSQLConnectionManager.d.ts +1 -0
- package/dist/replication/MSSQLConnectionManager.js +19 -14
- package/dist/replication/MSSQLConnectionManager.js.map +1 -1
- package/dist/replication/MSSQLTableReconciliationContext.d.ts +21 -0
- package/dist/replication/MSSQLTableReconciliationContext.js +7 -0
- package/dist/replication/MSSQLTableReconciliationContext.js.map +1 -0
- package/dist/replication/SchemaChange.d.ts +67 -0
- package/dist/replication/SchemaChange.js +31 -0
- package/dist/replication/SchemaChange.js.map +1 -0
- package/dist/types/types.d.ts +13 -0
- package/dist/types/types.js +28 -2
- package/dist/types/types.js.map +1 -1
- package/dist/utils/mssql.js +1 -1
- package/dist/utils/schema.d.ts +14 -1
- package/dist/utils/schema.js +43 -45
- package/dist/utils/schema.js.map +1 -1
- package/package.json +11 -21
- package/src/api/MSSQLRouteAPIAdapter.ts +38 -49
- package/src/common/MSSQLSourceTable.ts +32 -4
- package/src/module/MSSQLModule.ts +2 -1
- package/src/replication/CDCPoller.ts +206 -162
- package/src/replication/CDCReplicationJob.ts +1 -1
- package/src/replication/CDCReplicator.ts +1 -1
- package/src/replication/CDCStream.ts +157 -163
- package/src/replication/CaptureReconciler.ts +186 -0
- package/src/replication/MSSQLConnectionManager.ts +23 -14
- package/src/replication/MSSQLTableReconciliationContext.ts +29 -0
- package/src/replication/SchemaChange.ts +79 -0
- package/src/types/types.ts +47 -2
- package/src/utils/mssql.ts +1 -1
- package/src/utils/schema.ts +60 -54
- package/test/src/CDCPoller.test.ts +382 -0
- package/test/src/CDCStream.test.ts +6 -2
- package/test/src/CDCStreamTestContext.ts +30 -23
- package/test/src/CaptureReconciler.test.ts +171 -0
- package/test/src/MSSQLSourceTable.test.ts +30 -0
- package/test/src/config.test.ts +71 -0
- package/test/src/schema-changes.test.ts +513 -249
- package/test/src/schema.test.ts +17 -0
- package/test/src/util.ts +73 -9
- package/tsconfig.json +0 -3
- package/tsconfig.tsbuildinfo +1 -1
package/dist/utils/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEpF,OAAO,GAAG,MAAM,OAAO,CAAC;AAUxB,KAAK,UAAU,UAAU,CAAC,OAA0B;IAClD,MAAM,EAAE,iBAAiB,EAAE,MAAM,E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H,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE;KACnD,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/service-module-mssql",
|
|
3
3
|
"repository": "https://github.com/powersync-ja/powersync-service",
|
|
4
|
-
"
|
|
5
|
-
"version": "0.0.0-dev-20260602073133",
|
|
4
|
+
"version": "0.0.0-dev-20260909133214",
|
|
6
5
|
"license": "FSL-1.1-ALv2",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
6
|
"type": "module",
|
|
9
7
|
"publishConfig": {
|
|
10
8
|
"access": "public"
|
|
11
9
|
},
|
|
12
10
|
"exports": {
|
|
13
|
-
".":
|
|
14
|
-
|
|
15
|
-
"require": "./dist/index.js",
|
|
16
|
-
"default": "./dist/index.js"
|
|
17
|
-
},
|
|
18
|
-
"./types": {
|
|
19
|
-
"import": "./dist/types/types.js",
|
|
20
|
-
"require": "./dist/types/types.js",
|
|
21
|
-
"default": "./dist/types/types.js"
|
|
22
|
-
}
|
|
11
|
+
".": "./dist/index.js",
|
|
12
|
+
"./types": "./dist/types/types.js"
|
|
23
13
|
},
|
|
24
14
|
"dependencies": {
|
|
25
15
|
"mssql": "^12.2.1",
|
|
@@ -27,20 +17,20 @@
|
|
|
27
17
|
"ts-codec": "^1.3.0",
|
|
28
18
|
"uri-js": "^4.4.1",
|
|
29
19
|
"uuid": "^14.0.0",
|
|
30
|
-
"@powersync/lib-services-framework": "0.0.0-dev-
|
|
31
|
-
"@powersync/service-core": "0.0.0-dev-
|
|
32
|
-
"@powersync/service-errors": "0.
|
|
20
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20260909133214",
|
|
21
|
+
"@powersync/service-core": "0.0.0-dev-20260909133214",
|
|
22
|
+
"@powersync/service-errors": "0.5.0",
|
|
33
23
|
"@powersync/service-jsonbig": "0.17.13",
|
|
34
|
-
"@powersync/service-sync-rules": "0.0.0-dev-
|
|
35
|
-
"@powersync/service-types": "0.
|
|
24
|
+
"@powersync/service-sync-rules": "0.0.0-dev-20260909133214",
|
|
25
|
+
"@powersync/service-types": "0.18.0"
|
|
36
26
|
},
|
|
37
27
|
"devDependencies": {
|
|
38
28
|
"@types/mssql": "^9.1.9",
|
|
39
29
|
"@types/semver": "^7.7.1",
|
|
40
30
|
"@types/uuid": "^11.0.0",
|
|
41
|
-
"@powersync/service-core-tests": "0.0.0-dev-
|
|
42
|
-
"@powersync/service-module-mongodb-storage": "0.0.0-dev-
|
|
43
|
-
"@powersync/service-module-postgres-storage": "0.0.0-dev-
|
|
31
|
+
"@powersync/service-core-tests": "0.0.0-dev-20260909133214",
|
|
32
|
+
"@powersync/service-module-mongodb-storage": "0.0.0-dev-20260909133214",
|
|
33
|
+
"@powersync/service-module-postgres-storage": "0.0.0-dev-20260909133214"
|
|
44
34
|
},
|
|
45
35
|
"scripts": {
|
|
46
36
|
"build": "tsc -b",
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
api,
|
|
3
|
-
ParseSyncRulesOptions,
|
|
4
|
-
PatternResult,
|
|
5
|
-
ReplicationHeadCallback,
|
|
6
|
-
ReplicationLagOptions
|
|
7
|
-
} from '@powersync/service-core';
|
|
1
|
+
import { api, ParseSyncConfigOptions, PatternResult, ReplicationLagOptions } from '@powersync/service-core';
|
|
8
2
|
import { SqlSyncRules, TablePattern } from '@powersync/service-sync-rules';
|
|
9
3
|
import * as service_types from '@powersync/service-types';
|
|
10
|
-
import { ExecuteSqlResponse } from '@powersync/service-types/dist/routes.js';
|
|
11
4
|
import sql from 'mssql';
|
|
12
5
|
import { toExpressionTypeFromMSSQLType } from '../common/mssqls-to-sqlite.js';
|
|
13
6
|
import { MSSQLConnectionManager } from '../replication/MSSQLConnectionManager.js';
|
|
@@ -19,7 +12,7 @@ import {
|
|
|
19
12
|
getLatestLSN,
|
|
20
13
|
POWERSYNC_CHECKPOINTS_TABLE
|
|
21
14
|
} from '../utils/mssql.js';
|
|
22
|
-
import { getTablesFromPattern, ResolvedTable } from '../utils/schema.js';
|
|
15
|
+
import { getTablesFromPattern, ResolvedTable, unsupportedTablePatternMessage } from '../utils/schema.js';
|
|
23
16
|
|
|
24
17
|
export class MSSQLRouteAPIAdapter implements api.RouteAPI {
|
|
25
18
|
protected connectionManager: MSSQLConnectionManager;
|
|
@@ -28,17 +21,19 @@ export class MSSQLRouteAPIAdapter implements api.RouteAPI {
|
|
|
28
21
|
this.connectionManager = new MSSQLConnectionManager(config, {});
|
|
29
22
|
}
|
|
30
23
|
|
|
31
|
-
async createReplicationHead<T>(callback: ReplicationHeadCallback<T>): Promise<T> {
|
|
32
|
-
const currentLSN = await getLatestLSN(this.connectionManager);
|
|
33
|
-
const
|
|
24
|
+
async createReplicationHead<T>(callback: api.ReplicationHeadCallback<T>): Promise<T> {
|
|
25
|
+
const currentLSN = (await getLatestLSN(this.connectionManager)).toString();
|
|
26
|
+
const { response, shouldAdvance } = await callback(currentLSN);
|
|
34
27
|
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
if (shouldAdvance) {
|
|
29
|
+
// Updates the powersync checkpoints table on the source database, ensuring that an update with a newer LSN will be captured by the CDC.
|
|
30
|
+
await createCheckpoint(this.connectionManager);
|
|
31
|
+
}
|
|
37
32
|
|
|
38
|
-
return
|
|
33
|
+
return response;
|
|
39
34
|
}
|
|
40
35
|
|
|
41
|
-
async executeQuery(query: string, params: any[]): Promise<ExecuteSqlResponse> {
|
|
36
|
+
async executeQuery(query: string, params: any[]): Promise<service_types.internal_routes.ExecuteSqlResponse> {
|
|
42
37
|
return service_types.internal_routes.ExecuteSqlResponse.encode({
|
|
43
38
|
results: {
|
|
44
39
|
columns: [],
|
|
@@ -187,47 +182,41 @@ export class MSSQLRouteAPIAdapter implements api.RouteAPI {
|
|
|
187
182
|
};
|
|
188
183
|
result.push(patternResult);
|
|
189
184
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// This should technically never happen, but we'll handle it anyway.
|
|
205
|
-
const resolvedTable: ResolvedTable = {
|
|
206
|
-
objectId: 0,
|
|
207
|
-
schema: schema,
|
|
208
|
-
name: tablePattern.name
|
|
209
|
-
};
|
|
210
|
-
patternResult.table = await getDebugTableInfo({
|
|
211
|
-
connectionManager: this.connectionManager,
|
|
212
|
-
tablePattern,
|
|
213
|
-
table: resolvedTable,
|
|
214
|
-
syncRules: sqlSyncRules
|
|
215
|
-
});
|
|
185
|
+
// Unsupported patterns are reported per pattern here, rather than failing the whole request.
|
|
186
|
+
const unsupported = unsupportedTablePatternMessage(tablePattern);
|
|
187
|
+
if (unsupported != null) {
|
|
188
|
+
const unsupportedTable: service_types.TableInfo = {
|
|
189
|
+
schema,
|
|
190
|
+
name: tablePattern.tablePattern,
|
|
191
|
+
pattern: tablePattern.tablePattern,
|
|
192
|
+
replication_id: [],
|
|
193
|
+
data_queries: false,
|
|
194
|
+
parameter_queries: false,
|
|
195
|
+
errors: [{ level: 'fatal', message: unsupported }]
|
|
196
|
+
};
|
|
197
|
+
if (patternResult.wildcard) {
|
|
198
|
+
patternResult.tables = [unsupportedTable];
|
|
216
199
|
} else {
|
|
217
|
-
patternResult.table =
|
|
218
|
-
connectionManager: this.connectionManager,
|
|
219
|
-
tablePattern,
|
|
220
|
-
table: tables[0],
|
|
221
|
-
syncRules: sqlSyncRules
|
|
222
|
-
});
|
|
200
|
+
patternResult.table = unsupportedTable;
|
|
223
201
|
}
|
|
202
|
+
continue;
|
|
224
203
|
}
|
|
204
|
+
|
|
205
|
+
const tables = await getTablesFromPattern(this.connectionManager, tablePattern);
|
|
206
|
+
// A missing table is still reported, so that its errors are surfaced.
|
|
207
|
+
const resolvedTable: ResolvedTable = tables[0] ?? { objectId: 0, schema: schema, name: tablePattern.name };
|
|
208
|
+
patternResult.table = await getDebugTableInfo({
|
|
209
|
+
connectionManager: this.connectionManager,
|
|
210
|
+
tablePattern,
|
|
211
|
+
table: resolvedTable,
|
|
212
|
+
syncRules: sqlSyncRules
|
|
213
|
+
});
|
|
225
214
|
}
|
|
226
215
|
|
|
227
216
|
return result;
|
|
228
217
|
}
|
|
229
218
|
|
|
230
|
-
getParseSyncRulesOptions():
|
|
219
|
+
getParseSyncRulesOptions(): ParseSyncConfigOptions {
|
|
231
220
|
return {
|
|
232
221
|
defaultSchema: this.connectionManager.schema
|
|
233
222
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SourceEntityDescriptor, SourceTable } from '@powersync/service-core';
|
|
2
2
|
import { ServiceAssertionError } from '@powersync/service-errors';
|
|
3
|
+
import { readCaptureMetadata } from '../replication/CaptureReconciler.js';
|
|
3
4
|
import { toQualifiedTableName } from '../utils/mssql.js';
|
|
4
5
|
import { CaptureInstance } from './CaptureInstance.js';
|
|
5
6
|
|
|
@@ -26,9 +27,15 @@ export class MSSQLSourceTable {
|
|
|
26
27
|
|
|
27
28
|
public readonly ref: SourceEntityDescriptor;
|
|
28
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Decoded once, since the persisted metadata only changes when a SourceTable is replaced.
|
|
32
|
+
*/
|
|
33
|
+
private captureObjectId: number | null;
|
|
34
|
+
|
|
29
35
|
constructor(ref: SourceEntityDescriptor, sourceTables: SourceTable[]) {
|
|
30
36
|
this.sourceTables = sourceTables;
|
|
31
37
|
this.ref = ref;
|
|
38
|
+
this.captureObjectId = readPinnedCaptureObjectId(sourceTables);
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
updateSourceTable(updated: SourceTable): void {
|
|
@@ -37,6 +44,7 @@ export class MSSQLSourceTable {
|
|
|
37
44
|
throw new ServiceAssertionError(`No SourceTable found for table: ${updated.id}`);
|
|
38
45
|
}
|
|
39
46
|
this.sourceTables[index] = updated;
|
|
47
|
+
this.captureObjectId = readPinnedCaptureObjectId(this.sourceTables);
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
getReplicatedSourceTables(): SourceTable[] {
|
|
@@ -47,12 +55,19 @@ export class MSSQLSourceTable {
|
|
|
47
55
|
return this.captureInstance !== null;
|
|
48
56
|
}
|
|
49
57
|
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Persisted capture-table object id, or null for a legacy binding.
|
|
60
|
+
*/
|
|
61
|
+
get pinnedCaptureObjectId(): number | null {
|
|
62
|
+
return this.captureObjectId;
|
|
52
63
|
}
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Bind the available capture instance matching this table's persisted identity.
|
|
67
|
+
*/
|
|
68
|
+
setCaptureInstance(availableInstances: readonly CaptureInstance[]): void {
|
|
69
|
+
this.captureInstance =
|
|
70
|
+
availableInstances.find((instance) => instance.objectId === this.pinnedCaptureObjectId) ?? null;
|
|
56
71
|
}
|
|
57
72
|
|
|
58
73
|
get allChangesFunction() {
|
|
@@ -84,3 +99,16 @@ export class MSSQLSourceTable {
|
|
|
84
99
|
return toQualifiedTableName(this.ref.schema, this.ref.name);
|
|
85
100
|
}
|
|
86
101
|
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The pinned capture-table object id shared by these records, or null for a legacy binding.
|
|
105
|
+
*/
|
|
106
|
+
function readPinnedCaptureObjectId(sourceTables: SourceTable[]): number | null {
|
|
107
|
+
for (const sourceTable of sourceTables) {
|
|
108
|
+
const metadata = readCaptureMetadata(sourceTable.sourceMetadata);
|
|
109
|
+
if (metadata != null) {
|
|
110
|
+
return metadata.captureTableObjectId;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
@@ -41,7 +41,8 @@ export class MSSQLModule extends replication.ReplicationModule<types.MSSQLConnec
|
|
|
41
41
|
metricsEngine: context.metricsEngine,
|
|
42
42
|
connectionFactory: connectionFactory,
|
|
43
43
|
rateLimiter: new MSSQLErrorRateLimiter(),
|
|
44
|
-
additionalConfig: normalisedConfig.additionalConfig
|
|
44
|
+
additionalConfig: normalisedConfig.additionalConfig,
|
|
45
|
+
heartbeatIntervalSeconds: normalisedConfig.heartbeat_interval_seconds
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
|