@powersync/service-module-mssql 0.9.0 → 0.10.1

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 (53) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/dist/api/MSSQLRouteAPIAdapter.js +26 -34
  3. package/dist/api/MSSQLRouteAPIAdapter.js.map +1 -1
  4. package/dist/common/MSSQLSourceTable.d.ts +12 -2
  5. package/dist/common/MSSQLSourceTable.js +30 -4
  6. package/dist/common/MSSQLSourceTable.js.map +1 -1
  7. package/dist/replication/CDCPoller.d.ts +13 -36
  8. package/dist/replication/CDCPoller.js +173 -129
  9. package/dist/replication/CDCPoller.js.map +1 -1
  10. package/dist/replication/CDCStream.d.ts +11 -14
  11. package/dist/replication/CDCStream.js +115 -106
  12. package/dist/replication/CDCStream.js.map +1 -1
  13. package/dist/replication/CaptureReconciler.d.ts +47 -0
  14. package/dist/replication/CaptureReconciler.js +155 -0
  15. package/dist/replication/CaptureReconciler.js.map +1 -0
  16. package/dist/replication/MSSQLConnectionManager.d.ts +1 -0
  17. package/dist/replication/MSSQLConnectionManager.js +19 -14
  18. package/dist/replication/MSSQLConnectionManager.js.map +1 -1
  19. package/dist/replication/MSSQLTableReconciliationContext.d.ts +21 -0
  20. package/dist/replication/MSSQLTableReconciliationContext.js +7 -0
  21. package/dist/replication/MSSQLTableReconciliationContext.js.map +1 -0
  22. package/dist/replication/SchemaChange.d.ts +67 -0
  23. package/dist/replication/SchemaChange.js +31 -0
  24. package/dist/replication/SchemaChange.js.map +1 -0
  25. package/dist/types/types.d.ts +8 -0
  26. package/dist/types/types.js +10 -1
  27. package/dist/types/types.js.map +1 -1
  28. package/dist/utils/mssql.js +1 -1
  29. package/dist/utils/schema.d.ts +14 -1
  30. package/dist/utils/schema.js +40 -45
  31. package/dist/utils/schema.js.map +1 -1
  32. package/package.json +8 -8
  33. package/src/api/MSSQLRouteAPIAdapter.ts +27 -33
  34. package/src/common/MSSQLSourceTable.ts +32 -4
  35. package/src/replication/CDCPoller.ts +206 -162
  36. package/src/replication/CDCStream.ts +148 -154
  37. package/src/replication/CaptureReconciler.ts +186 -0
  38. package/src/replication/MSSQLConnectionManager.ts +23 -14
  39. package/src/replication/MSSQLTableReconciliationContext.ts +29 -0
  40. package/src/replication/SchemaChange.ts +79 -0
  41. package/src/types/types.ts +22 -1
  42. package/src/utils/mssql.ts +1 -1
  43. package/src/utils/schema.ts +57 -58
  44. package/test/src/CDCPoller.test.ts +382 -0
  45. package/test/src/CDCStream.test.ts +6 -2
  46. package/test/src/CDCStreamTestContext.ts +7 -0
  47. package/test/src/CaptureReconciler.test.ts +171 -0
  48. package/test/src/MSSQLSourceTable.test.ts +30 -0
  49. package/test/src/config.test.ts +37 -0
  50. package/test/src/schema-changes.test.ts +513 -249
  51. package/test/src/schema.test.ts +17 -0
  52. package/test/src/util.ts +70 -6
  53. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,118 @@
1
1
  # @powersync/service-module-mssql
2
2
 
