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