@powersync/service-module-mssql 0.0.0-dev-20251128080741

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 (92) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/LICENSE +67 -0
  3. package/README.md +3 -0
  4. package/ci/init-mssql.sql +50 -0
  5. package/dist/api/MSSQLRouteAPIAdapter.d.ts +21 -0
  6. package/dist/api/MSSQLRouteAPIAdapter.js +248 -0
  7. package/dist/api/MSSQLRouteAPIAdapter.js.map +1 -0
  8. package/dist/common/LSN.d.ts +37 -0
  9. package/dist/common/LSN.js +64 -0
  10. package/dist/common/LSN.js.map +1 -0
  11. package/dist/common/MSSQLSourceTable.d.ts +27 -0
  12. package/dist/common/MSSQLSourceTable.js +35 -0
  13. package/dist/common/MSSQLSourceTable.js.map +1 -0
  14. package/dist/common/MSSQLSourceTableCache.d.ts +14 -0
  15. package/dist/common/MSSQLSourceTableCache.js +28 -0
  16. package/dist/common/MSSQLSourceTableCache.js.map +1 -0
  17. package/dist/common/mssqls-to-sqlite.d.ts +18 -0
  18. package/dist/common/mssqls-to-sqlite.js +143 -0
  19. package/dist/common/mssqls-to-sqlite.js.map +1 -0
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +2 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/module/MSSQLModule.d.ts +15 -0
  24. package/dist/module/MSSQLModule.js +68 -0
  25. package/dist/module/MSSQLModule.js.map +1 -0
  26. package/dist/replication/CDCPoller.d.ts +67 -0
  27. package/dist/replication/CDCPoller.js +188 -0
  28. package/dist/replication/CDCPoller.js.map +1 -0
  29. package/dist/replication/CDCReplicationJob.d.ts +17 -0
  30. package/dist/replication/CDCReplicationJob.js +76 -0
  31. package/dist/replication/CDCReplicationJob.js.map +1 -0
  32. package/dist/replication/CDCReplicator.d.ts +18 -0
  33. package/dist/replication/CDCReplicator.js +55 -0
  34. package/dist/replication/CDCReplicator.js.map +1 -0
  35. package/dist/replication/CDCStream.d.ts +106 -0
  36. package/dist/replication/CDCStream.js +539 -0
  37. package/dist/replication/CDCStream.js.map +1 -0
  38. package/dist/replication/MSSQLConnectionManager.d.ts +23 -0
  39. package/dist/replication/MSSQLConnectionManager.js +97 -0
  40. package/dist/replication/MSSQLConnectionManager.js.map +1 -0
  41. package/dist/replication/MSSQLConnectionManagerFactory.d.ts +10 -0
  42. package/dist/replication/MSSQLConnectionManagerFactory.js +28 -0
  43. package/dist/replication/MSSQLConnectionManagerFactory.js.map +1 -0
  44. package/dist/replication/MSSQLErrorRateLimiter.d.ts +10 -0
  45. package/dist/replication/MSSQLErrorRateLimiter.js +34 -0
  46. package/dist/replication/MSSQLErrorRateLimiter.js.map +1 -0
  47. package/dist/replication/MSSQLSnapshotQuery.d.ts +71 -0
  48. package/dist/replication/MSSQLSnapshotQuery.js +190 -0
  49. package/dist/replication/MSSQLSnapshotQuery.js.map +1 -0
  50. package/dist/types/mssql-data-types.d.ts +66 -0
  51. package/dist/types/mssql-data-types.js +62 -0
  52. package/dist/types/mssql-data-types.js.map +1 -0
  53. package/dist/types/types.d.ts +177 -0
  54. package/dist/types/types.js +141 -0
  55. package/dist/types/types.js.map +1 -0
  56. package/dist/utils/mssql.d.ts +80 -0
  57. package/dist/utils/mssql.js +329 -0
  58. package/dist/utils/mssql.js.map +1 -0
  59. package/dist/utils/schema.d.ts +21 -0
  60. package/dist/utils/schema.js +131 -0
  61. package/dist/utils/schema.js.map +1 -0
  62. package/package.json +51 -0
  63. package/src/api/MSSQLRouteAPIAdapter.ts +283 -0
  64. package/src/common/LSN.ts +77 -0
  65. package/src/common/MSSQLSourceTable.ts +54 -0
  66. package/src/common/MSSQLSourceTableCache.ts +36 -0
  67. package/src/common/mssqls-to-sqlite.ts +151 -0
  68. package/src/index.ts +1 -0
  69. package/src/module/MSSQLModule.ts +82 -0
  70. package/src/replication/CDCPoller.ts +247 -0
  71. package/src/replication/CDCReplicationJob.ts +87 -0
  72. package/src/replication/CDCReplicator.ts +70 -0
  73. package/src/replication/CDCStream.ts +691 -0
  74. package/src/replication/MSSQLConnectionManager.ts +113 -0
  75. package/src/replication/MSSQLConnectionManagerFactory.ts +33 -0
  76. package/src/replication/MSSQLErrorRateLimiter.ts +36 -0
  77. package/src/replication/MSSQLSnapshotQuery.ts +230 -0
  78. package/src/types/mssql-data-types.ts +79 -0
  79. package/src/types/types.ts +224 -0
  80. package/src/utils/mssql.ts +420 -0
  81. package/src/utils/schema.ts +172 -0
  82. package/test/src/CDCStream.test.ts +204 -0
  83. package/test/src/CDCStreamTestContext.ts +212 -0
  84. package/test/src/CDCStream_resumable_snapshot.test.ts +159 -0
  85. package/test/src/env.ts +11 -0
  86. package/test/src/mssql-to-sqlite.test.ts +474 -0
  87. package/test/src/setup.ts +12 -0
  88. package/test/src/util.ts +188 -0
  89. package/test/tsconfig.json +28 -0
  90. package/tsconfig.json +26 -0
  91. package/tsconfig.tsbuildinfo +1 -0
  92. package/vitest.config.ts +15 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # @powersync/service-module-mssql
