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

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 (33) hide show
  1. package/CHANGELOG.md +6 -6
  2. package/dist/module/MSSQLModule.js +1 -1
  3. package/dist/module/MSSQLModule.js.map +1 -1
  4. package/dist/replication/CDCPoller.d.ts +2 -2
  5. package/dist/replication/CDCPoller.js +2 -2
  6. package/dist/replication/CDCPoller.js.map +1 -1
  7. package/dist/replication/CDCReplicationJob.d.ts +2 -2
  8. package/dist/replication/CDCReplicationJob.js +1 -1
  9. package/dist/replication/CDCReplicationJob.js.map +1 -1
  10. package/dist/replication/CDCReplicator.d.ts +2 -2
  11. package/dist/replication/CDCReplicator.js +1 -1
  12. package/dist/replication/CDCReplicator.js.map +1 -1
  13. package/dist/replication/CDCStream.d.ts +2 -2
  14. package/dist/replication/CDCStream.js +2 -2
  15. package/dist/replication/CDCStream.js.map +1 -1
  16. package/dist/replication/MSSQLConnectionManager.js +1 -1
  17. package/dist/replication/MSSQLConnectionManager.js.map +1 -1
  18. package/dist/types/types.d.ts +80 -23
  19. package/dist/types/types.js +24 -24
  20. package/dist/types/types.js.map +1 -1
  21. package/package.json +9 -9
  22. package/src/module/MSSQLModule.ts +1 -1
  23. package/src/replication/CDCPoller.ts +4 -4
  24. package/src/replication/CDCReplicationJob.ts +3 -3
  25. package/src/replication/CDCReplicator.ts +3 -3
  26. package/src/replication/CDCStream.ts +4 -4
  27. package/src/replication/MSSQLConnectionManager.ts +1 -1
  28. package/src/types/types.ts +41 -45
  29. package/test/src/CDCStream.test.ts +1 -7
  30. package/test/src/CDCStreamTestContext.ts +5 -5
  31. package/test/src/CDCStream_resumable_snapshot.test.ts +1 -2
  32. package/test/src/util.ts +5 -1
  33. package/tsconfig.tsbuildinfo +1 -1
@@ -5,7 +5,7 @@ import { MSSQLSourceTable } from '../common/MSSQLSourceTable.js';
5
5
  import { LSN } from '../common/LSN.js';
6
6
  import sql from 'mssql';
7
7
  import { getMinLSN, incrementLSN } from '../utils/mssql.js';
8
- import { CDCPollingOptions } from '../types/types.js';
8
+ import { AdditionalConfig } from '../types/types.js';
9
9
 
