rawsql-ts 0.11.32-beta → 0.11.33-beta

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 (123) hide show
  1. package/dist/esm/index.js +9 -0
  2. package/dist/esm/index.js.map +1 -1
  3. package/dist/esm/index.min.js +37 -29
  4. package/dist/esm/index.min.js.map +4 -4
  5. package/dist/esm/src/formatters/OriginalFormatRestorer.d.ts +40 -0
  6. package/dist/esm/src/formatters/OriginalFormatRestorer.js +135 -0
  7. package/dist/esm/src/formatters/OriginalFormatRestorer.js.map +1 -0
  8. package/dist/esm/src/index.d.ts +11 -0
  9. package/dist/esm/src/index.js +9 -0
  10. package/dist/esm/src/index.js.map +1 -1
  11. package/dist/esm/src/models/FormattingLexeme.d.ts +66 -0
  12. package/dist/esm/src/models/FormattingLexeme.js +2 -0
  13. package/dist/esm/src/models/FormattingLexeme.js.map +1 -0
  14. package/dist/esm/src/models/ValueComponent.d.ts +3 -1
  15. package/dist/esm/src/models/ValueComponent.js +3 -1
  16. package/dist/esm/src/models/ValueComponent.js.map +1 -1
  17. package/dist/esm/src/parsers/FunctionExpressionParser.d.ts +12 -0
  18. package/dist/esm/src/parsers/FunctionExpressionParser.js +111 -7
  19. package/dist/esm/src/parsers/FunctionExpressionParser.js.map +1 -1
  20. package/dist/esm/src/parsers/KeywordParser.d.ts +1 -0
  21. package/dist/esm/src/parsers/KeywordParser.js +10 -4
  22. package/dist/esm/src/parsers/KeywordParser.js.map +1 -1
  23. package/dist/esm/src/parsers/SqlPrintTokenParser.js +8 -0
  24. package/dist/esm/src/parsers/SqlPrintTokenParser.js.map +1 -1
  25. package/dist/esm/src/parsers/SqlTokenizer.d.ts +42 -2
  26. package/dist/esm/src/parsers/SqlTokenizer.js +213 -12
  27. package/dist/esm/src/parsers/SqlTokenizer.js.map +1 -1
  28. package/dist/esm/src/tokenReaders/CommandTokenReader.d.ts +3 -0
  29. package/dist/esm/src/tokenReaders/CommandTokenReader.js +4 -1
  30. package/dist/esm/src/tokenReaders/CommandTokenReader.js.map +1 -1
  31. package/dist/esm/src/transformers/AliasRenamer.d.ts +199 -0
  32. package/dist/esm/src/transformers/AliasRenamer.js +595 -0
  33. package/dist/esm/src/transformers/AliasRenamer.js.map +1 -0
  34. package/dist/esm/src/transformers/CTERenamer.d.ts +53 -0
  35. package/dist/esm/src/transformers/CTERenamer.js +138 -0
  36. package/dist/esm/src/transformers/CTERenamer.js.map +1 -1
  37. package/dist/esm/src/transformers/DynamicQueryBuilder.d.ts +72 -0
  38. package/dist/esm/src/transformers/DynamicQueryBuilder.js +42 -0
  39. package/dist/esm/src/transformers/DynamicQueryBuilder.js.map +1 -1
  40. package/dist/esm/src/transformers/FilterableItemCollector.d.ts +80 -0
  41. package/dist/esm/src/transformers/FilterableItemCollector.js +254 -0
  42. package/dist/esm/src/transformers/FilterableItemCollector.js.map +1 -0
  43. package/dist/esm/src/transformers/SelectableColumnCollector.d.ts +3 -0
  44. package/dist/esm/src/transformers/SelectableColumnCollector.js +68 -7
  45. package/dist/esm/src/transformers/SelectableColumnCollector.js.map +1 -1
  46. package/dist/esm/src/transformers/SmartRenamer.d.ts +134 -0
  47. package/dist/esm/src/transformers/SmartRenamer.js +430 -0
  48. package/dist/esm/src/transformers/SmartRenamer.js.map +1 -0
  49. package/dist/esm/src/transformers/SqlIdentifierRenamer.d.ts +150 -0
  50. package/dist/esm/src/transformers/SqlIdentifierRenamer.js +493 -0
  51. package/dist/esm/src/transformers/SqlIdentifierRenamer.js.map +1 -0
  52. package/dist/esm/src/transformers/SqlParamInjector.d.ts +27 -0
  53. package/dist/esm/src/transformers/SqlParamInjector.js +304 -16
  54. package/dist/esm/src/transformers/SqlParamInjector.js.map +1 -1
  55. package/dist/esm/src/transformers/SqlSortInjector.js +6 -3
  56. package/dist/esm/src/transformers/SqlSortInjector.js.map +1 -1
  57. package/dist/esm/src/transformers/UpstreamSelectQueryFinder.js +5 -2
  58. package/dist/esm/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
  59. package/dist/esm/src/utils/LexemeCursor.d.ts +41 -0
  60. package/dist/esm/src/utils/LexemeCursor.js +93 -0
  61. package/dist/esm/src/utils/LexemeCursor.js.map +1 -1
  62. package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
  63. package/dist/index.min.js +37 -29
  64. package/dist/index.min.js.map +4 -4
  65. package/dist/src/formatters/OriginalFormatRestorer.d.ts +40 -0
  66. package/dist/src/formatters/OriginalFormatRestorer.js +139 -0
  67. package/dist/src/formatters/OriginalFormatRestorer.js.map +1 -0
  68. package/dist/src/index.d.ts +11 -0
  69. package/dist/src/index.js +11 -1
  70. package/dist/src/index.js.map +1 -1
  71. package/dist/src/models/FormattingLexeme.d.ts +66 -0
  72. package/dist/src/models/FormattingLexeme.js +3 -0
  73. package/dist/src/models/FormattingLexeme.js.map +1 -0
  74. package/dist/src/models/ValueComponent.d.ts +3 -1
  75. package/dist/src/models/ValueComponent.js +3 -1
  76. package/dist/src/models/ValueComponent.js.map +1 -1
  77. package/dist/src/parsers/FunctionExpressionParser.d.ts +12 -0
  78. package/dist/src/parsers/FunctionExpressionParser.js +110 -6
  79. package/dist/src/parsers/FunctionExpressionParser.js.map +1 -1
  80. package/dist/src/parsers/KeywordParser.d.ts +1 -0
  81. package/dist/src/parsers/KeywordParser.js +10 -4
  82. package/dist/src/parsers/KeywordParser.js.map +1 -1
  83. package/dist/src/parsers/SqlPrintTokenParser.js +8 -0
  84. package/dist/src/parsers/SqlPrintTokenParser.js.map +1 -1
  85. package/dist/src/parsers/SqlTokenizer.d.ts +42 -2
  86. package/dist/src/parsers/SqlTokenizer.js +222 -12
  87. package/dist/src/parsers/SqlTokenizer.js.map +1 -1
  88. package/dist/src/tokenReaders/CommandTokenReader.d.ts +3 -0
  89. package/dist/src/tokenReaders/CommandTokenReader.js +5 -2
  90. package/dist/src/tokenReaders/CommandTokenReader.js.map +1 -1
  91. package/dist/src/transformers/AliasRenamer.d.ts +199 -0
  92. package/dist/src/transformers/AliasRenamer.js +599 -0
  93. package/dist/src/transformers/AliasRenamer.js.map +1 -0
  94. package/dist/src/transformers/CTERenamer.d.ts +53 -0
  95. package/dist/src/transformers/CTERenamer.js +138 -0
  96. package/dist/src/transformers/CTERenamer.js.map +1 -1
  97. package/dist/src/transformers/DynamicQueryBuilder.d.ts +72 -0
  98. package/dist/src/transformers/DynamicQueryBuilder.js +42 -0
  99. package/dist/src/transformers/DynamicQueryBuilder.js.map +1 -1
  100. package/dist/src/transformers/FilterableItemCollector.d.ts +80 -0
  101. package/dist/src/transformers/FilterableItemCollector.js +259 -0
  102. package/dist/src/transformers/FilterableItemCollector.js.map +1 -0
  103. package/dist/src/transformers/SelectableColumnCollector.d.ts +3 -0
  104. package/dist/src/transformers/SelectableColumnCollector.js +67 -6
  105. package/dist/src/transformers/SelectableColumnCollector.js.map +1 -1
  106. package/dist/src/transformers/SmartRenamer.d.ts +134 -0
  107. package/dist/src/transformers/SmartRenamer.js +442 -0
  108. package/dist/src/transformers/SmartRenamer.js.map +1 -0
  109. package/dist/src/transformers/SqlIdentifierRenamer.d.ts +150 -0
  110. package/dist/src/transformers/SqlIdentifierRenamer.js +497 -0
  111. package/dist/src/transformers/SqlIdentifierRenamer.js.map +1 -0
  112. package/dist/src/transformers/SqlParamInjector.d.ts +27 -0
  113. package/dist/src/transformers/SqlParamInjector.js +303 -15
  114. package/dist/src/transformers/SqlParamInjector.js.map +1 -1
  115. package/dist/src/transformers/SqlSortInjector.js +5 -2
  116. package/dist/src/transformers/SqlSortInjector.js.map +1 -1
  117. package/dist/src/transformers/UpstreamSelectQueryFinder.js +4 -1
  118. package/dist/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
  119. package/dist/src/utils/LexemeCursor.d.ts +41 -0
  120. package/dist/src/utils/LexemeCursor.js +93 -0
  121. package/dist/src/utils/LexemeCursor.js.map +1 -1
  122. package/dist/tsconfig.tsbuildinfo +1 -1
  123. package/package.json +1 -1