3
+ ## 0.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 4e4063b: Optimize runtime type checks, closes https://github.com/powersync-ja/powersync-service/issues/771.
8
+ - 2407f71: Apply timeouts and abortSignal handling to all S3 operations. The broad timeouts can be configured using the new `storage.object_storage.defaults_mode` option, or the `AWS_DEFAULTS_MODE` environment variable. Upgrade S3 SDK to fix further timeout issues.
9
+ - Updated dependencies [e11c54b]
10
+ - Updated dependencies [4b6a23e]
11
+ - Updated dependencies [189bd9e]
12
+ - Updated dependencies [bb08068]
13
+ - Updated dependencies [0077a8d]
14
+ - Updated dependencies [332d649]
15
+ - Updated dependencies [33a3c23]
16
+ - Updated dependencies [fccdff2]
17
+ - Updated dependencies [989d9e1]
18
+ - Updated dependencies [646c0de]
19
+ - Updated dependencies [cc121b3]
20
+ - Updated dependencies [4e4063b]
21
+ - Updated dependencies [2407f71]
22
+ - Updated dependencies [10131ca]
23
+ - Updated dependencies [4037e8f]
24
+ - Updated dependencies [3972bac]
25
+ - Updated dependencies [dd7a22f]
26
+ - Updated dependencies [a997c88]
27
+ - @powersync/service-core@1.26.0
28
+ - @powersync/service-sync-rules@0.41.0
29
+ - @powersync/service-types@0.18.0
30
+ - @powersync/lib-services-framework@0.10.1
31
+
32
+ ## 0.10.0
33
+
34
+ ### Minor Changes
35
+
36
+ - 3ca835d: Add custom CA certificate support for MSSQL connections.
37
+
38
+ The new `cacert` option allows PowerSync to validate SQL Server certificates issued by a private CA
39
+ without enabling `trustServerCertificate`. An optional `tls_servername` can be specified when the connection
40
+ hostname differs from the name in the server certificate.
41
+
42
+ - 798d739: Pin MSSQL source-table bindings to a specific CDC capture instance.
43
+
44
+ A source table now persists the object ID of the CDC change table it replicates from, and restores that
45
+ binding across restarts, so a stream always replicates the capture schema it started with. Existing
46
+ bindings without this metadata are backfilled at job startup with the same capture instance the previous
47
+ streaming logic would have selected.
48
+
49
+ SQL Server allows two capture instances per table. When a newer one appears, the current replication
50
+ process keeps polling the instance it is bound to and warns. Deploy a new sync config to use the newer
51
+ instance; the active sync config can continue serving clients through the old instance while the new sync
52
+ config snapshots and catches up. Keep the old instance available until the new sync config becomes active.
53
+
54
+ If CDC is disabled for a bound table, or its capture instance is removed while the source table and replica
55
+ identity remain unchanged, replication stops with `PSYNC_S1601`. A newly configured table that cannot be
56
+ replicated yet — it does not exist, or CDC has not been enabled for it — stops replication with
57
+ `PSYNC_S1602` rather than being skipped. Dropping, recreating, or otherwise changing the source identity of
58
+ a previously bound table stops replication with `PSYNC_S1603`.
59
+
60
+ - 798d739: [Breaking Change]
61
+
62
+ Pin the replicated schema at the start of replication for SQL Server connections.
63
+
64
+ SQL Server does not deliver schema changes in the replication stream, so they can only be found by
65
+ polling, and a poll is never atomic with a commit. That leaves a gap where checkpoints are committed
66
+ against a schema that has already changed — producing a state the source database was never in, which
67
+ clients cannot detect. PowerSync therefore no longer adopts schema changes automatically.
68
+
69
+ The recommended schema-change workflow treats a sync config deployment as the consistency boundary. A
70
+ replication stream keeps the exact table set and CDC capture-instance identities it selected when it
71
+ started; it does not adopt schema or table changes in place. Tables must therefore be listed explicitly
72
+ rather than selected with wildcards.
73
+
74
+ What this means when making schema changes:
75
+
76
+ - **Add a table:** create the table, enable CDC, add its exact qualified name to the sync config, and
77
+ deploy a new sync config. The new sync config snapshots the table before becoming active.
78
+ - **Change captured columns:** where SQL Server allows a rolling change, apply the DDL and create a second
79
+ capture instance with the desired captured columns. Update explicit sync queries if needed, deploy a
80
+ new sync config, wait for its snapshots to finish and for it to become active, and only then remove the
81
+ old capture instance.
82
+ - **Make an identity-breaking change:** for a primary-key change, identity-column rename, or another
83
+ change that requires CDC to be disabled, disable CDC, apply the DDL, re-enable CDC, update the sync
84
+ config if needed, and deploy a new sync config. The current replication process cannot adopt the
85
+ replacement in place, so this results in downtime. If it observes CDC being disabled first, it stops
86
+ with `PSYNC_S1601` because its capture instance was removed. If it next reconciles after the replica
87
+ identity has changed, it stops with `PSYNC_S1603` instead. Disabling and re-enabling CDC without changing
88
+ the replica identity stops with `PSYNC_S1601`.
89
+ - **Drop a table:** remove it from the sync config, deploy a new sync config and wait for it to become
90
+ active, and only then drop the source table. Dropping the table first stops replication with
91
+ `PSYNC_S1603`; already-replicated data is retained until the new sync config becomes active.
92
+ - **Rename or drop/recreate a table:** update the sync config to express the intended table explicitly,
93
+ ensure the resulting table is CDC-enabled with the expected schema and replica identity, and deploy a
94
+ new sync config. The current replication process stops with `PSYNC_S1603` if its bound table is removed.
95
+ - **No deployment is needed** for changes that do not affect the captured row shape or replica identity,
96
+ such as many index, constraint, or default changes. A non-identity column change also needs no PowerSync
97
+ action if that changed column does not need to be replicated; otherwise use the rolling capture-instance
98
+ workflow above.
99
+
100
+ This sequencing keeps the old table or capture instance available while the new sync config snapshots and
101
+ becomes active whenever a rolling transition is possible. If a pinned capture instance or bound table is
102
+ removed first, the current replication process stops and a new sync config must be deployed.
103
+
104
+ - 9d0b129: MSSQL CDCPoller improvements and fixes:
105
+
106
+ - Ensure correct ordering of CDC results which previously could cause inconsistencies when handling deferred updates
107
+ - Correctly count processed transactions in each polling cycle
108
+ - CDC polling query now streams results
109
+
110
+ ### Patch Changes
111
+
112
+ - Updated dependencies [27b56cb]
113
+ - Updated dependencies [798d739]
114
+ - @powersync/service-core@1.25.0
115
+
3
116
  ## 0.9.0