10
10
  enum Operation {
11
11
  DELETE = 1,
@@ -52,8 +52,8 @@ export interface CDCPollerOptions {
52
52
  eventHandler: CDCEventHandler;
53
53
  sourceTables: MSSQLSourceTable[];
54
54
  startLSN: LSN;
55
- pollingOptions: CDCPollingOptions;
56
55
  logger?: Logger;
56
+ additionalConfig: AdditionalConfig;
57
57
  }
58
58
 
59
59
  /**
@@ -79,11 +79,11 @@ export class CDCPoller {
79
79
  }
80
80
 
81
81
  private get pollingBatchSize(): number {
82
- return this.options.pollingOptions.batchSize;
82
+ return this.options.additionalConfig.pollingBatchSize;
83
83
  }
84
84
 
85
85
  private get pollingIntervalMs(): number {
86
- return this.options.pollingOptions.intervalMs;
86
+ return this.options.additionalConfig.pollingIntervalMs;
87
87
  }
88
88
 
89
89
  private get sourceTables(): MSSQLSourceTable[] {
@@ -2,11 +2,11 @@ import { replication } from '@powersync/service-core';
2
2
  import { MSSQLConnectionManagerFactory } from './MSSQLConnectionManagerFactory.js';
3
3
  import { container, logger as defaultLogger } from '@powersync/lib-services-framework';
4
4
  import { CDCDataExpiredError, CDCStream } from './CDCStream.js';
5
- import { CDCPollingOptions } from '../types/types.js';
5
+ import { AdditionalConfig } from '../types/types.js';
6
6
 
7
7
  export interface CDCReplicationJobOptions extends replication.AbstractReplicationJobOptions {
8
8
  connectionFactory: MSSQLConnectionManagerFactory;
9
- pollingOptions: CDCPollingOptions;
9
+ additionalConfig: AdditionalConfig;
10
10
  }
11
11
 
12
12
  export class CDCReplicationJob extends replication.AbstractReplicationJob {
@@ -72,7 +72,7 @@ export class CDCReplicationJob extends replication.AbstractReplicationJob {
72
72
  storage: this.options.storage,
73
73
  metrics: this.options.metrics,
74
74
  connections: connectionManager,
75
- pollingOptions: this.cdcReplicationJobOptions.pollingOptions
75
+ additionalConfig: this.cdcReplicationJobOptions.additionalConfig
76
76
  });
77
77
  this.lastStream = stream;
78
78
  await stream.replicate();
@@ -2,11 +2,11 @@ import { replication, storage } from '@powersync/service-core';
2
2
  import { MSSQLConnectionManagerFactory } from './MSSQLConnectionManagerFactory.js';
3
3
  import { CDCReplicationJob } from './CDCReplicationJob.js';
4
4
  import { MSSQLModule } from '../module/MSSQLModule.js';
5
- import { CDCPollingOptions } from '../types/types.js';
5
+ import { AdditionalConfig } from '../types/types.js';
6
6
 
7
7
  export interface CDCReplicatorOptions extends replication.AbstractReplicatorOptions {
8
8
  connectionFactory: MSSQLConnectionManagerFactory;
9
- pollingOptions: CDCPollingOptions;
9
+ additionalConfig: AdditionalConfig;
10
10
  }
11
11
 
12
12
  export class CDCReplicator extends replication.AbstractReplicator<CDCReplicationJob> {
@@ -27,7 +27,7 @@ export class CDCReplicator extends replication.AbstractReplicator<CDCReplication
27
27
  lock: options.lock,
28
28
  connectionFactory: this.connectionFactory,
29
29
  rateLimiter: this.rateLimiter,
30
- pollingOptions: this.cdcReplicatorOptions.pollingOptions
30
+ additionalConfig: this.cdcReplicatorOptions.additionalConfig
31
31
  });
32
32
  }
33
33
 
@@ -39,7 +39,7 @@ import { LSN } from '../common/LSN.js';
39
39
  import { MSSQLSourceTable } from '../common/MSSQLSourceTable.js';
40
40
  import { MSSQLSourceTableCache } from '../common/MSSQLSourceTableCache.js';
41
41
  import { CDCEventHandler, CDCPoller } from './CDCPoller.js';
42
- import { CDCPollingOptions } from '../types/types.js';
42
+ import { AdditionalConfig } from '../types/types.js';
43
43
 
44
44
  export interface CDCStreamOptions {
45
45
  connections: MSSQLConnectionManager;
@@ -54,7 +54,7 @@ export interface CDCStreamOptions {
54
54
  */
55
55
  snapshotBatchSize?: number;
56
56
 
57
- pollingOptions: CDCPollingOptions;
57
+ additionalConfig: AdditionalConfig;
58
58
  }
59
59
 
60
60
  export enum SnapshotStatus {
@@ -589,8 +589,8 @@ export class CDCStream {
589
589
  eventHandler,
590
590
  sourceTables,
591
591
  startLSN,
592
- pollingOptions: this.options.pollingOptions,
593
- logger: this.logger
592
+ logger: this.logger,
593
+ additionalConfig: this.options.additionalConfig
594
594
  });
595
595
 
596
596
  this.abortSignal.addEventListener(
@@ -31,7 +31,7 @@ export class MSSQLConnectionManager extends BaseObserver<MSSQLConnectionManagerL
31
31
  options: {
32
32
  appName: `powersync/${POWERSYNC_VERSION}`,
33
33
  encrypt: true, // Required for Azure
34
- trustServerCertificate: options.trustServerCertificate
34
+ trustServerCertificate: options.additionalConfig.trustServerCertificate
35
35
  }
36
36
  });
37
37
  }
@@ -63,21 +63,42 @@ export const DefaultAuthentication = t.object({
63
63
  });
64
64
  export type DefaultAuthentication = t.Decoded<typeof DefaultAuthentication>;
65
65
 