@@ -0,0 +1,599 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AliasRenamer = void 0;
4
+ const SelectQuery_1 = require("../models/SelectQuery");
5
+ const LexemeCursor_1 = require("../utils/LexemeCursor");
6
+ const Lexeme_1 = require("../models/Lexeme");
7
+ const SelectQueryParser_1 = require("../parsers/SelectQueryParser");
8
+ const CTERegionDetector_1 = require("../utils/CTERegionDetector");
9
+ const TableSourceCollector_1 = require("./TableSourceCollector");
10
+ const ColumnReferenceCollector_1 = require("./ColumnReferenceCollector");
11
+ const KeywordParser_1 = require("../parsers/KeywordParser");
12
+ const CommandTokenReader_1 = require("../tokenReaders/CommandTokenReader");
13
+ /**
14
+ * Error messages for alias renaming operations
15
+ */
16
+ const ERROR_MESSAGES = {
17
+ invalidSql: 'Invalid SQL: unable to parse query',
18
+ invalidPosition: 'Invalid position: line or column out of bounds',
19
+ noLexemeAtPosition: 'No lexeme found at the specified position',
20
+ notAnAlias: 'Selected lexeme is not a valid alias',
21
+ invalidNewName: 'New alias name must be a non-empty string',
22
+ sameNames: 'Old and new alias names cannot be the same',
23
+ nameConflict: (name) => `Alias '${name}' already exists in this scope`,
24
+ aliasNotFound: (name) => `Alias '${name}' not found in current scope`,
25
+ };
26
+ /**
27
+ * A utility class for renaming table and column aliases in SQL queries.
28
+ *
29
+ * This class provides functionality to rename aliases within specific scopes
30
+ * (CTE, subquery, or main query) based on cursor position from GUI editors.
31
+ * It automatically detects the appropriate scope and updates all references
32
+ * to the alias within that scope boundary.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * import { AliasRenamer } from 'rawsql-ts';
37
+ *
38
+ * const sql = `
39
+ * SELECT u.name, o.date
40
+ * FROM users u
41
+ * JOIN orders o ON u.id = o.user_id
42
+ * `;
43
+ *
44
+ * const renamer = new AliasRenamer();
45
+ *
46
+ * // Rename 'u' to 'user_alias' by selecting it at line 2, column 10
47
+ * const result = renamer.renameAlias(sql, { line: 2, column: 10 }, 'user_alias');
48
+ *
49
+ * if (result.success) {
50
+ * console.log(result.newSql);
51
+ * // SELECT user_alias.name, o.date
52
+ * // FROM users user_alias
53
+ * // JOIN orders o ON user_alias.id = o.user_id
54
+ * }
55
+ * ```
56
+ *
57
+ * @since 0.12.0
58
+ */
59
+ class AliasRenamer {
60
+ /**
61
+ * Creates a new instance of AliasRenamer.
62
+ */
63
+ constructor() {
64
+ // Initialize keyword parser for reserved word detection using shared trie
65
+ this.keywordParser = new KeywordParser_1.KeywordParser(CommandTokenReader_1.commandKeywordTrie);
66
+ }
67
+ /**
68
+ * Renames an alias based on the cursor position in GUI editor.
69
+ *
70
+ * This method detects the alias at the specified line and column position,
71
+ * determines its scope (CTE, subquery, or main query), and renames all
72
+ * references to that alias within the scope boundaries.
73
+ *
74
+ * @param sql - The SQL string containing the alias to rename
75
+ * @param position - Line and column position (1-based) from GUI editor
76
+ * @param newName - The new name for the alias
77
+ * @param options - Optional configuration for the rename operation
78
+ * @returns Result containing success status, modified SQL, and change details
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const sql = "SELECT u.name FROM users u WHERE u.active = true";
83
+ * const result = renamer.renameAlias(sql, { line: 1, column: 8 }, 'user_table');
84
+ *
85
+ * if (result.success) {
86
+ * console.log(result.newSql);
87
+ * // "SELECT user_table.name FROM users user_table WHERE user_table.active = true"
88
+ * }
89
+ * ```
90
+ *
91
+ * @throws {Error} When the SQL cannot be parsed or position is invalid
92
+ */
93
+ renameAlias(sql, position, newName, options = {}) {
94
+ try {
95
+ // Input validation
96
+ this.validateInputs(sql, position, newName);
97
+ // Find lexeme at the specified position
98
+ const lexeme = LexemeCursor_1.LexemeCursor.findLexemeAtLineColumn(sql, position);
99
+ if (!lexeme) {
100
+ throw new Error(ERROR_MESSAGES.noLexemeAtPosition);
101
+ }
102
+ // Validate that the lexeme is a valid alias
103
+ this.validateLexemeIsAlias(lexeme);
104
+ // Parse SQL to get AST
105
+ const query = SelectQueryParser_1.SelectQueryParser.parse(sql);
106
+ // Detect the scope containing this alias
107
+ const scope = this.detectAliasScope(sql, query, lexeme, options.scopeType);
108
+ // Find all references to this alias within the scope
109
+ const references = this.collectAliasReferences(scope, lexeme.value);
110
+ // Check for naming conflicts
111
+ const conflicts = this.checkNameConflicts(scope, newName, lexeme.value);
112
+ if (conflicts.length > 0) {
113
+ return {
114
+ success: false,
115
+ originalSql: sql,
116
+ changes: [],
117
+ conflicts,
118
+ scope
119
+ };
120
+ }
121
+ // Prepare changes
122
+ const changes = this.prepareChanges(references, newName);
123
+ // If dry run, return without making changes
124
+ if (options.dryRun) {
125
+ return {
126
+ success: true,
127
+ originalSql: sql,
128
+ changes,
129
+ conflicts,
130
+ scope
131
+ };
132
+ }
133
+ // Perform the actual renaming using lexeme-based approach for better accuracy
134
+ const newSql = this.performLexemeBasedRename(sql, lexeme.value, newName, scope);
135
+ return {
136
+ success: true,
137
+ originalSql: sql,
138
+ newSql,
139
+ changes,
140
+ scope
141
+ };
142
+ }
143
+ catch (error) {
144
+ return {
145
+ success: false,
146
+ originalSql: sql,
147
+ changes: [],
148
+ conflicts: [error instanceof Error ? error.message : String(error)]
149
+ };
150
+ }
151
+ }
152
+ /**
153
+ * Validates input parameters for alias renaming.
154
+ */
155
+ validateInputs(sql, position, newName) {
156
+ if (!sql || typeof sql !== 'string' || sql.trim() === '') {
157
+ throw new Error(ERROR_MESSAGES.invalidSql);
158
+ }
159
+ if (!position || typeof position.line !== 'number' || typeof position.column !== 'number' ||
160
+ position.line < 1 || position.column < 1) {
161
+ throw new Error(ERROR_MESSAGES.invalidPosition);
162
+ }
163
+ if (!newName || typeof newName !== 'string' || newName.trim() === '') {
164
+ throw new Error(ERROR_MESSAGES.invalidNewName);
165
+ }
166
+ }
167
+ /**
168
+ * Validates that the lexeme represents a valid alias.
169
+ */
170
+ validateLexemeIsAlias(lexeme) {
171
+ // Check if lexeme is an identifier (potential alias)
172
+ if (!(lexeme.type & Lexeme_1.TokenType.Identifier)) {
173
+ throw new Error(ERROR_MESSAGES.notAnAlias);
174
+ }
175
+ }
176
+ /**
177
+ * Detects the scope (CTE, subquery, main query) containing the alias.
178
+ */
179
+ detectAliasScope(sql, query, lexeme, scopeType) {
180
+ if (!lexeme.position) {
181
+ // Fallback to main query if no position info
182
+ return {
183
+ type: 'main',
184
+ query,
185
+ startPosition: 0,
186
+ endPosition: sql.length
187
+ };
188
+ }
189
+ const lexemePosition = lexeme.position.startPosition;
190
+ // Force specific scope type if requested
191
+ if (scopeType && scopeType !== 'auto') {
192
+ return this.createScopeForType(scopeType, sql, query, lexemePosition);
193
+ }
194
+ // Auto-detect scope based on position
195
+ return this.autoDetectScope(sql, query, lexemePosition);
196
+ }
197
+ /**
198
+ * Creates scope for a specific requested type.
199
+ */
200
+ createScopeForType(scopeType, sql, query, position) {
201
+ switch (scopeType) {
202
+ case 'cte':
203
+ return this.detectCTEScope(sql, query, position);
204
+ case 'subquery':
205
+ return this.detectSubqueryScope(sql, query, position);
206
+ case 'main':
207
+ default:
208
+ return {
209
+ type: 'main',
210
+ query,
211
+ startPosition: 0,
212
+ endPosition: sql.length
213
+ };
214
+ }
215
+ }
216
+ /**
217
+ * Auto-detects the most appropriate scope based on cursor position.
218
+ */
219
+ autoDetectScope(sql, query, position) {
220
+ // First check if we're in a CTE
221
+ const cteScope = this.detectCTEScope(sql, query, position);
222
+ if (cteScope.type === 'cte') {
223
+ return cteScope;
224
+ }
225
+ // Then check for subqueries (implementation needed)
226
+ const subqueryScope = this.detectSubqueryScope(sql, query, position);
227
+ if (subqueryScope.type === 'subquery') {
228
+ return subqueryScope;
229
+ }
230
+ // Default to main query
231
+ return {
232
+ type: 'main',
233
+ query,
234
+ startPosition: 0,
235
+ endPosition: sql.length
236
+ };
237
+ }
238
+ /**
239
+ * Detects if the position is within a CTE and returns appropriate scope.
240
+ */
241
+ detectCTEScope(sql, query, position) {
242
+ try {
243
+ // Use CTERegionDetector to analyze cursor position
244
+ const analysis = CTERegionDetector_1.CTERegionDetector.analyzeCursorPosition(sql, position);
245
+ if (analysis.isInCTE && analysis.cteRegion) {
246
+ // Find the corresponding CTE query in the AST
247
+ const cteQuery = this.findCTEQueryByName(query, analysis.cteRegion.name);
248
+ return {
249
+ type: 'cte',
250
+ name: analysis.cteRegion.name,
251
+ query: cteQuery || query, // Fallback to main query if CTE not found
252
+ startPosition: analysis.cteRegion.startPosition,
253
+ endPosition: analysis.cteRegion.endPosition
254
+ };
255
+ }
256
+ }
257
+ catch (error) {
258
+ // If CTE detection fails, fall back to main query
259
+ console.warn('CTE scope detection failed:', error);
260
+ }
261
+ // Not in CTE, return main query scope
262
+ return {
263
+ type: 'main',
264
+ query,
265
+ startPosition: 0,
266
+ endPosition: sql.length
267
+ };
268
+ }
269
+ /**
270
+ * Detects if the position is within a subquery scope.
271
+ */
272
+ detectSubqueryScope(sql, query, position) {
273
+ // TODO: Implement subquery detection
274
+ // This would involve traversing the AST to find nested SELECT queries
275
+ // and determining if the position falls within their boundaries
276
+ // For now, return main query scope
277
+ return {
278
+ type: 'main',
279
+ query,
280
+ startPosition: 0,
281
+ endPosition: sql.length
282
+ };
283
+ }
284
+ /**
285
+ * Finds a CTE query by name within the parsed AST.
286
+ */
287
+ findCTEQueryByName(query, cteName) {
288
+ var _a;
289
+ if (query instanceof SelectQuery_1.SimpleSelectQuery && ((_a = query.withClause) === null || _a === void 0 ? void 0 : _a.tables)) {
290
+ for (const cte of query.withClause.tables) {
291
+ if (cte.aliasExpression.table.name === cteName) {
292
+ return cte.query;
293
+ }
294
+ }
295
+ }
296
+ else if (query instanceof SelectQuery_1.BinarySelectQuery) {
297
+ // Check left side first
298
+ const leftResult = this.findCTEQueryByName(query.left, cteName);
299
+ if (leftResult)
300
+ return leftResult;
301
+ // Then check right side
302
+ const rightResult = this.findCTEQueryByName(query.right, cteName);
303
+ if (rightResult)
304
+ return rightResult;
305
+ }
306
+ return null;
307
+ }
308
+ /**
309
+ * Collects all references to the specified alias within the given scope.
310
+ */
311
+ collectAliasReferences(scope, aliasName) {
312
+ const references = [];
313
+ try {
314
+ // Collect table source references (FROM, JOIN clauses)
315
+ const tableReferences = this.collectTableAliasReferences(scope, aliasName);
316
+ references.push(...tableReferences);
317
+ // Collect column references (table_alias.column format)
318
+ const columnReferences = this.collectColumnAliasReferences(scope, aliasName);
319
+ references.push(...columnReferences);
320
+ }
321
+ catch (error) {
322
+ console.warn(`Failed to collect alias references for '${aliasName}':`, error);
323
+ }
324
+ return references;
325
+ }
326
+ /**
327
+ * Collects table alias references within the scope.
328
+ */
329
+ collectTableAliasReferences(scope, aliasName) {
330
+ const references = [];
331
+ try {
332
+ // Use TableSourceCollector to find all table sources in the scope
333
+ const collector = new TableSourceCollector_1.TableSourceCollector(true); // selectableOnly=true for proper scope
334
+ const tableSources = collector.collect(scope.query);
335
+ for (const tableSource of tableSources) {
336
+ const sourceName = tableSource.getSourceName();
337
+ // Check if this table source matches our alias
338
+ if (sourceName === aliasName) {
339
+ // This is likely the definition of the alias (FROM users u, JOIN orders o)
340
+ const lexeme = this.createLexemeFromTableSource(tableSource, aliasName);
341
+ if (lexeme) {
342
+ references.push({
343
+ lexeme,
344
+ scope,
345
+ referenceType: 'definition',
346
+ context: 'table'
347
+ });
348
+ }
349
+ }
350
+ }
351
+ }
352
+ catch (error) {
353
+ console.warn(`Failed to collect table alias references for '${aliasName}':`, error);
354
+ }
355
+ return references;
356
+ }
357
+ /**
358
+ * Collects column alias references (table_alias.column format) within the scope.
359
+ */
360
+ collectColumnAliasReferences(scope, aliasName) {
361
+ const references = [];
362
+ try {
363
+ // Use ColumnReferenceCollector to find all column references
364
+ const collector = new ColumnReferenceCollector_1.ColumnReferenceCollector();
365
+ const columnRefs = collector.collect(scope.query);
366
+ for (const columnRef of columnRefs) {
367
+ // Check if any namespace in this column reference matches our alias
368
+ if (columnRef.namespaces && columnRef.namespaces.length > 0) {
369
+ for (const namespace of columnRef.namespaces) {
370
+ if (namespace.name === aliasName) {
371
+ // This is a usage of the alias (u.name, u.id, etc.)
372
+ const lexeme = this.createLexemeFromNamespace(namespace, aliasName);
373
+ if (lexeme) {
374
+ references.push({
375
+ lexeme,
376
+ scope,
377
+ referenceType: 'usage',
378
+ context: 'column'
379
+ });
380
+ }
381
+ }
382
+ }
383
+ }
384
+ }
385
+ }
386
+ catch (error) {
387
+ console.warn(`Failed to collect column alias references for '${aliasName}':`, error);
388
+ }
389
+ return references;
390
+ }
391
+ /**
392
+ * Creates a lexeme representation from a table source for reference tracking.
393
+ */
394
+ createLexemeFromTableSource(tableSource, aliasName) {
395
+ try {
396
+ // Try to extract position information from the table source
397
+ // This is a best-effort approach since TableSource might not have direct lexeme info
398
+ return {
399
+ type: Lexeme_1.TokenType.Identifier,
400
+ value: aliasName,
401
+ comments: null,
402
+ position: {
403
+ startPosition: 0, // TODO: Extract actual position if available
404
+ endPosition: aliasName.length
405
+ }
406
+ };
407
+ }
408
+ catch (error) {
409
+ console.warn('Failed to create lexeme from table source:', error);
410
+ return null;
411
+ }
412
+ }
413
+ /**
414
+ * Creates a lexeme representation from a namespace for reference tracking.
415
+ */
416
+ createLexemeFromNamespace(namespace, aliasName) {
417
+ try {
418
+ // Try to extract position information from the namespace
419
+ return {
420
+ type: Lexeme_1.TokenType.Identifier,
421
+ value: aliasName,
422
+ comments: null,
423
+ position: {
424
+ startPosition: 0, // TODO: Extract actual position if available
425
+ endPosition: aliasName.length
426
+ }
427
+ };
428
+ }
429
+ catch (error) {
430
+ console.warn('Failed to create lexeme from namespace:', error);
431
+ return null;
432
+ }
433
+ }
434
+ /**
435
+ * Checks for naming conflicts when renaming to the new name.
436
+ */
437
+ checkNameConflicts(scope, newName, currentName) {
438
+ const conflicts = [];
439
+ if (newName.toLowerCase() === currentName.toLowerCase()) {
440
+ conflicts.push(ERROR_MESSAGES.sameNames);
441
+ return conflicts;
442
+ }
443
+ try {
444
+ // Check for conflicts with existing table aliases
445
+ const tableConflicts = this.checkTableAliasConflicts(scope, newName);
446
+ conflicts.push(...tableConflicts);
447
+ // Check for conflicts with SQL keywords (basic check)
448
+ const keywordConflicts = this.checkKeywordConflicts(newName);
449
+ conflicts.push(...keywordConflicts);
450
+ }
451
+ catch (error) {
452
+ console.warn(`Error during conflict detection for '${newName}':`, error);
453
+ conflicts.push(`Unable to verify conflicts for name '${newName}'`);
454
+ }
455
+ return conflicts;
456
+ }
457
+ /**
458
+ * Checks for conflicts with existing table aliases and table names in the scope.
459
+ */
460
+ checkTableAliasConflicts(scope, newName) {
461
+ const conflicts = [];
462
+ try {
463
+ // Use TableSourceCollector to get all existing table sources in scope
464
+ const collector = new TableSourceCollector_1.TableSourceCollector(true);
465
+ const tableSources = collector.collect(scope.query);
466
+ for (const tableSource of tableSources) {
467
+ // Check alias conflicts
468
+ const aliasName = tableSource.getSourceName();
469
+ if (aliasName && aliasName.toLowerCase() === newName.toLowerCase()) {
470
+ conflicts.push(ERROR_MESSAGES.nameConflict(newName));
471
+ continue; // Avoid duplicate messages
472
+ }
473
+ // Check table name conflicts
474
+ const tableName = this.extractTableName(tableSource);
475
+ if (tableName && tableName.toLowerCase() === newName.toLowerCase()) {
476
+ conflicts.push(`'${newName}' conflicts with table name in this scope`);
477
+ }
478
+ }
479
+ }
480
+ catch (error) {
481
+ console.warn(`Failed to check table alias conflicts for '${newName}':`, error);
482
+ }
483
+ return conflicts;
484
+ }
485
+ /**
486
+ * Extracts the actual table name from a table source (not the alias).
487
+ */
488
+ extractTableName(tableSource) {
489
+ try {
490
+ // Try to access the qualified name to get the actual table name
491
+ if (tableSource.qualifiedName && tableSource.qualifiedName.name) {
492
+ const name = tableSource.qualifiedName.name;
493
+ // Handle different name types
494
+ if (typeof name === 'string') {
495
+ return name;
496
+ }
497
+ else if (name.name && typeof name.name === 'string') {
498
+ // IdentifierString case
499
+ return name.name;
500
+ }
501
+ else if (name.value && typeof name.value === 'string') {
502
+ // RawString case
503
+ return name.value;
504
+ }
505
+ }
506
+ // Fallback: try to get table name from other properties
507
+ if (tableSource.table && typeof tableSource.table === 'string') {
508
+ return tableSource.table;
509
+ }
510
+ return null;
511
+ }
512
+ catch (error) {
513
+ console.warn('Failed to extract table name from table source:', error);
514
+ return null;
515
+ }
516
+ }
517
+ /**
518
+ * Checks if the new name conflicts with SQL keywords using the existing KeywordTrie.
519
+ */
520
+ checkKeywordConflicts(newName) {
521
+ const conflicts = [];
522
+ // Use basic check as primary method for now to ensure test reliability
523
+ if (this.isBasicReservedKeyword(newName)) {
524
+ conflicts.push(`'${newName}' is a reserved SQL keyword and should not be used as an alias`);
525
+ return conflicts;
526
+ }
527
+ try {
528
+ // Use the KeywordParser to check if the new name is a reserved keyword
529
+ const keywordResult = this.keywordParser.parse(newName, 0);
530
+ if (keywordResult !== null && keywordResult.keyword.toLowerCase() === newName.toLowerCase()) {
531
+ conflicts.push(`'${newName}' is a reserved SQL keyword and should not be used as an alias`);
532
+ }
533
+ }
534
+ catch (error) {
535
+ console.warn(`Failed to check keyword conflicts for '${newName}':`, error);
536
+ }
537
+ return conflicts;
538
+ }
539
+ /**
540
+ * Fallback method for basic reserved keyword checking.
541
+ */
542
+ isBasicReservedKeyword(name) {
543
+ const basicKeywords = ['select', 'from', 'where', 'join', 'table', 'null', 'and', 'or'];
544
+ return basicKeywords.includes(name.toLowerCase());
545
+ }
546
+ /**
547
+ * Prepares change details for the rename operation.
548
+ */
549
+ prepareChanges(references, newName) {
550
+ return references.map(ref => {
551
+ var _a;
552
+ return ({
553
+ oldName: ref.lexeme.value,
554
+ newName,
555
+ position: LexemeCursor_1.LexemeCursor.charOffsetToLineColumn('', // TODO: Get original SQL
556
+ ((_a = ref.lexeme.position) === null || _a === void 0 ? void 0 : _a.startPosition) || 0) || { line: 1, column: 1 },
557
+ context: ref.context,
558
+ referenceType: ref.referenceType
559
+ });
560
+ });
561
+ }
562
+ /**
563
+ * Enhanced SQL text replacement using lexeme-based approach.
564
+ * This method re-tokenizes the SQL to get accurate position information.
565
+ */
566
+ performLexemeBasedRename(sql, aliasName, newName, scope) {
567
+ try {
568
+ // Get all lexemes with position information
569
+ const lexemes = LexemeCursor_1.LexemeCursor.getAllLexemesWithPosition(sql);
570
+ // Filter lexemes within the scope and matching the alias name
571
+ const targetLexemes = lexemes.filter(lexeme => lexeme.value === aliasName &&
572
+ lexeme.position &&
573
+ lexeme.position.startPosition >= scope.startPosition &&
574
+ lexeme.position.endPosition <= scope.endPosition &&
575
+ (lexeme.type & Lexeme_1.TokenType.Identifier) // Only rename identifiers
576
+ );
577
+ if (targetLexemes.length === 0) {
578
+ return sql; // No matches found
579
+ }
580
+ // Sort by position (descending) for safe replacement
581
+ targetLexemes.sort((a, b) => b.position.startPosition - a.position.startPosition);
582
+ let modifiedSql = sql;
583
+ // Replace each occurrence
584
+ for (const lexeme of targetLexemes) {
585
+ const pos = lexeme.position;
586
+ modifiedSql = modifiedSql.substring(0, pos.startPosition) +
587
+ newName +
588
+ modifiedSql.substring(pos.endPosition);
589
+ }
590
+ return modifiedSql;
591
+ }
592
+ catch (error) {
593
+ console.error('Failed to perform lexeme-based rename:', error);
594
+ throw new Error(`Unable to rename alias using lexeme approach: ${error instanceof Error ? error.message : String(error)}`);
595
+ }
596
+ }
597
+ }
598
+ exports.AliasRenamer = AliasRenamer;
599
+ //# sourceMappingURL=AliasRenamer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AliasRenamer.js","sourceRoot":"","sources":["../../../src/transformers/AliasRenamer.ts"],"names":[],"mappings":";;;AAAA,uDAA0F;AAC1F,wDAAiE;AACjE,6CAAqD;AACrD,oEAAiE;AACjE,kEAA+D;AAC/D,iEAA8D;AAC9D,yEAAsE;AACtE,4DAAyD;AACzD,2EAAwE;AAuDxE;;GAEG;AACH,MAAM,cAAc,GAAG;IACnB,UAAU,EAAE,oCAAoC;IAChD,eAAe,EAAE,gDAAgD;IACjE,kBAAkB,EAAE,2CAA2C;IAC/D,UAAU,EAAE,sCAAsC;IAClD,cAAc,EAAE,2CAA2C;IAC3D,SAAS,EAAE,4CAA4C;IACvD,YAAY,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,UAAU,IAAI,gCAAgC;I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