4
117
 
5
118
  ### Minor Changes
@@ -4,7 +4,7 @@ import { toExpressionTypeFromMSSQLType } from '../common/mssqls-to-sqlite.js';
4
4
  import { MSSQLConnectionManager } from '../replication/MSSQLConnectionManager.js';
5
5
  import * as types from '../types/types.js';
6
6
  import { checkSourceConfiguration, createCheckpoint, getDebugTableInfo, getLatestLSN, POWERSYNC_CHECKPOINTS_TABLE } from '../utils/mssql.js';
7
- import { getTablesFromPattern } from '../utils/schema.js';
7
+ import { getTablesFromPattern, unsupportedTablePatternMessage } from '../utils/schema.js';
8
8
  export class MSSQLRouteAPIAdapter {
9
9
  config;
10
10
  connectionManager;
@@ -154,43 +154,35 @@ export class MSSQLRouteAPIAdapter {
154
154
  wildcard: tablePattern.isWildcard
155
155
  };
156
156
  result.push(patternResult);
157
- const tables = await getTablesFromPattern(this.connectionManager, tablePattern);
158
- if (tablePattern.isWildcard) {
159
- patternResult.tables = [];
160
- for (const table of tables) {
161
- const details = await getDebugTableInfo({
162
- connectionManager: this.connectionManager,
163
- tablePattern,
164
- table,
165
- syncRules: sqlSyncRules
166
- });
167
- patternResult.tables.push(details);
168
- }
169
- }
170
- else {
171
- if (tables.length == 0) {
172
- // This should technically never happen, but we'll handle it anyway.
173
- const resolvedTable = {
174
- objectId: 0,
175
- schema: schema,
176
- name: tablePattern.name
177
- };
178
- patternResult.table = await getDebugTableInfo({
179
- connectionManager: this.connectionManager,
180
- tablePattern,
181
- table: resolvedTable,
182
- syncRules: sqlSyncRules
183
- });
157
+ // Unsupported patterns are reported per pattern here, rather than failing the whole request.
158
+ const unsupported = unsupportedTablePatternMessage(tablePattern);
159
+ if (unsupported != null) {
160
+ const unsupportedTable = {
161
+ schema,
162
+ name: tablePattern.tablePattern,
163
+ pattern: tablePattern.tablePattern,
164
+ replication_id: [],
165
+ data_queries: false,
166
+ parameter_queries: false,
167
+ errors: [{ level: 'fatal', message: unsupported }]
168
+ };
169
+ if (patternResult.wildcard) {
170
+ patternResult.tables = [unsupportedTable];
184
171
  }
185
172
  else {
186
- patternResult.table = await getDebugTableInfo({
187
- connectionManager: this.connectionManager,
188
- tablePattern,
189
- table: tables[0],
190
- syncRules: sqlSyncRules
191
- });
173
+ patternResult.table = unsupportedTable;
192
174
  }
175
+ continue;
193
176
  }
177
+ const tables = await getTablesFromPattern(this.connectionManager, tablePattern);
178
+ // A missing table is still reported, so that its errors are surfaced.
179
+ const resolvedTable = tables[0] ?? { objectId: 0, schema: schema, name: tablePattern.name };
180
+ patternResult.table = await getDebugTableInfo({
181
+ connectionManager: this.connectionManager,
182
+ tablePattern,
183
+ table: resolvedTable,
184
+ syncRules: sqlSyncRules
185
+ });
194
186
  }
195
187
  return result;
196
188
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MSSQLRouteAPIAdapter.js","sourceRoot":"","sources":["../../src/api/MSSQLRouteAPIAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAC;AAC1D,OAAO,GAAG,MAAM,OAAO,CAAC;AACxB,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,2BAA2B,EAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAiB,MAAM,oBAAoB,CAAC;AAEzE,MAAM,OAAO,oBAAoB;IAGT;IAFZ,iBAAiB,CAAyB;IAEpD,YAA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AE,MAAM,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,CAAC;YAC3G,aAAa,CAAC,KAAK,GAAG,MAAM,iBAAiB,CAAC;gBAC5C,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;gBACzC,YAAY;gBACZ,KAAK,EAAE,aAAa;gBACpB,SAAS,EAAE,YAAY;aACxB,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,wBAAwB;QACtB,OAAO;YACL,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM;SAC7C,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,sBAAsB,CAAC,OAA8B;QACzD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC;IACrC,CAAC;CACF"}
@@ -19,12 +19,22 @@ export declare class MSSQLSourceTable {
19
19
  */
20
20
  readonly sourceTables: SourceTable[];
21
21
  readonly ref: SourceEntityDescriptor;
22
+ /**
23
+ * Decoded once, since the persisted metadata only changes when a SourceTable is replaced.
24
+ */
25
+ private captureObjectId;
22
26
  constructor(ref: SourceEntityDescriptor, sourceTables: SourceTable[]);
23
27
  updateSourceTable(updated: SourceTable): void;
24
28
  getReplicatedSourceTables(): SourceTable[];
25
29
  enabledForCDC(): boolean;
26
- setCaptureInstance(captureInstance: CaptureInstance): void;
27
- clearCaptureInstance(): void;
30
+ /**
31
+ * Persisted capture-table object id, or null for a legacy binding.
32
+ */
33
+ get pinnedCaptureObjectId(): number | null;
34
+ /**
35
+ * Bind the available capture instance matching this table's persisted identity.
36
+ */
37
+ setCaptureInstance(availableInstances: readonly CaptureInstance[]): void;
28
38
  get allChangesFunction(): string;
29
39
  get netChangesFunction(): string;
30
40
  /**
@@ -1,4 +1,5 @@
1
1
  import { ServiceAssertionError } from '@powersync/service-errors';
2
+ import { readCaptureMetadata } from '../replication/CaptureReconciler.js';
2
3
  import { toQualifiedTableName } from '../utils/mssql.js';
3
4
  /**
4
5
  * The cdc schema in SQL Server is reserved and created when enabling CDC on a database.
@@ -19,9 +20,14 @@ export class MSSQLSourceTable {
19
20
  */
20
21
  sourceTables;
21
22
  ref;
23
+ /**
24
+ * Decoded once, since the persisted metadata only changes when a SourceTable is replaced.
25
+ */
26
+ captureObjectId;
22
27
  constructor(ref, sourceTables) {
23
28
  this.sourceTables = sourceTables;
24
29
  this.ref = ref;
30
+ this.captureObjectId = readPinnedCaptureObjectId(sourceTables);
25
31
  }
26
32
  updateSourceTable(updated) {
27
33
  const index = this.sourceTables.findIndex((table) => table.id == updated.id);
@@ -29,6 +35,7 @@ export class MSSQLSourceTable {
29
35
  throw new ServiceAssertionError(`No SourceTable found for table: ${updated.id}`);
30
36
  }
31
37
  this.sourceTables[index] = updated;
38
+ this.captureObjectId = readPinnedCaptureObjectId(this.sourceTables);
32
39
  }
33
40
  getReplicatedSourceTables() {
34
41
  return this.sourceTables.filter((sourceTable) => sourceTable.syncAny);
@@ -36,11 +43,18 @@ export class MSSQLSourceTable {
36
43
  enabledForCDC() {
37
44
  return this.captureInstance !== null;
38
45
  }
39
- setCaptureInstance(captureInstance) {
40
- this.captureInstance = captureInstance;
46
+ /**
47
+ * Persisted capture-table object id, or null for a legacy binding.
48
+ */
49
+ get pinnedCaptureObjectId() {
50
+ return this.captureObjectId;
41
51
  }
42
- clearCaptureInstance() {
43
- this.captureInstance = null;
52
+ /**
53
+ * Bind the available capture instance matching this table's persisted identity.
54
+ */
55
+ setCaptureInstance(availableInstances) {
56
+ this.captureInstance =
57
+ availableInstances.find((instance) => instance.objectId === this.pinnedCaptureObjectId) ?? null;
44
58
  }
45
59
  get allChangesFunction() {
46
60
  if (!this.captureInstance) {
@@ -68,4 +82,16 @@ export class MSSQLSourceTable {
68
82
  return toQualifiedTableName(this.ref.schema, this.ref.name);
69
83
  }
70
84
  }
85
+ /**
86
+ * The pinned capture-table object id shared by these records, or null for a legacy binding.
87
+ */
88
+ function readPinnedCaptureObjectId(sourceTables) {
89
+ for (const sourceTable of sourceTables) {
90
+ const metadata = readCaptureMetadata(sourceTable.sourceMetadata);
91
+ if (metadata != null) {
92
+ return metadata.captureTableObjectId;
93
+ }
94
+ }
95
+ return null;
96
+ }
71
97
  //# sourceMappingURL=MSSQLSourceTable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MSSQLSourceTable.js","sourceRoot":"","sources":["../../src/common/MSSQLSourceTable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGzD;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC;AAEhC;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAC3B;;OAEG;IACI,eAAe,GAA2B,IAAI,CAAC;IAEtD;;OAEG;IACa,YAAY,CAAgB;IAE5B,GAAG,CAAyB;IAE5C,YAAY,GAA2B,EAAE,YAA2B;QAClE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,iBAAiB,CAAC,OAAoB;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,OAAO,CAAC,EAAE,CAAC,CAAC;QAC7E,IAAI,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC;YAChB,MAAM,IAAI,qBAAqB,CAAC,mCAAmC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;QACnF,CAAC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CAAC,CAAC;QACjE,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,OAAO,QAAQ,CAAC,oBAAoB,CAAC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,32 +1,11 @@
1
1
  import { Logger } from '@powersync/lib-services-framework';
2
- import { TablePattern } from '@powersync/service-sync-rules';
3
2
  import sql from 'mssql';
4
- import { CaptureInstance } from '../common/CaptureInstance.js';
5
3
  import { LSN } from '../common/LSN.js';
6
4
  import { MSSQLSourceTable } from '../common/MSSQLSourceTable.js';
7
5
  import { AdditionalConfig } from '../types/types.js';
8
- import { SourceTableChangeRef } from '../utils/schema.js';
9
6
  import { MSSQLConnectionManager } from './MSSQLConnectionManager.js';
10
- export declare enum SchemaChangeType {
11
- TABLE_RENAME = "table_rename",
12
- TABLE_DROP = "table_drop",
13
- TABLE_CREATE = "table_create",
14
- TABLE_COLUMN_CHANGES = "table_column_changes",
15
- NEW_CAPTURE_INSTANCE = "new_capture_instance",
16
- MISSING_CAPTURE_INSTANCE = "missing_capture_instance"
17
- }
18
- export interface SchemaChange {
19
- type: SchemaChangeType;
20
- /**
21
- * The table that the schema change applies to. Populated for table drops, renames, new capture instances, and DDL changes.
22
- */
23
- table?: MSSQLSourceTable;
24
- /**
25
- * Populated for new tables or renames, but only if the new table matches a sync config source table.
26
- */
27
- newTable?: SourceTableChangeRef;
28
- newCaptureInstance?: CaptureInstance;
29
- }
7
+ import { SchemaChange } from './SchemaChange.js';
8
+ export declare const DEFAULT_SCHEMA_CHECK_INTERVAL_MS = 60000;
30
9
  export interface CDCEventHandler {
31
10
  onInsert: (row: any, table: MSSQLSourceTable, columns: sql.IColumnMetadata) => Promise<void>;
32
11
  onUpdate: (rowAfter: any, rowBefore: any, table: MSSQLSourceTable, columns: sql.IColumnMetadata) => Promise<void>;
@@ -34,16 +13,11 @@ export interface CDCEventHandler {
34
13
  onCommit: (lsn: string, transactionCount: number) => Promise<void>;
35
14
  onSchemaChange: (change: SchemaChange) => Promise<void>;
36
15
  }
37
- export declare const DEFAULT_SCHEMA_CHECK_INTERVAL_MS = 60000;
38
16
  export interface CDCPollerOptions {
39
17
  connectionManager: MSSQLConnectionManager;
40
18
  eventHandler: CDCEventHandler;
41
19
  /** CDC enabled source tables from the sync config to replicate */
42
20
  getReplicatedTables: () => MSSQLSourceTable[];
43
- /** All table patterns from the sync config. Can contain tables that need to be replicated
44
- * but do not yet have CDC enabled
45
- */
46
- sourceTables: TablePattern[];
47
21
  startLSN: LSN;
48
22
  logger?: Logger;
49
23
  additionalConfig: AdditionalConfig;
@@ -55,16 +29,20 @@ export interface CDCPollerOptions {
55
29
  schemaCheckIntervalMs?: number;
56
30
  }
57
31
  /**
32
+ * Polls SQL Server CDC change tables for changes at a configurable interval.
58
33
  *
34
+ * Processes changes in commit order, groups CDC rows into logical insert,
35
+ * update, and delete operations. It only commits once all the operations recorded in a polling cycle have been processed.
36
+ * Periodically runs checks to detect schema and capture-instance changes.
59
37
  */
60
38
  export declare class CDCPoller {
61
- options: CDCPollerOptions;
39
+ private options;
62
40
  private connectionManager;
63
41
  private eventHandler;
64
42
  private currentLSN;
65
43
  private logger;
66
- private listenerError;
67
44
  private captureInstances;
45
+ private pollingError;
68
46
  private isStopped;
69
47
  private isStopping;
70
48
  private isPolling;
@@ -77,13 +55,12 @@ export declare class CDCPoller {
77
55
  stop(): Promise<void>;
78
56
  replicateUntilStopped(): Promise<void>;
79
57
  private poll;
80
- private pollTable;
81
- private shouldCheckSchema;
82
58
  /**
83
- * Checks the given table for pending schema changes that can lead to inconsistencies in the replicated data if not handled.
84
- * Returns the SchemaChange if any are found, null otherwise.
59
+ * Processes the changes this table has within the given bounds, and returns the LSNs of the
60
+ * transactions those changes belong to. The LSNs are returned in their string form so that the
61
+ * caller can deduplicate them across tables by value.
85
62
  */
63
+ private pollTable;
64
+ private shouldCheckSchema;
86
65
  private checkForSchemaChanges;
87
- private checkForNewTables;
88
- private tableMatchesSyncRules;
89
66
  }