66
- export type AuthenticationType =
67
- | DefaultAuthentication
68
- | AzureActiveDirectoryPasswordAuthentication
69
- | AzureActiveDirectoryServicePrincipalSecret;
66
+ export const Authentication = DefaultAuthentication.or(AzureActiveDirectoryPasswordAuthentication).or(
67
+ AzureActiveDirectoryServicePrincipalSecret
68
+ );
69
+ export type Authentication = t.Decoded<typeof Authentication>;
70
70
 
71
-
72
- export interface CDCPollingOptions {
71
+ export const AdditionalConfig = t.object({
72
+ /**
73
+ * Interval in milliseconds to wait between polling cycles. Defaults to 1000 milliseconds.
74
+ */
75
+ pollingIntervalMs: t.number.optional(),
73
76
  /**
74
77
  * Maximum number of transactions to poll per polling cycle. Defaults to 10.
75
78
  */
76
- batchSize: number;
79
+ pollingBatchSize: t.number.optional(),
80
+
77
81
  /**
78
- * Interval in milliseconds to wait between polling cycles. Defaults to 1 second.
82
+ * Whether to trust the server certificate. Set to true for local development and self-signed certificates.
83
+ * Default is false.
79
84
  */
80
- intervalMs: number;
85
+ trustServerCertificate: t.boolean.optional()
86
+ });
87
+
88
+ export interface AdditionalConfig {
89
+ /**
90
+ * Interval in milliseconds to wait between polling cycles. Defaults to 1000 milliseconds.
91
+ */
92
+ pollingIntervalMs: number;
93
+ /**
94
+ * Maximum number of transactions to poll per polling cycle. Defaults to 10.
95
+ */
96
+ pollingBatchSize: number;
97
+ /**
98
+ * Whether to trust the server certificate. Set to true for local development and self-signed certificates.
99
+ * Default is false.
100
+ */
101
+ trustServerCertificate: boolean;
81
102
  }
82
103
 
83
104
  export interface NormalizedMSSQLConnectionConfig {
@@ -91,16 +112,11 @@ export interface NormalizedMSSQLConnectionConfig {
91
112
  database: string;
92
113
  schema?: string;
93
114
 
94
- authentication?: AuthenticationType;
95
-
96
- cdcPollingOptions: CDCPollingOptions;
115
+ authentication?: Authentication;
97
116
 
98
- /**
99
- * Whether to trust the server certificate. Set to true for local development and self-signed certificates.
100
- * Default is false.
101
- */
102
- trustServerCertificate: boolean;
103
117
  lookup?: LookupFunction;
118
+
119
+ additionalConfig: AdditionalConfig;
104
120
  }
105
121
 
106
122
  export const MSSQLConnectionConfig = service_types.configFile.DataSourceConfig.and(
@@ -114,22 +130,10 @@ export const MSSQLConnectionConfig = service_types.configFile.DataSourceConfig.a
114
130
  hostname: t.string.optional(),
115
131
  port: service_types.configFile.portCodec.optional(),
116
132
 
117
- authentication: DefaultAuthentication.or(AzureActiveDirectoryPasswordAuthentication)
118
- .or(AzureActiveDirectoryServicePrincipalSecret)
119
- .optional(),
120
-
121
- cdcPollingOptions: t.object({
122
- batchSize: t.number.optional(),
123
- intervalMs: t.number.optional()
124
- }).optional(),
125
-
126
- /**
127
- * Whether to trust the server certificate. Set to true for local development and self-signed certificates.
128
- * Default is false.
129
- */
130
- trustServerCertificate: t.boolean.optional(),
133
+ authentication: Authentication.optional(),
131
134
 
132
- reject_ip_ranges: t.array(t.string).optional()
135
+ reject_ip_ranges: t.array(t.string).optional(),
136
+ additionalConfig: AdditionalConfig.optional()
133
137
  })
134
138
  );
135
139
 
@@ -203,19 +207,11 @@ export function normalizeConnectionConfig(options: MSSQLConnectionConfig): Norma
203
207
  lookup,
204
208
  authentication: options.authentication,
205
209
 