2
+
3
+ ## 0.0.0-dev-20251128080741
4
+
5
+ ### Minor Changes
6
+
7
+ - f51f987: - First iteration of MSSQL replication using Change Data Capture (CDC).
8
+ - Supports resumable snapshot replication
9
+ - Uses CDC polling for replication
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [57f7660]
14
+ - Updated dependencies [0156d10]
15
+ - Updated dependencies [f51f987]
16
+ - @powersync/service-core@0.0.0-dev-20251128080741
17
+ - @powersync/service-types@0.0.0-dev-20251128080741
18
+ - @powersync/service-sync-rules@0.0.0-dev-20251128080741
19
+ - @powersync/service-errors@0.0.0-dev-20251128080741
20
+ - @powersync/lib-services-framework@0.0.0-dev-20251128080741
package/LICENSE ADDED
@@ -0,0 +1,67 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2023-2025 Journey Mobile, Inc.
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under these Terms and Conditions, as indicated by our inclusion of these Terms and Conditions with the Software.
20
+
21
+ ### License Grant
22
+
23
+ Subject to your compliance with this License Grant and the Patents, Redistribution and Trademark clauses below, we hereby grant you the right to use, copy, modify, create derivative works, publicly perform, publicly display and redistribute the Software for any Permitted Purpose identified below.
24
+
25
+ ### Permitted Purpose
26
+
27
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use means making the Software available to others in a commercial product or service that:
28
+
29
+ 1. substitutes for the Software;
30
+ 2. substitutes for any other product or service we offer using the Software that exists as of the date we make the Software available; or
31
+ 3. offers the same or substantially similar functionality as the Software.
32
+
33
+ Permitted Purposes specifically include using the Software:
34
+
35
+ 1. for your internal use and access;
36
+ 2. for non-commercial education;
37
+ 3. for non-commercial research; and
38
+ 4. in connection with professional services that you provide to a licensee using the Software in accordance with these Terms and Conditions.
39
+
40
+ ### Patents
41
+
42
+ To the extent your use for a Permitted Purpose would necessarily infringe our patents, the license grant above includes a license under our patents. If you make a claim against any party that the Software infringes or contributes to the infringement of any patent, then your patent license to the Software ends immediately.
43
+
44
+ ### Redistribution
45
+
46
+ The Terms and Conditions apply to all copies, modifications and derivatives of the Software.
47
+ If you redistribute any copies, modifications or derivatives of the Software, you must include a copy of or a link to these Terms and Conditions and not remove any copyright notices provided in or with the Software.
48
+
49
+ ### Disclaimer
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
52
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
53
+
54
+ ### Trademarks
55
+
56
+ Except for displaying the License Details and identifying us as the origin of the Software, you have no right under these Terms and Conditions to use our trademarks, trade names, service marks or product names.
57
+
58
+ ## Grant of Future License
59
+
60
+ We hereby irrevocably grant you an additional license to use the Software under the Apache License, Version 2.0 that is effective on the second anniversary of the date we make the Software available. On or after that date, you may use the Software under the Apache License, Version 2.0, in which case the following will apply:
61
+
62
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
63
+ You may obtain a copy of the License at
64
+
65
+ http://www.apache.org/licenses/LICENSE-2.0
66
+
67
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # PowerSync MSSQL Module
2
+
3
+ MSSQL replication module for PowerSync
@@ -0,0 +1,50 @@
1
+ -- Create database (idempotent)
2
+ IF DB_ID('$(DATABASE)') IS NULL
3
+ BEGIN
4
+ CREATE DATABASE [$(DATABASE)];
5
+ END
6
+ GO
7
+
8
+ -- Enable CDC at the database level (idempotent)
9
+ USE [$(DATABASE)];
10
+ IF (SELECT is_cdc_enabled FROM sys.databases WHERE name = '$(DATABASE)') = 0
11
+ BEGIN
12
+ EXEC sys.sp_cdc_enable_db;
13
+ END
14
+ GO
15
+
16
+ -- Create PowerSync checkpoints table
17
+ -- Powersync requires this table to ensure regular checkpoints appear in CDC
18
+ IF OBJECT_ID('dbo._powersync_checkpoints', 'U') IS NULL
19
+ BEGIN
20
+ CREATE TABLE dbo._powersync_checkpoints (
21
+ id INT IDENTITY PRIMARY KEY,
22
+ last_updated DATETIME NOT NULL DEFAULT (GETDATE())
23
+ );
24
+ END
25
+
26
+ GRANT INSERT, UPDATE ON dbo._powersync_checkpoints TO [$(DB_USER)];
27
+ GO
28
+
29
+ -- Enable CDC for the powersync checkpoints table
30
+ IF NOT EXISTS (SELECT 1 FROM cdc.change_tables WHERE source_object_id = OBJECT_ID(N'dbo._powersync_checkpoints'))
31
+ BEGIN
32
+ EXEC sys.sp_cdc_enable_table
33
+ @source_schema = N'dbo',
34
+ @source_name = N'_powersync_checkpoints',
35
+ @role_name = N'cdc_reader',
36
+ @supports_net_changes = 0;
37
+ END
38
+ GO
39
+
40
+ -- Wait until capture job exists - usually takes a few seconds after enabling CDC on a table for the first time
41
+ DECLARE @tries int = 10;
42
+ WHILE @tries > 0 AND NOT EXISTS (SELECT 1 FROM msdb.dbo.cdc_jobs WHERE job_type = N'capture')
43
+ BEGIN
44
+ WAITFOR DELAY '00:00:01';
45
+ SET @tries -= 1;
46
+ END;
47
+
48
+ -- Set the CDC capture job polling interval to 1 second (default is 5 seconds)
49
+ EXEC sys.sp_cdc_change_job @job_type = N'capture', @pollinginterval = 1;
50
+ GO
@@ -0,0 +1,21 @@
1
+ import { api, ParseSyncRulesOptions, PatternResult, ReplicationHeadCallback, ReplicationLagOptions } from '@powersync/service-core';
2
+ import * as service_types from '@powersync/service-types';
3
+ import { SqlSyncRules, TablePattern } from '@powersync/service-sync-rules';
4
+ import * as types from '../types/types.js';
5
+ import { ExecuteSqlResponse } from '@powersync/service-types/dist/routes.js';
6
+ import { MSSQLConnectionManager } from '../replication/MSSQLConnectionManager.js';
7
+ export declare class MSSQLRouteAPIAdapter implements api.RouteAPI {
8
+ protected config: types.ResolvedMSSQLConnectionConfig;
9
+ protected connectionManager: MSSQLConnectionManager;
10
+ constructor(config: types.ResolvedMSSQLConnectionConfig);
11
+ createReplicationHead<T>(callback: ReplicationHeadCallback<T>): Promise<T>;
12
+ executeQuery(query: string, params: any[]): Promise<ExecuteSqlResponse>;
13
+ getConnectionSchema(): Promise<service_types.DatabaseSchema[]>;
14
+ getConnectionStatus(): Promise<service_types.ConnectionStatusV2>;
15
+ getDebugTablesInfo(tablePatterns: TablePattern[], sqlSyncRules: SqlSyncRules): Promise<PatternResult[]>;
16
+ getParseSyncRulesOptions(): ParseSyncRulesOptions;
17
+ getReplicationLagBytes(options: ReplicationLagOptions): Promise<number | undefined>;
18
+ getSourceConfig(): Promise<service_types.configFile.ResolvedDataSourceConfig>;
19
+ [Symbol.asyncDispose](): Promise<void>;
20
+ shutdown(): Promise<void>;
21
+ }
@@ -0,0 +1,248 @@
1
+ import * as service_types from '@powersync/service-types';
2
+ import * as sync_rules from '@powersync/service-sync-rules';
3
+ import * as types from '../types/types.js';
4
+ import { MSSQLConnectionManager } from '../replication/MSSQLConnectionManager.js';
5
+ import { checkSourceConfiguration, createCheckpoint, getDebugTableInfo, getLatestLSN, POWERSYNC_CHECKPOINTS_TABLE } from '../utils/mssql.js';
6
+ import { getTablesFromPattern } from '../utils/schema.js';
7
+ import { toExpressionTypeFromMSSQLType } from '../common/mssqls-to-sqlite.js';
8
+ export class MSSQLRouteAPIAdapter {
9
+ config;
10
+ connectionManager;
11
+ constructor(config) {
12
+ this.config = config;
13
+ this.connectionManager = new MSSQLConnectionManager(config, {});
14
+ }
15
+ async createReplicationHead(callback) {
16
+ const currentLSN = await getLatestLSN(this.connectionManager);
17
+ const result = await callback(currentLSN.toString());
18
+ // Updates the powersync checkpoints table on the source database, ensuring that an update with a newer LSN will be captured by the CDC.
19
+ await createCheckpoint(this.connectionManager);
20
+ return result;
21
+ }
22
+ async executeQuery(query, params) {
23
+ if (!this.config.debug_api) {
24
+ return service_types.internal_routes.ExecuteSqlResponse.encode({
25
+ results: {
26
+ columns: [],
27
+ rows: []
28
+ },
29
+ success: false,
30
+ error: 'SQL querying is not enabled'
31
+ });
32
+ }
33
+ try {
34
+ const { recordset: result } = await this.connectionManager.query(query, params);
35
+ return service_types.internal_routes.ExecuteSqlResponse.encode({
36
+ success: true,
37
+ results: {
38
+ columns: Object.values(result.columns).map((column) => column.name),
39
+ rows: result.map((row) => {
40
+ return Object.values(row).map((value) => {
41
+ const sqlValue = sync_rules.applyValueContext(sync_rules.toSyncRulesValue(row), sync_rules.CompatibilityContext.FULL_BACKWARDS_COMPATIBILITY);
42
+ if (typeof sqlValue == 'bigint') {
43
+ return Number(row);
44
+ }
45
+ else if (value instanceof Date) {
46
+ return value.toISOString();
47
+ }
48
+ else if (sync_rules.isJsonValue(sqlValue)) {
49
+ return sqlValue;
50
+ }
51
+ else {
52
+ return null;
53
+ }
54
+ });
55
+ })
56
+ }
57
+ });
58
+ }
59
+ catch (e) {
60
+ return service_types.internal_routes.ExecuteSqlResponse.encode({
61
+ results: {
62
+ columns: [],
63
+ rows: []
64
+ },
65
+ success: false,
66
+ error: e.message
67
+ });
68
+ }
69
+ }
70
+ async getConnectionSchema() {
71
+ const { recordset: results } = await this.connectionManager.query(`
72
+ SELECT
73
+ sch.name AS schema_name,
74
+ tbl.name AS table_name,
75
+ col.name AS column_name,
76
+ typ.name AS data_type,
77
+ CASE
78
+ WHEN typ.name IN ('nvarchar', 'nchar')
79
+ AND col.max_length > 0
80
+ AND col.max_length != -1
81
+ THEN typ.name + '(' + CAST(col.max_length / 2 AS VARCHAR) + ')'
82
+ WHEN typ.name IN ('varchar', 'char', 'varbinary', 'binary')
83
+ AND col.max_length > 0
84
+ AND col.max_length != -1
85
+ THEN typ.name + '(' + CAST(col.max_length AS VARCHAR) + ')'
86
+ WHEN typ.name IN ('varchar', 'nvarchar', 'char', 'nchar')
87
+ AND col.max_length = -1
88
+ THEN typ.name + '(MAX)'
89
+ WHEN typ.name IN ('decimal', 'numeric')
90
+ AND col.precision > 0
91
+ THEN typ.name + '(' + CAST(col.precision AS VARCHAR) + ',' + CAST(col.scale AS VARCHAR) + ')'
92
+ WHEN typ.name IN ('float', 'real')
93
+ AND col.precision > 0
94
+ THEN typ.name + '(' + CAST(col.precision AS VARCHAR) + ')'
95
+ ELSE typ.name
96
+ END AS formatted_type
97
+ FROM sys.tables AS tbl
98
+ JOIN sys.schemas AS sch ON sch.schema_id = tbl.schema_id
99
+ JOIN sys.columns AS col ON col.object_id = tbl.object_id
100
+ JOIN sys.types AS typ ON typ.user_type_id = col.user_type_id
101
+ WHERE sch.name = '${this.connectionManager.schema}'
102
+ AND sch.name NOT IN ('sys', 'INFORMATION_SCHEMA', 'cdc')
103
+ AND tbl.name NOT IN ('systranschemas', '${POWERSYNC_CHECKPOINTS_TABLE}')
104
+ AND tbl.type = 'U'
105
+ AND col.is_computed = 0
106
+ ORDER BY sch.name, tbl.name, col.column_id
107
+ `);
108
+ /**
109
+ * Reduces the SQL results into a Record of {@link DatabaseSchema}
110
+ * then returns the values as an array.
111
+ */
112
+ const schemas = {};
113
+ for (const row of results) {
114
+ const schemaName = row.schema_name;
115
+ const tableName = row.table_name;
116
+ const columnName = row.column_name;
117
+ const dataType = row.data_type;
118
+ const formattedType = row.formatted_type || dataType;
119
+ const schema = schemas[schemaName] ||
120
+ (schemas[schemaName] = {
121
+ name: schemaName,
122
+ tables: []
123
+ });
124
+ let table = schema.tables.find((t) => t.name === tableName);
125
+ if (!table) {
126
+ table = {
127
+ name: tableName,
128
+ columns: []
129
+ };
130
+ schema.tables.push(table);
131
+ }
132
+ table.columns.push({
133
+ name: columnName,
134
+ type: formattedType,
135
+ sqlite_type: toExpressionTypeFromMSSQLType(dataType).typeFlags,
136
+ internal_type: formattedType,
137
+ pg_type: formattedType
138
+ });
139
+ }
140
+ return Object.values(schemas);
141
+ }
142
+ async getConnectionStatus() {
143
+ const base = {
144
+ id: this.config?.id ?? '',
145
+ uri: this.config == null ? '' : types.baseUri(this.config)
146
+ };
147
+ try {
148
+ await this.connectionManager.query(`SELECT 'PowerSync connection test'`);
149
+ }
150
+ catch (e) {
151
+ return {
152
+ ...base,
153
+ connected: false,
154
+ errors: [{ level: 'fatal', message: `${e.code} - message: ${e.message}` }]
155
+ };
156
+ }
157
+ try {
158
+ const errors = await checkSourceConfiguration(this.connectionManager);
159
+ if (errors.length) {
160
+ return {
161
+ ...base,
162
+ connected: true,
163
+ errors: errors.map((e) => ({ level: 'fatal', message: e }))
164
+ };
165
+ }
166
+ }
167
+ catch (e) {
168
+ return {
169
+ ...base,
170
+ connected: true,
171
+ errors: [{ level: 'fatal', message: e.message }]
172
+ };
173
+ }
174
+ return {
175
+ ...base,
176
+ connected: true,
177
+ errors: []
178
+ };
179
+ }
180
+ async getDebugTablesInfo(tablePatterns, sqlSyncRules) {
181
+ const result = [];
182
+ for (const tablePattern of tablePatterns) {
183
+ const schema = tablePattern.schema;
184
+ const patternResult = {
185
+ schema: schema,
186
+ pattern: tablePattern.tablePattern,
187
+ wildcard: tablePattern.isWildcard
188
+ };
189
+ result.push(patternResult);
190
+ const tables = await getTablesFromPattern(this.connectionManager, tablePattern);
191
+ if (tablePattern.isWildcard) {
192
+ patternResult.tables = [];
193
+ for (const table of tables) {
194
+ const details = await getDebugTableInfo({
195
+ connectionManager: this.connectionManager,
196
+ tablePattern,
197
+ table,
198
+ syncRules: sqlSyncRules
199
+ });
200
+ patternResult.tables.push(details);
201
+ }
202
+ }
203
+ else {
204
+ if (tables.length == 0) {
205
+ // This should tenchnically never happen, but we'll handle it anyway.
206
+ const resolvedTable = {
207
+ objectId: 0,
208
+ schema: schema,
209
+ name: tablePattern.name
210
+ };
211
+ patternResult.table = await getDebugTableInfo({
212
+ connectionManager: this.connectionManager,
213
+ tablePattern,
214
+ table: resolvedTable,
215
+ syncRules: sqlSyncRules
216
+ });
217
+ }
218
+ else {
219
+ patternResult.table = await getDebugTableInfo({
220
+ connectionManager: this.connectionManager,
221
+ tablePattern,
222
+ table: tables[0],
223
+ syncRules: sqlSyncRules
224
+ });
225
+ }
226
+ }
227
+ }
228
+ return result;
229
+ }
230
+ getParseSyncRulesOptions() {
231
+ return {
232
+ defaultSchema: this.connectionManager.schema
233
+ };
234
+ }
235
+ async getReplicationLagBytes(options) {
236
+ return undefined;
237
+ }
238
+ async getSourceConfig() {
239
+ return this.config;
240
+ }
241
+ async [Symbol.asyncDispose]() {
242
+ await this.shutdown();
243
+ }
244
+ async shutdown() {
245
+ await this.connectionManager.end();
246
+ }
247
+ }
248
+ //# sourceMappingURL=MSSQLRouteAPIAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MSSQLRouteAPIAdapter.js","sourceRoot":"","sources":["../../src/api/MSSQLRouteAPIAdapter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,UAAU,MAAM,+BAA+B,CAAC;AAE5D,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,2BAA2B,EAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAiB,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAE9E,MAAM,OAAO,oBAAoB;IAGT;IAFZ,iBAAiB,CAAyB;IAEpD,YAAsB,MAA2C;QAA3C,WAAM,GAAN,MAAM,CAAqC;QAC/D,IAAI,CAAC,iBAAiB,GAAG,IAAI,sBAAsB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAI,QAAoC;QACjE,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC9D,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;QAErD,wIAAwI;QACxI,MAAM,gBAAgB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAE/C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,KAAa,EAAE,MAAa;QAC7C,IAAI,CAAC,IAAI,CAAC,MAAM,CA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K,CAAC,QAAQ;QACZ,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Helper class for interpreting and manipulating SQL Server Log Sequence Numbers (LSNs).
3
+ * In SQL Server, an LSN is stored as a 10-byte binary value.
4
+ * But it is commonly represented in a human-readable format as three hexadecimal parts separated by colons:
5
+ * `00000000:00000000:0000`.
6
+ *
7
+ * The three parts represent different hierarchical levels of the transaction log:
8
+ * 1. The first part identifies the Virtual Log File (VLF).
9
+ * 2. The second part points to the log block within the VLF.
10
+ * 3. The third part specifies the exact log record within the log block.
11
+ */
12
+ export declare class LSN {
13
+ /**
14
+ * The zero or null LSN value. All other LSN values are greater than this.
15
+ */
16
+ static ZERO: string;
17
+ protected value: string;
18
+ private constructor();
19
+ /**
20
+ * Converts this LSN back into its raw 10-byte binary representation for use in SQL Server functions.
21
+ */
22
+ toBinary(): Buffer;
23
+ /**
24
+ * Converts a raw 10-byte binary LSN value into its string representation.
25
+ * An error is thrown if the binary value is not exactly 10 bytes.
26
+ * @param rawLSN
27
+ */
28
+ static fromBinary(rawLSN: Buffer): LSN;
29
+ /**
30
+ * Creates an LSN instance from the provided string representation. An error is thrown if the format is invalid.
31
+ * @param stringLSN
32
+ */
33
+ static fromString(stringLSN: string): LSN;
34
+ compare(other: LSN): -1 | 0 | 1;
35
+ valueOf(): string;
36
+ toString(): string;
37
+ }
@@ -0,0 +1,64 @@
1
+ import { ReplicationAssertionError } from '@powersync/service-errors';
2
+ /**
3
+ * Helper class for interpreting and manipulating SQL Server Log Sequence Numbers (LSNs).
4
+ * In SQL Server, an LSN is stored as a 10-byte binary value.
5
+ * But it is commonly represented in a human-readable format as three hexadecimal parts separated by colons:
6
+ * `00000000:00000000:0000`.
7
+ *
8
+ * The three parts represent different hierarchical levels of the transaction log:
9
+ * 1. The first part identifies the Virtual Log File (VLF).
10
+ * 2. The second part points to the log block within the VLF.
11
+ * 3. The third part specifies the exact log record within the log block.
12
+ */
13
+ export class LSN {
14
+ /**
15
+ * The zero or null LSN value. All other LSN values are greater than this.
16
+ */
17
+ static ZERO = '00000000:00000000:0000';
18
+ value;
19
+ constructor(lsn) {
20
+ this.value = lsn;
21
+ }
22
+ /**
23
+ * Converts this LSN back into its raw 10-byte binary representation for use in SQL Server functions.
24
+ */
25
+ toBinary() {
26
+ let sanitized = this.value.replace(/:/g, '');
27
+ return Buffer.from(sanitized, 'hex');
28
+ }
29
+ /**
30
+ * Converts a raw 10-byte binary LSN value into its string representation.
31
+ * An error is thrown if the binary value is not exactly 10 bytes.
32
+ * @param rawLSN
33
+ */
34
+ static fromBinary(rawLSN) {
35
+ if (rawLSN.length !== 10) {
36
+ throw new ReplicationAssertionError(`LSN must be 10 bytes, got ${rawLSN.length}`);
37
+ }
38
+ const hex = rawLSN.toString('hex').toUpperCase(); // 20 hex chars
39
+ return new LSN(`${hex.slice(0, 8)}:${hex.slice(8, 16)}:${hex.slice(16, 20)}`);
40
+ }
41
+ /**
42
+ * Creates an LSN instance from the provided string representation. An error is thrown if the format is invalid.
43
+ * @param stringLSN
44
+ */
45
+ static fromString(stringLSN) {
46
+ if (!/^[0-9A-Fa-f]{8}:[0-9A-Fa-f]{8}:[0-9A-Fa-f]{4}$/.test(stringLSN)) {
47
+ throw new ReplicationAssertionError(`Invalid LSN string. Expected format is [00000000:00000000:0000]. Got: ${stringLSN}`);
48
+ }
49
+ return new LSN(stringLSN);
50
+ }
51
+ compare(other) {
52
+ if (this.value === other.value) {
53
+ return 0;
54
+ }
55
+ return this.value < other.value ? -1 : 1;
56
+ }
57
+ valueOf() {
58
+ return this.value;
59
+ }
60
+ toString() {
61
+ return this.value;
62
+ }
63
+ }
64
+ //# sourceMappingURL=LSN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LSN.js","sourceRoot":"","sources":["../../src/common/LSN.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,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C,KAAK,EAAE,CAAC;YAC/B,OAAO,CAAC,CAAC;QACX,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { SourceTable } from '@powersync/service-core';
2
+ export interface CaptureInstance {
3
+ name: string;
4
+ schema: string;
5
+ }
6
+ export interface MSSQLSourceTableOptions {
7
+ sourceTable: SourceTable;
8
+ /**
9
+ * The unique name of the CDC capture instance for this table
10
+ */
11
+ captureInstance: CaptureInstance;
12
+ }
13
+ export declare class MSSQLSourceTable {
14
+ private options;
15
+ constructor(options: MSSQLSourceTableOptions);
16
+ get sourceTable(): SourceTable;
17
+ updateSourceTable(updated: SourceTable): void;
18
+ get captureInstance(): string;
19
+ get cdcSchema(): string;
20
+ get CTTable(): string;
21
+ get allChangesFunction(): string;
22
+ get netChangesFunction(): string;
23
+ /**
24
+ * Escapes this source table's name and schema for use in MSSQL queries.
25
+ */
26
+ toQualifiedName(): string;
27
+ }
@@ -0,0 +1,35 @@
1
+ import { toQualifiedTableName } from '../utils/mssql.js';
2
+ export class MSSQLSourceTable {
3
+ options;
4
+ constructor(options) {
5
+ this.options = options;
6
+ }
7
+ get sourceTable() {
8
+ return this.options.sourceTable;
9
+ }
10
+ updateSourceTable(updated) {
11
+ this.options.sourceTable = updated;
12
+ }
13
+ get captureInstance() {
14
+ return this.options.captureInstance.name;
15
+ }
16
+ get cdcSchema() {
17
+ return this.options.captureInstance.schema;
18
+ }
19
+ get CTTable() {
20
+ return `${this.cdcSchema}.${this.captureInstance}_CT`;
21
+ }
22
+ get allChangesFunction() {
23
+ return `${this.cdcSchema}.fn_cdc_get_all_changes_${this.captureInstance}`;
24
+ }
25
+ get netChangesFunction() {
26
+ return `${this.cdcSchema}.fn_cdc_get_net_changes_${this.captureInstance}`;
27
+ }
28
+ /**
29
+ * Escapes this source table's name and schema for use in MSSQL queries.
30
+ */
31
+ toQualifiedName() {
32
+ return toQualifiedTableName(this.sourceTable.schema, this.sourceTable.name);
33
+ }
34
+ }
35
+ //# sourceMappingURL=MSSQLSourceTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MSSQLSourceTable.js","sourceRoot":"","sources":["../../src/common/MSSQLSourceTable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAezD,MAAM,OAAO,gBAAgB;IACP;IAApB,YAAoB,OAAgC;QAAhC,YAAO,GAAP,OAAO,CAAyB;IAAG,CAAC;IAExD,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;IAClC,CAAC;IAED,iBAAiB,CAAC,OAAoB;QACpC,IAAI,CAAC,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC;IACrC,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC;IAC3C,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,eAAe,KAAK,CAAC;IACxD,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,GAAG,IAAI,CAAC,SAAS,2BAA2B,IAAI,CAAC,eAAe,EAAE,CAAC;IAC5E,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,GAAG,IAAI,CAAC,SAAS,2BAA2B,IAAI,CAAC,eAAe,EAAE,CAAC;IAC5E,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC9E,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import { SourceTable } from '@powersync/service-core';
2
+ import { MSSQLSourceTable } from './MSSQLSourceTable.js';
3
+ export declare class MSSQLSourceTableCache {
4
+ private cache;
5
+ set(table: MSSQLSourceTable): void;
6
+ /**
7
+ * Updates the underlying source table of the cached MSSQLSourceTable.
8
+ * @param updatedTable
9
+ */
10
+ updateSourceTable(updatedTable: SourceTable): void;
11
+ get(tableId: number): MSSQLSourceTable | undefined;
12
+ getAll(): MSSQLSourceTable[];
13
+ delete(tableId: number): boolean;
14
+ }
@@ -0,0 +1,28 @@
1
+ import { ServiceAssertionError } from '@powersync/service-errors';
2
+ export class MSSQLSourceTableCache {
3
+ cache = new Map();
4
+ set(table) {
5
+ this.cache.set(table.sourceTable.objectId, table);
6
+ }
7
+ /**
8
+ * Updates the underlying source table of the cached MSSQLSourceTable.
9
+ * @param updatedTable
10
+ */
11
+ updateSourceTable(updatedTable) {
12
+ const existingTable = this.cache.get(updatedTable.objectId);
13
+ if (!existingTable) {
14
+ throw new ServiceAssertionError('Tried to update a non-existing MSSQLSourceTable in the cache');
15
+ }
16
+ existingTable.updateSourceTable(updatedTable);
17
+ }
18
+ get(tableId) {
19
+ return this.cache.get(tableId);
20
+ }
21
+ getAll() {
22
+ return Array.from(this.cache.values());
23
+ }
24
+ delete(tableId) {
25
+ return this.cache.delete(tableId);
26
+ }
27
+ }
28
+ //# sourceMappingURL=MSSQLSourceTableCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MSSQLSourceTableCache.js","sourceRoot":"","sources":["../../src/common/MSSQLSourceTableCache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,MAAM,OAAO,qBAAqB;IACxB,KAAK,GAAG,IAAI,GAAG,EAAqC,CAAC;IAE7D,GAAG,CAAC,KAAuB;QACzB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,QAAS,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IAED;;;OAGG;IACH,iBAAiB,CAAC,YAAyB;QACzC,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,QAAS,CAAC,CAAC;QAE7D,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,qBAAqB,CAAC,8DAA8D,CAAC,CAAC;QAClG,CAAC;QACD,aAAa,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;IAED,GAAG,CAAC,OAAe;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,OAAe;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;CACF"}