rawsql-ts 0.11.9-beta → 0.11.10-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.min.js +9 -9
- package/dist/esm/index.min.js.map +3 -3
- package/dist/esm/src/transformers/SqlFormatter.d.ts +1 -0
- package/dist/esm/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/esm/src/transformers/SqlPrinter.d.ts +59 -14
- package/dist/esm/src/transformers/SqlPrinter.js +119 -65
- package/dist/esm/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/esm/tsconfig.browser.tsbuildinfo +1 -1
- package/dist/index.min.js +8 -8
- package/dist/index.min.js.map +3 -3
- package/dist/src/transformers/SqlFormatter.d.ts +1 -0
- package/dist/src/transformers/SqlFormatter.js.map +1 -1
- package/dist/src/transformers/SqlPrinter.d.ts +59 -14
- package/dist/src/transformers/SqlPrinter.js +119 -65
- package/dist/src/transformers/SqlPrinter.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -28,6 +28,7 @@ export declare class SqlFormatter {
|
|
|
28
28
|
andBreak?: AndBreakStyle;
|
|
29
29
|
exportComment?: boolean;
|
|
30
30
|
strictCommentPlacement?: boolean;
|
|
31
|
+
cteOneline?: boolean;
|
|
31
32
|
}); /**
|
|
32
33
|
* Formats a SQL query string with the given parameters.
|
|
33
34
|
* @param sqlText The SQL query string to format.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlFormatter.js","sourceRoot":"","sources":["../../../src/transformers/SqlFormatter.ts"],"names":[],"mappings":";;;AAAA,wEAA+F;AAC/F,6CAA0E;AAK1E,4CAA4C;AAC/B,QAAA,aAAa,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAU,CAAC;AAGnF;;GAEG;AACH,MAAa,YAAY;IAIrB,YAAY,
|
|
1
|
+
{"version":3,"file":"SqlFormatter.js","sourceR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AC,KAAK,CAAC,KAAK,CAAC,CAAC;QAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;IACpC,CAAC;CACJ;AA/CD,oCA+CC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SqlPrintToken } from "../models/SqlPrintToken";
|
|
1
|
+
import { SqlPrintToken, SqlPrintTokenContainerType } from "../models/SqlPrintToken";
|
|
2
2
|
import { IndentCharOption, NewlineOption } from "./LinePrinter";
|
|
3
3
|
/**
|
|
4
4
|
* CommaBreakStyle determines how commas are placed in formatted SQL output.
|
|
@@ -14,8 +14,49 @@ export type CommaBreakStyle = 'none' | 'before' | 'after';
|
|
|
14
14
|
* - 'after': Line break after AND
|
|
15
15
|
*/
|
|
16
16
|
export type AndBreakStyle = 'none' | 'before' | 'after';
|
|
17
|
+
/**
|
|
18
|
+
* Options for configuring SqlPrinter formatting behavior
|
|
19
|
+
*/
|
|
20
|
+
export interface SqlPrinterOptions {
|
|
21
|
+
/** Indent character (e.g., ' ' or '\t') */
|
|
22
|
+
indentChar?: IndentCharOption;
|
|
23
|
+
/** Indent size (number of indentChar repetitions per level) */
|
|
24
|
+
indentSize?: number;
|
|
25
|
+
/** Newline character (e.g., '\n' or '\r\n') */
|
|
26
|
+
newline?: NewlineOption;
|
|
27
|
+
/** Comma break style: 'none', 'before', or 'after' */
|
|
28
|
+
commaBreak?: CommaBreakStyle;
|
|
29
|
+
/** AND break style: 'none', 'before', or 'after' */
|
|
30
|
+
andBreak?: AndBreakStyle;
|
|
31
|
+
/** Keyword case style: 'none', 'upper' | 'lower' */
|
|
32
|
+
keywordCase?: 'none' | 'upper' | 'lower';
|
|
33
|
+
/** Whether to export comments in the output (default: false for compatibility) */
|
|
34
|
+
exportComment?: boolean;
|
|
35
|
+
/** Whether to use strict comment placement (only clause-level comments, default: false) */
|
|
36
|
+
strictCommentPlacement?: boolean;
|
|
37
|
+
/** Container types that should increase indentation level */
|
|
38
|
+
indentIncrementContainerTypes?: SqlPrintTokenContainerType[];
|
|
39
|
+
/** Whether to format CTE parts as one-liners (default: false) */
|
|
40
|
+
cteOneline?: boolean;
|
|
41
|
+
}
|
|
17
42
|
/**
|
|
18
43
|
* SqlPrinter formats a SqlPrintToken tree into a SQL string with flexible style options.
|
|
44
|
+
*
|
|
45
|
+
* This class provides various formatting options including:
|
|
46
|
+
* - Indentation control (character and size)
|
|
47
|
+
* - Line break styles for commas and AND operators
|
|
48
|
+
* - Keyword case transformation
|
|
49
|
+
* - Comment handling
|
|
50
|
+
* - CTE (Common Table Expression) formatting
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* const printer = new SqlPrinter({
|
|
54
|
+
* indentChar: ' ',
|
|
55
|
+
* indentSize: 1,
|
|
56
|
+
* keywordCase: 'upper',
|
|
57
|
+
* commaBreak: 'after'
|
|
58
|
+
* });
|
|
59
|
+
* const formatted = printer.print(sqlToken);
|
|
19
60
|
*/
|
|
20
61
|
export declare class SqlPrinter {
|
|
21
62
|
/** Indent character (e.g., ' ' or '\\t') */
|
|
@@ -34,27 +75,31 @@ export declare class SqlPrinter {
|
|
|
34
75
|
exportComment: boolean;
|
|
35
76
|
/** Whether to use strict comment placement (only clause-level comments, default: false) */
|
|
36
77
|
strictCommentPlacement: boolean;
|
|
78
|
+
/** Whether to format CTE parts as one-liners (default: false) */
|
|
79
|
+
cteOneline: boolean;
|
|
37
80
|
private linePrinter;
|
|
38
81
|
private indentIncrementContainers;
|
|
39
82
|
/**
|
|
40
83
|
* @param options Optional style settings for pretty printing
|
|
41
84
|
*/
|
|
42
|
-
constructor(options?:
|
|
43
|
-
indentChar?: IndentCharOption;
|
|
44
|
-
indentSize?: number;
|
|
45
|
-
newline?: NewlineOption;
|
|
46
|
-
commaBreak?: CommaBreakStyle;
|
|
47
|
-
andBreak?: AndBreakStyle;
|
|
48
|
-
keywordCase?: 'none' | 'upper' | 'lower';
|
|
49
|
-
exportComment?: boolean;
|
|
50
|
-
strictCommentPlacement?: boolean;
|
|
51
|
-
indentIncrementContainerTypes?: string[];
|
|
52
|
-
});
|
|
85
|
+
constructor(options?: SqlPrinterOptions);
|
|
53
86
|
/**
|
|
54
87
|
* Converts a SqlPrintToken tree to a formatted SQL string.
|
|
55
|
-
* @param token The root SqlPrintToken
|
|
56
|
-
* @param level
|
|
88
|
+
* @param token The root SqlPrintToken to format
|
|
89
|
+
* @param level Initial indentation level (default: 0)
|
|
90
|
+
* @returns Formatted SQL string
|
|
91
|
+
* @example
|
|
92
|
+
* const printer = new SqlPrinter({ indentChar: ' ', keywordCase: 'upper' });
|
|
93
|
+
* const formatted = printer.print(sqlToken);
|
|
57
94
|
*/
|
|
58
95
|
print(token: SqlPrintToken, level?: number): string;
|
|
59
96
|
private appendToken;
|
|
97
|
+
private shouldSkipToken;
|
|
98
|
+
private applyKeywordCase;
|
|
99
|
+
private handleKeywordToken;
|
|
100
|
+
private handleCommaToken;
|
|
101
|
+
private handleAndOperatorToken;
|
|
102
|
+
private handleJoinClauseToken;
|
|
103
|
+
private handleCommentToken;
|
|
104
|
+
private handleCteOnelineToken;
|
|
60
105
|
}
|
|
@@ -5,13 +5,29 @@ const SqlPrintToken_1 = require("../models/SqlPrintToken");
|
|
|
5
5
|
const LinePrinter_1 = require("./LinePrinter");
|
|
6
6
|
/**
|
|
7
7
|
* SqlPrinter formats a SqlPrintToken tree into a SQL string with flexible style options.
|
|
8
|
+
*
|
|
9
|
+
* This class provides various formatting options including:
|
|
10
|
+
* - Indentation control (character and size)
|
|
11
|
+
* - Line break styles for commas and AND operators
|
|
12
|
+
* - Keyword case transformation
|
|
13
|
+
* - Comment handling
|
|
14
|
+
* - CTE (Common Table Expression) formatting
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const printer = new SqlPrinter({
|
|
18
|
+
* indentChar: ' ',
|
|
19
|
+
* indentSize: 1,
|
|
20
|
+
* keywordCase: 'upper',
|
|
21
|
+
* commaBreak: 'after'
|
|
22
|
+
* });
|
|
23
|
+
* const formatted = printer.print(sqlToken);
|
|
8
24
|
*/
|
|
9
25
|
class SqlPrinter {
|
|
10
26
|
/**
|
|
11
27
|
* @param options Optional style settings for pretty printing
|
|
12
28
|
*/
|
|
13
29
|
constructor(options) {
|
|
14
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
30
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
15
31
|
this.indentChar = (_a = options === null || options === void 0 ? void 0 : options.indentChar) !== null && _a !== void 0 ? _a : '';
|
|
16
32
|
this.indentSize = (_b = options === null || options === void 0 ? void 0 : options.indentSize) !== null && _b !== void 0 ? _b : 0;
|
|
17
33
|
// The default newline character is set to a blank space (' ') to enable one-liner formatting.
|
|
@@ -22,9 +38,10 @@ class SqlPrinter {
|
|
|
22
38
|
this.keywordCase = (_f = options === null || options === void 0 ? void 0 : options.keywordCase) !== null && _f !== void 0 ? _f : 'none';
|
|
23
39
|
this.exportComment = (_g = options === null || options === void 0 ? void 0 : options.exportComment) !== null && _g !== void 0 ? _g : false;
|
|
24
40
|
this.strictCommentPlacement = (_h = options === null || options === void 0 ? void 0 : options.strictCommentPlacement) !== null && _h !== void 0 ? _h : false;
|
|
41
|
+
this.cteOneline = (_j = options === null || options === void 0 ? void 0 : options.cteOneline) !== null && _j !== void 0 ? _j : false;
|
|
25
42
|
this.linePrinter = new LinePrinter_1.LinePrinter(this.indentChar, this.indentSize, this.newline);
|
|
26
43
|
// Initialize
|
|
27
|
-
this.indentIncrementContainers = new Set((
|
|
44
|
+
this.indentIncrementContainers = new Set((_k = options === null || options === void 0 ? void 0 : options.indentIncrementContainerTypes) !== null && _k !== void 0 ? _k : [
|
|
28
45
|
SqlPrintToken_1.SqlPrintTokenContainerType.SelectClause,
|
|
29
46
|
SqlPrintToken_1.SqlPrintTokenContainerType.FromClause,
|
|
30
47
|
SqlPrintToken_1.SqlPrintTokenContainerType.WhereClause,
|
|
@@ -51,8 +68,12 @@ class SqlPrinter {
|
|
|
51
68
|
}
|
|
52
69
|
/**
|
|
53
70
|
* Converts a SqlPrintToken tree to a formatted SQL string.
|
|
54
|
-
* @param token The root SqlPrintToken
|
|
55
|
-
* @param level
|
|
71
|
+
* @param token The root SqlPrintToken to format
|
|
72
|
+
* @param level Initial indentation level (default: 0)
|
|
73
|
+
* @returns Formatted SQL string
|
|
74
|
+
* @example
|
|
75
|
+
* const printer = new SqlPrinter({ indentChar: ' ', keywordCase: 'upper' });
|
|
76
|
+
* const formatted = printer.print(sqlToken);
|
|
56
77
|
*/
|
|
57
78
|
print(token, level = 0) {
|
|
58
79
|
// initialize
|
|
@@ -63,76 +84,30 @@ class SqlPrinter {
|
|
|
63
84
|
this.appendToken(token, level);
|
|
64
85
|
return this.linePrinter.print();
|
|
65
86
|
}
|
|
66
|
-
appendToken(token, level) {
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
87
|
+
appendToken(token, level, parentContainerType) {
|
|
88
|
+
if (this.shouldSkipToken(token)) {
|
|
89
|
+
return;
|
|
71
90
|
}
|
|
72
91
|
const current = this.linePrinter.getCurrentLine();
|
|
92
|
+
// Handle different token types
|
|
73
93
|
if (token.type === SqlPrintToken_1.SqlPrintTokenType.keyword) {
|
|
74
|
-
|
|
75
|
-
if (this.keywordCase === 'upper') {
|
|
76
|
-
text = text.toUpperCase();
|
|
77
|
-
}
|
|
78
|
-
else if (this.keywordCase === 'lower') {
|
|
79
|
-
text = text.toLowerCase();
|
|
80
|
-
}
|
|
81
|
-
this.linePrinter.appendText(text);
|
|
94
|
+
this.handleKeywordToken(token, level);
|
|
82
95
|
}
|
|
83
96
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.comma) {
|
|
84
|
-
|
|
85
|
-
if (this.commaBreak === 'before') {
|
|
86
|
-
this.linePrinter.appendNewline(level);
|
|
87
|
-
this.linePrinter.appendText(text);
|
|
88
|
-
}
|
|
89
|
-
else if (this.commaBreak === 'after') {
|
|
90
|
-
this.linePrinter.appendText(text);
|
|
91
|
-
this.linePrinter.appendNewline(level);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
this.linePrinter.appendText(text);
|
|
95
|
-
}
|
|
97
|
+
this.handleCommaToken(token, level, parentContainerType);
|
|
96
98
|
}
|
|
97
99
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.operator && token.text.toLowerCase() === 'and') {
|
|
98
|
-
|
|
99
|
-
if (this.keywordCase === 'upper') {
|
|
100
|
-
text = text.toUpperCase();
|
|
101
|
-
}
|
|
102
|
-
else if (this.keywordCase === 'lower') {
|
|
103
|
-
text = text.toLowerCase();
|
|
104
|
-
}
|
|
105
|
-
if (this.andBreak === 'before') {
|
|
106
|
-
this.linePrinter.appendNewline(level);
|
|
107
|
-
this.linePrinter.appendText(text);
|
|
108
|
-
}
|
|
109
|
-
else if (this.andBreak === 'after') {
|
|
110
|
-
this.linePrinter.appendText(text);
|
|
111
|
-
this.linePrinter.appendNewline(level);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
this.linePrinter.appendText(text);
|
|
115
|
-
}
|
|
100
|
+
this.handleAndOperatorToken(token, level);
|
|
116
101
|
}
|
|
117
102
|
else if (token.containerType === "JoinClause") {
|
|
118
|
-
|
|
119
|
-
if (this.keywordCase === 'upper') {
|
|
120
|
-
text = text.toUpperCase();
|
|
121
|
-
}
|
|
122
|
-
else if (this.keywordCase === 'lower') {
|
|
123
|
-
text = text.toLowerCase();
|
|
124
|
-
}
|
|
125
|
-
// before join clause, add newline
|
|
126
|
-
this.linePrinter.appendNewline(level);
|
|
127
|
-
this.linePrinter.appendText(text);
|
|
103
|
+
this.handleJoinClauseToken(token, level);
|
|
128
104
|
}
|
|
129
105
|
else if (token.type === SqlPrintToken_1.SqlPrintTokenType.comment) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
106
|
+
this.handleCommentToken(token);
|
|
107
|
+
}
|
|
108
|
+
else if (token.containerType === SqlPrintToken_1.SqlPrintTokenContainerType.CommonTable && this.cteOneline) {
|
|
109
|
+
this.handleCteOnelineToken(token, level);
|
|
110
|
+
return; // Return early to avoid processing innerTokens
|
|
136
111
|
}
|
|
137
112
|
else {
|
|
138
113
|
this.linePrinter.appendText(token.text);
|
|
@@ -141,7 +116,7 @@ class SqlPrinter {
|
|
|
141
116
|
if (token.keywordTokens && token.keywordTokens.length > 0) {
|
|
142
117
|
for (let i = 0; i < token.keywordTokens.length; i++) {
|
|
143
118
|
const keywordToken = token.keywordTokens[i];
|
|
144
|
-
this.appendToken(keywordToken, level);
|
|
119
|
+
this.appendToken(keywordToken, level, token.containerType);
|
|
145
120
|
}
|
|
146
121
|
}
|
|
147
122
|
let innerLevel = level;
|
|
@@ -152,13 +127,92 @@ class SqlPrinter {
|
|
|
152
127
|
}
|
|
153
128
|
for (let i = 0; i < token.innerTokens.length; i++) {
|
|
154
129
|
const child = token.innerTokens[i];
|
|
155
|
-
this.appendToken(child, innerLevel);
|
|
130
|
+
this.appendToken(child, innerLevel, token.containerType);
|
|
156
131
|
}
|
|
157
132
|
// indent level down
|
|
158
133
|
if (innerLevel !== level) {
|
|
159
134
|
this.linePrinter.appendNewline(level);
|
|
160
135
|
}
|
|
161
136
|
}
|
|
137
|
+
shouldSkipToken(token) {
|
|
138
|
+
return (!token.innerTokens || token.innerTokens.length === 0) && token.text === '';
|
|
139
|
+
}
|
|
140
|
+
applyKeywordCase(text) {
|
|
141
|
+
if (this.keywordCase === 'upper') {
|
|
142
|
+
return text.toUpperCase();
|
|
143
|
+
}
|
|
144
|
+
else if (this.keywordCase === 'lower') {
|
|
145
|
+
return text.toLowerCase();
|
|
146
|
+
}
|
|
147
|
+
return text;
|
|
148
|
+
}
|
|
149
|
+
handleKeywordToken(token, level) {
|
|
150
|
+
const text = this.applyKeywordCase(token.text);
|
|
151
|
+
this.linePrinter.appendText(text);
|
|
152
|
+
}
|
|
153
|
+
handleCommaToken(token, level, parentContainerType) {
|
|
154
|
+
const text = token.text;
|
|
155
|
+
// Special handling for commas in WithClause when cteOneline is enabled
|
|
156
|
+
if (this.cteOneline && parentContainerType === SqlPrintToken_1.SqlPrintTokenContainerType.WithClause) {
|
|
157
|
+
this.linePrinter.appendText(text);
|
|
158
|
+
this.linePrinter.appendNewline(level);
|
|
159
|
+
}
|
|
160
|
+
else if (this.commaBreak === 'before') {
|
|
161
|
+
this.linePrinter.appendNewline(level);
|
|
162
|
+
this.linePrinter.appendText(text);
|
|
163
|
+
}
|
|
164
|
+
else if (this.commaBreak === 'after') {
|
|
165
|
+
this.linePrinter.appendText(text);
|
|
166
|
+
this.linePrinter.appendNewline(level);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
this.linePrinter.appendText(text);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
handleAndOperatorToken(token, level) {
|
|
173
|
+
const text = this.applyKeywordCase(token.text);
|
|
174
|
+
if (this.andBreak === 'before') {
|
|
175
|
+
this.linePrinter.appendNewline(level);
|
|
176
|
+
this.linePrinter.appendText(text);
|
|
177
|
+
}
|
|
178
|
+
else if (this.andBreak === 'after') {
|
|
179
|
+
this.linePrinter.appendText(text);
|
|
180
|
+
this.linePrinter.appendNewline(level);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
this.linePrinter.appendText(text);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
handleJoinClauseToken(token, level) {
|
|
187
|
+
const text = this.applyKeywordCase(token.text);
|
|
188
|
+
// before join clause, add newline
|
|
189
|
+
this.linePrinter.appendNewline(level);
|
|
190
|
+
this.linePrinter.appendText(text);
|
|
191
|
+
}
|
|
192
|
+
handleCommentToken(token) {
|
|
193
|
+
// Handle comments - only output if exportComment is true
|
|
194
|
+
if (this.exportComment) {
|
|
195
|
+
this.linePrinter.appendText(token.text);
|
|
196
|
+
// Always add a space after comment to ensure SQL structure safety
|
|
197
|
+
this.linePrinter.appendText(' ');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
handleCteOnelineToken(token, level) {
|
|
201
|
+
// Handle CTE with one-liner formatting when cteOneline is enabled
|
|
202
|
+
const onelinePrinter = new SqlPrinter({
|
|
203
|
+
indentChar: '',
|
|
204
|
+
indentSize: 0,
|
|
205
|
+
newline: ' ',
|
|
206
|
+
commaBreak: this.commaBreak,
|
|
207
|
+
andBreak: this.andBreak,
|
|
208
|
+
keywordCase: this.keywordCase,
|
|
209
|
+
exportComment: this.exportComment,
|
|
210
|
+
strictCommentPlacement: this.strictCommentPlacement,
|
|
211
|
+
cteOneline: false, // Prevent recursive CTE oneline processing
|
|
212
|
+
});
|
|
213
|
+
const onelineResult = onelinePrinter.print(token, level);
|
|
214
|
+
this.linePrinter.appendText(onelineResult);
|
|
215
|
+
}
|
|
162
216
|
}
|
|
163
217
|
exports.SqlPrinter = SqlPrinter;
|
|
164
218
|
//# sourceMappingURL=SqlPrinter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlPrinter.js","sourceRoot":"","sources":["../../../src/transformers/SqlPrinter.ts"],"names":[],"mappings":";;;AAAA,2DAAuG;AACvG,+CAA6E;
|
|
1
|
+
{"version":3,"file":"SqlPrinter.js","sourceRoot":"","sources":["../../../src/transformers/SqlPrinter.ts"],"names":[],"mappings":";;;AAAA,2DAAuG;AACvG,+CAA6E;AA4C7E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,UAAU;IA2BnB;;OAEG;IACH,YAAY,OAA2B;;QACnC,IAAI,CAAC,UAAU,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,mCAAI,EAAE,CAAC;QAC5C,IAAI,CAAC,UAAU,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,mCAAI,CAAC,CAAC;QAE3C,8FAA8F;QAC9F,0EAA0E;QAC1E,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAA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