@@ -75,59 +75,41 @@ export class V13ToV14Transformer {
7575 const nodeType = keys [ 0 ] ;
7676 const nodeData = node [ keys [ 0 ] ] ;
7777
78-
78+ if ( 'ctes' in nodeData ) {
79+ console . log ( 'transformGenericNode: Processing node with ctes:' , {
80+ nodeType,
81+ ctesType : typeof nodeData . ctes ,
82+ isArray : Array . isArray ( nodeData . ctes )
83+ } ) ;
84+ }
7985
8086 const transformedData : any = { } ;
8187 for ( const [ key , value ] of Object . entries ( nodeData ) ) {
8288 if ( key === 'ctes' && Array . isArray ( value ) ) {
8389 transformedData [ key ] = value . map ( item => this . transform ( item as any , context ) ) ;
8490 } else if ( key === 'objname' && typeof value === 'object' && value !== null ) {
91+ console . log ( 'transformGenericNode: Processing objname:' , {
92+ isArray : Array . isArray ( value ) ,
93+ value : JSON . stringify ( value , null , 2 ) ,
94+ keys : Object . keys ( value )
95+ } ) ;
8596 if ( Array . isArray ( value ) ) {
97+ console . log ( 'transformGenericNode: objname is array, transforming items' ) ;
8698 transformedData [ key ] = value . map ( item => this . transform ( item as any , context ) ) ;
8799 } else {
88100 const keys = Object . keys ( value ) ;
89101 const isNumericKeysObject = keys . every ( k => / ^ \d + $ / . test ( k ) ) ;
102+ console . log ( 'transformGenericNode: objname is object, isNumericKeysObject:' , isNumericKeysObject , 'keys:' , keys ) ;
90103 if ( isNumericKeysObject && keys . length > 0 ) {
91104 const sortedKeys = keys . sort ( ( a , b ) => parseInt ( a ) - parseInt ( b ) ) ;
105+ console . log ( 'transformGenericNode: Converting numeric keys object to array, sortedKeys:' , sortedKeys ) ;
92106 transformedData [ key ] = sortedKeys . map ( k => this . transform ( ( value as any ) [ k ] , context ) ) ;
93107 } else {
108+ // Regular object transformation
109+ console . log ( 'transformGenericNode: Regular object transformation for objname' ) ;
94110 transformedData [ key ] = this . transform ( value as any , context ) ;
95111 }
96112 }
97- } else if ( key === 'objargs' && typeof value === 'object' && value !== null ) {
98- if ( Array . isArray ( value ) ) {
99- transformedData [ key ] = value . map ( item => this . transform ( item as any , context ) ) ;
100- } else {
101- const keys = Object . keys ( value ) ;
102- const isNumericKeysObject = keys . every ( k => / ^ \d + $ / . test ( k ) ) ;
103- if ( isNumericKeysObject && keys . length > 0 ) {
104- const sortedKeys = keys . sort ( ( a , b ) => parseInt ( a ) - parseInt ( b ) ) ;
105- transformedData [ key ] = sortedKeys . map ( k => this . transform ( ( value as any ) [ k ] , context ) ) ;
106- } else {
107- transformedData [ key ] = this . transform ( value as any , context ) ;
108- }
109- }
110-
111- // Create objfuncargs from objargs for AlterOpFamilyStmt context
112- console . log ( 'DEBUG: Found objargs in transformGenericNode, context:' , {
113- parentNodeTypes : context . parentNodeTypes ,
114- nodeType : nodeType ,
115- objargs : transformedData [ key ]
116- } ) ;
117-
118- const shouldCreate = this . shouldCreateObjfuncargsFromObjargs ( context ) ;
119- console . log ( 'DEBUG: shouldCreateObjfuncargsFromObjargs returned:' , shouldCreate ) ;
120-
121- if ( shouldCreate ) {
122- const objargs = transformedData [ key ] ;
123- console . log ( 'DEBUG: Creating objfuncargs from objargs:' , objargs ) ;
124- if ( Array . isArray ( objargs ) ) {
125- transformedData [ 'objfuncargs' ] = objargs . map ( ( arg : any ) => this . createFunctionParameterFromTypeName ( arg ) ) ;
126- } else {
127- transformedData [ 'objfuncargs' ] = [ this . createFunctionParameterFromTypeName ( objargs ) ] ;
128- }
129- console . log ( 'DEBUG: Created objfuncargs:' , transformedData [ 'objfuncargs' ] ) ;
130- }
131113 } else if ( Array . isArray ( value ) ) {
132114 transformedData [ key ] = value . map ( item => this . transform ( item as any , context ) ) ;
133115 } else if ( typeof value === 'object' && value !== null ) {
@@ -770,17 +752,6 @@ export class V13ToV14Transformer {
770752
771753 if ( result . name !== undefined ) {
772754 result . name = this . transform ( result . name , childContext ) ;
773-
774- // Add objfuncargs creation logic for CreateOpClassItem in AlterOpFamilyStmt context
775- // Only add objfuncargs for functions (itemtype 2), not operators (itemtype 1)
776- if ( result . itemtype === 2 && result . name && typeof result . name === 'object' && result . name . objargs && ! result . name . objfuncargs ) {
777- const objargs = result . name . objargs ;
778- if ( Array . isArray ( objargs ) ) {
779- result . name . objfuncargs = objargs . map ( ( arg : any ) => this . createFunctionParameterFromTypeName ( arg ) ) ;
780- } else {
781- result . name . objfuncargs = [ this . createFunctionParameterFromTypeName ( objargs ) ] ;
782- }
783- }
784755 }
785756
786757 if ( result . args !== undefined ) {
@@ -991,17 +962,7 @@ export class V13ToV14Transformer {
991962 funcData = funcResult . ObjectWithArgs ;
992963 }
993964
994- if ( ! ( 'ObjectWithArgs' in funcResult ) && funcData . objname && funcData . objargs ) {
995- // Create objfuncargs from objargs for AlterFunctionStmt contexts
996- const objfuncargs = Array . isArray ( funcData . objargs )
997- ? funcData . objargs . map ( ( arg : any ) => this . createFunctionParameterFromTypeName ( arg ) )
998- : [ this . createFunctionParameterFromTypeName ( funcData . objargs ) ] ;
999-
1000- funcData . objfuncargs = objfuncargs ;
1001- result . func = funcData ;
1002- } else {
1003- result . func = 'ObjectWithArgs' in funcResult ? { ObjectWithArgs : funcData } : funcData ;
1004- }
965+ result . func = 'ObjectWithArgs' in funcResult ? { ObjectWithArgs : funcData } : funcData ;
1005966 } else {
1006967 result . func = funcResult ;
1007968 }
@@ -1705,16 +1666,8 @@ export class V13ToV14Transformer {
17051666 if ( Array . isArray ( result . objname ) ) {
17061667 result . objname = result . objname . map ( ( item : any ) => this . transform ( item , context ) ) ;
17071668 } else if ( typeof result . objname === 'object' && result . objname !== null ) {
1708- if ( this . shouldPreserveObjnameAsObject ( context ) ) {
1709- const transformedObjname : any = { } ;
1710- Object . keys ( result . objname ) . forEach ( key => {
1711- transformedObjname [ key ] = this . transform ( result . objname [ key ] , context ) ;
1712- } ) ;
1713- result . objname = transformedObjname ;
1714- } else {
1715- const keys = Object . keys ( result . objname ) . sort ( ( a , b ) => parseInt ( a ) - parseInt ( b ) ) ;
1716- result . objname = keys . map ( key => this . transform ( result . objname [ key ] , context ) ) ;
1717- }
1669+ const keys = Object . keys ( result . objname ) . sort ( ( a , b ) => parseInt ( a ) - parseInt ( b ) ) ;
1670+ result . objname = keys . map ( key => this . transform ( result . objname [ key ] , context ) ) ;
17181671 } else {
17191672 result . objname = this . transform ( result . objname , context ) ;
17201673 }
@@ -1724,13 +1677,30 @@ export class V13ToV14Transformer {
17241677 result . objargs = Array . isArray ( result . objargs )
17251678 ? result . objargs . map ( ( item : any ) => this . transform ( item , context ) )
17261679 : [ this . transform ( result . objargs , context ) ] ;
1727-
1728- // Only add objfuncargs when appropriate based on context
1729- if ( this . shouldCreateObjfuncargsFromObjargs ( context ) ) {
1730- result . objfuncargs = Array . isArray ( result . objargs )
1731- ? result . objargs . map ( ( arg : any ) => this . createFunctionParameterFromTypeName ( arg ) )
1732- : [ this . createFunctionParameterFromTypeName ( result . objargs ) ] ;
1680+ }
1681+
1682+ // Handle objfuncargs based on context
1683+ const shouldCreateObjfuncargs = this . shouldCreateObjfuncargs ( context ) ;
1684+ const shouldPreserveObjfuncargs = this . shouldPreserveObjfuncargs ( context ) ;
1685+ const shouldCreateObjfuncargsFromObjargs = this . shouldCreateObjfuncargsFromObjargs ( context ) ;
1686+
1687+ if ( shouldCreateObjfuncargsFromObjargs && result . objargs ) {
1688+ // Create objfuncargs from objargs (this takes priority over shouldCreateObjfuncargs)
1689+ result . objfuncargs = Array . isArray ( result . objargs )
1690+ ? result . objargs . map ( ( arg : any ) => this . createFunctionParameterFromTypeName ( arg ) )
1691+ : [ this . createFunctionParameterFromTypeName ( result . objargs ) ] ;
1692+ } else if ( shouldCreateObjfuncargs ) {
1693+ result . objfuncargs = [ ] ;
1694+ } else if ( result . objfuncargs !== undefined ) {
1695+ if ( shouldPreserveObjfuncargs ) {
1696+ result . objfuncargs = Array . isArray ( result . objfuncargs )
1697+ ? result . objfuncargs . map ( ( item : any ) => this . transform ( item , context ) )
1698+ : [ this . transform ( result . objfuncargs , context ) ] ;
1699+ } else {
1700+ delete result . objfuncargs ;
17331701 }
1702+ } else if ( ! shouldPreserveObjfuncargs ) {
1703+ delete result . objfuncargs ;
17341704 }
17351705
17361706 return { ObjectWithArgs : result } ;
@@ -1813,9 +1783,9 @@ export class V13ToV14Transformer {
18131783
18141784 const path = context . path || [ ] ;
18151785 const excludedNodeTypes = [
1816- 'CreateOpClassStmt' , 'CreateAggregateStmt' , 'AlterAggregateStmt' ,
1817- 'CreateFunctionStmt' , 'CreateStmt' , 'CreateTypeStmt' ,
1818- 'CreateOperatorStmt'
1786+ 'CreateOpClassStmt' , 'CreateOpClassItem' , ' CreateAggregateStmt', 'AlterAggregateStmt' ,
1787+ 'CreateFunctionStmt' , 'CreateStmt' , 'CreateTypeStmt' , 'CreateOpFamilyStmt' ,
1788+ 'CreateOperatorStmt' , 'GrantStmt' , 'RevokeStmt'
18191789 ] ;
18201790
18211791 for ( const node of path ) {
@@ -1834,7 +1804,7 @@ export class V13ToV14Transformer {
18341804 }
18351805
18361806 const allowedNodeTypes = [
1837- 'CommentStmt' , 'AlterFunctionStmt' , 'AlterOwnerStmt' , 'RenameStmt' , 'AlterObjectSchemaStmt' , 'CreateCastStmt' , 'AlterOpFamilyStmt' , 'GrantStmt' , 'RevokeStmt'
1807+ 'CommentStmt' , 'AlterFunctionStmt' , 'AlterOwnerStmt' , 'RenameStmt' , 'AlterObjectSchemaStmt' , 'CreateCastStmt' , 'AlterOpFamilyStmt'
18381808 ] ;
18391809
18401810 for ( const node of path ) {
@@ -1846,9 +1816,6 @@ export class V13ToV14Transformer {
18461816 if ( nodeType === 'DropStmt' ) {
18471817 return this . shouldAddObjfuncargsForDropStmt ( context ) ;
18481818 }
1849- if ( nodeType === 'GrantStmt' || nodeType === 'RevokeStmt' ) {
1850- return this . shouldAddObjfuncargsForGrantStmt ( context ) ;
1851- }
18521819 }
18531820 }
18541821
@@ -1859,9 +1826,6 @@ export class V13ToV14Transformer {
18591826 if ( parentType === 'DropStmt' ) {
18601827 return this . shouldAddObjfuncargsForDropStmt ( context ) ;
18611828 }
1862- if ( parentType === 'GrantStmt' || parentType === 'RevokeStmt' ) {
1863- return this . shouldAddObjfuncargsForGrantStmt ( context ) ;
1864- }
18651829 }
18661830
18671831 return false ;
@@ -1898,48 +1862,6 @@ export class V13ToV14Transformer {
18981862 return false ;
18991863 }
19001864
1901- private shouldAddObjfuncargsForGrantStmt ( context : TransformerContext ) : boolean {
1902- const path = context . path || [ ] ;
1903- for ( const node of path ) {
1904- if ( node && typeof node === 'object' && ( 'GrantStmt' in node || 'RevokeStmt' in node ) ) {
1905- const stmt = node . GrantStmt || node . RevokeStmt ;
1906- if ( stmt && stmt . objtype === 'OBJECT_FUNCTION' ) {
1907- return true ;
1908- }
1909- if ( stmt && stmt . objtype === 'OBJECT_AGGREGATE' ) {
1910- return true ;
1911- }
1912- if ( stmt && stmt . objtype === 'OBJECT_PROCEDURE' ) {
1913- return true ;
1914- }
1915- if ( stmt && stmt . objtype === 'OBJECT_OPERATOR' ) {
1916- return false ;
1917- }
1918- }
1919- }
1920-
1921- return false ;
1922- }
1923-
1924- private shouldPreserveObjnameAsObject ( context : TransformerContext ) : boolean {
1925- if ( ! context . parentNodeTypes || context . parentNodeTypes . length === 0 ) {
1926- return false ;
1927- }
1928-
1929- // For CreateOpClassItem contexts, preserve objname as objects for operators (itemtype 1)
1930- const preserveAsObjectContexts = [
1931- 'CreateOpClassStmt' , 'CreateOpClassItem' , 'CreateAccessMethodStmt'
1932- ] ;
1933-
1934- for ( const parentType of context . parentNodeTypes ) {
1935- if ( preserveAsObjectContexts . includes ( parentType ) ) {
1936- return true ;
1937- }
1938- }
1939-
1940- return false ;
1941- }
1942-
19431865 private createFunctionParameterFromTypeName ( typeNameNode : any ) : any {
19441866 const transformedTypeName = this . transform ( typeNameNode , { parentNodeTypes : [ ] } ) ;
19451867
0 commit comments