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.
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +37 -29
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/src/formatters/OriginalFormatRestorer.d.ts +40 -0
- package/dist/esm/src/formatters/OriginalFormatRestorer.js +135 -0
- package/dist/esm/src/formatters/OriginalFormatRestorer.js.map +1 -0
- package/dist/esm/src/index.d.ts +11 -0
- package/dist/esm/src/index.js +9 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/models/FormattingLexeme.d.ts +66 -0
- package/dist/esm/src/models/FormattingLexeme.js +2 -0
- package/dist/esm/src/models/FormattingLexeme.js.map +1 -0
- package/dist/esm/src/models/ValueComponent.d.ts +3 -1
- package/dist/esm/src/models/ValueComponent.js +3 -1
- package/dist/esm/src/models/ValueComponent.js.map +1 -1
- package/dist/esm/src/parsers/FunctionExpressionParser.d.ts +12 -0
- package/dist/esm/src/parsers/FunctionExpressionParser.js +111 -7
- package/dist/esm/src/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/esm/src/parsers/KeywordParser.d.ts +1 -0
- package/dist/esm/src/parsers/KeywordParser.js +10 -4
- package/dist/esm/src/parsers/KeywordParser.js.map +1 -1
- package/dist/esm/src/parsers/SqlPrintTokenParser.js +8 -0
- package/dist/esm/src/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/esm/src/parsers/SqlTokenizer.d.ts +42 -2
- package/dist/esm/src/parsers/SqlTokenizer.js +213 -12
- package/dist/esm/src/parsers/SqlTokenizer.js.map +1 -1
- package/dist/esm/src/tokenReaders/CommandTokenReader.d.ts +3 -0
- package/dist/esm/src/tokenReaders/CommandTokenReader.js +4 -1
- package/dist/esm/src/tokenReaders/CommandTokenReader.js.map +1 -1
- package/dist/esm/src/transformers/AliasRenamer.d.ts +199 -0
- package/dist/esm/src/transformers/AliasRenamer.js +595 -0
- package/dist/esm/src/transformers/AliasRenamer.js.map +1 -0
- package/dist/esm/src/transformers/CTERenamer.d.ts +53 -0
- package/dist/esm/src/transformers/CTERenamer.js +138 -0
- package/dist/esm/src/transformers/CTERenamer.js.map +1 -1
- package/dist/esm/src/transformers/DynamicQueryBuilder.d.ts +72 -0
- package/dist/esm/src/transformers/DynamicQueryBuilder.js +42 -0
- package/dist/esm/src/transformers/DynamicQueryBuilder.js.map +1 -1
- package/dist/esm/src/transformers/FilterableItemCollector.d.ts +80 -0
- package/dist/esm/src/transformers/FilterableItemCollector.js +254 -0
- package/dist/esm/src/transformers/FilterableItemCollector.js.map +1 -0
- package/dist/esm/src/transformers/SelectableColumnCollector.d.ts +3 -0
- package/dist/esm/src/transformers/SelectableColumnCollector.js +68 -7
- package/dist/esm/src/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/esm/src/transformers/SmartRenamer.d.ts +134 -0
- package/dist/esm/src/transformers/SmartRenamer.js +430 -0
- package/dist/esm/src/transformers/SmartRenamer.js.map +1 -0
- package/dist/esm/src/transformers/SqlIdentifierRenamer.d.ts +150 -0
- package/dist/esm/src/transformers/SqlIdentifierRenamer.js +493 -0
- package/dist/esm/src/transformers/SqlIdentifierRenamer.js.map +1 -0
- package/dist/esm/src/transformers/SqlParamInjector.d.ts +27 -0
- package/dist/esm/src/transformers/SqlParamInjector.js +304 -16
- package/dist/esm/src/transformers/SqlParamInjector.js.map +1 -1
- package/dist/esm/src/transformers/SqlSortInjector.js +6 -3
- package/dist/esm/src/transformers/SqlSortInjector.js.map +1 -1
- package/dist/esm/src/transformers/UpstreamSelectQueryFinder.js +5 -2
- package/dist/esm/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/dist/esm/src/utils/LexemeCursor.d.ts +41 -0
- package/dist/esm/src/utils/LexemeCursor.js +93 -0
- package/dist/esm/src/utils/LexemeCursor.js.map +1 -1
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/index.min.js +37 -29
- package/dist/index.min.js.map +4 -4
- package/dist/src/formatters/OriginalFormatRestorer.d.ts +40 -0
- package/dist/src/formatters/OriginalFormatRestorer.js +139 -0
- package/dist/src/formatters/OriginalFormatRestorer.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +11 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/FormattingLexeme.d.ts +66 -0
- package/dist/src/models/FormattingLexeme.js +3 -0
- package/dist/src/models/FormattingLexeme.js.map +1 -0
- package/dist/src/models/ValueComponent.d.ts +3 -1
- package/dist/src/models/ValueComponent.js +3 -1
- package/dist/src/models/ValueComponent.js.map +1 -1
- package/dist/src/parsers/FunctionExpressionParser.d.ts +12 -0
- package/dist/src/parsers/FunctionExpressionParser.js +110 -6
- package/dist/src/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/src/parsers/KeywordParser.d.ts +1 -0
- package/dist/src/parsers/KeywordParser.js +10 -4
- package/dist/src/parsers/KeywordParser.js.map +1 -1
- package/dist/src/parsers/SqlPrintTokenParser.js +8 -0
- package/dist/src/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/src/parsers/SqlTokenizer.d.ts +42 -2
- package/dist/src/parsers/SqlTokenizer.js +222 -12
- package/dist/src/parsers/SqlTokenizer.js.map +1 -1
- package/dist/src/tokenReaders/CommandTokenReader.d.ts +3 -0
- package/dist/src/tokenReaders/CommandTokenReader.js +5 -2
- package/dist/src/tokenReaders/CommandTokenReader.js.map +1 -1
- package/dist/src/transformers/AliasRenamer.d.ts +199 -0
- package/dist/src/transformers/AliasRenamer.js +599 -0
- package/dist/src/transformers/AliasRenamer.js.map +1 -0
- package/dist/src/transformers/CTERenamer.d.ts +53 -0
- package/dist/src/transformers/CTERenamer.js +138 -0
- package/dist/src/transformers/CTERenamer.js.map +1 -1
- package/dist/src/transformers/DynamicQueryBuilder.d.ts +72 -0
- package/dist/src/transformers/DynamicQueryBuilder.js +42 -0
- package/dist/src/transformers/DynamicQueryBuilder.js.map +1 -1
- package/dist/src/transformers/FilterableItemCollector.d.ts +80 -0
- package/dist/src/transformers/FilterableItemCollector.js +259 -0
- package/dist/src/transformers/FilterableItemCollector.js.map +1 -0
- package/dist/src/transformers/SelectableColumnCollector.d.ts +3 -0
- package/dist/src/transformers/SelectableColumnCollector.js +67 -6
- package/dist/src/transformers/SelectableColumnCollector.js.map +1 -1
- package/dist/src/transformers/SmartRenamer.d.ts +134 -0
- package/dist/src/transformers/SmartRenamer.js +442 -0
- package/dist/src/transformers/SmartRenamer.js.map +1 -0
- package/dist/src/transformers/SqlIdentifierRenamer.d.ts +150 -0
- package/dist/src/transformers/SqlIdentifierRenamer.js +497 -0
- package/dist/src/transformers/SqlIdentifierRenamer.js.map +1 -0
- package/dist/src/transformers/SqlParamInjector.d.ts +27 -0
- package/dist/src/transformers/SqlParamInjector.js +303 -15
- package/dist/src/transformers/SqlParamInjector.js.map +1 -1
- package/dist/src/transformers/SqlSortInjector.js +5 -2
- package/dist/src/transformers/SqlSortInjector.js.map +1 -1
- package/dist/src/transformers/UpstreamSelectQueryFinder.js +4 -1
- package/dist/src/transformers/UpstreamSelectQueryFinder.js.map +1 -1
- package/dist/src/utils/LexemeCursor.d.ts +41 -0
- package/dist/src/utils/LexemeCursor.js +93 -0
- package/dist/src/utils/LexemeCursor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -0,0 +1,493 @@
|
|
1
|
+
/**
|
2
|
+
* Handles safe renaming of SQL identifiers within SQL strings
|
3
|
+
* Uses character-by-character parsing instead of regex for better performance and maintainability
|
4
|
+
*/
|
5
|
+
export class SqlIdentifierRenamer {
|
6
|
+
/**
|
7
|
+
* Safely renames identifiers in SQL string while preserving context
|
8
|
+
* @param sql SQL string to modify
|
9
|
+
* @param renames Map of original identifiers to new identifiers
|
10
|
+
* @returns Modified SQL string with renamed identifiers
|
11
|
+
*/
|
12
|
+
renameIdentifiers(sql, renames) {
|
13
|
+
if (renames.size === 0) {
|
14
|
+
return sql;
|
15
|
+
}
|
16
|
+
let result = sql;
|
17
|
+
// Apply all renames
|
18
|
+
for (const [originalValue, newValue] of renames) {
|
19
|
+
result = this.replaceIdentifierSafely(result, originalValue, newValue);
|
20
|
+
}
|
21
|
+
return result;
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* Renames a single identifier in SQL string
|
25
|
+
* @param sql SQL string to modify
|
26
|
+
* @param oldIdentifier Original identifier to replace
|
27
|
+
* @param newIdentifier New identifier to replace with
|
28
|
+
* @returns Modified SQL string
|
29
|
+
*/
|
30
|
+
renameIdentifier(sql, oldIdentifier, newIdentifier) {
|
31
|
+
return this.replaceIdentifierSafely(sql, oldIdentifier, newIdentifier);
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Renames a single identifier within a specified scope range
|
35
|
+
* @param sql SQL string to modify
|
36
|
+
* @param oldIdentifier Original identifier to replace
|
37
|
+
* @param newIdentifier New identifier to replace with
|
38
|
+
* @param scopeRange Optional scope range to limit replacement
|
39
|
+
* @returns Modified SQL string
|
40
|
+
*/
|
41
|
+
renameIdentifierInScope(sql, oldIdentifier, newIdentifier, scopeRange) {
|
42
|
+
if (!scopeRange) {
|
43
|
+
// Fallback to full SQL replacement
|
44
|
+
return this.replaceIdentifierSafely(sql, oldIdentifier, newIdentifier);
|
45
|
+
}
|
46
|
+
// Extract the portion of SQL within scope range
|
47
|
+
const beforeScope = sql.slice(0, scopeRange.start);
|
48
|
+
const scopeContent = sql.slice(scopeRange.start, scopeRange.end);
|
49
|
+
const afterScope = sql.slice(scopeRange.end);
|
50
|
+
// Replace identifiers only within the scope
|
51
|
+
const modifiedScopeContent = this.replaceIdentifierSafely(scopeContent, oldIdentifier, newIdentifier);
|
52
|
+
// Reconstruct the full SQL
|
53
|
+
return beforeScope + modifiedScopeContent + afterScope;
|
54
|
+
}
|
55
|
+
/**
|
56
|
+
* Checks if an identifier at the given position can be renamed
|
57
|
+
* @param sql SQL string
|
58
|
+
* @param position Position in the SQL text
|
59
|
+
* @returns Renameability result
|
60
|
+
*/
|
61
|
+
checkRenameability(sql, position) {
|
62
|
+
// Convert line/column to character position
|
63
|
+
const charPosition = this.positionToCharIndex(sql, position);
|
64
|
+
// TODO: Implement proper identifier detection and scope analysis
|
65
|
+
// For now, minimal implementation to make tests pass
|
66
|
+
// Simple detection - if we're in a string literal, not renameable
|
67
|
+
if (this.isInsideStringLiteral(sql, charPosition)) {
|
68
|
+
return {
|
69
|
+
canRename: false,
|
70
|
+
reason: 'Cannot rename identifiers inside string literal'
|
71
|
+
};
|
72
|
+
}
|
73
|
+
// Detect if we're on an identifier (simplified)
|
74
|
+
const identifier = this.getIdentifierAtPosition(sql, charPosition);
|
75
|
+
if (!identifier) {
|
76
|
+
return {
|
77
|
+
canRename: false,
|
78
|
+
reason: 'No identifier found at position'
|
79
|
+
};
|
80
|
+
}
|
81
|
+
// Determine type and scope (simplified logic)
|
82
|
+
const type = this.determineIdentifierType(sql, charPosition, identifier);
|
83
|
+
const scopeRange = this.calculateScopeRange(sql, charPosition, type);
|
84
|
+
return {
|
85
|
+
canRename: true,
|
86
|
+
currentName: identifier,
|
87
|
+
type: type,
|
88
|
+
scopeRange: scopeRange
|
89
|
+
};
|
90
|
+
}
|
91
|
+
/**
|
92
|
+
* Renames identifier at the specified position
|
93
|
+
* @param sql SQL string
|
94
|
+
* @param position Position in the SQL text
|
95
|
+
* @param newName New identifier name
|
96
|
+
* @returns Modified SQL string
|
97
|
+
*/
|
98
|
+
renameAtPosition(sql, position, newName) {
|
99
|
+
const renameability = this.checkRenameability(sql, position);
|
100
|
+
if (!renameability.canRename || !renameability.currentName) {
|
101
|
+
throw new Error(renameability.reason || 'Cannot rename at this position');
|
102
|
+
}
|
103
|
+
return this.renameIdentifierInScope(sql, renameability.currentName, newName, renameability.scopeRange);
|
104
|
+
}
|
105
|
+
/**
|
106
|
+
* Convert line/column position to character index
|
107
|
+
*/
|
108
|
+
positionToCharIndex(sql, position) {
|
109
|
+
const lines = sql.split('\n');
|
110
|
+
let charIndex = 0;
|
111
|
+
for (let i = 0; i < position.line - 1 && i < lines.length; i++) {
|
112
|
+
charIndex += lines[i].length + 1; // +1 for newline
|
113
|
+
}
|
114
|
+
charIndex += position.column - 1;
|
115
|
+
return Math.min(charIndex, sql.length - 1);
|
116
|
+
}
|
117
|
+
/**
|
118
|
+
* Check if position is inside a string literal
|
119
|
+
*/
|
120
|
+
isInsideStringLiteral(sql, charPosition) {
|
121
|
+
// Simple check - count single quotes before position
|
122
|
+
let inString = false;
|
123
|
+
for (let i = 0; i < charPosition && i < sql.length; i++) {
|
124
|
+
if (sql[i] === "'") {
|
125
|
+
inString = !inString;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
return inString;
|
129
|
+
}
|
130
|
+
/**
|
131
|
+
* Get identifier at the specified character position
|
132
|
+
*/
|
133
|
+
getIdentifierAtPosition(sql, charPosition) {
|
134
|
+
if (charPosition >= sql.length)
|
135
|
+
return null;
|
136
|
+
// Find start of identifier
|
137
|
+
let start = charPosition;
|
138
|
+
while (start > 0 && this.isIdentifierChar(sql.charCodeAt(start - 1))) {
|
139
|
+
start--;
|
140
|
+
}
|
141
|
+
// Find end of identifier
|
142
|
+
let end = charPosition;
|
143
|
+
while (end < sql.length && this.isIdentifierChar(sql.charCodeAt(end))) {
|
144
|
+
end++;
|
145
|
+
}
|
146
|
+
if (start === end)
|
147
|
+
return null;
|
148
|
+
return sql.slice(start, end);
|
149
|
+
}
|
150
|
+
/**
|
151
|
+
* Determine the type of identifier (improved logic)
|
152
|
+
*/
|
153
|
+
determineIdentifierType(sql, charPosition, identifier) {
|
154
|
+
const beforePosition = sql.slice(0, charPosition);
|
155
|
+
const afterPosition = sql.slice(charPosition);
|
156
|
+
// Check if this is a CTE name (appears between WITH and AS)
|
157
|
+
const beforeUpper = beforePosition.toUpperCase();
|
158
|
+
const afterUpper = afterPosition.toUpperCase();
|
159
|
+
// Find last WITH before our position
|
160
|
+
const lastWithIndex = beforeUpper.lastIndexOf('WITH');
|
161
|
+
if (lastWithIndex !== -1) {
|
162
|
+
// Get the identifier bounds
|
163
|
+
let start = charPosition;
|
164
|
+
while (start > 0 && this.isIdentifierChar(sql.charCodeAt(start - 1))) {
|
165
|
+
start--;
|
166
|
+
}
|
167
|
+
let end = charPosition;
|
168
|
+
while (end < sql.length && this.isIdentifierChar(sql.charCodeAt(end))) {
|
169
|
+
end++;
|
170
|
+
}
|
171
|
+
// Check what comes after the complete identifier
|
172
|
+
const afterIdentifier = sql.slice(end).toUpperCase();
|
173
|
+
// CTE pattern: WITH identifier AS (
|
174
|
+
if (afterIdentifier.trim().startsWith('AS (')) {
|
175
|
+
return 'cte';
|
176
|
+
}
|
177
|
+
}
|
178
|
+
// Check if this appears after FROM or JOIN (table alias)
|
179
|
+
const beforeLines = beforePosition.split('\n');
|
180
|
+
const currentLine = beforeLines[beforeLines.length - 1].toUpperCase();
|
181
|
+
if (currentLine.includes('FROM ') || currentLine.includes('JOIN ')) {
|
182
|
+
return 'table_alias';
|
183
|
+
}
|
184
|
+
// Check context around the identifier for table alias patterns
|
185
|
+
const contextBefore = beforePosition.slice(Math.max(0, charPosition - 50));
|
186
|
+
const contextAfter = afterPosition.slice(0, 50);
|
187
|
+
const fullContext = (contextBefore + identifier + contextAfter).toUpperCase();
|
188
|
+
// Table alias patterns: "FROM table AS alias" or "JOIN table alias"
|
189
|
+
if (fullContext.includes(' AS ' + identifier.toUpperCase()) ||
|
190
|
+
fullContext.includes(' ' + identifier.toUpperCase() + ' ON') ||
|
191
|
+
fullContext.includes(' ' + identifier.toUpperCase() + '\n')) {
|
192
|
+
return 'table_alias';
|
193
|
+
}
|
194
|
+
// Default to table alias if uncertain
|
195
|
+
return 'table_alias';
|
196
|
+
}
|
197
|
+
/**
|
198
|
+
* Calculate scope range for the identifier
|
199
|
+
*/
|
200
|
+
calculateScopeRange(sql, charPosition, type) {
|
201
|
+
if (type === 'cte') {
|
202
|
+
// CTE has global scope
|
203
|
+
return { start: 0, end: sql.length };
|
204
|
+
}
|
205
|
+
// Table alias - find the containing SELECT statement (simplified)
|
206
|
+
// This is a very basic implementation
|
207
|
+
const beforePosition = sql.slice(0, charPosition);
|
208
|
+
const afterPosition = sql.slice(charPosition);
|
209
|
+
// Find the start of current SELECT
|
210
|
+
const lastSelect = beforePosition.toUpperCase().lastIndexOf('SELECT');
|
211
|
+
const start = lastSelect !== -1 ? lastSelect : 0;
|
212
|
+
// Find the end (next major clause or end of SQL)
|
213
|
+
const nextMajorClause = afterPosition.search(/\b(SELECT|WITH|UNION)\b/i);
|
214
|
+
const end = nextMajorClause !== -1 ? charPosition + nextMajorClause : sql.length;
|
215
|
+
return { start, end };
|
216
|
+
}
|
217
|
+
/**
|
218
|
+
* Safely replaces SQL identifiers while preserving word boundaries and context
|
219
|
+
* Uses character-by-character parsing instead of regex for better maintainability
|
220
|
+
* @param sql SQL string to modify
|
221
|
+
* @param oldIdentifier Original identifier to replace
|
222
|
+
* @param newIdentifier New identifier to replace with
|
223
|
+
* @returns Modified SQL string
|
224
|
+
*/
|
225
|
+
replaceIdentifierSafely(sql, oldIdentifier, newIdentifier) {
|
226
|
+
if (oldIdentifier === newIdentifier || oldIdentifier.length === 0) {
|
227
|
+
return sql;
|
228
|
+
}
|
229
|
+
const result = [];
|
230
|
+
let position = 0;
|
231
|
+
const sqlLength = sql.length;
|
232
|
+
const oldIdLength = oldIdentifier.length;
|
233
|
+
while (position < sqlLength) {
|
234
|
+
const char = sql[position];
|
235
|
+
const charCode = char.charCodeAt(0);
|
236
|
+
// Handle quoted identifiers - check for identifier matches within quotes
|
237
|
+
if (charCode === 34 || charCode === 96 || charCode === 91) { // " ` [
|
238
|
+
const { content, nextPosition } = this.extractAndReplaceQuotedIdentifier(sql, position, char, oldIdentifier, newIdentifier);
|
239
|
+
result.push(content);
|
240
|
+
position = nextPosition;
|
241
|
+
continue;
|
242
|
+
}
|
243
|
+
// Skip string literals (only single quotes are actual string literals)
|
244
|
+
if (charCode === 39) { // '
|
245
|
+
const { content, nextPosition } = this.extractQuotedString(sql, position, char);
|
246
|
+
result.push(content);
|
247
|
+
position = nextPosition;
|
248
|
+
continue;
|
249
|
+
}
|
250
|
+
// Skip line comments --
|
251
|
+
if (charCode === 45 && position + 1 < sqlLength && sql.charCodeAt(position + 1) === 45) {
|
252
|
+
const { content, nextPosition } = this.extractLineComment(sql, position);
|
253
|
+
result.push(content);
|
254
|
+
position = nextPosition;
|
255
|
+
continue;
|
256
|
+
}
|
257
|
+
// Skip block comments
|
258
|
+
if (charCode === 47 && position + 1 < sqlLength && sql.charCodeAt(position + 1) === 42) {
|
259
|
+
const { content, nextPosition } = this.extractBlockComment(sql, position);
|
260
|
+
result.push(content);
|
261
|
+
position = nextPosition;
|
262
|
+
continue;
|
263
|
+
}
|
264
|
+
// Check for potential identifier match
|
265
|
+
if (this.isIdentifierStartChar(charCode) && this.matchesIdentifierAt(sql, position, oldIdentifier)) {
|
266
|
+
const beforePosition = position - 1;
|
267
|
+
const afterPosition = position + oldIdLength;
|
268
|
+
// Validate word boundaries
|
269
|
+
const beforeChar = beforePosition >= 0 ? sql[beforePosition] : null;
|
270
|
+
const afterChar = afterPosition < sqlLength ? sql[afterPosition] : null;
|
271
|
+
if (this.hasValidWordBoundaries(beforeChar, afterChar)) {
|
272
|
+
result.push(newIdentifier);
|
273
|
+
position += oldIdLength;
|
274
|
+
continue;
|
275
|
+
}
|
276
|
+
}
|
277
|
+
// Default: add current character
|
278
|
+
result.push(char);
|
279
|
+
position++;
|
280
|
+
}
|
281
|
+
return result.join('');
|
282
|
+
}
|
283
|
+
/**
|
284
|
+
* Validates that the rename operation was successful
|
285
|
+
* @param originalSql Original SQL string
|
286
|
+
* @param modifiedSql Modified SQL string after rename
|
287
|
+
* @param oldIdentifier Old identifier that was replaced
|
288
|
+
* @param newIdentifier New identifier that was added
|
289
|
+
* @returns True if rename appears successful
|
290
|
+
*/
|
291
|
+
validateRename(originalSql, modifiedSql, oldIdentifier, newIdentifier) {
|
292
|
+
// Basic validation: modified SQL should be different from original
|
293
|
+
if (originalSql === modifiedSql) {
|
294
|
+
return false;
|
295
|
+
}
|
296
|
+
// The new identifier should appear in the result
|
297
|
+
if (!modifiedSql.includes(newIdentifier)) {
|
298
|
+
return false;
|
299
|
+
}
|
300
|
+
// The modified SQL should have fewer occurrences of the old identifier than the original
|
301
|
+
const originalOccurrences = this.countWordOccurrences(originalSql, oldIdentifier);
|
302
|
+
const modifiedOccurrences = this.countWordOccurrences(modifiedSql, oldIdentifier);
|
303
|
+
return modifiedOccurrences < originalOccurrences;
|
304
|
+
}
|
305
|
+
/**
|
306
|
+
* Extract and potentially replace quoted identifiers
|
307
|
+
*/
|
308
|
+
extractAndReplaceQuotedIdentifier(sql, startPosition, quoteChar, oldIdentifier, newIdentifier) {
|
309
|
+
if (quoteChar === '[') {
|
310
|
+
return this.extractAndReplaceBracketedIdentifier(sql, startPosition, oldIdentifier, newIdentifier);
|
311
|
+
}
|
312
|
+
const result = [quoteChar];
|
313
|
+
let position = startPosition + 1;
|
314
|
+
const identifierStart = position;
|
315
|
+
while (position < sql.length) {
|
316
|
+
const char = sql[position];
|
317
|
+
if (char === quoteChar) {
|
318
|
+
// Check for escaped quotes (double quotes)
|
319
|
+
if (position + 1 < sql.length && sql[position + 1] === quoteChar) {
|
320
|
+
result.push(char);
|
321
|
+
result.push(sql[position + 1]);
|
322
|
+
position += 2;
|
323
|
+
continue;
|
324
|
+
}
|
325
|
+
// Extract the content within quotes and check for identifier match
|
326
|
+
const quotedContent = sql.slice(identifierStart, position);
|
327
|
+
if (quotedContent.toLowerCase() === oldIdentifier.toLowerCase()) {
|
328
|
+
result.push(newIdentifier);
|
329
|
+
}
|
330
|
+
else {
|
331
|
+
result.push(quotedContent);
|
332
|
+
}
|
333
|
+
result.push(char); // closing quote
|
334
|
+
break;
|
335
|
+
}
|
336
|
+
position++;
|
337
|
+
}
|
338
|
+
return { content: result.join(''), nextPosition: position + 1 };
|
339
|
+
}
|
340
|
+
/**
|
341
|
+
* Extract and potentially replace bracketed identifiers [identifier]
|
342
|
+
*/
|
343
|
+
extractAndReplaceBracketedIdentifier(sql, startPosition, oldIdentifier, newIdentifier) {
|
344
|
+
const result = ['['];
|
345
|
+
let position = startPosition + 1;
|
346
|
+
const identifierStart = position;
|
347
|
+
while (position < sql.length) {
|
348
|
+
const char = sql[position];
|
349
|
+
if (char === ']') {
|
350
|
+
// Extract the content within brackets and check for identifier match
|
351
|
+
const bracketedContent = sql.slice(identifierStart, position);
|
352
|
+
if (bracketedContent.toLowerCase() === oldIdentifier.toLowerCase()) {
|
353
|
+
result.push(newIdentifier);
|
354
|
+
}
|
355
|
+
else {
|
356
|
+
result.push(bracketedContent);
|
357
|
+
}
|
358
|
+
result.push(char); // closing bracket
|
359
|
+
break;
|
360
|
+
}
|
361
|
+
position++;
|
362
|
+
}
|
363
|
+
return { content: result.join(''), nextPosition: position + 1 };
|
364
|
+
}
|
365
|
+
/**
|
366
|
+
* Extract quoted string (handles quotes)
|
367
|
+
*/
|
368
|
+
extractQuotedString(sql, startPosition, quoteChar) {
|
369
|
+
const result = [quoteChar];
|
370
|
+
let position = startPosition + 1;
|
371
|
+
while (position < sql.length) {
|
372
|
+
const char = sql[position];
|
373
|
+
result.push(char);
|
374
|
+
if (char === quoteChar) {
|
375
|
+
// Check for escaped quotes (double quotes)
|
376
|
+
if (position + 1 < sql.length && sql[position + 1] === quoteChar) {
|
377
|
+
result.push(sql[position + 1]);
|
378
|
+
position += 2;
|
379
|
+
continue;
|
380
|
+
}
|
381
|
+
break;
|
382
|
+
}
|
383
|
+
position++;
|
384
|
+
}
|
385
|
+
return { content: result.join(''), nextPosition: position + 1 };
|
386
|
+
}
|
387
|
+
/**
|
388
|
+
* Extract line comment
|
389
|
+
*/
|
390
|
+
extractLineComment(sql, startPosition) {
|
391
|
+
const result = [];
|
392
|
+
let position = startPosition;
|
393
|
+
while (position < sql.length && sql.charCodeAt(position) !== 10 && sql.charCodeAt(position) !== 13) {
|
394
|
+
result.push(sql[position]);
|
395
|
+
position++;
|
396
|
+
}
|
397
|
+
// Include the newline if present
|
398
|
+
if (position < sql.length && (sql.charCodeAt(position) === 10 || sql.charCodeAt(position) === 13)) {
|
399
|
+
result.push(sql[position]);
|
400
|
+
position++;
|
401
|
+
}
|
402
|
+
return { content: result.join(''), nextPosition: position };
|
403
|
+
}
|
404
|
+
/**
|
405
|
+
* Extract block comment
|
406
|
+
*/
|
407
|
+
extractBlockComment(sql, startPosition) {
|
408
|
+
const result = ['/', '*'];
|
409
|
+
let position = startPosition + 2;
|
410
|
+
while (position < sql.length - 1) {
|
411
|
+
const char = sql[position];
|
412
|
+
result.push(char);
|
413
|
+
if (char === '*' && sql[position + 1] === '/') {
|
414
|
+
result.push('/');
|
415
|
+
position += 2;
|
416
|
+
break;
|
417
|
+
}
|
418
|
+
position++;
|
419
|
+
}
|
420
|
+
return { content: result.join(''), nextPosition: position };
|
421
|
+
}
|
422
|
+
/**
|
423
|
+
* Check if character code can start an identifier
|
424
|
+
*/
|
425
|
+
isIdentifierStartChar(charCode) {
|
426
|
+
return (charCode >= 65 && charCode <= 90) || // A-Z
|
427
|
+
(charCode >= 97 && charCode <= 122) || // a-z
|
428
|
+
(charCode === 95); // _
|
429
|
+
}
|
430
|
+
/**
|
431
|
+
* Check if character code can be part of an identifier
|
432
|
+
*/
|
433
|
+
isIdentifierChar(charCode) {
|
434
|
+
return (charCode >= 65 && charCode <= 90) || // A-Z
|
435
|
+
(charCode >= 97 && charCode <= 122) || // a-z
|
436
|
+
(charCode >= 48 && charCode <= 57) || // 0-9
|
437
|
+
(charCode === 95); // _
|
438
|
+
}
|
439
|
+
/**
|
440
|
+
* Check if the identifier matches at the given position (case-insensitive)
|
441
|
+
*/
|
442
|
+
matchesIdentifierAt(sql, position, identifier) {
|
443
|
+
if (position + identifier.length > sql.length) {
|
444
|
+
return false;
|
445
|
+
}
|
446
|
+
// Case-insensitive comparison
|
447
|
+
for (let i = 0; i < identifier.length; i++) {
|
448
|
+
const sqlChar = sql.charCodeAt(position + i);
|
449
|
+
const idChar = identifier.charCodeAt(i);
|
450
|
+
// Convert both to lowercase for comparison
|
451
|
+
const sqlLower = sqlChar >= 65 && sqlChar <= 90 ? sqlChar + 32 : sqlChar;
|
452
|
+
const idLower = idChar >= 65 && idChar <= 90 ? idChar + 32 : idChar;
|
453
|
+
if (sqlLower !== idLower) {
|
454
|
+
return false;
|
455
|
+
}
|
456
|
+
}
|
457
|
+
return true;
|
458
|
+
}
|
459
|
+
/**
|
460
|
+
* Validate word boundaries
|
461
|
+
*/
|
462
|
+
hasValidWordBoundaries(beforeChar, afterChar) {
|
463
|
+
const isValidBefore = beforeChar === null || !this.isIdentifierChar(beforeChar.charCodeAt(0));
|
464
|
+
const isValidAfter = afterChar === null || !this.isIdentifierChar(afterChar.charCodeAt(0));
|
465
|
+
return isValidBefore && isValidAfter;
|
466
|
+
}
|
467
|
+
/**
|
468
|
+
* Counts word boundary occurrences of an identifier in SQL
|
469
|
+
* @param sql SQL string to search
|
470
|
+
* @param identifier Identifier to count
|
471
|
+
* @returns Number of occurrences
|
472
|
+
*/
|
473
|
+
countWordOccurrences(sql, identifier) {
|
474
|
+
let count = 0;
|
475
|
+
let position = 0;
|
476
|
+
const sqlLength = sql.length;
|
477
|
+
const idLength = identifier.length;
|
478
|
+
while (position <= sqlLength - idLength) {
|
479
|
+
if (this.matchesIdentifierAt(sql, position, identifier)) {
|
480
|
+
const beforePosition = position - 1;
|
481
|
+
const afterPosition = position + idLength;
|
482
|
+
const beforeChar = beforePosition >= 0 ? sql[beforePosition] : null;
|
483
|
+
const afterChar = afterPosition < sqlLength ? sql[afterPosition] : null;
|
484
|
+
if (this.hasValidWordBoundaries(beforeChar, afterChar)) {
|
485
|
+
count++;
|
486
|
+
}
|
487
|
+
}
|
488
|
+
position++;
|
489
|
+
}
|
490
|
+
return count;
|
491
|
+
}
|
492
|
+
}
|
493
|
+
//# sourceMappingURL=SqlIdentifierRenam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oBAAoB,CAAC,GAAW,EAAE,UAAkB;QACxD,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC;QAC7B,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC;QAEnC,OAAO,QAAQ,IAAI,SAAS,GAAG,QAAQ,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,mBAAmB,CAAC,GAAG,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,CAAC;gBACtD,MAAM,cAAc,GAAG,QAAQ,GAAG,CAAC,CAAC;gBACpC,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,CAAC;gBAE1C,MAAM,UAAU,GAAG,cAAc,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;gBACpE,MAAM,SAAS,GAAG,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;gBAExE,IAAI,IAAI,CAAC,sBAAsB,CAAC,UAAU,EAAE,SAAS,CAAC,EAAE,CAAC;oBACrD,KAAK,EAAE,CAAC;gBACZ,CAAC;YACL,CAAC;YACD,QAAQ,EAAE,CAAC;QACf,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ"}
|
@@ -44,6 +44,21 @@ export declare class SqlParamInjector {
|
|
44
44
|
* Type guard for objects that need operator validation
|
45
45
|
*/
|
46
46
|
private isValidatableObject;
|
47
|
+
/**
|
48
|
+
* Parses a qualified column name (table.column) into its components
|
49
|
+
* @param qualifiedName The qualified name (e.g., 'users.name' or 'name')
|
50
|
+
* @returns Object with table and column parts, or null if invalid
|
51
|
+
*/
|
52
|
+
private parseQualifiedColumnName;
|
53
|
+
/**
|
54
|
+
* Checks if a column name is qualified (contains a dot)
|
55
|
+
*/
|
56
|
+
private isQualifiedColumnName;
|
57
|
+
/**
|
58
|
+
* Sanitizes parameter names by replacing dots with underscores
|
59
|
+
* This ensures qualified names like 'users.name' become 'users_name' as parameter names
|
60
|
+
*/
|
61
|
+
private sanitizeParameterName;
|
47
62
|
/**
|
48
63
|
* Type guard for column mapping presence
|
49
64
|
*/
|
@@ -56,6 +71,10 @@ export declare class SqlParamInjector {
|
|
56
71
|
* Processes a single state parameter
|
57
72
|
*/
|
58
73
|
private processStateParameter;
|
74
|
+
/**
|
75
|
+
* Processes unqualified parameters, respecting qualified parameter overrides
|
76
|
+
*/
|
77
|
+
private processUnqualifiedParameter;
|
59
78
|
/**
|
60
79
|
* Processes regular column conditions (non-logical, non-explicit)
|
61
80
|
*/
|
@@ -76,6 +95,14 @@ export declare class SqlParamInjector {
|
|
76
95
|
* Recursively collects columns from any SelectQuery type
|
77
96
|
*/
|
78
97
|
private collectColumnsFromSelectQuery;
|
98
|
+
/**
|
99
|
+
* Builds a mapping between table aliases and real table names for enhanced qualified name resolution
|
100
|
+
*/
|
101
|
+
private buildTableMapping;
|
102
|
+
/**
|
103
|
+
* Helper method to process a single SourceExpression for table mapping
|
104
|
+
*/
|
105
|
+
private processSourceForMapping;
|
79
106
|
}
|
80
107
|
type BaseCondition = {
|
81
108
|
'='?: number | string | boolean | Date;
|