@powersync/service-module-mssql 0.0.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 (92) hide show
  1. package/LICENSE +67 -0
  2. package/README.md +3 -0
  3. package/ci/init-mssql.sql +50 -0
  4. package/dist/api/MSSQLRouteAPIAdapter.d.ts +21 -0
  5. package/dist/api/MSSQLRouteAPIAdapter.js +248 -0
  6. package/dist/api/MSSQLRouteAPIAdapter.js.map +1 -0
  7. package/dist/common/LSN.d.ts +37 -0
  8. package/dist/common/LSN.js +64 -0
  9. package/dist/common/LSN.js.map +1 -0
  10. package/dist/common/MSSQLSourceTable.d.ts +27 -0
  11. package/dist/common/MSSQLSourceTable.js +35 -0
  12. package/dist/common/MSSQLSourceTable.js.map +1 -0
  13. package/dist/common/MSSQLSourceTableCache.d.ts +14 -0
  14. package/dist/common/MSSQLSourceTableCache.js +28 -0
  15. package/dist/common/MSSQLSourceTableCache.js.map +1 -0
  16. package/dist/common/mssqls-to-sqlite.d.ts +18 -0
  17. package/dist/common/mssqls-to-sqlite.js +143 -0
  18. package/dist/common/mssqls-to-sqlite.js.map +1 -0
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.js +2 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/module/MSSQLModule.d.ts +15 -0
  23. package/dist/module/MSSQLModule.js +68 -0
  24. package/dist/module/MSSQLModule.js.map +1 -0
  25. package/dist/replication/CDCPoller.d.ts +67 -0
  26. package/dist/replication/CDCPoller.js +183 -0
  27. package/dist/replication/CDCPoller.js.map +1 -0
  28. package/dist/replication/CDCReplicationJob.d.ts +17 -0
  29. package/dist/replication/CDCReplicationJob.js +76 -0
  30. package/dist/replication/CDCReplicationJob.js.map +1 -0
  31. package/dist/replication/CDCReplicator.d.ts +18 -0
  32. package/dist/replication/CDCReplicator.js +55 -0
  33. package/dist/replication/CDCReplicator.js.map +1 -0
  34. package/dist/replication/CDCStream.d.ts +106 -0
  35. package/dist/replication/CDCStream.js +536 -0
  36. package/dist/replication/CDCStream.js.map +1 -0
  37. package/dist/replication/MSSQLConnectionManager.d.ts +23 -0
  38. package/dist/replication/MSSQLConnectionManager.js +97 -0
  39. package/dist/replication/MSSQLConnectionManager.js.map +1 -0
  40. package/dist/replication/MSSQLConnectionManagerFactory.d.ts +10 -0
  41. package/dist/replication/MSSQLConnectionManagerFactory.js +28 -0
  42. package/dist/replication/MSSQLConnectionManagerFactory.js.map +1 -0
  43. package/dist/replication/MSSQLErrorRateLimiter.d.ts +10 -0
  44. package/dist/replication/MSSQLErrorRateLimiter.js +34 -0
  45. package/dist/replication/MSSQLErrorRateLimiter.js.map +1 -0
  46. package/dist/replication/MSSQLSnapshotQuery.d.ts +71 -0
  47. package/dist/replication/MSSQLSnapshotQuery.js +190 -0
  48. package/dist/replication/MSSQLSnapshotQuery.js.map +1 -0
  49. package/dist/types/mssql-data-types.d.ts +66 -0
  50. package/dist/types/mssql-data-types.js +62 -0
  51. package/dist/types/mssql-data-types.js.map +1 -0
  52. package/dist/types/types.d.ts +177 -0
  53. package/dist/types/types.js +141 -0
  54. package/dist/types/types.js.map +1 -0
  55. package/dist/utils/mssql.d.ts +80 -0
  56. package/dist/utils/mssql.js +329 -0
  57. package/dist/utils/mssql.js.map +1 -0
  58. package/dist/utils/schema.d.ts +21 -0
  59. package/dist/utils/schema.js +131 -0
  60. package/dist/utils/schema.js.map +1 -0
  61. package/package.json +51 -0
  62. package/src/api/MSSQLRouteAPIAdapter.ts +283 -0
  63. package/src/common/LSN.ts +77 -0
  64. package/src/common/MSSQLSourceTable.ts +54 -0
  65. package/src/common/MSSQLSourceTableCache.ts +36 -0
  66. package/src/common/mssqls-to-sqlite.ts +151 -0
  67. package/src/index.ts +1 -0
  68. package/src/module/MSSQLModule.ts +82 -0
  69. package/src/replication/CDCPoller.ts +241 -0
  70. package/src/replication/CDCReplicationJob.ts +87 -0
  71. package/src/replication/CDCReplicator.ts +70 -0
  72. package/src/replication/CDCStream.ts +688 -0
  73. package/src/replication/MSSQLConnectionManager.ts +113 -0
  74. package/src/replication/MSSQLConnectionManagerFactory.ts +33 -0
  75. package/src/replication/MSSQLErrorRateLimiter.ts +36 -0
  76. package/src/replication/MSSQLSnapshotQuery.ts +230 -0
  77. package/src/types/mssql-data-types.ts +79 -0
  78. package/src/types/types.ts +224 -0
  79. package/src/utils/mssql.ts +420 -0
  80. package/src/utils/schema.ts +172 -0
  81. package/test/src/CDCStream.test.ts +206 -0
  82. package/test/src/CDCStreamTestContext.ts +212 -0
  83. package/test/src/CDCStream_resumable_snapshot.test.ts +152 -0
  84. package/test/src/env.ts +11 -0
  85. package/test/src/mssql-to-sqlite.test.ts +474 -0
  86. package/test/src/setup.ts +12 -0
  87. package/test/src/util.ts +189 -0
  88. package/test/tsconfig.json +28 -0
  89. package/test/tsconfig.tsbuildinfo +1 -0
  90. package/tsconfig.json +26 -0
  91. package/tsconfig.tsbuildinfo +1 -0
  92. package/vitest.config.ts +15 -0