206
- cdcPollingOptions: {
207
- /**
208
- * Maximum number of transactions to poll per polling cycle. Defaults to 10.
209
- */
210
- batchSize: options.cdcPollingOptions?.batchSize ?? 10,
211
-
212
- /**
213
- * Interval in milliseconds to wait between polling cycles. Defaults to 1 second.
214
- */
215
- intervalMs: options.cdcPollingOptions?.intervalMs ?? 1000,
216
- },
217
-
218
- trustServerCertificate: options.trustServerCertificate ?? false,
210
+ additionalConfig: {
211
+ pollingIntervalMs: options.additionalConfig?.pollingIntervalMs ?? 1000,
212
+ pollingBatchSize: options.additionalConfig?.pollingBatchSize ?? 10,
213
+ trustServerCertificate: options.additionalConfig?.trustServerCertificate ?? false
214
+ }
219
215
  } satisfies NormalizedMSSQLConnectionConfig;
220
216
  }
221
217
 
@@ -1,13 +1,7 @@
1
1
  import { describe, expect, test } from 'vitest';
2
2
  import { METRICS_HELPER, putOp, removeOp } from '@powersync/service-core-tests';
3
3
  import { ReplicationMetric } from '@powersync/service-types';
4
- import {
5
- createTestTable,
6
- describeWithStorage,
7
- INITIALIZED_MONGO_STORAGE_FACTORY,
8
- insertTestData,
9
- waitForPendingCDCChanges
10
- } from './util.js';
4
+ import { createTestTable, describeWithStorage, insertTestData, waitForPendingCDCChanges } from './util.js';
11
5
  import { storage } from '@powersync/service-core';
12
6
  import { CDCStreamTestContext } from './CDCStreamTestContext.js';
13
7
  import { getLatestReplicatedLSN } from '@module/utils/mssql.js';
@@ -12,7 +12,6 @@ import { clearTestDb, getClientCheckpoint, TEST_CONNECTION_OPTIONS } from './uti
12
12
  import { CDCStream, CDCStreamOptions } from '@module/replication/CDCStream.js';
13
13
  import { MSSQLConnectionManager } from '@module/replication/MSSQLConnectionManager.js';
14
14
  import timers from 'timers/promises';
15
- import { CDCPollingOptions } from '@module/types/types.js';
16
15
 
17
16
  /**
18
17
  * Tests operating on the change data capture need to configure the stream and manage asynchronous
@@ -110,10 +109,11 @@ export class CDCStreamTestContext implements AsyncDisposable {
110
109
  metrics: METRICS_HELPER.metricsEngine,
111
110
  connections: this.connectionManager,
112
111
  abortSignal: this.abortController.signal,
113
- pollingOptions: {
114
- batchSize: 10,
115
- intervalMs: 1000
116
- } satisfies CDCPollingOptions,
112
+ additionalConfig: {
113
+ pollingBatchSize: 10,
114
+ pollingIntervalMs: 1000,
115
+ trustServerCertificate: true
116
+ },
117
117
  ...this.cdcStreamOptions
118
118
  };
119
119
  this._cdcStream = new CDCStream(options);
@@ -46,10 +46,9 @@ async function testResumingReplication(factory: TestStorageFactory, stopAfter: n
46
46
  await createTestTableWithBasicId(connectionManager, 'test_data1');
47
47
  await createTestTableWithBasicId(connectionManager, 'test_data2');
48
48
 
49
- let beforeLSN = await getLatestReplicatedLSN(connectionManager);
50
49
  await connectionManager.query(`INSERT INTO test_data1(description) SELECT 'value' FROM GENERATE_SERIES(1, 1000, 1)`);
50
+ let beforeLSN = await getLatestReplicatedLSN(connectionManager);
51
51
  await connectionManager.query(`INSERT INTO test_data2(description) SELECT 'value' FROM GENERATE_SERIES(1, 10000, 1)`);
52
-
53
52
  await waitForPendingCDCChanges(beforeLSN, connectionManager);
54
53
 
55
54
  const p = context.replicateSnapshot();
package/test/src/util.ts CHANGED
@@ -37,7 +37,11 @@ export function describeWithStorage(options: TestOptions, fn: (factory: TestStor
37
37
  export const TEST_CONNECTION_OPTIONS = types.normalizeConnectionConfig({
38
38
  type: 'mssql',
39
39
  uri: TEST_URI,
40
- trustServerCertificate: true
40
+ additionalConfig: {
41
+ pollingBatchSize: 10,
42
+ pollingIntervalMs: 1000,
43
+ trustServerCertificate: true
44
+ }
41
45
  });
42
46
 
43
47
  /**