@tejasanik/postgres-mcp-server 2.1.0 → 2.2.0

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 (96) hide show
  1. package/README.md +186 -10
  2. package/dist/db-manager/index.d.ts +7 -0
  3. package/dist/db-manager/index.d.ts.map +1 -0
  4. package/dist/db-manager/index.js +7 -0
  5. package/dist/db-manager/index.js.map +1 -0
  6. package/dist/db-manager/validation.d.ts +35 -0
  7. package/dist/db-manager/validation.d.ts.map +1 -0
  8. package/dist/db-manager/validation.js +54 -0
  9. package/dist/db-manager/validation.js.map +1 -0
  10. package/dist/db-manager.d.ts +175 -5
  11. package/dist/db-manager.d.ts.map +1 -1
  12. package/dist/db-manager.js +589 -26
  13. package/dist/db-manager.js.map +1 -1
  14. package/dist/index.js +141 -11
  15. package/dist/index.js.map +1 -1
  16. package/dist/tools/analysis-tools.d.ts.map +1 -1
  17. package/dist/tools/analysis-tools.js +53 -49
  18. package/dist/tools/analysis-tools.js.map +1 -1
  19. package/dist/tools/schema-tools.d.ts +40 -1
  20. package/dist/tools/schema-tools.d.ts.map +1 -1
  21. package/dist/tools/schema-tools.js +174 -92
  22. package/dist/tools/schema-tools.js.map +1 -1
  23. package/dist/tools/server-tools.d.ts +1 -0
  24. package/dist/tools/server-tools.d.ts.map +1 -1
  25. package/dist/tools/server-tools.js +10 -6
  26. package/dist/tools/server-tools.js.map +1 -1
  27. package/dist/tools/sql/utils/connection-utils.d.ts +79 -0
  28. package/dist/tools/sql/utils/connection-utils.d.ts.map +1 -0
  29. package/dist/tools/sql/utils/connection-utils.js +129 -0
  30. package/dist/tools/sql/utils/connection-utils.js.map +1 -0
  31. package/dist/tools/sql/utils/constants.d.ts +55 -0
  32. package/dist/tools/sql/utils/constants.d.ts.map +1 -0
  33. package/dist/tools/sql/utils/constants.js +55 -0
  34. package/dist/tools/sql/utils/constants.js.map +1 -0
  35. package/dist/tools/sql/utils/dry-run-utils.d.ts +31 -0
  36. package/dist/tools/sql/utils/dry-run-utils.d.ts.map +1 -0
  37. package/dist/tools/sql/utils/dry-run-utils.js +173 -0
  38. package/dist/tools/sql/utils/dry-run-utils.js.map +1 -0
  39. package/dist/tools/sql/utils/file-handler.d.ts +57 -0
  40. package/dist/tools/sql/utils/file-handler.d.ts.map +1 -0
  41. package/dist/tools/sql/utils/file-handler.js +150 -0
  42. package/dist/tools/sql/utils/file-handler.js.map +1 -0
  43. package/dist/tools/sql/utils/index.d.ts +12 -0
  44. package/dist/tools/sql/utils/index.d.ts.map +1 -0
  45. package/dist/tools/sql/utils/index.js +12 -0
  46. package/dist/tools/sql/utils/index.js.map +1 -0
  47. package/dist/tools/sql/utils/result-formatter.d.ts +94 -0
  48. package/dist/tools/sql/utils/result-formatter.d.ts.map +1 -0
  49. package/dist/tools/sql/utils/result-formatter.js +154 -0
  50. package/dist/tools/sql/utils/result-formatter.js.map +1 -0
  51. package/dist/tools/sql/utils/sql-parser.d.ts +125 -0
  52. package/dist/tools/sql/utils/sql-parser.d.ts.map +1 -0
  53. package/dist/tools/sql/utils/sql-parser.js +468 -0
  54. package/dist/tools/sql/utils/sql-parser.js.map +1 -0
  55. package/dist/tools/sql-tools.d.ts +21 -0
  56. package/dist/tools/sql-tools.d.ts.map +1 -1
  57. package/dist/tools/sql-tools.js +383 -532
  58. package/dist/tools/sql-tools.js.map +1 -1
  59. package/dist/types.d.ts +38 -0
  60. package/dist/types.d.ts.map +1 -1
  61. package/dist/utils/retry.d.ts +1 -1
  62. package/dist/utils/retry.d.ts.map +1 -1
  63. package/dist/utils/retry.js.map +1 -1
  64. package/dist/utils/validation.d.ts +45 -9
  65. package/dist/utils/validation.d.ts.map +1 -1
  66. package/dist/utils/validation.js +335 -72
  67. package/dist/utils/validation.js.map +1 -1
  68. package/package.json +9 -2
  69. package/dist/__tests__/analysis-tools.test.d.ts +0 -2
  70. package/dist/__tests__/analysis-tools.test.d.ts.map +0 -1
  71. package/dist/__tests__/analysis-tools.test.js +0 -294
  72. package/dist/__tests__/analysis-tools.test.js.map +0 -1
  73. package/dist/__tests__/db-manager.test.d.ts +0 -2
  74. package/dist/__tests__/db-manager.test.d.ts.map +0 -1
  75. package/dist/__tests__/db-manager.test.js +0 -410
  76. package/dist/__tests__/db-manager.test.js.map +0 -1
  77. package/dist/__tests__/mcp-server.test.d.ts +0 -13
  78. package/dist/__tests__/mcp-server.test.d.ts.map +0 -1
  79. package/dist/__tests__/mcp-server.test.js +0 -146
  80. package/dist/__tests__/mcp-server.test.js.map +0 -1
  81. package/dist/__tests__/schema-tools.test.d.ts +0 -2
  82. package/dist/__tests__/schema-tools.test.d.ts.map +0 -1
  83. package/dist/__tests__/schema-tools.test.js +0 -171
  84. package/dist/__tests__/schema-tools.test.js.map +0 -1
  85. package/dist/__tests__/server-tools.test.d.ts +0 -2
  86. package/dist/__tests__/server-tools.test.d.ts.map +0 -1
  87. package/dist/__tests__/server-tools.test.js +0 -113
  88. package/dist/__tests__/server-tools.test.js.map +0 -1
  89. package/dist/__tests__/sql-tools.test.d.ts +0 -2
  90. package/dist/__tests__/sql-tools.test.d.ts.map +0 -1
  91. package/dist/__tests__/sql-tools.test.js +0 -1912
  92. package/dist/__tests__/sql-tools.test.js.map +0 -1
  93. package/dist/__tests__/validation.test.d.ts +0 -2
  94. package/dist/__tests__/validation.test.d.ts.map +0 -1
  95. package/dist/__tests__/validation.test.js +0 -203
  96. package/dist/__tests__/validation.test.js.map +0 -1
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Connection Utilities
3
+ *
4
+ * Helper functions for connection management and override handling.
5
+ * Centralizes connection override logic to reduce duplication.
6
+ */
7
+ import { getDbManager } from '../../../db-manager.js';
8
+ /**
9
+ * Build a ConnectionOverride object from optional parameters.
10
+ * Returns undefined if no override parameters are provided.
11
+ *
12
+ * @param params - Optional connection override parameters
13
+ * @returns ConnectionOverride object or undefined
14
+ */
15
+ export function buildConnectionOverride(params) {
16
+ const hasOverride = params.server || params.database || params.schema;
17
+ if (!hasOverride) {
18
+ return undefined;
19
+ }
20
+ return {
21
+ server: params.server,
22
+ database: params.database,
23
+ schema: params.schema,
24
+ };
25
+ }
26
+ /**
27
+ * Check if connection override parameters conflict with transaction usage.
28
+ *
29
+ * @param params - Connection override parameters
30
+ * @param transactionId - Transaction ID if any
31
+ * @throws Error if override is used with transaction
32
+ */
33
+ export function validateOverrideWithTransaction(params, transactionId) {
34
+ const hasOverride = params.server || params.database || params.schema;
35
+ if (hasOverride && transactionId) {
36
+ throw new Error('Connection override (server/database/schema) cannot be used with transactions. ' +
37
+ 'Transactions are bound to the main connection.');
38
+ }
39
+ }
40
+ /**
41
+ * Acquire a client with optional connection override.
42
+ * Handles both regular and override client acquisition.
43
+ *
44
+ * @param override - Optional connection override
45
+ * @returns Acquired client with release function
46
+ */
47
+ export async function acquireClient(override) {
48
+ const dbManager = getDbManager();
49
+ if (override) {
50
+ const result = await dbManager.getClientWithOverride(override);
51
+ return {
52
+ client: result.client,
53
+ release: result.release,
54
+ isOverride: true,
55
+ connectionInfo: {
56
+ server: result.server,
57
+ database: result.database,
58
+ schema: result.schema,
59
+ },
60
+ };
61
+ }
62
+ const client = await dbManager.getClient();
63
+ return {
64
+ client,
65
+ release: () => client.release(),
66
+ isOverride: false,
67
+ };
68
+ }
69
+ /**
70
+ * Execute a function with an acquired client, ensuring proper cleanup.
71
+ *
72
+ * @param override - Optional connection override
73
+ * @param fn - Function to execute with the client
74
+ * @returns Result of the function
75
+ */
76
+ export async function withClient(override, fn) {
77
+ const { client, release } = await acquireClient(override);
78
+ try {
79
+ return await fn(client);
80
+ }
81
+ finally {
82
+ release();
83
+ }
84
+ }
85
+ /**
86
+ * Execute a function with a transaction, ensuring proper rollback on error.
87
+ *
88
+ * @param override - Optional connection override
89
+ * @param fn - Function to execute within transaction
90
+ * @param rollbackOnComplete - If true, rollback even on success (for dry-run)
91
+ * @returns Result of the function
92
+ */
93
+ export async function withTransaction(override, fn, rollbackOnComplete = false) {
94
+ const { client, release } = await acquireClient(override);
95
+ try {
96
+ await client.query('BEGIN');
97
+ const result = await fn(client);
98
+ if (rollbackOnComplete) {
99
+ await client.query('ROLLBACK');
100
+ }
101
+ else {
102
+ await client.query('COMMIT');
103
+ }
104
+ return result;
105
+ }
106
+ catch (error) {
107
+ try {
108
+ await client.query('ROLLBACK');
109
+ }
110
+ catch {
111
+ // Ignore rollback errors
112
+ }
113
+ throw error;
114
+ }
115
+ finally {
116
+ release();
117
+ }
118
+ }
119
+ /**
120
+ * Execute a dry-run transaction (always rollback).
121
+ *
122
+ * @param override - Optional connection override
123
+ * @param fn - Function to execute within transaction
124
+ * @returns Result of the function
125
+ */
126
+ export async function withDryRunTransaction(override, fn) {
127
+ return withTransaction(override, fn, true);
128
+ }
129
+ //# sourceMappingURL=connection-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-utils.js","sourceRoot":"","sources":["../../../../src/tools/sql/utils/connection-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AA2BtD;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAgC;IAEhC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC;IACtE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,+BAA+B,CAC7C,MAAgC,EAChC,aAAsB;IAEtB,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC;IACtE,IAAI,WAAW,IAAI,aAAa,E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AAa,CAAC,QAAQ,CAAC,CAAC;IAC1D,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC5B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,kBAAkB,EAAE,CAAC;YACvB,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACN,MAAM,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,yBAAyB;QAC3B,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,QAAwC,EACxC,EAAsC;IAEtC,OAAO,eAAe,CAAC,QAAQ,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * SQL Tools Constants
3
+ *
4
+ * Centralized configuration values for SQL execution tools.
5
+ * All magic numbers are defined here for maintainability.
6
+ */
7
+ /** Maximum characters in response before writing to temp file */
8
+ export declare const MAX_OUTPUT_CHARS = 50000;
9
+ /** Default maximum rows to return in direct response */
10
+ export declare const MAX_ROWS_DEFAULT = 1000;
11
+ /** Absolute maximum rows allowed */
12
+ export declare const MAX_ROWS_LIMIT = 100000;
13
+ /** Default SQL query length limit (100KB) */
14
+ export declare const DEFAULT_SQL_LENGTH_LIMIT = 100000;
15
+ /** Maximum number of query parameters */
16
+ export declare const MAX_PARAMS = 100;
17
+ /** Maximum SQL file size (50MB) */
18
+ export declare const MAX_SQL_FILE_SIZE: number;
19
+ /** Maximum sample rows to return in dry-run */
20
+ export declare const MAX_DRY_RUN_SAMPLE_ROWS = 10;
21
+ /** Maximum statements to preview in file preview */
22
+ export declare const MAX_PREVIEW_STATEMENTS = 100;
23
+ /** Default statements to show in preview */
24
+ export declare const DEFAULT_PREVIEW_STATEMENTS = 20;
25
+ /** Maximum batch queries in single call */
26
+ export declare const MAX_BATCH_QUERIES = 20;
27
+ /** Maximum sample size for mutation preview */
28
+ export declare const MAX_MUTATION_SAMPLE_SIZE = 20;
29
+ /** Default sample size for mutation preview */
30
+ export declare const DEFAULT_MUTATION_SAMPLE_SIZE = 5;
31
+ /** Transaction timeout in milliseconds (10 minutes for active operations) */
32
+ export declare const TRANSACTION_TIMEOUT_MS: number;
33
+ /** Transaction auto-cleanup timeout in milliseconds (45 minutes) */
34
+ export declare const TRANSACTION_CLEANUP_TIMEOUT_MS: number;
35
+ /** Transaction cleanup check interval in milliseconds (5 minutes) */
36
+ export declare const TRANSACTION_CLEANUP_INTERVAL_MS: number;
37
+ /** Maximum SQL length for ReDoS-safe regex operations (100KB) */
38
+ export declare const MAX_SQL_LENGTH_FOR_REGEX = 100000;
39
+ /** Maximum hypothetical indexes per query */
40
+ export declare const MAX_HYPOTHETICAL_INDEXES = 10;
41
+ /** Maximum columns per hypothetical index */
42
+ export declare const MAX_HYPOTHETICAL_INDEX_COLUMNS = 10;
43
+ /** Maximum statements in dry-run file results */
44
+ export declare const MAX_DRY_RUN_STATEMENTS = 200;
45
+ /** Default statements in dry-run file results */
46
+ export declare const DEFAULT_DRY_RUN_STATEMENTS = 50;
47
+ /** Maximum rows per statement in multi-statement execution */
48
+ export declare const MAX_ROWS_PER_STATEMENT = 100;
49
+ /** Short SQL truncation limit for display */
50
+ export declare const SQL_TRUNCATION_SHORT = 200;
51
+ /** Long SQL truncation limit for detailed display */
52
+ export declare const SQL_TRUNCATION_LONG = 300;
53
+ /** Maximum tables to analyze for schema hints */
54
+ export declare const MAX_TABLES_TO_ANALYZE = 10;
55
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/tools/sql/utils/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,iEAAiE;AACjE,eAAO,MAAM,gBAAgB,QAAQ,CAAC;AAEtC,wDAAwD;AACxD,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC,oCAAoC;AACpC,eAAO,MAAM,cAAc,SAAS,CAAC;AAErC,6CAA6C;AAC7C,eAAO,MAAM,wBAAwB,SAAS,CAAC;AAE/C,yCAAyC;AACzC,eAAO,MAAM,UAAU,MAAM,CAAC;AAE9B,mCAAmC;AACnC,eAAO,MAAM,iBAAiB,QAAmB,CAAC;AAElD,+CAA+C;AAC/C,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,oDAAoD;AACpD,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,4CAA4C;AAC5C,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C,2CAA2C;AAC3C,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,+CAA+C;AAC/C,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C,+CAA+C;AAC/C,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAE9C,6EAA6E;AAC7E,eAAO,MAAM,sBAAsB,QAAiB,CAAC;AAErD,oEAAoE;AACpE,eAAO,MAAM,8BAA8B,QAAiB,CAAC;AAE7D,qEAAqE;AACrE,eAAO,MAAM,+BAA+B,QAAgB,CAAC;AAE7D,iEAAiE;AACjE,eAAO,MAAM,wBAAwB,SAAS,CAAC;AAE/C,6CAA6C;AAC7C,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C,6CAA6C;AAC7C,eAAO,MAAM,8BAA8B,KAAK,CAAC;AAEjD,iDAAiD;AACjD,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,iDAAiD;AACjD,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C,8DAA8D;AAC9D,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,6CAA6C;AAC7C,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,qDAAqD;AACrD,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,iDAAiD;AACjD,eAAO,MAAM,qBAAqB,KAAK,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * SQL Tools Constants
3
+ *
4
+ * Centralized configuration values for SQL execution tools.
5
+ * All magic numbers are defined here for maintainability.
6
+ */
7
+ /** Maximum characters in response before writing to temp file */
8
+ export const MAX_OUTPUT_CHARS = 50000;
9
+ /** Default maximum rows to return in direct response */
10
+ export const MAX_ROWS_DEFAULT = 1000;
11
+ /** Absolute maximum rows allowed */
12
+ export const MAX_ROWS_LIMIT = 100000;
13
+ /** Default SQL query length limit (100KB) */
14
+ export const DEFAULT_SQL_LENGTH_LIMIT = 100000;
15
+ /** Maximum number of query parameters */
16
+ export const MAX_PARAMS = 100;
17
+ /** Maximum SQL file size (50MB) */
18
+ export const MAX_SQL_FILE_SIZE = 50 * 1024 * 1024;
19
+ /** Maximum sample rows to return in dry-run */
20
+ export const MAX_DRY_RUN_SAMPLE_ROWS = 10;
21
+ /** Maximum statements to preview in file preview */
22
+ export const MAX_PREVIEW_STATEMENTS = 100;
23
+ /** Default statements to show in preview */
24
+ export const DEFAULT_PREVIEW_STATEMENTS = 20;
25
+ /** Maximum batch queries in single call */
26
+ export const MAX_BATCH_QUERIES = 20;
27
+ /** Maximum sample size for mutation preview */
28
+ export const MAX_MUTATION_SAMPLE_SIZE = 20;
29
+ /** Default sample size for mutation preview */
30
+ export const DEFAULT_MUTATION_SAMPLE_SIZE = 5;
31
+ /** Transaction timeout in milliseconds (10 minutes for active operations) */
32
+ export const TRANSACTION_TIMEOUT_MS = 10 * 60 * 1000;
33
+ /** Transaction auto-cleanup timeout in milliseconds (45 minutes) */
34
+ export const TRANSACTION_CLEANUP_TIMEOUT_MS = 45 * 60 * 1000;
35
+ /** Transaction cleanup check interval in milliseconds (5 minutes) */
36
+ export const TRANSACTION_CLEANUP_INTERVAL_MS = 5 * 60 * 1000;
37
+ /** Maximum SQL length for ReDoS-safe regex operations (100KB) */
38
+ export const MAX_SQL_LENGTH_FOR_REGEX = 100000;
39
+ /** Maximum hypothetical indexes per query */
40
+ export const MAX_HYPOTHETICAL_INDEXES = 10;
41
+ /** Maximum columns per hypothetical index */
42
+ export const MAX_HYPOTHETICAL_INDEX_COLUMNS = 10;
43
+ /** Maximum statements in dry-run file results */
44
+ export const MAX_DRY_RUN_STATEMENTS = 200;
45
+ /** Default statements in dry-run file results */
46
+ export const DEFAULT_DRY_RUN_STATEMENTS = 50;
47
+ /** Maximum rows per statement in multi-statement execution */
48
+ export const MAX_ROWS_PER_STATEMENT = 100;
49
+ /** Short SQL truncation limit for display */
50
+ export const SQL_TRUNCATION_SHORT = 200;
51
+ /** Long SQL truncation limit for detailed display */
52
+ export const SQL_TRUNCATION_LONG = 300;
53
+ /** Maximum tables to analyze for schema hints */
54
+ export const MAX_TABLES_TO_ANALYZE = 10;
55
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/tools/sql/utils/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,iEAAiE;AACjE,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAEtC,wDAAwD;AACxD,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAErC,oCAAoC;AACpC,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AAErC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAE/C,yCAAyC;AACzC,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC;AAE9B,mCAAmC;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,E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G,CAAC;AAEvC,iDAAiD;AACjD,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Dry-Run Utilities
3
+ *
4
+ * Helper functions for transaction-based dry-run operations.
5
+ * Handles error extraction and detection of non-rollbackable operations.
6
+ */
7
+ import { DryRunError, NonRollbackableWarning } from '../../../types.js';
8
+ /**
9
+ * Extract detailed error information from a PostgreSQL error.
10
+ * Captures all available fields to help AI quickly identify and fix issues.
11
+ */
12
+ export declare function extractDryRunError(error: unknown): DryRunError;
13
+ /**
14
+ * Check if a SQL statement contains operations that cannot be fully rolled back
15
+ * or have side effects even within a transaction.
16
+ *
17
+ * @param sql - The SQL statement to check
18
+ * @param statementIndex - Optional statement index for error reporting
19
+ * @param lineNumber - Optional line number for error reporting
20
+ * @returns Array of warnings about non-rollbackable operations
21
+ */
22
+ export declare function detectNonRollbackableOperations(sql: string, statementIndex?: number, lineNumber?: number): NonRollbackableWarning[];
23
+ /**
24
+ * Check if any warning requires skipping the statement.
25
+ */
26
+ export declare function hasMustSkipWarning(warnings: NonRollbackableWarning[]): boolean;
27
+ /**
28
+ * Get skip reason from must-skip warnings.
29
+ */
30
+ export declare function getSkipReason(warnings: NonRollbackableWarning[]): string;
31
+ //# sourceMappingURL=dry-run-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dry-run-utils.d.ts","sourceRoot":"","sources":["../../../../src/tools/sql/utils/dry-run-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAgFxE;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAsC9D;AAED;;;;;;;;GAQG;AACH,wBAAgB,+BAA+B,CAC7C,GAAG,EAAE,MAAM,EACX,cAAc,CAAC,EAAE,MAAM,EACvB,UAAU,CAAC,EAAE,MAAM,GAClB,sBAAsB,EAAE,CAkB1B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAE9E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,sBAAsB,EAAE,GAAG,MAAM,CAKxE"}
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Dry-Run Utilities
3
+ *
4
+ * Helper functions for transaction-based dry-run operations.
5
+ * Handles error extraction and detection of non-rollbackable operations.
6
+ */
7
+ /**
8
+ * Non-rollbackable operation patterns.
9
+ * Operations that cannot run inside a transaction or have permanent side effects.
10
+ */
11
+ const NON_ROLLBACKABLE_PATTERNS = [
12
+ // Operations that cannot run inside a transaction at all
13
+ {
14
+ pattern: /\bVACUUM\b/,
15
+ operation: 'VACUUM',
16
+ message: 'VACUUM cannot run inside a transaction block. Statement skipped.',
17
+ mustSkip: true,
18
+ },
19
+ {
20
+ pattern: /\bCLUSTER\b(?!.*CREATE)/,
21
+ operation: 'CLUSTER',
22
+ message: 'CLUSTER cannot run inside a transaction block. Statement skipped.',
23
+ mustSkip: true,
24
+ },
25
+ {
26
+ pattern: /\bREINDEX\b.*\bCONCURRENTLY\b/,
27
+ operation: 'REINDEX_CONCURRENTLY',
28
+ message: 'REINDEX CONCURRENTLY cannot run inside a transaction block. Statement skipped.',
29
+ mustSkip: true,
30
+ },
31
+ {
32
+ pattern: /\bCREATE\s+INDEX\b.*\bCONCURRENTLY\b/,
33
+ operation: 'CREATE_INDEX_CONCURRENTLY',
34
+ message: 'CREATE INDEX CONCURRENTLY cannot run inside a transaction block. Statement skipped.',
35
+ mustSkip: true,
36
+ },
37
+ {
38
+ pattern: /\bCREATE\s+DATABASE\b/,
39
+ operation: 'CREATE_DATABASE',
40
+ message: 'CREATE DATABASE cannot run inside a transaction block. Statement skipped.',
41
+ mustSkip: true,
42
+ },
43
+ {
44
+ pattern: /\bDROP\s+DATABASE\b/,
45
+ operation: 'DROP_DATABASE',
46
+ message: 'DROP DATABASE cannot run inside a transaction block. Statement skipped.',
47
+ mustSkip: true,
48
+ },
49
+ // Operations with permanent side effects
50
+ {
51
+ pattern: /\bNEXTVAL\s*\(/,
52
+ operation: 'SEQUENCE',
53
+ message: 'NEXTVAL increments sequence even when transaction is rolled back. Statement skipped to prevent sequence consumption.',
54
+ mustSkip: true,
55
+ },
56
+ {
57
+ pattern: /\bSETVAL\s*\(/,
58
+ operation: 'SEQUENCE',
59
+ message: 'SETVAL modifies sequence. Statement skipped to prevent side effects.',
60
+ mustSkip: true,
61
+ },
62
+ // Warning-only operations (still executed)
63
+ {
64
+ pattern: /\bINSERT\s+INTO\b/,
65
+ operation: 'SEQUENCE',
66
+ message: 'INSERT may consume sequence values (for SERIAL/BIGSERIAL columns) even when rolled back.',
67
+ mustSkip: false,
68
+ },
69
+ {
70
+ pattern: /\bNOTIFY\b/,
71
+ operation: 'NOTIFY',
72
+ message: 'NOTIFY sends notifications on commit. Since dry-run rolls back, notifications will NOT be sent.',
73
+ mustSkip: false,
74
+ },
75
+ ];
76
+ /**
77
+ * Extract detailed error information from a PostgreSQL error.
78
+ * Captures all available fields to help AI quickly identify and fix issues.
79
+ */
80
+ export function extractDryRunError(error) {
81
+ // Extract message - prioritize Error.message, then object.message, then String conversion
82
+ let message;
83
+ if (error instanceof Error) {
84
+ message = error.message;
85
+ }
86
+ else if (error && typeof error === 'object' && 'message' in error) {
87
+ message = String(error.message);
88
+ }
89
+ else {
90
+ message = String(error);
91
+ }
92
+ const result = { message };
93
+ if (error && typeof error === 'object') {
94
+ const pgError = error;
95
+ // Extract string fields
96
+ if (pgError.code)
97
+ result.code = String(pgError.code);
98
+ if (pgError.severity)
99
+ result.severity = String(pgError.severity);
100
+ if (pgError.detail)
101
+ result.detail = String(pgError.detail);
102
+ if (pgError.hint)
103
+ result.hint = String(pgError.hint);
104
+ if (pgError.internalQuery)
105
+ result.internalQuery = String(pgError.internalQuery);
106
+ if (pgError.where)
107
+ result.where = String(pgError.where);
108
+ if (pgError.schema)
109
+ result.schema = String(pgError.schema);
110
+ if (pgError.table)
111
+ result.table = String(pgError.table);
112
+ if (pgError.column)
113
+ result.column = String(pgError.column);
114
+ if (pgError.dataType)
115
+ result.dataType = String(pgError.dataType);
116
+ if (pgError.constraint)
117
+ result.constraint = String(pgError.constraint);
118
+ if (pgError.file)
119
+ result.file = String(pgError.file);
120
+ if (pgError.line)
121
+ result.line = String(pgError.line);
122
+ if (pgError.routine)
123
+ result.routine = String(pgError.routine);
124
+ // Extract number fields
125
+ if (pgError.position !== undefined)
126
+ result.position = Number(pgError.position);
127
+ if (pgError.internalPosition !== undefined)
128
+ result.internalPosition = Number(pgError.internalPosition);
129
+ }
130
+ return result;
131
+ }
132
+ /**
133
+ * Check if a SQL statement contains operations that cannot be fully rolled back
134
+ * or have side effects even within a transaction.
135
+ *
136
+ * @param sql - The SQL statement to check
137
+ * @param statementIndex - Optional statement index for error reporting
138
+ * @param lineNumber - Optional line number for error reporting
139
+ * @returns Array of warnings about non-rollbackable operations
140
+ */
141
+ export function detectNonRollbackableOperations(sql, statementIndex, lineNumber) {
142
+ const warnings = [];
143
+ const upperSql = sql.toUpperCase().trim();
144
+ const clusterPattern = /\bCLUSTER\b/;
145
+ for (const { pattern, operation, message, mustSkip } of NON_ROLLBACKABLE_PATTERNS) {
146
+ // Special handling for CLUSTER (must not be part of CREATE)
147
+ if (operation === 'CLUSTER') {
148
+ if (clusterPattern.test(upperSql) && !upperSql.includes('CREATE')) {
149
+ warnings.push({ operation, message, statementIndex, lineNumber, mustSkip });
150
+ }
151
+ }
152
+ else if (pattern.test(upperSql)) {
153
+ warnings.push({ operation, message, statementIndex, lineNumber, mustSkip });
154
+ }
155
+ }
156
+ return warnings;
157
+ }
158
+ /**
159
+ * Check if any warning requires skipping the statement.
160
+ */
161
+ export function hasMustSkipWarning(warnings) {
162
+ return warnings.some((w) => w.mustSkip);
163
+ }
164
+ /**
165
+ * Get skip reason from must-skip warnings.
166
+ */
167
+ export function getSkipReason(warnings) {
168
+ return warnings
169
+ .filter((w) => w.mustSkip)
170
+ .map((w) => w.message)
171
+ .join('; ');
172
+ }
173
+ //# sourceMappingURL=dry-run-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dry-run-utils.js","sourceRoot":"","sources":["../../../../src/tools/sql/utils/dry-run-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH;;;GAGG;AACH,MAAM,yBAAyB,GAK1B;IACH,yDAAyD;IACzD;QACE,OAAO,EAAE,YAAY;QACrB,SAAS,EAAE,QAAQ;QACnB,OAAO,EAAE,kEAAkE;QAC3E,QAAQ,EAAE,IAAI;KACf;IACD;QACE,OAAO,EAAE,yBAAyB;QAClC,SAAS,EAAE,SAAS;QACpB,OAAO,EAAE,mEAAmE;QAC5E,QAAQ,EAAE,IAAI;KACf;IACD;QACE,OAAO,EAAE,+BAA+B;QACxC,SAAS,EAAE,sBAAsB;QACjC,OAAO,EAAE,gFAAgF;QACzF,QAAQ,EAAE,IAAI;KACf;IACD;QACE,OAAO,EAAE,sCAAsC;QAC/C,SAAS,EAAE,2BAA2B;QACtC,OAAO,EAAE,qFAAqF;QAC9F,QAAQ,EAAE,IAAI;KACf;IACD;QACE,OAAO,EAAE,uBAAuB;QAChC,SAAS,EAAE,iBAAiB;QAC5B,OAAO,EAAE,2EAA2E;QACpF,QAAQ,EAAE,IAAI;KACf;IACD;QACE,OAAO,EAAE,qBAAqB;QAC9B,SAAS,EAAE,eAAe;QAC1B,OAAO,EAAE,yEAAyE;QAClF,QAAQ,EAAE,IAAI;KACf;IACD,yCAAyC;IACzC;QACE,OAAO,EAAE,gBAAgB;QACzB,SAAS,EAAE,UAAU;QACrB,OAAO,EAAE,sHAAsH;QAC/H,QAAQ,EAAE,IAAI;KACf;IACD;QACE,OAAO,EAAE,eAAe;QACxB,SAAS,EAAE,UAAU;QACrB,OAAO,EAAE,sEAAsE;QAC/E,QAAQ,EAAE,IAAI;KACf;IACD,2CAA2C;IAC3C;Q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,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;SACzB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;SACrB,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * File Handler Utilities
3
+ *
4
+ * Functions for validating and processing SQL files.
5
+ * Handles file validation, reading, and preprocessing.
6
+ */
7
+ /**
8
+ * Result of file validation.
9
+ */
10
+ export interface FileValidationResult {
11
+ isValid: boolean;
12
+ resolvedPath: string;
13
+ fileSize: number;
14
+ error?: string;
15
+ }
16
+ /**
17
+ * Validates a SQL file path and returns file information.
18
+ *
19
+ * @param filePath - Path to the SQL file
20
+ * @returns Validation result with resolved path and file size
21
+ */
22
+ export declare function validateSqlFile(filePath: string): FileValidationResult;
23
+ /**
24
+ * Reads a SQL file and optionally preprocesses it.
25
+ *
26
+ * @param resolvedPath - Resolved path to the SQL file
27
+ * @param stripPatterns - Optional patterns to remove from content
28
+ * @param stripAsRegex - If true, patterns are regex; if false, literal strings
29
+ * @returns Preprocessed SQL content
30
+ */
31
+ export declare function readSqlFile(resolvedPath: string, stripPatterns?: string[], stripAsRegex?: boolean): string;
32
+ /**
33
+ * Preprocess SQL content by removing patterns.
34
+ * Supports both literal string matching and regex patterns.
35
+ *
36
+ * @param sql - The SQL content to preprocess
37
+ * @param patterns - Array of patterns to remove from SQL content
38
+ * @param isRegex - If true, patterns are treated as regex; if false, as literal strings
39
+ * @returns Preprocessed SQL content
40
+ */
41
+ export declare function preprocessSqlContent(sql: string, patterns: string[], isRegex?: boolean): string;
42
+ /**
43
+ * Format file size in human-readable format.
44
+ *
45
+ * @param bytes - File size in bytes
46
+ * @returns Human-readable file size (e.g., "1.5 MB")
47
+ */
48
+ export declare function formatFileSize(bytes: number): string;
49
+ /**
50
+ * Ensure a file path is safe (no path traversal attacks).
51
+ *
52
+ * @param basePath - Base directory path
53
+ * @param filePath - File path to validate
54
+ * @returns True if the file path is within the base path
55
+ */
56
+ export declare function isPathSafe(basePath: string, filePath: string): boolean;
57
+ //# sourceMappingURL=file-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-handler.d.ts","sourceRoot":"","sources":["../../../../src/tools/sql/utils/file-handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,oBAAoB,CA+DtE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,YAAY,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,EAAE,EACxB,YAAY,GAAE,OAAe,GAC5B,MAAM,CAQR;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,GAAE,OAAe,GACvB,MAAM,CA2BR;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAYpD;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAItE"}