@@ -0,0 +1,177 @@
1
+ import { LookupFunction } from 'node:net';
2
+ import * as t from 'ts-codec';
3
+ export declare const MSSQL_CONNECTION_TYPE: "mssql";
4
+ export declare const AzureActiveDirectoryPasswordAuthentication: t.ObjectCodec<{
5
+ type: t.LiteralCodec<"azure-active-directory-password">;
6
+ options: t.ObjectCodec<{
7
+ /**
8
+ * A user need to provide `userName` associate to their account.
9
+ */
10
+ userName: t.IdentityCodec<t.CodecType.String>;
11
+ /**
12
+ * A user need to provide `password` associate to their account.
13
+ */
14
+ password: t.IdentityCodec<t.CodecType.String>;
15
+ /**
16
+ * A client id to use.
17
+ */
18
+ clientId: t.IdentityCodec<t.CodecType.String>;
19
+ /**
20
+ * Azure tenant ID
21
+ */
22
+ tenantId: t.IdentityCodec<t.CodecType.String>;
23
+ }>;
24
+ }>;
25
+ export type AzureActiveDirectoryPasswordAuthentication = t.Decoded<typeof AzureActiveDirectoryPasswordAuthentication>;
26
+ export declare const AzureActiveDirectoryServicePrincipalSecret: t.ObjectCodec<{
27
+ type: t.LiteralCodec<"azure-active-directory-service-principal-secret">;
28
+ options: t.ObjectCodec<{
29
+ /**
30
+ * Application (`client`) ID from your registered Azure application
31
+ */
32
+ clientId: t.IdentityCodec<t.CodecType.String>;
33
+ /**
34
+ * The created `client secret` for this registered Azure application
35
+ */
36
+ clientSecret: t.IdentityCodec<t.CodecType.String>;
37
+ /**
38
+ * Directory (`tenant`) ID from your registered Azure application
39
+ */
40
+ tenantId: t.IdentityCodec<t.CodecType.String>;
41
+ }>;
42
+ }>;
43
+ export type AzureActiveDirectoryServicePrincipalSecret = t.Decoded<typeof AzureActiveDirectoryServicePrincipalSecret>;
44
+ export declare const DefaultAuthentication: t.ObjectCodec<{
45
+ type: t.LiteralCodec<"default">;
46
+ options: t.ObjectCodec<{
47
+ /**
48
+ * User name to use for sql server login.
49
+ */
50
+ userName: t.IdentityCodec<t.CodecType.String>;
51
+ /**
52
+ * Password to use for sql server login.
53
+ */
54
+ password: t.IdentityCodec<t.CodecType.String>;
55
+ }>;
56
+ }>;
57
+ export type DefaultAuthentication = t.Decoded<typeof DefaultAuthentication>;
58
+ export type AuthenticationType = DefaultAuthentication | AzureActiveDirectoryPasswordAuthentication | AzureActiveDirectoryServicePrincipalSecret;
59
+ export interface CDCPollingOptions {
60
+ /**
61
+ * Maximum number of transactions to poll per polling cycle. Defaults to 10.
62
+ */
63
+ batchSize: number;
64
+ /**
65
+ * Interval in milliseconds to wait between polling cycles. Defaults to 1 second.
66
+ */
67
+ intervalMs: number;
68
+ }
69
+ export interface NormalizedMSSQLConnectionConfig {
70
+ id: string;
71
+ tag: string;
72
+ username?: string;
73
+ password?: string;
74
+ hostname: string;
75
+ port: number;
76
+ database: string;
77
+ schema?: string;
78
+ authentication?: AuthenticationType;
79
+ cdcPollingOptions: CDCPollingOptions;
80
+ /**
81
+ * Whether to trust the server certificate. Set to true for local development and self-signed certificates.
82
+ * Default is false.
83
+ */
84
+ trustServerCertificate: boolean;
85
+ lookup?: LookupFunction;
86
+ }
87
+ export declare const MSSQLConnectionConfig: t.Intersection<t.Codec<{
88
+ type: string;
89
+ id?: string | undefined;
90
+ tag?: string | undefined;
91
+ debug_api?: boolean | undefined;
92
+ }, {
93
+ type: string;
94
+ id?: string | undefined;
95
+ tag?: string | undefined;
96
+ debug_api?: boolean | undefined;
97
+ }, string, t.CodecProps>, t.ObjectCodec<{
98
+ type: t.LiteralCodec<"mssql">;
99
+ uri: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
100
+ username: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
101
+ password: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
102
+ database: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
103
+ schema: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
104
+ hostname: t.OptionalCodec<t.Codec<string, string, string, t.CodecProps>>;
105
+ port: t.OptionalCodec<t.Codec<number, string | number, string, t.CodecProps>>;
106
+ authentication: t.OptionalCodec<t.Codec<{
107
+ type: "azure-active-directory-password";
108
+ options: {
109
+ userName: string;
110
+ password: string;
111
+ clientId: string;
112
+ tenantId: string;
113
+ };
114
+ } | {
115
+ type: "azure-active-directory-service-principal-secret";
116
+ options: {
117
+ clientId: string;
118
+ tenantId: string;
119
+ clientSecret: string;
120
+ };
121
+ } | {
122
+ type: "default";
123
+ options: {
124
+ userName: string;
125
+ password: string;
126
+ };
127
+ }, {
128
+ type: "azure-active-directory-password";
129
+ options: {
130
+ userName: string;
131
+ password: string;
132
+ clientId: string;
133
+ tenantId: string;
134
+ };
135
+ } | {
136
+ type: "azure-active-directory-service-principal-secret";
137
+ options: {
138
+ clientId: string;
139
+ tenantId: string;
140
+ clientSecret: string;
141
+ };
142
+ } | {
143
+ type: "default";
144
+ options: {
145
+ userName: string;
146
+ password: string;
147
+ };
148
+ }, string, t.CodecProps>>;
149
+ cdcPollingOptions: t.OptionalCodec<t.Codec<{
150
+ batchSize?: number | undefined;
151
+ intervalMs?: number | undefined;
152
+ }, {
153
+ batchSize?: number | undefined;
154
+ intervalMs?: number | undefined;
155
+ }, string, t.CodecProps>>;
156
+ /**
157
+ * Whether to trust the server certificate. Set to true for local development and self-signed certificates.
158
+ * Default is false.
159
+ */
160
+ trustServerCertificate: t.OptionalCodec<t.Codec<boolean, boolean, string, t.CodecProps>>;
161
+ reject_ip_ranges: t.OptionalCodec<t.Codec<string[], string[], string, t.CodecProps>>;
162
+ }>>;
163
+ /**
164
+ * Config input specified when starting services
165
+ */
166
+ export type MSSQLConnectionConfig = t.Decoded<typeof MSSQLConnectionConfig>;
167
+ /**
168
+ * Resolved version of {@link MSSQLConnectionConfig}
169
+ */
170
+ export type ResolvedMSSQLConnectionConfig = MSSQLConnectionConfig & NormalizedMSSQLConnectionConfig;
171
+ /**
172
+ * Validate and normalize connection options.
173
+ *
174
+ * Returns destructured options.
175
+ */
176
+ export declare function normalizeConnectionConfig(options: MSSQLConnectionConfig): NormalizedMSSQLConnectionConfig;
177
+ export declare function baseUri(config: ResolvedMSSQLConnectionConfig): string;
@@ -0,0 +1,141 @@
1
+ import { ErrorCode, makeHostnameLookupFunction, ServiceError } from '@powersync/lib-services-framework';
2
+ import * as service_types from '@powersync/service-types';
3
+ import * as t from 'ts-codec';
4
+ import * as urijs from 'uri-js';
5
+ export const MSSQL_CONNECTION_TYPE = 'mssql';
6
+ export const AzureActiveDirectoryPasswordAuthentication = t.object({
7
+ type: t.literal('azure-active-directory-password'),
8
+ options: t.object({
9
+ /**
10
+ * A user need to provide `userName` associate to their account.
11
+ */
12
+ userName: t.string,
13
+ /**
14
+ * A user need to provide `password` associate to their account.
15
+ */
16
+ password: t.string,
17
+ /**
18
+ * A client id to use.
19
+ */
20
+ clientId: t.string,
21
+ /**
22
+ * Azure tenant ID
23
+ */
24
+ tenantId: t.string
25
+ })
26
+ });
27
+ export const AzureActiveDirectoryServicePrincipalSecret = t.object({
28
+ type: t.literal('azure-active-directory-service-principal-secret'),
29
+ options: t.object({
30
+ /**
31
+ * Application (`client`) ID from your registered Azure application
32
+ */
33
+ clientId: t.string,
34
+ /**
35
+ * The created `client secret` for this registered Azure application
36
+ */
37
+ clientSecret: t.string,
38
+ /**
39
+ * Directory (`tenant`) ID from your registered Azure application
40
+ */
41
+ tenantId: t.string
42
+ })
43
+ });
44
+ export const DefaultAuthentication = t.object({
45
+ type: t.literal('default'),
46
+ options: t.object({
47
+ /**
48
+ * User name to use for sql server login.
49
+ */
50
+ userName: t.string,
51
+ /**
52
+ * Password to use for sql server login.
53
+ */
54
+ password: t.string
55
+ })
56
+ });
57
+ export const MSSQLConnectionConfig = service_types.configFile.DataSourceConfig.and(t.object({
58
+ type: t.literal(MSSQL_CONNECTION_TYPE),
59
+ uri: t.string.optional(),
60
+ username: t.string.optional(),
61
+ password: t.string.optional(),
62
+ database: t.string.optional(),
63
+ schema: t.string.optional(),
64
+ hostname: t.string.optional(),
65
+ port: service_types.configFile.portCodec.optional(),
66
+ authentication: DefaultAuthentication.or(AzureActiveDirectoryPasswordAuthentication)
67
+ .or(AzureActiveDirectoryServicePrincipalSecret)
68
+ .optional(),
69
+ cdcPollingOptions: t.object({
70
+ batchSize: t.number.optional(),
71
+ intervalMs: t.number.optional()
72
+ }).optional(),
73
+ /**
74
+ * Whether to trust the server certificate. Set to true for local development and self-signed certificates.
75
+ * Default is false.
76
+ */
77
+ trustServerCertificate: t.boolean.optional(),
78
+ reject_ip_ranges: t.array(t.string).optional()
79
+ }));
80
+ /**
81
+ * Validate and normalize connection options.
82
+ *
83
+ * Returns destructured options.
84
+ */
85
+ export function normalizeConnectionConfig(options) {
86
+ let uri;
87
+ if (options.uri) {
88
+ uri = urijs.parse(options.uri);
89
+ if (uri.scheme != 'mssql') {
90
+ throw new ServiceError(ErrorCode.PSYNC_S1109, `Invalid URI - protocol must be mssql, got ${JSON.stringify(uri.scheme)}`);
91
+ }
92
+ }
93
+ else {
94
+ uri = urijs.parse('mssql:///');
95
+ }
96
+ const hostname = options.hostname ?? uri.host ?? '';
97
+ const port = Number(options.port ?? uri.port ?? 1433);
98
+ const database = options.database ?? uri.path?.substring(1) ?? '';
99
+ const [uri_username, uri_password] = (uri.userinfo ?? '').split(':');
100
+ const username = options.username ?? uri_username ?? '';
101
+ const password = options.password ?? uri_password ?? '';
102
+ if (hostname == '') {
103
+ throw new ServiceError(ErrorCode.PSYNC_S1106, `MSSQL connection: hostname required`);
104
+ }
105
+ if (username == '' && !options.authentication) {
106
+ throw new ServiceError(ErrorCode.PSYNC_S1107, `MSSQL connection: username or authentication config is required`);
107
+ }
108
+ if (password == '' && !options.authentication) {
109
+ throw new ServiceError(ErrorCode.PSYNC_S1108, `MSSQL connection: password or authentication config is required`);
110
+ }
111
+ if (database == '') {
112
+ throw new ServiceError(ErrorCode.PSYNC_S1105, `MSSQL connection: database required`);
113
+ }
114
+ const lookup = makeHostnameLookupFunction(hostname, { reject_ip_ranges: options.reject_ip_ranges ?? [] });
115
+ return {
116
+ id: options.id ?? 'default',
117
+ tag: options.tag ?? 'default',
118
+ username,
119
+ password,
120
+ hostname,
121
+ port,
122
+ database,
123
+ lookup,
124
+ authentication: options.authentication,
125
+ cdcPollingOptions: {
126
+ /**
127
+ * Maximum number of transactions to poll per polling cycle. Defaults to 10.
128
+ */
129
+ batchSize: options.cdcPollingOptions?.batchSize ?? 10,
130
+ /**
131
+ * Interval in milliseconds to wait between polling cycles. Defaults to 1 second.
132
+ */
133
+ intervalMs: options.cdcPollingOptions?.intervalMs ?? 1000,
134
+ },
135
+ trustServerCertificate: options.trustServerCertificate ?? false,
136
+ };
137
+ }
138
+ export function baseUri(config) {
139
+ return `mssql://${config.hostname}:${config.port}/${config.database}`;
140
+ }
141
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACxG,OAAO,K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,IAAI,YAAY,CAAC,SAAS,CAAC,WAAW,EAAE,iEAAiE,CAAC,CAAC;IACnH,CAAC;IAED,IAAI,QAAQ,IAAI,EAAE,EAAE,CAAC;QACnB,MAAM,IAAI,YAAY,CAAC,SAAS,CAAC,WAAW,EAAE,qCAAqC,CAAC,CAAC;IACvF,CAAC;IAED,MAAM,MAAM,GAAG,0BAA0B,CAAC,QAAQ,EAAE,EAAE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,EAAE,EAAE,CAAC,CAAC;IAE1G,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,SAAS;QAC3B,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,SAAS;QAE7B,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,IAAI;QACJ,QAAQ;QAER,MAAM;QACN,cAAc,EAAE,OAAO,CAAC,cAAc;QAEtC,iBAAiB,EAAE;YACjB;;eAEG;YACH,SAAS,EAAE,OAAO,CAAC,iBAAiB,EAAE,SAAS,IAAI,EAAE;YAErD;;eAEG;YACH,UAAU,EAAE,OAAO,CAAC,iBAAiB,EAAE,UAAU,IAAI,IAAI;SAC1D;QAED,sBAAsB,EAAE,OAAO,CAAC,sBAAsB,IAAI,KAAK;KACtB,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,MAAqC;IAC3D,OAAO,WAAW,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;AACxE,CAAC"}
@@ -0,0 +1,80 @@
1
+ import sql from 'mssql';
2
+ import { MSSQLConnectionManager } from '../replication/MSSQLConnectionManager.js';
3
+ import { LSN } from '../common/LSN.js';
4
+ import { CaptureInstance, MSSQLSourceTable } from '../common/MSSQLSourceTable.js';
5
+ import { MSSQLParameter } from '../types/mssql-data-types.js';
6
+ import { SqlSyncRules, TablePattern } from '@powersync/service-sync-rules';
7
+ import { ResolvedTable } from './schema.js';
8
+ import * as service_types from '@powersync/service-types';
9
+ export declare const POWERSYNC_CHECKPOINTS_TABLE = "_powersync_checkpoints";
10
+ export declare const SUPPORTED_ENGINE_EDITIONS: Map<number, string>;
11
+ export declare const MINIMUM_SUPPORTED_VERSION = "16.0";
12
+ export declare function checkSourceConfiguration(connectionManager: MSSQLConnectionManager): Promise<string[]>;
13
+ export declare function ensurePowerSyncCheckpointsTable(connectionManager: MSSQLConnectionManager): Promise<string[]>;
14
+ export declare function createCheckpoint(connectionManager: MSSQLConnectionManager): Promise<void>;
15
+ export interface IsTableEnabledForCDCOptions {
16
+ connectionManager: MSSQLConnectionManager;
17
+ table: string;
18
+ schema: string;
19
+ }
20
+ /**
21
+ * Check if the specified table is enabled for CDC.
22
+ * @param options
23
+ */
24
+ export declare function isTableEnabledForCDC(options: IsTableEnabledForCDCOptions): Promise<boolean>;
25
+ export interface EnableCDCForTableOptions {
26
+ connectionManager: MSSQLConnectionManager;
27
+ table: string;
28
+ }
29
+ export declare function enableCDCForTable(options: EnableCDCForTableOptions): Promise<void>;
30
+ /**
31
+ * Check if the supplied version is newer or equal to the target version.
32
+ * @param version
33
+ * @param minimumVersion
34
+ */
35
+ export declare function isVersionAtLeast(version: string, minimumVersion: string): boolean;
36
+ export interface IsWithinRetentionThresholdOptions {
37
+ checkpointLSN: LSN;
38
+ tables: MSSQLSourceTable[];
39
+ connectionManager: MSSQLConnectionManager;
40
+ }
41
+ /**
42
+ * Checks that CDC the specified checkpoint LSN is within the retention threshold for all specified tables.
43
+ * CDC periodically cleans up old data up to the retention threshold. If replication has been stopped for too long it is
44
+ * possible for the checkpoint LSN to be older than the minimum LSN in the CDC tables. In such a case we need to perform a new snapshot.
45
+ * @param options
46
+ */
47
+ export declare function isWithinRetentionThreshold(options: IsWithinRetentionThresholdOptions): Promise<boolean>;
48
+ export declare function getMinLSN(connectionManager: MSSQLConnectionManager, captureInstance: string): Promise<LSN>;
49
+ export declare function incrementLSN(lsn: LSN, connectionManager: MSSQLConnectionManager): Promise<LSN>;
50
+ export interface GetCaptureInstanceOptions {
51
+ connectionManager: MSSQLConnectionManager;
52
+ tableName: string;
53
+ schema: string;
54
+ }
55
+ export declare function getCaptureInstance(options: GetCaptureInstanceOptions): Promise<CaptureInstance | null>;
56
+ /**
57
+ * Return the LSN of the latest transaction recorded in the transaction log
58
+ * @param connectionManager
59
+ */
60
+ export declare function getLatestLSN(connectionManager: MSSQLConnectionManager): Promise<LSN>;
61
+ /**
62
+ * Return the LSN of the lastest transaction replicated to the CDC tables.
63
+ * @param connectionManager
64
+ */
65
+ export declare function getLatestReplicatedLSN(connectionManager: MSSQLConnectionManager): Promise<LSN>;
66
+ /**
67
+ * Escapes an identifier for use in MSSQL queries.
68
+ * @param identifier
69
+ */
70
+ export declare function escapeIdentifier(identifier: string): string;
71
+ export declare function toQualifiedTableName(schema: string, tableName: string): string;
72
+ export declare function isIColumnMetadata(obj: any): obj is sql.IColumnMetadata;
73
+ export declare function addParameters(request: sql.Request, parameters: MSSQLParameter[]): sql.Request;
74
+ export interface GetDebugTableInfoOptions {
75
+ connectionManager: MSSQLConnectionManager;
76
+ tablePattern: TablePattern;
77
+ table: ResolvedTable;
78
+ syncRules: SqlSyncRules;
79
+ }
80
+ export declare function getDebugTableInfo(options: GetDebugTableInfoOptions): Promise<service_types.TableInfo>;