11import { BaseTransformer , TransformerContext } from '../visitors/base' ;
2- import { Node as PG14Node } from '../14/types' ;
3- import { Node as PG15Node } from '../15/types' ;
2+ import * as PG14 from '../14/types' ;
3+ import * as PG15 from '../15/types' ;
4+
5+ // Note: We use 'any' for some node types because the generated types don't accurately
6+ // reflect the actual parser output. For example, A_Const.val is typed as generic 'Node'
7+ // but actually contains specific node types like String, Integer, Float, etc.
48
59export class V14ToV15Transformer extends BaseTransformer {
610 transform ( node : any , context ?: TransformerContext ) : any {
@@ -23,6 +27,7 @@ export class V14ToV15Transformer extends BaseTransformer {
2327 }
2428
2529 A_Const ( nodeData : any , context ?: TransformerContext ) : any {
30+ // Using 'any' because PG14.A_Const.val is typed as generic Node but contains specific types
2631 const transformedData : any = { ...nodeData } ;
2732
2833 if ( nodeData . val ) {
@@ -64,6 +69,7 @@ export class V14ToV15Transformer extends BaseTransformer {
6469 }
6570
6671 String ( node : any , context ?: TransformerContext ) : any {
72+ // String node transformation: str -> sval
6773 const transformedData = { ...node } ;
6874
6975 if ( 'str' in transformedData ) {
@@ -75,6 +81,7 @@ export class V14ToV15Transformer extends BaseTransformer {
7581 }
7682
7783 BitString ( node : any , context ?: TransformerContext ) : any {
84+ // BitString node transformation: str -> bsval
7885 const transformedData = { ...node } ;
7986
8087 if ( 'str' in transformedData ) {
@@ -86,6 +93,7 @@ export class V14ToV15Transformer extends BaseTransformer {
8693 }
8794
8895 Float ( node : any , context ?: TransformerContext ) : any {
96+ // Float node transformation: str -> fval
8997 const transformedData = { ...node } ;
9098
9199 if ( 'str' in transformedData ) {
@@ -97,6 +105,7 @@ export class V14ToV15Transformer extends BaseTransformer {
97105 }
98106
99107 AlterPublicationStmt ( node : any , context ?: TransformerContext ) : any {
108+ // AlterPublicationStmt: tables -> pubobjects, tableAction -> action
100109 const transformedData = { ...node } ;
101110
102111 if ( 'tables' in transformedData ) {
@@ -112,6 +121,7 @@ export class V14ToV15Transformer extends BaseTransformer {
112121 }
113122
114123 CreatePublicationStmt ( node : any , context ?: TransformerContext ) : any {
124+ // CreatePublicationStmt: transform tables array to pubobjects with PublicationObjSpec
115125 const transformedData = { ...node } ;
116126
117127 if ( 'tables' in transformedData && Array . isArray ( transformedData . tables ) ) {
@@ -141,7 +151,7 @@ export class V14ToV15Transformer extends BaseTransformer {
141151 return transformedData ;
142152 }
143153
144- FuncCall ( node : any , context ?: TransformerContext ) : any {
154+ FuncCall ( node : PG14 . FuncCall , context ?: TransformerContext ) : any {
145155 const transformedData = { ...node } ;
146156
147157 if ( ! ( 'funcformat' in transformedData ) ) {
@@ -181,7 +191,7 @@ export class V14ToV15Transformer extends BaseTransformer {
181191 return transformedData ;
182192 }
183193
184- ColumnRef ( node : any , context ?: TransformerContext ) : any {
194+ ColumnRef ( node : PG14 . ColumnRef , context ?: TransformerContext ) : any {
185195 const transformedData = { ...node } ;
186196
187197 if ( transformedData . fields && Array . isArray ( transformedData . fields ) ) {
@@ -191,7 +201,7 @@ export class V14ToV15Transformer extends BaseTransformer {
191201 return transformedData ;
192202 }
193203
194- WindowDef ( node : any , context ?: TransformerContext ) : any {
204+ WindowDef ( node : PG14 . WindowDef , context ?: TransformerContext ) : any {
195205 const transformedData = { ...node } ;
196206
197207 if ( ! ( 'frameOptions' in transformedData ) ) {
@@ -213,6 +223,7 @@ export class V14ToV15Transformer extends BaseTransformer {
213223 }
214224
215225 SelectStmt ( nodeData : any , context ?: TransformerContext ) : any {
226+ // SelectStmt: handle limitOption and op defaults, orderClause -> sortClause in some contexts
216227 const transformedData : any = { } ;
217228
218229 for ( const [ key , value ] of Object . entries ( nodeData ) ) {
@@ -289,7 +300,7 @@ export class V14ToV15Transformer extends BaseTransformer {
289300
290301
291302
292- Integer ( node : any , context ?: TransformerContext ) : any {
303+ Integer ( node : PG14 . Integer , context ?: TransformerContext ) : any {
293304 const transformedData = { ...node } ;
294305
295306 if ( ! ( 'ival' in transformedData ) ) {
@@ -300,6 +311,7 @@ export class V14ToV15Transformer extends BaseTransformer {
300311 }
301312
302313 DefElem ( node : any , context ?: TransformerContext ) : any {
314+ // DefElem: convert Integer(0/1) to Boolean for 'strict' and 'cycle' definitions
303315 const transformedData = { ...node } ;
304316
305317 if ( transformedData . arg && transformedData . arg . Integer && ( transformedData . defname === 'strict' || transformedData . defname === 'cycle' ) ) {
@@ -326,7 +338,7 @@ export class V14ToV15Transformer extends BaseTransformer {
326338 return transformedData ;
327339 }
328340
329- RangeVar ( node : any , context ?: TransformerContext ) : any {
341+ RangeVar ( node : PG14 . RangeVar , context ?: TransformerContext ) : any {
330342 return node ;
331343 }
332344}
0 commit comments