rawsql-ts 0.24.3 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +9 -9
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/models/ValueComponent.d.ts +2 -1
- package/dist/esm/models/ValueComponent.js +2 -1
- package/dist/esm/models/ValueComponent.js.map +1 -1
- package/dist/esm/parsers/FunctionExpressionParser.d.ts +3 -0
- package/dist/esm/parsers/FunctionExpressionParser.js +50 -2
- package/dist/esm/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/esm/parsers/ParameterDecorator.d.ts +2 -2
- package/dist/esm/parsers/ParameterDecorator.js +1 -1
- package/dist/esm/parsers/ParameterDecorator.js.map +1 -1
- package/dist/esm/parsers/ParameterExpressionParser.js +2 -1
- package/dist/esm/parsers/ParameterExpressionParser.js.map +1 -1
- package/dist/esm/parsers/SqlPrintTokenParser.d.ts +16 -4
- package/dist/esm/parsers/SqlPrintTokenParser.js +76 -13
- package/dist/esm/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/esm/transformers/AstCommentAttachmentExtractor.d.ts +61 -0
- package/dist/esm/transformers/AstCommentAttachmentExtractor.js +221 -0
- package/dist/esm/transformers/AstCommentAttachmentExtractor.js.map +1 -0
- package/dist/esm/transformers/ClauseScopedColumnReferenceCollector.d.ts +47 -0
- package/dist/esm/transformers/ClauseScopedColumnReferenceCollector.js +235 -0
- package/dist/esm/transformers/ClauseScopedColumnReferenceCollector.js.map +1 -0
- package/dist/esm/transformers/FormatOptionResolver.js +1 -0
- package/dist/esm/transformers/FormatOptionResolver.js.map +1 -1
- package/dist/esm/transformers/LinePrinter.d.ts +1 -1
- package/dist/esm/transformers/NamedQueryDefinitionExtractor.d.ts +53 -0
- package/dist/esm/transformers/NamedQueryDefinitionExtractor.js +370 -0
- package/dist/esm/transformers/NamedQueryDefinitionExtractor.js.map +1 -0
- package/dist/esm/transformers/OnelineFormattingHelper.d.ts +1 -0
- package/dist/esm/transformers/OnelineFormattingHelper.js.map +1 -1
- package/dist/esm/transformers/SelectBodyExtractor.d.ts +21 -0
- package/dist/esm/transformers/SelectBodyExtractor.js +137 -0
- package/dist/esm/transformers/SelectBodyExtractor.js.map +1 -0
- package/dist/esm/transformers/SelectOutputCollector.d.ts +47 -0
- package/dist/esm/transformers/SelectOutputCollector.js +281 -0
- package/dist/esm/transformers/SelectOutputCollector.js.map +1 -0
- package/dist/esm/transformers/SelectValueCollector.d.ts +9 -1
- package/dist/esm/transformers/SelectValueCollector.js +83 -58
- package/dist/esm/transformers/SelectValueCollector.js.map +1 -1
- package/dist/esm/transformers/SqlFormatter.d.ts +9 -5
- package/dist/esm/transformers/SqlFormatter.js +4 -4
- package/dist/esm/transformers/SqlFormatter.js.map +1 -1
- package/dist/esm/transformers/SqlPrinter.d.ts +17 -2
- package/dist/esm/transformers/SqlPrinter.js +182 -21
- package/dist/esm/transformers/SqlPrinter.js.map +1 -1
- package/dist/esm/transformers/WildcardColumnInferenceCollector.d.ts +129 -0
- package/dist/esm/transformers/WildcardColumnInferenceCollector.js +373 -0
- package/dist/esm/transformers/WildcardColumnInferenceCollector.js.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +9 -9
- package/dist/index.min.js.map +4 -4
- package/dist/models/ValueComponent.js +2 -1
- package/dist/models/ValueComponent.js.map +1 -1
- package/dist/parsers/FunctionExpressionParser.js +49 -1
- package/dist/parsers/FunctionExpressionParser.js.map +1 -1
- package/dist/parsers/ParameterDecorator.js +1 -1
- package/dist/parsers/ParameterDecorator.js.map +1 -1
- package/dist/parsers/ParameterExpressionParser.js +2 -1
- package/dist/parsers/ParameterExpressionParser.js.map +1 -1
- package/dist/parsers/SqlPrintTokenParser.js +76 -13
- package/dist/parsers/SqlPrintTokenParser.js.map +1 -1
- package/dist/src/index.d.ts +6 -0
- package/dist/src/models/ValueComponent.d.ts +2 -1
- package/dist/src/parsers/FunctionExpressionParser.d.ts +3 -0
- package/dist/src/parsers/ParameterDecorator.d.ts +2 -2
- package/dist/src/parsers/SqlPrintTokenParser.d.ts +16 -4
- package/dist/src/transformers/AstCommentAttachmentExtractor.d.ts +61 -0
- package/dist/src/transformers/ClauseScopedColumnReferenceCollector.d.ts +47 -0
- package/dist/src/transformers/LinePrinter.d.ts +1 -1
- package/dist/src/transformers/NamedQueryDefinitionExtractor.d.ts +53 -0
- package/dist/src/transformers/OnelineFormattingHelper.d.ts +1 -0
- package/dist/src/transformers/SelectBodyExtractor.d.ts +21 -0
- package/dist/src/transformers/SelectOutputCollector.d.ts +47 -0
- package/dist/src/transformers/SelectValueCollector.d.ts +9 -1
- package/dist/src/transformers/SqlFormatter.d.ts +9 -5
- package/dist/src/transformers/SqlPrinter.d.ts +17 -2
- package/dist/src/transformers/WildcardColumnInferenceCollector.d.ts +129 -0
- package/dist/transformers/AstCommentAttachmentExtractor.js +231 -0
- package/dist/transformers/AstCommentAttachmentExtractor.js.map +1 -0
- package/dist/transformers/ClauseScopedColumnReferenceCollector.js +239 -0
- package/dist/transformers/ClauseScopedColumnReferenceCollector.js.map +1 -0
- package/dist/transformers/FormatOptionResolver.js +1 -0
- package/dist/transformers/FormatOptionResolver.js.map +1 -1
- package/dist/transformers/NamedQueryDefinitionExtractor.js +374 -0
- package/dist/transformers/NamedQueryDefinitionExtractor.js.map +1 -0
- package/dist/transformers/OnelineFormattingHelper.js.map +1 -1
- package/dist/transformers/SelectBodyExtractor.js +141 -0
- package/dist/transformers/SelectBodyExtractor.js.map +1 -0
- package/dist/transformers/SelectOutputCollector.js +291 -0
- package/dist/transformers/SelectOutputCollector.js.map +1 -0
- package/dist/transformers/SelectValueCollector.js +83 -58
- package/dist/transformers/SelectValueCollector.js.map +1 -1
- package/dist/transformers/SqlFormatter.js +5 -3
- package/dist/transformers/SqlFormatter.js.map +1 -1
- package/dist/transformers/SqlPrinter.js +182 -21
- package/dist/transformers/SqlPrinter.js.map +1 -1
- package/dist/transformers/WildcardColumnInferenceCollector.js +377 -0
- package/dist/transformers/WildcardColumnInferenceCollector.js.map +1 -0
- package/dist/tsconfig.browser.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CastStyle, ConstraintStyle, SourceAliasStyle, OrderByDefaultDirectionStyle } from '../parsers/SqlPrintTokenParser';
|
|
1
|
+
import { CastStyle, ConstraintStyle, SourceAliasStyle, ColumnAliasStyle, OrderByDefaultDirectionStyle } from '../parsers/SqlPrintTokenParser';
|
|
2
2
|
import { CommaBreakStyle, AndBreakStyle, OrBreakStyle, JoinOnBreakStyle } from './SqlPrinter';
|
|
3
3
|
import { CommentExportMode } from '../types/Formatting';
|
|
4
4
|
import { IndentCharOption, NewlineOption } from './LinePrinter';
|
|
@@ -38,7 +38,7 @@ export interface BaseFormattingOptions {
|
|
|
38
38
|
/** Newline character style (logical 'lf'/'crlf'/'cr' or literal newline string) */
|
|
39
39
|
newline?: NewlineOption;
|
|
40
40
|
/** Case transformation for SQL keywords */
|
|
41
|
-
keywordCase?: 'none' | 'upper' | 'lower';
|
|
41
|
+
keywordCase?: 'none' | 'upper' | 'lower' | 'preserve';
|
|
42
42
|
/** Style for comma line breaks */
|
|
43
43
|
commaBreak?: CommaBreakStyle;
|
|
44
44
|
/** Style for comma line breaks inside WITH clause definitions */
|
|
@@ -63,6 +63,8 @@ export interface BaseFormattingOptions {
|
|
|
63
63
|
betweenOneLine?: boolean;
|
|
64
64
|
/** Keep VALUES clause on one line regardless of comma break settings */
|
|
65
65
|
valuesOneLine?: boolean;
|
|
66
|
+
/** Keep IN value lists on one line until oneLineMaxLength forces expansion */
|
|
67
|
+
inOneLine?: boolean;
|
|
66
68
|
/** Keep JOIN conditions on one line regardless of AND/OR break settings */
|
|
67
69
|
joinOneLine?: boolean;
|
|
68
70
|
/** Keep CASE expressions on one line regardless of formatting settings */
|
|
@@ -75,8 +77,8 @@ export interface BaseFormattingOptions {
|
|
|
75
77
|
insertColumnsOneLine?: boolean;
|
|
76
78
|
/** Keep MERGE WHEN clause predicates on one line regardless of AND break settings */
|
|
77
79
|
whenOneLine?: boolean;
|
|
78
|
-
/** Maximum rendered width for opt-in one-line constructs.
|
|
79
|
-
oneLineMaxLength?: number;
|
|
80
|
+
/** Maximum rendered width for opt-in one-line constructs. Use 0, null, or omit to disable the limit. */
|
|
81
|
+
oneLineMaxLength?: number | null;
|
|
80
82
|
/** Indent AND/OR continuation lines inside JOIN ON predicates */
|
|
81
83
|
joinConditionContinuationIndent?: boolean;
|
|
82
84
|
/** Reorder JOIN ON column comparisons to follow table declaration order */
|
|
@@ -106,13 +108,15 @@ export interface SqlFormatterOptions extends BaseFormattingOptions {
|
|
|
106
108
|
end: string;
|
|
107
109
|
};
|
|
108
110
|
/** Style for parameter formatting */
|
|
109
|
-
parameterStyle?: 'anonymous' | 'indexed' | 'named';
|
|
111
|
+
parameterStyle?: 'anonymous' | 'indexed' | 'named' | 'original';
|
|
110
112
|
/** Preferred CAST rendering style */
|
|
111
113
|
castStyle?: CastStyle;
|
|
112
114
|
/** Constraint rendering style (affects CREATE TABLE constraint layout) */
|
|
113
115
|
constraintStyle?: ConstraintStyle;
|
|
114
116
|
/** Source alias rendering style for FROM/JOIN sources */
|
|
115
117
|
sourceAliasStyle?: SourceAliasStyle;
|
|
118
|
+
/** Column alias rendering style for SELECT items */
|
|
119
|
+
columnAliasStyle?: ColumnAliasStyle;
|
|
116
120
|
/** Default ORDER BY direction rendering style */
|
|
117
121
|
orderByDefaultDirectionStyle?: OrderByDefaultDirectionStyle;
|
|
118
122
|
}
|
|
@@ -16,15 +16,15 @@ export const VALID_PRESETS = ['mysql', 'postgres', 'sqlserver', 'sqlite'];
|
|
|
16
16
|
*/
|
|
17
17
|
export class SqlFormatter {
|
|
18
18
|
constructor(options = {}) {
|
|
19
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
20
20
|
const presetConfig = options.preset ? PRESETS[options.preset] : undefined;
|
|
21
21
|
if (options.preset && !presetConfig) {
|
|
22
22
|
throw new Error(`Invalid preset: ${options.preset}`); // Throw error for invalid preset
|
|
23
23
|
}
|
|
24
24
|
// Normalize identifier escape names into actual delimiter pairs before configuring the parser.
|
|
25
25
|
const resolvedIdentifierEscape = resolveIdentifierEscapeOption((_a = options.identifierEscape) !== null && _a !== void 0 ? _a : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.identifierEscape, (_b = options.identifierEscapeTarget) !== null && _b !== void 0 ? _b : 'all');
|
|
26
|
-
const parserOptions = Object.assign(Object.assign({}, presetConfig), { identifierEscape: resolvedIdentifierEscape !== null && resolvedIdentifierEscape !== void 0 ? resolvedIdentifierEscape : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.identifierEscape, parameterSymbol: (_c = options.parameterSymbol) !== null && _c !== void 0 ? _c : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.parameterSymbol, parameterStyle: (_d = options.parameterStyle) !== null && _d !== void 0 ? _d : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.parameterStyle, castStyle: (_e = options.castStyle) !== null && _e !== void 0 ? _e : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.castStyle, sourceAliasStyle: (_f = options.sourceAliasStyle) !== null && _f !== void 0 ? _f : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.sourceAliasStyle,
|
|
27
|
-
const constraintStyle = (
|
|
26
|
+
const parserOptions = Object.assign(Object.assign({}, presetConfig), { identifierEscape: resolvedIdentifierEscape !== null && resolvedIdentifierEscape !== void 0 ? resolvedIdentifierEscape : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.identifierEscape, parameterSymbol: (_c = options.parameterSymbol) !== null && _c !== void 0 ? _c : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.parameterSymbol, parameterStyle: (_d = options.parameterStyle) !== null && _d !== void 0 ? _d : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.parameterStyle, castStyle: (_e = options.castStyle) !== null && _e !== void 0 ? _e : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.castStyle, sourceAliasStyle: (_f = options.sourceAliasStyle) !== null && _f !== void 0 ? _f : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.sourceAliasStyle, columnAliasStyle: (_g = options.columnAliasStyle) !== null && _g !== void 0 ? _g : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.columnAliasStyle, orderByDefaultDirectionStyle: (_h = options.orderByDefaultDirectionStyle) !== null && _h !== void 0 ? _h : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.orderByDefaultDirectionStyle, joinConditionOrderByDeclaration: options.joinConditionOrderByDeclaration });
|
|
27
|
+
const constraintStyle = (_k = (_j = options.constraintStyle) !== null && _j !== void 0 ? _j : presetConfig === null || presetConfig === void 0 ? void 0 : presetConfig.constraintStyle) !== null && _k !== void 0 ? _k : 'postgres';
|
|
28
28
|
const parserConfig = Object.assign(Object.assign({}, parserOptions), { constraintStyle });
|
|
29
29
|
this.parser = new SqlPrintTokenParser(Object.assign({}, parserConfig));
|
|
30
30
|
// Normalize legacy boolean comment export flags before configuring the printer.
|
|
@@ -33,7 +33,7 @@ export class SqlFormatter {
|
|
|
33
33
|
: options.exportComment === false
|
|
34
34
|
? 'none'
|
|
35
35
|
: options.exportComment;
|
|
36
|
-
const printerOptions = Object.assign(Object.assign({}, options), { exportComment: normalizedExportComment, parenthesesOneLine: options.parenthesesOneLine, betweenOneLine: options.betweenOneLine, valuesOneLine: options.valuesOneLine, joinOneLine: options.joinOneLine, caseOneLine: options.caseOneLine, subqueryOneLine: options.subqueryOneLine, indentNestedParentheses: options.indentNestedParentheses });
|
|
36
|
+
const printerOptions = Object.assign(Object.assign({}, options), { exportComment: normalizedExportComment, parenthesesOneLine: options.parenthesesOneLine, betweenOneLine: options.betweenOneLine, valuesOneLine: options.valuesOneLine, inOneLine: options.inOneLine, joinOneLine: options.joinOneLine, caseOneLine: options.caseOneLine, subqueryOneLine: options.subqueryOneLine, indentNestedParentheses: options.indentNestedParentheses });
|
|
37
37
|
this.printer = new SqlPrinter(printerOptions);
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlFormatter.js","sourceRoot":"","sources":["../../../src/transformers/SqlFormatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAmB,OAAO,
|
|
1
|
+
{"version":3,"file":"SqlFormatter.js","sourceRoot":"","sources":["../../../src/transformers/SqlFormatter.ts"],"names":[],"mappings":"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"}
|
|
@@ -28,8 +28,9 @@ export type OrBreakStyle = 'none' | 'before' | 'after';
|
|
|
28
28
|
* JoinOnBreakStyle determines whether JOIN ON starts on the JOIN line or its own indented line.
|
|
29
29
|
* - 'none': Keep ON inline with the JOIN target
|
|
30
30
|
* - 'before': Break before ON and indent the join condition
|
|
31
|
+
* - 'after': Legacy alias accepted as 'none'
|
|
31
32
|
*/
|
|
32
|
-
export type JoinOnBreakStyle = 'none' | 'before';
|
|
33
|
+
export type JoinOnBreakStyle = 'none' | 'before' | 'after';
|
|
33
34
|
/**
|
|
34
35
|
* Options for configuring SqlPrinter formatting behavior
|
|
35
36
|
*/
|
|
@@ -74,7 +75,7 @@ export declare class SqlPrinter {
|
|
|
74
75
|
andBreak: AndBreakStyle;
|
|
75
76
|
/** OR break style: 'none', 'before', or 'after' */
|
|
76
77
|
orBreak: OrBreakStyle;
|
|
77
|
-
/** JOIN ON break style: 'none' or 'before' */
|
|
78
|
+
/** JOIN ON break style: 'none' or 'before' (legacy 'after' is treated as 'none') */
|
|
78
79
|
joinOnBreak: JoinOnBreakStyle;
|
|
79
80
|
/** Keyword case style: 'none', 'upper' | 'lower' */
|
|
80
81
|
keywordCase: 'none' | 'upper' | 'lower';
|
|
@@ -94,6 +95,8 @@ export declare class SqlPrinter {
|
|
|
94
95
|
private betweenOneLine;
|
|
95
96
|
/** Whether to keep VALUES clause on one line */
|
|
96
97
|
private valuesOneLine;
|
|
98
|
+
/** Whether to keep IN value lists on one line */
|
|
99
|
+
private inOneLine;
|
|
97
100
|
/** Whether to keep JOIN conditions on one line */
|
|
98
101
|
private joinOneLine;
|
|
99
102
|
/** Whether to keep CASE expressions on one line */
|
|
@@ -145,6 +148,7 @@ export declare class SqlPrinter {
|
|
|
145
148
|
private shouldAlignExplainStatementChild;
|
|
146
149
|
private shouldExpandCommentedFunctionCall;
|
|
147
150
|
private containsCommentBlock;
|
|
151
|
+
private containsRenderableCommentBlock;
|
|
148
152
|
private isLogicalOperatorWithComment;
|
|
149
153
|
private currentLineEndsWithLogicalOperator;
|
|
150
154
|
private isCaseContext;
|
|
@@ -183,6 +187,8 @@ export declare class SqlPrinter {
|
|
|
183
187
|
* Decides whether the current container should collapse into a single line.
|
|
184
188
|
*/
|
|
185
189
|
private shouldFormatContainerAsOneline;
|
|
190
|
+
private isInValueListExpression;
|
|
191
|
+
private getInValueListParts;
|
|
186
192
|
/**
|
|
187
193
|
* Detects an INSERT column list that must stay on a single line.
|
|
188
194
|
*/
|
|
@@ -206,8 +212,11 @@ export declare class SqlPrinter {
|
|
|
206
212
|
private normalizeSmartBlockLine;
|
|
207
213
|
private extractLineCommentContent;
|
|
208
214
|
private flushSmartCommentBlockBuilder;
|
|
215
|
+
private shouldFallbackSmartLineCommentToBlock;
|
|
216
|
+
private buildSmartLineComment;
|
|
209
217
|
private collectCommentBlockLines;
|
|
210
218
|
private extractRawCommentBlockLines;
|
|
219
|
+
private extractDirectBlockCommentTexts;
|
|
211
220
|
private normalizeCommentForSmart;
|
|
212
221
|
private buildBlockComment;
|
|
213
222
|
private getIndentString;
|
|
@@ -236,12 +245,15 @@ export declare class SqlPrinter {
|
|
|
236
245
|
*/
|
|
237
246
|
private isOnelineMode;
|
|
238
247
|
private normalizeOneLineMaxLength;
|
|
248
|
+
private normalizeKeywordCase;
|
|
249
|
+
private normalizeJoinOnBreak;
|
|
239
250
|
private fitsOneLineMaxLength;
|
|
240
251
|
/**
|
|
241
252
|
* Handles CTE tokens with one-liner formatting.
|
|
242
253
|
* Creates a nested SqlPrinter instance for proper CTE oneline formatting.
|
|
243
254
|
*/
|
|
244
255
|
private tryHandleCteOnelineToken;
|
|
256
|
+
private shouldPreserveCteComments;
|
|
245
257
|
/**
|
|
246
258
|
* Creates a SqlPrinter instance configured for CTE oneline formatting.
|
|
247
259
|
*/
|
|
@@ -251,6 +263,9 @@ export declare class SqlPrinter {
|
|
|
251
263
|
* Creates a unified oneline printer that formats everything as one line regardless of content type.
|
|
252
264
|
*/
|
|
253
265
|
private tryHandleOnelineToken;
|
|
266
|
+
private tryHandleInOneLineToken;
|
|
267
|
+
private appendExpandedInValueList;
|
|
268
|
+
private splitValueListItems;
|
|
254
269
|
private isBooleanParenExpression;
|
|
255
270
|
private containsLogicalOperator;
|
|
256
271
|
private getClauseBreakIndentLevel;
|
|
@@ -30,7 +30,7 @@ export class SqlPrinter {
|
|
|
30
30
|
* @param options Optional style settings for pretty printing
|
|
31
31
|
*/
|
|
32
32
|
constructor(options) {
|
|
33
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v
|
|
33
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
34
34
|
/** Track whether we are currently inside a WITH clause for full-oneline formatting */
|
|
35
35
|
this.insideWithClause = false;
|
|
36
36
|
/** Tracks nesting depth while formatting MERGE WHEN predicate segments */
|
|
@@ -58,26 +58,28 @@ export class SqlPrinter {
|
|
|
58
58
|
this.valuesCommaBreak = (_d = options === null || options === void 0 ? void 0 : options.valuesCommaBreak) !== null && _d !== void 0 ? _d : this.commaBreak;
|
|
59
59
|
this.andBreak = (_e = options === null || options === void 0 ? void 0 : options.andBreak) !== null && _e !== void 0 ? _e : 'none';
|
|
60
60
|
this.orBreak = (_f = options === null || options === void 0 ? void 0 : options.orBreak) !== null && _f !== void 0 ? _f : 'none';
|
|
61
|
-
this.joinOnBreak = (
|
|
62
|
-
this.keywordCase = (
|
|
61
|
+
this.joinOnBreak = this.normalizeJoinOnBreak(options === null || options === void 0 ? void 0 : options.joinOnBreak);
|
|
62
|
+
this.keywordCase = this.normalizeKeywordCase(options === null || options === void 0 ? void 0 : options.keywordCase);
|
|
63
63
|
this.commentExportMode = this.resolveCommentExportMode(options === null || options === void 0 ? void 0 : options.exportComment);
|
|
64
|
-
this.withClauseStyle = (
|
|
65
|
-
this.commentStyle = (
|
|
66
|
-
this.parenthesesOneLine = (
|
|
67
|
-
this.betweenOneLine = (
|
|
68
|
-
this.valuesOneLine = (
|
|
69
|
-
this.
|
|
70
|
-
this.
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
64
|
+
this.withClauseStyle = (_g = options === null || options === void 0 ? void 0 : options.withClauseStyle) !== null && _g !== void 0 ? _g : 'standard';
|
|
65
|
+
this.commentStyle = (_h = options === null || options === void 0 ? void 0 : options.commentStyle) !== null && _h !== void 0 ? _h : 'block';
|
|
66
|
+
this.parenthesesOneLine = (_j = options === null || options === void 0 ? void 0 : options.parenthesesOneLine) !== null && _j !== void 0 ? _j : false;
|
|
67
|
+
this.betweenOneLine = (_k = options === null || options === void 0 ? void 0 : options.betweenOneLine) !== null && _k !== void 0 ? _k : false;
|
|
68
|
+
this.valuesOneLine = (_l = options === null || options === void 0 ? void 0 : options.valuesOneLine) !== null && _l !== void 0 ? _l : false;
|
|
69
|
+
this.inOneLine = (_m = options === null || options === void 0 ? void 0 : options.inOneLine) !== null && _m !== void 0 ? _m : false;
|
|
70
|
+
this.joinOneLine = (_o = options === null || options === void 0 ? void 0 : options.joinOneLine) !== null && _o !== void 0 ? _o : false;
|
|
71
|
+
this.caseOneLine = (_p = options === null || options === void 0 ? void 0 : options.caseOneLine) !== null && _p !== void 0 ? _p : false;
|
|
72
|
+
this.subqueryOneLine = (_q = options === null || options === void 0 ? void 0 : options.subqueryOneLine) !== null && _q !== void 0 ? _q : false;
|
|
73
|
+
this.indentNestedParentheses = (_r = options === null || options === void 0 ? void 0 : options.indentNestedParentheses) !== null && _r !== void 0 ? _r : false;
|
|
74
|
+
this.insertColumnsOneLine = (_s = options === null || options === void 0 ? void 0 : options.insertColumnsOneLine) !== null && _s !== void 0 ? _s : false;
|
|
75
|
+
this.whenOneLine = (_t = options === null || options === void 0 ? void 0 : options.whenOneLine) !== null && _t !== void 0 ? _t : false;
|
|
75
76
|
this.oneLineMaxLength = this.normalizeOneLineMaxLength(options === null || options === void 0 ? void 0 : options.oneLineMaxLength);
|
|
76
|
-
this.joinConditionContinuationIndent = (
|
|
77
|
+
this.joinConditionContinuationIndent = (_u = options === null || options === void 0 ? void 0 : options.joinConditionContinuationIndent) !== null && _u !== void 0 ? _u : false;
|
|
77
78
|
const onelineOptions = {
|
|
78
79
|
parenthesesOneLine: this.parenthesesOneLine,
|
|
79
80
|
betweenOneLine: this.betweenOneLine,
|
|
80
81
|
valuesOneLine: this.valuesOneLine,
|
|
82
|
+
inOneLine: this.inOneLine,
|
|
81
83
|
joinOneLine: this.joinOneLine,
|
|
82
84
|
caseOneLine: this.caseOneLine,
|
|
83
85
|
subqueryOneLine: this.subqueryOneLine,
|
|
@@ -87,7 +89,7 @@ export class SqlPrinter {
|
|
|
87
89
|
this.onelineHelper = new OnelineFormattingHelper(onelineOptions);
|
|
88
90
|
this.linePrinter = new LinePrinter(this.indentChar, this.indentSize, this.newline, this.commaBreak);
|
|
89
91
|
// Initialize
|
|
90
|
-
this.indentIncrementContainers = new Set((
|
|
92
|
+
this.indentIncrementContainers = new Set((_v = options === null || options === void 0 ? void 0 : options.indentIncrementContainerTypes) !== null && _v !== void 0 ? _v : [
|
|
91
93
|
SqlPrintTokenContainerType.SelectClause,
|
|
92
94
|
SqlPrintTokenContainerType.ReturningClause,
|
|
93
95
|
SqlPrintTokenContainerType.FromClause,
|
|
@@ -235,6 +237,18 @@ export class SqlPrinter {
|
|
|
235
237
|
((_a = this.smartCommentBlockBuilder) === null || _a === void 0 ? void 0 : _a.mode) === 'line') {
|
|
236
238
|
this.flushSmartCommentBlockBuilder();
|
|
237
239
|
}
|
|
240
|
+
if (containerIsTopLevel &&
|
|
241
|
+
!this.isOnelineMode() &&
|
|
242
|
+
this.pendingLineCommentBreak === null &&
|
|
243
|
+
this.linePrinter.getCurrentLine().text.trim() !== '') {
|
|
244
|
+
this.linePrinter.appendNewline(level);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (hasRenderableLeadingComment &&
|
|
248
|
+
containerIsTopLevel &&
|
|
249
|
+
!this.isOnelineMode() &&
|
|
250
|
+
this.linePrinter.getCurrentLine().text.trim() !== '') {
|
|
251
|
+
this.linePrinter.appendNewline(level);
|
|
238
252
|
}
|
|
239
253
|
if (leadingCommentFollowsLogicalOperator &&
|
|
240
254
|
this.pendingLineCommentBreak === null &&
|
|
@@ -326,6 +340,9 @@ export class SqlPrinter {
|
|
|
326
340
|
return; // Return early to avoid processing innerTokens
|
|
327
341
|
}
|
|
328
342
|
}
|
|
343
|
+
else if (this.inOneLine && this.isInValueListExpression(token) && this.tryHandleInOneLineToken(token, level)) {
|
|
344
|
+
return; // Return early to avoid processing innerTokens
|
|
345
|
+
}
|
|
329
346
|
else if (this.shouldFormatContainerAsOneline(token, shouldIndentNested) && this.tryHandleOnelineToken(token, level)) {
|
|
330
347
|
return; // Return early to avoid processing innerTokens
|
|
331
348
|
}
|
|
@@ -536,6 +553,12 @@ export class SqlPrinter {
|
|
|
536
553
|
}
|
|
537
554
|
return token.innerTokens.some(child => this.containsCommentBlock(child));
|
|
538
555
|
}
|
|
556
|
+
containsRenderableCommentBlock(token, context) {
|
|
557
|
+
if (token.containerType === SqlPrintTokenContainerType.CommentBlock) {
|
|
558
|
+
return this.shouldRenderComment(token, context);
|
|
559
|
+
}
|
|
560
|
+
return token.innerTokens.some(child => this.containsRenderableCommentBlock(child, context));
|
|
561
|
+
}
|
|
539
562
|
isLogicalOperatorWithComment(token) {
|
|
540
563
|
return this.containsCommentBlock(token) &&
|
|
541
564
|
token.type === SqlPrintTokenType.operator &&
|
|
@@ -873,6 +896,32 @@ export class SqlPrinter {
|
|
|
873
896
|
shouldFormatContainerAsOneline(token, shouldIndentNested) {
|
|
874
897
|
return this.onelineHelper.shouldFormatContainer(token, shouldIndentNested);
|
|
875
898
|
}
|
|
899
|
+
isInValueListExpression(token) {
|
|
900
|
+
const parts = this.getInValueListParts(token);
|
|
901
|
+
return parts !== null;
|
|
902
|
+
}
|
|
903
|
+
getInValueListParts(token) {
|
|
904
|
+
if (token.containerType !== SqlPrintTokenContainerType.BinaryExpression) {
|
|
905
|
+
return null;
|
|
906
|
+
}
|
|
907
|
+
const significant = token.innerTokens.filter(child => child.type !== SqlPrintTokenType.space);
|
|
908
|
+
if (significant.length !== 3) {
|
|
909
|
+
return null;
|
|
910
|
+
}
|
|
911
|
+
const [left, operator, right] = significant;
|
|
912
|
+
const operatorText = operator.text.trim().toLowerCase();
|
|
913
|
+
if (operatorText !== 'in' && operatorText !== 'not in') {
|
|
914
|
+
return null;
|
|
915
|
+
}
|
|
916
|
+
if (right.containerType !== SqlPrintTokenContainerType.ParenExpression) {
|
|
917
|
+
return null;
|
|
918
|
+
}
|
|
919
|
+
const valueList = right.innerTokens.find(child => child.containerType === SqlPrintTokenContainerType.ValueList);
|
|
920
|
+
if (!valueList) {
|
|
921
|
+
return null;
|
|
922
|
+
}
|
|
923
|
+
return { left, operator, valueList };
|
|
924
|
+
}
|
|
876
925
|
/**
|
|
877
926
|
* Detects an INSERT column list that must stay on a single line.
|
|
878
927
|
*/
|
|
@@ -1020,7 +1069,12 @@ export class SqlPrinter {
|
|
|
1020
1069
|
}
|
|
1021
1070
|
else {
|
|
1022
1071
|
const content = normalized.lines[0];
|
|
1023
|
-
|
|
1072
|
+
if (this.shouldFallbackSmartLineCommentToBlock()) {
|
|
1073
|
+
this.linePrinter.appendText(this.buildBlockComment([content], level));
|
|
1074
|
+
this.ensureTrailingSpace();
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
const lineText = this.buildSmartLineComment(content);
|
|
1024
1078
|
if (parentContainerType === SqlPrintTokenContainerType.CommentBlock) {
|
|
1025
1079
|
this.linePrinter.appendText(lineText);
|
|
1026
1080
|
this.pendingLineCommentBreak = this.resolveCommentIndentLevel(level, parentContainerType);
|
|
@@ -1101,11 +1155,26 @@ export class SqlPrinter {
|
|
|
1101
1155
|
if (this.commentStyle !== 'smart') {
|
|
1102
1156
|
const rawLines = this.extractRawCommentBlockLines(token);
|
|
1103
1157
|
if (rawLines.length > 0) {
|
|
1158
|
+
if (context.position === 'leading' && context.isTopLevelContainer && !this.isOnelineMode()) {
|
|
1159
|
+
for (const line of rawLines) {
|
|
1160
|
+
this.linePrinter.appendText(`/* ${line} */`);
|
|
1161
|
+
this.linePrinter.appendNewline(level);
|
|
1162
|
+
}
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1104
1165
|
const normalizedBlocks = rawLines.map(line => `/* ${line} */`).join(' ');
|
|
1105
1166
|
const hasTrailingSpace = (_a = token.innerTokens) === null || _a === void 0 ? void 0 : _a.some(child => child.type === SqlPrintTokenType.space && child.text.includes(' '));
|
|
1106
1167
|
this.linePrinter.appendText(hasTrailingSpace ? `${normalizedBlocks} ` : normalizedBlocks);
|
|
1107
1168
|
return;
|
|
1108
1169
|
}
|
|
1170
|
+
const directBlockComments = this.extractDirectBlockCommentTexts(token);
|
|
1171
|
+
if (directBlockComments.length > 1 && context.position === 'leading' && context.isTopLevelContainer && !this.isOnelineMode()) {
|
|
1172
|
+
for (const comment of directBlockComments) {
|
|
1173
|
+
this.linePrinter.appendText(comment);
|
|
1174
|
+
this.linePrinter.appendNewline(level);
|
|
1175
|
+
}
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1109
1178
|
for (const child of token.innerTokens) {
|
|
1110
1179
|
// Force inner comment tokens to render once the block is approved.
|
|
1111
1180
|
const childContext = {
|
|
@@ -1193,14 +1262,16 @@ export class SqlPrinter {
|
|
|
1193
1262
|
const { lines, level, mode } = this.smartCommentBlockBuilder;
|
|
1194
1263
|
if (mode === 'line') {
|
|
1195
1264
|
const meaningfulLineCount = lines.filter(line => line.trim() !== '').length;
|
|
1196
|
-
if (meaningfulLineCount > 1) {
|
|
1265
|
+
if (meaningfulLineCount > 1 || this.shouldFallbackSmartLineCommentToBlock()) {
|
|
1197
1266
|
const blockText = this.buildBlockComment(lines, level);
|
|
1198
1267
|
this.linePrinter.appendText(blockText);
|
|
1268
|
+
if (this.shouldFallbackSmartLineCommentToBlock()) {
|
|
1269
|
+
this.ensureTrailingSpace();
|
|
1270
|
+
}
|
|
1199
1271
|
}
|
|
1200
1272
|
else {
|
|
1201
1273
|
const content = (_a = lines[0]) !== null && _a !== void 0 ? _a : '';
|
|
1202
|
-
|
|
1203
|
-
this.linePrinter.appendText(lineText);
|
|
1274
|
+
this.linePrinter.appendText(this.buildSmartLineComment(content));
|
|
1204
1275
|
}
|
|
1205
1276
|
if (!this.isOnelineMode()) {
|
|
1206
1277
|
this.linePrinter.appendNewline(level);
|
|
@@ -1209,6 +1280,12 @@ export class SqlPrinter {
|
|
|
1209
1280
|
}
|
|
1210
1281
|
this.smartCommentBlockBuilder = null;
|
|
1211
1282
|
}
|
|
1283
|
+
shouldFallbackSmartLineCommentToBlock() {
|
|
1284
|
+
return this.isOnelineMode();
|
|
1285
|
+
}
|
|
1286
|
+
buildSmartLineComment(content) {
|
|
1287
|
+
return content ? `-- ${content}` : '--';
|
|
1288
|
+
}
|
|
1212
1289
|
collectCommentBlockLines(token) {
|
|
1213
1290
|
var _a;
|
|
1214
1291
|
const lines = [];
|
|
@@ -1267,6 +1344,20 @@ export class SqlPrinter {
|
|
|
1267
1344
|
}
|
|
1268
1345
|
return lines;
|
|
1269
1346
|
}
|
|
1347
|
+
extractDirectBlockCommentTexts(token) {
|
|
1348
|
+
var _a;
|
|
1349
|
+
const comments = [];
|
|
1350
|
+
for (const child of (_a = token.innerTokens) !== null && _a !== void 0 ? _a : []) {
|
|
1351
|
+
if (child.type !== SqlPrintTokenType.comment) {
|
|
1352
|
+
continue;
|
|
1353
|
+
}
|
|
1354
|
+
const trimmed = child.text.trim();
|
|
1355
|
+
if (trimmed.startsWith('/*') && trimmed.endsWith('*/')) {
|
|
1356
|
+
comments.push(trimmed);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
return comments;
|
|
1360
|
+
}
|
|
1270
1361
|
normalizeCommentForSmart(text) {
|
|
1271
1362
|
const trimmed = text.trim();
|
|
1272
1363
|
let source = trimmed;
|
|
@@ -1470,12 +1561,18 @@ export class SqlPrinter {
|
|
|
1470
1561
|
return this.newline === ' ';
|
|
1471
1562
|
}
|
|
1472
1563
|
normalizeOneLineMaxLength(value) {
|
|
1473
|
-
if (value
|
|
1564
|
+
if (value == null || !Number.isFinite(value) || value <= 0) {
|
|
1474
1565
|
return undefined;
|
|
1475
1566
|
}
|
|
1476
1567
|
const normalized = Math.floor(value);
|
|
1477
1568
|
return normalized > 0 ? normalized : undefined;
|
|
1478
1569
|
}
|
|
1570
|
+
normalizeKeywordCase(value) {
|
|
1571
|
+
return value === 'preserve' ? 'none' : value !== null && value !== void 0 ? value : 'none';
|
|
1572
|
+
}
|
|
1573
|
+
normalizeJoinOnBreak(value) {
|
|
1574
|
+
return value === 'before' ? 'before' : 'none';
|
|
1575
|
+
}
|
|
1479
1576
|
fitsOneLineMaxLength(text) {
|
|
1480
1577
|
if (this.oneLineMaxLength === undefined) {
|
|
1481
1578
|
return true;
|
|
@@ -1489,9 +1586,13 @@ export class SqlPrinter {
|
|
|
1489
1586
|
* Creates a nested SqlPrinter instance for proper CTE oneline formatting.
|
|
1490
1587
|
*/
|
|
1491
1588
|
tryHandleCteOnelineToken(token, level) {
|
|
1589
|
+
if (this.shouldPreserveCteComments(token)) {
|
|
1590
|
+
return false;
|
|
1591
|
+
}
|
|
1492
1592
|
const onelinePrinter = this.createCteOnelinePrinter();
|
|
1493
1593
|
const onelineResult = onelinePrinter.print(token, level);
|
|
1494
1594
|
let cleanedResult = this.cleanDuplicateSpaces(onelineResult);
|
|
1595
|
+
// TODO(rawsql-ts#890): replace this CTE-oneline whitespace fallback with a token-level rewrite.
|
|
1495
1596
|
cleanedResult = cleanedResult.replace(/\(\s+/g, '(').replace(/\s+\)/g, ' )');
|
|
1496
1597
|
const trimmedResult = cleanedResult.trim();
|
|
1497
1598
|
if (!this.fitsOneLineMaxLength(trimmedResult)) {
|
|
@@ -1500,6 +1601,12 @@ export class SqlPrinter {
|
|
|
1500
1601
|
this.linePrinter.appendText(trimmedResult);
|
|
1501
1602
|
return true;
|
|
1502
1603
|
}
|
|
1604
|
+
shouldPreserveCteComments(token) {
|
|
1605
|
+
return this.containsRenderableCommentBlock(token, {
|
|
1606
|
+
position: 'inline',
|
|
1607
|
+
isTopLevelContainer: false,
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1503
1610
|
/**
|
|
1504
1611
|
* Creates a SqlPrinter instance configured for CTE oneline formatting.
|
|
1505
1612
|
*/
|
|
@@ -1537,6 +1644,59 @@ export class SqlPrinter {
|
|
|
1537
1644
|
this.linePrinter.appendText(cleanedResult);
|
|
1538
1645
|
return true;
|
|
1539
1646
|
}
|
|
1647
|
+
tryHandleInOneLineToken(token, level) {
|
|
1648
|
+
const parts = this.getInValueListParts(token);
|
|
1649
|
+
if (!parts) {
|
|
1650
|
+
return false;
|
|
1651
|
+
}
|
|
1652
|
+
if (this.containsRenderableCommentBlock(parts.valueList, { position: 'inline', isTopLevelContainer: false })) {
|
|
1653
|
+
this.appendExpandedInValueList(parts, token, level);
|
|
1654
|
+
return true;
|
|
1655
|
+
}
|
|
1656
|
+
const onelinePrinter = this.createOnelinePrinter();
|
|
1657
|
+
const onelineResult = onelinePrinter.print(token, level);
|
|
1658
|
+
const cleanedResult = this.cleanDuplicateSpaces(onelineResult);
|
|
1659
|
+
if (this.fitsOneLineMaxLength(cleanedResult)) {
|
|
1660
|
+
this.linePrinter.appendText(cleanedResult);
|
|
1661
|
+
return true;
|
|
1662
|
+
}
|
|
1663
|
+
this.appendExpandedInValueList(parts, token, level);
|
|
1664
|
+
return true;
|
|
1665
|
+
}
|
|
1666
|
+
appendExpandedInValueList(parts, token, level) {
|
|
1667
|
+
this.appendToken(parts.left, level, token.containerType);
|
|
1668
|
+
this.ensureTrailingSpace();
|
|
1669
|
+
this.linePrinter.appendText(this.applyKeywordCase(parts.operator.text));
|
|
1670
|
+
this.ensureTrailingSpace();
|
|
1671
|
+
this.linePrinter.appendText('(');
|
|
1672
|
+
const valueGroups = this.splitValueListItems(parts.valueList);
|
|
1673
|
+
for (let i = 0; i < valueGroups.length; i++) {
|
|
1674
|
+
this.linePrinter.appendNewline(level + 1);
|
|
1675
|
+
if (i > 0) {
|
|
1676
|
+
this.linePrinter.appendText(',');
|
|
1677
|
+
this.ensureTrailingSpace();
|
|
1678
|
+
}
|
|
1679
|
+
for (const valueToken of valueGroups[i]) {
|
|
1680
|
+
this.appendToken(valueToken, level + 1, SqlPrintTokenContainerType.ValueList);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
this.linePrinter.appendNewline(level);
|
|
1684
|
+
this.linePrinter.appendText(')');
|
|
1685
|
+
}
|
|
1686
|
+
splitValueListItems(valueList) {
|
|
1687
|
+
const groups = [[]];
|
|
1688
|
+
for (const child of valueList.innerTokens) {
|
|
1689
|
+
if (child.type === SqlPrintTokenType.argumentSplitter) {
|
|
1690
|
+
groups.push([]);
|
|
1691
|
+
continue;
|
|
1692
|
+
}
|
|
1693
|
+
if (child.type === SqlPrintTokenType.space && groups[groups.length - 1].length === 0) {
|
|
1694
|
+
continue;
|
|
1695
|
+
}
|
|
1696
|
+
groups[groups.length - 1].push(child);
|
|
1697
|
+
}
|
|
1698
|
+
return groups.filter(group => group.length > 0);
|
|
1699
|
+
}
|
|
1540
1700
|
isBooleanParenExpression(token) {
|
|
1541
1701
|
if (token.containerType !== SqlPrintTokenContainerType.ParenExpression) {
|
|
1542
1702
|
return false;
|
|
@@ -1684,6 +1844,7 @@ export class SqlPrinter {
|
|
|
1684
1844
|
parenthesesOneLine: false, // Prevent recursive processing (avoid infinite loops)
|
|
1685
1845
|
betweenOneLine: false, // Prevent recursive processing (avoid infinite loops)
|
|
1686
1846
|
valuesOneLine: false, // Prevent recursive processing (avoid infinite loops)
|
|
1847
|
+
inOneLine: false, // Prevent recursive processing (avoid infinite loops)
|
|
1687
1848
|
joinOneLine: false, // Prevent recursive processing (avoid infinite loops)
|
|
1688
1849
|
caseOneLine: false, // Prevent recursive processing (avoid infinite loops)
|
|
1689
1850
|
subqueryOneLine: false, // Prevent recursive processing (avoid infinite loops)
|