rawsql-ts 0.11.25-beta → 0.11.26-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 +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +14 -14
- package/dist/esm/index.min.js.map +3 -3
- package/dist/esm/src/index.d.ts +1 -0
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/transformers/JoinAggregationDecomposer.d.ts +188 -0
- package/dist/esm/src/transformers/JoinAggregationDecomposer.js +490 -0
- package/dist/esm/src/transformers/JoinAggregationDecomposer.js.map +1 -0
- package/dist/esm/src/transformers/QueryBuilder.d.ts +22 -0
- package/dist/esm/src/transformers/QueryBuilder.js +49 -3
- package/dist/esm/src/transformers/QueryBuilder.js.map +1 -1
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/index.min.js +12 -12
- package/dist/index.min.js.map +3 -3
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/transformers/JoinAggregationDecomposer.d.ts +188 -0
- package/dist/src/transformers/JoinAggregationDecomposer.js +497 -0
- package/dist/src/transformers/JoinAggregationDecomposer.js.map +1 -0
- package/dist/src/transformers/QueryBuilder.d.ts +22 -0
- package/dist/src/transformers/QueryBuilder.js +49 -3
- package/dist/src/transformers/QueryBuilder.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
package/dist/src/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './parsers/InsertQueryParser';
|
|
|
4
4
|
export * from './parsers/WithClauseParser';
|
|
5
5
|
export * from './models/BinarySelectQuery';
|
|
6
6
|
export * from './models/SelectQuery';
|
|
7
|
+
export * from './models/SqlComponent';
|
|
7
8
|
export * from './models/ValueComponent';
|
|
8
9
|
export * from './models/ValuesQuery';
|
|
9
10
|
export * from './models/CTEError';
|
package/dist/src/index.js
CHANGED
|
@@ -21,6 +21,7 @@ __exportStar(require("./parsers/InsertQueryParser"), exports);
|
|
|
21
21
|
__exportStar(require("./parsers/WithClauseParser"), exports);
|
|
22
22
|
__exportStar(require("./models/BinarySelectQuery"), exports);
|
|
23
23
|
__exportStar(require("./models/SelectQuery"), exports);
|
|
24
|
+
__exportStar(require("./models/SqlComponent"), exports);
|
|
24
25
|
__exportStar(require("./models/ValueComponent"), exports);
|
|
25
26
|
__exportStar(require("./models/ValuesQuery"), exports);
|
|
26
27
|
__exportStar(require("./models/CTEError"), exports);
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,8DAA4C;AAE5C,8DAA4C;AAC5C,6DAA2C;AAE3C,6DAA2C;AAC3C,uDAAqC;AACrC,0DAAwC;AACxC,uDAAqC;AACrC,oDAAkC;AAClC,kDAAgC;AAEhC,8DAA4C;AAC5C,+DAA6C;AAC7C,6DAA2C;AAC3C,uEAAqD;AACrD,oEAAkD;AAClD,6DAA2C;AAC3C,4DAA0C;AAC1C,0EAAwD;AACxD,2DAAyC;AACzC,8DAA4C;AAC5C,0EAAwD;AACxD,8DAA4C,CAAC,0BAA0B;AACvE,sEAAoD;AACpD,2EAAyD;AACzD,sFAAkF;AAAzE,mIAAA,sBAAsB,OAAA;AAC/B,qEAAmD;AACnD,sEAAoD;AACpD,sEAAoD;AACpD,qEAAmD;AACnD,gFAQ+C;AAN3C,mIAAA,yBAAyB,OAAA;AACzB,oIAAA,0BAA0B,OAAA;AAM9B,wEAM2C;AALvC,6DAA6D;AAC7D,wHAAA,kBAAkB,OAAA;AAClB,yHAAA,mBAAmB,OAAA;AACnB,qHAAA,eAAe,OAAA;AACf,oHAAA,cAAc,OAAA;AAGlB,qEAAqE;AACrE,wEAAqE;AAA5D,sHAAA,gBA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,iEAA+C;AAC/C,uEAAqD;AACrD,qEAAmD;AAEnD,6DAA2C;AAC3C,8DAA4C;AAC5C,wDAAsC;AACtC,wDAAsC;AACtC,uDAAqC;AAGrC,oEAAoE"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { SimpleSelectQuery } from "../models/SimpleSelectQuery";
|
|
2
|
+
/**
|
|
3
|
+
* Options for JoinAggregationDecomposer
|
|
4
|
+
*/
|
|
5
|
+
export interface JoinDecomposerOptions {
|
|
6
|
+
/** Name for the detail CTE (default: "detail_data") */
|
|
7
|
+
detailCTEName?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Result of decomposition analysis (safe, no exceptions)
|
|
11
|
+
*/
|
|
12
|
+
export interface DecompositionAnalysisResult {
|
|
13
|
+
/** Whether the query can be decomposed */
|
|
14
|
+
success: boolean;
|
|
15
|
+
/** The decomposed query if successful */
|
|
16
|
+
decomposedQuery?: SimpleSelectQuery;
|
|
17
|
+
/** Error message if failed */
|
|
18
|
+
error?: string;
|
|
19
|
+
/** Known limitations that may affect the result */
|
|
20
|
+
limitations?: string[];
|
|
21
|
+
/** Metadata about the decomposition process */
|
|
22
|
+
metadata: {
|
|
23
|
+
/** Number of JOINs found */
|
|
24
|
+
joinCount: number;
|
|
25
|
+
/** Number of aggregation functions found */
|
|
26
|
+
aggregationCount: number;
|
|
27
|
+
/** Columns included in detail CTE */
|
|
28
|
+
detailColumns: string[];
|
|
29
|
+
/** Whether HAVING clause exists */
|
|
30
|
+
hasHaving: boolean;
|
|
31
|
+
/** Whether ORDER BY clause exists */
|
|
32
|
+
hasOrderBy: boolean;
|
|
33
|
+
/** Whether window functions are present */
|
|
34
|
+
hasWindowFunctions: boolean;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Error thrown when query decomposition fails
|
|
39
|
+
*/
|
|
40
|
+
export declare class DecompositionError extends Error {
|
|
41
|
+
readonly originalQuery: SimpleSelectQuery;
|
|
42
|
+
readonly cause?: Error | undefined;
|
|
43
|
+
constructor(message: string, originalQuery: SimpleSelectQuery, cause?: Error | undefined);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Decomposes queries that combine table joins with aggregations into separate detail and aggregation queries using CTEs
|
|
47
|
+
*
|
|
48
|
+
* This transformer separates JOIN operations from aggregation operations to make queries easier to debug:
|
|
49
|
+
* - Detail query: Contains JOINs and column selection
|
|
50
|
+
* - Aggregation query: Contains GROUP BY and aggregation functions, referencing the CTE
|
|
51
|
+
*
|
|
52
|
+
* Provides two patterns following existing codebase conventions:
|
|
53
|
+
* - analyze(): Safe analysis (Result pattern like SelectQueryParser.analyze)
|
|
54
|
+
* - decompose(): Direct decomposition with exceptions (Exception pattern like SelectQueryParser.parse)
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const decomposer = new JoinAggregationDecomposer();
|
|
59
|
+
*
|
|
60
|
+
* // Safe analysis (Result pattern)
|
|
61
|
+
* const analysis = decomposer.analyze(query);
|
|
62
|
+
* if (analysis.success) {
|
|
63
|
+
* console.log('Can decompose with', analysis.metadata.joinCount, 'joins');
|
|
64
|
+
* if (analysis.limitations) {
|
|
65
|
+
* console.log('Known limitations:', analysis.limitations);
|
|
66
|
+
* }
|
|
67
|
+
* } else {
|
|
68
|
+
* console.log('Cannot decompose:', analysis.error);
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* // Direct decomposition (Exception pattern)
|
|
72
|
+
* try {
|
|
73
|
+
* const decomposed = decomposer.decompose(query);
|
|
74
|
+
* // Success: decomposed query ready to use
|
|
75
|
+
* } catch (error) {
|
|
76
|
+
* if (error instanceof DecompositionError) {
|
|
77
|
+
* console.log('Decomposition failed:', error.message);
|
|
78
|
+
* }
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare class JoinAggregationDecomposer {
|
|
83
|
+
private readonly options;
|
|
84
|
+
private readonly formatter;
|
|
85
|
+
constructor(options?: JoinDecomposerOptions);
|
|
86
|
+
/**
|
|
87
|
+
* Analyzes a query for decomposition without throwing errors (safe analysis)
|
|
88
|
+
* Follows the same pattern as SelectQueryParser.analyze()
|
|
89
|
+
*
|
|
90
|
+
* @param query The query to analyze
|
|
91
|
+
* @returns Analysis result with success status, error information, and metadata
|
|
92
|
+
*/
|
|
93
|
+
analyze(query: SimpleSelectQuery): DecompositionAnalysisResult;
|
|
94
|
+
/**
|
|
95
|
+
* Decomposes a JOIN + aggregation query into separate detail and aggregation queries
|
|
96
|
+
* Follows the same pattern as SelectQueryParser.parse() - throws on error
|
|
97
|
+
*
|
|
98
|
+
* @param query The query to decompose
|
|
99
|
+
* @returns The decomposed query with CTE structure
|
|
100
|
+
* @throws DecompositionError if the query cannot be decomposed or formatted
|
|
101
|
+
*/
|
|
102
|
+
decompose(query: SimpleSelectQuery): SimpleSelectQuery;
|
|
103
|
+
/**
|
|
104
|
+
* Gets validation error message without throwing (for analyze method)
|
|
105
|
+
*/
|
|
106
|
+
private getValidationError;
|
|
107
|
+
/**
|
|
108
|
+
* Performs the actual decomposition
|
|
109
|
+
*/
|
|
110
|
+
private performDecomposition;
|
|
111
|
+
/**
|
|
112
|
+
* Extracts metadata about the query
|
|
113
|
+
*/
|
|
114
|
+
private extractMetadata;
|
|
115
|
+
/**
|
|
116
|
+
* Detects known limitations based on metadata
|
|
117
|
+
*/
|
|
118
|
+
private detectLimitations;
|
|
119
|
+
/**
|
|
120
|
+
* Counts the number of JOINs in the query
|
|
121
|
+
*/
|
|
122
|
+
private countJoins;
|
|
123
|
+
/**
|
|
124
|
+
* Counts aggregation functions in the query
|
|
125
|
+
*/
|
|
126
|
+
private countAggregationFunctions;
|
|
127
|
+
/**
|
|
128
|
+
* Checks if query contains window functions
|
|
129
|
+
*/
|
|
130
|
+
private hasWindowFunctions;
|
|
131
|
+
/**
|
|
132
|
+
* Checks if an expression contains aggregation functions
|
|
133
|
+
*/
|
|
134
|
+
private containsAggregationFunction;
|
|
135
|
+
/**
|
|
136
|
+
* Checks if an expression contains window functions
|
|
137
|
+
*/
|
|
138
|
+
private containsWindowFunction;
|
|
139
|
+
/**
|
|
140
|
+
* Gets function name from FunctionCall
|
|
141
|
+
*/
|
|
142
|
+
private getFunctionName;
|
|
143
|
+
/**
|
|
144
|
+
* Extracts detail column names for metadata
|
|
145
|
+
*/
|
|
146
|
+
private extractDetailColumnNames;
|
|
147
|
+
/**
|
|
148
|
+
* Extracts columns needed for the detail CTE
|
|
149
|
+
*/
|
|
150
|
+
private extractDetailColumns;
|
|
151
|
+
/**
|
|
152
|
+
* Extracts column references from an expression
|
|
153
|
+
*/
|
|
154
|
+
private extractColumnsFromExpression;
|
|
155
|
+
/**
|
|
156
|
+
* Gets a unique key for a column reference
|
|
157
|
+
*/
|
|
158
|
+
private getColumnKey;
|
|
159
|
+
/**
|
|
160
|
+
* Builds the detail query (CTE content)
|
|
161
|
+
*/
|
|
162
|
+
private buildDetailQuery;
|
|
163
|
+
/**
|
|
164
|
+
* Builds the aggregation query that references the CTE
|
|
165
|
+
*/
|
|
166
|
+
private buildAggregationQuery;
|
|
167
|
+
/**
|
|
168
|
+
* Transforms an expression to reference CTE columns instead of original table columns
|
|
169
|
+
*/
|
|
170
|
+
private transformExpressionForCTE;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Utility function to analyze a JOIN + aggregation query from SQL string (safe, no exceptions)
|
|
174
|
+
*
|
|
175
|
+
* @param sql The SQL string to parse and analyze
|
|
176
|
+
* @param options Decomposer options
|
|
177
|
+
* @returns Analysis result with success status, error information, and metadata
|
|
178
|
+
*/
|
|
179
|
+
export declare function analyzeJoinAggregation(sql: string, options?: JoinDecomposerOptions): DecompositionAnalysisResult;
|
|
180
|
+
/**
|
|
181
|
+
* Utility function to decompose a JOIN + aggregation query from SQL string
|
|
182
|
+
*
|
|
183
|
+
* @param sql The SQL string to parse and decompose
|
|
184
|
+
* @param options Decomposer options
|
|
185
|
+
* @returns The decomposed query
|
|
186
|
+
* @throws DecompositionError if parsing or decomposition fails
|
|
187
|
+
*/
|
|
188
|
+
export declare function decomposeJoinAggregation(sql: string, options?: JoinDecomposerOptions): SimpleSelectQuery;
|